1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2016, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 with Aspects
; use Aspects
;
27 with Atree
; use Atree
;
28 with Checks
; use Checks
;
29 with Debug
; use Debug
;
30 with Einfo
; use Einfo
;
31 with Elists
; use Elists
;
32 with Errout
; use Errout
;
33 with Expander
; use Expander
;
34 with Exp_Disp
; use Exp_Disp
;
35 with Exp_Tss
; use Exp_Tss
;
36 with Exp_Util
; use Exp_Util
;
37 with Freeze
; use Freeze
;
38 with Ghost
; use Ghost
;
40 with Lib
.Xref
; use Lib
.Xref
;
41 with Namet
; use Namet
;
42 with Nlists
; use Nlists
;
43 with Nmake
; use Nmake
;
45 with Restrict
; use Restrict
;
46 with Rident
; use Rident
;
47 with Rtsfind
; use Rtsfind
;
49 with Sem_Aux
; use Sem_Aux
;
50 with Sem_Case
; use Sem_Case
;
51 with Sem_Ch3
; use Sem_Ch3
;
52 with Sem_Ch6
; use Sem_Ch6
;
53 with Sem_Ch8
; use Sem_Ch8
;
54 with Sem_Dim
; use Sem_Dim
;
55 with Sem_Disp
; use Sem_Disp
;
56 with Sem_Eval
; use Sem_Eval
;
57 with Sem_Prag
; use Sem_Prag
;
58 with Sem_Res
; use Sem_Res
;
59 with Sem_Type
; use Sem_Type
;
60 with Sem_Util
; use Sem_Util
;
61 with Sem_Warn
; use Sem_Warn
;
62 with Sinput
; use Sinput
;
63 with Snames
; use Snames
;
64 with Stand
; use Stand
;
65 with Sinfo
; use Sinfo
;
66 with Targparm
; use Targparm
;
67 with Ttypes
; use Ttypes
;
68 with Tbuild
; use Tbuild
;
69 with Urealp
; use Urealp
;
70 with Warnsw
; use Warnsw
;
72 with GNAT
.Heap_Sort_G
;
74 package body Sem_Ch13
is
76 SSU
: constant Pos
:= System_Storage_Unit
;
77 -- Convenient short hand for commonly used constant
79 -----------------------
80 -- Local Subprograms --
81 -----------------------
83 procedure Alignment_Check_For_Size_Change
(Typ
: Entity_Id
; Size
: Uint
);
84 -- This routine is called after setting one of the sizes of type entity
85 -- Typ to Size. The purpose is to deal with the situation of a derived
86 -- type whose inherited alignment is no longer appropriate for the new
87 -- size value. In this case, we reset the Alignment to unknown.
89 procedure Build_Discrete_Static_Predicate
93 -- Given a predicated type Typ, where Typ is a discrete static subtype,
94 -- whose predicate expression is Expr, tests if Expr is a static predicate,
95 -- and if so, builds the predicate range list. Nam is the name of the one
96 -- argument to the predicate function. Occurrences of the type name in the
97 -- predicate expression have been replaced by identifier references to this
98 -- name, which is unique, so any identifier with Chars matching Nam must be
99 -- a reference to the type. If the predicate is non-static, this procedure
100 -- returns doing nothing. If the predicate is static, then the predicate
101 -- list is stored in Static_Discrete_Predicate (Typ), and the Expr is
102 -- rewritten as a canonicalized membership operation.
104 function Build_Export_Import_Pragma
106 Id
: Entity_Id
) return Node_Id
;
107 -- Create the corresponding pragma for aspect Export or Import denoted by
108 -- Asp. Id is the related entity subject to the aspect. Return Empty when
109 -- the expression of aspect Asp evaluates to False or is erroneous.
111 function Build_Predicate_Function_Declaration
112 (Typ
: Entity_Id
) return Node_Id
;
113 -- Build the declaration for a predicate function. The declaration is built
114 -- at the end of the declarative part containing the type definition, which
115 -- may be before the freeze point of the type. The predicate expression is
116 -- pre-analyzed at this point, to catch visibility errors.
118 procedure Build_Predicate_Functions
(Typ
: Entity_Id
; N
: Node_Id
);
119 -- If Typ has predicates (indicated by Has_Predicates being set for Typ),
120 -- then either there are pragma Predicate entries on the rep chain for the
121 -- type (note that Predicate aspects are converted to pragma Predicate), or
122 -- there are inherited aspects from a parent type, or ancestor subtypes.
123 -- This procedure builds body for the Predicate function that tests these
124 -- predicates. N is the freeze node for the type. The spec of the function
125 -- is inserted before the freeze node, and the body of the function is
126 -- inserted after the freeze node. If the predicate expression has a least
127 -- one Raise_Expression, then this procedure also builds the M version of
128 -- the predicate function for use in membership tests.
130 procedure Check_Pool_Size_Clash
(Ent
: Entity_Id
; SP
, SS
: Node_Id
);
131 -- Called if both Storage_Pool and Storage_Size attribute definition
132 -- clauses (SP and SS) are present for entity Ent. Issue error message.
134 procedure Freeze_Entity_Checks
(N
: Node_Id
);
135 -- Called from Analyze_Freeze_Entity and Analyze_Generic_Freeze Entity
136 -- to generate appropriate semantic checks that are delayed until this
137 -- point (they had to be delayed this long for cases of delayed aspects,
138 -- e.g. analysis of statically predicated subtypes in choices, for which
139 -- we have to be sure the subtypes in question are frozen before checking).
141 function Get_Alignment_Value
(Expr
: Node_Id
) return Uint
;
142 -- Given the expression for an alignment value, returns the corresponding
143 -- Uint value. If the value is inappropriate, then error messages are
144 -- posted as required, and a value of No_Uint is returned.
146 procedure Get_Interfacing_Aspects
147 (Iface_Asp
: Node_Id
;
148 Conv_Asp
: out Node_Id
;
149 EN_Asp
: out Node_Id
;
150 Expo_Asp
: out Node_Id
;
151 Imp_Asp
: out Node_Id
;
152 LN_Asp
: out Node_Id
;
153 Do_Checks
: Boolean := False);
154 -- Given a single interfacing aspect Iface_Asp, retrieve other interfacing
155 -- aspects that apply to the same related entity. The aspects considered by
156 -- this routine are as follows:
158 -- Conv_Asp - aspect Convention
159 -- EN_Asp - aspect External_Name
160 -- Expo_Asp - aspect Export
161 -- Imp_Asp - aspect Import
162 -- LN_Asp - aspect Link_Name
164 -- When flag Do_Checks is set, this routine will flag duplicate uses of
167 function Is_Operational_Item
(N
: Node_Id
) return Boolean;
168 -- A specification for a stream attribute is allowed before the full type
169 -- is declared, as explained in AI-00137 and the corrigendum. Attributes
170 -- that do not specify a representation characteristic are operational
173 function Is_Predicate_Static
175 Nam
: Name_Id
) return Boolean;
176 -- Given predicate expression Expr, tests if Expr is predicate-static in
177 -- the sense of the rules in (RM 3.2.4 (15-24)). Occurrences of the type
178 -- name in the predicate expression have been replaced by references to
179 -- an identifier whose Chars field is Nam. This name is unique, so any
180 -- identifier with Chars matching Nam must be a reference to the type.
181 -- Returns True if the expression is predicate-static and False otherwise,
182 -- but is not in the business of setting flags or issuing error messages.
184 -- Only scalar types can have static predicates, so False is always
185 -- returned for non-scalar types.
187 -- Note: the RM seems to suggest that string types can also have static
188 -- predicates. But that really makes lttle sense as very few useful
189 -- predicates can be constructed for strings. Remember that:
193 -- is not a static expression. So even though the clearly faulty RM wording
194 -- allows the following:
196 -- subtype S is String with Static_Predicate => S < "DEF"
198 -- We can't allow this, otherwise we have predicate-static applying to a
199 -- larger class than static expressions, which was never intended.
201 procedure New_Stream_Subprogram
205 Nam
: TSS_Name_Type
);
206 -- Create a subprogram renaming of a given stream attribute to the
207 -- designated subprogram and then in the tagged case, provide this as a
208 -- primitive operation, or in the untagged case make an appropriate TSS
209 -- entry. This is more properly an expansion activity than just semantics,
210 -- but the presence of user-defined stream functions for limited types
211 -- is a legality check, which is why this takes place here rather than in
212 -- exp_ch13, where it was previously. Nam indicates the name of the TSS
213 -- function to be generated.
215 -- To avoid elaboration anomalies with freeze nodes, for untagged types
216 -- we generate both a subprogram declaration and a subprogram renaming
217 -- declaration, so that the attribute specification is handled as a
218 -- renaming_as_body. For tagged types, the specification is one of the
221 procedure Resolve_Iterable_Operation
226 -- If the name of a primitive operation for an Iterable aspect is
227 -- overloaded, resolve according to required signature.
233 Biased
: Boolean := True);
234 -- If Biased is True, sets Has_Biased_Representation flag for E, and
235 -- outputs a warning message at node N if Warn_On_Biased_Representation is
236 -- is True. This warning inserts the string Msg to describe the construct
239 ---------------------------------------------------
240 -- Table for Validate_Compile_Time_Warning_Error --
241 ---------------------------------------------------
243 -- The following table collects pragmas Compile_Time_Error and Compile_
244 -- Time_Warning for validation. Entries are made by calls to subprogram
245 -- Validate_Compile_Time_Warning_Error, and the call to the procedure
246 -- Validate_Compile_Time_Warning_Errors does the actual error checking
247 -- and posting of warning and error messages. The reason for this delayed
248 -- processing is to take advantage of back-annotations of attributes size
249 -- and alignment values performed by the back end.
251 -- Note: the reason we store a Source_Ptr value instead of a Node_Id is
252 -- that by the time Validate_Unchecked_Conversions is called, Sprint will
253 -- already have modified all Sloc values if the -gnatD option is set.
255 type CTWE_Entry
is record
257 -- Source location used in warnings and error messages
260 -- Pragma Compile_Time_Error or Compile_Time_Warning
263 -- The scope which encloses the pragma
266 package Compile_Time_Warnings_Errors
is new Table
.Table
(
267 Table_Component_Type
=> CTWE_Entry
,
268 Table_Index_Type
=> Int
,
269 Table_Low_Bound
=> 1,
271 Table_Increment
=> 200,
272 Table_Name
=> "Compile_Time_Warnings_Errors");
274 ----------------------------------------------
275 -- Table for Validate_Unchecked_Conversions --
276 ----------------------------------------------
278 -- The following table collects unchecked conversions for validation.
279 -- Entries are made by Validate_Unchecked_Conversion and then the call
280 -- to Validate_Unchecked_Conversions does the actual error checking and
281 -- posting of warnings. The reason for this delayed processing is to take
282 -- advantage of back-annotations of size and alignment values performed by
285 -- Note: the reason we store a Source_Ptr value instead of a Node_Id is
286 -- that by the time Validate_Unchecked_Conversions is called, Sprint will
287 -- already have modified all Sloc values if the -gnatD option is set.
289 type UC_Entry
is record
290 Eloc
: Source_Ptr
; -- node used for posting warnings
291 Source
: Entity_Id
; -- source type for unchecked conversion
292 Target
: Entity_Id
; -- target type for unchecked conversion
293 Act_Unit
: Entity_Id
; -- actual function instantiated
296 package Unchecked_Conversions
is new Table
.Table
(
297 Table_Component_Type
=> UC_Entry
,
298 Table_Index_Type
=> Int
,
299 Table_Low_Bound
=> 1,
301 Table_Increment
=> 200,
302 Table_Name
=> "Unchecked_Conversions");
304 ----------------------------------------
305 -- Table for Validate_Address_Clauses --
306 ----------------------------------------
308 -- If an address clause has the form
310 -- for X'Address use Expr
312 -- where Expr has a value known at compile time or is of the form Y'Address
313 -- or recursively is a reference to a constant initialized with either of
314 -- these forms, and the value of Expr is not a multiple of X's alignment,
315 -- or if Y has a smaller alignment than X, then that merits a warning about
316 -- possible bad alignment. The following table collects address clauses of
317 -- this kind. We put these in a table so that they can be checked after the
318 -- back end has completed annotation of the alignments of objects, since we
319 -- can catch more cases that way.
321 type Address_Clause_Check_Record
is record
323 -- The address clause
326 -- The entity of the object subject to the address clause
329 -- The value of the address in the first case
332 -- The entity of the object being overlaid in the second case
335 -- Whether the address is offset within Y in the second case
338 package Address_Clause_Checks
is new Table
.Table
(
339 Table_Component_Type
=> Address_Clause_Check_Record
,
340 Table_Index_Type
=> Int
,
341 Table_Low_Bound
=> 1,
343 Table_Increment
=> 200,
344 Table_Name
=> "Address_Clause_Checks");
346 -----------------------------------------
347 -- Adjust_Record_For_Reverse_Bit_Order --
348 -----------------------------------------
350 procedure Adjust_Record_For_Reverse_Bit_Order
(R
: Entity_Id
) is
355 -- Processing depends on version of Ada
357 -- For Ada 95, we just renumber bits within a storage unit. We do the
358 -- same for Ada 83 mode, since we recognize the Bit_Order attribute in
359 -- Ada 83, and are free to add this extension.
361 if Ada_Version
< Ada_2005
then
362 Comp
:= First_Component_Or_Discriminant
(R
);
363 while Present
(Comp
) loop
364 CC
:= Component_Clause
(Comp
);
366 -- If component clause is present, then deal with the non-default
367 -- bit order case for Ada 95 mode.
369 -- We only do this processing for the base type, and in fact that
370 -- is important, since otherwise if there are record subtypes, we
371 -- could reverse the bits once for each subtype, which is wrong.
373 if Present
(CC
) and then Ekind
(R
) = E_Record_Type
then
375 CFB
: constant Uint
:= Component_Bit_Offset
(Comp
);
376 CSZ
: constant Uint
:= Esize
(Comp
);
377 CLC
: constant Node_Id
:= Component_Clause
(Comp
);
378 Pos
: constant Node_Id
:= Position
(CLC
);
379 FB
: constant Node_Id
:= First_Bit
(CLC
);
381 Storage_Unit_Offset
: constant Uint
:=
382 CFB
/ System_Storage_Unit
;
384 Start_Bit
: constant Uint
:=
385 CFB
mod System_Storage_Unit
;
388 -- Cases where field goes over storage unit boundary
390 if Start_Bit
+ CSZ
> System_Storage_Unit
then
392 -- Allow multi-byte field but generate warning
394 if Start_Bit
mod System_Storage_Unit
= 0
395 and then CSZ
mod System_Storage_Unit
= 0
398 ("info: multi-byte field specified with "
399 & "non-standard Bit_Order?V?", CLC
);
401 if Bytes_Big_Endian
then
403 ("\bytes are not reversed "
404 & "(component is big-endian)?V?", CLC
);
407 ("\bytes are not reversed "
408 & "(component is little-endian)?V?", CLC
);
411 -- Do not allow non-contiguous field
415 ("attempt to specify non-contiguous field "
416 & "not permitted", CLC
);
418 ("\caused by non-standard Bit_Order "
421 ("\consider possibility of using "
422 & "Ada 2005 mode here", CLC
);
425 -- Case where field fits in one storage unit
428 -- Give warning if suspicious component clause
430 if Intval
(FB
) >= System_Storage_Unit
431 and then Warn_On_Reverse_Bit_Order
434 ("info: Bit_Order clause does not affect " &
435 "byte ordering?V?", Pos
);
437 Intval
(Pos
) + Intval
(FB
) /
440 ("info: position normalized to ^ before bit " &
441 "order interpreted?V?", Pos
);
444 -- Here is where we fix up the Component_Bit_Offset value
445 -- to account for the reverse bit order. Some examples of
446 -- what needs to be done are:
448 -- First_Bit .. Last_Bit Component_Bit_Offset
460 -- The rule is that the first bit is is obtained by
461 -- subtracting the old ending bit from storage_unit - 1.
463 Set_Component_Bit_Offset
465 (Storage_Unit_Offset
* System_Storage_Unit
) +
466 (System_Storage_Unit
- 1) -
467 (Start_Bit
+ CSZ
- 1));
469 Set_Normalized_First_Bit
471 Component_Bit_Offset
(Comp
) mod
472 System_Storage_Unit
);
477 Next_Component_Or_Discriminant
(Comp
);
480 -- For Ada 2005, we do machine scalar processing, as fully described In
481 -- AI-133. This involves gathering all components which start at the
482 -- same byte offset and processing them together. Same approach is still
483 -- valid in later versions including Ada 2012.
487 Max_Machine_Scalar_Size
: constant Uint
:=
489 (Standard_Long_Long_Integer_Size
);
490 -- We use this as the maximum machine scalar size
493 SSU
: constant Uint
:= UI_From_Int
(System_Storage_Unit
);
496 -- This first loop through components does two things. First it
497 -- deals with the case of components with component clauses whose
498 -- length is greater than the maximum machine scalar size (either
499 -- accepting them or rejecting as needed). Second, it counts the
500 -- number of components with component clauses whose length does
501 -- not exceed this maximum for later processing.
504 Comp
:= First_Component_Or_Discriminant
(R
);
505 while Present
(Comp
) loop
506 CC
:= Component_Clause
(Comp
);
510 Fbit
: constant Uint
:= Static_Integer
(First_Bit
(CC
));
511 Lbit
: constant Uint
:= Static_Integer
(Last_Bit
(CC
));
514 -- Case of component with last bit >= max machine scalar
516 if Lbit
>= Max_Machine_Scalar_Size
then
518 -- This is allowed only if first bit is zero, and
519 -- last bit + 1 is a multiple of storage unit size.
521 if Fbit
= 0 and then (Lbit
+ 1) mod SSU
= 0 then
523 -- This is the case to give a warning if enabled
525 if Warn_On_Reverse_Bit_Order
then
527 ("info: multi-byte field specified with "
528 & "non-standard Bit_Order?V?", CC
);
530 if Bytes_Big_Endian
then
532 ("\bytes are not reversed "
533 & "(component is big-endian)?V?", CC
);
536 ("\bytes are not reversed "
537 & "(component is little-endian)?V?", CC
);
541 -- Give error message for RM 13.5.1(10) violation
545 ("machine scalar rules not followed for&",
546 First_Bit
(CC
), Comp
);
548 Error_Msg_Uint_1
:= Lbit
+ 1;
549 Error_Msg_Uint_2
:= Max_Machine_Scalar_Size
;
551 ("\last bit + 1 (^) exceeds maximum machine "
555 if (Lbit
+ 1) mod SSU
/= 0 then
556 Error_Msg_Uint_1
:= SSU
;
558 ("\and is not a multiple of Storage_Unit (^) "
563 Error_Msg_Uint_1
:= Fbit
;
565 ("\and first bit (^) is non-zero "
571 -- OK case of machine scalar related component clause,
572 -- For now, just count them.
575 Num_CC
:= Num_CC
+ 1;
580 Next_Component_Or_Discriminant
(Comp
);
583 -- We need to sort the component clauses on the basis of the
584 -- Position values in the clause, so we can group clauses with
585 -- the same Position together to determine the relevant machine
589 Comps
: array (0 .. Num_CC
) of Entity_Id
;
590 -- Array to collect component and discriminant entities. The
591 -- data starts at index 1, the 0'th entry is for the sort
594 function CP_Lt
(Op1
, Op2
: Natural) return Boolean;
595 -- Compare routine for Sort
597 procedure CP_Move
(From
: Natural; To
: Natural);
598 -- Move routine for Sort
600 package Sorting
is new GNAT
.Heap_Sort_G
(CP_Move
, CP_Lt
);
604 -- Start and stop positions in the component list of the set of
605 -- components with the same starting position (that constitute
606 -- components in a single machine scalar).
609 -- Maximum last bit value of any component in this set
612 -- Corresponding machine scalar size
618 function CP_Lt
(Op1
, Op2
: Natural) return Boolean is
620 return Position
(Component_Clause
(Comps
(Op1
))) <
621 Position
(Component_Clause
(Comps
(Op2
)));
628 procedure CP_Move
(From
: Natural; To
: Natural) is
630 Comps
(To
) := Comps
(From
);
633 -- Start of processing for Sort_CC
636 -- Collect the machine scalar relevant component clauses
639 Comp
:= First_Component_Or_Discriminant
(R
);
640 while Present
(Comp
) loop
642 CC
: constant Node_Id
:= Component_Clause
(Comp
);
645 -- Collect only component clauses whose last bit is less
646 -- than machine scalar size. Any component clause whose
647 -- last bit exceeds this value does not take part in
648 -- machine scalar layout considerations. The test for
649 -- Error_Posted makes sure we exclude component clauses
650 -- for which we already posted an error.
653 and then not Error_Posted
(Last_Bit
(CC
))
654 and then Static_Integer
(Last_Bit
(CC
)) <
655 Max_Machine_Scalar_Size
657 Num_CC
:= Num_CC
+ 1;
658 Comps
(Num_CC
) := Comp
;
662 Next_Component_Or_Discriminant
(Comp
);
665 -- Sort by ascending position number
667 Sorting
.Sort
(Num_CC
);
669 -- We now have all the components whose size does not exceed
670 -- the max machine scalar value, sorted by starting position.
671 -- In this loop we gather groups of clauses starting at the
672 -- same position, to process them in accordance with AI-133.
675 while Stop
< Num_CC
loop
680 (Last_Bit
(Component_Clause
(Comps
(Start
))));
681 while Stop
< Num_CC
loop
683 (Position
(Component_Clause
(Comps
(Stop
+ 1)))) =
685 (Position
(Component_Clause
(Comps
(Stop
))))
693 (Component_Clause
(Comps
(Stop
)))));
699 -- Now we have a group of component clauses from Start to
700 -- Stop whose positions are identical, and MaxL is the
701 -- maximum last bit value of any of these components.
703 -- We need to determine the corresponding machine scalar
704 -- size. This loop assumes that machine scalar sizes are
705 -- even, and that each possible machine scalar has twice
706 -- as many bits as the next smaller one.
708 MSS
:= Max_Machine_Scalar_Size
;
710 and then (MSS
/ 2) >= SSU
711 and then (MSS
/ 2) > MaxL
716 -- Here is where we fix up the Component_Bit_Offset value
717 -- to account for the reverse bit order. Some examples of
718 -- what needs to be done for the case of a machine scalar
721 -- First_Bit .. Last_Bit Component_Bit_Offset
733 -- The rule is that the first bit is obtained by subtracting
734 -- the old ending bit from machine scalar size - 1.
736 for C
in Start
.. Stop
loop
738 Comp
: constant Entity_Id
:= Comps
(C
);
739 CC
: constant Node_Id
:= Component_Clause
(Comp
);
741 LB
: constant Uint
:= Static_Integer
(Last_Bit
(CC
));
742 NFB
: constant Uint
:= MSS
- Uint_1
- LB
;
743 NLB
: constant Uint
:= NFB
+ Esize
(Comp
) - 1;
744 Pos
: constant Uint
:= Static_Integer
(Position
(CC
));
747 if Warn_On_Reverse_Bit_Order
then
748 Error_Msg_Uint_1
:= MSS
;
750 ("info: reverse bit order in machine " &
751 "scalar of length^?V?", First_Bit
(CC
));
752 Error_Msg_Uint_1
:= NFB
;
753 Error_Msg_Uint_2
:= NLB
;
755 if Bytes_Big_Endian
then
757 ("\big-endian range for component "
758 & "& is ^ .. ^?V?", First_Bit
(CC
), Comp
);
761 ("\little-endian range for component"
762 & "& is ^ .. ^?V?", First_Bit
(CC
), Comp
);
766 Set_Component_Bit_Offset
(Comp
, Pos
* SSU
+ NFB
);
767 Set_Normalized_First_Bit
(Comp
, NFB
mod SSU
);
774 end Adjust_Record_For_Reverse_Bit_Order
;
776 -------------------------------------
777 -- Alignment_Check_For_Size_Change --
778 -------------------------------------
780 procedure Alignment_Check_For_Size_Change
(Typ
: Entity_Id
; Size
: Uint
) is
782 -- If the alignment is known, and not set by a rep clause, and is
783 -- inconsistent with the size being set, then reset it to unknown,
784 -- we assume in this case that the size overrides the inherited
785 -- alignment, and that the alignment must be recomputed.
787 if Known_Alignment
(Typ
)
788 and then not Has_Alignment_Clause
(Typ
)
789 and then Size
mod (Alignment
(Typ
) * SSU
) /= 0
791 Init_Alignment
(Typ
);
793 end Alignment_Check_For_Size_Change
;
795 -------------------------------------
796 -- Analyze_Aspects_At_Freeze_Point --
797 -------------------------------------
799 procedure Analyze_Aspects_At_Freeze_Point
(E
: Entity_Id
) is
800 procedure Analyze_Aspect_Default_Value
(ASN
: Node_Id
);
801 -- This routine analyzes an Aspect_Default_[Component_]Value denoted by
802 -- the aspect specification node ASN.
804 procedure Inherit_Delayed_Rep_Aspects
(ASN
: Node_Id
);
805 -- As discussed in the spec of Aspects (see Aspect_Delay declaration),
806 -- a derived type can inherit aspects from its parent which have been
807 -- specified at the time of the derivation using an aspect, as in:
809 -- type A is range 1 .. 10
810 -- with Size => Not_Defined_Yet;
814 -- Not_Defined_Yet : constant := 64;
816 -- In this example, the Size of A is considered to be specified prior
817 -- to the derivation, and thus inherited, even though the value is not
818 -- known at the time of derivation. To deal with this, we use two entity
819 -- flags. The flag Has_Derived_Rep_Aspects is set in the parent type (A
820 -- here), and then the flag May_Inherit_Delayed_Rep_Aspects is set in
821 -- the derived type (B here). If this flag is set when the derived type
822 -- is frozen, then this procedure is called to ensure proper inheritance
823 -- of all delayed aspects from the parent type. The derived type is E,
824 -- the argument to Analyze_Aspects_At_Freeze_Point. ASN is the first
825 -- aspect specification node in the Rep_Item chain for the parent type.
827 procedure Make_Pragma_From_Boolean_Aspect
(ASN
: Node_Id
);
828 -- Given an aspect specification node ASN whose expression is an
829 -- optional Boolean, this routines creates the corresponding pragma
830 -- at the freezing point.
832 ----------------------------------
833 -- Analyze_Aspect_Default_Value --
834 ----------------------------------
836 procedure Analyze_Aspect_Default_Value
(ASN
: Node_Id
) is
837 A_Id
: constant Aspect_Id
:= Get_Aspect_Id
(ASN
);
838 Ent
: constant Entity_Id
:= Entity
(ASN
);
839 Expr
: constant Node_Id
:= Expression
(ASN
);
840 Id
: constant Node_Id
:= Identifier
(ASN
);
843 Error_Msg_Name_1
:= Chars
(Id
);
845 if not Is_Type
(Ent
) then
846 Error_Msg_N
("aspect% can only apply to a type", Id
);
849 elsif not Is_First_Subtype
(Ent
) then
850 Error_Msg_N
("aspect% cannot apply to subtype", Id
);
853 elsif A_Id
= Aspect_Default_Value
854 and then not Is_Scalar_Type
(Ent
)
856 Error_Msg_N
("aspect% can only be applied to scalar type", Id
);
859 elsif A_Id
= Aspect_Default_Component_Value
then
860 if not Is_Array_Type
(Ent
) then
861 Error_Msg_N
("aspect% can only be applied to array type", Id
);
864 elsif not Is_Scalar_Type
(Component_Type
(Ent
)) then
865 Error_Msg_N
("aspect% requires scalar components", Id
);
870 Set_Has_Default_Aspect
(Base_Type
(Ent
));
872 if Is_Scalar_Type
(Ent
) then
873 Set_Default_Aspect_Value
(Base_Type
(Ent
), Expr
);
875 Set_Default_Aspect_Component_Value
(Base_Type
(Ent
), Expr
);
877 end Analyze_Aspect_Default_Value
;
879 ---------------------------------
880 -- Inherit_Delayed_Rep_Aspects --
881 ---------------------------------
883 procedure Inherit_Delayed_Rep_Aspects
(ASN
: Node_Id
) is
884 A_Id
: constant Aspect_Id
:= Get_Aspect_Id
(ASN
);
885 P
: constant Entity_Id
:= Entity
(ASN
);
886 -- Entithy for parent type
889 -- Item from Rep_Item chain
894 -- Loop through delayed aspects for the parent type
897 while Present
(N
) loop
898 if Nkind
(N
) = N_Aspect_Specification
then
899 exit when Entity
(N
) /= P
;
901 if Is_Delayed_Aspect
(N
) then
902 A
:= Get_Aspect_Id
(Chars
(Identifier
(N
)));
904 -- Process delayed rep aspect. For Boolean attributes it is
905 -- not possible to cancel an attribute once set (the attempt
906 -- to use an aspect with xxx => False is an error) for a
907 -- derived type. So for those cases, we do not have to check
908 -- if a clause has been given for the derived type, since it
909 -- is harmless to set it again if it is already set.
915 when Aspect_Alignment
=>
916 if not Has_Alignment_Clause
(E
) then
917 Set_Alignment
(E
, Alignment
(P
));
922 when Aspect_Atomic
=>
923 if Is_Atomic
(P
) then
929 when Aspect_Atomic_Components
=>
930 if Has_Atomic_Components
(P
) then
931 Set_Has_Atomic_Components
(Base_Type
(E
));
936 when Aspect_Bit_Order
=>
937 if Is_Record_Type
(E
)
938 and then No
(Get_Attribute_Definition_Clause
939 (E
, Attribute_Bit_Order
))
940 and then Reverse_Bit_Order
(P
)
942 Set_Reverse_Bit_Order
(Base_Type
(E
));
947 when Aspect_Component_Size
=>
949 and then not Has_Component_Size_Clause
(E
)
952 (Base_Type
(E
), Component_Size
(P
));
957 when Aspect_Machine_Radix
=>
958 if Is_Decimal_Fixed_Point_Type
(E
)
959 and then not Has_Machine_Radix_Clause
(E
)
961 Set_Machine_Radix_10
(E
, Machine_Radix_10
(P
));
964 -- Object_Size (also Size which also sets Object_Size)
966 when Aspect_Object_Size | Aspect_Size
=>
967 if not Has_Size_Clause
(E
)
969 No
(Get_Attribute_Definition_Clause
970 (E
, Attribute_Object_Size
))
972 Set_Esize
(E
, Esize
(P
));
978 if not Is_Packed
(E
) then
979 Set_Is_Packed
(Base_Type
(E
));
981 if Is_Bit_Packed_Array
(P
) then
982 Set_Is_Bit_Packed_Array
(Base_Type
(E
));
983 Set_Packed_Array_Impl_Type
984 (E
, Packed_Array_Impl_Type
(P
));
988 -- Scalar_Storage_Order
990 when Aspect_Scalar_Storage_Order
=>
991 if (Is_Record_Type
(E
) or else Is_Array_Type
(E
))
992 and then No
(Get_Attribute_Definition_Clause
993 (E
, Attribute_Scalar_Storage_Order
))
994 and then Reverse_Storage_Order
(P
)
996 Set_Reverse_Storage_Order
(Base_Type
(E
));
998 -- Clear default SSO indications, since the aspect
999 -- overrides the default.
1001 Set_SSO_Set_Low_By_Default
(Base_Type
(E
), False);
1002 Set_SSO_Set_High_By_Default
(Base_Type
(E
), False);
1007 when Aspect_Small
=>
1008 if Is_Fixed_Point_Type
(E
)
1009 and then not Has_Small_Clause
(E
)
1011 Set_Small_Value
(E
, Small_Value
(P
));
1016 when Aspect_Storage_Size
=>
1017 if (Is_Access_Type
(E
) or else Is_Task_Type
(E
))
1018 and then not Has_Storage_Size_Clause
(E
)
1020 Set_Storage_Size_Variable
1021 (Base_Type
(E
), Storage_Size_Variable
(P
));
1026 when Aspect_Value_Size
=>
1028 -- Value_Size is never inherited, it is either set by
1029 -- default, or it is explicitly set for the derived
1030 -- type. So nothing to do here.
1036 when Aspect_Volatile
=>
1037 if Is_Volatile
(P
) then
1038 Set_Is_Volatile
(E
);
1041 -- Volatile_Full_Access
1043 when Aspect_Volatile_Full_Access
=>
1044 if Is_Volatile_Full_Access
(P
) then
1045 Set_Is_Volatile_Full_Access
(E
);
1048 -- Volatile_Components
1050 when Aspect_Volatile_Components
=>
1051 if Has_Volatile_Components
(P
) then
1052 Set_Has_Volatile_Components
(Base_Type
(E
));
1055 -- That should be all the Rep Aspects
1058 pragma Assert
(Aspect_Delay
(A_Id
) /= Rep_Aspect
);
1065 N
:= Next_Rep_Item
(N
);
1067 end Inherit_Delayed_Rep_Aspects
;
1069 -------------------------------------
1070 -- Make_Pragma_From_Boolean_Aspect --
1071 -------------------------------------
1073 procedure Make_Pragma_From_Boolean_Aspect
(ASN
: Node_Id
) is
1074 Ident
: constant Node_Id
:= Identifier
(ASN
);
1075 A_Name
: constant Name_Id
:= Chars
(Ident
);
1076 A_Id
: constant Aspect_Id
:= Get_Aspect_Id
(A_Name
);
1077 Ent
: constant Entity_Id
:= Entity
(ASN
);
1078 Expr
: constant Node_Id
:= Expression
(ASN
);
1079 Loc
: constant Source_Ptr
:= Sloc
(ASN
);
1081 procedure Check_False_Aspect_For_Derived_Type
;
1082 -- This procedure checks for the case of a false aspect for a derived
1083 -- type, which improperly tries to cancel an aspect inherited from
1086 -----------------------------------------
1087 -- Check_False_Aspect_For_Derived_Type --
1088 -----------------------------------------
1090 procedure Check_False_Aspect_For_Derived_Type
is
1094 -- We are only checking derived types
1096 if not Is_Derived_Type
(E
) then
1100 Par
:= Nearest_Ancestor
(E
);
1103 when Aspect_Atomic | Aspect_Shared
=>
1104 if not Is_Atomic
(Par
) then
1108 when Aspect_Atomic_Components
=>
1109 if not Has_Atomic_Components
(Par
) then
1113 when Aspect_Discard_Names
=>
1114 if not Discard_Names
(Par
) then
1119 if not Is_Packed
(Par
) then
1123 when Aspect_Unchecked_Union
=>
1124 if not Is_Unchecked_Union
(Par
) then
1128 when Aspect_Volatile
=>
1129 if not Is_Volatile
(Par
) then
1133 when Aspect_Volatile_Components
=>
1134 if not Has_Volatile_Components
(Par
) then
1138 when Aspect_Volatile_Full_Access
=>
1139 if not Is_Volatile_Full_Access
(Par
) then
1147 -- Fall through means we are canceling an inherited aspect
1149 Error_Msg_Name_1
:= A_Name
;
1151 ("derived type& inherits aspect%, cannot cancel", Expr
, E
);
1152 end Check_False_Aspect_For_Derived_Type
;
1158 -- Start of processing for Make_Pragma_From_Boolean_Aspect
1161 -- Note that we know Expr is present, because for a missing Expr
1162 -- argument, we knew it was True and did not need to delay the
1163 -- evaluation to the freeze point.
1165 if Is_False
(Static_Boolean
(Expr
)) then
1166 Check_False_Aspect_For_Derived_Type
;
1171 Pragma_Identifier
=>
1172 Make_Identifier
(Sloc
(Ident
), Chars
(Ident
)),
1173 Pragma_Argument_Associations
=> New_List
(
1174 Make_Pragma_Argument_Association
(Sloc
(Ident
),
1175 Expression
=> New_Occurrence_Of
(Ent
, Sloc
(Ident
)))));
1177 Set_From_Aspect_Specification
(Prag
, True);
1178 Set_Corresponding_Aspect
(Prag
, ASN
);
1179 Set_Aspect_Rep_Item
(ASN
, Prag
);
1180 Set_Is_Delayed_Aspect
(Prag
);
1181 Set_Parent
(Prag
, ASN
);
1183 end Make_Pragma_From_Boolean_Aspect
;
1191 -- Start of processing for Analyze_Aspects_At_Freeze_Point
1194 -- Must be visible in current scope
1196 if not Scope_Within_Or_Same
(Current_Scope
, Scope
(E
)) then
1200 -- Look for aspect specification entries for this entity
1202 ASN
:= First_Rep_Item
(E
);
1203 while Present
(ASN
) loop
1204 if Nkind
(ASN
) = N_Aspect_Specification
then
1205 exit when Entity
(ASN
) /= E
;
1207 if Is_Delayed_Aspect
(ASN
) then
1208 A_Id
:= Get_Aspect_Id
(ASN
);
1212 -- For aspects whose expression is an optional Boolean, make
1213 -- the corresponding pragma at the freeze point.
1215 when Boolean_Aspects |
1216 Library_Unit_Aspects
=>
1218 -- Aspects Export and Import require special handling.
1219 -- Both are by definition Boolean and may benefit from
1220 -- forward references, however their expressions are
1221 -- treated as static. In addition, the syntax of their
1222 -- corresponding pragmas requires extra "pieces" which
1223 -- may also contain forward references. To account for
1224 -- all of this, the corresponding pragma is created by
1225 -- Analyze_Aspect_Export_Import, but is not analyzed as
1226 -- the complete analysis must happen now.
1228 if A_Id
= Aspect_Export
or else A_Id
= Aspect_Import
then
1231 -- Otherwise create a corresponding pragma
1234 Make_Pragma_From_Boolean_Aspect
(ASN
);
1237 -- Special handling for aspects that don't correspond to
1238 -- pragmas/attributes.
1240 when Aspect_Default_Value |
1241 Aspect_Default_Component_Value
=>
1243 -- Do not inherit aspect for anonymous base type of a
1244 -- scalar or array type, because they apply to the first
1245 -- subtype of the type, and will be processed when that
1246 -- first subtype is frozen.
1248 if Is_Derived_Type
(E
)
1249 and then not Comes_From_Source
(E
)
1250 and then E
/= First_Subtype
(E
)
1254 Analyze_Aspect_Default_Value
(ASN
);
1257 -- Ditto for iterator aspects, because the corresponding
1258 -- attributes may not have been analyzed yet.
1260 when Aspect_Constant_Indexing |
1261 Aspect_Variable_Indexing |
1262 Aspect_Default_Iterator |
1263 Aspect_Iterator_Element
=>
1264 Analyze
(Expression
(ASN
));
1266 if Etype
(Expression
(ASN
)) = Any_Type
then
1268 ("\aspect must be fully defined before & is frozen",
1272 when Aspect_Iterable
=>
1273 Validate_Iterable_Aspect
(E
, ASN
);
1279 Ritem
:= Aspect_Rep_Item
(ASN
);
1281 if Present
(Ritem
) then
1287 Next_Rep_Item
(ASN
);
1290 -- This is where we inherit delayed rep aspects from our parent. Note
1291 -- that if we fell out of the above loop with ASN non-empty, it means
1292 -- we hit an aspect for an entity other than E, and it must be the
1293 -- type from which we were derived.
1295 if May_Inherit_Delayed_Rep_Aspects
(E
) then
1296 Inherit_Delayed_Rep_Aspects
(ASN
);
1298 end Analyze_Aspects_At_Freeze_Point
;
1300 -----------------------------------
1301 -- Analyze_Aspect_Specifications --
1302 -----------------------------------
1304 procedure Analyze_Aspect_Specifications
(N
: Node_Id
; E
: Entity_Id
) is
1305 procedure Decorate
(Asp
: Node_Id
; Prag
: Node_Id
);
1306 -- Establish linkages between an aspect and its corresponding pragma
1308 procedure Insert_Pragma
1310 Is_Instance
: Boolean := False);
1311 -- Subsidiary to the analysis of aspects
1318 -- Initial_Condition
1327 -- Insert pragma Prag such that it mimics the placement of a source
1328 -- pragma of the same kind. Flag Is_Generic should be set when the
1329 -- context denotes a generic instance.
1335 procedure Decorate
(Asp
: Node_Id
; Prag
: Node_Id
) is
1337 Set_Aspect_Rep_Item
(Asp
, Prag
);
1338 Set_Corresponding_Aspect
(Prag
, Asp
);
1339 Set_From_Aspect_Specification
(Prag
);
1340 Set_Parent
(Prag
, Asp
);
1347 procedure Insert_Pragma
1349 Is_Instance
: Boolean := False)
1355 Inserted
: Boolean := False;
1358 -- When the aspect appears on an entry, package, protected unit,
1359 -- subprogram, or task unit body, insert the generated pragma at the
1360 -- top of the body declarations to emulate the behavior of a source
1363 -- package body Pack with Aspect is
1365 -- package body Pack is
1368 if Nkind_In
(N
, N_Entry_Body
,
1374 Decls
:= Declarations
(N
);
1378 Set_Declarations
(N
, Decls
);
1381 Prepend_To
(Decls
, Prag
);
1383 -- When the aspect is associated with a [generic] package declaration
1384 -- insert the generated pragma at the top of the visible declarations
1385 -- to emulate the behavior of a source pragma.
1387 -- package Pack with Aspect is
1392 elsif Nkind_In
(N
, N_Generic_Package_Declaration
,
1393 N_Package_Declaration
)
1395 Decls
:= Visible_Declarations
(Specification
(N
));
1399 Set_Visible_Declarations
(Specification
(N
), Decls
);
1402 -- The visible declarations of a generic instance have the
1403 -- following structure:
1405 -- <renamings of generic formals>
1406 -- <renamings of internally-generated spec and body>
1407 -- <first source declaration>
1409 -- Insert the pragma before the first source declaration by
1410 -- skipping the instance "header" to ensure proper visibility of
1414 Decl
:= First
(Decls
);
1415 while Present
(Decl
) loop
1416 if Comes_From_Source
(Decl
) then
1417 Insert_Before
(Decl
, Prag
);
1425 -- The pragma is placed after the instance "header"
1427 if not Inserted
then
1428 Append_To
(Decls
, Prag
);
1431 -- Otherwise this is not a generic instance
1434 Prepend_To
(Decls
, Prag
);
1437 -- When the aspect is associated with a protected unit declaration,
1438 -- insert the generated pragma at the top of the visible declarations
1439 -- the emulate the behavior of a source pragma.
1441 -- protected [type] Prot with Aspect is
1443 -- protected [type] Prot is
1446 elsif Nkind
(N
) = N_Protected_Type_Declaration
then
1447 Def
:= Protected_Definition
(N
);
1451 Make_Protected_Definition
(Sloc
(N
),
1452 Visible_Declarations
=> New_List
,
1453 End_Label
=> Empty
);
1455 Set_Protected_Definition
(N
, Def
);
1458 Decls
:= Visible_Declarations
(Def
);
1462 Set_Visible_Declarations
(Def
, Decls
);
1465 Prepend_To
(Decls
, Prag
);
1467 -- When the aspect is associated with a task unit declaration, insert
1468 -- insert the generated pragma at the top of the visible declarations
1469 -- the emulate the behavior of a source pragma.
1471 -- task [type] Prot with Aspect is
1473 -- task [type] Prot is
1476 elsif Nkind
(N
) = N_Task_Type_Declaration
then
1477 Def
:= Task_Definition
(N
);
1481 Make_Task_Definition
(Sloc
(N
),
1482 Visible_Declarations
=> New_List
,
1483 End_Label
=> Empty
);
1485 Set_Task_Definition
(N
, Def
);
1488 Decls
:= Visible_Declarations
(Def
);
1492 Set_Visible_Declarations
(Def
, Decls
);
1495 Prepend_To
(Decls
, Prag
);
1497 -- When the context is a library unit, the pragma is added to the
1498 -- Pragmas_After list.
1500 elsif Nkind
(Parent
(N
)) = N_Compilation_Unit
then
1501 Aux
:= Aux_Decls_Node
(Parent
(N
));
1503 if No
(Pragmas_After
(Aux
)) then
1504 Set_Pragmas_After
(Aux
, New_List
);
1507 Prepend
(Prag
, Pragmas_After
(Aux
));
1509 -- Default, the pragma is inserted after the context
1512 Insert_After
(N
, Prag
);
1522 L
: constant List_Id
:= Aspect_Specifications
(N
);
1524 Ins_Node
: Node_Id
:= N
;
1525 -- Insert pragmas/attribute definition clause after this node when no
1526 -- delayed analysis is required.
1528 -- Start of processing for Analyze_Aspect_Specifications
1531 -- The general processing involves building an attribute definition
1532 -- clause or a pragma node that corresponds to the aspect. Then in order
1533 -- to delay the evaluation of this aspect to the freeze point, we attach
1534 -- the corresponding pragma/attribute definition clause to the aspect
1535 -- specification node, which is then placed in the Rep Item chain. In
1536 -- this case we mark the entity by setting the flag Has_Delayed_Aspects
1537 -- and we evaluate the rep item at the freeze point. When the aspect
1538 -- doesn't have a corresponding pragma/attribute definition clause, then
1539 -- its analysis is simply delayed at the freeze point.
1541 -- Some special cases don't require delay analysis, thus the aspect is
1542 -- analyzed right now.
1544 -- Note that there is a special handling for Pre, Post, Test_Case,
1545 -- Contract_Cases aspects. In these cases, we do not have to worry
1546 -- about delay issues, since the pragmas themselves deal with delay
1547 -- of visibility for the expression analysis. Thus, we just insert
1548 -- the pragma after the node N.
1550 pragma Assert
(Present
(L
));
1552 -- Loop through aspects
1554 Aspect
:= First
(L
);
1555 Aspect_Loop
: while Present
(Aspect
) loop
1556 Analyze_One_Aspect
: declare
1557 Expr
: constant Node_Id
:= Expression
(Aspect
);
1558 Id
: constant Node_Id
:= Identifier
(Aspect
);
1559 Loc
: constant Source_Ptr
:= Sloc
(Aspect
);
1560 Nam
: constant Name_Id
:= Chars
(Id
);
1561 A_Id
: constant Aspect_Id
:= Get_Aspect_Id
(Nam
);
1564 Delay_Required
: Boolean;
1565 -- Set False if delay is not required
1567 Eloc
: Source_Ptr
:= No_Location
;
1568 -- Source location of expression, modified when we split PPC's. It
1569 -- is set below when Expr is present.
1571 procedure Analyze_Aspect_Convention
;
1572 -- Perform analysis of aspect Convention
1574 procedure Analyze_Aspect_Export_Import
;
1575 -- Perform analysis of aspects Export or Import
1577 procedure Analyze_Aspect_External_Link_Name
;
1578 -- Perform analysis of aspects External_Name or Link_Name
1580 procedure Analyze_Aspect_Implicit_Dereference
;
1581 -- Perform analysis of the Implicit_Dereference aspects
1583 procedure Make_Aitem_Pragma
1584 (Pragma_Argument_Associations
: List_Id
;
1585 Pragma_Name
: Name_Id
);
1586 -- This is a wrapper for Make_Pragma used for converting aspects
1587 -- to pragmas. It takes care of Sloc (set from Loc) and building
1588 -- the pragma identifier from the given name. In addition the
1589 -- flags Class_Present and Split_PPC are set from the aspect
1590 -- node, as well as Is_Ignored. This routine also sets the
1591 -- From_Aspect_Specification in the resulting pragma node to
1592 -- True, and sets Corresponding_Aspect to point to the aspect.
1593 -- The resulting pragma is assigned to Aitem.
1595 -------------------------------
1596 -- Analyze_Aspect_Convention --
1597 -------------------------------
1599 procedure Analyze_Aspect_Convention
is
1608 -- Obtain all interfacing aspects that apply to the related
1611 Get_Interfacing_Aspects
1612 (Iface_Asp
=> Aspect
,
1613 Conv_Asp
=> Dummy_1
,
1620 -- The related entity is subject to aspect Export or Import.
1621 -- Do not process Convention now because it must be analysed
1622 -- as part of Export or Import.
1624 if Present
(Expo
) or else Present
(Imp
) then
1627 -- Otherwise Convention appears by itself
1630 -- The aspect specifies a particular convention
1632 if Present
(Expr
) then
1633 Conv
:= New_Copy_Tree
(Expr
);
1635 -- Otherwise assume convention Ada
1638 Conv
:= Make_Identifier
(Loc
, Name_Ada
);
1642 -- pragma Convention (<Conv>, <E>);
1645 (Pragma_Name
=> Name_Convention
,
1646 Pragma_Argument_Associations
=> New_List
(
1647 Make_Pragma_Argument_Association
(Loc
,
1648 Expression
=> Conv
),
1649 Make_Pragma_Argument_Association
(Loc
,
1650 Expression
=> New_Occurrence_Of
(E
, Loc
))));
1652 Decorate
(Aspect
, Aitem
);
1653 Insert_Pragma
(Aitem
);
1655 end Analyze_Aspect_Convention
;
1657 ----------------------------------
1658 -- Analyze_Aspect_Export_Import --
1659 ----------------------------------
1661 procedure Analyze_Aspect_Export_Import
is
1669 -- Obtain all interfacing aspects that apply to the related
1672 Get_Interfacing_Aspects
1673 (Iface_Asp
=> Aspect
,
1674 Conv_Asp
=> Dummy_1
,
1681 -- The related entity cannot be subject to both aspects Export
1684 if Present
(Expo
) and then Present
(Imp
) then
1686 ("incompatible interfacing aspects given for &", E
);
1687 Error_Msg_Sloc
:= Sloc
(Expo
);
1688 Error_Msg_N
("\aspect `Export` #", E
);
1689 Error_Msg_Sloc
:= Sloc
(Imp
);
1690 Error_Msg_N
("\aspect `Import` #", E
);
1693 -- A variable is most likely modified from the outside. Take
1694 -- Take the optimistic approach to avoid spurious errors.
1696 if Ekind
(E
) = E_Variable
then
1697 Set_Never_Set_In_Source
(E
, False);
1700 -- Resolve the expression of an Import or Export here, and
1701 -- require it to be of type Boolean and static. This is not
1702 -- quite right, because in general this should be delayed,
1703 -- but that seems tricky for these, because normally Boolean
1704 -- aspects are replaced with pragmas at the freeze point in
1705 -- Make_Pragma_From_Boolean_Aspect.
1707 if not Present
(Expr
)
1708 or else Is_True
(Static_Boolean
(Expr
))
1710 if A_Id
= Aspect_Import
then
1711 Set_Has_Completion
(E
);
1712 Set_Is_Imported
(E
);
1714 -- An imported object cannot be explicitly initialized
1716 if Nkind
(N
) = N_Object_Declaration
1717 and then Present
(Expression
(N
))
1720 ("imported entities cannot be initialized "
1721 & "(RM B.1(24))", Expression
(N
));
1725 pragma Assert
(A_Id
= Aspect_Export
);
1726 Set_Is_Exported
(E
);
1729 -- Create the proper form of pragma Export or Import taking
1730 -- into account Conversion, External_Name, and Link_Name.
1732 Aitem
:= Build_Export_Import_Pragma
(Aspect
, E
);
1734 -- Otherwise the expression is either False or erroneous. There
1735 -- is no corresponding pragma.
1740 end Analyze_Aspect_Export_Import
;
1742 ---------------------------------------
1743 -- Analyze_Aspect_External_Link_Name --
1744 ---------------------------------------
1746 procedure Analyze_Aspect_External_Link_Name
is
1754 -- Obtain all interfacing aspects that apply to the related
1757 Get_Interfacing_Aspects
1758 (Iface_Asp
=> Aspect
,
1759 Conv_Asp
=> Dummy_1
,
1766 -- Ensure that aspect External_Name applies to aspect Export or
1769 if A_Id
= Aspect_External_Name
then
1770 if No
(Expo
) and then No
(Imp
) then
1772 ("aspect `External_Name` requires aspect `Import` or "
1773 & "`Export`", Aspect
);
1776 -- Otherwise ensure that aspect Link_Name applies to aspect
1777 -- Export or Import.
1780 pragma Assert
(A_Id
= Aspect_Link_Name
);
1781 if No
(Expo
) and then No
(Imp
) then
1783 ("aspect `Link_Name` requires aspect `Import` or "
1784 & "`Export`", Aspect
);
1787 end Analyze_Aspect_External_Link_Name
;
1789 -----------------------------------------
1790 -- Analyze_Aspect_Implicit_Dereference --
1791 -----------------------------------------
1793 procedure Analyze_Aspect_Implicit_Dereference
is
1795 Parent_Disc
: Entity_Id
;
1798 if not Is_Type
(E
) or else not Has_Discriminants
(E
) then
1800 ("aspect must apply to a type with discriminants", Expr
);
1802 elsif not Is_Entity_Name
(Expr
) then
1804 ("aspect must name a discriminant of current type", Expr
);
1807 Disc
:= First_Discriminant
(E
);
1808 while Present
(Disc
) loop
1809 if Chars
(Expr
) = Chars
(Disc
)
1810 and then Ekind
(Etype
(Disc
)) =
1811 E_Anonymous_Access_Type
1813 Set_Has_Implicit_Dereference
(E
);
1814 Set_Has_Implicit_Dereference
(Disc
);
1818 Next_Discriminant
(Disc
);
1821 -- Error if no proper access discriminant
1824 Error_Msg_NE
("not an access discriminant of&", Expr
, E
);
1829 -- For a type extension, check whether parent has a
1830 -- reference discriminant, to verify that use is proper.
1832 if Is_Derived_Type
(E
)
1833 and then Has_Discriminants
(Etype
(E
))
1835 Parent_Disc
:= Get_Reference_Discriminant
(Etype
(E
));
1837 if Present
(Parent_Disc
)
1838 and then Corresponding_Discriminant
(Disc
) /= Parent_Disc
1841 ("reference discriminant does not match discriminant "
1842 & "of parent type", Expr
);
1845 end Analyze_Aspect_Implicit_Dereference
;
1847 -----------------------
1848 -- Make_Aitem_Pragma --
1849 -----------------------
1851 procedure Make_Aitem_Pragma
1852 (Pragma_Argument_Associations
: List_Id
;
1853 Pragma_Name
: Name_Id
)
1855 Args
: List_Id
:= Pragma_Argument_Associations
;
1858 -- We should never get here if aspect was disabled
1860 pragma Assert
(not Is_Disabled
(Aspect
));
1862 -- Certain aspects allow for an optional name or expression. Do
1863 -- not generate a pragma with empty argument association list.
1865 if No
(Args
) or else No
(Expression
(First
(Args
))) then
1873 Pragma_Argument_Associations
=> Args
,
1874 Pragma_Identifier
=>
1875 Make_Identifier
(Sloc
(Id
), Pragma_Name
),
1876 Class_Present
=> Class_Present
(Aspect
),
1877 Split_PPC
=> Split_PPC
(Aspect
));
1879 -- Set additional semantic fields
1881 if Is_Ignored
(Aspect
) then
1882 Set_Is_Ignored
(Aitem
);
1883 elsif Is_Checked
(Aspect
) then
1884 Set_Is_Checked
(Aitem
);
1887 Set_Corresponding_Aspect
(Aitem
, Aspect
);
1888 Set_From_Aspect_Specification
(Aitem
);
1889 end Make_Aitem_Pragma
;
1891 -- Start of processing for Analyze_Aspect_Specifications
1894 -- Skip aspect if already analyzed, to avoid looping in some cases
1896 if Analyzed
(Aspect
) then
1900 -- Skip looking at aspect if it is totally disabled. Just mark it
1901 -- as such for later reference in the tree. This also sets the
1902 -- Is_Ignored and Is_Checked flags appropriately.
1904 Check_Applicable_Policy
(Aspect
);
1906 if Is_Disabled
(Aspect
) then
1910 -- Set the source location of expression, used in the case of
1911 -- a failed precondition/postcondition or invariant. Note that
1912 -- the source location of the expression is not usually the best
1913 -- choice here. For example, it gets located on the last AND
1914 -- keyword in a chain of boolean expressiond AND'ed together.
1915 -- It is best to put the message on the first character of the
1916 -- assertion, which is the effect of the First_Node call here.
1918 if Present
(Expr
) then
1919 Eloc
:= Sloc
(First_Node
(Expr
));
1922 -- Check restriction No_Implementation_Aspect_Specifications
1924 if Implementation_Defined_Aspect
(A_Id
) then
1926 (No_Implementation_Aspect_Specifications
, Aspect
);
1929 -- Check restriction No_Specification_Of_Aspect
1931 Check_Restriction_No_Specification_Of_Aspect
(Aspect
);
1933 -- Mark aspect analyzed (actual analysis is delayed till later)
1935 Set_Analyzed
(Aspect
);
1936 Set_Entity
(Aspect
, E
);
1937 Ent
:= New_Occurrence_Of
(E
, Sloc
(Id
));
1939 -- Check for duplicate aspect. Note that the Comes_From_Source
1940 -- test allows duplicate Pre/Post's that we generate internally
1941 -- to escape being flagged here.
1943 if No_Duplicates_Allowed
(A_Id
) then
1945 while Anod
/= Aspect
loop
1946 if Comes_From_Source
(Aspect
)
1947 and then Same_Aspect
(A_Id
, Get_Aspect_Id
(Anod
))
1949 Error_Msg_Name_1
:= Nam
;
1950 Error_Msg_Sloc
:= Sloc
(Anod
);
1952 -- Case of same aspect specified twice
1954 if Class_Present
(Anod
) = Class_Present
(Aspect
) then
1955 if not Class_Present
(Anod
) then
1957 ("aspect% for & previously given#",
1961 ("aspect `%''Class` for & previously given#",
1971 -- Check some general restrictions on language defined aspects
1973 if not Implementation_Defined_Aspect
(A_Id
) then
1974 Error_Msg_Name_1
:= Nam
;
1976 -- Not allowed for renaming declarations. Examine the original
1977 -- node because a subprogram renaming may have been rewritten
1980 if Nkind
(Original_Node
(N
)) in N_Renaming_Declaration
then
1982 ("aspect % not allowed for renaming declaration",
1986 -- Not allowed for formal type declarations
1988 if Nkind
(N
) = N_Formal_Type_Declaration
then
1990 ("aspect % not allowed for formal type declaration",
1995 -- Copy expression for later processing by the procedures
1996 -- Check_Aspect_At_[Freeze_Point | End_Of_Declarations]
1998 Set_Entity
(Id
, New_Copy_Tree
(Expr
));
2000 -- Set Delay_Required as appropriate to aspect
2002 case Aspect_Delay
(A_Id
) is
2003 when Always_Delay
=>
2004 Delay_Required
:= True;
2007 Delay_Required
:= False;
2011 -- If expression has the form of an integer literal, then
2012 -- do not delay, since we know the value cannot change.
2013 -- This optimization catches most rep clause cases.
2015 -- For Boolean aspects, don't delay if no expression
2017 if A_Id
in Boolean_Aspects
and then No
(Expr
) then
2018 Delay_Required
:= False;
2020 -- For non-Boolean aspects, don't delay if integer literal
2022 elsif A_Id
not in Boolean_Aspects
2023 and then Present
(Expr
)
2024 and then Nkind
(Expr
) = N_Integer_Literal
2026 Delay_Required
:= False;
2028 -- All other cases are delayed
2031 Delay_Required
:= True;
2032 Set_Has_Delayed_Rep_Aspects
(E
);
2036 -- Processing based on specific aspect
2039 when Aspect_Unimplemented
=>
2040 null; -- ??? temp for now
2042 -- No_Aspect should be impossible
2045 raise Program_Error
;
2047 -- Case 1: Aspects corresponding to attribute definition
2050 when Aspect_Address |
2053 Aspect_Component_Size |
2054 Aspect_Constant_Indexing |
2055 Aspect_Default_Iterator |
2056 Aspect_Dispatching_Domain |
2057 Aspect_External_Tag |
2060 Aspect_Iterator_Element |
2061 Aspect_Machine_Radix |
2062 Aspect_Object_Size |
2065 Aspect_Scalar_Storage_Order |
2068 Aspect_Simple_Storage_Pool |
2069 Aspect_Storage_Pool |
2070 Aspect_Stream_Size |
2072 Aspect_Variable_Indexing |
2075 -- Indexing aspects apply only to tagged type
2077 if (A_Id
= Aspect_Constant_Indexing
2079 A_Id
= Aspect_Variable_Indexing
)
2080 and then not (Is_Type
(E
)
2081 and then Is_Tagged_Type
(E
))
2084 ("indexing aspect can only apply to a tagged type",
2089 -- For the case of aspect Address, we don't consider that we
2090 -- know the entity is never set in the source, since it is
2091 -- is likely aliasing is occurring.
2093 -- Note: one might think that the analysis of the resulting
2094 -- attribute definition clause would take care of that, but
2095 -- that's not the case since it won't be from source.
2097 if A_Id
= Aspect_Address
then
2098 Set_Never_Set_In_Source
(E
, False);
2101 -- Correctness of the profile of a stream operation is
2102 -- verified at the freeze point, but we must detect the
2103 -- illegal specification of this aspect for a subtype now,
2104 -- to prevent malformed rep_item chains.
2106 if A_Id
= Aspect_Input
or else
2107 A_Id
= Aspect_Output
or else
2108 A_Id
= Aspect_Read
or else
2111 if not Is_First_Subtype
(E
) then
2113 ("local name must be a first subtype", Aspect
);
2116 -- If stream aspect applies to the class-wide type,
2117 -- the generated attribute definition applies to the
2118 -- class-wide type as well.
2120 elsif Class_Present
(Aspect
) then
2122 Make_Attribute_Reference
(Loc
,
2124 Attribute_Name
=> Name_Class
);
2128 -- Construct the attribute definition clause
2131 Make_Attribute_Definition_Clause
(Loc
,
2133 Chars
=> Chars
(Id
),
2134 Expression
=> Relocate_Node
(Expr
));
2136 -- If the address is specified, then we treat the entity as
2137 -- referenced, to avoid spurious warnings. This is analogous
2138 -- to what is done with an attribute definition clause, but
2139 -- here we don't want to generate a reference because this
2140 -- is the point of definition of the entity.
2142 if A_Id
= Aspect_Address
then
2146 -- Case 2: Aspects corresponding to pragmas
2148 -- Case 2a: Aspects corresponding to pragmas with two
2149 -- arguments, where the first argument is a local name
2150 -- referring to the entity, and the second argument is the
2151 -- aspect definition expression.
2153 -- Linker_Section/Suppress/Unsuppress
2155 when Aspect_Linker_Section |
2157 Aspect_Unsuppress
=>
2160 (Pragma_Argument_Associations
=> New_List
(
2161 Make_Pragma_Argument_Association
(Loc
,
2162 Expression
=> New_Occurrence_Of
(E
, Loc
)),
2163 Make_Pragma_Argument_Association
(Sloc
(Expr
),
2164 Expression
=> Relocate_Node
(Expr
))),
2165 Pragma_Name
=> Chars
(Id
));
2169 -- Corresponds to pragma Implemented, construct the pragma
2171 when Aspect_Synchronization
=>
2173 (Pragma_Argument_Associations
=> New_List
(
2174 Make_Pragma_Argument_Association
(Loc
,
2175 Expression
=> New_Occurrence_Of
(E
, Loc
)),
2176 Make_Pragma_Argument_Association
(Sloc
(Expr
),
2177 Expression
=> Relocate_Node
(Expr
))),
2178 Pragma_Name
=> Name_Implemented
);
2182 when Aspect_Attach_Handler
=>
2184 (Pragma_Argument_Associations
=> New_List
(
2185 Make_Pragma_Argument_Association
(Sloc
(Ent
),
2187 Make_Pragma_Argument_Association
(Sloc
(Expr
),
2188 Expression
=> Relocate_Node
(Expr
))),
2189 Pragma_Name
=> Name_Attach_Handler
);
2191 -- We need to insert this pragma into the tree to get proper
2192 -- processing and to look valid from a placement viewpoint.
2194 Insert_Pragma
(Aitem
);
2197 -- Dynamic_Predicate, Predicate, Static_Predicate
2199 when Aspect_Dynamic_Predicate |
2201 Aspect_Static_Predicate
=>
2203 -- These aspects apply only to subtypes
2205 if not Is_Type
(E
) then
2207 ("predicate can only be specified for a subtype",
2211 elsif Is_Incomplete_Type
(E
) then
2213 ("predicate cannot apply to incomplete view", Aspect
);
2217 -- Construct the pragma (always a pragma Predicate, with
2218 -- flags recording whether it is static/dynamic). We also
2219 -- set flags recording this in the type itself.
2222 (Pragma_Argument_Associations
=> New_List
(
2223 Make_Pragma_Argument_Association
(Sloc
(Ent
),
2225 Make_Pragma_Argument_Association
(Sloc
(Expr
),
2226 Expression
=> Relocate_Node
(Expr
))),
2227 Pragma_Name
=> Name_Predicate
);
2229 -- Mark type has predicates, and remember what kind of
2230 -- aspect lead to this predicate (we need this to access
2231 -- the right set of check policies later on).
2233 Set_Has_Predicates
(E
);
2235 if A_Id
= Aspect_Dynamic_Predicate
then
2236 Set_Has_Dynamic_Predicate_Aspect
(E
);
2237 elsif A_Id
= Aspect_Static_Predicate
then
2238 Set_Has_Static_Predicate_Aspect
(E
);
2241 -- If the type is private, indicate that its completion
2242 -- has a freeze node, because that is the one that will
2243 -- be visible at freeze time.
2245 if Is_Private_Type
(E
) and then Present
(Full_View
(E
)) then
2246 Set_Has_Predicates
(Full_View
(E
));
2248 if A_Id
= Aspect_Dynamic_Predicate
then
2249 Set_Has_Dynamic_Predicate_Aspect
(Full_View
(E
));
2250 elsif A_Id
= Aspect_Static_Predicate
then
2251 Set_Has_Static_Predicate_Aspect
(Full_View
(E
));
2254 Set_Has_Delayed_Aspects
(Full_View
(E
));
2255 Ensure_Freeze_Node
(Full_View
(E
));
2258 -- Predicate_Failure
2260 when Aspect_Predicate_Failure
=>
2262 -- This aspect applies only to subtypes
2264 if not Is_Type
(E
) then
2266 ("predicate can only be specified for a subtype",
2270 elsif Is_Incomplete_Type
(E
) then
2272 ("predicate cannot apply to incomplete view", Aspect
);
2276 -- Construct the pragma
2279 (Pragma_Argument_Associations
=> New_List
(
2280 Make_Pragma_Argument_Association
(Sloc
(Ent
),
2282 Make_Pragma_Argument_Association
(Sloc
(Expr
),
2283 Expression
=> Relocate_Node
(Expr
))),
2284 Pragma_Name
=> Name_Predicate_Failure
);
2286 Set_Has_Predicates
(E
);
2288 -- If the type is private, indicate that its completion
2289 -- has a freeze node, because that is the one that will
2290 -- be visible at freeze time.
2292 if Is_Private_Type
(E
) and then Present
(Full_View
(E
)) then
2293 Set_Has_Predicates
(Full_View
(E
));
2294 Set_Has_Delayed_Aspects
(Full_View
(E
));
2295 Ensure_Freeze_Node
(Full_View
(E
));
2298 -- Case 2b: Aspects corresponding to pragmas with two
2299 -- arguments, where the second argument is a local name
2300 -- referring to the entity, and the first argument is the
2301 -- aspect definition expression.
2305 when Aspect_Convention
=>
2306 Analyze_Aspect_Convention
;
2309 -- External_Name, Link_Name
2311 when Aspect_External_Name |
2313 Analyze_Aspect_External_Link_Name
;
2316 -- CPU, Interrupt_Priority, Priority
2318 -- These three aspects can be specified for a subprogram spec
2319 -- or body, in which case we analyze the expression and export
2320 -- the value of the aspect.
2322 -- Previously, we generated an equivalent pragma for bodies
2323 -- (note that the specs cannot contain these pragmas). The
2324 -- pragma was inserted ahead of local declarations, rather than
2325 -- after the body. This leads to a certain duplication between
2326 -- the processing performed for the aspect and the pragma, but
2327 -- given the straightforward handling required it is simpler
2328 -- to duplicate than to translate the aspect in the spec into
2329 -- a pragma in the declarative part of the body.
2332 Aspect_Interrupt_Priority |
2335 if Nkind_In
(N
, N_Subprogram_Body
,
2336 N_Subprogram_Declaration
)
2338 -- Analyze the aspect expression
2340 Analyze_And_Resolve
(Expr
, Standard_Integer
);
2342 -- Interrupt_Priority aspect not allowed for main
2343 -- subprograms. RM D.1 does not forbid this explicitly,
2344 -- but RM J.15.11(6/3) does not permit pragma
2345 -- Interrupt_Priority for subprograms.
2347 if A_Id
= Aspect_Interrupt_Priority
then
2349 ("Interrupt_Priority aspect cannot apply to "
2350 & "subprogram", Expr
);
2352 -- The expression must be static
2354 elsif not Is_OK_Static_Expression
(Expr
) then
2355 Flag_Non_Static_Expr
2356 ("aspect requires static expression!", Expr
);
2358 -- Check whether this is the main subprogram. Issue a
2359 -- warning only if it is obviously not a main program
2360 -- (when it has parameters or when the subprogram is
2361 -- within a package).
2363 elsif Present
(Parameter_Specifications
2364 (Specification
(N
)))
2365 or else not Is_Compilation_Unit
(Defining_Entity
(N
))
2367 -- See RM D.1(14/3) and D.16(12/3)
2370 ("aspect applied to subprogram other than the "
2371 & "main subprogram has no effect??", Expr
);
2373 -- Otherwise check in range and export the value
2375 -- For the CPU aspect
2377 elsif A_Id
= Aspect_CPU
then
2378 if Is_In_Range
(Expr
, RTE
(RE_CPU_Range
)) then
2380 -- Value is correct so we export the value to make
2381 -- it available at execution time.
2384 (Main_Unit
, UI_To_Int
(Expr_Value
(Expr
)));
2388 ("main subprogram CPU is out of range", Expr
);
2391 -- For the Priority aspect
2393 elsif A_Id
= Aspect_Priority
then
2394 if Is_In_Range
(Expr
, RTE
(RE_Priority
)) then
2396 -- Value is correct so we export the value to make
2397 -- it available at execution time.
2400 (Main_Unit
, UI_To_Int
(Expr_Value
(Expr
)));
2402 -- Ignore pragma if Relaxed_RM_Semantics to support
2403 -- other targets/non GNAT compilers.
2405 elsif not Relaxed_RM_Semantics
then
2407 ("main subprogram priority is out of range",
2412 -- Load an arbitrary entity from System.Tasking.Stages
2413 -- or System.Tasking.Restricted.Stages (depending on
2414 -- the supported profile) to make sure that one of these
2415 -- packages is implicitly with'ed, since we need to have
2416 -- the tasking run time active for the pragma Priority to
2417 -- have any effect. Previously we with'ed the package
2418 -- System.Tasking, but this package does not trigger the
2419 -- required initialization of the run-time library.
2422 Discard
: Entity_Id
;
2424 if Restricted_Profile
then
2425 Discard
:= RTE
(RE_Activate_Restricted_Tasks
);
2427 Discard
:= RTE
(RE_Activate_Tasks
);
2431 -- Handling for these Aspects in subprograms is complete
2435 -- For tasks pass the aspect as an attribute
2439 Make_Attribute_Definition_Clause
(Loc
,
2441 Chars
=> Chars
(Id
),
2442 Expression
=> Relocate_Node
(Expr
));
2447 when Aspect_Warnings
=>
2449 (Pragma_Argument_Associations
=> New_List
(
2450 Make_Pragma_Argument_Association
(Sloc
(Expr
),
2451 Expression
=> Relocate_Node
(Expr
)),
2452 Make_Pragma_Argument_Association
(Loc
,
2453 Expression
=> New_Occurrence_Of
(E
, Loc
))),
2454 Pragma_Name
=> Chars
(Id
));
2456 Decorate
(Aspect
, Aitem
);
2457 Insert_Pragma
(Aitem
);
2460 -- Case 2c: Aspects corresponding to pragmas with three
2463 -- Invariant aspects have a first argument that references the
2464 -- entity, a second argument that is the expression and a third
2465 -- argument that is an appropriate message.
2467 -- Invariant, Type_Invariant
2469 when Aspect_Invariant |
2470 Aspect_Type_Invariant
=>
2472 -- Analysis of the pragma will verify placement legality:
2473 -- an invariant must apply to a private type, or appear in
2474 -- the private part of a spec and apply to a completion.
2477 (Pragma_Argument_Associations
=> New_List
(
2478 Make_Pragma_Argument_Association
(Sloc
(Ent
),
2480 Make_Pragma_Argument_Association
(Sloc
(Expr
),
2481 Expression
=> Relocate_Node
(Expr
))),
2482 Pragma_Name
=> Name_Invariant
);
2484 -- Add message unless exception messages are suppressed
2486 if not Opt
.Exception_Locations_Suppressed
then
2487 Append_To
(Pragma_Argument_Associations
(Aitem
),
2488 Make_Pragma_Argument_Association
(Eloc
,
2489 Chars
=> Name_Message
,
2491 Make_String_Literal
(Eloc
,
2492 Strval
=> "failed invariant from "
2493 & Build_Location_String
(Eloc
))));
2496 -- For Invariant case, insert immediately after the entity
2497 -- declaration. We do not have to worry about delay issues
2498 -- since the pragma processing takes care of this.
2500 Delay_Required
:= False;
2502 -- Case 2d : Aspects that correspond to a pragma with one
2507 -- Aspect Abstract_State introduces implicit declarations for
2508 -- all state abstraction entities it defines. To emulate this
2509 -- behavior, insert the pragma at the beginning of the visible
2510 -- declarations of the related package so that it is analyzed
2513 when Aspect_Abstract_State
=> Abstract_State
: declare
2514 Context
: Node_Id
:= N
;
2517 -- When aspect Abstract_State appears on a generic package,
2518 -- it is propageted to the package instance. The context in
2519 -- this case is the instance spec.
2521 if Nkind
(Context
) = N_Package_Instantiation
then
2522 Context
:= Instance_Spec
(Context
);
2525 if Nkind_In
(Context
, N_Generic_Package_Declaration
,
2526 N_Package_Declaration
)
2529 (Pragma_Argument_Associations
=> New_List
(
2530 Make_Pragma_Argument_Association
(Loc
,
2531 Expression
=> Relocate_Node
(Expr
))),
2532 Pragma_Name
=> Name_Abstract_State
);
2534 Decorate
(Aspect
, Aitem
);
2538 Is_Generic_Instance
(Defining_Entity
(Context
)));
2542 ("aspect & must apply to a package declaration",
2549 -- Aspect Async_Readers is never delayed because it is
2550 -- equivalent to a source pragma which appears after the
2551 -- related object declaration.
2553 when Aspect_Async_Readers
=>
2555 (Pragma_Argument_Associations
=> New_List
(
2556 Make_Pragma_Argument_Association
(Loc
,
2557 Expression
=> Relocate_Node
(Expr
))),
2558 Pragma_Name
=> Name_Async_Readers
);
2560 Decorate
(Aspect
, Aitem
);
2561 Insert_Pragma
(Aitem
);
2564 -- Aspect Async_Writers is never delayed because it is
2565 -- equivalent to a source pragma which appears after the
2566 -- related object declaration.
2568 when Aspect_Async_Writers
=>
2570 (Pragma_Argument_Associations
=> New_List
(
2571 Make_Pragma_Argument_Association
(Loc
,
2572 Expression
=> Relocate_Node
(Expr
))),
2573 Pragma_Name
=> Name_Async_Writers
);
2575 Decorate
(Aspect
, Aitem
);
2576 Insert_Pragma
(Aitem
);
2579 -- Aspect Constant_After_Elaboration is never delayed because
2580 -- it is equivalent to a source pragma which appears after the
2581 -- related object declaration.
2583 when Aspect_Constant_After_Elaboration
=>
2585 (Pragma_Argument_Associations
=> New_List
(
2586 Make_Pragma_Argument_Association
(Loc
,
2587 Expression
=> Relocate_Node
(Expr
))),
2589 Name_Constant_After_Elaboration
);
2591 Decorate
(Aspect
, Aitem
);
2592 Insert_Pragma
(Aitem
);
2595 -- Aspect Default_Internal_Condition is never delayed because
2596 -- it is equivalent to a source pragma which appears after the
2597 -- related private type. To deal with forward references, the
2598 -- generated pragma is stored in the rep chain of the related
2599 -- private type as types do not carry contracts. The pragma is
2600 -- wrapped inside of a procedure at the freeze point of the
2601 -- private type's full view.
2603 when Aspect_Default_Initial_Condition
=>
2605 (Pragma_Argument_Associations
=> New_List
(
2606 Make_Pragma_Argument_Association
(Loc
,
2607 Expression
=> Relocate_Node
(Expr
))),
2609 Name_Default_Initial_Condition
);
2611 Decorate
(Aspect
, Aitem
);
2612 Insert_Pragma
(Aitem
);
2615 -- Default_Storage_Pool
2617 when Aspect_Default_Storage_Pool
=>
2619 (Pragma_Argument_Associations
=> New_List
(
2620 Make_Pragma_Argument_Association
(Loc
,
2621 Expression
=> Relocate_Node
(Expr
))),
2623 Name_Default_Storage_Pool
);
2625 Decorate
(Aspect
, Aitem
);
2626 Insert_Pragma
(Aitem
);
2631 -- Aspect Depends is never delayed because it is equivalent to
2632 -- a source pragma which appears after the related subprogram.
2633 -- To deal with forward references, the generated pragma is
2634 -- stored in the contract of the related subprogram and later
2635 -- analyzed at the end of the declarative region. See routine
2636 -- Analyze_Depends_In_Decl_Part for details.
2638 when Aspect_Depends
=>
2640 (Pragma_Argument_Associations
=> New_List
(
2641 Make_Pragma_Argument_Association
(Loc
,
2642 Expression
=> Relocate_Node
(Expr
))),
2643 Pragma_Name
=> Name_Depends
);
2645 Decorate
(Aspect
, Aitem
);
2646 Insert_Pragma
(Aitem
);
2649 -- Aspect Effecitve_Reads is never delayed because it is
2650 -- equivalent to a source pragma which appears after the
2651 -- related object declaration.
2653 when Aspect_Effective_Reads
=>
2655 (Pragma_Argument_Associations
=> New_List
(
2656 Make_Pragma_Argument_Association
(Loc
,
2657 Expression
=> Relocate_Node
(Expr
))),
2658 Pragma_Name
=> Name_Effective_Reads
);
2660 Decorate
(Aspect
, Aitem
);
2661 Insert_Pragma
(Aitem
);
2664 -- Aspect Effective_Writes is never delayed because it is
2665 -- equivalent to a source pragma which appears after the
2666 -- related object declaration.
2668 when Aspect_Effective_Writes
=>
2670 (Pragma_Argument_Associations
=> New_List
(
2671 Make_Pragma_Argument_Association
(Loc
,
2672 Expression
=> Relocate_Node
(Expr
))),
2673 Pragma_Name
=> Name_Effective_Writes
);
2675 Decorate
(Aspect
, Aitem
);
2676 Insert_Pragma
(Aitem
);
2679 -- Aspect Extensions_Visible is never delayed because it is
2680 -- equivalent to a source pragma which appears after the
2681 -- related subprogram.
2683 when Aspect_Extensions_Visible
=>
2685 (Pragma_Argument_Associations
=> New_List
(
2686 Make_Pragma_Argument_Association
(Loc
,
2687 Expression
=> Relocate_Node
(Expr
))),
2688 Pragma_Name
=> Name_Extensions_Visible
);
2690 Decorate
(Aspect
, Aitem
);
2691 Insert_Pragma
(Aitem
);
2694 -- Aspect Ghost is never delayed because it is equivalent to a
2695 -- source pragma which appears at the top of [generic] package
2696 -- declarations or after an object, a [generic] subprogram, or
2697 -- a type declaration.
2699 when Aspect_Ghost
=>
2701 (Pragma_Argument_Associations
=> New_List
(
2702 Make_Pragma_Argument_Association
(Loc
,
2703 Expression
=> Relocate_Node
(Expr
))),
2704 Pragma_Name
=> Name_Ghost
);
2706 Decorate
(Aspect
, Aitem
);
2707 Insert_Pragma
(Aitem
);
2712 -- Aspect Global is never delayed because it is equivalent to
2713 -- a source pragma which appears after the related subprogram.
2714 -- To deal with forward references, the generated pragma is
2715 -- stored in the contract of the related subprogram and later
2716 -- analyzed at the end of the declarative region. See routine
2717 -- Analyze_Global_In_Decl_Part for details.
2719 when Aspect_Global
=>
2721 (Pragma_Argument_Associations
=> New_List
(
2722 Make_Pragma_Argument_Association
(Loc
,
2723 Expression
=> Relocate_Node
(Expr
))),
2724 Pragma_Name
=> Name_Global
);
2726 Decorate
(Aspect
, Aitem
);
2727 Insert_Pragma
(Aitem
);
2730 -- Initial_Condition
2732 -- Aspect Initial_Condition is never delayed because it is
2733 -- equivalent to a source pragma which appears after the
2734 -- related package. To deal with forward references, the
2735 -- generated pragma is stored in the contract of the related
2736 -- package and later analyzed at the end of the declarative
2737 -- region. See routine Analyze_Initial_Condition_In_Decl_Part
2740 when Aspect_Initial_Condition
=> Initial_Condition
: declare
2741 Context
: Node_Id
:= N
;
2744 -- When aspect Initial_Condition appears on a generic
2745 -- package, it is propageted to the package instance. The
2746 -- context in this case is the instance spec.
2748 if Nkind
(Context
) = N_Package_Instantiation
then
2749 Context
:= Instance_Spec
(Context
);
2752 if Nkind_In
(Context
, N_Generic_Package_Declaration
,
2753 N_Package_Declaration
)
2756 (Pragma_Argument_Associations
=> New_List
(
2757 Make_Pragma_Argument_Association
(Loc
,
2758 Expression
=> Relocate_Node
(Expr
))),
2760 Name_Initial_Condition
);
2762 Decorate
(Aspect
, Aitem
);
2766 Is_Generic_Instance
(Defining_Entity
(Context
)));
2768 -- Otherwise the context is illegal
2772 ("aspect & must apply to a package declaration",
2777 end Initial_Condition
;
2781 -- Aspect Initializes is never delayed because it is equivalent
2782 -- to a source pragma appearing after the related package. To
2783 -- deal with forward references, the generated pragma is stored
2784 -- in the contract of the related package and later analyzed at
2785 -- the end of the declarative region. For details, see routine
2786 -- Analyze_Initializes_In_Decl_Part.
2788 when Aspect_Initializes
=> Initializes
: declare
2789 Context
: Node_Id
:= N
;
2792 -- When aspect Initializes appears on a generic package,
2793 -- it is propageted to the package instance. The context
2794 -- in this case is the instance spec.
2796 if Nkind
(Context
) = N_Package_Instantiation
then
2797 Context
:= Instance_Spec
(Context
);
2800 if Nkind_In
(Context
, N_Generic_Package_Declaration
,
2801 N_Package_Declaration
)
2804 (Pragma_Argument_Associations
=> New_List
(
2805 Make_Pragma_Argument_Association
(Loc
,
2806 Expression
=> Relocate_Node
(Expr
))),
2807 Pragma_Name
=> Name_Initializes
);
2809 Decorate
(Aspect
, Aitem
);
2813 Is_Generic_Instance
(Defining_Entity
(Context
)));
2815 -- Otherwise the context is illegal
2819 ("aspect & must apply to a package declaration",
2828 when Aspect_Obsolescent
=> declare
2836 Make_Pragma_Argument_Association
(Sloc
(Expr
),
2837 Expression
=> Relocate_Node
(Expr
)));
2841 (Pragma_Argument_Associations
=> Args
,
2842 Pragma_Name
=> Chars
(Id
));
2847 when Aspect_Part_Of
=>
2848 if Nkind_In
(N
, N_Object_Declaration
,
2849 N_Package_Instantiation
)
2850 or else Is_Single_Concurrent_Type_Declaration
(N
)
2853 (Pragma_Argument_Associations
=> New_List
(
2854 Make_Pragma_Argument_Association
(Loc
,
2855 Expression
=> Relocate_Node
(Expr
))),
2856 Pragma_Name
=> Name_Part_Of
);
2858 Decorate
(Aspect
, Aitem
);
2859 Insert_Pragma
(Aitem
);
2863 ("aspect & must apply to package instantiation, "
2864 & "object, single protected type or single task type",
2872 when Aspect_SPARK_Mode
=>
2874 (Pragma_Argument_Associations
=> New_List
(
2875 Make_Pragma_Argument_Association
(Loc
,
2876 Expression
=> Relocate_Node
(Expr
))),
2877 Pragma_Name
=> Name_SPARK_Mode
);
2879 Decorate
(Aspect
, Aitem
);
2880 Insert_Pragma
(Aitem
);
2885 -- Aspect Refined_Depends is never delayed because it is
2886 -- equivalent to a source pragma which appears in the
2887 -- declarations of the related subprogram body. To deal with
2888 -- forward references, the generated pragma is stored in the
2889 -- contract of the related subprogram body and later analyzed
2890 -- at the end of the declarative region. For details, see
2891 -- routine Analyze_Refined_Depends_In_Decl_Part.
2893 when Aspect_Refined_Depends
=>
2895 (Pragma_Argument_Associations
=> New_List
(
2896 Make_Pragma_Argument_Association
(Loc
,
2897 Expression
=> Relocate_Node
(Expr
))),
2898 Pragma_Name
=> Name_Refined_Depends
);
2900 Decorate
(Aspect
, Aitem
);
2901 Insert_Pragma
(Aitem
);
2906 -- Aspect Refined_Global is never delayed because it is
2907 -- equivalent to a source pragma which appears in the
2908 -- declarations of the related subprogram body. To deal with
2909 -- forward references, the generated pragma is stored in the
2910 -- contract of the related subprogram body and later analyzed
2911 -- at the end of the declarative region. For details, see
2912 -- routine Analyze_Refined_Global_In_Decl_Part.
2914 when Aspect_Refined_Global
=>
2916 (Pragma_Argument_Associations
=> New_List
(
2917 Make_Pragma_Argument_Association
(Loc
,
2918 Expression
=> Relocate_Node
(Expr
))),
2919 Pragma_Name
=> Name_Refined_Global
);
2921 Decorate
(Aspect
, Aitem
);
2922 Insert_Pragma
(Aitem
);
2927 when Aspect_Refined_Post
=>
2929 (Pragma_Argument_Associations
=> New_List
(
2930 Make_Pragma_Argument_Association
(Loc
,
2931 Expression
=> Relocate_Node
(Expr
))),
2932 Pragma_Name
=> Name_Refined_Post
);
2934 Decorate
(Aspect
, Aitem
);
2935 Insert_Pragma
(Aitem
);
2940 when Aspect_Refined_State
=>
2942 -- The corresponding pragma for Refined_State is inserted in
2943 -- the declarations of the related package body. This action
2944 -- synchronizes both the source and from-aspect versions of
2947 if Nkind
(N
) = N_Package_Body
then
2949 (Pragma_Argument_Associations
=> New_List
(
2950 Make_Pragma_Argument_Association
(Loc
,
2951 Expression
=> Relocate_Node
(Expr
))),
2952 Pragma_Name
=> Name_Refined_State
);
2954 Decorate
(Aspect
, Aitem
);
2955 Insert_Pragma
(Aitem
);
2957 -- Otherwise the context is illegal
2961 ("aspect & must apply to a package body", Aspect
, Id
);
2966 -- Relative_Deadline
2968 when Aspect_Relative_Deadline
=>
2970 (Pragma_Argument_Associations
=> New_List
(
2971 Make_Pragma_Argument_Association
(Loc
,
2972 Expression
=> Relocate_Node
(Expr
))),
2973 Pragma_Name
=> Name_Relative_Deadline
);
2975 -- If the aspect applies to a task, the corresponding pragma
2976 -- must appear within its declarations, not after.
2978 if Nkind
(N
) = N_Task_Type_Declaration
then
2984 if No
(Task_Definition
(N
)) then
2985 Set_Task_Definition
(N
,
2986 Make_Task_Definition
(Loc
,
2987 Visible_Declarations
=> New_List
,
2988 End_Label
=> Empty
));
2991 Def
:= Task_Definition
(N
);
2992 V
:= Visible_Declarations
(Def
);
2993 if not Is_Empty_List
(V
) then
2994 Insert_Before
(First
(V
), Aitem
);
2997 Set_Visible_Declarations
(Def
, New_List
(Aitem
));
3004 -- Aspect Volatile_Function is never delayed because it is
3005 -- equivalent to a source pragma which appears after the
3006 -- related subprogram.
3008 when Aspect_Volatile_Function
=>
3010 (Pragma_Argument_Associations
=> New_List
(
3011 Make_Pragma_Argument_Association
(Loc
,
3012 Expression
=> Relocate_Node
(Expr
))),
3013 Pragma_Name
=> Name_Volatile_Function
);
3015 Decorate
(Aspect
, Aitem
);
3016 Insert_Pragma
(Aitem
);
3019 -- Case 2e: Annotate aspect
3021 when Aspect_Annotate
=>
3028 -- The argument can be a single identifier
3030 if Nkind
(Expr
) = N_Identifier
then
3032 -- One level of parens is allowed
3034 if Paren_Count
(Expr
) > 1 then
3035 Error_Msg_F
("extra parentheses ignored", Expr
);
3038 Set_Paren_Count
(Expr
, 0);
3040 -- Add the single item to the list
3042 Args
:= New_List
(Expr
);
3044 -- Otherwise we must have an aggregate
3046 elsif Nkind
(Expr
) = N_Aggregate
then
3048 -- Must be positional
3050 if Present
(Component_Associations
(Expr
)) then
3052 ("purely positional aggregate required", Expr
);
3056 -- Must not be parenthesized
3058 if Paren_Count
(Expr
) /= 0 then
3059 Error_Msg_F
("extra parentheses ignored", Expr
);
3062 -- List of arguments is list of aggregate expressions
3064 Args
:= Expressions
(Expr
);
3066 -- Anything else is illegal
3069 Error_Msg_F
("wrong form for Annotate aspect", Expr
);
3073 -- Prepare pragma arguments
3076 Arg
:= First
(Args
);
3077 while Present
(Arg
) loop
3079 Make_Pragma_Argument_Association
(Sloc
(Arg
),
3080 Expression
=> Relocate_Node
(Arg
)));
3085 Make_Pragma_Argument_Association
(Sloc
(Ent
),
3086 Chars
=> Name_Entity
,
3087 Expression
=> Ent
));
3090 (Pragma_Argument_Associations
=> Pargs
,
3091 Pragma_Name
=> Name_Annotate
);
3094 -- Case 3 : Aspects that don't correspond to pragma/attribute
3095 -- definition clause.
3097 -- Case 3a: The aspects listed below don't correspond to
3098 -- pragmas/attributes but do require delayed analysis.
3100 -- Default_Value can only apply to a scalar type
3102 when Aspect_Default_Value
=>
3103 if not Is_Scalar_Type
(E
) then
3105 ("aspect Default_Value must apply to a scalar type", N
);
3110 -- Default_Component_Value can only apply to an array type
3111 -- with scalar components.
3113 when Aspect_Default_Component_Value
=>
3114 if not (Is_Array_Type
(E
)
3115 and then Is_Scalar_Type
(Component_Type
(E
)))
3118 ("aspect Default_Component_Value can only apply to an "
3119 & "array of scalar components", N
);
3124 -- Case 3b: The aspects listed below don't correspond to
3125 -- pragmas/attributes and don't need delayed analysis.
3127 -- Implicit_Dereference
3129 -- For Implicit_Dereference, External_Name and Link_Name, only
3130 -- the legality checks are done during the analysis, thus no
3131 -- delay is required.
3133 when Aspect_Implicit_Dereference
=>
3134 Analyze_Aspect_Implicit_Dereference
;
3139 when Aspect_Dimension
=>
3140 Analyze_Aspect_Dimension
(N
, Id
, Expr
);
3145 when Aspect_Dimension_System
=>
3146 Analyze_Aspect_Dimension_System
(N
, Id
, Expr
);
3149 -- Case 4: Aspects requiring special handling
3151 -- Pre/Post/Test_Case/Contract_Cases whose corresponding
3152 -- pragmas take care of the delay.
3156 -- Aspects Pre/Post generate Precondition/Postcondition pragmas
3157 -- with a first argument that is the expression, and a second
3158 -- argument that is an informative message if the test fails.
3159 -- This is inserted right after the declaration, to get the
3160 -- required pragma placement. The processing for the pragmas
3161 -- takes care of the required delay.
3163 when Pre_Post_Aspects
=> Pre_Post
: declare
3167 if A_Id
= Aspect_Pre
or else A_Id
= Aspect_Precondition
then
3168 Pname
:= Name_Precondition
;
3170 Pname
:= Name_Postcondition
;
3173 -- Check that the class-wide predicate cannot be applied to
3174 -- an operation of a synchronized type that is not a tagged
3175 -- type. Other legality checks are performed when analyzing
3176 -- the contract of the operation.
3178 if Class_Present
(Aspect
)
3179 and then Is_Concurrent_Type
(Current_Scope
)
3180 and then not Is_Tagged_Type
(Current_Scope
)
3181 and then Ekind_In
(E
, E_Entry
, E_Function
, E_Procedure
)
3183 Error_Msg_Name_1
:= Original_Aspect_Pragma_Name
(Aspect
);
3185 ("aspect % can only be specified for a primitive "
3186 & "operation of a tagged type", Aspect
);
3191 -- If the expressions is of the form A and then B, then
3192 -- we generate separate Pre/Post aspects for the separate
3193 -- clauses. Since we allow multiple pragmas, there is no
3194 -- problem in allowing multiple Pre/Post aspects internally.
3195 -- These should be treated in reverse order (B first and
3196 -- A second) since they are later inserted just after N in
3197 -- the order they are treated. This way, the pragma for A
3198 -- ends up preceding the pragma for B, which may have an
3199 -- importance for the error raised (either constraint error
3200 -- or precondition error).
3202 -- We do not do this for Pre'Class, since we have to put
3203 -- these conditions together in a complex OR expression.
3205 -- We do not do this in ASIS mode, as ASIS relies on the
3206 -- original node representing the complete expression, when
3207 -- retrieving it through the source aspect table.
3210 and then (Pname
= Name_Postcondition
3211 or else not Class_Present
(Aspect
))
3213 while Nkind
(Expr
) = N_And_Then
loop
3214 Insert_After
(Aspect
,
3215 Make_Aspect_Specification
(Sloc
(Left_Opnd
(Expr
)),
3216 Identifier
=> Identifier
(Aspect
),
3217 Expression
=> Relocate_Node
(Left_Opnd
(Expr
)),
3218 Class_Present
=> Class_Present
(Aspect
),
3219 Split_PPC
=> True));
3220 Rewrite
(Expr
, Relocate_Node
(Right_Opnd
(Expr
)));
3221 Eloc
:= Sloc
(Expr
);
3225 -- Build the precondition/postcondition pragma
3227 -- Add note about why we do NOT need Copy_Tree here???
3230 (Pragma_Argument_Associations
=> New_List
(
3231 Make_Pragma_Argument_Association
(Eloc
,
3232 Chars
=> Name_Check
,
3233 Expression
=> Relocate_Node
(Expr
))),
3234 Pragma_Name
=> Pname
);
3236 -- Add message unless exception messages are suppressed
3238 if not Opt
.Exception_Locations_Suppressed
then
3239 Append_To
(Pragma_Argument_Associations
(Aitem
),
3240 Make_Pragma_Argument_Association
(Eloc
,
3241 Chars
=> Name_Message
,
3243 Make_String_Literal
(Eloc
,
3245 & Get_Name_String
(Pname
)
3247 & Build_Location_String
(Eloc
))));
3250 Set_Is_Delayed_Aspect
(Aspect
);
3252 -- For Pre/Post cases, insert immediately after the entity
3253 -- declaration, since that is the required pragma placement.
3254 -- Note that for these aspects, we do not have to worry
3255 -- about delay issues, since the pragmas themselves deal
3256 -- with delay of visibility for the expression analysis.
3258 Insert_Pragma
(Aitem
);
3265 when Aspect_Test_Case
=> Test_Case
: declare
3267 Comp_Expr
: Node_Id
;
3268 Comp_Assn
: Node_Id
;
3274 if Nkind
(Parent
(N
)) = N_Compilation_Unit
then
3275 Error_Msg_Name_1
:= Nam
;
3276 Error_Msg_N
("incorrect placement of aspect `%`", E
);
3280 if Nkind
(Expr
) /= N_Aggregate
then
3281 Error_Msg_Name_1
:= Nam
;
3283 ("wrong syntax for aspect `%` for &", Id
, E
);
3287 -- Make pragma expressions refer to the original aspect
3288 -- expressions through the Original_Node link. This is used
3289 -- in semantic analysis for ASIS mode, so that the original
3290 -- expression also gets analyzed.
3292 Comp_Expr
:= First
(Expressions
(Expr
));
3293 while Present
(Comp_Expr
) loop
3294 New_Expr
:= Relocate_Node
(Comp_Expr
);
3296 Make_Pragma_Argument_Association
(Sloc
(Comp_Expr
),
3297 Expression
=> New_Expr
));
3301 Comp_Assn
:= First
(Component_Associations
(Expr
));
3302 while Present
(Comp_Assn
) loop
3303 if List_Length
(Choices
(Comp_Assn
)) /= 1
3305 Nkind
(First
(Choices
(Comp_Assn
))) /= N_Identifier
3307 Error_Msg_Name_1
:= Nam
;
3309 ("wrong syntax for aspect `%` for &", Id
, E
);
3314 Make_Pragma_Argument_Association
(Sloc
(Comp_Assn
),
3315 Chars
=> Chars
(First
(Choices
(Comp_Assn
))),
3317 Relocate_Node
(Expression
(Comp_Assn
))));
3321 -- Build the test-case pragma
3324 (Pragma_Argument_Associations
=> Args
,
3325 Pragma_Name
=> Nam
);
3330 when Aspect_Contract_Cases
=>
3332 (Pragma_Argument_Associations
=> New_List
(
3333 Make_Pragma_Argument_Association
(Loc
,
3334 Expression
=> Relocate_Node
(Expr
))),
3335 Pragma_Name
=> Nam
);
3337 Decorate
(Aspect
, Aitem
);
3338 Insert_Pragma
(Aitem
);
3341 -- Case 5: Special handling for aspects with an optional
3342 -- boolean argument.
3344 -- In the delayed case, the corresponding pragma cannot be
3345 -- generated yet because the evaluation of the boolean needs
3346 -- to be delayed till the freeze point.
3348 when Boolean_Aspects |
3349 Library_Unit_Aspects
=>
3351 Set_Is_Boolean_Aspect
(Aspect
);
3353 -- Lock_Free aspect only apply to protected objects
3355 if A_Id
= Aspect_Lock_Free
then
3356 if Ekind
(E
) /= E_Protected_Type
then
3357 Error_Msg_Name_1
:= Nam
;
3359 ("aspect % only applies to a protected object",
3363 -- Set the Uses_Lock_Free flag to True if there is no
3364 -- expression or if the expression is True. The
3365 -- evaluation of this aspect should be delayed to the
3366 -- freeze point (why???)
3369 or else Is_True
(Static_Boolean
(Expr
))
3371 Set_Uses_Lock_Free
(E
);
3374 Record_Rep_Item
(E
, Aspect
);
3379 elsif A_Id
= Aspect_Export
or else A_Id
= Aspect_Import
then
3380 Analyze_Aspect_Export_Import
;
3382 -- Disable_Controlled
3384 elsif A_Id
= Aspect_Disable_Controlled
then
3385 if Ekind
(E
) /= E_Record_Type
3386 or else not Is_Controlled
(E
)
3389 ("aspect % requires controlled record type", Aspect
);
3393 -- If we're in a generic template, we don't want to try
3394 -- to disable controlled types, because typical usage is
3395 -- "Disable_Controlled => not <some_check>'Enabled", and
3396 -- the value of Enabled is not known until we see a
3397 -- particular instance. In such a context, we just need
3398 -- to preanalyze the expression for legality.
3400 if Expander_Active
then
3401 Analyze_And_Resolve
(Expr
, Standard_Boolean
);
3403 if not Present
(Expr
)
3404 or else Is_True
(Static_Boolean
(Expr
))
3406 Set_Disable_Controlled
(E
);
3409 elsif Serious_Errors_Detected
= 0 then
3410 Preanalyze_And_Resolve
(Expr
, Standard_Boolean
);
3416 -- Library unit aspects require special handling in the case
3417 -- of a package declaration, the pragma needs to be inserted
3418 -- in the list of declarations for the associated package.
3419 -- There is no issue of visibility delay for these aspects.
3421 if A_Id
in Library_Unit_Aspects
3423 Nkind_In
(N
, N_Package_Declaration
,
3424 N_Generic_Package_Declaration
)
3425 and then Nkind
(Parent
(N
)) /= N_Compilation_Unit
3427 -- Aspect is legal on a local instantiation of a library-
3428 -- level generic unit.
3430 and then not Is_Generic_Instance
(Defining_Entity
(N
))
3433 ("incorrect context for library unit aspect&", Id
);
3437 -- Cases where we do not delay, includes all cases where the
3438 -- expression is missing other than the above cases.
3440 if not Delay_Required
or else No
(Expr
) then
3442 -- Exclude aspects Export and Import because their pragma
3443 -- syntax does not map directly to a Boolean aspect.
3445 if A_Id
/= Aspect_Export
3446 and then A_Id
/= Aspect_Import
3449 (Pragma_Argument_Associations
=> New_List
(
3450 Make_Pragma_Argument_Association
(Sloc
(Ent
),
3451 Expression
=> Ent
)),
3452 Pragma_Name
=> Chars
(Id
));
3455 Delay_Required
:= False;
3457 -- In general cases, the corresponding pragma/attribute
3458 -- definition clause will be inserted later at the freezing
3459 -- point, and we do not need to build it now.
3467 -- This is special because for access types we need to generate
3468 -- an attribute definition clause. This also works for single
3469 -- task declarations, but it does not work for task type
3470 -- declarations, because we have the case where the expression
3471 -- references a discriminant of the task type. That can't use
3472 -- an attribute definition clause because we would not have
3473 -- visibility on the discriminant. For that case we must
3474 -- generate a pragma in the task definition.
3476 when Aspect_Storage_Size
=>
3480 if Ekind
(E
) = E_Task_Type
then
3482 Decl
: constant Node_Id
:= Declaration_Node
(E
);
3485 pragma Assert
(Nkind
(Decl
) = N_Task_Type_Declaration
);
3487 -- If no task definition, create one
3489 if No
(Task_Definition
(Decl
)) then
3490 Set_Task_Definition
(Decl
,
3491 Make_Task_Definition
(Loc
,
3492 Visible_Declarations
=> Empty_List
,
3493 End_Label
=> Empty
));
3496 -- Create a pragma and put it at the start of the task
3497 -- definition for the task type declaration.
3500 (Pragma_Argument_Associations
=> New_List
(
3501 Make_Pragma_Argument_Association
(Loc
,
3502 Expression
=> Relocate_Node
(Expr
))),
3503 Pragma_Name
=> Name_Storage_Size
);
3507 Visible_Declarations
(Task_Definition
(Decl
)));
3511 -- All other cases, generate attribute definition
3515 Make_Attribute_Definition_Clause
(Loc
,
3517 Chars
=> Chars
(Id
),
3518 Expression
=> Relocate_Node
(Expr
));
3522 -- Attach the corresponding pragma/attribute definition clause to
3523 -- the aspect specification node.
3525 if Present
(Aitem
) then
3526 Set_From_Aspect_Specification
(Aitem
);
3529 -- In the context of a compilation unit, we directly put the
3530 -- pragma in the Pragmas_After list of the N_Compilation_Unit_Aux
3531 -- node (no delay is required here) except for aspects on a
3532 -- subprogram body (see below) and a generic package, for which we
3533 -- need to introduce the pragma before building the generic copy
3534 -- (see sem_ch12), and for package instantiations, where the
3535 -- library unit pragmas are better handled early.
3537 if Nkind
(Parent
(N
)) = N_Compilation_Unit
3538 and then (Present
(Aitem
) or else Is_Boolean_Aspect
(Aspect
))
3541 Aux
: constant Node_Id
:= Aux_Decls_Node
(Parent
(N
));
3544 pragma Assert
(Nkind
(Aux
) = N_Compilation_Unit_Aux
);
3546 -- For a Boolean aspect, create the corresponding pragma if
3547 -- no expression or if the value is True.
3549 if Is_Boolean_Aspect
(Aspect
) and then No
(Aitem
) then
3550 if Is_True
(Static_Boolean
(Expr
)) then
3552 (Pragma_Argument_Associations
=> New_List
(
3553 Make_Pragma_Argument_Association
(Sloc
(Ent
),
3554 Expression
=> Ent
)),
3555 Pragma_Name
=> Chars
(Id
));
3557 Set_From_Aspect_Specification
(Aitem
, True);
3558 Set_Corresponding_Aspect
(Aitem
, Aspect
);
3565 -- If the aspect is on a subprogram body (relevant aspect
3566 -- is Inline), add the pragma in front of the declarations.
3568 if Nkind
(N
) = N_Subprogram_Body
then
3569 if No
(Declarations
(N
)) then
3570 Set_Declarations
(N
, New_List
);
3573 Prepend
(Aitem
, Declarations
(N
));
3575 elsif Nkind
(N
) = N_Generic_Package_Declaration
then
3576 if No
(Visible_Declarations
(Specification
(N
))) then
3577 Set_Visible_Declarations
(Specification
(N
), New_List
);
3581 Visible_Declarations
(Specification
(N
)));
3583 elsif Nkind
(N
) = N_Package_Instantiation
then
3585 Spec
: constant Node_Id
:=
3586 Specification
(Instance_Spec
(N
));
3588 if No
(Visible_Declarations
(Spec
)) then
3589 Set_Visible_Declarations
(Spec
, New_List
);
3592 Prepend
(Aitem
, Visible_Declarations
(Spec
));
3596 if No
(Pragmas_After
(Aux
)) then
3597 Set_Pragmas_After
(Aux
, New_List
);
3600 Append
(Aitem
, Pragmas_After
(Aux
));
3607 -- The evaluation of the aspect is delayed to the freezing point.
3608 -- The pragma or attribute clause if there is one is then attached
3609 -- to the aspect specification which is put in the rep item list.
3611 if Delay_Required
then
3612 if Present
(Aitem
) then
3613 Set_Is_Delayed_Aspect
(Aitem
);
3614 Set_Aspect_Rep_Item
(Aspect
, Aitem
);
3615 Set_Parent
(Aitem
, Aspect
);
3618 Set_Is_Delayed_Aspect
(Aspect
);
3620 -- In the case of Default_Value, link the aspect to base type
3621 -- as well, even though it appears on a first subtype. This is
3622 -- mandated by the semantics of the aspect. Do not establish
3623 -- the link when processing the base type itself as this leads
3624 -- to a rep item circularity. Verify that we are dealing with
3625 -- a scalar type to prevent cascaded errors.
3627 if A_Id
= Aspect_Default_Value
3628 and then Is_Scalar_Type
(E
)
3629 and then Base_Type
(E
) /= E
3631 Set_Has_Delayed_Aspects
(Base_Type
(E
));
3632 Record_Rep_Item
(Base_Type
(E
), Aspect
);
3635 Set_Has_Delayed_Aspects
(E
);
3636 Record_Rep_Item
(E
, Aspect
);
3638 -- When delay is not required and the context is a package or a
3639 -- subprogram body, insert the pragma in the body declarations.
3641 elsif Nkind_In
(N
, N_Package_Body
, N_Subprogram_Body
) then
3642 if No
(Declarations
(N
)) then
3643 Set_Declarations
(N
, New_List
);
3646 -- The pragma is added before source declarations
3648 Prepend_To
(Declarations
(N
), Aitem
);
3650 -- When delay is not required and the context is not a compilation
3651 -- unit, we simply insert the pragma/attribute definition clause
3654 elsif Present
(Aitem
) then
3655 Insert_After
(Ins_Node
, Aitem
);
3658 end Analyze_One_Aspect
;
3662 end loop Aspect_Loop
;
3664 if Has_Delayed_Aspects
(E
) then
3665 Ensure_Freeze_Node
(E
);
3667 end Analyze_Aspect_Specifications
;
3669 ---------------------------------------------------
3670 -- Analyze_Aspect_Specifications_On_Body_Or_Stub --
3671 ---------------------------------------------------
3673 procedure Analyze_Aspect_Specifications_On_Body_Or_Stub
(N
: Node_Id
) is
3674 Body_Id
: constant Entity_Id
:= Defining_Entity
(N
);
3676 procedure Diagnose_Misplaced_Aspects
(Spec_Id
: Entity_Id
);
3677 -- Body [stub] N has aspects, but they are not properly placed. Emit an
3678 -- error message depending on the aspects involved. Spec_Id denotes the
3679 -- entity of the corresponding spec.
3681 --------------------------------
3682 -- Diagnose_Misplaced_Aspects --
3683 --------------------------------
3685 procedure Diagnose_Misplaced_Aspects
(Spec_Id
: Entity_Id
) is
3686 procedure Misplaced_Aspect_Error
3689 -- Emit an error message concerning misplaced aspect Asp. Ref_Nam is
3690 -- the name of the refined version of the aspect.
3692 ----------------------------
3693 -- Misplaced_Aspect_Error --
3694 ----------------------------
3696 procedure Misplaced_Aspect_Error
3700 Asp_Nam
: constant Name_Id
:= Chars
(Identifier
(Asp
));
3701 Asp_Id
: constant Aspect_Id
:= Get_Aspect_Id
(Asp_Nam
);
3704 -- The corresponding spec already contains the aspect in question
3705 -- and the one appearing on the body must be the refined form:
3707 -- procedure P with Global ...;
3708 -- procedure P with Global ... is ... end P;
3712 if Has_Aspect
(Spec_Id
, Asp_Id
) then
3713 Error_Msg_Name_1
:= Asp_Nam
;
3715 -- Subunits cannot carry aspects that apply to a subprogram
3718 if Nkind
(Parent
(N
)) = N_Subunit
then
3719 Error_Msg_N
("aspect % cannot apply to a subunit", Asp
);
3721 -- Otherwise suggest the refined form
3724 Error_Msg_Name_2
:= Ref_Nam
;
3725 Error_Msg_N
("aspect % should be %", Asp
);
3728 -- Otherwise the aspect must appear on the spec, not on the body
3731 -- procedure P with Global ... is ... end P;
3735 ("aspect specification must appear on initial declaration",
3738 end Misplaced_Aspect_Error
;
3745 -- Start of processing for Diagnose_Misplaced_Aspects
3748 -- Iterate over the aspect specifications and emit specific errors
3749 -- where applicable.
3751 Asp
:= First
(Aspect_Specifications
(N
));
3752 while Present
(Asp
) loop
3753 Asp_Nam
:= Chars
(Identifier
(Asp
));
3755 -- Do not emit errors on aspects that can appear on a subprogram
3756 -- body. This scenario occurs when the aspect specification list
3757 -- contains both misplaced and properly placed aspects.
3759 if Aspect_On_Body_Or_Stub_OK
(Get_Aspect_Id
(Asp_Nam
)) then
3762 -- Special diagnostics for SPARK aspects
3764 elsif Asp_Nam
= Name_Depends
then
3765 Misplaced_Aspect_Error
(Asp
, Name_Refined_Depends
);
3767 elsif Asp_Nam
= Name_Global
then
3768 Misplaced_Aspect_Error
(Asp
, Name_Refined_Global
);
3770 elsif Asp_Nam
= Name_Post
then
3771 Misplaced_Aspect_Error
(Asp
, Name_Refined_Post
);
3773 -- Otherwise a language-defined aspect is misplaced
3777 ("aspect specification must appear on initial declaration",
3783 end Diagnose_Misplaced_Aspects
;
3787 Spec_Id
: constant Entity_Id
:= Unique_Defining_Entity
(N
);
3789 -- Start of processing for Analyze_Aspects_On_Body_Or_Stub
3792 -- Language-defined aspects cannot be associated with a subprogram body
3793 -- [stub] if the subprogram has a spec. Certain implementation defined
3794 -- aspects are allowed to break this rule (for all applicable cases, see
3795 -- table Aspects.Aspect_On_Body_Or_Stub_OK).
3797 if Spec_Id
/= Body_Id
and then not Aspects_On_Body_Or_Stub_OK
(N
) then
3798 Diagnose_Misplaced_Aspects
(Spec_Id
);
3800 Analyze_Aspect_Specifications
(N
, Body_Id
);
3802 end Analyze_Aspect_Specifications_On_Body_Or_Stub
;
3804 -----------------------
3805 -- Analyze_At_Clause --
3806 -----------------------
3808 -- An at clause is replaced by the corresponding Address attribute
3809 -- definition clause that is the preferred approach in Ada 95.
3811 procedure Analyze_At_Clause
(N
: Node_Id
) is
3812 CS
: constant Boolean := Comes_From_Source
(N
);
3815 -- This is an obsolescent feature
3817 Check_Restriction
(No_Obsolescent_Features
, N
);
3819 if Warn_On_Obsolescent_Feature
then
3821 ("?j?at clause is an obsolescent feature (RM J.7(2))", N
);
3823 ("\?j?use address attribute definition clause instead", N
);
3826 -- Rewrite as address clause
3829 Make_Attribute_Definition_Clause
(Sloc
(N
),
3830 Name
=> Identifier
(N
),
3831 Chars
=> Name_Address
,
3832 Expression
=> Expression
(N
)));
3834 -- We preserve Comes_From_Source, since logically the clause still comes
3835 -- from the source program even though it is changed in form.
3837 Set_Comes_From_Source
(N
, CS
);
3839 -- Analyze rewritten clause
3841 Analyze_Attribute_Definition_Clause
(N
);
3842 end Analyze_At_Clause
;
3844 -----------------------------------------
3845 -- Analyze_Attribute_Definition_Clause --
3846 -----------------------------------------
3848 procedure Analyze_Attribute_Definition_Clause
(N
: Node_Id
) is
3849 Loc
: constant Source_Ptr
:= Sloc
(N
);
3850 Nam
: constant Node_Id
:= Name
(N
);
3851 Attr
: constant Name_Id
:= Chars
(N
);
3852 Expr
: constant Node_Id
:= Expression
(N
);
3853 Id
: constant Attribute_Id
:= Get_Attribute_Id
(Attr
);
3856 -- The entity of Nam after it is analyzed. In the case of an incomplete
3857 -- type, this is the underlying type.
3860 -- The underlying entity to which the attribute applies. Generally this
3861 -- is the Underlying_Type of Ent, except in the case where the clause
3862 -- applies to the full view of an incomplete or private type, in which
3863 -- case U_Ent is just a copy of Ent.
3865 FOnly
: Boolean := False;
3866 -- Reset to True for subtype specific attribute (Alignment, Size)
3867 -- and for stream attributes, i.e. those cases where in the call to
3868 -- Rep_Item_Too_Late, FOnly is set True so that only the freezing rules
3869 -- are checked. Note that the case of stream attributes is not clear
3870 -- from the RM, but see AI95-00137. Also, the RM seems to disallow
3871 -- Storage_Size for derived task types, but that is also clearly
3874 procedure Analyze_Stream_TSS_Definition
(TSS_Nam
: TSS_Name_Type
);
3875 -- Common processing for 'Read, 'Write, 'Input and 'Output attribute
3876 -- definition clauses.
3878 function Duplicate_Clause
return Boolean;
3879 -- This routine checks if the aspect for U_Ent being given by attribute
3880 -- definition clause N is for an aspect that has already been specified,
3881 -- and if so gives an error message. If there is a duplicate, True is
3882 -- returned, otherwise if there is no error, False is returned.
3884 procedure Check_Indexing_Functions
;
3885 -- Check that the function in Constant_Indexing or Variable_Indexing
3886 -- attribute has the proper type structure. If the name is overloaded,
3887 -- check that some interpretation is legal.
3889 procedure Check_Iterator_Functions
;
3890 -- Check that there is a single function in Default_Iterator attribute
3891 -- has the proper type structure.
3893 function Check_Primitive_Function
(Subp
: Entity_Id
) return Boolean;
3894 -- Common legality check for the previous two
3896 -----------------------------------
3897 -- Analyze_Stream_TSS_Definition --
3898 -----------------------------------
3900 procedure Analyze_Stream_TSS_Definition
(TSS_Nam
: TSS_Name_Type
) is
3901 Subp
: Entity_Id
:= Empty
;
3906 Is_Read
: constant Boolean := (TSS_Nam
= TSS_Stream_Read
);
3907 -- True for Read attribute, False for other attributes
3909 function Has_Good_Profile
3911 Report
: Boolean := False) return Boolean;
3912 -- Return true if the entity is a subprogram with an appropriate
3913 -- profile for the attribute being defined. If result is False and
3914 -- Report is True, function emits appropriate error.
3916 ----------------------
3917 -- Has_Good_Profile --
3918 ----------------------
3920 function Has_Good_Profile
3922 Report
: Boolean := False) return Boolean
3924 Expected_Ekind
: constant array (Boolean) of Entity_Kind
:=
3925 (False => E_Procedure
, True => E_Function
);
3926 Is_Function
: constant Boolean := (TSS_Nam
= TSS_Stream_Input
);
3931 if Ekind
(Subp
) /= Expected_Ekind
(Is_Function
) then
3935 F
:= First_Formal
(Subp
);
3938 or else Ekind
(Etype
(F
)) /= E_Anonymous_Access_Type
3939 or else Designated_Type
(Etype
(F
)) /=
3940 Class_Wide_Type
(RTE
(RE_Root_Stream_Type
))
3945 if not Is_Function
then
3949 Expected_Mode
: constant array (Boolean) of Entity_Kind
:=
3950 (False => E_In_Parameter
,
3951 True => E_Out_Parameter
);
3953 if Parameter_Mode
(F
) /= Expected_Mode
(Is_Read
) then
3960 -- If the attribute specification comes from an aspect
3961 -- specification for a class-wide stream, the parameter must be
3962 -- a class-wide type of the entity to which the aspect applies.
3964 if From_Aspect_Specification
(N
)
3965 and then Class_Present
(Parent
(N
))
3966 and then Is_Class_Wide_Type
(Typ
)
3972 Typ
:= Etype
(Subp
);
3975 -- Verify that the prefix of the attribute and the local name for
3976 -- the type of the formal match, or one is the class-wide of the
3977 -- other, in the case of a class-wide stream operation.
3979 if Base_Type
(Typ
) = Base_Type
(Ent
)
3980 or else (Is_Class_Wide_Type
(Typ
)
3981 and then Typ
= Class_Wide_Type
(Base_Type
(Ent
)))
3982 or else (Is_Class_Wide_Type
(Ent
)
3983 and then Ent
= Class_Wide_Type
(Base_Type
(Typ
)))
3990 if Present
(Next_Formal
(F
)) then
3993 elsif not Is_Scalar_Type
(Typ
)
3994 and then not Is_First_Subtype
(Typ
)
3995 and then not Is_Class_Wide_Type
(Typ
)
3997 if Report
and not Is_First_Subtype
(Typ
) then
3999 ("subtype of formal in stream operation must be a first "
4000 & "subtype", Parameter_Type
(Parent
(F
)));
4008 end Has_Good_Profile
;
4010 -- Start of processing for Analyze_Stream_TSS_Definition
4015 if not Is_Type
(U_Ent
) then
4016 Error_Msg_N
("local name must be a subtype", Nam
);
4019 elsif not Is_First_Subtype
(U_Ent
) then
4020 Error_Msg_N
("local name must be a first subtype", Nam
);
4024 Pnam
:= TSS
(Base_Type
(U_Ent
), TSS_Nam
);
4026 -- If Pnam is present, it can be either inherited from an ancestor
4027 -- type (in which case it is legal to redefine it for this type), or
4028 -- be a previous definition of the attribute for the same type (in
4029 -- which case it is illegal).
4031 -- In the first case, it will have been analyzed already, and we
4032 -- can check that its profile does not match the expected profile
4033 -- for a stream attribute of U_Ent. In the second case, either Pnam
4034 -- has been analyzed (and has the expected profile), or it has not
4035 -- been analyzed yet (case of a type that has not been frozen yet
4036 -- and for which the stream attribute has been set using Set_TSS).
4039 and then (No
(First_Entity
(Pnam
)) or else Has_Good_Profile
(Pnam
))
4041 Error_Msg_Sloc
:= Sloc
(Pnam
);
4042 Error_Msg_Name_1
:= Attr
;
4043 Error_Msg_N
("% attribute already defined #", Nam
);
4049 if Is_Entity_Name
(Expr
) then
4050 if not Is_Overloaded
(Expr
) then
4051 if Has_Good_Profile
(Entity
(Expr
), Report
=> True) then
4052 Subp
:= Entity
(Expr
);
4056 Get_First_Interp
(Expr
, I
, It
);
4057 while Present
(It
.Nam
) loop
4058 if Has_Good_Profile
(It
.Nam
) then
4063 Get_Next_Interp
(I
, It
);
4068 if Present
(Subp
) then
4069 if Is_Abstract_Subprogram
(Subp
) then
4070 Error_Msg_N
("stream subprogram must not be abstract", Expr
);
4073 -- A stream subprogram for an interface type must be a null
4074 -- procedure (RM 13.13.2 (38/3)). Note that the class-wide type
4075 -- of an interface is not an interface type (3.9.4 (6.b/2)).
4077 elsif Is_Interface
(U_Ent
)
4078 and then not Is_Class_Wide_Type
(U_Ent
)
4079 and then not Inside_A_Generic
4081 (Ekind
(Subp
) = E_Function
4085 (Unit_Declaration_Node
(Ultimate_Alias
(Subp
)))))
4088 ("stream subprogram for interface type must be null "
4089 & "procedure", Expr
);
4092 Set_Entity
(Expr
, Subp
);
4093 Set_Etype
(Expr
, Etype
(Subp
));
4095 New_Stream_Subprogram
(N
, U_Ent
, Subp
, TSS_Nam
);
4098 Error_Msg_Name_1
:= Attr
;
4099 Error_Msg_N
("incorrect expression for% attribute", Expr
);
4101 end Analyze_Stream_TSS_Definition
;
4103 ------------------------------
4104 -- Check_Indexing_Functions --
4105 ------------------------------
4107 procedure Check_Indexing_Functions
is
4108 Indexing_Found
: Boolean := False;
4110 procedure Check_Inherited_Indexing
;
4111 -- For a derived type, check that no indexing aspect is specified
4112 -- for the type if it is also inherited
4114 procedure Check_One_Function
(Subp
: Entity_Id
);
4115 -- Check one possible interpretation. Sets Indexing_Found True if a
4116 -- legal indexing function is found.
4118 procedure Illegal_Indexing
(Msg
: String);
4119 -- Diagnose illegal indexing function if not overloaded. In the
4120 -- overloaded case indicate that no legal interpretation exists.
4122 ------------------------------
4123 -- Check_Inherited_Indexing --
4124 ------------------------------
4126 procedure Check_Inherited_Indexing
is
4127 Inherited
: Node_Id
;
4130 if Attr
= Name_Constant_Indexing
then
4132 Find_Aspect
(Etype
(Ent
), Aspect_Constant_Indexing
);
4133 else pragma Assert
(Attr
= Name_Variable_Indexing
);
4135 Find_Aspect
(Etype
(Ent
), Aspect_Variable_Indexing
);
4138 if Present
(Inherited
) then
4139 if Debug_Flag_Dot_XX
then
4142 -- OK if current attribute_definition_clause is expansion of
4143 -- inherited aspect.
4145 elsif Aspect_Rep_Item
(Inherited
) = N
then
4148 -- Indicate the operation that must be overridden, rather than
4149 -- redefining the indexing aspect.
4153 ("indexing function already inherited from parent type");
4155 ("!override & instead",
4156 N
, Entity
(Expression
(Inherited
)));
4159 end Check_Inherited_Indexing
;
4161 ------------------------
4162 -- Check_One_Function --
4163 ------------------------
4165 procedure Check_One_Function
(Subp
: Entity_Id
) is
4166 Default_Element
: Node_Id
;
4167 Ret_Type
: constant Entity_Id
:= Etype
(Subp
);
4170 if not Is_Overloadable
(Subp
) then
4171 Illegal_Indexing
("illegal indexing function for type&");
4174 elsif Scope
(Subp
) /= Scope
(Ent
) then
4175 if Nkind
(Expr
) = N_Expanded_Name
then
4177 -- Indexing function can't be declared elsewhere
4180 ("indexing function must be declared in scope of type&");
4185 elsif No
(First_Formal
(Subp
)) then
4187 ("Indexing requires a function that applies to type&");
4190 elsif No
(Next_Formal
(First_Formal
(Subp
))) then
4192 ("indexing function must have at least two parameters");
4195 elsif Is_Derived_Type
(Ent
) then
4196 Check_Inherited_Indexing
;
4199 if not Check_Primitive_Function
(Subp
) then
4201 ("Indexing aspect requires a function that applies to type&");
4205 -- If partial declaration exists, verify that it is not tagged.
4207 if Ekind
(Current_Scope
) = E_Package
4208 and then Has_Private_Declaration
(Ent
)
4209 and then From_Aspect_Specification
(N
)
4211 List_Containing
(Parent
(Ent
)) =
4212 Private_Declarations
4213 (Specification
(Unit_Declaration_Node
(Current_Scope
)))
4214 and then Nkind
(N
) = N_Attribute_Definition_Clause
4221 First
(Visible_Declarations
4223 (Unit_Declaration_Node
(Current_Scope
))));
4225 while Present
(Decl
) loop
4226 if Nkind
(Decl
) = N_Private_Type_Declaration
4227 and then Ent
= Full_View
(Defining_Identifier
(Decl
))
4228 and then Tagged_Present
(Decl
)
4229 and then No
(Aspect_Specifications
(Decl
))
4232 ("Indexing aspect cannot be specified on full view "
4233 & "if partial view is tagged");
4242 -- An indexing function must return either the default element of
4243 -- the container, or a reference type. For variable indexing it
4244 -- must be the latter.
4247 Find_Value_Of_Aspect
4248 (Etype
(First_Formal
(Subp
)), Aspect_Iterator_Element
);
4250 if Present
(Default_Element
) then
4251 Analyze
(Default_Element
);
4253 if Is_Entity_Name
(Default_Element
)
4254 and then not Covers
(Entity
(Default_Element
), Ret_Type
)
4258 ("wrong return type for indexing function");
4263 -- For variable_indexing the return type must be a reference type
4265 if Attr
= Name_Variable_Indexing
then
4266 if not Has_Implicit_Dereference
(Ret_Type
) then
4268 ("variable indexing must return a reference type");
4271 elsif Is_Access_Constant
4272 (Etype
(First_Discriminant
(Ret_Type
)))
4275 ("variable indexing must return an access to variable");
4280 if Has_Implicit_Dereference
(Ret_Type
)
4282 Is_Access_Constant
(Etype
(First_Discriminant
(Ret_Type
)))
4285 ("constant indexing must return an access to constant");
4288 elsif Is_Access_Type
(Etype
(First_Formal
(Subp
)))
4289 and then not Is_Access_Constant
(Etype
(First_Formal
(Subp
)))
4292 ("constant indexing must apply to an access to constant");
4297 -- All checks succeeded.
4299 Indexing_Found
:= True;
4300 end Check_One_Function
;
4302 -----------------------
4303 -- Illegal_Indexing --
4304 -----------------------
4306 procedure Illegal_Indexing
(Msg
: String) is
4308 Error_Msg_NE
(Msg
, N
, Ent
);
4309 end Illegal_Indexing
;
4311 -- Start of processing for Check_Indexing_Functions
4315 Check_Inherited_Indexing
;
4320 if not Is_Overloaded
(Expr
) then
4321 Check_One_Function
(Entity
(Expr
));
4329 Indexing_Found
:= False;
4330 Get_First_Interp
(Expr
, I
, It
);
4331 while Present
(It
.Nam
) loop
4333 -- Note that analysis will have added the interpretation
4334 -- that corresponds to the dereference. We only check the
4335 -- subprogram itself.
4337 if Is_Overloadable
(It
.Nam
) then
4338 Check_One_Function
(It
.Nam
);
4341 Get_Next_Interp
(I
, It
);
4346 if not Indexing_Found
and then not Error_Posted
(N
) then
4348 ("aspect Indexing requires a local function that "
4349 & "applies to type&", Expr
, Ent
);
4351 end Check_Indexing_Functions
;
4353 ------------------------------
4354 -- Check_Iterator_Functions --
4355 ------------------------------
4357 procedure Check_Iterator_Functions
is
4358 function Valid_Default_Iterator
(Subp
: Entity_Id
) return Boolean;
4359 -- Check one possible interpretation for validity
4361 ----------------------------
4362 -- Valid_Default_Iterator --
4363 ----------------------------
4365 function Valid_Default_Iterator
(Subp
: Entity_Id
) return Boolean is
4366 Root_T
: constant Entity_Id
:= Root_Type
(Etype
(Etype
(Subp
)));
4370 if not Check_Primitive_Function
(Subp
) then
4373 -- The return type must be derived from a type in an instance
4374 -- of Iterator.Interfaces, and thus its root type must have a
4377 elsif Chars
(Root_T
) /= Name_Forward_Iterator
4378 and then Chars
(Root_T
) /= Name_Reversible_Iterator
4383 Formal
:= First_Formal
(Subp
);
4386 -- False if any subsequent formal has no default expression
4388 Formal
:= Next_Formal
(Formal
);
4389 while Present
(Formal
) loop
4390 if No
(Expression
(Parent
(Formal
))) then
4394 Next_Formal
(Formal
);
4397 -- True if all subsequent formals have default expressions
4400 end Valid_Default_Iterator
;
4402 -- Start of processing for Check_Iterator_Functions
4407 if not Is_Entity_Name
(Expr
) then
4408 Error_Msg_N
("aspect Iterator must be a function name", Expr
);
4411 if not Is_Overloaded
(Expr
) then
4412 if not Check_Primitive_Function
(Entity
(Expr
)) then
4414 ("aspect Indexing requires a function that applies to type&",
4415 Entity
(Expr
), Ent
);
4418 -- Flag the default_iterator as well as the denoted function.
4420 if not Valid_Default_Iterator
(Entity
(Expr
)) then
4421 Error_Msg_N
("improper function for default iterator!", Expr
);
4426 Default
: Entity_Id
:= Empty
;
4431 Get_First_Interp
(Expr
, I
, It
);
4432 while Present
(It
.Nam
) loop
4433 if not Check_Primitive_Function
(It
.Nam
)
4434 or else not Valid_Default_Iterator
(It
.Nam
)
4438 elsif Present
(Default
) then
4440 -- An explicit one should override an implicit one
4442 if Comes_From_Source
(Default
) =
4443 Comes_From_Source
(It
.Nam
)
4445 Error_Msg_N
("default iterator must be unique", Expr
);
4446 Error_Msg_Sloc
:= Sloc
(Default
);
4447 Error_Msg_N
("\\possible interpretation#", Expr
);
4448 Error_Msg_Sloc
:= Sloc
(It
.Nam
);
4449 Error_Msg_N
("\\possible interpretation#", Expr
);
4451 elsif Comes_From_Source
(It
.Nam
) then
4458 Get_Next_Interp
(I
, It
);
4461 if Present
(Default
) then
4462 Set_Entity
(Expr
, Default
);
4463 Set_Is_Overloaded
(Expr
, False);
4466 ("no interpretation is a valid default iterator!", Expr
);
4470 end Check_Iterator_Functions
;
4472 -------------------------------
4473 -- Check_Primitive_Function --
4474 -------------------------------
4476 function Check_Primitive_Function
(Subp
: Entity_Id
) return Boolean is
4480 if Ekind
(Subp
) /= E_Function
then
4484 if No
(First_Formal
(Subp
)) then
4487 Ctrl
:= Etype
(First_Formal
(Subp
));
4490 -- To be a primitive operation subprogram has to be in same scope.
4492 if Scope
(Ctrl
) /= Scope
(Subp
) then
4496 -- Type of formal may be the class-wide type, an access to such,
4497 -- or an incomplete view.
4500 or else Ctrl
= Class_Wide_Type
(Ent
)
4502 (Ekind
(Ctrl
) = E_Anonymous_Access_Type
4503 and then (Designated_Type
(Ctrl
) = Ent
4505 Designated_Type
(Ctrl
) = Class_Wide_Type
(Ent
)))
4507 (Ekind
(Ctrl
) = E_Incomplete_Type
4508 and then Full_View
(Ctrl
) = Ent
)
4516 end Check_Primitive_Function
;
4518 ----------------------
4519 -- Duplicate_Clause --
4520 ----------------------
4522 function Duplicate_Clause
return Boolean is
4526 -- Nothing to do if this attribute definition clause comes from
4527 -- an aspect specification, since we could not be duplicating an
4528 -- explicit clause, and we dealt with the case of duplicated aspects
4529 -- in Analyze_Aspect_Specifications.
4531 if From_Aspect_Specification
(N
) then
4535 -- Otherwise current clause may duplicate previous clause, or a
4536 -- previously given pragma or aspect specification for the same
4539 A
:= Get_Rep_Item
(U_Ent
, Chars
(N
), Check_Parents
=> False);
4542 Error_Msg_Name_1
:= Chars
(N
);
4543 Error_Msg_Sloc
:= Sloc
(A
);
4545 Error_Msg_NE
("aspect% for & previously given#", N
, U_Ent
);
4550 end Duplicate_Clause
;
4552 -- Start of processing for Analyze_Attribute_Definition_Clause
4555 -- The following code is a defense against recursion. Not clear that
4556 -- this can happen legitimately, but perhaps some error situations can
4557 -- cause it, and we did see this recursion during testing.
4559 if Analyzed
(N
) then
4562 Set_Analyzed
(N
, True);
4565 Check_Restriction_No_Use_Of_Attribute
(N
);
4567 -- Ignore some selected attributes in CodePeer mode since they are not
4568 -- relevant in this context.
4570 if CodePeer_Mode
then
4573 -- Ignore Component_Size in CodePeer mode, to avoid changing the
4574 -- internal representation of types by implicitly packing them.
4576 when Attribute_Component_Size
=>
4577 Rewrite
(N
, Make_Null_Statement
(Sloc
(N
)));
4585 -- Process Ignore_Rep_Clauses option
4587 if Ignore_Rep_Clauses
then
4590 -- The following should be ignored. They do not affect legality
4591 -- and may be target dependent. The basic idea of -gnatI is to
4592 -- ignore any rep clauses that may be target dependent but do not
4593 -- affect legality (except possibly to be rejected because they
4594 -- are incompatible with the compilation target).
4596 when Attribute_Alignment |
4597 Attribute_Bit_Order |
4598 Attribute_Component_Size |
4599 Attribute_Machine_Radix |
4600 Attribute_Object_Size |
4603 Attribute_Stream_Size |
4604 Attribute_Value_Size
=>
4605 Kill_Rep_Clause
(N
);
4608 -- The following should not be ignored, because in the first place
4609 -- they are reasonably portable, and should not cause problems
4610 -- in compiling code from another target, and also they do affect
4611 -- legality, e.g. failing to provide a stream attribute for a type
4612 -- may make a program illegal.
4614 when Attribute_External_Tag |
4618 Attribute_Simple_Storage_Pool |
4619 Attribute_Storage_Pool |
4620 Attribute_Storage_Size |
4624 -- We do not do anything here with address clauses, they will be
4625 -- removed by Freeze later on, but for now, it works better to
4626 -- keep then in the tree.
4628 when Attribute_Address
=>
4631 -- Other cases are errors ("attribute& cannot be set with
4632 -- definition clause"), which will be caught below.
4640 Ent
:= Entity
(Nam
);
4642 if Rep_Item_Too_Early
(Ent
, N
) then
4646 -- Rep clause applies to full view of incomplete type or private type if
4647 -- we have one (if not, this is a premature use of the type). However,
4648 -- certain semantic checks need to be done on the specified entity (i.e.
4649 -- the private view), so we save it in Ent.
4651 if Is_Private_Type
(Ent
)
4652 and then Is_Derived_Type
(Ent
)
4653 and then not Is_Tagged_Type
(Ent
)
4654 and then No
(Full_View
(Ent
))
4656 -- If this is a private type whose completion is a derivation from
4657 -- another private type, there is no full view, and the attribute
4658 -- belongs to the type itself, not its underlying parent.
4662 elsif Ekind
(Ent
) = E_Incomplete_Type
then
4664 -- The attribute applies to the full view, set the entity of the
4665 -- attribute definition accordingly.
4667 Ent
:= Underlying_Type
(Ent
);
4669 Set_Entity
(Nam
, Ent
);
4672 U_Ent
:= Underlying_Type
(Ent
);
4675 -- Avoid cascaded error
4677 if Etype
(Nam
) = Any_Type
then
4680 -- Must be declared in current scope or in case of an aspect
4681 -- specification, must be visible in current scope.
4683 elsif Scope
(Ent
) /= Current_Scope
4685 not (From_Aspect_Specification
(N
)
4686 and then Scope_Within_Or_Same
(Current_Scope
, Scope
(Ent
)))
4688 Error_Msg_N
("entity must be declared in this scope", Nam
);
4691 -- Must not be a source renaming (we do have some cases where the
4692 -- expander generates a renaming, and those cases are OK, in such
4693 -- cases any attribute applies to the renamed object as well).
4695 elsif Is_Object
(Ent
)
4696 and then Present
(Renamed_Object
(Ent
))
4698 -- Case of renamed object from source, this is an error
4700 if Comes_From_Source
(Renamed_Object
(Ent
)) then
4701 Get_Name_String
(Chars
(N
));
4702 Error_Msg_Strlen
:= Name_Len
;
4703 Error_Msg_String
(1 .. Name_Len
) := Name_Buffer
(1 .. Name_Len
);
4705 ("~ clause not allowed for a renaming declaration "
4706 & "(RM 13.1(6))", Nam
);
4709 -- For the case of a compiler generated renaming, the attribute
4710 -- definition clause applies to the renamed object created by the
4711 -- expander. The easiest general way to handle this is to create a
4712 -- copy of the attribute definition clause for this object.
4714 elsif Is_Entity_Name
(Renamed_Object
(Ent
)) then
4716 Make_Attribute_Definition_Clause
(Loc
,
4718 New_Occurrence_Of
(Entity
(Renamed_Object
(Ent
)), Loc
),
4720 Expression
=> Duplicate_Subexpr
(Expression
(N
))));
4722 -- If the renamed object is not an entity, it must be a dereference
4723 -- of an unconstrained function call, and we must introduce a new
4724 -- declaration to capture the expression. This is needed in the case
4725 -- of 'Alignment, where the original declaration must be rewritten.
4729 (Nkind
(Renamed_Object
(Ent
)) = N_Explicit_Dereference
);
4733 -- If no underlying entity, use entity itself, applies to some
4734 -- previously detected error cases ???
4736 elsif No
(U_Ent
) then
4739 -- Cannot specify for a subtype (exception Object/Value_Size)
4741 elsif Is_Type
(U_Ent
)
4742 and then not Is_First_Subtype
(U_Ent
)
4743 and then Id
/= Attribute_Object_Size
4744 and then Id
/= Attribute_Value_Size
4745 and then not From_At_Mod
(N
)
4747 Error_Msg_N
("cannot specify attribute for subtype", Nam
);
4751 Set_Entity
(N
, U_Ent
);
4753 -- Switch on particular attribute
4761 -- Address attribute definition clause
4763 when Attribute_Address
=> Address
: begin
4765 -- A little error check, catch for X'Address use X'Address;
4767 if Nkind
(Nam
) = N_Identifier
4768 and then Nkind
(Expr
) = N_Attribute_Reference
4769 and then Attribute_Name
(Expr
) = Name_Address
4770 and then Nkind
(Prefix
(Expr
)) = N_Identifier
4771 and then Chars
(Nam
) = Chars
(Prefix
(Expr
))
4774 ("address for & is self-referencing", Prefix
(Expr
), Ent
);
4778 -- Not that special case, carry on with analysis of expression
4780 Analyze_And_Resolve
(Expr
, RTE
(RE_Address
));
4782 -- Even when ignoring rep clauses we need to indicate that the
4783 -- entity has an address clause and thus it is legal to declare
4784 -- it imported. Freeze will get rid of the address clause later.
4786 if Ignore_Rep_Clauses
then
4787 if Ekind_In
(U_Ent
, E_Variable
, E_Constant
) then
4788 Record_Rep_Item
(U_Ent
, N
);
4794 if Duplicate_Clause
then
4797 -- Case of address clause for subprogram
4799 elsif Is_Subprogram
(U_Ent
) then
4800 if Has_Homonym
(U_Ent
) then
4802 ("address clause cannot be given for overloaded "
4803 & "subprogram", Nam
);
4807 -- For subprograms, all address clauses are permitted, and we
4808 -- mark the subprogram as having a deferred freeze so that Gigi
4809 -- will not elaborate it too soon.
4811 -- Above needs more comments, what is too soon about???
4813 Set_Has_Delayed_Freeze
(U_Ent
);
4815 -- Case of address clause for entry
4817 elsif Ekind
(U_Ent
) = E_Entry
then
4818 if Nkind
(Parent
(N
)) = N_Task_Body
then
4820 ("entry address must be specified in task spec", Nam
);
4824 -- For entries, we require a constant address
4826 Check_Constant_Address_Clause
(Expr
, U_Ent
);
4828 -- Special checks for task types
4830 if Is_Task_Type
(Scope
(U_Ent
))
4831 and then Comes_From_Source
(Scope
(U_Ent
))
4834 ("??entry address declared for entry in task type", N
);
4836 ("\??only one task can be declared of this type", N
);
4839 -- Entry address clauses are obsolescent
4841 Check_Restriction
(No_Obsolescent_Features
, N
);
4843 if Warn_On_Obsolescent_Feature
then
4845 ("?j?attaching interrupt to task entry is an obsolescent "
4846 & "feature (RM J.7.1)", N
);
4848 ("\?j?use interrupt procedure instead", N
);
4851 -- Case of an address clause for a controlled object which we
4852 -- consider to be erroneous.
4854 elsif Is_Controlled
(Etype
(U_Ent
))
4855 or else Has_Controlled_Component
(Etype
(U_Ent
))
4858 ("??controlled object& must not be overlaid", Nam
, U_Ent
);
4860 ("\??Program_Error will be raised at run time", Nam
);
4861 Insert_Action
(Declaration_Node
(U_Ent
),
4862 Make_Raise_Program_Error
(Loc
,
4863 Reason
=> PE_Overlaid_Controlled_Object
));
4866 -- Case of address clause for a (non-controlled) object
4868 elsif Ekind_In
(U_Ent
, E_Variable
, E_Constant
) then
4870 Expr
: constant Node_Id
:= Expression
(N
);
4875 -- Exported variables cannot have an address clause, because
4876 -- this cancels the effect of the pragma Export.
4878 if Is_Exported
(U_Ent
) then
4880 ("cannot export object with address clause", Nam
);
4884 Find_Overlaid_Entity
(N
, O_Ent
, Off
);
4886 if Present
(O_Ent
) then
4888 -- If the object overlays a constant object, mark it so
4890 if Is_Constant_Object
(O_Ent
) then
4891 Set_Overlays_Constant
(U_Ent
);
4894 -- If the address clause is of the form:
4896 -- for X'Address use Y'Address;
4900 -- C : constant Address := Y'Address;
4902 -- for X'Address use C;
4904 -- then we make an entry in the table to check the size
4905 -- and alignment of the overlaying variable. But we defer
4906 -- this check till after code generation to take full
4907 -- advantage of the annotation done by the back end.
4909 -- If the entity has a generic type, the check will be
4910 -- performed in the instance if the actual type justifies
4911 -- it, and we do not insert the clause in the table to
4912 -- prevent spurious warnings.
4914 -- Note: we used to test Comes_From_Source and only give
4915 -- this warning for source entities, but we have removed
4916 -- this test. It really seems bogus to generate overlays
4917 -- that would trigger this warning in generated code.
4918 -- Furthermore, by removing the test, we handle the
4919 -- aspect case properly.
4921 if Is_Object
(O_Ent
)
4922 and then not Is_Generic_Type
(Etype
(U_Ent
))
4923 and then Address_Clause_Overlay_Warnings
4925 Address_Clause_Checks
.Append
4926 ((N
, U_Ent
, No_Uint
, O_Ent
, Off
));
4929 -- If this is not an overlay, mark a variable as being
4930 -- volatile to prevent unwanted optimizations. It's a
4931 -- conservative interpretation of RM 13.3(19) for the
4932 -- cases where the compiler cannot detect potential
4933 -- aliasing issues easily and it also covers the case
4934 -- of an absolute address where the volatile aspect is
4935 -- kind of implicit.
4937 if Ekind
(U_Ent
) = E_Variable
then
4938 Set_Treat_As_Volatile
(U_Ent
);
4941 -- Make an entry in the table for an absolute address as
4942 -- above to check that the value is compatible with the
4943 -- alignment of the object.
4946 Addr
: constant Node_Id
:= Address_Value
(Expr
);
4948 if Compile_Time_Known_Value
(Addr
)
4949 and then Address_Clause_Overlay_Warnings
4951 Address_Clause_Checks
.Append
4952 ((N
, U_Ent
, Expr_Value
(Addr
), Empty
, False));
4957 -- Overlaying controlled objects is erroneous. Emit warning
4958 -- but continue analysis because program is itself legal,
4959 -- and back end must see address clause.
4962 and then (Has_Controlled_Component
(Etype
(O_Ent
))
4963 or else Is_Controlled
(Etype
(O_Ent
)))
4964 and then not Inside_A_Generic
4967 ("??cannot use overlays with controlled objects", Expr
);
4969 ("\??Program_Error will be raised at run time", Expr
);
4970 Insert_Action
(Declaration_Node
(U_Ent
),
4971 Make_Raise_Program_Error
(Loc
,
4972 Reason
=> PE_Overlaid_Controlled_Object
));
4974 -- Issue an unconditional warning for a constant overlaying
4975 -- a variable. For the reverse case, we will issue it only
4976 -- if the variable is modified.
4978 elsif Ekind
(U_Ent
) = E_Constant
4979 and then Present
(O_Ent
)
4980 and then not Overlays_Constant
(U_Ent
)
4981 and then Address_Clause_Overlay_Warnings
4983 Error_Msg_N
("??constant overlays a variable", Expr
);
4985 -- Imported variables can have an address clause, but then
4986 -- the import is pretty meaningless except to suppress
4987 -- initializations, so we do not need such variables to
4988 -- be statically allocated (and in fact it causes trouble
4989 -- if the address clause is a local value).
4991 elsif Is_Imported
(U_Ent
) then
4992 Set_Is_Statically_Allocated
(U_Ent
, False);
4995 -- We mark a possible modification of a variable with an
4996 -- address clause, since it is likely aliasing is occurring.
4998 Note_Possible_Modification
(Nam
, Sure
=> False);
5000 -- Legality checks on the address clause for initialized
5001 -- objects is deferred until the freeze point, because
5002 -- a subsequent pragma might indicate that the object
5003 -- is imported and thus not initialized. Also, the address
5004 -- clause might involve entities that have yet to be
5007 Set_Has_Delayed_Freeze
(U_Ent
);
5009 -- If an initialization call has been generated for this
5010 -- object, it needs to be deferred to after the freeze node
5011 -- we have just now added, otherwise GIGI will see a
5012 -- reference to the variable (as actual to the IP call)
5013 -- before its definition.
5016 Init_Call
: constant Node_Id
:=
5017 Remove_Init_Call
(U_Ent
, N
);
5020 if Present
(Init_Call
) then
5021 Append_Freeze_Action
(U_Ent
, Init_Call
);
5023 -- Reset Initialization_Statements pointer so that
5024 -- if there is a pragma Import further down, it can
5025 -- clear any default initialization.
5027 Set_Initialization_Statements
(U_Ent
, Init_Call
);
5031 -- Entity has delayed freeze, so we will generate an
5032 -- alignment check at the freeze point unless suppressed.
5034 if not Range_Checks_Suppressed
(U_Ent
)
5035 and then not Alignment_Checks_Suppressed
(U_Ent
)
5037 Set_Check_Address_Alignment
(N
);
5040 -- Kill the size check code, since we are not allocating
5041 -- the variable, it is somewhere else.
5043 Kill_Size_Check_Code
(U_Ent
);
5046 -- Not a valid entity for an address clause
5049 Error_Msg_N
("address cannot be given for &", Nam
);
5057 -- Alignment attribute definition clause
5059 when Attribute_Alignment
=> Alignment
: declare
5060 Align
: constant Uint
:= Get_Alignment_Value
(Expr
);
5061 Max_Align
: constant Uint
:= UI_From_Int
(Maximum_Alignment
);
5066 if not Is_Type
(U_Ent
)
5067 and then Ekind
(U_Ent
) /= E_Variable
5068 and then Ekind
(U_Ent
) /= E_Constant
5070 Error_Msg_N
("alignment cannot be given for &", Nam
);
5072 elsif Duplicate_Clause
then
5075 elsif Align
/= No_Uint
then
5076 Set_Has_Alignment_Clause
(U_Ent
);
5078 -- Tagged type case, check for attempt to set alignment to a
5079 -- value greater than Max_Align, and reset if so. This error
5080 -- is suppressed in ASIS mode to allow for different ASIS
5081 -- back ends or ASIS-based tools to query the illegal clause.
5083 if Is_Tagged_Type
(U_Ent
)
5084 and then Align
> Max_Align
5085 and then not ASIS_Mode
5088 ("alignment for & set to Maximum_Aligment??", Nam
);
5089 Set_Alignment
(U_Ent
, Max_Align
);
5094 Set_Alignment
(U_Ent
, Align
);
5097 -- For an array type, U_Ent is the first subtype. In that case,
5098 -- also set the alignment of the anonymous base type so that
5099 -- other subtypes (such as the itypes for aggregates of the
5100 -- type) also receive the expected alignment.
5102 if Is_Array_Type
(U_Ent
) then
5103 Set_Alignment
(Base_Type
(U_Ent
), Align
);
5112 -- Bit_Order attribute definition clause
5114 when Attribute_Bit_Order
=> Bit_Order
: declare
5116 if not Is_Record_Type
(U_Ent
) then
5118 ("Bit_Order can only be defined for record type", Nam
);
5120 elsif Duplicate_Clause
then
5124 Analyze_And_Resolve
(Expr
, RTE
(RE_Bit_Order
));
5126 if Etype
(Expr
) = Any_Type
then
5129 elsif not Is_OK_Static_Expression
(Expr
) then
5130 Flag_Non_Static_Expr
5131 ("Bit_Order requires static expression!", Expr
);
5134 if (Expr_Value
(Expr
) = 0) /= Bytes_Big_Endian
then
5135 Set_Reverse_Bit_Order
(Base_Type
(U_Ent
), True);
5141 --------------------
5142 -- Component_Size --
5143 --------------------
5145 -- Component_Size attribute definition clause
5147 when Attribute_Component_Size
=> Component_Size_Case
: declare
5148 Csize
: constant Uint
:= Static_Integer
(Expr
);
5152 New_Ctyp
: Entity_Id
;
5156 if not Is_Array_Type
(U_Ent
) then
5157 Error_Msg_N
("component size requires array type", Nam
);
5161 Btype
:= Base_Type
(U_Ent
);
5162 Ctyp
:= Component_Type
(Btype
);
5164 if Duplicate_Clause
then
5167 elsif Rep_Item_Too_Early
(Btype
, N
) then
5170 elsif Csize
/= No_Uint
then
5171 Check_Size
(Expr
, Ctyp
, Csize
, Biased
);
5173 -- For the biased case, build a declaration for a subtype that
5174 -- will be used to represent the biased subtype that reflects
5175 -- the biased representation of components. We need the subtype
5176 -- to get proper conversions on referencing elements of the
5181 Make_Defining_Identifier
(Loc
,
5183 New_External_Name
(Chars
(U_Ent
), 'C', 0, 'T'));
5186 Make_Subtype_Declaration
(Loc
,
5187 Defining_Identifier
=> New_Ctyp
,
5188 Subtype_Indication
=>
5189 New_Occurrence_Of
(Component_Type
(Btype
), Loc
));
5191 Set_Parent
(Decl
, N
);
5192 Analyze
(Decl
, Suppress
=> All_Checks
);
5194 Set_Has_Delayed_Freeze
(New_Ctyp
, False);
5195 Set_Esize
(New_Ctyp
, Csize
);
5196 Set_RM_Size
(New_Ctyp
, Csize
);
5197 Init_Alignment
(New_Ctyp
);
5198 Set_Is_Itype
(New_Ctyp
, True);
5199 Set_Associated_Node_For_Itype
(New_Ctyp
, U_Ent
);
5201 Set_Component_Type
(Btype
, New_Ctyp
);
5202 Set_Biased
(New_Ctyp
, N
, "component size clause");
5205 Set_Component_Size
(Btype
, Csize
);
5207 -- Deal with warning on overridden size
5209 if Warn_On_Overridden_Size
5210 and then Has_Size_Clause
(Ctyp
)
5211 and then RM_Size
(Ctyp
) /= Csize
5214 ("component size overrides size clause for&?S?", N
, Ctyp
);
5217 Set_Has_Component_Size_Clause
(Btype
, True);
5218 Set_Has_Non_Standard_Rep
(Btype
, True);
5220 end Component_Size_Case
;
5222 -----------------------
5223 -- Constant_Indexing --
5224 -----------------------
5226 when Attribute_Constant_Indexing
=>
5227 Check_Indexing_Functions
;
5233 when Attribute_CPU
=> CPU
:
5235 -- CPU attribute definition clause not allowed except from aspect
5238 if From_Aspect_Specification
(N
) then
5239 if not Is_Task_Type
(U_Ent
) then
5240 Error_Msg_N
("CPU can only be defined for task", Nam
);
5242 elsif Duplicate_Clause
then
5246 -- The expression must be analyzed in the special manner
5247 -- described in "Handling of Default and Per-Object
5248 -- Expressions" in sem.ads.
5250 -- The visibility to the discriminants must be restored
5252 Push_Scope_And_Install_Discriminants
(U_Ent
);
5253 Preanalyze_Spec_Expression
(Expr
, RTE
(RE_CPU_Range
));
5254 Uninstall_Discriminants_And_Pop_Scope
(U_Ent
);
5256 if not Is_OK_Static_Expression
(Expr
) then
5257 Check_Restriction
(Static_Priorities
, Expr
);
5263 ("attribute& cannot be set with definition clause", N
);
5267 ----------------------
5268 -- Default_Iterator --
5269 ----------------------
5271 when Attribute_Default_Iterator
=> Default_Iterator
: declare
5276 -- If target type is untagged, further checks are irrelevant
5278 if not Is_Tagged_Type
(U_Ent
) then
5280 ("aspect Default_Iterator applies to tagged type", Nam
);
5284 Check_Iterator_Functions
;
5288 if not Is_Entity_Name
(Expr
)
5289 or else Ekind
(Entity
(Expr
)) /= E_Function
5291 Error_Msg_N
("aspect Iterator must be a function", Expr
);
5294 Func
:= Entity
(Expr
);
5297 -- The type of the first parameter must be T, T'class, or a
5298 -- corresponding access type (5.5.1 (8/3). If function is
5299 -- parameterless label type accordingly.
5301 if No
(First_Formal
(Func
)) then
5304 Typ
:= Etype
(First_Formal
(Func
));
5308 or else Typ
= Class_Wide_Type
(U_Ent
)
5309 or else (Is_Access_Type
(Typ
)
5310 and then Designated_Type
(Typ
) = U_Ent
)
5311 or else (Is_Access_Type
(Typ
)
5312 and then Designated_Type
(Typ
) =
5313 Class_Wide_Type
(U_Ent
))
5319 ("Default Iterator must be a primitive of&", Func
, U_Ent
);
5321 end Default_Iterator
;
5323 ------------------------
5324 -- Dispatching_Domain --
5325 ------------------------
5327 when Attribute_Dispatching_Domain
=> Dispatching_Domain
:
5329 -- Dispatching_Domain attribute definition clause not allowed
5330 -- except from aspect specification.
5332 if From_Aspect_Specification
(N
) then
5333 if not Is_Task_Type
(U_Ent
) then
5335 ("Dispatching_Domain can only be defined for task", Nam
);
5337 elsif Duplicate_Clause
then
5341 -- The expression must be analyzed in the special manner
5342 -- described in "Handling of Default and Per-Object
5343 -- Expressions" in sem.ads.
5345 -- The visibility to the discriminants must be restored
5347 Push_Scope_And_Install_Discriminants
(U_Ent
);
5349 Preanalyze_Spec_Expression
5350 (Expr
, RTE
(RE_Dispatching_Domain
));
5352 Uninstall_Discriminants_And_Pop_Scope
(U_Ent
);
5357 ("attribute& cannot be set with definition clause", N
);
5359 end Dispatching_Domain
;
5365 when Attribute_External_Tag
=> External_Tag
:
5367 if not Is_Tagged_Type
(U_Ent
) then
5368 Error_Msg_N
("should be a tagged type", Nam
);
5371 if Duplicate_Clause
then
5375 Analyze_And_Resolve
(Expr
, Standard_String
);
5377 if not Is_OK_Static_Expression
(Expr
) then
5378 Flag_Non_Static_Expr
5379 ("static string required for tag name!", Nam
);
5382 if not Is_Library_Level_Entity
(U_Ent
) then
5384 ("??non-unique external tag supplied for &", N
, U_Ent
);
5386 ("\??same external tag applies to all subprogram calls",
5389 ("\??corresponding internal tag cannot be obtained", N
);
5394 --------------------------
5395 -- Implicit_Dereference --
5396 --------------------------
5398 when Attribute_Implicit_Dereference
=>
5400 -- Legality checks already performed at the point of the type
5401 -- declaration, aspect is not delayed.
5409 when Attribute_Input
=>
5410 Analyze_Stream_TSS_Definition
(TSS_Stream_Input
);
5411 Set_Has_Specified_Stream_Input
(Ent
);
5413 ------------------------
5414 -- Interrupt_Priority --
5415 ------------------------
5417 when Attribute_Interrupt_Priority
=> Interrupt_Priority
:
5419 -- Interrupt_Priority attribute definition clause not allowed
5420 -- except from aspect specification.
5422 if From_Aspect_Specification
(N
) then
5423 if not Is_Concurrent_Type
(U_Ent
) then
5425 ("Interrupt_Priority can only be defined for task and "
5426 & "protected object", Nam
);
5428 elsif Duplicate_Clause
then
5432 -- The expression must be analyzed in the special manner
5433 -- described in "Handling of Default and Per-Object
5434 -- Expressions" in sem.ads.
5436 -- The visibility to the discriminants must be restored
5438 Push_Scope_And_Install_Discriminants
(U_Ent
);
5440 Preanalyze_Spec_Expression
5441 (Expr
, RTE
(RE_Interrupt_Priority
));
5443 Uninstall_Discriminants_And_Pop_Scope
(U_Ent
);
5445 -- Check the No_Task_At_Interrupt_Priority restriction
5447 if Is_Task_Type
(U_Ent
) then
5448 Check_Restriction
(No_Task_At_Interrupt_Priority
, N
);
5454 ("attribute& cannot be set with definition clause", N
);
5456 end Interrupt_Priority
;
5462 when Attribute_Iterable
=>
5465 if Nkind
(Expr
) /= N_Aggregate
then
5466 Error_Msg_N
("aspect Iterable must be an aggregate", Expr
);
5473 Assoc
:= First
(Component_Associations
(Expr
));
5474 while Present
(Assoc
) loop
5475 if not Is_Entity_Name
(Expression
(Assoc
)) then
5476 Error_Msg_N
("value must be a function", Assoc
);
5483 ----------------------
5484 -- Iterator_Element --
5485 ----------------------
5487 when Attribute_Iterator_Element
=>
5490 if not Is_Entity_Name
(Expr
)
5491 or else not Is_Type
(Entity
(Expr
))
5493 Error_Msg_N
("aspect Iterator_Element must be a type", Expr
);
5500 -- Machine radix attribute definition clause
5502 when Attribute_Machine_Radix
=> Machine_Radix
: declare
5503 Radix
: constant Uint
:= Static_Integer
(Expr
);
5506 if not Is_Decimal_Fixed_Point_Type
(U_Ent
) then
5507 Error_Msg_N
("decimal fixed-point type expected for &", Nam
);
5509 elsif Duplicate_Clause
then
5512 elsif Radix
/= No_Uint
then
5513 Set_Has_Machine_Radix_Clause
(U_Ent
);
5514 Set_Has_Non_Standard_Rep
(Base_Type
(U_Ent
));
5519 elsif Radix
= 10 then
5520 Set_Machine_Radix_10
(U_Ent
);
5522 -- The following error is suppressed in ASIS mode to allow for
5523 -- different ASIS back ends or ASIS-based tools to query the
5526 elsif not ASIS_Mode
then
5527 Error_Msg_N
("machine radix value must be 2 or 10", Expr
);
5536 -- Object_Size attribute definition clause
5538 when Attribute_Object_Size
=> Object_Size
: declare
5539 Size
: constant Uint
:= Static_Integer
(Expr
);
5542 pragma Warnings
(Off
, Biased
);
5545 if not Is_Type
(U_Ent
) then
5546 Error_Msg_N
("Object_Size cannot be given for &", Nam
);
5548 elsif Duplicate_Clause
then
5552 Check_Size
(Expr
, U_Ent
, Size
, Biased
);
5554 -- The following errors are suppressed in ASIS mode to allow
5555 -- for different ASIS back ends or ASIS-based tools to query
5556 -- the illegal clause.
5561 elsif Is_Scalar_Type
(U_Ent
) then
5562 if Size
/= 8 and then Size
/= 16 and then Size
/= 32
5563 and then UI_Mod
(Size
, 64) /= 0
5566 ("Object_Size must be 8, 16, 32, or multiple of 64",
5570 elsif Size
mod 8 /= 0 then
5571 Error_Msg_N
("Object_Size must be a multiple of 8", Expr
);
5574 Set_Esize
(U_Ent
, Size
);
5575 Set_Has_Object_Size_Clause
(U_Ent
);
5576 Alignment_Check_For_Size_Change
(U_Ent
, Size
);
5584 when Attribute_Output
=>
5585 Analyze_Stream_TSS_Definition
(TSS_Stream_Output
);
5586 Set_Has_Specified_Stream_Output
(Ent
);
5592 when Attribute_Priority
=> Priority
:
5594 -- Priority attribute definition clause not allowed except from
5595 -- aspect specification.
5597 if From_Aspect_Specification
(N
) then
5598 if not (Is_Concurrent_Type
(U_Ent
)
5599 or else Ekind
(U_Ent
) = E_Procedure
)
5602 ("Priority can only be defined for task and protected "
5605 elsif Duplicate_Clause
then
5609 -- The expression must be analyzed in the special manner
5610 -- described in "Handling of Default and Per-Object
5611 -- Expressions" in sem.ads.
5613 -- The visibility to the discriminants must be restored
5615 Push_Scope_And_Install_Discriminants
(U_Ent
);
5616 Preanalyze_Spec_Expression
(Expr
, Standard_Integer
);
5617 Uninstall_Discriminants_And_Pop_Scope
(U_Ent
);
5619 if not Is_OK_Static_Expression
(Expr
) then
5620 Check_Restriction
(Static_Priorities
, Expr
);
5626 ("attribute& cannot be set with definition clause", N
);
5634 when Attribute_Read
=>
5635 Analyze_Stream_TSS_Definition
(TSS_Stream_Read
);
5636 Set_Has_Specified_Stream_Read
(Ent
);
5638 --------------------------
5639 -- Scalar_Storage_Order --
5640 --------------------------
5642 -- Scalar_Storage_Order attribute definition clause
5644 when Attribute_Scalar_Storage_Order
=> Scalar_Storage_Order
: declare
5646 if not (Is_Record_Type
(U_Ent
) or else Is_Array_Type
(U_Ent
)) then
5648 ("Scalar_Storage_Order can only be defined for record or "
5649 & "array type", Nam
);
5651 elsif Duplicate_Clause
then
5655 Analyze_And_Resolve
(Expr
, RTE
(RE_Bit_Order
));
5657 if Etype
(Expr
) = Any_Type
then
5660 elsif not Is_OK_Static_Expression
(Expr
) then
5661 Flag_Non_Static_Expr
5662 ("Scalar_Storage_Order requires static expression!", Expr
);
5664 elsif (Expr_Value
(Expr
) = 0) /= Bytes_Big_Endian
then
5666 -- Here for the case of a non-default (i.e. non-confirming)
5667 -- Scalar_Storage_Order attribute definition.
5669 if Support_Nondefault_SSO_On_Target
then
5670 Set_Reverse_Storage_Order
(Base_Type
(U_Ent
), True);
5673 ("non-default Scalar_Storage_Order not supported on "
5678 -- Clear SSO default indications since explicit setting of the
5679 -- order overrides the defaults.
5681 Set_SSO_Set_Low_By_Default
(Base_Type
(U_Ent
), False);
5682 Set_SSO_Set_High_By_Default
(Base_Type
(U_Ent
), False);
5684 end Scalar_Storage_Order
;
5690 -- Size attribute definition clause
5692 when Attribute_Size
=> Size
: declare
5693 Size
: constant Uint
:= Static_Integer
(Expr
);
5700 if Duplicate_Clause
then
5703 elsif not Is_Type
(U_Ent
)
5704 and then Ekind
(U_Ent
) /= E_Variable
5705 and then Ekind
(U_Ent
) /= E_Constant
5707 Error_Msg_N
("size cannot be given for &", Nam
);
5709 elsif Is_Array_Type
(U_Ent
)
5710 and then not Is_Constrained
(U_Ent
)
5713 ("size cannot be given for unconstrained array", Nam
);
5715 elsif Size
/= No_Uint
then
5716 if Is_Type
(U_Ent
) then
5719 Etyp
:= Etype
(U_Ent
);
5722 -- Check size, note that Gigi is in charge of checking that the
5723 -- size of an array or record type is OK. Also we do not check
5724 -- the size in the ordinary fixed-point case, since it is too
5725 -- early to do so (there may be subsequent small clause that
5726 -- affects the size). We can check the size if a small clause
5727 -- has already been given.
5729 if not Is_Ordinary_Fixed_Point_Type
(U_Ent
)
5730 or else Has_Small_Clause
(U_Ent
)
5732 Check_Size
(Expr
, Etyp
, Size
, Biased
);
5733 Set_Biased
(U_Ent
, N
, "size clause", Biased
);
5736 -- For types set RM_Size and Esize if possible
5738 if Is_Type
(U_Ent
) then
5739 Set_RM_Size
(U_Ent
, Size
);
5741 -- For elementary types, increase Object_Size to power of 2,
5742 -- but not less than a storage unit in any case (normally
5743 -- this means it will be byte addressable).
5745 -- For all other types, nothing else to do, we leave Esize
5746 -- (object size) unset, the back end will set it from the
5747 -- size and alignment in an appropriate manner.
5749 -- In both cases, we check whether the alignment must be
5750 -- reset in the wake of the size change.
5752 if Is_Elementary_Type
(U_Ent
) then
5753 if Size
<= System_Storage_Unit
then
5754 Init_Esize
(U_Ent
, System_Storage_Unit
);
5755 elsif Size
<= 16 then
5756 Init_Esize
(U_Ent
, 16);
5757 elsif Size
<= 32 then
5758 Init_Esize
(U_Ent
, 32);
5760 Set_Esize
(U_Ent
, (Size
+ 63) / 64 * 64);
5763 Alignment_Check_For_Size_Change
(U_Ent
, Esize
(U_Ent
));
5765 Alignment_Check_For_Size_Change
(U_Ent
, Size
);
5768 -- For objects, set Esize only
5771 -- The following error is suppressed in ASIS mode to allow
5772 -- for different ASIS back ends or ASIS-based tools to query
5773 -- the illegal clause.
5775 if Is_Elementary_Type
(Etyp
)
5776 and then Size
/= System_Storage_Unit
5777 and then Size
/= System_Storage_Unit
* 2
5778 and then Size
/= System_Storage_Unit
* 4
5779 and then Size
/= System_Storage_Unit
* 8
5780 and then not ASIS_Mode
5782 Error_Msg_Uint_1
:= UI_From_Int
(System_Storage_Unit
);
5783 Error_Msg_Uint_2
:= Error_Msg_Uint_1
* 8;
5785 ("size for primitive object must be a power of 2 in "
5786 & "the range ^-^", N
);
5789 Set_Esize
(U_Ent
, Size
);
5792 Set_Has_Size_Clause
(U_Ent
);
5800 -- Small attribute definition clause
5802 when Attribute_Small
=> Small
: declare
5803 Implicit_Base
: constant Entity_Id
:= Base_Type
(U_Ent
);
5807 Analyze_And_Resolve
(Expr
, Any_Real
);
5809 if Etype
(Expr
) = Any_Type
then
5812 elsif not Is_OK_Static_Expression
(Expr
) then
5813 Flag_Non_Static_Expr
5814 ("small requires static expression!", Expr
);
5818 Small
:= Expr_Value_R
(Expr
);
5820 if Small
<= Ureal_0
then
5821 Error_Msg_N
("small value must be greater than zero", Expr
);
5827 if not Is_Ordinary_Fixed_Point_Type
(U_Ent
) then
5829 ("small requires an ordinary fixed point type", Nam
);
5831 elsif Has_Small_Clause
(U_Ent
) then
5832 Error_Msg_N
("small already given for &", Nam
);
5834 elsif Small
> Delta_Value
(U_Ent
) then
5836 ("small value must not be greater than delta value", Nam
);
5839 Set_Small_Value
(U_Ent
, Small
);
5840 Set_Small_Value
(Implicit_Base
, Small
);
5841 Set_Has_Small_Clause
(U_Ent
);
5842 Set_Has_Small_Clause
(Implicit_Base
);
5843 Set_Has_Non_Standard_Rep
(Implicit_Base
);
5851 -- Storage_Pool attribute definition clause
5853 when Attribute_Storage_Pool | Attribute_Simple_Storage_Pool
=> declare
5858 if Ekind
(U_Ent
) = E_Access_Subprogram_Type
then
5860 ("storage pool cannot be given for access-to-subprogram type",
5865 Ekind_In
(U_Ent
, E_Access_Type
, E_General_Access_Type
)
5868 ("storage pool can only be given for access types", Nam
);
5871 elsif Is_Derived_Type
(U_Ent
) then
5873 ("storage pool cannot be given for a derived access type",
5876 elsif Duplicate_Clause
then
5879 elsif Present
(Associated_Storage_Pool
(U_Ent
)) then
5880 Error_Msg_N
("storage pool already given for &", Nam
);
5884 -- Check for Storage_Size previously given
5887 SS
: constant Node_Id
:=
5888 Get_Attribute_Definition_Clause
5889 (U_Ent
, Attribute_Storage_Size
);
5891 if Present
(SS
) then
5892 Check_Pool_Size_Clash
(U_Ent
, N
, SS
);
5896 -- Storage_Pool case
5898 if Id
= Attribute_Storage_Pool
then
5900 (Expr
, Class_Wide_Type
(RTE
(RE_Root_Storage_Pool
)));
5902 -- In the Simple_Storage_Pool case, we allow a variable of any
5903 -- simple storage pool type, so we Resolve without imposing an
5907 Analyze_And_Resolve
(Expr
);
5909 if not Present
(Get_Rep_Pragma
5910 (Etype
(Expr
), Name_Simple_Storage_Pool_Type
))
5913 ("expression must be of a simple storage pool type", Expr
);
5917 if not Denotes_Variable
(Expr
) then
5918 Error_Msg_N
("storage pool must be a variable", Expr
);
5922 if Nkind
(Expr
) = N_Type_Conversion
then
5923 T
:= Etype
(Expression
(Expr
));
5928 -- The Stack_Bounded_Pool is used internally for implementing
5929 -- access types with a Storage_Size. Since it only work properly
5930 -- when used on one specific type, we need to check that it is not
5931 -- hijacked improperly:
5933 -- type T is access Integer;
5934 -- for T'Storage_Size use n;
5935 -- type Q is access Float;
5936 -- for Q'Storage_Size use T'Storage_Size; -- incorrect
5938 if RTE_Available
(RE_Stack_Bounded_Pool
)
5939 and then Base_Type
(T
) = RTE
(RE_Stack_Bounded_Pool
)
5941 Error_Msg_N
("non-shareable internal Pool", Expr
);
5945 -- If the argument is a name that is not an entity name, then
5946 -- we construct a renaming operation to define an entity of
5947 -- type storage pool.
5949 if not Is_Entity_Name
(Expr
)
5950 and then Is_Object_Reference
(Expr
)
5952 Pool
:= Make_Temporary
(Loc
, 'P', Expr
);
5955 Rnode
: constant Node_Id
:=
5956 Make_Object_Renaming_Declaration
(Loc
,
5957 Defining_Identifier
=> Pool
,
5959 New_Occurrence_Of
(Etype
(Expr
), Loc
),
5963 -- If the attribute definition clause comes from an aspect
5964 -- clause, then insert the renaming before the associated
5965 -- entity's declaration, since the attribute clause has
5966 -- not yet been appended to the declaration list.
5968 if From_Aspect_Specification
(N
) then
5969 Insert_Before
(Parent
(Entity
(N
)), Rnode
);
5971 Insert_Before
(N
, Rnode
);
5975 Set_Associated_Storage_Pool
(U_Ent
, Pool
);
5978 elsif Is_Entity_Name
(Expr
) then
5979 Pool
:= Entity
(Expr
);
5981 -- If pool is a renamed object, get original one. This can
5982 -- happen with an explicit renaming, and within instances.
5984 while Present
(Renamed_Object
(Pool
))
5985 and then Is_Entity_Name
(Renamed_Object
(Pool
))
5987 Pool
:= Entity
(Renamed_Object
(Pool
));
5990 if Present
(Renamed_Object
(Pool
))
5991 and then Nkind
(Renamed_Object
(Pool
)) = N_Type_Conversion
5992 and then Is_Entity_Name
(Expression
(Renamed_Object
(Pool
)))
5994 Pool
:= Entity
(Expression
(Renamed_Object
(Pool
)));
5997 Set_Associated_Storage_Pool
(U_Ent
, Pool
);
5999 elsif Nkind
(Expr
) = N_Type_Conversion
6000 and then Is_Entity_Name
(Expression
(Expr
))
6001 and then Nkind
(Original_Node
(Expr
)) = N_Attribute_Reference
6003 Pool
:= Entity
(Expression
(Expr
));
6004 Set_Associated_Storage_Pool
(U_Ent
, Pool
);
6007 Error_Msg_N
("incorrect reference to a Storage Pool", Expr
);
6016 -- Storage_Size attribute definition clause
6018 when Attribute_Storage_Size
=> Storage_Size
: declare
6019 Btype
: constant Entity_Id
:= Base_Type
(U_Ent
);
6022 if Is_Task_Type
(U_Ent
) then
6024 -- Check obsolescent (but never obsolescent if from aspect)
6026 if not From_Aspect_Specification
(N
) then
6027 Check_Restriction
(No_Obsolescent_Features
, N
);
6029 if Warn_On_Obsolescent_Feature
then
6031 ("?j?storage size clause for task is an obsolescent "
6032 & "feature (RM J.9)", N
);
6033 Error_Msg_N
("\?j?use Storage_Size pragma instead", N
);
6040 if not Is_Access_Type
(U_Ent
)
6041 and then Ekind
(U_Ent
) /= E_Task_Type
6043 Error_Msg_N
("storage size cannot be given for &", Nam
);
6045 elsif Is_Access_Type
(U_Ent
) and Is_Derived_Type
(U_Ent
) then
6047 ("storage size cannot be given for a derived access type",
6050 elsif Duplicate_Clause
then
6054 Analyze_And_Resolve
(Expr
, Any_Integer
);
6056 if Is_Access_Type
(U_Ent
) then
6058 -- Check for Storage_Pool previously given
6061 SP
: constant Node_Id
:=
6062 Get_Attribute_Definition_Clause
6063 (U_Ent
, Attribute_Storage_Pool
);
6066 if Present
(SP
) then
6067 Check_Pool_Size_Clash
(U_Ent
, SP
, N
);
6071 -- Special case of for x'Storage_Size use 0
6073 if Is_OK_Static_Expression
(Expr
)
6074 and then Expr_Value
(Expr
) = 0
6076 Set_No_Pool_Assigned
(Btype
);
6080 Set_Has_Storage_Size_Clause
(Btype
);
6088 when Attribute_Stream_Size
=> Stream_Size
: declare
6089 Size
: constant Uint
:= Static_Integer
(Expr
);
6092 if Ada_Version
<= Ada_95
then
6093 Check_Restriction
(No_Implementation_Attributes
, N
);
6096 if Duplicate_Clause
then
6099 elsif Is_Elementary_Type
(U_Ent
) then
6101 -- The following errors are suppressed in ASIS mode to allow
6102 -- for different ASIS back ends or ASIS-based tools to query
6103 -- the illegal clause.
6108 elsif Size
/= System_Storage_Unit
6109 and then Size
/= System_Storage_Unit
* 2
6110 and then Size
/= System_Storage_Unit
* 4
6111 and then Size
/= System_Storage_Unit
* 8
6113 Error_Msg_Uint_1
:= UI_From_Int
(System_Storage_Unit
);
6115 ("stream size for elementary type must be a power of 2 "
6116 & "and at least ^", N
);
6118 elsif RM_Size
(U_Ent
) > Size
then
6119 Error_Msg_Uint_1
:= RM_Size
(U_Ent
);
6121 ("stream size for elementary type must be a power of 2 "
6122 & "and at least ^", N
);
6125 Set_Has_Stream_Size_Clause
(U_Ent
);
6128 Error_Msg_N
("Stream_Size cannot be given for &", Nam
);
6136 -- Value_Size attribute definition clause
6138 when Attribute_Value_Size
=> Value_Size
: declare
6139 Size
: constant Uint
:= Static_Integer
(Expr
);
6143 if not Is_Type
(U_Ent
) then
6144 Error_Msg_N
("Value_Size cannot be given for &", Nam
);
6146 elsif Duplicate_Clause
then
6149 elsif Is_Array_Type
(U_Ent
)
6150 and then not Is_Constrained
(U_Ent
)
6153 ("Value_Size cannot be given for unconstrained array", Nam
);
6156 if Is_Elementary_Type
(U_Ent
) then
6157 Check_Size
(Expr
, U_Ent
, Size
, Biased
);
6158 Set_Biased
(U_Ent
, N
, "value size clause", Biased
);
6161 Set_RM_Size
(U_Ent
, Size
);
6165 -----------------------
6166 -- Variable_Indexing --
6167 -----------------------
6169 when Attribute_Variable_Indexing
=>
6170 Check_Indexing_Functions
;
6176 when Attribute_Write
=>
6177 Analyze_Stream_TSS_Definition
(TSS_Stream_Write
);
6178 Set_Has_Specified_Stream_Write
(Ent
);
6180 -- All other attributes cannot be set
6184 ("attribute& cannot be set with definition clause", N
);
6187 -- The test for the type being frozen must be performed after any
6188 -- expression the clause has been analyzed since the expression itself
6189 -- might cause freezing that makes the clause illegal.
6191 if Rep_Item_Too_Late
(U_Ent
, N
, FOnly
) then
6194 end Analyze_Attribute_Definition_Clause
;
6196 ----------------------------
6197 -- Analyze_Code_Statement --
6198 ----------------------------
6200 procedure Analyze_Code_Statement
(N
: Node_Id
) is
6201 HSS
: constant Node_Id
:= Parent
(N
);
6202 SBody
: constant Node_Id
:= Parent
(HSS
);
6203 Subp
: constant Entity_Id
:= Current_Scope
;
6210 -- Accept foreign code statements for CodePeer. The analysis is skipped
6211 -- to avoid rejecting unrecognized constructs.
6213 if CodePeer_Mode
then
6218 -- Analyze and check we get right type, note that this implements the
6219 -- requirement (RM 13.8(1)) that Machine_Code be with'ed, since that is
6220 -- the only way that Asm_Insn could possibly be visible.
6222 Analyze_And_Resolve
(Expression
(N
));
6224 if Etype
(Expression
(N
)) = Any_Type
then
6226 elsif Etype
(Expression
(N
)) /= RTE
(RE_Asm_Insn
) then
6227 Error_Msg_N
("incorrect type for code statement", N
);
6231 Check_Code_Statement
(N
);
6233 -- Make sure we appear in the handled statement sequence of a subprogram
6236 if Nkind
(HSS
) /= N_Handled_Sequence_Of_Statements
6237 or else Nkind
(SBody
) /= N_Subprogram_Body
6240 ("code statement can only appear in body of subprogram", N
);
6244 -- Do remaining checks (RM 13.8(3)) if not already done
6246 if not Is_Machine_Code_Subprogram
(Subp
) then
6247 Set_Is_Machine_Code_Subprogram
(Subp
);
6249 -- No exception handlers allowed
6251 if Present
(Exception_Handlers
(HSS
)) then
6253 ("exception handlers not permitted in machine code subprogram",
6254 First
(Exception_Handlers
(HSS
)));
6257 -- No declarations other than use clauses and pragmas (we allow
6258 -- certain internally generated declarations as well).
6260 Decl
:= First
(Declarations
(SBody
));
6261 while Present
(Decl
) loop
6262 DeclO
:= Original_Node
(Decl
);
6263 if Comes_From_Source
(DeclO
)
6264 and not Nkind_In
(DeclO
, N_Pragma
,
6265 N_Use_Package_Clause
,
6267 N_Implicit_Label_Declaration
)
6270 ("this declaration not allowed in machine code subprogram",
6277 -- No statements other than code statements, pragmas, and labels.
6278 -- Again we allow certain internally generated statements.
6280 -- In Ada 2012, qualified expressions are names, and the code
6281 -- statement is initially parsed as a procedure call.
6283 Stmt
:= First
(Statements
(HSS
));
6284 while Present
(Stmt
) loop
6285 StmtO
:= Original_Node
(Stmt
);
6287 -- A procedure call transformed into a code statement is OK
6289 if Ada_Version
>= Ada_2012
6290 and then Nkind
(StmtO
) = N_Procedure_Call_Statement
6291 and then Nkind
(Name
(StmtO
)) = N_Qualified_Expression
6295 elsif Comes_From_Source
(StmtO
)
6296 and then not Nkind_In
(StmtO
, N_Pragma
,
6301 ("this statement is not allowed in machine code subprogram",
6308 end Analyze_Code_Statement
;
6310 -----------------------------------------------
6311 -- Analyze_Enumeration_Representation_Clause --
6312 -----------------------------------------------
6314 procedure Analyze_Enumeration_Representation_Clause
(N
: Node_Id
) is
6315 Ident
: constant Node_Id
:= Identifier
(N
);
6316 Aggr
: constant Node_Id
:= Array_Aggregate
(N
);
6317 Enumtype
: Entity_Id
;
6324 Err
: Boolean := False;
6325 -- Set True to avoid cascade errors and crashes on incorrect source code
6327 Lo
: constant Uint
:= Expr_Value
(Type_Low_Bound
(Universal_Integer
));
6328 Hi
: constant Uint
:= Expr_Value
(Type_High_Bound
(Universal_Integer
));
6329 -- Allowed range of universal integer (= allowed range of enum lit vals)
6333 -- Minimum and maximum values of entries
6336 -- Pointer to node for literal providing max value
6339 if Ignore_Rep_Clauses
then
6340 Kill_Rep_Clause
(N
);
6344 -- Ignore enumeration rep clauses by default in CodePeer mode,
6345 -- unless -gnatd.I is specified, as a work around for potential false
6346 -- positive messages.
6348 if CodePeer_Mode
and not Debug_Flag_Dot_II
then
6352 -- First some basic error checks
6355 Enumtype
:= Entity
(Ident
);
6357 if Enumtype
= Any_Type
6358 or else Rep_Item_Too_Early
(Enumtype
, N
)
6362 Enumtype
:= Underlying_Type
(Enumtype
);
6365 if not Is_Enumeration_Type
(Enumtype
) then
6367 ("enumeration type required, found}",
6368 Ident
, First_Subtype
(Enumtype
));
6372 -- Ignore rep clause on generic actual type. This will already have
6373 -- been flagged on the template as an error, and this is the safest
6374 -- way to ensure we don't get a junk cascaded message in the instance.
6376 if Is_Generic_Actual_Type
(Enumtype
) then
6379 -- Type must be in current scope
6381 elsif Scope
(Enumtype
) /= Current_Scope
then
6382 Error_Msg_N
("type must be declared in this scope", Ident
);
6385 -- Type must be a first subtype
6387 elsif not Is_First_Subtype
(Enumtype
) then
6388 Error_Msg_N
("cannot give enumeration rep clause for subtype", N
);
6391 -- Ignore duplicate rep clause
6393 elsif Has_Enumeration_Rep_Clause
(Enumtype
) then
6394 Error_Msg_N
("duplicate enumeration rep clause ignored", N
);
6397 -- Don't allow rep clause for standard [wide_[wide_]]character
6399 elsif Is_Standard_Character_Type
(Enumtype
) then
6400 Error_Msg_N
("enumeration rep clause not allowed for this type", N
);
6403 -- Check that the expression is a proper aggregate (no parentheses)
6405 elsif Paren_Count
(Aggr
) /= 0 then
6407 ("extra parentheses surrounding aggregate not allowed",
6411 -- All tests passed, so set rep clause in place
6414 Set_Has_Enumeration_Rep_Clause
(Enumtype
);
6415 Set_Has_Enumeration_Rep_Clause
(Base_Type
(Enumtype
));
6418 -- Now we process the aggregate. Note that we don't use the normal
6419 -- aggregate code for this purpose, because we don't want any of the
6420 -- normal expansion activities, and a number of special semantic
6421 -- rules apply (including the component type being any integer type)
6423 Elit
:= First_Literal
(Enumtype
);
6425 -- First the positional entries if any
6427 if Present
(Expressions
(Aggr
)) then
6428 Expr
:= First
(Expressions
(Aggr
));
6429 while Present
(Expr
) loop
6431 Error_Msg_N
("too many entries in aggregate", Expr
);
6435 Val
:= Static_Integer
(Expr
);
6437 -- Err signals that we found some incorrect entries processing
6438 -- the list. The final checks for completeness and ordering are
6439 -- skipped in this case.
6441 if Val
= No_Uint
then
6444 elsif Val
< Lo
or else Hi
< Val
then
6445 Error_Msg_N
("value outside permitted range", Expr
);
6449 Set_Enumeration_Rep
(Elit
, Val
);
6450 Set_Enumeration_Rep_Expr
(Elit
, Expr
);
6456 -- Now process the named entries if present
6458 if Present
(Component_Associations
(Aggr
)) then
6459 Assoc
:= First
(Component_Associations
(Aggr
));
6460 while Present
(Assoc
) loop
6461 Choice
:= First
(Choices
(Assoc
));
6463 if Present
(Next
(Choice
)) then
6465 ("multiple choice not allowed here", Next
(Choice
));
6469 if Nkind
(Choice
) = N_Others_Choice
then
6470 Error_Msg_N
("others choice not allowed here", Choice
);
6473 elsif Nkind
(Choice
) = N_Range
then
6475 -- ??? should allow zero/one element range here
6477 Error_Msg_N
("range not allowed here", Choice
);
6481 Analyze_And_Resolve
(Choice
, Enumtype
);
6483 if Error_Posted
(Choice
) then
6488 if Is_Entity_Name
(Choice
)
6489 and then Is_Type
(Entity
(Choice
))
6491 Error_Msg_N
("subtype name not allowed here", Choice
);
6494 -- ??? should allow static subtype with zero/one entry
6496 elsif Etype
(Choice
) = Base_Type
(Enumtype
) then
6497 if not Is_OK_Static_Expression
(Choice
) then
6498 Flag_Non_Static_Expr
6499 ("non-static expression used for choice!", Choice
);
6503 Elit
:= Expr_Value_E
(Choice
);
6505 if Present
(Enumeration_Rep_Expr
(Elit
)) then
6507 Sloc
(Enumeration_Rep_Expr
(Elit
));
6509 ("representation for& previously given#",
6514 Set_Enumeration_Rep_Expr
(Elit
, Expression
(Assoc
));
6516 Expr
:= Expression
(Assoc
);
6517 Val
:= Static_Integer
(Expr
);
6519 if Val
= No_Uint
then
6522 elsif Val
< Lo
or else Hi
< Val
then
6523 Error_Msg_N
("value outside permitted range", Expr
);
6527 Set_Enumeration_Rep
(Elit
, Val
);
6537 -- Aggregate is fully processed. Now we check that a full set of
6538 -- representations was given, and that they are in range and in order.
6539 -- These checks are only done if no other errors occurred.
6545 Elit
:= First_Literal
(Enumtype
);
6546 while Present
(Elit
) loop
6547 if No
(Enumeration_Rep_Expr
(Elit
)) then
6548 Error_Msg_NE
("missing representation for&!", N
, Elit
);
6551 Val
:= Enumeration_Rep
(Elit
);
6553 if Min
= No_Uint
then
6557 if Val
/= No_Uint
then
6558 if Max
/= No_Uint
and then Val
<= Max
then
6560 ("enumeration value for& not ordered!",
6561 Enumeration_Rep_Expr
(Elit
), Elit
);
6564 Max_Node
:= Enumeration_Rep_Expr
(Elit
);
6568 -- If there is at least one literal whose representation is not
6569 -- equal to the Pos value, then note that this enumeration type
6570 -- has a non-standard representation.
6572 if Val
/= Enumeration_Pos
(Elit
) then
6573 Set_Has_Non_Standard_Rep
(Base_Type
(Enumtype
));
6580 -- Now set proper size information
6583 Minsize
: Uint
:= UI_From_Int
(Minimum_Size
(Enumtype
));
6586 if Has_Size_Clause
(Enumtype
) then
6588 -- All OK, if size is OK now
6590 if RM_Size
(Enumtype
) >= Minsize
then
6594 -- Try if we can get by with biasing
6597 UI_From_Int
(Minimum_Size
(Enumtype
, Biased
=> True));
6599 -- Error message if even biasing does not work
6601 if RM_Size
(Enumtype
) < Minsize
then
6602 Error_Msg_Uint_1
:= RM_Size
(Enumtype
);
6603 Error_Msg_Uint_2
:= Max
;
6605 ("previously given size (^) is too small "
6606 & "for this value (^)", Max_Node
);
6608 -- If biasing worked, indicate that we now have biased rep
6612 (Enumtype
, Size_Clause
(Enumtype
), "size clause");
6617 Set_RM_Size
(Enumtype
, Minsize
);
6618 Set_Enum_Esize
(Enumtype
);
6621 Set_RM_Size
(Base_Type
(Enumtype
), RM_Size
(Enumtype
));
6622 Set_Esize
(Base_Type
(Enumtype
), Esize
(Enumtype
));
6623 Set_Alignment
(Base_Type
(Enumtype
), Alignment
(Enumtype
));
6627 -- We repeat the too late test in case it froze itself
6629 if Rep_Item_Too_Late
(Enumtype
, N
) then
6632 end Analyze_Enumeration_Representation_Clause
;
6634 ----------------------------
6635 -- Analyze_Free_Statement --
6636 ----------------------------
6638 procedure Analyze_Free_Statement
(N
: Node_Id
) is
6640 Analyze
(Expression
(N
));
6641 end Analyze_Free_Statement
;
6643 ---------------------------
6644 -- Analyze_Freeze_Entity --
6645 ---------------------------
6647 procedure Analyze_Freeze_Entity
(N
: Node_Id
) is
6649 Freeze_Entity_Checks
(N
);
6650 end Analyze_Freeze_Entity
;
6652 -----------------------------------
6653 -- Analyze_Freeze_Generic_Entity --
6654 -----------------------------------
6656 procedure Analyze_Freeze_Generic_Entity
(N
: Node_Id
) is
6657 E
: constant Entity_Id
:= Entity
(N
);
6660 if not Is_Frozen
(E
) and then Has_Delayed_Aspects
(E
) then
6661 Analyze_Aspects_At_Freeze_Point
(E
);
6664 Freeze_Entity_Checks
(N
);
6665 end Analyze_Freeze_Generic_Entity
;
6667 ------------------------------------------
6668 -- Analyze_Record_Representation_Clause --
6669 ------------------------------------------
6671 -- Note: we check as much as we can here, but we can't do any checks
6672 -- based on the position values (e.g. overlap checks) until freeze time
6673 -- because especially in Ada 2005 (machine scalar mode), the processing
6674 -- for non-standard bit order can substantially change the positions.
6675 -- See procedure Check_Record_Representation_Clause (called from Freeze)
6676 -- for the remainder of this processing.
6678 procedure Analyze_Record_Representation_Clause
(N
: Node_Id
) is
6679 Ident
: constant Node_Id
:= Identifier
(N
);
6684 Hbit
: Uint
:= Uint_0
;
6688 Rectype
: Entity_Id
;
6691 function Is_Inherited
(Comp
: Entity_Id
) return Boolean;
6692 -- True if Comp is an inherited component in a record extension
6698 function Is_Inherited
(Comp
: Entity_Id
) return Boolean is
6699 Comp_Base
: Entity_Id
;
6702 if Ekind
(Rectype
) = E_Record_Subtype
then
6703 Comp_Base
:= Original_Record_Component
(Comp
);
6708 return Comp_Base
/= Original_Record_Component
(Comp_Base
);
6713 Is_Record_Extension
: Boolean;
6714 -- True if Rectype is a record extension
6716 CR_Pragma
: Node_Id
:= Empty
;
6717 -- Points to N_Pragma node if Complete_Representation pragma present
6719 -- Start of processing for Analyze_Record_Representation_Clause
6722 if Ignore_Rep_Clauses
then
6723 Kill_Rep_Clause
(N
);
6728 Rectype
:= Entity
(Ident
);
6730 if Rectype
= Any_Type
or else Rep_Item_Too_Early
(Rectype
, N
) then
6733 Rectype
:= Underlying_Type
(Rectype
);
6736 -- First some basic error checks
6738 if not Is_Record_Type
(Rectype
) then
6740 ("record type required, found}", Ident
, First_Subtype
(Rectype
));
6743 elsif Scope
(Rectype
) /= Current_Scope
then
6744 Error_Msg_N
("type must be declared in this scope", N
);
6747 elsif not Is_First_Subtype
(Rectype
) then
6748 Error_Msg_N
("cannot give record rep clause for subtype", N
);
6751 elsif Has_Record_Rep_Clause
(Rectype
) then
6752 Error_Msg_N
("duplicate record rep clause ignored", N
);
6755 elsif Rep_Item_Too_Late
(Rectype
, N
) then
6759 -- We know we have a first subtype, now possibly go to the anonymous
6760 -- base type to determine whether Rectype is a record extension.
6762 Recdef
:= Type_Definition
(Declaration_Node
(Base_Type
(Rectype
)));
6763 Is_Record_Extension
:=
6764 Nkind
(Recdef
) = N_Derived_Type_Definition
6765 and then Present
(Record_Extension_Part
(Recdef
));
6767 if Present
(Mod_Clause
(N
)) then
6769 Loc
: constant Source_Ptr
:= Sloc
(N
);
6770 M
: constant Node_Id
:= Mod_Clause
(N
);
6771 P
: constant List_Id
:= Pragmas_Before
(M
);
6775 pragma Warnings
(Off
, Mod_Val
);
6778 Check_Restriction
(No_Obsolescent_Features
, Mod_Clause
(N
));
6780 if Warn_On_Obsolescent_Feature
then
6782 ("?j?mod clause is an obsolescent feature (RM J.8)", N
);
6784 ("\?j?use alignment attribute definition clause instead", N
);
6791 -- In ASIS_Mode mode, expansion is disabled, but we must convert
6792 -- the Mod clause into an alignment clause anyway, so that the
6793 -- back end can compute and back-annotate properly the size and
6794 -- alignment of types that may include this record.
6796 -- This seems dubious, this destroys the source tree in a manner
6797 -- not detectable by ASIS ???
6799 if Operating_Mode
= Check_Semantics
and then ASIS_Mode
then
6801 Make_Attribute_Definition_Clause
(Loc
,
6802 Name
=> New_Occurrence_Of
(Base_Type
(Rectype
), Loc
),
6803 Chars
=> Name_Alignment
,
6804 Expression
=> Relocate_Node
(Expression
(M
)));
6806 Set_From_At_Mod
(AtM_Nod
);
6807 Insert_After
(N
, AtM_Nod
);
6808 Mod_Val
:= Get_Alignment_Value
(Expression
(AtM_Nod
));
6809 Set_Mod_Clause
(N
, Empty
);
6812 -- Get the alignment value to perform error checking
6814 Mod_Val
:= Get_Alignment_Value
(Expression
(M
));
6819 -- For untagged types, clear any existing component clauses for the
6820 -- type. If the type is derived, this is what allows us to override
6821 -- a rep clause for the parent. For type extensions, the representation
6822 -- of the inherited components is inherited, so we want to keep previous
6823 -- component clauses for completeness.
6825 if not Is_Tagged_Type
(Rectype
) then
6826 Comp
:= First_Component_Or_Discriminant
(Rectype
);
6827 while Present
(Comp
) loop
6828 Set_Component_Clause
(Comp
, Empty
);
6829 Next_Component_Or_Discriminant
(Comp
);
6833 -- All done if no component clauses
6835 CC
:= First
(Component_Clauses
(N
));
6841 -- A representation like this applies to the base type
6843 Set_Has_Record_Rep_Clause
(Base_Type
(Rectype
));
6844 Set_Has_Non_Standard_Rep
(Base_Type
(Rectype
));
6845 Set_Has_Specified_Layout
(Base_Type
(Rectype
));
6847 -- Process the component clauses
6849 while Present
(CC
) loop
6853 if Nkind
(CC
) = N_Pragma
then
6856 -- The only pragma of interest is Complete_Representation
6858 if Pragma_Name
(CC
) = Name_Complete_Representation
then
6862 -- Processing for real component clause
6865 Posit
:= Static_Integer
(Position
(CC
));
6866 Fbit
:= Static_Integer
(First_Bit
(CC
));
6867 Lbit
:= Static_Integer
(Last_Bit
(CC
));
6870 and then Fbit
/= No_Uint
6871 and then Lbit
/= No_Uint
6874 Error_Msg_N
("position cannot be negative", Position
(CC
));
6877 Error_Msg_N
("first bit cannot be negative", First_Bit
(CC
));
6879 -- The Last_Bit specified in a component clause must not be
6880 -- less than the First_Bit minus one (RM-13.5.1(10)).
6882 elsif Lbit
< Fbit
- 1 then
6884 ("last bit cannot be less than first bit minus one",
6887 -- Values look OK, so find the corresponding record component
6888 -- Even though the syntax allows an attribute reference for
6889 -- implementation-defined components, GNAT does not allow the
6890 -- tag to get an explicit position.
6892 elsif Nkind
(Component_Name
(CC
)) = N_Attribute_Reference
then
6893 if Attribute_Name
(Component_Name
(CC
)) = Name_Tag
then
6894 Error_Msg_N
("position of tag cannot be specified", CC
);
6896 Error_Msg_N
("illegal component name", CC
);
6900 Comp
:= First_Entity
(Rectype
);
6901 while Present
(Comp
) loop
6902 exit when Chars
(Comp
) = Chars
(Component_Name
(CC
));
6908 -- Maybe component of base type that is absent from
6909 -- statically constrained first subtype.
6911 Comp
:= First_Entity
(Base_Type
(Rectype
));
6912 while Present
(Comp
) loop
6913 exit when Chars
(Comp
) = Chars
(Component_Name
(CC
));
6920 ("component clause is for non-existent field", CC
);
6922 -- Ada 2012 (AI05-0026): Any name that denotes a
6923 -- discriminant of an object of an unchecked union type
6924 -- shall not occur within a record_representation_clause.
6926 -- The general restriction of using record rep clauses on
6927 -- Unchecked_Union types has now been lifted. Since it is
6928 -- possible to introduce a record rep clause which mentions
6929 -- the discriminant of an Unchecked_Union in non-Ada 2012
6930 -- code, this check is applied to all versions of the
6933 elsif Ekind
(Comp
) = E_Discriminant
6934 and then Is_Unchecked_Union
(Rectype
)
6937 ("cannot reference discriminant of unchecked union",
6938 Component_Name
(CC
));
6940 elsif Is_Record_Extension
and then Is_Inherited
(Comp
) then
6942 ("component clause not allowed for inherited "
6943 & "component&", CC
, Comp
);
6945 elsif Present
(Component_Clause
(Comp
)) then
6947 -- Diagnose duplicate rep clause, or check consistency
6948 -- if this is an inherited component. In a double fault,
6949 -- there may be a duplicate inconsistent clause for an
6950 -- inherited component.
6952 if Scope
(Original_Record_Component
(Comp
)) = Rectype
6953 or else Parent
(Component_Clause
(Comp
)) = N
6955 Error_Msg_Sloc
:= Sloc
(Component_Clause
(Comp
));
6956 Error_Msg_N
("component clause previously given#", CC
);
6960 Rep1
: constant Node_Id
:= Component_Clause
(Comp
);
6962 if Intval
(Position
(Rep1
)) /=
6963 Intval
(Position
(CC
))
6964 or else Intval
(First_Bit
(Rep1
)) /=
6965 Intval
(First_Bit
(CC
))
6966 or else Intval
(Last_Bit
(Rep1
)) /=
6967 Intval
(Last_Bit
(CC
))
6970 ("component clause inconsistent with "
6971 & "representation of ancestor", CC
);
6973 elsif Warn_On_Redundant_Constructs
then
6975 ("?r?redundant confirming component clause "
6976 & "for component!", CC
);
6981 -- Normal case where this is the first component clause we
6982 -- have seen for this entity, so set it up properly.
6985 -- Make reference for field in record rep clause and set
6986 -- appropriate entity field in the field identifier.
6989 (Comp
, Component_Name
(CC
), Set_Ref
=> False);
6990 Set_Entity
(Component_Name
(CC
), Comp
);
6992 -- Update Fbit and Lbit to the actual bit number
6994 Fbit
:= Fbit
+ UI_From_Int
(SSU
) * Posit
;
6995 Lbit
:= Lbit
+ UI_From_Int
(SSU
) * Posit
;
6997 if Has_Size_Clause
(Rectype
)
6998 and then RM_Size
(Rectype
) <= Lbit
7001 ("bit number out of range of specified size",
7004 Set_Component_Clause
(Comp
, CC
);
7005 Set_Component_Bit_Offset
(Comp
, Fbit
);
7006 Set_Esize
(Comp
, 1 + (Lbit
- Fbit
));
7007 Set_Normalized_First_Bit
(Comp
, Fbit
mod SSU
);
7008 Set_Normalized_Position
(Comp
, Fbit
/ SSU
);
7010 if Warn_On_Overridden_Size
7011 and then Has_Size_Clause
(Etype
(Comp
))
7012 and then RM_Size
(Etype
(Comp
)) /= Esize
(Comp
)
7015 ("?S?component size overrides size clause for&",
7016 Component_Name
(CC
), Etype
(Comp
));
7019 -- This information is also set in the corresponding
7020 -- component of the base type, found by accessing the
7021 -- Original_Record_Component link if it is present.
7023 Ocomp
:= Original_Record_Component
(Comp
);
7030 (Component_Name
(CC
),
7036 (Comp
, First_Node
(CC
), "component clause", Biased
);
7038 if Present
(Ocomp
) then
7039 Set_Component_Clause
(Ocomp
, CC
);
7040 Set_Component_Bit_Offset
(Ocomp
, Fbit
);
7041 Set_Normalized_First_Bit
(Ocomp
, Fbit
mod SSU
);
7042 Set_Normalized_Position
(Ocomp
, Fbit
/ SSU
);
7043 Set_Esize
(Ocomp
, 1 + (Lbit
- Fbit
));
7045 Set_Normalized_Position_Max
7046 (Ocomp
, Normalized_Position
(Ocomp
));
7048 -- Note: we don't use Set_Biased here, because we
7049 -- already gave a warning above if needed, and we
7050 -- would get a duplicate for the same name here.
7052 Set_Has_Biased_Representation
7053 (Ocomp
, Has_Biased_Representation
(Comp
));
7056 if Esize
(Comp
) < 0 then
7057 Error_Msg_N
("component size is negative", CC
);
7068 -- Check missing components if Complete_Representation pragma appeared
7070 if Present
(CR_Pragma
) then
7071 Comp
:= First_Component_Or_Discriminant
(Rectype
);
7072 while Present
(Comp
) loop
7073 if No
(Component_Clause
(Comp
)) then
7075 ("missing component clause for &", CR_Pragma
, Comp
);
7078 Next_Component_Or_Discriminant
(Comp
);
7081 -- Give missing components warning if required
7083 elsif Warn_On_Unrepped_Components
then
7085 Num_Repped_Components
: Nat
:= 0;
7086 Num_Unrepped_Components
: Nat
:= 0;
7089 -- First count number of repped and unrepped components
7091 Comp
:= First_Component_Or_Discriminant
(Rectype
);
7092 while Present
(Comp
) loop
7093 if Present
(Component_Clause
(Comp
)) then
7094 Num_Repped_Components
:= Num_Repped_Components
+ 1;
7096 Num_Unrepped_Components
:= Num_Unrepped_Components
+ 1;
7099 Next_Component_Or_Discriminant
(Comp
);
7102 -- We are only interested in the case where there is at least one
7103 -- unrepped component, and at least half the components have rep
7104 -- clauses. We figure that if less than half have them, then the
7105 -- partial rep clause is really intentional. If the component
7106 -- type has no underlying type set at this point (as for a generic
7107 -- formal type), we don't know enough to give a warning on the
7110 if Num_Unrepped_Components
> 0
7111 and then Num_Unrepped_Components
< Num_Repped_Components
7113 Comp
:= First_Component_Or_Discriminant
(Rectype
);
7114 while Present
(Comp
) loop
7115 if No
(Component_Clause
(Comp
))
7116 and then Comes_From_Source
(Comp
)
7117 and then Present
(Underlying_Type
(Etype
(Comp
)))
7118 and then (Is_Scalar_Type
(Underlying_Type
(Etype
(Comp
)))
7119 or else Size_Known_At_Compile_Time
7120 (Underlying_Type
(Etype
(Comp
))))
7121 and then not Has_Warnings_Off
(Rectype
)
7123 -- Ignore discriminant in unchecked union, since it is
7124 -- not there, and cannot have a component clause.
7126 and then (not Is_Unchecked_Union
(Rectype
)
7127 or else Ekind
(Comp
) /= E_Discriminant
)
7129 Error_Msg_Sloc
:= Sloc
(Comp
);
7131 ("?C?no component clause given for & declared #",
7135 Next_Component_Or_Discriminant
(Comp
);
7140 end Analyze_Record_Representation_Clause
;
7142 -------------------------------------
7143 -- Build_Discrete_Static_Predicate --
7144 -------------------------------------
7146 procedure Build_Discrete_Static_Predicate
7151 Loc
: constant Source_Ptr
:= Sloc
(Expr
);
7153 Non_Static
: exception;
7154 -- Raised if something non-static is found
7156 Btyp
: constant Entity_Id
:= Base_Type
(Typ
);
7158 BLo
: constant Uint
:= Expr_Value
(Type_Low_Bound
(Btyp
));
7159 BHi
: constant Uint
:= Expr_Value
(Type_High_Bound
(Btyp
));
7160 -- Low bound and high bound value of base type of Typ
7164 -- Bounds for constructing the static predicate. We use the bound of the
7165 -- subtype if it is static, otherwise the corresponding base type bound.
7166 -- Note: a non-static subtype can have a static predicate.
7171 -- One entry in a Rlist value, a single REnt (range entry) value denotes
7172 -- one range from Lo to Hi. To represent a single value range Lo = Hi =
7175 type RList
is array (Nat
range <>) of REnt
;
7176 -- A list of ranges. The ranges are sorted in increasing order, and are
7177 -- disjoint (there is a gap of at least one value between each range in
7178 -- the table). A value is in the set of ranges in Rlist if it lies
7179 -- within one of these ranges.
7181 False_Range
: constant RList
:=
7182 RList
'(1 .. 0 => REnt'(No_Uint
, No_Uint
));
7183 -- An empty set of ranges represents a range list that can never be
7184 -- satisfied, since there are no ranges in which the value could lie,
7185 -- so it does not lie in any of them. False_Range is a canonical value
7186 -- for this empty set, but general processing should test for an Rlist
7187 -- with length zero (see Is_False predicate), since other null ranges
7188 -- may appear which must be treated as False.
7190 True_Range
: constant RList
:= RList
'(1 => REnt'(BLo
, BHi
));
7191 -- Range representing True, value must be in the base range
7193 function "and" (Left
: RList
; Right
: RList
) return RList
;
7194 -- And's together two range lists, returning a range list. This is a set
7195 -- intersection operation.
7197 function "or" (Left
: RList
; Right
: RList
) return RList
;
7198 -- Or's together two range lists, returning a range list. This is a set
7201 function "not" (Right
: RList
) return RList
;
7202 -- Returns complement of a given range list, i.e. a range list
7203 -- representing all the values in TLo .. THi that are not in the input
7206 function Build_Val
(V
: Uint
) return Node_Id
;
7207 -- Return an analyzed N_Identifier node referencing this value, suitable
7208 -- for use as an entry in the Static_Discrte_Predicate list. This node
7209 -- is typed with the base type.
7211 function Build_Range
(Lo
: Uint
; Hi
: Uint
) return Node_Id
;
7212 -- Return an analyzed N_Range node referencing this range, suitable for
7213 -- use as an entry in the Static_Discrete_Predicate list. This node is
7214 -- typed with the base type.
7216 function Get_RList
(Exp
: Node_Id
) return RList
;
7217 -- This is a recursive routine that converts the given expression into a
7218 -- list of ranges, suitable for use in building the static predicate.
7220 function Is_False
(R
: RList
) return Boolean;
7221 pragma Inline
(Is_False
);
7222 -- Returns True if the given range list is empty, and thus represents a
7223 -- False list of ranges that can never be satisfied.
7225 function Is_True
(R
: RList
) return Boolean;
7226 -- Returns True if R trivially represents the True predicate by having a
7227 -- single range from BLo to BHi.
7229 function Is_Type_Ref
(N
: Node_Id
) return Boolean;
7230 pragma Inline
(Is_Type_Ref
);
7231 -- Returns if True if N is a reference to the type for the predicate in
7232 -- the expression (i.e. if it is an identifier whose Chars field matches
7233 -- the Nam given in the call). N must not be parenthesized, if the type
7234 -- name appears in parens, this routine will return False.
7236 function Lo_Val
(N
: Node_Id
) return Uint
;
7237 -- Given an entry from a Static_Discrete_Predicate list that is either
7238 -- a static expression or static range, gets either the expression value
7239 -- or the low bound of the range.
7241 function Hi_Val
(N
: Node_Id
) return Uint
;
7242 -- Given an entry from a Static_Discrete_Predicate list that is either
7243 -- a static expression or static range, gets either the expression value
7244 -- or the high bound of the range.
7246 function Membership_Entry
(N
: Node_Id
) return RList
;
7247 -- Given a single membership entry (range, value, or subtype), returns
7248 -- the corresponding range list. Raises Static_Error if not static.
7250 function Membership_Entries
(N
: Node_Id
) return RList
;
7251 -- Given an element on an alternatives list of a membership operation,
7252 -- returns the range list corresponding to this entry and all following
7253 -- entries (i.e. returns the "or" of this list of values).
7255 function Stat_Pred
(Typ
: Entity_Id
) return RList
;
7256 -- Given a type, if it has a static predicate, then return the predicate
7257 -- as a range list, otherwise raise Non_Static.
7263 function "and" (Left
: RList
; Right
: RList
) return RList
is
7265 -- First range of result
7267 SLeft
: Nat
:= Left
'First;
7268 -- Start of rest of left entries
7270 SRight
: Nat
:= Right
'First;
7271 -- Start of rest of right entries
7274 -- If either range is True, return the other
7276 if Is_True
(Left
) then
7278 elsif Is_True
(Right
) then
7282 -- If either range is False, return False
7284 if Is_False
(Left
) or else Is_False
(Right
) then
7288 -- Loop to remove entries at start that are disjoint, and thus just
7289 -- get discarded from the result entirely.
7292 -- If no operands left in either operand, result is false
7294 if SLeft
> Left
'Last or else SRight
> Right
'Last then
7297 -- Discard first left operand entry if disjoint with right
7299 elsif Left
(SLeft
).Hi
< Right
(SRight
).Lo
then
7302 -- Discard first right operand entry if disjoint with left
7304 elsif Right
(SRight
).Hi
< Left
(SLeft
).Lo
then
7305 SRight
:= SRight
+ 1;
7307 -- Otherwise we have an overlapping entry
7314 -- Now we have two non-null operands, and first entries overlap. The
7315 -- first entry in the result will be the overlapping part of these
7318 FEnt
:= REnt
'(Lo => UI_Max (Left (SLeft).Lo, Right (SRight).Lo),
7319 Hi => UI_Min (Left (SLeft).Hi, Right (SRight).Hi));
7321 -- Now we can remove the entry that ended at a lower value, since its
7322 -- contribution is entirely contained in Fent.
7324 if Left (SLeft).Hi <= Right (SRight).Hi then
7327 SRight := SRight + 1;
7330 -- Compute result by concatenating this first entry with the "and" of
7331 -- the remaining parts of the left and right operands. Note that if
7332 -- either of these is empty, "and" will yield empty, so that we will
7333 -- end up with just Fent, which is what we want in that case.
7336 FEnt & (Left (SLeft .. Left'Last) and Right (SRight .. Right'Last));
7343 function "not" (Right : RList) return RList is
7345 -- Return True if False range
7347 if Is_False (Right) then
7351 -- Return False if True range
7353 if Is_True (Right) then
7357 -- Here if not trivial case
7360 Result : RList (1 .. Right'Length + 1);
7361 -- May need one more entry for gap at beginning and end
7364 -- Number of entries stored in Result
7369 if Right (Right'First).Lo > TLo then
7371 Result (Count) := REnt'(TLo
, Right
(Right
'First).Lo
- 1);
7374 -- Gaps between ranges
7376 for J
in Right
'First .. Right
'Last - 1 loop
7378 Result
(Count
) := REnt
'(Right (J).Hi + 1, Right (J + 1).Lo - 1);
7383 if Right (Right'Last).Hi < THi then
7385 Result (Count) := REnt'(Right
(Right
'Last).Hi
+ 1, THi
);
7388 return Result
(1 .. Count
);
7396 function "or" (Left
: RList
; Right
: RList
) return RList
is
7398 -- First range of result
7400 SLeft
: Nat
:= Left
'First;
7401 -- Start of rest of left entries
7403 SRight
: Nat
:= Right
'First;
7404 -- Start of rest of right entries
7407 -- If either range is True, return True
7409 if Is_True
(Left
) or else Is_True
(Right
) then
7413 -- If either range is False (empty), return the other
7415 if Is_False
(Left
) then
7417 elsif Is_False
(Right
) then
7421 -- Initialize result first entry from left or right operand depending
7422 -- on which starts with the lower range.
7424 if Left
(SLeft
).Lo
< Right
(SRight
).Lo
then
7425 FEnt
:= Left
(SLeft
);
7428 FEnt
:= Right
(SRight
);
7429 SRight
:= SRight
+ 1;
7432 -- This loop eats ranges from left and right operands that are
7433 -- contiguous with the first range we are gathering.
7436 -- Eat first entry in left operand if contiguous or overlapped by
7437 -- gathered first operand of result.
7439 if SLeft
<= Left
'Last
7440 and then Left
(SLeft
).Lo
<= FEnt
.Hi
+ 1
7442 FEnt
.Hi
:= UI_Max
(FEnt
.Hi
, Left
(SLeft
).Hi
);
7445 -- Eat first entry in right operand if contiguous or overlapped by
7446 -- gathered right operand of result.
7448 elsif SRight
<= Right
'Last
7449 and then Right
(SRight
).Lo
<= FEnt
.Hi
+ 1
7451 FEnt
.Hi
:= UI_Max
(FEnt
.Hi
, Right
(SRight
).Hi
);
7452 SRight
:= SRight
+ 1;
7454 -- All done if no more entries to eat
7461 -- Obtain result as the first entry we just computed, concatenated
7462 -- to the "or" of the remaining results (if one operand is empty,
7463 -- this will just concatenate with the other
7466 FEnt
& (Left
(SLeft
.. Left
'Last) or Right
(SRight
.. Right
'Last));
7473 function Build_Range
(Lo
: Uint
; Hi
: Uint
) return Node_Id
is
7478 Low_Bound
=> Build_Val
(Lo
),
7479 High_Bound
=> Build_Val
(Hi
));
7480 Set_Etype
(Result
, Btyp
);
7481 Set_Analyzed
(Result
);
7489 function Build_Val
(V
: Uint
) return Node_Id
is
7493 if Is_Enumeration_Type
(Typ
) then
7494 Result
:= Get_Enum_Lit_From_Pos
(Typ
, V
, Loc
);
7496 Result
:= Make_Integer_Literal
(Loc
, V
);
7499 Set_Etype
(Result
, Btyp
);
7500 Set_Is_Static_Expression
(Result
);
7501 Set_Analyzed
(Result
);
7509 function Get_RList
(Exp
: Node_Id
) return RList
is
7514 -- Static expression can only be true or false
7516 if Is_OK_Static_Expression
(Exp
) then
7517 if Expr_Value
(Exp
) = 0 then
7524 -- Otherwise test node type
7532 when N_Op_And | N_And_Then
=>
7533 return Get_RList
(Left_Opnd
(Exp
))
7535 Get_RList
(Right_Opnd
(Exp
));
7539 when N_Op_Or | N_Or_Else
=>
7540 return Get_RList
(Left_Opnd
(Exp
))
7542 Get_RList
(Right_Opnd
(Exp
));
7547 return not Get_RList
(Right_Opnd
(Exp
));
7549 -- Comparisons of type with static value
7551 when N_Op_Compare
=>
7553 -- Type is left operand
7555 if Is_Type_Ref
(Left_Opnd
(Exp
))
7556 and then Is_OK_Static_Expression
(Right_Opnd
(Exp
))
7558 Val
:= Expr_Value
(Right_Opnd
(Exp
));
7560 -- Typ is right operand
7562 elsif Is_Type_Ref
(Right_Opnd
(Exp
))
7563 and then Is_OK_Static_Expression
(Left_Opnd
(Exp
))
7565 Val
:= Expr_Value
(Left_Opnd
(Exp
));
7567 -- Invert sense of comparison
7570 when N_Op_Gt
=> Op
:= N_Op_Lt
;
7571 when N_Op_Lt
=> Op
:= N_Op_Gt
;
7572 when N_Op_Ge
=> Op
:= N_Op_Le
;
7573 when N_Op_Le
=> Op
:= N_Op_Ge
;
7574 when others => null;
7577 -- Other cases are non-static
7583 -- Construct range according to comparison operation
7587 return RList
'(1 => REnt'(Val
, Val
));
7590 return RList
'(1 => REnt'(Val
, BHi
));
7593 return RList
'(1 => REnt'(Val
+ 1, BHi
));
7596 return RList
'(1 => REnt'(BLo
, Val
));
7599 return RList
'(1 => REnt'(BLo
, Val
- 1));
7602 return RList
'(REnt'(BLo
, Val
- 1), REnt
'(Val + 1, BHi));
7605 raise Program_Error;
7611 if not Is_Type_Ref (Left_Opnd (Exp)) then
7615 if Present (Right_Opnd (Exp)) then
7616 return Membership_Entry (Right_Opnd (Exp));
7618 return Membership_Entries (First (Alternatives (Exp)));
7621 -- Negative membership (NOT IN)
7624 if not Is_Type_Ref (Left_Opnd (Exp)) then
7628 if Present (Right_Opnd (Exp)) then
7629 return not Membership_Entry (Right_Opnd (Exp));
7631 return not Membership_Entries (First (Alternatives (Exp)));
7634 -- Function call, may be call to static predicate
7636 when N_Function_Call =>
7637 if Is_Entity_Name (Name (Exp)) then
7639 Ent : constant Entity_Id := Entity (Name (Exp));
7641 if Is_Predicate_Function (Ent)
7643 Is_Predicate_Function_M (Ent)
7645 return Stat_Pred (Etype (First_Formal (Ent)));
7650 -- Other function call cases are non-static
7654 -- Qualified expression, dig out the expression
7656 when N_Qualified_Expression =>
7657 return Get_RList (Expression (Exp));
7659 when N_Case_Expression =>
7666 if not Is_Entity_Name (Expression (Expr))
7667 or else Etype (Expression (Expr)) /= Typ
7670 ("expression must denaote subtype", Expression (Expr));
7674 -- Collect discrete choices in all True alternatives
7676 Choices := New_List;
7677 Alt := First (Alternatives (Exp));
7678 while Present (Alt) loop
7679 Dep := Expression (Alt);
7681 if not Is_OK_Static_Expression (Dep) then
7684 elsif Is_True (Expr_Value (Dep)) then
7685 Append_List_To (Choices,
7686 New_Copy_List (Discrete_Choices (Alt)));
7692 return Membership_Entries (First (Choices));
7695 -- Expression with actions: if no actions, dig out expression
7697 when N_Expression_With_Actions =>
7698 if Is_Empty_List (Actions (Exp)) then
7699 return Get_RList (Expression (Exp));
7707 return (Get_RList (Left_Opnd (Exp))
7708 and not Get_RList (Right_Opnd (Exp)))
7709 or (Get_RList (Right_Opnd (Exp))
7710 and not Get_RList (Left_Opnd (Exp)));
7712 -- Any other node type is non-static
7723 function Hi_Val (N : Node_Id) return Uint is
7725 if Is_OK_Static_Expression (N) then
7726 return Expr_Value (N);
7728 pragma Assert (Nkind (N) = N_Range);
7729 return Expr_Value (High_Bound (N));
7737 function Is_False (R : RList) return Boolean is
7739 return R'Length = 0;
7746 function Is_True (R : RList) return Boolean is
7749 and then R (R'First).Lo = BLo
7750 and then R (R'First).Hi = BHi;
7757 function Is_Type_Ref (N : Node_Id) return Boolean is
7759 return Nkind (N) = N_Identifier
7760 and then Chars (N) = Nam
7761 and then Paren_Count (N) = 0;
7768 function Lo_Val (N : Node_Id) return Uint is
7770 if Is_OK_Static_Expression (N) then
7771 return Expr_Value (N);
7773 pragma Assert (Nkind (N) = N_Range);
7774 return Expr_Value (Low_Bound (N));
7778 ------------------------
7779 -- Membership_Entries --
7780 ------------------------
7782 function Membership_Entries (N : Node_Id) return RList is
7784 if No (Next (N)) then
7785 return Membership_Entry (N);
7787 return Membership_Entry (N) or Membership_Entries (Next (N));
7789 end Membership_Entries;
7791 ----------------------
7792 -- Membership_Entry --
7793 ----------------------
7795 function Membership_Entry (N : Node_Id) return RList is
7803 if Nkind (N) = N_Range then
7804 if not Is_OK_Static_Expression (Low_Bound (N))
7806 not Is_OK_Static_Expression (High_Bound (N))
7810 SLo := Expr_Value (Low_Bound (N));
7811 SHi := Expr_Value (High_Bound (N));
7812 return RList'(1 => REnt
'(SLo, SHi));
7815 -- Static expression case
7817 elsif Is_OK_Static_Expression (N) then
7818 Val := Expr_Value (N);
7819 return RList'(1 => REnt
'(Val, Val));
7821 -- Identifier (other than static expression) case
7823 else pragma Assert (Nkind (N) = N_Identifier);
7827 if Is_Type (Entity (N)) then
7829 -- If type has predicates, process them
7831 if Has_Predicates (Entity (N)) then
7832 return Stat_Pred (Entity (N));
7834 -- For static subtype without predicates, get range
7836 elsif Is_OK_Static_Subtype (Entity (N)) then
7837 SLo := Expr_Value (Type_Low_Bound (Entity (N)));
7838 SHi := Expr_Value (Type_High_Bound (Entity (N)));
7839 return RList'(1 => REnt
'(SLo, SHi));
7841 -- Any other type makes us non-static
7847 -- Any other kind of identifier in predicate (e.g. a non-static
7848 -- expression value) means this is not a static predicate.
7854 end Membership_Entry;
7860 function Stat_Pred (Typ : Entity_Id) return RList is
7862 -- Not static if type does not have static predicates
7864 if not Has_Static_Predicate (Typ) then
7868 -- Otherwise we convert the predicate list to a range list
7871 Spred : constant List_Id := Static_Discrete_Predicate (Typ);
7872 Result : RList (1 .. List_Length (Spred));
7876 P := First (Static_Discrete_Predicate (Typ));
7877 for J in Result'Range loop
7878 Result (J) := REnt'(Lo_Val
(P
), Hi_Val
(P
));
7886 -- Start of processing for Build_Discrete_Static_Predicate
7889 -- Establish bounds for the predicate
7891 if Compile_Time_Known_Value
(Type_Low_Bound
(Typ
)) then
7892 TLo
:= Expr_Value
(Type_Low_Bound
(Typ
));
7897 if Compile_Time_Known_Value
(Type_High_Bound
(Typ
)) then
7898 THi
:= Expr_Value
(Type_High_Bound
(Typ
));
7903 -- Analyze the expression to see if it is a static predicate
7906 Ranges
: constant RList
:= Get_RList
(Expr
);
7907 -- Range list from expression if it is static
7912 -- Convert range list into a form for the static predicate. In the
7913 -- Ranges array, we just have raw ranges, these must be converted
7914 -- to properly typed and analyzed static expressions or range nodes.
7916 -- Note: here we limit ranges to the ranges of the subtype, so that
7917 -- a predicate is always false for values outside the subtype. That
7918 -- seems fine, such values are invalid anyway, and considering them
7919 -- to fail the predicate seems allowed and friendly, and furthermore
7920 -- simplifies processing for case statements and loops.
7924 for J
in Ranges
'Range loop
7926 Lo
: Uint
:= Ranges
(J
).Lo
;
7927 Hi
: Uint
:= Ranges
(J
).Hi
;
7930 -- Ignore completely out of range entry
7932 if Hi
< TLo
or else Lo
> THi
then
7935 -- Otherwise process entry
7938 -- Adjust out of range value to subtype range
7948 -- Convert range into required form
7950 Append_To
(Plist
, Build_Range
(Lo
, Hi
));
7955 -- Processing was successful and all entries were static, so now we
7956 -- can store the result as the predicate list.
7958 Set_Static_Discrete_Predicate
(Typ
, Plist
);
7960 -- The processing for static predicates put the expression into
7961 -- canonical form as a series of ranges. It also eliminated
7962 -- duplicates and collapsed and combined ranges. We might as well
7963 -- replace the alternatives list of the right operand of the
7964 -- membership test with the static predicate list, which will
7965 -- usually be more efficient.
7968 New_Alts
: constant List_Id
:= New_List
;
7973 Old_Node
:= First
(Plist
);
7974 while Present
(Old_Node
) loop
7975 New_Node
:= New_Copy
(Old_Node
);
7977 if Nkind
(New_Node
) = N_Range
then
7978 Set_Low_Bound
(New_Node
, New_Copy
(Low_Bound
(Old_Node
)));
7979 Set_High_Bound
(New_Node
, New_Copy
(High_Bound
(Old_Node
)));
7982 Append_To
(New_Alts
, New_Node
);
7986 -- If empty list, replace by False
7988 if Is_Empty_List
(New_Alts
) then
7989 Rewrite
(Expr
, New_Occurrence_Of
(Standard_False
, Loc
));
7991 -- Else replace by set membership test
7996 Left_Opnd
=> Make_Identifier
(Loc
, Nam
),
7997 Right_Opnd
=> Empty
,
7998 Alternatives
=> New_Alts
));
8000 -- Resolve new expression in function context
8002 Install_Formals
(Predicate_Function
(Typ
));
8003 Push_Scope
(Predicate_Function
(Typ
));
8004 Analyze_And_Resolve
(Expr
, Standard_Boolean
);
8010 -- If non-static, return doing nothing
8015 end Build_Discrete_Static_Predicate
;
8017 --------------------------------
8018 -- Build_Export_Import_Pragma --
8019 --------------------------------
8021 function Build_Export_Import_Pragma
8023 Id
: Entity_Id
) return Node_Id
8025 Asp_Id
: constant Aspect_Id
:= Get_Aspect_Id
(Asp
);
8026 Expr
: constant Node_Id
:= Expression
(Asp
);
8027 Loc
: constant Source_Ptr
:= Sloc
(Asp
);
8038 Create_Pragma
: Boolean := False;
8039 -- This flag is set when the aspect form is such that it warrants the
8040 -- creation of a corresponding pragma.
8043 if Present
(Expr
) then
8044 if Error_Posted
(Expr
) then
8047 elsif Is_True
(Expr_Value
(Expr
)) then
8048 Create_Pragma
:= True;
8051 -- Otherwise the aspect defaults to True
8054 Create_Pragma
:= True;
8057 -- Nothing to do when the expression is False or is erroneous
8059 if not Create_Pragma
then
8063 -- Obtain all interfacing aspects that apply to the related entity
8065 Get_Interfacing_Aspects
8069 Expo_Asp
=> Dummy_1
,
8075 -- Handle the convention argument
8077 if Present
(Conv
) then
8078 Conv_Arg
:= New_Copy_Tree
(Expression
(Conv
));
8080 -- Assume convention "Ada' when aspect Convention is missing
8083 Conv_Arg
:= Make_Identifier
(Loc
, Name_Ada
);
8087 Make_Pragma_Argument_Association
(Loc
,
8088 Chars
=> Name_Convention
,
8089 Expression
=> Conv_Arg
));
8091 -- Handle the entity argument
8094 Make_Pragma_Argument_Association
(Loc
,
8095 Chars
=> Name_Entity
,
8096 Expression
=> New_Occurrence_Of
(Id
, Loc
)));
8098 -- Handle the External_Name argument
8100 if Present
(EN
) then
8102 Make_Pragma_Argument_Association
(Loc
,
8103 Chars
=> Name_External_Name
,
8104 Expression
=> New_Copy_Tree
(Expression
(EN
))));
8107 -- Handle the Link_Name argument
8109 if Present
(LN
) then
8111 Make_Pragma_Argument_Association
(Loc
,
8112 Chars
=> Name_Link_Name
,
8113 Expression
=> New_Copy_Tree
(Expression
(LN
))));
8117 -- pragma Export/Import
8118 -- (Convention => <Conv>/Ada,
8120 -- [External_Name => <EN>,]
8121 -- [Link_Name => <LN>]);
8125 Pragma_Identifier
=>
8126 Make_Identifier
(Loc
, Chars
(Identifier
(Asp
))),
8127 Pragma_Argument_Associations
=> Args
);
8129 -- Decorate the relevant aspect and the pragma
8131 Set_Aspect_Rep_Item
(Asp
, Prag
);
8133 Set_Corresponding_Aspect
(Prag
, Asp
);
8134 Set_From_Aspect_Specification
(Prag
);
8135 Set_Parent
(Prag
, Asp
);
8137 if Asp_Id
= Aspect_Import
and then Is_Subprogram
(Id
) then
8138 Set_Import_Pragma
(Id
, Prag
);
8142 end Build_Export_Import_Pragma
;
8144 -------------------------------
8145 -- Build_Predicate_Functions --
8146 -------------------------------
8148 -- The procedures that are constructed here have the form:
8150 -- function typPredicate (Ixxx : typ) return Boolean is
8153 -- typ1Predicate (typ1 (Ixxx))
8154 -- and then typ2Predicate (typ2 (Ixxx))
8156 -- exp1 and then exp2 and then ...
8157 -- end typPredicate;
8159 -- Here exp1, and exp2 are expressions from Predicate pragmas. Note that
8160 -- this is the point at which these expressions get analyzed, providing the
8161 -- required delay, and typ1, typ2, are entities from which predicates are
8162 -- inherited. Note that we do NOT generate Check pragmas, that's because we
8163 -- use this function even if checks are off, e.g. for membership tests.
8165 -- Note that the inherited predicates are evaluated first, as required by
8168 -- Note that Sem_Eval.Real_Or_String_Static_Predicate_Matches depends on
8169 -- the form of this return expression.
8171 -- If the expression has at least one Raise_Expression, then we also build
8172 -- the typPredicateM version of the function, in which any occurrence of a
8173 -- Raise_Expression is converted to "return False".
8175 procedure Build_Predicate_Functions
(Typ
: Entity_Id
; N
: Node_Id
) is
8176 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
8179 -- This is the expression for the result of the function. It is
8180 -- is build by connecting the component predicates with AND THEN.
8183 -- This is the corresponding return expression for the Predicate_M
8184 -- function. It differs in that raise expressions are marked for
8185 -- special expansion (see Process_REs).
8187 Object_Name
: Name_Id
;
8188 -- Name for argument of Predicate procedure. Note that we use the same
8189 -- name for both predicate functions. That way the reference within the
8190 -- predicate expression is the same in both functions.
8192 Object_Entity
: Entity_Id
;
8193 -- Entity for argument of Predicate procedure
8195 Object_Entity_M
: Entity_Id
;
8196 -- Entity for argument of separate Predicate procedure when exceptions
8197 -- are present in expression.
8200 -- The function declaration
8205 Raise_Expression_Present
: Boolean := False;
8206 -- Set True if Expr has at least one Raise_Expression
8208 procedure Add_Condition
(Cond
: Node_Id
);
8209 -- Append Cond to Expr using "and then" (or just copy Cond to Expr if
8212 procedure Add_Predicates
;
8213 -- Appends expressions for any Predicate pragmas in the rep item chain
8214 -- Typ to Expr. Note that we look only at items for this exact entity.
8215 -- Inheritance of predicates for the parent type is done by calling the
8216 -- Predicate_Function of the parent type, using Add_Call above.
8218 procedure Add_Call
(T
: Entity_Id
);
8219 -- Includes a call to the predicate function for type T in Expr if T
8220 -- has predicates and Predicate_Function (T) is non-empty.
8222 function Process_RE
(N
: Node_Id
) return Traverse_Result
;
8223 -- Used in Process REs, tests if node N is a raise expression, and if
8224 -- so, marks it to be converted to return False.
8226 procedure Process_REs
is new Traverse_Proc
(Process_RE
);
8227 -- Marks any raise expressions in Expr_M to return False
8229 function Test_RE
(N
: Node_Id
) return Traverse_Result
;
8230 -- Used in Test_REs, tests one node for being a raise expression, and if
8231 -- so sets Raise_Expression_Present True.
8233 procedure Test_REs
is new Traverse_Proc
(Test_RE
);
8234 -- Tests to see if Expr contains any raise expressions
8240 procedure Add_Call
(T
: Entity_Id
) is
8244 if Present
(T
) and then Present
(Predicate_Function
(T
)) then
8245 Set_Has_Predicates
(Typ
);
8247 -- Build the call to the predicate function of T
8251 (T
, Convert_To
(T
, Make_Identifier
(Loc
, Object_Name
)));
8253 -- "and"-in the call to evolving expression
8255 Add_Condition
(Exp
);
8257 -- Output info message on inheritance if required. Note we do not
8258 -- give this information for generic actual types, since it is
8259 -- unwelcome noise in that case in instantiations. We also
8260 -- generally suppress the message in instantiations, and also
8261 -- if it involves internal names.
8263 if Opt
.List_Inherited_Aspects
8264 and then not Is_Generic_Actual_Type
(Typ
)
8265 and then Instantiation_Depth
(Sloc
(Typ
)) = 0
8266 and then not Is_Internal_Name
(Chars
(T
))
8267 and then not Is_Internal_Name
(Chars
(Typ
))
8269 Error_Msg_Sloc
:= Sloc
(Predicate_Function
(T
));
8270 Error_Msg_Node_2
:= T
;
8271 Error_Msg_N
("info: & inherits predicate from & #?L?", Typ
);
8280 procedure Add_Condition
(Cond
: Node_Id
) is
8282 -- This is the first predicate expression
8287 -- Otherwise concatenate to the existing predicate expressions by
8288 -- using "and then".
8293 Left_Opnd
=> Relocate_Node
(Expr
),
8294 Right_Opnd
=> Cond
);
8298 --------------------
8299 -- Add_Predicates --
8300 --------------------
8302 procedure Add_Predicates
is
8303 procedure Add_Predicate
(Prag
: Node_Id
);
8304 -- Concatenate the expression of predicate pragma Prag to Expr by
8305 -- using a short circuit "and then" operator.
8311 procedure Add_Predicate
(Prag
: Node_Id
) is
8312 procedure Replace_Type_Reference
(N
: Node_Id
);
8313 -- Replace a single occurrence N of the subtype name with a
8314 -- reference to the formal of the predicate function. N can be an
8315 -- identifier referencing the subtype, or a selected component,
8316 -- representing an appropriately qualified occurrence of the
8319 procedure Replace_Type_References
is
8320 new Replace_Type_References_Generic
(Replace_Type_Reference
);
8321 -- Traverse an expression changing every occurrence of an
8322 -- identifier whose name matches the name of the subtype with a
8323 -- reference to the formal parameter of the predicate function.
8325 ----------------------------
8326 -- Replace_Type_Reference --
8327 ----------------------------
8329 procedure Replace_Type_Reference
(N
: Node_Id
) is
8331 Rewrite
(N
, Make_Identifier
(Sloc
(N
), Object_Name
));
8332 -- Use the Sloc of the usage name, not the defining name
8335 Set_Entity
(N
, Object_Entity
);
8337 -- We want to treat the node as if it comes from source, so
8338 -- that ASIS will not ignore it.
8340 Set_Comes_From_Source
(N
, True);
8341 end Replace_Type_Reference
;
8345 Asp
: constant Node_Id
:= Corresponding_Aspect
(Prag
);
8349 -- Start of processing for Add_Predicate
8352 -- Extract the arguments of the pragma. The expression itself
8353 -- is copied for use in the predicate function, to preserve the
8354 -- original version for ASIS use.
8356 Arg1
:= First
(Pragma_Argument_Associations
(Prag
));
8357 Arg2
:= Next
(Arg1
);
8359 Arg1
:= Get_Pragma_Arg
(Arg1
);
8360 Arg2
:= New_Copy_Tree
(Get_Pragma_Arg
(Arg2
));
8362 -- When the predicate pragma applies to the current type or its
8363 -- full view, replace all occurrences of the subtype name with
8364 -- references to the formal parameter of the predicate function.
8366 if Entity
(Arg1
) = Typ
8367 or else Full_View
(Entity
(Arg1
)) = Typ
8369 Replace_Type_References
(Arg2
, Typ
);
8371 -- If the predicate pragma comes from an aspect, replace the
8372 -- saved expression because we need the subtype references
8373 -- replaced for the calls to Preanalyze_Spec_Expression in
8374 -- Check_Aspect_At_xxx routines.
8376 if Present
(Asp
) then
8377 Set_Entity
(Identifier
(Asp
), New_Copy_Tree
(Arg2
));
8380 -- "and"-in the Arg2 condition to evolving expression
8382 Add_Condition
(Relocate_Node
(Arg2
));
8390 -- Start of processing for Add_Predicates
8393 Ritem
:= First_Rep_Item
(Typ
);
8394 while Present
(Ritem
) loop
8395 if Nkind
(Ritem
) = N_Pragma
8396 and then Pragma_Name
(Ritem
) = Name_Predicate
8398 Add_Predicate
(Ritem
);
8400 -- If the type is declared in an inner package it may be frozen
8401 -- outside of the package, and the generated pragma has not been
8402 -- analyzed yet, so capture the expression for the predicate
8403 -- function at this point.
8405 elsif Nkind
(Ritem
) = N_Aspect_Specification
8406 and then Present
(Aspect_Rep_Item
(Ritem
))
8407 and then Scope
(Typ
) /= Current_Scope
8410 Prag
: constant Node_Id
:= Aspect_Rep_Item
(Ritem
);
8413 if Nkind
(Prag
) = N_Pragma
8414 and then Pragma_Name
(Prag
) = Name_Predicate
8416 Add_Predicate
(Prag
);
8421 Next_Rep_Item
(Ritem
);
8429 function Process_RE
(N
: Node_Id
) return Traverse_Result
is
8431 if Nkind
(N
) = N_Raise_Expression
then
8432 Set_Convert_To_Return_False
(N
);
8443 function Test_RE
(N
: Node_Id
) return Traverse_Result
is
8445 if Nkind
(N
) = N_Raise_Expression
then
8446 Raise_Expression_Present
:= True;
8455 Save_Ghost_Mode
: constant Ghost_Mode_Type
:= Ghost_Mode
;
8457 -- Start of processing for Build_Predicate_Functions
8460 -- Return if already built or if type does not have predicates
8462 SId
:= Predicate_Function
(Typ
);
8463 if not Has_Predicates
(Typ
)
8464 or else (Present
(SId
) and then Has_Completion
(SId
))
8469 -- The related type may be subject to pragma Ghost. Set the mode now to
8470 -- ensure that the predicate functions are properly marked as Ghost.
8472 Set_Ghost_Mode_From_Entity
(Typ
);
8474 -- Prepare to construct predicate expression
8478 if Present
(SId
) then
8479 FDecl
:= Unit_Declaration_Node
(SId
);
8482 FDecl
:= Build_Predicate_Function_Declaration
(Typ
);
8483 SId
:= Defining_Entity
(FDecl
);
8486 -- Recover name of formal parameter of function that replaces references
8487 -- to the type in predicate expressions.
8491 (First
(Parameter_Specifications
(Specification
(FDecl
))));
8493 Object_Name
:= Chars
(Object_Entity
);
8494 Object_Entity_M
:= Make_Defining_Identifier
(Loc
, Chars
=> Object_Name
);
8496 -- Add predicates for ancestor if present. These must come before the
8497 -- ones for the current type, as required by AI12-0071-1.
8500 Atyp
: constant Entity_Id
:= Nearest_Ancestor
(Typ
);
8502 if Present
(Atyp
) then
8507 -- Add Predicates for the current type
8511 -- Case where predicates are present
8513 if Present
(Expr
) then
8515 -- Test for raise expression present
8519 -- If raise expression is present, capture a copy of Expr for use
8520 -- in building the predicateM function version later on. For this
8521 -- copy we replace references to Object_Entity by Object_Entity_M.
8523 if Raise_Expression_Present
then
8525 Map
: constant Elist_Id
:= New_Elmt_List
;
8526 New_V
: Entity_Id
:= Empty
;
8528 -- The unanalyzed expression will be copied and appear in
8529 -- both functions. Normally expressions do not declare new
8530 -- entities, but quantified expressions do, so we need to
8531 -- create new entities for their bound variables, to prevent
8532 -- multiple definitions in gigi.
8534 function Reset_Loop_Variable
(N
: Node_Id
)
8535 return Traverse_Result
;
8537 procedure Collect_Loop_Variables
is
8538 new Traverse_Proc
(Reset_Loop_Variable
);
8540 ------------------------
8541 -- Reset_Loop_Variable --
8542 ------------------------
8544 function Reset_Loop_Variable
(N
: Node_Id
)
8545 return Traverse_Result
8548 if Nkind
(N
) = N_Iterator_Specification
then
8549 New_V
:= Make_Defining_Identifier
8550 (Sloc
(N
), Chars
(Defining_Identifier
(N
)));
8552 Set_Defining_Identifier
(N
, New_V
);
8556 end Reset_Loop_Variable
;
8559 Append_Elmt
(Object_Entity
, Map
);
8560 Append_Elmt
(Object_Entity_M
, Map
);
8561 Expr_M
:= New_Copy_Tree
(Expr
, Map
=> Map
);
8562 Collect_Loop_Variables
(Expr_M
);
8566 -- Build the main predicate function
8569 SIdB
: constant Entity_Id
:=
8570 Make_Defining_Identifier
(Loc
,
8571 Chars
=> New_External_Name
(Chars
(Typ
), "Predicate"));
8572 -- The entity for the function body
8579 -- The predicate function is shared between views of a type
8581 if Is_Private_Type
(Typ
) and then Present
(Full_View
(Typ
)) then
8582 Set_Predicate_Function
(Full_View
(Typ
), SId
);
8585 -- Mark the predicate function explicitly as Ghost because it does
8586 -- not come from source.
8588 if Ghost_Mode
> None
then
8589 Set_Is_Ghost_Entity
(SId
);
8592 -- Build function body
8595 Make_Function_Specification
(Loc
,
8596 Defining_Unit_Name
=> SIdB
,
8597 Parameter_Specifications
=> New_List
(
8598 Make_Parameter_Specification
(Loc
,
8599 Defining_Identifier
=>
8600 Make_Defining_Identifier
(Loc
, Object_Name
),
8602 New_Occurrence_Of
(Typ
, Loc
))),
8603 Result_Definition
=>
8604 New_Occurrence_Of
(Standard_Boolean
, Loc
));
8607 Make_Subprogram_Body
(Loc
,
8608 Specification
=> Spec
,
8609 Declarations
=> Empty_List
,
8610 Handled_Statement_Sequence
=>
8611 Make_Handled_Sequence_Of_Statements
(Loc
,
8612 Statements
=> New_List
(
8613 Make_Simple_Return_Statement
(Loc
,
8614 Expression
=> Expr
))));
8616 -- If declaration has not been analyzed yet, Insert declaration
8617 -- before freeze node. Insert body itself after freeze node.
8619 if not Analyzed
(FDecl
) then
8620 Insert_Before_And_Analyze
(N
, FDecl
);
8623 Insert_After_And_Analyze
(N
, FBody
);
8625 -- Static predicate functions are always side-effect free, and
8626 -- in most cases dynamic predicate functions are as well. Mark
8627 -- them as such whenever possible, so redundant predicate checks
8628 -- can be optimized. If there is a variable reference within the
8629 -- expression, the function is not pure.
8631 if Expander_Active
then
8633 Side_Effect_Free
(Expr
, Variable_Ref
=> True));
8634 Set_Is_Inlined
(SId
);
8638 -- Test for raise expressions present and if so build M version
8640 if Raise_Expression_Present
then
8642 SId
: constant Entity_Id
:=
8643 Make_Defining_Identifier
(Loc
,
8644 Chars
=> New_External_Name
(Chars
(Typ
), "PredicateM"));
8645 -- The entity for the function spec
8647 SIdB
: constant Entity_Id
:=
8648 Make_Defining_Identifier
(Loc
,
8649 Chars
=> New_External_Name
(Chars
(Typ
), "PredicateM"));
8650 -- The entity for the function body
8658 -- Mark any raise expressions for special expansion
8660 Process_REs
(Expr_M
);
8662 -- Build function declaration
8664 Set_Ekind
(SId
, E_Function
);
8665 Set_Is_Predicate_Function_M
(SId
);
8666 Set_Predicate_Function_M
(Typ
, SId
);
8668 -- The predicate function is shared between views of a type
8670 if Is_Private_Type
(Typ
) and then Present
(Full_View
(Typ
)) then
8671 Set_Predicate_Function_M
(Full_View
(Typ
), SId
);
8674 -- Mark the predicate function explicitly as Ghost because it
8675 -- does not come from source.
8677 if Ghost_Mode
> None
then
8678 Set_Is_Ghost_Entity
(SId
);
8682 Make_Function_Specification
(Loc
,
8683 Defining_Unit_Name
=> SId
,
8684 Parameter_Specifications
=> New_List
(
8685 Make_Parameter_Specification
(Loc
,
8686 Defining_Identifier
=> Object_Entity_M
,
8687 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
))),
8688 Result_Definition
=>
8689 New_Occurrence_Of
(Standard_Boolean
, Loc
));
8692 Make_Subprogram_Declaration
(Loc
,
8693 Specification
=> Spec
);
8695 -- Build function body
8698 Make_Function_Specification
(Loc
,
8699 Defining_Unit_Name
=> SIdB
,
8700 Parameter_Specifications
=> New_List
(
8701 Make_Parameter_Specification
(Loc
,
8702 Defining_Identifier
=>
8703 Make_Defining_Identifier
(Loc
, Object_Name
),
8705 New_Occurrence_Of
(Typ
, Loc
))),
8706 Result_Definition
=>
8707 New_Occurrence_Of
(Standard_Boolean
, Loc
));
8709 -- Build the body, we declare the boolean expression before
8710 -- doing the return, because we are not really confident of
8711 -- what happens if a return appears within a return.
8714 Make_Defining_Identifier
(Loc
,
8715 Chars
=> New_Internal_Name
('B'));
8718 Make_Subprogram_Body
(Loc
,
8719 Specification
=> Spec
,
8721 Declarations
=> New_List
(
8722 Make_Object_Declaration
(Loc
,
8723 Defining_Identifier
=> BTemp
,
8724 Constant_Present
=> True,
8725 Object_Definition
=>
8726 New_Occurrence_Of
(Standard_Boolean
, Loc
),
8727 Expression
=> Expr_M
)),
8729 Handled_Statement_Sequence
=>
8730 Make_Handled_Sequence_Of_Statements
(Loc
,
8731 Statements
=> New_List
(
8732 Make_Simple_Return_Statement
(Loc
,
8733 Expression
=> New_Occurrence_Of
(BTemp
, Loc
)))));
8735 -- Insert declaration before freeze node and body after
8737 Insert_Before_And_Analyze
(N
, FDecl
);
8738 Insert_After_And_Analyze
(N
, FBody
);
8742 -- See if we have a static predicate. Note that the answer may be
8743 -- yes even if we have an explicit Dynamic_Predicate present.
8750 if not Is_Scalar_Type
(Typ
) and then not Is_String_Type
(Typ
) then
8753 PS
:= Is_Predicate_Static
(Expr
, Object_Name
);
8756 -- Case where we have a predicate-static aspect
8760 -- We don't set Has_Static_Predicate_Aspect, since we can have
8761 -- any of the three cases (Predicate, Dynamic_Predicate, or
8762 -- Static_Predicate) generating a predicate with an expression
8763 -- that is predicate-static. We just indicate that we have a
8764 -- predicate that can be treated as static.
8766 Set_Has_Static_Predicate
(Typ
);
8768 -- For discrete subtype, build the static predicate list
8770 if Is_Discrete_Type
(Typ
) then
8771 Build_Discrete_Static_Predicate
(Typ
, Expr
, Object_Name
);
8773 -- If we don't get a static predicate list, it means that we
8774 -- have a case where this is not possible, most typically in
8775 -- the case where we inherit a dynamic predicate. We do not
8776 -- consider this an error, we just leave the predicate as
8777 -- dynamic. But if we do succeed in building the list, then
8778 -- we mark the predicate as static.
8780 if No
(Static_Discrete_Predicate
(Typ
)) then
8781 Set_Has_Static_Predicate
(Typ
, False);
8784 -- For real or string subtype, save predicate expression
8786 elsif Is_Real_Type
(Typ
) or else Is_String_Type
(Typ
) then
8787 Set_Static_Real_Or_String_Predicate
(Typ
, Expr
);
8790 -- Case of dynamic predicate (expression is not predicate-static)
8793 -- Again, we don't set Has_Dynamic_Predicate_Aspect, since that
8794 -- is only set if we have an explicit Dynamic_Predicate aspect
8795 -- given. Here we may simply have a Predicate aspect where the
8796 -- expression happens not to be predicate-static.
8798 -- Emit an error when the predicate is categorized as static
8799 -- but its expression is not predicate-static.
8801 -- First a little fiddling to get a nice location for the
8802 -- message. If the expression is of the form (A and then B),
8803 -- where A is an inherited predicate, then use the right
8804 -- operand for the Sloc. This avoids getting confused by a call
8805 -- to an inherited predicate with a less convenient source
8809 while Nkind
(EN
) = N_And_Then
8810 and then Nkind
(Left_Opnd
(EN
)) = N_Function_Call
8811 and then Is_Predicate_Function
8812 (Entity
(Name
(Left_Opnd
(EN
))))
8814 EN
:= Right_Opnd
(EN
);
8817 -- Now post appropriate message
8819 if Has_Static_Predicate_Aspect
(Typ
) then
8820 if Is_Scalar_Type
(Typ
) or else Is_String_Type
(Typ
) then
8822 ("expression is not predicate-static (RM 3.2.4(16-22))",
8826 ("static predicate requires scalar or string type", EN
);
8833 Ghost_Mode
:= Save_Ghost_Mode
;
8834 end Build_Predicate_Functions
;
8836 ------------------------------------------
8837 -- Build_Predicate_Function_Declaration --
8838 ------------------------------------------
8840 function Build_Predicate_Function_Declaration
8841 (Typ
: Entity_Id
) return Node_Id
8843 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
8845 Object_Entity
: constant Entity_Id
:=
8846 Make_Defining_Identifier
(Loc
,
8847 Chars
=> New_Internal_Name
('I'));
8849 -- The formal parameter of the function
8851 SId
: constant Entity_Id
:=
8852 Make_Defining_Identifier
(Loc
,
8853 Chars
=> New_External_Name
(Chars
(Typ
), "Predicate"));
8855 -- The entity for the function spec
8862 Make_Function_Specification
(Loc
,
8863 Defining_Unit_Name
=> SId
,
8864 Parameter_Specifications
=> New_List
(
8865 Make_Parameter_Specification
(Loc
,
8866 Defining_Identifier
=> Object_Entity
,
8867 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
))),
8868 Result_Definition
=>
8869 New_Occurrence_Of
(Standard_Boolean
, Loc
));
8871 FDecl
:= Make_Subprogram_Declaration
(Loc
, Specification
=> Spec
);
8873 Set_Ekind
(SId
, E_Function
);
8874 Set_Etype
(SId
, Standard_Boolean
);
8875 Set_Is_Internal
(SId
);
8876 Set_Is_Predicate_Function
(SId
);
8877 Set_Predicate_Function
(Typ
, SId
);
8879 Insert_After
(Parent
(Typ
), FDecl
);
8884 end Build_Predicate_Function_Declaration
;
8886 -----------------------------------------
8887 -- Check_Aspect_At_End_Of_Declarations --
8888 -----------------------------------------
8890 procedure Check_Aspect_At_End_Of_Declarations
(ASN
: Node_Id
) is
8891 Ent
: constant Entity_Id
:= Entity
(ASN
);
8892 Ident
: constant Node_Id
:= Identifier
(ASN
);
8893 A_Id
: constant Aspect_Id
:= Get_Aspect_Id
(Chars
(Ident
));
8895 End_Decl_Expr
: constant Node_Id
:= Entity
(Ident
);
8896 -- Expression to be analyzed at end of declarations
8898 Freeze_Expr
: constant Node_Id
:= Expression
(ASN
);
8899 -- Expression from call to Check_Aspect_At_Freeze_Point
8901 T
: constant Entity_Id
:= Etype
(Freeze_Expr
);
8902 -- Type required for preanalyze call
8905 -- Set False if error
8907 -- On entry to this procedure, Entity (Ident) contains a copy of the
8908 -- original expression from the aspect, saved for this purpose, and
8909 -- but Expression (Ident) is a preanalyzed copy of the expression,
8910 -- preanalyzed just after the freeze point.
8912 procedure Check_Overloaded_Name
;
8913 -- For aspects whose expression is simply a name, this routine checks if
8914 -- the name is overloaded or not. If so, it verifies there is an
8915 -- interpretation that matches the entity obtained at the freeze point,
8916 -- otherwise the compiler complains.
8918 ---------------------------
8919 -- Check_Overloaded_Name --
8920 ---------------------------
8922 procedure Check_Overloaded_Name
is
8924 if not Is_Overloaded
(End_Decl_Expr
) then
8925 Err
:= not Is_Entity_Name
(End_Decl_Expr
)
8926 or else Entity
(End_Decl_Expr
) /= Entity
(Freeze_Expr
);
8932 Index
: Interp_Index
;
8936 Get_First_Interp
(End_Decl_Expr
, Index
, It
);
8937 while Present
(It
.Typ
) loop
8938 if It
.Nam
= Entity
(Freeze_Expr
) then
8943 Get_Next_Interp
(Index
, It
);
8947 end Check_Overloaded_Name
;
8949 -- Start of processing for Check_Aspect_At_End_Of_Declarations
8952 -- In an instance we do not perform the consistency check between freeze
8953 -- point and end of declarations, because it was done already in the
8954 -- analysis of the generic. Furthermore, the delayed analysis of an
8955 -- aspect of the instance may produce spurious errors when the generic
8956 -- is a child unit that references entities in the parent (which might
8957 -- not be in scope at the freeze point of the instance).
8962 -- Case of aspects Dimension, Dimension_System and Synchronization
8964 elsif A_Id
= Aspect_Synchronization
then
8967 -- Case of stream attributes, just have to compare entities. However,
8968 -- the expression is just a name (possibly overloaded), and there may
8969 -- be stream operations declared for unrelated types, so we just need
8970 -- to verify that one of these interpretations is the one available at
8971 -- at the freeze point.
8973 elsif A_Id
= Aspect_Input
or else
8974 A_Id
= Aspect_Output
or else
8975 A_Id
= Aspect_Read
or else
8978 Analyze
(End_Decl_Expr
);
8979 Check_Overloaded_Name
;
8981 elsif A_Id
= Aspect_Variable_Indexing
or else
8982 A_Id
= Aspect_Constant_Indexing
or else
8983 A_Id
= Aspect_Default_Iterator
or else
8984 A_Id
= Aspect_Iterator_Element
8986 -- Make type unfrozen before analysis, to prevent spurious errors
8987 -- about late attributes.
8989 Set_Is_Frozen
(Ent
, False);
8990 Analyze
(End_Decl_Expr
);
8991 Set_Is_Frozen
(Ent
, True);
8993 -- If the end of declarations comes before any other freeze
8994 -- point, the Freeze_Expr is not analyzed: no check needed.
8996 if Analyzed
(Freeze_Expr
) and then not In_Instance
then
8997 Check_Overloaded_Name
;
9005 -- Indicate that the expression comes from an aspect specification,
9006 -- which is used in subsequent analysis even if expansion is off.
9008 Set_Parent
(End_Decl_Expr
, ASN
);
9010 -- In a generic context the aspect expressions have not been
9011 -- preanalyzed, so do it now. There are no conformance checks
9012 -- to perform in this case.
9015 Check_Aspect_At_Freeze_Point
(ASN
);
9018 -- The default values attributes may be defined in the private part,
9019 -- and the analysis of the expression may take place when only the
9020 -- partial view is visible. The expression must be scalar, so use
9021 -- the full view to resolve.
9023 elsif (A_Id
= Aspect_Default_Value
9025 A_Id
= Aspect_Default_Component_Value
)
9026 and then Is_Private_Type
(T
)
9028 Preanalyze_Spec_Expression
(End_Decl_Expr
, Full_View
(T
));
9031 Preanalyze_Spec_Expression
(End_Decl_Expr
, T
);
9034 Err
:= not Fully_Conformant_Expressions
(End_Decl_Expr
, Freeze_Expr
);
9037 -- Output error message if error. Force error on aspect specification
9038 -- even if there is an error on the expression itself.
9042 ("!visibility of aspect for& changes after freeze point",
9045 ("info: & is frozen here, aspects evaluated at this point??",
9046 Freeze_Node
(Ent
), Ent
);
9048 end Check_Aspect_At_End_Of_Declarations
;
9050 ----------------------------------
9051 -- Check_Aspect_At_Freeze_Point --
9052 ----------------------------------
9054 procedure Check_Aspect_At_Freeze_Point
(ASN
: Node_Id
) is
9055 Ident
: constant Node_Id
:= Identifier
(ASN
);
9056 -- Identifier (use Entity field to save expression)
9058 A_Id
: constant Aspect_Id
:= Get_Aspect_Id
(Chars
(Ident
));
9060 T
: Entity_Id
:= Empty
;
9061 -- Type required for preanalyze call
9064 -- On entry to this procedure, Entity (Ident) contains a copy of the
9065 -- original expression from the aspect, saved for this purpose.
9067 -- On exit from this procedure Entity (Ident) is unchanged, still
9068 -- containing that copy, but Expression (Ident) is a preanalyzed copy
9069 -- of the expression, preanalyzed just after the freeze point.
9071 -- Make a copy of the expression to be preanalyzed
9073 Set_Expression
(ASN
, New_Copy_Tree
(Entity
(Ident
)));
9075 -- Find type for preanalyze call
9079 -- No_Aspect should be impossible
9082 raise Program_Error
;
9084 -- Aspects taking an optional boolean argument
9086 when Boolean_Aspects |
9087 Library_Unit_Aspects
=>
9089 T
:= Standard_Boolean
;
9091 -- Aspects corresponding to attribute definition clauses
9093 when Aspect_Address
=>
9094 T
:= RTE
(RE_Address
);
9096 when Aspect_Attach_Handler
=>
9097 T
:= RTE
(RE_Interrupt_ID
);
9099 when Aspect_Bit_Order | Aspect_Scalar_Storage_Order
=>
9100 T
:= RTE
(RE_Bit_Order
);
9102 when Aspect_Convention
=>
9106 T
:= RTE
(RE_CPU_Range
);
9108 -- Default_Component_Value is resolved with the component type
9110 when Aspect_Default_Component_Value
=>
9111 T
:= Component_Type
(Entity
(ASN
));
9113 when Aspect_Default_Storage_Pool
=>
9114 T
:= Class_Wide_Type
(RTE
(RE_Root_Storage_Pool
));
9116 -- Default_Value is resolved with the type entity in question
9118 when Aspect_Default_Value
=>
9121 when Aspect_Dispatching_Domain
=>
9122 T
:= RTE
(RE_Dispatching_Domain
);
9124 when Aspect_External_Tag
=>
9125 T
:= Standard_String
;
9127 when Aspect_External_Name
=>
9128 T
:= Standard_String
;
9130 when Aspect_Link_Name
=>
9131 T
:= Standard_String
;
9133 when Aspect_Priority | Aspect_Interrupt_Priority
=>
9134 T
:= Standard_Integer
;
9136 when Aspect_Relative_Deadline
=>
9137 T
:= RTE
(RE_Time_Span
);
9139 when Aspect_Small
=>
9140 T
:= Universal_Real
;
9142 -- For a simple storage pool, we have to retrieve the type of the
9143 -- pool object associated with the aspect's corresponding attribute
9144 -- definition clause.
9146 when Aspect_Simple_Storage_Pool
=>
9147 T
:= Etype
(Expression
(Aspect_Rep_Item
(ASN
)));
9149 when Aspect_Storage_Pool
=>
9150 T
:= Class_Wide_Type
(RTE
(RE_Root_Storage_Pool
));
9152 when Aspect_Alignment |
9153 Aspect_Component_Size |
9154 Aspect_Machine_Radix |
9155 Aspect_Object_Size |
9157 Aspect_Storage_Size |
9158 Aspect_Stream_Size |
9159 Aspect_Value_Size
=>
9162 when Aspect_Linker_Section
=>
9163 T
:= Standard_String
;
9165 when Aspect_Synchronization
=>
9168 -- Special case, the expression of these aspects is just an entity
9169 -- that does not need any resolution, so just analyze.
9178 Analyze
(Expression
(ASN
));
9181 -- Same for Iterator aspects, where the expression is a function
9182 -- name. Legality rules are checked separately.
9184 when Aspect_Constant_Indexing |
9185 Aspect_Default_Iterator |
9186 Aspect_Iterator_Element |
9187 Aspect_Variable_Indexing
=>
9188 Analyze
(Expression
(ASN
));
9191 -- Ditto for Iterable, legality checks in Validate_Iterable_Aspect.
9193 when Aspect_Iterable
=>
9197 Cursor
: constant Entity_Id
:= Get_Cursor_Type
(ASN
, T
);
9202 if Cursor
= Any_Type
then
9206 Assoc
:= First
(Component_Associations
(Expression
(ASN
)));
9207 while Present
(Assoc
) loop
9208 Expr
:= Expression
(Assoc
);
9211 if not Error_Posted
(Expr
) then
9212 Resolve_Iterable_Operation
9213 (Expr
, Cursor
, T
, Chars
(First
(Choices
(Assoc
))));
9222 -- Invariant/Predicate take boolean expressions
9224 when Aspect_Dynamic_Predicate |
9227 Aspect_Static_Predicate |
9228 Aspect_Type_Invariant
=>
9229 T
:= Standard_Boolean
;
9231 when Aspect_Predicate_Failure
=>
9232 T
:= Standard_String
;
9234 -- Here is the list of aspects that don't require delay analysis
9236 when Aspect_Abstract_State |
9238 Aspect_Async_Readers |
9239 Aspect_Async_Writers |
9240 Aspect_Constant_After_Elaboration |
9241 Aspect_Contract_Cases |
9242 Aspect_Default_Initial_Condition |
9245 Aspect_Dimension_System |
9246 Aspect_Effective_Reads |
9247 Aspect_Effective_Writes |
9248 Aspect_Extensions_Visible |
9251 Aspect_Implicit_Dereference |
9252 Aspect_Initial_Condition |
9253 Aspect_Initializes |
9254 Aspect_Obsolescent |
9257 Aspect_Postcondition |
9259 Aspect_Precondition |
9260 Aspect_Refined_Depends |
9261 Aspect_Refined_Global |
9262 Aspect_Refined_Post |
9263 Aspect_Refined_State |
9266 Aspect_Unimplemented |
9267 Aspect_Volatile_Function
=>
9268 raise Program_Error
;
9272 -- Do the preanalyze call
9274 Preanalyze_Spec_Expression
(Expression
(ASN
), T
);
9275 end Check_Aspect_At_Freeze_Point
;
9277 -----------------------------------
9278 -- Check_Constant_Address_Clause --
9279 -----------------------------------
9281 procedure Check_Constant_Address_Clause
9285 procedure Check_At_Constant_Address
(Nod
: Node_Id
);
9286 -- Checks that the given node N represents a name whose 'Address is
9287 -- constant (in the same sense as OK_Constant_Address_Clause, i.e. the
9288 -- address value is the same at the point of declaration of U_Ent and at
9289 -- the time of elaboration of the address clause.
9291 procedure Check_Expr_Constants
(Nod
: Node_Id
);
9292 -- Checks that Nod meets the requirements for a constant address clause
9293 -- in the sense of the enclosing procedure.
9295 procedure Check_List_Constants
(Lst
: List_Id
);
9296 -- Check that all elements of list Lst meet the requirements for a
9297 -- constant address clause in the sense of the enclosing procedure.
9299 -------------------------------
9300 -- Check_At_Constant_Address --
9301 -------------------------------
9303 procedure Check_At_Constant_Address
(Nod
: Node_Id
) is
9305 if Is_Entity_Name
(Nod
) then
9306 if Present
(Address_Clause
(Entity
((Nod
)))) then
9308 ("invalid address clause for initialized object &!",
9311 ("address for& cannot" &
9312 " depend on another address clause! (RM 13.1(22))!",
9315 elsif In_Same_Source_Unit
(Entity
(Nod
), U_Ent
)
9316 and then Sloc
(U_Ent
) < Sloc
(Entity
(Nod
))
9319 ("invalid address clause for initialized object &!",
9321 Error_Msg_Node_2
:= U_Ent
;
9323 ("\& must be defined before & (RM 13.1(22))!",
9327 elsif Nkind
(Nod
) = N_Selected_Component
then
9329 T
: constant Entity_Id
:= Etype
(Prefix
(Nod
));
9332 if (Is_Record_Type
(T
)
9333 and then Has_Discriminants
(T
))
9336 and then Is_Record_Type
(Designated_Type
(T
))
9337 and then Has_Discriminants
(Designated_Type
(T
)))
9340 ("invalid address clause for initialized object &!",
9343 ("\address cannot depend on component" &
9344 " of discriminated record (RM 13.1(22))!",
9347 Check_At_Constant_Address
(Prefix
(Nod
));
9351 elsif Nkind
(Nod
) = N_Indexed_Component
then
9352 Check_At_Constant_Address
(Prefix
(Nod
));
9353 Check_List_Constants
(Expressions
(Nod
));
9356 Check_Expr_Constants
(Nod
);
9358 end Check_At_Constant_Address
;
9360 --------------------------
9361 -- Check_Expr_Constants --
9362 --------------------------
9364 procedure Check_Expr_Constants
(Nod
: Node_Id
) is
9365 Loc_U_Ent
: constant Source_Ptr
:= Sloc
(U_Ent
);
9366 Ent
: Entity_Id
:= Empty
;
9369 if Nkind
(Nod
) in N_Has_Etype
9370 and then Etype
(Nod
) = Any_Type
9376 when N_Empty | N_Error
=>
9379 when N_Identifier | N_Expanded_Name
=>
9380 Ent
:= Entity
(Nod
);
9382 -- We need to look at the original node if it is different
9383 -- from the node, since we may have rewritten things and
9384 -- substituted an identifier representing the rewrite.
9386 if Original_Node
(Nod
) /= Nod
then
9387 Check_Expr_Constants
(Original_Node
(Nod
));
9389 -- If the node is an object declaration without initial
9390 -- value, some code has been expanded, and the expression
9391 -- is not constant, even if the constituents might be
9392 -- acceptable, as in A'Address + offset.
9394 if Ekind
(Ent
) = E_Variable
9396 Nkind
(Declaration_Node
(Ent
)) = N_Object_Declaration
9398 No
(Expression
(Declaration_Node
(Ent
)))
9401 ("invalid address clause for initialized object &!",
9404 -- If entity is constant, it may be the result of expanding
9405 -- a check. We must verify that its declaration appears
9406 -- before the object in question, else we also reject the
9409 elsif Ekind
(Ent
) = E_Constant
9410 and then In_Same_Source_Unit
(Ent
, U_Ent
)
9411 and then Sloc
(Ent
) > Loc_U_Ent
9414 ("invalid address clause for initialized object &!",
9421 -- Otherwise look at the identifier and see if it is OK
9423 if Ekind_In
(Ent
, E_Named_Integer
, E_Named_Real
)
9424 or else Is_Type
(Ent
)
9428 elsif Ekind_In
(Ent
, E_Constant
, E_In_Parameter
) then
9430 -- This is the case where we must have Ent defined before
9431 -- U_Ent. Clearly if they are in different units this
9432 -- requirement is met since the unit containing Ent is
9433 -- already processed.
9435 if not In_Same_Source_Unit
(Ent
, U_Ent
) then
9438 -- Otherwise location of Ent must be before the location
9439 -- of U_Ent, that's what prior defined means.
9441 elsif Sloc
(Ent
) < Loc_U_Ent
then
9446 ("invalid address clause for initialized object &!",
9448 Error_Msg_Node_2
:= U_Ent
;
9450 ("\& must be defined before & (RM 13.1(22))!",
9454 elsif Nkind
(Original_Node
(Nod
)) = N_Function_Call
then
9455 Check_Expr_Constants
(Original_Node
(Nod
));
9459 ("invalid address clause for initialized object &!",
9462 if Comes_From_Source
(Ent
) then
9464 ("\reference to variable& not allowed"
9465 & " (RM 13.1(22))!", Nod
, Ent
);
9468 ("non-static expression not allowed"
9469 & " (RM 13.1(22))!", Nod
);
9473 when N_Integer_Literal
=>
9475 -- If this is a rewritten unchecked conversion, in a system
9476 -- where Address is an integer type, always use the base type
9477 -- for a literal value. This is user-friendly and prevents
9478 -- order-of-elaboration issues with instances of unchecked
9481 if Nkind
(Original_Node
(Nod
)) = N_Function_Call
then
9482 Set_Etype
(Nod
, Base_Type
(Etype
(Nod
)));
9485 when N_Real_Literal |
9487 N_Character_Literal
=>
9491 Check_Expr_Constants
(Low_Bound
(Nod
));
9492 Check_Expr_Constants
(High_Bound
(Nod
));
9494 when N_Explicit_Dereference
=>
9495 Check_Expr_Constants
(Prefix
(Nod
));
9497 when N_Indexed_Component
=>
9498 Check_Expr_Constants
(Prefix
(Nod
));
9499 Check_List_Constants
(Expressions
(Nod
));
9502 Check_Expr_Constants
(Prefix
(Nod
));
9503 Check_Expr_Constants
(Discrete_Range
(Nod
));
9505 when N_Selected_Component
=>
9506 Check_Expr_Constants
(Prefix
(Nod
));
9508 when N_Attribute_Reference
=>
9509 if Nam_In
(Attribute_Name
(Nod
), Name_Address
,
9511 Name_Unchecked_Access
,
9512 Name_Unrestricted_Access
)
9514 Check_At_Constant_Address
(Prefix
(Nod
));
9517 Check_Expr_Constants
(Prefix
(Nod
));
9518 Check_List_Constants
(Expressions
(Nod
));
9522 Check_List_Constants
(Component_Associations
(Nod
));
9523 Check_List_Constants
(Expressions
(Nod
));
9525 when N_Component_Association
=>
9526 Check_Expr_Constants
(Expression
(Nod
));
9528 when N_Extension_Aggregate
=>
9529 Check_Expr_Constants
(Ancestor_Part
(Nod
));
9530 Check_List_Constants
(Component_Associations
(Nod
));
9531 Check_List_Constants
(Expressions
(Nod
));
9536 when N_Binary_Op | N_Short_Circuit | N_Membership_Test
=>
9537 Check_Expr_Constants
(Left_Opnd
(Nod
));
9538 Check_Expr_Constants
(Right_Opnd
(Nod
));
9541 Check_Expr_Constants
(Right_Opnd
(Nod
));
9543 when N_Type_Conversion |
9544 N_Qualified_Expression |
9546 N_Unchecked_Type_Conversion
=>
9547 Check_Expr_Constants
(Expression
(Nod
));
9549 when N_Function_Call
=>
9550 if not Is_Pure
(Entity
(Name
(Nod
))) then
9552 ("invalid address clause for initialized object &!",
9556 ("\function & is not pure (RM 13.1(22))!",
9557 Nod
, Entity
(Name
(Nod
)));
9560 Check_List_Constants
(Parameter_Associations
(Nod
));
9563 when N_Parameter_Association
=>
9564 Check_Expr_Constants
(Explicit_Actual_Parameter
(Nod
));
9568 ("invalid address clause for initialized object &!",
9571 ("\must be constant defined before& (RM 13.1(22))!",
9574 end Check_Expr_Constants
;
9576 --------------------------
9577 -- Check_List_Constants --
9578 --------------------------
9580 procedure Check_List_Constants
(Lst
: List_Id
) is
9584 if Present
(Lst
) then
9585 Nod1
:= First
(Lst
);
9586 while Present
(Nod1
) loop
9587 Check_Expr_Constants
(Nod1
);
9591 end Check_List_Constants
;
9593 -- Start of processing for Check_Constant_Address_Clause
9596 -- If rep_clauses are to be ignored, no need for legality checks. In
9597 -- particular, no need to pester user about rep clauses that violate the
9598 -- rule on constant addresses, given that these clauses will be removed
9599 -- by Freeze before they reach the back end. Similarly in CodePeer mode,
9600 -- we want to relax these checks.
9602 if not Ignore_Rep_Clauses
and not CodePeer_Mode
then
9603 Check_Expr_Constants
(Expr
);
9605 end Check_Constant_Address_Clause
;
9607 ---------------------------
9608 -- Check_Pool_Size_Clash --
9609 ---------------------------
9611 procedure Check_Pool_Size_Clash
(Ent
: Entity_Id
; SP
, SS
: Node_Id
) is
9615 -- We need to find out which one came first. Note that in the case of
9616 -- aspects mixed with pragmas there are cases where the processing order
9617 -- is reversed, which is why we do the check here.
9619 if Sloc
(SP
) < Sloc
(SS
) then
9620 Error_Msg_Sloc
:= Sloc
(SP
);
9622 Error_Msg_NE
("Storage_Pool previously given for&#", Post
, Ent
);
9625 Error_Msg_Sloc
:= Sloc
(SS
);
9627 Error_Msg_NE
("Storage_Size previously given for&#", Post
, Ent
);
9631 ("\cannot have Storage_Size and Storage_Pool (RM 13.11(3))", Post
);
9632 end Check_Pool_Size_Clash
;
9634 ----------------------------------------
9635 -- Check_Record_Representation_Clause --
9636 ----------------------------------------
9638 procedure Check_Record_Representation_Clause
(N
: Node_Id
) is
9639 Loc
: constant Source_Ptr
:= Sloc
(N
);
9640 Ident
: constant Node_Id
:= Identifier
(N
);
9641 Rectype
: Entity_Id
;
9646 Hbit
: Uint
:= Uint_0
;
9650 Max_Bit_So_Far
: Uint
;
9651 -- Records the maximum bit position so far. If all field positions
9652 -- are monotonically increasing, then we can skip the circuit for
9653 -- checking for overlap, since no overlap is possible.
9655 Tagged_Parent
: Entity_Id
:= Empty
;
9656 -- This is set in the case of a derived tagged type for which we have
9657 -- Is_Fully_Repped_Tagged_Type True (indicating that all components are
9658 -- positioned by record representation clauses). In this case we must
9659 -- check for overlap between components of this tagged type, and the
9660 -- components of its parent. Tagged_Parent will point to this parent
9661 -- type. For all other cases Tagged_Parent is left set to Empty.
9663 Parent_Last_Bit
: Uint
;
9664 -- Relevant only if Tagged_Parent is set, Parent_Last_Bit indicates the
9665 -- last bit position for any field in the parent type. We only need to
9666 -- check overlap for fields starting below this point.
9668 Overlap_Check_Required
: Boolean;
9669 -- Used to keep track of whether or not an overlap check is required
9671 Overlap_Detected
: Boolean := False;
9672 -- Set True if an overlap is detected
9674 Ccount
: Natural := 0;
9675 -- Number of component clauses in record rep clause
9677 procedure Check_Component_Overlap
(C1_Ent
, C2_Ent
: Entity_Id
);
9678 -- Given two entities for record components or discriminants, checks
9679 -- if they have overlapping component clauses and issues errors if so.
9681 procedure Find_Component
;
9682 -- Finds component entity corresponding to current component clause (in
9683 -- CC), and sets Comp to the entity, and Fbit/Lbit to the zero origin
9684 -- start/stop bits for the field. If there is no matching component or
9685 -- if the matching component does not have a component clause, then
9686 -- that's an error and Comp is set to Empty, but no error message is
9687 -- issued, since the message was already given. Comp is also set to
9688 -- Empty if the current "component clause" is in fact a pragma.
9690 -----------------------------
9691 -- Check_Component_Overlap --
9692 -----------------------------
9694 procedure Check_Component_Overlap
(C1_Ent
, C2_Ent
: Entity_Id
) is
9695 CC1
: constant Node_Id
:= Component_Clause
(C1_Ent
);
9696 CC2
: constant Node_Id
:= Component_Clause
(C2_Ent
);
9699 if Present
(CC1
) and then Present
(CC2
) then
9701 -- Exclude odd case where we have two tag components in the same
9702 -- record, both at location zero. This seems a bit strange, but
9703 -- it seems to happen in some circumstances, perhaps on an error.
9705 if Nam_In
(Chars
(C1_Ent
), Name_uTag
, Name_uTag
) then
9709 -- Here we check if the two fields overlap
9712 S1
: constant Uint
:= Component_Bit_Offset
(C1_Ent
);
9713 S2
: constant Uint
:= Component_Bit_Offset
(C2_Ent
);
9714 E1
: constant Uint
:= S1
+ Esize
(C1_Ent
);
9715 E2
: constant Uint
:= S2
+ Esize
(C2_Ent
);
9718 if E2
<= S1
or else E1
<= S2
then
9721 Error_Msg_Node_2
:= Component_Name
(CC2
);
9722 Error_Msg_Sloc
:= Sloc
(Error_Msg_Node_2
);
9723 Error_Msg_Node_1
:= Component_Name
(CC1
);
9725 ("component& overlaps & #", Component_Name
(CC1
));
9726 Overlap_Detected
:= True;
9730 end Check_Component_Overlap
;
9732 --------------------
9733 -- Find_Component --
9734 --------------------
9736 procedure Find_Component
is
9738 procedure Search_Component
(R
: Entity_Id
);
9739 -- Search components of R for a match. If found, Comp is set
9741 ----------------------
9742 -- Search_Component --
9743 ----------------------
9745 procedure Search_Component
(R
: Entity_Id
) is
9747 Comp
:= First_Component_Or_Discriminant
(R
);
9748 while Present
(Comp
) loop
9750 -- Ignore error of attribute name for component name (we
9751 -- already gave an error message for this, so no need to
9754 if Nkind
(Component_Name
(CC
)) = N_Attribute_Reference
then
9757 exit when Chars
(Comp
) = Chars
(Component_Name
(CC
));
9760 Next_Component_Or_Discriminant
(Comp
);
9762 end Search_Component
;
9764 -- Start of processing for Find_Component
9767 -- Return with Comp set to Empty if we have a pragma
9769 if Nkind
(CC
) = N_Pragma
then
9774 -- Search current record for matching component
9776 Search_Component
(Rectype
);
9778 -- If not found, maybe component of base type discriminant that is
9779 -- absent from statically constrained first subtype.
9782 Search_Component
(Base_Type
(Rectype
));
9785 -- If no component, or the component does not reference the component
9786 -- clause in question, then there was some previous error for which
9787 -- we already gave a message, so just return with Comp Empty.
9789 if No
(Comp
) or else Component_Clause
(Comp
) /= CC
then
9790 Check_Error_Detected
;
9793 -- Normal case where we have a component clause
9796 Fbit
:= Component_Bit_Offset
(Comp
);
9797 Lbit
:= Fbit
+ Esize
(Comp
) - 1;
9801 -- Start of processing for Check_Record_Representation_Clause
9805 Rectype
:= Entity
(Ident
);
9807 if Rectype
= Any_Type
then
9810 Rectype
:= Underlying_Type
(Rectype
);
9813 -- See if we have a fully repped derived tagged type
9816 PS
: constant Entity_Id
:= Parent_Subtype
(Rectype
);
9819 if Present
(PS
) and then Is_Fully_Repped_Tagged_Type
(PS
) then
9820 Tagged_Parent
:= PS
;
9822 -- Find maximum bit of any component of the parent type
9824 Parent_Last_Bit
:= UI_From_Int
(System_Address_Size
- 1);
9825 Pcomp
:= First_Entity
(Tagged_Parent
);
9826 while Present
(Pcomp
) loop
9827 if Ekind_In
(Pcomp
, E_Discriminant
, E_Component
) then
9828 if Component_Bit_Offset
(Pcomp
) /= No_Uint
9829 and then Known_Static_Esize
(Pcomp
)
9834 Component_Bit_Offset
(Pcomp
) + Esize
(Pcomp
) - 1);
9838 -- Skip anonymous types generated for constrained array
9839 -- or record components.
9844 Next_Entity
(Pcomp
);
9849 -- All done if no component clauses
9851 CC
:= First
(Component_Clauses
(N
));
9857 -- If a tag is present, then create a component clause that places it
9858 -- at the start of the record (otherwise gigi may place it after other
9859 -- fields that have rep clauses).
9861 Fent
:= First_Entity
(Rectype
);
9863 if Nkind
(Fent
) = N_Defining_Identifier
9864 and then Chars
(Fent
) = Name_uTag
9866 Set_Component_Bit_Offset
(Fent
, Uint_0
);
9867 Set_Normalized_Position
(Fent
, Uint_0
);
9868 Set_Normalized_First_Bit
(Fent
, Uint_0
);
9869 Set_Normalized_Position_Max
(Fent
, Uint_0
);
9870 Init_Esize
(Fent
, System_Address_Size
);
9872 Set_Component_Clause
(Fent
,
9873 Make_Component_Clause
(Loc
,
9874 Component_Name
=> Make_Identifier
(Loc
, Name_uTag
),
9876 Position
=> Make_Integer_Literal
(Loc
, Uint_0
),
9877 First_Bit
=> Make_Integer_Literal
(Loc
, Uint_0
),
9879 Make_Integer_Literal
(Loc
,
9880 UI_From_Int
(System_Address_Size
))));
9882 Ccount
:= Ccount
+ 1;
9885 Max_Bit_So_Far
:= Uint_Minus_1
;
9886 Overlap_Check_Required
:= False;
9888 -- Process the component clauses
9890 while Present
(CC
) loop
9893 if Present
(Comp
) then
9894 Ccount
:= Ccount
+ 1;
9896 -- We need a full overlap check if record positions non-monotonic
9898 if Fbit
<= Max_Bit_So_Far
then
9899 Overlap_Check_Required
:= True;
9902 Max_Bit_So_Far
:= Lbit
;
9904 -- Check bit position out of range of specified size
9906 if Has_Size_Clause
(Rectype
)
9907 and then RM_Size
(Rectype
) <= Lbit
9910 ("bit number out of range of specified size",
9913 -- Check for overlap with tag component
9916 if Is_Tagged_Type
(Rectype
)
9917 and then Fbit
< System_Address_Size
9920 ("component overlaps tag field of&",
9921 Component_Name
(CC
), Rectype
);
9922 Overlap_Detected
:= True;
9930 -- Check parent overlap if component might overlap parent field
9932 if Present
(Tagged_Parent
) and then Fbit
<= Parent_Last_Bit
then
9933 Pcomp
:= First_Component_Or_Discriminant
(Tagged_Parent
);
9934 while Present
(Pcomp
) loop
9935 if not Is_Tag
(Pcomp
)
9936 and then Chars
(Pcomp
) /= Name_uParent
9938 Check_Component_Overlap
(Comp
, Pcomp
);
9941 Next_Component_Or_Discriminant
(Pcomp
);
9949 -- Now that we have processed all the component clauses, check for
9950 -- overlap. We have to leave this till last, since the components can
9951 -- appear in any arbitrary order in the representation clause.
9953 -- We do not need this check if all specified ranges were monotonic,
9954 -- as recorded by Overlap_Check_Required being False at this stage.
9956 -- This first section checks if there are any overlapping entries at
9957 -- all. It does this by sorting all entries and then seeing if there are
9958 -- any overlaps. If there are none, then that is decisive, but if there
9959 -- are overlaps, they may still be OK (they may result from fields in
9960 -- different variants).
9962 if Overlap_Check_Required
then
9963 Overlap_Check1
: declare
9965 OC_Fbit
: array (0 .. Ccount
) of Uint
;
9966 -- First-bit values for component clauses, the value is the offset
9967 -- of the first bit of the field from start of record. The zero
9968 -- entry is for use in sorting.
9970 OC_Lbit
: array (0 .. Ccount
) of Uint
;
9971 -- Last-bit values for component clauses, the value is the offset
9972 -- of the last bit of the field from start of record. The zero
9973 -- entry is for use in sorting.
9975 OC_Count
: Natural := 0;
9976 -- Count of entries in OC_Fbit and OC_Lbit
9978 function OC_Lt
(Op1
, Op2
: Natural) return Boolean;
9979 -- Compare routine for Sort
9981 procedure OC_Move
(From
: Natural; To
: Natural);
9982 -- Move routine for Sort
9984 package Sorting
is new GNAT
.Heap_Sort_G
(OC_Move
, OC_Lt
);
9990 function OC_Lt
(Op1
, Op2
: Natural) return Boolean is
9992 return OC_Fbit
(Op1
) < OC_Fbit
(Op2
);
9999 procedure OC_Move
(From
: Natural; To
: Natural) is
10001 OC_Fbit
(To
) := OC_Fbit
(From
);
10002 OC_Lbit
(To
) := OC_Lbit
(From
);
10005 -- Start of processing for Overlap_Check
10008 CC
:= First
(Component_Clauses
(N
));
10009 while Present
(CC
) loop
10011 -- Exclude component clause already marked in error
10013 if not Error_Posted
(CC
) then
10016 if Present
(Comp
) then
10017 OC_Count
:= OC_Count
+ 1;
10018 OC_Fbit
(OC_Count
) := Fbit
;
10019 OC_Lbit
(OC_Count
) := Lbit
;
10026 Sorting
.Sort
(OC_Count
);
10028 Overlap_Check_Required
:= False;
10029 for J
in 1 .. OC_Count
- 1 loop
10030 if OC_Lbit
(J
) >= OC_Fbit
(J
+ 1) then
10031 Overlap_Check_Required
:= True;
10035 end Overlap_Check1
;
10038 -- If Overlap_Check_Required is still True, then we have to do the full
10039 -- scale overlap check, since we have at least two fields that do
10040 -- overlap, and we need to know if that is OK since they are in
10041 -- different variant, or whether we have a definite problem.
10043 if Overlap_Check_Required
then
10044 Overlap_Check2
: declare
10045 C1_Ent
, C2_Ent
: Entity_Id
;
10046 -- Entities of components being checked for overlap
10049 -- Component_List node whose Component_Items are being checked
10052 -- Component declaration for component being checked
10055 C1_Ent
:= First_Entity
(Base_Type
(Rectype
));
10057 -- Loop through all components in record. For each component check
10058 -- for overlap with any of the preceding elements on the component
10059 -- list containing the component and also, if the component is in
10060 -- a variant, check against components outside the case structure.
10061 -- This latter test is repeated recursively up the variant tree.
10063 Main_Component_Loop
: while Present
(C1_Ent
) loop
10064 if not Ekind_In
(C1_Ent
, E_Component
, E_Discriminant
) then
10065 goto Continue_Main_Component_Loop
;
10068 -- Skip overlap check if entity has no declaration node. This
10069 -- happens with discriminants in constrained derived types.
10070 -- Possibly we are missing some checks as a result, but that
10071 -- does not seem terribly serious.
10073 if No
(Declaration_Node
(C1_Ent
)) then
10074 goto Continue_Main_Component_Loop
;
10077 Clist
:= Parent
(List_Containing
(Declaration_Node
(C1_Ent
)));
10079 -- Loop through component lists that need checking. Check the
10080 -- current component list and all lists in variants above us.
10082 Component_List_Loop
: loop
10084 -- If derived type definition, go to full declaration
10085 -- If at outer level, check discriminants if there are any.
10087 if Nkind
(Clist
) = N_Derived_Type_Definition
then
10088 Clist
:= Parent
(Clist
);
10091 -- Outer level of record definition, check discriminants
10093 if Nkind_In
(Clist
, N_Full_Type_Declaration
,
10094 N_Private_Type_Declaration
)
10096 if Has_Discriminants
(Defining_Identifier
(Clist
)) then
10098 First_Discriminant
(Defining_Identifier
(Clist
));
10099 while Present
(C2_Ent
) loop
10100 exit when C1_Ent
= C2_Ent
;
10101 Check_Component_Overlap
(C1_Ent
, C2_Ent
);
10102 Next_Discriminant
(C2_Ent
);
10106 -- Record extension case
10108 elsif Nkind
(Clist
) = N_Derived_Type_Definition
then
10111 -- Otherwise check one component list
10114 Citem
:= First
(Component_Items
(Clist
));
10115 while Present
(Citem
) loop
10116 if Nkind
(Citem
) = N_Component_Declaration
then
10117 C2_Ent
:= Defining_Identifier
(Citem
);
10118 exit when C1_Ent
= C2_Ent
;
10119 Check_Component_Overlap
(C1_Ent
, C2_Ent
);
10126 -- Check for variants above us (the parent of the Clist can
10127 -- be a variant, in which case its parent is a variant part,
10128 -- and the parent of the variant part is a component list
10129 -- whose components must all be checked against the current
10130 -- component for overlap).
10132 if Nkind
(Parent
(Clist
)) = N_Variant
then
10133 Clist
:= Parent
(Parent
(Parent
(Clist
)));
10135 -- Check for possible discriminant part in record, this
10136 -- is treated essentially as another level in the
10137 -- recursion. For this case the parent of the component
10138 -- list is the record definition, and its parent is the
10139 -- full type declaration containing the discriminant
10142 elsif Nkind
(Parent
(Clist
)) = N_Record_Definition
then
10143 Clist
:= Parent
(Parent
((Clist
)));
10145 -- If neither of these two cases, we are at the top of
10149 exit Component_List_Loop
;
10151 end loop Component_List_Loop
;
10153 <<Continue_Main_Component_Loop
>>
10154 Next_Entity
(C1_Ent
);
10156 end loop Main_Component_Loop
;
10157 end Overlap_Check2
;
10160 -- The following circuit deals with warning on record holes (gaps). We
10161 -- skip this check if overlap was detected, since it makes sense for the
10162 -- programmer to fix this illegality before worrying about warnings.
10164 if not Overlap_Detected
and Warn_On_Record_Holes
then
10165 Record_Hole_Check
: declare
10166 Decl
: constant Node_Id
:= Declaration_Node
(Base_Type
(Rectype
));
10167 -- Full declaration of record type
10169 procedure Check_Component_List
10173 -- Check component list CL for holes. The starting bit should be
10174 -- Sbit. which is zero for the main record component list and set
10175 -- appropriately for recursive calls for variants. DS is set to
10176 -- a list of discriminant specifications to be included in the
10177 -- consideration of components. It is No_List if none to consider.
10179 --------------------------
10180 -- Check_Component_List --
10181 --------------------------
10183 procedure Check_Component_List
10191 Compl
:= Integer (List_Length
(Component_Items
(CL
)));
10193 if DS
/= No_List
then
10194 Compl
:= Compl
+ Integer (List_Length
(DS
));
10198 Comps
: array (Natural range 0 .. Compl
) of Entity_Id
;
10199 -- Gather components (zero entry is for sort routine)
10201 Ncomps
: Natural := 0;
10202 -- Number of entries stored in Comps (starting at Comps (1))
10205 -- One component item or discriminant specification
10208 -- Starting bit for next component
10211 -- Component entity
10216 function Lt
(Op1
, Op2
: Natural) return Boolean;
10217 -- Compare routine for Sort
10219 procedure Move
(From
: Natural; To
: Natural);
10220 -- Move routine for Sort
10222 package Sorting
is new GNAT
.Heap_Sort_G
(Move
, Lt
);
10228 function Lt
(Op1
, Op2
: Natural) return Boolean is
10230 return Component_Bit_Offset
(Comps
(Op1
))
10232 Component_Bit_Offset
(Comps
(Op2
));
10239 procedure Move
(From
: Natural; To
: Natural) is
10241 Comps
(To
) := Comps
(From
);
10245 -- Gather discriminants into Comp
10247 if DS
/= No_List
then
10248 Citem
:= First
(DS
);
10249 while Present
(Citem
) loop
10250 if Nkind
(Citem
) = N_Discriminant_Specification
then
10252 Ent
: constant Entity_Id
:=
10253 Defining_Identifier
(Citem
);
10255 if Ekind
(Ent
) = E_Discriminant
then
10256 Ncomps
:= Ncomps
+ 1;
10257 Comps
(Ncomps
) := Ent
;
10266 -- Gather component entities into Comp
10268 Citem
:= First
(Component_Items
(CL
));
10269 while Present
(Citem
) loop
10270 if Nkind
(Citem
) = N_Component_Declaration
then
10271 Ncomps
:= Ncomps
+ 1;
10272 Comps
(Ncomps
) := Defining_Identifier
(Citem
);
10278 -- Now sort the component entities based on the first bit.
10279 -- Note we already know there are no overlapping components.
10281 Sorting
.Sort
(Ncomps
);
10283 -- Loop through entries checking for holes
10286 for J
in 1 .. Ncomps
loop
10288 Error_Msg_Uint_1
:= Component_Bit_Offset
(CEnt
) - Nbit
;
10290 if Error_Msg_Uint_1
> 0 then
10292 ("?H?^-bit gap before component&",
10293 Component_Name
(Component_Clause
(CEnt
)), CEnt
);
10296 Nbit
:= Component_Bit_Offset
(CEnt
) + Esize
(CEnt
);
10299 -- Process variant parts recursively if present
10301 if Present
(Variant_Part
(CL
)) then
10302 Variant
:= First
(Variants
(Variant_Part
(CL
)));
10303 while Present
(Variant
) loop
10304 Check_Component_List
10305 (Component_List
(Variant
), Nbit
, No_List
);
10310 end Check_Component_List
;
10312 -- Start of processing for Record_Hole_Check
10319 if Is_Tagged_Type
(Rectype
) then
10320 Sbit
:= UI_From_Int
(System_Address_Size
);
10325 if Nkind
(Decl
) = N_Full_Type_Declaration
10326 and then Nkind
(Type_Definition
(Decl
)) = N_Record_Definition
10328 Check_Component_List
10329 (Component_List
(Type_Definition
(Decl
)),
10331 Discriminant_Specifications
(Decl
));
10334 end Record_Hole_Check
;
10337 -- For records that have component clauses for all components, and whose
10338 -- size is less than or equal to 32, we need to know the size in the
10339 -- front end to activate possible packed array processing where the
10340 -- component type is a record.
10342 -- At this stage Hbit + 1 represents the first unused bit from all the
10343 -- component clauses processed, so if the component clauses are
10344 -- complete, then this is the length of the record.
10346 -- For records longer than System.Storage_Unit, and for those where not
10347 -- all components have component clauses, the back end determines the
10348 -- length (it may for example be appropriate to round up the size
10349 -- to some convenient boundary, based on alignment considerations, etc).
10351 if Unknown_RM_Size
(Rectype
) and then Hbit
+ 1 <= 32 then
10353 -- Nothing to do if at least one component has no component clause
10355 Comp
:= First_Component_Or_Discriminant
(Rectype
);
10356 while Present
(Comp
) loop
10357 exit when No
(Component_Clause
(Comp
));
10358 Next_Component_Or_Discriminant
(Comp
);
10361 -- If we fall out of loop, all components have component clauses
10362 -- and so we can set the size to the maximum value.
10365 Set_RM_Size
(Rectype
, Hbit
+ 1);
10368 end Check_Record_Representation_Clause
;
10374 procedure Check_Size
10378 Biased
: out Boolean)
10380 procedure Size_Too_Small_Error
(Min_Siz
: Uint
);
10381 -- Emit an error concerning illegal size Siz. Min_Siz denotes the
10384 --------------------------
10385 -- Size_Too_Small_Error --
10386 --------------------------
10388 procedure Size_Too_Small_Error
(Min_Siz
: Uint
) is
10390 -- This error is suppressed in ASIS mode to allow for different ASIS
10391 -- back ends or ASIS-based tools to query the illegal clause.
10393 if not ASIS_Mode
then
10394 Error_Msg_Uint_1
:= Min_Siz
;
10395 Error_Msg_NE
("size for& too small, minimum allowed is ^", N
, T
);
10397 end Size_Too_Small_Error
;
10401 UT
: constant Entity_Id
:= Underlying_Type
(T
);
10404 -- Start of processing for Check_Size
10409 -- Reject patently improper size values
10411 if Is_Elementary_Type
(T
)
10412 and then Siz
> UI_From_Int
(Int
'Last)
10414 Error_Msg_N
("Size value too large for elementary type", N
);
10416 if Nkind
(Original_Node
(N
)) = N_Op_Expon
then
10418 ("\maybe '* was meant, rather than '*'*", Original_Node
(N
));
10422 -- Dismiss generic types
10424 if Is_Generic_Type
(T
)
10426 Is_Generic_Type
(UT
)
10428 Is_Generic_Type
(Root_Type
(UT
))
10432 -- Guard against previous errors
10434 elsif No
(UT
) or else UT
= Any_Type
then
10435 Check_Error_Detected
;
10438 -- Check case of bit packed array
10440 elsif Is_Array_Type
(UT
)
10441 and then Known_Static_Component_Size
(UT
)
10442 and then Is_Bit_Packed_Array
(UT
)
10450 Asiz
:= Component_Size
(UT
);
10451 Indx
:= First_Index
(UT
);
10453 Ityp
:= Etype
(Indx
);
10455 -- If non-static bound, then we are not in the business of
10456 -- trying to check the length, and indeed an error will be
10457 -- issued elsewhere, since sizes of non-static array types
10458 -- cannot be set implicitly or explicitly.
10460 if not Is_OK_Static_Subtype
(Ityp
) then
10464 -- Otherwise accumulate next dimension
10466 Asiz
:= Asiz
* (Expr_Value
(Type_High_Bound
(Ityp
)) -
10467 Expr_Value
(Type_Low_Bound
(Ityp
)) +
10471 exit when No
(Indx
);
10474 if Asiz
<= Siz
then
10478 Size_Too_Small_Error
(Asiz
);
10479 Set_Esize
(T
, Asiz
);
10480 Set_RM_Size
(T
, Asiz
);
10484 -- All other composite types are ignored
10486 elsif Is_Composite_Type
(UT
) then
10489 -- For fixed-point types, don't check minimum if type is not frozen,
10490 -- since we don't know all the characteristics of the type that can
10491 -- affect the size (e.g. a specified small) till freeze time.
10493 elsif Is_Fixed_Point_Type
(UT
) and then not Is_Frozen
(UT
) then
10496 -- Cases for which a minimum check is required
10499 -- Ignore if specified size is correct for the type
10501 if Known_Esize
(UT
) and then Siz
= Esize
(UT
) then
10505 -- Otherwise get minimum size
10507 M
:= UI_From_Int
(Minimum_Size
(UT
));
10511 -- Size is less than minimum size, but one possibility remains
10512 -- that we can manage with the new size if we bias the type.
10514 M
:= UI_From_Int
(Minimum_Size
(UT
, Biased
=> True));
10517 Size_Too_Small_Error
(M
);
10519 Set_RM_Size
(T
, M
);
10527 --------------------------
10528 -- Freeze_Entity_Checks --
10529 --------------------------
10531 procedure Freeze_Entity_Checks
(N
: Node_Id
) is
10532 procedure Hide_Non_Overridden_Subprograms
(Typ
: Entity_Id
);
10533 -- Inspect the primitive operations of type Typ and hide all pairs of
10534 -- implicitly declared non-overridden non-fully conformant homographs
10535 -- (Ada RM 8.3 12.3/2).
10537 -------------------------------------
10538 -- Hide_Non_Overridden_Subprograms --
10539 -------------------------------------
10541 procedure Hide_Non_Overridden_Subprograms
(Typ
: Entity_Id
) is
10542 procedure Hide_Matching_Homographs
10543 (Subp_Id
: Entity_Id
;
10544 Start_Elmt
: Elmt_Id
);
10545 -- Inspect a list of primitive operations starting with Start_Elmt
10546 -- and find matching implicitly declared non-overridden non-fully
10547 -- conformant homographs of Subp_Id. If found, all matches along
10548 -- with Subp_Id are hidden from all visibility.
10550 function Is_Non_Overridden_Or_Null_Procedure
10551 (Subp_Id
: Entity_Id
) return Boolean;
10552 -- Determine whether subprogram Subp_Id is implicitly declared non-
10553 -- overridden subprogram or an implicitly declared null procedure.
10555 ------------------------------
10556 -- Hide_Matching_Homographs --
10557 ------------------------------
10559 procedure Hide_Matching_Homographs
10560 (Subp_Id
: Entity_Id
;
10561 Start_Elmt
: Elmt_Id
)
10564 Prim_Elmt
: Elmt_Id
;
10567 Prim_Elmt
:= Start_Elmt
;
10568 while Present
(Prim_Elmt
) loop
10569 Prim
:= Node
(Prim_Elmt
);
10571 -- The current primitive is implicitly declared non-overridden
10572 -- non-fully conformant homograph of Subp_Id. Both subprograms
10573 -- must be hidden from visibility.
10575 if Chars
(Prim
) = Chars
(Subp_Id
)
10576 and then Is_Non_Overridden_Or_Null_Procedure
(Prim
)
10577 and then not Fully_Conformant
(Prim
, Subp_Id
)
10579 Set_Is_Hidden_Non_Overridden_Subpgm
(Prim
);
10580 Set_Is_Immediately_Visible
(Prim
, False);
10581 Set_Is_Potentially_Use_Visible
(Prim
, False);
10583 Set_Is_Hidden_Non_Overridden_Subpgm
(Subp_Id
);
10584 Set_Is_Immediately_Visible
(Subp_Id
, False);
10585 Set_Is_Potentially_Use_Visible
(Subp_Id
, False);
10588 Next_Elmt
(Prim_Elmt
);
10590 end Hide_Matching_Homographs
;
10592 -----------------------------------------
10593 -- Is_Non_Overridden_Or_Null_Procedure --
10594 -----------------------------------------
10596 function Is_Non_Overridden_Or_Null_Procedure
10597 (Subp_Id
: Entity_Id
) return Boolean
10599 Alias_Id
: Entity_Id
;
10602 -- The subprogram is inherited (implicitly declared), it does not
10603 -- override and does not cover a primitive of an interface.
10605 if Ekind_In
(Subp_Id
, E_Function
, E_Procedure
)
10606 and then Present
(Alias
(Subp_Id
))
10607 and then No
(Interface_Alias
(Subp_Id
))
10608 and then No
(Overridden_Operation
(Subp_Id
))
10610 Alias_Id
:= Alias
(Subp_Id
);
10612 if Requires_Overriding
(Alias_Id
) then
10615 elsif Nkind
(Parent
(Alias_Id
)) = N_Procedure_Specification
10616 and then Null_Present
(Parent
(Alias_Id
))
10623 end Is_Non_Overridden_Or_Null_Procedure
;
10627 Prim_Ops
: constant Elist_Id
:= Direct_Primitive_Operations
(Typ
);
10629 Prim_Elmt
: Elmt_Id
;
10631 -- Start of processing for Hide_Non_Overridden_Subprograms
10634 -- Inspect the list of primitives looking for non-overridden
10637 if Present
(Prim_Ops
) then
10638 Prim_Elmt
:= First_Elmt
(Prim_Ops
);
10639 while Present
(Prim_Elmt
) loop
10640 Prim
:= Node
(Prim_Elmt
);
10641 Next_Elmt
(Prim_Elmt
);
10643 if Is_Non_Overridden_Or_Null_Procedure
(Prim
) then
10644 Hide_Matching_Homographs
10646 Start_Elmt
=> Prim_Elmt
);
10650 end Hide_Non_Overridden_Subprograms
;
10654 E
: constant Entity_Id
:= Entity
(N
);
10656 Non_Generic_Case
: constant Boolean := Nkind
(N
) = N_Freeze_Entity
;
10657 -- True in non-generic case. Some of the processing here is skipped
10658 -- for the generic case since it is not needed. Basically in the
10659 -- generic case, we only need to do stuff that might generate error
10660 -- messages or warnings.
10662 -- Start of processing for Freeze_Entity_Checks
10665 -- Remember that we are processing a freezing entity. Required to
10666 -- ensure correct decoration of internal entities associated with
10667 -- interfaces (see New_Overloaded_Entity).
10669 Inside_Freezing_Actions
:= Inside_Freezing_Actions
+ 1;
10671 -- For tagged types covering interfaces add internal entities that link
10672 -- the primitives of the interfaces with the primitives that cover them.
10673 -- Note: These entities were originally generated only when generating
10674 -- code because their main purpose was to provide support to initialize
10675 -- the secondary dispatch tables. They are now generated also when
10676 -- compiling with no code generation to provide ASIS the relationship
10677 -- between interface primitives and tagged type primitives. They are
10678 -- also used to locate primitives covering interfaces when processing
10679 -- generics (see Derive_Subprograms).
10681 -- This is not needed in the generic case
10683 if Ada_Version
>= Ada_2005
10684 and then Non_Generic_Case
10685 and then Ekind
(E
) = E_Record_Type
10686 and then Is_Tagged_Type
(E
)
10687 and then not Is_Interface
(E
)
10688 and then Has_Interfaces
(E
)
10690 -- This would be a good common place to call the routine that checks
10691 -- overriding of interface primitives (and thus factorize calls to
10692 -- Check_Abstract_Overriding located at different contexts in the
10693 -- compiler). However, this is not possible because it causes
10694 -- spurious errors in case of late overriding.
10696 Add_Internal_Interface_Entities
(E
);
10699 -- After all forms of overriding have been resolved, a tagged type may
10700 -- be left with a set of implicitly declared and possibly erroneous
10701 -- abstract subprograms, null procedures and subprograms that require
10702 -- overriding. If this set contains fully conformant homographs, then
10703 -- one is chosen arbitrarily (already done during resolution), otherwise
10704 -- all remaining non-fully conformant homographs are hidden from
10705 -- visibility (Ada RM 8.3 12.3/2).
10707 if Is_Tagged_Type
(E
) then
10708 Hide_Non_Overridden_Subprograms
(E
);
10713 if Ekind
(E
) = E_Record_Type
10714 and then Is_CPP_Class
(E
)
10715 and then Is_Tagged_Type
(E
)
10716 and then Tagged_Type_Expansion
10718 if CPP_Num_Prims
(E
) = 0 then
10720 -- If the CPP type has user defined components then it must import
10721 -- primitives from C++. This is required because if the C++ class
10722 -- has no primitives then the C++ compiler does not added the _tag
10723 -- component to the type.
10725 if First_Entity
(E
) /= Last_Entity
(E
) then
10727 ("'C'P'P type must import at least one primitive from C++??",
10732 -- Check that all its primitives are abstract or imported from C++.
10733 -- Check also availability of the C++ constructor.
10736 Has_Constructors
: constant Boolean := Has_CPP_Constructors
(E
);
10738 Error_Reported
: Boolean := False;
10742 Elmt
:= First_Elmt
(Primitive_Operations
(E
));
10743 while Present
(Elmt
) loop
10744 Prim
:= Node
(Elmt
);
10746 if Comes_From_Source
(Prim
) then
10747 if Is_Abstract_Subprogram
(Prim
) then
10750 elsif not Is_Imported
(Prim
)
10751 or else Convention
(Prim
) /= Convention_CPP
10754 ("primitives of 'C'P'P types must be imported from C++ "
10755 & "or abstract??", Prim
);
10757 elsif not Has_Constructors
10758 and then not Error_Reported
10760 Error_Msg_Name_1
:= Chars
(E
);
10762 ("??'C'P'P constructor required for type %", Prim
);
10763 Error_Reported
:= True;
10772 -- Check Ada derivation of CPP type
10774 if Expander_Active
-- why? losing errors in -gnatc mode???
10775 and then Present
(Etype
(E
)) -- defend against errors
10776 and then Tagged_Type_Expansion
10777 and then Ekind
(E
) = E_Record_Type
10778 and then Etype
(E
) /= E
10779 and then Is_CPP_Class
(Etype
(E
))
10780 and then CPP_Num_Prims
(Etype
(E
)) > 0
10781 and then not Is_CPP_Class
(E
)
10782 and then not Has_CPP_Constructors
(Etype
(E
))
10784 -- If the parent has C++ primitives but it has no constructor then
10785 -- check that all the primitives are overridden in this derivation;
10786 -- otherwise the constructor of the parent is needed to build the
10794 Elmt
:= First_Elmt
(Primitive_Operations
(E
));
10795 while Present
(Elmt
) loop
10796 Prim
:= Node
(Elmt
);
10798 if not Is_Abstract_Subprogram
(Prim
)
10799 and then No
(Interface_Alias
(Prim
))
10800 and then Find_Dispatching_Type
(Ultimate_Alias
(Prim
)) /= E
10802 Error_Msg_Name_1
:= Chars
(Etype
(E
));
10804 ("'C'P'P constructor required for parent type %", E
);
10813 Inside_Freezing_Actions
:= Inside_Freezing_Actions
- 1;
10815 -- If we have a type with predicates, build predicate function. This is
10816 -- not needed in the generic case, nor within TSS subprograms and other
10817 -- predefined primitives.
10820 and then Non_Generic_Case
10821 and then not Within_Internal_Subprogram
10822 and then Has_Predicates
(E
)
10824 Build_Predicate_Functions
(E
, N
);
10827 -- If type has delayed aspects, this is where we do the preanalysis at
10828 -- the freeze point, as part of the consistent visibility check. Note
10829 -- that this must be done after calling Build_Predicate_Functions or
10830 -- Build_Invariant_Procedure since these subprograms fix occurrences of
10831 -- the subtype name in the saved expression so that they will not cause
10832 -- trouble in the preanalysis.
10834 -- This is also not needed in the generic case
10836 if Non_Generic_Case
10837 and then Has_Delayed_Aspects
(E
)
10838 and then Scope
(E
) = Current_Scope
10840 -- Retrieve the visibility to the discriminants in order to properly
10841 -- analyze the aspects.
10843 Push_Scope_And_Install_Discriminants
(E
);
10849 -- Look for aspect specification entries for this entity
10851 Ritem
:= First_Rep_Item
(E
);
10852 while Present
(Ritem
) loop
10853 if Nkind
(Ritem
) = N_Aspect_Specification
10854 and then Entity
(Ritem
) = E
10855 and then Is_Delayed_Aspect
(Ritem
)
10857 Check_Aspect_At_Freeze_Point
(Ritem
);
10860 Next_Rep_Item
(Ritem
);
10864 Uninstall_Discriminants_And_Pop_Scope
(E
);
10867 -- For a record type, deal with variant parts. This has to be delayed
10868 -- to this point, because of the issue of statically predicated
10869 -- subtypes, which we have to ensure are frozen before checking
10870 -- choices, since we need to have the static choice list set.
10872 if Is_Record_Type
(E
) then
10873 Check_Variant_Part
: declare
10874 D
: constant Node_Id
:= Declaration_Node
(E
);
10879 Others_Present
: Boolean;
10880 pragma Warnings
(Off
, Others_Present
);
10881 -- Indicates others present, not used in this case
10883 procedure Non_Static_Choice_Error
(Choice
: Node_Id
);
10884 -- Error routine invoked by the generic instantiation below when
10885 -- the variant part has a non static choice.
10887 procedure Process_Declarations
(Variant
: Node_Id
);
10888 -- Processes declarations associated with a variant. We analyzed
10889 -- the declarations earlier (in Sem_Ch3.Analyze_Variant_Part),
10890 -- but we still need the recursive call to Check_Choices for any
10891 -- nested variant to get its choices properly processed. This is
10892 -- also where we expand out the choices if expansion is active.
10894 package Variant_Choices_Processing
is new
10895 Generic_Check_Choices
10896 (Process_Empty_Choice
=> No_OP
,
10897 Process_Non_Static_Choice
=> Non_Static_Choice_Error
,
10898 Process_Associated_Node
=> Process_Declarations
);
10899 use Variant_Choices_Processing
;
10901 -----------------------------
10902 -- Non_Static_Choice_Error --
10903 -----------------------------
10905 procedure Non_Static_Choice_Error
(Choice
: Node_Id
) is
10907 Flag_Non_Static_Expr
10908 ("choice given in variant part is not static!", Choice
);
10909 end Non_Static_Choice_Error
;
10911 --------------------------
10912 -- Process_Declarations --
10913 --------------------------
10915 procedure Process_Declarations
(Variant
: Node_Id
) is
10916 CL
: constant Node_Id
:= Component_List
(Variant
);
10920 -- Check for static predicate present in this variant
10922 if Has_SP_Choice
(Variant
) then
10924 -- Here we expand. You might expect to find this call in
10925 -- Expand_N_Variant_Part, but that is called when we first
10926 -- see the variant part, and we cannot do this expansion
10927 -- earlier than the freeze point, since for statically
10928 -- predicated subtypes, the predicate is not known till
10929 -- the freeze point.
10931 -- Furthermore, we do this expansion even if the expander
10932 -- is not active, because other semantic processing, e.g.
10933 -- for aggregates, requires the expanded list of choices.
10935 -- If the expander is not active, then we can't just clobber
10936 -- the list since it would invalidate the ASIS -gnatct tree.
10937 -- So we have to rewrite the variant part with a Rewrite
10938 -- call that replaces it with a copy and clobber the copy.
10940 if not Expander_Active
then
10942 NewV
: constant Node_Id
:= New_Copy
(Variant
);
10944 Set_Discrete_Choices
10945 (NewV
, New_Copy_List
(Discrete_Choices
(Variant
)));
10946 Rewrite
(Variant
, NewV
);
10950 Expand_Static_Predicates_In_Choices
(Variant
);
10953 -- We don't need to worry about the declarations in the variant
10954 -- (since they were analyzed by Analyze_Choices when we first
10955 -- encountered the variant), but we do need to take care of
10956 -- expansion of any nested variants.
10958 if not Null_Present
(CL
) then
10959 VP
:= Variant_Part
(CL
);
10961 if Present
(VP
) then
10963 (VP
, Variants
(VP
), Etype
(Name
(VP
)), Others_Present
);
10966 end Process_Declarations
;
10968 -- Start of processing for Check_Variant_Part
10971 -- Find component list
10975 if Nkind
(D
) = N_Full_Type_Declaration
then
10976 T
:= Type_Definition
(D
);
10978 if Nkind
(T
) = N_Record_Definition
then
10979 C
:= Component_List
(T
);
10981 elsif Nkind
(T
) = N_Derived_Type_Definition
10982 and then Present
(Record_Extension_Part
(T
))
10984 C
:= Component_List
(Record_Extension_Part
(T
));
10988 -- Case of variant part present
10990 if Present
(C
) and then Present
(Variant_Part
(C
)) then
10991 VP
:= Variant_Part
(C
);
10996 (VP
, Variants
(VP
), Etype
(Name
(VP
)), Others_Present
);
10998 -- If the last variant does not contain the Others choice,
10999 -- replace it with an N_Others_Choice node since Gigi always
11000 -- wants an Others. Note that we do not bother to call Analyze
11001 -- on the modified variant part, since its only effect would be
11002 -- to compute the Others_Discrete_Choices node laboriously, and
11003 -- of course we already know the list of choices corresponding
11004 -- to the others choice (it's the list we're replacing).
11006 -- We only want to do this if the expander is active, since
11007 -- we do not want to clobber the ASIS tree.
11009 if Expander_Active
then
11011 Last_Var
: constant Node_Id
:=
11012 Last_Non_Pragma
(Variants
(VP
));
11014 Others_Node
: Node_Id
;
11017 if Nkind
(First
(Discrete_Choices
(Last_Var
))) /=
11020 Others_Node
:= Make_Others_Choice
(Sloc
(Last_Var
));
11021 Set_Others_Discrete_Choices
11022 (Others_Node
, Discrete_Choices
(Last_Var
));
11023 Set_Discrete_Choices
11024 (Last_Var
, New_List
(Others_Node
));
11029 end Check_Variant_Part
;
11031 end Freeze_Entity_Checks
;
11033 -------------------------
11034 -- Get_Alignment_Value --
11035 -------------------------
11037 function Get_Alignment_Value
(Expr
: Node_Id
) return Uint
is
11038 Align
: constant Uint
:= Static_Integer
(Expr
);
11041 if Align
= No_Uint
then
11044 elsif Align
<= 0 then
11046 -- This error is suppressed in ASIS mode to allow for different ASIS
11047 -- back ends or ASIS-based tools to query the illegal clause.
11049 if not ASIS_Mode
then
11050 Error_Msg_N
("alignment value must be positive", Expr
);
11056 for J
in Int
range 0 .. 64 loop
11058 M
: constant Uint
:= Uint_2
** J
;
11061 exit when M
= Align
;
11065 -- This error is suppressed in ASIS mode to allow for
11066 -- different ASIS back ends or ASIS-based tools to query the
11069 if not ASIS_Mode
then
11070 Error_Msg_N
("alignment value must be power of 2", Expr
);
11080 end Get_Alignment_Value
;
11082 -----------------------------
11083 -- Get_Interfacing_Aspects --
11084 -----------------------------
11086 procedure Get_Interfacing_Aspects
11087 (Iface_Asp
: Node_Id
;
11088 Conv_Asp
: out Node_Id
;
11089 EN_Asp
: out Node_Id
;
11090 Expo_Asp
: out Node_Id
;
11091 Imp_Asp
: out Node_Id
;
11092 LN_Asp
: out Node_Id
;
11093 Do_Checks
: Boolean := False)
11095 procedure Save_Or_Duplication_Error
11097 To
: in out Node_Id
);
11098 -- Save the value of aspect Asp in node To. If To already has a value,
11099 -- then this is considered a duplicate use of aspect. Emit an error if
11100 -- flag Do_Checks is set.
11102 -------------------------------
11103 -- Save_Or_Duplication_Error --
11104 -------------------------------
11106 procedure Save_Or_Duplication_Error
11108 To
: in out Node_Id
)
11111 -- Detect an extra aspect and issue an error
11113 if Present
(To
) then
11115 Error_Msg_Name_1
:= Chars
(Identifier
(Asp
));
11116 Error_Msg_Sloc
:= Sloc
(To
);
11117 Error_Msg_N
("aspect % previously given #", Asp
);
11120 -- Otherwise capture the aspect
11125 end Save_Or_Duplication_Error
;
11130 Asp_Id
: Aspect_Id
;
11132 -- The following variables capture each individual aspect
11134 Conv
: Node_Id
:= Empty
;
11135 EN
: Node_Id
:= Empty
;
11136 Expo
: Node_Id
:= Empty
;
11137 Imp
: Node_Id
:= Empty
;
11138 LN
: Node_Id
:= Empty
;
11140 -- Start of processing for Get_Interfacing_Aspects
11143 -- The input interfacing aspect should reside in an aspect specification
11146 pragma Assert
(Is_List_Member
(Iface_Asp
));
11148 -- Examine the aspect specifications of the related entity. Find and
11149 -- capture all interfacing aspects. Detect duplicates and emit errors
11152 Asp
:= First
(List_Containing
(Iface_Asp
));
11153 while Present
(Asp
) loop
11154 Asp_Id
:= Get_Aspect_Id
(Asp
);
11156 if Asp_Id
= Aspect_Convention
then
11157 Save_Or_Duplication_Error
(Asp
, Conv
);
11159 elsif Asp_Id
= Aspect_External_Name
then
11160 Save_Or_Duplication_Error
(Asp
, EN
);
11162 elsif Asp_Id
= Aspect_Export
then
11163 Save_Or_Duplication_Error
(Asp
, Expo
);
11165 elsif Asp_Id
= Aspect_Import
then
11166 Save_Or_Duplication_Error
(Asp
, Imp
);
11168 elsif Asp_Id
= Aspect_Link_Name
then
11169 Save_Or_Duplication_Error
(Asp
, LN
);
11180 end Get_Interfacing_Aspects
;
11182 -------------------------------------
11183 -- Inherit_Aspects_At_Freeze_Point --
11184 -------------------------------------
11186 procedure Inherit_Aspects_At_Freeze_Point
(Typ
: Entity_Id
) is
11187 function Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11188 (Rep_Item
: Node_Id
) return Boolean;
11189 -- This routine checks if Rep_Item is either a pragma or an aspect
11190 -- specification node whose correponding pragma (if any) is present in
11191 -- the Rep Item chain of the entity it has been specified to.
11193 --------------------------------------------------
11194 -- Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item --
11195 --------------------------------------------------
11197 function Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11198 (Rep_Item
: Node_Id
) return Boolean
11202 Nkind
(Rep_Item
) = N_Pragma
11203 or else Present_In_Rep_Item
11204 (Entity
(Rep_Item
), Aspect_Rep_Item
(Rep_Item
));
11205 end Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
;
11207 -- Start of processing for Inherit_Aspects_At_Freeze_Point
11210 -- A representation item is either subtype-specific (Size and Alignment
11211 -- clauses) or type-related (all others). Subtype-specific aspects may
11212 -- differ for different subtypes of the same type (RM 13.1.8).
11214 -- A derived type inherits each type-related representation aspect of
11215 -- its parent type that was directly specified before the declaration of
11216 -- the derived type (RM 13.1.15).
11218 -- A derived subtype inherits each subtype-specific representation
11219 -- aspect of its parent subtype that was directly specified before the
11220 -- declaration of the derived type (RM 13.1.15).
11222 -- The general processing involves inheriting a representation aspect
11223 -- from a parent type whenever the first rep item (aspect specification,
11224 -- attribute definition clause, pragma) corresponding to the given
11225 -- representation aspect in the rep item chain of Typ, if any, isn't
11226 -- directly specified to Typ but to one of its parents.
11228 -- ??? Note that, for now, just a limited number of representation
11229 -- aspects have been inherited here so far. Many of them are
11230 -- still inherited in Sem_Ch3. This will be fixed soon. Here is
11231 -- a non- exhaustive list of aspects that likely also need to
11232 -- be moved to this routine: Alignment, Component_Alignment,
11233 -- Component_Size, Machine_Radix, Object_Size, Pack, Predicates,
11234 -- Preelaborable_Initialization, RM_Size and Small.
11236 -- In addition, Convention must be propagated from base type to subtype,
11237 -- because the subtype may have been declared on an incomplete view.
11239 if Nkind
(Parent
(Typ
)) = N_Private_Extension_Declaration
then
11245 if not Has_Rep_Item
(Typ
, Name_Ada_05
, Name_Ada_2005
, False)
11246 and then Has_Rep_Item
(Typ
, Name_Ada_05
, Name_Ada_2005
)
11247 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11248 (Get_Rep_Item
(Typ
, Name_Ada_05
, Name_Ada_2005
))
11250 Set_Is_Ada_2005_Only
(Typ
);
11255 if not Has_Rep_Item
(Typ
, Name_Ada_12
, Name_Ada_2012
, False)
11256 and then Has_Rep_Item
(Typ
, Name_Ada_12
, Name_Ada_2012
)
11257 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11258 (Get_Rep_Item
(Typ
, Name_Ada_12
, Name_Ada_2012
))
11260 Set_Is_Ada_2012_Only
(Typ
);
11265 if not Has_Rep_Item
(Typ
, Name_Atomic
, Name_Shared
, False)
11266 and then Has_Rep_Pragma
(Typ
, Name_Atomic
, Name_Shared
)
11267 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11268 (Get_Rep_Item
(Typ
, Name_Atomic
, Name_Shared
))
11270 Set_Is_Atomic
(Typ
);
11271 Set_Is_Volatile
(Typ
);
11272 Set_Treat_As_Volatile
(Typ
);
11277 if Is_Record_Type
(Typ
)
11278 and then Typ
/= Base_Type
(Typ
) and then Is_Frozen
(Base_Type
(Typ
))
11280 Set_Convention
(Typ
, Convention
(Base_Type
(Typ
)));
11283 -- Default_Component_Value
11285 -- Verify that there is no rep_item declared for the type, and there
11286 -- is one coming from an ancestor.
11288 if Is_Array_Type
(Typ
)
11289 and then Is_Base_Type
(Typ
)
11290 and then not Has_Rep_Item
(Typ
, Name_Default_Component_Value
, False)
11291 and then Has_Rep_Item
(Typ
, Name_Default_Component_Value
)
11293 Set_Default_Aspect_Component_Value
(Typ
,
11294 Default_Aspect_Component_Value
11295 (Entity
(Get_Rep_Item
(Typ
, Name_Default_Component_Value
))));
11300 if Is_Scalar_Type
(Typ
)
11301 and then Is_Base_Type
(Typ
)
11302 and then not Has_Rep_Item
(Typ
, Name_Default_Value
, False)
11303 and then Has_Rep_Item
(Typ
, Name_Default_Value
)
11305 Set_Has_Default_Aspect
(Typ
);
11306 Set_Default_Aspect_Value
(Typ
,
11307 Default_Aspect_Value
11308 (Entity
(Get_Rep_Item
(Typ
, Name_Default_Value
))));
11313 if not Has_Rep_Item
(Typ
, Name_Discard_Names
, False)
11314 and then Has_Rep_Item
(Typ
, Name_Discard_Names
)
11315 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11316 (Get_Rep_Item
(Typ
, Name_Discard_Names
))
11318 Set_Discard_Names
(Typ
);
11323 if not Has_Rep_Item
(Typ
, Name_Volatile
, False)
11324 and then Has_Rep_Item
(Typ
, Name_Volatile
)
11325 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11326 (Get_Rep_Item
(Typ
, Name_Volatile
))
11328 Set_Is_Volatile
(Typ
);
11329 Set_Treat_As_Volatile
(Typ
);
11332 -- Volatile_Full_Access
11334 if not Has_Rep_Item
(Typ
, Name_Volatile_Full_Access
, False)
11335 and then Has_Rep_Pragma
(Typ
, Name_Volatile_Full_Access
)
11336 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11337 (Get_Rep_Item
(Typ
, Name_Volatile_Full_Access
))
11339 Set_Is_Volatile_Full_Access
(Typ
);
11340 Set_Is_Volatile
(Typ
);
11341 Set_Treat_As_Volatile
(Typ
);
11344 -- Inheritance for derived types only
11346 if Is_Derived_Type
(Typ
) then
11348 Bas_Typ
: constant Entity_Id
:= Base_Type
(Typ
);
11349 Imp_Bas_Typ
: constant Entity_Id
:= Implementation_Base_Type
(Typ
);
11352 -- Atomic_Components
11354 if not Has_Rep_Item
(Typ
, Name_Atomic_Components
, False)
11355 and then Has_Rep_Item
(Typ
, Name_Atomic_Components
)
11356 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11357 (Get_Rep_Item
(Typ
, Name_Atomic_Components
))
11359 Set_Has_Atomic_Components
(Imp_Bas_Typ
);
11362 -- Volatile_Components
11364 if not Has_Rep_Item
(Typ
, Name_Volatile_Components
, False)
11365 and then Has_Rep_Item
(Typ
, Name_Volatile_Components
)
11366 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11367 (Get_Rep_Item
(Typ
, Name_Volatile_Components
))
11369 Set_Has_Volatile_Components
(Imp_Bas_Typ
);
11372 -- Finalize_Storage_Only
11374 if not Has_Rep_Pragma
(Typ
, Name_Finalize_Storage_Only
, False)
11375 and then Has_Rep_Pragma
(Typ
, Name_Finalize_Storage_Only
)
11377 Set_Finalize_Storage_Only
(Bas_Typ
);
11380 -- Universal_Aliasing
11382 if not Has_Rep_Item
(Typ
, Name_Universal_Aliasing
, False)
11383 and then Has_Rep_Item
(Typ
, Name_Universal_Aliasing
)
11384 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11385 (Get_Rep_Item
(Typ
, Name_Universal_Aliasing
))
11387 Set_Universal_Aliasing
(Imp_Bas_Typ
);
11392 if Is_Record_Type
(Typ
) then
11393 if not Has_Rep_Item
(Typ
, Name_Bit_Order
, False)
11394 and then Has_Rep_Item
(Typ
, Name_Bit_Order
)
11396 Set_Reverse_Bit_Order
(Bas_Typ
,
11397 Reverse_Bit_Order
(Entity
(Name
11398 (Get_Rep_Item
(Typ
, Name_Bit_Order
)))));
11402 -- Scalar_Storage_Order
11404 -- Note: the aspect is specified on a first subtype, but recorded
11405 -- in a flag of the base type!
11407 if (Is_Record_Type
(Typ
) or else Is_Array_Type
(Typ
))
11408 and then Typ
= Bas_Typ
11410 -- For a type extension, always inherit from parent; otherwise
11411 -- inherit if no default applies. Note: we do not check for
11412 -- an explicit rep item on the parent type when inheriting,
11413 -- because the parent SSO may itself have been set by default.
11415 if not Has_Rep_Item
(First_Subtype
(Typ
),
11416 Name_Scalar_Storage_Order
, False)
11417 and then (Is_Tagged_Type
(Bas_Typ
)
11418 or else not (SSO_Set_Low_By_Default
(Bas_Typ
)
11420 SSO_Set_High_By_Default
(Bas_Typ
)))
11422 Set_Reverse_Storage_Order
(Bas_Typ
,
11423 Reverse_Storage_Order
11424 (Implementation_Base_Type
(Etype
(Bas_Typ
))));
11426 -- Clear default SSO indications, since the inherited aspect
11427 -- which was set explicitly overrides the default.
11429 Set_SSO_Set_Low_By_Default
(Bas_Typ
, False);
11430 Set_SSO_Set_High_By_Default
(Bas_Typ
, False);
11435 end Inherit_Aspects_At_Freeze_Point
;
11441 procedure Initialize
is
11443 Address_Clause_Checks
.Init
;
11444 Compile_Time_Warnings_Errors
.Init
;
11445 Unchecked_Conversions
.Init
;
11447 if AAMP_On_Target
then
11448 Independence_Checks
.Init
;
11452 ---------------------------
11453 -- Install_Discriminants --
11454 ---------------------------
11456 procedure Install_Discriminants
(E
: Entity_Id
) is
11460 Disc
:= First_Discriminant
(E
);
11461 while Present
(Disc
) loop
11462 Prev
:= Current_Entity
(Disc
);
11463 Set_Current_Entity
(Disc
);
11464 Set_Is_Immediately_Visible
(Disc
);
11465 Set_Homonym
(Disc
, Prev
);
11466 Next_Discriminant
(Disc
);
11468 end Install_Discriminants
;
11470 -------------------------
11471 -- Is_Operational_Item --
11472 -------------------------
11474 function Is_Operational_Item
(N
: Node_Id
) return Boolean is
11476 if Nkind
(N
) /= N_Attribute_Definition_Clause
then
11481 Id
: constant Attribute_Id
:= Get_Attribute_Id
(Chars
(N
));
11484 -- List of operational items is given in AARM 13.1(8.mm/1).
11485 -- It is clearly incomplete, as it does not include iterator
11486 -- aspects, among others.
11488 return Id
= Attribute_Constant_Indexing
11489 or else Id
= Attribute_Default_Iterator
11490 or else Id
= Attribute_Implicit_Dereference
11491 or else Id
= Attribute_Input
11492 or else Id
= Attribute_Iterator_Element
11493 or else Id
= Attribute_Iterable
11494 or else Id
= Attribute_Output
11495 or else Id
= Attribute_Read
11496 or else Id
= Attribute_Variable_Indexing
11497 or else Id
= Attribute_Write
11498 or else Id
= Attribute_External_Tag
;
11501 end Is_Operational_Item
;
11503 -------------------------
11504 -- Is_Predicate_Static --
11505 -------------------------
11507 -- Note: the basic legality of the expression has already been checked, so
11508 -- we don't need to worry about cases or ranges on strings for example.
11510 function Is_Predicate_Static
11512 Nam
: Name_Id
) return Boolean
11514 function All_Static_Case_Alternatives
(L
: List_Id
) return Boolean;
11515 -- Given a list of case expression alternatives, returns True if all
11516 -- the alternatives are static (have all static choices, and a static
11519 function All_Static_Choices
(L
: List_Id
) return Boolean;
11520 -- Returns true if all elements of the list are OK static choices
11521 -- as defined below for Is_Static_Choice. Used for case expression
11522 -- alternatives and for the right operand of a membership test. An
11523 -- others_choice is static if the corresponding expression is static.
11524 -- The staticness of the bounds is checked separately.
11526 function Is_Static_Choice
(N
: Node_Id
) return Boolean;
11527 -- Returns True if N represents a static choice (static subtype, or
11528 -- static subtype indication, or static expression, or static range).
11530 -- Note that this is a bit more inclusive than we actually need
11531 -- (in particular membership tests do not allow the use of subtype
11532 -- indications). But that doesn't matter, we have already checked
11533 -- that the construct is legal to get this far.
11535 function Is_Type_Ref
(N
: Node_Id
) return Boolean;
11536 pragma Inline
(Is_Type_Ref
);
11537 -- Returns True if N is a reference to the type for the predicate in the
11538 -- expression (i.e. if it is an identifier whose Chars field matches the
11539 -- Nam given in the call). N must not be parenthesized, if the type name
11540 -- appears in parens, this routine will return False.
11542 ----------------------------------
11543 -- All_Static_Case_Alternatives --
11544 ----------------------------------
11546 function All_Static_Case_Alternatives
(L
: List_Id
) return Boolean is
11551 while Present
(N
) loop
11552 if not (All_Static_Choices
(Discrete_Choices
(N
))
11553 and then Is_OK_Static_Expression
(Expression
(N
)))
11562 end All_Static_Case_Alternatives
;
11564 ------------------------
11565 -- All_Static_Choices --
11566 ------------------------
11568 function All_Static_Choices
(L
: List_Id
) return Boolean is
11573 while Present
(N
) loop
11574 if not Is_Static_Choice
(N
) then
11582 end All_Static_Choices
;
11584 ----------------------
11585 -- Is_Static_Choice --
11586 ----------------------
11588 function Is_Static_Choice
(N
: Node_Id
) return Boolean is
11590 return Nkind
(N
) = N_Others_Choice
11591 or else Is_OK_Static_Expression
(N
)
11592 or else (Is_Entity_Name
(N
) and then Is_Type
(Entity
(N
))
11593 and then Is_OK_Static_Subtype
(Entity
(N
)))
11594 or else (Nkind
(N
) = N_Subtype_Indication
11595 and then Is_OK_Static_Subtype
(Entity
(N
)))
11596 or else (Nkind
(N
) = N_Range
and then Is_OK_Static_Range
(N
));
11597 end Is_Static_Choice
;
11603 function Is_Type_Ref
(N
: Node_Id
) return Boolean is
11605 return Nkind
(N
) = N_Identifier
11606 and then Chars
(N
) = Nam
11607 and then Paren_Count
(N
) = 0;
11610 -- Start of processing for Is_Predicate_Static
11613 -- Predicate_Static means one of the following holds. Numbers are the
11614 -- corresponding paragraph numbers in (RM 3.2.4(16-22)).
11616 -- 16: A static expression
11618 if Is_OK_Static_Expression
(Expr
) then
11621 -- 17: A membership test whose simple_expression is the current
11622 -- instance, and whose membership_choice_list meets the requirements
11623 -- for a static membership test.
11625 elsif Nkind
(Expr
) in N_Membership_Test
11626 and then ((Present
(Right_Opnd
(Expr
))
11627 and then Is_Static_Choice
(Right_Opnd
(Expr
)))
11629 (Present
(Alternatives
(Expr
))
11630 and then All_Static_Choices
(Alternatives
(Expr
))))
11634 -- 18. A case_expression whose selecting_expression is the current
11635 -- instance, and whose dependent expressions are static expressions.
11637 elsif Nkind
(Expr
) = N_Case_Expression
11638 and then Is_Type_Ref
(Expression
(Expr
))
11639 and then All_Static_Case_Alternatives
(Alternatives
(Expr
))
11643 -- 19. A call to a predefined equality or ordering operator, where one
11644 -- operand is the current instance, and the other is a static
11647 -- Note: the RM is clearly wrong here in not excluding string types.
11648 -- Without this exclusion, we would allow expressions like X > "ABC"
11649 -- to be considered as predicate-static, which is clearly not intended,
11650 -- since the idea is for predicate-static to be a subset of normal
11651 -- static expressions (and "DEF" > "ABC" is not a static expression).
11653 -- However, we do allow internally generated (not from source) equality
11654 -- and inequality operations to be valid on strings (this helps deal
11655 -- with cases where we transform A in "ABC" to A = "ABC).
11657 elsif Nkind
(Expr
) in N_Op_Compare
11658 and then ((not Is_String_Type
(Etype
(Left_Opnd
(Expr
))))
11659 or else (Nkind_In
(Expr
, N_Op_Eq
, N_Op_Ne
)
11660 and then not Comes_From_Source
(Expr
)))
11661 and then ((Is_Type_Ref
(Left_Opnd
(Expr
))
11662 and then Is_OK_Static_Expression
(Right_Opnd
(Expr
)))
11664 (Is_Type_Ref
(Right_Opnd
(Expr
))
11665 and then Is_OK_Static_Expression
(Left_Opnd
(Expr
))))
11669 -- 20. A call to a predefined boolean logical operator, where each
11670 -- operand is predicate-static.
11672 elsif (Nkind_In
(Expr
, N_Op_And
, N_Op_Or
, N_Op_Xor
)
11673 and then Is_Predicate_Static
(Left_Opnd
(Expr
), Nam
)
11674 and then Is_Predicate_Static
(Right_Opnd
(Expr
), Nam
))
11676 (Nkind
(Expr
) = N_Op_Not
11677 and then Is_Predicate_Static
(Right_Opnd
(Expr
), Nam
))
11681 -- 21. A short-circuit control form where both operands are
11682 -- predicate-static.
11684 elsif Nkind
(Expr
) in N_Short_Circuit
11685 and then Is_Predicate_Static
(Left_Opnd
(Expr
), Nam
)
11686 and then Is_Predicate_Static
(Right_Opnd
(Expr
), Nam
)
11690 -- 22. A parenthesized predicate-static expression. This does not
11691 -- require any special test, since we just ignore paren levels in
11692 -- all the cases above.
11694 -- One more test that is an implementation artifact caused by the fact
11695 -- that we are analyzing not the original expression, but the generated
11696 -- expression in the body of the predicate function. This can include
11697 -- references to inherited predicates, so that the expression we are
11698 -- processing looks like:
11700 -- xxPredicate (typ (Inns)) and then expression
11702 -- Where the call is to a Predicate function for an inherited predicate.
11703 -- We simply ignore such a call, which could be to either a dynamic or
11704 -- a static predicate. Note that if the parent predicate is dynamic then
11705 -- eventually this type will be marked as dynamic, but you are allowed
11706 -- to specify a static predicate for a subtype which is inheriting a
11707 -- dynamic predicate, so the static predicate validation here ignores
11708 -- the inherited predicate even if it is dynamic.
11709 -- In all cases, a static predicate can only apply to a scalar type.
11711 elsif Nkind
(Expr
) = N_Function_Call
11712 and then Is_Predicate_Function
(Entity
(Name
(Expr
)))
11713 and then Is_Scalar_Type
(Etype
(First_Entity
(Entity
(Name
(Expr
)))))
11717 -- That's an exhaustive list of tests, all other cases are not
11718 -- predicate-static, so we return False.
11723 end Is_Predicate_Static
;
11725 ---------------------
11726 -- Kill_Rep_Clause --
11727 ---------------------
11729 procedure Kill_Rep_Clause
(N
: Node_Id
) is
11731 pragma Assert
(Ignore_Rep_Clauses
);
11733 -- Note: we use Replace rather than Rewrite, because we don't want
11734 -- ASIS to be able to use Original_Node to dig out the (undecorated)
11735 -- rep clause that is being replaced.
11737 Replace
(N
, Make_Null_Statement
(Sloc
(N
)));
11739 -- The null statement must be marked as not coming from source. This is
11740 -- so that ASIS ignores it, and also the back end does not expect bogus
11741 -- "from source" null statements in weird places (e.g. in declarative
11742 -- regions where such null statements are not allowed).
11744 Set_Comes_From_Source
(N
, False);
11745 end Kill_Rep_Clause
;
11751 function Minimum_Size
11753 Biased
: Boolean := False) return Nat
11755 Lo
: Uint
:= No_Uint
;
11756 Hi
: Uint
:= No_Uint
;
11757 LoR
: Ureal
:= No_Ureal
;
11758 HiR
: Ureal
:= No_Ureal
;
11759 LoSet
: Boolean := False;
11760 HiSet
: Boolean := False;
11763 Ancest
: Entity_Id
;
11764 R_Typ
: constant Entity_Id
:= Root_Type
(T
);
11767 -- If bad type, return 0
11769 if T
= Any_Type
then
11772 -- For generic types, just return zero. There cannot be any legitimate
11773 -- need to know such a size, but this routine may be called with a
11774 -- generic type as part of normal processing.
11776 elsif Is_Generic_Type
(R_Typ
) or else R_Typ
= Any_Type
then
11779 -- Access types (cannot have size smaller than System.Address)
11781 elsif Is_Access_Type
(T
) then
11782 return System_Address_Size
;
11784 -- Floating-point types
11786 elsif Is_Floating_Point_Type
(T
) then
11787 return UI_To_Int
(Esize
(R_Typ
));
11791 elsif Is_Discrete_Type
(T
) then
11793 -- The following loop is looking for the nearest compile time known
11794 -- bounds following the ancestor subtype chain. The idea is to find
11795 -- the most restrictive known bounds information.
11799 if Ancest
= Any_Type
or else Etype
(Ancest
) = Any_Type
then
11804 if Compile_Time_Known_Value
(Type_Low_Bound
(Ancest
)) then
11805 Lo
:= Expr_Rep_Value
(Type_Low_Bound
(Ancest
));
11812 if Compile_Time_Known_Value
(Type_High_Bound
(Ancest
)) then
11813 Hi
:= Expr_Rep_Value
(Type_High_Bound
(Ancest
));
11819 Ancest
:= Ancestor_Subtype
(Ancest
);
11821 if No
(Ancest
) then
11822 Ancest
:= Base_Type
(T
);
11824 if Is_Generic_Type
(Ancest
) then
11830 -- Fixed-point types. We can't simply use Expr_Value to get the
11831 -- Corresponding_Integer_Value values of the bounds, since these do not
11832 -- get set till the type is frozen, and this routine can be called
11833 -- before the type is frozen. Similarly the test for bounds being static
11834 -- needs to include the case where we have unanalyzed real literals for
11835 -- the same reason.
11837 elsif Is_Fixed_Point_Type
(T
) then
11839 -- The following loop is looking for the nearest compile time known
11840 -- bounds following the ancestor subtype chain. The idea is to find
11841 -- the most restrictive known bounds information.
11845 if Ancest
= Any_Type
or else Etype
(Ancest
) = Any_Type
then
11849 -- Note: In the following two tests for LoSet and HiSet, it may
11850 -- seem redundant to test for N_Real_Literal here since normally
11851 -- one would assume that the test for the value being known at
11852 -- compile time includes this case. However, there is a glitch.
11853 -- If the real literal comes from folding a non-static expression,
11854 -- then we don't consider any non- static expression to be known
11855 -- at compile time if we are in configurable run time mode (needed
11856 -- in some cases to give a clearer definition of what is and what
11857 -- is not accepted). So the test is indeed needed. Without it, we
11858 -- would set neither Lo_Set nor Hi_Set and get an infinite loop.
11861 if Nkind
(Type_Low_Bound
(Ancest
)) = N_Real_Literal
11862 or else Compile_Time_Known_Value
(Type_Low_Bound
(Ancest
))
11864 LoR
:= Expr_Value_R
(Type_Low_Bound
(Ancest
));
11871 if Nkind
(Type_High_Bound
(Ancest
)) = N_Real_Literal
11872 or else Compile_Time_Known_Value
(Type_High_Bound
(Ancest
))
11874 HiR
:= Expr_Value_R
(Type_High_Bound
(Ancest
));
11880 Ancest
:= Ancestor_Subtype
(Ancest
);
11882 if No
(Ancest
) then
11883 Ancest
:= Base_Type
(T
);
11885 if Is_Generic_Type
(Ancest
) then
11891 Lo
:= UR_To_Uint
(LoR
/ Small_Value
(T
));
11892 Hi
:= UR_To_Uint
(HiR
/ Small_Value
(T
));
11894 -- No other types allowed
11897 raise Program_Error
;
11900 -- Fall through with Hi and Lo set. Deal with biased case
11903 and then not Is_Fixed_Point_Type
(T
)
11904 and then not (Is_Enumeration_Type
(T
)
11905 and then Has_Non_Standard_Rep
(T
)))
11906 or else Has_Biased_Representation
(T
)
11912 -- Null range case, size is always zero. We only do this in the discrete
11913 -- type case, since that's the odd case that came up. Probably we should
11914 -- also do this in the fixed-point case, but doing so causes peculiar
11915 -- gigi failures, and it is not worth worrying about this incredibly
11916 -- marginal case (explicit null-range fixed-point type declarations)???
11918 if Lo
> Hi
and then Is_Discrete_Type
(T
) then
11921 -- Signed case. Note that we consider types like range 1 .. -1 to be
11922 -- signed for the purpose of computing the size, since the bounds have
11923 -- to be accommodated in the base type.
11925 elsif Lo
< 0 or else Hi
< 0 then
11929 -- S = size, B = 2 ** (size - 1) (can accommodate -B .. +(B - 1))
11930 -- Note that we accommodate the case where the bounds cross. This
11931 -- can happen either because of the way the bounds are declared
11932 -- or because of the algorithm in Freeze_Fixed_Point_Type.
11946 -- If both bounds are positive, make sure that both are represen-
11947 -- table in the case where the bounds are crossed. This can happen
11948 -- either because of the way the bounds are declared, or because of
11949 -- the algorithm in Freeze_Fixed_Point_Type.
11955 -- S = size, (can accommodate 0 .. (2**size - 1))
11958 while Hi
>= Uint_2
** S
loop
11966 ---------------------------
11967 -- New_Stream_Subprogram --
11968 ---------------------------
11970 procedure New_Stream_Subprogram
11974 Nam
: TSS_Name_Type
)
11976 Loc
: constant Source_Ptr
:= Sloc
(N
);
11977 Sname
: constant Name_Id
:= Make_TSS_Name
(Base_Type
(Ent
), Nam
);
11978 Subp_Id
: Entity_Id
;
11979 Subp_Decl
: Node_Id
;
11983 Defer_Declaration
: constant Boolean :=
11984 Is_Tagged_Type
(Ent
) or else Is_Private_Type
(Ent
);
11985 -- For a tagged type, there is a declaration for each stream attribute
11986 -- at the freeze point, and we must generate only a completion of this
11987 -- declaration. We do the same for private types, because the full view
11988 -- might be tagged. Otherwise we generate a declaration at the point of
11989 -- the attribute definition clause. If the attribute definition comes
11990 -- from an aspect specification the declaration is part of the freeze
11991 -- actions of the type.
11993 function Build_Spec
return Node_Id
;
11994 -- Used for declaration and renaming declaration, so that this is
11995 -- treated as a renaming_as_body.
12001 function Build_Spec
return Node_Id
is
12002 Out_P
: constant Boolean := (Nam
= TSS_Stream_Read
);
12005 T_Ref
: constant Node_Id
:= New_Occurrence_Of
(Etyp
, Loc
);
12008 Subp_Id
:= Make_Defining_Identifier
(Loc
, Sname
);
12010 -- S : access Root_Stream_Type'Class
12012 Formals
:= New_List
(
12013 Make_Parameter_Specification
(Loc
,
12014 Defining_Identifier
=>
12015 Make_Defining_Identifier
(Loc
, Name_S
),
12017 Make_Access_Definition
(Loc
,
12019 New_Occurrence_Of
(
12020 Designated_Type
(Etype
(F
)), Loc
))));
12022 if Nam
= TSS_Stream_Input
then
12024 Make_Function_Specification
(Loc
,
12025 Defining_Unit_Name
=> Subp_Id
,
12026 Parameter_Specifications
=> Formals
,
12027 Result_Definition
=> T_Ref
);
12031 Append_To
(Formals
,
12032 Make_Parameter_Specification
(Loc
,
12033 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_V
),
12034 Out_Present
=> Out_P
,
12035 Parameter_Type
=> T_Ref
));
12038 Make_Procedure_Specification
(Loc
,
12039 Defining_Unit_Name
=> Subp_Id
,
12040 Parameter_Specifications
=> Formals
);
12046 -- Start of processing for New_Stream_Subprogram
12049 F
:= First_Formal
(Subp
);
12051 if Ekind
(Subp
) = E_Procedure
then
12052 Etyp
:= Etype
(Next_Formal
(F
));
12054 Etyp
:= Etype
(Subp
);
12057 -- Prepare subprogram declaration and insert it as an action on the
12058 -- clause node. The visibility for this entity is used to test for
12059 -- visibility of the attribute definition clause (in the sense of
12060 -- 8.3(23) as amended by AI-195).
12062 if not Defer_Declaration
then
12064 Make_Subprogram_Declaration
(Loc
,
12065 Specification
=> Build_Spec
);
12067 -- For a tagged type, there is always a visible declaration for each
12068 -- stream TSS (it is a predefined primitive operation), and the
12069 -- completion of this declaration occurs at the freeze point, which is
12070 -- not always visible at places where the attribute definition clause is
12071 -- visible. So, we create a dummy entity here for the purpose of
12072 -- tracking the visibility of the attribute definition clause itself.
12076 Make_Defining_Identifier
(Loc
, New_External_Name
(Sname
, 'V'));
12078 Make_Object_Declaration
(Loc
,
12079 Defining_Identifier
=> Subp_Id
,
12080 Object_Definition
=> New_Occurrence_Of
(Standard_Boolean
, Loc
));
12083 if not Defer_Declaration
12084 and then From_Aspect_Specification
(N
)
12085 and then Has_Delayed_Freeze
(Ent
)
12087 Append_Freeze_Action
(Ent
, Subp_Decl
);
12090 Insert_Action
(N
, Subp_Decl
);
12091 Set_Entity
(N
, Subp_Id
);
12095 Make_Subprogram_Renaming_Declaration
(Loc
,
12096 Specification
=> Build_Spec
,
12097 Name
=> New_Occurrence_Of
(Subp
, Loc
));
12099 if Defer_Declaration
then
12100 Set_TSS
(Base_Type
(Ent
), Subp_Id
);
12103 if From_Aspect_Specification
(N
) then
12104 Append_Freeze_Action
(Ent
, Subp_Decl
);
12106 Insert_Action
(N
, Subp_Decl
);
12109 Copy_TSS
(Subp_Id
, Base_Type
(Ent
));
12111 end New_Stream_Subprogram
;
12113 ------------------------------------------
12114 -- Push_Scope_And_Install_Discriminants --
12115 ------------------------------------------
12117 procedure Push_Scope_And_Install_Discriminants
(E
: Entity_Id
) is
12119 if Has_Discriminants
(E
) then
12122 -- Make the discriminants visible for type declarations and protected
12123 -- type declarations, not for subtype declarations (RM 13.1.1 (12/3))
12125 if Nkind
(Parent
(E
)) /= N_Subtype_Declaration
then
12126 Install_Discriminants
(E
);
12129 end Push_Scope_And_Install_Discriminants
;
12131 ------------------------
12132 -- Rep_Item_Too_Early --
12133 ------------------------
12135 function Rep_Item_Too_Early
(T
: Entity_Id
; N
: Node_Id
) return Boolean is
12137 -- Cannot apply non-operational rep items to generic types
12139 if Is_Operational_Item
(N
) then
12143 and then Is_Generic_Type
(Root_Type
(T
))
12144 and then (Nkind
(N
) /= N_Pragma
12145 or else Get_Pragma_Id
(N
) /= Pragma_Convention
)
12147 Error_Msg_N
("representation item not allowed for generic type", N
);
12151 -- Otherwise check for incomplete type
12153 if Is_Incomplete_Or_Private_Type
(T
)
12154 and then No
(Underlying_Type
(T
))
12156 (Nkind
(N
) /= N_Pragma
12157 or else Get_Pragma_Id
(N
) /= Pragma_Import
)
12160 ("representation item must be after full type declaration", N
);
12163 -- If the type has incomplete components, a representation clause is
12164 -- illegal but stream attributes and Convention pragmas are correct.
12166 elsif Has_Private_Component
(T
) then
12167 if Nkind
(N
) = N_Pragma
then
12172 ("representation item must appear after type is fully defined",
12179 end Rep_Item_Too_Early
;
12181 -----------------------
12182 -- Rep_Item_Too_Late --
12183 -----------------------
12185 function Rep_Item_Too_Late
12188 FOnly
: Boolean := False) return Boolean
12191 Parent_Type
: Entity_Id
;
12193 procedure No_Type_Rep_Item
;
12194 -- Output message indicating that no type-related aspects can be
12195 -- specified due to some property of the parent type.
12197 procedure Too_Late
;
12198 -- Output message for an aspect being specified too late
12200 -- Note that neither of the above errors is considered a serious one,
12201 -- since the effect is simply that we ignore the representation clause
12203 -- Is this really true? In any case if we make this change we must
12204 -- document the requirement in the spec of Rep_Item_Too_Late that
12205 -- if True is returned, then the rep item must be completely ignored???
12207 ----------------------
12208 -- No_Type_Rep_Item --
12209 ----------------------
12211 procedure No_Type_Rep_Item
is
12213 Error_Msg_N
("|type-related representation item not permitted!", N
);
12214 end No_Type_Rep_Item
;
12220 procedure Too_Late
is
12222 -- Other compilers seem more relaxed about rep items appearing too
12223 -- late. Since analysis tools typically don't care about rep items
12224 -- anyway, no reason to be too strict about this.
12226 if not Relaxed_RM_Semantics
then
12227 Error_Msg_N
("|representation item appears too late!", N
);
12231 -- Start of processing for Rep_Item_Too_Late
12234 -- First make sure entity is not frozen (RM 13.1(9))
12238 -- Exclude imported types, which may be frozen if they appear in a
12239 -- representation clause for a local type.
12241 and then not From_Limited_With
(T
)
12243 -- Exclude generated entities (not coming from source). The common
12244 -- case is when we generate a renaming which prematurely freezes the
12245 -- renamed internal entity, but we still want to be able to set copies
12246 -- of attribute values such as Size/Alignment.
12248 and then Comes_From_Source
(T
)
12250 -- A self-referential aspect is illegal if it forces freezing the
12251 -- entity before the corresponding pragma has been analyzed.
12253 if Nkind_In
(N
, N_Attribute_Definition_Clause
, N_Pragma
)
12254 and then From_Aspect_Specification
(N
)
12257 ("aspect specification causes premature freezing of&", T
, N
);
12258 Set_Has_Delayed_Freeze
(T
, False);
12263 S
:= First_Subtype
(T
);
12265 if Present
(Freeze_Node
(S
)) then
12266 if not Relaxed_RM_Semantics
then
12268 ("??no more representation items for }", Freeze_Node
(S
), S
);
12274 -- Check for case of untagged derived type whose parent either has
12275 -- primitive operations, or is a by reference type (RM 13.1(10)). In
12276 -- this case we do not output a Too_Late message, since there is no
12277 -- earlier point where the rep item could be placed to make it legal.
12281 and then Is_Derived_Type
(T
)
12282 and then not Is_Tagged_Type
(T
)
12284 Parent_Type
:= Etype
(Base_Type
(T
));
12286 if Has_Primitive_Operations
(Parent_Type
) then
12289 if not Relaxed_RM_Semantics
then
12291 ("\parent type & has primitive operations!", N
, Parent_Type
);
12296 elsif Is_By_Reference_Type
(Parent_Type
) then
12299 if not Relaxed_RM_Semantics
then
12301 ("\parent type & is a by reference type!", N
, Parent_Type
);
12308 -- No error, but one more warning to consider. The RM (surprisingly)
12309 -- allows this pattern:
12312 -- primitive operations for S
12313 -- type R is new S;
12314 -- rep clause for S
12316 -- Meaning that calls on the primitive operations of S for values of
12317 -- type R may require possibly expensive implicit conversion operations.
12318 -- This is not an error, but is worth a warning.
12320 if not Relaxed_RM_Semantics
and then Is_Type
(T
) then
12322 DTL
: constant Entity_Id
:= Derived_Type_Link
(Base_Type
(T
));
12326 and then Has_Primitive_Operations
(Base_Type
(T
))
12328 -- For now, do not generate this warning for the case of aspect
12329 -- specification using Ada 2012 syntax, since we get wrong
12330 -- messages we do not understand. The whole business of derived
12331 -- types and rep items seems a bit confused when aspects are
12332 -- used, since the aspects are not evaluated till freeze time.
12334 and then not From_Aspect_Specification
(N
)
12336 Error_Msg_Sloc
:= Sloc
(DTL
);
12338 ("representation item for& appears after derived type "
12339 & "declaration#??", N
);
12341 ("\may result in implicit conversions for primitive "
12342 & "operations of&??", N
, T
);
12344 ("\to change representations when called with arguments "
12345 & "of type&??", N
, DTL
);
12350 -- No error, link item into head of chain of rep items for the entity,
12351 -- but avoid chaining if we have an overloadable entity, and the pragma
12352 -- is one that can apply to multiple overloaded entities.
12354 if Is_Overloadable
(T
) and then Nkind
(N
) = N_Pragma
then
12356 Pname
: constant Name_Id
:= Pragma_Name
(N
);
12358 if Nam_In
(Pname
, Name_Convention
, Name_Import
, Name_Export
,
12359 Name_External
, Name_Interface
)
12366 Record_Rep_Item
(T
, N
);
12368 end Rep_Item_Too_Late
;
12370 -------------------------------------
12371 -- Replace_Type_References_Generic --
12372 -------------------------------------
12374 procedure Replace_Type_References_Generic
(N
: Node_Id
; T
: Entity_Id
) is
12375 TName
: constant Name_Id
:= Chars
(T
);
12377 function Replace_Type_Ref
(N
: Node_Id
) return Traverse_Result
;
12378 -- Processes a single node in the traversal procedure below, checking
12379 -- if node N should be replaced, and if so, doing the replacement.
12381 function Visible_Component
(Comp
: Name_Id
) return Entity_Id
;
12382 -- Given an identifier in the expression, check whether there is a
12383 -- discriminant or component of the type that is directy visible, and
12384 -- rewrite it as the corresponding selected component of the formal of
12385 -- the subprogram. The entity is located by a sequential search, which
12386 -- seems acceptable given the typical size of component lists and check
12387 -- expressions. Possible optimization ???
12389 ----------------------
12390 -- Replace_Type_Ref --
12391 ----------------------
12393 function Replace_Type_Ref
(N
: Node_Id
) return Traverse_Result
is
12394 Loc
: constant Source_Ptr
:= Sloc
(N
);
12396 procedure Add_Prefix
(Ref
: Node_Id
; Comp
: Entity_Id
);
12397 -- Add the proper prefix to a reference to a component of the type
12398 -- when it is not already a selected component.
12404 procedure Add_Prefix
(Ref
: Node_Id
; Comp
: Entity_Id
) is
12407 Make_Selected_Component
(Loc
,
12408 Prefix
=> New_Occurrence_Of
(T
, Loc
),
12409 Selector_Name
=> New_Occurrence_Of
(Comp
, Loc
)));
12410 Replace_Type_Reference
(Prefix
(Ref
));
12419 -- Start of processing for Replace_Type_Ref
12422 if Nkind
(N
) = N_Identifier
then
12424 -- If not the type name, check whether it is a reference to some
12425 -- other type, which must be frozen before the predicate function
12426 -- is analyzed, i.e. before the freeze node of the type to which
12427 -- the predicate applies.
12429 if Chars
(N
) /= TName
then
12430 if Present
(Current_Entity
(N
))
12431 and then Is_Type
(Current_Entity
(N
))
12433 Freeze_Before
(Freeze_Node
(T
), Current_Entity
(N
));
12436 -- The components of the type are directly visible and can
12437 -- be referenced without a prefix.
12439 if Nkind
(Parent
(N
)) = N_Selected_Component
then
12442 -- In expression C (I), C may be a directly visible function
12443 -- or a visible component that has an array type. Disambiguate
12444 -- by examining the component type.
12446 elsif Nkind
(Parent
(N
)) = N_Indexed_Component
12447 and then N
= Prefix
(Parent
(N
))
12449 Comp
:= Visible_Component
(Chars
(N
));
12451 if Present
(Comp
) and then Is_Array_Type
(Etype
(Comp
)) then
12452 Add_Prefix
(N
, Comp
);
12456 Comp
:= Visible_Component
(Chars
(N
));
12458 if Present
(Comp
) then
12459 Add_Prefix
(N
, Comp
);
12465 -- Otherwise do the replacement and we are done with this node
12468 Replace_Type_Reference
(N
);
12472 -- Case of selected component (which is what a qualification looks
12473 -- like in the unanalyzed tree, which is what we have.
12475 elsif Nkind
(N
) = N_Selected_Component
then
12477 -- If selector name is not our type, keeping going (we might still
12478 -- have an occurrence of the type in the prefix).
12480 if Nkind
(Selector_Name
(N
)) /= N_Identifier
12481 or else Chars
(Selector_Name
(N
)) /= TName
12485 -- Selector name is our type, check qualification
12488 -- Loop through scopes and prefixes, doing comparison
12490 Scop
:= Current_Scope
;
12491 Pref
:= Prefix
(N
);
12493 -- Continue if no more scopes or scope with no name
12495 if No
(Scop
) or else Nkind
(Scop
) not in N_Has_Chars
then
12499 -- Do replace if prefix is an identifier matching the scope
12500 -- that we are currently looking at.
12502 if Nkind
(Pref
) = N_Identifier
12503 and then Chars
(Pref
) = Chars
(Scop
)
12505 Replace_Type_Reference
(N
);
12509 -- Go check scope above us if prefix is itself of the form
12510 -- of a selected component, whose selector matches the scope
12511 -- we are currently looking at.
12513 if Nkind
(Pref
) = N_Selected_Component
12514 and then Nkind
(Selector_Name
(Pref
)) = N_Identifier
12515 and then Chars
(Selector_Name
(Pref
)) = Chars
(Scop
)
12517 Scop
:= Scope
(Scop
);
12518 Pref
:= Prefix
(Pref
);
12520 -- For anything else, we don't have a match, so keep on
12521 -- going, there are still some weird cases where we may
12522 -- still have a replacement within the prefix.
12530 -- Continue for any other node kind
12535 end Replace_Type_Ref
;
12537 procedure Replace_Type_Refs
is new Traverse_Proc
(Replace_Type_Ref
);
12539 -----------------------
12540 -- Visible_Component --
12541 -----------------------
12543 function Visible_Component
(Comp
: Name_Id
) return Entity_Id
is
12547 if Ekind
(T
) /= E_Record_Type
then
12551 E
:= First_Entity
(T
);
12552 while Present
(E
) loop
12553 if Comes_From_Source
(E
) and then Chars
(E
) = Comp
then
12562 end Visible_Component
;
12564 -- Start of processing for Replace_Type_References_Generic
12567 Replace_Type_Refs
(N
);
12568 end Replace_Type_References_Generic
;
12570 --------------------------------
12571 -- Resolve_Aspect_Expressions --
12572 --------------------------------
12574 procedure Resolve_Aspect_Expressions
(E
: Entity_Id
) is
12579 function Resolve_Name
(N
: Node_Id
) return Traverse_Result
;
12580 -- Verify that all identifiers in the expression, with the exception
12581 -- of references to the current entity, denote visible entities. This
12582 -- is done only to detect visibility errors, as the expression will be
12583 -- properly analyzed/expanded during analysis of the predicate function
12584 -- body. We omit quantified expressions from this test, given that they
12585 -- introduce a local identifier that would require proper expansion to
12586 -- handle properly.
12592 function Resolve_Name
(N
: Node_Id
) return Traverse_Result
is
12594 if Nkind
(N
) = N_Selected_Component
then
12595 if Nkind
(Prefix
(N
)) = N_Identifier
12596 and then Chars
(Prefix
(N
)) /= Chars
(E
)
12598 Find_Selected_Component
(N
);
12603 elsif Nkind
(N
) = N_Identifier
and then Chars
(N
) /= Chars
(E
) then
12604 Find_Direct_Name
(N
);
12605 Set_Entity
(N
, Empty
);
12607 elsif Nkind
(N
) = N_Quantified_Expression
then
12614 procedure Resolve_Aspect_Expression
is new Traverse_Proc
(Resolve_Name
);
12616 -- Start of processing for Resolve_Aspect_Expressions
12619 ASN
:= First_Rep_Item
(E
);
12620 while Present
(ASN
) loop
12621 if Nkind
(ASN
) = N_Aspect_Specification
and then Entity
(ASN
) = E
then
12622 A_Id
:= Get_Aspect_Id
(ASN
);
12623 Expr
:= Expression
(ASN
);
12627 -- For now we only deal with aspects that do not generate
12628 -- subprograms, or that may mention current instances of
12629 -- types. These will require special handling (???TBD).
12631 when Aspect_Predicate |
12632 Aspect_Predicate_Failure |
12633 Aspect_Invariant
=>
12636 when Aspect_Dynamic_Predicate |
12637 Aspect_Static_Predicate
=>
12639 -- Build predicate function specification and preanalyze
12640 -- expression after type replacement.
12642 if No
(Predicate_Function
(E
)) then
12644 FDecl
: constant Node_Id
:=
12645 Build_Predicate_Function_Declaration
(E
);
12646 pragma Unreferenced
(FDecl
);
12648 Resolve_Aspect_Expression
(Expr
);
12652 when Pre_Post_Aspects
=>
12655 when Aspect_Iterable
=>
12656 if Nkind
(Expr
) = N_Aggregate
then
12661 Assoc
:= First
(Component_Associations
(Expr
));
12662 while Present
(Assoc
) loop
12663 Find_Direct_Name
(Expression
(Assoc
));
12670 if Present
(Expr
) then
12671 case Aspect_Argument
(A_Id
) is
12672 when Expression | Optional_Expression
=>
12673 Analyze_And_Resolve
(Expression
(ASN
));
12675 when Name | Optional_Name
=>
12676 if Nkind
(Expr
) = N_Identifier
then
12677 Find_Direct_Name
(Expr
);
12679 elsif Nkind
(Expr
) = N_Selected_Component
then
12680 Find_Selected_Component
(Expr
);
12690 ASN
:= Next_Rep_Item
(ASN
);
12692 end Resolve_Aspect_Expressions
;
12694 -------------------------
12695 -- Same_Representation --
12696 -------------------------
12698 function Same_Representation
(Typ1
, Typ2
: Entity_Id
) return Boolean is
12699 T1
: constant Entity_Id
:= Underlying_Type
(Typ1
);
12700 T2
: constant Entity_Id
:= Underlying_Type
(Typ2
);
12703 -- A quick check, if base types are the same, then we definitely have
12704 -- the same representation, because the subtype specific representation
12705 -- attributes (Size and Alignment) do not affect representation from
12706 -- the point of view of this test.
12708 if Base_Type
(T1
) = Base_Type
(T2
) then
12711 elsif Is_Private_Type
(Base_Type
(T2
))
12712 and then Base_Type
(T1
) = Full_View
(Base_Type
(T2
))
12717 -- Tagged types never have differing representations
12719 if Is_Tagged_Type
(T1
) then
12723 -- Representations are definitely different if conventions differ
12725 if Convention
(T1
) /= Convention
(T2
) then
12729 -- Representations are different if component alignments or scalar
12730 -- storage orders differ.
12732 if (Is_Record_Type
(T1
) or else Is_Array_Type
(T1
))
12734 (Is_Record_Type
(T2
) or else Is_Array_Type
(T2
))
12736 (Component_Alignment
(T1
) /= Component_Alignment
(T2
)
12737 or else Reverse_Storage_Order
(T1
) /= Reverse_Storage_Order
(T2
))
12742 -- For arrays, the only real issue is component size. If we know the
12743 -- component size for both arrays, and it is the same, then that's
12744 -- good enough to know we don't have a change of representation.
12746 if Is_Array_Type
(T1
) then
12747 if Known_Component_Size
(T1
)
12748 and then Known_Component_Size
(T2
)
12749 and then Component_Size
(T1
) = Component_Size
(T2
)
12755 -- Types definitely have same representation if neither has non-standard
12756 -- representation since default representations are always consistent.
12757 -- If only one has non-standard representation, and the other does not,
12758 -- then we consider that they do not have the same representation. They
12759 -- might, but there is no way of telling early enough.
12761 if Has_Non_Standard_Rep
(T1
) then
12762 if not Has_Non_Standard_Rep
(T2
) then
12766 return not Has_Non_Standard_Rep
(T2
);
12769 -- Here the two types both have non-standard representation, and we need
12770 -- to determine if they have the same non-standard representation.
12772 -- For arrays, we simply need to test if the component sizes are the
12773 -- same. Pragma Pack is reflected in modified component sizes, so this
12774 -- check also deals with pragma Pack.
12776 if Is_Array_Type
(T1
) then
12777 return Component_Size
(T1
) = Component_Size
(T2
);
12779 -- Tagged types always have the same representation, because it is not
12780 -- possible to specify different representations for common fields.
12782 elsif Is_Tagged_Type
(T1
) then
12785 -- Case of record types
12787 elsif Is_Record_Type
(T1
) then
12789 -- Packed status must conform
12791 if Is_Packed
(T1
) /= Is_Packed
(T2
) then
12794 -- Otherwise we must check components. Typ2 maybe a constrained
12795 -- subtype with fewer components, so we compare the components
12796 -- of the base types.
12799 Record_Case
: declare
12800 CD1
, CD2
: Entity_Id
;
12802 function Same_Rep
return Boolean;
12803 -- CD1 and CD2 are either components or discriminants. This
12804 -- function tests whether they have the same representation.
12810 function Same_Rep
return Boolean is
12812 if No
(Component_Clause
(CD1
)) then
12813 return No
(Component_Clause
(CD2
));
12815 -- Note: at this point, component clauses have been
12816 -- normalized to the default bit order, so that the
12817 -- comparison of Component_Bit_Offsets is meaningful.
12820 Present
(Component_Clause
(CD2
))
12822 Component_Bit_Offset
(CD1
) = Component_Bit_Offset
(CD2
)
12824 Esize
(CD1
) = Esize
(CD2
);
12828 -- Start of processing for Record_Case
12831 if Has_Discriminants
(T1
) then
12833 -- The number of discriminants may be different if the
12834 -- derived type has fewer (constrained by values). The
12835 -- invisible discriminants retain the representation of
12836 -- the original, so the discrepancy does not per se
12837 -- indicate a different representation.
12839 CD1
:= First_Discriminant
(T1
);
12840 CD2
:= First_Discriminant
(T2
);
12841 while Present
(CD1
) and then Present
(CD2
) loop
12842 if not Same_Rep
then
12845 Next_Discriminant
(CD1
);
12846 Next_Discriminant
(CD2
);
12851 CD1
:= First_Component
(Underlying_Type
(Base_Type
(T1
)));
12852 CD2
:= First_Component
(Underlying_Type
(Base_Type
(T2
)));
12853 while Present
(CD1
) loop
12854 if not Same_Rep
then
12857 Next_Component
(CD1
);
12858 Next_Component
(CD2
);
12866 -- For enumeration types, we must check each literal to see if the
12867 -- representation is the same. Note that we do not permit enumeration
12868 -- representation clauses for Character and Wide_Character, so these
12869 -- cases were already dealt with.
12871 elsif Is_Enumeration_Type
(T1
) then
12872 Enumeration_Case
: declare
12873 L1
, L2
: Entity_Id
;
12876 L1
:= First_Literal
(T1
);
12877 L2
:= First_Literal
(T2
);
12878 while Present
(L1
) loop
12879 if Enumeration_Rep
(L1
) /= Enumeration_Rep
(L2
) then
12888 end Enumeration_Case
;
12890 -- Any other types have the same representation for these purposes
12895 end Same_Representation
;
12897 --------------------------------
12898 -- Resolve_Iterable_Operation --
12899 --------------------------------
12901 procedure Resolve_Iterable_Operation
12903 Cursor
: Entity_Id
;
12912 if not Is_Overloaded
(N
) then
12913 if not Is_Entity_Name
(N
)
12914 or else Ekind
(Entity
(N
)) /= E_Function
12915 or else Scope
(Entity
(N
)) /= Scope
(Typ
)
12916 or else No
(First_Formal
(Entity
(N
)))
12917 or else Etype
(First_Formal
(Entity
(N
))) /= Typ
12919 Error_Msg_N
("iterable primitive must be local function name "
12920 & "whose first formal is an iterable type", N
);
12925 F1
:= First_Formal
(Ent
);
12926 if Nam
= Name_First
then
12928 -- First (Container) => Cursor
12930 if Etype
(Ent
) /= Cursor
then
12931 Error_Msg_N
("primitive for First must yield a curosr", N
);
12934 elsif Nam
= Name_Next
then
12936 -- Next (Container, Cursor) => Cursor
12938 F2
:= Next_Formal
(F1
);
12940 if Etype
(F2
) /= Cursor
12941 or else Etype
(Ent
) /= Cursor
12942 or else Present
(Next_Formal
(F2
))
12944 Error_Msg_N
("no match for Next iterable primitive", N
);
12947 elsif Nam
= Name_Has_Element
then
12949 -- Has_Element (Container, Cursor) => Boolean
12951 F2
:= Next_Formal
(F1
);
12952 if Etype
(F2
) /= Cursor
12953 or else Etype
(Ent
) /= Standard_Boolean
12954 or else Present
(Next_Formal
(F2
))
12956 Error_Msg_N
("no match for Has_Element iterable primitive", N
);
12959 elsif Nam
= Name_Element
then
12960 F2
:= Next_Formal
(F1
);
12963 or else Etype
(F2
) /= Cursor
12964 or else Present
(Next_Formal
(F2
))
12966 Error_Msg_N
("no match for Element iterable primitive", N
);
12971 raise Program_Error
;
12975 -- Overloaded case: find subprogram with proper signature.
12976 -- Caller will report error if no match is found.
12983 Get_First_Interp
(N
, I
, It
);
12984 while Present
(It
.Typ
) loop
12985 if Ekind
(It
.Nam
) = E_Function
12986 and then Scope
(It
.Nam
) = Scope
(Typ
)
12987 and then Etype
(First_Formal
(It
.Nam
)) = Typ
12989 F1
:= First_Formal
(It
.Nam
);
12991 if Nam
= Name_First
then
12992 if Etype
(It
.Nam
) = Cursor
12993 and then No
(Next_Formal
(F1
))
12995 Set_Entity
(N
, It
.Nam
);
12999 elsif Nam
= Name_Next
then
13000 F2
:= Next_Formal
(F1
);
13003 and then No
(Next_Formal
(F2
))
13004 and then Etype
(F2
) = Cursor
13005 and then Etype
(It
.Nam
) = Cursor
13007 Set_Entity
(N
, It
.Nam
);
13011 elsif Nam
= Name_Has_Element
then
13012 F2
:= Next_Formal
(F1
);
13015 and then No
(Next_Formal
(F2
))
13016 and then Etype
(F2
) = Cursor
13017 and then Etype
(It
.Nam
) = Standard_Boolean
13019 Set_Entity
(N
, It
.Nam
);
13020 F2
:= Next_Formal
(F1
);
13024 elsif Nam
= Name_Element
then
13025 F2
:= Next_Formal
(F1
);
13028 and then No
(Next_Formal
(F2
))
13029 and then Etype
(F2
) = Cursor
13031 Set_Entity
(N
, It
.Nam
);
13037 Get_Next_Interp
(I
, It
);
13041 end Resolve_Iterable_Operation
;
13047 procedure Set_Biased
13051 Biased
: Boolean := True)
13055 Set_Has_Biased_Representation
(E
);
13057 if Warn_On_Biased_Representation
then
13059 ("?B?" & Msg
& " forces biased representation for&", N
, E
);
13064 --------------------
13065 -- Set_Enum_Esize --
13066 --------------------
13068 procedure Set_Enum_Esize
(T
: Entity_Id
) is
13074 Init_Alignment
(T
);
13076 -- Find the minimum standard size (8,16,32,64) that fits
13078 Lo
:= Enumeration_Rep
(Entity
(Type_Low_Bound
(T
)));
13079 Hi
:= Enumeration_Rep
(Entity
(Type_High_Bound
(T
)));
13082 if Lo
>= -Uint_2
**07 and then Hi
< Uint_2
**07 then
13083 Sz
:= Standard_Character_Size
; -- May be > 8 on some targets
13085 elsif Lo
>= -Uint_2
**15 and then Hi
< Uint_2
**15 then
13088 elsif Lo
>= -Uint_2
**31 and then Hi
< Uint_2
**31 then
13091 else pragma Assert
(Lo
>= -Uint_2
**63 and then Hi
< Uint_2
**63);
13096 if Hi
< Uint_2
**08 then
13097 Sz
:= Standard_Character_Size
; -- May be > 8 on some targets
13099 elsif Hi
< Uint_2
**16 then
13102 elsif Hi
< Uint_2
**32 then
13105 else pragma Assert
(Hi
< Uint_2
**63);
13110 -- That minimum is the proper size unless we have a foreign convention
13111 -- and the size required is 32 or less, in which case we bump the size
13112 -- up to 32. This is required for C and C++ and seems reasonable for
13113 -- all other foreign conventions.
13115 if Has_Foreign_Convention
(T
)
13116 and then Esize
(T
) < Standard_Integer_Size
13118 -- Don't do this if Short_Enums on target
13120 and then not Target_Short_Enums
13122 Init_Esize
(T
, Standard_Integer_Size
);
13124 Init_Esize
(T
, Sz
);
13126 end Set_Enum_Esize
;
13128 -----------------------------
13129 -- Uninstall_Discriminants --
13130 -----------------------------
13132 procedure Uninstall_Discriminants
(E
: Entity_Id
) is
13138 -- Discriminants have been made visible for type declarations and
13139 -- protected type declarations, not for subtype declarations.
13141 if Nkind
(Parent
(E
)) /= N_Subtype_Declaration
then
13142 Disc
:= First_Discriminant
(E
);
13143 while Present
(Disc
) loop
13144 if Disc
/= Current_Entity
(Disc
) then
13145 Prev
:= Current_Entity
(Disc
);
13146 while Present
(Prev
)
13147 and then Present
(Homonym
(Prev
))
13148 and then Homonym
(Prev
) /= Disc
13150 Prev
:= Homonym
(Prev
);
13156 Set_Is_Immediately_Visible
(Disc
, False);
13158 Outer
:= Homonym
(Disc
);
13159 while Present
(Outer
) and then Scope
(Outer
) = E
loop
13160 Outer
:= Homonym
(Outer
);
13163 -- Reset homonym link of other entities, but do not modify link
13164 -- between entities in current scope, so that the back end can
13165 -- have a proper count of local overloadings.
13168 Set_Name_Entity_Id
(Chars
(Disc
), Outer
);
13170 elsif Scope
(Prev
) /= Scope
(Disc
) then
13171 Set_Homonym
(Prev
, Outer
);
13174 Next_Discriminant
(Disc
);
13177 end Uninstall_Discriminants
;
13179 -------------------------------------------
13180 -- Uninstall_Discriminants_And_Pop_Scope --
13181 -------------------------------------------
13183 procedure Uninstall_Discriminants_And_Pop_Scope
(E
: Entity_Id
) is
13185 if Has_Discriminants
(E
) then
13186 Uninstall_Discriminants
(E
);
13189 end Uninstall_Discriminants_And_Pop_Scope
;
13191 ------------------------------
13192 -- Validate_Address_Clauses --
13193 ------------------------------
13195 procedure Validate_Address_Clauses
is
13196 function Offset_Value
(Expr
: Node_Id
) return Uint
;
13197 -- Given an Address attribute reference, return the value in bits of its
13198 -- offset from the first bit of the underlying entity, or 0 if it is not
13199 -- known at compile time.
13205 function Offset_Value
(Expr
: Node_Id
) return Uint
is
13206 N
: Node_Id
:= Prefix
(Expr
);
13208 Val
: Uint
:= Uint_0
;
13211 -- Climb the prefix chain and compute the cumulative offset
13214 if Is_Entity_Name
(N
) then
13217 elsif Nkind
(N
) = N_Selected_Component
then
13218 Off
:= Component_Bit_Offset
(Entity
(Selector_Name
(N
)));
13219 if Off
/= No_Uint
and then Off
>= Uint_0
then
13226 elsif Nkind
(N
) = N_Indexed_Component
then
13227 Off
:= Indexed_Component_Bit_Offset
(N
);
13228 if Off
/= No_Uint
then
13241 -- Start of processing for Validate_Address_Clauses
13244 for J
in Address_Clause_Checks
.First
.. Address_Clause_Checks
.Last
loop
13246 ACCR
: Address_Clause_Check_Record
13247 renames Address_Clause_Checks
.Table
(J
);
13251 X_Alignment
: Uint
;
13252 Y_Alignment
: Uint
;
13260 -- Skip processing of this entry if warning already posted
13262 if not Address_Warning_Posted
(ACCR
.N
) then
13263 Expr
:= Original_Node
(Expression
(ACCR
.N
));
13265 -- Get alignments, sizes and offset, if any
13267 X_Alignment
:= Alignment
(ACCR
.X
);
13268 X_Size
:= Esize
(ACCR
.X
);
13270 if Present
(ACCR
.Y
) then
13271 Y_Alignment
:= Alignment
(ACCR
.Y
);
13272 Y_Size
:= Esize
(ACCR
.Y
);
13276 and then Nkind
(Expr
) = N_Attribute_Reference
13277 and then Attribute_Name
(Expr
) = Name_Address
13279 X_Offs
:= Offset_Value
(Expr
);
13284 -- Check for known value not multiple of alignment
13286 if No
(ACCR
.Y
) then
13287 if not Alignment_Checks_Suppressed
(ACCR
.X
)
13288 and then X_Alignment
/= 0
13289 and then ACCR
.A
mod X_Alignment
/= 0
13292 ("??specified address for& is inconsistent with "
13293 & "alignment", ACCR
.N
, ACCR
.X
);
13295 ("\??program execution may be erroneous (RM 13.3(27))",
13298 Error_Msg_Uint_1
:= X_Alignment
;
13299 Error_Msg_NE
("\??alignment of & is ^", ACCR
.N
, ACCR
.X
);
13302 -- Check for large object overlaying smaller one
13304 elsif Y_Size
> Uint_0
13305 and then X_Size
> Uint_0
13306 and then X_Offs
+ X_Size
> Y_Size
13308 Error_Msg_NE
("??& overlays smaller object", ACCR
.N
, ACCR
.X
);
13310 ("\??program execution may be erroneous", ACCR
.N
);
13312 Error_Msg_Uint_1
:= X_Size
;
13313 Error_Msg_NE
("\??size of & is ^", ACCR
.N
, ACCR
.X
);
13315 Error_Msg_Uint_1
:= Y_Size
;
13316 Error_Msg_NE
("\??size of & is ^", ACCR
.N
, ACCR
.Y
);
13318 if Y_Size
>= X_Size
then
13319 Error_Msg_Uint_1
:= X_Offs
;
13320 Error_Msg_NE
("\??but offset of & is ^", ACCR
.N
, ACCR
.X
);
13323 -- Check for inadequate alignment, both of the base object
13324 -- and of the offset, if any. We only do this check if the
13325 -- run-time Alignment_Check is active. No point in warning
13326 -- if this check has been suppressed (or is suppressed by
13327 -- default in the non-strict alignment machine case).
13329 -- Note: we do not check the alignment if we gave a size
13330 -- warning, since it would likely be redundant.
13332 elsif not Alignment_Checks_Suppressed
(ACCR
.X
)
13333 and then Y_Alignment
/= Uint_0
13335 (Y_Alignment
< X_Alignment
13338 and then Nkind
(Expr
) = N_Attribute_Reference
13339 and then Attribute_Name
(Expr
) = Name_Address
13340 and then Has_Compatible_Alignment
13341 (ACCR
.X
, Prefix
(Expr
), True) /=
13345 ("??specified address for& may be inconsistent with "
13346 & "alignment", ACCR
.N
, ACCR
.X
);
13348 ("\??program execution may be erroneous (RM 13.3(27))",
13351 Error_Msg_Uint_1
:= X_Alignment
;
13352 Error_Msg_NE
("\??alignment of & is ^", ACCR
.N
, ACCR
.X
);
13354 Error_Msg_Uint_1
:= Y_Alignment
;
13355 Error_Msg_NE
("\??alignment of & is ^", ACCR
.N
, ACCR
.Y
);
13357 if Y_Alignment
>= X_Alignment
then
13359 ("\??but offset is not multiple of alignment", ACCR
.N
);
13365 end Validate_Address_Clauses
;
13367 -----------------------------------------
13368 -- Validate_Compile_Time_Warning_Error --
13369 -----------------------------------------
13371 procedure Validate_Compile_Time_Warning_Error
(N
: Node_Id
) is
13373 Compile_Time_Warnings_Errors
.Append
13374 (New_Val
=> CTWE_Entry
'(Eloc => Sloc (N),
13375 Scope => Current_Scope,
13377 end Validate_Compile_Time_Warning_Error;
13379 ------------------------------------------
13380 -- Validate_Compile_Time_Warning_Errors --
13381 ------------------------------------------
13383 procedure Validate_Compile_Time_Warning_Errors is
13384 procedure Set_Scope (S : Entity_Id);
13385 -- Install all enclosing scopes of S along with S itself
13387 procedure Unset_Scope (S : Entity_Id);
13388 -- Uninstall all enclosing scopes of S along with S itself
13394 procedure Set_Scope (S : Entity_Id) is
13396 if S /= Standard_Standard then
13397 Set_Scope (Scope (S));
13407 procedure Unset_Scope (S : Entity_Id) is
13409 if S /= Standard_Standard then
13410 Unset_Scope (Scope (S));
13416 -- Start of processing for Validate_Compile_Time_Warning_Errors
13419 Expander_Mode_Save_And_Set (False);
13420 In_Compile_Time_Warning_Or_Error := True;
13422 for N in Compile_Time_Warnings_Errors.First ..
13423 Compile_Time_Warnings_Errors.Last
13426 T : CTWE_Entry renames Compile_Time_Warnings_Errors.Table (N);
13429 Set_Scope (T.Scope);
13430 Reset_Analyzed_Flags (T.Prag);
13431 Process_Compile_Time_Warning_Or_Error (T.Prag, T.Eloc);
13432 Unset_Scope (T.Scope);
13436 In_Compile_Time_Warning_Or_Error := False;
13437 Expander_Mode_Restore;
13438 end Validate_Compile_Time_Warning_Errors;
13440 ---------------------------
13441 -- Validate_Independence --
13442 ---------------------------
13444 procedure Validate_Independence is
13445 SU : constant Uint := UI_From_Int (System_Storage_Unit);
13453 procedure Check_Array_Type (Atyp : Entity_Id);
13454 -- Checks if the array type Atyp has independent components, and
13455 -- if not, outputs an appropriate set of error messages.
13457 procedure No_Independence;
13458 -- Output message that independence cannot be guaranteed
13460 function OK_Component (C : Entity_Id) return Boolean;
13461 -- Checks one component to see if it is independently accessible, and
13462 -- if so yields True, otherwise yields False if independent access
13463 -- cannot be guaranteed. This is a conservative routine, it only
13464 -- returns True if it knows for sure, it returns False if it knows
13465 -- there is a problem, or it cannot be sure there is no problem.
13467 procedure Reason_Bad_Component (C : Entity_Id);
13468 -- Outputs continuation message if a reason can be determined for
13469 -- the component C being bad.
13471 ----------------------
13472 -- Check_Array_Type --
13473 ----------------------
13475 procedure Check_Array_Type (Atyp : Entity_Id) is
13476 Ctyp : constant Entity_Id := Component_Type (Atyp);
13479 -- OK if no alignment clause, no pack, and no component size
13481 if not Has_Component_Size_Clause (Atyp)
13482 and then not Has_Alignment_Clause (Atyp)
13483 and then not Is_Packed (Atyp)
13488 -- Case of component size is greater than or equal to 64 and the
13489 -- alignment of the array is at least as large as the alignment
13490 -- of the component. We are definitely OK in this situation.
13492 if Known_Component_Size (Atyp)
13493 and then Component_Size (Atyp) >= 64
13494 and then Known_Alignment (Atyp)
13495 and then Known_Alignment (Ctyp)
13496 and then Alignment (Atyp) >= Alignment (Ctyp)
13501 -- Check actual component size
13503 if not Known_Component_Size (Atyp)
13504 or else not (Addressable (Component_Size (Atyp))
13505 and then Component_Size (Atyp) < 64)
13506 or else Component_Size (Atyp) mod Esize (Ctyp) /= 0
13510 -- Bad component size, check reason
13512 if Has_Component_Size_Clause (Atyp) then
13513 P := Get_Attribute_Definition_Clause
13514 (Atyp, Attribute_Component_Size);
13516 if Present (P) then
13517 Error_Msg_Sloc := Sloc (P);
13518 Error_Msg_N ("\because of Component_Size clause#", N);
13523 if Is_Packed (Atyp) then
13524 P := Get_Rep_Pragma (Atyp, Name_Pack);
13526 if Present (P) then
13527 Error_Msg_Sloc := Sloc (P);
13528 Error_Msg_N ("\because of pragma Pack#", N);
13533 -- No reason found, just return
13538 -- Array type is OK independence-wise
13541 end Check_Array_Type;
13543 ---------------------
13544 -- No_Independence --
13545 ---------------------
13547 procedure No_Independence is
13549 if Pragma_Name (N) = Name_Independent then
13550 Error_Msg_NE ("independence cannot be guaranteed for&", N, E);
13553 ("independent components cannot be guaranteed for&", N, E);
13555 end No_Independence;
13561 function OK_Component (C : Entity_Id) return Boolean is
13562 Rec : constant Entity_Id := Scope (C);
13563 Ctyp : constant Entity_Id := Etype (C);
13566 -- OK if no component clause, no Pack, and no alignment clause
13568 if No (Component_Clause (C))
13569 and then not Is_Packed (Rec)
13570 and then not Has_Alignment_Clause (Rec)
13575 -- Here we look at the actual component layout. A component is
13576 -- addressable if its size is a multiple of the Esize of the
13577 -- component type, and its starting position in the record has
13578 -- appropriate alignment, and the record itself has appropriate
13579 -- alignment to guarantee the component alignment.
13581 -- Make sure sizes are static, always assume the worst for any
13582 -- cases where we cannot check static values.
13584 if not (Known_Static_Esize (C)
13586 Known_Static_Esize (Ctyp))
13591 -- Size of component must be addressable or greater than 64 bits
13592 -- and a multiple of bytes.
13594 if not Addressable (Esize (C)) and then Esize (C) < Uint_64 then
13598 -- Check size is proper multiple
13600 if Esize (C) mod Esize (Ctyp) /= 0 then
13604 -- Check alignment of component is OK
13606 if not Known_Component_Bit_Offset (C)
13607 or else Component_Bit_Offset (C) < Uint_0
13608 or else Component_Bit_Offset (C) mod Esize (Ctyp) /= 0
13613 -- Check alignment of record type is OK
13615 if not Known_Alignment (Rec)
13616 or else (Alignment (Rec) * SU) mod Esize (Ctyp) /= 0
13621 -- All tests passed, component is addressable
13626 --------------------------
13627 -- Reason_Bad_Component --
13628 --------------------------
13630 procedure Reason_Bad_Component (C : Entity_Id) is
13631 Rec : constant Entity_Id := Scope (C);
13632 Ctyp : constant Entity_Id := Etype (C);
13635 -- If component clause present assume that's the problem
13637 if Present (Component_Clause (C)) then
13638 Error_Msg_Sloc := Sloc (Component_Clause (C));
13639 Error_Msg_N ("\because of Component_Clause#", N);
13643 -- If pragma Pack clause present, assume that's the problem
13645 if Is_Packed (Rec) then
13646 P := Get_Rep_Pragma (Rec, Name_Pack);
13648 if Present (P) then
13649 Error_Msg_Sloc := Sloc (P);
13650 Error_Msg_N ("\because of pragma Pack#", N);
13655 -- See if record has bad alignment clause
13657 if Has_Alignment_Clause (Rec)
13658 and then Known_Alignment (Rec)
13659 and then (Alignment (Rec) * SU) mod Esize (Ctyp) /= 0
13661 P := Get_Attribute_Definition_Clause (Rec, Attribute_Alignment);
13663 if Present (P) then
13664 Error_Msg_Sloc := Sloc (P);
13665 Error_Msg_N ("\because of Alignment clause#", N);
13669 -- Couldn't find a reason, so return without a message
13672 end Reason_Bad_Component;
13674 -- Start of processing for Validate_Independence
13677 for J in Independence_Checks.First .. Independence_Checks.Last loop
13678 N := Independence_Checks.Table (J).N;
13679 E := Independence_Checks.Table (J).E;
13680 IC := Pragma_Name (N) = Name_Independent_Components;
13682 -- Deal with component case
13684 if Ekind (E) = E_Discriminant or else Ekind (E) = E_Component then
13685 if not OK_Component (E) then
13687 Reason_Bad_Component (E);
13692 -- Deal with record with Independent_Components
13694 if IC and then Is_Record_Type (E) then
13695 Comp := First_Component_Or_Discriminant (E);
13696 while Present (Comp) loop
13697 if not OK_Component (Comp) then
13699 Reason_Bad_Component (Comp);
13703 Next_Component_Or_Discriminant (Comp);
13707 -- Deal with address clause case
13709 if Is_Object (E) then
13710 Addr := Address_Clause (E);
13712 if Present (Addr) then
13714 Error_Msg_Sloc := Sloc (Addr);
13715 Error_Msg_N ("\because of Address clause#", N);
13720 -- Deal with independent components for array type
13722 if IC and then Is_Array_Type (E) then
13723 Check_Array_Type (E);
13726 -- Deal with independent components for array object
13728 if IC and then Is_Object (E) and then Is_Array_Type (Etype (E)) then
13729 Check_Array_Type (Etype (E));
13734 end Validate_Independence;
13736 ------------------------------
13737 -- Validate_Iterable_Aspect --
13738 ------------------------------
13740 procedure Validate_Iterable_Aspect (Typ : Entity_Id; ASN : Node_Id) is
13745 Cursor : constant Entity_Id := Get_Cursor_Type (ASN, Typ);
13747 First_Id : Entity_Id;
13748 Next_Id : Entity_Id;
13749 Has_Element_Id : Entity_Id;
13750 Element_Id : Entity_Id;
13753 -- If previous error aspect is unusable
13755 if Cursor = Any_Type then
13761 Has_Element_Id := Empty;
13762 Element_Id := Empty;
13764 -- Each expression must resolve to a function with the proper signature
13766 Assoc := First (Component_Associations (Expression (ASN)));
13767 while Present (Assoc) loop
13768 Expr := Expression (Assoc);
13771 Prim := First (Choices (Assoc));
13773 if Nkind (Prim) /= N_Identifier or else Present (Next (Prim)) then
13774 Error_Msg_N ("illegal name in association", Prim);
13776 elsif Chars (Prim) = Name_First then
13777 Resolve_Iterable_Operation (Expr, Cursor, Typ, Name_First);
13778 First_Id := Entity (Expr);
13780 elsif Chars (Prim) = Name_Next then
13781 Resolve_Iterable_Operation (Expr, Cursor, Typ, Name_Next);
13782 Next_Id := Entity (Expr);
13784 elsif Chars (Prim) = Name_Has_Element then
13785 Resolve_Iterable_Operation (Expr, Cursor, Typ, Name_Has_Element);
13786 Has_Element_Id := Entity (Expr);
13788 elsif Chars (Prim) = Name_Element then
13789 Resolve_Iterable_Operation (Expr, Cursor, Typ, Name_Element);
13790 Element_Id := Entity (Expr);
13793 Error_Msg_N ("invalid name for iterable function", Prim);
13799 if No (First_Id) then
13800 Error_Msg_N ("match for First primitive not found", ASN);
13802 elsif No (Next_Id) then
13803 Error_Msg_N ("match for Next primitive not found", ASN);
13805 elsif No (Has_Element_Id) then
13806 Error_Msg_N ("match for Has_Element primitive not found", ASN);
13808 elsif No (Element_Id) then
13811 end Validate_Iterable_Aspect;
13813 -----------------------------------
13814 -- Validate_Unchecked_Conversion --
13815 -----------------------------------
13817 procedure Validate_Unchecked_Conversion
13819 Act_Unit : Entity_Id)
13821 Source : Entity_Id;
13822 Target : Entity_Id;
13826 -- Obtain source and target types. Note that we call Ancestor_Subtype
13827 -- here because the processing for generic instantiation always makes
13828 -- subtypes, and we want the original frozen actual types.
13830 -- If we are dealing with private types, then do the check on their
13831 -- fully declared counterparts if the full declarations have been
13832 -- encountered (they don't have to be visible, but they must exist).
13834 Source := Ancestor_Subtype (Etype (First_Formal (Act_Unit)));
13836 if Is_Private_Type (Source)
13837 and then Present (Underlying_Type (Source))
13839 Source := Underlying_Type (Source);
13842 Target := Ancestor_Subtype (Etype (Act_Unit));
13844 -- If either type is generic, the instantiation happens within a generic
13845 -- unit, and there is nothing to check. The proper check will happen
13846 -- when the enclosing generic is instantiated.
13848 if Is_Generic_Type (Source) or else Is_Generic_Type (Target) then
13852 if Is_Private_Type (Target)
13853 and then Present (Underlying_Type (Target))
13855 Target := Underlying_Type (Target);
13858 -- Source may be unconstrained array, but not target, except in relaxed
13861 if Is_Array_Type (Target)
13862 and then not Is_Constrained (Target)
13863 and then not Relaxed_RM_Semantics
13866 ("unchecked conversion to unconstrained array not allowed", N);
13870 -- Warn if conversion between two different convention pointers
13872 if Is_Access_Type (Target)
13873 and then Is_Access_Type (Source)
13874 and then Convention (Target) /= Convention (Source)
13875 and then Warn_On_Unchecked_Conversion
13877 -- Give warnings for subprogram pointers only on most targets
13879 if Is_Access_Subprogram_Type (Target)
13880 or else Is_Access_Subprogram_Type (Source)
13883 ("?z?conversion between pointers with different conventions!",
13888 -- Warn if one of the operands is Ada.Calendar.Time. Do not emit a
13889 -- warning when compiling GNAT-related sources.
13891 if Warn_On_Unchecked_Conversion
13892 and then not In_Predefined_Unit (N)
13893 and then RTU_Loaded (Ada_Calendar)
13894 and then (Chars (Source) = Name_Time
13896 Chars (Target) = Name_Time)
13898 -- If Ada.Calendar is loaded and the name of one of the operands is
13899 -- Time, there is a good chance that this is Ada.Calendar.Time.
13902 Calendar_Time : constant Entity_Id := Full_View (RTE (RO_CA_Time));
13904 pragma Assert (Present (Calendar_Time));
13906 if Source = Calendar_Time or else Target = Calendar_Time then
13908 ("?z?representation of 'Time values may change between
"
13909 & "'G'N'A
'T versions
", N);
13914 -- Make entry in unchecked conversion table for later processing by
13915 -- Validate_Unchecked_Conversions, which will check sizes and alignments
13916 -- (using values set by the back end where possible). This is only done
13917 -- if the appropriate warning is active.
13919 if Warn_On_Unchecked_Conversion then
13920 Unchecked_Conversions.Append
13921 (New_Val => UC_Entry'(Eloc => Sloc (N),
13924 Act_Unit => Act_Unit));
13926 -- If both sizes are known statically now, then back-end annotation
13927 -- is not required to do a proper check but if either size is not
13928 -- known statically, then we need the annotation.
13930 if Known_Static_RM_Size (Source)
13932 Known_Static_RM_Size (Target)
13936 Back_Annotate_Rep_Info := True;
13940 -- If unchecked conversion to access type, and access type is declared
13941 -- in the same unit as the unchecked conversion, then set the flag
13942 -- No_Strict_Aliasing (no strict aliasing is implicit here)
13944 if Is_Access_Type (Target) and then
13945 In_Same_Source_Unit (Target, N)
13947 Set_No_Strict_Aliasing (Implementation_Base_Type (Target));
13950 -- Generate N_Validate_Unchecked_Conversion node for back end in case
13951 -- the back end needs to perform special validation checks.
13953 -- Shouldn't this be in Exp_Ch13, since the check only gets done if we
13954 -- have full expansion and the back end is called ???
13957 Make_Validate_Unchecked_Conversion (Sloc (N));
13958 Set_Source_Type (Vnode, Source);
13959 Set_Target_Type (Vnode, Target);
13961 -- If the unchecked conversion node is in a list, just insert before it.
13962 -- If not we have some strange case, not worth bothering about.
13964 if Is_List_Member (N) then
13965 Insert_After (N, Vnode);
13967 end Validate_Unchecked_Conversion;
13969 ------------------------------------
13970 -- Validate_Unchecked_Conversions --
13971 ------------------------------------
13973 procedure Validate_Unchecked_Conversions is
13975 for N in Unchecked_Conversions.First .. Unchecked_Conversions.Last loop
13977 T : UC_Entry renames Unchecked_Conversions.Table (N);
13979 Act_Unit : constant Entity_Id := T.Act_Unit;
13980 Eloc : constant Source_Ptr := T.Eloc;
13981 Source : constant Entity_Id := T.Source;
13982 Target : constant Entity_Id := T.Target;
13988 -- Skip if function marked as warnings off
13990 if Warnings_Off (Act_Unit) then
13994 -- This validation check, which warns if we have unequal sizes for
13995 -- unchecked conversion, and thus potentially implementation
13996 -- dependent semantics, is one of the few occasions on which we
13997 -- use the official RM size instead of Esize. See description in
13998 -- Einfo "Handling
of Type'Size Values
" for details.
14000 if Serious_Errors_Detected = 0
14001 and then Known_Static_RM_Size (Source)
14002 and then Known_Static_RM_Size (Target)
14004 -- Don't do the check if warnings off for either type, note the
14005 -- deliberate use of OR here instead of OR ELSE to get the flag
14006 -- Warnings_Off_Used set for both types if appropriate.
14008 and then not (Has_Warnings_Off (Source)
14010 Has_Warnings_Off (Target))
14012 Source_Siz := RM_Size (Source);
14013 Target_Siz := RM_Size (Target);
14015 if Source_Siz /= Target_Siz then
14017 ("?z?types
for unchecked conversion have different sizes
!",
14020 if All_Errors_Mode then
14021 Error_Msg_Name_1 := Chars (Source);
14022 Error_Msg_Uint_1 := Source_Siz;
14023 Error_Msg_Name_2 := Chars (Target);
14024 Error_Msg_Uint_2 := Target_Siz;
14025 Error_Msg ("\size
of % is ^
, size
of % is ^?z?
", Eloc);
14027 Error_Msg_Uint_1 := UI_Abs (Source_Siz - Target_Siz);
14029 if Is_Discrete_Type (Source)
14031 Is_Discrete_Type (Target)
14033 if Source_Siz > Target_Siz then
14035 ("\?z?^ high order bits
of source will
"
14036 & "be ignored
!", Eloc);
14038 elsif Is_Unsigned_Type (Source) then
14040 ("\?z?source will be extended
with ^ high order
"
14041 & "zero bits
!", Eloc);
14045 ("\?z?source will be extended
with ^ high order
"
14046 & "sign bits
!", Eloc);
14049 elsif Source_Siz < Target_Siz then
14050 if Is_Discrete_Type (Target) then
14051 if Bytes_Big_Endian then
14053 ("\?z?target value will include ^ undefined
"
14054 & "low order bits
!", Eloc);
14057 ("\?z?target value will include ^ undefined
"
14058 & "high order bits
!", Eloc);
14063 ("\?z?^ trailing bits
of target value will be
"
14064 & "undefined
!", Eloc);
14067 else pragma Assert (Source_Siz > Target_Siz);
14068 if Is_Discrete_Type (Source) then
14069 if Bytes_Big_Endian then
14071 ("\?z?^ low order bits
of source will be
"
14072 & "ignored
!", Eloc);
14075 ("\?z?^ high order bits
of source will be
"
14076 & "ignored
!", Eloc);
14081 ("\?z?^ trailing bits
of source will be
"
14082 & "ignored
!", Eloc);
14089 -- If both types are access types, we need to check the alignment.
14090 -- If the alignment of both is specified, we can do it here.
14092 if Serious_Errors_Detected = 0
14093 and then Is_Access_Type (Source)
14094 and then Is_Access_Type (Target)
14095 and then Target_Strict_Alignment
14096 and then Present (Designated_Type (Source))
14097 and then Present (Designated_Type (Target))
14100 D_Source : constant Entity_Id := Designated_Type (Source);
14101 D_Target : constant Entity_Id := Designated_Type (Target);
14104 if Known_Alignment (D_Source)
14106 Known_Alignment (D_Target)
14109 Source_Align : constant Uint := Alignment (D_Source);
14110 Target_Align : constant Uint := Alignment (D_Target);
14113 if Source_Align < Target_Align
14114 and then not Is_Tagged_Type (D_Source)
14116 -- Suppress warning if warnings suppressed on either
14117 -- type or either designated type. Note the use of
14118 -- OR here instead of OR ELSE. That is intentional,
14119 -- we would like to set flag Warnings_Off_Used in
14120 -- all types for which warnings are suppressed.
14122 and then not (Has_Warnings_Off (D_Source)
14124 Has_Warnings_Off (D_Target)
14126 Has_Warnings_Off (Source)
14128 Has_Warnings_Off (Target))
14130 Error_Msg_Uint_1 := Target_Align;
14131 Error_Msg_Uint_2 := Source_Align;
14132 Error_Msg_Node_1 := D_Target;
14133 Error_Msg_Node_2 := D_Source;
14135 ("?z?alignment
of & (^
) is stricter than
"
14136 & "alignment
of & (^
)!", Eloc);
14138 ("\?z?resulting
access value may have invalid
"
14139 & "alignment
!", Eloc);
14150 end Validate_Unchecked_Conversions;