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 procedure Decorate
(Asp
: Node_Id
; Prag
: Node_Id
);
1364 -- Establish linkages between an aspect and its corresponding pragma
1366 procedure Insert_Pragma
1368 Is_Instance
: Boolean := False);
1369 -- Subsidiary to the analysis of aspects
1376 -- Initial_Condition
1385 -- Insert pragma Prag such that it mimics the placement of a source
1386 -- pragma of the same kind. Flag Is_Generic should be set when the
1387 -- context denotes a generic instance.
1393 procedure Decorate
(Asp
: Node_Id
; Prag
: Node_Id
) is
1395 Set_Aspect_Rep_Item
(Asp
, Prag
);
1396 Set_Corresponding_Aspect
(Prag
, Asp
);
1397 Set_From_Aspect_Specification
(Prag
);
1398 Set_Parent
(Prag
, Asp
);
1405 procedure Insert_Pragma
1407 Is_Instance
: Boolean := False)
1413 Inserted
: Boolean := False;
1416 -- When the aspect appears on an entry, package, protected unit,
1417 -- subprogram, or task unit body, insert the generated pragma at the
1418 -- top of the body declarations to emulate the behavior of a source
1421 -- package body Pack with Aspect is
1423 -- package body Pack is
1426 if Nkind_In
(N
, N_Entry_Body
,
1432 Decls
:= Declarations
(N
);
1436 Set_Declarations
(N
, Decls
);
1439 Prepend_To
(Decls
, Prag
);
1441 -- When the aspect is associated with a [generic] package declaration
1442 -- insert the generated pragma at the top of the visible declarations
1443 -- to emulate the behavior of a source pragma.
1445 -- package Pack with Aspect is
1450 elsif Nkind_In
(N
, N_Generic_Package_Declaration
,
1451 N_Package_Declaration
)
1453 Decls
:= Visible_Declarations
(Specification
(N
));
1457 Set_Visible_Declarations
(Specification
(N
), Decls
);
1460 -- The visible declarations of a generic instance have the
1461 -- following structure:
1463 -- <renamings of generic formals>
1464 -- <renamings of internally-generated spec and body>
1465 -- <first source declaration>
1467 -- Insert the pragma before the first source declaration by
1468 -- skipping the instance "header" to ensure proper visibility of
1472 Decl
:= First
(Decls
);
1473 while Present
(Decl
) loop
1474 if Comes_From_Source
(Decl
) then
1475 Insert_Before
(Decl
, Prag
);
1483 -- The pragma is placed after the instance "header"
1485 if not Inserted
then
1486 Append_To
(Decls
, Prag
);
1489 -- Otherwise this is not a generic instance
1492 Prepend_To
(Decls
, Prag
);
1495 -- When the aspect is associated with a protected unit declaration,
1496 -- insert the generated pragma at the top of the visible declarations
1497 -- the emulate the behavior of a source pragma.
1499 -- protected [type] Prot with Aspect is
1501 -- protected [type] Prot is
1504 elsif Nkind
(N
) = N_Protected_Type_Declaration
then
1505 Def
:= Protected_Definition
(N
);
1509 Make_Protected_Definition
(Sloc
(N
),
1510 Visible_Declarations
=> New_List
,
1511 End_Label
=> Empty
);
1513 Set_Protected_Definition
(N
, Def
);
1516 Decls
:= Visible_Declarations
(Def
);
1520 Set_Visible_Declarations
(Def
, Decls
);
1523 Prepend_To
(Decls
, Prag
);
1525 -- When the aspect is associated with a task unit declaration, insert
1526 -- insert the generated pragma at the top of the visible declarations
1527 -- the emulate the behavior of a source pragma.
1529 -- task [type] Prot with Aspect is
1531 -- task [type] Prot is
1534 elsif Nkind
(N
) = N_Task_Type_Declaration
then
1535 Def
:= Task_Definition
(N
);
1539 Make_Task_Definition
(Sloc
(N
),
1540 Visible_Declarations
=> New_List
,
1541 End_Label
=> Empty
);
1543 Set_Task_Definition
(N
, Def
);
1546 Decls
:= Visible_Declarations
(Def
);
1550 Set_Visible_Declarations
(Def
, Decls
);
1553 Prepend_To
(Decls
, Prag
);
1555 -- When the context is a library unit, the pragma is added to the
1556 -- Pragmas_After list.
1558 elsif Nkind
(Parent
(N
)) = N_Compilation_Unit
then
1559 Aux
:= Aux_Decls_Node
(Parent
(N
));
1561 if No
(Pragmas_After
(Aux
)) then
1562 Set_Pragmas_After
(Aux
, New_List
);
1565 Prepend
(Prag
, Pragmas_After
(Aux
));
1567 -- Default, the pragma is inserted after the context
1570 Insert_After
(N
, Prag
);
1580 L
: constant List_Id
:= Aspect_Specifications
(N
);
1582 Ins_Node
: Node_Id
:= N
;
1583 -- Insert pragmas/attribute definition clause after this node when no
1584 -- delayed analysis is required.
1586 -- Start of processing for Analyze_Aspect_Specifications
1589 -- The general processing involves building an attribute definition
1590 -- clause or a pragma node that corresponds to the aspect. Then in order
1591 -- to delay the evaluation of this aspect to the freeze point, we attach
1592 -- the corresponding pragma/attribute definition clause to the aspect
1593 -- specification node, which is then placed in the Rep Item chain. In
1594 -- this case we mark the entity by setting the flag Has_Delayed_Aspects
1595 -- and we evaluate the rep item at the freeze point. When the aspect
1596 -- doesn't have a corresponding pragma/attribute definition clause, then
1597 -- its analysis is simply delayed at the freeze point.
1599 -- Some special cases don't require delay analysis, thus the aspect is
1600 -- analyzed right now.
1602 -- Note that there is a special handling for Pre, Post, Test_Case,
1603 -- Contract_Cases aspects. In these cases, we do not have to worry
1604 -- about delay issues, since the pragmas themselves deal with delay
1605 -- of visibility for the expression analysis. Thus, we just insert
1606 -- the pragma after the node N.
1608 pragma Assert
(Present
(L
));
1610 -- Loop through aspects
1612 Aspect
:= First
(L
);
1613 Aspect_Loop
: while Present
(Aspect
) loop
1614 Analyze_One_Aspect
: declare
1615 Expr
: constant Node_Id
:= Expression
(Aspect
);
1616 Id
: constant Node_Id
:= Identifier
(Aspect
);
1617 Loc
: constant Source_Ptr
:= Sloc
(Aspect
);
1618 Nam
: constant Name_Id
:= Chars
(Id
);
1619 A_Id
: constant Aspect_Id
:= Get_Aspect_Id
(Nam
);
1622 Delay_Required
: Boolean;
1623 -- Set False if delay is not required
1625 Eloc
: Source_Ptr
:= No_Location
;
1626 -- Source location of expression, modified when we split PPC's. It
1627 -- is set below when Expr is present.
1629 procedure Analyze_Aspect_Convention
;
1630 -- Perform analysis of aspect Convention
1632 procedure Analyze_Aspect_Disable_Controlled
;
1633 -- Perform analysis of aspect Disable_Controlled
1635 procedure Analyze_Aspect_Export_Import
;
1636 -- Perform analysis of aspects Export or Import
1638 procedure Analyze_Aspect_External_Link_Name
;
1639 -- Perform analysis of aspects External_Name or Link_Name
1641 procedure Analyze_Aspect_Implicit_Dereference
;
1642 -- Perform analysis of the Implicit_Dereference aspects
1644 procedure Make_Aitem_Pragma
1645 (Pragma_Argument_Associations
: List_Id
;
1646 Pragma_Name
: Name_Id
);
1647 -- This is a wrapper for Make_Pragma used for converting aspects
1648 -- to pragmas. It takes care of Sloc (set from Loc) and building
1649 -- the pragma identifier from the given name. In addition the
1650 -- flags Class_Present and Split_PPC are set from the aspect
1651 -- node, as well as Is_Ignored. This routine also sets the
1652 -- From_Aspect_Specification in the resulting pragma node to
1653 -- True, and sets Corresponding_Aspect to point to the aspect.
1654 -- The resulting pragma is assigned to Aitem.
1656 -------------------------------
1657 -- Analyze_Aspect_Convention --
1658 -------------------------------
1660 procedure Analyze_Aspect_Convention
is
1669 -- Obtain all interfacing aspects that apply to the related
1672 Get_Interfacing_Aspects
1673 (Iface_Asp
=> Aspect
,
1674 Conv_Asp
=> Dummy_1
,
1681 -- The related entity is subject to aspect Export or Import.
1682 -- Do not process Convention now because it must be analysed
1683 -- as part of Export or Import.
1685 if Present
(Expo
) or else Present
(Imp
) then
1688 -- Otherwise Convention appears by itself
1691 -- The aspect specifies a particular convention
1693 if Present
(Expr
) then
1694 Conv
:= New_Copy_Tree
(Expr
);
1696 -- Otherwise assume convention Ada
1699 Conv
:= Make_Identifier
(Loc
, Name_Ada
);
1703 -- pragma Convention (<Conv>, <E>);
1706 (Pragma_Name
=> Name_Convention
,
1707 Pragma_Argument_Associations
=> New_List
(
1708 Make_Pragma_Argument_Association
(Loc
,
1709 Expression
=> Conv
),
1710 Make_Pragma_Argument_Association
(Loc
,
1711 Expression
=> New_Occurrence_Of
(E
, Loc
))));
1713 Decorate
(Aspect
, Aitem
);
1714 Insert_Pragma
(Aitem
);
1716 end Analyze_Aspect_Convention
;
1718 ---------------------------------------
1719 -- Analyze_Aspect_Disable_Controlled --
1720 ---------------------------------------
1722 procedure Analyze_Aspect_Disable_Controlled
is
1724 -- The aspect applies only to controlled records
1726 if not (Ekind
(E
) = E_Record_Type
1727 and then Is_Controlled_Active
(E
))
1730 ("aspect % requires controlled record type", Aspect
);
1734 -- Preanalyze the expression (if any) when the aspect resides
1735 -- in a generic unit.
1737 if Inside_A_Generic
then
1738 if Present
(Expr
) then
1739 Preanalyze_And_Resolve
(Expr
, Any_Boolean
);
1742 -- Otherwise the aspect resides in a nongeneric context
1745 -- A controlled record type loses its controlled semantics
1746 -- when the expression statically evaluates to True.
1748 if Present
(Expr
) then
1749 Analyze_And_Resolve
(Expr
, Any_Boolean
);
1751 if Is_OK_Static_Expression
(Expr
) then
1752 if Is_True
(Static_Boolean
(Expr
)) then
1753 Set_Disable_Controlled
(E
);
1756 -- Otherwise the expression is not static
1760 ("expression of aspect % must be static", Aspect
);
1763 -- Otherwise the aspect appears without an expression and
1764 -- defaults to True.
1767 Set_Disable_Controlled
(E
);
1770 end Analyze_Aspect_Disable_Controlled
;
1772 ----------------------------------
1773 -- Analyze_Aspect_Export_Import --
1774 ----------------------------------
1776 procedure Analyze_Aspect_Export_Import
is
1784 -- Obtain all interfacing aspects that apply to the related
1787 Get_Interfacing_Aspects
1788 (Iface_Asp
=> Aspect
,
1789 Conv_Asp
=> Dummy_1
,
1796 -- The related entity cannot be subject to both aspects Export
1799 if Present
(Expo
) and then Present
(Imp
) then
1801 ("incompatible interfacing aspects given for &", E
);
1802 Error_Msg_Sloc
:= Sloc
(Expo
);
1803 Error_Msg_N
("\aspect `Export` #", E
);
1804 Error_Msg_Sloc
:= Sloc
(Imp
);
1805 Error_Msg_N
("\aspect `Import` #", E
);
1808 -- A variable is most likely modified from the outside. Take
1809 -- the optimistic approach to avoid spurious errors.
1811 if Ekind
(E
) = E_Variable
then
1812 Set_Never_Set_In_Source
(E
, False);
1815 -- Resolve the expression of an Import or Export here, and
1816 -- require it to be of type Boolean and static. This is not
1817 -- quite right, because in general this should be delayed,
1818 -- but that seems tricky for these, because normally Boolean
1819 -- aspects are replaced with pragmas at the freeze point in
1820 -- Make_Pragma_From_Boolean_Aspect.
1822 if not Present
(Expr
)
1823 or else Is_True
(Static_Boolean
(Expr
))
1825 if A_Id
= Aspect_Import
then
1826 Set_Has_Completion
(E
);
1827 Set_Is_Imported
(E
);
1829 -- An imported object cannot be explicitly initialized
1831 if Nkind
(N
) = N_Object_Declaration
1832 and then Present
(Expression
(N
))
1835 ("imported entities cannot be initialized "
1836 & "(RM B.1(24))", Expression
(N
));
1840 pragma Assert
(A_Id
= Aspect_Export
);
1841 Set_Is_Exported
(E
);
1844 -- Create the proper form of pragma Export or Import taking
1845 -- into account Conversion, External_Name, and Link_Name.
1847 Aitem
:= Build_Export_Import_Pragma
(Aspect
, E
);
1849 -- Otherwise the expression is either False or erroneous. There
1850 -- is no corresponding pragma.
1855 end Analyze_Aspect_Export_Import
;
1857 ---------------------------------------
1858 -- Analyze_Aspect_External_Link_Name --
1859 ---------------------------------------
1861 procedure Analyze_Aspect_External_Link_Name
is
1869 -- Obtain all interfacing aspects that apply to the related
1872 Get_Interfacing_Aspects
1873 (Iface_Asp
=> Aspect
,
1874 Conv_Asp
=> Dummy_1
,
1881 -- Ensure that aspect External_Name applies to aspect Export or
1884 if A_Id
= Aspect_External_Name
then
1885 if No
(Expo
) and then No
(Imp
) then
1887 ("aspect `External_Name` requires aspect `Import` or "
1888 & "`Export`", Aspect
);
1891 -- Otherwise ensure that aspect Link_Name applies to aspect
1892 -- Export or Import.
1895 pragma Assert
(A_Id
= Aspect_Link_Name
);
1896 if No
(Expo
) and then No
(Imp
) then
1898 ("aspect `Link_Name` requires aspect `Import` or "
1899 & "`Export`", Aspect
);
1902 end Analyze_Aspect_External_Link_Name
;
1904 -----------------------------------------
1905 -- Analyze_Aspect_Implicit_Dereference --
1906 -----------------------------------------
1908 procedure Analyze_Aspect_Implicit_Dereference
is
1910 Parent_Disc
: Entity_Id
;
1913 if not Is_Type
(E
) or else not Has_Discriminants
(E
) then
1915 ("aspect must apply to a type with discriminants", Expr
);
1917 elsif not Is_Entity_Name
(Expr
) then
1919 ("aspect must name a discriminant of current type", Expr
);
1922 -- Discriminant type be an anonymous access type or an
1923 -- anonymous access to subprogram.
1925 -- Missing synchronized types???
1927 Disc
:= First_Discriminant
(E
);
1928 while Present
(Disc
) loop
1929 if Chars
(Expr
) = Chars
(Disc
)
1930 and then Ekind_In
(Etype
(Disc
),
1931 E_Anonymous_Access_Subprogram_Type
,
1932 E_Anonymous_Access_Type
)
1934 Set_Has_Implicit_Dereference
(E
);
1935 Set_Has_Implicit_Dereference
(Disc
);
1939 Next_Discriminant
(Disc
);
1942 -- Error if no proper access discriminant
1945 Error_Msg_NE
("not an access discriminant of&", Expr
, E
);
1950 -- For a type extension, check whether parent has a
1951 -- reference discriminant, to verify that use is proper.
1953 if Is_Derived_Type
(E
)
1954 and then Has_Discriminants
(Etype
(E
))
1956 Parent_Disc
:= Get_Reference_Discriminant
(Etype
(E
));
1958 if Present
(Parent_Disc
)
1959 and then Corresponding_Discriminant
(Disc
) /= Parent_Disc
1962 ("reference discriminant does not match discriminant "
1963 & "of parent type", Expr
);
1966 end Analyze_Aspect_Implicit_Dereference
;
1968 -----------------------
1969 -- Make_Aitem_Pragma --
1970 -----------------------
1972 procedure Make_Aitem_Pragma
1973 (Pragma_Argument_Associations
: List_Id
;
1974 Pragma_Name
: Name_Id
)
1976 Args
: List_Id
:= Pragma_Argument_Associations
;
1979 -- We should never get here if aspect was disabled
1981 pragma Assert
(not Is_Disabled
(Aspect
));
1983 -- Certain aspects allow for an optional name or expression. Do
1984 -- not generate a pragma with empty argument association list.
1986 if No
(Args
) or else No
(Expression
(First
(Args
))) then
1994 Pragma_Argument_Associations
=> Args
,
1995 Pragma_Identifier
=>
1996 Make_Identifier
(Sloc
(Id
), Pragma_Name
),
1997 Class_Present
=> Class_Present
(Aspect
),
1998 Split_PPC
=> Split_PPC
(Aspect
));
2000 -- Set additional semantic fields
2002 if Is_Ignored
(Aspect
) then
2003 Set_Is_Ignored
(Aitem
);
2004 elsif Is_Checked
(Aspect
) then
2005 Set_Is_Checked
(Aitem
);
2008 Set_Corresponding_Aspect
(Aitem
, Aspect
);
2009 Set_From_Aspect_Specification
(Aitem
);
2010 end Make_Aitem_Pragma
;
2012 -- Start of processing for Analyze_One_Aspect
2015 -- Skip aspect if already analyzed, to avoid looping in some cases
2017 if Analyzed
(Aspect
) then
2021 -- Skip looking at aspect if it is totally disabled. Just mark it
2022 -- as such for later reference in the tree. This also sets the
2023 -- Is_Ignored and Is_Checked flags appropriately.
2025 Check_Applicable_Policy
(Aspect
);
2027 if Is_Disabled
(Aspect
) then
2031 -- Set the source location of expression, used in the case of
2032 -- a failed precondition/postcondition or invariant. Note that
2033 -- the source location of the expression is not usually the best
2034 -- choice here. For example, it gets located on the last AND
2035 -- keyword in a chain of boolean expressiond AND'ed together.
2036 -- It is best to put the message on the first character of the
2037 -- assertion, which is the effect of the First_Node call here.
2039 if Present
(Expr
) then
2040 Eloc
:= Sloc
(First_Node
(Expr
));
2043 -- Check restriction No_Implementation_Aspect_Specifications
2045 if Implementation_Defined_Aspect
(A_Id
) then
2047 (No_Implementation_Aspect_Specifications
, Aspect
);
2050 -- Check restriction No_Specification_Of_Aspect
2052 Check_Restriction_No_Specification_Of_Aspect
(Aspect
);
2054 -- Mark aspect analyzed (actual analysis is delayed till later)
2056 Set_Analyzed
(Aspect
);
2057 Set_Entity
(Aspect
, E
);
2059 -- Build the reference to E that will be used in the built pragmas
2061 Ent
:= New_Occurrence_Of
(E
, Sloc
(Id
));
2063 if A_Id
= Aspect_Attach_Handler
2064 or else A_Id
= Aspect_Interrupt_Handler
2067 -- Treat the specification as a reference to the protected
2068 -- operation, which might otherwise appear unreferenced and
2069 -- generate spurious warnings.
2071 Generate_Reference
(E
, Id
);
2074 -- Check for duplicate aspect. Note that the Comes_From_Source
2075 -- test allows duplicate Pre/Post's that we generate internally
2076 -- to escape being flagged here.
2078 if No_Duplicates_Allowed
(A_Id
) then
2080 while Anod
/= Aspect
loop
2081 if Comes_From_Source
(Aspect
)
2082 and then Same_Aspect
(A_Id
, Get_Aspect_Id
(Anod
))
2084 Error_Msg_Name_1
:= Nam
;
2085 Error_Msg_Sloc
:= Sloc
(Anod
);
2087 -- Case of same aspect specified twice
2089 if Class_Present
(Anod
) = Class_Present
(Aspect
) then
2090 if not Class_Present
(Anod
) then
2092 ("aspect% for & previously given#",
2096 ("aspect `%''Class` for & previously given#",
2106 -- Check some general restrictions on language defined aspects
2108 if not Implementation_Defined_Aspect
(A_Id
) then
2109 Error_Msg_Name_1
:= Nam
;
2111 -- Not allowed for renaming declarations. Examine the original
2112 -- node because a subprogram renaming may have been rewritten
2115 if Nkind
(Original_Node
(N
)) in N_Renaming_Declaration
then
2117 ("aspect % not allowed for renaming declaration",
2121 -- Not allowed for formal type declarations
2123 if Nkind
(N
) = N_Formal_Type_Declaration
then
2125 ("aspect % not allowed for formal type declaration",
2130 -- Copy expression for later processing by the procedures
2131 -- Check_Aspect_At_[Freeze_Point | End_Of_Declarations]
2133 Set_Entity
(Id
, New_Copy_Tree
(Expr
));
2135 -- Set Delay_Required as appropriate to aspect
2137 case Aspect_Delay
(A_Id
) is
2138 when Always_Delay
=>
2139 Delay_Required
:= True;
2142 Delay_Required
:= False;
2146 -- If expression has the form of an integer literal, then
2147 -- do not delay, since we know the value cannot change.
2148 -- This optimization catches most rep clause cases.
2150 -- For Boolean aspects, don't delay if no expression
2152 if A_Id
in Boolean_Aspects
and then No
(Expr
) then
2153 Delay_Required
:= False;
2155 -- For non-Boolean aspects, don't delay if integer literal,
2156 -- unless the aspect is Alignment, which affects the
2157 -- freezing of an initialized object.
2159 elsif A_Id
not in Boolean_Aspects
2160 and then A_Id
/= Aspect_Alignment
2161 and then Present
(Expr
)
2162 and then Nkind
(Expr
) = N_Integer_Literal
2164 Delay_Required
:= False;
2166 -- All other cases are delayed
2169 Delay_Required
:= True;
2170 Set_Has_Delayed_Rep_Aspects
(E
);
2174 -- Processing based on specific aspect
2177 when Aspect_Unimplemented
=>
2178 null; -- ??? temp for now
2180 -- No_Aspect should be impossible
2183 raise Program_Error
;
2185 -- Case 1: Aspects corresponding to attribute definition
2191 | Aspect_Component_Size
2192 | Aspect_Constant_Indexing
2193 | Aspect_Default_Iterator
2194 | Aspect_Dispatching_Domain
2195 | Aspect_External_Tag
2198 | Aspect_Iterator_Element
2199 | Aspect_Machine_Radix
2200 | Aspect_Object_Size
2203 | Aspect_Scalar_Storage_Order
2204 | Aspect_Secondary_Stack_Size
2205 | Aspect_Simple_Storage_Pool
2208 | Aspect_Storage_Pool
2209 | Aspect_Stream_Size
2211 | Aspect_Variable_Indexing
2214 -- Indexing aspects apply only to tagged type
2216 if (A_Id
= Aspect_Constant_Indexing
2218 A_Id
= Aspect_Variable_Indexing
)
2219 and then not (Is_Type
(E
)
2220 and then Is_Tagged_Type
(E
))
2223 ("indexing aspect can only apply to a tagged type",
2228 -- For the case of aspect Address, we don't consider that we
2229 -- know the entity is never set in the source, since it is
2230 -- is likely aliasing is occurring.
2232 -- Note: one might think that the analysis of the resulting
2233 -- attribute definition clause would take care of that, but
2234 -- that's not the case since it won't be from source.
2236 if A_Id
= Aspect_Address
then
2237 Set_Never_Set_In_Source
(E
, False);
2240 -- Correctness of the profile of a stream operation is
2241 -- verified at the freeze point, but we must detect the
2242 -- illegal specification of this aspect for a subtype now,
2243 -- to prevent malformed rep_item chains.
2245 if A_Id
= Aspect_Input
or else
2246 A_Id
= Aspect_Output
or else
2247 A_Id
= Aspect_Read
or else
2250 if not Is_First_Subtype
(E
) then
2252 ("local name must be a first subtype", Aspect
);
2255 -- If stream aspect applies to the class-wide type,
2256 -- the generated attribute definition applies to the
2257 -- class-wide type as well.
2259 elsif Class_Present
(Aspect
) then
2261 Make_Attribute_Reference
(Loc
,
2263 Attribute_Name
=> Name_Class
);
2267 -- Construct the attribute definition clause
2270 Make_Attribute_Definition_Clause
(Loc
,
2272 Chars
=> Chars
(Id
),
2273 Expression
=> Relocate_Node
(Expr
));
2275 -- If the address is specified, then we treat the entity as
2276 -- referenced, to avoid spurious warnings. This is analogous
2277 -- to what is done with an attribute definition clause, but
2278 -- here we don't want to generate a reference because this
2279 -- is the point of definition of the entity.
2281 if A_Id
= Aspect_Address
then
2285 -- Case 2: Aspects corresponding to pragmas
2287 -- Case 2a: Aspects corresponding to pragmas with two
2288 -- arguments, where the first argument is a local name
2289 -- referring to the entity, and the second argument is the
2290 -- aspect definition expression.
2292 -- Linker_Section/Suppress/Unsuppress
2294 when Aspect_Linker_Section
2299 (Pragma_Argument_Associations
=> New_List
(
2300 Make_Pragma_Argument_Association
(Loc
,
2301 Expression
=> New_Occurrence_Of
(E
, Loc
)),
2302 Make_Pragma_Argument_Association
(Sloc
(Expr
),
2303 Expression
=> Relocate_Node
(Expr
))),
2304 Pragma_Name
=> Chars
(Id
));
2306 -- Linker_Section does not need delaying, as its argument
2307 -- must be a static string. Furthermore, if applied to
2308 -- an object with an explicit initialization, the object
2309 -- must be frozen in order to elaborate the initialization
2310 -- code. (This is already done for types with implicit
2311 -- initialization, such as protected types.)
2313 if A_Id
= Aspect_Linker_Section
2314 and then Nkind
(N
) = N_Object_Declaration
2315 and then Has_Init_Expression
(N
)
2317 Delay_Required
:= False;
2322 -- Corresponds to pragma Implemented, construct the pragma
2324 when Aspect_Synchronization
=>
2326 (Pragma_Argument_Associations
=> New_List
(
2327 Make_Pragma_Argument_Association
(Loc
,
2328 Expression
=> New_Occurrence_Of
(E
, Loc
)),
2329 Make_Pragma_Argument_Association
(Sloc
(Expr
),
2330 Expression
=> Relocate_Node
(Expr
))),
2331 Pragma_Name
=> Name_Implemented
);
2335 when Aspect_Attach_Handler
=>
2337 (Pragma_Argument_Associations
=> New_List
(
2338 Make_Pragma_Argument_Association
(Sloc
(Ent
),
2340 Make_Pragma_Argument_Association
(Sloc
(Expr
),
2341 Expression
=> Relocate_Node
(Expr
))),
2342 Pragma_Name
=> Name_Attach_Handler
);
2344 -- We need to insert this pragma into the tree to get proper
2345 -- processing and to look valid from a placement viewpoint.
2347 Insert_Pragma
(Aitem
);
2350 -- Dynamic_Predicate, Predicate, Static_Predicate
2352 when Aspect_Dynamic_Predicate
2354 | Aspect_Static_Predicate
2356 -- These aspects apply only to subtypes
2358 if not Is_Type
(E
) then
2360 ("predicate can only be specified for a subtype",
2364 elsif Is_Incomplete_Type
(E
) then
2366 ("predicate cannot apply to incomplete view", Aspect
);
2370 -- Construct the pragma (always a pragma Predicate, with
2371 -- flags recording whether it is static/dynamic). We also
2372 -- set flags recording this in the type itself.
2375 (Pragma_Argument_Associations
=> New_List
(
2376 Make_Pragma_Argument_Association
(Sloc
(Ent
),
2378 Make_Pragma_Argument_Association
(Sloc
(Expr
),
2379 Expression
=> Relocate_Node
(Expr
))),
2380 Pragma_Name
=> Name_Predicate
);
2382 -- Mark type has predicates, and remember what kind of
2383 -- aspect lead to this predicate (we need this to access
2384 -- the right set of check policies later on).
2386 Set_Has_Predicates
(E
);
2388 if A_Id
= Aspect_Dynamic_Predicate
then
2389 Set_Has_Dynamic_Predicate_Aspect
(E
);
2391 -- If the entity has a dynamic predicate, any inherited
2392 -- static predicate becomes dynamic as well, and the
2393 -- predicate function includes the conjunction of both.
2395 Set_Has_Static_Predicate_Aspect
(E
, False);
2397 elsif A_Id
= Aspect_Static_Predicate
then
2398 Set_Has_Static_Predicate_Aspect
(E
);
2401 -- If the type is private, indicate that its completion
2402 -- has a freeze node, because that is the one that will
2403 -- be visible at freeze time.
2405 if Is_Private_Type
(E
) and then Present
(Full_View
(E
)) then
2406 Set_Has_Predicates
(Full_View
(E
));
2408 if A_Id
= Aspect_Dynamic_Predicate
then
2409 Set_Has_Dynamic_Predicate_Aspect
(Full_View
(E
));
2410 elsif A_Id
= Aspect_Static_Predicate
then
2411 Set_Has_Static_Predicate_Aspect
(Full_View
(E
));
2414 Set_Has_Delayed_Aspects
(Full_View
(E
));
2415 Ensure_Freeze_Node
(Full_View
(E
));
2418 -- Predicate_Failure
2420 when Aspect_Predicate_Failure
=>
2422 -- This aspect applies only to subtypes
2424 if not Is_Type
(E
) then
2426 ("predicate can only be specified for a subtype",
2430 elsif Is_Incomplete_Type
(E
) then
2432 ("predicate cannot apply to incomplete view", Aspect
);
2436 -- Construct the pragma
2439 (Pragma_Argument_Associations
=> New_List
(
2440 Make_Pragma_Argument_Association
(Sloc
(Ent
),
2442 Make_Pragma_Argument_Association
(Sloc
(Expr
),
2443 Expression
=> Relocate_Node
(Expr
))),
2444 Pragma_Name
=> Name_Predicate_Failure
);
2446 Set_Has_Predicates
(E
);
2448 -- If the type is private, indicate that its completion
2449 -- has a freeze node, because that is the one that will
2450 -- be visible at freeze time.
2452 if Is_Private_Type
(E
) and then Present
(Full_View
(E
)) then
2453 Set_Has_Predicates
(Full_View
(E
));
2454 Set_Has_Delayed_Aspects
(Full_View
(E
));
2455 Ensure_Freeze_Node
(Full_View
(E
));
2458 -- Case 2b: Aspects corresponding to pragmas with two
2459 -- arguments, where the second argument is a local name
2460 -- referring to the entity, and the first argument is the
2461 -- aspect definition expression.
2465 when Aspect_Convention
=>
2466 Analyze_Aspect_Convention
;
2469 -- External_Name, Link_Name
2471 when Aspect_External_Name
2474 Analyze_Aspect_External_Link_Name
;
2477 -- CPU, Interrupt_Priority, Priority
2479 -- These three aspects can be specified for a subprogram spec
2480 -- or body, in which case we analyze the expression and export
2481 -- the value of the aspect.
2483 -- Previously, we generated an equivalent pragma for bodies
2484 -- (note that the specs cannot contain these pragmas). The
2485 -- pragma was inserted ahead of local declarations, rather than
2486 -- after the body. This leads to a certain duplication between
2487 -- the processing performed for the aspect and the pragma, but
2488 -- given the straightforward handling required it is simpler
2489 -- to duplicate than to translate the aspect in the spec into
2490 -- a pragma in the declarative part of the body.
2493 | Aspect_Interrupt_Priority
2496 if Nkind_In
(N
, N_Subprogram_Body
,
2497 N_Subprogram_Declaration
)
2499 -- Analyze the aspect expression
2501 Analyze_And_Resolve
(Expr
, Standard_Integer
);
2503 -- Interrupt_Priority aspect not allowed for main
2504 -- subprograms. RM D.1 does not forbid this explicitly,
2505 -- but RM J.15.11(6/3) does not permit pragma
2506 -- Interrupt_Priority for subprograms.
2508 if A_Id
= Aspect_Interrupt_Priority
then
2510 ("Interrupt_Priority aspect cannot apply to "
2511 & "subprogram", Expr
);
2513 -- The expression must be static
2515 elsif not Is_OK_Static_Expression
(Expr
) then
2516 Flag_Non_Static_Expr
2517 ("aspect requires static expression!", Expr
);
2519 -- Check whether this is the main subprogram. Issue a
2520 -- warning only if it is obviously not a main program
2521 -- (when it has parameters or when the subprogram is
2522 -- within a package).
2524 elsif Present
(Parameter_Specifications
2525 (Specification
(N
)))
2526 or else not Is_Compilation_Unit
(Defining_Entity
(N
))
2528 -- See RM D.1(14/3) and D.16(12/3)
2531 ("aspect applied to subprogram other than the "
2532 & "main subprogram has no effect??", Expr
);
2534 -- Otherwise check in range and export the value
2536 -- For the CPU aspect
2538 elsif A_Id
= Aspect_CPU
then
2539 if Is_In_Range
(Expr
, RTE
(RE_CPU_Range
)) then
2541 -- Value is correct so we export the value to make
2542 -- it available at execution time.
2545 (Main_Unit
, UI_To_Int
(Expr_Value
(Expr
)));
2549 ("main subprogram CPU is out of range", Expr
);
2552 -- For the Priority aspect
2554 elsif A_Id
= Aspect_Priority
then
2555 if Is_In_Range
(Expr
, RTE
(RE_Priority
)) then
2557 -- Value is correct so we export the value to make
2558 -- it available at execution time.
2561 (Main_Unit
, UI_To_Int
(Expr_Value
(Expr
)));
2563 -- Ignore pragma if Relaxed_RM_Semantics to support
2564 -- other targets/non GNAT compilers.
2566 elsif not Relaxed_RM_Semantics
then
2568 ("main subprogram priority is out of range",
2573 -- Load an arbitrary entity from System.Tasking.Stages
2574 -- or System.Tasking.Restricted.Stages (depending on
2575 -- the supported profile) to make sure that one of these
2576 -- packages is implicitly with'ed, since we need to have
2577 -- the tasking run time active for the pragma Priority to
2578 -- have any effect. Previously we with'ed the package
2579 -- System.Tasking, but this package does not trigger the
2580 -- required initialization of the run-time library.
2583 Discard
: Entity_Id
;
2585 if Restricted_Profile
then
2586 Discard
:= RTE
(RE_Activate_Restricted_Tasks
);
2588 Discard
:= RTE
(RE_Activate_Tasks
);
2592 -- Handling for these aspects in subprograms is complete
2596 -- For task and protected types pass the aspect as an
2601 Make_Attribute_Definition_Clause
(Loc
,
2603 Chars
=> Chars
(Id
),
2604 Expression
=> Relocate_Node
(Expr
));
2609 when Aspect_Warnings
=>
2611 (Pragma_Argument_Associations
=> New_List
(
2612 Make_Pragma_Argument_Association
(Sloc
(Expr
),
2613 Expression
=> Relocate_Node
(Expr
)),
2614 Make_Pragma_Argument_Association
(Loc
,
2615 Expression
=> New_Occurrence_Of
(E
, Loc
))),
2616 Pragma_Name
=> Chars
(Id
));
2618 Decorate
(Aspect
, Aitem
);
2619 Insert_Pragma
(Aitem
);
2622 -- Case 2c: Aspects corresponding to pragmas with three
2625 -- Invariant aspects have a first argument that references the
2626 -- entity, a second argument that is the expression and a third
2627 -- argument that is an appropriate message.
2629 -- Invariant, Type_Invariant
2631 when Aspect_Invariant
2632 | Aspect_Type_Invariant
2634 -- Analysis of the pragma will verify placement legality:
2635 -- an invariant must apply to a private type, or appear in
2636 -- the private part of a spec and apply to a completion.
2639 (Pragma_Argument_Associations
=> New_List
(
2640 Make_Pragma_Argument_Association
(Sloc
(Ent
),
2642 Make_Pragma_Argument_Association
(Sloc
(Expr
),
2643 Expression
=> Relocate_Node
(Expr
))),
2644 Pragma_Name
=> Name_Invariant
);
2646 -- Add message unless exception messages are suppressed
2648 if not Opt
.Exception_Locations_Suppressed
then
2649 Append_To
(Pragma_Argument_Associations
(Aitem
),
2650 Make_Pragma_Argument_Association
(Eloc
,
2651 Chars
=> Name_Message
,
2653 Make_String_Literal
(Eloc
,
2654 Strval
=> "failed invariant from "
2655 & Build_Location_String
(Eloc
))));
2658 -- For Invariant case, insert immediately after the entity
2659 -- declaration. We do not have to worry about delay issues
2660 -- since the pragma processing takes care of this.
2662 Delay_Required
:= False;
2664 -- Case 2d : Aspects that correspond to a pragma with one
2669 -- Aspect Abstract_State introduces implicit declarations for
2670 -- all state abstraction entities it defines. To emulate this
2671 -- behavior, insert the pragma at the beginning of the visible
2672 -- declarations of the related package so that it is analyzed
2675 when Aspect_Abstract_State
=> Abstract_State
: declare
2676 Context
: Node_Id
:= N
;
2679 -- When aspect Abstract_State appears on a generic package,
2680 -- it is propageted to the package instance. The context in
2681 -- this case is the instance spec.
2683 if Nkind
(Context
) = N_Package_Instantiation
then
2684 Context
:= Instance_Spec
(Context
);
2687 if Nkind_In
(Context
, N_Generic_Package_Declaration
,
2688 N_Package_Declaration
)
2691 (Pragma_Argument_Associations
=> New_List
(
2692 Make_Pragma_Argument_Association
(Loc
,
2693 Expression
=> Relocate_Node
(Expr
))),
2694 Pragma_Name
=> Name_Abstract_State
);
2696 Decorate
(Aspect
, Aitem
);
2700 Is_Generic_Instance
(Defining_Entity
(Context
)));
2704 ("aspect & must apply to a package declaration",
2711 -- Aspect Async_Readers is never delayed because it is
2712 -- equivalent to a source pragma which appears after the
2713 -- related object declaration.
2715 when Aspect_Async_Readers
=>
2717 (Pragma_Argument_Associations
=> New_List
(
2718 Make_Pragma_Argument_Association
(Loc
,
2719 Expression
=> Relocate_Node
(Expr
))),
2720 Pragma_Name
=> Name_Async_Readers
);
2722 Decorate
(Aspect
, Aitem
);
2723 Insert_Pragma
(Aitem
);
2726 -- Aspect Async_Writers is never delayed because it is
2727 -- equivalent to a source pragma which appears after the
2728 -- related object declaration.
2730 when Aspect_Async_Writers
=>
2732 (Pragma_Argument_Associations
=> New_List
(
2733 Make_Pragma_Argument_Association
(Loc
,
2734 Expression
=> Relocate_Node
(Expr
))),
2735 Pragma_Name
=> Name_Async_Writers
);
2737 Decorate
(Aspect
, Aitem
);
2738 Insert_Pragma
(Aitem
);
2741 -- Aspect Constant_After_Elaboration is never delayed because
2742 -- it is equivalent to a source pragma which appears after the
2743 -- related object declaration.
2745 when Aspect_Constant_After_Elaboration
=>
2747 (Pragma_Argument_Associations
=> New_List
(
2748 Make_Pragma_Argument_Association
(Loc
,
2749 Expression
=> Relocate_Node
(Expr
))),
2751 Name_Constant_After_Elaboration
);
2753 Decorate
(Aspect
, Aitem
);
2754 Insert_Pragma
(Aitem
);
2757 -- Aspect Default_Internal_Condition is never delayed because
2758 -- it is equivalent to a source pragma which appears after the
2759 -- related private type. To deal with forward references, the
2760 -- generated pragma is stored in the rep chain of the related
2761 -- private type as types do not carry contracts. The pragma is
2762 -- wrapped inside of a procedure at the freeze point of the
2763 -- private type's full view.
2765 when Aspect_Default_Initial_Condition
=>
2767 (Pragma_Argument_Associations
=> New_List
(
2768 Make_Pragma_Argument_Association
(Loc
,
2769 Expression
=> Relocate_Node
(Expr
))),
2771 Name_Default_Initial_Condition
);
2773 Decorate
(Aspect
, Aitem
);
2774 Insert_Pragma
(Aitem
);
2777 -- Default_Storage_Pool
2779 when Aspect_Default_Storage_Pool
=>
2781 (Pragma_Argument_Associations
=> New_List
(
2782 Make_Pragma_Argument_Association
(Loc
,
2783 Expression
=> Relocate_Node
(Expr
))),
2785 Name_Default_Storage_Pool
);
2787 Decorate
(Aspect
, Aitem
);
2788 Insert_Pragma
(Aitem
);
2793 -- Aspect Depends is never delayed because it is equivalent to
2794 -- a source pragma which appears after the related subprogram.
2795 -- To deal with forward references, the generated pragma is
2796 -- stored in the contract of the related subprogram and later
2797 -- analyzed at the end of the declarative region. See routine
2798 -- Analyze_Depends_In_Decl_Part for details.
2800 when Aspect_Depends
=>
2802 (Pragma_Argument_Associations
=> New_List
(
2803 Make_Pragma_Argument_Association
(Loc
,
2804 Expression
=> Relocate_Node
(Expr
))),
2805 Pragma_Name
=> Name_Depends
);
2807 Decorate
(Aspect
, Aitem
);
2808 Insert_Pragma
(Aitem
);
2811 -- Aspect Effecitve_Reads is never delayed because it is
2812 -- equivalent to a source pragma which appears after the
2813 -- related object declaration.
2815 when Aspect_Effective_Reads
=>
2817 (Pragma_Argument_Associations
=> New_List
(
2818 Make_Pragma_Argument_Association
(Loc
,
2819 Expression
=> Relocate_Node
(Expr
))),
2820 Pragma_Name
=> Name_Effective_Reads
);
2822 Decorate
(Aspect
, Aitem
);
2823 Insert_Pragma
(Aitem
);
2826 -- Aspect Effective_Writes is never delayed because it is
2827 -- equivalent to a source pragma which appears after the
2828 -- related object declaration.
2830 when Aspect_Effective_Writes
=>
2832 (Pragma_Argument_Associations
=> New_List
(
2833 Make_Pragma_Argument_Association
(Loc
,
2834 Expression
=> Relocate_Node
(Expr
))),
2835 Pragma_Name
=> Name_Effective_Writes
);
2837 Decorate
(Aspect
, Aitem
);
2838 Insert_Pragma
(Aitem
);
2841 -- Aspect Extensions_Visible is never delayed because it is
2842 -- equivalent to a source pragma which appears after the
2843 -- related subprogram.
2845 when Aspect_Extensions_Visible
=>
2847 (Pragma_Argument_Associations
=> New_List
(
2848 Make_Pragma_Argument_Association
(Loc
,
2849 Expression
=> Relocate_Node
(Expr
))),
2850 Pragma_Name
=> Name_Extensions_Visible
);
2852 Decorate
(Aspect
, Aitem
);
2853 Insert_Pragma
(Aitem
);
2856 -- Aspect Ghost is never delayed because it is equivalent to a
2857 -- source pragma which appears at the top of [generic] package
2858 -- declarations or after an object, a [generic] subprogram, or
2859 -- a type declaration.
2861 when Aspect_Ghost
=>
2863 (Pragma_Argument_Associations
=> New_List
(
2864 Make_Pragma_Argument_Association
(Loc
,
2865 Expression
=> Relocate_Node
(Expr
))),
2866 Pragma_Name
=> Name_Ghost
);
2868 Decorate
(Aspect
, Aitem
);
2869 Insert_Pragma
(Aitem
);
2874 -- Aspect Global is never delayed because it is equivalent to
2875 -- a source pragma which appears after the related subprogram.
2876 -- To deal with forward references, the generated pragma is
2877 -- stored in the contract of the related subprogram and later
2878 -- analyzed at the end of the declarative region. See routine
2879 -- Analyze_Global_In_Decl_Part for details.
2881 when Aspect_Global
=>
2883 (Pragma_Argument_Associations
=> New_List
(
2884 Make_Pragma_Argument_Association
(Loc
,
2885 Expression
=> Relocate_Node
(Expr
))),
2886 Pragma_Name
=> Name_Global
);
2888 Decorate
(Aspect
, Aitem
);
2889 Insert_Pragma
(Aitem
);
2892 -- Initial_Condition
2894 -- Aspect Initial_Condition is never delayed because it is
2895 -- equivalent to a source pragma which appears after the
2896 -- related package. To deal with forward references, the
2897 -- generated pragma is stored in the contract of the related
2898 -- package and later analyzed at the end of the declarative
2899 -- region. See routine Analyze_Initial_Condition_In_Decl_Part
2902 when Aspect_Initial_Condition
=> Initial_Condition
: declare
2903 Context
: Node_Id
:= N
;
2906 -- When aspect Initial_Condition appears on a generic
2907 -- package, it is propageted to the package instance. The
2908 -- context in this case is the instance spec.
2910 if Nkind
(Context
) = N_Package_Instantiation
then
2911 Context
:= Instance_Spec
(Context
);
2914 if Nkind_In
(Context
, N_Generic_Package_Declaration
,
2915 N_Package_Declaration
)
2918 (Pragma_Argument_Associations
=> New_List
(
2919 Make_Pragma_Argument_Association
(Loc
,
2920 Expression
=> Relocate_Node
(Expr
))),
2922 Name_Initial_Condition
);
2924 Decorate
(Aspect
, Aitem
);
2928 Is_Generic_Instance
(Defining_Entity
(Context
)));
2930 -- Otherwise the context is illegal
2934 ("aspect & must apply to a package declaration",
2939 end Initial_Condition
;
2943 -- Aspect Initializes is never delayed because it is equivalent
2944 -- to a source pragma appearing after the related package. To
2945 -- deal with forward references, the generated pragma is stored
2946 -- in the contract of the related package and later analyzed at
2947 -- the end of the declarative region. For details, see routine
2948 -- Analyze_Initializes_In_Decl_Part.
2950 when Aspect_Initializes
=> Initializes
: declare
2951 Context
: Node_Id
:= N
;
2954 -- When aspect Initializes appears on a generic package,
2955 -- it is propageted to the package instance. The context
2956 -- in this case is the instance spec.
2958 if Nkind
(Context
) = N_Package_Instantiation
then
2959 Context
:= Instance_Spec
(Context
);
2962 if Nkind_In
(Context
, N_Generic_Package_Declaration
,
2963 N_Package_Declaration
)
2966 (Pragma_Argument_Associations
=> New_List
(
2967 Make_Pragma_Argument_Association
(Loc
,
2968 Expression
=> Relocate_Node
(Expr
))),
2969 Pragma_Name
=> Name_Initializes
);
2971 Decorate
(Aspect
, Aitem
);
2975 Is_Generic_Instance
(Defining_Entity
(Context
)));
2977 -- Otherwise the context is illegal
2981 ("aspect & must apply to a package declaration",
2990 when Aspect_Max_Queue_Length
=>
2992 (Pragma_Argument_Associations
=> New_List
(
2993 Make_Pragma_Argument_Association
(Loc
,
2994 Expression
=> Relocate_Node
(Expr
))),
2995 Pragma_Name
=> Name_Max_Queue_Length
);
2997 Decorate
(Aspect
, Aitem
);
2998 Insert_Pragma
(Aitem
);
3003 when Aspect_Obsolescent
=> declare
3011 Make_Pragma_Argument_Association
(Sloc
(Expr
),
3012 Expression
=> Relocate_Node
(Expr
)));
3016 (Pragma_Argument_Associations
=> Args
,
3017 Pragma_Name
=> Chars
(Id
));
3022 when Aspect_Part_Of
=>
3023 if Nkind_In
(N
, N_Object_Declaration
,
3024 N_Package_Instantiation
)
3025 or else Is_Single_Concurrent_Type_Declaration
(N
)
3028 (Pragma_Argument_Associations
=> New_List
(
3029 Make_Pragma_Argument_Association
(Loc
,
3030 Expression
=> Relocate_Node
(Expr
))),
3031 Pragma_Name
=> Name_Part_Of
);
3033 Decorate
(Aspect
, Aitem
);
3034 Insert_Pragma
(Aitem
);
3038 ("aspect & must apply to package instantiation, "
3039 & "object, single protected type or single task type",
3047 when Aspect_SPARK_Mode
=>
3049 (Pragma_Argument_Associations
=> New_List
(
3050 Make_Pragma_Argument_Association
(Loc
,
3051 Expression
=> Relocate_Node
(Expr
))),
3052 Pragma_Name
=> Name_SPARK_Mode
);
3054 Decorate
(Aspect
, Aitem
);
3055 Insert_Pragma
(Aitem
);
3060 -- Aspect Refined_Depends is never delayed because it is
3061 -- equivalent to a source pragma which appears in the
3062 -- declarations of the related subprogram body. To deal with
3063 -- forward references, the generated pragma is stored in the
3064 -- contract of the related subprogram body and later analyzed
3065 -- at the end of the declarative region. For details, see
3066 -- routine Analyze_Refined_Depends_In_Decl_Part.
3068 when Aspect_Refined_Depends
=>
3070 (Pragma_Argument_Associations
=> New_List
(
3071 Make_Pragma_Argument_Association
(Loc
,
3072 Expression
=> Relocate_Node
(Expr
))),
3073 Pragma_Name
=> Name_Refined_Depends
);
3075 Decorate
(Aspect
, Aitem
);
3076 Insert_Pragma
(Aitem
);
3081 -- Aspect Refined_Global is never delayed because it is
3082 -- equivalent to a source pragma which appears in the
3083 -- declarations of the related subprogram body. To deal with
3084 -- forward references, the generated pragma is stored in the
3085 -- contract of the related subprogram body and later analyzed
3086 -- at the end of the declarative region. For details, see
3087 -- routine Analyze_Refined_Global_In_Decl_Part.
3089 when Aspect_Refined_Global
=>
3091 (Pragma_Argument_Associations
=> New_List
(
3092 Make_Pragma_Argument_Association
(Loc
,
3093 Expression
=> Relocate_Node
(Expr
))),
3094 Pragma_Name
=> Name_Refined_Global
);
3096 Decorate
(Aspect
, Aitem
);
3097 Insert_Pragma
(Aitem
);
3102 when Aspect_Refined_Post
=>
3104 (Pragma_Argument_Associations
=> New_List
(
3105 Make_Pragma_Argument_Association
(Loc
,
3106 Expression
=> Relocate_Node
(Expr
))),
3107 Pragma_Name
=> Name_Refined_Post
);
3109 Decorate
(Aspect
, Aitem
);
3110 Insert_Pragma
(Aitem
);
3115 when Aspect_Refined_State
=>
3117 -- The corresponding pragma for Refined_State is inserted in
3118 -- the declarations of the related package body. This action
3119 -- synchronizes both the source and from-aspect versions of
3122 if Nkind
(N
) = N_Package_Body
then
3124 (Pragma_Argument_Associations
=> New_List
(
3125 Make_Pragma_Argument_Association
(Loc
,
3126 Expression
=> Relocate_Node
(Expr
))),
3127 Pragma_Name
=> Name_Refined_State
);
3129 Decorate
(Aspect
, Aitem
);
3130 Insert_Pragma
(Aitem
);
3132 -- Otherwise the context is illegal
3136 ("aspect & must apply to a package body", Aspect
, Id
);
3141 -- Relative_Deadline
3143 when Aspect_Relative_Deadline
=>
3145 (Pragma_Argument_Associations
=> New_List
(
3146 Make_Pragma_Argument_Association
(Loc
,
3147 Expression
=> Relocate_Node
(Expr
))),
3148 Pragma_Name
=> Name_Relative_Deadline
);
3150 -- If the aspect applies to a task, the corresponding pragma
3151 -- must appear within its declarations, not after.
3153 if Nkind
(N
) = N_Task_Type_Declaration
then
3159 if No
(Task_Definition
(N
)) then
3160 Set_Task_Definition
(N
,
3161 Make_Task_Definition
(Loc
,
3162 Visible_Declarations
=> New_List
,
3163 End_Label
=> Empty
));
3166 Def
:= Task_Definition
(N
);
3167 V
:= Visible_Declarations
(Def
);
3168 if not Is_Empty_List
(V
) then
3169 Insert_Before
(First
(V
), Aitem
);
3172 Set_Visible_Declarations
(Def
, New_List
(Aitem
));
3179 -- Aspect Volatile_Function is never delayed because it is
3180 -- equivalent to a source pragma which appears after the
3181 -- related subprogram.
3183 when Aspect_Volatile_Function
=>
3185 (Pragma_Argument_Associations
=> New_List
(
3186 Make_Pragma_Argument_Association
(Loc
,
3187 Expression
=> Relocate_Node
(Expr
))),
3188 Pragma_Name
=> Name_Volatile_Function
);
3190 Decorate
(Aspect
, Aitem
);
3191 Insert_Pragma
(Aitem
);
3194 -- Case 2e: Annotate aspect
3196 when Aspect_Annotate
=>
3203 -- The argument can be a single identifier
3205 if Nkind
(Expr
) = N_Identifier
then
3207 -- One level of parens is allowed
3209 if Paren_Count
(Expr
) > 1 then
3210 Error_Msg_F
("extra parentheses ignored", Expr
);
3213 Set_Paren_Count
(Expr
, 0);
3215 -- Add the single item to the list
3217 Args
:= New_List
(Expr
);
3219 -- Otherwise we must have an aggregate
3221 elsif Nkind
(Expr
) = N_Aggregate
then
3223 -- Must be positional
3225 if Present
(Component_Associations
(Expr
)) then
3227 ("purely positional aggregate required", Expr
);
3231 -- Must not be parenthesized
3233 if Paren_Count
(Expr
) /= 0 then
3234 Error_Msg_F
("extra parentheses ignored", Expr
);
3237 -- List of arguments is list of aggregate expressions
3239 Args
:= Expressions
(Expr
);
3241 -- Anything else is illegal
3244 Error_Msg_F
("wrong form for Annotate aspect", Expr
);
3248 -- Prepare pragma arguments
3251 Arg
:= First
(Args
);
3252 while Present
(Arg
) loop
3254 Make_Pragma_Argument_Association
(Sloc
(Arg
),
3255 Expression
=> Relocate_Node
(Arg
)));
3260 Make_Pragma_Argument_Association
(Sloc
(Ent
),
3261 Chars
=> Name_Entity
,
3262 Expression
=> Ent
));
3265 (Pragma_Argument_Associations
=> Pargs
,
3266 Pragma_Name
=> Name_Annotate
);
3269 -- Case 3 : Aspects that don't correspond to pragma/attribute
3270 -- definition clause.
3272 -- Case 3a: The aspects listed below don't correspond to
3273 -- pragmas/attributes but do require delayed analysis.
3275 -- Default_Value can only apply to a scalar type
3277 when Aspect_Default_Value
=>
3278 if not Is_Scalar_Type
(E
) then
3280 ("aspect Default_Value must apply to a scalar type", N
);
3285 -- Default_Component_Value can only apply to an array type
3286 -- with scalar components.
3288 when Aspect_Default_Component_Value
=>
3289 if not (Is_Array_Type
(E
)
3290 and then Is_Scalar_Type
(Component_Type
(E
)))
3293 ("aspect Default_Component_Value can only apply to an "
3294 & "array of scalar components", N
);
3299 -- Case 3b: The aspects listed below don't correspond to
3300 -- pragmas/attributes and don't need delayed analysis.
3302 -- Implicit_Dereference
3304 -- For Implicit_Dereference, External_Name and Link_Name, only
3305 -- the legality checks are done during the analysis, thus no
3306 -- delay is required.
3308 when Aspect_Implicit_Dereference
=>
3309 Analyze_Aspect_Implicit_Dereference
;
3314 when Aspect_Dimension
=>
3315 Analyze_Aspect_Dimension
(N
, Id
, Expr
);
3320 when Aspect_Dimension_System
=>
3321 Analyze_Aspect_Dimension_System
(N
, Id
, Expr
);
3324 -- Case 4: Aspects requiring special handling
3326 -- Pre/Post/Test_Case/Contract_Cases whose corresponding
3327 -- pragmas take care of the delay.
3331 -- Aspects Pre/Post generate Precondition/Postcondition pragmas
3332 -- with a first argument that is the expression, and a second
3333 -- argument that is an informative message if the test fails.
3334 -- This is inserted right after the declaration, to get the
3335 -- required pragma placement. The processing for the pragmas
3336 -- takes care of the required delay.
3338 when Pre_Post_Aspects
=> Pre_Post
: declare
3342 if A_Id
= Aspect_Pre
or else A_Id
= Aspect_Precondition
then
3343 Pname
:= Name_Precondition
;
3345 Pname
:= Name_Postcondition
;
3348 -- Check that the class-wide predicate cannot be applied to
3349 -- an operation of a synchronized type. AI12-0182 forbids
3350 -- these altogether, while earlier language semantics made
3351 -- them legal on tagged synchronized types.
3353 -- Other legality checks are performed when analyzing the
3354 -- contract of the operation.
3356 if Class_Present
(Aspect
)
3357 and then Is_Concurrent_Type
(Current_Scope
)
3358 and then Ekind_In
(E
, E_Entry
, E_Function
, E_Procedure
)
3360 Error_Msg_Name_1
:= Original_Aspect_Pragma_Name
(Aspect
);
3362 ("aspect % can only be specified for a primitive "
3363 & "operation of a tagged type", Aspect
);
3368 -- If the expressions is of the form A and then B, then
3369 -- we generate separate Pre/Post aspects for the separate
3370 -- clauses. Since we allow multiple pragmas, there is no
3371 -- problem in allowing multiple Pre/Post aspects internally.
3372 -- These should be treated in reverse order (B first and
3373 -- A second) since they are later inserted just after N in
3374 -- the order they are treated. This way, the pragma for A
3375 -- ends up preceding the pragma for B, which may have an
3376 -- importance for the error raised (either constraint error
3377 -- or precondition error).
3379 -- We do not do this for Pre'Class, since we have to put
3380 -- these conditions together in a complex OR expression.
3382 -- We do not do this in ASIS mode, as ASIS relies on the
3383 -- original node representing the complete expression, when
3384 -- retrieving it through the source aspect table.
3387 and then (Pname
= Name_Postcondition
3388 or else not Class_Present
(Aspect
))
3390 while Nkind
(Expr
) = N_And_Then
loop
3391 Insert_After
(Aspect
,
3392 Make_Aspect_Specification
(Sloc
(Left_Opnd
(Expr
)),
3393 Identifier
=> Identifier
(Aspect
),
3394 Expression
=> Relocate_Node
(Left_Opnd
(Expr
)),
3395 Class_Present
=> Class_Present
(Aspect
),
3396 Split_PPC
=> True));
3397 Rewrite
(Expr
, Relocate_Node
(Right_Opnd
(Expr
)));
3398 Eloc
:= Sloc
(Expr
);
3402 -- Build the precondition/postcondition pragma
3404 -- Add note about why we do NOT need Copy_Tree here???
3407 (Pragma_Argument_Associations
=> New_List
(
3408 Make_Pragma_Argument_Association
(Eloc
,
3409 Chars
=> Name_Check
,
3410 Expression
=> Relocate_Node
(Expr
))),
3411 Pragma_Name
=> Pname
);
3413 -- Add message unless exception messages are suppressed
3415 if not Opt
.Exception_Locations_Suppressed
then
3416 Append_To
(Pragma_Argument_Associations
(Aitem
),
3417 Make_Pragma_Argument_Association
(Eloc
,
3418 Chars
=> Name_Message
,
3420 Make_String_Literal
(Eloc
,
3422 & Get_Name_String
(Pname
)
3424 & Build_Location_String
(Eloc
))));
3427 Set_Is_Delayed_Aspect
(Aspect
);
3429 -- For Pre/Post cases, insert immediately after the entity
3430 -- declaration, since that is the required pragma placement.
3431 -- Note that for these aspects, we do not have to worry
3432 -- about delay issues, since the pragmas themselves deal
3433 -- with delay of visibility for the expression analysis.
3435 Insert_Pragma
(Aitem
);
3442 when Aspect_Test_Case
=> Test_Case
: declare
3444 Comp_Expr
: Node_Id
;
3445 Comp_Assn
: Node_Id
;
3451 if Nkind
(Parent
(N
)) = N_Compilation_Unit
then
3452 Error_Msg_Name_1
:= Nam
;
3453 Error_Msg_N
("incorrect placement of aspect `%`", E
);
3457 if Nkind
(Expr
) /= N_Aggregate
then
3458 Error_Msg_Name_1
:= Nam
;
3460 ("wrong syntax for aspect `%` for &", Id
, E
);
3464 -- Make pragma expressions refer to the original aspect
3465 -- expressions through the Original_Node link. This is used
3466 -- in semantic analysis for ASIS mode, so that the original
3467 -- expression also gets analyzed.
3469 Comp_Expr
:= First
(Expressions
(Expr
));
3470 while Present
(Comp_Expr
) loop
3471 New_Expr
:= Relocate_Node
(Comp_Expr
);
3473 Make_Pragma_Argument_Association
(Sloc
(Comp_Expr
),
3474 Expression
=> New_Expr
));
3478 Comp_Assn
:= First
(Component_Associations
(Expr
));
3479 while Present
(Comp_Assn
) loop
3480 if List_Length
(Choices
(Comp_Assn
)) /= 1
3482 Nkind
(First
(Choices
(Comp_Assn
))) /= N_Identifier
3484 Error_Msg_Name_1
:= Nam
;
3486 ("wrong syntax for aspect `%` for &", Id
, E
);
3491 Make_Pragma_Argument_Association
(Sloc
(Comp_Assn
),
3492 Chars
=> Chars
(First
(Choices
(Comp_Assn
))),
3494 Relocate_Node
(Expression
(Comp_Assn
))));
3498 -- Build the test-case pragma
3501 (Pragma_Argument_Associations
=> Args
,
3502 Pragma_Name
=> Nam
);
3507 when Aspect_Contract_Cases
=>
3509 (Pragma_Argument_Associations
=> New_List
(
3510 Make_Pragma_Argument_Association
(Loc
,
3511 Expression
=> Relocate_Node
(Expr
))),
3512 Pragma_Name
=> Nam
);
3514 Decorate
(Aspect
, Aitem
);
3515 Insert_Pragma
(Aitem
);
3518 -- Case 5: Special handling for aspects with an optional
3519 -- boolean argument.
3521 -- In the delayed case, the corresponding pragma cannot be
3522 -- generated yet because the evaluation of the boolean needs
3523 -- to be delayed till the freeze point.
3525 when Boolean_Aspects
3526 | Library_Unit_Aspects
3528 Set_Is_Boolean_Aspect
(Aspect
);
3530 -- Lock_Free aspect only apply to protected objects
3532 if A_Id
= Aspect_Lock_Free
then
3533 if Ekind
(E
) /= E_Protected_Type
then
3534 Error_Msg_Name_1
:= Nam
;
3536 ("aspect % only applies to a protected object",
3540 -- Set the Uses_Lock_Free flag to True if there is no
3541 -- expression or if the expression is True. The
3542 -- evaluation of this aspect should be delayed to the
3543 -- freeze point (why???)
3546 or else Is_True
(Static_Boolean
(Expr
))
3548 Set_Uses_Lock_Free
(E
);
3551 Record_Rep_Item
(E
, Aspect
);
3556 elsif A_Id
= Aspect_Export
or else A_Id
= Aspect_Import
then
3557 Analyze_Aspect_Export_Import
;
3559 -- Disable_Controlled
3561 elsif A_Id
= Aspect_Disable_Controlled
then
3562 Analyze_Aspect_Disable_Controlled
;
3566 -- Library unit aspects require special handling in the case
3567 -- of a package declaration, the pragma needs to be inserted
3568 -- in the list of declarations for the associated package.
3569 -- There is no issue of visibility delay for these aspects.
3571 if A_Id
in Library_Unit_Aspects
3573 Nkind_In
(N
, N_Package_Declaration
,
3574 N_Generic_Package_Declaration
)
3575 and then Nkind
(Parent
(N
)) /= N_Compilation_Unit
3577 -- Aspect is legal on a local instantiation of a library-
3578 -- level generic unit.
3580 and then not Is_Generic_Instance
(Defining_Entity
(N
))
3583 ("incorrect context for library unit aspect&", Id
);
3587 -- Cases where we do not delay, includes all cases where the
3588 -- expression is missing other than the above cases.
3590 if not Delay_Required
or else No
(Expr
) then
3592 -- Exclude aspects Export and Import because their pragma
3593 -- syntax does not map directly to a Boolean aspect.
3595 if A_Id
/= Aspect_Export
3596 and then A_Id
/= Aspect_Import
3599 (Pragma_Argument_Associations
=> New_List
(
3600 Make_Pragma_Argument_Association
(Sloc
(Ent
),
3601 Expression
=> Ent
)),
3602 Pragma_Name
=> Chars
(Id
));
3605 Delay_Required
:= False;
3607 -- In general cases, the corresponding pragma/attribute
3608 -- definition clause will be inserted later at the freezing
3609 -- point, and we do not need to build it now.
3617 -- This is special because for access types we need to generate
3618 -- an attribute definition clause. This also works for single
3619 -- task declarations, but it does not work for task type
3620 -- declarations, because we have the case where the expression
3621 -- references a discriminant of the task type. That can't use
3622 -- an attribute definition clause because we would not have
3623 -- visibility on the discriminant. For that case we must
3624 -- generate a pragma in the task definition.
3626 when Aspect_Storage_Size
=>
3630 if Ekind
(E
) = E_Task_Type
then
3632 Decl
: constant Node_Id
:= Declaration_Node
(E
);
3635 pragma Assert
(Nkind
(Decl
) = N_Task_Type_Declaration
);
3637 -- If no task definition, create one
3639 if No
(Task_Definition
(Decl
)) then
3640 Set_Task_Definition
(Decl
,
3641 Make_Task_Definition
(Loc
,
3642 Visible_Declarations
=> Empty_List
,
3643 End_Label
=> Empty
));
3646 -- Create a pragma and put it at the start of the task
3647 -- definition for the task type declaration.
3650 (Pragma_Argument_Associations
=> New_List
(
3651 Make_Pragma_Argument_Association
(Loc
,
3652 Expression
=> Relocate_Node
(Expr
))),
3653 Pragma_Name
=> Name_Storage_Size
);
3657 Visible_Declarations
(Task_Definition
(Decl
)));
3661 -- All other cases, generate attribute definition
3665 Make_Attribute_Definition_Clause
(Loc
,
3667 Chars
=> Chars
(Id
),
3668 Expression
=> Relocate_Node
(Expr
));
3672 -- Attach the corresponding pragma/attribute definition clause to
3673 -- the aspect specification node.
3675 if Present
(Aitem
) then
3676 Set_From_Aspect_Specification
(Aitem
);
3679 -- In the context of a compilation unit, we directly put the
3680 -- pragma in the Pragmas_After list of the N_Compilation_Unit_Aux
3681 -- node (no delay is required here) except for aspects on a
3682 -- subprogram body (see below) and a generic package, for which we
3683 -- need to introduce the pragma before building the generic copy
3684 -- (see sem_ch12), and for package instantiations, where the
3685 -- library unit pragmas are better handled early.
3687 if Nkind
(Parent
(N
)) = N_Compilation_Unit
3688 and then (Present
(Aitem
) or else Is_Boolean_Aspect
(Aspect
))
3691 Aux
: constant Node_Id
:= Aux_Decls_Node
(Parent
(N
));
3694 pragma Assert
(Nkind
(Aux
) = N_Compilation_Unit_Aux
);
3696 -- For a Boolean aspect, create the corresponding pragma if
3697 -- no expression or if the value is True.
3699 if Is_Boolean_Aspect
(Aspect
) and then No
(Aitem
) then
3700 if Is_True
(Static_Boolean
(Expr
)) then
3702 (Pragma_Argument_Associations
=> New_List
(
3703 Make_Pragma_Argument_Association
(Sloc
(Ent
),
3704 Expression
=> Ent
)),
3705 Pragma_Name
=> Chars
(Id
));
3707 Set_From_Aspect_Specification
(Aitem
, True);
3708 Set_Corresponding_Aspect
(Aitem
, Aspect
);
3715 -- If the aspect is on a subprogram body (relevant aspect
3716 -- is Inline), add the pragma in front of the declarations.
3718 if Nkind
(N
) = N_Subprogram_Body
then
3719 if No
(Declarations
(N
)) then
3720 Set_Declarations
(N
, New_List
);
3723 Prepend
(Aitem
, Declarations
(N
));
3725 elsif Nkind
(N
) = N_Generic_Package_Declaration
then
3726 if No
(Visible_Declarations
(Specification
(N
))) then
3727 Set_Visible_Declarations
(Specification
(N
), New_List
);
3731 Visible_Declarations
(Specification
(N
)));
3733 elsif Nkind
(N
) = N_Package_Instantiation
then
3735 Spec
: constant Node_Id
:=
3736 Specification
(Instance_Spec
(N
));
3738 if No
(Visible_Declarations
(Spec
)) then
3739 Set_Visible_Declarations
(Spec
, New_List
);
3742 Prepend
(Aitem
, Visible_Declarations
(Spec
));
3746 if No
(Pragmas_After
(Aux
)) then
3747 Set_Pragmas_After
(Aux
, New_List
);
3750 Append
(Aitem
, Pragmas_After
(Aux
));
3757 -- The evaluation of the aspect is delayed to the freezing point.
3758 -- The pragma or attribute clause if there is one is then attached
3759 -- to the aspect specification which is put in the rep item list.
3761 if Delay_Required
then
3762 if Present
(Aitem
) then
3763 Set_Is_Delayed_Aspect
(Aitem
);
3764 Set_Aspect_Rep_Item
(Aspect
, Aitem
);
3765 Set_Parent
(Aitem
, Aspect
);
3768 Set_Is_Delayed_Aspect
(Aspect
);
3770 -- In the case of Default_Value, link the aspect to base type
3771 -- as well, even though it appears on a first subtype. This is
3772 -- mandated by the semantics of the aspect. Do not establish
3773 -- the link when processing the base type itself as this leads
3774 -- to a rep item circularity. Verify that we are dealing with
3775 -- a scalar type to prevent cascaded errors.
3777 if A_Id
= Aspect_Default_Value
3778 and then Is_Scalar_Type
(E
)
3779 and then Base_Type
(E
) /= E
3781 Set_Has_Delayed_Aspects
(Base_Type
(E
));
3782 Record_Rep_Item
(Base_Type
(E
), Aspect
);
3785 Set_Has_Delayed_Aspects
(E
);
3786 Record_Rep_Item
(E
, Aspect
);
3788 -- When delay is not required and the context is a package or a
3789 -- subprogram body, insert the pragma in the body declarations.
3791 elsif Nkind_In
(N
, N_Package_Body
, N_Subprogram_Body
) then
3792 if No
(Declarations
(N
)) then
3793 Set_Declarations
(N
, New_List
);
3796 -- The pragma is added before source declarations
3798 Prepend_To
(Declarations
(N
), Aitem
);
3800 -- When delay is not required and the context is not a compilation
3801 -- unit, we simply insert the pragma/attribute definition clause
3804 elsif Present
(Aitem
) then
3805 Insert_After
(Ins_Node
, Aitem
);
3808 end Analyze_One_Aspect
;
3812 end loop Aspect_Loop
;
3814 if Has_Delayed_Aspects
(E
) then
3815 Ensure_Freeze_Node
(E
);
3817 end Analyze_Aspect_Specifications
;
3819 ---------------------------------------------------
3820 -- Analyze_Aspect_Specifications_On_Body_Or_Stub --
3821 ---------------------------------------------------
3823 procedure Analyze_Aspect_Specifications_On_Body_Or_Stub
(N
: Node_Id
) is
3824 Body_Id
: constant Entity_Id
:= Defining_Entity
(N
);
3826 procedure Diagnose_Misplaced_Aspects
(Spec_Id
: Entity_Id
);
3827 -- Body [stub] N has aspects, but they are not properly placed. Emit an
3828 -- error message depending on the aspects involved. Spec_Id denotes the
3829 -- entity of the corresponding spec.
3831 --------------------------------
3832 -- Diagnose_Misplaced_Aspects --
3833 --------------------------------
3835 procedure Diagnose_Misplaced_Aspects
(Spec_Id
: Entity_Id
) is
3836 procedure Misplaced_Aspect_Error
3839 -- Emit an error message concerning misplaced aspect Asp. Ref_Nam is
3840 -- the name of the refined version of the aspect.
3842 ----------------------------
3843 -- Misplaced_Aspect_Error --
3844 ----------------------------
3846 procedure Misplaced_Aspect_Error
3850 Asp_Nam
: constant Name_Id
:= Chars
(Identifier
(Asp
));
3851 Asp_Id
: constant Aspect_Id
:= Get_Aspect_Id
(Asp_Nam
);
3854 -- The corresponding spec already contains the aspect in question
3855 -- and the one appearing on the body must be the refined form:
3857 -- procedure P with Global ...;
3858 -- procedure P with Global ... is ... end P;
3862 if Has_Aspect
(Spec_Id
, Asp_Id
) then
3863 Error_Msg_Name_1
:= Asp_Nam
;
3865 -- Subunits cannot carry aspects that apply to a subprogram
3868 if Nkind
(Parent
(N
)) = N_Subunit
then
3869 Error_Msg_N
("aspect % cannot apply to a subunit", Asp
);
3871 -- Otherwise suggest the refined form
3874 Error_Msg_Name_2
:= Ref_Nam
;
3875 Error_Msg_N
("aspect % should be %", Asp
);
3878 -- Otherwise the aspect must appear on the spec, not on the body
3881 -- procedure P with Global ... is ... end P;
3885 ("aspect specification must appear on initial declaration",
3888 end Misplaced_Aspect_Error
;
3895 -- Start of processing for Diagnose_Misplaced_Aspects
3898 -- Iterate over the aspect specifications and emit specific errors
3899 -- where applicable.
3901 Asp
:= First
(Aspect_Specifications
(N
));
3902 while Present
(Asp
) loop
3903 Asp_Nam
:= Chars
(Identifier
(Asp
));
3905 -- Do not emit errors on aspects that can appear on a subprogram
3906 -- body. This scenario occurs when the aspect specification list
3907 -- contains both misplaced and properly placed aspects.
3909 if Aspect_On_Body_Or_Stub_OK
(Get_Aspect_Id
(Asp_Nam
)) then
3912 -- Special diagnostics for SPARK aspects
3914 elsif Asp_Nam
= Name_Depends
then
3915 Misplaced_Aspect_Error
(Asp
, Name_Refined_Depends
);
3917 elsif Asp_Nam
= Name_Global
then
3918 Misplaced_Aspect_Error
(Asp
, Name_Refined_Global
);
3920 elsif Asp_Nam
= Name_Post
then
3921 Misplaced_Aspect_Error
(Asp
, Name_Refined_Post
);
3923 -- Otherwise a language-defined aspect is misplaced
3927 ("aspect specification must appear on initial declaration",
3933 end Diagnose_Misplaced_Aspects
;
3937 Spec_Id
: constant Entity_Id
:= Unique_Defining_Entity
(N
);
3939 -- Start of processing for Analyze_Aspects_On_Body_Or_Stub
3942 -- Language-defined aspects cannot be associated with a subprogram body
3943 -- [stub] if the subprogram has a spec. Certain implementation defined
3944 -- aspects are allowed to break this rule (for all applicable cases, see
3945 -- table Aspects.Aspect_On_Body_Or_Stub_OK).
3947 if Spec_Id
/= Body_Id
and then not Aspects_On_Body_Or_Stub_OK
(N
) then
3948 Diagnose_Misplaced_Aspects
(Spec_Id
);
3950 Analyze_Aspect_Specifications
(N
, Body_Id
);
3952 end Analyze_Aspect_Specifications_On_Body_Or_Stub
;
3954 -----------------------
3955 -- Analyze_At_Clause --
3956 -----------------------
3958 -- An at clause is replaced by the corresponding Address attribute
3959 -- definition clause that is the preferred approach in Ada 95.
3961 procedure Analyze_At_Clause
(N
: Node_Id
) is
3962 CS
: constant Boolean := Comes_From_Source
(N
);
3965 -- This is an obsolescent feature
3967 Check_Restriction
(No_Obsolescent_Features
, N
);
3969 if Warn_On_Obsolescent_Feature
then
3971 ("?j?at clause is an obsolescent feature (RM J.7(2))", N
);
3973 ("\?j?use address attribute definition clause instead", N
);
3976 -- Rewrite as address clause
3979 Make_Attribute_Definition_Clause
(Sloc
(N
),
3980 Name
=> Identifier
(N
),
3981 Chars
=> Name_Address
,
3982 Expression
=> Expression
(N
)));
3984 -- We preserve Comes_From_Source, since logically the clause still comes
3985 -- from the source program even though it is changed in form.
3987 Set_Comes_From_Source
(N
, CS
);
3989 -- Analyze rewritten clause
3991 Analyze_Attribute_Definition_Clause
(N
);
3992 end Analyze_At_Clause
;
3994 -----------------------------------------
3995 -- Analyze_Attribute_Definition_Clause --
3996 -----------------------------------------
3998 procedure Analyze_Attribute_Definition_Clause
(N
: Node_Id
) is
3999 Loc
: constant Source_Ptr
:= Sloc
(N
);
4000 Nam
: constant Node_Id
:= Name
(N
);
4001 Attr
: constant Name_Id
:= Chars
(N
);
4002 Expr
: constant Node_Id
:= Expression
(N
);
4003 Id
: constant Attribute_Id
:= Get_Attribute_Id
(Attr
);
4006 -- The entity of Nam after it is analyzed. In the case of an incomplete
4007 -- type, this is the underlying type.
4010 -- The underlying entity to which the attribute applies. Generally this
4011 -- is the Underlying_Type of Ent, except in the case where the clause
4012 -- applies to the full view of an incomplete or private type, in which
4013 -- case U_Ent is just a copy of Ent.
4015 FOnly
: Boolean := False;
4016 -- Reset to True for subtype specific attribute (Alignment, Size)
4017 -- and for stream attributes, i.e. those cases where in the call to
4018 -- Rep_Item_Too_Late, FOnly is set True so that only the freezing rules
4019 -- are checked. Note that the case of stream attributes is not clear
4020 -- from the RM, but see AI95-00137. Also, the RM seems to disallow
4021 -- Storage_Size for derived task types, but that is also clearly
4024 procedure Analyze_Stream_TSS_Definition
(TSS_Nam
: TSS_Name_Type
);
4025 -- Common processing for 'Read, 'Write, 'Input and 'Output attribute
4026 -- definition clauses.
4028 function Duplicate_Clause
return Boolean;
4029 -- This routine checks if the aspect for U_Ent being given by attribute
4030 -- definition clause N is for an aspect that has already been specified,
4031 -- and if so gives an error message. If there is a duplicate, True is
4032 -- returned, otherwise if there is no error, False is returned.
4034 procedure Check_Indexing_Functions
;
4035 -- Check that the function in Constant_Indexing or Variable_Indexing
4036 -- attribute has the proper type structure. If the name is overloaded,
4037 -- check that some interpretation is legal.
4039 procedure Check_Iterator_Functions
;
4040 -- Check that there is a single function in Default_Iterator attribute
4041 -- that has the proper type structure.
4043 function Check_Primitive_Function
(Subp
: Entity_Id
) return Boolean;
4044 -- Common legality check for the previous two
4046 -----------------------------------
4047 -- Analyze_Stream_TSS_Definition --
4048 -----------------------------------
4050 procedure Analyze_Stream_TSS_Definition
(TSS_Nam
: TSS_Name_Type
) is
4051 Subp
: Entity_Id
:= Empty
;
4056 Is_Read
: constant Boolean := (TSS_Nam
= TSS_Stream_Read
);
4057 -- True for Read attribute, False for other attributes
4059 function Has_Good_Profile
4061 Report
: Boolean := False) return Boolean;
4062 -- Return true if the entity is a subprogram with an appropriate
4063 -- profile for the attribute being defined. If result is False and
4064 -- Report is True, function emits appropriate error.
4066 ----------------------
4067 -- Has_Good_Profile --
4068 ----------------------
4070 function Has_Good_Profile
4072 Report
: Boolean := False) return Boolean
4074 Expected_Ekind
: constant array (Boolean) of Entity_Kind
:=
4075 (False => E_Procedure
, True => E_Function
);
4076 Is_Function
: constant Boolean := (TSS_Nam
= TSS_Stream_Input
);
4081 if Ekind
(Subp
) /= Expected_Ekind
(Is_Function
) then
4085 F
:= First_Formal
(Subp
);
4088 or else Ekind
(Etype
(F
)) /= E_Anonymous_Access_Type
4089 or else Designated_Type
(Etype
(F
)) /=
4090 Class_Wide_Type
(RTE
(RE_Root_Stream_Type
))
4095 if not Is_Function
then
4099 Expected_Mode
: constant array (Boolean) of Entity_Kind
:=
4100 (False => E_In_Parameter
,
4101 True => E_Out_Parameter
);
4103 if Parameter_Mode
(F
) /= Expected_Mode
(Is_Read
) then
4110 -- If the attribute specification comes from an aspect
4111 -- specification for a class-wide stream, the parameter must be
4112 -- a class-wide type of the entity to which the aspect applies.
4114 if From_Aspect_Specification
(N
)
4115 and then Class_Present
(Parent
(N
))
4116 and then Is_Class_Wide_Type
(Typ
)
4122 Typ
:= Etype
(Subp
);
4125 -- Verify that the prefix of the attribute and the local name for
4126 -- the type of the formal match, or one is the class-wide of the
4127 -- other, in the case of a class-wide stream operation.
4129 if Base_Type
(Typ
) = Base_Type
(Ent
)
4130 or else (Is_Class_Wide_Type
(Typ
)
4131 and then Typ
= Class_Wide_Type
(Base_Type
(Ent
)))
4132 or else (Is_Class_Wide_Type
(Ent
)
4133 and then Ent
= Class_Wide_Type
(Base_Type
(Typ
)))
4140 if Present
(Next_Formal
(F
)) then
4143 elsif not Is_Scalar_Type
(Typ
)
4144 and then not Is_First_Subtype
(Typ
)
4145 and then not Is_Class_Wide_Type
(Typ
)
4147 if Report
and not Is_First_Subtype
(Typ
) then
4149 ("subtype of formal in stream operation must be a first "
4150 & "subtype", Parameter_Type
(Parent
(F
)));
4158 end Has_Good_Profile
;
4160 -- Start of processing for Analyze_Stream_TSS_Definition
4165 if not Is_Type
(U_Ent
) then
4166 Error_Msg_N
("local name must be a subtype", Nam
);
4169 elsif not Is_First_Subtype
(U_Ent
) then
4170 Error_Msg_N
("local name must be a first subtype", Nam
);
4174 Pnam
:= TSS
(Base_Type
(U_Ent
), TSS_Nam
);
4176 -- If Pnam is present, it can be either inherited from an ancestor
4177 -- type (in which case it is legal to redefine it for this type), or
4178 -- be a previous definition of the attribute for the same type (in
4179 -- which case it is illegal).
4181 -- In the first case, it will have been analyzed already, and we
4182 -- can check that its profile does not match the expected profile
4183 -- for a stream attribute of U_Ent. In the second case, either Pnam
4184 -- has been analyzed (and has the expected profile), or it has not
4185 -- been analyzed yet (case of a type that has not been frozen yet
4186 -- and for which the stream attribute has been set using Set_TSS).
4189 and then (No
(First_Entity
(Pnam
)) or else Has_Good_Profile
(Pnam
))
4191 Error_Msg_Sloc
:= Sloc
(Pnam
);
4192 Error_Msg_Name_1
:= Attr
;
4193 Error_Msg_N
("% attribute already defined #", Nam
);
4199 if Is_Entity_Name
(Expr
) then
4200 if not Is_Overloaded
(Expr
) then
4201 if Has_Good_Profile
(Entity
(Expr
), Report
=> True) then
4202 Subp
:= Entity
(Expr
);
4206 Get_First_Interp
(Expr
, I
, It
);
4207 while Present
(It
.Nam
) loop
4208 if Has_Good_Profile
(It
.Nam
) then
4213 Get_Next_Interp
(I
, It
);
4218 if Present
(Subp
) then
4219 if Is_Abstract_Subprogram
(Subp
) then
4220 Error_Msg_N
("stream subprogram must not be abstract", Expr
);
4223 -- A stream subprogram for an interface type must be a null
4224 -- procedure (RM 13.13.2 (38/3)). Note that the class-wide type
4225 -- of an interface is not an interface type (3.9.4 (6.b/2)).
4227 elsif Is_Interface
(U_Ent
)
4228 and then not Is_Class_Wide_Type
(U_Ent
)
4229 and then not Inside_A_Generic
4231 (Ekind
(Subp
) = E_Function
4235 (Unit_Declaration_Node
(Ultimate_Alias
(Subp
)))))
4238 ("stream subprogram for interface type must be null "
4239 & "procedure", Expr
);
4242 Set_Entity
(Expr
, Subp
);
4243 Set_Etype
(Expr
, Etype
(Subp
));
4245 New_Stream_Subprogram
(N
, U_Ent
, Subp
, TSS_Nam
);
4248 Error_Msg_Name_1
:= Attr
;
4249 Error_Msg_N
("incorrect expression for% attribute", Expr
);
4251 end Analyze_Stream_TSS_Definition
;
4253 ------------------------------
4254 -- Check_Indexing_Functions --
4255 ------------------------------
4257 procedure Check_Indexing_Functions
is
4258 Indexing_Found
: Boolean := False;
4260 procedure Check_Inherited_Indexing
;
4261 -- For a derived type, check that no indexing aspect is specified
4262 -- for the type if it is also inherited
4264 procedure Check_One_Function
(Subp
: Entity_Id
);
4265 -- Check one possible interpretation. Sets Indexing_Found True if a
4266 -- legal indexing function is found.
4268 procedure Illegal_Indexing
(Msg
: String);
4269 -- Diagnose illegal indexing function if not overloaded. In the
4270 -- overloaded case indicate that no legal interpretation exists.
4272 ------------------------------
4273 -- Check_Inherited_Indexing --
4274 ------------------------------
4276 procedure Check_Inherited_Indexing
is
4277 Inherited
: Node_Id
;
4280 if Attr
= Name_Constant_Indexing
then
4282 Find_Aspect
(Etype
(Ent
), Aspect_Constant_Indexing
);
4283 else pragma Assert
(Attr
= Name_Variable_Indexing
);
4285 Find_Aspect
(Etype
(Ent
), Aspect_Variable_Indexing
);
4288 if Present
(Inherited
) then
4289 if Debug_Flag_Dot_XX
then
4292 -- OK if current attribute_definition_clause is expansion of
4293 -- inherited aspect.
4295 elsif Aspect_Rep_Item
(Inherited
) = N
then
4298 -- Indicate the operation that must be overridden, rather than
4299 -- redefining the indexing aspect.
4303 ("indexing function already inherited from parent type");
4305 ("!override & instead",
4306 N
, Entity
(Expression
(Inherited
)));
4309 end Check_Inherited_Indexing
;
4311 ------------------------
4312 -- Check_One_Function --
4313 ------------------------
4315 procedure Check_One_Function
(Subp
: Entity_Id
) is
4316 Default_Element
: Node_Id
;
4317 Ret_Type
: constant Entity_Id
:= Etype
(Subp
);
4320 if not Is_Overloadable
(Subp
) then
4321 Illegal_Indexing
("illegal indexing function for type&");
4324 elsif Scope
(Subp
) /= Scope
(Ent
) then
4325 if Nkind
(Expr
) = N_Expanded_Name
then
4327 -- Indexing function can't be declared elsewhere
4330 ("indexing function must be declared in scope of type&");
4335 elsif No
(First_Formal
(Subp
)) then
4337 ("Indexing requires a function that applies to type&");
4340 elsif No
(Next_Formal
(First_Formal
(Subp
))) then
4342 ("indexing function must have at least two parameters");
4345 elsif Is_Derived_Type
(Ent
) then
4346 Check_Inherited_Indexing
;
4349 if not Check_Primitive_Function
(Subp
) then
4351 ("Indexing aspect requires a function that applies to type&");
4355 -- If partial declaration exists, verify that it is not tagged.
4357 if Ekind
(Current_Scope
) = E_Package
4358 and then Has_Private_Declaration
(Ent
)
4359 and then From_Aspect_Specification
(N
)
4361 List_Containing
(Parent
(Ent
)) =
4362 Private_Declarations
4363 (Specification
(Unit_Declaration_Node
(Current_Scope
)))
4364 and then Nkind
(N
) = N_Attribute_Definition_Clause
4371 First
(Visible_Declarations
4373 (Unit_Declaration_Node
(Current_Scope
))));
4375 while Present
(Decl
) loop
4376 if Nkind
(Decl
) = N_Private_Type_Declaration
4377 and then Ent
= Full_View
(Defining_Identifier
(Decl
))
4378 and then Tagged_Present
(Decl
)
4379 and then No
(Aspect_Specifications
(Decl
))
4382 ("Indexing aspect cannot be specified on full view "
4383 & "if partial view is tagged");
4392 -- An indexing function must return either the default element of
4393 -- the container, or a reference type. For variable indexing it
4394 -- must be the latter.
4397 Find_Value_Of_Aspect
4398 (Etype
(First_Formal
(Subp
)), Aspect_Iterator_Element
);
4400 if Present
(Default_Element
) then
4401 Analyze
(Default_Element
);
4403 if Is_Entity_Name
(Default_Element
)
4404 and then not Covers
(Entity
(Default_Element
), Ret_Type
)
4408 ("wrong return type for indexing function");
4413 -- For variable_indexing the return type must be a reference type
4415 if Attr
= Name_Variable_Indexing
then
4416 if not Has_Implicit_Dereference
(Ret_Type
) then
4418 ("variable indexing must return a reference type");
4421 elsif Is_Access_Constant
4422 (Etype
(First_Discriminant
(Ret_Type
)))
4425 ("variable indexing must return an access to variable");
4430 if Has_Implicit_Dereference
(Ret_Type
)
4432 Is_Access_Constant
(Etype
(First_Discriminant
(Ret_Type
)))
4435 ("constant indexing must return an access to constant");
4438 elsif Is_Access_Type
(Etype
(First_Formal
(Subp
)))
4439 and then not Is_Access_Constant
(Etype
(First_Formal
(Subp
)))
4442 ("constant indexing must apply to an access to constant");
4447 -- All checks succeeded.
4449 Indexing_Found
:= True;
4450 end Check_One_Function
;
4452 -----------------------
4453 -- Illegal_Indexing --
4454 -----------------------
4456 procedure Illegal_Indexing
(Msg
: String) is
4458 Error_Msg_NE
(Msg
, N
, Ent
);
4459 end Illegal_Indexing
;
4461 -- Start of processing for Check_Indexing_Functions
4465 Check_Inherited_Indexing
;
4470 if not Is_Overloaded
(Expr
) then
4471 Check_One_Function
(Entity
(Expr
));
4479 Indexing_Found
:= False;
4480 Get_First_Interp
(Expr
, I
, It
);
4481 while Present
(It
.Nam
) loop
4483 -- Note that analysis will have added the interpretation
4484 -- that corresponds to the dereference. We only check the
4485 -- subprogram itself. Ignore homonyms that may come from
4486 -- derived types in the context.
4488 if Is_Overloadable
(It
.Nam
)
4489 and then Comes_From_Source
(It
.Nam
)
4491 Check_One_Function
(It
.Nam
);
4494 Get_Next_Interp
(I
, It
);
4499 if not Indexing_Found
and then not Error_Posted
(N
) then
4501 ("aspect Indexing requires a local function that applies to "
4502 & "type&", Expr
, Ent
);
4504 end Check_Indexing_Functions
;
4506 ------------------------------
4507 -- Check_Iterator_Functions --
4508 ------------------------------
4510 procedure Check_Iterator_Functions
is
4511 function Valid_Default_Iterator
(Subp
: Entity_Id
) return Boolean;
4512 -- Check one possible interpretation for validity
4514 ----------------------------
4515 -- Valid_Default_Iterator --
4516 ----------------------------
4518 function Valid_Default_Iterator
(Subp
: Entity_Id
) return Boolean is
4519 Root_T
: constant Entity_Id
:= Root_Type
(Etype
(Etype
(Subp
)));
4523 if not Check_Primitive_Function
(Subp
) then
4526 -- The return type must be derived from a type in an instance
4527 -- of Iterator.Interfaces, and thus its root type must have a
4530 elsif Chars
(Root_T
) /= Name_Forward_Iterator
4531 and then Chars
(Root_T
) /= Name_Reversible_Iterator
4536 Formal
:= First_Formal
(Subp
);
4539 -- False if any subsequent formal has no default expression
4541 Formal
:= Next_Formal
(Formal
);
4542 while Present
(Formal
) loop
4543 if No
(Expression
(Parent
(Formal
))) then
4547 Next_Formal
(Formal
);
4550 -- True if all subsequent formals have default expressions
4553 end Valid_Default_Iterator
;
4555 -- Start of processing for Check_Iterator_Functions
4560 if not Is_Entity_Name
(Expr
) then
4561 Error_Msg_N
("aspect Iterator must be a function name", Expr
);
4564 if not Is_Overloaded
(Expr
) then
4565 if not Check_Primitive_Function
(Entity
(Expr
)) then
4567 ("aspect Indexing requires a function that applies to type&",
4568 Entity
(Expr
), Ent
);
4571 -- Flag the default_iterator as well as the denoted function.
4573 if not Valid_Default_Iterator
(Entity
(Expr
)) then
4574 Error_Msg_N
("improper function for default iterator!", Expr
);
4579 Default
: Entity_Id
:= Empty
;
4584 Get_First_Interp
(Expr
, I
, It
);
4585 while Present
(It
.Nam
) loop
4586 if not Check_Primitive_Function
(It
.Nam
)
4587 or else not Valid_Default_Iterator
(It
.Nam
)
4591 elsif Present
(Default
) then
4593 -- An explicit one should override an implicit one
4595 if Comes_From_Source
(Default
) =
4596 Comes_From_Source
(It
.Nam
)
4598 Error_Msg_N
("default iterator must be unique", Expr
);
4599 Error_Msg_Sloc
:= Sloc
(Default
);
4600 Error_Msg_N
("\\possible interpretation#", Expr
);
4601 Error_Msg_Sloc
:= Sloc
(It
.Nam
);
4602 Error_Msg_N
("\\possible interpretation#", Expr
);
4604 elsif Comes_From_Source
(It
.Nam
) then
4611 Get_Next_Interp
(I
, It
);
4614 if Present
(Default
) then
4615 Set_Entity
(Expr
, Default
);
4616 Set_Is_Overloaded
(Expr
, False);
4619 ("no interpretation is a valid default iterator!", Expr
);
4623 end Check_Iterator_Functions
;
4625 -------------------------------
4626 -- Check_Primitive_Function --
4627 -------------------------------
4629 function Check_Primitive_Function
(Subp
: Entity_Id
) return Boolean is
4633 if Ekind
(Subp
) /= E_Function
then
4637 if No
(First_Formal
(Subp
)) then
4640 Ctrl
:= Etype
(First_Formal
(Subp
));
4643 -- To be a primitive operation subprogram has to be in same scope.
4645 if Scope
(Ctrl
) /= Scope
(Subp
) then
4649 -- Type of formal may be the class-wide type, an access to such,
4650 -- or an incomplete view.
4653 or else Ctrl
= Class_Wide_Type
(Ent
)
4655 (Ekind
(Ctrl
) = E_Anonymous_Access_Type
4656 and then (Designated_Type
(Ctrl
) = Ent
4658 Designated_Type
(Ctrl
) = Class_Wide_Type
(Ent
)))
4660 (Ekind
(Ctrl
) = E_Incomplete_Type
4661 and then Full_View
(Ctrl
) = Ent
)
4669 end Check_Primitive_Function
;
4671 ----------------------
4672 -- Duplicate_Clause --
4673 ----------------------
4675 function Duplicate_Clause
return Boolean is
4679 -- Nothing to do if this attribute definition clause comes from
4680 -- an aspect specification, since we could not be duplicating an
4681 -- explicit clause, and we dealt with the case of duplicated aspects
4682 -- in Analyze_Aspect_Specifications.
4684 if From_Aspect_Specification
(N
) then
4688 -- Otherwise current clause may duplicate previous clause, or a
4689 -- previously given pragma or aspect specification for the same
4692 A
:= Get_Rep_Item
(U_Ent
, Chars
(N
), Check_Parents
=> False);
4695 Error_Msg_Name_1
:= Chars
(N
);
4696 Error_Msg_Sloc
:= Sloc
(A
);
4698 Error_Msg_NE
("aspect% for & previously given#", N
, U_Ent
);
4703 end Duplicate_Clause
;
4705 -- Start of processing for Analyze_Attribute_Definition_Clause
4708 -- The following code is a defense against recursion. Not clear that
4709 -- this can happen legitimately, but perhaps some error situations can
4710 -- cause it, and we did see this recursion during testing.
4712 if Analyzed
(N
) then
4715 Set_Analyzed
(N
, True);
4718 Check_Restriction_No_Use_Of_Attribute
(N
);
4720 -- Ignore some selected attributes in CodePeer mode since they are not
4721 -- relevant in this context.
4723 if CodePeer_Mode
then
4726 -- Ignore Component_Size in CodePeer mode, to avoid changing the
4727 -- internal representation of types by implicitly packing them.
4729 when Attribute_Component_Size
=>
4730 Rewrite
(N
, Make_Null_Statement
(Sloc
(N
)));
4738 -- Process Ignore_Rep_Clauses option
4740 if Ignore_Rep_Clauses
then
4743 -- The following should be ignored. They do not affect legality
4744 -- and may be target dependent. The basic idea of -gnatI is to
4745 -- ignore any rep clauses that may be target dependent but do not
4746 -- affect legality (except possibly to be rejected because they
4747 -- are incompatible with the compilation target).
4749 when Attribute_Alignment
4750 | Attribute_Bit_Order
4751 | Attribute_Component_Size
4752 | Attribute_Default_Scalar_Storage_Order
4753 | Attribute_Machine_Radix
4754 | Attribute_Object_Size
4755 | Attribute_Scalar_Storage_Order
4758 | Attribute_Stream_Size
4759 | Attribute_Value_Size
4761 Kill_Rep_Clause
(N
);
4764 -- The following should not be ignored, because in the first place
4765 -- they are reasonably portable, and should not cause problems
4766 -- in compiling code from another target, and also they do affect
4767 -- legality, e.g. failing to provide a stream attribute for a type
4768 -- may make a program illegal.
4770 when Attribute_External_Tag
4774 | Attribute_Simple_Storage_Pool
4775 | Attribute_Storage_Pool
4776 | Attribute_Storage_Size
4781 -- We do not do anything here with address clauses, they will be
4782 -- removed by Freeze later on, but for now, it works better to
4783 -- keep them in the tree.
4785 when Attribute_Address
=>
4788 -- Other cases are errors ("attribute& cannot be set with
4789 -- definition clause"), which will be caught below.
4797 Ent
:= Entity
(Nam
);
4799 if Rep_Item_Too_Early
(Ent
, N
) then
4803 -- Rep clause applies to full view of incomplete type or private type if
4804 -- we have one (if not, this is a premature use of the type). However,
4805 -- certain semantic checks need to be done on the specified entity (i.e.
4806 -- the private view), so we save it in Ent.
4808 if Is_Private_Type
(Ent
)
4809 and then Is_Derived_Type
(Ent
)
4810 and then not Is_Tagged_Type
(Ent
)
4811 and then No
(Full_View
(Ent
))
4813 -- If this is a private type whose completion is a derivation from
4814 -- another private type, there is no full view, and the attribute
4815 -- belongs to the type itself, not its underlying parent.
4819 elsif Ekind
(Ent
) = E_Incomplete_Type
then
4821 -- The attribute applies to the full view, set the entity of the
4822 -- attribute definition accordingly.
4824 Ent
:= Underlying_Type
(Ent
);
4826 Set_Entity
(Nam
, Ent
);
4829 U_Ent
:= Underlying_Type
(Ent
);
4832 -- Avoid cascaded error
4834 if Etype
(Nam
) = Any_Type
then
4837 -- Must be declared in current scope or in case of an aspect
4838 -- specification, must be visible in current scope.
4840 elsif Scope
(Ent
) /= Current_Scope
4842 not (From_Aspect_Specification
(N
)
4843 and then Scope_Within_Or_Same
(Current_Scope
, Scope
(Ent
)))
4845 Error_Msg_N
("entity must be declared in this scope", Nam
);
4848 -- Must not be a source renaming (we do have some cases where the
4849 -- expander generates a renaming, and those cases are OK, in such
4850 -- cases any attribute applies to the renamed object as well).
4852 elsif Is_Object
(Ent
)
4853 and then Present
(Renamed_Object
(Ent
))
4855 -- Case of renamed object from source, this is an error
4857 if Comes_From_Source
(Renamed_Object
(Ent
)) then
4858 Get_Name_String
(Chars
(N
));
4859 Error_Msg_Strlen
:= Name_Len
;
4860 Error_Msg_String
(1 .. Name_Len
) := Name_Buffer
(1 .. Name_Len
);
4862 ("~ clause not allowed for a renaming declaration "
4863 & "(RM 13.1(6))", Nam
);
4866 -- For the case of a compiler generated renaming, the attribute
4867 -- definition clause applies to the renamed object created by the
4868 -- expander. The easiest general way to handle this is to create a
4869 -- copy of the attribute definition clause for this object.
4871 elsif Is_Entity_Name
(Renamed_Object
(Ent
)) then
4873 Make_Attribute_Definition_Clause
(Loc
,
4875 New_Occurrence_Of
(Entity
(Renamed_Object
(Ent
)), Loc
),
4877 Expression
=> Duplicate_Subexpr
(Expression
(N
))));
4879 -- If the renamed object is not an entity, it must be a dereference
4880 -- of an unconstrained function call, and we must introduce a new
4881 -- declaration to capture the expression. This is needed in the case
4882 -- of 'Alignment, where the original declaration must be rewritten.
4886 (Nkind
(Renamed_Object
(Ent
)) = N_Explicit_Dereference
);
4890 -- If no underlying entity, use entity itself, applies to some
4891 -- previously detected error cases ???
4893 elsif No
(U_Ent
) then
4896 -- Cannot specify for a subtype (exception Object/Value_Size)
4898 elsif Is_Type
(U_Ent
)
4899 and then not Is_First_Subtype
(U_Ent
)
4900 and then Id
/= Attribute_Object_Size
4901 and then Id
/= Attribute_Value_Size
4902 and then not From_At_Mod
(N
)
4904 Error_Msg_N
("cannot specify attribute for subtype", Nam
);
4908 Set_Entity
(N
, U_Ent
);
4910 -- Switch on particular attribute
4918 -- Address attribute definition clause
4920 when Attribute_Address
=> Address
: begin
4922 -- A little error check, catch for X'Address use X'Address;
4924 if Nkind
(Nam
) = N_Identifier
4925 and then Nkind
(Expr
) = N_Attribute_Reference
4926 and then Attribute_Name
(Expr
) = Name_Address
4927 and then Nkind
(Prefix
(Expr
)) = N_Identifier
4928 and then Chars
(Nam
) = Chars
(Prefix
(Expr
))
4931 ("address for & is self-referencing", Prefix
(Expr
), Ent
);
4935 -- Not that special case, carry on with analysis of expression
4937 Analyze_And_Resolve
(Expr
, RTE
(RE_Address
));
4939 -- Even when ignoring rep clauses we need to indicate that the
4940 -- entity has an address clause and thus it is legal to declare
4941 -- it imported. Freeze will get rid of the address clause later.
4942 -- Also call Set_Address_Taken to indicate that an address clause
4943 -- was present, even if we are about to remove it.
4945 if Ignore_Rep_Clauses
then
4946 Set_Address_Taken
(U_Ent
);
4948 if Ekind_In
(U_Ent
, E_Variable
, E_Constant
) then
4949 Record_Rep_Item
(U_Ent
, N
);
4955 if Duplicate_Clause
then
4958 -- Case of address clause for subprogram
4960 elsif Is_Subprogram
(U_Ent
) then
4961 if Has_Homonym
(U_Ent
) then
4963 ("address clause cannot be given for overloaded "
4964 & "subprogram", Nam
);
4968 -- For subprograms, all address clauses are permitted, and we
4969 -- mark the subprogram as having a deferred freeze so that Gigi
4970 -- will not elaborate it too soon.
4972 -- Above needs more comments, what is too soon about???
4974 Set_Has_Delayed_Freeze
(U_Ent
);
4976 -- Case of address clause for entry
4978 elsif Ekind
(U_Ent
) = E_Entry
then
4979 if Nkind
(Parent
(N
)) = N_Task_Body
then
4981 ("entry address must be specified in task spec", Nam
);
4985 -- For entries, we require a constant address
4987 Check_Constant_Address_Clause
(Expr
, U_Ent
);
4989 -- Special checks for task types
4991 if Is_Task_Type
(Scope
(U_Ent
))
4992 and then Comes_From_Source
(Scope
(U_Ent
))
4995 ("??entry address declared for entry in task type", N
);
4997 ("\??only one task can be declared of this type", N
);
5000 -- Entry address clauses are obsolescent
5002 Check_Restriction
(No_Obsolescent_Features
, N
);
5004 if Warn_On_Obsolescent_Feature
then
5006 ("?j?attaching interrupt to task entry is an obsolescent "
5007 & "feature (RM J.7.1)", N
);
5009 ("\?j?use interrupt procedure instead", N
);
5012 -- Case of an address clause for a class-wide object, which is
5013 -- considered erroneous.
5015 elsif Is_Class_Wide_Type
(Etype
(U_Ent
)) then
5017 ("??class-wide object & must not be overlaid", Nam
, U_Ent
);
5019 ("\??Program_Error will be raised at run time", Nam
);
5020 Insert_Action
(Declaration_Node
(U_Ent
),
5021 Make_Raise_Program_Error
(Loc
,
5022 Reason
=> PE_Overlaid_Controlled_Object
));
5025 -- Case of address clause for an object
5027 elsif Ekind_In
(U_Ent
, E_Constant
, E_Variable
) then
5029 Expr
: constant Node_Id
:= Expression
(N
);
5034 -- Exported variables cannot have an address clause, because
5035 -- this cancels the effect of the pragma Export.
5037 if Is_Exported
(U_Ent
) then
5039 ("cannot export object with address clause", Nam
);
5043 Find_Overlaid_Entity
(N
, O_Ent
, Off
);
5045 if Present
(O_Ent
) then
5047 -- If the object overlays a constant object, mark it so
5049 if Is_Constant_Object
(O_Ent
) then
5050 Set_Overlays_Constant
(U_Ent
);
5053 -- If the address clause is of the form:
5055 -- for X'Address use Y'Address;
5059 -- C : constant Address := Y'Address;
5061 -- for X'Address use C;
5063 -- then we make an entry in the table to check the size
5064 -- and alignment of the overlaying variable. But we defer
5065 -- this check till after code generation to take full
5066 -- advantage of the annotation done by the back end.
5068 -- If the entity has a generic type, the check will be
5069 -- performed in the instance if the actual type justifies
5070 -- it, and we do not insert the clause in the table to
5071 -- prevent spurious warnings.
5073 -- Note: we used to test Comes_From_Source and only give
5074 -- this warning for source entities, but we have removed
5075 -- this test. It really seems bogus to generate overlays
5076 -- that would trigger this warning in generated code.
5077 -- Furthermore, by removing the test, we handle the
5078 -- aspect case properly.
5080 if Is_Object
(O_Ent
)
5081 and then not Is_Generic_Type
(Etype
(U_Ent
))
5082 and then Address_Clause_Overlay_Warnings
5084 Register_Address_Clause_Check
5085 (N
, U_Ent
, No_Uint
, O_Ent
, Off
);
5088 -- If the overlay changes the storage order, mark the
5089 -- entity as being volatile to block any optimization
5090 -- for it since the construct is not really supported
5093 if (Is_Record_Type
(Etype
(U_Ent
))
5094 or else Is_Array_Type
(Etype
(U_Ent
)))
5095 and then (Is_Record_Type
(Etype
(O_Ent
))
5096 or else Is_Array_Type
(Etype
(O_Ent
)))
5097 and then Reverse_Storage_Order
(Etype
(U_Ent
)) /=
5098 Reverse_Storage_Order
(Etype
(O_Ent
))
5100 Set_Treat_As_Volatile
(U_Ent
);
5104 -- If this is not an overlay, mark a variable as being
5105 -- volatile to prevent unwanted optimizations. It's a
5106 -- conservative interpretation of RM 13.3(19) for the
5107 -- cases where the compiler cannot detect potential
5108 -- aliasing issues easily and it also covers the case
5109 -- of an absolute address where the volatile aspect is
5110 -- kind of implicit.
5112 if Ekind
(U_Ent
) = E_Variable
then
5113 Set_Treat_As_Volatile
(U_Ent
);
5116 -- Make an entry in the table for an absolute address as
5117 -- above to check that the value is compatible with the
5118 -- alignment of the object.
5121 Addr
: constant Node_Id
:= Address_Value
(Expr
);
5123 if Compile_Time_Known_Value
(Addr
)
5124 and then Address_Clause_Overlay_Warnings
5126 Register_Address_Clause_Check
5127 (N
, U_Ent
, Expr_Value
(Addr
), Empty
, False);
5132 -- Issue an unconditional warning for a constant overlaying
5133 -- a variable. For the reverse case, we will issue it only
5134 -- if the variable is modified.
5136 if Ekind
(U_Ent
) = E_Constant
5137 and then Present
(O_Ent
)
5138 and then not Overlays_Constant
(U_Ent
)
5139 and then Address_Clause_Overlay_Warnings
5141 Error_Msg_N
("??constant overlays a variable", Expr
);
5143 -- Imported variables can have an address clause, but then
5144 -- the import is pretty meaningless except to suppress
5145 -- initializations, so we do not need such variables to
5146 -- be statically allocated (and in fact it causes trouble
5147 -- if the address clause is a local value).
5149 elsif Is_Imported
(U_Ent
) then
5150 Set_Is_Statically_Allocated
(U_Ent
, False);
5153 -- We mark a possible modification of a variable with an
5154 -- address clause, since it is likely aliasing is occurring.
5156 Note_Possible_Modification
(Nam
, Sure
=> False);
5158 -- Legality checks on the address clause for initialized
5159 -- objects is deferred until the freeze point, because
5160 -- a subsequent pragma might indicate that the object
5161 -- is imported and thus not initialized. Also, the address
5162 -- clause might involve entities that have yet to be
5165 Set_Has_Delayed_Freeze
(U_Ent
);
5167 -- If an initialization call has been generated for this
5168 -- object, it needs to be deferred to after the freeze node
5169 -- we have just now added, otherwise GIGI will see a
5170 -- reference to the variable (as actual to the IP call)
5171 -- before its definition.
5174 Init_Call
: constant Node_Id
:=
5175 Remove_Init_Call
(U_Ent
, N
);
5178 if Present
(Init_Call
) then
5179 Append_Freeze_Action
(U_Ent
, Init_Call
);
5181 -- Reset Initialization_Statements pointer so that
5182 -- if there is a pragma Import further down, it can
5183 -- clear any default initialization.
5185 Set_Initialization_Statements
(U_Ent
, Init_Call
);
5189 -- Entity has delayed freeze, so we will generate an
5190 -- alignment check at the freeze point unless suppressed.
5192 if not Range_Checks_Suppressed
(U_Ent
)
5193 and then not Alignment_Checks_Suppressed
(U_Ent
)
5195 Set_Check_Address_Alignment
(N
);
5198 -- Kill the size check code, since we are not allocating
5199 -- the variable, it is somewhere else.
5201 Kill_Size_Check_Code
(U_Ent
);
5204 -- Not a valid entity for an address clause
5207 Error_Msg_N
("address cannot be given for &", Nam
);
5215 -- Alignment attribute definition clause
5217 when Attribute_Alignment
=> Alignment
: declare
5218 Align
: constant Uint
:= Get_Alignment_Value
(Expr
);
5219 Max_Align
: constant Uint
:= UI_From_Int
(Maximum_Alignment
);
5224 if not Is_Type
(U_Ent
)
5225 and then Ekind
(U_Ent
) /= E_Variable
5226 and then Ekind
(U_Ent
) /= E_Constant
5228 Error_Msg_N
("alignment cannot be given for &", Nam
);
5230 elsif Duplicate_Clause
then
5233 elsif Align
/= No_Uint
then
5234 Set_Has_Alignment_Clause
(U_Ent
);
5236 -- Tagged type case, check for attempt to set alignment to a
5237 -- value greater than Max_Align, and reset if so. This error
5238 -- is suppressed in ASIS mode to allow for different ASIS
5239 -- back ends or ASIS-based tools to query the illegal clause.
5241 if Is_Tagged_Type
(U_Ent
)
5242 and then Align
> Max_Align
5243 and then not ASIS_Mode
5246 ("alignment for & set to Maximum_Aligment??", Nam
);
5247 Set_Alignment
(U_Ent
, Max_Align
);
5252 Set_Alignment
(U_Ent
, Align
);
5255 -- For an array type, U_Ent is the first subtype. In that case,
5256 -- also set the alignment of the anonymous base type so that
5257 -- other subtypes (such as the itypes for aggregates of the
5258 -- type) also receive the expected alignment.
5260 if Is_Array_Type
(U_Ent
) then
5261 Set_Alignment
(Base_Type
(U_Ent
), Align
);
5270 -- Bit_Order attribute definition clause
5272 when Attribute_Bit_Order
=>
5273 if not Is_Record_Type
(U_Ent
) then
5275 ("Bit_Order can only be defined for record type", Nam
);
5277 elsif Duplicate_Clause
then
5281 Analyze_And_Resolve
(Expr
, RTE
(RE_Bit_Order
));
5283 if Etype
(Expr
) = Any_Type
then
5286 elsif not Is_OK_Static_Expression
(Expr
) then
5287 Flag_Non_Static_Expr
5288 ("Bit_Order requires static expression!", Expr
);
5291 if (Expr_Value
(Expr
) = 0) /= Bytes_Big_Endian
then
5292 Set_Reverse_Bit_Order
(Base_Type
(U_Ent
), True);
5297 --------------------
5298 -- Component_Size --
5299 --------------------
5301 -- Component_Size attribute definition clause
5303 when Attribute_Component_Size
=> Component_Size_Case
: declare
5304 Csize
: constant Uint
:= Static_Integer
(Expr
);
5308 New_Ctyp
: Entity_Id
;
5312 if not Is_Array_Type
(U_Ent
) then
5313 Error_Msg_N
("component size requires array type", Nam
);
5317 Btype
:= Base_Type
(U_Ent
);
5318 Ctyp
:= Component_Type
(Btype
);
5320 if Duplicate_Clause
then
5323 elsif Rep_Item_Too_Early
(Btype
, N
) then
5326 elsif Csize
/= No_Uint
then
5327 Check_Size
(Expr
, Ctyp
, Csize
, Biased
);
5329 -- For the biased case, build a declaration for a subtype that
5330 -- will be used to represent the biased subtype that reflects
5331 -- the biased representation of components. We need the subtype
5332 -- to get proper conversions on referencing elements of the
5337 Make_Defining_Identifier
(Loc
,
5339 New_External_Name
(Chars
(U_Ent
), 'C', 0, 'T'));
5342 Make_Subtype_Declaration
(Loc
,
5343 Defining_Identifier
=> New_Ctyp
,
5344 Subtype_Indication
=>
5345 New_Occurrence_Of
(Component_Type
(Btype
), Loc
));
5347 Set_Parent
(Decl
, N
);
5348 Analyze
(Decl
, Suppress
=> All_Checks
);
5350 Set_Has_Delayed_Freeze
(New_Ctyp
, False);
5351 Set_Esize
(New_Ctyp
, Csize
);
5352 Set_RM_Size
(New_Ctyp
, Csize
);
5353 Init_Alignment
(New_Ctyp
);
5354 Set_Is_Itype
(New_Ctyp
, True);
5355 Set_Associated_Node_For_Itype
(New_Ctyp
, U_Ent
);
5357 Set_Component_Type
(Btype
, New_Ctyp
);
5358 Set_Biased
(New_Ctyp
, N
, "component size clause");
5361 Set_Component_Size
(Btype
, Csize
);
5363 -- Deal with warning on overridden size
5365 if Warn_On_Overridden_Size
5366 and then Has_Size_Clause
(Ctyp
)
5367 and then RM_Size
(Ctyp
) /= Csize
5370 ("component size overrides size clause for&?S?", N
, Ctyp
);
5373 Set_Has_Component_Size_Clause
(Btype
, True);
5374 Set_Has_Non_Standard_Rep
(Btype
, True);
5376 end Component_Size_Case
;
5378 -----------------------
5379 -- Constant_Indexing --
5380 -----------------------
5382 when Attribute_Constant_Indexing
=>
5383 Check_Indexing_Functions
;
5389 when Attribute_CPU
=>
5391 -- CPU attribute definition clause not allowed except from aspect
5394 if From_Aspect_Specification
(N
) then
5395 if not Is_Task_Type
(U_Ent
) then
5396 Error_Msg_N
("CPU can only be defined for task", Nam
);
5398 elsif Duplicate_Clause
then
5402 -- The expression must be analyzed in the special manner
5403 -- described in "Handling of Default and Per-Object
5404 -- Expressions" in sem.ads.
5406 -- The visibility to the discriminants must be restored
5408 Push_Scope_And_Install_Discriminants
(U_Ent
);
5409 Preanalyze_Spec_Expression
(Expr
, RTE
(RE_CPU_Range
));
5410 Uninstall_Discriminants_And_Pop_Scope
(U_Ent
);
5412 if not Is_OK_Static_Expression
(Expr
) then
5413 Check_Restriction
(Static_Priorities
, Expr
);
5419 ("attribute& cannot be set with definition clause", N
);
5422 ----------------------
5423 -- Default_Iterator --
5424 ----------------------
5426 when Attribute_Default_Iterator
=> Default_Iterator
: declare
5431 -- If target type is untagged, further checks are irrelevant
5433 if not Is_Tagged_Type
(U_Ent
) then
5435 ("aspect Default_Iterator applies to tagged type", Nam
);
5439 Check_Iterator_Functions
;
5443 if not Is_Entity_Name
(Expr
)
5444 or else Ekind
(Entity
(Expr
)) /= E_Function
5446 Error_Msg_N
("aspect Iterator must be a function", Expr
);
5449 Func
:= Entity
(Expr
);
5452 -- The type of the first parameter must be T, T'class, or a
5453 -- corresponding access type (5.5.1 (8/3). If function is
5454 -- parameterless label type accordingly.
5456 if No
(First_Formal
(Func
)) then
5459 Typ
:= Etype
(First_Formal
(Func
));
5463 or else Typ
= Class_Wide_Type
(U_Ent
)
5464 or else (Is_Access_Type
(Typ
)
5465 and then Designated_Type
(Typ
) = U_Ent
)
5466 or else (Is_Access_Type
(Typ
)
5467 and then Designated_Type
(Typ
) =
5468 Class_Wide_Type
(U_Ent
))
5474 ("Default Iterator must be a primitive of&", Func
, U_Ent
);
5476 end Default_Iterator
;
5478 ------------------------
5479 -- Dispatching_Domain --
5480 ------------------------
5482 when Attribute_Dispatching_Domain
=>
5484 -- Dispatching_Domain attribute definition clause not allowed
5485 -- except from aspect specification.
5487 if From_Aspect_Specification
(N
) then
5488 if not Is_Task_Type
(U_Ent
) then
5490 ("Dispatching_Domain can only be defined for task", Nam
);
5492 elsif Duplicate_Clause
then
5496 -- The expression must be analyzed in the special manner
5497 -- described in "Handling of Default and Per-Object
5498 -- Expressions" in sem.ads.
5500 -- The visibility to the discriminants must be restored
5502 Push_Scope_And_Install_Discriminants
(U_Ent
);
5504 Preanalyze_Spec_Expression
5505 (Expr
, RTE
(RE_Dispatching_Domain
));
5507 Uninstall_Discriminants_And_Pop_Scope
(U_Ent
);
5512 ("attribute& cannot be set with definition clause", N
);
5519 when Attribute_External_Tag
=>
5520 if not Is_Tagged_Type
(U_Ent
) then
5521 Error_Msg_N
("should be a tagged type", Nam
);
5524 if Duplicate_Clause
then
5528 Analyze_And_Resolve
(Expr
, Standard_String
);
5530 if not Is_OK_Static_Expression
(Expr
) then
5531 Flag_Non_Static_Expr
5532 ("static string required for tag name!", Nam
);
5535 if not Is_Library_Level_Entity
(U_Ent
) then
5537 ("??non-unique external tag supplied for &", N
, U_Ent
);
5539 ("\??same external tag applies to all subprogram calls",
5542 ("\??corresponding internal tag cannot be obtained", N
);
5546 --------------------------
5547 -- Implicit_Dereference --
5548 --------------------------
5550 when Attribute_Implicit_Dereference
=>
5552 -- Legality checks already performed at the point of the type
5553 -- declaration, aspect is not delayed.
5561 when Attribute_Input
=>
5562 Analyze_Stream_TSS_Definition
(TSS_Stream_Input
);
5563 Set_Has_Specified_Stream_Input
(Ent
);
5565 ------------------------
5566 -- Interrupt_Priority --
5567 ------------------------
5569 when Attribute_Interrupt_Priority
=>
5571 -- Interrupt_Priority attribute definition clause not allowed
5572 -- except from aspect specification.
5574 if From_Aspect_Specification
(N
) then
5575 if not Is_Concurrent_Type
(U_Ent
) then
5577 ("Interrupt_Priority can only be defined for task and "
5578 & "protected object", Nam
);
5580 elsif Duplicate_Clause
then
5584 -- The expression must be analyzed in the special manner
5585 -- described in "Handling of Default and Per-Object
5586 -- Expressions" in sem.ads.
5588 -- The visibility to the discriminants must be restored
5590 Push_Scope_And_Install_Discriminants
(U_Ent
);
5592 Preanalyze_Spec_Expression
5593 (Expr
, RTE
(RE_Interrupt_Priority
));
5595 Uninstall_Discriminants_And_Pop_Scope
(U_Ent
);
5597 -- Check the No_Task_At_Interrupt_Priority restriction
5599 if Is_Task_Type
(U_Ent
) then
5600 Check_Restriction
(No_Task_At_Interrupt_Priority
, N
);
5606 ("attribute& cannot be set with definition clause", N
);
5613 when Attribute_Iterable
=>
5616 if Nkind
(Expr
) /= N_Aggregate
then
5617 Error_Msg_N
("aspect Iterable must be an aggregate", Expr
);
5624 Assoc
:= First
(Component_Associations
(Expr
));
5625 while Present
(Assoc
) loop
5626 if not Is_Entity_Name
(Expression
(Assoc
)) then
5627 Error_Msg_N
("value must be a function", Assoc
);
5634 ----------------------
5635 -- Iterator_Element --
5636 ----------------------
5638 when Attribute_Iterator_Element
=>
5641 if not Is_Entity_Name
(Expr
)
5642 or else not Is_Type
(Entity
(Expr
))
5644 Error_Msg_N
("aspect Iterator_Element must be a type", Expr
);
5651 -- Machine radix attribute definition clause
5653 when Attribute_Machine_Radix
=> Machine_Radix
: declare
5654 Radix
: constant Uint
:= Static_Integer
(Expr
);
5657 if not Is_Decimal_Fixed_Point_Type
(U_Ent
) then
5658 Error_Msg_N
("decimal fixed-point type expected for &", Nam
);
5660 elsif Duplicate_Clause
then
5663 elsif Radix
/= No_Uint
then
5664 Set_Has_Machine_Radix_Clause
(U_Ent
);
5665 Set_Has_Non_Standard_Rep
(Base_Type
(U_Ent
));
5670 elsif Radix
= 10 then
5671 Set_Machine_Radix_10
(U_Ent
);
5673 -- The following error is suppressed in ASIS mode to allow for
5674 -- different ASIS back ends or ASIS-based tools to query the
5677 elsif not ASIS_Mode
then
5678 Error_Msg_N
("machine radix value must be 2 or 10", Expr
);
5687 -- Object_Size attribute definition clause
5689 when Attribute_Object_Size
=> Object_Size
: declare
5690 Size
: constant Uint
:= Static_Integer
(Expr
);
5693 pragma Warnings
(Off
, Biased
);
5696 if not Is_Type
(U_Ent
) then
5697 Error_Msg_N
("Object_Size cannot be given for &", Nam
);
5699 elsif Duplicate_Clause
then
5703 Check_Size
(Expr
, U_Ent
, Size
, Biased
);
5705 -- The following errors are suppressed in ASIS mode to allow
5706 -- for different ASIS back ends or ASIS-based tools to query
5707 -- the illegal clause.
5712 elsif Is_Scalar_Type
(U_Ent
) then
5713 if Size
/= 8 and then Size
/= 16 and then Size
/= 32
5714 and then UI_Mod
(Size
, 64) /= 0
5717 ("Object_Size must be 8, 16, 32, or multiple of 64",
5721 elsif Size
mod 8 /= 0 then
5722 Error_Msg_N
("Object_Size must be a multiple of 8", Expr
);
5725 Set_Esize
(U_Ent
, Size
);
5726 Set_Has_Object_Size_Clause
(U_Ent
);
5727 Alignment_Check_For_Size_Change
(U_Ent
, Size
);
5735 when Attribute_Output
=>
5736 Analyze_Stream_TSS_Definition
(TSS_Stream_Output
);
5737 Set_Has_Specified_Stream_Output
(Ent
);
5743 when Attribute_Priority
=>
5745 -- Priority attribute definition clause not allowed except from
5746 -- aspect specification.
5748 if From_Aspect_Specification
(N
) then
5749 if not (Is_Concurrent_Type
(U_Ent
)
5750 or else Ekind
(U_Ent
) = E_Procedure
)
5753 ("Priority can only be defined for task and protected "
5756 elsif Duplicate_Clause
then
5760 -- The expression must be analyzed in the special manner
5761 -- described in "Handling of Default and Per-Object
5762 -- Expressions" in sem.ads.
5764 -- The visibility to the discriminants must be restored
5766 Push_Scope_And_Install_Discriminants
(U_Ent
);
5767 Preanalyze_Spec_Expression
(Expr
, Standard_Integer
);
5768 Uninstall_Discriminants_And_Pop_Scope
(U_Ent
);
5770 if not Is_OK_Static_Expression
(Expr
) then
5771 Check_Restriction
(Static_Priorities
, Expr
);
5777 ("attribute& cannot be set with definition clause", N
);
5784 when Attribute_Read
=>
5785 Analyze_Stream_TSS_Definition
(TSS_Stream_Read
);
5786 Set_Has_Specified_Stream_Read
(Ent
);
5788 --------------------------
5789 -- Scalar_Storage_Order --
5790 --------------------------
5792 -- Scalar_Storage_Order attribute definition clause
5794 when Attribute_Scalar_Storage_Order
=>
5795 if not (Is_Record_Type
(U_Ent
) or else Is_Array_Type
(U_Ent
)) then
5797 ("Scalar_Storage_Order can only be defined for record or "
5798 & "array type", Nam
);
5800 elsif Duplicate_Clause
then
5804 Analyze_And_Resolve
(Expr
, RTE
(RE_Bit_Order
));
5806 if Etype
(Expr
) = Any_Type
then
5809 elsif not Is_OK_Static_Expression
(Expr
) then
5810 Flag_Non_Static_Expr
5811 ("Scalar_Storage_Order requires static expression!", Expr
);
5813 elsif (Expr_Value
(Expr
) = 0) /= Bytes_Big_Endian
then
5815 -- Here for the case of a non-default (i.e. non-confirming)
5816 -- Scalar_Storage_Order attribute definition.
5818 if Support_Nondefault_SSO_On_Target
then
5819 Set_Reverse_Storage_Order
(Base_Type
(U_Ent
), True);
5822 ("non-default Scalar_Storage_Order not supported on "
5827 -- Clear SSO default indications since explicit setting of the
5828 -- order overrides the defaults.
5830 Set_SSO_Set_Low_By_Default
(Base_Type
(U_Ent
), False);
5831 Set_SSO_Set_High_By_Default
(Base_Type
(U_Ent
), False);
5834 --------------------------
5835 -- Secondary_Stack_Size --
5836 --------------------------
5838 when Attribute_Secondary_Stack_Size
=>
5840 -- Secondary_Stack_Size attribute definition clause not allowed
5841 -- except from aspect specification.
5843 if From_Aspect_Specification
(N
) then
5844 if not Is_Task_Type
(U_Ent
) then
5846 ("Secondary Stack Size can only be defined for task", Nam
);
5848 elsif Duplicate_Clause
then
5852 Check_Restriction
(No_Secondary_Stack
, Expr
);
5854 -- The expression must be analyzed in the special manner
5855 -- described in "Handling of Default and Per-Object
5856 -- Expressions" in sem.ads.
5858 -- The visibility to the discriminants must be restored
5860 Push_Scope_And_Install_Discriminants
(U_Ent
);
5861 Preanalyze_Spec_Expression
(Expr
, Any_Integer
);
5862 Uninstall_Discriminants_And_Pop_Scope
(U_Ent
);
5864 if not Is_OK_Static_Expression
(Expr
) then
5865 Check_Restriction
(Static_Storage_Size
, Expr
);
5871 ("attribute& cannot be set with definition clause", N
);
5878 -- Size attribute definition clause
5880 when Attribute_Size
=> Size
: declare
5881 Size
: constant Uint
:= Static_Integer
(Expr
);
5888 if Duplicate_Clause
then
5891 elsif not Is_Type
(U_Ent
)
5892 and then Ekind
(U_Ent
) /= E_Variable
5893 and then Ekind
(U_Ent
) /= E_Constant
5895 Error_Msg_N
("size cannot be given for &", Nam
);
5897 elsif Is_Array_Type
(U_Ent
)
5898 and then not Is_Constrained
(U_Ent
)
5901 ("size cannot be given for unconstrained array", Nam
);
5903 elsif Size
/= No_Uint
then
5904 if Is_Type
(U_Ent
) then
5907 Etyp
:= Etype
(U_Ent
);
5910 -- Check size, note that Gigi is in charge of checking that the
5911 -- size of an array or record type is OK. Also we do not check
5912 -- the size in the ordinary fixed-point case, since it is too
5913 -- early to do so (there may be subsequent small clause that
5914 -- affects the size). We can check the size if a small clause
5915 -- has already been given.
5917 if not Is_Ordinary_Fixed_Point_Type
(U_Ent
)
5918 or else Has_Small_Clause
(U_Ent
)
5920 Check_Size
(Expr
, Etyp
, Size
, Biased
);
5921 Set_Biased
(U_Ent
, N
, "size clause", Biased
);
5924 -- For types set RM_Size and Esize if possible
5926 if Is_Type
(U_Ent
) then
5927 Set_RM_Size
(U_Ent
, Size
);
5929 -- For elementary types, increase Object_Size to power of 2,
5930 -- but not less than a storage unit in any case (normally
5931 -- this means it will be byte addressable).
5933 -- For all other types, nothing else to do, we leave Esize
5934 -- (object size) unset, the back end will set it from the
5935 -- size and alignment in an appropriate manner.
5937 -- In both cases, we check whether the alignment must be
5938 -- reset in the wake of the size change.
5940 if Is_Elementary_Type
(U_Ent
) then
5941 if Size
<= System_Storage_Unit
then
5942 Init_Esize
(U_Ent
, System_Storage_Unit
);
5943 elsif Size
<= 16 then
5944 Init_Esize
(U_Ent
, 16);
5945 elsif Size
<= 32 then
5946 Init_Esize
(U_Ent
, 32);
5948 Set_Esize
(U_Ent
, (Size
+ 63) / 64 * 64);
5951 Alignment_Check_For_Size_Change
(U_Ent
, Esize
(U_Ent
));
5953 Alignment_Check_For_Size_Change
(U_Ent
, Size
);
5956 -- For objects, set Esize only
5959 -- The following error is suppressed in ASIS mode to allow
5960 -- for different ASIS back ends or ASIS-based tools to query
5961 -- the illegal clause.
5963 if Is_Elementary_Type
(Etyp
)
5964 and then Size
/= System_Storage_Unit
5965 and then Size
/= System_Storage_Unit
* 2
5966 and then Size
/= System_Storage_Unit
* 4
5967 and then Size
/= System_Storage_Unit
* 8
5968 and then not ASIS_Mode
5970 Error_Msg_Uint_1
:= UI_From_Int
(System_Storage_Unit
);
5971 Error_Msg_Uint_2
:= Error_Msg_Uint_1
* 8;
5973 ("size for primitive object must be a power of 2 in "
5974 & "the range ^-^", N
);
5977 Set_Esize
(U_Ent
, Size
);
5980 Set_Has_Size_Clause
(U_Ent
);
5988 -- Small attribute definition clause
5990 when Attribute_Small
=> Small
: declare
5991 Implicit_Base
: constant Entity_Id
:= Base_Type
(U_Ent
);
5995 Analyze_And_Resolve
(Expr
, Any_Real
);
5997 if Etype
(Expr
) = Any_Type
then
6000 elsif not Is_OK_Static_Expression
(Expr
) then
6001 Flag_Non_Static_Expr
6002 ("small requires static expression!", Expr
);
6006 Small
:= Expr_Value_R
(Expr
);
6008 if Small
<= Ureal_0
then
6009 Error_Msg_N
("small value must be greater than zero", Expr
);
6015 if not Is_Ordinary_Fixed_Point_Type
(U_Ent
) then
6017 ("small requires an ordinary fixed point type", Nam
);
6019 elsif Has_Small_Clause
(U_Ent
) then
6020 Error_Msg_N
("small already given for &", Nam
);
6022 elsif Small
> Delta_Value
(U_Ent
) then
6024 ("small value must not be greater than delta value", Nam
);
6027 Set_Small_Value
(U_Ent
, Small
);
6028 Set_Small_Value
(Implicit_Base
, Small
);
6029 Set_Has_Small_Clause
(U_Ent
);
6030 Set_Has_Small_Clause
(Implicit_Base
);
6031 Set_Has_Non_Standard_Rep
(Implicit_Base
);
6039 -- Storage_Pool attribute definition clause
6041 when Attribute_Simple_Storage_Pool
6042 | Attribute_Storage_Pool
6044 Storage_Pool
: declare
6049 if Ekind
(U_Ent
) = E_Access_Subprogram_Type
then
6051 ("storage pool cannot be given for access-to-subprogram type",
6055 elsif not Ekind_In
(U_Ent
, E_Access_Type
, E_General_Access_Type
)
6058 ("storage pool can only be given for access types", Nam
);
6061 elsif Is_Derived_Type
(U_Ent
) then
6063 ("storage pool cannot be given for a derived access type",
6066 elsif Duplicate_Clause
then
6069 elsif Present
(Associated_Storage_Pool
(U_Ent
)) then
6070 Error_Msg_N
("storage pool already given for &", Nam
);
6074 -- Check for Storage_Size previously given
6077 SS
: constant Node_Id
:=
6078 Get_Attribute_Definition_Clause
6079 (U_Ent
, Attribute_Storage_Size
);
6081 if Present
(SS
) then
6082 Check_Pool_Size_Clash
(U_Ent
, N
, SS
);
6086 -- Storage_Pool case
6088 if Id
= Attribute_Storage_Pool
then
6090 (Expr
, Class_Wide_Type
(RTE
(RE_Root_Storage_Pool
)));
6092 -- In the Simple_Storage_Pool case, we allow a variable of any
6093 -- simple storage pool type, so we Resolve without imposing an
6097 Analyze_And_Resolve
(Expr
);
6099 if not Present
(Get_Rep_Pragma
6100 (Etype
(Expr
), Name_Simple_Storage_Pool_Type
))
6103 ("expression must be of a simple storage pool type", Expr
);
6107 if not Denotes_Variable
(Expr
) then
6108 Error_Msg_N
("storage pool must be a variable", Expr
);
6112 if Nkind
(Expr
) = N_Type_Conversion
then
6113 T
:= Etype
(Expression
(Expr
));
6118 -- The Stack_Bounded_Pool is used internally for implementing
6119 -- access types with a Storage_Size. Since it only work properly
6120 -- when used on one specific type, we need to check that it is not
6121 -- hijacked improperly:
6123 -- type T is access Integer;
6124 -- for T'Storage_Size use n;
6125 -- type Q is access Float;
6126 -- for Q'Storage_Size use T'Storage_Size; -- incorrect
6128 if RTE_Available
(RE_Stack_Bounded_Pool
)
6129 and then Base_Type
(T
) = RTE
(RE_Stack_Bounded_Pool
)
6131 Error_Msg_N
("non-shareable internal Pool", Expr
);
6135 -- If the argument is a name that is not an entity name, then
6136 -- we construct a renaming operation to define an entity of
6137 -- type storage pool.
6139 if not Is_Entity_Name
(Expr
)
6140 and then Is_Object_Reference
(Expr
)
6142 Pool
:= Make_Temporary
(Loc
, 'P', Expr
);
6145 Rnode
: constant Node_Id
:=
6146 Make_Object_Renaming_Declaration
(Loc
,
6147 Defining_Identifier
=> Pool
,
6149 New_Occurrence_Of
(Etype
(Expr
), Loc
),
6153 -- If the attribute definition clause comes from an aspect
6154 -- clause, then insert the renaming before the associated
6155 -- entity's declaration, since the attribute clause has
6156 -- not yet been appended to the declaration list.
6158 if From_Aspect_Specification
(N
) then
6159 Insert_Before
(Parent
(Entity
(N
)), Rnode
);
6161 Insert_Before
(N
, Rnode
);
6165 Set_Associated_Storage_Pool
(U_Ent
, Pool
);
6168 elsif Is_Entity_Name
(Expr
) then
6169 Pool
:= Entity
(Expr
);
6171 -- If pool is a renamed object, get original one. This can
6172 -- happen with an explicit renaming, and within instances.
6174 while Present
(Renamed_Object
(Pool
))
6175 and then Is_Entity_Name
(Renamed_Object
(Pool
))
6177 Pool
:= Entity
(Renamed_Object
(Pool
));
6180 if Present
(Renamed_Object
(Pool
))
6181 and then Nkind
(Renamed_Object
(Pool
)) = N_Type_Conversion
6182 and then Is_Entity_Name
(Expression
(Renamed_Object
(Pool
)))
6184 Pool
:= Entity
(Expression
(Renamed_Object
(Pool
)));
6187 Set_Associated_Storage_Pool
(U_Ent
, Pool
);
6189 elsif Nkind
(Expr
) = N_Type_Conversion
6190 and then Is_Entity_Name
(Expression
(Expr
))
6191 and then Nkind
(Original_Node
(Expr
)) = N_Attribute_Reference
6193 Pool
:= Entity
(Expression
(Expr
));
6194 Set_Associated_Storage_Pool
(U_Ent
, Pool
);
6197 Error_Msg_N
("incorrect reference to a Storage Pool", Expr
);
6206 -- Storage_Size attribute definition clause
6208 when Attribute_Storage_Size
=> Storage_Size
: declare
6209 Btype
: constant Entity_Id
:= Base_Type
(U_Ent
);
6212 if Is_Task_Type
(U_Ent
) then
6214 -- Check obsolescent (but never obsolescent if from aspect)
6216 if not From_Aspect_Specification
(N
) then
6217 Check_Restriction
(No_Obsolescent_Features
, N
);
6219 if Warn_On_Obsolescent_Feature
then
6221 ("?j?storage size clause for task is an obsolescent "
6222 & "feature (RM J.9)", N
);
6223 Error_Msg_N
("\?j?use Storage_Size pragma instead", N
);
6230 if not Is_Access_Type
(U_Ent
)
6231 and then Ekind
(U_Ent
) /= E_Task_Type
6233 Error_Msg_N
("storage size cannot be given for &", Nam
);
6235 elsif Is_Access_Type
(U_Ent
) and Is_Derived_Type
(U_Ent
) then
6237 ("storage size cannot be given for a derived access type",
6240 elsif Duplicate_Clause
then
6244 Analyze_And_Resolve
(Expr
, Any_Integer
);
6246 if Is_Access_Type
(U_Ent
) then
6248 -- Check for Storage_Pool previously given
6251 SP
: constant Node_Id
:=
6252 Get_Attribute_Definition_Clause
6253 (U_Ent
, Attribute_Storage_Pool
);
6256 if Present
(SP
) then
6257 Check_Pool_Size_Clash
(U_Ent
, SP
, N
);
6261 -- Special case of for x'Storage_Size use 0
6263 if Is_OK_Static_Expression
(Expr
)
6264 and then Expr_Value
(Expr
) = 0
6266 Set_No_Pool_Assigned
(Btype
);
6270 Set_Has_Storage_Size_Clause
(Btype
);
6278 when Attribute_Stream_Size
=> Stream_Size
: declare
6279 Size
: constant Uint
:= Static_Integer
(Expr
);
6282 if Ada_Version
<= Ada_95
then
6283 Check_Restriction
(No_Implementation_Attributes
, N
);
6286 if Duplicate_Clause
then
6289 elsif Is_Elementary_Type
(U_Ent
) then
6291 -- The following errors are suppressed in ASIS mode to allow
6292 -- for different ASIS back ends or ASIS-based tools to query
6293 -- the illegal clause.
6298 elsif Size
/= System_Storage_Unit
6299 and then Size
/= System_Storage_Unit
* 2
6300 and then Size
/= System_Storage_Unit
* 4
6301 and then Size
/= System_Storage_Unit
* 8
6303 Error_Msg_Uint_1
:= UI_From_Int
(System_Storage_Unit
);
6305 ("stream size for elementary type must be a power of 2 "
6306 & "and at least ^", N
);
6308 elsif RM_Size
(U_Ent
) > Size
then
6309 Error_Msg_Uint_1
:= RM_Size
(U_Ent
);
6311 ("stream size for elementary type must be a power of 2 "
6312 & "and at least ^", N
);
6315 Set_Has_Stream_Size_Clause
(U_Ent
);
6318 Error_Msg_N
("Stream_Size cannot be given for &", Nam
);
6326 -- Value_Size attribute definition clause
6328 when Attribute_Value_Size
=> Value_Size
: declare
6329 Size
: constant Uint
:= Static_Integer
(Expr
);
6333 if not Is_Type
(U_Ent
) then
6334 Error_Msg_N
("Value_Size cannot be given for &", Nam
);
6336 elsif Duplicate_Clause
then
6339 elsif Is_Array_Type
(U_Ent
)
6340 and then not Is_Constrained
(U_Ent
)
6343 ("Value_Size cannot be given for unconstrained array", Nam
);
6346 if Is_Elementary_Type
(U_Ent
) then
6347 Check_Size
(Expr
, U_Ent
, Size
, Biased
);
6348 Set_Biased
(U_Ent
, N
, "value size clause", Biased
);
6351 Set_RM_Size
(U_Ent
, Size
);
6355 -----------------------
6356 -- Variable_Indexing --
6357 -----------------------
6359 when Attribute_Variable_Indexing
=>
6360 Check_Indexing_Functions
;
6366 when Attribute_Write
=>
6367 Analyze_Stream_TSS_Definition
(TSS_Stream_Write
);
6368 Set_Has_Specified_Stream_Write
(Ent
);
6370 -- All other attributes cannot be set
6374 ("attribute& cannot be set with definition clause", N
);
6377 -- The test for the type being frozen must be performed after any
6378 -- expression the clause has been analyzed since the expression itself
6379 -- might cause freezing that makes the clause illegal.
6381 if Rep_Item_Too_Late
(U_Ent
, N
, FOnly
) then
6384 end Analyze_Attribute_Definition_Clause
;
6386 ----------------------------
6387 -- Analyze_Code_Statement --
6388 ----------------------------
6390 procedure Analyze_Code_Statement
(N
: Node_Id
) is
6391 HSS
: constant Node_Id
:= Parent
(N
);
6392 SBody
: constant Node_Id
:= Parent
(HSS
);
6393 Subp
: constant Entity_Id
:= Current_Scope
;
6400 -- Accept foreign code statements for CodePeer. The analysis is skipped
6401 -- to avoid rejecting unrecognized constructs.
6403 if CodePeer_Mode
then
6408 -- Analyze and check we get right type, note that this implements the
6409 -- requirement (RM 13.8(1)) that Machine_Code be with'ed, since that is
6410 -- the only way that Asm_Insn could possibly be visible.
6412 Analyze_And_Resolve
(Expression
(N
));
6414 if Etype
(Expression
(N
)) = Any_Type
then
6416 elsif Etype
(Expression
(N
)) /= RTE
(RE_Asm_Insn
) then
6417 Error_Msg_N
("incorrect type for code statement", N
);
6421 Check_Code_Statement
(N
);
6423 -- Make sure we appear in the handled statement sequence of a subprogram
6426 if Nkind
(HSS
) /= N_Handled_Sequence_Of_Statements
6427 or else Nkind
(SBody
) /= N_Subprogram_Body
6430 ("code statement can only appear in body of subprogram", N
);
6434 -- Do remaining checks (RM 13.8(3)) if not already done
6436 if not Is_Machine_Code_Subprogram
(Subp
) then
6437 Set_Is_Machine_Code_Subprogram
(Subp
);
6439 -- No exception handlers allowed
6441 if Present
(Exception_Handlers
(HSS
)) then
6443 ("exception handlers not permitted in machine code subprogram",
6444 First
(Exception_Handlers
(HSS
)));
6447 -- No declarations other than use clauses and pragmas (we allow
6448 -- certain internally generated declarations as well).
6450 Decl
:= First
(Declarations
(SBody
));
6451 while Present
(Decl
) loop
6452 DeclO
:= Original_Node
(Decl
);
6453 if Comes_From_Source
(DeclO
)
6454 and not Nkind_In
(DeclO
, N_Pragma
,
6455 N_Use_Package_Clause
,
6457 N_Implicit_Label_Declaration
)
6460 ("this declaration not allowed in machine code subprogram",
6467 -- No statements other than code statements, pragmas, and labels.
6468 -- Again we allow certain internally generated statements.
6470 -- In Ada 2012, qualified expressions are names, and the code
6471 -- statement is initially parsed as a procedure call.
6473 Stmt
:= First
(Statements
(HSS
));
6474 while Present
(Stmt
) loop
6475 StmtO
:= Original_Node
(Stmt
);
6477 -- A procedure call transformed into a code statement is OK
6479 if Ada_Version
>= Ada_2012
6480 and then Nkind
(StmtO
) = N_Procedure_Call_Statement
6481 and then Nkind
(Name
(StmtO
)) = N_Qualified_Expression
6485 elsif Comes_From_Source
(StmtO
)
6486 and then not Nkind_In
(StmtO
, N_Pragma
,
6491 ("this statement is not allowed in machine code subprogram",
6498 end Analyze_Code_Statement
;
6500 -----------------------------------------------
6501 -- Analyze_Enumeration_Representation_Clause --
6502 -----------------------------------------------
6504 procedure Analyze_Enumeration_Representation_Clause
(N
: Node_Id
) is
6505 Ident
: constant Node_Id
:= Identifier
(N
);
6506 Aggr
: constant Node_Id
:= Array_Aggregate
(N
);
6507 Enumtype
: Entity_Id
;
6514 Err
: Boolean := False;
6515 -- Set True to avoid cascade errors and crashes on incorrect source code
6517 Lo
: constant Uint
:= Expr_Value
(Type_Low_Bound
(Universal_Integer
));
6518 Hi
: constant Uint
:= Expr_Value
(Type_High_Bound
(Universal_Integer
));
6519 -- Allowed range of universal integer (= allowed range of enum lit vals)
6523 -- Minimum and maximum values of entries
6526 -- Pointer to node for literal providing max value
6529 if Ignore_Rep_Clauses
then
6530 Kill_Rep_Clause
(N
);
6534 -- Ignore enumeration rep clauses by default in CodePeer mode,
6535 -- unless -gnatd.I is specified, as a work around for potential false
6536 -- positive messages.
6538 if CodePeer_Mode
and not Debug_Flag_Dot_II
then
6542 -- First some basic error checks
6545 Enumtype
:= Entity
(Ident
);
6547 if Enumtype
= Any_Type
6548 or else Rep_Item_Too_Early
(Enumtype
, N
)
6552 Enumtype
:= Underlying_Type
(Enumtype
);
6555 if not Is_Enumeration_Type
(Enumtype
) then
6557 ("enumeration type required, found}",
6558 Ident
, First_Subtype
(Enumtype
));
6562 -- Ignore rep clause on generic actual type. This will already have
6563 -- been flagged on the template as an error, and this is the safest
6564 -- way to ensure we don't get a junk cascaded message in the instance.
6566 if Is_Generic_Actual_Type
(Enumtype
) then
6569 -- Type must be in current scope
6571 elsif Scope
(Enumtype
) /= Current_Scope
then
6572 Error_Msg_N
("type must be declared in this scope", Ident
);
6575 -- Type must be a first subtype
6577 elsif not Is_First_Subtype
(Enumtype
) then
6578 Error_Msg_N
("cannot give enumeration rep clause for subtype", N
);
6581 -- Ignore duplicate rep clause
6583 elsif Has_Enumeration_Rep_Clause
(Enumtype
) then
6584 Error_Msg_N
("duplicate enumeration rep clause ignored", N
);
6587 -- Don't allow rep clause for standard [wide_[wide_]]character
6589 elsif Is_Standard_Character_Type
(Enumtype
) then
6590 Error_Msg_N
("enumeration rep clause not allowed for this type", N
);
6593 -- Check that the expression is a proper aggregate (no parentheses)
6595 elsif Paren_Count
(Aggr
) /= 0 then
6597 ("extra parentheses surrounding aggregate not allowed",
6601 -- All tests passed, so set rep clause in place
6604 Set_Has_Enumeration_Rep_Clause
(Enumtype
);
6605 Set_Has_Enumeration_Rep_Clause
(Base_Type
(Enumtype
));
6608 -- Now we process the aggregate. Note that we don't use the normal
6609 -- aggregate code for this purpose, because we don't want any of the
6610 -- normal expansion activities, and a number of special semantic
6611 -- rules apply (including the component type being any integer type)
6613 Elit
:= First_Literal
(Enumtype
);
6615 -- First the positional entries if any
6617 if Present
(Expressions
(Aggr
)) then
6618 Expr
:= First
(Expressions
(Aggr
));
6619 while Present
(Expr
) loop
6621 Error_Msg_N
("too many entries in aggregate", Expr
);
6625 Val
:= Static_Integer
(Expr
);
6627 -- Err signals that we found some incorrect entries processing
6628 -- the list. The final checks for completeness and ordering are
6629 -- skipped in this case.
6631 if Val
= No_Uint
then
6634 elsif Val
< Lo
or else Hi
< Val
then
6635 Error_Msg_N
("value outside permitted range", Expr
);
6639 Set_Enumeration_Rep
(Elit
, Val
);
6640 Set_Enumeration_Rep_Expr
(Elit
, Expr
);
6646 -- Now process the named entries if present
6648 if Present
(Component_Associations
(Aggr
)) then
6649 Assoc
:= First
(Component_Associations
(Aggr
));
6650 while Present
(Assoc
) loop
6651 Choice
:= First
(Choices
(Assoc
));
6653 if Present
(Next
(Choice
)) then
6655 ("multiple choice not allowed here", Next
(Choice
));
6659 if Nkind
(Choice
) = N_Others_Choice
then
6660 Error_Msg_N
("others choice not allowed here", Choice
);
6663 elsif Nkind
(Choice
) = N_Range
then
6665 -- ??? should allow zero/one element range here
6667 Error_Msg_N
("range not allowed here", Choice
);
6671 Analyze_And_Resolve
(Choice
, Enumtype
);
6673 if Error_Posted
(Choice
) then
6678 if Is_Entity_Name
(Choice
)
6679 and then Is_Type
(Entity
(Choice
))
6681 Error_Msg_N
("subtype name not allowed here", Choice
);
6684 -- ??? should allow static subtype with zero/one entry
6686 elsif Etype
(Choice
) = Base_Type
(Enumtype
) then
6687 if not Is_OK_Static_Expression
(Choice
) then
6688 Flag_Non_Static_Expr
6689 ("non-static expression used for choice!", Choice
);
6693 Elit
:= Expr_Value_E
(Choice
);
6695 if Present
(Enumeration_Rep_Expr
(Elit
)) then
6697 Sloc
(Enumeration_Rep_Expr
(Elit
));
6699 ("representation for& previously given#",
6704 Set_Enumeration_Rep_Expr
(Elit
, Expression
(Assoc
));
6706 Expr
:= Expression
(Assoc
);
6707 Val
:= Static_Integer
(Expr
);
6709 if Val
= No_Uint
then
6712 elsif Val
< Lo
or else Hi
< Val
then
6713 Error_Msg_N
("value outside permitted range", Expr
);
6717 Set_Enumeration_Rep
(Elit
, Val
);
6727 -- Aggregate is fully processed. Now we check that a full set of
6728 -- representations was given, and that they are in range and in order.
6729 -- These checks are only done if no other errors occurred.
6735 Elit
:= First_Literal
(Enumtype
);
6736 while Present
(Elit
) loop
6737 if No
(Enumeration_Rep_Expr
(Elit
)) then
6738 Error_Msg_NE
("missing representation for&!", N
, Elit
);
6741 Val
:= Enumeration_Rep
(Elit
);
6743 if Min
= No_Uint
then
6747 if Val
/= No_Uint
then
6748 if Max
/= No_Uint
and then Val
<= Max
then
6750 ("enumeration value for& not ordered!",
6751 Enumeration_Rep_Expr
(Elit
), Elit
);
6754 Max_Node
:= Enumeration_Rep_Expr
(Elit
);
6758 -- If there is at least one literal whose representation is not
6759 -- equal to the Pos value, then note that this enumeration type
6760 -- has a non-standard representation.
6762 if Val
/= Enumeration_Pos
(Elit
) then
6763 Set_Has_Non_Standard_Rep
(Base_Type
(Enumtype
));
6770 -- Now set proper size information
6773 Minsize
: Uint
:= UI_From_Int
(Minimum_Size
(Enumtype
));
6776 if Has_Size_Clause
(Enumtype
) then
6778 -- All OK, if size is OK now
6780 if RM_Size
(Enumtype
) >= Minsize
then
6784 -- Try if we can get by with biasing
6787 UI_From_Int
(Minimum_Size
(Enumtype
, Biased
=> True));
6789 -- Error message if even biasing does not work
6791 if RM_Size
(Enumtype
) < Minsize
then
6792 Error_Msg_Uint_1
:= RM_Size
(Enumtype
);
6793 Error_Msg_Uint_2
:= Max
;
6795 ("previously given size (^) is too small "
6796 & "for this value (^)", Max_Node
);
6798 -- If biasing worked, indicate that we now have biased rep
6802 (Enumtype
, Size_Clause
(Enumtype
), "size clause");
6807 Set_RM_Size
(Enumtype
, Minsize
);
6808 Set_Enum_Esize
(Enumtype
);
6811 Set_RM_Size
(Base_Type
(Enumtype
), RM_Size
(Enumtype
));
6812 Set_Esize
(Base_Type
(Enumtype
), Esize
(Enumtype
));
6813 Set_Alignment
(Base_Type
(Enumtype
), Alignment
(Enumtype
));
6817 -- We repeat the too late test in case it froze itself
6819 if Rep_Item_Too_Late
(Enumtype
, N
) then
6822 end Analyze_Enumeration_Representation_Clause
;
6824 ----------------------------
6825 -- Analyze_Free_Statement --
6826 ----------------------------
6828 procedure Analyze_Free_Statement
(N
: Node_Id
) is
6830 Analyze
(Expression
(N
));
6831 end Analyze_Free_Statement
;
6833 ---------------------------
6834 -- Analyze_Freeze_Entity --
6835 ---------------------------
6837 procedure Analyze_Freeze_Entity
(N
: Node_Id
) is
6839 Freeze_Entity_Checks
(N
);
6840 end Analyze_Freeze_Entity
;
6842 -----------------------------------
6843 -- Analyze_Freeze_Generic_Entity --
6844 -----------------------------------
6846 procedure Analyze_Freeze_Generic_Entity
(N
: Node_Id
) is
6847 E
: constant Entity_Id
:= Entity
(N
);
6850 if not Is_Frozen
(E
) and then Has_Delayed_Aspects
(E
) then
6851 Analyze_Aspects_At_Freeze_Point
(E
);
6854 Freeze_Entity_Checks
(N
);
6855 end Analyze_Freeze_Generic_Entity
;
6857 ------------------------------------------
6858 -- Analyze_Record_Representation_Clause --
6859 ------------------------------------------
6861 -- Note: we check as much as we can here, but we can't do any checks
6862 -- based on the position values (e.g. overlap checks) until freeze time
6863 -- because especially in Ada 2005 (machine scalar mode), the processing
6864 -- for non-standard bit order can substantially change the positions.
6865 -- See procedure Check_Record_Representation_Clause (called from Freeze)
6866 -- for the remainder of this processing.
6868 procedure Analyze_Record_Representation_Clause
(N
: Node_Id
) is
6869 Ident
: constant Node_Id
:= Identifier
(N
);
6874 Hbit
: Uint
:= Uint_0
;
6878 Rectype
: Entity_Id
;
6881 function Is_Inherited
(Comp
: Entity_Id
) return Boolean;
6882 -- True if Comp is an inherited component in a record extension
6888 function Is_Inherited
(Comp
: Entity_Id
) return Boolean is
6889 Comp_Base
: Entity_Id
;
6892 if Ekind
(Rectype
) = E_Record_Subtype
then
6893 Comp_Base
:= Original_Record_Component
(Comp
);
6898 return Comp_Base
/= Original_Record_Component
(Comp_Base
);
6903 Is_Record_Extension
: Boolean;
6904 -- True if Rectype is a record extension
6906 CR_Pragma
: Node_Id
:= Empty
;
6907 -- Points to N_Pragma node if Complete_Representation pragma present
6909 -- Start of processing for Analyze_Record_Representation_Clause
6912 if Ignore_Rep_Clauses
then
6913 Kill_Rep_Clause
(N
);
6918 Rectype
:= Entity
(Ident
);
6920 if Rectype
= Any_Type
or else Rep_Item_Too_Early
(Rectype
, N
) then
6923 Rectype
:= Underlying_Type
(Rectype
);
6926 -- First some basic error checks
6928 if not Is_Record_Type
(Rectype
) then
6930 ("record type required, found}", Ident
, First_Subtype
(Rectype
));
6933 elsif Scope
(Rectype
) /= Current_Scope
then
6934 Error_Msg_N
("type must be declared in this scope", N
);
6937 elsif not Is_First_Subtype
(Rectype
) then
6938 Error_Msg_N
("cannot give record rep clause for subtype", N
);
6941 elsif Has_Record_Rep_Clause
(Rectype
) then
6942 Error_Msg_N
("duplicate record rep clause ignored", N
);
6945 elsif Rep_Item_Too_Late
(Rectype
, N
) then
6949 -- We know we have a first subtype, now possibly go to the anonymous
6950 -- base type to determine whether Rectype is a record extension.
6952 Recdef
:= Type_Definition
(Declaration_Node
(Base_Type
(Rectype
)));
6953 Is_Record_Extension
:=
6954 Nkind
(Recdef
) = N_Derived_Type_Definition
6955 and then Present
(Record_Extension_Part
(Recdef
));
6957 if Present
(Mod_Clause
(N
)) then
6959 Loc
: constant Source_Ptr
:= Sloc
(N
);
6960 M
: constant Node_Id
:= Mod_Clause
(N
);
6961 P
: constant List_Id
:= Pragmas_Before
(M
);
6965 pragma Warnings
(Off
, Mod_Val
);
6968 Check_Restriction
(No_Obsolescent_Features
, Mod_Clause
(N
));
6970 if Warn_On_Obsolescent_Feature
then
6972 ("?j?mod clause is an obsolescent feature (RM J.8)", N
);
6974 ("\?j?use alignment attribute definition clause instead", N
);
6981 -- In ASIS_Mode mode, expansion is disabled, but we must convert
6982 -- the Mod clause into an alignment clause anyway, so that the
6983 -- back end can compute and back-annotate properly the size and
6984 -- alignment of types that may include this record.
6986 -- This seems dubious, this destroys the source tree in a manner
6987 -- not detectable by ASIS ???
6989 if Operating_Mode
= Check_Semantics
and then ASIS_Mode
then
6991 Make_Attribute_Definition_Clause
(Loc
,
6992 Name
=> New_Occurrence_Of
(Base_Type
(Rectype
), Loc
),
6993 Chars
=> Name_Alignment
,
6994 Expression
=> Relocate_Node
(Expression
(M
)));
6996 Set_From_At_Mod
(AtM_Nod
);
6997 Insert_After
(N
, AtM_Nod
);
6998 Mod_Val
:= Get_Alignment_Value
(Expression
(AtM_Nod
));
6999 Set_Mod_Clause
(N
, Empty
);
7002 -- Get the alignment value to perform error checking
7004 Mod_Val
:= Get_Alignment_Value
(Expression
(M
));
7009 -- For untagged types, clear any existing component clauses for the
7010 -- type. If the type is derived, this is what allows us to override
7011 -- a rep clause for the parent. For type extensions, the representation
7012 -- of the inherited components is inherited, so we want to keep previous
7013 -- component clauses for completeness.
7015 if not Is_Tagged_Type
(Rectype
) then
7016 Comp
:= First_Component_Or_Discriminant
(Rectype
);
7017 while Present
(Comp
) loop
7018 Set_Component_Clause
(Comp
, Empty
);
7019 Next_Component_Or_Discriminant
(Comp
);
7023 -- All done if no component clauses
7025 CC
:= First
(Component_Clauses
(N
));
7031 -- A representation like this applies to the base type
7033 Set_Has_Record_Rep_Clause
(Base_Type
(Rectype
));
7034 Set_Has_Non_Standard_Rep
(Base_Type
(Rectype
));
7035 Set_Has_Specified_Layout
(Base_Type
(Rectype
));
7037 -- Process the component clauses
7039 while Present
(CC
) loop
7043 if Nkind
(CC
) = N_Pragma
then
7046 -- The only pragma of interest is Complete_Representation
7048 if Pragma_Name
(CC
) = Name_Complete_Representation
then
7052 -- Processing for real component clause
7055 Posit
:= Static_Integer
(Position
(CC
));
7056 Fbit
:= Static_Integer
(First_Bit
(CC
));
7057 Lbit
:= Static_Integer
(Last_Bit
(CC
));
7060 and then Fbit
/= No_Uint
7061 and then Lbit
/= No_Uint
7064 Error_Msg_N
("position cannot be negative", Position
(CC
));
7067 Error_Msg_N
("first bit cannot be negative", First_Bit
(CC
));
7069 -- The Last_Bit specified in a component clause must not be
7070 -- less than the First_Bit minus one (RM-13.5.1(10)).
7072 elsif Lbit
< Fbit
- 1 then
7074 ("last bit cannot be less than first bit minus one",
7077 -- Values look OK, so find the corresponding record component
7078 -- Even though the syntax allows an attribute reference for
7079 -- implementation-defined components, GNAT does not allow the
7080 -- tag to get an explicit position.
7082 elsif Nkind
(Component_Name
(CC
)) = N_Attribute_Reference
then
7083 if Attribute_Name
(Component_Name
(CC
)) = Name_Tag
then
7084 Error_Msg_N
("position of tag cannot be specified", CC
);
7086 Error_Msg_N
("illegal component name", CC
);
7090 Comp
:= First_Entity
(Rectype
);
7091 while Present
(Comp
) loop
7092 exit when Chars
(Comp
) = Chars
(Component_Name
(CC
));
7098 -- Maybe component of base type that is absent from
7099 -- statically constrained first subtype.
7101 Comp
:= First_Entity
(Base_Type
(Rectype
));
7102 while Present
(Comp
) loop
7103 exit when Chars
(Comp
) = Chars
(Component_Name
(CC
));
7110 ("component clause is for non-existent field", CC
);
7112 -- Ada 2012 (AI05-0026): Any name that denotes a
7113 -- discriminant of an object of an unchecked union type
7114 -- shall not occur within a record_representation_clause.
7116 -- The general restriction of using record rep clauses on
7117 -- Unchecked_Union types has now been lifted. Since it is
7118 -- possible to introduce a record rep clause which mentions
7119 -- the discriminant of an Unchecked_Union in non-Ada 2012
7120 -- code, this check is applied to all versions of the
7123 elsif Ekind
(Comp
) = E_Discriminant
7124 and then Is_Unchecked_Union
(Rectype
)
7127 ("cannot reference discriminant of unchecked union",
7128 Component_Name
(CC
));
7130 elsif Is_Record_Extension
and then Is_Inherited
(Comp
) then
7132 ("component clause not allowed for inherited "
7133 & "component&", CC
, Comp
);
7135 elsif Present
(Component_Clause
(Comp
)) then
7137 -- Diagnose duplicate rep clause, or check consistency
7138 -- if this is an inherited component. In a double fault,
7139 -- there may be a duplicate inconsistent clause for an
7140 -- inherited component.
7142 if Scope
(Original_Record_Component
(Comp
)) = Rectype
7143 or else Parent
(Component_Clause
(Comp
)) = N
7145 Error_Msg_Sloc
:= Sloc
(Component_Clause
(Comp
));
7146 Error_Msg_N
("component clause previously given#", CC
);
7150 Rep1
: constant Node_Id
:= Component_Clause
(Comp
);
7152 if Intval
(Position
(Rep1
)) /=
7153 Intval
(Position
(CC
))
7154 or else Intval
(First_Bit
(Rep1
)) /=
7155 Intval
(First_Bit
(CC
))
7156 or else Intval
(Last_Bit
(Rep1
)) /=
7157 Intval
(Last_Bit
(CC
))
7160 ("component clause inconsistent with "
7161 & "representation of ancestor", CC
);
7163 elsif Warn_On_Redundant_Constructs
then
7165 ("?r?redundant confirming component clause "
7166 & "for component!", CC
);
7171 -- Normal case where this is the first component clause we
7172 -- have seen for this entity, so set it up properly.
7175 -- Make reference for field in record rep clause and set
7176 -- appropriate entity field in the field identifier.
7179 (Comp
, Component_Name
(CC
), Set_Ref
=> False);
7180 Set_Entity
(Component_Name
(CC
), Comp
);
7182 -- Update Fbit and Lbit to the actual bit number
7184 Fbit
:= Fbit
+ UI_From_Int
(SSU
) * Posit
;
7185 Lbit
:= Lbit
+ UI_From_Int
(SSU
) * Posit
;
7187 if Has_Size_Clause
(Rectype
)
7188 and then RM_Size
(Rectype
) <= Lbit
7191 ("bit number out of range of specified size",
7194 Set_Component_Clause
(Comp
, CC
);
7195 Set_Component_Bit_Offset
(Comp
, Fbit
);
7196 Set_Esize
(Comp
, 1 + (Lbit
- Fbit
));
7197 Set_Normalized_First_Bit
(Comp
, Fbit
mod SSU
);
7198 Set_Normalized_Position
(Comp
, Fbit
/ SSU
);
7200 if Warn_On_Overridden_Size
7201 and then Has_Size_Clause
(Etype
(Comp
))
7202 and then RM_Size
(Etype
(Comp
)) /= Esize
(Comp
)
7205 ("?S?component size overrides size clause for&",
7206 Component_Name
(CC
), Etype
(Comp
));
7209 -- This information is also set in the corresponding
7210 -- component of the base type, found by accessing the
7211 -- Original_Record_Component link if it is present.
7213 Ocomp
:= Original_Record_Component
(Comp
);
7220 (Component_Name
(CC
),
7226 (Comp
, First_Node
(CC
), "component clause", Biased
);
7228 if Present
(Ocomp
) then
7229 Set_Component_Clause
(Ocomp
, CC
);
7230 Set_Component_Bit_Offset
(Ocomp
, Fbit
);
7231 Set_Normalized_First_Bit
(Ocomp
, Fbit
mod SSU
);
7232 Set_Normalized_Position
(Ocomp
, Fbit
/ SSU
);
7233 Set_Esize
(Ocomp
, 1 + (Lbit
- Fbit
));
7235 Set_Normalized_Position_Max
7236 (Ocomp
, Normalized_Position
(Ocomp
));
7238 -- Note: we don't use Set_Biased here, because we
7239 -- already gave a warning above if needed, and we
7240 -- would get a duplicate for the same name here.
7242 Set_Has_Biased_Representation
7243 (Ocomp
, Has_Biased_Representation
(Comp
));
7246 if Esize
(Comp
) < 0 then
7247 Error_Msg_N
("component size is negative", CC
);
7258 -- Check missing components if Complete_Representation pragma appeared
7260 if Present
(CR_Pragma
) then
7261 Comp
:= First_Component_Or_Discriminant
(Rectype
);
7262 while Present
(Comp
) loop
7263 if No
(Component_Clause
(Comp
)) then
7265 ("missing component clause for &", CR_Pragma
, Comp
);
7268 Next_Component_Or_Discriminant
(Comp
);
7271 -- Give missing components warning if required
7273 elsif Warn_On_Unrepped_Components
then
7275 Num_Repped_Components
: Nat
:= 0;
7276 Num_Unrepped_Components
: Nat
:= 0;
7279 -- First count number of repped and unrepped components
7281 Comp
:= First_Component_Or_Discriminant
(Rectype
);
7282 while Present
(Comp
) loop
7283 if Present
(Component_Clause
(Comp
)) then
7284 Num_Repped_Components
:= Num_Repped_Components
+ 1;
7286 Num_Unrepped_Components
:= Num_Unrepped_Components
+ 1;
7289 Next_Component_Or_Discriminant
(Comp
);
7292 -- We are only interested in the case where there is at least one
7293 -- unrepped component, and at least half the components have rep
7294 -- clauses. We figure that if less than half have them, then the
7295 -- partial rep clause is really intentional. If the component
7296 -- type has no underlying type set at this point (as for a generic
7297 -- formal type), we don't know enough to give a warning on the
7300 if Num_Unrepped_Components
> 0
7301 and then Num_Unrepped_Components
< Num_Repped_Components
7303 Comp
:= First_Component_Or_Discriminant
(Rectype
);
7304 while Present
(Comp
) loop
7305 if No
(Component_Clause
(Comp
))
7306 and then Comes_From_Source
(Comp
)
7307 and then Present
(Underlying_Type
(Etype
(Comp
)))
7308 and then (Is_Scalar_Type
(Underlying_Type
(Etype
(Comp
)))
7309 or else Size_Known_At_Compile_Time
7310 (Underlying_Type
(Etype
(Comp
))))
7311 and then not Has_Warnings_Off
(Rectype
)
7313 -- Ignore discriminant in unchecked union, since it is
7314 -- not there, and cannot have a component clause.
7316 and then (not Is_Unchecked_Union
(Rectype
)
7317 or else Ekind
(Comp
) /= E_Discriminant
)
7319 Error_Msg_Sloc
:= Sloc
(Comp
);
7321 ("?C?no component clause given for & declared #",
7325 Next_Component_Or_Discriminant
(Comp
);
7330 end Analyze_Record_Representation_Clause
;
7332 -------------------------------------
7333 -- Build_Discrete_Static_Predicate --
7334 -------------------------------------
7336 procedure Build_Discrete_Static_Predicate
7341 Loc
: constant Source_Ptr
:= Sloc
(Expr
);
7343 Non_Static
: exception;
7344 -- Raised if something non-static is found
7346 Btyp
: constant Entity_Id
:= Base_Type
(Typ
);
7348 BLo
: constant Uint
:= Expr_Value
(Type_Low_Bound
(Btyp
));
7349 BHi
: constant Uint
:= Expr_Value
(Type_High_Bound
(Btyp
));
7350 -- Low bound and high bound value of base type of Typ
7354 -- Bounds for constructing the static predicate. We use the bound of the
7355 -- subtype if it is static, otherwise the corresponding base type bound.
7356 -- Note: a non-static subtype can have a static predicate.
7361 -- One entry in a Rlist value, a single REnt (range entry) value denotes
7362 -- one range from Lo to Hi. To represent a single value range Lo = Hi =
7365 type RList
is array (Nat
range <>) of REnt
;
7366 -- A list of ranges. The ranges are sorted in increasing order, and are
7367 -- disjoint (there is a gap of at least one value between each range in
7368 -- the table). A value is in the set of ranges in Rlist if it lies
7369 -- within one of these ranges.
7371 False_Range
: constant RList
:=
7372 RList
'(1 .. 0 => REnt'(No_Uint
, No_Uint
));
7373 -- An empty set of ranges represents a range list that can never be
7374 -- satisfied, since there are no ranges in which the value could lie,
7375 -- so it does not lie in any of them. False_Range is a canonical value
7376 -- for this empty set, but general processing should test for an Rlist
7377 -- with length zero (see Is_False predicate), since other null ranges
7378 -- may appear which must be treated as False.
7380 True_Range
: constant RList
:= RList
'(1 => REnt'(BLo
, BHi
));
7381 -- Range representing True, value must be in the base range
7383 function "and" (Left
: RList
; Right
: RList
) return RList
;
7384 -- And's together two range lists, returning a range list. This is a set
7385 -- intersection operation.
7387 function "or" (Left
: RList
; Right
: RList
) return RList
;
7388 -- Or's together two range lists, returning a range list. This is a set
7391 function "not" (Right
: RList
) return RList
;
7392 -- Returns complement of a given range list, i.e. a range list
7393 -- representing all the values in TLo .. THi that are not in the input
7396 function Build_Val
(V
: Uint
) return Node_Id
;
7397 -- Return an analyzed N_Identifier node referencing this value, suitable
7398 -- for use as an entry in the Static_Discrte_Predicate list. This node
7399 -- is typed with the base type.
7401 function Build_Range
(Lo
: Uint
; Hi
: Uint
) return Node_Id
;
7402 -- Return an analyzed N_Range node referencing this range, suitable for
7403 -- use as an entry in the Static_Discrete_Predicate list. This node is
7404 -- typed with the base type.
7406 function Get_RList
(Exp
: Node_Id
) return RList
;
7407 -- This is a recursive routine that converts the given expression into a
7408 -- list of ranges, suitable for use in building the static predicate.
7410 function Is_False
(R
: RList
) return Boolean;
7411 pragma Inline
(Is_False
);
7412 -- Returns True if the given range list is empty, and thus represents a
7413 -- False list of ranges that can never be satisfied.
7415 function Is_True
(R
: RList
) return Boolean;
7416 -- Returns True if R trivially represents the True predicate by having a
7417 -- single range from BLo to BHi.
7419 function Is_Type_Ref
(N
: Node_Id
) return Boolean;
7420 pragma Inline
(Is_Type_Ref
);
7421 -- Returns if True if N is a reference to the type for the predicate in
7422 -- the expression (i.e. if it is an identifier whose Chars field matches
7423 -- the Nam given in the call). N must not be parenthesized, if the type
7424 -- name appears in parens, this routine will return False.
7426 function Lo_Val
(N
: Node_Id
) return Uint
;
7427 -- Given an entry from a Static_Discrete_Predicate list that is either
7428 -- a static expression or static range, gets either the expression value
7429 -- or the low bound of the range.
7431 function Hi_Val
(N
: Node_Id
) return Uint
;
7432 -- Given an entry from a Static_Discrete_Predicate list that is either
7433 -- a static expression or static range, gets either the expression value
7434 -- or the high bound of the range.
7436 function Membership_Entry
(N
: Node_Id
) return RList
;
7437 -- Given a single membership entry (range, value, or subtype), returns
7438 -- the corresponding range list. Raises Static_Error if not static.
7440 function Membership_Entries
(N
: Node_Id
) return RList
;
7441 -- Given an element on an alternatives list of a membership operation,
7442 -- returns the range list corresponding to this entry and all following
7443 -- entries (i.e. returns the "or" of this list of values).
7445 function Stat_Pred
(Typ
: Entity_Id
) return RList
;
7446 -- Given a type, if it has a static predicate, then return the predicate
7447 -- as a range list, otherwise raise Non_Static.
7453 function "and" (Left
: RList
; Right
: RList
) return RList
is
7455 -- First range of result
7457 SLeft
: Nat
:= Left
'First;
7458 -- Start of rest of left entries
7460 SRight
: Nat
:= Right
'First;
7461 -- Start of rest of right entries
7464 -- If either range is True, return the other
7466 if Is_True
(Left
) then
7468 elsif Is_True
(Right
) then
7472 -- If either range is False, return False
7474 if Is_False
(Left
) or else Is_False
(Right
) then
7478 -- Loop to remove entries at start that are disjoint, and thus just
7479 -- get discarded from the result entirely.
7482 -- If no operands left in either operand, result is false
7484 if SLeft
> Left
'Last or else SRight
> Right
'Last then
7487 -- Discard first left operand entry if disjoint with right
7489 elsif Left
(SLeft
).Hi
< Right
(SRight
).Lo
then
7492 -- Discard first right operand entry if disjoint with left
7494 elsif Right
(SRight
).Hi
< Left
(SLeft
).Lo
then
7495 SRight
:= SRight
+ 1;
7497 -- Otherwise we have an overlapping entry
7504 -- Now we have two non-null operands, and first entries overlap. The
7505 -- first entry in the result will be the overlapping part of these
7508 FEnt
:= REnt
'(Lo => UI_Max (Left (SLeft).Lo, Right (SRight).Lo),
7509 Hi => UI_Min (Left (SLeft).Hi, Right (SRight).Hi));
7511 -- Now we can remove the entry that ended at a lower value, since its
7512 -- contribution is entirely contained in Fent.
7514 if Left (SLeft).Hi <= Right (SRight).Hi then
7517 SRight := SRight + 1;
7520 -- Compute result by concatenating this first entry with the "and" of
7521 -- the remaining parts of the left and right operands. Note that if
7522 -- either of these is empty, "and" will yield empty, so that we will
7523 -- end up with just Fent, which is what we want in that case.
7526 FEnt & (Left (SLeft .. Left'Last) and Right (SRight .. Right'Last));
7533 function "not" (Right : RList) return RList is
7535 -- Return True if False range
7537 if Is_False (Right) then
7541 -- Return False if True range
7543 if Is_True (Right) then
7547 -- Here if not trivial case
7550 Result : RList (1 .. Right'Length + 1);
7551 -- May need one more entry for gap at beginning and end
7554 -- Number of entries stored in Result
7559 if Right (Right'First).Lo > TLo then
7561 Result (Count) := REnt'(TLo
, Right
(Right
'First).Lo
- 1);
7564 -- Gaps between ranges
7566 for J
in Right
'First .. Right
'Last - 1 loop
7568 Result
(Count
) := REnt
'(Right (J).Hi + 1, Right (J + 1).Lo - 1);
7573 if Right (Right'Last).Hi < THi then
7575 Result (Count) := REnt'(Right
(Right
'Last).Hi
+ 1, THi
);
7578 return Result
(1 .. Count
);
7586 function "or" (Left
: RList
; Right
: RList
) return RList
is
7588 -- First range of result
7590 SLeft
: Nat
:= Left
'First;
7591 -- Start of rest of left entries
7593 SRight
: Nat
:= Right
'First;
7594 -- Start of rest of right entries
7597 -- If either range is True, return True
7599 if Is_True
(Left
) or else Is_True
(Right
) then
7603 -- If either range is False (empty), return the other
7605 if Is_False
(Left
) then
7607 elsif Is_False
(Right
) then
7611 -- Initialize result first entry from left or right operand depending
7612 -- on which starts with the lower range.
7614 if Left
(SLeft
).Lo
< Right
(SRight
).Lo
then
7615 FEnt
:= Left
(SLeft
);
7618 FEnt
:= Right
(SRight
);
7619 SRight
:= SRight
+ 1;
7622 -- This loop eats ranges from left and right operands that are
7623 -- contiguous with the first range we are gathering.
7626 -- Eat first entry in left operand if contiguous or overlapped by
7627 -- gathered first operand of result.
7629 if SLeft
<= Left
'Last
7630 and then Left
(SLeft
).Lo
<= FEnt
.Hi
+ 1
7632 FEnt
.Hi
:= UI_Max
(FEnt
.Hi
, Left
(SLeft
).Hi
);
7635 -- Eat first entry in right operand if contiguous or overlapped by
7636 -- gathered right operand of result.
7638 elsif SRight
<= Right
'Last
7639 and then Right
(SRight
).Lo
<= FEnt
.Hi
+ 1
7641 FEnt
.Hi
:= UI_Max
(FEnt
.Hi
, Right
(SRight
).Hi
);
7642 SRight
:= SRight
+ 1;
7644 -- All done if no more entries to eat
7651 -- Obtain result as the first entry we just computed, concatenated
7652 -- to the "or" of the remaining results (if one operand is empty,
7653 -- this will just concatenate with the other
7656 FEnt
& (Left
(SLeft
.. Left
'Last) or Right
(SRight
.. Right
'Last));
7663 function Build_Range
(Lo
: Uint
; Hi
: Uint
) return Node_Id
is
7668 Low_Bound
=> Build_Val
(Lo
),
7669 High_Bound
=> Build_Val
(Hi
));
7670 Set_Etype
(Result
, Btyp
);
7671 Set_Analyzed
(Result
);
7679 function Build_Val
(V
: Uint
) return Node_Id
is
7683 if Is_Enumeration_Type
(Typ
) then
7684 Result
:= Get_Enum_Lit_From_Pos
(Typ
, V
, Loc
);
7686 Result
:= Make_Integer_Literal
(Loc
, V
);
7689 Set_Etype
(Result
, Btyp
);
7690 Set_Is_Static_Expression
(Result
);
7691 Set_Analyzed
(Result
);
7699 function Get_RList
(Exp
: Node_Id
) return RList
is
7704 -- Static expression can only be true or false
7706 if Is_OK_Static_Expression
(Exp
) then
7707 if Expr_Value
(Exp
) = 0 then
7714 -- Otherwise test node type
7725 return Get_RList
(Left_Opnd
(Exp
))
7727 Get_RList
(Right_Opnd
(Exp
));
7734 return Get_RList
(Left_Opnd
(Exp
))
7736 Get_RList
(Right_Opnd
(Exp
));
7741 return not Get_RList
(Right_Opnd
(Exp
));
7743 -- Comparisons of type with static value
7745 when N_Op_Compare
=>
7747 -- Type is left operand
7749 if Is_Type_Ref
(Left_Opnd
(Exp
))
7750 and then Is_OK_Static_Expression
(Right_Opnd
(Exp
))
7752 Val
:= Expr_Value
(Right_Opnd
(Exp
));
7754 -- Typ is right operand
7756 elsif Is_Type_Ref
(Right_Opnd
(Exp
))
7757 and then Is_OK_Static_Expression
(Left_Opnd
(Exp
))
7759 Val
:= Expr_Value
(Left_Opnd
(Exp
));
7761 -- Invert sense of comparison
7764 when N_Op_Gt
=> Op
:= N_Op_Lt
;
7765 when N_Op_Lt
=> Op
:= N_Op_Gt
;
7766 when N_Op_Ge
=> Op
:= N_Op_Le
;
7767 when N_Op_Le
=> Op
:= N_Op_Ge
;
7768 when others => null;
7771 -- Other cases are non-static
7777 -- Construct range according to comparison operation
7781 return RList
'(1 => REnt'(Val
, Val
));
7784 return RList
'(1 => REnt'(Val
, BHi
));
7787 return RList
'(1 => REnt'(Val
+ 1, BHi
));
7790 return RList
'(1 => REnt'(BLo
, Val
));
7793 return RList
'(1 => REnt'(BLo
, Val
- 1));
7796 return RList
'(REnt'(BLo
, Val
- 1), REnt
'(Val + 1, BHi));
7799 raise Program_Error;
7805 if not Is_Type_Ref (Left_Opnd (Exp)) then
7809 if Present (Right_Opnd (Exp)) then
7810 return Membership_Entry (Right_Opnd (Exp));
7812 return Membership_Entries (First (Alternatives (Exp)));
7815 -- Negative membership (NOT IN)
7818 if not Is_Type_Ref (Left_Opnd (Exp)) then
7822 if Present (Right_Opnd (Exp)) then
7823 return not Membership_Entry (Right_Opnd (Exp));
7825 return not Membership_Entries (First (Alternatives (Exp)));
7828 -- Function call, may be call to static predicate
7830 when N_Function_Call =>
7831 if Is_Entity_Name (Name (Exp)) then
7833 Ent : constant Entity_Id := Entity (Name (Exp));
7835 if Is_Predicate_Function (Ent)
7837 Is_Predicate_Function_M (Ent)
7839 return Stat_Pred (Etype (First_Formal (Ent)));
7844 -- Other function call cases are non-static
7848 -- Qualified expression, dig out the expression
7850 when N_Qualified_Expression =>
7851 return Get_RList (Expression (Exp));
7853 when N_Case_Expression =>
7860 if not Is_Entity_Name (Expression (Expr))
7861 or else Etype (Expression (Expr)) /= Typ
7864 ("expression must denaote subtype", Expression (Expr));
7868 -- Collect discrete choices in all True alternatives
7870 Choices := New_List;
7871 Alt := First (Alternatives (Exp));
7872 while Present (Alt) loop
7873 Dep := Expression (Alt);
7875 if not Is_OK_Static_Expression (Dep) then
7878 elsif Is_True (Expr_Value (Dep)) then
7879 Append_List_To (Choices,
7880 New_Copy_List (Discrete_Choices (Alt)));
7886 return Membership_Entries (First (Choices));
7889 -- Expression with actions: if no actions, dig out expression
7891 when N_Expression_With_Actions =>
7892 if Is_Empty_List (Actions (Exp)) then
7893 return Get_RList (Expression (Exp));
7901 return (Get_RList (Left_Opnd (Exp))
7902 and not Get_RList (Right_Opnd (Exp)))
7903 or (Get_RList (Right_Opnd (Exp))
7904 and not Get_RList (Left_Opnd (Exp)));
7906 -- Any other node type is non-static
7917 function Hi_Val (N : Node_Id) return Uint is
7919 if Is_OK_Static_Expression (N) then
7920 return Expr_Value (N);
7922 pragma Assert (Nkind (N) = N_Range);
7923 return Expr_Value (High_Bound (N));
7931 function Is_False (R : RList) return Boolean is
7933 return R'Length = 0;
7940 function Is_True (R : RList) return Boolean is
7943 and then R (R'First).Lo = BLo
7944 and then R (R'First).Hi = BHi;
7951 function Is_Type_Ref (N : Node_Id) return Boolean is
7953 return Nkind (N) = N_Identifier
7954 and then Chars (N) = Nam
7955 and then Paren_Count (N) = 0;
7962 function Lo_Val (N : Node_Id) return Uint is
7964 if Is_OK_Static_Expression (N) then
7965 return Expr_Value (N);
7967 pragma Assert (Nkind (N) = N_Range);
7968 return Expr_Value (Low_Bound (N));
7972 ------------------------
7973 -- Membership_Entries --
7974 ------------------------
7976 function Membership_Entries (N : Node_Id) return RList is
7978 if No (Next (N)) then
7979 return Membership_Entry (N);
7981 return Membership_Entry (N) or Membership_Entries (Next (N));
7983 end Membership_Entries;
7985 ----------------------
7986 -- Membership_Entry --
7987 ----------------------
7989 function Membership_Entry (N : Node_Id) return RList is
7997 if Nkind (N) = N_Range then
7998 if not Is_OK_Static_Expression (Low_Bound (N))
8000 not Is_OK_Static_Expression (High_Bound (N))
8004 SLo := Expr_Value (Low_Bound (N));
8005 SHi := Expr_Value (High_Bound (N));
8006 return RList'(1 => REnt
'(SLo, SHi));
8009 -- Static expression case
8011 elsif Is_OK_Static_Expression (N) then
8012 Val := Expr_Value (N);
8013 return RList'(1 => REnt
'(Val, Val));
8015 -- Identifier (other than static expression) case
8017 else pragma Assert (Nkind (N) = N_Identifier);
8021 if Is_Type (Entity (N)) then
8023 -- If type has predicates, process them
8025 if Has_Predicates (Entity (N)) then
8026 return Stat_Pred (Entity (N));
8028 -- For static subtype without predicates, get range
8030 elsif Is_OK_Static_Subtype (Entity (N)) then
8031 SLo := Expr_Value (Type_Low_Bound (Entity (N)));
8032 SHi := Expr_Value (Type_High_Bound (Entity (N)));
8033 return RList'(1 => REnt
'(SLo, SHi));
8035 -- Any other type makes us non-static
8041 -- Any other kind of identifier in predicate (e.g. a non-static
8042 -- expression value) means this is not a static predicate.
8048 end Membership_Entry;
8054 function Stat_Pred (Typ : Entity_Id) return RList is
8056 -- Not static if type does not have static predicates
8058 if not Has_Static_Predicate (Typ) then
8062 -- Otherwise we convert the predicate list to a range list
8065 Spred : constant List_Id := Static_Discrete_Predicate (Typ);
8066 Result : RList (1 .. List_Length (Spred));
8070 P := First (Static_Discrete_Predicate (Typ));
8071 for J in Result'Range loop
8072 Result (J) := REnt'(Lo_Val
(P
), Hi_Val
(P
));
8080 -- Start of processing for Build_Discrete_Static_Predicate
8083 -- Establish bounds for the predicate
8085 if Compile_Time_Known_Value
(Type_Low_Bound
(Typ
)) then
8086 TLo
:= Expr_Value
(Type_Low_Bound
(Typ
));
8091 if Compile_Time_Known_Value
(Type_High_Bound
(Typ
)) then
8092 THi
:= Expr_Value
(Type_High_Bound
(Typ
));
8097 -- Analyze the expression to see if it is a static predicate
8100 Ranges
: constant RList
:= Get_RList
(Expr
);
8101 -- Range list from expression if it is static
8106 -- Convert range list into a form for the static predicate. In the
8107 -- Ranges array, we just have raw ranges, these must be converted
8108 -- to properly typed and analyzed static expressions or range nodes.
8110 -- Note: here we limit ranges to the ranges of the subtype, so that
8111 -- a predicate is always false for values outside the subtype. That
8112 -- seems fine, such values are invalid anyway, and considering them
8113 -- to fail the predicate seems allowed and friendly, and furthermore
8114 -- simplifies processing for case statements and loops.
8118 for J
in Ranges
'Range loop
8120 Lo
: Uint
:= Ranges
(J
).Lo
;
8121 Hi
: Uint
:= Ranges
(J
).Hi
;
8124 -- Ignore completely out of range entry
8126 if Hi
< TLo
or else Lo
> THi
then
8129 -- Otherwise process entry
8132 -- Adjust out of range value to subtype range
8142 -- Convert range into required form
8144 Append_To
(Plist
, Build_Range
(Lo
, Hi
));
8149 -- Processing was successful and all entries were static, so now we
8150 -- can store the result as the predicate list.
8152 Set_Static_Discrete_Predicate
(Typ
, Plist
);
8154 -- The processing for static predicates put the expression into
8155 -- canonical form as a series of ranges. It also eliminated
8156 -- duplicates and collapsed and combined ranges. We might as well
8157 -- replace the alternatives list of the right operand of the
8158 -- membership test with the static predicate list, which will
8159 -- usually be more efficient.
8162 New_Alts
: constant List_Id
:= New_List
;
8167 Old_Node
:= First
(Plist
);
8168 while Present
(Old_Node
) loop
8169 New_Node
:= New_Copy
(Old_Node
);
8171 if Nkind
(New_Node
) = N_Range
then
8172 Set_Low_Bound
(New_Node
, New_Copy
(Low_Bound
(Old_Node
)));
8173 Set_High_Bound
(New_Node
, New_Copy
(High_Bound
(Old_Node
)));
8176 Append_To
(New_Alts
, New_Node
);
8180 -- If empty list, replace by False
8182 if Is_Empty_List
(New_Alts
) then
8183 Rewrite
(Expr
, New_Occurrence_Of
(Standard_False
, Loc
));
8185 -- Else replace by set membership test
8190 Left_Opnd
=> Make_Identifier
(Loc
, Nam
),
8191 Right_Opnd
=> Empty
,
8192 Alternatives
=> New_Alts
));
8194 -- Resolve new expression in function context
8196 Install_Formals
(Predicate_Function
(Typ
));
8197 Push_Scope
(Predicate_Function
(Typ
));
8198 Analyze_And_Resolve
(Expr
, Standard_Boolean
);
8204 -- If non-static, return doing nothing
8209 end Build_Discrete_Static_Predicate
;
8211 --------------------------------
8212 -- Build_Export_Import_Pragma --
8213 --------------------------------
8215 function Build_Export_Import_Pragma
8217 Id
: Entity_Id
) return Node_Id
8219 Asp_Id
: constant Aspect_Id
:= Get_Aspect_Id
(Asp
);
8220 Expr
: constant Node_Id
:= Expression
(Asp
);
8221 Loc
: constant Source_Ptr
:= Sloc
(Asp
);
8232 Create_Pragma
: Boolean := False;
8233 -- This flag is set when the aspect form is such that it warrants the
8234 -- creation of a corresponding pragma.
8237 if Present
(Expr
) then
8238 if Error_Posted
(Expr
) then
8241 elsif Is_True
(Expr_Value
(Expr
)) then
8242 Create_Pragma
:= True;
8245 -- Otherwise the aspect defaults to True
8248 Create_Pragma
:= True;
8251 -- Nothing to do when the expression is False or is erroneous
8253 if not Create_Pragma
then
8257 -- Obtain all interfacing aspects that apply to the related entity
8259 Get_Interfacing_Aspects
8263 Expo_Asp
=> Dummy_1
,
8269 -- Handle the convention argument
8271 if Present
(Conv
) then
8272 Conv_Arg
:= New_Copy_Tree
(Expression
(Conv
));
8274 -- Assume convention "Ada' when aspect Convention is missing
8277 Conv_Arg
:= Make_Identifier
(Loc
, Name_Ada
);
8281 Make_Pragma_Argument_Association
(Loc
,
8282 Chars
=> Name_Convention
,
8283 Expression
=> Conv_Arg
));
8285 -- Handle the entity argument
8288 Make_Pragma_Argument_Association
(Loc
,
8289 Chars
=> Name_Entity
,
8290 Expression
=> New_Occurrence_Of
(Id
, Loc
)));
8292 -- Handle the External_Name argument
8294 if Present
(EN
) then
8296 Make_Pragma_Argument_Association
(Loc
,
8297 Chars
=> Name_External_Name
,
8298 Expression
=> New_Copy_Tree
(Expression
(EN
))));
8301 -- Handle the Link_Name argument
8303 if Present
(LN
) then
8305 Make_Pragma_Argument_Association
(Loc
,
8306 Chars
=> Name_Link_Name
,
8307 Expression
=> New_Copy_Tree
(Expression
(LN
))));
8311 -- pragma Export/Import
8312 -- (Convention => <Conv>/Ada,
8314 -- [External_Name => <EN>,]
8315 -- [Link_Name => <LN>]);
8319 Pragma_Identifier
=>
8320 Make_Identifier
(Loc
, Chars
(Identifier
(Asp
))),
8321 Pragma_Argument_Associations
=> Args
);
8323 -- Decorate the relevant aspect and the pragma
8325 Set_Aspect_Rep_Item
(Asp
, Prag
);
8327 Set_Corresponding_Aspect
(Prag
, Asp
);
8328 Set_From_Aspect_Specification
(Prag
);
8329 Set_Parent
(Prag
, Asp
);
8331 if Asp_Id
= Aspect_Import
and then Is_Subprogram
(Id
) then
8332 Set_Import_Pragma
(Id
, Prag
);
8336 end Build_Export_Import_Pragma
;
8338 -------------------------------
8339 -- Build_Predicate_Functions --
8340 -------------------------------
8342 -- The procedures that are constructed here have the form:
8344 -- function typPredicate (Ixxx : typ) return Boolean is
8347 -- typ1Predicate (typ1 (Ixxx))
8348 -- and then typ2Predicate (typ2 (Ixxx))
8350 -- exp1 and then exp2 and then ...
8351 -- end typPredicate;
8353 -- Here exp1, and exp2 are expressions from Predicate pragmas. Note that
8354 -- this is the point at which these expressions get analyzed, providing the
8355 -- required delay, and typ1, typ2, are entities from which predicates are
8356 -- inherited. Note that we do NOT generate Check pragmas, that's because we
8357 -- use this function even if checks are off, e.g. for membership tests.
8359 -- Note that the inherited predicates are evaluated first, as required by
8362 -- Note that Sem_Eval.Real_Or_String_Static_Predicate_Matches depends on
8363 -- the form of this return expression.
8365 -- If the expression has at least one Raise_Expression, then we also build
8366 -- the typPredicateM version of the function, in which any occurrence of a
8367 -- Raise_Expression is converted to "return False".
8369 -- WARNING: This routine manages Ghost regions. Return statements must be
8370 -- replaced by gotos which jump to the end of the routine and restore the
8373 procedure Build_Predicate_Functions
(Typ
: Entity_Id
; N
: Node_Id
) is
8374 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
8377 -- This is the expression for the result of the function. It is
8378 -- is build by connecting the component predicates with AND THEN.
8381 -- This is the corresponding return expression for the Predicate_M
8382 -- function. It differs in that raise expressions are marked for
8383 -- special expansion (see Process_REs).
8385 Object_Name
: Name_Id
;
8386 -- Name for argument of Predicate procedure. Note that we use the same
8387 -- name for both predicate functions. That way the reference within the
8388 -- predicate expression is the same in both functions.
8390 Object_Entity
: Entity_Id
;
8391 -- Entity for argument of Predicate procedure
8393 Object_Entity_M
: Entity_Id
;
8394 -- Entity for argument of separate Predicate procedure when exceptions
8395 -- are present in expression.
8398 -- The function declaration
8403 Raise_Expression_Present
: Boolean := False;
8404 -- Set True if Expr has at least one Raise_Expression
8406 procedure Add_Condition
(Cond
: Node_Id
);
8407 -- Append Cond to Expr using "and then" (or just copy Cond to Expr if
8410 procedure Add_Predicates
;
8411 -- Appends expressions for any Predicate pragmas in the rep item chain
8412 -- Typ to Expr. Note that we look only at items for this exact entity.
8413 -- Inheritance of predicates for the parent type is done by calling the
8414 -- Predicate_Function of the parent type, using Add_Call above.
8416 procedure Add_Call
(T
: Entity_Id
);
8417 -- Includes a call to the predicate function for type T in Expr if T
8418 -- has predicates and Predicate_Function (T) is non-empty.
8420 function Process_RE
(N
: Node_Id
) return Traverse_Result
;
8421 -- Used in Process REs, tests if node N is a raise expression, and if
8422 -- so, marks it to be converted to return False.
8424 procedure Process_REs
is new Traverse_Proc
(Process_RE
);
8425 -- Marks any raise expressions in Expr_M to return False
8427 function Test_RE
(N
: Node_Id
) return Traverse_Result
;
8428 -- Used in Test_REs, tests one node for being a raise expression, and if
8429 -- so sets Raise_Expression_Present True.
8431 procedure Test_REs
is new Traverse_Proc
(Test_RE
);
8432 -- Tests to see if Expr contains any raise expressions
8438 procedure Add_Call
(T
: Entity_Id
) is
8442 if Present
(T
) and then Present
(Predicate_Function
(T
)) then
8443 Set_Has_Predicates
(Typ
);
8445 -- Build the call to the predicate function of T. The type may be
8446 -- derived, so use an unchecked conversion for the actual.
8452 Unchecked_Convert_To
(T
,
8453 Make_Identifier
(Loc
, Object_Name
)));
8455 -- "and"-in the call to evolving expression
8457 Add_Condition
(Exp
);
8459 -- Output info message on inheritance if required. Note we do not
8460 -- give this information for generic actual types, since it is
8461 -- unwelcome noise in that case in instantiations. We also
8462 -- generally suppress the message in instantiations, and also
8463 -- if it involves internal names.
8465 if Opt
.List_Inherited_Aspects
8466 and then not Is_Generic_Actual_Type
(Typ
)
8467 and then Instantiation_Depth
(Sloc
(Typ
)) = 0
8468 and then not Is_Internal_Name
(Chars
(T
))
8469 and then not Is_Internal_Name
(Chars
(Typ
))
8471 Error_Msg_Sloc
:= Sloc
(Predicate_Function
(T
));
8472 Error_Msg_Node_2
:= T
;
8473 Error_Msg_N
("info: & inherits predicate from & #?L?", Typ
);
8482 procedure Add_Condition
(Cond
: Node_Id
) is
8484 -- This is the first predicate expression
8489 -- Otherwise concatenate to the existing predicate expressions by
8490 -- using "and then".
8495 Left_Opnd
=> Relocate_Node
(Expr
),
8496 Right_Opnd
=> Cond
);
8500 --------------------
8501 -- Add_Predicates --
8502 --------------------
8504 procedure Add_Predicates
is
8505 procedure Add_Predicate
(Prag
: Node_Id
);
8506 -- Concatenate the expression of predicate pragma Prag to Expr by
8507 -- using a short circuit "and then" operator.
8513 procedure Add_Predicate
(Prag
: Node_Id
) is
8514 procedure Replace_Type_Reference
(N
: Node_Id
);
8515 -- Replace a single occurrence N of the subtype name with a
8516 -- reference to the formal of the predicate function. N can be an
8517 -- identifier referencing the subtype, or a selected component,
8518 -- representing an appropriately qualified occurrence of the
8521 procedure Replace_Type_References
is
8522 new Replace_Type_References_Generic
(Replace_Type_Reference
);
8523 -- Traverse an expression changing every occurrence of an
8524 -- identifier whose name matches the name of the subtype with a
8525 -- reference to the formal parameter of the predicate function.
8527 ----------------------------
8528 -- Replace_Type_Reference --
8529 ----------------------------
8531 procedure Replace_Type_Reference
(N
: Node_Id
) is
8533 Rewrite
(N
, Make_Identifier
(Sloc
(N
), Object_Name
));
8534 -- Use the Sloc of the usage name, not the defining name
8537 Set_Entity
(N
, Object_Entity
);
8539 -- We want to treat the node as if it comes from source, so
8540 -- that ASIS will not ignore it.
8542 Set_Comes_From_Source
(N
, True);
8543 end Replace_Type_Reference
;
8547 Asp
: constant Node_Id
:= Corresponding_Aspect
(Prag
);
8551 -- Start of processing for Add_Predicate
8554 -- Mark corresponding SCO as enabled
8556 Set_SCO_Pragma_Enabled
(Sloc
(Prag
));
8558 -- Extract the arguments of the pragma. The expression itself
8559 -- is copied for use in the predicate function, to preserve the
8560 -- original version for ASIS use.
8562 Arg1
:= First
(Pragma_Argument_Associations
(Prag
));
8563 Arg2
:= Next
(Arg1
);
8565 Arg1
:= Get_Pragma_Arg
(Arg1
);
8566 Arg2
:= New_Copy_Tree
(Get_Pragma_Arg
(Arg2
));
8568 -- When the predicate pragma applies to the current type or its
8569 -- full view, replace all occurrences of the subtype name with
8570 -- references to the formal parameter of the predicate function.
8572 if Entity
(Arg1
) = Typ
8573 or else Full_View
(Entity
(Arg1
)) = Typ
8575 Replace_Type_References
(Arg2
, Typ
);
8577 -- If the predicate pragma comes from an aspect, replace the
8578 -- saved expression because we need the subtype references
8579 -- replaced for the calls to Preanalyze_Spec_Expression in
8580 -- Check_Aspect_At_xxx routines.
8582 if Present
(Asp
) then
8583 Set_Entity
(Identifier
(Asp
), New_Copy_Tree
(Arg2
));
8586 -- "and"-in the Arg2 condition to evolving expression
8588 Add_Condition
(Relocate_Node
(Arg2
));
8596 -- Start of processing for Add_Predicates
8599 Ritem
:= First_Rep_Item
(Typ
);
8601 -- If the type is private, check whether full view has inherited
8604 if Is_Private_Type
(Typ
) and then No
(Ritem
) then
8605 Ritem
:= First_Rep_Item
(Full_View
(Typ
));
8608 while Present
(Ritem
) loop
8609 if Nkind
(Ritem
) = N_Pragma
8610 and then Pragma_Name
(Ritem
) = Name_Predicate
8612 Add_Predicate
(Ritem
);
8614 -- If the type is declared in an inner package it may be frozen
8615 -- outside of the package, and the generated pragma has not been
8616 -- analyzed yet, so capture the expression for the predicate
8617 -- function at this point.
8619 elsif Nkind
(Ritem
) = N_Aspect_Specification
8620 and then Present
(Aspect_Rep_Item
(Ritem
))
8621 and then Scope
(Typ
) /= Current_Scope
8624 Prag
: constant Node_Id
:= Aspect_Rep_Item
(Ritem
);
8627 if Nkind
(Prag
) = N_Pragma
8628 and then Pragma_Name
(Prag
) = Name_Predicate
8630 Add_Predicate
(Prag
);
8635 Next_Rep_Item
(Ritem
);
8643 function Process_RE
(N
: Node_Id
) return Traverse_Result
is
8645 if Nkind
(N
) = N_Raise_Expression
then
8646 Set_Convert_To_Return_False
(N
);
8657 function Test_RE
(N
: Node_Id
) return Traverse_Result
is
8659 if Nkind
(N
) = N_Raise_Expression
then
8660 Raise_Expression_Present
:= True;
8669 Saved_GM
: constant Ghost_Mode_Type
:= Ghost_Mode
;
8670 -- Save the Ghost mode to restore on exit
8672 -- Start of processing for Build_Predicate_Functions
8675 -- Return if already built or if type does not have predicates
8677 SId
:= Predicate_Function
(Typ
);
8678 if not Has_Predicates
(Typ
)
8679 or else (Present
(SId
) and then Has_Completion
(SId
))
8684 -- The related type may be subject to pragma Ghost. Set the mode now to
8685 -- ensure that the predicate functions are properly marked as Ghost.
8687 Set_Ghost_Mode
(Typ
);
8689 -- Prepare to construct predicate expression
8693 if Present
(SId
) then
8694 FDecl
:= Unit_Declaration_Node
(SId
);
8697 FDecl
:= Build_Predicate_Function_Declaration
(Typ
);
8698 SId
:= Defining_Entity
(FDecl
);
8701 -- Recover name of formal parameter of function that replaces references
8702 -- to the type in predicate expressions.
8706 (First
(Parameter_Specifications
(Specification
(FDecl
))));
8708 Object_Name
:= Chars
(Object_Entity
);
8709 Object_Entity_M
:= Make_Defining_Identifier
(Loc
, Chars
=> Object_Name
);
8711 -- Add predicates for ancestor if present. These must come before the
8712 -- ones for the current type, as required by AI12-0071-1.
8717 Atyp
:= Nearest_Ancestor
(Typ
);
8719 -- The type may be private but the full view may inherit predicates
8721 if No
(Atyp
) and then Is_Private_Type
(Typ
) then
8722 Atyp
:= Nearest_Ancestor
(Full_View
(Typ
));
8725 if Present
(Atyp
) then
8730 -- Add Predicates for the current type
8734 -- Case where predicates are present
8736 if Present
(Expr
) then
8738 -- Test for raise expression present
8742 -- If raise expression is present, capture a copy of Expr for use
8743 -- in building the predicateM function version later on. For this
8744 -- copy we replace references to Object_Entity by Object_Entity_M.
8746 if Raise_Expression_Present
then
8748 Map
: constant Elist_Id
:= New_Elmt_List
;
8749 New_V
: Entity_Id
:= Empty
;
8751 -- The unanalyzed expression will be copied and appear in
8752 -- both functions. Normally expressions do not declare new
8753 -- entities, but quantified expressions do, so we need to
8754 -- create new entities for their bound variables, to prevent
8755 -- multiple definitions in gigi.
8757 function Reset_Loop_Variable
(N
: Node_Id
)
8758 return Traverse_Result
;
8760 procedure Collect_Loop_Variables
is
8761 new Traverse_Proc
(Reset_Loop_Variable
);
8763 ------------------------
8764 -- Reset_Loop_Variable --
8765 ------------------------
8767 function Reset_Loop_Variable
(N
: Node_Id
)
8768 return Traverse_Result
8771 if Nkind
(N
) = N_Iterator_Specification
then
8772 New_V
:= Make_Defining_Identifier
8773 (Sloc
(N
), Chars
(Defining_Identifier
(N
)));
8775 Set_Defining_Identifier
(N
, New_V
);
8779 end Reset_Loop_Variable
;
8782 Append_Elmt
(Object_Entity
, Map
);
8783 Append_Elmt
(Object_Entity_M
, Map
);
8784 Expr_M
:= New_Copy_Tree
(Expr
, Map
=> Map
);
8785 Collect_Loop_Variables
(Expr_M
);
8789 -- Build the main predicate function
8792 SIdB
: constant Entity_Id
:=
8793 Make_Defining_Identifier
(Loc
,
8794 Chars
=> New_External_Name
(Chars
(Typ
), "Predicate"));
8795 -- The entity for the function body
8801 Set_Ekind
(SIdB
, E_Function
);
8802 Set_Is_Predicate_Function
(SIdB
);
8804 -- The predicate function is shared between views of a type
8806 if Is_Private_Type
(Typ
) and then Present
(Full_View
(Typ
)) then
8807 Set_Predicate_Function
(Full_View
(Typ
), SId
);
8810 -- Build function body
8813 Make_Function_Specification
(Loc
,
8814 Defining_Unit_Name
=> SIdB
,
8815 Parameter_Specifications
=> New_List
(
8816 Make_Parameter_Specification
(Loc
,
8817 Defining_Identifier
=>
8818 Make_Defining_Identifier
(Loc
, Object_Name
),
8820 New_Occurrence_Of
(Typ
, Loc
))),
8821 Result_Definition
=>
8822 New_Occurrence_Of
(Standard_Boolean
, Loc
));
8825 Make_Subprogram_Body
(Loc
,
8826 Specification
=> Spec
,
8827 Declarations
=> Empty_List
,
8828 Handled_Statement_Sequence
=>
8829 Make_Handled_Sequence_Of_Statements
(Loc
,
8830 Statements
=> New_List
(
8831 Make_Simple_Return_Statement
(Loc
,
8832 Expression
=> Expr
))));
8834 -- If declaration has not been analyzed yet, Insert declaration
8835 -- before freeze node. Insert body itself after freeze node.
8837 if not Analyzed
(FDecl
) then
8838 Insert_Before_And_Analyze
(N
, FDecl
);
8841 Insert_After_And_Analyze
(N
, FBody
);
8843 -- Static predicate functions are always side-effect free, and
8844 -- in most cases dynamic predicate functions are as well. Mark
8845 -- them as such whenever possible, so redundant predicate checks
8846 -- can be optimized. If there is a variable reference within the
8847 -- expression, the function is not pure.
8849 if Expander_Active
then
8851 Side_Effect_Free
(Expr
, Variable_Ref
=> True));
8852 Set_Is_Inlined
(SId
);
8856 -- Test for raise expressions present and if so build M version
8858 if Raise_Expression_Present
then
8860 SId
: constant Entity_Id
:=
8861 Make_Defining_Identifier
(Loc
,
8862 Chars
=> New_External_Name
(Chars
(Typ
), "PredicateM"));
8863 -- The entity for the function spec
8865 SIdB
: constant Entity_Id
:=
8866 Make_Defining_Identifier
(Loc
,
8867 Chars
=> New_External_Name
(Chars
(Typ
), "PredicateM"));
8868 -- The entity for the function body
8876 -- Mark any raise expressions for special expansion
8878 Process_REs
(Expr_M
);
8880 -- Build function declaration
8882 Set_Ekind
(SId
, E_Function
);
8883 Set_Is_Predicate_Function_M
(SId
);
8884 Set_Predicate_Function_M
(Typ
, SId
);
8886 -- The predicate function is shared between views of a type
8888 if Is_Private_Type
(Typ
) and then Present
(Full_View
(Typ
)) then
8889 Set_Predicate_Function_M
(Full_View
(Typ
), SId
);
8893 Make_Function_Specification
(Loc
,
8894 Defining_Unit_Name
=> SId
,
8895 Parameter_Specifications
=> New_List
(
8896 Make_Parameter_Specification
(Loc
,
8897 Defining_Identifier
=> Object_Entity_M
,
8898 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
))),
8899 Result_Definition
=>
8900 New_Occurrence_Of
(Standard_Boolean
, Loc
));
8903 Make_Subprogram_Declaration
(Loc
,
8904 Specification
=> Spec
);
8906 -- Build function body
8909 Make_Function_Specification
(Loc
,
8910 Defining_Unit_Name
=> SIdB
,
8911 Parameter_Specifications
=> New_List
(
8912 Make_Parameter_Specification
(Loc
,
8913 Defining_Identifier
=>
8914 Make_Defining_Identifier
(Loc
, Object_Name
),
8916 New_Occurrence_Of
(Typ
, Loc
))),
8917 Result_Definition
=>
8918 New_Occurrence_Of
(Standard_Boolean
, Loc
));
8920 -- Build the body, we declare the boolean expression before
8921 -- doing the return, because we are not really confident of
8922 -- what happens if a return appears within a return.
8925 Make_Defining_Identifier
(Loc
,
8926 Chars
=> New_Internal_Name
('B'));
8929 Make_Subprogram_Body
(Loc
,
8930 Specification
=> Spec
,
8932 Declarations
=> New_List
(
8933 Make_Object_Declaration
(Loc
,
8934 Defining_Identifier
=> BTemp
,
8935 Constant_Present
=> True,
8936 Object_Definition
=>
8937 New_Occurrence_Of
(Standard_Boolean
, Loc
),
8938 Expression
=> Expr_M
)),
8940 Handled_Statement_Sequence
=>
8941 Make_Handled_Sequence_Of_Statements
(Loc
,
8942 Statements
=> New_List
(
8943 Make_Simple_Return_Statement
(Loc
,
8944 Expression
=> New_Occurrence_Of
(BTemp
, Loc
)))));
8946 -- Insert declaration before freeze node and body after
8948 Insert_Before_And_Analyze
(N
, FDecl
);
8949 Insert_After_And_Analyze
(N
, FBody
);
8953 -- See if we have a static predicate. Note that the answer may be
8954 -- yes even if we have an explicit Dynamic_Predicate present.
8961 if not Is_Scalar_Type
(Typ
) and then not Is_String_Type
(Typ
) then
8964 PS
:= Is_Predicate_Static
(Expr
, Object_Name
);
8967 -- Case where we have a predicate-static aspect
8971 -- We don't set Has_Static_Predicate_Aspect, since we can have
8972 -- any of the three cases (Predicate, Dynamic_Predicate, or
8973 -- Static_Predicate) generating a predicate with an expression
8974 -- that is predicate-static. We just indicate that we have a
8975 -- predicate that can be treated as static.
8977 Set_Has_Static_Predicate
(Typ
);
8979 -- For discrete subtype, build the static predicate list
8981 if Is_Discrete_Type
(Typ
) then
8982 Build_Discrete_Static_Predicate
(Typ
, Expr
, Object_Name
);
8984 -- If we don't get a static predicate list, it means that we
8985 -- have a case where this is not possible, most typically in
8986 -- the case where we inherit a dynamic predicate. We do not
8987 -- consider this an error, we just leave the predicate as
8988 -- dynamic. But if we do succeed in building the list, then
8989 -- we mark the predicate as static.
8991 if No
(Static_Discrete_Predicate
(Typ
)) then
8992 Set_Has_Static_Predicate
(Typ
, False);
8995 -- For real or string subtype, save predicate expression
8997 elsif Is_Real_Type
(Typ
) or else Is_String_Type
(Typ
) then
8998 Set_Static_Real_Or_String_Predicate
(Typ
, Expr
);
9001 -- Case of dynamic predicate (expression is not predicate-static)
9004 -- Again, we don't set Has_Dynamic_Predicate_Aspect, since that
9005 -- is only set if we have an explicit Dynamic_Predicate aspect
9006 -- given. Here we may simply have a Predicate aspect where the
9007 -- expression happens not to be predicate-static.
9009 -- Emit an error when the predicate is categorized as static
9010 -- but its expression is not predicate-static.
9012 -- First a little fiddling to get a nice location for the
9013 -- message. If the expression is of the form (A and then B),
9014 -- where A is an inherited predicate, then use the right
9015 -- operand for the Sloc. This avoids getting confused by a call
9016 -- to an inherited predicate with a less convenient source
9020 while Nkind
(EN
) = N_And_Then
9021 and then Nkind
(Left_Opnd
(EN
)) = N_Function_Call
9022 and then Is_Predicate_Function
9023 (Entity
(Name
(Left_Opnd
(EN
))))
9025 EN
:= Right_Opnd
(EN
);
9028 -- Now post appropriate message
9030 if Has_Static_Predicate_Aspect
(Typ
) then
9031 if Is_Scalar_Type
(Typ
) or else Is_String_Type
(Typ
) then
9033 ("expression is not predicate-static (RM 3.2.4(16-22))",
9037 ("static predicate requires scalar or string type", EN
);
9044 Restore_Ghost_Mode
(Saved_GM
);
9045 end Build_Predicate_Functions
;
9047 ------------------------------------------
9048 -- Build_Predicate_Function_Declaration --
9049 ------------------------------------------
9051 -- WARNING: This routine manages Ghost regions. Return statements must be
9052 -- replaced by gotos which jump to the end of the routine and restore the
9055 function Build_Predicate_Function_Declaration
9056 (Typ
: Entity_Id
) return Node_Id
9058 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
9060 Saved_GM
: constant Ghost_Mode_Type
:= Ghost_Mode
;
9061 -- Save the Ghost mode to restore on exit
9063 Func_Decl
: Node_Id
;
9064 Func_Id
: Entity_Id
;
9068 -- The related type may be subject to pragma Ghost. Set the mode now to
9069 -- ensure that the predicate functions are properly marked as Ghost.
9071 Set_Ghost_Mode
(Typ
);
9074 Make_Defining_Identifier
(Loc
,
9075 Chars
=> New_External_Name
(Chars
(Typ
), "Predicate"));
9077 -- The predicate function requires debug info when the predicates are
9078 -- subject to Source Coverage Obligations.
9080 if Opt
.Generate_SCO
then
9081 Set_Debug_Info_Needed
(Func_Id
);
9085 Make_Function_Specification
(Loc
,
9086 Defining_Unit_Name
=> Func_Id
,
9087 Parameter_Specifications
=> New_List
(
9088 Make_Parameter_Specification
(Loc
,
9089 Defining_Identifier
=> Make_Temporary
(Loc
, 'I'),
9090 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
))),
9091 Result_Definition
=>
9092 New_Occurrence_Of
(Standard_Boolean
, Loc
));
9094 Func_Decl
:= Make_Subprogram_Declaration
(Loc
, Specification
=> Spec
);
9096 Set_Ekind
(Func_Id
, E_Function
);
9097 Set_Etype
(Func_Id
, Standard_Boolean
);
9098 Set_Is_Internal
(Func_Id
);
9099 Set_Is_Predicate_Function
(Func_Id
);
9100 Set_Predicate_Function
(Typ
, Func_Id
);
9102 Insert_After
(Parent
(Typ
), Func_Decl
);
9103 Analyze
(Func_Decl
);
9105 Restore_Ghost_Mode
(Saved_GM
);
9108 end Build_Predicate_Function_Declaration
;
9110 -----------------------------------------
9111 -- Check_Aspect_At_End_Of_Declarations --
9112 -----------------------------------------
9114 procedure Check_Aspect_At_End_Of_Declarations
(ASN
: Node_Id
) is
9115 Ent
: constant Entity_Id
:= Entity
(ASN
);
9116 Ident
: constant Node_Id
:= Identifier
(ASN
);
9117 A_Id
: constant Aspect_Id
:= Get_Aspect_Id
(Chars
(Ident
));
9119 End_Decl_Expr
: constant Node_Id
:= Entity
(Ident
);
9120 -- Expression to be analyzed at end of declarations
9122 Freeze_Expr
: constant Node_Id
:= Expression
(ASN
);
9123 -- Expression from call to Check_Aspect_At_Freeze_Point.
9125 T
: constant Entity_Id
:= Etype
(Original_Node
(Freeze_Expr
));
9126 -- Type required for preanalyze call. We use the original expression to
9127 -- get the proper type, to prevent cascaded errors when the expression
9128 -- is constant-folded.
9131 -- Set False if error
9133 -- On entry to this procedure, Entity (Ident) contains a copy of the
9134 -- original expression from the aspect, saved for this purpose, and
9135 -- but Expression (Ident) is a preanalyzed copy of the expression,
9136 -- preanalyzed just after the freeze point.
9138 procedure Check_Overloaded_Name
;
9139 -- For aspects whose expression is simply a name, this routine checks if
9140 -- the name is overloaded or not. If so, it verifies there is an
9141 -- interpretation that matches the entity obtained at the freeze point,
9142 -- otherwise the compiler complains.
9144 ---------------------------
9145 -- Check_Overloaded_Name --
9146 ---------------------------
9148 procedure Check_Overloaded_Name
is
9150 if not Is_Overloaded
(End_Decl_Expr
) then
9151 Err
:= not Is_Entity_Name
(End_Decl_Expr
)
9152 or else Entity
(End_Decl_Expr
) /= Entity
(Freeze_Expr
);
9158 Index
: Interp_Index
;
9162 Get_First_Interp
(End_Decl_Expr
, Index
, It
);
9163 while Present
(It
.Typ
) loop
9164 if It
.Nam
= Entity
(Freeze_Expr
) then
9169 Get_Next_Interp
(Index
, It
);
9173 end Check_Overloaded_Name
;
9175 -- Start of processing for Check_Aspect_At_End_Of_Declarations
9178 -- In an instance we do not perform the consistency check between freeze
9179 -- point and end of declarations, because it was done already in the
9180 -- analysis of the generic. Furthermore, the delayed analysis of an
9181 -- aspect of the instance may produce spurious errors when the generic
9182 -- is a child unit that references entities in the parent (which might
9183 -- not be in scope at the freeze point of the instance).
9188 -- The enclosing scope may have been rewritten during expansion (.e.g. a
9189 -- task body is rewritten as a procedure) after this conformance check
9190 -- has been performed, so do not perform it again (it may not easily be
9191 -- done if full visibility of local entities is not available).
9193 elsif not Comes_From_Source
(Current_Scope
) then
9196 -- Case of aspects Dimension, Dimension_System and Synchronization
9198 elsif A_Id
= Aspect_Synchronization
then
9201 -- Case of stream attributes, just have to compare entities. However,
9202 -- the expression is just a name (possibly overloaded), and there may
9203 -- be stream operations declared for unrelated types, so we just need
9204 -- to verify that one of these interpretations is the one available at
9205 -- at the freeze point.
9207 elsif A_Id
= Aspect_Input
or else
9208 A_Id
= Aspect_Output
or else
9209 A_Id
= Aspect_Read
or else
9212 Analyze
(End_Decl_Expr
);
9213 Check_Overloaded_Name
;
9215 elsif A_Id
= Aspect_Variable_Indexing
or else
9216 A_Id
= Aspect_Constant_Indexing
or else
9217 A_Id
= Aspect_Default_Iterator
or else
9218 A_Id
= Aspect_Iterator_Element
9220 -- Make type unfrozen before analysis, to prevent spurious errors
9221 -- about late attributes.
9223 Set_Is_Frozen
(Ent
, False);
9224 Analyze
(End_Decl_Expr
);
9225 Set_Is_Frozen
(Ent
, True);
9227 -- If the end of declarations comes before any other freeze
9228 -- point, the Freeze_Expr is not analyzed: no check needed.
9230 if Analyzed
(Freeze_Expr
) and then not In_Instance
then
9231 Check_Overloaded_Name
;
9239 -- Indicate that the expression comes from an aspect specification,
9240 -- which is used in subsequent analysis even if expansion is off.
9242 Set_Parent
(End_Decl_Expr
, ASN
);
9244 -- In a generic context the aspect expressions have not been
9245 -- preanalyzed, so do it now. There are no conformance checks
9246 -- to perform in this case.
9249 Check_Aspect_At_Freeze_Point
(ASN
);
9252 -- The default values attributes may be defined in the private part,
9253 -- and the analysis of the expression may take place when only the
9254 -- partial view is visible. The expression must be scalar, so use
9255 -- the full view to resolve.
9257 elsif (A_Id
= Aspect_Default_Value
9259 A_Id
= Aspect_Default_Component_Value
)
9260 and then Is_Private_Type
(T
)
9262 Preanalyze_Spec_Expression
(End_Decl_Expr
, Full_View
(T
));
9265 Preanalyze_Spec_Expression
(End_Decl_Expr
, T
);
9268 Err
:= not Fully_Conformant_Expressions
(End_Decl_Expr
, Freeze_Expr
);
9271 -- Output error message if error. Force error on aspect specification
9272 -- even if there is an error on the expression itself.
9276 ("!visibility of aspect for& changes after freeze point",
9279 ("info: & is frozen here, aspects evaluated at this point??",
9280 Freeze_Node
(Ent
), Ent
);
9282 end Check_Aspect_At_End_Of_Declarations
;
9284 ----------------------------------
9285 -- Check_Aspect_At_Freeze_Point --
9286 ----------------------------------
9288 procedure Check_Aspect_At_Freeze_Point
(ASN
: Node_Id
) is
9289 Ident
: constant Node_Id
:= Identifier
(ASN
);
9290 -- Identifier (use Entity field to save expression)
9292 A_Id
: constant Aspect_Id
:= Get_Aspect_Id
(Chars
(Ident
));
9294 T
: Entity_Id
:= Empty
;
9295 -- Type required for preanalyze call
9298 -- On entry to this procedure, Entity (Ident) contains a copy of the
9299 -- original expression from the aspect, saved for this purpose.
9301 -- On exit from this procedure Entity (Ident) is unchanged, still
9302 -- containing that copy, but Expression (Ident) is a preanalyzed copy
9303 -- of the expression, preanalyzed just after the freeze point.
9305 -- Make a copy of the expression to be preanalyzed
9307 Set_Expression
(ASN
, New_Copy_Tree
(Entity
(Ident
)));
9309 -- Find type for preanalyze call
9313 -- No_Aspect should be impossible
9316 raise Program_Error
;
9318 -- Aspects taking an optional boolean argument
9320 when Boolean_Aspects
9321 | Library_Unit_Aspects
9323 T
:= Standard_Boolean
;
9325 -- Aspects corresponding to attribute definition clauses
9327 when Aspect_Address
=>
9328 T
:= RTE
(RE_Address
);
9330 when Aspect_Attach_Handler
=>
9331 T
:= RTE
(RE_Interrupt_ID
);
9333 when Aspect_Bit_Order
9334 | Aspect_Scalar_Storage_Order
9336 T
:= RTE
(RE_Bit_Order
);
9338 when Aspect_Convention
=>
9342 T
:= RTE
(RE_CPU_Range
);
9344 -- Default_Component_Value is resolved with the component type
9346 when Aspect_Default_Component_Value
=>
9347 T
:= Component_Type
(Entity
(ASN
));
9349 when Aspect_Default_Storage_Pool
=>
9350 T
:= Class_Wide_Type
(RTE
(RE_Root_Storage_Pool
));
9352 -- Default_Value is resolved with the type entity in question
9354 when Aspect_Default_Value
=>
9357 when Aspect_Dispatching_Domain
=>
9358 T
:= RTE
(RE_Dispatching_Domain
);
9360 when Aspect_External_Tag
=>
9361 T
:= Standard_String
;
9363 when Aspect_External_Name
=>
9364 T
:= Standard_String
;
9366 when Aspect_Link_Name
=>
9367 T
:= Standard_String
;
9369 when Aspect_Interrupt_Priority
9372 T
:= Standard_Integer
;
9374 when Aspect_Relative_Deadline
=>
9375 T
:= RTE
(RE_Time_Span
);
9377 when Aspect_Secondary_Stack_Size
=>
9378 T
:= Standard_Integer
;
9380 when Aspect_Small
=>
9382 -- Note that the expression can be of any real type (not just a
9383 -- real universal literal) as long as it is a static constant.
9387 -- For a simple storage pool, we have to retrieve the type of the
9388 -- pool object associated with the aspect's corresponding attribute
9389 -- definition clause.
9391 when Aspect_Simple_Storage_Pool
=>
9392 T
:= Etype
(Expression
(Aspect_Rep_Item
(ASN
)));
9394 when Aspect_Storage_Pool
=>
9395 T
:= Class_Wide_Type
(RTE
(RE_Root_Storage_Pool
));
9397 when Aspect_Alignment
9398 | Aspect_Component_Size
9399 | Aspect_Machine_Radix
9400 | Aspect_Object_Size
9402 | Aspect_Storage_Size
9403 | Aspect_Stream_Size
9408 when Aspect_Linker_Section
=>
9409 T
:= Standard_String
;
9411 when Aspect_Synchronization
=>
9414 -- Special case, the expression of these aspects is just an entity
9415 -- that does not need any resolution, so just analyze.
9425 Analyze
(Expression
(ASN
));
9428 -- Same for Iterator aspects, where the expression is a function
9429 -- name. Legality rules are checked separately.
9431 when Aspect_Constant_Indexing
9432 | Aspect_Default_Iterator
9433 | Aspect_Iterator_Element
9434 | Aspect_Variable_Indexing
9436 Analyze
(Expression
(ASN
));
9439 -- Ditto for Iterable, legality checks in Validate_Iterable_Aspect.
9441 when Aspect_Iterable
=>
9445 Cursor
: constant Entity_Id
:= Get_Cursor_Type
(ASN
, T
);
9450 if Cursor
= Any_Type
then
9454 Assoc
:= First
(Component_Associations
(Expression
(ASN
)));
9455 while Present
(Assoc
) loop
9456 Expr
:= Expression
(Assoc
);
9459 if not Error_Posted
(Expr
) then
9460 Resolve_Iterable_Operation
9461 (Expr
, Cursor
, T
, Chars
(First
(Choices
(Assoc
))));
9470 -- Invariant/Predicate take boolean expressions
9472 when Aspect_Dynamic_Predicate
9475 | Aspect_Static_Predicate
9476 | Aspect_Type_Invariant
9478 T
:= Standard_Boolean
;
9480 when Aspect_Predicate_Failure
=>
9481 T
:= Standard_String
;
9483 -- Here is the list of aspects that don't require delay analysis
9485 when Aspect_Abstract_State
9487 | Aspect_Async_Readers
9488 | Aspect_Async_Writers
9489 | Aspect_Constant_After_Elaboration
9490 | Aspect_Contract_Cases
9491 | Aspect_Default_Initial_Condition
9494 | Aspect_Dimension_System
9495 | Aspect_Effective_Reads
9496 | Aspect_Effective_Writes
9497 | Aspect_Extensions_Visible
9500 | Aspect_Implicit_Dereference
9501 | Aspect_Initial_Condition
9502 | Aspect_Initializes
9503 | Aspect_Max_Queue_Length
9504 | Aspect_Obsolescent
9507 | Aspect_Postcondition
9509 | Aspect_Precondition
9510 | Aspect_Refined_Depends
9511 | Aspect_Refined_Global
9512 | Aspect_Refined_Post
9513 | Aspect_Refined_State
9516 | Aspect_Unimplemented
9517 | Aspect_Volatile_Function
9519 raise Program_Error
;
9523 -- Do the preanalyze call
9525 Preanalyze_Spec_Expression
(Expression
(ASN
), T
);
9526 end Check_Aspect_At_Freeze_Point
;
9528 -----------------------------------
9529 -- Check_Constant_Address_Clause --
9530 -----------------------------------
9532 procedure Check_Constant_Address_Clause
9536 procedure Check_At_Constant_Address
(Nod
: Node_Id
);
9537 -- Checks that the given node N represents a name whose 'Address is
9538 -- constant (in the same sense as OK_Constant_Address_Clause, i.e. the
9539 -- address value is the same at the point of declaration of U_Ent and at
9540 -- the time of elaboration of the address clause.
9542 procedure Check_Expr_Constants
(Nod
: Node_Id
);
9543 -- Checks that Nod meets the requirements for a constant address clause
9544 -- in the sense of the enclosing procedure.
9546 procedure Check_List_Constants
(Lst
: List_Id
);
9547 -- Check that all elements of list Lst meet the requirements for a
9548 -- constant address clause in the sense of the enclosing procedure.
9550 -------------------------------
9551 -- Check_At_Constant_Address --
9552 -------------------------------
9554 procedure Check_At_Constant_Address
(Nod
: Node_Id
) is
9556 if Is_Entity_Name
(Nod
) then
9557 if Present
(Address_Clause
(Entity
((Nod
)))) then
9559 ("invalid address clause for initialized object &!",
9562 ("address for& cannot depend on another address clause! "
9563 & "(RM 13.1(22))!", Nod
, U_Ent
);
9565 elsif In_Same_Source_Unit
(Entity
(Nod
), U_Ent
)
9566 and then Sloc
(U_Ent
) < Sloc
(Entity
(Nod
))
9569 ("invalid address clause for initialized object &!",
9571 Error_Msg_Node_2
:= U_Ent
;
9573 ("\& must be defined before & (RM 13.1(22))!",
9577 elsif Nkind
(Nod
) = N_Selected_Component
then
9579 T
: constant Entity_Id
:= Etype
(Prefix
(Nod
));
9582 if (Is_Record_Type
(T
)
9583 and then Has_Discriminants
(T
))
9586 and then Is_Record_Type
(Designated_Type
(T
))
9587 and then Has_Discriminants
(Designated_Type
(T
)))
9590 ("invalid address clause for initialized object &!",
9593 ("\address cannot depend on component of discriminated "
9594 & "record (RM 13.1(22))!", Nod
);
9596 Check_At_Constant_Address
(Prefix
(Nod
));
9600 elsif Nkind
(Nod
) = N_Indexed_Component
then
9601 Check_At_Constant_Address
(Prefix
(Nod
));
9602 Check_List_Constants
(Expressions
(Nod
));
9605 Check_Expr_Constants
(Nod
);
9607 end Check_At_Constant_Address
;
9609 --------------------------
9610 -- Check_Expr_Constants --
9611 --------------------------
9613 procedure Check_Expr_Constants
(Nod
: Node_Id
) is
9614 Loc_U_Ent
: constant Source_Ptr
:= Sloc
(U_Ent
);
9615 Ent
: Entity_Id
:= Empty
;
9618 if Nkind
(Nod
) in N_Has_Etype
9619 and then Etype
(Nod
) = Any_Type
9630 when N_Expanded_Name
9633 Ent
:= Entity
(Nod
);
9635 -- We need to look at the original node if it is different
9636 -- from the node, since we may have rewritten things and
9637 -- substituted an identifier representing the rewrite.
9639 if Original_Node
(Nod
) /= Nod
then
9640 Check_Expr_Constants
(Original_Node
(Nod
));
9642 -- If the node is an object declaration without initial
9643 -- value, some code has been expanded, and the expression
9644 -- is not constant, even if the constituents might be
9645 -- acceptable, as in A'Address + offset.
9647 if Ekind
(Ent
) = E_Variable
9649 Nkind
(Declaration_Node
(Ent
)) = N_Object_Declaration
9651 No
(Expression
(Declaration_Node
(Ent
)))
9654 ("invalid address clause for initialized object &!",
9657 -- If entity is constant, it may be the result of expanding
9658 -- a check. We must verify that its declaration appears
9659 -- before the object in question, else we also reject the
9662 elsif Ekind
(Ent
) = E_Constant
9663 and then In_Same_Source_Unit
(Ent
, U_Ent
)
9664 and then Sloc
(Ent
) > Loc_U_Ent
9667 ("invalid address clause for initialized object &!",
9674 -- Otherwise look at the identifier and see if it is OK
9676 if Ekind_In
(Ent
, E_Named_Integer
, E_Named_Real
)
9677 or else Is_Type
(Ent
)
9681 elsif Ekind_In
(Ent
, E_Constant
, E_In_Parameter
) then
9683 -- This is the case where we must have Ent defined before
9684 -- U_Ent. Clearly if they are in different units this
9685 -- requirement is met since the unit containing Ent is
9686 -- already processed.
9688 if not In_Same_Source_Unit
(Ent
, U_Ent
) then
9691 -- Otherwise location of Ent must be before the location
9692 -- of U_Ent, that's what prior defined means.
9694 elsif Sloc
(Ent
) < Loc_U_Ent
then
9699 ("invalid address clause for initialized object &!",
9701 Error_Msg_Node_2
:= U_Ent
;
9703 ("\& must be defined before & (RM 13.1(22))!",
9707 elsif Nkind
(Original_Node
(Nod
)) = N_Function_Call
then
9708 Check_Expr_Constants
(Original_Node
(Nod
));
9712 ("invalid address clause for initialized object &!",
9715 if Comes_From_Source
(Ent
) then
9717 ("\reference to variable& not allowed"
9718 & " (RM 13.1(22))!", Nod
, Ent
);
9721 ("non-static expression not allowed"
9722 & " (RM 13.1(22))!", Nod
);
9726 when N_Integer_Literal
=>
9728 -- If this is a rewritten unchecked conversion, in a system
9729 -- where Address is an integer type, always use the base type
9730 -- for a literal value. This is user-friendly and prevents
9731 -- order-of-elaboration issues with instances of unchecked
9734 if Nkind
(Original_Node
(Nod
)) = N_Function_Call
then
9735 Set_Etype
(Nod
, Base_Type
(Etype
(Nod
)));
9738 when N_Character_Literal
9745 Check_Expr_Constants
(Low_Bound
(Nod
));
9746 Check_Expr_Constants
(High_Bound
(Nod
));
9748 when N_Explicit_Dereference
=>
9749 Check_Expr_Constants
(Prefix
(Nod
));
9751 when N_Indexed_Component
=>
9752 Check_Expr_Constants
(Prefix
(Nod
));
9753 Check_List_Constants
(Expressions
(Nod
));
9756 Check_Expr_Constants
(Prefix
(Nod
));
9757 Check_Expr_Constants
(Discrete_Range
(Nod
));
9759 when N_Selected_Component
=>
9760 Check_Expr_Constants
(Prefix
(Nod
));
9762 when N_Attribute_Reference
=>
9763 if Nam_In
(Attribute_Name
(Nod
), Name_Address
,
9765 Name_Unchecked_Access
,
9766 Name_Unrestricted_Access
)
9768 Check_At_Constant_Address
(Prefix
(Nod
));
9771 Check_Expr_Constants
(Prefix
(Nod
));
9772 Check_List_Constants
(Expressions
(Nod
));
9776 Check_List_Constants
(Component_Associations
(Nod
));
9777 Check_List_Constants
(Expressions
(Nod
));
9779 when N_Component_Association
=>
9780 Check_Expr_Constants
(Expression
(Nod
));
9782 when N_Extension_Aggregate
=>
9783 Check_Expr_Constants
(Ancestor_Part
(Nod
));
9784 Check_List_Constants
(Component_Associations
(Nod
));
9785 Check_List_Constants
(Expressions
(Nod
));
9794 Check_Expr_Constants
(Left_Opnd
(Nod
));
9795 Check_Expr_Constants
(Right_Opnd
(Nod
));
9798 Check_Expr_Constants
(Right_Opnd
(Nod
));
9801 | N_Qualified_Expression
9803 | N_Unchecked_Type_Conversion
9805 Check_Expr_Constants
(Expression
(Nod
));
9807 when N_Function_Call
=>
9808 if not Is_Pure
(Entity
(Name
(Nod
))) then
9810 ("invalid address clause for initialized object &!",
9814 ("\function & is not pure (RM 13.1(22))!",
9815 Nod
, Entity
(Name
(Nod
)));
9818 Check_List_Constants
(Parameter_Associations
(Nod
));
9821 when N_Parameter_Association
=>
9822 Check_Expr_Constants
(Explicit_Actual_Parameter
(Nod
));
9826 ("invalid address clause for initialized object &!",
9829 ("\must be constant defined before& (RM 13.1(22))!",
9832 end Check_Expr_Constants
;
9834 --------------------------
9835 -- Check_List_Constants --
9836 --------------------------
9838 procedure Check_List_Constants
(Lst
: List_Id
) is
9842 if Present
(Lst
) then
9843 Nod1
:= First
(Lst
);
9844 while Present
(Nod1
) loop
9845 Check_Expr_Constants
(Nod1
);
9849 end Check_List_Constants
;
9851 -- Start of processing for Check_Constant_Address_Clause
9854 -- If rep_clauses are to be ignored, no need for legality checks. In
9855 -- particular, no need to pester user about rep clauses that violate the
9856 -- rule on constant addresses, given that these clauses will be removed
9857 -- by Freeze before they reach the back end. Similarly in CodePeer mode,
9858 -- we want to relax these checks.
9860 if not Ignore_Rep_Clauses
and not CodePeer_Mode
then
9861 Check_Expr_Constants
(Expr
);
9863 end Check_Constant_Address_Clause
;
9865 ---------------------------
9866 -- Check_Pool_Size_Clash --
9867 ---------------------------
9869 procedure Check_Pool_Size_Clash
(Ent
: Entity_Id
; SP
, SS
: Node_Id
) is
9873 -- We need to find out which one came first. Note that in the case of
9874 -- aspects mixed with pragmas there are cases where the processing order
9875 -- is reversed, which is why we do the check here.
9877 if Sloc
(SP
) < Sloc
(SS
) then
9878 Error_Msg_Sloc
:= Sloc
(SP
);
9880 Error_Msg_NE
("Storage_Pool previously given for&#", Post
, Ent
);
9883 Error_Msg_Sloc
:= Sloc
(SS
);
9885 Error_Msg_NE
("Storage_Size previously given for&#", Post
, Ent
);
9889 ("\cannot have Storage_Size and Storage_Pool (RM 13.11(3))", Post
);
9890 end Check_Pool_Size_Clash
;
9892 ----------------------------------------
9893 -- Check_Record_Representation_Clause --
9894 ----------------------------------------
9896 procedure Check_Record_Representation_Clause
(N
: Node_Id
) is
9897 Loc
: constant Source_Ptr
:= Sloc
(N
);
9898 Ident
: constant Node_Id
:= Identifier
(N
);
9899 Rectype
: Entity_Id
;
9904 Hbit
: Uint
:= Uint_0
;
9908 Max_Bit_So_Far
: Uint
;
9909 -- Records the maximum bit position so far. If all field positions
9910 -- are monotonically increasing, then we can skip the circuit for
9911 -- checking for overlap, since no overlap is possible.
9913 Tagged_Parent
: Entity_Id
:= Empty
;
9914 -- This is set in the case of an extension for which we have either a
9915 -- size clause or Is_Fully_Repped_Tagged_Type True (indicating that all
9916 -- components are positioned by record representation clauses) on the
9917 -- parent type. In this case we check for overlap between components of
9918 -- this tagged type and the parent component. Tagged_Parent will point
9919 -- to this parent type. For all other cases, Tagged_Parent is Empty.
9921 Parent_Last_Bit
: Uint
;
9922 -- Relevant only if Tagged_Parent is set, Parent_Last_Bit indicates the
9923 -- last bit position for any field in the parent type. We only need to
9924 -- check overlap for fields starting below this point.
9926 Overlap_Check_Required
: Boolean;
9927 -- Used to keep track of whether or not an overlap check is required
9929 Overlap_Detected
: Boolean := False;
9930 -- Set True if an overlap is detected
9932 Ccount
: Natural := 0;
9933 -- Number of component clauses in record rep clause
9935 procedure Check_Component_Overlap
(C1_Ent
, C2_Ent
: Entity_Id
);
9936 -- Given two entities for record components or discriminants, checks
9937 -- if they have overlapping component clauses and issues errors if so.
9939 procedure Find_Component
;
9940 -- Finds component entity corresponding to current component clause (in
9941 -- CC), and sets Comp to the entity, and Fbit/Lbit to the zero origin
9942 -- start/stop bits for the field. If there is no matching component or
9943 -- if the matching component does not have a component clause, then
9944 -- that's an error and Comp is set to Empty, but no error message is
9945 -- issued, since the message was already given. Comp is also set to
9946 -- Empty if the current "component clause" is in fact a pragma.
9948 -----------------------------
9949 -- Check_Component_Overlap --
9950 -----------------------------
9952 procedure Check_Component_Overlap
(C1_Ent
, C2_Ent
: Entity_Id
) is
9953 CC1
: constant Node_Id
:= Component_Clause
(C1_Ent
);
9954 CC2
: constant Node_Id
:= Component_Clause
(C2_Ent
);
9957 if Present
(CC1
) and then Present
(CC2
) then
9959 -- Exclude odd case where we have two tag components in the same
9960 -- record, both at location zero. This seems a bit strange, but
9961 -- it seems to happen in some circumstances, perhaps on an error.
9963 if Nam_In
(Chars
(C1_Ent
), Name_uTag
, Name_uTag
) then
9967 -- Here we check if the two fields overlap
9970 S1
: constant Uint
:= Component_Bit_Offset
(C1_Ent
);
9971 S2
: constant Uint
:= Component_Bit_Offset
(C2_Ent
);
9972 E1
: constant Uint
:= S1
+ Esize
(C1_Ent
);
9973 E2
: constant Uint
:= S2
+ Esize
(C2_Ent
);
9976 if E2
<= S1
or else E1
<= S2
then
9979 Error_Msg_Node_2
:= Component_Name
(CC2
);
9980 Error_Msg_Sloc
:= Sloc
(Error_Msg_Node_2
);
9981 Error_Msg_Node_1
:= Component_Name
(CC1
);
9983 ("component& overlaps & #", Component_Name
(CC1
));
9984 Overlap_Detected
:= True;
9988 end Check_Component_Overlap
;
9990 --------------------
9991 -- Find_Component --
9992 --------------------
9994 procedure Find_Component
is
9996 procedure Search_Component
(R
: Entity_Id
);
9997 -- Search components of R for a match. If found, Comp is set
9999 ----------------------
10000 -- Search_Component --
10001 ----------------------
10003 procedure Search_Component
(R
: Entity_Id
) is
10005 Comp
:= First_Component_Or_Discriminant
(R
);
10006 while Present
(Comp
) loop
10008 -- Ignore error of attribute name for component name (we
10009 -- already gave an error message for this, so no need to
10012 if Nkind
(Component_Name
(CC
)) = N_Attribute_Reference
then
10015 exit when Chars
(Comp
) = Chars
(Component_Name
(CC
));
10018 Next_Component_Or_Discriminant
(Comp
);
10020 end Search_Component
;
10022 -- Start of processing for Find_Component
10025 -- Return with Comp set to Empty if we have a pragma
10027 if Nkind
(CC
) = N_Pragma
then
10032 -- Search current record for matching component
10034 Search_Component
(Rectype
);
10036 -- If not found, maybe component of base type discriminant that is
10037 -- absent from statically constrained first subtype.
10040 Search_Component
(Base_Type
(Rectype
));
10043 -- If no component, or the component does not reference the component
10044 -- clause in question, then there was some previous error for which
10045 -- we already gave a message, so just return with Comp Empty.
10047 if No
(Comp
) or else Component_Clause
(Comp
) /= CC
then
10048 Check_Error_Detected
;
10051 -- Normal case where we have a component clause
10054 Fbit
:= Component_Bit_Offset
(Comp
);
10055 Lbit
:= Fbit
+ Esize
(Comp
) - 1;
10057 end Find_Component
;
10059 -- Start of processing for Check_Record_Representation_Clause
10063 Rectype
:= Entity
(Ident
);
10065 if Rectype
= Any_Type
then
10069 Rectype
:= Underlying_Type
(Rectype
);
10071 -- See if we have a fully repped derived tagged type
10074 PS
: constant Entity_Id
:= Parent_Subtype
(Rectype
);
10077 if Present
(PS
) and then Known_Static_RM_Size
(PS
) then
10078 Tagged_Parent
:= PS
;
10079 Parent_Last_Bit
:= RM_Size
(PS
) - 1;
10081 elsif Present
(PS
) and then Is_Fully_Repped_Tagged_Type
(PS
) then
10082 Tagged_Parent
:= PS
;
10084 -- Find maximum bit of any component of the parent type
10086 Parent_Last_Bit
:= UI_From_Int
(System_Address_Size
- 1);
10087 Pcomp
:= First_Entity
(Tagged_Parent
);
10088 while Present
(Pcomp
) loop
10089 if Ekind_In
(Pcomp
, E_Discriminant
, E_Component
) then
10090 if Component_Bit_Offset
(Pcomp
) /= No_Uint
10091 and then Known_Static_Esize
(Pcomp
)
10096 Component_Bit_Offset
(Pcomp
) + Esize
(Pcomp
) - 1);
10100 -- Skip anonymous types generated for constrained array
10101 -- or record components.
10106 Next_Entity
(Pcomp
);
10111 -- All done if no component clauses
10113 CC
:= First
(Component_Clauses
(N
));
10119 -- If a tag is present, then create a component clause that places it
10120 -- at the start of the record (otherwise gigi may place it after other
10121 -- fields that have rep clauses).
10123 Fent
:= First_Entity
(Rectype
);
10125 if Nkind
(Fent
) = N_Defining_Identifier
10126 and then Chars
(Fent
) = Name_uTag
10128 Set_Component_Bit_Offset
(Fent
, Uint_0
);
10129 Set_Normalized_Position
(Fent
, Uint_0
);
10130 Set_Normalized_First_Bit
(Fent
, Uint_0
);
10131 Set_Normalized_Position_Max
(Fent
, Uint_0
);
10132 Init_Esize
(Fent
, System_Address_Size
);
10134 Set_Component_Clause
(Fent
,
10135 Make_Component_Clause
(Loc
,
10136 Component_Name
=> Make_Identifier
(Loc
, Name_uTag
),
10138 Position
=> Make_Integer_Literal
(Loc
, Uint_0
),
10139 First_Bit
=> Make_Integer_Literal
(Loc
, Uint_0
),
10141 Make_Integer_Literal
(Loc
,
10142 UI_From_Int
(System_Address_Size
))));
10144 Ccount
:= Ccount
+ 1;
10147 Max_Bit_So_Far
:= Uint_Minus_1
;
10148 Overlap_Check_Required
:= False;
10150 -- Process the component clauses
10152 while Present
(CC
) loop
10155 if Present
(Comp
) then
10156 Ccount
:= Ccount
+ 1;
10158 -- We need a full overlap check if record positions non-monotonic
10160 if Fbit
<= Max_Bit_So_Far
then
10161 Overlap_Check_Required
:= True;
10164 Max_Bit_So_Far
:= Lbit
;
10166 -- Check bit position out of range of specified size
10168 if Has_Size_Clause
(Rectype
)
10169 and then RM_Size
(Rectype
) <= Lbit
10172 ("bit number out of range of specified size",
10175 -- Check for overlap with tag or parent component
10178 if Is_Tagged_Type
(Rectype
)
10179 and then Fbit
< System_Address_Size
10182 ("component overlaps tag field of&",
10183 Component_Name
(CC
), Rectype
);
10184 Overlap_Detected
:= True;
10186 elsif Present
(Tagged_Parent
)
10187 and then Fbit
<= Parent_Last_Bit
10190 ("component overlaps parent field of&",
10191 Component_Name
(CC
), Rectype
);
10192 Overlap_Detected
:= True;
10195 if Hbit
< Lbit
then
10204 -- Now that we have processed all the component clauses, check for
10205 -- overlap. We have to leave this till last, since the components can
10206 -- appear in any arbitrary order in the representation clause.
10208 -- We do not need this check if all specified ranges were monotonic,
10209 -- as recorded by Overlap_Check_Required being False at this stage.
10211 -- This first section checks if there are any overlapping entries at
10212 -- all. It does this by sorting all entries and then seeing if there are
10213 -- any overlaps. If there are none, then that is decisive, but if there
10214 -- are overlaps, they may still be OK (they may result from fields in
10215 -- different variants).
10217 if Overlap_Check_Required
then
10218 Overlap_Check1
: declare
10220 OC_Fbit
: array (0 .. Ccount
) of Uint
;
10221 -- First-bit values for component clauses, the value is the offset
10222 -- of the first bit of the field from start of record. The zero
10223 -- entry is for use in sorting.
10225 OC_Lbit
: array (0 .. Ccount
) of Uint
;
10226 -- Last-bit values for component clauses, the value is the offset
10227 -- of the last bit of the field from start of record. The zero
10228 -- entry is for use in sorting.
10230 OC_Count
: Natural := 0;
10231 -- Count of entries in OC_Fbit and OC_Lbit
10233 function OC_Lt
(Op1
, Op2
: Natural) return Boolean;
10234 -- Compare routine for Sort
10236 procedure OC_Move
(From
: Natural; To
: Natural);
10237 -- Move routine for Sort
10239 package Sorting
is new GNAT
.Heap_Sort_G
(OC_Move
, OC_Lt
);
10245 function OC_Lt
(Op1
, Op2
: Natural) return Boolean is
10247 return OC_Fbit
(Op1
) < OC_Fbit
(Op2
);
10254 procedure OC_Move
(From
: Natural; To
: Natural) is
10256 OC_Fbit
(To
) := OC_Fbit
(From
);
10257 OC_Lbit
(To
) := OC_Lbit
(From
);
10260 -- Start of processing for Overlap_Check
10263 CC
:= First
(Component_Clauses
(N
));
10264 while Present
(CC
) loop
10266 -- Exclude component clause already marked in error
10268 if not Error_Posted
(CC
) then
10271 if Present
(Comp
) then
10272 OC_Count
:= OC_Count
+ 1;
10273 OC_Fbit
(OC_Count
) := Fbit
;
10274 OC_Lbit
(OC_Count
) := Lbit
;
10281 Sorting
.Sort
(OC_Count
);
10283 Overlap_Check_Required
:= False;
10284 for J
in 1 .. OC_Count
- 1 loop
10285 if OC_Lbit
(J
) >= OC_Fbit
(J
+ 1) then
10286 Overlap_Check_Required
:= True;
10290 end Overlap_Check1
;
10293 -- If Overlap_Check_Required is still True, then we have to do the full
10294 -- scale overlap check, since we have at least two fields that do
10295 -- overlap, and we need to know if that is OK since they are in
10296 -- different variant, or whether we have a definite problem.
10298 if Overlap_Check_Required
then
10299 Overlap_Check2
: declare
10300 C1_Ent
, C2_Ent
: Entity_Id
;
10301 -- Entities of components being checked for overlap
10304 -- Component_List node whose Component_Items are being checked
10307 -- Component declaration for component being checked
10310 C1_Ent
:= First_Entity
(Base_Type
(Rectype
));
10312 -- Loop through all components in record. For each component check
10313 -- for overlap with any of the preceding elements on the component
10314 -- list containing the component and also, if the component is in
10315 -- a variant, check against components outside the case structure.
10316 -- This latter test is repeated recursively up the variant tree.
10318 Main_Component_Loop
: while Present
(C1_Ent
) loop
10319 if not Ekind_In
(C1_Ent
, E_Component
, E_Discriminant
) then
10320 goto Continue_Main_Component_Loop
;
10323 -- Skip overlap check if entity has no declaration node. This
10324 -- happens with discriminants in constrained derived types.
10325 -- Possibly we are missing some checks as a result, but that
10326 -- does not seem terribly serious.
10328 if No
(Declaration_Node
(C1_Ent
)) then
10329 goto Continue_Main_Component_Loop
;
10332 Clist
:= Parent
(List_Containing
(Declaration_Node
(C1_Ent
)));
10334 -- Loop through component lists that need checking. Check the
10335 -- current component list and all lists in variants above us.
10337 Component_List_Loop
: loop
10339 -- If derived type definition, go to full declaration
10340 -- If at outer level, check discriminants if there are any.
10342 if Nkind
(Clist
) = N_Derived_Type_Definition
then
10343 Clist
:= Parent
(Clist
);
10346 -- Outer level of record definition, check discriminants
10348 if Nkind_In
(Clist
, N_Full_Type_Declaration
,
10349 N_Private_Type_Declaration
)
10351 if Has_Discriminants
(Defining_Identifier
(Clist
)) then
10353 First_Discriminant
(Defining_Identifier
(Clist
));
10354 while Present
(C2_Ent
) loop
10355 exit when C1_Ent
= C2_Ent
;
10356 Check_Component_Overlap
(C1_Ent
, C2_Ent
);
10357 Next_Discriminant
(C2_Ent
);
10361 -- Record extension case
10363 elsif Nkind
(Clist
) = N_Derived_Type_Definition
then
10366 -- Otherwise check one component list
10369 Citem
:= First
(Component_Items
(Clist
));
10370 while Present
(Citem
) loop
10371 if Nkind
(Citem
) = N_Component_Declaration
then
10372 C2_Ent
:= Defining_Identifier
(Citem
);
10373 exit when C1_Ent
= C2_Ent
;
10374 Check_Component_Overlap
(C1_Ent
, C2_Ent
);
10381 -- Check for variants above us (the parent of the Clist can
10382 -- be a variant, in which case its parent is a variant part,
10383 -- and the parent of the variant part is a component list
10384 -- whose components must all be checked against the current
10385 -- component for overlap).
10387 if Nkind
(Parent
(Clist
)) = N_Variant
then
10388 Clist
:= Parent
(Parent
(Parent
(Clist
)));
10390 -- Check for possible discriminant part in record, this
10391 -- is treated essentially as another level in the
10392 -- recursion. For this case the parent of the component
10393 -- list is the record definition, and its parent is the
10394 -- full type declaration containing the discriminant
10397 elsif Nkind
(Parent
(Clist
)) = N_Record_Definition
then
10398 Clist
:= Parent
(Parent
((Clist
)));
10400 -- If neither of these two cases, we are at the top of
10404 exit Component_List_Loop
;
10406 end loop Component_List_Loop
;
10408 <<Continue_Main_Component_Loop
>>
10409 Next_Entity
(C1_Ent
);
10411 end loop Main_Component_Loop
;
10412 end Overlap_Check2
;
10415 -- The following circuit deals with warning on record holes (gaps). We
10416 -- skip this check if overlap was detected, since it makes sense for the
10417 -- programmer to fix this illegality before worrying about warnings.
10419 if not Overlap_Detected
and Warn_On_Record_Holes
then
10420 Record_Hole_Check
: declare
10421 Decl
: constant Node_Id
:= Declaration_Node
(Base_Type
(Rectype
));
10422 -- Full declaration of record type
10424 procedure Check_Component_List
10428 -- Check component list CL for holes. The starting bit should be
10429 -- Sbit. which is zero for the main record component list and set
10430 -- appropriately for recursive calls for variants. DS is set to
10431 -- a list of discriminant specifications to be included in the
10432 -- consideration of components. It is No_List if none to consider.
10434 --------------------------
10435 -- Check_Component_List --
10436 --------------------------
10438 procedure Check_Component_List
10446 Compl
:= Integer (List_Length
(Component_Items
(CL
)));
10448 if DS
/= No_List
then
10449 Compl
:= Compl
+ Integer (List_Length
(DS
));
10453 Comps
: array (Natural range 0 .. Compl
) of Entity_Id
;
10454 -- Gather components (zero entry is for sort routine)
10456 Ncomps
: Natural := 0;
10457 -- Number of entries stored in Comps (starting at Comps (1))
10460 -- One component item or discriminant specification
10463 -- Starting bit for next component
10466 -- Component entity
10471 function Lt
(Op1
, Op2
: Natural) return Boolean;
10472 -- Compare routine for Sort
10474 procedure Move
(From
: Natural; To
: Natural);
10475 -- Move routine for Sort
10477 package Sorting
is new GNAT
.Heap_Sort_G
(Move
, Lt
);
10483 function Lt
(Op1
, Op2
: Natural) return Boolean is
10485 return Component_Bit_Offset
(Comps
(Op1
))
10487 Component_Bit_Offset
(Comps
(Op2
));
10494 procedure Move
(From
: Natural; To
: Natural) is
10496 Comps
(To
) := Comps
(From
);
10500 -- Gather discriminants into Comp
10502 if DS
/= No_List
then
10503 Citem
:= First
(DS
);
10504 while Present
(Citem
) loop
10505 if Nkind
(Citem
) = N_Discriminant_Specification
then
10507 Ent
: constant Entity_Id
:=
10508 Defining_Identifier
(Citem
);
10510 if Ekind
(Ent
) = E_Discriminant
then
10511 Ncomps
:= Ncomps
+ 1;
10512 Comps
(Ncomps
) := Ent
;
10521 -- Gather component entities into Comp
10523 Citem
:= First
(Component_Items
(CL
));
10524 while Present
(Citem
) loop
10525 if Nkind
(Citem
) = N_Component_Declaration
then
10526 Ncomps
:= Ncomps
+ 1;
10527 Comps
(Ncomps
) := Defining_Identifier
(Citem
);
10533 -- Now sort the component entities based on the first bit.
10534 -- Note we already know there are no overlapping components.
10536 Sorting
.Sort
(Ncomps
);
10538 -- Loop through entries checking for holes
10541 for J
in 1 .. Ncomps
loop
10545 CBO
: constant Uint
:= Component_Bit_Offset
(CEnt
);
10548 -- Skip components with unknown offsets
10550 if CBO
/= No_Uint
and then CBO
>= 0 then
10551 Error_Msg_Uint_1
:= CBO
- Nbit
;
10553 if Error_Msg_Uint_1
> 0 then
10555 ("?H?^-bit gap before component&",
10556 Component_Name
(Component_Clause
(CEnt
)),
10560 Nbit
:= CBO
+ Esize
(CEnt
);
10565 -- Process variant parts recursively if present
10567 if Present
(Variant_Part
(CL
)) then
10568 Variant
:= First
(Variants
(Variant_Part
(CL
)));
10569 while Present
(Variant
) loop
10570 Check_Component_List
10571 (Component_List
(Variant
), Nbit
, No_List
);
10576 end Check_Component_List
;
10578 -- Start of processing for Record_Hole_Check
10585 if Is_Tagged_Type
(Rectype
) then
10586 Sbit
:= UI_From_Int
(System_Address_Size
);
10591 if Nkind
(Decl
) = N_Full_Type_Declaration
10592 and then Nkind
(Type_Definition
(Decl
)) = N_Record_Definition
10594 Check_Component_List
10595 (Component_List
(Type_Definition
(Decl
)),
10597 Discriminant_Specifications
(Decl
));
10600 end Record_Hole_Check
;
10603 -- For records that have component clauses for all components, and whose
10604 -- size is less than or equal to 32, we need to know the size in the
10605 -- front end to activate possible packed array processing where the
10606 -- component type is a record.
10608 -- At this stage Hbit + 1 represents the first unused bit from all the
10609 -- component clauses processed, so if the component clauses are
10610 -- complete, then this is the length of the record.
10612 -- For records longer than System.Storage_Unit, and for those where not
10613 -- all components have component clauses, the back end determines the
10614 -- length (it may for example be appropriate to round up the size
10615 -- to some convenient boundary, based on alignment considerations, etc).
10617 if Unknown_RM_Size
(Rectype
) and then Hbit
+ 1 <= 32 then
10619 -- Nothing to do if at least one component has no component clause
10621 Comp
:= First_Component_Or_Discriminant
(Rectype
);
10622 while Present
(Comp
) loop
10623 exit when No
(Component_Clause
(Comp
));
10624 Next_Component_Or_Discriminant
(Comp
);
10627 -- If we fall out of loop, all components have component clauses
10628 -- and so we can set the size to the maximum value.
10631 Set_RM_Size
(Rectype
, Hbit
+ 1);
10634 end Check_Record_Representation_Clause
;
10640 procedure Check_Size
10644 Biased
: out Boolean)
10646 procedure Size_Too_Small_Error
(Min_Siz
: Uint
);
10647 -- Emit an error concerning illegal size Siz. Min_Siz denotes the
10650 --------------------------
10651 -- Size_Too_Small_Error --
10652 --------------------------
10654 procedure Size_Too_Small_Error
(Min_Siz
: Uint
) is
10656 -- This error is suppressed in ASIS mode to allow for different ASIS
10657 -- back ends or ASIS-based tools to query the illegal clause.
10659 if not ASIS_Mode
then
10660 Error_Msg_Uint_1
:= Min_Siz
;
10661 Error_Msg_NE
("size for& too small, minimum allowed is ^", N
, T
);
10663 end Size_Too_Small_Error
;
10667 UT
: constant Entity_Id
:= Underlying_Type
(T
);
10670 -- Start of processing for Check_Size
10675 -- Reject patently improper size values
10677 if Is_Elementary_Type
(T
)
10678 and then Siz
> UI_From_Int
(Int
'Last)
10680 Error_Msg_N
("Size value too large for elementary type", N
);
10682 if Nkind
(Original_Node
(N
)) = N_Op_Expon
then
10684 ("\maybe '* was meant, rather than '*'*", Original_Node
(N
));
10688 -- Dismiss generic types
10690 if Is_Generic_Type
(T
)
10692 Is_Generic_Type
(UT
)
10694 Is_Generic_Type
(Root_Type
(UT
))
10698 -- Guard against previous errors
10700 elsif No
(UT
) or else UT
= Any_Type
then
10701 Check_Error_Detected
;
10704 -- Check case of bit packed array
10706 elsif Is_Array_Type
(UT
)
10707 and then Known_Static_Component_Size
(UT
)
10708 and then Is_Bit_Packed_Array
(UT
)
10716 Asiz
:= Component_Size
(UT
);
10717 Indx
:= First_Index
(UT
);
10719 Ityp
:= Etype
(Indx
);
10721 -- If non-static bound, then we are not in the business of
10722 -- trying to check the length, and indeed an error will be
10723 -- issued elsewhere, since sizes of non-static array types
10724 -- cannot be set implicitly or explicitly.
10726 if not Is_OK_Static_Subtype
(Ityp
) then
10730 -- Otherwise accumulate next dimension
10732 Asiz
:= Asiz
* (Expr_Value
(Type_High_Bound
(Ityp
)) -
10733 Expr_Value
(Type_Low_Bound
(Ityp
)) +
10737 exit when No
(Indx
);
10740 if Asiz
<= Siz
then
10744 Size_Too_Small_Error
(Asiz
);
10745 Set_Esize
(T
, Asiz
);
10746 Set_RM_Size
(T
, Asiz
);
10750 -- All other composite types are ignored
10752 elsif Is_Composite_Type
(UT
) then
10755 -- For fixed-point types, don't check minimum if type is not frozen,
10756 -- since we don't know all the characteristics of the type that can
10757 -- affect the size (e.g. a specified small) till freeze time.
10759 elsif Is_Fixed_Point_Type
(UT
) and then not Is_Frozen
(UT
) then
10762 -- Cases for which a minimum check is required
10765 -- Ignore if specified size is correct for the type
10767 if Known_Esize
(UT
) and then Siz
= Esize
(UT
) then
10771 -- Otherwise get minimum size
10773 M
:= UI_From_Int
(Minimum_Size
(UT
));
10777 -- Size is less than minimum size, but one possibility remains
10778 -- that we can manage with the new size if we bias the type.
10780 M
:= UI_From_Int
(Minimum_Size
(UT
, Biased
=> True));
10783 Size_Too_Small_Error
(M
);
10785 Set_RM_Size
(T
, M
);
10793 --------------------------
10794 -- Freeze_Entity_Checks --
10795 --------------------------
10797 procedure Freeze_Entity_Checks
(N
: Node_Id
) is
10798 procedure Hide_Non_Overridden_Subprograms
(Typ
: Entity_Id
);
10799 -- Inspect the primitive operations of type Typ and hide all pairs of
10800 -- implicitly declared non-overridden non-fully conformant homographs
10801 -- (Ada RM 8.3 12.3/2).
10803 -------------------------------------
10804 -- Hide_Non_Overridden_Subprograms --
10805 -------------------------------------
10807 procedure Hide_Non_Overridden_Subprograms
(Typ
: Entity_Id
) is
10808 procedure Hide_Matching_Homographs
10809 (Subp_Id
: Entity_Id
;
10810 Start_Elmt
: Elmt_Id
);
10811 -- Inspect a list of primitive operations starting with Start_Elmt
10812 -- and find matching implicitly declared non-overridden non-fully
10813 -- conformant homographs of Subp_Id. If found, all matches along
10814 -- with Subp_Id are hidden from all visibility.
10816 function Is_Non_Overridden_Or_Null_Procedure
10817 (Subp_Id
: Entity_Id
) return Boolean;
10818 -- Determine whether subprogram Subp_Id is implicitly declared non-
10819 -- overridden subprogram or an implicitly declared null procedure.
10821 ------------------------------
10822 -- Hide_Matching_Homographs --
10823 ------------------------------
10825 procedure Hide_Matching_Homographs
10826 (Subp_Id
: Entity_Id
;
10827 Start_Elmt
: Elmt_Id
)
10830 Prim_Elmt
: Elmt_Id
;
10833 Prim_Elmt
:= Start_Elmt
;
10834 while Present
(Prim_Elmt
) loop
10835 Prim
:= Node
(Prim_Elmt
);
10837 -- The current primitive is implicitly declared non-overridden
10838 -- non-fully conformant homograph of Subp_Id. Both subprograms
10839 -- must be hidden from visibility.
10841 if Chars
(Prim
) = Chars
(Subp_Id
)
10842 and then Is_Non_Overridden_Or_Null_Procedure
(Prim
)
10843 and then not Fully_Conformant
(Prim
, Subp_Id
)
10845 Set_Is_Hidden_Non_Overridden_Subpgm
(Prim
);
10846 Set_Is_Immediately_Visible
(Prim
, False);
10847 Set_Is_Potentially_Use_Visible
(Prim
, False);
10849 Set_Is_Hidden_Non_Overridden_Subpgm
(Subp_Id
);
10850 Set_Is_Immediately_Visible
(Subp_Id
, False);
10851 Set_Is_Potentially_Use_Visible
(Subp_Id
, False);
10854 Next_Elmt
(Prim_Elmt
);
10856 end Hide_Matching_Homographs
;
10858 -----------------------------------------
10859 -- Is_Non_Overridden_Or_Null_Procedure --
10860 -----------------------------------------
10862 function Is_Non_Overridden_Or_Null_Procedure
10863 (Subp_Id
: Entity_Id
) return Boolean
10865 Alias_Id
: Entity_Id
;
10868 -- The subprogram is inherited (implicitly declared), it does not
10869 -- override and does not cover a primitive of an interface.
10871 if Ekind_In
(Subp_Id
, E_Function
, E_Procedure
)
10872 and then Present
(Alias
(Subp_Id
))
10873 and then No
(Interface_Alias
(Subp_Id
))
10874 and then No
(Overridden_Operation
(Subp_Id
))
10876 Alias_Id
:= Alias
(Subp_Id
);
10878 if Requires_Overriding
(Alias_Id
) then
10881 elsif Nkind
(Parent
(Alias_Id
)) = N_Procedure_Specification
10882 and then Null_Present
(Parent
(Alias_Id
))
10889 end Is_Non_Overridden_Or_Null_Procedure
;
10893 Prim_Ops
: constant Elist_Id
:= Direct_Primitive_Operations
(Typ
);
10895 Prim_Elmt
: Elmt_Id
;
10897 -- Start of processing for Hide_Non_Overridden_Subprograms
10900 -- Inspect the list of primitives looking for non-overridden
10903 if Present
(Prim_Ops
) then
10904 Prim_Elmt
:= First_Elmt
(Prim_Ops
);
10905 while Present
(Prim_Elmt
) loop
10906 Prim
:= Node
(Prim_Elmt
);
10907 Next_Elmt
(Prim_Elmt
);
10909 if Is_Non_Overridden_Or_Null_Procedure
(Prim
) then
10910 Hide_Matching_Homographs
10912 Start_Elmt
=> Prim_Elmt
);
10916 end Hide_Non_Overridden_Subprograms
;
10920 E
: constant Entity_Id
:= Entity
(N
);
10922 Nongeneric_Case
: constant Boolean := Nkind
(N
) = N_Freeze_Entity
;
10923 -- True in nongeneric case. Some of the processing here is skipped
10924 -- for the generic case since it is not needed. Basically in the
10925 -- generic case, we only need to do stuff that might generate error
10926 -- messages or warnings.
10928 -- Start of processing for Freeze_Entity_Checks
10931 -- Remember that we are processing a freezing entity. Required to
10932 -- ensure correct decoration of internal entities associated with
10933 -- interfaces (see New_Overloaded_Entity).
10935 Inside_Freezing_Actions
:= Inside_Freezing_Actions
+ 1;
10937 -- For tagged types covering interfaces add internal entities that link
10938 -- the primitives of the interfaces with the primitives that cover them.
10939 -- Note: These entities were originally generated only when generating
10940 -- code because their main purpose was to provide support to initialize
10941 -- the secondary dispatch tables. They are now generated also when
10942 -- compiling with no code generation to provide ASIS the relationship
10943 -- between interface primitives and tagged type primitives. They are
10944 -- also used to locate primitives covering interfaces when processing
10945 -- generics (see Derive_Subprograms).
10947 -- This is not needed in the generic case
10949 if Ada_Version
>= Ada_2005
10950 and then Nongeneric_Case
10951 and then Ekind
(E
) = E_Record_Type
10952 and then Is_Tagged_Type
(E
)
10953 and then not Is_Interface
(E
)
10954 and then Has_Interfaces
(E
)
10956 -- This would be a good common place to call the routine that checks
10957 -- overriding of interface primitives (and thus factorize calls to
10958 -- Check_Abstract_Overriding located at different contexts in the
10959 -- compiler). However, this is not possible because it causes
10960 -- spurious errors in case of late overriding.
10962 Add_Internal_Interface_Entities
(E
);
10965 -- After all forms of overriding have been resolved, a tagged type may
10966 -- be left with a set of implicitly declared and possibly erroneous
10967 -- abstract subprograms, null procedures and subprograms that require
10968 -- overriding. If this set contains fully conformant homographs, then
10969 -- one is chosen arbitrarily (already done during resolution), otherwise
10970 -- all remaining non-fully conformant homographs are hidden from
10971 -- visibility (Ada RM 8.3 12.3/2).
10973 if Is_Tagged_Type
(E
) then
10974 Hide_Non_Overridden_Subprograms
(E
);
10979 if Ekind
(E
) = E_Record_Type
10980 and then Is_CPP_Class
(E
)
10981 and then Is_Tagged_Type
(E
)
10982 and then Tagged_Type_Expansion
10984 if CPP_Num_Prims
(E
) = 0 then
10986 -- If the CPP type has user defined components then it must import
10987 -- primitives from C++. This is required because if the C++ class
10988 -- has no primitives then the C++ compiler does not added the _tag
10989 -- component to the type.
10991 if First_Entity
(E
) /= Last_Entity
(E
) then
10993 ("'C'P'P type must import at least one primitive from C++??",
10998 -- Check that all its primitives are abstract or imported from C++.
10999 -- Check also availability of the C++ constructor.
11002 Has_Constructors
: constant Boolean := Has_CPP_Constructors
(E
);
11004 Error_Reported
: Boolean := False;
11008 Elmt
:= First_Elmt
(Primitive_Operations
(E
));
11009 while Present
(Elmt
) loop
11010 Prim
:= Node
(Elmt
);
11012 if Comes_From_Source
(Prim
) then
11013 if Is_Abstract_Subprogram
(Prim
) then
11016 elsif not Is_Imported
(Prim
)
11017 or else Convention
(Prim
) /= Convention_CPP
11020 ("primitives of 'C'P'P types must be imported from C++ "
11021 & "or abstract??", Prim
);
11023 elsif not Has_Constructors
11024 and then not Error_Reported
11026 Error_Msg_Name_1
:= Chars
(E
);
11028 ("??'C'P'P constructor required for type %", Prim
);
11029 Error_Reported
:= True;
11038 -- Check Ada derivation of CPP type
11040 if Expander_Active
-- why? losing errors in -gnatc mode???
11041 and then Present
(Etype
(E
)) -- defend against errors
11042 and then Tagged_Type_Expansion
11043 and then Ekind
(E
) = E_Record_Type
11044 and then Etype
(E
) /= E
11045 and then Is_CPP_Class
(Etype
(E
))
11046 and then CPP_Num_Prims
(Etype
(E
)) > 0
11047 and then not Is_CPP_Class
(E
)
11048 and then not Has_CPP_Constructors
(Etype
(E
))
11050 -- If the parent has C++ primitives but it has no constructor then
11051 -- check that all the primitives are overridden in this derivation;
11052 -- otherwise the constructor of the parent is needed to build the
11060 Elmt
:= First_Elmt
(Primitive_Operations
(E
));
11061 while Present
(Elmt
) loop
11062 Prim
:= Node
(Elmt
);
11064 if not Is_Abstract_Subprogram
(Prim
)
11065 and then No
(Interface_Alias
(Prim
))
11066 and then Find_Dispatching_Type
(Ultimate_Alias
(Prim
)) /= E
11068 Error_Msg_Name_1
:= Chars
(Etype
(E
));
11070 ("'C'P'P constructor required for parent type %", E
);
11079 Inside_Freezing_Actions
:= Inside_Freezing_Actions
- 1;
11081 -- If we have a type with predicates, build predicate function. This is
11082 -- not needed in the generic case, nor within TSS subprograms and other
11083 -- predefined primitives.
11086 and then Nongeneric_Case
11087 and then not Within_Internal_Subprogram
11088 and then Has_Predicates
(E
)
11090 Build_Predicate_Functions
(E
, N
);
11093 -- If type has delayed aspects, this is where we do the preanalysis at
11094 -- the freeze point, as part of the consistent visibility check. Note
11095 -- that this must be done after calling Build_Predicate_Functions or
11096 -- Build_Invariant_Procedure since these subprograms fix occurrences of
11097 -- the subtype name in the saved expression so that they will not cause
11098 -- trouble in the preanalysis.
11100 -- This is also not needed in the generic case
11103 and then Has_Delayed_Aspects
(E
)
11104 and then Scope
(E
) = Current_Scope
11106 -- Retrieve the visibility to the discriminants in order to properly
11107 -- analyze the aspects.
11109 Push_Scope_And_Install_Discriminants
(E
);
11115 -- Look for aspect specification entries for this entity
11117 Ritem
:= First_Rep_Item
(E
);
11118 while Present
(Ritem
) loop
11119 if Nkind
(Ritem
) = N_Aspect_Specification
11120 and then Entity
(Ritem
) = E
11121 and then Is_Delayed_Aspect
(Ritem
)
11123 Check_Aspect_At_Freeze_Point
(Ritem
);
11126 Next_Rep_Item
(Ritem
);
11130 Uninstall_Discriminants_And_Pop_Scope
(E
);
11133 -- For a record type, deal with variant parts. This has to be delayed
11134 -- to this point, because of the issue of statically predicated
11135 -- subtypes, which we have to ensure are frozen before checking
11136 -- choices, since we need to have the static choice list set.
11138 if Is_Record_Type
(E
) then
11139 Check_Variant_Part
: declare
11140 D
: constant Node_Id
:= Declaration_Node
(E
);
11145 Others_Present
: Boolean;
11146 pragma Warnings
(Off
, Others_Present
);
11147 -- Indicates others present, not used in this case
11149 procedure Non_Static_Choice_Error
(Choice
: Node_Id
);
11150 -- Error routine invoked by the generic instantiation below when
11151 -- the variant part has a non static choice.
11153 procedure Process_Declarations
(Variant
: Node_Id
);
11154 -- Processes declarations associated with a variant. We analyzed
11155 -- the declarations earlier (in Sem_Ch3.Analyze_Variant_Part),
11156 -- but we still need the recursive call to Check_Choices for any
11157 -- nested variant to get its choices properly processed. This is
11158 -- also where we expand out the choices if expansion is active.
11160 package Variant_Choices_Processing
is new
11161 Generic_Check_Choices
11162 (Process_Empty_Choice
=> No_OP
,
11163 Process_Non_Static_Choice
=> Non_Static_Choice_Error
,
11164 Process_Associated_Node
=> Process_Declarations
);
11165 use Variant_Choices_Processing
;
11167 -----------------------------
11168 -- Non_Static_Choice_Error --
11169 -----------------------------
11171 procedure Non_Static_Choice_Error
(Choice
: Node_Id
) is
11173 Flag_Non_Static_Expr
11174 ("choice given in variant part is not static!", Choice
);
11175 end Non_Static_Choice_Error
;
11177 --------------------------
11178 -- Process_Declarations --
11179 --------------------------
11181 procedure Process_Declarations
(Variant
: Node_Id
) is
11182 CL
: constant Node_Id
:= Component_List
(Variant
);
11186 -- Check for static predicate present in this variant
11188 if Has_SP_Choice
(Variant
) then
11190 -- Here we expand. You might expect to find this call in
11191 -- Expand_N_Variant_Part, but that is called when we first
11192 -- see the variant part, and we cannot do this expansion
11193 -- earlier than the freeze point, since for statically
11194 -- predicated subtypes, the predicate is not known till
11195 -- the freeze point.
11197 -- Furthermore, we do this expansion even if the expander
11198 -- is not active, because other semantic processing, e.g.
11199 -- for aggregates, requires the expanded list of choices.
11201 -- If the expander is not active, then we can't just clobber
11202 -- the list since it would invalidate the ASIS -gnatct tree.
11203 -- So we have to rewrite the variant part with a Rewrite
11204 -- call that replaces it with a copy and clobber the copy.
11206 if not Expander_Active
then
11208 NewV
: constant Node_Id
:= New_Copy
(Variant
);
11210 Set_Discrete_Choices
11211 (NewV
, New_Copy_List
(Discrete_Choices
(Variant
)));
11212 Rewrite
(Variant
, NewV
);
11216 Expand_Static_Predicates_In_Choices
(Variant
);
11219 -- We don't need to worry about the declarations in the variant
11220 -- (since they were analyzed by Analyze_Choices when we first
11221 -- encountered the variant), but we do need to take care of
11222 -- expansion of any nested variants.
11224 if not Null_Present
(CL
) then
11225 VP
:= Variant_Part
(CL
);
11227 if Present
(VP
) then
11229 (VP
, Variants
(VP
), Etype
(Name
(VP
)), Others_Present
);
11232 end Process_Declarations
;
11234 -- Start of processing for Check_Variant_Part
11237 -- Find component list
11241 if Nkind
(D
) = N_Full_Type_Declaration
then
11242 T
:= Type_Definition
(D
);
11244 if Nkind
(T
) = N_Record_Definition
then
11245 C
:= Component_List
(T
);
11247 elsif Nkind
(T
) = N_Derived_Type_Definition
11248 and then Present
(Record_Extension_Part
(T
))
11250 C
:= Component_List
(Record_Extension_Part
(T
));
11254 -- Case of variant part present
11256 if Present
(C
) and then Present
(Variant_Part
(C
)) then
11257 VP
:= Variant_Part
(C
);
11262 (VP
, Variants
(VP
), Etype
(Name
(VP
)), Others_Present
);
11264 -- If the last variant does not contain the Others choice,
11265 -- replace it with an N_Others_Choice node since Gigi always
11266 -- wants an Others. Note that we do not bother to call Analyze
11267 -- on the modified variant part, since its only effect would be
11268 -- to compute the Others_Discrete_Choices node laboriously, and
11269 -- of course we already know the list of choices corresponding
11270 -- to the others choice (it's the list we're replacing).
11272 -- We only want to do this if the expander is active, since
11273 -- we do not want to clobber the ASIS tree.
11275 if Expander_Active
then
11277 Last_Var
: constant Node_Id
:=
11278 Last_Non_Pragma
(Variants
(VP
));
11280 Others_Node
: Node_Id
;
11283 if Nkind
(First
(Discrete_Choices
(Last_Var
))) /=
11286 Others_Node
:= Make_Others_Choice
(Sloc
(Last_Var
));
11287 Set_Others_Discrete_Choices
11288 (Others_Node
, Discrete_Choices
(Last_Var
));
11289 Set_Discrete_Choices
11290 (Last_Var
, New_List
(Others_Node
));
11295 end Check_Variant_Part
;
11297 end Freeze_Entity_Checks
;
11299 -------------------------
11300 -- Get_Alignment_Value --
11301 -------------------------
11303 function Get_Alignment_Value
(Expr
: Node_Id
) return Uint
is
11304 Align
: constant Uint
:= Static_Integer
(Expr
);
11307 if Align
= No_Uint
then
11310 elsif Align
<= 0 then
11312 -- This error is suppressed in ASIS mode to allow for different ASIS
11313 -- back ends or ASIS-based tools to query the illegal clause.
11315 if not ASIS_Mode
then
11316 Error_Msg_N
("alignment value must be positive", Expr
);
11322 for J
in Int
range 0 .. 64 loop
11324 M
: constant Uint
:= Uint_2
** J
;
11327 exit when M
= Align
;
11331 -- This error is suppressed in ASIS mode to allow for
11332 -- different ASIS back ends or ASIS-based tools to query the
11335 if not ASIS_Mode
then
11336 Error_Msg_N
("alignment value must be power of 2", Expr
);
11346 end Get_Alignment_Value
;
11348 -------------------------------------
11349 -- Inherit_Aspects_At_Freeze_Point --
11350 -------------------------------------
11352 procedure Inherit_Aspects_At_Freeze_Point
(Typ
: Entity_Id
) is
11353 function Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11354 (Rep_Item
: Node_Id
) return Boolean;
11355 -- This routine checks if Rep_Item is either a pragma or an aspect
11356 -- specification node whose correponding pragma (if any) is present in
11357 -- the Rep Item chain of the entity it has been specified to.
11359 --------------------------------------------------
11360 -- Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item --
11361 --------------------------------------------------
11363 function Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11364 (Rep_Item
: Node_Id
) return Boolean
11368 Nkind
(Rep_Item
) = N_Pragma
11369 or else Present_In_Rep_Item
11370 (Entity
(Rep_Item
), Aspect_Rep_Item
(Rep_Item
));
11371 end Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
;
11373 -- Start of processing for Inherit_Aspects_At_Freeze_Point
11376 -- A representation item is either subtype-specific (Size and Alignment
11377 -- clauses) or type-related (all others). Subtype-specific aspects may
11378 -- differ for different subtypes of the same type (RM 13.1.8).
11380 -- A derived type inherits each type-related representation aspect of
11381 -- its parent type that was directly specified before the declaration of
11382 -- the derived type (RM 13.1.15).
11384 -- A derived subtype inherits each subtype-specific representation
11385 -- aspect of its parent subtype that was directly specified before the
11386 -- declaration of the derived type (RM 13.1.15).
11388 -- The general processing involves inheriting a representation aspect
11389 -- from a parent type whenever the first rep item (aspect specification,
11390 -- attribute definition clause, pragma) corresponding to the given
11391 -- representation aspect in the rep item chain of Typ, if any, isn't
11392 -- directly specified to Typ but to one of its parents.
11394 -- ??? Note that, for now, just a limited number of representation
11395 -- aspects have been inherited here so far. Many of them are
11396 -- still inherited in Sem_Ch3. This will be fixed soon. Here is
11397 -- a non- exhaustive list of aspects that likely also need to
11398 -- be moved to this routine: Alignment, Component_Alignment,
11399 -- Component_Size, Machine_Radix, Object_Size, Pack, Predicates,
11400 -- Preelaborable_Initialization, RM_Size and Small.
11402 -- In addition, Convention must be propagated from base type to subtype,
11403 -- because the subtype may have been declared on an incomplete view.
11405 if Nkind
(Parent
(Typ
)) = N_Private_Extension_Declaration
then
11411 if not Has_Rep_Item
(Typ
, Name_Ada_05
, Name_Ada_2005
, False)
11412 and then Has_Rep_Item
(Typ
, Name_Ada_05
, Name_Ada_2005
)
11413 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11414 (Get_Rep_Item
(Typ
, Name_Ada_05
, Name_Ada_2005
))
11416 Set_Is_Ada_2005_Only
(Typ
);
11421 if not Has_Rep_Item
(Typ
, Name_Ada_12
, Name_Ada_2012
, False)
11422 and then Has_Rep_Item
(Typ
, Name_Ada_12
, Name_Ada_2012
)
11423 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11424 (Get_Rep_Item
(Typ
, Name_Ada_12
, Name_Ada_2012
))
11426 Set_Is_Ada_2012_Only
(Typ
);
11431 if not Has_Rep_Item
(Typ
, Name_Atomic
, Name_Shared
, False)
11432 and then Has_Rep_Pragma
(Typ
, Name_Atomic
, Name_Shared
)
11433 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11434 (Get_Rep_Item
(Typ
, Name_Atomic
, Name_Shared
))
11436 Set_Is_Atomic
(Typ
);
11437 Set_Is_Volatile
(Typ
);
11438 Set_Treat_As_Volatile
(Typ
);
11443 if Is_Record_Type
(Typ
)
11444 and then Typ
/= Base_Type
(Typ
) and then Is_Frozen
(Base_Type
(Typ
))
11446 Set_Convention
(Typ
, Convention
(Base_Type
(Typ
)));
11449 -- Default_Component_Value
11451 -- Verify that there is no rep_item declared for the type, and there
11452 -- is one coming from an ancestor.
11454 if Is_Array_Type
(Typ
)
11455 and then Is_Base_Type
(Typ
)
11456 and then not Has_Rep_Item
(Typ
, Name_Default_Component_Value
, False)
11457 and then Has_Rep_Item
(Typ
, Name_Default_Component_Value
)
11459 Set_Default_Aspect_Component_Value
(Typ
,
11460 Default_Aspect_Component_Value
11461 (Entity
(Get_Rep_Item
(Typ
, Name_Default_Component_Value
))));
11466 if Is_Scalar_Type
(Typ
)
11467 and then Is_Base_Type
(Typ
)
11468 and then not Has_Rep_Item
(Typ
, Name_Default_Value
, False)
11469 and then Has_Rep_Item
(Typ
, Name_Default_Value
)
11471 Set_Has_Default_Aspect
(Typ
);
11472 Set_Default_Aspect_Value
(Typ
,
11473 Default_Aspect_Value
11474 (Entity
(Get_Rep_Item
(Typ
, Name_Default_Value
))));
11479 if not Has_Rep_Item
(Typ
, Name_Discard_Names
, False)
11480 and then Has_Rep_Item
(Typ
, Name_Discard_Names
)
11481 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11482 (Get_Rep_Item
(Typ
, Name_Discard_Names
))
11484 Set_Discard_Names
(Typ
);
11489 if not Has_Rep_Item
(Typ
, Name_Volatile
, False)
11490 and then Has_Rep_Item
(Typ
, Name_Volatile
)
11491 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11492 (Get_Rep_Item
(Typ
, Name_Volatile
))
11494 Set_Is_Volatile
(Typ
);
11495 Set_Treat_As_Volatile
(Typ
);
11498 -- Volatile_Full_Access
11500 if not Has_Rep_Item
(Typ
, Name_Volatile_Full_Access
, False)
11501 and then Has_Rep_Pragma
(Typ
, Name_Volatile_Full_Access
)
11502 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11503 (Get_Rep_Item
(Typ
, Name_Volatile_Full_Access
))
11505 Set_Is_Volatile_Full_Access
(Typ
);
11506 Set_Is_Volatile
(Typ
);
11507 Set_Treat_As_Volatile
(Typ
);
11510 -- Inheritance for derived types only
11512 if Is_Derived_Type
(Typ
) then
11514 Bas_Typ
: constant Entity_Id
:= Base_Type
(Typ
);
11515 Imp_Bas_Typ
: constant Entity_Id
:= Implementation_Base_Type
(Typ
);
11518 -- Atomic_Components
11520 if not Has_Rep_Item
(Typ
, Name_Atomic_Components
, False)
11521 and then Has_Rep_Item
(Typ
, Name_Atomic_Components
)
11522 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11523 (Get_Rep_Item
(Typ
, Name_Atomic_Components
))
11525 Set_Has_Atomic_Components
(Imp_Bas_Typ
);
11528 -- Volatile_Components
11530 if not Has_Rep_Item
(Typ
, Name_Volatile_Components
, False)
11531 and then Has_Rep_Item
(Typ
, Name_Volatile_Components
)
11532 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11533 (Get_Rep_Item
(Typ
, Name_Volatile_Components
))
11535 Set_Has_Volatile_Components
(Imp_Bas_Typ
);
11538 -- Finalize_Storage_Only
11540 if not Has_Rep_Pragma
(Typ
, Name_Finalize_Storage_Only
, False)
11541 and then Has_Rep_Pragma
(Typ
, Name_Finalize_Storage_Only
)
11543 Set_Finalize_Storage_Only
(Bas_Typ
);
11546 -- Universal_Aliasing
11548 if not Has_Rep_Item
(Typ
, Name_Universal_Aliasing
, False)
11549 and then Has_Rep_Item
(Typ
, Name_Universal_Aliasing
)
11550 and then Is_Pragma_Or_Corr_Pragma_Present_In_Rep_Item
11551 (Get_Rep_Item
(Typ
, Name_Universal_Aliasing
))
11553 Set_Universal_Aliasing
(Imp_Bas_Typ
);
11558 if Is_Record_Type
(Typ
) then
11559 if not Has_Rep_Item
(Typ
, Name_Bit_Order
, False)
11560 and then Has_Rep_Item
(Typ
, Name_Bit_Order
)
11562 Set_Reverse_Bit_Order
(Bas_Typ
,
11563 Reverse_Bit_Order
(Entity
(Name
11564 (Get_Rep_Item
(Typ
, Name_Bit_Order
)))));
11568 -- Scalar_Storage_Order
11570 -- Note: the aspect is specified on a first subtype, but recorded
11571 -- in a flag of the base type!
11573 if (Is_Record_Type
(Typ
) or else Is_Array_Type
(Typ
))
11574 and then Typ
= Bas_Typ
11576 -- For a type extension, always inherit from parent; otherwise
11577 -- inherit if no default applies. Note: we do not check for
11578 -- an explicit rep item on the parent type when inheriting,
11579 -- because the parent SSO may itself have been set by default.
11581 if not Has_Rep_Item
(First_Subtype
(Typ
),
11582 Name_Scalar_Storage_Order
, False)
11583 and then (Is_Tagged_Type
(Bas_Typ
)
11584 or else not (SSO_Set_Low_By_Default
(Bas_Typ
)
11586 SSO_Set_High_By_Default
(Bas_Typ
)))
11588 Set_Reverse_Storage_Order
(Bas_Typ
,
11589 Reverse_Storage_Order
11590 (Implementation_Base_Type
(Etype
(Bas_Typ
))));
11592 -- Clear default SSO indications, since the inherited aspect
11593 -- which was set explicitly overrides the default.
11595 Set_SSO_Set_Low_By_Default
(Bas_Typ
, False);
11596 Set_SSO_Set_High_By_Default
(Bas_Typ
, False);
11601 end Inherit_Aspects_At_Freeze_Point
;
11607 procedure Initialize
is
11609 Address_Clause_Checks
.Init
;
11610 Compile_Time_Warnings_Errors
.Init
;
11611 Unchecked_Conversions
.Init
;
11613 -- ??? Might be needed in the future for some non GCC back-ends
11614 -- if AAMP_On_Target then
11615 -- Independence_Checks.Init;
11619 ---------------------------
11620 -- Install_Discriminants --
11621 ---------------------------
11623 procedure Install_Discriminants
(E
: Entity_Id
) is
11627 Disc
:= First_Discriminant
(E
);
11628 while Present
(Disc
) loop
11629 Prev
:= Current_Entity
(Disc
);
11630 Set_Current_Entity
(Disc
);
11631 Set_Is_Immediately_Visible
(Disc
);
11632 Set_Homonym
(Disc
, Prev
);
11633 Next_Discriminant
(Disc
);
11635 end Install_Discriminants
;
11637 -------------------------
11638 -- Is_Operational_Item --
11639 -------------------------
11641 function Is_Operational_Item
(N
: Node_Id
) return Boolean is
11643 if Nkind
(N
) /= N_Attribute_Definition_Clause
then
11648 Id
: constant Attribute_Id
:= Get_Attribute_Id
(Chars
(N
));
11651 -- List of operational items is given in AARM 13.1(8.mm/1).
11652 -- It is clearly incomplete, as it does not include iterator
11653 -- aspects, among others.
11655 return Id
= Attribute_Constant_Indexing
11656 or else Id
= Attribute_Default_Iterator
11657 or else Id
= Attribute_Implicit_Dereference
11658 or else Id
= Attribute_Input
11659 or else Id
= Attribute_Iterator_Element
11660 or else Id
= Attribute_Iterable
11661 or else Id
= Attribute_Output
11662 or else Id
= Attribute_Read
11663 or else Id
= Attribute_Variable_Indexing
11664 or else Id
= Attribute_Write
11665 or else Id
= Attribute_External_Tag
;
11668 end Is_Operational_Item
;
11670 -------------------------
11671 -- Is_Predicate_Static --
11672 -------------------------
11674 -- Note: the basic legality of the expression has already been checked, so
11675 -- we don't need to worry about cases or ranges on strings for example.
11677 function Is_Predicate_Static
11679 Nam
: Name_Id
) return Boolean
11681 function All_Static_Case_Alternatives
(L
: List_Id
) return Boolean;
11682 -- Given a list of case expression alternatives, returns True if all
11683 -- the alternatives are static (have all static choices, and a static
11686 function All_Static_Choices
(L
: List_Id
) return Boolean;
11687 -- Returns true if all elements of the list are OK static choices
11688 -- as defined below for Is_Static_Choice. Used for case expression
11689 -- alternatives and for the right operand of a membership test. An
11690 -- others_choice is static if the corresponding expression is static.
11691 -- The staticness of the bounds is checked separately.
11693 function Is_Static_Choice
(N
: Node_Id
) return Boolean;
11694 -- Returns True if N represents a static choice (static subtype, or
11695 -- static subtype indication, or static expression, or static range).
11697 -- Note that this is a bit more inclusive than we actually need
11698 -- (in particular membership tests do not allow the use of subtype
11699 -- indications). But that doesn't matter, we have already checked
11700 -- that the construct is legal to get this far.
11702 function Is_Type_Ref
(N
: Node_Id
) return Boolean;
11703 pragma Inline
(Is_Type_Ref
);
11704 -- Returns True if N is a reference to the type for the predicate in the
11705 -- expression (i.e. if it is an identifier whose Chars field matches the
11706 -- Nam given in the call). N must not be parenthesized, if the type name
11707 -- appears in parens, this routine will return False.
11709 -- The routine also returns True for function calls generated during the
11710 -- expansion of comparison operators on strings, which are intended to
11711 -- be legal in static predicates, and are converted into calls to array
11712 -- comparison routines in the body of the corresponding predicate
11715 ----------------------------------
11716 -- All_Static_Case_Alternatives --
11717 ----------------------------------
11719 function All_Static_Case_Alternatives
(L
: List_Id
) return Boolean is
11724 while Present
(N
) loop
11725 if not (All_Static_Choices
(Discrete_Choices
(N
))
11726 and then Is_OK_Static_Expression
(Expression
(N
)))
11735 end All_Static_Case_Alternatives
;
11737 ------------------------
11738 -- All_Static_Choices --
11739 ------------------------
11741 function All_Static_Choices
(L
: List_Id
) return Boolean is
11746 while Present
(N
) loop
11747 if not Is_Static_Choice
(N
) then
11755 end All_Static_Choices
;
11757 ----------------------
11758 -- Is_Static_Choice --
11759 ----------------------
11761 function Is_Static_Choice
(N
: Node_Id
) return Boolean is
11763 return Nkind
(N
) = N_Others_Choice
11764 or else Is_OK_Static_Expression
(N
)
11765 or else (Is_Entity_Name
(N
) and then Is_Type
(Entity
(N
))
11766 and then Is_OK_Static_Subtype
(Entity
(N
)))
11767 or else (Nkind
(N
) = N_Subtype_Indication
11768 and then Is_OK_Static_Subtype
(Entity
(N
)))
11769 or else (Nkind
(N
) = N_Range
and then Is_OK_Static_Range
(N
));
11770 end Is_Static_Choice
;
11776 function Is_Type_Ref
(N
: Node_Id
) return Boolean is
11778 return (Nkind
(N
) = N_Identifier
11779 and then Chars
(N
) = Nam
11780 and then Paren_Count
(N
) = 0)
11781 or else Nkind
(N
) = N_Function_Call
;
11784 -- Start of processing for Is_Predicate_Static
11787 -- Predicate_Static means one of the following holds. Numbers are the
11788 -- corresponding paragraph numbers in (RM 3.2.4(16-22)).
11790 -- 16: A static expression
11792 if Is_OK_Static_Expression
(Expr
) then
11795 -- 17: A membership test whose simple_expression is the current
11796 -- instance, and whose membership_choice_list meets the requirements
11797 -- for a static membership test.
11799 elsif Nkind
(Expr
) in N_Membership_Test
11800 and then ((Present
(Right_Opnd
(Expr
))
11801 and then Is_Static_Choice
(Right_Opnd
(Expr
)))
11803 (Present
(Alternatives
(Expr
))
11804 and then All_Static_Choices
(Alternatives
(Expr
))))
11808 -- 18. A case_expression whose selecting_expression is the current
11809 -- instance, and whose dependent expressions are static expressions.
11811 elsif Nkind
(Expr
) = N_Case_Expression
11812 and then Is_Type_Ref
(Expression
(Expr
))
11813 and then All_Static_Case_Alternatives
(Alternatives
(Expr
))
11817 -- 19. A call to a predefined equality or ordering operator, where one
11818 -- operand is the current instance, and the other is a static
11821 -- Note: the RM is clearly wrong here in not excluding string types.
11822 -- Without this exclusion, we would allow expressions like X > "ABC"
11823 -- to be considered as predicate-static, which is clearly not intended,
11824 -- since the idea is for predicate-static to be a subset of normal
11825 -- static expressions (and "DEF" > "ABC" is not a static expression).
11827 -- However, we do allow internally generated (not from source) equality
11828 -- and inequality operations to be valid on strings (this helps deal
11829 -- with cases where we transform A in "ABC" to A = "ABC).
11831 -- In fact, it appears that the intent of the ARG is to extend static
11832 -- predicates to strings, and that the extension should probably apply
11833 -- to static expressions themselves. The code below accepts comparison
11834 -- operators that apply to static strings.
11836 elsif Nkind
(Expr
) in N_Op_Compare
11837 and then ((Is_Type_Ref
(Left_Opnd
(Expr
))
11838 and then Is_OK_Static_Expression
(Right_Opnd
(Expr
)))
11840 (Is_Type_Ref
(Right_Opnd
(Expr
))
11841 and then Is_OK_Static_Expression
(Left_Opnd
(Expr
))))
11845 -- 20. A call to a predefined boolean logical operator, where each
11846 -- operand is predicate-static.
11848 elsif (Nkind_In
(Expr
, N_Op_And
, N_Op_Or
, N_Op_Xor
)
11849 and then Is_Predicate_Static
(Left_Opnd
(Expr
), Nam
)
11850 and then Is_Predicate_Static
(Right_Opnd
(Expr
), Nam
))
11852 (Nkind
(Expr
) = N_Op_Not
11853 and then Is_Predicate_Static
(Right_Opnd
(Expr
), Nam
))
11857 -- 21. A short-circuit control form where both operands are
11858 -- predicate-static.
11860 elsif Nkind
(Expr
) in N_Short_Circuit
11861 and then Is_Predicate_Static
(Left_Opnd
(Expr
), Nam
)
11862 and then Is_Predicate_Static
(Right_Opnd
(Expr
), Nam
)
11866 -- 22. A parenthesized predicate-static expression. This does not
11867 -- require any special test, since we just ignore paren levels in
11868 -- all the cases above.
11870 -- One more test that is an implementation artifact caused by the fact
11871 -- that we are analyzing not the original expression, but the generated
11872 -- expression in the body of the predicate function. This can include
11873 -- references to inherited predicates, so that the expression we are
11874 -- processing looks like:
11876 -- xxPredicate (typ (Inns)) and then expression
11878 -- Where the call is to a Predicate function for an inherited predicate.
11879 -- We simply ignore such a call, which could be to either a dynamic or
11880 -- a static predicate. Note that if the parent predicate is dynamic then
11881 -- eventually this type will be marked as dynamic, but you are allowed
11882 -- to specify a static predicate for a subtype which is inheriting a
11883 -- dynamic predicate, so the static predicate validation here ignores
11884 -- the inherited predicate even if it is dynamic.
11885 -- In all cases, a static predicate can only apply to a scalar type.
11887 elsif Nkind
(Expr
) = N_Function_Call
11888 and then Is_Predicate_Function
(Entity
(Name
(Expr
)))
11889 and then Is_Scalar_Type
(Etype
(First_Entity
(Entity
(Name
(Expr
)))))
11893 -- That's an exhaustive list of tests, all other cases are not
11894 -- predicate-static, so we return False.
11899 end Is_Predicate_Static
;
11901 ---------------------
11902 -- Kill_Rep_Clause --
11903 ---------------------
11905 procedure Kill_Rep_Clause
(N
: Node_Id
) is
11907 pragma Assert
(Ignore_Rep_Clauses
);
11909 -- Note: we use Replace rather than Rewrite, because we don't want
11910 -- ASIS to be able to use Original_Node to dig out the (undecorated)
11911 -- rep clause that is being replaced.
11913 Replace
(N
, Make_Null_Statement
(Sloc
(N
)));
11915 -- The null statement must be marked as not coming from source. This is
11916 -- so that ASIS ignores it, and also the back end does not expect bogus
11917 -- "from source" null statements in weird places (e.g. in declarative
11918 -- regions where such null statements are not allowed).
11920 Set_Comes_From_Source
(N
, False);
11921 end Kill_Rep_Clause
;
11927 function Minimum_Size
11929 Biased
: Boolean := False) return Nat
11931 Lo
: Uint
:= No_Uint
;
11932 Hi
: Uint
:= No_Uint
;
11933 LoR
: Ureal
:= No_Ureal
;
11934 HiR
: Ureal
:= No_Ureal
;
11935 LoSet
: Boolean := False;
11936 HiSet
: Boolean := False;
11939 Ancest
: Entity_Id
;
11940 R_Typ
: constant Entity_Id
:= Root_Type
(T
);
11943 -- If bad type, return 0
11945 if T
= Any_Type
then
11948 -- For generic types, just return zero. There cannot be any legitimate
11949 -- need to know such a size, but this routine may be called with a
11950 -- generic type as part of normal processing.
11952 elsif Is_Generic_Type
(R_Typ
) or else R_Typ
= Any_Type
then
11955 -- Access types (cannot have size smaller than System.Address)
11957 elsif Is_Access_Type
(T
) then
11958 return System_Address_Size
;
11960 -- Floating-point types
11962 elsif Is_Floating_Point_Type
(T
) then
11963 return UI_To_Int
(Esize
(R_Typ
));
11967 elsif Is_Discrete_Type
(T
) then
11969 -- The following loop is looking for the nearest compile time known
11970 -- bounds following the ancestor subtype chain. The idea is to find
11971 -- the most restrictive known bounds information.
11975 if Ancest
= Any_Type
or else Etype
(Ancest
) = Any_Type
then
11980 if Compile_Time_Known_Value
(Type_Low_Bound
(Ancest
)) then
11981 Lo
:= Expr_Rep_Value
(Type_Low_Bound
(Ancest
));
11988 if Compile_Time_Known_Value
(Type_High_Bound
(Ancest
)) then
11989 Hi
:= Expr_Rep_Value
(Type_High_Bound
(Ancest
));
11995 Ancest
:= Ancestor_Subtype
(Ancest
);
11997 if No
(Ancest
) then
11998 Ancest
:= Base_Type
(T
);
12000 if Is_Generic_Type
(Ancest
) then
12006 -- Fixed-point types. We can't simply use Expr_Value to get the
12007 -- Corresponding_Integer_Value values of the bounds, since these do not
12008 -- get set till the type is frozen, and this routine can be called
12009 -- before the type is frozen. Similarly the test for bounds being static
12010 -- needs to include the case where we have unanalyzed real literals for
12011 -- the same reason.
12013 elsif Is_Fixed_Point_Type
(T
) then
12015 -- The following loop is looking for the nearest compile time known
12016 -- bounds following the ancestor subtype chain. The idea is to find
12017 -- the most restrictive known bounds information.
12021 if Ancest
= Any_Type
or else Etype
(Ancest
) = Any_Type
then
12025 -- Note: In the following two tests for LoSet and HiSet, it may
12026 -- seem redundant to test for N_Real_Literal here since normally
12027 -- one would assume that the test for the value being known at
12028 -- compile time includes this case. However, there is a glitch.
12029 -- If the real literal comes from folding a non-static expression,
12030 -- then we don't consider any non- static expression to be known
12031 -- at compile time if we are in configurable run time mode (needed
12032 -- in some cases to give a clearer definition of what is and what
12033 -- is not accepted). So the test is indeed needed. Without it, we
12034 -- would set neither Lo_Set nor Hi_Set and get an infinite loop.
12037 if Nkind
(Type_Low_Bound
(Ancest
)) = N_Real_Literal
12038 or else Compile_Time_Known_Value
(Type_Low_Bound
(Ancest
))
12040 LoR
:= Expr_Value_R
(Type_Low_Bound
(Ancest
));
12047 if Nkind
(Type_High_Bound
(Ancest
)) = N_Real_Literal
12048 or else Compile_Time_Known_Value
(Type_High_Bound
(Ancest
))
12050 HiR
:= Expr_Value_R
(Type_High_Bound
(Ancest
));
12056 Ancest
:= Ancestor_Subtype
(Ancest
);
12058 if No
(Ancest
) then
12059 Ancest
:= Base_Type
(T
);
12061 if Is_Generic_Type
(Ancest
) then
12067 Lo
:= UR_To_Uint
(LoR
/ Small_Value
(T
));
12068 Hi
:= UR_To_Uint
(HiR
/ Small_Value
(T
));
12070 -- No other types allowed
12073 raise Program_Error
;
12076 -- Fall through with Hi and Lo set. Deal with biased case
12079 and then not Is_Fixed_Point_Type
(T
)
12080 and then not (Is_Enumeration_Type
(T
)
12081 and then Has_Non_Standard_Rep
(T
)))
12082 or else Has_Biased_Representation
(T
)
12088 -- Null range case, size is always zero. We only do this in the discrete
12089 -- type case, since that's the odd case that came up. Probably we should
12090 -- also do this in the fixed-point case, but doing so causes peculiar
12091 -- gigi failures, and it is not worth worrying about this incredibly
12092 -- marginal case (explicit null-range fixed-point type declarations)???
12094 if Lo
> Hi
and then Is_Discrete_Type
(T
) then
12097 -- Signed case. Note that we consider types like range 1 .. -1 to be
12098 -- signed for the purpose of computing the size, since the bounds have
12099 -- to be accommodated in the base type.
12101 elsif Lo
< 0 or else Hi
< 0 then
12105 -- S = size, B = 2 ** (size - 1) (can accommodate -B .. +(B - 1))
12106 -- Note that we accommodate the case where the bounds cross. This
12107 -- can happen either because of the way the bounds are declared
12108 -- or because of the algorithm in Freeze_Fixed_Point_Type.
12122 -- If both bounds are positive, make sure that both are represen-
12123 -- table in the case where the bounds are crossed. This can happen
12124 -- either because of the way the bounds are declared, or because of
12125 -- the algorithm in Freeze_Fixed_Point_Type.
12131 -- S = size, (can accommodate 0 .. (2**size - 1))
12134 while Hi
>= Uint_2
** S
loop
12142 ---------------------------
12143 -- New_Stream_Subprogram --
12144 ---------------------------
12146 procedure New_Stream_Subprogram
12150 Nam
: TSS_Name_Type
)
12152 Loc
: constant Source_Ptr
:= Sloc
(N
);
12153 Sname
: constant Name_Id
:= Make_TSS_Name
(Base_Type
(Ent
), Nam
);
12154 Subp_Id
: Entity_Id
;
12155 Subp_Decl
: Node_Id
;
12159 Defer_Declaration
: constant Boolean :=
12160 Is_Tagged_Type
(Ent
) or else Is_Private_Type
(Ent
);
12161 -- For a tagged type, there is a declaration for each stream attribute
12162 -- at the freeze point, and we must generate only a completion of this
12163 -- declaration. We do the same for private types, because the full view
12164 -- might be tagged. Otherwise we generate a declaration at the point of
12165 -- the attribute definition clause. If the attribute definition comes
12166 -- from an aspect specification the declaration is part of the freeze
12167 -- actions of the type.
12169 function Build_Spec
return Node_Id
;
12170 -- Used for declaration and renaming declaration, so that this is
12171 -- treated as a renaming_as_body.
12177 function Build_Spec
return Node_Id
is
12178 Out_P
: constant Boolean := (Nam
= TSS_Stream_Read
);
12181 T_Ref
: constant Node_Id
:= New_Occurrence_Of
(Etyp
, Loc
);
12184 Subp_Id
:= Make_Defining_Identifier
(Loc
, Sname
);
12186 -- S : access Root_Stream_Type'Class
12188 Formals
:= New_List
(
12189 Make_Parameter_Specification
(Loc
,
12190 Defining_Identifier
=>
12191 Make_Defining_Identifier
(Loc
, Name_S
),
12193 Make_Access_Definition
(Loc
,
12195 New_Occurrence_Of
(
12196 Designated_Type
(Etype
(F
)), Loc
))));
12198 if Nam
= TSS_Stream_Input
then
12200 Make_Function_Specification
(Loc
,
12201 Defining_Unit_Name
=> Subp_Id
,
12202 Parameter_Specifications
=> Formals
,
12203 Result_Definition
=> T_Ref
);
12207 Append_To
(Formals
,
12208 Make_Parameter_Specification
(Loc
,
12209 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_V
),
12210 Out_Present
=> Out_P
,
12211 Parameter_Type
=> T_Ref
));
12214 Make_Procedure_Specification
(Loc
,
12215 Defining_Unit_Name
=> Subp_Id
,
12216 Parameter_Specifications
=> Formals
);
12222 -- Start of processing for New_Stream_Subprogram
12225 F
:= First_Formal
(Subp
);
12227 if Ekind
(Subp
) = E_Procedure
then
12228 Etyp
:= Etype
(Next_Formal
(F
));
12230 Etyp
:= Etype
(Subp
);
12233 -- Prepare subprogram declaration and insert it as an action on the
12234 -- clause node. The visibility for this entity is used to test for
12235 -- visibility of the attribute definition clause (in the sense of
12236 -- 8.3(23) as amended by AI-195).
12238 if not Defer_Declaration
then
12240 Make_Subprogram_Declaration
(Loc
,
12241 Specification
=> Build_Spec
);
12243 -- For a tagged type, there is always a visible declaration for each
12244 -- stream TSS (it is a predefined primitive operation), and the
12245 -- completion of this declaration occurs at the freeze point, which is
12246 -- not always visible at places where the attribute definition clause is
12247 -- visible. So, we create a dummy entity here for the purpose of
12248 -- tracking the visibility of the attribute definition clause itself.
12252 Make_Defining_Identifier
(Loc
, New_External_Name
(Sname
, 'V'));
12254 Make_Object_Declaration
(Loc
,
12255 Defining_Identifier
=> Subp_Id
,
12256 Object_Definition
=> New_Occurrence_Of
(Standard_Boolean
, Loc
));
12259 if not Defer_Declaration
12260 and then From_Aspect_Specification
(N
)
12261 and then Has_Delayed_Freeze
(Ent
)
12263 Append_Freeze_Action
(Ent
, Subp_Decl
);
12266 Insert_Action
(N
, Subp_Decl
);
12267 Set_Entity
(N
, Subp_Id
);
12271 Make_Subprogram_Renaming_Declaration
(Loc
,
12272 Specification
=> Build_Spec
,
12273 Name
=> New_Occurrence_Of
(Subp
, Loc
));
12275 if Defer_Declaration
then
12276 Set_TSS
(Base_Type
(Ent
), Subp_Id
);
12279 if From_Aspect_Specification
(N
) then
12280 Append_Freeze_Action
(Ent
, Subp_Decl
);
12282 Insert_Action
(N
, Subp_Decl
);
12285 Copy_TSS
(Subp_Id
, Base_Type
(Ent
));
12287 end New_Stream_Subprogram
;
12289 ------------------------------------------
12290 -- Push_Scope_And_Install_Discriminants --
12291 ------------------------------------------
12293 procedure Push_Scope_And_Install_Discriminants
(E
: Entity_Id
) is
12295 if Has_Discriminants
(E
) then
12298 -- Make the discriminants visible for type declarations and protected
12299 -- type declarations, not for subtype declarations (RM 13.1.1 (12/3))
12301 if Nkind
(Parent
(E
)) /= N_Subtype_Declaration
then
12302 Install_Discriminants
(E
);
12305 end Push_Scope_And_Install_Discriminants
;
12307 -----------------------------------
12308 -- Register_Address_Clause_Check --
12309 -----------------------------------
12311 procedure Register_Address_Clause_Check
12318 ACS
: constant Boolean := Scope_Suppress
.Suppress
(Alignment_Check
);
12320 Address_Clause_Checks
.Append
((N
, X
, A
, Y
, Off
, ACS
));
12321 end Register_Address_Clause_Check
;
12323 ------------------------
12324 -- Rep_Item_Too_Early --
12325 ------------------------
12327 function Rep_Item_Too_Early
(T
: Entity_Id
; N
: Node_Id
) return Boolean is
12329 -- Cannot apply non-operational rep items to generic types
12331 if Is_Operational_Item
(N
) then
12335 and then Is_Generic_Type
(Root_Type
(T
))
12336 and then (Nkind
(N
) /= N_Pragma
12337 or else Get_Pragma_Id
(N
) /= Pragma_Convention
)
12339 Error_Msg_N
("representation item not allowed for generic type", N
);
12343 -- Otherwise check for incomplete type
12345 if Is_Incomplete_Or_Private_Type
(T
)
12346 and then No
(Underlying_Type
(T
))
12348 (Nkind
(N
) /= N_Pragma
12349 or else Get_Pragma_Id
(N
) /= Pragma_Import
)
12352 ("representation item must be after full type declaration", N
);
12355 -- If the type has incomplete components, a representation clause is
12356 -- illegal but stream attributes and Convention pragmas are correct.
12358 elsif Has_Private_Component
(T
) then
12359 if Nkind
(N
) = N_Pragma
then
12364 ("representation item must appear after type is fully defined",
12371 end Rep_Item_Too_Early
;
12373 -----------------------
12374 -- Rep_Item_Too_Late --
12375 -----------------------
12377 function Rep_Item_Too_Late
12380 FOnly
: Boolean := False) return Boolean
12383 Parent_Type
: Entity_Id
;
12385 procedure No_Type_Rep_Item
;
12386 -- Output message indicating that no type-related aspects can be
12387 -- specified due to some property of the parent type.
12389 procedure Too_Late
;
12390 -- Output message for an aspect being specified too late
12392 -- Note that neither of the above errors is considered a serious one,
12393 -- since the effect is simply that we ignore the representation clause
12395 -- Is this really true? In any case if we make this change we must
12396 -- document the requirement in the spec of Rep_Item_Too_Late that
12397 -- if True is returned, then the rep item must be completely ignored???
12399 ----------------------
12400 -- No_Type_Rep_Item --
12401 ----------------------
12403 procedure No_Type_Rep_Item
is
12405 Error_Msg_N
("|type-related representation item not permitted!", N
);
12406 end No_Type_Rep_Item
;
12412 procedure Too_Late
is
12414 -- Other compilers seem more relaxed about rep items appearing too
12415 -- late. Since analysis tools typically don't care about rep items
12416 -- anyway, no reason to be too strict about this.
12418 if not Relaxed_RM_Semantics
then
12419 Error_Msg_N
("|representation item appears too late!", N
);
12423 -- Start of processing for Rep_Item_Too_Late
12426 -- First make sure entity is not frozen (RM 13.1(9))
12430 -- Exclude imported types, which may be frozen if they appear in a
12431 -- representation clause for a local type.
12433 and then not From_Limited_With
(T
)
12435 -- Exclude generated entities (not coming from source). The common
12436 -- case is when we generate a renaming which prematurely freezes the
12437 -- renamed internal entity, but we still want to be able to set copies
12438 -- of attribute values such as Size/Alignment.
12440 and then Comes_From_Source
(T
)
12442 -- A self-referential aspect is illegal if it forces freezing the
12443 -- entity before the corresponding pragma has been analyzed.
12445 if Nkind_In
(N
, N_Attribute_Definition_Clause
, N_Pragma
)
12446 and then From_Aspect_Specification
(N
)
12449 ("aspect specification causes premature freezing of&", N
, T
);
12450 Set_Has_Delayed_Freeze
(T
, False);
12455 S
:= First_Subtype
(T
);
12457 if Present
(Freeze_Node
(S
)) then
12458 if not Relaxed_RM_Semantics
then
12460 ("??no more representation items for }", Freeze_Node
(S
), S
);
12466 -- Check for case of untagged derived type whose parent either has
12467 -- primitive operations, or is a by reference type (RM 13.1(10)). In
12468 -- this case we do not output a Too_Late message, since there is no
12469 -- earlier point where the rep item could be placed to make it legal.
12473 and then Is_Derived_Type
(T
)
12474 and then not Is_Tagged_Type
(T
)
12476 Parent_Type
:= Etype
(Base_Type
(T
));
12478 if Has_Primitive_Operations
(Parent_Type
) then
12481 if not Relaxed_RM_Semantics
then
12483 ("\parent type & has primitive operations!", N
, Parent_Type
);
12488 elsif Is_By_Reference_Type
(Parent_Type
) then
12491 if not Relaxed_RM_Semantics
then
12493 ("\parent type & is a by reference type!", N
, Parent_Type
);
12500 -- No error, but one more warning to consider. The RM (surprisingly)
12501 -- allows this pattern:
12504 -- primitive operations for S
12505 -- type R is new S;
12506 -- rep clause for S
12508 -- Meaning that calls on the primitive operations of S for values of
12509 -- type R may require possibly expensive implicit conversion operations.
12510 -- This is not an error, but is worth a warning.
12512 if not Relaxed_RM_Semantics
and then Is_Type
(T
) then
12514 DTL
: constant Entity_Id
:= Derived_Type_Link
(Base_Type
(T
));
12518 and then Has_Primitive_Operations
(Base_Type
(T
))
12520 -- For now, do not generate this warning for the case of aspect
12521 -- specification using Ada 2012 syntax, since we get wrong
12522 -- messages we do not understand. The whole business of derived
12523 -- types and rep items seems a bit confused when aspects are
12524 -- used, since the aspects are not evaluated till freeze time.
12526 and then not From_Aspect_Specification
(N
)
12528 Error_Msg_Sloc
:= Sloc
(DTL
);
12530 ("representation item for& appears after derived type "
12531 & "declaration#??", N
);
12533 ("\may result in implicit conversions for primitive "
12534 & "operations of&??", N
, T
);
12536 ("\to change representations when called with arguments "
12537 & "of type&??", N
, DTL
);
12542 -- No error, link item into head of chain of rep items for the entity,
12543 -- but avoid chaining if we have an overloadable entity, and the pragma
12544 -- is one that can apply to multiple overloaded entities.
12546 if Is_Overloadable
(T
) and then Nkind
(N
) = N_Pragma
then
12548 Pname
: constant Name_Id
:= Pragma_Name
(N
);
12550 if Nam_In
(Pname
, Name_Convention
, Name_Import
, Name_Export
,
12551 Name_External
, Name_Interface
)
12558 Record_Rep_Item
(T
, N
);
12560 end Rep_Item_Too_Late
;
12562 -------------------------------------
12563 -- Replace_Type_References_Generic --
12564 -------------------------------------
12566 procedure Replace_Type_References_Generic
(N
: Node_Id
; T
: Entity_Id
) is
12567 TName
: constant Name_Id
:= Chars
(T
);
12569 function Replace_Type_Ref
(N
: Node_Id
) return Traverse_Result
;
12570 -- Processes a single node in the traversal procedure below, checking
12571 -- if node N should be replaced, and if so, doing the replacement.
12573 function Visible_Component
(Comp
: Name_Id
) return Entity_Id
;
12574 -- Given an identifier in the expression, check whether there is a
12575 -- discriminant or component of the type that is directy visible, and
12576 -- rewrite it as the corresponding selected component of the formal of
12577 -- the subprogram. The entity is located by a sequential search, which
12578 -- seems acceptable given the typical size of component lists and check
12579 -- expressions. Possible optimization ???
12581 ----------------------
12582 -- Replace_Type_Ref --
12583 ----------------------
12585 function Replace_Type_Ref
(N
: Node_Id
) return Traverse_Result
is
12586 Loc
: constant Source_Ptr
:= Sloc
(N
);
12588 procedure Add_Prefix
(Ref
: Node_Id
; Comp
: Entity_Id
);
12589 -- Add the proper prefix to a reference to a component of the type
12590 -- when it is not already a selected component.
12596 procedure Add_Prefix
(Ref
: Node_Id
; Comp
: Entity_Id
) is
12599 Make_Selected_Component
(Loc
,
12600 Prefix
=> New_Occurrence_Of
(T
, Loc
),
12601 Selector_Name
=> New_Occurrence_Of
(Comp
, Loc
)));
12602 Replace_Type_Reference
(Prefix
(Ref
));
12611 -- Start of processing for Replace_Type_Ref
12614 if Nkind
(N
) = N_Identifier
then
12616 -- If not the type name, check whether it is a reference to some
12617 -- other type, which must be frozen before the predicate function
12618 -- is analyzed, i.e. before the freeze node of the type to which
12619 -- the predicate applies.
12621 if Chars
(N
) /= TName
then
12622 if Present
(Current_Entity
(N
))
12623 and then Is_Type
(Current_Entity
(N
))
12625 Freeze_Before
(Freeze_Node
(T
), Current_Entity
(N
));
12628 -- The components of the type are directly visible and can
12629 -- be referenced without a prefix.
12631 if Nkind
(Parent
(N
)) = N_Selected_Component
then
12634 -- In expression C (I), C may be a directly visible function
12635 -- or a visible component that has an array type. Disambiguate
12636 -- by examining the component type.
12638 elsif Nkind
(Parent
(N
)) = N_Indexed_Component
12639 and then N
= Prefix
(Parent
(N
))
12641 Comp
:= Visible_Component
(Chars
(N
));
12643 if Present
(Comp
) and then Is_Array_Type
(Etype
(Comp
)) then
12644 Add_Prefix
(N
, Comp
);
12648 Comp
:= Visible_Component
(Chars
(N
));
12650 if Present
(Comp
) then
12651 Add_Prefix
(N
, Comp
);
12657 -- Otherwise do the replacement and we are done with this node
12660 Replace_Type_Reference
(N
);
12664 -- Case of selected component (which is what a qualification looks
12665 -- like in the unanalyzed tree, which is what we have.
12667 elsif Nkind
(N
) = N_Selected_Component
then
12669 -- If selector name is not our type, keeping going (we might still
12670 -- have an occurrence of the type in the prefix).
12672 if Nkind
(Selector_Name
(N
)) /= N_Identifier
12673 or else Chars
(Selector_Name
(N
)) /= TName
12677 -- Selector name is our type, check qualification
12680 -- Loop through scopes and prefixes, doing comparison
12682 Scop
:= Current_Scope
;
12683 Pref
:= Prefix
(N
);
12685 -- Continue if no more scopes or scope with no name
12687 if No
(Scop
) or else Nkind
(Scop
) not in N_Has_Chars
then
12691 -- Do replace if prefix is an identifier matching the scope
12692 -- that we are currently looking at.
12694 if Nkind
(Pref
) = N_Identifier
12695 and then Chars
(Pref
) = Chars
(Scop
)
12697 Replace_Type_Reference
(N
);
12701 -- Go check scope above us if prefix is itself of the form
12702 -- of a selected component, whose selector matches the scope
12703 -- we are currently looking at.
12705 if Nkind
(Pref
) = N_Selected_Component
12706 and then Nkind
(Selector_Name
(Pref
)) = N_Identifier
12707 and then Chars
(Selector_Name
(Pref
)) = Chars
(Scop
)
12709 Scop
:= Scope
(Scop
);
12710 Pref
:= Prefix
(Pref
);
12712 -- For anything else, we don't have a match, so keep on
12713 -- going, there are still some weird cases where we may
12714 -- still have a replacement within the prefix.
12722 -- Continue for any other node kind
12727 end Replace_Type_Ref
;
12729 procedure Replace_Type_Refs
is new Traverse_Proc
(Replace_Type_Ref
);
12731 -----------------------
12732 -- Visible_Component --
12733 -----------------------
12735 function Visible_Component
(Comp
: Name_Id
) return Entity_Id
is
12739 -- Types with nameable components are records and discriminated
12742 if Ekind
(T
) = E_Record_Type
12743 or else (Is_Private_Type
(T
) and then Has_Discriminants
(T
))
12745 E
:= First_Entity
(T
);
12746 while Present
(E
) loop
12747 if Comes_From_Source
(E
) and then Chars
(E
) = Comp
then
12755 -- Nothing by that name, or the type has no components
12758 end Visible_Component
;
12760 -- Start of processing for Replace_Type_References_Generic
12763 Replace_Type_Refs
(N
);
12764 end Replace_Type_References_Generic
;
12766 --------------------------------
12767 -- Resolve_Aspect_Expressions --
12768 --------------------------------
12770 procedure Resolve_Aspect_Expressions
(E
: Entity_Id
) is
12771 function Resolve_Name
(N
: Node_Id
) return Traverse_Result
;
12772 -- Verify that all identifiers in the expression, with the exception
12773 -- of references to the current entity, denote visible entities. This
12774 -- is done only to detect visibility errors, as the expression will be
12775 -- properly analyzed/expanded during analysis of the predicate function
12776 -- body. We omit quantified expressions from this test, given that they
12777 -- introduce a local identifier that would require proper expansion to
12778 -- handle properly.
12780 -- In ASIS_Mode we preserve the entity in the source because there is
12781 -- no subsequent expansion to decorate the tree.
12787 function Resolve_Name
(N
: Node_Id
) return Traverse_Result
is
12788 Dummy
: Traverse_Result
;
12791 if Nkind
(N
) = N_Selected_Component
then
12792 if Nkind
(Prefix
(N
)) = N_Identifier
12793 and then Chars
(Prefix
(N
)) /= Chars
(E
)
12795 Find_Selected_Component
(N
);
12800 -- Resolve identifiers that are not selectors in parameter
12801 -- associations (these are never resolved by visibility).
12803 elsif Nkind
(N
) = N_Identifier
12804 and then Chars
(N
) /= Chars
(E
)
12805 and then (Nkind
(Parent
(N
)) /= N_Parameter_Association
12806 or else N
/= Selector_Name
(Parent
(N
)))
12808 Find_Direct_Name
(N
);
12810 -- In ASIS mode we must analyze overloaded identifiers to ensure
12811 -- their correct decoration because expansion is disabled (and
12812 -- the expansion of freeze nodes takes care of resolving aspect
12816 if Is_Overloaded
(N
) then
12817 Analyze
(Parent
(N
));
12820 Set_Entity
(N
, Empty
);
12823 -- The name is component association needs no resolution.
12825 elsif Nkind
(N
) = N_Component_Association
then
12826 Dummy
:= Resolve_Name
(Expression
(N
));
12829 elsif Nkind
(N
) = N_Quantified_Expression
then
12836 procedure Resolve_Aspect_Expression
is new Traverse_Proc
(Resolve_Name
);
12840 ASN
: Node_Id
:= First_Rep_Item
(E
);
12842 -- Start of processing for Resolve_Aspect_Expressions
12845 -- Need to make sure discriminants, if any, are directly visible
12847 Push_Scope_And_Install_Discriminants
(E
);
12849 while Present
(ASN
) loop
12850 if Nkind
(ASN
) = N_Aspect_Specification
and then Entity
(ASN
) = E
then
12852 A_Id
: constant Aspect_Id
:= Get_Aspect_Id
(ASN
);
12853 Expr
: constant Node_Id
:= Expression
(ASN
);
12858 -- For now we only deal with aspects that do not generate
12859 -- subprograms, or that may mention current instances of
12860 -- types. These will require special handling (???TBD).
12862 when Aspect_Invariant
12864 | Aspect_Predicate_Failure
12868 when Aspect_Dynamic_Predicate
12869 | Aspect_Static_Predicate
12871 -- Build predicate function specification and preanalyze
12872 -- expression after type replacement. The function
12873 -- declaration must be analyzed in the scope of the
12874 -- type, but the expression must see components.
12876 if No
(Predicate_Function
(E
)) then
12877 Uninstall_Discriminants_And_Pop_Scope
(E
);
12879 FDecl
: constant Node_Id
:=
12880 Build_Predicate_Function_Declaration
(E
);
12881 pragma Unreferenced
(FDecl
);
12884 Push_Scope_And_Install_Discriminants
(E
);
12885 Resolve_Aspect_Expression
(Expr
);
12889 when Pre_Post_Aspects
=>
12892 when Aspect_Iterable
=>
12893 if Nkind
(Expr
) = N_Aggregate
then
12898 Assoc
:= First
(Component_Associations
(Expr
));
12899 while Present
(Assoc
) loop
12900 Find_Direct_Name
(Expression
(Assoc
));
12906 -- The expression for Default_Value is a static expression
12907 -- of the type, but this expression does not freeze the
12908 -- type, so it can still appear in a representation clause
12909 -- before the actual freeze point.
12911 when Aspect_Default_Value
=>
12912 Set_Must_Not_Freeze
(Expr
);
12913 Preanalyze_Spec_Expression
(Expr
, E
);
12916 if Present
(Expr
) then
12917 case Aspect_Argument
(A_Id
) is
12919 | Optional_Expression
12921 Analyze_And_Resolve
(Expr
);
12926 if Nkind
(Expr
) = N_Identifier
then
12927 Find_Direct_Name
(Expr
);
12929 elsif Nkind
(Expr
) = N_Selected_Component
then
12930 Find_Selected_Component
(Expr
);
12938 ASN
:= Next_Rep_Item
(ASN
);
12941 Uninstall_Discriminants_And_Pop_Scope
(E
);
12942 end Resolve_Aspect_Expressions
;
12944 -------------------------
12945 -- Same_Representation --
12946 -------------------------
12948 function Same_Representation
(Typ1
, Typ2
: Entity_Id
) return Boolean is
12949 T1
: constant Entity_Id
:= Underlying_Type
(Typ1
);
12950 T2
: constant Entity_Id
:= Underlying_Type
(Typ2
);
12953 -- A quick check, if base types are the same, then we definitely have
12954 -- the same representation, because the subtype specific representation
12955 -- attributes (Size and Alignment) do not affect representation from
12956 -- the point of view of this test.
12958 if Base_Type
(T1
) = Base_Type
(T2
) then
12961 elsif Is_Private_Type
(Base_Type
(T2
))
12962 and then Base_Type
(T1
) = Full_View
(Base_Type
(T2
))
12967 -- Tagged types always have the same representation, because it is not
12968 -- possible to specify different representations for common fields.
12970 if Is_Tagged_Type
(T1
) then
12974 -- Representations are definitely different if conventions differ
12976 if Convention
(T1
) /= Convention
(T2
) then
12980 -- Representations are different if component alignments or scalar
12981 -- storage orders differ.
12983 if (Is_Record_Type
(T1
) or else Is_Array_Type
(T1
))
12985 (Is_Record_Type
(T2
) or else Is_Array_Type
(T2
))
12987 (Component_Alignment
(T1
) /= Component_Alignment
(T2
)
12988 or else Reverse_Storage_Order
(T1
) /= Reverse_Storage_Order
(T2
))
12993 -- For arrays, the only real issue is component size. If we know the
12994 -- component size for both arrays, and it is the same, then that's
12995 -- good enough to know we don't have a change of representation.
12997 if Is_Array_Type
(T1
) then
12998 if Known_Component_Size
(T1
)
12999 and then Known_Component_Size
(T2
)
13000 and then Component_Size
(T1
) = Component_Size
(T2
)
13006 -- For records, representations are different if reorderings differ
13008 if Is_Record_Type
(T1
)
13009 and then Is_Record_Type
(T2
)
13010 and then No_Reordering
(T1
) /= No_Reordering
(T2
)
13015 -- Types definitely have same representation if neither has non-standard
13016 -- representation since default representations are always consistent.
13017 -- If only one has non-standard representation, and the other does not,
13018 -- then we consider that they do not have the same representation. They
13019 -- might, but there is no way of telling early enough.
13021 if Has_Non_Standard_Rep
(T1
) then
13022 if not Has_Non_Standard_Rep
(T2
) then
13026 return not Has_Non_Standard_Rep
(T2
);
13029 -- Here the two types both have non-standard representation, and we need
13030 -- to determine if they have the same non-standard representation.
13032 -- For arrays, we simply need to test if the component sizes are the
13033 -- same. Pragma Pack is reflected in modified component sizes, so this
13034 -- check also deals with pragma Pack.
13036 if Is_Array_Type
(T1
) then
13037 return Component_Size
(T1
) = Component_Size
(T2
);
13039 -- Case of record types
13041 elsif Is_Record_Type
(T1
) then
13043 -- Packed status must conform
13045 if Is_Packed
(T1
) /= Is_Packed
(T2
) then
13048 -- Otherwise we must check components. Typ2 maybe a constrained
13049 -- subtype with fewer components, so we compare the components
13050 -- of the base types.
13053 Record_Case
: declare
13054 CD1
, CD2
: Entity_Id
;
13056 function Same_Rep
return Boolean;
13057 -- CD1 and CD2 are either components or discriminants. This
13058 -- function tests whether they have the same representation.
13064 function Same_Rep
return Boolean is
13066 if No
(Component_Clause
(CD1
)) then
13067 return No
(Component_Clause
(CD2
));
13069 -- Note: at this point, component clauses have been
13070 -- normalized to the default bit order, so that the
13071 -- comparison of Component_Bit_Offsets is meaningful.
13074 Present
(Component_Clause
(CD2
))
13076 Component_Bit_Offset
(CD1
) = Component_Bit_Offset
(CD2
)
13078 Esize
(CD1
) = Esize
(CD2
);
13082 -- Start of processing for Record_Case
13085 if Has_Discriminants
(T1
) then
13087 -- The number of discriminants may be different if the
13088 -- derived type has fewer (constrained by values). The
13089 -- invisible discriminants retain the representation of
13090 -- the original, so the discrepancy does not per se
13091 -- indicate a different representation.
13093 CD1
:= First_Discriminant
(T1
);
13094 CD2
:= First_Discriminant
(T2
);
13095 while Present
(CD1
) and then Present
(CD2
) loop
13096 if not Same_Rep
then
13099 Next_Discriminant
(CD1
);
13100 Next_Discriminant
(CD2
);
13105 CD1
:= First_Component
(Underlying_Type
(Base_Type
(T1
)));
13106 CD2
:= First_Component
(Underlying_Type
(Base_Type
(T2
)));
13107 while Present
(CD1
) loop
13108 if not Same_Rep
then
13111 Next_Component
(CD1
);
13112 Next_Component
(CD2
);
13120 -- For enumeration types, we must check each literal to see if the
13121 -- representation is the same. Note that we do not permit enumeration
13122 -- representation clauses for Character and Wide_Character, so these
13123 -- cases were already dealt with.
13125 elsif Is_Enumeration_Type
(T1
) then
13126 Enumeration_Case
: declare
13127 L1
, L2
: Entity_Id
;
13130 L1
:= First_Literal
(T1
);
13131 L2
:= First_Literal
(T2
);
13132 while Present
(L1
) loop
13133 if Enumeration_Rep
(L1
) /= Enumeration_Rep
(L2
) then
13142 end Enumeration_Case
;
13144 -- Any other types have the same representation for these purposes
13149 end Same_Representation
;
13151 --------------------------------
13152 -- Resolve_Iterable_Operation --
13153 --------------------------------
13155 procedure Resolve_Iterable_Operation
13157 Cursor
: Entity_Id
;
13166 if not Is_Overloaded
(N
) then
13167 if not Is_Entity_Name
(N
)
13168 or else Ekind
(Entity
(N
)) /= E_Function
13169 or else Scope
(Entity
(N
)) /= Scope
(Typ
)
13170 or else No
(First_Formal
(Entity
(N
)))
13171 or else Etype
(First_Formal
(Entity
(N
))) /= Typ
13173 Error_Msg_N
("iterable primitive must be local function name "
13174 & "whose first formal is an iterable type", N
);
13179 F1
:= First_Formal
(Ent
);
13180 if Nam
= Name_First
then
13182 -- First (Container) => Cursor
13184 if Etype
(Ent
) /= Cursor
then
13185 Error_Msg_N
("primitive for First must yield a curosr", N
);
13188 elsif Nam
= Name_Next
then
13190 -- Next (Container, Cursor) => Cursor
13192 F2
:= Next_Formal
(F1
);
13194 if Etype
(F2
) /= Cursor
13195 or else Etype
(Ent
) /= Cursor
13196 or else Present
(Next_Formal
(F2
))
13198 Error_Msg_N
("no match for Next iterable primitive", N
);
13201 elsif Nam
= Name_Has_Element
then
13203 -- Has_Element (Container, Cursor) => Boolean
13205 F2
:= Next_Formal
(F1
);
13206 if Etype
(F2
) /= Cursor
13207 or else Etype
(Ent
) /= Standard_Boolean
13208 or else Present
(Next_Formal
(F2
))
13210 Error_Msg_N
("no match for Has_Element iterable primitive", N
);
13213 elsif Nam
= Name_Element
then
13214 F2
:= Next_Formal
(F1
);
13217 or else Etype
(F2
) /= Cursor
13218 or else Present
(Next_Formal
(F2
))
13220 Error_Msg_N
("no match for Element iterable primitive", N
);
13225 raise Program_Error
;
13229 -- Overloaded case: find subprogram with proper signature.
13230 -- Caller will report error if no match is found.
13237 Get_First_Interp
(N
, I
, It
);
13238 while Present
(It
.Typ
) loop
13239 if Ekind
(It
.Nam
) = E_Function
13240 and then Scope
(It
.Nam
) = Scope
(Typ
)
13241 and then Etype
(First_Formal
(It
.Nam
)) = Typ
13243 F1
:= First_Formal
(It
.Nam
);
13245 if Nam
= Name_First
then
13246 if Etype
(It
.Nam
) = Cursor
13247 and then No
(Next_Formal
(F1
))
13249 Set_Entity
(N
, It
.Nam
);
13253 elsif Nam
= Name_Next
then
13254 F2
:= Next_Formal
(F1
);
13257 and then No
(Next_Formal
(F2
))
13258 and then Etype
(F2
) = Cursor
13259 and then Etype
(It
.Nam
) = Cursor
13261 Set_Entity
(N
, It
.Nam
);
13265 elsif Nam
= Name_Has_Element
then
13266 F2
:= Next_Formal
(F1
);
13269 and then No
(Next_Formal
(F2
))
13270 and then Etype
(F2
) = Cursor
13271 and then Etype
(It
.Nam
) = Standard_Boolean
13273 Set_Entity
(N
, It
.Nam
);
13274 F2
:= Next_Formal
(F1
);
13278 elsif Nam
= Name_Element
then
13279 F2
:= Next_Formal
(F1
);
13282 and then No
(Next_Formal
(F2
))
13283 and then Etype
(F2
) = Cursor
13285 Set_Entity
(N
, It
.Nam
);
13291 Get_Next_Interp
(I
, It
);
13295 end Resolve_Iterable_Operation
;
13301 procedure Set_Biased
13305 Biased
: Boolean := True)
13309 Set_Has_Biased_Representation
(E
);
13311 if Warn_On_Biased_Representation
then
13313 ("?B?" & Msg
& " forces biased representation for&", N
, E
);
13318 --------------------
13319 -- Set_Enum_Esize --
13320 --------------------
13322 procedure Set_Enum_Esize
(T
: Entity_Id
) is
13328 Init_Alignment
(T
);
13330 -- Find the minimum standard size (8,16,32,64) that fits
13332 Lo
:= Enumeration_Rep
(Entity
(Type_Low_Bound
(T
)));
13333 Hi
:= Enumeration_Rep
(Entity
(Type_High_Bound
(T
)));
13336 if Lo
>= -Uint_2
**07 and then Hi
< Uint_2
**07 then
13337 Sz
:= Standard_Character_Size
; -- May be > 8 on some targets
13339 elsif Lo
>= -Uint_2
**15 and then Hi
< Uint_2
**15 then
13342 elsif Lo
>= -Uint_2
**31 and then Hi
< Uint_2
**31 then
13345 else pragma Assert
(Lo
>= -Uint_2
**63 and then Hi
< Uint_2
**63);
13350 if Hi
< Uint_2
**08 then
13351 Sz
:= Standard_Character_Size
; -- May be > 8 on some targets
13353 elsif Hi
< Uint_2
**16 then
13356 elsif Hi
< Uint_2
**32 then
13359 else pragma Assert
(Hi
< Uint_2
**63);
13364 -- That minimum is the proper size unless we have a foreign convention
13365 -- and the size required is 32 or less, in which case we bump the size
13366 -- up to 32. This is required for C and C++ and seems reasonable for
13367 -- all other foreign conventions.
13369 if Has_Foreign_Convention
(T
)
13370 and then Esize
(T
) < Standard_Integer_Size
13372 -- Don't do this if Short_Enums on target
13374 and then not Target_Short_Enums
13376 Init_Esize
(T
, Standard_Integer_Size
);
13378 Init_Esize
(T
, Sz
);
13380 end Set_Enum_Esize
;
13382 -----------------------------
13383 -- Uninstall_Discriminants --
13384 -----------------------------
13386 procedure Uninstall_Discriminants
(E
: Entity_Id
) is
13392 -- Discriminants have been made visible for type declarations and
13393 -- protected type declarations, not for subtype declarations.
13395 if Nkind
(Parent
(E
)) /= N_Subtype_Declaration
then
13396 Disc
:= First_Discriminant
(E
);
13397 while Present
(Disc
) loop
13398 if Disc
/= Current_Entity
(Disc
) then
13399 Prev
:= Current_Entity
(Disc
);
13400 while Present
(Prev
)
13401 and then Present
(Homonym
(Prev
))
13402 and then Homonym
(Prev
) /= Disc
13404 Prev
:= Homonym
(Prev
);
13410 Set_Is_Immediately_Visible
(Disc
, False);
13412 Outer
:= Homonym
(Disc
);
13413 while Present
(Outer
) and then Scope
(Outer
) = E
loop
13414 Outer
:= Homonym
(Outer
);
13417 -- Reset homonym link of other entities, but do not modify link
13418 -- between entities in current scope, so that the back end can
13419 -- have a proper count of local overloadings.
13422 Set_Name_Entity_Id
(Chars
(Disc
), Outer
);
13424 elsif Scope
(Prev
) /= Scope
(Disc
) then
13425 Set_Homonym
(Prev
, Outer
);
13428 Next_Discriminant
(Disc
);
13431 end Uninstall_Discriminants
;
13433 -------------------------------------------
13434 -- Uninstall_Discriminants_And_Pop_Scope --
13435 -------------------------------------------
13437 procedure Uninstall_Discriminants_And_Pop_Scope
(E
: Entity_Id
) is
13439 if Has_Discriminants
(E
) then
13440 Uninstall_Discriminants
(E
);
13443 end Uninstall_Discriminants_And_Pop_Scope
;
13445 ------------------------------
13446 -- Validate_Address_Clauses --
13447 ------------------------------
13449 procedure Validate_Address_Clauses
is
13450 function Offset_Value
(Expr
: Node_Id
) return Uint
;
13451 -- Given an Address attribute reference, return the value in bits of its
13452 -- offset from the first bit of the underlying entity, or 0 if it is not
13453 -- known at compile time.
13459 function Offset_Value
(Expr
: Node_Id
) return Uint
is
13460 N
: Node_Id
:= Prefix
(Expr
);
13462 Val
: Uint
:= Uint_0
;
13465 -- Climb the prefix chain and compute the cumulative offset
13468 if Is_Entity_Name
(N
) then
13471 elsif Nkind
(N
) = N_Selected_Component
then
13472 Off
:= Component_Bit_Offset
(Entity
(Selector_Name
(N
)));
13473 if Off
/= No_Uint
and then Off
>= Uint_0
then
13480 elsif Nkind
(N
) = N_Indexed_Component
then
13481 Off
:= Indexed_Component_Bit_Offset
(N
);
13482 if Off
/= No_Uint
then
13495 -- Start of processing for Validate_Address_Clauses
13498 for J
in Address_Clause_Checks
.First
.. Address_Clause_Checks
.Last
loop
13500 ACCR
: Address_Clause_Check_Record
13501 renames Address_Clause_Checks
.Table
(J
);
13505 X_Alignment
: Uint
;
13506 Y_Alignment
: Uint
:= Uint_0
;
13509 Y_Size
: Uint
:= Uint_0
;
13514 -- Skip processing of this entry if warning already posted
13516 if not Address_Warning_Posted
(ACCR
.N
) then
13517 Expr
:= Original_Node
(Expression
(ACCR
.N
));
13519 -- Get alignments, sizes and offset, if any
13521 X_Alignment
:= Alignment
(ACCR
.X
);
13522 X_Size
:= Esize
(ACCR
.X
);
13524 if Present
(ACCR
.Y
) then
13525 Y_Alignment
:= Alignment
(ACCR
.Y
);
13526 Y_Size
:= Esize
(ACCR
.Y
);
13530 and then Nkind
(Expr
) = N_Attribute_Reference
13531 and then Attribute_Name
(Expr
) = Name_Address
13533 X_Offs
:= Offset_Value
(Expr
);
13538 -- Check for known value not multiple of alignment
13540 if No
(ACCR
.Y
) then
13541 if not Alignment_Checks_Suppressed
(ACCR
)
13542 and then X_Alignment
/= 0
13543 and then ACCR
.A
mod X_Alignment
/= 0
13546 ("??specified address for& is inconsistent with "
13547 & "alignment", ACCR
.N
, ACCR
.X
);
13549 ("\??program execution may be erroneous (RM 13.3(27))",
13552 Error_Msg_Uint_1
:= X_Alignment
;
13553 Error_Msg_NE
("\??alignment of & is ^", ACCR
.N
, ACCR
.X
);
13556 -- Check for large object overlaying smaller one
13558 elsif Y_Size
> Uint_0
13559 and then X_Size
> Uint_0
13560 and then X_Offs
+ X_Size
> Y_Size
13562 Error_Msg_NE
("??& overlays smaller object", ACCR
.N
, ACCR
.X
);
13564 ("\??program execution may be erroneous", ACCR
.N
);
13566 Error_Msg_Uint_1
:= X_Size
;
13567 Error_Msg_NE
("\??size of & is ^", ACCR
.N
, ACCR
.X
);
13569 Error_Msg_Uint_1
:= Y_Size
;
13570 Error_Msg_NE
("\??size of & is ^", ACCR
.N
, ACCR
.Y
);
13572 if Y_Size
>= X_Size
then
13573 Error_Msg_Uint_1
:= X_Offs
;
13574 Error_Msg_NE
("\??but offset of & is ^", ACCR
.N
, ACCR
.X
);
13577 -- Check for inadequate alignment, both of the base object
13578 -- and of the offset, if any. We only do this check if the
13579 -- run-time Alignment_Check is active. No point in warning
13580 -- if this check has been suppressed (or is suppressed by
13581 -- default in the non-strict alignment machine case).
13583 -- Note: we do not check the alignment if we gave a size
13584 -- warning, since it would likely be redundant.
13586 elsif not Alignment_Checks_Suppressed
(ACCR
)
13587 and then Y_Alignment
/= Uint_0
13589 (Y_Alignment
< X_Alignment
13592 and then Nkind
(Expr
) = N_Attribute_Reference
13593 and then Attribute_Name
(Expr
) = Name_Address
13594 and then Has_Compatible_Alignment
13595 (ACCR
.X
, Prefix
(Expr
), True) /=
13599 ("??specified address for& may be inconsistent with "
13600 & "alignment", ACCR
.N
, ACCR
.X
);
13602 ("\??program execution may be erroneous (RM 13.3(27))",
13605 Error_Msg_Uint_1
:= X_Alignment
;
13606 Error_Msg_NE
("\??alignment of & is ^", ACCR
.N
, ACCR
.X
);
13608 Error_Msg_Uint_1
:= Y_Alignment
;
13609 Error_Msg_NE
("\??alignment of & is ^", ACCR
.N
, ACCR
.Y
);
13611 if Y_Alignment
>= X_Alignment
then
13613 ("\??but offset is not multiple of alignment", ACCR
.N
);
13619 end Validate_Address_Clauses
;
13621 -----------------------------------------
13622 -- Validate_Compile_Time_Warning_Error --
13623 -----------------------------------------
13625 procedure Validate_Compile_Time_Warning_Error
(N
: Node_Id
) is
13627 Compile_Time_Warnings_Errors
.Append
13628 (New_Val
=> CTWE_Entry
'(Eloc => Sloc (N),
13629 Scope => Current_Scope,
13631 end Validate_Compile_Time_Warning_Error;
13633 ------------------------------------------
13634 -- Validate_Compile_Time_Warning_Errors --
13635 ------------------------------------------
13637 procedure Validate_Compile_Time_Warning_Errors is
13638 procedure Set_Scope (S : Entity_Id);
13639 -- Install all enclosing scopes of S along with S itself
13641 procedure Unset_Scope (S : Entity_Id);
13642 -- Uninstall all enclosing scopes of S along with S itself
13648 procedure Set_Scope (S : Entity_Id) is
13650 if S /= Standard_Standard then
13651 Set_Scope (Scope (S));
13661 procedure Unset_Scope (S : Entity_Id) is
13663 if S /= Standard_Standard then
13664 Unset_Scope (Scope (S));
13670 -- Start of processing for Validate_Compile_Time_Warning_Errors
13673 Expander_Mode_Save_And_Set (False);
13674 In_Compile_Time_Warning_Or_Error := True;
13676 for N in Compile_Time_Warnings_Errors.First ..
13677 Compile_Time_Warnings_Errors.Last
13680 T : CTWE_Entry renames Compile_Time_Warnings_Errors.Table (N);
13683 Set_Scope (T.Scope);
13684 Reset_Analyzed_Flags (T.Prag);
13685 Process_Compile_Time_Warning_Or_Error (T.Prag, T.Eloc);
13686 Unset_Scope (T.Scope);
13690 In_Compile_Time_Warning_Or_Error := False;
13691 Expander_Mode_Restore;
13692 end Validate_Compile_Time_Warning_Errors;
13694 ---------------------------
13695 -- Validate_Independence --
13696 ---------------------------
13698 procedure Validate_Independence is
13699 SU : constant Uint := UI_From_Int (System_Storage_Unit);
13707 procedure Check_Array_Type (Atyp : Entity_Id);
13708 -- Checks if the array type Atyp has independent components, and
13709 -- if not, outputs an appropriate set of error messages.
13711 procedure No_Independence;
13712 -- Output message that independence cannot be guaranteed
13714 function OK_Component (C : Entity_Id) return Boolean;
13715 -- Checks one component to see if it is independently accessible, and
13716 -- if so yields True, otherwise yields False if independent access
13717 -- cannot be guaranteed. This is a conservative routine, it only
13718 -- returns True if it knows for sure, it returns False if it knows
13719 -- there is a problem, or it cannot be sure there is no problem.
13721 procedure Reason_Bad_Component (C : Entity_Id);
13722 -- Outputs continuation message if a reason can be determined for
13723 -- the component C being bad.
13725 ----------------------
13726 -- Check_Array_Type --
13727 ----------------------
13729 procedure Check_Array_Type (Atyp : Entity_Id) is
13730 Ctyp : constant Entity_Id := Component_Type (Atyp);
13733 -- OK if no alignment clause, no pack, and no component size
13735 if not Has_Component_Size_Clause (Atyp)
13736 and then not Has_Alignment_Clause (Atyp)
13737 and then not Is_Packed (Atyp)
13742 -- Case of component size is greater than or equal to 64 and the
13743 -- alignment of the array is at least as large as the alignment
13744 -- of the component. We are definitely OK in this situation.
13746 if Known_Component_Size (Atyp)
13747 and then Component_Size (Atyp) >= 64
13748 and then Known_Alignment (Atyp)
13749 and then Known_Alignment (Ctyp)
13750 and then Alignment (Atyp) >= Alignment (Ctyp)
13755 -- Check actual component size
13757 if not Known_Component_Size (Atyp)
13758 or else not (Addressable (Component_Size (Atyp))
13759 and then Component_Size (Atyp) < 64)
13760 or else Component_Size (Atyp) mod Esize (Ctyp) /= 0
13764 -- Bad component size, check reason
13766 if Has_Component_Size_Clause (Atyp) then
13767 P := Get_Attribute_Definition_Clause
13768 (Atyp, Attribute_Component_Size);
13770 if Present (P) then
13771 Error_Msg_Sloc := Sloc (P);
13772 Error_Msg_N ("\because of Component_Size clause#", N);
13777 if Is_Packed (Atyp) then
13778 P := Get_Rep_Pragma (Atyp, Name_Pack);
13780 if Present (P) then
13781 Error_Msg_Sloc := Sloc (P);
13782 Error_Msg_N ("\because of pragma Pack#", N);
13787 -- No reason found, just return
13792 -- Array type is OK independence-wise
13795 end Check_Array_Type;
13797 ---------------------
13798 -- No_Independence --
13799 ---------------------
13801 procedure No_Independence is
13803 if Pragma_Name (N) = Name_Independent then
13804 Error_Msg_NE ("independence cannot be guaranteed for&", N, E);
13807 ("independent components cannot be guaranteed for&", N, E);
13809 end No_Independence;
13815 function OK_Component (C : Entity_Id) return Boolean is
13816 Rec : constant Entity_Id := Scope (C);
13817 Ctyp : constant Entity_Id := Etype (C);
13820 -- OK if no component clause, no Pack, and no alignment clause
13822 if No (Component_Clause (C))
13823 and then not Is_Packed (Rec)
13824 and then not Has_Alignment_Clause (Rec)
13829 -- Here we look at the actual component layout. A component is
13830 -- addressable if its size is a multiple of the Esize of the
13831 -- component type, and its starting position in the record has
13832 -- appropriate alignment, and the record itself has appropriate
13833 -- alignment to guarantee the component alignment.
13835 -- Make sure sizes are static, always assume the worst for any
13836 -- cases where we cannot check static values.
13838 if not (Known_Static_Esize (C)
13840 Known_Static_Esize (Ctyp))
13845 -- Size of component must be addressable or greater than 64 bits
13846 -- and a multiple of bytes.
13848 if not Addressable (Esize (C)) and then Esize (C) < Uint_64 then
13852 -- Check size is proper multiple
13854 if Esize (C) mod Esize (Ctyp) /= 0 then
13858 -- Check alignment of component is OK
13860 if not Known_Component_Bit_Offset (C)
13861 or else Component_Bit_Offset (C) < Uint_0
13862 or else Component_Bit_Offset (C) mod Esize (Ctyp) /= 0
13867 -- Check alignment of record type is OK
13869 if not Known_Alignment (Rec)
13870 or else (Alignment (Rec) * SU) mod Esize (Ctyp) /= 0
13875 -- All tests passed, component is addressable
13880 --------------------------
13881 -- Reason_Bad_Component --
13882 --------------------------
13884 procedure Reason_Bad_Component (C : Entity_Id) is
13885 Rec : constant Entity_Id := Scope (C);
13886 Ctyp : constant Entity_Id := Etype (C);
13889 -- If component clause present assume that's the problem
13891 if Present (Component_Clause (C)) then
13892 Error_Msg_Sloc := Sloc (Component_Clause (C));
13893 Error_Msg_N ("\because of Component_Clause#", N);
13897 -- If pragma Pack clause present, assume that's the problem
13899 if Is_Packed (Rec) then
13900 P := Get_Rep_Pragma (Rec, Name_Pack);
13902 if Present (P) then
13903 Error_Msg_Sloc := Sloc (P);
13904 Error_Msg_N ("\because of pragma Pack#", N);
13909 -- See if record has bad alignment clause
13911 if Has_Alignment_Clause (Rec)
13912 and then Known_Alignment (Rec)
13913 and then (Alignment (Rec) * SU) mod Esize (Ctyp) /= 0
13915 P := Get_Attribute_Definition_Clause (Rec, Attribute_Alignment);
13917 if Present (P) then
13918 Error_Msg_Sloc := Sloc (P);
13919 Error_Msg_N ("\because of Alignment clause#", N);
13923 -- Couldn't find a reason, so return without a message
13926 end Reason_Bad_Component;
13928 -- Start of processing for Validate_Independence
13931 for J in Independence_Checks.First .. Independence_Checks.Last loop
13932 N := Independence_Checks.Table (J).N;
13933 E := Independence_Checks.Table (J).E;
13934 IC := Pragma_Name (N) = Name_Independent_Components;
13936 -- Deal with component case
13938 if Ekind (E) = E_Discriminant or else Ekind (E) = E_Component then
13939 if not OK_Component (E) then
13941 Reason_Bad_Component (E);
13946 -- Deal with record with Independent_Components
13948 if IC and then Is_Record_Type (E) then
13949 Comp := First_Component_Or_Discriminant (E);
13950 while Present (Comp) loop
13951 if not OK_Component (Comp) then
13953 Reason_Bad_Component (Comp);
13957 Next_Component_Or_Discriminant (Comp);
13961 -- Deal with address clause case
13963 if Is_Object (E) then
13964 Addr := Address_Clause (E);
13966 if Present (Addr) then
13968 Error_Msg_Sloc := Sloc (Addr);
13969 Error_Msg_N ("\because of Address clause#", N);
13974 -- Deal with independent components for array type
13976 if IC and then Is_Array_Type (E) then
13977 Check_Array_Type (E);
13980 -- Deal with independent components for array object
13982 if IC and then Is_Object (E) and then Is_Array_Type (Etype (E)) then
13983 Check_Array_Type (Etype (E));
13988 end Validate_Independence;
13990 ------------------------------
13991 -- Validate_Iterable_Aspect --
13992 ------------------------------
13994 procedure Validate_Iterable_Aspect (Typ : Entity_Id; ASN : Node_Id) is
13999 Cursor : constant Entity_Id := Get_Cursor_Type (ASN, Typ);
14001 First_Id : Entity_Id;
14002 Next_Id : Entity_Id;
14003 Has_Element_Id : Entity_Id;
14004 Element_Id : Entity_Id;
14007 -- If previous error aspect is unusable
14009 if Cursor = Any_Type then
14015 Has_Element_Id := Empty;
14016 Element_Id := Empty;
14018 -- Each expression must resolve to a function with the proper signature
14020 Assoc := First (Component_Associations (Expression (ASN)));
14021 while Present (Assoc) loop
14022 Expr := Expression (Assoc);
14025 Prim := First (Choices (Assoc));
14027 if Nkind (Prim) /= N_Identifier or else Present (Next (Prim)) then
14028 Error_Msg_N ("illegal name in association", Prim);
14030 elsif Chars (Prim) = Name_First then
14031 Resolve_Iterable_Operation (Expr, Cursor, Typ, Name_First);
14032 First_Id := Entity (Expr);
14034 elsif Chars (Prim) = Name_Next then
14035 Resolve_Iterable_Operation (Expr, Cursor, Typ, Name_Next);
14036 Next_Id := Entity (Expr);
14038 elsif Chars (Prim) = Name_Has_Element then
14039 Resolve_Iterable_Operation (Expr, Cursor, Typ, Name_Has_Element);
14040 Has_Element_Id := Entity (Expr);
14042 elsif Chars (Prim) = Name_Element then
14043 Resolve_Iterable_Operation (Expr, Cursor, Typ, Name_Element);
14044 Element_Id := Entity (Expr);
14047 Error_Msg_N ("invalid name for iterable function", Prim);
14053 if No (First_Id) then
14054 Error_Msg_N ("match for First primitive not found", ASN);
14056 elsif No (Next_Id) then
14057 Error_Msg_N ("match for Next primitive not found", ASN);
14059 elsif No (Has_Element_Id) then
14060 Error_Msg_N ("match for Has_Element primitive not found", ASN);
14062 elsif No (Element_Id) then
14065 end Validate_Iterable_Aspect;
14067 -----------------------------------
14068 -- Validate_Unchecked_Conversion --
14069 -----------------------------------
14071 procedure Validate_Unchecked_Conversion
14073 Act_Unit : Entity_Id)
14075 Source : Entity_Id;
14076 Target : Entity_Id;
14080 -- Obtain source and target types. Note that we call Ancestor_Subtype
14081 -- here because the processing for generic instantiation always makes
14082 -- subtypes, and we want the original frozen actual types.
14084 -- If we are dealing with private types, then do the check on their
14085 -- fully declared counterparts if the full declarations have been
14086 -- encountered (they don't have to be visible, but they must exist).
14088 Source := Ancestor_Subtype (Etype (First_Formal (Act_Unit)));
14090 if Is_Private_Type (Source)
14091 and then Present (Underlying_Type (Source))
14093 Source := Underlying_Type (Source);
14096 Target := Ancestor_Subtype (Etype (Act_Unit));
14098 -- If either type is generic, the instantiation happens within a generic
14099 -- unit, and there is nothing to check. The proper check will happen
14100 -- when the enclosing generic is instantiated.
14102 if Is_Generic_Type (Source) or else Is_Generic_Type (Target) then
14106 if Is_Private_Type (Target)
14107 and then Present (Underlying_Type (Target))
14109 Target := Underlying_Type (Target);
14112 -- Source may be unconstrained array, but not target, except in relaxed
14115 if Is_Array_Type (Target)
14116 and then not Is_Constrained (Target)
14117 and then not Relaxed_RM_Semantics
14120 ("unchecked conversion to unconstrained array not allowed", N);
14124 -- Warn if conversion between two different convention pointers
14126 if Is_Access_Type (Target)
14127 and then Is_Access_Type (Source)
14128 and then Convention (Target) /= Convention (Source)
14129 and then Warn_On_Unchecked_Conversion
14131 -- Give warnings for subprogram pointers only on most targets
14133 if Is_Access_Subprogram_Type (Target)
14134 or else Is_Access_Subprogram_Type (Source)
14137 ("?z?conversion between pointers with different conventions!",
14142 -- Warn if one of the operands is Ada.Calendar.Time. Do not emit a
14143 -- warning when compiling GNAT-related sources.
14145 if Warn_On_Unchecked_Conversion
14146 and then not In_Predefined_Unit (N)
14147 and then RTU_Loaded (Ada_Calendar)
14148 and then (Chars (Source) = Name_Time
14150 Chars (Target) = Name_Time)
14152 -- If Ada.Calendar is loaded and the name of one of the operands is
14153 -- Time, there is a good chance that this is Ada.Calendar.Time.
14156 Calendar_Time : constant Entity_Id := Full_View (RTE (RO_CA_Time));
14158 pragma Assert (Present (Calendar_Time));
14160 if Source = Calendar_Time or else Target = Calendar_Time then
14162 ("?z?representation of 'Time values may change between
"
14163 & "'G'N'A
'T versions
", N);
14168 -- Make entry in unchecked conversion table for later processing by
14169 -- Validate_Unchecked_Conversions, which will check sizes and alignments
14170 -- (using values set by the back end where possible). This is only done
14171 -- if the appropriate warning is active.
14173 if Warn_On_Unchecked_Conversion then
14174 Unchecked_Conversions.Append
14175 (New_Val => UC_Entry'(Eloc => Sloc (N),
14178 Act_Unit => Act_Unit));
14180 -- If both sizes are known statically now, then back-end annotation
14181 -- is not required to do a proper check but if either size is not
14182 -- known statically, then we need the annotation.
14184 if Known_Static_RM_Size (Source)
14186 Known_Static_RM_Size (Target)
14190 Back_Annotate_Rep_Info := True;
14194 -- If unchecked conversion to access type, and access type is declared
14195 -- in the same unit as the unchecked conversion, then set the flag
14196 -- No_Strict_Aliasing (no strict aliasing is implicit here)
14198 if Is_Access_Type (Target) and then
14199 In_Same_Source_Unit (Target, N)
14201 Set_No_Strict_Aliasing (Implementation_Base_Type (Target));
14204 -- Generate N_Validate_Unchecked_Conversion node for back end in case
14205 -- the back end needs to perform special validation checks.
14207 -- Shouldn't this be in Exp_Ch13, since the check only gets done if we
14208 -- have full expansion and the back end is called ???
14211 Make_Validate_Unchecked_Conversion (Sloc (N));
14212 Set_Source_Type (Vnode, Source);
14213 Set_Target_Type (Vnode, Target);
14215 -- If the unchecked conversion node is in a list, just insert before it.
14216 -- If not we have some strange case, not worth bothering about.
14218 if Is_List_Member (N) then
14219 Insert_After (N, Vnode);
14221 end Validate_Unchecked_Conversion;
14223 ------------------------------------
14224 -- Validate_Unchecked_Conversions --
14225 ------------------------------------
14227 procedure Validate_Unchecked_Conversions is
14229 for N in Unchecked_Conversions.First .. Unchecked_Conversions.Last loop
14231 T : UC_Entry renames Unchecked_Conversions.Table (N);
14233 Act_Unit : constant Entity_Id := T.Act_Unit;
14234 Eloc : constant Source_Ptr := T.Eloc;
14235 Source : constant Entity_Id := T.Source;
14236 Target : constant Entity_Id := T.Target;
14242 -- Skip if function marked as warnings off
14244 if Warnings_Off (Act_Unit) then
14248 -- This validation check, which warns if we have unequal sizes for
14249 -- unchecked conversion, and thus potentially implementation
14250 -- dependent semantics, is one of the few occasions on which we
14251 -- use the official RM size instead of Esize. See description in
14252 -- Einfo "Handling
of Type'Size Values
" for details.
14254 if Serious_Errors_Detected = 0
14255 and then Known_Static_RM_Size (Source)
14256 and then Known_Static_RM_Size (Target)
14258 -- Don't do the check if warnings off for either type, note the
14259 -- deliberate use of OR here instead of OR ELSE to get the flag
14260 -- Warnings_Off_Used set for both types if appropriate.
14262 and then not (Has_Warnings_Off (Source)
14264 Has_Warnings_Off (Target))
14266 Source_Siz := RM_Size (Source);
14267 Target_Siz := RM_Size (Target);
14269 if Source_Siz /= Target_Siz then
14271 ("?z?types
for unchecked conversion have different sizes
!",
14274 if All_Errors_Mode then
14275 Error_Msg_Name_1 := Chars (Source);
14276 Error_Msg_Uint_1 := Source_Siz;
14277 Error_Msg_Name_2 := Chars (Target);
14278 Error_Msg_Uint_2 := Target_Siz;
14279 Error_Msg ("\size
of % is ^
, size
of % is ^?z?
", Eloc);
14281 Error_Msg_Uint_1 := UI_Abs (Source_Siz - Target_Siz);
14283 if Is_Discrete_Type (Source)
14285 Is_Discrete_Type (Target)
14287 if Source_Siz > Target_Siz then
14289 ("\?z?^ high order bits
of source will
"
14290 & "be ignored
!", Eloc);
14292 elsif Is_Unsigned_Type (Source) then
14294 ("\?z?source will be extended
with ^ high order
"
14295 & "zero bits
!", Eloc);
14299 ("\?z?source will be extended
with ^ high order
"
14300 & "sign bits
!", Eloc);
14303 elsif Source_Siz < Target_Siz then
14304 if Is_Discrete_Type (Target) then
14305 if Bytes_Big_Endian then
14307 ("\?z?target value will include ^ undefined
"
14308 & "low order bits
!", Eloc);
14311 ("\?z?target value will include ^ undefined
"
14312 & "high order bits
!", Eloc);
14317 ("\?z?^ trailing bits
of target value will be
"
14318 & "undefined
!", Eloc);
14321 else pragma Assert (Source_Siz > Target_Siz);
14322 if Is_Discrete_Type (Source) then
14323 if Bytes_Big_Endian then
14325 ("\?z?^ low order bits
of source will be
"
14326 & "ignored
!", Eloc);
14329 ("\?z?^ high order bits
of source will be
"
14330 & "ignored
!", Eloc);
14335 ("\?z?^ trailing bits
of source will be
"
14336 & "ignored
!", Eloc);
14343 -- If both types are access types, we need to check the alignment.
14344 -- If the alignment of both is specified, we can do it here.
14346 if Serious_Errors_Detected = 0
14347 and then Is_Access_Type (Source)
14348 and then Is_Access_Type (Target)
14349 and then Target_Strict_Alignment
14350 and then Present (Designated_Type (Source))
14351 and then Present (Designated_Type (Target))
14354 D_Source : constant Entity_Id := Designated_Type (Source);
14355 D_Target : constant Entity_Id := Designated_Type (Target);
14358 if Known_Alignment (D_Source)
14360 Known_Alignment (D_Target)
14363 Source_Align : constant Uint := Alignment (D_Source);
14364 Target_Align : constant Uint := Alignment (D_Target);
14367 if Source_Align < Target_Align
14368 and then not Is_Tagged_Type (D_Source)
14370 -- Suppress warning if warnings suppressed on either
14371 -- type or either designated type. Note the use of
14372 -- OR here instead of OR ELSE. That is intentional,
14373 -- we would like to set flag Warnings_Off_Used in
14374 -- all types for which warnings are suppressed.
14376 and then not (Has_Warnings_Off (D_Source)
14378 Has_Warnings_Off (D_Target)
14380 Has_Warnings_Off (Source)
14382 Has_Warnings_Off (Target))
14384 Error_Msg_Uint_1 := Target_Align;
14385 Error_Msg_Uint_2 := Source_Align;
14386 Error_Msg_Node_1 := D_Target;
14387 Error_Msg_Node_2 := D_Source;
14389 ("?z?alignment
of & (^
) is stricter than
"
14390 & "alignment
of & (^
)!", Eloc);
14392 ("\?z?resulting
access value may have invalid
"
14393 & "alignment
!", Eloc);
14404 end Validate_Unchecked_Conversions;