1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2017, 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 -- pre-analyzed 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_Secondary_Stack_Size
2214 | Aspect_Simple_Storage_Pool
2217 | Aspect_Storage_Pool
2218 | Aspect_Stream_Size
2220 | Aspect_Variable_Indexing
2223 -- Indexing aspects apply only to tagged type
2225 if (A_Id
= Aspect_Constant_Indexing
2227 A_Id
= Aspect_Variable_Indexing
)
2228 and then not (Is_Type
(E
)
2229 and then Is_Tagged_Type
(E
))
2232 ("indexing aspect can only apply to a tagged type",
2237 -- For the case of aspect Address, we don't consider that we
2238 -- know the entity is never set in the source, since it is
2239 -- is likely aliasing is occurring.
2241 -- Note: one might think that the analysis of the resulting
2242 -- attribute definition clause would take care of that, but
2243 -- that's not the case since it won't be from source.
2245 if A_Id
= Aspect_Address
then
2246 Set_Never_Set_In_Source
(E
, False);
2249 -- Correctness of the profile of a stream operation is
2250 -- verified at the freeze point, but we must detect the
2251 -- illegal specification of this aspect for a subtype now,
2252 -- to prevent malformed rep_item chains.
2254 if A_Id
= Aspect_Input
or else
2255 A_Id
= Aspect_Output
or else
2256 A_Id
= Aspect_Read
or else
2259 if not Is_First_Subtype
(E
) then
2261 ("local name must be a first subtype", Aspect
);
2264 -- If stream aspect applies to the class-wide type,
2265 -- the generated attribute definition applies to the
2266 -- class-wide type as well.
2268 elsif Class_Present
(Aspect
) then
2270 Make_Attribute_Reference
(Loc
,
2272 Attribute_Name
=> Name_Class
);
2276 -- Construct the attribute_definition_clause. The expression
2277 -- in the aspect specification is simply shared with the
2278 -- constructed attribute, because it will be fully analyzed
2279 -- when the attribute is processed. However, in ASIS mode
2280 -- the aspect expression itself is preanalyzed and resolved
2281 -- to catch visibility errors that are otherwise caught
2282 -- later, and we create a separate copy of the expression
2283 -- to prevent analysis of a malformed tree (e.g. a function
2284 -- call with parameter associations).
2288 Make_Attribute_Definition_Clause
(Loc
,
2290 Chars
=> Chars
(Id
),
2291 Expression
=> New_Copy_Tree
(Expr
));
2294 Make_Attribute_Definition_Clause
(Loc
,
2296 Chars
=> Chars
(Id
),
2297 Expression
=> Relocate_Node
(Expr
));
2300 -- If the address is specified, then we treat the entity as
2301 -- referenced, to avoid spurious warnings. This is analogous
2302 -- to what is done with an attribute definition clause, but
2303 -- here we don't want to generate a reference because this
2304 -- is the point of definition of the entity.
2306 if A_Id
= Aspect_Address
then
2310 -- Case 2: Aspects corresponding to pragmas
2312 -- Case 2a: Aspects corresponding to pragmas with two
2313 -- arguments, where the first argument is a local name
2314 -- referring to the entity, and the second argument is the
2315 -- aspect definition expression.
2317 -- Linker_Section/Suppress/Unsuppress
2319 when Aspect_Linker_Section
2324 (Pragma_Argument_Associations
=> New_List
(
2325 Make_Pragma_Argument_Association
(Loc
,
2326 Expression
=> New_Occurrence_Of
(E
, Loc
)),
2327 Make_Pragma_Argument_Association
(Sloc
(Expr
),
2328 Expression
=> Relocate_Node
(Expr
))),
2329 Pragma_Name
=> Chars
(Id
));
2331 -- Linker_Section does not need delaying, as its argument
2332 -- must be a static string. Furthermore, if applied to
2333 -- an object with an explicit initialization, the object
2334 -- must be frozen in order to elaborate the initialization
2335 -- code. (This is already done for types with implicit
2336 -- initialization, such as protected types.)
2338 if A_Id
= Aspect_Linker_Section
2339 and then Nkind
(N
) = N_Object_Declaration
2340 and then Has_Init_Expression
(N
)
2342 Delay_Required
:= False;
2347 -- Corresponds to pragma Implemented, construct the pragma
2349 when Aspect_Synchronization
=>
2351 (Pragma_Argument_Associations
=> New_List
(
2352 Make_Pragma_Argument_Association
(Loc
,
2353 Expression
=> New_Occurrence_Of
(E
, Loc
)),
2354 Make_Pragma_Argument_Association
(Sloc
(Expr
),
2355 Expression
=> Relocate_Node
(Expr
))),
2356 Pragma_Name
=> Name_Implemented
);
2360 when Aspect_Attach_Handler
=>
2362 (Pragma_Argument_Associations
=> New_List
(
2363 Make_Pragma_Argument_Association
(Sloc
(Ent
),
2365 Make_Pragma_Argument_Association
(Sloc
(Expr
),
2366 Expression
=> Relocate_Node
(Expr
))),
2367 Pragma_Name
=> Name_Attach_Handler
);
2369 -- We need to insert this pragma into the tree to get proper
2370 -- processing and to look valid from a placement viewpoint.
2372 Insert_Pragma
(Aitem
);
2375 -- Dynamic_Predicate, Predicate, Static_Predicate
2377 when Aspect_Dynamic_Predicate
2379 | Aspect_Static_Predicate
2381 -- These aspects apply only to subtypes
2383 if not Is_Type
(E
) then
2385 ("predicate can only be specified for a subtype",
2389 elsif Is_Incomplete_Type
(E
) then
2391 ("predicate cannot apply to incomplete view", Aspect
);
2393 elsif Is_Generic_Type
(E
) then
2395 ("predicate cannot apply to formal type", Aspect
);
2399 -- Construct the pragma (always a pragma Predicate, with
2400 -- flags recording whether it is static/dynamic). We also
2401 -- set flags recording this in the type itself.
2404 (Pragma_Argument_Associations
=> New_List
(
2405 Make_Pragma_Argument_Association
(Sloc
(Ent
),
2407 Make_Pragma_Argument_Association
(Sloc
(Expr
),
2408 Expression
=> Relocate_Node
(Expr
))),
2409 Pragma_Name
=> Name_Predicate
);
2411 -- Mark type has predicates, and remember what kind of
2412 -- aspect lead to this predicate (we need this to access
2413 -- the right set of check policies later on).
2415 Set_Has_Predicates
(E
);
2417 if A_Id
= Aspect_Dynamic_Predicate
then
2418 Set_Has_Dynamic_Predicate_Aspect
(E
);
2420 -- If the entity has a dynamic predicate, any inherited
2421 -- static predicate becomes dynamic as well, and the
2422 -- predicate function includes the conjunction of both.
2424 Set_Has_Static_Predicate_Aspect
(E
, False);
2426 elsif A_Id
= Aspect_Static_Predicate
then
2427 Set_Has_Static_Predicate_Aspect
(E
);
2430 -- If the type is private, indicate that its completion
2431 -- has a freeze node, because that is the one that will
2432 -- be visible at freeze time.
2434 if Is_Private_Type
(E
) and then Present
(Full_View
(E
)) then
2435 Set_Has_Predicates
(Full_View
(E
));
2437 if A_Id
= Aspect_Dynamic_Predicate
then
2438 Set_Has_Dynamic_Predicate_Aspect
(Full_View
(E
));
2439 elsif A_Id
= Aspect_Static_Predicate
then
2440 Set_Has_Static_Predicate_Aspect
(Full_View
(E
));
2443 Set_Has_Delayed_Aspects
(Full_View
(E
));
2444 Ensure_Freeze_Node
(Full_View
(E
));
2447 -- Predicate_Failure
2449 when Aspect_Predicate_Failure
=>
2451 -- This aspect applies only to subtypes
2453 if not Is_Type
(E
) then
2455 ("predicate can only be specified for a subtype",
2459 elsif Is_Incomplete_Type
(E
) then
2461 ("predicate cannot apply to incomplete view", Aspect
);
2465 -- Construct the pragma
2468 (Pragma_Argument_Associations
=> New_List
(
2469 Make_Pragma_Argument_Association
(Sloc
(Ent
),
2471 Make_Pragma_Argument_Association
(Sloc
(Expr
),
2472 Expression
=> Relocate_Node
(Expr
))),
2473 Pragma_Name
=> Name_Predicate_Failure
);
2475 Set_Has_Predicates
(E
);
2477 -- If the type is private, indicate that its completion
2478 -- has a freeze node, because that is the one that will
2479 -- be visible at freeze time.
2481 if Is_Private_Type
(E
) and then Present
(Full_View
(E
)) then
2482 Set_Has_Predicates
(Full_View
(E
));
2483 Set_Has_Delayed_Aspects
(Full_View
(E
));
2484 Ensure_Freeze_Node
(Full_View
(E
));
2487 -- Case 2b: Aspects corresponding to pragmas with two
2488 -- arguments, where the second argument is a local name
2489 -- referring to the entity, and the first argument is the
2490 -- aspect definition expression.
2494 when Aspect_Convention
=>
2495 Analyze_Aspect_Convention
;
2498 -- External_Name, Link_Name
2500 when Aspect_External_Name
2503 Analyze_Aspect_External_Link_Name
;
2506 -- CPU, Interrupt_Priority, Priority
2508 -- These three aspects can be specified for a subprogram spec
2509 -- or body, in which case we analyze the expression and export
2510 -- the value of the aspect.
2512 -- Previously, we generated an equivalent pragma for bodies
2513 -- (note that the specs cannot contain these pragmas). The
2514 -- pragma was inserted ahead of local declarations, rather than
2515 -- after the body. This leads to a certain duplication between
2516 -- the processing performed for the aspect and the pragma, but
2517 -- given the straightforward handling required it is simpler
2518 -- to duplicate than to translate the aspect in the spec into
2519 -- a pragma in the declarative part of the body.
2522 | Aspect_Interrupt_Priority
2525 if Nkind_In
(N
, N_Subprogram_Body
,
2526 N_Subprogram_Declaration
)
2528 -- Analyze the aspect expression
2530 Analyze_And_Resolve
(Expr
, Standard_Integer
);
2532 -- Interrupt_Priority aspect not allowed for main
2533 -- subprograms. RM D.1 does not forbid this explicitly,
2534 -- but RM J.15.11(6/3) does not permit pragma
2535 -- Interrupt_Priority for subprograms.
2537 if A_Id
= Aspect_Interrupt_Priority
then
2539 ("Interrupt_Priority aspect cannot apply to "
2540 & "subprogram", Expr
);
2542 -- The expression must be static
2544 elsif not Is_OK_Static_Expression
(Expr
) then
2545 Flag_Non_Static_Expr
2546 ("aspect requires static expression!", Expr
);
2548 -- Check whether this is the main subprogram. Issue a
2549 -- warning only if it is obviously not a main program
2550 -- (when it has parameters or when the subprogram is
2551 -- within a package).
2553 elsif Present
(Parameter_Specifications
2554 (Specification
(N
)))
2555 or else not Is_Compilation_Unit
(Defining_Entity
(N
))
2557 -- See RM D.1(14/3) and D.16(12/3)
2560 ("aspect applied to subprogram other than the "
2561 & "main subprogram has no effect??", Expr
);
2563 -- Otherwise check in range and export the value
2565 -- For the CPU aspect
2567 elsif A_Id
= Aspect_CPU
then
2568 if Is_In_Range
(Expr
, RTE
(RE_CPU_Range
)) then
2570 -- Value is correct so we export the value to make
2571 -- it available at execution time.
2574 (Main_Unit
, UI_To_Int
(Expr_Value
(Expr
)));
2578 ("main subprogram CPU is out of range", Expr
);
2581 -- For the Priority aspect
2583 elsif A_Id
= Aspect_Priority
then
2584 if Is_In_Range
(Expr
, RTE
(RE_Priority
)) then
2586 -- Value is correct so we export the value to make
2587 -- it available at execution time.
2590 (Main_Unit
, UI_To_Int
(Expr_Value
(Expr
)));
2592 -- Ignore pragma if Relaxed_RM_Semantics to support
2593 -- other targets/non GNAT compilers.
2595 elsif not Relaxed_RM_Semantics
then
2597 ("main subprogram priority is out of range",
2602 -- Load an arbitrary entity from System.Tasking.Stages
2603 -- or System.Tasking.Restricted.Stages (depending on
2604 -- the supported profile) to make sure that one of these
2605 -- packages is implicitly with'ed, since we need to have
2606 -- the tasking run time active for the pragma Priority to
2607 -- have any effect. Previously we with'ed the package
2608 -- System.Tasking, but this package does not trigger the
2609 -- required initialization of the run-time library.
2612 Discard
: Entity_Id
;
2614 if Restricted_Profile
then
2615 Discard
:= RTE
(RE_Activate_Restricted_Tasks
);
2617 Discard
:= RTE
(RE_Activate_Tasks
);
2621 -- Handling for these aspects in subprograms is complete
2625 -- For task and protected types pass the aspect as an
2630 Make_Attribute_Definition_Clause
(Loc
,
2632 Chars
=> Chars
(Id
),
2633 Expression
=> Relocate_Node
(Expr
));
2638 when Aspect_Warnings
=>
2640 (Pragma_Argument_Associations
=> New_List
(
2641 Make_Pragma_Argument_Association
(Sloc
(Expr
),
2642 Expression
=> Relocate_Node
(Expr
)),
2643 Make_Pragma_Argument_Association
(Loc
,
2644 Expression
=> New_Occurrence_Of
(E
, Loc
))),
2645 Pragma_Name
=> Chars
(Id
));
2647 Decorate
(Aspect
, Aitem
);
2648 Insert_Pragma
(Aitem
);
2651 -- Case 2c: Aspects corresponding to pragmas with three
2654 -- Invariant aspects have a first argument that references the
2655 -- entity, a second argument that is the expression and a third
2656 -- argument that is an appropriate message.
2658 -- Invariant, Type_Invariant
2660 when Aspect_Invariant
2661 | Aspect_Type_Invariant
2663 -- Analysis of the pragma will verify placement legality:
2664 -- an invariant must apply to a private type, or appear in
2665 -- the private part of a spec and apply to a completion.
2668 (Pragma_Argument_Associations
=> New_List
(
2669 Make_Pragma_Argument_Association
(Sloc
(Ent
),
2671 Make_Pragma_Argument_Association
(Sloc
(Expr
),
2672 Expression
=> Relocate_Node
(Expr
))),
2673 Pragma_Name
=> Name_Invariant
);
2675 -- Add message unless exception messages are suppressed
2677 if not Opt
.Exception_Locations_Suppressed
then
2678 Append_To
(Pragma_Argument_Associations
(Aitem
),
2679 Make_Pragma_Argument_Association
(Eloc
,
2680 Chars
=> Name_Message
,
2682 Make_String_Literal
(Eloc
,
2683 Strval
=> "failed invariant from "
2684 & Build_Location_String
(Eloc
))));
2687 -- For Invariant case, insert immediately after the entity
2688 -- declaration. We do not have to worry about delay issues
2689 -- since the pragma processing takes care of this.
2691 Delay_Required
:= False;
2693 -- Case 2d : Aspects that correspond to a pragma with one
2698 -- Aspect Abstract_State introduces implicit declarations for
2699 -- all state abstraction entities it defines. To emulate this
2700 -- behavior, insert the pragma at the beginning of the visible
2701 -- declarations of the related package so that it is analyzed
2704 when Aspect_Abstract_State
=> Abstract_State
: declare
2705 Context
: Node_Id
:= N
;
2708 -- When aspect Abstract_State appears on a generic package,
2709 -- it is propageted to the package instance. The context in
2710 -- this case is the instance spec.
2712 if Nkind
(Context
) = N_Package_Instantiation
then
2713 Context
:= Instance_Spec
(Context
);
2716 if Nkind_In
(Context
, N_Generic_Package_Declaration
,
2717 N_Package_Declaration
)
2720 (Pragma_Argument_Associations
=> New_List
(
2721 Make_Pragma_Argument_Association
(Loc
,
2722 Expression
=> Relocate_Node
(Expr
))),
2723 Pragma_Name
=> Name_Abstract_State
);
2725 Decorate
(Aspect
, Aitem
);
2729 Is_Generic_Instance
(Defining_Entity
(Context
)));
2733 ("aspect & must apply to a package declaration",
2740 -- Aspect Async_Readers is never delayed because it is
2741 -- equivalent to a source pragma which appears after the
2742 -- related object declaration.
2744 when Aspect_Async_Readers
=>
2746 (Pragma_Argument_Associations
=> New_List
(
2747 Make_Pragma_Argument_Association
(Loc
,
2748 Expression
=> Relocate_Node
(Expr
))),
2749 Pragma_Name
=> Name_Async_Readers
);
2751 Decorate
(Aspect
, Aitem
);
2752 Insert_Pragma
(Aitem
);
2755 -- Aspect Async_Writers is never delayed because it is
2756 -- equivalent to a source pragma which appears after the
2757 -- related object declaration.
2759 when Aspect_Async_Writers
=>
2761 (Pragma_Argument_Associations
=> New_List
(
2762 Make_Pragma_Argument_Association
(Loc
,
2763 Expression
=> Relocate_Node
(Expr
))),
2764 Pragma_Name
=> Name_Async_Writers
);
2766 Decorate
(Aspect
, Aitem
);
2767 Insert_Pragma
(Aitem
);
2770 -- Aspect Constant_After_Elaboration is never delayed because
2771 -- it is equivalent to a source pragma which appears after the
2772 -- related object declaration.
2774 when Aspect_Constant_After_Elaboration
=>
2776 (Pragma_Argument_Associations
=> New_List
(
2777 Make_Pragma_Argument_Association
(Loc
,
2778 Expression
=> Relocate_Node
(Expr
))),
2780 Name_Constant_After_Elaboration
);
2782 Decorate
(Aspect
, Aitem
);
2783 Insert_Pragma
(Aitem
);
2786 -- Aspect Default_Internal_Condition is never delayed because
2787 -- it is equivalent to a source pragma which appears after the
2788 -- related private type. To deal with forward references, the
2789 -- generated pragma is stored in the rep chain of the related
2790 -- private type as types do not carry contracts. The pragma is
2791 -- wrapped inside of a procedure at the freeze point of the
2792 -- private type's full view.
2794 when Aspect_Default_Initial_Condition
=>
2796 (Pragma_Argument_Associations
=> New_List
(
2797 Make_Pragma_Argument_Association
(Loc
,
2798 Expression
=> Relocate_Node
(Expr
))),
2800 Name_Default_Initial_Condition
);
2802 Decorate
(Aspect
, Aitem
);
2803 Insert_Pragma
(Aitem
);
2806 -- Default_Storage_Pool
2808 when Aspect_Default_Storage_Pool
=>
2810 (Pragma_Argument_Associations
=> New_List
(
2811 Make_Pragma_Argument_Association
(Loc
,
2812 Expression
=> Relocate_Node
(Expr
))),
2814 Name_Default_Storage_Pool
);
2816 Decorate
(Aspect
, Aitem
);
2817 Insert_Pragma
(Aitem
);
2822 -- Aspect Depends is never delayed because it is equivalent to
2823 -- a source pragma which appears after the related subprogram.
2824 -- To deal with forward references, the generated pragma is
2825 -- stored in the contract of the related subprogram and later
2826 -- analyzed at the end of the declarative region. See routine
2827 -- Analyze_Depends_In_Decl_Part for details.
2829 when Aspect_Depends
=>
2831 (Pragma_Argument_Associations
=> New_List
(
2832 Make_Pragma_Argument_Association
(Loc
,
2833 Expression
=> Relocate_Node
(Expr
))),
2834 Pragma_Name
=> Name_Depends
);
2836 Decorate
(Aspect
, Aitem
);
2837 Insert_Pragma
(Aitem
);
2840 -- Aspect Effecitve_Reads is never delayed because it is
2841 -- equivalent to a source pragma which appears after the
2842 -- related object declaration.
2844 when Aspect_Effective_Reads
=>
2846 (Pragma_Argument_Associations
=> New_List
(
2847 Make_Pragma_Argument_Association
(Loc
,
2848 Expression
=> Relocate_Node
(Expr
))),
2849 Pragma_Name
=> Name_Effective_Reads
);
2851 Decorate
(Aspect
, Aitem
);
2852 Insert_Pragma
(Aitem
);
2855 -- Aspect Effective_Writes is never delayed because it is
2856 -- equivalent to a source pragma which appears after the
2857 -- related object declaration.
2859 when Aspect_Effective_Writes
=>
2861 (Pragma_Argument_Associations
=> New_List
(
2862 Make_Pragma_Argument_Association
(Loc
,
2863 Expression
=> Relocate_Node
(Expr
))),
2864 Pragma_Name
=> Name_Effective_Writes
);
2866 Decorate
(Aspect
, Aitem
);
2867 Insert_Pragma
(Aitem
);
2870 -- Aspect Extensions_Visible is never delayed because it is
2871 -- equivalent to a source pragma which appears after the
2872 -- related subprogram.
2874 when Aspect_Extensions_Visible
=>
2876 (Pragma_Argument_Associations
=> New_List
(
2877 Make_Pragma_Argument_Association
(Loc
,
2878 Expression
=> Relocate_Node
(Expr
))),
2879 Pragma_Name
=> Name_Extensions_Visible
);
2881 Decorate
(Aspect
, Aitem
);
2882 Insert_Pragma
(Aitem
);
2885 -- Aspect Ghost is never delayed because it is equivalent to a
2886 -- source pragma which appears at the top of [generic] package
2887 -- declarations or after an object, a [generic] subprogram, or
2888 -- a type declaration.
2890 when Aspect_Ghost
=>
2892 (Pragma_Argument_Associations
=> New_List
(
2893 Make_Pragma_Argument_Association
(Loc
,
2894 Expression
=> Relocate_Node
(Expr
))),
2895 Pragma_Name
=> Name_Ghost
);
2897 Decorate
(Aspect
, Aitem
);
2898 Insert_Pragma
(Aitem
);
2903 -- Aspect Global is never delayed because it is equivalent to
2904 -- a source pragma which appears after the related subprogram.
2905 -- To deal with forward references, the generated pragma is
2906 -- stored in the contract of the related subprogram and later
2907 -- analyzed at the end of the declarative region. See routine
2908 -- Analyze_Global_In_Decl_Part for details.
2910 when Aspect_Global
=>
2912 (Pragma_Argument_Associations
=> New_List
(
2913 Make_Pragma_Argument_Association
(Loc
,
2914 Expression
=> Relocate_Node
(Expr
))),
2915 Pragma_Name
=> Name_Global
);
2917 Decorate
(Aspect
, Aitem
);
2918 Insert_Pragma
(Aitem
);
2921 -- Initial_Condition
2923 -- Aspect Initial_Condition is never delayed because it is
2924 -- equivalent to a source pragma which appears after the
2925 -- related package. To deal with forward references, the
2926 -- generated pragma is stored in the contract of the related
2927 -- package and later analyzed at the end of the declarative
2928 -- region. See routine Analyze_Initial_Condition_In_Decl_Part
2931 when Aspect_Initial_Condition
=> Initial_Condition
: declare
2932 Context
: Node_Id
:= N
;
2935 -- When aspect Initial_Condition appears on a generic
2936 -- package, it is propageted to the package instance. The
2937 -- context in this case is the instance spec.
2939 if Nkind
(Context
) = N_Package_Instantiation
then
2940 Context
:= Instance_Spec
(Context
);
2943 if Nkind_In
(Context
, N_Generic_Package_Declaration
,
2944 N_Package_Declaration
)
2947 (Pragma_Argument_Associations
=> New_List
(
2948 Make_Pragma_Argument_Association
(Loc
,
2949 Expression
=> Relocate_Node
(Expr
))),
2951 Name_Initial_Condition
);
2953 Decorate
(Aspect
, Aitem
);
2957 Is_Generic_Instance
(Defining_Entity
(Context
)));
2959 -- Otherwise the context is illegal
2963 ("aspect & must apply to a package declaration",
2968 end Initial_Condition
;
2972 -- Aspect Initializes is never delayed because it is equivalent
2973 -- to a source pragma appearing after the related package. To
2974 -- deal with forward references, the generated pragma is stored
2975 -- in the contract of the related package and later analyzed at
2976 -- the end of the declarative region. For details, see routine
2977 -- Analyze_Initializes_In_Decl_Part.
2979 when Aspect_Initializes
=> Initializes
: declare
2980 Context
: Node_Id
:= N
;
2983 -- When aspect Initializes appears on a generic package,
2984 -- it is propageted to the package instance. The context
2985 -- in this case is the instance spec.
2987 if Nkind
(Context
) = N_Package_Instantiation
then
2988 Context
:= Instance_Spec
(Context
);
2991 if Nkind_In
(Context
, N_Generic_Package_Declaration
,
2992 N_Package_Declaration
)
2995 (Pragma_Argument_Associations
=> New_List
(
2996 Make_Pragma_Argument_Association
(Loc
,
2997 Expression
=> Relocate_Node
(Expr
))),
2998 Pragma_Name
=> Name_Initializes
);
3000 Decorate
(Aspect
, Aitem
);
3004 Is_Generic_Instance
(Defining_Entity
(Context
)));
3006 -- Otherwise the context is illegal
3010 ("aspect & must apply to a package declaration",
3019 when Aspect_Max_Queue_Length
=>
3021 (Pragma_Argument_Associations
=> New_List
(
3022 Make_Pragma_Argument_Association
(Loc
,
3023 Expression
=> Relocate_Node
(Expr
))),
3024 Pragma_Name
=> Name_Max_Queue_Length
);
3026 Decorate
(Aspect
, Aitem
);
3027 Insert_Pragma
(Aitem
);
3032 when Aspect_Obsolescent
=> declare
3040 Make_Pragma_Argument_Association
(Sloc
(Expr
),
3041 Expression
=> Relocate_Node
(Expr
)));
3045 (Pragma_Argument_Associations
=> Args
,
3046 Pragma_Name
=> Chars
(Id
));
3051 when Aspect_Part_Of
=>
3052 if Nkind_In
(N
, N_Object_Declaration
,
3053 N_Package_Instantiation
)
3054 or else Is_Single_Concurrent_Type_Declaration
(N
)
3057 (Pragma_Argument_Associations
=> New_List
(
3058 Make_Pragma_Argument_Association
(Loc
,
3059 Expression
=> Relocate_Node
(Expr
))),
3060 Pragma_Name
=> Name_Part_Of
);
3062 Decorate
(Aspect
, Aitem
);
3063 Insert_Pragma
(Aitem
);
3067 ("aspect & must apply to package instantiation, "
3068 & "object, single protected type or single task type",
3076 when Aspect_SPARK_Mode
=>
3078 (Pragma_Argument_Associations
=> New_List
(
3079 Make_Pragma_Argument_Association
(Loc
,
3080 Expression
=> Relocate_Node
(Expr
))),
3081 Pragma_Name
=> Name_SPARK_Mode
);
3083 Decorate
(Aspect
, Aitem
);
3084 Insert_Pragma
(Aitem
);
3089 -- Aspect Refined_Depends is never delayed because it is
3090 -- equivalent to a source pragma which appears in the
3091 -- declarations of the related subprogram body. To deal with
3092 -- forward references, the generated pragma is stored in the
3093 -- contract of the related subprogram body and later analyzed
3094 -- at the end of the declarative region. For details, see
3095 -- routine Analyze_Refined_Depends_In_Decl_Part.
3097 when Aspect_Refined_Depends
=>
3099 (Pragma_Argument_Associations
=> New_List
(
3100 Make_Pragma_Argument_Association
(Loc
,
3101 Expression
=> Relocate_Node
(Expr
))),
3102 Pragma_Name
=> Name_Refined_Depends
);
3104 Decorate
(Aspect
, Aitem
);
3105 Insert_Pragma
(Aitem
);
3110 -- Aspect Refined_Global is never delayed because it is
3111 -- equivalent to a source pragma which appears in the
3112 -- declarations of the related subprogram body. To deal with
3113 -- forward references, the generated pragma is stored in the
3114 -- contract of the related subprogram body and later analyzed
3115 -- at the end of the declarative region. For details, see
3116 -- routine Analyze_Refined_Global_In_Decl_Part.
3118 when Aspect_Refined_Global
=>
3120 (Pragma_Argument_Associations
=> New_List
(
3121 Make_Pragma_Argument_Association
(Loc
,
3122 Expression
=> Relocate_Node
(Expr
))),
3123 Pragma_Name
=> Name_Refined_Global
);
3125 Decorate
(Aspect
, Aitem
);
3126 Insert_Pragma
(Aitem
);
3131 when Aspect_Refined_Post
=>
3133 (Pragma_Argument_Associations
=> New_List
(
3134 Make_Pragma_Argument_Association
(Loc
,
3135 Expression
=> Relocate_Node
(Expr
))),
3136 Pragma_Name
=> Name_Refined_Post
);
3138 Decorate
(Aspect
, Aitem
);
3139 Insert_Pragma
(Aitem
);
3144 when Aspect_Refined_State
=>
3146 -- The corresponding pragma for Refined_State is inserted in
3147 -- the declarations of the related package body. This action
3148 -- synchronizes both the source and from-aspect versions of
3151 if Nkind
(N
) = N_Package_Body
then
3153 (Pragma_Argument_Associations
=> New_List
(
3154 Make_Pragma_Argument_Association
(Loc
,
3155 Expression
=> Relocate_Node
(Expr
))),
3156 Pragma_Name
=> Name_Refined_State
);
3158 Decorate
(Aspect
, Aitem
);
3159 Insert_Pragma
(Aitem
);
3161 -- Otherwise the context is illegal
3165 ("aspect & must apply to a package body", Aspect
, Id
);
3170 -- Relative_Deadline
3172 when Aspect_Relative_Deadline
=>
3174 (Pragma_Argument_Associations
=> New_List
(
3175 Make_Pragma_Argument_Association
(Loc
,
3176 Expression
=> Relocate_Node
(Expr
))),
3177 Pragma_Name
=> Name_Relative_Deadline
);
3179 -- If the aspect applies to a task, the corresponding pragma
3180 -- must appear within its declarations, not after.
3182 if Nkind
(N
) = N_Task_Type_Declaration
then
3188 if No
(Task_Definition
(N
)) then
3189 Set_Task_Definition
(N
,
3190 Make_Task_Definition
(Loc
,
3191 Visible_Declarations
=> New_List
,
3192 End_Label
=> Empty
));
3195 Def
:= Task_Definition
(N
);
3196 V
:= Visible_Declarations
(Def
);
3197 if not Is_Empty_List
(V
) then
3198 Insert_Before
(First
(V
), Aitem
);
3201 Set_Visible_Declarations
(Def
, New_List
(Aitem
));
3208 -- Aspect Volatile_Function is never delayed because it is
3209 -- equivalent to a source pragma which appears after the
3210 -- related subprogram.
3212 when Aspect_Volatile_Function
=>
3214 (Pragma_Argument_Associations
=> New_List
(
3215 Make_Pragma_Argument_Association
(Loc
,
3216 Expression
=> Relocate_Node
(Expr
))),
3217 Pragma_Name
=> Name_Volatile_Function
);
3219 Decorate
(Aspect
, Aitem
);
3220 Insert_Pragma
(Aitem
);
3223 -- Case 2e: Annotate aspect
3225 when Aspect_Annotate
=>
3232 -- The argument can be a single identifier
3234 if Nkind
(Expr
) = N_Identifier
then
3236 -- One level of parens is allowed
3238 if Paren_Count
(Expr
) > 1 then
3239 Error_Msg_F
("extra parentheses ignored", Expr
);
3242 Set_Paren_Count
(Expr
, 0);
3244 -- Add the single item to the list
3246 Args
:= New_List
(Expr
);
3248 -- Otherwise we must have an aggregate
3250 elsif Nkind
(Expr
) = N_Aggregate
then
3252 -- Must be positional
3254 if Present
(Component_Associations
(Expr
)) then
3256 ("purely positional aggregate required", Expr
);
3260 -- Must not be parenthesized
3262 if Paren_Count
(Expr
) /= 0 then
3263 Error_Msg_F
("extra parentheses ignored", Expr
);
3266 -- List of arguments is list of aggregate expressions
3268 Args
:= Expressions
(Expr
);
3270 -- Anything else is illegal
3273 Error_Msg_F
("wrong form for Annotate aspect", Expr
);
3277 -- Prepare pragma arguments
3280 Arg
:= First
(Args
);
3281 while Present
(Arg
) loop
3283 Make_Pragma_Argument_Association
(Sloc
(Arg
),
3284 Expression
=> Relocate_Node
(Arg
)));
3289 Make_Pragma_Argument_Association
(Sloc
(Ent
),
3290 Chars
=> Name_Entity
,
3291 Expression
=> Ent
));
3294 (Pragma_Argument_Associations
=> Pargs
,
3295 Pragma_Name
=> Name_Annotate
);
3298 -- Case 3 : Aspects that don't correspond to pragma/attribute
3299 -- definition clause.
3301 -- Case 3a: The aspects listed below don't correspond to
3302 -- pragmas/attributes but do require delayed analysis.
3304 -- Default_Value can only apply to a scalar type
3306 when Aspect_Default_Value
=>
3307 if not Is_Scalar_Type
(E
) then
3309 ("aspect Default_Value must apply to a scalar type", N
);
3314 -- Default_Component_Value can only apply to an array type
3315 -- with scalar components.
3317 when Aspect_Default_Component_Value
=>
3318 if not (Is_Array_Type
(E
)
3319 and then Is_Scalar_Type
(Component_Type
(E
)))
3322 ("aspect Default_Component_Value can only apply to an "
3323 & "array of scalar components", N
);
3328 -- Case 3b: The aspects listed below don't correspond to
3329 -- pragmas/attributes and don't need delayed analysis.
3331 -- Implicit_Dereference
3333 -- For Implicit_Dereference, External_Name and Link_Name, only
3334 -- the legality checks are done during the analysis, thus no
3335 -- delay is required.
3337 when Aspect_Implicit_Dereference
=>
3338 Analyze_Aspect_Implicit_Dereference
;
3343 when Aspect_Dimension
=>
3344 Analyze_Aspect_Dimension
(N
, Id
, Expr
);
3349 when Aspect_Dimension_System
=>
3350 Analyze_Aspect_Dimension_System
(N
, Id
, Expr
);
3353 -- Case 4: Aspects requiring special handling
3355 -- Pre/Post/Test_Case/Contract_Cases whose corresponding
3356 -- pragmas take care of the delay.
3360 -- Aspects Pre/Post generate Precondition/Postcondition pragmas
3361 -- with a first argument that is the expression, and a second
3362 -- argument that is an informative message if the test fails.
3363 -- This is inserted right after the declaration, to get the
3364 -- required pragma placement. The processing for the pragmas
3365 -- takes care of the required delay.
3367 when Pre_Post_Aspects
=> Pre_Post
: declare
3371 if A_Id
= Aspect_Pre
or else A_Id
= Aspect_Precondition
then
3372 Pname
:= Name_Precondition
;
3374 Pname
:= Name_Postcondition
;
3377 -- Check that the class-wide predicate cannot be applied to
3378 -- an operation of a synchronized type. AI12-0182 forbids
3379 -- these altogether, while earlier language semantics made
3380 -- them legal on tagged synchronized types.
3382 -- Other legality checks are performed when analyzing the
3383 -- contract of the operation.
3385 if Class_Present
(Aspect
)
3386 and then Is_Concurrent_Type
(Current_Scope
)
3387 and then Ekind_In
(E
, E_Entry
, E_Function
, E_Procedure
)
3389 Error_Msg_Name_1
:= Original_Aspect_Pragma_Name
(Aspect
);
3391 ("aspect % can only be specified for a primitive "
3392 & "operation of a tagged type", Aspect
);
3397 -- If the expressions is of the form A and then B, then
3398 -- we generate separate Pre/Post aspects for the separate
3399 -- clauses. Since we allow multiple pragmas, there is no
3400 -- problem in allowing multiple Pre/Post aspects internally.
3401 -- These should be treated in reverse order (B first and
3402 -- A second) since they are later inserted just after N in
3403 -- the order they are treated. This way, the pragma for A
3404 -- ends up preceding the pragma for B, which may have an
3405 -- importance for the error raised (either constraint error
3406 -- or precondition error).
3408 -- We do not do this for Pre'Class, since we have to put
3409 -- these conditions together in a complex OR expression.
3411 -- We do not do this in ASIS mode, as ASIS relies on the
3412 -- original node representing the complete expression, when
3413 -- retrieving it through the source aspect table.
3416 and then (Pname
= Name_Postcondition
3417 or else not Class_Present
(Aspect
))
3419 while Nkind
(Expr
) = N_And_Then
loop
3420 Insert_After
(Aspect
,
3421 Make_Aspect_Specification
(Sloc
(Left_Opnd
(Expr
)),
3422 Identifier
=> Identifier
(Aspect
),
3423 Expression
=> Relocate_Node
(Left_Opnd
(Expr
)),
3424 Class_Present
=> Class_Present
(Aspect
),
3425 Split_PPC
=> True));
3426 Rewrite
(Expr
, Relocate_Node
(Right_Opnd
(Expr
)));
3427 Eloc
:= Sloc
(Expr
);
3431 -- Build the precondition/postcondition pragma
3433 -- Add note about why we do NOT need Copy_Tree here???
3436 (Pragma_Argument_Associations
=> New_List
(
3437 Make_Pragma_Argument_Association
(Eloc
,
3438 Chars
=> Name_Check
,
3439 Expression
=> Relocate_Node
(Expr
))),
3440 Pragma_Name
=> Pname
);
3442 -- Add message unless exception messages are suppressed
3444 if not Opt
.Exception_Locations_Suppressed
then
3445 Append_To
(Pragma_Argument_Associations
(Aitem
),
3446 Make_Pragma_Argument_Association
(Eloc
,
3447 Chars
=> Name_Message
,
3449 Make_String_Literal
(Eloc
,
3451 & Get_Name_String
(Pname
)
3453 & Build_Location_String
(Eloc
))));
3456 Set_Is_Delayed_Aspect
(Aspect
);
3458 -- For Pre/Post cases, insert immediately after the entity
3459 -- declaration, since that is the required pragma placement.
3460 -- Note that for these aspects, we do not have to worry
3461 -- about delay issues, since the pragmas themselves deal
3462 -- with delay of visibility for the expression analysis.
3464 Insert_Pragma
(Aitem
);
3471 when Aspect_Test_Case
=> Test_Case
: declare
3473 Comp_Expr
: Node_Id
;
3474 Comp_Assn
: Node_Id
;
3480 if Nkind
(Parent
(N
)) = N_Compilation_Unit
then
3481 Error_Msg_Name_1
:= Nam
;
3482 Error_Msg_N
("incorrect placement of aspect `%`", E
);
3486 if Nkind
(Expr
) /= N_Aggregate
then
3487 Error_Msg_Name_1
:= Nam
;
3489 ("wrong syntax for aspect `%` for &", Id
, E
);
3493 -- Make pragma expressions refer to the original aspect
3494 -- expressions through the Original_Node link. This is used
3495 -- in semantic analysis for ASIS mode, so that the original
3496 -- expression also gets analyzed.
3498 Comp_Expr
:= First
(Expressions
(Expr
));
3499 while Present
(Comp_Expr
) loop
3500 New_Expr
:= Relocate_Node
(Comp_Expr
);
3502 Make_Pragma_Argument_Association
(Sloc
(Comp_Expr
),
3503 Expression
=> New_Expr
));
3507 Comp_Assn
:= First
(Component_Associations
(Expr
));
3508 while Present
(Comp_Assn
) loop
3509 if List_Length
(Choices
(Comp_Assn
)) /= 1
3511 Nkind
(First
(Choices
(Comp_Assn
))) /= N_Identifier
3513 Error_Msg_Name_1
:= Nam
;
3515 ("wrong syntax for aspect `%` for &", Id
, E
);
3520 Make_Pragma_Argument_Association
(Sloc
(Comp_Assn
),
3521 Chars
=> Chars
(First
(Choices
(Comp_Assn
))),
3523 Relocate_Node
(Expression
(Comp_Assn
))));
3527 -- Build the test-case pragma
3530 (Pragma_Argument_Associations
=> Args
,
3531 Pragma_Name
=> Nam
);
3536 when Aspect_Contract_Cases
=>
3538 (Pragma_Argument_Associations
=> New_List
(
3539 Make_Pragma_Argument_Association
(Loc
,
3540 Expression
=> Relocate_Node
(Expr
))),
3541 Pragma_Name
=> Nam
);
3543 Decorate
(Aspect
, Aitem
);
3544 Insert_Pragma
(Aitem
);
3547 -- Case 5: Special handling for aspects with an optional
3548 -- boolean argument.
3550 -- In the delayed case, the corresponding pragma cannot be
3551 -- generated yet because the evaluation of the boolean needs
3552 -- to be delayed till the freeze point.
3554 when Boolean_Aspects
3555 | Library_Unit_Aspects
3557 Set_Is_Boolean_Aspect
(Aspect
);
3559 -- Lock_Free aspect only apply to protected objects
3561 if A_Id
= Aspect_Lock_Free
then
3562 if Ekind
(E
) /= E_Protected_Type
then
3563 Error_Msg_Name_1
:= Nam
;
3565 ("aspect % only applies to a protected object",
3569 -- Set the Uses_Lock_Free flag to True if there is no
3570 -- expression or if the expression is True. The
3571 -- evaluation of this aspect should be delayed to the
3572 -- freeze point (why???)
3575 or else Is_True
(Static_Boolean
(Expr
))
3577 Set_Uses_Lock_Free
(E
);
3580 Record_Rep_Item
(E
, Aspect
);
3585 elsif A_Id
= Aspect_Export
or else A_Id
= Aspect_Import
then
3586 Analyze_Aspect_Export_Import
;
3588 -- Disable_Controlled
3590 elsif A_Id
= Aspect_Disable_Controlled
then
3591 Analyze_Aspect_Disable_Controlled
;
3595 -- Library unit aspects require special handling in the case
3596 -- of a package declaration, the pragma needs to be inserted
3597 -- in the list of declarations for the associated package.
3598 -- There is no issue of visibility delay for these aspects.
3600 if A_Id
in Library_Unit_Aspects
3602 Nkind_In
(N
, N_Package_Declaration
,
3603 N_Generic_Package_Declaration
)
3604 and then Nkind
(Parent
(N
)) /= N_Compilation_Unit
3606 -- Aspect is legal on a local instantiation of a library-
3607 -- level generic unit.
3609 and then not Is_Generic_Instance
(Defining_Entity
(N
))
3612 ("incorrect context for library unit aspect&", Id
);
3616 -- Cases where we do not delay, includes all cases where the
3617 -- expression is missing other than the above cases.
3619 if not Delay_Required
or else No
(Expr
) then
3621 -- Exclude aspects Export and Import because their pragma
3622 -- syntax does not map directly to a Boolean aspect.
3624 if A_Id
/= Aspect_Export
3625 and then A_Id
/= Aspect_Import
3628 (Pragma_Argument_Associations
=> New_List
(
3629 Make_Pragma_Argument_Association
(Sloc
(Ent
),
3630 Expression
=> Ent
)),
3631 Pragma_Name
=> Chars
(Id
));
3634 Delay_Required
:= False;
3636 -- In general cases, the corresponding pragma/attribute
3637 -- definition clause will be inserted later at the freezing
3638 -- point, and we do not need to build it now.
3646 -- This is special because for access types we need to generate
3647 -- an attribute definition clause. This also works for single
3648 -- task declarations, but it does not work for task type
3649 -- declarations, because we have the case where the expression
3650 -- references a discriminant of the task type. That can't use
3651 -- an attribute definition clause because we would not have
3652 -- visibility on the discriminant. For that case we must
3653 -- generate a pragma in the task definition.
3655 when Aspect_Storage_Size
=>
3659 if Ekind
(E
) = E_Task_Type
then
3661 Decl
: constant Node_Id
:= Declaration_Node
(E
);
3664 pragma Assert
(Nkind
(Decl
) = N_Task_Type_Declaration
);
3666 -- If no task definition, create one
3668 if No
(Task_Definition
(Decl
)) then
3669 Set_Task_Definition
(Decl
,
3670 Make_Task_Definition
(Loc
,
3671 Visible_Declarations
=> Empty_List
,
3672 End_Label
=> Empty
));
3675 -- Create a pragma and put it at the start of the task
3676 -- definition for the task type declaration.
3679 (Pragma_Argument_Associations
=> New_List
(
3680 Make_Pragma_Argument_Association
(Loc
,
3681 Expression
=> Relocate_Node
(Expr
))),
3682 Pragma_Name
=> Name_Storage_Size
);
3686 Visible_Declarations
(Task_Definition
(Decl
)));
3690 -- All other cases, generate attribute definition
3694 Make_Attribute_Definition_Clause
(Loc
,
3696 Chars
=> Chars
(Id
),
3697 Expression
=> Relocate_Node
(Expr
));
3701 -- Attach the corresponding pragma/attribute definition clause to
3702 -- the aspect specification node.
3704 if Present
(Aitem
) then
3705 Set_From_Aspect_Specification
(Aitem
);
3708 -- In the context of a compilation unit, we directly put the
3709 -- pragma in the Pragmas_After list of the N_Compilation_Unit_Aux
3710 -- node (no delay is required here) except for aspects on a
3711 -- subprogram body (see below) and a generic package, for which we
3712 -- need to introduce the pragma before building the generic copy
3713 -- (see sem_ch12), and for package instantiations, where the
3714 -- library unit pragmas are better handled early.
3716 if Nkind
(Parent
(N
)) = N_Compilation_Unit
3717 and then (Present
(Aitem
) or else Is_Boolean_Aspect
(Aspect
))
3720 Aux
: constant Node_Id
:= Aux_Decls_Node
(Parent
(N
));
3723 pragma Assert
(Nkind
(Aux
) = N_Compilation_Unit_Aux
);
3725 -- For a Boolean aspect, create the corresponding pragma if
3726 -- no expression or if the value is True.
3728 if Is_Boolean_Aspect
(Aspect
) and then No
(Aitem
) then
3729 if Is_True
(Static_Boolean
(Expr
)) then
3731 (Pragma_Argument_Associations
=> New_List
(
3732 Make_Pragma_Argument_Association
(Sloc
(Ent
),
3733 Expression
=> Ent
)),
3734 Pragma_Name
=> Chars
(Id
));
3736 Set_From_Aspect_Specification
(Aitem
, True);
3737 Set_Corresponding_Aspect
(Aitem
, Aspect
);
3744 -- If the aspect is on a subprogram body (relevant aspect
3745 -- is Inline), add the pragma in front of the declarations.
3747 if Nkind
(N
) = N_Subprogram_Body
then
3748 if No
(Declarations
(N
)) then
3749 Set_Declarations
(N
, New_List
);
3752 Prepend
(Aitem
, Declarations
(N
));
3754 elsif Nkind
(N
) = N_Generic_Package_Declaration
then
3755 if No
(Visible_Declarations
(Specification
(N
))) then
3756 Set_Visible_Declarations
(Specification
(N
), New_List
);
3760 Visible_Declarations
(Specification
(N
)));
3762 elsif Nkind
(N
) = N_Package_Instantiation
then
3764 Spec
: constant Node_Id
:=
3765 Specification
(Instance_Spec
(N
));
3767 if No
(Visible_Declarations
(Spec
)) then
3768 Set_Visible_Declarations
(Spec
, New_List
);
3771 Prepend
(Aitem
, Visible_Declarations
(Spec
));
3775 if No
(Pragmas_After
(Aux
)) then
3776 Set_Pragmas_After
(Aux
, New_List
);
3779 Append
(Aitem
, Pragmas_After
(Aux
));
3786 -- The evaluation of the aspect is delayed to the freezing point.
3787 -- The pragma or attribute clause if there is one is then attached
3788 -- to the aspect specification which is put in the rep item list.
3790 if Delay_Required
then
3791 if Present
(Aitem
) then
3792 Set_Is_Delayed_Aspect
(Aitem
);
3793 Set_Aspect_Rep_Item
(Aspect
, Aitem
);
3794 Set_Parent
(Aitem
, Aspect
);
3797 Set_Is_Delayed_Aspect
(Aspect
);
3799 -- In the case of Default_Value, link the aspect to base type
3800 -- as well, even though it appears on a first subtype. This is
3801 -- mandated by the semantics of the aspect. Do not establish
3802 -- the link when processing the base type itself as this leads
3803 -- to a rep item circularity. Verify that we are dealing with
3804 -- a scalar type to prevent cascaded errors.
3806 if A_Id
= Aspect_Default_Value
3807 and then Is_Scalar_Type
(E
)
3808 and then Base_Type
(E
) /= E
3810 Set_Has_Delayed_Aspects
(Base_Type
(E
));
3811 Record_Rep_Item
(Base_Type
(E
), Aspect
);
3814 Set_Has_Delayed_Aspects
(E
);
3815 Record_Rep_Item
(E
, Aspect
);
3817 -- When delay is not required and the context is a package or a
3818 -- subprogram body, insert the pragma in the body declarations.
3820 elsif Nkind_In
(N
, N_Package_Body
, N_Subprogram_Body
) then
3821 if No
(Declarations
(N
)) then
3822 Set_Declarations
(N
, New_List
);
3825 -- The pragma is added before source declarations
3827 Prepend_To
(Declarations
(N
), Aitem
);
3829 -- When delay is not required and the context is not a compilation
3830 -- unit, we simply insert the pragma/attribute definition clause
3833 elsif Present
(Aitem
) then
3834 Insert_After
(Ins_Node
, Aitem
);
3837 end Analyze_One_Aspect
;
3841 end loop Aspect_Loop
;
3843 if Has_Delayed_Aspects
(E
) then
3844 Ensure_Freeze_Node
(E
);
3846 end Analyze_Aspect_Specifications
;
3848 ---------------------------------------------------
3849 -- Analyze_Aspect_Specifications_On_Body_Or_Stub --
3850 ---------------------------------------------------
3852 procedure Analyze_Aspect_Specifications_On_Body_Or_Stub
(N
: Node_Id
) is
3853 Body_Id
: constant Entity_Id
:= Defining_Entity
(N
);
3855 procedure Diagnose_Misplaced_Aspects
(Spec_Id
: Entity_Id
);
3856 -- Body [stub] N has aspects, but they are not properly placed. Emit an
3857 -- error message depending on the aspects involved. Spec_Id denotes the
3858 -- entity of the corresponding spec.
3860 --------------------------------
3861 -- Diagnose_Misplaced_Aspects --
3862 --------------------------------
3864 procedure Diagnose_Misplaced_Aspects
(Spec_Id
: Entity_Id
) is
3865 procedure Misplaced_Aspect_Error
3868 -- Emit an error message concerning misplaced aspect Asp. Ref_Nam is
3869 -- the name of the refined version of the aspect.
3871 ----------------------------
3872 -- Misplaced_Aspect_Error --
3873 ----------------------------
3875 procedure Misplaced_Aspect_Error
3879 Asp_Nam
: constant Name_Id
:= Chars
(Identifier
(Asp
));
3880 Asp_Id
: constant Aspect_Id
:= Get_Aspect_Id
(Asp_Nam
);
3883 -- The corresponding spec already contains the aspect in question
3884 -- and the one appearing on the body must be the refined form:
3886 -- procedure P with Global ...;
3887 -- procedure P with Global ... is ... end P;
3891 if Has_Aspect
(Spec_Id
, Asp_Id
) then
3892 Error_Msg_Name_1
:= Asp_Nam
;
3894 -- Subunits cannot carry aspects that apply to a subprogram
3897 if Nkind
(Parent
(N
)) = N_Subunit
then
3898 Error_Msg_N
("aspect % cannot apply to a subunit", Asp
);
3900 -- Otherwise suggest the refined form
3903 Error_Msg_Name_2
:= Ref_Nam
;
3904 Error_Msg_N
("aspect % should be %", Asp
);
3907 -- Otherwise the aspect must appear on the spec, not on the body
3910 -- procedure P with Global ... is ... end P;
3914 ("aspect specification must appear on initial declaration",
3917 end Misplaced_Aspect_Error
;
3924 -- Start of processing for Diagnose_Misplaced_Aspects
3927 -- Iterate over the aspect specifications and emit specific errors
3928 -- where applicable.
3930 Asp
:= First
(Aspect_Specifications
(N
));
3931 while Present
(Asp
) loop
3932 Asp_Nam
:= Chars
(Identifier
(Asp
));
3934 -- Do not emit errors on aspects that can appear on a subprogram
3935 -- body. This scenario occurs when the aspect specification list
3936 -- contains both misplaced and properly placed aspects.
3938 if Aspect_On_Body_Or_Stub_OK
(Get_Aspect_Id
(Asp_Nam
)) then
3941 -- Special diagnostics for SPARK aspects
3943 elsif Asp_Nam
= Name_Depends
then
3944 Misplaced_Aspect_Error
(Asp
, Name_Refined_Depends
);
3946 elsif Asp_Nam
= Name_Global
then
3947 Misplaced_Aspect_Error
(Asp
, Name_Refined_Global
);
3949 elsif Asp_Nam
= Name_Post
then
3950 Misplaced_Aspect_Error
(Asp
, Name_Refined_Post
);
3952 -- Otherwise a language-defined aspect is misplaced
3956 ("aspect specification must appear on initial declaration",
3962 end Diagnose_Misplaced_Aspects
;
3966 Spec_Id
: constant Entity_Id
:= Unique_Defining_Entity
(N
);
3968 -- Start of processing for Analyze_Aspects_On_Body_Or_Stub
3971 -- Language-defined aspects cannot be associated with a subprogram body
3972 -- [stub] if the subprogram has a spec. Certain implementation defined
3973 -- aspects are allowed to break this rule (for all applicable cases, see
3974 -- table Aspects.Aspect_On_Body_Or_Stub_OK).
3976 if Spec_Id
/= Body_Id
and then not Aspects_On_Body_Or_Stub_OK
(N
) then
3977 Diagnose_Misplaced_Aspects
(Spec_Id
);
3979 Analyze_Aspect_Specifications
(N
, Body_Id
);
3981 end Analyze_Aspect_Specifications_On_Body_Or_Stub
;
3983 -----------------------
3984 -- Analyze_At_Clause --
3985 -----------------------
3987 -- An at clause is replaced by the corresponding Address attribute
3988 -- definition clause that is the preferred approach in Ada 95.
3990 procedure Analyze_At_Clause
(N
: Node_Id
) is
3991 CS
: constant Boolean := Comes_From_Source
(N
);
3994 -- This is an obsolescent feature
3996 Check_Restriction
(No_Obsolescent_Features
, N
);
3998 if Warn_On_Obsolescent_Feature
then
4000 ("?j?at clause is an obsolescent feature (RM J.7(2))", N
);
4002 ("\?j?use address attribute definition clause instead", N
);
4005 -- Rewrite as address clause
4008 Make_Attribute_Definition_Clause
(Sloc
(N
),
4009 Name
=> Identifier
(N
),
4010 Chars
=> Name_Address
,
4011 Expression
=> Expression
(N
)));
4013 -- We preserve Comes_From_Source, since logically the clause still comes
4014 -- from the source program even though it is changed in form.
4016 Set_Comes_From_Source
(N
, CS
);
4018 -- Analyze rewritten clause
4020 Analyze_Attribute_Definition_Clause
(N
);
4021 end Analyze_At_Clause
;
4023 -----------------------------------------
4024 -- Analyze_Attribute_Definition_Clause --
4025 -----------------------------------------
4027 procedure Analyze_Attribute_Definition_Clause
(N
: Node_Id
) is
4028 Loc
: constant Source_Ptr
:= Sloc
(N
);
4029 Nam
: constant Node_Id
:= Name
(N
);
4030 Attr
: constant Name_Id
:= Chars
(N
);
4031 Expr
: constant Node_Id
:= Expression
(N
);
4032 Id
: constant Attribute_Id
:= Get_Attribute_Id
(Attr
);
4035 -- The entity of Nam after it is analyzed. In the case of an incomplete
4036 -- type, this is the underlying type.
4039 -- The underlying entity to which the attribute applies. Generally this
4040 -- is the Underlying_Type of Ent, except in the case where the clause
4041 -- applies to the full view of an incomplete or private type, in which
4042 -- case U_Ent is just a copy of Ent.
4044 FOnly
: Boolean := False;
4045 -- Reset to True for subtype specific attribute (Alignment, Size)
4046 -- and for stream attributes, i.e. those cases where in the call to
4047 -- Rep_Item_Too_Late, FOnly is set True so that only the freezing rules
4048 -- are checked. Note that the case of stream attributes is not clear
4049 -- from the RM, but see AI95-00137. Also, the RM seems to disallow
4050 -- Storage_Size for derived task types, but that is also clearly
4053 procedure Analyze_Stream_TSS_Definition
(TSS_Nam
: TSS_Name_Type
);
4054 -- Common processing for 'Read, 'Write, 'Input and 'Output attribute
4055 -- definition clauses.
4057 function Duplicate_Clause
return Boolean;
4058 -- This routine checks if the aspect for U_Ent being given by attribute
4059 -- definition clause N is for an aspect that has already been specified,
4060 -- and if so gives an error message. If there is a duplicate, True is
4061 -- returned, otherwise if there is no error, False is returned.
4063 procedure Check_Indexing_Functions
;
4064 -- Check that the function in Constant_Indexing or Variable_Indexing
4065 -- attribute has the proper type structure. If the name is overloaded,
4066 -- check that some interpretation is legal.
4068 procedure Check_Iterator_Functions
;
4069 -- Check that there is a single function in Default_Iterator attribute
4070 -- that has the proper type structure.
4072 function Check_Primitive_Function
(Subp
: Entity_Id
) return Boolean;
4073 -- Common legality check for the previous two
4075 -----------------------------------
4076 -- Analyze_Stream_TSS_Definition --
4077 -----------------------------------
4079 procedure Analyze_Stream_TSS_Definition
(TSS_Nam
: TSS_Name_Type
) is
4080 Subp
: Entity_Id
:= Empty
;
4085 Is_Read
: constant Boolean := (TSS_Nam
= TSS_Stream_Read
);
4086 -- True for Read attribute, False for other attributes
4088 function Has_Good_Profile
4090 Report
: Boolean := False) return Boolean;
4091 -- Return true if the entity is a subprogram with an appropriate
4092 -- profile for the attribute being defined. If result is False and
4093 -- Report is True, function emits appropriate error.
4095 ----------------------
4096 -- Has_Good_Profile --
4097 ----------------------
4099 function Has_Good_Profile
4101 Report
: Boolean := False) return Boolean
4103 Expected_Ekind
: constant array (Boolean) of Entity_Kind
:=
4104 (False => E_Procedure
, True => E_Function
);
4105 Is_Function
: constant Boolean := (TSS_Nam
= TSS_Stream_Input
);
4110 if Ekind
(Subp
) /= Expected_Ekind
(Is_Function
) then
4114 F
:= First_Formal
(Subp
);
4117 or else Ekind
(Etype
(F
)) /= E_Anonymous_Access_Type
4118 or else Designated_Type
(Etype
(F
)) /=
4119 Class_Wide_Type
(RTE
(RE_Root_Stream_Type
))
4124 if not Is_Function
then
4128 Expected_Mode
: constant array (Boolean) of Entity_Kind
:=
4129 (False => E_In_Parameter
,
4130 True => E_Out_Parameter
);
4132 if Parameter_Mode
(F
) /= Expected_Mode
(Is_Read
) then
4139 -- If the attribute specification comes from an aspect
4140 -- specification for a class-wide stream, the parameter must be
4141 -- a class-wide type of the entity to which the aspect applies.
4143 if From_Aspect_Specification
(N
)
4144 and then Class_Present
(Parent
(N
))
4145 and then Is_Class_Wide_Type
(Typ
)
4151 Typ
:= Etype
(Subp
);
4154 -- Verify that the prefix of the attribute and the local name for
4155 -- the type of the formal match, or one is the class-wide of the
4156 -- other, in the case of a class-wide stream operation.
4158 if Base_Type
(Typ
) = Base_Type
(Ent
)
4159 or else (Is_Class_Wide_Type
(Typ
)
4160 and then Typ
= Class_Wide_Type
(Base_Type
(Ent
)))
4161 or else (Is_Class_Wide_Type
(Ent
)
4162 and then Ent
= Class_Wide_Type
(Base_Type
(Typ
)))
4169 if Present
(Next_Formal
(F
)) then
4172 elsif not Is_Scalar_Type
(Typ
)
4173 and then not Is_First_Subtype
(Typ
)
4174 and then not Is_Class_Wide_Type
(Typ
)
4176 if Report
and not Is_First_Subtype
(Typ
) then
4178 ("subtype of formal in stream operation must be a first "
4179 & "subtype", Parameter_Type
(Parent
(F
)));
4187 end Has_Good_Profile
;
4189 -- Start of processing for Analyze_Stream_TSS_Definition
4194 if not Is_Type
(U_Ent
) then
4195 Error_Msg_N
("local name must be a subtype", Nam
);
4198 elsif not Is_First_Subtype
(U_Ent
) then
4199 Error_Msg_N
("local name must be a first subtype", Nam
);
4203 Pnam
:= TSS
(Base_Type
(U_Ent
), TSS_Nam
);
4205 -- If Pnam is present, it can be either inherited from an ancestor
4206 -- type (in which case it is legal to redefine it for this type), or
4207 -- be a previous definition of the attribute for the same type (in
4208 -- which case it is illegal).
4210 -- In the first case, it will have been analyzed already, and we
4211 -- can check that its profile does not match the expected profile
4212 -- for a stream attribute of U_Ent. In the second case, either Pnam
4213 -- has been analyzed (and has the expected profile), or it has not
4214 -- been analyzed yet (case of a type that has not been frozen yet
4215 -- and for which the stream attribute has been set using Set_TSS).
4218 and then (No
(First_Entity
(Pnam
)) or else Has_Good_Profile
(Pnam
))
4220 Error_Msg_Sloc
:= Sloc
(Pnam
);
4221 Error_Msg_Name_1
:= Attr
;
4222 Error_Msg_N
("% attribute already defined #", Nam
);
4228 if Is_Entity_Name
(Expr
) then
4229 if not Is_Overloaded
(Expr
) then
4230 if Has_Good_Profile
(Entity
(Expr
), Report
=> True) then
4231 Subp
:= Entity
(Expr
);
4235 Get_First_Interp
(Expr
, I
, It
);
4236 while Present
(It
.Nam
) loop
4237 if Has_Good_Profile
(It
.Nam
) then
4242 Get_Next_Interp
(I
, It
);
4247 if Present
(Subp
) then
4248 if Is_Abstract_Subprogram
(Subp
) then
4249 Error_Msg_N
("stream subprogram must not be abstract", Expr
);
4252 -- A stream subprogram for an interface type must be a null
4253 -- procedure (RM 13.13.2 (38/3)). Note that the class-wide type
4254 -- of an interface is not an interface type (3.9.4 (6.b/2)).
4256 elsif Is_Interface
(U_Ent
)
4257 and then not Is_Class_Wide_Type
(U_Ent
)
4258 and then not Inside_A_Generic
4260 (Ekind
(Subp
) = E_Function
4264 (Unit_Declaration_Node
(Ultimate_Alias
(Subp
)))))
4267 ("stream subprogram for interface type must be null "
4268 & "procedure", Expr
);
4271 Set_Entity
(Expr
, Subp
);
4272 Set_Etype
(Expr
, Etype
(Subp
));
4274 New_Stream_Subprogram
(N
, U_Ent
, Subp
, TSS_Nam
);
4277 Error_Msg_Name_1
:= Attr
;
4278 Error_Msg_N
("incorrect expression for% attribute", Expr
);
4280 end Analyze_Stream_TSS_Definition
;
4282 ------------------------------
4283 -- Check_Indexing_Functions --
4284 ------------------------------
4286 procedure Check_Indexing_Functions
is
4287 Indexing_Found
: Boolean := False;
4289 procedure Check_Inherited_Indexing
;
4290 -- For a derived type, check that no indexing aspect is specified
4291 -- for the type if it is also inherited
4293 procedure Check_One_Function
(Subp
: Entity_Id
);
4294 -- Check one possible interpretation. Sets Indexing_Found True if a
4295 -- legal indexing function is found.
4297 procedure Illegal_Indexing
(Msg
: String);
4298 -- Diagnose illegal indexing function if not overloaded. In the
4299 -- overloaded case indicate that no legal interpretation exists.
4301 ------------------------------
4302 -- Check_Inherited_Indexing --
4303 ------------------------------
4305 procedure Check_Inherited_Indexing
is
4306 Inherited
: Node_Id
;
4309 if Attr
= Name_Constant_Indexing
then
4311 Find_Aspect
(Etype
(Ent
), Aspect_Constant_Indexing
);
4312 else pragma Assert
(Attr
= Name_Variable_Indexing
);
4314 Find_Aspect
(Etype
(Ent
), Aspect_Variable_Indexing
);
4317 if Present
(Inherited
) then
4318 if Debug_Flag_Dot_XX
then
4321 -- OK if current attribute_definition_clause is expansion of
4322 -- inherited aspect.
4324 elsif Aspect_Rep_Item
(Inherited
) = N
then
4327 -- Indicate the operation that must be overridden, rather than
4328 -- redefining the indexing aspect.
4332 ("indexing function already inherited from parent type");
4334 ("!override & instead",
4335 N
, Entity
(Expression
(Inherited
)));
4338 end Check_Inherited_Indexing
;
4340 ------------------------
4341 -- Check_One_Function --
4342 ------------------------
4344 procedure Check_One_Function
(Subp
: Entity_Id
) is
4345 Default_Element
: Node_Id
;
4346 Ret_Type
: constant Entity_Id
:= Etype
(Subp
);
4349 if not Is_Overloadable
(Subp
) then
4350 Illegal_Indexing
("illegal indexing function for type&");
4353 elsif Scope
(Subp
) /= Scope
(Ent
) then
4354 if Nkind
(Expr
) = N_Expanded_Name
then
4356 -- Indexing function can't be declared elsewhere
4359 ("indexing function must be declared in scope of type&");
4364 elsif No
(First_Formal
(Subp
)) then
4366 ("Indexing requires a function that applies to type&");
4369 elsif No
(Next_Formal
(First_Formal
(Subp
))) then
4371 ("indexing function must have at least two parameters");
4374 elsif Is_Derived_Type
(Ent
) then
4375 Check_Inherited_Indexing
;
4378 if not Check_Primitive_Function
(Subp
) then
4380 ("Indexing aspect requires a function that applies to type&");
4384 -- If partial declaration exists, verify that it is not tagged.
4386 if Ekind
(Current_Scope
) = E_Package
4387 and then Has_Private_Declaration
(Ent
)
4388 and then From_Aspect_Specification
(N
)
4390 List_Containing
(Parent
(Ent
)) =
4391 Private_Declarations
4392 (Specification
(Unit_Declaration_Node
(Current_Scope
)))
4393 and then Nkind
(N
) = N_Attribute_Definition_Clause
4400 First
(Visible_Declarations
4402 (Unit_Declaration_Node
(Current_Scope
))));
4404 while Present
(Decl
) loop
4405 if Nkind
(Decl
) = N_Private_Type_Declaration
4406 and then Ent
= Full_View
(Defining_Identifier
(Decl
))
4407 and then Tagged_Present
(Decl
)
4408 and then No
(Aspect_Specifications
(Decl
))
4411 ("Indexing aspect cannot be specified on full view "
4412 & "if partial view is tagged");
4421 -- An indexing function must return either the default element of
4422 -- the container, or a reference type. For variable indexing it
4423 -- must be the latter.
4426 Find_Value_Of_Aspect
4427 (Etype
(First_Formal
(Subp
)), Aspect_Iterator_Element
);
4429 if Present
(Default_Element
) then
4430 Analyze
(Default_Element
);
4433 -- For variable_indexing the return type must be a reference type
4435 if Attr
= Name_Variable_Indexing
then
4436 if not Has_Implicit_Dereference
(Ret_Type
) then
4438 ("variable indexing must return a reference type");
4441 elsif Is_Access_Constant
4442 (Etype
(First_Discriminant
(Ret_Type
)))
4445 ("variable indexing must return an access to variable");
4450 if Has_Implicit_Dereference
(Ret_Type
)
4452 Is_Access_Constant
(Etype
(First_Discriminant
(Ret_Type
)))
4455 ("constant indexing must return an access to constant");
4458 elsif Is_Access_Type
(Etype
(First_Formal
(Subp
)))
4459 and then not Is_Access_Constant
(Etype
(First_Formal
(Subp
)))
4462 ("constant indexing must apply to an access to constant");
4467 -- All checks succeeded.
4469 Indexing_Found
:= True;
4470 end Check_One_Function
;
4472 -----------------------
4473 -- Illegal_Indexing --
4474 -----------------------
4476 procedure Illegal_Indexing
(Msg
: String) is
4478 Error_Msg_NE
(Msg
, N
, Ent
);
4479 end Illegal_Indexing
;
4481 -- Start of processing for Check_Indexing_Functions
4485 Check_Inherited_Indexing
;
4490 if not Is_Overloaded
(Expr
) then
4491 Check_One_Function
(Entity
(Expr
));
4499 Indexing_Found
:= False;
4500 Get_First_Interp
(Expr
, I
, It
);
4501 while Present
(It
.Nam
) loop
4503 -- Note that analysis will have added the interpretation
4504 -- that corresponds to the dereference. We only check the
4505 -- subprogram itself. Ignore homonyms that may come from
4506 -- derived types in the context.
4508 if Is_Overloadable
(It
.Nam
)
4509 and then Comes_From_Source
(It
.Nam
)
4511 Check_One_Function
(It
.Nam
);
4514 Get_Next_Interp
(I
, It
);
4519 if not Indexing_Found
and then not Error_Posted
(N
) then
4521 ("aspect Indexing requires a local function that applies to "
4522 & "type&", Expr
, Ent
);
4524 end Check_Indexing_Functions
;
4526 ------------------------------
4527 -- Check_Iterator_Functions --
4528 ------------------------------
4530 procedure Check_Iterator_Functions
is
4531 function Valid_Default_Iterator
(Subp
: Entity_Id
) return Boolean;
4532 -- Check one possible interpretation for validity
4534 ----------------------------
4535 -- Valid_Default_Iterator --
4536 ----------------------------
4538 function Valid_Default_Iterator
(Subp
: Entity_Id
) return Boolean is
4539 Root_T
: constant Entity_Id
:= Root_Type
(Etype
(Etype
(Subp
)));
4543 if not Check_Primitive_Function
(Subp
) then
4546 -- The return type must be derived from a type in an instance
4547 -- of Iterator.Interfaces, and thus its root type must have a
4550 elsif Chars
(Root_T
) /= Name_Forward_Iterator
4551 and then Chars
(Root_T
) /= Name_Reversible_Iterator
4556 Formal
:= First_Formal
(Subp
);
4559 -- False if any subsequent formal has no default expression
4561 Formal
:= Next_Formal
(Formal
);
4562 while Present
(Formal
) loop
4563 if No
(Expression
(Parent
(Formal
))) then
4567 Next_Formal
(Formal
);
4570 -- True if all subsequent formals have default expressions
4573 end Valid_Default_Iterator
;
4575 -- Start of processing for Check_Iterator_Functions
4580 if not Is_Entity_Name
(Expr
) then
4581 Error_Msg_N
("aspect Iterator must be a function name", Expr
);
4584 if not Is_Overloaded
(Expr
) then
4585 if not Check_Primitive_Function
(Entity
(Expr
)) then
4587 ("aspect Indexing requires a function that applies to type&",
4588 Entity
(Expr
), Ent
);
4591 -- Flag the default_iterator as well as the denoted function.
4593 if not Valid_Default_Iterator
(Entity
(Expr
)) then
4594 Error_Msg_N
("improper function for default iterator!", Expr
);
4599 Default
: Entity_Id
:= Empty
;
4604 Get_First_Interp
(Expr
, I
, It
);
4605 while Present
(It
.Nam
) loop
4606 if not Check_Primitive_Function
(It
.Nam
)
4607 or else not Valid_Default_Iterator
(It
.Nam
)
4611 elsif Present
(Default
) then
4613 -- An explicit one should override an implicit one
4615 if Comes_From_Source
(Default
) =
4616 Comes_From_Source
(It
.Nam
)
4618 Error_Msg_N
("default iterator must be unique", Expr
);
4619 Error_Msg_Sloc
:= Sloc
(Default
);
4620 Error_Msg_N
("\\possible interpretation#", Expr
);
4621 Error_Msg_Sloc
:= Sloc
(It
.Nam
);
4622 Error_Msg_N
("\\possible interpretation#", Expr
);
4624 elsif Comes_From_Source
(It
.Nam
) then
4631 Get_Next_Interp
(I
, It
);
4634 if Present
(Default
) then
4635 Set_Entity
(Expr
, Default
);
4636 Set_Is_Overloaded
(Expr
, False);
4639 ("no interpretation is a valid default iterator!", Expr
);
4643 end Check_Iterator_Functions
;
4645 -------------------------------
4646 -- Check_Primitive_Function --
4647 -------------------------------
4649 function Check_Primitive_Function
(Subp
: Entity_Id
) return Boolean is
4653 if Ekind
(Subp
) /= E_Function
then
4657 if No
(First_Formal
(Subp
)) then
4660 Ctrl
:= Etype
(First_Formal
(Subp
));
4663 -- To be a primitive operation subprogram has to be in same scope.
4665 if Scope
(Ctrl
) /= Scope
(Subp
) then
4669 -- Type of formal may be the class-wide type, an access to such,
4670 -- or an incomplete view.
4673 or else Ctrl
= Class_Wide_Type
(Ent
)
4675 (Ekind
(Ctrl
) = E_Anonymous_Access_Type
4676 and then (Designated_Type
(Ctrl
) = Ent
4678 Designated_Type
(Ctrl
) = Class_Wide_Type
(Ent
)))
4680 (Ekind
(Ctrl
) = E_Incomplete_Type
4681 and then Full_View
(Ctrl
) = Ent
)
4689 end Check_Primitive_Function
;
4691 ----------------------
4692 -- Duplicate_Clause --
4693 ----------------------
4695 function Duplicate_Clause
return Boolean is
4699 -- Nothing to do if this attribute definition clause comes from
4700 -- an aspect specification, since we could not be duplicating an
4701 -- explicit clause, and we dealt with the case of duplicated aspects
4702 -- in Analyze_Aspect_Specifications.
4704 if From_Aspect_Specification
(N
) then
4708 -- Otherwise current clause may duplicate previous clause, or a
4709 -- previously given pragma or aspect specification for the same
4712 A
:= Get_Rep_Item
(U_Ent
, Chars
(N
), Check_Parents
=> False);
4715 Error_Msg_Name_1
:= Chars
(N
);
4716 Error_Msg_Sloc
:= Sloc
(A
);
4718 Error_Msg_NE
("aspect% for & previously given#", N
, U_Ent
);
4723 end Duplicate_Clause
;
4725 -- Start of processing for Analyze_Attribute_Definition_Clause
4728 -- The following code is a defense against recursion. Not clear that
4729 -- this can happen legitimately, but perhaps some error situations can
4730 -- cause it, and we did see this recursion during testing.
4732 if Analyzed
(N
) then
4735 Set_Analyzed
(N
, True);
4738 Check_Restriction_No_Use_Of_Attribute
(N
);
4740 -- Ignore some selected attributes in CodePeer mode since they are not
4741 -- relevant in this context.
4743 if CodePeer_Mode
then
4746 -- Ignore Component_Size in CodePeer mode, to avoid changing the
4747 -- internal representation of types by implicitly packing them.
4749 when Attribute_Component_Size
=>
4750 Rewrite
(N
, Make_Null_Statement
(Sloc
(N
)));
4758 -- Process Ignore_Rep_Clauses option
4760 if Ignore_Rep_Clauses
then
4763 -- The following should be ignored. They do not affect legality
4764 -- and may be target dependent. The basic idea of -gnatI is to
4765 -- ignore any rep clauses that may be target dependent but do not
4766 -- affect legality (except possibly to be rejected because they
4767 -- are incompatible with the compilation target).
4769 when Attribute_Alignment
4770 | Attribute_Bit_Order
4771 | Attribute_Component_Size
4772 | Attribute_Default_Scalar_Storage_Order
4773 | Attribute_Machine_Radix
4774 | Attribute_Object_Size
4775 | Attribute_Scalar_Storage_Order
4778 | Attribute_Stream_Size
4779 | Attribute_Value_Size
4781 Kill_Rep_Clause
(N
);
4784 -- The following should not be ignored, because in the first place
4785 -- they are reasonably portable, and should not cause problems
4786 -- in compiling code from another target, and also they do affect
4787 -- legality, e.g. failing to provide a stream attribute for a type
4788 -- may make a program illegal.
4790 when Attribute_External_Tag
4794 | Attribute_Simple_Storage_Pool
4795 | Attribute_Storage_Pool
4796 | Attribute_Storage_Size
4801 -- We do not do anything here with address clauses, they will be
4802 -- removed by Freeze later on, but for now, it works better to
4803 -- keep them in the tree.
4805 when Attribute_Address
=>
4808 -- Other cases are errors ("attribute& cannot be set with
4809 -- definition clause"), which will be caught below.
4817 Ent
:= Entity
(Nam
);
4819 if Rep_Item_Too_Early
(Ent
, N
) then
4823 -- Rep clause applies to full view of incomplete type or private type if
4824 -- we have one (if not, this is a premature use of the type). However,
4825 -- certain semantic checks need to be done on the specified entity (i.e.
4826 -- the private view), so we save it in Ent.
4828 if Is_Private_Type
(Ent
)
4829 and then Is_Derived_Type
(Ent
)
4830 and then not Is_Tagged_Type
(Ent
)
4831 and then No
(Full_View
(Ent
))
4833 -- If this is a private type whose completion is a derivation from
4834 -- another private type, there is no full view, and the attribute
4835 -- belongs to the type itself, not its underlying parent.
4839 elsif Ekind
(Ent
) = E_Incomplete_Type
then
4841 -- The attribute applies to the full view, set the entity of the
4842 -- attribute definition accordingly.
4844 Ent
:= Underlying_Type
(Ent
);
4846 Set_Entity
(Nam
, Ent
);
4849 U_Ent
:= Underlying_Type
(Ent
);
4852 -- Avoid cascaded error
4854 if Etype
(Nam
) = Any_Type
then
4857 -- Must be declared in current scope or in case of an aspect
4858 -- specification, must be visible in current scope.
4860 elsif Scope
(Ent
) /= Current_Scope
4862 not (From_Aspect_Specification
(N
)
4863 and then Scope_Within_Or_Same
(Current_Scope
, Scope
(Ent
)))
4865 Error_Msg_N
("entity must be declared in this scope", Nam
);
4868 -- Must not be a source renaming (we do have some cases where the
4869 -- expander generates a renaming, and those cases are OK, in such
4870 -- cases any attribute applies to the renamed object as well).
4872 elsif Is_Object
(Ent
)
4873 and then Present
(Renamed_Object
(Ent
))
4875 -- Case of renamed object from source, this is an error
4877 if Comes_From_Source
(Renamed_Object
(Ent
)) then
4878 Get_Name_String
(Chars
(N
));
4879 Error_Msg_Strlen
:= Name_Len
;
4880 Error_Msg_String
(1 .. Name_Len
) := Name_Buffer
(1 .. Name_Len
);
4882 ("~ clause not allowed for a renaming declaration "
4883 & "(RM 13.1(6))", Nam
);
4886 -- For the case of a compiler generated renaming, the attribute
4887 -- definition clause applies to the renamed object created by the
4888 -- expander. The easiest general way to handle this is to create a
4889 -- copy of the attribute definition clause for this object.
4891 elsif Is_Entity_Name
(Renamed_Object
(Ent
)) then
4893 Make_Attribute_Definition_Clause
(Loc
,
4895 New_Occurrence_Of
(Entity
(Renamed_Object
(Ent
)), Loc
),
4897 Expression
=> Duplicate_Subexpr
(Expression
(N
))));
4899 -- If the renamed object is not an entity, it must be a dereference
4900 -- of an unconstrained function call, and we must introduce a new
4901 -- declaration to capture the expression. This is needed in the case
4902 -- of 'Alignment, where the original declaration must be rewritten.
4906 (Nkind
(Renamed_Object
(Ent
)) = N_Explicit_Dereference
);
4910 -- If no underlying entity, use entity itself, applies to some
4911 -- previously detected error cases ???
4913 elsif No
(U_Ent
) then
4916 -- Cannot specify for a subtype (exception Object/Value_Size)
4918 elsif Is_Type
(U_Ent
)
4919 and then not Is_First_Subtype
(U_Ent
)
4920 and then Id
/= Attribute_Object_Size
4921 and then Id
/= Attribute_Value_Size
4922 and then not From_At_Mod
(N
)
4924 Error_Msg_N
("cannot specify attribute for subtype", Nam
);
4928 Set_Entity
(N
, U_Ent
);
4930 -- Switch on particular attribute
4938 -- Address attribute definition clause
4940 when Attribute_Address
=> Address
: begin
4942 -- A little error check, catch for X'Address use X'Address;
4944 if Nkind
(Nam
) = N_Identifier
4945 and then Nkind
(Expr
) = N_Attribute_Reference
4946 and then Attribute_Name
(Expr
) = Name_Address
4947 and then Nkind
(Prefix
(Expr
)) = N_Identifier
4948 and then Chars
(Nam
) = Chars
(Prefix
(Expr
))
4951 ("address for & is self-referencing", Prefix
(Expr
), Ent
);
4955 -- Not that special case, carry on with analysis of expression
4957 Analyze_And_Resolve
(Expr
, RTE
(RE_Address
));
4959 -- Even when ignoring rep clauses we need to indicate that the
4960 -- entity has an address clause and thus it is legal to declare
4961 -- it imported. Freeze will get rid of the address clause later.
4962 -- Also call Set_Address_Taken to indicate that an address clause
4963 -- was present, even if we are about to remove it.
4965 if Ignore_Rep_Clauses
then
4966 Set_Address_Taken
(U_Ent
);
4968 if Ekind_In
(U_Ent
, E_Variable
, E_Constant
) then
4969 Record_Rep_Item
(U_Ent
, N
);
4975 if Duplicate_Clause
then
4978 -- Case of address clause for subprogram
4980 elsif Is_Subprogram
(U_Ent
) then
4981 if Has_Homonym
(U_Ent
) then
4983 ("address clause cannot be given for overloaded "
4984 & "subprogram", Nam
);
4988 -- For subprograms, all address clauses are permitted, and we
4989 -- mark the subprogram as having a deferred freeze so that Gigi
4990 -- will not elaborate it too soon.
4992 -- Above needs more comments, what is too soon about???
4994 Set_Has_Delayed_Freeze
(U_Ent
);
4996 -- Case of address clause for entry
4998 elsif Ekind
(U_Ent
) = E_Entry
then
4999 if Nkind
(Parent
(N
)) = N_Task_Body
then
5001 ("entry address must be specified in task spec", Nam
);
5005 -- For entries, we require a constant address
5007 Check_Constant_Address_Clause
(Expr
, U_Ent
);
5009 -- Special checks for task types
5011 if Is_Task_Type
(Scope
(U_Ent
))
5012 and then Comes_From_Source
(Scope
(U_Ent
))
5015 ("??entry address declared for entry in task type", N
);
5017 ("\??only one task can be declared of this type", N
);
5020 -- Entry address clauses are obsolescent
5022 Check_Restriction
(No_Obsolescent_Features
, N
);
5024 if Warn_On_Obsolescent_Feature
then
5026 ("?j?attaching interrupt to task entry is an obsolescent "
5027 & "feature (RM J.7.1)", N
);
5029 ("\?j?use interrupt procedure instead", N
);
5032 -- Case of an address clause for a class-wide object, which is
5033 -- considered erroneous.
5035 elsif Is_Class_Wide_Type
(Etype
(U_Ent
)) then
5037 ("??class-wide object & must not be overlaid", Nam
, U_Ent
);
5039 ("\??Program_Error will be raised at run time", Nam
);
5040 Insert_Action
(Declaration_Node
(U_Ent
),
5041 Make_Raise_Program_Error
(Loc
,
5042 Reason
=> PE_Overlaid_Controlled_Object
));
5045 -- Case of address clause for an object
5047 elsif Ekind_In
(U_Ent
, E_Constant
, E_Variable
) then
5049 Expr
: constant Node_Id
:= Expression
(N
);
5054 -- Exported variables cannot have an address clause, because
5055 -- this cancels the effect of the pragma Export.
5057 if Is_Exported
(U_Ent
) then
5059 ("cannot export object with address clause", Nam
);
5063 Find_Overlaid_Entity
(N
, O_Ent
, Off
);
5065 if Present
(O_Ent
) then
5067 -- If the object overlays a constant object, mark it so
5069 if Is_Constant_Object
(O_Ent
) then
5070 Set_Overlays_Constant
(U_Ent
);
5073 -- If the address clause is of the form:
5075 -- for X'Address use Y'Address;
5079 -- C : constant Address := Y'Address;
5081 -- for X'Address use C;
5083 -- then we make an entry in the table to check the size
5084 -- and alignment of the overlaying variable. But we defer
5085 -- this check till after code generation to take full
5086 -- advantage of the annotation done by the back end.
5088 -- If the entity has a generic type, the check will be
5089 -- performed in the instance if the actual type justifies
5090 -- it, and we do not insert the clause in the table to
5091 -- prevent spurious warnings.
5093 -- Note: we used to test Comes_From_Source and only give
5094 -- this warning for source entities, but we have removed
5095 -- this test. It really seems bogus to generate overlays
5096 -- that would trigger this warning in generated code.
5097 -- Furthermore, by removing the test, we handle the
5098 -- aspect case properly.
5100 if Is_Object
(O_Ent
)
5101 and then not Is_Generic_Type
(Etype
(U_Ent
))
5102 and then Address_Clause_Overlay_Warnings
5104 Register_Address_Clause_Check
5105 (N
, U_Ent
, No_Uint
, O_Ent
, Off
);
5108 -- If the overlay changes the storage order, mark the
5109 -- entity as being volatile to block any optimization
5110 -- for it since the construct is not really supported
5113 if (Is_Record_Type
(Etype
(U_Ent
))
5114 or else Is_Array_Type
(Etype
(U_Ent
)))
5115 and then (Is_Record_Type
(Etype
(O_Ent
))
5116 or else Is_Array_Type
(Etype
(O_Ent
)))
5117 and then Reverse_Storage_Order
(Etype
(U_Ent
)) /=
5118 Reverse_Storage_Order
(Etype
(O_Ent
))
5120 Set_Treat_As_Volatile
(U_Ent
);
5124 -- If this is not an overlay, mark a variable as being
5125 -- volatile to prevent unwanted optimizations. It's a
5126 -- conservative interpretation of RM 13.3(19) for the
5127 -- cases where the compiler cannot detect potential
5128 -- aliasing issues easily and it also covers the case
5129 -- of an absolute address where the volatile aspect is
5130 -- kind of implicit.
5132 if Ekind
(U_Ent
) = E_Variable
then
5133 Set_Treat_As_Volatile
(U_Ent
);
5136 -- Make an entry in the table for an absolute address as
5137 -- above to check that the value is compatible with the
5138 -- alignment of the object.
5141 Addr
: constant Node_Id
:= Address_Value
(Expr
);
5143 if Compile_Time_Known_Value
(Addr
)
5144 and then Address_Clause_Overlay_Warnings
5146 Register_Address_Clause_Check
5147 (N
, U_Ent
, Expr_Value
(Addr
), Empty
, False);
5152 -- Issue an unconditional warning for a constant overlaying
5153 -- a variable. For the reverse case, we will issue it only
5154 -- if the variable is modified.
5156 if Ekind
(U_Ent
) = E_Constant
5157 and then Present
(O_Ent
)
5158 and then not Overlays_Constant
(U_Ent
)
5159 and then Address_Clause_Overlay_Warnings
5161 Error_Msg_N
("??constant overlays a variable", Expr
);
5163 -- Imported variables can have an address clause, but then
5164 -- the import is pretty meaningless except to suppress
5165 -- initializations, so we do not need such variables to
5166 -- be statically allocated (and in fact it causes trouble
5167 -- if the address clause is a local value).
5169 elsif Is_Imported
(U_Ent
) then
5170 Set_Is_Statically_Allocated
(U_Ent
, False);
5173 -- We mark a possible modification of a variable with an
5174 -- address clause, since it is likely aliasing is occurring.
5176 Note_Possible_Modification
(Nam
, Sure
=> False);
5178 -- Legality checks on the address clause for initialized
5179 -- objects is deferred until the freeze point, because
5180 -- a subsequent pragma might indicate that the object
5181 -- is imported and thus not initialized. Also, the address
5182 -- clause might involve entities that have yet to be
5185 Set_Has_Delayed_Freeze
(U_Ent
);
5187 -- If an initialization call has been generated for this
5188 -- object, it needs to be deferred to after the freeze node
5189 -- we have just now added, otherwise GIGI will see a
5190 -- reference to the variable (as actual to the IP call)
5191 -- before its definition.
5194 Init_Call
: constant Node_Id
:=
5195 Remove_Init_Call
(U_Ent
, N
);
5198 if Present
(Init_Call
) then
5199 Append_Freeze_Action
(U_Ent
, Init_Call
);
5201 -- Reset Initialization_Statements pointer so that
5202 -- if there is a pragma Import further down, it can
5203 -- clear any default initialization.
5205 Set_Initialization_Statements
(U_Ent
, Init_Call
);
5209 -- Entity has delayed freeze, so we will generate an
5210 -- alignment check at the freeze point unless suppressed.
5212 if not Range_Checks_Suppressed
(U_Ent
)
5213 and then not Alignment_Checks_Suppressed
(U_Ent
)
5215 Set_Check_Address_Alignment
(N
);
5218 -- Kill the size check code, since we are not allocating
5219 -- the variable, it is somewhere else.
5221 Kill_Size_Check_Code
(U_Ent
);
5224 -- Not a valid entity for an address clause
5227 Error_Msg_N
("address cannot be given for &", Nam
);
5235 -- Alignment attribute definition clause
5237 when Attribute_Alignment
=> Alignment
: declare
5238 Align
: constant Uint
:= Get_Alignment_Value
(Expr
);
5239 Max_Align
: constant Uint
:= UI_From_Int
(Maximum_Alignment
);
5244 if not Is_Type
(U_Ent
)
5245 and then Ekind
(U_Ent
) /= E_Variable
5246 and then Ekind
(U_Ent
) /= E_Constant
5248 Error_Msg_N
("alignment cannot be given for &", Nam
);
5250 elsif Duplicate_Clause
then
5253 elsif Align
/= No_Uint
then
5254 Set_Has_Alignment_Clause
(U_Ent
);
5256 -- Tagged type case, check for attempt to set alignment to a
5257 -- value greater than Max_Align, and reset if so. This error
5258 -- is suppressed in ASIS mode to allow for different ASIS
5259 -- back ends or ASIS-based tools to query the illegal clause.
5261 if Is_Tagged_Type
(U_Ent
)
5262 and then Align
> Max_Align
5263 and then not ASIS_Mode
5266 ("alignment for & set to Maximum_Aligment??", Nam
);
5267 Set_Alignment
(U_Ent
, Max_Align
);
5272 Set_Alignment
(U_Ent
, Align
);
5275 -- For an array type, U_Ent is the first subtype. In that case,
5276 -- also set the alignment of the anonymous base type so that
5277 -- other subtypes (such as the itypes for aggregates of the
5278 -- type) also receive the expected alignment.
5280 if Is_Array_Type
(U_Ent
) then
5281 Set_Alignment
(Base_Type
(U_Ent
), Align
);
5290 -- Bit_Order attribute definition clause
5292 when Attribute_Bit_Order
=>
5293 if not Is_Record_Type
(U_Ent
) then
5295 ("Bit_Order can only be defined for record type", Nam
);
5297 elsif Duplicate_Clause
then
5301 Analyze_And_Resolve
(Expr
, RTE
(RE_Bit_Order
));
5303 if Etype
(Expr
) = Any_Type
then
5306 elsif not Is_OK_Static_Expression
(Expr
) then
5307 Flag_Non_Static_Expr
5308 ("Bit_Order requires static expression!", Expr
);
5311 if (Expr_Value
(Expr
) = 0) /= Bytes_Big_Endian
then
5312 Set_Reverse_Bit_Order
(Base_Type
(U_Ent
), True);
5317 --------------------
5318 -- Component_Size --
5319 --------------------
5321 -- Component_Size attribute definition clause
5323 when Attribute_Component_Size
=> Component_Size_Case
: declare
5324 Csize
: constant Uint
:= Static_Integer
(Expr
);
5328 New_Ctyp
: Entity_Id
;
5332 if not Is_Array_Type
(U_Ent
) then
5333 Error_Msg_N
("component size requires array type", Nam
);
5337 Btype
:= Base_Type
(U_Ent
);
5338 Ctyp
:= Component_Type
(Btype
);
5340 if Duplicate_Clause
then
5343 elsif Rep_Item_Too_Early
(Btype
, N
) then
5346 elsif Csize
/= No_Uint
then
5347 Check_Size
(Expr
, Ctyp
, Csize
, Biased
);
5349 -- For the biased case, build a declaration for a subtype that
5350 -- will be used to represent the biased subtype that reflects
5351 -- the biased representation of components. We need the subtype
5352 -- to get proper conversions on referencing elements of the
5357 Make_Defining_Identifier
(Loc
,
5359 New_External_Name
(Chars
(U_Ent
), 'C', 0, 'T'));
5362 Make_Subtype_Declaration
(Loc
,
5363 Defining_Identifier
=> New_Ctyp
,
5364 Subtype_Indication
=>
5365 New_Occurrence_Of
(Component_Type
(Btype
), Loc
));
5367 Set_Parent
(Decl
, N
);
5368 Analyze
(Decl
, Suppress
=> All_Checks
);
5370 Set_Has_Delayed_Freeze
(New_Ctyp
, False);
5371 Set_Esize
(New_Ctyp
, Csize
);
5372 Set_RM_Size
(New_Ctyp
, Csize
);
5373 Init_Alignment
(New_Ctyp
);
5374 Set_Is_Itype
(New_Ctyp
, True);
5375 Set_Associated_Node_For_Itype
(New_Ctyp
, U_Ent
);
5377 Set_Component_Type
(Btype
, New_Ctyp
);
5378 Set_Biased
(New_Ctyp
, N
, "component size clause");
5381 Set_Component_Size
(Btype
, Csize
);
5383 -- Deal with warning on overridden size
5385 if Warn_On_Overridden_Size
5386 and then Has_Size_Clause
(Ctyp
)
5387 and then RM_Size
(Ctyp
) /= Csize
5390 ("component size overrides size clause for&?S?", N
, Ctyp
);
5393 Set_Has_Component_Size_Clause
(Btype
, True);
5394 Set_Has_Non_Standard_Rep
(Btype
, True);
5396 end Component_Size_Case
;
5398 -----------------------
5399 -- Constant_Indexing --
5400 -----------------------
5402 when Attribute_Constant_Indexing
=>
5403 Check_Indexing_Functions
;
5409 when Attribute_CPU
=>
5411 -- CPU attribute definition clause not allowed except from aspect
5414 if From_Aspect_Specification
(N
) then
5415 if not Is_Task_Type
(U_Ent
) then
5416 Error_Msg_N
("CPU can only be defined for task", Nam
);
5418 elsif Duplicate_Clause
then
5422 -- The expression must be analyzed in the special manner
5423 -- described in "Handling of Default and Per-Object
5424 -- Expressions" in sem.ads.
5426 -- The visibility to the discriminants must be restored
5428 Push_Scope_And_Install_Discriminants
(U_Ent
);
5429 Preanalyze_Spec_Expression
(Expr
, RTE
(RE_CPU_Range
));
5430 Uninstall_Discriminants_And_Pop_Scope
(U_Ent
);
5432 if not Is_OK_Static_Expression
(Expr
) then
5433 Check_Restriction
(Static_Priorities
, Expr
);
5439 ("attribute& cannot be set with definition clause", N
);
5442 ----------------------
5443 -- Default_Iterator --
5444 ----------------------
5446 when Attribute_Default_Iterator
=> Default_Iterator
: declare
5451 -- If target type is untagged, further checks are irrelevant
5453 if not Is_Tagged_Type
(U_Ent
) then
5455 ("aspect Default_Iterator applies to tagged type", Nam
);
5459 Check_Iterator_Functions
;
5463 if not Is_Entity_Name
(Expr
)
5464 or else Ekind
(Entity
(Expr
)) /= E_Function
5466 Error_Msg_N
("aspect Iterator must be a function", Expr
);
5469 Func
:= Entity
(Expr
);
5472 -- The type of the first parameter must be T, T'class, or a
5473 -- corresponding access type (5.5.1 (8/3). If function is
5474 -- parameterless label type accordingly.
5476 if No
(First_Formal
(Func
)) then
5479 Typ
:= Etype
(First_Formal
(Func
));
5483 or else Typ
= Class_Wide_Type
(U_Ent
)
5484 or else (Is_Access_Type
(Typ
)
5485 and then Designated_Type
(Typ
) = U_Ent
)
5486 or else (Is_Access_Type
(Typ
)
5487 and then Designated_Type
(Typ
) =
5488 Class_Wide_Type
(U_Ent
))
5494 ("Default Iterator must be a primitive of&", Func
, U_Ent
);
5496 end Default_Iterator
;
5498 ------------------------
5499 -- Dispatching_Domain --
5500 ------------------------
5502 when Attribute_Dispatching_Domain
=>
5504 -- Dispatching_Domain attribute definition clause not allowed
5505 -- except from aspect specification.
5507 if From_Aspect_Specification
(N
) then
5508 if not Is_Task_Type
(U_Ent
) then
5510 ("Dispatching_Domain can only be defined for task", Nam
);
5512 elsif Duplicate_Clause
then
5516 -- The expression must be analyzed in the special manner
5517 -- described in "Handling of Default and Per-Object
5518 -- Expressions" in sem.ads.
5520 -- The visibility to the discriminants must be restored
5522 Push_Scope_And_Install_Discriminants
(U_Ent
);
5524 Preanalyze_Spec_Expression
5525 (Expr
, RTE
(RE_Dispatching_Domain
));
5527 Uninstall_Discriminants_And_Pop_Scope
(U_Ent
);
5532 ("attribute& cannot be set with definition clause", N
);
5539 when Attribute_External_Tag
=>
5540 if not Is_Tagged_Type
(U_Ent
) then
5541 Error_Msg_N
("should be a tagged type", Nam
);
5544 if Duplicate_Clause
then
5548 Analyze_And_Resolve
(Expr
, Standard_String
);
5550 if not Is_OK_Static_Expression
(Expr
) then
5551 Flag_Non_Static_Expr
5552 ("static string required for tag name!", Nam
);
5555 if not Is_Library_Level_Entity
(U_Ent
) then
5557 ("??non-unique external tag supplied for &", N
, U_Ent
);
5559 ("\??same external tag applies to all subprogram calls",
5562 ("\??corresponding internal tag cannot be obtained", N
);
5566 --------------------------
5567 -- Implicit_Dereference --
5568 --------------------------
5570 when Attribute_Implicit_Dereference
=>
5572 -- Legality checks already performed at the point of the type
5573 -- declaration, aspect is not delayed.
5581 when Attribute_Input
=>
5582 Analyze_Stream_TSS_Definition
(TSS_Stream_Input
);
5583 Set_Has_Specified_Stream_Input
(Ent
);
5585 ------------------------
5586 -- Interrupt_Priority --
5587 ------------------------
5589 when Attribute_Interrupt_Priority
=>
5591 -- Interrupt_Priority attribute definition clause not allowed
5592 -- except from aspect specification.
5594 if From_Aspect_Specification
(N
) then
5595 if not Is_Concurrent_Type
(U_Ent
) then
5597 ("Interrupt_Priority can only be defined for task and "
5598 & "protected object", Nam
);
5600 elsif Duplicate_Clause
then
5604 -- The expression must be analyzed in the special manner
5605 -- described in "Handling of Default and Per-Object
5606 -- Expressions" in sem.ads.
5608 -- The visibility to the discriminants must be restored
5610 Push_Scope_And_Install_Discriminants
(U_Ent
);
5612 Preanalyze_Spec_Expression
5613 (Expr
, RTE
(RE_Interrupt_Priority
));
5615 Uninstall_Discriminants_And_Pop_Scope
(U_Ent
);
5617 -- Check the No_Task_At_Interrupt_Priority restriction
5619 if Is_Task_Type
(U_Ent
) then
5620 Check_Restriction
(No_Task_At_Interrupt_Priority
, N
);
5626 ("attribute& cannot be set with definition clause", N
);
5633 when Attribute_Iterable
=>
5636 if Nkind
(Expr
) /= N_Aggregate
then
5637 Error_Msg_N
("aspect Iterable must be an aggregate", Expr
);
5644 Assoc
:= First
(Component_Associations
(Expr
));
5645 while Present
(Assoc
) loop
5646 if not Is_Entity_Name
(Expression
(Assoc
)) then
5647 Error_Msg_N
("value must be a function", Assoc
);
5654 ----------------------
5655 -- Iterator_Element --
5656 ----------------------
5658 when Attribute_Iterator_Element
=>
5661 if not Is_Entity_Name
(Expr
)
5662 or else not Is_Type
(Entity
(Expr
))
5664 Error_Msg_N
("aspect Iterator_Element must be a type", Expr
);
5671 -- Machine radix attribute definition clause
5673 when Attribute_Machine_Radix
=> Machine_Radix
: declare
5674 Radix
: constant Uint
:= Static_Integer
(Expr
);
5677 if not Is_Decimal_Fixed_Point_Type
(U_Ent
) then
5678 Error_Msg_N
("decimal fixed-point type expected for &", Nam
);
5680 elsif Duplicate_Clause
then
5683 elsif Radix
/= No_Uint
then
5684 Set_Has_Machine_Radix_Clause
(U_Ent
);
5685 Set_Has_Non_Standard_Rep
(Base_Type
(U_Ent
));
5690 elsif Radix
= 10 then
5691 Set_Machine_Radix_10
(U_Ent
);
5693 -- The following error is suppressed in ASIS mode to allow for
5694 -- different ASIS back ends or ASIS-based tools to query the
5697 elsif not ASIS_Mode
then
5698 Error_Msg_N
("machine radix value must be 2 or 10", Expr
);
5707 -- Object_Size attribute definition clause
5709 when Attribute_Object_Size
=> Object_Size
: declare
5710 Size
: constant Uint
:= Static_Integer
(Expr
);
5713 pragma Warnings
(Off
, Biased
);
5716 if not Is_Type
(U_Ent
) then
5717 Error_Msg_N
("Object_Size cannot be given for &", Nam
);
5719 elsif Duplicate_Clause
then
5723 Check_Size
(Expr
, U_Ent
, Size
, Biased
);
5725 -- The following errors are suppressed in ASIS mode to allow
5726 -- for different ASIS back ends or ASIS-based tools to query
5727 -- the illegal clause.
5732 elsif Is_Scalar_Type
(U_Ent
) then
5733 if Size
/= 8 and then Size
/= 16 and then Size
/= 32
5734 and then UI_Mod
(Size
, 64) /= 0
5737 ("Object_Size must be 8, 16, 32, or multiple of 64",
5741 elsif Size
mod 8 /= 0 then
5742 Error_Msg_N
("Object_Size must be a multiple of 8", Expr
);
5745 Set_Esize
(U_Ent
, Size
);
5746 Set_Has_Object_Size_Clause
(U_Ent
);
5747 Alignment_Check_For_Size_Change
(U_Ent
, Size
);
5755 when Attribute_Output
=>
5756 Analyze_Stream_TSS_Definition
(TSS_Stream_Output
);
5757 Set_Has_Specified_Stream_Output
(Ent
);
5763 when Attribute_Priority
=>
5765 -- Priority attribute definition clause not allowed except from
5766 -- aspect specification.
5768 if From_Aspect_Specification
(N
) then
5769 if not (Is_Concurrent_Type
(U_Ent
)
5770 or else Ekind
(U_Ent
) = E_Procedure
)
5773 ("Priority can only be defined for task and protected "
5776 elsif Duplicate_Clause
then
5780 -- The expression must be analyzed in the special manner
5781 -- described in "Handling of Default and Per-Object
5782 -- Expressions" in sem.ads.
5784 -- The visibility to the discriminants must be restored
5786 Push_Scope_And_Install_Discriminants
(U_Ent
);
5787 Preanalyze_Spec_Expression
(Expr
, Standard_Integer
);
5788 Uninstall_Discriminants_And_Pop_Scope
(U_Ent
);
5790 if not Is_OK_Static_Expression
(Expr
) then
5791 Check_Restriction
(Static_Priorities
, Expr
);
5797 ("attribute& cannot be set with definition clause", N
);
5804 when Attribute_Read
=>
5805 Analyze_Stream_TSS_Definition
(TSS_Stream_Read
);
5806 Set_Has_Specified_Stream_Read
(Ent
);
5808 --------------------------
5809 -- Scalar_Storage_Order --
5810 --------------------------
5812 -- Scalar_Storage_Order attribute definition clause
5814 when Attribute_Scalar_Storage_Order
=>
5815 if not (Is_Record_Type
(U_Ent
) or else Is_Array_Type
(U_Ent
)) then
5817 ("Scalar_Storage_Order can only be defined for record or "
5818 & "array type", Nam
);
5820 elsif Duplicate_Clause
then
5824 Analyze_And_Resolve
(Expr
, RTE
(RE_Bit_Order
));
5826 if Etype
(Expr
) = Any_Type
then
5829 elsif not Is_OK_Static_Expression
(Expr
) then
5830 Flag_Non_Static_Expr
5831 ("Scalar_Storage_Order requires static expression!", Expr
);
5833 elsif (Expr_Value
(Expr
) = 0) /= Bytes_Big_Endian
then
5835 -- Here for the case of a non-default (i.e. non-confirming)
5836 -- Scalar_Storage_Order attribute definition.
5838 if Support_Nondefault_SSO_On_Target
then
5839 Set_Reverse_Storage_Order
(Base_Type
(U_Ent
), True);
5842 ("non-default Scalar_Storage_Order not supported on "
5847 -- Clear SSO default indications since explicit setting of the
5848 -- order overrides the defaults.
5850 Set_SSO_Set_Low_By_Default
(Base_Type
(U_Ent
), False);
5851 Set_SSO_Set_High_By_Default
(Base_Type
(U_Ent
), False);
5854 --------------------------
5855 -- Secondary_Stack_Size --
5856 --------------------------
5858 when Attribute_Secondary_Stack_Size
=>
5860 -- Secondary_Stack_Size attribute definition clause not allowed
5861 -- except from aspect specification.
5863 if From_Aspect_Specification
(N
) then
5864 if not Is_Task_Type
(U_Ent
) then
5866 ("Secondary Stack Size can only be defined for task", Nam
);
5868 elsif Duplicate_Clause
then
5872 Check_Restriction
(No_Secondary_Stack
, Expr
);
5874 -- The expression must be analyzed in the special manner
5875 -- described in "Handling of Default and Per-Object
5876 -- Expressions" in sem.ads.
5878 -- The visibility to the discriminants must be restored
5880 Push_Scope_And_Install_Discriminants
(U_Ent
);
5881 Preanalyze_Spec_Expression
(Expr
, Any_Integer
);
5882 Uninstall_Discriminants_And_Pop_Scope
(U_Ent
);
5884 if not Is_OK_Static_Expression
(Expr
) then
5885 Check_Restriction
(Static_Storage_Size
, Expr
);
5891 ("attribute& cannot be set with definition clause", N
);
5898 -- Size attribute definition clause
5900 when Attribute_Size
=> Size
: declare
5901 Size
: constant Uint
:= Static_Integer
(Expr
);
5908 if Duplicate_Clause
then
5911 elsif not Is_Type
(U_Ent
)
5912 and then Ekind
(U_Ent
) /= E_Variable
5913 and then Ekind
(U_Ent
) /= E_Constant
5915 Error_Msg_N
("size cannot be given for &", Nam
);
5917 elsif Is_Array_Type
(U_Ent
)
5918 and then not Is_Constrained
(U_Ent
)
5921 ("size cannot be given for unconstrained array", Nam
);
5923 elsif Size
/= No_Uint
then
5924 if Is_Type
(U_Ent
) then
5927 Etyp
:= Etype
(U_Ent
);
5930 -- Check size, note that Gigi is in charge of checking that the
5931 -- size of an array or record type is OK. Also we do not check
5932 -- the size in the ordinary fixed-point case, since it is too
5933 -- early to do so (there may be subsequent small clause that
5934 -- affects the size). We can check the size if a small clause
5935 -- has already been given.
5937 if not Is_Ordinary_Fixed_Point_Type
(U_Ent
)
5938 or else Has_Small_Clause
(U_Ent
)
5940 Check_Size
(Expr
, Etyp
, Size
, Biased
);
5941 Set_Biased
(U_Ent
, N
, "size clause", Biased
);
5944 -- For types set RM_Size and Esize if possible
5946 if Is_Type
(U_Ent
) then
5947 Set_RM_Size
(U_Ent
, Size
);
5949 -- For elementary types, increase Object_Size to power of 2,
5950 -- but not less than a storage unit in any case (normally
5951 -- this means it will be byte addressable).
5953 -- For all other types, nothing else to do, we leave Esize
5954 -- (object size) unset, the back end will set it from the
5955 -- size and alignment in an appropriate manner.
5957 -- In both cases, we check whether the alignment must be
5958 -- reset in the wake of the size change.
5960 if Is_Elementary_Type
(U_Ent
) then
5961 if Size
<= System_Storage_Unit
then
5962 Init_Esize
(U_Ent
, System_Storage_Unit
);
5963 elsif Size
<= 16 then
5964 Init_Esize
(U_Ent
, 16);
5965 elsif Size
<= 32 then
5966 Init_Esize
(U_Ent
, 32);
5968 Set_Esize
(U_Ent
, (Size
+ 63) / 64 * 64);
5971 Alignment_Check_For_Size_Change
(U_Ent
, Esize
(U_Ent
));
5973 Alignment_Check_For_Size_Change
(U_Ent
, Size
);
5976 -- For objects, set Esize only
5979 -- The following error is suppressed in ASIS mode to allow
5980 -- for different ASIS back ends or ASIS-based tools to query
5981 -- the illegal clause.
5983 if Is_Elementary_Type
(Etyp
)
5984 and then Size
/= System_Storage_Unit
5985 and then Size
/= System_Storage_Unit
* 2
5986 and then Size
/= System_Storage_Unit
* 4
5987 and then Size
/= System_Storage_Unit
* 8
5988 and then not ASIS_Mode
5990 Error_Msg_Uint_1
:= UI_From_Int
(System_Storage_Unit
);
5991 Error_Msg_Uint_2
:= Error_Msg_Uint_1
* 8;
5993 ("size for primitive object must be a power of 2 in "
5994 & "the range ^-^", N
);
5997 Set_Esize
(U_Ent
, Size
);
6000 Set_Has_Size_Clause
(U_Ent
);
6008 -- Small attribute definition clause
6010 when Attribute_Small
=> Small
: declare
6011 Implicit_Base
: constant Entity_Id
:= Base_Type
(U_Ent
);
6015 Analyze_And_Resolve
(Expr
, Any_Real
);
6017 if Etype
(Expr
) = Any_Type
then
6020 elsif not Is_OK_Static_Expression
(Expr
) then
6021 Flag_Non_Static_Expr
6022 ("small requires static expression!", Expr
);
6026 Small
:= Expr_Value_R
(Expr
);
6028 if Small
<= Ureal_0
then
6029 Error_Msg_N
("small value must be greater than zero", Expr
);
6035 if not Is_Ordinary_Fixed_Point_Type
(U_Ent
) then
6037 ("small requires an ordinary fixed point type", Nam
);
6039 elsif Has_Small_Clause
(U_Ent
) then
6040 Error_Msg_N
("small already given for &", Nam
);
6042 elsif Small
> Delta_Value
(U_Ent
) then
6044 ("small value must not be greater than delta value", Nam
);
6047 Set_Small_Value
(U_Ent
, Small
);
6048 Set_Small_Value
(Implicit_Base
, Small
);
6049 Set_Has_Small_Clause
(U_Ent
);
6050 Set_Has_Small_Clause
(Implicit_Base
);
6051 Set_Has_Non_Standard_Rep
(Implicit_Base
);
6059 -- Storage_Pool attribute definition clause
6061 when Attribute_Simple_Storage_Pool
6062 | Attribute_Storage_Pool
6064 Storage_Pool
: declare
6069 if Ekind
(U_Ent
) = E_Access_Subprogram_Type
then
6071 ("storage pool cannot be given for access-to-subprogram type",
6075 elsif not Ekind_In
(U_Ent
, E_Access_Type
, E_General_Access_Type
)
6078 ("storage pool can only be given for access types", Nam
);
6081 elsif Is_Derived_Type
(U_Ent
) then
6083 ("storage pool cannot be given for a derived access type",
6086 elsif Duplicate_Clause
then
6089 elsif Present
(Associated_Storage_Pool
(U_Ent
)) then
6090 Error_Msg_N
("storage pool already given for &", Nam
);
6094 -- Check for Storage_Size previously given
6097 SS
: constant Node_Id
:=
6098 Get_Attribute_Definition_Clause
6099 (U_Ent
, Attribute_Storage_Size
);
6101 if Present
(SS
) then
6102 Check_Pool_Size_Clash
(U_Ent
, N
, SS
);
6106 -- Storage_Pool case
6108 if Id
= Attribute_Storage_Pool
then
6110 (Expr
, Class_Wide_Type
(RTE
(RE_Root_Storage_Pool
)));
6112 -- In the Simple_Storage_Pool case, we allow a variable of any
6113 -- simple storage pool type, so we Resolve without imposing an
6117 Analyze_And_Resolve
(Expr
);
6119 if not Present
(Get_Rep_Pragma
6120 (Etype
(Expr
), Name_Simple_Storage_Pool_Type
))
6123 ("expression must be of a simple storage pool type", Expr
);
6127 if not Denotes_Variable
(Expr
) then
6128 Error_Msg_N
("storage pool must be a variable", Expr
);
6132 if Nkind
(Expr
) = N_Type_Conversion
then
6133 T
:= Etype
(Expression
(Expr
));
6138 -- The Stack_Bounded_Pool is used internally for implementing
6139 -- access types with a Storage_Size. Since it only work properly
6140 -- when used on one specific type, we need to check that it is not
6141 -- hijacked improperly:
6143 -- type T is access Integer;
6144 -- for T'Storage_Size use n;
6145 -- type Q is access Float;
6146 -- for Q'Storage_Size use T'Storage_Size; -- incorrect
6148 if RTE_Available
(RE_Stack_Bounded_Pool
)
6149 and then Base_Type
(T
) = RTE
(RE_Stack_Bounded_Pool
)
6151 Error_Msg_N
("non-shareable internal Pool", Expr
);
6155 -- If the argument is a name that is not an entity name, then
6156 -- we construct a renaming operation to define an entity of
6157 -- type storage pool.
6159 if not Is_Entity_Name
(Expr
)
6160 and then Is_Object_Reference
(Expr
)
6162 Pool
:= Make_Temporary
(Loc
, 'P', Expr
);
6165 Rnode
: constant Node_Id
:=
6166 Make_Object_Renaming_Declaration
(Loc
,
6167 Defining_Identifier
=> Pool
,
6169 New_Occurrence_Of
(Etype
(Expr
), Loc
),
6173 -- If the attribute definition clause comes from an aspect
6174 -- clause, then insert the renaming before the associated
6175 -- entity's declaration, since the attribute clause has
6176 -- not yet been appended to the declaration list.
6178 if From_Aspect_Specification
(N
) then
6179 Insert_Before
(Parent
(Entity
(N
)), Rnode
);
6181 Insert_Before
(N
, Rnode
);
6185 Set_Associated_Storage_Pool
(U_Ent
, Pool
);
6188 elsif Is_Entity_Name
(Expr
) then
6189 Pool
:= Entity
(Expr
);
6191 -- If pool is a renamed object, get original one. This can
6192 -- happen with an explicit renaming, and within instances.
6194 while Present
(Renamed_Object
(Pool
))
6195 and then Is_Entity_Name
(Renamed_Object
(Pool
))
6197 Pool
:= Entity
(Renamed_Object
(Pool
));
6200 if Present
(Renamed_Object
(Pool
))
6201 and then Nkind
(Renamed_Object
(Pool
)) = N_Type_Conversion
6202 and then Is_Entity_Name
(Expression
(Renamed_Object
(Pool
)))
6204 Pool
:= Entity
(Expression
(Renamed_Object
(Pool
)));
6207 Set_Associated_Storage_Pool
(U_Ent
, Pool
);
6209 elsif Nkind
(Expr
) = N_Type_Conversion
6210 and then Is_Entity_Name
(Expression
(Expr
))
6211 and then Nkind
(Original_Node
(Expr
)) = N_Attribute_Reference
6213 Pool
:= Entity
(Expression
(Expr
));
6214 Set_Associated_Storage_Pool
(U_Ent
, Pool
);
6217 Error_Msg_N
("incorrect reference to a Storage Pool", Expr
);
6226 -- Storage_Size attribute definition clause
6228 when Attribute_Storage_Size
=> Storage_Size
: declare
6229 Btype
: constant Entity_Id
:= Base_Type
(U_Ent
);
6232 if Is_Task_Type
(U_Ent
) then
6234 -- Check obsolescent (but never obsolescent if from aspect)
6236 if not From_Aspect_Specification
(N
) then
6237 Check_Restriction
(No_Obsolescent_Features
, N
);
6239 if Warn_On_Obsolescent_Feature
then
6241 ("?j?storage size clause for task is an obsolescent "
6242 & "feature (RM J.9)", N
);
6243 Error_Msg_N
("\?j?use Storage_Size pragma instead", N
);
6250 if not Is_Access_Type
(U_Ent
)
6251 and then Ekind
(U_Ent
) /= E_Task_Type
6253 Error_Msg_N
("storage size cannot be given for &", Nam
);
6255 elsif Is_Access_Type
(U_Ent
) and Is_Derived_Type
(U_Ent
) then
6257 ("storage size cannot be given for a derived access type",
6260 elsif Duplicate_Clause
then
6264 Analyze_And_Resolve
(Expr
, Any_Integer
);
6266 if Is_Access_Type
(U_Ent
) then
6268 -- Check for Storage_Pool previously given
6271 SP
: constant Node_Id
:=
6272 Get_Attribute_Definition_Clause
6273 (U_Ent
, Attribute_Storage_Pool
);
6276 if Present
(SP
) then
6277 Check_Pool_Size_Clash
(U_Ent
, SP
, N
);
6281 -- Special case of for x'Storage_Size use 0
6283 if Is_OK_Static_Expression
(Expr
)
6284 and then Expr_Value
(Expr
) = 0
6286 Set_No_Pool_Assigned
(Btype
);
6290 Set_Has_Storage_Size_Clause
(Btype
);
6298 when Attribute_Stream_Size
=> Stream_Size
: declare
6299 Size
: constant Uint
:= Static_Integer
(Expr
);
6302 if Ada_Version
<= Ada_95
then
6303 Check_Restriction
(No_Implementation_Attributes
, N
);
6306 if Duplicate_Clause
then
6309 elsif Is_Elementary_Type
(U_Ent
) then
6311 -- The following errors are suppressed in ASIS mode to allow
6312 -- for different ASIS back ends or ASIS-based tools to query
6313 -- the illegal clause.
6318 elsif Size
/= System_Storage_Unit
6319 and then Size
/= System_Storage_Unit
* 2
6320 and then Size
/= System_Storage_Unit
* 4
6321 and then Size
/= System_Storage_Unit
* 8
6323 Error_Msg_Uint_1
:= UI_From_Int
(System_Storage_Unit
);
6325 ("stream size for elementary type must be a power of 2 "
6326 & "and at least ^", N
);
6328 elsif RM_Size
(U_Ent
) > Size
then
6329 Error_Msg_Uint_1
:= RM_Size
(U_Ent
);
6331 ("stream size for elementary type must be a power of 2 "
6332 & "and at least ^", N
);
6335 Set_Has_Stream_Size_Clause
(U_Ent
);
6338 Error_Msg_N
("Stream_Size cannot be given for &", Nam
);
6346 -- Value_Size attribute definition clause
6348 when Attribute_Value_Size
=> Value_Size
: declare
6349 Size
: constant Uint
:= Static_Integer
(Expr
);
6353 if not Is_Type
(U_Ent
) then
6354 Error_Msg_N
("Value_Size cannot be given for &", Nam
);
6356 elsif Duplicate_Clause
then
6359 elsif Is_Array_Type
(U_Ent
)
6360 and then not Is_Constrained
(U_Ent
)
6363 ("Value_Size cannot be given for unconstrained array", Nam
);
6366 if Is_Elementary_Type
(U_Ent
) then
6367 Check_Size
(Expr
, U_Ent
, Size
, Biased
);
6368 Set_Biased
(U_Ent
, N
, "value size clause", Biased
);
6371 Set_RM_Size
(U_Ent
, Size
);
6375 -----------------------
6376 -- Variable_Indexing --
6377 -----------------------
6379 when Attribute_Variable_Indexing
=>
6380 Check_Indexing_Functions
;
6386 when Attribute_Write
=>
6387 Analyze_Stream_TSS_Definition
(TSS_Stream_Write
);
6388 Set_Has_Specified_Stream_Write
(Ent
);
6390 -- All other attributes cannot be set
6394 ("attribute& cannot be set with definition clause", N
);
6397 -- The test for the type being frozen must be performed after any
6398 -- expression the clause has been analyzed since the expression itself
6399 -- might cause freezing that makes the clause illegal.
6401 if Rep_Item_Too_Late
(U_Ent
, N
, FOnly
) then
6404 end Analyze_Attribute_Definition_Clause
;
6406 ----------------------------
6407 -- Analyze_Code_Statement --
6408 ----------------------------
6410 procedure Analyze_Code_Statement
(N
: Node_Id
) is
6411 HSS
: constant Node_Id
:= Parent
(N
);
6412 SBody
: constant Node_Id
:= Parent
(HSS
);
6413 Subp
: constant Entity_Id
:= Current_Scope
;
6420 -- Accept foreign code statements for CodePeer. The analysis is skipped
6421 -- to avoid rejecting unrecognized constructs.
6423 if CodePeer_Mode
then
6428 -- Analyze and check we get right type, note that this implements the
6429 -- requirement (RM 13.8(1)) that Machine_Code be with'ed, since that is
6430 -- the only way that Asm_Insn could possibly be visible.
6432 Analyze_And_Resolve
(Expression
(N
));
6434 if Etype
(Expression
(N
)) = Any_Type
then
6436 elsif Etype
(Expression
(N
)) /= RTE
(RE_Asm_Insn
) then
6437 Error_Msg_N
("incorrect type for code statement", N
);
6441 Check_Code_Statement
(N
);
6443 -- Make sure we appear in the handled statement sequence of a subprogram
6446 if Nkind
(HSS
) /= N_Handled_Sequence_Of_Statements
6447 or else Nkind
(SBody
) /= N_Subprogram_Body
6450 ("code statement can only appear in body of subprogram", N
);
6454 -- Do remaining checks (RM 13.8(3)) if not already done
6456 if not Is_Machine_Code_Subprogram
(Subp
) then
6457 Set_Is_Machine_Code_Subprogram
(Subp
);
6459 -- No exception handlers allowed
6461 if Present
(Exception_Handlers
(HSS
)) then
6463 ("exception handlers not permitted in machine code subprogram",
6464 First
(Exception_Handlers
(HSS
)));
6467 -- No declarations other than use clauses and pragmas (we allow
6468 -- certain internally generated declarations as well).
6470 Decl
:= First
(Declarations
(SBody
));
6471 while Present
(Decl
) loop
6472 DeclO
:= Original_Node
(Decl
);
6473 if Comes_From_Source
(DeclO
)
6474 and not Nkind_In
(DeclO
, N_Pragma
,
6475 N_Use_Package_Clause
,
6477 N_Implicit_Label_Declaration
)
6480 ("this declaration not allowed in machine code subprogram",
6487 -- No statements other than code statements, pragmas, and labels.
6488 -- Again we allow certain internally generated statements.
6490 -- In Ada 2012, qualified expressions are names, and the code
6491 -- statement is initially parsed as a procedure call.
6493 Stmt
:= First
(Statements
(HSS
));
6494 while Present
(Stmt
) loop
6495 StmtO
:= Original_Node
(Stmt
);
6497 -- A procedure call transformed into a code statement is OK
6499 if Ada_Version
>= Ada_2012
6500 and then Nkind
(StmtO
) = N_Procedure_Call_Statement
6501 and then Nkind
(Name
(StmtO
)) = N_Qualified_Expression
6505 elsif Comes_From_Source
(StmtO
)
6506 and then not Nkind_In
(StmtO
, N_Pragma
,
6511 ("this statement is not allowed in machine code subprogram",
6518 end Analyze_Code_Statement
;
6520 -----------------------------------------------
6521 -- Analyze_Enumeration_Representation_Clause --
6522 -----------------------------------------------
6524 procedure Analyze_Enumeration_Representation_Clause
(N
: Node_Id
) is
6525 Ident
: constant Node_Id
:= Identifier
(N
);
6526 Aggr
: constant Node_Id
:= Array_Aggregate
(N
);
6527 Enumtype
: Entity_Id
;
6534 Err
: Boolean := False;
6535 -- Set True to avoid cascade errors and crashes on incorrect source code
6537 Lo
: constant Uint
:= Expr_Value
(Type_Low_Bound
(Universal_Integer
));
6538 Hi
: constant Uint
:= Expr_Value
(Type_High_Bound
(Universal_Integer
));
6539 -- Allowed range of universal integer (= allowed range of enum lit vals)
6543 -- Minimum and maximum values of entries
6545 Max_Node
: Node_Id
:= Empty
; -- init to avoid warning
6546 -- Pointer to node for literal providing max value
6549 if Ignore_Rep_Clauses
then
6550 Kill_Rep_Clause
(N
);
6554 -- Ignore enumeration rep clauses by default in CodePeer mode,
6555 -- unless -gnatd.I is specified, as a work around for potential false
6556 -- positive messages.
6558 if CodePeer_Mode
and not Debug_Flag_Dot_II
then
6562 -- First some basic error checks
6565 Enumtype
:= Entity
(Ident
);
6567 if Enumtype
= Any_Type
6568 or else Rep_Item_Too_Early
(Enumtype
, N
)
6572 Enumtype
:= Underlying_Type
(Enumtype
);
6575 if not Is_Enumeration_Type
(Enumtype
) then
6577 ("enumeration type required, found}",
6578 Ident
, First_Subtype
(Enumtype
));
6582 -- Ignore rep clause on generic actual type. This will already have
6583 -- been flagged on the template as an error, and this is the safest
6584 -- way to ensure we don't get a junk cascaded message in the instance.
6586 if Is_Generic_Actual_Type
(Enumtype
) then
6589 -- Type must be in current scope
6591 elsif Scope
(Enumtype
) /= Current_Scope
then
6592 Error_Msg_N
("type must be declared in this scope", Ident
);
6595 -- Type must be a first subtype
6597 elsif not Is_First_Subtype
(Enumtype
) then
6598 Error_Msg_N
("cannot give enumeration rep clause for subtype", N
);
6601 -- Ignore duplicate rep clause
6603 elsif Has_Enumeration_Rep_Clause
(Enumtype
) then
6604 Error_Msg_N
("duplicate enumeration rep clause ignored", N
);
6607 -- Don't allow rep clause for standard [wide_[wide_]]character
6609 elsif Is_Standard_Character_Type
(Enumtype
) then
6610 Error_Msg_N
("enumeration rep clause not allowed for this type", N
);
6613 -- Check that the expression is a proper aggregate (no parentheses)
6615 elsif Paren_Count
(Aggr
) /= 0 then
6617 ("extra parentheses surrounding aggregate not allowed",
6621 -- All tests passed, so set rep clause in place
6624 Set_Has_Enumeration_Rep_Clause
(Enumtype
);
6625 Set_Has_Enumeration_Rep_Clause
(Base_Type
(Enumtype
));
6628 -- Now we process the aggregate. Note that we don't use the normal
6629 -- aggregate code for this purpose, because we don't want any of the
6630 -- normal expansion activities, and a number of special semantic
6631 -- rules apply (including the component type being any integer type)
6633 Elit
:= First_Literal
(Enumtype
);
6635 -- First the positional entries if any
6637 if Present
(Expressions
(Aggr
)) then
6638 Expr
:= First
(Expressions
(Aggr
));
6639 while Present
(Expr
) loop
6641 Error_Msg_N
("too many entries in aggregate", Expr
);
6645 Val
:= Static_Integer
(Expr
);
6647 -- Err signals that we found some incorrect entries processing
6648 -- the list. The final checks for completeness and ordering are
6649 -- skipped in this case.
6651 if Val
= No_Uint
then
6654 elsif Val
< Lo
or else Hi
< Val
then
6655 Error_Msg_N
("value outside permitted range", Expr
);
6659 Set_Enumeration_Rep
(Elit
, Val
);
6660 Set_Enumeration_Rep_Expr
(Elit
, Expr
);
6666 -- Now process the named entries if present
6668 if Present
(Component_Associations
(Aggr
)) then
6669 Assoc
:= First
(Component_Associations
(Aggr
));
6670 while Present
(Assoc
) loop
6671 Choice
:= First
(Choices
(Assoc
));
6673 if Present
(Next
(Choice
)) then
6675 ("multiple choice not allowed here", Next
(Choice
));
6679 if Nkind
(Choice
) = N_Others_Choice
then
6680 Error_Msg_N
("others choice not allowed here", Choice
);
6683 elsif Nkind
(Choice
) = N_Range
then
6685 -- ??? should allow zero/one element range here
6687 Error_Msg_N
("range not allowed here", Choice
);
6691 Analyze_And_Resolve
(Choice
, Enumtype
);
6693 if Error_Posted
(Choice
) then
6698 if Is_Entity_Name
(Choice
)
6699 and then Is_Type
(Entity
(Choice
))
6701 Error_Msg_N
("subtype name not allowed here", Choice
);
6704 -- ??? should allow static subtype with zero/one entry
6706 elsif Etype
(Choice
) = Base_Type
(Enumtype
) then
6707 if not Is_OK_Static_Expression
(Choice
) then
6708 Flag_Non_Static_Expr
6709 ("non-static expression used for choice!", Choice
);
6713 Elit
:= Expr_Value_E
(Choice
);
6715 if Present
(Enumeration_Rep_Expr
(Elit
)) then
6717 Sloc
(Enumeration_Rep_Expr
(Elit
));
6719 ("representation for& previously given#",
6724 Set_Enumeration_Rep_Expr
(Elit
, Expression
(Assoc
));
6726 Expr
:= Expression
(Assoc
);
6727 Val
:= Static_Integer
(Expr
);
6729 if Val
= No_Uint
then
6732 elsif Val
< Lo
or else Hi
< Val
then
6733 Error_Msg_N
("value outside permitted range", Expr
);
6737 Set_Enumeration_Rep
(Elit
, Val
);
6747 -- Aggregate is fully processed. Now we check that a full set of
6748 -- representations was given, and that they are in range and in order.
6749 -- These checks are only done if no other errors occurred.
6755 Elit
:= First_Literal
(Enumtype
);
6756 while Present
(Elit
) loop
6757 if No
(Enumeration_Rep_Expr
(Elit
)) then
6758 Error_Msg_NE
("missing representation for&!", N
, Elit
);
6761 Val
:= Enumeration_Rep
(Elit
);
6763 if Min
= No_Uint
then
6767 if Val
/= No_Uint
then
6768 if Max
/= No_Uint
and then Val
<= Max
then
6770 ("enumeration value for& not ordered!",
6771 Enumeration_Rep_Expr
(Elit
), Elit
);
6774 Max_Node
:= Enumeration_Rep_Expr
(Elit
);
6778 -- If there is at least one literal whose representation is not
6779 -- equal to the Pos value, then note that this enumeration type
6780 -- has a non-standard representation.
6782 if Val
/= Enumeration_Pos
(Elit
) then
6783 Set_Has_Non_Standard_Rep
(Base_Type
(Enumtype
));
6790 -- Now set proper size information
6793 Minsize
: Uint
:= UI_From_Int
(Minimum_Size
(Enumtype
));
6796 if Has_Size_Clause
(Enumtype
) then
6798 -- All OK, if size is OK now
6800 if RM_Size
(Enumtype
) >= Minsize
then
6804 -- Try if we can get by with biasing
6807 UI_From_Int
(Minimum_Size
(Enumtype
, Biased
=> True));
6809 -- Error message if even biasing does not work
6811 if RM_Size
(Enumtype
) < Minsize
then
6812 Error_Msg_Uint_1
:= RM_Size
(Enumtype
);
6813 Error_Msg_Uint_2
:= Max
;
6815 ("previously given size (^) is too small "
6816 & "for this value (^)", Max_Node
);
6818 -- If biasing worked, indicate that we now have biased rep
6822 (Enumtype
, Size_Clause
(Enumtype
), "size clause");
6827 Set_RM_Size
(Enumtype
, Minsize
);
6828 Set_Enum_Esize
(Enumtype
);
6831 Set_RM_Size
(Base_Type
(Enumtype
), RM_Size
(Enumtype
));
6832 Set_Esize
(Base_Type
(Enumtype
), Esize
(Enumtype
));
6833 Set_Alignment
(Base_Type
(Enumtype
), Alignment
(Enumtype
));
6837 -- We repeat the too late test in case it froze itself
6839 if Rep_Item_Too_Late
(Enumtype
, N
) then
6842 end Analyze_Enumeration_Representation_Clause
;
6844 ----------------------------
6845 -- Analyze_Free_Statement --
6846 ----------------------------
6848 procedure Analyze_Free_Statement
(N
: Node_Id
) is
6850 Analyze
(Expression
(N
));
6851 end Analyze_Free_Statement
;
6853 ---------------------------
6854 -- Analyze_Freeze_Entity --
6855 ---------------------------
6857 procedure Analyze_Freeze_Entity
(N
: Node_Id
) is
6859 Freeze_Entity_Checks
(N
);
6860 end Analyze_Freeze_Entity
;
6862 -----------------------------------
6863 -- Analyze_Freeze_Generic_Entity --
6864 -----------------------------------
6866 procedure Analyze_Freeze_Generic_Entity
(N
: Node_Id
) is
6867 E
: constant Entity_Id
:= Entity
(N
);
6870 if not Is_Frozen
(E
) and then Has_Delayed_Aspects
(E
) then
6871 Analyze_Aspects_At_Freeze_Point
(E
);
6874 Freeze_Entity_Checks
(N
);
6875 end Analyze_Freeze_Generic_Entity
;
6877 ------------------------------------------
6878 -- Analyze_Record_Representation_Clause --
6879 ------------------------------------------
6881 -- Note: we check as much as we can here, but we can't do any checks
6882 -- based on the position values (e.g. overlap checks) until freeze time
6883 -- because especially in Ada 2005 (machine scalar mode), the processing
6884 -- for non-standard bit order can substantially change the positions.
6885 -- See procedure Check_Record_Representation_Clause (called from Freeze)
6886 -- for the remainder of this processing.
6888 procedure Analyze_Record_Representation_Clause
(N
: Node_Id
) is
6889 Ident
: constant Node_Id
:= Identifier
(N
);
6894 Hbit
: Uint
:= Uint_0
;
6898 Rectype
: Entity_Id
;
6901 function Is_Inherited
(Comp
: Entity_Id
) return Boolean;
6902 -- True if Comp is an inherited component in a record extension
6908 function Is_Inherited
(Comp
: Entity_Id
) return Boolean is
6909 Comp_Base
: Entity_Id
;
6912 if Ekind
(Rectype
) = E_Record_Subtype
then
6913 Comp_Base
:= Original_Record_Component
(Comp
);
6918 return Comp_Base
/= Original_Record_Component
(Comp_Base
);
6923 Is_Record_Extension
: Boolean;
6924 -- True if Rectype is a record extension
6926 CR_Pragma
: Node_Id
:= Empty
;
6927 -- Points to N_Pragma node if Complete_Representation pragma present
6929 -- Start of processing for Analyze_Record_Representation_Clause
6932 if Ignore_Rep_Clauses
then
6933 Kill_Rep_Clause
(N
);
6938 Rectype
:= Entity
(Ident
);
6940 if Rectype
= Any_Type
or else Rep_Item_Too_Early
(Rectype
, N
) then
6943 Rectype
:= Underlying_Type
(Rectype
);
6946 -- First some basic error checks
6948 if not Is_Record_Type
(Rectype
) then
6950 ("record type required, found}", Ident
, First_Subtype
(Rectype
));
6953 elsif Scope
(Rectype
) /= Current_Scope
then
6954 Error_Msg_N
("type must be declared in this scope", N
);
6957 elsif not Is_First_Subtype
(Rectype
) then
6958 Error_Msg_N
("cannot give record rep clause for subtype", N
);
6961 elsif Has_Record_Rep_Clause
(Rectype
) then
6962 Error_Msg_N
("duplicate record rep clause ignored", N
);
6965 elsif Rep_Item_Too_Late
(Rectype
, N
) then
6969 -- We know we have a first subtype, now possibly go to the anonymous
6970 -- base type to determine whether Rectype is a record extension.
6972 Recdef
:= Type_Definition
(Declaration_Node
(Base_Type
(Rectype
)));
6973 Is_Record_Extension
:=
6974 Nkind
(Recdef
) = N_Derived_Type_Definition
6975 and then Present
(Record_Extension_Part
(Recdef
));
6977 if Present
(Mod_Clause
(N
)) then
6979 Loc
: constant Source_Ptr
:= Sloc
(N
);
6980 M
: constant Node_Id
:= Mod_Clause
(N
);
6981 P
: constant List_Id
:= Pragmas_Before
(M
);
6985 pragma Warnings
(Off
, Mod_Val
);
6988 Check_Restriction
(No_Obsolescent_Features
, Mod_Clause
(N
));
6990 if Warn_On_Obsolescent_Feature
then
6992 ("?j?mod clause is an obsolescent feature (RM J.8)", N
);
6994 ("\?j?use alignment attribute definition clause instead", N
);
7001 -- In ASIS_Mode mode, expansion is disabled, but we must convert
7002 -- the Mod clause into an alignment clause anyway, so that the
7003 -- back end can compute and back-annotate properly the size and
7004 -- alignment of types that may include this record.
7006 -- This seems dubious, this destroys the source tree in a manner
7007 -- not detectable by ASIS ???
7009 if Operating_Mode
= Check_Semantics
and then ASIS_Mode
then
7011 Make_Attribute_Definition_Clause
(Loc
,
7012 Name
=> New_Occurrence_Of
(Base_Type
(Rectype
), Loc
),
7013 Chars
=> Name_Alignment
,
7014 Expression
=> Relocate_Node
(Expression
(M
)));
7016 Set_From_At_Mod
(AtM_Nod
);
7017 Insert_After
(N
, AtM_Nod
);
7018 Mod_Val
:= Get_Alignment_Value
(Expression
(AtM_Nod
));
7019 Set_Mod_Clause
(N
, Empty
);
7022 -- Get the alignment value to perform error checking
7024 Mod_Val
:= Get_Alignment_Value
(Expression
(M
));
7029 -- For untagged types, clear any existing component clauses for the
7030 -- type. If the type is derived, this is what allows us to override
7031 -- a rep clause for the parent. For type extensions, the representation
7032 -- of the inherited components is inherited, so we want to keep previous
7033 -- component clauses for completeness.
7035 if not Is_Tagged_Type
(Rectype
) then
7036 Comp
:= First_Component_Or_Discriminant
(Rectype
);
7037 while Present
(Comp
) loop
7038 Set_Component_Clause
(Comp
, Empty
);
7039 Next_Component_Or_Discriminant
(Comp
);
7043 -- All done if no component clauses
7045 CC
:= First
(Component_Clauses
(N
));
7051 -- A representation like this applies to the base type
7053 Set_Has_Record_Rep_Clause
(Base_Type
(Rectype
));
7054 Set_Has_Non_Standard_Rep
(Base_Type
(Rectype
));
7055 Set_Has_Specified_Layout
(Base_Type
(Rectype
));
7057 -- Process the component clauses
7059 while Present
(CC
) loop
7063 if Nkind
(CC
) = N_Pragma
then
7066 -- The only pragma of interest is Complete_Representation
7068 if Pragma_Name
(CC
) = Name_Complete_Representation
then
7072 -- Processing for real component clause
7075 Posit
:= Static_Integer
(Position
(CC
));
7076 Fbit
:= Static_Integer
(First_Bit
(CC
));
7077 Lbit
:= Static_Integer
(Last_Bit
(CC
));
7080 and then Fbit
/= No_Uint
7081 and then Lbit
/= No_Uint
7084 Error_Msg_N
("position cannot be negative", Position
(CC
));
7087 Error_Msg_N
("first bit cannot be negative", First_Bit
(CC
));
7089 -- The Last_Bit specified in a component clause must not be
7090 -- less than the First_Bit minus one (RM-13.5.1(10)).
7092 elsif Lbit
< Fbit
- 1 then
7094 ("last bit cannot be less than first bit minus one",
7097 -- Values look OK, so find the corresponding record component
7098 -- Even though the syntax allows an attribute reference for
7099 -- implementation-defined components, GNAT does not allow the
7100 -- tag to get an explicit position.
7102 elsif Nkind
(Component_Name
(CC
)) = N_Attribute_Reference
then
7103 if Attribute_Name
(Component_Name
(CC
)) = Name_Tag
then
7104 Error_Msg_N
("position of tag cannot be specified", CC
);
7106 Error_Msg_N
("illegal component name", CC
);
7110 Comp
:= First_Entity
(Rectype
);
7111 while Present
(Comp
) loop
7112 exit when Chars
(Comp
) = Chars
(Component_Name
(CC
));
7118 -- Maybe component of base type that is absent from
7119 -- statically constrained first subtype.
7121 Comp
:= First_Entity
(Base_Type
(Rectype
));
7122 while Present
(Comp
) loop
7123 exit when Chars
(Comp
) = Chars
(Component_Name
(CC
));
7130 ("component clause is for non-existent field", CC
);
7132 -- Ada 2012 (AI05-0026): Any name that denotes a
7133 -- discriminant of an object of an unchecked union type
7134 -- shall not occur within a record_representation_clause.
7136 -- The general restriction of using record rep clauses on
7137 -- Unchecked_Union types has now been lifted. Since it is
7138 -- possible to introduce a record rep clause which mentions
7139 -- the discriminant of an Unchecked_Union in non-Ada 2012
7140 -- code, this check is applied to all versions of the
7143 elsif Ekind
(Comp
) = E_Discriminant
7144 and then Is_Unchecked_Union
(Rectype
)
7147 ("cannot reference discriminant of unchecked union",
7148 Component_Name
(CC
));
7150 elsif Is_Record_Extension
and then Is_Inherited
(Comp
) then
7152 ("component clause not allowed for inherited "
7153 & "component&", CC
, Comp
);
7155 elsif Present
(Component_Clause
(Comp
)) then
7157 -- Diagnose duplicate rep clause, or check consistency
7158 -- if this is an inherited component. In a double fault,
7159 -- there may be a duplicate inconsistent clause for an
7160 -- inherited component.
7162 if Scope
(Original_Record_Component
(Comp
)) = Rectype
7163 or else Parent
(Component_Clause
(Comp
)) = N
7165 Error_Msg_Sloc
:= Sloc
(Component_Clause
(Comp
));
7166 Error_Msg_N
("component clause previously given#", CC
);
7170 Rep1
: constant Node_Id
:= Component_Clause
(Comp
);
7172 if Intval
(Position
(Rep1
)) /=
7173 Intval
(Position
(CC
))
7174 or else Intval
(First_Bit
(Rep1
)) /=
7175 Intval
(First_Bit
(CC
))
7176 or else Intval
(Last_Bit
(Rep1
)) /=
7177 Intval
(Last_Bit
(CC
))
7180 ("component clause inconsistent with "
7181 & "representation of ancestor", CC
);
7183 elsif Warn_On_Redundant_Constructs
then
7185 ("?r?redundant confirming component clause "
7186 & "for component!", CC
);
7191 -- Normal case where this is the first component clause we
7192 -- have seen for this entity, so set it up properly.
7195 -- Make reference for field in record rep clause and set
7196 -- appropriate entity field in the field identifier.
7199 (Comp
, Component_Name
(CC
), Set_Ref
=> False);
7200 Set_Entity
(Component_Name
(CC
), Comp
);
7202 -- Update Fbit and Lbit to the actual bit number
7204 Fbit
:= Fbit
+ UI_From_Int
(SSU
) * Posit
;
7205 Lbit
:= Lbit
+ UI_From_Int
(SSU
) * Posit
;
7207 if Has_Size_Clause
(Rectype
)
7208 and then RM_Size
(Rectype
) <= Lbit
7211 ("bit number out of range of specified size",
7214 Set_Component_Clause
(Comp
, CC
);
7215 Set_Component_Bit_Offset
(Comp
, Fbit
);
7216 Set_Esize
(Comp
, 1 + (Lbit
- Fbit
));
7217 Set_Normalized_First_Bit
(Comp
, Fbit
mod SSU
);
7218 Set_Normalized_Position
(Comp
, Fbit
/ SSU
);
7220 if Warn_On_Overridden_Size
7221 and then Has_Size_Clause
(Etype
(Comp
))
7222 and then RM_Size
(Etype
(Comp
)) /= Esize
(Comp
)
7225 ("?S?component size overrides size clause for&",
7226 Component_Name
(CC
), Etype
(Comp
));
7229 -- This information is also set in the corresponding
7230 -- component of the base type, found by accessing the
7231 -- Original_Record_Component link if it is present.
7233 Ocomp
:= Original_Record_Component
(Comp
);
7240 (Component_Name
(CC
),
7246 (Comp
, First_Node
(CC
), "component clause", Biased
);
7248 if Present
(Ocomp
) then
7249 Set_Component_Clause
(Ocomp
, CC
);
7250 Set_Component_Bit_Offset
(Ocomp
, Fbit
);
7251 Set_Normalized_First_Bit
(Ocomp
, Fbit
mod SSU
);
7252 Set_Normalized_Position
(Ocomp
, Fbit
/ SSU
);
7253 Set_Esize
(Ocomp
, 1 + (Lbit
- Fbit
));
7255 Set_Normalized_Position_Max
7256 (Ocomp
, Normalized_Position
(Ocomp
));
7258 -- Note: we don't use Set_Biased here, because we
7259 -- already gave a warning above if needed, and we
7260 -- would get a duplicate for the same name here.
7262 Set_Has_Biased_Representation
7263 (Ocomp
, Has_Biased_Representation
(Comp
));
7266 if Esize
(Comp
) < 0 then
7267 Error_Msg_N
("component size is negative", CC
);
7278 -- Check missing components if Complete_Representation pragma appeared
7280 if Present
(CR_Pragma
) then
7281 Comp
:= First_Component_Or_Discriminant
(Rectype
);
7282 while Present
(Comp
) loop
7283 if No
(Component_Clause
(Comp
)) then
7285 ("missing component clause for &", CR_Pragma
, Comp
);
7288 Next_Component_Or_Discriminant
(Comp
);
7291 -- Give missing components warning if required
7293 elsif Warn_On_Unrepped_Components
then
7295 Num_Repped_Components
: Nat
:= 0;
7296 Num_Unrepped_Components
: Nat
:= 0;
7299 -- First count number of repped and unrepped components
7301 Comp
:= First_Component_Or_Discriminant
(Rectype
);
7302 while Present
(Comp
) loop
7303 if Present
(Component_Clause
(Comp
)) then
7304 Num_Repped_Components
:= Num_Repped_Components
+ 1;
7306 Num_Unrepped_Components
:= Num_Unrepped_Components
+ 1;
7309 Next_Component_Or_Discriminant
(Comp
);
7312 -- We are only interested in the case where there is at least one
7313 -- unrepped component, and at least half the components have rep
7314 -- clauses. We figure that if less than half have them, then the
7315 -- partial rep clause is really intentional. If the component
7316 -- type has no underlying type set at this point (as for a generic
7317 -- formal type), we don't know enough to give a warning on the
7320 if Num_Unrepped_Components
> 0
7321 and then Num_Unrepped_Components
< Num_Repped_Components
7323 Comp
:= First_Component_Or_Discriminant
(Rectype
);
7324 while Present
(Comp
) loop
7325 if No
(Component_Clause
(Comp
))
7326 and then Comes_From_Source
(Comp
)
7327 and then Present
(Underlying_Type
(Etype
(Comp
)))
7328 and then (Is_Scalar_Type
(Underlying_Type
(Etype
(Comp
)))
7329 or else Size_Known_At_Compile_Time
7330 (Underlying_Type
(Etype
(Comp
))))
7331 and then not Has_Warnings_Off
(Rectype
)
7333 -- Ignore discriminant in unchecked union, since it is
7334 -- not there, and cannot have a component clause.
7336 and then (not Is_Unchecked_Union
(Rectype
)
7337 or else Ekind
(Comp
) /= E_Discriminant
)
7339 Error_Msg_Sloc
:= Sloc
(Comp
);
7341 ("?C?no component clause given for & declared #",
7345 Next_Component_Or_Discriminant
(Comp
);
7350 end Analyze_Record_Representation_Clause
;
7352 -------------------------------------
7353 -- Build_Discrete_Static_Predicate --
7354 -------------------------------------
7356 procedure Build_Discrete_Static_Predicate
7361 Loc
: constant Source_Ptr
:= Sloc
(Expr
);
7363 Non_Static
: exception;
7364 -- Raised if something non-static is found
7366 Btyp
: constant Entity_Id
:= Base_Type
(Typ
);
7368 BLo
: constant Uint
:= Expr_Value
(Type_Low_Bound
(Btyp
));
7369 BHi
: constant Uint
:= Expr_Value
(Type_High_Bound
(Btyp
));
7370 -- Low bound and high bound value of base type of Typ
7374 -- Bounds for constructing the static predicate. We use the bound of the
7375 -- subtype if it is static, otherwise the corresponding base type bound.
7376 -- Note: a non-static subtype can have a static predicate.
7381 -- One entry in a Rlist value, a single REnt (range entry) value denotes
7382 -- one range from Lo to Hi. To represent a single value range Lo = Hi =
7385 type RList
is array (Nat
range <>) of REnt
;
7386 -- A list of ranges. The ranges are sorted in increasing order, and are
7387 -- disjoint (there is a gap of at least one value between each range in
7388 -- the table). A value is in the set of ranges in Rlist if it lies
7389 -- within one of these ranges.
7391 False_Range
: constant RList
:=
7392 RList
'(1 .. 0 => REnt'(No_Uint
, No_Uint
));
7393 -- An empty set of ranges represents a range list that can never be
7394 -- satisfied, since there are no ranges in which the value could lie,
7395 -- so it does not lie in any of them. False_Range is a canonical value
7396 -- for this empty set, but general processing should test for an Rlist
7397 -- with length zero (see Is_False predicate), since other null ranges
7398 -- may appear which must be treated as False.
7400 True_Range
: constant RList
:= RList
'(1 => REnt'(BLo
, BHi
));
7401 -- Range representing True, value must be in the base range
7403 function "and" (Left
: RList
; Right
: RList
) return RList
;
7404 -- And's together two range lists, returning a range list. This is a set
7405 -- intersection operation.
7407 function "or" (Left
: RList
; Right
: RList
) return RList
;
7408 -- Or's together two range lists, returning a range list. This is a set
7411 function "not" (Right
: RList
) return RList
;
7412 -- Returns complement of a given range list, i.e. a range list
7413 -- representing all the values in TLo .. THi that are not in the input
7416 function Build_Val
(V
: Uint
) return Node_Id
;
7417 -- Return an analyzed N_Identifier node referencing this value, suitable
7418 -- for use as an entry in the Static_Discrte_Predicate list. This node
7419 -- is typed with the base type.
7421 function Build_Range
(Lo
: Uint
; Hi
: Uint
) return Node_Id
;
7422 -- Return an analyzed N_Range node referencing this range, suitable for
7423 -- use as an entry in the Static_Discrete_Predicate list. This node is
7424 -- typed with the base type.
7426 function Get_RList
(Exp
: Node_Id
) return RList
;
7427 -- This is a recursive routine that converts the given expression into a
7428 -- list of ranges, suitable for use in building the static predicate.
7430 function Is_False
(R
: RList
) return Boolean;
7431 pragma Inline
(Is_False
);
7432 -- Returns True if the given range list is empty, and thus represents a
7433 -- False list of ranges that can never be satisfied.
7435 function Is_True
(R
: RList
) return Boolean;
7436 -- Returns True if R trivially represents the True predicate by having a
7437 -- single range from BLo to BHi.
7439 function Is_Type_Ref
(N
: Node_Id
) return Boolean;
7440 pragma Inline
(Is_Type_Ref
);
7441 -- Returns if True if N is a reference to the type for the predicate in
7442 -- the expression (i.e. if it is an identifier whose Chars field matches
7443 -- the Nam given in the call). N must not be parenthesized, if the type
7444 -- name appears in parens, this routine will return False.
7446 function Lo_Val
(N
: Node_Id
) return Uint
;
7447 -- Given an entry from a Static_Discrete_Predicate list that is either
7448 -- a static expression or static range, gets either the expression value
7449 -- or the low bound of the range.
7451 function Hi_Val
(N
: Node_Id
) return Uint
;
7452 -- Given an entry from a Static_Discrete_Predicate list that is either
7453 -- a static expression or static range, gets either the expression value
7454 -- or the high bound of the range.
7456 function Membership_Entry
(N
: Node_Id
) return RList
;
7457 -- Given a single membership entry (range, value, or subtype), returns
7458 -- the corresponding range list. Raises Static_Error if not static.
7460 function Membership_Entries
(N
: Node_Id
) return RList
;
7461 -- Given an element on an alternatives list of a membership operation,
7462 -- returns the range list corresponding to this entry and all following
7463 -- entries (i.e. returns the "or" of this list of values).
7465 function Stat_Pred
(Typ
: Entity_Id
) return RList
;
7466 -- Given a type, if it has a static predicate, then return the predicate
7467 -- as a range list, otherwise raise Non_Static.
7473 function "and" (Left
: RList
; Right
: RList
) return RList
is
7475 -- First range of result
7477 SLeft
: Nat
:= Left
'First;
7478 -- Start of rest of left entries
7480 SRight
: Nat
:= Right
'First;
7481 -- Start of rest of right entries
7484 -- If either range is True, return the other
7486 if Is_True
(Left
) then
7488 elsif Is_True
(Right
) then
7492 -- If either range is False, return False
7494 if Is_False
(Left
) or else Is_False
(Right
) then
7498 -- Loop to remove entries at start that are disjoint, and thus just
7499 -- get discarded from the result entirely.
7502 -- If no operands left in either operand, result is false
7504 if SLeft
> Left
'Last or else SRight
> Right
'Last then
7507 -- Discard first left operand entry if disjoint with right
7509 elsif Left
(SLeft
).Hi
< Right
(SRight
).Lo
then
7512 -- Discard first right operand entry if disjoint with left
7514 elsif Right
(SRight
).Hi
< Left
(SLeft
).Lo
then
7515 SRight
:= SRight
+ 1;
7517 -- Otherwise we have an overlapping entry
7524 -- Now we have two non-null operands, and first entries overlap. The
7525 -- first entry in the result will be the overlapping part of these
7528 FEnt
:= REnt
'(Lo => UI_Max (Left (SLeft).Lo, Right (SRight).Lo),
7529 Hi => UI_Min (Left (SLeft).Hi, Right (SRight).Hi));
7531 -- Now we can remove the entry that ended at a lower value, since its
7532 -- contribution is entirely contained in Fent.
7534 if Left (SLeft).Hi <= Right (SRight).Hi then
7537 SRight := SRight + 1;
7540 -- Compute result by concatenating this first entry with the "and" of
7541 -- the remaining parts of the left and right operands. Note that if
7542 -- either of these is empty, "and" will yield empty, so that we will
7543 -- end up with just Fent, which is what we want in that case.
7546 FEnt & (Left (SLeft .. Left'Last) and Right (SRight .. Right'Last));
7553 function "not" (Right : RList) return RList is
7555 -- Return True if False range
7557 if Is_False (Right) then
7561 -- Return False if True range
7563 if Is_True (Right) then
7567 -- Here if not trivial case
7570 Result : RList (1 .. Right'Length + 1);
7571 -- May need one more entry for gap at beginning and end
7574 -- Number of entries stored in Result
7579 if Right (Right'First).Lo > TLo then
7581 Result (Count) := REnt'(TLo
, Right
(Right
'First).Lo
- 1);
7584 -- Gaps between ranges
7586 for J
in Right
'First .. Right
'Last - 1 loop
7588 Result
(Count
) := REnt
'(Right (J).Hi + 1, Right (J + 1).Lo - 1);
7593 if Right (Right'Last).Hi < THi then
7595 Result (Count) := REnt'(Right
(Right
'Last).Hi
+ 1, THi
);
7598 return Result
(1 .. Count
);
7606 function "or" (Left
: RList
; Right
: RList
) return RList
is
7608 -- First range of result
7610 SLeft
: Nat
:= Left
'First;
7611 -- Start of rest of left entries
7613 SRight
: Nat
:= Right
'First;
7614 -- Start of rest of right entries
7617 -- If either range is True, return True
7619 if Is_True
(Left
) or else Is_True
(Right
) then
7623 -- If either range is False (empty), return the other
7625 if Is_False
(Left
) then
7627 elsif Is_False
(Right
) then
7631 -- Initialize result first entry from left or right operand depending
7632 -- on which starts with the lower range.
7634 if Left
(SLeft
).Lo
< Right
(SRight
).Lo
then
7635 FEnt
:= Left
(SLeft
);
7638 FEnt
:= Right
(SRight
);
7639 SRight
:= SRight
+ 1;
7642 -- This loop eats ranges from left and right operands that are
7643 -- contiguous with the first range we are gathering.
7646 -- Eat first entry in left operand if contiguous or overlapped by
7647 -- gathered first operand of result.
7649 if SLeft
<= Left
'Last
7650 and then Left
(SLeft
).Lo
<= FEnt
.Hi
+ 1
7652 FEnt
.Hi
:= UI_Max
(FEnt
.Hi
, Left
(SLeft
).Hi
);
7655 -- Eat first entry in right operand if contiguous or overlapped by
7656 -- gathered right operand of result.
7658 elsif SRight
<= Right
'Last
7659 and then Right
(SRight
).Lo
<= FEnt
.Hi
+ 1
7661 FEnt
.Hi
:= UI_Max
(FEnt
.Hi
, Right
(SRight
).Hi
);
7662 SRight
:= SRight
+ 1;
7664 -- All done if no more entries to eat
7671 -- Obtain result as the first entry we just computed, concatenated
7672 -- to the "or" of the remaining results (if one operand is empty,
7673 -- this will just concatenate with the other
7676 FEnt
& (Left
(SLeft
.. Left
'Last) or Right
(SRight
.. Right
'Last));
7683 function Build_Range
(Lo
: Uint
; Hi
: Uint
) return Node_Id
is
7688 Low_Bound
=> Build_Val
(Lo
),
7689 High_Bound
=> Build_Val
(Hi
));
7690 Set_Etype
(Result
, Btyp
);
7691 Set_Analyzed
(Result
);
7699 function Build_Val
(V
: Uint
) return Node_Id
is
7703 if Is_Enumeration_Type
(Typ
) then
7704 Result
:= Get_Enum_Lit_From_Pos
(Typ
, V
, Loc
);
7706 Result
:= Make_Integer_Literal
(Loc
, V
);
7709 Set_Etype
(Result
, Btyp
);
7710 Set_Is_Static_Expression
(Result
);
7711 Set_Analyzed
(Result
);
7719 function Get_RList
(Exp
: Node_Id
) return RList
is
7724 -- Static expression can only be true or false
7726 if Is_OK_Static_Expression
(Exp
) then
7727 if Expr_Value
(Exp
) = 0 then
7734 -- Otherwise test node type
7745 return Get_RList
(Left_Opnd
(Exp
))
7747 Get_RList
(Right_Opnd
(Exp
));
7754 return Get_RList
(Left_Opnd
(Exp
))
7756 Get_RList
(Right_Opnd
(Exp
));
7761 return not Get_RList
(Right_Opnd
(Exp
));
7763 -- Comparisons of type with static value
7765 when N_Op_Compare
=>
7767 -- Type is left operand
7769 if Is_Type_Ref
(Left_Opnd
(Exp
))
7770 and then Is_OK_Static_Expression
(Right_Opnd
(Exp
))
7772 Val
:= Expr_Value
(Right_Opnd
(Exp
));
7774 -- Typ is right operand
7776 elsif Is_Type_Ref
(Right_Opnd
(Exp
))
7777 and then Is_OK_Static_Expression
(Left_Opnd
(Exp
))
7779 Val
:= Expr_Value
(Left_Opnd
(Exp
));
7781 -- Invert sense of comparison
7784 when N_Op_Gt
=> Op
:= N_Op_Lt
;
7785 when N_Op_Lt
=> Op
:= N_Op_Gt
;
7786 when N_Op_Ge
=> Op
:= N_Op_Le
;
7787 when N_Op_Le
=> Op
:= N_Op_Ge
;
7788 when others => null;
7791 -- Other cases are non-static
7797 -- Construct range according to comparison operation
7801 return RList
'(1 => REnt'(Val
, Val
));
7804 return RList
'(1 => REnt'(Val
, BHi
));
7807 return RList
'(1 => REnt'(Val
+ 1, BHi
));
7810 return RList
'(1 => REnt'(BLo
, Val
));
7813 return RList
'(1 => REnt'(BLo
, Val
- 1));
7816 return RList
'(REnt'(BLo
, Val
- 1), REnt
'(Val + 1, BHi));
7819 raise Program_Error;
7825 if not Is_Type_Ref (Left_Opnd (Exp)) then
7829 if Present (Right_Opnd (Exp)) then
7830 return Membership_Entry (Right_Opnd (Exp));
7832 return Membership_Entries (First (Alternatives (Exp)));
7835 -- Negative membership (NOT IN)
7838 if not Is_Type_Ref (Left_Opnd (Exp)) then
7842 if Present (Right_Opnd (Exp)) then
7843 return not Membership_Entry (Right_Opnd (Exp));
7845 return not Membership_Entries (First (Alternatives (Exp)));
7848 -- Function call, may be call to static predicate
7850 when N_Function_Call =>
7851 if Is_Entity_Name (Name (Exp)) then
7853 Ent : constant Entity_Id := Entity (Name (Exp));
7855 if Is_Predicate_Function (Ent)
7857 Is_Predicate_Function_M (Ent)
7859 return Stat_Pred (Etype (First_Formal (Ent)));
7864 -- Other function call cases are non-static
7868 -- Qualified expression, dig out the expression
7870 when N_Qualified_Expression =>
7871 return Get_RList (Expression (Exp));
7873 when N_Case_Expression =>
7880 if not Is_Entity_Name (Expression (Expr))
7881 or else Etype (Expression (Expr)) /= Typ
7884 ("expression must denaote subtype", Expression (Expr));
7888 -- Collect discrete choices in all True alternatives
7890 Choices := New_List;
7891 Alt := First (Alternatives (Exp));
7892 while Present (Alt) loop
7893 Dep := Expression (Alt);
7895 if not Is_OK_Static_Expression (Dep) then
7898 elsif Is_True (Expr_Value (Dep)) then
7899 Append_List_To (Choices,
7900 New_Copy_List (Discrete_Choices (Alt)));
7906 return Membership_Entries (First (Choices));
7909 -- Expression with actions: if no actions, dig out expression
7911 when N_Expression_With_Actions =>
7912 if Is_Empty_List (Actions (Exp)) then
7913 return Get_RList (Expression (Exp));
7921 return (Get_RList (Left_Opnd (Exp))
7922 and not Get_RList (Right_Opnd (Exp)))
7923 or (Get_RList (Right_Opnd (Exp))
7924 and not Get_RList (Left_Opnd (Exp)));
7926 -- Any other node type is non-static
7937 function Hi_Val (N : Node_Id) return Uint is
7939 if Is_OK_Static_Expression (N) then
7940 return Expr_Value (N);
7942 pragma Assert (Nkind (N) = N_Range);
7943 return Expr_Value (High_Bound (N));
7951 function Is_False (R : RList) return Boolean is
7953 return R'Length = 0;
7960 function Is_True (R : RList) return Boolean is
7963 and then R (R'First).Lo = BLo
7964 and then R (R'First).Hi = BHi;
7971 function Is_Type_Ref (N : Node_Id) return Boolean is
7973 return Nkind (N) = N_Identifier
7974 and then Chars (N) = Nam
7975 and then Paren_Count (N) = 0;
7982 function Lo_Val (N : Node_Id) return Uint is
7984 if Is_OK_Static_Expression (N) then
7985 return Expr_Value (N);
7987 pragma Assert (Nkind (N) = N_Range);
7988 return Expr_Value (Low_Bound (N));
7992 ------------------------
7993 -- Membership_Entries --
7994 ------------------------
7996 function Membership_Entries (N : Node_Id) return RList is
7998 if No (Next (N)) then
7999 return Membership_Entry (N);
8001 return Membership_Entry (N) or Membership_Entries (Next (N));
8003 end Membership_Entries;
8005 ----------------------
8006 -- Membership_Entry --
8007 ----------------------
8009 function Membership_Entry (N : Node_Id) return RList is
8017 if Nkind (N) = N_Range then
8018 if not Is_OK_Static_Expression (Low_Bound (N))
8020 not Is_OK_Static_Expression (High_Bound (N))
8024 SLo := Expr_Value (Low_Bound (N));
8025 SHi := Expr_Value (High_Bound (N));
8026 return RList'(1 => REnt
'(SLo, SHi));
8029 -- Static expression case
8031 elsif Is_OK_Static_Expression (N) then
8032 Val := Expr_Value (N);
8033 return RList'(1 => REnt
'(Val, Val));
8035 -- Identifier (other than static expression) case
8037 else pragma Assert (Nkind (N) = N_Identifier);
8041 if Is_Type (Entity (N)) then
8043 -- If type has predicates, process them
8045 if Has_Predicates (Entity (N)) then
8046 return Stat_Pred (Entity (N));
8048 -- For static subtype without predicates, get range
8050 elsif Is_OK_Static_Subtype (Entity (N)) then
8051 SLo := Expr_Value (Type_Low_Bound (Entity (N)));
8052 SHi := Expr_Value (Type_High_Bound (Entity (N)));
8053 return RList'(1 => REnt
'(SLo, SHi));
8055 -- Any other type makes us non-static
8061 -- Any other kind of identifier in predicate (e.g. a non-static
8062 -- expression value) means this is not a static predicate.
8068 end Membership_Entry;
8074 function Stat_Pred (Typ : Entity_Id) return RList is
8076 -- Not static if type does not have static predicates
8078 if not Has_Static_Predicate (Typ) then
8082 -- Otherwise we convert the predicate list to a range list
8085 Spred : constant List_Id := Static_Discrete_Predicate (Typ);
8086 Result : RList (1 .. List_Length (Spred));
8090 P := First (Static_Discrete_Predicate (Typ));
8091 for J in Result'Range loop
8092 Result (J) := REnt'(Lo_Val
(P
), Hi_Val
(P
));
8100 -- Start of processing for Build_Discrete_Static_Predicate
8103 -- Establish bounds for the predicate
8105 if Compile_Time_Known_Value
(Type_Low_Bound
(Typ
)) then
8106 TLo
:= Expr_Value
(Type_Low_Bound
(Typ
));
8111 if Compile_Time_Known_Value
(Type_High_Bound
(Typ
)) then
8112 THi
:= Expr_Value
(Type_High_Bound
(Typ
));
8117 -- Analyze the expression to see if it is a static predicate
8120 Ranges
: constant RList
:= Get_RList
(Expr
);
8121 -- Range list from expression if it is static
8126 -- Convert range list into a form for the static predicate. In the
8127 -- Ranges array, we just have raw ranges, these must be converted
8128 -- to properly typed and analyzed static expressions or range nodes.
8130 -- Note: here we limit ranges to the ranges of the subtype, so that
8131 -- a predicate is always false for values outside the subtype. That
8132 -- seems fine, such values are invalid anyway, and considering them
8133 -- to fail the predicate seems allowed and friendly, and furthermore
8134 -- simplifies processing for case statements and loops.
8138 for J
in Ranges
'Range loop
8140 Lo
: Uint
:= Ranges
(J
).Lo
;
8141 Hi
: Uint
:= Ranges
(J
).Hi
;
8144 -- Ignore completely out of range entry
8146 if Hi
< TLo
or else Lo
> THi
then
8149 -- Otherwise process entry
8152 -- Adjust out of range value to subtype range
8162 -- Convert range into required form
8164 Append_To
(Plist
, Build_Range
(Lo
, Hi
));
8169 -- Processing was successful and all entries were static, so now we
8170 -- can store the result as the predicate list.
8172 Set_Static_Discrete_Predicate
(Typ
, Plist
);
8174 -- The processing for static predicates put the expression into
8175 -- canonical form as a series of ranges. It also eliminated
8176 -- duplicates and collapsed and combined ranges. We might as well
8177 -- replace the alternatives list of the right operand of the
8178 -- membership test with the static predicate list, which will
8179 -- usually be more efficient.
8182 New_Alts
: constant List_Id
:= New_List
;
8187 Old_Node
:= First
(Plist
);
8188 while Present
(Old_Node
) loop
8189 New_Node
:= New_Copy
(Old_Node
);
8191 if Nkind
(New_Node
) = N_Range
then
8192 Set_Low_Bound
(New_Node
, New_Copy
(Low_Bound
(Old_Node
)));
8193 Set_High_Bound
(New_Node
, New_Copy
(High_Bound
(Old_Node
)));
8196 Append_To
(New_Alts
, New_Node
);
8200 -- If empty list, replace by False
8202 if Is_Empty_List
(New_Alts
) then
8203 Rewrite
(Expr
, New_Occurrence_Of
(Standard_False
, Loc
));
8205 -- Else replace by set membership test
8210 Left_Opnd
=> Make_Identifier
(Loc
, Nam
),
8211 Right_Opnd
=> Empty
,
8212 Alternatives
=> New_Alts
));
8214 -- Resolve new expression in function context
8216 Install_Formals
(Predicate_Function
(Typ
));
8217 Push_Scope
(Predicate_Function
(Typ
));
8218 Analyze_And_Resolve
(Expr
, Standard_Boolean
);
8224 -- If non-static, return doing nothing
8229 end Build_Discrete_Static_Predicate
;
8231 --------------------------------
8232 -- Build_Export_Import_Pragma --
8233 --------------------------------
8235 function Build_Export_Import_Pragma
8237 Id
: Entity_Id
) return Node_Id
8239 Asp_Id
: constant Aspect_Id
:= Get_Aspect_Id
(Asp
);
8240 Expr
: constant Node_Id
:= Expression
(Asp
);
8241 Loc
: constant Source_Ptr
:= Sloc
(Asp
);
8252 Create_Pragma
: Boolean := False;
8253 -- This flag is set when the aspect form is such that it warrants the
8254 -- creation of a corresponding pragma.
8257 if Present
(Expr
) then
8258 if Error_Posted
(Expr
) then
8261 elsif Is_True
(Expr_Value
(Expr
)) then
8262 Create_Pragma
:= True;
8265 -- Otherwise the aspect defaults to True
8268 Create_Pragma
:= True;
8271 -- Nothing to do when the expression is False or is erroneous
8273 if not Create_Pragma
then
8277 -- Obtain all interfacing aspects that apply to the related entity
8279 Get_Interfacing_Aspects
8283 Expo_Asp
=> Dummy_1
,
8289 -- Handle the convention argument
8291 if Present
(Conv
) then
8292 Conv_Arg
:= New_Copy_Tree
(Expression
(Conv
));
8294 -- Assume convention "Ada' when aspect Convention is missing
8297 Conv_Arg
:= Make_Identifier
(Loc
, Name_Ada
);
8301 Make_Pragma_Argument_Association
(Loc
,
8302 Chars
=> Name_Convention
,
8303 Expression
=> Conv_Arg
));
8305 -- Handle the entity argument
8308 Make_Pragma_Argument_Association
(Loc
,
8309 Chars
=> Name_Entity
,
8310 Expression
=> New_Occurrence_Of
(Id
, Loc
)));
8312 -- Handle the External_Name argument
8314 if Present
(EN
) then
8316 Make_Pragma_Argument_Association
(Loc
,
8317 Chars
=> Name_External_Name
,
8318 Expression
=> New_Copy_Tree
(Expression
(EN
))));
8321 -- Handle the Link_Name argument
8323 if Present
(LN
) then
8325 Make_Pragma_Argument_Association
(Loc
,
8326 Chars
=> Name_Link_Name
,
8327 Expression
=> New_Copy_Tree
(Expression
(LN
))));
8331 -- pragma Export/Import
8332 -- (Convention => <Conv>/Ada,
8334 -- [External_Name => <EN>,]
8335 -- [Link_Name => <LN>]);
8339 Pragma_Identifier
=>
8340 Make_Identifier
(Loc
, Chars
(Identifier
(Asp
))),
8341 Pragma_Argument_Associations
=> Args
);
8343 -- Decorate the relevant aspect and the pragma
8345 Set_Aspect_Rep_Item
(Asp
, Prag
);
8347 Set_Corresponding_Aspect
(Prag
, Asp
);
8348 Set_From_Aspect_Specification
(Prag
);
8349 Set_Parent
(Prag
, Asp
);
8351 if Asp_Id
= Aspect_Import
and then Is_Subprogram
(Id
) then
8352 Set_Import_Pragma
(Id
, Prag
);
8356 end Build_Export_Import_Pragma
;
8358 -------------------------------
8359 -- Build_Predicate_Functions --
8360 -------------------------------
8362 -- The procedures that are constructed here have the form:
8364 -- function typPredicate (Ixxx : typ) return Boolean is
8367 -- typ1Predicate (typ1 (Ixxx))
8368 -- and then typ2Predicate (typ2 (Ixxx))
8370 -- exp1 and then exp2 and then ...
8371 -- end typPredicate;
8373 -- Here exp1, and exp2 are expressions from Predicate pragmas. Note that
8374 -- this is the point at which these expressions get analyzed, providing the
8375 -- required delay, and typ1, typ2, are entities from which predicates are
8376 -- inherited. Note that we do NOT generate Check pragmas, that's because we
8377 -- use this function even if checks are off, e.g. for membership tests.
8379 -- Note that the inherited predicates are evaluated first, as required by
8382 -- Note that Sem_Eval.Real_Or_String_Static_Predicate_Matches depends on
8383 -- the form of this return expression.
8385 -- If the expression has at least one Raise_Expression, then we also build
8386 -- the typPredicateM version of the function, in which any occurrence of a
8387 -- Raise_Expression is converted to "return False".
8389 -- WARNING: This routine manages Ghost regions. Return statements must be
8390 -- replaced by gotos which jump to the end of the routine and restore the
8393 procedure Build_Predicate_Functions
(Typ
: Entity_Id
; N
: Node_Id
) is
8394 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
8397 -- This is the expression for the result of the function. It is
8398 -- is build by connecting the component predicates with AND THEN.
8400 Expr_M
: Node_Id
:= Empty
; -- init to avoid warning
8401 -- This is the corresponding return expression for the Predicate_M
8402 -- function. It differs in that raise expressions are marked for
8403 -- special expansion (see Process_REs).
8405 Object_Name
: Name_Id
;
8406 -- Name for argument of Predicate procedure. Note that we use the same
8407 -- name for both predicate functions. That way the reference within the
8408 -- predicate expression is the same in both functions.
8410 Object_Entity
: Entity_Id
;
8411 -- Entity for argument of Predicate procedure
8413 Object_Entity_M
: Entity_Id
;
8414 -- Entity for argument of separate Predicate procedure when exceptions
8415 -- are present in expression.
8418 -- The function declaration
8423 Raise_Expression_Present
: Boolean := False;
8424 -- Set True if Expr has at least one Raise_Expression
8426 procedure Add_Condition
(Cond
: Node_Id
);
8427 -- Append Cond to Expr using "and then" (or just copy Cond to Expr if
8430 procedure Add_Predicates
;
8431 -- Appends expressions for any Predicate pragmas in the rep item chain
8432 -- Typ to Expr. Note that we look only at items for this exact entity.
8433 -- Inheritance of predicates for the parent type is done by calling the
8434 -- Predicate_Function of the parent type, using Add_Call above.
8436 procedure Add_Call
(T
: Entity_Id
);
8437 -- Includes a call to the predicate function for type T in Expr if T
8438 -- has predicates and Predicate_Function (T) is non-empty.
8440 function Process_RE
(N
: Node_Id
) return Traverse_Result
;
8441 -- Used in Process REs, tests if node N is a raise expression, and if
8442 -- so, marks it to be converted to return False.
8444 procedure Process_REs
is new Traverse_Proc
(Process_RE
);
8445 -- Marks any raise expressions in Expr_M to return False
8447 function Test_RE
(N
: Node_Id
) return Traverse_Result
;
8448 -- Used in Test_REs, tests one node for being a raise expression, and if
8449 -- so sets Raise_Expression_Present True.
8451 procedure Test_REs
is new Traverse_Proc
(Test_RE
);
8452 -- Tests to see if Expr contains any raise expressions
8458 procedure Add_Call
(T
: Entity_Id
) is
8462 if Present
(T
) and then Present
(Predicate_Function
(T
)) then
8463 Set_Has_Predicates
(Typ
);
8465 -- Build the call to the predicate function of T. The type may be
8466 -- derived, so use an unchecked conversion for the actual.
8472 Unchecked_Convert_To
(T
,
8473 Make_Identifier
(Loc
, Object_Name
)));
8475 -- "and"-in the call to evolving expression
8477 Add_Condition
(Exp
);
8479 -- Output info message on inheritance if required. Note we do not
8480 -- give this information for generic actual types, since it is
8481 -- unwelcome noise in that case in instantiations. We also
8482 -- generally suppress the message in instantiations, and also
8483 -- if it involves internal names.
8485 if Opt
.List_Inherited_Aspects
8486 and then not Is_Generic_Actual_Type
(Typ
)
8487 and then Instantiation_Depth
(Sloc
(Typ
)) = 0
8488 and then not Is_Internal_Name
(Chars
(T
))
8489 and then not Is_Internal_Name
(Chars
(Typ
))
8491 Error_Msg_Sloc
:= Sloc
(Predicate_Function
(T
));
8492 Error_Msg_Node_2
:= T
;
8493 Error_Msg_N
("info: & inherits predicate from & #?L?", Typ
);
8502 procedure Add_Condition
(Cond
: Node_Id
) is
8504 -- This is the first predicate expression
8509 -- Otherwise concatenate to the existing predicate expressions by
8510 -- using "and then".
8515 Left_Opnd
=> Relocate_Node
(Expr
),
8516 Right_Opnd
=> Cond
);
8520 --------------------
8521 -- Add_Predicates --
8522 --------------------
8524 procedure Add_Predicates
is
8525 procedure Add_Predicate
(Prag
: Node_Id
);
8526 -- Concatenate the expression of predicate pragma Prag to Expr by
8527 -- using a short circuit "and then" operator.
8533 procedure Add_Predicate
(Prag
: Node_Id
) is
8534 procedure Replace_Type_Reference
(N
: Node_Id
);
8535 -- Replace a single occurrence N of the subtype name with a
8536 -- reference to the formal of the predicate function. N can be an
8537 -- identifier referencing the subtype, or a selected component,
8538 -- representing an appropriately qualified occurrence of the
8541 procedure Replace_Type_References
is
8542 new Replace_Type_References_Generic
(Replace_Type_Reference
);
8543 -- Traverse an expression changing every occurrence of an
8544 -- identifier whose name matches the name of the subtype with a
8545 -- reference to the formal parameter of the predicate function.
8547 ----------------------------
8548 -- Replace_Type_Reference --
8549 ----------------------------
8551 procedure Replace_Type_Reference
(N
: Node_Id
) is
8553 Rewrite
(N
, Make_Identifier
(Sloc
(N
), Object_Name
));
8554 -- Use the Sloc of the usage name, not the defining name
8557 Set_Entity
(N
, Object_Entity
);
8559 -- We want to treat the node as if it comes from source, so
8560 -- that ASIS will not ignore it.
8562 Set_Comes_From_Source
(N
, True);
8563 end Replace_Type_Reference
;
8567 Asp
: constant Node_Id
:= Corresponding_Aspect
(Prag
);
8571 -- Start of processing for Add_Predicate
8574 -- Mark corresponding SCO as enabled
8576 Set_SCO_Pragma_Enabled
(Sloc
(Prag
));
8578 -- Extract the arguments of the pragma. The expression itself
8579 -- is copied for use in the predicate function, to preserve the
8580 -- original version for ASIS use.
8582 Arg1
:= First
(Pragma_Argument_Associations
(Prag
));
8583 Arg2
:= Next
(Arg1
);
8585 Arg1
:= Get_Pragma_Arg
(Arg1
);
8586 Arg2
:= New_Copy_Tree
(Get_Pragma_Arg
(Arg2
));
8588 -- When the predicate pragma applies to the current type or its
8589 -- full view, replace all occurrences of the subtype name with
8590 -- references to the formal parameter of the predicate function.
8592 if Entity
(Arg1
) = Typ
8593 or else Full_View
(Entity
(Arg1
)) = Typ
8595 Replace_Type_References
(Arg2
, Typ
);
8597 -- If the predicate pragma comes from an aspect, replace the
8598 -- saved expression because we need the subtype references
8599 -- replaced for the calls to Preanalyze_Spec_Expression in
8600 -- Check_Aspect_At_xxx routines.
8602 if Present
(Asp
) then
8603 Set_Entity
(Identifier
(Asp
), New_Copy_Tree
(Arg2
));
8606 -- "and"-in the Arg2 condition to evolving expression
8608 Add_Condition
(Relocate_Node
(Arg2
));
8616 -- Start of processing for Add_Predicates
8619 Ritem
:= First_Rep_Item
(Typ
);
8621 -- If the type is private, check whether full view has inherited
8624 if Is_Private_Type
(Typ
) and then No
(Ritem
) then
8625 Ritem
:= First_Rep_Item
(Full_View
(Typ
));
8628 while Present
(Ritem
) loop
8629 if Nkind
(Ritem
) = N_Pragma
8630 and then Pragma_Name
(Ritem
) = Name_Predicate
8632 Add_Predicate
(Ritem
);
8634 -- If the type is declared in an inner package it may be frozen
8635 -- outside of the package, and the generated pragma has not been
8636 -- analyzed yet, so capture the expression for the predicate
8637 -- function at this point.
8639 elsif Nkind
(Ritem
) = N_Aspect_Specification
8640 and then Present
(Aspect_Rep_Item
(Ritem
))
8641 and then Scope
(Typ
) /= Current_Scope
8644 Prag
: constant Node_Id
:= Aspect_Rep_Item
(Ritem
);
8647 if Nkind
(Prag
) = N_Pragma
8648 and then Pragma_Name
(Prag
) = Name_Predicate
8650 Add_Predicate
(Prag
);
8655 Next_Rep_Item
(Ritem
);
8663 function Process_RE
(N
: Node_Id
) return Traverse_Result
is
8665 if Nkind
(N
) = N_Raise_Expression
then
8666 Set_Convert_To_Return_False
(N
);
8677 function Test_RE
(N
: Node_Id
) return Traverse_Result
is
8679 if Nkind
(N
) = N_Raise_Expression
then
8680 Raise_Expression_Present
:= True;
8689 Saved_GM
: constant Ghost_Mode_Type
:= Ghost_Mode
;
8690 -- Save the Ghost mode 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 Map
: constant Elist_Id
:= New_Elmt_List
;
8769 New_V
: Entity_Id
:= Empty
;
8771 -- The unanalyzed expression will be copied and appear in
8772 -- both functions. Normally expressions do not declare new
8773 -- entities, but quantified expressions do, so we need to
8774 -- create new entities for their bound variables, to prevent
8775 -- multiple definitions in gigi.
8777 function Reset_Loop_Variable
(N
: Node_Id
)
8778 return Traverse_Result
;
8780 procedure Collect_Loop_Variables
is
8781 new Traverse_Proc
(Reset_Loop_Variable
);
8783 ------------------------
8784 -- Reset_Loop_Variable --
8785 ------------------------
8787 function Reset_Loop_Variable
(N
: Node_Id
)
8788 return Traverse_Result
8791 if Nkind
(N
) = N_Iterator_Specification
then
8792 New_V
:= Make_Defining_Identifier
8793 (Sloc
(N
), Chars
(Defining_Identifier
(N
)));
8795 Set_Defining_Identifier
(N
, New_V
);
8799 end Reset_Loop_Variable
;
8802 Append_Elmt
(Object_Entity
, Map
);
8803 Append_Elmt
(Object_Entity_M
, Map
);
8804 Expr_M
:= New_Copy_Tree
(Expr
, Map
=> Map
);
8805 Collect_Loop_Variables
(Expr_M
);
8809 -- Build the main predicate function
8812 SIdB
: constant Entity_Id
:=
8813 Make_Defining_Identifier
(Loc
,
8814 Chars
=> New_External_Name
(Chars
(Typ
), "Predicate"));
8815 -- The entity for the function body
8821 Set_Ekind
(SIdB
, E_Function
);
8822 Set_Is_Predicate_Function
(SIdB
);
8824 -- The predicate function is shared between views of a type
8826 if Is_Private_Type
(Typ
) and then Present
(Full_View
(Typ
)) then
8827 Set_Predicate_Function
(Full_View
(Typ
), SId
);
8830 -- Build function body
8833 Make_Function_Specification
(Loc
,
8834 Defining_Unit_Name
=> SIdB
,
8835 Parameter_Specifications
=> New_List
(
8836 Make_Parameter_Specification
(Loc
,
8837 Defining_Identifier
=>
8838 Make_Defining_Identifier
(Loc
, Object_Name
),
8840 New_Occurrence_Of
(Typ
, Loc
))),
8841 Result_Definition
=>
8842 New_Occurrence_Of
(Standard_Boolean
, Loc
));
8845 Make_Subprogram_Body
(Loc
,
8846 Specification
=> Spec
,
8847 Declarations
=> Empty_List
,
8848 Handled_Statement_Sequence
=>
8849 Make_Handled_Sequence_Of_Statements
(Loc
,
8850 Statements
=> New_List
(
8851 Make_Simple_Return_Statement
(Loc
,
8852 Expression
=> Expr
))));
8854 -- If declaration has not been analyzed yet, Insert declaration
8855 -- before freeze node. Insert body itself after freeze node.
8857 if not Analyzed
(FDecl
) then
8858 Insert_Before_And_Analyze
(N
, FDecl
);
8861 Insert_After_And_Analyze
(N
, FBody
);
8863 -- Static predicate functions are always side-effect free, and
8864 -- in most cases dynamic predicate functions are as well. Mark
8865 -- them as such whenever possible, so redundant predicate checks
8866 -- can be optimized. If there is a variable reference within the
8867 -- expression, the function is not pure.
8869 if Expander_Active
then
8871 Side_Effect_Free
(Expr
, Variable_Ref
=> True));
8872 Set_Is_Inlined
(SId
);
8876 -- Test for raise expressions present and if so build M version
8878 if Raise_Expression_Present
then
8880 SId
: constant Entity_Id
:=
8881 Make_Defining_Identifier
(Loc
,
8882 Chars
=> New_External_Name
(Chars
(Typ
), "PredicateM"));
8883 -- The entity for the function spec
8885 SIdB
: constant Entity_Id
:=
8886 Make_Defining_Identifier
(Loc
,
8887 Chars
=> New_External_Name
(Chars
(Typ
), "PredicateM"));
8888 -- The entity for the function body
8896 -- Mark any raise expressions for special expansion
8898 Process_REs
(Expr_M
);
8900 -- Build function declaration
8902 Set_Ekind
(SId
, E_Function
);
8903 Set_Is_Predicate_Function_M
(SId
);
8904 Set_Predicate_Function_M
(Typ
, SId
);
8906 -- The predicate function is shared between views of a type
8908 if Is_Private_Type
(Typ
) and then Present
(Full_View
(Typ
)) then
8909 Set_Predicate_Function_M
(Full_View
(Typ
), SId
);
8913 Make_Function_Specification
(Loc
,
8914 Defining_Unit_Name
=> SId
,
8915 Parameter_Specifications
=> New_List
(
8916 Make_Parameter_Specification
(Loc
,
8917 Defining_Identifier
=> Object_Entity_M
,
8918 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
))),
8919 Result_Definition
=>
8920 New_Occurrence_Of
(Standard_Boolean
, Loc
));
8923 Make_Subprogram_Declaration
(Loc
,
8924 Specification
=> Spec
);
8926 -- Build function body
8929 Make_Function_Specification
(Loc
,
8930 Defining_Unit_Name
=> SIdB
,
8931 Parameter_Specifications
=> New_List
(
8932 Make_Parameter_Specification
(Loc
,
8933 Defining_Identifier
=>
8934 Make_Defining_Identifier
(Loc
, Object_Name
),
8936 New_Occurrence_Of
(Typ
, Loc
))),
8937 Result_Definition
=>
8938 New_Occurrence_Of
(Standard_Boolean
, Loc
));
8940 -- Build the body, we declare the boolean expression before
8941 -- doing the return, because we are not really confident of
8942 -- what happens if a return appears within a return.
8945 Make_Defining_Identifier
(Loc
,
8946 Chars
=> New_Internal_Name
('B'));
8949 Make_Subprogram_Body
(Loc
,
8950 Specification
=> Spec
,
8952 Declarations
=> New_List
(
8953 Make_Object_Declaration
(Loc
,
8954 Defining_Identifier
=> BTemp
,
8955 Constant_Present
=> True,
8956 Object_Definition
=>
8957 New_Occurrence_Of
(Standard_Boolean
, Loc
),
8958 Expression
=> Expr_M
)),
8960 Handled_Statement_Sequence
=>
8961 Make_Handled_Sequence_Of_Statements
(Loc
,
8962 Statements
=> New_List
(
8963 Make_Simple_Return_Statement
(Loc
,
8964 Expression
=> New_Occurrence_Of
(BTemp
, Loc
)))));
8966 -- Insert declaration before freeze node and body after
8968 Insert_Before_And_Analyze
(N
, FDecl
);
8969 Insert_After_And_Analyze
(N
, FBody
);
8973 -- See if we have a static predicate. Note that the answer may be
8974 -- yes even if we have an explicit Dynamic_Predicate present.
8981 if not Is_Scalar_Type
(Typ
) and then not Is_String_Type
(Typ
) then
8984 PS
:= Is_Predicate_Static
(Expr
, Object_Name
);
8987 -- Case where we have a predicate-static aspect
8991 -- We don't set Has_Static_Predicate_Aspect, since we can have
8992 -- any of the three cases (Predicate, Dynamic_Predicate, or
8993 -- Static_Predicate) generating a predicate with an expression
8994 -- that is predicate-static. We just indicate that we have a
8995 -- predicate that can be treated as static.
8997 Set_Has_Static_Predicate
(Typ
);
8999 -- For discrete subtype, build the static predicate list
9001 if Is_Discrete_Type
(Typ
) then
9002 Build_Discrete_Static_Predicate
(Typ
, Expr
, Object_Name
);
9004 -- If we don't get a static predicate list, it means that we
9005 -- have a case where this is not possible, most typically in
9006 -- the case where we inherit a dynamic predicate. We do not
9007 -- consider this an error, we just leave the predicate as
9008 -- dynamic. But if we do succeed in building the list, then
9009 -- we mark the predicate as static.
9011 if No
(Static_Discrete_Predicate
(Typ
)) then
9012 Set_Has_Static_Predicate
(Typ
, False);
9015 -- For real or string subtype, save predicate expression
9017 elsif Is_Real_Type
(Typ
) or else Is_String_Type
(Typ
) then
9018 Set_Static_Real_Or_String_Predicate
(Typ
, Expr
);
9021 -- Case of dynamic predicate (expression is not predicate-static)
9024 -- Again, we don't set Has_Dynamic_Predicate_Aspect, since that
9025 -- is only set if we have an explicit Dynamic_Predicate aspect
9026 -- given. Here we may simply have a Predicate aspect where the
9027 -- expression happens not to be predicate-static.
9029 -- Emit an error when the predicate is categorized as static
9030 -- but its expression is not predicate-static.
9032 -- First a little fiddling to get a nice location for the
9033 -- message. If the expression is of the form (A and then B),
9034 -- where A is an inherited predicate, then use the right
9035 -- operand for the Sloc. This avoids getting confused by a call
9036 -- to an inherited predicate with a less convenient source
9040 while Nkind
(EN
) = N_And_Then
9041 and then Nkind
(Left_Opnd
(EN
)) = N_Function_Call
9042 and then Is_Predicate_Function
9043 (Entity
(Name
(Left_Opnd
(EN
))))
9045 EN
:= Right_Opnd
(EN
);
9048 -- Now post appropriate message
9050 if Has_Static_Predicate_Aspect
(Typ
) then
9051 if Is_Scalar_Type
(Typ
) or else Is_String_Type
(Typ
) then
9053 ("expression is not predicate-static (RM 3.2.4(16-22))",
9057 ("static predicate requires scalar or string type", EN
);
9064 Restore_Ghost_Mode
(Saved_GM
);
9065 end Build_Predicate_Functions
;
9067 ------------------------------------------
9068 -- Build_Predicate_Function_Declaration --
9069 ------------------------------------------
9071 -- WARNING: This routine manages Ghost regions. Return statements must be
9072 -- replaced by gotos which jump to the end of the routine and restore the
9075 function Build_Predicate_Function_Declaration
9076 (Typ
: Entity_Id
) return Node_Id
9078 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
9080 Saved_GM
: constant Ghost_Mode_Type
:= Ghost_Mode
;
9081 -- Save the Ghost mode to restore on exit
9083 Func_Decl
: Node_Id
;
9084 Func_Id
: Entity_Id
;
9088 -- The related type may be subject to pragma Ghost. Set the mode now to
9089 -- ensure that the predicate functions are properly marked as Ghost.
9091 Set_Ghost_Mode
(Typ
);
9094 Make_Defining_Identifier
(Loc
,
9095 Chars
=> New_External_Name
(Chars
(Typ
), "Predicate"));
9097 -- The predicate function requires debug info when the predicates are
9098 -- subject to Source Coverage Obligations.
9100 if Opt
.Generate_SCO
then
9101 Set_Debug_Info_Needed
(Func_Id
);
9105 Make_Function_Specification
(Loc
,
9106 Defining_Unit_Name
=> Func_Id
,
9107 Parameter_Specifications
=> New_List
(
9108 Make_Parameter_Specification
(Loc
,
9109 Defining_Identifier
=> Make_Temporary
(Loc
, 'I'),
9110 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
))),
9111 Result_Definition
=>
9112 New_Occurrence_Of
(Standard_Boolean
, Loc
));
9114 Func_Decl
:= Make_Subprogram_Declaration
(Loc
, Specification
=> Spec
);
9116 Set_Ekind
(Func_Id
, E_Function
);
9117 Set_Etype
(Func_Id
, Standard_Boolean
);
9118 Set_Is_Internal
(Func_Id
);
9119 Set_Is_Predicate_Function
(Func_Id
);
9120 Set_Predicate_Function
(Typ
, Func_Id
);
9122 Insert_After
(Parent
(Typ
), Func_Decl
);
9123 Analyze
(Func_Decl
);
9125 Restore_Ghost_Mode
(Saved_GM
);
9128 end Build_Predicate_Function_Declaration
;
9130 -----------------------------------------
9131 -- Check_Aspect_At_End_Of_Declarations --
9132 -----------------------------------------
9134 procedure Check_Aspect_At_End_Of_Declarations
(ASN
: Node_Id
) is
9135 Ent
: constant Entity_Id
:= Entity
(ASN
);
9136 Ident
: constant Node_Id
:= Identifier
(ASN
);
9137 A_Id
: constant Aspect_Id
:= Get_Aspect_Id
(Chars
(Ident
));
9139 End_Decl_Expr
: constant Node_Id
:= Entity
(Ident
);
9140 -- Expression to be analyzed at end of declarations
9142 Freeze_Expr
: constant Node_Id
:= Expression
(ASN
);
9143 -- Expression from call to Check_Aspect_At_Freeze_Point.
9145 T
: constant Entity_Id
:= Etype
(Original_Node
(Freeze_Expr
));
9146 -- Type required for preanalyze call. We use the original expression to
9147 -- get the proper type, to prevent cascaded errors when the expression
9148 -- is constant-folded.
9151 -- Set False if error
9153 -- On entry to this procedure, Entity (Ident) contains a copy of the
9154 -- original expression from the aspect, saved for this purpose, and
9155 -- but Expression (Ident) is a preanalyzed copy of the expression,
9156 -- preanalyzed just after the freeze point.
9158 procedure Check_Overloaded_Name
;
9159 -- For aspects whose expression is simply a name, this routine checks if
9160 -- the name is overloaded or not. If so, it verifies there is an
9161 -- interpretation that matches the entity obtained at the freeze point,
9162 -- otherwise the compiler complains.
9164 ---------------------------
9165 -- Check_Overloaded_Name --
9166 ---------------------------
9168 procedure Check_Overloaded_Name
is
9170 if not Is_Overloaded
(End_Decl_Expr
) then
9171 Err
:= not Is_Entity_Name
(End_Decl_Expr
)
9172 or else Entity
(End_Decl_Expr
) /= Entity
(Freeze_Expr
);
9178 Index
: Interp_Index
;
9182 Get_First_Interp
(End_Decl_Expr
, Index
, It
);
9183 while Present
(It
.Typ
) loop
9184 if It
.Nam
= Entity
(Freeze_Expr
) then
9189 Get_Next_Interp
(Index
, It
);
9193 end Check_Overloaded_Name
;
9195 -- Start of processing for Check_Aspect_At_End_Of_Declarations
9198 -- In an instance we do not perform the consistency check between freeze
9199 -- point and end of declarations, because it was done already in the
9200 -- analysis of the generic. Furthermore, the delayed analysis of an
9201 -- aspect of the instance may produce spurious errors when the generic
9202 -- is a child unit that references entities in the parent (which might
9203 -- not be in scope at the freeze point of the instance).
9208 -- The enclosing scope may have been rewritten during expansion (.e.g. a
9209 -- task body is rewritten as a procedure) after this conformance check
9210 -- has been performed, so do not perform it again (it may not easily be
9211 -- done if full visibility of local entities is not available).
9213 elsif not Comes_From_Source
(Current_Scope
) then
9216 -- Case of aspects Dimension, Dimension_System and Synchronization
9218 elsif A_Id
= Aspect_Synchronization
then
9221 -- Case of stream attributes, just have to compare entities. However,
9222 -- the expression is just a name (possibly overloaded), and there may
9223 -- be stream operations declared for unrelated types, so we just need
9224 -- to verify that one of these interpretations is the one available at
9225 -- at the freeze point.
9227 elsif A_Id
= Aspect_Input
or else
9228 A_Id
= Aspect_Output
or else
9229 A_Id
= Aspect_Read
or else
9232 Analyze
(End_Decl_Expr
);
9233 Check_Overloaded_Name
;
9235 elsif A_Id
= Aspect_Variable_Indexing
or else
9236 A_Id
= Aspect_Constant_Indexing
or else
9237 A_Id
= Aspect_Default_Iterator
or else
9238 A_Id
= Aspect_Iterator_Element
9240 -- Make type unfrozen before analysis, to prevent spurious errors
9241 -- about late attributes.
9243 Set_Is_Frozen
(Ent
, False);
9244 Analyze
(End_Decl_Expr
);
9245 Set_Is_Frozen
(Ent
, True);
9247 -- If the end of declarations comes before any other freeze
9248 -- point, the Freeze_Expr is not analyzed: no check needed.
9250 if Analyzed
(Freeze_Expr
) and then not In_Instance
then
9251 Check_Overloaded_Name
;
9259 -- Indicate that the expression comes from an aspect specification,
9260 -- which is used in subsequent analysis even if expansion is off.
9262 Set_Parent
(End_Decl_Expr
, ASN
);
9264 -- In a generic context the aspect expressions have not been
9265 -- preanalyzed, so do it now. There are no conformance checks
9266 -- to perform in this case.
9269 Check_Aspect_At_Freeze_Point
(ASN
);
9272 -- The default values attributes may be defined in the private part,
9273 -- and the analysis of the expression may take place when only the
9274 -- partial view is visible. The expression must be scalar, so use
9275 -- the full view to resolve.
9277 elsif (A_Id
= Aspect_Default_Value
9279 A_Id
= Aspect_Default_Component_Value
)
9280 and then Is_Private_Type
(T
)
9282 Preanalyze_Spec_Expression
(End_Decl_Expr
, Full_View
(T
));
9285 Preanalyze_Spec_Expression
(End_Decl_Expr
, T
);
9288 Err
:= not Fully_Conformant_Expressions
(End_Decl_Expr
, Freeze_Expr
);
9291 -- Output error message if error. Force error on aspect specification
9292 -- even if there is an error on the expression itself.
9296 ("!visibility of aspect for& changes after freeze point",
9299 ("info: & is frozen here, aspects evaluated at this point??",
9300 Freeze_Node
(Ent
), Ent
);
9302 end Check_Aspect_At_End_Of_Declarations
;
9304 ----------------------------------
9305 -- Check_Aspect_At_Freeze_Point --
9306 ----------------------------------
9308 procedure Check_Aspect_At_Freeze_Point
(ASN
: Node_Id
) is
9309 Ident
: constant Node_Id
:= Identifier
(ASN
);
9310 -- Identifier (use Entity field to save expression)
9312 A_Id
: constant Aspect_Id
:= Get_Aspect_Id
(Chars
(Ident
));
9314 T
: Entity_Id
:= Empty
;
9315 -- Type required for preanalyze call
9318 -- On entry to this procedure, Entity (Ident) contains a copy of the
9319 -- original expression from the aspect, saved for this purpose.
9321 -- On exit from this procedure Entity (Ident) is unchanged, still
9322 -- containing that copy, but Expression (Ident) is a preanalyzed copy
9323 -- of the expression, preanalyzed just after the freeze point.
9325 -- Make a copy of the expression to be preanalyzed
9327 Set_Expression
(ASN
, New_Copy_Tree
(Entity
(Ident
)));
9329 -- Find type for preanalyze call
9333 -- No_Aspect should be impossible
9336 raise Program_Error
;
9338 -- Aspects taking an optional boolean argument
9340 when Boolean_Aspects
9341 | Library_Unit_Aspects
9343 T
:= Standard_Boolean
;
9345 -- Aspects corresponding to attribute definition clauses
9347 when Aspect_Address
=>
9348 T
:= RTE
(RE_Address
);
9350 when Aspect_Attach_Handler
=>
9351 T
:= RTE
(RE_Interrupt_ID
);
9353 when Aspect_Bit_Order
9354 | Aspect_Scalar_Storage_Order
9356 T
:= RTE
(RE_Bit_Order
);
9358 when Aspect_Convention
=>
9362 T
:= RTE
(RE_CPU_Range
);
9364 -- Default_Component_Value is resolved with the component type
9366 when Aspect_Default_Component_Value
=>
9367 T
:= Component_Type
(Entity
(ASN
));
9369 when Aspect_Default_Storage_Pool
=>
9370 T
:= Class_Wide_Type
(RTE
(RE_Root_Storage_Pool
));
9372 -- Default_Value is resolved with the type entity in question
9374 when Aspect_Default_Value
=>
9377 when Aspect_Dispatching_Domain
=>
9378 T
:= RTE
(RE_Dispatching_Domain
);
9380 when Aspect_External_Tag
=>
9381 T
:= Standard_String
;
9383 when Aspect_External_Name
=>
9384 T
:= Standard_String
;
9386 when Aspect_Link_Name
=>
9387 T
:= Standard_String
;
9389 when Aspect_Interrupt_Priority
9392 T
:= Standard_Integer
;
9394 when Aspect_Relative_Deadline
=>
9395 T
:= RTE
(RE_Time_Span
);
9397 when Aspect_Secondary_Stack_Size
=>
9398 T
:= Standard_Integer
;
9400 when Aspect_Small
=>
9402 -- Note that the expression can be of any real type (not just a
9403 -- real universal literal) as long as it is a static constant.
9407 -- For a simple storage pool, we have to retrieve the type of the
9408 -- pool object associated with the aspect's corresponding attribute
9409 -- definition clause.
9411 when Aspect_Simple_Storage_Pool
=>
9412 T
:= Etype
(Expression
(Aspect_Rep_Item
(ASN
)));
9414 when Aspect_Storage_Pool
=>
9415 T
:= Class_Wide_Type
(RTE
(RE_Root_Storage_Pool
));
9417 when Aspect_Alignment
9418 | Aspect_Component_Size
9419 | Aspect_Machine_Radix
9420 | Aspect_Object_Size
9422 | Aspect_Storage_Size
9423 | Aspect_Stream_Size
9428 when Aspect_Linker_Section
=>
9429 T
:= Standard_String
;
9431 when Aspect_Synchronization
=>
9434 -- Special case, the expression of these aspects is just an entity
9435 -- that does not need any resolution, so just analyze.
9445 Analyze
(Expression
(ASN
));
9448 -- Same for Iterator aspects, where the expression is a function
9449 -- name. Legality rules are checked separately.
9451 when Aspect_Constant_Indexing
9452 | Aspect_Default_Iterator
9453 | Aspect_Iterator_Element
9454 | Aspect_Variable_Indexing
9456 Analyze
(Expression
(ASN
));
9459 -- Ditto for Iterable, legality checks in Validate_Iterable_Aspect.
9461 when Aspect_Iterable
=>
9465 Cursor
: constant Entity_Id
:= Get_Cursor_Type
(ASN
, T
);
9470 if Cursor
= Any_Type
then
9474 Assoc
:= First
(Component_Associations
(Expression
(ASN
)));
9475 while Present
(Assoc
) loop
9476 Expr
:= Expression
(Assoc
);
9479 if not Error_Posted
(Expr
) then
9480 Resolve_Iterable_Operation
9481 (Expr
, Cursor
, T
, Chars
(First
(Choices
(Assoc
))));
9490 -- Invariant/Predicate take boolean expressions
9492 when Aspect_Dynamic_Predicate
9495 | Aspect_Static_Predicate
9496 | Aspect_Type_Invariant
9498 T
:= Standard_Boolean
;
9500 when Aspect_Predicate_Failure
=>
9501 T
:= Standard_String
;
9503 -- Here is the list of aspects that don't require delay analysis
9505 when Aspect_Abstract_State
9507 | Aspect_Async_Readers
9508 | Aspect_Async_Writers
9509 | Aspect_Constant_After_Elaboration
9510 | Aspect_Contract_Cases
9511 | Aspect_Default_Initial_Condition
9514 | Aspect_Dimension_System
9515 | Aspect_Effective_Reads
9516 | Aspect_Effective_Writes
9517 | Aspect_Extensions_Visible
9520 | Aspect_Implicit_Dereference
9521 | Aspect_Initial_Condition
9522 | Aspect_Initializes
9523 | Aspect_Max_Queue_Length
9524 | Aspect_Obsolescent
9527 | Aspect_Postcondition
9529 | Aspect_Precondition
9530 | Aspect_Refined_Depends
9531 | Aspect_Refined_Global
9532 | Aspect_Refined_Post
9533 | Aspect_Refined_State
9536 | Aspect_Unimplemented
9537 | Aspect_Volatile_Function
9539 raise Program_Error
;
9543 -- Do the preanalyze call
9545 Preanalyze_Spec_Expression
(Expression
(ASN
), T
);
9546 end Check_Aspect_At_Freeze_Point
;
9548 -----------------------------------
9549 -- Check_Constant_Address_Clause --
9550 -----------------------------------
9552 procedure Check_Constant_Address_Clause
9556 procedure Check_At_Constant_Address
(Nod
: Node_Id
);
9557 -- Checks that the given node N represents a name whose 'Address is
9558 -- constant (in the same sense as OK_Constant_Address_Clause, i.e. the
9559 -- address value is the same at the point of declaration of U_Ent and at
9560 -- the time of elaboration of the address clause.
9562 procedure Check_Expr_Constants
(Nod
: Node_Id
);
9563 -- Checks that Nod meets the requirements for a constant address clause
9564 -- in the sense of the enclosing procedure.
9566 procedure Check_List_Constants
(Lst
: List_Id
);
9567 -- Check that all elements of list Lst meet the requirements for a
9568 -- constant address clause in the sense of the enclosing procedure.
9570 -------------------------------
9571 -- Check_At_Constant_Address --
9572 -------------------------------
9574 procedure Check_At_Constant_Address
(Nod
: Node_Id
) is
9576 if Is_Entity_Name
(Nod
) then
9577 if Present
(Address_Clause
(Entity
((Nod
)))) then
9579 ("invalid address clause for initialized object &!",
9582 ("address for& cannot depend on another address clause! "
9583 & "(RM 13.1(22))!", Nod
, U_Ent
);
9585 elsif In_Same_Source_Unit
(Entity
(Nod
), U_Ent
)
9586 and then Sloc
(U_Ent
) < Sloc
(Entity
(Nod
))
9589 ("invalid address clause for initialized object &!",
9591 Error_Msg_Node_2
:= U_Ent
;
9593 ("\& must be defined before & (RM 13.1(22))!",
9597 elsif Nkind
(Nod
) = N_Selected_Component
then
9599 T
: constant Entity_Id
:= Etype
(Prefix
(Nod
));
9602 if (Is_Record_Type
(T
)
9603 and then Has_Discriminants
(T
))
9606 and then Is_Record_Type
(Designated_Type
(T
))
9607 and then Has_Discriminants
(Designated_Type
(T
)))
9610 ("invalid address clause for initialized object &!",
9613 ("\address cannot depend on component of discriminated "
9614 & "record (RM 13.1(22))!", Nod
);
9616 Check_At_Constant_Address
(Prefix
(Nod
));
9620 elsif Nkind
(Nod
) = N_Indexed_Component
then
9621 Check_At_Constant_Address
(Prefix
(Nod
));
9622 Check_List_Constants
(Expressions
(Nod
));
9625 Check_Expr_Constants
(Nod
);
9627 end Check_At_Constant_Address
;
9629 --------------------------
9630 -- Check_Expr_Constants --
9631 --------------------------
9633 procedure Check_Expr_Constants
(Nod
: Node_Id
) is
9634 Loc_U_Ent
: constant Source_Ptr
:= Sloc
(U_Ent
);
9635 Ent
: Entity_Id
:= Empty
;
9638 if Nkind
(Nod
) in N_Has_Etype
9639 and then Etype
(Nod
) = Any_Type
9650 when N_Expanded_Name
9653 Ent
:= Entity
(Nod
);
9655 -- We need to look at the original node if it is different
9656 -- from the node, since we may have rewritten things and
9657 -- substituted an identifier representing the rewrite.
9659 if Original_Node
(Nod
) /= Nod
then
9660 Check_Expr_Constants
(Original_Node
(Nod
));
9662 -- If the node is an object declaration without initial
9663 -- value, some code has been expanded, and the expression
9664 -- is not constant, even if the constituents might be
9665 -- acceptable, as in A'Address + offset.
9667 if Ekind
(Ent
) = E_Variable
9669 Nkind
(Declaration_Node
(Ent
)) = N_Object_Declaration
9671 No
(Expression
(Declaration_Node
(Ent
)))
9674 ("invalid address clause for initialized object &!",
9677 -- If entity is constant, it may be the result of expanding
9678 -- a check. We must verify that its declaration appears
9679 -- before the object in question, else we also reject the
9682 elsif Ekind
(Ent
) = E_Constant
9683 and then In_Same_Source_Unit
(Ent
, U_Ent
)
9684 and then Sloc
(Ent
) > Loc_U_Ent
9687 ("invalid address clause for initialized object &!",
9694 -- Otherwise look at the identifier and see if it is OK
9696 if Ekind_In
(Ent
, E_Named_Integer
, E_Named_Real
)
9697 or else Is_Type
(Ent
)
9701 elsif Ekind_In
(Ent
, E_Constant
, E_In_Parameter
) then
9703 -- This is the case where we must have Ent defined before
9704 -- U_Ent. Clearly if they are in different units this
9705 -- requirement is met since the unit containing Ent is
9706 -- already processed.
9708 if not In_Same_Source_Unit
(Ent
, U_Ent
) then
9711 -- Otherwise location of Ent must be before the location
9712 -- of U_Ent, that's what prior defined means.
9714 elsif Sloc
(Ent
) < Loc_U_Ent
then
9719 ("invalid address clause for initialized object &!",
9721 Error_Msg_Node_2
:= U_Ent
;
9723 ("\& must be defined before & (RM 13.1(22))!",
9727 elsif Nkind
(Original_Node
(Nod
)) = N_Function_Call
then
9728 Check_Expr_Constants
(Original_Node
(Nod
));
9732 ("invalid address clause for initialized object &!",
9735 if Comes_From_Source
(Ent
) then
9737 ("\reference to variable& not allowed"
9738 & " (RM 13.1(22))!", Nod
, Ent
);
9741 ("non-static expression not allowed"
9742 & " (RM 13.1(22))!", Nod
);
9746 when N_Integer_Literal
=>
9748 -- If this is a rewritten unchecked conversion, in a system
9749 -- where Address is an integer type, always use the base type
9750 -- for a literal value. This is user-friendly and prevents
9751 -- order-of-elaboration issues with instances of unchecked
9754 if Nkind
(Original_Node
(Nod
)) = N_Function_Call
then
9755 Set_Etype
(Nod
, Base_Type
(Etype
(Nod
)));
9758 when N_Character_Literal
9765 Check_Expr_Constants
(Low_Bound
(Nod
));
9766 Check_Expr_Constants
(High_Bound
(Nod
));
9768 when N_Explicit_Dereference
=>
9769 Check_Expr_Constants
(Prefix
(Nod
));
9771 when N_Indexed_Component
=>
9772 Check_Expr_Constants
(Prefix
(Nod
));
9773 Check_List_Constants
(Expressions
(Nod
));
9776 Check_Expr_Constants
(Prefix
(Nod
));
9777 Check_Expr_Constants
(Discrete_Range
(Nod
));
9779 when N_Selected_Component
=>
9780 Check_Expr_Constants
(Prefix
(Nod
));
9782 when N_Attribute_Reference
=>
9783 if Nam_In
(Attribute_Name
(Nod
), Name_Address
,
9785 Name_Unchecked_Access
,
9786 Name_Unrestricted_Access
)
9788 Check_At_Constant_Address
(Prefix
(Nod
));
9790 -- Normally, System'To_Address will have been transformed into
9791 -- an Unchecked_Conversion, but in -gnatc mode, it will not,
9792 -- and we don't want to give an error, because the whole point
9793 -- of 'To_Address is that it is static.
9795 elsif Attribute_Name
(Nod
) = Name_To_Address
then
9796 pragma Assert
(Operating_Mode
= Check_Semantics
);
9800 Check_Expr_Constants
(Prefix
(Nod
));
9801 Check_List_Constants
(Expressions
(Nod
));
9805 Check_List_Constants
(Component_Associations
(Nod
));
9806 Check_List_Constants
(Expressions
(Nod
));
9808 when N_Component_Association
=>
9809 Check_Expr_Constants
(Expression
(Nod
));
9811 when N_Extension_Aggregate
=>
9812 Check_Expr_Constants
(Ancestor_Part
(Nod
));
9813 Check_List_Constants
(Component_Associations
(Nod
));
9814 Check_List_Constants
(Expressions
(Nod
));
9823 Check_Expr_Constants
(Left_Opnd
(Nod
));
9824 Check_Expr_Constants
(Right_Opnd
(Nod
));
9827 Check_Expr_Constants
(Right_Opnd
(Nod
));
9830 | N_Qualified_Expression
9832 | N_Unchecked_Type_Conversion
9834 Check_Expr_Constants
(Expression
(Nod
));
9836 when N_Function_Call
=>
9837 if not Is_Pure
(Entity
(Name
(Nod
))) then
9839 ("invalid address clause for initialized object &!",
9843 ("\function & is not pure (RM 13.1(22))!",
9844 Nod
, Entity
(Name
(Nod
)));
9847 Check_List_Constants
(Parameter_Associations
(Nod
));
9850 when N_Parameter_Association
=>
9851 Check_Expr_Constants
(Explicit_Actual_Parameter
(Nod
));
9855 ("invalid address clause for initialized object &!",
9858 ("\must be constant defined before& (RM 13.1(22))!",
9861 end Check_Expr_Constants
;
9863 --------------------------
9864 -- Check_List_Constants --
9865 --------------------------
9867 procedure Check_List_Constants
(Lst
: List_Id
) is
9871 if Present
(Lst
) then
9872 Nod1
:= First
(Lst
);
9873 while Present
(Nod1
) loop
9874 Check_Expr_Constants
(Nod1
);
9878 end Check_List_Constants
;
9880 -- Start of processing for Check_Constant_Address_Clause
9883 -- If rep_clauses are to be ignored, no need for legality checks. In
9884 -- particular, no need to pester user about rep clauses that violate the
9885 -- rule on constant addresses, given that these clauses will be removed
9886 -- by Freeze before they reach the back end. Similarly in CodePeer mode,
9887 -- we want to relax these checks.
9889 if not Ignore_Rep_Clauses
and not CodePeer_Mode
then
9890 Check_Expr_Constants
(Expr
);
9892 end Check_Constant_Address_Clause
;
9894 ---------------------------
9895 -- Check_Pool_Size_Clash --
9896 ---------------------------
9898 procedure Check_Pool_Size_Clash
(Ent
: Entity_Id
; SP
, SS
: Node_Id
) is
9902 -- We need to find out which one came first. Note that in the case of
9903 -- aspects mixed with pragmas there are cases where the processing order
9904 -- is reversed, which is why we do the check here.
9906 if Sloc
(SP
) < Sloc
(SS
) then
9907 Error_Msg_Sloc
:= Sloc
(SP
);
9909 Error_Msg_NE
("Storage_Pool previously given for&#", Post
, Ent
);
9912 Error_Msg_Sloc
:= Sloc
(SS
);
9914 Error_Msg_NE
("Storage_Size previously given for&#", Post
, Ent
);
9918 ("\cannot have Storage_Size and Storage_Pool (RM 13.11(3))", Post
);
9919 end Check_Pool_Size_Clash
;
9921 ----------------------------------------
9922 -- Check_Record_Representation_Clause --
9923 ----------------------------------------
9925 procedure Check_Record_Representation_Clause
(N
: Node_Id
) is
9926 Loc
: constant Source_Ptr
:= Sloc
(N
);
9927 Ident
: constant Node_Id
:= Identifier
(N
);
9928 Rectype
: Entity_Id
;
9933 Hbit
: Uint
:= Uint_0
;
9937 Max_Bit_So_Far
: Uint
;
9938 -- Records the maximum bit position so far. If all field positions
9939 -- are monotonically increasing, then we can skip the circuit for
9940 -- checking for overlap, since no overlap is possible.
9942 Tagged_Parent
: Entity_Id
:= Empty
;
9943 -- This is set in the case of an extension for which we have either a
9944 -- size clause or Is_Fully_Repped_Tagged_Type True (indicating that all
9945 -- components are positioned by record representation clauses) on the
9946 -- parent type. In this case we check for overlap between components of
9947 -- this tagged type and the parent component. Tagged_Parent will point
9948 -- to this parent type. For all other cases, Tagged_Parent is Empty.
9950 Parent_Last_Bit
: Uint
:= No_Uint
; -- init to avoid warning
9951 -- Relevant only if Tagged_Parent is set, Parent_Last_Bit indicates the
9952 -- last bit position for any field in the parent type. We only need to
9953 -- check overlap for fields starting below this point.
9955 Overlap_Check_Required
: Boolean;
9956 -- Used to keep track of whether or not an overlap check is required
9958 Overlap_Detected
: Boolean := False;
9959 -- Set True if an overlap is detected
9961 Ccount
: Natural := 0;
9962 -- Number of component clauses in record rep clause
9964 procedure Check_Component_Overlap
(C1_Ent
, C2_Ent
: Entity_Id
);
9965 -- Given two entities for record components or discriminants, checks
9966 -- if they have overlapping component clauses and issues errors if so.
9968 procedure Find_Component
;
9969 -- Finds component entity corresponding to current component clause (in
9970 -- CC), and sets Comp to the entity, and Fbit/Lbit to the zero origin
9971 -- start/stop bits for the field. If there is no matching component or
9972 -- if the matching component does not have a component clause, then
9973 -- that's an error and Comp is set to Empty, but no error message is
9974 -- issued, since the message was already given. Comp is also set to
9975 -- Empty if the current "component clause" is in fact a pragma.
9977 -----------------------------
9978 -- Check_Component_Overlap --
9979 -----------------------------
9981 procedure Check_Component_Overlap
(C1_Ent
, C2_Ent
: Entity_Id
) is
9982 CC1
: constant Node_Id
:= Component_Clause
(C1_Ent
);
9983 CC2
: constant Node_Id
:= Component_Clause
(C2_Ent
);
9986 if Present
(CC1
) and then Present
(CC2
) then
9988 -- Exclude odd case where we have two tag components in the same
9989 -- record, both at location zero. This seems a bit strange, but
9990 -- it seems to happen in some circumstances, perhaps on an error.
9992 if Nam_In
(Chars
(C1_Ent
), Name_uTag
, Name_uTag
) then
9996 -- Here we check if the two fields overlap
9999 S1
: constant Uint
:= Component_Bit_Offset
(C1_Ent
);
10000 S2
: constant Uint
:= Component_Bit_Offset
(C2_Ent
);
10001 E1
: constant Uint
:= S1
+ Esize
(C1_Ent
);
10002 E2
: constant Uint
:= S2
+ Esize
(C2_Ent
);
10005 if E2
<= S1
or else E1
<= S2
then
10008 Error_Msg_Node_2
:= Component_Name
(CC2
);
10009 Error_Msg_Sloc
:= Sloc
(Error_Msg_Node_2
);
10010 Error_Msg_Node_1
:= Component_Name
(CC1
);
10012 ("component& overlaps & #", Component_Name
(CC1
));
10013 Overlap_Detected
:= True;
10017 end Check_Component_Overlap
;
10019 --------------------
10020 -- Find_Component --
10021 --------------------
10023 procedure Find_Component
is
10025 procedure Search_Component
(R
: Entity_Id
);
10026 -- Search components of R for a match. If found, Comp is set
10028 ----------------------
10029 -- Search_Component --
10030 ----------------------
10032 procedure Search_Component
(R
: Entity_Id
) is
10034 Comp
:= First_Component_Or_Discriminant
(R
);
10035 while Present
(Comp
) loop
10037 -- Ignore error of attribute name for component name (we
10038 -- already gave an error message for this, so no need to
10041 if Nkind
(Component_Name
(CC
)) = N_Attribute_Reference
then
10044 exit when Chars
(Comp
) = Chars
(Component_Name
(CC
));
10047 Next_Component_Or_Discriminant
(Comp
);
10049 end Search_Component
;
10051 -- Start of processing for Find_Component
10054 -- Return with Comp set to Empty if we have a pragma
10056 if Nkind
(CC
) = N_Pragma
then
10061 -- Search current record for matching component
10063 Search_Component
(Rectype
);
10065 -- If not found, maybe component of base type discriminant that is
10066 -- absent from statically constrained first subtype.
10069 Search_Component
(Base_Type
(Rectype
));
10072 -- If no component, or the component does not reference the component
10073 -- clause in question, then there was some previous error for which
10074 -- we already gave a message, so just return with Comp Empty.
10076 if No
(Comp
) or else Component_Clause
(Comp
) /= CC
then
10077 Check_Error_Detected
;
10080 -- Normal case where we have a component clause
10083 Fbit
:= Component_Bit_Offset
(Comp
);
10084 Lbit
:= Fbit
+ Esize
(Comp
) - 1;
10086 end Find_Component
;
10088 -- Start of processing for Check_Record_Representation_Clause
10092 Rectype
:= Entity
(Ident
);
10094 if Rectype
= Any_Type
then
10098 Rectype
:= Underlying_Type
(Rectype
);
10100 -- See if we have a fully repped derived tagged type
10103 PS
: constant Entity_Id
:= Parent_Subtype
(Rectype
);
10106 if Present
(PS
) and then Known_Static_RM_Size
(PS
) then
10107 Tagged_Parent
:= PS
;
10108 Parent_Last_Bit
:= RM_Size
(PS
) - 1;
10110 elsif Present
(PS
) and then Is_Fully_Repped_Tagged_Type
(PS
) then
10111 Tagged_Parent
:= PS
;
10113 -- Find maximum bit of any component of the parent type
10115 Parent_Last_Bit
:= UI_From_Int
(System_Address_Size
- 1);
10116 Pcomp
:= First_Entity
(Tagged_Parent
);
10117 while Present
(Pcomp
) loop
10118 if Ekind_In
(Pcomp
, E_Discriminant
, E_Component
) then
10119 if Component_Bit_Offset
(Pcomp
) /= No_Uint
10120 and then Known_Static_Esize
(Pcomp
)
10125 Component_Bit_Offset
(Pcomp
) + Esize
(Pcomp
) - 1);
10129 -- Skip anonymous types generated for constrained array
10130 -- or record components.
10135 Next_Entity
(Pcomp
);
10140 -- All done if no component clauses
10142 CC
:= First
(Component_Clauses
(N
));
10148 -- If a tag is present, then create a component clause that places it
10149 -- at the start of the record (otherwise gigi may place it after other
10150 -- fields that have rep clauses).
10152 Fent
:= First_Entity
(Rectype
);
10154 if Nkind
(Fent
) = N_Defining_Identifier
10155 and then Chars
(Fent
) = Name_uTag
10157 Set_Component_Bit_Offset
(Fent
, Uint_0
);
10158 Set_Normalized_Position
(Fent
, Uint_0
);
10159 Set_Normalized_First_Bit
(Fent
, Uint_0
);
10160 Set_Normalized_Position_Max
(Fent
, Uint_0
);
10161 Init_Esize
(Fent
, System_Address_Size
);
10163 Set_Component_Clause
(Fent
,
10164 Make_Component_Clause
(Loc
,
10165 Component_Name
=> Make_Identifier
(Loc
, Name_uTag
),
10167 Position
=> Make_Integer_Literal
(Loc
, Uint_0
),
10168 First_Bit
=> Make_Integer_Literal
(Loc
, Uint_0
),
10170 Make_Integer_Literal
(Loc
,
10171 UI_From_Int
(System_Address_Size
))));
10173 Ccount
:= Ccount
+ 1;
10176 Max_Bit_So_Far
:= Uint_Minus_1
;
10177 Overlap_Check_Required
:= False;
10179 -- Process the component clauses
10181 while Present
(CC
) loop
10184 if Present
(Comp
) then
10185 Ccount
:= Ccount
+ 1;
10187 -- We need a full overlap check if record positions non-monotonic
10189 if Fbit
<= Max_Bit_So_Far
then
10190 Overlap_Check_Required
:= True;
10193 Max_Bit_So_Far
:= Lbit
;
10195 -- Check bit position out of range of specified size
10197 if Has_Size_Clause
(Rectype
)
10198 and then RM_Size
(Rectype
) <= Lbit
10201 ("bit number out of range of specified size",
10204 -- Check for overlap with tag or parent component
10207 if Is_Tagged_Type
(Rectype
)
10208 and then Fbit
< System_Address_Size
10211 ("component overlaps tag field of&",
10212 Component_Name
(CC
), Rectype
);
10213 Overlap_Detected
:= True;
10215 elsif Present
(Tagged_Parent
)
10216 and then Fbit
<= Parent_Last_Bit
10219 ("component overlaps parent field of&",
10220 Component_Name
(CC
), Rectype
);
10221 Overlap_Detected
:= True;
10224 if Hbit
< Lbit
then
10233 -- Now that we have processed all the component clauses, check for
10234 -- overlap. We have to leave this till last, since the components can
10235 -- appear in any arbitrary order in the representation clause.
10237 -- We do not need this check if all specified ranges were monotonic,
10238 -- as recorded by Overlap_Check_Required being False at this stage.
10240 -- This first section checks if there are any overlapping entries at
10241 -- all. It does this by sorting all entries and then seeing if there are
10242 -- any overlaps. If there are none, then that is decisive, but if there
10243 -- are overlaps, they may still be OK (they may result from fields in
10244 -- different variants).
10246 if Overlap_Check_Required
then
10247 Overlap_Check1
: declare
10249 OC_Fbit
: array (0 .. Ccount
) of Uint
;
10250 -- First-bit values for component clauses, the value is the offset
10251 -- of the first bit of the field from start of record. The zero
10252 -- entry is for use in sorting.
10254 OC_Lbit
: array (0 .. Ccount
) of Uint
;
10255 -- Last-bit values for component clauses, the value is the offset
10256 -- of the last bit of the field from start of record. The zero
10257 -- entry is for use in sorting.
10259 OC_Count
: Natural := 0;
10260 -- Count of entries in OC_Fbit and OC_Lbit
10262 function OC_Lt
(Op1
, Op2
: Natural) return Boolean;
10263 -- Compare routine for Sort
10265 procedure OC_Move
(From
: Natural; To
: Natural);
10266 -- Move routine for Sort
10268 package Sorting
is new GNAT
.Heap_Sort_G
(OC_Move
, OC_Lt
);
10274 function OC_Lt
(Op1
, Op2
: Natural) return Boolean is
10276 return OC_Fbit
(Op1
) < OC_Fbit
(Op2
);
10283 procedure OC_Move
(From
: Natural; To
: Natural) is
10285 OC_Fbit
(To
) := OC_Fbit
(From
);
10286 OC_Lbit
(To
) := OC_Lbit
(From
);
10289 -- Start of processing for Overlap_Check
10292 CC
:= First
(Component_Clauses
(N
));
10293 while Present
(CC
) loop
10295 -- Exclude component clause already marked in error
10297 if not Error_Posted
(CC
) then
10300 if Present
(Comp
) then
10301 OC_Count
:= OC_Count
+ 1;
10302 OC_Fbit
(OC_Count
) := Fbit
;
10303 OC_Lbit
(OC_Count
) := Lbit
;
10310 Sorting
.Sort
(OC_Count
);
10312 Overlap_Check_Required
:= False;
10313 for J
in 1 .. OC_Count
- 1 loop
10314 if OC_Lbit
(J
) >= OC_Fbit
(J
+ 1) then
10315 Overlap_Check_Required
:= True;
10319 end Overlap_Check1
;
10322 -- If Overlap_Check_Required is still True, then we have to do the full
10323 -- scale overlap check, since we have at least two fields that do
10324 -- overlap, and we need to know if that is OK since they are in
10325 -- different variant, or whether we have a definite problem.
10327 if Overlap_Check_Required
then
10328 Overlap_Check2
: declare
10329 C1_Ent
, C2_Ent
: Entity_Id
;
10330 -- Entities of components being checked for overlap
10333 -- Component_List node whose Component_Items are being checked
10336 -- Component declaration for component being checked
10339 C1_Ent
:= First_Entity
(Base_Type
(Rectype
));
10341 -- Loop through all components in record. For each component check
10342 -- for overlap with any of the preceding elements on the component
10343 -- list containing the component and also, if the component is in
10344 -- a variant, check against components outside the case structure.
10345 -- This latter test is repeated recursively up the variant tree.
10347 Main_Component_Loop
: while Present
(C1_Ent
) loop
10348 if not Ekind_In
(C1_Ent
, E_Component
, E_Discriminant
) then
10349 goto Continue_Main_Component_Loop
;
10352 -- Skip overlap check if entity has no declaration node. This
10353 -- happens with discriminants in constrained derived types.
10354 -- Possibly we are missing some checks as a result, but that
10355 -- does not seem terribly serious.
10357 if No
(Declaration_Node
(C1_Ent
)) then
10358 goto Continue_Main_Component_Loop
;
10361 Clist
:= Parent
(List_Containing
(Declaration_Node
(C1_Ent
)));
10363 -- Loop through component lists that need checking. Check the
10364 -- current component list and all lists in variants above us.
10366 Component_List_Loop
: loop
10368 -- If derived type definition, go to full declaration
10369 -- If at outer level, check discriminants if there are any.
10371 if Nkind
(Clist
) = N_Derived_Type_Definition
then
10372 Clist
:= Parent
(Clist
);
10375 -- Outer level of record definition, check discriminants
10377 if Nkind_In
(Clist
, N_Full_Type_Declaration
,
10378 N_Private_Type_Declaration
)
10380 if Has_Discriminants
(Defining_Identifier
(Clist
)) then
10382 First_Discriminant
(Defining_Identifier
(Clist
));
10383 while Present
(C2_Ent
) loop
10384 exit when C1_Ent
= C2_Ent
;
10385 Check_Component_Overlap
(C1_Ent
, C2_Ent
);
10386 Next_Discriminant
(C2_Ent
);
10390 -- Record extension case
10392 elsif Nkind
(Clist
) = N_Derived_Type_Definition
then
10395 -- Otherwise check one component list
10398 Citem
:= First
(Component_Items
(Clist
));
10399 while Present
(Citem
) loop
10400 if Nkind
(Citem
) = N_Component_Declaration
then
10401 C2_Ent
:= Defining_Identifier
(Citem
);
10402 exit when C1_Ent
= C2_Ent
;
10403 Check_Component_Overlap
(C1_Ent
, C2_Ent
);
10410 -- Check for variants above us (the parent of the Clist can
10411 -- be a variant, in which case its parent is a variant part,
10412 -- and the parent of the variant part is a component list
10413 -- whose components must all be checked against the current
10414 -- component for overlap).
10416 if Nkind
(Parent
(Clist
)) = N_Variant
then
10417 Clist
:= Parent
(Parent
(Parent
(Clist
)));
10419 -- Check for possible discriminant part in record, this
10420 -- is treated essentially as another level in the
10421 -- recursion. For this case the parent of the component
10422 -- list is the record definition, and its parent is the
10423 -- full type declaration containing the discriminant
10426 elsif Nkind
(Parent
(Clist
)) = N_Record_Definition
then
10427 Clist
:= Parent
(Parent
((Clist
)));
10429 -- If neither of these two cases, we are at the top of
10433 exit Component_List_Loop
;
10435 end loop Component_List_Loop
;
10437 <<Continue_Main_Component_Loop
>>
10438 Next_Entity
(C1_Ent
);
10440 end loop Main_Component_Loop
;
10441 end Overlap_Check2
;
10444 -- The following circuit deals with warning on record holes (gaps). We
10445 -- skip this check if overlap was detected, since it makes sense for the
10446 -- programmer to fix this illegality before worrying about warnings.
10448 if not Overlap_Detected
and Warn_On_Record_Holes
then
10449 Record_Hole_Check
: declare
10450 Decl
: constant Node_Id
:= Declaration_Node
(Base_Type
(Rectype
));
10451 -- Full declaration of record type
10453 procedure Check_Component_List
10457 -- Check component list CL for holes. The starting bit should be
10458 -- Sbit. which is zero for the main record component list and set
10459 -- appropriately for recursive calls for variants. DS is set to
10460 -- a list of discriminant specifications to be included in the
10461 -- consideration of components. It is No_List if none to consider.
10463 --------------------------
10464 -- Check_Component_List --
10465 --------------------------
10467 procedure Check_Component_List
10475 Compl
:= Integer (List_Length
(Component_Items
(CL
)));
10477 if DS
/= No_List
then
10478 Compl
:= Compl
+ Integer (List_Length
(DS
));
10482 Comps
: array (Natural range 0 .. Compl
) of Entity_Id
;
10483 -- Gather components (zero entry is for sort routine)
10485 Ncomps
: Natural := 0;
10486 -- Number of entries stored in Comps (starting at Comps (1))
10489 -- One component item or discriminant specification
10492 -- Starting bit for next component
10495 -- Component entity
10500 function Lt
(Op1
, Op2
: Natural) return Boolean;
10501 -- Compare routine for Sort
10503 procedure Move
(From
: Natural; To
: Natural);
10504 -- Move routine for Sort
10506 package Sorting
is new GNAT
.Heap_Sort_G
(Move
, Lt
);
10512 function Lt
(Op1
, Op2
: Natural) return Boolean is
10514 return Component_Bit_Offset
(Comps
(Op1
))
10516 Component_Bit_Offset
(Comps
(Op2
));
10523 procedure Move
(From
: Natural; To
: Natural) is
10525 Comps
(To
) := Comps
(From
);
10529 -- Gather discriminants into Comp
10531 if DS
/= No_List
then
10532 Citem
:= First
(DS
);
10533 while Present
(Citem
) loop
10534 if Nkind
(Citem
) = N_Discriminant_Specification
then
10536 Ent
: constant Entity_Id
:=
10537 Defining_Identifier
(Citem
);
10539 if Ekind
(Ent
) = E_Discriminant
then
10540 Ncomps
:= Ncomps
+ 1;
10541 Comps
(Ncomps
) := Ent
;
10550 -- Gather component entities into Comp
10552 Citem
:= First
(Component_Items
(CL
));
10553 while Present
(Citem
) loop
10554 if Nkind
(Citem
) = N_Component_Declaration
then
10555 Ncomps
:= Ncomps
+ 1;
10556 Comps
(Ncomps
) := Defining_Identifier
(Citem
);
10562 -- Now sort the component entities based on the first bit.
10563 -- Note we already know there are no overlapping components.
10565 Sorting
.Sort
(Ncomps
);
10567 -- Loop through entries checking for holes
10570 for J
in 1 .. Ncomps
loop
10574 CBO
: constant Uint
:= Component_Bit_Offset
(CEnt
);
10577 -- Skip components with unknown offsets
10579 if CBO
/= No_Uint
and then CBO
>= 0 then
10580 Error_Msg_Uint_1
:= CBO
- Nbit
;
10582 if Error_Msg_Uint_1
> 0 then
10584 ("?H?^-bit gap before component&",
10585 Component_Name
(Component_Clause
(CEnt
)),
10589 Nbit
:= CBO
+ Esize
(CEnt
);
10594 -- Process variant parts recursively if present
10596 if Present
(Variant_Part
(CL
)) then
10597 Variant
:= First
(Variants
(Variant_Part
(CL
)));
10598 while Present
(Variant
) loop
10599 Check_Component_List
10600 (Component_List
(Variant
), Nbit
, No_List
);
10605 end Check_Component_List
;
10607 -- Start of processing for Record_Hole_Check
10614 if Is_Tagged_Type
(Rectype
) then
10615 Sbit
:= UI_From_Int
(System_Address_Size
);
10620 if Nkind
(Decl
) = N_Full_Type_Declaration
10621 and then Nkind
(Type_Definition
(Decl
)) = N_Record_Definition
10623 Check_Component_List
10624 (Component_List
(Type_Definition
(Decl
)),
10626 Discriminant_Specifications
(Decl
));
10629 end Record_Hole_Check
;
10632 -- For records that have component clauses for all components, and whose
10633 -- size is less than or equal to 32, we need to know the size in the
10634 -- front end to activate possible packed array processing where the
10635 -- component type is a record.
10637 -- At this stage Hbit + 1 represents the first unused bit from all the
10638 -- component clauses processed, so if the component clauses are
10639 -- complete, then this is the length of the record.
10641 -- For records longer than System.Storage_Unit, and for those where not
10642 -- all components have component clauses, the back end determines the
10643 -- length (it may for example be appropriate to round up the size
10644 -- to some convenient boundary, based on alignment considerations, etc).
10646 if Unknown_RM_Size
(Rectype
) and then Hbit
+ 1 <= 32 then
10648 -- Nothing to do if at least one component has no component clause
10650 Comp
:= First_Component_Or_Discriminant
(Rectype
);
10651 while Present
(Comp
) loop
10652 exit when No
(Component_Clause
(Comp
));
10653 Next_Component_Or_Discriminant
(Comp
);
10656 -- If we fall out of loop, all components have component clauses
10657 -- and so we can set the size to the maximum value.
10660 Set_RM_Size
(Rectype
, Hbit
+ 1);
10663 end Check_Record_Representation_Clause
;
10669 procedure Check_Size
10673 Biased
: out Boolean)
10675 procedure Size_Too_Small_Error
(Min_Siz
: Uint
);
10676 -- Emit an error concerning illegal size Siz. Min_Siz denotes the
10679 --------------------------
10680 -- Size_Too_Small_Error --
10681 --------------------------
10683 procedure Size_Too_Small_Error
(Min_Siz
: Uint
) is
10685 -- This error is suppressed in ASIS mode to allow for different ASIS
10686 -- back ends or ASIS-based tools to query the illegal clause.
10688 if not ASIS_Mode
then
10689 Error_Msg_Uint_1
:= Min_Siz
;
10690 Error_Msg_NE
("size for& too small, minimum allowed is ^", N
, T
);
10692 end Size_Too_Small_Error
;
10696 UT
: constant Entity_Id
:= Underlying_Type
(T
);
10699 -- Start of processing for Check_Size
10704 -- Reject patently improper size values
10706 if Is_Elementary_Type
(T
)
10707 and then Siz
> UI_From_Int
(Int
'Last)
10709 Error_Msg_N
("Size value too large for elementary type", N
);
10711 if Nkind
(Original_Node
(N
)) = N_Op_Expon
then
10713 ("\maybe '* was meant, rather than '*'*", Original_Node
(N
));
10717 -- Dismiss generic types
10719 if Is_Generic_Type
(T
)
10721 Is_Generic_Type
(UT
)
10723 Is_Generic_Type
(Root_Type
(UT
))
10727 -- Guard against previous errors
10729 elsif No
(UT
) or else UT
= Any_Type
then
10730 Check_Error_Detected
;
10733 -- Check case of bit packed array
10735 elsif Is_Array_Type
(UT
)
10736 and then Known_Static_Component_Size
(UT
)
10737 and then Is_Bit_Packed_Array
(UT
)
10745 Asiz
:= Component_Size
(UT
);
10746 Indx
:= First_Index
(UT
);
10748 Ityp
:= Etype
(Indx
);
10750 -- If non-static bound, then we are not in the business of
10751 -- trying to check the length, and indeed an error will be
10752 -- issued elsewhere, since sizes of non-static array types
10753 -- cannot be set implicitly or explicitly.
10755 if not Is_OK_Static_Subtype
(Ityp
) then
10759 -- Otherwise accumulate next dimension
10761 Asiz
:= Asiz
* (Expr_Value
(Type_High_Bound
(Ityp
)) -
10762 Expr_Value
(Type_Low_Bound
(Ityp
)) +
10766 exit when No
(Indx
);
10769 if Asiz
<= Siz
then
10773 Size_Too_Small_Error
(Asiz
);
10774 Set_Esize
(T
, Asiz
);
10775 Set_RM_Size
(T
, Asiz
);
10779 -- All other composite types are ignored
10781 elsif Is_Composite_Type
(UT
) then
10784 -- For fixed-point types, don't check minimum if type is not frozen,
10785 -- since we don't know all the characteristics of the type that can
10786 -- affect the size (e.g. a specified small) till freeze time.
10788 elsif Is_Fixed_Point_Type
(UT
) and then not Is_Frozen
(UT
) then
10791 -- Cases for which a minimum check is required
10794 -- Ignore if specified size is correct for the type
10796 if Known_Esize
(UT
) and then Siz
= Esize
(UT
) then
10800 -- Otherwise get minimum size
10802 M
:= UI_From_Int
(Minimum_Size
(UT
));
10806 -- Size is less than minimum size, but one possibility remains
10807 -- that we can manage with the new size if we bias the type.
10809 M
:= UI_From_Int
(Minimum_Size
(UT
, Biased
=> True));
10812 Size_Too_Small_Error
(M
);
10814 Set_RM_Size
(T
, M
);
10822 --------------------------
10823 -- Freeze_Entity_Checks --
10824 --------------------------
10826 procedure Freeze_Entity_Checks
(N
: Node_Id
) is
10827 procedure Hide_Non_Overridden_Subprograms
(Typ
: Entity_Id
);
10828 -- Inspect the primitive operations of type Typ and hide all pairs of
10829 -- implicitly declared non-overridden non-fully conformant homographs
10830 -- (Ada RM 8.3 12.3/2).
10832 -------------------------------------
10833 -- Hide_Non_Overridden_Subprograms --
10834 -------------------------------------
10836 procedure Hide_Non_Overridden_Subprograms
(Typ
: Entity_Id
) is
10837 procedure Hide_Matching_Homographs
10838 (Subp_Id
: Entity_Id
;
10839 Start_Elmt
: Elmt_Id
);
10840 -- Inspect a list of primitive operations starting with Start_Elmt
10841 -- and find matching implicitly declared non-overridden non-fully
10842 -- conformant homographs of Subp_Id. If found, all matches along
10843 -- with Subp_Id are hidden from all visibility.
10845 function Is_Non_Overridden_Or_Null_Procedure
10846 (Subp_Id
: Entity_Id
) return Boolean;
10847 -- Determine whether subprogram Subp_Id is implicitly declared non-
10848 -- overridden subprogram or an implicitly declared null procedure.
10850 ------------------------------
10851 -- Hide_Matching_Homographs --
10852 ------------------------------
10854 procedure Hide_Matching_Homographs
10855 (Subp_Id
: Entity_Id
;
10856 Start_Elmt
: Elmt_Id
)
10859 Prim_Elmt
: Elmt_Id
;
10862 Prim_Elmt
:= Start_Elmt
;
10863 while Present
(Prim_Elmt
) loop
10864 Prim
:= Node
(Prim_Elmt
);
10866 -- The current primitive is implicitly declared non-overridden
10867 -- non-fully conformant homograph of Subp_Id. Both subprograms
10868 -- must be hidden from visibility.
10870 if Chars
(Prim
) = Chars
(Subp_Id
)
10871 and then Is_Non_Overridden_Or_Null_Procedure
(Prim
)
10872 and then not Fully_Conformant
(Prim
, Subp_Id
)
10874 Set_Is_Hidden_Non_Overridden_Subpgm
(Prim
);
10875 Set_Is_Immediately_Visible
(Prim
, False);
10876 Set_Is_Potentially_Use_Visible
(Prim
, False);
10878 Set_Is_Hidden_Non_Overridden_Subpgm
(Subp_Id
);
10879 Set_Is_Immediately_Visible
(Subp_Id
, False);
10880 Set_Is_Potentially_Use_Visible
(Subp_Id
, False);
10883 Next_Elmt
(Prim_Elmt
);
10885 end Hide_Matching_Homographs
;
10887 -----------------------------------------
10888 -- Is_Non_Overridden_Or_Null_Procedure --
10889 -----------------------------------------
10891 function Is_Non_Overridden_Or_Null_Procedure
10892 (Subp_Id
: Entity_Id
) return Boolean
10894 Alias_Id
: Entity_Id
;
10897 -- The subprogram is inherited (implicitly declared), it does not
10898 -- override and does not cover a primitive of an interface.
10900 if Ekind_In
(Subp_Id
, E_Function
, E_Procedure
)
10901 and then Present
(Alias
(Subp_Id
))
10902 and then No
(Interface_Alias
(Subp_Id
))
10903 and then No
(Overridden_Operation
(Subp_Id
))
10905 Alias_Id
:= Alias
(Subp_Id
);
10907 if Requires_Overriding
(Alias_Id
) then
10910 elsif Nkind
(Parent
(Alias_Id
)) = N_Procedure_Specification
10911 and then Null_Present
(Parent
(Alias_Id
))
10918 end Is_Non_Overridden_Or_Null_Procedure
;
10922 Prim_Ops
: constant Elist_Id
:= Direct_Primitive_Operations
(Typ
);
10924 Prim_Elmt
: Elmt_Id
;
10926 -- Start of processing for Hide_Non_Overridden_Subprograms
10929 -- Inspect the list of primitives looking for non-overridden
10932 if Present
(Prim_Ops
) then
10933 Prim_Elmt
:= First_Elmt
(Prim_Ops
);
10934 while Present
(Prim_Elmt
) loop
10935 Prim
:= Node
(Prim_Elmt
);
10936 Next_Elmt
(Prim_Elmt
);
10938 if Is_Non_Overridden_Or_Null_Procedure
(Prim
) then
10939 Hide_Matching_Homographs
10941 Start_Elmt
=> Prim_Elmt
);
10945 end Hide_Non_Overridden_Subprograms
;
10949 E
: constant Entity_Id
:= Entity
(N
);
10951 Nongeneric_Case
: constant Boolean := Nkind
(N
) = N_Freeze_Entity
;
10952 -- True in nongeneric case. Some of the processing here is skipped
10953 -- for the generic case since it is not needed. Basically in the
10954 -- generic case, we only need to do stuff that might generate error
10955 -- messages or warnings.
10957 -- Start of processing for Freeze_Entity_Checks
10960 -- Remember that we are processing a freezing entity. Required to
10961 -- ensure correct decoration of internal entities associated with
10962 -- interfaces (see New_Overloaded_Entity).
10964 Inside_Freezing_Actions
:= Inside_Freezing_Actions
+ 1;
10966 -- For tagged types covering interfaces add internal entities that link
10967 -- the primitives of the interfaces with the primitives that cover them.
10968 -- Note: These entities were originally generated only when generating
10969 -- code because their main purpose was to provide support to initialize
10970 -- the secondary dispatch tables. They are now generated also when
10971 -- compiling with no code generation to provide ASIS the relationship
10972 -- between interface primitives and tagged type primitives. They are
10973 -- also used to locate primitives covering interfaces when processing
10974 -- generics (see Derive_Subprograms).
10976 -- This is not needed in the generic case
10978 if Ada_Version
>= Ada_2005
10979 and then Nongeneric_Case
10980 and then Ekind
(E
) = E_Record_Type
10981 and then Is_Tagged_Type
(E
)
10982 and then not Is_Interface
(E
)
10983 and then Has_Interfaces
(E
)
10985 -- This would be a good common place to call the routine that checks
10986 -- overriding of interface primitives (and thus factorize calls to
10987 -- Check_Abstract_Overriding located at different contexts in the
10988 -- compiler). However, this is not possible because it causes
10989 -- spurious errors in case of late overriding.
10991 Add_Internal_Interface_Entities
(E
);
10994 -- After all forms of overriding have been resolved, a tagged type may
10995 -- be left with a set of implicitly declared and possibly erroneous
10996 -- abstract subprograms, null procedures and subprograms that require
10997 -- overriding. If this set contains fully conformant homographs, then
10998 -- one is chosen arbitrarily (already done during resolution), otherwise
10999 -- all remaining non-fully conformant homographs are hidden from
11000 -- visibility (Ada RM 8.3 12.3/2).
11002 if Is_Tagged_Type
(E
) then
11003 Hide_Non_Overridden_Subprograms
(E
);
11008 if Ekind
(E
) = E_Record_Type
11009 and then Is_CPP_Class
(E
)
11010 and then Is_Tagged_Type
(E
)
11011 and then Tagged_Type_Expansion
11013 if CPP_Num_Prims
(E
) = 0 then
11015 -- If the CPP type has user defined components then it must import
11016 -- primitives from C++. This is required because if the C++ class
11017 -- has no primitives then the C++ compiler does not added the _tag
11018 -- component to the type.
11020 if First_Entity
(E
) /= Last_Entity
(E
) then
11022 ("'C'P'P type must import at least one primitive from C++??",
11027 -- Check that all its primitives are abstract or imported from C++.
11028 -- Check also availability of the C++ constructor.
11031 Has_Constructors
: constant Boolean := Has_CPP_Constructors
(E
);
11033 Error_Reported
: Boolean := False;
11037 Elmt
:= First_Elmt
(Primitive_Operations
(E
));
11038 while Present
(Elmt
) loop
11039 Prim
:= Node
(Elmt
);
11041 if Comes_From_Source
(Prim
) then
11042 if Is_Abstract_Subprogram
(Prim
) then
11045 elsif not Is_Imported
(Prim
)
11046 or else Convention
(Prim
) /= Convention_CPP
11049 ("primitives of 'C'P'P types must be imported from C++ "
11050 & "or abstract??", Prim
);
11052 elsif not Has_Constructors
11053 and then not Error_Reported
11055 Error_Msg_Name_1
:= Chars
(E
);
11057 ("??'C'P'P constructor required for type %", Prim
);
11058 Error_Reported
:= True;
11067 -- Check Ada derivation of CPP type
11069 if Expander_Active
-- why? losing errors in -gnatc mode???
11070 and then Present
(Etype
(E
)) -- defend against errors
11071 and then Tagged_Type_Expansion
11072 and then Ekind
(E
) = E_Record_Type
11073 and then Etype
(E
) /= E
11074 and then Is_CPP_Class
(Etype
(E
))
11075 and then CPP_Num_Prims
(Etype
(E
)) > 0
11076 and then not Is_CPP_Class
(E
)
11077 and then not Has_CPP_Constructors
(Etype
(E
))
11079 -- If the parent has C++ primitives but it has no constructor then
11080 -- check that all the primitives are overridden in this derivation;
11081 -- otherwise the constructor of the parent is needed to build the
11089 Elmt
:= First_Elmt
(Primitive_Operations
(E
));
11090 while Present
(Elmt
) loop
11091 Prim
:= Node
(Elmt
);
11093 if not Is_Abstract_Subprogram
(Prim
)
11094 and then No
(Interface_Alias
(Prim
))
11095 and then Find_Dispatching_Type
(Ultimate_Alias
(Prim
)) /= E
11097 Error_Msg_Name_1
:= Chars
(Etype
(E
));
11099 ("'C'P'P constructor required for parent type %", E
);
11108 Inside_Freezing_Actions
:= Inside_Freezing_Actions
- 1;
11110 -- If we have a type with predicates, build predicate function. This is
11111 -- not needed in the generic case, nor within TSS subprograms and other
11112 -- predefined primitives.
11115 and then Nongeneric_Case
11116 and then not Within_Internal_Subprogram
11117 and then Has_Predicates
(E
)
11119 Build_Predicate_Functions
(E
, N
);
11122 -- If type has delayed aspects, this is where we do the preanalysis at
11123 -- the freeze point, as part of the consistent visibility check. Note
11124 -- that this must be done after calling Build_Predicate_Functions or
11125 -- Build_Invariant_Procedure since these subprograms fix occurrences of
11126 -- the subtype name in the saved expression so that they will not cause
11127 -- trouble in the preanalysis.
11129 -- This is also not needed in the generic case
11132 and then Has_Delayed_Aspects
(E
)
11133 and then Scope
(E
) = Current_Scope
11135 -- Retrieve the visibility to the discriminants in order to properly
11136 -- analyze the aspects.
11138 Push_Scope_And_Install_Discriminants
(E
);
11144 -- Look for aspect specification entries for this entity
11146 Ritem
:= First_Rep_Item
(E
);
11147 while Present
(Ritem
) loop
11148 if Nkind
(Ritem
) = N_Aspect_Specification
11149 and then Entity
(Ritem
) = E
11150 and then Is_Delayed_Aspect
(Ritem
)
11152 Check_Aspect_At_Freeze_Point
(Ritem
);
11155 Next_Rep_Item
(Ritem
);
11159 Uninstall_Discriminants_And_Pop_Scope
(E
);
11162 -- For a record type, deal with variant parts. This has to be delayed
11163 -- to this point, because of the issue of statically predicated
11164 -- subtypes, which we have to ensure are frozen before checking
11165 -- choices, since we need to have the static choice list set.
11167 if Is_Record_Type
(E
) then
11168 Check_Variant_Part
: declare
11169 D
: constant Node_Id
:= Declaration_Node
(E
);
11174 Others_Present
: Boolean;
11175 pragma Warnings
(Off
, Others_Present
);
11176 -- Indicates others present, not used in this case
11178 procedure Non_Static_Choice_Error
(Choice
: Node_Id
);
11179 -- Error routine invoked by the generic instantiation below when
11180 -- the variant part has a non static choice.
11182 procedure Process_Declarations
(Variant
: Node_Id
);
11183 -- Processes declarations associated with a variant. We analyzed
11184 -- the declarations earlier (in Sem_Ch3.Analyze_Variant_Part),
11185 -- but we still need the recursive call to Check_Choices for any
11186 -- nested variant to get its choices properly processed. This is
11187 -- also where we expand out the choices if expansion is active.
11189 package Variant_Choices_Processing
is new
11190 Generic_Check_Choices
11191 (Process_Empty_Choice
=> No_OP
,
11192 Process_Non_Static_Choice
=> Non_Static_Choice_Error
,
11193 Process_Associated_Node
=> Process_Declarations
);
11194 use Variant_Choices_Processing
;
11196 -----------------------------
11197 -- Non_Static_Choice_Error --
11198 -----------------------------
11200 procedure Non_Static_Choice_Error
(Choice
: Node_Id
) is
11202 Flag_Non_Static_Expr
11203 ("choice given in variant part is not static!", Choice
);
11204 end Non_Static_Choice_Error
;
11206 --------------------------
11207 -- Process_Declarations --
11208 --------------------------
11210 procedure Process_Declarations
(Variant
: Node_Id
) is
11211 CL
: constant Node_Id
:= Component_List
(Variant
);
11215 -- Check for static predicate present in this variant
11217 if Has_SP_Choice
(Variant
) then
11219 -- Here we expand. You might expect to find this call in
11220 -- Expand_N_Variant_Part, but that is called when we first
11221 -- see the variant part, and we cannot do this expansion
11222 -- earlier than the freeze point, since for statically
11223 -- predicated subtypes, the predicate is not known till
11224 -- the freeze point.
11226 -- Furthermore, we do this expansion even if the expander
11227 -- is not active, because other semantic processing, e.g.
11228 -- for aggregates, requires the expanded list of choices.
11230 -- If the expander is not active, then we can't just clobber
11231 -- the list since it would invalidate the ASIS -gnatct tree.
11232 -- So we have to rewrite the variant part with a Rewrite
11233 -- call that replaces it with a copy and clobber the copy.
11235 if not Expander_Active
then
11237 NewV
: constant Node_Id
:= New_Copy
(Variant
);
11239 Set_Discrete_Choices
11240 (NewV
, New_Copy_List
(Discrete_Choices
(Variant
)));
11241 Rewrite
(Variant
, NewV
);
11245 Expand_Static_Predicates_In_Choices
(Variant
);
11248 -- We don't need to worry about the declarations in the variant
11249 -- (since they were analyzed by Analyze_Choices when we first
11250 -- encountered the variant), but we do need to take care of
11251 -- expansion of any nested variants.
11253 if not Null_Present
(CL
) then
11254 VP
:= Variant_Part
(CL
);
11256 if Present
(VP
) then
11258 (VP
, Variants
(VP
), Etype
(Name
(VP
)), Others_Present
);
11261 end Process_Declarations
;
11263 -- Start of processing for Check_Variant_Part
11266 -- Find component list
11270 if Nkind
(D
) = N_Full_Type_Declaration
then
11271 T
:= Type_Definition
(D
);
11273 if Nkind
(T
) = N_Record_Definition
then
11274 C
:= Component_List
(T
);
11276 elsif Nkind
(T
) = N_Derived_Type_Definition
11277 and then Present
(Record_Extension_Part
(T
))
11279 C
:= Component_List
(Record_Extension_Part
(T
));
11283 -- Case of variant part present
11285 if Present
(C
) and then Present
(Variant_Part
(C
)) then
11286 VP
:= Variant_Part
(C
);
11291 (VP
, Variants
(VP
), Etype
(Name
(VP
)), Others_Present
);
11293 -- If the last variant does not contain the Others choice,
11294 -- replace it with an N_Others_Choice node since Gigi always
11295 -- wants an Others. Note that we do not bother to call Analyze
11296 -- on the modified variant part, since its only effect would be
11297 -- to compute the Others_Discrete_Choices node laboriously, and
11298 -- of course we already know the list of choices corresponding
11299 -- to the others choice (it's the list we're replacing).
11301 -- We only want to do this if the expander is active, since
11302 -- we do not want to clobber the ASIS tree.
11304 if Expander_Active
then
11306 Last_Var
: constant Node_Id
:=
11307 Last_Non_Pragma
(Variants
(VP
));
11309 Others_Node
: Node_Id
;
11312 if Nkind
(First
(Discrete_Choices
(Last_Var
))) /=
11315 Others_Node
:= Make_Others_Choice
(Sloc
(Last_Var
));
11316 Set_Others_Discrete_Choices
11317 (Others_Node
, Discrete_Choices
(Last_Var
));
11318 Set_Discrete_Choices
11319 (Last_Var
, New_List
(Others_Node
));
11324 end Check_Variant_Part
;
11326 end Freeze_Entity_Checks
;
11328 -------------------------
11329 -- Get_Alignment_Value --
11330 -------------------------
11332 function Get_Alignment_Value
(Expr
: Node_Id
) return Uint
is
11333 Align
: constant Uint
:= Static_Integer
(Expr
);
11336 if Align
= No_Uint
then
11339 elsif Align
<= 0 then
11341 -- This error is suppressed in ASIS mode to allow for different ASIS
11342 -- back ends or ASIS-based tools to query the illegal clause.
11344 if not ASIS_Mode
then
11345 Error_Msg_N
("alignment value must be positive", Expr
);
11351 for J
in Int
range 0 .. 64 loop
11353 M
: constant Uint
:= Uint_2
** J
;
11356 exit when M
= Align
;
11360 -- This error is suppressed in ASIS mode to allow for
11361 -- different ASIS back ends or ASIS-based tools to query the
11364 if not ASIS_Mode
then
11365 Error_Msg_N
("alignment value must be power of 2", Expr
);
11375 end Get_Alignment_Value
;
11377 -------------------------------------
11378 -- Inherit_Aspects_At_Freeze_Point --
11379 -------------------------------------
11381 procedure Inherit_Aspects_At_Freeze_Point
(Typ
: Entity_Id
) is
11382 function Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11383 (Rep_Item
: Node_Id
) return Boolean;
11384 -- This routine checks if Rep_Item is either a pragma or an aspect
11385 -- specification node whose correponding pragma (if any) is present in
11386 -- the Rep Item chain of the entity it has been specified to.
11388 --------------------------------------------------
11389 -- Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item --
11390 --------------------------------------------------
11392 function Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11393 (Rep_Item
: Node_Id
) return Boolean
11397 Nkind
(Rep_Item
) = N_Pragma
11398 or else Present_In_Rep_Item
11399 (Entity
(Rep_Item
), Aspect_Rep_Item
(Rep_Item
));
11400 end Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
;
11402 -- Start of processing for Inherit_Aspects_At_Freeze_Point
11405 -- A representation item is either subtype-specific (Size and Alignment
11406 -- clauses) or type-related (all others). Subtype-specific aspects may
11407 -- differ for different subtypes of the same type (RM 13.1.8).
11409 -- A derived type inherits each type-related representation aspect of
11410 -- its parent type that was directly specified before the declaration of
11411 -- the derived type (RM 13.1.15).
11413 -- A derived subtype inherits each subtype-specific representation
11414 -- aspect of its parent subtype that was directly specified before the
11415 -- declaration of the derived type (RM 13.1.15).
11417 -- The general processing involves inheriting a representation aspect
11418 -- from a parent type whenever the first rep item (aspect specification,
11419 -- attribute definition clause, pragma) corresponding to the given
11420 -- representation aspect in the rep item chain of Typ, if any, isn't
11421 -- directly specified to Typ but to one of its parents.
11423 -- ??? Note that, for now, just a limited number of representation
11424 -- aspects have been inherited here so far. Many of them are
11425 -- still inherited in Sem_Ch3. This will be fixed soon. Here is
11426 -- a non- exhaustive list of aspects that likely also need to
11427 -- be moved to this routine: Alignment, Component_Alignment,
11428 -- Component_Size, Machine_Radix, Object_Size, Pack, Predicates,
11429 -- Preelaborable_Initialization, RM_Size and Small.
11431 -- In addition, Convention must be propagated from base type to subtype,
11432 -- because the subtype may have been declared on an incomplete view.
11434 if Nkind
(Parent
(Typ
)) = N_Private_Extension_Declaration
then
11440 if not Has_Rep_Item
(Typ
, Name_Ada_05
, Name_Ada_2005
, False)
11441 and then Has_Rep_Item
(Typ
, Name_Ada_05
, Name_Ada_2005
)
11442 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11443 (Get_Rep_Item
(Typ
, Name_Ada_05
, Name_Ada_2005
))
11445 Set_Is_Ada_2005_Only
(Typ
);
11450 if not Has_Rep_Item
(Typ
, Name_Ada_12
, Name_Ada_2012
, False)
11451 and then Has_Rep_Item
(Typ
, Name_Ada_12
, Name_Ada_2012
)
11452 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11453 (Get_Rep_Item
(Typ
, Name_Ada_12
, Name_Ada_2012
))
11455 Set_Is_Ada_2012_Only
(Typ
);
11460 if not Has_Rep_Item
(Typ
, Name_Atomic
, Name_Shared
, False)
11461 and then Has_Rep_Pragma
(Typ
, Name_Atomic
, Name_Shared
)
11462 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11463 (Get_Rep_Item
(Typ
, Name_Atomic
, Name_Shared
))
11465 Set_Is_Atomic
(Typ
);
11466 Set_Is_Volatile
(Typ
);
11467 Set_Treat_As_Volatile
(Typ
);
11472 if Is_Record_Type
(Typ
)
11473 and then Typ
/= Base_Type
(Typ
) and then Is_Frozen
(Base_Type
(Typ
))
11475 Set_Convention
(Typ
, Convention
(Base_Type
(Typ
)));
11478 -- Default_Component_Value
11480 -- Verify that there is no rep_item declared for the type, and there
11481 -- is one coming from an ancestor.
11483 if Is_Array_Type
(Typ
)
11484 and then Is_Base_Type
(Typ
)
11485 and then not Has_Rep_Item
(Typ
, Name_Default_Component_Value
, False)
11486 and then Has_Rep_Item
(Typ
, Name_Default_Component_Value
)
11488 Set_Default_Aspect_Component_Value
(Typ
,
11489 Default_Aspect_Component_Value
11490 (Entity
(Get_Rep_Item
(Typ
, Name_Default_Component_Value
))));
11495 if Is_Scalar_Type
(Typ
)
11496 and then Is_Base_Type
(Typ
)
11497 and then not Has_Rep_Item
(Typ
, Name_Default_Value
, False)
11498 and then Has_Rep_Item
(Typ
, Name_Default_Value
)
11500 Set_Has_Default_Aspect
(Typ
);
11501 Set_Default_Aspect_Value
(Typ
,
11502 Default_Aspect_Value
11503 (Entity
(Get_Rep_Item
(Typ
, Name_Default_Value
))));
11508 if not Has_Rep_Item
(Typ
, Name_Discard_Names
, False)
11509 and then Has_Rep_Item
(Typ
, Name_Discard_Names
)
11510 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11511 (Get_Rep_Item
(Typ
, Name_Discard_Names
))
11513 Set_Discard_Names
(Typ
);
11518 if not Has_Rep_Item
(Typ
, Name_Volatile
, False)
11519 and then Has_Rep_Item
(Typ
, Name_Volatile
)
11520 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11521 (Get_Rep_Item
(Typ
, Name_Volatile
))
11523 Set_Is_Volatile
(Typ
);
11524 Set_Treat_As_Volatile
(Typ
);
11527 -- Volatile_Full_Access
11529 if not Has_Rep_Item
(Typ
, Name_Volatile_Full_Access
, False)
11530 and then Has_Rep_Pragma
(Typ
, Name_Volatile_Full_Access
)
11531 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11532 (Get_Rep_Item
(Typ
, Name_Volatile_Full_Access
))
11534 Set_Is_Volatile_Full_Access
(Typ
);
11535 Set_Is_Volatile
(Typ
);
11536 Set_Treat_As_Volatile
(Typ
);
11539 -- Inheritance for derived types only
11541 if Is_Derived_Type
(Typ
) then
11543 Bas_Typ
: constant Entity_Id
:= Base_Type
(Typ
);
11544 Imp_Bas_Typ
: constant Entity_Id
:= Implementation_Base_Type
(Typ
);
11547 -- Atomic_Components
11549 if not Has_Rep_Item
(Typ
, Name_Atomic_Components
, False)
11550 and then Has_Rep_Item
(Typ
, Name_Atomic_Components
)
11551 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11552 (Get_Rep_Item
(Typ
, Name_Atomic_Components
))
11554 Set_Has_Atomic_Components
(Imp_Bas_Typ
);
11557 -- Volatile_Components
11559 if not Has_Rep_Item
(Typ
, Name_Volatile_Components
, False)
11560 and then Has_Rep_Item
(Typ
, Name_Volatile_Components
)
11561 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11562 (Get_Rep_Item
(Typ
, Name_Volatile_Components
))
11564 Set_Has_Volatile_Components
(Imp_Bas_Typ
);
11567 -- Finalize_Storage_Only
11569 if not Has_Rep_Pragma
(Typ
, Name_Finalize_Storage_Only
, False)
11570 and then Has_Rep_Pragma
(Typ
, Name_Finalize_Storage_Only
)
11572 Set_Finalize_Storage_Only
(Bas_Typ
);
11575 -- Universal_Aliasing
11577 if not Has_Rep_Item
(Typ
, Name_Universal_Aliasing
, False)
11578 and then Has_Rep_Item
(Typ
, Name_Universal_Aliasing
)
11579 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11580 (Get_Rep_Item
(Typ
, Name_Universal_Aliasing
))
11582 Set_Universal_Aliasing
(Imp_Bas_Typ
);
11587 if Is_Record_Type
(Typ
) then
11588 if not Has_Rep_Item
(Typ
, Name_Bit_Order
, False)
11589 and then Has_Rep_Item
(Typ
, Name_Bit_Order
)
11591 Set_Reverse_Bit_Order
(Bas_Typ
,
11592 Reverse_Bit_Order
(Entity
(Name
11593 (Get_Rep_Item
(Typ
, Name_Bit_Order
)))));
11597 -- Scalar_Storage_Order
11599 -- Note: the aspect is specified on a first subtype, but recorded
11600 -- in a flag of the base type!
11602 if (Is_Record_Type
(Typ
) or else Is_Array_Type
(Typ
))
11603 and then Typ
= Bas_Typ
11605 -- For a type extension, always inherit from parent; otherwise
11606 -- inherit if no default applies. Note: we do not check for
11607 -- an explicit rep item on the parent type when inheriting,
11608 -- because the parent SSO may itself have been set by default.
11610 if not Has_Rep_Item
(First_Subtype
(Typ
),
11611 Name_Scalar_Storage_Order
, False)
11612 and then (Is_Tagged_Type
(Bas_Typ
)
11613 or else not (SSO_Set_Low_By_Default
(Bas_Typ
)
11615 SSO_Set_High_By_Default
(Bas_Typ
)))
11617 Set_Reverse_Storage_Order
(Bas_Typ
,
11618 Reverse_Storage_Order
11619 (Implementation_Base_Type
(Etype
(Bas_Typ
))));
11621 -- Clear default SSO indications, since the inherited aspect
11622 -- which was set explicitly overrides the default.
11624 Set_SSO_Set_Low_By_Default
(Bas_Typ
, False);
11625 Set_SSO_Set_High_By_Default
(Bas_Typ
, False);
11630 end Inherit_Aspects_At_Freeze_Point
;
11636 procedure Initialize
is
11638 Address_Clause_Checks
.Init
;
11639 Compile_Time_Warnings_Errors
.Init
;
11640 Unchecked_Conversions
.Init
;
11642 -- ??? Might be needed in the future for some non GCC back-ends
11643 -- if AAMP_On_Target then
11644 -- Independence_Checks.Init;
11648 ---------------------------
11649 -- Install_Discriminants --
11650 ---------------------------
11652 procedure Install_Discriminants
(E
: Entity_Id
) is
11656 Disc
:= First_Discriminant
(E
);
11657 while Present
(Disc
) loop
11658 Prev
:= Current_Entity
(Disc
);
11659 Set_Current_Entity
(Disc
);
11660 Set_Is_Immediately_Visible
(Disc
);
11661 Set_Homonym
(Disc
, Prev
);
11662 Next_Discriminant
(Disc
);
11664 end Install_Discriminants
;
11666 -------------------------
11667 -- Is_Operational_Item --
11668 -------------------------
11670 function Is_Operational_Item
(N
: Node_Id
) return Boolean is
11672 if Nkind
(N
) /= N_Attribute_Definition_Clause
then
11677 Id
: constant Attribute_Id
:= Get_Attribute_Id
(Chars
(N
));
11680 -- List of operational items is given in AARM 13.1(8.mm/1).
11681 -- It is clearly incomplete, as it does not include iterator
11682 -- aspects, among others.
11684 return Id
= Attribute_Constant_Indexing
11685 or else Id
= Attribute_Default_Iterator
11686 or else Id
= Attribute_Implicit_Dereference
11687 or else Id
= Attribute_Input
11688 or else Id
= Attribute_Iterator_Element
11689 or else Id
= Attribute_Iterable
11690 or else Id
= Attribute_Output
11691 or else Id
= Attribute_Read
11692 or else Id
= Attribute_Variable_Indexing
11693 or else Id
= Attribute_Write
11694 or else Id
= Attribute_External_Tag
;
11697 end Is_Operational_Item
;
11699 -------------------------
11700 -- Is_Predicate_Static --
11701 -------------------------
11703 -- Note: the basic legality of the expression has already been checked, so
11704 -- we don't need to worry about cases or ranges on strings for example.
11706 function Is_Predicate_Static
11708 Nam
: Name_Id
) return Boolean
11710 function All_Static_Case_Alternatives
(L
: List_Id
) return Boolean;
11711 -- Given a list of case expression alternatives, returns True if all
11712 -- the alternatives are static (have all static choices, and a static
11715 function All_Static_Choices
(L
: List_Id
) return Boolean;
11716 -- Returns true if all elements of the list are OK static choices
11717 -- as defined below for Is_Static_Choice. Used for case expression
11718 -- alternatives and for the right operand of a membership test. An
11719 -- others_choice is static if the corresponding expression is static.
11720 -- The staticness of the bounds is checked separately.
11722 function Is_Static_Choice
(N
: Node_Id
) return Boolean;
11723 -- Returns True if N represents a static choice (static subtype, or
11724 -- static subtype indication, or static expression, or static range).
11726 -- Note that this is a bit more inclusive than we actually need
11727 -- (in particular membership tests do not allow the use of subtype
11728 -- indications). But that doesn't matter, we have already checked
11729 -- that the construct is legal to get this far.
11731 function Is_Type_Ref
(N
: Node_Id
) return Boolean;
11732 pragma Inline
(Is_Type_Ref
);
11733 -- Returns True if N is a reference to the type for the predicate in the
11734 -- expression (i.e. if it is an identifier whose Chars field matches the
11735 -- Nam given in the call). N must not be parenthesized, if the type name
11736 -- appears in parens, this routine will return False.
11738 -- The routine also returns True for function calls generated during the
11739 -- expansion of comparison operators on strings, which are intended to
11740 -- be legal in static predicates, and are converted into calls to array
11741 -- comparison routines in the body of the corresponding predicate
11744 ----------------------------------
11745 -- All_Static_Case_Alternatives --
11746 ----------------------------------
11748 function All_Static_Case_Alternatives
(L
: List_Id
) return Boolean is
11753 while Present
(N
) loop
11754 if not (All_Static_Choices
(Discrete_Choices
(N
))
11755 and then Is_OK_Static_Expression
(Expression
(N
)))
11764 end All_Static_Case_Alternatives
;
11766 ------------------------
11767 -- All_Static_Choices --
11768 ------------------------
11770 function All_Static_Choices
(L
: List_Id
) return Boolean is
11775 while Present
(N
) loop
11776 if not Is_Static_Choice
(N
) then
11784 end All_Static_Choices
;
11786 ----------------------
11787 -- Is_Static_Choice --
11788 ----------------------
11790 function Is_Static_Choice
(N
: Node_Id
) return Boolean is
11792 return Nkind
(N
) = N_Others_Choice
11793 or else Is_OK_Static_Expression
(N
)
11794 or else (Is_Entity_Name
(N
) and then Is_Type
(Entity
(N
))
11795 and then Is_OK_Static_Subtype
(Entity
(N
)))
11796 or else (Nkind
(N
) = N_Subtype_Indication
11797 and then Is_OK_Static_Subtype
(Entity
(N
)))
11798 or else (Nkind
(N
) = N_Range
and then Is_OK_Static_Range
(N
));
11799 end Is_Static_Choice
;
11805 function Is_Type_Ref
(N
: Node_Id
) return Boolean is
11807 return (Nkind
(N
) = N_Identifier
11808 and then Chars
(N
) = Nam
11809 and then Paren_Count
(N
) = 0)
11810 or else Nkind
(N
) = N_Function_Call
;
11813 -- Start of processing for Is_Predicate_Static
11816 -- Predicate_Static means one of the following holds. Numbers are the
11817 -- corresponding paragraph numbers in (RM 3.2.4(16-22)).
11819 -- 16: A static expression
11821 if Is_OK_Static_Expression
(Expr
) then
11824 -- 17: A membership test whose simple_expression is the current
11825 -- instance, and whose membership_choice_list meets the requirements
11826 -- for a static membership test.
11828 elsif Nkind
(Expr
) in N_Membership_Test
11829 and then ((Present
(Right_Opnd
(Expr
))
11830 and then Is_Static_Choice
(Right_Opnd
(Expr
)))
11832 (Present
(Alternatives
(Expr
))
11833 and then All_Static_Choices
(Alternatives
(Expr
))))
11837 -- 18. A case_expression whose selecting_expression is the current
11838 -- instance, and whose dependent expressions are static expressions.
11840 elsif Nkind
(Expr
) = N_Case_Expression
11841 and then Is_Type_Ref
(Expression
(Expr
))
11842 and then All_Static_Case_Alternatives
(Alternatives
(Expr
))
11846 -- 19. A call to a predefined equality or ordering operator, where one
11847 -- operand is the current instance, and the other is a static
11850 -- Note: the RM is clearly wrong here in not excluding string types.
11851 -- Without this exclusion, we would allow expressions like X > "ABC"
11852 -- to be considered as predicate-static, which is clearly not intended,
11853 -- since the idea is for predicate-static to be a subset of normal
11854 -- static expressions (and "DEF" > "ABC" is not a static expression).
11856 -- However, we do allow internally generated (not from source) equality
11857 -- and inequality operations to be valid on strings (this helps deal
11858 -- with cases where we transform A in "ABC" to A = "ABC).
11860 -- In fact, it appears that the intent of the ARG is to extend static
11861 -- predicates to strings, and that the extension should probably apply
11862 -- to static expressions themselves. The code below accepts comparison
11863 -- operators that apply to static strings.
11865 elsif Nkind
(Expr
) in N_Op_Compare
11866 and then ((Is_Type_Ref
(Left_Opnd
(Expr
))
11867 and then Is_OK_Static_Expression
(Right_Opnd
(Expr
)))
11869 (Is_Type_Ref
(Right_Opnd
(Expr
))
11870 and then Is_OK_Static_Expression
(Left_Opnd
(Expr
))))
11874 -- 20. A call to a predefined boolean logical operator, where each
11875 -- operand is predicate-static.
11877 elsif (Nkind_In
(Expr
, N_Op_And
, N_Op_Or
, N_Op_Xor
)
11878 and then Is_Predicate_Static
(Left_Opnd
(Expr
), Nam
)
11879 and then Is_Predicate_Static
(Right_Opnd
(Expr
), Nam
))
11881 (Nkind
(Expr
) = N_Op_Not
11882 and then Is_Predicate_Static
(Right_Opnd
(Expr
), Nam
))
11886 -- 21. A short-circuit control form where both operands are
11887 -- predicate-static.
11889 elsif Nkind
(Expr
) in N_Short_Circuit
11890 and then Is_Predicate_Static
(Left_Opnd
(Expr
), Nam
)
11891 and then Is_Predicate_Static
(Right_Opnd
(Expr
), Nam
)
11895 -- 22. A parenthesized predicate-static expression. This does not
11896 -- require any special test, since we just ignore paren levels in
11897 -- all the cases above.
11899 -- One more test that is an implementation artifact caused by the fact
11900 -- that we are analyzing not the original expression, but the generated
11901 -- expression in the body of the predicate function. This can include
11902 -- references to inherited predicates, so that the expression we are
11903 -- processing looks like:
11905 -- xxPredicate (typ (Inns)) and then expression
11907 -- Where the call is to a Predicate function for an inherited predicate.
11908 -- We simply ignore such a call, which could be to either a dynamic or
11909 -- a static predicate. Note that if the parent predicate is dynamic then
11910 -- eventually this type will be marked as dynamic, but you are allowed
11911 -- to specify a static predicate for a subtype which is inheriting a
11912 -- dynamic predicate, so the static predicate validation here ignores
11913 -- the inherited predicate even if it is dynamic.
11914 -- In all cases, a static predicate can only apply to a scalar type.
11916 elsif Nkind
(Expr
) = N_Function_Call
11917 and then Is_Predicate_Function
(Entity
(Name
(Expr
)))
11918 and then Is_Scalar_Type
(Etype
(First_Entity
(Entity
(Name
(Expr
)))))
11922 -- That's an exhaustive list of tests, all other cases are not
11923 -- predicate-static, so we return False.
11928 end Is_Predicate_Static
;
11930 ---------------------
11931 -- Kill_Rep_Clause --
11932 ---------------------
11934 procedure Kill_Rep_Clause
(N
: Node_Id
) is
11936 pragma Assert
(Ignore_Rep_Clauses
);
11938 -- Note: we use Replace rather than Rewrite, because we don't want
11939 -- ASIS to be able to use Original_Node to dig out the (undecorated)
11940 -- rep clause that is being replaced.
11942 Replace
(N
, Make_Null_Statement
(Sloc
(N
)));
11944 -- The null statement must be marked as not coming from source. This is
11945 -- so that ASIS ignores it, and also the back end does not expect bogus
11946 -- "from source" null statements in weird places (e.g. in declarative
11947 -- regions where such null statements are not allowed).
11949 Set_Comes_From_Source
(N
, False);
11950 end Kill_Rep_Clause
;
11956 function Minimum_Size
11958 Biased
: Boolean := False) return Nat
11960 Lo
: Uint
:= No_Uint
;
11961 Hi
: Uint
:= No_Uint
;
11962 LoR
: Ureal
:= No_Ureal
;
11963 HiR
: Ureal
:= No_Ureal
;
11964 LoSet
: Boolean := False;
11965 HiSet
: Boolean := False;
11968 Ancest
: Entity_Id
;
11969 R_Typ
: constant Entity_Id
:= Root_Type
(T
);
11972 -- If bad type, return 0
11974 if T
= Any_Type
then
11977 -- For generic types, just return zero. There cannot be any legitimate
11978 -- need to know such a size, but this routine may be called with a
11979 -- generic type as part of normal processing.
11981 elsif Is_Generic_Type
(R_Typ
) or else R_Typ
= Any_Type
then
11984 -- Access types (cannot have size smaller than System.Address)
11986 elsif Is_Access_Type
(T
) then
11987 return System_Address_Size
;
11989 -- Floating-point types
11991 elsif Is_Floating_Point_Type
(T
) then
11992 return UI_To_Int
(Esize
(R_Typ
));
11996 elsif Is_Discrete_Type
(T
) then
11998 -- The following loop is looking for the nearest compile time known
11999 -- bounds following the ancestor subtype chain. The idea is to find
12000 -- the most restrictive known bounds information.
12004 if Ancest
= Any_Type
or else Etype
(Ancest
) = Any_Type
then
12009 if Compile_Time_Known_Value
(Type_Low_Bound
(Ancest
)) then
12010 Lo
:= Expr_Rep_Value
(Type_Low_Bound
(Ancest
));
12017 if Compile_Time_Known_Value
(Type_High_Bound
(Ancest
)) then
12018 Hi
:= Expr_Rep_Value
(Type_High_Bound
(Ancest
));
12024 Ancest
:= Ancestor_Subtype
(Ancest
);
12026 if No
(Ancest
) then
12027 Ancest
:= Base_Type
(T
);
12029 if Is_Generic_Type
(Ancest
) then
12035 -- Fixed-point types. We can't simply use Expr_Value to get the
12036 -- Corresponding_Integer_Value values of the bounds, since these do not
12037 -- get set till the type is frozen, and this routine can be called
12038 -- before the type is frozen. Similarly the test for bounds being static
12039 -- needs to include the case where we have unanalyzed real literals for
12040 -- the same reason.
12042 elsif Is_Fixed_Point_Type
(T
) then
12044 -- The following loop is looking for the nearest compile time known
12045 -- bounds following the ancestor subtype chain. The idea is to find
12046 -- the most restrictive known bounds information.
12050 if Ancest
= Any_Type
or else Etype
(Ancest
) = Any_Type
then
12054 -- Note: In the following two tests for LoSet and HiSet, it may
12055 -- seem redundant to test for N_Real_Literal here since normally
12056 -- one would assume that the test for the value being known at
12057 -- compile time includes this case. However, there is a glitch.
12058 -- If the real literal comes from folding a non-static expression,
12059 -- then we don't consider any non- static expression to be known
12060 -- at compile time if we are in configurable run time mode (needed
12061 -- in some cases to give a clearer definition of what is and what
12062 -- is not accepted). So the test is indeed needed. Without it, we
12063 -- would set neither Lo_Set nor Hi_Set and get an infinite loop.
12066 if Nkind
(Type_Low_Bound
(Ancest
)) = N_Real_Literal
12067 or else Compile_Time_Known_Value
(Type_Low_Bound
(Ancest
))
12069 LoR
:= Expr_Value_R
(Type_Low_Bound
(Ancest
));
12076 if Nkind
(Type_High_Bound
(Ancest
)) = N_Real_Literal
12077 or else Compile_Time_Known_Value
(Type_High_Bound
(Ancest
))
12079 HiR
:= Expr_Value_R
(Type_High_Bound
(Ancest
));
12085 Ancest
:= Ancestor_Subtype
(Ancest
);
12087 if No
(Ancest
) then
12088 Ancest
:= Base_Type
(T
);
12090 if Is_Generic_Type
(Ancest
) then
12096 Lo
:= UR_To_Uint
(LoR
/ Small_Value
(T
));
12097 Hi
:= UR_To_Uint
(HiR
/ Small_Value
(T
));
12099 -- No other types allowed
12102 raise Program_Error
;
12105 -- Fall through with Hi and Lo set. Deal with biased case
12108 and then not Is_Fixed_Point_Type
(T
)
12109 and then not (Is_Enumeration_Type
(T
)
12110 and then Has_Non_Standard_Rep
(T
)))
12111 or else Has_Biased_Representation
(T
)
12117 -- Null range case, size is always zero. We only do this in the discrete
12118 -- type case, since that's the odd case that came up. Probably we should
12119 -- also do this in the fixed-point case, but doing so causes peculiar
12120 -- gigi failures, and it is not worth worrying about this incredibly
12121 -- marginal case (explicit null-range fixed-point type declarations)???
12123 if Lo
> Hi
and then Is_Discrete_Type
(T
) then
12126 -- Signed case. Note that we consider types like range 1 .. -1 to be
12127 -- signed for the purpose of computing the size, since the bounds have
12128 -- to be accommodated in the base type.
12130 elsif Lo
< 0 or else Hi
< 0 then
12134 -- S = size, B = 2 ** (size - 1) (can accommodate -B .. +(B - 1))
12135 -- Note that we accommodate the case where the bounds cross. This
12136 -- can happen either because of the way the bounds are declared
12137 -- or because of the algorithm in Freeze_Fixed_Point_Type.
12151 -- If both bounds are positive, make sure that both are represen-
12152 -- table in the case where the bounds are crossed. This can happen
12153 -- either because of the way the bounds are declared, or because of
12154 -- the algorithm in Freeze_Fixed_Point_Type.
12160 -- S = size, (can accommodate 0 .. (2**size - 1))
12163 while Hi
>= Uint_2
** S
loop
12171 ---------------------------
12172 -- New_Stream_Subprogram --
12173 ---------------------------
12175 procedure New_Stream_Subprogram
12179 Nam
: TSS_Name_Type
)
12181 Loc
: constant Source_Ptr
:= Sloc
(N
);
12182 Sname
: constant Name_Id
:= Make_TSS_Name
(Base_Type
(Ent
), Nam
);
12183 Subp_Id
: Entity_Id
;
12184 Subp_Decl
: Node_Id
;
12188 Defer_Declaration
: constant Boolean :=
12189 Is_Tagged_Type
(Ent
) or else Is_Private_Type
(Ent
);
12190 -- For a tagged type, there is a declaration for each stream attribute
12191 -- at the freeze point, and we must generate only a completion of this
12192 -- declaration. We do the same for private types, because the full view
12193 -- might be tagged. Otherwise we generate a declaration at the point of
12194 -- the attribute definition clause. If the attribute definition comes
12195 -- from an aspect specification the declaration is part of the freeze
12196 -- actions of the type.
12198 function Build_Spec
return Node_Id
;
12199 -- Used for declaration and renaming declaration, so that this is
12200 -- treated as a renaming_as_body.
12206 function Build_Spec
return Node_Id
is
12207 Out_P
: constant Boolean := (Nam
= TSS_Stream_Read
);
12210 T_Ref
: constant Node_Id
:= New_Occurrence_Of
(Etyp
, Loc
);
12213 Subp_Id
:= Make_Defining_Identifier
(Loc
, Sname
);
12215 -- S : access Root_Stream_Type'Class
12217 Formals
:= New_List
(
12218 Make_Parameter_Specification
(Loc
,
12219 Defining_Identifier
=>
12220 Make_Defining_Identifier
(Loc
, Name_S
),
12222 Make_Access_Definition
(Loc
,
12224 New_Occurrence_Of
(
12225 Designated_Type
(Etype
(F
)), Loc
))));
12227 if Nam
= TSS_Stream_Input
then
12229 Make_Function_Specification
(Loc
,
12230 Defining_Unit_Name
=> Subp_Id
,
12231 Parameter_Specifications
=> Formals
,
12232 Result_Definition
=> T_Ref
);
12236 Append_To
(Formals
,
12237 Make_Parameter_Specification
(Loc
,
12238 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_V
),
12239 Out_Present
=> Out_P
,
12240 Parameter_Type
=> T_Ref
));
12243 Make_Procedure_Specification
(Loc
,
12244 Defining_Unit_Name
=> Subp_Id
,
12245 Parameter_Specifications
=> Formals
);
12251 -- Start of processing for New_Stream_Subprogram
12254 F
:= First_Formal
(Subp
);
12256 if Ekind
(Subp
) = E_Procedure
then
12257 Etyp
:= Etype
(Next_Formal
(F
));
12259 Etyp
:= Etype
(Subp
);
12262 -- Prepare subprogram declaration and insert it as an action on the
12263 -- clause node. The visibility for this entity is used to test for
12264 -- visibility of the attribute definition clause (in the sense of
12265 -- 8.3(23) as amended by AI-195).
12267 if not Defer_Declaration
then
12269 Make_Subprogram_Declaration
(Loc
,
12270 Specification
=> Build_Spec
);
12272 -- For a tagged type, there is always a visible declaration for each
12273 -- stream TSS (it is a predefined primitive operation), and the
12274 -- completion of this declaration occurs at the freeze point, which is
12275 -- not always visible at places where the attribute definition clause is
12276 -- visible. So, we create a dummy entity here for the purpose of
12277 -- tracking the visibility of the attribute definition clause itself.
12281 Make_Defining_Identifier
(Loc
, New_External_Name
(Sname
, 'V'));
12283 Make_Object_Declaration
(Loc
,
12284 Defining_Identifier
=> Subp_Id
,
12285 Object_Definition
=> New_Occurrence_Of
(Standard_Boolean
, Loc
));
12288 if not Defer_Declaration
12289 and then From_Aspect_Specification
(N
)
12290 and then Has_Delayed_Freeze
(Ent
)
12292 Append_Freeze_Action
(Ent
, Subp_Decl
);
12295 Insert_Action
(N
, Subp_Decl
);
12296 Set_Entity
(N
, Subp_Id
);
12300 Make_Subprogram_Renaming_Declaration
(Loc
,
12301 Specification
=> Build_Spec
,
12302 Name
=> New_Occurrence_Of
(Subp
, Loc
));
12304 if Defer_Declaration
then
12305 Set_TSS
(Base_Type
(Ent
), Subp_Id
);
12308 if From_Aspect_Specification
(N
) then
12309 Append_Freeze_Action
(Ent
, Subp_Decl
);
12311 Insert_Action
(N
, Subp_Decl
);
12314 Copy_TSS
(Subp_Id
, Base_Type
(Ent
));
12316 end New_Stream_Subprogram
;
12318 ------------------------------------------
12319 -- Push_Scope_And_Install_Discriminants --
12320 ------------------------------------------
12322 procedure Push_Scope_And_Install_Discriminants
(E
: Entity_Id
) is
12324 if Has_Discriminants
(E
) then
12327 -- Make the discriminants visible for type declarations and protected
12328 -- type declarations, not for subtype declarations (RM 13.1.1 (12/3))
12330 if Nkind
(Parent
(E
)) /= N_Subtype_Declaration
then
12331 Install_Discriminants
(E
);
12334 end Push_Scope_And_Install_Discriminants
;
12336 -----------------------------------
12337 -- Register_Address_Clause_Check --
12338 -----------------------------------
12340 procedure Register_Address_Clause_Check
12347 ACS
: constant Boolean := Scope_Suppress
.Suppress
(Alignment_Check
);
12349 Address_Clause_Checks
.Append
((N
, X
, A
, Y
, Off
, ACS
));
12350 end Register_Address_Clause_Check
;
12352 ------------------------
12353 -- Rep_Item_Too_Early --
12354 ------------------------
12356 function Rep_Item_Too_Early
(T
: Entity_Id
; N
: Node_Id
) return Boolean is
12358 -- Cannot apply non-operational rep items to generic types
12360 if Is_Operational_Item
(N
) then
12364 and then Is_Generic_Type
(Root_Type
(T
))
12365 and then (Nkind
(N
) /= N_Pragma
12366 or else Get_Pragma_Id
(N
) /= Pragma_Convention
)
12368 Error_Msg_N
("representation item not allowed for generic type", N
);
12372 -- Otherwise check for incomplete type
12374 if Is_Incomplete_Or_Private_Type
(T
)
12375 and then No
(Underlying_Type
(T
))
12377 (Nkind
(N
) /= N_Pragma
12378 or else Get_Pragma_Id
(N
) /= Pragma_Import
)
12381 ("representation item must be after full type declaration", N
);
12384 -- If the type has incomplete components, a representation clause is
12385 -- illegal but stream attributes and Convention pragmas are correct.
12387 elsif Has_Private_Component
(T
) then
12388 if Nkind
(N
) = N_Pragma
then
12393 ("representation item must appear after type is fully defined",
12400 end Rep_Item_Too_Early
;
12402 -----------------------
12403 -- Rep_Item_Too_Late --
12404 -----------------------
12406 function Rep_Item_Too_Late
12409 FOnly
: Boolean := False) return Boolean
12412 Parent_Type
: Entity_Id
;
12414 procedure No_Type_Rep_Item
;
12415 -- Output message indicating that no type-related aspects can be
12416 -- specified due to some property of the parent type.
12418 procedure Too_Late
;
12419 -- Output message for an aspect being specified too late
12421 -- Note that neither of the above errors is considered a serious one,
12422 -- since the effect is simply that we ignore the representation clause
12424 -- Is this really true? In any case if we make this change we must
12425 -- document the requirement in the spec of Rep_Item_Too_Late that
12426 -- if True is returned, then the rep item must be completely ignored???
12428 ----------------------
12429 -- No_Type_Rep_Item --
12430 ----------------------
12432 procedure No_Type_Rep_Item
is
12434 Error_Msg_N
("|type-related representation item not permitted!", N
);
12435 end No_Type_Rep_Item
;
12441 procedure Too_Late
is
12443 -- Other compilers seem more relaxed about rep items appearing too
12444 -- late. Since analysis tools typically don't care about rep items
12445 -- anyway, no reason to be too strict about this.
12447 if not Relaxed_RM_Semantics
then
12448 Error_Msg_N
("|representation item appears too late!", N
);
12452 -- Start of processing for Rep_Item_Too_Late
12455 -- First make sure entity is not frozen (RM 13.1(9))
12459 -- Exclude imported types, which may be frozen if they appear in a
12460 -- representation clause for a local type.
12462 and then not From_Limited_With
(T
)
12464 -- Exclude generated entities (not coming from source). The common
12465 -- case is when we generate a renaming which prematurely freezes the
12466 -- renamed internal entity, but we still want to be able to set copies
12467 -- of attribute values such as Size/Alignment.
12469 and then Comes_From_Source
(T
)
12471 -- A self-referential aspect is illegal if it forces freezing the
12472 -- entity before the corresponding pragma has been analyzed.
12474 if Nkind_In
(N
, N_Attribute_Definition_Clause
, N_Pragma
)
12475 and then From_Aspect_Specification
(N
)
12478 ("aspect specification causes premature freezing of&", N
, T
);
12479 Set_Has_Delayed_Freeze
(T
, False);
12484 S
:= First_Subtype
(T
);
12486 if Present
(Freeze_Node
(S
)) then
12487 if not Relaxed_RM_Semantics
then
12489 ("??no more representation items for }", Freeze_Node
(S
), S
);
12495 -- Check for case of untagged derived type whose parent either has
12496 -- primitive operations, or is a by reference type (RM 13.1(10)). In
12497 -- this case we do not output a Too_Late message, since there is no
12498 -- earlier point where the rep item could be placed to make it legal.
12502 and then Is_Derived_Type
(T
)
12503 and then not Is_Tagged_Type
(T
)
12505 Parent_Type
:= Etype
(Base_Type
(T
));
12507 if Has_Primitive_Operations
(Parent_Type
) then
12510 if not Relaxed_RM_Semantics
then
12512 ("\parent type & has primitive operations!", N
, Parent_Type
);
12517 elsif Is_By_Reference_Type
(Parent_Type
) then
12520 if not Relaxed_RM_Semantics
then
12522 ("\parent type & is a by reference type!", N
, Parent_Type
);
12529 -- No error, but one more warning to consider. The RM (surprisingly)
12530 -- allows this pattern:
12533 -- primitive operations for S
12534 -- type R is new S;
12535 -- rep clause for S
12537 -- Meaning that calls on the primitive operations of S for values of
12538 -- type R may require possibly expensive implicit conversion operations.
12539 -- This is not an error, but is worth a warning.
12541 if not Relaxed_RM_Semantics
and then Is_Type
(T
) then
12543 DTL
: constant Entity_Id
:= Derived_Type_Link
(Base_Type
(T
));
12547 and then Has_Primitive_Operations
(Base_Type
(T
))
12549 -- For now, do not generate this warning for the case of aspect
12550 -- specification using Ada 2012 syntax, since we get wrong
12551 -- messages we do not understand. The whole business of derived
12552 -- types and rep items seems a bit confused when aspects are
12553 -- used, since the aspects are not evaluated till freeze time.
12555 and then not From_Aspect_Specification
(N
)
12557 Error_Msg_Sloc
:= Sloc
(DTL
);
12559 ("representation item for& appears after derived type "
12560 & "declaration#??", N
);
12562 ("\may result in implicit conversions for primitive "
12563 & "operations of&??", N
, T
);
12565 ("\to change representations when called with arguments "
12566 & "of type&??", N
, DTL
);
12571 -- No error, link item into head of chain of rep items for the entity,
12572 -- but avoid chaining if we have an overloadable entity, and the pragma
12573 -- is one that can apply to multiple overloaded entities.
12575 if Is_Overloadable
(T
) and then Nkind
(N
) = N_Pragma
then
12577 Pname
: constant Name_Id
:= Pragma_Name
(N
);
12579 if Nam_In
(Pname
, Name_Convention
, Name_Import
, Name_Export
,
12580 Name_External
, Name_Interface
)
12587 Record_Rep_Item
(T
, N
);
12589 end Rep_Item_Too_Late
;
12591 -------------------------------------
12592 -- Replace_Type_References_Generic --
12593 -------------------------------------
12595 procedure Replace_Type_References_Generic
(N
: Node_Id
; T
: Entity_Id
) is
12596 TName
: constant Name_Id
:= Chars
(T
);
12598 function Replace_Type_Ref
(N
: Node_Id
) return Traverse_Result
;
12599 -- Processes a single node in the traversal procedure below, checking
12600 -- if node N should be replaced, and if so, doing the replacement.
12602 function Visible_Component
(Comp
: Name_Id
) return Entity_Id
;
12603 -- Given an identifier in the expression, check whether there is a
12604 -- discriminant or component of the type that is directy visible, and
12605 -- rewrite it as the corresponding selected component of the formal of
12606 -- the subprogram. The entity is located by a sequential search, which
12607 -- seems acceptable given the typical size of component lists and check
12608 -- expressions. Possible optimization ???
12610 ----------------------
12611 -- Replace_Type_Ref --
12612 ----------------------
12614 function Replace_Type_Ref
(N
: Node_Id
) return Traverse_Result
is
12615 Loc
: constant Source_Ptr
:= Sloc
(N
);
12617 procedure Add_Prefix
(Ref
: Node_Id
; Comp
: Entity_Id
);
12618 -- Add the proper prefix to a reference to a component of the type
12619 -- when it is not already a selected component.
12625 procedure Add_Prefix
(Ref
: Node_Id
; Comp
: Entity_Id
) is
12628 Make_Selected_Component
(Loc
,
12629 Prefix
=> New_Occurrence_Of
(T
, Loc
),
12630 Selector_Name
=> New_Occurrence_Of
(Comp
, Loc
)));
12631 Replace_Type_Reference
(Prefix
(Ref
));
12640 -- Start of processing for Replace_Type_Ref
12643 if Nkind
(N
) = N_Identifier
then
12645 -- If not the type name, check whether it is a reference to some
12646 -- other type, which must be frozen before the predicate function
12647 -- is analyzed, i.e. before the freeze node of the type to which
12648 -- the predicate applies.
12650 if Chars
(N
) /= TName
then
12651 if Present
(Current_Entity
(N
))
12652 and then Is_Type
(Current_Entity
(N
))
12654 Freeze_Before
(Freeze_Node
(T
), Current_Entity
(N
));
12657 -- The components of the type are directly visible and can
12658 -- be referenced without a prefix.
12660 if Nkind
(Parent
(N
)) = N_Selected_Component
then
12663 -- In expression C (I), C may be a directly visible function
12664 -- or a visible component that has an array type. Disambiguate
12665 -- by examining the component type.
12667 elsif Nkind
(Parent
(N
)) = N_Indexed_Component
12668 and then N
= Prefix
(Parent
(N
))
12670 Comp
:= Visible_Component
(Chars
(N
));
12672 if Present
(Comp
) and then Is_Array_Type
(Etype
(Comp
)) then
12673 Add_Prefix
(N
, Comp
);
12677 Comp
:= Visible_Component
(Chars
(N
));
12679 if Present
(Comp
) then
12680 Add_Prefix
(N
, Comp
);
12686 -- Otherwise do the replacement if this is not a qualified
12687 -- reference to a homograph of the type itself. Note that the
12688 -- current instance could not appear in such a context, e.g.
12689 -- the prefix of a type conversion.
12692 if Nkind
(Parent
(N
)) /= N_Selected_Component
12693 or else N
/= Selector_Name
(Parent
(N
))
12695 Replace_Type_Reference
(N
);
12701 -- Case of selected component (which is what a qualification looks
12702 -- like in the unanalyzed tree, which is what we have.
12704 elsif Nkind
(N
) = N_Selected_Component
then
12706 -- If selector name is not our type, keep going (we might still
12707 -- have an occurrence of the type in the prefix).
12709 if Nkind
(Selector_Name
(N
)) /= N_Identifier
12710 or else Chars
(Selector_Name
(N
)) /= TName
12714 -- Selector name is our type, check qualification
12717 -- Loop through scopes and prefixes, doing comparison
12719 Scop
:= Current_Scope
;
12720 Pref
:= Prefix
(N
);
12722 -- Continue if no more scopes or scope with no name
12724 if No
(Scop
) or else Nkind
(Scop
) not in N_Has_Chars
then
12728 -- Do replace if prefix is an identifier matching the scope
12729 -- that we are currently looking at.
12731 if Nkind
(Pref
) = N_Identifier
12732 and then Chars
(Pref
) = Chars
(Scop
)
12734 Replace_Type_Reference
(N
);
12738 -- Go check scope above us if prefix is itself of the form
12739 -- of a selected component, whose selector matches the scope
12740 -- we are currently looking at.
12742 if Nkind
(Pref
) = N_Selected_Component
12743 and then Nkind
(Selector_Name
(Pref
)) = N_Identifier
12744 and then Chars
(Selector_Name
(Pref
)) = Chars
(Scop
)
12746 Scop
:= Scope
(Scop
);
12747 Pref
:= Prefix
(Pref
);
12749 -- For anything else, we don't have a match, so keep on
12750 -- going, there are still some weird cases where we may
12751 -- still have a replacement within the prefix.
12759 -- Continue for any other node kind
12764 end Replace_Type_Ref
;
12766 procedure Replace_Type_Refs
is new Traverse_Proc
(Replace_Type_Ref
);
12768 -----------------------
12769 -- Visible_Component --
12770 -----------------------
12772 function Visible_Component
(Comp
: Name_Id
) return Entity_Id
is
12776 -- Types with nameable components are records and discriminated
12779 if Ekind
(T
) = E_Record_Type
12780 or else (Is_Private_Type
(T
) and then Has_Discriminants
(T
))
12782 E
:= First_Entity
(T
);
12783 while Present
(E
) loop
12784 if Comes_From_Source
(E
) and then Chars
(E
) = Comp
then
12792 -- Nothing by that name, or the type has no components
12795 end Visible_Component
;
12797 -- Start of processing for Replace_Type_References_Generic
12800 Replace_Type_Refs
(N
);
12801 end Replace_Type_References_Generic
;
12803 --------------------------------
12804 -- Resolve_Aspect_Expressions --
12805 --------------------------------
12807 procedure Resolve_Aspect_Expressions
(E
: Entity_Id
) is
12808 function Resolve_Name
(N
: Node_Id
) return Traverse_Result
;
12809 -- Verify that all identifiers in the expression, with the exception
12810 -- of references to the current entity, denote visible entities. This
12811 -- is done only to detect visibility errors, as the expression will be
12812 -- properly analyzed/expanded during analysis of the predicate function
12813 -- body. We omit quantified expressions from this test, given that they
12814 -- introduce a local identifier that would require proper expansion to
12815 -- handle properly.
12817 -- In ASIS_Mode we preserve the entity in the source because there is
12818 -- no subsequent expansion to decorate the tree.
12824 function Resolve_Name
(N
: Node_Id
) return Traverse_Result
is
12825 Dummy
: Traverse_Result
;
12828 if Nkind
(N
) = N_Selected_Component
then
12829 if Nkind
(Prefix
(N
)) = N_Identifier
12830 and then Chars
(Prefix
(N
)) /= Chars
(E
)
12832 Find_Selected_Component
(N
);
12837 -- Resolve identifiers that are not selectors in parameter
12838 -- associations (these are never resolved by visibility).
12840 elsif Nkind
(N
) = N_Identifier
12841 and then Chars
(N
) /= Chars
(E
)
12842 and then (Nkind
(Parent
(N
)) /= N_Parameter_Association
12843 or else N
/= Selector_Name
(Parent
(N
)))
12845 Find_Direct_Name
(N
);
12847 -- In ASIS mode we must analyze overloaded identifiers to ensure
12848 -- their correct decoration because expansion is disabled (and
12849 -- the expansion of freeze nodes takes care of resolving aspect
12853 if Is_Overloaded
(N
) then
12854 Analyze
(Parent
(N
));
12857 Set_Entity
(N
, Empty
);
12860 -- The name is component association needs no resolution.
12862 elsif Nkind
(N
) = N_Component_Association
then
12863 Dummy
:= Resolve_Name
(Expression
(N
));
12866 elsif Nkind
(N
) = N_Quantified_Expression
then
12873 procedure Resolve_Aspect_Expression
is new Traverse_Proc
(Resolve_Name
);
12877 ASN
: Node_Id
:= First_Rep_Item
(E
);
12879 -- Start of processing for Resolve_Aspect_Expressions
12882 -- Need to make sure discriminants, if any, are directly visible
12884 Push_Scope_And_Install_Discriminants
(E
);
12886 while Present
(ASN
) loop
12887 if Nkind
(ASN
) = N_Aspect_Specification
and then Entity
(ASN
) = E
then
12889 A_Id
: constant Aspect_Id
:= Get_Aspect_Id
(ASN
);
12890 Expr
: constant Node_Id
:= Expression
(ASN
);
12895 -- For now we only deal with aspects that do not generate
12896 -- subprograms, or that may mention current instances of
12897 -- types. These will require special handling (???TBD).
12899 when Aspect_Invariant
12901 | Aspect_Predicate_Failure
12905 when Aspect_Dynamic_Predicate
12906 | Aspect_Static_Predicate
12908 -- Build predicate function specification and preanalyze
12909 -- expression after type replacement. The function
12910 -- declaration must be analyzed in the scope of the
12911 -- type, but the expression must see components.
12913 if No
(Predicate_Function
(E
)) then
12914 Uninstall_Discriminants_And_Pop_Scope
(E
);
12916 FDecl
: constant Node_Id
:=
12917 Build_Predicate_Function_Declaration
(E
);
12918 pragma Unreferenced
(FDecl
);
12921 Push_Scope_And_Install_Discriminants
(E
);
12922 Resolve_Aspect_Expression
(Expr
);
12926 when Pre_Post_Aspects
=>
12929 when Aspect_Iterable
=>
12930 if Nkind
(Expr
) = N_Aggregate
then
12935 Assoc
:= First
(Component_Associations
(Expr
));
12936 while Present
(Assoc
) loop
12937 Find_Direct_Name
(Expression
(Assoc
));
12943 -- The expression for Default_Value is a static expression
12944 -- of the type, but this expression does not freeze the
12945 -- type, so it can still appear in a representation clause
12946 -- before the actual freeze point.
12948 when Aspect_Default_Value
=>
12949 Set_Must_Not_Freeze
(Expr
);
12950 Preanalyze_Spec_Expression
(Expr
, E
);
12952 -- Ditto for Storage_Size. Any other aspects that carry
12953 -- expressions that should not freeze ??? This is only
12954 -- relevant to the misuse of deferred constants.
12956 when Aspect_Storage_Size
=>
12957 Set_Must_Not_Freeze
(Expr
);
12958 Preanalyze_Spec_Expression
(Expr
, Any_Integer
);
12961 if Present
(Expr
) then
12962 case Aspect_Argument
(A_Id
) is
12964 | Optional_Expression
12966 Analyze_And_Resolve
(Expr
);
12971 if Nkind
(Expr
) = N_Identifier
then
12972 Find_Direct_Name
(Expr
);
12974 elsif Nkind
(Expr
) = N_Selected_Component
then
12975 Find_Selected_Component
(Expr
);
12983 ASN
:= Next_Rep_Item
(ASN
);
12986 Uninstall_Discriminants_And_Pop_Scope
(E
);
12987 end Resolve_Aspect_Expressions
;
12989 -------------------------
12990 -- Same_Representation --
12991 -------------------------
12993 function Same_Representation
(Typ1
, Typ2
: Entity_Id
) return Boolean is
12994 T1
: constant Entity_Id
:= Underlying_Type
(Typ1
);
12995 T2
: constant Entity_Id
:= Underlying_Type
(Typ2
);
12998 -- A quick check, if base types are the same, then we definitely have
12999 -- the same representation, because the subtype specific representation
13000 -- attributes (Size and Alignment) do not affect representation from
13001 -- the point of view of this test.
13003 if Base_Type
(T1
) = Base_Type
(T2
) then
13006 elsif Is_Private_Type
(Base_Type
(T2
))
13007 and then Base_Type
(T1
) = Full_View
(Base_Type
(T2
))
13012 -- Tagged types always have the same representation, because it is not
13013 -- possible to specify different representations for common fields.
13015 if Is_Tagged_Type
(T1
) then
13019 -- Representations are definitely different if conventions differ
13021 if Convention
(T1
) /= Convention
(T2
) then
13025 -- Representations are different if component alignments or scalar
13026 -- storage orders differ.
13028 if (Is_Record_Type
(T1
) or else Is_Array_Type
(T1
))
13030 (Is_Record_Type
(T2
) or else Is_Array_Type
(T2
))
13032 (Component_Alignment
(T1
) /= Component_Alignment
(T2
)
13033 or else Reverse_Storage_Order
(T1
) /= Reverse_Storage_Order
(T2
))
13038 -- For arrays, the only real issue is component size. If we know the
13039 -- component size for both arrays, and it is the same, then that's
13040 -- good enough to know we don't have a change of representation.
13042 if Is_Array_Type
(T1
) then
13043 if Known_Component_Size
(T1
)
13044 and then Known_Component_Size
(T2
)
13045 and then Component_Size
(T1
) = Component_Size
(T2
)
13051 -- For records, representations are different if reorderings differ
13053 if Is_Record_Type
(T1
)
13054 and then Is_Record_Type
(T2
)
13055 and then No_Reordering
(T1
) /= No_Reordering
(T2
)
13060 -- Types definitely have same representation if neither has non-standard
13061 -- representation since default representations are always consistent.
13062 -- If only one has non-standard representation, and the other does not,
13063 -- then we consider that they do not have the same representation. They
13064 -- might, but there is no way of telling early enough.
13066 if Has_Non_Standard_Rep
(T1
) then
13067 if not Has_Non_Standard_Rep
(T2
) then
13071 return not Has_Non_Standard_Rep
(T2
);
13074 -- Here the two types both have non-standard representation, and we need
13075 -- to determine if they have the same non-standard representation.
13077 -- For arrays, we simply need to test if the component sizes are the
13078 -- same. Pragma Pack is reflected in modified component sizes, so this
13079 -- check also deals with pragma Pack.
13081 if Is_Array_Type
(T1
) then
13082 return Component_Size
(T1
) = Component_Size
(T2
);
13084 -- Case of record types
13086 elsif Is_Record_Type
(T1
) then
13088 -- Packed status must conform
13090 if Is_Packed
(T1
) /= Is_Packed
(T2
) then
13093 -- Otherwise we must check components. Typ2 maybe a constrained
13094 -- subtype with fewer components, so we compare the components
13095 -- of the base types.
13098 Record_Case
: declare
13099 CD1
, CD2
: Entity_Id
;
13101 function Same_Rep
return Boolean;
13102 -- CD1 and CD2 are either components or discriminants. This
13103 -- function tests whether they have the same representation.
13109 function Same_Rep
return Boolean is
13111 if No
(Component_Clause
(CD1
)) then
13112 return No
(Component_Clause
(CD2
));
13114 -- Note: at this point, component clauses have been
13115 -- normalized to the default bit order, so that the
13116 -- comparison of Component_Bit_Offsets is meaningful.
13119 Present
(Component_Clause
(CD2
))
13121 Component_Bit_Offset
(CD1
) = Component_Bit_Offset
(CD2
)
13123 Esize
(CD1
) = Esize
(CD2
);
13127 -- Start of processing for Record_Case
13130 if Has_Discriminants
(T1
) then
13132 -- The number of discriminants may be different if the
13133 -- derived type has fewer (constrained by values). The
13134 -- invisible discriminants retain the representation of
13135 -- the original, so the discrepancy does not per se
13136 -- indicate a different representation.
13138 CD1
:= First_Discriminant
(T1
);
13139 CD2
:= First_Discriminant
(T2
);
13140 while Present
(CD1
) and then Present
(CD2
) loop
13141 if not Same_Rep
then
13144 Next_Discriminant
(CD1
);
13145 Next_Discriminant
(CD2
);
13150 CD1
:= First_Component
(Underlying_Type
(Base_Type
(T1
)));
13151 CD2
:= First_Component
(Underlying_Type
(Base_Type
(T2
)));
13152 while Present
(CD1
) loop
13153 if not Same_Rep
then
13156 Next_Component
(CD1
);
13157 Next_Component
(CD2
);
13165 -- For enumeration types, we must check each literal to see if the
13166 -- representation is the same. Note that we do not permit enumeration
13167 -- representation clauses for Character and Wide_Character, so these
13168 -- cases were already dealt with.
13170 elsif Is_Enumeration_Type
(T1
) then
13171 Enumeration_Case
: declare
13172 L1
, L2
: Entity_Id
;
13175 L1
:= First_Literal
(T1
);
13176 L2
:= First_Literal
(T2
);
13177 while Present
(L1
) loop
13178 if Enumeration_Rep
(L1
) /= Enumeration_Rep
(L2
) then
13187 end Enumeration_Case
;
13189 -- Any other types have the same representation for these purposes
13194 end Same_Representation
;
13196 --------------------------------
13197 -- Resolve_Iterable_Operation --
13198 --------------------------------
13200 procedure Resolve_Iterable_Operation
13202 Cursor
: Entity_Id
;
13211 if not Is_Overloaded
(N
) then
13212 if not Is_Entity_Name
(N
)
13213 or else Ekind
(Entity
(N
)) /= E_Function
13214 or else Scope
(Entity
(N
)) /= Scope
(Typ
)
13215 or else No
(First_Formal
(Entity
(N
)))
13216 or else Etype
(First_Formal
(Entity
(N
))) /= Typ
13219 ("iterable primitive must be local function name whose first "
13220 & "formal is an iterable type", N
);
13225 F1
:= First_Formal
(Ent
);
13227 if Nam
= Name_First
or else Nam
= Name_Last
then
13229 -- First or Last (Container) => Cursor
13231 if Etype
(Ent
) /= Cursor
then
13232 Error_Msg_N
("primitive for First must yield a curosr", N
);
13235 elsif Nam
= Name_Next
then
13237 -- Next (Container, Cursor) => Cursor
13239 F2
:= Next_Formal
(F1
);
13241 if Etype
(F2
) /= Cursor
13242 or else Etype
(Ent
) /= Cursor
13243 or else Present
(Next_Formal
(F2
))
13245 Error_Msg_N
("no match for Next iterable primitive", N
);
13248 elsif Nam
= Name_Previous
then
13250 -- Previous (Container, Cursor) => Cursor
13252 F2
:= Next_Formal
(F1
);
13254 if Etype
(F2
) /= Cursor
13255 or else Etype
(Ent
) /= Cursor
13256 or else Present
(Next_Formal
(F2
))
13258 Error_Msg_N
("no match for Previous iterable primitive", N
);
13261 elsif Nam
= Name_Has_Element
then
13263 -- Has_Element (Container, Cursor) => Boolean
13265 F2
:= Next_Formal
(F1
);
13267 if Etype
(F2
) /= Cursor
13268 or else Etype
(Ent
) /= Standard_Boolean
13269 or else Present
(Next_Formal
(F2
))
13271 Error_Msg_N
("no match for Has_Element iterable primitive", N
);
13274 elsif Nam
= Name_Element
then
13275 F2
:= Next_Formal
(F1
);
13278 or else Etype
(F2
) /= Cursor
13279 or else Present
(Next_Formal
(F2
))
13281 Error_Msg_N
("no match for Element iterable primitive", N
);
13285 raise Program_Error
;
13289 -- Overloaded case: find subprogram with proper signature. Caller
13290 -- will report error if no match is found.
13297 Get_First_Interp
(N
, I
, It
);
13298 while Present
(It
.Typ
) loop
13299 if Ekind
(It
.Nam
) = E_Function
13300 and then Scope
(It
.Nam
) = Scope
(Typ
)
13301 and then Etype
(First_Formal
(It
.Nam
)) = Typ
13303 F1
:= First_Formal
(It
.Nam
);
13305 if Nam
= Name_First
then
13306 if Etype
(It
.Nam
) = Cursor
13307 and then No
(Next_Formal
(F1
))
13309 Set_Entity
(N
, It
.Nam
);
13313 elsif Nam
= Name_Next
then
13314 F2
:= Next_Formal
(F1
);
13317 and then No
(Next_Formal
(F2
))
13318 and then Etype
(F2
) = Cursor
13319 and then Etype
(It
.Nam
) = Cursor
13321 Set_Entity
(N
, It
.Nam
);
13325 elsif Nam
= Name_Has_Element
then
13326 F2
:= Next_Formal
(F1
);
13329 and then No
(Next_Formal
(F2
))
13330 and then Etype
(F2
) = Cursor
13331 and then Etype
(It
.Nam
) = Standard_Boolean
13333 Set_Entity
(N
, It
.Nam
);
13334 F2
:= Next_Formal
(F1
);
13338 elsif Nam
= Name_Element
then
13339 F2
:= Next_Formal
(F1
);
13342 and then No
(Next_Formal
(F2
))
13343 and then Etype
(F2
) = Cursor
13345 Set_Entity
(N
, It
.Nam
);
13351 Get_Next_Interp
(I
, It
);
13355 end Resolve_Iterable_Operation
;
13361 procedure Set_Biased
13365 Biased
: Boolean := True)
13369 Set_Has_Biased_Representation
(E
);
13371 if Warn_On_Biased_Representation
then
13373 ("?B?" & Msg
& " forces biased representation for&", N
, E
);
13378 --------------------
13379 -- Set_Enum_Esize --
13380 --------------------
13382 procedure Set_Enum_Esize
(T
: Entity_Id
) is
13388 Init_Alignment
(T
);
13390 -- Find the minimum standard size (8,16,32,64) that fits
13392 Lo
:= Enumeration_Rep
(Entity
(Type_Low_Bound
(T
)));
13393 Hi
:= Enumeration_Rep
(Entity
(Type_High_Bound
(T
)));
13396 if Lo
>= -Uint_2
**07 and then Hi
< Uint_2
**07 then
13397 Sz
:= Standard_Character_Size
; -- May be > 8 on some targets
13399 elsif Lo
>= -Uint_2
**15 and then Hi
< Uint_2
**15 then
13402 elsif Lo
>= -Uint_2
**31 and then Hi
< Uint_2
**31 then
13405 else pragma Assert
(Lo
>= -Uint_2
**63 and then Hi
< Uint_2
**63);
13410 if Hi
< Uint_2
**08 then
13411 Sz
:= Standard_Character_Size
; -- May be > 8 on some targets
13413 elsif Hi
< Uint_2
**16 then
13416 elsif Hi
< Uint_2
**32 then
13419 else pragma Assert
(Hi
< Uint_2
**63);
13424 -- That minimum is the proper size unless we have a foreign convention
13425 -- and the size required is 32 or less, in which case we bump the size
13426 -- up to 32. This is required for C and C++ and seems reasonable for
13427 -- all other foreign conventions.
13429 if Has_Foreign_Convention
(T
)
13430 and then Esize
(T
) < Standard_Integer_Size
13432 -- Don't do this if Short_Enums on target
13434 and then not Target_Short_Enums
13436 Init_Esize
(T
, Standard_Integer_Size
);
13438 Init_Esize
(T
, Sz
);
13440 end Set_Enum_Esize
;
13442 -----------------------------
13443 -- Uninstall_Discriminants --
13444 -----------------------------
13446 procedure Uninstall_Discriminants
(E
: Entity_Id
) is
13452 -- Discriminants have been made visible for type declarations and
13453 -- protected type declarations, not for subtype declarations.
13455 if Nkind
(Parent
(E
)) /= N_Subtype_Declaration
then
13456 Disc
:= First_Discriminant
(E
);
13457 while Present
(Disc
) loop
13458 if Disc
/= Current_Entity
(Disc
) then
13459 Prev
:= Current_Entity
(Disc
);
13460 while Present
(Prev
)
13461 and then Present
(Homonym
(Prev
))
13462 and then Homonym
(Prev
) /= Disc
13464 Prev
:= Homonym
(Prev
);
13470 Set_Is_Immediately_Visible
(Disc
, False);
13472 Outer
:= Homonym
(Disc
);
13473 while Present
(Outer
) and then Scope
(Outer
) = E
loop
13474 Outer
:= Homonym
(Outer
);
13477 -- Reset homonym link of other entities, but do not modify link
13478 -- between entities in current scope, so that the back end can
13479 -- have a proper count of local overloadings.
13482 Set_Name_Entity_Id
(Chars
(Disc
), Outer
);
13484 elsif Scope
(Prev
) /= Scope
(Disc
) then
13485 Set_Homonym
(Prev
, Outer
);
13488 Next_Discriminant
(Disc
);
13491 end Uninstall_Discriminants
;
13493 -------------------------------------------
13494 -- Uninstall_Discriminants_And_Pop_Scope --
13495 -------------------------------------------
13497 procedure Uninstall_Discriminants_And_Pop_Scope
(E
: Entity_Id
) is
13499 if Has_Discriminants
(E
) then
13500 Uninstall_Discriminants
(E
);
13503 end Uninstall_Discriminants_And_Pop_Scope
;
13505 ------------------------------
13506 -- Validate_Address_Clauses --
13507 ------------------------------
13509 procedure Validate_Address_Clauses
is
13510 function Offset_Value
(Expr
: Node_Id
) return Uint
;
13511 -- Given an Address attribute reference, return the value in bits of its
13512 -- offset from the first bit of the underlying entity, or 0 if it is not
13513 -- known at compile time.
13519 function Offset_Value
(Expr
: Node_Id
) return Uint
is
13520 N
: Node_Id
:= Prefix
(Expr
);
13522 Val
: Uint
:= Uint_0
;
13525 -- Climb the prefix chain and compute the cumulative offset
13528 if Is_Entity_Name
(N
) then
13531 elsif Nkind
(N
) = N_Selected_Component
then
13532 Off
:= Component_Bit_Offset
(Entity
(Selector_Name
(N
)));
13533 if Off
/= No_Uint
and then Off
>= Uint_0
then
13540 elsif Nkind
(N
) = N_Indexed_Component
then
13541 Off
:= Indexed_Component_Bit_Offset
(N
);
13542 if Off
/= No_Uint
then
13555 -- Start of processing for Validate_Address_Clauses
13558 for J
in Address_Clause_Checks
.First
.. Address_Clause_Checks
.Last
loop
13560 ACCR
: Address_Clause_Check_Record
13561 renames Address_Clause_Checks
.Table
(J
);
13565 X_Alignment
: Uint
;
13566 Y_Alignment
: Uint
:= Uint_0
;
13569 Y_Size
: Uint
:= Uint_0
;
13574 -- Skip processing of this entry if warning already posted
13576 if not Address_Warning_Posted
(ACCR
.N
) then
13577 Expr
:= Original_Node
(Expression
(ACCR
.N
));
13579 -- Get alignments, sizes and offset, if any
13581 X_Alignment
:= Alignment
(ACCR
.X
);
13582 X_Size
:= Esize
(ACCR
.X
);
13584 if Present
(ACCR
.Y
) then
13585 Y_Alignment
:= Alignment
(ACCR
.Y
);
13586 Y_Size
:= Esize
(ACCR
.Y
);
13590 and then Nkind
(Expr
) = N_Attribute_Reference
13591 and then Attribute_Name
(Expr
) = Name_Address
13593 X_Offs
:= Offset_Value
(Expr
);
13598 -- Check for known value not multiple of alignment
13600 if No
(ACCR
.Y
) then
13601 if not Alignment_Checks_Suppressed
(ACCR
)
13602 and then X_Alignment
/= 0
13603 and then ACCR
.A
mod X_Alignment
/= 0
13606 ("??specified address for& is inconsistent with "
13607 & "alignment", ACCR
.N
, ACCR
.X
);
13609 ("\??program execution may be erroneous (RM 13.3(27))",
13612 Error_Msg_Uint_1
:= X_Alignment
;
13613 Error_Msg_NE
("\??alignment of & is ^", ACCR
.N
, ACCR
.X
);
13616 -- Check for large object overlaying smaller one
13618 elsif Y_Size
> Uint_0
13619 and then X_Size
> Uint_0
13620 and then X_Offs
+ X_Size
> Y_Size
13622 Error_Msg_NE
("??& overlays smaller object", ACCR
.N
, ACCR
.X
);
13624 ("\??program execution may be erroneous", ACCR
.N
);
13626 Error_Msg_Uint_1
:= X_Size
;
13627 Error_Msg_NE
("\??size of & is ^", ACCR
.N
, ACCR
.X
);
13629 Error_Msg_Uint_1
:= Y_Size
;
13630 Error_Msg_NE
("\??size of & is ^", ACCR
.N
, ACCR
.Y
);
13632 if Y_Size
>= X_Size
then
13633 Error_Msg_Uint_1
:= X_Offs
;
13634 Error_Msg_NE
("\??but offset of & is ^", ACCR
.N
, ACCR
.X
);
13637 -- Check for inadequate alignment, both of the base object
13638 -- and of the offset, if any. We only do this check if the
13639 -- run-time Alignment_Check is active. No point in warning
13640 -- if this check has been suppressed (or is suppressed by
13641 -- default in the non-strict alignment machine case).
13643 -- Note: we do not check the alignment if we gave a size
13644 -- warning, since it would likely be redundant.
13646 elsif not Alignment_Checks_Suppressed
(ACCR
)
13647 and then Y_Alignment
/= Uint_0
13649 (Y_Alignment
< X_Alignment
13652 and then Nkind
(Expr
) = N_Attribute_Reference
13653 and then Attribute_Name
(Expr
) = Name_Address
13654 and then Has_Compatible_Alignment
13655 (ACCR
.X
, Prefix
(Expr
), True) /=
13659 ("??specified address for& may be inconsistent with "
13660 & "alignment", ACCR
.N
, ACCR
.X
);
13662 ("\??program execution may be erroneous (RM 13.3(27))",
13665 Error_Msg_Uint_1
:= X_Alignment
;
13666 Error_Msg_NE
("\??alignment of & is ^", ACCR
.N
, ACCR
.X
);
13668 Error_Msg_Uint_1
:= Y_Alignment
;
13669 Error_Msg_NE
("\??alignment of & is ^", ACCR
.N
, ACCR
.Y
);
13671 if Y_Alignment
>= X_Alignment
then
13673 ("\??but offset is not multiple of alignment", ACCR
.N
);
13679 end Validate_Address_Clauses
;
13681 -----------------------------------------
13682 -- Validate_Compile_Time_Warning_Error --
13683 -----------------------------------------
13685 procedure Validate_Compile_Time_Warning_Error
(N
: Node_Id
) is
13687 Compile_Time_Warnings_Errors
.Append
13688 (New_Val
=> CTWE_Entry
'(Eloc => Sloc (N),
13689 Scope => Current_Scope,
13691 end Validate_Compile_Time_Warning_Error;
13693 ------------------------------------------
13694 -- Validate_Compile_Time_Warning_Errors --
13695 ------------------------------------------
13697 procedure Validate_Compile_Time_Warning_Errors is
13698 procedure Set_Scope (S : Entity_Id);
13699 -- Install all enclosing scopes of S along with S itself
13701 procedure Unset_Scope (S : Entity_Id);
13702 -- Uninstall all enclosing scopes of S along with S itself
13708 procedure Set_Scope (S : Entity_Id) is
13710 if S /= Standard_Standard then
13711 Set_Scope (Scope (S));
13721 procedure Unset_Scope (S : Entity_Id) is
13723 if S /= Standard_Standard then
13724 Unset_Scope (Scope (S));
13730 -- Start of processing for Validate_Compile_Time_Warning_Errors
13733 Expander_Mode_Save_And_Set (False);
13734 In_Compile_Time_Warning_Or_Error := True;
13736 for N in Compile_Time_Warnings_Errors.First ..
13737 Compile_Time_Warnings_Errors.Last
13740 T : CTWE_Entry renames Compile_Time_Warnings_Errors.Table (N);
13743 Set_Scope (T.Scope);
13744 Reset_Analyzed_Flags (T.Prag);
13745 Process_Compile_Time_Warning_Or_Error (T.Prag, T.Eloc);
13746 Unset_Scope (T.Scope);
13750 In_Compile_Time_Warning_Or_Error := False;
13751 Expander_Mode_Restore;
13752 end Validate_Compile_Time_Warning_Errors;
13754 ---------------------------
13755 -- Validate_Independence --
13756 ---------------------------
13758 procedure Validate_Independence is
13759 SU : constant Uint := UI_From_Int (System_Storage_Unit);
13767 procedure Check_Array_Type (Atyp : Entity_Id);
13768 -- Checks if the array type Atyp has independent components, and
13769 -- if not, outputs an appropriate set of error messages.
13771 procedure No_Independence;
13772 -- Output message that independence cannot be guaranteed
13774 function OK_Component (C : Entity_Id) return Boolean;
13775 -- Checks one component to see if it is independently accessible, and
13776 -- if so yields True, otherwise yields False if independent access
13777 -- cannot be guaranteed. This is a conservative routine, it only
13778 -- returns True if it knows for sure, it returns False if it knows
13779 -- there is a problem, or it cannot be sure there is no problem.
13781 procedure Reason_Bad_Component (C : Entity_Id);
13782 -- Outputs continuation message if a reason can be determined for
13783 -- the component C being bad.
13785 ----------------------
13786 -- Check_Array_Type --
13787 ----------------------
13789 procedure Check_Array_Type (Atyp : Entity_Id) is
13790 Ctyp : constant Entity_Id := Component_Type (Atyp);
13793 -- OK if no alignment clause, no pack, and no component size
13795 if not Has_Component_Size_Clause (Atyp)
13796 and then not Has_Alignment_Clause (Atyp)
13797 and then not Is_Packed (Atyp)
13802 -- Case of component size is greater than or equal to 64 and the
13803 -- alignment of the array is at least as large as the alignment
13804 -- of the component. We are definitely OK in this situation.
13806 if Known_Component_Size (Atyp)
13807 and then Component_Size (Atyp) >= 64
13808 and then Known_Alignment (Atyp)
13809 and then Known_Alignment (Ctyp)
13810 and then Alignment (Atyp) >= Alignment (Ctyp)
13815 -- Check actual component size
13817 if not Known_Component_Size (Atyp)
13818 or else not (Addressable (Component_Size (Atyp))
13819 and then Component_Size (Atyp) < 64)
13820 or else Component_Size (Atyp) mod Esize (Ctyp) /= 0
13824 -- Bad component size, check reason
13826 if Has_Component_Size_Clause (Atyp) then
13827 P := Get_Attribute_Definition_Clause
13828 (Atyp, Attribute_Component_Size);
13830 if Present (P) then
13831 Error_Msg_Sloc := Sloc (P);
13832 Error_Msg_N ("\because of Component_Size clause#", N);
13837 if Is_Packed (Atyp) then
13838 P := Get_Rep_Pragma (Atyp, Name_Pack);
13840 if Present (P) then
13841 Error_Msg_Sloc := Sloc (P);
13842 Error_Msg_N ("\because of pragma Pack#", N);
13847 -- No reason found, just return
13852 -- Array type is OK independence-wise
13855 end Check_Array_Type;
13857 ---------------------
13858 -- No_Independence --
13859 ---------------------
13861 procedure No_Independence is
13863 if Pragma_Name (N) = Name_Independent then
13864 Error_Msg_NE ("independence cannot be guaranteed for&", N, E);
13867 ("independent components cannot be guaranteed for&", N, E);
13869 end No_Independence;
13875 function OK_Component (C : Entity_Id) return Boolean is
13876 Rec : constant Entity_Id := Scope (C);
13877 Ctyp : constant Entity_Id := Etype (C);
13880 -- OK if no component clause, no Pack, and no alignment clause
13882 if No (Component_Clause (C))
13883 and then not Is_Packed (Rec)
13884 and then not Has_Alignment_Clause (Rec)
13889 -- Here we look at the actual component layout. A component is
13890 -- addressable if its size is a multiple of the Esize of the
13891 -- component type, and its starting position in the record has
13892 -- appropriate alignment, and the record itself has appropriate
13893 -- alignment to guarantee the component alignment.
13895 -- Make sure sizes are static, always assume the worst for any
13896 -- cases where we cannot check static values.
13898 if not (Known_Static_Esize (C)
13900 Known_Static_Esize (Ctyp))
13905 -- Size of component must be addressable or greater than 64 bits
13906 -- and a multiple of bytes.
13908 if not Addressable (Esize (C)) and then Esize (C) < Uint_64 then
13912 -- Check size is proper multiple
13914 if Esize (C) mod Esize (Ctyp) /= 0 then
13918 -- Check alignment of component is OK
13920 if not Known_Component_Bit_Offset (C)
13921 or else Component_Bit_Offset (C) < Uint_0
13922 or else Component_Bit_Offset (C) mod Esize (Ctyp) /= 0
13927 -- Check alignment of record type is OK
13929 if not Known_Alignment (Rec)
13930 or else (Alignment (Rec) * SU) mod Esize (Ctyp) /= 0
13935 -- All tests passed, component is addressable
13940 --------------------------
13941 -- Reason_Bad_Component --
13942 --------------------------
13944 procedure Reason_Bad_Component (C : Entity_Id) is
13945 Rec : constant Entity_Id := Scope (C);
13946 Ctyp : constant Entity_Id := Etype (C);
13949 -- If component clause present assume that's the problem
13951 if Present (Component_Clause (C)) then
13952 Error_Msg_Sloc := Sloc (Component_Clause (C));
13953 Error_Msg_N ("\because of Component_Clause#", N);
13957 -- If pragma Pack clause present, assume that's the problem
13959 if Is_Packed (Rec) then
13960 P := Get_Rep_Pragma (Rec, Name_Pack);
13962 if Present (P) then
13963 Error_Msg_Sloc := Sloc (P);
13964 Error_Msg_N ("\because of pragma Pack#", N);
13969 -- See if record has bad alignment clause
13971 if Has_Alignment_Clause (Rec)
13972 and then Known_Alignment (Rec)
13973 and then (Alignment (Rec) * SU) mod Esize (Ctyp) /= 0
13975 P := Get_Attribute_Definition_Clause (Rec, Attribute_Alignment);
13977 if Present (P) then
13978 Error_Msg_Sloc := Sloc (P);
13979 Error_Msg_N ("\because of Alignment clause#", N);
13983 -- Couldn't find a reason, so return without a message
13986 end Reason_Bad_Component;
13988 -- Start of processing for Validate_Independence
13991 for J in Independence_Checks.First .. Independence_Checks.Last loop
13992 N := Independence_Checks.Table (J).N;
13993 E := Independence_Checks.Table (J).E;
13994 IC := Pragma_Name (N) = Name_Independent_Components;
13996 -- Deal with component case
13998 if Ekind (E) = E_Discriminant or else Ekind (E) = E_Component then
13999 if not OK_Component (E) then
14001 Reason_Bad_Component (E);
14006 -- Deal with record with Independent_Components
14008 if IC and then Is_Record_Type (E) then
14009 Comp := First_Component_Or_Discriminant (E);
14010 while Present (Comp) loop
14011 if not OK_Component (Comp) then
14013 Reason_Bad_Component (Comp);
14017 Next_Component_Or_Discriminant (Comp);
14021 -- Deal with address clause case
14023 if Is_Object (E) then
14024 Addr := Address_Clause (E);
14026 if Present (Addr) then
14028 Error_Msg_Sloc := Sloc (Addr);
14029 Error_Msg_N ("\because of Address clause#", N);
14034 -- Deal with independent components for array type
14036 if IC and then Is_Array_Type (E) then
14037 Check_Array_Type (E);
14040 -- Deal with independent components for array object
14042 if IC and then Is_Object (E) and then Is_Array_Type (Etype (E)) then
14043 Check_Array_Type (Etype (E));
14048 end Validate_Independence;
14050 ------------------------------
14051 -- Validate_Iterable_Aspect --
14052 ------------------------------
14054 procedure Validate_Iterable_Aspect (Typ : Entity_Id; ASN : Node_Id) is
14059 Cursor : constant Entity_Id := Get_Cursor_Type (ASN, Typ);
14061 First_Id : Entity_Id;
14062 Last_Id : Entity_Id;
14063 Next_Id : Entity_Id;
14064 Has_Element_Id : Entity_Id;
14065 Element_Id : Entity_Id;
14068 -- If previous error aspect is unusable
14070 if Cursor = Any_Type then
14077 Has_Element_Id := Empty;
14078 Element_Id := Empty;
14080 -- Each expression must resolve to a function with the proper signature
14082 Assoc := First (Component_Associations (Expression (ASN)));
14083 while Present (Assoc) loop
14084 Expr := Expression (Assoc);
14087 Prim := First (Choices (Assoc));
14089 if Nkind (Prim) /= N_Identifier or else Present (Next (Prim)) then
14090 Error_Msg_N ("illegal name in association", Prim);
14092 elsif Chars (Prim) = Name_First then
14093 Resolve_Iterable_Operation (Expr, Cursor, Typ, Name_First);
14094 First_Id := Entity (Expr);
14096 elsif Chars (Prim) = Name_Last then
14097 Resolve_Iterable_Operation (Expr, Cursor, Typ, Name_Last);
14098 Last_Id := Entity (Expr);
14100 elsif Chars (Prim) = Name_Previous then
14101 Resolve_Iterable_Operation (Expr, Cursor, Typ, Name_Previous);
14102 Last_Id := Entity (Expr);
14104 elsif Chars (Prim) = Name_Next then
14105 Resolve_Iterable_Operation (Expr, Cursor, Typ, Name_Next);
14106 Next_Id := Entity (Expr);
14108 elsif Chars (Prim) = Name_Has_Element then
14109 Resolve_Iterable_Operation (Expr, Cursor, Typ, Name_Has_Element);
14110 Has_Element_Id := Entity (Expr);
14112 elsif Chars (Prim) = Name_Element then
14113 Resolve_Iterable_Operation (Expr, Cursor, Typ, Name_Element);
14114 Element_Id := Entity (Expr);
14117 Error_Msg_N ("invalid name for iterable function", Prim);
14123 if No (First_Id) then
14124 Error_Msg_N ("match for First primitive not found", ASN);
14126 elsif No (Next_Id) then
14127 Error_Msg_N ("match for Next primitive not found", ASN);
14129 elsif No (Has_Element_Id) then
14130 Error_Msg_N ("match for Has_Element primitive not found", ASN);
14132 elsif No (Element_Id) or else No (Last_Id) then
14135 end Validate_Iterable_Aspect;
14137 -----------------------------------
14138 -- Validate_Unchecked_Conversion --
14139 -----------------------------------
14141 procedure Validate_Unchecked_Conversion
14143 Act_Unit : Entity_Id)
14145 Source : Entity_Id;
14146 Target : Entity_Id;
14150 -- Obtain source and target types. Note that we call Ancestor_Subtype
14151 -- here because the processing for generic instantiation always makes
14152 -- subtypes, and we want the original frozen actual types.
14154 -- If we are dealing with private types, then do the check on their
14155 -- fully declared counterparts if the full declarations have been
14156 -- encountered (they don't have to be visible, but they must exist).
14158 Source := Ancestor_Subtype (Etype (First_Formal (Act_Unit)));
14160 if Is_Private_Type (Source)
14161 and then Present (Underlying_Type (Source))
14163 Source := Underlying_Type (Source);
14166 Target := Ancestor_Subtype (Etype (Act_Unit));
14168 -- If either type is generic, the instantiation happens within a generic
14169 -- unit, and there is nothing to check. The proper check will happen
14170 -- when the enclosing generic is instantiated.
14172 if Is_Generic_Type (Source) or else Is_Generic_Type (Target) then
14176 if Is_Private_Type (Target)
14177 and then Present (Underlying_Type (Target))
14179 Target := Underlying_Type (Target);
14182 -- Source may be unconstrained array, but not target, except in relaxed
14185 if Is_Array_Type (Target)
14186 and then not Is_Constrained (Target)
14187 and then not Relaxed_RM_Semantics
14190 ("unchecked conversion to unconstrained array not allowed", N);
14194 -- Warn if conversion between two different convention pointers
14196 if Is_Access_Type (Target)
14197 and then Is_Access_Type (Source)
14198 and then Convention (Target) /= Convention (Source)
14199 and then Warn_On_Unchecked_Conversion
14201 -- Give warnings for subprogram pointers only on most targets
14203 if Is_Access_Subprogram_Type (Target)
14204 or else Is_Access_Subprogram_Type (Source)
14207 ("?z?conversion between pointers with different conventions!",
14212 -- Warn if one of the operands is Ada.Calendar.Time. Do not emit a
14213 -- warning when compiling GNAT-related sources.
14215 if Warn_On_Unchecked_Conversion
14216 and then not In_Predefined_Unit (N)
14217 and then RTU_Loaded (Ada_Calendar)
14218 and then (Chars (Source) = Name_Time
14220 Chars (Target) = Name_Time)
14222 -- If Ada.Calendar is loaded and the name of one of the operands is
14223 -- Time, there is a good chance that this is Ada.Calendar.Time.
14226 Calendar_Time : constant Entity_Id := Full_View (RTE (RO_CA_Time));
14228 pragma Assert (Present (Calendar_Time));
14230 if Source = Calendar_Time or else Target = Calendar_Time then
14232 ("?z?representation of 'Time values may change between
"
14233 & "'G'N'A
'T versions
", N);
14238 -- Make entry in unchecked conversion table for later processing by
14239 -- Validate_Unchecked_Conversions, which will check sizes and alignments
14240 -- (using values set by the back end where possible). This is only done
14241 -- if the appropriate warning is active.
14243 if Warn_On_Unchecked_Conversion then
14244 Unchecked_Conversions.Append
14245 (New_Val => UC_Entry'(Eloc => Sloc (N),
14248 Act_Unit => Act_Unit));
14250 -- If both sizes are known statically now, then back-end annotation
14251 -- is not required to do a proper check but if either size is not
14252 -- known statically, then we need the annotation.
14254 if Known_Static_RM_Size (Source)
14256 Known_Static_RM_Size (Target)
14260 Back_Annotate_Rep_Info := True;
14264 -- If unchecked conversion to access type, and access type is declared
14265 -- in the same unit as the unchecked conversion, then set the flag
14266 -- No_Strict_Aliasing (no strict aliasing is implicit here)
14268 if Is_Access_Type (Target) and then
14269 In_Same_Source_Unit (Target, N)
14271 Set_No_Strict_Aliasing (Implementation_Base_Type (Target));
14274 -- Generate N_Validate_Unchecked_Conversion node for back end in case
14275 -- the back end needs to perform special validation checks.
14277 -- Shouldn't this be in Exp_Ch13, since the check only gets done if we
14278 -- have full expansion and the back end is called ???
14281 Make_Validate_Unchecked_Conversion (Sloc (N));
14282 Set_Source_Type (Vnode, Source);
14283 Set_Target_Type (Vnode, Target);
14285 -- If the unchecked conversion node is in a list, just insert before it.
14286 -- If not we have some strange case, not worth bothering about.
14288 if Is_List_Member (N) then
14289 Insert_After (N, Vnode);
14291 end Validate_Unchecked_Conversion;
14293 ------------------------------------
14294 -- Validate_Unchecked_Conversions --
14295 ------------------------------------
14297 procedure Validate_Unchecked_Conversions is
14299 for N in Unchecked_Conversions.First .. Unchecked_Conversions.Last loop
14301 T : UC_Entry renames Unchecked_Conversions.Table (N);
14303 Act_Unit : constant Entity_Id := T.Act_Unit;
14304 Eloc : constant Source_Ptr := T.Eloc;
14305 Source : constant Entity_Id := T.Source;
14306 Target : constant Entity_Id := T.Target;
14312 -- Skip if function marked as warnings off
14314 if Warnings_Off (Act_Unit) then
14318 -- This validation check, which warns if we have unequal sizes for
14319 -- unchecked conversion, and thus potentially implementation
14320 -- dependent semantics, is one of the few occasions on which we
14321 -- use the official RM size instead of Esize. See description in
14322 -- Einfo "Handling
of Type'Size Values
" for details.
14324 if Serious_Errors_Detected = 0
14325 and then Known_Static_RM_Size (Source)
14326 and then Known_Static_RM_Size (Target)
14328 -- Don't do the check if warnings off for either type, note the
14329 -- deliberate use of OR here instead of OR ELSE to get the flag
14330 -- Warnings_Off_Used set for both types if appropriate.
14332 and then not (Has_Warnings_Off (Source)
14334 Has_Warnings_Off (Target))
14336 Source_Siz := RM_Size (Source);
14337 Target_Siz := RM_Size (Target);
14339 if Source_Siz /= Target_Siz then
14341 ("?z?types
for unchecked conversion have different sizes
!",
14344 if All_Errors_Mode then
14345 Error_Msg_Name_1 := Chars (Source);
14346 Error_Msg_Uint_1 := Source_Siz;
14347 Error_Msg_Name_2 := Chars (Target);
14348 Error_Msg_Uint_2 := Target_Siz;
14349 Error_Msg ("\size
of % is ^
, size
of % is ^?z?
", Eloc);
14351 Error_Msg_Uint_1 := UI_Abs (Source_Siz - Target_Siz);
14353 if Is_Discrete_Type (Source)
14355 Is_Discrete_Type (Target)
14357 if Source_Siz > Target_Siz then
14359 ("\?z?^ high order bits
of source will
"
14360 & "be ignored
!", Eloc);
14362 elsif Is_Unsigned_Type (Source) then
14364 ("\?z?source will be extended
with ^ high order
"
14365 & "zero bits
!", Eloc);
14369 ("\?z?source will be extended
with ^ high order
"
14370 & "sign bits
!", Eloc);
14373 elsif Source_Siz < Target_Siz then
14374 if Is_Discrete_Type (Target) then
14375 if Bytes_Big_Endian then
14377 ("\?z?target value will include ^ undefined
"
14378 & "low order bits
!", Eloc, Act_Unit);
14381 ("\?z?target value will include ^ undefined
"
14382 & "high order bits
!", Eloc, Act_Unit);
14387 ("\?z?^ trailing bits
of target value will be
"
14388 & "undefined
!", Eloc, Act_Unit);
14391 else pragma Assert (Source_Siz > Target_Siz);
14392 if Is_Discrete_Type (Source) then
14393 if Bytes_Big_Endian then
14395 ("\?z?^ low order bits
of source will be
"
14396 & "ignored
!", Eloc, Act_Unit);
14399 ("\?z?^ high order bits
of source will be
"
14400 & "ignored
!", Eloc, Act_Unit);
14405 ("\?z?^ trailing bits
of source will be
"
14406 & "ignored
!", Eloc, Act_Unit);
14413 -- If both types are access types, we need to check the alignment.
14414 -- If the alignment of both is specified, we can do it here.
14416 if Serious_Errors_Detected = 0
14417 and then Is_Access_Type (Source)
14418 and then Is_Access_Type (Target)
14419 and then Target_Strict_Alignment
14420 and then Present (Designated_Type (Source))
14421 and then Present (Designated_Type (Target))
14424 D_Source : constant Entity_Id := Designated_Type (Source);
14425 D_Target : constant Entity_Id := Designated_Type (Target);
14428 if Known_Alignment (D_Source)
14430 Known_Alignment (D_Target)
14433 Source_Align : constant Uint := Alignment (D_Source);
14434 Target_Align : constant Uint := Alignment (D_Target);
14437 if Source_Align < Target_Align
14438 and then not Is_Tagged_Type (D_Source)
14440 -- Suppress warning if warnings suppressed on either
14441 -- type or either designated type. Note the use of
14442 -- OR here instead of OR ELSE. That is intentional,
14443 -- we would like to set flag Warnings_Off_Used in
14444 -- all types for which warnings are suppressed.
14446 and then not (Has_Warnings_Off (D_Source)
14448 Has_Warnings_Off (D_Target)
14450 Has_Warnings_Off (Source)
14452 Has_Warnings_Off (Target))
14454 Error_Msg_Uint_1 := Target_Align;
14455 Error_Msg_Uint_2 := Source_Align;
14456 Error_Msg_Node_1 := D_Target;
14457 Error_Msg_Node_2 := D_Source;
14459 ("?z?alignment
of & (^
) is stricter than
"
14460 & "alignment
of & (^
)!", Eloc, Act_Unit);
14462 ("\?z?resulting
access value may have invalid
"
14463 & "alignment
!", Eloc, Act_Unit);
14474 end Validate_Unchecked_Conversions;