1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2018, 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 Par_SCO
; use Par_SCO
;
46 with Restrict
; use Restrict
;
47 with Rident
; use Rident
;
48 with Rtsfind
; use Rtsfind
;
50 with Sem_Aux
; use Sem_Aux
;
51 with Sem_Case
; use Sem_Case
;
52 with Sem_Ch3
; use Sem_Ch3
;
53 with Sem_Ch6
; use Sem_Ch6
;
54 with Sem_Ch7
; use Sem_Ch7
;
55 with Sem_Ch8
; use Sem_Ch8
;
56 with Sem_Dim
; use Sem_Dim
;
57 with Sem_Disp
; use Sem_Disp
;
58 with Sem_Eval
; use Sem_Eval
;
59 with Sem_Prag
; use Sem_Prag
;
60 with Sem_Res
; use Sem_Res
;
61 with Sem_Type
; use Sem_Type
;
62 with Sem_Util
; use Sem_Util
;
63 with Sem_Warn
; use Sem_Warn
;
64 with Sinfo
; use Sinfo
;
65 with Sinput
; use Sinput
;
66 with Snames
; use Snames
;
67 with Stand
; use Stand
;
68 with Targparm
; use Targparm
;
69 with Ttypes
; use Ttypes
;
70 with Tbuild
; use Tbuild
;
71 with Urealp
; use Urealp
;
72 with Warnsw
; use Warnsw
;
74 with GNAT
.Heap_Sort_G
;
76 package body Sem_Ch13
is
78 SSU
: constant Pos
:= System_Storage_Unit
;
79 -- Convenient short hand for commonly used constant
81 -----------------------
82 -- Local Subprograms --
83 -----------------------
85 procedure Adjust_Record_For_Reverse_Bit_Order_Ada_95
(R
: Entity_Id
);
86 -- Helper routine providing the original (pre-AI95-0133) behavior for
87 -- Adjust_Record_For_Reverse_Bit_Order.
89 procedure Alignment_Check_For_Size_Change
(Typ
: Entity_Id
; Size
: Uint
);
90 -- This routine is called after setting one of the sizes of type entity
91 -- Typ to Size. The purpose is to deal with the situation of a derived
92 -- type whose inherited alignment is no longer appropriate for the new
93 -- size value. In this case, we reset the Alignment to unknown.
95 procedure Build_Discrete_Static_Predicate
99 -- Given a predicated type Typ, where Typ is a discrete static subtype,
100 -- whose predicate expression is Expr, tests if Expr is a static predicate,
101 -- and if so, builds the predicate range list. Nam is the name of the one
102 -- argument to the predicate function. Occurrences of the type name in the
103 -- predicate expression have been replaced by identifier references to this
104 -- name, which is unique, so any identifier with Chars matching Nam must be
105 -- a reference to the type. If the predicate is non-static, this procedure
106 -- returns doing nothing. If the predicate is static, then the predicate
107 -- list is stored in Static_Discrete_Predicate (Typ), and the Expr is
108 -- rewritten as a canonicalized membership operation.
110 function Build_Export_Import_Pragma
112 Id
: Entity_Id
) return Node_Id
;
113 -- Create the corresponding pragma for aspect Export or Import denoted by
114 -- Asp. Id is the related entity subject to the aspect. Return Empty when
115 -- the expression of aspect Asp evaluates to False or is erroneous.
117 function Build_Predicate_Function_Declaration
118 (Typ
: Entity_Id
) return Node_Id
;
119 -- Build the declaration for a predicate function. The declaration is built
120 -- at the end of the declarative part containing the type definition, which
121 -- may be before the freeze point of the type. The predicate expression is
122 -- preanalyzed at this point, to catch visibility errors.
124 procedure Build_Predicate_Functions
(Typ
: Entity_Id
; N
: Node_Id
);
125 -- If Typ has predicates (indicated by Has_Predicates being set for Typ),
126 -- then either there are pragma Predicate entries on the rep chain for the
127 -- type (note that Predicate aspects are converted to pragma Predicate), or
128 -- there are inherited aspects from a parent type, or ancestor subtypes.
129 -- This procedure builds body for the Predicate function that tests these
130 -- predicates. N is the freeze node for the type. The spec of the function
131 -- is inserted before the freeze node, and the body of the function is
132 -- inserted after the freeze node. If the predicate expression has a least
133 -- one Raise_Expression, then this procedure also builds the M version of
134 -- the predicate function for use in membership tests.
136 procedure Check_Pool_Size_Clash
(Ent
: Entity_Id
; SP
, SS
: Node_Id
);
137 -- Called if both Storage_Pool and Storage_Size attribute definition
138 -- clauses (SP and SS) are present for entity Ent. Issue error message.
140 procedure Freeze_Entity_Checks
(N
: Node_Id
);
141 -- Called from Analyze_Freeze_Entity and Analyze_Generic_Freeze Entity
142 -- to generate appropriate semantic checks that are delayed until this
143 -- point (they had to be delayed this long for cases of delayed aspects,
144 -- e.g. analysis of statically predicated subtypes in choices, for which
145 -- we have to be sure the subtypes in question are frozen before checking).
147 function Get_Alignment_Value
(Expr
: Node_Id
) return Uint
;
148 -- Given the expression for an alignment value, returns the corresponding
149 -- Uint value. If the value is inappropriate, then error messages are
150 -- posted as required, and a value of No_Uint is returned.
152 function Is_Operational_Item
(N
: Node_Id
) return Boolean;
153 -- A specification for a stream attribute is allowed before the full type
154 -- is declared, as explained in AI-00137 and the corrigendum. Attributes
155 -- that do not specify a representation characteristic are operational
158 function Is_Predicate_Static
160 Nam
: Name_Id
) return Boolean;
161 -- Given predicate expression Expr, tests if Expr is predicate-static in
162 -- the sense of the rules in (RM 3.2.4 (15-24)). Occurrences of the type
163 -- name in the predicate expression have been replaced by references to
164 -- an identifier whose Chars field is Nam. This name is unique, so any
165 -- identifier with Chars matching Nam must be a reference to the type.
166 -- Returns True if the expression is predicate-static and False otherwise,
167 -- but is not in the business of setting flags or issuing error messages.
169 -- Only scalar types can have static predicates, so False is always
170 -- returned for non-scalar types.
172 -- Note: the RM seems to suggest that string types can also have static
173 -- predicates. But that really makes lttle sense as very few useful
174 -- predicates can be constructed for strings. Remember that:
178 -- is not a static expression. So even though the clearly faulty RM wording
179 -- allows the following:
181 -- subtype S is String with Static_Predicate => S < "DEF"
183 -- We can't allow this, otherwise we have predicate-static applying to a
184 -- larger class than static expressions, which was never intended.
186 procedure New_Stream_Subprogram
190 Nam
: TSS_Name_Type
);
191 -- Create a subprogram renaming of a given stream attribute to the
192 -- designated subprogram and then in the tagged case, provide this as a
193 -- primitive operation, or in the untagged case make an appropriate TSS
194 -- entry. This is more properly an expansion activity than just semantics,
195 -- but the presence of user-defined stream functions for limited types
196 -- is a legality check, which is why this takes place here rather than in
197 -- exp_ch13, where it was previously. Nam indicates the name of the TSS
198 -- function to be generated.
200 -- To avoid elaboration anomalies with freeze nodes, for untagged types
201 -- we generate both a subprogram declaration and a subprogram renaming
202 -- declaration, so that the attribute specification is handled as a
203 -- renaming_as_body. For tagged types, the specification is one of the
206 procedure Register_Address_Clause_Check
212 -- Register a check for the address clause N. The rest of the parameters
213 -- are in keeping with the components of Address_Clause_Check_Record below.
215 procedure Resolve_Iterable_Operation
220 -- If the name of a primitive operation for an Iterable aspect is
221 -- overloaded, resolve according to required signature.
227 Biased
: Boolean := True);
228 -- If Biased is True, sets Has_Biased_Representation flag for E, and
229 -- outputs a warning message at node N if Warn_On_Biased_Representation is
230 -- is True. This warning inserts the string Msg to describe the construct
233 ---------------------------------------------------
234 -- Table for Validate_Compile_Time_Warning_Error --
235 ---------------------------------------------------
237 -- The following table collects pragmas Compile_Time_Error and Compile_
238 -- Time_Warning for validation. Entries are made by calls to subprogram
239 -- Validate_Compile_Time_Warning_Error, and the call to the procedure
240 -- Validate_Compile_Time_Warning_Errors does the actual error checking
241 -- and posting of warning and error messages. The reason for this delayed
242 -- processing is to take advantage of back-annotations of attributes size
243 -- and alignment values performed by the back end.
245 -- Note: the reason we store a Source_Ptr value instead of a Node_Id is
246 -- that by the time Validate_Unchecked_Conversions is called, Sprint will
247 -- already have modified all Sloc values if the -gnatD option is set.
249 type CTWE_Entry
is record
251 -- Source location used in warnings and error messages
254 -- Pragma Compile_Time_Error or Compile_Time_Warning
257 -- The scope which encloses the pragma
260 package Compile_Time_Warnings_Errors
is new Table
.Table
(
261 Table_Component_Type
=> CTWE_Entry
,
262 Table_Index_Type
=> Int
,
263 Table_Low_Bound
=> 1,
265 Table_Increment
=> 200,
266 Table_Name
=> "Compile_Time_Warnings_Errors");
268 ----------------------------------------------
269 -- Table for Validate_Unchecked_Conversions --
270 ----------------------------------------------
272 -- The following table collects unchecked conversions for validation.
273 -- Entries are made by Validate_Unchecked_Conversion and then the call
274 -- to Validate_Unchecked_Conversions does the actual error checking and
275 -- posting of warnings. The reason for this delayed processing is to take
276 -- advantage of back-annotations of size and alignment values performed by
279 -- Note: the reason we store a Source_Ptr value instead of a Node_Id is
280 -- that by the time Validate_Unchecked_Conversions is called, Sprint will
281 -- already have modified all Sloc values if the -gnatD option is set.
283 type UC_Entry
is record
284 Eloc
: Source_Ptr
; -- node used for posting warnings
285 Source
: Entity_Id
; -- source type for unchecked conversion
286 Target
: Entity_Id
; -- target type for unchecked conversion
287 Act_Unit
: Entity_Id
; -- actual function instantiated
290 package Unchecked_Conversions
is new Table
.Table
(
291 Table_Component_Type
=> UC_Entry
,
292 Table_Index_Type
=> Int
,
293 Table_Low_Bound
=> 1,
295 Table_Increment
=> 200,
296 Table_Name
=> "Unchecked_Conversions");
298 ----------------------------------------
299 -- Table for Validate_Address_Clauses --
300 ----------------------------------------
302 -- If an address clause has the form
304 -- for X'Address use Expr
306 -- where Expr has a value known at compile time or is of the form Y'Address
307 -- or recursively is a reference to a constant initialized with either of
308 -- these forms, and the value of Expr is not a multiple of X's alignment,
309 -- or if Y has a smaller alignment than X, then that merits a warning about
310 -- possible bad alignment. The following table collects address clauses of
311 -- this kind. We put these in a table so that they can be checked after the
312 -- back end has completed annotation of the alignments of objects, since we
313 -- can catch more cases that way.
315 type Address_Clause_Check_Record
is record
317 -- The address clause
320 -- The entity of the object subject to the address clause
323 -- The value of the address in the first case
326 -- The entity of the object being overlaid in the second case
329 -- Whether the address is offset within Y in the second case
331 Alignment_Checks_Suppressed
: Boolean;
332 -- Whether alignment checks are suppressed by an active scope suppress
333 -- setting. We need to save the value in order to be able to reuse it
334 -- after the back end has been run.
337 package Address_Clause_Checks
is new Table
.Table
(
338 Table_Component_Type
=> Address_Clause_Check_Record
,
339 Table_Index_Type
=> Int
,
340 Table_Low_Bound
=> 1,
342 Table_Increment
=> 200,
343 Table_Name
=> "Address_Clause_Checks");
345 function Alignment_Checks_Suppressed
346 (ACCR
: Address_Clause_Check_Record
) return Boolean;
347 -- Return whether the alignment check generated for the address clause
350 ---------------------------------
351 -- Alignment_Checks_Suppressed --
352 ---------------------------------
354 function Alignment_Checks_Suppressed
355 (ACCR
: Address_Clause_Check_Record
) return Boolean
358 if Checks_May_Be_Suppressed
(ACCR
.X
) then
359 return Is_Check_Suppressed
(ACCR
.X
, Alignment_Check
);
361 return ACCR
.Alignment_Checks_Suppressed
;
363 end Alignment_Checks_Suppressed
;
365 -----------------------------------------
366 -- Adjust_Record_For_Reverse_Bit_Order --
367 -----------------------------------------
369 procedure Adjust_Record_For_Reverse_Bit_Order
(R
: Entity_Id
) is
370 Max_Machine_Scalar_Size
: constant Uint
:=
372 (Standard_Long_Long_Integer_Size
);
373 -- We use this as the maximum machine scalar size
375 SSU
: constant Uint
:= UI_From_Int
(System_Storage_Unit
);
382 -- Processing here used to depend on Ada version: the behavior was
383 -- changed by AI95-0133. However this AI is a Binding interpretation,
384 -- so we now implement it even in Ada 95 mode. The original behavior
385 -- from unamended Ada 95 is still available for compatibility under
386 -- debugging switch -gnatd.
388 if Ada_Version
< Ada_2005
and then Debug_Flag_Dot_P
then
389 Adjust_Record_For_Reverse_Bit_Order_Ada_95
(R
);
393 -- For Ada 2005, we do machine scalar processing, as fully described In
394 -- AI-133. This involves gathering all components which start at the
395 -- same byte offset and processing them together. Same approach is still
396 -- valid in later versions including Ada 2012.
398 -- This first loop through components does two things. First it deals
399 -- with the case of components with component clauses whose length is
400 -- greater than the maximum machine scalar size (either accepting them
401 -- or rejecting as needed). Second, it counts the number of components
402 -- with component clauses whose length does not exceed this maximum for
406 Comp
:= First_Component_Or_Discriminant
(R
);
407 while Present
(Comp
) loop
408 CC
:= Component_Clause
(Comp
);
412 Fbit
: constant Uint
:= Static_Integer
(First_Bit
(CC
));
413 Lbit
: constant Uint
:= Static_Integer
(Last_Bit
(CC
));
416 -- Case of component with last bit >= max machine scalar
418 if Lbit
>= Max_Machine_Scalar_Size
then
420 -- This is allowed only if first bit is zero, and last bit
421 -- + 1 is a multiple of storage unit size.
423 if Fbit
= 0 and then (Lbit
+ 1) mod SSU
= 0 then
425 -- This is the case to give a warning if enabled
427 if Warn_On_Reverse_Bit_Order
then
429 ("info: multi-byte field specified with "
430 & "non-standard Bit_Order?V?", CC
);
432 if Bytes_Big_Endian
then
434 ("\bytes are not reversed "
435 & "(component is big-endian)?V?", CC
);
438 ("\bytes are not reversed "
439 & "(component is little-endian)?V?", CC
);
443 -- Give error message for RM 13.5.1(10) violation
447 ("machine scalar rules not followed for&",
448 First_Bit
(CC
), Comp
);
450 Error_Msg_Uint_1
:= Lbit
+ 1;
451 Error_Msg_Uint_2
:= Max_Machine_Scalar_Size
;
453 ("\last bit + 1 (^) exceeds maximum machine scalar "
454 & "size (^)", First_Bit
(CC
));
456 if (Lbit
+ 1) mod SSU
/= 0 then
457 Error_Msg_Uint_1
:= SSU
;
459 ("\and is not a multiple of Storage_Unit (^) "
460 & "(RM 13.5.1(10))", First_Bit
(CC
));
463 Error_Msg_Uint_1
:= Fbit
;
465 ("\and first bit (^) is non-zero "
466 & "(RM 13.4.1(10))", First_Bit
(CC
));
470 -- OK case of machine scalar related component clause. For now,
474 Num_CC
:= Num_CC
+ 1;
479 Next_Component_Or_Discriminant
(Comp
);
482 -- We need to sort the component clauses on the basis of the Position
483 -- values in the clause, so we can group clauses with the same Position
484 -- together to determine the relevant machine scalar size.
487 Comps
: array (0 .. Num_CC
) of Entity_Id
;
488 -- Array to collect component and discriminant entities. The data
489 -- starts at index 1, the 0'th entry is for the sort routine.
491 function CP_Lt
(Op1
, Op2
: Natural) return Boolean;
492 -- Compare routine for Sort
494 procedure CP_Move
(From
: Natural; To
: Natural);
495 -- Move routine for Sort
497 package Sorting
is new GNAT
.Heap_Sort_G
(CP_Move
, CP_Lt
);
500 -- Maximum last bit value of any component in this set
503 -- Corresponding machine scalar size
507 -- Start and stop positions in the component list of the set of
508 -- components with the same starting position (that constitute
509 -- components in a single machine scalar).
515 function CP_Lt
(Op1
, Op2
: Natural) return Boolean is
518 Position
(Component_Clause
(Comps
(Op1
))) <
519 Position
(Component_Clause
(Comps
(Op2
)));
526 procedure CP_Move
(From
: Natural; To
: Natural) is
528 Comps
(To
) := Comps
(From
);
531 -- Start of processing for Sort_CC
534 -- Collect the machine scalar relevant component clauses
537 Comp
:= First_Component_Or_Discriminant
(R
);
538 while Present
(Comp
) loop
540 CC
: constant Node_Id
:= Component_Clause
(Comp
);
543 -- Collect only component clauses whose last bit is less than
544 -- machine scalar size. Any component clause whose last bit
545 -- exceeds this value does not take part in machine scalar
546 -- layout considerations. The test for Error_Posted makes sure
547 -- we exclude component clauses for which we already posted an
551 and then not Error_Posted
(Last_Bit
(CC
))
552 and then Static_Integer
(Last_Bit
(CC
)) <
553 Max_Machine_Scalar_Size
555 Num_CC
:= Num_CC
+ 1;
556 Comps
(Num_CC
) := Comp
;
560 Next_Component_Or_Discriminant
(Comp
);
563 -- Sort by ascending position number
565 Sorting
.Sort
(Num_CC
);
567 -- We now have all the components whose size does not exceed the max
568 -- machine scalar value, sorted by starting position. In this loop we
569 -- gather groups of clauses starting at the same position, to process
570 -- them in accordance with AI-133.
573 while Stop
< Num_CC
loop
578 (Last_Bit
(Component_Clause
(Comps
(Start
))));
579 while Stop
< Num_CC
loop
581 (Position
(Component_Clause
(Comps
(Stop
+ 1)))) =
583 (Position
(Component_Clause
(Comps
(Stop
))))
591 (Component_Clause
(Comps
(Stop
)))));
597 -- Now we have a group of component clauses from Start to Stop
598 -- whose positions are identical, and MaxL is the maximum last
599 -- bit value of any of these components.
601 -- We need to determine the corresponding machine scalar size.
602 -- This loop assumes that machine scalar sizes are even, and that
603 -- each possible machine scalar has twice as many bits as the next
606 MSS
:= Max_Machine_Scalar_Size
;
608 and then (MSS
/ 2) >= SSU
609 and then (MSS
/ 2) > MaxL
614 -- Here is where we fix up the Component_Bit_Offset value to
615 -- account for the reverse bit order. Some examples of what needs
616 -- to be done for the case of a machine scalar size of 8 are:
618 -- First_Bit .. Last_Bit Component_Bit_Offset
630 -- The rule is that the first bit is obtained by subtracting the
631 -- old ending bit from machine scalar size - 1.
633 for C
in Start
.. Stop
loop
635 Comp
: constant Entity_Id
:= Comps
(C
);
636 CC
: constant Node_Id
:= Component_Clause
(Comp
);
638 LB
: constant Uint
:= Static_Integer
(Last_Bit
(CC
));
639 NFB
: constant Uint
:= MSS
- Uint_1
- LB
;
640 NLB
: constant Uint
:= NFB
+ Esize
(Comp
) - 1;
641 Pos
: constant Uint
:= Static_Integer
(Position
(CC
));
644 if Warn_On_Reverse_Bit_Order
then
645 Error_Msg_Uint_1
:= MSS
;
647 ("info: reverse bit order in machine scalar of "
648 & "length^?V?", First_Bit
(CC
));
649 Error_Msg_Uint_1
:= NFB
;
650 Error_Msg_Uint_2
:= NLB
;
652 if Bytes_Big_Endian
then
654 ("\big-endian range for component & is ^ .. ^?V?",
655 First_Bit
(CC
), Comp
);
658 ("\little-endian range for component & is ^ .. ^?V?",
659 First_Bit
(CC
), Comp
);
663 Set_Component_Bit_Offset
(Comp
, Pos
* SSU
+ NFB
);
664 Set_Normalized_Position
(Comp
, Pos
+ NFB
/ SSU
);
665 Set_Normalized_First_Bit
(Comp
, NFB
mod SSU
);
670 end Adjust_Record_For_Reverse_Bit_Order
;
672 ------------------------------------------------
673 -- Adjust_Record_For_Reverse_Bit_Order_Ada_95 --
674 ------------------------------------------------
676 procedure Adjust_Record_For_Reverse_Bit_Order_Ada_95
(R
: Entity_Id
) is
681 -- For Ada 95, we just renumber bits within a storage unit. We do the
682 -- same for Ada 83 mode, since we recognize the Bit_Order attribute in
683 -- Ada 83, and are free to add this extension.
685 Comp
:= First_Component_Or_Discriminant
(R
);
686 while Present
(Comp
) loop
687 CC
:= Component_Clause
(Comp
);
689 -- If component clause is present, then deal with the non-default
690 -- bit order case for Ada 95 mode.
692 -- We only do this processing for the base type, and in fact that
693 -- is important, since otherwise if there are record subtypes, we
694 -- could reverse the bits once for each subtype, which is wrong.
696 if Present
(CC
) and then Ekind
(R
) = E_Record_Type
then
698 CFB
: constant Uint
:= Component_Bit_Offset
(Comp
);
699 CSZ
: constant Uint
:= Esize
(Comp
);
700 CLC
: constant Node_Id
:= Component_Clause
(Comp
);
701 Pos
: constant Node_Id
:= Position
(CLC
);
702 FB
: constant Node_Id
:= First_Bit
(CLC
);
704 Storage_Unit_Offset
: constant Uint
:=
705 CFB
/ System_Storage_Unit
;
707 Start_Bit
: constant Uint
:=
708 CFB
mod System_Storage_Unit
;
711 -- Cases where field goes over storage unit boundary
713 if Start_Bit
+ CSZ
> System_Storage_Unit
then
715 -- Allow multi-byte field but generate warning
717 if Start_Bit
mod System_Storage_Unit
= 0
718 and then CSZ
mod System_Storage_Unit
= 0
721 ("info: multi-byte field specified with non-standard "
722 & "Bit_Order?V?", CLC
);
724 if Bytes_Big_Endian
then
726 ("\bytes are not reversed "
727 & "(component is big-endian)?V?", CLC
);
730 ("\bytes are not reversed "
731 & "(component is little-endian)?V?", CLC
);
734 -- Do not allow non-contiguous field
738 ("attempt to specify non-contiguous field not "
741 ("\caused by non-standard Bit_Order specified in "
742 & "legacy Ada 95 mode", CLC
);
745 -- Case where field fits in one storage unit
748 -- Give warning if suspicious component clause
750 if Intval
(FB
) >= System_Storage_Unit
751 and then Warn_On_Reverse_Bit_Order
754 ("info: Bit_Order clause does not affect byte "
755 & "ordering?V?", Pos
);
757 Intval
(Pos
) + Intval
(FB
) /
760 ("info: position normalized to ^ before bit order "
761 & "interpreted?V?", Pos
);
764 -- Here is where we fix up the Component_Bit_Offset value
765 -- to account for the reverse bit order. Some examples of
766 -- what needs to be done are:
768 -- First_Bit .. Last_Bit Component_Bit_Offset
780 -- The rule is that the first bit is is obtained by
781 -- subtracting the old ending bit from storage_unit - 1.
783 Set_Component_Bit_Offset
(Comp
,
784 (Storage_Unit_Offset
* System_Storage_Unit
) +
785 (System_Storage_Unit
- 1) -
786 (Start_Bit
+ CSZ
- 1));
788 Set_Normalized_Position
(Comp
,
789 Component_Bit_Offset
(Comp
) / System_Storage_Unit
);
791 Set_Normalized_First_Bit
(Comp
,
792 Component_Bit_Offset
(Comp
) mod System_Storage_Unit
);
797 Next_Component_Or_Discriminant
(Comp
);
799 end Adjust_Record_For_Reverse_Bit_Order_Ada_95
;
801 -------------------------------------
802 -- Alignment_Check_For_Size_Change --
803 -------------------------------------
805 procedure Alignment_Check_For_Size_Change
(Typ
: Entity_Id
; Size
: Uint
) is
807 -- If the alignment is known, and not set by a rep clause, and is
808 -- inconsistent with the size being set, then reset it to unknown,
809 -- we assume in this case that the size overrides the inherited
810 -- alignment, and that the alignment must be recomputed.
812 if Known_Alignment
(Typ
)
813 and then not Has_Alignment_Clause
(Typ
)
814 and then Size
mod (Alignment
(Typ
) * SSU
) /= 0
816 Init_Alignment
(Typ
);
818 end Alignment_Check_For_Size_Change
;
820 -------------------------------------
821 -- Analyze_Aspects_At_Freeze_Point --
822 -------------------------------------
824 procedure Analyze_Aspects_At_Freeze_Point
(E
: Entity_Id
) is
825 procedure Analyze_Aspect_Default_Value
(ASN
: Node_Id
);
826 -- This routine analyzes an Aspect_Default_[Component_]Value denoted by
827 -- the aspect specification node ASN.
829 procedure Inherit_Delayed_Rep_Aspects
(ASN
: Node_Id
);
830 -- As discussed in the spec of Aspects (see Aspect_Delay declaration),
831 -- a derived type can inherit aspects from its parent which have been
832 -- specified at the time of the derivation using an aspect, as in:
834 -- type A is range 1 .. 10
835 -- with Size => Not_Defined_Yet;
839 -- Not_Defined_Yet : constant := 64;
841 -- In this example, the Size of A is considered to be specified prior
842 -- to the derivation, and thus inherited, even though the value is not
843 -- known at the time of derivation. To deal with this, we use two entity
844 -- flags. The flag Has_Derived_Rep_Aspects is set in the parent type (A
845 -- here), and then the flag May_Inherit_Delayed_Rep_Aspects is set in
846 -- the derived type (B here). If this flag is set when the derived type
847 -- is frozen, then this procedure is called to ensure proper inheritance
848 -- of all delayed aspects from the parent type. The derived type is E,
849 -- the argument to Analyze_Aspects_At_Freeze_Point. ASN is the first
850 -- aspect specification node in the Rep_Item chain for the parent type.
852 procedure Make_Pragma_From_Boolean_Aspect
(ASN
: Node_Id
);
853 -- Given an aspect specification node ASN whose expression is an
854 -- optional Boolean, this routines creates the corresponding pragma
855 -- at the freezing point.
857 ----------------------------------
858 -- Analyze_Aspect_Default_Value --
859 ----------------------------------
861 procedure Analyze_Aspect_Default_Value
(ASN
: Node_Id
) is
862 A_Id
: constant Aspect_Id
:= Get_Aspect_Id
(ASN
);
863 Ent
: constant Entity_Id
:= Entity
(ASN
);
864 Expr
: constant Node_Id
:= Expression
(ASN
);
865 Id
: constant Node_Id
:= Identifier
(ASN
);
868 Error_Msg_Name_1
:= Chars
(Id
);
870 if not Is_Type
(Ent
) then
871 Error_Msg_N
("aspect% can only apply to a type", Id
);
874 elsif not Is_First_Subtype
(Ent
) then
875 Error_Msg_N
("aspect% cannot apply to subtype", Id
);
878 elsif A_Id
= Aspect_Default_Value
879 and then not Is_Scalar_Type
(Ent
)
881 Error_Msg_N
("aspect% can only be applied to scalar type", Id
);
884 elsif A_Id
= Aspect_Default_Component_Value
then
885 if not Is_Array_Type
(Ent
) then
886 Error_Msg_N
("aspect% can only be applied to array type", Id
);
889 elsif not Is_Scalar_Type
(Component_Type
(Ent
)) then
890 Error_Msg_N
("aspect% requires scalar components", Id
);
895 Set_Has_Default_Aspect
(Base_Type
(Ent
));
897 if Is_Scalar_Type
(Ent
) then
898 Set_Default_Aspect_Value
(Base_Type
(Ent
), Expr
);
900 Set_Default_Aspect_Component_Value
(Base_Type
(Ent
), Expr
);
902 end Analyze_Aspect_Default_Value
;
904 ---------------------------------
905 -- Inherit_Delayed_Rep_Aspects --
906 ---------------------------------
908 procedure Inherit_Delayed_Rep_Aspects
(ASN
: Node_Id
) is
909 A_Id
: constant Aspect_Id
:= Get_Aspect_Id
(ASN
);
910 P
: constant Entity_Id
:= Entity
(ASN
);
911 -- Entithy for parent type
914 -- Item from Rep_Item chain
919 -- Loop through delayed aspects for the parent type
922 while Present
(N
) loop
923 if Nkind
(N
) = N_Aspect_Specification
then
924 exit when Entity
(N
) /= P
;
926 if Is_Delayed_Aspect
(N
) then
927 A
:= Get_Aspect_Id
(Chars
(Identifier
(N
)));
929 -- Process delayed rep aspect. For Boolean attributes it is
930 -- not possible to cancel an attribute once set (the attempt
931 -- to use an aspect with xxx => False is an error) for a
932 -- derived type. So for those cases, we do not have to check
933 -- if a clause has been given for the derived type, since it
934 -- is harmless to set it again if it is already set.
940 when Aspect_Alignment
=>
941 if not Has_Alignment_Clause
(E
) then
942 Set_Alignment
(E
, Alignment
(P
));
947 when Aspect_Atomic
=>
948 if Is_Atomic
(P
) then
954 when Aspect_Atomic_Components
=>
955 if Has_Atomic_Components
(P
) then
956 Set_Has_Atomic_Components
(Base_Type
(E
));
961 when Aspect_Bit_Order
=>
962 if Is_Record_Type
(E
)
963 and then No
(Get_Attribute_Definition_Clause
964 (E
, Attribute_Bit_Order
))
965 and then Reverse_Bit_Order
(P
)
967 Set_Reverse_Bit_Order
(Base_Type
(E
));
972 when Aspect_Component_Size
=>
974 and then not Has_Component_Size_Clause
(E
)
977 (Base_Type
(E
), Component_Size
(P
));
982 when Aspect_Machine_Radix
=>
983 if Is_Decimal_Fixed_Point_Type
(E
)
984 and then not Has_Machine_Radix_Clause
(E
)
986 Set_Machine_Radix_10
(E
, Machine_Radix_10
(P
));
989 -- Object_Size (also Size which also sets Object_Size)
991 when Aspect_Object_Size
994 if not Has_Size_Clause
(E
)
996 No
(Get_Attribute_Definition_Clause
997 (E
, Attribute_Object_Size
))
999 Set_Esize
(E
, Esize
(P
));
1005 if not Is_Packed
(E
) then
1006 Set_Is_Packed
(Base_Type
(E
));
1008 if Is_Bit_Packed_Array
(P
) then
1009 Set_Is_Bit_Packed_Array
(Base_Type
(E
));
1010 Set_Packed_Array_Impl_Type
1011 (E
, Packed_Array_Impl_Type
(P
));
1015 -- Scalar_Storage_Order
1017 when Aspect_Scalar_Storage_Order
=>
1018 if (Is_Record_Type
(E
) or else Is_Array_Type
(E
))
1019 and then No
(Get_Attribute_Definition_Clause
1020 (E
, Attribute_Scalar_Storage_Order
))
1021 and then Reverse_Storage_Order
(P
)
1023 Set_Reverse_Storage_Order
(Base_Type
(E
));
1025 -- Clear default SSO indications, since the aspect
1026 -- overrides the default.
1028 Set_SSO_Set_Low_By_Default
(Base_Type
(E
), False);
1029 Set_SSO_Set_High_By_Default
(Base_Type
(E
), False);
1034 when Aspect_Small
=>
1035 if Is_Fixed_Point_Type
(E
)
1036 and then not Has_Small_Clause
(E
)
1038 Set_Small_Value
(E
, Small_Value
(P
));
1043 when Aspect_Storage_Size
=>
1044 if (Is_Access_Type
(E
) or else Is_Task_Type
(E
))
1045 and then not Has_Storage_Size_Clause
(E
)
1047 Set_Storage_Size_Variable
1048 (Base_Type
(E
), Storage_Size_Variable
(P
));
1053 when Aspect_Value_Size
=>
1055 -- Value_Size is never inherited, it is either set by
1056 -- default, or it is explicitly set for the derived
1057 -- type. So nothing to do here.
1063 when Aspect_Volatile
=>
1064 if Is_Volatile
(P
) then
1065 Set_Is_Volatile
(E
);
1068 -- Volatile_Full_Access
1070 when Aspect_Volatile_Full_Access
=>
1071 if Is_Volatile_Full_Access
(P
) then
1072 Set_Is_Volatile_Full_Access
(E
);
1075 -- Volatile_Components
1077 when Aspect_Volatile_Components
=>
1078 if Has_Volatile_Components
(P
) then
1079 Set_Has_Volatile_Components
(Base_Type
(E
));
1082 -- That should be all the Rep Aspects
1085 pragma Assert
(Aspect_Delay
(A_Id
) /= Rep_Aspect
);
1091 N
:= Next_Rep_Item
(N
);
1093 end Inherit_Delayed_Rep_Aspects
;
1095 -------------------------------------
1096 -- Make_Pragma_From_Boolean_Aspect --
1097 -------------------------------------
1099 procedure Make_Pragma_From_Boolean_Aspect
(ASN
: Node_Id
) is
1100 Ident
: constant Node_Id
:= Identifier
(ASN
);
1101 A_Name
: constant Name_Id
:= Chars
(Ident
);
1102 A_Id
: constant Aspect_Id
:= Get_Aspect_Id
(A_Name
);
1103 Ent
: constant Entity_Id
:= Entity
(ASN
);
1104 Expr
: constant Node_Id
:= Expression
(ASN
);
1105 Loc
: constant Source_Ptr
:= Sloc
(ASN
);
1107 procedure Check_False_Aspect_For_Derived_Type
;
1108 -- This procedure checks for the case of a false aspect for a derived
1109 -- type, which improperly tries to cancel an aspect inherited from
1112 -----------------------------------------
1113 -- Check_False_Aspect_For_Derived_Type --
1114 -----------------------------------------
1116 procedure Check_False_Aspect_For_Derived_Type
is
1120 -- We are only checking derived types
1122 if not Is_Derived_Type
(E
) then
1126 Par
:= Nearest_Ancestor
(E
);
1132 if not Is_Atomic
(Par
) then
1136 when Aspect_Atomic_Components
=>
1137 if not Has_Atomic_Components
(Par
) then
1141 when Aspect_Discard_Names
=>
1142 if not Discard_Names
(Par
) then
1147 if not Is_Packed
(Par
) then
1151 when Aspect_Unchecked_Union
=>
1152 if not Is_Unchecked_Union
(Par
) then
1156 when Aspect_Volatile
=>
1157 if not Is_Volatile
(Par
) then
1161 when Aspect_Volatile_Components
=>
1162 if not Has_Volatile_Components
(Par
) then
1166 when Aspect_Volatile_Full_Access
=>
1167 if not Is_Volatile_Full_Access
(Par
) then
1175 -- Fall through means we are canceling an inherited aspect
1177 Error_Msg_Name_1
:= A_Name
;
1179 ("derived type& inherits aspect%, cannot cancel", Expr
, E
);
1180 end Check_False_Aspect_For_Derived_Type
;
1186 -- Start of processing for Make_Pragma_From_Boolean_Aspect
1189 -- Note that we know Expr is present, because for a missing Expr
1190 -- argument, we knew it was True and did not need to delay the
1191 -- evaluation to the freeze point.
1193 if Is_False
(Static_Boolean
(Expr
)) then
1194 Check_False_Aspect_For_Derived_Type
;
1199 Pragma_Identifier
=>
1200 Make_Identifier
(Sloc
(Ident
), Chars
(Ident
)),
1201 Pragma_Argument_Associations
=> New_List
(
1202 Make_Pragma_Argument_Association
(Sloc
(Ident
),
1203 Expression
=> New_Occurrence_Of
(Ent
, Sloc
(Ident
)))));
1205 Set_From_Aspect_Specification
(Prag
, True);
1206 Set_Corresponding_Aspect
(Prag
, ASN
);
1207 Set_Aspect_Rep_Item
(ASN
, Prag
);
1208 Set_Is_Delayed_Aspect
(Prag
);
1209 Set_Parent
(Prag
, ASN
);
1211 end Make_Pragma_From_Boolean_Aspect
;
1219 -- Start of processing for Analyze_Aspects_At_Freeze_Point
1222 -- Must be visible in current scope, but if this is a type from a nested
1223 -- package it may be frozen from an object declaration in the enclosing
1224 -- scope, so install the package declarations to complete the analysis
1225 -- of the aspects, if any. If the package itself is frozen the type will
1226 -- have been frozen as well.
1228 if not Scope_Within_Or_Same
(Current_Scope
, Scope
(E
)) then
1229 if Is_Type
(E
) and then From_Nested_Package
(E
) then
1231 Pack
: constant Entity_Id
:= Scope
(E
);
1235 Install_Visible_Declarations
(Pack
);
1236 Install_Private_Declarations
(Pack
);
1237 Analyze_Aspects_At_Freeze_Point
(E
);
1239 if Is_Private_Type
(E
)
1240 and then Present
(Full_View
(E
))
1242 Analyze_Aspects_At_Freeze_Point
(Full_View
(E
));
1245 End_Package_Scope
(Pack
);
1249 -- Aspects from other entities in different contexts are analyzed
1257 -- Look for aspect specification entries for this entity
1259 ASN
:= First_Rep_Item
(E
);
1260 while Present
(ASN
) loop
1261 if Nkind
(ASN
) = N_Aspect_Specification
then
1262 exit when Entity
(ASN
) /= E
;
1264 if Is_Delayed_Aspect
(ASN
) then
1265 A_Id
:= Get_Aspect_Id
(ASN
);
1269 -- For aspects whose expression is an optional Boolean, make
1270 -- the corresponding pragma at the freeze point.
1272 when Boolean_Aspects
1273 | Library_Unit_Aspects
1275 -- Aspects Export and Import require special handling.
1276 -- Both are by definition Boolean and may benefit from
1277 -- forward references, however their expressions are
1278 -- treated as static. In addition, the syntax of their
1279 -- corresponding pragmas requires extra "pieces" which
1280 -- may also contain forward references. To account for
1281 -- all of this, the corresponding pragma is created by
1282 -- Analyze_Aspect_Export_Import, but is not analyzed as
1283 -- the complete analysis must happen now.
1285 if A_Id
= Aspect_Export
or else A_Id
= Aspect_Import
then
1288 -- Otherwise create a corresponding pragma
1291 Make_Pragma_From_Boolean_Aspect
(ASN
);
1294 -- Special handling for aspects that don't correspond to
1295 -- pragmas/attributes.
1297 when Aspect_Default_Value
1298 | Aspect_Default_Component_Value
1300 -- Do not inherit aspect for anonymous base type of a
1301 -- scalar or array type, because they apply to the first
1302 -- subtype of the type, and will be processed when that
1303 -- first subtype is frozen.
1305 if Is_Derived_Type
(E
)
1306 and then not Comes_From_Source
(E
)
1307 and then E
/= First_Subtype
(E
)
1311 Analyze_Aspect_Default_Value
(ASN
);
1314 -- Ditto for iterator aspects, because the corresponding
1315 -- attributes may not have been analyzed yet.
1317 when Aspect_Constant_Indexing
1318 | Aspect_Default_Iterator
1319 | Aspect_Iterator_Element
1320 | Aspect_Variable_Indexing
1322 Analyze
(Expression
(ASN
));
1324 if Etype
(Expression
(ASN
)) = Any_Type
then
1326 ("\aspect must be fully defined before & is frozen",
1330 when Aspect_Iterable
=>
1331 Validate_Iterable_Aspect
(E
, ASN
);
1337 Ritem
:= Aspect_Rep_Item
(ASN
);
1339 if Present
(Ritem
) then
1345 Next_Rep_Item
(ASN
);
1348 -- This is where we inherit delayed rep aspects from our parent. Note
1349 -- that if we fell out of the above loop with ASN non-empty, it means
1350 -- we hit an aspect for an entity other than E, and it must be the
1351 -- type from which we were derived.
1353 if May_Inherit_Delayed_Rep_Aspects
(E
) then
1354 Inherit_Delayed_Rep_Aspects
(ASN
);
1356 end Analyze_Aspects_At_Freeze_Point
;
1358 -----------------------------------
1359 -- Analyze_Aspect_Specifications --
1360 -----------------------------------
1362 procedure Analyze_Aspect_Specifications
(N
: Node_Id
; E
: Entity_Id
) is
1363 pragma Assert
(Present
(E
));
1365 procedure Decorate
(Asp
: Node_Id
; Prag
: Node_Id
);
1366 -- Establish linkages between an aspect and its corresponding pragma
1368 procedure Insert_Pragma
1370 Is_Instance
: Boolean := False);
1371 -- Subsidiary to the analysis of aspects
1378 -- Initial_Condition
1387 -- Insert pragma Prag such that it mimics the placement of a source
1388 -- pragma of the same kind. Flag Is_Generic should be set when the
1389 -- context denotes a generic instance.
1395 procedure Decorate
(Asp
: Node_Id
; Prag
: Node_Id
) is
1397 Set_Aspect_Rep_Item
(Asp
, Prag
);
1398 Set_Corresponding_Aspect
(Prag
, Asp
);
1399 Set_From_Aspect_Specification
(Prag
);
1400 Set_Parent
(Prag
, Asp
);
1407 procedure Insert_Pragma
1409 Is_Instance
: Boolean := False)
1415 Inserted
: Boolean := False;
1418 -- When the aspect appears on an entry, package, protected unit,
1419 -- subprogram, or task unit body, insert the generated pragma at the
1420 -- top of the body declarations to emulate the behavior of a source
1423 -- package body Pack with Aspect is
1425 -- package body Pack is
1428 if Nkind_In
(N
, N_Entry_Body
,
1434 Decls
:= Declarations
(N
);
1438 Set_Declarations
(N
, Decls
);
1441 Prepend_To
(Decls
, Prag
);
1443 -- When the aspect is associated with a [generic] package declaration
1444 -- insert the generated pragma at the top of the visible declarations
1445 -- to emulate the behavior of a source pragma.
1447 -- package Pack with Aspect is
1452 elsif Nkind_In
(N
, N_Generic_Package_Declaration
,
1453 N_Package_Declaration
)
1455 Decls
:= Visible_Declarations
(Specification
(N
));
1459 Set_Visible_Declarations
(Specification
(N
), Decls
);
1462 -- The visible declarations of a generic instance have the
1463 -- following structure:
1465 -- <renamings of generic formals>
1466 -- <renamings of internally-generated spec and body>
1467 -- <first source declaration>
1469 -- Insert the pragma before the first source declaration by
1470 -- skipping the instance "header" to ensure proper visibility of
1474 Decl
:= First
(Decls
);
1475 while Present
(Decl
) loop
1476 if Comes_From_Source
(Decl
) then
1477 Insert_Before
(Decl
, Prag
);
1485 -- The pragma is placed after the instance "header"
1487 if not Inserted
then
1488 Append_To
(Decls
, Prag
);
1491 -- Otherwise this is not a generic instance
1494 Prepend_To
(Decls
, Prag
);
1497 -- When the aspect is associated with a protected unit declaration,
1498 -- insert the generated pragma at the top of the visible declarations
1499 -- the emulate the behavior of a source pragma.
1501 -- protected [type] Prot with Aspect is
1503 -- protected [type] Prot is
1506 elsif Nkind
(N
) = N_Protected_Type_Declaration
then
1507 Def
:= Protected_Definition
(N
);
1511 Make_Protected_Definition
(Sloc
(N
),
1512 Visible_Declarations
=> New_List
,
1513 End_Label
=> Empty
);
1515 Set_Protected_Definition
(N
, Def
);
1518 Decls
:= Visible_Declarations
(Def
);
1522 Set_Visible_Declarations
(Def
, Decls
);
1525 Prepend_To
(Decls
, Prag
);
1527 -- When the aspect is associated with a task unit declaration, insert
1528 -- insert the generated pragma at the top of the visible declarations
1529 -- the emulate the behavior of a source pragma.
1531 -- task [type] Prot with Aspect is
1533 -- task [type] Prot is
1536 elsif Nkind
(N
) = N_Task_Type_Declaration
then
1537 Def
:= Task_Definition
(N
);
1541 Make_Task_Definition
(Sloc
(N
),
1542 Visible_Declarations
=> New_List
,
1543 End_Label
=> Empty
);
1545 Set_Task_Definition
(N
, Def
);
1548 Decls
:= Visible_Declarations
(Def
);
1552 Set_Visible_Declarations
(Def
, Decls
);
1555 Prepend_To
(Decls
, Prag
);
1557 -- When the context is a library unit, the pragma is added to the
1558 -- Pragmas_After list.
1560 elsif Nkind
(Parent
(N
)) = N_Compilation_Unit
then
1561 Aux
:= Aux_Decls_Node
(Parent
(N
));
1563 if No
(Pragmas_After
(Aux
)) then
1564 Set_Pragmas_After
(Aux
, New_List
);
1567 Prepend
(Prag
, Pragmas_After
(Aux
));
1569 -- Default, the pragma is inserted after the context
1572 Insert_After
(N
, Prag
);
1582 L
: constant List_Id
:= Aspect_Specifications
(N
);
1583 pragma Assert
(Present
(L
));
1585 Ins_Node
: Node_Id
:= N
;
1586 -- Insert pragmas/attribute definition clause after this node when no
1587 -- delayed analysis is required.
1589 -- Start of processing for Analyze_Aspect_Specifications
1592 -- The general processing involves building an attribute definition
1593 -- clause or a pragma node that corresponds to the aspect. Then in order
1594 -- to delay the evaluation of this aspect to the freeze point, we attach
1595 -- the corresponding pragma/attribute definition clause to the aspect
1596 -- specification node, which is then placed in the Rep Item chain. In
1597 -- this case we mark the entity by setting the flag Has_Delayed_Aspects
1598 -- and we evaluate the rep item at the freeze point. When the aspect
1599 -- doesn't have a corresponding pragma/attribute definition clause, then
1600 -- its analysis is simply delayed at the freeze point.
1602 -- Some special cases don't require delay analysis, thus the aspect is
1603 -- analyzed right now.
1605 -- Note that there is a special handling for Pre, Post, Test_Case,
1606 -- Contract_Cases aspects. In these cases, we do not have to worry
1607 -- about delay issues, since the pragmas themselves deal with delay
1608 -- of visibility for the expression analysis. Thus, we just insert
1609 -- the pragma after the node N.
1611 -- Loop through aspects
1613 Aspect
:= First
(L
);
1614 Aspect_Loop
: while Present
(Aspect
) loop
1615 Analyze_One_Aspect
: declare
1616 Expr
: constant Node_Id
:= Expression
(Aspect
);
1617 Id
: constant Node_Id
:= Identifier
(Aspect
);
1618 Loc
: constant Source_Ptr
:= Sloc
(Aspect
);
1619 Nam
: constant Name_Id
:= Chars
(Id
);
1620 A_Id
: constant Aspect_Id
:= Get_Aspect_Id
(Nam
);
1623 Delay_Required
: Boolean;
1624 -- Set False if delay is not required
1626 Eloc
: Source_Ptr
:= No_Location
;
1627 -- Source location of expression, modified when we split PPC's. It
1628 -- is set below when Expr is present.
1630 procedure Analyze_Aspect_Convention
;
1631 -- Perform analysis of aspect Convention
1633 procedure Analyze_Aspect_Disable_Controlled
;
1634 -- Perform analysis of aspect Disable_Controlled
1636 procedure Analyze_Aspect_Export_Import
;
1637 -- Perform analysis of aspects Export or Import
1639 procedure Analyze_Aspect_External_Link_Name
;
1640 -- Perform analysis of aspects External_Name or Link_Name
1642 procedure Analyze_Aspect_Implicit_Dereference
;
1643 -- Perform analysis of the Implicit_Dereference aspects
1645 procedure Make_Aitem_Pragma
1646 (Pragma_Argument_Associations
: List_Id
;
1647 Pragma_Name
: Name_Id
);
1648 -- This is a wrapper for Make_Pragma used for converting aspects
1649 -- to pragmas. It takes care of Sloc (set from Loc) and building
1650 -- the pragma identifier from the given name. In addition the
1651 -- flags Class_Present and Split_PPC are set from the aspect
1652 -- node, as well as Is_Ignored. This routine also sets the
1653 -- From_Aspect_Specification in the resulting pragma node to
1654 -- True, and sets Corresponding_Aspect to point to the aspect.
1655 -- The resulting pragma is assigned to Aitem.
1657 -------------------------------
1658 -- Analyze_Aspect_Convention --
1659 -------------------------------
1661 procedure Analyze_Aspect_Convention
is
1670 -- Obtain all interfacing aspects that apply to the related
1673 Get_Interfacing_Aspects
1674 (Iface_Asp
=> Aspect
,
1675 Conv_Asp
=> Dummy_1
,
1682 -- The related entity is subject to aspect Export or Import.
1683 -- Do not process Convention now because it must be analysed
1684 -- as part of Export or Import.
1686 if Present
(Expo
) or else Present
(Imp
) then
1689 -- Otherwise Convention appears by itself
1692 -- The aspect specifies a particular convention
1694 if Present
(Expr
) then
1695 Conv
:= New_Copy_Tree
(Expr
);
1697 -- Otherwise assume convention Ada
1700 Conv
:= Make_Identifier
(Loc
, Name_Ada
);
1704 -- pragma Convention (<Conv>, <E>);
1707 (Pragma_Name
=> Name_Convention
,
1708 Pragma_Argument_Associations
=> New_List
(
1709 Make_Pragma_Argument_Association
(Loc
,
1710 Expression
=> Conv
),
1711 Make_Pragma_Argument_Association
(Loc
,
1712 Expression
=> New_Occurrence_Of
(E
, Loc
))));
1714 Decorate
(Aspect
, Aitem
);
1715 Insert_Pragma
(Aitem
);
1717 end Analyze_Aspect_Convention
;
1719 ---------------------------------------
1720 -- Analyze_Aspect_Disable_Controlled --
1721 ---------------------------------------
1723 procedure Analyze_Aspect_Disable_Controlled
is
1725 -- The aspect applies only to controlled records
1727 if not (Ekind
(E
) = E_Record_Type
1728 and then Is_Controlled_Active
(E
))
1731 ("aspect % requires controlled record type", Aspect
);
1735 -- Preanalyze the expression (if any) when the aspect resides
1736 -- in a generic unit.
1738 if Inside_A_Generic
then
1739 if Present
(Expr
) then
1740 Preanalyze_And_Resolve
(Expr
, Any_Boolean
);
1743 -- Otherwise the aspect resides in a nongeneric context
1746 -- A controlled record type loses its controlled semantics
1747 -- when the expression statically evaluates to True.
1749 if Present
(Expr
) then
1750 Analyze_And_Resolve
(Expr
, Any_Boolean
);
1752 if Is_OK_Static_Expression
(Expr
) then
1753 if Is_True
(Static_Boolean
(Expr
)) then
1754 Set_Disable_Controlled
(E
);
1757 -- Otherwise the expression is not static
1761 ("expression of aspect % must be static", Aspect
);
1764 -- Otherwise the aspect appears without an expression and
1765 -- defaults to True.
1768 Set_Disable_Controlled
(E
);
1771 end Analyze_Aspect_Disable_Controlled
;
1773 ----------------------------------
1774 -- Analyze_Aspect_Export_Import --
1775 ----------------------------------
1777 procedure Analyze_Aspect_Export_Import
is
1785 -- Obtain all interfacing aspects that apply to the related
1788 Get_Interfacing_Aspects
1789 (Iface_Asp
=> Aspect
,
1790 Conv_Asp
=> Dummy_1
,
1797 -- The related entity cannot be subject to both aspects Export
1800 if Present
(Expo
) and then Present
(Imp
) then
1802 ("incompatible interfacing aspects given for &", E
);
1803 Error_Msg_Sloc
:= Sloc
(Expo
);
1804 Error_Msg_N
("\aspect `Export` #", E
);
1805 Error_Msg_Sloc
:= Sloc
(Imp
);
1806 Error_Msg_N
("\aspect `Import` #", E
);
1809 -- A variable is most likely modified from the outside. Take
1810 -- the optimistic approach to avoid spurious errors.
1812 if Ekind
(E
) = E_Variable
then
1813 Set_Never_Set_In_Source
(E
, False);
1816 -- Resolve the expression of an Import or Export here, and
1817 -- require it to be of type Boolean and static. This is not
1818 -- quite right, because in general this should be delayed,
1819 -- but that seems tricky for these, because normally Boolean
1820 -- aspects are replaced with pragmas at the freeze point in
1821 -- Make_Pragma_From_Boolean_Aspect.
1823 if not Present
(Expr
)
1824 or else Is_True
(Static_Boolean
(Expr
))
1826 if A_Id
= Aspect_Import
then
1827 Set_Has_Completion
(E
);
1828 Set_Is_Imported
(E
);
1830 -- An imported object cannot be explicitly initialized
1832 if Nkind
(N
) = N_Object_Declaration
1833 and then Present
(Expression
(N
))
1836 ("imported entities cannot be initialized "
1837 & "(RM B.1(24))", Expression
(N
));
1841 pragma Assert
(A_Id
= Aspect_Export
);
1842 Set_Is_Exported
(E
);
1845 -- Create the proper form of pragma Export or Import taking
1846 -- into account Conversion, External_Name, and Link_Name.
1848 Aitem
:= Build_Export_Import_Pragma
(Aspect
, E
);
1850 -- Otherwise the expression is either False or erroneous. There
1851 -- is no corresponding pragma.
1856 end Analyze_Aspect_Export_Import
;
1858 ---------------------------------------
1859 -- Analyze_Aspect_External_Link_Name --
1860 ---------------------------------------
1862 procedure Analyze_Aspect_External_Link_Name
is
1870 -- Obtain all interfacing aspects that apply to the related
1873 Get_Interfacing_Aspects
1874 (Iface_Asp
=> Aspect
,
1875 Conv_Asp
=> Dummy_1
,
1882 -- Ensure that aspect External_Name applies to aspect Export or
1885 if A_Id
= Aspect_External_Name
then
1886 if No
(Expo
) and then No
(Imp
) then
1888 ("aspect `External_Name` requires aspect `Import` or "
1889 & "`Export`", Aspect
);
1892 -- Otherwise ensure that aspect Link_Name applies to aspect
1893 -- Export or Import.
1896 pragma Assert
(A_Id
= Aspect_Link_Name
);
1897 if No
(Expo
) and then No
(Imp
) then
1899 ("aspect `Link_Name` requires aspect `Import` or "
1900 & "`Export`", Aspect
);
1903 end Analyze_Aspect_External_Link_Name
;
1905 -----------------------------------------
1906 -- Analyze_Aspect_Implicit_Dereference --
1907 -----------------------------------------
1909 procedure Analyze_Aspect_Implicit_Dereference
is
1911 if not Is_Type
(E
) or else not Has_Discriminants
(E
) then
1913 ("aspect must apply to a type with discriminants", Expr
);
1915 elsif not Is_Entity_Name
(Expr
) then
1917 ("aspect must name a discriminant of current type", Expr
);
1920 -- Discriminant type be an anonymous access type or an
1921 -- anonymous access to subprogram.
1923 -- Missing synchronized types???
1926 Disc
: Entity_Id
:= First_Discriminant
(E
);
1928 while Present
(Disc
) loop
1929 if Chars
(Expr
) = Chars
(Disc
)
1932 E_Anonymous_Access_Subprogram_Type
,
1933 E_Anonymous_Access_Type
)
1935 Set_Has_Implicit_Dereference
(E
);
1936 Set_Has_Implicit_Dereference
(Disc
);
1940 Next_Discriminant
(Disc
);
1943 -- Error if no proper access discriminant
1945 if Present
(Disc
) then
1946 -- For a type extension, check whether parent has
1947 -- a reference discriminant, to verify that use is
1950 if Is_Derived_Type
(E
)
1951 and then Has_Discriminants
(Etype
(E
))
1954 Parent_Disc
: constant Entity_Id
:=
1955 Get_Reference_Discriminant
(Etype
(E
));
1957 if Present
(Parent_Disc
)
1958 and then Corresponding_Discriminant
(Disc
) /=
1962 ("reference discriminant does not match "
1963 & "discriminant of parent type", Expr
);
1970 ("not an access discriminant of&", Expr
, E
);
1975 end Analyze_Aspect_Implicit_Dereference
;
1977 -----------------------
1978 -- Make_Aitem_Pragma --
1979 -----------------------
1981 procedure Make_Aitem_Pragma
1982 (Pragma_Argument_Associations
: List_Id
;
1983 Pragma_Name
: Name_Id
)
1985 Args
: List_Id
:= Pragma_Argument_Associations
;
1988 -- We should never get here if aspect was disabled
1990 pragma Assert
(not Is_Disabled
(Aspect
));
1992 -- Certain aspects allow for an optional name or expression. Do
1993 -- not generate a pragma with empty argument association list.
1995 if No
(Args
) or else No
(Expression
(First
(Args
))) then
2003 Pragma_Argument_Associations
=> Args
,
2004 Pragma_Identifier
=>
2005 Make_Identifier
(Sloc
(Id
), Pragma_Name
),
2006 Class_Present
=> Class_Present
(Aspect
),
2007 Split_PPC
=> Split_PPC
(Aspect
));
2009 -- Set additional semantic fields
2011 if Is_Ignored
(Aspect
) then
2012 Set_Is_Ignored
(Aitem
);
2013 elsif Is_Checked
(Aspect
) then
2014 Set_Is_Checked
(Aitem
);
2017 Set_Corresponding_Aspect
(Aitem
, Aspect
);
2018 Set_From_Aspect_Specification
(Aitem
);
2019 end Make_Aitem_Pragma
;
2021 -- Start of processing for Analyze_One_Aspect
2024 -- Skip aspect if already analyzed, to avoid looping in some cases
2026 if Analyzed
(Aspect
) then
2030 -- Skip looking at aspect if it is totally disabled. Just mark it
2031 -- as such for later reference in the tree. This also sets the
2032 -- Is_Ignored and Is_Checked flags appropriately.
2034 Check_Applicable_Policy
(Aspect
);
2036 if Is_Disabled
(Aspect
) then
2040 -- Set the source location of expression, used in the case of
2041 -- a failed precondition/postcondition or invariant. Note that
2042 -- the source location of the expression is not usually the best
2043 -- choice here. For example, it gets located on the last AND
2044 -- keyword in a chain of boolean expressiond AND'ed together.
2045 -- It is best to put the message on the first character of the
2046 -- assertion, which is the effect of the First_Node call here.
2048 if Present
(Expr
) then
2049 Eloc
:= Sloc
(First_Node
(Expr
));
2052 -- Check restriction No_Implementation_Aspect_Specifications
2054 if Implementation_Defined_Aspect
(A_Id
) then
2056 (No_Implementation_Aspect_Specifications
, Aspect
);
2059 -- Check restriction No_Specification_Of_Aspect
2061 Check_Restriction_No_Specification_Of_Aspect
(Aspect
);
2063 -- Mark aspect analyzed (actual analysis is delayed till later)
2065 Set_Analyzed
(Aspect
);
2066 Set_Entity
(Aspect
, E
);
2068 -- Build the reference to E that will be used in the built pragmas
2070 Ent
:= New_Occurrence_Of
(E
, Sloc
(Id
));
2072 if A_Id
= Aspect_Attach_Handler
2073 or else A_Id
= Aspect_Interrupt_Handler
2076 -- Treat the specification as a reference to the protected
2077 -- operation, which might otherwise appear unreferenced and
2078 -- generate spurious warnings.
2080 Generate_Reference
(E
, Id
);
2083 -- Check for duplicate aspect. Note that the Comes_From_Source
2084 -- test allows duplicate Pre/Post's that we generate internally
2085 -- to escape being flagged here.
2087 if No_Duplicates_Allowed
(A_Id
) then
2089 while Anod
/= Aspect
loop
2090 if Comes_From_Source
(Aspect
)
2091 and then Same_Aspect
(A_Id
, Get_Aspect_Id
(Anod
))
2093 Error_Msg_Name_1
:= Nam
;
2094 Error_Msg_Sloc
:= Sloc
(Anod
);
2096 -- Case of same aspect specified twice
2098 if Class_Present
(Anod
) = Class_Present
(Aspect
) then
2099 if not Class_Present
(Anod
) then
2101 ("aspect% for & previously given#",
2105 ("aspect `%''Class` for & previously given#",
2115 -- Check some general restrictions on language defined aspects
2117 if not Implementation_Defined_Aspect
(A_Id
) then
2118 Error_Msg_Name_1
:= Nam
;
2120 -- Not allowed for renaming declarations. Examine the original
2121 -- node because a subprogram renaming may have been rewritten
2124 if Nkind
(Original_Node
(N
)) in N_Renaming_Declaration
then
2126 ("aspect % not allowed for renaming declaration",
2130 -- Not allowed for formal type declarations
2132 if Nkind
(N
) = N_Formal_Type_Declaration
then
2134 ("aspect % not allowed for formal type declaration",
2139 -- Copy expression for later processing by the procedures
2140 -- Check_Aspect_At_[Freeze_Point | End_Of_Declarations]
2142 Set_Entity
(Id
, New_Copy_Tree
(Expr
));
2144 -- Set Delay_Required as appropriate to aspect
2146 case Aspect_Delay
(A_Id
) is
2147 when Always_Delay
=>
2148 Delay_Required
:= True;
2151 Delay_Required
:= False;
2155 -- If expression has the form of an integer literal, then
2156 -- do not delay, since we know the value cannot change.
2157 -- This optimization catches most rep clause cases.
2159 -- For Boolean aspects, don't delay if no expression
2161 if A_Id
in Boolean_Aspects
and then No
(Expr
) then
2162 Delay_Required
:= False;
2164 -- For non-Boolean aspects, don't delay if integer literal,
2165 -- unless the aspect is Alignment, which affects the
2166 -- freezing of an initialized object.
2168 elsif A_Id
not in Boolean_Aspects
2169 and then A_Id
/= Aspect_Alignment
2170 and then Present
(Expr
)
2171 and then Nkind
(Expr
) = N_Integer_Literal
2173 Delay_Required
:= False;
2175 -- All other cases are delayed
2178 Delay_Required
:= True;
2179 Set_Has_Delayed_Rep_Aspects
(E
);
2183 -- Processing based on specific aspect
2186 when Aspect_Unimplemented
=>
2187 null; -- ??? temp for now
2189 -- No_Aspect should be impossible
2192 raise Program_Error
;
2194 -- Case 1: Aspects corresponding to attribute definition
2200 | Aspect_Component_Size
2201 | Aspect_Constant_Indexing
2202 | Aspect_Default_Iterator
2203 | Aspect_Dispatching_Domain
2204 | Aspect_External_Tag
2207 | Aspect_Iterator_Element
2208 | Aspect_Machine_Radix
2209 | Aspect_Object_Size
2212 | Aspect_Scalar_Storage_Order
2213 | Aspect_Simple_Storage_Pool
2216 | Aspect_Storage_Pool
2217 | Aspect_Stream_Size
2219 | Aspect_Variable_Indexing
2222 -- Indexing aspects apply only to tagged type
2224 if (A_Id
= Aspect_Constant_Indexing
2226 A_Id
= Aspect_Variable_Indexing
)
2227 and then not (Is_Type
(E
)
2228 and then Is_Tagged_Type
(E
))
2231 ("indexing aspect can only apply to a tagged type",
2236 -- For the case of aspect Address, we don't consider that we
2237 -- know the entity is never set in the source, since it is
2238 -- is likely aliasing is occurring.
2240 -- Note: one might think that the analysis of the resulting
2241 -- attribute definition clause would take care of that, but
2242 -- that's not the case since it won't be from source.
2244 if A_Id
= Aspect_Address
then
2245 Set_Never_Set_In_Source
(E
, False);
2248 -- Correctness of the profile of a stream operation is
2249 -- verified at the freeze point, but we must detect the
2250 -- illegal specification of this aspect for a subtype now,
2251 -- to prevent malformed rep_item chains.
2253 if A_Id
= Aspect_Input
or else
2254 A_Id
= Aspect_Output
or else
2255 A_Id
= Aspect_Read
or else
2258 if not Is_First_Subtype
(E
) then
2260 ("local name must be a first subtype", Aspect
);
2263 -- If stream aspect applies to the class-wide type,
2264 -- the generated attribute definition applies to the
2265 -- class-wide type as well.
2267 elsif Class_Present
(Aspect
) then
2269 Make_Attribute_Reference
(Loc
,
2271 Attribute_Name
=> Name_Class
);
2275 -- Construct the attribute_definition_clause. The expression
2276 -- in the aspect specification is simply shared with the
2277 -- constructed attribute, because it will be fully analyzed
2278 -- when the attribute is processed. However, in ASIS mode
2279 -- the aspect expression itself is preanalyzed and resolved
2280 -- to catch visibility errors that are otherwise caught
2281 -- later, and we create a separate copy of the expression
2282 -- to prevent analysis of a malformed tree (e.g. a function
2283 -- call with parameter associations).
2287 Make_Attribute_Definition_Clause
(Loc
,
2289 Chars
=> Chars
(Id
),
2290 Expression
=> New_Copy_Tree
(Expr
));
2293 Make_Attribute_Definition_Clause
(Loc
,
2295 Chars
=> Chars
(Id
),
2296 Expression
=> Relocate_Node
(Expr
));
2299 -- If the address is specified, then we treat the entity as
2300 -- referenced, to avoid spurious warnings. This is analogous
2301 -- to what is done with an attribute definition clause, but
2302 -- here we don't want to generate a reference because this
2303 -- is the point of definition of the entity.
2305 if A_Id
= Aspect_Address
then
2309 -- Case 2: Aspects corresponding to pragmas
2311 -- Case 2a: Aspects corresponding to pragmas with two
2312 -- arguments, where the first argument is a local name
2313 -- referring to the entity, and the second argument is the
2314 -- aspect definition expression.
2316 -- Linker_Section/Suppress/Unsuppress
2318 when Aspect_Linker_Section
2323 (Pragma_Argument_Associations
=> New_List
(
2324 Make_Pragma_Argument_Association
(Loc
,
2325 Expression
=> New_Occurrence_Of
(E
, Loc
)),
2326 Make_Pragma_Argument_Association
(Sloc
(Expr
),
2327 Expression
=> Relocate_Node
(Expr
))),
2328 Pragma_Name
=> Chars
(Id
));
2330 -- Linker_Section does not need delaying, as its argument
2331 -- must be a static string. Furthermore, if applied to
2332 -- an object with an explicit initialization, the object
2333 -- must be frozen in order to elaborate the initialization
2334 -- code. (This is already done for types with implicit
2335 -- initialization, such as protected types.)
2337 if A_Id
= Aspect_Linker_Section
2338 and then Nkind
(N
) = N_Object_Declaration
2339 and then Has_Init_Expression
(N
)
2341 Delay_Required
:= False;
2346 -- Corresponds to pragma Implemented, construct the pragma
2348 when Aspect_Synchronization
=>
2350 (Pragma_Argument_Associations
=> New_List
(
2351 Make_Pragma_Argument_Association
(Loc
,
2352 Expression
=> New_Occurrence_Of
(E
, Loc
)),
2353 Make_Pragma_Argument_Association
(Sloc
(Expr
),
2354 Expression
=> Relocate_Node
(Expr
))),
2355 Pragma_Name
=> Name_Implemented
);
2359 when Aspect_Attach_Handler
=>
2361 (Pragma_Argument_Associations
=> New_List
(
2362 Make_Pragma_Argument_Association
(Sloc
(Ent
),
2364 Make_Pragma_Argument_Association
(Sloc
(Expr
),
2365 Expression
=> Relocate_Node
(Expr
))),
2366 Pragma_Name
=> Name_Attach_Handler
);
2368 -- We need to insert this pragma into the tree to get proper
2369 -- processing and to look valid from a placement viewpoint.
2371 Insert_Pragma
(Aitem
);
2374 -- Dynamic_Predicate, Predicate, Static_Predicate
2376 when Aspect_Dynamic_Predicate
2378 | Aspect_Static_Predicate
2380 -- These aspects apply only to subtypes
2382 if not Is_Type
(E
) then
2384 ("predicate can only be specified for a subtype",
2388 elsif Is_Incomplete_Type
(E
) then
2390 ("predicate cannot apply to incomplete view", Aspect
);
2392 elsif Is_Generic_Type
(E
) then
2394 ("predicate cannot apply to formal type", Aspect
);
2398 -- Construct the pragma (always a pragma Predicate, with
2399 -- flags recording whether it is static/dynamic). We also
2400 -- set flags recording this in the type itself.
2403 (Pragma_Argument_Associations
=> New_List
(
2404 Make_Pragma_Argument_Association
(Sloc
(Ent
),
2406 Make_Pragma_Argument_Association
(Sloc
(Expr
),
2407 Expression
=> Relocate_Node
(Expr
))),
2408 Pragma_Name
=> Name_Predicate
);
2410 -- Mark type has predicates, and remember what kind of
2411 -- aspect lead to this predicate (we need this to access
2412 -- the right set of check policies later on).
2414 Set_Has_Predicates
(E
);
2416 if A_Id
= Aspect_Dynamic_Predicate
then
2417 Set_Has_Dynamic_Predicate_Aspect
(E
);
2419 -- If the entity has a dynamic predicate, any inherited
2420 -- static predicate becomes dynamic as well, and the
2421 -- predicate function includes the conjunction of both.
2423 Set_Has_Static_Predicate_Aspect
(E
, False);
2425 elsif A_Id
= Aspect_Static_Predicate
then
2426 Set_Has_Static_Predicate_Aspect
(E
);
2429 -- If the type is private, indicate that its completion
2430 -- has a freeze node, because that is the one that will
2431 -- be visible at freeze time.
2433 if Is_Private_Type
(E
) and then Present
(Full_View
(E
)) then
2434 Set_Has_Predicates
(Full_View
(E
));
2436 if A_Id
= Aspect_Dynamic_Predicate
then
2437 Set_Has_Dynamic_Predicate_Aspect
(Full_View
(E
));
2438 elsif A_Id
= Aspect_Static_Predicate
then
2439 Set_Has_Static_Predicate_Aspect
(Full_View
(E
));
2442 Set_Has_Delayed_Aspects
(Full_View
(E
));
2443 Ensure_Freeze_Node
(Full_View
(E
));
2446 -- Predicate_Failure
2448 when Aspect_Predicate_Failure
=>
2450 -- This aspect applies only to subtypes
2452 if not Is_Type
(E
) then
2454 ("predicate can only be specified for a subtype",
2458 elsif Is_Incomplete_Type
(E
) then
2460 ("predicate cannot apply to incomplete view", Aspect
);
2464 -- Construct the pragma
2467 (Pragma_Argument_Associations
=> New_List
(
2468 Make_Pragma_Argument_Association
(Sloc
(Ent
),
2470 Make_Pragma_Argument_Association
(Sloc
(Expr
),
2471 Expression
=> Relocate_Node
(Expr
))),
2472 Pragma_Name
=> Name_Predicate_Failure
);
2474 Set_Has_Predicates
(E
);
2476 -- If the type is private, indicate that its completion
2477 -- has a freeze node, because that is the one that will
2478 -- be visible at freeze time.
2480 if Is_Private_Type
(E
) and then Present
(Full_View
(E
)) then
2481 Set_Has_Predicates
(Full_View
(E
));
2482 Set_Has_Delayed_Aspects
(Full_View
(E
));
2483 Ensure_Freeze_Node
(Full_View
(E
));
2486 -- Case 2b: Aspects corresponding to pragmas with two
2487 -- arguments, where the second argument is a local name
2488 -- referring to the entity, and the first argument is the
2489 -- aspect definition expression.
2493 when Aspect_Convention
=>
2494 Analyze_Aspect_Convention
;
2497 -- External_Name, Link_Name
2499 when Aspect_External_Name
2502 Analyze_Aspect_External_Link_Name
;
2505 -- CPU, Interrupt_Priority, Priority
2507 -- These three aspects can be specified for a subprogram spec
2508 -- or body, in which case we analyze the expression and export
2509 -- the value of the aspect.
2511 -- Previously, we generated an equivalent pragma for bodies
2512 -- (note that the specs cannot contain these pragmas). The
2513 -- pragma was inserted ahead of local declarations, rather than
2514 -- after the body. This leads to a certain duplication between
2515 -- the processing performed for the aspect and the pragma, but
2516 -- given the straightforward handling required it is simpler
2517 -- to duplicate than to translate the aspect in the spec into
2518 -- a pragma in the declarative part of the body.
2521 | Aspect_Interrupt_Priority
2524 if Nkind_In
(N
, N_Subprogram_Body
,
2525 N_Subprogram_Declaration
)
2527 -- Analyze the aspect expression
2529 Analyze_And_Resolve
(Expr
, Standard_Integer
);
2531 -- Interrupt_Priority aspect not allowed for main
2532 -- subprograms. RM D.1 does not forbid this explicitly,
2533 -- but RM J.15.11(6/3) does not permit pragma
2534 -- Interrupt_Priority for subprograms.
2536 if A_Id
= Aspect_Interrupt_Priority
then
2538 ("Interrupt_Priority aspect cannot apply to "
2539 & "subprogram", Expr
);
2541 -- The expression must be static
2543 elsif not Is_OK_Static_Expression
(Expr
) then
2544 Flag_Non_Static_Expr
2545 ("aspect requires static expression!", Expr
);
2547 -- Check whether this is the main subprogram. Issue a
2548 -- warning only if it is obviously not a main program
2549 -- (when it has parameters or when the subprogram is
2550 -- within a package).
2552 elsif Present
(Parameter_Specifications
2553 (Specification
(N
)))
2554 or else not Is_Compilation_Unit
(Defining_Entity
(N
))
2556 -- See RM D.1(14/3) and D.16(12/3)
2559 ("aspect applied to subprogram other than the "
2560 & "main subprogram has no effect??", Expr
);
2562 -- Otherwise check in range and export the value
2564 -- For the CPU aspect
2566 elsif A_Id
= Aspect_CPU
then
2567 if Is_In_Range
(Expr
, RTE
(RE_CPU_Range
)) then
2569 -- Value is correct so we export the value to make
2570 -- it available at execution time.
2573 (Main_Unit
, UI_To_Int
(Expr_Value
(Expr
)));
2577 ("main subprogram CPU is out of range", Expr
);
2580 -- For the Priority aspect
2582 elsif A_Id
= Aspect_Priority
then
2583 if Is_In_Range
(Expr
, RTE
(RE_Priority
)) then
2585 -- Value is correct so we export the value to make
2586 -- it available at execution time.
2589 (Main_Unit
, UI_To_Int
(Expr_Value
(Expr
)));
2591 -- Ignore pragma if Relaxed_RM_Semantics to support
2592 -- other targets/non GNAT compilers.
2594 elsif not Relaxed_RM_Semantics
then
2596 ("main subprogram priority is out of range",
2601 -- Load an arbitrary entity from System.Tasking.Stages
2602 -- or System.Tasking.Restricted.Stages (depending on
2603 -- the supported profile) to make sure that one of these
2604 -- packages is implicitly with'ed, since we need to have
2605 -- the tasking run time active for the pragma Priority to
2606 -- have any effect. Previously we with'ed the package
2607 -- System.Tasking, but this package does not trigger the
2608 -- required initialization of the run-time library.
2611 Discard
: Entity_Id
;
2613 if Restricted_Profile
then
2614 Discard
:= RTE
(RE_Activate_Restricted_Tasks
);
2616 Discard
:= RTE
(RE_Activate_Tasks
);
2620 -- Handling for these aspects in subprograms is complete
2624 -- For task and protected types pass the aspect as an
2629 Make_Attribute_Definition_Clause
(Loc
,
2631 Chars
=> Chars
(Id
),
2632 Expression
=> Relocate_Node
(Expr
));
2637 when Aspect_Warnings
=>
2639 (Pragma_Argument_Associations
=> New_List
(
2640 Make_Pragma_Argument_Association
(Sloc
(Expr
),
2641 Expression
=> Relocate_Node
(Expr
)),
2642 Make_Pragma_Argument_Association
(Loc
,
2643 Expression
=> New_Occurrence_Of
(E
, Loc
))),
2644 Pragma_Name
=> Chars
(Id
));
2646 Decorate
(Aspect
, Aitem
);
2647 Insert_Pragma
(Aitem
);
2650 -- Case 2c: Aspects corresponding to pragmas with three
2653 -- Invariant aspects have a first argument that references the
2654 -- entity, a second argument that is the expression and a third
2655 -- argument that is an appropriate message.
2657 -- Invariant, Type_Invariant
2659 when Aspect_Invariant
2660 | Aspect_Type_Invariant
2662 -- Analysis of the pragma will verify placement legality:
2663 -- an invariant must apply to a private type, or appear in
2664 -- the private part of a spec and apply to a completion.
2667 (Pragma_Argument_Associations
=> New_List
(
2668 Make_Pragma_Argument_Association
(Sloc
(Ent
),
2670 Make_Pragma_Argument_Association
(Sloc
(Expr
),
2671 Expression
=> Relocate_Node
(Expr
))),
2672 Pragma_Name
=> Name_Invariant
);
2674 -- Add message unless exception messages are suppressed
2676 if not Opt
.Exception_Locations_Suppressed
then
2677 Append_To
(Pragma_Argument_Associations
(Aitem
),
2678 Make_Pragma_Argument_Association
(Eloc
,
2679 Chars
=> Name_Message
,
2681 Make_String_Literal
(Eloc
,
2682 Strval
=> "failed invariant from "
2683 & Build_Location_String
(Eloc
))));
2686 -- For Invariant case, insert immediately after the entity
2687 -- declaration. We do not have to worry about delay issues
2688 -- since the pragma processing takes care of this.
2690 Delay_Required
:= False;
2692 -- Case 2d : Aspects that correspond to a pragma with one
2697 -- Aspect Abstract_State introduces implicit declarations for
2698 -- all state abstraction entities it defines. To emulate this
2699 -- behavior, insert the pragma at the beginning of the visible
2700 -- declarations of the related package so that it is analyzed
2703 when Aspect_Abstract_State
=> Abstract_State
: declare
2704 Context
: Node_Id
:= N
;
2707 -- When aspect Abstract_State appears on a generic package,
2708 -- it is propageted to the package instance. The context in
2709 -- this case is the instance spec.
2711 if Nkind
(Context
) = N_Package_Instantiation
then
2712 Context
:= Instance_Spec
(Context
);
2715 if Nkind_In
(Context
, N_Generic_Package_Declaration
,
2716 N_Package_Declaration
)
2719 (Pragma_Argument_Associations
=> New_List
(
2720 Make_Pragma_Argument_Association
(Loc
,
2721 Expression
=> Relocate_Node
(Expr
))),
2722 Pragma_Name
=> Name_Abstract_State
);
2724 Decorate
(Aspect
, Aitem
);
2728 Is_Generic_Instance
(Defining_Entity
(Context
)));
2732 ("aspect & must apply to a package declaration",
2739 -- Aspect Async_Readers is never delayed because it is
2740 -- equivalent to a source pragma which appears after the
2741 -- related object declaration.
2743 when Aspect_Async_Readers
=>
2745 (Pragma_Argument_Associations
=> New_List
(
2746 Make_Pragma_Argument_Association
(Loc
,
2747 Expression
=> Relocate_Node
(Expr
))),
2748 Pragma_Name
=> Name_Async_Readers
);
2750 Decorate
(Aspect
, Aitem
);
2751 Insert_Pragma
(Aitem
);
2754 -- Aspect Async_Writers is never delayed because it is
2755 -- equivalent to a source pragma which appears after the
2756 -- related object declaration.
2758 when Aspect_Async_Writers
=>
2760 (Pragma_Argument_Associations
=> New_List
(
2761 Make_Pragma_Argument_Association
(Loc
,
2762 Expression
=> Relocate_Node
(Expr
))),
2763 Pragma_Name
=> Name_Async_Writers
);
2765 Decorate
(Aspect
, Aitem
);
2766 Insert_Pragma
(Aitem
);
2769 -- Aspect Constant_After_Elaboration is never delayed because
2770 -- it is equivalent to a source pragma which appears after the
2771 -- related object declaration.
2773 when Aspect_Constant_After_Elaboration
=>
2775 (Pragma_Argument_Associations
=> New_List
(
2776 Make_Pragma_Argument_Association
(Loc
,
2777 Expression
=> Relocate_Node
(Expr
))),
2779 Name_Constant_After_Elaboration
);
2781 Decorate
(Aspect
, Aitem
);
2782 Insert_Pragma
(Aitem
);
2785 -- Aspect Default_Internal_Condition is never delayed because
2786 -- it is equivalent to a source pragma which appears after the
2787 -- related private type. To deal with forward references, the
2788 -- generated pragma is stored in the rep chain of the related
2789 -- private type as types do not carry contracts. The pragma is
2790 -- wrapped inside of a procedure at the freeze point of the
2791 -- private type's full view.
2793 when Aspect_Default_Initial_Condition
=>
2795 (Pragma_Argument_Associations
=> New_List
(
2796 Make_Pragma_Argument_Association
(Loc
,
2797 Expression
=> Relocate_Node
(Expr
))),
2799 Name_Default_Initial_Condition
);
2801 Decorate
(Aspect
, Aitem
);
2802 Insert_Pragma
(Aitem
);
2805 -- Default_Storage_Pool
2807 when Aspect_Default_Storage_Pool
=>
2809 (Pragma_Argument_Associations
=> New_List
(
2810 Make_Pragma_Argument_Association
(Loc
,
2811 Expression
=> Relocate_Node
(Expr
))),
2813 Name_Default_Storage_Pool
);
2815 Decorate
(Aspect
, Aitem
);
2816 Insert_Pragma
(Aitem
);
2821 -- Aspect Depends is never delayed because it is equivalent to
2822 -- a source pragma which appears after the related subprogram.
2823 -- To deal with forward references, the generated pragma is
2824 -- stored in the contract of the related subprogram and later
2825 -- analyzed at the end of the declarative region. See routine
2826 -- Analyze_Depends_In_Decl_Part for details.
2828 when Aspect_Depends
=>
2830 (Pragma_Argument_Associations
=> New_List
(
2831 Make_Pragma_Argument_Association
(Loc
,
2832 Expression
=> Relocate_Node
(Expr
))),
2833 Pragma_Name
=> Name_Depends
);
2835 Decorate
(Aspect
, Aitem
);
2836 Insert_Pragma
(Aitem
);
2839 -- Aspect Effecitve_Reads is never delayed because it is
2840 -- equivalent to a source pragma which appears after the
2841 -- related object declaration.
2843 when Aspect_Effective_Reads
=>
2845 (Pragma_Argument_Associations
=> New_List
(
2846 Make_Pragma_Argument_Association
(Loc
,
2847 Expression
=> Relocate_Node
(Expr
))),
2848 Pragma_Name
=> Name_Effective_Reads
);
2850 Decorate
(Aspect
, Aitem
);
2851 Insert_Pragma
(Aitem
);
2854 -- Aspect Effective_Writes is never delayed because it is
2855 -- equivalent to a source pragma which appears after the
2856 -- related object declaration.
2858 when Aspect_Effective_Writes
=>
2860 (Pragma_Argument_Associations
=> New_List
(
2861 Make_Pragma_Argument_Association
(Loc
,
2862 Expression
=> Relocate_Node
(Expr
))),
2863 Pragma_Name
=> Name_Effective_Writes
);
2865 Decorate
(Aspect
, Aitem
);
2866 Insert_Pragma
(Aitem
);
2869 -- Aspect Extensions_Visible is never delayed because it is
2870 -- equivalent to a source pragma which appears after the
2871 -- related subprogram.
2873 when Aspect_Extensions_Visible
=>
2875 (Pragma_Argument_Associations
=> New_List
(
2876 Make_Pragma_Argument_Association
(Loc
,
2877 Expression
=> Relocate_Node
(Expr
))),
2878 Pragma_Name
=> Name_Extensions_Visible
);
2880 Decorate
(Aspect
, Aitem
);
2881 Insert_Pragma
(Aitem
);
2884 -- Aspect Ghost is never delayed because it is equivalent to a
2885 -- source pragma which appears at the top of [generic] package
2886 -- declarations or after an object, a [generic] subprogram, or
2887 -- a type declaration.
2889 when Aspect_Ghost
=>
2891 (Pragma_Argument_Associations
=> New_List
(
2892 Make_Pragma_Argument_Association
(Loc
,
2893 Expression
=> Relocate_Node
(Expr
))),
2894 Pragma_Name
=> Name_Ghost
);
2896 Decorate
(Aspect
, Aitem
);
2897 Insert_Pragma
(Aitem
);
2902 -- Aspect Global is never delayed because it is equivalent to
2903 -- a source pragma which appears after the related subprogram.
2904 -- To deal with forward references, the generated pragma is
2905 -- stored in the contract of the related subprogram and later
2906 -- analyzed at the end of the declarative region. See routine
2907 -- Analyze_Global_In_Decl_Part for details.
2909 when Aspect_Global
=>
2911 (Pragma_Argument_Associations
=> New_List
(
2912 Make_Pragma_Argument_Association
(Loc
,
2913 Expression
=> Relocate_Node
(Expr
))),
2914 Pragma_Name
=> Name_Global
);
2916 Decorate
(Aspect
, Aitem
);
2917 Insert_Pragma
(Aitem
);
2920 -- Initial_Condition
2922 -- Aspect Initial_Condition is never delayed because it is
2923 -- equivalent to a source pragma which appears after the
2924 -- related package. To deal with forward references, the
2925 -- generated pragma is stored in the contract of the related
2926 -- package and later analyzed at the end of the declarative
2927 -- region. See routine Analyze_Initial_Condition_In_Decl_Part
2930 when Aspect_Initial_Condition
=> Initial_Condition
: declare
2931 Context
: Node_Id
:= N
;
2934 -- When aspect Initial_Condition appears on a generic
2935 -- package, it is propageted to the package instance. The
2936 -- context in this case is the instance spec.
2938 if Nkind
(Context
) = N_Package_Instantiation
then
2939 Context
:= Instance_Spec
(Context
);
2942 if Nkind_In
(Context
, N_Generic_Package_Declaration
,
2943 N_Package_Declaration
)
2946 (Pragma_Argument_Associations
=> New_List
(
2947 Make_Pragma_Argument_Association
(Loc
,
2948 Expression
=> Relocate_Node
(Expr
))),
2950 Name_Initial_Condition
);
2952 Decorate
(Aspect
, Aitem
);
2956 Is_Generic_Instance
(Defining_Entity
(Context
)));
2958 -- Otherwise the context is illegal
2962 ("aspect & must apply to a package declaration",
2967 end Initial_Condition
;
2971 -- Aspect Initializes is never delayed because it is equivalent
2972 -- to a source pragma appearing after the related package. To
2973 -- deal with forward references, the generated pragma is stored
2974 -- in the contract of the related package and later analyzed at
2975 -- the end of the declarative region. For details, see routine
2976 -- Analyze_Initializes_In_Decl_Part.
2978 when Aspect_Initializes
=> Initializes
: declare
2979 Context
: Node_Id
:= N
;
2982 -- When aspect Initializes appears on a generic package,
2983 -- it is propageted to the package instance. The context
2984 -- in this case is the instance spec.
2986 if Nkind
(Context
) = N_Package_Instantiation
then
2987 Context
:= Instance_Spec
(Context
);
2990 if Nkind_In
(Context
, N_Generic_Package_Declaration
,
2991 N_Package_Declaration
)
2994 (Pragma_Argument_Associations
=> New_List
(
2995 Make_Pragma_Argument_Association
(Loc
,
2996 Expression
=> Relocate_Node
(Expr
))),
2997 Pragma_Name
=> Name_Initializes
);
2999 Decorate
(Aspect
, Aitem
);
3003 Is_Generic_Instance
(Defining_Entity
(Context
)));
3005 -- Otherwise the context is illegal
3009 ("aspect & must apply to a package declaration",
3016 -- Max_Entry_Queue_Depth
3018 when Aspect_Max_Entry_Queue_Depth
=>
3020 (Pragma_Argument_Associations
=> New_List
(
3021 Make_Pragma_Argument_Association
(Loc
,
3022 Expression
=> Relocate_Node
(Expr
))),
3023 Pragma_Name
=> Name_Max_Entry_Queue_Depth
);
3025 Decorate
(Aspect
, Aitem
);
3026 Insert_Pragma
(Aitem
);
3031 when Aspect_Max_Queue_Length
=>
3033 (Pragma_Argument_Associations
=> New_List
(
3034 Make_Pragma_Argument_Association
(Loc
,
3035 Expression
=> Relocate_Node
(Expr
))),
3036 Pragma_Name
=> Name_Max_Queue_Length
);
3038 Decorate
(Aspect
, Aitem
);
3039 Insert_Pragma
(Aitem
);
3044 when Aspect_Obsolescent
=> declare
3052 Make_Pragma_Argument_Association
(Sloc
(Expr
),
3053 Expression
=> Relocate_Node
(Expr
)));
3057 (Pragma_Argument_Associations
=> Args
,
3058 Pragma_Name
=> Chars
(Id
));
3063 when Aspect_Part_Of
=>
3064 if Nkind_In
(N
, N_Object_Declaration
,
3065 N_Package_Instantiation
)
3066 or else Is_Single_Concurrent_Type_Declaration
(N
)
3069 (Pragma_Argument_Associations
=> New_List
(
3070 Make_Pragma_Argument_Association
(Loc
,
3071 Expression
=> Relocate_Node
(Expr
))),
3072 Pragma_Name
=> Name_Part_Of
);
3074 Decorate
(Aspect
, Aitem
);
3075 Insert_Pragma
(Aitem
);
3079 ("aspect & must apply to package instantiation, "
3080 & "object, single protected type or single task type",
3088 when Aspect_SPARK_Mode
=>
3090 (Pragma_Argument_Associations
=> New_List
(
3091 Make_Pragma_Argument_Association
(Loc
,
3092 Expression
=> Relocate_Node
(Expr
))),
3093 Pragma_Name
=> Name_SPARK_Mode
);
3095 Decorate
(Aspect
, Aitem
);
3096 Insert_Pragma
(Aitem
);
3101 -- Aspect Refined_Depends is never delayed because it is
3102 -- equivalent to a source pragma which appears in the
3103 -- declarations of the related subprogram body. To deal with
3104 -- forward references, the generated pragma is stored in the
3105 -- contract of the related subprogram body and later analyzed
3106 -- at the end of the declarative region. For details, see
3107 -- routine Analyze_Refined_Depends_In_Decl_Part.
3109 when Aspect_Refined_Depends
=>
3111 (Pragma_Argument_Associations
=> New_List
(
3112 Make_Pragma_Argument_Association
(Loc
,
3113 Expression
=> Relocate_Node
(Expr
))),
3114 Pragma_Name
=> Name_Refined_Depends
);
3116 Decorate
(Aspect
, Aitem
);
3117 Insert_Pragma
(Aitem
);
3122 -- Aspect Refined_Global is never delayed because it is
3123 -- equivalent to a source pragma which appears in the
3124 -- declarations of the related subprogram body. To deal with
3125 -- forward references, the generated pragma is stored in the
3126 -- contract of the related subprogram body and later analyzed
3127 -- at the end of the declarative region. For details, see
3128 -- routine Analyze_Refined_Global_In_Decl_Part.
3130 when Aspect_Refined_Global
=>
3132 (Pragma_Argument_Associations
=> New_List
(
3133 Make_Pragma_Argument_Association
(Loc
,
3134 Expression
=> Relocate_Node
(Expr
))),
3135 Pragma_Name
=> Name_Refined_Global
);
3137 Decorate
(Aspect
, Aitem
);
3138 Insert_Pragma
(Aitem
);
3143 when Aspect_Refined_Post
=>
3145 (Pragma_Argument_Associations
=> New_List
(
3146 Make_Pragma_Argument_Association
(Loc
,
3147 Expression
=> Relocate_Node
(Expr
))),
3148 Pragma_Name
=> Name_Refined_Post
);
3150 Decorate
(Aspect
, Aitem
);
3151 Insert_Pragma
(Aitem
);
3156 when Aspect_Refined_State
=>
3158 -- The corresponding pragma for Refined_State is inserted in
3159 -- the declarations of the related package body. This action
3160 -- synchronizes both the source and from-aspect versions of
3163 if Nkind
(N
) = N_Package_Body
then
3165 (Pragma_Argument_Associations
=> New_List
(
3166 Make_Pragma_Argument_Association
(Loc
,
3167 Expression
=> Relocate_Node
(Expr
))),
3168 Pragma_Name
=> Name_Refined_State
);
3170 Decorate
(Aspect
, Aitem
);
3171 Insert_Pragma
(Aitem
);
3173 -- Otherwise the context is illegal
3177 ("aspect & must apply to a package body", Aspect
, Id
);
3182 -- Relative_Deadline
3184 when Aspect_Relative_Deadline
=>
3186 (Pragma_Argument_Associations
=> New_List
(
3187 Make_Pragma_Argument_Association
(Loc
,
3188 Expression
=> Relocate_Node
(Expr
))),
3189 Pragma_Name
=> Name_Relative_Deadline
);
3191 -- If the aspect applies to a task, the corresponding pragma
3192 -- must appear within its declarations, not after.
3194 if Nkind
(N
) = N_Task_Type_Declaration
then
3200 if No
(Task_Definition
(N
)) then
3201 Set_Task_Definition
(N
,
3202 Make_Task_Definition
(Loc
,
3203 Visible_Declarations
=> New_List
,
3204 End_Label
=> Empty
));
3207 Def
:= Task_Definition
(N
);
3208 V
:= Visible_Declarations
(Def
);
3209 if not Is_Empty_List
(V
) then
3210 Insert_Before
(First
(V
), Aitem
);
3213 Set_Visible_Declarations
(Def
, New_List
(Aitem
));
3220 -- Secondary_Stack_Size
3222 -- Aspect Secondary_Stack_Size needs to be converted into a
3223 -- pragma for two reasons: the attribute is not analyzed until
3224 -- after the expansion of the task type declaration and the
3225 -- attribute does not have visibility on the discriminant.
3227 when Aspect_Secondary_Stack_Size
=>
3229 (Pragma_Argument_Associations
=> New_List
(
3230 Make_Pragma_Argument_Association
(Loc
,
3231 Expression
=> Relocate_Node
(Expr
))),
3233 Name_Secondary_Stack_Size
);
3235 Decorate
(Aspect
, Aitem
);
3236 Insert_Pragma
(Aitem
);
3239 -- Volatile_Function
3241 -- Aspect Volatile_Function is never delayed because it is
3242 -- equivalent to a source pragma which appears after the
3243 -- related subprogram.
3245 when Aspect_Volatile_Function
=>
3247 (Pragma_Argument_Associations
=> New_List
(
3248 Make_Pragma_Argument_Association
(Loc
,
3249 Expression
=> Relocate_Node
(Expr
))),
3250 Pragma_Name
=> Name_Volatile_Function
);
3252 Decorate
(Aspect
, Aitem
);
3253 Insert_Pragma
(Aitem
);
3256 -- Case 2e: Annotate aspect
3258 when Aspect_Annotate
=>
3265 -- The argument can be a single identifier
3267 if Nkind
(Expr
) = N_Identifier
then
3269 -- One level of parens is allowed
3271 if Paren_Count
(Expr
) > 1 then
3272 Error_Msg_F
("extra parentheses ignored", Expr
);
3275 Set_Paren_Count
(Expr
, 0);
3277 -- Add the single item to the list
3279 Args
:= New_List
(Expr
);
3281 -- Otherwise we must have an aggregate
3283 elsif Nkind
(Expr
) = N_Aggregate
then
3285 -- Must be positional
3287 if Present
(Component_Associations
(Expr
)) then
3289 ("purely positional aggregate required", Expr
);
3293 -- Must not be parenthesized
3295 if Paren_Count
(Expr
) /= 0 then
3296 Error_Msg_F
("extra parentheses ignored", Expr
);
3299 -- List of arguments is list of aggregate expressions
3301 Args
:= Expressions
(Expr
);
3303 -- Anything else is illegal
3306 Error_Msg_F
("wrong form for Annotate aspect", Expr
);
3310 -- Prepare pragma arguments
3313 Arg
:= First
(Args
);
3314 while Present
(Arg
) loop
3316 Make_Pragma_Argument_Association
(Sloc
(Arg
),
3317 Expression
=> Relocate_Node
(Arg
)));
3322 Make_Pragma_Argument_Association
(Sloc
(Ent
),
3323 Chars
=> Name_Entity
,
3324 Expression
=> Ent
));
3327 (Pragma_Argument_Associations
=> Pargs
,
3328 Pragma_Name
=> Name_Annotate
);
3331 -- Case 3 : Aspects that don't correspond to pragma/attribute
3332 -- definition clause.
3334 -- Case 3a: The aspects listed below don't correspond to
3335 -- pragmas/attributes but do require delayed analysis.
3337 -- Default_Value can only apply to a scalar type
3339 when Aspect_Default_Value
=>
3340 if not Is_Scalar_Type
(E
) then
3342 ("aspect Default_Value must apply to a scalar type", N
);
3347 -- Default_Component_Value can only apply to an array type
3348 -- with scalar components.
3350 when Aspect_Default_Component_Value
=>
3351 if not (Is_Array_Type
(E
)
3352 and then Is_Scalar_Type
(Component_Type
(E
)))
3355 ("aspect Default_Component_Value can only apply to an "
3356 & "array of scalar components", N
);
3361 -- Case 3b: The aspects listed below don't correspond to
3362 -- pragmas/attributes and don't need delayed analysis.
3364 -- Implicit_Dereference
3366 -- For Implicit_Dereference, External_Name and Link_Name, only
3367 -- the legality checks are done during the analysis, thus no
3368 -- delay is required.
3370 when Aspect_Implicit_Dereference
=>
3371 Analyze_Aspect_Implicit_Dereference
;
3376 when Aspect_Dimension
=>
3377 Analyze_Aspect_Dimension
(N
, Id
, Expr
);
3382 when Aspect_Dimension_System
=>
3383 Analyze_Aspect_Dimension_System
(N
, Id
, Expr
);
3386 -- Case 4: Aspects requiring special handling
3388 -- Pre/Post/Test_Case/Contract_Cases whose corresponding
3389 -- pragmas take care of the delay.
3393 -- Aspects Pre/Post generate Precondition/Postcondition pragmas
3394 -- with a first argument that is the expression, and a second
3395 -- argument that is an informative message if the test fails.
3396 -- This is inserted right after the declaration, to get the
3397 -- required pragma placement. The processing for the pragmas
3398 -- takes care of the required delay.
3400 when Pre_Post_Aspects
=> Pre_Post
: declare
3404 if A_Id
= Aspect_Pre
or else A_Id
= Aspect_Precondition
then
3405 Pname
:= Name_Precondition
;
3407 Pname
:= Name_Postcondition
;
3410 -- Check that the class-wide predicate cannot be applied to
3411 -- an operation of a synchronized type. AI12-0182 forbids
3412 -- these altogether, while earlier language semantics made
3413 -- them legal on tagged synchronized types.
3415 -- Other legality checks are performed when analyzing the
3416 -- contract of the operation.
3418 if Class_Present
(Aspect
)
3419 and then Is_Concurrent_Type
(Current_Scope
)
3420 and then Ekind_In
(E
, E_Entry
, E_Function
, E_Procedure
)
3422 Error_Msg_Name_1
:= Original_Aspect_Pragma_Name
(Aspect
);
3424 ("aspect % can only be specified for a primitive "
3425 & "operation of a tagged type", Aspect
);
3430 -- If the expressions is of the form A and then B, then
3431 -- we generate separate Pre/Post aspects for the separate
3432 -- clauses. Since we allow multiple pragmas, there is no
3433 -- problem in allowing multiple Pre/Post aspects internally.
3434 -- These should be treated in reverse order (B first and
3435 -- A second) since they are later inserted just after N in
3436 -- the order they are treated. This way, the pragma for A
3437 -- ends up preceding the pragma for B, which may have an
3438 -- importance for the error raised (either constraint error
3439 -- or precondition error).
3441 -- We do not do this for Pre'Class, since we have to put
3442 -- these conditions together in a complex OR expression.
3444 -- We do not do this in ASIS mode, as ASIS relies on the
3445 -- original node representing the complete expression, when
3446 -- retrieving it through the source aspect table. Also, we
3447 -- don't do this in GNATprove mode, because it brings no
3448 -- benefit for proof and causes annoynace for flow analysis,
3449 -- which prefers to be as close to the original source code
3452 if not (ASIS_Mode
or GNATprove_Mode
)
3453 and then (Pname
= Name_Postcondition
3454 or else not Class_Present
(Aspect
))
3456 while Nkind
(Expr
) = N_And_Then
loop
3457 Insert_After
(Aspect
,
3458 Make_Aspect_Specification
(Sloc
(Left_Opnd
(Expr
)),
3459 Identifier
=> Identifier
(Aspect
),
3460 Expression
=> Relocate_Node
(Left_Opnd
(Expr
)),
3461 Class_Present
=> Class_Present
(Aspect
),
3462 Split_PPC
=> True));
3463 Rewrite
(Expr
, Relocate_Node
(Right_Opnd
(Expr
)));
3464 Eloc
:= Sloc
(Expr
);
3468 -- Build the precondition/postcondition pragma
3470 -- Add note about why we do NOT need Copy_Tree here???
3473 (Pragma_Argument_Associations
=> New_List
(
3474 Make_Pragma_Argument_Association
(Eloc
,
3475 Chars
=> Name_Check
,
3476 Expression
=> Relocate_Node
(Expr
))),
3477 Pragma_Name
=> Pname
);
3479 -- Add message unless exception messages are suppressed
3481 if not Opt
.Exception_Locations_Suppressed
then
3482 Append_To
(Pragma_Argument_Associations
(Aitem
),
3483 Make_Pragma_Argument_Association
(Eloc
,
3484 Chars
=> Name_Message
,
3486 Make_String_Literal
(Eloc
,
3488 & Get_Name_String
(Pname
)
3490 & Build_Location_String
(Eloc
))));
3493 Set_Is_Delayed_Aspect
(Aspect
);
3495 -- For Pre/Post cases, insert immediately after the entity
3496 -- declaration, since that is the required pragma placement.
3497 -- Note that for these aspects, we do not have to worry
3498 -- about delay issues, since the pragmas themselves deal
3499 -- with delay of visibility for the expression analysis.
3501 Insert_Pragma
(Aitem
);
3508 when Aspect_Test_Case
=> Test_Case
: declare
3510 Comp_Expr
: Node_Id
;
3511 Comp_Assn
: Node_Id
;
3517 if Nkind
(Parent
(N
)) = N_Compilation_Unit
then
3518 Error_Msg_Name_1
:= Nam
;
3519 Error_Msg_N
("incorrect placement of aspect `%`", E
);
3523 if Nkind
(Expr
) /= N_Aggregate
then
3524 Error_Msg_Name_1
:= Nam
;
3526 ("wrong syntax for aspect `%` for &", Id
, E
);
3530 -- Make pragma expressions refer to the original aspect
3531 -- expressions through the Original_Node link. This is used
3532 -- in semantic analysis for ASIS mode, so that the original
3533 -- expression also gets analyzed.
3535 Comp_Expr
:= First
(Expressions
(Expr
));
3536 while Present
(Comp_Expr
) loop
3537 New_Expr
:= Relocate_Node
(Comp_Expr
);
3539 Make_Pragma_Argument_Association
(Sloc
(Comp_Expr
),
3540 Expression
=> New_Expr
));
3544 Comp_Assn
:= First
(Component_Associations
(Expr
));
3545 while Present
(Comp_Assn
) loop
3546 if List_Length
(Choices
(Comp_Assn
)) /= 1
3548 Nkind
(First
(Choices
(Comp_Assn
))) /= N_Identifier
3550 Error_Msg_Name_1
:= Nam
;
3552 ("wrong syntax for aspect `%` for &", Id
, E
);
3557 Make_Pragma_Argument_Association
(Sloc
(Comp_Assn
),
3558 Chars
=> Chars
(First
(Choices
(Comp_Assn
))),
3560 Relocate_Node
(Expression
(Comp_Assn
))));
3564 -- Build the test-case pragma
3567 (Pragma_Argument_Associations
=> Args
,
3568 Pragma_Name
=> Nam
);
3573 when Aspect_Contract_Cases
=>
3575 (Pragma_Argument_Associations
=> New_List
(
3576 Make_Pragma_Argument_Association
(Loc
,
3577 Expression
=> Relocate_Node
(Expr
))),
3578 Pragma_Name
=> Nam
);
3580 Decorate
(Aspect
, Aitem
);
3581 Insert_Pragma
(Aitem
);
3584 -- Case 5: Special handling for aspects with an optional
3585 -- boolean argument.
3587 -- In the delayed case, the corresponding pragma cannot be
3588 -- generated yet because the evaluation of the boolean needs
3589 -- to be delayed till the freeze point.
3591 when Boolean_Aspects
3592 | Library_Unit_Aspects
3594 Set_Is_Boolean_Aspect
(Aspect
);
3596 -- Lock_Free aspect only apply to protected objects
3598 if A_Id
= Aspect_Lock_Free
then
3599 if Ekind
(E
) /= E_Protected_Type
then
3600 Error_Msg_Name_1
:= Nam
;
3602 ("aspect % only applies to a protected object",
3606 -- Set the Uses_Lock_Free flag to True if there is no
3607 -- expression or if the expression is True. The
3608 -- evaluation of this aspect should be delayed to the
3609 -- freeze point (why???)
3612 or else Is_True
(Static_Boolean
(Expr
))
3614 Set_Uses_Lock_Free
(E
);
3617 Record_Rep_Item
(E
, Aspect
);
3622 elsif A_Id
= Aspect_Export
or else A_Id
= Aspect_Import
then
3623 Analyze_Aspect_Export_Import
;
3625 -- Disable_Controlled
3627 elsif A_Id
= Aspect_Disable_Controlled
then
3628 Analyze_Aspect_Disable_Controlled
;
3632 -- Library unit aspects require special handling in the case
3633 -- of a package declaration, the pragma needs to be inserted
3634 -- in the list of declarations for the associated package.
3635 -- There is no issue of visibility delay for these aspects.
3637 if A_Id
in Library_Unit_Aspects
3639 Nkind_In
(N
, N_Package_Declaration
,
3640 N_Generic_Package_Declaration
)
3641 and then Nkind
(Parent
(N
)) /= N_Compilation_Unit
3643 -- Aspect is legal on a local instantiation of a library-
3644 -- level generic unit.
3646 and then not Is_Generic_Instance
(Defining_Entity
(N
))
3649 ("incorrect context for library unit aspect&", Id
);
3653 -- Cases where we do not delay, includes all cases where the
3654 -- expression is missing other than the above cases.
3656 if not Delay_Required
or else No
(Expr
) then
3658 -- Exclude aspects Export and Import because their pragma
3659 -- syntax does not map directly to a Boolean aspect.
3661 if A_Id
/= Aspect_Export
3662 and then A_Id
/= Aspect_Import
3665 (Pragma_Argument_Associations
=> New_List
(
3666 Make_Pragma_Argument_Association
(Sloc
(Ent
),
3667 Expression
=> Ent
)),
3668 Pragma_Name
=> Chars
(Id
));
3671 Delay_Required
:= False;
3673 -- In general cases, the corresponding pragma/attribute
3674 -- definition clause will be inserted later at the freezing
3675 -- point, and we do not need to build it now.
3683 -- This is special because for access types we need to generate
3684 -- an attribute definition clause. This also works for single
3685 -- task declarations, but it does not work for task type
3686 -- declarations, because we have the case where the expression
3687 -- references a discriminant of the task type. That can't use
3688 -- an attribute definition clause because we would not have
3689 -- visibility on the discriminant. For that case we must
3690 -- generate a pragma in the task definition.
3692 when Aspect_Storage_Size
=>
3696 if Ekind
(E
) = E_Task_Type
then
3698 Decl
: constant Node_Id
:= Declaration_Node
(E
);
3701 pragma Assert
(Nkind
(Decl
) = N_Task_Type_Declaration
);
3703 -- If no task definition, create one
3705 if No
(Task_Definition
(Decl
)) then
3706 Set_Task_Definition
(Decl
,
3707 Make_Task_Definition
(Loc
,
3708 Visible_Declarations
=> Empty_List
,
3709 End_Label
=> Empty
));
3712 -- Create a pragma and put it at the start of the task
3713 -- definition for the task type declaration.
3716 (Pragma_Argument_Associations
=> New_List
(
3717 Make_Pragma_Argument_Association
(Loc
,
3718 Expression
=> Relocate_Node
(Expr
))),
3719 Pragma_Name
=> Name_Storage_Size
);
3723 Visible_Declarations
(Task_Definition
(Decl
)));
3727 -- All other cases, generate attribute definition
3731 Make_Attribute_Definition_Clause
(Loc
,
3733 Chars
=> Chars
(Id
),
3734 Expression
=> Relocate_Node
(Expr
));
3738 -- Attach the corresponding pragma/attribute definition clause to
3739 -- the aspect specification node.
3741 if Present
(Aitem
) then
3742 Set_From_Aspect_Specification
(Aitem
);
3745 -- In the context of a compilation unit, we directly put the
3746 -- pragma in the Pragmas_After list of the N_Compilation_Unit_Aux
3747 -- node (no delay is required here) except for aspects on a
3748 -- subprogram body (see below) and a generic package, for which we
3749 -- need to introduce the pragma before building the generic copy
3750 -- (see sem_ch12), and for package instantiations, where the
3751 -- library unit pragmas are better handled early.
3753 if Nkind
(Parent
(N
)) = N_Compilation_Unit
3754 and then (Present
(Aitem
) or else Is_Boolean_Aspect
(Aspect
))
3757 Aux
: constant Node_Id
:= Aux_Decls_Node
(Parent
(N
));
3760 pragma Assert
(Nkind
(Aux
) = N_Compilation_Unit_Aux
);
3762 -- For a Boolean aspect, create the corresponding pragma if
3763 -- no expression or if the value is True.
3765 if Is_Boolean_Aspect
(Aspect
) and then No
(Aitem
) then
3766 if Is_True
(Static_Boolean
(Expr
)) then
3768 (Pragma_Argument_Associations
=> New_List
(
3769 Make_Pragma_Argument_Association
(Sloc
(Ent
),
3770 Expression
=> Ent
)),
3771 Pragma_Name
=> Chars
(Id
));
3773 Set_From_Aspect_Specification
(Aitem
, True);
3774 Set_Corresponding_Aspect
(Aitem
, Aspect
);
3781 -- If the aspect is on a subprogram body (relevant aspect
3782 -- is Inline), add the pragma in front of the declarations.
3784 if Nkind
(N
) = N_Subprogram_Body
then
3785 if No
(Declarations
(N
)) then
3786 Set_Declarations
(N
, New_List
);
3789 Prepend
(Aitem
, Declarations
(N
));
3791 elsif Nkind
(N
) = N_Generic_Package_Declaration
then
3792 if No
(Visible_Declarations
(Specification
(N
))) then
3793 Set_Visible_Declarations
(Specification
(N
), New_List
);
3797 Visible_Declarations
(Specification
(N
)));
3799 elsif Nkind
(N
) = N_Package_Instantiation
then
3801 Spec
: constant Node_Id
:=
3802 Specification
(Instance_Spec
(N
));
3804 if No
(Visible_Declarations
(Spec
)) then
3805 Set_Visible_Declarations
(Spec
, New_List
);
3808 Prepend
(Aitem
, Visible_Declarations
(Spec
));
3812 if No
(Pragmas_After
(Aux
)) then
3813 Set_Pragmas_After
(Aux
, New_List
);
3816 Append
(Aitem
, Pragmas_After
(Aux
));
3823 -- The evaluation of the aspect is delayed to the freezing point.
3824 -- The pragma or attribute clause if there is one is then attached
3825 -- to the aspect specification which is put in the rep item list.
3827 if Delay_Required
then
3828 if Present
(Aitem
) then
3829 Set_Is_Delayed_Aspect
(Aitem
);
3830 Set_Aspect_Rep_Item
(Aspect
, Aitem
);
3831 Set_Parent
(Aitem
, Aspect
);
3834 Set_Is_Delayed_Aspect
(Aspect
);
3836 -- In the case of Default_Value, link the aspect to base type
3837 -- as well, even though it appears on a first subtype. This is
3838 -- mandated by the semantics of the aspect. Do not establish
3839 -- the link when processing the base type itself as this leads
3840 -- to a rep item circularity. Verify that we are dealing with
3841 -- a scalar type to prevent cascaded errors.
3843 if A_Id
= Aspect_Default_Value
3844 and then Is_Scalar_Type
(E
)
3845 and then Base_Type
(E
) /= E
3847 Set_Has_Delayed_Aspects
(Base_Type
(E
));
3848 Record_Rep_Item
(Base_Type
(E
), Aspect
);
3851 Set_Has_Delayed_Aspects
(E
);
3852 Record_Rep_Item
(E
, Aspect
);
3854 -- When delay is not required and the context is a package or a
3855 -- subprogram body, insert the pragma in the body declarations.
3857 elsif Nkind_In
(N
, N_Package_Body
, N_Subprogram_Body
) then
3858 if No
(Declarations
(N
)) then
3859 Set_Declarations
(N
, New_List
);
3862 -- The pragma is added before source declarations
3864 Prepend_To
(Declarations
(N
), Aitem
);
3866 -- When delay is not required and the context is not a compilation
3867 -- unit, we simply insert the pragma/attribute definition clause
3870 elsif Present
(Aitem
) then
3871 Insert_After
(Ins_Node
, Aitem
);
3874 end Analyze_One_Aspect
;
3878 end loop Aspect_Loop
;
3880 if Has_Delayed_Aspects
(E
) then
3881 Ensure_Freeze_Node
(E
);
3883 end Analyze_Aspect_Specifications
;
3885 ------------------------------------------------
3886 -- Analyze_Aspects_On_Subprogram_Body_Or_Stub --
3887 ------------------------------------------------
3889 procedure Analyze_Aspects_On_Subprogram_Body_Or_Stub
(N
: Node_Id
) is
3890 Body_Id
: constant Entity_Id
:= Defining_Entity
(N
);
3892 procedure Diagnose_Misplaced_Aspects
(Spec_Id
: Entity_Id
);
3893 -- Body [stub] N has aspects, but they are not properly placed. Emit an
3894 -- error message depending on the aspects involved. Spec_Id denotes the
3895 -- entity of the corresponding spec.
3897 --------------------------------
3898 -- Diagnose_Misplaced_Aspects --
3899 --------------------------------
3901 procedure Diagnose_Misplaced_Aspects
(Spec_Id
: Entity_Id
) is
3902 procedure Misplaced_Aspect_Error
3905 -- Emit an error message concerning misplaced aspect Asp. Ref_Nam is
3906 -- the name of the refined version of the aspect.
3908 ----------------------------
3909 -- Misplaced_Aspect_Error --
3910 ----------------------------
3912 procedure Misplaced_Aspect_Error
3916 Asp_Nam
: constant Name_Id
:= Chars
(Identifier
(Asp
));
3917 Asp_Id
: constant Aspect_Id
:= Get_Aspect_Id
(Asp_Nam
);
3920 -- The corresponding spec already contains the aspect in question
3921 -- and the one appearing on the body must be the refined form:
3923 -- procedure P with Global ...;
3924 -- procedure P with Global ... is ... end P;
3928 if Has_Aspect
(Spec_Id
, Asp_Id
) then
3929 Error_Msg_Name_1
:= Asp_Nam
;
3931 -- Subunits cannot carry aspects that apply to a subprogram
3934 if Nkind
(Parent
(N
)) = N_Subunit
then
3935 Error_Msg_N
("aspect % cannot apply to a subunit", Asp
);
3937 -- Otherwise suggest the refined form
3940 Error_Msg_Name_2
:= Ref_Nam
;
3941 Error_Msg_N
("aspect % should be %", Asp
);
3944 -- Otherwise the aspect must appear on the spec, not on the body
3947 -- procedure P with Global ... is ... end P;
3951 ("aspect specification must appear on initial declaration",
3954 end Misplaced_Aspect_Error
;
3961 -- Start of processing for Diagnose_Misplaced_Aspects
3964 -- Iterate over the aspect specifications and emit specific errors
3965 -- where applicable.
3967 Asp
:= First
(Aspect_Specifications
(N
));
3968 while Present
(Asp
) loop
3969 Asp_Nam
:= Chars
(Identifier
(Asp
));
3971 -- Do not emit errors on aspects that can appear on a subprogram
3972 -- body. This scenario occurs when the aspect specification list
3973 -- contains both misplaced and properly placed aspects.
3975 if Aspect_On_Body_Or_Stub_OK
(Get_Aspect_Id
(Asp_Nam
)) then
3978 -- Special diagnostics for SPARK aspects
3980 elsif Asp_Nam
= Name_Depends
then
3981 Misplaced_Aspect_Error
(Asp
, Name_Refined_Depends
);
3983 elsif Asp_Nam
= Name_Global
then
3984 Misplaced_Aspect_Error
(Asp
, Name_Refined_Global
);
3986 elsif Asp_Nam
= Name_Post
then
3987 Misplaced_Aspect_Error
(Asp
, Name_Refined_Post
);
3989 -- Otherwise a language-defined aspect is misplaced
3993 ("aspect specification must appear on initial declaration",
3999 end Diagnose_Misplaced_Aspects
;
4003 Spec_Id
: constant Entity_Id
:= Unique_Defining_Entity
(N
);
4005 -- Start of processing for Analyze_Aspects_On_Subprogram_Body_Or_Stub
4008 -- Language-defined aspects cannot be associated with a subprogram body
4009 -- [stub] if the subprogram has a spec. Certain implementation defined
4010 -- aspects are allowed to break this rule (for all applicable cases, see
4011 -- table Aspects.Aspect_On_Body_Or_Stub_OK).
4013 if Spec_Id
/= Body_Id
and then not Aspects_On_Body_Or_Stub_OK
(N
) then
4014 Diagnose_Misplaced_Aspects
(Spec_Id
);
4016 Analyze_Aspect_Specifications
(N
, Body_Id
);
4018 end Analyze_Aspects_On_Subprogram_Body_Or_Stub
;
4020 -----------------------
4021 -- Analyze_At_Clause --
4022 -----------------------
4024 -- An at clause is replaced by the corresponding Address attribute
4025 -- definition clause that is the preferred approach in Ada 95.
4027 procedure Analyze_At_Clause
(N
: Node_Id
) is
4028 CS
: constant Boolean := Comes_From_Source
(N
);
4031 -- This is an obsolescent feature
4033 Check_Restriction
(No_Obsolescent_Features
, N
);
4035 if Warn_On_Obsolescent_Feature
then
4037 ("?j?at clause is an obsolescent feature (RM J.7(2))", N
);
4039 ("\?j?use address attribute definition clause instead", N
);
4042 -- Rewrite as address clause
4045 Make_Attribute_Definition_Clause
(Sloc
(N
),
4046 Name
=> Identifier
(N
),
4047 Chars
=> Name_Address
,
4048 Expression
=> Expression
(N
)));
4050 -- We preserve Comes_From_Source, since logically the clause still comes
4051 -- from the source program even though it is changed in form.
4053 Set_Comes_From_Source
(N
, CS
);
4055 -- Analyze rewritten clause
4057 Analyze_Attribute_Definition_Clause
(N
);
4058 end Analyze_At_Clause
;
4060 -----------------------------------------
4061 -- Analyze_Attribute_Definition_Clause --
4062 -----------------------------------------
4064 procedure Analyze_Attribute_Definition_Clause
(N
: Node_Id
) is
4065 Loc
: constant Source_Ptr
:= Sloc
(N
);
4066 Nam
: constant Node_Id
:= Name
(N
);
4067 Attr
: constant Name_Id
:= Chars
(N
);
4068 Expr
: constant Node_Id
:= Expression
(N
);
4069 Id
: constant Attribute_Id
:= Get_Attribute_Id
(Attr
);
4072 -- The entity of Nam after it is analyzed. In the case of an incomplete
4073 -- type, this is the underlying type.
4076 -- The underlying entity to which the attribute applies. Generally this
4077 -- is the Underlying_Type of Ent, except in the case where the clause
4078 -- applies to the full view of an incomplete or private type, in which
4079 -- case U_Ent is just a copy of Ent.
4081 FOnly
: Boolean := False;
4082 -- Reset to True for subtype specific attribute (Alignment, Size)
4083 -- and for stream attributes, i.e. those cases where in the call to
4084 -- Rep_Item_Too_Late, FOnly is set True so that only the freezing rules
4085 -- are checked. Note that the case of stream attributes is not clear
4086 -- from the RM, but see AI95-00137. Also, the RM seems to disallow
4087 -- Storage_Size for derived task types, but that is also clearly
4090 procedure Analyze_Stream_TSS_Definition
(TSS_Nam
: TSS_Name_Type
);
4091 -- Common processing for 'Read, 'Write, 'Input and 'Output attribute
4092 -- definition clauses.
4094 function Duplicate_Clause
return Boolean;
4095 -- This routine checks if the aspect for U_Ent being given by attribute
4096 -- definition clause N is for an aspect that has already been specified,
4097 -- and if so gives an error message. If there is a duplicate, True is
4098 -- returned, otherwise if there is no error, False is returned.
4100 procedure Check_Indexing_Functions
;
4101 -- Check that the function in Constant_Indexing or Variable_Indexing
4102 -- attribute has the proper type structure. If the name is overloaded,
4103 -- check that some interpretation is legal.
4105 procedure Check_Iterator_Functions
;
4106 -- Check that there is a single function in Default_Iterator attribute
4107 -- that has the proper type structure.
4109 function Check_Primitive_Function
(Subp
: Entity_Id
) return Boolean;
4110 -- Common legality check for the previous two
4112 -----------------------------------
4113 -- Analyze_Stream_TSS_Definition --
4114 -----------------------------------
4116 procedure Analyze_Stream_TSS_Definition
(TSS_Nam
: TSS_Name_Type
) is
4117 Subp
: Entity_Id
:= Empty
;
4122 Is_Read
: constant Boolean := (TSS_Nam
= TSS_Stream_Read
);
4123 -- True for Read attribute, False for other attributes
4125 function Has_Good_Profile
4127 Report
: Boolean := False) return Boolean;
4128 -- Return true if the entity is a subprogram with an appropriate
4129 -- profile for the attribute being defined. If result is False and
4130 -- Report is True, function emits appropriate error.
4132 ----------------------
4133 -- Has_Good_Profile --
4134 ----------------------
4136 function Has_Good_Profile
4138 Report
: Boolean := False) return Boolean
4140 Expected_Ekind
: constant array (Boolean) of Entity_Kind
:=
4141 (False => E_Procedure
, True => E_Function
);
4142 Is_Function
: constant Boolean := (TSS_Nam
= TSS_Stream_Input
);
4147 if Ekind
(Subp
) /= Expected_Ekind
(Is_Function
) then
4151 F
:= First_Formal
(Subp
);
4154 or else Ekind
(Etype
(F
)) /= E_Anonymous_Access_Type
4155 or else Designated_Type
(Etype
(F
)) /=
4156 Class_Wide_Type
(RTE
(RE_Root_Stream_Type
))
4161 if not Is_Function
then
4165 Expected_Mode
: constant array (Boolean) of Entity_Kind
:=
4166 (False => E_In_Parameter
,
4167 True => E_Out_Parameter
);
4169 if Parameter_Mode
(F
) /= Expected_Mode
(Is_Read
) then
4176 -- If the attribute specification comes from an aspect
4177 -- specification for a class-wide stream, the parameter must be
4178 -- a class-wide type of the entity to which the aspect applies.
4180 if From_Aspect_Specification
(N
)
4181 and then Class_Present
(Parent
(N
))
4182 and then Is_Class_Wide_Type
(Typ
)
4188 Typ
:= Etype
(Subp
);
4191 -- Verify that the prefix of the attribute and the local name for
4192 -- the type of the formal match, or one is the class-wide of the
4193 -- other, in the case of a class-wide stream operation.
4195 if Base_Type
(Typ
) = Base_Type
(Ent
)
4196 or else (Is_Class_Wide_Type
(Typ
)
4197 and then Typ
= Class_Wide_Type
(Base_Type
(Ent
)))
4198 or else (Is_Class_Wide_Type
(Ent
)
4199 and then Ent
= Class_Wide_Type
(Base_Type
(Typ
)))
4206 if Present
(Next_Formal
(F
)) then
4209 elsif not Is_Scalar_Type
(Typ
)
4210 and then not Is_First_Subtype
(Typ
)
4211 and then not Is_Class_Wide_Type
(Typ
)
4213 if Report
and not Is_First_Subtype
(Typ
) then
4215 ("subtype of formal in stream operation must be a first "
4216 & "subtype", Parameter_Type
(Parent
(F
)));
4224 end Has_Good_Profile
;
4226 -- Start of processing for Analyze_Stream_TSS_Definition
4231 if not Is_Type
(U_Ent
) then
4232 Error_Msg_N
("local name must be a subtype", Nam
);
4235 elsif not Is_First_Subtype
(U_Ent
) then
4236 Error_Msg_N
("local name must be a first subtype", Nam
);
4240 Pnam
:= TSS
(Base_Type
(U_Ent
), TSS_Nam
);
4242 -- If Pnam is present, it can be either inherited from an ancestor
4243 -- type (in which case it is legal to redefine it for this type), or
4244 -- be a previous definition of the attribute for the same type (in
4245 -- which case it is illegal).
4247 -- In the first case, it will have been analyzed already, and we
4248 -- can check that its profile does not match the expected profile
4249 -- for a stream attribute of U_Ent. In the second case, either Pnam
4250 -- has been analyzed (and has the expected profile), or it has not
4251 -- been analyzed yet (case of a type that has not been frozen yet
4252 -- and for which the stream attribute has been set using Set_TSS).
4255 and then (No
(First_Entity
(Pnam
)) or else Has_Good_Profile
(Pnam
))
4257 Error_Msg_Sloc
:= Sloc
(Pnam
);
4258 Error_Msg_Name_1
:= Attr
;
4259 Error_Msg_N
("% attribute already defined #", Nam
);
4265 if Is_Entity_Name
(Expr
) then
4266 if not Is_Overloaded
(Expr
) then
4267 if Has_Good_Profile
(Entity
(Expr
), Report
=> True) then
4268 Subp
:= Entity
(Expr
);
4272 Get_First_Interp
(Expr
, I
, It
);
4273 while Present
(It
.Nam
) loop
4274 if Has_Good_Profile
(It
.Nam
) then
4279 Get_Next_Interp
(I
, It
);
4284 if Present
(Subp
) then
4285 if Is_Abstract_Subprogram
(Subp
) then
4286 Error_Msg_N
("stream subprogram must not be abstract", Expr
);
4289 -- A stream subprogram for an interface type must be a null
4290 -- procedure (RM 13.13.2 (38/3)). Note that the class-wide type
4291 -- of an interface is not an interface type (3.9.4 (6.b/2)).
4293 elsif Is_Interface
(U_Ent
)
4294 and then not Is_Class_Wide_Type
(U_Ent
)
4295 and then not Inside_A_Generic
4297 (Ekind
(Subp
) = E_Function
4301 (Unit_Declaration_Node
(Ultimate_Alias
(Subp
)))))
4304 ("stream subprogram for interface type must be null "
4305 & "procedure", Expr
);
4308 Set_Entity
(Expr
, Subp
);
4309 Set_Etype
(Expr
, Etype
(Subp
));
4311 New_Stream_Subprogram
(N
, U_Ent
, Subp
, TSS_Nam
);
4314 Error_Msg_Name_1
:= Attr
;
4315 Error_Msg_N
("incorrect expression for% attribute", Expr
);
4317 end Analyze_Stream_TSS_Definition
;
4319 ------------------------------
4320 -- Check_Indexing_Functions --
4321 ------------------------------
4323 procedure Check_Indexing_Functions
is
4324 Indexing_Found
: Boolean := False;
4326 procedure Check_Inherited_Indexing
;
4327 -- For a derived type, check that no indexing aspect is specified
4328 -- for the type if it is also inherited
4330 procedure Check_One_Function
(Subp
: Entity_Id
);
4331 -- Check one possible interpretation. Sets Indexing_Found True if a
4332 -- legal indexing function is found.
4334 procedure Illegal_Indexing
(Msg
: String);
4335 -- Diagnose illegal indexing function if not overloaded. In the
4336 -- overloaded case indicate that no legal interpretation exists.
4338 ------------------------------
4339 -- Check_Inherited_Indexing --
4340 ------------------------------
4342 procedure Check_Inherited_Indexing
is
4343 Inherited
: Node_Id
;
4346 if Attr
= Name_Constant_Indexing
then
4348 Find_Aspect
(Etype
(Ent
), Aspect_Constant_Indexing
);
4349 else pragma Assert
(Attr
= Name_Variable_Indexing
);
4351 Find_Aspect
(Etype
(Ent
), Aspect_Variable_Indexing
);
4354 if Present
(Inherited
) then
4355 if Debug_Flag_Dot_XX
then
4358 -- OK if current attribute_definition_clause is expansion of
4359 -- inherited aspect.
4361 elsif Aspect_Rep_Item
(Inherited
) = N
then
4364 -- Indicate the operation that must be overridden, rather than
4365 -- redefining the indexing aspect.
4369 ("indexing function already inherited from parent type");
4371 ("!override & instead",
4372 N
, Entity
(Expression
(Inherited
)));
4375 end Check_Inherited_Indexing
;
4377 ------------------------
4378 -- Check_One_Function --
4379 ------------------------
4381 procedure Check_One_Function
(Subp
: Entity_Id
) is
4382 Default_Element
: Node_Id
;
4383 Ret_Type
: constant Entity_Id
:= Etype
(Subp
);
4386 if not Is_Overloadable
(Subp
) then
4387 Illegal_Indexing
("illegal indexing function for type&");
4390 elsif Scope
(Subp
) /= Scope
(Ent
) then
4391 if Nkind
(Expr
) = N_Expanded_Name
then
4393 -- Indexing function can't be declared elsewhere
4396 ("indexing function must be declared in scope of type&");
4401 elsif No
(First_Formal
(Subp
)) then
4403 ("Indexing requires a function that applies to type&");
4406 elsif No
(Next_Formal
(First_Formal
(Subp
))) then
4408 ("indexing function must have at least two parameters");
4411 elsif Is_Derived_Type
(Ent
) then
4412 Check_Inherited_Indexing
;
4415 if not Check_Primitive_Function
(Subp
) then
4417 ("Indexing aspect requires a function that applies to type&");
4421 -- If partial declaration exists, verify that it is not tagged.
4423 if Ekind
(Current_Scope
) = E_Package
4424 and then Has_Private_Declaration
(Ent
)
4425 and then From_Aspect_Specification
(N
)
4427 List_Containing
(Parent
(Ent
)) =
4428 Private_Declarations
4429 (Specification
(Unit_Declaration_Node
(Current_Scope
)))
4430 and then Nkind
(N
) = N_Attribute_Definition_Clause
4437 First
(Visible_Declarations
4439 (Unit_Declaration_Node
(Current_Scope
))));
4441 while Present
(Decl
) loop
4442 if Nkind
(Decl
) = N_Private_Type_Declaration
4443 and then Ent
= Full_View
(Defining_Identifier
(Decl
))
4444 and then Tagged_Present
(Decl
)
4445 and then No
(Aspect_Specifications
(Decl
))
4448 ("Indexing aspect cannot be specified on full view "
4449 & "if partial view is tagged");
4458 -- An indexing function must return either the default element of
4459 -- the container, or a reference type. For variable indexing it
4460 -- must be the latter.
4463 Find_Value_Of_Aspect
4464 (Etype
(First_Formal
(Subp
)), Aspect_Iterator_Element
);
4466 if Present
(Default_Element
) then
4467 Analyze
(Default_Element
);
4470 -- For variable_indexing the return type must be a reference type
4472 if Attr
= Name_Variable_Indexing
then
4473 if not Has_Implicit_Dereference
(Ret_Type
) then
4475 ("variable indexing must return a reference type");
4478 elsif Is_Access_Constant
4479 (Etype
(First_Discriminant
(Ret_Type
)))
4482 ("variable indexing must return an access to variable");
4487 if Has_Implicit_Dereference
(Ret_Type
)
4489 Is_Access_Constant
(Etype
(First_Discriminant
(Ret_Type
)))
4492 ("constant indexing must return an access to constant");
4495 elsif Is_Access_Type
(Etype
(First_Formal
(Subp
)))
4496 and then not Is_Access_Constant
(Etype
(First_Formal
(Subp
)))
4499 ("constant indexing must apply to an access to constant");
4504 -- All checks succeeded.
4506 Indexing_Found
:= True;
4507 end Check_One_Function
;
4509 -----------------------
4510 -- Illegal_Indexing --
4511 -----------------------
4513 procedure Illegal_Indexing
(Msg
: String) is
4515 Error_Msg_NE
(Msg
, N
, Ent
);
4516 end Illegal_Indexing
;
4518 -- Start of processing for Check_Indexing_Functions
4522 Check_Inherited_Indexing
;
4527 if not Is_Overloaded
(Expr
) then
4528 Check_One_Function
(Entity
(Expr
));
4536 Indexing_Found
:= False;
4537 Get_First_Interp
(Expr
, I
, It
);
4538 while Present
(It
.Nam
) loop
4540 -- Note that analysis will have added the interpretation
4541 -- that corresponds to the dereference. We only check the
4542 -- subprogram itself. Ignore homonyms that may come from
4543 -- derived types in the context.
4545 if Is_Overloadable
(It
.Nam
)
4546 and then Comes_From_Source
(It
.Nam
)
4548 Check_One_Function
(It
.Nam
);
4551 Get_Next_Interp
(I
, It
);
4556 if not Indexing_Found
and then not Error_Posted
(N
) then
4558 ("aspect Indexing requires a local function that applies to "
4559 & "type&", Expr
, Ent
);
4561 end Check_Indexing_Functions
;
4563 ------------------------------
4564 -- Check_Iterator_Functions --
4565 ------------------------------
4567 procedure Check_Iterator_Functions
is
4568 function Valid_Default_Iterator
(Subp
: Entity_Id
) return Boolean;
4569 -- Check one possible interpretation for validity
4571 ----------------------------
4572 -- Valid_Default_Iterator --
4573 ----------------------------
4575 function Valid_Default_Iterator
(Subp
: Entity_Id
) return Boolean is
4576 Root_T
: constant Entity_Id
:= Root_Type
(Etype
(Etype
(Subp
)));
4580 if not Check_Primitive_Function
(Subp
) then
4583 -- The return type must be derived from a type in an instance
4584 -- of Iterator.Interfaces, and thus its root type must have a
4587 elsif Chars
(Root_T
) /= Name_Forward_Iterator
4588 and then Chars
(Root_T
) /= Name_Reversible_Iterator
4593 Formal
:= First_Formal
(Subp
);
4596 -- False if any subsequent formal has no default expression
4598 Formal
:= Next_Formal
(Formal
);
4599 while Present
(Formal
) loop
4600 if No
(Expression
(Parent
(Formal
))) then
4604 Next_Formal
(Formal
);
4607 -- True if all subsequent formals have default expressions
4610 end Valid_Default_Iterator
;
4612 -- Start of processing for Check_Iterator_Functions
4617 if not Is_Entity_Name
(Expr
) then
4618 Error_Msg_N
("aspect Iterator must be a function name", Expr
);
4621 if not Is_Overloaded
(Expr
) then
4622 if not Check_Primitive_Function
(Entity
(Expr
)) then
4624 ("aspect Indexing requires a function that applies to type&",
4625 Entity
(Expr
), Ent
);
4628 -- Flag the default_iterator as well as the denoted function.
4630 if not Valid_Default_Iterator
(Entity
(Expr
)) then
4631 Error_Msg_N
("improper function for default iterator!", Expr
);
4636 Default
: Entity_Id
:= Empty
;
4641 Get_First_Interp
(Expr
, I
, It
);
4642 while Present
(It
.Nam
) loop
4643 if not Check_Primitive_Function
(It
.Nam
)
4644 or else not Valid_Default_Iterator
(It
.Nam
)
4648 elsif Present
(Default
) then
4650 -- An explicit one should override an implicit one
4652 if Comes_From_Source
(Default
) =
4653 Comes_From_Source
(It
.Nam
)
4655 Error_Msg_N
("default iterator must be unique", Expr
);
4656 Error_Msg_Sloc
:= Sloc
(Default
);
4657 Error_Msg_N
("\\possible interpretation#", Expr
);
4658 Error_Msg_Sloc
:= Sloc
(It
.Nam
);
4659 Error_Msg_N
("\\possible interpretation#", Expr
);
4661 elsif Comes_From_Source
(It
.Nam
) then
4668 Get_Next_Interp
(I
, It
);
4671 if Present
(Default
) then
4672 Set_Entity
(Expr
, Default
);
4673 Set_Is_Overloaded
(Expr
, False);
4676 ("no interpretation is a valid default iterator!", Expr
);
4680 end Check_Iterator_Functions
;
4682 -------------------------------
4683 -- Check_Primitive_Function --
4684 -------------------------------
4686 function Check_Primitive_Function
(Subp
: Entity_Id
) return Boolean is
4690 if Ekind
(Subp
) /= E_Function
then
4694 if No
(First_Formal
(Subp
)) then
4697 Ctrl
:= Etype
(First_Formal
(Subp
));
4700 -- To be a primitive operation subprogram has to be in same scope.
4702 if Scope
(Ctrl
) /= Scope
(Subp
) then
4706 -- Type of formal may be the class-wide type, an access to such,
4707 -- or an incomplete view.
4710 or else Ctrl
= Class_Wide_Type
(Ent
)
4712 (Ekind
(Ctrl
) = E_Anonymous_Access_Type
4713 and then (Designated_Type
(Ctrl
) = Ent
4715 Designated_Type
(Ctrl
) = Class_Wide_Type
(Ent
)))
4717 (Ekind
(Ctrl
) = E_Incomplete_Type
4718 and then Full_View
(Ctrl
) = Ent
)
4726 end Check_Primitive_Function
;
4728 ----------------------
4729 -- Duplicate_Clause --
4730 ----------------------
4732 function Duplicate_Clause
return Boolean is
4736 -- Nothing to do if this attribute definition clause comes from
4737 -- an aspect specification, since we could not be duplicating an
4738 -- explicit clause, and we dealt with the case of duplicated aspects
4739 -- in Analyze_Aspect_Specifications.
4741 if From_Aspect_Specification
(N
) then
4745 -- Otherwise current clause may duplicate previous clause, or a
4746 -- previously given pragma or aspect specification for the same
4749 A
:= Get_Rep_Item
(U_Ent
, Chars
(N
), Check_Parents
=> False);
4752 Error_Msg_Name_1
:= Chars
(N
);
4753 Error_Msg_Sloc
:= Sloc
(A
);
4755 Error_Msg_NE
("aspect% for & previously given#", N
, U_Ent
);
4760 end Duplicate_Clause
;
4762 -- Start of processing for Analyze_Attribute_Definition_Clause
4765 -- The following code is a defense against recursion. Not clear that
4766 -- this can happen legitimately, but perhaps some error situations can
4767 -- cause it, and we did see this recursion during testing.
4769 if Analyzed
(N
) then
4772 Set_Analyzed
(N
, True);
4775 Check_Restriction_No_Use_Of_Attribute
(N
);
4777 -- Ignore some selected attributes in CodePeer mode since they are not
4778 -- relevant in this context.
4780 if CodePeer_Mode
then
4783 -- Ignore Component_Size in CodePeer mode, to avoid changing the
4784 -- internal representation of types by implicitly packing them.
4786 when Attribute_Component_Size
=>
4787 Rewrite
(N
, Make_Null_Statement
(Sloc
(N
)));
4795 -- Process Ignore_Rep_Clauses option
4797 if Ignore_Rep_Clauses
then
4800 -- The following should be ignored. They do not affect legality
4801 -- and may be target dependent. The basic idea of -gnatI is to
4802 -- ignore any rep clauses that may be target dependent but do not
4803 -- affect legality (except possibly to be rejected because they
4804 -- are incompatible with the compilation target).
4806 when Attribute_Alignment
4807 | Attribute_Bit_Order
4808 | Attribute_Component_Size
4809 | Attribute_Default_Scalar_Storage_Order
4810 | Attribute_Machine_Radix
4811 | Attribute_Object_Size
4812 | Attribute_Scalar_Storage_Order
4815 | Attribute_Stream_Size
4816 | Attribute_Value_Size
4818 Kill_Rep_Clause
(N
);
4821 -- The following should not be ignored, because in the first place
4822 -- they are reasonably portable, and should not cause problems
4823 -- in compiling code from another target, and also they do affect
4824 -- legality, e.g. failing to provide a stream attribute for a type
4825 -- may make a program illegal.
4827 when Attribute_External_Tag
4831 | Attribute_Simple_Storage_Pool
4832 | Attribute_Storage_Pool
4833 | Attribute_Storage_Size
4838 -- We do not do anything here with address clauses, they will be
4839 -- removed by Freeze later on, but for now, it works better to
4840 -- keep them in the tree.
4842 when Attribute_Address
=>
4845 -- Other cases are errors ("attribute& cannot be set with
4846 -- definition clause"), which will be caught below.
4854 Ent
:= Entity
(Nam
);
4856 if Rep_Item_Too_Early
(Ent
, N
) then
4860 -- Rep clause applies to full view of incomplete type or private type if
4861 -- we have one (if not, this is a premature use of the type). However,
4862 -- certain semantic checks need to be done on the specified entity (i.e.
4863 -- the private view), so we save it in Ent.
4865 if Is_Private_Type
(Ent
)
4866 and then Is_Derived_Type
(Ent
)
4867 and then not Is_Tagged_Type
(Ent
)
4868 and then No
(Full_View
(Ent
))
4870 -- If this is a private type whose completion is a derivation from
4871 -- another private type, there is no full view, and the attribute
4872 -- belongs to the type itself, not its underlying parent.
4876 elsif Ekind
(Ent
) = E_Incomplete_Type
then
4878 -- The attribute applies to the full view, set the entity of the
4879 -- attribute definition accordingly.
4881 Ent
:= Underlying_Type
(Ent
);
4883 Set_Entity
(Nam
, Ent
);
4886 U_Ent
:= Underlying_Type
(Ent
);
4889 -- Avoid cascaded error
4891 if Etype
(Nam
) = Any_Type
then
4894 -- Must be declared in current scope or in case of an aspect
4895 -- specification, must be visible in current scope.
4897 elsif Scope
(Ent
) /= Current_Scope
4899 not (From_Aspect_Specification
(N
)
4900 and then Scope_Within_Or_Same
(Current_Scope
, Scope
(Ent
)))
4902 Error_Msg_N
("entity must be declared in this scope", Nam
);
4905 -- Must not be a source renaming (we do have some cases where the
4906 -- expander generates a renaming, and those cases are OK, in such
4907 -- cases any attribute applies to the renamed object as well).
4909 elsif Is_Object
(Ent
)
4910 and then Present
(Renamed_Object
(Ent
))
4912 -- Case of renamed object from source, this is an error
4914 if Comes_From_Source
(Renamed_Object
(Ent
)) then
4915 Get_Name_String
(Chars
(N
));
4916 Error_Msg_Strlen
:= Name_Len
;
4917 Error_Msg_String
(1 .. Name_Len
) := Name_Buffer
(1 .. Name_Len
);
4919 ("~ clause not allowed for a renaming declaration "
4920 & "(RM 13.1(6))", Nam
);
4923 -- For the case of a compiler generated renaming, the attribute
4924 -- definition clause applies to the renamed object created by the
4925 -- expander. The easiest general way to handle this is to create a
4926 -- copy of the attribute definition clause for this object.
4928 elsif Is_Entity_Name
(Renamed_Object
(Ent
)) then
4930 Make_Attribute_Definition_Clause
(Loc
,
4932 New_Occurrence_Of
(Entity
(Renamed_Object
(Ent
)), Loc
),
4934 Expression
=> Duplicate_Subexpr
(Expression
(N
))));
4936 -- If the renamed object is not an entity, it must be a dereference
4937 -- of an unconstrained function call, and we must introduce a new
4938 -- declaration to capture the expression. This is needed in the case
4939 -- of 'Alignment, where the original declaration must be rewritten.
4943 (Nkind
(Renamed_Object
(Ent
)) = N_Explicit_Dereference
);
4947 -- If no underlying entity, use entity itself, applies to some
4948 -- previously detected error cases ???
4950 elsif No
(U_Ent
) then
4953 -- Cannot specify for a subtype (exception Object/Value_Size)
4955 elsif Is_Type
(U_Ent
)
4956 and then not Is_First_Subtype
(U_Ent
)
4957 and then Id
/= Attribute_Object_Size
4958 and then Id
/= Attribute_Value_Size
4959 and then not From_At_Mod
(N
)
4961 Error_Msg_N
("cannot specify attribute for subtype", Nam
);
4965 Set_Entity
(N
, U_Ent
);
4967 -- Switch on particular attribute
4975 -- Address attribute definition clause
4977 when Attribute_Address
=> Address
: begin
4979 -- A little error check, catch for X'Address use X'Address;
4981 if Nkind
(Nam
) = N_Identifier
4982 and then Nkind
(Expr
) = N_Attribute_Reference
4983 and then Attribute_Name
(Expr
) = Name_Address
4984 and then Nkind
(Prefix
(Expr
)) = N_Identifier
4985 and then Chars
(Nam
) = Chars
(Prefix
(Expr
))
4988 ("address for & is self-referencing", Prefix
(Expr
), Ent
);
4992 -- Not that special case, carry on with analysis of expression
4994 Analyze_And_Resolve
(Expr
, RTE
(RE_Address
));
4996 -- Even when ignoring rep clauses we need to indicate that the
4997 -- entity has an address clause and thus it is legal to declare
4998 -- it imported. Freeze will get rid of the address clause later.
4999 -- Also call Set_Address_Taken to indicate that an address clause
5000 -- was present, even if we are about to remove it.
5002 if Ignore_Rep_Clauses
then
5003 Set_Address_Taken
(U_Ent
);
5005 if Ekind_In
(U_Ent
, E_Variable
, E_Constant
) then
5006 Record_Rep_Item
(U_Ent
, N
);
5012 if Duplicate_Clause
then
5015 -- Case of address clause for subprogram
5017 elsif Is_Subprogram
(U_Ent
) then
5018 if Has_Homonym
(U_Ent
) then
5020 ("address clause cannot be given for overloaded "
5021 & "subprogram", Nam
);
5025 -- For subprograms, all address clauses are permitted, and we
5026 -- mark the subprogram as having a deferred freeze so that Gigi
5027 -- will not elaborate it too soon.
5029 -- Above needs more comments, what is too soon about???
5031 Set_Has_Delayed_Freeze
(U_Ent
);
5033 -- Case of address clause for entry
5035 elsif Ekind
(U_Ent
) = E_Entry
then
5036 if Nkind
(Parent
(N
)) = N_Task_Body
then
5038 ("entry address must be specified in task spec", Nam
);
5042 -- For entries, we require a constant address
5044 Check_Constant_Address_Clause
(Expr
, U_Ent
);
5046 -- Special checks for task types
5048 if Is_Task_Type
(Scope
(U_Ent
))
5049 and then Comes_From_Source
(Scope
(U_Ent
))
5052 ("??entry address declared for entry in task type", N
);
5054 ("\??only one task can be declared of this type", N
);
5057 -- Entry address clauses are obsolescent
5059 Check_Restriction
(No_Obsolescent_Features
, N
);
5061 if Warn_On_Obsolescent_Feature
then
5063 ("?j?attaching interrupt to task entry is an obsolescent "
5064 & "feature (RM J.7.1)", N
);
5066 ("\?j?use interrupt procedure instead", N
);
5069 -- Case of an address clause for a class-wide object, which is
5070 -- considered erroneous.
5072 elsif Is_Class_Wide_Type
(Etype
(U_Ent
)) then
5074 ("??class-wide object & must not be overlaid", Nam
, U_Ent
);
5076 ("\??Program_Error will be raised at run time", Nam
);
5077 Insert_Action
(Declaration_Node
(U_Ent
),
5078 Make_Raise_Program_Error
(Loc
,
5079 Reason
=> PE_Overlaid_Controlled_Object
));
5082 -- Case of address clause for an object
5084 elsif Ekind_In
(U_Ent
, E_Constant
, E_Variable
) then
5086 Expr
: constant Node_Id
:= Expression
(N
);
5091 -- Exported variables cannot have an address clause, because
5092 -- this cancels the effect of the pragma Export.
5094 if Is_Exported
(U_Ent
) then
5096 ("cannot export object with address clause", Nam
);
5100 Find_Overlaid_Entity
(N
, O_Ent
, Off
);
5102 if Present
(O_Ent
) then
5104 -- If the object overlays a constant object, mark it so
5106 if Is_Constant_Object
(O_Ent
) then
5107 Set_Overlays_Constant
(U_Ent
);
5110 -- If the address clause is of the form:
5112 -- for X'Address use Y'Address;
5116 -- C : constant Address := Y'Address;
5118 -- for X'Address use C;
5120 -- then we make an entry in the table to check the size
5121 -- and alignment of the overlaying variable. But we defer
5122 -- this check till after code generation to take full
5123 -- advantage of the annotation done by the back end.
5125 -- If the entity has a generic type, the check will be
5126 -- performed in the instance if the actual type justifies
5127 -- it, and we do not insert the clause in the table to
5128 -- prevent spurious warnings.
5130 -- Note: we used to test Comes_From_Source and only give
5131 -- this warning for source entities, but we have removed
5132 -- this test. It really seems bogus to generate overlays
5133 -- that would trigger this warning in generated code.
5134 -- Furthermore, by removing the test, we handle the
5135 -- aspect case properly.
5137 if Is_Object
(O_Ent
)
5138 and then not Is_Generic_Type
(Etype
(U_Ent
))
5139 and then Address_Clause_Overlay_Warnings
5141 Register_Address_Clause_Check
5142 (N
, U_Ent
, No_Uint
, O_Ent
, Off
);
5145 -- If the overlay changes the storage order, mark the
5146 -- entity as being volatile to block any optimization
5147 -- for it since the construct is not really supported
5150 if (Is_Record_Type
(Etype
(U_Ent
))
5151 or else Is_Array_Type
(Etype
(U_Ent
)))
5152 and then (Is_Record_Type
(Etype
(O_Ent
))
5153 or else Is_Array_Type
(Etype
(O_Ent
)))
5154 and then Reverse_Storage_Order
(Etype
(U_Ent
)) /=
5155 Reverse_Storage_Order
(Etype
(O_Ent
))
5157 Set_Treat_As_Volatile
(U_Ent
);
5161 -- If this is not an overlay, mark a variable as being
5162 -- volatile to prevent unwanted optimizations. It's a
5163 -- conservative interpretation of RM 13.3(19) for the
5164 -- cases where the compiler cannot detect potential
5165 -- aliasing issues easily and it also covers the case
5166 -- of an absolute address where the volatile aspect is
5167 -- kind of implicit.
5169 if Ekind
(U_Ent
) = E_Variable
then
5170 Set_Treat_As_Volatile
(U_Ent
);
5173 -- Make an entry in the table for an absolute address as
5174 -- above to check that the value is compatible with the
5175 -- alignment of the object.
5178 Addr
: constant Node_Id
:= Address_Value
(Expr
);
5180 if Compile_Time_Known_Value
(Addr
)
5181 and then Address_Clause_Overlay_Warnings
5183 Register_Address_Clause_Check
5184 (N
, U_Ent
, Expr_Value
(Addr
), Empty
, False);
5189 -- Issue an unconditional warning for a constant overlaying
5190 -- a variable. For the reverse case, we will issue it only
5191 -- if the variable is modified.
5193 if Ekind
(U_Ent
) = E_Constant
5194 and then Present
(O_Ent
)
5195 and then not Overlays_Constant
(U_Ent
)
5196 and then Address_Clause_Overlay_Warnings
5198 Error_Msg_N
("??constant overlays a variable", Expr
);
5200 -- Imported variables can have an address clause, but then
5201 -- the import is pretty meaningless except to suppress
5202 -- initializations, so we do not need such variables to
5203 -- be statically allocated (and in fact it causes trouble
5204 -- if the address clause is a local value).
5206 elsif Is_Imported
(U_Ent
) then
5207 Set_Is_Statically_Allocated
(U_Ent
, False);
5210 -- We mark a possible modification of a variable with an
5211 -- address clause, since it is likely aliasing is occurring.
5213 Note_Possible_Modification
(Nam
, Sure
=> False);
5215 -- Legality checks on the address clause for initialized
5216 -- objects is deferred until the freeze point, because
5217 -- a subsequent pragma might indicate that the object
5218 -- is imported and thus not initialized. Also, the address
5219 -- clause might involve entities that have yet to be
5222 Set_Has_Delayed_Freeze
(U_Ent
);
5224 -- If an initialization call has been generated for this
5225 -- object, it needs to be deferred to after the freeze node
5226 -- we have just now added, otherwise GIGI will see a
5227 -- reference to the variable (as actual to the IP call)
5228 -- before its definition.
5231 Init_Call
: constant Node_Id
:=
5232 Remove_Init_Call
(U_Ent
, N
);
5235 if Present
(Init_Call
) then
5236 Append_Freeze_Action
(U_Ent
, Init_Call
);
5238 -- Reset Initialization_Statements pointer so that
5239 -- if there is a pragma Import further down, it can
5240 -- clear any default initialization.
5242 Set_Initialization_Statements
(U_Ent
, Init_Call
);
5246 -- Entity has delayed freeze, so we will generate an
5247 -- alignment check at the freeze point unless suppressed.
5249 if not Range_Checks_Suppressed
(U_Ent
)
5250 and then not Alignment_Checks_Suppressed
(U_Ent
)
5252 Set_Check_Address_Alignment
(N
);
5255 -- Kill the size check code, since we are not allocating
5256 -- the variable, it is somewhere else.
5258 Kill_Size_Check_Code
(U_Ent
);
5261 -- Not a valid entity for an address clause
5264 Error_Msg_N
("address cannot be given for &", Nam
);
5272 -- Alignment attribute definition clause
5274 when Attribute_Alignment
=> Alignment
: declare
5275 Align
: constant Uint
:= Get_Alignment_Value
(Expr
);
5276 Max_Align
: constant Uint
:= UI_From_Int
(Maximum_Alignment
);
5281 if not Is_Type
(U_Ent
)
5282 and then Ekind
(U_Ent
) /= E_Variable
5283 and then Ekind
(U_Ent
) /= E_Constant
5285 Error_Msg_N
("alignment cannot be given for &", Nam
);
5287 elsif Duplicate_Clause
then
5290 elsif Align
/= No_Uint
then
5291 Set_Has_Alignment_Clause
(U_Ent
);
5293 -- Tagged type case, check for attempt to set alignment to a
5294 -- value greater than Max_Align, and reset if so. This error
5295 -- is suppressed in ASIS mode to allow for different ASIS
5296 -- back ends or ASIS-based tools to query the illegal clause.
5298 if Is_Tagged_Type
(U_Ent
)
5299 and then Align
> Max_Align
5300 and then not ASIS_Mode
5303 ("alignment for & set to Maximum_Aligment??", Nam
);
5304 Set_Alignment
(U_Ent
, Max_Align
);
5309 Set_Alignment
(U_Ent
, Align
);
5312 -- For an array type, U_Ent is the first subtype. In that case,
5313 -- also set the alignment of the anonymous base type so that
5314 -- other subtypes (such as the itypes for aggregates of the
5315 -- type) also receive the expected alignment.
5317 if Is_Array_Type
(U_Ent
) then
5318 Set_Alignment
(Base_Type
(U_Ent
), Align
);
5327 -- Bit_Order attribute definition clause
5329 when Attribute_Bit_Order
=>
5330 if not Is_Record_Type
(U_Ent
) then
5332 ("Bit_Order can only be defined for record type", Nam
);
5334 elsif Is_Tagged_Type
(U_Ent
) and then Is_Derived_Type
(U_Ent
) then
5336 ("Bit_Order cannot be defined for record extensions", Nam
);
5338 elsif Duplicate_Clause
then
5342 Analyze_And_Resolve
(Expr
, RTE
(RE_Bit_Order
));
5344 if Etype
(Expr
) = Any_Type
then
5347 elsif not Is_OK_Static_Expression
(Expr
) then
5348 Flag_Non_Static_Expr
5349 ("Bit_Order requires static expression!", Expr
);
5351 elsif (Expr_Value
(Expr
) = 0) /= Bytes_Big_Endian
then
5352 Set_Reverse_Bit_Order
(Base_Type
(U_Ent
), True);
5356 --------------------
5357 -- Component_Size --
5358 --------------------
5360 -- Component_Size attribute definition clause
5362 when Attribute_Component_Size
=> Component_Size_Case
: declare
5363 Csize
: constant Uint
:= Static_Integer
(Expr
);
5367 New_Ctyp
: Entity_Id
;
5371 if not Is_Array_Type
(U_Ent
) then
5372 Error_Msg_N
("component size requires array type", Nam
);
5376 Btype
:= Base_Type
(U_Ent
);
5377 Ctyp
:= Component_Type
(Btype
);
5379 if Duplicate_Clause
then
5382 elsif Rep_Item_Too_Early
(Btype
, N
) then
5385 elsif Csize
/= No_Uint
then
5386 Check_Size
(Expr
, Ctyp
, Csize
, Biased
);
5388 -- For the biased case, build a declaration for a subtype that
5389 -- will be used to represent the biased subtype that reflects
5390 -- the biased representation of components. We need the subtype
5391 -- to get proper conversions on referencing elements of the
5396 Make_Defining_Identifier
(Loc
,
5398 New_External_Name
(Chars
(U_Ent
), 'C', 0, 'T'));
5401 Make_Subtype_Declaration
(Loc
,
5402 Defining_Identifier
=> New_Ctyp
,
5403 Subtype_Indication
=>
5404 New_Occurrence_Of
(Component_Type
(Btype
), Loc
));
5406 Set_Parent
(Decl
, N
);
5407 Analyze
(Decl
, Suppress
=> All_Checks
);
5409 Set_Has_Delayed_Freeze
(New_Ctyp
, False);
5410 Set_Esize
(New_Ctyp
, Csize
);
5411 Set_RM_Size
(New_Ctyp
, Csize
);
5412 Init_Alignment
(New_Ctyp
);
5413 Set_Is_Itype
(New_Ctyp
, True);
5414 Set_Associated_Node_For_Itype
(New_Ctyp
, U_Ent
);
5416 Set_Component_Type
(Btype
, New_Ctyp
);
5417 Set_Biased
(New_Ctyp
, N
, "component size clause");
5420 Set_Component_Size
(Btype
, Csize
);
5422 -- Deal with warning on overridden size
5424 if Warn_On_Overridden_Size
5425 and then Has_Size_Clause
(Ctyp
)
5426 and then RM_Size
(Ctyp
) /= Csize
5429 ("component size overrides size clause for&?S?", N
, Ctyp
);
5432 Set_Has_Component_Size_Clause
(Btype
, True);
5433 Set_Has_Non_Standard_Rep
(Btype
, True);
5435 end Component_Size_Case
;
5437 -----------------------
5438 -- Constant_Indexing --
5439 -----------------------
5441 when Attribute_Constant_Indexing
=>
5442 Check_Indexing_Functions
;
5448 when Attribute_CPU
=>
5450 -- CPU attribute definition clause not allowed except from aspect
5453 if From_Aspect_Specification
(N
) then
5454 if not Is_Task_Type
(U_Ent
) then
5455 Error_Msg_N
("CPU can only be defined for task", Nam
);
5457 elsif Duplicate_Clause
then
5461 -- The expression must be analyzed in the special manner
5462 -- described in "Handling of Default and Per-Object
5463 -- Expressions" in sem.ads.
5465 -- The visibility to the discriminants must be restored
5467 Push_Scope_And_Install_Discriminants
(U_Ent
);
5468 Preanalyze_Spec_Expression
(Expr
, RTE
(RE_CPU_Range
));
5469 Uninstall_Discriminants_And_Pop_Scope
(U_Ent
);
5471 if not Is_OK_Static_Expression
(Expr
) then
5472 Check_Restriction
(Static_Priorities
, Expr
);
5478 ("attribute& cannot be set with definition clause", N
);
5481 ----------------------
5482 -- Default_Iterator --
5483 ----------------------
5485 when Attribute_Default_Iterator
=> Default_Iterator
: declare
5490 -- If target type is untagged, further checks are irrelevant
5492 if not Is_Tagged_Type
(U_Ent
) then
5494 ("aspect Default_Iterator applies to tagged type", Nam
);
5498 Check_Iterator_Functions
;
5502 if not Is_Entity_Name
(Expr
)
5503 or else Ekind
(Entity
(Expr
)) /= E_Function
5505 Error_Msg_N
("aspect Iterator must be a function", Expr
);
5508 Func
:= Entity
(Expr
);
5511 -- The type of the first parameter must be T, T'class, or a
5512 -- corresponding access type (5.5.1 (8/3). If function is
5513 -- parameterless label type accordingly.
5515 if No
(First_Formal
(Func
)) then
5518 Typ
:= Etype
(First_Formal
(Func
));
5522 or else Typ
= Class_Wide_Type
(U_Ent
)
5523 or else (Is_Access_Type
(Typ
)
5524 and then Designated_Type
(Typ
) = U_Ent
)
5525 or else (Is_Access_Type
(Typ
)
5526 and then Designated_Type
(Typ
) =
5527 Class_Wide_Type
(U_Ent
))
5533 ("Default Iterator must be a primitive of&", Func
, U_Ent
);
5535 end Default_Iterator
;
5537 ------------------------
5538 -- Dispatching_Domain --
5539 ------------------------
5541 when Attribute_Dispatching_Domain
=>
5543 -- Dispatching_Domain attribute definition clause not allowed
5544 -- except from aspect specification.
5546 if From_Aspect_Specification
(N
) then
5547 if not Is_Task_Type
(U_Ent
) then
5549 ("Dispatching_Domain can only be defined for task", Nam
);
5551 elsif Duplicate_Clause
then
5555 -- The expression must be analyzed in the special manner
5556 -- described in "Handling of Default and Per-Object
5557 -- Expressions" in sem.ads.
5559 -- The visibility to the discriminants must be restored
5561 Push_Scope_And_Install_Discriminants
(U_Ent
);
5563 Preanalyze_Spec_Expression
5564 (Expr
, RTE
(RE_Dispatching_Domain
));
5566 Uninstall_Discriminants_And_Pop_Scope
(U_Ent
);
5571 ("attribute& cannot be set with definition clause", N
);
5578 when Attribute_External_Tag
=>
5579 if not Is_Tagged_Type
(U_Ent
) then
5580 Error_Msg_N
("should be a tagged type", Nam
);
5583 if Duplicate_Clause
then
5587 Analyze_And_Resolve
(Expr
, Standard_String
);
5589 if not Is_OK_Static_Expression
(Expr
) then
5590 Flag_Non_Static_Expr
5591 ("static string required for tag name!", Nam
);
5594 if not Is_Library_Level_Entity
(U_Ent
) then
5596 ("??non-unique external tag supplied for &", N
, U_Ent
);
5598 ("\??same external tag applies to all subprogram calls",
5601 ("\??corresponding internal tag cannot be obtained", N
);
5605 --------------------------
5606 -- Implicit_Dereference --
5607 --------------------------
5609 when Attribute_Implicit_Dereference
=>
5611 -- Legality checks already performed at the point of the type
5612 -- declaration, aspect is not delayed.
5620 when Attribute_Input
=>
5621 Analyze_Stream_TSS_Definition
(TSS_Stream_Input
);
5622 Set_Has_Specified_Stream_Input
(Ent
);
5624 ------------------------
5625 -- Interrupt_Priority --
5626 ------------------------
5628 when Attribute_Interrupt_Priority
=>
5630 -- Interrupt_Priority attribute definition clause not allowed
5631 -- except from aspect specification.
5633 if From_Aspect_Specification
(N
) then
5634 if not Is_Concurrent_Type
(U_Ent
) then
5636 ("Interrupt_Priority can only be defined for task and "
5637 & "protected object", Nam
);
5639 elsif Duplicate_Clause
then
5643 -- The expression must be analyzed in the special manner
5644 -- described in "Handling of Default and Per-Object
5645 -- Expressions" in sem.ads.
5647 -- The visibility to the discriminants must be restored
5649 Push_Scope_And_Install_Discriminants
(U_Ent
);
5651 Preanalyze_Spec_Expression
5652 (Expr
, RTE
(RE_Interrupt_Priority
));
5654 Uninstall_Discriminants_And_Pop_Scope
(U_Ent
);
5656 -- Check the No_Task_At_Interrupt_Priority restriction
5658 if Is_Task_Type
(U_Ent
) then
5659 Check_Restriction
(No_Task_At_Interrupt_Priority
, N
);
5665 ("attribute& cannot be set with definition clause", N
);
5672 when Attribute_Iterable
=>
5675 if Nkind
(Expr
) /= N_Aggregate
then
5676 Error_Msg_N
("aspect Iterable must be an aggregate", Expr
);
5683 Assoc
:= First
(Component_Associations
(Expr
));
5684 while Present
(Assoc
) loop
5685 if not Is_Entity_Name
(Expression
(Assoc
)) then
5686 Error_Msg_N
("value must be a function", Assoc
);
5693 ----------------------
5694 -- Iterator_Element --
5695 ----------------------
5697 when Attribute_Iterator_Element
=>
5700 if not Is_Entity_Name
(Expr
)
5701 or else not Is_Type
(Entity
(Expr
))
5703 Error_Msg_N
("aspect Iterator_Element must be a type", Expr
);
5710 -- Machine radix attribute definition clause
5712 when Attribute_Machine_Radix
=> Machine_Radix
: declare
5713 Radix
: constant Uint
:= Static_Integer
(Expr
);
5716 if not Is_Decimal_Fixed_Point_Type
(U_Ent
) then
5717 Error_Msg_N
("decimal fixed-point type expected for &", Nam
);
5719 elsif Duplicate_Clause
then
5722 elsif Radix
/= No_Uint
then
5723 Set_Has_Machine_Radix_Clause
(U_Ent
);
5724 Set_Has_Non_Standard_Rep
(Base_Type
(U_Ent
));
5729 elsif Radix
= 10 then
5730 Set_Machine_Radix_10
(U_Ent
);
5732 -- The following error is suppressed in ASIS mode to allow for
5733 -- different ASIS back ends or ASIS-based tools to query the
5736 elsif not ASIS_Mode
then
5737 Error_Msg_N
("machine radix value must be 2 or 10", Expr
);
5746 -- Object_Size attribute definition clause
5748 when Attribute_Object_Size
=> Object_Size
: declare
5749 Size
: constant Uint
:= Static_Integer
(Expr
);
5752 pragma Warnings
(Off
, Biased
);
5755 if not Is_Type
(U_Ent
) then
5756 Error_Msg_N
("Object_Size cannot be given for &", Nam
);
5758 elsif Duplicate_Clause
then
5762 Check_Size
(Expr
, U_Ent
, Size
, Biased
);
5764 -- The following errors are suppressed in ASIS mode to allow
5765 -- for different ASIS back ends or ASIS-based tools to query
5766 -- the illegal clause.
5771 elsif Is_Scalar_Type
(U_Ent
) then
5772 if Size
/= 8 and then Size
/= 16 and then Size
/= 32
5773 and then UI_Mod
(Size
, 64) /= 0
5776 ("Object_Size must be 8, 16, 32, or multiple of 64",
5780 elsif Size
mod 8 /= 0 then
5781 Error_Msg_N
("Object_Size must be a multiple of 8", Expr
);
5784 Set_Esize
(U_Ent
, Size
);
5785 Set_Has_Object_Size_Clause
(U_Ent
);
5786 Alignment_Check_For_Size_Change
(U_Ent
, Size
);
5794 when Attribute_Output
=>
5795 Analyze_Stream_TSS_Definition
(TSS_Stream_Output
);
5796 Set_Has_Specified_Stream_Output
(Ent
);
5802 when Attribute_Priority
=>
5804 -- Priority attribute definition clause not allowed except from
5805 -- aspect specification.
5807 if From_Aspect_Specification
(N
) then
5808 if not (Is_Concurrent_Type
(U_Ent
)
5809 or else Ekind
(U_Ent
) = E_Procedure
)
5812 ("Priority can only be defined for task and protected "
5815 elsif Duplicate_Clause
then
5819 -- The expression must be analyzed in the special manner
5820 -- described in "Handling of Default and Per-Object
5821 -- Expressions" in sem.ads.
5823 -- The visibility to the discriminants must be restored
5825 Push_Scope_And_Install_Discriminants
(U_Ent
);
5826 Preanalyze_Spec_Expression
(Expr
, Standard_Integer
);
5827 Uninstall_Discriminants_And_Pop_Scope
(U_Ent
);
5829 if not Is_OK_Static_Expression
(Expr
) then
5830 Check_Restriction
(Static_Priorities
, Expr
);
5836 ("attribute& cannot be set with definition clause", N
);
5843 when Attribute_Read
=>
5844 Analyze_Stream_TSS_Definition
(TSS_Stream_Read
);
5845 Set_Has_Specified_Stream_Read
(Ent
);
5847 --------------------------
5848 -- Scalar_Storage_Order --
5849 --------------------------
5851 -- Scalar_Storage_Order attribute definition clause
5853 when Attribute_Scalar_Storage_Order
=>
5854 if not (Is_Record_Type
(U_Ent
) or else Is_Array_Type
(U_Ent
)) then
5856 ("Scalar_Storage_Order can only be defined for record or "
5857 & "array type", Nam
);
5859 elsif Duplicate_Clause
then
5863 Analyze_And_Resolve
(Expr
, RTE
(RE_Bit_Order
));
5865 if Etype
(Expr
) = Any_Type
then
5868 elsif not Is_OK_Static_Expression
(Expr
) then
5869 Flag_Non_Static_Expr
5870 ("Scalar_Storage_Order requires static expression!", Expr
);
5872 elsif (Expr_Value
(Expr
) = 0) /= Bytes_Big_Endian
then
5874 -- Here for the case of a non-default (i.e. non-confirming)
5875 -- Scalar_Storage_Order attribute definition.
5877 if Support_Nondefault_SSO_On_Target
then
5878 Set_Reverse_Storage_Order
(Base_Type
(U_Ent
), True);
5881 ("non-default Scalar_Storage_Order not supported on "
5886 -- Clear SSO default indications since explicit setting of the
5887 -- order overrides the defaults.
5889 Set_SSO_Set_Low_By_Default
(Base_Type
(U_Ent
), False);
5890 Set_SSO_Set_High_By_Default
(Base_Type
(U_Ent
), False);
5897 -- Size attribute definition clause
5899 when Attribute_Size
=> Size
: declare
5900 Size
: constant Uint
:= Static_Integer
(Expr
);
5907 if Duplicate_Clause
then
5910 elsif not Is_Type
(U_Ent
)
5911 and then Ekind
(U_Ent
) /= E_Variable
5912 and then Ekind
(U_Ent
) /= E_Constant
5914 Error_Msg_N
("size cannot be given for &", Nam
);
5916 elsif Is_Array_Type
(U_Ent
)
5917 and then not Is_Constrained
(U_Ent
)
5920 ("size cannot be given for unconstrained array", Nam
);
5922 elsif Size
/= No_Uint
then
5923 if Is_Type
(U_Ent
) then
5926 Etyp
:= Etype
(U_Ent
);
5929 -- Check size, note that Gigi is in charge of checking that the
5930 -- size of an array or record type is OK. Also we do not check
5931 -- the size in the ordinary fixed-point case, since it is too
5932 -- early to do so (there may be subsequent small clause that
5933 -- affects the size). We can check the size if a small clause
5934 -- has already been given.
5936 if not Is_Ordinary_Fixed_Point_Type
(U_Ent
)
5937 or else Has_Small_Clause
(U_Ent
)
5939 Check_Size
(Expr
, Etyp
, Size
, Biased
);
5940 Set_Biased
(U_Ent
, N
, "size clause", Biased
);
5943 -- For types set RM_Size and Esize if possible
5945 if Is_Type
(U_Ent
) then
5946 Set_RM_Size
(U_Ent
, Size
);
5948 -- For elementary types, increase Object_Size to power of 2,
5949 -- but not less than a storage unit in any case (normally
5950 -- this means it will be byte addressable).
5952 -- For all other types, nothing else to do, we leave Esize
5953 -- (object size) unset, the back end will set it from the
5954 -- size and alignment in an appropriate manner.
5956 -- In both cases, we check whether the alignment must be
5957 -- reset in the wake of the size change.
5959 if Is_Elementary_Type
(U_Ent
) then
5960 if Size
<= System_Storage_Unit
then
5961 Init_Esize
(U_Ent
, System_Storage_Unit
);
5962 elsif Size
<= 16 then
5963 Init_Esize
(U_Ent
, 16);
5964 elsif Size
<= 32 then
5965 Init_Esize
(U_Ent
, 32);
5967 Set_Esize
(U_Ent
, (Size
+ 63) / 64 * 64);
5970 Alignment_Check_For_Size_Change
(U_Ent
, Esize
(U_Ent
));
5972 Alignment_Check_For_Size_Change
(U_Ent
, Size
);
5975 -- For objects, set Esize only
5978 -- The following error is suppressed in ASIS mode to allow
5979 -- for different ASIS back ends or ASIS-based tools to query
5980 -- the illegal clause.
5982 if Is_Elementary_Type
(Etyp
)
5983 and then Size
/= System_Storage_Unit
5984 and then Size
/= System_Storage_Unit
* 2
5985 and then Size
/= System_Storage_Unit
* 4
5986 and then Size
/= System_Storage_Unit
* 8
5987 and then not ASIS_Mode
5989 Error_Msg_Uint_1
:= UI_From_Int
(System_Storage_Unit
);
5990 Error_Msg_Uint_2
:= Error_Msg_Uint_1
* 8;
5992 ("size for primitive object must be a power of 2 in "
5993 & "the range ^-^", N
);
5996 Set_Esize
(U_Ent
, Size
);
5999 Set_Has_Size_Clause
(U_Ent
);
6007 -- Small attribute definition clause
6009 when Attribute_Small
=> Small
: declare
6010 Implicit_Base
: constant Entity_Id
:= Base_Type
(U_Ent
);
6014 Analyze_And_Resolve
(Expr
, Any_Real
);
6016 if Etype
(Expr
) = Any_Type
then
6019 elsif not Is_OK_Static_Expression
(Expr
) then
6020 Flag_Non_Static_Expr
6021 ("small requires static expression!", Expr
);
6025 Small
:= Expr_Value_R
(Expr
);
6027 if Small
<= Ureal_0
then
6028 Error_Msg_N
("small value must be greater than zero", Expr
);
6034 if not Is_Ordinary_Fixed_Point_Type
(U_Ent
) then
6036 ("small requires an ordinary fixed point type", Nam
);
6038 elsif Has_Small_Clause
(U_Ent
) then
6039 Error_Msg_N
("small already given for &", Nam
);
6041 elsif Small
> Delta_Value
(U_Ent
) then
6043 ("small value must not be greater than delta value", Nam
);
6046 Set_Small_Value
(U_Ent
, Small
);
6047 Set_Small_Value
(Implicit_Base
, Small
);
6048 Set_Has_Small_Clause
(U_Ent
);
6049 Set_Has_Small_Clause
(Implicit_Base
);
6050 Set_Has_Non_Standard_Rep
(Implicit_Base
);
6058 -- Storage_Pool attribute definition clause
6060 when Attribute_Simple_Storage_Pool
6061 | Attribute_Storage_Pool
6063 Storage_Pool
: declare
6068 if Ekind
(U_Ent
) = E_Access_Subprogram_Type
then
6070 ("storage pool cannot be given for access-to-subprogram type",
6074 elsif not Ekind_In
(U_Ent
, E_Access_Type
, E_General_Access_Type
)
6077 ("storage pool can only be given for access types", Nam
);
6080 elsif Is_Derived_Type
(U_Ent
) then
6082 ("storage pool cannot be given for a derived access type",
6085 elsif Duplicate_Clause
then
6088 elsif Present
(Associated_Storage_Pool
(U_Ent
)) then
6089 Error_Msg_N
("storage pool already given for &", Nam
);
6093 -- Check for Storage_Size previously given
6096 SS
: constant Node_Id
:=
6097 Get_Attribute_Definition_Clause
6098 (U_Ent
, Attribute_Storage_Size
);
6100 if Present
(SS
) then
6101 Check_Pool_Size_Clash
(U_Ent
, N
, SS
);
6105 -- Storage_Pool case
6107 if Id
= Attribute_Storage_Pool
then
6109 (Expr
, Class_Wide_Type
(RTE
(RE_Root_Storage_Pool
)));
6111 -- In the Simple_Storage_Pool case, we allow a variable of any
6112 -- simple storage pool type, so we Resolve without imposing an
6116 Analyze_And_Resolve
(Expr
);
6118 if not Present
(Get_Rep_Pragma
6119 (Etype
(Expr
), Name_Simple_Storage_Pool_Type
))
6122 ("expression must be of a simple storage pool type", Expr
);
6126 if not Denotes_Variable
(Expr
) then
6127 Error_Msg_N
("storage pool must be a variable", Expr
);
6131 if Nkind
(Expr
) = N_Type_Conversion
then
6132 T
:= Etype
(Expression
(Expr
));
6137 -- The Stack_Bounded_Pool is used internally for implementing
6138 -- access types with a Storage_Size. Since it only work properly
6139 -- when used on one specific type, we need to check that it is not
6140 -- hijacked improperly:
6142 -- type T is access Integer;
6143 -- for T'Storage_Size use n;
6144 -- type Q is access Float;
6145 -- for Q'Storage_Size use T'Storage_Size; -- incorrect
6147 if RTE_Available
(RE_Stack_Bounded_Pool
)
6148 and then Base_Type
(T
) = RTE
(RE_Stack_Bounded_Pool
)
6150 Error_Msg_N
("non-shareable internal Pool", Expr
);
6154 -- If the argument is a name that is not an entity name, then
6155 -- we construct a renaming operation to define an entity of
6156 -- type storage pool.
6158 if not Is_Entity_Name
(Expr
)
6159 and then Is_Object_Reference
(Expr
)
6161 Pool
:= Make_Temporary
(Loc
, 'P', Expr
);
6164 Rnode
: constant Node_Id
:=
6165 Make_Object_Renaming_Declaration
(Loc
,
6166 Defining_Identifier
=> Pool
,
6168 New_Occurrence_Of
(Etype
(Expr
), Loc
),
6172 -- If the attribute definition clause comes from an aspect
6173 -- clause, then insert the renaming before the associated
6174 -- entity's declaration, since the attribute clause has
6175 -- not yet been appended to the declaration list.
6177 if From_Aspect_Specification
(N
) then
6178 Insert_Before
(Parent
(Entity
(N
)), Rnode
);
6180 Insert_Before
(N
, Rnode
);
6184 Set_Associated_Storage_Pool
(U_Ent
, Pool
);
6187 elsif Is_Entity_Name
(Expr
) then
6188 Pool
:= Entity
(Expr
);
6190 -- If pool is a renamed object, get original one. This can
6191 -- happen with an explicit renaming, and within instances.
6193 while Present
(Renamed_Object
(Pool
))
6194 and then Is_Entity_Name
(Renamed_Object
(Pool
))
6196 Pool
:= Entity
(Renamed_Object
(Pool
));
6199 if Present
(Renamed_Object
(Pool
))
6200 and then Nkind
(Renamed_Object
(Pool
)) = N_Type_Conversion
6201 and then Is_Entity_Name
(Expression
(Renamed_Object
(Pool
)))
6203 Pool
:= Entity
(Expression
(Renamed_Object
(Pool
)));
6206 Set_Associated_Storage_Pool
(U_Ent
, Pool
);
6208 elsif Nkind
(Expr
) = N_Type_Conversion
6209 and then Is_Entity_Name
(Expression
(Expr
))
6210 and then Nkind
(Original_Node
(Expr
)) = N_Attribute_Reference
6212 Pool
:= Entity
(Expression
(Expr
));
6213 Set_Associated_Storage_Pool
(U_Ent
, Pool
);
6216 Error_Msg_N
("incorrect reference to a Storage Pool", Expr
);
6225 -- Storage_Size attribute definition clause
6227 when Attribute_Storage_Size
=> Storage_Size
: declare
6228 Btype
: constant Entity_Id
:= Base_Type
(U_Ent
);
6231 if Is_Task_Type
(U_Ent
) then
6233 -- Check obsolescent (but never obsolescent if from aspect)
6235 if not From_Aspect_Specification
(N
) then
6236 Check_Restriction
(No_Obsolescent_Features
, N
);
6238 if Warn_On_Obsolescent_Feature
then
6240 ("?j?storage size clause for task is an obsolescent "
6241 & "feature (RM J.9)", N
);
6242 Error_Msg_N
("\?j?use Storage_Size pragma instead", N
);
6249 if not Is_Access_Type
(U_Ent
)
6250 and then Ekind
(U_Ent
) /= E_Task_Type
6252 Error_Msg_N
("storage size cannot be given for &", Nam
);
6254 elsif Is_Access_Type
(U_Ent
) and Is_Derived_Type
(U_Ent
) then
6256 ("storage size cannot be given for a derived access type",
6259 elsif Duplicate_Clause
then
6263 Analyze_And_Resolve
(Expr
, Any_Integer
);
6265 if Is_Access_Type
(U_Ent
) then
6267 -- Check for Storage_Pool previously given
6270 SP
: constant Node_Id
:=
6271 Get_Attribute_Definition_Clause
6272 (U_Ent
, Attribute_Storage_Pool
);
6275 if Present
(SP
) then
6276 Check_Pool_Size_Clash
(U_Ent
, SP
, N
);
6280 -- Special case of for x'Storage_Size use 0
6282 if Is_OK_Static_Expression
(Expr
)
6283 and then Expr_Value
(Expr
) = 0
6285 Set_No_Pool_Assigned
(Btype
);
6289 Set_Has_Storage_Size_Clause
(Btype
);
6297 when Attribute_Stream_Size
=> Stream_Size
: declare
6298 Size
: constant Uint
:= Static_Integer
(Expr
);
6301 if Ada_Version
<= Ada_95
then
6302 Check_Restriction
(No_Implementation_Attributes
, N
);
6305 if Duplicate_Clause
then
6308 elsif Is_Elementary_Type
(U_Ent
) then
6310 -- The following errors are suppressed in ASIS mode to allow
6311 -- for different ASIS back ends or ASIS-based tools to query
6312 -- the illegal clause.
6317 elsif Size
/= System_Storage_Unit
6318 and then Size
/= System_Storage_Unit
* 2
6319 and then Size
/= System_Storage_Unit
* 4
6320 and then Size
/= System_Storage_Unit
* 8
6322 Error_Msg_Uint_1
:= UI_From_Int
(System_Storage_Unit
);
6324 ("stream size for elementary type must be a power of 2 "
6325 & "and at least ^", N
);
6327 elsif RM_Size
(U_Ent
) > Size
then
6328 Error_Msg_Uint_1
:= RM_Size
(U_Ent
);
6330 ("stream size for elementary type must be a power of 2 "
6331 & "and at least ^", N
);
6334 Set_Has_Stream_Size_Clause
(U_Ent
);
6337 Error_Msg_N
("Stream_Size cannot be given for &", Nam
);
6345 -- Value_Size attribute definition clause
6347 when Attribute_Value_Size
=> Value_Size
: declare
6348 Size
: constant Uint
:= Static_Integer
(Expr
);
6352 if not Is_Type
(U_Ent
) then
6353 Error_Msg_N
("Value_Size cannot be given for &", Nam
);
6355 elsif Duplicate_Clause
then
6358 elsif Is_Array_Type
(U_Ent
)
6359 and then not Is_Constrained
(U_Ent
)
6362 ("Value_Size cannot be given for unconstrained array", Nam
);
6365 if Is_Elementary_Type
(U_Ent
) then
6366 Check_Size
(Expr
, U_Ent
, Size
, Biased
);
6367 Set_Biased
(U_Ent
, N
, "value size clause", Biased
);
6370 Set_RM_Size
(U_Ent
, Size
);
6374 -----------------------
6375 -- Variable_Indexing --
6376 -----------------------
6378 when Attribute_Variable_Indexing
=>
6379 Check_Indexing_Functions
;
6385 when Attribute_Write
=>
6386 Analyze_Stream_TSS_Definition
(TSS_Stream_Write
);
6387 Set_Has_Specified_Stream_Write
(Ent
);
6389 -- All other attributes cannot be set
6393 ("attribute& cannot be set with definition clause", N
);
6396 -- The test for the type being frozen must be performed after any
6397 -- expression the clause has been analyzed since the expression itself
6398 -- might cause freezing that makes the clause illegal.
6400 if Rep_Item_Too_Late
(U_Ent
, N
, FOnly
) then
6403 end Analyze_Attribute_Definition_Clause
;
6405 ----------------------------
6406 -- Analyze_Code_Statement --
6407 ----------------------------
6409 procedure Analyze_Code_Statement
(N
: Node_Id
) is
6410 HSS
: constant Node_Id
:= Parent
(N
);
6411 SBody
: constant Node_Id
:= Parent
(HSS
);
6412 Subp
: constant Entity_Id
:= Current_Scope
;
6419 -- Accept foreign code statements for CodePeer. The analysis is skipped
6420 -- to avoid rejecting unrecognized constructs.
6422 if CodePeer_Mode
then
6427 -- Analyze and check we get right type, note that this implements the
6428 -- requirement (RM 13.8(1)) that Machine_Code be with'ed, since that is
6429 -- the only way that Asm_Insn could possibly be visible.
6431 Analyze_And_Resolve
(Expression
(N
));
6433 if Etype
(Expression
(N
)) = Any_Type
then
6435 elsif Etype
(Expression
(N
)) /= RTE
(RE_Asm_Insn
) then
6436 Error_Msg_N
("incorrect type for code statement", N
);
6440 Check_Code_Statement
(N
);
6442 -- Make sure we appear in the handled statement sequence of a subprogram
6445 if Nkind
(HSS
) /= N_Handled_Sequence_Of_Statements
6446 or else Nkind
(SBody
) /= N_Subprogram_Body
6449 ("code statement can only appear in body of subprogram", N
);
6453 -- Do remaining checks (RM 13.8(3)) if not already done
6455 if not Is_Machine_Code_Subprogram
(Subp
) then
6456 Set_Is_Machine_Code_Subprogram
(Subp
);
6458 -- No exception handlers allowed
6460 if Present
(Exception_Handlers
(HSS
)) then
6462 ("exception handlers not permitted in machine code subprogram",
6463 First
(Exception_Handlers
(HSS
)));
6466 -- No declarations other than use clauses and pragmas (we allow
6467 -- certain internally generated declarations as well).
6469 Decl
:= First
(Declarations
(SBody
));
6470 while Present
(Decl
) loop
6471 DeclO
:= Original_Node
(Decl
);
6472 if Comes_From_Source
(DeclO
)
6473 and not Nkind_In
(DeclO
, N_Pragma
,
6474 N_Use_Package_Clause
,
6476 N_Implicit_Label_Declaration
)
6479 ("this declaration not allowed in machine code subprogram",
6486 -- No statements other than code statements, pragmas, and labels.
6487 -- Again we allow certain internally generated statements.
6489 -- In Ada 2012, qualified expressions are names, and the code
6490 -- statement is initially parsed as a procedure call.
6492 Stmt
:= First
(Statements
(HSS
));
6493 while Present
(Stmt
) loop
6494 StmtO
:= Original_Node
(Stmt
);
6496 -- A procedure call transformed into a code statement is OK
6498 if Ada_Version
>= Ada_2012
6499 and then Nkind
(StmtO
) = N_Procedure_Call_Statement
6500 and then Nkind
(Name
(StmtO
)) = N_Qualified_Expression
6504 elsif Comes_From_Source
(StmtO
)
6505 and then not Nkind_In
(StmtO
, N_Pragma
,
6510 ("this statement is not allowed in machine code subprogram",
6517 end Analyze_Code_Statement
;
6519 -----------------------------------------------
6520 -- Analyze_Enumeration_Representation_Clause --
6521 -----------------------------------------------
6523 procedure Analyze_Enumeration_Representation_Clause
(N
: Node_Id
) is
6524 Ident
: constant Node_Id
:= Identifier
(N
);
6525 Aggr
: constant Node_Id
:= Array_Aggregate
(N
);
6526 Enumtype
: Entity_Id
;
6533 Err
: Boolean := False;
6534 -- Set True to avoid cascade errors and crashes on incorrect source code
6536 Lo
: constant Uint
:= Expr_Value
(Type_Low_Bound
(Universal_Integer
));
6537 Hi
: constant Uint
:= Expr_Value
(Type_High_Bound
(Universal_Integer
));
6538 -- Allowed range of universal integer (= allowed range of enum lit vals)
6542 -- Minimum and maximum values of entries
6544 Max_Node
: Node_Id
:= Empty
; -- init to avoid warning
6545 -- Pointer to node for literal providing max value
6548 if Ignore_Rep_Clauses
then
6549 Kill_Rep_Clause
(N
);
6553 -- Ignore enumeration rep clauses by default in CodePeer mode,
6554 -- unless -gnatd.I is specified, as a work around for potential false
6555 -- positive messages.
6557 if CodePeer_Mode
and not Debug_Flag_Dot_II
then
6561 -- First some basic error checks
6564 Enumtype
:= Entity
(Ident
);
6566 if Enumtype
= Any_Type
6567 or else Rep_Item_Too_Early
(Enumtype
, N
)
6571 Enumtype
:= Underlying_Type
(Enumtype
);
6574 if not Is_Enumeration_Type
(Enumtype
) then
6576 ("enumeration type required, found}",
6577 Ident
, First_Subtype
(Enumtype
));
6581 -- Ignore rep clause on generic actual type. This will already have
6582 -- been flagged on the template as an error, and this is the safest
6583 -- way to ensure we don't get a junk cascaded message in the instance.
6585 if Is_Generic_Actual_Type
(Enumtype
) then
6588 -- Type must be in current scope
6590 elsif Scope
(Enumtype
) /= Current_Scope
then
6591 Error_Msg_N
("type must be declared in this scope", Ident
);
6594 -- Type must be a first subtype
6596 elsif not Is_First_Subtype
(Enumtype
) then
6597 Error_Msg_N
("cannot give enumeration rep clause for subtype", N
);
6600 -- Ignore duplicate rep clause
6602 elsif Has_Enumeration_Rep_Clause
(Enumtype
) then
6603 Error_Msg_N
("duplicate enumeration rep clause ignored", N
);
6606 -- Don't allow rep clause for standard [wide_[wide_]]character
6608 elsif Is_Standard_Character_Type
(Enumtype
) then
6609 Error_Msg_N
("enumeration rep clause not allowed for this type", N
);
6612 -- Check that the expression is a proper aggregate (no parentheses)
6614 elsif Paren_Count
(Aggr
) /= 0 then
6616 ("extra parentheses surrounding aggregate not allowed",
6620 -- All tests passed, so set rep clause in place
6623 Set_Has_Enumeration_Rep_Clause
(Enumtype
);
6624 Set_Has_Enumeration_Rep_Clause
(Base_Type
(Enumtype
));
6627 -- Now we process the aggregate. Note that we don't use the normal
6628 -- aggregate code for this purpose, because we don't want any of the
6629 -- normal expansion activities, and a number of special semantic
6630 -- rules apply (including the component type being any integer type)
6632 Elit
:= First_Literal
(Enumtype
);
6634 -- First the positional entries if any
6636 if Present
(Expressions
(Aggr
)) then
6637 Expr
:= First
(Expressions
(Aggr
));
6638 while Present
(Expr
) loop
6640 Error_Msg_N
("too many entries in aggregate", Expr
);
6644 Val
:= Static_Integer
(Expr
);
6646 -- Err signals that we found some incorrect entries processing
6647 -- the list. The final checks for completeness and ordering are
6648 -- skipped in this case.
6650 if Val
= No_Uint
then
6653 elsif Val
< Lo
or else Hi
< Val
then
6654 Error_Msg_N
("value outside permitted range", Expr
);
6658 Set_Enumeration_Rep
(Elit
, Val
);
6659 Set_Enumeration_Rep_Expr
(Elit
, Expr
);
6665 -- Now process the named entries if present
6667 if Present
(Component_Associations
(Aggr
)) then
6668 Assoc
:= First
(Component_Associations
(Aggr
));
6669 while Present
(Assoc
) loop
6670 Choice
:= First
(Choices
(Assoc
));
6672 if Present
(Next
(Choice
)) then
6674 ("multiple choice not allowed here", Next
(Choice
));
6678 if Nkind
(Choice
) = N_Others_Choice
then
6679 Error_Msg_N
("others choice not allowed here", Choice
);
6682 elsif Nkind
(Choice
) = N_Range
then
6684 -- ??? should allow zero/one element range here
6686 Error_Msg_N
("range not allowed here", Choice
);
6690 Analyze_And_Resolve
(Choice
, Enumtype
);
6692 if Error_Posted
(Choice
) then
6697 if Is_Entity_Name
(Choice
)
6698 and then Is_Type
(Entity
(Choice
))
6700 Error_Msg_N
("subtype name not allowed here", Choice
);
6703 -- ??? should allow static subtype with zero/one entry
6705 elsif Etype
(Choice
) = Base_Type
(Enumtype
) then
6706 if not Is_OK_Static_Expression
(Choice
) then
6707 Flag_Non_Static_Expr
6708 ("non-static expression used for choice!", Choice
);
6712 Elit
:= Expr_Value_E
(Choice
);
6714 if Present
(Enumeration_Rep_Expr
(Elit
)) then
6716 Sloc
(Enumeration_Rep_Expr
(Elit
));
6718 ("representation for& previously given#",
6723 Set_Enumeration_Rep_Expr
(Elit
, Expression
(Assoc
));
6725 Expr
:= Expression
(Assoc
);
6726 Val
:= Static_Integer
(Expr
);
6728 if Val
= No_Uint
then
6731 elsif Val
< Lo
or else Hi
< Val
then
6732 Error_Msg_N
("value outside permitted range", Expr
);
6736 Set_Enumeration_Rep
(Elit
, Val
);
6746 -- Aggregate is fully processed. Now we check that a full set of
6747 -- representations was given, and that they are in range and in order.
6748 -- These checks are only done if no other errors occurred.
6754 Elit
:= First_Literal
(Enumtype
);
6755 while Present
(Elit
) loop
6756 if No
(Enumeration_Rep_Expr
(Elit
)) then
6757 Error_Msg_NE
("missing representation for&!", N
, Elit
);
6760 Val
:= Enumeration_Rep
(Elit
);
6762 if Min
= No_Uint
then
6766 if Val
/= No_Uint
then
6767 if Max
/= No_Uint
and then Val
<= Max
then
6769 ("enumeration value for& not ordered!",
6770 Enumeration_Rep_Expr
(Elit
), Elit
);
6773 Max_Node
:= Enumeration_Rep_Expr
(Elit
);
6777 -- If there is at least one literal whose representation is not
6778 -- equal to the Pos value, then note that this enumeration type
6779 -- has a non-standard representation.
6781 if Val
/= Enumeration_Pos
(Elit
) then
6782 Set_Has_Non_Standard_Rep
(Base_Type
(Enumtype
));
6789 -- Now set proper size information
6792 Minsize
: Uint
:= UI_From_Int
(Minimum_Size
(Enumtype
));
6795 if Has_Size_Clause
(Enumtype
) then
6797 -- All OK, if size is OK now
6799 if RM_Size
(Enumtype
) >= Minsize
then
6803 -- Try if we can get by with biasing
6806 UI_From_Int
(Minimum_Size
(Enumtype
, Biased
=> True));
6808 -- Error message if even biasing does not work
6810 if RM_Size
(Enumtype
) < Minsize
then
6811 Error_Msg_Uint_1
:= RM_Size
(Enumtype
);
6812 Error_Msg_Uint_2
:= Max
;
6814 ("previously given size (^) is too small "
6815 & "for this value (^)", Max_Node
);
6817 -- If biasing worked, indicate that we now have biased rep
6821 (Enumtype
, Size_Clause
(Enumtype
), "size clause");
6826 Set_RM_Size
(Enumtype
, Minsize
);
6827 Set_Enum_Esize
(Enumtype
);
6830 Set_RM_Size
(Base_Type
(Enumtype
), RM_Size
(Enumtype
));
6831 Set_Esize
(Base_Type
(Enumtype
), Esize
(Enumtype
));
6832 Set_Alignment
(Base_Type
(Enumtype
), Alignment
(Enumtype
));
6836 -- We repeat the too late test in case it froze itself
6838 if Rep_Item_Too_Late
(Enumtype
, N
) then
6841 end Analyze_Enumeration_Representation_Clause
;
6843 ----------------------------
6844 -- Analyze_Free_Statement --
6845 ----------------------------
6847 procedure Analyze_Free_Statement
(N
: Node_Id
) is
6849 Analyze
(Expression
(N
));
6850 end Analyze_Free_Statement
;
6852 ---------------------------
6853 -- Analyze_Freeze_Entity --
6854 ---------------------------
6856 procedure Analyze_Freeze_Entity
(N
: Node_Id
) is
6858 Freeze_Entity_Checks
(N
);
6859 end Analyze_Freeze_Entity
;
6861 -----------------------------------
6862 -- Analyze_Freeze_Generic_Entity --
6863 -----------------------------------
6865 procedure Analyze_Freeze_Generic_Entity
(N
: Node_Id
) is
6866 E
: constant Entity_Id
:= Entity
(N
);
6869 if not Is_Frozen
(E
) and then Has_Delayed_Aspects
(E
) then
6870 Analyze_Aspects_At_Freeze_Point
(E
);
6873 Freeze_Entity_Checks
(N
);
6874 end Analyze_Freeze_Generic_Entity
;
6876 ------------------------------------------
6877 -- Analyze_Record_Representation_Clause --
6878 ------------------------------------------
6880 -- Note: we check as much as we can here, but we can't do any checks
6881 -- based on the position values (e.g. overlap checks) until freeze time
6882 -- because especially in Ada 2005 (machine scalar mode), the processing
6883 -- for non-standard bit order can substantially change the positions.
6884 -- See procedure Check_Record_Representation_Clause (called from Freeze)
6885 -- for the remainder of this processing.
6887 procedure Analyze_Record_Representation_Clause
(N
: Node_Id
) is
6888 Ident
: constant Node_Id
:= Identifier
(N
);
6893 Hbit
: Uint
:= Uint_0
;
6897 Rectype
: Entity_Id
;
6900 function Is_Inherited
(Comp
: Entity_Id
) return Boolean;
6901 -- True if Comp is an inherited component in a record extension
6907 function Is_Inherited
(Comp
: Entity_Id
) return Boolean is
6908 Comp_Base
: Entity_Id
;
6911 if Ekind
(Rectype
) = E_Record_Subtype
then
6912 Comp_Base
:= Original_Record_Component
(Comp
);
6917 return Comp_Base
/= Original_Record_Component
(Comp_Base
);
6922 Is_Record_Extension
: Boolean;
6923 -- True if Rectype is a record extension
6925 CR_Pragma
: Node_Id
:= Empty
;
6926 -- Points to N_Pragma node if Complete_Representation pragma present
6928 -- Start of processing for Analyze_Record_Representation_Clause
6931 if Ignore_Rep_Clauses
then
6932 Kill_Rep_Clause
(N
);
6937 Rectype
:= Entity
(Ident
);
6939 if Rectype
= Any_Type
or else Rep_Item_Too_Early
(Rectype
, N
) then
6942 Rectype
:= Underlying_Type
(Rectype
);
6945 -- First some basic error checks
6947 if not Is_Record_Type
(Rectype
) then
6949 ("record type required, found}", Ident
, First_Subtype
(Rectype
));
6952 elsif Scope
(Rectype
) /= Current_Scope
then
6953 Error_Msg_N
("type must be declared in this scope", N
);
6956 elsif not Is_First_Subtype
(Rectype
) then
6957 Error_Msg_N
("cannot give record rep clause for subtype", N
);
6960 elsif Has_Record_Rep_Clause
(Rectype
) then
6961 Error_Msg_N
("duplicate record rep clause ignored", N
);
6964 elsif Rep_Item_Too_Late
(Rectype
, N
) then
6968 -- We know we have a first subtype, now possibly go to the anonymous
6969 -- base type to determine whether Rectype is a record extension.
6971 Recdef
:= Type_Definition
(Declaration_Node
(Base_Type
(Rectype
)));
6972 Is_Record_Extension
:=
6973 Nkind
(Recdef
) = N_Derived_Type_Definition
6974 and then Present
(Record_Extension_Part
(Recdef
));
6976 if Present
(Mod_Clause
(N
)) then
6978 Loc
: constant Source_Ptr
:= Sloc
(N
);
6979 M
: constant Node_Id
:= Mod_Clause
(N
);
6980 P
: constant List_Id
:= Pragmas_Before
(M
);
6984 pragma Warnings
(Off
, Mod_Val
);
6987 Check_Restriction
(No_Obsolescent_Features
, Mod_Clause
(N
));
6989 if Warn_On_Obsolescent_Feature
then
6991 ("?j?mod clause is an obsolescent feature (RM J.8)", N
);
6993 ("\?j?use alignment attribute definition clause instead", N
);
7000 -- In ASIS_Mode mode, expansion is disabled, but we must convert
7001 -- the Mod clause into an alignment clause anyway, so that the
7002 -- back end can compute and back-annotate properly the size and
7003 -- alignment of types that may include this record.
7005 -- This seems dubious, this destroys the source tree in a manner
7006 -- not detectable by ASIS ???
7008 if Operating_Mode
= Check_Semantics
and then ASIS_Mode
then
7010 Make_Attribute_Definition_Clause
(Loc
,
7011 Name
=> New_Occurrence_Of
(Base_Type
(Rectype
), Loc
),
7012 Chars
=> Name_Alignment
,
7013 Expression
=> Relocate_Node
(Expression
(M
)));
7015 Set_From_At_Mod
(AtM_Nod
);
7016 Insert_After
(N
, AtM_Nod
);
7017 Mod_Val
:= Get_Alignment_Value
(Expression
(AtM_Nod
));
7018 Set_Mod_Clause
(N
, Empty
);
7021 -- Get the alignment value to perform error checking
7023 Mod_Val
:= Get_Alignment_Value
(Expression
(M
));
7028 -- For untagged types, clear any existing component clauses for the
7029 -- type. If the type is derived, this is what allows us to override
7030 -- a rep clause for the parent. For type extensions, the representation
7031 -- of the inherited components is inherited, so we want to keep previous
7032 -- component clauses for completeness.
7034 if not Is_Tagged_Type
(Rectype
) then
7035 Comp
:= First_Component_Or_Discriminant
(Rectype
);
7036 while Present
(Comp
) loop
7037 Set_Component_Clause
(Comp
, Empty
);
7038 Next_Component_Or_Discriminant
(Comp
);
7042 -- All done if no component clauses
7044 CC
:= First
(Component_Clauses
(N
));
7050 -- A representation like this applies to the base type
7052 Set_Has_Record_Rep_Clause
(Base_Type
(Rectype
));
7053 Set_Has_Non_Standard_Rep
(Base_Type
(Rectype
));
7054 Set_Has_Specified_Layout
(Base_Type
(Rectype
));
7056 -- Process the component clauses
7058 while Present
(CC
) loop
7062 if Nkind
(CC
) = N_Pragma
then
7065 -- The only pragma of interest is Complete_Representation
7067 if Pragma_Name
(CC
) = Name_Complete_Representation
then
7071 -- Processing for real component clause
7074 Posit
:= Static_Integer
(Position
(CC
));
7075 Fbit
:= Static_Integer
(First_Bit
(CC
));
7076 Lbit
:= Static_Integer
(Last_Bit
(CC
));
7079 and then Fbit
/= No_Uint
7080 and then Lbit
/= No_Uint
7083 Error_Msg_N
("position cannot be negative", Position
(CC
));
7086 Error_Msg_N
("first bit cannot be negative", First_Bit
(CC
));
7088 -- The Last_Bit specified in a component clause must not be
7089 -- less than the First_Bit minus one (RM-13.5.1(10)).
7091 elsif Lbit
< Fbit
- 1 then
7093 ("last bit cannot be less than first bit minus one",
7096 -- Values look OK, so find the corresponding record component
7097 -- Even though the syntax allows an attribute reference for
7098 -- implementation-defined components, GNAT does not allow the
7099 -- tag to get an explicit position.
7101 elsif Nkind
(Component_Name
(CC
)) = N_Attribute_Reference
then
7102 if Attribute_Name
(Component_Name
(CC
)) = Name_Tag
then
7103 Error_Msg_N
("position of tag cannot be specified", CC
);
7105 Error_Msg_N
("illegal component name", CC
);
7109 Comp
:= First_Entity
(Rectype
);
7110 while Present
(Comp
) loop
7111 exit when Chars
(Comp
) = Chars
(Component_Name
(CC
));
7117 -- Maybe component of base type that is absent from
7118 -- statically constrained first subtype.
7120 Comp
:= First_Entity
(Base_Type
(Rectype
));
7121 while Present
(Comp
) loop
7122 exit when Chars
(Comp
) = Chars
(Component_Name
(CC
));
7129 ("component clause is for non-existent field", CC
);
7131 -- Ada 2012 (AI05-0026): Any name that denotes a
7132 -- discriminant of an object of an unchecked union type
7133 -- shall not occur within a record_representation_clause.
7135 -- The general restriction of using record rep clauses on
7136 -- Unchecked_Union types has now been lifted. Since it is
7137 -- possible to introduce a record rep clause which mentions
7138 -- the discriminant of an Unchecked_Union in non-Ada 2012
7139 -- code, this check is applied to all versions of the
7142 elsif Ekind
(Comp
) = E_Discriminant
7143 and then Is_Unchecked_Union
(Rectype
)
7146 ("cannot reference discriminant of unchecked union",
7147 Component_Name
(CC
));
7149 elsif Is_Record_Extension
and then Is_Inherited
(Comp
) then
7151 ("component clause not allowed for inherited "
7152 & "component&", CC
, Comp
);
7154 elsif Present
(Component_Clause
(Comp
)) then
7156 -- Diagnose duplicate rep clause, or check consistency
7157 -- if this is an inherited component. In a double fault,
7158 -- there may be a duplicate inconsistent clause for an
7159 -- inherited component.
7161 if Scope
(Original_Record_Component
(Comp
)) = Rectype
7162 or else Parent
(Component_Clause
(Comp
)) = N
7164 Error_Msg_Sloc
:= Sloc
(Component_Clause
(Comp
));
7165 Error_Msg_N
("component clause previously given#", CC
);
7169 Rep1
: constant Node_Id
:= Component_Clause
(Comp
);
7171 if Intval
(Position
(Rep1
)) /=
7172 Intval
(Position
(CC
))
7173 or else Intval
(First_Bit
(Rep1
)) /=
7174 Intval
(First_Bit
(CC
))
7175 or else Intval
(Last_Bit
(Rep1
)) /=
7176 Intval
(Last_Bit
(CC
))
7179 ("component clause inconsistent with "
7180 & "representation of ancestor", CC
);
7182 elsif Warn_On_Redundant_Constructs
then
7184 ("?r?redundant confirming component clause "
7185 & "for component!", CC
);
7190 -- Normal case where this is the first component clause we
7191 -- have seen for this entity, so set it up properly.
7194 -- Make reference for field in record rep clause and set
7195 -- appropriate entity field in the field identifier.
7198 (Comp
, Component_Name
(CC
), Set_Ref
=> False);
7199 Set_Entity
(Component_Name
(CC
), Comp
);
7201 -- Update Fbit and Lbit to the actual bit number
7203 Fbit
:= Fbit
+ UI_From_Int
(SSU
) * Posit
;
7204 Lbit
:= Lbit
+ UI_From_Int
(SSU
) * Posit
;
7206 if Has_Size_Clause
(Rectype
)
7207 and then RM_Size
(Rectype
) <= Lbit
7210 ("bit number out of range of specified size",
7213 Set_Component_Clause
(Comp
, CC
);
7214 Set_Component_Bit_Offset
(Comp
, Fbit
);
7215 Set_Esize
(Comp
, 1 + (Lbit
- Fbit
));
7216 Set_Normalized_First_Bit
(Comp
, Fbit
mod SSU
);
7217 Set_Normalized_Position
(Comp
, Fbit
/ SSU
);
7219 if Warn_On_Overridden_Size
7220 and then Has_Size_Clause
(Etype
(Comp
))
7221 and then RM_Size
(Etype
(Comp
)) /= Esize
(Comp
)
7224 ("?S?component size overrides size clause for&",
7225 Component_Name
(CC
), Etype
(Comp
));
7228 -- This information is also set in the corresponding
7229 -- component of the base type, found by accessing the
7230 -- Original_Record_Component link if it is present.
7232 Ocomp
:= Original_Record_Component
(Comp
);
7239 (Component_Name
(CC
),
7245 (Comp
, First_Node
(CC
), "component clause", Biased
);
7247 if Present
(Ocomp
) then
7248 Set_Component_Clause
(Ocomp
, CC
);
7249 Set_Component_Bit_Offset
(Ocomp
, Fbit
);
7250 Set_Normalized_First_Bit
(Ocomp
, Fbit
mod SSU
);
7251 Set_Normalized_Position
(Ocomp
, Fbit
/ SSU
);
7252 Set_Esize
(Ocomp
, 1 + (Lbit
- Fbit
));
7254 Set_Normalized_Position_Max
7255 (Ocomp
, Normalized_Position
(Ocomp
));
7257 -- Note: we don't use Set_Biased here, because we
7258 -- already gave a warning above if needed, and we
7259 -- would get a duplicate for the same name here.
7261 Set_Has_Biased_Representation
7262 (Ocomp
, Has_Biased_Representation
(Comp
));
7265 if Esize
(Comp
) < 0 then
7266 Error_Msg_N
("component size is negative", CC
);
7277 -- Check missing components if Complete_Representation pragma appeared
7279 if Present
(CR_Pragma
) then
7280 Comp
:= First_Component_Or_Discriminant
(Rectype
);
7281 while Present
(Comp
) loop
7282 if No
(Component_Clause
(Comp
)) then
7284 ("missing component clause for &", CR_Pragma
, Comp
);
7287 Next_Component_Or_Discriminant
(Comp
);
7290 -- Give missing components warning if required
7292 elsif Warn_On_Unrepped_Components
then
7294 Num_Repped_Components
: Nat
:= 0;
7295 Num_Unrepped_Components
: Nat
:= 0;
7298 -- First count number of repped and unrepped components
7300 Comp
:= First_Component_Or_Discriminant
(Rectype
);
7301 while Present
(Comp
) loop
7302 if Present
(Component_Clause
(Comp
)) then
7303 Num_Repped_Components
:= Num_Repped_Components
+ 1;
7305 Num_Unrepped_Components
:= Num_Unrepped_Components
+ 1;
7308 Next_Component_Or_Discriminant
(Comp
);
7311 -- We are only interested in the case where there is at least one
7312 -- unrepped component, and at least half the components have rep
7313 -- clauses. We figure that if less than half have them, then the
7314 -- partial rep clause is really intentional. If the component
7315 -- type has no underlying type set at this point (as for a generic
7316 -- formal type), we don't know enough to give a warning on the
7319 if Num_Unrepped_Components
> 0
7320 and then Num_Unrepped_Components
< Num_Repped_Components
7322 Comp
:= First_Component_Or_Discriminant
(Rectype
);
7323 while Present
(Comp
) loop
7324 if No
(Component_Clause
(Comp
))
7325 and then Comes_From_Source
(Comp
)
7326 and then Present
(Underlying_Type
(Etype
(Comp
)))
7327 and then (Is_Scalar_Type
(Underlying_Type
(Etype
(Comp
)))
7328 or else Size_Known_At_Compile_Time
7329 (Underlying_Type
(Etype
(Comp
))))
7330 and then not Has_Warnings_Off
(Rectype
)
7332 -- Ignore discriminant in unchecked union, since it is
7333 -- not there, and cannot have a component clause.
7335 and then (not Is_Unchecked_Union
(Rectype
)
7336 or else Ekind
(Comp
) /= E_Discriminant
)
7338 Error_Msg_Sloc
:= Sloc
(Comp
);
7340 ("?C?no component clause given for & declared #",
7344 Next_Component_Or_Discriminant
(Comp
);
7349 end Analyze_Record_Representation_Clause
;
7351 -------------------------------------
7352 -- Build_Discrete_Static_Predicate --
7353 -------------------------------------
7355 procedure Build_Discrete_Static_Predicate
7360 Loc
: constant Source_Ptr
:= Sloc
(Expr
);
7362 Non_Static
: exception;
7363 -- Raised if something non-static is found
7365 Btyp
: constant Entity_Id
:= Base_Type
(Typ
);
7367 BLo
: constant Uint
:= Expr_Value
(Type_Low_Bound
(Btyp
));
7368 BHi
: constant Uint
:= Expr_Value
(Type_High_Bound
(Btyp
));
7369 -- Low bound and high bound value of base type of Typ
7373 -- Bounds for constructing the static predicate. We use the bound of the
7374 -- subtype if it is static, otherwise the corresponding base type bound.
7375 -- Note: a non-static subtype can have a static predicate.
7380 -- One entry in a Rlist value, a single REnt (range entry) value denotes
7381 -- one range from Lo to Hi. To represent a single value range Lo = Hi =
7384 type RList
is array (Nat
range <>) of REnt
;
7385 -- A list of ranges. The ranges are sorted in increasing order, and are
7386 -- disjoint (there is a gap of at least one value between each range in
7387 -- the table). A value is in the set of ranges in Rlist if it lies
7388 -- within one of these ranges.
7390 False_Range
: constant RList
:=
7391 RList
'(1 .. 0 => REnt'(No_Uint
, No_Uint
));
7392 -- An empty set of ranges represents a range list that can never be
7393 -- satisfied, since there are no ranges in which the value could lie,
7394 -- so it does not lie in any of them. False_Range is a canonical value
7395 -- for this empty set, but general processing should test for an Rlist
7396 -- with length zero (see Is_False predicate), since other null ranges
7397 -- may appear which must be treated as False.
7399 True_Range
: constant RList
:= RList
'(1 => REnt'(BLo
, BHi
));
7400 -- Range representing True, value must be in the base range
7402 function "and" (Left
: RList
; Right
: RList
) return RList
;
7403 -- And's together two range lists, returning a range list. This is a set
7404 -- intersection operation.
7406 function "or" (Left
: RList
; Right
: RList
) return RList
;
7407 -- Or's together two range lists, returning a range list. This is a set
7410 function "not" (Right
: RList
) return RList
;
7411 -- Returns complement of a given range list, i.e. a range list
7412 -- representing all the values in TLo .. THi that are not in the input
7415 function Build_Val
(V
: Uint
) return Node_Id
;
7416 -- Return an analyzed N_Identifier node referencing this value, suitable
7417 -- for use as an entry in the Static_Discrte_Predicate list. This node
7418 -- is typed with the base type.
7420 function Build_Range
(Lo
: Uint
; Hi
: Uint
) return Node_Id
;
7421 -- Return an analyzed N_Range node referencing this range, suitable for
7422 -- use as an entry in the Static_Discrete_Predicate list. This node is
7423 -- typed with the base type.
7425 function Get_RList
(Exp
: Node_Id
) return RList
;
7426 -- This is a recursive routine that converts the given expression into a
7427 -- list of ranges, suitable for use in building the static predicate.
7429 function Is_False
(R
: RList
) return Boolean;
7430 pragma Inline
(Is_False
);
7431 -- Returns True if the given range list is empty, and thus represents a
7432 -- False list of ranges that can never be satisfied.
7434 function Is_True
(R
: RList
) return Boolean;
7435 -- Returns True if R trivially represents the True predicate by having a
7436 -- single range from BLo to BHi.
7438 function Is_Type_Ref
(N
: Node_Id
) return Boolean;
7439 pragma Inline
(Is_Type_Ref
);
7440 -- Returns if True if N is a reference to the type for the predicate in
7441 -- the expression (i.e. if it is an identifier whose Chars field matches
7442 -- the Nam given in the call). N must not be parenthesized, if the type
7443 -- name appears in parens, this routine will return False.
7445 function Lo_Val
(N
: Node_Id
) return Uint
;
7446 -- Given an entry from a Static_Discrete_Predicate list that is either
7447 -- a static expression or static range, gets either the expression value
7448 -- or the low bound of the range.
7450 function Hi_Val
(N
: Node_Id
) return Uint
;
7451 -- Given an entry from a Static_Discrete_Predicate list that is either
7452 -- a static expression or static range, gets either the expression value
7453 -- or the high bound of the range.
7455 function Membership_Entry
(N
: Node_Id
) return RList
;
7456 -- Given a single membership entry (range, value, or subtype), returns
7457 -- the corresponding range list. Raises Static_Error if not static.
7459 function Membership_Entries
(N
: Node_Id
) return RList
;
7460 -- Given an element on an alternatives list of a membership operation,
7461 -- returns the range list corresponding to this entry and all following
7462 -- entries (i.e. returns the "or" of this list of values).
7464 function Stat_Pred
(Typ
: Entity_Id
) return RList
;
7465 -- Given a type, if it has a static predicate, then return the predicate
7466 -- as a range list, otherwise raise Non_Static.
7472 function "and" (Left
: RList
; Right
: RList
) return RList
is
7474 -- First range of result
7476 SLeft
: Nat
:= Left
'First;
7477 -- Start of rest of left entries
7479 SRight
: Nat
:= Right
'First;
7480 -- Start of rest of right entries
7483 -- If either range is True, return the other
7485 if Is_True
(Left
) then
7487 elsif Is_True
(Right
) then
7491 -- If either range is False, return False
7493 if Is_False
(Left
) or else Is_False
(Right
) then
7497 -- Loop to remove entries at start that are disjoint, and thus just
7498 -- get discarded from the result entirely.
7501 -- If no operands left in either operand, result is false
7503 if SLeft
> Left
'Last or else SRight
> Right
'Last then
7506 -- Discard first left operand entry if disjoint with right
7508 elsif Left
(SLeft
).Hi
< Right
(SRight
).Lo
then
7511 -- Discard first right operand entry if disjoint with left
7513 elsif Right
(SRight
).Hi
< Left
(SLeft
).Lo
then
7514 SRight
:= SRight
+ 1;
7516 -- Otherwise we have an overlapping entry
7523 -- Now we have two non-null operands, and first entries overlap. The
7524 -- first entry in the result will be the overlapping part of these
7527 FEnt
:= REnt
'(Lo => UI_Max (Left (SLeft).Lo, Right (SRight).Lo),
7528 Hi => UI_Min (Left (SLeft).Hi, Right (SRight).Hi));
7530 -- Now we can remove the entry that ended at a lower value, since its
7531 -- contribution is entirely contained in Fent.
7533 if Left (SLeft).Hi <= Right (SRight).Hi then
7536 SRight := SRight + 1;
7539 -- Compute result by concatenating this first entry with the "and" of
7540 -- the remaining parts of the left and right operands. Note that if
7541 -- either of these is empty, "and" will yield empty, so that we will
7542 -- end up with just Fent, which is what we want in that case.
7545 FEnt & (Left (SLeft .. Left'Last) and Right (SRight .. Right'Last));
7552 function "not" (Right : RList) return RList is
7554 -- Return True if False range
7556 if Is_False (Right) then
7560 -- Return False if True range
7562 if Is_True (Right) then
7566 -- Here if not trivial case
7569 Result : RList (1 .. Right'Length + 1);
7570 -- May need one more entry for gap at beginning and end
7573 -- Number of entries stored in Result
7578 if Right (Right'First).Lo > TLo then
7580 Result (Count) := REnt'(TLo
, Right
(Right
'First).Lo
- 1);
7583 -- Gaps between ranges
7585 for J
in Right
'First .. Right
'Last - 1 loop
7587 Result
(Count
) := REnt
'(Right (J).Hi + 1, Right (J + 1).Lo - 1);
7592 if Right (Right'Last).Hi < THi then
7594 Result (Count) := REnt'(Right
(Right
'Last).Hi
+ 1, THi
);
7597 return Result
(1 .. Count
);
7605 function "or" (Left
: RList
; Right
: RList
) return RList
is
7607 -- First range of result
7609 SLeft
: Nat
:= Left
'First;
7610 -- Start of rest of left entries
7612 SRight
: Nat
:= Right
'First;
7613 -- Start of rest of right entries
7616 -- If either range is True, return True
7618 if Is_True
(Left
) or else Is_True
(Right
) then
7622 -- If either range is False (empty), return the other
7624 if Is_False
(Left
) then
7626 elsif Is_False
(Right
) then
7630 -- Initialize result first entry from left or right operand depending
7631 -- on which starts with the lower range.
7633 if Left
(SLeft
).Lo
< Right
(SRight
).Lo
then
7634 FEnt
:= Left
(SLeft
);
7637 FEnt
:= Right
(SRight
);
7638 SRight
:= SRight
+ 1;
7641 -- This loop eats ranges from left and right operands that are
7642 -- contiguous with the first range we are gathering.
7645 -- Eat first entry in left operand if contiguous or overlapped by
7646 -- gathered first operand of result.
7648 if SLeft
<= Left
'Last
7649 and then Left
(SLeft
).Lo
<= FEnt
.Hi
+ 1
7651 FEnt
.Hi
:= UI_Max
(FEnt
.Hi
, Left
(SLeft
).Hi
);
7654 -- Eat first entry in right operand if contiguous or overlapped by
7655 -- gathered right operand of result.
7657 elsif SRight
<= Right
'Last
7658 and then Right
(SRight
).Lo
<= FEnt
.Hi
+ 1
7660 FEnt
.Hi
:= UI_Max
(FEnt
.Hi
, Right
(SRight
).Hi
);
7661 SRight
:= SRight
+ 1;
7663 -- All done if no more entries to eat
7670 -- Obtain result as the first entry we just computed, concatenated
7671 -- to the "or" of the remaining results (if one operand is empty,
7672 -- this will just concatenate with the other
7675 FEnt
& (Left
(SLeft
.. Left
'Last) or Right
(SRight
.. Right
'Last));
7682 function Build_Range
(Lo
: Uint
; Hi
: Uint
) return Node_Id
is
7687 Low_Bound
=> Build_Val
(Lo
),
7688 High_Bound
=> Build_Val
(Hi
));
7689 Set_Etype
(Result
, Btyp
);
7690 Set_Analyzed
(Result
);
7698 function Build_Val
(V
: Uint
) return Node_Id
is
7702 if Is_Enumeration_Type
(Typ
) then
7703 Result
:= Get_Enum_Lit_From_Pos
(Typ
, V
, Loc
);
7705 Result
:= Make_Integer_Literal
(Loc
, V
);
7708 Set_Etype
(Result
, Btyp
);
7709 Set_Is_Static_Expression
(Result
);
7710 Set_Analyzed
(Result
);
7718 function Get_RList
(Exp
: Node_Id
) return RList
is
7723 -- Static expression can only be true or false
7725 if Is_OK_Static_Expression
(Exp
) then
7726 if Expr_Value
(Exp
) = 0 then
7733 -- Otherwise test node type
7744 return Get_RList
(Left_Opnd
(Exp
))
7746 Get_RList
(Right_Opnd
(Exp
));
7753 return Get_RList
(Left_Opnd
(Exp
))
7755 Get_RList
(Right_Opnd
(Exp
));
7760 return not Get_RList
(Right_Opnd
(Exp
));
7762 -- Comparisons of type with static value
7764 when N_Op_Compare
=>
7766 -- Type is left operand
7768 if Is_Type_Ref
(Left_Opnd
(Exp
))
7769 and then Is_OK_Static_Expression
(Right_Opnd
(Exp
))
7771 Val
:= Expr_Value
(Right_Opnd
(Exp
));
7773 -- Typ is right operand
7775 elsif Is_Type_Ref
(Right_Opnd
(Exp
))
7776 and then Is_OK_Static_Expression
(Left_Opnd
(Exp
))
7778 Val
:= Expr_Value
(Left_Opnd
(Exp
));
7780 -- Invert sense of comparison
7783 when N_Op_Gt
=> Op
:= N_Op_Lt
;
7784 when N_Op_Lt
=> Op
:= N_Op_Gt
;
7785 when N_Op_Ge
=> Op
:= N_Op_Le
;
7786 when N_Op_Le
=> Op
:= N_Op_Ge
;
7787 when others => null;
7790 -- Other cases are non-static
7796 -- Construct range according to comparison operation
7800 return RList
'(1 => REnt'(Val
, Val
));
7803 return RList
'(1 => REnt'(Val
, BHi
));
7806 return RList
'(1 => REnt'(Val
+ 1, BHi
));
7809 return RList
'(1 => REnt'(BLo
, Val
));
7812 return RList
'(1 => REnt'(BLo
, Val
- 1));
7815 return RList
'(REnt'(BLo
, Val
- 1), REnt
'(Val + 1, BHi));
7818 raise Program_Error;
7824 if not Is_Type_Ref (Left_Opnd (Exp)) then
7828 if Present (Right_Opnd (Exp)) then
7829 return Membership_Entry (Right_Opnd (Exp));
7831 return Membership_Entries (First (Alternatives (Exp)));
7834 -- Negative membership (NOT IN)
7837 if not Is_Type_Ref (Left_Opnd (Exp)) then
7841 if Present (Right_Opnd (Exp)) then
7842 return not Membership_Entry (Right_Opnd (Exp));
7844 return not Membership_Entries (First (Alternatives (Exp)));
7847 -- Function call, may be call to static predicate
7849 when N_Function_Call =>
7850 if Is_Entity_Name (Name (Exp)) then
7852 Ent : constant Entity_Id := Entity (Name (Exp));
7854 if Is_Predicate_Function (Ent)
7856 Is_Predicate_Function_M (Ent)
7858 return Stat_Pred (Etype (First_Formal (Ent)));
7863 -- Other function call cases are non-static
7867 -- Qualified expression, dig out the expression
7869 when N_Qualified_Expression =>
7870 return Get_RList (Expression (Exp));
7872 when N_Case_Expression =>
7879 if not Is_Entity_Name (Expression (Expr))
7880 or else Etype (Expression (Expr)) /= Typ
7883 ("expression must denaote subtype", Expression (Expr));
7887 -- Collect discrete choices in all True alternatives
7889 Choices := New_List;
7890 Alt := First (Alternatives (Exp));
7891 while Present (Alt) loop
7892 Dep := Expression (Alt);
7894 if not Is_OK_Static_Expression (Dep) then
7897 elsif Is_True (Expr_Value (Dep)) then
7898 Append_List_To (Choices,
7899 New_Copy_List (Discrete_Choices (Alt)));
7905 return Membership_Entries (First (Choices));
7908 -- Expression with actions: if no actions, dig out expression
7910 when N_Expression_With_Actions =>
7911 if Is_Empty_List (Actions (Exp)) then
7912 return Get_RList (Expression (Exp));
7920 return (Get_RList (Left_Opnd (Exp))
7921 and not Get_RList (Right_Opnd (Exp)))
7922 or (Get_RList (Right_Opnd (Exp))
7923 and not Get_RList (Left_Opnd (Exp)));
7925 -- Any other node type is non-static
7936 function Hi_Val (N : Node_Id) return Uint is
7938 if Is_OK_Static_Expression (N) then
7939 return Expr_Value (N);
7941 pragma Assert (Nkind (N) = N_Range);
7942 return Expr_Value (High_Bound (N));
7950 function Is_False (R : RList) return Boolean is
7952 return R'Length = 0;
7959 function Is_True (R : RList) return Boolean is
7962 and then R (R'First).Lo = BLo
7963 and then R (R'First).Hi = BHi;
7970 function Is_Type_Ref (N : Node_Id) return Boolean is
7972 return Nkind (N) = N_Identifier
7973 and then Chars (N) = Nam
7974 and then Paren_Count (N) = 0;
7981 function Lo_Val (N : Node_Id) return Uint is
7983 if Is_OK_Static_Expression (N) then
7984 return Expr_Value (N);
7986 pragma Assert (Nkind (N) = N_Range);
7987 return Expr_Value (Low_Bound (N));
7991 ------------------------
7992 -- Membership_Entries --
7993 ------------------------
7995 function Membership_Entries (N : Node_Id) return RList is
7997 if No (Next (N)) then
7998 return Membership_Entry (N);
8000 return Membership_Entry (N) or Membership_Entries (Next (N));
8002 end Membership_Entries;
8004 ----------------------
8005 -- Membership_Entry --
8006 ----------------------
8008 function Membership_Entry (N : Node_Id) return RList is
8016 if Nkind (N) = N_Range then
8017 if not Is_OK_Static_Expression (Low_Bound (N))
8019 not Is_OK_Static_Expression (High_Bound (N))
8023 SLo := Expr_Value (Low_Bound (N));
8024 SHi := Expr_Value (High_Bound (N));
8025 return RList'(1 => REnt
'(SLo, SHi));
8028 -- Static expression case
8030 elsif Is_OK_Static_Expression (N) then
8031 Val := Expr_Value (N);
8032 return RList'(1 => REnt
'(Val, Val));
8034 -- Identifier (other than static expression) case
8036 else pragma Assert (Nkind (N) = N_Identifier);
8040 if Is_Type (Entity (N)) then
8042 -- If type has predicates, process them
8044 if Has_Predicates (Entity (N)) then
8045 return Stat_Pred (Entity (N));
8047 -- For static subtype without predicates, get range
8049 elsif Is_OK_Static_Subtype (Entity (N)) then
8050 SLo := Expr_Value (Type_Low_Bound (Entity (N)));
8051 SHi := Expr_Value (Type_High_Bound (Entity (N)));
8052 return RList'(1 => REnt
'(SLo, SHi));
8054 -- Any other type makes us non-static
8060 -- Any other kind of identifier in predicate (e.g. a non-static
8061 -- expression value) means this is not a static predicate.
8067 end Membership_Entry;
8073 function Stat_Pred (Typ : Entity_Id) return RList is
8075 -- Not static if type does not have static predicates
8077 if not Has_Static_Predicate (Typ) then
8081 -- Otherwise we convert the predicate list to a range list
8084 Spred : constant List_Id := Static_Discrete_Predicate (Typ);
8085 Result : RList (1 .. List_Length (Spred));
8089 P := First (Static_Discrete_Predicate (Typ));
8090 for J in Result'Range loop
8091 Result (J) := REnt'(Lo_Val
(P
), Hi_Val
(P
));
8099 -- Start of processing for Build_Discrete_Static_Predicate
8102 -- Establish bounds for the predicate
8104 if Compile_Time_Known_Value
(Type_Low_Bound
(Typ
)) then
8105 TLo
:= Expr_Value
(Type_Low_Bound
(Typ
));
8110 if Compile_Time_Known_Value
(Type_High_Bound
(Typ
)) then
8111 THi
:= Expr_Value
(Type_High_Bound
(Typ
));
8116 -- Analyze the expression to see if it is a static predicate
8119 Ranges
: constant RList
:= Get_RList
(Expr
);
8120 -- Range list from expression if it is static
8125 -- Convert range list into a form for the static predicate. In the
8126 -- Ranges array, we just have raw ranges, these must be converted
8127 -- to properly typed and analyzed static expressions or range nodes.
8129 -- Note: here we limit ranges to the ranges of the subtype, so that
8130 -- a predicate is always false for values outside the subtype. That
8131 -- seems fine, such values are invalid anyway, and considering them
8132 -- to fail the predicate seems allowed and friendly, and furthermore
8133 -- simplifies processing for case statements and loops.
8137 for J
in Ranges
'Range loop
8139 Lo
: Uint
:= Ranges
(J
).Lo
;
8140 Hi
: Uint
:= Ranges
(J
).Hi
;
8143 -- Ignore completely out of range entry
8145 if Hi
< TLo
or else Lo
> THi
then
8148 -- Otherwise process entry
8151 -- Adjust out of range value to subtype range
8161 -- Convert range into required form
8163 Append_To
(Plist
, Build_Range
(Lo
, Hi
));
8168 -- Processing was successful and all entries were static, so now we
8169 -- can store the result as the predicate list.
8171 Set_Static_Discrete_Predicate
(Typ
, Plist
);
8173 -- The processing for static predicates put the expression into
8174 -- canonical form as a series of ranges. It also eliminated
8175 -- duplicates and collapsed and combined ranges. We might as well
8176 -- replace the alternatives list of the right operand of the
8177 -- membership test with the static predicate list, which will
8178 -- usually be more efficient.
8181 New_Alts
: constant List_Id
:= New_List
;
8186 Old_Node
:= First
(Plist
);
8187 while Present
(Old_Node
) loop
8188 New_Node
:= New_Copy
(Old_Node
);
8190 if Nkind
(New_Node
) = N_Range
then
8191 Set_Low_Bound
(New_Node
, New_Copy
(Low_Bound
(Old_Node
)));
8192 Set_High_Bound
(New_Node
, New_Copy
(High_Bound
(Old_Node
)));
8195 Append_To
(New_Alts
, New_Node
);
8199 -- If empty list, replace by False
8201 if Is_Empty_List
(New_Alts
) then
8202 Rewrite
(Expr
, New_Occurrence_Of
(Standard_False
, Loc
));
8204 -- Else replace by set membership test
8209 Left_Opnd
=> Make_Identifier
(Loc
, Nam
),
8210 Right_Opnd
=> Empty
,
8211 Alternatives
=> New_Alts
));
8213 -- Resolve new expression in function context
8215 Install_Formals
(Predicate_Function
(Typ
));
8216 Push_Scope
(Predicate_Function
(Typ
));
8217 Analyze_And_Resolve
(Expr
, Standard_Boolean
);
8223 -- If non-static, return doing nothing
8228 end Build_Discrete_Static_Predicate
;
8230 --------------------------------
8231 -- Build_Export_Import_Pragma --
8232 --------------------------------
8234 function Build_Export_Import_Pragma
8236 Id
: Entity_Id
) return Node_Id
8238 Asp_Id
: constant Aspect_Id
:= Get_Aspect_Id
(Asp
);
8239 Expr
: constant Node_Id
:= Expression
(Asp
);
8240 Loc
: constant Source_Ptr
:= Sloc
(Asp
);
8251 Create_Pragma
: Boolean := False;
8252 -- This flag is set when the aspect form is such that it warrants the
8253 -- creation of a corresponding pragma.
8256 if Present
(Expr
) then
8257 if Error_Posted
(Expr
) then
8260 elsif Is_True
(Expr_Value
(Expr
)) then
8261 Create_Pragma
:= True;
8264 -- Otherwise the aspect defaults to True
8267 Create_Pragma
:= True;
8270 -- Nothing to do when the expression is False or is erroneous
8272 if not Create_Pragma
then
8276 -- Obtain all interfacing aspects that apply to the related entity
8278 Get_Interfacing_Aspects
8282 Expo_Asp
=> Dummy_1
,
8288 -- Handle the convention argument
8290 if Present
(Conv
) then
8291 Conv_Arg
:= New_Copy_Tree
(Expression
(Conv
));
8293 -- Assume convention "Ada' when aspect Convention is missing
8296 Conv_Arg
:= Make_Identifier
(Loc
, Name_Ada
);
8300 Make_Pragma_Argument_Association
(Loc
,
8301 Chars
=> Name_Convention
,
8302 Expression
=> Conv_Arg
));
8304 -- Handle the entity argument
8307 Make_Pragma_Argument_Association
(Loc
,
8308 Chars
=> Name_Entity
,
8309 Expression
=> New_Occurrence_Of
(Id
, Loc
)));
8311 -- Handle the External_Name argument
8313 if Present
(EN
) then
8315 Make_Pragma_Argument_Association
(Loc
,
8316 Chars
=> Name_External_Name
,
8317 Expression
=> New_Copy_Tree
(Expression
(EN
))));
8320 -- Handle the Link_Name argument
8322 if Present
(LN
) then
8324 Make_Pragma_Argument_Association
(Loc
,
8325 Chars
=> Name_Link_Name
,
8326 Expression
=> New_Copy_Tree
(Expression
(LN
))));
8330 -- pragma Export/Import
8331 -- (Convention => <Conv>/Ada,
8333 -- [External_Name => <EN>,]
8334 -- [Link_Name => <LN>]);
8338 Pragma_Identifier
=>
8339 Make_Identifier
(Loc
, Chars
(Identifier
(Asp
))),
8340 Pragma_Argument_Associations
=> Args
);
8342 -- Decorate the relevant aspect and the pragma
8344 Set_Aspect_Rep_Item
(Asp
, Prag
);
8346 Set_Corresponding_Aspect
(Prag
, Asp
);
8347 Set_From_Aspect_Specification
(Prag
);
8348 Set_Parent
(Prag
, Asp
);
8350 if Asp_Id
= Aspect_Import
and then Is_Subprogram
(Id
) then
8351 Set_Import_Pragma
(Id
, Prag
);
8355 end Build_Export_Import_Pragma
;
8357 -------------------------------
8358 -- Build_Predicate_Functions --
8359 -------------------------------
8361 -- The functions that are constructed here have the form:
8363 -- function typPredicate (Ixxx : typ) return Boolean is
8366 -- typ1Predicate (typ1 (Ixxx))
8367 -- and then typ2Predicate (typ2 (Ixxx))
8369 -- and then exp1 and then exp2 and then ...;
8370 -- end typPredicate;
8372 -- Here exp1, and exp2 are expressions from Predicate pragmas. Note that
8373 -- this is the point at which these expressions get analyzed, providing the
8374 -- required delay, and typ1, typ2, are entities from which predicates are
8375 -- inherited. Note that we do NOT generate Check pragmas, that's because we
8376 -- use this function even if checks are off, e.g. for membership tests.
8378 -- Note that the inherited predicates are evaluated first, as required by
8381 -- Note that Sem_Eval.Real_Or_String_Static_Predicate_Matches depends on
8382 -- the form of this return expression.
8384 -- If the expression has at least one Raise_Expression, then we also build
8385 -- the typPredicateM version of the function, in which any occurrence of a
8386 -- Raise_Expression is converted to "return False".
8388 -- WARNING: This routine manages Ghost regions. Return statements must be
8389 -- replaced by gotos which jump to the end of the routine and restore the
8392 procedure Build_Predicate_Functions
(Typ
: Entity_Id
; N
: Node_Id
) is
8393 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
8396 -- This is the expression for the result of the function. It is
8397 -- is build by connecting the component predicates with AND THEN.
8399 Expr_M
: Node_Id
:= Empty
; -- init to avoid warning
8400 -- This is the corresponding return expression for the Predicate_M
8401 -- function. It differs in that raise expressions are marked for
8402 -- special expansion (see Process_REs).
8404 Object_Name
: Name_Id
;
8405 -- Name for argument of Predicate procedure. Note that we use the same
8406 -- name for both predicate functions. That way the reference within the
8407 -- predicate expression is the same in both functions.
8409 Object_Entity
: Entity_Id
;
8410 -- Entity for argument of Predicate procedure
8412 Object_Entity_M
: Entity_Id
;
8413 -- Entity for argument of separate Predicate procedure when exceptions
8414 -- are present in expression.
8417 -- The function declaration
8422 Raise_Expression_Present
: Boolean := False;
8423 -- Set True if Expr has at least one Raise_Expression
8425 procedure Add_Condition
(Cond
: Node_Id
);
8426 -- Append Cond to Expr using "and then" (or just copy Cond to Expr if
8429 procedure Add_Predicates
;
8430 -- Appends expressions for any Predicate pragmas in the rep item chain
8431 -- Typ to Expr. Note that we look only at items for this exact entity.
8432 -- Inheritance of predicates for the parent type is done by calling the
8433 -- Predicate_Function of the parent type, using Add_Call above.
8435 procedure Add_Call
(T
: Entity_Id
);
8436 -- Includes a call to the predicate function for type T in Expr if T
8437 -- has predicates and Predicate_Function (T) is non-empty.
8439 function Process_RE
(N
: Node_Id
) return Traverse_Result
;
8440 -- Used in Process REs, tests if node N is a raise expression, and if
8441 -- so, marks it to be converted to return False.
8443 procedure Process_REs
is new Traverse_Proc
(Process_RE
);
8444 -- Marks any raise expressions in Expr_M to return False
8446 function Test_RE
(N
: Node_Id
) return Traverse_Result
;
8447 -- Used in Test_REs, tests one node for being a raise expression, and if
8448 -- so sets Raise_Expression_Present True.
8450 procedure Test_REs
is new Traverse_Proc
(Test_RE
);
8451 -- Tests to see if Expr contains any raise expressions
8457 procedure Add_Call
(T
: Entity_Id
) is
8461 if Present
(T
) and then Present
(Predicate_Function
(T
)) then
8462 Set_Has_Predicates
(Typ
);
8464 -- Build the call to the predicate function of T. The type may be
8465 -- derived, so use an unchecked conversion for the actual.
8471 Unchecked_Convert_To
(T
,
8472 Make_Identifier
(Loc
, Object_Name
)));
8474 -- "and"-in the call to evolving expression
8476 Add_Condition
(Exp
);
8478 -- Output info message on inheritance if required. Note we do not
8479 -- give this information for generic actual types, since it is
8480 -- unwelcome noise in that case in instantiations. We also
8481 -- generally suppress the message in instantiations, and also
8482 -- if it involves internal names.
8484 if Opt
.List_Inherited_Aspects
8485 and then not Is_Generic_Actual_Type
(Typ
)
8486 and then Instantiation_Depth
(Sloc
(Typ
)) = 0
8487 and then not Is_Internal_Name
(Chars
(T
))
8488 and then not Is_Internal_Name
(Chars
(Typ
))
8490 Error_Msg_Sloc
:= Sloc
(Predicate_Function
(T
));
8491 Error_Msg_Node_2
:= T
;
8492 Error_Msg_N
("info: & inherits predicate from & #?L?", Typ
);
8501 procedure Add_Condition
(Cond
: Node_Id
) is
8503 -- This is the first predicate expression
8508 -- Otherwise concatenate to the existing predicate expressions by
8509 -- using "and then".
8514 Left_Opnd
=> Relocate_Node
(Expr
),
8515 Right_Opnd
=> Cond
);
8519 --------------------
8520 -- Add_Predicates --
8521 --------------------
8523 procedure Add_Predicates
is
8524 procedure Add_Predicate
(Prag
: Node_Id
);
8525 -- Concatenate the expression of predicate pragma Prag to Expr by
8526 -- using a short circuit "and then" operator.
8532 procedure Add_Predicate
(Prag
: Node_Id
) is
8533 procedure Replace_Type_Reference
(N
: Node_Id
);
8534 -- Replace a single occurrence N of the subtype name with a
8535 -- reference to the formal of the predicate function. N can be an
8536 -- identifier referencing the subtype, or a selected component,
8537 -- representing an appropriately qualified occurrence of the
8540 procedure Replace_Type_References
is
8541 new Replace_Type_References_Generic
(Replace_Type_Reference
);
8542 -- Traverse an expression changing every occurrence of an
8543 -- identifier whose name matches the name of the subtype with a
8544 -- reference to the formal parameter of the predicate function.
8546 ----------------------------
8547 -- Replace_Type_Reference --
8548 ----------------------------
8550 procedure Replace_Type_Reference
(N
: Node_Id
) is
8552 Rewrite
(N
, Make_Identifier
(Sloc
(N
), Object_Name
));
8553 -- Use the Sloc of the usage name, not the defining name
8556 Set_Entity
(N
, Object_Entity
);
8558 -- We want to treat the node as if it comes from source, so
8559 -- that ASIS will not ignore it.
8561 Set_Comes_From_Source
(N
, True);
8562 end Replace_Type_Reference
;
8566 Asp
: constant Node_Id
:= Corresponding_Aspect
(Prag
);
8570 -- Start of processing for Add_Predicate
8573 -- Mark corresponding SCO as enabled
8575 Set_SCO_Pragma_Enabled
(Sloc
(Prag
));
8577 -- Extract the arguments of the pragma. The expression itself
8578 -- is copied for use in the predicate function, to preserve the
8579 -- original version for ASIS use.
8581 Arg1
:= First
(Pragma_Argument_Associations
(Prag
));
8582 Arg2
:= Next
(Arg1
);
8584 Arg1
:= Get_Pragma_Arg
(Arg1
);
8585 Arg2
:= New_Copy_Tree
(Get_Pragma_Arg
(Arg2
));
8587 -- When the predicate pragma applies to the current type or its
8588 -- full view, replace all occurrences of the subtype name with
8589 -- references to the formal parameter of the predicate function.
8591 if Entity
(Arg1
) = Typ
8592 or else Full_View
(Entity
(Arg1
)) = Typ
8594 Replace_Type_References
(Arg2
, Typ
);
8596 -- If the predicate pragma comes from an aspect, replace the
8597 -- saved expression because we need the subtype references
8598 -- replaced for the calls to Preanalyze_Spec_Expression in
8599 -- Check_Aspect_At_xxx routines.
8601 if Present
(Asp
) then
8602 Set_Entity
(Identifier
(Asp
), New_Copy_Tree
(Arg2
));
8605 -- "and"-in the Arg2 condition to evolving expression
8607 Add_Condition
(Relocate_Node
(Arg2
));
8615 -- Start of processing for Add_Predicates
8618 Ritem
:= First_Rep_Item
(Typ
);
8620 -- If the type is private, check whether full view has inherited
8623 if Is_Private_Type
(Typ
) and then No
(Ritem
) then
8624 Ritem
:= First_Rep_Item
(Full_View
(Typ
));
8627 while Present
(Ritem
) loop
8628 if Nkind
(Ritem
) = N_Pragma
8629 and then Pragma_Name
(Ritem
) = Name_Predicate
8631 Add_Predicate
(Ritem
);
8633 -- If the type is declared in an inner package it may be frozen
8634 -- outside of the package, and the generated pragma has not been
8635 -- analyzed yet, so capture the expression for the predicate
8636 -- function at this point.
8638 elsif Nkind
(Ritem
) = N_Aspect_Specification
8639 and then Present
(Aspect_Rep_Item
(Ritem
))
8640 and then Scope
(Typ
) /= Current_Scope
8643 Prag
: constant Node_Id
:= Aspect_Rep_Item
(Ritem
);
8646 if Nkind
(Prag
) = N_Pragma
8647 and then Pragma_Name
(Prag
) = Name_Predicate
8649 Add_Predicate
(Prag
);
8654 Next_Rep_Item
(Ritem
);
8662 function Process_RE
(N
: Node_Id
) return Traverse_Result
is
8664 if Nkind
(N
) = N_Raise_Expression
then
8665 Set_Convert_To_Return_False
(N
);
8676 function Test_RE
(N
: Node_Id
) return Traverse_Result
is
8678 if Nkind
(N
) = N_Raise_Expression
then
8679 Raise_Expression_Present
:= True;
8688 Saved_GM
: constant Ghost_Mode_Type
:= Ghost_Mode
;
8689 Saved_IGR
: constant Node_Id
:= Ignored_Ghost_Region
;
8690 -- Save the Ghost-related attributes to restore on exit
8692 -- Start of processing for Build_Predicate_Functions
8695 -- Return if already built or if type does not have predicates
8697 SId
:= Predicate_Function
(Typ
);
8698 if not Has_Predicates
(Typ
)
8699 or else (Present
(SId
) and then Has_Completion
(SId
))
8704 -- The related type may be subject to pragma Ghost. Set the mode now to
8705 -- ensure that the predicate functions are properly marked as Ghost.
8707 Set_Ghost_Mode
(Typ
);
8709 -- Prepare to construct predicate expression
8713 if Present
(SId
) then
8714 FDecl
:= Unit_Declaration_Node
(SId
);
8717 FDecl
:= Build_Predicate_Function_Declaration
(Typ
);
8718 SId
:= Defining_Entity
(FDecl
);
8721 -- Recover name of formal parameter of function that replaces references
8722 -- to the type in predicate expressions.
8726 (First
(Parameter_Specifications
(Specification
(FDecl
))));
8728 Object_Name
:= Chars
(Object_Entity
);
8729 Object_Entity_M
:= Make_Defining_Identifier
(Loc
, Chars
=> Object_Name
);
8731 -- Add predicates for ancestor if present. These must come before the
8732 -- ones for the current type, as required by AI12-0071-1.
8737 Atyp
:= Nearest_Ancestor
(Typ
);
8739 -- The type may be private but the full view may inherit predicates
8741 if No
(Atyp
) and then Is_Private_Type
(Typ
) then
8742 Atyp
:= Nearest_Ancestor
(Full_View
(Typ
));
8745 if Present
(Atyp
) then
8750 -- Add Predicates for the current type
8754 -- Case where predicates are present
8756 if Present
(Expr
) then
8758 -- Test for raise expression present
8762 -- If raise expression is present, capture a copy of Expr for use
8763 -- in building the predicateM function version later on. For this
8764 -- copy we replace references to Object_Entity by Object_Entity_M.
8766 if Raise_Expression_Present
then
8768 function Reset_Loop_Variable
8769 (N
: Node_Id
) return Traverse_Result
;
8771 procedure Reset_Loop_Variables
is
8772 new Traverse_Proc
(Reset_Loop_Variable
);
8774 ------------------------
8775 -- Reset_Loop_Variable --
8776 ------------------------
8778 function Reset_Loop_Variable
8779 (N
: Node_Id
) return Traverse_Result
8782 if Nkind
(N
) = N_Iterator_Specification
then
8783 Set_Defining_Identifier
(N
,
8784 Make_Defining_Identifier
8785 (Sloc
(N
), Chars
(Defining_Identifier
(N
))));
8789 end Reset_Loop_Variable
;
8793 Map
: constant Elist_Id
:= New_Elmt_List
;
8796 Append_Elmt
(Object_Entity
, Map
);
8797 Append_Elmt
(Object_Entity_M
, Map
);
8798 Expr_M
:= New_Copy_Tree
(Expr
, Map
=> Map
);
8800 -- The unanalyzed expression will be copied and appear in
8801 -- both functions. Normally expressions do not declare new
8802 -- entities, but quantified expressions do, so we need to
8803 -- create new entities for their bound variables, to prevent
8804 -- multiple definitions in gigi.
8806 Reset_Loop_Variables
(Expr_M
);
8810 -- Build the main predicate function
8813 SIdB
: constant Entity_Id
:=
8814 Make_Defining_Identifier
(Loc
,
8815 Chars
=> New_External_Name
(Chars
(Typ
), "Predicate"));
8816 -- The entity for the function body
8822 Set_Ekind
(SIdB
, E_Function
);
8823 Set_Is_Predicate_Function
(SIdB
);
8825 -- The predicate function is shared between views of a type
8827 if Is_Private_Type
(Typ
) and then Present
(Full_View
(Typ
)) then
8828 Set_Predicate_Function
(Full_View
(Typ
), SId
);
8831 -- Build function body
8834 Make_Function_Specification
(Loc
,
8835 Defining_Unit_Name
=> SIdB
,
8836 Parameter_Specifications
=> New_List
(
8837 Make_Parameter_Specification
(Loc
,
8838 Defining_Identifier
=>
8839 Make_Defining_Identifier
(Loc
, Object_Name
),
8841 New_Occurrence_Of
(Typ
, Loc
))),
8842 Result_Definition
=>
8843 New_Occurrence_Of
(Standard_Boolean
, Loc
));
8846 Make_Subprogram_Body
(Loc
,
8847 Specification
=> Spec
,
8848 Declarations
=> Empty_List
,
8849 Handled_Statement_Sequence
=>
8850 Make_Handled_Sequence_Of_Statements
(Loc
,
8851 Statements
=> New_List
(
8852 Make_Simple_Return_Statement
(Loc
,
8853 Expression
=> Expr
))));
8855 -- The declaration has been analyzed when created, and placed
8856 -- after type declaration. Insert body itself after freeze node.
8858 Insert_After_And_Analyze
(N
, FBody
);
8860 -- The defining identifier of a quantified expression carries the
8861 -- scope in which the type appears, but when unnesting we need
8862 -- to indicate that its proper scope is the constructed predicate
8863 -- function. The quantified expressions have been converted into
8864 -- loops during analysis and expansion.
8867 function Reset_Quantified_Variable_Scope
8868 (N
: Node_Id
) return Traverse_Result
;
8870 procedure Reset_Quantified_Variables_Scope
is
8871 new Traverse_Proc
(Reset_Quantified_Variable_Scope
);
8873 -------------------------------------
8874 -- Reset_Quantified_Variable_Scope --
8875 -------------------------------------
8877 function Reset_Quantified_Variable_Scope
8878 (N
: Node_Id
) return Traverse_Result
8881 if Nkind_In
(N
, N_Iterator_Specification
,
8882 N_Loop_Parameter_Specification
)
8884 Set_Scope
(Defining_Identifier
(N
),
8885 Predicate_Function
(Typ
));
8889 end Reset_Quantified_Variable_Scope
;
8892 if Unnest_Subprogram_Mode
then
8893 Reset_Quantified_Variables_Scope
(Expr
);
8897 -- within a generic unit, prevent a double analysis of the body
8898 -- which will not be marked analyzed yet. This will happen when
8899 -- the freeze node is created during the preanalysis of an
8900 -- expression function.
8902 if Inside_A_Generic
then
8903 Set_Analyzed
(FBody
);
8906 -- Static predicate functions are always side-effect free, and
8907 -- in most cases dynamic predicate functions are as well. Mark
8908 -- them as such whenever possible, so redundant predicate checks
8909 -- can be optimized. If there is a variable reference within the
8910 -- expression, the function is not pure.
8912 if Expander_Active
then
8914 Side_Effect_Free
(Expr
, Variable_Ref
=> True));
8915 Set_Is_Inlined
(SId
);
8919 -- Test for raise expressions present and if so build M version
8921 if Raise_Expression_Present
then
8923 SId
: constant Entity_Id
:=
8924 Make_Defining_Identifier
(Loc
,
8925 Chars
=> New_External_Name
(Chars
(Typ
), "PredicateM"));
8926 -- The entity for the function spec
8928 SIdB
: constant Entity_Id
:=
8929 Make_Defining_Identifier
(Loc
,
8930 Chars
=> New_External_Name
(Chars
(Typ
), "PredicateM"));
8931 -- The entity for the function body
8939 -- Mark any raise expressions for special expansion
8941 Process_REs
(Expr_M
);
8943 -- Build function declaration
8945 Set_Ekind
(SId
, E_Function
);
8946 Set_Is_Predicate_Function_M
(SId
);
8947 Set_Predicate_Function_M
(Typ
, SId
);
8949 -- The predicate function is shared between views of a type
8951 if Is_Private_Type
(Typ
) and then Present
(Full_View
(Typ
)) then
8952 Set_Predicate_Function_M
(Full_View
(Typ
), SId
);
8956 Make_Function_Specification
(Loc
,
8957 Defining_Unit_Name
=> SId
,
8958 Parameter_Specifications
=> New_List
(
8959 Make_Parameter_Specification
(Loc
,
8960 Defining_Identifier
=> Object_Entity_M
,
8961 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
))),
8962 Result_Definition
=>
8963 New_Occurrence_Of
(Standard_Boolean
, Loc
));
8966 Make_Subprogram_Declaration
(Loc
,
8967 Specification
=> Spec
);
8969 -- Build function body
8972 Make_Function_Specification
(Loc
,
8973 Defining_Unit_Name
=> SIdB
,
8974 Parameter_Specifications
=> New_List
(
8975 Make_Parameter_Specification
(Loc
,
8976 Defining_Identifier
=>
8977 Make_Defining_Identifier
(Loc
, Object_Name
),
8979 New_Occurrence_Of
(Typ
, Loc
))),
8980 Result_Definition
=>
8981 New_Occurrence_Of
(Standard_Boolean
, Loc
));
8983 -- Build the body, we declare the boolean expression before
8984 -- doing the return, because we are not really confident of
8985 -- what happens if a return appears within a return.
8988 Make_Defining_Identifier
(Loc
,
8989 Chars
=> New_Internal_Name
('B'));
8992 Make_Subprogram_Body
(Loc
,
8993 Specification
=> Spec
,
8995 Declarations
=> New_List
(
8996 Make_Object_Declaration
(Loc
,
8997 Defining_Identifier
=> BTemp
,
8998 Constant_Present
=> True,
8999 Object_Definition
=>
9000 New_Occurrence_Of
(Standard_Boolean
, Loc
),
9001 Expression
=> Expr_M
)),
9003 Handled_Statement_Sequence
=>
9004 Make_Handled_Sequence_Of_Statements
(Loc
,
9005 Statements
=> New_List
(
9006 Make_Simple_Return_Statement
(Loc
,
9007 Expression
=> New_Occurrence_Of
(BTemp
, Loc
)))));
9009 -- Insert declaration before freeze node and body after
9011 Insert_Before_And_Analyze
(N
, FDecl
);
9012 Insert_After_And_Analyze
(N
, FBody
);
9014 -- Should quantified expressions be handled here as well ???
9018 -- See if we have a static predicate. Note that the answer may be
9019 -- yes even if we have an explicit Dynamic_Predicate present.
9026 if not Is_Scalar_Type
(Typ
) and then not Is_String_Type
(Typ
) then
9029 PS
:= Is_Predicate_Static
(Expr
, Object_Name
);
9032 -- Case where we have a predicate-static aspect
9036 -- We don't set Has_Static_Predicate_Aspect, since we can have
9037 -- any of the three cases (Predicate, Dynamic_Predicate, or
9038 -- Static_Predicate) generating a predicate with an expression
9039 -- that is predicate-static. We just indicate that we have a
9040 -- predicate that can be treated as static.
9042 Set_Has_Static_Predicate
(Typ
);
9044 -- For discrete subtype, build the static predicate list
9046 if Is_Discrete_Type
(Typ
) then
9047 Build_Discrete_Static_Predicate
(Typ
, Expr
, Object_Name
);
9049 -- If we don't get a static predicate list, it means that we
9050 -- have a case where this is not possible, most typically in
9051 -- the case where we inherit a dynamic predicate. We do not
9052 -- consider this an error, we just leave the predicate as
9053 -- dynamic. But if we do succeed in building the list, then
9054 -- we mark the predicate as static.
9056 if No
(Static_Discrete_Predicate
(Typ
)) then
9057 Set_Has_Static_Predicate
(Typ
, False);
9060 -- For real or string subtype, save predicate expression
9062 elsif Is_Real_Type
(Typ
) or else Is_String_Type
(Typ
) then
9063 Set_Static_Real_Or_String_Predicate
(Typ
, Expr
);
9066 -- Case of dynamic predicate (expression is not predicate-static)
9069 -- Again, we don't set Has_Dynamic_Predicate_Aspect, since that
9070 -- is only set if we have an explicit Dynamic_Predicate aspect
9071 -- given. Here we may simply have a Predicate aspect where the
9072 -- expression happens not to be predicate-static.
9074 -- Emit an error when the predicate is categorized as static
9075 -- but its expression is not predicate-static.
9077 -- First a little fiddling to get a nice location for the
9078 -- message. If the expression is of the form (A and then B),
9079 -- where A is an inherited predicate, then use the right
9080 -- operand for the Sloc. This avoids getting confused by a call
9081 -- to an inherited predicate with a less convenient source
9085 while Nkind
(EN
) = N_And_Then
9086 and then Nkind
(Left_Opnd
(EN
)) = N_Function_Call
9087 and then Is_Predicate_Function
9088 (Entity
(Name
(Left_Opnd
(EN
))))
9090 EN
:= Right_Opnd
(EN
);
9093 -- Now post appropriate message
9095 if Has_Static_Predicate_Aspect
(Typ
) then
9096 if Is_Scalar_Type
(Typ
) or else Is_String_Type
(Typ
) then
9098 ("expression is not predicate-static (RM 3.2.4(16-22))",
9102 ("static predicate requires scalar or string type", EN
);
9109 Restore_Ghost_Region
(Saved_GM
, Saved_IGR
);
9110 end Build_Predicate_Functions
;
9112 ------------------------------------------
9113 -- Build_Predicate_Function_Declaration --
9114 ------------------------------------------
9116 -- WARNING: This routine manages Ghost regions. Return statements must be
9117 -- replaced by gotos which jump to the end of the routine and restore the
9120 function Build_Predicate_Function_Declaration
9121 (Typ
: Entity_Id
) return Node_Id
9123 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
9125 Saved_GM
: constant Ghost_Mode_Type
:= Ghost_Mode
;
9126 Saved_IGR
: constant Node_Id
:= Ignored_Ghost_Region
;
9127 -- Save the Ghost-related attributes to restore on exit
9129 Func_Decl
: Node_Id
;
9130 Func_Id
: Entity_Id
;
9134 -- The related type may be subject to pragma Ghost. Set the mode now to
9135 -- ensure that the predicate functions are properly marked as Ghost.
9137 Set_Ghost_Mode
(Typ
);
9140 Make_Defining_Identifier
(Loc
,
9141 Chars
=> New_External_Name
(Chars
(Typ
), "Predicate"));
9143 -- The predicate function requires debug info when the predicates are
9144 -- subject to Source Coverage Obligations.
9146 if Opt
.Generate_SCO
then
9147 Set_Debug_Info_Needed
(Func_Id
);
9151 Make_Function_Specification
(Loc
,
9152 Defining_Unit_Name
=> Func_Id
,
9153 Parameter_Specifications
=> New_List
(
9154 Make_Parameter_Specification
(Loc
,
9155 Defining_Identifier
=> Make_Temporary
(Loc
, 'I'),
9156 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
))),
9157 Result_Definition
=>
9158 New_Occurrence_Of
(Standard_Boolean
, Loc
));
9160 Func_Decl
:= Make_Subprogram_Declaration
(Loc
, Specification
=> Spec
);
9162 Set_Ekind
(Func_Id
, E_Function
);
9163 Set_Etype
(Func_Id
, Standard_Boolean
);
9164 Set_Is_Internal
(Func_Id
);
9165 Set_Is_Predicate_Function
(Func_Id
);
9166 Set_Predicate_Function
(Typ
, Func_Id
);
9168 Insert_After
(Parent
(Typ
), Func_Decl
);
9169 Analyze
(Func_Decl
);
9171 Restore_Ghost_Region
(Saved_GM
, Saved_IGR
);
9174 end Build_Predicate_Function_Declaration
;
9176 -----------------------------------------
9177 -- Check_Aspect_At_End_Of_Declarations --
9178 -----------------------------------------
9180 procedure Check_Aspect_At_End_Of_Declarations
(ASN
: Node_Id
) is
9181 Ent
: constant Entity_Id
:= Entity
(ASN
);
9182 Ident
: constant Node_Id
:= Identifier
(ASN
);
9183 A_Id
: constant Aspect_Id
:= Get_Aspect_Id
(Chars
(Ident
));
9185 End_Decl_Expr
: constant Node_Id
:= Entity
(Ident
);
9186 -- Expression to be analyzed at end of declarations
9188 Freeze_Expr
: constant Node_Id
:= Expression
(ASN
);
9189 -- Expression from call to Check_Aspect_At_Freeze_Point.
9191 T
: constant Entity_Id
:= Etype
(Original_Node
(Freeze_Expr
));
9192 -- Type required for preanalyze call. We use the original expression to
9193 -- get the proper type, to prevent cascaded errors when the expression
9194 -- is constant-folded.
9197 -- Set False if error
9199 -- On entry to this procedure, Entity (Ident) contains a copy of the
9200 -- original expression from the aspect, saved for this purpose, and
9201 -- but Expression (Ident) is a preanalyzed copy of the expression,
9202 -- preanalyzed just after the freeze point.
9204 procedure Check_Overloaded_Name
;
9205 -- For aspects whose expression is simply a name, this routine checks if
9206 -- the name is overloaded or not. If so, it verifies there is an
9207 -- interpretation that matches the entity obtained at the freeze point,
9208 -- otherwise the compiler complains.
9210 ---------------------------
9211 -- Check_Overloaded_Name --
9212 ---------------------------
9214 procedure Check_Overloaded_Name
is
9216 if not Is_Overloaded
(End_Decl_Expr
) then
9217 Err
:= not Is_Entity_Name
(End_Decl_Expr
)
9218 or else Entity
(End_Decl_Expr
) /= Entity
(Freeze_Expr
);
9224 Index
: Interp_Index
;
9228 Get_First_Interp
(End_Decl_Expr
, Index
, It
);
9229 while Present
(It
.Typ
) loop
9230 if It
.Nam
= Entity
(Freeze_Expr
) then
9235 Get_Next_Interp
(Index
, It
);
9239 end Check_Overloaded_Name
;
9241 -- Start of processing for Check_Aspect_At_End_Of_Declarations
9244 -- In an instance we do not perform the consistency check between freeze
9245 -- point and end of declarations, because it was done already in the
9246 -- analysis of the generic. Furthermore, the delayed analysis of an
9247 -- aspect of the instance may produce spurious errors when the generic
9248 -- is a child unit that references entities in the parent (which might
9249 -- not be in scope at the freeze point of the instance).
9254 -- The enclosing scope may have been rewritten during expansion (.e.g. a
9255 -- task body is rewritten as a procedure) after this conformance check
9256 -- has been performed, so do not perform it again (it may not easily be
9257 -- done if full visibility of local entities is not available).
9259 elsif not Comes_From_Source
(Current_Scope
) then
9262 -- Case of aspects Dimension, Dimension_System and Synchronization
9264 elsif A_Id
= Aspect_Synchronization
then
9267 -- Case of stream attributes, just have to compare entities. However,
9268 -- the expression is just a name (possibly overloaded), and there may
9269 -- be stream operations declared for unrelated types, so we just need
9270 -- to verify that one of these interpretations is the one available at
9271 -- at the freeze point.
9273 elsif A_Id
= Aspect_Input
or else
9274 A_Id
= Aspect_Output
or else
9275 A_Id
= Aspect_Read
or else
9278 Analyze
(End_Decl_Expr
);
9279 Check_Overloaded_Name
;
9281 elsif A_Id
= Aspect_Variable_Indexing
or else
9282 A_Id
= Aspect_Constant_Indexing
or else
9283 A_Id
= Aspect_Default_Iterator
or else
9284 A_Id
= Aspect_Iterator_Element
9286 -- Make type unfrozen before analysis, to prevent spurious errors
9287 -- about late attributes.
9289 Set_Is_Frozen
(Ent
, False);
9290 Analyze
(End_Decl_Expr
);
9291 Set_Is_Frozen
(Ent
, True);
9293 -- If the end of declarations comes before any other freeze
9294 -- point, the Freeze_Expr is not analyzed: no check needed.
9296 if Analyzed
(Freeze_Expr
) and then not In_Instance
then
9297 Check_Overloaded_Name
;
9305 -- Indicate that the expression comes from an aspect specification,
9306 -- which is used in subsequent analysis even if expansion is off.
9308 Set_Parent
(End_Decl_Expr
, ASN
);
9310 -- In a generic context the aspect expressions have not been
9311 -- preanalyzed, so do it now. There are no conformance checks
9312 -- to perform in this case.
9315 Check_Aspect_At_Freeze_Point
(ASN
);
9318 -- The default values attributes may be defined in the private part,
9319 -- and the analysis of the expression may take place when only the
9320 -- partial view is visible. The expression must be scalar, so use
9321 -- the full view to resolve.
9323 elsif (A_Id
= Aspect_Default_Value
9325 A_Id
= Aspect_Default_Component_Value
)
9326 and then Is_Private_Type
(T
)
9328 Preanalyze_Spec_Expression
(End_Decl_Expr
, Full_View
(T
));
9331 Preanalyze_Spec_Expression
(End_Decl_Expr
, T
);
9334 Err
:= not Fully_Conformant_Expressions
(End_Decl_Expr
, Freeze_Expr
);
9337 -- Output error message if error. Force error on aspect specification
9338 -- even if there is an error on the expression itself.
9342 ("!visibility of aspect for& changes after freeze point",
9345 ("info: & is frozen here, aspects evaluated at this point??",
9346 Freeze_Node
(Ent
), Ent
);
9348 end Check_Aspect_At_End_Of_Declarations
;
9350 ----------------------------------
9351 -- Check_Aspect_At_Freeze_Point --
9352 ----------------------------------
9354 procedure Check_Aspect_At_Freeze_Point
(ASN
: Node_Id
) is
9355 Ident
: constant Node_Id
:= Identifier
(ASN
);
9356 -- Identifier (use Entity field to save expression)
9358 A_Id
: constant Aspect_Id
:= Get_Aspect_Id
(Chars
(Ident
));
9360 T
: Entity_Id
:= Empty
;
9361 -- Type required for preanalyze call
9364 -- On entry to this procedure, Entity (Ident) contains a copy of the
9365 -- original expression from the aspect, saved for this purpose.
9367 -- On exit from this procedure Entity (Ident) is unchanged, still
9368 -- containing that copy, but Expression (Ident) is a preanalyzed copy
9369 -- of the expression, preanalyzed just after the freeze point.
9371 -- Make a copy of the expression to be preanalyzed
9373 Set_Expression
(ASN
, New_Copy_Tree
(Entity
(Ident
)));
9375 -- Find type for preanalyze call
9379 -- No_Aspect should be impossible
9382 raise Program_Error
;
9384 -- Aspects taking an optional boolean argument
9386 when Boolean_Aspects
9387 | Library_Unit_Aspects
9389 T
:= Standard_Boolean
;
9391 -- Aspects corresponding to attribute definition clauses
9393 when Aspect_Address
=>
9394 T
:= RTE
(RE_Address
);
9396 when Aspect_Attach_Handler
=>
9397 T
:= RTE
(RE_Interrupt_ID
);
9399 when Aspect_Bit_Order
9400 | Aspect_Scalar_Storage_Order
9402 T
:= RTE
(RE_Bit_Order
);
9404 when Aspect_Convention
=>
9408 T
:= RTE
(RE_CPU_Range
);
9410 -- Default_Component_Value is resolved with the component type
9412 when Aspect_Default_Component_Value
=>
9413 T
:= Component_Type
(Entity
(ASN
));
9415 when Aspect_Default_Storage_Pool
=>
9416 T
:= Class_Wide_Type
(RTE
(RE_Root_Storage_Pool
));
9418 -- Default_Value is resolved with the type entity in question
9420 when Aspect_Default_Value
=>
9423 when Aspect_Dispatching_Domain
=>
9424 T
:= RTE
(RE_Dispatching_Domain
);
9426 when Aspect_External_Tag
=>
9427 T
:= Standard_String
;
9429 when Aspect_External_Name
=>
9430 T
:= Standard_String
;
9432 when Aspect_Link_Name
=>
9433 T
:= Standard_String
;
9435 when Aspect_Interrupt_Priority
9438 T
:= Standard_Integer
;
9440 when Aspect_Relative_Deadline
=>
9441 T
:= RTE
(RE_Time_Span
);
9443 when Aspect_Secondary_Stack_Size
=>
9444 T
:= Standard_Integer
;
9446 when Aspect_Small
=>
9448 -- Note that the expression can be of any real type (not just a
9449 -- real universal literal) as long as it is a static constant.
9453 -- For a simple storage pool, we have to retrieve the type of the
9454 -- pool object associated with the aspect's corresponding attribute
9455 -- definition clause.
9457 when Aspect_Simple_Storage_Pool
=>
9458 T
:= Etype
(Expression
(Aspect_Rep_Item
(ASN
)));
9460 when Aspect_Storage_Pool
=>
9461 T
:= Class_Wide_Type
(RTE
(RE_Root_Storage_Pool
));
9463 when Aspect_Alignment
9464 | Aspect_Component_Size
9465 | Aspect_Machine_Radix
9466 | Aspect_Object_Size
9468 | Aspect_Storage_Size
9469 | Aspect_Stream_Size
9474 when Aspect_Linker_Section
=>
9475 T
:= Standard_String
;
9477 when Aspect_Synchronization
=>
9480 -- Special case, the expression of these aspects is just an entity
9481 -- that does not need any resolution, so just analyze.
9491 Analyze
(Expression
(ASN
));
9494 -- Same for Iterator aspects, where the expression is a function
9495 -- name. Legality rules are checked separately.
9497 when Aspect_Constant_Indexing
9498 | Aspect_Default_Iterator
9499 | Aspect_Iterator_Element
9500 | Aspect_Variable_Indexing
9502 Analyze
(Expression
(ASN
));
9505 -- Ditto for Iterable, legality checks in Validate_Iterable_Aspect.
9507 when Aspect_Iterable
=>
9511 Cursor
: constant Entity_Id
:= Get_Cursor_Type
(ASN
, T
);
9516 if Cursor
= Any_Type
then
9520 Assoc
:= First
(Component_Associations
(Expression
(ASN
)));
9521 while Present
(Assoc
) loop
9522 Expr
:= Expression
(Assoc
);
9525 if not Error_Posted
(Expr
) then
9526 Resolve_Iterable_Operation
9527 (Expr
, Cursor
, T
, Chars
(First
(Choices
(Assoc
))));
9536 -- Invariant/Predicate take boolean expressions
9538 when Aspect_Dynamic_Predicate
9541 | Aspect_Static_Predicate
9542 | Aspect_Type_Invariant
9544 T
:= Standard_Boolean
;
9546 when Aspect_Predicate_Failure
=>
9547 T
:= Standard_String
;
9549 -- Here is the list of aspects that don't require delay analysis
9551 when Aspect_Abstract_State
9553 | Aspect_Async_Readers
9554 | Aspect_Async_Writers
9555 | Aspect_Constant_After_Elaboration
9556 | Aspect_Contract_Cases
9557 | Aspect_Default_Initial_Condition
9560 | Aspect_Dimension_System
9561 | Aspect_Effective_Reads
9562 | Aspect_Effective_Writes
9563 | Aspect_Extensions_Visible
9566 | Aspect_Implicit_Dereference
9567 | Aspect_Initial_Condition
9568 | Aspect_Initializes
9569 | Aspect_Max_Entry_Queue_Depth
9570 | Aspect_Max_Queue_Length
9571 | Aspect_Obsolescent
9574 | Aspect_Postcondition
9576 | Aspect_Precondition
9577 | Aspect_Refined_Depends
9578 | Aspect_Refined_Global
9579 | Aspect_Refined_Post
9580 | Aspect_Refined_State
9583 | Aspect_Unimplemented
9584 | Aspect_Volatile_Function
9586 raise Program_Error
;
9590 -- Do the preanalyze call
9592 Preanalyze_Spec_Expression
(Expression
(ASN
), T
);
9593 end Check_Aspect_At_Freeze_Point
;
9595 -----------------------------------
9596 -- Check_Constant_Address_Clause --
9597 -----------------------------------
9599 procedure Check_Constant_Address_Clause
9603 procedure Check_At_Constant_Address
(Nod
: Node_Id
);
9604 -- Checks that the given node N represents a name whose 'Address is
9605 -- constant (in the same sense as OK_Constant_Address_Clause, i.e. the
9606 -- address value is the same at the point of declaration of U_Ent and at
9607 -- the time of elaboration of the address clause.
9609 procedure Check_Expr_Constants
(Nod
: Node_Id
);
9610 -- Checks that Nod meets the requirements for a constant address clause
9611 -- in the sense of the enclosing procedure.
9613 procedure Check_List_Constants
(Lst
: List_Id
);
9614 -- Check that all elements of list Lst meet the requirements for a
9615 -- constant address clause in the sense of the enclosing procedure.
9617 -------------------------------
9618 -- Check_At_Constant_Address --
9619 -------------------------------
9621 procedure Check_At_Constant_Address
(Nod
: Node_Id
) is
9623 if Is_Entity_Name
(Nod
) then
9624 if Present
(Address_Clause
(Entity
((Nod
)))) then
9626 ("invalid address clause for initialized object &!",
9629 ("address for& cannot depend on another address clause! "
9630 & "(RM 13.1(22))!", Nod
, U_Ent
);
9632 elsif In_Same_Source_Unit
(Entity
(Nod
), U_Ent
)
9633 and then Sloc
(U_Ent
) < Sloc
(Entity
(Nod
))
9636 ("invalid address clause for initialized object &!",
9638 Error_Msg_Node_2
:= U_Ent
;
9640 ("\& must be defined before & (RM 13.1(22))!",
9644 elsif Nkind
(Nod
) = N_Selected_Component
then
9646 T
: constant Entity_Id
:= Etype
(Prefix
(Nod
));
9649 if (Is_Record_Type
(T
)
9650 and then Has_Discriminants
(T
))
9653 and then Is_Record_Type
(Designated_Type
(T
))
9654 and then Has_Discriminants
(Designated_Type
(T
)))
9657 ("invalid address clause for initialized object &!",
9660 ("\address cannot depend on component of discriminated "
9661 & "record (RM 13.1(22))!", Nod
);
9663 Check_At_Constant_Address
(Prefix
(Nod
));
9667 elsif Nkind
(Nod
) = N_Indexed_Component
then
9668 Check_At_Constant_Address
(Prefix
(Nod
));
9669 Check_List_Constants
(Expressions
(Nod
));
9672 Check_Expr_Constants
(Nod
);
9674 end Check_At_Constant_Address
;
9676 --------------------------
9677 -- Check_Expr_Constants --
9678 --------------------------
9680 procedure Check_Expr_Constants
(Nod
: Node_Id
) is
9681 Loc_U_Ent
: constant Source_Ptr
:= Sloc
(U_Ent
);
9682 Ent
: Entity_Id
:= Empty
;
9685 if Nkind
(Nod
) in N_Has_Etype
9686 and then Etype
(Nod
) = Any_Type
9697 when N_Expanded_Name
9700 Ent
:= Entity
(Nod
);
9702 -- We need to look at the original node if it is different
9703 -- from the node, since we may have rewritten things and
9704 -- substituted an identifier representing the rewrite.
9706 if Is_Rewrite_Substitution
(Nod
) then
9707 Check_Expr_Constants
(Original_Node
(Nod
));
9709 -- If the node is an object declaration without initial
9710 -- value, some code has been expanded, and the expression
9711 -- is not constant, even if the constituents might be
9712 -- acceptable, as in A'Address + offset.
9714 if Ekind
(Ent
) = E_Variable
9716 Nkind
(Declaration_Node
(Ent
)) = N_Object_Declaration
9718 No
(Expression
(Declaration_Node
(Ent
)))
9721 ("invalid address clause for initialized object &!",
9724 -- If entity is constant, it may be the result of expanding
9725 -- a check. We must verify that its declaration appears
9726 -- before the object in question, else we also reject the
9729 elsif Ekind
(Ent
) = E_Constant
9730 and then In_Same_Source_Unit
(Ent
, U_Ent
)
9731 and then Sloc
(Ent
) > Loc_U_Ent
9734 ("invalid address clause for initialized object &!",
9741 -- Otherwise look at the identifier and see if it is OK
9743 if Ekind_In
(Ent
, E_Named_Integer
, E_Named_Real
)
9744 or else Is_Type
(Ent
)
9748 elsif Ekind_In
(Ent
, E_Constant
, E_In_Parameter
) then
9750 -- This is the case where we must have Ent defined before
9751 -- U_Ent. Clearly if they are in different units this
9752 -- requirement is met since the unit containing Ent is
9753 -- already processed.
9755 if not In_Same_Source_Unit
(Ent
, U_Ent
) then
9758 -- Otherwise location of Ent must be before the location
9759 -- of U_Ent, that's what prior defined means.
9761 elsif Sloc
(Ent
) < Loc_U_Ent
then
9766 ("invalid address clause for initialized object &!",
9768 Error_Msg_Node_2
:= U_Ent
;
9770 ("\& must be defined before & (RM 13.1(22))!",
9774 elsif Nkind
(Original_Node
(Nod
)) = N_Function_Call
then
9775 Check_Expr_Constants
(Original_Node
(Nod
));
9779 ("invalid address clause for initialized object &!",
9782 if Comes_From_Source
(Ent
) then
9784 ("\reference to variable& not allowed"
9785 & " (RM 13.1(22))!", Nod
, Ent
);
9788 ("non-static expression not allowed"
9789 & " (RM 13.1(22))!", Nod
);
9793 when N_Integer_Literal
=>
9795 -- If this is a rewritten unchecked conversion, in a system
9796 -- where Address is an integer type, always use the base type
9797 -- for a literal value. This is user-friendly and prevents
9798 -- order-of-elaboration issues with instances of unchecked
9801 if Nkind
(Original_Node
(Nod
)) = N_Function_Call
then
9802 Set_Etype
(Nod
, Base_Type
(Etype
(Nod
)));
9805 when N_Character_Literal
9812 Check_Expr_Constants
(Low_Bound
(Nod
));
9813 Check_Expr_Constants
(High_Bound
(Nod
));
9815 when N_Explicit_Dereference
=>
9816 Check_Expr_Constants
(Prefix
(Nod
));
9818 when N_Indexed_Component
=>
9819 Check_Expr_Constants
(Prefix
(Nod
));
9820 Check_List_Constants
(Expressions
(Nod
));
9823 Check_Expr_Constants
(Prefix
(Nod
));
9824 Check_Expr_Constants
(Discrete_Range
(Nod
));
9826 when N_Selected_Component
=>
9827 Check_Expr_Constants
(Prefix
(Nod
));
9829 when N_Attribute_Reference
=>
9830 if Nam_In
(Attribute_Name
(Nod
), Name_Address
,
9832 Name_Unchecked_Access
,
9833 Name_Unrestricted_Access
)
9835 Check_At_Constant_Address
(Prefix
(Nod
));
9837 -- Normally, System'To_Address will have been transformed into
9838 -- an Unchecked_Conversion, but in -gnatc mode, it will not,
9839 -- and we don't want to give an error, because the whole point
9840 -- of 'To_Address is that it is static.
9842 elsif Attribute_Name
(Nod
) = Name_To_Address
then
9843 pragma Assert
(Operating_Mode
= Check_Semantics
);
9847 Check_Expr_Constants
(Prefix
(Nod
));
9848 Check_List_Constants
(Expressions
(Nod
));
9852 Check_List_Constants
(Component_Associations
(Nod
));
9853 Check_List_Constants
(Expressions
(Nod
));
9855 when N_Component_Association
=>
9856 Check_Expr_Constants
(Expression
(Nod
));
9858 when N_Extension_Aggregate
=>
9859 Check_Expr_Constants
(Ancestor_Part
(Nod
));
9860 Check_List_Constants
(Component_Associations
(Nod
));
9861 Check_List_Constants
(Expressions
(Nod
));
9870 Check_Expr_Constants
(Left_Opnd
(Nod
));
9871 Check_Expr_Constants
(Right_Opnd
(Nod
));
9874 Check_Expr_Constants
(Right_Opnd
(Nod
));
9877 | N_Qualified_Expression
9879 | N_Unchecked_Type_Conversion
9881 Check_Expr_Constants
(Expression
(Nod
));
9883 when N_Function_Call
=>
9884 if not Is_Pure
(Entity
(Name
(Nod
))) then
9886 ("invalid address clause for initialized object &!",
9890 ("\function & is not pure (RM 13.1(22))!",
9891 Nod
, Entity
(Name
(Nod
)));
9894 Check_List_Constants
(Parameter_Associations
(Nod
));
9897 when N_Parameter_Association
=>
9898 Check_Expr_Constants
(Explicit_Actual_Parameter
(Nod
));
9902 ("invalid address clause for initialized object &!",
9905 ("\must be constant defined before& (RM 13.1(22))!",
9908 end Check_Expr_Constants
;
9910 --------------------------
9911 -- Check_List_Constants --
9912 --------------------------
9914 procedure Check_List_Constants
(Lst
: List_Id
) is
9918 if Present
(Lst
) then
9919 Nod1
:= First
(Lst
);
9920 while Present
(Nod1
) loop
9921 Check_Expr_Constants
(Nod1
);
9925 end Check_List_Constants
;
9927 -- Start of processing for Check_Constant_Address_Clause
9930 -- If rep_clauses are to be ignored, no need for legality checks. In
9931 -- particular, no need to pester user about rep clauses that violate the
9932 -- rule on constant addresses, given that these clauses will be removed
9933 -- by Freeze before they reach the back end. Similarly in CodePeer mode,
9934 -- we want to relax these checks.
9936 if not Ignore_Rep_Clauses
and not CodePeer_Mode
then
9937 Check_Expr_Constants
(Expr
);
9939 end Check_Constant_Address_Clause
;
9941 ---------------------------
9942 -- Check_Pool_Size_Clash --
9943 ---------------------------
9945 procedure Check_Pool_Size_Clash
(Ent
: Entity_Id
; SP
, SS
: Node_Id
) is
9949 -- We need to find out which one came first. Note that in the case of
9950 -- aspects mixed with pragmas there are cases where the processing order
9951 -- is reversed, which is why we do the check here.
9953 if Sloc
(SP
) < Sloc
(SS
) then
9954 Error_Msg_Sloc
:= Sloc
(SP
);
9956 Error_Msg_NE
("Storage_Pool previously given for&#", Post
, Ent
);
9959 Error_Msg_Sloc
:= Sloc
(SS
);
9961 Error_Msg_NE
("Storage_Size previously given for&#", Post
, Ent
);
9965 ("\cannot have Storage_Size and Storage_Pool (RM 13.11(3))", Post
);
9966 end Check_Pool_Size_Clash
;
9968 ----------------------------------------
9969 -- Check_Record_Representation_Clause --
9970 ----------------------------------------
9972 procedure Check_Record_Representation_Clause
(N
: Node_Id
) is
9973 Loc
: constant Source_Ptr
:= Sloc
(N
);
9974 Ident
: constant Node_Id
:= Identifier
(N
);
9975 Rectype
: Entity_Id
;
9980 Hbit
: Uint
:= Uint_0
;
9984 Max_Bit_So_Far
: Uint
;
9985 -- Records the maximum bit position so far. If all field positions
9986 -- are monotonically increasing, then we can skip the circuit for
9987 -- checking for overlap, since no overlap is possible.
9989 Tagged_Parent
: Entity_Id
:= Empty
;
9990 -- This is set in the case of an extension for which we have either a
9991 -- size clause or Is_Fully_Repped_Tagged_Type True (indicating that all
9992 -- components are positioned by record representation clauses) on the
9993 -- parent type. In this case we check for overlap between components of
9994 -- this tagged type and the parent component. Tagged_Parent will point
9995 -- to this parent type. For all other cases, Tagged_Parent is Empty.
9997 Parent_Last_Bit
: Uint
:= No_Uint
; -- init to avoid warning
9998 -- Relevant only if Tagged_Parent is set, Parent_Last_Bit indicates the
9999 -- last bit position for any field in the parent type. We only need to
10000 -- check overlap for fields starting below this point.
10002 Overlap_Check_Required
: Boolean;
10003 -- Used to keep track of whether or not an overlap check is required
10005 Overlap_Detected
: Boolean := False;
10006 -- Set True if an overlap is detected
10008 Ccount
: Natural := 0;
10009 -- Number of component clauses in record rep clause
10011 procedure Check_Component_Overlap
(C1_Ent
, C2_Ent
: Entity_Id
);
10012 -- Given two entities for record components or discriminants, checks
10013 -- if they have overlapping component clauses and issues errors if so.
10015 procedure Find_Component
;
10016 -- Finds component entity corresponding to current component clause (in
10017 -- CC), and sets Comp to the entity, and Fbit/Lbit to the zero origin
10018 -- start/stop bits for the field. If there is no matching component or
10019 -- if the matching component does not have a component clause, then
10020 -- that's an error and Comp is set to Empty, but no error message is
10021 -- issued, since the message was already given. Comp is also set to
10022 -- Empty if the current "component clause" is in fact a pragma.
10024 -----------------------------
10025 -- Check_Component_Overlap --
10026 -----------------------------
10028 procedure Check_Component_Overlap
(C1_Ent
, C2_Ent
: Entity_Id
) is
10029 CC1
: constant Node_Id
:= Component_Clause
(C1_Ent
);
10030 CC2
: constant Node_Id
:= Component_Clause
(C2_Ent
);
10033 if Present
(CC1
) and then Present
(CC2
) then
10035 -- Exclude odd case where we have two tag components in the same
10036 -- record, both at location zero. This seems a bit strange, but
10037 -- it seems to happen in some circumstances, perhaps on an error.
10039 if Nam_In
(Chars
(C1_Ent
), Name_uTag
, Name_uTag
) then
10043 -- Here we check if the two fields overlap
10046 S1
: constant Uint
:= Component_Bit_Offset
(C1_Ent
);
10047 S2
: constant Uint
:= Component_Bit_Offset
(C2_Ent
);
10048 E1
: constant Uint
:= S1
+ Esize
(C1_Ent
);
10049 E2
: constant Uint
:= S2
+ Esize
(C2_Ent
);
10052 if E2
<= S1
or else E1
<= S2
then
10055 Error_Msg_Node_2
:= Component_Name
(CC2
);
10056 Error_Msg_Sloc
:= Sloc
(Error_Msg_Node_2
);
10057 Error_Msg_Node_1
:= Component_Name
(CC1
);
10059 ("component& overlaps & #", Component_Name
(CC1
));
10060 Overlap_Detected
:= True;
10064 end Check_Component_Overlap
;
10066 --------------------
10067 -- Find_Component --
10068 --------------------
10070 procedure Find_Component
is
10072 procedure Search_Component
(R
: Entity_Id
);
10073 -- Search components of R for a match. If found, Comp is set
10075 ----------------------
10076 -- Search_Component --
10077 ----------------------
10079 procedure Search_Component
(R
: Entity_Id
) is
10081 Comp
:= First_Component_Or_Discriminant
(R
);
10082 while Present
(Comp
) loop
10084 -- Ignore error of attribute name for component name (we
10085 -- already gave an error message for this, so no need to
10088 if Nkind
(Component_Name
(CC
)) = N_Attribute_Reference
then
10091 exit when Chars
(Comp
) = Chars
(Component_Name
(CC
));
10094 Next_Component_Or_Discriminant
(Comp
);
10096 end Search_Component
;
10098 -- Start of processing for Find_Component
10101 -- Return with Comp set to Empty if we have a pragma
10103 if Nkind
(CC
) = N_Pragma
then
10108 -- Search current record for matching component
10110 Search_Component
(Rectype
);
10112 -- If not found, maybe component of base type discriminant that is
10113 -- absent from statically constrained first subtype.
10116 Search_Component
(Base_Type
(Rectype
));
10119 -- If no component, or the component does not reference the component
10120 -- clause in question, then there was some previous error for which
10121 -- we already gave a message, so just return with Comp Empty.
10123 if No
(Comp
) or else Component_Clause
(Comp
) /= CC
then
10124 Check_Error_Detected
;
10127 -- Normal case where we have a component clause
10130 Fbit
:= Component_Bit_Offset
(Comp
);
10131 Lbit
:= Fbit
+ Esize
(Comp
) - 1;
10133 end Find_Component
;
10135 -- Start of processing for Check_Record_Representation_Clause
10139 Rectype
:= Entity
(Ident
);
10141 if Rectype
= Any_Type
then
10145 Rectype
:= Underlying_Type
(Rectype
);
10147 -- See if we have a fully repped derived tagged type
10150 PS
: constant Entity_Id
:= Parent_Subtype
(Rectype
);
10153 if Present
(PS
) and then Known_Static_RM_Size
(PS
) then
10154 Tagged_Parent
:= PS
;
10155 Parent_Last_Bit
:= RM_Size
(PS
) - 1;
10157 elsif Present
(PS
) and then Is_Fully_Repped_Tagged_Type
(PS
) then
10158 Tagged_Parent
:= PS
;
10160 -- Find maximum bit of any component of the parent type
10162 Parent_Last_Bit
:= UI_From_Int
(System_Address_Size
- 1);
10163 Pcomp
:= First_Entity
(Tagged_Parent
);
10164 while Present
(Pcomp
) loop
10165 if Ekind_In
(Pcomp
, E_Discriminant
, E_Component
) then
10166 if Component_Bit_Offset
(Pcomp
) /= No_Uint
10167 and then Known_Static_Esize
(Pcomp
)
10172 Component_Bit_Offset
(Pcomp
) + Esize
(Pcomp
) - 1);
10176 -- Skip anonymous types generated for constrained array
10177 -- or record components.
10182 Next_Entity
(Pcomp
);
10187 -- All done if no component clauses
10189 CC
:= First
(Component_Clauses
(N
));
10195 -- If a tag is present, then create a component clause that places it
10196 -- at the start of the record (otherwise gigi may place it after other
10197 -- fields that have rep clauses).
10199 Fent
:= First_Entity
(Rectype
);
10201 if Nkind
(Fent
) = N_Defining_Identifier
10202 and then Chars
(Fent
) = Name_uTag
10204 Set_Component_Bit_Offset
(Fent
, Uint_0
);
10205 Set_Normalized_Position
(Fent
, Uint_0
);
10206 Set_Normalized_First_Bit
(Fent
, Uint_0
);
10207 Set_Normalized_Position_Max
(Fent
, Uint_0
);
10208 Init_Esize
(Fent
, System_Address_Size
);
10210 Set_Component_Clause
(Fent
,
10211 Make_Component_Clause
(Loc
,
10212 Component_Name
=> Make_Identifier
(Loc
, Name_uTag
),
10214 Position
=> Make_Integer_Literal
(Loc
, Uint_0
),
10215 First_Bit
=> Make_Integer_Literal
(Loc
, Uint_0
),
10217 Make_Integer_Literal
(Loc
,
10218 UI_From_Int
(System_Address_Size
))));
10220 Ccount
:= Ccount
+ 1;
10223 Max_Bit_So_Far
:= Uint_Minus_1
;
10224 Overlap_Check_Required
:= False;
10226 -- Process the component clauses
10228 while Present
(CC
) loop
10231 if Present
(Comp
) then
10232 Ccount
:= Ccount
+ 1;
10234 -- We need a full overlap check if record positions non-monotonic
10236 if Fbit
<= Max_Bit_So_Far
then
10237 Overlap_Check_Required
:= True;
10240 Max_Bit_So_Far
:= Lbit
;
10242 -- Check bit position out of range of specified size
10244 if Has_Size_Clause
(Rectype
)
10245 and then RM_Size
(Rectype
) <= Lbit
10248 ("bit number out of range of specified size",
10251 -- Check for overlap with tag or parent component
10254 if Is_Tagged_Type
(Rectype
)
10255 and then Fbit
< System_Address_Size
10258 ("component overlaps tag field of&",
10259 Component_Name
(CC
), Rectype
);
10260 Overlap_Detected
:= True;
10262 elsif Present
(Tagged_Parent
)
10263 and then Fbit
<= Parent_Last_Bit
10266 ("component overlaps parent field of&",
10267 Component_Name
(CC
), Rectype
);
10268 Overlap_Detected
:= True;
10271 if Hbit
< Lbit
then
10280 -- Now that we have processed all the component clauses, check for
10281 -- overlap. We have to leave this till last, since the components can
10282 -- appear in any arbitrary order in the representation clause.
10284 -- We do not need this check if all specified ranges were monotonic,
10285 -- as recorded by Overlap_Check_Required being False at this stage.
10287 -- This first section checks if there are any overlapping entries at
10288 -- all. It does this by sorting all entries and then seeing if there are
10289 -- any overlaps. If there are none, then that is decisive, but if there
10290 -- are overlaps, they may still be OK (they may result from fields in
10291 -- different variants).
10293 if Overlap_Check_Required
then
10294 Overlap_Check1
: declare
10296 OC_Fbit
: array (0 .. Ccount
) of Uint
;
10297 -- First-bit values for component clauses, the value is the offset
10298 -- of the first bit of the field from start of record. The zero
10299 -- entry is for use in sorting.
10301 OC_Lbit
: array (0 .. Ccount
) of Uint
;
10302 -- Last-bit values for component clauses, the value is the offset
10303 -- of the last bit of the field from start of record. The zero
10304 -- entry is for use in sorting.
10306 OC_Count
: Natural := 0;
10307 -- Count of entries in OC_Fbit and OC_Lbit
10309 function OC_Lt
(Op1
, Op2
: Natural) return Boolean;
10310 -- Compare routine for Sort
10312 procedure OC_Move
(From
: Natural; To
: Natural);
10313 -- Move routine for Sort
10315 package Sorting
is new GNAT
.Heap_Sort_G
(OC_Move
, OC_Lt
);
10321 function OC_Lt
(Op1
, Op2
: Natural) return Boolean is
10323 return OC_Fbit
(Op1
) < OC_Fbit
(Op2
);
10330 procedure OC_Move
(From
: Natural; To
: Natural) is
10332 OC_Fbit
(To
) := OC_Fbit
(From
);
10333 OC_Lbit
(To
) := OC_Lbit
(From
);
10336 -- Start of processing for Overlap_Check
10339 CC
:= First
(Component_Clauses
(N
));
10340 while Present
(CC
) loop
10342 -- Exclude component clause already marked in error
10344 if not Error_Posted
(CC
) then
10347 if Present
(Comp
) then
10348 OC_Count
:= OC_Count
+ 1;
10349 OC_Fbit
(OC_Count
) := Fbit
;
10350 OC_Lbit
(OC_Count
) := Lbit
;
10357 Sorting
.Sort
(OC_Count
);
10359 Overlap_Check_Required
:= False;
10360 for J
in 1 .. OC_Count
- 1 loop
10361 if OC_Lbit
(J
) >= OC_Fbit
(J
+ 1) then
10362 Overlap_Check_Required
:= True;
10366 end Overlap_Check1
;
10369 -- If Overlap_Check_Required is still True, then we have to do the full
10370 -- scale overlap check, since we have at least two fields that do
10371 -- overlap, and we need to know if that is OK since they are in
10372 -- different variant, or whether we have a definite problem.
10374 if Overlap_Check_Required
then
10375 Overlap_Check2
: declare
10376 C1_Ent
, C2_Ent
: Entity_Id
;
10377 -- Entities of components being checked for overlap
10380 -- Component_List node whose Component_Items are being checked
10383 -- Component declaration for component being checked
10386 C1_Ent
:= First_Entity
(Base_Type
(Rectype
));
10388 -- Loop through all components in record. For each component check
10389 -- for overlap with any of the preceding elements on the component
10390 -- list containing the component and also, if the component is in
10391 -- a variant, check against components outside the case structure.
10392 -- This latter test is repeated recursively up the variant tree.
10394 Main_Component_Loop
: while Present
(C1_Ent
) loop
10395 if not Ekind_In
(C1_Ent
, E_Component
, E_Discriminant
) then
10396 goto Continue_Main_Component_Loop
;
10399 -- Skip overlap check if entity has no declaration node. This
10400 -- happens with discriminants in constrained derived types.
10401 -- Possibly we are missing some checks as a result, but that
10402 -- does not seem terribly serious.
10404 if No
(Declaration_Node
(C1_Ent
)) then
10405 goto Continue_Main_Component_Loop
;
10408 Clist
:= Parent
(List_Containing
(Declaration_Node
(C1_Ent
)));
10410 -- Loop through component lists that need checking. Check the
10411 -- current component list and all lists in variants above us.
10413 Component_List_Loop
: loop
10415 -- If derived type definition, go to full declaration
10416 -- If at outer level, check discriminants if there are any.
10418 if Nkind
(Clist
) = N_Derived_Type_Definition
then
10419 Clist
:= Parent
(Clist
);
10422 -- Outer level of record definition, check discriminants
10424 if Nkind_In
(Clist
, N_Full_Type_Declaration
,
10425 N_Private_Type_Declaration
)
10427 if Has_Discriminants
(Defining_Identifier
(Clist
)) then
10429 First_Discriminant
(Defining_Identifier
(Clist
));
10430 while Present
(C2_Ent
) loop
10431 exit when C1_Ent
= C2_Ent
;
10432 Check_Component_Overlap
(C1_Ent
, C2_Ent
);
10433 Next_Discriminant
(C2_Ent
);
10437 -- Record extension case
10439 elsif Nkind
(Clist
) = N_Derived_Type_Definition
then
10442 -- Otherwise check one component list
10445 Citem
:= First
(Component_Items
(Clist
));
10446 while Present
(Citem
) loop
10447 if Nkind
(Citem
) = N_Component_Declaration
then
10448 C2_Ent
:= Defining_Identifier
(Citem
);
10449 exit when C1_Ent
= C2_Ent
;
10450 Check_Component_Overlap
(C1_Ent
, C2_Ent
);
10457 -- Check for variants above us (the parent of the Clist can
10458 -- be a variant, in which case its parent is a variant part,
10459 -- and the parent of the variant part is a component list
10460 -- whose components must all be checked against the current
10461 -- component for overlap).
10463 if Nkind
(Parent
(Clist
)) = N_Variant
then
10464 Clist
:= Parent
(Parent
(Parent
(Clist
)));
10466 -- Check for possible discriminant part in record, this
10467 -- is treated essentially as another level in the
10468 -- recursion. For this case the parent of the component
10469 -- list is the record definition, and its parent is the
10470 -- full type declaration containing the discriminant
10473 elsif Nkind
(Parent
(Clist
)) = N_Record_Definition
then
10474 Clist
:= Parent
(Parent
((Clist
)));
10476 -- If neither of these two cases, we are at the top of
10480 exit Component_List_Loop
;
10482 end loop Component_List_Loop
;
10484 <<Continue_Main_Component_Loop
>>
10485 Next_Entity
(C1_Ent
);
10487 end loop Main_Component_Loop
;
10488 end Overlap_Check2
;
10491 -- The following circuit deals with warning on record holes (gaps). We
10492 -- skip this check if overlap was detected, since it makes sense for the
10493 -- programmer to fix this illegality before worrying about warnings.
10495 if not Overlap_Detected
and Warn_On_Record_Holes
then
10496 Record_Hole_Check
: declare
10497 Decl
: constant Node_Id
:= Declaration_Node
(Base_Type
(Rectype
));
10498 -- Full declaration of record type
10500 procedure Check_Component_List
10504 -- Check component list CL for holes. The starting bit should be
10505 -- Sbit. which is zero for the main record component list and set
10506 -- appropriately for recursive calls for variants. DS is set to
10507 -- a list of discriminant specifications to be included in the
10508 -- consideration of components. It is No_List if none to consider.
10510 --------------------------
10511 -- Check_Component_List --
10512 --------------------------
10514 procedure Check_Component_List
10522 Compl
:= Integer (List_Length
(Component_Items
(CL
)));
10524 if DS
/= No_List
then
10525 Compl
:= Compl
+ Integer (List_Length
(DS
));
10529 Comps
: array (Natural range 0 .. Compl
) of Entity_Id
;
10530 -- Gather components (zero entry is for sort routine)
10532 Ncomps
: Natural := 0;
10533 -- Number of entries stored in Comps (starting at Comps (1))
10536 -- One component item or discriminant specification
10539 -- Starting bit for next component
10542 -- Component entity
10547 function Lt
(Op1
, Op2
: Natural) return Boolean;
10548 -- Compare routine for Sort
10550 procedure Move
(From
: Natural; To
: Natural);
10551 -- Move routine for Sort
10553 package Sorting
is new GNAT
.Heap_Sort_G
(Move
, Lt
);
10559 function Lt
(Op1
, Op2
: Natural) return Boolean is
10561 return Component_Bit_Offset
(Comps
(Op1
))
10563 Component_Bit_Offset
(Comps
(Op2
));
10570 procedure Move
(From
: Natural; To
: Natural) is
10572 Comps
(To
) := Comps
(From
);
10576 -- Gather discriminants into Comp
10578 if DS
/= No_List
then
10579 Citem
:= First
(DS
);
10580 while Present
(Citem
) loop
10581 if Nkind
(Citem
) = N_Discriminant_Specification
then
10583 Ent
: constant Entity_Id
:=
10584 Defining_Identifier
(Citem
);
10586 if Ekind
(Ent
) = E_Discriminant
then
10587 Ncomps
:= Ncomps
+ 1;
10588 Comps
(Ncomps
) := Ent
;
10597 -- Gather component entities into Comp
10599 Citem
:= First
(Component_Items
(CL
));
10600 while Present
(Citem
) loop
10601 if Nkind
(Citem
) = N_Component_Declaration
then
10602 Ncomps
:= Ncomps
+ 1;
10603 Comps
(Ncomps
) := Defining_Identifier
(Citem
);
10609 -- Now sort the component entities based on the first bit.
10610 -- Note we already know there are no overlapping components.
10612 Sorting
.Sort
(Ncomps
);
10614 -- Loop through entries checking for holes
10617 for J
in 1 .. Ncomps
loop
10621 CBO
: constant Uint
:= Component_Bit_Offset
(CEnt
);
10624 -- Skip components with unknown offsets
10626 if CBO
/= No_Uint
and then CBO
>= 0 then
10627 Error_Msg_Uint_1
:= CBO
- Nbit
;
10629 if Error_Msg_Uint_1
> 0 then
10631 ("?H?^-bit gap before component&",
10632 Component_Name
(Component_Clause
(CEnt
)),
10636 Nbit
:= CBO
+ Esize
(CEnt
);
10641 -- Process variant parts recursively if present
10643 if Present
(Variant_Part
(CL
)) then
10644 Variant
:= First
(Variants
(Variant_Part
(CL
)));
10645 while Present
(Variant
) loop
10646 Check_Component_List
10647 (Component_List
(Variant
), Nbit
, No_List
);
10652 end Check_Component_List
;
10654 -- Start of processing for Record_Hole_Check
10661 if Is_Tagged_Type
(Rectype
) then
10662 Sbit
:= UI_From_Int
(System_Address_Size
);
10667 if Nkind
(Decl
) = N_Full_Type_Declaration
10668 and then Nkind
(Type_Definition
(Decl
)) = N_Record_Definition
10670 Check_Component_List
10671 (Component_List
(Type_Definition
(Decl
)),
10673 Discriminant_Specifications
(Decl
));
10676 end Record_Hole_Check
;
10679 -- For records that have component clauses for all components, and whose
10680 -- size is less than or equal to 32, we need to know the size in the
10681 -- front end to activate possible packed array processing where the
10682 -- component type is a record.
10684 -- At this stage Hbit + 1 represents the first unused bit from all the
10685 -- component clauses processed, so if the component clauses are
10686 -- complete, then this is the length of the record.
10688 -- For records longer than System.Storage_Unit, and for those where not
10689 -- all components have component clauses, the back end determines the
10690 -- length (it may for example be appropriate to round up the size
10691 -- to some convenient boundary, based on alignment considerations, etc).
10693 if Unknown_RM_Size
(Rectype
) and then Hbit
+ 1 <= 32 then
10695 -- Nothing to do if at least one component has no component clause
10697 Comp
:= First_Component_Or_Discriminant
(Rectype
);
10698 while Present
(Comp
) loop
10699 exit when No
(Component_Clause
(Comp
));
10700 Next_Component_Or_Discriminant
(Comp
);
10703 -- If we fall out of loop, all components have component clauses
10704 -- and so we can set the size to the maximum value.
10707 Set_RM_Size
(Rectype
, Hbit
+ 1);
10710 end Check_Record_Representation_Clause
;
10716 procedure Check_Size
10720 Biased
: out Boolean)
10722 procedure Size_Too_Small_Error
(Min_Siz
: Uint
);
10723 -- Emit an error concerning illegal size Siz. Min_Siz denotes the
10726 --------------------------
10727 -- Size_Too_Small_Error --
10728 --------------------------
10730 procedure Size_Too_Small_Error
(Min_Siz
: Uint
) is
10732 -- This error is suppressed in ASIS mode to allow for different ASIS
10733 -- back ends or ASIS-based tools to query the illegal clause.
10735 if not ASIS_Mode
then
10736 Error_Msg_Uint_1
:= Min_Siz
;
10737 Error_Msg_NE
("size for& too small, minimum allowed is ^", N
, T
);
10739 end Size_Too_Small_Error
;
10743 UT
: constant Entity_Id
:= Underlying_Type
(T
);
10746 -- Start of processing for Check_Size
10751 -- Reject patently improper size values
10753 if Is_Elementary_Type
(T
)
10754 and then Siz
> UI_From_Int
(Int
'Last)
10756 Error_Msg_N
("Size value too large for elementary type", N
);
10758 if Nkind
(Original_Node
(N
)) = N_Op_Expon
then
10760 ("\maybe '* was meant, rather than '*'*", Original_Node
(N
));
10764 -- Dismiss generic types
10766 if Is_Generic_Type
(T
)
10768 Is_Generic_Type
(UT
)
10770 Is_Generic_Type
(Root_Type
(UT
))
10774 -- Guard against previous errors
10776 elsif No
(UT
) or else UT
= Any_Type
then
10777 Check_Error_Detected
;
10780 -- Check case of bit packed array
10782 elsif Is_Array_Type
(UT
)
10783 and then Known_Static_Component_Size
(UT
)
10784 and then Is_Bit_Packed_Array
(UT
)
10792 Asiz
:= Component_Size
(UT
);
10793 Indx
:= First_Index
(UT
);
10795 Ityp
:= Etype
(Indx
);
10797 -- If non-static bound, then we are not in the business of
10798 -- trying to check the length, and indeed an error will be
10799 -- issued elsewhere, since sizes of non-static array types
10800 -- cannot be set implicitly or explicitly.
10802 if not Is_OK_Static_Subtype
(Ityp
) then
10806 -- Otherwise accumulate next dimension
10808 Asiz
:= Asiz
* (Expr_Value
(Type_High_Bound
(Ityp
)) -
10809 Expr_Value
(Type_Low_Bound
(Ityp
)) +
10813 exit when No
(Indx
);
10816 if Asiz
<= Siz
then
10820 Size_Too_Small_Error
(Asiz
);
10821 Set_Esize
(T
, Asiz
);
10822 Set_RM_Size
(T
, Asiz
);
10826 -- All other composite types are ignored
10828 elsif Is_Composite_Type
(UT
) then
10831 -- For fixed-point types, don't check minimum if type is not frozen,
10832 -- since we don't know all the characteristics of the type that can
10833 -- affect the size (e.g. a specified small) till freeze time.
10835 elsif Is_Fixed_Point_Type
(UT
) and then not Is_Frozen
(UT
) then
10838 -- Cases for which a minimum check is required
10841 -- Ignore if specified size is correct for the type
10843 if Known_Esize
(UT
) and then Siz
= Esize
(UT
) then
10847 -- Otherwise get minimum size
10849 M
:= UI_From_Int
(Minimum_Size
(UT
));
10853 -- Size is less than minimum size, but one possibility remains
10854 -- that we can manage with the new size if we bias the type.
10856 M
:= UI_From_Int
(Minimum_Size
(UT
, Biased
=> True));
10859 Size_Too_Small_Error
(M
);
10861 Set_RM_Size
(T
, M
);
10869 --------------------------
10870 -- Freeze_Entity_Checks --
10871 --------------------------
10873 procedure Freeze_Entity_Checks
(N
: Node_Id
) is
10874 procedure Hide_Non_Overridden_Subprograms
(Typ
: Entity_Id
);
10875 -- Inspect the primitive operations of type Typ and hide all pairs of
10876 -- implicitly declared non-overridden non-fully conformant homographs
10877 -- (Ada RM 8.3 12.3/2).
10879 -------------------------------------
10880 -- Hide_Non_Overridden_Subprograms --
10881 -------------------------------------
10883 procedure Hide_Non_Overridden_Subprograms
(Typ
: Entity_Id
) is
10884 procedure Hide_Matching_Homographs
10885 (Subp_Id
: Entity_Id
;
10886 Start_Elmt
: Elmt_Id
);
10887 -- Inspect a list of primitive operations starting with Start_Elmt
10888 -- and find matching implicitly declared non-overridden non-fully
10889 -- conformant homographs of Subp_Id. If found, all matches along
10890 -- with Subp_Id are hidden from all visibility.
10892 function Is_Non_Overridden_Or_Null_Procedure
10893 (Subp_Id
: Entity_Id
) return Boolean;
10894 -- Determine whether subprogram Subp_Id is implicitly declared non-
10895 -- overridden subprogram or an implicitly declared null procedure.
10897 ------------------------------
10898 -- Hide_Matching_Homographs --
10899 ------------------------------
10901 procedure Hide_Matching_Homographs
10902 (Subp_Id
: Entity_Id
;
10903 Start_Elmt
: Elmt_Id
)
10906 Prim_Elmt
: Elmt_Id
;
10909 Prim_Elmt
:= Start_Elmt
;
10910 while Present
(Prim_Elmt
) loop
10911 Prim
:= Node
(Prim_Elmt
);
10913 -- The current primitive is implicitly declared non-overridden
10914 -- non-fully conformant homograph of Subp_Id. Both subprograms
10915 -- must be hidden from visibility.
10917 if Chars
(Prim
) = Chars
(Subp_Id
)
10918 and then Is_Non_Overridden_Or_Null_Procedure
(Prim
)
10919 and then not Fully_Conformant
(Prim
, Subp_Id
)
10921 Set_Is_Hidden_Non_Overridden_Subpgm
(Prim
);
10922 Set_Is_Immediately_Visible
(Prim
, False);
10923 Set_Is_Potentially_Use_Visible
(Prim
, False);
10925 Set_Is_Hidden_Non_Overridden_Subpgm
(Subp_Id
);
10926 Set_Is_Immediately_Visible
(Subp_Id
, False);
10927 Set_Is_Potentially_Use_Visible
(Subp_Id
, False);
10930 Next_Elmt
(Prim_Elmt
);
10932 end Hide_Matching_Homographs
;
10934 -----------------------------------------
10935 -- Is_Non_Overridden_Or_Null_Procedure --
10936 -----------------------------------------
10938 function Is_Non_Overridden_Or_Null_Procedure
10939 (Subp_Id
: Entity_Id
) return Boolean
10941 Alias_Id
: Entity_Id
;
10944 -- The subprogram is inherited (implicitly declared), it does not
10945 -- override and does not cover a primitive of an interface.
10947 if Ekind_In
(Subp_Id
, E_Function
, E_Procedure
)
10948 and then Present
(Alias
(Subp_Id
))
10949 and then No
(Interface_Alias
(Subp_Id
))
10950 and then No
(Overridden_Operation
(Subp_Id
))
10952 Alias_Id
:= Alias
(Subp_Id
);
10954 if Requires_Overriding
(Alias_Id
) then
10957 elsif Nkind
(Parent
(Alias_Id
)) = N_Procedure_Specification
10958 and then Null_Present
(Parent
(Alias_Id
))
10965 end Is_Non_Overridden_Or_Null_Procedure
;
10969 Prim_Ops
: constant Elist_Id
:= Direct_Primitive_Operations
(Typ
);
10971 Prim_Elmt
: Elmt_Id
;
10973 -- Start of processing for Hide_Non_Overridden_Subprograms
10976 -- Inspect the list of primitives looking for non-overridden
10979 if Present
(Prim_Ops
) then
10980 Prim_Elmt
:= First_Elmt
(Prim_Ops
);
10981 while Present
(Prim_Elmt
) loop
10982 Prim
:= Node
(Prim_Elmt
);
10983 Next_Elmt
(Prim_Elmt
);
10985 if Is_Non_Overridden_Or_Null_Procedure
(Prim
) then
10986 Hide_Matching_Homographs
10988 Start_Elmt
=> Prim_Elmt
);
10992 end Hide_Non_Overridden_Subprograms
;
10996 E
: constant Entity_Id
:= Entity
(N
);
10998 Nongeneric_Case
: constant Boolean := Nkind
(N
) = N_Freeze_Entity
;
10999 -- True in nongeneric case. Some of the processing here is skipped
11000 -- for the generic case since it is not needed. Basically in the
11001 -- generic case, we only need to do stuff that might generate error
11002 -- messages or warnings.
11004 -- Start of processing for Freeze_Entity_Checks
11007 -- Remember that we are processing a freezing entity. Required to
11008 -- ensure correct decoration of internal entities associated with
11009 -- interfaces (see New_Overloaded_Entity).
11011 Inside_Freezing_Actions
:= Inside_Freezing_Actions
+ 1;
11013 -- For tagged types covering interfaces add internal entities that link
11014 -- the primitives of the interfaces with the primitives that cover them.
11015 -- Note: These entities were originally generated only when generating
11016 -- code because their main purpose was to provide support to initialize
11017 -- the secondary dispatch tables. They are now generated also when
11018 -- compiling with no code generation to provide ASIS the relationship
11019 -- between interface primitives and tagged type primitives. They are
11020 -- also used to locate primitives covering interfaces when processing
11021 -- generics (see Derive_Subprograms).
11023 -- This is not needed in the generic case
11025 if Ada_Version
>= Ada_2005
11026 and then Nongeneric_Case
11027 and then Ekind
(E
) = E_Record_Type
11028 and then Is_Tagged_Type
(E
)
11029 and then not Is_Interface
(E
)
11030 and then Has_Interfaces
(E
)
11032 -- This would be a good common place to call the routine that checks
11033 -- overriding of interface primitives (and thus factorize calls to
11034 -- Check_Abstract_Overriding located at different contexts in the
11035 -- compiler). However, this is not possible because it causes
11036 -- spurious errors in case of late overriding.
11038 Add_Internal_Interface_Entities
(E
);
11041 -- After all forms of overriding have been resolved, a tagged type may
11042 -- be left with a set of implicitly declared and possibly erroneous
11043 -- abstract subprograms, null procedures and subprograms that require
11044 -- overriding. If this set contains fully conformant homographs, then
11045 -- one is chosen arbitrarily (already done during resolution), otherwise
11046 -- all remaining non-fully conformant homographs are hidden from
11047 -- visibility (Ada RM 8.3 12.3/2).
11049 if Is_Tagged_Type
(E
) then
11050 Hide_Non_Overridden_Subprograms
(E
);
11055 if Ekind
(E
) = E_Record_Type
11056 and then Is_CPP_Class
(E
)
11057 and then Is_Tagged_Type
(E
)
11058 and then Tagged_Type_Expansion
11060 if CPP_Num_Prims
(E
) = 0 then
11062 -- If the CPP type has user defined components then it must import
11063 -- primitives from C++. This is required because if the C++ class
11064 -- has no primitives then the C++ compiler does not added the _tag
11065 -- component to the type.
11067 if First_Entity
(E
) /= Last_Entity
(E
) then
11069 ("'C'P'P type must import at least one primitive from C++??",
11074 -- Check that all its primitives are abstract or imported from C++.
11075 -- Check also availability of the C++ constructor.
11078 Has_Constructors
: constant Boolean := Has_CPP_Constructors
(E
);
11080 Error_Reported
: Boolean := False;
11084 Elmt
:= First_Elmt
(Primitive_Operations
(E
));
11085 while Present
(Elmt
) loop
11086 Prim
:= Node
(Elmt
);
11088 if Comes_From_Source
(Prim
) then
11089 if Is_Abstract_Subprogram
(Prim
) then
11092 elsif not Is_Imported
(Prim
)
11093 or else Convention
(Prim
) /= Convention_CPP
11096 ("primitives of 'C'P'P types must be imported from C++ "
11097 & "or abstract??", Prim
);
11099 elsif not Has_Constructors
11100 and then not Error_Reported
11102 Error_Msg_Name_1
:= Chars
(E
);
11104 ("??'C'P'P constructor required for type %", Prim
);
11105 Error_Reported
:= True;
11114 -- Check Ada derivation of CPP type
11116 if Expander_Active
-- why? losing errors in -gnatc mode???
11117 and then Present
(Etype
(E
)) -- defend against errors
11118 and then Tagged_Type_Expansion
11119 and then Ekind
(E
) = E_Record_Type
11120 and then Etype
(E
) /= E
11121 and then Is_CPP_Class
(Etype
(E
))
11122 and then CPP_Num_Prims
(Etype
(E
)) > 0
11123 and then not Is_CPP_Class
(E
)
11124 and then not Has_CPP_Constructors
(Etype
(E
))
11126 -- If the parent has C++ primitives but it has no constructor then
11127 -- check that all the primitives are overridden in this derivation;
11128 -- otherwise the constructor of the parent is needed to build the
11136 Elmt
:= First_Elmt
(Primitive_Operations
(E
));
11137 while Present
(Elmt
) loop
11138 Prim
:= Node
(Elmt
);
11140 if not Is_Abstract_Subprogram
(Prim
)
11141 and then No
(Interface_Alias
(Prim
))
11142 and then Find_Dispatching_Type
(Ultimate_Alias
(Prim
)) /= E
11144 Error_Msg_Name_1
:= Chars
(Etype
(E
));
11146 ("'C'P'P constructor required for parent type %", E
);
11155 Inside_Freezing_Actions
:= Inside_Freezing_Actions
- 1;
11157 -- If we have a type with predicates, build predicate function. This is
11158 -- not needed in the generic case, nor within TSS subprograms and other
11159 -- predefined primitives. For a derived type, ensure that the parent
11160 -- type is already frozen so that its predicate function has been
11161 -- constructed already. This is necessary if the parent is declared
11162 -- in a nested package and its own freeze point has not been reached.
11165 and then Nongeneric_Case
11166 and then not Within_Internal_Subprogram
11167 and then Has_Predicates
(E
)
11170 Atyp
: constant Entity_Id
:= Nearest_Ancestor
(E
);
11173 and then Has_Predicates
(Atyp
)
11174 and then not Is_Frozen
(Atyp
)
11176 Freeze_Before
(N
, Atyp
);
11180 Build_Predicate_Functions
(E
, N
);
11183 -- If type has delayed aspects, this is where we do the preanalysis at
11184 -- the freeze point, as part of the consistent visibility check. Note
11185 -- that this must be done after calling Build_Predicate_Functions or
11186 -- Build_Invariant_Procedure since these subprograms fix occurrences of
11187 -- the subtype name in the saved expression so that they will not cause
11188 -- trouble in the preanalysis.
11190 -- This is also not needed in the generic case
11193 and then Has_Delayed_Aspects
(E
)
11194 and then Scope
(E
) = Current_Scope
11196 -- Retrieve the visibility to the discriminants in order to properly
11197 -- analyze the aspects.
11199 Push_Scope_And_Install_Discriminants
(E
);
11205 -- Look for aspect specification entries for this entity
11207 Ritem
:= First_Rep_Item
(E
);
11208 while Present
(Ritem
) loop
11209 if Nkind
(Ritem
) = N_Aspect_Specification
11210 and then Entity
(Ritem
) = E
11211 and then Is_Delayed_Aspect
(Ritem
)
11213 Check_Aspect_At_Freeze_Point
(Ritem
);
11216 Next_Rep_Item
(Ritem
);
11220 Uninstall_Discriminants_And_Pop_Scope
(E
);
11223 -- For a record type, deal with variant parts. This has to be delayed
11224 -- to this point, because of the issue of statically predicated
11225 -- subtypes, which we have to ensure are frozen before checking
11226 -- choices, since we need to have the static choice list set.
11228 if Is_Record_Type
(E
) then
11229 Check_Variant_Part
: declare
11230 D
: constant Node_Id
:= Declaration_Node
(E
);
11235 Others_Present
: Boolean;
11236 pragma Warnings
(Off
, Others_Present
);
11237 -- Indicates others present, not used in this case
11239 procedure Non_Static_Choice_Error
(Choice
: Node_Id
);
11240 -- Error routine invoked by the generic instantiation below when
11241 -- the variant part has a non static choice.
11243 procedure Process_Declarations
(Variant
: Node_Id
);
11244 -- Processes declarations associated with a variant. We analyzed
11245 -- the declarations earlier (in Sem_Ch3.Analyze_Variant_Part),
11246 -- but we still need the recursive call to Check_Choices for any
11247 -- nested variant to get its choices properly processed. This is
11248 -- also where we expand out the choices if expansion is active.
11250 package Variant_Choices_Processing
is new
11251 Generic_Check_Choices
11252 (Process_Empty_Choice
=> No_OP
,
11253 Process_Non_Static_Choice
=> Non_Static_Choice_Error
,
11254 Process_Associated_Node
=> Process_Declarations
);
11255 use Variant_Choices_Processing
;
11257 -----------------------------
11258 -- Non_Static_Choice_Error --
11259 -----------------------------
11261 procedure Non_Static_Choice_Error
(Choice
: Node_Id
) is
11263 Flag_Non_Static_Expr
11264 ("choice given in variant part is not static!", Choice
);
11265 end Non_Static_Choice_Error
;
11267 --------------------------
11268 -- Process_Declarations --
11269 --------------------------
11271 procedure Process_Declarations
(Variant
: Node_Id
) is
11272 CL
: constant Node_Id
:= Component_List
(Variant
);
11276 -- Check for static predicate present in this variant
11278 if Has_SP_Choice
(Variant
) then
11280 -- Here we expand. You might expect to find this call in
11281 -- Expand_N_Variant_Part, but that is called when we first
11282 -- see the variant part, and we cannot do this expansion
11283 -- earlier than the freeze point, since for statically
11284 -- predicated subtypes, the predicate is not known till
11285 -- the freeze point.
11287 -- Furthermore, we do this expansion even if the expander
11288 -- is not active, because other semantic processing, e.g.
11289 -- for aggregates, requires the expanded list of choices.
11291 -- If the expander is not active, then we can't just clobber
11292 -- the list since it would invalidate the ASIS -gnatct tree.
11293 -- So we have to rewrite the variant part with a Rewrite
11294 -- call that replaces it with a copy and clobber the copy.
11296 if not Expander_Active
then
11298 NewV
: constant Node_Id
:= New_Copy
(Variant
);
11300 Set_Discrete_Choices
11301 (NewV
, New_Copy_List
(Discrete_Choices
(Variant
)));
11302 Rewrite
(Variant
, NewV
);
11306 Expand_Static_Predicates_In_Choices
(Variant
);
11309 -- We don't need to worry about the declarations in the variant
11310 -- (since they were analyzed by Analyze_Choices when we first
11311 -- encountered the variant), but we do need to take care of
11312 -- expansion of any nested variants.
11314 if not Null_Present
(CL
) then
11315 VP
:= Variant_Part
(CL
);
11317 if Present
(VP
) then
11319 (VP
, Variants
(VP
), Etype
(Name
(VP
)), Others_Present
);
11322 end Process_Declarations
;
11324 -- Start of processing for Check_Variant_Part
11327 -- Find component list
11331 if Nkind
(D
) = N_Full_Type_Declaration
then
11332 T
:= Type_Definition
(D
);
11334 if Nkind
(T
) = N_Record_Definition
then
11335 C
:= Component_List
(T
);
11337 elsif Nkind
(T
) = N_Derived_Type_Definition
11338 and then Present
(Record_Extension_Part
(T
))
11340 C
:= Component_List
(Record_Extension_Part
(T
));
11344 -- Case of variant part present
11346 if Present
(C
) and then Present
(Variant_Part
(C
)) then
11347 VP
:= Variant_Part
(C
);
11352 (VP
, Variants
(VP
), Etype
(Name
(VP
)), Others_Present
);
11354 -- If the last variant does not contain the Others choice,
11355 -- replace it with an N_Others_Choice node since Gigi always
11356 -- wants an Others. Note that we do not bother to call Analyze
11357 -- on the modified variant part, since its only effect would be
11358 -- to compute the Others_Discrete_Choices node laboriously, and
11359 -- of course we already know the list of choices corresponding
11360 -- to the others choice (it's the list we're replacing).
11362 -- We only want to do this if the expander is active, since
11363 -- we do not want to clobber the ASIS tree.
11365 if Expander_Active
then
11367 Last_Var
: constant Node_Id
:=
11368 Last_Non_Pragma
(Variants
(VP
));
11370 Others_Node
: Node_Id
;
11373 if Nkind
(First
(Discrete_Choices
(Last_Var
))) /=
11376 Others_Node
:= Make_Others_Choice
(Sloc
(Last_Var
));
11377 Set_Others_Discrete_Choices
11378 (Others_Node
, Discrete_Choices
(Last_Var
));
11379 Set_Discrete_Choices
11380 (Last_Var
, New_List
(Others_Node
));
11385 end Check_Variant_Part
;
11387 end Freeze_Entity_Checks
;
11389 -------------------------
11390 -- Get_Alignment_Value --
11391 -------------------------
11393 function Get_Alignment_Value
(Expr
: Node_Id
) return Uint
is
11394 Align
: constant Uint
:= Static_Integer
(Expr
);
11397 if Align
= No_Uint
then
11400 elsif Align
<= 0 then
11402 -- This error is suppressed in ASIS mode to allow for different ASIS
11403 -- back ends or ASIS-based tools to query the illegal clause.
11405 if not ASIS_Mode
then
11406 Error_Msg_N
("alignment value must be positive", Expr
);
11412 for J
in Int
range 0 .. 64 loop
11414 M
: constant Uint
:= Uint_2
** J
;
11417 exit when M
= Align
;
11421 -- This error is suppressed in ASIS mode to allow for
11422 -- different ASIS back ends or ASIS-based tools to query the
11425 if not ASIS_Mode
then
11426 Error_Msg_N
("alignment value must be power of 2", Expr
);
11436 end Get_Alignment_Value
;
11438 -------------------------------------
11439 -- Inherit_Aspects_At_Freeze_Point --
11440 -------------------------------------
11442 procedure Inherit_Aspects_At_Freeze_Point
(Typ
: Entity_Id
) is
11443 function Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11444 (Rep_Item
: Node_Id
) return Boolean;
11445 -- This routine checks if Rep_Item is either a pragma or an aspect
11446 -- specification node whose correponding pragma (if any) is present in
11447 -- the Rep Item chain of the entity it has been specified to.
11449 function Rep_Item_Entity
(Rep_Item
: Node_Id
) return Entity_Id
;
11450 -- Return the entity for which Rep_Item is specified
11452 --------------------------------------------------
11453 -- Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item --
11454 --------------------------------------------------
11456 function Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11457 (Rep_Item
: Node_Id
) return Boolean
11461 Nkind
(Rep_Item
) = N_Pragma
11462 or else Present_In_Rep_Item
11463 (Entity
(Rep_Item
), Aspect_Rep_Item
(Rep_Item
));
11464 end Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
;
11466 ---------------------
11467 -- Rep_Item_Entity --
11468 ---------------------
11470 function Rep_Item_Entity
(Rep_Item
: Node_Id
) return Entity_Id
is
11472 if Nkind
(Rep_Item
) = N_Aspect_Specification
then
11473 return Entity
(Rep_Item
);
11476 pragma Assert
(Nkind_In
(Rep_Item
,
11477 N_Attribute_Definition_Clause
,
11479 return Entity
(Name
(Rep_Item
));
11481 end Rep_Item_Entity
;
11483 -- Start of processing for Inherit_Aspects_At_Freeze_Point
11486 -- A representation item is either subtype-specific (Size and Alignment
11487 -- clauses) or type-related (all others). Subtype-specific aspects may
11488 -- differ for different subtypes of the same type (RM 13.1.8).
11490 -- A derived type inherits each type-related representation aspect of
11491 -- its parent type that was directly specified before the declaration of
11492 -- the derived type (RM 13.1.15).
11494 -- A derived subtype inherits each subtype-specific representation
11495 -- aspect of its parent subtype that was directly specified before the
11496 -- declaration of the derived type (RM 13.1.15).
11498 -- The general processing involves inheriting a representation aspect
11499 -- from a parent type whenever the first rep item (aspect specification,
11500 -- attribute definition clause, pragma) corresponding to the given
11501 -- representation aspect in the rep item chain of Typ, if any, isn't
11502 -- directly specified to Typ but to one of its parents.
11504 -- ??? Note that, for now, just a limited number of representation
11505 -- aspects have been inherited here so far. Many of them are
11506 -- still inherited in Sem_Ch3. This will be fixed soon. Here is
11507 -- a non- exhaustive list of aspects that likely also need to
11508 -- be moved to this routine: Alignment, Component_Alignment,
11509 -- Component_Size, Machine_Radix, Object_Size, Pack, Predicates,
11510 -- Preelaborable_Initialization, RM_Size and Small.
11512 -- In addition, Convention must be propagated from base type to subtype,
11513 -- because the subtype may have been declared on an incomplete view.
11515 if Nkind
(Parent
(Typ
)) = N_Private_Extension_Declaration
then
11521 if not Has_Rep_Item
(Typ
, Name_Ada_05
, Name_Ada_2005
, False)
11522 and then Has_Rep_Item
(Typ
, Name_Ada_05
, Name_Ada_2005
)
11523 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11524 (Get_Rep_Item
(Typ
, Name_Ada_05
, Name_Ada_2005
))
11526 Set_Is_Ada_2005_Only
(Typ
);
11531 if not Has_Rep_Item
(Typ
, Name_Ada_12
, Name_Ada_2012
, False)
11532 and then Has_Rep_Item
(Typ
, Name_Ada_12
, Name_Ada_2012
)
11533 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11534 (Get_Rep_Item
(Typ
, Name_Ada_12
, Name_Ada_2012
))
11536 Set_Is_Ada_2012_Only
(Typ
);
11541 if not Has_Rep_Item
(Typ
, Name_Atomic
, Name_Shared
, False)
11542 and then Has_Rep_Pragma
(Typ
, Name_Atomic
, Name_Shared
)
11543 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11544 (Get_Rep_Item
(Typ
, Name_Atomic
, Name_Shared
))
11546 Set_Is_Atomic
(Typ
);
11547 Set_Is_Volatile
(Typ
);
11548 Set_Treat_As_Volatile
(Typ
);
11553 if Is_Record_Type
(Typ
)
11554 and then Typ
/= Base_Type
(Typ
) and then Is_Frozen
(Base_Type
(Typ
))
11556 Set_Convention
(Typ
, Convention
(Base_Type
(Typ
)));
11559 -- Default_Component_Value
11561 -- Verify that there is no rep_item declared for the type, and there
11562 -- is one coming from an ancestor.
11564 if Is_Array_Type
(Typ
)
11565 and then Is_Base_Type
(Typ
)
11566 and then not Has_Rep_Item
(Typ
, Name_Default_Component_Value
, False)
11567 and then Has_Rep_Item
(Typ
, Name_Default_Component_Value
)
11569 Set_Default_Aspect_Component_Value
(Typ
,
11570 Default_Aspect_Component_Value
11571 (Entity
(Get_Rep_Item
(Typ
, Name_Default_Component_Value
))));
11576 if Is_Scalar_Type
(Typ
)
11577 and then Is_Base_Type
(Typ
)
11578 and then not Has_Rep_Item
(Typ
, Name_Default_Value
, False)
11579 and then Has_Rep_Item
(Typ
, Name_Default_Value
)
11581 Set_Has_Default_Aspect
(Typ
);
11582 Set_Default_Aspect_Value
(Typ
,
11583 Default_Aspect_Value
11584 (Entity
(Get_Rep_Item
(Typ
, Name_Default_Value
))));
11589 if not Has_Rep_Item
(Typ
, Name_Discard_Names
, False)
11590 and then Has_Rep_Item
(Typ
, Name_Discard_Names
)
11591 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11592 (Get_Rep_Item
(Typ
, Name_Discard_Names
))
11594 Set_Discard_Names
(Typ
);
11599 if not Has_Rep_Item
(Typ
, Name_Volatile
, False)
11600 and then Has_Rep_Item
(Typ
, Name_Volatile
)
11601 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11602 (Get_Rep_Item
(Typ
, Name_Volatile
))
11604 Set_Is_Volatile
(Typ
);
11605 Set_Treat_As_Volatile
(Typ
);
11608 -- Volatile_Full_Access
11610 if not Has_Rep_Item
(Typ
, Name_Volatile_Full_Access
, False)
11611 and then Has_Rep_Pragma
(Typ
, Name_Volatile_Full_Access
)
11612 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11613 (Get_Rep_Item
(Typ
, Name_Volatile_Full_Access
))
11615 Set_Is_Volatile_Full_Access
(Typ
);
11616 Set_Is_Volatile
(Typ
);
11617 Set_Treat_As_Volatile
(Typ
);
11620 -- Inheritance for derived types only
11622 if Is_Derived_Type
(Typ
) then
11624 Bas_Typ
: constant Entity_Id
:= Base_Type
(Typ
);
11625 Imp_Bas_Typ
: constant Entity_Id
:= Implementation_Base_Type
(Typ
);
11628 -- Atomic_Components
11630 if not Has_Rep_Item
(Typ
, Name_Atomic_Components
, False)
11631 and then Has_Rep_Item
(Typ
, Name_Atomic_Components
)
11632 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11633 (Get_Rep_Item
(Typ
, Name_Atomic_Components
))
11635 Set_Has_Atomic_Components
(Imp_Bas_Typ
);
11638 -- Volatile_Components
11640 if not Has_Rep_Item
(Typ
, Name_Volatile_Components
, False)
11641 and then Has_Rep_Item
(Typ
, Name_Volatile_Components
)
11642 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11643 (Get_Rep_Item
(Typ
, Name_Volatile_Components
))
11645 Set_Has_Volatile_Components
(Imp_Bas_Typ
);
11648 -- Finalize_Storage_Only
11650 if not Has_Rep_Pragma
(Typ
, Name_Finalize_Storage_Only
, False)
11651 and then Has_Rep_Pragma
(Typ
, Name_Finalize_Storage_Only
)
11653 Set_Finalize_Storage_Only
(Bas_Typ
);
11656 -- Universal_Aliasing
11658 if not Has_Rep_Item
(Typ
, Name_Universal_Aliasing
, False)
11659 and then Has_Rep_Item
(Typ
, Name_Universal_Aliasing
)
11660 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11661 (Get_Rep_Item
(Typ
, Name_Universal_Aliasing
))
11663 Set_Universal_Aliasing
(Imp_Bas_Typ
);
11668 if Is_Record_Type
(Typ
) then
11669 if not Has_Rep_Item
(Typ
, Name_Bit_Order
, False)
11670 and then Has_Rep_Item
(Typ
, Name_Bit_Order
)
11672 Set_Reverse_Bit_Order
(Bas_Typ
,
11673 Reverse_Bit_Order
(Rep_Item_Entity
11674 (Get_Rep_Item
(Typ
, Name_Bit_Order
))));
11678 -- Scalar_Storage_Order
11680 -- Note: the aspect is specified on a first subtype, but recorded
11681 -- in a flag of the base type!
11683 if (Is_Record_Type
(Typ
) or else Is_Array_Type
(Typ
))
11684 and then Typ
= Bas_Typ
11686 -- For a type extension, always inherit from parent; otherwise
11687 -- inherit if no default applies. Note: we do not check for
11688 -- an explicit rep item on the parent type when inheriting,
11689 -- because the parent SSO may itself have been set by default.
11691 if not Has_Rep_Item
(First_Subtype
(Typ
),
11692 Name_Scalar_Storage_Order
, False)
11693 and then (Is_Tagged_Type
(Bas_Typ
)
11694 or else not (SSO_Set_Low_By_Default
(Bas_Typ
)
11696 SSO_Set_High_By_Default
(Bas_Typ
)))
11698 Set_Reverse_Storage_Order
(Bas_Typ
,
11699 Reverse_Storage_Order
11700 (Implementation_Base_Type
(Etype
(Bas_Typ
))));
11702 -- Clear default SSO indications, since the inherited aspect
11703 -- which was set explicitly overrides the default.
11705 Set_SSO_Set_Low_By_Default
(Bas_Typ
, False);
11706 Set_SSO_Set_High_By_Default
(Bas_Typ
, False);
11711 end Inherit_Aspects_At_Freeze_Point
;
11717 procedure Initialize
is
11719 Address_Clause_Checks
.Init
;
11720 Compile_Time_Warnings_Errors
.Init
;
11721 Unchecked_Conversions
.Init
;
11723 -- ??? Might be needed in the future for some non GCC back-ends
11724 -- if AAMP_On_Target then
11725 -- Independence_Checks.Init;
11729 ---------------------------
11730 -- Install_Discriminants --
11731 ---------------------------
11733 procedure Install_Discriminants
(E
: Entity_Id
) is
11737 Disc
:= First_Discriminant
(E
);
11738 while Present
(Disc
) loop
11739 Prev
:= Current_Entity
(Disc
);
11740 Set_Current_Entity
(Disc
);
11741 Set_Is_Immediately_Visible
(Disc
);
11742 Set_Homonym
(Disc
, Prev
);
11743 Next_Discriminant
(Disc
);
11745 end Install_Discriminants
;
11747 -------------------------
11748 -- Is_Operational_Item --
11749 -------------------------
11751 function Is_Operational_Item
(N
: Node_Id
) return Boolean is
11753 if Nkind
(N
) /= N_Attribute_Definition_Clause
then
11758 Id
: constant Attribute_Id
:= Get_Attribute_Id
(Chars
(N
));
11761 -- List of operational items is given in AARM 13.1(8.mm/1).
11762 -- It is clearly incomplete, as it does not include iterator
11763 -- aspects, among others.
11765 return Id
= Attribute_Constant_Indexing
11766 or else Id
= Attribute_Default_Iterator
11767 or else Id
= Attribute_Implicit_Dereference
11768 or else Id
= Attribute_Input
11769 or else Id
= Attribute_Iterator_Element
11770 or else Id
= Attribute_Iterable
11771 or else Id
= Attribute_Output
11772 or else Id
= Attribute_Read
11773 or else Id
= Attribute_Variable_Indexing
11774 or else Id
= Attribute_Write
11775 or else Id
= Attribute_External_Tag
;
11778 end Is_Operational_Item
;
11780 -------------------------
11781 -- Is_Predicate_Static --
11782 -------------------------
11784 -- Note: the basic legality of the expression has already been checked, so
11785 -- we don't need to worry about cases or ranges on strings for example.
11787 function Is_Predicate_Static
11789 Nam
: Name_Id
) return Boolean
11791 function All_Static_Case_Alternatives
(L
: List_Id
) return Boolean;
11792 -- Given a list of case expression alternatives, returns True if all
11793 -- the alternatives are static (have all static choices, and a static
11796 function All_Static_Choices
(L
: List_Id
) return Boolean;
11797 -- Returns true if all elements of the list are OK static choices
11798 -- as defined below for Is_Static_Choice. Used for case expression
11799 -- alternatives and for the right operand of a membership test. An
11800 -- others_choice is static if the corresponding expression is static.
11801 -- The staticness of the bounds is checked separately.
11803 function Is_Static_Choice
(N
: Node_Id
) return Boolean;
11804 -- Returns True if N represents a static choice (static subtype, or
11805 -- static subtype indication, or static expression, or static range).
11807 -- Note that this is a bit more inclusive than we actually need
11808 -- (in particular membership tests do not allow the use of subtype
11809 -- indications). But that doesn't matter, we have already checked
11810 -- that the construct is legal to get this far.
11812 function Is_Type_Ref
(N
: Node_Id
) return Boolean;
11813 pragma Inline
(Is_Type_Ref
);
11814 -- Returns True if N is a reference to the type for the predicate in the
11815 -- expression (i.e. if it is an identifier whose Chars field matches the
11816 -- Nam given in the call). N must not be parenthesized, if the type name
11817 -- appears in parens, this routine will return False.
11819 -- The routine also returns True for function calls generated during the
11820 -- expansion of comparison operators on strings, which are intended to
11821 -- be legal in static predicates, and are converted into calls to array
11822 -- comparison routines in the body of the corresponding predicate
11825 ----------------------------------
11826 -- All_Static_Case_Alternatives --
11827 ----------------------------------
11829 function All_Static_Case_Alternatives
(L
: List_Id
) return Boolean is
11834 while Present
(N
) loop
11835 if not (All_Static_Choices
(Discrete_Choices
(N
))
11836 and then Is_OK_Static_Expression
(Expression
(N
)))
11845 end All_Static_Case_Alternatives
;
11847 ------------------------
11848 -- All_Static_Choices --
11849 ------------------------
11851 function All_Static_Choices
(L
: List_Id
) return Boolean is
11856 while Present
(N
) loop
11857 if not Is_Static_Choice
(N
) then
11865 end All_Static_Choices
;
11867 ----------------------
11868 -- Is_Static_Choice --
11869 ----------------------
11871 function Is_Static_Choice
(N
: Node_Id
) return Boolean is
11873 return Nkind
(N
) = N_Others_Choice
11874 or else Is_OK_Static_Expression
(N
)
11875 or else (Is_Entity_Name
(N
) and then Is_Type
(Entity
(N
))
11876 and then Is_OK_Static_Subtype
(Entity
(N
)))
11877 or else (Nkind
(N
) = N_Subtype_Indication
11878 and then Is_OK_Static_Subtype
(Entity
(N
)))
11879 or else (Nkind
(N
) = N_Range
and then Is_OK_Static_Range
(N
));
11880 end Is_Static_Choice
;
11886 function Is_Type_Ref
(N
: Node_Id
) return Boolean is
11888 return (Nkind
(N
) = N_Identifier
11889 and then Chars
(N
) = Nam
11890 and then Paren_Count
(N
) = 0)
11891 or else Nkind
(N
) = N_Function_Call
;
11894 -- Start of processing for Is_Predicate_Static
11897 -- Predicate_Static means one of the following holds. Numbers are the
11898 -- corresponding paragraph numbers in (RM 3.2.4(16-22)).
11900 -- 16: A static expression
11902 if Is_OK_Static_Expression
(Expr
) then
11905 -- 17: A membership test whose simple_expression is the current
11906 -- instance, and whose membership_choice_list meets the requirements
11907 -- for a static membership test.
11909 elsif Nkind
(Expr
) in N_Membership_Test
11910 and then ((Present
(Right_Opnd
(Expr
))
11911 and then Is_Static_Choice
(Right_Opnd
(Expr
)))
11913 (Present
(Alternatives
(Expr
))
11914 and then All_Static_Choices
(Alternatives
(Expr
))))
11918 -- 18. A case_expression whose selecting_expression is the current
11919 -- instance, and whose dependent expressions are static expressions.
11921 elsif Nkind
(Expr
) = N_Case_Expression
11922 and then Is_Type_Ref
(Expression
(Expr
))
11923 and then All_Static_Case_Alternatives
(Alternatives
(Expr
))
11927 -- 19. A call to a predefined equality or ordering operator, where one
11928 -- operand is the current instance, and the other is a static
11931 -- Note: the RM is clearly wrong here in not excluding string types.
11932 -- Without this exclusion, we would allow expressions like X > "ABC"
11933 -- to be considered as predicate-static, which is clearly not intended,
11934 -- since the idea is for predicate-static to be a subset of normal
11935 -- static expressions (and "DEF" > "ABC" is not a static expression).
11937 -- However, we do allow internally generated (not from source) equality
11938 -- and inequality operations to be valid on strings (this helps deal
11939 -- with cases where we transform A in "ABC" to A = "ABC).
11941 -- In fact, it appears that the intent of the ARG is to extend static
11942 -- predicates to strings, and that the extension should probably apply
11943 -- to static expressions themselves. The code below accepts comparison
11944 -- operators that apply to static strings.
11946 elsif Nkind
(Expr
) in N_Op_Compare
11947 and then ((Is_Type_Ref
(Left_Opnd
(Expr
))
11948 and then Is_OK_Static_Expression
(Right_Opnd
(Expr
)))
11950 (Is_Type_Ref
(Right_Opnd
(Expr
))
11951 and then Is_OK_Static_Expression
(Left_Opnd
(Expr
))))
11955 -- 20. A call to a predefined boolean logical operator, where each
11956 -- operand is predicate-static.
11958 elsif (Nkind_In
(Expr
, N_Op_And
, N_Op_Or
, N_Op_Xor
)
11959 and then Is_Predicate_Static
(Left_Opnd
(Expr
), Nam
)
11960 and then Is_Predicate_Static
(Right_Opnd
(Expr
), Nam
))
11962 (Nkind
(Expr
) = N_Op_Not
11963 and then Is_Predicate_Static
(Right_Opnd
(Expr
), Nam
))
11967 -- 21. A short-circuit control form where both operands are
11968 -- predicate-static.
11970 elsif Nkind
(Expr
) in N_Short_Circuit
11971 and then Is_Predicate_Static
(Left_Opnd
(Expr
), Nam
)
11972 and then Is_Predicate_Static
(Right_Opnd
(Expr
), Nam
)
11976 -- 22. A parenthesized predicate-static expression. This does not
11977 -- require any special test, since we just ignore paren levels in
11978 -- all the cases above.
11980 -- One more test that is an implementation artifact caused by the fact
11981 -- that we are analyzing not the original expression, but the generated
11982 -- expression in the body of the predicate function. This can include
11983 -- references to inherited predicates, so that the expression we are
11984 -- processing looks like:
11986 -- xxPredicate (typ (Inns)) and then expression
11988 -- Where the call is to a Predicate function for an inherited predicate.
11989 -- We simply ignore such a call, which could be to either a dynamic or
11990 -- a static predicate. Note that if the parent predicate is dynamic then
11991 -- eventually this type will be marked as dynamic, but you are allowed
11992 -- to specify a static predicate for a subtype which is inheriting a
11993 -- dynamic predicate, so the static predicate validation here ignores
11994 -- the inherited predicate even if it is dynamic.
11995 -- In all cases, a static predicate can only apply to a scalar type.
11997 elsif Nkind
(Expr
) = N_Function_Call
11998 and then Is_Predicate_Function
(Entity
(Name
(Expr
)))
11999 and then Is_Scalar_Type
(Etype
(First_Entity
(Entity
(Name
(Expr
)))))
12003 elsif Is_Entity_Name
(Expr
)
12004 and then Entity
(Expr
) = Standard_True
12006 Error_Msg_N
("predicate is redundant (always True)?", Expr
);
12009 -- That's an exhaustive list of tests, all other cases are not
12010 -- predicate-static, so we return False.
12015 end Is_Predicate_Static
;
12017 ---------------------
12018 -- Kill_Rep_Clause --
12019 ---------------------
12021 procedure Kill_Rep_Clause
(N
: Node_Id
) is
12023 pragma Assert
(Ignore_Rep_Clauses
);
12025 -- Note: we use Replace rather than Rewrite, because we don't want
12026 -- ASIS to be able to use Original_Node to dig out the (undecorated)
12027 -- rep clause that is being replaced.
12029 Replace
(N
, Make_Null_Statement
(Sloc
(N
)));
12031 -- The null statement must be marked as not coming from source. This is
12032 -- so that ASIS ignores it, and also the back end does not expect bogus
12033 -- "from source" null statements in weird places (e.g. in declarative
12034 -- regions where such null statements are not allowed).
12036 Set_Comes_From_Source
(N
, False);
12037 end Kill_Rep_Clause
;
12043 function Minimum_Size
12045 Biased
: Boolean := False) return Nat
12047 Lo
: Uint
:= No_Uint
;
12048 Hi
: Uint
:= No_Uint
;
12049 LoR
: Ureal
:= No_Ureal
;
12050 HiR
: Ureal
:= No_Ureal
;
12051 LoSet
: Boolean := False;
12052 HiSet
: Boolean := False;
12055 Ancest
: Entity_Id
;
12056 R_Typ
: constant Entity_Id
:= Root_Type
(T
);
12059 -- If bad type, return 0
12061 if T
= Any_Type
then
12064 -- For generic types, just return zero. There cannot be any legitimate
12065 -- need to know such a size, but this routine may be called with a
12066 -- generic type as part of normal processing.
12068 elsif Is_Generic_Type
(R_Typ
) or else R_Typ
= Any_Type
then
12071 -- Access types (cannot have size smaller than System.Address)
12073 elsif Is_Access_Type
(T
) then
12074 return System_Address_Size
;
12076 -- Floating-point types
12078 elsif Is_Floating_Point_Type
(T
) then
12079 return UI_To_Int
(Esize
(R_Typ
));
12083 elsif Is_Discrete_Type
(T
) then
12085 -- The following loop is looking for the nearest compile time known
12086 -- bounds following the ancestor subtype chain. The idea is to find
12087 -- the most restrictive known bounds information.
12091 if Ancest
= Any_Type
or else Etype
(Ancest
) = Any_Type
then
12096 if Compile_Time_Known_Value
(Type_Low_Bound
(Ancest
)) then
12097 Lo
:= Expr_Rep_Value
(Type_Low_Bound
(Ancest
));
12104 if Compile_Time_Known_Value
(Type_High_Bound
(Ancest
)) then
12105 Hi
:= Expr_Rep_Value
(Type_High_Bound
(Ancest
));
12111 Ancest
:= Ancestor_Subtype
(Ancest
);
12113 if No
(Ancest
) then
12114 Ancest
:= Base_Type
(T
);
12116 if Is_Generic_Type
(Ancest
) then
12122 -- Fixed-point types. We can't simply use Expr_Value to get the
12123 -- Corresponding_Integer_Value values of the bounds, since these do not
12124 -- get set till the type is frozen, and this routine can be called
12125 -- before the type is frozen. Similarly the test for bounds being static
12126 -- needs to include the case where we have unanalyzed real literals for
12127 -- the same reason.
12129 elsif Is_Fixed_Point_Type
(T
) then
12131 -- The following loop is looking for the nearest compile time known
12132 -- bounds following the ancestor subtype chain. The idea is to find
12133 -- the most restrictive known bounds information.
12137 if Ancest
= Any_Type
or else Etype
(Ancest
) = Any_Type
then
12141 -- Note: In the following two tests for LoSet and HiSet, it may
12142 -- seem redundant to test for N_Real_Literal here since normally
12143 -- one would assume that the test for the value being known at
12144 -- compile time includes this case. However, there is a glitch.
12145 -- If the real literal comes from folding a non-static expression,
12146 -- then we don't consider any non- static expression to be known
12147 -- at compile time if we are in configurable run time mode (needed
12148 -- in some cases to give a clearer definition of what is and what
12149 -- is not accepted). So the test is indeed needed. Without it, we
12150 -- would set neither Lo_Set nor Hi_Set and get an infinite loop.
12153 if Nkind
(Type_Low_Bound
(Ancest
)) = N_Real_Literal
12154 or else Compile_Time_Known_Value
(Type_Low_Bound
(Ancest
))
12156 LoR
:= Expr_Value_R
(Type_Low_Bound
(Ancest
));
12163 if Nkind
(Type_High_Bound
(Ancest
)) = N_Real_Literal
12164 or else Compile_Time_Known_Value
(Type_High_Bound
(Ancest
))
12166 HiR
:= Expr_Value_R
(Type_High_Bound
(Ancest
));
12172 Ancest
:= Ancestor_Subtype
(Ancest
);
12174 if No
(Ancest
) then
12175 Ancest
:= Base_Type
(T
);
12177 if Is_Generic_Type
(Ancest
) then
12183 Lo
:= UR_To_Uint
(LoR
/ Small_Value
(T
));
12184 Hi
:= UR_To_Uint
(HiR
/ Small_Value
(T
));
12186 -- No other types allowed
12189 raise Program_Error
;
12192 -- Fall through with Hi and Lo set. Deal with biased case
12195 and then not Is_Fixed_Point_Type
(T
)
12196 and then not (Is_Enumeration_Type
(T
)
12197 and then Has_Non_Standard_Rep
(T
)))
12198 or else Has_Biased_Representation
(T
)
12204 -- Null range case, size is always zero. We only do this in the discrete
12205 -- type case, since that's the odd case that came up. Probably we should
12206 -- also do this in the fixed-point case, but doing so causes peculiar
12207 -- gigi failures, and it is not worth worrying about this incredibly
12208 -- marginal case (explicit null-range fixed-point type declarations)???
12210 if Lo
> Hi
and then Is_Discrete_Type
(T
) then
12213 -- Signed case. Note that we consider types like range 1 .. -1 to be
12214 -- signed for the purpose of computing the size, since the bounds have
12215 -- to be accommodated in the base type.
12217 elsif Lo
< 0 or else Hi
< 0 then
12221 -- S = size, B = 2 ** (size - 1) (can accommodate -B .. +(B - 1))
12222 -- Note that we accommodate the case where the bounds cross. This
12223 -- can happen either because of the way the bounds are declared
12224 -- or because of the algorithm in Freeze_Fixed_Point_Type.
12238 -- If both bounds are positive, make sure that both are represen-
12239 -- table in the case where the bounds are crossed. This can happen
12240 -- either because of the way the bounds are declared, or because of
12241 -- the algorithm in Freeze_Fixed_Point_Type.
12247 -- S = size, (can accommodate 0 .. (2**size - 1))
12250 while Hi
>= Uint_2
** S
loop
12258 ---------------------------
12259 -- New_Stream_Subprogram --
12260 ---------------------------
12262 procedure New_Stream_Subprogram
12266 Nam
: TSS_Name_Type
)
12268 Loc
: constant Source_Ptr
:= Sloc
(N
);
12269 Sname
: constant Name_Id
:= Make_TSS_Name
(Base_Type
(Ent
), Nam
);
12270 Subp_Id
: Entity_Id
;
12271 Subp_Decl
: Node_Id
;
12275 Defer_Declaration
: constant Boolean :=
12276 Is_Tagged_Type
(Ent
) or else Is_Private_Type
(Ent
);
12277 -- For a tagged type, there is a declaration for each stream attribute
12278 -- at the freeze point, and we must generate only a completion of this
12279 -- declaration. We do the same for private types, because the full view
12280 -- might be tagged. Otherwise we generate a declaration at the point of
12281 -- the attribute definition clause. If the attribute definition comes
12282 -- from an aspect specification the declaration is part of the freeze
12283 -- actions of the type.
12285 function Build_Spec
return Node_Id
;
12286 -- Used for declaration and renaming declaration, so that this is
12287 -- treated as a renaming_as_body.
12293 function Build_Spec
return Node_Id
is
12294 Out_P
: constant Boolean := (Nam
= TSS_Stream_Read
);
12297 T_Ref
: constant Node_Id
:= New_Occurrence_Of
(Etyp
, Loc
);
12300 Subp_Id
:= Make_Defining_Identifier
(Loc
, Sname
);
12302 -- S : access Root_Stream_Type'Class
12304 Formals
:= New_List
(
12305 Make_Parameter_Specification
(Loc
,
12306 Defining_Identifier
=>
12307 Make_Defining_Identifier
(Loc
, Name_S
),
12309 Make_Access_Definition
(Loc
,
12311 New_Occurrence_Of
(
12312 Designated_Type
(Etype
(F
)), Loc
))));
12314 if Nam
= TSS_Stream_Input
then
12316 Make_Function_Specification
(Loc
,
12317 Defining_Unit_Name
=> Subp_Id
,
12318 Parameter_Specifications
=> Formals
,
12319 Result_Definition
=> T_Ref
);
12323 Append_To
(Formals
,
12324 Make_Parameter_Specification
(Loc
,
12325 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_V
),
12326 Out_Present
=> Out_P
,
12327 Parameter_Type
=> T_Ref
));
12330 Make_Procedure_Specification
(Loc
,
12331 Defining_Unit_Name
=> Subp_Id
,
12332 Parameter_Specifications
=> Formals
);
12338 -- Start of processing for New_Stream_Subprogram
12341 F
:= First_Formal
(Subp
);
12343 if Ekind
(Subp
) = E_Procedure
then
12344 Etyp
:= Etype
(Next_Formal
(F
));
12346 Etyp
:= Etype
(Subp
);
12349 -- Prepare subprogram declaration and insert it as an action on the
12350 -- clause node. The visibility for this entity is used to test for
12351 -- visibility of the attribute definition clause (in the sense of
12352 -- 8.3(23) as amended by AI-195).
12354 if not Defer_Declaration
then
12356 Make_Subprogram_Declaration
(Loc
,
12357 Specification
=> Build_Spec
);
12359 -- For a tagged type, there is always a visible declaration for each
12360 -- stream TSS (it is a predefined primitive operation), and the
12361 -- completion of this declaration occurs at the freeze point, which is
12362 -- not always visible at places where the attribute definition clause is
12363 -- visible. So, we create a dummy entity here for the purpose of
12364 -- tracking the visibility of the attribute definition clause itself.
12368 Make_Defining_Identifier
(Loc
, New_External_Name
(Sname
, 'V'));
12370 Make_Object_Declaration
(Loc
,
12371 Defining_Identifier
=> Subp_Id
,
12372 Object_Definition
=> New_Occurrence_Of
(Standard_Boolean
, Loc
));
12375 if not Defer_Declaration
12376 and then From_Aspect_Specification
(N
)
12377 and then Has_Delayed_Freeze
(Ent
)
12379 Append_Freeze_Action
(Ent
, Subp_Decl
);
12382 Insert_Action
(N
, Subp_Decl
);
12383 Set_Entity
(N
, Subp_Id
);
12387 Make_Subprogram_Renaming_Declaration
(Loc
,
12388 Specification
=> Build_Spec
,
12389 Name
=> New_Occurrence_Of
(Subp
, Loc
));
12391 if Defer_Declaration
then
12392 Set_TSS
(Base_Type
(Ent
), Subp_Id
);
12395 if From_Aspect_Specification
(N
) then
12396 Append_Freeze_Action
(Ent
, Subp_Decl
);
12398 Insert_Action
(N
, Subp_Decl
);
12401 Copy_TSS
(Subp_Id
, Base_Type
(Ent
));
12403 end New_Stream_Subprogram
;
12405 ------------------------------------------
12406 -- Push_Scope_And_Install_Discriminants --
12407 ------------------------------------------
12409 procedure Push_Scope_And_Install_Discriminants
(E
: Entity_Id
) is
12411 if Is_Type
(E
) and then Has_Discriminants
(E
) then
12414 -- Make the discriminants visible for type declarations and protected
12415 -- type declarations, not for subtype declarations (RM 13.1.1 (12/3))
12417 if Nkind
(Parent
(E
)) /= N_Subtype_Declaration
then
12418 Install_Discriminants
(E
);
12421 end Push_Scope_And_Install_Discriminants
;
12423 -----------------------------------
12424 -- Register_Address_Clause_Check --
12425 -----------------------------------
12427 procedure Register_Address_Clause_Check
12434 ACS
: constant Boolean := Scope_Suppress
.Suppress
(Alignment_Check
);
12436 Address_Clause_Checks
.Append
((N
, X
, A
, Y
, Off
, ACS
));
12437 end Register_Address_Clause_Check
;
12439 ------------------------
12440 -- Rep_Item_Too_Early --
12441 ------------------------
12443 function Rep_Item_Too_Early
(T
: Entity_Id
; N
: Node_Id
) return Boolean is
12445 -- Cannot apply non-operational rep items to generic types
12447 if Is_Operational_Item
(N
) then
12451 and then Is_Generic_Type
(Root_Type
(T
))
12452 and then (Nkind
(N
) /= N_Pragma
12453 or else Get_Pragma_Id
(N
) /= Pragma_Convention
)
12455 Error_Msg_N
("representation item not allowed for generic type", N
);
12459 -- Otherwise check for incomplete type
12461 if Is_Incomplete_Or_Private_Type
(T
)
12462 and then No
(Underlying_Type
(T
))
12464 (Nkind
(N
) /= N_Pragma
12465 or else Get_Pragma_Id
(N
) /= Pragma_Import
)
12468 ("representation item must be after full type declaration", N
);
12471 -- If the type has incomplete components, a representation clause is
12472 -- illegal but stream attributes and Convention pragmas are correct.
12474 elsif Has_Private_Component
(T
) then
12475 if Nkind
(N
) = N_Pragma
then
12480 ("representation item must appear after type is fully defined",
12487 end Rep_Item_Too_Early
;
12489 -----------------------
12490 -- Rep_Item_Too_Late --
12491 -----------------------
12493 function Rep_Item_Too_Late
12496 FOnly
: Boolean := False) return Boolean
12499 Parent_Type
: Entity_Id
;
12501 procedure No_Type_Rep_Item
;
12502 -- Output message indicating that no type-related aspects can be
12503 -- specified due to some property of the parent type.
12505 procedure Too_Late
;
12506 -- Output message for an aspect being specified too late
12508 -- Note that neither of the above errors is considered a serious one,
12509 -- since the effect is simply that we ignore the representation clause
12511 -- Is this really true? In any case if we make this change we must
12512 -- document the requirement in the spec of Rep_Item_Too_Late that
12513 -- if True is returned, then the rep item must be completely ignored???
12515 ----------------------
12516 -- No_Type_Rep_Item --
12517 ----------------------
12519 procedure No_Type_Rep_Item
is
12521 Error_Msg_N
("|type-related representation item not permitted!", N
);
12522 end No_Type_Rep_Item
;
12528 procedure Too_Late
is
12530 -- Other compilers seem more relaxed about rep items appearing too
12531 -- late. Since analysis tools typically don't care about rep items
12532 -- anyway, no reason to be too strict about this.
12534 if not Relaxed_RM_Semantics
then
12535 Error_Msg_N
("|representation item appears too late!", N
);
12539 -- Start of processing for Rep_Item_Too_Late
12542 -- First make sure entity is not frozen (RM 13.1(9))
12546 -- Exclude imported types, which may be frozen if they appear in a
12547 -- representation clause for a local type.
12549 and then not From_Limited_With
(T
)
12551 -- Exclude generated entities (not coming from source). The common
12552 -- case is when we generate a renaming which prematurely freezes the
12553 -- renamed internal entity, but we still want to be able to set copies
12554 -- of attribute values such as Size/Alignment.
12556 and then Comes_From_Source
(T
)
12558 -- A self-referential aspect is illegal if it forces freezing the
12559 -- entity before the corresponding pragma has been analyzed.
12561 if Nkind_In
(N
, N_Attribute_Definition_Clause
, N_Pragma
)
12562 and then From_Aspect_Specification
(N
)
12565 ("aspect specification causes premature freezing of&", N
, T
);
12566 Set_Has_Delayed_Freeze
(T
, False);
12571 S
:= First_Subtype
(T
);
12573 if Present
(Freeze_Node
(S
)) then
12574 if not Relaxed_RM_Semantics
then
12576 ("??no more representation items for }", Freeze_Node
(S
), S
);
12582 -- Check for case of untagged derived type whose parent either has
12583 -- primitive operations, or is a by reference type (RM 13.1(10)). In
12584 -- this case we do not output a Too_Late message, since there is no
12585 -- earlier point where the rep item could be placed to make it legal.
12589 and then Is_Derived_Type
(T
)
12590 and then not Is_Tagged_Type
(T
)
12592 Parent_Type
:= Etype
(Base_Type
(T
));
12594 if Has_Primitive_Operations
(Parent_Type
) then
12597 if not Relaxed_RM_Semantics
then
12599 ("\parent type & has primitive operations!", N
, Parent_Type
);
12604 elsif Is_By_Reference_Type
(Parent_Type
) then
12607 if not Relaxed_RM_Semantics
then
12609 ("\parent type & is a by reference type!", N
, Parent_Type
);
12616 -- No error, but one more warning to consider. The RM (surprisingly)
12617 -- allows this pattern:
12620 -- primitive operations for S
12621 -- type R is new S;
12622 -- rep clause for S
12624 -- Meaning that calls on the primitive operations of S for values of
12625 -- type R may require possibly expensive implicit conversion operations.
12626 -- This is not an error, but is worth a warning.
12628 if not Relaxed_RM_Semantics
and then Is_Type
(T
) then
12630 DTL
: constant Entity_Id
:= Derived_Type_Link
(Base_Type
(T
));
12634 and then Has_Primitive_Operations
(Base_Type
(T
))
12636 -- For now, do not generate this warning for the case of aspect
12637 -- specification using Ada 2012 syntax, since we get wrong
12638 -- messages we do not understand. The whole business of derived
12639 -- types and rep items seems a bit confused when aspects are
12640 -- used, since the aspects are not evaluated till freeze time.
12642 and then not From_Aspect_Specification
(N
)
12644 Error_Msg_Sloc
:= Sloc
(DTL
);
12646 ("representation item for& appears after derived type "
12647 & "declaration#??", N
);
12649 ("\may result in implicit conversions for primitive "
12650 & "operations of&??", N
, T
);
12652 ("\to change representations when called with arguments "
12653 & "of type&??", N
, DTL
);
12658 -- No error, link item into head of chain of rep items for the entity,
12659 -- but avoid chaining if we have an overloadable entity, and the pragma
12660 -- is one that can apply to multiple overloaded entities.
12662 if Is_Overloadable
(T
) and then Nkind
(N
) = N_Pragma
then
12664 Pname
: constant Name_Id
:= Pragma_Name
(N
);
12666 if Nam_In
(Pname
, Name_Convention
, Name_Import
, Name_Export
,
12667 Name_External
, Name_Interface
)
12674 Record_Rep_Item
(T
, N
);
12676 end Rep_Item_Too_Late
;
12678 -------------------------------------
12679 -- Replace_Type_References_Generic --
12680 -------------------------------------
12682 procedure Replace_Type_References_Generic
(N
: Node_Id
; T
: Entity_Id
) is
12683 TName
: constant Name_Id
:= Chars
(T
);
12685 function Replace_Type_Ref
(N
: Node_Id
) return Traverse_Result
;
12686 -- Processes a single node in the traversal procedure below, checking
12687 -- if node N should be replaced, and if so, doing the replacement.
12689 function Visible_Component
(Comp
: Name_Id
) return Entity_Id
;
12690 -- Given an identifier in the expression, check whether there is a
12691 -- discriminant or component of the type that is directy visible, and
12692 -- rewrite it as the corresponding selected component of the formal of
12693 -- the subprogram. The entity is located by a sequential search, which
12694 -- seems acceptable given the typical size of component lists and check
12695 -- expressions. Possible optimization ???
12697 ----------------------
12698 -- Replace_Type_Ref --
12699 ----------------------
12701 function Replace_Type_Ref
(N
: Node_Id
) return Traverse_Result
is
12702 Loc
: constant Source_Ptr
:= Sloc
(N
);
12704 procedure Add_Prefix
(Ref
: Node_Id
; Comp
: Entity_Id
);
12705 -- Add the proper prefix to a reference to a component of the type
12706 -- when it is not already a selected component.
12712 procedure Add_Prefix
(Ref
: Node_Id
; Comp
: Entity_Id
) is
12715 Make_Selected_Component
(Loc
,
12716 Prefix
=> New_Occurrence_Of
(T
, Loc
),
12717 Selector_Name
=> New_Occurrence_Of
(Comp
, Loc
)));
12718 Replace_Type_Reference
(Prefix
(Ref
));
12727 -- Start of processing for Replace_Type_Ref
12730 if Nkind
(N
) = N_Identifier
then
12732 -- If not the type name, check whether it is a reference to some
12733 -- other type, which must be frozen before the predicate function
12734 -- is analyzed, i.e. before the freeze node of the type to which
12735 -- the predicate applies.
12737 if Chars
(N
) /= TName
then
12738 if Present
(Current_Entity
(N
))
12739 and then Is_Type
(Current_Entity
(N
))
12741 Freeze_Before
(Freeze_Node
(T
), Current_Entity
(N
));
12744 -- The components of the type are directly visible and can
12745 -- be referenced without a prefix.
12747 if Nkind
(Parent
(N
)) = N_Selected_Component
then
12750 -- In expression C (I), C may be a directly visible function
12751 -- or a visible component that has an array type. Disambiguate
12752 -- by examining the component type.
12754 elsif Nkind
(Parent
(N
)) = N_Indexed_Component
12755 and then N
= Prefix
(Parent
(N
))
12757 Comp
:= Visible_Component
(Chars
(N
));
12759 if Present
(Comp
) and then Is_Array_Type
(Etype
(Comp
)) then
12760 Add_Prefix
(N
, Comp
);
12764 Comp
:= Visible_Component
(Chars
(N
));
12766 if Present
(Comp
) then
12767 Add_Prefix
(N
, Comp
);
12773 -- Otherwise do the replacement if this is not a qualified
12774 -- reference to a homograph of the type itself. Note that the
12775 -- current instance could not appear in such a context, e.g.
12776 -- the prefix of a type conversion.
12779 if Nkind
(Parent
(N
)) /= N_Selected_Component
12780 or else N
/= Selector_Name
(Parent
(N
))
12782 Replace_Type_Reference
(N
);
12788 -- Case of selected component, which may be a subcomponent of the
12789 -- current instance, or an expanded name which is still unanalyzed.
12791 elsif Nkind
(N
) = N_Selected_Component
then
12793 -- If selector name is not our type, keep going (we might still
12794 -- have an occurrence of the type in the prefix). If it is a
12795 -- subcomponent of the current entity, add prefix.
12797 if Nkind
(Selector_Name
(N
)) /= N_Identifier
12798 or else Chars
(Selector_Name
(N
)) /= TName
12800 if Nkind
(Prefix
(N
)) = N_Identifier
then
12801 Comp
:= Visible_Component
(Chars
(Prefix
(N
)));
12803 if Present
(Comp
) then
12804 Add_Prefix
(Prefix
(N
), Comp
);
12810 -- Selector name is our type, check qualification
12813 -- Loop through scopes and prefixes, doing comparison
12815 Scop
:= Current_Scope
;
12816 Pref
:= Prefix
(N
);
12818 -- Continue if no more scopes or scope with no name
12820 if No
(Scop
) or else Nkind
(Scop
) not in N_Has_Chars
then
12824 -- Do replace if prefix is an identifier matching the scope
12825 -- that we are currently looking at.
12827 if Nkind
(Pref
) = N_Identifier
12828 and then Chars
(Pref
) = Chars
(Scop
)
12830 Replace_Type_Reference
(N
);
12834 -- Go check scope above us if prefix is itself of the form
12835 -- of a selected component, whose selector matches the scope
12836 -- we are currently looking at.
12838 if Nkind
(Pref
) = N_Selected_Component
12839 and then Nkind
(Selector_Name
(Pref
)) = N_Identifier
12840 and then Chars
(Selector_Name
(Pref
)) = Chars
(Scop
)
12842 Scop
:= Scope
(Scop
);
12843 Pref
:= Prefix
(Pref
);
12845 -- For anything else, we don't have a match, so keep on
12846 -- going, there are still some weird cases where we may
12847 -- still have a replacement within the prefix.
12855 -- Continue for any other node kind
12860 end Replace_Type_Ref
;
12862 procedure Replace_Type_Refs
is new Traverse_Proc
(Replace_Type_Ref
);
12864 -----------------------
12865 -- Visible_Component --
12866 -----------------------
12868 function Visible_Component
(Comp
: Name_Id
) return Entity_Id
is
12872 -- Types with nameable components are records and discriminated
12875 if Ekind
(T
) = E_Record_Type
12876 or else (Is_Private_Type
(T
) and then Has_Discriminants
(T
))
12878 E
:= First_Entity
(T
);
12879 while Present
(E
) loop
12880 if Comes_From_Source
(E
) and then Chars
(E
) = Comp
then
12888 -- Nothing by that name, or the type has no components
12891 end Visible_Component
;
12893 -- Start of processing for Replace_Type_References_Generic
12896 Replace_Type_Refs
(N
);
12897 end Replace_Type_References_Generic
;
12899 --------------------------------
12900 -- Resolve_Aspect_Expressions --
12901 --------------------------------
12903 procedure Resolve_Aspect_Expressions
(E
: Entity_Id
) is
12904 function Resolve_Name
(N
: Node_Id
) return Traverse_Result
;
12905 -- Verify that all identifiers in the expression, with the exception
12906 -- of references to the current entity, denote visible entities. This
12907 -- is done only to detect visibility errors, as the expression will be
12908 -- properly analyzed/expanded during analysis of the predicate function
12909 -- body. We omit quantified expressions from this test, given that they
12910 -- introduce a local identifier that would require proper expansion to
12911 -- handle properly.
12913 -- In ASIS_Mode we preserve the entity in the source because there is
12914 -- no subsequent expansion to decorate the tree.
12920 function Resolve_Name
(N
: Node_Id
) return Traverse_Result
is
12921 Dummy
: Traverse_Result
;
12924 if Nkind
(N
) = N_Selected_Component
then
12925 if Nkind
(Prefix
(N
)) = N_Identifier
12926 and then Chars
(Prefix
(N
)) /= Chars
(E
)
12928 Find_Selected_Component
(N
);
12933 -- Resolve identifiers that are not selectors in parameter
12934 -- associations (these are never resolved by visibility).
12936 elsif Nkind
(N
) = N_Identifier
12937 and then Chars
(N
) /= Chars
(E
)
12938 and then (Nkind
(Parent
(N
)) /= N_Parameter_Association
12939 or else N
/= Selector_Name
(Parent
(N
)))
12941 Find_Direct_Name
(N
);
12943 -- In ASIS mode we must analyze overloaded identifiers to ensure
12944 -- their correct decoration because expansion is disabled (and
12945 -- the expansion of freeze nodes takes care of resolving aspect
12949 if Is_Overloaded
(N
) then
12950 Analyze
(Parent
(N
));
12953 Set_Entity
(N
, Empty
);
12956 -- The name is component association needs no resolution.
12958 elsif Nkind
(N
) = N_Component_Association
then
12959 Dummy
:= Resolve_Name
(Expression
(N
));
12962 elsif Nkind
(N
) = N_Quantified_Expression
then
12969 procedure Resolve_Aspect_Expression
is new Traverse_Proc
(Resolve_Name
);
12973 ASN
: Node_Id
:= First_Rep_Item
(E
);
12975 -- Start of processing for Resolve_Aspect_Expressions
12978 -- Need to make sure discriminants, if any, are directly visible
12980 Push_Scope_And_Install_Discriminants
(E
);
12982 while Present
(ASN
) loop
12983 if Nkind
(ASN
) = N_Aspect_Specification
and then Entity
(ASN
) = E
then
12985 A_Id
: constant Aspect_Id
:= Get_Aspect_Id
(ASN
);
12986 Expr
: constant Node_Id
:= Expression
(ASN
);
12991 -- For now we only deal with aspects that do not generate
12992 -- subprograms, or that may mention current instances of
12993 -- types. These will require special handling (???TBD).
12995 when Aspect_Invariant
12997 | Aspect_Predicate_Failure
13001 when Aspect_Dynamic_Predicate
13002 | Aspect_Static_Predicate
13004 -- Build predicate function specification and preanalyze
13005 -- expression after type replacement. The function
13006 -- declaration must be analyzed in the scope of the
13007 -- type, but the expression must see components.
13009 if No
(Predicate_Function
(E
)) then
13010 Uninstall_Discriminants_And_Pop_Scope
(E
);
13012 FDecl
: constant Node_Id
:=
13013 Build_Predicate_Function_Declaration
(E
);
13014 pragma Unreferenced
(FDecl
);
13017 Push_Scope_And_Install_Discriminants
(E
);
13018 Resolve_Aspect_Expression
(Expr
);
13022 when Pre_Post_Aspects
=>
13025 when Aspect_Iterable
=>
13026 if Nkind
(Expr
) = N_Aggregate
then
13031 Assoc
:= First
(Component_Associations
(Expr
));
13032 while Present
(Assoc
) loop
13033 Find_Direct_Name
(Expression
(Assoc
));
13039 -- The expression for Default_Value is a static expression
13040 -- of the type, but this expression does not freeze the
13041 -- type, so it can still appear in a representation clause
13042 -- before the actual freeze point.
13044 when Aspect_Default_Value
=>
13045 Set_Must_Not_Freeze
(Expr
);
13046 Preanalyze_Spec_Expression
(Expr
, E
);
13048 -- Ditto for Storage_Size. Any other aspects that carry
13049 -- expressions that should not freeze ??? This is only
13050 -- relevant to the misuse of deferred constants.
13052 when Aspect_Storage_Size
=>
13053 Set_Must_Not_Freeze
(Expr
);
13054 Preanalyze_Spec_Expression
(Expr
, Any_Integer
);
13057 if Present
(Expr
) then
13058 case Aspect_Argument
(A_Id
) is
13060 | Optional_Expression
13062 Analyze_And_Resolve
(Expr
);
13067 if Nkind
(Expr
) = N_Identifier
then
13068 Find_Direct_Name
(Expr
);
13070 elsif Nkind
(Expr
) = N_Selected_Component
then
13071 Find_Selected_Component
(Expr
);
13079 ASN
:= Next_Rep_Item
(ASN
);
13082 Uninstall_Discriminants_And_Pop_Scope
(E
);
13083 end Resolve_Aspect_Expressions
;
13085 -------------------------
13086 -- Same_Representation --
13087 -------------------------
13089 function Same_Representation
(Typ1
, Typ2
: Entity_Id
) return Boolean is
13090 T1
: constant Entity_Id
:= Underlying_Type
(Typ1
);
13091 T2
: constant Entity_Id
:= Underlying_Type
(Typ2
);
13094 -- A quick check, if base types are the same, then we definitely have
13095 -- the same representation, because the subtype specific representation
13096 -- attributes (Size and Alignment) do not affect representation from
13097 -- the point of view of this test.
13099 if Base_Type
(T1
) = Base_Type
(T2
) then
13102 elsif Is_Private_Type
(Base_Type
(T2
))
13103 and then Base_Type
(T1
) = Full_View
(Base_Type
(T2
))
13108 -- Tagged types always have the same representation, because it is not
13109 -- possible to specify different representations for common fields.
13111 if Is_Tagged_Type
(T1
) then
13115 -- Representations are definitely different if conventions differ
13117 if Convention
(T1
) /= Convention
(T2
) then
13121 -- Representations are different if component alignments or scalar
13122 -- storage orders differ.
13124 if (Is_Record_Type
(T1
) or else Is_Array_Type
(T1
))
13126 (Is_Record_Type
(T2
) or else Is_Array_Type
(T2
))
13128 (Component_Alignment
(T1
) /= Component_Alignment
(T2
)
13129 or else Reverse_Storage_Order
(T1
) /= Reverse_Storage_Order
(T2
))
13134 -- For arrays, the only real issue is component size. If we know the
13135 -- component size for both arrays, and it is the same, then that's
13136 -- good enough to know we don't have a change of representation.
13138 if Is_Array_Type
(T1
) then
13139 if Known_Component_Size
(T1
)
13140 and then Known_Component_Size
(T2
)
13141 and then Component_Size
(T1
) = Component_Size
(T2
)
13147 -- For records, representations are different if reorderings differ
13149 if Is_Record_Type
(T1
)
13150 and then Is_Record_Type
(T2
)
13151 and then No_Reordering
(T1
) /= No_Reordering
(T2
)
13156 -- Types definitely have same representation if neither has non-standard
13157 -- representation since default representations are always consistent.
13158 -- If only one has non-standard representation, and the other does not,
13159 -- then we consider that they do not have the same representation. They
13160 -- might, but there is no way of telling early enough.
13162 if Has_Non_Standard_Rep
(T1
) then
13163 if not Has_Non_Standard_Rep
(T2
) then
13167 return not Has_Non_Standard_Rep
(T2
);
13170 -- Here the two types both have non-standard representation, and we need
13171 -- to determine if they have the same non-standard representation.
13173 -- For arrays, we simply need to test if the component sizes are the
13174 -- same. Pragma Pack is reflected in modified component sizes, so this
13175 -- check also deals with pragma Pack.
13177 if Is_Array_Type
(T1
) then
13178 return Component_Size
(T1
) = Component_Size
(T2
);
13180 -- Case of record types
13182 elsif Is_Record_Type
(T1
) then
13184 -- Packed status must conform
13186 if Is_Packed
(T1
) /= Is_Packed
(T2
) then
13189 -- Otherwise we must check components. Typ2 maybe a constrained
13190 -- subtype with fewer components, so we compare the components
13191 -- of the base types.
13194 Record_Case
: declare
13195 CD1
, CD2
: Entity_Id
;
13197 function Same_Rep
return Boolean;
13198 -- CD1 and CD2 are either components or discriminants. This
13199 -- function tests whether they have the same representation.
13205 function Same_Rep
return Boolean is
13207 if No
(Component_Clause
(CD1
)) then
13208 return No
(Component_Clause
(CD2
));
13210 -- Note: at this point, component clauses have been
13211 -- normalized to the default bit order, so that the
13212 -- comparison of Component_Bit_Offsets is meaningful.
13215 Present
(Component_Clause
(CD2
))
13217 Component_Bit_Offset
(CD1
) = Component_Bit_Offset
(CD2
)
13219 Esize
(CD1
) = Esize
(CD2
);
13223 -- Start of processing for Record_Case
13226 if Has_Discriminants
(T1
) then
13228 -- The number of discriminants may be different if the
13229 -- derived type has fewer (constrained by values). The
13230 -- invisible discriminants retain the representation of
13231 -- the original, so the discrepancy does not per se
13232 -- indicate a different representation.
13234 CD1
:= First_Discriminant
(T1
);
13235 CD2
:= First_Discriminant
(T2
);
13236 while Present
(CD1
) and then Present
(CD2
) loop
13237 if not Same_Rep
then
13240 Next_Discriminant
(CD1
);
13241 Next_Discriminant
(CD2
);
13246 CD1
:= First_Component
(Underlying_Type
(Base_Type
(T1
)));
13247 CD2
:= First_Component
(Underlying_Type
(Base_Type
(T2
)));
13248 while Present
(CD1
) loop
13249 if not Same_Rep
then
13252 Next_Component
(CD1
);
13253 Next_Component
(CD2
);
13261 -- For enumeration types, we must check each literal to see if the
13262 -- representation is the same. Note that we do not permit enumeration
13263 -- representation clauses for Character and Wide_Character, so these
13264 -- cases were already dealt with.
13266 elsif Is_Enumeration_Type
(T1
) then
13267 Enumeration_Case
: declare
13268 L1
, L2
: Entity_Id
;
13271 L1
:= First_Literal
(T1
);
13272 L2
:= First_Literal
(T2
);
13273 while Present
(L1
) loop
13274 if Enumeration_Rep
(L1
) /= Enumeration_Rep
(L2
) then
13283 end Enumeration_Case
;
13285 -- Any other types have the same representation for these purposes
13290 end Same_Representation
;
13292 --------------------------------
13293 -- Resolve_Iterable_Operation --
13294 --------------------------------
13296 procedure Resolve_Iterable_Operation
13298 Cursor
: Entity_Id
;
13307 if not Is_Overloaded
(N
) then
13308 if not Is_Entity_Name
(N
)
13309 or else Ekind
(Entity
(N
)) /= E_Function
13310 or else Scope
(Entity
(N
)) /= Scope
(Typ
)
13311 or else No
(First_Formal
(Entity
(N
)))
13312 or else Etype
(First_Formal
(Entity
(N
))) /= Typ
13315 ("iterable primitive must be local function name whose first "
13316 & "formal is an iterable type", N
);
13321 F1
:= First_Formal
(Ent
);
13323 if Nam
= Name_First
or else Nam
= Name_Last
then
13325 -- First or Last (Container) => Cursor
13327 if Etype
(Ent
) /= Cursor
then
13328 Error_Msg_N
("primitive for First must yield a curosr", N
);
13331 elsif Nam
= Name_Next
then
13333 -- Next (Container, Cursor) => Cursor
13335 F2
:= Next_Formal
(F1
);
13337 if Etype
(F2
) /= Cursor
13338 or else Etype
(Ent
) /= Cursor
13339 or else Present
(Next_Formal
(F2
))
13341 Error_Msg_N
("no match for Next iterable primitive", N
);
13344 elsif Nam
= Name_Previous
then
13346 -- Previous (Container, Cursor) => Cursor
13348 F2
:= Next_Formal
(F1
);
13350 if Etype
(F2
) /= Cursor
13351 or else Etype
(Ent
) /= Cursor
13352 or else Present
(Next_Formal
(F2
))
13354 Error_Msg_N
("no match for Previous iterable primitive", N
);
13357 elsif Nam
= Name_Has_Element
then
13359 -- Has_Element (Container, Cursor) => Boolean
13361 F2
:= Next_Formal
(F1
);
13363 if Etype
(F2
) /= Cursor
13364 or else Etype
(Ent
) /= Standard_Boolean
13365 or else Present
(Next_Formal
(F2
))
13367 Error_Msg_N
("no match for Has_Element iterable primitive", N
);
13370 elsif Nam
= Name_Element
then
13371 F2
:= Next_Formal
(F1
);
13374 or else Etype
(F2
) /= Cursor
13375 or else Present
(Next_Formal
(F2
))
13377 Error_Msg_N
("no match for Element iterable primitive", N
);
13381 raise Program_Error
;
13385 -- Overloaded case: find subprogram with proper signature. Caller
13386 -- will report error if no match is found.
13393 Get_First_Interp
(N
, I
, It
);
13394 while Present
(It
.Typ
) loop
13395 if Ekind
(It
.Nam
) = E_Function
13396 and then Scope
(It
.Nam
) = Scope
(Typ
)
13397 and then Etype
(First_Formal
(It
.Nam
)) = Typ
13399 F1
:= First_Formal
(It
.Nam
);
13401 if Nam
= Name_First
then
13402 if Etype
(It
.Nam
) = Cursor
13403 and then No
(Next_Formal
(F1
))
13405 Set_Entity
(N
, It
.Nam
);
13409 elsif Nam
= Name_Next
then
13410 F2
:= Next_Formal
(F1
);
13413 and then No
(Next_Formal
(F2
))
13414 and then Etype
(F2
) = Cursor
13415 and then Etype
(It
.Nam
) = Cursor
13417 Set_Entity
(N
, It
.Nam
);
13421 elsif Nam
= Name_Has_Element
then
13422 F2
:= Next_Formal
(F1
);
13425 and then No
(Next_Formal
(F2
))
13426 and then Etype
(F2
) = Cursor
13427 and then Etype
(It
.Nam
) = Standard_Boolean
13429 Set_Entity
(N
, It
.Nam
);
13430 F2
:= Next_Formal
(F1
);
13434 elsif Nam
= Name_Element
then
13435 F2
:= Next_Formal
(F1
);
13438 and then No
(Next_Formal
(F2
))
13439 and then Etype
(F2
) = Cursor
13441 Set_Entity
(N
, It
.Nam
);
13447 Get_Next_Interp
(I
, It
);
13451 end Resolve_Iterable_Operation
;
13457 procedure Set_Biased
13461 Biased
: Boolean := True)
13465 Set_Has_Biased_Representation
(E
);
13467 if Warn_On_Biased_Representation
then
13469 ("?B?" & Msg
& " forces biased representation for&", N
, E
);
13474 --------------------
13475 -- Set_Enum_Esize --
13476 --------------------
13478 procedure Set_Enum_Esize
(T
: Entity_Id
) is
13484 Init_Alignment
(T
);
13486 -- Find the minimum standard size (8,16,32,64) that fits
13488 Lo
:= Enumeration_Rep
(Entity
(Type_Low_Bound
(T
)));
13489 Hi
:= Enumeration_Rep
(Entity
(Type_High_Bound
(T
)));
13492 if Lo
>= -Uint_2
**07 and then Hi
< Uint_2
**07 then
13493 Sz
:= Standard_Character_Size
; -- May be > 8 on some targets
13495 elsif Lo
>= -Uint_2
**15 and then Hi
< Uint_2
**15 then
13498 elsif Lo
>= -Uint_2
**31 and then Hi
< Uint_2
**31 then
13501 else pragma Assert
(Lo
>= -Uint_2
**63 and then Hi
< Uint_2
**63);
13506 if Hi
< Uint_2
**08 then
13507 Sz
:= Standard_Character_Size
; -- May be > 8 on some targets
13509 elsif Hi
< Uint_2
**16 then
13512 elsif Hi
< Uint_2
**32 then
13515 else pragma Assert
(Hi
< Uint_2
**63);
13520 -- That minimum is the proper size unless we have a foreign convention
13521 -- and the size required is 32 or less, in which case we bump the size
13522 -- up to 32. This is required for C and C++ and seems reasonable for
13523 -- all other foreign conventions.
13525 if Has_Foreign_Convention
(T
)
13526 and then Esize
(T
) < Standard_Integer_Size
13528 -- Don't do this if Short_Enums on target
13530 and then not Target_Short_Enums
13532 Init_Esize
(T
, Standard_Integer_Size
);
13534 Init_Esize
(T
, Sz
);
13536 end Set_Enum_Esize
;
13538 -----------------------------
13539 -- Uninstall_Discriminants --
13540 -----------------------------
13542 procedure Uninstall_Discriminants
(E
: Entity_Id
) is
13548 -- Discriminants have been made visible for type declarations and
13549 -- protected type declarations, not for subtype declarations.
13551 if Nkind
(Parent
(E
)) /= N_Subtype_Declaration
then
13552 Disc
:= First_Discriminant
(E
);
13553 while Present
(Disc
) loop
13554 if Disc
/= Current_Entity
(Disc
) then
13555 Prev
:= Current_Entity
(Disc
);
13556 while Present
(Prev
)
13557 and then Present
(Homonym
(Prev
))
13558 and then Homonym
(Prev
) /= Disc
13560 Prev
:= Homonym
(Prev
);
13566 Set_Is_Immediately_Visible
(Disc
, False);
13568 Outer
:= Homonym
(Disc
);
13569 while Present
(Outer
) and then Scope
(Outer
) = E
loop
13570 Outer
:= Homonym
(Outer
);
13573 -- Reset homonym link of other entities, but do not modify link
13574 -- between entities in current scope, so that the back end can
13575 -- have a proper count of local overloadings.
13578 Set_Name_Entity_Id
(Chars
(Disc
), Outer
);
13580 elsif Scope
(Prev
) /= Scope
(Disc
) then
13581 Set_Homonym
(Prev
, Outer
);
13584 Next_Discriminant
(Disc
);
13587 end Uninstall_Discriminants
;
13589 -------------------------------------------
13590 -- Uninstall_Discriminants_And_Pop_Scope --
13591 -------------------------------------------
13593 procedure Uninstall_Discriminants_And_Pop_Scope
(E
: Entity_Id
) is
13595 if Is_Type
(E
) and then Has_Discriminants
(E
) then
13596 Uninstall_Discriminants
(E
);
13599 end Uninstall_Discriminants_And_Pop_Scope
;
13601 ------------------------------
13602 -- Validate_Address_Clauses --
13603 ------------------------------
13605 procedure Validate_Address_Clauses
is
13606 function Offset_Value
(Expr
: Node_Id
) return Uint
;
13607 -- Given an Address attribute reference, return the value in bits of its
13608 -- offset from the first bit of the underlying entity, or 0 if it is not
13609 -- known at compile time.
13615 function Offset_Value
(Expr
: Node_Id
) return Uint
is
13616 N
: Node_Id
:= Prefix
(Expr
);
13618 Val
: Uint
:= Uint_0
;
13621 -- Climb the prefix chain and compute the cumulative offset
13624 if Is_Entity_Name
(N
) then
13627 elsif Nkind
(N
) = N_Selected_Component
then
13628 Off
:= Component_Bit_Offset
(Entity
(Selector_Name
(N
)));
13629 if Off
/= No_Uint
and then Off
>= Uint_0
then
13636 elsif Nkind
(N
) = N_Indexed_Component
then
13637 Off
:= Indexed_Component_Bit_Offset
(N
);
13638 if Off
/= No_Uint
then
13651 -- Start of processing for Validate_Address_Clauses
13654 for J
in Address_Clause_Checks
.First
.. Address_Clause_Checks
.Last
loop
13656 ACCR
: Address_Clause_Check_Record
13657 renames Address_Clause_Checks
.Table
(J
);
13661 X_Alignment
: Uint
;
13662 Y_Alignment
: Uint
:= Uint_0
;
13665 Y_Size
: Uint
:= Uint_0
;
13670 -- Skip processing of this entry if warning already posted
13672 if not Address_Warning_Posted
(ACCR
.N
) then
13673 Expr
:= Original_Node
(Expression
(ACCR
.N
));
13675 -- Get alignments, sizes and offset, if any
13677 X_Alignment
:= Alignment
(ACCR
.X
);
13678 X_Size
:= Esize
(ACCR
.X
);
13680 if Present
(ACCR
.Y
) then
13681 Y_Alignment
:= Alignment
(ACCR
.Y
);
13682 Y_Size
:= Esize
(ACCR
.Y
);
13686 and then Nkind
(Expr
) = N_Attribute_Reference
13687 and then Attribute_Name
(Expr
) = Name_Address
13689 X_Offs
:= Offset_Value
(Expr
);
13694 -- Check for known value not multiple of alignment
13696 if No
(ACCR
.Y
) then
13697 if not Alignment_Checks_Suppressed
(ACCR
)
13698 and then X_Alignment
/= 0
13699 and then ACCR
.A
mod X_Alignment
/= 0
13702 ("??specified address for& is inconsistent with "
13703 & "alignment", ACCR
.N
, ACCR
.X
);
13705 ("\??program execution may be erroneous (RM 13.3(27))",
13708 Error_Msg_Uint_1
:= X_Alignment
;
13709 Error_Msg_NE
("\??alignment of & is ^", ACCR
.N
, ACCR
.X
);
13712 -- Check for large object overlaying smaller one
13714 elsif Y_Size
> Uint_0
13715 and then X_Size
> Uint_0
13716 and then X_Offs
+ X_Size
> Y_Size
13718 Error_Msg_NE
("??& overlays smaller object", ACCR
.N
, ACCR
.X
);
13720 ("\??program execution may be erroneous", ACCR
.N
);
13722 Error_Msg_Uint_1
:= X_Size
;
13723 Error_Msg_NE
("\??size of & is ^", ACCR
.N
, ACCR
.X
);
13725 Error_Msg_Uint_1
:= Y_Size
;
13726 Error_Msg_NE
("\??size of & is ^", ACCR
.N
, ACCR
.Y
);
13728 if Y_Size
>= X_Size
then
13729 Error_Msg_Uint_1
:= X_Offs
;
13730 Error_Msg_NE
("\??but offset of & is ^", ACCR
.N
, ACCR
.X
);
13733 -- Check for inadequate alignment, both of the base object
13734 -- and of the offset, if any. We only do this check if the
13735 -- run-time Alignment_Check is active. No point in warning
13736 -- if this check has been suppressed (or is suppressed by
13737 -- default in the non-strict alignment machine case).
13739 -- Note: we do not check the alignment if we gave a size
13740 -- warning, since it would likely be redundant.
13742 elsif not Alignment_Checks_Suppressed
(ACCR
)
13743 and then Y_Alignment
/= Uint_0
13745 (Y_Alignment
< X_Alignment
13748 and then Nkind
(Expr
) = N_Attribute_Reference
13749 and then Attribute_Name
(Expr
) = Name_Address
13750 and then Has_Compatible_Alignment
13751 (ACCR
.X
, Prefix
(Expr
), True) /=
13755 ("??specified address for& may be inconsistent with "
13756 & "alignment", ACCR
.N
, ACCR
.X
);
13758 ("\??program execution may be erroneous (RM 13.3(27))",
13761 Error_Msg_Uint_1
:= X_Alignment
;
13762 Error_Msg_NE
("\??alignment of & is ^", ACCR
.N
, ACCR
.X
);
13764 Error_Msg_Uint_1
:= Y_Alignment
;
13765 Error_Msg_NE
("\??alignment of & is ^", ACCR
.N
, ACCR
.Y
);
13767 if Y_Alignment
>= X_Alignment
then
13769 ("\??but offset is not multiple of alignment", ACCR
.N
);
13775 end Validate_Address_Clauses
;
13777 -----------------------------------------
13778 -- Validate_Compile_Time_Warning_Error --
13779 -----------------------------------------
13781 procedure Validate_Compile_Time_Warning_Error
(N
: Node_Id
) is
13783 Compile_Time_Warnings_Errors
.Append
13784 (New_Val
=> CTWE_Entry
'(Eloc => Sloc (N),
13785 Scope => Current_Scope,
13787 end Validate_Compile_Time_Warning_Error;
13789 ------------------------------------------
13790 -- Validate_Compile_Time_Warning_Errors --
13791 ------------------------------------------
13793 procedure Validate_Compile_Time_Warning_Errors is
13794 procedure Set_Scope (S : Entity_Id);
13795 -- Install all enclosing scopes of S along with S itself
13797 procedure Unset_Scope (S : Entity_Id);
13798 -- Uninstall all enclosing scopes of S along with S itself
13804 procedure Set_Scope (S : Entity_Id) is
13806 if S /= Standard_Standard then
13807 Set_Scope (Scope (S));
13817 procedure Unset_Scope (S : Entity_Id) is
13819 if S /= Standard_Standard then
13820 Unset_Scope (Scope (S));
13826 -- Start of processing for Validate_Compile_Time_Warning_Errors
13829 Expander_Mode_Save_And_Set (False);
13830 In_Compile_Time_Warning_Or_Error := True;
13832 for N in Compile_Time_Warnings_Errors.First ..
13833 Compile_Time_Warnings_Errors.Last
13836 T : CTWE_Entry renames Compile_Time_Warnings_Errors.Table (N);
13839 Set_Scope (T.Scope);
13840 Reset_Analyzed_Flags (T.Prag);
13841 Process_Compile_Time_Warning_Or_Error (T.Prag, T.Eloc);
13842 Unset_Scope (T.Scope);
13846 In_Compile_Time_Warning_Or_Error := False;
13847 Expander_Mode_Restore;
13848 end Validate_Compile_Time_Warning_Errors;
13850 ---------------------------
13851 -- Validate_Independence --
13852 ---------------------------
13854 procedure Validate_Independence is
13855 SU : constant Uint := UI_From_Int (System_Storage_Unit);
13863 procedure Check_Array_Type (Atyp : Entity_Id);
13864 -- Checks if the array type Atyp has independent components, and
13865 -- if not, outputs an appropriate set of error messages.
13867 procedure No_Independence;
13868 -- Output message that independence cannot be guaranteed
13870 function OK_Component (C : Entity_Id) return Boolean;
13871 -- Checks one component to see if it is independently accessible, and
13872 -- if so yields True, otherwise yields False if independent access
13873 -- cannot be guaranteed. This is a conservative routine, it only
13874 -- returns True if it knows for sure, it returns False if it knows
13875 -- there is a problem, or it cannot be sure there is no problem.
13877 procedure Reason_Bad_Component (C : Entity_Id);
13878 -- Outputs continuation message if a reason can be determined for
13879 -- the component C being bad.
13881 ----------------------
13882 -- Check_Array_Type --
13883 ----------------------
13885 procedure Check_Array_Type (Atyp : Entity_Id) is
13886 Ctyp : constant Entity_Id := Component_Type (Atyp);
13889 -- OK if no alignment clause, no pack, and no component size
13891 if not Has_Component_Size_Clause (Atyp)
13892 and then not Has_Alignment_Clause (Atyp)
13893 and then not Is_Packed (Atyp)
13898 -- Case of component size is greater than or equal to 64 and the
13899 -- alignment of the array is at least as large as the alignment
13900 -- of the component. We are definitely OK in this situation.
13902 if Known_Component_Size (Atyp)
13903 and then Component_Size (Atyp) >= 64
13904 and then Known_Alignment (Atyp)
13905 and then Known_Alignment (Ctyp)
13906 and then Alignment (Atyp) >= Alignment (Ctyp)
13911 -- Check actual component size
13913 if not Known_Component_Size (Atyp)
13914 or else not (Addressable (Component_Size (Atyp))
13915 and then Component_Size (Atyp) < 64)
13916 or else Component_Size (Atyp) mod Esize (Ctyp) /= 0
13920 -- Bad component size, check reason
13922 if Has_Component_Size_Clause (Atyp) then
13923 P := Get_Attribute_Definition_Clause
13924 (Atyp, Attribute_Component_Size);
13926 if Present (P) then
13927 Error_Msg_Sloc := Sloc (P);
13928 Error_Msg_N ("\because of Component_Size clause#", N);
13933 if Is_Packed (Atyp) then
13934 P := Get_Rep_Pragma (Atyp, Name_Pack);
13936 if Present (P) then
13937 Error_Msg_Sloc := Sloc (P);
13938 Error_Msg_N ("\because of pragma Pack#", N);
13943 -- No reason found, just return
13948 -- Array type is OK independence-wise
13951 end Check_Array_Type;
13953 ---------------------
13954 -- No_Independence --
13955 ---------------------
13957 procedure No_Independence is
13959 if Pragma_Name (N) = Name_Independent then
13960 Error_Msg_NE ("independence cannot be guaranteed for&", N, E);
13963 ("independent components cannot be guaranteed for&", N, E);
13965 end No_Independence;
13971 function OK_Component (C : Entity_Id) return Boolean is
13972 Rec : constant Entity_Id := Scope (C);
13973 Ctyp : constant Entity_Id := Etype (C);
13976 -- OK if no component clause, no Pack, and no alignment clause
13978 if No (Component_Clause (C))
13979 and then not Is_Packed (Rec)
13980 and then not Has_Alignment_Clause (Rec)
13985 -- Here we look at the actual component layout. A component is
13986 -- addressable if its size is a multiple of the Esize of the
13987 -- component type, and its starting position in the record has
13988 -- appropriate alignment, and the record itself has appropriate
13989 -- alignment to guarantee the component alignment.
13991 -- Make sure sizes are static, always assume the worst for any
13992 -- cases where we cannot check static values.
13994 if not (Known_Static_Esize (C)
13996 Known_Static_Esize (Ctyp))
14001 -- Size of component must be addressable or greater than 64 bits
14002 -- and a multiple of bytes.
14004 if not Addressable (Esize (C)) and then Esize (C) < Uint_64 then
14008 -- Check size is proper multiple
14010 if Esize (C) mod Esize (Ctyp) /= 0 then
14014 -- Check alignment of component is OK
14016 if not Known_Component_Bit_Offset (C)
14017 or else Component_Bit_Offset (C) < Uint_0
14018 or else Component_Bit_Offset (C) mod Esize (Ctyp) /= 0
14023 -- Check alignment of record type is OK
14025 if not Known_Alignment (Rec)
14026 or else (Alignment (Rec) * SU) mod Esize (Ctyp) /= 0
14031 -- All tests passed, component is addressable
14036 --------------------------
14037 -- Reason_Bad_Component --
14038 --------------------------
14040 procedure Reason_Bad_Component (C : Entity_Id) is
14041 Rec : constant Entity_Id := Scope (C);
14042 Ctyp : constant Entity_Id := Etype (C);
14045 -- If component clause present assume that's the problem
14047 if Present (Component_Clause (C)) then
14048 Error_Msg_Sloc := Sloc (Component_Clause (C));
14049 Error_Msg_N ("\because of Component_Clause#", N);
14053 -- If pragma Pack clause present, assume that's the problem
14055 if Is_Packed (Rec) then
14056 P := Get_Rep_Pragma (Rec, Name_Pack);
14058 if Present (P) then
14059 Error_Msg_Sloc := Sloc (P);
14060 Error_Msg_N ("\because of pragma Pack#", N);
14065 -- See if record has bad alignment clause
14067 if Has_Alignment_Clause (Rec)
14068 and then Known_Alignment (Rec)
14069 and then (Alignment (Rec) * SU) mod Esize (Ctyp) /= 0
14071 P := Get_Attribute_Definition_Clause (Rec, Attribute_Alignment);
14073 if Present (P) then
14074 Error_Msg_Sloc := Sloc (P);
14075 Error_Msg_N ("\because of Alignment clause#", N);
14079 -- Couldn't find a reason, so return without a message
14082 end Reason_Bad_Component;
14084 -- Start of processing for Validate_Independence
14087 for J in Independence_Checks.First .. Independence_Checks.Last loop
14088 N := Independence_Checks.Table (J).N;
14089 E := Independence_Checks.Table (J).E;
14090 IC := Pragma_Name (N) = Name_Independent_Components;
14092 -- Deal with component case
14094 if Ekind (E) = E_Discriminant or else Ekind (E) = E_Component then
14095 if not OK_Component (E) then
14097 Reason_Bad_Component (E);
14102 -- Deal with record with Independent_Components
14104 if IC and then Is_Record_Type (E) then
14105 Comp := First_Component_Or_Discriminant (E);
14106 while Present (Comp) loop
14107 if not OK_Component (Comp) then
14109 Reason_Bad_Component (Comp);
14113 Next_Component_Or_Discriminant (Comp);
14117 -- Deal with address clause case
14119 if Is_Object (E) then
14120 Addr := Address_Clause (E);
14122 if Present (Addr) then
14124 Error_Msg_Sloc := Sloc (Addr);
14125 Error_Msg_N ("\because of Address clause#", N);
14130 -- Deal with independent components for array type
14132 if IC and then Is_Array_Type (E) then
14133 Check_Array_Type (E);
14136 -- Deal with independent components for array object
14138 if IC and then Is_Object (E) and then Is_Array_Type (Etype (E)) then
14139 Check_Array_Type (Etype (E));
14144 end Validate_Independence;
14146 ------------------------------
14147 -- Validate_Iterable_Aspect --
14148 ------------------------------
14150 procedure Validate_Iterable_Aspect (Typ : Entity_Id; ASN : Node_Id) is
14155 Cursor : constant Entity_Id := Get_Cursor_Type (ASN, Typ);
14157 First_Id : Entity_Id;
14158 Last_Id : Entity_Id;
14159 Next_Id : Entity_Id;
14160 Has_Element_Id : Entity_Id;
14161 Element_Id : Entity_Id;
14164 -- If previous error aspect is unusable
14166 if Cursor = Any_Type then
14173 Has_Element_Id := Empty;
14174 Element_Id := Empty;
14176 -- Each expression must resolve to a function with the proper signature
14178 Assoc := First (Component_Associations (Expression (ASN)));
14179 while Present (Assoc) loop
14180 Expr := Expression (Assoc);
14183 Prim := First (Choices (Assoc));
14185 if Nkind (Prim) /= N_Identifier or else Present (Next (Prim)) then
14186 Error_Msg_N ("illegal name in association", Prim);
14188 elsif Chars (Prim) = Name_First then
14189 Resolve_Iterable_Operation (Expr, Cursor, Typ, Name_First);
14190 First_Id := Entity (Expr);
14192 elsif Chars (Prim) = Name_Last then
14193 Resolve_Iterable_Operation (Expr, Cursor, Typ, Name_Last);
14194 Last_Id := Entity (Expr);
14196 elsif Chars (Prim) = Name_Previous then
14197 Resolve_Iterable_Operation (Expr, Cursor, Typ, Name_Previous);
14198 Last_Id := Entity (Expr);
14200 elsif Chars (Prim) = Name_Next then
14201 Resolve_Iterable_Operation (Expr, Cursor, Typ, Name_Next);
14202 Next_Id := Entity (Expr);
14204 elsif Chars (Prim) = Name_Has_Element then
14205 Resolve_Iterable_Operation (Expr, Cursor, Typ, Name_Has_Element);
14206 Has_Element_Id := Entity (Expr);
14208 elsif Chars (Prim) = Name_Element then
14209 Resolve_Iterable_Operation (Expr, Cursor, Typ, Name_Element);
14210 Element_Id := Entity (Expr);
14213 Error_Msg_N ("invalid name for iterable function", Prim);
14219 if No (First_Id) then
14220 Error_Msg_N ("match for First primitive not found", ASN);
14222 elsif No (Next_Id) then
14223 Error_Msg_N ("match for Next primitive not found", ASN);
14225 elsif No (Has_Element_Id) then
14226 Error_Msg_N ("match for Has_Element primitive not found", ASN);
14228 elsif No (Element_Id) or else No (Last_Id) then
14231 end Validate_Iterable_Aspect;
14233 -----------------------------------
14234 -- Validate_Unchecked_Conversion --
14235 -----------------------------------
14237 procedure Validate_Unchecked_Conversion
14239 Act_Unit : Entity_Id)
14241 Source : Entity_Id;
14242 Target : Entity_Id;
14246 -- Obtain source and target types. Note that we call Ancestor_Subtype
14247 -- here because the processing for generic instantiation always makes
14248 -- subtypes, and we want the original frozen actual types.
14250 -- If we are dealing with private types, then do the check on their
14251 -- fully declared counterparts if the full declarations have been
14252 -- encountered (they don't have to be visible, but they must exist).
14254 Source := Ancestor_Subtype (Etype (First_Formal (Act_Unit)));
14256 if Is_Private_Type (Source)
14257 and then Present (Underlying_Type (Source))
14259 Source := Underlying_Type (Source);
14262 Target := Ancestor_Subtype (Etype (Act_Unit));
14264 -- If either type is generic, the instantiation happens within a generic
14265 -- unit, and there is nothing to check. The proper check will happen
14266 -- when the enclosing generic is instantiated.
14268 if Is_Generic_Type (Source) or else Is_Generic_Type (Target) then
14272 if Is_Private_Type (Target)
14273 and then Present (Underlying_Type (Target))
14275 Target := Underlying_Type (Target);
14278 -- Source may be unconstrained array, but not target, except in relaxed
14281 if Is_Array_Type (Target)
14282 and then not Is_Constrained (Target)
14283 and then not Relaxed_RM_Semantics
14286 ("unchecked conversion to unconstrained array not allowed", N);
14290 -- Warn if conversion between two different convention pointers
14292 if Is_Access_Type (Target)
14293 and then Is_Access_Type (Source)
14294 and then Convention (Target) /= Convention (Source)
14295 and then Warn_On_Unchecked_Conversion
14297 -- Give warnings for subprogram pointers only on most targets
14299 if Is_Access_Subprogram_Type (Target)
14300 or else Is_Access_Subprogram_Type (Source)
14303 ("?z?conversion between pointers with different conventions!",
14308 -- Warn if one of the operands is Ada.Calendar.Time. Do not emit a
14309 -- warning when compiling GNAT-related sources.
14311 if Warn_On_Unchecked_Conversion
14312 and then not In_Predefined_Unit (N)
14313 and then RTU_Loaded (Ada_Calendar)
14314 and then (Chars (Source) = Name_Time
14316 Chars (Target) = Name_Time)
14318 -- If Ada.Calendar is loaded and the name of one of the operands is
14319 -- Time, there is a good chance that this is Ada.Calendar.Time.
14322 Calendar_Time : constant Entity_Id := Full_View (RTE (RO_CA_Time));
14324 pragma Assert (Present (Calendar_Time));
14326 if Source = Calendar_Time or else Target = Calendar_Time then
14328 ("?z?representation of 'Time values may change between
"
14329 & "'G'N'A
'T versions
", N);
14334 -- Make entry in unchecked conversion table for later processing by
14335 -- Validate_Unchecked_Conversions, which will check sizes and alignments
14336 -- (using values set by the back end where possible). This is only done
14337 -- if the appropriate warning is active.
14339 if Warn_On_Unchecked_Conversion then
14340 Unchecked_Conversions.Append
14341 (New_Val => UC_Entry'(Eloc => Sloc (N),
14344 Act_Unit => Act_Unit));
14346 -- If both sizes are known statically now, then back-end annotation
14347 -- is not required to do a proper check but if either size is not
14348 -- known statically, then we need the annotation.
14350 if Known_Static_RM_Size (Source)
14352 Known_Static_RM_Size (Target)
14356 Back_Annotate_Rep_Info := True;
14360 -- If unchecked conversion to access type, and access type is declared
14361 -- in the same unit as the unchecked conversion, then set the flag
14362 -- No_Strict_Aliasing (no strict aliasing is implicit here)
14364 if Is_Access_Type (Target) and then
14365 In_Same_Source_Unit (Target, N)
14367 Set_No_Strict_Aliasing (Implementation_Base_Type (Target));
14370 -- Generate N_Validate_Unchecked_Conversion node for back end in case
14371 -- the back end needs to perform special validation checks.
14373 -- Shouldn't this be in Exp_Ch13, since the check only gets done if we
14374 -- have full expansion and the back end is called ???
14377 Make_Validate_Unchecked_Conversion (Sloc (N));
14378 Set_Source_Type (Vnode, Source);
14379 Set_Target_Type (Vnode, Target);
14381 -- If the unchecked conversion node is in a list, just insert before it.
14382 -- If not we have some strange case, not worth bothering about.
14384 if Is_List_Member (N) then
14385 Insert_After (N, Vnode);
14387 end Validate_Unchecked_Conversion;
14389 ------------------------------------
14390 -- Validate_Unchecked_Conversions --
14391 ------------------------------------
14393 procedure Validate_Unchecked_Conversions is
14395 for N in Unchecked_Conversions.First .. Unchecked_Conversions.Last loop
14397 T : UC_Entry renames Unchecked_Conversions.Table (N);
14399 Act_Unit : constant Entity_Id := T.Act_Unit;
14400 Eloc : constant Source_Ptr := T.Eloc;
14401 Source : constant Entity_Id := T.Source;
14402 Target : constant Entity_Id := T.Target;
14408 -- Skip if function marked as warnings off
14410 if Warnings_Off (Act_Unit) then
14414 -- This validation check, which warns if we have unequal sizes for
14415 -- unchecked conversion, and thus potentially implementation
14416 -- dependent semantics, is one of the few occasions on which we
14417 -- use the official RM size instead of Esize. See description in
14418 -- Einfo "Handling
of Type'Size Values
" for details.
14420 if Serious_Errors_Detected = 0
14421 and then Known_Static_RM_Size (Source)
14422 and then Known_Static_RM_Size (Target)
14424 -- Don't do the check if warnings off for either type, note the
14425 -- deliberate use of OR here instead of OR ELSE to get the flag
14426 -- Warnings_Off_Used set for both types if appropriate.
14428 and then not (Has_Warnings_Off (Source)
14430 Has_Warnings_Off (Target))
14432 Source_Siz := RM_Size (Source);
14433 Target_Siz := RM_Size (Target);
14435 if Source_Siz /= Target_Siz then
14437 ("?z?types
for unchecked conversion have different sizes
!",
14440 if All_Errors_Mode then
14441 Error_Msg_Name_1 := Chars (Source);
14442 Error_Msg_Uint_1 := Source_Siz;
14443 Error_Msg_Name_2 := Chars (Target);
14444 Error_Msg_Uint_2 := Target_Siz;
14445 Error_Msg ("\size
of % is ^
, size
of % is ^?z?
", Eloc);
14447 Error_Msg_Uint_1 := UI_Abs (Source_Siz - Target_Siz);
14449 if Is_Discrete_Type (Source)
14451 Is_Discrete_Type (Target)
14453 if Source_Siz > Target_Siz then
14455 ("\?z?^ high order bits
of source will
"
14456 & "be ignored
!", Eloc);
14458 elsif Is_Unsigned_Type (Source) then
14460 ("\?z?source will be extended
with ^ high order
"
14461 & "zero bits
!", Eloc);
14465 ("\?z?source will be extended
with ^ high order
"
14466 & "sign bits
!", Eloc);
14469 elsif Source_Siz < Target_Siz then
14470 if Is_Discrete_Type (Target) then
14471 if Bytes_Big_Endian then
14473 ("\?z?target value will include ^ undefined
"
14474 & "low order bits
!", Eloc, Act_Unit);
14477 ("\?z?target value will include ^ undefined
"
14478 & "high order bits
!", Eloc, Act_Unit);
14483 ("\?z?^ trailing bits
of target value will be
"
14484 & "undefined
!", Eloc, Act_Unit);
14487 else pragma Assert (Source_Siz > Target_Siz);
14488 if Is_Discrete_Type (Source) then
14489 if Bytes_Big_Endian then
14491 ("\?z?^ low order bits
of source will be
"
14492 & "ignored
!", Eloc, Act_Unit);
14495 ("\?z?^ high order bits
of source will be
"
14496 & "ignored
!", Eloc, Act_Unit);
14501 ("\?z?^ trailing bits
of source will be
"
14502 & "ignored
!", Eloc, Act_Unit);
14509 -- If both types are access types, we need to check the alignment.
14510 -- If the alignment of both is specified, we can do it here.
14512 if Serious_Errors_Detected = 0
14513 and then Is_Access_Type (Source)
14514 and then Is_Access_Type (Target)
14515 and then Target_Strict_Alignment
14516 and then Present (Designated_Type (Source))
14517 and then Present (Designated_Type (Target))
14520 D_Source : constant Entity_Id := Designated_Type (Source);
14521 D_Target : constant Entity_Id := Designated_Type (Target);
14524 if Known_Alignment (D_Source)
14526 Known_Alignment (D_Target)
14529 Source_Align : constant Uint := Alignment (D_Source);
14530 Target_Align : constant Uint := Alignment (D_Target);
14533 if Source_Align < Target_Align
14534 and then not Is_Tagged_Type (D_Source)
14536 -- Suppress warning if warnings suppressed on either
14537 -- type or either designated type. Note the use of
14538 -- OR here instead of OR ELSE. That is intentional,
14539 -- we would like to set flag Warnings_Off_Used in
14540 -- all types for which warnings are suppressed.
14542 and then not (Has_Warnings_Off (D_Source)
14544 Has_Warnings_Off (D_Target)
14546 Has_Warnings_Off (Source)
14548 Has_Warnings_Off (Target))
14550 Error_Msg_Uint_1 := Target_Align;
14551 Error_Msg_Uint_2 := Source_Align;
14552 Error_Msg_Node_1 := D_Target;
14553 Error_Msg_Node_2 := D_Source;
14555 ("?z?alignment
of & (^
) is stricter than
"
14556 & "alignment
of & (^
)!", Eloc, Act_Unit);
14558 ("\?z?resulting
access value may have invalid
"
14559 & "alignment
!", Eloc, Act_Unit);
14570 end Validate_Unchecked_Conversions;