| 1 |
------------------------------------------------------------------------------ |
| 2 |
-- -- |
| 3 |
-- GNAT COMPILER COMPONENTS -- |
| 4 |
-- -- |
| 5 |
-- S E M _ C H 1 3 -- |
| 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 |
with Accessibility; use Accessibility; |
| 27 |
with Aspects; use Aspects; |
| 28 |
with Atree; use Atree; |
| 29 |
with Checks; use Checks; |
| 30 |
with Contracts; use Contracts; |
| 31 |
with Debug; use Debug; |
| 32 |
with Diagnostics.Constructors; use Diagnostics.Constructors; |
| 33 |
with Einfo; use Einfo; |
| 34 |
with Einfo.Entities; use Einfo.Entities; |
| 35 |
with Einfo.Utils; use Einfo.Utils; |
| 36 |
with Elists; use Elists; |
| 37 |
with Errout; use Errout; |
| 38 |
with Exp_Ch3; use Exp_Ch3; |
| 39 |
with Exp_Disp; use Exp_Disp; |
| 40 |
with Exp_Tss; use Exp_Tss; |
| 41 |
with Exp_Util; use Exp_Util; |
| 42 |
with Expander; use Expander; |
| 43 |
with Freeze; use Freeze; |
| 44 |
with Ghost; use Ghost; |
| 45 |
with Lib; use Lib; |
| 46 |
with Lib.Xref; use Lib.Xref; |
| 47 |
with Mutably_Tagged; use Mutably_Tagged; |
| 48 |
with Namet; use Namet; |
| 49 |
with Nlists; use Nlists; |
| 50 |
with Nmake; use Nmake; |
| 51 |
with Opt; use Opt; |
| 52 |
with Par_SCO; use Par_SCO; |
| 53 |
with Restrict; use Restrict; |
| 54 |
with Rident; use Rident; |
| 55 |
with Rtsfind; use Rtsfind; |
| 56 |
with Sem; use Sem; |
| 57 |
with Sem_Aux; use Sem_Aux; |
| 58 |
with Sem_Case; use Sem_Case; |
| 59 |
with Sem_Cat; use Sem_Cat; |
| 60 |
with Sem_Ch3; use Sem_Ch3; |
| 61 |
with Sem_Ch6; use Sem_Ch6; |
| 62 |
with Sem_Ch7; use Sem_Ch7; |
| 63 |
with Sem_Ch8; use Sem_Ch8; |
| 64 |
with Sem_Dim; use Sem_Dim; |
| 65 |
with Sem_Eval; use Sem_Eval; |
| 66 |
with Sem_Prag; use Sem_Prag; |
| 67 |
with Sem_Res; use Sem_Res; |
| 68 |
with Sem_Type; use Sem_Type; |
| 69 |
with Sem_Util; use Sem_Util; |
| 70 |
with Sem_Warn; use Sem_Warn; |
| 71 |
with Sinfo; use Sinfo; |
| 72 |
with Sinfo.Nodes; use Sinfo.Nodes; |
| 73 |
with Sinfo.Utils; use Sinfo.Utils; |
| 74 |
with Sinput; use Sinput; |
| 75 |
with Snames; use Snames; |
| 76 |
with Stand; use Stand; |
| 77 |
with System.Case_Util; use System.Case_Util; |
| 78 |
with Table; |
| 79 |
with Targparm; use Targparm; |
| 80 |
with Ttypes; use Ttypes; |
| 81 |
with Tbuild; use Tbuild; |
| 82 |
with Urealp; use Urealp; |
| 83 |
with Warnsw; use Warnsw; |
| 84 |
|
| 85 |
with GNAT.Heap_Sort_G; |
| 86 |
|
| 87 |
package body Sem_Ch13 is |
| 88 |
|
| 89 |
SSU : constant Pos := System_Storage_Unit; |
| 90 |
-- Convenient short hand for commonly used constant |
| 91 |
|
| 92 |
----------------------- |
| 93 |
-- Local Subprograms -- |
| 94 |
----------------------- |
| 95 |
|
| 96 |
procedure Adjust_Record_For_Reverse_Bit_Order_Ada_95 (R : Entity_Id); |
| 97 |
-- Helper routine providing the original (pre-AI95-0133) behavior for |
| 98 |
-- Adjust_Record_For_Reverse_Bit_Order. |
| 99 |
|
| 100 |
procedure Alignment_Check_For_Size_Change (Typ : Entity_Id; Size : Uint); |
| 101 |
-- This routine is called after setting one of the sizes of type entity |
| 102 |
-- Typ to Size. The purpose is to deal with the situation of a derived |
| 103 |
-- type whose inherited alignment is no longer appropriate for the new |
| 104 |
-- size value. In this case, we reset the Alignment to unknown. |
| 105 |
|
| 106 |
function All_Static_Choices (L : List_Id) return Boolean; |
| 107 |
-- Returns true if all elements of the list are OK static choices |
| 108 |
-- as defined below for Is_Static_Choice. Used for case expression |
| 109 |
-- alternatives and for the right operand of a membership test. An |
| 110 |
-- others_choice is static if the corresponding expression is static. |
| 111 |
-- The staticness of the bounds is checked separately. |
| 112 |
|
| 113 |
procedure Analyze_User_Aspect_Aspect_Specification (N : Node_Id); |
| 114 |
-- Analyze a User_Aspect aspect specification. Called from outside |
| 115 |
-- this package (in addition to locally), but the call from aspect.adb |
| 116 |
-- is via an access-to-subprogram value. |
| 117 |
|
| 118 |
procedure Build_Discrete_Static_Predicate |
| 119 |
(Typ : Entity_Id; |
| 120 |
Expr : Node_Id; |
| 121 |
Nam : Name_Id); |
| 122 |
-- Given a predicated type Typ, where Typ is a discrete static subtype, |
| 123 |
-- whose predicate expression is Expr, tests if Expr is a static predicate, |
| 124 |
-- and if so, builds the predicate range list. Nam is the name of the one |
| 125 |
-- argument to the predicate function. Occurrences of the type name in the |
| 126 |
-- predicate expression have been replaced by identifier references to this |
| 127 |
-- name, which is unique, so any identifier with Chars matching Nam must be |
| 128 |
-- a reference to the type. If the predicate is non-static, this procedure |
| 129 |
-- returns doing nothing. If the predicate is static, then the predicate |
| 130 |
-- list is stored in Static_Discrete_Predicate (Typ), and the Expr is |
| 131 |
-- rewritten as a canonicalized membership operation. |
| 132 |
|
| 133 |
function Build_Export_Import_Pragma |
| 134 |
(Asp : Node_Id; |
| 135 |
Id : Entity_Id) return Node_Id; |
| 136 |
-- Create the corresponding pragma for aspect Export or Import denoted by |
| 137 |
-- Asp. Id is the related entity subject to the aspect. Return Empty when |
| 138 |
-- the expression of aspect Asp evaluates to False or is erroneous. |
| 139 |
|
| 140 |
function Build_Predicate_Function_Declaration |
| 141 |
(Typ : Entity_Id) return Node_Id; |
| 142 |
-- Build the declaration for a predicate function. The declaration is built |
| 143 |
-- at the same time as the body but inserted before, as explained below. |
| 144 |
|
| 145 |
procedure Build_Predicate_Function (Typ : Entity_Id; N : Node_Id); |
| 146 |
-- If Typ has predicates (indicated by Has_Predicates being set for Typ), |
| 147 |
-- then either there are pragma Predicate entries on the rep chain for the |
| 148 |
-- type (note that Predicate aspects are converted to pragma Predicate), or |
| 149 |
-- there are inherited aspects from a parent type, or ancestor subtypes. |
| 150 |
-- This procedure builds body for the Predicate function that tests these |
| 151 |
-- predicates. N is the freeze node for the type. The spec of the function |
| 152 |
-- is inserted before the freeze node, and the body of the function is |
| 153 |
-- inserted after the freeze node. |
| 154 |
|
| 155 |
procedure Check_Aspect_At_End_Of_Declarations (ASN : Node_Id); |
| 156 |
-- Performs the processing of an aspect at the freeze all point and issues |
| 157 |
-- appropriate error messages if the visibility has indeed changed. ASN is |
| 158 |
-- the N_Aspect_Specification node for the aspect. |
| 159 |
|
| 160 |
procedure Check_Aspect_At_Freeze_Point (ASN : Node_Id); |
| 161 |
-- Performs the processing of an aspect at the freeze point. ASN is the |
| 162 |
-- N_Aspect_Specification node for the aspect. |
| 163 |
|
| 164 |
procedure Check_Aspect_Too_Late (N : Node_Id); |
| 165 |
-- This procedure is similar to Rep_Item_Too_Late for representation |
| 166 |
-- aspects that apply to type and that do not have a corresponding pragma. |
| 167 |
-- |
| 168 |
-- Used to check in particular that the expression associated with aspect |
| 169 |
-- node N for the given type (entity) of the aspect does not appear too |
| 170 |
-- late according to the rules in RM 13.1(9) and 13.1(10). |
| 171 |
|
| 172 |
procedure Check_Iterator_Functions (Typ : Entity_Id; Expr : Node_Id); |
| 173 |
-- Check that there is a single function in the type's Default_Iterator |
| 174 |
-- aspect that has the proper type structure. Expr is the name given in |
| 175 |
-- the aspect specification. |
| 176 |
|
| 177 |
procedure Check_Pool_Size_Clash (Ent : Entity_Id; SP, SS : Node_Id); |
| 178 |
-- Called if both Storage_Pool and Storage_Size attribute definition |
| 179 |
-- clauses (SP and SS) are present for entity Ent. Issue error message. |
| 180 |
|
| 181 |
function Check_Primitive_Function |
| 182 |
(Subp : Entity_Id; Ent : Entity_Id) return Boolean; |
| 183 |
-- Common legality checks for primitive-denoting aspects. Checks that |
| 184 |
-- Subp is a primitive subprogram of the type Ent. |
| 185 |
|
| 186 |
procedure Freeze_Entity_Checks (N : Node_Id); |
| 187 |
-- Called from Analyze_Freeze_Entity and Analyze_Generic_Freeze Entity |
| 188 |
-- to generate appropriate semantic checks that are delayed until this |
| 189 |
-- point (they had to be delayed this long for cases of delayed aspects, |
| 190 |
-- e.g. analysis of statically predicated subtypes in choices, for which |
| 191 |
-- we have to be sure the subtypes in question are frozen before checking). |
| 192 |
|
| 193 |
function Get_Alignment_Value (Expr : Node_Id) return Uint; |
| 194 |
-- Given the expression for an alignment value, returns the corresponding |
| 195 |
-- Uint value. If the value is inappropriate, then error messages are |
| 196 |
-- posted as required, and a value of No_Uint is returned. |
| 197 |
|
| 198 |
function Is_Operational_Item (N : Node_Id) return Boolean; |
| 199 |
-- A specification for a stream attribute is allowed before the full type |
| 200 |
-- is declared, as explained in AI-00137 and the corrigendum. Attributes |
| 201 |
-- that do not specify a representation characteristic are operational |
| 202 |
-- attributes. |
| 203 |
|
| 204 |
function Is_Static_Choice (N : Node_Id) return Boolean; |
| 205 |
-- Returns True if N represents a static choice (static subtype, or |
| 206 |
-- static subtype indication, or static expression, or static range). |
| 207 |
-- |
| 208 |
-- Note that this is a bit more inclusive than we actually need |
| 209 |
-- (in particular membership tests do not allow the use of subtype |
| 210 |
-- indications). But that doesn't matter, we have already checked |
| 211 |
-- that the construct is legal to get this far. |
| 212 |
|
| 213 |
function Is_Type_Related_Rep_Item (N : Node_Id) return Boolean; |
| 214 |
-- Returns True for a representation clause/pragma that specifies a |
| 215 |
-- type-related representation (as opposed to operational) aspect. |
| 216 |
|
| 217 |
function Is_Predicate_Static |
| 218 |
(Expr : Node_Id; |
| 219 |
Nam : Name_Id; |
| 220 |
Warn : Boolean := True) return Boolean; |
| 221 |
-- Given predicate expression Expr, tests if Expr is predicate-static in |
| 222 |
-- the sense of the rules in (RM 3.2.4 (15-24)). Occurrences of the type |
| 223 |
-- name in the predicate expression have been replaced by references to |
| 224 |
-- an identifier whose Chars field is Nam. This name is unique, so any |
| 225 |
-- identifier with Chars matching Nam must be a reference to the type. |
| 226 |
-- Returns True if the expression is predicate-static and False otherwise, |
| 227 |
-- but is not in the business of setting flags or issuing error messages. |
| 228 |
-- |
| 229 |
-- Only scalar types can have static predicates, so False is always |
| 230 |
-- returned for non-scalar types. |
| 231 |
-- |
| 232 |
-- Note: the RM seems to suggest that string types can also have static |
| 233 |
-- predicates. But that really makes little sense as very few useful |
| 234 |
-- predicates can be constructed for strings. Remember that: |
| 235 |
-- |
| 236 |
-- "ABC" < "DEF" |
| 237 |
-- |
| 238 |
-- is not a static expression. So even though the clearly faulty RM wording |
| 239 |
-- allows the following: |
| 240 |
-- |
| 241 |
-- subtype S is String with Static_Predicate => S < "DEF" |
| 242 |
-- |
| 243 |
-- We can't allow this, otherwise we have predicate-static applying to a |
| 244 |
-- larger class than static expressions, which was never intended. |
| 245 |
-- |
| 246 |
-- The Warn parameter is True iff this is not a recursive call. This |
| 247 |
-- parameter is used to avoid generating warnings for subexpressions and |
| 248 |
-- for cases where the predicate expression (as originally written by |
| 249 |
-- the user, before any transformations) is a Boolean literal. |
| 250 |
|
| 251 |
procedure New_Put_Image_Subprogram |
| 252 |
(N : Node_Id; |
| 253 |
Ent : Entity_Id; |
| 254 |
Subp : Entity_Id); |
| 255 |
-- Similar to New_Stream_Subprogram, but for the Put_Image attribute |
| 256 |
|
| 257 |
procedure New_Stream_Subprogram |
| 258 |
(N : Node_Id; |
| 259 |
Ent : Entity_Id; |
| 260 |
Subp : Entity_Id; |
| 261 |
Nam : TSS_Name_Type); |
| 262 |
-- Create a subprogram renaming of a given stream attribute to the |
| 263 |
-- designated subprogram and then in the tagged case, provide this as a |
| 264 |
-- primitive operation, or in the untagged case make an appropriate TSS |
| 265 |
-- entry. This is more properly an expansion activity than just semantics, |
| 266 |
-- but the presence of user-defined stream functions for limited types |
| 267 |
-- is a legality check, which is why this takes place here rather than in |
| 268 |
-- exp_ch13, where it was previously. Nam indicates the name of the TSS |
| 269 |
-- function to be generated. |
| 270 |
-- |
| 271 |
-- To avoid elaboration anomalies with freeze nodes, for untagged types |
| 272 |
-- we generate both a subprogram declaration and a subprogram renaming |
| 273 |
-- declaration, so that the attribute specification is handled as a |
| 274 |
-- renaming_as_body. For tagged types, the specification is one of the |
| 275 |
-- primitive specs. |
| 276 |
|
| 277 |
procedure No_Type_Rep_Item (N : Node_Id); |
| 278 |
-- Output message indicating that no type-related aspects can be |
| 279 |
-- specified due to some property of the parent type. |
| 280 |
|
| 281 |
procedure Register_Address_Clause_Check |
| 282 |
(N : Node_Id; |
| 283 |
X : Entity_Id; |
| 284 |
A : Uint; |
| 285 |
Y : Entity_Id; |
| 286 |
Off : Boolean); |
| 287 |
-- Register a check for the address clause N. The rest of the parameters |
| 288 |
-- are in keeping with the components of Address_Clause_Check_Record below. |
| 289 |
|
| 290 |
procedure Validate_Aspect_Aggregate (N : Node_Id); |
| 291 |
-- Check legality of operations given in the Ada 2022 Aggregate aspect for |
| 292 |
-- containers. |
| 293 |
|
| 294 |
procedure Resolve_Aspect_Aggregate |
| 295 |
(Typ : Entity_Id; |
| 296 |
Expr : Node_Id); |
| 297 |
-- Resolve each one of the operations specified in the specification of |
| 298 |
-- Aspect_Aggregate. |
| 299 |
|
| 300 |
procedure Validate_Aspect_Local_Restrictions (E : Entity_Id; N : Node_Id); |
| 301 |
-- Check legality of a Local_Restrictions aspect specification |
| 302 |
|
| 303 |
procedure Validate_Aspect_Stable_Properties |
| 304 |
(E : Entity_Id; N : Node_Id; Class_Present : Boolean); |
| 305 |
-- Check legality of functions given in the Ada 2022 Stable_Properties |
| 306 |
-- (or Stable_Properties'Class) aspect. |
| 307 |
|
| 308 |
procedure Validate_Storage_Model_Type_Aspect |
| 309 |
(Typ : Entity_Id; ASN : Node_Id); |
| 310 |
-- Check legality and completeness of the aggregate associations given in |
| 311 |
-- the Storage_Model_Type aspect associated with Typ. |
| 312 |
|
| 313 |
procedure Validate_Finalizable_Aspect (Typ : Entity_Id; ASN : Node_Id); |
| 314 |
-- Check legality and completeness of the aggregate associations given in |
| 315 |
-- the Finalizable aspect associated with Typ. |
| 316 |
|
| 317 |
procedure Resolve_Storage_Model_Type_Argument |
| 318 |
(N : Node_Id; |
| 319 |
Typ : Entity_Id; |
| 320 |
Addr_Type : in out Entity_Id; |
| 321 |
Nam : Name_Id); |
| 322 |
-- Resolve argument N to be of the proper kind (when a type or constant) |
| 323 |
-- or to have the proper profile (when a subprogram). |
| 324 |
|
| 325 |
procedure Resolve_Aspect_Stable_Properties |
| 326 |
(Typ_Or_Subp : Entity_Id; |
| 327 |
Expr : Node_Id; |
| 328 |
Class_Present : Boolean); |
| 329 |
-- Resolve each one of the functions specified in the specification of |
| 330 |
-- aspect Stable_Properties (or Stable_Properties'Class). |
| 331 |
|
| 332 |
procedure Resolve_Finalizable_Argument |
| 333 |
(N : Node_Id; |
| 334 |
Typ : Entity_Id; |
| 335 |
Nam : Name_Id); |
| 336 |
-- Resolve each one of the arguments specified in the specification of |
| 337 |
-- aspect Finalizable. |
| 338 |
|
| 339 |
procedure Resolve_Iterable_Operation |
| 340 |
(N : Node_Id; |
| 341 |
Cursor : Entity_Id; |
| 342 |
Typ : Entity_Id; |
| 343 |
Nam : Name_Id); |
| 344 |
-- If the name of a primitive operation for an Iterable aspect is |
| 345 |
-- overloaded, resolve according to required signature. |
| 346 |
|
| 347 |
procedure Set_Biased |
| 348 |
(E : Entity_Id; |
| 349 |
N : Node_Id; |
| 350 |
Msg : String; |
| 351 |
Biased : Boolean := True); |
| 352 |
-- If Biased is True, sets Has_Biased_Representation flag for E, and |
| 353 |
-- outputs a warning message at node N if Warn_On_Biased_Representation is |
| 354 |
-- is True. This warning inserts the string Msg to describe the construct |
| 355 |
-- causing biasing. |
| 356 |
|
| 357 |
----------------------------------------------------------- |
| 358 |
-- Visibility of Discriminants in Aspect Specifications -- |
| 359 |
----------------------------------------------------------- |
| 360 |
|
| 361 |
-- The discriminants of a type are visible when analyzing the aspect |
| 362 |
-- specifications of a type declaration or protected type declaration, |
| 363 |
-- but not when analyzing those of a subtype declaration. The following |
| 364 |
-- routines enforce this distinction. |
| 365 |
|
| 366 |
procedure Push_Type (E : Entity_Id); |
| 367 |
-- Push scope E and make visible the discriminants of type entity E if E |
| 368 |
-- has discriminants and is not a subtype. |
| 369 |
|
| 370 |
procedure Pop_Type (E : Entity_Id); |
| 371 |
-- Remove visibility to the discriminants of type entity E and pop the |
| 372 |
-- scope stack if E has discriminants and is not a subtype. |
| 373 |
|
| 374 |
---------------------------------------------- |
| 375 |
-- Table for Validate_Unchecked_Conversions -- |
| 376 |
---------------------------------------------- |
| 377 |
|
| 378 |
-- The following table collects unchecked conversions for validation. |
| 379 |
-- Entries are made by Validate_Unchecked_Conversion and then the call |
| 380 |
-- to Validate_Unchecked_Conversions does the actual error checking and |
| 381 |
-- posting of warnings. The reason for this delayed processing is to take |
| 382 |
-- advantage of back-annotations of size and alignment values performed by |
| 383 |
-- the back end. |
| 384 |
|
| 385 |
-- Note: the reason we store a Source_Ptr value instead of a Node_Id is |
| 386 |
-- that by the time Validate_Unchecked_Conversions is called, Sprint will |
| 387 |
-- already have modified all Sloc values if the -gnatD option is set. |
| 388 |
|
| 389 |
type UC_Entry is record |
| 390 |
Eloc : Source_Ptr; -- node used for posting warnings |
| 391 |
Source : Entity_Id; -- source type for unchecked conversion |
| 392 |
Target : Entity_Id; -- target type for unchecked conversion |
| 393 |
Act_Unit : Entity_Id; -- actual function instantiated |
| 394 |
end record; |
| 395 |
|
| 396 |
package Unchecked_Conversions is new Table.Table ( |
| 397 |
Table_Component_Type => UC_Entry, |
| 398 |
Table_Index_Type => Int, |
| 399 |
Table_Low_Bound => 1, |
| 400 |
Table_Initial => 50, |
| 401 |
Table_Increment => 200, |
| 402 |
Table_Name => "Unchecked_Conversions"); |
| 403 |
|
| 404 |
---------------------------------------- |
| 405 |
-- Table for Validate_Address_Clauses -- |
| 406 |
---------------------------------------- |
| 407 |
|
| 408 |
-- If an address clause has the form |
| 409 |
|
| 410 |
-- for X'Address use Expr |
| 411 |
|
| 412 |
-- where Expr has a value known at compile time or is of the form Y'Address |
| 413 |
-- or recursively is a reference to a constant initialized with either of |
| 414 |
-- these forms, and the value of Expr is not a multiple of X's alignment, |
| 415 |
-- or if Y has a smaller alignment than X, then that merits a warning about |
| 416 |
-- possible bad alignment. The following table collects address clauses of |
| 417 |
-- this kind. We put these in a table so that they can be checked after the |
| 418 |
-- back end has completed annotation of the alignments of objects, since we |
| 419 |
-- can catch more cases that way. |
| 420 |
|
| 421 |
type Address_Clause_Check_Record is record |
| 422 |
N : Node_Id; |
| 423 |
-- The address clause |
| 424 |
|
| 425 |
X : Entity_Id; |
| 426 |
-- The entity of the object subject to the address clause |
| 427 |
|
| 428 |
A : Uint; |
| 429 |
-- The value of the address in the first case |
| 430 |
|
| 431 |
Y : Entity_Id; |
| 432 |
-- The entity of the object being overlaid in the second case |
| 433 |
|
| 434 |
Off : Boolean; |
| 435 |
-- Whether the address is offset within Y in the second case |
| 436 |
|
| 437 |
Alignment_Checks_Suppressed : Boolean; |
| 438 |
-- Whether alignment checks are suppressed by an active scope suppress |
| 439 |
-- setting. We need to save the value in order to be able to reuse it |
| 440 |
-- after the back end has been run. |
| 441 |
end record; |
| 442 |
|
| 443 |
package Address_Clause_Checks is new Table.Table ( |
| 444 |
Table_Component_Type => Address_Clause_Check_Record, |
| 445 |
Table_Index_Type => Int, |
| 446 |
Table_Low_Bound => 1, |
| 447 |
Table_Initial => 20, |
| 448 |
Table_Increment => 200, |
| 449 |
Table_Name => "Address_Clause_Checks"); |
| 450 |
|
| 451 |
function Alignment_Checks_Suppressed |
| 452 |
(ACCR : Address_Clause_Check_Record) return Boolean; |
| 453 |
-- Return whether the alignment check generated for the address clause |
| 454 |
-- is suppressed. |
| 455 |
|
| 456 |
--------------------------------- |
| 457 |
-- Alignment_Checks_Suppressed -- |
| 458 |
--------------------------------- |
| 459 |
|
| 460 |
function Alignment_Checks_Suppressed |
| 461 |
(ACCR : Address_Clause_Check_Record) return Boolean |
| 462 |
is |
| 463 |
begin |
| 464 |
if Checks_May_Be_Suppressed (ACCR.X) then |
| 465 |
return Is_Check_Suppressed (ACCR.X, Alignment_Check); |
| 466 |
else |
| 467 |
return ACCR.Alignment_Checks_Suppressed; |
| 468 |
end if; |
| 469 |
end Alignment_Checks_Suppressed; |
| 470 |
|
| 471 |
----------------------------------------- |
| 472 |
-- Adjust_Record_For_Reverse_Bit_Order -- |
| 473 |
----------------------------------------- |
| 474 |
|
| 475 |
procedure Adjust_Record_For_Reverse_Bit_Order (R : Entity_Id) is |
| 476 |
Max_Machine_Scalar_Size : constant Uint := |
| 477 |
UI_From_Int (if Reverse_Bit_Order_Threshold >= 0 |
| 478 |
then Reverse_Bit_Order_Threshold |
| 479 |
else System_Max_Integer_Size); |
| 480 |
-- We use this as the maximum machine scalar size |
| 481 |
|
| 482 |
SSU : constant Uint := UI_From_Int (System_Storage_Unit); |
| 483 |
|
| 484 |
CC : Node_Id; |
| 485 |
Comp : Node_Id; |
| 486 |
Num_CC : Natural; |
| 487 |
|
| 488 |
begin |
| 489 |
-- The processing done here used to depend on the Ada version, but the |
| 490 |
-- behavior has been changed by AI95-0133. However this AI is a Binding |
| 491 |
-- Interpretation, so we now implement it even in Ada 95 mode. But the |
| 492 |
-- original behavior from unamended Ada 95 is available for the sake of |
| 493 |
-- compatibility under the debugging switch -gnatd.p in Ada 95 mode. |
| 494 |
|
| 495 |
if Ada_Version < Ada_2005 and then Debug_Flag_Dot_P then |
| 496 |
Adjust_Record_For_Reverse_Bit_Order_Ada_95 (R); |
| 497 |
return; |
| 498 |
end if; |
| 499 |
|
| 500 |
-- For Ada 2005, we do machine scalar processing, as fully described In |
| 501 |
-- AI-133. This involves gathering all components which start at the |
| 502 |
-- same byte offset and processing them together. Same approach is still |
| 503 |
-- valid in later versions including Ada 2012. |
| 504 |
|
| 505 |
-- Note that component clauses found on record types may be inherited, |
| 506 |
-- in which case the layout of the component with such a clause still |
| 507 |
-- has to be done at this point. Therefore, the processing done here |
| 508 |
-- must exclusively rely on the Component_Clause of the component. |
| 509 |
|
| 510 |
-- This first loop through components does two things. First it deals |
| 511 |
-- with the case of components with component clauses whose length is |
| 512 |
-- greater than the maximum machine scalar size (either accepting them |
| 513 |
-- or rejecting as needed). Second, it counts the number of components |
| 514 |
-- with component clauses whose length does not exceed this maximum for |
| 515 |
-- later processing. |
| 516 |
|
| 517 |
Num_CC := 0; |
| 518 |
Comp := First_Component_Or_Discriminant (R); |
| 519 |
while Present (Comp) loop |
| 520 |
CC := Component_Clause (Comp); |
| 521 |
|
| 522 |
if Present (CC) then |
| 523 |
declare |
| 524 |
Fbit : constant Uint := Static_Integer (First_Bit (CC)); |
| 525 |
Lbit : constant Uint := Static_Integer (Last_Bit (CC)); |
| 526 |
|
| 527 |
begin |
| 528 |
-- Case of component with last bit >= max machine scalar |
| 529 |
|
| 530 |
if Lbit >= Max_Machine_Scalar_Size then |
| 531 |
|
| 532 |
-- This is allowed only if first bit is zero, and last bit |
| 533 |
-- + 1 is a multiple of storage unit size. |
| 534 |
|
| 535 |
if Fbit = 0 and then (Lbit + 1) mod SSU = 0 then |
| 536 |
|
| 537 |
-- This is the case to give a warning if enabled |
| 538 |
|
| 539 |
if Warn_On_Reverse_Bit_Order then |
| 540 |
Error_Msg_N |
| 541 |
("multi-byte field specified with " |
| 542 |
& "non-standard Bit_Order?.v?", CC); |
| 543 |
|
| 544 |
if Bytes_Big_Endian then |
| 545 |
Error_Msg_N |
| 546 |
("\bytes are not reversed " |
| 547 |
& "(component is big-endian)?.v?", CC); |
| 548 |
else |
| 549 |
Error_Msg_N |
| 550 |
("\bytes are not reversed " |
| 551 |
& "(component is little-endian)?.v?", CC); |
| 552 |
end if; |
| 553 |
end if; |
| 554 |
|
| 555 |
-- Give error message for RM 13.5.1(10) violation |
| 556 |
|
| 557 |
else |
| 558 |
Error_Msg_FE |
| 559 |
("machine scalar rules not followed for&", |
| 560 |
First_Bit (CC), Comp); |
| 561 |
|
| 562 |
Error_Msg_Uint_1 := Lbit + 1; |
| 563 |
Error_Msg_Uint_2 := Max_Machine_Scalar_Size; |
| 564 |
Error_Msg_F |
| 565 |
("\last bit + 1 (^) exceeds maximum machine scalar " |
| 566 |
& "size (^)", First_Bit (CC)); |
| 567 |
|
| 568 |
if (Lbit + 1) mod SSU /= 0 then |
| 569 |
Error_Msg_Uint_1 := SSU; |
| 570 |
Error_Msg_F |
| 571 |
("\and is not a multiple of Storage_Unit (^) " |
| 572 |
& "(RM 13.5.1(10))", First_Bit (CC)); |
| 573 |
|
| 574 |
else |
| 575 |
Error_Msg_Uint_1 := Fbit; |
| 576 |
Error_Msg_F |
| 577 |
("\and first bit (^) is non-zero " |
| 578 |
& "(RM 13.4.1(10))", First_Bit (CC)); |
| 579 |
end if; |
| 580 |
end if; |
| 581 |
|
| 582 |
-- OK case of machine scalar related component clause. For now, |
| 583 |
-- just count them. |
| 584 |
|
| 585 |
else |
| 586 |
Num_CC := Num_CC + 1; |
| 587 |
end if; |
| 588 |
end; |
| 589 |
end if; |
| 590 |
|
| 591 |
Next_Component_Or_Discriminant (Comp); |
| 592 |
end loop; |
| 593 |
|
| 594 |
-- We need to sort the component clauses on the basis of the Position |
| 595 |
-- values in the clause, so we can group clauses with the same Position |
| 596 |
-- together to determine the relevant machine scalar size. |
| 597 |
|
| 598 |
Sort_CC : declare |
| 599 |
Comps : array (0 .. Num_CC) of Entity_Id; |
| 600 |
-- Array to collect component and discriminant entities. The data |
| 601 |
-- starts at index 1, the 0'th entry is for the sort routine. |
| 602 |
|
| 603 |
function CP_Lt (Op1, Op2 : Natural) return Boolean; |
| 604 |
-- Compare routine for Sort |
| 605 |
|
| 606 |
procedure CP_Move (From : Natural; To : Natural); |
| 607 |
-- Move routine for Sort |
| 608 |
|
| 609 |
package Sorting is new GNAT.Heap_Sort_G (CP_Move, CP_Lt); |
| 610 |
|
| 611 |
MaxL : Uint; |
| 612 |
-- Maximum last bit value of any component in this set |
| 613 |
|
| 614 |
MSS : Uint; |
| 615 |
-- Corresponding machine scalar size |
| 616 |
|
| 617 |
Start : Natural; |
| 618 |
Stop : Natural; |
| 619 |
-- Start and stop positions in the component list of the set of |
| 620 |
-- components with the same starting position (that constitute |
| 621 |
-- components in a single machine scalar). |
| 622 |
|
| 623 |
----------- |
| 624 |
-- CP_Lt -- |
| 625 |
----------- |
| 626 |
|
| 627 |
function CP_Lt (Op1, Op2 : Natural) return Boolean is |
| 628 |
begin |
| 629 |
return |
| 630 |
Position (Component_Clause (Comps (Op1))) < |
| 631 |
Position (Component_Clause (Comps (Op2))); |
| 632 |
end CP_Lt; |
| 633 |
|
| 634 |
------------- |
| 635 |
-- CP_Move -- |
| 636 |
------------- |
| 637 |
|
| 638 |
procedure CP_Move (From : Natural; To : Natural) is |
| 639 |
begin |
| 640 |
Comps (To) := Comps (From); |
| 641 |
end CP_Move; |
| 642 |
|
| 643 |
-- Start of processing for Sort_CC |
| 644 |
|
| 645 |
begin |
| 646 |
-- Collect the machine scalar relevant component clauses |
| 647 |
|
| 648 |
Num_CC := 0; |
| 649 |
Comp := First_Component_Or_Discriminant (R); |
| 650 |
while Present (Comp) loop |
| 651 |
declare |
| 652 |
CC : constant Node_Id := Component_Clause (Comp); |
| 653 |
|
| 654 |
begin |
| 655 |
-- Collect only component clauses whose last bit is less than |
| 656 |
-- machine scalar size. Any component clause whose last bit |
| 657 |
-- exceeds this value does not take part in machine scalar |
| 658 |
-- layout considerations. The test for Error_Posted makes sure |
| 659 |
-- we exclude component clauses for which we already posted an |
| 660 |
-- error. |
| 661 |
|
| 662 |
if Present (CC) |
| 663 |
and then not Error_Posted (Last_Bit (CC)) |
| 664 |
and then Static_Integer (Last_Bit (CC)) < |
| 665 |
Max_Machine_Scalar_Size |
| 666 |
then |
| 667 |
Num_CC := Num_CC + 1; |
| 668 |
Comps (Num_CC) := Comp; |
| 669 |
end if; |
| 670 |
end; |
| 671 |
|
| 672 |
Next_Component_Or_Discriminant (Comp); |
| 673 |
end loop; |
| 674 |
|
| 675 |
-- Sort by ascending position number |
| 676 |
|
| 677 |
Sorting.Sort (Num_CC); |
| 678 |
|
| 679 |
-- We now have all the components whose size does not exceed the max |
| 680 |
-- machine scalar value, sorted by starting position. In this loop we |
| 681 |
-- gather groups of clauses starting at the same position, to process |
| 682 |
-- them in accordance with AI-133. |
| 683 |
|
| 684 |
Stop := 0; |
| 685 |
while Stop < Num_CC loop |
| 686 |
Start := Stop + 1; |
| 687 |
Stop := Start; |
| 688 |
MaxL := |
| 689 |
Static_Integer |
| 690 |
(Last_Bit (Component_Clause (Comps (Start)))); |
| 691 |
while Stop < Num_CC loop |
| 692 |
if Static_Integer |
| 693 |
(Position (Component_Clause (Comps (Stop + 1)))) = |
| 694 |
Static_Integer |
| 695 |
(Position (Component_Clause (Comps (Stop)))) |
| 696 |
then |
| 697 |
Stop := Stop + 1; |
| 698 |
MaxL := |
| 699 |
UI_Max |
| 700 |
(MaxL, |
| 701 |
Static_Integer |
| 702 |
(Last_Bit |
| 703 |
(Component_Clause (Comps (Stop))))); |
| 704 |
else |
| 705 |
exit; |
| 706 |
end if; |
| 707 |
end loop; |
| 708 |
|
| 709 |
-- Now we have a group of component clauses from Start to Stop |
| 710 |
-- whose positions are identical, and MaxL is the maximum last |
| 711 |
-- bit value of any of these components. |
| 712 |
|
| 713 |
-- We need to determine the corresponding machine scalar size. |
| 714 |
-- This loop assumes that machine scalar sizes are even, and that |
| 715 |
-- each possible machine scalar has twice as many bits as the next |
| 716 |
-- smaller one. |
| 717 |
|
| 718 |
MSS := Max_Machine_Scalar_Size; |
| 719 |
while MSS mod 2 = 0 |
| 720 |
and then (MSS / 2) >= SSU |
| 721 |
and then (MSS / 2) > MaxL |
| 722 |
loop |
| 723 |
MSS := MSS / 2; |
| 724 |
end loop; |
| 725 |
|
| 726 |
-- Here is where we fix up the Component_Bit_Offset value to |
| 727 |
-- account for the reverse bit order. Some examples of what needs |
| 728 |
-- to be done for the case of a machine scalar size of 8 are: |
| 729 |
|
| 730 |
-- First_Bit .. Last_Bit Component_Bit_Offset |
| 731 |
-- old new old new |
| 732 |
|
| 733 |
-- 0 .. 0 7 .. 7 0 7 |
| 734 |
-- 0 .. 1 6 .. 7 0 6 |
| 735 |
-- 0 .. 2 5 .. 7 0 5 |
| 736 |
-- 0 .. 7 0 .. 7 0 4 |
| 737 |
|
| 738 |
-- 1 .. 1 6 .. 6 1 6 |
| 739 |
-- 1 .. 4 3 .. 6 1 3 |
| 740 |
-- 4 .. 7 0 .. 3 4 0 |
| 741 |
|
| 742 |
-- The rule is that the first bit is obtained by subtracting the |
| 743 |
-- old ending bit from machine scalar size - 1. |
| 744 |
|
| 745 |
for C in Start .. Stop loop |
| 746 |
declare |
| 747 |
Comp : constant Entity_Id := Comps (C); |
| 748 |
CC : constant Node_Id := Component_Clause (Comp); |
| 749 |
|
| 750 |
FB : constant Uint := Static_Integer (First_Bit (CC)); |
| 751 |
LB : constant Uint := Static_Integer (Last_Bit (CC)); |
| 752 |
NFB : constant Uint := MSS - 1 - LB; |
| 753 |
NLB : constant Uint := NFB + LB - FB; |
| 754 |
Pos : constant Uint := Static_Integer (Position (CC)); |
| 755 |
|
| 756 |
begin |
| 757 |
-- Do not warn for the artificial clause built for the tag |
| 758 |
-- in Check_Record_Representation_Clause if it is inherited. |
| 759 |
|
| 760 |
if Warn_On_Reverse_Bit_Order |
| 761 |
and then Chars (Comp) /= Name_uTag |
| 762 |
then |
| 763 |
Error_Msg_Uint_1 := MSS; |
| 764 |
Error_Msg_N |
| 765 |
("reverse bit order in machine scalar of " |
| 766 |
& "length^?.v?", First_Bit (CC)); |
| 767 |
Error_Msg_Uint_1 := NFB; |
| 768 |
Error_Msg_Uint_2 := NLB; |
| 769 |
|
| 770 |
if Bytes_Big_Endian then |
| 771 |
Error_Msg_NE |
| 772 |
("\big-endian range for component & is ^ .. ^?.v?", |
| 773 |
First_Bit (CC), Comp); |
| 774 |
else |
| 775 |
Error_Msg_NE |
| 776 |
("\little-endian range for component " & |
| 777 |
"& is ^ .. ^?.v?", |
| 778 |
First_Bit (CC), Comp); |
| 779 |
end if; |
| 780 |
end if; |
| 781 |
|
| 782 |
Set_Component_Bit_Offset (Comp, Pos * SSU + NFB); |
| 783 |
Set_Esize (Comp, 1 + (NLB - NFB)); |
| 784 |
Set_Normalized_First_Bit (Comp, NFB mod SSU); |
| 785 |
Set_Normalized_Position (Comp, Pos + NFB / SSU); |
| 786 |
end; |
| 787 |
end loop; |
| 788 |
end loop; |
| 789 |
end Sort_CC; |
| 790 |
end Adjust_Record_For_Reverse_Bit_Order; |
| 791 |
|
| 792 |
------------------------------------------------ |
| 793 |
-- Adjust_Record_For_Reverse_Bit_Order_Ada_95 -- |
| 794 |
------------------------------------------------ |
| 795 |
|
| 796 |
procedure Adjust_Record_For_Reverse_Bit_Order_Ada_95 (R : Entity_Id) is |
| 797 |
CC : Node_Id; |
| 798 |
Comp : Node_Id; |
| 799 |
|
| 800 |
begin |
| 801 |
-- For Ada 95, we just renumber bits within a storage unit. We do the |
| 802 |
-- same for Ada 83 mode, since we recognize the Bit_Order attribute in |
| 803 |
-- Ada 83, and are free to add this extension. |
| 804 |
|
| 805 |
Comp := First_Component_Or_Discriminant (R); |
| 806 |
while Present (Comp) loop |
| 807 |
CC := Component_Clause (Comp); |
| 808 |
|
| 809 |
-- If component clause is present, then deal with the non-default |
| 810 |
-- bit order case for Ada 95 mode. |
| 811 |
|
| 812 |
-- We only do this processing for the base type, and in fact that |
| 813 |
-- is important, since otherwise if there are record subtypes, we |
| 814 |
-- could reverse the bits once for each subtype, which is wrong. |
| 815 |
|
| 816 |
if Present (CC) and then Ekind (R) = E_Record_Type then |
| 817 |
declare |
| 818 |
CFB : constant Uint := Component_Bit_Offset (Comp); |
| 819 |
CSZ : constant Uint := Esize (Comp); |
| 820 |
CLC : constant Node_Id := Component_Clause (Comp); |
| 821 |
Pos : constant Node_Id := Position (CLC); |
| 822 |
FB : constant Node_Id := First_Bit (CLC); |
| 823 |
|
| 824 |
Storage_Unit_Offset : constant Uint := |
| 825 |
CFB / System_Storage_Unit; |
| 826 |
|
| 827 |
Start_Bit : constant Uint := |
| 828 |
CFB mod System_Storage_Unit; |
| 829 |
|
| 830 |
begin |
| 831 |
-- Cases where field goes over storage unit boundary |
| 832 |
|
| 833 |
if Start_Bit + CSZ > System_Storage_Unit then |
| 834 |
|
| 835 |
-- Allow multi-byte field but generate warning |
| 836 |
|
| 837 |
if Start_Bit mod System_Storage_Unit = 0 |
| 838 |
and then CSZ mod System_Storage_Unit = 0 |
| 839 |
then |
| 840 |
Error_Msg_N |
| 841 |
("multi-byte field specified with non-standard " |
| 842 |
& "Bit_Order?.v?", CLC); |
| 843 |
|
| 844 |
if Bytes_Big_Endian then |
| 845 |
Error_Msg_N |
| 846 |
("\bytes are not reversed " |
| 847 |
& "(component is big-endian)?.v?", CLC); |
| 848 |
else |
| 849 |
Error_Msg_N |
| 850 |
("\bytes are not reversed " |
| 851 |
& "(component is little-endian)?.v?", CLC); |
| 852 |
end if; |
| 853 |
|
| 854 |
-- Do not allow non-contiguous field |
| 855 |
|
| 856 |
else |
| 857 |
Error_Msg_N |
| 858 |
("attempt to specify non-contiguous field not " |
| 859 |
& "permitted", CLC); |
| 860 |
Error_Msg_N |
| 861 |
("\caused by non-standard Bit_Order specified in " |
| 862 |
& "legacy Ada 95 mode", CLC); |
| 863 |
end if; |
| 864 |
|
| 865 |
-- Case where field fits in one storage unit |
| 866 |
|
| 867 |
else |
| 868 |
-- Give warning if suspicious component clause |
| 869 |
|
| 870 |
if Intval (FB) >= System_Storage_Unit |
| 871 |
and then Warn_On_Reverse_Bit_Order |
| 872 |
then |
| 873 |
Error_Msg_N |
| 874 |
("Bit_Order clause does not affect byte " |
| 875 |
& "ordering?.v?", Pos); |
| 876 |
Error_Msg_Uint_1 := |
| 877 |
Intval (Pos) + Intval (FB) / |
| 878 |
System_Storage_Unit; |
| 879 |
Error_Msg_N |
| 880 |
("position normalized to ^ before bit order " |
| 881 |
& "interpreted?.v?", Pos); |
| 882 |
end if; |
| 883 |
|
| 884 |
-- Here is where we fix up the Component_Bit_Offset value |
| 885 |
-- to account for the reverse bit order. Some examples of |
| 886 |
-- what needs to be done are: |
| 887 |
|
| 888 |
-- First_Bit .. Last_Bit Component_Bit_Offset |
| 889 |
-- old new old new |
| 890 |
|
| 891 |
-- 0 .. 0 7 .. 7 0 7 |
| 892 |
-- 0 .. 1 6 .. 7 0 6 |
| 893 |
-- 0 .. 2 5 .. 7 0 5 |
| 894 |
-- 0 .. 7 0 .. 7 0 4 |
| 895 |
|
| 896 |
-- 1 .. 1 6 .. 6 1 6 |
| 897 |
-- 1 .. 4 3 .. 6 1 3 |
| 898 |
-- 4 .. 7 0 .. 3 4 0 |
| 899 |
|
| 900 |
-- The rule is that the first bit is obtained by subtracting |
| 901 |
-- the old ending bit from storage_unit - 1. |
| 902 |
|
| 903 |
Set_Component_Bit_Offset (Comp, |
| 904 |
(Storage_Unit_Offset * System_Storage_Unit) + |
| 905 |
(System_Storage_Unit - 1) - |
| 906 |
(Start_Bit + CSZ - 1)); |
| 907 |
|
| 908 |
Set_Normalized_Position (Comp, |
| 909 |
Component_Bit_Offset (Comp) / System_Storage_Unit); |
| 910 |
|
| 911 |
Set_Normalized_First_Bit (Comp, |
| 912 |
Component_Bit_Offset (Comp) mod System_Storage_Unit); |
| 913 |
end if; |
| 914 |
end; |
| 915 |
end if; |
| 916 |
|
| 917 |
Next_Component_Or_Discriminant (Comp); |
| 918 |
end loop; |
| 919 |
end Adjust_Record_For_Reverse_Bit_Order_Ada_95; |
| 920 |
|
| 921 |
------------------------------------- |
| 922 |
-- Alignment_Check_For_Size_Change -- |
| 923 |
------------------------------------- |
| 924 |
|
| 925 |
procedure Alignment_Check_For_Size_Change (Typ : Entity_Id; Size : Uint) is |
| 926 |
begin |
| 927 |
-- If the alignment is known, and not set by a rep clause, and is |
| 928 |
-- inconsistent with the size being set, then reset it to unknown, |
| 929 |
-- we assume in this case that the size overrides the inherited |
| 930 |
-- alignment, and that the alignment must be recomputed. |
| 931 |
|
| 932 |
if Known_Alignment (Typ) |
| 933 |
and then not Has_Alignment_Clause (Typ) |
| 934 |
and then Present (Size) |
| 935 |
and then Size mod (Alignment (Typ) * SSU) /= 0 |
| 936 |
then |
| 937 |
Reinit_Alignment (Typ); |
| 938 |
end if; |
| 939 |
end Alignment_Check_For_Size_Change; |
| 940 |
|
| 941 |
----------------------------------- |
| 942 |
-- All_Membership_Choices_Static -- |
| 943 |
----------------------------------- |
| 944 |
|
| 945 |
function All_Membership_Choices_Static (Expr : Node_Id) return Boolean is |
| 946 |
pragma Assert (Nkind (Expr) in N_Membership_Test); |
| 947 |
begin |
| 948 |
pragma Assert |
| 949 |
(Present (Right_Opnd (Expr)) |
| 950 |
xor |
| 951 |
Present (Alternatives (Expr))); |
| 952 |
|
| 953 |
if Present (Right_Opnd (Expr)) then |
| 954 |
return Is_Static_Choice (Right_Opnd (Expr)); |
| 955 |
else |
| 956 |
return All_Static_Choices (Alternatives (Expr)); |
| 957 |
end if; |
| 958 |
end All_Membership_Choices_Static; |
| 959 |
|
| 960 |
------------------------ |
| 961 |
-- All_Static_Choices -- |
| 962 |
------------------------ |
| 963 |
|
| 964 |
function All_Static_Choices (L : List_Id) return Boolean is |
| 965 |
N : Node_Id; |
| 966 |
|
| 967 |
begin |
| 968 |
N := First (L); |
| 969 |
while Present (N) loop |
| 970 |
if not Is_Static_Choice (N) then |
| 971 |
return False; |
| 972 |
end if; |
| 973 |
|
| 974 |
Next (N); |
| 975 |
end loop; |
| 976 |
|
| 977 |
return True; |
| 978 |
end All_Static_Choices; |
| 979 |
|
| 980 |
------------------------------------- |
| 981 |
-- Analyze_Aspects_At_Freeze_Point -- |
| 982 |
------------------------------------- |
| 983 |
|
| 984 |
procedure Analyze_Aspects_At_Freeze_Point |
| 985 |
(E : Entity_Id; |
| 986 |
Nonoverridable_Only : Boolean := False) |
| 987 |
is |
| 988 |
procedure Analyze_Aspect_Default_Value (ASN : Node_Id); |
| 989 |
-- This routine analyzes an Aspect_Default_[Component_]Value denoted by |
| 990 |
-- the aspect specification node ASN. |
| 991 |
|
| 992 |
procedure Check_Indexing_Functions (ASN : Node_Id); |
| 993 |
-- Check that the function in a Constant_Indexing or Variable_Indexing |
| 994 |
-- aspect has the proper profile. If the name is overloaded, check that |
| 995 |
-- some interpretation is legal. |
| 996 |
|
| 997 |
procedure Make_Pragma_From_Boolean_Aspect (ASN : Node_Id); |
| 998 |
-- Given an aspect specification node ASN whose expression is an |
| 999 |
-- optional Boolean, this routines creates the corresponding pragma |
| 1000 |
-- at the freezing point. |
| 1001 |
|
| 1002 |
---------------------------------- |
| 1003 |
-- Analyze_Aspect_Default_Value -- |
| 1004 |
---------------------------------- |
| 1005 |
|
| 1006 |
procedure Analyze_Aspect_Default_Value (ASN : Node_Id) is |
| 1007 |
Ent : constant Entity_Id := Entity (ASN); |
| 1008 |
Expr : constant Node_Id := Expression (ASN); |
| 1009 |
|
| 1010 |
begin |
| 1011 |
Set_Has_Default_Aspect (Base_Type (Ent)); |
| 1012 |
|
| 1013 |
if Is_Scalar_Type (Ent) then |
| 1014 |
Set_Default_Aspect_Value (Base_Type (Ent), Expr); |
| 1015 |
else |
| 1016 |
Set_Default_Aspect_Component_Value (Base_Type (Ent), Expr); |
| 1017 |
end if; |
| 1018 |
|
| 1019 |
Check_Aspect_Too_Late (ASN); |
| 1020 |
end Analyze_Aspect_Default_Value; |
| 1021 |
|
| 1022 |
------------------------------ |
| 1023 |
-- Check_Indexing_Functions -- |
| 1024 |
------------------------------ |
| 1025 |
|
| 1026 |
procedure Check_Indexing_Functions (ASN : Node_Id) is |
| 1027 |
Aspect : constant Aspect_Id := Get_Aspect_Id (ASN); |
| 1028 |
Expr : constant Node_Id := Expression (ASN); |
| 1029 |
|
| 1030 |
Indexing_Found : Boolean := False; |
| 1031 |
|
| 1032 |
procedure Check_Inherited_Indexing; |
| 1033 |
-- For a derived type, check that the specification of an indexing |
| 1034 |
-- aspect can only be confirming (i.e., that it uses the same name |
| 1035 |
-- as the parent type's aspect). |
| 1036 |
-- |
| 1037 |
-- AI12-0160: The uses of Constant_Indexing and Variable_Indexing |
| 1038 |
-- aspects have to be the same for all descendants of an indexable |
| 1039 |
-- container type. |
| 1040 |
|
| 1041 |
------------------------------ |
| 1042 |
-- Check_Inherited_Indexing -- |
| 1043 |
------------------------------ |
| 1044 |
|
| 1045 |
procedure Check_Inherited_Indexing is |
| 1046 |
Inherited : Node_Id; |
| 1047 |
Other_Indexing : Node_Id; |
| 1048 |
|
| 1049 |
begin |
| 1050 |
if Aspect = Aspect_Constant_Indexing then |
| 1051 |
Inherited := |
| 1052 |
Find_Aspect (Etype (E), Aspect_Constant_Indexing); |
| 1053 |
Other_Indexing := |
| 1054 |
Find_Aspect (Etype (E), Aspect_Variable_Indexing); |
| 1055 |
|
| 1056 |
else pragma Assert (Aspect = Aspect_Variable_Indexing); |
| 1057 |
Inherited := |
| 1058 |
Find_Aspect (Etype (E), Aspect_Variable_Indexing); |
| 1059 |
Other_Indexing := |
| 1060 |
Find_Aspect (Etype (E), Aspect_Constant_Indexing); |
| 1061 |
end if; |
| 1062 |
|
| 1063 |
if Present (Inherited) then |
| 1064 |
|
| 1065 |
-- Check if this is a confirming specification. The name |
| 1066 |
-- may be overloaded between the parent operation and the |
| 1067 |
-- inherited one, so we check that the Chars fields match. |
| 1068 |
|
| 1069 |
if Same_Name (Expression (Inherited), Expression (ASN)) then |
| 1070 |
Indexing_Found := True; |
| 1071 |
|
| 1072 |
-- Indicate the operation that must be overridden, rather than |
| 1073 |
-- redefining the indexing aspect. |
| 1074 |
|
| 1075 |
else |
| 1076 |
Error_Msg_NE |
| 1077 |
("overriding of inherited indexing aspect" & |
| 1078 |
" must be confirming", ASN, E); |
| 1079 |
Error_Msg_NE |
| 1080 |
("\\override & instead", |
| 1081 |
ASN, Entity (Expression (Inherited))); |
| 1082 |
end if; |
| 1083 |
|
| 1084 |
-- If not inherited and the parent has another indexing function |
| 1085 |
-- this is illegal, because it leads to inconsistent results in |
| 1086 |
-- class-wide calls. |
| 1087 |
|
| 1088 |
elsif Present (Other_Indexing) then |
| 1089 |
Error_Msg_N |
| 1090 |
("cannot specify one indexing aspect for derived type" |
| 1091 |
& " if the other indexing aspect is specified for the" |
| 1092 |
& " parent and this aspect is not", ASN); |
| 1093 |
end if; |
| 1094 |
end Check_Inherited_Indexing; |
| 1095 |
|
| 1096 |
-- Start of processing for Check_Indexing_Functions |
| 1097 |
|
| 1098 |
begin |
| 1099 |
-- If the aspect specification was effectively inherited from the |
| 1100 |
-- parent type (so constructed anew by analysis), then no point |
| 1101 |
-- in validating. |
| 1102 |
|
| 1103 |
if not Comes_From_Source (ASN) then |
| 1104 |
return; |
| 1105 |
end if; |
| 1106 |
|
| 1107 |
if not Is_Overloaded (Expr) then |
| 1108 |
Check_Function_For_Indexing_Aspect |
| 1109 |
(ASN, E, Entity (Expr), Valid => Indexing_Found); |
| 1110 |
|
| 1111 |
else |
| 1112 |
declare |
| 1113 |
I : Interp_Index; |
| 1114 |
It : Interp; |
| 1115 |
Valid : Boolean; |
| 1116 |
|
| 1117 |
begin |
| 1118 |
Get_First_Interp (Expr, I, It); |
| 1119 |
while Present (It.Nam) loop |
| 1120 |
|
| 1121 |
-- Check that each interpretation is a function valid for |
| 1122 |
-- use as an indexing function. (Note that the rules for |
| 1123 |
-- indexing aspects are to be treated as legality rules, |
| 1124 |
-- as per AI22-0084. If this is ever changed to treat these |
| 1125 |
-- as resolution rules, then we'll have to keep track of |
| 1126 |
-- whether there are further interpretations to be tested, |
| 1127 |
-- and condition the error reporting within Illegal_Indexing |
| 1128 |
-- on that.) |
| 1129 |
|
| 1130 |
if Is_Overloadable (It.Nam) then |
| 1131 |
Check_Function_For_Indexing_Aspect |
| 1132 |
(ASN, E, It.Nam, Valid); |
| 1133 |
Indexing_Found := Indexing_Found or Valid; |
| 1134 |
end if; |
| 1135 |
|
| 1136 |
Get_Next_Interp (I, It); |
| 1137 |
end loop; |
| 1138 |
end; |
| 1139 |
end if; |
| 1140 |
|
| 1141 |
if not Indexing_Found and then not Error_Posted (ASN) then |
| 1142 |
Error_Msg_NE |
| 1143 |
("indexing aspect requires a local function that applies to " |
| 1144 |
& "type&", Expr, E); |
| 1145 |
end if; |
| 1146 |
|
| 1147 |
-- ??? Is Is_Derived_Type the right test here? A derived type's |
| 1148 |
-- ancestor might or might not have the aspect specified, and |
| 1149 |
-- the derived type itself might or might not have an explicit |
| 1150 |
-- aspect specification (as opposed to an aspect specification |
| 1151 |
-- implicitly introduced by the compiler). So lots of cases to |
| 1152 |
-- consider. |
| 1153 |
|
| 1154 |
if Is_Derived_Type (E) |
| 1155 |
-- See comment re this debug flag in exp_ch5.adb |
| 1156 |
and then not Debug_Flag_Dot_XX |
| 1157 |
then |
| 1158 |
Check_Inherited_Indexing; |
| 1159 |
end if; |
| 1160 |
|
| 1161 |
-- If partial declaration exists, verify that it is not tagged. |
| 1162 |
|
| 1163 |
if Ekind (Current_Scope) = E_Package |
| 1164 |
and then Has_Private_Declaration (E) |
| 1165 |
and then |
| 1166 |
List_Containing (Parent (E)) = |
| 1167 |
Private_Declarations |
| 1168 |
(Specification (Unit_Declaration_Node (Current_Scope))) |
| 1169 |
then |
| 1170 |
declare |
| 1171 |
Decl : Node_Id; |
| 1172 |
|
| 1173 |
begin |
| 1174 |
Decl := |
| 1175 |
First (Visible_Declarations |
| 1176 |
(Specification |
| 1177 |
(Unit_Declaration_Node (Current_Scope)))); |
| 1178 |
|
| 1179 |
while Present (Decl) loop |
| 1180 |
if Nkind (Decl) = N_Private_Type_Declaration |
| 1181 |
and then E = Full_View (Defining_Identifier (Decl)) |
| 1182 |
and then Tagged_Present (Decl) |
| 1183 |
and then No (Aspect_Specifications (Decl)) |
| 1184 |
-- Don't complain about compiler-generated |
| 1185 |
-- confirming specifications for inherited aspects. |
| 1186 |
and then Comes_From_Source (ASN) |
| 1187 |
then |
| 1188 |
Error_Msg_NE |
| 1189 |
("indexing aspect cannot be specified on full view " |
| 1190 |
& "if partial view is tagged", ASN, E); |
| 1191 |
return; |
| 1192 |
end if; |
| 1193 |
|
| 1194 |
Next (Decl); |
| 1195 |
end loop; |
| 1196 |
end; |
| 1197 |
end if; |
| 1198 |
end Check_Indexing_Functions; |
| 1199 |
|
| 1200 |
------------------------------------- |
| 1201 |
-- Make_Pragma_From_Boolean_Aspect -- |
| 1202 |
------------------------------------- |
| 1203 |
|
| 1204 |
procedure Make_Pragma_From_Boolean_Aspect (ASN : Node_Id) is |
| 1205 |
Ident : constant Node_Id := Identifier (ASN); |
| 1206 |
A_Name : constant Name_Id := Chars (Ident); |
| 1207 |
A_Id : constant Aspect_Id := Get_Aspect_Id (A_Name); |
| 1208 |
Ent : constant Entity_Id := Entity (ASN); |
| 1209 |
Expr : constant Node_Id := Expression (ASN); |
| 1210 |
Loc : constant Source_Ptr := Sloc (ASN); |
| 1211 |
|
| 1212 |
procedure Check_False_Aspect_For_Derived_Type; |
| 1213 |
-- This procedure checks for the case of a false aspect for a derived |
| 1214 |
-- type, which improperly tries to cancel an aspect inherited from |
| 1215 |
-- the parent. |
| 1216 |
|
| 1217 |
----------------------------------------- |
| 1218 |
-- Check_False_Aspect_For_Derived_Type -- |
| 1219 |
----------------------------------------- |
| 1220 |
|
| 1221 |
procedure Check_False_Aspect_For_Derived_Type is |
| 1222 |
Par : Node_Id; |
| 1223 |
|
| 1224 |
begin |
| 1225 |
-- We are only checking derived types |
| 1226 |
|
| 1227 |
if not Is_Derived_Type (E) then |
| 1228 |
return; |
| 1229 |
end if; |
| 1230 |
|
| 1231 |
Par := Nearest_Ancestor (E); |
| 1232 |
|
| 1233 |
case A_Id is |
| 1234 |
when Aspect_Atomic |
| 1235 |
| Aspect_Shared |
| 1236 |
=> |
| 1237 |
if not Is_Atomic (Par) then |
| 1238 |
return; |
| 1239 |
end if; |
| 1240 |
|
| 1241 |
when Aspect_Atomic_Components => |
| 1242 |
if not Has_Atomic_Components (Par) then |
| 1243 |
return; |
| 1244 |
end if; |
| 1245 |
|
| 1246 |
when Aspect_Discard_Names => |
| 1247 |
if not Discard_Names (Par) then |
| 1248 |
return; |
| 1249 |
end if; |
| 1250 |
|
| 1251 |
when Aspect_Pack => |
| 1252 |
if not Is_Packed (Par) then |
| 1253 |
return; |
| 1254 |
end if; |
| 1255 |
|
| 1256 |
when Aspect_Unchecked_Union => |
| 1257 |
if not Is_Unchecked_Union (Par) then |
| 1258 |
return; |
| 1259 |
end if; |
| 1260 |
|
| 1261 |
when Aspect_Volatile => |
| 1262 |
if not Is_Volatile (Par) then |
| 1263 |
return; |
| 1264 |
end if; |
| 1265 |
|
| 1266 |
when Aspect_Volatile_Components => |
| 1267 |
if not Has_Volatile_Components (Par) then |
| 1268 |
return; |
| 1269 |
end if; |
| 1270 |
|
| 1271 |
when Aspect_Volatile_Full_Access |
| 1272 |
| Aspect_Full_Access_Only |
| 1273 |
=> |
| 1274 |
if not Is_Volatile_Full_Access (Par) then |
| 1275 |
return; |
| 1276 |
end if; |
| 1277 |
|
| 1278 |
when others => |
| 1279 |
return; |
| 1280 |
end case; |
| 1281 |
|
| 1282 |
-- Fall through means we are canceling an inherited aspect |
| 1283 |
|
| 1284 |
Error_Msg_Name_1 := A_Name; |
| 1285 |
Error_Msg_NE |
| 1286 |
("derived type& inherits aspect%, cannot cancel", Expr, E); |
| 1287 |
end Check_False_Aspect_For_Derived_Type; |
| 1288 |
|
| 1289 |
-- Local variables |
| 1290 |
|
| 1291 |
Prag : Node_Id; |
| 1292 |
P_Name : Name_Id; |
| 1293 |
|
| 1294 |
-- Start of processing for Make_Pragma_From_Boolean_Aspect |
| 1295 |
|
| 1296 |
begin |
| 1297 |
if Present (Expr) and then Is_False (Static_Boolean (Expr)) then |
| 1298 |
Check_False_Aspect_For_Derived_Type; |
| 1299 |
|
| 1300 |
else |
| 1301 |
-- There is no Full_Access_Only pragma so use VFA instead |
| 1302 |
|
| 1303 |
if A_Name = Name_Full_Access_Only then |
| 1304 |
P_Name := Name_Volatile_Full_Access; |
| 1305 |
else |
| 1306 |
P_Name := A_Name; |
| 1307 |
end if; |
| 1308 |
|
| 1309 |
Prag := |
| 1310 |
Make_Pragma (Loc, |
| 1311 |
Pragma_Identifier => |
| 1312 |
Make_Identifier (Sloc (Ident), P_Name), |
| 1313 |
Pragma_Argument_Associations => New_List ( |
| 1314 |
Make_Pragma_Argument_Association (Sloc (Ident), |
| 1315 |
Expression => New_Occurrence_Of (Ent, Sloc (Ident))))); |
| 1316 |
|
| 1317 |
Set_From_Aspect_Specification (Prag, True); |
| 1318 |
Set_Corresponding_Aspect (Prag, ASN); |
| 1319 |
Set_Aspect_Rep_Item (ASN, Prag); |
| 1320 |
Set_Is_Delayed_Aspect (Prag); |
| 1321 |
Set_Parent (Prag, ASN); |
| 1322 |
end if; |
| 1323 |
end Make_Pragma_From_Boolean_Aspect; |
| 1324 |
|
| 1325 |
-- Local variables |
| 1326 |
|
| 1327 |
A_Id : Aspect_Id; |
| 1328 |
ASN : Node_Id; |
| 1329 |
Ritem : Node_Id; |
| 1330 |
|
| 1331 |
-- Start of processing for Analyze_Aspects_At_Freeze_Point |
| 1332 |
|
| 1333 |
begin |
| 1334 |
-- Must be visible in current scope, but if this is a type from a nested |
| 1335 |
-- package it may be frozen from an object declaration in the enclosing |
| 1336 |
-- scope, so install the package declarations to complete the analysis |
| 1337 |
-- of the aspects, if any. If the package itself is frozen the type will |
| 1338 |
-- have been frozen as well. We don't do this in the case where formal |
| 1339 |
-- Nonoverridable_Only is True, because that formal is only passed True |
| 1340 |
-- at the ends of certain declaration lists (like visible-part lists), |
| 1341 |
-- not when this procedure is called at arbitrary freeze points. |
| 1342 |
|
| 1343 |
if not Nonoverridable_Only and then not In_Open_Scopes (Scope (E)) then |
| 1344 |
if Is_Type (E) and then From_Nested_Package (E) then |
| 1345 |
declare |
| 1346 |
Pack : constant Entity_Id := Scope (E); |
| 1347 |
|
| 1348 |
begin |
| 1349 |
Push_Scope (Pack); |
| 1350 |
Install_Visible_Declarations (Pack); |
| 1351 |
Install_Private_Declarations (Pack); |
| 1352 |
Analyze_Aspects_At_Freeze_Point (E); |
| 1353 |
|
| 1354 |
if Is_Private_Type (E) |
| 1355 |
and then Present (Full_View (E)) |
| 1356 |
then |
| 1357 |
Analyze_Aspects_At_Freeze_Point (Full_View (E)); |
| 1358 |
end if; |
| 1359 |
|
| 1360 |
End_Package_Scope (Pack); |
| 1361 |
return; |
| 1362 |
end; |
| 1363 |
|
| 1364 |
-- Aspects from other entities in different contexts are analyzed |
| 1365 |
-- elsewhere. |
| 1366 |
|
| 1367 |
else |
| 1368 |
return; |
| 1369 |
end if; |
| 1370 |
end if; |
| 1371 |
|
| 1372 |
-- Look for aspect specification entries for this entity |
| 1373 |
|
| 1374 |
ASN := First_Rep_Item (E); |
| 1375 |
while Present (ASN) loop |
| 1376 |
if Nkind (ASN) = N_Aspect_Specification then |
| 1377 |
exit when Entity (ASN) /= E; |
| 1378 |
|
| 1379 |
if Is_Delayed_Aspect (ASN) then |
| 1380 |
A_Id := Get_Aspect_Id (ASN); |
| 1381 |
|
| 1382 |
-- When Nonoverridable_Only is True (such as at the end of |
| 1383 |
-- a visible part), we only want to process aspects that are |
| 1384 |
-- nonoverridable, and skip others. |
| 1385 |
|
| 1386 |
if Nonoverridable_Only |
| 1387 |
and then A_Id not in Nonoverridable_Aspect_Id |
| 1388 |
then |
| 1389 |
goto Skip_Aspect; |
| 1390 |
end if; |
| 1391 |
|
| 1392 |
case A_Id is |
| 1393 |
|
| 1394 |
-- For aspects whose expression is an optional Boolean, make |
| 1395 |
-- the corresponding pragma at the freeze point. |
| 1396 |
|
| 1397 |
when Boolean_Aspects |
| 1398 |
| Library_Unit_Aspects |
| 1399 |
=> |
| 1400 |
-- Aspects Export and Import require special handling. |
| 1401 |
-- Both are by definition Boolean and may benefit from |
| 1402 |
-- forward references, however their expressions are |
| 1403 |
-- treated as static. In addition, the syntax of their |
| 1404 |
-- corresponding pragmas requires extra "pieces" which |
| 1405 |
-- may also contain forward references. To account for |
| 1406 |
-- all of this, the corresponding pragma is created by |
| 1407 |
-- Analyze_Aspect_Export_Import, but is not analyzed as |
| 1408 |
-- the complete analysis must happen now. |
| 1409 |
|
| 1410 |
-- Aspect Full_Access_Only must be analyzed last so that |
| 1411 |
-- aspects Volatile and Atomic, if any, are analyzed. |
| 1412 |
|
| 1413 |
-- Skip creation of pragma Preelaborable_Initialization |
| 1414 |
-- in the case where the aspect has an expression, |
| 1415 |
-- because the pragma is only needed for setting flag |
| 1416 |
-- Known_To_Have_Preelab_Init, which is set by other |
| 1417 |
-- means following resolution of the aspect expression. |
| 1418 |
|
| 1419 |
if A_Id not in Aspect_Export |
| 1420 |
| Aspect_Full_Access_Only |
| 1421 |
| Aspect_Import |
| 1422 |
and then (A_Id /= Aspect_Preelaborable_Initialization |
| 1423 |
or else No (Expression (ASN))) |
| 1424 |
then |
| 1425 |
Make_Pragma_From_Boolean_Aspect (ASN); |
| 1426 |
end if; |
| 1427 |
|
| 1428 |
-- Special handling for aspects that don't correspond to |
| 1429 |
-- pragmas/attributes. |
| 1430 |
|
| 1431 |
when Aspect_Default_Value |
| 1432 |
| Aspect_Default_Component_Value |
| 1433 |
=> |
| 1434 |
-- Do not inherit aspect for anonymous base type of a |
| 1435 |
-- scalar or array type, because they apply to the first |
| 1436 |
-- subtype of the type, and will be processed when that |
| 1437 |
-- first subtype is frozen. |
| 1438 |
|
| 1439 |
if Is_Derived_Type (E) |
| 1440 |
and then not Comes_From_Source (E) |
| 1441 |
and then E /= First_Subtype (E) |
| 1442 |
then |
| 1443 |
null; |
| 1444 |
else |
| 1445 |
Analyze_Aspect_Default_Value (ASN); |
| 1446 |
end if; |
| 1447 |
|
| 1448 |
-- Ditto for iterator aspects, because the corresponding |
| 1449 |
-- attributes may not have been analyzed yet. |
| 1450 |
|
| 1451 |
when Aspect_Constant_Indexing |
| 1452 |
| Aspect_Default_Iterator |
| 1453 |
| Aspect_Iterator_Element |
| 1454 |
| Aspect_Variable_Indexing |
| 1455 |
=> |
| 1456 |
Analyze (Expression (ASN)); |
| 1457 |
|
| 1458 |
if Etype (Expression (ASN)) = Any_Type then |
| 1459 |
Error_Msg_NE |
| 1460 |
("aspect must be fully defined before & is frozen", |
| 1461 |
ASN, E); |
| 1462 |
|
| 1463 |
elsif A_Id in Aspect_Constant_Indexing |
| 1464 |
| Aspect_Variable_Indexing |
| 1465 |
then |
| 1466 |
Check_Indexing_Functions (ASN); |
| 1467 |
end if; |
| 1468 |
|
| 1469 |
when Aspect_Integer_Literal |
| 1470 |
| Aspect_Real_Literal |
| 1471 |
| Aspect_String_Literal |
| 1472 |
=> |
| 1473 |
Validate_Literal_Aspect (E, ASN); |
| 1474 |
|
| 1475 |
when Aspect_Iterable => |
| 1476 |
Validate_Iterable_Aspect (E, ASN); |
| 1477 |
|
| 1478 |
when Aspect_Designated_Storage_Model => |
| 1479 |
Analyze_And_Resolve (Expression (ASN)); |
| 1480 |
|
| 1481 |
if not Is_Entity_Name (Expression (ASN)) |
| 1482 |
or else not Is_Object (Entity (Expression (ASN))) |
| 1483 |
or else |
| 1484 |
No (Find_Aspect (Etype (Expression (ASN)), |
| 1485 |
Aspect_Storage_Model_Type)) |
| 1486 |
then |
| 1487 |
Error_Msg_N |
| 1488 |
("must specify name of stand-alone object of type " |
| 1489 |
& "with aspect Storage_Model_Type", |
| 1490 |
Expression (ASN)); |
| 1491 |
|
| 1492 |
-- Set access type's Associated_Storage_Pool to denote |
| 1493 |
-- the Storage_Model_Type object given for the aspect |
| 1494 |
-- (even though that isn't actually an Ada storage pool). |
| 1495 |
|
| 1496 |
else |
| 1497 |
Set_Associated_Storage_Pool |
| 1498 |
(E, Entity (Expression (ASN))); |
| 1499 |
end if; |
| 1500 |
|
| 1501 |
when Aspect_Storage_Model_Type => |
| 1502 |
Validate_Storage_Model_Type_Aspect (E, ASN); |
| 1503 |
|
| 1504 |
when Aspect_Aggregate => |
| 1505 |
if Is_Array_Type (E) then |
| 1506 |
Error_Msg_N |
| 1507 |
("aspect Aggregate may not be applied to array type", |
| 1508 |
ASN); |
| 1509 |
end if; |
| 1510 |
|
| 1511 |
-- Inherited nonoverridable aspect: analysis will |
| 1512 |
-- verify that it is consistent. |
| 1513 |
|
| 1514 |
-- If the aspect is not Comes_From_Source, then it's |
| 1515 |
-- an inherited aspect, in which case the aspect's |
| 1516 |
-- operations have already been set and there's no need |
| 1517 |
-- to resolve it. |
| 1518 |
|
| 1519 |
-- Does this test of Is_Derived_Type make sense here, |
| 1520 |
-- and is the call to Resolve_Aspect_Aggregate even |
| 1521 |
-- needed here??? (It's called other places.) |
| 1522 |
|
| 1523 |
if Is_Derived_Type (E) |
| 1524 |
and then Comes_From_Source (ASN) |
| 1525 |
then |
| 1526 |
Resolve_Aspect_Aggregate (E, Expression (ASN)); |
| 1527 |
end if; |
| 1528 |
|
| 1529 |
when Aspect_Finalizable => |
| 1530 |
Validate_Finalizable_Aspect (E, ASN); |
| 1531 |
|
| 1532 |
when others => |
| 1533 |
null; |
| 1534 |
end case; |
| 1535 |
|
| 1536 |
Ritem := Aspect_Rep_Item (ASN); |
| 1537 |
|
| 1538 |
if Present (Ritem) then |
| 1539 |
Analyze (Ritem); |
| 1540 |
end if; |
| 1541 |
end if; |
| 1542 |
end if; |
| 1543 |
|
| 1544 |
<<Skip_Aspect>> |
| 1545 |
Next_Rep_Item (ASN); |
| 1546 |
end loop; |
| 1547 |
|
| 1548 |
if not Nonoverridable_Only then |
| 1549 |
-- Make a second pass for a Full_Access_Only entry, see above why |
| 1550 |
|
| 1551 |
ASN := First_Rep_Item (E); |
| 1552 |
while Present (ASN) loop |
| 1553 |
if Nkind (ASN) = N_Aspect_Specification then |
| 1554 |
exit when Entity (ASN) /= E; |
| 1555 |
|
| 1556 |
if Get_Aspect_Id (ASN) = Aspect_Full_Access_Only then |
| 1557 |
Make_Pragma_From_Boolean_Aspect (ASN); |
| 1558 |
Ritem := Aspect_Rep_Item (ASN); |
| 1559 |
if Present (Ritem) then |
| 1560 |
Analyze (Ritem); |
| 1561 |
end if; |
| 1562 |
end if; |
| 1563 |
end if; |
| 1564 |
|
| 1565 |
Next_Rep_Item (ASN); |
| 1566 |
end loop; |
| 1567 |
end if; |
| 1568 |
|
| 1569 |
-- Would be nice to have a comment explaining what this is about. ??? |
| 1570 |
-- Also, it's not clear whether this should be done in the case where |
| 1571 |
-- Nonoverridable_Only is True. |
| 1572 |
|
| 1573 |
if In_Instance |
| 1574 |
and then E /= Base_Type (E) |
| 1575 |
and then Is_First_Subtype (E) |
| 1576 |
then |
| 1577 |
Inherit_Rep_Item_Chain (Base_Type (E), E); |
| 1578 |
end if; |
| 1579 |
end Analyze_Aspects_At_Freeze_Point; |
| 1580 |
|
| 1581 |
----------------------------------- |
| 1582 |
-- Analyze_Aspect_Specifications -- |
| 1583 |
----------------------------------- |
| 1584 |
|
| 1585 |
procedure Analyze_Aspect_Specifications (N : Node_Id; E : Entity_Id) is |
| 1586 |
pragma Assert (Present (E)); |
| 1587 |
|
| 1588 |
procedure Decorate (Asp : Node_Id; Prag : Node_Id); |
| 1589 |
-- Establish linkages between an aspect and its corresponding pragma |
| 1590 |
|
| 1591 |
procedure Insert_Pragma |
| 1592 |
(Prag : Node_Id; |
| 1593 |
Is_Instance : Boolean := False); |
| 1594 |
-- Subsidiary to the analysis of aspects |
| 1595 |
-- Abstract_State |
| 1596 |
-- Always_Terminates |
| 1597 |
-- Attach_Handler |
| 1598 |
-- Async_Readers |
| 1599 |
-- Async_Writers |
| 1600 |
-- Constant_After_Elaboration |
| 1601 |
-- Contract_Cases |
| 1602 |
-- Convention |
| 1603 |
-- Default_Initial_Condition |
| 1604 |
-- Default_Storage_Pool |
| 1605 |
-- Depends |
| 1606 |
-- Effective_Reads |
| 1607 |
-- Effective_Writes |
| 1608 |
-- Exceptional_Cases |
| 1609 |
-- Exit_Cases |
| 1610 |
-- Extensions_Visible |
| 1611 |
-- Ghost |
| 1612 |
-- Global |
| 1613 |
-- Initial_Condition |
| 1614 |
-- Initializes |
| 1615 |
-- Max_Entry_Queue_Length |
| 1616 |
-- Max_Queue_Length |
| 1617 |
-- No_Caching |
| 1618 |
-- Part_Of |
| 1619 |
-- Post |
| 1620 |
-- Pre |
| 1621 |
-- Refined_Depends |
| 1622 |
-- Refined_Global |
| 1623 |
-- Refined_Post |
| 1624 |
-- Refined_State |
| 1625 |
-- Side_Effects |
| 1626 |
-- SPARK_Mode |
| 1627 |
-- Secondary_Stack_Size |
| 1628 |
-- Subprogram_Variant |
| 1629 |
-- Volatile_Function |
| 1630 |
-- Warnings |
| 1631 |
-- Insert pragma Prag such that it mimics the placement of a source |
| 1632 |
-- pragma of the same kind. Flag Is_Generic should be set when the |
| 1633 |
-- context denotes a generic instance. |
| 1634 |
|
| 1635 |
function Relocate_Expression (Source : Node_Id) return Node_Id; |
| 1636 |
-- Outside of a generic this function is equivalent to Relocate_Node. |
| 1637 |
-- Inside a generic it is an identity function, because Relocate_Node |
| 1638 |
-- would create a new node that is not associated with the generic |
| 1639 |
-- template. This association is needed to save references to entities |
| 1640 |
-- that are global to the generic (and might be not visible from where |
| 1641 |
-- the generic is instantiated). |
| 1642 |
-- |
| 1643 |
-- Inside a generic the original tree is shared between aspect and |
| 1644 |
-- a corresponding pragma (or an attribute definition clause). This |
| 1645 |
-- parallels what is done in sem_prag.adb (see Get_Argument). |
| 1646 |
|
| 1647 |
-------------- |
| 1648 |
-- Decorate -- |
| 1649 |
-------------- |
| 1650 |
|
| 1651 |
procedure Decorate (Asp : Node_Id; Prag : Node_Id) is |
| 1652 |
begin |
| 1653 |
Set_Aspect_Rep_Item (Asp, Prag); |
| 1654 |
Set_Corresponding_Aspect (Prag, Asp); |
| 1655 |
Set_From_Aspect_Specification (Prag); |
| 1656 |
Set_Parent (Prag, Asp); |
| 1657 |
end Decorate; |
| 1658 |
|
| 1659 |
------------------- |
| 1660 |
-- Insert_Pragma -- |
| 1661 |
------------------- |
| 1662 |
|
| 1663 |
procedure Insert_Pragma |
| 1664 |
(Prag : Node_Id; |
| 1665 |
Is_Instance : Boolean := False) |
| 1666 |
is |
| 1667 |
Aux : Node_Id; |
| 1668 |
Decl : Node_Id; |
| 1669 |
Decls : List_Id; |
| 1670 |
Def : Node_Id; |
| 1671 |
Inserted : Boolean := False; |
| 1672 |
|
| 1673 |
begin |
| 1674 |
-- When the aspect appears on an entry, package, protected unit, |
| 1675 |
-- subprogram, or task unit body, insert the generated pragma at the |
| 1676 |
-- top of the body declarations to emulate the behavior of a source |
| 1677 |
-- pragma. |
| 1678 |
|
| 1679 |
-- package body Pack with Aspect is |
| 1680 |
|
| 1681 |
-- package body Pack is |
| 1682 |
-- pragma Prag; |
| 1683 |
|
| 1684 |
if Nkind (N) in N_Entry_Body |
| 1685 |
| N_Package_Body |
| 1686 |
| N_Protected_Body |
| 1687 |
| N_Subprogram_Body |
| 1688 |
| N_Task_Body |
| 1689 |
then |
| 1690 |
Decls := Declarations (N); |
| 1691 |
|
| 1692 |
if No (Decls) then |
| 1693 |
Decls := New_List; |
| 1694 |
Set_Declarations (N, Decls); |
| 1695 |
end if; |
| 1696 |
|
| 1697 |
Prepend_To (Decls, Prag); |
| 1698 |
|
| 1699 |
-- When the aspect is associated with a [generic] package declaration |
| 1700 |
-- insert the generated pragma at the top of the visible declarations |
| 1701 |
-- to emulate the behavior of a source pragma. |
| 1702 |
|
| 1703 |
-- package Pack with Aspect is |
| 1704 |
|
| 1705 |
-- package Pack is |
| 1706 |
-- pragma Prag; |
| 1707 |
|
| 1708 |
elsif Nkind (N) in N_Generic_Package_Declaration |
| 1709 |
| N_Package_Declaration |
| 1710 |
then |
| 1711 |
Decls := Visible_Declarations (Specification (N)); |
| 1712 |
|
| 1713 |
if No (Decls) then |
| 1714 |
Decls := New_List; |
| 1715 |
Set_Visible_Declarations (Specification (N), Decls); |
| 1716 |
end if; |
| 1717 |
|
| 1718 |
-- The visible declarations of a generic instance have the |
| 1719 |
-- following structure: |
| 1720 |
|
| 1721 |
-- <renamings of generic formals> |
| 1722 |
-- <renamings of internally-generated spec and body> |
| 1723 |
-- <first source declaration> |
| 1724 |
|
| 1725 |
-- Insert the pragma before the first source declaration by |
| 1726 |
-- skipping the instance "header" to ensure proper visibility of |
| 1727 |
-- all formals. |
| 1728 |
|
| 1729 |
if Is_Instance then |
| 1730 |
Decl := First (Decls); |
| 1731 |
while Present (Decl) loop |
| 1732 |
if Comes_From_Source (Decl) then |
| 1733 |
Insert_Before (Decl, Prag); |
| 1734 |
Inserted := True; |
| 1735 |
exit; |
| 1736 |
else |
| 1737 |
Next (Decl); |
| 1738 |
end if; |
| 1739 |
end loop; |
| 1740 |
|
| 1741 |
-- The pragma is placed after the instance "header" |
| 1742 |
|
| 1743 |
if not Inserted then |
| 1744 |
Append_To (Decls, Prag); |
| 1745 |
end if; |
| 1746 |
|
| 1747 |
-- Otherwise this is not a generic instance |
| 1748 |
|
| 1749 |
else |
| 1750 |
Prepend_To (Decls, Prag); |
| 1751 |
end if; |
| 1752 |
|
| 1753 |
-- When the aspect is associated with a protected unit declaration, |
| 1754 |
-- insert the generated pragma at the top of the visible declarations |
| 1755 |
-- the emulate the behavior of a source pragma. |
| 1756 |
|
| 1757 |
-- protected [type] Prot with Aspect is |
| 1758 |
|
| 1759 |
-- protected [type] Prot is |
| 1760 |
-- pragma Prag; |
| 1761 |
|
| 1762 |
elsif Nkind (N) = N_Protected_Type_Declaration then |
| 1763 |
Def := Protected_Definition (N); |
| 1764 |
|
| 1765 |
if No (Def) then |
| 1766 |
Def := |
| 1767 |
Make_Protected_Definition (Sloc (N), |
| 1768 |
Visible_Declarations => New_List, |
| 1769 |
End_Label => Empty); |
| 1770 |
|
| 1771 |
Set_Protected_Definition (N, Def); |
| 1772 |
end if; |
| 1773 |
|
| 1774 |
Decls := Visible_Declarations (Def); |
| 1775 |
|
| 1776 |
if No (Decls) then |
| 1777 |
Decls := New_List; |
| 1778 |
Set_Visible_Declarations (Def, Decls); |
| 1779 |
end if; |
| 1780 |
|
| 1781 |
Prepend_To (Decls, Prag); |
| 1782 |
|
| 1783 |
-- When the aspect is associated with a task unit declaration, insert |
| 1784 |
-- insert the generated pragma at the top of the visible declarations |
| 1785 |
-- the emulate the behavior of a source pragma. |
| 1786 |
|
| 1787 |
-- task [type] Prot with Aspect is |
| 1788 |
|
| 1789 |
-- task [type] Prot is |
| 1790 |
-- pragma Prag; |
| 1791 |
|
| 1792 |
elsif Nkind (N) = N_Task_Type_Declaration then |
| 1793 |
Def := Task_Definition (N); |
| 1794 |
|
| 1795 |
if No (Def) then |
| 1796 |
Def := |
| 1797 |
Make_Task_Definition (Sloc (N), |
| 1798 |
Visible_Declarations => New_List, |
| 1799 |
End_Label => Empty); |
| 1800 |
|
| 1801 |
Set_Task_Definition (N, Def); |
| 1802 |
end if; |
| 1803 |
|
| 1804 |
Decls := Visible_Declarations (Def); |
| 1805 |
|
| 1806 |
if No (Decls) then |
| 1807 |
Decls := New_List; |
| 1808 |
Set_Visible_Declarations (Def, Decls); |
| 1809 |
end if; |
| 1810 |
|
| 1811 |
Prepend_To (Decls, Prag); |
| 1812 |
|
| 1813 |
-- When the context is a library unit, the pragma is added to the |
| 1814 |
-- Pragmas_After list. |
| 1815 |
|
| 1816 |
elsif Nkind (Parent (N)) = N_Compilation_Unit then |
| 1817 |
Aux := Aux_Decls_Node (Parent (N)); |
| 1818 |
|
| 1819 |
if No (Pragmas_After (Aux)) then |
| 1820 |
Set_Pragmas_After (Aux, New_List); |
| 1821 |
end if; |
| 1822 |
|
| 1823 |
Prepend (Prag, Pragmas_After (Aux)); |
| 1824 |
|
| 1825 |
-- Default, the pragma is inserted after the context |
| 1826 |
|
| 1827 |
else |
| 1828 |
Insert_After (N, Prag); |
| 1829 |
end if; |
| 1830 |
end Insert_Pragma; |
| 1831 |
|
| 1832 |
------------------------- |
| 1833 |
-- Relocate_Expression -- |
| 1834 |
------------------------- |
| 1835 |
|
| 1836 |
function Relocate_Expression (Source : Node_Id) return Node_Id is |
| 1837 |
begin |
| 1838 |
if Inside_A_Generic then |
| 1839 |
return Source; |
| 1840 |
else |
| 1841 |
return Atree.Relocate_Node (Source); |
| 1842 |
end if; |
| 1843 |
end Relocate_Expression; |
| 1844 |
|
| 1845 |
-- Local variables |
| 1846 |
|
| 1847 |
Aspect : Node_Id; |
| 1848 |
Ent : Node_Id; |
| 1849 |
|
| 1850 |
L : constant List_Id := Aspect_Specifications (N); |
| 1851 |
|
| 1852 |
Ins_Node : Node_Id := N; |
| 1853 |
-- Insert pragmas/attribute definition clause after this node when no |
| 1854 |
-- delayed analysis is required. |
| 1855 |
|
| 1856 |
-- Start of processing for Analyze_Aspect_Specifications |
| 1857 |
|
| 1858 |
begin |
| 1859 |
-- The general processing involves building an attribute definition |
| 1860 |
-- clause or a pragma node that corresponds to the aspect. Then in order |
| 1861 |
-- to delay the evaluation of this aspect to the freeze point, we attach |
| 1862 |
-- the corresponding pragma/attribute definition clause to the aspect |
| 1863 |
-- specification node, which is then placed in the Rep Item chain. In |
| 1864 |
-- this case we mark the entity by setting the flag Has_Delayed_Aspects |
| 1865 |
-- and we evaluate the rep item at the freeze point. When the aspect |
| 1866 |
-- doesn't have a corresponding pragma/attribute definition clause, then |
| 1867 |
-- its analysis is simply delayed at the freeze point. |
| 1868 |
|
| 1869 |
-- Some special cases don't require delay analysis, thus the aspect is |
| 1870 |
-- analyzed right now. |
| 1871 |
|
| 1872 |
-- Note that there is a special handling for Pre, Post, Test_Case, |
| 1873 |
-- Contract_Cases, Always_Terminates, Exit_Cases, Exceptional_Cases and |
| 1874 |
-- Subprogram_Variant aspects. In these cases, we do not have to worry |
| 1875 |
-- about delay issues, since the pragmas themselves deal with delay of |
| 1876 |
-- visibility for the expression analysis. Thus, we just insert the |
| 1877 |
-- pragma after the node N. |
| 1878 |
|
| 1879 |
if No (L) then |
| 1880 |
return; |
| 1881 |
end if; |
| 1882 |
|
| 1883 |
-- Loop through aspects |
| 1884 |
|
| 1885 |
Aspect := First (L); |
| 1886 |
Aspect_Loop : while Present (Aspect) loop |
| 1887 |
Analyze_One_Aspect : declare |
| 1888 |
|
| 1889 |
Aspect_Exit : exception; |
| 1890 |
-- This exception is used to exit aspect processing completely. It |
| 1891 |
-- is used when an error is detected, and no further processing is |
| 1892 |
-- required. It is also used if an earlier error has left the tree |
| 1893 |
-- in a state where the aspect should not be processed. |
| 1894 |
|
| 1895 |
Expr : constant Node_Id := Expression (Aspect); |
| 1896 |
Id : constant Node_Id := Identifier (Aspect); |
| 1897 |
Loc : constant Source_Ptr := Sloc (Aspect); |
| 1898 |
Nam : constant Name_Id := Chars (Id); |
| 1899 |
A_Id : constant Aspect_Id := Get_Aspect_Id (Nam); |
| 1900 |
|
| 1901 |
Aitem : Node_Id := Empty; |
| 1902 |
-- The associated N_Pragma or N_Attribute_Definition_Clause |
| 1903 |
|
| 1904 |
Anod : Node_Id; |
| 1905 |
-- An auxiliary node |
| 1906 |
|
| 1907 |
Delay_Required : Boolean; |
| 1908 |
-- Set False if delay is not required |
| 1909 |
|
| 1910 |
Eloc : Source_Ptr := No_Location; |
| 1911 |
-- Source location of expression, modified when we split PPC's. It |
| 1912 |
-- is set below when Expr is present. |
| 1913 |
|
| 1914 |
procedure Analyze_Aspect_Convention; |
| 1915 |
-- Perform analysis of aspect Convention |
| 1916 |
|
| 1917 |
procedure Analyze_Aspect_Disable_Controlled; |
| 1918 |
-- Perform analysis of aspect Disable_Controlled |
| 1919 |
|
| 1920 |
procedure Analyze_Aspect_Export_Import; |
| 1921 |
-- Perform analysis of aspects Export or Import |
| 1922 |
|
| 1923 |
procedure Analyze_Aspect_External_Link_Name; |
| 1924 |
-- Perform analysis of aspects External_Name or Link_Name |
| 1925 |
|
| 1926 |
procedure Analyze_Aspect_Implicit_Dereference; |
| 1927 |
-- Perform analysis of the Implicit_Dereference aspects |
| 1928 |
|
| 1929 |
procedure Analyze_Aspect_Relaxed_Initialization; |
| 1930 |
-- Perform analysis of aspect Relaxed_Initialization |
| 1931 |
|
| 1932 |
procedure Analyze_Aspect_Yield; |
| 1933 |
-- Perform analysis of aspect Yield |
| 1934 |
|
| 1935 |
procedure Analyze_Aspect_Static; |
| 1936 |
-- Ada 2022 (AI12-0075): Perform analysis of aspect Static |
| 1937 |
|
| 1938 |
procedure Check_Expr_Is_OK_Static_Expression |
| 1939 |
(Expr : Node_Id; |
| 1940 |
Typ : Entity_Id := Empty); |
| 1941 |
-- Check the specified expression Expr to make sure that it is a |
| 1942 |
-- static expression of the given type (i.e. it will be analyzed |
| 1943 |
-- and resolved using this type, which can be any valid argument |
| 1944 |
-- to Resolve, e.g. Any_Integer is OK). If not, give an error |
| 1945 |
-- and raise Aspect_Exit. If Typ is left Empty, then any static |
| 1946 |
-- expression is allowed. Includes checking that the expression |
| 1947 |
-- does not raise Constraint_Error. |
| 1948 |
|
| 1949 |
function Directly_Specified |
| 1950 |
(Id : Entity_Id; A : Aspect_Id) return Boolean; |
| 1951 |
-- Returns True if the given aspect is directly (as opposed to |
| 1952 |
-- via any form of inheritance) specified for the given entity. |
| 1953 |
|
| 1954 |
function Make_Aitem_Pragma |
| 1955 |
(Pragma_Argument_Associations : List_Id; |
| 1956 |
Pragma_Name : Name_Id) return Node_Id; |
| 1957 |
-- This is a wrapper for Make_Pragma used for converting aspects |
| 1958 |
-- to pragmas. It takes care of Sloc (set from Loc) and building |
| 1959 |
-- the pragma identifier from the given name. In addition the flag |
| 1960 |
-- Class_Present is set from the aspect node, as well as |
| 1961 |
-- Is_Ignored. This routine also sets the |
| 1962 |
-- From_Aspect_Specification in the resulting pragma node to True, |
| 1963 |
-- and sets Corresponding_Aspect to point to the aspect. The |
| 1964 |
-- resulting pragma is assigned to Aitem. |
| 1965 |
|
| 1966 |
------------------------------- |
| 1967 |
-- Analyze_Aspect_Convention -- |
| 1968 |
------------------------------- |
| 1969 |
|
| 1970 |
procedure Analyze_Aspect_Convention is |
| 1971 |
Conv : Node_Id; |
| 1972 |
Dummy_1 : Node_Id; |
| 1973 |
Dummy_2 : Node_Id; |
| 1974 |
Dummy_3 : Node_Id; |
| 1975 |
Expo : Node_Id; |
| 1976 |
Imp : Node_Id; |
| 1977 |
|
| 1978 |
begin |
| 1979 |
-- Obtain all interfacing aspects that apply to the related |
| 1980 |
-- entity. |
| 1981 |
|
| 1982 |
Get_Interfacing_Aspects |
| 1983 |
(Iface_Asp => Aspect, |
| 1984 |
Conv_Asp => Dummy_1, |
| 1985 |
EN_Asp => Dummy_2, |
| 1986 |
Expo_Asp => Expo, |
| 1987 |
Imp_Asp => Imp, |
| 1988 |
LN_Asp => Dummy_3, |
| 1989 |
Do_Checks => True); |
| 1990 |
|
| 1991 |
-- The related entity is subject to aspect Export or Import. |
| 1992 |
-- Do not process Convention now because it must be analysed |
| 1993 |
-- as part of Export or Import. |
| 1994 |
|
| 1995 |
if Present (Expo) or else Present (Imp) then |
| 1996 |
return; |
| 1997 |
|
| 1998 |
-- Otherwise Convention appears by itself |
| 1999 |
|
| 2000 |
else |
| 2001 |
-- The aspect specifies a particular convention |
| 2002 |
|
| 2003 |
if Present (Expr) then |
| 2004 |
Conv := New_Copy_Tree (Expr); |
| 2005 |
|
| 2006 |
-- Otherwise assume convention Ada |
| 2007 |
|
| 2008 |
else |
| 2009 |
Conv := Make_Identifier (Loc, Name_Ada); |
| 2010 |
end if; |
| 2011 |
|
| 2012 |
-- Generate: |
| 2013 |
-- pragma Convention (<Conv>, <E>); |
| 2014 |
|
| 2015 |
Aitem := Make_Aitem_Pragma |
| 2016 |
(Pragma_Name => Name_Convention, |
| 2017 |
Pragma_Argument_Associations => New_List ( |
| 2018 |
Make_Pragma_Argument_Association (Loc, |
| 2019 |
Expression => Conv), |
| 2020 |
Make_Pragma_Argument_Association (Loc, |
| 2021 |
Expression => Ent))); |
| 2022 |
|
| 2023 |
Decorate (Aspect, Aitem); |
| 2024 |
Insert_Pragma (Aitem); |
| 2025 |
end if; |
| 2026 |
end Analyze_Aspect_Convention; |
| 2027 |
|
| 2028 |
--------------------------------------- |
| 2029 |
-- Analyze_Aspect_Disable_Controlled -- |
| 2030 |
--------------------------------------- |
| 2031 |
|
| 2032 |
procedure Analyze_Aspect_Disable_Controlled is |
| 2033 |
begin |
| 2034 |
Error_Msg_Name_1 := Nam; |
| 2035 |
|
| 2036 |
-- The aspect applies only to controlled records |
| 2037 |
|
| 2038 |
if not (Ekind (E) = E_Record_Type |
| 2039 |
and then Is_Controlled_Active (E)) |
| 2040 |
then |
| 2041 |
Error_Msg_N |
| 2042 |
("aspect % requires controlled record type", Aspect); |
| 2043 |
return; |
| 2044 |
end if; |
| 2045 |
|
| 2046 |
-- Preanalyze the expression (if any) when the aspect resides |
| 2047 |
-- in a generic unit. |
| 2048 |
|
| 2049 |
if Inside_A_Generic then |
| 2050 |
if Present (Expr) then |
| 2051 |
Preanalyze_And_Resolve (Expr, Any_Boolean); |
| 2052 |
end if; |
| 2053 |
|
| 2054 |
-- Otherwise the aspect resides in a nongeneric context |
| 2055 |
|
| 2056 |
else |
| 2057 |
-- A controlled record type loses its controlled semantics |
| 2058 |
-- when the expression statically evaluates to True. |
| 2059 |
|
| 2060 |
if Present (Expr) then |
| 2061 |
Analyze_And_Resolve (Expr, Any_Boolean); |
| 2062 |
|
| 2063 |
if Is_OK_Static_Expression (Expr) then |
| 2064 |
if Is_True (Static_Boolean (Expr)) then |
| 2065 |
Set_Disable_Controlled (E); |
| 2066 |
end if; |
| 2067 |
|
| 2068 |
-- Otherwise the expression is not static |
| 2069 |
|
| 2070 |
else |
| 2071 |
Flag_Non_Static_Expr |
| 2072 |
("expression of aspect % must be static!", Aspect); |
| 2073 |
end if; |
| 2074 |
|
| 2075 |
-- Otherwise the aspect appears without an expression and |
| 2076 |
-- defaults to True. |
| 2077 |
|
| 2078 |
else |
| 2079 |
Set_Disable_Controlled (E); |
| 2080 |
end if; |
| 2081 |
end if; |
| 2082 |
end Analyze_Aspect_Disable_Controlled; |
| 2083 |
|
| 2084 |
---------------------------------- |
| 2085 |
-- Analyze_Aspect_Export_Import -- |
| 2086 |
---------------------------------- |
| 2087 |
|
| 2088 |
procedure Analyze_Aspect_Export_Import is |
| 2089 |
Dummy_1 : Node_Id; |
| 2090 |
Dummy_2 : Node_Id; |
| 2091 |
Dummy_3 : Node_Id; |
| 2092 |
Expo : Node_Id; |
| 2093 |
Imp : Node_Id; |
| 2094 |
|
| 2095 |
begin |
| 2096 |
-- Obtain all interfacing aspects that apply to the related |
| 2097 |
-- entity. |
| 2098 |
|
| 2099 |
Get_Interfacing_Aspects |
| 2100 |
(Iface_Asp => Aspect, |
| 2101 |
Conv_Asp => Dummy_1, |
| 2102 |
EN_Asp => Dummy_2, |
| 2103 |
Expo_Asp => Expo, |
| 2104 |
Imp_Asp => Imp, |
| 2105 |
LN_Asp => Dummy_3, |
| 2106 |
Do_Checks => True); |
| 2107 |
|
| 2108 |
-- The related entity cannot be subject to both aspects Export |
| 2109 |
-- and Import. |
| 2110 |
|
| 2111 |
if Present (Expo) and then Present (Imp) then |
| 2112 |
Error_Msg_N |
| 2113 |
("incompatible interfacing aspects given for &", E); |
| 2114 |
Error_Msg_Sloc := Sloc (Expo); |
| 2115 |
Error_Msg_N ("\aspect Export #", E); |
| 2116 |
Error_Msg_Sloc := Sloc (Imp); |
| 2117 |
Error_Msg_N ("\aspect Import #", E); |
| 2118 |
end if; |
| 2119 |
|
| 2120 |
-- A variable is most likely modified from the outside. Take |
| 2121 |
-- the optimistic approach to avoid spurious errors. |
| 2122 |
|
| 2123 |
if Ekind (E) = E_Variable then |
| 2124 |
Set_Never_Set_In_Source (E, False); |
| 2125 |
end if; |
| 2126 |
|
| 2127 |
-- Resolve the expression of an Import or Export here, and |
| 2128 |
-- require it to be of type Boolean and static. This is not |
| 2129 |
-- quite right, because in general this should be delayed, |
| 2130 |
-- but that seems tricky for these, because normally Boolean |
| 2131 |
-- aspects are replaced with pragmas at the freeze point in |
| 2132 |
-- Make_Pragma_From_Boolean_Aspect. |
| 2133 |
|
| 2134 |
if No (Expr) |
| 2135 |
or else Is_True (Static_Boolean (Expr)) |
| 2136 |
then |
| 2137 |
if A_Id = Aspect_Import then |
| 2138 |
Set_Has_Completion (E); |
| 2139 |
Set_Is_Imported (E); |
| 2140 |
|
| 2141 |
-- An imported object cannot be explicitly initialized |
| 2142 |
|
| 2143 |
if Nkind (N) = N_Object_Declaration |
| 2144 |
and then Present (Expression (N)) |
| 2145 |
then |
| 2146 |
Error_Msg_Sloc := Sloc (Defining_Identifier (N)); |
| 2147 |
Error_Msg_N |
| 2148 |
("no initialization allowed for declaration of& #", |
| 2149 |
Defining_Identifier (N)); |
| 2150 |
Error_Msg_N |
| 2151 |
("imported entities cannot be initialized " |
| 2152 |
& "(RM B.1(24))", Expression (N)); |
| 2153 |
end if; |
| 2154 |
|
| 2155 |
else |
| 2156 |
pragma Assert (A_Id = Aspect_Export); |
| 2157 |
Set_Is_Exported (E); |
| 2158 |
end if; |
| 2159 |
|
| 2160 |
-- Create the proper form of pragma Export or Import taking |
| 2161 |
-- into account Conversion, External_Name, and Link_Name. |
| 2162 |
|
| 2163 |
Aitem := Build_Export_Import_Pragma (Aspect, E); |
| 2164 |
|
| 2165 |
-- Otherwise the expression is either False or erroneous. There |
| 2166 |
-- is no corresponding pragma. |
| 2167 |
|
| 2168 |
else |
| 2169 |
Aitem := Empty; |
| 2170 |
end if; |
| 2171 |
end Analyze_Aspect_Export_Import; |
| 2172 |
|
| 2173 |
--------------------------------------- |
| 2174 |
-- Analyze_Aspect_External_Link_Name -- |
| 2175 |
--------------------------------------- |
| 2176 |
|
| 2177 |
procedure Analyze_Aspect_External_Link_Name is |
| 2178 |
Dummy_1 : Node_Id; |
| 2179 |
Dummy_2 : Node_Id; |
| 2180 |
Dummy_3 : Node_Id; |
| 2181 |
Expo : Node_Id; |
| 2182 |
Imp : Node_Id; |
| 2183 |
|
| 2184 |
begin |
| 2185 |
-- Obtain all interfacing aspects that apply to the related |
| 2186 |
-- entity. |
| 2187 |
|
| 2188 |
Get_Interfacing_Aspects |
| 2189 |
(Iface_Asp => Aspect, |
| 2190 |
Conv_Asp => Dummy_1, |
| 2191 |
EN_Asp => Dummy_2, |
| 2192 |
Expo_Asp => Expo, |
| 2193 |
Imp_Asp => Imp, |
| 2194 |
LN_Asp => Dummy_3, |
| 2195 |
Do_Checks => True); |
| 2196 |
|
| 2197 |
-- Ensure that aspect External_Name applies to aspect Export or |
| 2198 |
-- Import. |
| 2199 |
|
| 2200 |
if A_Id = Aspect_External_Name then |
| 2201 |
if No (Expo) and then No (Imp) then |
| 2202 |
Error_Msg_N |
| 2203 |
("aspect External_Name requires aspect Import or " |
| 2204 |
& "Export", Aspect); |
| 2205 |
end if; |
| 2206 |
|
| 2207 |
-- Otherwise ensure that aspect Link_Name applies to aspect |
| 2208 |
-- Export or Import. |
| 2209 |
|
| 2210 |
else |
| 2211 |
pragma Assert (A_Id = Aspect_Link_Name); |
| 2212 |
if No (Expo) and then No (Imp) then |
| 2213 |
Error_Msg_N |
| 2214 |
("aspect Link_Name requires aspect Import or Export", |
| 2215 |
Aspect); |
| 2216 |
end if; |
| 2217 |
end if; |
| 2218 |
end Analyze_Aspect_External_Link_Name; |
| 2219 |
|
| 2220 |
----------------------------------------- |
| 2221 |
-- Analyze_Aspect_Implicit_Dereference -- |
| 2222 |
----------------------------------------- |
| 2223 |
|
| 2224 |
procedure Analyze_Aspect_Implicit_Dereference is |
| 2225 |
begin |
| 2226 |
if not Is_Type (E) or else not Has_Discriminants (E) then |
| 2227 |
Error_Msg_N |
| 2228 |
("aspect must apply to a type with discriminants", Expr); |
| 2229 |
|
| 2230 |
elsif not Is_First_Subtype (E) then |
| 2231 |
Error_Msg_N |
| 2232 |
("aspect not specifiable in a subtype declaration", |
| 2233 |
Aspect); |
| 2234 |
|
| 2235 |
elsif not Is_Entity_Name (Expr) then |
| 2236 |
Error_Msg_N |
| 2237 |
("aspect must name a discriminant of current type", Expr); |
| 2238 |
|
| 2239 |
else |
| 2240 |
-- Discriminant type be an anonymous access type or an |
| 2241 |
-- anonymous access to subprogram. |
| 2242 |
|
| 2243 |
-- Missing synchronized types??? |
| 2244 |
|
| 2245 |
declare |
| 2246 |
Disc : Entity_Id := First_Discriminant (E); |
| 2247 |
begin |
| 2248 |
while Present (Disc) loop |
| 2249 |
if Chars (Expr) = Chars (Disc) |
| 2250 |
and then Ekind (Etype (Disc)) in |
| 2251 |
E_Anonymous_Access_Subprogram_Type | |
| 2252 |
E_Anonymous_Access_Type |
| 2253 |
then |
| 2254 |
Set_Has_Implicit_Dereference (E); |
| 2255 |
Set_Has_Implicit_Dereference (Disc); |
| 2256 |
exit; |
| 2257 |
end if; |
| 2258 |
|
| 2259 |
Next_Discriminant (Disc); |
| 2260 |
end loop; |
| 2261 |
|
| 2262 |
-- Error if no proper access discriminant |
| 2263 |
|
| 2264 |
if Present (Disc) then |
| 2265 |
-- For a type extension, check whether parent has |
| 2266 |
-- a reference discriminant, to verify that use is |
| 2267 |
-- proper. |
| 2268 |
|
| 2269 |
if Is_Derived_Type (E) |
| 2270 |
and then Has_Discriminants (Etype (E)) |
| 2271 |
then |
| 2272 |
declare |
| 2273 |
Parent_Disc : constant Entity_Id := |
| 2274 |
Get_Reference_Discriminant (Etype (E)); |
| 2275 |
begin |
| 2276 |
if Present (Parent_Disc) |
| 2277 |
and then Corresponding_Discriminant (Disc) /= |
| 2278 |
Parent_Disc |
| 2279 |
then |
| 2280 |
Error_Msg_N |
| 2281 |
("reference discriminant does not match " |
| 2282 |
& "discriminant of parent type", Expr); |
| 2283 |
end if; |
| 2284 |
end; |
| 2285 |
end if; |
| 2286 |
|
| 2287 |
else |
| 2288 |
Error_Msg_NE |
| 2289 |
("not an access discriminant of&", Expr, E); |
| 2290 |
end if; |
| 2291 |
end; |
| 2292 |
end if; |
| 2293 |
|
| 2294 |
end Analyze_Aspect_Implicit_Dereference; |
| 2295 |
|
| 2296 |
------------------------------------------- |
| 2297 |
-- Analyze_Aspect_Relaxed_Initialization -- |
| 2298 |
------------------------------------------- |
| 2299 |
|
| 2300 |
procedure Analyze_Aspect_Relaxed_Initialization is |
| 2301 |
procedure Analyze_Relaxed_Parameter |
| 2302 |
(Subp_Id : Entity_Id; |
| 2303 |
Param : Node_Id; |
| 2304 |
Seen : in out Elist_Id); |
| 2305 |
-- Analyze parameter that appears in the expression of the |
| 2306 |
-- aspect Relaxed_Initialization. |
| 2307 |
|
| 2308 |
------------------------------- |
| 2309 |
-- Analyze_Relaxed_Parameter -- |
| 2310 |
------------------------------- |
| 2311 |
|
| 2312 |
procedure Analyze_Relaxed_Parameter |
| 2313 |
(Subp_Id : Entity_Id; |
| 2314 |
Param : Node_Id; |
| 2315 |
Seen : in out Elist_Id) |
| 2316 |
is |
| 2317 |
begin |
| 2318 |
-- Set name of the aspect for error messages |
| 2319 |
Error_Msg_Name_1 := Nam; |
| 2320 |
|
| 2321 |
-- The relaxed parameter is a formal parameter |
| 2322 |
|
| 2323 |
if Nkind (Param) in N_Identifier | N_Expanded_Name then |
| 2324 |
Analyze (Param); |
| 2325 |
|
| 2326 |
declare |
| 2327 |
Item : constant Entity_Id := Entity (Param); |
| 2328 |
begin |
| 2329 |
-- It must be a formal of the analyzed subprogram |
| 2330 |
|
| 2331 |
if Scope (Item) = Subp_Id then |
| 2332 |
|
| 2333 |
pragma Assert (Is_Formal (Item)); |
| 2334 |
|
| 2335 |
-- It must not have scalar or access type |
| 2336 |
|
| 2337 |
if Is_Elementary_Type (Etype (Item)) then |
| 2338 |
Error_Msg_N ("illegal aspect % item", Param); |
| 2339 |
Error_Msg_N |
| 2340 |
("\item must not have elementary type", Param); |
| 2341 |
end if; |
| 2342 |
|
| 2343 |
-- Detect duplicated items |
| 2344 |
|
| 2345 |
if Contains (Seen, Item) then |
| 2346 |
Error_Msg_N ("duplicate aspect % item", Param); |
| 2347 |
else |
| 2348 |
Append_New_Elmt (Item, Seen); |
| 2349 |
end if; |
| 2350 |
else |
| 2351 |
Error_Msg_N ("illegal aspect % item", Param); |
| 2352 |
end if; |
| 2353 |
end; |
| 2354 |
|
| 2355 |
-- The relaxed parameter is the function's Result attribute |
| 2356 |
|
| 2357 |
elsif Is_Attribute_Result (Param) then |
| 2358 |
Analyze (Param); |
| 2359 |
|
| 2360 |
declare |
| 2361 |
Pref : constant Node_Id := Prefix (Param); |
| 2362 |
begin |
| 2363 |
if Present (Pref) |
| 2364 |
and then |
| 2365 |
Nkind (Pref) in N_Identifier | N_Expanded_Name |
| 2366 |
and then |
| 2367 |
Entity (Pref) = Subp_Id |
| 2368 |
then |
| 2369 |
-- Function result must not have scalar or access |
| 2370 |
-- type. |
| 2371 |
|
| 2372 |
if Is_Elementary_Type (Etype (Pref)) then |
| 2373 |
Error_Msg_N ("illegal aspect % item", Param); |
| 2374 |
Error_Msg_N |
| 2375 |
("\function result must not have elementary" |
| 2376 |
& " type", Param); |
| 2377 |
end if; |
| 2378 |
|
| 2379 |
-- Detect duplicated items |
| 2380 |
|
| 2381 |
if Contains (Seen, Subp_Id) then |
| 2382 |
Error_Msg_N ("duplicate aspect % item", Param); |
| 2383 |
else |
| 2384 |
Append_New_Elmt (Entity (Pref), Seen); |
| 2385 |
end if; |
| 2386 |
|
| 2387 |
else |
| 2388 |
Error_Msg_N ("illegal aspect % item", Param); |
| 2389 |
end if; |
| 2390 |
end; |
| 2391 |
else |
| 2392 |
Error_Msg_N ("illegal aspect % item", Param); |
| 2393 |
end if; |
| 2394 |
end Analyze_Relaxed_Parameter; |
| 2395 |
|
| 2396 |
-- Local variables |
| 2397 |
|
| 2398 |
Seen : Elist_Id := No_Elist; |
| 2399 |
-- Items that appear in the relaxed initialization aspect |
| 2400 |
-- expression of a subprogram; for detecting duplicates. |
| 2401 |
|
| 2402 |
Restore_Scope : Boolean; |
| 2403 |
-- Will be set to True if we need to restore the scope table |
| 2404 |
-- after analyzing the aspect expression. |
| 2405 |
|
| 2406 |
Prev_Id : Entity_Id; |
| 2407 |
|
| 2408 |
-- Start of processing for Analyze_Aspect_Relaxed_Initialization |
| 2409 |
|
| 2410 |
begin |
| 2411 |
-- Set name of the aspect for error messages |
| 2412 |
Error_Msg_Name_1 := Nam; |
| 2413 |
|
| 2414 |
-- Annotation of a type; no aspect expression is allowed. |
| 2415 |
-- For a private type, the aspect must be attached to the |
| 2416 |
-- partial view. |
| 2417 |
-- |
| 2418 |
-- ??? Once the exact rule for this aspect is ready, we will |
| 2419 |
-- likely reject concurrent types, etc., so let's keep the code |
| 2420 |
-- for types and variable separate. |
| 2421 |
|
| 2422 |
if Is_First_Subtype (E) then |
| 2423 |
Prev_Id := Incomplete_Or_Partial_View (E); |
| 2424 |
if Present (Prev_Id) then |
| 2425 |
|
| 2426 |
-- Aspect may appear on the full view of an incomplete |
| 2427 |
-- type because the incomplete declaration cannot have |
| 2428 |
-- any aspects. |
| 2429 |
|
| 2430 |
if Ekind (Prev_Id) = E_Incomplete_Type then |
| 2431 |
null; |
| 2432 |
else |
| 2433 |
Error_Msg_N ("aspect % must apply to partial view", N); |
| 2434 |
end if; |
| 2435 |
|
| 2436 |
elsif Present (Expr) then |
| 2437 |
Error_Msg_N ("illegal aspect % expression", Expr); |
| 2438 |
end if; |
| 2439 |
|
| 2440 |
-- Annotation of a variable; no aspect expression is allowed |
| 2441 |
|
| 2442 |
elsif Ekind (E) = E_Variable then |
| 2443 |
if Present (Expr) then |
| 2444 |
Error_Msg_N ("illegal aspect % expression", Expr); |
| 2445 |
end if; |
| 2446 |
|
| 2447 |
-- Annotation of a constant; no aspect expression is allowed. |
| 2448 |
-- For a deferred constant, the aspect must be attached to the |
| 2449 |
-- partial view. |
| 2450 |
|
| 2451 |
elsif Ekind (E) = E_Constant then |
| 2452 |
if Present (Incomplete_Or_Partial_View (E)) then |
| 2453 |
Error_Msg_N |
| 2454 |
("aspect % must apply to deferred constant", N); |
| 2455 |
|
| 2456 |
elsif Present (Expr) then |
| 2457 |
Error_Msg_N ("illegal aspect % expression", Expr); |
| 2458 |
end if; |
| 2459 |
|
| 2460 |
-- Annotation of a subprogram; aspect expression is required |
| 2461 |
|
| 2462 |
elsif Is_Subprogram_Or_Entry (E) |
| 2463 |
or else Is_Generic_Subprogram (E) |
| 2464 |
then |
| 2465 |
if Present (Expr) then |
| 2466 |
|
| 2467 |
-- If we analyze subprogram body that acts as its own |
| 2468 |
-- spec, then the subprogram itself and its formals are |
| 2469 |
-- already installed; otherwise, we need to install them, |
| 2470 |
-- as they must be visible when analyzing the aspect |
| 2471 |
-- expression. |
| 2472 |
|
| 2473 |
if In_Open_Scopes (E) then |
| 2474 |
Restore_Scope := False; |
| 2475 |
else |
| 2476 |
Restore_Scope := True; |
| 2477 |
Push_Scope (E); |
| 2478 |
|
| 2479 |
-- Only formals of the subprogram itself can appear |
| 2480 |
-- in Relaxed_Initialization aspect expression, not |
| 2481 |
-- formals of the enclosing generic unit. (This is |
| 2482 |
-- different than in Precondition or Depends aspects, |
| 2483 |
-- where both kinds of formals are allowed.) |
| 2484 |
|
| 2485 |
Install_Formals (E); |
| 2486 |
end if; |
| 2487 |
|
| 2488 |
-- Aspect expression is either an aggregate with list of |
| 2489 |
-- parameters (and possibly the Result attribute for a |
| 2490 |
-- function). |
| 2491 |
|
| 2492 |
if Nkind (Expr) = N_Aggregate then |
| 2493 |
|
| 2494 |
-- Component associations in the aggregate must be a |
| 2495 |
-- parameter name followed by a static boolean |
| 2496 |
-- expression. |
| 2497 |
|
| 2498 |
if Present (Component_Associations (Expr)) then |
| 2499 |
declare |
| 2500 |
Assoc : Node_Id := |
| 2501 |
First (Component_Associations (Expr)); |
| 2502 |
begin |
| 2503 |
while Present (Assoc) loop |
| 2504 |
if List_Length (Choices (Assoc)) = 1 then |
| 2505 |
Analyze_Relaxed_Parameter |
| 2506 |
(E, First (Choices (Assoc)), Seen); |
| 2507 |
|
| 2508 |
if Inside_A_Generic then |
| 2509 |
Preanalyze_And_Resolve |
| 2510 |
(Expression (Assoc), Any_Boolean); |
| 2511 |
else |
| 2512 |
Analyze_And_Resolve |
| 2513 |
(Expression (Assoc), Any_Boolean); |
| 2514 |
end if; |
| 2515 |
|
| 2516 |
if not Is_OK_Static_Expression |
| 2517 |
(Expression (Assoc)) |
| 2518 |
then |
| 2519 |
Error_Msg_Name_1 := Nam; |
| 2520 |
Flag_Non_Static_Expr |
| 2521 |
("expression of aspect % " & |
| 2522 |
"must be static!", Aspect); |
| 2523 |
end if; |
| 2524 |
|
| 2525 |
else |
| 2526 |
Error_Msg_Name_1 := Nam; |
| 2527 |
Error_Msg_N |
| 2528 |
("illegal aspect % expression", Expr); |
| 2529 |
end if; |
| 2530 |
Next (Assoc); |
| 2531 |
end loop; |
| 2532 |
end; |
| 2533 |
end if; |
| 2534 |
|
| 2535 |
-- Expressions of the aggregate are parameter names |
| 2536 |
|
| 2537 |
if Present (Expressions (Expr)) then |
| 2538 |
declare |
| 2539 |
Param : Node_Id := First (Expressions (Expr)); |
| 2540 |
|
| 2541 |
begin |
| 2542 |
while Present (Param) loop |
| 2543 |
Analyze_Relaxed_Parameter (E, Param, Seen); |
| 2544 |
Next (Param); |
| 2545 |
end loop; |
| 2546 |
end; |
| 2547 |
end if; |
| 2548 |
|
| 2549 |
-- Mark the aggregate expression itself as analyzed; |
| 2550 |
-- its subexpressions were marked when they themselves |
| 2551 |
-- were analyzed. |
| 2552 |
|
| 2553 |
Set_Analyzed (Expr); |
| 2554 |
|
| 2555 |
-- Otherwise, it is a single name of a subprogram |
| 2556 |
-- parameter (or possibly the Result attribute for |
| 2557 |
-- a function). |
| 2558 |
|
| 2559 |
else |
| 2560 |
Analyze_Relaxed_Parameter (E, Expr, Seen); |
| 2561 |
end if; |
| 2562 |
|
| 2563 |
if Restore_Scope then |
| 2564 |
End_Scope; |
| 2565 |
end if; |
| 2566 |
else |
| 2567 |
Error_Msg_N ("missing expression for aspect %", N); |
| 2568 |
end if; |
| 2569 |
|
| 2570 |
else |
| 2571 |
Error_Msg_N ("inappropriate entity for aspect %", E); |
| 2572 |
end if; |
| 2573 |
end Analyze_Aspect_Relaxed_Initialization; |
| 2574 |
|
| 2575 |
--------------------------- |
| 2576 |
-- Analyze_Aspect_Static -- |
| 2577 |
--------------------------- |
| 2578 |
|
| 2579 |
procedure Analyze_Aspect_Static is |
| 2580 |
function Has_Convention_Intrinsic (L : List_Id) return Boolean; |
| 2581 |
-- Return True if L contains a pragma argument association |
| 2582 |
-- node representing a convention Intrinsic. |
| 2583 |
|
| 2584 |
------------------------------ |
| 2585 |
-- Has_Convention_Intrinsic -- |
| 2586 |
------------------------------ |
| 2587 |
|
| 2588 |
function Has_Convention_Intrinsic |
| 2589 |
(L : List_Id) return Boolean |
| 2590 |
is |
| 2591 |
Arg : Node_Id := First (L); |
| 2592 |
begin |
| 2593 |
while Present (Arg) loop |
| 2594 |
if Nkind (Arg) = N_Pragma_Argument_Association |
| 2595 |
and then Chars (Arg) = Name_Convention |
| 2596 |
and then Chars (Expression (Arg)) = Name_Intrinsic |
| 2597 |
then |
| 2598 |
return True; |
| 2599 |
end if; |
| 2600 |
|
| 2601 |
Next (Arg); |
| 2602 |
end loop; |
| 2603 |
|
| 2604 |
return False; |
| 2605 |
end Has_Convention_Intrinsic; |
| 2606 |
|
| 2607 |
Is_Imported_Intrinsic : Boolean; |
| 2608 |
|
| 2609 |
begin |
| 2610 |
if Ada_Version < Ada_2022 then |
| 2611 |
Error_Msg_Ada_2022_Feature ("aspect %", Loc); |
| 2612 |
return; |
| 2613 |
end if; |
| 2614 |
|
| 2615 |
Is_Imported_Intrinsic := Is_Imported (E) |
| 2616 |
and then |
| 2617 |
Has_Convention_Intrinsic |
| 2618 |
(Pragma_Argument_Associations (Import_Pragma (E))); |
| 2619 |
|
| 2620 |
-- The aspect applies only to expression functions that |
| 2621 |
-- statisfy the requirements for a static expression function |
| 2622 |
-- (such as having an expression that is predicate-static) as |
| 2623 |
-- well as Intrinsic imported functions as a -gnatX extension. |
| 2624 |
|
| 2625 |
if not Is_Expression_Function (E) |
| 2626 |
and then |
| 2627 |
not (All_Extensions_Allowed and then Is_Imported_Intrinsic) |
| 2628 |
then |
| 2629 |
if All_Extensions_Allowed then |
| 2630 |
Error_Msg_N |
| 2631 |
("aspect % requires intrinsic or expression function", |
| 2632 |
Aspect); |
| 2633 |
|
| 2634 |
elsif Is_Imported_Intrinsic then |
| 2635 |
Error_Msg_GNAT_Extension |
| 2636 |
("aspect % on intrinsic function", Loc, |
| 2637 |
Is_Core_Extension => True); |
| 2638 |
|
| 2639 |
else |
| 2640 |
Error_Msg_N |
| 2641 |
("aspect % requires expression function", Aspect); |
| 2642 |
end if; |
| 2643 |
|
| 2644 |
return; |
| 2645 |
|
| 2646 |
-- Ada 2022 (AI12-0075): Check that the function satisfies |
| 2647 |
-- several requirements of static functions as specified in |
| 2648 |
-- RM 6.8(5.1-5.8). Note that some of the requirements given |
| 2649 |
-- there are checked elsewhere. |
| 2650 |
|
| 2651 |
else |
| 2652 |
-- The expression of the expression function must be a |
| 2653 |
-- potentially static expression (RM 2022 6.8(3.2-3.4)). |
| 2654 |
-- That's checked in Sem_Ch6.Analyze_Expression_Function. |
| 2655 |
|
| 2656 |
-- The function must not contain any calls to itself, which |
| 2657 |
-- is checked in Sem_Res.Resolve_Call. |
| 2658 |
|
| 2659 |
-- Each formal must be of mode in and have a static subtype |
| 2660 |
|
| 2661 |
declare |
| 2662 |
Formal : Entity_Id := First_Formal (E); |
| 2663 |
begin |
| 2664 |
while Present (Formal) loop |
| 2665 |
if Ekind (Formal) /= E_In_Parameter then |
| 2666 |
Error_Msg_N |
| 2667 |
("aspect % requires formals of mode IN", |
| 2668 |
Aspect); |
| 2669 |
|
| 2670 |
return; |
| 2671 |
end if; |
| 2672 |
|
| 2673 |
if not Is_Static_Subtype (Etype (Formal)) then |
| 2674 |
Error_Msg_N |
| 2675 |
("aspect % requires formals with static subtypes", |
| 2676 |
Aspect); |
| 2677 |
|
| 2678 |
return; |
| 2679 |
end if; |
| 2680 |
|
| 2681 |
Next_Formal (Formal); |
| 2682 |
end loop; |
| 2683 |
end; |
| 2684 |
|
| 2685 |
-- The function's result subtype must be a static subtype |
| 2686 |
|
| 2687 |
if not Is_Static_Subtype (Etype (E)) then |
| 2688 |
Error_Msg_N |
| 2689 |
("aspect % requires function with result of " |
| 2690 |
& "a static subtype", |
| 2691 |
Aspect); |
| 2692 |
|
| 2693 |
return; |
| 2694 |
end if; |
| 2695 |
|
| 2696 |
-- Check that the function does not have any applicable |
| 2697 |
-- precondition or postcondition expression. |
| 2698 |
|
| 2699 |
for Asp in Pre_Post_Aspects loop |
| 2700 |
if Has_Aspect (E, Asp) then |
| 2701 |
Error_Msg_Name_1 := Aspect_Names (Asp); |
| 2702 |
Error_Msg_N |
| 2703 |
("aspect % is not allowed for a static " |
| 2704 |
& "expression function", |
| 2705 |
Find_Aspect (E, Asp)); |
| 2706 |
|
| 2707 |
return; |
| 2708 |
end if; |
| 2709 |
end loop; |
| 2710 |
|
| 2711 |
-- ??? Must check that "for result type R, if the |
| 2712 |
-- function is a boundary entity for type R (see 7.3.2), |
| 2713 |
-- no type invariant applies to type R; if R has a |
| 2714 |
-- component type C, a similar rule applies to C." |
| 2715 |
end if; |
| 2716 |
|
| 2717 |
-- When the expression is present, it must be static. If it |
| 2718 |
-- evaluates to True, the expression function is treated as |
| 2719 |
-- a static function. Otherwise the aspect appears without |
| 2720 |
-- an expression and defaults to True. |
| 2721 |
|
| 2722 |
if Present (Expr) then |
| 2723 |
-- Preanalyze the expression when the aspect resides in a |
| 2724 |
-- generic unit. (Is this generic-related code necessary |
| 2725 |
-- for this aspect? It's modeled on what's done for aspect |
| 2726 |
-- Disable_Controlled. ???) |
| 2727 |
|
| 2728 |
if Inside_A_Generic then |
| 2729 |
Preanalyze_And_Resolve (Expr, Any_Boolean); |
| 2730 |
|
| 2731 |
-- Otherwise the aspect resides in a nongeneric context |
| 2732 |
|
| 2733 |
else |
| 2734 |
Analyze_And_Resolve (Expr, Any_Boolean); |
| 2735 |
|
| 2736 |
-- Error if the boolean expression is not static |
| 2737 |
|
| 2738 |
if not Is_OK_Static_Expression (Expr) then |
| 2739 |
Flag_Non_Static_Expr |
| 2740 |
("expression of aspect % must be static!", Aspect); |
| 2741 |
end if; |
| 2742 |
end if; |
| 2743 |
end if; |
| 2744 |
end Analyze_Aspect_Static; |
| 2745 |
|
| 2746 |
-------------------------- |
| 2747 |
-- Analyze_Aspect_Yield -- |
| 2748 |
-------------------------- |
| 2749 |
|
| 2750 |
procedure Analyze_Aspect_Yield is |
| 2751 |
Expr_Value : Boolean := False; |
| 2752 |
|
| 2753 |
begin |
| 2754 |
-- Check valid entity for 'Yield |
| 2755 |
|
| 2756 |
if (Is_Subprogram (E) |
| 2757 |
or else Is_Generic_Subprogram (E) |
| 2758 |
or else Is_Entry (E)) |
| 2759 |
and then not Within_Protected_Type (E) |
| 2760 |
then |
| 2761 |
null; |
| 2762 |
|
| 2763 |
elsif Within_Protected_Type (E) then |
| 2764 |
Error_Msg_N |
| 2765 |
("aspect% not applicable to protected operation", Id); |
| 2766 |
return; |
| 2767 |
|
| 2768 |
else |
| 2769 |
Error_Msg_N |
| 2770 |
("aspect% only applicable to subprogram and entry " |
| 2771 |
& "declarations", Id); |
| 2772 |
return; |
| 2773 |
end if; |
| 2774 |
|
| 2775 |
-- Evaluate its static expression (if available); otherwise it |
| 2776 |
-- defaults to True. |
| 2777 |
|
| 2778 |
if No (Expr) then |
| 2779 |
Expr_Value := True; |
| 2780 |
|
| 2781 |
-- Otherwise it must have a static boolean expression |
| 2782 |
|
| 2783 |
else |
| 2784 |
if Inside_A_Generic then |
| 2785 |
Preanalyze_And_Resolve (Expr, Any_Boolean); |
| 2786 |
else |
| 2787 |
Analyze_And_Resolve (Expr, Any_Boolean); |
| 2788 |
end if; |
| 2789 |
|
| 2790 |
if Is_OK_Static_Expression (Expr) then |
| 2791 |
if Is_True (Static_Boolean (Expr)) then |
| 2792 |
Expr_Value := True; |
| 2793 |
end if; |
| 2794 |
else |
| 2795 |
Flag_Non_Static_Expr |
| 2796 |
("expression of aspect % must be static!", Aspect); |
| 2797 |
end if; |
| 2798 |
end if; |
| 2799 |
|
| 2800 |
if Expr_Value then |
| 2801 |
Set_Has_Yield_Aspect (E); |
| 2802 |
end if; |
| 2803 |
|
| 2804 |
-- If the Yield aspect is specified for a dispatching |
| 2805 |
-- subprogram that inherits the aspect, the specified |
| 2806 |
-- value shall be confirming. |
| 2807 |
|
| 2808 |
if Present (Expr) |
| 2809 |
and then Is_Dispatching_Operation (E) |
| 2810 |
and then Present (Overridden_Operation (E)) |
| 2811 |
and then Has_Yield_Aspect (Overridden_Operation (E)) |
| 2812 |
/= Is_True (Static_Boolean (Expr)) |
| 2813 |
then |
| 2814 |
Error_Msg_N ("specification of inherited aspect% can only " & |
| 2815 |
"confirm parent value", Id); |
| 2816 |
end if; |
| 2817 |
end Analyze_Aspect_Yield; |
| 2818 |
|
| 2819 |
---------------------------------------- |
| 2820 |
-- Check_Expr_Is_OK_Static_Expression -- |
| 2821 |
---------------------------------------- |
| 2822 |
|
| 2823 |
procedure Check_Expr_Is_OK_Static_Expression |
| 2824 |
(Expr : Node_Id; Typ : Entity_Id := Empty) is |
| 2825 |
begin |
| 2826 |
case Is_OK_Static_Expression_Of_Type (Expr, Typ) is |
| 2827 |
when Static => |
| 2828 |
null; |
| 2829 |
|
| 2830 |
when Not_Static => |
| 2831 |
Error_Msg_Name_1 := Nam; |
| 2832 |
Flag_Non_Static_Expr |
| 2833 |
("entity for aspect% must be a static expression!", |
| 2834 |
Expr); |
| 2835 |
raise Aspect_Exit; |
| 2836 |
|
| 2837 |
when Invalid => |
| 2838 |
raise Aspect_Exit; |
| 2839 |
end case; |
| 2840 |
end Check_Expr_Is_OK_Static_Expression; |
| 2841 |
|
| 2842 |
------------------------ |
| 2843 |
-- Directly_Specified -- |
| 2844 |
------------------------ |
| 2845 |
|
| 2846 |
function Directly_Specified |
| 2847 |
(Id : Entity_Id; A : Aspect_Id) return Boolean |
| 2848 |
is |
| 2849 |
Aspect_Spec : constant Node_Id := Find_Aspect (Id, A); |
| 2850 |
begin |
| 2851 |
return Present (Aspect_Spec) and then Entity (Aspect_Spec) = Id; |
| 2852 |
end Directly_Specified; |
| 2853 |
|
| 2854 |
----------------------- |
| 2855 |
-- Make_Aitem_Pragma -- |
| 2856 |
----------------------- |
| 2857 |
|
| 2858 |
function Make_Aitem_Pragma |
| 2859 |
(Pragma_Argument_Associations : List_Id; |
| 2860 |
Pragma_Name : Name_Id) return Node_Id |
| 2861 |
is |
| 2862 |
Args : List_Id := Pragma_Argument_Associations; |
| 2863 |
Aitem : Node_Id; |
| 2864 |
|
| 2865 |
begin |
| 2866 |
-- We should never get here if aspect was disabled |
| 2867 |
|
| 2868 |
pragma Assert (not Is_Disabled (Aspect)); |
| 2869 |
|
| 2870 |
-- Certain aspects allow for an optional name or expression. Do |
| 2871 |
-- not generate a pragma with empty argument association list. |
| 2872 |
|
| 2873 |
if No (Args) or else No (Expression (First (Args))) then |
| 2874 |
Args := No_List; |
| 2875 |
end if; |
| 2876 |
|
| 2877 |
-- Build the pragma |
| 2878 |
|
| 2879 |
Aitem := |
| 2880 |
Make_Pragma (Loc, |
| 2881 |
Pragma_Argument_Associations => Args, |
| 2882 |
Pragma_Identifier => |
| 2883 |
Make_Identifier (Sloc (Id), Pragma_Name), |
| 2884 |
Class_Present => Class_Present (Aspect)); |
| 2885 |
|
| 2886 |
-- Set additional semantic fields |
| 2887 |
|
| 2888 |
if Is_Ignored (Aspect) then |
| 2889 |
Set_Is_Ignored (Aitem); |
| 2890 |
elsif Is_Checked (Aspect) then |
| 2891 |
Set_Is_Checked (Aitem); |
| 2892 |
end if; |
| 2893 |
|
| 2894 |
Set_Corresponding_Aspect (Aitem, Aspect); |
| 2895 |
Set_From_Aspect_Specification (Aitem); |
| 2896 |
|
| 2897 |
return Aitem; |
| 2898 |
end Make_Aitem_Pragma; |
| 2899 |
|
| 2900 |
-- Start of processing for Analyze_One_Aspect |
| 2901 |
|
| 2902 |
begin |
| 2903 |
-- Skip aspect if already analyzed, to avoid looping in some cases |
| 2904 |
|
| 2905 |
if Analyzed (Aspect) then |
| 2906 |
goto Continue; |
| 2907 |
end if; |
| 2908 |
|
| 2909 |
-- Skip looking at aspect if it is totally disabled. Just mark it |
| 2910 |
-- as such for later reference in the tree. This also sets the |
| 2911 |
-- Is_Ignored and Is_Checked flags appropriately. |
| 2912 |
|
| 2913 |
Check_Applicable_Policy (Aspect); |
| 2914 |
|
| 2915 |
if Is_Disabled (Aspect) then |
| 2916 |
goto Continue; |
| 2917 |
end if; |
| 2918 |
|
| 2919 |
-- Set the source location of expression, used in the case of |
| 2920 |
-- a failed precondition/postcondition or invariant. Note that |
| 2921 |
-- the source location of the expression is not usually the best |
| 2922 |
-- choice here. For example, it gets located on the last AND |
| 2923 |
-- keyword in a chain of boolean expressiond AND'ed together. |
| 2924 |
-- It is best to put the message on the first character of the |
| 2925 |
-- assertion, which is the effect of the First_Node call here. |
| 2926 |
|
| 2927 |
if Present (Expr) then |
| 2928 |
Eloc := Sloc (First_Node (Expr)); |
| 2929 |
end if; |
| 2930 |
|
| 2931 |
-- Check restriction No_Implementation_Aspect_Specifications |
| 2932 |
|
| 2933 |
if Implementation_Defined_Aspect (A_Id) then |
| 2934 |
Check_Restriction |
| 2935 |
(No_Implementation_Aspect_Specifications, Aspect); |
| 2936 |
end if; |
| 2937 |
|
| 2938 |
-- Check restriction No_Specification_Of_Aspect |
| 2939 |
|
| 2940 |
Check_Restriction_No_Specification_Of_Aspect (Aspect); |
| 2941 |
|
| 2942 |
-- Mark aspect analyzed (actual analysis is delayed till later) |
| 2943 |
|
| 2944 |
if A_Id /= Aspect_User_Aspect then |
| 2945 |
-- Analyzed flag is handled differently for a User_Aspect |
| 2946 |
-- aspect specification because it can also be analyzed |
| 2947 |
-- "on demand" from Aspects.Find_Aspect. So that analysis |
| 2948 |
-- tests for the case where the aspect specification has |
| 2949 |
-- already been analyzed (in which case it just returns) |
| 2950 |
-- and takes care of calling Set_Analyzed. |
| 2951 |
|
| 2952 |
Set_Analyzed (Aspect); |
| 2953 |
end if; |
| 2954 |
|
| 2955 |
Set_Entity (Aspect, E); |
| 2956 |
|
| 2957 |
-- Build the reference to E that will be used in the built pragmas |
| 2958 |
|
| 2959 |
Ent := New_Occurrence_Of (E, Sloc (Id)); |
| 2960 |
|
| 2961 |
if A_Id in Aspect_Attach_Handler | Aspect_Interrupt_Handler then |
| 2962 |
|
| 2963 |
-- Treat the specification as a reference to the protected |
| 2964 |
-- operation, which might otherwise appear unreferenced and |
| 2965 |
-- generate spurious warnings. |
| 2966 |
|
| 2967 |
Generate_Reference (E, Id); |
| 2968 |
end if; |
| 2969 |
|
| 2970 |
-- Check for duplicate aspect. Note that the Comes_From_Source |
| 2971 |
-- test allows duplicate Pre/Post's that we generate internally |
| 2972 |
-- to escape being flagged here. |
| 2973 |
|
| 2974 |
if No_Duplicates_Allowed (A_Id) then |
| 2975 |
Anod := First (L); |
| 2976 |
while Anod /= Aspect loop |
| 2977 |
if Comes_From_Source (Aspect) |
| 2978 |
and then Same_Aspect (A_Id, Get_Aspect_Id (Anod)) |
| 2979 |
then |
| 2980 |
Error_Msg_Name_1 := Nam; |
| 2981 |
Error_Msg_Sloc := Sloc (Anod); |
| 2982 |
|
| 2983 |
-- Case of same aspect specified twice |
| 2984 |
|
| 2985 |
if Class_Present (Anod) = Class_Present (Aspect) then |
| 2986 |
if not Class_Present (Anod) then |
| 2987 |
Error_Msg_NE |
| 2988 |
("aspect% for & previously given#", |
| 2989 |
Id, E); |
| 2990 |
else |
| 2991 |
Error_Msg_NE |
| 2992 |
("aspect `%''Class` for & previously given#", |
| 2993 |
Id, E); |
| 2994 |
end if; |
| 2995 |
end if; |
| 2996 |
end if; |
| 2997 |
|
| 2998 |
Next (Anod); |
| 2999 |
end loop; |
| 3000 |
end if; |
| 3001 |
|
| 3002 |
-- Check some general restrictions on language defined aspects |
| 3003 |
|
| 3004 |
if not Implementation_Defined_Aspect (A_Id) |
| 3005 |
or else A_Id in Aspect_Async_Readers |
| 3006 |
| Aspect_Async_Writers |
| 3007 |
| Aspect_Effective_Reads |
| 3008 |
| Aspect_Effective_Writes |
| 3009 |
| Aspect_Preelaborable_Initialization |
| 3010 |
then |
| 3011 |
Error_Msg_Name_1 := Nam; |
| 3012 |
|
| 3013 |
-- Not allowed for renaming declarations. Examine the original |
| 3014 |
-- node because a subprogram renaming may have been rewritten |
| 3015 |
-- as a body. |
| 3016 |
|
| 3017 |
if Nkind (Original_Node (N)) in N_Renaming_Declaration then |
| 3018 |
Error_Msg_N |
| 3019 |
("aspect % not allowed for renaming declaration", |
| 3020 |
Aspect); |
| 3021 |
end if; |
| 3022 |
|
| 3023 |
-- Not allowed for formal type declarations in previous |
| 3024 |
-- versions of the language. Allowed for them only for |
| 3025 |
-- shared variable control aspects. |
| 3026 |
|
| 3027 |
-- Original node is used in case expansion rewrote the node - |
| 3028 |
-- as is the case with generic derived types. |
| 3029 |
|
| 3030 |
if Nkind (Original_Node (N)) = N_Formal_Type_Declaration then |
| 3031 |
if Ada_Version < Ada_2022 then |
| 3032 |
Error_Msg_N |
| 3033 |
("aspect % not allowed for formal type declaration", |
| 3034 |
Aspect); |
| 3035 |
|
| 3036 |
elsif A_Id not in Aspect_Atomic |
| 3037 |
| Aspect_Volatile |
| 3038 |
| Aspect_Independent |
| 3039 |
| Aspect_Atomic_Components |
| 3040 |
| Aspect_Independent_Components |
| 3041 |
| Aspect_Volatile_Components |
| 3042 |
| Aspect_Async_Readers |
| 3043 |
| Aspect_Async_Writers |
| 3044 |
| Aspect_Effective_Reads |
| 3045 |
| Aspect_Effective_Writes |
| 3046 |
| Aspect_Preelaborable_Initialization |
| 3047 |
then |
| 3048 |
Error_Msg_N |
| 3049 |
("aspect % not allowed for formal type declaration", |
| 3050 |
Aspect); |
| 3051 |
end if; |
| 3052 |
end if; |
| 3053 |
end if; |
| 3054 |
|
| 3055 |
-- Copy expression for later processing by the procedures |
| 3056 |
-- Check_Aspect_At_[Freeze_Point | End_Of_Declarations] |
| 3057 |
|
| 3058 |
-- The expression may be a subprogram name, and can |
| 3059 |
-- be an operator name that appears as a string, but |
| 3060 |
-- requires its own analysis procedure (see sem_ch6). |
| 3061 |
|
| 3062 |
if Nkind (Expr) = N_Operator_Symbol then |
| 3063 |
Set_Expression_Copy (Aspect, Expr); |
| 3064 |
else |
| 3065 |
Set_Expression_Copy (Aspect, New_Copy_Tree (Expr)); |
| 3066 |
end if; |
| 3067 |
|
| 3068 |
-- Set Delay_Required as appropriate to aspect |
| 3069 |
|
| 3070 |
case Aspect_Delay (A_Id) is |
| 3071 |
when Always_Delay => |
| 3072 |
-- For Boolean aspects, do not delay if no expression |
| 3073 |
|
| 3074 |
if A_Id in Boolean_Aspects | Library_Unit_Aspects then |
| 3075 |
Delay_Required := Present (Expr); |
| 3076 |
else |
| 3077 |
Delay_Required := True; |
| 3078 |
end if; |
| 3079 |
|
| 3080 |
when Never_Delay => |
| 3081 |
Delay_Required := False; |
| 3082 |
|
| 3083 |
when Rep_Aspect => |
| 3084 |
|
| 3085 |
-- For Boolean aspects, do not delay if no expression except |
| 3086 |
-- for Full_Access_Only because we need to process it after |
| 3087 |
-- Volatile and Atomic, which can be independently delayed. |
| 3088 |
|
| 3089 |
if A_Id in Boolean_Aspects |
| 3090 |
and then A_Id /= Aspect_Full_Access_Only |
| 3091 |
and then No (Expr) |
| 3092 |
then |
| 3093 |
Delay_Required := False; |
| 3094 |
|
| 3095 |
-- For non-Boolean aspects, if the expression has the form |
| 3096 |
-- of an integer literal, then do not delay, since we know |
| 3097 |
-- the value cannot change. This optimization catches most |
| 3098 |
-- rep clause cases. Likewise for a string literal. |
| 3099 |
|
| 3100 |
elsif A_Id not in Boolean_Aspects |
| 3101 |
and then Present (Expr) |
| 3102 |
and then |
| 3103 |
Nkind (Expr) in N_Integer_Literal | N_String_Literal |
| 3104 |
then |
| 3105 |
Delay_Required := False; |
| 3106 |
|
| 3107 |
-- For Alignment and various Size aspects, do not delay for |
| 3108 |
-- an attribute reference whose prefix is Standard, for |
| 3109 |
-- example Standard'Maximum_Alignment or Standard'Word_Size. |
| 3110 |
|
| 3111 |
elsif A_Id in Aspect_Alignment |
| 3112 |
| Aspect_Component_Size |
| 3113 |
| Aspect_Object_Size |
| 3114 |
| Aspect_Size |
| 3115 |
| Aspect_Value_Size |
| 3116 |
and then Present (Expr) |
| 3117 |
and then Nkind (Expr) = N_Attribute_Reference |
| 3118 |
and then Nkind (Prefix (Expr)) = N_Identifier |
| 3119 |
and then Chars (Prefix (Expr)) = Name_Standard |
| 3120 |
then |
| 3121 |
Delay_Required := False; |
| 3122 |
|
| 3123 |
-- All other cases are delayed |
| 3124 |
|
| 3125 |
else |
| 3126 |
Delay_Required := True; |
| 3127 |
Set_Has_Delayed_Rep_Aspects (E); |
| 3128 |
end if; |
| 3129 |
end case; |
| 3130 |
|
| 3131 |
-- Check 13.1(9.2/5): A representation aspect of a subtype or type |
| 3132 |
-- shall not be specified (whether by a representation item or an |
| 3133 |
-- aspect_specification) before the type is completely defined |
| 3134 |
-- (see 3.11.1). |
| 3135 |
|
| 3136 |
if Is_Representation_Aspect (A_Id) |
| 3137 |
and then Rep_Item_Too_Early (E, N) |
| 3138 |
then |
| 3139 |
goto Continue; |
| 3140 |
end if; |
| 3141 |
|
| 3142 |
-- Processing based on specific aspect |
| 3143 |
|
| 3144 |
case A_Id is |
| 3145 |
when Aspect_Unimplemented => |
| 3146 |
null; -- ??? temp for now |
| 3147 |
|
| 3148 |
-- No_Aspect should be impossible |
| 3149 |
|
| 3150 |
when No_Aspect => |
| 3151 |
raise Program_Error; |
| 3152 |
|
| 3153 |
-- Case 1: Aspects corresponding to attribute definition |
| 3154 |
-- clauses. |
| 3155 |
|
| 3156 |
when Aspect_Address |
| 3157 |
| Aspect_Alignment |
| 3158 |
| Aspect_Bit_Order |
| 3159 |
| Aspect_Component_Size |
| 3160 |
| Aspect_Constant_Indexing |
| 3161 |
| Aspect_Default_Iterator |
| 3162 |
| Aspect_Dispatching_Domain |
| 3163 |
| Aspect_External_Tag |
| 3164 |
| Aspect_Input |
| 3165 |
| Aspect_Iterable |
| 3166 |
| Aspect_Iterator_Element |
| 3167 |
| Aspect_Machine_Radix |
| 3168 |
| Aspect_Object_Size |
| 3169 |
| Aspect_Output |
| 3170 |
| Aspect_Put_Image |
| 3171 |
| Aspect_Read |
| 3172 |
| Aspect_Scalar_Storage_Order |
| 3173 |
| Aspect_Simple_Storage_Pool |
| 3174 |
| Aspect_Size |
| 3175 |
| Aspect_Small |
| 3176 |
| Aspect_Storage_Pool |
| 3177 |
| Aspect_Stream_Size |
| 3178 |
| Aspect_Value_Size |
| 3179 |
| Aspect_Variable_Indexing |
| 3180 |
| Aspect_Write |
| 3181 |
=> |
| 3182 |
-- Indexing aspects apply only to tagged type |
| 3183 |
|
| 3184 |
if A_Id in Aspect_Constant_Indexing |
| 3185 |
| Aspect_Variable_Indexing |
| 3186 |
and then not (Is_Type (E) |
| 3187 |
and then Is_Tagged_Type (E)) |
| 3188 |
then |
| 3189 |
Error_Msg_N |
| 3190 |
("indexing aspect can only apply to a tagged type", |
| 3191 |
Aspect); |
| 3192 |
goto Continue; |
| 3193 |
end if; |
| 3194 |
|
| 3195 |
-- For the case of aspect Address, we don't consider that we |
| 3196 |
-- know the entity is never set in the source, since it is |
| 3197 |
-- is likely aliasing is occurring. |
| 3198 |
|
| 3199 |
-- Note: one might think that the analysis of the resulting |
| 3200 |
-- attribute definition clause would take care of that, but |
| 3201 |
-- that's not the case since it won't be from source. |
| 3202 |
|
| 3203 |
if A_Id = Aspect_Address then |
| 3204 |
Set_Never_Set_In_Source (E, False); |
| 3205 |
end if; |
| 3206 |
|
| 3207 |
-- Correctness of the profile of a stream operation is |
| 3208 |
-- verified at the freeze point, but we must detect the |
| 3209 |
-- illegal specification of this aspect for a subtype now, |
| 3210 |
-- to prevent malformed rep_item chains. |
| 3211 |
|
| 3212 |
if A_Id in Aspect_Input |
| 3213 |
| Aspect_Output |
| 3214 |
| Aspect_Read |
| 3215 |
| Aspect_Write |
| 3216 |
then |
| 3217 |
if not Is_First_Subtype (E) then |
| 3218 |
Error_Msg_N |
| 3219 |
("local name must be a first subtype", Aspect); |
| 3220 |
goto Continue; |
| 3221 |
|
| 3222 |
-- If stream aspect applies to the class-wide type, |
| 3223 |
-- the generated attribute definition applies to the |
| 3224 |
-- class-wide type as well. |
| 3225 |
|
| 3226 |
elsif Class_Present (Aspect) then |
| 3227 |
Ent := |
| 3228 |
Make_Attribute_Reference (Loc, |
| 3229 |
Prefix => Ent, |
| 3230 |
Attribute_Name => Name_Class); |
| 3231 |
end if; |
| 3232 |
end if; |
| 3233 |
|
| 3234 |
-- Propagate the 'Size'Class aspect to the class-wide type |
| 3235 |
|
| 3236 |
if A_Id = Aspect_Size and then Class_Present (Aspect) then |
| 3237 |
Ent := |
| 3238 |
Make_Attribute_Reference (Loc, |
| 3239 |
Prefix => Ent, |
| 3240 |
Attribute_Name => Name_Class); |
| 3241 |
end if; |
| 3242 |
|
| 3243 |
-- Construct the attribute_definition_clause. The expression |
| 3244 |
-- in the aspect specification is simply shared with the |
| 3245 |
-- constructed attribute, because it will be fully analyzed |
| 3246 |
-- when the attribute is processed. |
| 3247 |
|
| 3248 |
Aitem := |
| 3249 |
Make_Attribute_Definition_Clause (Loc, |
| 3250 |
Name => Ent, |
| 3251 |
Chars => Nam, |
| 3252 |
Expression => Relocate_Expression (Expr)); |
| 3253 |
|
| 3254 |
-- If the address is specified, then we treat the entity as |
| 3255 |
-- referenced, to avoid spurious warnings. This is analogous |
| 3256 |
-- to what is done with an attribute definition clause, but |
| 3257 |
-- here we don't want to generate a reference because this |
| 3258 |
-- is the point of definition of the entity. |
| 3259 |
|
| 3260 |
if A_Id = Aspect_Address then |
| 3261 |
Set_Referenced (E); |
| 3262 |
end if; |
| 3263 |
|
| 3264 |
-- Case 2: Aspects corresponding to pragmas |
| 3265 |
|
| 3266 |
-- Case 2a: Aspects corresponding to pragmas with two |
| 3267 |
-- arguments, where the first argument is a local name |
| 3268 |
-- referring to the entity, and the second argument is the |
| 3269 |
-- aspect definition expression. |
| 3270 |
|
| 3271 |
-- Linker_Section |
| 3272 |
|
| 3273 |
when Aspect_Linker_Section => |
| 3274 |
Aitem := Make_Aitem_Pragma |
| 3275 |
(Pragma_Argument_Associations => New_List ( |
| 3276 |
Make_Pragma_Argument_Association (Loc, |
| 3277 |
Expression => Ent), |
| 3278 |
Make_Pragma_Argument_Association (Sloc (Expr), |
| 3279 |
Expression => Relocate_Node (Expr))), |
| 3280 |
Pragma_Name => Name_Linker_Section); |
| 3281 |
|
| 3282 |
-- No need to delay the processing if the entity is already |
| 3283 |
-- frozen. This should only happen for subprogram bodies. |
| 3284 |
|
| 3285 |
if Is_Frozen (E) then |
| 3286 |
pragma Assert (Nkind (N) = N_Subprogram_Body); |
| 3287 |
Delay_Required := False; |
| 3288 |
end if; |
| 3289 |
|
| 3290 |
-- Synchronization |
| 3291 |
|
| 3292 |
-- Corresponds to pragma Implemented, construct the pragma |
| 3293 |
|
| 3294 |
when Aspect_Synchronization => |
| 3295 |
Aitem := Make_Aitem_Pragma |
| 3296 |
(Pragma_Argument_Associations => New_List ( |
| 3297 |
Make_Pragma_Argument_Association (Loc, |
| 3298 |
Expression => Ent), |
| 3299 |
Make_Pragma_Argument_Association (Sloc (Expr), |
| 3300 |
Expression => Relocate_Node (Expr))), |
| 3301 |
Pragma_Name => Name_Implemented); |
| 3302 |
|
| 3303 |
-- Attach_Handler |
| 3304 |
|
| 3305 |
when Aspect_Attach_Handler => |
| 3306 |
Aitem := Make_Aitem_Pragma |
| 3307 |
(Pragma_Argument_Associations => New_List ( |
| 3308 |
Make_Pragma_Argument_Association (Sloc (Ent), |
| 3309 |
Expression => Ent), |
| 3310 |
Make_Pragma_Argument_Association (Sloc (Expr), |
| 3311 |
Expression => Relocate_Expression (Expr))), |
| 3312 |
Pragma_Name => Name_Attach_Handler); |
| 3313 |
|
| 3314 |
-- We need to insert this pragma into the tree to get proper |
| 3315 |
-- processing and to look valid from a placement viewpoint. |
| 3316 |
|
| 3317 |
Insert_Pragma (Aitem); |
| 3318 |
goto Continue; |
| 3319 |
|
| 3320 |
-- Dynamic_Predicate, Predicate, Static_Predicate |
| 3321 |
|
| 3322 |
when Aspect_Dynamic_Predicate |
| 3323 |
| Aspect_Ghost_Predicate |
| 3324 |
| Aspect_Predicate |
| 3325 |
| Aspect_Static_Predicate |
| 3326 |
=> |
| 3327 |
-- These aspects apply only to subtypes |
| 3328 |
|
| 3329 |
if not Is_Type (E) then |
| 3330 |
Error_Msg_N |
| 3331 |
("predicate can only be specified for a subtype", |
| 3332 |
Aspect); |
| 3333 |
goto Continue; |
| 3334 |
|
| 3335 |
elsif Is_Incomplete_Type (E) then |
| 3336 |
Error_Msg_N |
| 3337 |
("predicate cannot apply to incomplete view", Aspect); |
| 3338 |
|
| 3339 |
elsif Is_Generic_Type (E) then |
| 3340 |
Error_Msg_N |
| 3341 |
("predicate cannot apply to formal type", Aspect); |
| 3342 |
goto Continue; |
| 3343 |
end if; |
| 3344 |
|
| 3345 |
-- Construct the pragma (always a pragma Predicate, with |
| 3346 |
-- flags recording whether it is static/dynamic). We also |
| 3347 |
-- set flags recording this in the type itself. |
| 3348 |
|
| 3349 |
Aitem := Make_Aitem_Pragma |
| 3350 |
(Pragma_Argument_Associations => New_List ( |
| 3351 |
Make_Pragma_Argument_Association (Sloc (Ent), |
| 3352 |
Expression => Ent), |
| 3353 |
Make_Pragma_Argument_Association (Sloc (Expr), |
| 3354 |
Expression => Relocate_Expression (Expr))), |
| 3355 |
Pragma_Name => Name_Predicate); |
| 3356 |
|
| 3357 |
-- Mark type has predicates, and remember what kind of |
| 3358 |
-- aspect lead to this predicate (we need this to access |
| 3359 |
-- the right set of check policies later on). |
| 3360 |
|
| 3361 |
Set_Has_Predicates (E); |
| 3362 |
|
| 3363 |
if A_Id = Aspect_Dynamic_Predicate then |
| 3364 |
Set_Has_Dynamic_Predicate_Aspect (E); |
| 3365 |
|
| 3366 |
-- If the entity has a dynamic predicate, any inherited |
| 3367 |
-- static predicate becomes dynamic as well, and the |
| 3368 |
-- predicate function includes the conjunction of both. |
| 3369 |
|
| 3370 |
Set_Has_Static_Predicate_Aspect (E, False); |
| 3371 |
|
| 3372 |
-- Query the applicable policy since it must rely on the |
| 3373 |
-- policy applicable in the context of the declaration of |
| 3374 |
-- entity E; it cannot be done when the built pragma is |
| 3375 |
-- analyzed because it will be analyzed when E is frozen, |
| 3376 |
-- and at that point the applicable policy may differ. |
| 3377 |
-- For example: |
| 3378 |
|
| 3379 |
-- pragma Assertion_Policy (Dynamic_Predicate => Check); |
| 3380 |
-- type T is ... with Dynamic_Predicate => ... |
| 3381 |
-- pragma Assertion_Policy (Dynamic_Predicate => Ignore); |
| 3382 |
-- X : T; -- freezes T |
| 3383 |
|
| 3384 |
Set_Predicates_Ignored (E, |
| 3385 |
Policy_In_Effect (Name_Dynamic_Predicate) |
| 3386 |
= Name_Ignore); |
| 3387 |
|
| 3388 |
elsif A_Id = Aspect_Static_Predicate then |
| 3389 |
Set_Has_Static_Predicate_Aspect (E); |
| 3390 |
elsif A_Id = Aspect_Ghost_Predicate then |
| 3391 |
Set_Has_Ghost_Predicate_Aspect (E); |
| 3392 |
end if; |
| 3393 |
|
| 3394 |
-- If the type is private, indicate that its completion |
| 3395 |
-- has a freeze node, because that is the one that will |
| 3396 |
-- be visible at freeze time. |
| 3397 |
|
| 3398 |
if Is_Private_Type (E) and then Present (Full_View (E)) then |
| 3399 |
Set_Has_Predicates (Full_View (E)); |
| 3400 |
|
| 3401 |
if A_Id = Aspect_Dynamic_Predicate then |
| 3402 |
Set_Has_Dynamic_Predicate_Aspect (Full_View (E)); |
| 3403 |
elsif A_Id = Aspect_Static_Predicate then |
| 3404 |
Set_Has_Static_Predicate_Aspect (Full_View (E)); |
| 3405 |
elsif A_Id = Aspect_Ghost_Predicate then |
| 3406 |
Set_Has_Ghost_Predicate_Aspect (Full_View (E)); |
| 3407 |
end if; |
| 3408 |
|
| 3409 |
Set_Has_Delayed_Aspects (Full_View (E)); |
| 3410 |
Ensure_Freeze_Node (Full_View (E)); |
| 3411 |
|
| 3412 |
-- If there is an Underlying_Full_View, also create a |
| 3413 |
-- freeze node for that one. |
| 3414 |
|
| 3415 |
if Is_Private_Type (Full_View (E)) then |
| 3416 |
declare |
| 3417 |
U_Full : constant Entity_Id := |
| 3418 |
Underlying_Full_View (Full_View (E)); |
| 3419 |
begin |
| 3420 |
if Present (U_Full) then |
| 3421 |
Set_Has_Delayed_Aspects (U_Full); |
| 3422 |
Ensure_Freeze_Node (U_Full); |
| 3423 |
end if; |
| 3424 |
end; |
| 3425 |
end if; |
| 3426 |
end if; |
| 3427 |
|
| 3428 |
-- Predicate_Failure |
| 3429 |
|
| 3430 |
when Aspect_Predicate_Failure => |
| 3431 |
|
| 3432 |
-- This aspect applies only to subtypes |
| 3433 |
|
| 3434 |
if not Is_Type (E) then |
| 3435 |
Error_Msg_N |
| 3436 |
("predicate can only be specified for a subtype", |
| 3437 |
Aspect); |
| 3438 |
goto Continue; |
| 3439 |
|
| 3440 |
elsif Is_Incomplete_Type (E) then |
| 3441 |
Error_Msg_N |
| 3442 |
("predicate cannot apply to incomplete view", Aspect); |
| 3443 |
goto Continue; |
| 3444 |
|
| 3445 |
elsif not Has_Predicates (E) then |
| 3446 |
Error_Msg_N |
| 3447 |
("Predicate_Failure requires previous predicate" & |
| 3448 |
" specification", Aspect); |
| 3449 |
goto Continue; |
| 3450 |
|
| 3451 |
elsif not (Directly_Specified (E, Aspect_Dynamic_Predicate) |
| 3452 |
or else Directly_Specified (E, Aspect_Predicate) |
| 3453 |
or else Directly_Specified (E, Aspect_Ghost_Predicate) |
| 3454 |
or else Directly_Specified (E, Aspect_Static_Predicate)) |
| 3455 |
then |
| 3456 |
Error_Msg_N |
| 3457 |
("Predicate_Failure requires accompanying" & |
| 3458 |
" noninherited predicate specification", Aspect); |
| 3459 |
goto Continue; |
| 3460 |
end if; |
| 3461 |
|
| 3462 |
-- Construct the pragma |
| 3463 |
|
| 3464 |
Aitem := Make_Aitem_Pragma |
| 3465 |
(Pragma_Argument_Associations => New_List ( |
| 3466 |
Make_Pragma_Argument_Association (Sloc (Ent), |
| 3467 |
Expression => Ent), |
| 3468 |
Make_Pragma_Argument_Association (Sloc (Expr), |
| 3469 |
Expression => Relocate_Node (Expr))), |
| 3470 |
Pragma_Name => Name_Predicate_Failure); |
| 3471 |
|
| 3472 |
-- Case 2b: Aspects corresponding to pragmas with two |
| 3473 |
-- arguments, where the second argument is a local name |
| 3474 |
-- referring to the entity, and the first argument is the |
| 3475 |
-- aspect definition expression. |
| 3476 |
|
| 3477 |
-- Convention |
| 3478 |
|
| 3479 |
when Aspect_Convention => |
| 3480 |
Analyze_Aspect_Convention; |
| 3481 |
goto Continue; |
| 3482 |
|
| 3483 |
-- External_Name, Link_Name |
| 3484 |
|
| 3485 |
-- Only the legality checks are done during the analysis, thus |
| 3486 |
-- no delay is required. |
| 3487 |
|
| 3488 |
when Aspect_External_Name |
| 3489 |
| Aspect_Link_Name |
| 3490 |
=> |
| 3491 |
Analyze_Aspect_External_Link_Name; |
| 3492 |
goto Continue; |
| 3493 |
|
| 3494 |
-- CPU, Interrupt_Priority, Priority |
| 3495 |
|
| 3496 |
-- These three aspects can be specified for a subprogram spec |
| 3497 |
-- or body, in which case we analyze the expression and export |
| 3498 |
-- the value of the aspect. |
| 3499 |
|
| 3500 |
-- Previously, we generated an equivalent pragma for bodies |
| 3501 |
-- (note that the specs cannot contain these pragmas). The |
| 3502 |
-- pragma was inserted ahead of local declarations, rather than |
| 3503 |
-- after the body. This leads to a certain duplication between |
| 3504 |
-- the processing performed for the aspect and the pragma, but |
| 3505 |
-- given the straightforward handling required it is simpler |
| 3506 |
-- to duplicate than to translate the aspect in the spec into |
| 3507 |
-- a pragma in the declarative part of the body. |
| 3508 |
|
| 3509 |
when Aspect_CPU |
| 3510 |
| Aspect_Interrupt_Priority |
| 3511 |
| Aspect_Priority |
| 3512 |
=> |
| 3513 |
-- Verify the expression is static when Static_Priorities is |
| 3514 |
-- enabled. |
| 3515 |
|
| 3516 |
if not Is_OK_Static_Expression (Expr) then |
| 3517 |
Check_Restriction (Static_Priorities, Expr); |
| 3518 |
end if; |
| 3519 |
|
| 3520 |
if Nkind (N) in N_Subprogram_Body | N_Subprogram_Declaration |
| 3521 |
then |
| 3522 |
-- Analyze the aspect expression |
| 3523 |
|
| 3524 |
Analyze_And_Resolve (Expr, Standard_Integer); |
| 3525 |
|
| 3526 |
-- Interrupt_Priority aspect not allowed for main |
| 3527 |
-- subprograms. RM D.1 does not forbid this explicitly, |
| 3528 |
-- but RM J.15.11(6/3) does not permit pragma |
| 3529 |
-- Interrupt_Priority for subprograms. |
| 3530 |
|
| 3531 |
if A_Id = Aspect_Interrupt_Priority then |
| 3532 |
Error_Msg_N |
| 3533 |
("Interrupt_Priority aspect cannot apply to " |
| 3534 |
& "subprogram", Expr); |
| 3535 |
|
| 3536 |
-- The expression must be static |
| 3537 |
|
| 3538 |
elsif not Is_OK_Static_Expression (Expr) then |
| 3539 |
Flag_Non_Static_Expr |
| 3540 |
("aspect requires static expression!", Expr); |
| 3541 |
|
| 3542 |
-- Check whether this is the main subprogram. Issue a |
| 3543 |
-- warning only if it is obviously not a main program |
| 3544 |
-- (when it has parameters or when the subprogram is |
| 3545 |
-- within a package). |
| 3546 |
|
| 3547 |
elsif Present (Parameter_Specifications |
| 3548 |
(Specification (N))) |
| 3549 |
or else not Is_Compilation_Unit (Defining_Entity (N)) |
| 3550 |
then |
| 3551 |
-- See RM D.1(14/3) and D.16(12/3) |
| 3552 |
|
| 3553 |
Error_Msg_N |
| 3554 |
("aspect applied to subprogram other than the " |
| 3555 |
& "main subprogram has no effect??", Expr); |
| 3556 |
|
| 3557 |
-- Otherwise check in range and export the value |
| 3558 |
|
| 3559 |
-- For the CPU aspect |
| 3560 |
|
| 3561 |
elsif A_Id = Aspect_CPU then |
| 3562 |
if Is_In_Range (Expr, RTE (RE_CPU_Range)) then |
| 3563 |
|
| 3564 |
-- Value is correct so we export the value to make |
| 3565 |
-- it available at execution time. |
| 3566 |
|
| 3567 |
Set_Main_CPU |
| 3568 |
(Main_Unit, UI_To_Int (Expr_Value (Expr))); |
| 3569 |
|
| 3570 |
else |
| 3571 |
Error_Msg_N |
| 3572 |
("main subprogram 'C'P'U is out of range", Expr); |
| 3573 |
end if; |
| 3574 |
|
| 3575 |
-- For the Priority aspect |
| 3576 |
|
| 3577 |
elsif A_Id = Aspect_Priority then |
| 3578 |
if Is_In_Range (Expr, RTE (RE_Priority)) then |
| 3579 |
|
| 3580 |
-- Value is correct so we export the value to make |
| 3581 |
-- it available at execution time. |
| 3582 |
|
| 3583 |
Set_Main_Priority |
| 3584 |
(Main_Unit, UI_To_Int (Expr_Value (Expr))); |
| 3585 |
|
| 3586 |
-- Ignore pragma if Relaxed_RM_Semantics to support |
| 3587 |
-- other targets/non GNAT compilers. |
| 3588 |
|
| 3589 |
elsif not Relaxed_RM_Semantics then |
| 3590 |
Error_Msg_N |
| 3591 |
("main subprogram priority is out of range", |
| 3592 |
Expr); |
| 3593 |
end if; |
| 3594 |
end if; |
| 3595 |
|
| 3596 |
-- Load an arbitrary entity from System.Tasking.Stages |
| 3597 |
-- or System.Tasking.Restricted.Stages (depending on |
| 3598 |
-- the supported profile) to make sure that one of these |
| 3599 |
-- packages is implicitly with'ed, since we need to have |
| 3600 |
-- the tasking run time active for the pragma Priority to |
| 3601 |
-- have any effect. Previously we with'ed the package |
| 3602 |
-- System.Tasking, but this package does not trigger the |
| 3603 |
-- required initialization of the run-time library. |
| 3604 |
|
| 3605 |
if Restricted_Profile then |
| 3606 |
Discard_Node (RTE (RE_Activate_Restricted_Tasks)); |
| 3607 |
else |
| 3608 |
Discard_Node (RTE (RE_Activate_Tasks)); |
| 3609 |
end if; |
| 3610 |
|
| 3611 |
-- Handling for these aspects in subprograms is complete |
| 3612 |
|
| 3613 |
goto Continue; |
| 3614 |
|
| 3615 |
-- For task and protected types pass the aspect as an |
| 3616 |
-- attribute. |
| 3617 |
|
| 3618 |
else |
| 3619 |
Aitem := |
| 3620 |
Make_Attribute_Definition_Clause (Loc, |
| 3621 |
Name => Ent, |
| 3622 |
Chars => Nam, |
| 3623 |
Expression => Relocate_Expression (Expr)); |
| 3624 |
end if; |
| 3625 |
|
| 3626 |
-- Suppress/Unsuppress |
| 3627 |
|
| 3628 |
when Aspect_Suppress |
| 3629 |
| Aspect_Unsuppress |
| 3630 |
=> |
| 3631 |
Aitem := Make_Aitem_Pragma |
| 3632 |
(Pragma_Argument_Associations => New_List ( |
| 3633 |
Make_Pragma_Argument_Association (Loc, |
| 3634 |
Expression => Relocate_Node (Expr)), |
| 3635 |
Make_Pragma_Argument_Association (Sloc (Expr), |
| 3636 |
Expression => Ent)), |
| 3637 |
Pragma_Name => Nam); |
| 3638 |
|
| 3639 |
Delay_Required := False; |
| 3640 |
|
| 3641 |
-- Warnings |
| 3642 |
|
| 3643 |
when Aspect_Warnings => |
| 3644 |
Aitem := Make_Aitem_Pragma |
| 3645 |
(Pragma_Argument_Associations => New_List ( |
| 3646 |
Make_Pragma_Argument_Association (Sloc (Expr), |
| 3647 |
Expression => Relocate_Node (Expr)), |
| 3648 |
Make_Pragma_Argument_Association (Loc, |
| 3649 |
Expression => Ent)), |
| 3650 |
Pragma_Name => Name_Warnings); |
| 3651 |
|
| 3652 |
Decorate (Aspect, Aitem); |
| 3653 |
Insert_Pragma (Aitem); |
| 3654 |
goto Continue; |
| 3655 |
|
| 3656 |
-- Case 2c: Aspects corresponding to pragmas with three |
| 3657 |
-- arguments. |
| 3658 |
|
| 3659 |
-- Invariant aspects have a first argument that references the |
| 3660 |
-- entity, a second argument that is the expression and a third |
| 3661 |
-- argument that is an appropriate message. |
| 3662 |
|
| 3663 |
-- Invariant, Type_Invariant |
| 3664 |
|
| 3665 |
when Aspect_Invariant |
| 3666 |
| Aspect_Type_Invariant |
| 3667 |
=> |
| 3668 |
-- Analysis of the pragma will verify placement legality: |
| 3669 |
-- an invariant must apply to a private type, or appear in |
| 3670 |
-- the private part of a spec and apply to a completion. |
| 3671 |
|
| 3672 |
Aitem := Make_Aitem_Pragma |
| 3673 |
(Pragma_Argument_Associations => New_List ( |
| 3674 |
Make_Pragma_Argument_Association (Sloc (Ent), |
| 3675 |
Expression => Ent), |
| 3676 |
Make_Pragma_Argument_Association (Sloc (Expr), |
| 3677 |
Expression => Relocate_Node (Expr))), |
| 3678 |
Pragma_Name => Name_Invariant); |
| 3679 |
|
| 3680 |
-- Add message unless exception messages are suppressed |
| 3681 |
|
| 3682 |
if not Opt.Exception_Locations_Suppressed then |
| 3683 |
Append_To (Pragma_Argument_Associations (Aitem), |
| 3684 |
Make_Pragma_Argument_Association (Eloc, |
| 3685 |
Chars => Name_Message, |
| 3686 |
Expression => |
| 3687 |
Make_String_Literal (Eloc, |
| 3688 |
Strval => "failed invariant from " |
| 3689 |
& Build_Location_String (Eloc)))); |
| 3690 |
end if; |
| 3691 |
|
| 3692 |
-- For Invariant case, insert immediately after the entity |
| 3693 |
-- declaration. We do not have to worry about delay issues |
| 3694 |
-- since the pragma processing takes care of this. |
| 3695 |
|
| 3696 |
Delay_Required := False; |
| 3697 |
|
| 3698 |
-- Case 2d : Aspects that correspond to a pragma with one |
| 3699 |
-- argument. |
| 3700 |
|
| 3701 |
-- Abstract_State |
| 3702 |
|
| 3703 |
-- Aspect Abstract_State introduces implicit declarations for |
| 3704 |
-- all state abstraction entities it defines. To emulate this |
| 3705 |
-- behavior, insert the pragma at the beginning of the visible |
| 3706 |
-- declarations of the related package so that it is analyzed |
| 3707 |
-- immediately. |
| 3708 |
|
| 3709 |
when Aspect_Abstract_State => Abstract_State : declare |
| 3710 |
Context : Node_Id := N; |
| 3711 |
|
| 3712 |
begin |
| 3713 |
-- When aspect Abstract_State appears on a generic package, |
| 3714 |
-- it is propagated to the package instance. The context in |
| 3715 |
-- this case is the instance spec. |
| 3716 |
|
| 3717 |
if Nkind (Context) = N_Package_Instantiation then |
| 3718 |
Context := Instance_Spec (Context); |
| 3719 |
end if; |
| 3720 |
|
| 3721 |
if Nkind (Context) in N_Generic_Package_Declaration |
| 3722 |
| N_Package_Declaration |
| 3723 |
then |
| 3724 |
Aitem := Make_Aitem_Pragma |
| 3725 |
(Pragma_Argument_Associations => New_List ( |
| 3726 |
Make_Pragma_Argument_Association (Loc, |
| 3727 |
Expression => Relocate_Node (Expr))), |
| 3728 |
Pragma_Name => Name_Abstract_State); |
| 3729 |
|
| 3730 |
Decorate (Aspect, Aitem); |
| 3731 |
Insert_Pragma |
| 3732 |
(Prag => Aitem, |
| 3733 |
Is_Instance => |
| 3734 |
Is_Generic_Instance (Defining_Entity (Context))); |
| 3735 |
|
| 3736 |
else |
| 3737 |
Error_Msg_NE |
| 3738 |
("aspect & must apply to a package declaration", |
| 3739 |
Aspect, Id); |
| 3740 |
end if; |
| 3741 |
|
| 3742 |
goto Continue; |
| 3743 |
end Abstract_State; |
| 3744 |
|
| 3745 |
-- Aspect Default_Internal_Condition is never delayed because |
| 3746 |
-- it is equivalent to a source pragma which appears after the |
| 3747 |
-- related private type. To deal with forward references, the |
| 3748 |
-- generated pragma is stored in the rep chain of the related |
| 3749 |
-- private type as types do not carry contracts. The pragma is |
| 3750 |
-- wrapped inside of a procedure at the freeze point of the |
| 3751 |
-- private type's full view. |
| 3752 |
|
| 3753 |
-- A type entity argument is appended to facilitate inheriting |
| 3754 |
-- the aspect from parent types (see Build_DIC_Procedure_Body), |
| 3755 |
-- though that extra argument isn't documented for the pragma. |
| 3756 |
|
| 3757 |
when Aspect_Default_Initial_Condition => |
| 3758 |
Aitem := Make_Aitem_Pragma |
| 3759 |
(Pragma_Argument_Associations => New_List ( |
| 3760 |
Make_Pragma_Argument_Association (Loc, |
| 3761 |
Expression => Relocate_Node (Expr)), |
| 3762 |
Make_Pragma_Argument_Association (Sloc (Ent), |
| 3763 |
Expression => Ent)), |
| 3764 |
Pragma_Name => |
| 3765 |
Name_Default_Initial_Condition); |
| 3766 |
|
| 3767 |
Decorate (Aspect, Aitem); |
| 3768 |
Insert_Pragma (Aitem); |
| 3769 |
goto Continue; |
| 3770 |
|
| 3771 |
-- Default_Storage_Pool |
| 3772 |
|
| 3773 |
when Aspect_Default_Storage_Pool => |
| 3774 |
Aitem := Make_Aitem_Pragma |
| 3775 |
(Pragma_Argument_Associations => New_List ( |
| 3776 |
Make_Pragma_Argument_Association (Loc, |
| 3777 |
Expression => Relocate_Node (Expr))), |
| 3778 |
Pragma_Name => |
| 3779 |
Name_Default_Storage_Pool); |
| 3780 |
|
| 3781 |
Decorate (Aspect, Aitem); |
| 3782 |
Insert_Pragma (Aitem); |
| 3783 |
goto Continue; |
| 3784 |
|
| 3785 |
-- Depends |
| 3786 |
|
| 3787 |
-- Aspect Depends is never delayed because it is equivalent to |
| 3788 |
-- a source pragma which appears after the related subprogram. |
| 3789 |
-- To deal with forward references, the generated pragma is |
| 3790 |
-- stored in the contract of the related subprogram and later |
| 3791 |
-- analyzed at the end of the declarative region. See routine |
| 3792 |
-- Analyze_Depends_In_Decl_Part for details. |
| 3793 |
|
| 3794 |
when Aspect_Depends => |
| 3795 |
Aitem := Make_Aitem_Pragma |
| 3796 |
(Pragma_Argument_Associations => New_List ( |
| 3797 |
Make_Pragma_Argument_Association (Loc, |
| 3798 |
Expression => Relocate_Node (Expr))), |
| 3799 |
Pragma_Name => Name_Depends); |
| 3800 |
|
| 3801 |
Decorate (Aspect, Aitem); |
| 3802 |
Insert_Pragma (Aitem); |
| 3803 |
goto Continue; |
| 3804 |
|
| 3805 |
-- Global |
| 3806 |
|
| 3807 |
-- Aspect Global is never delayed because it is equivalent to |
| 3808 |
-- a source pragma which appears after the related subprogram. |
| 3809 |
-- To deal with forward references, the generated pragma is |
| 3810 |
-- stored in the contract of the related subprogram and later |
| 3811 |
-- analyzed at the end of the declarative region. See routine |
| 3812 |
-- Analyze_Global_In_Decl_Part for details. |
| 3813 |
|
| 3814 |
when Aspect_Global => |
| 3815 |
Aitem := Make_Aitem_Pragma |
| 3816 |
(Pragma_Argument_Associations => New_List ( |
| 3817 |
Make_Pragma_Argument_Association (Loc, |
| 3818 |
Expression => Relocate_Node (Expr))), |
| 3819 |
Pragma_Name => Name_Global); |
| 3820 |
|
| 3821 |
Decorate (Aspect, Aitem); |
| 3822 |
Insert_Pragma (Aitem); |
| 3823 |
goto Continue; |
| 3824 |
|
| 3825 |
-- Initial_Condition |
| 3826 |
|
| 3827 |
-- Aspect Initial_Condition is never delayed because it is |
| 3828 |
-- equivalent to a source pragma which appears after the |
| 3829 |
-- related package. To deal with forward references, the |
| 3830 |
-- generated pragma is stored in the contract of the related |
| 3831 |
-- package and later analyzed at the end of the declarative |
| 3832 |
-- region. See routine Analyze_Initial_Condition_In_Decl_Part |
| 3833 |
-- for details. |
| 3834 |
|
| 3835 |
when Aspect_Initial_Condition => Initial_Condition : declare |
| 3836 |
Context : Node_Id := N; |
| 3837 |
|
| 3838 |
begin |
| 3839 |
-- When aspect Initial_Condition appears on a generic |
| 3840 |
-- package, it is propagated to the package instance. The |
| 3841 |
-- context in this case is the instance spec. |
| 3842 |
|
| 3843 |
if Nkind (Context) = N_Package_Instantiation then |
| 3844 |
Context := Instance_Spec (Context); |
| 3845 |
end if; |
| 3846 |
|
| 3847 |
if Nkind (Context) in N_Generic_Package_Declaration |
| 3848 |
| N_Package_Declaration |
| 3849 |
then |
| 3850 |
Aitem := Make_Aitem_Pragma |
| 3851 |
(Pragma_Argument_Associations => New_List ( |
| 3852 |
Make_Pragma_Argument_Association (Loc, |
| 3853 |
Expression => Relocate_Node (Expr))), |
| 3854 |
Pragma_Name => |
| 3855 |
Name_Initial_Condition); |
| 3856 |
|
| 3857 |
Decorate (Aspect, Aitem); |
| 3858 |
Insert_Pragma |
| 3859 |
(Prag => Aitem, |
| 3860 |
Is_Instance => |
| 3861 |
Is_Generic_Instance (Defining_Entity (Context))); |
| 3862 |
|
| 3863 |
-- Otherwise the context is illegal |
| 3864 |
|
| 3865 |
else |
| 3866 |
Error_Msg_NE |
| 3867 |
("aspect & must apply to a package declaration", |
| 3868 |
Aspect, Id); |
| 3869 |
end if; |
| 3870 |
|
| 3871 |
goto Continue; |
| 3872 |
end Initial_Condition; |
| 3873 |
|
| 3874 |
-- Initializes |
| 3875 |
|
| 3876 |
-- Aspect Initializes is never delayed because it is equivalent |
| 3877 |
-- to a source pragma appearing after the related package. To |
| 3878 |
-- deal with forward references, the generated pragma is stored |
| 3879 |
-- in the contract of the related package and later analyzed at |
| 3880 |
-- the end of the declarative region. For details, see routine |
| 3881 |
-- Analyze_Initializes_In_Decl_Part. |
| 3882 |
|
| 3883 |
when Aspect_Initializes => Initializes : declare |
| 3884 |
Context : Node_Id := N; |
| 3885 |
|
| 3886 |
begin |
| 3887 |
-- When aspect Initializes appears on a generic package, |
| 3888 |
-- it is propagated to the package instance. The context |
| 3889 |
-- in this case is the instance spec. |
| 3890 |
|
| 3891 |
if Nkind (Context) = N_Package_Instantiation then |
| 3892 |
Context := Instance_Spec (Context); |
| 3893 |
end if; |
| 3894 |
|
| 3895 |
if Nkind (Context) in N_Generic_Package_Declaration |
| 3896 |
| N_Package_Declaration |
| 3897 |
then |
| 3898 |
Aitem := Make_Aitem_Pragma |
| 3899 |
(Pragma_Argument_Associations => New_List ( |
| 3900 |
Make_Pragma_Argument_Association (Loc, |
| 3901 |
Expression => Relocate_Node (Expr))), |
| 3902 |
Pragma_Name => Name_Initializes); |
| 3903 |
|
| 3904 |
Decorate (Aspect, Aitem); |
| 3905 |
Insert_Pragma |
| 3906 |
(Prag => Aitem, |
| 3907 |
Is_Instance => |
| 3908 |
Is_Generic_Instance (Defining_Entity (Context))); |
| 3909 |
|
| 3910 |
-- Otherwise the context is illegal |
| 3911 |
|
| 3912 |
else |
| 3913 |
Error_Msg_NE |
| 3914 |
("aspect & must apply to a package declaration", |
| 3915 |
Aspect, Id); |
| 3916 |
end if; |
| 3917 |
|
| 3918 |
goto Continue; |
| 3919 |
end Initializes; |
| 3920 |
|
| 3921 |
-- Max_Entry_Queue_Length |
| 3922 |
|
| 3923 |
when Aspect_Max_Entry_Queue_Length => |
| 3924 |
Aitem := Make_Aitem_Pragma |
| 3925 |
(Pragma_Argument_Associations => New_List ( |
| 3926 |
Make_Pragma_Argument_Association (Loc, |
| 3927 |
Expression => Relocate_Node (Expr))), |
| 3928 |
Pragma_Name => Name_Max_Entry_Queue_Length); |
| 3929 |
|
| 3930 |
Decorate (Aspect, Aitem); |
| 3931 |
Insert_Pragma (Aitem); |
| 3932 |
goto Continue; |
| 3933 |
|
| 3934 |
-- Max_Queue_Length |
| 3935 |
|
| 3936 |
when Aspect_Max_Queue_Length => |
| 3937 |
Aitem := Make_Aitem_Pragma |
| 3938 |
(Pragma_Argument_Associations => New_List ( |
| 3939 |
Make_Pragma_Argument_Association (Loc, |
| 3940 |
Expression => Relocate_Node (Expr))), |
| 3941 |
Pragma_Name => Name_Max_Queue_Length); |
| 3942 |
|
| 3943 |
Decorate (Aspect, Aitem); |
| 3944 |
Insert_Pragma (Aitem); |
| 3945 |
goto Continue; |
| 3946 |
|
| 3947 |
-- Obsolescent |
| 3948 |
|
| 3949 |
when Aspect_Obsolescent => declare |
| 3950 |
Args : List_Id; |
| 3951 |
|
| 3952 |
begin |
| 3953 |
if No (Expr) then |
| 3954 |
Args := No_List; |
| 3955 |
else |
| 3956 |
Args := New_List ( |
| 3957 |
Make_Pragma_Argument_Association (Sloc (Expr), |
| 3958 |
Expression => Relocate_Node (Expr))); |
| 3959 |
end if; |
| 3960 |
|
| 3961 |
Aitem := Make_Aitem_Pragma |
| 3962 |
(Pragma_Argument_Associations => Args, |
| 3963 |
Pragma_Name => Name_Obsolescent); |
| 3964 |
end; |
| 3965 |
|
| 3966 |
-- Part_Of |
| 3967 |
|
| 3968 |
when Aspect_Part_Of => |
| 3969 |
if Nkind (N) in N_Object_Declaration |
| 3970 |
| N_Package_Instantiation |
| 3971 |
or else Is_Single_Concurrent_Type_Declaration (N) |
| 3972 |
then |
| 3973 |
Aitem := Make_Aitem_Pragma |
| 3974 |
(Pragma_Argument_Associations => New_List ( |
| 3975 |
Make_Pragma_Argument_Association (Loc, |
| 3976 |
Expression => Relocate_Node (Expr))), |
| 3977 |
Pragma_Name => Name_Part_Of); |
| 3978 |
|
| 3979 |
Decorate (Aspect, Aitem); |
| 3980 |
Insert_Pragma (Aitem); |
| 3981 |
|
| 3982 |
else |
| 3983 |
Error_Msg_NE |
| 3984 |
("aspect & must apply to package instantiation, " |
| 3985 |
& "object, single protected type or single task type", |
| 3986 |
Aspect, Id); |
| 3987 |
end if; |
| 3988 |
|
| 3989 |
goto Continue; |
| 3990 |
|
| 3991 |
-- SPARK_Mode |
| 3992 |
|
| 3993 |
when Aspect_SPARK_Mode => |
| 3994 |
Aitem := Make_Aitem_Pragma |
| 3995 |
(Pragma_Argument_Associations => New_List ( |
| 3996 |
Make_Pragma_Argument_Association (Loc, |
| 3997 |
Expression => Relocate_Node (Expr))), |
| 3998 |
Pragma_Name => Name_SPARK_Mode); |
| 3999 |
|
| 4000 |
Decorate (Aspect, Aitem); |
| 4001 |
Insert_Pragma (Aitem); |
| 4002 |
goto Continue; |
| 4003 |
|
| 4004 |
-- Refined_Depends |
| 4005 |
|
| 4006 |
-- Aspect Refined_Depends is never delayed because it is |
| 4007 |
-- equivalent to a source pragma which appears in the |
| 4008 |
-- declarations of the related subprogram body. To deal with |
| 4009 |
-- forward references, the generated pragma is stored in the |
| 4010 |
-- contract of the related subprogram body and later analyzed |
| 4011 |
-- at the end of the declarative region. For details, see |
| 4012 |
-- routine Analyze_Refined_Depends_In_Decl_Part. |
| 4013 |
|
| 4014 |
when Aspect_Refined_Depends => |
| 4015 |
Aitem := Make_Aitem_Pragma |
| 4016 |
(Pragma_Argument_Associations => New_List ( |
| 4017 |
Make_Pragma_Argument_Association (Loc, |
| 4018 |
Expression => Relocate_Node (Expr))), |
| 4019 |
Pragma_Name => Name_Refined_Depends); |
| 4020 |
|
| 4021 |
Decorate (Aspect, Aitem); |
| 4022 |
Insert_Pragma (Aitem); |
| 4023 |
goto Continue; |
| 4024 |
|
| 4025 |
-- Refined_Global |
| 4026 |
|
| 4027 |
-- Aspect Refined_Global is never delayed because it is |
| 4028 |
-- equivalent to a source pragma which appears in the |
| 4029 |
-- declarations of the related subprogram body. To deal with |
| 4030 |
-- forward references, the generated pragma is stored in the |
| 4031 |
-- contract of the related subprogram body and later analyzed |
| 4032 |
-- at the end of the declarative region. For details, see |
| 4033 |
-- routine Analyze_Refined_Global_In_Decl_Part. |
| 4034 |
|
| 4035 |
when Aspect_Refined_Global => |
| 4036 |
Aitem := Make_Aitem_Pragma |
| 4037 |
(Pragma_Argument_Associations => New_List ( |
| 4038 |
Make_Pragma_Argument_Association (Loc, |
| 4039 |
Expression => Relocate_Node (Expr))), |
| 4040 |
Pragma_Name => Name_Refined_Global); |
| 4041 |
|
| 4042 |
Decorate (Aspect, Aitem); |
| 4043 |
Insert_Pragma (Aitem); |
| 4044 |
goto Continue; |
| 4045 |
|
| 4046 |
-- Refined_Post |
| 4047 |
|
| 4048 |
when Aspect_Refined_Post => |
| 4049 |
Aitem := Make_Aitem_Pragma |
| 4050 |
(Pragma_Argument_Associations => New_List ( |
| 4051 |
Make_Pragma_Argument_Association (Loc, |
| 4052 |
Expression => Relocate_Node (Expr))), |
| 4053 |
Pragma_Name => Name_Refined_Post); |
| 4054 |
|
| 4055 |
Decorate (Aspect, Aitem); |
| 4056 |
Insert_Pragma (Aitem); |
| 4057 |
goto Continue; |
| 4058 |
|
| 4059 |
-- Refined_State |
| 4060 |
|
| 4061 |
when Aspect_Refined_State => |
| 4062 |
|
| 4063 |
-- The corresponding pragma for Refined_State is inserted in |
| 4064 |
-- the declarations of the related package body. This action |
| 4065 |
-- synchronizes both the source and from-aspect versions of |
| 4066 |
-- the pragma. |
| 4067 |
|
| 4068 |
if Nkind (N) = N_Package_Body then |
| 4069 |
Aitem := Make_Aitem_Pragma |
| 4070 |
(Pragma_Argument_Associations => New_List ( |
| 4071 |
Make_Pragma_Argument_Association (Loc, |
| 4072 |
Expression => Relocate_Node (Expr))), |
| 4073 |
Pragma_Name => Name_Refined_State); |
| 4074 |
|
| 4075 |
Decorate (Aspect, Aitem); |
| 4076 |
Insert_Pragma (Aitem); |
| 4077 |
|
| 4078 |
-- Otherwise the context is illegal |
| 4079 |
|
| 4080 |
else |
| 4081 |
Error_Msg_NE |
| 4082 |
("aspect & must apply to a package body", Aspect, Id); |
| 4083 |
end if; |
| 4084 |
|
| 4085 |
goto Continue; |
| 4086 |
|
| 4087 |
-- Relative_Deadline |
| 4088 |
|
| 4089 |
when Aspect_Relative_Deadline => |
| 4090 |
Aitem := Make_Aitem_Pragma |
| 4091 |
(Pragma_Argument_Associations => New_List ( |
| 4092 |
Make_Pragma_Argument_Association (Loc, |
| 4093 |
Expression => Relocate_Node (Expr))), |
| 4094 |
Pragma_Name => Name_Relative_Deadline); |
| 4095 |
|
| 4096 |
-- If the aspect applies to a task, the corresponding pragma |
| 4097 |
-- must appear within its declarations, not after. |
| 4098 |
|
| 4099 |
if Nkind (N) = N_Task_Type_Declaration then |
| 4100 |
declare |
| 4101 |
Def : Node_Id; |
| 4102 |
V : List_Id; |
| 4103 |
|
| 4104 |
begin |
| 4105 |
if No (Task_Definition (N)) then |
| 4106 |
Set_Task_Definition (N, |
| 4107 |
Make_Task_Definition (Loc, |
| 4108 |
Visible_Declarations => New_List, |
| 4109 |
End_Label => Empty)); |
| 4110 |
end if; |
| 4111 |
|
| 4112 |
Def := Task_Definition (N); |
| 4113 |
V := Visible_Declarations (Def); |
| 4114 |
if not Is_Empty_List (V) then |
| 4115 |
Insert_Before (First (V), Aitem); |
| 4116 |
|
| 4117 |
else |
| 4118 |
Set_Visible_Declarations (Def, New_List (Aitem)); |
| 4119 |
end if; |
| 4120 |
|
| 4121 |
goto Continue; |
| 4122 |
end; |
| 4123 |
end if; |
| 4124 |
|
| 4125 |
-- Relaxed_Initialization |
| 4126 |
|
| 4127 |
when Aspect_Relaxed_Initialization => |
| 4128 |
Analyze_Aspect_Relaxed_Initialization; |
| 4129 |
goto Continue; |
| 4130 |
|
| 4131 |
-- Secondary_Stack_Size |
| 4132 |
|
| 4133 |
-- Aspect Secondary_Stack_Size needs to be converted into a |
| 4134 |
-- pragma for two reasons: the attribute is not analyzed until |
| 4135 |
-- after the expansion of the task type declaration and the |
| 4136 |
-- attribute does not have visibility on the discriminant. |
| 4137 |
|
| 4138 |
when Aspect_Secondary_Stack_Size => |
| 4139 |
Aitem := Make_Aitem_Pragma |
| 4140 |
(Pragma_Argument_Associations => New_List ( |
| 4141 |
Make_Pragma_Argument_Association (Loc, |
| 4142 |
Expression => Relocate_Node (Expr))), |
| 4143 |
Pragma_Name => |
| 4144 |
Name_Secondary_Stack_Size); |
| 4145 |
|
| 4146 |
Decorate (Aspect, Aitem); |
| 4147 |
Insert_Pragma (Aitem); |
| 4148 |
goto Continue; |
| 4149 |
|
| 4150 |
-- User_Aspect |
| 4151 |
|
| 4152 |
when Aspect_User_Aspect => |
| 4153 |
Analyze_User_Aspect_Aspect_Specification (Aspect); |
| 4154 |
goto Continue; |
| 4155 |
|
| 4156 |
-- Case 2e: Annotate aspect |
| 4157 |
|
| 4158 |
when Aspect_Annotate | Aspect_GNAT_Annotate => |
| 4159 |
declare |
| 4160 |
Args : List_Id; |
| 4161 |
Pargs : List_Id; |
| 4162 |
Arg : Node_Id; |
| 4163 |
|
| 4164 |
begin |
| 4165 |
-- The argument can be a single identifier |
| 4166 |
|
| 4167 |
if Nkind (Expr) = N_Identifier then |
| 4168 |
|
| 4169 |
-- One level of parens is allowed |
| 4170 |
|
| 4171 |
if Paren_Count (Expr) > 1 then |
| 4172 |
Error_Msg_F ("extra parentheses ignored", Expr); |
| 4173 |
end if; |
| 4174 |
|
| 4175 |
Set_Paren_Count (Expr, 0); |
| 4176 |
|
| 4177 |
-- Add the single item to the list |
| 4178 |
|
| 4179 |
Args := New_List (Expr); |
| 4180 |
|
| 4181 |
-- Otherwise we must have an aggregate |
| 4182 |
|
| 4183 |
elsif Nkind (Expr) = N_Aggregate then |
| 4184 |
|
| 4185 |
-- Must be positional |
| 4186 |
|
| 4187 |
if Present (Component_Associations (Expr)) then |
| 4188 |
Error_Msg_F |
| 4189 |
("purely positional aggregate required", Expr); |
| 4190 |
goto Continue; |
| 4191 |
end if; |
| 4192 |
|
| 4193 |
-- Must not be parenthesized |
| 4194 |
|
| 4195 |
if Paren_Count (Expr) /= 0 then |
| 4196 |
Error_Msg_F -- CODEFIX |
| 4197 |
("redundant parentheses", Expr); |
| 4198 |
end if; |
| 4199 |
|
| 4200 |
-- List of arguments is list of aggregate expressions |
| 4201 |
|
| 4202 |
Args := Expressions (Expr); |
| 4203 |
|
| 4204 |
-- Anything else is illegal |
| 4205 |
|
| 4206 |
else |
| 4207 |
Error_Msg_F ("wrong form for Annotate aspect", Expr); |
| 4208 |
goto Continue; |
| 4209 |
end if; |
| 4210 |
|
| 4211 |
-- Prepare pragma arguments |
| 4212 |
|
| 4213 |
Pargs := New_List; |
| 4214 |
Arg := First (Args); |
| 4215 |
while Present (Arg) loop |
| 4216 |
Append_To (Pargs, |
| 4217 |
Make_Pragma_Argument_Association (Sloc (Arg), |
| 4218 |
Expression => Relocate_Node (Arg))); |
| 4219 |
Next (Arg); |
| 4220 |
end loop; |
| 4221 |
|
| 4222 |
Append_To (Pargs, |
| 4223 |
Make_Pragma_Argument_Association (Sloc (Ent), |
| 4224 |
Chars => Name_Entity, |
| 4225 |
Expression => Ent)); |
| 4226 |
|
| 4227 |
Aitem := Make_Aitem_Pragma |
| 4228 |
(Pragma_Argument_Associations => Pargs, |
| 4229 |
Pragma_Name => Name_Annotate); |
| 4230 |
end; |
| 4231 |
|
| 4232 |
-- Case 3 : Aspects that don't correspond to pragma/attribute |
| 4233 |
-- definition clause. |
| 4234 |
|
| 4235 |
-- Case 3a: The aspects listed below don't correspond to |
| 4236 |
-- pragmas/attributes but do require delayed analysis. |
| 4237 |
|
| 4238 |
when Aspect_Default_Value | Aspect_Default_Component_Value => |
| 4239 |
Error_Msg_Name_1 := Nam; |
| 4240 |
|
| 4241 |
if not Is_Type (E) then |
| 4242 |
Error_Msg_N ("aspect% can only apply to a type", Id); |
| 4243 |
goto Continue; |
| 4244 |
|
| 4245 |
elsif not Is_First_Subtype (E) then |
| 4246 |
Error_Msg_N ("aspect% cannot apply to subtype", Id); |
| 4247 |
goto Continue; |
| 4248 |
|
| 4249 |
elsif A_Id = Aspect_Default_Value then |
| 4250 |
if not Is_Scalar_Type (E) then |
| 4251 |
Error_Msg_N |
| 4252 |
("aspect% can only be applied to scalar type", Id); |
| 4253 |
goto Continue; |
| 4254 |
end if; |
| 4255 |
|
| 4256 |
elsif A_Id = Aspect_Default_Component_Value then |
| 4257 |
if not Is_Array_Type (E) then |
| 4258 |
Error_Msg_N |
| 4259 |
("aspect% can only be applied to array type", Id); |
| 4260 |
goto Continue; |
| 4261 |
|
| 4262 |
elsif not Is_Scalar_Type (Component_Type (E)) then |
| 4263 |
Error_Msg_N ("aspect% requires scalar components", Id); |
| 4264 |
goto Continue; |
| 4265 |
end if; |
| 4266 |
end if; |
| 4267 |
|
| 4268 |
when Aspect_Aggregate => |
| 4269 |
-- We will be checking that the aspect is not specified on |
| 4270 |
-- an array type in Analyze_Aspects_At_Freeze_Point. |
| 4271 |
|
| 4272 |
Validate_Aspect_Aggregate (Expr); |
| 4273 |
|
| 4274 |
when Aspect_Stable_Properties => |
| 4275 |
Validate_Aspect_Stable_Properties |
| 4276 |
(E, Expr, Class_Present => Class_Present (Aspect)); |
| 4277 |
|
| 4278 |
when Aspect_Designated_Storage_Model => |
| 4279 |
if not All_Extensions_Allowed then |
| 4280 |
Error_Msg_Name_1 := Nam; |
| 4281 |
Error_Msg_GNAT_Extension ("aspect %", Loc); |
| 4282 |
goto Continue; |
| 4283 |
|
| 4284 |
elsif not Is_Type (E) |
| 4285 |
or else Ekind (E) /= E_Access_Type |
| 4286 |
then |
| 4287 |
Error_Msg_N |
| 4288 |
("can only be specified for pool-specific access type", |
| 4289 |
Aspect); |
| 4290 |
goto Continue; |
| 4291 |
end if; |
| 4292 |
|
| 4293 |
when Aspect_Storage_Model_Type => |
| 4294 |
if not All_Extensions_Allowed then |
| 4295 |
Error_Msg_Name_1 := Nam; |
| 4296 |
Error_Msg_GNAT_Extension ("aspect %", Loc); |
| 4297 |
goto Continue; |
| 4298 |
|
| 4299 |
elsif not Is_Type (E) |
| 4300 |
or else not Is_Immutably_Limited_Type (E) |
| 4301 |
then |
| 4302 |
Error_Msg_N |
| 4303 |
("can only be specified for immutably limited type", |
| 4304 |
Aspect); |
| 4305 |
goto Continue; |
| 4306 |
end if; |
| 4307 |
|
| 4308 |
when Aspect_Finalizable => |
| 4309 |
if not Core_Extensions_Allowed then |
| 4310 |
Error_Msg_Name_1 := Nam; |
| 4311 |
Error_Msg_GNAT_Extension |
| 4312 |
("aspect %", Loc, Is_Core_Extension => True); |
| 4313 |
goto Continue; |
| 4314 |
|
| 4315 |
elsif not Is_Type (E) then |
| 4316 |
Error_Msg_N ("can only be specified for a type", Aspect); |
| 4317 |
goto Continue; |
| 4318 |
end if; |
| 4319 |
|
| 4320 |
when Aspect_Integer_Literal |
| 4321 |
| Aspect_Real_Literal |
| 4322 |
| Aspect_String_Literal |
| 4323 |
=> |
| 4324 |
|
| 4325 |
if not Is_First_Subtype (E) then |
| 4326 |
Error_Msg_N |
| 4327 |
("may only be specified for a first subtype", Aspect); |
| 4328 |
goto Continue; |
| 4329 |
end if; |
| 4330 |
|
| 4331 |
if Ada_Version < Ada_2022 then |
| 4332 |
Check_Restriction |
| 4333 |
(No_Implementation_Aspect_Specifications, N); |
| 4334 |
end if; |
| 4335 |
|
| 4336 |
-- Case 3b: The aspects listed below don't correspond to |
| 4337 |
-- pragmas/attributes and don't need delayed analysis. |
| 4338 |
|
| 4339 |
-- Implicit_Dereference |
| 4340 |
|
| 4341 |
-- Only the legality checks are done during the analysis, thus |
| 4342 |
-- no delay is required. |
| 4343 |
|
| 4344 |
when Aspect_Implicit_Dereference => |
| 4345 |
Analyze_Aspect_Implicit_Dereference; |
| 4346 |
goto Continue; |
| 4347 |
|
| 4348 |
-- Dimension |
| 4349 |
|
| 4350 |
when Aspect_Dimension => |
| 4351 |
Analyze_Aspect_Dimension (N, Id, Expr); |
| 4352 |
goto Continue; |
| 4353 |
|
| 4354 |
-- Dimension_System |
| 4355 |
|
| 4356 |
when Aspect_Dimension_System => |
| 4357 |
Analyze_Aspect_Dimension_System (N, Id, Expr); |
| 4358 |
goto Continue; |
| 4359 |
|
| 4360 |
when Aspect_Local_Restrictions => |
| 4361 |
Validate_Aspect_Local_Restrictions (E, Expr); |
| 4362 |
Record_Rep_Item (E, Aspect); |
| 4363 |
goto Continue; |
| 4364 |
|
| 4365 |
-- Case 4: Aspects requiring special handling |
| 4366 |
|
| 4367 |
-- Pre/Post/Test_Case/Contract_Cases/Always_Terminates/ |
| 4368 |
-- Exceptional_Cases/Exit_Cases and Subprogram_Variant whose |
| 4369 |
-- corresponding pragmas take care of the delay. |
| 4370 |
|
| 4371 |
-- Pre/Post |
| 4372 |
|
| 4373 |
-- Aspects Pre/Post generate Precondition/Postcondition pragmas |
| 4374 |
-- with a first argument that is the expression, and a second |
| 4375 |
-- argument that is an informative message if the test fails. |
| 4376 |
-- This is inserted right after the declaration, to get the |
| 4377 |
-- required pragma placement. The processing for the pragmas |
| 4378 |
-- takes care of the required delay. |
| 4379 |
|
| 4380 |
when Pre_Post_Aspects => Pre_Post : declare |
| 4381 |
Pname : Name_Id; |
| 4382 |
|
| 4383 |
begin |
| 4384 |
if A_Id in Aspect_Pre | Aspect_Precondition then |
| 4385 |
Pname := Name_Precondition; |
| 4386 |
else |
| 4387 |
Pname := Name_Postcondition; |
| 4388 |
end if; |
| 4389 |
|
| 4390 |
-- Check that the class-wide predicate cannot be applied to |
| 4391 |
-- an operation of a synchronized type. AI12-0182 forbids |
| 4392 |
-- these altogether, while earlier language semantics made |
| 4393 |
-- them legal on tagged synchronized types. |
| 4394 |
|
| 4395 |
-- Other legality checks are performed when analyzing the |
| 4396 |
-- contract of the operation. |
| 4397 |
|
| 4398 |
if Class_Present (Aspect) |
| 4399 |
and then Is_Concurrent_Type (Current_Scope) |
| 4400 |
and then Ekind (E) in E_Entry | E_Function | E_Procedure |
| 4401 |
then |
| 4402 |
Error_Msg_Name_1 := Original_Aspect_Pragma_Name (Aspect); |
| 4403 |
Error_Msg_N |
| 4404 |
("aspect % can only be specified for a primitive " |
| 4405 |
& "operation of a tagged type", Aspect); |
| 4406 |
|
| 4407 |
goto Continue; |
| 4408 |
end if; |
| 4409 |
|
| 4410 |
-- Remember class-wide conditions; they will be merged |
| 4411 |
-- with inherited conditions. |
| 4412 |
|
| 4413 |
if Class_Present (Aspect) |
| 4414 |
and then A_Id in Aspect_Pre | Aspect_Post |
| 4415 |
and then Is_Subprogram (E) |
| 4416 |
and then not Is_Ignored_Ghost_Entity (E) |
| 4417 |
then |
| 4418 |
if A_Id = Aspect_Pre then |
| 4419 |
if Is_Ignored (Aspect) then |
| 4420 |
Set_Ignored_Class_Preconditions (E, |
| 4421 |
New_Copy_Tree (Expr)); |
| 4422 |
else |
| 4423 |
Set_Class_Preconditions (E, New_Copy_Tree (Expr)); |
| 4424 |
end if; |
| 4425 |
|
| 4426 |
-- Postconditions may split into separate aspects, and we |
| 4427 |
-- remember the expression before such split (i.e. when |
| 4428 |
-- the first postcondition is processed). |
| 4429 |
|
| 4430 |
elsif No (Class_Postconditions (E)) |
| 4431 |
and then No (Ignored_Class_Postconditions (E)) |
| 4432 |
then |
| 4433 |
if Is_Ignored (Aspect) then |
| 4434 |
Set_Ignored_Class_Postconditions (E, |
| 4435 |
New_Copy_Tree (Expr)); |
| 4436 |
else |
| 4437 |
Set_Class_Postconditions (E, New_Copy_Tree (Expr)); |
| 4438 |
end if; |
| 4439 |
end if; |
| 4440 |
end if; |
| 4441 |
|
| 4442 |
-- Build the precondition/postcondition pragma |
| 4443 |
|
| 4444 |
Aitem := Make_Aitem_Pragma |
| 4445 |
(Pragma_Argument_Associations => New_List ( |
| 4446 |
Make_Pragma_Argument_Association (Eloc, |
| 4447 |
Chars => Name_Check, |
| 4448 |
Expression => Relocate_Expression (Expr))), |
| 4449 |
Pragma_Name => Pname); |
| 4450 |
|
| 4451 |
Set_Is_Delayed_Aspect (Aspect); |
| 4452 |
|
| 4453 |
-- For Pre/Post cases, insert immediately after the entity |
| 4454 |
-- declaration, since that is the required pragma placement. |
| 4455 |
-- Note that for these aspects, we do not have to worry |
| 4456 |
-- about delay issues, since the pragmas themselves deal |
| 4457 |
-- with delay of visibility for the expression analysis. |
| 4458 |
|
| 4459 |
Insert_Pragma (Aitem); |
| 4460 |
|
| 4461 |
goto Continue; |
| 4462 |
end Pre_Post; |
| 4463 |
|
| 4464 |
-- Test_Case |
| 4465 |
|
| 4466 |
when Aspect_Test_Case => Test_Case : declare |
| 4467 |
Args : List_Id; |
| 4468 |
Comp_Expr : Node_Id; |
| 4469 |
Comp_Assn : Node_Id; |
| 4470 |
|
| 4471 |
begin |
| 4472 |
Args := New_List; |
| 4473 |
|
| 4474 |
if Nkind (Parent (N)) = N_Compilation_Unit then |
| 4475 |
Error_Msg_Name_1 := Nam; |
| 4476 |
Error_Msg_N ("incorrect placement of aspect %", E); |
| 4477 |
goto Continue; |
| 4478 |
end if; |
| 4479 |
|
| 4480 |
if Nkind (Expr) /= N_Aggregate |
| 4481 |
or else Null_Record_Present (Expr) |
| 4482 |
then |
| 4483 |
Error_Msg_Name_1 := Nam; |
| 4484 |
Error_Msg_NE |
| 4485 |
("wrong syntax for aspect % for &", Id, E); |
| 4486 |
goto Continue; |
| 4487 |
end if; |
| 4488 |
|
| 4489 |
-- Check that the expression is a proper aggregate (no |
| 4490 |
-- parentheses). |
| 4491 |
|
| 4492 |
if Paren_Count (Expr) /= 0 then |
| 4493 |
Error_Msg_F -- CODEFIX |
| 4494 |
("redundant parentheses", Expr); |
| 4495 |
goto Continue; |
| 4496 |
end if; |
| 4497 |
|
| 4498 |
-- Create the list of arguments for building the Test_Case |
| 4499 |
-- pragma. |
| 4500 |
|
| 4501 |
Comp_Expr := First (Expressions (Expr)); |
| 4502 |
while Present (Comp_Expr) loop |
| 4503 |
Append_To (Args, |
| 4504 |
Make_Pragma_Argument_Association (Sloc (Comp_Expr), |
| 4505 |
Expression => Relocate_Node (Comp_Expr))); |
| 4506 |
Next (Comp_Expr); |
| 4507 |
end loop; |
| 4508 |
|
| 4509 |
Comp_Assn := First (Component_Associations (Expr)); |
| 4510 |
while Present (Comp_Assn) loop |
| 4511 |
if List_Length (Choices (Comp_Assn)) /= 1 |
| 4512 |
or else |
| 4513 |
Nkind (First (Choices (Comp_Assn))) /= N_Identifier |
| 4514 |
then |
| 4515 |
Error_Msg_Name_1 := Nam; |
| 4516 |
Error_Msg_NE |
| 4517 |
("wrong syntax for aspect % for &", Id, E); |
| 4518 |
goto Continue; |
| 4519 |
end if; |
| 4520 |
|
| 4521 |
Append_To (Args, |
| 4522 |
Make_Pragma_Argument_Association (Sloc (Comp_Assn), |
| 4523 |
Chars => Chars (First (Choices (Comp_Assn))), |
| 4524 |
Expression => |
| 4525 |
Relocate_Node (Expression (Comp_Assn)))); |
| 4526 |
Next (Comp_Assn); |
| 4527 |
end loop; |
| 4528 |
|
| 4529 |
-- Build the test-case pragma |
| 4530 |
|
| 4531 |
Aitem := Make_Aitem_Pragma |
| 4532 |
(Pragma_Argument_Associations => Args, |
| 4533 |
Pragma_Name => Name_Test_Case); |
| 4534 |
end Test_Case; |
| 4535 |
|
| 4536 |
-- Contract_Cases |
| 4537 |
|
| 4538 |
when Aspect_Contract_Cases => |
| 4539 |
Aitem := Make_Aitem_Pragma |
| 4540 |
(Pragma_Argument_Associations => New_List ( |
| 4541 |
Make_Pragma_Argument_Association (Loc, |
| 4542 |
Expression => Relocate_Node (Expr))), |
| 4543 |
Pragma_Name => Name_Contract_Cases); |
| 4544 |
|
| 4545 |
Decorate (Aspect, Aitem); |
| 4546 |
Insert_Pragma (Aitem); |
| 4547 |
goto Continue; |
| 4548 |
|
| 4549 |
-- Exceptional_Cases |
| 4550 |
|
| 4551 |
when Aspect_Exceptional_Cases => |
| 4552 |
Aitem := Make_Aitem_Pragma |
| 4553 |
(Pragma_Argument_Associations => New_List ( |
| 4554 |
Make_Pragma_Argument_Association (Loc, |
| 4555 |
Expression => Relocate_Node (Expr))), |
| 4556 |
Pragma_Name => Name_Exceptional_Cases); |
| 4557 |
|
| 4558 |
Decorate (Aspect, Aitem); |
| 4559 |
Insert_Pragma (Aitem); |
| 4560 |
goto Continue; |
| 4561 |
|
| 4562 |
-- Exit_Cases |
| 4563 |
|
| 4564 |
when Aspect_Exit_Cases => |
| 4565 |
Aitem := Make_Aitem_Pragma |
| 4566 |
(Pragma_Argument_Associations => New_List ( |
| 4567 |
Make_Pragma_Argument_Association (Loc, |
| 4568 |
Expression => Relocate_Node (Expr))), |
| 4569 |
Pragma_Name => Name_Exit_Cases); |
| 4570 |
|
| 4571 |
Decorate (Aspect, Aitem); |
| 4572 |
Insert_Pragma (Aitem); |
| 4573 |
goto Continue; |
| 4574 |
|
| 4575 |
-- Subprogram_Variant |
| 4576 |
|
| 4577 |
when Aspect_Subprogram_Variant => |
| 4578 |
Aitem := Make_Aitem_Pragma |
| 4579 |
(Pragma_Argument_Associations => New_List ( |
| 4580 |
Make_Pragma_Argument_Association (Loc, |
| 4581 |
Expression => Relocate_Node (Expr))), |
| 4582 |
Pragma_Name => Name_Subprogram_Variant); |
| 4583 |
|
| 4584 |
Decorate (Aspect, Aitem); |
| 4585 |
Insert_Pragma (Aitem); |
| 4586 |
goto Continue; |
| 4587 |
|
| 4588 |
-- Case 5: Special handling for aspects with an optional |
| 4589 |
-- boolean argument. |
| 4590 |
|
| 4591 |
-- In the delayed case, the corresponding pragma cannot be |
| 4592 |
-- generated yet because the evaluation of the boolean needs |
| 4593 |
-- to be delayed till the freeze point. |
| 4594 |
|
| 4595 |
when Boolean_Aspects |
| 4596 |
| Library_Unit_Aspects |
| 4597 |
=> |
| 4598 |
Set_Is_Boolean_Aspect (Aspect); |
| 4599 |
|
| 4600 |
-- Lock_Free aspect only apply to protected objects |
| 4601 |
|
| 4602 |
if A_Id = Aspect_Lock_Free then |
| 4603 |
if Ekind (E) /= E_Protected_Type then |
| 4604 |
Error_Msg_Name_1 := Nam; |
| 4605 |
Error_Msg_N |
| 4606 |
("aspect % only applies to a protected type " & |
| 4607 |
"or object", |
| 4608 |
Aspect); |
| 4609 |
|
| 4610 |
else |
| 4611 |
-- Set the Uses_Lock_Free flag to True if there is no |
| 4612 |
-- expression or if the expression is True. The |
| 4613 |
-- evaluation of this aspect should be delayed to the |
| 4614 |
-- freeze point if we wanted to handle the corner case |
| 4615 |
-- of "true" or "false" being redefined. |
| 4616 |
|
| 4617 |
if No (Expr) |
| 4618 |
or else Is_True (Static_Boolean (Expr)) |
| 4619 |
then |
| 4620 |
Set_Uses_Lock_Free (E); |
| 4621 |
end if; |
| 4622 |
|
| 4623 |
Record_Rep_Item (E, Aspect); |
| 4624 |
end if; |
| 4625 |
|
| 4626 |
goto Continue; |
| 4627 |
|
| 4628 |
elsif A_Id in Aspect_Export | Aspect_Import then |
| 4629 |
Analyze_Aspect_Export_Import; |
| 4630 |
|
| 4631 |
-- Disable_Controlled |
| 4632 |
|
| 4633 |
elsif A_Id = Aspect_Disable_Controlled then |
| 4634 |
Analyze_Aspect_Disable_Controlled; |
| 4635 |
goto Continue; |
| 4636 |
|
| 4637 |
-- Ada 2022 (AI12-0129): Exclusive_Functions |
| 4638 |
|
| 4639 |
elsif A_Id = Aspect_Exclusive_Functions then |
| 4640 |
if Ekind (E) /= E_Protected_Type then |
| 4641 |
Error_Msg_Name_1 := Nam; |
| 4642 |
Error_Msg_N |
| 4643 |
("aspect % only applies to a protected type " & |
| 4644 |
"or object", |
| 4645 |
Aspect); |
| 4646 |
end if; |
| 4647 |
|
| 4648 |
goto Continue; |
| 4649 |
|
| 4650 |
-- Ada 2022 (AI12-0363): Full_Access_Only |
| 4651 |
|
| 4652 |
elsif A_Id = Aspect_Full_Access_Only then |
| 4653 |
Error_Msg_Ada_2022_Feature ("aspect %", Loc); |
| 4654 |
|
| 4655 |
-- No_Controlled_Parts, No_Task_Parts |
| 4656 |
|
| 4657 |
elsif A_Id in Aspect_No_Controlled_Parts |
| 4658 |
| Aspect_No_Task_Parts |
| 4659 |
then |
| 4660 |
Error_Msg_Name_1 := Nam; |
| 4661 |
|
| 4662 |
-- Disallow formal types |
| 4663 |
|
| 4664 |
if Nkind (Original_Node (N)) = N_Formal_Type_Declaration |
| 4665 |
then |
| 4666 |
Error_Msg_N |
| 4667 |
("aspect % not allowed for formal type declaration", |
| 4668 |
Aspect); |
| 4669 |
|
| 4670 |
-- Disallow subtypes |
| 4671 |
|
| 4672 |
elsif Nkind (Original_Node (N)) = N_Subtype_Declaration |
| 4673 |
then |
| 4674 |
Error_Msg_N |
| 4675 |
("aspect % not allowed for subtype declaration", |
| 4676 |
Aspect); |
| 4677 |
|
| 4678 |
-- Accept all other types |
| 4679 |
|
| 4680 |
elsif not Is_Type (E) then |
| 4681 |
Error_Msg_N |
| 4682 |
("aspect % can only be specified for a type", |
| 4683 |
Aspect); |
| 4684 |
end if; |
| 4685 |
|
| 4686 |
-- Resolve the expression to a boolean |
| 4687 |
|
| 4688 |
if Present (Expr) then |
| 4689 |
Check_Expr_Is_OK_Static_Expression (Expr, Any_Boolean); |
| 4690 |
end if; |
| 4691 |
|
| 4692 |
goto Continue; |
| 4693 |
|
| 4694 |
-- Ada 2022 (AI12-0075): static expression functions |
| 4695 |
|
| 4696 |
elsif A_Id = Aspect_Static then |
| 4697 |
Analyze_Aspect_Static; |
| 4698 |
goto Continue; |
| 4699 |
|
| 4700 |
-- Ada 2022 (AI12-0279) |
| 4701 |
|
| 4702 |
elsif A_Id = Aspect_Yield then |
| 4703 |
Analyze_Aspect_Yield; |
| 4704 |
goto Continue; |
| 4705 |
|
| 4706 |
-- Handle Boolean aspects equivalent to source pragmas which |
| 4707 |
-- appears after the related object declaration. |
| 4708 |
|
| 4709 |
elsif A_Id in Aspect_Always_Terminates |
| 4710 |
| Aspect_Async_Readers |
| 4711 |
| Aspect_Async_Writers |
| 4712 |
| Aspect_Constant_After_Elaboration |
| 4713 |
| Aspect_Effective_Reads |
| 4714 |
| Aspect_Effective_Writes |
| 4715 |
| Aspect_Extensions_Visible |
| 4716 |
| Aspect_Ghost |
| 4717 |
| Aspect_No_Caching |
| 4718 |
| Aspect_Side_Effects |
| 4719 |
| Aspect_Volatile_Function |
| 4720 |
then |
| 4721 |
Aitem := |
| 4722 |
Make_Aitem_Pragma |
| 4723 |
(Pragma_Argument_Associations => New_List ( |
| 4724 |
Make_Pragma_Argument_Association (Loc, |
| 4725 |
Expression => Relocate_Node (Expr))), |
| 4726 |
Pragma_Name => Nam); |
| 4727 |
Decorate (Aspect, Aitem); |
| 4728 |
Insert_Pragma (Aitem); |
| 4729 |
goto Continue; |
| 4730 |
end if; |
| 4731 |
|
| 4732 |
-- Library unit aspects require special handling in the case |
| 4733 |
-- of a package declaration, the pragma needs to be inserted |
| 4734 |
-- in the list of declarations for the associated package. |
| 4735 |
-- There is no issue of visibility delay for these aspects. |
| 4736 |
|
| 4737 |
if A_Id in Library_Unit_Aspects |
| 4738 |
and then |
| 4739 |
Nkind (N) in N_Package_Declaration |
| 4740 |
| N_Generic_Package_Declaration |
| 4741 |
and then Nkind (Parent (N)) /= N_Compilation_Unit |
| 4742 |
|
| 4743 |
-- Aspect is legal on a local instantiation of a library- |
| 4744 |
-- level generic unit. |
| 4745 |
|
| 4746 |
and then not Is_Generic_Instance (Defining_Entity (N)) |
| 4747 |
then |
| 4748 |
Error_Msg_N |
| 4749 |
("incorrect context for library unit aspect&", Id); |
| 4750 |
goto Continue; |
| 4751 |
end if; |
| 4752 |
|
| 4753 |
-- Cases where we do not delay |
| 4754 |
|
| 4755 |
if not Delay_Required then |
| 4756 |
|
| 4757 |
-- Exclude aspects Export and Import because their pragma |
| 4758 |
-- syntax does not map directly to a Boolean aspect. |
| 4759 |
|
| 4760 |
if A_Id not in Aspect_Export | Aspect_Import then |
| 4761 |
Aitem := Make_Aitem_Pragma |
| 4762 |
(Pragma_Argument_Associations => New_List ( |
| 4763 |
Make_Pragma_Argument_Association (Sloc (Ent), |
| 4764 |
Expression => Ent)), |
| 4765 |
Pragma_Name => Nam); |
| 4766 |
end if; |
| 4767 |
|
| 4768 |
-- Minimum check of First_Controlling_Parameter aspect; |
| 4769 |
-- the checks shared by the aspect and its corresponding |
| 4770 |
-- pragma are performed when the pragma is analyzed. |
| 4771 |
|
| 4772 |
if A_Id = Aspect_First_Controlling_Parameter then |
| 4773 |
if Present (Expr) then |
| 4774 |
Analyze (Expr); |
| 4775 |
end if; |
| 4776 |
|
| 4777 |
if (No (Expr) or else Entity (Expr) = Standard_True) |
| 4778 |
and then not Core_Extensions_Allowed |
| 4779 |
then |
| 4780 |
Error_Msg_GNAT_Extension |
| 4781 |
("'First_'Controlling_'Parameter", Sloc (Aspect), |
| 4782 |
Is_Core_Extension => True); |
| 4783 |
goto Continue; |
| 4784 |
end if; |
| 4785 |
|
| 4786 |
if not (Is_Type (E) |
| 4787 |
and then |
| 4788 |
(Is_Tagged_Type (E) |
| 4789 |
or else Is_Concurrent_Type (E))) |
| 4790 |
then |
| 4791 |
Error_Msg_N |
| 4792 |
("aspect 'First_'Controlling_'Parameter can only " |
| 4793 |
& "apply to tagged type or concurrent type", |
| 4794 |
Aspect); |
| 4795 |
goto Continue; |
| 4796 |
end if; |
| 4797 |
|
| 4798 |
if Present (Expr) |
| 4799 |
and then Entity (Expr) = Standard_False |
| 4800 |
then |
| 4801 |
-- If the aspect is specified for a derived type, |
| 4802 |
-- the specified value shall be confirming. |
| 4803 |
|
| 4804 |
if Is_Derived_Type (E) |
| 4805 |
and then Has_First_Controlling_Parameter_Aspect |
| 4806 |
(Etype (E)) |
| 4807 |
then |
| 4808 |
Error_Msg_Name_1 := Nam; |
| 4809 |
Error_Msg_N |
| 4810 |
("specification of inherited True value for " |
| 4811 |
& "aspect% can only confirm parent value", |
| 4812 |
Id); |
| 4813 |
end if; |
| 4814 |
|
| 4815 |
goto Continue; |
| 4816 |
end if; |
| 4817 |
|
| 4818 |
-- Given that the aspect has been explicitly given, |
| 4819 |
-- we take note to avoid checking for its implicit |
| 4820 |
-- inheritance (see Analyze_Full_Type_Declaration). |
| 4821 |
|
| 4822 |
Set_Has_First_Controlling_Parameter_Aspect (E); |
| 4823 |
end if; |
| 4824 |
|
| 4825 |
-- In general cases, the corresponding pragma/attribute |
| 4826 |
-- definition clause will be inserted later at the freezing |
| 4827 |
-- point, and we do not need to build it now. |
| 4828 |
|
| 4829 |
else |
| 4830 |
Aitem := Empty; |
| 4831 |
end if; |
| 4832 |
|
| 4833 |
-- Storage_Size |
| 4834 |
|
| 4835 |
-- This is special because for access types we need to generate |
| 4836 |
-- an attribute definition clause. This also works for single |
| 4837 |
-- task declarations, but it does not work for task type |
| 4838 |
-- declarations, because we have the case where the expression |
| 4839 |
-- references a discriminant of the task type. That can't use |
| 4840 |
-- an attribute definition clause because we would not have |
| 4841 |
-- visibility on the discriminant. For that case we must |
| 4842 |
-- generate a pragma in the task definition. |
| 4843 |
|
| 4844 |
when Aspect_Storage_Size => |
| 4845 |
|
| 4846 |
-- Task type case |
| 4847 |
|
| 4848 |
if Ekind (E) = E_Task_Type then |
| 4849 |
declare |
| 4850 |
Decl : constant Node_Id := Declaration_Node (E); |
| 4851 |
|
| 4852 |
begin |
| 4853 |
pragma Assert (Nkind (Decl) = N_Task_Type_Declaration); |
| 4854 |
|
| 4855 |
-- If no task definition, create one |
| 4856 |
|
| 4857 |
if No (Task_Definition (Decl)) then |
| 4858 |
Set_Task_Definition (Decl, |
| 4859 |
Make_Task_Definition (Loc, |
| 4860 |
Visible_Declarations => Empty_List, |
| 4861 |
End_Label => Empty)); |
| 4862 |
end if; |
| 4863 |
|
| 4864 |
-- Create a pragma and put it at the start of the task |
| 4865 |
-- definition for the task type declaration. |
| 4866 |
|
| 4867 |
Aitem := Make_Aitem_Pragma |
| 4868 |
(Pragma_Argument_Associations => New_List ( |
| 4869 |
Make_Pragma_Argument_Association (Loc, |
| 4870 |
Expression => Relocate_Node (Expr))), |
| 4871 |
Pragma_Name => Name_Storage_Size); |
| 4872 |
|
| 4873 |
Prepend |
| 4874 |
(Aitem, |
| 4875 |
Visible_Declarations (Task_Definition (Decl))); |
| 4876 |
goto Continue; |
| 4877 |
end; |
| 4878 |
|
| 4879 |
-- Generate an attribute definition for access types |
| 4880 |
|
| 4881 |
elsif Is_Access_Type (E) then |
| 4882 |
Aitem := |
| 4883 |
Make_Attribute_Definition_Clause (Loc, |
| 4884 |
Name => Ent, |
| 4885 |
Chars => Name_Storage_Size, |
| 4886 |
Expression => Relocate_Node (Expr)); |
| 4887 |
|
| 4888 |
-- This is likely a misplaced aspect. Create a pragma to |
| 4889 |
-- emit the actual error. |
| 4890 |
|
| 4891 |
else |
| 4892 |
Aitem := |
| 4893 |
Make_Aitem_Pragma |
| 4894 |
(Pragma_Argument_Associations => |
| 4895 |
New_List |
| 4896 |
(Make_Pragma_Argument_Association |
| 4897 |
(Loc, Expression => Relocate_Node (Expr))), |
| 4898 |
Pragma_Name => Name_Storage_Size); |
| 4899 |
Insert_Pragma (Aitem); |
| 4900 |
goto Continue; |
| 4901 |
end if; |
| 4902 |
|
| 4903 |
when Aspect_External_Initialization => |
| 4904 |
Error_Msg_GNAT_Extension |
| 4905 |
("External_Initialization aspect", Sloc (Aspect)); |
| 4906 |
|
| 4907 |
-- The External_Initialization aspect specifications that |
| 4908 |
-- are attached to object declarations were already |
| 4909 |
-- processed and detached from the list at an earlier stage, |
| 4910 |
-- so we can only get here if the specification is not in an |
| 4911 |
-- appropriate place. |
| 4912 |
|
| 4913 |
Error_Msg_N |
| 4914 |
("External_Initialization aspect can only be specified " & |
| 4915 |
"for object declarations", Aspect); |
| 4916 |
end case; |
| 4917 |
|
| 4918 |
-- Attach the corresponding pragma/attribute definition clause to |
| 4919 |
-- the aspect specification node. |
| 4920 |
|
| 4921 |
if Present (Aitem) then |
| 4922 |
Set_From_Aspect_Specification (Aitem); |
| 4923 |
end if; |
| 4924 |
|
| 4925 |
-- For an aspect that applies to a type, indicate whether it |
| 4926 |
-- appears on a partial view of the type. |
| 4927 |
|
| 4928 |
if Is_Type (E) and then Is_Private_Type (E) then |
| 4929 |
Set_Aspect_On_Partial_View (Aspect); |
| 4930 |
end if; |
| 4931 |
|
| 4932 |
-- In the context of a compilation unit, we directly put the |
| 4933 |
-- pragma in the Pragmas_After list of the N_Compilation_Unit_Aux |
| 4934 |
-- node (no delay is required here) except for aspects on a |
| 4935 |
-- subprogram body (see below) and a generic package, for which we |
| 4936 |
-- need to introduce the pragma before building the generic copy |
| 4937 |
-- (see sem_ch12), and for package instantiations, where the |
| 4938 |
-- library unit pragmas are better handled early. |
| 4939 |
|
| 4940 |
if Nkind (Parent (N)) = N_Compilation_Unit |
| 4941 |
and then (Present (Aitem) or else Is_Boolean_Aspect (Aspect)) |
| 4942 |
then |
| 4943 |
declare |
| 4944 |
Aux : constant Node_Id := Aux_Decls_Node (Parent (N)); |
| 4945 |
|
| 4946 |
begin |
| 4947 |
pragma Assert (Nkind (Aux) = N_Compilation_Unit_Aux); |
| 4948 |
|
| 4949 |
-- For a Boolean aspect, create the corresponding pragma if |
| 4950 |
-- no expression or if the value is True. |
| 4951 |
|
| 4952 |
if Is_Boolean_Aspect (Aspect) and then No (Aitem) then |
| 4953 |
if Is_True (Static_Boolean (Expr)) then |
| 4954 |
Aitem := Make_Aitem_Pragma |
| 4955 |
(Pragma_Argument_Associations => New_List ( |
| 4956 |
Make_Pragma_Argument_Association (Sloc (Ent), |
| 4957 |
Expression => Ent)), |
| 4958 |
Pragma_Name => Nam); |
| 4959 |
|
| 4960 |
Set_From_Aspect_Specification (Aitem, True); |
| 4961 |
Set_Corresponding_Aspect (Aitem, Aspect); |
| 4962 |
|
| 4963 |
else |
| 4964 |
goto Continue; |
| 4965 |
end if; |
| 4966 |
end if; |
| 4967 |
|
| 4968 |
-- If the aspect is on a subprogram body (relevant aspect |
| 4969 |
-- is Inline), add the pragma in front of the declarations. |
| 4970 |
|
| 4971 |
if Nkind (N) = N_Subprogram_Body then |
| 4972 |
if No (Declarations (N)) then |
| 4973 |
Set_Declarations (N, New_List); |
| 4974 |
end if; |
| 4975 |
|
| 4976 |
Prepend (Aitem, Declarations (N)); |
| 4977 |
|
| 4978 |
elsif Nkind (N) = N_Generic_Package_Declaration then |
| 4979 |
if No (Visible_Declarations (Specification (N))) then |
| 4980 |
Set_Visible_Declarations (Specification (N), New_List); |
| 4981 |
end if; |
| 4982 |
|
| 4983 |
Prepend (Aitem, |
| 4984 |
Visible_Declarations (Specification (N))); |
| 4985 |
|
| 4986 |
elsif Nkind (N) = N_Package_Instantiation then |
| 4987 |
declare |
| 4988 |
Spec : constant Node_Id := |
| 4989 |
Specification (Instance_Spec (N)); |
| 4990 |
begin |
| 4991 |
if No (Visible_Declarations (Spec)) then |
| 4992 |
Set_Visible_Declarations (Spec, New_List); |
| 4993 |
end if; |
| 4994 |
|
| 4995 |
Prepend (Aitem, Visible_Declarations (Spec)); |
| 4996 |
end; |
| 4997 |
|
| 4998 |
else |
| 4999 |
if No (Pragmas_After (Aux)) then |
| 5000 |
Set_Pragmas_After (Aux, New_List); |
| 5001 |
end if; |
| 5002 |
|
| 5003 |
Append (Aitem, Pragmas_After (Aux)); |
| 5004 |
end if; |
| 5005 |
|
| 5006 |
goto Continue; |
| 5007 |
end; |
| 5008 |
end if; |
| 5009 |
|
| 5010 |
-- The evaluation of the aspect is delayed to the freezing point. |
| 5011 |
-- The pragma or attribute clause if there is one is then attached |
| 5012 |
-- to the aspect specification which is put in the rep item list. |
| 5013 |
|
| 5014 |
if Delay_Required then |
| 5015 |
if Present (Aitem) then |
| 5016 |
Set_Is_Delayed_Aspect (Aitem); |
| 5017 |
Set_Aspect_Rep_Item (Aspect, Aitem); |
| 5018 |
Set_Parent (Aitem, Aspect); |
| 5019 |
end if; |
| 5020 |
|
| 5021 |
Set_Is_Delayed_Aspect (Aspect); |
| 5022 |
|
| 5023 |
-- In the case of Default_Value, link the aspect to base type |
| 5024 |
-- as well, even though it appears on a first subtype. This is |
| 5025 |
-- mandated by the semantics of the aspect. Do not establish |
| 5026 |
-- the link when processing the base type itself as this leads |
| 5027 |
-- to a rep item circularity. |
| 5028 |
|
| 5029 |
if A_Id = Aspect_Default_Value and then Base_Type (E) /= E then |
| 5030 |
Set_Has_Delayed_Aspects (Base_Type (E)); |
| 5031 |
Record_Rep_Item (Base_Type (E), Aspect); |
| 5032 |
end if; |
| 5033 |
|
| 5034 |
Set_Has_Delayed_Aspects (E); |
| 5035 |
Record_Rep_Item (E, Aspect); |
| 5036 |
|
| 5037 |
-- When delay is not required and the context is a package or a |
| 5038 |
-- subprogram body, insert the pragma in the body declarations. |
| 5039 |
|
| 5040 |
elsif Nkind (N) in N_Package_Body | N_Subprogram_Body then |
| 5041 |
if No (Declarations (N)) then |
| 5042 |
Set_Declarations (N, New_List); |
| 5043 |
end if; |
| 5044 |
|
| 5045 |
-- The pragma is added before source declarations |
| 5046 |
|
| 5047 |
Prepend_To (Declarations (N), Aitem); |
| 5048 |
|
| 5049 |
-- When delay is not required and the context is not a compilation |
| 5050 |
-- unit, we simply insert the pragma/attribute definition clause |
| 5051 |
-- in sequence. |
| 5052 |
|
| 5053 |
elsif Present (Aitem) then |
| 5054 |
Insert_After (Ins_Node, Aitem); |
| 5055 |
Ins_Node := Aitem; |
| 5056 |
end if; |
| 5057 |
|
| 5058 |
<<Continue>> |
| 5059 |
|
| 5060 |
-- If a nonoverridable aspect is explicitly specified for a |
| 5061 |
-- derived type, then check consistency with the parent type. |
| 5062 |
|
| 5063 |
if A_Id in Nonoverridable_Aspect_Id |
| 5064 |
and then Nkind (N) = N_Full_Type_Declaration |
| 5065 |
and then Nkind (Type_Definition (N)) = N_Derived_Type_Definition |
| 5066 |
and then not In_Instance_Body |
| 5067 |
then |
| 5068 |
-- Locate the nearest ancestor type that has an explicit aspect |
| 5069 |
-- corresponding to E's aspect, and flag an error on that if |
| 5070 |
-- E's aspect does not confirm the aspect inherited from the |
| 5071 |
-- ancestor. |
| 5072 |
|
| 5073 |
-- In order to locate the parent type we must go first to its |
| 5074 |
-- base type because the frontend introduces an implicit base |
| 5075 |
-- type even if there is no constraint attached to it, since |
| 5076 |
-- this is closer to the Ada semantics. |
| 5077 |
|
| 5078 |
declare |
| 5079 |
Ancestor_Type : Entity_Id := Etype (Base_Type (E)); |
| 5080 |
Ancestor_Aspect : Node_Id := Find_Aspect |
| 5081 |
(Ancestor_Type, A_Id); |
| 5082 |
begin |
| 5083 |
while Present (Ancestor_Aspect) loop |
| 5084 |
if Comes_From_Source (Ancestor_Aspect) |
| 5085 |
and then |
| 5086 |
not Is_Confirming (A_Id, Ancestor_Aspect, Aspect) |
| 5087 |
then |
| 5088 |
Error_Msg_Name_1 := Aspect_Names (A_Id); |
| 5089 |
Error_Msg_Sloc := Sloc (Ancestor_Aspect); |
| 5090 |
|
| 5091 |
Error_Msg_N |
| 5092 |
("overriding aspect specification for " |
| 5093 |
& "nonoverridable aspect % does not confirm " |
| 5094 |
& "aspect specification inherited from #", |
| 5095 |
Aspect); |
| 5096 |
|
| 5097 |
exit; |
| 5098 |
end if; |
| 5099 |
|
| 5100 |
if not Is_Derived_Type (Ancestor_Type) then |
| 5101 |
exit; |
| 5102 |
end if; |
| 5103 |
|
| 5104 |
Ancestor_Type := Etype (Base_Type (Ancestor_Type)); |
| 5105 |
Ancestor_Aspect := Find_Aspect (Ancestor_Type, A_Id); |
| 5106 |
end loop; |
| 5107 |
end; |
| 5108 |
end if; |
| 5109 |
|
| 5110 |
exception |
| 5111 |
when Aspect_Exit => null; |
| 5112 |
end Analyze_One_Aspect; |
| 5113 |
|
| 5114 |
Next (Aspect); |
| 5115 |
end loop Aspect_Loop; |
| 5116 |
|
| 5117 |
if Has_Delayed_Aspects (E) then |
| 5118 |
Ensure_Freeze_Node (E); |
| 5119 |
end if; |
| 5120 |
end Analyze_Aspect_Specifications; |
| 5121 |
|
| 5122 |
------------------------------------------------ |
| 5123 |
-- Analyze_Aspects_On_Subprogram_Body_Or_Stub -- |
| 5124 |
------------------------------------------------ |
| 5125 |
|
| 5126 |
procedure Analyze_Aspects_On_Subprogram_Body_Or_Stub (N : Node_Id) is |
| 5127 |
Body_Id : constant Entity_Id := Defining_Entity (N); |
| 5128 |
|
| 5129 |
procedure Diagnose_Misplaced_Aspects (Spec_Id : Entity_Id); |
| 5130 |
-- Body [stub] N has aspects, but they are not properly placed. Emit an |
| 5131 |
-- error message depending on the aspects involved. Spec_Id denotes the |
| 5132 |
-- entity of the corresponding spec. |
| 5133 |
|
| 5134 |
-------------------------------- |
| 5135 |
-- Diagnose_Misplaced_Aspects -- |
| 5136 |
-------------------------------- |
| 5137 |
|
| 5138 |
procedure Diagnose_Misplaced_Aspects (Spec_Id : Entity_Id) is |
| 5139 |
procedure Misplaced_Aspect_Error |
| 5140 |
(Asp : Node_Id; |
| 5141 |
Ref_Nam : Name_Id); |
| 5142 |
-- Emit an error message concerning misplaced aspect Asp. Ref_Nam is |
| 5143 |
-- the name of the refined version of the aspect. |
| 5144 |
|
| 5145 |
---------------------------- |
| 5146 |
-- Misplaced_Aspect_Error -- |
| 5147 |
---------------------------- |
| 5148 |
|
| 5149 |
procedure Misplaced_Aspect_Error |
| 5150 |
(Asp : Node_Id; |
| 5151 |
Ref_Nam : Name_Id) |
| 5152 |
is |
| 5153 |
Asp_Nam : constant Name_Id := Chars (Identifier (Asp)); |
| 5154 |
Asp_Id : constant Aspect_Id := Get_Aspect_Id (Asp_Nam); |
| 5155 |
|
| 5156 |
begin |
| 5157 |
-- The corresponding spec already contains the aspect in question |
| 5158 |
-- and the one appearing on the body must be the refined form: |
| 5159 |
|
| 5160 |
-- procedure P with Global ...; |
| 5161 |
-- procedure P with Global ... is ... end P; |
| 5162 |
-- ^ |
| 5163 |
-- Refined_Global |
| 5164 |
|
| 5165 |
if Has_Aspect (Spec_Id, Asp_Id) then |
| 5166 |
Error_Msg_Name_1 := Asp_Nam; |
| 5167 |
|
| 5168 |
-- Subunits cannot carry aspects that apply to a subprogram |
| 5169 |
-- declaration. |
| 5170 |
|
| 5171 |
if Nkind (Parent (N)) = N_Subunit then |
| 5172 |
Error_Msg_N ("aspect % cannot apply to a subunit", Asp); |
| 5173 |
|
| 5174 |
-- Otherwise suggest the refined form |
| 5175 |
|
| 5176 |
else |
| 5177 |
Error_Msg_Name_2 := Ref_Nam; |
| 5178 |
Error_Msg_N ("aspect % should be %", Asp); |
| 5179 |
end if; |
| 5180 |
|
| 5181 |
-- Otherwise the aspect must appear on the spec, not on the body |
| 5182 |
|
| 5183 |
-- procedure P; |
| 5184 |
-- procedure P with Global ... is ... end P; |
| 5185 |
|
| 5186 |
else |
| 5187 |
Error_Msg_N |
| 5188 |
("aspect specification must appear on initial declaration", |
| 5189 |
Asp); |
| 5190 |
end if; |
| 5191 |
end Misplaced_Aspect_Error; |
| 5192 |
|
| 5193 |
-- Local variables |
| 5194 |
|
| 5195 |
Asp : Node_Id; |
| 5196 |
Asp_Nam : Name_Id; |
| 5197 |
|
| 5198 |
-- Start of processing for Diagnose_Misplaced_Aspects |
| 5199 |
|
| 5200 |
begin |
| 5201 |
-- Iterate over the aspect specifications and emit specific errors |
| 5202 |
-- where applicable. |
| 5203 |
|
| 5204 |
Asp := First (Aspect_Specifications (N)); |
| 5205 |
while Present (Asp) loop |
| 5206 |
Asp_Nam := Chars (Identifier (Asp)); |
| 5207 |
|
| 5208 |
-- Do not emit errors on aspects that can appear on a subprogram |
| 5209 |
-- body. This scenario occurs when the aspect specification list |
| 5210 |
-- contains both misplaced and properly placed aspects. |
| 5211 |
|
| 5212 |
if Aspect_On_Body_Or_Stub_OK (Get_Aspect_Id (Asp_Nam)) then |
| 5213 |
null; |
| 5214 |
|
| 5215 |
-- Special diagnostics for SPARK aspects |
| 5216 |
|
| 5217 |
elsif Asp_Nam = Name_Depends then |
| 5218 |
Misplaced_Aspect_Error (Asp, Name_Refined_Depends); |
| 5219 |
|
| 5220 |
elsif Asp_Nam = Name_Global then |
| 5221 |
Misplaced_Aspect_Error (Asp, Name_Refined_Global); |
| 5222 |
|
| 5223 |
elsif Asp_Nam = Name_Post then |
| 5224 |
Misplaced_Aspect_Error (Asp, Name_Refined_Post); |
| 5225 |
|
| 5226 |
-- Otherwise a language-defined aspect is misplaced |
| 5227 |
|
| 5228 |
else |
| 5229 |
Error_Msg_N |
| 5230 |
("aspect specification must appear on initial declaration", |
| 5231 |
Asp); |
| 5232 |
end if; |
| 5233 |
|
| 5234 |
Next (Asp); |
| 5235 |
end loop; |
| 5236 |
end Diagnose_Misplaced_Aspects; |
| 5237 |
|
| 5238 |
-- Local variables |
| 5239 |
|
| 5240 |
Spec_Id : constant Entity_Id := Unique_Defining_Entity (N); |
| 5241 |
|
| 5242 |
-- Start of processing for Analyze_Aspects_On_Subprogram_Body_Or_Stub |
| 5243 |
|
| 5244 |
begin |
| 5245 |
-- Language-defined aspects cannot be associated with a subprogram body |
| 5246 |
-- [stub] if the subprogram has a spec. Certain implementation defined |
| 5247 |
-- aspects are allowed to break this rule (for all applicable cases, see |
| 5248 |
-- table Aspects.Aspect_On_Body_Or_Stub_OK). |
| 5249 |
|
| 5250 |
if Spec_Id /= Body_Id |
| 5251 |
and then Has_Aspects (N) |
| 5252 |
and then not Aspects_On_Body_Or_Stub_OK (N) |
| 5253 |
then |
| 5254 |
Diagnose_Misplaced_Aspects (Spec_Id); |
| 5255 |
else |
| 5256 |
Analyze_Aspect_Specifications (N, Body_Id); |
| 5257 |
end if; |
| 5258 |
end Analyze_Aspects_On_Subprogram_Body_Or_Stub; |
| 5259 |
|
| 5260 |
----------------------- |
| 5261 |
-- Analyze_At_Clause -- |
| 5262 |
----------------------- |
| 5263 |
|
| 5264 |
-- An at clause is replaced by the corresponding Address attribute |
| 5265 |
-- definition clause that is the preferred approach in Ada 95. |
| 5266 |
|
| 5267 |
procedure Analyze_At_Clause (N : Node_Id) is |
| 5268 |
CS : constant Boolean := Comes_From_Source (N); |
| 5269 |
|
| 5270 |
begin |
| 5271 |
-- This is an obsolescent feature |
| 5272 |
|
| 5273 |
Check_Restriction (No_Obsolescent_Features, N); |
| 5274 |
|
| 5275 |
if Warn_On_Obsolescent_Feature then |
| 5276 |
Error_Msg_N |
| 5277 |
("?j?at clause is an obsolescent feature (RM J.7(2))", N); |
| 5278 |
Error_Msg_N |
| 5279 |
("\?j?use address attribute definition clause instead", N); |
| 5280 |
end if; |
| 5281 |
|
| 5282 |
-- Rewrite as address clause |
| 5283 |
|
| 5284 |
Rewrite (N, |
| 5285 |
Make_Attribute_Definition_Clause (Sloc (N), |
| 5286 |
Name => Identifier (N), |
| 5287 |
Chars => Name_Address, |
| 5288 |
Expression => Expression (N))); |
| 5289 |
|
| 5290 |
-- We preserve Comes_From_Source, since logically the clause still comes |
| 5291 |
-- from the source program even though it is changed in form. |
| 5292 |
|
| 5293 |
Set_Comes_From_Source (N, CS); |
| 5294 |
|
| 5295 |
-- Analyze rewritten clause |
| 5296 |
|
| 5297 |
Analyze_Attribute_Definition_Clause (N); |
| 5298 |
end Analyze_At_Clause; |
| 5299 |
|
| 5300 |
----------------------------------------- |
| 5301 |
-- Analyze_Attribute_Definition_Clause -- |
| 5302 |
----------------------------------------- |
| 5303 |
|
| 5304 |
procedure Analyze_Attribute_Definition_Clause (N : Node_Id) is |
| 5305 |
Loc : constant Source_Ptr := Sloc (N); |
| 5306 |
Nam : constant Node_Id := Name (N); |
| 5307 |
Attr : constant Name_Id := Chars (N); |
| 5308 |
Expr : constant Node_Id := Expression (N); |
| 5309 |
Id : constant Attribute_Id := Get_Attribute_Id (Attr); |
| 5310 |
|
| 5311 |
Ent : Entity_Id; |
| 5312 |
-- The entity of Nam after it is analyzed. In the case of an incomplete |
| 5313 |
-- type, this is the underlying type. |
| 5314 |
|
| 5315 |
U_Ent : Entity_Id; |
| 5316 |
-- The underlying entity to which the attribute applies. Generally this |
| 5317 |
-- is the Underlying_Type of Ent, except in the case where the clause |
| 5318 |
-- applies to the full view of an incomplete or private type, in which |
| 5319 |
-- case U_Ent is just a copy of Ent. |
| 5320 |
|
| 5321 |
FOnly : Boolean := False; |
| 5322 |
-- Reset to True for subtype specific attribute (Alignment, Size) |
| 5323 |
-- and for stream attributes, i.e. those cases where in the call to |
| 5324 |
-- Rep_Item_Too_Late, FOnly is set True so that only the freezing rules |
| 5325 |
-- are checked. Note that the case of stream attributes is not clear |
| 5326 |
-- from the RM, but see AI95-00137. Also, the RM seems to disallow |
| 5327 |
-- Storage_Size for derived task types, but that is also clearly |
| 5328 |
-- unintentional. |
| 5329 |
|
| 5330 |
procedure Analyze_Put_Image_TSS_Definition; |
| 5331 |
|
| 5332 |
procedure Analyze_Stream_TSS_Definition (TSS_Nam : TSS_Name_Type); |
| 5333 |
-- Common processing for 'Read, 'Write, 'Input and 'Output attribute |
| 5334 |
-- definition clauses. |
| 5335 |
|
| 5336 |
function Duplicate_Clause return Boolean; |
| 5337 |
-- This routine checks if the aspect for U_Ent being given by attribute |
| 5338 |
-- definition clause N is for an aspect that has already been specified, |
| 5339 |
-- and if so gives an error message. If there is a duplicate, True is |
| 5340 |
-- returned, otherwise there is no error, and False is returned. Size |
| 5341 |
-- and Value_Size are considered to conflict, but for compatibility, |
| 5342 |
-- this is merely a warning. |
| 5343 |
|
| 5344 |
----------------------------------- |
| 5345 |
-- Analyze_Put_Image_TSS_Definition -- |
| 5346 |
----------------------------------- |
| 5347 |
|
| 5348 |
procedure Analyze_Put_Image_TSS_Definition is |
| 5349 |
Subp : Entity_Id := Empty; |
| 5350 |
I : Interp_Index; |
| 5351 |
It : Interp; |
| 5352 |
Pnam : Entity_Id; |
| 5353 |
|
| 5354 |
function Has_Good_Profile |
| 5355 |
(Subp : Entity_Id; |
| 5356 |
Report : Boolean := False) return Boolean; |
| 5357 |
-- Return true if the entity is a subprogram with an appropriate |
| 5358 |
-- profile for the attribute being defined. If result is False and |
| 5359 |
-- Report is True, function emits appropriate error. |
| 5360 |
|
| 5361 |
---------------------- |
| 5362 |
-- Has_Good_Profile -- |
| 5363 |
---------------------- |
| 5364 |
|
| 5365 |
function Has_Good_Profile |
| 5366 |
(Subp : Entity_Id; |
| 5367 |
Report : Boolean := False) return Boolean |
| 5368 |
is |
| 5369 |
F : Entity_Id; |
| 5370 |
Typ : Entity_Id; |
| 5371 |
|
| 5372 |
begin |
| 5373 |
if Ekind (Subp) /= E_Procedure then |
| 5374 |
return False; |
| 5375 |
end if; |
| 5376 |
|
| 5377 |
F := First_Formal (Subp); |
| 5378 |
|
| 5379 |
if No (F) then |
| 5380 |
return False; |
| 5381 |
end if; |
| 5382 |
|
| 5383 |
if Base_Type (Etype (F)) |
| 5384 |
/= Class_Wide_Type (RTE (RE_Root_Buffer_Type)) |
| 5385 |
then |
| 5386 |
if Report then |
| 5387 |
Error_Msg_N |
| 5388 |
("wrong type for Put_Image procedure''s first parameter", |
| 5389 |
Parameter_Type (Parent (F))); |
| 5390 |
end if; |
| 5391 |
|
| 5392 |
return False; |
| 5393 |
end if; |
| 5394 |
|
| 5395 |
if Parameter_Mode (F) /= E_In_Out_Parameter then |
| 5396 |
if Report then |
| 5397 |
Error_Msg_N |
| 5398 |
("wrong mode for Put_Image procedure''s first parameter", |
| 5399 |
Parent (F)); |
| 5400 |
end if; |
| 5401 |
|
| 5402 |
return False; |
| 5403 |
end if; |
| 5404 |
|
| 5405 |
Next_Formal (F); |
| 5406 |
|
| 5407 |
Typ := Etype (F); |
| 5408 |
|
| 5409 |
-- Verify that the prefix of the attribute and the local name for |
| 5410 |
-- the type of the formal match. |
| 5411 |
|
| 5412 |
if Base_Type (Typ) /= Base_Type (Ent) then |
| 5413 |
if Report then |
| 5414 |
Error_Msg_N |
| 5415 |
("wrong type for Put_Image procedure''s second parameter", |
| 5416 |
Parameter_Type (Parent (F))); |
| 5417 |
end if; |
| 5418 |
|
| 5419 |
return False; |
| 5420 |
end if; |
| 5421 |
|
| 5422 |
if Parameter_Mode (F) /= E_In_Parameter then |
| 5423 |
if Report then |
| 5424 |
Error_Msg_N |
| 5425 |
("wrong mode for Put_Image procedure''s second parameter", |
| 5426 |
Parent (F)); |
| 5427 |
end if; |
| 5428 |
|
| 5429 |
return False; |
| 5430 |
end if; |
| 5431 |
|
| 5432 |
if Present (Next_Formal (F)) then |
| 5433 |
return False; |
| 5434 |
end if; |
| 5435 |
|
| 5436 |
return True; |
| 5437 |
end Has_Good_Profile; |
| 5438 |
|
| 5439 |
-- Start of processing for Analyze_Put_Image_TSS_Definition |
| 5440 |
|
| 5441 |
begin |
| 5442 |
if not Is_Type (U_Ent) then |
| 5443 |
Error_Msg_N ("local name must be a subtype", Nam); |
| 5444 |
return; |
| 5445 |
|
| 5446 |
elsif not Is_First_Subtype (U_Ent) then |
| 5447 |
Error_Msg_N ("local name must be a first subtype", Nam); |
| 5448 |
return; |
| 5449 |
end if; |
| 5450 |
|
| 5451 |
Pnam := TSS (Base_Type (U_Ent), TSS_Put_Image); |
| 5452 |
|
| 5453 |
-- If Pnam is present, it can be either inherited from an ancestor |
| 5454 |
-- type (in which case it is legal to redefine it for this type), or |
| 5455 |
-- be a previous definition of the attribute for the same type (in |
| 5456 |
-- which case it is illegal). |
| 5457 |
|
| 5458 |
-- In the first case, it will have been analyzed already, and we can |
| 5459 |
-- check that its profile does not match the expected profile for the |
| 5460 |
-- Put_Image attribute of U_Ent. In the second case, either Pnam has |
| 5461 |
-- been analyzed (and has the expected profile), or it has not been |
| 5462 |
-- analyzed yet (case of a type that has not been frozen yet and for |
| 5463 |
-- which Put_Image has been set using Set_TSS). |
| 5464 |
|
| 5465 |
if Present (Pnam) |
| 5466 |
and then (No (First_Entity (Pnam)) or else Has_Good_Profile (Pnam)) |
| 5467 |
then |
| 5468 |
Error_Msg_Sloc := Sloc (Pnam); |
| 5469 |
Error_Msg_Name_1 := Attr; |
| 5470 |
Error_Msg_N ("% attribute already defined #", Nam); |
| 5471 |
return; |
| 5472 |
end if; |
| 5473 |
|
| 5474 |
Analyze (Expr); |
| 5475 |
|
| 5476 |
if Is_Entity_Name (Expr) then |
| 5477 |
if not Is_Overloaded (Expr) then |
| 5478 |
if Has_Good_Profile (Entity (Expr), Report => True) then |
| 5479 |
Subp := Entity (Expr); |
| 5480 |
end if; |
| 5481 |
|
| 5482 |
else |
| 5483 |
Get_First_Interp (Expr, I, It); |
| 5484 |
while Present (It.Nam) loop |
| 5485 |
if Has_Good_Profile (It.Nam) then |
| 5486 |
Subp := It.Nam; |
| 5487 |
exit; |
| 5488 |
end if; |
| 5489 |
|
| 5490 |
Get_Next_Interp (I, It); |
| 5491 |
end loop; |
| 5492 |
end if; |
| 5493 |
end if; |
| 5494 |
|
| 5495 |
if Present (Subp) then |
| 5496 |
if Is_Abstract_Subprogram (Subp) then |
| 5497 |
Error_Msg_N ("Put_Image subprogram must not be abstract", Expr); |
| 5498 |
return; |
| 5499 |
end if; |
| 5500 |
|
| 5501 |
Set_Entity (Expr, Subp); |
| 5502 |
Set_Etype (Expr, Etype (Subp)); |
| 5503 |
|
| 5504 |
New_Put_Image_Subprogram (N, U_Ent, Subp); |
| 5505 |
|
| 5506 |
else |
| 5507 |
Error_Msg_Name_1 := Attr; |
| 5508 |
Error_Msg_N ("incorrect expression for% attribute", Expr); |
| 5509 |
end if; |
| 5510 |
end Analyze_Put_Image_TSS_Definition; |
| 5511 |
|
| 5512 |
----------------------------------- |
| 5513 |
-- Analyze_Stream_TSS_Definition -- |
| 5514 |
----------------------------------- |
| 5515 |
|
| 5516 |
procedure Analyze_Stream_TSS_Definition (TSS_Nam : TSS_Name_Type) is |
| 5517 |
Subp : Entity_Id := Empty; |
| 5518 |
I : Interp_Index; |
| 5519 |
It : Interp; |
| 5520 |
Pnam : Entity_Id; |
| 5521 |
|
| 5522 |
Is_Read : constant Boolean := (TSS_Nam = TSS_Stream_Read); |
| 5523 |
-- True for Read attribute, False for other attributes |
| 5524 |
|
| 5525 |
function Has_Good_Profile |
| 5526 |
(Subp : Entity_Id; |
| 5527 |
Report : Boolean := False) return Boolean; |
| 5528 |
-- Return true if the entity is a subprogram with an appropriate |
| 5529 |
-- profile for the attribute being defined. If result is False and |
| 5530 |
-- Report is True, function emits appropriate error. |
| 5531 |
|
| 5532 |
---------------------- |
| 5533 |
-- Has_Good_Profile -- |
| 5534 |
---------------------- |
| 5535 |
|
| 5536 |
function Has_Good_Profile |
| 5537 |
(Subp : Entity_Id; |
| 5538 |
Report : Boolean := False) return Boolean |
| 5539 |
is |
| 5540 |
Expected_Ekind : constant array (Boolean) of Entity_Kind := |
| 5541 |
(False => E_Procedure, True => E_Function); |
| 5542 |
Is_Function : constant Boolean := (TSS_Nam = TSS_Stream_Input); |
| 5543 |
F : Entity_Id; |
| 5544 |
Typ : Entity_Id; |
| 5545 |
|
| 5546 |
begin |
| 5547 |
if Ekind (Subp) /= Expected_Ekind (Is_Function) then |
| 5548 |
return False; |
| 5549 |
end if; |
| 5550 |
|
| 5551 |
F := First_Formal (Subp); |
| 5552 |
|
| 5553 |
if No (F) |
| 5554 |
or else Ekind (Etype (F)) /= E_Anonymous_Access_Type |
| 5555 |
or else Base_Type (Designated_Type (Etype (F))) /= |
| 5556 |
Class_Wide_Type (RTE (RE_Root_Stream_Type)) |
| 5557 |
then |
| 5558 |
return False; |
| 5559 |
end if; |
| 5560 |
|
| 5561 |
if not Is_Function then |
| 5562 |
Next_Formal (F); |
| 5563 |
|
| 5564 |
declare |
| 5565 |
Expected_Mode : constant array (Boolean) of Entity_Kind := |
| 5566 |
(False => E_In_Parameter, |
| 5567 |
True => E_Out_Parameter); |
| 5568 |
begin |
| 5569 |
if Parameter_Mode (F) /= Expected_Mode (Is_Read) then |
| 5570 |
return False; |
| 5571 |
end if; |
| 5572 |
end; |
| 5573 |
|
| 5574 |
Typ := Etype (F); |
| 5575 |
|
| 5576 |
else |
| 5577 |
Typ := Etype (Subp); |
| 5578 |
end if; |
| 5579 |
|
| 5580 |
-- Verify that the prefix of the attribute and the local name for |
| 5581 |
-- the type of the formal match. |
| 5582 |
|
| 5583 |
if Base_Type (Typ) /= Base_Type (Ent) then |
| 5584 |
return False; |
| 5585 |
end if; |
| 5586 |
|
| 5587 |
if Present (Next_Formal (F)) then |
| 5588 |
return False; |
| 5589 |
|
| 5590 |
elsif not Is_Scalar_Type (Typ) |
| 5591 |
and then not Is_First_Subtype (Typ) |
| 5592 |
and then not Is_Class_Wide_Type (Typ) |
| 5593 |
then |
| 5594 |
if Report and not Is_First_Subtype (Typ) then |
| 5595 |
Error_Msg_N |
| 5596 |
("subtype of formal in stream operation must be a first " |
| 5597 |
& "subtype", Parameter_Type (Parent (F))); |
| 5598 |
end if; |
| 5599 |
|
| 5600 |
return False; |
| 5601 |
|
| 5602 |
else |
| 5603 |
return True; |
| 5604 |
end if; |
| 5605 |
end Has_Good_Profile; |
| 5606 |
|
| 5607 |
-- Start of processing for Analyze_Stream_TSS_Definition |
| 5608 |
|
| 5609 |
begin |
| 5610 |
FOnly := True; |
| 5611 |
|
| 5612 |
if not Is_Type (U_Ent) then |
| 5613 |
Error_Msg_N ("local name must be a subtype", Nam); |
| 5614 |
return; |
| 5615 |
|
| 5616 |
elsif not Is_First_Subtype (U_Ent) then |
| 5617 |
Error_Msg_N ("local name must be a first subtype", Nam); |
| 5618 |
return; |
| 5619 |
end if; |
| 5620 |
|
| 5621 |
Pnam := TSS (Base_Type (U_Ent), TSS_Nam); |
| 5622 |
|
| 5623 |
-- If Pnam is present, it can be either inherited from an ancestor |
| 5624 |
-- type (in which case it is legal to redefine it for this type), or |
| 5625 |
-- be a previous definition of the attribute for the same type (in |
| 5626 |
-- which case it is illegal). |
| 5627 |
|
| 5628 |
-- In the first case, it will have been analyzed already, and we |
| 5629 |
-- can check that its profile does not match the expected profile |
| 5630 |
-- for a stream attribute of U_Ent. In the second case, either Pnam |
| 5631 |
-- has been analyzed (and has the expected profile), or it has not |
| 5632 |
-- been analyzed yet (case of a type that has not been frozen yet |
| 5633 |
-- and for which the stream attribute has been set using Set_TSS). |
| 5634 |
|
| 5635 |
if Present (Pnam) |
| 5636 |
and then (No (First_Entity (Pnam)) or else Has_Good_Profile (Pnam)) |
| 5637 |
then |
| 5638 |
Error_Msg_Sloc := Sloc (Pnam); |
| 5639 |
Error_Msg_Name_1 := Attr; |
| 5640 |
Error_Msg_N ("% attribute already defined #", Nam); |
| 5641 |
return; |
| 5642 |
end if; |
| 5643 |
|
| 5644 |
Analyze (Expr); |
| 5645 |
|
| 5646 |
if Is_Entity_Name (Expr) then |
| 5647 |
if not Is_Overloaded (Expr) then |
| 5648 |
if Has_Good_Profile (Entity (Expr), Report => True) then |
| 5649 |
Subp := Entity (Expr); |
| 5650 |
end if; |
| 5651 |
|
| 5652 |
else |
| 5653 |
Get_First_Interp (Expr, I, It); |
| 5654 |
while Present (It.Nam) loop |
| 5655 |
if Has_Good_Profile (It.Nam) then |
| 5656 |
Subp := It.Nam; |
| 5657 |
exit; |
| 5658 |
end if; |
| 5659 |
|
| 5660 |
Get_Next_Interp (I, It); |
| 5661 |
end loop; |
| 5662 |
end if; |
| 5663 |
end if; |
| 5664 |
|
| 5665 |
if Present (Subp) then |
| 5666 |
if Is_Abstract_Subprogram (Subp) then |
| 5667 |
Error_Msg_N ("stream subprogram must not be abstract", Expr); |
| 5668 |
return; |
| 5669 |
|
| 5670 |
-- A stream subprogram for an interface type must be a null |
| 5671 |
-- procedure (RM 13.13.2 (38/3)). Note that the class-wide type |
| 5672 |
-- of an interface is not an interface type (3.9.4 (6.b/2)). |
| 5673 |
|
| 5674 |
elsif Is_Interface (U_Ent) |
| 5675 |
and then not Is_Class_Wide_Type (U_Ent) |
| 5676 |
and then not Inside_A_Generic |
| 5677 |
and then |
| 5678 |
(Ekind (Subp) = E_Function |
| 5679 |
or else |
| 5680 |
not Null_Present |
| 5681 |
(Specification |
| 5682 |
(Unit_Declaration_Node (Ultimate_Alias (Subp))))) |
| 5683 |
then |
| 5684 |
Error_Msg_N |
| 5685 |
("stream subprogram for interface type must be null " |
| 5686 |
& "procedure", Expr); |
| 5687 |
end if; |
| 5688 |
|
| 5689 |
Set_Entity (Expr, Subp); |
| 5690 |
Set_Etype (Expr, Etype (Subp)); |
| 5691 |
|
| 5692 |
New_Stream_Subprogram (N, U_Ent, Subp, TSS_Nam); |
| 5693 |
|
| 5694 |
else |
| 5695 |
Error_Msg_Name_1 := Attr; |
| 5696 |
|
| 5697 |
if Is_Class_Wide_Type (Base_Type (Ent)) then |
| 5698 |
Error_Msg_N |
| 5699 |
("incorrect expression for class-wide% attribute", Expr); |
| 5700 |
else |
| 5701 |
Error_Msg_N ("incorrect expression for% attribute", Expr); |
| 5702 |
end if; |
| 5703 |
end if; |
| 5704 |
end Analyze_Stream_TSS_Definition; |
| 5705 |
|
| 5706 |
---------------------- |
| 5707 |
-- Duplicate_Clause -- |
| 5708 |
---------------------- |
| 5709 |
|
| 5710 |
function Duplicate_Clause return Boolean is |
| 5711 |
|
| 5712 |
function Check_One_Attr (Attr_1, Attr_2 : Name_Id) return Boolean; |
| 5713 |
-- Check for one attribute; Attr_1 is the attribute_designator we are |
| 5714 |
-- looking for. Attr_2 is the attribute_designator of the current |
| 5715 |
-- node. Normally, this is called just once by Duplicate_Clause, with |
| 5716 |
-- Attr_1 = Attr_2. However, it needs to be called twice for Size and |
| 5717 |
-- Value_Size, because these mean the same thing. For compatibility, |
| 5718 |
-- we allow specifying both Size and Value_Size, but only if the two |
| 5719 |
-- sizes are equal. |
| 5720 |
|
| 5721 |
-------------------- |
| 5722 |
-- Check_One_Attr -- |
| 5723 |
-------------------- |
| 5724 |
|
| 5725 |
function Check_One_Attr (Attr_1, Attr_2 : Name_Id) return Boolean is |
| 5726 |
A : constant Node_Id := |
| 5727 |
Get_Rep_Item (U_Ent, Attr_1, Check_Parents => False); |
| 5728 |
begin |
| 5729 |
if Present (A) then |
| 5730 |
if Attr_1 = Attr_2 then |
| 5731 |
Error_Msg_Name_1 := Attr_1; |
| 5732 |
Error_Msg_Sloc := Sloc (A); |
| 5733 |
Error_Msg_NE ("aspect% for & previously given#", N, U_Ent); |
| 5734 |
|
| 5735 |
else |
| 5736 |
pragma Assert (Attr_1 in Name_Size | Name_Value_Size); |
| 5737 |
pragma Assert (Attr_2 in Name_Size | Name_Value_Size); |
| 5738 |
|
| 5739 |
Error_Msg_Name_1 := Attr_2; |
| 5740 |
Error_Msg_Name_2 := Attr_1; |
| 5741 |
Error_Msg_Sloc := Sloc (A); |
| 5742 |
Error_Msg_NE ("?% for & conflicts with % #", N, U_Ent); |
| 5743 |
end if; |
| 5744 |
|
| 5745 |
return True; |
| 5746 |
end if; |
| 5747 |
|
| 5748 |
return False; |
| 5749 |
end Check_One_Attr; |
| 5750 |
|
| 5751 |
-- Start of processing for Duplicate_Clause |
| 5752 |
|
| 5753 |
begin |
| 5754 |
-- Nothing to do if this attribute definition clause comes from |
| 5755 |
-- an aspect specification, since we could not be duplicating an |
| 5756 |
-- explicit clause, and we dealt with the case of duplicated aspects |
| 5757 |
-- in Analyze_Aspect_Specifications. |
| 5758 |
|
| 5759 |
if From_Aspect_Specification (N) then |
| 5760 |
return False; |
| 5761 |
end if; |
| 5762 |
|
| 5763 |
-- Special cases for Size and Value_Size |
| 5764 |
|
| 5765 |
if (Chars (N) = Name_Size |
| 5766 |
and then Check_One_Attr (Name_Value_Size, Name_Size)) |
| 5767 |
or else |
| 5768 |
(Chars (N) = Name_Value_Size |
| 5769 |
and then Check_One_Attr (Name_Size, Name_Value_Size)) |
| 5770 |
then |
| 5771 |
return True; |
| 5772 |
end if; |
| 5773 |
|
| 5774 |
-- Normal case (including Size and Value_Size) |
| 5775 |
|
| 5776 |
return Check_One_Attr (Chars (N), Chars (N)); |
| 5777 |
end Duplicate_Clause; |
| 5778 |
|
| 5779 |
-- Start of processing for Analyze_Attribute_Definition_Clause |
| 5780 |
|
| 5781 |
begin |
| 5782 |
-- The following code is a defense against recursion. Not clear that |
| 5783 |
-- this can happen legitimately, but perhaps some error situations can |
| 5784 |
-- cause it, and we did see this recursion during testing. |
| 5785 |
|
| 5786 |
if Analyzed (N) then |
| 5787 |
return; |
| 5788 |
else |
| 5789 |
Set_Analyzed (N, True); |
| 5790 |
end if; |
| 5791 |
|
| 5792 |
Check_Restriction_No_Use_Of_Attribute (N); |
| 5793 |
|
| 5794 |
if Is_Aspect_Id (Chars (N)) then |
| 5795 |
-- 6.1/3 No_Specification_of_Aspect: Identifies an aspect for which |
| 5796 |
-- no aspect_specification, attribute_definition_clause, or pragma |
| 5797 |
-- is given. |
| 5798 |
Check_Restriction_No_Specification_Of_Aspect (N); |
| 5799 |
end if; |
| 5800 |
|
| 5801 |
-- Process Ignore_Rep_Clauses option |
| 5802 |
|
| 5803 |
if Ignore_Rep_Clauses then |
| 5804 |
case Id is |
| 5805 |
|
| 5806 |
-- The following should be ignored. They do not affect legality |
| 5807 |
-- and may be target dependent. The basic idea of -gnatI is to |
| 5808 |
-- ignore any rep clauses that may be target dependent but do not |
| 5809 |
-- affect legality (except possibly to be rejected because they |
| 5810 |
-- are incompatible with the compilation target). |
| 5811 |
|
| 5812 |
when Attribute_Alignment |
| 5813 |
| Attribute_Bit_Order |
| 5814 |
| Attribute_Component_Size |
| 5815 |
| Attribute_Default_Scalar_Storage_Order |
| 5816 |
| Attribute_Machine_Radix |
| 5817 |
| Attribute_Object_Size |
| 5818 |
| Attribute_Scalar_Storage_Order |
| 5819 |
| Attribute_Size |
| 5820 |
| Attribute_Small |
| 5821 |
| Attribute_Stream_Size |
| 5822 |
| Attribute_Value_Size |
| 5823 |
=> |
| 5824 |
Kill_Rep_Clause (N); |
| 5825 |
return; |
| 5826 |
|
| 5827 |
-- The following should not be ignored, because in the first place |
| 5828 |
-- they are reasonably portable, and should not cause problems |
| 5829 |
-- in compiling code from another target, and also they do affect |
| 5830 |
-- legality, e.g. failing to provide a stream attribute for a type |
| 5831 |
-- may make a program illegal. |
| 5832 |
|
| 5833 |
when Attribute_External_Tag |
| 5834 |
| Attribute_Input |
| 5835 |
| Attribute_Output |
| 5836 |
| Attribute_Put_Image |
| 5837 |
| Attribute_Read |
| 5838 |
| Attribute_Simple_Storage_Pool |
| 5839 |
| Attribute_Storage_Pool |
| 5840 |
| Attribute_Storage_Size |
| 5841 |
| Attribute_Write |
| 5842 |
=> |
| 5843 |
null; |
| 5844 |
|
| 5845 |
-- We do not do anything here with address clauses, they will be |
| 5846 |
-- removed by Freeze later on, but for now, it works better to |
| 5847 |
-- keep them in the tree. |
| 5848 |
|
| 5849 |
when Attribute_Address => |
| 5850 |
null; |
| 5851 |
|
| 5852 |
-- Other cases are errors ("attribute& cannot be set with |
| 5853 |
-- definition clause"), which will be caught below. |
| 5854 |
|
| 5855 |
when others => |
| 5856 |
null; |
| 5857 |
end case; |
| 5858 |
end if; |
| 5859 |
|
| 5860 |
Analyze (Nam); |
| 5861 |
Ent := Entity (Nam); |
| 5862 |
|
| 5863 |
if Rep_Item_Too_Early (Ent, N) then |
| 5864 |
return; |
| 5865 |
end if; |
| 5866 |
|
| 5867 |
-- Rep clause applies to (underlying) full view of private or incomplete |
| 5868 |
-- type if we have one (if not, this is a premature use of the type). |
| 5869 |
-- However, some semantic checks need to be done on the specified entity |
| 5870 |
-- i.e. the private view, so we save it in Ent. |
| 5871 |
|
| 5872 |
if Is_Private_Type (Ent) |
| 5873 |
and then Is_Derived_Type (Ent) |
| 5874 |
and then not Is_Tagged_Type (Ent) |
| 5875 |
and then No (Full_View (Ent)) |
| 5876 |
and then No (Underlying_Full_View (Ent)) |
| 5877 |
then |
| 5878 |
U_Ent := Ent; |
| 5879 |
|
| 5880 |
elsif Ekind (Ent) = E_Incomplete_Type then |
| 5881 |
|
| 5882 |
-- The attribute applies to the full view, set the entity of the |
| 5883 |
-- attribute definition accordingly. |
| 5884 |
|
| 5885 |
Ent := Underlying_Type (Ent); |
| 5886 |
U_Ent := Ent; |
| 5887 |
Set_Entity (Nam, Ent); |
| 5888 |
|
| 5889 |
else |
| 5890 |
U_Ent := Underlying_Type (Ent); |
| 5891 |
end if; |
| 5892 |
|
| 5893 |
-- Avoid cascaded error |
| 5894 |
|
| 5895 |
if Etype (Nam) = Any_Type then |
| 5896 |
return; |
| 5897 |
|
| 5898 |
-- Must be declared in current scope or in case of an aspect |
| 5899 |
-- specification, must be visible in current scope. |
| 5900 |
|
| 5901 |
elsif Scope (Ent) /= Current_Scope |
| 5902 |
and then |
| 5903 |
not (From_Aspect_Specification (N) |
| 5904 |
and then Scope_Within_Or_Same (Current_Scope, Scope (Ent))) |
| 5905 |
then |
| 5906 |
Error_Msg_N ("entity must be declared in this scope", Nam); |
| 5907 |
return; |
| 5908 |
|
| 5909 |
-- Must not be a source renaming (we do have some cases where the |
| 5910 |
-- expander generates a renaming, and those cases are OK, in such |
| 5911 |
-- cases any attribute applies to the renamed object as well). |
| 5912 |
|
| 5913 |
elsif Is_Object (Ent) |
| 5914 |
and then Present (Renamed_Object (Ent)) |
| 5915 |
then |
| 5916 |
-- In the case of a renamed object from source, this is an error |
| 5917 |
-- unless the object is an aggregate and the renaming is created |
| 5918 |
-- for an object declaration. |
| 5919 |
|
| 5920 |
if Comes_From_Source (Renamed_Object (Ent)) |
| 5921 |
and then Nkind (Renamed_Object (Ent)) /= N_Aggregate |
| 5922 |
then |
| 5923 |
Get_Name_String (Chars (N)); |
| 5924 |
Error_Msg_Strlen := Name_Len; |
| 5925 |
Error_Msg_String (1 .. Name_Len) := Name_Buffer (1 .. Name_Len); |
| 5926 |
Error_Msg_N |
| 5927 |
("~ clause not allowed for a renaming declaration " |
| 5928 |
& "(RM 13.1(6))", Nam); |
| 5929 |
return; |
| 5930 |
|
| 5931 |
-- For the case of a compiler generated renaming, the attribute |
| 5932 |
-- definition clause applies to the renamed object created by the |
| 5933 |
-- expander. The easiest general way to handle this is to create a |
| 5934 |
-- copy of the attribute definition clause for this object. |
| 5935 |
|
| 5936 |
elsif Is_Entity_Name (Renamed_Object (Ent)) then |
| 5937 |
Insert_Action (N, |
| 5938 |
Make_Attribute_Definition_Clause (Loc, |
| 5939 |
Name => |
| 5940 |
New_Occurrence_Of (Entity (Renamed_Object (Ent)), Loc), |
| 5941 |
Chars => Chars (N), |
| 5942 |
Expression => Duplicate_Subexpr (Expression (N)))); |
| 5943 |
|
| 5944 |
-- If the renamed object is not an entity, it must be a dereference |
| 5945 |
-- of an unconstrained function call, and we must introduce a new |
| 5946 |
-- declaration to capture the expression. This is needed in the case |
| 5947 |
-- of 'Alignment, where the original declaration must be rewritten. |
| 5948 |
|
| 5949 |
else |
| 5950 |
pragma Assert |
| 5951 |
(Nkind (Renamed_Object (Ent)) = N_Explicit_Dereference); |
| 5952 |
null; |
| 5953 |
end if; |
| 5954 |
|
| 5955 |
-- If no underlying entity, use entity itself, applies to some |
| 5956 |
-- previously detected error cases ??? |
| 5957 |
|
| 5958 |
elsif No (U_Ent) then |
| 5959 |
U_Ent := Ent; |
| 5960 |
|
| 5961 |
-- Cannot specify for a subtype (exception Object/Value_Size) |
| 5962 |
|
| 5963 |
elsif Is_Type (U_Ent) |
| 5964 |
and then not Is_First_Subtype (U_Ent) |
| 5965 |
and then Id /= Attribute_Object_Size |
| 5966 |
and then Id /= Attribute_Value_Size |
| 5967 |
and then not From_At_Mod (N) |
| 5968 |
then |
| 5969 |
Error_Msg_N ("cannot specify attribute for subtype", Nam); |
| 5970 |
return; |
| 5971 |
end if; |
| 5972 |
|
| 5973 |
Set_Entity (N, U_Ent); |
| 5974 |
|
| 5975 |
-- Switch on particular attribute |
| 5976 |
|
| 5977 |
case Id is |
| 5978 |
|
| 5979 |
------------- |
| 5980 |
-- Address -- |
| 5981 |
------------- |
| 5982 |
|
| 5983 |
-- Address attribute definition clause |
| 5984 |
|
| 5985 |
when Attribute_Address => Address : begin |
| 5986 |
|
| 5987 |
-- A little error check, catch for X'Address use X'Address; |
| 5988 |
|
| 5989 |
if Nkind (Nam) = N_Identifier |
| 5990 |
and then Nkind (Expr) = N_Attribute_Reference |
| 5991 |
and then Attribute_Name (Expr) = Name_Address |
| 5992 |
and then Nkind (Prefix (Expr)) = N_Identifier |
| 5993 |
and then Chars (Nam) = Chars (Prefix (Expr)) |
| 5994 |
then |
| 5995 |
Error_Msg_NE |
| 5996 |
("address for & is self-referencing", Prefix (Expr), Ent); |
| 5997 |
return; |
| 5998 |
end if; |
| 5999 |
|
| 6000 |
-- Not that special case, carry on with analysis of expression |
| 6001 |
|
| 6002 |
Analyze_And_Resolve (Expr, RTE (RE_Address)); |
| 6003 |
|
| 6004 |
-- Even when ignoring rep clauses we need to indicate that the |
| 6005 |
-- entity has an address clause and thus it is legal to declare |
| 6006 |
-- it imported. Freeze will get rid of the address clause later. |
| 6007 |
-- Also call Set_Address_Taken to indicate that an address clause |
| 6008 |
-- was present, even if we are about to remove it. |
| 6009 |
|
| 6010 |
if Ignore_Rep_Clauses then |
| 6011 |
Set_Address_Taken (U_Ent); |
| 6012 |
|
| 6013 |
if Ekind (U_Ent) in E_Variable | E_Constant then |
| 6014 |
Record_Rep_Item (U_Ent, N); |
| 6015 |
end if; |
| 6016 |
|
| 6017 |
return; |
| 6018 |
end if; |
| 6019 |
|
| 6020 |
if Duplicate_Clause then |
| 6021 |
null; |
| 6022 |
|
| 6023 |
-- Case of address clause for subprogram |
| 6024 |
|
| 6025 |
elsif Is_Subprogram (U_Ent) then |
| 6026 |
if Has_Homonym (U_Ent) then |
| 6027 |
Error_Msg_N |
| 6028 |
("address clause cannot be given for overloaded " |
| 6029 |
& "subprogram", Nam); |
| 6030 |
return; |
| 6031 |
end if; |
| 6032 |
|
| 6033 |
-- For subprograms, all address clauses are permitted, and we |
| 6034 |
-- mark the subprogram as having a deferred freeze so that Gigi |
| 6035 |
-- will not elaborate it too soon. |
| 6036 |
|
| 6037 |
-- Above needs more comments, what is too soon about??? |
| 6038 |
|
| 6039 |
Set_Has_Delayed_Freeze (U_Ent); |
| 6040 |
|
| 6041 |
-- Case of address clause for entry |
| 6042 |
|
| 6043 |
elsif Ekind (U_Ent) = E_Entry then |
| 6044 |
if Nkind (Parent (N)) = N_Task_Body then |
| 6045 |
Error_Msg_N |
| 6046 |
("entry address must be specified in task spec", Nam); |
| 6047 |
return; |
| 6048 |
end if; |
| 6049 |
|
| 6050 |
-- For entries, we require a constant address |
| 6051 |
|
| 6052 |
Check_Constant_Address_Clause (Expr, U_Ent); |
| 6053 |
|
| 6054 |
-- Special checks for task types |
| 6055 |
|
| 6056 |
if Is_Task_Type (Scope (U_Ent)) |
| 6057 |
and then Comes_From_Source (Scope (U_Ent)) |
| 6058 |
then |
| 6059 |
Error_Msg_N |
| 6060 |
("??entry address declared for entry in task type", N); |
| 6061 |
Error_Msg_N |
| 6062 |
("\??only one task can be declared of this type", N); |
| 6063 |
end if; |
| 6064 |
|
| 6065 |
-- Entry address clauses are obsolescent |
| 6066 |
|
| 6067 |
Check_Restriction (No_Obsolescent_Features, N); |
| 6068 |
|
| 6069 |
if Warn_On_Obsolescent_Feature then |
| 6070 |
Error_Msg_N |
| 6071 |
("?j?attaching interrupt to task entry is an obsolescent " |
| 6072 |
& "feature (RM J.7.1)", N); |
| 6073 |
Error_Msg_N |
| 6074 |
("\?j?use interrupt procedure instead", N); |
| 6075 |
end if; |
| 6076 |
|
| 6077 |
-- Case of address clause for an object |
| 6078 |
|
| 6079 |
elsif Ekind (U_Ent) in E_Constant | E_Variable then |
| 6080 |
|
| 6081 |
-- Disallow case of an address clause for an object of an |
| 6082 |
-- indefinite subtype which takes its bounds/discriminant/tag |
| 6083 |
-- from its initial value. Without this, we get a Gigi |
| 6084 |
-- assertion failure for things like |
| 6085 |
-- X : String := Some_Function (...) with Address => ...; |
| 6086 |
-- where the result subtype of the function is unconstrained. |
| 6087 |
-- |
| 6088 |
-- We want to reject two cases: the class-wide case, and the |
| 6089 |
-- case where the FE conjures up a renaming declaration and |
| 6090 |
-- would then otherwise generate an address specification for |
| 6091 |
-- that renaming (which is a malformed tree, which is why Gigi |
| 6092 |
-- complains). |
| 6093 |
|
| 6094 |
if Is_Class_Wide_Type (Etype (U_Ent)) then |
| 6095 |
Error_Msg_N |
| 6096 |
("address specification not supported for class-wide " & |
| 6097 |
"object declaration", Nam); |
| 6098 |
return; |
| 6099 |
elsif Is_Constr_Subt_For_U_Nominal (Etype (U_Ent)) |
| 6100 |
and then |
| 6101 |
Nkind (Parent (U_Ent)) = N_Object_Renaming_Declaration |
| 6102 |
then |
| 6103 |
-- Confirm accuracy of " and dynamic size" message text |
| 6104 |
-- before including it. We want to include that text when |
| 6105 |
-- it is correct because it may be useful to the reader. |
| 6106 |
-- The case where we omit that part of the message text |
| 6107 |
-- might be dead code, but let's not rely on that. |
| 6108 |
|
| 6109 |
Error_Msg_N |
| 6110 |
("address specification not supported for object " & |
| 6111 |
"declaration with indefinite nominal subtype" & |
| 6112 |
(if Size_Known_At_Compile_Time (Etype (U_Ent)) |
| 6113 |
then "" |
| 6114 |
else " and dynamic size"), Nam); |
| 6115 |
return; |
| 6116 |
end if; |
| 6117 |
|
| 6118 |
declare |
| 6119 |
Expr : constant Node_Id := Expression (N); |
| 6120 |
O_Ent : Entity_Id; |
| 6121 |
Off : Boolean; |
| 6122 |
|
| 6123 |
begin |
| 6124 |
-- Exported variables cannot have an address clause, because |
| 6125 |
-- this cancels the effect of the pragma Export. |
| 6126 |
|
| 6127 |
if Is_Exported (U_Ent) then |
| 6128 |
Error_Msg_N |
| 6129 |
("cannot export object with address clause", Nam); |
| 6130 |
return; |
| 6131 |
end if; |
| 6132 |
|
| 6133 |
Find_Overlaid_Entity (N, O_Ent, Off); |
| 6134 |
|
| 6135 |
if Present (O_Ent) then |
| 6136 |
|
| 6137 |
-- If the object overlays a constant object, mark it so |
| 6138 |
|
| 6139 |
if Is_Constant_Object (O_Ent) then |
| 6140 |
Set_Overlays_Constant (U_Ent); |
| 6141 |
end if; |
| 6142 |
|
| 6143 |
-- If the address clause is of the form: |
| 6144 |
|
| 6145 |
-- for X'Address use Y'Address; |
| 6146 |
|
| 6147 |
-- or |
| 6148 |
|
| 6149 |
-- C : constant Address := Y'Address; |
| 6150 |
-- ... |
| 6151 |
-- for X'Address use C; |
| 6152 |
|
| 6153 |
-- then we make an entry in the table to check the size |
| 6154 |
-- and alignment of the overlaying variable. But we defer |
| 6155 |
-- this check till after code generation to take full |
| 6156 |
-- advantage of the annotation done by the back end. |
| 6157 |
|
| 6158 |
-- If the entity has a generic type, the check will be |
| 6159 |
-- performed in the instance if the actual type justifies |
| 6160 |
-- it, and we do not insert the clause in the table to |
| 6161 |
-- prevent spurious warnings. |
| 6162 |
|
| 6163 |
-- Note: we used to test Comes_From_Source and only give |
| 6164 |
-- this warning for source entities, but we have removed |
| 6165 |
-- this test. It really seems bogus to generate overlays |
| 6166 |
-- that would trigger this warning in generated code. |
| 6167 |
-- Furthermore, by removing the test, we handle the |
| 6168 |
-- aspect case properly. |
| 6169 |
|
| 6170 |
if Is_Object (O_Ent) |
| 6171 |
and then not Is_Generic_Formal (O_Ent) |
| 6172 |
and then not Is_Generic_Type (Etype (U_Ent)) |
| 6173 |
and then Address_Clause_Overlay_Warnings |
| 6174 |
then |
| 6175 |
Register_Address_Clause_Check |
| 6176 |
(N, U_Ent, No_Uint, O_Ent, Off); |
| 6177 |
end if; |
| 6178 |
|
| 6179 |
-- If the overlay changes the storage order, warn since |
| 6180 |
-- the construct is not really supported by the back end. |
| 6181 |
-- Also mark the entity as being volatile to block the |
| 6182 |
-- optimizer, even if there is no warranty on the result. |
| 6183 |
|
| 6184 |
if (Is_Record_Type (Etype (U_Ent)) |
| 6185 |
or else Is_Array_Type (Etype (U_Ent))) |
| 6186 |
and then (Is_Record_Type (Etype (O_Ent)) |
| 6187 |
or else Is_Array_Type (Etype (O_Ent))) |
| 6188 |
and then Reverse_Storage_Order (Etype (U_Ent)) /= |
| 6189 |
Reverse_Storage_Order (Etype (O_Ent)) |
| 6190 |
then |
| 6191 |
Error_Msg_N |
| 6192 |
("??overlay changes scalar storage order", Expr); |
| 6193 |
Set_Treat_As_Volatile (U_Ent); |
| 6194 |
end if; |
| 6195 |
|
| 6196 |
else |
| 6197 |
-- If this is not an overlay, mark a variable as being |
| 6198 |
-- volatile to prevent unwanted optimizations. It's a |
| 6199 |
-- conservative interpretation of RM 13.3(19) for the |
| 6200 |
-- cases where the compiler cannot detect potential |
| 6201 |
-- aliasing issues easily and it also covers the case |
| 6202 |
-- of an absolute address where the volatile aspect is |
| 6203 |
-- kind of implicit. |
| 6204 |
|
| 6205 |
if Ekind (U_Ent) = E_Variable then |
| 6206 |
Set_Treat_As_Volatile (U_Ent); |
| 6207 |
end if; |
| 6208 |
|
| 6209 |
-- Make an entry in the table for an absolute address as |
| 6210 |
-- above to check that the value is compatible with the |
| 6211 |
-- alignment of the object. |
| 6212 |
|
| 6213 |
declare |
| 6214 |
Addr : constant Node_Id := Address_Value (Expr); |
| 6215 |
begin |
| 6216 |
if Compile_Time_Known_Value (Addr) |
| 6217 |
and then Address_Clause_Overlay_Warnings |
| 6218 |
then |
| 6219 |
Register_Address_Clause_Check |
| 6220 |
(N, U_Ent, Expr_Value (Addr), Empty, False); |
| 6221 |
end if; |
| 6222 |
end; |
| 6223 |
end if; |
| 6224 |
|
| 6225 |
-- Issue an unconditional warning for a constant overlaying |
| 6226 |
-- a variable. For the reverse case, we will issue it only |
| 6227 |
-- if the variable is modified. |
| 6228 |
-- Within a generic unit an In_Parameter is a constant. |
| 6229 |
-- It can be instantiated with a variable, in which case |
| 6230 |
-- there will be a warning on the instance. |
| 6231 |
|
| 6232 |
if Ekind (U_Ent) = E_Constant |
| 6233 |
and then Present (O_Ent) |
| 6234 |
and then Ekind (O_Ent) /= E_Generic_In_Parameter |
| 6235 |
and then not Overlays_Constant (U_Ent) |
| 6236 |
and then Address_Clause_Overlay_Warnings |
| 6237 |
then |
| 6238 |
Error_Msg_N ("?o?constant overlays a variable", Expr); |
| 6239 |
|
| 6240 |
-- Imported variables can have an address clause, but then |
| 6241 |
-- the import is pretty meaningless except to suppress |
| 6242 |
-- initializations, so we do not need such variables to |
| 6243 |
-- be statically allocated (and in fact it causes trouble |
| 6244 |
-- if the address clause is a local value). |
| 6245 |
|
| 6246 |
elsif Is_Imported (U_Ent) then |
| 6247 |
Set_Is_Statically_Allocated (U_Ent, False); |
| 6248 |
end if; |
| 6249 |
|
| 6250 |
-- We mark a possible modification of a variable with an |
| 6251 |
-- address clause, since it is likely aliasing is occurring. |
| 6252 |
|
| 6253 |
Note_Possible_Modification (Nam, Sure => False); |
| 6254 |
|
| 6255 |
-- Legality checks on the address clause for initialized |
| 6256 |
-- objects is deferred until the freeze point, because |
| 6257 |
-- a subsequent pragma might indicate that the object |
| 6258 |
-- is imported and thus not initialized. Also, the address |
| 6259 |
-- clause might involve entities that have yet to be |
| 6260 |
-- elaborated. |
| 6261 |
|
| 6262 |
Set_Has_Delayed_Freeze (U_Ent); |
| 6263 |
|
| 6264 |
-- If an initialization call has been generated for this |
| 6265 |
-- object, it needs to be deferred to after the freeze node |
| 6266 |
-- we have just now added, otherwise GIGI will see a |
| 6267 |
-- reference to the variable (as actual to the IP call) |
| 6268 |
-- before its definition. |
| 6269 |
|
| 6270 |
declare |
| 6271 |
Init_Call : constant Node_Id := |
| 6272 |
Remove_Init_Call (U_Ent, N); |
| 6273 |
|
| 6274 |
begin |
| 6275 |
if Present (Init_Call) then |
| 6276 |
Append_Freeze_Action (U_Ent, Init_Call); |
| 6277 |
|
| 6278 |
-- Reset Initialization_Statements pointer so that |
| 6279 |
-- if there is a pragma Import further down, it can |
| 6280 |
-- clear any default initialization. |
| 6281 |
|
| 6282 |
Set_Initialization_Statements (U_Ent, Init_Call); |
| 6283 |
end if; |
| 6284 |
end; |
| 6285 |
|
| 6286 |
-- Entity has delayed freeze, so we will generate an |
| 6287 |
-- alignment check at the freeze point unless suppressed. |
| 6288 |
|
| 6289 |
if not Range_Checks_Suppressed (U_Ent) |
| 6290 |
and then not Alignment_Checks_Suppressed (U_Ent) |
| 6291 |
then |
| 6292 |
Set_Check_Address_Alignment (N); |
| 6293 |
end if; |
| 6294 |
|
| 6295 |
-- Kill the size check code, since we are not allocating |
| 6296 |
-- the variable, it is somewhere else. |
| 6297 |
|
| 6298 |
Kill_Size_Check_Code (U_Ent); |
| 6299 |
end; |
| 6300 |
|
| 6301 |
-- Not a valid entity for an address clause |
| 6302 |
|
| 6303 |
else |
| 6304 |
Error_Msg_N ("address cannot be given for &", Nam); |
| 6305 |
end if; |
| 6306 |
end Address; |
| 6307 |
|
| 6308 |
--------------- |
| 6309 |
-- Alignment -- |
| 6310 |
--------------- |
| 6311 |
|
| 6312 |
-- Alignment attribute definition clause |
| 6313 |
|
| 6314 |
when Attribute_Alignment => Alignment : declare |
| 6315 |
Align : constant Uint := Get_Alignment_Value (Expr); |
| 6316 |
Max_Align : constant Uint := UI_From_Int (Maximum_Alignment); |
| 6317 |
|
| 6318 |
begin |
| 6319 |
FOnly := True; |
| 6320 |
|
| 6321 |
if not Is_Type (U_Ent) |
| 6322 |
and then Ekind (U_Ent) /= E_Variable |
| 6323 |
and then Ekind (U_Ent) /= E_Constant |
| 6324 |
then |
| 6325 |
Error_Msg_N ("alignment cannot be given for &", Nam); |
| 6326 |
|
| 6327 |
elsif Duplicate_Clause then |
| 6328 |
null; |
| 6329 |
|
| 6330 |
elsif Present (Align) then |
| 6331 |
Set_Has_Alignment_Clause (U_Ent); |
| 6332 |
|
| 6333 |
-- Tagged type case, check for attempt to set alignment to a |
| 6334 |
-- value greater than Max_Align, and reset if so. |
| 6335 |
|
| 6336 |
if Is_Tagged_Type (U_Ent) and then Align > Max_Align then |
| 6337 |
Error_Msg_N |
| 6338 |
("alignment for & set to Maximum_Aligment??", Nam); |
| 6339 |
Set_Alignment (U_Ent, Max_Align); |
| 6340 |
|
| 6341 |
-- Because Object_Size must be multiple of Alignment (in bits), |
| 6342 |
-- System_Max_Integer_Size limit for discrete and fixed point |
| 6343 |
-- types implies a limit on alignment for such types. |
| 6344 |
|
| 6345 |
elsif (Is_Discrete_Type (U_Ent) |
| 6346 |
or else Is_Fixed_Point_Type (U_Ent)) |
| 6347 |
and then Align > System_Max_Integer_Size / System_Storage_Unit |
| 6348 |
then |
| 6349 |
Error_Msg_N |
| 6350 |
("specified alignment too large for discrete or fixed " & |
| 6351 |
"point type", Expr); |
| 6352 |
Set_Alignment |
| 6353 |
(U_Ent, UI_From_Int (System_Max_Integer_Size / |
| 6354 |
System_Storage_Unit)); |
| 6355 |
|
| 6356 |
-- All other cases |
| 6357 |
|
| 6358 |
else |
| 6359 |
Set_Alignment (U_Ent, Align); |
| 6360 |
end if; |
| 6361 |
|
| 6362 |
-- For an array type, U_Ent is the first subtype. In that case, |
| 6363 |
-- also set the alignment of the anonymous base type so that |
| 6364 |
-- other subtypes (such as the itypes for aggregates of the |
| 6365 |
-- type) also receive the expected alignment. |
| 6366 |
|
| 6367 |
if Is_Array_Type (U_Ent) then |
| 6368 |
Set_Alignment (Base_Type (U_Ent), Align); |
| 6369 |
end if; |
| 6370 |
end if; |
| 6371 |
end Alignment; |
| 6372 |
|
| 6373 |
--------------- |
| 6374 |
-- Bit_Order -- |
| 6375 |
--------------- |
| 6376 |
|
| 6377 |
-- Bit_Order attribute definition clause |
| 6378 |
|
| 6379 |
when Attribute_Bit_Order => |
| 6380 |
if not Is_Record_Type (U_Ent) then |
| 6381 |
Error_Msg_N |
| 6382 |
("Bit_Order can only be defined for record type", Nam); |
| 6383 |
|
| 6384 |
elsif Is_Tagged_Type (U_Ent) and then Is_Derived_Type (U_Ent) then |
| 6385 |
Error_Msg_N |
| 6386 |
("Bit_Order cannot be defined for record extensions", Nam); |
| 6387 |
|
| 6388 |
elsif Duplicate_Clause then |
| 6389 |
null; |
| 6390 |
|
| 6391 |
else |
| 6392 |
Analyze_And_Resolve (Expr, RTE (RE_Bit_Order)); |
| 6393 |
|
| 6394 |
if Etype (Expr) = Any_Type then |
| 6395 |
return; |
| 6396 |
|
| 6397 |
elsif not Is_OK_Static_Expression (Expr) then |
| 6398 |
Flag_Non_Static_Expr |
| 6399 |
("Bit_Order requires static expression!", Expr); |
| 6400 |
|
| 6401 |
elsif (Expr_Value (Expr) = 0) /= Bytes_Big_Endian then |
| 6402 |
Set_Reverse_Bit_Order (Base_Type (U_Ent), True); |
| 6403 |
end if; |
| 6404 |
end if; |
| 6405 |
|
| 6406 |
-------------------- |
| 6407 |
-- Component_Size -- |
| 6408 |
-------------------- |
| 6409 |
|
| 6410 |
-- Component_Size attribute definition clause |
| 6411 |
|
| 6412 |
when Attribute_Component_Size => Component_Size_Case : declare |
| 6413 |
Csize : constant Uint := Static_Integer (Expr); |
| 6414 |
Ctyp : Entity_Id; |
| 6415 |
Btype : Entity_Id; |
| 6416 |
Biased : Boolean; |
| 6417 |
New_Ctyp : Entity_Id; |
| 6418 |
Decl : Node_Id; |
| 6419 |
|
| 6420 |
begin |
| 6421 |
if not Is_Array_Type (U_Ent) then |
| 6422 |
Error_Msg_N ("component size requires array type", Nam); |
| 6423 |
return; |
| 6424 |
end if; |
| 6425 |
|
| 6426 |
Btype := Base_Type (U_Ent); |
| 6427 |
Ctyp := Component_Type (Btype); |
| 6428 |
|
| 6429 |
if Duplicate_Clause then |
| 6430 |
null; |
| 6431 |
|
| 6432 |
elsif Rep_Item_Too_Early (Btype, N) then |
| 6433 |
null; |
| 6434 |
|
| 6435 |
elsif Present (Csize) then |
| 6436 |
Check_Size (Expr, Ctyp, Csize, Biased); |
| 6437 |
|
| 6438 |
-- For the biased case, build a declaration for a subtype that |
| 6439 |
-- will be used to represent the biased subtype that reflects |
| 6440 |
-- the biased representation of components. We need the subtype |
| 6441 |
-- to get proper conversions on referencing elements of the |
| 6442 |
-- array. |
| 6443 |
|
| 6444 |
if Biased then |
| 6445 |
New_Ctyp := |
| 6446 |
Make_Defining_Identifier (Loc, |
| 6447 |
Chars => |
| 6448 |
New_External_Name (Chars (U_Ent), 'C', 0, 'T')); |
| 6449 |
|
| 6450 |
Decl := |
| 6451 |
Make_Subtype_Declaration (Loc, |
| 6452 |
Defining_Identifier => New_Ctyp, |
| 6453 |
Subtype_Indication => |
| 6454 |
New_Occurrence_Of (Component_Type (Btype), Loc)); |
| 6455 |
|
| 6456 |
Set_Parent (Decl, N); |
| 6457 |
Analyze (Decl, Suppress => All_Checks); |
| 6458 |
|
| 6459 |
Set_Has_Delayed_Freeze (New_Ctyp, False); |
| 6460 |
Reinit_Esize (New_Ctyp); |
| 6461 |
Set_RM_Size (New_Ctyp, Csize); |
| 6462 |
Reinit_Alignment (New_Ctyp); |
| 6463 |
Set_Is_Itype (New_Ctyp, True); |
| 6464 |
Set_Associated_Node_For_Itype (New_Ctyp, U_Ent); |
| 6465 |
|
| 6466 |
Set_Component_Type (Btype, New_Ctyp); |
| 6467 |
Set_Biased (New_Ctyp, N, "component size clause"); |
| 6468 |
end if; |
| 6469 |
|
| 6470 |
Set_Component_Size (Btype, Csize); |
| 6471 |
|
| 6472 |
-- Deal with warning on overridden size |
| 6473 |
|
| 6474 |
if Warn_On_Overridden_Size |
| 6475 |
and then Has_Size_Clause (Ctyp) |
| 6476 |
and then RM_Size (Ctyp) /= Csize |
| 6477 |
then |
| 6478 |
Error_Msg_NE |
| 6479 |
("component size overrides size clause for&?.s?", N, Ctyp); |
| 6480 |
end if; |
| 6481 |
|
| 6482 |
Set_Has_Component_Size_Clause (Btype, True); |
| 6483 |
Set_Has_Non_Standard_Rep (Btype, True); |
| 6484 |
end if; |
| 6485 |
end Component_Size_Case; |
| 6486 |
|
| 6487 |
----------------------- |
| 6488 |
-- Constant_Indexing -- |
| 6489 |
----------------------- |
| 6490 |
|
| 6491 |
when Attribute_Constant_Indexing => |
| 6492 |
null; |
| 6493 |
|
| 6494 |
--------- |
| 6495 |
-- CPU -- |
| 6496 |
--------- |
| 6497 |
|
| 6498 |
when Attribute_CPU => |
| 6499 |
pragma Assert (From_Aspect_Specification (N)); |
| 6500 |
-- The parser forbids this clause in source code, so it must have |
| 6501 |
-- come from an aspect specification. |
| 6502 |
|
| 6503 |
if not Is_Task_Type (U_Ent) then |
| 6504 |
Error_Msg_N ("'C'P'U can only be defined for task", Nam); |
| 6505 |
|
| 6506 |
elsif Duplicate_Clause then |
| 6507 |
null; |
| 6508 |
|
| 6509 |
else |
| 6510 |
-- The expression must be analyzed in the special manner |
| 6511 |
-- described in "Handling of Default and Per-Object |
| 6512 |
-- Expressions" in sem.ads. |
| 6513 |
|
| 6514 |
-- The visibility to the components must be established |
| 6515 |
-- and restored before and after analysis. |
| 6516 |
|
| 6517 |
Push_Type (U_Ent); |
| 6518 |
Preanalyze_Spec_Expression (Expr, RTE (RE_CPU_Range)); |
| 6519 |
Pop_Type (U_Ent); |
| 6520 |
|
| 6521 |
-- AI12-0117-1, "Restriction No_Tasks_Unassigned_To_CPU": |
| 6522 |
-- If the expression is static, and its value is |
| 6523 |
-- System.Multiprocessors.Not_A_Specific_CPU (i.e. zero) then |
| 6524 |
-- that's a violation of No_Tasks_Unassigned_To_CPU. It might |
| 6525 |
-- seem better to refer to Not_A_Specific_CPU here, but that |
| 6526 |
-- involves a lot of horsing around with Rtsfind, and this |
| 6527 |
-- value is not going to change, so it's better to hardwire |
| 6528 |
-- Uint_0. |
| 6529 |
-- |
| 6530 |
-- AI12-0055-1, "All properties of a usage profile are defined |
| 6531 |
-- by pragmas": If the expression is nonstatic, that's a |
| 6532 |
-- violation of No_Dynamic_CPU_Assignment. |
| 6533 |
|
| 6534 |
if Is_OK_Static_Expression (Expr) then |
| 6535 |
if Expr_Value (Expr) = Uint_0 then |
| 6536 |
Check_Restriction (No_Tasks_Unassigned_To_CPU, Expr); |
| 6537 |
end if; |
| 6538 |
else |
| 6539 |
Check_Restriction (No_Dynamic_CPU_Assignment, Expr); |
| 6540 |
end if; |
| 6541 |
end if; |
| 6542 |
|
| 6543 |
---------------------- |
| 6544 |
-- Default_Iterator -- |
| 6545 |
---------------------- |
| 6546 |
|
| 6547 |
when Attribute_Default_Iterator => Default_Iterator : declare |
| 6548 |
begin |
| 6549 |
-- If target type is untagged, further checks are irrelevant |
| 6550 |
|
| 6551 |
if not Is_Tagged_Type (U_Ent) then |
| 6552 |
Error_Msg_N |
| 6553 |
("aspect Default_Iterator can only apply to a tagged type", |
| 6554 |
Nam); |
| 6555 |
return; |
| 6556 |
end if; |
| 6557 |
|
| 6558 |
declare |
| 6559 |
Parent_Aspect : constant Node_Id := |
| 6560 |
Find_Aspect (U_Ent, Aspect_Default_Iterator); |
| 6561 |
begin |
| 6562 |
-- If the attribute definition clause comes from an aspect that |
| 6563 |
-- is not Comes_From_Source, then the aspect must be inherited |
| 6564 |
-- from a parent type, in which case the operation has already |
| 6565 |
-- been set properly, and there's no need to do the check. |
| 6566 |
|
| 6567 |
if No (Parent_Aspect) |
| 6568 |
or else Comes_From_Source (Parent_Aspect) |
| 6569 |
then |
| 6570 |
Check_Iterator_Functions (Typ => U_Ent, Expr => Expr); |
| 6571 |
end if; |
| 6572 |
end; |
| 6573 |
|
| 6574 |
Analyze (Expr); |
| 6575 |
|
| 6576 |
if not Is_Entity_Name (Expr) |
| 6577 |
or else Ekind (Entity (Expr)) /= E_Function |
| 6578 |
then |
| 6579 |
Error_Msg_N ("aspect Iterator must be a function", Expr); |
| 6580 |
return; |
| 6581 |
end if; |
| 6582 |
end Default_Iterator; |
| 6583 |
|
| 6584 |
------------------------ |
| 6585 |
-- Dispatching_Domain -- |
| 6586 |
------------------------ |
| 6587 |
|
| 6588 |
when Attribute_Dispatching_Domain => |
| 6589 |
pragma Assert (From_Aspect_Specification (N)); |
| 6590 |
-- The parser forbids this clause in source code, so it must have |
| 6591 |
-- come from an aspect specification. |
| 6592 |
|
| 6593 |
if not Is_Task_Type (U_Ent) then |
| 6594 |
Error_Msg_N |
| 6595 |
("Dispatching_Domain can only be defined for task", Nam); |
| 6596 |
|
| 6597 |
elsif Duplicate_Clause then |
| 6598 |
null; |
| 6599 |
|
| 6600 |
else |
| 6601 |
-- The expression must be analyzed in the special manner |
| 6602 |
-- described in "Handling of Default and Per-Object |
| 6603 |
-- Expressions" in sem.ads. |
| 6604 |
|
| 6605 |
-- The visibility to the components must be restored |
| 6606 |
|
| 6607 |
Push_Type (U_Ent); |
| 6608 |
|
| 6609 |
Preanalyze_Spec_Expression |
| 6610 |
(Expr, RTE (RE_Dispatching_Domain)); |
| 6611 |
|
| 6612 |
Pop_Type (U_Ent); |
| 6613 |
end if; |
| 6614 |
|
| 6615 |
------------------ |
| 6616 |
-- External_Tag -- |
| 6617 |
------------------ |
| 6618 |
|
| 6619 |
when Attribute_External_Tag => |
| 6620 |
if not Is_Tagged_Type (U_Ent) then |
| 6621 |
Error_Msg_N ("should be a tagged type", Nam); |
| 6622 |
end if; |
| 6623 |
|
| 6624 |
if Duplicate_Clause then |
| 6625 |
null; |
| 6626 |
|
| 6627 |
else |
| 6628 |
Analyze_And_Resolve (Expr, Standard_String); |
| 6629 |
|
| 6630 |
if not Is_OK_Static_Expression (Expr) then |
| 6631 |
Flag_Non_Static_Expr |
| 6632 |
("static string required for tag name!", Nam); |
| 6633 |
end if; |
| 6634 |
|
| 6635 |
if not Is_Library_Level_Entity (U_Ent) then |
| 6636 |
Error_Msg_NE |
| 6637 |
("??non-unique external tag supplied for &", N, U_Ent); |
| 6638 |
Error_Msg_N |
| 6639 |
("\??same external tag applies to all subprogram calls", |
| 6640 |
N); |
| 6641 |
Error_Msg_N |
| 6642 |
("\??corresponding internal tag cannot be obtained", N); |
| 6643 |
end if; |
| 6644 |
end if; |
| 6645 |
|
| 6646 |
-------------------------- |
| 6647 |
-- Implicit_Dereference -- |
| 6648 |
-------------------------- |
| 6649 |
|
| 6650 |
when Attribute_Implicit_Dereference => |
| 6651 |
|
| 6652 |
-- Legality checks already performed at the point of the type |
| 6653 |
-- declaration, aspect is not delayed. |
| 6654 |
|
| 6655 |
null; |
| 6656 |
|
| 6657 |
----------- |
| 6658 |
-- Input -- |
| 6659 |
----------- |
| 6660 |
|
| 6661 |
when Attribute_Input => |
| 6662 |
Analyze_Stream_TSS_Definition (TSS_Stream_Input); |
| 6663 |
Set_Has_Specified_Stream_Input (Ent); |
| 6664 |
|
| 6665 |
------------------------ |
| 6666 |
-- Interrupt_Priority -- |
| 6667 |
------------------------ |
| 6668 |
|
| 6669 |
when Attribute_Interrupt_Priority => |
| 6670 |
pragma Assert (From_Aspect_Specification (N)); |
| 6671 |
-- The parser forbids this clause in source code, so it must have |
| 6672 |
-- come from an aspect specification. |
| 6673 |
|
| 6674 |
if not Is_Concurrent_Type (U_Ent) then |
| 6675 |
Error_Msg_N |
| 6676 |
("Interrupt_Priority can only be defined for task and " |
| 6677 |
& "protected object", Nam); |
| 6678 |
|
| 6679 |
elsif Duplicate_Clause then |
| 6680 |
null; |
| 6681 |
|
| 6682 |
else |
| 6683 |
-- The expression must be analyzed in the special manner |
| 6684 |
-- described in "Handling of Default and Per-Object |
| 6685 |
-- Expressions" in sem.ads. |
| 6686 |
|
| 6687 |
-- The visibility to the components must be restored |
| 6688 |
|
| 6689 |
Push_Type (U_Ent); |
| 6690 |
|
| 6691 |
Preanalyze_Spec_Expression |
| 6692 |
(Expr, RTE (RE_Interrupt_Priority)); |
| 6693 |
|
| 6694 |
Pop_Type (U_Ent); |
| 6695 |
|
| 6696 |
-- Check the No_Task_At_Interrupt_Priority restriction |
| 6697 |
|
| 6698 |
if Is_Task_Type (U_Ent) then |
| 6699 |
Check_Restriction (No_Task_At_Interrupt_Priority, N); |
| 6700 |
end if; |
| 6701 |
end if; |
| 6702 |
|
| 6703 |
-------------- |
| 6704 |
-- Iterable -- |
| 6705 |
-------------- |
| 6706 |
|
| 6707 |
when Attribute_Iterable => |
| 6708 |
Analyze (Expr); |
| 6709 |
|
| 6710 |
if Nkind (Expr) /= N_Aggregate then |
| 6711 |
Error_Msg_N ("aspect Iterable must be an aggregate", Expr); |
| 6712 |
return; |
| 6713 |
end if; |
| 6714 |
|
| 6715 |
declare |
| 6716 |
Assoc : Node_Id; |
| 6717 |
|
| 6718 |
begin |
| 6719 |
Assoc := First (Component_Associations (Expr)); |
| 6720 |
while Present (Assoc) loop |
| 6721 |
Analyze (Expression (Assoc)); |
| 6722 |
|
| 6723 |
if not Is_Entity_Name (Expression (Assoc)) |
| 6724 |
or else Ekind (Entity (Expression (Assoc))) /= E_Function |
| 6725 |
then |
| 6726 |
Error_Msg_N ("value must be a function", Assoc); |
| 6727 |
end if; |
| 6728 |
|
| 6729 |
Next (Assoc); |
| 6730 |
end loop; |
| 6731 |
end; |
| 6732 |
|
| 6733 |
---------------------- |
| 6734 |
-- Iterator_Element -- |
| 6735 |
---------------------- |
| 6736 |
|
| 6737 |
when Attribute_Iterator_Element => |
| 6738 |
Analyze (Expr); |
| 6739 |
|
| 6740 |
if not Is_Entity_Name (Expr) |
| 6741 |
or else not Is_Type (Entity (Expr)) |
| 6742 |
then |
| 6743 |
Error_Msg_N ("aspect Iterator_Element must be a type", Expr); |
| 6744 |
return; |
| 6745 |
end if; |
| 6746 |
|
| 6747 |
------------------- |
| 6748 |
-- Machine_Radix -- |
| 6749 |
------------------- |
| 6750 |
|
| 6751 |
-- Machine radix attribute definition clause |
| 6752 |
|
| 6753 |
when Attribute_Machine_Radix => Machine_Radix : declare |
| 6754 |
Radix : constant Uint := Static_Integer (Expr); |
| 6755 |
|
| 6756 |
begin |
| 6757 |
if not Is_Decimal_Fixed_Point_Type (U_Ent) then |
| 6758 |
Error_Msg_N ("decimal fixed-point type expected for &", Nam); |
| 6759 |
|
| 6760 |
elsif Duplicate_Clause then |
| 6761 |
null; |
| 6762 |
|
| 6763 |
elsif Present (Radix) then |
| 6764 |
Set_Has_Machine_Radix_Clause (U_Ent); |
| 6765 |
Set_Has_Non_Standard_Rep (Base_Type (U_Ent)); |
| 6766 |
|
| 6767 |
if Radix = 2 then |
| 6768 |
null; |
| 6769 |
|
| 6770 |
elsif Radix = 10 then |
| 6771 |
Set_Machine_Radix_10 (U_Ent); |
| 6772 |
|
| 6773 |
else |
| 6774 |
Error_Msg_N ("machine radix value must be 2 or 10", Expr); |
| 6775 |
end if; |
| 6776 |
end if; |
| 6777 |
end Machine_Radix; |
| 6778 |
|
| 6779 |
----------------- |
| 6780 |
-- Object_Size -- |
| 6781 |
----------------- |
| 6782 |
|
| 6783 |
-- Object_Size attribute definition clause |
| 6784 |
|
| 6785 |
when Attribute_Object_Size => Object_Size : declare |
| 6786 |
Size : constant Uint := Static_Integer (Expr); |
| 6787 |
|
| 6788 |
Biased : Boolean; |
| 6789 |
pragma Warnings (Off, Biased); |
| 6790 |
|
| 6791 |
begin |
| 6792 |
if not Is_Type (U_Ent) then |
| 6793 |
Error_Msg_N ("Object_Size cannot be given for &", Nam); |
| 6794 |
|
| 6795 |
elsif Duplicate_Clause then |
| 6796 |
null; |
| 6797 |
|
| 6798 |
else |
| 6799 |
Check_Size (Expr, U_Ent, Size, Biased); |
| 6800 |
|
| 6801 |
if No (Size) or else Size <= 0 then |
| 6802 |
Error_Msg_N ("Object_Size must be positive", Expr); |
| 6803 |
|
| 6804 |
elsif Is_Scalar_Type (U_Ent) then |
| 6805 |
if Size /= 8 and then Size /= 16 and then Size /= 32 |
| 6806 |
and then UI_Mod (Size, 64) /= 0 |
| 6807 |
then |
| 6808 |
Error_Msg_N |
| 6809 |
("Object_Size must be 8, 16, 32, or multiple of 64", |
| 6810 |
Expr); |
| 6811 |
end if; |
| 6812 |
|
| 6813 |
elsif Size mod 8 /= 0 then |
| 6814 |
Error_Msg_N ("Object_Size must be a multiple of 8", Expr); |
| 6815 |
end if; |
| 6816 |
|
| 6817 |
Set_Esize (U_Ent, Size); |
| 6818 |
Set_Has_Object_Size_Clause (U_Ent); |
| 6819 |
Alignment_Check_For_Size_Change (U_Ent, Size); |
| 6820 |
end if; |
| 6821 |
end Object_Size; |
| 6822 |
|
| 6823 |
------------ |
| 6824 |
-- Output -- |
| 6825 |
------------ |
| 6826 |
|
| 6827 |
when Attribute_Output => |
| 6828 |
Analyze_Stream_TSS_Definition (TSS_Stream_Output); |
| 6829 |
Set_Has_Specified_Stream_Output (Ent); |
| 6830 |
|
| 6831 |
-------------- |
| 6832 |
-- Priority -- |
| 6833 |
-------------- |
| 6834 |
|
| 6835 |
when Attribute_Priority => |
| 6836 |
|
| 6837 |
-- Priority attribute definition clause not allowed except from |
| 6838 |
-- aspect specification. |
| 6839 |
|
| 6840 |
if From_Aspect_Specification (N) then |
| 6841 |
if not (Is_Concurrent_Type (U_Ent) |
| 6842 |
or else Ekind (U_Ent) = E_Procedure) |
| 6843 |
then |
| 6844 |
Error_Msg_N |
| 6845 |
("Priority can only be defined for task and protected " |
| 6846 |
& "object", Nam); |
| 6847 |
|
| 6848 |
elsif Duplicate_Clause then |
| 6849 |
null; |
| 6850 |
|
| 6851 |
else |
| 6852 |
-- The expression must be analyzed in the special manner |
| 6853 |
-- described in "Handling of Default and Per-Object |
| 6854 |
-- Expressions" in sem.ads. |
| 6855 |
|
| 6856 |
-- The visibility to the components must be restored |
| 6857 |
|
| 6858 |
Push_Type (U_Ent); |
| 6859 |
Preanalyze_Spec_Expression (Expr, Standard_Integer); |
| 6860 |
Pop_Type (U_Ent); |
| 6861 |
|
| 6862 |
if not Is_OK_Static_Expression (Expr) then |
| 6863 |
Check_Restriction (Static_Priorities, Expr); |
| 6864 |
end if; |
| 6865 |
end if; |
| 6866 |
|
| 6867 |
else |
| 6868 |
Error_Msg_N |
| 6869 |
("attribute& cannot be set with definition clause", N); |
| 6870 |
end if; |
| 6871 |
|
| 6872 |
--------------- |
| 6873 |
-- Put_Image -- |
| 6874 |
--------------- |
| 6875 |
|
| 6876 |
when Attribute_Put_Image => |
| 6877 |
Analyze_Put_Image_TSS_Definition; |
| 6878 |
|
| 6879 |
---------- |
| 6880 |
-- Read -- |
| 6881 |
---------- |
| 6882 |
|
| 6883 |
when Attribute_Read => |
| 6884 |
Analyze_Stream_TSS_Definition (TSS_Stream_Read); |
| 6885 |
Set_Has_Specified_Stream_Read (Ent); |
| 6886 |
|
| 6887 |
-------------------------- |
| 6888 |
-- Scalar_Storage_Order -- |
| 6889 |
-------------------------- |
| 6890 |
|
| 6891 |
-- Scalar_Storage_Order attribute definition clause |
| 6892 |
|
| 6893 |
when Attribute_Scalar_Storage_Order => |
| 6894 |
if not (Is_Record_Type (U_Ent) or else Is_Array_Type (U_Ent)) then |
| 6895 |
Error_Msg_N |
| 6896 |
("Scalar_Storage_Order can only be defined for record or " |
| 6897 |
& "array type", Nam); |
| 6898 |
|
| 6899 |
elsif Duplicate_Clause then |
| 6900 |
null; |
| 6901 |
|
| 6902 |
else |
| 6903 |
Analyze_And_Resolve (Expr, RTE (RE_Bit_Order)); |
| 6904 |
|
| 6905 |
if Etype (Expr) = Any_Type then |
| 6906 |
return; |
| 6907 |
|
| 6908 |
elsif not Is_OK_Static_Expression (Expr) then |
| 6909 |
Flag_Non_Static_Expr |
| 6910 |
("Scalar_Storage_Order requires static expression!", Expr); |
| 6911 |
|
| 6912 |
elsif (Expr_Value (Expr) = 0) /= Bytes_Big_Endian then |
| 6913 |
|
| 6914 |
-- Here for the case of a non-default (i.e. non-confirming) |
| 6915 |
-- Scalar_Storage_Order attribute definition. |
| 6916 |
|
| 6917 |
if Support_Nondefault_SSO_On_Target then |
| 6918 |
Set_Reverse_Storage_Order (Base_Type (U_Ent), True); |
| 6919 |
else |
| 6920 |
Error_Msg_N |
| 6921 |
("non-default Scalar_Storage_Order not supported on " |
| 6922 |
& "target", Expr); |
| 6923 |
end if; |
| 6924 |
end if; |
| 6925 |
|
| 6926 |
-- Clear SSO default indications since explicit setting of the |
| 6927 |
-- order overrides the defaults. |
| 6928 |
|
| 6929 |
Set_SSO_Set_Low_By_Default (Base_Type (U_Ent), False); |
| 6930 |
Set_SSO_Set_High_By_Default (Base_Type (U_Ent), False); |
| 6931 |
end if; |
| 6932 |
|
| 6933 |
------------------------ |
| 6934 |
-- Size or Value_Size -- |
| 6935 |
------------------------ |
| 6936 |
|
| 6937 |
-- Size or Value_Size attribute definition clause. These are treated |
| 6938 |
-- the same, except that Size is allowed on objects, and Value_Size |
| 6939 |
-- is allowed on nonfirst subtypes. First subtypes allow both Size |
| 6940 |
-- and Value_Size; the treatment is the same for both. |
| 6941 |
|
| 6942 |
when Attribute_Size | Attribute_Value_Size => Size : declare |
| 6943 |
Size : constant Uint := Static_Integer (Expr); |
| 6944 |
|
| 6945 |
Attr_Name : constant String := |
| 6946 |
(if Id = Attribute_Size then "size" |
| 6947 |
elsif Id = Attribute_Value_Size then "value size" |
| 6948 |
else ""); -- can't happen |
| 6949 |
-- Name of the attribute for printing in messages |
| 6950 |
|
| 6951 |
OK_Prefix : constant Boolean := |
| 6952 |
(if Id = Attribute_Size then |
| 6953 |
Ekind (U_Ent) in Type_Kind | Constant_Or_Variable_Kind |
| 6954 |
elsif Id = Attribute_Value_Size then |
| 6955 |
Ekind (U_Ent) in Type_Kind |
| 6956 |
else False); -- can't happen |
| 6957 |
-- For X'Size, X can be a type or object; for X'Value_Size, |
| 6958 |
-- X can be a type. Note that we already checked that 'Size |
| 6959 |
-- can be specified only for a first subtype. |
| 6960 |
|
| 6961 |
begin |
| 6962 |
FOnly := True; |
| 6963 |
|
| 6964 |
if not OK_Prefix then |
| 6965 |
Error_Msg_N (Attr_Name & " cannot be given for &", Nam); |
| 6966 |
|
| 6967 |
elsif Duplicate_Clause then |
| 6968 |
null; |
| 6969 |
|
| 6970 |
elsif Is_Array_Type (U_Ent) |
| 6971 |
and then not Is_Constrained (U_Ent) |
| 6972 |
then |
| 6973 |
Error_Msg_N |
| 6974 |
(Attr_Name & " cannot be given for unconstrained array", Nam); |
| 6975 |
|
| 6976 |
elsif Present (Size) then |
| 6977 |
declare |
| 6978 |
Etyp : constant Entity_Id := |
| 6979 |
(if Is_Type (U_Ent) then U_Ent else Etype (U_Ent)); |
| 6980 |
|
| 6981 |
begin |
| 6982 |
-- Check size, note that Gigi is in charge of checking that |
| 6983 |
-- the size of an array or record type is OK. Also we do not |
| 6984 |
-- check the size in the ordinary fixed-point case, since |
| 6985 |
-- it is too early to do so (there may be subsequent small |
| 6986 |
-- clause that affects the size). We can check the size if |
| 6987 |
-- a small clause has already been given. |
| 6988 |
|
| 6989 |
if not Is_Ordinary_Fixed_Point_Type (U_Ent) |
| 6990 |
or else Has_Small_Clause (U_Ent) |
| 6991 |
then |
| 6992 |
declare |
| 6993 |
Biased : Boolean; |
| 6994 |
begin |
| 6995 |
Check_Size (Expr, Etyp, Size, Biased); |
| 6996 |
Set_Biased (U_Ent, N, Attr_Name & " clause", Biased); |
| 6997 |
end; |
| 6998 |
end if; |
| 6999 |
|
| 7000 |
-- For types, set RM_Size and Esize if appropriate |
| 7001 |
|
| 7002 |
if Is_Type (U_Ent) then |
| 7003 |
Set_RM_Size (U_Ent, Size); |
| 7004 |
|
| 7005 |
-- If we are specifying the Size or Value_Size of a |
| 7006 |
-- first subtype, then for elementary types, increase |
| 7007 |
-- Object_Size to power of 2, but not less than a storage |
| 7008 |
-- unit in any case (normally this means it will be byte |
| 7009 |
-- addressable). |
| 7010 |
|
| 7011 |
-- For all other types, nothing else to do, we leave |
| 7012 |
-- Esize (object size) unset; the back end will set it |
| 7013 |
-- from the size and alignment in an appropriate manner. |
| 7014 |
|
| 7015 |
-- In both cases, we check whether the alignment must be |
| 7016 |
-- reset in the wake of the size change. |
| 7017 |
|
| 7018 |
-- For nonfirst subtypes ('Value_Size only), we do |
| 7019 |
-- nothing here. |
| 7020 |
|
| 7021 |
if Is_First_Subtype (U_Ent) then |
| 7022 |
if Is_Elementary_Type (U_Ent) then |
| 7023 |
if Size <= System_Storage_Unit then |
| 7024 |
Set_Esize |
| 7025 |
(U_Ent, UI_From_Int (System_Storage_Unit)); |
| 7026 |
elsif Size <= 16 then |
| 7027 |
Set_Esize (U_Ent, Uint_16); |
| 7028 |
elsif Size <= 32 then |
| 7029 |
Set_Esize (U_Ent, Uint_32); |
| 7030 |
else |
| 7031 |
Set_Esize (U_Ent, (Size + 63) / 64 * 64); |
| 7032 |
end if; |
| 7033 |
|
| 7034 |
Alignment_Check_For_Size_Change |
| 7035 |
(U_Ent, Esize (U_Ent)); |
| 7036 |
else |
| 7037 |
Alignment_Check_For_Size_Change (U_Ent, Size); |
| 7038 |
end if; |
| 7039 |
end if; |
| 7040 |
|
| 7041 |
-- For Object'Size, set Esize only |
| 7042 |
|
| 7043 |
else |
| 7044 |
if Is_Elementary_Type (Etyp) |
| 7045 |
and then Size /= System_Storage_Unit |
| 7046 |
and then Size /= 16 |
| 7047 |
and then Size /= 32 |
| 7048 |
and then Size /= 64 |
| 7049 |
and then Size /= System_Max_Integer_Size |
| 7050 |
then |
| 7051 |
Error_Msg_Uint_1 := UI_From_Int (System_Storage_Unit); |
| 7052 |
Error_Msg_Uint_2 := |
| 7053 |
UI_From_Int (System_Max_Integer_Size); |
| 7054 |
Error_Msg_N |
| 7055 |
("size for primitive object must be a power of 2 in " |
| 7056 |
& "the range ^-^", N); |
| 7057 |
end if; |
| 7058 |
|
| 7059 |
Set_Esize (U_Ent, Size); |
| 7060 |
end if; |
| 7061 |
|
| 7062 |
-- As of RM 13.1, only confirming size |
| 7063 |
-- (i.e. (Size = Esize (Etyp))) for aliased object of |
| 7064 |
-- elementary type must be supported. |
| 7065 |
-- GNAT rejects nonconfirming size for such object. |
| 7066 |
|
| 7067 |
if Is_Aliased (U_Ent) |
| 7068 |
and then Is_Elementary_Type (Etyp) |
| 7069 |
and then Known_Esize (U_Ent) |
| 7070 |
and then Size /= Esize (Etyp) |
| 7071 |
then |
| 7072 |
Error_Msg_N |
| 7073 |
("nonconfirming Size for aliased object is not " |
| 7074 |
& "supported", N); |
| 7075 |
end if; |
| 7076 |
|
| 7077 |
-- Handle extension aspect 'Size'Class which allows for |
| 7078 |
-- "mutably tagged" types. |
| 7079 |
|
| 7080 |
if Ekind (Etyp) = E_Class_Wide_Type then |
| 7081 |
Error_Msg_GNAT_Extension |
| 7082 |
("attribute size class", Sloc (N)); |
| 7083 |
|
| 7084 |
-- Check for various restrictions applied to mutably |
| 7085 |
-- tagged types. |
| 7086 |
|
| 7087 |
if Is_Derived_Type (Etype (Etyp)) then |
| 7088 |
Error_Msg_N |
| 7089 |
("cannot be specified on derived types", Nam); |
| 7090 |
|
| 7091 |
elsif Ekind (Etype (Prefix (Nam))) = E_Record_Subtype then |
| 7092 |
Error_Msg_N |
| 7093 |
("cannot be specified on a subtype", Nam); |
| 7094 |
|
| 7095 |
elsif Is_Interface (Etype (Etyp)) then |
| 7096 |
Error_Msg_N |
| 7097 |
("cannot be specified on interface types", Nam); |
| 7098 |
|
| 7099 |
elsif Has_Discriminants (Etype (Etyp)) then |
| 7100 |
Error_Msg_N |
| 7101 |
("cannot be specified on discriminated type", Nam); |
| 7102 |
|
| 7103 |
elsif Present (Incomplete_Or_Partial_View (Etype (Etyp))) |
| 7104 |
and then Is_Tagged_Type |
| 7105 |
(Incomplete_Or_Partial_View (Etype (Etyp))) |
| 7106 |
then |
| 7107 |
Error_Msg_N |
| 7108 |
("cannot be specified on a type whose partial view" |
| 7109 |
& " is tagged", Nam); |
| 7110 |
|
| 7111 |
-- Otherwise, the declaration is valid |
| 7112 |
|
| 7113 |
else |
| 7114 |
declare |
| 7115 |
Actions : List_Id; |
| 7116 |
begin |
| 7117 |
-- Generate our class-wide equivalent type which |
| 7118 |
-- is sized according to the value specified by |
| 7119 |
-- 'Size'Class. |
| 7120 |
|
| 7121 |
Set_Class_Wide_Equivalent_Type (Etyp, |
| 7122 |
Make_CW_Equivalent_Type (Etyp, Empty, Actions)); |
| 7123 |
|
| 7124 |
-- Insert its declaration immediately after that of |
| 7125 |
-- the root type. |
| 7126 |
|
| 7127 |
Insert_Actions_After |
| 7128 |
(Declaration_Node (Etype (Etyp)), Actions); |
| 7129 |
|
| 7130 |
-- Add a Compile_Time_Error size check for the root |
| 7131 |
-- type at the freeze point. |
| 7132 |
|
| 7133 |
Append_Freeze_Action (Etype (Etyp), |
| 7134 |
Make_CW_Size_Compile_Check (Etype (Etyp), U_Ent)); |
| 7135 |
|
| 7136 |
Set_Is_Mutably_Tagged_Type (Etyp); |
| 7137 |
end; |
| 7138 |
end if; |
| 7139 |
end if; |
| 7140 |
|
| 7141 |
Set_Has_Size_Clause (U_Ent); |
| 7142 |
end; |
| 7143 |
end if; |
| 7144 |
end Size; |
| 7145 |
|
| 7146 |
----------- |
| 7147 |
-- Small -- |
| 7148 |
----------- |
| 7149 |
|
| 7150 |
-- Small attribute definition clause |
| 7151 |
|
| 7152 |
when Attribute_Small => Small : declare |
| 7153 |
Implicit_Base : constant Entity_Id := Base_Type (U_Ent); |
| 7154 |
Small : Ureal; |
| 7155 |
|
| 7156 |
begin |
| 7157 |
Analyze_And_Resolve (Expr, Any_Real); |
| 7158 |
|
| 7159 |
if Etype (Expr) = Any_Type then |
| 7160 |
return; |
| 7161 |
|
| 7162 |
elsif not Is_OK_Static_Expression (Expr) then |
| 7163 |
Flag_Non_Static_Expr |
| 7164 |
("small requires static expression!", Expr); |
| 7165 |
return; |
| 7166 |
|
| 7167 |
else |
| 7168 |
Small := Expr_Value_R (Expr); |
| 7169 |
|
| 7170 |
if Small <= Ureal_0 then |
| 7171 |
Error_Msg_N ("small value must be greater than zero", Expr); |
| 7172 |
return; |
| 7173 |
end if; |
| 7174 |
|
| 7175 |
end if; |
| 7176 |
|
| 7177 |
if not Is_Ordinary_Fixed_Point_Type (U_Ent) then |
| 7178 |
Error_Msg_N |
| 7179 |
("small requires an ordinary fixed point type", Nam); |
| 7180 |
|
| 7181 |
elsif Has_Small_Clause (U_Ent) then |
| 7182 |
Error_Msg_N ("small already given for &", Nam); |
| 7183 |
|
| 7184 |
elsif Small > Delta_Value (U_Ent) then |
| 7185 |
Error_Msg_N |
| 7186 |
("small value must not be greater than delta value", Nam); |
| 7187 |
|
| 7188 |
else |
| 7189 |
Set_Small_Value (U_Ent, Small); |
| 7190 |
Set_Small_Value (Implicit_Base, Small); |
| 7191 |
Set_Has_Small_Clause (U_Ent); |
| 7192 |
Set_Has_Small_Clause (Implicit_Base); |
| 7193 |
Set_Has_Non_Standard_Rep (Implicit_Base); |
| 7194 |
end if; |
| 7195 |
end Small; |
| 7196 |
|
| 7197 |
------------------ |
| 7198 |
-- Storage_Pool -- |
| 7199 |
------------------ |
| 7200 |
|
| 7201 |
-- Storage_Pool attribute definition clause |
| 7202 |
|
| 7203 |
when Attribute_Simple_Storage_Pool |
| 7204 |
| Attribute_Storage_Pool |
| 7205 |
=> |
| 7206 |
Storage_Pool : declare |
| 7207 |
Pool : Entity_Id; |
| 7208 |
T : Entity_Id; |
| 7209 |
|
| 7210 |
procedure Associate_Storage_Pool |
| 7211 |
(Ent : Entity_Id; Pool : Entity_Id); |
| 7212 |
-- Associate Pool to Ent and perform legality checks on subpools |
| 7213 |
|
| 7214 |
---------------------------- |
| 7215 |
-- Associate_Storage_Pool -- |
| 7216 |
---------------------------- |
| 7217 |
|
| 7218 |
procedure Associate_Storage_Pool |
| 7219 |
(Ent : Entity_Id; Pool : Entity_Id) |
| 7220 |
is |
| 7221 |
function Object_From (Pool : Entity_Id) return Entity_Id; |
| 7222 |
-- Return the entity of which Pool is a part of |
| 7223 |
|
| 7224 |
----------------- |
| 7225 |
-- Object_From -- |
| 7226 |
----------------- |
| 7227 |
|
| 7228 |
function Object_From |
| 7229 |
(Pool : Entity_Id) return Entity_Id |
| 7230 |
is |
| 7231 |
N : Node_Id := Pool; |
| 7232 |
begin |
| 7233 |
if Present (Renamed_Object (Pool)) then |
| 7234 |
N := Renamed_Object (Pool); |
| 7235 |
end if; |
| 7236 |
|
| 7237 |
while Present (N) loop |
| 7238 |
case Nkind (N) is |
| 7239 |
when N_Defining_Identifier => |
| 7240 |
return N; |
| 7241 |
|
| 7242 |
when N_Identifier | N_Expanded_Name => |
| 7243 |
return Entity (N); |
| 7244 |
|
| 7245 |
when N_Indexed_Component | N_Selected_Component | |
| 7246 |
N_Explicit_Dereference |
| 7247 |
=> |
| 7248 |
N := Prefix (N); |
| 7249 |
|
| 7250 |
when N_Type_Conversion => |
| 7251 |
N := Expression (N); |
| 7252 |
|
| 7253 |
when others => |
| 7254 |
-- ??? we probably should handle more cases but |
| 7255 |
-- this is good enough in practice for this check |
| 7256 |
-- on a corner case. |
| 7257 |
|
| 7258 |
return Empty; |
| 7259 |
end case; |
| 7260 |
end loop; |
| 7261 |
|
| 7262 |
return Empty; |
| 7263 |
end Object_From; |
| 7264 |
|
| 7265 |
Obj : Entity_Id; |
| 7266 |
|
| 7267 |
begin |
| 7268 |
Set_Associated_Storage_Pool (Ent, Pool); |
| 7269 |
|
| 7270 |
-- Check RM 13.11.4(22-23/3): a specification of a storage pool |
| 7271 |
-- is illegal if the storage pool supports subpools and: |
| 7272 |
-- (A) The access type is a general access type. |
| 7273 |
-- (B) The access type is statically deeper than the storage |
| 7274 |
-- pool object; |
| 7275 |
-- (C) The storage pool object is a part of a formal parameter; |
| 7276 |
-- (D) The storage pool object is a part of the dereference of |
| 7277 |
-- a non-library level general access type; |
| 7278 |
|
| 7279 |
if Ada_Version >= Ada_2012 |
| 7280 |
and then RTU_Loaded (System_Storage_Pools_Subpools) |
| 7281 |
and then |
| 7282 |
Is_Ancestor (RTE (RE_Root_Storage_Pool_With_Subpools), |
| 7283 |
Etype (Pool)) |
| 7284 |
then |
| 7285 |
-- check (A) |
| 7286 |
|
| 7287 |
if Ekind (Etype (Ent)) = E_General_Access_Type then |
| 7288 |
Error_Msg_N |
| 7289 |
("subpool cannot be used on general access type", Ent); |
| 7290 |
end if; |
| 7291 |
|
| 7292 |
-- check (B) |
| 7293 |
|
| 7294 |
if Type_Access_Level (Ent) |
| 7295 |
> Static_Accessibility_Level |
| 7296 |
(Pool, Object_Decl_Level) |
| 7297 |
then |
| 7298 |
Error_Msg_N |
| 7299 |
("subpool access type has deeper accessibility " |
| 7300 |
& "level than pool", Ent); |
| 7301 |
return; |
| 7302 |
end if; |
| 7303 |
|
| 7304 |
Obj := Object_From (Pool); |
| 7305 |
|
| 7306 |
-- check (C) |
| 7307 |
|
| 7308 |
if Present (Obj) and then Is_Formal (Obj) then |
| 7309 |
Error_Msg_N |
| 7310 |
("subpool cannot be part of a parameter", Ent); |
| 7311 |
return; |
| 7312 |
end if; |
| 7313 |
|
| 7314 |
-- check (D) |
| 7315 |
|
| 7316 |
if Present (Obj) |
| 7317 |
and then Ekind (Etype (Obj)) = E_General_Access_Type |
| 7318 |
and then not Is_Library_Level_Entity (Etype (Obj)) |
| 7319 |
then |
| 7320 |
Error_Msg_N |
| 7321 |
("subpool cannot be part of the dereference of a " & |
| 7322 |
"nested general access type", Ent); |
| 7323 |
return; |
| 7324 |
end if; |
| 7325 |
end if; |
| 7326 |
end Associate_Storage_Pool; |
| 7327 |
|
| 7328 |
begin |
| 7329 |
if Ekind (U_Ent) = E_Access_Subprogram_Type then |
| 7330 |
Error_Msg_N |
| 7331 |
("storage pool cannot be given for access-to-subprogram type", |
| 7332 |
Nam); |
| 7333 |
return; |
| 7334 |
|
| 7335 |
elsif Ekind (U_Ent) not in E_Access_Type | E_General_Access_Type |
| 7336 |
then |
| 7337 |
Error_Msg_N |
| 7338 |
("storage pool can only be given for access types", Nam); |
| 7339 |
return; |
| 7340 |
|
| 7341 |
elsif Is_Derived_Type (U_Ent) then |
| 7342 |
Error_Msg_N |
| 7343 |
("storage pool cannot be given for a derived access type", |
| 7344 |
Nam); |
| 7345 |
|
| 7346 |
elsif Duplicate_Clause then |
| 7347 |
return; |
| 7348 |
|
| 7349 |
elsif Present (Associated_Storage_Pool (U_Ent)) then |
| 7350 |
Error_Msg_N ("storage pool already given for &", Nam); |
| 7351 |
return; |
| 7352 |
end if; |
| 7353 |
|
| 7354 |
-- Check for Storage_Size previously given |
| 7355 |
|
| 7356 |
declare |
| 7357 |
SS : constant Node_Id := |
| 7358 |
Get_Attribute_Definition_Clause |
| 7359 |
(U_Ent, Attribute_Storage_Size); |
| 7360 |
begin |
| 7361 |
if Present (SS) then |
| 7362 |
Check_Pool_Size_Clash (U_Ent, N, SS); |
| 7363 |
end if; |
| 7364 |
end; |
| 7365 |
|
| 7366 |
-- Storage_Pool case |
| 7367 |
|
| 7368 |
if Id = Attribute_Storage_Pool then |
| 7369 |
Analyze_And_Resolve |
| 7370 |
(Expr, Class_Wide_Type (RTE (RE_Root_Storage_Pool))); |
| 7371 |
|
| 7372 |
-- In the Simple_Storage_Pool case, we allow a variable of any |
| 7373 |
-- simple storage pool type, so we Resolve without imposing an |
| 7374 |
-- expected type. |
| 7375 |
|
| 7376 |
else |
| 7377 |
Analyze_And_Resolve (Expr); |
| 7378 |
|
| 7379 |
if No (Get_Rep_Pragma |
| 7380 |
(Etype (Expr), Name_Simple_Storage_Pool_Type)) |
| 7381 |
then |
| 7382 |
Error_Msg_N |
| 7383 |
("expression must be of a simple storage pool type", Expr); |
| 7384 |
end if; |
| 7385 |
end if; |
| 7386 |
|
| 7387 |
if not Denotes_Variable (Expr) then |
| 7388 |
Error_Msg_N ("storage pool must be a variable", Expr); |
| 7389 |
return; |
| 7390 |
end if; |
| 7391 |
|
| 7392 |
if Nkind (Expr) = N_Type_Conversion then |
| 7393 |
T := Etype (Expression (Expr)); |
| 7394 |
else |
| 7395 |
T := Etype (Expr); |
| 7396 |
end if; |
| 7397 |
|
| 7398 |
-- The Stack_Bounded_Pool is used internally for implementing |
| 7399 |
-- access types with a Storage_Size. Since it only work properly |
| 7400 |
-- when used on one specific type, we need to check that it is not |
| 7401 |
-- hijacked improperly: |
| 7402 |
|
| 7403 |
-- type T is access Integer; |
| 7404 |
-- for T'Storage_Size use n; |
| 7405 |
-- type Q is access Float; |
| 7406 |
-- for Q'Storage_Size use T'Storage_Size; -- incorrect |
| 7407 |
|
| 7408 |
if Is_RTE (Base_Type (T), RE_Stack_Bounded_Pool) then |
| 7409 |
Error_Msg_N ("non-shareable internal Pool", Expr); |
| 7410 |
return; |
| 7411 |
end if; |
| 7412 |
|
| 7413 |
-- Validate_Remote_Access_To_Class_Wide_Type for attribute |
| 7414 |
-- Storage_Pool since this attribute cannot be defined for such |
| 7415 |
-- types (RM E.2.2(17)). |
| 7416 |
|
| 7417 |
Validate_Remote_Access_To_Class_Wide_Type (N); |
| 7418 |
|
| 7419 |
-- If the argument is a name that is not an entity name, then |
| 7420 |
-- we construct a renaming operation to define an entity of |
| 7421 |
-- type storage pool. |
| 7422 |
|
| 7423 |
if not Is_Entity_Name (Expr) |
| 7424 |
and then Is_Object_Reference (Expr) |
| 7425 |
then |
| 7426 |
Pool := Make_Temporary (Loc, 'P', Expr); |
| 7427 |
|
| 7428 |
declare |
| 7429 |
Rnode : constant Node_Id := |
| 7430 |
Make_Object_Renaming_Declaration (Loc, |
| 7431 |
Defining_Identifier => Pool, |
| 7432 |
Subtype_Mark => |
| 7433 |
New_Occurrence_Of (Etype (Expr), Loc), |
| 7434 |
Name => Expr); |
| 7435 |
|
| 7436 |
begin |
| 7437 |
-- If the attribute definition clause comes from an aspect |
| 7438 |
-- clause, then insert the renaming before the associated |
| 7439 |
-- entity's declaration, since the attribute clause has |
| 7440 |
-- not yet been appended to the declaration list. |
| 7441 |
|
| 7442 |
if From_Aspect_Specification (N) then |
| 7443 |
Insert_Before (Parent (Entity (N)), Rnode); |
| 7444 |
else |
| 7445 |
Insert_Before (N, Rnode); |
| 7446 |
end if; |
| 7447 |
|
| 7448 |
Analyze (Rnode); |
| 7449 |
Associate_Storage_Pool (U_Ent, Pool); |
| 7450 |
end; |
| 7451 |
|
| 7452 |
elsif Is_Entity_Name (Expr) then |
| 7453 |
Pool := Entity (Expr); |
| 7454 |
|
| 7455 |
-- If pool is a renamed object, get original one. This can |
| 7456 |
-- happen with an explicit renaming, and within instances. |
| 7457 |
|
| 7458 |
while Present (Renamed_Object (Pool)) |
| 7459 |
and then Is_Entity_Name (Renamed_Object (Pool)) |
| 7460 |
loop |
| 7461 |
Pool := Entity (Renamed_Object (Pool)); |
| 7462 |
end loop; |
| 7463 |
|
| 7464 |
if Present (Renamed_Object (Pool)) |
| 7465 |
and then Nkind (Renamed_Object (Pool)) = N_Type_Conversion |
| 7466 |
and then Is_Entity_Name (Expression (Renamed_Object (Pool))) |
| 7467 |
then |
| 7468 |
Pool := Entity (Expression (Renamed_Object (Pool))); |
| 7469 |
end if; |
| 7470 |
|
| 7471 |
Associate_Storage_Pool (U_Ent, Pool); |
| 7472 |
|
| 7473 |
elsif Nkind (Expr) = N_Type_Conversion |
| 7474 |
and then Is_Entity_Name (Expression (Expr)) |
| 7475 |
and then Nkind (Original_Node (Expr)) = N_Attribute_Reference |
| 7476 |
then |
| 7477 |
Pool := Entity (Expression (Expr)); |
| 7478 |
Associate_Storage_Pool (U_Ent, Pool); |
| 7479 |
|
| 7480 |
else |
| 7481 |
Error_Msg_N ("incorrect reference to a Storage Pool", Expr); |
| 7482 |
return; |
| 7483 |
end if; |
| 7484 |
end Storage_Pool; |
| 7485 |
|
| 7486 |
------------------ |
| 7487 |
-- Storage_Size -- |
| 7488 |
------------------ |
| 7489 |
|
| 7490 |
-- Storage_Size attribute definition clause |
| 7491 |
|
| 7492 |
when Attribute_Storage_Size => Storage_Size : declare |
| 7493 |
Btype : constant Entity_Id := Base_Type (U_Ent); |
| 7494 |
|
| 7495 |
begin |
| 7496 |
if Is_Task_Type (U_Ent) then |
| 7497 |
|
| 7498 |
-- Check obsolescent (but never obsolescent if from aspect) |
| 7499 |
|
| 7500 |
if not From_Aspect_Specification (N) then |
| 7501 |
Check_Restriction (No_Obsolescent_Features, N); |
| 7502 |
|
| 7503 |
if Warn_On_Obsolescent_Feature then |
| 7504 |
Error_Msg_N |
| 7505 |
("?j?storage size clause for task is an obsolescent " |
| 7506 |
& "feature (RM J.9)", N); |
| 7507 |
Error_Msg_N ("\?j?use Storage_Size pragma instead", N); |
| 7508 |
end if; |
| 7509 |
end if; |
| 7510 |
|
| 7511 |
FOnly := True; |
| 7512 |
end if; |
| 7513 |
|
| 7514 |
if not Is_Access_Type (U_Ent) |
| 7515 |
and then Ekind (U_Ent) /= E_Task_Type |
| 7516 |
then |
| 7517 |
Error_Msg_N ("storage size cannot be given for &", Nam); |
| 7518 |
|
| 7519 |
elsif Is_Access_Type (U_Ent) and Is_Derived_Type (U_Ent) then |
| 7520 |
Error_Msg_N |
| 7521 |
("storage size cannot be given for a derived access type", |
| 7522 |
Nam); |
| 7523 |
|
| 7524 |
elsif Duplicate_Clause then |
| 7525 |
null; |
| 7526 |
|
| 7527 |
else |
| 7528 |
-- Validate_Remote_Access_To_Class_Wide_Type for attribute |
| 7529 |
-- Storage_Size since this attribute cannot be defined for such |
| 7530 |
-- types (RM E.2.2(17)). |
| 7531 |
|
| 7532 |
Validate_Remote_Access_To_Class_Wide_Type (N); |
| 7533 |
|
| 7534 |
Analyze_And_Resolve (Expr, Any_Integer); |
| 7535 |
|
| 7536 |
if Is_Access_Type (U_Ent) then |
| 7537 |
|
| 7538 |
-- Check for Storage_Pool previously given |
| 7539 |
|
| 7540 |
declare |
| 7541 |
SP : constant Node_Id := |
| 7542 |
Get_Attribute_Definition_Clause |
| 7543 |
(U_Ent, Attribute_Storage_Pool); |
| 7544 |
|
| 7545 |
begin |
| 7546 |
if Present (SP) then |
| 7547 |
Check_Pool_Size_Clash (U_Ent, SP, N); |
| 7548 |
end if; |
| 7549 |
end; |
| 7550 |
|
| 7551 |
-- Special case of for x'Storage_Size use 0 |
| 7552 |
|
| 7553 |
if Is_OK_Static_Expression (Expr) |
| 7554 |
and then Expr_Value (Expr) = 0 |
| 7555 |
then |
| 7556 |
Set_No_Pool_Assigned (Btype); |
| 7557 |
end if; |
| 7558 |
end if; |
| 7559 |
|
| 7560 |
Set_Has_Storage_Size_Clause (Btype); |
| 7561 |
end if; |
| 7562 |
end Storage_Size; |
| 7563 |
|
| 7564 |
----------------- |
| 7565 |
-- Stream_Size -- |
| 7566 |
----------------- |
| 7567 |
|
| 7568 |
when Attribute_Stream_Size => Stream_Size : declare |
| 7569 |
Size : constant Uint := Static_Integer (Expr); |
| 7570 |
|
| 7571 |
begin |
| 7572 |
if Ada_Version <= Ada_95 then |
| 7573 |
Check_Restriction (No_Implementation_Attributes, N); |
| 7574 |
end if; |
| 7575 |
|
| 7576 |
if Duplicate_Clause then |
| 7577 |
null; |
| 7578 |
|
| 7579 |
elsif Is_Elementary_Type (U_Ent) then |
| 7580 |
-- Size will be empty if we already detected an error |
| 7581 |
-- (e.g. Expr is of the wrong type); we might as well |
| 7582 |
-- give the useful hint below even in that case. |
| 7583 |
|
| 7584 |
if No (Size) or else |
| 7585 |
(Size /= System_Storage_Unit |
| 7586 |
and then Size /= System_Storage_Unit * 2 |
| 7587 |
and then Size /= System_Storage_Unit * 3 |
| 7588 |
and then Size /= System_Storage_Unit * 4 |
| 7589 |
and then Size /= System_Storage_Unit * 8) |
| 7590 |
then |
| 7591 |
Error_Msg_N |
| 7592 |
("stream size for elementary type must be 8, 16, 24, " & |
| 7593 |
"32 or 64", N); |
| 7594 |
|
| 7595 |
elsif Known_RM_Size (U_Ent) and then RM_Size (U_Ent) > Size then |
| 7596 |
Error_Msg_Uint_1 := RM_Size (U_Ent); |
| 7597 |
Error_Msg_N |
| 7598 |
("stream size for elementary type must be 8, 16, 24, " & |
| 7599 |
"32 or 64 and at least ^", N); |
| 7600 |
end if; |
| 7601 |
|
| 7602 |
Set_Has_Stream_Size_Clause (U_Ent); |
| 7603 |
|
| 7604 |
else |
| 7605 |
Error_Msg_N ("Stream_Size cannot be given for &", Nam); |
| 7606 |
end if; |
| 7607 |
end Stream_Size; |
| 7608 |
|
| 7609 |
----------------------- |
| 7610 |
-- Variable_Indexing -- |
| 7611 |
----------------------- |
| 7612 |
|
| 7613 |
when Attribute_Variable_Indexing => |
| 7614 |
null; |
| 7615 |
|
| 7616 |
----------- |
| 7617 |
-- Write -- |
| 7618 |
----------- |
| 7619 |
|
| 7620 |
when Attribute_Write => |
| 7621 |
Analyze_Stream_TSS_Definition (TSS_Stream_Write); |
| 7622 |
Set_Has_Specified_Stream_Write (Ent); |
| 7623 |
|
| 7624 |
-- All other attributes cannot be set |
| 7625 |
|
| 7626 |
when others => |
| 7627 |
Error_Msg_N |
| 7628 |
("attribute& cannot be set with definition clause", N); |
| 7629 |
end case; |
| 7630 |
|
| 7631 |
-- The test for the type being frozen must be performed after any |
| 7632 |
-- expression the clause has been analyzed since the expression itself |
| 7633 |
-- might cause freezing that makes the clause illegal. |
| 7634 |
|
| 7635 |
if Rep_Item_Too_Late (U_Ent, N, FOnly) then |
| 7636 |
return; |
| 7637 |
end if; |
| 7638 |
end Analyze_Attribute_Definition_Clause; |
| 7639 |
|
| 7640 |
---------------------------- |
| 7641 |
-- Analyze_Code_Statement -- |
| 7642 |
---------------------------- |
| 7643 |
|
| 7644 |
procedure Analyze_Code_Statement (N : Node_Id) is |
| 7645 |
HSS : constant Node_Id := Parent (N); |
| 7646 |
SBody : constant Node_Id := Parent (HSS); |
| 7647 |
Subp : constant Entity_Id := Current_Scope; |
| 7648 |
Stmt : Node_Id; |
| 7649 |
Decl : Node_Id; |
| 7650 |
StmtO : Node_Id; |
| 7651 |
DeclO : Node_Id; |
| 7652 |
|
| 7653 |
begin |
| 7654 |
-- Accept foreign code statements for CodePeer. The analysis is skipped |
| 7655 |
-- to avoid rejecting unrecognized constructs. |
| 7656 |
|
| 7657 |
if CodePeer_Mode then |
| 7658 |
Set_Analyzed (N); |
| 7659 |
return; |
| 7660 |
end if; |
| 7661 |
|
| 7662 |
-- Analyze and check we get right type, note that this implements the |
| 7663 |
-- requirement (RM 13.8(1)) that Machine_Code be with'ed, since that is |
| 7664 |
-- the only way that Asm_Insn could possibly be visible. |
| 7665 |
|
| 7666 |
Analyze_And_Resolve (Expression (N)); |
| 7667 |
|
| 7668 |
if Etype (Expression (N)) = Any_Type then |
| 7669 |
return; |
| 7670 |
elsif not Is_RTE (Etype (Expression (N)), RE_Asm_Insn) then |
| 7671 |
Error_Msg_N ("incorrect type for code statement", N); |
| 7672 |
return; |
| 7673 |
end if; |
| 7674 |
|
| 7675 |
Check_Code_Statement (N); |
| 7676 |
|
| 7677 |
-- Make sure we appear in the handled statement sequence of a subprogram |
| 7678 |
-- (RM 13.8(3)). |
| 7679 |
|
| 7680 |
if Nkind (HSS) /= N_Handled_Sequence_Of_Statements |
| 7681 |
or else Nkind (SBody) /= N_Subprogram_Body |
| 7682 |
then |
| 7683 |
Error_Msg_N |
| 7684 |
("code statement can only appear in body of subprogram", N); |
| 7685 |
return; |
| 7686 |
end if; |
| 7687 |
|
| 7688 |
-- Do remaining checks (RM 13.8(3)) if not already done |
| 7689 |
|
| 7690 |
if not Is_Machine_Code_Subprogram (Subp) then |
| 7691 |
Set_Is_Machine_Code_Subprogram (Subp); |
| 7692 |
|
| 7693 |
-- No exception handlers allowed |
| 7694 |
|
| 7695 |
if Present (Exception_Handlers (HSS)) then |
| 7696 |
Error_Msg_N |
| 7697 |
("exception handlers not permitted in machine code subprogram", |
| 7698 |
First (Exception_Handlers (HSS))); |
| 7699 |
end if; |
| 7700 |
|
| 7701 |
-- No declarations other than use clauses and pragmas (we allow |
| 7702 |
-- certain internally generated declarations as well). |
| 7703 |
|
| 7704 |
Decl := First (Declarations (SBody)); |
| 7705 |
while Present (Decl) loop |
| 7706 |
DeclO := Original_Node (Decl); |
| 7707 |
if Comes_From_Source (DeclO) |
| 7708 |
and Nkind (DeclO) not in N_Pragma |
| 7709 |
| N_Use_Package_Clause |
| 7710 |
| N_Use_Type_Clause |
| 7711 |
| N_Implicit_Label_Declaration |
| 7712 |
then |
| 7713 |
Error_Msg_N |
| 7714 |
("this declaration is not allowed in machine code subprogram", |
| 7715 |
DeclO); |
| 7716 |
end if; |
| 7717 |
|
| 7718 |
Next (Decl); |
| 7719 |
end loop; |
| 7720 |
|
| 7721 |
-- No statements other than code statements, pragmas, and labels. |
| 7722 |
-- Again we allow certain internally generated statements. |
| 7723 |
|
| 7724 |
-- In Ada 2012, qualified expressions are names, and the code |
| 7725 |
-- statement is initially parsed as a procedure call. |
| 7726 |
|
| 7727 |
Stmt := First (Statements (HSS)); |
| 7728 |
while Present (Stmt) loop |
| 7729 |
StmtO := Original_Node (Stmt); |
| 7730 |
|
| 7731 |
-- A procedure call transformed into a code statement is OK |
| 7732 |
|
| 7733 |
if Ada_Version >= Ada_2012 |
| 7734 |
and then Nkind (StmtO) = N_Procedure_Call_Statement |
| 7735 |
and then Nkind (Name (StmtO)) = N_Qualified_Expression |
| 7736 |
then |
| 7737 |
null; |
| 7738 |
|
| 7739 |
elsif Comes_From_Source (StmtO) |
| 7740 |
and then Nkind (StmtO) not in |
| 7741 |
N_Pragma | N_Label | N_Code_Statement |
| 7742 |
then |
| 7743 |
Error_Msg_N |
| 7744 |
("this statement is not allowed in machine code subprogram", |
| 7745 |
StmtO); |
| 7746 |
end if; |
| 7747 |
|
| 7748 |
Next (Stmt); |
| 7749 |
end loop; |
| 7750 |
end if; |
| 7751 |
end Analyze_Code_Statement; |
| 7752 |
|
| 7753 |
----------------------------------------------- |
| 7754 |
-- Analyze_Enumeration_Representation_Clause -- |
| 7755 |
----------------------------------------------- |
| 7756 |
|
| 7757 |
procedure Analyze_Enumeration_Representation_Clause (N : Node_Id) is |
| 7758 |
Ident : constant Node_Id := Identifier (N); |
| 7759 |
Aggr : constant Node_Id := Array_Aggregate (N); |
| 7760 |
Enumtype : Entity_Id; |
| 7761 |
Elit : Entity_Id; |
| 7762 |
Expr : Node_Id; |
| 7763 |
Assoc : Node_Id; |
| 7764 |
Choice : Node_Id; |
| 7765 |
Val : Uint; |
| 7766 |
|
| 7767 |
Err : Boolean := False; |
| 7768 |
-- Set True to avoid cascade errors and crashes on incorrect source code |
| 7769 |
|
| 7770 |
Lo : constant Uint := Expr_Value (Type_Low_Bound (Universal_Integer)); |
| 7771 |
Hi : constant Uint := Expr_Value (Type_High_Bound (Universal_Integer)); |
| 7772 |
-- Allowed range of universal integer (= allowed range of enum lit vals) |
| 7773 |
|
| 7774 |
Min : Uint; |
| 7775 |
Max : Uint; |
| 7776 |
-- Minimum and maximum values of entries |
| 7777 |
|
| 7778 |
Max_Node : Node_Id := Empty; -- init to avoid warning |
| 7779 |
-- Pointer to node for literal providing max value |
| 7780 |
|
| 7781 |
begin |
| 7782 |
if Ignore_Rep_Clauses then |
| 7783 |
Kill_Rep_Clause (N); |
| 7784 |
return; |
| 7785 |
end if; |
| 7786 |
|
| 7787 |
-- Ignore enumeration rep clauses by default in CodePeer mode, |
| 7788 |
-- unless -gnatd.I is specified, as a work around for potential false |
| 7789 |
-- positive messages. |
| 7790 |
|
| 7791 |
if CodePeer_Mode and not Debug_Flag_Dot_II then |
| 7792 |
return; |
| 7793 |
end if; |
| 7794 |
|
| 7795 |
-- First some basic error checks |
| 7796 |
|
| 7797 |
Find_Type (Ident); |
| 7798 |
Enumtype := Entity (Ident); |
| 7799 |
|
| 7800 |
if Enumtype = Any_Type |
| 7801 |
or else Rep_Item_Too_Early (Enumtype, N) |
| 7802 |
then |
| 7803 |
return; |
| 7804 |
else |
| 7805 |
Enumtype := Underlying_Type (Enumtype); |
| 7806 |
end if; |
| 7807 |
|
| 7808 |
if not Is_Enumeration_Type (Enumtype) then |
| 7809 |
Error_Msg_NE |
| 7810 |
("enumeration type required, found}", |
| 7811 |
Ident, First_Subtype (Enumtype)); |
| 7812 |
return; |
| 7813 |
end if; |
| 7814 |
|
| 7815 |
-- Ignore rep clause on generic actual type. This will already have |
| 7816 |
-- been flagged on the template as an error, and this is the safest |
| 7817 |
-- way to ensure we don't get a junk cascaded message in the instance. |
| 7818 |
|
| 7819 |
if Is_Generic_Actual_Type (Enumtype) then |
| 7820 |
return; |
| 7821 |
|
| 7822 |
-- Type must be in current scope |
| 7823 |
|
| 7824 |
elsif Scope (Enumtype) /= Current_Scope then |
| 7825 |
Error_Msg_N ("type must be declared in this scope", Ident); |
| 7826 |
return; |
| 7827 |
|
| 7828 |
-- Type must be a first subtype |
| 7829 |
|
| 7830 |
elsif not Is_First_Subtype (Enumtype) then |
| 7831 |
Error_Msg_N ("cannot give enumeration rep clause for subtype", N); |
| 7832 |
return; |
| 7833 |
|
| 7834 |
-- Ignore duplicate rep clause |
| 7835 |
|
| 7836 |
elsif Has_Enumeration_Rep_Clause (Enumtype) then |
| 7837 |
Error_Msg_N ("duplicate enumeration rep clause ignored", N); |
| 7838 |
return; |
| 7839 |
|
| 7840 |
-- Don't allow rep clause for standard [wide_[wide_]]character |
| 7841 |
|
| 7842 |
elsif Is_Standard_Character_Type (Enumtype) then |
| 7843 |
Error_Msg_N ("enumeration rep clause not allowed for this type", N); |
| 7844 |
return; |
| 7845 |
|
| 7846 |
-- Check that the expression is a proper aggregate (no parentheses) |
| 7847 |
|
| 7848 |
elsif Paren_Count (Aggr) /= 0 then |
| 7849 |
Error_Msg_F |
| 7850 |
("extra parentheses surrounding aggregate not allowed", Aggr); |
| 7851 |
return; |
| 7852 |
|
| 7853 |
-- Reject the mixing of named and positional entries in the aggregate |
| 7854 |
|
| 7855 |
elsif Present (Expressions (Aggr)) |
| 7856 |
and then Present (Component_Associations (Aggr)) |
| 7857 |
then |
| 7858 |
Error_Msg_N ("cannot mix positional and named entries in " |
| 7859 |
& "enumeration rep clause", N); |
| 7860 |
return; |
| 7861 |
|
| 7862 |
-- All tests passed, so set rep clause in place |
| 7863 |
|
| 7864 |
else |
| 7865 |
Set_Has_Enumeration_Rep_Clause (Enumtype); |
| 7866 |
Set_Has_Enumeration_Rep_Clause (Base_Type (Enumtype)); |
| 7867 |
end if; |
| 7868 |
|
| 7869 |
-- Now we process the aggregate. Note that we don't use the normal |
| 7870 |
-- aggregate code for this purpose, because we don't want any of the |
| 7871 |
-- normal expansion activities, and a number of special semantic |
| 7872 |
-- rules apply (including the component type being any integer type) |
| 7873 |
|
| 7874 |
Elit := First_Literal (Enumtype); |
| 7875 |
|
| 7876 |
-- Process positional entries |
| 7877 |
|
| 7878 |
if Present (Expressions (Aggr)) then |
| 7879 |
Expr := First (Expressions (Aggr)); |
| 7880 |
while Present (Expr) loop |
| 7881 |
if No (Elit) then |
| 7882 |
Error_Msg_N ("too many entries in aggregate", Expr); |
| 7883 |
return; |
| 7884 |
end if; |
| 7885 |
|
| 7886 |
Val := Static_Integer (Expr); |
| 7887 |
|
| 7888 |
-- Err signals that we found some incorrect entries processing |
| 7889 |
-- the list. The final checks for completeness and ordering are |
| 7890 |
-- skipped in this case. |
| 7891 |
|
| 7892 |
if No (Val) then |
| 7893 |
Err := True; |
| 7894 |
|
| 7895 |
elsif Val < Lo or else Hi < Val then |
| 7896 |
Error_Msg_N ("value outside permitted range", Expr); |
| 7897 |
Err := True; |
| 7898 |
|
| 7899 |
else |
| 7900 |
Set_Enumeration_Rep (Elit, Val); |
| 7901 |
Set_Enumeration_Rep_Expr (Elit, Expr); |
| 7902 |
end if; |
| 7903 |
|
| 7904 |
Next (Expr); |
| 7905 |
Next (Elit); |
| 7906 |
end loop; |
| 7907 |
|
| 7908 |
-- Process named entries |
| 7909 |
|
| 7910 |
elsif Present (Component_Associations (Aggr)) then |
| 7911 |
Assoc := First (Component_Associations (Aggr)); |
| 7912 |
while Present (Assoc) loop |
| 7913 |
Choice := First (Choices (Assoc)); |
| 7914 |
|
| 7915 |
if Present (Next (Choice)) then |
| 7916 |
Error_Msg_N |
| 7917 |
("multiple choice not allowed here", Next (Choice)); |
| 7918 |
Err := True; |
| 7919 |
end if; |
| 7920 |
|
| 7921 |
if Nkind (Choice) = N_Others_Choice then |
| 7922 |
Error_Msg_N ("OTHERS choice not allowed here", Choice); |
| 7923 |
Err := True; |
| 7924 |
|
| 7925 |
elsif Nkind (Choice) = N_Range then |
| 7926 |
|
| 7927 |
-- ??? should allow zero/one element range here |
| 7928 |
|
| 7929 |
Error_Msg_N ("range not allowed here", Choice); |
| 7930 |
Err := True; |
| 7931 |
|
| 7932 |
else |
| 7933 |
Analyze_And_Resolve (Choice, Enumtype); |
| 7934 |
|
| 7935 |
if Error_Posted (Choice) then |
| 7936 |
Err := True; |
| 7937 |
end if; |
| 7938 |
|
| 7939 |
if not Err then |
| 7940 |
if Is_Entity_Name (Choice) |
| 7941 |
and then Is_Type (Entity (Choice)) |
| 7942 |
then |
| 7943 |
Error_Msg_N ("subtype name not allowed here", Choice); |
| 7944 |
Err := True; |
| 7945 |
|
| 7946 |
-- ??? should allow static subtype with zero/one entry |
| 7947 |
|
| 7948 |
elsif Etype (Choice) = Base_Type (Enumtype) then |
| 7949 |
if not Is_OK_Static_Expression (Choice) then |
| 7950 |
Flag_Non_Static_Expr |
| 7951 |
("non-static expression used for choice!", Choice); |
| 7952 |
Err := True; |
| 7953 |
|
| 7954 |
else |
| 7955 |
Elit := Expr_Value_E (Choice); |
| 7956 |
|
| 7957 |
if Present (Enumeration_Rep_Expr (Elit)) then |
| 7958 |
Error_Msg_Sloc := |
| 7959 |
Sloc (Enumeration_Rep_Expr (Elit)); |
| 7960 |
Error_Msg_NE |
| 7961 |
("representation for& previously given#", |
| 7962 |
Choice, Elit); |
| 7963 |
Err := True; |
| 7964 |
end if; |
| 7965 |
|
| 7966 |
Set_Enumeration_Rep_Expr (Elit, Expression (Assoc)); |
| 7967 |
|
| 7968 |
Expr := Expression (Assoc); |
| 7969 |
Val := Static_Integer (Expr); |
| 7970 |
|
| 7971 |
if No (Val) then |
| 7972 |
Err := True; |
| 7973 |
|
| 7974 |
elsif Val < Lo or else Hi < Val then |
| 7975 |
Error_Msg_N ("value outside permitted range", Expr); |
| 7976 |
Err := True; |
| 7977 |
|
| 7978 |
else |
| 7979 |
Set_Enumeration_Rep (Elit, Val); |
| 7980 |
end if; |
| 7981 |
end if; |
| 7982 |
end if; |
| 7983 |
end if; |
| 7984 |
end if; |
| 7985 |
|
| 7986 |
Next (Assoc); |
| 7987 |
end loop; |
| 7988 |
end if; |
| 7989 |
|
| 7990 |
-- Aggregate is fully processed. Now we check that a full set of |
| 7991 |
-- representations was given, and that they are in range and in order. |
| 7992 |
-- These checks are only done if no other errors occurred. |
| 7993 |
|
| 7994 |
if not Err then |
| 7995 |
Min := No_Uint; |
| 7996 |
Max := No_Uint; |
| 7997 |
|
| 7998 |
Elit := First_Literal (Enumtype); |
| 7999 |
while Present (Elit) loop |
| 8000 |
if No (Enumeration_Rep_Expr (Elit)) then |
| 8001 |
Error_Msg_NE ("missing representation for&!", N, Elit); |
| 8002 |
|
| 8003 |
else |
| 8004 |
Val := Enumeration_Rep (Elit); |
| 8005 |
|
| 8006 |
if No (Min) then |
| 8007 |
Min := Val; |
| 8008 |
end if; |
| 8009 |
|
| 8010 |
if Present (Val) then |
| 8011 |
if Present (Max) and then Val <= Max then |
| 8012 |
Error_Msg_NE |
| 8013 |
("enumeration value for& not ordered!", |
| 8014 |
Enumeration_Rep_Expr (Elit), Elit); |
| 8015 |
end if; |
| 8016 |
|
| 8017 |
Max_Node := Enumeration_Rep_Expr (Elit); |
| 8018 |
Max := Val; |
| 8019 |
end if; |
| 8020 |
|
| 8021 |
-- If there is at least one literal whose representation is not |
| 8022 |
-- equal to the Pos value, then note that this enumeration type |
| 8023 |
-- has a non-standard representation. |
| 8024 |
|
| 8025 |
if Val /= Enumeration_Pos (Elit) then |
| 8026 |
Set_Has_Non_Standard_Rep (Base_Type (Enumtype)); |
| 8027 |
end if; |
| 8028 |
end if; |
| 8029 |
|
| 8030 |
Next (Elit); |
| 8031 |
end loop; |
| 8032 |
|
| 8033 |
-- Now set proper size information |
| 8034 |
|
| 8035 |
declare |
| 8036 |
Minsize : Uint := UI_From_Int (Minimum_Size (Enumtype)); |
| 8037 |
|
| 8038 |
begin |
| 8039 |
if Has_Size_Clause (Enumtype) then |
| 8040 |
|
| 8041 |
-- All OK, if size is OK now |
| 8042 |
|
| 8043 |
if RM_Size (Enumtype) >= Minsize then |
| 8044 |
null; |
| 8045 |
|
| 8046 |
else |
| 8047 |
-- Try if we can get by with biasing |
| 8048 |
|
| 8049 |
Minsize := |
| 8050 |
UI_From_Int (Minimum_Size (Enumtype, Biased => True)); |
| 8051 |
|
| 8052 |
-- Error message if even biasing does not work |
| 8053 |
|
| 8054 |
if RM_Size (Enumtype) < Minsize then |
| 8055 |
Error_Msg_Uint_1 := RM_Size (Enumtype); |
| 8056 |
Error_Msg_Uint_2 := Max; |
| 8057 |
Error_Msg_N |
| 8058 |
("previously given size (^) is too small " |
| 8059 |
& "for this value (^)", Max_Node); |
| 8060 |
|
| 8061 |
-- If biasing worked, indicate that we now have biased rep |
| 8062 |
|
| 8063 |
else |
| 8064 |
Set_Biased |
| 8065 |
(Enumtype, Size_Clause (Enumtype), "size clause"); |
| 8066 |
end if; |
| 8067 |
end if; |
| 8068 |
|
| 8069 |
else |
| 8070 |
Set_RM_Size (Enumtype, Minsize); |
| 8071 |
Set_Enum_Esize (Enumtype); |
| 8072 |
end if; |
| 8073 |
|
| 8074 |
Set_RM_Size (Base_Type (Enumtype), RM_Size (Enumtype)); |
| 8075 |
Set_Esize (Base_Type (Enumtype), Esize (Enumtype)); |
| 8076 |
|
| 8077 |
Copy_Alignment (To => Base_Type (Enumtype), From => Enumtype); |
| 8078 |
end; |
| 8079 |
end if; |
| 8080 |
|
| 8081 |
-- We repeat the too late test in case it froze itself |
| 8082 |
|
| 8083 |
if Rep_Item_Too_Late (Enumtype, N) then |
| 8084 |
null; |
| 8085 |
end if; |
| 8086 |
end Analyze_Enumeration_Representation_Clause; |
| 8087 |
|
| 8088 |
---------------------------- |
| 8089 |
-- Analyze_Free_Statement -- |
| 8090 |
---------------------------- |
| 8091 |
|
| 8092 |
procedure Analyze_Free_Statement (N : Node_Id) is |
| 8093 |
begin |
| 8094 |
Analyze (Expression (N)); |
| 8095 |
end Analyze_Free_Statement; |
| 8096 |
|
| 8097 |
--------------------------- |
| 8098 |
-- Analyze_Freeze_Entity -- |
| 8099 |
--------------------------- |
| 8100 |
|
| 8101 |
procedure Analyze_Freeze_Entity (N : Node_Id) is |
| 8102 |
begin |
| 8103 |
Freeze_Entity_Checks (N); |
| 8104 |
end Analyze_Freeze_Entity; |
| 8105 |
|
| 8106 |
----------------------------------- |
| 8107 |
-- Analyze_Freeze_Generic_Entity -- |
| 8108 |
----------------------------------- |
| 8109 |
|
| 8110 |
procedure Analyze_Freeze_Generic_Entity (N : Node_Id) is |
| 8111 |
E : constant Entity_Id := Entity (N); |
| 8112 |
|
| 8113 |
begin |
| 8114 |
if not Is_Frozen (E) and then Has_Delayed_Aspects (E) then |
| 8115 |
Analyze_Aspects_At_Freeze_Point (E); |
| 8116 |
end if; |
| 8117 |
|
| 8118 |
Freeze_Entity_Checks (N); |
| 8119 |
end Analyze_Freeze_Generic_Entity; |
| 8120 |
|
| 8121 |
------------------------------------------ |
| 8122 |
-- Analyze_Record_Representation_Clause -- |
| 8123 |
------------------------------------------ |
| 8124 |
|
| 8125 |
-- Note: we check as much as we can here, but we can't do any checks |
| 8126 |
-- based on the position values (e.g. overlap checks) until freeze time |
| 8127 |
-- because especially in Ada 2005 (machine scalar mode), the processing |
| 8128 |
-- for non-standard bit order can substantially change the positions. |
| 8129 |
-- See procedure Check_Record_Representation_Clause (called from Freeze) |
| 8130 |
-- for the remainder of this processing. |
| 8131 |
|
| 8132 |
procedure Analyze_Record_Representation_Clause (N : Node_Id) is |
| 8133 |
Ident : constant Node_Id := Identifier (N); |
| 8134 |
Biased : Boolean; |
| 8135 |
CC : Node_Id; |
| 8136 |
Comp : Entity_Id; |
| 8137 |
Fbit : Uint; |
| 8138 |
Lbit : Uint; |
| 8139 |
Ocomp : Entity_Id; |
| 8140 |
Posit : Uint; |
| 8141 |
Rectype : Entity_Id; |
| 8142 |
Recdef : Node_Id; |
| 8143 |
|
| 8144 |
function Is_Inherited (Comp : Entity_Id) return Boolean; |
| 8145 |
-- True if Comp is an inherited component in a record extension |
| 8146 |
|
| 8147 |
------------------ |
| 8148 |
-- Is_Inherited -- |
| 8149 |
------------------ |
| 8150 |
|
| 8151 |
function Is_Inherited (Comp : Entity_Id) return Boolean is |
| 8152 |
Comp_Base : Entity_Id; |
| 8153 |
|
| 8154 |
begin |
| 8155 |
if Ekind (Rectype) = E_Record_Subtype then |
| 8156 |
Comp_Base := Original_Record_Component (Comp); |
| 8157 |
else |
| 8158 |
Comp_Base := Comp; |
| 8159 |
end if; |
| 8160 |
|
| 8161 |
return Comp_Base /= Original_Record_Component (Comp_Base); |
| 8162 |
end Is_Inherited; |
| 8163 |
|
| 8164 |
-- Local variables |
| 8165 |
|
| 8166 |
Is_Record_Extension : Boolean; |
| 8167 |
-- True if Rectype is a record extension |
| 8168 |
|
| 8169 |
CR_Pragma : Node_Id := Empty; |
| 8170 |
-- Points to N_Pragma node if Complete_Representation pragma present |
| 8171 |
|
| 8172 |
-- Start of processing for Analyze_Record_Representation_Clause |
| 8173 |
|
| 8174 |
begin |
| 8175 |
if Ignore_Rep_Clauses then |
| 8176 |
Kill_Rep_Clause (N); |
| 8177 |
return; |
| 8178 |
end if; |
| 8179 |
|
| 8180 |
Find_Type (Ident); |
| 8181 |
Rectype := Entity (Ident); |
| 8182 |
|
| 8183 |
if Rectype = Any_Type or else Rep_Item_Too_Early (Rectype, N) then |
| 8184 |
return; |
| 8185 |
else |
| 8186 |
Rectype := Underlying_Type (Rectype); |
| 8187 |
end if; |
| 8188 |
|
| 8189 |
-- First some basic error checks |
| 8190 |
|
| 8191 |
if not Is_Record_Type (Rectype) then |
| 8192 |
Error_Msg_NE |
| 8193 |
("record type required, found}", Ident, First_Subtype (Rectype)); |
| 8194 |
return; |
| 8195 |
|
| 8196 |
elsif Scope (Rectype) /= Current_Scope then |
| 8197 |
Error_Msg_N ("type must be declared in this scope", N); |
| 8198 |
return; |
| 8199 |
|
| 8200 |
elsif not Is_First_Subtype (Rectype) then |
| 8201 |
Error_Msg_N ("cannot give record rep clause for subtype", N); |
| 8202 |
return; |
| 8203 |
|
| 8204 |
elsif Has_Record_Rep_Clause (Rectype) then |
| 8205 |
Error_Msg_N ("duplicate record rep clause ignored", N); |
| 8206 |
return; |
| 8207 |
|
| 8208 |
elsif Rep_Item_Too_Late (Rectype, N) then |
| 8209 |
return; |
| 8210 |
end if; |
| 8211 |
|
| 8212 |
-- We know we have a first subtype, now possibly go to the anonymous |
| 8213 |
-- base type to determine whether Rectype is a record extension. |
| 8214 |
|
| 8215 |
Recdef := Type_Definition (Declaration_Node (Base_Type (Rectype))); |
| 8216 |
Is_Record_Extension := |
| 8217 |
Nkind (Recdef) = N_Derived_Type_Definition |
| 8218 |
and then Present (Record_Extension_Part (Recdef)); |
| 8219 |
|
| 8220 |
if Present (Mod_Clause (N)) then |
| 8221 |
declare |
| 8222 |
M : constant Node_Id := Mod_Clause (N); |
| 8223 |
P : constant List_Id := Pragmas_Before (M); |
| 8224 |
Ignore : Uint; |
| 8225 |
|
| 8226 |
begin |
| 8227 |
Check_Restriction (No_Obsolescent_Features, Mod_Clause (N)); |
| 8228 |
|
| 8229 |
if Warn_On_Obsolescent_Feature then |
| 8230 |
Error_Msg_N |
| 8231 |
("?j?mod clause is an obsolescent feature (RM J.8)", N); |
| 8232 |
Error_Msg_N |
| 8233 |
("\?j?use alignment attribute definition clause instead", N); |
| 8234 |
end if; |
| 8235 |
|
| 8236 |
if Present (P) then |
| 8237 |
Analyze_List (P); |
| 8238 |
end if; |
| 8239 |
|
| 8240 |
-- Get the alignment value to perform error checking |
| 8241 |
|
| 8242 |
Ignore := Get_Alignment_Value (Expression (M)); |
| 8243 |
end; |
| 8244 |
end if; |
| 8245 |
|
| 8246 |
-- For untagged types, clear any existing component clauses for the |
| 8247 |
-- type. If the type is derived, this is what allows us to override |
| 8248 |
-- a rep clause for the parent. For type extensions, the representation |
| 8249 |
-- of the inherited components is inherited, so we want to keep previous |
| 8250 |
-- component clauses for completeness. |
| 8251 |
|
| 8252 |
if not Is_Tagged_Type (Rectype) then |
| 8253 |
Comp := First_Component_Or_Discriminant (Rectype); |
| 8254 |
while Present (Comp) loop |
| 8255 |
Set_Component_Clause (Comp, Empty); |
| 8256 |
Next_Component_Or_Discriminant (Comp); |
| 8257 |
end loop; |
| 8258 |
end if; |
| 8259 |
|
| 8260 |
-- All done if no component clauses |
| 8261 |
|
| 8262 |
CC := First (Component_Clauses (N)); |
| 8263 |
|
| 8264 |
if No (CC) then |
| 8265 |
return; |
| 8266 |
end if; |
| 8267 |
|
| 8268 |
-- A representation like this applies to the base type |
| 8269 |
|
| 8270 |
Set_Has_Record_Rep_Clause (Base_Type (Rectype)); |
| 8271 |
Set_Has_Non_Standard_Rep (Base_Type (Rectype)); |
| 8272 |
Set_Has_Specified_Layout (Base_Type (Rectype)); |
| 8273 |
|
| 8274 |
-- Process the component clauses |
| 8275 |
|
| 8276 |
while Present (CC) loop |
| 8277 |
|
| 8278 |
-- Pragma |
| 8279 |
|
| 8280 |
if Nkind (CC) = N_Pragma then |
| 8281 |
Analyze (CC); |
| 8282 |
|
| 8283 |
-- The only pragma of interest is Complete_Representation |
| 8284 |
|
| 8285 |
if Pragma_Name (CC) = Name_Complete_Representation then |
| 8286 |
CR_Pragma := CC; |
| 8287 |
end if; |
| 8288 |
|
| 8289 |
-- Processing for real component clause |
| 8290 |
|
| 8291 |
else |
| 8292 |
Posit := Static_Integer (Position (CC)); |
| 8293 |
Fbit := Static_Integer (First_Bit (CC)); |
| 8294 |
Lbit := Static_Integer (Last_Bit (CC)); |
| 8295 |
|
| 8296 |
if Present (Posit) |
| 8297 |
and then Present (Fbit) |
| 8298 |
and then Present (Lbit) |
| 8299 |
then |
| 8300 |
if Posit < 0 then |
| 8301 |
Error_Msg_N ("position cannot be negative", Position (CC)); |
| 8302 |
|
| 8303 |
elsif Fbit < 0 then |
| 8304 |
Error_Msg_N ("first bit cannot be negative", First_Bit (CC)); |
| 8305 |
|
| 8306 |
-- The Last_Bit specified in a component clause must not be |
| 8307 |
-- less than the First_Bit minus one (RM-13.5.1(10)). |
| 8308 |
|
| 8309 |
elsif Lbit < Fbit - 1 then |
| 8310 |
Error_Msg_N |
| 8311 |
("last bit cannot be less than first bit minus one", |
| 8312 |
Last_Bit (CC)); |
| 8313 |
|
| 8314 |
-- Values look OK, so find the corresponding record component |
| 8315 |
-- Even though the syntax allows an attribute reference for |
| 8316 |
-- implementation-defined components, GNAT does not allow the |
| 8317 |
-- tag to get an explicit position. |
| 8318 |
|
| 8319 |
elsif Nkind (Component_Name (CC)) = N_Attribute_Reference then |
| 8320 |
if Attribute_Name (Component_Name (CC)) = Name_Tag then |
| 8321 |
Error_Msg_N ("position of tag cannot be specified", CC); |
| 8322 |
else |
| 8323 |
Error_Msg_N ("illegal component name", CC); |
| 8324 |
end if; |
| 8325 |
|
| 8326 |
else |
| 8327 |
Comp := First_Entity (Rectype); |
| 8328 |
while Present (Comp) loop |
| 8329 |
exit when Chars (Comp) = Chars (Component_Name (CC)); |
| 8330 |
Next_Entity (Comp); |
| 8331 |
end loop; |
| 8332 |
|
| 8333 |
if No (Comp) then |
| 8334 |
|
| 8335 |
-- Maybe component of base type that is absent from |
| 8336 |
-- statically constrained first subtype. |
| 8337 |
|
| 8338 |
Comp := First_Entity (Base_Type (Rectype)); |
| 8339 |
while Present (Comp) loop |
| 8340 |
exit when Chars (Comp) = Chars (Component_Name (CC)); |
| 8341 |
Next_Entity (Comp); |
| 8342 |
end loop; |
| 8343 |
end if; |
| 8344 |
|
| 8345 |
if No (Comp) then |
| 8346 |
Error_Msg_N |
| 8347 |
("component clause is for non-existent field", CC); |
| 8348 |
|
| 8349 |
-- Ada 2012 (AI05-0026): Any name that denotes a |
| 8350 |
-- discriminant of an object of an unchecked union type |
| 8351 |
-- shall not occur within a record_representation_clause. |
| 8352 |
|
| 8353 |
-- The general restriction of using record rep clauses on |
| 8354 |
-- Unchecked_Union types has now been lifted. Since it is |
| 8355 |
-- possible to introduce a record rep clause which mentions |
| 8356 |
-- the discriminant of an Unchecked_Union in non-Ada 2012 |
| 8357 |
-- code, this check is applied to all versions of the |
| 8358 |
-- language. |
| 8359 |
|
| 8360 |
elsif Ekind (Comp) = E_Discriminant |
| 8361 |
and then Is_Unchecked_Union (Rectype) |
| 8362 |
then |
| 8363 |
Error_Msg_N |
| 8364 |
("cannot reference discriminant of unchecked union", |
| 8365 |
Component_Name (CC)); |
| 8366 |
|
| 8367 |
elsif Is_Record_Extension and then Is_Inherited (Comp) then |
| 8368 |
Error_Msg_NE |
| 8369 |
("component clause not allowed for inherited " |
| 8370 |
& "component&", CC, Comp); |
| 8371 |
|
| 8372 |
elsif Present (Component_Clause (Comp)) then |
| 8373 |
|
| 8374 |
-- Diagnose duplicate rep clause, or check consistency |
| 8375 |
-- if this is an inherited component. In a double fault, |
| 8376 |
-- there may be a duplicate inconsistent clause for an |
| 8377 |
-- inherited component. |
| 8378 |
|
| 8379 |
if Scope (Original_Record_Component (Comp)) = Rectype |
| 8380 |
or else Parent (Component_Clause (Comp)) = N |
| 8381 |
then |
| 8382 |
Error_Msg_Sloc := Sloc (Component_Clause (Comp)); |
| 8383 |
Error_Msg_N ("component clause previously given#", CC); |
| 8384 |
|
| 8385 |
else |
| 8386 |
declare |
| 8387 |
Rep1 : constant Node_Id := Component_Clause (Comp); |
| 8388 |
begin |
| 8389 |
if Intval (Position (Rep1)) /= |
| 8390 |
Intval (Position (CC)) |
| 8391 |
or else Intval (First_Bit (Rep1)) /= |
| 8392 |
Intval (First_Bit (CC)) |
| 8393 |
or else Intval (Last_Bit (Rep1)) /= |
| 8394 |
Intval (Last_Bit (CC)) |
| 8395 |
then |
| 8396 |
Error_Msg_N |
| 8397 |
("component clause inconsistent with " |
| 8398 |
& "representation of ancestor", CC); |
| 8399 |
|
| 8400 |
elsif Warn_On_Redundant_Constructs then |
| 8401 |
Error_Msg_N |
| 8402 |
("?r?redundant confirming component clause " |
| 8403 |
& "for component!", CC); |
| 8404 |
end if; |
| 8405 |
end; |
| 8406 |
end if; |
| 8407 |
|
| 8408 |
-- Normal case where this is the first component clause we |
| 8409 |
-- have seen for this entity, so set it up properly. |
| 8410 |
|
| 8411 |
else |
| 8412 |
-- Make reference for field in record rep clause and set |
| 8413 |
-- appropriate entity field in the field identifier. |
| 8414 |
|
| 8415 |
Generate_Reference |
| 8416 |
(Comp, Component_Name (CC), Set_Ref => False); |
| 8417 |
Set_Entity_With_Checks (Component_Name (CC), Comp); |
| 8418 |
|
| 8419 |
-- Update Fbit and Lbit to the actual bit number |
| 8420 |
|
| 8421 |
Fbit := Fbit + UI_From_Int (SSU) * Posit; |
| 8422 |
Lbit := Lbit + UI_From_Int (SSU) * Posit; |
| 8423 |
|
| 8424 |
if Has_Size_Clause (Rectype) |
| 8425 |
and then RM_Size (Rectype) <= Lbit |
| 8426 |
then |
| 8427 |
Error_Msg_Uint_1 := RM_Size (Rectype); |
| 8428 |
Error_Msg_Uint_2 := Lbit + 1; |
| 8429 |
Error_Msg_N ("bit number out of range of specified " |
| 8430 |
& "size (expected ^, got ^)", |
| 8431 |
Last_Bit (CC)); |
| 8432 |
else |
| 8433 |
Set_Component_Clause (Comp, CC); |
| 8434 |
Set_Component_Bit_Offset (Comp, Fbit); |
| 8435 |
Set_Esize (Comp, 1 + (Lbit - Fbit)); |
| 8436 |
Set_Normalized_First_Bit (Comp, Fbit mod SSU); |
| 8437 |
Set_Normalized_Position (Comp, Fbit / SSU); |
| 8438 |
|
| 8439 |
if Warn_On_Overridden_Size |
| 8440 |
and then Has_Size_Clause (Etype (Comp)) |
| 8441 |
and then RM_Size (Etype (Comp)) /= Esize (Comp) |
| 8442 |
then |
| 8443 |
Error_Msg_NE |
| 8444 |
("?.s?component size overrides size clause for&", |
| 8445 |
Component_Name (CC), Etype (Comp)); |
| 8446 |
end if; |
| 8447 |
|
| 8448 |
Check_Size |
| 8449 |
(Component_Name (CC), |
| 8450 |
Etype (Comp), |
| 8451 |
Esize (Comp), |
| 8452 |
Biased); |
| 8453 |
|
| 8454 |
Set_Biased |
| 8455 |
(Comp, First_Node (CC), "component clause", Biased); |
| 8456 |
|
| 8457 |
-- This information is also set in the corresponding |
| 8458 |
-- component of the base type, found by accessing the |
| 8459 |
-- Original_Record_Component link if it is present. |
| 8460 |
|
| 8461 |
Ocomp := Original_Record_Component (Comp); |
| 8462 |
|
| 8463 |
if Present (Ocomp) and then Ocomp /= Comp then |
| 8464 |
Set_Component_Clause (Ocomp, CC); |
| 8465 |
Set_Component_Bit_Offset (Ocomp, Fbit); |
| 8466 |
Set_Esize (Ocomp, 1 + (Lbit - Fbit)); |
| 8467 |
Set_Normalized_First_Bit (Ocomp, Fbit mod SSU); |
| 8468 |
Set_Normalized_Position (Ocomp, Fbit / SSU); |
| 8469 |
|
| 8470 |
-- Note: we don't use Set_Biased here, because we |
| 8471 |
-- already gave a warning above if needed, and we |
| 8472 |
-- would get a duplicate for the same name here. |
| 8473 |
|
| 8474 |
Set_Has_Biased_Representation |
| 8475 |
(Ocomp, Has_Biased_Representation (Comp)); |
| 8476 |
end if; |
| 8477 |
|
| 8478 |
if Esize (Comp) < 0 then |
| 8479 |
Error_Msg_N ("component size is negative", CC); |
| 8480 |
end if; |
| 8481 |
end if; |
| 8482 |
end if; |
| 8483 |
end if; |
| 8484 |
end if; |
| 8485 |
end if; |
| 8486 |
|
| 8487 |
Next (CC); |
| 8488 |
end loop; |
| 8489 |
|
| 8490 |
-- Check missing components if Complete_Representation pragma appeared |
| 8491 |
|
| 8492 |
if Present (CR_Pragma) then |
| 8493 |
Comp := First_Component_Or_Discriminant (Rectype); |
| 8494 |
while Present (Comp) loop |
| 8495 |
if No (Component_Clause (Comp)) then |
| 8496 |
Error_Msg_NE |
| 8497 |
("missing component clause for &", CR_Pragma, Comp); |
| 8498 |
end if; |
| 8499 |
|
| 8500 |
Next_Component_Or_Discriminant (Comp); |
| 8501 |
end loop; |
| 8502 |
|
| 8503 |
-- Give missing components warning if required |
| 8504 |
|
| 8505 |
elsif Warn_On_Unrepped_Components then |
| 8506 |
declare |
| 8507 |
Num_Repped_Components : Nat := 0; |
| 8508 |
Num_Unrepped_Components : Nat := 0; |
| 8509 |
|
| 8510 |
begin |
| 8511 |
-- First count number of repped and unrepped components |
| 8512 |
|
| 8513 |
Comp := First_Component_Or_Discriminant (Rectype); |
| 8514 |
while Present (Comp) loop |
| 8515 |
if Present (Component_Clause (Comp)) then |
| 8516 |
Num_Repped_Components := Num_Repped_Components + 1; |
| 8517 |
else |
| 8518 |
Num_Unrepped_Components := Num_Unrepped_Components + 1; |
| 8519 |
end if; |
| 8520 |
|
| 8521 |
Next_Component_Or_Discriminant (Comp); |
| 8522 |
end loop; |
| 8523 |
|
| 8524 |
-- We are only interested in the case where there is at least one |
| 8525 |
-- unrepped component, and at least half the components have rep |
| 8526 |
-- clauses. We figure that if less than half have them, then the |
| 8527 |
-- partial rep clause is really intentional. If the component |
| 8528 |
-- type has no underlying type set at this point (as for a generic |
| 8529 |
-- formal type), we don't know enough to give a warning on the |
| 8530 |
-- component. |
| 8531 |
|
| 8532 |
if Num_Unrepped_Components > 0 |
| 8533 |
and then Num_Unrepped_Components < Num_Repped_Components |
| 8534 |
then |
| 8535 |
Comp := First_Component_Or_Discriminant (Rectype); |
| 8536 |
while Present (Comp) loop |
| 8537 |
if No (Component_Clause (Comp)) |
| 8538 |
and then Comes_From_Source (Comp) |
| 8539 |
and then Present (Underlying_Type (Etype (Comp))) |
| 8540 |
and then (Is_Scalar_Type (Underlying_Type (Etype (Comp))) |
| 8541 |
or else Size_Known_At_Compile_Time |
| 8542 |
(Underlying_Type (Etype (Comp)))) |
| 8543 |
and then not Has_Warnings_Off (Rectype) |
| 8544 |
|
| 8545 |
-- Ignore discriminant in unchecked union, since it is |
| 8546 |
-- not there, and cannot have a component clause. |
| 8547 |
|
| 8548 |
and then (not Is_Unchecked_Union (Rectype) |
| 8549 |
or else Ekind (Comp) /= E_Discriminant) |
| 8550 |
then |
| 8551 |
Error_Msg_Sloc := Sloc (Comp); |
| 8552 |
Error_Msg_NE |
| 8553 |
("?.c?no component clause given for & declared #", |
| 8554 |
N, Comp); |
| 8555 |
end if; |
| 8556 |
|
| 8557 |
Next_Component_Or_Discriminant (Comp); |
| 8558 |
end loop; |
| 8559 |
end if; |
| 8560 |
end; |
| 8561 |
end if; |
| 8562 |
end Analyze_Record_Representation_Clause; |
| 8563 |
|
| 8564 |
---------------------------------------------- |
| 8565 |
-- Analyze_User_Aspect_Aspect_Specification -- |
| 8566 |
---------------------------------------------- |
| 8567 |
|
| 8568 |
procedure Analyze_User_Aspect_Aspect_Specification (N : Node_Id) is |
| 8569 |
OK : Boolean := True; |
| 8570 |
|
| 8571 |
procedure Analyze_One_User_Aspect (Id : Node_Id); |
| 8572 |
-- A User_Aspect aspect specification may specify multiple |
| 8573 |
-- user-defined aspects. This procedure is called for each one. |
| 8574 |
|
| 8575 |
----------------------------- |
| 8576 |
-- Analyze_One_User_Aspect -- |
| 8577 |
----------------------------- |
| 8578 |
|
| 8579 |
procedure Analyze_One_User_Aspect (Id : Node_Id) is |
| 8580 |
UAD_Pragma : constant Node_Id := |
| 8581 |
User_Aspect_Support.Registered_UAD_Pragma (Chars (Id)); |
| 8582 |
|
| 8583 |
Arg : Node_Id; |
| 8584 |
begin |
| 8585 |
if No (UAD_Pragma) then |
| 8586 |
Error_Msg_N ("no definition for user-defined aspect", Id); |
| 8587 |
return; |
| 8588 |
end if; |
| 8589 |
|
| 8590 |
-- Process args in reverse order so that inserted |
| 8591 |
-- aspect specs end up in "right" order (although |
| 8592 |
-- order shouldn't matter). |
| 8593 |
Arg := Last (Pragma_Argument_Associations (UAD_Pragma)); |
| 8594 |
|
| 8595 |
-- Skip first argument, which is the name of the |
| 8596 |
-- user-defined aspect. |
| 8597 |
while Present (Prev (Arg)) loop |
| 8598 |
declare |
| 8599 |
Exp : constant Node_Id := Expression (Arg); |
| 8600 |
New_Sloc : constant Source_Ptr := Sloc (N); |
| 8601 |
New_Aspect_Spec : Node_Id; |
| 8602 |
New_Exp : Node_Id; |
| 8603 |
New_Exp_List : List_Id; |
| 8604 |
begin |
| 8605 |
case Nkind (Exp) is |
| 8606 |
when N_Identifier => |
| 8607 |
New_Aspect_Spec := |
| 8608 |
Make_Aspect_Specification |
| 8609 |
(New_Sloc, |
| 8610 |
Identifier => |
| 8611 |
New_Copy_Tree (Exp, New_Sloc => New_Sloc)); |
| 8612 |
|
| 8613 |
when N_Indexed_Component => |
| 8614 |
New_Exp_List := New_List; |
| 8615 |
|
| 8616 |
declare |
| 8617 |
Index_Exp : Node_Id := First (Expressions (Exp)); |
| 8618 |
begin |
| 8619 |
while Present (Index_Exp) loop |
| 8620 |
Append (New_Copy_Tree |
| 8621 |
(Index_Exp, New_Sloc => New_Sloc), |
| 8622 |
To => New_Exp_List); |
| 8623 |
Next (Index_Exp); |
| 8624 |
end loop; |
| 8625 |
end; |
| 8626 |
|
| 8627 |
New_Exp := Make_Aggregate |
| 8628 |
(Sloc => New_Sloc, |
| 8629 |
Expressions => New_Exp_List, |
| 8630 |
Is_Parenthesis_Aggregate => True); |
| 8631 |
|
| 8632 |
New_Aspect_Spec := |
| 8633 |
Make_Aspect_Specification |
| 8634 |
(New_Sloc, |
| 8635 |
Identifier => |
| 8636 |
New_Copy_Tree (Prefix (Exp), New_Sloc => New_Sloc), |
| 8637 |
Expression => New_Exp); |
| 8638 |
|
| 8639 |
when others => |
| 8640 |
raise Program_Error; |
| 8641 |
end case; |
| 8642 |
|
| 8643 |
Insert_After (After => N, Node => New_Aspect_Spec); |
| 8644 |
end; |
| 8645 |
Arg := Prev (Arg); |
| 8646 |
end loop; |
| 8647 |
end Analyze_One_User_Aspect; |
| 8648 |
begin |
| 8649 |
if Analyzed (N) then |
| 8650 |
return; |
| 8651 |
end if; |
| 8652 |
|
| 8653 |
-- This aspect can be specified for any entity whose |
| 8654 |
-- syntax allows an aspect specification. |
| 8655 |
-- The analysis code below constructs new aspect |
| 8656 |
-- specifications for the given entity; each might |
| 8657 |
-- turn out to be legal or illegal. That is determined |
| 8658 |
-- when each of these new aspect_specs is analyzed. |
| 8659 |
|
| 8660 |
case Nkind (Expression (N)) is |
| 8661 |
when N_Identifier => |
| 8662 |
Analyze_One_User_Aspect (Expression (N)); |
| 8663 |
when N_Aggregate => |
| 8664 |
OK := Is_Parenthesis_Aggregate (Expression (N)); |
| 8665 |
declare |
| 8666 |
Id : Node_Id := First (Expressions (Expression (N))); |
| 8667 |
begin |
| 8668 |
while Present (Id) loop |
| 8669 |
if Nkind (Id) = N_Identifier then |
| 8670 |
Analyze_One_User_Aspect (Id); |
| 8671 |
else |
| 8672 |
OK := False; |
| 8673 |
end if; |
| 8674 |
Next (Id); |
| 8675 |
end loop; |
| 8676 |
end; |
| 8677 |
when others => |
| 8678 |
OK := False; |
| 8679 |
end case; |
| 8680 |
|
| 8681 |
if not OK then |
| 8682 |
Error_Msg_N |
| 8683 |
("Bad argument for User_Aspect aspect specification", N); |
| 8684 |
end if; |
| 8685 |
|
| 8686 |
Set_Analyzed (N); |
| 8687 |
end Analyze_User_Aspect_Aspect_Specification; |
| 8688 |
|
| 8689 |
------------------------------------- |
| 8690 |
-- Build_Discrete_Static_Predicate -- |
| 8691 |
------------------------------------- |
| 8692 |
|
| 8693 |
procedure Build_Discrete_Static_Predicate |
| 8694 |
(Typ : Entity_Id; |
| 8695 |
Expr : Node_Id; |
| 8696 |
Nam : Name_Id) |
| 8697 |
is |
| 8698 |
Loc : constant Source_Ptr := Sloc (Expr); |
| 8699 |
|
| 8700 |
Btyp : constant Entity_Id := Base_Type (Typ); |
| 8701 |
|
| 8702 |
BLo : constant Uint := Expr_Value (Type_Low_Bound (Btyp)); |
| 8703 |
BHi : constant Uint := Expr_Value (Type_High_Bound (Btyp)); |
| 8704 |
-- Low bound and high bound value of base type of Typ |
| 8705 |
|
| 8706 |
TLo : Uint; |
| 8707 |
THi : Uint; |
| 8708 |
-- Bounds for constructing the static predicate. We use the bound of the |
| 8709 |
-- subtype if it is static, otherwise the corresponding base type bound. |
| 8710 |
-- Note: a non-static subtype can have a static predicate. |
| 8711 |
|
| 8712 |
type REnt is record |
| 8713 |
Lo, Hi : Uint; |
| 8714 |
end record; |
| 8715 |
-- One entry in a Rlist value, a single REnt (range entry) value denotes |
| 8716 |
-- one range from Lo to Hi. To represent a single value range Lo = Hi = |
| 8717 |
-- value. |
| 8718 |
|
| 8719 |
type RList is array (Nat range <>) of REnt; |
| 8720 |
-- A list of ranges. The ranges are sorted in increasing order, and are |
| 8721 |
-- disjoint (there is a gap of at least one value between each range in |
| 8722 |
-- the table). A value is in the set of ranges in Rlist if it lies |
| 8723 |
-- within one of these ranges. |
| 8724 |
|
| 8725 |
False_Range : constant RList := |
| 8726 |
RList'(1 .. 0 => REnt'(No_Uint, No_Uint)); |
| 8727 |
-- An empty set of ranges represents a range list that can never be |
| 8728 |
-- satisfied, since there are no ranges in which the value could lie, |
| 8729 |
-- so it does not lie in any of them. False_Range is a canonical value |
| 8730 |
-- for this empty set, but general processing should test for an Rlist |
| 8731 |
-- with length zero (see Is_False predicate), since other null ranges |
| 8732 |
-- may appear which must be treated as False. |
| 8733 |
|
| 8734 |
True_Range : constant RList := RList'(1 => REnt'(BLo, BHi)); |
| 8735 |
-- Range representing True, value must be in the base range |
| 8736 |
|
| 8737 |
function "and" (Left : RList; Right : RList) return RList; |
| 8738 |
-- And's together two range lists, returning a range list. This is a set |
| 8739 |
-- intersection operation. |
| 8740 |
|
| 8741 |
function "or" (Left : RList; Right : RList) return RList; |
| 8742 |
-- Or's together two range lists, returning a range list. This is a set |
| 8743 |
-- union operation. |
| 8744 |
|
| 8745 |
function "not" (Right : RList) return RList; |
| 8746 |
-- Returns complement of a given range list, i.e. a range list |
| 8747 |
-- representing all the values in TLo .. THi that are not in the input |
| 8748 |
-- operand Right. |
| 8749 |
|
| 8750 |
function Build_Val (V : Uint) return Node_Id; |
| 8751 |
-- Return an analyzed N_Identifier node referencing this value, suitable |
| 8752 |
-- for use as an entry in the Static_Discrete_Predicate list. This node |
| 8753 |
-- is typed with the base type. |
| 8754 |
|
| 8755 |
function Build_Range (Lo : Uint; Hi : Uint) return Node_Id; |
| 8756 |
-- Return an analyzed N_Range node referencing this range, suitable for |
| 8757 |
-- use as an entry in the Static_Discrete_Predicate list. This node is |
| 8758 |
-- typed with the base type. |
| 8759 |
|
| 8760 |
function Get_RList |
| 8761 |
(Exp : Node_Id; |
| 8762 |
Static : access Boolean) return RList; |
| 8763 |
-- This is a recursive routine that converts the given expression into a |
| 8764 |
-- list of ranges, suitable for use in building the static predicate. |
| 8765 |
-- Static.all will be set to False if the expression is found to be non |
| 8766 |
-- static. Note that Static.all should be set to True by the caller. |
| 8767 |
|
| 8768 |
function Is_False (R : RList) return Boolean; |
| 8769 |
pragma Inline (Is_False); |
| 8770 |
-- Returns True if the given range list is empty, and thus represents a |
| 8771 |
-- False list of ranges that can never be satisfied. |
| 8772 |
|
| 8773 |
function Is_True (R : RList) return Boolean; |
| 8774 |
-- Returns True if R trivially represents the True predicate by having a |
| 8775 |
-- single range from BLo to BHi. |
| 8776 |
|
| 8777 |
function Is_Type_Ref (N : Node_Id) return Boolean; |
| 8778 |
pragma Inline (Is_Type_Ref); |
| 8779 |
-- Returns if True if N is a reference to the type for the predicate in |
| 8780 |
-- the expression (i.e. if it is an identifier whose Chars field matches |
| 8781 |
-- the Nam given in the call). N must not be parenthesized, if the type |
| 8782 |
-- name appears in parens, this routine will return False. |
| 8783 |
|
| 8784 |
function Lo_Val (N : Node_Id) return Uint; |
| 8785 |
-- Given an entry from a Static_Discrete_Predicate list that is either |
| 8786 |
-- a static expression or static range, gets either the expression value |
| 8787 |
-- or the low bound of the range. |
| 8788 |
|
| 8789 |
function Hi_Val (N : Node_Id) return Uint; |
| 8790 |
-- Given an entry from a Static_Discrete_Predicate list that is either |
| 8791 |
-- a static expression or static range, gets either the expression value |
| 8792 |
-- or the high bound of the range. |
| 8793 |
|
| 8794 |
function Membership_Entry |
| 8795 |
(N : Node_Id; Static : access Boolean) return RList; |
| 8796 |
-- Given a single membership entry (range, value, or subtype), returns |
| 8797 |
-- the corresponding range list. Set Static.all to False if not static. |
| 8798 |
|
| 8799 |
function Membership_Entries |
| 8800 |
(N : Node_Id; Static : access Boolean) return RList; |
| 8801 |
-- Given an element on an alternatives list of a membership operation, |
| 8802 |
-- returns the range list corresponding to this entry and all following |
| 8803 |
-- entries (i.e. returns the "or" of this list of values). |
| 8804 |
-- Set Static.all to False if not static. |
| 8805 |
|
| 8806 |
function Stat_Pred |
| 8807 |
(Typ : Entity_Id; |
| 8808 |
Static : access Boolean) return RList; |
| 8809 |
-- Given a type, if it has a static predicate, then set Result to the |
| 8810 |
-- predicate as a range list, otherwise set Static.all to False. |
| 8811 |
|
| 8812 |
procedure Warn_If_Test_Ineffective (REntry : REnt; N : Node_Id); |
| 8813 |
-- Issue a warning if REntry includes only values that are |
| 8814 |
-- outside the range TLo .. THi. |
| 8815 |
|
| 8816 |
----------- |
| 8817 |
-- "and" -- |
| 8818 |
----------- |
| 8819 |
|
| 8820 |
function "and" (Left : RList; Right : RList) return RList is |
| 8821 |
FEnt : REnt; |
| 8822 |
-- First range of result |
| 8823 |
|
| 8824 |
SLeft : Nat := Left'First; |
| 8825 |
-- Start of rest of left entries |
| 8826 |
|
| 8827 |
SRight : Nat := Right'First; |
| 8828 |
-- Start of rest of right entries |
| 8829 |
|
| 8830 |
begin |
| 8831 |
-- If either range is True, return the other |
| 8832 |
|
| 8833 |
if Is_True (Left) then |
| 8834 |
return Right; |
| 8835 |
elsif Is_True (Right) then |
| 8836 |
return Left; |
| 8837 |
end if; |
| 8838 |
|
| 8839 |
-- If either range is False, return False |
| 8840 |
|
| 8841 |
if Is_False (Left) or else Is_False (Right) then |
| 8842 |
return False_Range; |
| 8843 |
end if; |
| 8844 |
|
| 8845 |
-- Loop to remove entries at start that are disjoint, and thus just |
| 8846 |
-- get discarded from the result entirely. |
| 8847 |
|
| 8848 |
loop |
| 8849 |
-- If no operands left in either operand, result is false |
| 8850 |
|
| 8851 |
if SLeft > Left'Last or else SRight > Right'Last then |
| 8852 |
return False_Range; |
| 8853 |
|
| 8854 |
-- Discard first left operand entry if disjoint with right |
| 8855 |
|
| 8856 |
elsif Left (SLeft).Hi < Right (SRight).Lo then |
| 8857 |
SLeft := SLeft + 1; |
| 8858 |
|
| 8859 |
-- Discard first right operand entry if disjoint with left |
| 8860 |
|
| 8861 |
elsif Right (SRight).Hi < Left (SLeft).Lo then |
| 8862 |
SRight := SRight + 1; |
| 8863 |
|
| 8864 |
-- Otherwise we have an overlapping entry |
| 8865 |
|
| 8866 |
else |
| 8867 |
exit; |
| 8868 |
end if; |
| 8869 |
end loop; |
| 8870 |
|
| 8871 |
-- Now we have two non-null operands, and first entries overlap. The |
| 8872 |
-- first entry in the result will be the overlapping part of these |
| 8873 |
-- two entries. |
| 8874 |
|
| 8875 |
FEnt := REnt'(Lo => UI_Max (Left (SLeft).Lo, Right (SRight).Lo), |
| 8876 |
Hi => UI_Min (Left (SLeft).Hi, Right (SRight).Hi)); |
| 8877 |
|
| 8878 |
-- Now we can remove the entry that ended at a lower value, since its |
| 8879 |
-- contribution is entirely contained in Fent. |
| 8880 |
|
| 8881 |
if Left (SLeft).Hi <= Right (SRight).Hi then |
| 8882 |
SLeft := SLeft + 1; |
| 8883 |
else |
| 8884 |
SRight := SRight + 1; |
| 8885 |
end if; |
| 8886 |
|
| 8887 |
-- Compute result by concatenating this first entry with the "and" of |
| 8888 |
-- the remaining parts of the left and right operands. Note that if |
| 8889 |
-- either of these is empty, "and" will yield empty, so that we will |
| 8890 |
-- end up with just Fent, which is what we want in that case. |
| 8891 |
|
| 8892 |
return |
| 8893 |
FEnt & (Left (SLeft .. Left'Last) and Right (SRight .. Right'Last)); |
| 8894 |
end "and"; |
| 8895 |
|
| 8896 |
----------- |
| 8897 |
-- "not" -- |
| 8898 |
----------- |
| 8899 |
|
| 8900 |
function "not" (Right : RList) return RList is |
| 8901 |
begin |
| 8902 |
-- Return True if False range |
| 8903 |
|
| 8904 |
if Is_False (Right) then |
| 8905 |
return True_Range; |
| 8906 |
end if; |
| 8907 |
|
| 8908 |
-- Return False if True range |
| 8909 |
|
| 8910 |
if Is_True (Right) then |
| 8911 |
return False_Range; |
| 8912 |
end if; |
| 8913 |
|
| 8914 |
-- Here if not trivial case |
| 8915 |
|
| 8916 |
declare |
| 8917 |
Result : RList (1 .. Right'Length + 1); |
| 8918 |
-- May need one more entry for gap at beginning and end |
| 8919 |
|
| 8920 |
Count : Nat := 0; |
| 8921 |
-- Number of entries stored in Result |
| 8922 |
|
| 8923 |
begin |
| 8924 |
-- Gap at start |
| 8925 |
|
| 8926 |
if Right (Right'First).Lo > TLo then |
| 8927 |
Count := Count + 1; |
| 8928 |
Result (Count) := REnt'(TLo, Right (Right'First).Lo - 1); |
| 8929 |
end if; |
| 8930 |
|
| 8931 |
-- Gaps between ranges |
| 8932 |
|
| 8933 |
for J in Right'First .. Right'Last - 1 loop |
| 8934 |
Count := Count + 1; |
| 8935 |
Result (Count) := REnt'(Right (J).Hi + 1, Right (J + 1).Lo - 1); |
| 8936 |
end loop; |
| 8937 |
|
| 8938 |
-- Gap at end |
| 8939 |
|
| 8940 |
if Right (Right'Last).Hi < THi then |
| 8941 |
Count := Count + 1; |
| 8942 |
Result (Count) := REnt'(Right (Right'Last).Hi + 1, THi); |
| 8943 |
end if; |
| 8944 |
|
| 8945 |
return Result (1 .. Count); |
| 8946 |
end; |
| 8947 |
end "not"; |
| 8948 |
|
| 8949 |
---------- |
| 8950 |
-- "or" -- |
| 8951 |
---------- |
| 8952 |
|
| 8953 |
function "or" (Left : RList; Right : RList) return RList is |
| 8954 |
FEnt : REnt; |
| 8955 |
-- First range of result |
| 8956 |
|
| 8957 |
SLeft : Nat := Left'First; |
| 8958 |
-- Start of rest of left entries |
| 8959 |
|
| 8960 |
SRight : Nat := Right'First; |
| 8961 |
-- Start of rest of right entries |
| 8962 |
|
| 8963 |
begin |
| 8964 |
-- If either range is True, return True |
| 8965 |
|
| 8966 |
if Is_True (Left) or else Is_True (Right) then |
| 8967 |
return True_Range; |
| 8968 |
end if; |
| 8969 |
|
| 8970 |
-- If either range is False (empty), return the other |
| 8971 |
|
| 8972 |
if Is_False (Left) then |
| 8973 |
return Right; |
| 8974 |
elsif Is_False (Right) then |
| 8975 |
return Left; |
| 8976 |
end if; |
| 8977 |
|
| 8978 |
-- Initialize result first entry from left or right operand depending |
| 8979 |
-- on which starts with the lower range. |
| 8980 |
|
| 8981 |
if Left (SLeft).Lo < Right (SRight).Lo then |
| 8982 |
FEnt := Left (SLeft); |
| 8983 |
SLeft := SLeft + 1; |
| 8984 |
else |
| 8985 |
FEnt := Right (SRight); |
| 8986 |
SRight := SRight + 1; |
| 8987 |
end if; |
| 8988 |
|
| 8989 |
-- This loop eats ranges from left and right operands that are |
| 8990 |
-- contiguous with the first range we are gathering. |
| 8991 |
|
| 8992 |
loop |
| 8993 |
-- Eat first entry in left operand if contiguous or overlapped by |
| 8994 |
-- gathered first operand of result. |
| 8995 |
|
| 8996 |
if SLeft <= Left'Last |
| 8997 |
and then Left (SLeft).Lo <= FEnt.Hi + 1 |
| 8998 |
then |
| 8999 |
FEnt.Hi := UI_Max (FEnt.Hi, Left (SLeft).Hi); |
| 9000 |
SLeft := SLeft + 1; |
| 9001 |
|
| 9002 |
-- Eat first entry in right operand if contiguous or overlapped by |
| 9003 |
-- gathered right operand of result. |
| 9004 |
|
| 9005 |
elsif SRight <= Right'Last |
| 9006 |
and then Right (SRight).Lo <= FEnt.Hi + 1 |
| 9007 |
then |
| 9008 |
FEnt.Hi := UI_Max (FEnt.Hi, Right (SRight).Hi); |
| 9009 |
SRight := SRight + 1; |
| 9010 |
|
| 9011 |
-- All done if no more entries to eat |
| 9012 |
|
| 9013 |
else |
| 9014 |
exit; |
| 9015 |
end if; |
| 9016 |
end loop; |
| 9017 |
|
| 9018 |
-- Obtain result as the first entry we just computed, concatenated |
| 9019 |
-- to the "or" of the remaining results (if one operand is empty, |
| 9020 |
-- this will just concatenate with the other |
| 9021 |
|
| 9022 |
return |
| 9023 |
FEnt & (Left (SLeft .. Left'Last) or Right (SRight .. Right'Last)); |
| 9024 |
end "or"; |
| 9025 |
|
| 9026 |
----------------- |
| 9027 |
-- Build_Range -- |
| 9028 |
----------------- |
| 9029 |
|
| 9030 |
function Build_Range (Lo : Uint; Hi : Uint) return Node_Id is |
| 9031 |
Result : Node_Id; |
| 9032 |
begin |
| 9033 |
Result := |
| 9034 |
Make_Range (Loc, |
| 9035 |
Low_Bound => Build_Val (Lo), |
| 9036 |
High_Bound => Build_Val (Hi)); |
| 9037 |
Set_Etype (Result, Btyp); |
| 9038 |
Set_Analyzed (Result); |
| 9039 |
return Result; |
| 9040 |
end Build_Range; |
| 9041 |
|
| 9042 |
--------------- |
| 9043 |
-- Build_Val -- |
| 9044 |
--------------- |
| 9045 |
|
| 9046 |
function Build_Val (V : Uint) return Node_Id is |
| 9047 |
Result : Node_Id; |
| 9048 |
|
| 9049 |
begin |
| 9050 |
if Is_Enumeration_Type (Typ) then |
| 9051 |
Result := Get_Enum_Lit_From_Pos (Typ, V, Loc); |
| 9052 |
else |
| 9053 |
Result := Make_Integer_Literal (Loc, V); |
| 9054 |
end if; |
| 9055 |
|
| 9056 |
Set_Etype (Result, Btyp); |
| 9057 |
Set_Is_Static_Expression (Result); |
| 9058 |
Set_Analyzed (Result); |
| 9059 |
return Result; |
| 9060 |
end Build_Val; |
| 9061 |
|
| 9062 |
--------------- |
| 9063 |
-- Get_RList -- |
| 9064 |
--------------- |
| 9065 |
|
| 9066 |
function Get_RList |
| 9067 |
(Exp : Node_Id; |
| 9068 |
Static : access Boolean) return RList |
| 9069 |
is |
| 9070 |
Op : Node_Kind; |
| 9071 |
Val : Uint; |
| 9072 |
Val_Bearer : Node_Id; |
| 9073 |
|
| 9074 |
begin |
| 9075 |
-- Static expression can only be true or false |
| 9076 |
|
| 9077 |
if Is_OK_Static_Expression (Exp) then |
| 9078 |
if Expr_Value (Exp) = 0 then |
| 9079 |
return False_Range; |
| 9080 |
else |
| 9081 |
return True_Range; |
| 9082 |
end if; |
| 9083 |
end if; |
| 9084 |
|
| 9085 |
-- Otherwise test node type |
| 9086 |
|
| 9087 |
Op := Nkind (Exp); |
| 9088 |
|
| 9089 |
case Op is |
| 9090 |
|
| 9091 |
-- And |
| 9092 |
|
| 9093 |
when N_And_Then |
| 9094 |
| N_Op_And |
| 9095 |
=> |
| 9096 |
return Get_RList (Left_Opnd (Exp), Static) |
| 9097 |
and |
| 9098 |
Get_RList (Right_Opnd (Exp), Static); |
| 9099 |
|
| 9100 |
-- Or |
| 9101 |
|
| 9102 |
when N_Op_Or |
| 9103 |
| N_Or_Else |
| 9104 |
=> |
| 9105 |
return Get_RList (Left_Opnd (Exp), Static) |
| 9106 |
or |
| 9107 |
Get_RList (Right_Opnd (Exp), Static); |
| 9108 |
|
| 9109 |
-- Not |
| 9110 |
|
| 9111 |
when N_Op_Not => |
| 9112 |
return not Get_RList (Right_Opnd (Exp), Static); |
| 9113 |
|
| 9114 |
-- Comparisons of type with static value |
| 9115 |
|
| 9116 |
when N_Op_Compare => |
| 9117 |
|
| 9118 |
-- Type is left operand |
| 9119 |
|
| 9120 |
if Is_Type_Ref (Left_Opnd (Exp)) |
| 9121 |
and then Is_OK_Static_Expression (Right_Opnd (Exp)) |
| 9122 |
then |
| 9123 |
Val_Bearer := Right_Opnd (Exp); |
| 9124 |
|
| 9125 |
-- Typ is right operand |
| 9126 |
|
| 9127 |
elsif Is_Type_Ref (Right_Opnd (Exp)) |
| 9128 |
and then Is_OK_Static_Expression (Left_Opnd (Exp)) |
| 9129 |
then |
| 9130 |
Val_Bearer := Left_Opnd (Exp); |
| 9131 |
|
| 9132 |
-- Invert sense of comparison |
| 9133 |
|
| 9134 |
case Op is |
| 9135 |
when N_Op_Gt => Op := N_Op_Lt; |
| 9136 |
when N_Op_Lt => Op := N_Op_Gt; |
| 9137 |
when N_Op_Ge => Op := N_Op_Le; |
| 9138 |
when N_Op_Le => Op := N_Op_Ge; |
| 9139 |
when others => null; |
| 9140 |
end case; |
| 9141 |
|
| 9142 |
-- Other cases are non-static |
| 9143 |
|
| 9144 |
else |
| 9145 |
Static.all := False; |
| 9146 |
return False_Range; |
| 9147 |
end if; |
| 9148 |
|
| 9149 |
Val := Expr_Value (Val_Bearer); |
| 9150 |
|
| 9151 |
-- Construct range according to comparison operation |
| 9152 |
|
| 9153 |
declare |
| 9154 |
REntry : REnt; |
| 9155 |
begin |
| 9156 |
case Op is |
| 9157 |
when N_Op_Eq => |
| 9158 |
REntry := (Val, Val); |
| 9159 |
|
| 9160 |
when N_Op_Ge => |
| 9161 |
REntry := (Val, THi); |
| 9162 |
|
| 9163 |
when N_Op_Gt => |
| 9164 |
REntry := (Val + 1, THi); |
| 9165 |
|
| 9166 |
when N_Op_Le => |
| 9167 |
REntry := (TLo, Val); |
| 9168 |
|
| 9169 |
when N_Op_Lt => |
| 9170 |
REntry := (TLo, Val - 1); |
| 9171 |
|
| 9172 |
when N_Op_Ne => |
| 9173 |
Warn_If_Test_Ineffective ((Val, Val), Val_Bearer); |
| 9174 |
return RList'(REnt'(TLo, Val - 1), |
| 9175 |
REnt'(Val + 1, THi)); |
| 9176 |
|
| 9177 |
when others => |
| 9178 |
raise Program_Error; |
| 9179 |
end case; |
| 9180 |
|
| 9181 |
Warn_If_Test_Ineffective (REntry, Val_Bearer); |
| 9182 |
return RList'(1 => REntry); |
| 9183 |
end; |
| 9184 |
|
| 9185 |
-- Membership (IN) |
| 9186 |
|
| 9187 |
when N_In => |
| 9188 |
if not Is_Type_Ref (Left_Opnd (Exp)) then |
| 9189 |
Static.all := False; |
| 9190 |
return False_Range; |
| 9191 |
end if; |
| 9192 |
|
| 9193 |
if Present (Right_Opnd (Exp)) then |
| 9194 |
return Membership_Entry (Right_Opnd (Exp), Static); |
| 9195 |
else |
| 9196 |
return Membership_Entries |
| 9197 |
(First (Alternatives (Exp)), Static); |
| 9198 |
end if; |
| 9199 |
|
| 9200 |
-- Negative membership (NOT IN) |
| 9201 |
|
| 9202 |
when N_Not_In => |
| 9203 |
if not Is_Type_Ref (Left_Opnd (Exp)) then |
| 9204 |
Static.all := False; |
| 9205 |
return False_Range; |
| 9206 |
end if; |
| 9207 |
|
| 9208 |
if Present (Right_Opnd (Exp)) then |
| 9209 |
return not Membership_Entry (Right_Opnd (Exp), Static); |
| 9210 |
else |
| 9211 |
return not Membership_Entries |
| 9212 |
(First (Alternatives (Exp)), Static); |
| 9213 |
end if; |
| 9214 |
|
| 9215 |
-- Function call, may be call to static predicate |
| 9216 |
|
| 9217 |
when N_Function_Call => |
| 9218 |
if Is_Entity_Name (Name (Exp)) then |
| 9219 |
declare |
| 9220 |
Ent : constant Entity_Id := Entity (Name (Exp)); |
| 9221 |
begin |
| 9222 |
if Is_Predicate_Function (Ent) then |
| 9223 |
return Stat_Pred (Etype (First_Formal (Ent)), Static); |
| 9224 |
end if; |
| 9225 |
end; |
| 9226 |
end if; |
| 9227 |
|
| 9228 |
-- Other function call cases are non-static |
| 9229 |
|
| 9230 |
Static.all := False; |
| 9231 |
return False_Range; |
| 9232 |
|
| 9233 |
-- Qualified expression, dig out the expression |
| 9234 |
|
| 9235 |
when N_Qualified_Expression => |
| 9236 |
return Get_RList (Expression (Exp), Static); |
| 9237 |
|
| 9238 |
when N_Case_Expression => |
| 9239 |
declare |
| 9240 |
Alt : Node_Id; |
| 9241 |
Choices : List_Id; |
| 9242 |
Dep : Node_Id; |
| 9243 |
|
| 9244 |
begin |
| 9245 |
if not Is_Entity_Name (Expression (Expr)) |
| 9246 |
or else Etype (Expression (Expr)) /= Typ |
| 9247 |
then |
| 9248 |
Error_Msg_N |
| 9249 |
("expression must denote subtype", Expression (Expr)); |
| 9250 |
return False_Range; |
| 9251 |
end if; |
| 9252 |
|
| 9253 |
-- Collect discrete choices in all True alternatives |
| 9254 |
|
| 9255 |
Choices := New_List; |
| 9256 |
Alt := First (Alternatives (Exp)); |
| 9257 |
while Present (Alt) loop |
| 9258 |
Dep := Expression (Alt); |
| 9259 |
|
| 9260 |
if not Is_OK_Static_Expression (Dep) then |
| 9261 |
Static.all := False; |
| 9262 |
return False_Range; |
| 9263 |
|
| 9264 |
elsif Is_True (Expr_Value (Dep)) then |
| 9265 |
Append_List_To (Choices, |
| 9266 |
New_Copy_List (Discrete_Choices (Alt))); |
| 9267 |
end if; |
| 9268 |
|
| 9269 |
Next (Alt); |
| 9270 |
end loop; |
| 9271 |
|
| 9272 |
return Membership_Entries (First (Choices), Static); |
| 9273 |
end; |
| 9274 |
|
| 9275 |
-- Expression with actions: if no actions, dig out expression |
| 9276 |
|
| 9277 |
when N_Expression_With_Actions => |
| 9278 |
if Is_Empty_List (Actions (Exp)) then |
| 9279 |
return Get_RList (Expression (Exp), Static); |
| 9280 |
else |
| 9281 |
Static.all := False; |
| 9282 |
return False_Range; |
| 9283 |
end if; |
| 9284 |
|
| 9285 |
-- Xor operator |
| 9286 |
|
| 9287 |
when N_Op_Xor => |
| 9288 |
return (Get_RList (Left_Opnd (Exp), Static) |
| 9289 |
and not Get_RList (Right_Opnd (Exp), Static)) |
| 9290 |
or (Get_RList (Right_Opnd (Exp), Static) |
| 9291 |
and not Get_RList (Left_Opnd (Exp), Static)); |
| 9292 |
|
| 9293 |
-- Any other node type is non-static |
| 9294 |
|
| 9295 |
when others => |
| 9296 |
Static.all := False; |
| 9297 |
return False_Range; |
| 9298 |
end case; |
| 9299 |
end Get_RList; |
| 9300 |
|
| 9301 |
------------ |
| 9302 |
-- Hi_Val -- |
| 9303 |
------------ |
| 9304 |
|
| 9305 |
function Hi_Val (N : Node_Id) return Uint is |
| 9306 |
begin |
| 9307 |
if Is_OK_Static_Expression (N) then |
| 9308 |
return Expr_Value (N); |
| 9309 |
else |
| 9310 |
pragma Assert (Nkind (N) = N_Range); |
| 9311 |
return Expr_Value (High_Bound (N)); |
| 9312 |
end if; |
| 9313 |
end Hi_Val; |
| 9314 |
|
| 9315 |
-------------- |
| 9316 |
-- Is_False -- |
| 9317 |
-------------- |
| 9318 |
|
| 9319 |
function Is_False (R : RList) return Boolean is |
| 9320 |
begin |
| 9321 |
return R'Length = 0; |
| 9322 |
end Is_False; |
| 9323 |
|
| 9324 |
------------- |
| 9325 |
-- Is_True -- |
| 9326 |
------------- |
| 9327 |
|
| 9328 |
function Is_True (R : RList) return Boolean is |
| 9329 |
begin |
| 9330 |
return R'Length = 1 |
| 9331 |
and then R (R'First).Lo = BLo |
| 9332 |
and then R (R'First).Hi = BHi; |
| 9333 |
end Is_True; |
| 9334 |
|
| 9335 |
----------------- |
| 9336 |
-- Is_Type_Ref -- |
| 9337 |
----------------- |
| 9338 |
|
| 9339 |
function Is_Type_Ref (N : Node_Id) return Boolean is |
| 9340 |
begin |
| 9341 |
return Nkind (N) = N_Identifier |
| 9342 |
and then Chars (N) = Nam |
| 9343 |
and then Paren_Count (N) = 0; |
| 9344 |
end Is_Type_Ref; |
| 9345 |
|
| 9346 |
------------ |
| 9347 |
-- Lo_Val -- |
| 9348 |
------------ |
| 9349 |
|
| 9350 |
function Lo_Val (N : Node_Id) return Uint is |
| 9351 |
begin |
| 9352 |
if Is_OK_Static_Expression (N) then |
| 9353 |
return Expr_Value (N); |
| 9354 |
else |
| 9355 |
pragma Assert (Nkind (N) = N_Range); |
| 9356 |
return Expr_Value (Low_Bound (N)); |
| 9357 |
end if; |
| 9358 |
end Lo_Val; |
| 9359 |
|
| 9360 |
------------------------ |
| 9361 |
-- Membership_Entries -- |
| 9362 |
------------------------ |
| 9363 |
|
| 9364 |
function Membership_Entries |
| 9365 |
(N : Node_Id; Static : access Boolean) return RList is |
| 9366 |
begin |
| 9367 |
if No (Next (N)) then |
| 9368 |
return Membership_Entry (N, Static); |
| 9369 |
else |
| 9370 |
return Membership_Entry (N, Static) |
| 9371 |
or Membership_Entries (Next (N), Static); |
| 9372 |
end if; |
| 9373 |
end Membership_Entries; |
| 9374 |
|
| 9375 |
---------------------- |
| 9376 |
-- Membership_Entry -- |
| 9377 |
---------------------- |
| 9378 |
|
| 9379 |
function Membership_Entry |
| 9380 |
(N : Node_Id; Static : access Boolean) return RList |
| 9381 |
is |
| 9382 |
Val : Uint; |
| 9383 |
SLo : Uint; |
| 9384 |
SHi : Uint; |
| 9385 |
|
| 9386 |
begin |
| 9387 |
-- Range case |
| 9388 |
|
| 9389 |
if Nkind (N) = N_Range then |
| 9390 |
if not Is_OK_Static_Expression (Low_Bound (N)) |
| 9391 |
or else |
| 9392 |
not Is_OK_Static_Expression (High_Bound (N)) |
| 9393 |
then |
| 9394 |
Static.all := False; |
| 9395 |
return False_Range; |
| 9396 |
else |
| 9397 |
SLo := Expr_Value (Low_Bound (N)); |
| 9398 |
SHi := Expr_Value (High_Bound (N)); |
| 9399 |
declare |
| 9400 |
REntry : constant REnt := (SLo, SHi); |
| 9401 |
begin |
| 9402 |
Warn_If_Test_Ineffective (REntry, N); |
| 9403 |
return RList'(1 => REntry); |
| 9404 |
end; |
| 9405 |
end if; |
| 9406 |
|
| 9407 |
-- Others case |
| 9408 |
|
| 9409 |
elsif Nkind (N) = N_Others_Choice then |
| 9410 |
declare |
| 9411 |
Choices : constant List_Id := Others_Discrete_Choices (N); |
| 9412 |
Choice : Node_Id; |
| 9413 |
Range_List : RList (1 .. List_Length (Choices)); |
| 9414 |
|
| 9415 |
begin |
| 9416 |
Choice := First (Choices); |
| 9417 |
|
| 9418 |
for J in Range_List'Range loop |
| 9419 |
Range_List (J) := REnt'(Lo_Val (Choice), Hi_Val (Choice)); |
| 9420 |
Next (Choice); |
| 9421 |
end loop; |
| 9422 |
|
| 9423 |
return Range_List; |
| 9424 |
end; |
| 9425 |
|
| 9426 |
-- Static expression case |
| 9427 |
|
| 9428 |
elsif Is_OK_Static_Expression (N) then |
| 9429 |
Val := Expr_Value (N); |
| 9430 |
declare |
| 9431 |
REntry : constant REnt := (Val, Val); |
| 9432 |
begin |
| 9433 |
Warn_If_Test_Ineffective (REntry, N); |
| 9434 |
return RList'(1 => REntry); |
| 9435 |
end; |
| 9436 |
|
| 9437 |
-- Identifier (other than static expression) case |
| 9438 |
|
| 9439 |
else pragma Assert (Nkind (N) in N_Expanded_Name | N_Identifier); |
| 9440 |
|
| 9441 |
-- Type case |
| 9442 |
|
| 9443 |
if Is_Type (Entity (N)) then |
| 9444 |
|
| 9445 |
-- If type has predicates, process them |
| 9446 |
|
| 9447 |
if Has_Predicates (Entity (N)) then |
| 9448 |
return Stat_Pred (Entity (N), Static); |
| 9449 |
|
| 9450 |
-- For static subtype without predicates, get range |
| 9451 |
|
| 9452 |
elsif Is_OK_Static_Subtype (Entity (N)) then |
| 9453 |
SLo := Expr_Value (Type_Low_Bound (Entity (N))); |
| 9454 |
SHi := Expr_Value (Type_High_Bound (Entity (N))); |
| 9455 |
return RList'(1 => REnt'(SLo, SHi)); |
| 9456 |
|
| 9457 |
-- Any other type makes us non-static |
| 9458 |
|
| 9459 |
else |
| 9460 |
Static.all := False; |
| 9461 |
return False_Range; |
| 9462 |
end if; |
| 9463 |
|
| 9464 |
-- Any other kind of identifier in predicate (e.g. a non-static |
| 9465 |
-- expression value) means this is not a static predicate. |
| 9466 |
|
| 9467 |
else |
| 9468 |
Static.all := False; |
| 9469 |
return False_Range; |
| 9470 |
end if; |
| 9471 |
end if; |
| 9472 |
end Membership_Entry; |
| 9473 |
|
| 9474 |
--------------- |
| 9475 |
-- Stat_Pred -- |
| 9476 |
--------------- |
| 9477 |
|
| 9478 |
function Stat_Pred |
| 9479 |
(Typ : Entity_Id; |
| 9480 |
Static : access Boolean) return RList is |
| 9481 |
begin |
| 9482 |
-- Not static if type does not have static predicates |
| 9483 |
|
| 9484 |
if not Has_Static_Predicate (Typ) then |
| 9485 |
Static.all := False; |
| 9486 |
return False_Range; |
| 9487 |
end if; |
| 9488 |
|
| 9489 |
-- Otherwise we convert the predicate list to a range list |
| 9490 |
|
| 9491 |
declare |
| 9492 |
Spred : constant List_Id := Static_Discrete_Predicate (Typ); |
| 9493 |
Result : RList (1 .. List_Length (Spred)); |
| 9494 |
P : Node_Id; |
| 9495 |
|
| 9496 |
begin |
| 9497 |
P := First (Static_Discrete_Predicate (Typ)); |
| 9498 |
for J in Result'Range loop |
| 9499 |
Result (J) := REnt'(Lo_Val (P), Hi_Val (P)); |
| 9500 |
Next (P); |
| 9501 |
end loop; |
| 9502 |
|
| 9503 |
return Result; |
| 9504 |
end; |
| 9505 |
end Stat_Pred; |
| 9506 |
|
| 9507 |
procedure Warn_If_Test_Ineffective (REntry : REnt; N : Node_Id) is |
| 9508 |
|
| 9509 |
procedure IPT_Warning (Msg : String); |
| 9510 |
-- Emit warning |
| 9511 |
|
| 9512 |
----------------- |
| 9513 |
-- IPT_Warning -- |
| 9514 |
----------------- |
| 9515 |
procedure IPT_Warning (Msg : String) is |
| 9516 |
begin |
| 9517 |
Error_Msg_N ("ineffective predicate test " & Msg & "?_s?", N); |
| 9518 |
end IPT_Warning; |
| 9519 |
|
| 9520 |
-- Start of processing for Warn_If_Test_Ineffective |
| 9521 |
|
| 9522 |
begin |
| 9523 |
-- Do nothing if warning disabled |
| 9524 |
|
| 9525 |
if not Warn_On_Ineffective_Predicate_Test then |
| 9526 |
null; |
| 9527 |
|
| 9528 |
-- skip null-range corner cases |
| 9529 |
|
| 9530 |
elsif REntry.Lo > REntry.Hi or else TLo > THi then |
| 9531 |
null; |
| 9532 |
|
| 9533 |
-- warn if no overlap between subtype bounds and the given range |
| 9534 |
|
| 9535 |
elsif REntry.Lo > THi or else REntry.Hi < TLo then |
| 9536 |
Error_Msg_Uint_1 := REntry.Lo; |
| 9537 |
if REntry.Lo /= REntry.Hi then |
| 9538 |
Error_Msg_Uint_2 := REntry.Hi; |
| 9539 |
IPT_Warning ("range: ^ .. ^"); |
| 9540 |
elsif Is_Enumeration_Type (Typ) and then |
| 9541 |
Nkind (N) in N_Identifier | N_Expanded_Name |
| 9542 |
then |
| 9543 |
IPT_Warning ("value: &"); |
| 9544 |
else |
| 9545 |
IPT_Warning ("value: ^"); |
| 9546 |
end if; |
| 9547 |
end if; |
| 9548 |
end Warn_If_Test_Ineffective; |
| 9549 |
|
| 9550 |
-- Start of processing for Build_Discrete_Static_Predicate |
| 9551 |
|
| 9552 |
begin |
| 9553 |
-- Establish bounds for the predicate |
| 9554 |
|
| 9555 |
if Compile_Time_Known_Value (Type_Low_Bound (Typ)) then |
| 9556 |
TLo := Expr_Value (Type_Low_Bound (Typ)); |
| 9557 |
else |
| 9558 |
TLo := BLo; |
| 9559 |
end if; |
| 9560 |
|
| 9561 |
if Compile_Time_Known_Value (Type_High_Bound (Typ)) then |
| 9562 |
THi := Expr_Value (Type_High_Bound (Typ)); |
| 9563 |
else |
| 9564 |
THi := BHi; |
| 9565 |
end if; |
| 9566 |
|
| 9567 |
-- Analyze the expression to see if it is a static predicate |
| 9568 |
|
| 9569 |
declare |
| 9570 |
Static : aliased Boolean := True; |
| 9571 |
Ranges : constant RList := Get_RList (Expr, Static'Access); |
| 9572 |
-- Range list from expression if it is static |
| 9573 |
|
| 9574 |
Plist : List_Id; |
| 9575 |
|
| 9576 |
begin |
| 9577 |
-- If non-static, return doing nothing |
| 9578 |
|
| 9579 |
if not Static then |
| 9580 |
return; |
| 9581 |
end if; |
| 9582 |
|
| 9583 |
-- Convert range list into a form for the static predicate. In the |
| 9584 |
-- Ranges array, we just have raw ranges, these must be converted |
| 9585 |
-- to properly typed and analyzed static expressions or range nodes. |
| 9586 |
|
| 9587 |
-- Note: here we limit ranges to the ranges of the subtype, so that |
| 9588 |
-- a predicate is always false for values outside the subtype. That |
| 9589 |
-- seems fine, such values are invalid anyway, and considering them |
| 9590 |
-- to fail the predicate seems allowed and friendly, and furthermore |
| 9591 |
-- simplifies processing for case statements and loops. |
| 9592 |
|
| 9593 |
Plist := New_List; |
| 9594 |
|
| 9595 |
for J in Ranges'Range loop |
| 9596 |
declare |
| 9597 |
Lo : Uint := Ranges (J).Lo; |
| 9598 |
Hi : Uint := Ranges (J).Hi; |
| 9599 |
|
| 9600 |
begin |
| 9601 |
-- Ignore completely out of range entry |
| 9602 |
|
| 9603 |
if Hi < TLo or else Lo > THi then |
| 9604 |
null; |
| 9605 |
|
| 9606 |
-- Otherwise process entry |
| 9607 |
|
| 9608 |
else |
| 9609 |
-- Adjust out of range value to subtype range |
| 9610 |
|
| 9611 |
if Lo < TLo then |
| 9612 |
Lo := TLo; |
| 9613 |
end if; |
| 9614 |
|
| 9615 |
if Hi > THi then |
| 9616 |
Hi := THi; |
| 9617 |
end if; |
| 9618 |
|
| 9619 |
-- Convert range into required form |
| 9620 |
|
| 9621 |
Append_To (Plist, Build_Range (Lo, Hi)); |
| 9622 |
end if; |
| 9623 |
end; |
| 9624 |
end loop; |
| 9625 |
|
| 9626 |
-- Processing was successful and all entries were static, so now we |
| 9627 |
-- can store the result as the predicate list. |
| 9628 |
|
| 9629 |
Set_Static_Discrete_Predicate (Typ, Plist); |
| 9630 |
|
| 9631 |
-- Within a generic the predicate functions themselves need not |
| 9632 |
-- be constructed. |
| 9633 |
|
| 9634 |
if Inside_A_Generic then |
| 9635 |
return; |
| 9636 |
end if; |
| 9637 |
|
| 9638 |
-- The processing for static predicates put the expression into |
| 9639 |
-- canonical form as a series of ranges. It also eliminated |
| 9640 |
-- duplicates and collapsed and combined ranges. We might as well |
| 9641 |
-- replace the alternatives list of the right operand of the |
| 9642 |
-- membership test with the static predicate list, which will |
| 9643 |
-- usually be more efficient. |
| 9644 |
|
| 9645 |
declare |
| 9646 |
New_Alts : constant List_Id := New_List; |
| 9647 |
Old_Node : Node_Id; |
| 9648 |
New_Node : Node_Id; |
| 9649 |
|
| 9650 |
begin |
| 9651 |
Old_Node := First (Plist); |
| 9652 |
while Present (Old_Node) loop |
| 9653 |
New_Node := New_Copy (Old_Node); |
| 9654 |
|
| 9655 |
if Nkind (New_Node) = N_Range then |
| 9656 |
Set_Low_Bound (New_Node, New_Copy (Low_Bound (Old_Node))); |
| 9657 |
Set_High_Bound (New_Node, New_Copy (High_Bound (Old_Node))); |
| 9658 |
end if; |
| 9659 |
|
| 9660 |
Append_To (New_Alts, New_Node); |
| 9661 |
Next (Old_Node); |
| 9662 |
end loop; |
| 9663 |
|
| 9664 |
-- If empty list, replace by False |
| 9665 |
|
| 9666 |
if Is_Empty_List (New_Alts) then |
| 9667 |
Rewrite (Expr, New_Occurrence_Of (Standard_False, Loc)); |
| 9668 |
|
| 9669 |
-- Else replace by set membership test |
| 9670 |
|
| 9671 |
else |
| 9672 |
Rewrite (Expr, |
| 9673 |
Make_In (Loc, |
| 9674 |
Left_Opnd => Make_Identifier (Loc, Nam), |
| 9675 |
Right_Opnd => Empty, |
| 9676 |
Alternatives => New_Alts)); |
| 9677 |
|
| 9678 |
-- Resolve new expression in function context |
| 9679 |
|
| 9680 |
Push_Scope (Predicate_Function (Typ)); |
| 9681 |
Install_Formals (Predicate_Function (Typ)); |
| 9682 |
Analyze_And_Resolve (Expr, Standard_Boolean); |
| 9683 |
End_Scope; |
| 9684 |
end if; |
| 9685 |
end; |
| 9686 |
end; |
| 9687 |
end Build_Discrete_Static_Predicate; |
| 9688 |
|
| 9689 |
-------------------------------- |
| 9690 |
-- Build_Export_Import_Pragma -- |
| 9691 |
-------------------------------- |
| 9692 |
|
| 9693 |
function Build_Export_Import_Pragma |
| 9694 |
(Asp : Node_Id; |
| 9695 |
Id : Entity_Id) return Node_Id |
| 9696 |
is |
| 9697 |
Asp_Id : constant Aspect_Id := Get_Aspect_Id (Asp); |
| 9698 |
Expr : constant Node_Id := Expression (Asp); |
| 9699 |
Loc : constant Source_Ptr := Sloc (Asp); |
| 9700 |
|
| 9701 |
Args : List_Id; |
| 9702 |
Conv : Node_Id; |
| 9703 |
Conv_Arg : Node_Id; |
| 9704 |
Dummy_1 : Node_Id; |
| 9705 |
Dummy_2 : Node_Id; |
| 9706 |
EN : Node_Id; |
| 9707 |
LN : Node_Id; |
| 9708 |
Prag : Node_Id; |
| 9709 |
|
| 9710 |
Create_Pragma : Boolean := False; |
| 9711 |
-- This flag is set when the aspect form is such that it warrants the |
| 9712 |
-- creation of a corresponding pragma. |
| 9713 |
|
| 9714 |
begin |
| 9715 |
if Present (Expr) then |
| 9716 |
if Error_Posted (Expr) then |
| 9717 |
null; |
| 9718 |
|
| 9719 |
elsif Is_True (Expr_Value (Expr)) then |
| 9720 |
Create_Pragma := True; |
| 9721 |
end if; |
| 9722 |
|
| 9723 |
-- Otherwise the aspect defaults to True |
| 9724 |
|
| 9725 |
else |
| 9726 |
Create_Pragma := True; |
| 9727 |
end if; |
| 9728 |
|
| 9729 |
-- Nothing to do when the expression is False or is erroneous |
| 9730 |
|
| 9731 |
if not Create_Pragma then |
| 9732 |
return Empty; |
| 9733 |
end if; |
| 9734 |
|
| 9735 |
-- Obtain all interfacing aspects that apply to the related entity |
| 9736 |
|
| 9737 |
Get_Interfacing_Aspects |
| 9738 |
(Iface_Asp => Asp, |
| 9739 |
Conv_Asp => Conv, |
| 9740 |
EN_Asp => EN, |
| 9741 |
Expo_Asp => Dummy_1, |
| 9742 |
Imp_Asp => Dummy_2, |
| 9743 |
LN_Asp => LN); |
| 9744 |
|
| 9745 |
Args := New_List; |
| 9746 |
|
| 9747 |
-- Handle the convention argument |
| 9748 |
|
| 9749 |
if Present (Conv) then |
| 9750 |
Conv_Arg := New_Copy_Tree (Expression (Conv)); |
| 9751 |
|
| 9752 |
-- Assume convention "Ada' when aspect Convention is missing |
| 9753 |
|
| 9754 |
else |
| 9755 |
Conv_Arg := Make_Identifier (Loc, Name_Ada); |
| 9756 |
end if; |
| 9757 |
|
| 9758 |
Append_To (Args, |
| 9759 |
Make_Pragma_Argument_Association (Loc, |
| 9760 |
Chars => Name_Convention, |
| 9761 |
Expression => Conv_Arg)); |
| 9762 |
|
| 9763 |
-- Handle the entity argument |
| 9764 |
|
| 9765 |
Append_To (Args, |
| 9766 |
Make_Pragma_Argument_Association (Loc, |
| 9767 |
Chars => Name_Entity, |
| 9768 |
Expression => New_Occurrence_Of (Id, Loc))); |
| 9769 |
|
| 9770 |
-- Handle the External_Name argument |
| 9771 |
|
| 9772 |
if Present (EN) then |
| 9773 |
Append_To (Args, |
| 9774 |
Make_Pragma_Argument_Association (Loc, |
| 9775 |
Chars => Name_External_Name, |
| 9776 |
Expression => New_Copy_Tree (Expression (EN)))); |
| 9777 |
end if; |
| 9778 |
|
| 9779 |
-- Handle the Link_Name argument |
| 9780 |
|
| 9781 |
if Present (LN) then |
| 9782 |
Append_To (Args, |
| 9783 |
Make_Pragma_Argument_Association (Loc, |
| 9784 |
Chars => Name_Link_Name, |
| 9785 |
Expression => New_Copy_Tree (Expression (LN)))); |
| 9786 |
end if; |
| 9787 |
|
| 9788 |
-- Generate: |
| 9789 |
-- pragma Export/Import |
| 9790 |
-- (Convention => <Conv>/Ada, |
| 9791 |
-- Entity => <Id>, |
| 9792 |
-- [External_Name => <EN>,] |
| 9793 |
-- [Link_Name => <LN>]); |
| 9794 |
|
| 9795 |
Prag := |
| 9796 |
Make_Pragma (Loc, |
| 9797 |
Pragma_Identifier => |
| 9798 |
Make_Identifier (Loc, Chars (Identifier (Asp))), |
| 9799 |
Pragma_Argument_Associations => Args); |
| 9800 |
|
| 9801 |
-- Decorate the relevant aspect and the pragma |
| 9802 |
|
| 9803 |
Set_Aspect_Rep_Item (Asp, Prag); |
| 9804 |
|
| 9805 |
Set_Corresponding_Aspect (Prag, Asp); |
| 9806 |
Set_From_Aspect_Specification (Prag); |
| 9807 |
Set_Parent (Prag, Asp); |
| 9808 |
|
| 9809 |
if Asp_Id = Aspect_Import and then Is_Subprogram (Id) then |
| 9810 |
Set_Import_Pragma (Id, Prag); |
| 9811 |
end if; |
| 9812 |
|
| 9813 |
return Prag; |
| 9814 |
end Build_Export_Import_Pragma; |
| 9815 |
|
| 9816 |
------------------------------ |
| 9817 |
-- Build_Predicate_Function -- |
| 9818 |
------------------------------ |
| 9819 |
|
| 9820 |
-- The function constructed here has the form: |
| 9821 |
|
| 9822 |
-- function typPredicate (Ixxx : typ) return Boolean is |
| 9823 |
-- begin |
| 9824 |
-- return |
| 9825 |
-- typ1Predicate (typ1 (Ixxx)) |
| 9826 |
-- and then typ2Predicate (typ2 (Ixxx)) |
| 9827 |
-- and then ... |
| 9828 |
-- and then exp1 and then exp2 and then ...; |
| 9829 |
-- end typPredicate; |
| 9830 |
|
| 9831 |
-- If Predicate_Function_Needs_Membership_Parameter is true, then this |
| 9832 |
-- function takes an additional boolean parameter; the parameter |
| 9833 |
-- indicates whether the predicate evaluation is part of a membership |
| 9834 |
-- test. This parameter is used in two cases: 1) It is passed along |
| 9835 |
-- if another predicate function is called and that predicate function |
| 9836 |
-- expects to be passed a boolean parameter. 2) If the Predicate_Failure |
| 9837 |
-- aspect is directly specified for typ, then we replace the return |
| 9838 |
-- expression described above with |
| 9839 |
-- (if <expression described above> then True |
| 9840 |
-- elsif For_Membership_Test then False |
| 9841 |
-- else (raise Assertion_Error |
| 9842 |
-- with <Predicate_Failure expression>)) |
| 9843 |
-- Here exp1, and exp2 are expressions from Predicate pragmas. Note that |
| 9844 |
-- this is the point at which these expressions get analyzed, providing the |
| 9845 |
-- required delay, and typ1, typ2, are entities from which predicates are |
| 9846 |
-- inherited. Note that we do NOT generate Check pragmas, that's because we |
| 9847 |
-- use this function even if checks are off, e.g. for membership tests. |
| 9848 |
|
| 9849 |
-- Note that the inherited predicates are evaluated first, as required by |
| 9850 |
-- AI12-0071-1. |
| 9851 |
|
| 9852 |
-- Note that Sem_Eval.Real_Or_String_Static_Predicate_Matches depends on |
| 9853 |
-- the form of this return expression. |
| 9854 |
|
| 9855 |
-- WARNING: This routine manages Ghost regions. Return statements must be |
| 9856 |
-- replaced by gotos which jump to the end of the routine and restore the |
| 9857 |
-- Ghost mode. |
| 9858 |
|
| 9859 |
procedure Build_Predicate_Function (Typ : Entity_Id; N : Node_Id) is |
| 9860 |
Loc : constant Source_Ptr := Sloc (Typ); |
| 9861 |
|
| 9862 |
Saved_GM : constant Ghost_Mode_Type := Ghost_Mode; |
| 9863 |
Saved_IGR : constant Node_Id := Ignored_Ghost_Region; |
| 9864 |
-- Save the Ghost-related attributes to restore on exit |
| 9865 |
|
| 9866 |
Expr : Node_Id; |
| 9867 |
-- This is the expression for the result of the function. It is |
| 9868 |
-- built by connecting the component predicates with AND THEN. |
| 9869 |
|
| 9870 |
Object_Name : Name_Id; |
| 9871 |
-- Name for argument of Predicate procedure. Note that we use the same |
| 9872 |
-- name for both predicate functions. That way the reference within the |
| 9873 |
-- predicate expression is the same in both functions. |
| 9874 |
|
| 9875 |
Object_Entity : Entity_Id; |
| 9876 |
-- Entity for argument of Predicate procedure |
| 9877 |
|
| 9878 |
FDecl : Node_Id; |
| 9879 |
-- The function declaration |
| 9880 |
|
| 9881 |
SId : Entity_Id; |
| 9882 |
-- Its entity |
| 9883 |
|
| 9884 |
Restore_Scope : Boolean; |
| 9885 |
-- True if the current scope must be restored on exit |
| 9886 |
|
| 9887 |
Ancestor_Predicate_Function_Called : Boolean := False; |
| 9888 |
-- Does this predicate function include a call to the |
| 9889 |
-- predication function of an ancestor subtype? |
| 9890 |
|
| 9891 |
procedure Add_Condition (Cond : Node_Id); |
| 9892 |
-- Append Cond to Expr using "and then" (or just copy Cond to Expr if |
| 9893 |
-- Expr is empty). |
| 9894 |
|
| 9895 |
procedure Add_Predicates; |
| 9896 |
-- Appends expressions for any Predicate pragmas in the rep item chain |
| 9897 |
-- Typ to Expr. Note that we look only at items for this exact entity. |
| 9898 |
-- Inheritance of predicates for the parent type is done by calling the |
| 9899 |
-- Predicate_Function of the parent type, using Add_Call above. |
| 9900 |
|
| 9901 |
procedure Add_Call (T : Entity_Id); |
| 9902 |
-- Includes a call to the predicate function for type T in Expr if |
| 9903 |
-- Predicate_Function (T) is non-empty. |
| 9904 |
|
| 9905 |
procedure Replace_Current_Instance_References |
| 9906 |
(N : Node_Id; Typ, New_Entity : Entity_Id); |
| 9907 |
-- Replace all references to Typ in the tree rooted at N with |
| 9908 |
-- references to Param. [New_Entity will be a formal parameter of a |
| 9909 |
-- predicate function.] |
| 9910 |
|
| 9911 |
-------------- |
| 9912 |
-- Add_Call -- |
| 9913 |
-------------- |
| 9914 |
|
| 9915 |
procedure Add_Call (T : Entity_Id) is |
| 9916 |
Exp : Node_Id; |
| 9917 |
|
| 9918 |
begin |
| 9919 |
if Present (Predicate_Function (T)) then |
| 9920 |
pragma Assert (Has_Predicates (Typ)); |
| 9921 |
|
| 9922 |
-- Build the call to the predicate function of T. The type may be |
| 9923 |
-- derived, so use an unchecked conversion for the actual. |
| 9924 |
|
| 9925 |
declare |
| 9926 |
Dynamic_Mem : Node_Id := Empty; |
| 9927 |
Second_Formal : constant Entity_Id := |
| 9928 |
Next_Entity (Object_Entity); |
| 9929 |
begin |
| 9930 |
-- Some predicate functions require a second parameter; |
| 9931 |
-- If one predicate function calls another and the second |
| 9932 |
-- requires two parameters, then the first should also |
| 9933 |
-- take two parameters (so that the first function has |
| 9934 |
-- something to pass to the second function). |
| 9935 |
if Predicate_Function_Needs_Membership_Parameter (T) then |
| 9936 |
pragma Assert (Present (Second_Formal)); |
| 9937 |
Dynamic_Mem := New_Occurrence_Of (Second_Formal, Loc); |
| 9938 |
end if; |
| 9939 |
|
| 9940 |
Exp := |
| 9941 |
Make_Predicate_Call |
| 9942 |
(Typ => T, |
| 9943 |
Expr => |
| 9944 |
Unchecked_Convert_To (T, |
| 9945 |
Make_Identifier (Loc, Object_Name)), |
| 9946 |
Dynamic_Mem => Dynamic_Mem); |
| 9947 |
end; |
| 9948 |
|
| 9949 |
-- "and"-in the call to evolving expression |
| 9950 |
|
| 9951 |
Add_Condition (Exp); |
| 9952 |
Ancestor_Predicate_Function_Called := True; |
| 9953 |
|
| 9954 |
-- Output info message on inheritance if required. Note we do not |
| 9955 |
-- give this information for generic actual types, since it is |
| 9956 |
-- unwelcome noise in that case in instantiations. We also |
| 9957 |
-- generally suppress the message in instantiations, and also |
| 9958 |
-- if it involves internal names. |
| 9959 |
|
| 9960 |
if List_Inherited_Aspects |
| 9961 |
and then not Is_Generic_Actual_Type (Typ) |
| 9962 |
and then Instantiation_Location (Sloc (Typ)) = No_Location |
| 9963 |
and then not Is_Internal_Name (Chars (T)) |
| 9964 |
and then not Is_Internal_Name (Chars (Typ)) |
| 9965 |
then |
| 9966 |
Error_Msg_Sloc := Sloc (Predicate_Function (T)); |
| 9967 |
Error_Msg_Node_2 := T; |
| 9968 |
Error_Msg_N ("info: & inherits predicate from & #?.l?", Typ); |
| 9969 |
end if; |
| 9970 |
end if; |
| 9971 |
end Add_Call; |
| 9972 |
|
| 9973 |
------------------- |
| 9974 |
-- Add_Condition -- |
| 9975 |
------------------- |
| 9976 |
|
| 9977 |
procedure Add_Condition (Cond : Node_Id) is |
| 9978 |
begin |
| 9979 |
-- This is the first predicate expression |
| 9980 |
|
| 9981 |
if No (Expr) then |
| 9982 |
Expr := Cond; |
| 9983 |
|
| 9984 |
-- Otherwise concatenate to the existing predicate expressions by |
| 9985 |
-- using "and then". |
| 9986 |
|
| 9987 |
else |
| 9988 |
Expr := |
| 9989 |
Make_And_Then (Loc, |
| 9990 |
Left_Opnd => Relocate_Node (Expr), |
| 9991 |
Right_Opnd => Cond); |
| 9992 |
end if; |
| 9993 |
end Add_Condition; |
| 9994 |
|
| 9995 |
-------------------- |
| 9996 |
-- Add_Predicates -- |
| 9997 |
-------------------- |
| 9998 |
|
| 9999 |
procedure Add_Predicates is |
| 10000 |
procedure Add_Predicate (Prag : Node_Id); |
| 10001 |
-- Concatenate the expression of predicate pragma Prag to Expr by |
| 10002 |
-- using a short circuit "and then" operator. |
| 10003 |
|
| 10004 |
------------------- |
| 10005 |
-- Add_Predicate -- |
| 10006 |
------------------- |
| 10007 |
|
| 10008 |
procedure Add_Predicate (Prag : Node_Id) is |
| 10009 |
-- Local variables |
| 10010 |
|
| 10011 |
Asp : constant Node_Id := Corresponding_Aspect (Prag); |
| 10012 |
Arg1 : Node_Id; |
| 10013 |
Arg2 : Node_Id; |
| 10014 |
|
| 10015 |
-- Start of processing for Add_Predicate |
| 10016 |
|
| 10017 |
begin |
| 10018 |
-- A ghost predicate is checked only when Ghost mode is enabled. |
| 10019 |
-- Add a condition for the presence of a predicate to be recorded, |
| 10020 |
-- which is needed to generate the corresponding predicate |
| 10021 |
-- function. |
| 10022 |
|
| 10023 |
if Is_Ignored_Ghost_Pragma (Prag) then |
| 10024 |
Add_Condition (New_Occurrence_Of (Standard_True, Sloc (Prag))); |
| 10025 |
|
| 10026 |
else |
| 10027 |
-- Mark corresponding SCO as enabled |
| 10028 |
|
| 10029 |
Set_SCO_Pragma_Enabled (Sloc (Prag)); |
| 10030 |
end if; |
| 10031 |
|
| 10032 |
-- Extract the arguments of the pragma |
| 10033 |
|
| 10034 |
Arg1 := First (Pragma_Argument_Associations (Prag)); |
| 10035 |
Arg2 := Next (Arg1); |
| 10036 |
|
| 10037 |
Arg1 := Get_Pragma_Arg (Arg1); |
| 10038 |
Arg2 := Get_Pragma_Arg (Arg2); |
| 10039 |
|
| 10040 |
-- When the predicate pragma applies to the current type or its |
| 10041 |
-- full view, replace all occurrences of the subtype name with |
| 10042 |
-- references to the formal parameter of the predicate function. |
| 10043 |
|
| 10044 |
if Entity (Arg1) = Typ |
| 10045 |
or else Full_View (Entity (Arg1)) = Typ |
| 10046 |
then |
| 10047 |
declare |
| 10048 |
Arg2_Copy : constant Node_Id := New_Copy_Tree (Arg2); |
| 10049 |
begin |
| 10050 |
Replace_Current_Instance_References |
| 10051 |
(Arg2_Copy, Typ => Typ, New_Entity => Object_Entity); |
| 10052 |
|
| 10053 |
-- If the predicate pragma comes from an aspect, replace the |
| 10054 |
-- saved expression because we need the subtype references |
| 10055 |
-- replaced for the calls to Preanalyze_Spec_Expression in |
| 10056 |
-- Check_Aspect_At_xxx routines. |
| 10057 |
|
| 10058 |
if Present (Asp) then |
| 10059 |
Set_Expression_Copy (Asp, New_Copy_Tree (Arg2_Copy)); |
| 10060 |
end if; |
| 10061 |
|
| 10062 |
-- "and"-in the Arg2 condition to evolving expression |
| 10063 |
|
| 10064 |
if not Is_Ignored_Ghost_Pragma (Prag) then |
| 10065 |
Add_Condition (Arg2_Copy); |
| 10066 |
end if; |
| 10067 |
end; |
| 10068 |
end if; |
| 10069 |
end Add_Predicate; |
| 10070 |
|
| 10071 |
-- Local variables |
| 10072 |
|
| 10073 |
Ritem : Node_Id; |
| 10074 |
|
| 10075 |
-- Start of processing for Add_Predicates |
| 10076 |
|
| 10077 |
begin |
| 10078 |
Ritem := First_Rep_Item (Typ); |
| 10079 |
|
| 10080 |
-- If the type is private, check whether full view has inherited |
| 10081 |
-- predicates. |
| 10082 |
|
| 10083 |
if Is_Private_Type (Typ) |
| 10084 |
and then No (Ritem) |
| 10085 |
and then Present (Full_View (Typ)) |
| 10086 |
then |
| 10087 |
Ritem := First_Rep_Item (Full_View (Typ)); |
| 10088 |
end if; |
| 10089 |
|
| 10090 |
while Present (Ritem) loop |
| 10091 |
if Nkind (Ritem) = N_Pragma |
| 10092 |
and then Pragma_Name (Ritem) = Name_Predicate |
| 10093 |
then |
| 10094 |
Add_Predicate (Ritem); |
| 10095 |
|
| 10096 |
-- If the type is declared in an inner package it may be frozen |
| 10097 |
-- outside of the package, and the generated pragma has not been |
| 10098 |
-- analyzed yet, so capture the expression for the predicate |
| 10099 |
-- function at this point. |
| 10100 |
|
| 10101 |
elsif Nkind (Ritem) = N_Aspect_Specification |
| 10102 |
and then Present (Aspect_Rep_Item (Ritem)) |
| 10103 |
and then Scope_Depth (Scope (Typ)) > Scope_Depth (Current_Scope) |
| 10104 |
then |
| 10105 |
declare |
| 10106 |
Prag : constant Node_Id := Aspect_Rep_Item (Ritem); |
| 10107 |
|
| 10108 |
begin |
| 10109 |
if Nkind (Prag) = N_Pragma |
| 10110 |
and then Pragma_Name (Prag) = Name_Predicate |
| 10111 |
then |
| 10112 |
Add_Predicate (Prag); |
| 10113 |
end if; |
| 10114 |
end; |
| 10115 |
end if; |
| 10116 |
|
| 10117 |
Next_Rep_Item (Ritem); |
| 10118 |
end loop; |
| 10119 |
end Add_Predicates; |
| 10120 |
|
| 10121 |
----------------------------------------- |
| 10122 |
-- Replace_Current_Instance_References -- |
| 10123 |
----------------------------------------- |
| 10124 |
|
| 10125 |
procedure Replace_Current_Instance_References |
| 10126 |
(N : Node_Id; Typ, New_Entity : Entity_Id) |
| 10127 |
is |
| 10128 |
Root : Node_Id renames N; |
| 10129 |
|
| 10130 |
procedure Replace_One_Reference (N : Node_Id); |
| 10131 |
-- Actual parameter for Replace_Type_References_Generic instance |
| 10132 |
|
| 10133 |
--------------------------- |
| 10134 |
-- Replace_One_Reference -- |
| 10135 |
--------------------------- |
| 10136 |
|
| 10137 |
procedure Replace_One_Reference (N : Node_Id) is |
| 10138 |
pragma Assert (In_Subtree (N, Root => Root)); |
| 10139 |
begin |
| 10140 |
Rewrite (N, New_Occurrence_Of (New_Entity, Sloc (N))); |
| 10141 |
-- Use the Sloc of the usage name, not the defining name |
| 10142 |
end Replace_One_Reference; |
| 10143 |
|
| 10144 |
procedure Replace_Type_References is |
| 10145 |
new Replace_Type_References_Generic (Replace_One_Reference); |
| 10146 |
begin |
| 10147 |
Replace_Type_References (N, Typ); |
| 10148 |
end Replace_Current_Instance_References; |
| 10149 |
|
| 10150 |
-- Start of processing for Build_Predicate_Function |
| 10151 |
|
| 10152 |
begin |
| 10153 |
-- Return if already built, if type does not have predicates, |
| 10154 |
-- or if type is a constructed subtype that will inherit a |
| 10155 |
-- predicate function from its ancestor. In a generic context |
| 10156 |
-- the predicated parent may not have a predicate function yet |
| 10157 |
-- but we don't want to build a new one for the subtype. This can |
| 10158 |
-- happen in an instance body which is nested within a generic |
| 10159 |
-- unit, in which case Within_A_Generic may be false, SId is |
| 10160 |
-- Empty, but uses of Typ will receive a predicate check in a |
| 10161 |
-- context where expansion and tests are enabled. |
| 10162 |
|
| 10163 |
SId := Predicate_Function (Typ); |
| 10164 |
if not Has_Predicates (Typ) |
| 10165 |
or else (Present (SId) and then Has_Completion (SId)) |
| 10166 |
or else |
| 10167 |
(Is_Itype (Typ) |
| 10168 |
and then not Comes_From_Source (Typ) |
| 10169 |
and then Ekind (Typ) in E_Array_Subtype |
| 10170 |
| E_Record_Subtype |
| 10171 |
| E_Record_Subtype_With_Private |
| 10172 |
and then Present (Predicated_Parent (Typ))) |
| 10173 |
then |
| 10174 |
return; |
| 10175 |
|
| 10176 |
-- Do not generate predicate bodies within a generic unit. The |
| 10177 |
-- expressions have been analyzed already, and the bodies play no role |
| 10178 |
-- if not within an executable unit. However, if a static predicate is |
| 10179 |
-- present it must be processed for legality checks such as case |
| 10180 |
-- coverage in an expression. |
| 10181 |
|
| 10182 |
elsif Inside_A_Generic |
| 10183 |
and then not Has_Static_Predicate_Aspect (Typ) |
| 10184 |
then |
| 10185 |
return; |
| 10186 |
end if; |
| 10187 |
|
| 10188 |
-- Ensure that the declarations are added to the scope of the type |
| 10189 |
|
| 10190 |
if Scope (Typ) /= Current_Scope then |
| 10191 |
Push_Scope (Scope (Typ)); |
| 10192 |
Restore_Scope := True; |
| 10193 |
else |
| 10194 |
Restore_Scope := False; |
| 10195 |
end if; |
| 10196 |
|
| 10197 |
-- The related type may be subject to pragma Ghost. Set the mode now to |
| 10198 |
-- ensure that the predicate functions are properly marked as Ghost. |
| 10199 |
|
| 10200 |
Set_Ghost_Mode (Typ); |
| 10201 |
|
| 10202 |
-- Prepare to construct predicate expression |
| 10203 |
|
| 10204 |
Expr := Empty; |
| 10205 |
|
| 10206 |
if Present (SId) then |
| 10207 |
FDecl := Unit_Declaration_Node (SId); |
| 10208 |
|
| 10209 |
else |
| 10210 |
FDecl := Build_Predicate_Function_Declaration (Typ); |
| 10211 |
SId := Defining_Entity (FDecl); |
| 10212 |
end if; |
| 10213 |
|
| 10214 |
-- Recover name of formal parameter of function that replaces references |
| 10215 |
-- to the type in predicate expressions. |
| 10216 |
|
| 10217 |
Object_Entity := |
| 10218 |
Defining_Identifier |
| 10219 |
(First (Parameter_Specifications (Specification (FDecl)))); |
| 10220 |
|
| 10221 |
Object_Name := Chars (Object_Entity); |
| 10222 |
|
| 10223 |
-- Add predicates for ancestor if present. These must come before the |
| 10224 |
-- ones for the current type, as required by AI12-0071-1. |
| 10225 |
|
| 10226 |
-- Looks like predicates aren't added for case of inheriting from |
| 10227 |
-- multiple progenitors??? |
| 10228 |
|
| 10229 |
declare |
| 10230 |
Atyp : Entity_Id; |
| 10231 |
begin |
| 10232 |
Atyp := Nearest_Ancestor (Typ); |
| 10233 |
|
| 10234 |
-- The type may be private but the full view may inherit predicates |
| 10235 |
|
| 10236 |
if No (Atyp) and then Is_Private_Type (Typ) then |
| 10237 |
Atyp := Nearest_Ancestor (Full_View (Typ)); |
| 10238 |
end if; |
| 10239 |
|
| 10240 |
if Present (Atyp) then |
| 10241 |
Add_Call (Atyp); |
| 10242 |
end if; |
| 10243 |
end; |
| 10244 |
|
| 10245 |
-- Add Predicates for the current type |
| 10246 |
|
| 10247 |
Add_Predicates; |
| 10248 |
|
| 10249 |
-- Case where predicates are present |
| 10250 |
|
| 10251 |
if Present (Expr) then |
| 10252 |
|
| 10253 |
-- Build the main predicate function |
| 10254 |
|
| 10255 |
declare |
| 10256 |
SIdB : constant Entity_Id := |
| 10257 |
Make_Defining_Identifier (Loc, |
| 10258 |
Chars => New_External_Name (Chars (Typ), "Predicate")); |
| 10259 |
-- The entity for the function body |
| 10260 |
|
| 10261 |
Spec : Node_Id; |
| 10262 |
FBody : Node_Id; |
| 10263 |
|
| 10264 |
begin |
| 10265 |
Mutate_Ekind (SIdB, E_Function); |
| 10266 |
Set_Is_Predicate_Function (SIdB); |
| 10267 |
|
| 10268 |
-- Build function body |
| 10269 |
|
| 10270 |
declare |
| 10271 |
Param_Specs : constant List_Id := New_List ( |
| 10272 |
Make_Parameter_Specification (Loc, |
| 10273 |
Defining_Identifier => |
| 10274 |
Make_Defining_Identifier (Loc, Object_Name), |
| 10275 |
Parameter_Type => |
| 10276 |
New_Occurrence_Of (Typ, Loc))); |
| 10277 |
begin |
| 10278 |
-- if Spec has 2 parameters, then body should too |
| 10279 |
if Present (Next_Entity (Object_Entity)) then |
| 10280 |
Append (Make_Parameter_Specification (Loc, |
| 10281 |
Defining_Identifier => |
| 10282 |
Make_Defining_Identifier |
| 10283 |
(Loc, Chars (Next_Entity (Object_Entity))), |
| 10284 |
Parameter_Type => |
| 10285 |
New_Occurrence_Of (Standard_Boolean, Loc)), |
| 10286 |
Param_Specs); |
| 10287 |
end if; |
| 10288 |
|
| 10289 |
Spec := |
| 10290 |
Make_Function_Specification (Loc, |
| 10291 |
Defining_Unit_Name => SIdB, |
| 10292 |
Parameter_Specifications => Param_Specs, |
| 10293 |
Result_Definition => |
| 10294 |
New_Occurrence_Of (Standard_Boolean, Loc)); |
| 10295 |
end; |
| 10296 |
|
| 10297 |
-- The Predicate_Expression attribute is used by SPARK. |
| 10298 |
-- |
| 10299 |
-- If Ancestor_Predicate_Function_Called is True, then |
| 10300 |
-- we try to exclude that call to the ancestor's |
| 10301 |
-- predicate function by calling Right_Opnd. |
| 10302 |
-- The call is not excluded in the case where |
| 10303 |
-- it is not "and"ed with anything else (so we don't have |
| 10304 |
-- an N_And_Then node). This exclusion is required if the |
| 10305 |
-- Predicate_Failure aspect is specified for Typ because |
| 10306 |
-- in that case we are going to drop the N_And_Then node |
| 10307 |
-- on the floor. Otherwise, it is a question of what is |
| 10308 |
-- most convenient for SPARK. |
| 10309 |
|
| 10310 |
Set_Predicate_Expression |
| 10311 |
(SId, (if Ancestor_Predicate_Function_Called |
| 10312 |
and then Nkind (Expr) = N_And_Then |
| 10313 |
then Right_Opnd (Expr) |
| 10314 |
else Expr)); |
| 10315 |
|
| 10316 |
declare |
| 10317 |
Result_Expr : Node_Id := Expr; |
| 10318 |
PF_Expr : Node_Id := Predicate_Failure_Expression |
| 10319 |
(Typ, Inherited_OK => False); |
| 10320 |
PF_Expr_Copy : Node_Id; |
| 10321 |
Second_Formal : constant Entity_Id := |
| 10322 |
Next_Entity (Object_Entity); |
| 10323 |
begin |
| 10324 |
-- In GNATprove mode we are only interested in the predicate |
| 10325 |
-- expression itself and don't want a raise expression that |
| 10326 |
-- comes from the Predicate_Failure. Ditto for CodePeer. |
| 10327 |
-- And an illegal Predicate_Failure aspect can lead to cases |
| 10328 |
-- we want to avoid. |
| 10329 |
|
| 10330 |
if Present (PF_Expr) |
| 10331 |
and then not GNATprove_Mode |
| 10332 |
and then not CodePeer_Mode |
| 10333 |
and then Serious_Errors_Detected = 0 |
| 10334 |
then |
| 10335 |
pragma Assert (Present (Second_Formal)); |
| 10336 |
|
| 10337 |
-- This is an ugly hack to cope with an ugly situation. |
| 10338 |
-- PF_Expr may have children whose Parent attribute |
| 10339 |
-- does not point back to PF_Expr. If we pass such a |
| 10340 |
-- tree to New_Copy_Tree, then it does not make a deep |
| 10341 |
-- copy. But we need a deep copy. So we need to find a |
| 10342 |
-- tree for which New_Copy_Tree *will* make a deep copy. |
| 10343 |
|
| 10344 |
declare |
| 10345 |
function Check_Node_Parent (Parent_Node, Node : Node_Id) |
| 10346 |
return Traverse_Result; |
| 10347 |
function Check_Node_Parent (Parent_Node, Node : Node_Id) |
| 10348 |
return Traverse_Result is |
| 10349 |
begin |
| 10350 |
if Parent_Node = PF_Expr |
| 10351 |
and then not Is_List_Member (Node) |
| 10352 |
then |
| 10353 |
pragma Assert |
| 10354 |
(Nkind (PF_Expr) = Nkind (Parent (Node))); |
| 10355 |
|
| 10356 |
-- We need PF_Expr to be a node for which |
| 10357 |
-- New_Copy_Tree will make a deep copy. |
| 10358 |
PF_Expr := Parent (Node); |
| 10359 |
return Abandon; |
| 10360 |
end if; |
| 10361 |
return OK; |
| 10362 |
end Check_Node_Parent; |
| 10363 |
procedure Check_Parentage is |
| 10364 |
new Traverse_Proc_With_Parent (Check_Node_Parent); |
| 10365 |
begin |
| 10366 |
Check_Parentage (PF_Expr); |
| 10367 |
PF_Expr_Copy := New_Copy_Tree (PF_Expr); |
| 10368 |
end; |
| 10369 |
|
| 10370 |
-- Current instance uses need to have their Entity |
| 10371 |
-- fields set so that Replace_Current_Instance_References |
| 10372 |
-- can find them. So we preanalyze. Just for purposes of |
| 10373 |
-- calls to Is_Current_Instance during this preanalysis, |
| 10374 |
-- we set the Parent field. |
| 10375 |
Set_Parent (PF_Expr_Copy, Parent (PF_Expr)); |
| 10376 |
Preanalyze (PF_Expr_Copy); |
| 10377 |
Set_Parent (PF_Expr_Copy, Empty); |
| 10378 |
|
| 10379 |
Replace_Current_Instance_References |
| 10380 |
(PF_Expr_Copy, Typ => Typ, New_Entity => Object_Entity); |
| 10381 |
|
| 10382 |
if Ancestor_Predicate_Function_Called then |
| 10383 |
-- If the call to an ancestor predicate function |
| 10384 |
-- returns False, we do not want to raise an |
| 10385 |
-- exception here. Our Predicate_Failure aspect does |
| 10386 |
-- not apply in that case. So we have to build a |
| 10387 |
-- more complicated result expression: |
| 10388 |
-- (if not Ancestor_Predicate_Function (...) then False |
| 10389 |
-- elsif Noninherited_Predicates (...) then True |
| 10390 |
-- elsif Is_Membership_Test then False |
| 10391 |
-- else (raise Assertion_Error with PF text)) |
| 10392 |
|
| 10393 |
declare |
| 10394 |
Ancestor_Call : constant Node_Id := |
| 10395 |
Left_Opnd (Result_Expr); |
| 10396 |
Local_Preds : constant Node_Id := |
| 10397 |
Right_Opnd (Result_Expr); |
| 10398 |
begin |
| 10399 |
Result_Expr := |
| 10400 |
Make_If_Expression (Loc, |
| 10401 |
Expressions => New_List ( |
| 10402 |
Make_Op_Not (Loc, Ancestor_Call), |
| 10403 |
New_Occurrence_Of (Standard_False, Loc), |
| 10404 |
Make_If_Expression (Loc, |
| 10405 |
Is_Elsif => True, |
| 10406 |
Expressions => New_List ( |
| 10407 |
Local_Preds, |
| 10408 |
New_Occurrence_Of (Standard_True, Loc), |
| 10409 |
Make_If_Expression (Loc, |
| 10410 |
Is_Elsif => True, |
| 10411 |
Expressions => New_List ( |
| 10412 |
New_Occurrence_Of (Second_Formal, Loc), |
| 10413 |
New_Occurrence_Of (Standard_False, Loc), |
| 10414 |
Make_Raise_Expression (Loc, |
| 10415 |
New_Occurrence_Of (RTE |
| 10416 |
(RE_Assert_Failure), Loc), |
| 10417 |
PF_Expr_Copy))))))); |
| 10418 |
end; |
| 10419 |
|
| 10420 |
else |
| 10421 |
-- Build a conditional expression: |
| 10422 |
-- (if <predicate evaluates to True> then True |
| 10423 |
-- elsif Is_Membership_Test then False |
| 10424 |
-- else (raise Assertion_Error with PF text)) |
| 10425 |
|
| 10426 |
Result_Expr := |
| 10427 |
Make_If_Expression (Loc, |
| 10428 |
Expressions => New_List ( |
| 10429 |
Result_Expr, |
| 10430 |
New_Occurrence_Of (Standard_True, Loc), |
| 10431 |
Make_If_Expression (Loc, |
| 10432 |
Is_Elsif => True, |
| 10433 |
Expressions => New_List ( |
| 10434 |
New_Occurrence_Of (Second_Formal, Loc), |
| 10435 |
New_Occurrence_Of (Standard_False, Loc), |
| 10436 |
Make_Raise_Expression (Loc, |
| 10437 |
New_Occurrence_Of (RTE |
| 10438 |
(RE_Assert_Failure), Loc), |
| 10439 |
PF_Expr_Copy))))); |
| 10440 |
end if; |
| 10441 |
end if; |
| 10442 |
|
| 10443 |
FBody := |
| 10444 |
Make_Subprogram_Body (Loc, |
| 10445 |
Specification => Spec, |
| 10446 |
Declarations => Empty_List, |
| 10447 |
Handled_Statement_Sequence => |
| 10448 |
Make_Handled_Sequence_Of_Statements (Loc, |
| 10449 |
Statements => New_List ( |
| 10450 |
Make_Simple_Return_Statement (Loc, |
| 10451 |
Expression => Result_Expr)))); |
| 10452 |
end; |
| 10453 |
|
| 10454 |
-- The declaration has been analyzed when created, and placed |
| 10455 |
-- after type declaration. Insert body itself after freeze node, |
| 10456 |
-- unless subprogram declaration is already there, in which case |
| 10457 |
-- body better be placed afterwards. |
| 10458 |
|
| 10459 |
if FDecl = Next (N) then |
| 10460 |
Insert_After_And_Analyze (FDecl, FBody); |
| 10461 |
else |
| 10462 |
Insert_After_And_Analyze (N, FBody); |
| 10463 |
end if; |
| 10464 |
|
| 10465 |
-- The defining identifier of a quantified expression carries the |
| 10466 |
-- scope in which the type appears, but when unnesting we need |
| 10467 |
-- to indicate that its proper scope is the constructed predicate |
| 10468 |
-- function. The quantified expressions have been converted into |
| 10469 |
-- loops during analysis and expansion. |
| 10470 |
|
| 10471 |
declare |
| 10472 |
function Reset_Quantified_Variable_Scope |
| 10473 |
(N : Node_Id) return Traverse_Result; |
| 10474 |
|
| 10475 |
procedure Reset_Quantified_Variables_Scope is |
| 10476 |
new Traverse_Proc (Reset_Quantified_Variable_Scope); |
| 10477 |
|
| 10478 |
------------------------------------- |
| 10479 |
-- Reset_Quantified_Variable_Scope -- |
| 10480 |
------------------------------------- |
| 10481 |
|
| 10482 |
function Reset_Quantified_Variable_Scope |
| 10483 |
(N : Node_Id) return Traverse_Result is |
| 10484 |
begin |
| 10485 |
if Nkind (N) in N_Iterator_Specification |
| 10486 |
| N_Loop_Parameter_Specification |
| 10487 |
then |
| 10488 |
Set_Scope (Defining_Identifier (N), |
| 10489 |
Predicate_Function (Typ)); |
| 10490 |
end if; |
| 10491 |
|
| 10492 |
return OK; |
| 10493 |
end Reset_Quantified_Variable_Scope; |
| 10494 |
|
| 10495 |
begin |
| 10496 |
if Unnest_Subprogram_Mode then |
| 10497 |
Reset_Quantified_Variables_Scope (Expr); |
| 10498 |
end if; |
| 10499 |
end; |
| 10500 |
|
| 10501 |
-- Within a generic unit, prevent a double analysis of the body |
| 10502 |
-- which will not be marked analyzed yet. This will happen when |
| 10503 |
-- the freeze node is created during the preanalysis of an |
| 10504 |
-- expression function. |
| 10505 |
|
| 10506 |
if Inside_A_Generic then |
| 10507 |
Set_Analyzed (FBody); |
| 10508 |
end if; |
| 10509 |
|
| 10510 |
-- Static predicate functions are always side-effect-free, and |
| 10511 |
-- in most cases dynamic predicate functions are as well. Mark |
| 10512 |
-- them as such whenever possible, so redundant predicate checks |
| 10513 |
-- can be optimized. If there is a variable reference within the |
| 10514 |
-- expression, the function is not pure. |
| 10515 |
|
| 10516 |
if Expander_Active then |
| 10517 |
Set_Is_Pure (SId, |
| 10518 |
Side_Effect_Free (Expr, Variable_Ref => True)); |
| 10519 |
Set_Is_Inlined (SId); |
| 10520 |
end if; |
| 10521 |
end; |
| 10522 |
|
| 10523 |
-- See if we have a static predicate. Note that the answer may be |
| 10524 |
-- yes even if we have an explicit Dynamic_Predicate present. |
| 10525 |
|
| 10526 |
declare |
| 10527 |
PS : Boolean; |
| 10528 |
EN : Node_Id; |
| 10529 |
|
| 10530 |
begin |
| 10531 |
if not Is_Scalar_Type (Typ) and then not Is_String_Type (Typ) then |
| 10532 |
PS := False; |
| 10533 |
else |
| 10534 |
PS := Is_Predicate_Static (Expr, Object_Name); |
| 10535 |
end if; |
| 10536 |
|
| 10537 |
-- Case where we have a predicate-static aspect |
| 10538 |
|
| 10539 |
if PS then |
| 10540 |
|
| 10541 |
-- We don't set Has_Static_Predicate_Aspect, since we can have |
| 10542 |
-- any of the three cases (Predicate, Dynamic_Predicate, or |
| 10543 |
-- Static_Predicate) generating a predicate with an expression |
| 10544 |
-- that is predicate-static. We just indicate that we have a |
| 10545 |
-- predicate that can be treated as static. |
| 10546 |
|
| 10547 |
Set_Has_Static_Predicate (Typ); |
| 10548 |
|
| 10549 |
-- For discrete subtype, build the static predicate list |
| 10550 |
|
| 10551 |
if Is_Discrete_Type (Typ) then |
| 10552 |
Build_Discrete_Static_Predicate (Typ, Expr, Object_Name); |
| 10553 |
|
| 10554 |
-- If we don't get a static predicate list, it means that we |
| 10555 |
-- have a case where this is not possible, most typically in |
| 10556 |
-- the case where we inherit a dynamic predicate. We do not |
| 10557 |
-- consider this an error, we just leave the predicate as |
| 10558 |
-- dynamic. But if we do succeed in building the list, then |
| 10559 |
-- we mark the predicate as static. |
| 10560 |
|
| 10561 |
if No (Static_Discrete_Predicate (Typ)) then |
| 10562 |
Set_Has_Static_Predicate (Typ, False); |
| 10563 |
end if; |
| 10564 |
|
| 10565 |
-- For real or string subtype, save predicate expression |
| 10566 |
|
| 10567 |
elsif Is_Real_Type (Typ) or else Is_String_Type (Typ) then |
| 10568 |
Set_Static_Real_Or_String_Predicate (Typ, Expr); |
| 10569 |
end if; |
| 10570 |
|
| 10571 |
-- Case of dynamic predicate (expression is not predicate-static) |
| 10572 |
|
| 10573 |
else |
| 10574 |
-- Again, we don't set Has_Dynamic_Predicate_Aspect, since that |
| 10575 |
-- is only set if we have an explicit Dynamic_Predicate aspect |
| 10576 |
-- given. Here we may simply have a Predicate aspect where the |
| 10577 |
-- expression happens not to be predicate-static. |
| 10578 |
|
| 10579 |
-- Emit an error when the predicate is categorized as static |
| 10580 |
-- but its expression is not predicate-static. |
| 10581 |
|
| 10582 |
-- First a little fiddling to get a nice location for the |
| 10583 |
-- message. If the expression is of the form (A and then B), |
| 10584 |
-- where A is an inherited predicate, then use the right |
| 10585 |
-- operand for the Sloc. This avoids getting confused by a call |
| 10586 |
-- to an inherited predicate with a less convenient source |
| 10587 |
-- location. |
| 10588 |
|
| 10589 |
EN := Expr; |
| 10590 |
while Nkind (EN) = N_And_Then |
| 10591 |
and then Nkind (Left_Opnd (EN)) = N_Function_Call |
| 10592 |
and then Is_Predicate_Function |
| 10593 |
(Entity (Name (Left_Opnd (EN)))) |
| 10594 |
loop |
| 10595 |
EN := Right_Opnd (EN); |
| 10596 |
end loop; |
| 10597 |
|
| 10598 |
-- Now post appropriate message |
| 10599 |
|
| 10600 |
if Has_Static_Predicate_Aspect (Typ) then |
| 10601 |
if Is_Scalar_Type (Typ) or else Is_String_Type (Typ) then |
| 10602 |
Error_Msg_F |
| 10603 |
("expression is not predicate-static (RM 3.2.4(16-22))", |
| 10604 |
EN); |
| 10605 |
else |
| 10606 |
Error_Msg_F |
| 10607 |
("static predicate requires scalar or string type", EN); |
| 10608 |
end if; |
| 10609 |
end if; |
| 10610 |
end if; |
| 10611 |
end; |
| 10612 |
end if; |
| 10613 |
|
| 10614 |
Restore_Ghost_Region (Saved_GM, Saved_IGR); |
| 10615 |
|
| 10616 |
if Restore_Scope then |
| 10617 |
Pop_Scope; |
| 10618 |
end if; |
| 10619 |
end Build_Predicate_Function; |
| 10620 |
|
| 10621 |
------------------------------------------ |
| 10622 |
-- Build_Predicate_Function_Declaration -- |
| 10623 |
------------------------------------------ |
| 10624 |
|
| 10625 |
-- WARNING: This routine manages Ghost regions. Return statements must be |
| 10626 |
-- replaced by gotos which jump to the end of the routine and restore the |
| 10627 |
-- Ghost mode. |
| 10628 |
|
| 10629 |
function Build_Predicate_Function_Declaration |
| 10630 |
(Typ : Entity_Id) return Node_Id |
| 10631 |
is |
| 10632 |
Loc : constant Source_Ptr := Sloc (Typ); |
| 10633 |
|
| 10634 |
Saved_GM : constant Ghost_Mode_Type := Ghost_Mode; |
| 10635 |
Saved_IGR : constant Node_Id := Ignored_Ghost_Region; |
| 10636 |
-- Save the Ghost-related attributes to restore on exit |
| 10637 |
|
| 10638 |
Func_Decl : Node_Id; |
| 10639 |
Func_Id : Entity_Id; |
| 10640 |
Spec : Node_Id; |
| 10641 |
|
| 10642 |
CRec_Typ : Entity_Id; |
| 10643 |
-- The corresponding record type of Full_Typ |
| 10644 |
|
| 10645 |
Full_Typ : Entity_Id; |
| 10646 |
-- The full view of Typ |
| 10647 |
|
| 10648 |
Priv_Typ : Entity_Id; |
| 10649 |
-- The partial view of Typ |
| 10650 |
|
| 10651 |
UFull_Typ : Entity_Id; |
| 10652 |
-- The underlying full view of Full_Typ |
| 10653 |
|
| 10654 |
begin |
| 10655 |
-- The related type may be subject to pragma Ghost. Set the mode now to |
| 10656 |
-- ensure that the predicate functions are properly marked as Ghost. |
| 10657 |
|
| 10658 |
Set_Ghost_Mode (Typ); |
| 10659 |
|
| 10660 |
Func_Id := |
| 10661 |
Make_Defining_Identifier (Loc, |
| 10662 |
Chars => New_External_Name (Chars (Typ), "Predicate")); |
| 10663 |
|
| 10664 |
Mutate_Ekind (Func_Id, E_Function); |
| 10665 |
Set_Etype (Func_Id, Standard_Boolean); |
| 10666 |
Set_Is_Internal (Func_Id); |
| 10667 |
Set_Is_Predicate_Function (Func_Id); |
| 10668 |
Set_Predicate_Function (Typ, Func_Id); |
| 10669 |
|
| 10670 |
-- The predicate function requires debug info when the predicates are |
| 10671 |
-- subject to Source Coverage Obligations. |
| 10672 |
|
| 10673 |
if Opt.Generate_SCO then |
| 10674 |
Set_Debug_Info_Needed (Func_Id); |
| 10675 |
end if; |
| 10676 |
|
| 10677 |
-- Obtain all views of the input type |
| 10678 |
|
| 10679 |
Get_Views (Typ, Priv_Typ, Full_Typ, UFull_Typ, CRec_Typ); |
| 10680 |
|
| 10681 |
-- Associate the predicate function and various flags with all views |
| 10682 |
|
| 10683 |
Propagate_Predicate_Attributes (Priv_Typ, From_Typ => Typ); |
| 10684 |
Propagate_Predicate_Attributes (Full_Typ, From_Typ => Typ); |
| 10685 |
Propagate_Predicate_Attributes (UFull_Typ, From_Typ => Typ); |
| 10686 |
Propagate_Predicate_Attributes (CRec_Typ, From_Typ => Typ); |
| 10687 |
|
| 10688 |
declare |
| 10689 |
Param_Specs : constant List_Id := New_List ( |
| 10690 |
Make_Parameter_Specification (Loc, |
| 10691 |
Defining_Identifier => Make_Temporary (Loc, 'I'), |
| 10692 |
Parameter_Type => New_Occurrence_Of (Typ, Loc))); |
| 10693 |
begin |
| 10694 |
if Predicate_Function_Needs_Membership_Parameter (Typ) then |
| 10695 |
-- Add Boolean-valued For_Membership_Test param |
| 10696 |
Append (Make_Parameter_Specification (Loc, |
| 10697 |
Defining_Identifier => Make_Temporary (Loc, 'M'), |
| 10698 |
Parameter_Type => |
| 10699 |
New_Occurrence_Of (Standard_Boolean, Loc)), |
| 10700 |
Param_Specs); |
| 10701 |
end if; |
| 10702 |
|
| 10703 |
Spec := |
| 10704 |
Make_Function_Specification (Loc, |
| 10705 |
Defining_Unit_Name => Func_Id, |
| 10706 |
Parameter_Specifications => Param_Specs, |
| 10707 |
Result_Definition => |
| 10708 |
New_Occurrence_Of (Standard_Boolean, Loc)); |
| 10709 |
end; |
| 10710 |
|
| 10711 |
Func_Decl := Make_Subprogram_Declaration (Loc, Specification => Spec); |
| 10712 |
|
| 10713 |
Insert_After (Parent (Typ), Func_Decl); |
| 10714 |
Analyze (Func_Decl); |
| 10715 |
|
| 10716 |
Restore_Ghost_Region (Saved_GM, Saved_IGR); |
| 10717 |
|
| 10718 |
return Func_Decl; |
| 10719 |
end Build_Predicate_Function_Declaration; |
| 10720 |
|
| 10721 |
----------------------------------------- |
| 10722 |
-- Check_Aspect_At_End_Of_Declarations -- |
| 10723 |
----------------------------------------- |
| 10724 |
|
| 10725 |
procedure Check_Aspect_At_End_Of_Declarations (ASN : Node_Id) is |
| 10726 |
Ent : constant Entity_Id := Entity (ASN); |
| 10727 |
Ident : constant Node_Id := Identifier (ASN); |
| 10728 |
A_Id : constant Aspect_Id := Get_Aspect_Id (Chars (Ident)); |
| 10729 |
|
| 10730 |
End_Decl_Expr : constant Node_Id := Expression_Copy (ASN); |
| 10731 |
-- Expression to be analyzed at end of declarations |
| 10732 |
|
| 10733 |
Freeze_Expr : constant Node_Id := Expression (ASN); |
| 10734 |
-- Expression from call to Check_Aspect_At_Freeze_Point |
| 10735 |
|
| 10736 |
T : constant Entity_Id := |
| 10737 |
(if Present (Freeze_Expr) and then A_Id /= Aspect_Stable_Properties |
| 10738 |
then Etype (Original_Node (Freeze_Expr)) |
| 10739 |
else Empty); |
| 10740 |
-- Type required for preanalyze call. We use the original expression to |
| 10741 |
-- get the proper type, to prevent cascaded errors when the expression |
| 10742 |
-- is constant-folded. For Stable_Properties, the aspect value is |
| 10743 |
-- not semantically an expression (although it is syntactically); |
| 10744 |
-- in particular, it has no type. |
| 10745 |
|
| 10746 |
Err : Boolean; |
| 10747 |
-- Set True if error |
| 10748 |
|
| 10749 |
-- On entry to this procedure, Entity (Ident) contains a copy of the |
| 10750 |
-- original expression from the aspect, saved for this purpose, and |
| 10751 |
-- but Expression (Ident) is a preanalyzed copy of the expression, |
| 10752 |
-- preanalyzed just after the freeze point. |
| 10753 |
|
| 10754 |
procedure Check_Overloaded_Name; |
| 10755 |
-- For aspects whose expression is simply a name, this routine checks if |
| 10756 |
-- the name is overloaded or not. If so, it verifies there is an |
| 10757 |
-- interpretation that matches the entity obtained at the freeze point, |
| 10758 |
-- otherwise the compiler complains. |
| 10759 |
|
| 10760 |
--------------------------- |
| 10761 |
-- Check_Overloaded_Name -- |
| 10762 |
--------------------------- |
| 10763 |
|
| 10764 |
procedure Check_Overloaded_Name is |
| 10765 |
begin |
| 10766 |
if not Is_Overloaded (End_Decl_Expr) then |
| 10767 |
Err := not Is_Entity_Name (End_Decl_Expr) |
| 10768 |
or else Entity (End_Decl_Expr) /= Entity (Freeze_Expr); |
| 10769 |
|
| 10770 |
else |
| 10771 |
Err := True; |
| 10772 |
|
| 10773 |
declare |
| 10774 |
Index : Interp_Index; |
| 10775 |
It : Interp; |
| 10776 |
|
| 10777 |
begin |
| 10778 |
Get_First_Interp (End_Decl_Expr, Index, It); |
| 10779 |
while Present (It.Typ) loop |
| 10780 |
if It.Nam = Entity (Freeze_Expr) then |
| 10781 |
Err := False; |
| 10782 |
exit; |
| 10783 |
end if; |
| 10784 |
|
| 10785 |
Get_Next_Interp (Index, It); |
| 10786 |
end loop; |
| 10787 |
end; |
| 10788 |
end if; |
| 10789 |
end Check_Overloaded_Name; |
| 10790 |
|
| 10791 |
-- Start of processing for Check_Aspect_At_End_Of_Declarations |
| 10792 |
|
| 10793 |
begin |
| 10794 |
-- In an instance we do not perform the consistency check between freeze |
| 10795 |
-- point and end of declarations, because it was done already in the |
| 10796 |
-- analysis of the generic. Furthermore, the delayed analysis of an |
| 10797 |
-- aspect of the instance may produce spurious errors when the generic |
| 10798 |
-- is a child unit that references entities in the parent (which might |
| 10799 |
-- not be in scope at the freeze point of the instance). |
| 10800 |
|
| 10801 |
if In_Instance then |
| 10802 |
return; |
| 10803 |
|
| 10804 |
-- The enclosing scope may have been rewritten during expansion (e.g. a |
| 10805 |
-- task body is rewritten as a procedure) after this conformance check |
| 10806 |
-- has been performed, so do not perform it again (it may not easily be |
| 10807 |
-- done if full visibility of local entities is not available). |
| 10808 |
|
| 10809 |
elsif not Comes_From_Source (Current_Scope) then |
| 10810 |
return; |
| 10811 |
|
| 10812 |
-- Case of aspects Dimension, Dimension_System and Synchronization |
| 10813 |
|
| 10814 |
elsif A_Id = Aspect_Synchronization then |
| 10815 |
return; |
| 10816 |
|
| 10817 |
-- Case of stream attributes and Put_Image, just have to compare |
| 10818 |
-- entities. However, the expression is just a possibly-overloaded |
| 10819 |
-- name, so we need to verify that one of these interpretations is |
| 10820 |
-- the one available at at the freeze point. |
| 10821 |
|
| 10822 |
elsif A_Id in Aspect_Input |
| 10823 |
| Aspect_Output |
| 10824 |
| Aspect_Read |
| 10825 |
| Aspect_Write |
| 10826 |
| Aspect_Put_Image |
| 10827 |
then |
| 10828 |
Analyze (End_Decl_Expr); |
| 10829 |
Check_Overloaded_Name; |
| 10830 |
|
| 10831 |
elsif A_Id in Aspect_Variable_Indexing |
| 10832 |
| Aspect_Constant_Indexing |
| 10833 |
| Aspect_Default_Iterator |
| 10834 |
| Aspect_Iterator_Element |
| 10835 |
| Aspect_Integer_Literal |
| 10836 |
| Aspect_Real_Literal |
| 10837 |
| Aspect_String_Literal |
| 10838 |
then |
| 10839 |
-- Make type unfrozen before analysis, to prevent spurious errors |
| 10840 |
-- about late attributes. |
| 10841 |
|
| 10842 |
Set_Is_Frozen (Ent, False); |
| 10843 |
Analyze (End_Decl_Expr); |
| 10844 |
Set_Is_Frozen (Ent, True); |
| 10845 |
|
| 10846 |
-- If the end of declarations comes before any other freeze point, |
| 10847 |
-- the Freeze_Expr is not analyzed: no check needed. |
| 10848 |
|
| 10849 |
if Analyzed (Freeze_Expr) then |
| 10850 |
Check_Overloaded_Name; |
| 10851 |
else |
| 10852 |
Err := False; |
| 10853 |
end if; |
| 10854 |
|
| 10855 |
-- All other cases |
| 10856 |
|
| 10857 |
else |
| 10858 |
-- In a generic context freeze nodes are not always generated, so |
| 10859 |
-- analyze the expression now. If the aspect is for a type, we must |
| 10860 |
-- also make its potential components accessible. |
| 10861 |
|
| 10862 |
if not Analyzed (Freeze_Expr) and then Inside_A_Generic then |
| 10863 |
if A_Id in Aspect_Dynamic_Predicate |
| 10864 |
| Aspect_Ghost_Predicate |
| 10865 |
| Aspect_Predicate |
| 10866 |
| Aspect_Static_Predicate |
| 10867 |
then |
| 10868 |
Push_Type (Ent); |
| 10869 |
Preanalyze_Spec_Expression (Freeze_Expr, Standard_Boolean); |
| 10870 |
Pop_Type (Ent); |
| 10871 |
|
| 10872 |
elsif A_Id = Aspect_Priority then |
| 10873 |
Push_Type (Ent); |
| 10874 |
Preanalyze_Spec_Expression (Freeze_Expr, Any_Integer); |
| 10875 |
Pop_Type (Ent); |
| 10876 |
|
| 10877 |
else |
| 10878 |
Preanalyze (Freeze_Expr); |
| 10879 |
end if; |
| 10880 |
end if; |
| 10881 |
|
| 10882 |
-- Indicate that the expression comes from an aspect specification, |
| 10883 |
-- which is used in subsequent analysis even if expansion is off. |
| 10884 |
|
| 10885 |
if Present (End_Decl_Expr) then |
| 10886 |
Set_Parent (End_Decl_Expr, ASN); |
| 10887 |
end if; |
| 10888 |
|
| 10889 |
-- In a generic context the original aspect expressions have not |
| 10890 |
-- been preanalyzed, so do it now. There are no conformance checks |
| 10891 |
-- to perform in this case. As before, we have to make components |
| 10892 |
-- visible for aspects that may reference them. |
| 10893 |
|
| 10894 |
if Present (Freeze_Expr) and then No (T) then |
| 10895 |
if A_Id in Aspect_Dynamic_Predicate |
| 10896 |
| Aspect_Ghost_Predicate |
| 10897 |
| Aspect_Predicate |
| 10898 |
| Aspect_Priority |
| 10899 |
| Aspect_Static_Predicate |
| 10900 |
then |
| 10901 |
Push_Type (Ent); |
| 10902 |
Check_Aspect_At_Freeze_Point (ASN); |
| 10903 |
Pop_Type (Ent); |
| 10904 |
|
| 10905 |
else |
| 10906 |
Check_Aspect_At_Freeze_Point (ASN); |
| 10907 |
end if; |
| 10908 |
return; |
| 10909 |
|
| 10910 |
-- The expression must be analyzed in the special manner described in |
| 10911 |
-- "Handling of Default and Per-Object Expressions" in sem.ads, since |
| 10912 |
-- any static expressions within an aspect_specification also cause |
| 10913 |
-- freezing at the end of the immediately enclosing declaration list |
| 10914 |
-- (RM 13.14(7.2/5)). |
| 10915 |
|
| 10916 |
-- The default values attributes may be defined in the private part, |
| 10917 |
-- and the analysis of the expression may take place when only the |
| 10918 |
-- partial view is visible. The expression must be scalar, so use |
| 10919 |
-- the full view to resolve. |
| 10920 |
|
| 10921 |
elsif A_Id in Aspect_Default_Component_Value | Aspect_Default_Value |
| 10922 |
and then Is_Private_Type (T) |
| 10923 |
then |
| 10924 |
Preanalyze_Spec_Expression (End_Decl_Expr, Full_View (T)); |
| 10925 |
|
| 10926 |
-- The following aspect expressions may contain references to |
| 10927 |
-- components and discriminants of the type. |
| 10928 |
|
| 10929 |
elsif A_Id in Aspect_CPU |
| 10930 |
| Aspect_Dynamic_Predicate |
| 10931 |
| Aspect_Ghost_Predicate |
| 10932 |
| Aspect_Interrupt_Priority |
| 10933 |
| Aspect_Predicate |
| 10934 |
| Aspect_Priority |
| 10935 |
| Aspect_Static_Predicate |
| 10936 |
then |
| 10937 |
Push_Type (Ent); |
| 10938 |
Preanalyze_Spec_Expression (End_Decl_Expr, T); |
| 10939 |
Pop_Type (Ent); |
| 10940 |
|
| 10941 |
elsif A_Id = Aspect_Predicate_Failure then |
| 10942 |
Preanalyze_Spec_Expression (End_Decl_Expr, Standard_String); |
| 10943 |
|
| 10944 |
elsif Present (End_Decl_Expr) then |
| 10945 |
Preanalyze_Spec_Expression (End_Decl_Expr, T); |
| 10946 |
end if; |
| 10947 |
|
| 10948 |
Err := |
| 10949 |
not Fully_Conformant_Expressions |
| 10950 |
(End_Decl_Expr, Freeze_Expr, Report => True); |
| 10951 |
end if; |
| 10952 |
|
| 10953 |
-- Output error message if error. Force error on aspect specification |
| 10954 |
-- even if there is an error on the expression itself. |
| 10955 |
|
| 10956 |
if Err then |
| 10957 |
Error_Msg_NE |
| 10958 |
("!visibility of aspect for& changes after freeze point", |
| 10959 |
ASN, Ent); |
| 10960 |
Error_Msg_Sloc := Sloc (Freeze_Node (Ent)); |
| 10961 |
Error_Msg_NE |
| 10962 |
("\& is frozen #, (RM 13.1.1 (13/3))", |
| 10963 |
ASN, Ent); |
| 10964 |
end if; |
| 10965 |
end Check_Aspect_At_End_Of_Declarations; |
| 10966 |
|
| 10967 |
------------------------------------------ |
| 10968 |
-- Check_Aspects_At_End_Of_Declarations -- |
| 10969 |
------------------------------------------ |
| 10970 |
|
| 10971 |
procedure Check_Aspects_At_End_Of_Declarations (E : Entity_Id) is |
| 10972 |
ASN : Node_Id; |
| 10973 |
|
| 10974 |
begin |
| 10975 |
ASN := First_Rep_Item (E); |
| 10976 |
|
| 10977 |
while Present (ASN) loop |
| 10978 |
if Nkind (ASN) = N_Aspect_Specification |
| 10979 |
and then Entity (ASN) = E |
| 10980 |
and then Is_Delayed_Aspect (ASN) |
| 10981 |
then |
| 10982 |
Check_Aspect_At_End_Of_Declarations (ASN); |
| 10983 |
end if; |
| 10984 |
|
| 10985 |
Next_Rep_Item (ASN); |
| 10986 |
end loop; |
| 10987 |
end Check_Aspects_At_End_Of_Declarations; |
| 10988 |
|
| 10989 |
---------------------------------- |
| 10990 |
-- Check_Aspect_At_Freeze_Point -- |
| 10991 |
---------------------------------- |
| 10992 |
|
| 10993 |
procedure Check_Aspect_At_Freeze_Point (ASN : Node_Id) is |
| 10994 |
Ident : constant Node_Id := Identifier (ASN); |
| 10995 |
-- Identifier (use Entity field to save expression) |
| 10996 |
|
| 10997 |
Expr : constant Node_Id := Expression (ASN); |
| 10998 |
-- For cases where using Entity (Identifier) doesn't work |
| 10999 |
|
| 11000 |
A_Id : constant Aspect_Id := Get_Aspect_Id (Chars (Ident)); |
| 11001 |
|
| 11002 |
T : Entity_Id := Empty; |
| 11003 |
-- Type required for preanalyze call |
| 11004 |
|
| 11005 |
begin |
| 11006 |
-- On entry to this procedure, Entity (Ident) contains a copy of the |
| 11007 |
-- original expression from the aspect, saved for this purpose. |
| 11008 |
|
| 11009 |
-- On exit from this procedure Entity (Ident) is unchanged, still |
| 11010 |
-- containing that copy, but Expression (Ident) is a preanalyzed copy |
| 11011 |
-- of the expression, preanalyzed just after the freeze point. |
| 11012 |
|
| 11013 |
-- Make a copy of the expression to be preanalyzed |
| 11014 |
|
| 11015 |
Set_Expression (ASN, New_Copy_Tree (Expression_Copy (ASN))); |
| 11016 |
|
| 11017 |
-- Find type for preanalyze call |
| 11018 |
|
| 11019 |
case A_Id is |
| 11020 |
|
| 11021 |
-- No_Aspect should be impossible |
| 11022 |
|
| 11023 |
when No_Aspect => |
| 11024 |
raise Program_Error; |
| 11025 |
|
| 11026 |
-- Aspects taking an optional boolean argument |
| 11027 |
|
| 11028 |
when Boolean_Aspects |
| 11029 |
| Library_Unit_Aspects |
| 11030 |
=> |
| 11031 |
T := Standard_Boolean; |
| 11032 |
|
| 11033 |
-- Aspects corresponding to attribute definition clauses |
| 11034 |
|
| 11035 |
when Aspect_Address => |
| 11036 |
T := RTE (RE_Address); |
| 11037 |
|
| 11038 |
when Aspect_Attach_Handler => |
| 11039 |
T := RTE (RE_Interrupt_ID); |
| 11040 |
|
| 11041 |
when Aspect_Bit_Order |
| 11042 |
| Aspect_Scalar_Storage_Order |
| 11043 |
=> |
| 11044 |
T := RTE (RE_Bit_Order); |
| 11045 |
|
| 11046 |
when Aspect_Convention => |
| 11047 |
return; |
| 11048 |
|
| 11049 |
when Aspect_CPU => |
| 11050 |
T := RTE (RE_CPU_Range); |
| 11051 |
|
| 11052 |
-- Default_Component_Value is resolved with the component type |
| 11053 |
|
| 11054 |
when Aspect_Default_Component_Value => |
| 11055 |
T := Component_Type (Entity (ASN)); |
| 11056 |
|
| 11057 |
when Aspect_Default_Storage_Pool => |
| 11058 |
T := Class_Wide_Type (RTE (RE_Root_Storage_Pool)); |
| 11059 |
|
| 11060 |
-- Default_Value is resolved with the type entity in question |
| 11061 |
|
| 11062 |
when Aspect_Default_Value => |
| 11063 |
T := Entity (ASN); |
| 11064 |
|
| 11065 |
when Aspect_Dispatching_Domain => |
| 11066 |
T := RTE (RE_Dispatching_Domain); |
| 11067 |
|
| 11068 |
when Aspect_External_Tag => |
| 11069 |
T := Standard_String; |
| 11070 |
|
| 11071 |
when Aspect_External_Name => |
| 11072 |
T := Standard_String; |
| 11073 |
|
| 11074 |
when Aspect_Link_Name => |
| 11075 |
T := Standard_String; |
| 11076 |
|
| 11077 |
when Aspect_Interrupt_Priority |
| 11078 |
| Aspect_Priority |
| 11079 |
=> |
| 11080 |
T := Standard_Integer; |
| 11081 |
|
| 11082 |
when Aspect_Relative_Deadline => |
| 11083 |
T := RTE (RE_Time_Span); |
| 11084 |
|
| 11085 |
when Aspect_Secondary_Stack_Size => |
| 11086 |
T := Standard_Integer; |
| 11087 |
|
| 11088 |
when Aspect_Small => |
| 11089 |
|
| 11090 |
-- Note that the expression can be of any real type (not just a |
| 11091 |
-- real universal literal) as long as it is a static constant. |
| 11092 |
|
| 11093 |
T := Any_Real; |
| 11094 |
|
| 11095 |
-- For a simple storage pool, we have to retrieve the type of the |
| 11096 |
-- pool object associated with the aspect's corresponding attribute |
| 11097 |
-- definition clause. |
| 11098 |
|
| 11099 |
when Aspect_Simple_Storage_Pool => |
| 11100 |
T := Etype (Expression (Aspect_Rep_Item (ASN))); |
| 11101 |
|
| 11102 |
when Aspect_Storage_Pool => |
| 11103 |
T := Class_Wide_Type (RTE (RE_Root_Storage_Pool)); |
| 11104 |
|
| 11105 |
when Aspect_Alignment |
| 11106 |
| Aspect_Component_Size |
| 11107 |
| Aspect_Machine_Radix |
| 11108 |
| Aspect_Object_Size |
| 11109 |
| Aspect_Size |
| 11110 |
| Aspect_Storage_Size |
| 11111 |
| Aspect_Stream_Size |
| 11112 |
| Aspect_Value_Size |
| 11113 |
=> |
| 11114 |
T := Any_Integer; |
| 11115 |
|
| 11116 |
when Aspect_Linker_Section => |
| 11117 |
T := Standard_String; |
| 11118 |
|
| 11119 |
when Aspect_Local_Restrictions => |
| 11120 |
return; |
| 11121 |
|
| 11122 |
when Aspect_Synchronization => |
| 11123 |
return; |
| 11124 |
|
| 11125 |
-- Special case, the expression of these aspects is just an entity |
| 11126 |
-- that does not need any resolution, so just analyze. |
| 11127 |
|
| 11128 |
when Aspect_Input |
| 11129 |
| Aspect_Output |
| 11130 |
| Aspect_Put_Image |
| 11131 |
| Aspect_Read |
| 11132 |
| Aspect_Warnings |
| 11133 |
| Aspect_Write |
| 11134 |
=> |
| 11135 |
Analyze (Expression (ASN)); |
| 11136 |
return; |
| 11137 |
|
| 11138 |
-- Same for Iterator aspects, where the expression is a function |
| 11139 |
-- name. Legality rules are checked separately. |
| 11140 |
|
| 11141 |
when Aspect_Constant_Indexing |
| 11142 |
| Aspect_Iterator_Element |
| 11143 |
| Aspect_Variable_Indexing |
| 11144 |
=> |
| 11145 |
Analyze (Expression (ASN)); |
| 11146 |
return; |
| 11147 |
|
| 11148 |
-- Same for Literal aspects, where the expression is a function |
| 11149 |
-- name. Legality rules are checked separately. Use Expr to avoid |
| 11150 |
-- losing track of the previous resolution of Expression. |
| 11151 |
|
| 11152 |
when Aspect_Integer_Literal |
| 11153 |
| Aspect_Real_Literal |
| 11154 |
| Aspect_String_Literal |
| 11155 |
=> |
| 11156 |
Set_Entity (Expression (ASN), Entity (Expr)); |
| 11157 |
Set_Etype (Expression (ASN), Etype (Expr)); |
| 11158 |
Set_Is_Overloaded (Expression (ASN), False); |
| 11159 |
Analyze (Expression (ASN)); |
| 11160 |
return; |
| 11161 |
|
| 11162 |
when Aspect_Default_Iterator => |
| 11163 |
|
| 11164 |
-- If the aspect is not Comes_From_Source, then it's an inherited |
| 11165 |
-- aspect, in which case the aspect's operation has already been |
| 11166 |
-- set, and there's no need to call Check_Iterator_Functions. |
| 11167 |
|
| 11168 |
if Comes_From_Source (ASN) then |
| 11169 |
Check_Iterator_Functions |
| 11170 |
(Typ => Entity (ASN), Expr => Expression (ASN)); |
| 11171 |
end if; |
| 11172 |
return; |
| 11173 |
|
| 11174 |
-- Finalizable, legality checks in Validate_Finalizable_Aspect |
| 11175 |
|
| 11176 |
when Aspect_Finalizable => |
| 11177 |
T := Entity (ASN); |
| 11178 |
|
| 11179 |
if Nkind (Expression (ASN)) /= N_Aggregate then |
| 11180 |
pragma Assert (Serious_Errors_Detected > 0); |
| 11181 |
return; |
| 11182 |
end if; |
| 11183 |
|
| 11184 |
declare |
| 11185 |
Assoc : Node_Id; |
| 11186 |
Exp : Node_Id; |
| 11187 |
Nam : Node_Id; |
| 11188 |
|
| 11189 |
begin |
| 11190 |
Assoc := First (Component_Associations (Expression (ASN))); |
| 11191 |
while Present (Assoc) loop |
| 11192 |
Nam := First (Choices (Assoc)); |
| 11193 |
Exp := Expression (Assoc); |
| 11194 |
|
| 11195 |
if Chars (Nam) = Name_Relaxed_Finalization |
| 11196 |
and then Inside_A_Generic |
| 11197 |
then |
| 11198 |
Preanalyze_And_Resolve (Exp, Any_Boolean); |
| 11199 |
|
| 11200 |
else |
| 11201 |
Analyze (Exp); |
| 11202 |
Resolve_Finalizable_Argument (Exp, T, Chars (Nam)); |
| 11203 |
end if; |
| 11204 |
|
| 11205 |
Next (Assoc); |
| 11206 |
end loop; |
| 11207 |
end; |
| 11208 |
|
| 11209 |
return; |
| 11210 |
|
| 11211 |
-- Iterable, legality checks in Validate_Iterable_Aspect |
| 11212 |
|
| 11213 |
when Aspect_Iterable => |
| 11214 |
T := Entity (ASN); |
| 11215 |
|
| 11216 |
if Nkind (Expression (ASN)) /= N_Aggregate then |
| 11217 |
pragma Assert (Serious_Errors_Detected > 0); |
| 11218 |
return; |
| 11219 |
end if; |
| 11220 |
|
| 11221 |
declare |
| 11222 |
Cursor : constant Entity_Id := Get_Cursor_Type (ASN, T); |
| 11223 |
Assoc : Node_Id; |
| 11224 |
Expr : Node_Id; |
| 11225 |
|
| 11226 |
begin |
| 11227 |
if Cursor = Any_Type then |
| 11228 |
return; |
| 11229 |
end if; |
| 11230 |
|
| 11231 |
Assoc := First (Component_Associations (Expression (ASN))); |
| 11232 |
while Present (Assoc) loop |
| 11233 |
Expr := Expression (Assoc); |
| 11234 |
Analyze (Expr); |
| 11235 |
|
| 11236 |
if not Error_Posted (Expr) then |
| 11237 |
Resolve_Iterable_Operation |
| 11238 |
(Expr, Cursor, T, Chars (First (Choices (Assoc)))); |
| 11239 |
end if; |
| 11240 |
|
| 11241 |
Next (Assoc); |
| 11242 |
end loop; |
| 11243 |
end; |
| 11244 |
|
| 11245 |
return; |
| 11246 |
|
| 11247 |
when Aspect_Aggregate => |
| 11248 |
|
| 11249 |
-- If the aspect is not Comes_From_Source, then it's |
| 11250 |
-- an inherited aspect, in which case the aspect's |
| 11251 |
-- operations have already been set and there's no need |
| 11252 |
-- to resolve it. |
| 11253 |
|
| 11254 |
-- Is it even necessary to be calling Resolve_Aspect_Aggr here??? |
| 11255 |
|
| 11256 |
if Comes_From_Source (ASN) then |
| 11257 |
Resolve_Aspect_Aggregate (Entity (ASN), Expression (ASN)); |
| 11258 |
end if; |
| 11259 |
|
| 11260 |
return; |
| 11261 |
|
| 11262 |
when Aspect_Stable_Properties => |
| 11263 |
Resolve_Aspect_Stable_Properties |
| 11264 |
(Entity (ASN), Expression (ASN), |
| 11265 |
Class_Present => Class_Present (ASN)); |
| 11266 |
return; |
| 11267 |
|
| 11268 |
-- Invariant/Predicate take boolean expressions |
| 11269 |
|
| 11270 |
when Aspect_Dynamic_Predicate |
| 11271 |
| Aspect_Invariant |
| 11272 |
| Aspect_Ghost_Predicate |
| 11273 |
| Aspect_Predicate |
| 11274 |
| Aspect_Static_Predicate |
| 11275 |
| Aspect_Type_Invariant |
| 11276 |
=> |
| 11277 |
T := Standard_Boolean; |
| 11278 |
|
| 11279 |
when Aspect_Predicate_Failure => |
| 11280 |
T := Standard_String; |
| 11281 |
|
| 11282 |
-- As for some other aspects above, the expression of this aspect is |
| 11283 |
-- just an entity that does not need any resolution, so just analyze. |
| 11284 |
|
| 11285 |
when Aspect_Designated_Storage_Model => |
| 11286 |
Analyze (Expression (ASN)); |
| 11287 |
return; |
| 11288 |
|
| 11289 |
when Aspect_Storage_Model_Type => |
| 11290 |
|
| 11291 |
-- The aggregate argument of Storage_Model_Type is optional, and |
| 11292 |
-- when not present the aspect defaults to the native storage |
| 11293 |
-- model (where the address type is System.Address, and other |
| 11294 |
-- arguments default to corresponding native storage operations). |
| 11295 |
|
| 11296 |
if No (Expression (ASN)) then |
| 11297 |
return; |
| 11298 |
end if; |
| 11299 |
|
| 11300 |
T := Entity (ASN); |
| 11301 |
|
| 11302 |
declare |
| 11303 |
Assoc : Node_Id; |
| 11304 |
Expr : Node_Id; |
| 11305 |
Addr_Type : Entity_Id := Empty; |
| 11306 |
|
| 11307 |
begin |
| 11308 |
Assoc := First (Component_Associations (Expression (ASN))); |
| 11309 |
while Present (Assoc) loop |
| 11310 |
Expr := Expression (Assoc); |
| 11311 |
Analyze (Expr); |
| 11312 |
|
| 11313 |
if not Error_Posted (Expr) then |
| 11314 |
Resolve_Storage_Model_Type_Argument |
| 11315 |
(Expr, T, Addr_Type, Chars (First (Choices (Assoc)))); |
| 11316 |
end if; |
| 11317 |
|
| 11318 |
Next (Assoc); |
| 11319 |
end loop; |
| 11320 |
end; |
| 11321 |
|
| 11322 |
return; |
| 11323 |
|
| 11324 |
-- Here is the list of aspects that don't require delay analysis |
| 11325 |
|
| 11326 |
when Aspect_Abstract_State |
| 11327 |
| Aspect_Annotate |
| 11328 |
| Aspect_Contract_Cases |
| 11329 |
| Aspect_Default_Initial_Condition |
| 11330 |
| Aspect_Depends |
| 11331 |
| Aspect_Dimension |
| 11332 |
| Aspect_Dimension_System |
| 11333 |
| Aspect_Exceptional_Cases |
| 11334 |
| Aspect_Exit_Cases |
| 11335 |
| Aspect_External_Initialization |
| 11336 |
| Aspect_Global |
| 11337 |
| Aspect_GNAT_Annotate |
| 11338 |
| Aspect_Implicit_Dereference |
| 11339 |
| Aspect_Initial_Condition |
| 11340 |
| Aspect_Initializes |
| 11341 |
| Aspect_Max_Entry_Queue_Length |
| 11342 |
| Aspect_Max_Queue_Length |
| 11343 |
| Aspect_Obsolescent |
| 11344 |
| Aspect_Part_Of |
| 11345 |
| Aspect_Post |
| 11346 |
| Aspect_Postcondition |
| 11347 |
| Aspect_Pre |
| 11348 |
| Aspect_Precondition |
| 11349 |
| Aspect_Refined_Depends |
| 11350 |
| Aspect_Refined_Global |
| 11351 |
| Aspect_Refined_Post |
| 11352 |
| Aspect_Refined_State |
| 11353 |
| Aspect_Relaxed_Initialization |
| 11354 |
| Aspect_SPARK_Mode |
| 11355 |
| Aspect_Subprogram_Variant |
| 11356 |
| Aspect_Suppress |
| 11357 |
| Aspect_Test_Case |
| 11358 |
| Aspect_Unimplemented |
| 11359 |
| Aspect_Unsuppress |
| 11360 |
| Aspect_User_Aspect |
| 11361 |
=> |
| 11362 |
raise Program_Error; |
| 11363 |
|
| 11364 |
end case; |
| 11365 |
|
| 11366 |
-- Do the preanalyze call |
| 11367 |
|
| 11368 |
-- The expression must be analyzed in the special manner described in |
| 11369 |
-- "Handling of Default and Per-Object Expressions" in sem.ads, since |
| 11370 |
-- at the freezing point of the entity associated with an aspect |
| 11371 |
-- specification, any static expressions expressions or names within |
| 11372 |
-- the aspect_specification cause freezing (RM 13.14(7.2/5)). |
| 11373 |
|
| 11374 |
if Present (Expression (ASN)) then |
| 11375 |
Preanalyze_Spec_Expression (Expression (ASN), T); |
| 11376 |
end if; |
| 11377 |
end Check_Aspect_At_Freeze_Point; |
| 11378 |
|
| 11379 |
--------------------------- |
| 11380 |
-- Check_Aspect_Too_Late -- |
| 11381 |
--------------------------- |
| 11382 |
|
| 11383 |
procedure Check_Aspect_Too_Late (N : Node_Id) is |
| 11384 |
Typ : constant Entity_Id := Entity (N); |
| 11385 |
Expr : constant Node_Id := Expression (N); |
| 11386 |
|
| 11387 |
function Find_Type_Reference |
| 11388 |
(Typ : Entity_Id; Expr : Node_Id) return Boolean; |
| 11389 |
-- Return True if a reference to type Typ is found in the expression |
| 11390 |
-- Expr. |
| 11391 |
|
| 11392 |
------------------------- |
| 11393 |
-- Find_Type_Reference -- |
| 11394 |
------------------------- |
| 11395 |
|
| 11396 |
function Find_Type_Reference |
| 11397 |
(Typ : Entity_Id; Expr : Node_Id) return Boolean |
| 11398 |
is |
| 11399 |
function Find_Type (N : Node_Id) return Traverse_Result; |
| 11400 |
-- Set Found to True if N refers to Typ |
| 11401 |
|
| 11402 |
--------------- |
| 11403 |
-- Find_Type -- |
| 11404 |
--------------- |
| 11405 |
|
| 11406 |
function Find_Type (N : Node_Id) return Traverse_Result is |
| 11407 |
begin |
| 11408 |
if N = Typ |
| 11409 |
or else (Nkind (N) in N_Identifier | N_Expanded_Name |
| 11410 |
and then Present (Entity (N)) |
| 11411 |
and then Entity (N) = Typ) |
| 11412 |
then |
| 11413 |
return Abandon; |
| 11414 |
else |
| 11415 |
return OK; |
| 11416 |
end if; |
| 11417 |
end Find_Type; |
| 11418 |
|
| 11419 |
function Search_Type_Reference is new Traverse_Func (Find_Type); |
| 11420 |
|
| 11421 |
begin |
| 11422 |
return Search_Type_Reference (Expr) = Abandon; |
| 11423 |
end Find_Type_Reference; |
| 11424 |
|
| 11425 |
Parent_Type : Entity_Id; |
| 11426 |
|
| 11427 |
Save_In_Spec_Expression : constant Boolean := In_Spec_Expression; |
| 11428 |
Save_Must_Not_Freeze : constant Boolean := Must_Not_Freeze (Expr); |
| 11429 |
|
| 11430 |
begin |
| 11431 |
-- Ensure Expr is analyzed so that e.g. all types are properly |
| 11432 |
-- resolved for Find_Type_Reference. We preanalyze this expression |
| 11433 |
-- (to avoid expansion), handle it as a spec expression (like default |
| 11434 |
-- expression), disable freezing and skip resolution (to not fold |
| 11435 |
-- type self-references, e.g. T'Last). |
| 11436 |
|
| 11437 |
In_Spec_Expression := True; |
| 11438 |
Set_Must_Not_Freeze (Expr); |
| 11439 |
|
| 11440 |
Preanalyze (Expr); |
| 11441 |
|
| 11442 |
Set_Must_Not_Freeze (Expr, Save_Must_Not_Freeze); |
| 11443 |
In_Spec_Expression := Save_In_Spec_Expression; |
| 11444 |
|
| 11445 |
-- A self-referential aspect is illegal if it forces freezing the |
| 11446 |
-- entity before the corresponding aspect has been analyzed. |
| 11447 |
|
| 11448 |
if Find_Type_Reference (Typ, Expr) then |
| 11449 |
Error_Msg_NE |
| 11450 |
("aspect specification causes premature freezing of&", N, Typ); |
| 11451 |
end if; |
| 11452 |
|
| 11453 |
-- For representation aspects, check for case of untagged derived |
| 11454 |
-- type whose parent either has primitive operations (pre Ada 2022), |
| 11455 |
-- or is a by-reference type (RM 13.1(10)). |
| 11456 |
-- Strictly speaking the check also applies to Ada 2012 but it is |
| 11457 |
-- really too constraining for existing code already, so relax it. |
| 11458 |
-- ??? Confirming aspects should be allowed here. |
| 11459 |
|
| 11460 |
if Is_Representation_Aspect (Get_Aspect_Id (N)) |
| 11461 |
and then Is_Derived_Type (Typ) |
| 11462 |
and then not Is_Tagged_Type (Typ) |
| 11463 |
then |
| 11464 |
Parent_Type := Etype (Base_Type (Typ)); |
| 11465 |
|
| 11466 |
if Ada_Version <= Ada_2012 |
| 11467 |
and then Has_Primitive_Operations (Parent_Type) |
| 11468 |
then |
| 11469 |
Error_Msg_N |
| 11470 |
("|representation aspect not permitted before Ada 2022: " & |
| 11471 |
"use -gnat2022!", N); |
| 11472 |
Error_Msg_NE |
| 11473 |
("\parent type & has primitive operations!", N, Parent_Type); |
| 11474 |
|
| 11475 |
elsif Is_By_Reference_Type (Parent_Type) then |
| 11476 |
No_Type_Rep_Item (N); |
| 11477 |
Error_Msg_NE |
| 11478 |
("\parent type & is a by-reference type!", N, Parent_Type); |
| 11479 |
end if; |
| 11480 |
end if; |
| 11481 |
end Check_Aspect_Too_Late; |
| 11482 |
|
| 11483 |
----------------------------------- |
| 11484 |
-- Check_Constant_Address_Clause -- |
| 11485 |
----------------------------------- |
| 11486 |
|
| 11487 |
procedure Check_Constant_Address_Clause |
| 11488 |
(Expr : Node_Id; |
| 11489 |
U_Ent : Entity_Id) |
| 11490 |
is |
| 11491 |
procedure Check_At_Constant_Address (Nod : Node_Id); |
| 11492 |
-- Checks that the given node N represents a name whose 'Address is |
| 11493 |
-- constant (in the same sense as OK_Constant_Address_Clause, i.e. the |
| 11494 |
-- address value is the same at the point of declaration of U_Ent and at |
| 11495 |
-- the time of elaboration of the address clause. |
| 11496 |
|
| 11497 |
procedure Check_Expr_Constants (Nod : Node_Id); |
| 11498 |
-- Checks that Nod meets the requirements for a constant address clause |
| 11499 |
-- in the sense of the enclosing procedure. |
| 11500 |
|
| 11501 |
procedure Check_List_Constants (Lst : List_Id); |
| 11502 |
-- Check that all elements of list Lst meet the requirements for a |
| 11503 |
-- constant address clause in the sense of the enclosing procedure. |
| 11504 |
|
| 11505 |
------------------------------- |
| 11506 |
-- Check_At_Constant_Address -- |
| 11507 |
------------------------------- |
| 11508 |
|
| 11509 |
procedure Check_At_Constant_Address (Nod : Node_Id) is |
| 11510 |
begin |
| 11511 |
if Is_Entity_Name (Nod) then |
| 11512 |
if Present (Address_Clause (Entity ((Nod)))) then |
| 11513 |
Error_Msg_NE |
| 11514 |
("invalid address clause for initialized object &!", |
| 11515 |
Nod, U_Ent); |
| 11516 |
Error_Msg_NE |
| 11517 |
("address for& cannot depend on another address clause! " |
| 11518 |
& "(RM 13.1(22))!", Nod, U_Ent); |
| 11519 |
|
| 11520 |
elsif In_Same_Source_Unit (Entity (Nod), U_Ent) |
| 11521 |
and then Sloc (U_Ent) < Sloc (Entity (Nod)) |
| 11522 |
then |
| 11523 |
Error_Msg_NE |
| 11524 |
("invalid address clause for initialized object &!", |
| 11525 |
Nod, U_Ent); |
| 11526 |
Error_Msg_Node_2 := U_Ent; |
| 11527 |
Error_Msg_NE |
| 11528 |
("\& must be defined before & (RM 13.1(22))!", |
| 11529 |
Nod, Entity (Nod)); |
| 11530 |
end if; |
| 11531 |
|
| 11532 |
elsif Nkind (Nod) = N_Selected_Component then |
| 11533 |
declare |
| 11534 |
T : constant Entity_Id := Etype (Prefix (Nod)); |
| 11535 |
|
| 11536 |
begin |
| 11537 |
if (Is_Record_Type (T) |
| 11538 |
and then Has_Discriminants (T)) |
| 11539 |
or else |
| 11540 |
(Is_Access_Type (T) |
| 11541 |
and then Is_Record_Type (Designated_Type (T)) |
| 11542 |
and then Has_Discriminants (Designated_Type (T))) |
| 11543 |
then |
| 11544 |
Error_Msg_NE |
| 11545 |
("invalid address clause for initialized object &!", |
| 11546 |
Nod, U_Ent); |
| 11547 |
Error_Msg_N |
| 11548 |
("\address cannot depend on component of discriminated " |
| 11549 |
& "record (RM 13.1(22))!", Nod); |
| 11550 |
else |
| 11551 |
Check_At_Constant_Address (Prefix (Nod)); |
| 11552 |
end if; |
| 11553 |
end; |
| 11554 |
|
| 11555 |
elsif Nkind (Nod) = N_Indexed_Component then |
| 11556 |
Check_At_Constant_Address (Prefix (Nod)); |
| 11557 |
Check_List_Constants (Expressions (Nod)); |
| 11558 |
|
| 11559 |
else |
| 11560 |
Check_Expr_Constants (Nod); |
| 11561 |
end if; |
| 11562 |
end Check_At_Constant_Address; |
| 11563 |
|
| 11564 |
-------------------------- |
| 11565 |
-- Check_Expr_Constants -- |
| 11566 |
-------------------------- |
| 11567 |
|
| 11568 |
procedure Check_Expr_Constants (Nod : Node_Id) is |
| 11569 |
Loc_U_Ent : constant Source_Ptr := Sloc (U_Ent); |
| 11570 |
Ent : Entity_Id := Empty; |
| 11571 |
|
| 11572 |
begin |
| 11573 |
if Nkind (Nod) in N_Has_Etype |
| 11574 |
and then Etype (Nod) = Any_Type |
| 11575 |
then |
| 11576 |
return; |
| 11577 |
end if; |
| 11578 |
|
| 11579 |
case Nkind (Nod) is |
| 11580 |
when N_Empty |
| 11581 |
| N_Error |
| 11582 |
=> |
| 11583 |
return; |
| 11584 |
|
| 11585 |
when N_Expanded_Name |
| 11586 |
| N_Identifier |
| 11587 |
=> |
| 11588 |
Ent := Entity (Nod); |
| 11589 |
|
| 11590 |
-- We need to look at the original node if it is different |
| 11591 |
-- from the node, since we may have rewritten things and |
| 11592 |
-- substituted an identifier representing the rewrite. |
| 11593 |
|
| 11594 |
if Is_Rewrite_Substitution (Nod) then |
| 11595 |
Check_Expr_Constants (Original_Node (Nod)); |
| 11596 |
|
| 11597 |
-- If the node is an object declaration without initial |
| 11598 |
-- value, some code has been expanded, and the expression |
| 11599 |
-- is not constant, even if the constituents might be |
| 11600 |
-- acceptable, as in A'Address + offset. |
| 11601 |
|
| 11602 |
if Ekind (Ent) = E_Variable |
| 11603 |
and then |
| 11604 |
Nkind (Declaration_Node (Ent)) = N_Object_Declaration |
| 11605 |
and then |
| 11606 |
No (Expression (Declaration_Node (Ent))) |
| 11607 |
then |
| 11608 |
Error_Msg_NE |
| 11609 |
("invalid address clause for initialized object &!", |
| 11610 |
Nod, U_Ent); |
| 11611 |
|
| 11612 |
-- If entity is constant, it may be the result of expanding |
| 11613 |
-- a check. We must verify that its declaration appears |
| 11614 |
-- before the object in question, else we also reject the |
| 11615 |
-- address clause. |
| 11616 |
|
| 11617 |
elsif Ekind (Ent) = E_Constant |
| 11618 |
and then In_Same_Source_Unit (Ent, U_Ent) |
| 11619 |
and then Sloc (Ent) > Loc_U_Ent |
| 11620 |
then |
| 11621 |
Error_Msg_NE |
| 11622 |
("invalid address clause for initialized object &!", |
| 11623 |
Nod, U_Ent); |
| 11624 |
end if; |
| 11625 |
|
| 11626 |
return; |
| 11627 |
end if; |
| 11628 |
|
| 11629 |
-- Otherwise look at the identifier and see if it is OK |
| 11630 |
|
| 11631 |
if Is_Named_Number (Ent) or else Is_Type (Ent) then |
| 11632 |
return; |
| 11633 |
|
| 11634 |
elsif Ekind (Ent) in E_Constant | E_In_Parameter then |
| 11635 |
|
| 11636 |
-- This is the case where we must have Ent defined before |
| 11637 |
-- U_Ent. Clearly if they are in different units this |
| 11638 |
-- requirement is met since the unit containing Ent is |
| 11639 |
-- already processed. |
| 11640 |
|
| 11641 |
if not In_Same_Source_Unit (Ent, U_Ent) then |
| 11642 |
return; |
| 11643 |
|
| 11644 |
-- Otherwise location of Ent must be before the location |
| 11645 |
-- of U_Ent, that's what prior defined means. |
| 11646 |
|
| 11647 |
elsif Sloc (Ent) < Loc_U_Ent then |
| 11648 |
return; |
| 11649 |
|
| 11650 |
else |
| 11651 |
Error_Msg_NE |
| 11652 |
("invalid address clause for initialized object &!", |
| 11653 |
Nod, U_Ent); |
| 11654 |
Error_Msg_Node_2 := U_Ent; |
| 11655 |
Error_Msg_NE |
| 11656 |
("\& must be defined before & (RM 13.1(22))!", |
| 11657 |
Nod, Ent); |
| 11658 |
end if; |
| 11659 |
|
| 11660 |
elsif Nkind (Original_Node (Nod)) = N_Function_Call then |
| 11661 |
Check_Expr_Constants (Original_Node (Nod)); |
| 11662 |
|
| 11663 |
else |
| 11664 |
Error_Msg_NE |
| 11665 |
("invalid address clause for initialized object &!", |
| 11666 |
Nod, U_Ent); |
| 11667 |
|
| 11668 |
if Comes_From_Source (Ent) then |
| 11669 |
Error_Msg_NE |
| 11670 |
("\reference to variable& not allowed" |
| 11671 |
& " (RM 13.1(22))!", Nod, Ent); |
| 11672 |
else |
| 11673 |
Error_Msg_N |
| 11674 |
("non-static expression not allowed" |
| 11675 |
& " (RM 13.1(22))!", Nod); |
| 11676 |
end if; |
| 11677 |
end if; |
| 11678 |
|
| 11679 |
when N_Integer_Literal => |
| 11680 |
|
| 11681 |
-- If this is a rewritten unchecked conversion, in a system |
| 11682 |
-- where Address is an integer type, always use the base type |
| 11683 |
-- for a literal value. This is user-friendly and prevents |
| 11684 |
-- order-of-elaboration issues with instances of unchecked |
| 11685 |
-- conversion. |
| 11686 |
|
| 11687 |
if Nkind (Original_Node (Nod)) = N_Function_Call then |
| 11688 |
Set_Etype (Nod, Base_Type (Etype (Nod))); |
| 11689 |
end if; |
| 11690 |
|
| 11691 |
when N_Character_Literal |
| 11692 |
| N_Real_Literal |
| 11693 |
| N_String_Literal |
| 11694 |
=> |
| 11695 |
return; |
| 11696 |
|
| 11697 |
when N_Range => |
| 11698 |
Check_Expr_Constants (Low_Bound (Nod)); |
| 11699 |
Check_Expr_Constants (High_Bound (Nod)); |
| 11700 |
|
| 11701 |
when N_Explicit_Dereference => |
| 11702 |
Check_Expr_Constants (Prefix (Nod)); |
| 11703 |
|
| 11704 |
when N_Indexed_Component => |
| 11705 |
Check_Expr_Constants (Prefix (Nod)); |
| 11706 |
Check_List_Constants (Expressions (Nod)); |
| 11707 |
|
| 11708 |
when N_Slice => |
| 11709 |
Check_Expr_Constants (Prefix (Nod)); |
| 11710 |
Check_Expr_Constants (Discrete_Range (Nod)); |
| 11711 |
|
| 11712 |
when N_Selected_Component => |
| 11713 |
Check_Expr_Constants (Prefix (Nod)); |
| 11714 |
|
| 11715 |
when N_Attribute_Reference => |
| 11716 |
if Attribute_Name (Nod) in Name_Address |
| 11717 |
| Name_Access |
| 11718 |
| Name_Unchecked_Access |
| 11719 |
| Name_Unrestricted_Access |
| 11720 |
then |
| 11721 |
Check_At_Constant_Address (Prefix (Nod)); |
| 11722 |
|
| 11723 |
-- Normally, System'To_Address will have been transformed into |
| 11724 |
-- an Unchecked_Conversion, but in -gnatc mode, it will not, |
| 11725 |
-- and we don't want to give an error, because the whole point |
| 11726 |
-- of 'To_Address is that it is static. |
| 11727 |
|
| 11728 |
elsif Attribute_Name (Nod) = Name_To_Address then |
| 11729 |
pragma Assert (Operating_Mode = Check_Semantics); |
| 11730 |
null; |
| 11731 |
|
| 11732 |
else |
| 11733 |
Check_Expr_Constants (Prefix (Nod)); |
| 11734 |
Check_List_Constants (Expressions (Nod)); |
| 11735 |
end if; |
| 11736 |
|
| 11737 |
when N_Aggregate => |
| 11738 |
Check_List_Constants (Component_Associations (Nod)); |
| 11739 |
Check_List_Constants (Expressions (Nod)); |
| 11740 |
|
| 11741 |
when N_Component_Association => |
| 11742 |
Check_Expr_Constants (Expression (Nod)); |
| 11743 |
|
| 11744 |
when N_Extension_Aggregate => |
| 11745 |
Check_Expr_Constants (Ancestor_Part (Nod)); |
| 11746 |
Check_List_Constants (Component_Associations (Nod)); |
| 11747 |
Check_List_Constants (Expressions (Nod)); |
| 11748 |
|
| 11749 |
when N_Null => |
| 11750 |
return; |
| 11751 |
|
| 11752 |
when N_Binary_Op |
| 11753 |
| N_Membership_Test |
| 11754 |
| N_Short_Circuit |
| 11755 |
=> |
| 11756 |
Check_Expr_Constants (Left_Opnd (Nod)); |
| 11757 |
Check_Expr_Constants (Right_Opnd (Nod)); |
| 11758 |
|
| 11759 |
when N_Unary_Op => |
| 11760 |
Check_Expr_Constants (Right_Opnd (Nod)); |
| 11761 |
|
| 11762 |
when N_Allocator |
| 11763 |
| N_Qualified_Expression |
| 11764 |
| N_Type_Conversion |
| 11765 |
| N_Unchecked_Type_Conversion |
| 11766 |
=> |
| 11767 |
Check_Expr_Constants (Expression (Nod)); |
| 11768 |
|
| 11769 |
when N_Function_Call => |
| 11770 |
if not Is_Pure (Entity (Name (Nod))) then |
| 11771 |
Error_Msg_NE |
| 11772 |
("invalid address clause for initialized object &!", |
| 11773 |
Nod, U_Ent); |
| 11774 |
|
| 11775 |
Error_Msg_NE |
| 11776 |
("\function & is not pure (RM 13.1(22))!", |
| 11777 |
Nod, Entity (Name (Nod))); |
| 11778 |
|
| 11779 |
else |
| 11780 |
Check_List_Constants (Parameter_Associations (Nod)); |
| 11781 |
end if; |
| 11782 |
|
| 11783 |
when N_Parameter_Association => |
| 11784 |
Check_Expr_Constants (Explicit_Actual_Parameter (Nod)); |
| 11785 |
|
| 11786 |
when others => |
| 11787 |
Error_Msg_NE |
| 11788 |
("invalid address clause for initialized object &!", |
| 11789 |
Nod, U_Ent); |
| 11790 |
Error_Msg_NE |
| 11791 |
("\must be constant defined before& (RM 13.1(22))!", |
| 11792 |
Nod, U_Ent); |
| 11793 |
end case; |
| 11794 |
end Check_Expr_Constants; |
| 11795 |
|
| 11796 |
-------------------------- |
| 11797 |
-- Check_List_Constants -- |
| 11798 |
-------------------------- |
| 11799 |
|
| 11800 |
procedure Check_List_Constants (Lst : List_Id) is |
| 11801 |
Nod1 : Node_Id; |
| 11802 |
|
| 11803 |
begin |
| 11804 |
Nod1 := First (Lst); |
| 11805 |
while Present (Nod1) loop |
| 11806 |
Check_Expr_Constants (Nod1); |
| 11807 |
Next (Nod1); |
| 11808 |
end loop; |
| 11809 |
end Check_List_Constants; |
| 11810 |
|
| 11811 |
-- Start of processing for Check_Constant_Address_Clause |
| 11812 |
|
| 11813 |
begin |
| 11814 |
-- If rep_clauses are to be ignored, no need for legality checks. In |
| 11815 |
-- particular, no need to pester user about rep clauses that violate the |
| 11816 |
-- rule on constant addresses, given that these clauses will be removed |
| 11817 |
-- by Freeze before they reach the back end. Similarly in CodePeer mode, |
| 11818 |
-- we want to relax these checks. |
| 11819 |
|
| 11820 |
if not Ignore_Rep_Clauses and not CodePeer_Mode then |
| 11821 |
Check_Expr_Constants (Expr); |
| 11822 |
end if; |
| 11823 |
end Check_Constant_Address_Clause; |
| 11824 |
|
| 11825 |
---------------------------------------- |
| 11826 |
-- Check_Function_For_Indexing_Aspect -- |
| 11827 |
---------------------------------------- |
| 11828 |
|
| 11829 |
procedure Check_Function_For_Indexing_Aspect |
| 11830 |
(ASN : Node_Id; |
| 11831 |
Typ : Entity_Id; |
| 11832 |
Subp : Entity_Id; |
| 11833 |
Valid : out Boolean) |
| 11834 |
is |
| 11835 |
Aspect : constant Aspect_Id := Get_Aspect_Id (ASN); |
| 11836 |
|
| 11837 |
procedure Illegal_Indexing (Msg : String); |
| 11838 |
-- Report error on illegal candidate for indexing function |
| 11839 |
|
| 11840 |
function Is_CW_Or_Access_To_CW |
| 11841 |
(Param_Type : Entity_Id; |
| 11842 |
Specific_Type : Entity_Id) return Boolean; |
| 11843 |
-- Is Param_Type either Specific_Type'Class or an anonymous |
| 11844 |
-- access-to-Specific_Type'Class type? |
| 11845 |
|
| 11846 |
function Look_Through_Anon_Access (Typ : Entity_Id) return Entity_Id; |
| 11847 |
-- For an appropriate access type, return designated type; |
| 11848 |
-- otherwise return argument. |
| 11849 |
|
| 11850 |
function Subp_Is_Dispatching_Op_Of_Typ |
| 11851 |
(Subp : Entity_Id; |
| 11852 |
Typ : Entity_Id) return Boolean; |
| 11853 |
-- Is subprogram Subp is a dispatching operation of type Typ? |
| 11854 |
|
| 11855 |
---------------------- |
| 11856 |
-- Illegal_Indexing -- |
| 11857 |
---------------------- |
| 11858 |
|
| 11859 |
-- NOTE: If the semantics of indexing aspects are ever changed |
| 11860 |
-- to be treated like resolution rules instead of legality rules, |
| 11861 |
-- then this procedure could be modified to only issue the error |
| 11862 |
-- if an appropriate function has not yet been found and there are |
| 11863 |
-- no further operations yet to be considered as interpretations |
| 11864 |
-- (i.e., return immediately without a message if Indexing_Found |
| 11865 |
-- or no further candidate functions are yet to be considered). |
| 11866 |
|
| 11867 |
procedure Illegal_Indexing (Msg : String) is |
| 11868 |
begin |
| 11869 |
Error_Msg_NE (Msg, ASN, Typ); |
| 11870 |
end Illegal_Indexing; |
| 11871 |
|
| 11872 |
--------------------------- |
| 11873 |
-- Is_CW_Or_Access_To_CW -- |
| 11874 |
--------------------------- |
| 11875 |
|
| 11876 |
function Is_CW_Or_Access_To_CW |
| 11877 |
(Param_Type : Entity_Id; |
| 11878 |
Specific_Type : Entity_Id) return Boolean |
| 11879 |
is |
| 11880 |
Typ : constant Entity_Id := |
| 11881 |
Look_Through_Anon_Access (Param_Type); |
| 11882 |
|
| 11883 |
Aspect_Specification_Is_Inherited : constant Boolean := |
| 11884 |
Is_Derived_Type (Specific_Type) |
| 11885 |
and then Has_Aspect (Etype (Specific_Type), Aspect); |
| 11886 |
begin |
| 11887 |
if not Is_Class_Wide_Type (Typ) then |
| 11888 |
return False; |
| 11889 |
end if; |
| 11890 |
|
| 11891 |
declare |
| 11892 |
Specific_1 : constant Entity_Id := |
| 11893 |
Implementation_Base_Type (Find_Specific_Type (Typ)); |
| 11894 |
Specific_2 : constant Entity_Id := |
| 11895 |
Implementation_Base_Type (Specific_Type); |
| 11896 |
begin |
| 11897 |
if Aspect_Specification_Is_Inherited then |
| 11898 |
return Is_Ancestor (T1 => Specific_1, T2 => Specific_2); |
| 11899 |
else |
| 11900 |
return Specific_1 = Specific_2; |
| 11901 |
end if; |
| 11902 |
end; |
| 11903 |
end Is_CW_Or_Access_To_CW; |
| 11904 |
|
| 11905 |
------------------------------ |
| 11906 |
-- Look_Through_Anon_Access -- |
| 11907 |
------------------------------ |
| 11908 |
|
| 11909 |
function Look_Through_Anon_Access |
| 11910 |
(Typ : Entity_Id) return Entity_Id |
| 11911 |
is |
| 11912 |
Result : Entity_Id := Typ; |
| 11913 |
begin |
| 11914 |
if Is_Anonymous_Access_Type (Typ) |
| 11915 |
and then Is_Access_Object_Type (Typ) |
| 11916 |
then |
| 11917 |
Result := Designated_Type (Typ); |
| 11918 |
end if; |
| 11919 |
|
| 11920 |
return Implementation_Base_Type (Result); |
| 11921 |
end Look_Through_Anon_Access; |
| 11922 |
|
| 11923 |
----------------------------------- |
| 11924 |
-- Subp_Is_Dispatching_Op_Of_Typ -- |
| 11925 |
----------------------------------- |
| 11926 |
|
| 11927 |
function Subp_Is_Dispatching_Op_Of_Typ |
| 11928 |
(Subp : Entity_Id; Typ : Entity_Id) return Boolean |
| 11929 |
is |
| 11930 |
Base_Typ : constant Entity_Id := |
| 11931 |
Implementation_Base_Type (Typ); |
| 11932 |
Dispatching_Type : Entity_Id := Find_Dispatching_Type (Subp); |
| 11933 |
begin |
| 11934 |
if No (Dispatching_Type) then |
| 11935 |
return False; |
| 11936 |
end if; |
| 11937 |
Dispatching_Type := Implementation_Base_Type (Dispatching_Type); |
| 11938 |
|
| 11939 |
return Base_Typ = Dispatching_Type |
| 11940 |
and then |
| 11941 |
-- test whether first formal is controlling |
| 11942 |
Base_Typ = Look_Through_Anon_Access |
| 11943 |
(Etype (First_Formal (Subp))); |
| 11944 |
end Subp_Is_Dispatching_Op_Of_Typ; |
| 11945 |
|
| 11946 |
-- Local variables |
| 11947 |
|
| 11948 |
Ret_Type : constant Entity_Id := Etype (Subp); |
| 11949 |
|
| 11950 |
-- Start of processing for Check_Function_For_Indexing_Aspect |
| 11951 |
|
| 11952 |
begin |
| 11953 |
Valid := False; |
| 11954 |
|
| 11955 |
-- If the subprogram isn't declared in the same scope as the type |
| 11956 |
-- E, then it shouldn't be considered (see AI22-0084 as well as |
| 11957 |
-- RM 4.1.6(2/5-3/5), though the latter are apparently intended |
| 11958 |
-- as legality rules, not resolution rules). |
| 11959 |
|
| 11960 |
if Scope (Subp) /= Scope (Typ) then |
| 11961 |
return; |
| 11962 |
|
| 11963 |
elsif not Is_Overloadable (Subp) or else No (Ret_Type) then |
| 11964 |
Illegal_Indexing ("illegal indexing function for type&"); |
| 11965 |
return; |
| 11966 |
|
| 11967 |
elsif No (First_Formal (Subp)) then |
| 11968 |
Illegal_Indexing |
| 11969 |
("indexing aspect requires a function that applies to type&"); |
| 11970 |
return; |
| 11971 |
|
| 11972 |
elsif No (Next_Formal (First_Formal (Subp))) then |
| 11973 |
Error_Msg_Sloc := Sloc (Subp); |
| 11974 |
Illegal_Indexing |
| 11975 |
("at least two parameters required for indexing function " |
| 11976 |
& "defined #"); |
| 11977 |
return; |
| 11978 |
|
| 11979 |
elsif not Subp_Is_Dispatching_Op_Of_Typ |
| 11980 |
(Subp => Subp, Typ => Typ) |
| 11981 |
and then not Is_CW_Or_Access_To_CW |
| 11982 |
(Param_Type => Etype (First_Formal (Subp)), |
| 11983 |
Specific_Type => Typ) |
| 11984 |
then |
| 11985 |
Illegal_Indexing |
| 11986 |
("indexing aspect requires function with first formal " |
| 11987 |
& "applying to type& or its class-wide type"); |
| 11988 |
return; |
| 11989 |
|
| 11990 |
elsif Aspect = Aspect_Constant_Indexing |
| 11991 |
and then Is_Anonymous_Access_Type (Etype (First_Formal (Subp))) |
| 11992 |
and then not Is_Access_Constant (Etype (First_Formal (Subp))) |
| 11993 |
then |
| 11994 |
Illegal_Indexing |
| 11995 |
("Constant_Indexing must apply to function with " |
| 11996 |
& "access-to-constant formal"); |
| 11997 |
return; |
| 11998 |
end if; |
| 11999 |
|
| 12000 |
-- For variable_indexing the return type must be a reference type |
| 12001 |
|
| 12002 |
if Aspect = Aspect_Variable_Indexing then |
| 12003 |
if not Has_Implicit_Dereference (Ret_Type) then |
| 12004 |
Illegal_Indexing |
| 12005 |
("function for Variable_Indexing must return " |
| 12006 |
& "a reference type"); |
| 12007 |
return; |
| 12008 |
|
| 12009 |
elsif Is_Access_Constant |
| 12010 |
(Etype (First_Discriminant (Ret_Type))) |
| 12011 |
then |
| 12012 |
Illegal_Indexing |
| 12013 |
("function for Variable_Indexing must return an " |
| 12014 |
& "access-to-variable result"); |
| 12015 |
return; |
| 12016 |
end if; |
| 12017 |
end if; |
| 12018 |
|
| 12019 |
Valid := True; |
| 12020 |
|
| 12021 |
-- Add the acceptable subprogram to the indexing aspect's list |
| 12022 |
-- of subprograms. |
| 12023 |
|
| 12024 |
declare |
| 12025 |
Subp_List : Elist_Id := Aspect_Subprograms (ASN); |
| 12026 |
begin |
| 12027 |
Append_New_Elmt (Subp, Subp_List); |
| 12028 |
Set_Aspect_Subprograms (ASN, Subp_List); |
| 12029 |
end; |
| 12030 |
end Check_Function_For_Indexing_Aspect; |
| 12031 |
|
| 12032 |
------------------------------ |
| 12033 |
-- Check_Iterator_Functions -- |
| 12034 |
------------------------------ |
| 12035 |
|
| 12036 |
procedure Check_Iterator_Functions (Typ : Entity_Id; Expr : Node_Id) is |
| 12037 |
|
| 12038 |
function Valid_Default_Iterator |
| 12039 |
(Subp : Entity_Id; |
| 12040 |
Ref_Node : Node_Id := Empty) return Boolean; |
| 12041 |
-- Check one possible interpretation for validity. If |
| 12042 |
-- Ref_Node is present report errors on violations. |
| 12043 |
|
| 12044 |
---------------------------- |
| 12045 |
-- Valid_Default_Iterator -- |
| 12046 |
---------------------------- |
| 12047 |
|
| 12048 |
function Valid_Default_Iterator |
| 12049 |
(Subp : Entity_Id; |
| 12050 |
Ref_Node : Node_Id := Empty) return Boolean |
| 12051 |
is |
| 12052 |
Return_Type : constant Entity_Id := Etype (Etype (Subp)); |
| 12053 |
Return_Node : Node_Id; |
| 12054 |
Root_T : constant Entity_Id := Root_Type (Return_Type); |
| 12055 |
Formal : Entity_Id; |
| 12056 |
|
| 12057 |
function Valid_Iterator_Name (E : Entity_Id) return Boolean |
| 12058 |
is (Chars (E) in Name_Forward_Iterator | Name_Reversible_Iterator); |
| 12059 |
|
| 12060 |
function Valid_Iterator_Name (L : Elist_Id) return Boolean; |
| 12061 |
|
| 12062 |
------------------------- |
| 12063 |
-- Valid_Iterator_Name -- |
| 12064 |
------------------------- |
| 12065 |
|
| 12066 |
function Valid_Iterator_Name (L : Elist_Id) return Boolean |
| 12067 |
is |
| 12068 |
Iface_Elmt : Elmt_Id := First_Elmt (L); |
| 12069 |
begin |
| 12070 |
while Present (Iface_Elmt) loop |
| 12071 |
if Valid_Iterator_Name (Node (Iface_Elmt)) then |
| 12072 |
return True; |
| 12073 |
end if; |
| 12074 |
Next_Elmt (Iface_Elmt); |
| 12075 |
end loop; |
| 12076 |
|
| 12077 |
return False; |
| 12078 |
end Valid_Iterator_Name; |
| 12079 |
|
| 12080 |
-- Start of processing for Valid_Default_Iterator |
| 12081 |
|
| 12082 |
begin |
| 12083 |
if Subp = Any_Id then |
| 12084 |
if Present (Ref_Node) then |
| 12085 |
|
| 12086 |
-- Subp is not resolved and an error will be posted about |
| 12087 |
-- it later |
| 12088 |
|
| 12089 |
Error_Msg_N ("improper function for default iterator!", |
| 12090 |
Ref_Node); |
| 12091 |
end if; |
| 12092 |
|
| 12093 |
return False; |
| 12094 |
end if; |
| 12095 |
|
| 12096 |
if not Check_Primitive_Function (Subp, Typ) then |
| 12097 |
if Present (Ref_Node) then |
| 12098 |
if Debug_Flag_Underscore_DD then |
| 12099 |
Record_Default_Iterator_Not_Primitive_Error |
| 12100 |
(Ref_Node, Subp); |
| 12101 |
else |
| 12102 |
Error_Msg_N ("improper function for default iterator!", |
| 12103 |
Ref_Node); |
| 12104 |
Error_Msg_Sloc := Sloc (Subp); |
| 12105 |
Error_Msg_NE |
| 12106 |
("\\default iterator defined # " |
| 12107 |
& "must be a local primitive or class-wide function", |
| 12108 |
Ref_Node, Subp); |
| 12109 |
end if; |
| 12110 |
end if; |
| 12111 |
|
| 12112 |
return False; |
| 12113 |
end if; |
| 12114 |
|
| 12115 |
-- The return type must be derived from a type in an instance |
| 12116 |
-- of Iterator.Interfaces, and thus its root type must have a |
| 12117 |
-- predefined name. |
| 12118 |
|
| 12119 |
if not Valid_Iterator_Name (Root_T) |
| 12120 |
and then not (Has_Interfaces (Return_Type) and then |
| 12121 |
Valid_Iterator_Name (Interfaces (Return_Type))) |
| 12122 |
then |
| 12123 |
if Present (Ref_Node) then |
| 12124 |
|
| 12125 |
Return_Node := Result_Definition (Parent (Subp)); |
| 12126 |
|
| 12127 |
Error_Msg_N ("improper function for default iterator!", |
| 12128 |
Ref_Node); |
| 12129 |
Error_Msg_Sloc := Sloc (Return_Node); |
| 12130 |
Error_Msg_NE ("\\return type & # " |
| 12131 |
& "must inherit from either " |
| 12132 |
& "Forward_Iterator or Reversible_Iterator", |
| 12133 |
Ref_Node, Return_Node); |
| 12134 |
end if; |
| 12135 |
|
| 12136 |
return False; |
| 12137 |
end if; |
| 12138 |
|
| 12139 |
Formal := First_Formal (Subp); |
| 12140 |
|
| 12141 |
-- False if any subsequent formal has no default expression |
| 12142 |
|
| 12143 |
Next_Formal (Formal); |
| 12144 |
while Present (Formal) loop |
| 12145 |
if No (Expression (Parent (Formal))) then |
| 12146 |
if Present (Ref_Node) then |
| 12147 |
Error_Msg_N ("improper function for default iterator!", |
| 12148 |
Ref_Node); |
| 12149 |
Error_Msg_Sloc := Sloc (Formal); |
| 12150 |
Error_Msg_NE ("\\formal parameter & # " |
| 12151 |
& "must have a default expression", |
| 12152 |
Ref_Node, Formal); |
| 12153 |
end if; |
| 12154 |
|
| 12155 |
return False; |
| 12156 |
end if; |
| 12157 |
|
| 12158 |
Next_Formal (Formal); |
| 12159 |
end loop; |
| 12160 |
|
| 12161 |
-- True if all subsequent formals have default expressions |
| 12162 |
|
| 12163 |
return True; |
| 12164 |
end Valid_Default_Iterator; |
| 12165 |
|
| 12166 |
Ignore : Boolean; |
| 12167 |
|
| 12168 |
-- Start of processing for Check_Iterator_Functions |
| 12169 |
|
| 12170 |
begin |
| 12171 |
Analyze (Expr); |
| 12172 |
|
| 12173 |
if not Is_Entity_Name (Expr) then |
| 12174 |
Error_Msg_N ("aspect Default_Iterator must be a function name", Expr); |
| 12175 |
end if; |
| 12176 |
|
| 12177 |
if not Is_Overloaded (Expr) then |
| 12178 |
if Entity (Expr) /= Any_Id |
| 12179 |
and then not Check_Primitive_Function (Entity (Expr), Typ) |
| 12180 |
then |
| 12181 |
Error_Msg_NE |
| 12182 |
("aspect Default_Iterator requires a local function applying " |
| 12183 |
& "to type&", Entity (Expr), Typ); |
| 12184 |
end if; |
| 12185 |
|
| 12186 |
-- Flag the default_iterator as well as the denoted function. |
| 12187 |
|
| 12188 |
Ignore := Valid_Default_Iterator (Entity (Expr), Expr); |
| 12189 |
|
| 12190 |
else |
| 12191 |
declare |
| 12192 |
Default : Entity_Id := Empty; |
| 12193 |
I : Interp_Index; |
| 12194 |
It : Interp; |
| 12195 |
|
| 12196 |
begin |
| 12197 |
Get_First_Interp (Expr, I, It); |
| 12198 |
while Present (It.Nam) loop |
| 12199 |
if not Check_Primitive_Function (It.Nam, Typ) |
| 12200 |
or else not Valid_Default_Iterator (It.Nam) |
| 12201 |
then |
| 12202 |
Remove_Interp (I); |
| 12203 |
|
| 12204 |
elsif Present (Default) then |
| 12205 |
|
| 12206 |
-- An explicit one should override an implicit one |
| 12207 |
|
| 12208 |
if Comes_From_Source (Default) = |
| 12209 |
Comes_From_Source (It.Nam) |
| 12210 |
then |
| 12211 |
Error_Msg_N ("default iterator must be unique", Expr); |
| 12212 |
Error_Msg_Sloc := Sloc (Default); |
| 12213 |
Error_Msg_N ("\\possible interpretation#", Expr); |
| 12214 |
Error_Msg_Sloc := Sloc (It.Nam); |
| 12215 |
Error_Msg_N ("\\possible interpretation#", Expr); |
| 12216 |
|
| 12217 |
elsif Comes_From_Source (It.Nam) then |
| 12218 |
Default := It.Nam; |
| 12219 |
end if; |
| 12220 |
else |
| 12221 |
Default := It.Nam; |
| 12222 |
end if; |
| 12223 |
|
| 12224 |
Get_Next_Interp (I, It); |
| 12225 |
end loop; |
| 12226 |
|
| 12227 |
if Present (Default) then |
| 12228 |
Set_Entity (Expr, Default); |
| 12229 |
Set_Is_Overloaded (Expr, False); |
| 12230 |
else |
| 12231 |
Error_Msg_N |
| 12232 |
("no interpretation is a valid default iterator!", Expr); |
| 12233 |
end if; |
| 12234 |
end; |
| 12235 |
end if; |
| 12236 |
end Check_Iterator_Functions; |
| 12237 |
|
| 12238 |
------------------------------- |
| 12239 |
-- Check_Primitive_Function -- |
| 12240 |
------------------------------- |
| 12241 |
|
| 12242 |
function Check_Primitive_Function |
| 12243 |
(Subp : Entity_Id; Ent : Entity_Id) return Boolean |
| 12244 |
is |
| 12245 |
Ctrl : Entity_Id; |
| 12246 |
|
| 12247 |
begin |
| 12248 |
if Ekind (Subp) /= E_Function then |
| 12249 |
return False; |
| 12250 |
end if; |
| 12251 |
|
| 12252 |
if No (First_Formal (Subp)) then |
| 12253 |
return False; |
| 12254 |
else |
| 12255 |
Ctrl := Etype (First_Formal (Subp)); |
| 12256 |
end if; |
| 12257 |
|
| 12258 |
-- To be a primitive operation subprogram has to be in same scope. |
| 12259 |
|
| 12260 |
if Scope (Ctrl) /= Scope (Subp) then |
| 12261 |
return False; |
| 12262 |
end if; |
| 12263 |
|
| 12264 |
-- Type of formal may be the class-wide type, an access to such, |
| 12265 |
-- or an incomplete view. |
| 12266 |
|
| 12267 |
if Ctrl = Ent |
| 12268 |
or else Ctrl = Class_Wide_Type (Ent) |
| 12269 |
or else |
| 12270 |
(Ekind (Ctrl) = E_Anonymous_Access_Type |
| 12271 |
and then (Designated_Type (Ctrl) = Ent |
| 12272 |
or else |
| 12273 |
Designated_Type (Ctrl) = Class_Wide_Type (Ent))) |
| 12274 |
or else |
| 12275 |
(Ekind (Ctrl) = E_Incomplete_Type |
| 12276 |
and then Full_View (Ctrl) = Ent) |
| 12277 |
then |
| 12278 |
null; |
| 12279 |
else |
| 12280 |
return False; |
| 12281 |
end if; |
| 12282 |
|
| 12283 |
return True; |
| 12284 |
end Check_Primitive_Function; |
| 12285 |
|
| 12286 |
--------------------------- |
| 12287 |
-- Check_Pool_Size_Clash -- |
| 12288 |
--------------------------- |
| 12289 |
|
| 12290 |
procedure Check_Pool_Size_Clash (Ent : Entity_Id; SP, SS : Node_Id) is |
| 12291 |
Post : Node_Id; |
| 12292 |
|
| 12293 |
begin |
| 12294 |
-- We need to find out which one came first. Note that in the case of |
| 12295 |
-- aspects mixed with pragmas there are cases where the processing order |
| 12296 |
-- is reversed, which is why we do the check here. |
| 12297 |
|
| 12298 |
if Sloc (SP) < Sloc (SS) then |
| 12299 |
Error_Msg_Sloc := Sloc (SP); |
| 12300 |
Post := SS; |
| 12301 |
Error_Msg_NE ("Storage_Pool previously given for&#", Post, Ent); |
| 12302 |
|
| 12303 |
else |
| 12304 |
Error_Msg_Sloc := Sloc (SS); |
| 12305 |
Post := SP; |
| 12306 |
Error_Msg_NE ("Storage_Size previously given for&#", Post, Ent); |
| 12307 |
end if; |
| 12308 |
|
| 12309 |
Error_Msg_N |
| 12310 |
("\cannot have Storage_Size and Storage_Pool (RM 13.11(3))", Post); |
| 12311 |
end Check_Pool_Size_Clash; |
| 12312 |
|
| 12313 |
---------------------------------------- |
| 12314 |
-- Check_Record_Representation_Clause -- |
| 12315 |
---------------------------------------- |
| 12316 |
|
| 12317 |
procedure Check_Record_Representation_Clause (N : Node_Id) is |
| 12318 |
Loc : constant Source_Ptr := Sloc (N); |
| 12319 |
Ident : constant Node_Id := Identifier (N); |
| 12320 |
Rectype : Entity_Id; |
| 12321 |
Fent : Entity_Id; |
| 12322 |
CC : Node_Id; |
| 12323 |
Fbit : Uint := No_Uint; |
| 12324 |
Lbit : Uint := No_Uint; |
| 12325 |
Hbit : Uint := Uint_0; |
| 12326 |
Comp : Entity_Id; |
| 12327 |
Pcomp : Entity_Id; |
| 12328 |
|
| 12329 |
Max_Bit_So_Far : Uint; |
| 12330 |
-- Records the maximum bit position so far. If all field positions |
| 12331 |
-- are monotonically increasing, then we can skip the circuit for |
| 12332 |
-- checking for overlap, since no overlap is possible. |
| 12333 |
|
| 12334 |
Tagged_Parent : Entity_Id := Empty; |
| 12335 |
-- This is set in the case of an extension for which we have either a |
| 12336 |
-- size clause or Is_Fully_Repped_Tagged_Type True (indicating that all |
| 12337 |
-- components are positioned by record representation clauses) on the |
| 12338 |
-- parent type. In this case we check for overlap between components of |
| 12339 |
-- this tagged type and the parent component. Tagged_Parent will point |
| 12340 |
-- to this parent type. For all other cases, Tagged_Parent is Empty. |
| 12341 |
|
| 12342 |
Parent_Last_Bit : Uint := No_Uint; -- init to avoid warning |
| 12343 |
-- Relevant only if Tagged_Parent is set, Parent_Last_Bit indicates the |
| 12344 |
-- last bit position for any field in the parent type. We only need to |
| 12345 |
-- check overlap for fields starting below this point. |
| 12346 |
|
| 12347 |
Overlap_Check_Required : Boolean; |
| 12348 |
-- Used to keep track of whether or not an overlap check is required |
| 12349 |
|
| 12350 |
Overlap_Detected : Boolean := False; |
| 12351 |
-- Set True if an overlap is detected |
| 12352 |
|
| 12353 |
Ccount : Natural := 0; |
| 12354 |
-- Number of component clauses in record rep clause |
| 12355 |
|
| 12356 |
procedure Check_Component_Overlap (C1_Ent, C2_Ent : Entity_Id); |
| 12357 |
-- Given two entities for record components or discriminants, checks |
| 12358 |
-- if they have overlapping component clauses and issues errors if so. |
| 12359 |
|
| 12360 |
procedure Find_Component; |
| 12361 |
-- Finds component entity corresponding to current component clause (in |
| 12362 |
-- CC), and sets Comp to the entity, and Fbit/Lbit to the zero origin |
| 12363 |
-- start/stop bits for the field. If there is no matching component or |
| 12364 |
-- if the matching component does not have a component clause, then |
| 12365 |
-- that's an error and Comp is set to Empty, but no error message is |
| 12366 |
-- issued, since the message was already given. Comp is also set to |
| 12367 |
-- Empty if the current "component clause" is in fact a pragma. |
| 12368 |
|
| 12369 |
procedure Record_Hole_Check |
| 12370 |
(Rectype : Entity_Id; After_Last : out Uint; Warn : Boolean); |
| 12371 |
-- Checks for gaps in the given Rectype. Compute After_Last, the bit |
| 12372 |
-- number after the last component. Warn is True on the initial call, |
| 12373 |
-- and warnings are given for gaps. For a type extension, this is called |
| 12374 |
-- recursively to compute After_Last on the parent subtype; in this case |
| 12375 |
-- Warn is False and the warnings are suppressed. |
| 12376 |
|
| 12377 |
procedure Component_Order_Check (Rectype : Entity_Id); |
| 12378 |
-- Check that the order of component clauses agrees with the order of |
| 12379 |
-- component declarations, and that the component clauses are given in |
| 12380 |
-- increasing order of bit offset. |
| 12381 |
|
| 12382 |
----------------------------- |
| 12383 |
-- Check_Component_Overlap -- |
| 12384 |
----------------------------- |
| 12385 |
|
| 12386 |
procedure Check_Component_Overlap (C1_Ent, C2_Ent : Entity_Id) is |
| 12387 |
CC1 : constant Node_Id := Component_Clause (C1_Ent); |
| 12388 |
CC2 : constant Node_Id := Component_Clause (C2_Ent); |
| 12389 |
|
| 12390 |
begin |
| 12391 |
if Present (CC1) and then Present (CC2) then |
| 12392 |
|
| 12393 |
-- Exclude odd case where we have two tag components in the same |
| 12394 |
-- record, both at location zero. This seems a bit strange, but |
| 12395 |
-- it seems to happen in some circumstances, perhaps on an error. |
| 12396 |
|
| 12397 |
if Chars (C1_Ent) = Name_uTag then |
| 12398 |
return; |
| 12399 |
end if; |
| 12400 |
|
| 12401 |
-- Here we check if the two fields overlap |
| 12402 |
|
| 12403 |
declare |
| 12404 |
S1 : constant Uint := Component_Bit_Offset (C1_Ent); |
| 12405 |
S2 : constant Uint := Component_Bit_Offset (C2_Ent); |
| 12406 |
E1 : constant Uint := S1 + Esize (C1_Ent); |
| 12407 |
E2 : constant Uint := S2 + Esize (C2_Ent); |
| 12408 |
|
| 12409 |
begin |
| 12410 |
if E2 <= S1 or else E1 <= S2 then |
| 12411 |
null; |
| 12412 |
else |
| 12413 |
Error_Msg_Node_2 := Component_Name (CC2); |
| 12414 |
Error_Msg_Sloc := Sloc (Error_Msg_Node_2); |
| 12415 |
Error_Msg_Node_1 := Component_Name (CC1); |
| 12416 |
Error_Msg_N |
| 12417 |
("component& overlaps & #", Component_Name (CC1)); |
| 12418 |
Overlap_Detected := True; |
| 12419 |
end if; |
| 12420 |
end; |
| 12421 |
end if; |
| 12422 |
end Check_Component_Overlap; |
| 12423 |
|
| 12424 |
--------------------------- |
| 12425 |
-- Component_Order_Check -- |
| 12426 |
--------------------------- |
| 12427 |
|
| 12428 |
procedure Component_Order_Check (Rectype : Entity_Id) is |
| 12429 |
Comp : Entity_Id := First_Component (Rectype); |
| 12430 |
Clause : Node_Id := First (Component_Clauses (N)); |
| 12431 |
Prev_Bit_Offset : Uint := Uint_0; |
| 12432 |
OOO : constant String := |
| 12433 |
"?_r?component clause out of order with respect to declaration"; |
| 12434 |
|
| 12435 |
begin |
| 12436 |
-- Step Comp through components and Clause through component clauses, |
| 12437 |
-- skipping pragmas. We ignore discriminants and variant parts, |
| 12438 |
-- because we get most of the benefit from the plain vanilla |
| 12439 |
-- component cases, without the extra complexity. If we find a Comp |
| 12440 |
-- and Clause that don't match, give a warning on both and quit. If |
| 12441 |
-- we find two subsequent clauses out of order by bit layout, give |
| 12442 |
-- warning and quit. On each iteration, Prev_Bit_Offset is the one |
| 12443 |
-- from the previous iteration (or 0 to start). |
| 12444 |
|
| 12445 |
while Present (Comp) and then Present (Clause) loop |
| 12446 |
if Nkind (Clause) = N_Component_Clause |
| 12447 |
and then Ekind (Entity (Component_Name (Clause))) = E_Component |
| 12448 |
then |
| 12449 |
if Entity (Component_Name (Clause)) /= Comp then |
| 12450 |
Error_Msg_N (OOO, Comp); |
| 12451 |
Error_Msg_N (OOO, Clause); |
| 12452 |
exit; |
| 12453 |
end if; |
| 12454 |
|
| 12455 |
if not Reverse_Bit_Order (Rectype) |
| 12456 |
and then not Reverse_Storage_Order (Rectype) |
| 12457 |
and then Component_Bit_Offset (Comp) < Prev_Bit_Offset |
| 12458 |
then |
| 12459 |
Error_Msg_N ("?_r?memory layout out of order", Clause); |
| 12460 |
exit; |
| 12461 |
end if; |
| 12462 |
|
| 12463 |
Prev_Bit_Offset := Component_Bit_Offset (Comp); |
| 12464 |
Next_Component (Comp); |
| 12465 |
end if; |
| 12466 |
|
| 12467 |
Next (Clause); |
| 12468 |
end loop; |
| 12469 |
end Component_Order_Check; |
| 12470 |
|
| 12471 |
-------------------- |
| 12472 |
-- Find_Component -- |
| 12473 |
-------------------- |
| 12474 |
|
| 12475 |
procedure Find_Component is |
| 12476 |
|
| 12477 |
procedure Search_Component (R : Entity_Id); |
| 12478 |
-- Search components of R for a match. If found, Comp is set |
| 12479 |
|
| 12480 |
---------------------- |
| 12481 |
-- Search_Component -- |
| 12482 |
---------------------- |
| 12483 |
|
| 12484 |
procedure Search_Component (R : Entity_Id) is |
| 12485 |
begin |
| 12486 |
Comp := First_Component_Or_Discriminant (R); |
| 12487 |
while Present (Comp) loop |
| 12488 |
|
| 12489 |
-- Ignore error of attribute name for component name (we |
| 12490 |
-- already gave an error message for this, so no need to |
| 12491 |
-- complain here) |
| 12492 |
|
| 12493 |
if Nkind (Component_Name (CC)) = N_Attribute_Reference then |
| 12494 |
null; |
| 12495 |
else |
| 12496 |
exit when Chars (Comp) = Chars (Component_Name (CC)); |
| 12497 |
end if; |
| 12498 |
|
| 12499 |
Next_Component_Or_Discriminant (Comp); |
| 12500 |
end loop; |
| 12501 |
end Search_Component; |
| 12502 |
|
| 12503 |
-- Start of processing for Find_Component |
| 12504 |
|
| 12505 |
begin |
| 12506 |
-- Return with Comp set to Empty if we have a pragma |
| 12507 |
|
| 12508 |
if Nkind (CC) = N_Pragma then |
| 12509 |
Comp := Empty; |
| 12510 |
return; |
| 12511 |
end if; |
| 12512 |
|
| 12513 |
-- Search current record for matching component |
| 12514 |
|
| 12515 |
Search_Component (Rectype); |
| 12516 |
|
| 12517 |
-- If not found, maybe component of base type discriminant that is |
| 12518 |
-- absent from statically constrained first subtype. |
| 12519 |
|
| 12520 |
if No (Comp) then |
| 12521 |
Search_Component (Base_Type (Rectype)); |
| 12522 |
end if; |
| 12523 |
|
| 12524 |
-- If no component, or the component does not reference the component |
| 12525 |
-- clause in question, then there was some previous error for which |
| 12526 |
-- we already gave a message, so just return with Comp Empty. |
| 12527 |
|
| 12528 |
if No (Comp) or else Component_Clause (Comp) /= CC then |
| 12529 |
Check_Error_Detected; |
| 12530 |
Comp := Empty; |
| 12531 |
|
| 12532 |
-- Normal case where we have a component clause |
| 12533 |
|
| 12534 |
else |
| 12535 |
Fbit := Component_Bit_Offset (Comp); |
| 12536 |
Lbit := Fbit + Esize (Comp) - 1; |
| 12537 |
end if; |
| 12538 |
end Find_Component; |
| 12539 |
|
| 12540 |
----------------------- |
| 12541 |
-- Record_Hole_Check -- |
| 12542 |
----------------------- |
| 12543 |
|
| 12544 |
procedure Record_Hole_Check |
| 12545 |
(Rectype : Entity_Id; After_Last : out Uint; Warn : Boolean) |
| 12546 |
is |
| 12547 |
Base_Typ : constant Entity_Id := Base_Type (Rectype); |
| 12548 |
-- Base type of record type |
| 12549 |
|
| 12550 |
Decl : constant Node_Id := Declaration_Node (Base_Typ); |
| 12551 |
-- Full declaration of base type of record type |
| 12552 |
|
| 12553 |
procedure Check_Component_List |
| 12554 |
(DS : List_Id; |
| 12555 |
CL : Node_Id; |
| 12556 |
Sbit : Uint; |
| 12557 |
Abit : out Uint); |
| 12558 |
-- Check component list CL for holes. DS is a list of discriminant |
| 12559 |
-- specifications to be included in the consideration of components. |
| 12560 |
-- Sbit is the starting bit, which is zero if there are no preceding |
| 12561 |
-- components (before a variant part, or a parent type, or a tag |
| 12562 |
-- field). If there are preceding components, Sbit is the bit just |
| 12563 |
-- after the last such component. Abit is set to the bit just after |
| 12564 |
-- the last component of DS and CL. |
| 12565 |
|
| 12566 |
-------------------------- |
| 12567 |
-- Check_Component_List -- |
| 12568 |
-------------------------- |
| 12569 |
|
| 12570 |
procedure Check_Component_List |
| 12571 |
(DS : List_Id; |
| 12572 |
CL : Node_Id; |
| 12573 |
Sbit : Uint; |
| 12574 |
Abit : out Uint) |
| 12575 |
is |
| 12576 |
Compl : constant Natural := |
| 12577 |
Natural (List_Length (Component_Items (CL)) + List_Length (DS)); |
| 12578 |
|
| 12579 |
Comps : array (Natural range 0 .. Compl) of Entity_Id; |
| 12580 |
-- Gather components (zero entry is for sort routine) |
| 12581 |
|
| 12582 |
Ncomps : Natural := 0; |
| 12583 |
-- Number of entries stored in Comps (starting at Comps (1)) |
| 12584 |
|
| 12585 |
Citem : Node_Id; |
| 12586 |
-- One component item or discriminant specification |
| 12587 |
|
| 12588 |
Nbit : Uint; |
| 12589 |
-- Starting bit for next component |
| 12590 |
|
| 12591 |
CEnt : Entity_Id; |
| 12592 |
-- Component entity |
| 12593 |
|
| 12594 |
Variant : Node_Id; |
| 12595 |
-- One variant |
| 12596 |
|
| 12597 |
function Lt (Op1, Op2 : Natural) return Boolean; |
| 12598 |
-- Compare routine for Sort |
| 12599 |
|
| 12600 |
procedure Move (From : Natural; To : Natural); |
| 12601 |
-- Move routine for Sort |
| 12602 |
|
| 12603 |
package Sorting is new GNAT.Heap_Sort_G (Move, Lt); |
| 12604 |
|
| 12605 |
-------- |
| 12606 |
-- Lt -- |
| 12607 |
-------- |
| 12608 |
|
| 12609 |
function Lt (Op1, Op2 : Natural) return Boolean is |
| 12610 |
K1 : constant Boolean := |
| 12611 |
Known_Component_Bit_Offset (Comps (Op1)); |
| 12612 |
K2 : constant Boolean := |
| 12613 |
Known_Component_Bit_Offset (Comps (Op2)); |
| 12614 |
-- Record representation clauses can be incomplete, so the |
| 12615 |
-- Component_Bit_Offsets can be unknown. |
| 12616 |
begin |
| 12617 |
if K1 then |
| 12618 |
if K2 then |
| 12619 |
return Component_Bit_Offset (Comps (Op1)) |
| 12620 |
< Component_Bit_Offset (Comps (Op2)); |
| 12621 |
else |
| 12622 |
return True; |
| 12623 |
end if; |
| 12624 |
else |
| 12625 |
return K2; |
| 12626 |
end if; |
| 12627 |
end Lt; |
| 12628 |
|
| 12629 |
---------- |
| 12630 |
-- Move -- |
| 12631 |
---------- |
| 12632 |
|
| 12633 |
procedure Move (From : Natural; To : Natural) is |
| 12634 |
begin |
| 12635 |
Comps (To) := Comps (From); |
| 12636 |
end Move; |
| 12637 |
|
| 12638 |
-- Start of processing for Check_Component_List |
| 12639 |
|
| 12640 |
begin |
| 12641 |
-- Gather discriminants into Comp |
| 12642 |
|
| 12643 |
Citem := First (DS); |
| 12644 |
while Present (Citem) loop |
| 12645 |
if Nkind (Citem) = N_Discriminant_Specification then |
| 12646 |
Ncomps := Ncomps + 1; |
| 12647 |
Comps (Ncomps) := Defining_Identifier (Citem); |
| 12648 |
|
| 12649 |
-- Check that we pick discriminants from the proper view |
| 12650 |
|
| 12651 |
pragma Assert (Ekind (Comps (Ncomps)) = E_Discriminant); |
| 12652 |
end if; |
| 12653 |
|
| 12654 |
Next (Citem); |
| 12655 |
end loop; |
| 12656 |
|
| 12657 |
-- Gather component entities into Comp |
| 12658 |
|
| 12659 |
Citem := First (Component_Items (CL)); |
| 12660 |
while Present (Citem) loop |
| 12661 |
if Nkind (Citem) = N_Component_Declaration then |
| 12662 |
Ncomps := Ncomps + 1; |
| 12663 |
Comps (Ncomps) := Defining_Identifier (Citem); |
| 12664 |
end if; |
| 12665 |
|
| 12666 |
Next (Citem); |
| 12667 |
end loop; |
| 12668 |
|
| 12669 |
-- Now sort the component entities based on the first bit. |
| 12670 |
-- Note we already know there are no overlapping components. |
| 12671 |
|
| 12672 |
Sorting.Sort (Ncomps); |
| 12673 |
|
| 12674 |
-- Loop through entries checking for holes |
| 12675 |
|
| 12676 |
Nbit := Sbit; |
| 12677 |
for J in 1 .. Ncomps loop |
| 12678 |
CEnt := Comps (J); |
| 12679 |
pragma Annotate (CodePeer, Modified, CEnt); |
| 12680 |
|
| 12681 |
declare |
| 12682 |
CBO : constant Uint := Component_Bit_Offset (CEnt); |
| 12683 |
|
| 12684 |
begin |
| 12685 |
-- Skip components with unknown offsets |
| 12686 |
|
| 12687 |
if Present (CBO) and then CBO >= 0 then |
| 12688 |
Error_Msg_Uint_1 := CBO - Nbit; |
| 12689 |
|
| 12690 |
if Warn and then Error_Msg_Uint_1 > 0 then |
| 12691 |
Error_Msg_NE |
| 12692 |
("?.h?^-bit gap before component&", |
| 12693 |
Component_Name (Component_Clause (CEnt)), |
| 12694 |
CEnt); |
| 12695 |
end if; |
| 12696 |
|
| 12697 |
Nbit := CBO + Esize (CEnt); |
| 12698 |
end if; |
| 12699 |
end; |
| 12700 |
end loop; |
| 12701 |
|
| 12702 |
-- Set Abit to just after the last nonvariant component |
| 12703 |
|
| 12704 |
Abit := Nbit; |
| 12705 |
|
| 12706 |
-- Process variant parts recursively if present. Set Abit to the |
| 12707 |
-- maximum for all variant parts. |
| 12708 |
|
| 12709 |
if Present (Variant_Part (CL)) then |
| 12710 |
declare |
| 12711 |
Var_Start : constant Uint := Nbit; |
| 12712 |
begin |
| 12713 |
Variant := First (Variants (Variant_Part (CL))); |
| 12714 |
while Present (Variant) loop |
| 12715 |
Check_Component_List |
| 12716 |
(No_List, Component_List (Variant), Var_Start, Nbit); |
| 12717 |
Next (Variant); |
| 12718 |
if Nbit > Abit then |
| 12719 |
Abit := Nbit; |
| 12720 |
end if; |
| 12721 |
end loop; |
| 12722 |
end; |
| 12723 |
end if; |
| 12724 |
end Check_Component_List; |
| 12725 |
|
| 12726 |
-- Local variables |
| 12727 |
|
| 12728 |
Decl_For_Discriminants : Node_Id; |
| 12729 |
-- Declaration node for the view that provides discriminants |
| 12730 |
|
| 12731 |
Record_Definition : Node_Id; |
| 12732 |
-- Record_Definition containing Component_List to pass to |
| 12733 |
-- Check_Component_List. |
| 12734 |
|
| 12735 |
Sbit : Uint; |
| 12736 |
-- Starting bit for call to Check_Component_List. Zero for an |
| 12737 |
-- untagged type. The size of the Tag for a nonderived tagged |
| 12738 |
-- type. Parent size for a type extension. |
| 12739 |
|
| 12740 |
-- Start of processing for Record_Hole_Check |
| 12741 |
|
| 12742 |
begin |
| 12743 |
-- The tag is not present in the list of components of a tagged type |
| 12744 |
|
| 12745 |
if Is_Tagged_Type (Base_Typ) then |
| 12746 |
Sbit := UI_From_Int (System_Address_Size); |
| 12747 |
else |
| 12748 |
Sbit := Uint_0; |
| 12749 |
end if; |
| 12750 |
|
| 12751 |
After_Last := Sbit; |
| 12752 |
|
| 12753 |
-- We need the full declaration of the base type of the record type |
| 12754 |
|
| 12755 |
if Nkind (Decl) /= N_Full_Type_Declaration then |
| 12756 |
return; |
| 12757 |
end if; |
| 12758 |
|
| 12759 |
Record_Definition := Type_Definition (Decl); |
| 12760 |
|
| 12761 |
-- If we have a record extension, set Sbit to point after the last |
| 12762 |
-- component of the parent subtype, by calling Record_Hole_Check |
| 12763 |
-- recursively on this parent subtype. |
| 12764 |
|
| 12765 |
if Nkind (Record_Definition) = N_Derived_Type_Definition then |
| 12766 |
Record_Definition := Record_Extension_Part (Record_Definition); |
| 12767 |
Record_Hole_Check |
| 12768 |
(Underlying_Type (Parent_Subtype (Base_Typ)), |
| 12769 |
After_Last => Sbit, |
| 12770 |
Warn => False); |
| 12771 |
end if; |
| 12772 |
|
| 12773 |
pragma Assert (Nkind (Record_Definition) = N_Record_Definition); |
| 12774 |
|
| 12775 |
-- If the type has a private declaration that does not specify |
| 12776 |
-- unknown discriminants, this declaration provides the (known) |
| 12777 |
-- discriminants, if any. |
| 12778 |
|
| 12779 |
if Has_Private_Declaration (Base_Typ) |
| 12780 |
and then not Partial_View_Has_Unknown_Discr (Base_Typ) |
| 12781 |
then |
| 12782 |
Decl_For_Discriminants := |
| 12783 |
Declaration_Node (Incomplete_Or_Partial_View (Base_Typ)); |
| 12784 |
else |
| 12785 |
Decl_For_Discriminants := Decl; |
| 12786 |
end if; |
| 12787 |
|
| 12788 |
Check_Component_List |
| 12789 |
(Discriminant_Specifications (Decl_For_Discriminants), |
| 12790 |
Component_List (Record_Definition), |
| 12791 |
Sbit => Sbit, |
| 12792 |
Abit => After_Last); |
| 12793 |
end Record_Hole_Check; |
| 12794 |
|
| 12795 |
-- Start of processing for Check_Record_Representation_Clause |
| 12796 |
|
| 12797 |
begin |
| 12798 |
Find_Type (Ident); |
| 12799 |
Rectype := Entity (Ident); |
| 12800 |
|
| 12801 |
if Rectype = Any_Type then |
| 12802 |
return; |
| 12803 |
end if; |
| 12804 |
|
| 12805 |
Rectype := Underlying_Type (Rectype); |
| 12806 |
|
| 12807 |
-- See if we have a fully repped derived tagged type |
| 12808 |
|
| 12809 |
declare |
| 12810 |
PS : constant Entity_Id := Parent_Subtype (Rectype); |
| 12811 |
|
| 12812 |
begin |
| 12813 |
if Present (PS) and then Known_Static_RM_Size (PS) then |
| 12814 |
Tagged_Parent := PS; |
| 12815 |
Parent_Last_Bit := RM_Size (PS) - 1; |
| 12816 |
|
| 12817 |
elsif Present (PS) and then Is_Fully_Repped_Tagged_Type (PS) then |
| 12818 |
Tagged_Parent := PS; |
| 12819 |
|
| 12820 |
-- Find maximum bit of any component of the parent type |
| 12821 |
|
| 12822 |
Parent_Last_Bit := UI_From_Int (System_Address_Size - 1); |
| 12823 |
Pcomp := First_Component_Or_Discriminant (Tagged_Parent); |
| 12824 |
while Present (Pcomp) loop |
| 12825 |
if Present (Component_Bit_Offset (Pcomp)) |
| 12826 |
and then Known_Static_Esize (Pcomp) |
| 12827 |
then |
| 12828 |
Parent_Last_Bit := |
| 12829 |
UI_Max |
| 12830 |
(Parent_Last_Bit, |
| 12831 |
Component_Bit_Offset (Pcomp) + Esize (Pcomp) - 1); |
| 12832 |
end if; |
| 12833 |
|
| 12834 |
Next_Component_Or_Discriminant (Pcomp); |
| 12835 |
end loop; |
| 12836 |
end if; |
| 12837 |
end; |
| 12838 |
|
| 12839 |
-- All done if no component clauses |
| 12840 |
|
| 12841 |
CC := First (Component_Clauses (N)); |
| 12842 |
|
| 12843 |
if No (CC) then |
| 12844 |
return; |
| 12845 |
end if; |
| 12846 |
|
| 12847 |
-- If a tag is present, then create a component clause that places it |
| 12848 |
-- at the start of the record (otherwise gigi may place it after other |
| 12849 |
-- fields that have rep clauses). |
| 12850 |
|
| 12851 |
Fent := First_Entity (Rectype); |
| 12852 |
|
| 12853 |
if Nkind (Fent) = N_Defining_Identifier |
| 12854 |
and then Chars (Fent) = Name_uTag |
| 12855 |
then |
| 12856 |
Set_Component_Bit_Offset (Fent, Uint_0); |
| 12857 |
Set_Normalized_Position (Fent, Uint_0); |
| 12858 |
Set_Normalized_First_Bit (Fent, Uint_0); |
| 12859 |
Set_Esize (Fent, UI_From_Int (System_Address_Size)); |
| 12860 |
|
| 12861 |
Set_Component_Clause (Fent, |
| 12862 |
Make_Component_Clause (Loc, |
| 12863 |
Component_Name => Make_Identifier (Loc, Name_uTag), |
| 12864 |
|
| 12865 |
Position => Make_Integer_Literal (Loc, Uint_0), |
| 12866 |
First_Bit => Make_Integer_Literal (Loc, Uint_0), |
| 12867 |
Last_Bit => |
| 12868 |
Make_Integer_Literal (Loc, |
| 12869 |
UI_From_Int (System_Address_Size - 1)))); |
| 12870 |
|
| 12871 |
Ccount := Ccount + 1; |
| 12872 |
end if; |
| 12873 |
|
| 12874 |
Max_Bit_So_Far := Uint_Minus_1; |
| 12875 |
Overlap_Check_Required := False; |
| 12876 |
|
| 12877 |
-- Process the component clauses |
| 12878 |
|
| 12879 |
while Present (CC) loop |
| 12880 |
Find_Component; |
| 12881 |
|
| 12882 |
if Present (Comp) then |
| 12883 |
Ccount := Ccount + 1; |
| 12884 |
|
| 12885 |
-- We need a full overlap check if record positions non-monotonic |
| 12886 |
|
| 12887 |
if Fbit <= Max_Bit_So_Far then |
| 12888 |
Overlap_Check_Required := True; |
| 12889 |
end if; |
| 12890 |
|
| 12891 |
Max_Bit_So_Far := Lbit; |
| 12892 |
|
| 12893 |
-- Check bit position out of range of specified size |
| 12894 |
|
| 12895 |
if Has_Size_Clause (Rectype) |
| 12896 |
and then RM_Size (Rectype) <= Lbit |
| 12897 |
then |
| 12898 |
Error_Msg_Uint_1 := RM_Size (Rectype); |
| 12899 |
Error_Msg_Uint_2 := Lbit + 1; |
| 12900 |
Error_Msg_N ("bit number out of range of specified " |
| 12901 |
& "size (expected ^, got ^)", |
| 12902 |
Last_Bit (CC)); |
| 12903 |
|
| 12904 |
-- Check for overlap with tag or parent component |
| 12905 |
|
| 12906 |
else |
| 12907 |
if Is_Tagged_Type (Rectype) |
| 12908 |
and then Fbit < System_Address_Size |
| 12909 |
then |
| 12910 |
Error_Msg_NE |
| 12911 |
("component overlaps tag field of&", |
| 12912 |
Component_Name (CC), Rectype); |
| 12913 |
Overlap_Detected := True; |
| 12914 |
|
| 12915 |
elsif Present (Tagged_Parent) |
| 12916 |
and then Fbit <= Parent_Last_Bit |
| 12917 |
then |
| 12918 |
Error_Msg_NE |
| 12919 |
("component overlaps parent field of&", |
| 12920 |
Component_Name (CC), Rectype); |
| 12921 |
Overlap_Detected := True; |
| 12922 |
end if; |
| 12923 |
|
| 12924 |
if Hbit < Lbit then |
| 12925 |
Hbit := Lbit; |
| 12926 |
end if; |
| 12927 |
end if; |
| 12928 |
end if; |
| 12929 |
|
| 12930 |
Next (CC); |
| 12931 |
end loop; |
| 12932 |
|
| 12933 |
-- Now that we have processed all the component clauses, check for |
| 12934 |
-- overlap. We have to leave this till last, since the components can |
| 12935 |
-- appear in any arbitrary order in the representation clause. |
| 12936 |
|
| 12937 |
-- We do not need this check if all specified ranges were monotonic, |
| 12938 |
-- as recorded by Overlap_Check_Required being False at this stage. |
| 12939 |
|
| 12940 |
-- This first section checks if there are any overlapping entries at |
| 12941 |
-- all. It does this by sorting all entries and then seeing if there are |
| 12942 |
-- any overlaps. If there are none, then that is decisive, but if there |
| 12943 |
-- are overlaps, they may still be OK (they may result from fields in |
| 12944 |
-- different variants). |
| 12945 |
|
| 12946 |
if Overlap_Check_Required then |
| 12947 |
Overlap_Check1 : declare |
| 12948 |
|
| 12949 |
OC_Fbit : array (0 .. Ccount) of Uint; |
| 12950 |
-- First-bit values for component clauses, the value is the offset |
| 12951 |
-- of the first bit of the field from start of record. The zero |
| 12952 |
-- entry is for use in sorting. |
| 12953 |
|
| 12954 |
OC_Lbit : array (0 .. Ccount) of Uint; |
| 12955 |
-- Last-bit values for component clauses, the value is the offset |
| 12956 |
-- of the last bit of the field from start of record. The zero |
| 12957 |
-- entry is for use in sorting. |
| 12958 |
|
| 12959 |
OC_Count : Natural := 0; |
| 12960 |
-- Count of entries in OC_Fbit and OC_Lbit |
| 12961 |
|
| 12962 |
function OC_Lt (Op1, Op2 : Natural) return Boolean; |
| 12963 |
-- Compare routine for Sort |
| 12964 |
|
| 12965 |
procedure OC_Move (From : Natural; To : Natural); |
| 12966 |
-- Move routine for Sort |
| 12967 |
|
| 12968 |
package Sorting is new GNAT.Heap_Sort_G (OC_Move, OC_Lt); |
| 12969 |
|
| 12970 |
----------- |
| 12971 |
-- OC_Lt -- |
| 12972 |
----------- |
| 12973 |
|
| 12974 |
function OC_Lt (Op1, Op2 : Natural) return Boolean is |
| 12975 |
begin |
| 12976 |
return OC_Fbit (Op1) < OC_Fbit (Op2); |
| 12977 |
end OC_Lt; |
| 12978 |
|
| 12979 |
------------- |
| 12980 |
-- OC_Move -- |
| 12981 |
------------- |
| 12982 |
|
| 12983 |
procedure OC_Move (From : Natural; To : Natural) is |
| 12984 |
begin |
| 12985 |
OC_Fbit (To) := OC_Fbit (From); |
| 12986 |
OC_Lbit (To) := OC_Lbit (From); |
| 12987 |
end OC_Move; |
| 12988 |
|
| 12989 |
-- Start of processing for Overlap_Check |
| 12990 |
|
| 12991 |
begin |
| 12992 |
CC := First (Component_Clauses (N)); |
| 12993 |
while Present (CC) loop |
| 12994 |
|
| 12995 |
-- Exclude component clause already marked in error |
| 12996 |
|
| 12997 |
if not Error_Posted (CC) then |
| 12998 |
Find_Component; |
| 12999 |
|
| 13000 |
if Present (Comp) then |
| 13001 |
OC_Count := OC_Count + 1; |
| 13002 |
OC_Fbit (OC_Count) := Fbit; |
| 13003 |
OC_Lbit (OC_Count) := Lbit; |
| 13004 |
end if; |
| 13005 |
end if; |
| 13006 |
|
| 13007 |
Next (CC); |
| 13008 |
end loop; |
| 13009 |
|
| 13010 |
Sorting.Sort (OC_Count); |
| 13011 |
|
| 13012 |
Overlap_Check_Required := False; |
| 13013 |
for J in 1 .. OC_Count - 1 loop |
| 13014 |
if OC_Lbit (J) >= OC_Fbit (J + 1) then |
| 13015 |
Overlap_Check_Required := True; |
| 13016 |
exit; |
| 13017 |
end if; |
| 13018 |
end loop; |
| 13019 |
end Overlap_Check1; |
| 13020 |
end if; |
| 13021 |
|
| 13022 |
-- If Overlap_Check_Required is still True, then we have to do the full |
| 13023 |
-- scale overlap check, since we have at least two fields that do |
| 13024 |
-- overlap, and we need to know if that is OK since they are in |
| 13025 |
-- different variant, or whether we have a definite problem. |
| 13026 |
|
| 13027 |
if Overlap_Check_Required then |
| 13028 |
Overlap_Check2 : declare |
| 13029 |
C1_Ent, C2_Ent : Entity_Id; |
| 13030 |
-- Entities of components being checked for overlap |
| 13031 |
|
| 13032 |
Clist : Node_Id; |
| 13033 |
-- Component_List node whose Component_Items are being checked |
| 13034 |
|
| 13035 |
Citem : Node_Id; |
| 13036 |
-- Component declaration for component being checked |
| 13037 |
|
| 13038 |
begin |
| 13039 |
C1_Ent := First_Entity (Base_Type (Rectype)); |
| 13040 |
|
| 13041 |
-- Loop through all components in record. For each component check |
| 13042 |
-- for overlap with any of the preceding elements on the component |
| 13043 |
-- list containing the component and also, if the component is in |
| 13044 |
-- a variant, check against components outside the case structure. |
| 13045 |
-- This latter test is repeated recursively up the variant tree. |
| 13046 |
|
| 13047 |
Main_Component_Loop : while Present (C1_Ent) loop |
| 13048 |
if Ekind (C1_Ent) not in E_Component | E_Discriminant then |
| 13049 |
goto Continue_Main_Component_Loop; |
| 13050 |
end if; |
| 13051 |
|
| 13052 |
-- Skip overlap check if entity has no declaration node. This |
| 13053 |
-- happens with discriminants in constrained derived types. |
| 13054 |
-- Possibly we are missing some checks as a result, but that |
| 13055 |
-- does not seem terribly serious. |
| 13056 |
|
| 13057 |
if No (Declaration_Node (C1_Ent)) then |
| 13058 |
goto Continue_Main_Component_Loop; |
| 13059 |
end if; |
| 13060 |
|
| 13061 |
Clist := Parent (List_Containing (Declaration_Node (C1_Ent))); |
| 13062 |
|
| 13063 |
-- Loop through component lists that need checking. Check the |
| 13064 |
-- current component list and all lists in variants above us. |
| 13065 |
|
| 13066 |
Component_List_Loop : loop |
| 13067 |
|
| 13068 |
-- If derived type definition, go to full declaration |
| 13069 |
-- If at outer level, check discriminants if there are any. |
| 13070 |
|
| 13071 |
if Nkind (Clist) = N_Derived_Type_Definition then |
| 13072 |
Clist := Parent (Clist); |
| 13073 |
end if; |
| 13074 |
|
| 13075 |
-- Outer level of record definition, check discriminants |
| 13076 |
-- but be careful not to flag a non-stored discriminant |
| 13077 |
-- and the stored discriminant it renames as overlapping. |
| 13078 |
|
| 13079 |
if Nkind (Clist) in N_Full_Type_Declaration |
| 13080 |
| N_Private_Type_Declaration |
| 13081 |
then |
| 13082 |
if Has_Discriminants (Defining_Identifier (Clist)) then |
| 13083 |
C2_Ent := |
| 13084 |
First_Discriminant (Defining_Identifier (Clist)); |
| 13085 |
while Present (C2_Ent) loop |
| 13086 |
exit when |
| 13087 |
Original_Record_Component (C1_Ent) = |
| 13088 |
Original_Record_Component (C2_Ent); |
| 13089 |
Check_Component_Overlap (C1_Ent, C2_Ent); |
| 13090 |
Next_Discriminant (C2_Ent); |
| 13091 |
end loop; |
| 13092 |
end if; |
| 13093 |
|
| 13094 |
-- Record extension case |
| 13095 |
|
| 13096 |
elsif Nkind (Clist) = N_Derived_Type_Definition then |
| 13097 |
Clist := Empty; |
| 13098 |
|
| 13099 |
-- Otherwise check one component list |
| 13100 |
|
| 13101 |
else |
| 13102 |
Citem := First (Component_Items (Clist)); |
| 13103 |
while Present (Citem) loop |
| 13104 |
if Nkind (Citem) = N_Component_Declaration then |
| 13105 |
C2_Ent := Defining_Identifier (Citem); |
| 13106 |
exit when C1_Ent = C2_Ent; |
| 13107 |
Check_Component_Overlap (C1_Ent, C2_Ent); |
| 13108 |
end if; |
| 13109 |
|
| 13110 |
Next (Citem); |
| 13111 |
end loop; |
| 13112 |
end if; |
| 13113 |
|
| 13114 |
-- Check for variants above us (the parent of the Clist can |
| 13115 |
-- be a variant, in which case its parent is a variant part, |
| 13116 |
-- and the parent of the variant part is a component list |
| 13117 |
-- whose components must all be checked against the current |
| 13118 |
-- component for overlap). |
| 13119 |
|
| 13120 |
if Nkind (Parent (Clist)) = N_Variant then |
| 13121 |
Clist := Parent (Parent (Parent (Clist))); |
| 13122 |
|
| 13123 |
-- Check for possible discriminant part in record, this |
| 13124 |
-- is treated essentially as another level in the |
| 13125 |
-- recursion. For this case the parent of the component |
| 13126 |
-- list is the record definition, and its parent is the |
| 13127 |
-- full type declaration containing the discriminant |
| 13128 |
-- specifications. |
| 13129 |
|
| 13130 |
elsif Nkind (Parent (Clist)) = N_Record_Definition then |
| 13131 |
Clist := Parent (Parent ((Clist))); |
| 13132 |
|
| 13133 |
-- If neither of these two cases, we are at the top of |
| 13134 |
-- the tree. |
| 13135 |
|
| 13136 |
else |
| 13137 |
exit Component_List_Loop; |
| 13138 |
end if; |
| 13139 |
end loop Component_List_Loop; |
| 13140 |
|
| 13141 |
<<Continue_Main_Component_Loop>> |
| 13142 |
Next_Entity (C1_Ent); |
| 13143 |
|
| 13144 |
end loop Main_Component_Loop; |
| 13145 |
end Overlap_Check2; |
| 13146 |
end if; |
| 13147 |
|
| 13148 |
-- Skip the following warnings if overlap was detected; programmer |
| 13149 |
-- should fix the errors first. Also skip the warnings for types in |
| 13150 |
-- generics, because their representation information is not fully |
| 13151 |
-- computed. |
| 13152 |
|
| 13153 |
if not Overlap_Detected and then not In_Generic_Scope (Rectype) then |
| 13154 |
-- Check for record holes (gaps) |
| 13155 |
|
| 13156 |
if Warn_On_Record_Holes then |
| 13157 |
declare |
| 13158 |
Ignore : Uint; |
| 13159 |
begin |
| 13160 |
Record_Hole_Check (Rectype, After_Last => Ignore, Warn => True); |
| 13161 |
end; |
| 13162 |
end if; |
| 13163 |
|
| 13164 |
-- Check for out-of-order component clauses |
| 13165 |
|
| 13166 |
if Warn_On_Component_Order then |
| 13167 |
Component_Order_Check (Rectype); |
| 13168 |
end if; |
| 13169 |
end if; |
| 13170 |
|
| 13171 |
-- For records that have component clauses for all components, and whose |
| 13172 |
-- size is less than or equal to 32, and which can be fully packed, we |
| 13173 |
-- need to know the size in the front end to activate possible packed |
| 13174 |
-- array processing where the component type is a record. |
| 13175 |
|
| 13176 |
-- At this stage Hbit + 1 represents the first unused bit from all the |
| 13177 |
-- component clauses processed, so if the component clauses are |
| 13178 |
-- complete, then this is the length of the record. |
| 13179 |
|
| 13180 |
-- For records longer than System.Storage_Unit, and for those where not |
| 13181 |
-- all components have component clauses, the back end determines the |
| 13182 |
-- length (it may for example be appropriate to round up the size |
| 13183 |
-- to some convenient boundary, based on alignment considerations, etc). |
| 13184 |
|
| 13185 |
if not Known_RM_Size (Rectype) |
| 13186 |
and then Hbit + 1 <= 32 |
| 13187 |
and then not Strict_Alignment (Rectype) |
| 13188 |
then |
| 13189 |
|
| 13190 |
-- Nothing to do if at least one component has no component clause |
| 13191 |
|
| 13192 |
Comp := First_Component_Or_Discriminant (Rectype); |
| 13193 |
while Present (Comp) loop |
| 13194 |
exit when No (Component_Clause (Comp)); |
| 13195 |
Next_Component_Or_Discriminant (Comp); |
| 13196 |
end loop; |
| 13197 |
|
| 13198 |
-- If we fall out of loop, all components have component clauses |
| 13199 |
-- and so we can set the size to the maximum value. |
| 13200 |
|
| 13201 |
if No (Comp) then |
| 13202 |
Set_RM_Size (Rectype, Hbit + 1); |
| 13203 |
end if; |
| 13204 |
end if; |
| 13205 |
end Check_Record_Representation_Clause; |
| 13206 |
|
| 13207 |
---------------- |
| 13208 |
-- Check_Size -- |
| 13209 |
---------------- |
| 13210 |
|
| 13211 |
procedure Check_Size |
| 13212 |
(N : Node_Id; |
| 13213 |
T : Entity_Id; |
| 13214 |
Siz : Uint; |
| 13215 |
Biased : out Boolean) |
| 13216 |
is |
| 13217 |
procedure Size_Too_Small_Error (Min_Siz : Uint); |
| 13218 |
-- Emit an error concerning illegal size Siz. Min_Siz denotes the |
| 13219 |
-- minimum size. |
| 13220 |
|
| 13221 |
-------------------------- |
| 13222 |
-- Size_Too_Small_Error -- |
| 13223 |
-------------------------- |
| 13224 |
|
| 13225 |
procedure Size_Too_Small_Error (Min_Siz : Uint) is |
| 13226 |
begin |
| 13227 |
Error_Msg_Uint_1 := Min_Siz; |
| 13228 |
Error_Msg_NE (Size_Too_Small_Message, N, T); |
| 13229 |
end Size_Too_Small_Error; |
| 13230 |
|
| 13231 |
-- Local variables |
| 13232 |
|
| 13233 |
UT : constant Entity_Id := Underlying_Type (T); |
| 13234 |
M : Uint; |
| 13235 |
|
| 13236 |
-- Start of processing for Check_Size |
| 13237 |
|
| 13238 |
begin |
| 13239 |
Biased := False; |
| 13240 |
|
| 13241 |
-- Reject patently improper size values |
| 13242 |
|
| 13243 |
if Is_Elementary_Type (T) |
| 13244 |
and then Siz > Int'Last |
| 13245 |
then |
| 13246 |
Error_Msg_N ("Size value too large for elementary type", N); |
| 13247 |
|
| 13248 |
if Nkind (Original_Node (N)) = N_Op_Expon then |
| 13249 |
Error_Msg_N |
| 13250 |
("\maybe '* was meant, rather than '*'*", Original_Node (N)); |
| 13251 |
end if; |
| 13252 |
end if; |
| 13253 |
|
| 13254 |
-- Dismiss generic types |
| 13255 |
|
| 13256 |
if Is_Generic_Type (T) |
| 13257 |
or else |
| 13258 |
Is_Generic_Type (UT) |
| 13259 |
or else |
| 13260 |
Is_Generic_Type (Root_Type (UT)) |
| 13261 |
then |
| 13262 |
return; |
| 13263 |
|
| 13264 |
-- Guard against previous errors |
| 13265 |
|
| 13266 |
elsif No (UT) or else UT = Any_Type then |
| 13267 |
Check_Error_Detected; |
| 13268 |
return; |
| 13269 |
|
| 13270 |
-- Check case of bit packed array |
| 13271 |
|
| 13272 |
elsif Is_Array_Type (UT) |
| 13273 |
and then Known_Static_Component_Size (UT) |
| 13274 |
and then Is_Bit_Packed_Array (UT) |
| 13275 |
then |
| 13276 |
declare |
| 13277 |
Asiz : Uint; |
| 13278 |
Indx : Node_Id; |
| 13279 |
Ityp : Entity_Id; |
| 13280 |
|
| 13281 |
begin |
| 13282 |
Asiz := Component_Size (UT); |
| 13283 |
Indx := First_Index (UT); |
| 13284 |
loop |
| 13285 |
Ityp := Etype (Indx); |
| 13286 |
|
| 13287 |
-- If non-static bound, then we are not in the business of |
| 13288 |
-- trying to check the length, and indeed an error will be |
| 13289 |
-- issued elsewhere, since sizes of non-static array types |
| 13290 |
-- cannot be set implicitly or explicitly. |
| 13291 |
|
| 13292 |
if not Is_OK_Static_Subtype (Ityp) then |
| 13293 |
return; |
| 13294 |
end if; |
| 13295 |
|
| 13296 |
-- Otherwise accumulate next dimension |
| 13297 |
|
| 13298 |
Asiz := Asiz * (Expr_Value (Type_High_Bound (Ityp)) - |
| 13299 |
Expr_Value (Type_Low_Bound (Ityp)) + |
| 13300 |
Uint_1); |
| 13301 |
|
| 13302 |
Next_Index (Indx); |
| 13303 |
exit when No (Indx); |
| 13304 |
end loop; |
| 13305 |
|
| 13306 |
if Asiz <= Siz then |
| 13307 |
return; |
| 13308 |
|
| 13309 |
else |
| 13310 |
Size_Too_Small_Error (Asiz); |
| 13311 |
end if; |
| 13312 |
end; |
| 13313 |
|
| 13314 |
-- All other composite types are ignored |
| 13315 |
|
| 13316 |
elsif Is_Composite_Type (UT) then |
| 13317 |
return; |
| 13318 |
|
| 13319 |
-- For fixed-point types, don't check minimum if type is not frozen, |
| 13320 |
-- since we don't know all the characteristics of the type that can |
| 13321 |
-- affect the size (e.g. a specified small) till freeze time. |
| 13322 |
|
| 13323 |
elsif Is_Fixed_Point_Type (UT) and then not Is_Frozen (UT) then |
| 13324 |
null; |
| 13325 |
|
| 13326 |
-- Cases for which a minimum check is required |
| 13327 |
|
| 13328 |
else |
| 13329 |
-- Ignore if specified size is correct for the type |
| 13330 |
|
| 13331 |
if Known_Esize (UT) and then Siz = Esize (UT) then |
| 13332 |
return; |
| 13333 |
end if; |
| 13334 |
|
| 13335 |
-- Otherwise get minimum size |
| 13336 |
|
| 13337 |
M := UI_From_Int (Minimum_Size (UT)); |
| 13338 |
|
| 13339 |
if Siz < M then |
| 13340 |
|
| 13341 |
-- Size is less than minimum size, but one possibility remains |
| 13342 |
-- that we can manage with the new size if we bias the type. |
| 13343 |
|
| 13344 |
M := UI_From_Int (Minimum_Size (UT, Biased => True)); |
| 13345 |
|
| 13346 |
if Siz < M then |
| 13347 |
Size_Too_Small_Error (M); |
| 13348 |
else |
| 13349 |
Biased := True; |
| 13350 |
end if; |
| 13351 |
end if; |
| 13352 |
end if; |
| 13353 |
end Check_Size; |
| 13354 |
|
| 13355 |
-------------------------- |
| 13356 |
-- Freeze_Entity_Checks -- |
| 13357 |
-------------------------- |
| 13358 |
|
| 13359 |
procedure Freeze_Entity_Checks (N : Node_Id) is |
| 13360 |
procedure Hide_Non_Overridden_Subprograms (Typ : Entity_Id); |
| 13361 |
-- Inspect the primitive operations of type Typ and hide all pairs of |
| 13362 |
-- implicitly declared non-overridden non-fully conformant homographs |
| 13363 |
-- (RM 8.3(12.3/2)). |
| 13364 |
|
| 13365 |
------------------------------------- |
| 13366 |
-- Hide_Non_Overridden_Subprograms -- |
| 13367 |
------------------------------------- |
| 13368 |
|
| 13369 |
procedure Hide_Non_Overridden_Subprograms (Typ : Entity_Id) is |
| 13370 |
procedure Hide_Matching_Homographs |
| 13371 |
(Subp_Id : Entity_Id; |
| 13372 |
Start_Elmt : Elmt_Id); |
| 13373 |
-- Inspect a list of primitive operations starting with Start_Elmt |
| 13374 |
-- and find matching implicitly declared non-overridden non-fully |
| 13375 |
-- conformant homographs of Subp_Id. If found, all matches along |
| 13376 |
-- with Subp_Id are hidden from all visibility. |
| 13377 |
|
| 13378 |
function Is_Non_Overridden_Or_Null_Procedure |
| 13379 |
(Subp_Id : Entity_Id) return Boolean; |
| 13380 |
-- Determine whether subprogram Subp_Id is implicitly declared non- |
| 13381 |
-- overridden subprogram or an implicitly declared null procedure. |
| 13382 |
|
| 13383 |
------------------------------ |
| 13384 |
-- Hide_Matching_Homographs -- |
| 13385 |
------------------------------ |
| 13386 |
|
| 13387 |
procedure Hide_Matching_Homographs |
| 13388 |
(Subp_Id : Entity_Id; |
| 13389 |
Start_Elmt : Elmt_Id) |
| 13390 |
is |
| 13391 |
Prim : Entity_Id; |
| 13392 |
Prim_Elmt : Elmt_Id; |
| 13393 |
|
| 13394 |
begin |
| 13395 |
Prim_Elmt := Start_Elmt; |
| 13396 |
while Present (Prim_Elmt) loop |
| 13397 |
Prim := Node (Prim_Elmt); |
| 13398 |
|
| 13399 |
-- The current primitive is implicitly declared non-overridden |
| 13400 |
-- non-fully conformant homograph of Subp_Id. Both subprograms |
| 13401 |
-- must be hidden from visibility. |
| 13402 |
|
| 13403 |
if Chars (Prim) = Chars (Subp_Id) |
| 13404 |
and then Is_Non_Overridden_Or_Null_Procedure (Prim) |
| 13405 |
and then not Fully_Conformant (Prim, Subp_Id) |
| 13406 |
then |
| 13407 |
Set_Is_Hidden_Non_Overridden_Subpgm (Prim); |
| 13408 |
Set_Is_Immediately_Visible (Prim, False); |
| 13409 |
Set_Is_Potentially_Use_Visible (Prim, False); |
| 13410 |
|
| 13411 |
Set_Is_Hidden_Non_Overridden_Subpgm (Subp_Id); |
| 13412 |
Set_Is_Immediately_Visible (Subp_Id, False); |
| 13413 |
Set_Is_Potentially_Use_Visible (Subp_Id, False); |
| 13414 |
end if; |
| 13415 |
|
| 13416 |
Next_Elmt (Prim_Elmt); |
| 13417 |
end loop; |
| 13418 |
end Hide_Matching_Homographs; |
| 13419 |
|
| 13420 |
----------------------------------------- |
| 13421 |
-- Is_Non_Overridden_Or_Null_Procedure -- |
| 13422 |
----------------------------------------- |
| 13423 |
|
| 13424 |
function Is_Non_Overridden_Or_Null_Procedure |
| 13425 |
(Subp_Id : Entity_Id) return Boolean |
| 13426 |
is |
| 13427 |
Alias_Id : Entity_Id; |
| 13428 |
|
| 13429 |
begin |
| 13430 |
-- The subprogram is inherited (implicitly declared), it does not |
| 13431 |
-- override and does not cover a primitive of an interface. |
| 13432 |
|
| 13433 |
if Ekind (Subp_Id) in E_Function | E_Procedure |
| 13434 |
and then Present (Alias (Subp_Id)) |
| 13435 |
and then No (Interface_Alias (Subp_Id)) |
| 13436 |
and then No (Overridden_Operation (Subp_Id)) |
| 13437 |
then |
| 13438 |
Alias_Id := Alias (Subp_Id); |
| 13439 |
|
| 13440 |
if Requires_Overriding (Alias_Id) then |
| 13441 |
return True; |
| 13442 |
|
| 13443 |
elsif Nkind (Parent (Alias_Id)) = N_Procedure_Specification |
| 13444 |
and then Null_Present (Parent (Alias_Id)) |
| 13445 |
then |
| 13446 |
return True; |
| 13447 |
end if; |
| 13448 |
end if; |
| 13449 |
|
| 13450 |
return False; |
| 13451 |
end Is_Non_Overridden_Or_Null_Procedure; |
| 13452 |
|
| 13453 |
-- Local variables |
| 13454 |
|
| 13455 |
Prim_Ops : constant Elist_Id := Direct_Primitive_Operations (Typ); |
| 13456 |
Prim : Entity_Id; |
| 13457 |
Prim_Elmt : Elmt_Id; |
| 13458 |
|
| 13459 |
-- Start of processing for Hide_Non_Overridden_Subprograms |
| 13460 |
|
| 13461 |
begin |
| 13462 |
-- Inspect the list of primitives looking for non-overridden |
| 13463 |
-- subprograms. |
| 13464 |
|
| 13465 |
if Present (Prim_Ops) then |
| 13466 |
Prim_Elmt := First_Elmt (Prim_Ops); |
| 13467 |
while Present (Prim_Elmt) loop |
| 13468 |
Prim := Node (Prim_Elmt); |
| 13469 |
Next_Elmt (Prim_Elmt); |
| 13470 |
|
| 13471 |
if Is_Non_Overridden_Or_Null_Procedure (Prim) then |
| 13472 |
Hide_Matching_Homographs |
| 13473 |
(Subp_Id => Prim, |
| 13474 |
Start_Elmt => Prim_Elmt); |
| 13475 |
end if; |
| 13476 |
end loop; |
| 13477 |
end if; |
| 13478 |
end Hide_Non_Overridden_Subprograms; |
| 13479 |
|
| 13480 |
-- Local variables |
| 13481 |
|
| 13482 |
E : constant Entity_Id := Entity (N); |
| 13483 |
|
| 13484 |
Nongeneric_Case : constant Boolean := Nkind (N) = N_Freeze_Entity; |
| 13485 |
-- True in nongeneric case. Some of the processing here is skipped |
| 13486 |
-- for the generic case since it is not needed. Basically in the |
| 13487 |
-- generic case, we only need to do stuff that might generate error |
| 13488 |
-- messages or warnings. |
| 13489 |
|
| 13490 |
-- Start of processing for Freeze_Entity_Checks |
| 13491 |
|
| 13492 |
begin |
| 13493 |
-- Remember that we are processing a freezing entity. Required to |
| 13494 |
-- ensure correct decoration of internal entities associated with |
| 13495 |
-- interfaces (see New_Overloaded_Entity). |
| 13496 |
|
| 13497 |
Inside_Freezing_Actions := Inside_Freezing_Actions + 1; |
| 13498 |
|
| 13499 |
-- For tagged types covering interfaces add internal entities that link |
| 13500 |
-- the primitives of the interfaces with the primitives that cover them. |
| 13501 |
-- Note: These entities were originally generated only when generating |
| 13502 |
-- code because their main purpose was to provide support to initialize |
| 13503 |
-- the secondary dispatch tables. They are also used to locate |
| 13504 |
-- primitives covering interfaces when processing generics (see |
| 13505 |
-- Derive_Subprograms). |
| 13506 |
|
| 13507 |
-- This is not needed in the generic case |
| 13508 |
|
| 13509 |
if Ada_Version >= Ada_2005 |
| 13510 |
and then Nongeneric_Case |
| 13511 |
and then Ekind (E) = E_Record_Type |
| 13512 |
and then Is_Tagged_Type (E) |
| 13513 |
then |
| 13514 |
-- This would be a good common place to call the routine that checks |
| 13515 |
-- overriding of interface primitives (and thus factorize calls to |
| 13516 |
-- Check_Abstract_Overriding located at different contexts in the |
| 13517 |
-- compiler). However, this is not possible because it causes |
| 13518 |
-- spurious errors in case of late overriding. |
| 13519 |
|
| 13520 |
if Has_Interfaces (E) |
| 13521 |
and then not Is_Interface (E) |
| 13522 |
then |
| 13523 |
Add_Internal_Interface_Entities (E); |
| 13524 |
end if; |
| 13525 |
|
| 13526 |
-- For a derived tagged type, check strub mode compatibility of |
| 13527 |
-- its primitives and whether inherited primitives might require |
| 13528 |
-- a wrapper to handle class-wide conditions. For derived interface |
| 13529 |
-- check strub mode compatibility of its primitives. |
| 13530 |
|
| 13531 |
if Is_Derived_Type (E) |
| 13532 |
and then not In_Generic_Scope (E) |
| 13533 |
then |
| 13534 |
Check_Inherited_Conditions (E); |
| 13535 |
end if; |
| 13536 |
end if; |
| 13537 |
|
| 13538 |
-- After all forms of overriding have been resolved, a tagged type may |
| 13539 |
-- be left with a set of implicitly declared and possibly erroneous |
| 13540 |
-- abstract subprograms, null procedures and subprograms that require |
| 13541 |
-- overriding. If this set contains fully conformant homographs, then |
| 13542 |
-- one is chosen arbitrarily (already done during resolution), otherwise |
| 13543 |
-- all remaining non-fully conformant homographs are hidden from |
| 13544 |
-- visibility (RM 8.3(12.3/2)). |
| 13545 |
|
| 13546 |
if Is_Tagged_Type (E) then |
| 13547 |
Hide_Non_Overridden_Subprograms (E); |
| 13548 |
end if; |
| 13549 |
|
| 13550 |
-- Check CPP types |
| 13551 |
|
| 13552 |
if Ekind (E) = E_Record_Type |
| 13553 |
and then Is_CPP_Class (E) |
| 13554 |
and then Is_Tagged_Type (E) |
| 13555 |
and then Tagged_Type_Expansion |
| 13556 |
then |
| 13557 |
if CPP_Num_Prims (E) = 0 then |
| 13558 |
|
| 13559 |
-- If the CPP type has user defined components then it must import |
| 13560 |
-- primitives from C++. This is required because if the C++ class |
| 13561 |
-- has no primitives then the C++ compiler does not added the _tag |
| 13562 |
-- component to the type. |
| 13563 |
|
| 13564 |
if First_Entity (E) /= Last_Entity (E) then |
| 13565 |
Error_Msg_N |
| 13566 |
("'C'P'P type must import at least one primitive from C++??", |
| 13567 |
E); |
| 13568 |
end if; |
| 13569 |
end if; |
| 13570 |
|
| 13571 |
-- Check that all its primitives are abstract or imported from C++. |
| 13572 |
-- Check also availability of the C++ constructor. |
| 13573 |
|
| 13574 |
declare |
| 13575 |
Has_Constructors : constant Boolean := Has_CPP_Constructors (E); |
| 13576 |
Elmt : Elmt_Id; |
| 13577 |
Error_Reported : Boolean := False; |
| 13578 |
Prim : Node_Id; |
| 13579 |
|
| 13580 |
begin |
| 13581 |
Elmt := First_Elmt (Primitive_Operations (E)); |
| 13582 |
while Present (Elmt) loop |
| 13583 |
Prim := Node (Elmt); |
| 13584 |
|
| 13585 |
if Comes_From_Source (Prim) then |
| 13586 |
if Is_Abstract_Subprogram (Prim) then |
| 13587 |
null; |
| 13588 |
|
| 13589 |
elsif not Is_Imported (Prim) |
| 13590 |
or else Convention (Prim) /= Convention_CPP |
| 13591 |
then |
| 13592 |
Error_Msg_N |
| 13593 |
("primitives of 'C'P'P types must be imported from C++ " |
| 13594 |
& "or abstract??", Prim); |
| 13595 |
|
| 13596 |
elsif not Has_Constructors |
| 13597 |
and then not Error_Reported |
| 13598 |
then |
| 13599 |
Error_Msg_Name_1 := Chars (E); |
| 13600 |
Error_Msg_N |
| 13601 |
("??'C'P'P constructor required for type %", Prim); |
| 13602 |
Error_Reported := True; |
| 13603 |
end if; |
| 13604 |
end if; |
| 13605 |
|
| 13606 |
Next_Elmt (Elmt); |
| 13607 |
end loop; |
| 13608 |
end; |
| 13609 |
end if; |
| 13610 |
|
| 13611 |
-- Check Ada derivation of CPP type |
| 13612 |
|
| 13613 |
if Expander_Active -- why? losing errors in -gnatc mode??? |
| 13614 |
and then Present (Etype (E)) -- defend against errors |
| 13615 |
and then Tagged_Type_Expansion |
| 13616 |
and then Ekind (E) = E_Record_Type |
| 13617 |
and then Etype (E) /= E |
| 13618 |
and then Is_CPP_Class (Etype (E)) |
| 13619 |
and then CPP_Num_Prims (Etype (E)) > 0 |
| 13620 |
and then not Is_CPP_Class (E) |
| 13621 |
and then not Has_CPP_Constructors (Etype (E)) |
| 13622 |
then |
| 13623 |
-- If the parent has C++ primitives but it has no constructor then |
| 13624 |
-- check that all the primitives are overridden in this derivation; |
| 13625 |
-- otherwise the constructor of the parent is needed to build the |
| 13626 |
-- dispatch table. |
| 13627 |
|
| 13628 |
declare |
| 13629 |
Elmt : Elmt_Id; |
| 13630 |
Prim : Node_Id; |
| 13631 |
|
| 13632 |
begin |
| 13633 |
Elmt := First_Elmt (Primitive_Operations (E)); |
| 13634 |
while Present (Elmt) loop |
| 13635 |
Prim := Node (Elmt); |
| 13636 |
|
| 13637 |
if not Is_Abstract_Subprogram (Prim) |
| 13638 |
and then No (Interface_Alias (Prim)) |
| 13639 |
and then Find_Dispatching_Type (Ultimate_Alias (Prim)) /= E |
| 13640 |
then |
| 13641 |
Error_Msg_Name_1 := Chars (Etype (E)); |
| 13642 |
Error_Msg_N |
| 13643 |
("'C'P'P constructor required for parent type %", E); |
| 13644 |
exit; |
| 13645 |
end if; |
| 13646 |
|
| 13647 |
Next_Elmt (Elmt); |
| 13648 |
end loop; |
| 13649 |
end; |
| 13650 |
end if; |
| 13651 |
|
| 13652 |
Inside_Freezing_Actions := Inside_Freezing_Actions - 1; |
| 13653 |
|
| 13654 |
-- For a record type, deal with variant parts. This has to be delayed to |
| 13655 |
-- this point, because of the issue of statically predicated subtypes, |
| 13656 |
-- which we have to ensure are frozen before checking choices, since we |
| 13657 |
-- need to have the static choice list set. |
| 13658 |
|
| 13659 |
if Is_Record_Type (E) then |
| 13660 |
Check_Variant_Part : declare |
| 13661 |
D : constant Node_Id := Declaration_Node (E); |
| 13662 |
T : Node_Id; |
| 13663 |
C : Node_Id; |
| 13664 |
VP : Node_Id; |
| 13665 |
|
| 13666 |
Others_Present : Boolean; |
| 13667 |
pragma Warnings (Off, Others_Present); |
| 13668 |
-- Indicates others present, not used in this case |
| 13669 |
|
| 13670 |
procedure Non_Static_Choice_Error (Choice : Node_Id); |
| 13671 |
-- Error routine invoked by the generic instantiation below when |
| 13672 |
-- the variant part has a non static choice. |
| 13673 |
|
| 13674 |
procedure Process_Declarations (Variant : Node_Id); |
| 13675 |
-- Processes declarations associated with a variant. We analyzed |
| 13676 |
-- the declarations earlier (in Sem_Ch3.Analyze_Variant_Part), |
| 13677 |
-- but we still need the recursive call to Check_Choices for any |
| 13678 |
-- nested variant to get its choices properly processed. This is |
| 13679 |
-- also where we expand out the choices if expansion is active. |
| 13680 |
|
| 13681 |
package Variant_Choices_Processing is new |
| 13682 |
Generic_Check_Choices |
| 13683 |
(Process_Empty_Choice => No_OP, |
| 13684 |
Process_Non_Static_Choice => Non_Static_Choice_Error, |
| 13685 |
Process_Associated_Node => Process_Declarations); |
| 13686 |
use Variant_Choices_Processing; |
| 13687 |
|
| 13688 |
----------------------------- |
| 13689 |
-- Non_Static_Choice_Error -- |
| 13690 |
----------------------------- |
| 13691 |
|
| 13692 |
procedure Non_Static_Choice_Error (Choice : Node_Id) is |
| 13693 |
begin |
| 13694 |
Flag_Non_Static_Expr |
| 13695 |
("choice given in variant part is not static!", Choice); |
| 13696 |
end Non_Static_Choice_Error; |
| 13697 |
|
| 13698 |
-------------------------- |
| 13699 |
-- Process_Declarations -- |
| 13700 |
-------------------------- |
| 13701 |
|
| 13702 |
procedure Process_Declarations (Variant : Node_Id) is |
| 13703 |
CL : constant Node_Id := Component_List (Variant); |
| 13704 |
VP : Node_Id; |
| 13705 |
|
| 13706 |
begin |
| 13707 |
-- Check for static predicate present in this variant |
| 13708 |
|
| 13709 |
if Has_SP_Choice (Variant) then |
| 13710 |
|
| 13711 |
-- Here we expand. You might expect to find this call in |
| 13712 |
-- Expand_N_Variant_Part, but that is called when we first |
| 13713 |
-- see the variant part, and we cannot do this expansion |
| 13714 |
-- earlier than the freeze point, since for statically |
| 13715 |
-- predicated subtypes, the predicate is not known till |
| 13716 |
-- the freeze point. |
| 13717 |
|
| 13718 |
-- Furthermore, we do this expansion even if the expander |
| 13719 |
-- is not active, because other semantic processing, e.g. |
| 13720 |
-- for aggregates, requires the expanded list of choices. |
| 13721 |
|
| 13722 |
-- If the expander is not active, then we can't just clobber |
| 13723 |
-- the list since it would invalidate the tree. |
| 13724 |
-- So we have to rewrite the variant part with a Rewrite |
| 13725 |
-- call that replaces it with a copy and clobber the copy. |
| 13726 |
|
| 13727 |
if not Expander_Active then |
| 13728 |
declare |
| 13729 |
NewV : constant Node_Id := New_Copy (Variant); |
| 13730 |
begin |
| 13731 |
Set_Discrete_Choices |
| 13732 |
(NewV, New_Copy_List (Discrete_Choices (Variant))); |
| 13733 |
Rewrite (Variant, NewV); |
| 13734 |
end; |
| 13735 |
end if; |
| 13736 |
|
| 13737 |
Expand_Static_Predicates_In_Choices (Variant); |
| 13738 |
end if; |
| 13739 |
|
| 13740 |
-- We don't need to worry about the declarations in the variant |
| 13741 |
-- (since they were analyzed by Analyze_Choices when we first |
| 13742 |
-- encountered the variant), but we do need to take care of |
| 13743 |
-- expansion of any nested variants. |
| 13744 |
|
| 13745 |
if not Null_Present (CL) then |
| 13746 |
VP := Variant_Part (CL); |
| 13747 |
|
| 13748 |
if Present (VP) then |
| 13749 |
Check_Choices |
| 13750 |
(VP, Variants (VP), Etype (Name (VP)), Others_Present); |
| 13751 |
end if; |
| 13752 |
end if; |
| 13753 |
end Process_Declarations; |
| 13754 |
|
| 13755 |
-- Start of processing for Check_Variant_Part |
| 13756 |
|
| 13757 |
begin |
| 13758 |
-- Find component list |
| 13759 |
|
| 13760 |
C := Empty; |
| 13761 |
|
| 13762 |
if Nkind (D) = N_Full_Type_Declaration then |
| 13763 |
T := Type_Definition (D); |
| 13764 |
|
| 13765 |
if Nkind (T) = N_Record_Definition then |
| 13766 |
C := Component_List (T); |
| 13767 |
|
| 13768 |
elsif Nkind (T) = N_Derived_Type_Definition |
| 13769 |
and then Present (Record_Extension_Part (T)) |
| 13770 |
then |
| 13771 |
C := Component_List (Record_Extension_Part (T)); |
| 13772 |
end if; |
| 13773 |
end if; |
| 13774 |
|
| 13775 |
-- Case of variant part present |
| 13776 |
|
| 13777 |
if Present (C) and then Present (Variant_Part (C)) then |
| 13778 |
VP := Variant_Part (C); |
| 13779 |
|
| 13780 |
-- Check choices |
| 13781 |
|
| 13782 |
Check_Choices |
| 13783 |
(VP, Variants (VP), Etype (Name (VP)), Others_Present); |
| 13784 |
|
| 13785 |
-- If the last variant does not contain the Others choice, |
| 13786 |
-- replace it with an N_Others_Choice node since Gigi always |
| 13787 |
-- wants an Others. Note that we do not bother to call Analyze |
| 13788 |
-- on the modified variant part, since its only effect would be |
| 13789 |
-- to compute the Others_Discrete_Choices node laboriously, and |
| 13790 |
-- of course we already know the list of choices corresponding |
| 13791 |
-- to the others choice (it's the list we're replacing). |
| 13792 |
|
| 13793 |
-- We only want to do this if the expander is active, since |
| 13794 |
-- we do not want to clobber the tree. |
| 13795 |
|
| 13796 |
if Expander_Active then |
| 13797 |
declare |
| 13798 |
Last_Var : constant Node_Id := |
| 13799 |
Last_Non_Pragma (Variants (VP)); |
| 13800 |
|
| 13801 |
Others_Node : Node_Id; |
| 13802 |
|
| 13803 |
begin |
| 13804 |
if Nkind (First (Discrete_Choices (Last_Var))) /= |
| 13805 |
N_Others_Choice |
| 13806 |
then |
| 13807 |
Others_Node := Make_Others_Choice (Sloc (Last_Var)); |
| 13808 |
Set_Others_Discrete_Choices |
| 13809 |
(Others_Node, Discrete_Choices (Last_Var)); |
| 13810 |
Set_Discrete_Choices |
| 13811 |
(Last_Var, New_List (Others_Node)); |
| 13812 |
end if; |
| 13813 |
end; |
| 13814 |
end if; |
| 13815 |
end if; |
| 13816 |
end Check_Variant_Part; |
| 13817 |
end if; |
| 13818 |
|
| 13819 |
-- If we have a type with predicates, build predicate function. This is |
| 13820 |
-- not needed in the generic case, nor within e.g. TSS subprograms and |
| 13821 |
-- other predefined primitives. For a derived type, ensure that the |
| 13822 |
-- parent type is already frozen so that its predicate function has been |
| 13823 |
-- constructed already. This is necessary if the parent is declared |
| 13824 |
-- in a nested package and its own freeze point has not been reached. |
| 13825 |
|
| 13826 |
if Is_Type (E) |
| 13827 |
and then Nongeneric_Case |
| 13828 |
and then Has_Predicates (E) |
| 13829 |
and then Predicate_Check_In_Scope (N) |
| 13830 |
then |
| 13831 |
declare |
| 13832 |
Atyp : constant Entity_Id := Nearest_Ancestor (E); |
| 13833 |
|
| 13834 |
begin |
| 13835 |
if Present (Atyp) |
| 13836 |
and then Has_Predicates (Atyp) |
| 13837 |
and then not Is_Frozen (Atyp) |
| 13838 |
then |
| 13839 |
Freeze_Before (N, Atyp); |
| 13840 |
end if; |
| 13841 |
end; |
| 13842 |
|
| 13843 |
-- Before we build a predicate function, ensure that discriminant |
| 13844 |
-- checking functions are available. The predicate function might |
| 13845 |
-- need to call these functions if the predicate references any |
| 13846 |
-- components declared in a variant part. |
| 13847 |
|
| 13848 |
if Ekind (E) = E_Record_Type and then Has_Discriminants (E) then |
| 13849 |
Build_Or_Copy_Discr_Checking_Funcs (Parent (E)); |
| 13850 |
end if; |
| 13851 |
|
| 13852 |
Build_Predicate_Function (E, N); |
| 13853 |
end if; |
| 13854 |
|
| 13855 |
-- If type has delayed aspects, this is where we do the preanalysis at |
| 13856 |
-- the freeze point, as part of the consistent visibility check. Note |
| 13857 |
-- that this must be done after calling Build_Predicate_Function or |
| 13858 |
-- Build_Invariant_Procedure since these subprograms fix occurrences of |
| 13859 |
-- the subtype name in the saved expression so that they will not cause |
| 13860 |
-- trouble in the preanalysis. |
| 13861 |
|
| 13862 |
-- This is also not needed in the generic case |
| 13863 |
|
| 13864 |
if Nongeneric_Case |
| 13865 |
and then Has_Delayed_Aspects (E) |
| 13866 |
and then Scope (E) = Current_Scope |
| 13867 |
then |
| 13868 |
declare |
| 13869 |
Ritem : Node_Id; |
| 13870 |
|
| 13871 |
begin |
| 13872 |
-- Look for aspect specification entries for this entity |
| 13873 |
|
| 13874 |
Ritem := First_Rep_Item (E); |
| 13875 |
while Present (Ritem) loop |
| 13876 |
if Nkind (Ritem) = N_Aspect_Specification |
| 13877 |
and then Entity (Ritem) = E |
| 13878 |
and then Is_Delayed_Aspect (Ritem) |
| 13879 |
then |
| 13880 |
if Get_Aspect_Id (Ritem) in Aspect_CPU |
| 13881 |
| Aspect_Dynamic_Predicate |
| 13882 |
| Aspect_Ghost_Predicate |
| 13883 |
| Aspect_Interrupt_Priority |
| 13884 |
| Aspect_Predicate |
| 13885 |
| Aspect_Static_Predicate |
| 13886 |
| Aspect_Priority |
| 13887 |
then |
| 13888 |
-- Retrieve the visibility to components and discriminants |
| 13889 |
-- in order to properly analyze the aspects. |
| 13890 |
|
| 13891 |
Push_Type (E); |
| 13892 |
Check_Aspect_At_Freeze_Point (Ritem); |
| 13893 |
|
| 13894 |
-- In the case of predicate aspects, there will be |
| 13895 |
-- a corresponding Predicate pragma associated with |
| 13896 |
-- the aspect, and the expression of the pragma also |
| 13897 |
-- needs to be analyzed at this point, to ensure that |
| 13898 |
-- Save_Global_References will capture global refs in |
| 13899 |
-- expressions that occur in generic bodies, for proper |
| 13900 |
-- later resolution of the pragma in instantiations. |
| 13901 |
|
| 13902 |
if Is_Type (E) |
| 13903 |
and then Inside_A_Generic |
| 13904 |
and then Has_Predicates (E) |
| 13905 |
and then Present (Aspect_Rep_Item (Ritem)) |
| 13906 |
then |
| 13907 |
declare |
| 13908 |
Pragma_Args : constant List_Id := |
| 13909 |
Pragma_Argument_Associations |
| 13910 |
(Aspect_Rep_Item (Ritem)); |
| 13911 |
Pragma_Expr : constant Node_Id := |
| 13912 |
Expression (Next (First (Pragma_Args))); |
| 13913 |
begin |
| 13914 |
if Present (Pragma_Expr) then |
| 13915 |
Analyze_And_Resolve |
| 13916 |
(Pragma_Expr, Standard_Boolean); |
| 13917 |
end if; |
| 13918 |
end; |
| 13919 |
end if; |
| 13920 |
|
| 13921 |
Pop_Type (E); |
| 13922 |
|
| 13923 |
else |
| 13924 |
Check_Aspect_At_Freeze_Point (Ritem); |
| 13925 |
end if; |
| 13926 |
|
| 13927 |
-- A pragma Predicate should be checked like one of the |
| 13928 |
-- corresponding aspects, wrt possible misuse of ghost |
| 13929 |
-- entities. |
| 13930 |
|
| 13931 |
elsif Nkind (Ritem) = N_Pragma |
| 13932 |
and then No (Corresponding_Aspect (Ritem)) |
| 13933 |
and then |
| 13934 |
Get_Pragma_Id (Pragma_Name (Ritem)) = Pragma_Predicate |
| 13935 |
then |
| 13936 |
-- Retrieve the visibility to components and discriminants |
| 13937 |
-- in order to properly analyze the pragma. |
| 13938 |
|
| 13939 |
declare |
| 13940 |
Arg : constant Node_Id := |
| 13941 |
Next (First (Pragma_Argument_Associations (Ritem))); |
| 13942 |
begin |
| 13943 |
Push_Type (E); |
| 13944 |
Preanalyze_Spec_Expression |
| 13945 |
(Expression (Arg), Standard_Boolean); |
| 13946 |
Pop_Type (E); |
| 13947 |
end; |
| 13948 |
end if; |
| 13949 |
|
| 13950 |
Next_Rep_Item (Ritem); |
| 13951 |
end loop; |
| 13952 |
end; |
| 13953 |
end if; |
| 13954 |
|
| 13955 |
if not In_Generic_Scope (E) |
| 13956 |
and then Ekind (E) = E_Record_Type |
| 13957 |
and then Is_Tagged_Type (E) |
| 13958 |
then |
| 13959 |
Process_Class_Conditions_At_Freeze_Point (E); |
| 13960 |
end if; |
| 13961 |
end Freeze_Entity_Checks; |
| 13962 |
|
| 13963 |
------------------------- |
| 13964 |
-- Get_Alignment_Value -- |
| 13965 |
------------------------- |
| 13966 |
|
| 13967 |
function Get_Alignment_Value (Expr : Node_Id) return Uint is |
| 13968 |
Align : constant Uint := Static_Integer (Expr); |
| 13969 |
|
| 13970 |
begin |
| 13971 |
if No (Align) then |
| 13972 |
return No_Uint; |
| 13973 |
|
| 13974 |
elsif Align < 0 then |
| 13975 |
Error_Msg_N ("alignment value must be positive", Expr); |
| 13976 |
return No_Uint; |
| 13977 |
|
| 13978 |
-- If Alignment is specified to be 0, we treat it the same as 1 |
| 13979 |
|
| 13980 |
elsif Align = 0 then |
| 13981 |
return Uint_1; |
| 13982 |
|
| 13983 |
else |
| 13984 |
for J in Int range 0 .. 64 loop |
| 13985 |
declare |
| 13986 |
M : constant Uint := Uint_2 ** J; |
| 13987 |
|
| 13988 |
begin |
| 13989 |
exit when M = Align; |
| 13990 |
|
| 13991 |
if M > Align then |
| 13992 |
Error_Msg_N ("alignment value must be power of 2", Expr); |
| 13993 |
return No_Uint; |
| 13994 |
end if; |
| 13995 |
end; |
| 13996 |
end loop; |
| 13997 |
|
| 13998 |
return Align; |
| 13999 |
end if; |
| 14000 |
end Get_Alignment_Value; |
| 14001 |
|
| 14002 |
----------------------------------- |
| 14003 |
-- Has_Compatible_Representation -- |
| 14004 |
----------------------------------- |
| 14005 |
|
| 14006 |
function Has_Compatible_Representation |
| 14007 |
(Target_Typ, Operand_Typ : Entity_Id) return Boolean |
| 14008 |
is |
| 14009 |
-- The subtype-specific representation attributes (Size and Alignment) |
| 14010 |
-- do not affect representation from the point of view of this function. |
| 14011 |
|
| 14012 |
T1 : constant Entity_Id := Implementation_Base_Type (Target_Typ); |
| 14013 |
T2 : constant Entity_Id := Implementation_Base_Type (Operand_Typ); |
| 14014 |
|
| 14015 |
begin |
| 14016 |
-- Return true immediately for the same base type |
| 14017 |
|
| 14018 |
if T1 = T2 then |
| 14019 |
return True; |
| 14020 |
|
| 14021 |
-- Tagged types always have the same representation, because it is not |
| 14022 |
-- possible to specify different representations for common fields. |
| 14023 |
|
| 14024 |
elsif Is_Tagged_Type (T1) then |
| 14025 |
return True; |
| 14026 |
|
| 14027 |
-- Representations are definitely different if conventions differ |
| 14028 |
|
| 14029 |
elsif Convention (T1) /= Convention (T2) then |
| 14030 |
return False; |
| 14031 |
|
| 14032 |
-- Representations are different if component alignments or scalar |
| 14033 |
-- storage orders differ. |
| 14034 |
|
| 14035 |
elsif (Is_Record_Type (T1) or else Is_Array_Type (T1)) |
| 14036 |
and then |
| 14037 |
(Is_Record_Type (T2) or else Is_Array_Type (T2)) |
| 14038 |
and then (Component_Alignment (T1) /= Component_Alignment (T2) |
| 14039 |
or else |
| 14040 |
Reverse_Storage_Order (T1) /= Reverse_Storage_Order (T2)) |
| 14041 |
then |
| 14042 |
return False; |
| 14043 |
end if; |
| 14044 |
|
| 14045 |
-- For arrays, the only real issue is component size. If we know the |
| 14046 |
-- component size for both arrays, and it is the same, then that's |
| 14047 |
-- good enough to know we don't have a change of representation. |
| 14048 |
|
| 14049 |
if Is_Array_Type (T1) then |
| 14050 |
|
| 14051 |
-- In a view conversion, if the target type is an array type having |
| 14052 |
-- aliased components and the operand type is an array type having |
| 14053 |
-- unaliased components, then a new object is created (4.6(58.3/4)). |
| 14054 |
|
| 14055 |
if Has_Aliased_Components (T1) |
| 14056 |
and then not Has_Aliased_Components (T2) |
| 14057 |
then |
| 14058 |
return False; |
| 14059 |
end if; |
| 14060 |
|
| 14061 |
if Known_Component_Size (T1) |
| 14062 |
and then Known_Component_Size (T2) |
| 14063 |
and then Component_Size (T1) = Component_Size (T2) |
| 14064 |
then |
| 14065 |
return True; |
| 14066 |
end if; |
| 14067 |
|
| 14068 |
-- For records, representations are different if reordering differs |
| 14069 |
|
| 14070 |
elsif Is_Record_Type (T1) |
| 14071 |
and then Is_Record_Type (T2) |
| 14072 |
and then No_Reordering (T1) /= No_Reordering (T2) |
| 14073 |
then |
| 14074 |
return False; |
| 14075 |
end if; |
| 14076 |
|
| 14077 |
-- Types definitely have same representation if neither has non-standard |
| 14078 |
-- representation since default representations are always consistent. |
| 14079 |
-- If only one has non-standard representation, and the other does not, |
| 14080 |
-- then we consider that they do not have the same representation. They |
| 14081 |
-- might, but there is no way of telling early enough. |
| 14082 |
|
| 14083 |
if Has_Non_Standard_Rep (T1) then |
| 14084 |
if not Has_Non_Standard_Rep (T2) then |
| 14085 |
return False; |
| 14086 |
end if; |
| 14087 |
else |
| 14088 |
return not Has_Non_Standard_Rep (T2); |
| 14089 |
end if; |
| 14090 |
|
| 14091 |
-- Here the two types both have non-standard representation, and we need |
| 14092 |
-- to determine if they have the same non-standard representation. |
| 14093 |
|
| 14094 |
-- For arrays, we simply need to test if the component sizes are the |
| 14095 |
-- same. Pragma Pack is reflected in modified component sizes, so this |
| 14096 |
-- check also deals with pragma Pack. |
| 14097 |
|
| 14098 |
if Is_Array_Type (T1) then |
| 14099 |
return Component_Size (T1) = Component_Size (T2); |
| 14100 |
|
| 14101 |
-- Case of record types |
| 14102 |
|
| 14103 |
elsif Is_Record_Type (T1) then |
| 14104 |
|
| 14105 |
-- Packed status must conform |
| 14106 |
|
| 14107 |
if Is_Packed (T1) /= Is_Packed (T2) then |
| 14108 |
return False; |
| 14109 |
|
| 14110 |
-- If the operand type is derived from the target type and no clause |
| 14111 |
-- has been given after the derivation, then the representations are |
| 14112 |
-- the same since the derived type inherits that of the parent type. |
| 14113 |
|
| 14114 |
elsif Is_Derived_Type (T2) |
| 14115 |
and then Etype (T2) = T1 |
| 14116 |
and then not Has_Record_Rep_Clause (T2) |
| 14117 |
then |
| 14118 |
return True; |
| 14119 |
|
| 14120 |
-- Otherwise we must check components. Typ2 maybe a constrained |
| 14121 |
-- subtype with fewer components, so we compare the components |
| 14122 |
-- of the base types. |
| 14123 |
|
| 14124 |
else |
| 14125 |
Record_Case : declare |
| 14126 |
CD1, CD2 : Entity_Id; |
| 14127 |
|
| 14128 |
function Same_Rep return Boolean; |
| 14129 |
-- CD1 and CD2 are either components or discriminants. This |
| 14130 |
-- function tests whether they have the same representation. |
| 14131 |
|
| 14132 |
-------------- |
| 14133 |
-- Same_Rep -- |
| 14134 |
-------------- |
| 14135 |
|
| 14136 |
function Same_Rep return Boolean is |
| 14137 |
begin |
| 14138 |
if No (Component_Clause (CD1)) then |
| 14139 |
return No (Component_Clause (CD2)); |
| 14140 |
else |
| 14141 |
-- Note: at this point, component clauses have been |
| 14142 |
-- normalized to the default bit order, so that the |
| 14143 |
-- comparison of Component_Bit_Offsets is meaningful. |
| 14144 |
|
| 14145 |
return |
| 14146 |
Present (Component_Clause (CD2)) |
| 14147 |
and then |
| 14148 |
Component_Bit_Offset (CD1) = Component_Bit_Offset (CD2) |
| 14149 |
and then |
| 14150 |
Esize (CD1) = Esize (CD2); |
| 14151 |
end if; |
| 14152 |
end Same_Rep; |
| 14153 |
|
| 14154 |
-- Start of processing for Record_Case |
| 14155 |
|
| 14156 |
begin |
| 14157 |
if Has_Discriminants (T1) then |
| 14158 |
|
| 14159 |
-- The number of discriminants may be different if the |
| 14160 |
-- derived type has fewer (constrained by values). The |
| 14161 |
-- invisible discriminants retain the representation of |
| 14162 |
-- the original, so the discrepancy does not per se |
| 14163 |
-- indicate a different representation. |
| 14164 |
|
| 14165 |
CD1 := First_Discriminant (T1); |
| 14166 |
CD2 := First_Discriminant (T2); |
| 14167 |
while Present (CD1) and then Present (CD2) loop |
| 14168 |
if not Same_Rep then |
| 14169 |
return False; |
| 14170 |
else |
| 14171 |
Next_Discriminant (CD1); |
| 14172 |
Next_Discriminant (CD2); |
| 14173 |
end if; |
| 14174 |
end loop; |
| 14175 |
end if; |
| 14176 |
|
| 14177 |
CD1 := First_Component (Underlying_Type (Base_Type (T1))); |
| 14178 |
CD2 := First_Component (Underlying_Type (Base_Type (T2))); |
| 14179 |
while Present (CD1) loop |
| 14180 |
if not Same_Rep then |
| 14181 |
return False; |
| 14182 |
else |
| 14183 |
Next_Component (CD1); |
| 14184 |
Next_Component (CD2); |
| 14185 |
end if; |
| 14186 |
end loop; |
| 14187 |
|
| 14188 |
return True; |
| 14189 |
end Record_Case; |
| 14190 |
end if; |
| 14191 |
|
| 14192 |
-- For enumeration types, we must check each literal to see if the |
| 14193 |
-- representation is the same. Note that we do not permit enumeration |
| 14194 |
-- representation clauses for Character and Wide_Character, so these |
| 14195 |
-- cases were already dealt with. |
| 14196 |
|
| 14197 |
elsif Is_Enumeration_Type (T1) then |
| 14198 |
Enumeration_Case : declare |
| 14199 |
L1, L2 : Entity_Id; |
| 14200 |
|
| 14201 |
begin |
| 14202 |
L1 := First_Literal (T1); |
| 14203 |
L2 := First_Literal (T2); |
| 14204 |
while Present (L1) loop |
| 14205 |
if Enumeration_Rep (L1) /= Enumeration_Rep (L2) then |
| 14206 |
return False; |
| 14207 |
else |
| 14208 |
Next_Literal (L1); |
| 14209 |
Next_Literal (L2); |
| 14210 |
end if; |
| 14211 |
end loop; |
| 14212 |
|
| 14213 |
return True; |
| 14214 |
end Enumeration_Case; |
| 14215 |
|
| 14216 |
-- Any other types have the same representation for these purposes |
| 14217 |
|
| 14218 |
else |
| 14219 |
return True; |
| 14220 |
end if; |
| 14221 |
end Has_Compatible_Representation; |
| 14222 |
|
| 14223 |
------------------------------------- |
| 14224 |
-- Inherit_Aspects_At_Freeze_Point -- |
| 14225 |
------------------------------------- |
| 14226 |
|
| 14227 |
procedure Inherit_Aspects_At_Freeze_Point (Typ : Entity_Id) is |
| 14228 |
function Get_Inherited_Rep_Item |
| 14229 |
(E : Entity_Id; |
| 14230 |
Nam : Name_Id) return Node_Id; |
| 14231 |
-- Search the Rep_Item chain of entity E for an instance of a rep item |
| 14232 |
-- (pragma, attribute definition clause, or aspect specification) whose |
| 14233 |
-- name matches the given name Nam, and that has been inherited from its |
| 14234 |
-- parent, i.e. that has not been directly specified for E . If one is |
| 14235 |
-- found, it is returned, otherwise Empty is returned. |
| 14236 |
|
| 14237 |
function Get_Inherited_Rep_Item |
| 14238 |
(E : Entity_Id; |
| 14239 |
Nam1 : Name_Id; |
| 14240 |
Nam2 : Name_Id) return Node_Id; |
| 14241 |
-- Search the Rep_Item chain of entity E for an instance of a rep item |
| 14242 |
-- (pragma, attribute definition clause, or aspect specification) whose |
| 14243 |
-- name matches one of the given names Nam1 or Nam2, and that has been |
| 14244 |
-- inherited from its parent, i.e. that has not been directly specified |
| 14245 |
-- for E . If one is found, it is returned, otherwise Empty is returned. |
| 14246 |
|
| 14247 |
function Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item |
| 14248 |
(Rep_Item : Node_Id) return Boolean; |
| 14249 |
-- This routine checks if Rep_Item is either a pragma or an aspect |
| 14250 |
-- specification node whose corresponding pragma (if any) is present in |
| 14251 |
-- the Rep Item chain of the entity it has been specified to. |
| 14252 |
|
| 14253 |
---------------------------- |
| 14254 |
-- Get_Inherited_Rep_Item -- |
| 14255 |
---------------------------- |
| 14256 |
|
| 14257 |
function Get_Inherited_Rep_Item |
| 14258 |
(E : Entity_Id; |
| 14259 |
Nam : Name_Id) return Node_Id |
| 14260 |
is |
| 14261 |
Rep : constant Node_Id := |
| 14262 |
Get_Rep_Item (E, Nam, Check_Parents => True); |
| 14263 |
begin |
| 14264 |
if Present (Rep) |
| 14265 |
and then not Has_Rep_Item (E, Nam, Check_Parents => False) |
| 14266 |
then |
| 14267 |
return Rep; |
| 14268 |
else |
| 14269 |
return Empty; |
| 14270 |
end if; |
| 14271 |
end Get_Inherited_Rep_Item; |
| 14272 |
|
| 14273 |
function Get_Inherited_Rep_Item |
| 14274 |
(E : Entity_Id; |
| 14275 |
Nam1 : Name_Id; |
| 14276 |
Nam2 : Name_Id) return Node_Id |
| 14277 |
is |
| 14278 |
Rep : constant Node_Id := |
| 14279 |
Get_Rep_Item (E, Nam1, Nam2, Check_Parents => True); |
| 14280 |
begin |
| 14281 |
if Present (Rep) |
| 14282 |
and then not Has_Rep_Item (E, Nam1, Nam2, Check_Parents => False) |
| 14283 |
then |
| 14284 |
return Rep; |
| 14285 |
else |
| 14286 |
return Empty; |
| 14287 |
end if; |
| 14288 |
end Get_Inherited_Rep_Item; |
| 14289 |
|
| 14290 |
-------------------------------------------------- |
| 14291 |
-- Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item -- |
| 14292 |
-------------------------------------------------- |
| 14293 |
|
| 14294 |
function Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item |
| 14295 |
(Rep_Item : Node_Id) return Boolean |
| 14296 |
is |
| 14297 |
begin |
| 14298 |
return |
| 14299 |
Nkind (Rep_Item) = N_Pragma |
| 14300 |
or else |
| 14301 |
Present_In_Rep_Item (Entity (Rep_Item), Aspect_Rep_Item (Rep_Item)); |
| 14302 |
end Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item; |
| 14303 |
|
| 14304 |
Rep : Node_Id; |
| 14305 |
|
| 14306 |
-- Start of processing for Inherit_Aspects_At_Freeze_Point |
| 14307 |
|
| 14308 |
begin |
| 14309 |
-- A representation item is either subtype-specific (Size and Alignment |
| 14310 |
-- clauses) or type-related (all others). Subtype-specific aspects may |
| 14311 |
-- differ for different subtypes of the same type (RM 13.1.8). |
| 14312 |
|
| 14313 |
-- A derived type inherits each type-related representation aspect of |
| 14314 |
-- its parent type that was directly specified before the declaration of |
| 14315 |
-- the derived type (RM 13.1.15). |
| 14316 |
|
| 14317 |
-- A derived subtype inherits each subtype-specific representation |
| 14318 |
-- aspect of its parent subtype that was directly specified before the |
| 14319 |
-- declaration of the derived type (RM 13.1.15). |
| 14320 |
|
| 14321 |
-- The general processing involves inheriting a representation aspect |
| 14322 |
-- from a parent type whenever the first rep item (aspect specification, |
| 14323 |
-- attribute definition clause, pragma) corresponding to the given |
| 14324 |
-- representation aspect in the rep item chain of Typ, if any, isn't |
| 14325 |
-- directly specified to Typ but to one of its parents. |
| 14326 |
|
| 14327 |
-- In addition, Convention must be propagated from base type to subtype, |
| 14328 |
-- because the subtype may have been declared on an incomplete view. |
| 14329 |
|
| 14330 |
if Nkind (Parent (Typ)) = N_Private_Extension_Declaration then |
| 14331 |
return; |
| 14332 |
end if; |
| 14333 |
|
| 14334 |
-- Ada_05/Ada_2005 |
| 14335 |
|
| 14336 |
Rep := Get_Inherited_Rep_Item (Typ, Name_Ada_05, Name_Ada_2005); |
| 14337 |
if Present (Rep) |
| 14338 |
and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item (Rep) |
| 14339 |
then |
| 14340 |
Set_Is_Ada_2005_Only (Typ); |
| 14341 |
end if; |
| 14342 |
|
| 14343 |
-- Ada_12/Ada_2012 |
| 14344 |
|
| 14345 |
Rep := Get_Inherited_Rep_Item (Typ, Name_Ada_12, Name_Ada_2012); |
| 14346 |
if Present (Rep) |
| 14347 |
and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item (Rep) |
| 14348 |
then |
| 14349 |
Set_Is_Ada_2012_Only (Typ); |
| 14350 |
end if; |
| 14351 |
|
| 14352 |
-- Ada_2022 |
| 14353 |
|
| 14354 |
Rep := Get_Inherited_Rep_Item (Typ, Name_Ada_2022); |
| 14355 |
if Present (Rep) |
| 14356 |
and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item (Rep) |
| 14357 |
then |
| 14358 |
Set_Is_Ada_2022_Only (Typ); |
| 14359 |
end if; |
| 14360 |
|
| 14361 |
-- Atomic/Shared |
| 14362 |
|
| 14363 |
Rep := Get_Inherited_Rep_Item (Typ, Name_Atomic, Name_Shared); |
| 14364 |
if Present (Rep) |
| 14365 |
and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item (Rep) |
| 14366 |
then |
| 14367 |
Set_Is_Atomic (Typ); |
| 14368 |
Set_Is_Volatile (Typ); |
| 14369 |
Set_Treat_As_Volatile (Typ); |
| 14370 |
end if; |
| 14371 |
|
| 14372 |
-- Convention |
| 14373 |
|
| 14374 |
if Is_Record_Type (Typ) |
| 14375 |
and then Typ /= Base_Type (Typ) and then Is_Frozen (Base_Type (Typ)) |
| 14376 |
then |
| 14377 |
Set_Convention (Typ, Convention (Base_Type (Typ))); |
| 14378 |
end if; |
| 14379 |
|
| 14380 |
-- Default_Component_Value (for base types only) |
| 14381 |
|
| 14382 |
-- Note that we need to look into the first subtype because the base |
| 14383 |
-- type may be the implicit base type built by the compiler for the |
| 14384 |
-- declaration of a constrained subtype with the aspect. |
| 14385 |
|
| 14386 |
if Is_Array_Type (Typ) and then Is_Base_Type (Typ) then |
| 14387 |
declare |
| 14388 |
F_Typ : constant Entity_Id := First_Subtype (Typ); |
| 14389 |
|
| 14390 |
E : Entity_Id; |
| 14391 |
|
| 14392 |
begin |
| 14393 |
Rep := |
| 14394 |
Get_Inherited_Rep_Item (F_Typ, Name_Default_Component_Value); |
| 14395 |
if Present (Rep) then |
| 14396 |
E := Entity (Rep); |
| 14397 |
|
| 14398 |
-- Deal with private types |
| 14399 |
|
| 14400 |
if Is_Private_Type (E) then |
| 14401 |
E := Full_View (E); |
| 14402 |
end if; |
| 14403 |
|
| 14404 |
Set_Default_Aspect_Component_Value |
| 14405 |
(Typ, Default_Aspect_Component_Value (E)); |
| 14406 |
Set_Has_Default_Aspect (Typ); |
| 14407 |
end if; |
| 14408 |
end; |
| 14409 |
end if; |
| 14410 |
|
| 14411 |
-- Default_Value (for base types only) |
| 14412 |
|
| 14413 |
-- Note that we need to look into the first subtype because the base |
| 14414 |
-- type may be the implicit base type built by the compiler for the |
| 14415 |
-- declaration of a constrained subtype with the aspect. |
| 14416 |
|
| 14417 |
if Is_Scalar_Type (Typ) and then Is_Base_Type (Typ) then |
| 14418 |
declare |
| 14419 |
F_Typ : constant Entity_Id := First_Subtype (Typ); |
| 14420 |
|
| 14421 |
E : Entity_Id; |
| 14422 |
|
| 14423 |
begin |
| 14424 |
Rep := Get_Inherited_Rep_Item (F_Typ, Name_Default_Value); |
| 14425 |
if Present (Rep) then |
| 14426 |
E := Entity (Rep); |
| 14427 |
|
| 14428 |
-- Deal with private types |
| 14429 |
|
| 14430 |
if Is_Private_Type (E) then |
| 14431 |
E := Full_View (E); |
| 14432 |
end if; |
| 14433 |
|
| 14434 |
Set_Default_Aspect_Value (Typ, Default_Aspect_Value (E)); |
| 14435 |
Set_Has_Default_Aspect (Typ); |
| 14436 |
end if; |
| 14437 |
end; |
| 14438 |
end if; |
| 14439 |
|
| 14440 |
-- Discard_Names |
| 14441 |
|
| 14442 |
Rep := Get_Inherited_Rep_Item (Typ, Name_Discard_Names); |
| 14443 |
if Present (Rep) |
| 14444 |
and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item (Rep) |
| 14445 |
then |
| 14446 |
Set_Discard_Names (Typ); |
| 14447 |
end if; |
| 14448 |
|
| 14449 |
-- Volatile |
| 14450 |
|
| 14451 |
Rep := Get_Inherited_Rep_Item (Typ, Name_Volatile); |
| 14452 |
if Present (Rep) |
| 14453 |
and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item (Rep) |
| 14454 |
then |
| 14455 |
Set_Is_Volatile (Typ); |
| 14456 |
Set_Treat_As_Volatile (Typ); |
| 14457 |
end if; |
| 14458 |
|
| 14459 |
-- Volatile_Full_Access and Full_Access_Only |
| 14460 |
|
| 14461 |
Rep := Get_Inherited_Rep_Item |
| 14462 |
(Typ, Name_Volatile_Full_Access, Name_Full_Access_Only); |
| 14463 |
if Present (Rep) |
| 14464 |
and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item (Rep) |
| 14465 |
then |
| 14466 |
Set_Is_Volatile_Full_Access (Typ); |
| 14467 |
Set_Is_Volatile (Typ); |
| 14468 |
Set_Treat_As_Volatile (Typ); |
| 14469 |
end if; |
| 14470 |
|
| 14471 |
-- Inheritance for derived types only |
| 14472 |
|
| 14473 |
if Is_Derived_Type (Typ) then |
| 14474 |
declare |
| 14475 |
Bas_Typ : constant Entity_Id := Base_Type (Typ); |
| 14476 |
Imp_Bas_Typ : constant Entity_Id := Implementation_Base_Type (Typ); |
| 14477 |
|
| 14478 |
begin |
| 14479 |
-- Atomic_Components |
| 14480 |
|
| 14481 |
Rep := Get_Inherited_Rep_Item (Typ, Name_Atomic_Components); |
| 14482 |
if Present (Rep) |
| 14483 |
and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item (Rep) |
| 14484 |
then |
| 14485 |
Set_Has_Atomic_Components (Imp_Bas_Typ); |
| 14486 |
end if; |
| 14487 |
|
| 14488 |
-- Volatile_Components |
| 14489 |
|
| 14490 |
Rep := Get_Inherited_Rep_Item (Typ, Name_Volatile_Components); |
| 14491 |
if Present (Rep) |
| 14492 |
and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item (Rep) |
| 14493 |
then |
| 14494 |
Set_Has_Volatile_Components (Imp_Bas_Typ); |
| 14495 |
end if; |
| 14496 |
|
| 14497 |
-- Universal_Aliasing |
| 14498 |
|
| 14499 |
Rep := Get_Inherited_Rep_Item (Typ, Name_Universal_Aliasing); |
| 14500 |
if Present (Rep) |
| 14501 |
and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item (Rep) |
| 14502 |
then |
| 14503 |
Set_Universal_Aliasing (Imp_Bas_Typ); |
| 14504 |
end if; |
| 14505 |
|
| 14506 |
-- Bit_Order |
| 14507 |
|
| 14508 |
if Is_Record_Type (Typ) and then Typ = Bas_Typ then |
| 14509 |
Rep := Get_Inherited_Rep_Item (Typ, Name_Bit_Order); |
| 14510 |
if Present (Rep) then |
| 14511 |
Set_Reverse_Bit_Order (Bas_Typ, |
| 14512 |
Reverse_Bit_Order |
| 14513 |
(Implementation_Base_Type (Etype (Bas_Typ)))); |
| 14514 |
end if; |
| 14515 |
end if; |
| 14516 |
|
| 14517 |
-- Scalar_Storage_Order |
| 14518 |
|
| 14519 |
if (Is_Record_Type (Typ) or else Is_Array_Type (Typ)) |
| 14520 |
and then Typ = Bas_Typ |
| 14521 |
then |
| 14522 |
-- For a type extension, always inherit from parent; otherwise |
| 14523 |
-- inherit if no default applies. Note: we do not check for |
| 14524 |
-- an explicit rep item on the parent type when inheriting, |
| 14525 |
-- because the parent SSO may itself have been set by default. |
| 14526 |
|
| 14527 |
if not Has_Rep_Item (First_Subtype (Typ), |
| 14528 |
Name_Scalar_Storage_Order, False) |
| 14529 |
and then (Is_Tagged_Type (Bas_Typ) |
| 14530 |
or else not (SSO_Set_Low_By_Default (Bas_Typ) |
| 14531 |
or else |
| 14532 |
SSO_Set_High_By_Default (Bas_Typ))) |
| 14533 |
then |
| 14534 |
Set_Reverse_Storage_Order (Bas_Typ, |
| 14535 |
Reverse_Storage_Order |
| 14536 |
(Implementation_Base_Type (Etype (Bas_Typ)))); |
| 14537 |
|
| 14538 |
-- Clear default SSO indications, since the inherited aspect |
| 14539 |
-- which was set explicitly overrides the default. |
| 14540 |
|
| 14541 |
Set_SSO_Set_Low_By_Default (Bas_Typ, False); |
| 14542 |
Set_SSO_Set_High_By_Default (Bas_Typ, False); |
| 14543 |
end if; |
| 14544 |
end if; |
| 14545 |
|
| 14546 |
-- Finalizable |
| 14547 |
|
| 14548 |
if Is_Record_Type (Typ) and then Typ = Bas_Typ then |
| 14549 |
Rep := Get_Inherited_Rep_Item (Typ, Name_Finalizable); |
| 14550 |
if Present (Rep) then |
| 14551 |
Propagate_Controlled_Flags (Typ, Etype (Bas_Typ)); |
| 14552 |
end if; |
| 14553 |
end if; |
| 14554 |
end; |
| 14555 |
end if; |
| 14556 |
end Inherit_Aspects_At_Freeze_Point; |
| 14557 |
|
| 14558 |
--------------------------------- |
| 14559 |
-- Inherit_Delayed_Rep_Aspects -- |
| 14560 |
--------------------------------- |
| 14561 |
|
| 14562 |
procedure Inherit_Delayed_Rep_Aspects (Typ : Entity_Id) is |
| 14563 |
A : Aspect_Id; |
| 14564 |
N : Node_Id; |
| 14565 |
P : Entity_Id; |
| 14566 |
|
| 14567 |
begin |
| 14568 |
-- Find the first aspect that has been inherited |
| 14569 |
|
| 14570 |
N := First_Rep_Item (Typ); |
| 14571 |
while Present (N) loop |
| 14572 |
if Nkind (N) = N_Aspect_Specification then |
| 14573 |
exit when Entity (N) /= Typ; |
| 14574 |
end if; |
| 14575 |
|
| 14576 |
Next_Rep_Item (N); |
| 14577 |
end loop; |
| 14578 |
|
| 14579 |
-- There must be one if we reach here |
| 14580 |
|
| 14581 |
pragma Assert (Present (N)); |
| 14582 |
P := Entity (N); |
| 14583 |
|
| 14584 |
-- Loop through delayed aspects for the parent type |
| 14585 |
|
| 14586 |
while Present (N) loop |
| 14587 |
if Nkind (N) = N_Aspect_Specification then |
| 14588 |
exit when Entity (N) /= P; |
| 14589 |
|
| 14590 |
if Is_Delayed_Aspect (N) then |
| 14591 |
A := Get_Aspect_Id (N); |
| 14592 |
|
| 14593 |
-- Process delayed rep aspect. For Boolean attributes it is |
| 14594 |
-- not possible to cancel an attribute once set (the attempt |
| 14595 |
-- to use an aspect with xxx => False is an error) for a |
| 14596 |
-- derived type. So for those cases, we do not have to check |
| 14597 |
-- if a clause has been given for the derived type, since it |
| 14598 |
-- is harmless to set it again if it is already set. |
| 14599 |
|
| 14600 |
case A is |
| 14601 |
|
| 14602 |
-- Alignment |
| 14603 |
|
| 14604 |
when Aspect_Alignment => |
| 14605 |
if not Has_Alignment_Clause (Typ) then |
| 14606 |
Set_Alignment (Typ, Alignment (P)); |
| 14607 |
end if; |
| 14608 |
|
| 14609 |
-- Atomic |
| 14610 |
|
| 14611 |
when Aspect_Atomic => |
| 14612 |
if Is_Atomic (P) then |
| 14613 |
Set_Is_Atomic (Typ); |
| 14614 |
end if; |
| 14615 |
|
| 14616 |
-- Atomic_Components |
| 14617 |
|
| 14618 |
when Aspect_Atomic_Components => |
| 14619 |
if Has_Atomic_Components (P) then |
| 14620 |
Set_Has_Atomic_Components (Base_Type (Typ)); |
| 14621 |
end if; |
| 14622 |
|
| 14623 |
-- Bit_Order |
| 14624 |
|
| 14625 |
when Aspect_Bit_Order => |
| 14626 |
if Is_Record_Type (Typ) |
| 14627 |
and then No (Get_Attribute_Definition_Clause |
| 14628 |
(Typ, Attribute_Bit_Order)) |
| 14629 |
and then Reverse_Bit_Order (P) |
| 14630 |
then |
| 14631 |
Set_Reverse_Bit_Order (Base_Type (Typ)); |
| 14632 |
end if; |
| 14633 |
|
| 14634 |
-- Component_Size |
| 14635 |
|
| 14636 |
when Aspect_Component_Size => |
| 14637 |
if Is_Array_Type (Typ) |
| 14638 |
and then not Has_Component_Size_Clause (Typ) |
| 14639 |
then |
| 14640 |
Set_Component_Size |
| 14641 |
(Base_Type (Typ), Component_Size (P)); |
| 14642 |
end if; |
| 14643 |
|
| 14644 |
-- Machine_Radix |
| 14645 |
|
| 14646 |
when Aspect_Machine_Radix => |
| 14647 |
if Is_Decimal_Fixed_Point_Type (Typ) |
| 14648 |
and then not Has_Machine_Radix_Clause (Typ) |
| 14649 |
then |
| 14650 |
Set_Machine_Radix_10 (Typ, Machine_Radix_10 (P)); |
| 14651 |
end if; |
| 14652 |
|
| 14653 |
-- Object_Size (also Size which also sets Object_Size) |
| 14654 |
|
| 14655 |
when Aspect_Object_Size |
| 14656 |
| Aspect_Size |
| 14657 |
=> |
| 14658 |
if not Has_Size_Clause (Typ) |
| 14659 |
and then No (Object_Size_Clause (Typ)) |
| 14660 |
then |
| 14661 |
Set_Esize (Typ, Esize (P)); |
| 14662 |
end if; |
| 14663 |
|
| 14664 |
-- Pack |
| 14665 |
|
| 14666 |
when Aspect_Pack => |
| 14667 |
if not Is_Packed (Typ) then |
| 14668 |
Set_Is_Packed (Base_Type (Typ)); |
| 14669 |
|
| 14670 |
if Is_Bit_Packed_Array (P) then |
| 14671 |
Set_Is_Bit_Packed_Array (Base_Type (Typ)); |
| 14672 |
Set_Packed_Array_Impl_Type |
| 14673 |
(Typ, Packed_Array_Impl_Type (P)); |
| 14674 |
end if; |
| 14675 |
end if; |
| 14676 |
|
| 14677 |
-- Scalar_Storage_Order |
| 14678 |
|
| 14679 |
when Aspect_Scalar_Storage_Order => |
| 14680 |
if (Is_Record_Type (Typ) or else Is_Array_Type (Typ)) |
| 14681 |
and then No (Get_Attribute_Definition_Clause |
| 14682 |
(Typ, Attribute_Scalar_Storage_Order)) |
| 14683 |
and then Reverse_Storage_Order (P) |
| 14684 |
then |
| 14685 |
Set_Reverse_Storage_Order (Base_Type (Typ)); |
| 14686 |
|
| 14687 |
-- Clear default SSO indications, since the aspect |
| 14688 |
-- overrides the default. |
| 14689 |
|
| 14690 |
Set_SSO_Set_Low_By_Default (Base_Type (Typ), False); |
| 14691 |
Set_SSO_Set_High_By_Default (Base_Type (Typ), False); |
| 14692 |
end if; |
| 14693 |
|
| 14694 |
-- Small |
| 14695 |
|
| 14696 |
when Aspect_Small => |
| 14697 |
if Is_Fixed_Point_Type (Typ) |
| 14698 |
and then not Has_Small_Clause (Typ) |
| 14699 |
then |
| 14700 |
Set_Small_Value (Typ, Small_Value (P)); |
| 14701 |
end if; |
| 14702 |
|
| 14703 |
-- Storage_Size |
| 14704 |
|
| 14705 |
when Aspect_Storage_Size => |
| 14706 |
if (Is_Access_Type (Typ) or else Is_Task_Type (Typ)) |
| 14707 |
and then not Has_Storage_Size_Clause (Typ) |
| 14708 |
then |
| 14709 |
Set_Storage_Size_Variable |
| 14710 |
(Base_Type (Typ), Storage_Size_Variable (P)); |
| 14711 |
end if; |
| 14712 |
|
| 14713 |
-- Value_Size |
| 14714 |
|
| 14715 |
when Aspect_Value_Size => |
| 14716 |
|
| 14717 |
-- Value_Size is never inherited, it is either set by |
| 14718 |
-- default, or it is explicitly set for the derived |
| 14719 |
-- type. So nothing to do here. |
| 14720 |
|
| 14721 |
null; |
| 14722 |
|
| 14723 |
-- Volatile |
| 14724 |
|
| 14725 |
when Aspect_Volatile => |
| 14726 |
if Is_Volatile (P) then |
| 14727 |
Set_Is_Volatile (Typ); |
| 14728 |
end if; |
| 14729 |
|
| 14730 |
-- Volatile_Full_Access (also Full_Access_Only) |
| 14731 |
|
| 14732 |
when Aspect_Volatile_Full_Access |
| 14733 |
| Aspect_Full_Access_Only |
| 14734 |
=> |
| 14735 |
if Is_Volatile_Full_Access (P) then |
| 14736 |
Set_Is_Volatile_Full_Access (Typ); |
| 14737 |
end if; |
| 14738 |
|
| 14739 |
-- Volatile_Components |
| 14740 |
|
| 14741 |
when Aspect_Volatile_Components => |
| 14742 |
if Has_Volatile_Components (P) then |
| 14743 |
Set_Has_Volatile_Components (Base_Type (Typ)); |
| 14744 |
end if; |
| 14745 |
|
| 14746 |
-- That should be all the Rep Aspects |
| 14747 |
|
| 14748 |
when others => |
| 14749 |
pragma Assert (Aspect_Delay (A) /= Rep_Aspect); |
| 14750 |
null; |
| 14751 |
end case; |
| 14752 |
end if; |
| 14753 |
end if; |
| 14754 |
|
| 14755 |
Next_Rep_Item (N); |
| 14756 |
end loop; |
| 14757 |
end Inherit_Delayed_Rep_Aspects; |
| 14758 |
|
| 14759 |
---------------- |
| 14760 |
-- Initialize -- |
| 14761 |
---------------- |
| 14762 |
|
| 14763 |
procedure Initialize is |
| 14764 |
begin |
| 14765 |
Address_Clause_Checks.Init; |
| 14766 |
Unchecked_Conversions.Init; |
| 14767 |
|
| 14768 |
-- The following might be needed in the future for some non-GCC back |
| 14769 |
-- ends: |
| 14770 |
-- if AAMP_On_Target then |
| 14771 |
-- Independence_Checks.Init; |
| 14772 |
-- end if; |
| 14773 |
end Initialize; |
| 14774 |
|
| 14775 |
--------------------------- |
| 14776 |
-- Install_Discriminants -- |
| 14777 |
--------------------------- |
| 14778 |
|
| 14779 |
procedure Install_Discriminants (E : Entity_Id) is |
| 14780 |
Disc : Entity_Id; |
| 14781 |
Prev : Entity_Id; |
| 14782 |
begin |
| 14783 |
Disc := First_Discriminant (E); |
| 14784 |
while Present (Disc) loop |
| 14785 |
Prev := Current_Entity (Disc); |
| 14786 |
Set_Current_Entity (Disc); |
| 14787 |
Set_Is_Immediately_Visible (Disc); |
| 14788 |
Set_Homonym (Disc, Prev); |
| 14789 |
Next_Discriminant (Disc); |
| 14790 |
end loop; |
| 14791 |
end Install_Discriminants; |
| 14792 |
|
| 14793 |
------------------------- |
| 14794 |
-- Is_Operational_Item -- |
| 14795 |
------------------------- |
| 14796 |
|
| 14797 |
function Is_Operational_Item (N : Node_Id) return Boolean is |
| 14798 |
begin |
| 14799 |
-- List of operational items is given in AARM 13.1(8.mm/1). It is |
| 14800 |
-- clearly incomplete, as it does not include iterator aspects, among |
| 14801 |
-- others. |
| 14802 |
|
| 14803 |
return Nkind (N) = N_Attribute_Definition_Clause |
| 14804 |
and then |
| 14805 |
Get_Attribute_Id (Chars (N)) in Attribute_Constant_Indexing |
| 14806 |
| Attribute_External_Tag |
| 14807 |
| Attribute_Default_Iterator |
| 14808 |
| Attribute_Implicit_Dereference |
| 14809 |
| Attribute_Input |
| 14810 |
| Attribute_Iterable |
| 14811 |
| Attribute_Iterator_Element |
| 14812 |
| Attribute_Output |
| 14813 |
| Attribute_Put_Image |
| 14814 |
| Attribute_Read |
| 14815 |
| Attribute_Variable_Indexing |
| 14816 |
| Attribute_Write; |
| 14817 |
end Is_Operational_Item; |
| 14818 |
|
| 14819 |
------------------------- |
| 14820 |
-- Is_Predicate_Static -- |
| 14821 |
------------------------- |
| 14822 |
|
| 14823 |
-- Note: the basic legality of the expression has already been checked, so |
| 14824 |
-- we don't need to worry about cases or ranges on strings for example. |
| 14825 |
|
| 14826 |
function Is_Predicate_Static |
| 14827 |
(Expr : Node_Id; |
| 14828 |
Nam : Name_Id; |
| 14829 |
Warn : Boolean := True) return Boolean |
| 14830 |
is |
| 14831 |
function All_Static_Case_Alternatives (L : List_Id) return Boolean; |
| 14832 |
-- Given a list of case expression alternatives, returns True if all |
| 14833 |
-- the alternatives are static (have all static choices, and a static |
| 14834 |
-- expression). |
| 14835 |
|
| 14836 |
function Is_Type_Ref (N : Node_Id) return Boolean; |
| 14837 |
pragma Inline (Is_Type_Ref); |
| 14838 |
-- Returns True if N is a reference to the type for the predicate in the |
| 14839 |
-- expression (i.e. if it is an identifier whose Chars field matches the |
| 14840 |
-- Nam given in the call). N must not be parenthesized, if the type name |
| 14841 |
-- appears in parens, this routine will return False. |
| 14842 |
-- |
| 14843 |
-- The routine also returns True for function calls generated during the |
| 14844 |
-- expansion of comparison operators on strings, which are intended to |
| 14845 |
-- be legal in static predicates, and are converted into calls to array |
| 14846 |
-- comparison routines in the body of the corresponding predicate |
| 14847 |
-- function. |
| 14848 |
|
| 14849 |
---------------------------------- |
| 14850 |
-- All_Static_Case_Alternatives -- |
| 14851 |
---------------------------------- |
| 14852 |
|
| 14853 |
function All_Static_Case_Alternatives (L : List_Id) return Boolean is |
| 14854 |
N : Node_Id; |
| 14855 |
|
| 14856 |
begin |
| 14857 |
N := First (L); |
| 14858 |
while Present (N) loop |
| 14859 |
if not (All_Static_Choices (Discrete_Choices (N)) |
| 14860 |
and then Is_OK_Static_Expression (Expression (N))) |
| 14861 |
then |
| 14862 |
return False; |
| 14863 |
end if; |
| 14864 |
|
| 14865 |
Next (N); |
| 14866 |
end loop; |
| 14867 |
|
| 14868 |
return True; |
| 14869 |
end All_Static_Case_Alternatives; |
| 14870 |
|
| 14871 |
----------------- |
| 14872 |
-- Is_Type_Ref -- |
| 14873 |
----------------- |
| 14874 |
|
| 14875 |
function Is_Type_Ref (N : Node_Id) return Boolean is |
| 14876 |
begin |
| 14877 |
return (Nkind (N) = N_Identifier |
| 14878 |
and then Chars (N) = Nam |
| 14879 |
and then Paren_Count (N) = 0); |
| 14880 |
end Is_Type_Ref; |
| 14881 |
|
| 14882 |
-- helper function for recursive calls |
| 14883 |
function Is_Predicate_Static_Aux (Expr : Node_Id) return Boolean is |
| 14884 |
(Is_Predicate_Static (Expr, Nam, Warn => False)); |
| 14885 |
|
| 14886 |
-- Start of processing for Is_Predicate_Static |
| 14887 |
|
| 14888 |
begin |
| 14889 |
-- Handle cases like |
| 14890 |
-- subtype S is Integer with Static_Predicate => |
| 14891 |
-- (Some_Integer_Variable in Integer) and then (S /= 0); |
| 14892 |
-- where the predicate (which should be rejected) might have been |
| 14893 |
-- transformed into just "(S /= 0)", which would appear to be |
| 14894 |
-- a predicate-static expression (and therefore legal). |
| 14895 |
|
| 14896 |
if Is_Rewrite_Substitution (Expr) then |
| 14897 |
|
| 14898 |
-- Emit warnings for predicates that are always True or always False |
| 14899 |
-- and were not originally expressed as Boolean literals. |
| 14900 |
|
| 14901 |
return Result : constant Boolean := |
| 14902 |
Is_Predicate_Static_Aux (Original_Node (Expr)) |
| 14903 |
do |
| 14904 |
if Result and then Warn and then Is_Entity_Name (Expr) then |
| 14905 |
if Entity (Expr) = Standard_True then |
| 14906 |
Error_Msg_N ("predicate is redundant (always True)?", Expr); |
| 14907 |
elsif Entity (Expr) = Standard_False then |
| 14908 |
Error_Msg_N |
| 14909 |
("predicate is unsatisfiable (always False)?", Expr); |
| 14910 |
end if; |
| 14911 |
end if; |
| 14912 |
end return; |
| 14913 |
end if; |
| 14914 |
|
| 14915 |
-- Predicate_Static means one of the following holds. Numbers are the |
| 14916 |
-- corresponding paragraph numbers in (RM 3.2.4(16-22)). |
| 14917 |
|
| 14918 |
-- 16: A static expression |
| 14919 |
|
| 14920 |
if Is_OK_Static_Expression (Expr) then |
| 14921 |
return True; |
| 14922 |
|
| 14923 |
-- 17: A membership test whose simple_expression is the current |
| 14924 |
-- instance, and whose membership_choice_list meets the requirements |
| 14925 |
-- for a static membership test. |
| 14926 |
|
| 14927 |
elsif Nkind (Expr) in N_Membership_Test |
| 14928 |
and then Is_Type_Ref (Left_Opnd (Expr)) |
| 14929 |
and then All_Membership_Choices_Static (Expr) |
| 14930 |
then |
| 14931 |
return True; |
| 14932 |
|
| 14933 |
-- 18. A case_expression whose selecting_expression is the current |
| 14934 |
-- instance, and whose dependent expressions are static expressions. |
| 14935 |
|
| 14936 |
elsif Nkind (Expr) = N_Case_Expression |
| 14937 |
and then Is_Type_Ref (Expression (Expr)) |
| 14938 |
and then All_Static_Case_Alternatives (Alternatives (Expr)) |
| 14939 |
then |
| 14940 |
return True; |
| 14941 |
|
| 14942 |
-- 19. A call to a predefined equality or ordering operator, where one |
| 14943 |
-- operand is the current instance, and the other is a static |
| 14944 |
-- expression. |
| 14945 |
|
| 14946 |
-- Note: the RM is clearly wrong here in not excluding string types. |
| 14947 |
-- Without this exclusion, we would allow expressions like X > "ABC" |
| 14948 |
-- to be considered as predicate-static, which is clearly not intended, |
| 14949 |
-- since the idea is for predicate-static to be a subset of normal |
| 14950 |
-- static expressions (and "DEF" > "ABC" is not a static expression). |
| 14951 |
|
| 14952 |
-- However, we do allow internally generated (not from source) equality |
| 14953 |
-- and inequality operations to be valid on strings (this helps deal |
| 14954 |
-- with cases where we transform A in "ABC" to A = "ABC). |
| 14955 |
|
| 14956 |
-- In fact, it appears that the intent of the ARG is to extend static |
| 14957 |
-- predicates to strings, and that the extension should probably apply |
| 14958 |
-- to static expressions themselves. The code below accepts comparison |
| 14959 |
-- operators that apply to static strings. |
| 14960 |
|
| 14961 |
elsif Nkind (Expr) in N_Op_Compare |
| 14962 |
and then ((Is_Type_Ref (Left_Opnd (Expr)) |
| 14963 |
and then Is_OK_Static_Expression (Right_Opnd (Expr))) |
| 14964 |
or else |
| 14965 |
(Is_Type_Ref (Right_Opnd (Expr)) |
| 14966 |
and then Is_OK_Static_Expression (Left_Opnd (Expr)))) |
| 14967 |
then |
| 14968 |
return True; |
| 14969 |
|
| 14970 |
-- 20. A call to a predefined boolean logical operator, where each |
| 14971 |
-- operand is predicate-static. |
| 14972 |
|
| 14973 |
elsif (Nkind (Expr) in N_Op_And | N_Op_Or | N_Op_Xor |
| 14974 |
and then Is_Predicate_Static_Aux (Left_Opnd (Expr)) |
| 14975 |
and then Is_Predicate_Static_Aux (Right_Opnd (Expr))) |
| 14976 |
or else |
| 14977 |
(Nkind (Expr) = N_Op_Not |
| 14978 |
and then Is_Predicate_Static_Aux (Right_Opnd (Expr))) |
| 14979 |
then |
| 14980 |
return True; |
| 14981 |
|
| 14982 |
-- 21. A short-circuit control form where both operands are |
| 14983 |
-- predicate-static. |
| 14984 |
|
| 14985 |
elsif Nkind (Expr) in N_Short_Circuit |
| 14986 |
and then Is_Predicate_Static_Aux (Left_Opnd (Expr)) |
| 14987 |
and then Is_Predicate_Static_Aux (Right_Opnd (Expr)) |
| 14988 |
then |
| 14989 |
return True; |
| 14990 |
|
| 14991 |
-- 22. A parenthesized predicate-static expression. This does not |
| 14992 |
-- require any special test, since we just ignore paren levels in |
| 14993 |
-- all the cases above. |
| 14994 |
|
| 14995 |
-- One more test that is an implementation artifact caused by the fact |
| 14996 |
-- that we are analyzing not the original expression, but the generated |
| 14997 |
-- expression in the body of the predicate function. This can include |
| 14998 |
-- references to inherited predicates, so that the expression we are |
| 14999 |
-- processing looks like: |
| 15000 |
|
| 15001 |
-- xxPredicate (typ (Inns)) and then expression |
| 15002 |
|
| 15003 |
-- Where the call is to a Predicate function for an inherited predicate. |
| 15004 |
-- We simply ignore such a call, which could be to either a dynamic or |
| 15005 |
-- a static predicate. Note that if the parent predicate is dynamic then |
| 15006 |
-- eventually this type will be marked as dynamic, but you are allowed |
| 15007 |
-- to specify a static predicate for a subtype which is inheriting a |
| 15008 |
-- dynamic predicate, so the static predicate validation here ignores |
| 15009 |
-- the inherited predicate even if it is dynamic. |
| 15010 |
-- In all cases, a static predicate can only apply to a scalar type. |
| 15011 |
|
| 15012 |
elsif Nkind (Expr) = N_Function_Call |
| 15013 |
and then Is_Predicate_Function (Entity (Name (Expr))) |
| 15014 |
and then Is_Scalar_Type (Etype (First_Entity (Entity (Name (Expr))))) |
| 15015 |
then |
| 15016 |
return True; |
| 15017 |
|
| 15018 |
-- That's an exhaustive list of tests, all other cases are not |
| 15019 |
-- predicate-static, so we return False. |
| 15020 |
|
| 15021 |
else |
| 15022 |
return False; |
| 15023 |
end if; |
| 15024 |
end Is_Predicate_Static; |
| 15025 |
|
| 15026 |
---------------------- |
| 15027 |
-- Is_Static_Choice -- |
| 15028 |
---------------------- |
| 15029 |
|
| 15030 |
function Is_Static_Choice (N : Node_Id) return Boolean is |
| 15031 |
begin |
| 15032 |
return Nkind (N) = N_Others_Choice |
| 15033 |
or else Is_OK_Static_Expression (N) |
| 15034 |
or else (Is_Entity_Name (N) and then Is_Type (Entity (N)) |
| 15035 |
and then Is_OK_Static_Subtype (Entity (N))) |
| 15036 |
or else (Nkind (N) = N_Subtype_Indication |
| 15037 |
and then Is_OK_Static_Subtype (Entity (N))) |
| 15038 |
or else (Nkind (N) = N_Range and then Is_OK_Static_Range (N)); |
| 15039 |
end Is_Static_Choice; |
| 15040 |
|
| 15041 |
------------------------------ |
| 15042 |
-- Is_Type_Related_Rep_Item -- |
| 15043 |
------------------------------ |
| 15044 |
|
| 15045 |
function Is_Type_Related_Rep_Item (N : Node_Id) return Boolean is |
| 15046 |
begin |
| 15047 |
case Nkind (N) is |
| 15048 |
when N_Attribute_Definition_Clause => |
| 15049 |
-- See AARM 13.1(8.f-8.x) list items that end in "clause" |
| 15050 |
-- ???: include any GNAT-defined attributes here? |
| 15051 |
return Get_Attribute_Id (Chars (N)) in Attribute_Bit_Order |
| 15052 |
| Attribute_Component_Size |
| 15053 |
| Attribute_Machine_Radix |
| 15054 |
| Attribute_Storage_Pool |
| 15055 |
| Attribute_Stream_Size; |
| 15056 |
|
| 15057 |
when N_Pragma => |
| 15058 |
case Get_Pragma_Id (N) is |
| 15059 |
-- See AARM 13.1(8.f-8.x) list items that start with "pragma" |
| 15060 |
-- ???: include any GNAT-defined pragmas here? |
| 15061 |
when Pragma_Pack |
| 15062 |
| Pragma_Import |
| 15063 |
| Pragma_Export |
| 15064 |
| Pragma_Convention |
| 15065 |
| Pragma_Atomic |
| 15066 |
| Pragma_Independent |
| 15067 |
| Pragma_Volatile |
| 15068 |
| Pragma_Atomic_Components |
| 15069 |
| Pragma_Independent_Components |
| 15070 |
| Pragma_Volatile_Components |
| 15071 |
| Pragma_Discard_Names |
| 15072 |
=> |
| 15073 |
return True; |
| 15074 |
when others => |
| 15075 |
null; |
| 15076 |
end case; |
| 15077 |
|
| 15078 |
when N_Enumeration_Representation_Clause |
| 15079 |
| N_Record_Representation_Clause |
| 15080 |
=> |
| 15081 |
return True; |
| 15082 |
|
| 15083 |
when others => |
| 15084 |
null; |
| 15085 |
end case; |
| 15086 |
|
| 15087 |
return False; |
| 15088 |
end Is_Type_Related_Rep_Item; |
| 15089 |
|
| 15090 |
--------------------- |
| 15091 |
-- Kill_Rep_Clause -- |
| 15092 |
--------------------- |
| 15093 |
|
| 15094 |
procedure Kill_Rep_Clause (N : Node_Id) is |
| 15095 |
begin |
| 15096 |
pragma Assert (Ignore_Rep_Clauses); |
| 15097 |
|
| 15098 |
-- Note: we use Replace rather than Rewrite, because we don't want |
| 15099 |
-- tools to be able to use Original_Node to dig out the (undecorated) |
| 15100 |
-- rep clause that is being replaced. |
| 15101 |
|
| 15102 |
Replace (N, Make_Null_Statement (Sloc (N))); |
| 15103 |
|
| 15104 |
-- The null statement must be marked as not coming from source. This is |
| 15105 |
-- so that tools ignore it, and also the back end does not expect bogus |
| 15106 |
-- "from source" null statements in weird places (e.g. in declarative |
| 15107 |
-- regions where such null statements are not allowed). |
| 15108 |
|
| 15109 |
Set_Comes_From_Source (N, False); |
| 15110 |
end Kill_Rep_Clause; |
| 15111 |
|
| 15112 |
------------------ |
| 15113 |
-- Minimum_Size -- |
| 15114 |
------------------ |
| 15115 |
|
| 15116 |
function Minimum_Size |
| 15117 |
(T : Entity_Id; |
| 15118 |
Biased : Boolean := False) return Int |
| 15119 |
is |
| 15120 |
Lo : Uint := No_Uint; |
| 15121 |
Hi : Uint := No_Uint; |
| 15122 |
LoR : Ureal := No_Ureal; |
| 15123 |
HiR : Ureal := No_Ureal; |
| 15124 |
LoSet : Boolean := False; |
| 15125 |
HiSet : Boolean := False; |
| 15126 |
B : Uint; |
| 15127 |
S : Nat; |
| 15128 |
Ancest : Entity_Id; |
| 15129 |
R_Typ : constant Entity_Id := Root_Type (T); |
| 15130 |
|
| 15131 |
begin |
| 15132 |
-- Bad type |
| 15133 |
|
| 15134 |
if T = Any_Type then |
| 15135 |
return Unknown_Minimum_Size; |
| 15136 |
|
| 15137 |
-- For generic types, just return unknown. There cannot be any |
| 15138 |
-- legitimate need to know such a size, but this routine may be |
| 15139 |
-- called with a generic type as part of normal processing. |
| 15140 |
|
| 15141 |
elsif Is_Generic_Type (R_Typ) or else R_Typ = Any_Type then |
| 15142 |
return Unknown_Minimum_Size; |
| 15143 |
|
| 15144 |
-- Access types (cannot have size smaller than System.Address) |
| 15145 |
|
| 15146 |
elsif Is_Access_Type (T) then |
| 15147 |
return System_Address_Size; |
| 15148 |
|
| 15149 |
-- Floating-point types |
| 15150 |
|
| 15151 |
elsif Is_Floating_Point_Type (T) then |
| 15152 |
return UI_To_Int (Esize (R_Typ)); |
| 15153 |
|
| 15154 |
-- Discrete types |
| 15155 |
|
| 15156 |
elsif Is_Discrete_Type (T) then |
| 15157 |
|
| 15158 |
-- The following loop is looking for the nearest compile time known |
| 15159 |
-- bounds following the ancestor subtype chain. The idea is to find |
| 15160 |
-- the most restrictive known bounds information. |
| 15161 |
|
| 15162 |
Ancest := T; |
| 15163 |
loop |
| 15164 |
if Ancest = Any_Type or else Etype (Ancest) = Any_Type then |
| 15165 |
return Unknown_Minimum_Size; |
| 15166 |
end if; |
| 15167 |
|
| 15168 |
if not LoSet then |
| 15169 |
if Compile_Time_Known_Value (Type_Low_Bound (Ancest)) then |
| 15170 |
Lo := Expr_Rep_Value (Type_Low_Bound (Ancest)); |
| 15171 |
LoSet := True; |
| 15172 |
exit when HiSet; |
| 15173 |
end if; |
| 15174 |
end if; |
| 15175 |
|
| 15176 |
if not HiSet then |
| 15177 |
if Compile_Time_Known_Value (Type_High_Bound (Ancest)) then |
| 15178 |
Hi := Expr_Rep_Value (Type_High_Bound (Ancest)); |
| 15179 |
HiSet := True; |
| 15180 |
exit when LoSet; |
| 15181 |
end if; |
| 15182 |
end if; |
| 15183 |
|
| 15184 |
Ancest := Ancestor_Subtype (Ancest); |
| 15185 |
|
| 15186 |
if No (Ancest) then |
| 15187 |
Ancest := Base_Type (T); |
| 15188 |
|
| 15189 |
if Is_Generic_Type (Ancest) then |
| 15190 |
return Unknown_Minimum_Size; |
| 15191 |
end if; |
| 15192 |
end if; |
| 15193 |
end loop; |
| 15194 |
|
| 15195 |
-- Fixed-point types. We can't simply use Expr_Value to get the |
| 15196 |
-- Corresponding_Integer_Value values of the bounds, since these do not |
| 15197 |
-- get set till the type is frozen, and this routine can be called |
| 15198 |
-- before the type is frozen. Similarly the test for bounds being static |
| 15199 |
-- needs to include the case where we have unanalyzed real literals for |
| 15200 |
-- the same reason. |
| 15201 |
|
| 15202 |
elsif Is_Fixed_Point_Type (T) then |
| 15203 |
|
| 15204 |
-- The following loop is looking for the nearest compile time known |
| 15205 |
-- bounds following the ancestor subtype chain. The idea is to find |
| 15206 |
-- the most restrictive known bounds information. |
| 15207 |
|
| 15208 |
Ancest := T; |
| 15209 |
loop |
| 15210 |
if Ancest = Any_Type or else Etype (Ancest) = Any_Type then |
| 15211 |
return Unknown_Minimum_Size; |
| 15212 |
end if; |
| 15213 |
|
| 15214 |
-- Note: In the following two tests for LoSet and HiSet, it may |
| 15215 |
-- seem redundant to test for N_Real_Literal here since normally |
| 15216 |
-- one would assume that the test for the value being known at |
| 15217 |
-- compile time includes this case. However, there is a glitch. |
| 15218 |
-- If the real literal comes from folding a non-static expression, |
| 15219 |
-- then we don't consider any non- static expression to be known |
| 15220 |
-- at compile time if we are in configurable run time mode (needed |
| 15221 |
-- in some cases to give a clearer definition of what is and what |
| 15222 |
-- is not accepted). So the test is indeed needed. Without it, we |
| 15223 |
-- would set neither Lo_Set nor Hi_Set and get an infinite loop. |
| 15224 |
|
| 15225 |
if not LoSet then |
| 15226 |
if Nkind (Type_Low_Bound (Ancest)) = N_Real_Literal |
| 15227 |
or else Compile_Time_Known_Value (Type_Low_Bound (Ancest)) |
| 15228 |
then |
| 15229 |
LoR := Expr_Value_R (Type_Low_Bound (Ancest)); |
| 15230 |
LoSet := True; |
| 15231 |
exit when HiSet; |
| 15232 |
end if; |
| 15233 |
end if; |
| 15234 |
|
| 15235 |
if not HiSet then |
| 15236 |
if Nkind (Type_High_Bound (Ancest)) = N_Real_Literal |
| 15237 |
or else Compile_Time_Known_Value (Type_High_Bound (Ancest)) |
| 15238 |
then |
| 15239 |
HiR := Expr_Value_R (Type_High_Bound (Ancest)); |
| 15240 |
HiSet := True; |
| 15241 |
exit when LoSet; |
| 15242 |
end if; |
| 15243 |
end if; |
| 15244 |
|
| 15245 |
Ancest := Ancestor_Subtype (Ancest); |
| 15246 |
|
| 15247 |
if No (Ancest) then |
| 15248 |
Ancest := Base_Type (T); |
| 15249 |
|
| 15250 |
if Is_Generic_Type (Ancest) then |
| 15251 |
return Unknown_Minimum_Size; |
| 15252 |
end if; |
| 15253 |
end if; |
| 15254 |
end loop; |
| 15255 |
|
| 15256 |
Lo := UR_To_Uint (LoR / Small_Value (T)); |
| 15257 |
Hi := UR_To_Uint (HiR / Small_Value (T)); |
| 15258 |
|
| 15259 |
-- No other types allowed |
| 15260 |
|
| 15261 |
else |
| 15262 |
raise Program_Error; |
| 15263 |
end if; |
| 15264 |
|
| 15265 |
-- Fall through with Hi and Lo set. Deal with biased case |
| 15266 |
|
| 15267 |
if (Biased |
| 15268 |
and then not Is_Fixed_Point_Type (T) |
| 15269 |
and then not (Is_Enumeration_Type (T) |
| 15270 |
and then Has_Non_Standard_Rep (T))) |
| 15271 |
or else Has_Biased_Representation (T) |
| 15272 |
then |
| 15273 |
Hi := Hi - Lo; |
| 15274 |
Lo := Uint_0; |
| 15275 |
end if; |
| 15276 |
|
| 15277 |
-- Null range case, size is always zero. We only do this in the discrete |
| 15278 |
-- type case, since that's the odd case that came up. Probably we should |
| 15279 |
-- also do this in the fixed-point case, but doing so causes peculiar |
| 15280 |
-- gigi failures, and it is not worth worrying about this incredibly |
| 15281 |
-- marginal case (explicit null-range fixed-point type declarations). |
| 15282 |
|
| 15283 |
if Lo > Hi and then Is_Discrete_Type (T) then |
| 15284 |
S := 0; |
| 15285 |
|
| 15286 |
-- Signed case. Note that we consider types like range 1 .. -1 to be |
| 15287 |
-- signed for the purpose of computing the size, since the bounds have |
| 15288 |
-- to be accommodated in the base type. |
| 15289 |
|
| 15290 |
elsif Lo < 0 or else Hi < 0 then |
| 15291 |
S := 1; |
| 15292 |
B := Uint_1; |
| 15293 |
|
| 15294 |
-- S = size, B = 2 ** (size - 1) (can accommodate -B .. +(B - 1)) |
| 15295 |
-- Note that we accommodate the case where the bounds cross. This |
| 15296 |
-- can happen either because of the way the bounds are declared |
| 15297 |
-- or because of the algorithm in Freeze_Fixed_Point_Type. |
| 15298 |
|
| 15299 |
while Lo < -B |
| 15300 |
or else Hi < -B |
| 15301 |
or else Lo >= B |
| 15302 |
or else Hi >= B |
| 15303 |
loop |
| 15304 |
B := Uint_2 ** S; |
| 15305 |
S := S + 1; |
| 15306 |
end loop; |
| 15307 |
|
| 15308 |
-- Unsigned case |
| 15309 |
|
| 15310 |
else |
| 15311 |
-- If both bounds are positive, make sure that both are represen- |
| 15312 |
-- table in the case where the bounds are crossed. This can happen |
| 15313 |
-- either because of the way the bounds are declared, or because of |
| 15314 |
-- the algorithm in Freeze_Fixed_Point_Type. |
| 15315 |
|
| 15316 |
if Lo > Hi then |
| 15317 |
Hi := Lo; |
| 15318 |
end if; |
| 15319 |
|
| 15320 |
-- S = size, (can accommodate 0 .. (2**size - 1)) |
| 15321 |
|
| 15322 |
S := 0; |
| 15323 |
while Hi >= Uint_2 ** S loop |
| 15324 |
S := S + 1; |
| 15325 |
end loop; |
| 15326 |
end if; |
| 15327 |
|
| 15328 |
return S; |
| 15329 |
end Minimum_Size; |
| 15330 |
|
| 15331 |
------------------------------ |
| 15332 |
-- New_Put_Image_Subprogram -- |
| 15333 |
------------------------------ |
| 15334 |
|
| 15335 |
procedure New_Put_Image_Subprogram |
| 15336 |
(N : Node_Id; |
| 15337 |
Ent : Entity_Id; |
| 15338 |
Subp : Entity_Id) |
| 15339 |
is |
| 15340 |
Loc : constant Source_Ptr := Sloc (N); |
| 15341 |
Sname : constant Name_Id := |
| 15342 |
Make_TSS_Name (Base_Type (Ent), TSS_Put_Image); |
| 15343 |
Subp_Id : Entity_Id; |
| 15344 |
Subp_Decl : Node_Id; |
| 15345 |
F : Entity_Id; |
| 15346 |
Etyp : Entity_Id; |
| 15347 |
|
| 15348 |
Defer_Declaration : constant Boolean := |
| 15349 |
Is_Tagged_Type (Ent) or else Is_Private_Type (Ent); |
| 15350 |
-- For a tagged type, there is a declaration at the freeze point, and |
| 15351 |
-- we must generate only a completion of this declaration. We do the |
| 15352 |
-- same for private types, because the full view might be tagged. |
| 15353 |
-- Otherwise we generate a declaration at the point of the attribute |
| 15354 |
-- definition clause. If the attribute definition comes from an aspect |
| 15355 |
-- specification the declaration is part of the freeze actions of the |
| 15356 |
-- type. |
| 15357 |
|
| 15358 |
function Build_Spec return Node_Id; |
| 15359 |
-- Used for declaration and renaming declaration, so that this is |
| 15360 |
-- treated as a renaming_as_body. |
| 15361 |
|
| 15362 |
---------------- |
| 15363 |
-- Build_Spec -- |
| 15364 |
---------------- |
| 15365 |
|
| 15366 |
function Build_Spec return Node_Id is |
| 15367 |
Formals : List_Id; |
| 15368 |
Spec : Node_Id; |
| 15369 |
T_Ref : constant Node_Id := New_Occurrence_Of (Etyp, Loc); |
| 15370 |
|
| 15371 |
begin |
| 15372 |
Subp_Id := Make_Defining_Identifier (Loc, Sname); |
| 15373 |
|
| 15374 |
-- S : Root_Buffer_Type'Class |
| 15375 |
|
| 15376 |
Formals := New_List ( |
| 15377 |
Make_Parameter_Specification (Loc, |
| 15378 |
Defining_Identifier => |
| 15379 |
Make_Defining_Identifier (Loc, Name_S), |
| 15380 |
In_Present => True, |
| 15381 |
Out_Present => True, |
| 15382 |
Parameter_Type => |
| 15383 |
New_Occurrence_Of (Etype (F), Loc))); |
| 15384 |
|
| 15385 |
-- V : T |
| 15386 |
|
| 15387 |
Append_To (Formals, |
| 15388 |
Make_Parameter_Specification (Loc, |
| 15389 |
Defining_Identifier => Make_Defining_Identifier (Loc, Name_V), |
| 15390 |
Parameter_Type => T_Ref)); |
| 15391 |
|
| 15392 |
Spec := |
| 15393 |
Make_Procedure_Specification (Loc, |
| 15394 |
Defining_Unit_Name => Subp_Id, |
| 15395 |
Parameter_Specifications => Formals); |
| 15396 |
|
| 15397 |
return Spec; |
| 15398 |
end Build_Spec; |
| 15399 |
|
| 15400 |
-- Start of processing for New_Put_Image_Subprogram |
| 15401 |
|
| 15402 |
begin |
| 15403 |
F := First_Formal (Subp); |
| 15404 |
|
| 15405 |
Etyp := Etype (Next_Formal (F)); |
| 15406 |
|
| 15407 |
-- Prepare subprogram declaration and insert it as an action on the |
| 15408 |
-- clause node. The visibility for this entity is used to test for |
| 15409 |
-- visibility of the attribute definition clause (in the sense of |
| 15410 |
-- 8.3(23) as amended by AI-195). |
| 15411 |
|
| 15412 |
if not Defer_Declaration then |
| 15413 |
Subp_Decl := |
| 15414 |
Make_Subprogram_Declaration (Loc, |
| 15415 |
Specification => Build_Spec); |
| 15416 |
|
| 15417 |
-- For a tagged type, there is always a visible declaration for the |
| 15418 |
-- Put_Image TSS (it is a predefined primitive operation), and the |
| 15419 |
-- completion of this declaration occurs at the freeze point, which is |
| 15420 |
-- not always visible at places where the attribute definition clause is |
| 15421 |
-- visible. So, we create a dummy entity here for the purpose of |
| 15422 |
-- tracking the visibility of the attribute definition clause itself. |
| 15423 |
|
| 15424 |
else |
| 15425 |
Subp_Id := |
| 15426 |
Make_Defining_Identifier (Loc, New_External_Name (Sname, 'V')); |
| 15427 |
Subp_Decl := |
| 15428 |
Make_Object_Declaration (Loc, |
| 15429 |
Defining_Identifier => Subp_Id, |
| 15430 |
Object_Definition => New_Occurrence_Of (Standard_Boolean, Loc)); |
| 15431 |
end if; |
| 15432 |
|
| 15433 |
if not Defer_Declaration |
| 15434 |
and then From_Aspect_Specification (N) |
| 15435 |
and then Has_Delayed_Freeze (Ent) |
| 15436 |
then |
| 15437 |
Append_Freeze_Action (Ent, Subp_Decl); |
| 15438 |
|
| 15439 |
-- We may freeze Subp_Id immediately since Ent has just been frozen. |
| 15440 |
-- This will help to shield us from potential late freezing issues. |
| 15441 |
|
| 15442 |
Set_Is_Frozen (Subp_Id); |
| 15443 |
|
| 15444 |
else |
| 15445 |
Insert_Action (N, Subp_Decl); |
| 15446 |
Set_Entity (N, Subp_Id); |
| 15447 |
end if; |
| 15448 |
|
| 15449 |
Subp_Decl := |
| 15450 |
Make_Subprogram_Renaming_Declaration (Loc, |
| 15451 |
Specification => Build_Spec, |
| 15452 |
Name => New_Occurrence_Of (Subp, Loc)); |
| 15453 |
|
| 15454 |
if Defer_Declaration then |
| 15455 |
Set_TSS (Base_Type (Ent), Subp_Id); |
| 15456 |
|
| 15457 |
else |
| 15458 |
if From_Aspect_Specification (N) then |
| 15459 |
Append_Freeze_Action (Ent, Subp_Decl); |
| 15460 |
else |
| 15461 |
Insert_Action (N, Subp_Decl); |
| 15462 |
end if; |
| 15463 |
|
| 15464 |
Copy_TSS (Subp_Id, Base_Type (Ent)); |
| 15465 |
end if; |
| 15466 |
end New_Put_Image_Subprogram; |
| 15467 |
|
| 15468 |
--------------------------- |
| 15469 |
-- New_Stream_Subprogram -- |
| 15470 |
--------------------------- |
| 15471 |
|
| 15472 |
procedure New_Stream_Subprogram |
| 15473 |
(N : Node_Id; |
| 15474 |
Ent : Entity_Id; |
| 15475 |
Subp : Entity_Id; |
| 15476 |
Nam : TSS_Name_Type) |
| 15477 |
is |
| 15478 |
Loc : constant Source_Ptr := Sloc (N); |
| 15479 |
Sname : constant Name_Id := Make_TSS_Name (Base_Type (Ent), Nam); |
| 15480 |
Subp_Id : Entity_Id; |
| 15481 |
Subp_Decl : Node_Id; |
| 15482 |
F : Entity_Id; |
| 15483 |
Etyp : Entity_Id; |
| 15484 |
|
| 15485 |
Defer_Declaration : constant Boolean := |
| 15486 |
Is_Tagged_Type (Ent) or else Is_Private_Type (Ent); |
| 15487 |
-- For a tagged type, there is a declaration for each stream attribute |
| 15488 |
-- at the freeze point, and we must generate only a completion of this |
| 15489 |
-- declaration. We do the same for private types, because the full view |
| 15490 |
-- might be tagged. Otherwise we generate a declaration at the point of |
| 15491 |
-- the attribute definition clause. If the attribute definition comes |
| 15492 |
-- from an aspect specification the declaration is part of the freeze |
| 15493 |
-- actions of the type. |
| 15494 |
|
| 15495 |
function Build_Spec return Node_Id; |
| 15496 |
-- Used for declaration and renaming declaration, so that this is |
| 15497 |
-- treated as a renaming_as_body. |
| 15498 |
|
| 15499 |
---------------- |
| 15500 |
-- Build_Spec -- |
| 15501 |
---------------- |
| 15502 |
|
| 15503 |
function Build_Spec return Node_Id is |
| 15504 |
Out_P : constant Boolean := (Nam = TSS_Stream_Read); |
| 15505 |
Formals : List_Id; |
| 15506 |
Spec : Node_Id; |
| 15507 |
T_Ref : constant Node_Id := New_Occurrence_Of (Etyp, Loc); |
| 15508 |
|
| 15509 |
begin |
| 15510 |
Subp_Id := Make_Defining_Identifier (Loc, Sname); |
| 15511 |
|
| 15512 |
-- S : access Root_Stream_Type'Class |
| 15513 |
|
| 15514 |
Formals := New_List ( |
| 15515 |
Make_Parameter_Specification (Loc, |
| 15516 |
Defining_Identifier => |
| 15517 |
Make_Defining_Identifier (Loc, Name_S), |
| 15518 |
Parameter_Type => |
| 15519 |
Make_Access_Definition (Loc, |
| 15520 |
Subtype_Mark => |
| 15521 |
New_Occurrence_Of ( |
| 15522 |
Designated_Type (Etype (F)), Loc)))); |
| 15523 |
|
| 15524 |
if Nam = TSS_Stream_Input then |
| 15525 |
Spec := |
| 15526 |
Make_Function_Specification (Loc, |
| 15527 |
Defining_Unit_Name => Subp_Id, |
| 15528 |
Parameter_Specifications => Formals, |
| 15529 |
Result_Definition => T_Ref); |
| 15530 |
else |
| 15531 |
-- V : [out] T |
| 15532 |
|
| 15533 |
Append_To (Formals, |
| 15534 |
Make_Parameter_Specification (Loc, |
| 15535 |
Defining_Identifier => Make_Defining_Identifier (Loc, Name_V), |
| 15536 |
Out_Present => Out_P, |
| 15537 |
Parameter_Type => T_Ref)); |
| 15538 |
|
| 15539 |
Spec := |
| 15540 |
Make_Procedure_Specification (Loc, |
| 15541 |
Defining_Unit_Name => Subp_Id, |
| 15542 |
Parameter_Specifications => Formals); |
| 15543 |
end if; |
| 15544 |
|
| 15545 |
return Spec; |
| 15546 |
end Build_Spec; |
| 15547 |
|
| 15548 |
-- Start of processing for New_Stream_Subprogram |
| 15549 |
|
| 15550 |
begin |
| 15551 |
F := First_Formal (Subp); |
| 15552 |
|
| 15553 |
if Ekind (Subp) = E_Procedure then |
| 15554 |
Etyp := Etype (Next_Formal (F)); |
| 15555 |
else |
| 15556 |
Etyp := Etype (Subp); |
| 15557 |
end if; |
| 15558 |
|
| 15559 |
-- Prepare subprogram declaration and insert it as an action on the |
| 15560 |
-- clause node. The visibility for this entity is used to test for |
| 15561 |
-- visibility of the attribute definition clause (in the sense of |
| 15562 |
-- 8.3(23) as amended by AI-195). |
| 15563 |
|
| 15564 |
if not Defer_Declaration then |
| 15565 |
Subp_Decl := |
| 15566 |
Make_Subprogram_Declaration (Loc, |
| 15567 |
Specification => Build_Spec); |
| 15568 |
|
| 15569 |
-- For a tagged type, there is always a visible declaration for each |
| 15570 |
-- stream TSS (it is a predefined primitive operation), and the |
| 15571 |
-- completion of this declaration occurs at the freeze point, which is |
| 15572 |
-- not always visible at places where the attribute definition clause is |
| 15573 |
-- visible. So, we create a dummy entity here for the purpose of |
| 15574 |
-- tracking the visibility of the attribute definition clause itself. |
| 15575 |
|
| 15576 |
else |
| 15577 |
Subp_Id := |
| 15578 |
Make_Defining_Identifier (Loc, New_External_Name (Sname, 'V')); |
| 15579 |
Subp_Decl := |
| 15580 |
Make_Object_Declaration (Loc, |
| 15581 |
Defining_Identifier => Subp_Id, |
| 15582 |
Object_Definition => New_Occurrence_Of (Standard_Boolean, Loc)); |
| 15583 |
end if; |
| 15584 |
|
| 15585 |
if not Defer_Declaration |
| 15586 |
and then From_Aspect_Specification (N) |
| 15587 |
and then Has_Delayed_Freeze (Ent) |
| 15588 |
then |
| 15589 |
Append_Freeze_Action (Ent, Subp_Decl); |
| 15590 |
|
| 15591 |
else |
| 15592 |
Insert_Action (N, Subp_Decl); |
| 15593 |
Set_Entity (N, Subp_Id); |
| 15594 |
end if; |
| 15595 |
|
| 15596 |
Subp_Decl := |
| 15597 |
Make_Subprogram_Renaming_Declaration (Loc, |
| 15598 |
Specification => Build_Spec, |
| 15599 |
Name => New_Occurrence_Of (Subp, Loc)); |
| 15600 |
|
| 15601 |
if Defer_Declaration then |
| 15602 |
Set_TSS (Base_Type (Ent), Subp_Id); |
| 15603 |
|
| 15604 |
else |
| 15605 |
if From_Aspect_Specification (N) then |
| 15606 |
Append_Freeze_Action (Ent, Subp_Decl); |
| 15607 |
else |
| 15608 |
Insert_Action (N, Subp_Decl); |
| 15609 |
end if; |
| 15610 |
|
| 15611 |
Copy_TSS (Subp_Id, Base_Type (Ent)); |
| 15612 |
end if; |
| 15613 |
end New_Stream_Subprogram; |
| 15614 |
|
| 15615 |
---------------------- |
| 15616 |
-- No_Type_Rep_Item -- |
| 15617 |
---------------------- |
| 15618 |
|
| 15619 |
procedure No_Type_Rep_Item (N : Node_Id) is |
| 15620 |
begin |
| 15621 |
Error_Msg_N ("|type-related representation item not permitted!", N); |
| 15622 |
end No_Type_Rep_Item; |
| 15623 |
|
| 15624 |
-------------- |
| 15625 |
-- Pop_Type -- |
| 15626 |
-------------- |
| 15627 |
|
| 15628 |
procedure Pop_Type (E : Entity_Id) is |
| 15629 |
begin |
| 15630 |
if Ekind (E) = E_Record_Type and then E = Current_Scope then |
| 15631 |
End_Scope; |
| 15632 |
|
| 15633 |
elsif Is_Type (E) |
| 15634 |
and then Has_Discriminants (E) |
| 15635 |
and then Nkind (Parent (E)) /= N_Subtype_Declaration |
| 15636 |
then |
| 15637 |
Uninstall_Discriminants (E); |
| 15638 |
Pop_Scope; |
| 15639 |
end if; |
| 15640 |
end Pop_Type; |
| 15641 |
|
| 15642 |
--------------- |
| 15643 |
-- Push_Type -- |
| 15644 |
--------------- |
| 15645 |
|
| 15646 |
procedure Push_Type (E : Entity_Id) is |
| 15647 |
Comp : Entity_Id; |
| 15648 |
|
| 15649 |
begin |
| 15650 |
if Ekind (E) = E_Record_Type then |
| 15651 |
Push_Scope (E); |
| 15652 |
|
| 15653 |
Comp := First_Component (E); |
| 15654 |
while Present (Comp) loop |
| 15655 |
Install_Entity (Comp); |
| 15656 |
Next_Component (Comp); |
| 15657 |
end loop; |
| 15658 |
|
| 15659 |
if Has_Discriminants (E) then |
| 15660 |
Install_Discriminants (E); |
| 15661 |
end if; |
| 15662 |
|
| 15663 |
elsif Is_Type (E) |
| 15664 |
and then Has_Discriminants (E) |
| 15665 |
and then Nkind (Parent (E)) /= N_Subtype_Declaration |
| 15666 |
then |
| 15667 |
Push_Scope (E); |
| 15668 |
Install_Discriminants (E); |
| 15669 |
end if; |
| 15670 |
end Push_Type; |
| 15671 |
|
| 15672 |
----------------------------------- |
| 15673 |
-- Register_Address_Clause_Check -- |
| 15674 |
----------------------------------- |
| 15675 |
|
| 15676 |
procedure Register_Address_Clause_Check |
| 15677 |
(N : Node_Id; |
| 15678 |
X : Entity_Id; |
| 15679 |
A : Uint; |
| 15680 |
Y : Entity_Id; |
| 15681 |
Off : Boolean) |
| 15682 |
is |
| 15683 |
ACS : constant Boolean := Scope_Suppress.Suppress (Alignment_Check); |
| 15684 |
begin |
| 15685 |
Address_Clause_Checks.Append ((N, X, A, Y, Off, ACS)); |
| 15686 |
end Register_Address_Clause_Check; |
| 15687 |
|
| 15688 |
------------------------ |
| 15689 |
-- Rep_Item_Too_Early -- |
| 15690 |
------------------------ |
| 15691 |
|
| 15692 |
function Rep_Item_Too_Early (T : Entity_Id; N : Node_Id) return Boolean is |
| 15693 |
function Has_Generic_Parent (E : Entity_Id) return Boolean; |
| 15694 |
-- Return True if R or any ancestor is a generic type |
| 15695 |
|
| 15696 |
------------------------ |
| 15697 |
-- Has_Generic_Parent -- |
| 15698 |
------------------------ |
| 15699 |
|
| 15700 |
function Has_Generic_Parent (E : Entity_Id) return Boolean is |
| 15701 |
Ancestor_Type : Entity_Id := Etype (E); |
| 15702 |
|
| 15703 |
begin |
| 15704 |
if Is_Generic_Type (E) then |
| 15705 |
return True; |
| 15706 |
end if; |
| 15707 |
|
| 15708 |
while Present (Ancestor_Type) |
| 15709 |
and then not Is_Generic_Type (Ancestor_Type) |
| 15710 |
and then Etype (Ancestor_Type) /= Ancestor_Type |
| 15711 |
loop |
| 15712 |
Ancestor_Type := Etype (Ancestor_Type); |
| 15713 |
end loop; |
| 15714 |
|
| 15715 |
return |
| 15716 |
Present (Ancestor_Type) and then Is_Generic_Type (Ancestor_Type); |
| 15717 |
end Has_Generic_Parent; |
| 15718 |
|
| 15719 |
-- Start of processing for Rep_Item_Too_Early |
| 15720 |
|
| 15721 |
begin |
| 15722 |
-- Cannot apply non-operational rep items to generic types |
| 15723 |
|
| 15724 |
if Is_Operational_Item (N) then |
| 15725 |
return False; |
| 15726 |
|
| 15727 |
elsif Is_Type (T) |
| 15728 |
and then Has_Generic_Parent (T) |
| 15729 |
and then (Nkind (N) /= N_Pragma |
| 15730 |
or else Get_Pragma_Id (N) /= Pragma_Convention) |
| 15731 |
then |
| 15732 |
if Ada_Version < Ada_2022 then |
| 15733 |
Error_Msg_N |
| 15734 |
("representation item not allowed for generic type", N); |
| 15735 |
return True; |
| 15736 |
else |
| 15737 |
return False; |
| 15738 |
end if; |
| 15739 |
end if; |
| 15740 |
|
| 15741 |
-- Otherwise check for incomplete type |
| 15742 |
|
| 15743 |
if Is_Incomplete_Or_Private_Type (T) |
| 15744 |
and then No (Underlying_Type (T)) |
| 15745 |
and then |
| 15746 |
(Nkind (N) /= N_Pragma |
| 15747 |
or else Get_Pragma_Id (N) /= Pragma_Import) |
| 15748 |
then |
| 15749 |
Error_Msg_N |
| 15750 |
("representation item must be after full type declaration", N); |
| 15751 |
return True; |
| 15752 |
|
| 15753 |
-- If the type has incomplete components, a representation clause is |
| 15754 |
-- illegal but stream attributes and Convention pragmas are correct. |
| 15755 |
|
| 15756 |
elsif Has_Private_Component (T) then |
| 15757 |
if Nkind (N) = N_Pragma then |
| 15758 |
return False; |
| 15759 |
|
| 15760 |
else |
| 15761 |
Error_Msg_N |
| 15762 |
("representation item must appear after type is fully defined", |
| 15763 |
N); |
| 15764 |
return True; |
| 15765 |
end if; |
| 15766 |
else |
| 15767 |
return False; |
| 15768 |
end if; |
| 15769 |
end Rep_Item_Too_Early; |
| 15770 |
|
| 15771 |
----------------------- |
| 15772 |
-- Rep_Item_Too_Late -- |
| 15773 |
----------------------- |
| 15774 |
|
| 15775 |
function Rep_Item_Too_Late |
| 15776 |
(T : Entity_Id; |
| 15777 |
N : Node_Id; |
| 15778 |
FOnly : Boolean := False) return Boolean |
| 15779 |
is |
| 15780 |
procedure Too_Late; |
| 15781 |
-- Output message for an aspect being specified too late |
| 15782 |
|
| 15783 |
-- Note that neither of the above errors is considered a serious one, |
| 15784 |
-- since the effect is simply that we ignore the representation clause |
| 15785 |
-- in these cases. |
| 15786 |
-- Is this really true? In any case if we make this change we must |
| 15787 |
-- document the requirement in the spec of Rep_Item_Too_Late that |
| 15788 |
-- if True is returned, then the rep item must be completely ignored??? |
| 15789 |
|
| 15790 |
-------------- |
| 15791 |
-- Too_Late -- |
| 15792 |
-------------- |
| 15793 |
|
| 15794 |
procedure Too_Late is |
| 15795 |
S : Entity_Id; |
| 15796 |
begin |
| 15797 |
-- Other compilers seem more relaxed about rep items appearing too |
| 15798 |
-- late. Since analysis tools typically don't care about rep items |
| 15799 |
-- anyway, no reason to be too strict about this. |
| 15800 |
|
| 15801 |
if not Relaxed_RM_Semantics then |
| 15802 |
if Debug_Flag_Underscore_DD then |
| 15803 |
|
| 15804 |
S := First_Subtype (T); |
| 15805 |
if Present (Freeze_Node (S)) then |
| 15806 |
Record_Representation_Too_Late_Error |
| 15807 |
(Rep => N, |
| 15808 |
Freeze => Freeze_Node (S), |
| 15809 |
Def => S); |
| 15810 |
else |
| 15811 |
Error_Msg_N ("|representation item appears too late!", N); |
| 15812 |
end if; |
| 15813 |
|
| 15814 |
else |
| 15815 |
Error_Msg_N ("|representation item appears too late!", N); |
| 15816 |
|
| 15817 |
S := First_Subtype (T); |
| 15818 |
if Present (Freeze_Node (S)) then |
| 15819 |
Error_Msg_NE |
| 15820 |
("??no more representation items for }", |
| 15821 |
Freeze_Node (S), S); |
| 15822 |
end if; |
| 15823 |
end if; |
| 15824 |
end if; |
| 15825 |
end Too_Late; |
| 15826 |
|
| 15827 |
-- Local variables |
| 15828 |
|
| 15829 |
Parent_Type : Entity_Id; |
| 15830 |
|
| 15831 |
-- Start of processing for Rep_Item_Too_Late |
| 15832 |
|
| 15833 |
begin |
| 15834 |
-- First make sure entity is not frozen (RM 13.1(9)) |
| 15835 |
|
| 15836 |
if Is_Frozen (T) |
| 15837 |
|
| 15838 |
-- Exclude imported types, which may be frozen if they appear in a |
| 15839 |
-- representation clause for a local type. |
| 15840 |
|
| 15841 |
and then not From_Limited_With (T) |
| 15842 |
|
| 15843 |
-- Exclude generated entities (not coming from source). The common |
| 15844 |
-- case is when we generate a renaming which prematurely freezes the |
| 15845 |
-- renamed internal entity, but we still want to be able to set copies |
| 15846 |
-- of attribute values such as Size/Alignment. |
| 15847 |
|
| 15848 |
and then Comes_From_Source (T) |
| 15849 |
then |
| 15850 |
-- A self-referential aspect is illegal if it forces freezing the |
| 15851 |
-- entity before the corresponding pragma has been analyzed. |
| 15852 |
|
| 15853 |
if Nkind (N) in N_Attribute_Definition_Clause | N_Pragma |
| 15854 |
and then From_Aspect_Specification (N) |
| 15855 |
then |
| 15856 |
-- If an attribute_definition_clause or pragma comes from |
| 15857 |
-- an aspect_specification that is not Comes_From_Source (as when |
| 15858 |
-- it's an inherited aspect), then we assume it must be OK, since |
| 15859 |
-- it was generated by the compiler. |
| 15860 |
|
| 15861 |
if Present (Parent (N)) |
| 15862 |
and then not Comes_From_Source (Parent (N)) |
| 15863 |
then |
| 15864 |
return False; |
| 15865 |
|
| 15866 |
else |
| 15867 |
Error_Msg_NE |
| 15868 |
("aspect specification causes premature freezing of&", N, T); |
| 15869 |
Set_Has_Delayed_Freeze (T, False); |
| 15870 |
return True; |
| 15871 |
end if; |
| 15872 |
end if; |
| 15873 |
|
| 15874 |
Too_Late; |
| 15875 |
|
| 15876 |
return True; |
| 15877 |
|
| 15878 |
-- Check for case of untagged derived type whose parent either has |
| 15879 |
-- primitive operations (pre Ada 2022), or is a by-reference type (RM |
| 15880 |
-- 13.1(10)). In this case we do not output a Too_Late message, since |
| 15881 |
-- there is no earlier point where the rep item could be placed to make |
| 15882 |
-- it legal. |
| 15883 |
-- ??? Confirming representation clauses should be allowed here. |
| 15884 |
|
| 15885 |
elsif Is_Type (T) |
| 15886 |
and then not FOnly |
| 15887 |
and then Is_Derived_Type (T) |
| 15888 |
and then not Is_Tagged_Type (T) |
| 15889 |
then |
| 15890 |
Parent_Type := Etype (Base_Type (T)); |
| 15891 |
|
| 15892 |
if Relaxed_RM_Semantics then |
| 15893 |
null; |
| 15894 |
|
| 15895 |
elsif Ada_Version <= Ada_2012 |
| 15896 |
and then Has_Primitive_Operations (Parent_Type) |
| 15897 |
then |
| 15898 |
Error_Msg_N |
| 15899 |
("|representation item not permitted before Ada 2022!", N); |
| 15900 |
Error_Msg_NE |
| 15901 |
("\parent type & has primitive operations!", N, Parent_Type); |
| 15902 |
return True; |
| 15903 |
|
| 15904 |
elsif Is_By_Reference_Type (Parent_Type) then |
| 15905 |
No_Type_Rep_Item (N); |
| 15906 |
Error_Msg_NE |
| 15907 |
("\parent type & is a by-reference type!", N, Parent_Type); |
| 15908 |
return True; |
| 15909 |
end if; |
| 15910 |
end if; |
| 15911 |
|
| 15912 |
-- No error, but one more warning to consider. The RM (surprisingly) |
| 15913 |
-- allows this pattern in some cases: |
| 15914 |
|
| 15915 |
-- type S is ... |
| 15916 |
-- primitive operations for S |
| 15917 |
-- type R is new S; |
| 15918 |
-- rep clause for S |
| 15919 |
|
| 15920 |
-- Meaning that calls on the primitive operations of S for values of |
| 15921 |
-- type R may require possibly expensive implicit conversion operations. |
| 15922 |
-- So even when this is not an error, it is still worth a warning. |
| 15923 |
|
| 15924 |
if not Relaxed_RM_Semantics and then Is_Type (T) then |
| 15925 |
declare |
| 15926 |
DTL : constant Entity_Id := Derived_Type_Link (Base_Type (T)); |
| 15927 |
|
| 15928 |
begin |
| 15929 |
if Present (DTL) |
| 15930 |
|
| 15931 |
-- For now, do not generate this warning for the case of |
| 15932 |
-- aspect specification using Ada 2012 syntax, since we get |
| 15933 |
-- wrong messages we do not understand. The whole business |
| 15934 |
-- of derived types and rep items seems a bit confused when |
| 15935 |
-- aspects are used, since the aspects are not evaluated |
| 15936 |
-- till freeze time. However, AI12-0109 confirms (in an AARM |
| 15937 |
-- ramification) that inheritance in this case is required |
| 15938 |
-- to work. |
| 15939 |
|
| 15940 |
and then not From_Aspect_Specification (N) |
| 15941 |
then |
| 15942 |
if Is_By_Reference_Type (T) |
| 15943 |
and then not Is_Tagged_Type (T) |
| 15944 |
and then Is_Type_Related_Rep_Item (N) |
| 15945 |
and then (Ada_Version >= Ada_2012 |
| 15946 |
or else Has_Primitive_Operations (Base_Type (T))) |
| 15947 |
then |
| 15948 |
-- Treat as hard error (AI12-0109, binding interpretation). |
| 15949 |
-- Implementing a change of representation is not really |
| 15950 |
-- an option in the case of a by-reference type, so we |
| 15951 |
-- take this path for all Ada dialects if primitive |
| 15952 |
-- operations are present. |
| 15953 |
Error_Msg_Sloc := Sloc (DTL); |
| 15954 |
Error_Msg_N |
| 15955 |
("representation item for& appears after derived type " |
| 15956 |
& "declaration#", N); |
| 15957 |
|
| 15958 |
elsif Has_Primitive_Operations (Base_Type (T)) then |
| 15959 |
Error_Msg_Sloc := Sloc (DTL); |
| 15960 |
|
| 15961 |
Error_Msg_N |
| 15962 |
("representation item for& appears after derived type " |
| 15963 |
& "declaration#??", N); |
| 15964 |
Error_Msg_NE |
| 15965 |
("\may result in implicit conversions for primitive " |
| 15966 |
& "operations of&??", N, T); |
| 15967 |
Error_Msg_NE |
| 15968 |
("\to change representations when called with arguments " |
| 15969 |
& "of type&??", N, DTL); |
| 15970 |
end if; |
| 15971 |
end if; |
| 15972 |
end; |
| 15973 |
end if; |
| 15974 |
|
| 15975 |
-- No error, link item into head of chain of rep items for the entity, |
| 15976 |
-- but avoid chaining if we have an overloadable entity, and the pragma |
| 15977 |
-- is one that can apply to multiple overloaded entities. |
| 15978 |
|
| 15979 |
if Is_Overloadable (T) and then Nkind (N) = N_Pragma then |
| 15980 |
declare |
| 15981 |
Pname : constant Name_Id := Pragma_Name (N); |
| 15982 |
begin |
| 15983 |
if Pname in Name_Convention | Name_Import | Name_Export |
| 15984 |
| Name_External | Name_Interface |
| 15985 |
then |
| 15986 |
return False; |
| 15987 |
end if; |
| 15988 |
end; |
| 15989 |
end if; |
| 15990 |
|
| 15991 |
Record_Rep_Item (T, N); |
| 15992 |
return False; |
| 15993 |
end Rep_Item_Too_Late; |
| 15994 |
|
| 15995 |
------------------------------------- |
| 15996 |
-- Replace_Type_References_Generic -- |
| 15997 |
------------------------------------- |
| 15998 |
|
| 15999 |
procedure Replace_Type_References_Generic (N : Node_Id; T : Entity_Id) is |
| 16000 |
TName : constant Name_Id := Chars (T); |
| 16001 |
|
| 16002 |
function Replace_Type_Ref (N : Node_Id) return Traverse_Result; |
| 16003 |
-- Processes a single node in the traversal procedure below, checking |
| 16004 |
-- if node N should be replaced, and if so, doing the replacement. |
| 16005 |
|
| 16006 |
function Visible_Component (Comp : Name_Id) return Entity_Id; |
| 16007 |
-- Given an identifier in the expression, check whether there is a |
| 16008 |
-- discriminant, component, protected procedure, or entry of the type |
| 16009 |
-- that is directy visible, and rewrite it as the corresponding selected |
| 16010 |
-- component of the formal of the subprogram. |
| 16011 |
|
| 16012 |
---------------------- |
| 16013 |
-- Replace_Type_Ref -- |
| 16014 |
---------------------- |
| 16015 |
|
| 16016 |
function Replace_Type_Ref (N : Node_Id) return Traverse_Result is |
| 16017 |
Loc : constant Source_Ptr := Sloc (N); |
| 16018 |
|
| 16019 |
procedure Add_Prefix (Ref : Node_Id; Comp : Entity_Id); |
| 16020 |
-- Add the proper prefix to a reference to a component of the type |
| 16021 |
-- when it is not already a selected component. |
| 16022 |
|
| 16023 |
---------------- |
| 16024 |
-- Add_Prefix -- |
| 16025 |
---------------- |
| 16026 |
|
| 16027 |
procedure Add_Prefix (Ref : Node_Id; Comp : Entity_Id) is |
| 16028 |
begin |
| 16029 |
Rewrite (Ref, |
| 16030 |
Make_Selected_Component (Loc, |
| 16031 |
Prefix => New_Occurrence_Of (T, Loc), |
| 16032 |
Selector_Name => New_Occurrence_Of (Comp, Loc))); |
| 16033 |
Replace_Type_Reference (Prefix (Ref)); |
| 16034 |
end Add_Prefix; |
| 16035 |
|
| 16036 |
-- Local variables |
| 16037 |
|
| 16038 |
Comp : Entity_Id; |
| 16039 |
Pref : Node_Id; |
| 16040 |
Scop : Entity_Id; |
| 16041 |
|
| 16042 |
-- Start of processing for Replace_Type_Ref |
| 16043 |
|
| 16044 |
begin |
| 16045 |
if Nkind (N) = N_Identifier then |
| 16046 |
|
| 16047 |
-- If not the type name, check whether it is a reference to some |
| 16048 |
-- other type, which must be frozen before the predicate function |
| 16049 |
-- is analyzed, i.e. before the freeze node of the type to which |
| 16050 |
-- the predicate applies. |
| 16051 |
|
| 16052 |
if Chars (N) /= TName then |
| 16053 |
if Present (Current_Entity (N)) |
| 16054 |
and then Is_Type (Current_Entity (N)) |
| 16055 |
then |
| 16056 |
Freeze_Before (Freeze_Node (T), Current_Entity (N)); |
| 16057 |
end if; |
| 16058 |
|
| 16059 |
-- The components of the type are directly visible and can |
| 16060 |
-- be referenced in the source code without a prefix. |
| 16061 |
-- If a name denoting a component doesn't already have a |
| 16062 |
-- prefix, then normalize it by adding a reference to the |
| 16063 |
-- current instance of the type as a prefix. |
| 16064 |
-- |
| 16065 |
-- This isn't right in the pathological corner case of an |
| 16066 |
-- object-declaring expression (e.g., a quantified expression |
| 16067 |
-- or a declare expression) that declares an object with the |
| 16068 |
-- same name as a visible component declaration, thereby hiding |
| 16069 |
-- the component within that expression. For example, given a |
| 16070 |
-- record with a Boolean component "C" and a dynamic predicate |
| 16071 |
-- "C = (for some C in Character => Some_Function (C))", only |
| 16072 |
-- the first of the two uses of C should have a prefix added |
| 16073 |
-- here; instead, both will get prefixes. |
| 16074 |
|
| 16075 |
if Nkind (Parent (N)) /= N_Selected_Component |
| 16076 |
or else N /= Selector_Name (Parent (N)) |
| 16077 |
then |
| 16078 |
Comp := Visible_Component (Chars (N)); |
| 16079 |
|
| 16080 |
if Present (Comp) then |
| 16081 |
Add_Prefix (N, Comp); |
| 16082 |
end if; |
| 16083 |
end if; |
| 16084 |
|
| 16085 |
return Skip; |
| 16086 |
|
| 16087 |
-- Otherwise do the replacement if this is not a qualified |
| 16088 |
-- reference to a homograph of the type itself. Note that the |
| 16089 |
-- current instance could not appear in such a context, e.g. |
| 16090 |
-- the prefix of a type conversion. |
| 16091 |
|
| 16092 |
else |
| 16093 |
if Nkind (Parent (N)) /= N_Selected_Component |
| 16094 |
or else N /= Selector_Name (Parent (N)) |
| 16095 |
then |
| 16096 |
Replace_Type_Reference (N); |
| 16097 |
end if; |
| 16098 |
|
| 16099 |
return Skip; |
| 16100 |
end if; |
| 16101 |
|
| 16102 |
-- Case of selected component, which may be a subcomponent of the |
| 16103 |
-- current instance, or an expanded name which is still unanalyzed. |
| 16104 |
|
| 16105 |
elsif Nkind (N) = N_Selected_Component then |
| 16106 |
|
| 16107 |
-- If selector name is not our type, keep going (we might still |
| 16108 |
-- have an occurrence of the type in the prefix). If it is a |
| 16109 |
-- subcomponent of the current entity, add prefix. |
| 16110 |
|
| 16111 |
if Nkind (Selector_Name (N)) /= N_Identifier |
| 16112 |
or else Chars (Selector_Name (N)) /= TName |
| 16113 |
then |
| 16114 |
if Nkind (Prefix (N)) = N_Identifier then |
| 16115 |
Comp := Visible_Component (Chars (Prefix (N))); |
| 16116 |
|
| 16117 |
if Present (Comp) then |
| 16118 |
Add_Prefix (Prefix (N), Comp); |
| 16119 |
end if; |
| 16120 |
end if; |
| 16121 |
|
| 16122 |
return OK; |
| 16123 |
|
| 16124 |
-- Selector name is our type, check qualification |
| 16125 |
|
| 16126 |
else |
| 16127 |
-- Loop through scopes and prefixes, doing comparison |
| 16128 |
|
| 16129 |
Scop := Current_Scope; |
| 16130 |
Pref := Prefix (N); |
| 16131 |
loop |
| 16132 |
-- Continue if no more scopes or scope with no name |
| 16133 |
|
| 16134 |
if No (Scop) or else Nkind (Scop) not in N_Has_Chars then |
| 16135 |
return OK; |
| 16136 |
end if; |
| 16137 |
|
| 16138 |
-- Do replace if prefix is an identifier matching the scope |
| 16139 |
-- that we are currently looking at. |
| 16140 |
|
| 16141 |
if Nkind (Pref) = N_Identifier |
| 16142 |
and then Chars (Pref) = Chars (Scop) |
| 16143 |
then |
| 16144 |
Replace_Type_Reference (N); |
| 16145 |
return Skip; |
| 16146 |
end if; |
| 16147 |
|
| 16148 |
-- Go check scope above us if prefix is itself of the form |
| 16149 |
-- of a selected component, whose selector matches the scope |
| 16150 |
-- we are currently looking at. |
| 16151 |
|
| 16152 |
if Nkind (Pref) = N_Selected_Component |
| 16153 |
and then Nkind (Selector_Name (Pref)) = N_Identifier |
| 16154 |
and then Chars (Selector_Name (Pref)) = Chars (Scop) |
| 16155 |
then |
| 16156 |
Scop := Scope (Scop); |
| 16157 |
Pref := Prefix (Pref); |
| 16158 |
|
| 16159 |
-- For anything else, we don't have a match, so keep on |
| 16160 |
-- going, there are still some weird cases where we may |
| 16161 |
-- still have a replacement within the prefix. |
| 16162 |
|
| 16163 |
else |
| 16164 |
return OK; |
| 16165 |
end if; |
| 16166 |
end loop; |
| 16167 |
end if; |
| 16168 |
|
| 16169 |
-- Continue for any other node kind |
| 16170 |
|
| 16171 |
else |
| 16172 |
return OK; |
| 16173 |
end if; |
| 16174 |
end Replace_Type_Ref; |
| 16175 |
|
| 16176 |
procedure Replace_Type_Refs is new Traverse_Proc (Replace_Type_Ref); |
| 16177 |
|
| 16178 |
----------------------- |
| 16179 |
-- Visible_Component -- |
| 16180 |
----------------------- |
| 16181 |
|
| 16182 |
function Visible_Component (Comp : Name_Id) return Entity_Id is |
| 16183 |
E : Entity_Id; |
| 16184 |
|
| 16185 |
begin |
| 16186 |
-- Types with nameable components are record, task, protected types |
| 16187 |
|
| 16188 |
if Ekind (T) in E_Record_Type | E_Task_Type | E_Protected_Type then |
| 16189 |
-- This is a sequential search, which seems acceptable |
| 16190 |
-- efficiency-wise, given the typical size of component |
| 16191 |
-- lists, protected operation lists, task item lists, and |
| 16192 |
-- check expressions. |
| 16193 |
|
| 16194 |
E := First_Entity (T); |
| 16195 |
while Present (E) loop |
| 16196 |
if Comes_From_Source (E) and then Chars (E) = Comp then |
| 16197 |
return E; |
| 16198 |
end if; |
| 16199 |
|
| 16200 |
Next_Entity (E); |
| 16201 |
end loop; |
| 16202 |
|
| 16203 |
-- Private discriminated types may have visible discriminants |
| 16204 |
|
| 16205 |
elsif Is_Private_Type (T) and then Has_Discriminants (T) then |
| 16206 |
declare |
| 16207 |
Decl : constant Node_Id := Declaration_Node (T); |
| 16208 |
|
| 16209 |
Discr : Node_Id; |
| 16210 |
|
| 16211 |
begin |
| 16212 |
-- Loop over the discriminants listed in the discriminant part |
| 16213 |
-- of the private type declaration to find one with a matching |
| 16214 |
-- name; then, if it exists, return the discriminant entity of |
| 16215 |
-- the same name in the type, which is that of its full view. |
| 16216 |
|
| 16217 |
if Nkind (Decl) in N_Private_Extension_Declaration |
| 16218 |
| N_Private_Type_Declaration |
| 16219 |
and then Present (Discriminant_Specifications (Decl)) |
| 16220 |
then |
| 16221 |
Discr := First (Discriminant_Specifications (Decl)); |
| 16222 |
|
| 16223 |
while Present (Discr) loop |
| 16224 |
if Chars (Defining_Identifier (Discr)) = Comp then |
| 16225 |
Discr := First_Discriminant (T); |
| 16226 |
|
| 16227 |
while Present (Discr) loop |
| 16228 |
if Chars (Discr) = Comp then |
| 16229 |
return Discr; |
| 16230 |
end if; |
| 16231 |
|
| 16232 |
Next_Discriminant (Discr); |
| 16233 |
end loop; |
| 16234 |
|
| 16235 |
pragma Assert (False); |
| 16236 |
end if; |
| 16237 |
|
| 16238 |
Next (Discr); |
| 16239 |
end loop; |
| 16240 |
end if; |
| 16241 |
end; |
| 16242 |
end if; |
| 16243 |
|
| 16244 |
-- Nothing by that name |
| 16245 |
|
| 16246 |
return Empty; |
| 16247 |
end Visible_Component; |
| 16248 |
|
| 16249 |
-- Start of processing for Replace_Type_References_Generic |
| 16250 |
|
| 16251 |
begin |
| 16252 |
Replace_Type_Refs (N); |
| 16253 |
end Replace_Type_References_Generic; |
| 16254 |
|
| 16255 |
-------------------------------- |
| 16256 |
-- Resolve_Aspect_Expressions -- |
| 16257 |
-------------------------------- |
| 16258 |
|
| 16259 |
procedure Resolve_Aspect_Expressions (E : Entity_Id) is |
| 16260 |
function Resolve_Name (N : Node_Id) return Traverse_Result; |
| 16261 |
-- Verify that all identifiers in the expression, with the exception |
| 16262 |
-- of references to the current entity, denote visible entities. This |
| 16263 |
-- is done only to detect visibility errors, as the expression will be |
| 16264 |
-- properly analyzed/expanded during analysis of the predicate function |
| 16265 |
-- body. We omit quantified expressions from this test, given that they |
| 16266 |
-- introduce a local identifier that would require proper expansion to |
| 16267 |
-- handle properly. |
| 16268 |
|
| 16269 |
------------------ |
| 16270 |
-- Resolve_Name -- |
| 16271 |
------------------ |
| 16272 |
|
| 16273 |
function Resolve_Name (N : Node_Id) return Traverse_Result is |
| 16274 |
Dummy : Traverse_Result; |
| 16275 |
|
| 16276 |
begin |
| 16277 |
if Nkind (N) = N_Selected_Component then |
| 16278 |
if Nkind (Prefix (N)) = N_Identifier |
| 16279 |
and then Chars (Prefix (N)) /= Chars (E) |
| 16280 |
then |
| 16281 |
Find_Selected_Component (N); |
| 16282 |
|
| 16283 |
-- Reset the Entity if N is overloaded since the entity might |
| 16284 |
-- not be the correct one; allow later resolution to set it |
| 16285 |
-- properly. |
| 16286 |
|
| 16287 |
if Is_Overloaded (N) then |
| 16288 |
Set_Entity (N, Empty); |
| 16289 |
end if; |
| 16290 |
end if; |
| 16291 |
|
| 16292 |
return Skip; |
| 16293 |
|
| 16294 |
-- Resolve identifiers, but not selectors in parameter associations; |
| 16295 |
-- such selectors are never resolved by visibility. |
| 16296 |
|
| 16297 |
elsif Nkind (N) = N_Identifier |
| 16298 |
and then Chars (N) /= Chars (E) |
| 16299 |
and then (Nkind (Parent (N)) /= N_Parameter_Association |
| 16300 |
or else N /= Selector_Name (Parent (N))) |
| 16301 |
then |
| 16302 |
Find_Direct_Name (N); |
| 16303 |
|
| 16304 |
-- Reset the Entity as above for selected_components |
| 16305 |
|
| 16306 |
if Is_Overloaded (N) then |
| 16307 |
Set_Entity (N, Empty); |
| 16308 |
end if; |
| 16309 |
|
| 16310 |
-- The name in a component association needs no resolution |
| 16311 |
|
| 16312 |
elsif Nkind (N) = N_Component_Association then |
| 16313 |
Dummy := Resolve_Name (Expression (N)); |
| 16314 |
return Skip; |
| 16315 |
|
| 16316 |
elsif Nkind (N) = N_Quantified_Expression then |
| 16317 |
return Skip; |
| 16318 |
end if; |
| 16319 |
|
| 16320 |
return OK; |
| 16321 |
end Resolve_Name; |
| 16322 |
|
| 16323 |
procedure Resolve_Aspect_Expression is new Traverse_Proc (Resolve_Name); |
| 16324 |
|
| 16325 |
-- Local variables |
| 16326 |
|
| 16327 |
ASN : Node_Id := First_Rep_Item (E); |
| 16328 |
|
| 16329 |
-- Start of processing for Resolve_Aspect_Expressions |
| 16330 |
|
| 16331 |
begin |
| 16332 |
while Present (ASN) loop |
| 16333 |
if Nkind (ASN) = N_Aspect_Specification and then Entity (ASN) = E then |
| 16334 |
declare |
| 16335 |
A_Id : constant Aspect_Id := Get_Aspect_Id (ASN); |
| 16336 |
Expr : constant Node_Id := Expression (ASN); |
| 16337 |
|
| 16338 |
begin |
| 16339 |
case A_Id is |
| 16340 |
|
| 16341 |
when Aspect_Aggregate => |
| 16342 |
Resolve_Aspect_Aggregate (Entity (ASN), Expr); |
| 16343 |
|
| 16344 |
when Aspect_Stable_Properties => |
| 16345 |
Resolve_Aspect_Stable_Properties |
| 16346 |
(Entity (ASN), Expr, Class_Present (ASN)); |
| 16347 |
|
| 16348 |
when Aspect_Local_Restrictions => |
| 16349 |
-- Expression is an aggregate, but only syntactically |
| 16350 |
null; |
| 16351 |
|
| 16352 |
-- For now we only deal with aspects that do not generate |
| 16353 |
-- subprograms, or that may mention current instances of |
| 16354 |
-- types. These will require special handling???. |
| 16355 |
|
| 16356 |
when Aspect_Invariant |
| 16357 |
| Aspect_Predicate_Failure |
| 16358 |
=> |
| 16359 |
null; |
| 16360 |
|
| 16361 |
when Aspect_Dynamic_Predicate |
| 16362 |
| Aspect_Ghost_Predicate |
| 16363 |
| Aspect_Predicate |
| 16364 |
| Aspect_Static_Predicate |
| 16365 |
=> |
| 16366 |
-- Preanalyze expression after type replacement to catch |
| 16367 |
-- name resolution errors if the predicate function has |
| 16368 |
-- not been built yet. |
| 16369 |
|
| 16370 |
-- Note that we cannot use Preanalyze_And_Resolve |
| 16371 |
-- directly because of the special handling required for |
| 16372 |
-- quantifiers (see comments on Resolve_Aspect_Expression |
| 16373 |
-- above) but we need to emulate it properly. |
| 16374 |
|
| 16375 |
if No (Predicate_Function (E)) then |
| 16376 |
declare |
| 16377 |
Save_Full_Analysis : constant Boolean := |
| 16378 |
Full_Analysis; |
| 16379 |
begin |
| 16380 |
Full_Analysis := False; |
| 16381 |
Expander_Mode_Save_And_Set (False); |
| 16382 |
Push_Type (E); |
| 16383 |
Resolve_Aspect_Expression (Expr); |
| 16384 |
Pop_Type (E); |
| 16385 |
Expander_Mode_Restore; |
| 16386 |
Full_Analysis := Save_Full_Analysis; |
| 16387 |
end; |
| 16388 |
end if; |
| 16389 |
|
| 16390 |
when Pre_Post_Aspects => |
| 16391 |
null; |
| 16392 |
|
| 16393 |
when Aspect_Finalizable | Aspect_Iterable => |
| 16394 |
if Nkind (Expr) = N_Aggregate then |
| 16395 |
declare |
| 16396 |
Assoc : Node_Id; |
| 16397 |
|
| 16398 |
begin |
| 16399 |
Assoc := First (Component_Associations (Expr)); |
| 16400 |
while Present (Assoc) loop |
| 16401 |
if Nkind (Expression (Assoc)) in N_Has_Entity |
| 16402 |
then |
| 16403 |
Find_Direct_Name (Expression (Assoc)); |
| 16404 |
end if; |
| 16405 |
|
| 16406 |
Next (Assoc); |
| 16407 |
end loop; |
| 16408 |
end; |
| 16409 |
end if; |
| 16410 |
|
| 16411 |
-- The expression for Default_Value is a static expression |
| 16412 |
-- of the type, but this expression does not freeze the |
| 16413 |
-- type, so it can still appear in a representation clause |
| 16414 |
-- before the actual freeze point. |
| 16415 |
|
| 16416 |
when Aspect_Default_Value => |
| 16417 |
Check_Aspect_Too_Late (ASN); |
| 16418 |
Preanalyze_And_Resolve (Expr, E); |
| 16419 |
|
| 16420 |
when Aspect_Default_Component_Value => |
| 16421 |
Check_Aspect_Too_Late (ASN); |
| 16422 |
Preanalyze_And_Resolve (Expr, Component_Type (E)); |
| 16423 |
|
| 16424 |
when Aspect_CPU |
| 16425 |
| Aspect_Interrupt_Priority |
| 16426 |
| Aspect_Priority |
| 16427 |
=> |
| 16428 |
Push_Type (E); |
| 16429 |
Preanalyze_And_Resolve (Expr, Any_Integer); |
| 16430 |
Pop_Type (E); |
| 16431 |
|
| 16432 |
-- Ditto for Storage_Size. Any other aspects that carry |
| 16433 |
-- expressions that should not freeze ??? This is only |
| 16434 |
-- relevant to the misuse of deferred constants. |
| 16435 |
|
| 16436 |
when Aspect_Storage_Size => |
| 16437 |
Preanalyze_And_Resolve (Expr, Any_Integer); |
| 16438 |
|
| 16439 |
when others => |
| 16440 |
if Present (Expr) then |
| 16441 |
case Aspect_Argument (A_Id) is |
| 16442 |
when Expression |
| 16443 |
| Optional_Expression |
| 16444 |
=> |
| 16445 |
Analyze_And_Resolve (Expr); |
| 16446 |
|
| 16447 |
when Name |
| 16448 |
| Optional_Name |
| 16449 |
=> |
| 16450 |
if Nkind (Expr) = N_Identifier then |
| 16451 |
Find_Direct_Name (Expr); |
| 16452 |
|
| 16453 |
elsif Nkind (Expr) = N_Selected_Component then |
| 16454 |
Find_Selected_Component (Expr); |
| 16455 |
end if; |
| 16456 |
end case; |
| 16457 |
end if; |
| 16458 |
end case; |
| 16459 |
end; |
| 16460 |
end if; |
| 16461 |
|
| 16462 |
Next_Rep_Item (ASN); |
| 16463 |
end loop; |
| 16464 |
end Resolve_Aspect_Expressions; |
| 16465 |
|
| 16466 |
---------------------------- |
| 16467 |
-- Parse_Aspect_Aggregate -- |
| 16468 |
---------------------------- |
| 16469 |
|
| 16470 |
procedure Parse_Aspect_Aggregate |
| 16471 |
(N : Node_Id; |
| 16472 |
Empty_Subp : in out Node_Id; |
| 16473 |
Add_Named_Subp : in out Node_Id; |
| 16474 |
Add_Unnamed_Subp : in out Node_Id; |
| 16475 |
New_Indexed_Subp : in out Node_Id; |
| 16476 |
Assign_Indexed_Subp : in out Node_Id) |
| 16477 |
is |
| 16478 |
Assoc : Node_Id := First (Component_Associations (N)); |
| 16479 |
Op_Name : Name_Id; |
| 16480 |
Subp : Node_Id; |
| 16481 |
|
| 16482 |
begin |
| 16483 |
while Present (Assoc) loop |
| 16484 |
Subp := Expression (Assoc); |
| 16485 |
Op_Name := Chars (First (Choices (Assoc))); |
| 16486 |
if Op_Name = Name_Empty then |
| 16487 |
Empty_Subp := Subp; |
| 16488 |
|
| 16489 |
elsif Op_Name = Name_Add_Named then |
| 16490 |
Add_Named_Subp := Subp; |
| 16491 |
|
| 16492 |
elsif Op_Name = Name_Add_Unnamed then |
| 16493 |
Add_Unnamed_Subp := Subp; |
| 16494 |
|
| 16495 |
elsif Op_Name = Name_New_Indexed then |
| 16496 |
New_Indexed_Subp := Subp; |
| 16497 |
|
| 16498 |
elsif Op_Name = Name_Assign_Indexed then |
| 16499 |
Assign_Indexed_Subp := Subp; |
| 16500 |
end if; |
| 16501 |
|
| 16502 |
Next (Assoc); |
| 16503 |
end loop; |
| 16504 |
end Parse_Aspect_Aggregate; |
| 16505 |
|
| 16506 |
------------------------------------- |
| 16507 |
-- Parse_Aspect_Local_Restrictions -- |
| 16508 |
------------------------------------- |
| 16509 |
|
| 16510 |
function Parse_Aspect_Local_Restrictions (Aspect_Spec : Node_Id) |
| 16511 |
return Local_Restrict.Local_Restriction_Set |
| 16512 |
is |
| 16513 |
use Local_Restrict; |
| 16514 |
|
| 16515 |
Result : Local_Restriction_Set := (others => False); |
| 16516 |
Id : Node_Id := Expression (Aspect_Spec); |
| 16517 |
Is_Agg : constant Boolean := Nkind (Id) = N_Aggregate |
| 16518 |
and then not Is_Empty_List (Expressions (Id)); |
| 16519 |
begin |
| 16520 |
if Is_Agg then |
| 16521 |
Id := First (Expressions (Id)); |
| 16522 |
end if; |
| 16523 |
|
| 16524 |
while Present (Id) loop |
| 16525 |
if Nkind (Id) /= N_Identifier then |
| 16526 |
Error_Msg_N ("local restriction name not an identifier", Id); |
| 16527 |
exit; |
| 16528 |
end if; |
| 16529 |
|
| 16530 |
declare |
| 16531 |
Found : Boolean := False; |
| 16532 |
Nam : constant Name_Id := Chars (Id); |
| 16533 |
begin |
| 16534 |
for L_R in Local_Restriction loop |
| 16535 |
declare |
| 16536 |
S : String := L_R'Img; |
| 16537 |
begin |
| 16538 |
-- Note that the instance of System.Case_Util.To_Lower that |
| 16539 |
-- has signature |
| 16540 |
-- |
| 16541 |
-- function To_Lower (A : String) return String |
| 16542 |
-- |
| 16543 |
-- cannot be used here because it is not present in the |
| 16544 |
-- run-time library used by the bootstrap compiler at the |
| 16545 |
-- time of writing. |
| 16546 |
To_Lower (S); |
| 16547 |
if Length_Of_Name (Nam) = S'Length |
| 16548 |
and then Get_Name_String (Nam) = S |
| 16549 |
then |
| 16550 |
if Result (L_R) then |
| 16551 |
Error_Msg_N ("local restriction duplicated", Id); |
| 16552 |
exit; |
| 16553 |
end if; |
| 16554 |
Found := True; |
| 16555 |
Result (L_R) := True; |
| 16556 |
exit; |
| 16557 |
end if; |
| 16558 |
end; |
| 16559 |
end loop; |
| 16560 |
|
| 16561 |
if not Found then |
| 16562 |
Error_Msg_N ("invalid local restriction name", Id); |
| 16563 |
exit; |
| 16564 |
end if; |
| 16565 |
end; |
| 16566 |
|
| 16567 |
exit when not Is_Agg; |
| 16568 |
Next (Id); |
| 16569 |
end loop; |
| 16570 |
|
| 16571 |
return Result; |
| 16572 |
end Parse_Aspect_Local_Restrictions; |
| 16573 |
|
| 16574 |
------------------------------------ |
| 16575 |
-- Parse_Aspect_Stable_Properties -- |
| 16576 |
------------------------------------ |
| 16577 |
|
| 16578 |
function Parse_Aspect_Stable_Properties |
| 16579 |
(Aspect_Spec : Node_Id; Negated : out Boolean) return Subprogram_List |
| 16580 |
is |
| 16581 |
function Extract_Entity (Expr : Node_Id) return Entity_Id; |
| 16582 |
-- Given an element of a Stable_Properties aspect spec, return the |
| 16583 |
-- associated entity. |
| 16584 |
-- This function updates the Negated flag as a side effect. |
| 16585 |
|
| 16586 |
-------------------- |
| 16587 |
-- Extract_Entity -- |
| 16588 |
-------------------- |
| 16589 |
|
| 16590 |
function Extract_Entity (Expr : Node_Id) return Entity_Id is |
| 16591 |
Name : Node_Id; |
| 16592 |
begin |
| 16593 |
if Nkind (Expr) = N_Op_Not then |
| 16594 |
Negated := True; |
| 16595 |
Name := Right_Opnd (Expr); |
| 16596 |
else |
| 16597 |
Name := Expr; |
| 16598 |
end if; |
| 16599 |
|
| 16600 |
if Nkind (Name) in N_Has_Entity then |
| 16601 |
return Entity (Name); |
| 16602 |
else |
| 16603 |
return Empty; |
| 16604 |
end if; |
| 16605 |
end Extract_Entity; |
| 16606 |
|
| 16607 |
-- Local variables |
| 16608 |
|
| 16609 |
L : List_Id; |
| 16610 |
Id : Node_Id; |
| 16611 |
|
| 16612 |
-- Start of processing for Parse_Aspect_Stable_Properties |
| 16613 |
|
| 16614 |
begin |
| 16615 |
Negated := False; |
| 16616 |
|
| 16617 |
if Nkind (Aspect_Spec) /= N_Aggregate then |
| 16618 |
return (1 => Extract_Entity (Aspect_Spec)); |
| 16619 |
else |
| 16620 |
L := Expressions (Aspect_Spec); |
| 16621 |
Id := First (L); |
| 16622 |
|
| 16623 |
return Result : Subprogram_List (1 .. List_Length (L)) do |
| 16624 |
for I in Result'Range loop |
| 16625 |
Result (I) := Extract_Entity (Id); |
| 16626 |
|
| 16627 |
if No (Result (I)) then |
| 16628 |
pragma Assert (Serious_Errors_Detected > 0); |
| 16629 |
goto Ignore_Aspect; |
| 16630 |
end if; |
| 16631 |
|
| 16632 |
Next (Id); |
| 16633 |
end loop; |
| 16634 |
end return; |
| 16635 |
end if; |
| 16636 |
|
| 16637 |
<<Ignore_Aspect>> return (1 .. 0 => <>); |
| 16638 |
end Parse_Aspect_Stable_Properties; |
| 16639 |
|
| 16640 |
------------------------------- |
| 16641 |
-- Validate_Aspect_Aggregate -- |
| 16642 |
------------------------------- |
| 16643 |
|
| 16644 |
procedure Validate_Aspect_Aggregate (N : Node_Id) is |
| 16645 |
Empty_Subp : Node_Id := Empty; |
| 16646 |
Add_Named_Subp : Node_Id := Empty; |
| 16647 |
Add_Unnamed_Subp : Node_Id := Empty; |
| 16648 |
New_Indexed_Subp : Node_Id := Empty; |
| 16649 |
Assign_Indexed_Subp : Node_Id := Empty; |
| 16650 |
|
| 16651 |
begin |
| 16652 |
Error_Msg_Ada_2022_Feature ("aspect Aggregate", Sloc (N)); |
| 16653 |
|
| 16654 |
if Nkind (N) /= N_Aggregate |
| 16655 |
or else Present (Expressions (N)) |
| 16656 |
or else No (Component_Associations (N)) |
| 16657 |
then |
| 16658 |
Error_Msg_N ("aspect Aggregate requires an aggregate " |
| 16659 |
& "with component associations", N); |
| 16660 |
return; |
| 16661 |
end if; |
| 16662 |
|
| 16663 |
Parse_Aspect_Aggregate (N, |
| 16664 |
Empty_Subp, Add_Named_Subp, Add_Unnamed_Subp, |
| 16665 |
New_Indexed_Subp, Assign_Indexed_Subp); |
| 16666 |
|
| 16667 |
if No (Empty_Subp) then |
| 16668 |
Error_Msg_N ("missing specification for Empty in aggregate", N); |
| 16669 |
end if; |
| 16670 |
|
| 16671 |
if Present (Add_Named_Subp) then |
| 16672 |
if Present (Add_Unnamed_Subp) |
| 16673 |
or else Present (Assign_Indexed_Subp) |
| 16674 |
then |
| 16675 |
Error_Msg_N |
| 16676 |
("conflicting operations for aggregate (RM 4.3.5)", N); |
| 16677 |
return; |
| 16678 |
end if; |
| 16679 |
|
| 16680 |
elsif No (Add_Named_Subp) |
| 16681 |
and then No (Add_Unnamed_Subp) |
| 16682 |
and then No (Assign_Indexed_Subp) |
| 16683 |
then |
| 16684 |
Error_Msg_N ("incomplete specification for aggregate", N); |
| 16685 |
|
| 16686 |
elsif Present (New_Indexed_Subp) /= Present (Assign_Indexed_Subp) then |
| 16687 |
Error_Msg_N ("incomplete specification for indexed aggregate", N); |
| 16688 |
end if; |
| 16689 |
end Validate_Aspect_Aggregate; |
| 16690 |
|
| 16691 |
----------------------------------------- |
| 16692 |
-- Validate_Aspect_Local_Restrictions -- |
| 16693 |
----------------------------------------- |
| 16694 |
|
| 16695 |
procedure Validate_Aspect_Local_Restrictions (E : Entity_Id; N : Node_Id) is |
| 16696 |
use Local_Restrict; |
| 16697 |
begin |
| 16698 |
-- Do not check Is_Parenthesis_Aggregate. We don't want to |
| 16699 |
-- disallow the more familiar parens, but we also don't |
| 16700 |
-- want to require parens for a homogeneous list. |
| 16701 |
|
| 16702 |
if Nkind (N) = N_Identifier and then Paren_Count (N) = 1 then |
| 16703 |
-- a positional aggregate with one element (in effect) is ok |
| 16704 |
null; |
| 16705 |
elsif Nkind (N) /= N_Aggregate |
| 16706 |
or else No (Expressions (N)) |
| 16707 |
or else Present (Component_Associations (N)) |
| 16708 |
then |
| 16709 |
Error_Msg_N |
| 16710 |
("aspect Local_Restrictions requires a parenthesized list", N); |
| 16711 |
return; |
| 16712 |
end if; |
| 16713 |
|
| 16714 |
declare |
| 16715 |
Set : constant Local_Restriction_Set := |
| 16716 |
Parse_Aspect_Local_Restrictions (Parent (N)); |
| 16717 |
pragma Unreferenced (Set); |
| 16718 |
begin |
| 16719 |
null; |
| 16720 |
end; |
| 16721 |
|
| 16722 |
-- This will be relaxed later, e.g. for generic subprograms or |
| 16723 |
-- for packages. |
| 16724 |
|
| 16725 |
if Ekind (E) in Subprogram_Kind | E_Package then |
| 16726 |
if Get_Renamed_Entity (E) /= E then |
| 16727 |
Error_Msg_N |
| 16728 |
("aspect Local_Restrictions cannot be specified for " |
| 16729 |
& "a renaming", N); |
| 16730 |
end if; |
| 16731 |
else |
| 16732 |
Error_Msg_N |
| 16733 |
("aspect Local_Restrictions can only be specified for " |
| 16734 |
& "a subprogram or package spec", N); |
| 16735 |
end if; |
| 16736 |
end Validate_Aspect_Local_Restrictions; |
| 16737 |
|
| 16738 |
--------------------------------------- |
| 16739 |
-- Validate_Aspect_Stable_Properties -- |
| 16740 |
--------------------------------------- |
| 16741 |
|
| 16742 |
procedure Validate_Aspect_Stable_Properties |
| 16743 |
(E : Entity_Id; N : Node_Id; Class_Present : Boolean) |
| 16744 |
is |
| 16745 |
Is_Aspect_Of_Type : constant Boolean := Is_Type (E); |
| 16746 |
|
| 16747 |
type Permission is (Forbidden, Optional, Required); |
| 16748 |
Modifier_Permission : Permission := |
| 16749 |
(if Is_Aspect_Of_Type then Forbidden else Optional); |
| 16750 |
Modifier_Error_Called : Boolean := False; |
| 16751 |
|
| 16752 |
procedure Check_Property_Function_Arg (PF_Arg : Node_Id); |
| 16753 |
-- Check syntax of a property function argument |
| 16754 |
|
| 16755 |
---------------------------------- |
| 16756 |
-- Check_Property_Function_Arg -- |
| 16757 |
---------------------------------- |
| 16758 |
|
| 16759 |
procedure Check_Property_Function_Arg (PF_Arg : Node_Id) is |
| 16760 |
procedure Modifier_Error; |
| 16761 |
-- Generate message about bad "not" modifier if no message already |
| 16762 |
-- generated. Errors include specifying "not" for an aspect of |
| 16763 |
-- of a type and specifying "not" for some but not all of the |
| 16764 |
-- names in a list. |
| 16765 |
|
| 16766 |
-------------------- |
| 16767 |
-- Modifier_Error -- |
| 16768 |
-------------------- |
| 16769 |
|
| 16770 |
procedure Modifier_Error is |
| 16771 |
begin |
| 16772 |
if Modifier_Error_Called then |
| 16773 |
return; -- error message already generated |
| 16774 |
end if; |
| 16775 |
|
| 16776 |
Modifier_Error_Called := True; |
| 16777 |
|
| 16778 |
if Is_Aspect_Of_Type then |
| 16779 |
Error_Msg_N |
| 16780 |
("NOT modifier not allowed for Stable_Properties aspect" |
| 16781 |
& " of a type", PF_Arg); |
| 16782 |
else |
| 16783 |
Error_Msg_N ("mixed use of NOT modifiers", PF_Arg); |
| 16784 |
end if; |
| 16785 |
end Modifier_Error; |
| 16786 |
|
| 16787 |
PF_Name : Node_Id := PF_Arg; |
| 16788 |
|
| 16789 |
-- Start of processing for Check_Property_Function_Arg |
| 16790 |
|
| 16791 |
begin |
| 16792 |
if Nkind (PF_Arg) = N_Op_Not then |
| 16793 |
PF_Name := Right_Opnd (PF_Arg); |
| 16794 |
|
| 16795 |
case Modifier_Permission is |
| 16796 |
when Forbidden => |
| 16797 |
Modifier_Error; |
| 16798 |
when Optional => |
| 16799 |
Modifier_Permission := Required; |
| 16800 |
when Required => |
| 16801 |
null; |
| 16802 |
end case; |
| 16803 |
else |
| 16804 |
case Modifier_Permission is |
| 16805 |
when Forbidden => |
| 16806 |
null; |
| 16807 |
when Optional => |
| 16808 |
Modifier_Permission := Forbidden; |
| 16809 |
when Required => |
| 16810 |
Modifier_Error; |
| 16811 |
end case; |
| 16812 |
end if; |
| 16813 |
|
| 16814 |
if Nkind (PF_Name) not in |
| 16815 |
N_Identifier | N_Operator_Symbol | N_Selected_Component |
| 16816 |
then |
| 16817 |
Error_Msg_N ("bad property function name", PF_Name); |
| 16818 |
end if; |
| 16819 |
end Check_Property_Function_Arg; |
| 16820 |
|
| 16821 |
-- Start of processing for Validate_Aspect_Stable_Properties |
| 16822 |
|
| 16823 |
begin |
| 16824 |
Error_Msg_Ada_2022_Feature ("aspect Stable_Properties", Sloc (N)); |
| 16825 |
|
| 16826 |
if not Is_Aspect_Of_Type and then not Is_Subprogram (E) then |
| 16827 |
Error_Msg_N ("Stable_Properties aspect can only be specified for " |
| 16828 |
& "a type or a subprogram", N); |
| 16829 |
elsif Class_Present then |
| 16830 |
if Is_Aspect_Of_Type then |
| 16831 |
if not Is_Tagged_Type (E) then |
| 16832 |
Error_Msg_N |
| 16833 |
("Stable_Properties''Class aspect cannot be specified for " |
| 16834 |
& "an untagged type", N); |
| 16835 |
end if; |
| 16836 |
else |
| 16837 |
if not Is_Dispatching_Operation (E) then |
| 16838 |
Error_Msg_N |
| 16839 |
("Stable_Properties''Class aspect cannot be specified for " |
| 16840 |
& "a subprogram that is not a primitive subprogram " |
| 16841 |
& "of a tagged type", N); |
| 16842 |
end if; |
| 16843 |
end if; |
| 16844 |
end if; |
| 16845 |
|
| 16846 |
if Nkind (N) = N_Aggregate then |
| 16847 |
if Present (Component_Associations (N)) |
| 16848 |
or else Null_Record_Present (N) |
| 16849 |
or else No (Expressions (N)) |
| 16850 |
then |
| 16851 |
Error_Msg_N ("bad Stable_Properties aspect specification", N); |
| 16852 |
return; |
| 16853 |
end if; |
| 16854 |
|
| 16855 |
declare |
| 16856 |
PF_Arg : Node_Id := First (Expressions (N)); |
| 16857 |
begin |
| 16858 |
while Present (PF_Arg) loop |
| 16859 |
Check_Property_Function_Arg (PF_Arg); |
| 16860 |
Next (PF_Arg); |
| 16861 |
end loop; |
| 16862 |
end; |
| 16863 |
else |
| 16864 |
Check_Property_Function_Arg (N); |
| 16865 |
end if; |
| 16866 |
end Validate_Aspect_Stable_Properties; |
| 16867 |
|
| 16868 |
---------------------------------- |
| 16869 |
-- Resolve_Finalizable_Argument -- |
| 16870 |
---------------------------------- |
| 16871 |
|
| 16872 |
procedure Resolve_Finalizable_Argument |
| 16873 |
(N : Node_Id; |
| 16874 |
Typ : Entity_Id; |
| 16875 |
Nam : Name_Id) |
| 16876 |
is |
| 16877 |
function Is_Finalizable_Primitive (E : Entity_Id) return Boolean; |
| 16878 |
-- Check whether E is a finalizable primitive for Typ |
| 16879 |
|
| 16880 |
------------------------------ |
| 16881 |
-- Is_Finalizable_Primitive -- |
| 16882 |
------------------------------ |
| 16883 |
|
| 16884 |
function Is_Finalizable_Primitive (E : Entity_Id) return Boolean is |
| 16885 |
begin |
| 16886 |
return Ekind (E) = E_Procedure |
| 16887 |
and then Scope (E) = Scope (Typ) |
| 16888 |
and then Is_Primitive (E) |
| 16889 |
and then Present (First_Formal (E)) |
| 16890 |
and then Ekind (First_Formal (E)) = E_In_Out_Parameter |
| 16891 |
and then Etype (First_Formal (E)) = Typ |
| 16892 |
and then No (Next_Formal (First_Formal (E))); |
| 16893 |
end Is_Finalizable_Primitive; |
| 16894 |
|
| 16895 |
-- Start of processing for Resolve_Finalizable_Argument |
| 16896 |
|
| 16897 |
begin |
| 16898 |
if Nam = Name_Relaxed_Finalization then |
| 16899 |
Resolve (N, Any_Boolean); |
| 16900 |
|
| 16901 |
if Is_OK_Static_Expression (N) then |
| 16902 |
Set_Has_Relaxed_Finalization (Typ, Is_True (Static_Boolean (N))); |
| 16903 |
|
| 16904 |
else |
| 16905 |
Flag_Non_Static_Expr |
| 16906 |
("expression of aspect Finalizable must be static!", N); |
| 16907 |
end if; |
| 16908 |
|
| 16909 |
return; |
| 16910 |
end if; |
| 16911 |
|
| 16912 |
if not Is_Entity_Name (N) then |
| 16913 |
null; |
| 16914 |
|
| 16915 |
elsif not Is_Overloaded (N) then |
| 16916 |
if Is_Finalizable_Primitive (Entity (N)) then |
| 16917 |
return; |
| 16918 |
end if; |
| 16919 |
|
| 16920 |
else |
| 16921 |
-- Overloaded case: find subprogram with proper signature |
| 16922 |
|
| 16923 |
declare |
| 16924 |
I : Interp_Index; |
| 16925 |
It : Interp; |
| 16926 |
|
| 16927 |
begin |
| 16928 |
Get_First_Interp (N, I, It); |
| 16929 |
|
| 16930 |
while Present (It.Typ) loop |
| 16931 |
if Is_Finalizable_Primitive (It.Nam) then |
| 16932 |
Set_Entity (N, It.Nam); |
| 16933 |
return; |
| 16934 |
end if; |
| 16935 |
|
| 16936 |
Get_Next_Interp (I, It); |
| 16937 |
end loop; |
| 16938 |
end; |
| 16939 |
end if; |
| 16940 |
|
| 16941 |
Error_Msg_N |
| 16942 |
("subprogram must denote primitive procedure whose only formal " & |
| 16943 |
"parameter has mode `IN OUT` and is of the finalizable type", N); |
| 16944 |
end Resolve_Finalizable_Argument; |
| 16945 |
|
| 16946 |
-------------------------------- |
| 16947 |
-- Resolve_Iterable_Operation -- |
| 16948 |
-------------------------------- |
| 16949 |
|
| 16950 |
procedure Resolve_Iterable_Operation |
| 16951 |
(N : Node_Id; |
| 16952 |
Cursor : Entity_Id; |
| 16953 |
Typ : Entity_Id; |
| 16954 |
Nam : Name_Id) |
| 16955 |
is |
| 16956 |
Ent : Entity_Id; |
| 16957 |
F1 : Entity_Id; |
| 16958 |
F2 : Entity_Id; |
| 16959 |
|
| 16960 |
begin |
| 16961 |
if not Is_Overloaded (N) then |
| 16962 |
if not Is_Entity_Name (N) |
| 16963 |
or else Ekind (Entity (N)) /= E_Function |
| 16964 |
or else Scope (Entity (N)) /= Scope (Typ) |
| 16965 |
or else No (First_Formal (Entity (N))) |
| 16966 |
or else Etype (First_Formal (Entity (N))) /= Typ |
| 16967 |
then |
| 16968 |
Error_Msg_N |
| 16969 |
("iterable primitive must be local function name whose first " |
| 16970 |
& "formal is an iterable type", N); |
| 16971 |
return; |
| 16972 |
end if; |
| 16973 |
|
| 16974 |
Ent := Entity (N); |
| 16975 |
F1 := First_Formal (Ent); |
| 16976 |
F2 := Next_Formal (F1); |
| 16977 |
|
| 16978 |
if Nam = Name_First then |
| 16979 |
|
| 16980 |
-- First (Container) => Cursor |
| 16981 |
|
| 16982 |
if Etype (Ent) /= Cursor then |
| 16983 |
Error_Msg_N ("primitive for First must yield a cursor", N); |
| 16984 |
elsif Present (F2) then |
| 16985 |
Error_Msg_N ("no match for First iterable primitive", N); |
| 16986 |
end if; |
| 16987 |
|
| 16988 |
elsif Nam = Name_Last then |
| 16989 |
|
| 16990 |
-- Last (Container) => Cursor |
| 16991 |
|
| 16992 |
if Etype (Ent) /= Cursor then |
| 16993 |
Error_Msg_N ("primitive for Last must yield a cursor", N); |
| 16994 |
elsif Present (F2) then |
| 16995 |
Error_Msg_N ("no match for Last iterable primitive", N); |
| 16996 |
end if; |
| 16997 |
|
| 16998 |
elsif Nam = Name_Next then |
| 16999 |
|
| 17000 |
-- Next (Container, Cursor) => Cursor |
| 17001 |
|
| 17002 |
if No (F2) |
| 17003 |
or else Etype (F2) /= Cursor |
| 17004 |
or else Etype (Ent) /= Cursor |
| 17005 |
or else Present (Next_Formal (F2)) |
| 17006 |
then |
| 17007 |
Error_Msg_N ("no match for Next iterable primitive", N); |
| 17008 |
end if; |
| 17009 |
|
| 17010 |
elsif Nam = Name_Previous then |
| 17011 |
|
| 17012 |
-- Previous (Container, Cursor) => Cursor |
| 17013 |
|
| 17014 |
if No (F2) |
| 17015 |
or else Etype (F2) /= Cursor |
| 17016 |
or else Etype (Ent) /= Cursor |
| 17017 |
or else Present (Next_Formal (F2)) |
| 17018 |
then |
| 17019 |
Error_Msg_N ("no match for Previous iterable primitive", N); |
| 17020 |
end if; |
| 17021 |
|
| 17022 |
elsif Nam = Name_Has_Element then |
| 17023 |
|
| 17024 |
-- Has_Element (Container, Cursor) => Boolean |
| 17025 |
|
| 17026 |
if No (F2) |
| 17027 |
or else Etype (F2) /= Cursor |
| 17028 |
or else Etype (Ent) /= Standard_Boolean |
| 17029 |
or else Present (Next_Formal (F2)) |
| 17030 |
then |
| 17031 |
Error_Msg_N ("no match for Has_Element iterable primitive", N); |
| 17032 |
end if; |
| 17033 |
|
| 17034 |
elsif Nam = Name_Element then |
| 17035 |
|
| 17036 |
-- Element (Container, Cursor) => Element_Type; |
| 17037 |
|
| 17038 |
if No (F2) |
| 17039 |
or else Etype (F2) /= Cursor |
| 17040 |
or else Present (Next_Formal (F2)) |
| 17041 |
then |
| 17042 |
Error_Msg_N ("no match for Element iterable primitive", N); |
| 17043 |
end if; |
| 17044 |
|
| 17045 |
else |
| 17046 |
raise Program_Error; |
| 17047 |
end if; |
| 17048 |
|
| 17049 |
else |
| 17050 |
-- Overloaded case: find subprogram with proper signature. Caller |
| 17051 |
-- will report error if no match is found. |
| 17052 |
|
| 17053 |
declare |
| 17054 |
I : Interp_Index; |
| 17055 |
It : Interp; |
| 17056 |
|
| 17057 |
begin |
| 17058 |
Get_First_Interp (N, I, It); |
| 17059 |
while Present (It.Typ) loop |
| 17060 |
if Ekind (It.Nam) = E_Function |
| 17061 |
and then Scope (It.Nam) = Scope (Typ) |
| 17062 |
and then Present (First_Formal (It.Nam)) |
| 17063 |
and then Etype (First_Formal (It.Nam)) = Typ |
| 17064 |
then |
| 17065 |
F1 := First_Formal (It.Nam); |
| 17066 |
|
| 17067 |
if Nam = Name_First then |
| 17068 |
if Etype (It.Nam) = Cursor |
| 17069 |
and then No (Next_Formal (F1)) |
| 17070 |
then |
| 17071 |
Set_Entity (N, It.Nam); |
| 17072 |
exit; |
| 17073 |
end if; |
| 17074 |
|
| 17075 |
elsif Nam = Name_Next then |
| 17076 |
F2 := Next_Formal (F1); |
| 17077 |
|
| 17078 |
if Present (F2) |
| 17079 |
and then No (Next_Formal (F2)) |
| 17080 |
and then Etype (F2) = Cursor |
| 17081 |
and then Etype (It.Nam) = Cursor |
| 17082 |
then |
| 17083 |
Set_Entity (N, It.Nam); |
| 17084 |
exit; |
| 17085 |
end if; |
| 17086 |
|
| 17087 |
elsif Nam = Name_Has_Element then |
| 17088 |
F2 := Next_Formal (F1); |
| 17089 |
|
| 17090 |
if Present (F2) |
| 17091 |
and then No (Next_Formal (F2)) |
| 17092 |
and then Etype (F2) = Cursor |
| 17093 |
and then Etype (It.Nam) = Standard_Boolean |
| 17094 |
then |
| 17095 |
Set_Entity (N, It.Nam); |
| 17096 |
F2 := Next_Formal (F1); |
| 17097 |
exit; |
| 17098 |
end if; |
| 17099 |
|
| 17100 |
elsif Nam = Name_Element then |
| 17101 |
F2 := Next_Formal (F1); |
| 17102 |
|
| 17103 |
if Present (F2) |
| 17104 |
and then No (Next_Formal (F2)) |
| 17105 |
and then Etype (F2) = Cursor |
| 17106 |
then |
| 17107 |
Set_Entity (N, It.Nam); |
| 17108 |
exit; |
| 17109 |
end if; |
| 17110 |
end if; |
| 17111 |
end if; |
| 17112 |
|
| 17113 |
Get_Next_Interp (I, It); |
| 17114 |
end loop; |
| 17115 |
end; |
| 17116 |
end if; |
| 17117 |
end Resolve_Iterable_Operation; |
| 17118 |
|
| 17119 |
------------------------------ |
| 17120 |
-- Resolve_Aspect_Aggregate -- |
| 17121 |
------------------------------ |
| 17122 |
|
| 17123 |
procedure Resolve_Aspect_Aggregate |
| 17124 |
(Typ : Entity_Id; |
| 17125 |
Expr : Node_Id) |
| 17126 |
is |
| 17127 |
Impl_Typ : constant Entity_Id := Implementation_Base_Type (Typ); |
| 17128 |
|
| 17129 |
function Valid_Empty (E : Entity_Id) return Boolean; |
| 17130 |
function Valid_Add_Named (E : Entity_Id) return Boolean; |
| 17131 |
function Valid_Add_Unnamed (E : Entity_Id) return Boolean; |
| 17132 |
function Valid_New_Indexed (E : Entity_Id) return Boolean; |
| 17133 |
function Valid_Assign_Indexed (E : Entity_Id) return Boolean; |
| 17134 |
-- Predicates that establish the legality of each possible operation in |
| 17135 |
-- an Aggregate aspect. |
| 17136 |
|
| 17137 |
generic |
| 17138 |
with function Pred (Id : Node_Id) return Boolean; |
| 17139 |
procedure Resolve_Operation (Subp_Id : Node_Id); |
| 17140 |
-- Common processing to resolve each aggregate operation. |
| 17141 |
|
| 17142 |
------------------------ |
| 17143 |
-- Valid_Assign_Index -- |
| 17144 |
------------------------ |
| 17145 |
|
| 17146 |
function Valid_Assign_Indexed (E : Entity_Id) return Boolean is |
| 17147 |
begin |
| 17148 |
-- The profile must be the same as for Add_Named, with the added |
| 17149 |
-- requirement that the key_type be a discrete type. |
| 17150 |
|
| 17151 |
if Valid_Add_Named (E) then |
| 17152 |
return Is_Discrete_Type (Etype (Next_Formal (First_Formal (E)))); |
| 17153 |
else |
| 17154 |
return False; |
| 17155 |
end if; |
| 17156 |
end Valid_Assign_Indexed; |
| 17157 |
|
| 17158 |
----------------- |
| 17159 |
-- Valid_Empty -- |
| 17160 |
----------------- |
| 17161 |
|
| 17162 |
function Valid_Empty (E : Entity_Id) return Boolean is |
| 17163 |
begin |
| 17164 |
if Implementation_Base_Type (Etype (E)) /= Impl_Typ |
| 17165 |
or else Scope (E) /= Scope (Typ) |
| 17166 |
then |
| 17167 |
return False; |
| 17168 |
|
| 17169 |
elsif Ekind (E) = E_Function then |
| 17170 |
return No (First_Formal (E)) |
| 17171 |
or else |
| 17172 |
(Is_Signed_Integer_Type (Etype (First_Formal (E))) |
| 17173 |
and then No (Next_Formal (First_Formal (E)))); |
| 17174 |
else |
| 17175 |
return False; |
| 17176 |
end if; |
| 17177 |
end Valid_Empty; |
| 17178 |
|
| 17179 |
--------------------- |
| 17180 |
-- Valid_Add_Named -- |
| 17181 |
--------------------- |
| 17182 |
|
| 17183 |
function Valid_Add_Named (E : Entity_Id) return Boolean is |
| 17184 |
F2, F3 : Entity_Id; |
| 17185 |
begin |
| 17186 |
if Ekind (E) = E_Procedure |
| 17187 |
and then Scope (E) = Scope (Typ) |
| 17188 |
and then Number_Formals (E) = 3 |
| 17189 |
and then |
| 17190 |
Implementation_Base_Type (Etype (First_Formal (E))) = Impl_Typ |
| 17191 |
and then Ekind (First_Formal (E)) = E_In_Out_Parameter |
| 17192 |
then |
| 17193 |
F2 := Next_Formal (First_Formal (E)); |
| 17194 |
F3 := Next_Formal (F2); |
| 17195 |
return Ekind (F2) = E_In_Parameter |
| 17196 |
and then Ekind (F3) = E_In_Parameter |
| 17197 |
and then not Is_Limited_Type (Etype (F2)) |
| 17198 |
and then not Is_Limited_Type (Etype (F3)); |
| 17199 |
else |
| 17200 |
return False; |
| 17201 |
end if; |
| 17202 |
end Valid_Add_Named; |
| 17203 |
|
| 17204 |
----------------------- |
| 17205 |
-- Valid_Add_Unnamed -- |
| 17206 |
----------------------- |
| 17207 |
|
| 17208 |
function Valid_Add_Unnamed (E : Entity_Id) return Boolean is |
| 17209 |
begin |
| 17210 |
return Ekind (E) = E_Procedure |
| 17211 |
and then Scope (E) = Scope (Typ) |
| 17212 |
and then Number_Formals (E) = 2 |
| 17213 |
and then |
| 17214 |
Implementation_Base_Type (Etype (First_Formal (E))) = Impl_Typ |
| 17215 |
and then Ekind (First_Formal (E)) = E_In_Out_Parameter |
| 17216 |
and then |
| 17217 |
not Is_Limited_Type (Etype (Next_Formal (First_Formal (E)))); |
| 17218 |
end Valid_Add_Unnamed; |
| 17219 |
|
| 17220 |
----------------------- |
| 17221 |
-- Valid_New_Indexed -- |
| 17222 |
----------------------- |
| 17223 |
|
| 17224 |
function Valid_New_Indexed (E : Entity_Id) return Boolean is |
| 17225 |
begin |
| 17226 |
return Ekind (E) = E_Function |
| 17227 |
and then Scope (E) = Scope (Typ) |
| 17228 |
and then Implementation_Base_Type (Etype (E)) = Impl_Typ |
| 17229 |
and then Number_Formals (E) = 2 |
| 17230 |
and then Is_Discrete_Type (Etype (First_Formal (E))) |
| 17231 |
and then Etype (First_Formal (E)) = |
| 17232 |
Etype (Next_Formal (First_Formal (E))); |
| 17233 |
end Valid_New_Indexed; |
| 17234 |
|
| 17235 |
----------------------- |
| 17236 |
-- Resolve_Operation -- |
| 17237 |
----------------------- |
| 17238 |
|
| 17239 |
procedure Resolve_Operation (Subp_Id : Node_Id) is |
| 17240 |
I : Interp_Index; |
| 17241 |
It : Interp; |
| 17242 |
|
| 17243 |
begin |
| 17244 |
if not Is_Overloaded (Subp_Id) then |
| 17245 |
if not Pred (Entity (Subp_Id)) then |
| 17246 |
Error_Msg_NE |
| 17247 |
("improper aggregate operation for&", Subp_Id, Typ); |
| 17248 |
end if; |
| 17249 |
|
| 17250 |
else |
| 17251 |
Set_Entity (Subp_Id, Empty); |
| 17252 |
Get_First_Interp (Subp_Id, I, It); |
| 17253 |
while Present (It.Nam) loop |
| 17254 |
if Pred (It.Nam) then |
| 17255 |
if Present (Entity (Subp_Id)) then |
| 17256 |
-- ??? Cope with the obsolete renaming of Append_Vector |
| 17257 |
-- in Ada.Containers.Vectors retained for compatibility. |
| 17258 |
|
| 17259 |
if No (Alias (Entity (Subp_Id))) |
| 17260 |
and then No (Alias (It.Nam)) |
| 17261 |
then |
| 17262 |
Error_Msg_N |
| 17263 |
("& must denote exactly one subprogram", Subp_Id); |
| 17264 |
end if; |
| 17265 |
|
| 17266 |
exit; |
| 17267 |
end if; |
| 17268 |
Set_Is_Overloaded (Subp_Id, False); |
| 17269 |
Set_Entity (Subp_Id, It.Nam); |
| 17270 |
end if; |
| 17271 |
|
| 17272 |
Get_Next_Interp (I, It); |
| 17273 |
end loop; |
| 17274 |
|
| 17275 |
if No (Entity (Subp_Id)) then |
| 17276 |
Error_Msg_NE |
| 17277 |
("improper aggregate operation for&", Subp_Id, Typ); |
| 17278 |
end if; |
| 17279 |
end if; |
| 17280 |
end Resolve_Operation; |
| 17281 |
|
| 17282 |
Assoc : Node_Id; |
| 17283 |
Op_Name : Name_Id; |
| 17284 |
Subp_Id : Node_Id; |
| 17285 |
|
| 17286 |
procedure Resolve_Empty is new Resolve_Operation (Valid_Empty); |
| 17287 |
procedure Resolve_Unnamed is new Resolve_Operation (Valid_Add_Unnamed); |
| 17288 |
procedure Resolve_Named is new Resolve_Operation (Valid_Add_Named); |
| 17289 |
procedure Resolve_Indexed is new Resolve_Operation (Valid_New_Indexed); |
| 17290 |
procedure Resolve_Assign_Indexed |
| 17291 |
is new Resolve_Operation |
| 17292 |
(Valid_Assign_Indexed); |
| 17293 |
|
| 17294 |
-- Start of processing for Resolve_Aspect_Aggregate |
| 17295 |
|
| 17296 |
begin |
| 17297 |
Assoc := First (Component_Associations (Expr)); |
| 17298 |
|
| 17299 |
while Present (Assoc) loop |
| 17300 |
Op_Name := Chars (First (Choices (Assoc))); |
| 17301 |
|
| 17302 |
-- When verifying the consistency of aspects between the freeze point |
| 17303 |
-- and the end of declarations, we use a copy which is not analyzed |
| 17304 |
-- yet, so do it now. |
| 17305 |
|
| 17306 |
Subp_Id := Expression (Assoc); |
| 17307 |
if No (Etype (Subp_Id)) then |
| 17308 |
Analyze (Subp_Id); |
| 17309 |
end if; |
| 17310 |
|
| 17311 |
if Op_Name = Name_Empty then |
| 17312 |
Resolve_Empty (Subp_Id); |
| 17313 |
|
| 17314 |
elsif Op_Name = Name_Add_Named then |
| 17315 |
Resolve_Named (Subp_Id); |
| 17316 |
|
| 17317 |
elsif Op_Name = Name_Add_Unnamed then |
| 17318 |
Resolve_Unnamed (Subp_Id); |
| 17319 |
|
| 17320 |
elsif Op_Name = Name_New_Indexed then |
| 17321 |
Resolve_Indexed (Subp_Id); |
| 17322 |
|
| 17323 |
elsif Op_Name = Name_Assign_Indexed then |
| 17324 |
Resolve_Assign_Indexed (Subp_Id); |
| 17325 |
end if; |
| 17326 |
|
| 17327 |
Next (Assoc); |
| 17328 |
end loop; |
| 17329 |
end Resolve_Aspect_Aggregate; |
| 17330 |
|
| 17331 |
-------------------------------------- |
| 17332 |
-- Resolve_Aspect_Stable_Properties -- |
| 17333 |
-------------------------------------- |
| 17334 |
|
| 17335 |
procedure Resolve_Aspect_Stable_Properties |
| 17336 |
(Typ_Or_Subp : Entity_Id; Expr : Node_Id; Class_Present : Boolean) |
| 17337 |
is |
| 17338 |
Is_Aspect_Of_Type : constant Boolean := Is_Type (Typ_Or_Subp); |
| 17339 |
|
| 17340 |
Singleton : constant Boolean := Nkind (Expr) /= N_Aggregate; |
| 17341 |
Subp_Name : Node_Id := (if Singleton |
| 17342 |
then Expr |
| 17343 |
else First (Expressions (Expr))); |
| 17344 |
Has_Not : Boolean; |
| 17345 |
begin |
| 17346 |
if Is_Aspect_Of_Type |
| 17347 |
and then Has_Private_Declaration (Typ_Or_Subp) |
| 17348 |
and then not Is_Private_Type (Typ_Or_Subp) |
| 17349 |
then |
| 17350 |
Error_Msg_N |
| 17351 |
("Stable_Properties aspect cannot be specified " & |
| 17352 |
"for the completion of a private type", Typ_Or_Subp); |
| 17353 |
end if; |
| 17354 |
|
| 17355 |
-- Analogous checks that the aspect is not specified for a completion |
| 17356 |
-- in the subprogram case are not performed here because they are not |
| 17357 |
-- specific to this particular aspect. Right ??? |
| 17358 |
|
| 17359 |
loop |
| 17360 |
Has_Not := Nkind (Subp_Name) = N_Op_Not; |
| 17361 |
if Has_Not then |
| 17362 |
Set_Analyzed (Subp_Name); -- ??? |
| 17363 |
Subp_Name := Right_Opnd (Subp_Name); |
| 17364 |
end if; |
| 17365 |
|
| 17366 |
if No (Etype (Subp_Name)) then |
| 17367 |
Analyze (Subp_Name); |
| 17368 |
end if; |
| 17369 |
|
| 17370 |
declare |
| 17371 |
Subp : Entity_Id := Empty; |
| 17372 |
|
| 17373 |
I : Interp_Index; |
| 17374 |
It : Interp; |
| 17375 |
|
| 17376 |
function Is_Property_Function (E : Entity_Id) return Boolean; |
| 17377 |
-- Implements RM 7.3.4 definition of "property function" |
| 17378 |
|
| 17379 |
-------------------------- |
| 17380 |
-- Is_Property_Function -- |
| 17381 |
-------------------------- |
| 17382 |
|
| 17383 |
function Is_Property_Function (E : Entity_Id) return Boolean is |
| 17384 |
begin |
| 17385 |
if Ekind (E) not in E_Function | E_Operator |
| 17386 |
or else Number_Formals (E) /= 1 |
| 17387 |
then |
| 17388 |
return False; |
| 17389 |
end if; |
| 17390 |
|
| 17391 |
declare |
| 17392 |
Param_Type : constant Entity_Id := |
| 17393 |
Base_Type (Etype (First_Formal (E))); |
| 17394 |
|
| 17395 |
function Matches_Param_Type (Typ : Entity_Id) |
| 17396 |
return Boolean is |
| 17397 |
(Base_Type (Typ) = Param_Type |
| 17398 |
or else |
| 17399 |
(Is_Class_Wide_Type (Param_Type) |
| 17400 |
and then Is_Ancestor (Root_Type (Param_Type), |
| 17401 |
Base_Type (Typ)))); |
| 17402 |
begin |
| 17403 |
if Is_Aspect_Of_Type then |
| 17404 |
if Matches_Param_Type (Typ_Or_Subp) then |
| 17405 |
return True; |
| 17406 |
end if; |
| 17407 |
elsif Is_Primitive (Typ_Or_Subp) then |
| 17408 |
declare |
| 17409 |
Formal : Entity_Id := First_Formal (Typ_Or_Subp); |
| 17410 |
begin |
| 17411 |
while Present (Formal) loop |
| 17412 |
if Matches_Param_Type (Etype (Formal)) then |
| 17413 |
|
| 17414 |
-- Test whether Typ_Or_Subp (which is a subp |
| 17415 |
-- in this case) is primitive op of the type |
| 17416 |
-- of this parameter. |
| 17417 |
if Scope (Typ_Or_Subp) = Scope (Param_Type) then |
| 17418 |
return True; |
| 17419 |
end if; |
| 17420 |
end if; |
| 17421 |
Next_Formal (Formal); |
| 17422 |
end loop; |
| 17423 |
end; |
| 17424 |
end if; |
| 17425 |
end; |
| 17426 |
|
| 17427 |
return False; |
| 17428 |
end Is_Property_Function; |
| 17429 |
begin |
| 17430 |
if not Is_Overloaded (Subp_Name) then |
| 17431 |
Subp := Entity (Subp_Name); |
| 17432 |
if not Is_Property_Function (Subp) then |
| 17433 |
Error_Msg_NE ("improper property function for&", |
| 17434 |
Subp_Name, Typ_Or_Subp); |
| 17435 |
return; |
| 17436 |
end if; |
| 17437 |
else |
| 17438 |
Set_Entity (Subp_Name, Empty); |
| 17439 |
Get_First_Interp (Subp_Name, I, It); |
| 17440 |
while Present (It.Nam) loop |
| 17441 |
if Is_Property_Function (It.Nam) then |
| 17442 |
if Present (Subp) then |
| 17443 |
Error_Msg_NE |
| 17444 |
("ambiguous property function name for&", |
| 17445 |
Subp_Name, Typ_Or_Subp); |
| 17446 |
return; |
| 17447 |
end if; |
| 17448 |
|
| 17449 |
Subp := It.Nam; |
| 17450 |
Set_Is_Overloaded (Subp_Name, False); |
| 17451 |
Set_Entity (Subp_Name, Subp); |
| 17452 |
end if; |
| 17453 |
|
| 17454 |
Get_Next_Interp (I, It); |
| 17455 |
end loop; |
| 17456 |
|
| 17457 |
if No (Subp) then |
| 17458 |
Error_Msg_NE ("improper property function for&", |
| 17459 |
Subp_Name, Typ_Or_Subp); |
| 17460 |
return; |
| 17461 |
end if; |
| 17462 |
end if; |
| 17463 |
|
| 17464 |
-- perform legality (as opposed to name resolution) Subp checks |
| 17465 |
|
| 17466 |
if Is_Limited_Type (Etype (Subp)) then |
| 17467 |
Error_Msg_NE |
| 17468 |
("result type of property function for& is limited", |
| 17469 |
Subp_Name, Typ_Or_Subp); |
| 17470 |
end if; |
| 17471 |
|
| 17472 |
if Ekind (First_Formal (Subp)) /= E_In_Parameter then |
| 17473 |
Error_Msg_NE |
| 17474 |
("mode of parameter of property function for& is not IN", |
| 17475 |
Subp_Name, Typ_Or_Subp); |
| 17476 |
end if; |
| 17477 |
|
| 17478 |
if Is_Class_Wide_Type (Etype (First_Formal (Subp))) then |
| 17479 |
if not Covers (Etype (First_Formal (Subp)), Typ_Or_Subp) then |
| 17480 |
Error_Msg_NE |
| 17481 |
("class-wide parameter type of property function " & |
| 17482 |
"for& does not cover the type", |
| 17483 |
Subp_Name, Typ_Or_Subp); |
| 17484 |
|
| 17485 |
-- ??? This test is slightly stricter than 7.3.4(12/5); |
| 17486 |
-- some legal corner cases may be incorrectly rejected. |
| 17487 |
elsif Scope (Subp) /= Scope (Etype (First_Formal (Subp))) |
| 17488 |
then |
| 17489 |
Error_Msg_NE |
| 17490 |
("property function for& not declared in same scope " & |
| 17491 |
"as parameter type", |
| 17492 |
Subp_Name, Typ_Or_Subp); |
| 17493 |
end if; |
| 17494 |
elsif Is_Aspect_Of_Type and then |
| 17495 |
Scope (Subp) /= Scope (Typ_Or_Subp) and then |
| 17496 |
Scope (Subp) /= Standard_Standard -- e.g., derived type's "abs" |
| 17497 |
then |
| 17498 |
Error_Msg_NE |
| 17499 |
("property function for& " & |
| 17500 |
"not a primitive function of the type", |
| 17501 |
Subp_Name, Typ_Or_Subp); |
| 17502 |
end if; |
| 17503 |
|
| 17504 |
if Has_Not then |
| 17505 |
-- check that Subp was mentioned in param type's aspect spec |
| 17506 |
declare |
| 17507 |
Param_Type : constant Entity_Id := |
| 17508 |
Base_Type (Etype (First_Formal (Subp))); |
| 17509 |
Aspect_Spec : constant Node_Id := |
| 17510 |
Find_Value_Of_Aspect |
| 17511 |
(Param_Type, Aspect_Stable_Properties, |
| 17512 |
Class_Present => Class_Present); |
| 17513 |
Found : Boolean := False; |
| 17514 |
begin |
| 17515 |
if Present (Aspect_Spec) then |
| 17516 |
declare |
| 17517 |
Ignored : Boolean; |
| 17518 |
SPF_List : constant Subprogram_List := |
| 17519 |
Parse_Aspect_Stable_Properties |
| 17520 |
(Aspect_Spec, Negated => Ignored); |
| 17521 |
begin |
| 17522 |
Found := (for some E of SPF_List => E = Subp); |
| 17523 |
-- look through renamings ??? |
| 17524 |
end; |
| 17525 |
end if; |
| 17526 |
if not Found then |
| 17527 |
declare |
| 17528 |
CW_Modifier : constant String := |
| 17529 |
(if Class_Present then "class-wide " else ""); |
| 17530 |
begin |
| 17531 |
Error_Msg_NE |
| 17532 |
(CW_Modifier |
| 17533 |
& "property function for& mentioned after NOT " |
| 17534 |
& "but not a " |
| 17535 |
& CW_Modifier |
| 17536 |
& "stable property function of its parameter type", |
| 17537 |
Subp_Name, Typ_Or_Subp); |
| 17538 |
end; |
| 17539 |
end if; |
| 17540 |
end; |
| 17541 |
end if; |
| 17542 |
end; |
| 17543 |
|
| 17544 |
exit when Singleton; |
| 17545 |
Subp_Name := |
| 17546 |
Next ((if Has_Not then Parent (Subp_Name) else Subp_Name)); |
| 17547 |
exit when No (Subp_Name); |
| 17548 |
end loop; |
| 17549 |
|
| 17550 |
Set_Analyzed (Expr); |
| 17551 |
end Resolve_Aspect_Stable_Properties; |
| 17552 |
|
| 17553 |
----------------------------------------- |
| 17554 |
-- Resolve_Storage_Model_Type_Argument -- |
| 17555 |
----------------------------------------- |
| 17556 |
|
| 17557 |
procedure Resolve_Storage_Model_Type_Argument |
| 17558 |
(N : Node_Id; |
| 17559 |
Typ : Entity_Id; |
| 17560 |
Addr_Type : in out Entity_Id; |
| 17561 |
Nam : Name_Id) |
| 17562 |
is |
| 17563 |
|
| 17564 |
type Formal_Profile is record |
| 17565 |
Subt : Entity_Id; |
| 17566 |
Mode : Formal_Kind; |
| 17567 |
end record; |
| 17568 |
|
| 17569 |
type Formal_Profiles is array (Positive range <>) of Formal_Profile; |
| 17570 |
|
| 17571 |
function Aspect_Argument_Profile_Matches |
| 17572 |
(Subp : Entity_Id; |
| 17573 |
Profiles : Formal_Profiles; |
| 17574 |
Result_Subt : Entity_Id; |
| 17575 |
Err_On_Mismatch : Boolean) return Boolean; |
| 17576 |
-- Checks that the formal parameters of subprogram Subp conform to the |
| 17577 |
-- subtypes and modes specified by Profiles, as well as to the result |
| 17578 |
-- subtype Result_Subt when that is nonempty. |
| 17579 |
|
| 17580 |
function Aspect_Argument_Profile_Matches |
| 17581 |
(Subp : Entity_Id; |
| 17582 |
Profiles : Formal_Profiles; |
| 17583 |
Result_Subt : Entity_Id; |
| 17584 |
Err_On_Mismatch : Boolean) return Boolean |
| 17585 |
is |
| 17586 |
|
| 17587 |
procedure Report_Argument_Error |
| 17588 |
(Msg : String; |
| 17589 |
Formal : Entity_Id := Empty; |
| 17590 |
Subt : Entity_Id := Empty); |
| 17591 |
-- If Err_On_Mismatch is True, reports an argument error given by Msg |
| 17592 |
-- associated with Formal and/or Subt. |
| 17593 |
|
| 17594 |
procedure Report_Argument_Error |
| 17595 |
(Msg : String; |
| 17596 |
Formal : Entity_Id := Empty; |
| 17597 |
Subt : Entity_Id := Empty) |
| 17598 |
is |
| 17599 |
begin |
| 17600 |
if Err_On_Mismatch then |
| 17601 |
if Present (Formal) then |
| 17602 |
if Present (Subt) then |
| 17603 |
Error_Msg_Node_2 := Subt; |
| 17604 |
end if; |
| 17605 |
Error_Msg_NE (Msg, N, Formal); |
| 17606 |
|
| 17607 |
elsif Present (Subt) then |
| 17608 |
Error_Msg_NE (Msg, N, Subt); |
| 17609 |
|
| 17610 |
else |
| 17611 |
Error_Msg_N (Msg, N); |
| 17612 |
end if; |
| 17613 |
end if; |
| 17614 |
end Report_Argument_Error; |
| 17615 |
|
| 17616 |
-- Local variables |
| 17617 |
|
| 17618 |
Formal : Entity_Id := First_Formal (Subp); |
| 17619 |
Is_Error : Boolean := False; |
| 17620 |
|
| 17621 |
-- Start of processing for Aspect_Argument_Profile_Matches |
| 17622 |
|
| 17623 |
begin |
| 17624 |
for FP of Profiles loop |
| 17625 |
if No (Formal) then |
| 17626 |
Is_Error := True; |
| 17627 |
Report_Argument_Error ("missing formal of }", Subt => FP.Subt); |
| 17628 |
exit; |
| 17629 |
|
| 17630 |
elsif not Subtypes_Statically_Match |
| 17631 |
(Etype (Formal), FP.Subt) |
| 17632 |
then |
| 17633 |
Is_Error := True; |
| 17634 |
Report_Argument_Error |
| 17635 |
("formal& must be of subtype&", |
| 17636 |
Formal => Formal, Subt => FP.Subt); |
| 17637 |
exit; |
| 17638 |
|
| 17639 |
elsif Ekind (Formal) /= FP.Mode then |
| 17640 |
Is_Error := True; |
| 17641 |
Report_Argument_Error |
| 17642 |
("formal& has wrong mode", Formal => Formal); |
| 17643 |
exit; |
| 17644 |
end if; |
| 17645 |
|
| 17646 |
Formal := Next_Formal (Formal); |
| 17647 |
end loop; |
| 17648 |
|
| 17649 |
if not Is_Error |
| 17650 |
and then Present (Formal) |
| 17651 |
then |
| 17652 |
Is_Error := True; |
| 17653 |
Report_Argument_Error |
| 17654 |
("too many formals for subprogram in aspect"); |
| 17655 |
end if; |
| 17656 |
|
| 17657 |
if not Is_Error |
| 17658 |
and then Present (Result_Subt) |
| 17659 |
and then not Subtypes_Statically_Match (Etype (Subp), Result_Subt) |
| 17660 |
then |
| 17661 |
Is_Error := True; |
| 17662 |
Report_Argument_Error |
| 17663 |
("subprogram must have result}", Subt => Result_Subt); |
| 17664 |
end if; |
| 17665 |
|
| 17666 |
return not Is_Error; |
| 17667 |
end Aspect_Argument_Profile_Matches; |
| 17668 |
|
| 17669 |
-- Local variables |
| 17670 |
|
| 17671 |
Ent : Entity_Id; |
| 17672 |
|
| 17673 |
Storage_Count_Type : constant Entity_Id := RTE (RE_Storage_Count); |
| 17674 |
System_Address_Type : constant Entity_Id := RTE (RE_Address); |
| 17675 |
|
| 17676 |
-- Start of processing for Resolve_Storage_Model_Type_Argument |
| 17677 |
|
| 17678 |
begin |
| 17679 |
if Nam = Name_Address_Type then |
| 17680 |
if not Is_Entity_Name (N) |
| 17681 |
or else not Is_Type (Entity (N)) |
| 17682 |
or else (Root_Type (Entity (N)) /= System_Address_Type |
| 17683 |
and then not Is_Integer_Type (Entity (N))) |
| 17684 |
then |
| 17685 |
Error_Msg_N ("named entity must be a descendant of System.Address " |
| 17686 |
& "or an integer type", N); |
| 17687 |
end if; |
| 17688 |
|
| 17689 |
Addr_Type := Entity (N); |
| 17690 |
|
| 17691 |
return; |
| 17692 |
|
| 17693 |
-- If Addr_Type is not present as the first association, then we default |
| 17694 |
-- it to System.Address. |
| 17695 |
|
| 17696 |
elsif No (Addr_Type) then |
| 17697 |
Addr_Type := RTE (RE_Address); |
| 17698 |
end if; |
| 17699 |
|
| 17700 |
if Nam = Name_Null_Address then |
| 17701 |
if not Is_Entity_Name (N) |
| 17702 |
or else not Is_Constant_Object (Entity (N)) |
| 17703 |
or else |
| 17704 |
not Subtypes_Statically_Match (Etype (Entity (N)), Addr_Type) |
| 17705 |
then |
| 17706 |
Error_Msg_NE |
| 17707 |
("named entity must be constant of subtype}", N, Addr_Type); |
| 17708 |
end if; |
| 17709 |
|
| 17710 |
return; |
| 17711 |
|
| 17712 |
elsif not Is_Overloaded (N) then |
| 17713 |
if not Is_Entity_Name (N) |
| 17714 |
or else Ekind (Entity (N)) not in E_Function | E_Procedure |
| 17715 |
or else Scope (Entity (N)) /= Scope (Typ) |
| 17716 |
then |
| 17717 |
Error_Msg_N ("argument must be local subprogram name", N); |
| 17718 |
return; |
| 17719 |
end if; |
| 17720 |
|
| 17721 |
Ent := Entity (N); |
| 17722 |
|
| 17723 |
if Nam = Name_Allocate then |
| 17724 |
if not Aspect_Argument_Profile_Matches |
| 17725 |
(Ent, |
| 17726 |
Profiles => |
| 17727 |
((Typ, E_In_Out_Parameter), |
| 17728 |
(Addr_Type, E_Out_Parameter), |
| 17729 |
(Storage_Count_Type, E_In_Parameter), |
| 17730 |
(Storage_Count_Type, E_In_Parameter)), |
| 17731 |
Result_Subt => Empty, |
| 17732 |
Err_On_Mismatch => True) |
| 17733 |
then |
| 17734 |
Error_Msg_N ("no match for Allocate operation", N); |
| 17735 |
end if; |
| 17736 |
|
| 17737 |
elsif Nam = Name_Deallocate then |
| 17738 |
if not Aspect_Argument_Profile_Matches |
| 17739 |
(Ent, |
| 17740 |
Profiles => |
| 17741 |
((Typ, E_In_Out_Parameter), |
| 17742 |
(Addr_Type, E_In_Parameter), |
| 17743 |
(Storage_Count_Type, E_In_Parameter), |
| 17744 |
(Storage_Count_Type, E_In_Parameter)), |
| 17745 |
Result_Subt => Empty, |
| 17746 |
Err_On_Mismatch => True) |
| 17747 |
then |
| 17748 |
Error_Msg_N ("no match for Deallocate operation", N); |
| 17749 |
end if; |
| 17750 |
|
| 17751 |
elsif Nam = Name_Copy_From then |
| 17752 |
if not Aspect_Argument_Profile_Matches |
| 17753 |
(Ent, |
| 17754 |
Profiles => |
| 17755 |
((Typ, E_In_Out_Parameter), |
| 17756 |
(System_Address_Type, E_In_Parameter), |
| 17757 |
(Addr_Type, E_In_Parameter), |
| 17758 |
(Storage_Count_Type, E_In_Parameter)), |
| 17759 |
Result_Subt => Empty, |
| 17760 |
Err_On_Mismatch => True) |
| 17761 |
then |
| 17762 |
Error_Msg_N ("no match for Copy_From operation", N); |
| 17763 |
end if; |
| 17764 |
|
| 17765 |
elsif Nam = Name_Copy_To then |
| 17766 |
if not Aspect_Argument_Profile_Matches |
| 17767 |
(Ent, |
| 17768 |
Profiles => |
| 17769 |
((Typ, E_In_Out_Parameter), |
| 17770 |
(Addr_Type, E_In_Parameter), |
| 17771 |
(System_Address_Type, E_In_Parameter), |
| 17772 |
(Storage_Count_Type, E_In_Parameter)), |
| 17773 |
Result_Subt => Empty, |
| 17774 |
Err_On_Mismatch => True) |
| 17775 |
then |
| 17776 |
Error_Msg_N ("no match for Copy_To operation", N); |
| 17777 |
end if; |
| 17778 |
|
| 17779 |
elsif Nam = Name_Storage_Size then |
| 17780 |
if not Aspect_Argument_Profile_Matches |
| 17781 |
(Ent, |
| 17782 |
Profiles => (1 => (Typ, E_In_Parameter)), |
| 17783 |
Result_Subt => Storage_Count_Type, |
| 17784 |
Err_On_Mismatch => True) |
| 17785 |
then |
| 17786 |
Error_Msg_N ("no match for Storage_Size operation", N); |
| 17787 |
end if; |
| 17788 |
|
| 17789 |
else |
| 17790 |
null; -- Error will be caught in Validate_Storage_Model_Type_Aspect |
| 17791 |
end if; |
| 17792 |
|
| 17793 |
else |
| 17794 |
-- Overloaded case: find subprogram with proper signature |
| 17795 |
|
| 17796 |
declare |
| 17797 |
I : Interp_Index; |
| 17798 |
It : Interp; |
| 17799 |
Found_Match : Boolean := False; |
| 17800 |
|
| 17801 |
begin |
| 17802 |
Get_First_Interp (N, I, It); |
| 17803 |
while Present (It.Typ) loop |
| 17804 |
if Ekind (It.Nam) in E_Function | E_Procedure |
| 17805 |
and then Scope (It.Nam) = Scope (Typ) |
| 17806 |
then |
| 17807 |
if Nam = Name_Allocate then |
| 17808 |
Found_Match := |
| 17809 |
Aspect_Argument_Profile_Matches |
| 17810 |
(It.Nam, |
| 17811 |
Profiles => |
| 17812 |
((Typ, E_In_Out_Parameter), |
| 17813 |
(Addr_Type, E_Out_Parameter), |
| 17814 |
(Storage_Count_Type, E_In_Parameter), |
| 17815 |
(Storage_Count_Type, E_In_Parameter)), |
| 17816 |
Result_Subt => Empty, |
| 17817 |
Err_On_Mismatch => False); |
| 17818 |
|
| 17819 |
elsif Nam = Name_Deallocate then |
| 17820 |
Found_Match := |
| 17821 |
Aspect_Argument_Profile_Matches |
| 17822 |
(It.Nam, |
| 17823 |
Profiles => |
| 17824 |
((Typ, E_In_Out_Parameter), |
| 17825 |
(Addr_Type, E_In_Parameter), |
| 17826 |
(Storage_Count_Type, E_In_Parameter), |
| 17827 |
(Storage_Count_Type, E_In_Parameter)), |
| 17828 |
Result_Subt => Empty, |
| 17829 |
Err_On_Mismatch => False); |
| 17830 |
|
| 17831 |
elsif Nam = Name_Copy_From then |
| 17832 |
Found_Match := |
| 17833 |
Aspect_Argument_Profile_Matches |
| 17834 |
(It.Nam, |
| 17835 |
Profiles => |
| 17836 |
((Typ, E_In_Out_Parameter), |
| 17837 |
(System_Address_Type, E_In_Parameter), |
| 17838 |
(Addr_Type, E_In_Parameter), |
| 17839 |
(Storage_Count_Type, E_In_Parameter), |
| 17840 |
(Storage_Count_Type, E_In_Parameter)), |
| 17841 |
Result_Subt => Empty, |
| 17842 |
Err_On_Mismatch => False); |
| 17843 |
|
| 17844 |
elsif Nam = Name_Copy_To then |
| 17845 |
Found_Match := |
| 17846 |
Aspect_Argument_Profile_Matches |
| 17847 |
(It.Nam, |
| 17848 |
Profiles => |
| 17849 |
((Typ, E_In_Out_Parameter), |
| 17850 |
(Addr_Type, E_In_Parameter), |
| 17851 |
(Storage_Count_Type, E_In_Parameter), |
| 17852 |
(System_Address_Type, E_In_Parameter), |
| 17853 |
(Storage_Count_Type, E_In_Parameter)), |
| 17854 |
Result_Subt => Empty, |
| 17855 |
Err_On_Mismatch => False); |
| 17856 |
|
| 17857 |
elsif Nam = Name_Storage_Size then |
| 17858 |
Found_Match := |
| 17859 |
Aspect_Argument_Profile_Matches |
| 17860 |
(It.Nam, |
| 17861 |
Profiles => (1 => (Typ, E_In_Parameter)), |
| 17862 |
Result_Subt => Storage_Count_Type, |
| 17863 |
Err_On_Mismatch => False); |
| 17864 |
end if; |
| 17865 |
|
| 17866 |
if Found_Match then |
| 17867 |
Set_Entity (N, It.Nam); |
| 17868 |
exit; |
| 17869 |
end if; |
| 17870 |
end if; |
| 17871 |
|
| 17872 |
Get_Next_Interp (I, It); |
| 17873 |
end loop; |
| 17874 |
|
| 17875 |
if not Found_Match then |
| 17876 |
Error_Msg_N |
| 17877 |
("no match found for Storage_Model_Type operation", N); |
| 17878 |
end if; |
| 17879 |
end; |
| 17880 |
end if; |
| 17881 |
end Resolve_Storage_Model_Type_Argument; |
| 17882 |
|
| 17883 |
---------------- |
| 17884 |
-- Set_Biased -- |
| 17885 |
---------------- |
| 17886 |
|
| 17887 |
procedure Set_Biased |
| 17888 |
(E : Entity_Id; |
| 17889 |
N : Node_Id; |
| 17890 |
Msg : String; |
| 17891 |
Biased : Boolean := True) |
| 17892 |
is |
| 17893 |
begin |
| 17894 |
if Biased then |
| 17895 |
Set_Has_Biased_Representation (E); |
| 17896 |
|
| 17897 |
if Warn_On_Biased_Representation then |
| 17898 |
Error_Msg_NE |
| 17899 |
("?.b?" & Msg & " forces biased representation for&", N, E); |
| 17900 |
end if; |
| 17901 |
end if; |
| 17902 |
end Set_Biased; |
| 17903 |
|
| 17904 |
-------------------- |
| 17905 |
-- Set_Enum_Esize -- |
| 17906 |
-------------------- |
| 17907 |
|
| 17908 |
procedure Set_Enum_Esize (T : Entity_Id) is |
| 17909 |
Lo : Uint; |
| 17910 |
Hi : Uint; |
| 17911 |
Sz : Unat; |
| 17912 |
|
| 17913 |
begin |
| 17914 |
-- Find the minimum standard size (8,16,32,64,128) that fits |
| 17915 |
|
| 17916 |
Lo := Enumeration_Rep (Entity (Type_Low_Bound (T))); |
| 17917 |
Hi := Enumeration_Rep (Entity (Type_High_Bound (T))); |
| 17918 |
|
| 17919 |
if Lo < 0 then |
| 17920 |
if Lo >= -Uint_2**7 and then Hi < Uint_2**7 then |
| 17921 |
Sz := UI_From_Int (Standard_Character_Size); |
| 17922 |
-- Might be > 8 on some targets |
| 17923 |
|
| 17924 |
elsif Lo >= -Uint_2**15 and then Hi < Uint_2**15 then |
| 17925 |
Sz := Uint_16; |
| 17926 |
|
| 17927 |
elsif Lo >= -Uint_2**31 and then Hi < Uint_2**31 then |
| 17928 |
Sz := Uint_32; |
| 17929 |
|
| 17930 |
elsif Lo >= -Uint_2**63 and then Hi < Uint_2**63 then |
| 17931 |
Sz := Uint_64; |
| 17932 |
|
| 17933 |
else pragma Assert (Lo >= -Uint_2**127 and then Hi < Uint_2**127); |
| 17934 |
Sz := Uint_128; |
| 17935 |
end if; |
| 17936 |
|
| 17937 |
else |
| 17938 |
if Hi < Uint_2**8 then |
| 17939 |
Sz := UI_From_Int (Standard_Character_Size); |
| 17940 |
|
| 17941 |
elsif Hi < Uint_2**16 then |
| 17942 |
Sz := Uint_16; |
| 17943 |
|
| 17944 |
elsif Hi < Uint_2**32 then |
| 17945 |
Sz := Uint_32; |
| 17946 |
|
| 17947 |
elsif Hi < Uint_2**64 then |
| 17948 |
Sz := Uint_64; |
| 17949 |
|
| 17950 |
else pragma Assert (Hi < Uint_2**128); |
| 17951 |
Sz := Uint_128; |
| 17952 |
end if; |
| 17953 |
end if; |
| 17954 |
|
| 17955 |
-- That minimum is the proper size unless we have a foreign convention |
| 17956 |
-- and the size required is 32 or less, in which case we bump the size |
| 17957 |
-- up to 32. This is required for C and C++ and seems reasonable for |
| 17958 |
-- all other foreign conventions. |
| 17959 |
|
| 17960 |
if Has_Foreign_Convention (T) |
| 17961 |
and then Esize (T) < Standard_Integer_Size |
| 17962 |
|
| 17963 |
-- Don't do this if Short_Enums on target |
| 17964 |
|
| 17965 |
and then not Target_Short_Enums |
| 17966 |
then |
| 17967 |
Set_Esize (T, UI_From_Int (Standard_Integer_Size)); |
| 17968 |
else |
| 17969 |
Set_Esize (T, Sz); |
| 17970 |
end if; |
| 17971 |
end Set_Enum_Esize; |
| 17972 |
|
| 17973 |
----------------------------- |
| 17974 |
-- Uninstall_Discriminants -- |
| 17975 |
----------------------------- |
| 17976 |
|
| 17977 |
procedure Uninstall_Discriminants (E : Entity_Id) is |
| 17978 |
Disc : Entity_Id; |
| 17979 |
Prev : Entity_Id; |
| 17980 |
Outer : Entity_Id; |
| 17981 |
|
| 17982 |
begin |
| 17983 |
-- Discriminants have been made visible for type declarations and |
| 17984 |
-- protected type declarations, not for subtype declarations. |
| 17985 |
|
| 17986 |
if Nkind (Parent (E)) /= N_Subtype_Declaration then |
| 17987 |
Disc := First_Discriminant (E); |
| 17988 |
while Present (Disc) loop |
| 17989 |
if Disc /= Current_Entity (Disc) then |
| 17990 |
Prev := Current_Entity (Disc); |
| 17991 |
while Present (Prev) |
| 17992 |
and then Present (Homonym (Prev)) |
| 17993 |
and then Homonym (Prev) /= Disc |
| 17994 |
loop |
| 17995 |
Prev := Homonym (Prev); |
| 17996 |
end loop; |
| 17997 |
else |
| 17998 |
Prev := Empty; |
| 17999 |
end if; |
| 18000 |
|
| 18001 |
Set_Is_Immediately_Visible (Disc, False); |
| 18002 |
|
| 18003 |
Outer := Homonym (Disc); |
| 18004 |
while Present (Outer) and then Scope (Outer) = E loop |
| 18005 |
Outer := Homonym (Outer); |
| 18006 |
end loop; |
| 18007 |
|
| 18008 |
-- Reset homonym link of other entities, but do not modify link |
| 18009 |
-- between entities in current scope, so that the back end can |
| 18010 |
-- have a proper count of local overloadings. |
| 18011 |
|
| 18012 |
if No (Prev) then |
| 18013 |
Set_Name_Entity_Id (Chars (Disc), Outer); |
| 18014 |
|
| 18015 |
elsif Scope (Prev) /= Scope (Disc) then |
| 18016 |
Set_Homonym (Prev, Outer); |
| 18017 |
end if; |
| 18018 |
|
| 18019 |
Next_Discriminant (Disc); |
| 18020 |
end loop; |
| 18021 |
end if; |
| 18022 |
end Uninstall_Discriminants; |
| 18023 |
|
| 18024 |
------------------------------ |
| 18025 |
-- Validate_Address_Clauses -- |
| 18026 |
------------------------------ |
| 18027 |
|
| 18028 |
procedure Validate_Address_Clauses is |
| 18029 |
function Offset_Value (Expr : Node_Id) return Uint; |
| 18030 |
-- Given an Address attribute reference, return the value in bits of its |
| 18031 |
-- offset from the first bit of the underlying entity, or 0 if it is not |
| 18032 |
-- known at compile time. |
| 18033 |
|
| 18034 |
------------------ |
| 18035 |
-- Offset_Value -- |
| 18036 |
------------------ |
| 18037 |
|
| 18038 |
function Offset_Value (Expr : Node_Id) return Uint is |
| 18039 |
N : Node_Id := Prefix (Expr); |
| 18040 |
Off : Uint; |
| 18041 |
Val : Uint := Uint_0; |
| 18042 |
|
| 18043 |
begin |
| 18044 |
-- Climb the prefix chain and compute the cumulative offset |
| 18045 |
|
| 18046 |
loop |
| 18047 |
if Is_Entity_Name (N) then |
| 18048 |
return Val; |
| 18049 |
|
| 18050 |
elsif Nkind (N) = N_Selected_Component then |
| 18051 |
Off := Component_Bit_Offset (Entity (Selector_Name (N))); |
| 18052 |
if Present (Off) and then Off >= Uint_0 then |
| 18053 |
Val := Val + Off; |
| 18054 |
N := Prefix (N); |
| 18055 |
else |
| 18056 |
return Uint_0; |
| 18057 |
end if; |
| 18058 |
|
| 18059 |
elsif Nkind (N) = N_Indexed_Component then |
| 18060 |
Off := Indexed_Component_Bit_Offset (N); |
| 18061 |
if Present (Off) then |
| 18062 |
Val := Val + Off; |
| 18063 |
N := Prefix (N); |
| 18064 |
else |
| 18065 |
return Uint_0; |
| 18066 |
end if; |
| 18067 |
|
| 18068 |
else |
| 18069 |
return Uint_0; |
| 18070 |
end if; |
| 18071 |
end loop; |
| 18072 |
end Offset_Value; |
| 18073 |
|
| 18074 |
-- Start of processing for Validate_Address_Clauses |
| 18075 |
|
| 18076 |
begin |
| 18077 |
for J in Address_Clause_Checks.First .. Address_Clause_Checks.Last loop |
| 18078 |
declare |
| 18079 |
ACCR : Address_Clause_Check_Record |
| 18080 |
renames Address_Clause_Checks.Table (J); |
| 18081 |
|
| 18082 |
Expr : Node_Id; |
| 18083 |
|
| 18084 |
X_Alignment : Uint; |
| 18085 |
Y_Alignment : Uint := Uint_0; |
| 18086 |
|
| 18087 |
X_Size : Uint; |
| 18088 |
Y_Size : Uint := Uint_0; |
| 18089 |
|
| 18090 |
X_Offs : Uint; |
| 18091 |
|
| 18092 |
begin |
| 18093 |
-- Skip processing of this entry if alignments are not set |
| 18094 |
|
| 18095 |
if Known_Alignment (ACCR.X) |
| 18096 |
and then Known_Alignment (ACCR.Y) |
| 18097 |
then |
| 18098 |
Expr := Original_Node (Expression (ACCR.N)); |
| 18099 |
|
| 18100 |
-- Get alignments, sizes and offset, if any |
| 18101 |
|
| 18102 |
X_Alignment := Alignment (ACCR.X); |
| 18103 |
X_Size := Esize (ACCR.X); |
| 18104 |
|
| 18105 |
if Present (ACCR.Y) then |
| 18106 |
Y_Alignment := Alignment (ACCR.Y); |
| 18107 |
Y_Size := |
| 18108 |
(if Known_Esize (ACCR.Y) then Esize (ACCR.Y) else Uint_0); |
| 18109 |
end if; |
| 18110 |
|
| 18111 |
if ACCR.Off |
| 18112 |
and then Nkind (Expr) = N_Attribute_Reference |
| 18113 |
and then Attribute_Name (Expr) = Name_Address |
| 18114 |
then |
| 18115 |
X_Offs := Offset_Value (Expr); |
| 18116 |
else |
| 18117 |
X_Offs := Uint_0; |
| 18118 |
end if; |
| 18119 |
|
| 18120 |
-- Check for known value not multiple of alignment |
| 18121 |
|
| 18122 |
if No (ACCR.Y) then |
| 18123 |
if not Alignment_Checks_Suppressed (ACCR) |
| 18124 |
and then X_Alignment /= 0 |
| 18125 |
and then ACCR.A mod X_Alignment /= 0 |
| 18126 |
then |
| 18127 |
Error_Msg_NE |
| 18128 |
("??specified address for& is inconsistent with " |
| 18129 |
& "alignment", ACCR.N, ACCR.X); |
| 18130 |
Error_Msg_N |
| 18131 |
("\??program execution may be erroneous (RM 13.3(27))", |
| 18132 |
ACCR.N); |
| 18133 |
|
| 18134 |
Error_Msg_Uint_1 := X_Alignment; |
| 18135 |
Error_Msg_NE ("\??alignment of & is ^", ACCR.N, ACCR.X); |
| 18136 |
end if; |
| 18137 |
|
| 18138 |
-- Check for large object overlaying smaller one |
| 18139 |
|
| 18140 |
elsif Y_Size > Uint_0 |
| 18141 |
and then X_Size > Uint_0 |
| 18142 |
and then X_Offs + X_Size > Y_Size |
| 18143 |
then |
| 18144 |
Error_Msg_NE ("??& overlays smaller object", ACCR.N, ACCR.X); |
| 18145 |
Error_Msg_N |
| 18146 |
("\??program execution may be erroneous", ACCR.N); |
| 18147 |
|
| 18148 |
Error_Msg_Uint_1 := X_Size; |
| 18149 |
Error_Msg_NE ("\??size of & is ^", ACCR.N, ACCR.X); |
| 18150 |
|
| 18151 |
Error_Msg_Uint_1 := Y_Size; |
| 18152 |
Error_Msg_NE ("\??size of & is ^", ACCR.N, ACCR.Y); |
| 18153 |
|
| 18154 |
if Y_Size >= X_Size then |
| 18155 |
Error_Msg_Uint_1 := X_Offs; |
| 18156 |
Error_Msg_NE ("\??but offset of & is ^", ACCR.N, ACCR.X); |
| 18157 |
end if; |
| 18158 |
|
| 18159 |
-- Check for inadequate alignment, both of the base object |
| 18160 |
-- and of the offset, if any. We only do this check if the |
| 18161 |
-- run-time Alignment_Check is active. No point in warning |
| 18162 |
-- if this check has been suppressed (or is suppressed by |
| 18163 |
-- default in the non-strict alignment machine case). |
| 18164 |
|
| 18165 |
-- Note: we do not check the alignment if we gave a size |
| 18166 |
-- warning, since it would likely be redundant. |
| 18167 |
|
| 18168 |
elsif not Alignment_Checks_Suppressed (ACCR) |
| 18169 |
and then Y_Alignment /= Uint_0 |
| 18170 |
and then |
| 18171 |
(Y_Alignment < X_Alignment |
| 18172 |
or else |
| 18173 |
(ACCR.Off |
| 18174 |
and then Nkind (Expr) = N_Attribute_Reference |
| 18175 |
and then Attribute_Name (Expr) = Name_Address |
| 18176 |
and then Has_Compatible_Alignment |
| 18177 |
(ACCR.X, Prefix (Expr), True) /= |
| 18178 |
Known_Compatible)) |
| 18179 |
then |
| 18180 |
Error_Msg_NE |
| 18181 |
("??specified address for& may be inconsistent with " |
| 18182 |
& "alignment", ACCR.N, ACCR.X); |
| 18183 |
Error_Msg_N |
| 18184 |
("\??program execution may be erroneous (RM 13.3(27))", |
| 18185 |
ACCR.N); |
| 18186 |
|
| 18187 |
Error_Msg_Uint_1 := X_Alignment; |
| 18188 |
Error_Msg_NE ("\??alignment of & is ^", ACCR.N, ACCR.X); |
| 18189 |
|
| 18190 |
Error_Msg_Uint_1 := Y_Alignment; |
| 18191 |
Error_Msg_NE ("\??alignment of & is ^", ACCR.N, ACCR.Y); |
| 18192 |
|
| 18193 |
if Y_Alignment >= X_Alignment then |
| 18194 |
Error_Msg_N |
| 18195 |
("\??but offset is not multiple of alignment", ACCR.N); |
| 18196 |
end if; |
| 18197 |
end if; |
| 18198 |
end if; |
| 18199 |
end; |
| 18200 |
end loop; |
| 18201 |
end Validate_Address_Clauses; |
| 18202 |
|
| 18203 |
--------------------------------- |
| 18204 |
-- Validate_Finalizable_Aspect -- |
| 18205 |
--------------------------------- |
| 18206 |
|
| 18207 |
procedure Validate_Finalizable_Aspect (Typ : Entity_Id; ASN : Node_Id) is |
| 18208 |
Aggr : constant Node_Id := Expression (ASN); |
| 18209 |
|
| 18210 |
Assoc : Node_Id; |
| 18211 |
Exp : Node_Id; |
| 18212 |
Nam : Node_Id; |
| 18213 |
|
| 18214 |
begin |
| 18215 |
if not Is_Record_Type (Typ) then |
| 18216 |
Error_Msg_N |
| 18217 |
("aspect Finalizable can only be specified for a record type", ASN); |
| 18218 |
return; |
| 18219 |
|
| 18220 |
elsif Is_Derived_Type (Typ) then |
| 18221 |
Error_Msg_N |
| 18222 |
("aspect Finalizable cannot be specified for a derived type", ASN); |
| 18223 |
return; |
| 18224 |
|
| 18225 |
elsif Nkind (Aggr) /= N_Aggregate then |
| 18226 |
Error_Msg_N ("aspect Finalizable must be an aggregate", Aggr); |
| 18227 |
return; |
| 18228 |
|
| 18229 |
elsif not Is_Empty_List (Expressions (Aggr)) then |
| 18230 |
Error_Msg_N |
| 18231 |
("illegal positional association", First (Expressions (Aggr))); |
| 18232 |
return; |
| 18233 |
end if; |
| 18234 |
|
| 18235 |
Set_Is_Controlled_Active (Typ); |
| 18236 |
|
| 18237 |
-- Relaxed_Finalization is optional and set True if not specified |
| 18238 |
|
| 18239 |
Set_Has_Relaxed_Finalization (Typ); |
| 18240 |
|
| 18241 |
Assoc := First (Component_Associations (Aggr)); |
| 18242 |
while Present (Assoc) loop |
| 18243 |
Nam := First (Choices (Assoc)); |
| 18244 |
Exp := Expression (Assoc); |
| 18245 |
|
| 18246 |
if Nkind (Nam) /= N_Identifier or else Present (Next (Nam)) then |
| 18247 |
Error_Msg_N ("illegal name in association", Nam); |
| 18248 |
|
| 18249 |
elsif Chars (Nam) in Name_Initialize | Name_Adjust | Name_Finalize |
| 18250 |
then |
| 18251 |
Analyze (Exp); |
| 18252 |
Resolve_Finalizable_Argument (Exp, Typ, Chars (Nam)); |
| 18253 |
|
| 18254 |
elsif Chars (Nam) = Name_Relaxed_Finalization then |
| 18255 |
if Inside_A_Generic then |
| 18256 |
Preanalyze_And_Resolve (Exp, Any_Boolean); |
| 18257 |
else |
| 18258 |
Analyze (Exp); |
| 18259 |
Resolve_Finalizable_Argument (Exp, Typ, Chars (Nam)); |
| 18260 |
end if; |
| 18261 |
|
| 18262 |
else |
| 18263 |
Error_Msg_N ("invalid argument for Finalizable aspect", Nam); |
| 18264 |
end if; |
| 18265 |
|
| 18266 |
Next (Assoc); |
| 18267 |
end loop; |
| 18268 |
|
| 18269 |
-- If Relaxed_Finalization is set, the Finalize and Adjust procedures |
| 18270 |
-- are considered as having the No_Raise aspect specified. |
| 18271 |
|
| 18272 |
if Serious_Errors_Detected > 0 then |
| 18273 |
null; |
| 18274 |
|
| 18275 |
elsif Has_Relaxed_Finalization (Typ) then |
| 18276 |
Assoc := First (Component_Associations (Aggr)); |
| 18277 |
while Present (Assoc) loop |
| 18278 |
Nam := First (Choices (Assoc)); |
| 18279 |
Exp := Expression (Assoc); |
| 18280 |
|
| 18281 |
if Chars (Nam) in Name_Adjust | Name_Finalize then |
| 18282 |
pragma Assert (Is_Entity_Name (Exp)); |
| 18283 |
Set_No_Raise (Entity (Exp)); |
| 18284 |
end if; |
| 18285 |
|
| 18286 |
Next (Assoc); |
| 18287 |
end loop; |
| 18288 |
|
| 18289 |
-- If Relaxed_Finalization is not set, then check that the support for |
| 18290 |
-- strict finalization is available in the runtime library. |
| 18291 |
|
| 18292 |
elsif not In_Predefined_Unit (Cunit (Get_Source_Unit (Typ))) |
| 18293 |
and then not RTE_Available (RE_Finalization_Master) |
| 18294 |
then |
| 18295 |
Error_Msg_N |
| 18296 |
("only Relaxed Finalization is supported in this configuration", |
| 18297 |
ASN); |
| 18298 |
end if; |
| 18299 |
end Validate_Finalizable_Aspect; |
| 18300 |
|
| 18301 |
------------------------------ |
| 18302 |
-- Validate_Iterable_Aspect -- |
| 18303 |
------------------------------ |
| 18304 |
|
| 18305 |
procedure Validate_Iterable_Aspect (Typ : Entity_Id; ASN : Node_Id) is |
| 18306 |
Aggr : constant Node_Id := Expression (ASN); |
| 18307 |
Assoc : Node_Id; |
| 18308 |
Expr : Node_Id; |
| 18309 |
|
| 18310 |
Prim : Node_Id; |
| 18311 |
Cursor : Entity_Id; |
| 18312 |
|
| 18313 |
First_Id : Entity_Id := Empty; |
| 18314 |
Last_Id : Entity_Id := Empty; |
| 18315 |
Next_Id : Entity_Id := Empty; |
| 18316 |
Has_Element_Id : Entity_Id := Empty; |
| 18317 |
Element_Id : Entity_Id := Empty; |
| 18318 |
|
| 18319 |
begin |
| 18320 |
if Nkind (Aggr) /= N_Aggregate then |
| 18321 |
Error_Msg_N ("aspect Iterable must be an aggregate", Aggr); |
| 18322 |
return; |
| 18323 |
end if; |
| 18324 |
|
| 18325 |
Cursor := Get_Cursor_Type (ASN, Typ); |
| 18326 |
|
| 18327 |
-- If previous error aspect is unusable |
| 18328 |
|
| 18329 |
if Cursor = Any_Type then |
| 18330 |
return; |
| 18331 |
end if; |
| 18332 |
|
| 18333 |
if not Is_Empty_List (Expressions (Aggr)) then |
| 18334 |
Error_Msg_N |
| 18335 |
("illegal positional association", First (Expressions (Aggr))); |
| 18336 |
end if; |
| 18337 |
|
| 18338 |
-- Each expression must resolve to a function with the proper signature |
| 18339 |
|
| 18340 |
Assoc := First (Component_Associations (Aggr)); |
| 18341 |
while Present (Assoc) loop |
| 18342 |
Expr := Expression (Assoc); |
| 18343 |
Analyze (Expr); |
| 18344 |
|
| 18345 |
Prim := First (Choices (Assoc)); |
| 18346 |
|
| 18347 |
if Nkind (Prim) /= N_Identifier or else Present (Next (Prim)) then |
| 18348 |
Error_Msg_N ("illegal name in association", Prim); |
| 18349 |
|
| 18350 |
elsif Chars (Prim) = Name_First then |
| 18351 |
Resolve_Iterable_Operation (Expr, Cursor, Typ, Name_First); |
| 18352 |
First_Id := Entity (Expr); |
| 18353 |
|
| 18354 |
elsif Chars (Prim) = Name_Last then |
| 18355 |
Resolve_Iterable_Operation (Expr, Cursor, Typ, Name_Last); |
| 18356 |
Last_Id := Entity (Expr); |
| 18357 |
|
| 18358 |
elsif Chars (Prim) = Name_Previous then |
| 18359 |
Resolve_Iterable_Operation (Expr, Cursor, Typ, Name_Previous); |
| 18360 |
Last_Id := Entity (Expr); |
| 18361 |
|
| 18362 |
elsif Chars (Prim) = Name_Next then |
| 18363 |
Resolve_Iterable_Operation (Expr, Cursor, Typ, Name_Next); |
| 18364 |
Next_Id := Entity (Expr); |
| 18365 |
|
| 18366 |
elsif Chars (Prim) = Name_Has_Element then |
| 18367 |
Resolve_Iterable_Operation (Expr, Cursor, Typ, Name_Has_Element); |
| 18368 |
Has_Element_Id := Entity (Expr); |
| 18369 |
|
| 18370 |
elsif Chars (Prim) = Name_Element then |
| 18371 |
Resolve_Iterable_Operation (Expr, Cursor, Typ, Name_Element); |
| 18372 |
Element_Id := Entity (Expr); |
| 18373 |
|
| 18374 |
else |
| 18375 |
Error_Msg_N ("invalid name for iterable function", Prim); |
| 18376 |
end if; |
| 18377 |
|
| 18378 |
Next (Assoc); |
| 18379 |
end loop; |
| 18380 |
|
| 18381 |
if No (First_Id) then |
| 18382 |
Error_Msg_N ("match for First primitive not found", ASN); |
| 18383 |
|
| 18384 |
elsif No (Next_Id) then |
| 18385 |
Error_Msg_N ("match for Next primitive not found", ASN); |
| 18386 |
|
| 18387 |
elsif No (Has_Element_Id) then |
| 18388 |
Error_Msg_N ("match for Has_Element primitive not found", ASN); |
| 18389 |
|
| 18390 |
elsif No (Element_Id) or else No (Last_Id) then |
| 18391 |
null; -- optional |
| 18392 |
end if; |
| 18393 |
end Validate_Iterable_Aspect; |
| 18394 |
|
| 18395 |
------------------------------ |
| 18396 |
-- Validate_Literal_Aspect -- |
| 18397 |
------------------------------ |
| 18398 |
|
| 18399 |
procedure Validate_Literal_Aspect (Typ : Entity_Id; ASN : Node_Id) is |
| 18400 |
A_Id : constant Aspect_Id := Get_Aspect_Id (ASN); |
| 18401 |
pragma Assert (A_Id in Aspect_Integer_Literal | |
| 18402 |
Aspect_Real_Literal | Aspect_String_Literal); |
| 18403 |
Func_Name : constant Node_Id := Expression (ASN); |
| 18404 |
Overloaded : Boolean := Is_Overloaded (Func_Name); |
| 18405 |
|
| 18406 |
I : Interp_Index := 0; |
| 18407 |
It : Interp; |
| 18408 |
Param_Type : Entity_Id; |
| 18409 |
Match_Found : Boolean := False; |
| 18410 |
Match2_Found : Boolean := False; |
| 18411 |
Is_Match : Boolean; |
| 18412 |
Match : Interp; |
| 18413 |
Match2 : Entity_Id := Empty; |
| 18414 |
|
| 18415 |
function Matching |
| 18416 |
(Param_Id : Entity_Id; Param_Type : Entity_Id) return Boolean; |
| 18417 |
-- Return True if Param_Id is a non aliased in parameter whose base type |
| 18418 |
-- is Param_Type. |
| 18419 |
|
| 18420 |
-------------- |
| 18421 |
-- Matching -- |
| 18422 |
-------------- |
| 18423 |
|
| 18424 |
function Matching |
| 18425 |
(Param_Id : Entity_Id; Param_Type : Entity_Id) return Boolean is |
| 18426 |
begin |
| 18427 |
return Base_Type (Etype (Param_Id)) = Param_Type |
| 18428 |
and then Ekind (Param_Id) = E_In_Parameter |
| 18429 |
and then not Is_Aliased (Param_Id); |
| 18430 |
end Matching; |
| 18431 |
|
| 18432 |
-- Start of processing for Validate_Literal_Aspect |
| 18433 |
|
| 18434 |
begin |
| 18435 |
-- If the aspect specification was effectively inherited from the parent |
| 18436 |
-- type (so constructed anew by analysis), then no point in validating. |
| 18437 |
|
| 18438 |
if not Comes_From_Source (ASN) then |
| 18439 |
return; |
| 18440 |
end if; |
| 18441 |
|
| 18442 |
if not Is_Type (Typ) then |
| 18443 |
Error_Msg_N ("aspect can only be specified for a type", ASN); |
| 18444 |
return; |
| 18445 |
|
| 18446 |
elsif not Is_First_Subtype (Typ) then |
| 18447 |
Error_Msg_N ("aspect cannot be specified for a subtype", ASN); |
| 18448 |
return; |
| 18449 |
end if; |
| 18450 |
|
| 18451 |
if A_Id = Aspect_String_Literal then |
| 18452 |
if Is_String_Type (Typ) then |
| 18453 |
Error_Msg_N ("aspect cannot be specified for a string type", ASN); |
| 18454 |
return; |
| 18455 |
end if; |
| 18456 |
|
| 18457 |
Param_Type := Standard_Wide_Wide_String; |
| 18458 |
|
| 18459 |
else |
| 18460 |
if Is_Numeric_Type (Typ) then |
| 18461 |
Error_Msg_N ("aspect cannot be specified for a numeric type", ASN); |
| 18462 |
return; |
| 18463 |
end if; |
| 18464 |
|
| 18465 |
Param_Type := Standard_String; |
| 18466 |
end if; |
| 18467 |
|
| 18468 |
if not Overloaded and then No (Entity (Func_Name)) then |
| 18469 |
-- The aspect is specified by a subprogram name, which |
| 18470 |
-- may be an operator name given originally by a string. |
| 18471 |
|
| 18472 |
if Is_Operator_Name (Chars (Func_Name)) then |
| 18473 |
Analyze_Operator_Symbol (Func_Name); |
| 18474 |
else |
| 18475 |
Analyze (Func_Name); |
| 18476 |
end if; |
| 18477 |
|
| 18478 |
Overloaded := Is_Overloaded (Func_Name); |
| 18479 |
end if; |
| 18480 |
|
| 18481 |
if Overloaded then |
| 18482 |
Get_First_Interp (Func_Name, I => I, It => It); |
| 18483 |
else |
| 18484 |
-- only one possible interpretation |
| 18485 |
It.Nam := Entity (Func_Name); |
| 18486 |
pragma Assert (Present (It.Nam)); |
| 18487 |
end if; |
| 18488 |
|
| 18489 |
while It.Nam /= Empty loop |
| 18490 |
Is_Match := False; |
| 18491 |
|
| 18492 |
if Ekind (It.Nam) = E_Function |
| 18493 |
and then Base_Type (Etype (It.Nam)) = Base_Type (Typ) |
| 18494 |
then |
| 18495 |
declare |
| 18496 |
Params : constant List_Id := |
| 18497 |
Parameter_Specifications (Parent (It.Nam)); |
| 18498 |
Param_Spec : Node_Id; |
| 18499 |
|
| 18500 |
begin |
| 18501 |
if List_Length (Params) = 1 then |
| 18502 |
Param_Spec := First (Params); |
| 18503 |
Is_Match := |
| 18504 |
Matching (Defining_Identifier (Param_Spec), Param_Type); |
| 18505 |
|
| 18506 |
-- Look for the optional overloaded 2-param Real_Literal |
| 18507 |
|
| 18508 |
elsif List_Length (Params) = 2 |
| 18509 |
and then A_Id = Aspect_Real_Literal |
| 18510 |
then |
| 18511 |
Param_Spec := First (Params); |
| 18512 |
|
| 18513 |
if Matching (Defining_Identifier (Param_Spec), Param_Type) |
| 18514 |
then |
| 18515 |
Param_Spec := Next (Param_Spec); |
| 18516 |
|
| 18517 |
if Matching (Defining_Identifier (Param_Spec), Param_Type) |
| 18518 |
then |
| 18519 |
if No (Match2) then |
| 18520 |
Match2 := It.Nam; |
| 18521 |
Match2_Found := True; |
| 18522 |
else |
| 18523 |
-- If we find more than one possible match then |
| 18524 |
-- do not take any into account here: since the |
| 18525 |
-- 2-parameter version of Real_Literal is optional |
| 18526 |
-- we cannot generate an error here, so let |
| 18527 |
-- standard resolution fail later if we do need to |
| 18528 |
-- call this variant. |
| 18529 |
|
| 18530 |
Match2_Found := False; |
| 18531 |
end if; |
| 18532 |
end if; |
| 18533 |
end if; |
| 18534 |
end if; |
| 18535 |
end; |
| 18536 |
end if; |
| 18537 |
|
| 18538 |
if Is_Match then |
| 18539 |
if Match_Found then |
| 18540 |
Error_Msg_N ("aspect specification is ambiguous", ASN); |
| 18541 |
return; |
| 18542 |
end if; |
| 18543 |
|
| 18544 |
Match_Found := True; |
| 18545 |
Match := It; |
| 18546 |
end if; |
| 18547 |
|
| 18548 |
exit when not Overloaded; |
| 18549 |
|
| 18550 |
if not Is_Match then |
| 18551 |
Remove_Interp (I => I); |
| 18552 |
end if; |
| 18553 |
|
| 18554 |
Get_Next_Interp (I => I, It => It); |
| 18555 |
end loop; |
| 18556 |
|
| 18557 |
if not Match_Found then |
| 18558 |
Error_Msg_N |
| 18559 |
("function name in aspect specification cannot be resolved", ASN); |
| 18560 |
return; |
| 18561 |
end if; |
| 18562 |
|
| 18563 |
Set_Entity (Func_Name, Match.Nam); |
| 18564 |
Set_Etype (Func_Name, Etype (Match.Nam)); |
| 18565 |
Set_Is_Overloaded (Func_Name, False); |
| 18566 |
|
| 18567 |
-- Record the match for 2-parameter function if found |
| 18568 |
|
| 18569 |
if Match2_Found then |
| 18570 |
Set_Related_Expression (Match.Nam, Match2); |
| 18571 |
end if; |
| 18572 |
end Validate_Literal_Aspect; |
| 18573 |
|
| 18574 |
---------------------------------------- |
| 18575 |
-- Validate_Storage_Model_Type_Aspect -- |
| 18576 |
---------------------------------------- |
| 18577 |
|
| 18578 |
procedure Validate_Storage_Model_Type_Aspect |
| 18579 |
(Typ : Entity_Id; ASN : Node_Id) |
| 18580 |
is |
| 18581 |
Assoc : Node_Id; |
| 18582 |
Choice : Entity_Id; |
| 18583 |
Choice_Name : Name_Id; |
| 18584 |
Expr : Node_Id; |
| 18585 |
|
| 18586 |
Address_Type_Id : Entity_Id := Empty; |
| 18587 |
Null_Address_Id : Entity_Id := Empty; |
| 18588 |
Allocate_Id : Entity_Id := Empty; |
| 18589 |
Deallocate_Id : Entity_Id := Empty; |
| 18590 |
Copy_From_Id : Entity_Id := Empty; |
| 18591 |
Copy_To_Id : Entity_Id := Empty; |
| 18592 |
Storage_Size_Id : Entity_Id := Empty; |
| 18593 |
|
| 18594 |
procedure Check_And_Resolve_Storage_Model_Type_Argument |
| 18595 |
(Expr : Node_Id; |
| 18596 |
Typ : Entity_Id; |
| 18597 |
Argument_Id : in out Entity_Id; |
| 18598 |
Nam : Name_Id); |
| 18599 |
-- Checks that the subaspect for Nam has not already been specified for |
| 18600 |
-- Typ's Storage_Model_Type aspect (i.e., checks Argument_Id = Empty), |
| 18601 |
-- resolves Expr, and sets Argument_Id to the entity resolved for Expr. |
| 18602 |
|
| 18603 |
procedure Check_And_Resolve_Storage_Model_Type_Argument |
| 18604 |
(Expr : Node_Id; |
| 18605 |
Typ : Entity_Id; |
| 18606 |
Argument_Id : in out Entity_Id; |
| 18607 |
Nam : Name_Id) |
| 18608 |
is |
| 18609 |
Name_String : String := Get_Name_String (Nam); |
| 18610 |
|
| 18611 |
begin |
| 18612 |
To_Mixed (Name_String); |
| 18613 |
|
| 18614 |
if Present (Argument_Id) then |
| 18615 |
Error_Msg_String (1 .. Name_String'Length) := Name_String; |
| 18616 |
Error_Msg_Strlen := Name_String'Length; |
| 18617 |
|
| 18618 |
Error_Msg_N ("~ already specified", Expr); |
| 18619 |
end if; |
| 18620 |
|
| 18621 |
Resolve_Storage_Model_Type_Argument (Expr, Typ, Address_Type_Id, Nam); |
| 18622 |
Argument_Id := Entity (Expr); |
| 18623 |
end Check_And_Resolve_Storage_Model_Type_Argument; |
| 18624 |
|
| 18625 |
-- Start of processing for Validate_Storage_Model_Type_Aspect |
| 18626 |
|
| 18627 |
begin |
| 18628 |
-- The aggregate argument of Storage_Model_Type is optional, and when |
| 18629 |
-- not present the aspect defaults to the native storage model (where |
| 18630 |
-- the address type is System.Address, and other arguments default to |
| 18631 |
-- the corresponding native storage operations). |
| 18632 |
|
| 18633 |
if No (Expression (ASN)) then |
| 18634 |
return; |
| 18635 |
end if; |
| 18636 |
|
| 18637 |
-- Each expression must resolve to an entity of the right kind or proper |
| 18638 |
-- profile. |
| 18639 |
|
| 18640 |
Assoc := First (Component_Associations (Expression (ASN))); |
| 18641 |
while Present (Assoc) loop |
| 18642 |
Expr := Expression (Assoc); |
| 18643 |
Analyze (Expr); |
| 18644 |
|
| 18645 |
Choice := First (Choices (Assoc)); |
| 18646 |
|
| 18647 |
Choice_Name := Chars (Choice); |
| 18648 |
|
| 18649 |
if Nkind (Choice) /= N_Identifier or else Present (Next (Choice)) then |
| 18650 |
Error_Msg_N ("illegal name in association", Choice); |
| 18651 |
|
| 18652 |
elsif Choice_Name = Name_Address_Type then |
| 18653 |
if Assoc /= First (Component_Associations (Expression (ASN))) then |
| 18654 |
Error_Msg_N ("Address_Type must be first association", Choice); |
| 18655 |
end if; |
| 18656 |
|
| 18657 |
Check_And_Resolve_Storage_Model_Type_Argument |
| 18658 |
(Expr, Typ, Address_Type_Id, Name_Address_Type); |
| 18659 |
|
| 18660 |
else |
| 18661 |
-- It's allowed to leave out the Address_Type argument, in which |
| 18662 |
-- case the address type is defined to default to System.Address. |
| 18663 |
|
| 18664 |
if No (Address_Type_Id) then |
| 18665 |
Address_Type_Id := RTE (RE_Address); |
| 18666 |
end if; |
| 18667 |
|
| 18668 |
if Choice_Name = Name_Null_Address then |
| 18669 |
Check_And_Resolve_Storage_Model_Type_Argument |
| 18670 |
(Expr, Typ, Null_Address_Id, Name_Null_Address); |
| 18671 |
|
| 18672 |
elsif Choice_Name = Name_Allocate then |
| 18673 |
Check_And_Resolve_Storage_Model_Type_Argument |
| 18674 |
(Expr, Typ, Allocate_Id, Name_Allocate); |
| 18675 |
|
| 18676 |
elsif Choice_Name = Name_Deallocate then |
| 18677 |
Check_And_Resolve_Storage_Model_Type_Argument |
| 18678 |
(Expr, Typ, Deallocate_Id, Name_Deallocate); |
| 18679 |
|
| 18680 |
elsif Choice_Name = Name_Copy_From then |
| 18681 |
Check_And_Resolve_Storage_Model_Type_Argument |
| 18682 |
(Expr, Typ, Copy_From_Id, Name_Copy_From); |
| 18683 |
|
| 18684 |
elsif Choice_Name = Name_Copy_To then |
| 18685 |
Check_And_Resolve_Storage_Model_Type_Argument |
| 18686 |
(Expr, Typ, Copy_To_Id, Name_Copy_To); |
| 18687 |
|
| 18688 |
elsif Choice_Name = Name_Storage_Size then |
| 18689 |
Check_And_Resolve_Storage_Model_Type_Argument |
| 18690 |
(Expr, Typ, Storage_Size_Id, Name_Storage_Size); |
| 18691 |
|
| 18692 |
else |
| 18693 |
Error_Msg_N |
| 18694 |
("invalid name for Storage_Model_Type argument", Choice); |
| 18695 |
end if; |
| 18696 |
end if; |
| 18697 |
|
| 18698 |
Next (Assoc); |
| 18699 |
end loop; |
| 18700 |
|
| 18701 |
-- If Address_Type has been specified as or defaults to System.Address, |
| 18702 |
-- then other "subaspect" arguments can be specified, but are optional. |
| 18703 |
-- Otherwise, all other arguments are required and an error is flagged |
| 18704 |
-- about any that are missing. |
| 18705 |
|
| 18706 |
if Address_Type_Id = RTE (RE_Address) then |
| 18707 |
return; |
| 18708 |
|
| 18709 |
elsif No (Null_Address_Id) then |
| 18710 |
Error_Msg_N ("match for Null_Address primitive not found", ASN); |
| 18711 |
|
| 18712 |
elsif No (Allocate_Id) then |
| 18713 |
Error_Msg_N ("match for Allocate primitive not found", ASN); |
| 18714 |
|
| 18715 |
elsif No (Deallocate_Id) then |
| 18716 |
Error_Msg_N ("match for Deallocate primitive not found", ASN); |
| 18717 |
|
| 18718 |
elsif No (Copy_From_Id) then |
| 18719 |
Error_Msg_N ("match for Copy_From primitive not found", ASN); |
| 18720 |
|
| 18721 |
elsif No (Copy_To_Id) then |
| 18722 |
Error_Msg_N ("match for Copy_To primitive not found", ASN); |
| 18723 |
|
| 18724 |
elsif No (Storage_Size_Id) then |
| 18725 |
Error_Msg_N ("match for Storage_Size primitive not found", ASN); |
| 18726 |
end if; |
| 18727 |
end Validate_Storage_Model_Type_Aspect; |
| 18728 |
|
| 18729 |
----------------------------------- |
| 18730 |
-- Validate_Unchecked_Conversion -- |
| 18731 |
----------------------------------- |
| 18732 |
|
| 18733 |
procedure Validate_Unchecked_Conversion |
| 18734 |
(N : Node_Id; |
| 18735 |
Act_Unit : Entity_Id) |
| 18736 |
is |
| 18737 |
Source : Entity_Id; |
| 18738 |
Target : Entity_Id; |
| 18739 |
|
| 18740 |
procedure Warn_Nonportable (RE : RE_Id); |
| 18741 |
-- Warn if either source or target of the conversion is a predefined |
| 18742 |
-- private type, whose representation might differ between releases and |
| 18743 |
-- targets of the compiler. |
| 18744 |
|
| 18745 |
---------------------- |
| 18746 |
-- Warn_Nonportable -- |
| 18747 |
---------------------- |
| 18748 |
|
| 18749 |
procedure Warn_Nonportable (RE : RE_Id) is |
| 18750 |
begin |
| 18751 |
if Is_RTE (Source, RE) or else Is_RTE (Target, RE) then |
| 18752 |
pragma Assert (Is_Private_Type (RTE (RE))); |
| 18753 |
Error_Msg_NE |
| 18754 |
("?z?representation of & values may change between " |
| 18755 |
& "'G'N'A'T versions", N, RTE (RE)); |
| 18756 |
end if; |
| 18757 |
end Warn_Nonportable; |
| 18758 |
|
| 18759 |
-- Local variables |
| 18760 |
|
| 18761 |
Vnode : Node_Id; |
| 18762 |
|
| 18763 |
-- Start of processing for Validate_Unchecked_Conversion |
| 18764 |
|
| 18765 |
begin |
| 18766 |
-- Obtain source and target types. Note that we call Ancestor_Subtype |
| 18767 |
-- here because the processing for generic instantiation always makes |
| 18768 |
-- subtypes, and we want the original frozen actual types. |
| 18769 |
|
| 18770 |
Source := Ancestor_Subtype (Etype (First_Formal (Act_Unit))); |
| 18771 |
Target := Ancestor_Subtype (Etype (Act_Unit)); |
| 18772 |
|
| 18773 |
-- If either type is generic, the instantiation happens within a generic |
| 18774 |
-- unit, and there is nothing to check. The proper check will happen |
| 18775 |
-- when the enclosing generic is instantiated. |
| 18776 |
|
| 18777 |
if Is_Generic_Type (Source) or else Is_Generic_Type (Target) then |
| 18778 |
return; |
| 18779 |
end if; |
| 18780 |
|
| 18781 |
-- Warn if one of the operands is a private type declared in |
| 18782 |
-- Ada.Calendar or Ada.Real_Time. Do not emit a warning when compiling |
| 18783 |
-- GNAT-related sources. |
| 18784 |
|
| 18785 |
if Warn_On_Unchecked_Conversion |
| 18786 |
and then not In_Predefined_Unit (N) |
| 18787 |
then |
| 18788 |
Warn_Nonportable (RO_CA_Time); |
| 18789 |
Warn_Nonportable (RO_RT_Time); |
| 18790 |
Warn_Nonportable (RE_Time_Span); |
| 18791 |
end if; |
| 18792 |
|
| 18793 |
-- If we are dealing with private types, then do the check on their |
| 18794 |
-- fully declared counterparts if the full declarations have been |
| 18795 |
-- encountered (they don't have to be visible, but they must exist). |
| 18796 |
|
| 18797 |
if Is_Private_Type (Source) |
| 18798 |
and then Present (Underlying_Type (Source)) |
| 18799 |
then |
| 18800 |
Source := Underlying_Type (Source); |
| 18801 |
end if; |
| 18802 |
|
| 18803 |
if Is_Private_Type (Target) |
| 18804 |
and then Present (Underlying_Type (Target)) |
| 18805 |
then |
| 18806 |
Target := Underlying_Type (Target); |
| 18807 |
end if; |
| 18808 |
|
| 18809 |
-- Source may be unconstrained array, but not target, except in relaxed |
| 18810 |
-- semantics mode. |
| 18811 |
|
| 18812 |
if Is_Array_Type (Target) |
| 18813 |
and then not Is_Constrained (Target) |
| 18814 |
and then not Relaxed_RM_Semantics |
| 18815 |
then |
| 18816 |
Error_Msg_N |
| 18817 |
("unchecked conversion to unconstrained array not allowed", N); |
| 18818 |
return; |
| 18819 |
end if; |
| 18820 |
|
| 18821 |
-- Warn if conversion between two different convention pointers |
| 18822 |
|
| 18823 |
if Is_Access_Type (Target) |
| 18824 |
and then Is_Access_Type (Source) |
| 18825 |
and then Convention (Target) /= Convention (Source) |
| 18826 |
and then Warn_On_Unchecked_Conversion |
| 18827 |
then |
| 18828 |
-- Give warnings for subprogram pointers only on most targets |
| 18829 |
|
| 18830 |
if Is_Access_Subprogram_Type (Target) |
| 18831 |
or else Is_Access_Subprogram_Type (Source) |
| 18832 |
then |
| 18833 |
Error_Msg_N |
| 18834 |
("?z?conversion between pointers with different conventions!", |
| 18835 |
N); |
| 18836 |
end if; |
| 18837 |
end if; |
| 18838 |
|
| 18839 |
-- Make entry in unchecked conversion table for later processing by |
| 18840 |
-- Validate_Unchecked_Conversions, which will check sizes and alignments |
| 18841 |
-- (using values set by the back end where possible). This is only done |
| 18842 |
-- if the appropriate warning is active. |
| 18843 |
|
| 18844 |
if Warn_On_Unchecked_Conversion then |
| 18845 |
Unchecked_Conversions.Append |
| 18846 |
(New_Val => UC_Entry'(Eloc => Sloc (N), |
| 18847 |
Source => Source, |
| 18848 |
Target => Target, |
| 18849 |
Act_Unit => Act_Unit)); |
| 18850 |
|
| 18851 |
-- If both sizes are known statically now, then back-end annotation |
| 18852 |
-- is not required to do a proper check but if either size is not |
| 18853 |
-- known statically, then we need the annotation. |
| 18854 |
|
| 18855 |
if Known_Static_RM_Size (Source) |
| 18856 |
and then |
| 18857 |
Known_Static_RM_Size (Target) |
| 18858 |
then |
| 18859 |
null; |
| 18860 |
else |
| 18861 |
Back_Annotate_Rep_Info := True; |
| 18862 |
end if; |
| 18863 |
end if; |
| 18864 |
|
| 18865 |
-- If unchecked conversion to access type, and access type is declared |
| 18866 |
-- in the same unit as the unchecked conversion, then set the flag |
| 18867 |
-- No_Strict_Aliasing (no strict aliasing is implicit here) |
| 18868 |
|
| 18869 |
if Is_Access_Type (Target) |
| 18870 |
and then In_Same_Source_Unit (Target, N) |
| 18871 |
then |
| 18872 |
Set_No_Strict_Aliasing (Implementation_Base_Type (Target)); |
| 18873 |
end if; |
| 18874 |
|
| 18875 |
-- For code generators that do not support nested subprograms, if the |
| 18876 |
-- unchecked conversion is between Address and an access subprogram |
| 18877 |
-- type, show that we shouldn't use an internal representation for the |
| 18878 |
-- access subprogram type. |
| 18879 |
|
| 18880 |
if Unnest_Subprogram_Mode then |
| 18881 |
if Is_Access_Subprogram_Type (Target) |
| 18882 |
and then Is_Descendant_Of_Address (Source) |
| 18883 |
and then In_Same_Source_Unit (Target, N) |
| 18884 |
then |
| 18885 |
Set_Can_Use_Internal_Rep (Base_Type (Target), False); |
| 18886 |
elsif Is_Access_Subprogram_Type (Source) |
| 18887 |
and then Is_Descendant_Of_Address (Target) |
| 18888 |
and then In_Same_Source_Unit (Source, N) |
| 18889 |
then |
| 18890 |
Set_Can_Use_Internal_Rep (Base_Type (Source), False); |
| 18891 |
end if; |
| 18892 |
end if; |
| 18893 |
|
| 18894 |
-- Generate N_Validate_Unchecked_Conversion node for back end in case |
| 18895 |
-- the back end needs to perform special validation checks. |
| 18896 |
|
| 18897 |
-- Shouldn't this be in Exp_Ch13, since the check only gets done if we |
| 18898 |
-- have full expansion and the back end is called ??? |
| 18899 |
|
| 18900 |
Vnode := |
| 18901 |
Make_Validate_Unchecked_Conversion (Sloc (N)); |
| 18902 |
Set_Source_Type (Vnode, Source); |
| 18903 |
Set_Target_Type (Vnode, Target); |
| 18904 |
|
| 18905 |
-- If the unchecked conversion node is in a list, just insert before it. |
| 18906 |
-- If not we have some strange case, not worth bothering about. |
| 18907 |
|
| 18908 |
if Is_List_Member (N) then |
| 18909 |
Insert_After (N, Vnode); |
| 18910 |
end if; |
| 18911 |
end Validate_Unchecked_Conversion; |
| 18912 |
|
| 18913 |
------------------------------------ |
| 18914 |
-- Validate_Unchecked_Conversions -- |
| 18915 |
------------------------------------ |
| 18916 |
|
| 18917 |
procedure Validate_Unchecked_Conversions is |
| 18918 |
begin |
| 18919 |
for N in Unchecked_Conversions.First .. Unchecked_Conversions.Last loop |
| 18920 |
declare |
| 18921 |
T : UC_Entry renames Unchecked_Conversions.Table (N); |
| 18922 |
|
| 18923 |
Act_Unit : constant Entity_Id := T.Act_Unit; |
| 18924 |
Eloc : constant Source_Ptr := T.Eloc; |
| 18925 |
Source : constant Entity_Id := T.Source; |
| 18926 |
Target : constant Entity_Id := T.Target; |
| 18927 |
|
| 18928 |
Source_Siz : Uint; |
| 18929 |
Target_Siz : Uint; |
| 18930 |
|
| 18931 |
begin |
| 18932 |
-- Skip if function marked as warnings off |
| 18933 |
|
| 18934 |
if Has_Warnings_Off (Act_Unit) |
| 18935 |
or else Serious_Errors_Detected > 0 |
| 18936 |
then |
| 18937 |
goto Continue; |
| 18938 |
end if; |
| 18939 |
|
| 18940 |
-- Don't do the check if warnings off for either type, note the |
| 18941 |
-- deliberate use of OR here instead of OR ELSE to get the flag |
| 18942 |
-- Warnings_Off_Used set for both types if appropriate. |
| 18943 |
|
| 18944 |
if Has_Warnings_Off (Source) or Has_Warnings_Off (Target) then |
| 18945 |
goto Continue; |
| 18946 |
end if; |
| 18947 |
|
| 18948 |
if Known_Static_RM_Size (Source) |
| 18949 |
and then Known_Static_RM_Size (Target) |
| 18950 |
then |
| 18951 |
-- This validation check, which warns if we have unequal sizes |
| 18952 |
-- for unchecked conversion, and thus implementation dependent |
| 18953 |
-- semantics, is one of the few occasions on which we use the |
| 18954 |
-- official RM size instead of Esize. See description in Einfo |
| 18955 |
-- "Handling of Type'Size Values" for details. |
| 18956 |
|
| 18957 |
Source_Siz := RM_Size (Source); |
| 18958 |
Target_Siz := RM_Size (Target); |
| 18959 |
|
| 18960 |
if Source_Siz /= Target_Siz then |
| 18961 |
Error_Msg |
| 18962 |
("?z?types for unchecked conversion have different sizes!", |
| 18963 |
Eloc, Act_Unit); |
| 18964 |
|
| 18965 |
if All_Errors_Mode then |
| 18966 |
Error_Msg_Name_1 := Chars (Source); |
| 18967 |
Error_Msg_Uint_1 := Source_Siz; |
| 18968 |
Error_Msg_Name_2 := Chars (Target); |
| 18969 |
Error_Msg_Uint_2 := Target_Siz; |
| 18970 |
Error_Msg |
| 18971 |
("\size of % is ^, size of % is ^?z?", Eloc, Act_Unit); |
| 18972 |
|
| 18973 |
Error_Msg_Uint_1 := UI_Abs (Source_Siz - Target_Siz); |
| 18974 |
|
| 18975 |
if Is_Discrete_Type (Source) |
| 18976 |
and then |
| 18977 |
Is_Discrete_Type (Target) |
| 18978 |
then |
| 18979 |
if Source_Siz > Target_Siz then |
| 18980 |
Error_Msg |
| 18981 |
("\?z?^ high order bits of source will " |
| 18982 |
& "be ignored!", Eloc, Act_Unit); |
| 18983 |
|
| 18984 |
elsif Is_Unsigned_Type (Source) then |
| 18985 |
Error_Msg |
| 18986 |
("\?z?source will be extended with ^ high order " |
| 18987 |
& "zero bits!", Eloc, Act_Unit); |
| 18988 |
|
| 18989 |
else |
| 18990 |
Error_Msg |
| 18991 |
("\?z?source will be extended with ^ high order " |
| 18992 |
& "sign bits!", Eloc, Act_Unit); |
| 18993 |
end if; |
| 18994 |
|
| 18995 |
elsif Source_Siz < Target_Siz then |
| 18996 |
if Is_Discrete_Type (Target) then |
| 18997 |
if Bytes_Big_Endian then |
| 18998 |
Error_Msg |
| 18999 |
("\?z?target value will include ^ undefined " |
| 19000 |
& "low order bits!", Eloc, Act_Unit); |
| 19001 |
else |
| 19002 |
Error_Msg |
| 19003 |
("\?z?target value will include ^ undefined " |
| 19004 |
& "high order bits!", Eloc, Act_Unit); |
| 19005 |
end if; |
| 19006 |
|
| 19007 |
else |
| 19008 |
Error_Msg |
| 19009 |
("\?z?^ trailing bits of target value will be " |
| 19010 |
& "undefined!", Eloc, Act_Unit); |
| 19011 |
end if; |
| 19012 |
|
| 19013 |
else pragma Assert (Source_Siz > Target_Siz); |
| 19014 |
if Is_Discrete_Type (Source) then |
| 19015 |
if Bytes_Big_Endian then |
| 19016 |
Error_Msg |
| 19017 |
("\?z?^ low order bits of source will be " |
| 19018 |
& "ignored!", Eloc, Act_Unit); |
| 19019 |
else |
| 19020 |
Error_Msg |
| 19021 |
("\?z?^ high order bits of source will be " |
| 19022 |
& "ignored!", Eloc, Act_Unit); |
| 19023 |
end if; |
| 19024 |
|
| 19025 |
else |
| 19026 |
Error_Msg |
| 19027 |
("\?z?^ trailing bits of source will be " |
| 19028 |
& "ignored!", Eloc, Act_Unit); |
| 19029 |
end if; |
| 19030 |
end if; |
| 19031 |
end if; |
| 19032 |
end if; |
| 19033 |
end if; |
| 19034 |
|
| 19035 |
-- If both types are access types, we need to check the alignment. |
| 19036 |
-- If the alignment of both is specified, we can do it here. |
| 19037 |
|
| 19038 |
if Serious_Errors_Detected = 0 |
| 19039 |
and then Is_Access_Type (Source) |
| 19040 |
and then Is_Access_Type (Target) |
| 19041 |
and then Target_Strict_Alignment |
| 19042 |
and then Present (Designated_Type (Source)) |
| 19043 |
and then Present (Designated_Type (Target)) |
| 19044 |
then |
| 19045 |
declare |
| 19046 |
D_Source : constant Entity_Id := Designated_Type (Source); |
| 19047 |
D_Target : constant Entity_Id := Designated_Type (Target); |
| 19048 |
|
| 19049 |
begin |
| 19050 |
if Known_Alignment (D_Source) |
| 19051 |
and then |
| 19052 |
Known_Alignment (D_Target) |
| 19053 |
then |
| 19054 |
declare |
| 19055 |
Source_Align : constant Uint := Alignment (D_Source); |
| 19056 |
Target_Align : constant Uint := Alignment (D_Target); |
| 19057 |
|
| 19058 |
begin |
| 19059 |
if Source_Align < Target_Align |
| 19060 |
and then not Is_Tagged_Type (D_Source) |
| 19061 |
|
| 19062 |
-- Suppress warning if warnings suppressed on either |
| 19063 |
-- type or either designated type. Note the use of |
| 19064 |
-- OR here instead of OR ELSE. That is intentional, |
| 19065 |
-- we would like to set flag Warnings_Off_Used in |
| 19066 |
-- all types for which warnings are suppressed. |
| 19067 |
|
| 19068 |
and then not (Has_Warnings_Off (D_Source) |
| 19069 |
or |
| 19070 |
Has_Warnings_Off (D_Target) |
| 19071 |
or |
| 19072 |
Has_Warnings_Off (Source) |
| 19073 |
or |
| 19074 |
Has_Warnings_Off (Target)) |
| 19075 |
then |
| 19076 |
Error_Msg_Uint_1 := Target_Align; |
| 19077 |
Error_Msg_Uint_2 := Source_Align; |
| 19078 |
Error_Msg_Node_1 := D_Target; |
| 19079 |
Error_Msg_Node_2 := D_Source; |
| 19080 |
Error_Msg |
| 19081 |
("?z?alignment of & (^) is stricter than " |
| 19082 |
& "alignment of & (^)!", Eloc, Act_Unit); |
| 19083 |
Error_Msg |
| 19084 |
("\?z?resulting access value may have invalid " |
| 19085 |
& "alignment!", Eloc, Act_Unit); |
| 19086 |
end if; |
| 19087 |
end; |
| 19088 |
end if; |
| 19089 |
end; |
| 19090 |
end if; |
| 19091 |
end; |
| 19092 |
|
| 19093 |
<<Continue>> |
| 19094 |
null; |
| 19095 |
end loop; |
| 19096 |
end Validate_Unchecked_Conversions; |
| 19097 |
|
| 19098 |
begin |
| 19099 |
User_Aspect_Support.Analyze_User_Aspect_Aspect_Specification_Hook := |
| 19100 |
Analyze_User_Aspect_Aspect_Specification'Access; |
| 19101 |
end Sem_Ch13; |