1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2010, 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 Exp_Disp; use Exp_Disp;
34 with Exp_Tss; use Exp_Tss;
35 with Exp_Util; use Exp_Util;
37 with Lib.Xref; use Lib.Xref;
38 with Namet; use Namet;
39 with Nlists; use Nlists;
40 with Nmake; use Nmake;
42 with Restrict; use Restrict;
43 with Rident; use Rident;
44 with Rtsfind; use Rtsfind;
46 with Sem_Aux; use Sem_Aux;
47 with Sem_Ch3; use Sem_Ch3;
48 with Sem_Ch8; use Sem_Ch8;
49 with Sem_Eval; use Sem_Eval;
50 with Sem_Res; use Sem_Res;
51 with Sem_Type; use Sem_Type;
52 with Sem_Util; use Sem_Util;
53 with Sem_Warn; use Sem_Warn;
54 with Snames; use Snames;
55 with Stand; use Stand;
56 with Sinfo; use Sinfo;
57 with Targparm; use Targparm;
58 with Ttypes; use Ttypes;
59 with Tbuild; use Tbuild;
60 with Urealp; use Urealp;
62 with GNAT.Heap_Sort_G;
64 package body Sem_Ch13 is
66 SSU : constant Pos := System_Storage_Unit;
67 -- Convenient short hand for commonly used constant
69 -----------------------
70 -- Local Subprograms --
71 -----------------------
73 procedure Alignment_Check_For_Esize_Change (Typ : Entity_Id);
74 -- This routine is called after setting the Esize of type entity Typ.
75 -- The purpose is to deal with the situation where an alignment has been
76 -- inherited from a derived type that is no longer appropriate for the
77 -- new Esize value. In this case, we reset the Alignment to unknown.
79 function Get_Alignment_Value (Expr : Node_Id) return Uint;
80 -- Given the expression for an alignment value, returns the corresponding
81 -- Uint value. If the value is inappropriate, then error messages are
82 -- posted as required, and a value of No_Uint is returned.
84 function Is_Operational_Item (N : Node_Id) return Boolean;
85 -- A specification for a stream attribute is allowed before the full
86 -- type is declared, as explained in AI-00137 and the corrigendum.
87 -- Attributes that do not specify a representation characteristic are
88 -- operational attributes.
90 procedure New_Stream_Subprogram
95 -- Create a subprogram renaming of a given stream attribute to the
96 -- designated subprogram and then in the tagged case, provide this as a
97 -- primitive operation, or in the non-tagged case make an appropriate TSS
98 -- entry. This is more properly an expansion activity than just semantics,
99 -- but the presence of user-defined stream functions for limited types is a
100 -- legality check, which is why this takes place here rather than in
101 -- exp_ch13, where it was previously. Nam indicates the name of the TSS
102 -- function to be generated.
104 -- To avoid elaboration anomalies with freeze nodes, for untagged types
105 -- we generate both a subprogram declaration and a subprogram renaming
106 -- declaration, so that the attribute specification is handled as a
107 -- renaming_as_body. For tagged types, the specification is one of the
114 Biased : Boolean := True);
115 -- If Biased is True, sets Has_Biased_Representation flag for E, and
116 -- outputs a warning message at node N if Warn_On_Biased_Representation is
117 -- is True. This warning inserts the string Msg to describe the construct
120 ----------------------------------------------
121 -- Table for Validate_Unchecked_Conversions --
122 ----------------------------------------------
124 -- The following table collects unchecked conversions for validation.
125 -- Entries are made by Validate_Unchecked_Conversion and then the
126 -- call to Validate_Unchecked_Conversions does the actual error
127 -- checking and posting of warnings. The reason for this delayed
128 -- processing is to take advantage of back-annotations of size and
129 -- alignment values performed by the back end.
131 -- Note: the reason we store a Source_Ptr value instead of a Node_Id
132 -- is that by the time Validate_Unchecked_Conversions is called, Sprint
133 -- will already have modified all Sloc values if the -gnatD option is set.
135 type UC_Entry is record
136 Eloc : Source_Ptr; -- node used for posting warnings
137 Source : Entity_Id; -- source type for unchecked conversion
138 Target : Entity_Id; -- target type for unchecked conversion
141 package Unchecked_Conversions is new Table.Table (
142 Table_Component_Type => UC_Entry,
143 Table_Index_Type => Int,
144 Table_Low_Bound => 1,
146 Table_Increment => 200,
147 Table_Name => "Unchecked_Conversions");
149 ----------------------------------------
150 -- Table for Validate_Address_Clauses --
151 ----------------------------------------
153 -- If an address clause has the form
155 -- for X'Address use Expr
157 -- where Expr is of the form Y'Address or recursively is a reference
158 -- to a constant of either of these forms, and X and Y are entities of
159 -- objects, then if Y has a smaller alignment than X, that merits a
160 -- warning about possible bad alignment. The following table collects
161 -- address clauses of this kind. We put these in a table so that they
162 -- can be checked after the back end has completed annotation of the
163 -- alignments of objects, since we can catch more cases that way.
165 type Address_Clause_Check_Record is record
167 -- The address clause
170 -- The entity of the object overlaying Y
173 -- The entity of the object being overlaid
176 -- Whether the address is offseted within Y
179 package Address_Clause_Checks is new Table.Table (
180 Table_Component_Type => Address_Clause_Check_Record,
181 Table_Index_Type => Int,
182 Table_Low_Bound => 1,
184 Table_Increment => 200,
185 Table_Name => "Address_Clause_Checks");
187 -----------------------------------------
188 -- Adjust_Record_For_Reverse_Bit_Order --
189 -----------------------------------------
191 procedure Adjust_Record_For_Reverse_Bit_Order (R : Entity_Id) is
196 -- Processing depends on version of Ada
198 -- For Ada 95, we just renumber bits within a storage unit. We do the
199 -- same for Ada 83 mode, since we recognize pragma Bit_Order in Ada 83,
200 -- and are free to add this extension.
202 if Ada_Version < Ada_2005 then
203 Comp := First_Component_Or_Discriminant (R);
204 while Present (Comp) loop
205 CC := Component_Clause (Comp);
207 -- If component clause is present, then deal with the non-default
208 -- bit order case for Ada 95 mode.
210 -- We only do this processing for the base type, and in fact that
211 -- is important, since otherwise if there are record subtypes, we
212 -- could reverse the bits once for each subtype, which is wrong.
215 and then Ekind (R) = E_Record_Type
218 CFB : constant Uint := Component_Bit_Offset (Comp);
219 CSZ : constant Uint := Esize (Comp);
220 CLC : constant Node_Id := Component_Clause (Comp);
221 Pos : constant Node_Id := Position (CLC);
222 FB : constant Node_Id := First_Bit (CLC);
224 Storage_Unit_Offset : constant Uint :=
225 CFB / System_Storage_Unit;
227 Start_Bit : constant Uint :=
228 CFB mod System_Storage_Unit;
231 -- Cases where field goes over storage unit boundary
233 if Start_Bit + CSZ > System_Storage_Unit then
235 -- Allow multi-byte field but generate warning
237 if Start_Bit mod System_Storage_Unit = 0
238 and then CSZ mod System_Storage_Unit = 0
241 ("multi-byte field specified with non-standard"
242 & " Bit_Order?", CLC);
244 if Bytes_Big_Endian then
246 ("bytes are not reversed "
247 & "(component is big-endian)?", CLC);
250 ("bytes are not reversed "
251 & "(component is little-endian)?", CLC);
254 -- Do not allow non-contiguous field
258 ("attempt to specify non-contiguous field "
259 & "not permitted", CLC);
261 ("\caused by non-standard Bit_Order "
264 ("\consider possibility of using "
265 & "Ada 2005 mode here", CLC);
268 -- Case where field fits in one storage unit
271 -- Give warning if suspicious component clause
273 if Intval (FB) >= System_Storage_Unit
274 and then Warn_On_Reverse_Bit_Order
277 ("?Bit_Order clause does not affect " &
278 "byte ordering", Pos);
280 Intval (Pos) + Intval (FB) /
283 ("?position normalized to ^ before bit " &
284 "order interpreted", Pos);
287 -- Here is where we fix up the Component_Bit_Offset value
288 -- to account for the reverse bit order. Some examples of
289 -- what needs to be done are:
291 -- First_Bit .. Last_Bit Component_Bit_Offset
303 -- The rule is that the first bit is is obtained by
304 -- subtracting the old ending bit from storage_unit - 1.
306 Set_Component_Bit_Offset
308 (Storage_Unit_Offset * System_Storage_Unit) +
309 (System_Storage_Unit - 1) -
310 (Start_Bit + CSZ - 1));
312 Set_Normalized_First_Bit
314 Component_Bit_Offset (Comp) mod
315 System_Storage_Unit);
320 Next_Component_Or_Discriminant (Comp);
323 -- For Ada 2005, we do machine scalar processing, as fully described In
324 -- AI-133. This involves gathering all components which start at the
325 -- same byte offset and processing them together. Same approach is still
326 -- valid in later versions including Ada 2012.
330 Max_Machine_Scalar_Size : constant Uint :=
332 (Standard_Long_Long_Integer_Size);
333 -- We use this as the maximum machine scalar size
336 SSU : constant Uint := UI_From_Int (System_Storage_Unit);
339 -- This first loop through components does two things. First it
340 -- deals with the case of components with component clauses whose
341 -- length is greater than the maximum machine scalar size (either
342 -- accepting them or rejecting as needed). Second, it counts the
343 -- number of components with component clauses whose length does
344 -- not exceed this maximum for later processing.
347 Comp := First_Component_Or_Discriminant (R);
348 while Present (Comp) loop
349 CC := Component_Clause (Comp);
353 Fbit : constant Uint :=
354 Static_Integer (First_Bit (CC));
357 -- Case of component with size > max machine scalar
359 if Esize (Comp) > Max_Machine_Scalar_Size then
361 -- Must begin on byte boundary
363 if Fbit mod SSU /= 0 then
365 ("illegal first bit value for "
366 & "reverse bit order",
368 Error_Msg_Uint_1 := SSU;
369 Error_Msg_Uint_2 := Max_Machine_Scalar_Size;
372 ("\must be a multiple of ^ "
373 & "if size greater than ^",
376 -- Must end on byte boundary
378 elsif Esize (Comp) mod SSU /= 0 then
380 ("illegal last bit value for "
381 & "reverse bit order",
383 Error_Msg_Uint_1 := SSU;
384 Error_Msg_Uint_2 := Max_Machine_Scalar_Size;
387 ("\must be a multiple of ^ if size "
391 -- OK, give warning if enabled
393 elsif Warn_On_Reverse_Bit_Order then
395 ("multi-byte field specified with "
396 & " non-standard Bit_Order?", CC);
398 if Bytes_Big_Endian then
400 ("\bytes are not reversed "
401 & "(component is big-endian)?", CC);
404 ("\bytes are not reversed "
405 & "(component is little-endian)?", CC);
409 -- Case where size is not greater than max machine
410 -- scalar. For now, we just count these.
413 Num_CC := Num_CC + 1;
418 Next_Component_Or_Discriminant (Comp);
421 -- We need to sort the component clauses on the basis of the
422 -- Position values in the clause, so we can group clauses with
423 -- the same Position. together to determine the relevant machine
427 Comps : array (0 .. Num_CC) of Entity_Id;
428 -- Array to collect component and discriminant entities. The
429 -- data starts at index 1, the 0'th entry is for the sort
432 function CP_Lt (Op1, Op2 : Natural) return Boolean;
433 -- Compare routine for Sort
435 procedure CP_Move (From : Natural; To : Natural);
436 -- Move routine for Sort
438 package Sorting is new GNAT.Heap_Sort_G (CP_Move, CP_Lt);
442 -- Start and stop positions in the component list of the set of
443 -- components with the same starting position (that constitute
444 -- components in a single machine scalar).
447 -- Maximum last bit value of any component in this set
450 -- Corresponding machine scalar size
456 function CP_Lt (Op1, Op2 : Natural) return Boolean is
458 return Position (Component_Clause (Comps (Op1))) <
459 Position (Component_Clause (Comps (Op2)));
466 procedure CP_Move (From : Natural; To : Natural) is
468 Comps (To) := Comps (From);
471 -- Start of processing for Sort_CC
474 -- Collect the component clauses
477 Comp := First_Component_Or_Discriminant (R);
478 while Present (Comp) loop
479 if Present (Component_Clause (Comp))
480 and then Esize (Comp) <= Max_Machine_Scalar_Size
482 Num_CC := Num_CC + 1;
483 Comps (Num_CC) := Comp;
486 Next_Component_Or_Discriminant (Comp);
489 -- Sort by ascending position number
491 Sorting.Sort (Num_CC);
493 -- We now have all the components whose size does not exceed
494 -- the max machine scalar value, sorted by starting position.
495 -- In this loop we gather groups of clauses starting at the
496 -- same position, to process them in accordance with AI-133.
499 while Stop < Num_CC loop
504 (Last_Bit (Component_Clause (Comps (Start))));
505 while Stop < Num_CC loop
507 (Position (Component_Clause (Comps (Stop + 1)))) =
509 (Position (Component_Clause (Comps (Stop))))
517 (Component_Clause (Comps (Stop)))));
523 -- Now we have a group of component clauses from Start to
524 -- Stop whose positions are identical, and MaxL is the
525 -- maximum last bit value of any of these components.
527 -- We need to determine the corresponding machine scalar
528 -- size. This loop assumes that machine scalar sizes are
529 -- even, and that each possible machine scalar has twice
530 -- as many bits as the next smaller one.
532 MSS := Max_Machine_Scalar_Size;
534 and then (MSS / 2) >= SSU
535 and then (MSS / 2) > MaxL
540 -- Here is where we fix up the Component_Bit_Offset value
541 -- to account for the reverse bit order. Some examples of
542 -- what needs to be done for the case of a machine scalar
545 -- First_Bit .. Last_Bit Component_Bit_Offset
557 -- The rule is that the first bit is obtained by subtracting
558 -- the old ending bit from machine scalar size - 1.
560 for C in Start .. Stop loop
562 Comp : constant Entity_Id := Comps (C);
563 CC : constant Node_Id :=
564 Component_Clause (Comp);
565 LB : constant Uint :=
566 Static_Integer (Last_Bit (CC));
567 NFB : constant Uint := MSS - Uint_1 - LB;
568 NLB : constant Uint := NFB + Esize (Comp) - 1;
569 Pos : constant Uint :=
570 Static_Integer (Position (CC));
573 if Warn_On_Reverse_Bit_Order then
574 Error_Msg_Uint_1 := MSS;
576 ("info: reverse bit order in machine " &
577 "scalar of length^?", First_Bit (CC));
578 Error_Msg_Uint_1 := NFB;
579 Error_Msg_Uint_2 := NLB;
581 if Bytes_Big_Endian then
583 ("?\info: big-endian range for "
584 & "component & is ^ .. ^",
585 First_Bit (CC), Comp);
588 ("?\info: little-endian range "
589 & "for component & is ^ .. ^",
590 First_Bit (CC), Comp);
594 Set_Component_Bit_Offset (Comp, Pos * SSU + NFB);
595 Set_Normalized_First_Bit (Comp, NFB mod SSU);
602 end Adjust_Record_For_Reverse_Bit_Order;
604 --------------------------------------
605 -- Alignment_Check_For_Esize_Change --
606 --------------------------------------
608 procedure Alignment_Check_For_Esize_Change (Typ : Entity_Id) is
610 -- If the alignment is known, and not set by a rep clause, and is
611 -- inconsistent with the size being set, then reset it to unknown,
612 -- we assume in this case that the size overrides the inherited
613 -- alignment, and that the alignment must be recomputed.
615 if Known_Alignment (Typ)
616 and then not Has_Alignment_Clause (Typ)
617 and then Esize (Typ) mod (Alignment (Typ) * SSU) /= 0
619 Init_Alignment (Typ);
621 end Alignment_Check_For_Esize_Change;
623 -----------------------------------
624 -- Analyze_Aspect_Specifications --
625 -----------------------------------
627 procedure Analyze_Aspect_Specifications
636 Ins_Node : Node_Id := N;
637 -- Insert pragmas (other than Pre/Post) after this node
639 -- The general processing involves building an attribute definition
640 -- clause or a pragma node that corresponds to the access type. Then
641 -- one of two things happens:
643 -- If we are required to delay the evaluation of this aspect to the
644 -- freeze point, we preanalyze the relevant argument, and then attach
645 -- the corresponding pragma/attribute definition clause to the aspect
646 -- specification node, which is then placed in the Rep Item chain.
647 -- In this case we mark the entity with the Has_Delayed_Aspects flag,
648 -- and we evaluate the rep item at the freeze point.
650 -- If no delay is required, we just insert the pragma or attribute
651 -- after the declaration, and it will get processed by the normal
652 -- circuit. The From_Aspect_Specification flag is set on the pragma
653 -- or attribute definition node in either case to activate special
654 -- processing (e.g. not traversing the list of homonyms for inline).
656 Delay_Required : Boolean;
657 -- Set True if delay is required
665 while Present (Aspect) loop
667 Id : constant Node_Id := Identifier (Aspect);
668 Expr : constant Node_Id := Expression (Aspect);
669 Nam : constant Name_Id := Chars (Id);
670 A_Id : constant Aspect_Id := Get_Aspect_Id (Nam);
675 Set_Entity (Aspect, E);
676 Ent := New_Occurrence_Of (E, Sloc (Id));
678 -- Check for duplicate aspect
681 while Anod /= Aspect loop
682 if Nam = Chars (Identifier (Anod)) then
683 Error_Msg_Name_1 := Nam;
684 Error_Msg_Sloc := Sloc (Anod);
686 ("aspect% for & ignored, already given at#", Id, E);
693 -- Processing based on specific aspect
697 -- No_Aspect should be impossible
702 -- Aspects taking an optional boolean argument. For all of
703 -- these we just create a matching pragma and insert it,
704 -- setting flag Cancel_Aspect if the expression is False.
706 when Aspect_Ada_2005 |
709 Aspect_Atomic_Components |
710 Aspect_Discard_Names |
711 Aspect_Favor_Top_Level |
713 Aspect_Inline_Always |
716 Aspect_Persistent_BSS |
717 Aspect_Preelaborable_Initialization |
718 Aspect_Pure_Function |
720 Aspect_Suppress_Debug_Info |
721 Aspect_Unchecked_Union |
722 Aspect_Universal_Aliasing |
724 Aspect_Unreferenced |
725 Aspect_Unreferenced_Objects |
727 Aspect_Volatile_Components =>
729 -- Build corresponding pragma node
732 Make_Pragma (Sloc (Aspect),
733 Pragma_Argument_Associations => New_List (Ent),
735 Make_Identifier (Sloc (Id), Chars (Id)));
737 -- Deal with missing expression case, delay never needed
740 Delay_Required := False;
742 -- Expression is present
745 Preanalyze_Spec_Expression (Expr, Standard_Boolean);
747 -- If preanalysis gives a static expression, we don't
748 -- need to delay (this will happen often in practice).
750 if Is_OK_Static_Expression (Expr) then
751 Delay_Required := False;
753 if Is_False (Expr_Value (Expr)) then
754 Set_Aspect_Cancel (Aitem);
757 -- If we don't get a static expression, then delay, the
758 -- expression may turn out static by freeze time.
761 Delay_Required := True;
765 -- Aspects corresponding to attribute definition clauses with
766 -- the exception of Address which is treated specially.
768 when Aspect_Alignment |
770 Aspect_Component_Size |
771 Aspect_External_Tag |
772 Aspect_Machine_Radix |
775 Aspect_Storage_Pool |
776 Aspect_Storage_Size |
780 -- Preanalyze the expression with the appropriate type
783 when Aspect_Bit_Order =>
784 T := RTE (RE_Bit_Order);
785 when Aspect_External_Tag =>
786 T := Standard_String;
787 when Aspect_Storage_Pool =>
788 T := Class_Wide_Type (RTE (RE_Root_Storage_Pool));
793 Preanalyze_Spec_Expression (Expr, T);
795 -- Construct the attribute definition clause
798 Make_Attribute_Definition_Clause (Sloc (Aspect),
801 Expression => Relocate_Node (Expr));
803 -- We do not need a delay if we have a static expression
805 if Is_OK_Static_Expression (Expression (Aitem)) then
806 Delay_Required := False;
808 -- Here a delay is required
811 Delay_Required := True;
814 -- Address aspect, treated specially because we have some
815 -- strange problem in the back end if we try to delay ???
817 when Aspect_Address =>
819 -- Construct the attribute definition clause
822 Make_Attribute_Definition_Clause (Sloc (Aspect),
825 Expression => Relocate_Node (Expr));
827 -- If -gnatd.A is set, do the delay if needed (this is
828 -- so we can debug the relevant problem).
830 if Debug_Flag_Dot_AA then
831 Preanalyze_Spec_Expression
832 (Expression (Aitem), RTE (RE_Address));
834 if Is_OK_Static_Expression (Expression (Aitem)) then
835 Delay_Required := False;
837 Delay_Required := True;
840 -- Here if -gnatd.A not set, never do the delay
843 Delay_Required := False;
846 -- Aspects corresponding to pragmas with two arguments, where
847 -- the first argument is a local name referring to the entity,
848 -- and the second argument is the aspect definition expression.
850 when Aspect_Suppress |
853 -- Construct the pragma
856 Make_Pragma (Sloc (Aspect),
857 Pragma_Argument_Associations => New_List (
858 New_Occurrence_Of (E, Sloc (Expr)),
859 Relocate_Node (Expr)),
861 Make_Identifier (Sloc (Id), Chars (Id)));
863 -- We don't have to play the delay game here, since the only
864 -- values are check names which don't get analyzed anyway.
866 Delay_Required := False;
868 -- Aspects corresponding to pragmas with two arguments, where
869 -- the second argument is a local name referring to the entity,
870 -- and the first argument is the aspect definition expression.
872 when Aspect_Warnings =>
874 -- Construct the pragma
877 Make_Pragma (Sloc (Aspect),
878 Pragma_Argument_Associations => New_List (
879 Relocate_Node (Expr),
880 New_Occurrence_Of (E, Sloc (Expr))),
882 Make_Identifier (Sloc (Id), Chars (Id)));
884 -- We don't have to play the delay game here, since the only
885 -- values are check names which don't get analyzed anyway.
887 Delay_Required := False;
889 -- Aspect Post corresponds to pragma Postcondition with single
890 -- argument that is the expression (we never give a message
891 -- argument. This is inserted right after the declaration,
892 -- to get the required pragma placement.
896 -- Construct the pragma
899 Make_Pragma (Sloc (Expr),
900 Pragma_Argument_Associations => New_List (
901 Relocate_Node (Expr)),
903 Make_Identifier (Sloc (Id), Name_Postcondition));
905 -- We don't have to play the delay game here. The required
906 -- delay in this case is already implemented by the pragma.
908 Delay_Required := False;
910 -- Aspect Pre corresponds to pragma Precondition with single
911 -- argument that is the expression (we never give a message
912 -- argument). This is inserted right after the declaration,
913 -- to get the required pragma placement.
917 -- Construct the pragma
920 Make_Pragma (Sloc (Expr),
921 Pragma_Argument_Associations => New_List (
922 Relocate_Node (Expr)),
924 Make_Identifier (Sloc (Id), Name_Precondition));
926 -- We don't have to play the delay game here. The required
927 -- delay in this case is already implemented by the pragma.
929 Delay_Required := False;
931 -- Aspects currently unimplemented
933 when Aspect_Invariant |
936 Error_Msg_N ("aspect& not implemented", Identifier (Aspect));
940 Set_From_Aspect_Specification (Aitem, True);
942 -- If a delay is required, we delay the freeze (not much point in
943 -- delaying the aspect if we don't delay the freeze!). The pragma
944 -- or clause is then attached to the aspect specification which
945 -- is placed in the rep item list.
947 if Delay_Required then
948 Ensure_Freeze_Node (E);
949 Set_Is_Delayed_Aspect (Aitem);
950 Set_Has_Delayed_Aspects (E);
951 Set_Aspect_Rep_Item (Aspect, Aitem);
952 Record_Rep_Item (E, Aspect);
954 -- If no delay required, insert the pragma/clause in the tree
957 -- For Pre/Post cases, insert immediately after the entity
958 -- declaration, since that is the required pragma placement.
960 if A_Id = Aspect_Pre or else A_Id = Aspect_Post then
961 Insert_After (N, Aitem);
963 -- For all other cases, insert in sequence
966 Insert_After (Ins_Node, Aitem);
975 end Analyze_Aspect_Specifications;
977 -----------------------
978 -- Analyze_At_Clause --
979 -----------------------
981 -- An at clause is replaced by the corresponding Address attribute
982 -- definition clause that is the preferred approach in Ada 95.
984 procedure Analyze_At_Clause (N : Node_Id) is
985 CS : constant Boolean := Comes_From_Source (N);
988 -- This is an obsolescent feature
990 Check_Restriction (No_Obsolescent_Features, N);
992 if Warn_On_Obsolescent_Feature then
994 ("at clause is an obsolescent feature (RM J.7(2))?", N);
996 ("\use address attribute definition clause instead?", N);
999 -- Rewrite as address clause
1002 Make_Attribute_Definition_Clause (Sloc (N),
1003 Name => Identifier (N),
1004 Chars => Name_Address,
1005 Expression => Expression (N)));
1007 -- We preserve Comes_From_Source, since logically the clause still
1008 -- comes from the source program even though it is changed in form.
1010 Set_Comes_From_Source (N, CS);
1012 -- Analyze rewritten clause
1014 Analyze_Attribute_Definition_Clause (N);
1015 end Analyze_At_Clause;
1017 -----------------------------------------
1018 -- Analyze_Attribute_Definition_Clause --
1019 -----------------------------------------
1021 procedure Analyze_Attribute_Definition_Clause (N : Node_Id) is
1022 Loc : constant Source_Ptr := Sloc (N);
1023 Nam : constant Node_Id := Name (N);
1024 Attr : constant Name_Id := Chars (N);
1025 Expr : constant Node_Id := Expression (N);
1026 Id : constant Attribute_Id := Get_Attribute_Id (Attr);
1030 FOnly : Boolean := False;
1031 -- Reset to True for subtype specific attribute (Alignment, Size)
1032 -- and for stream attributes, i.e. those cases where in the call
1033 -- to Rep_Item_Too_Late, FOnly is set True so that only the freezing
1034 -- rules are checked. Note that the case of stream attributes is not
1035 -- clear from the RM, but see AI95-00137. Also, the RM seems to
1036 -- disallow Storage_Size for derived task types, but that is also
1037 -- clearly unintentional.
1039 procedure Analyze_Stream_TSS_Definition (TSS_Nam : TSS_Name_Type);
1040 -- Common processing for 'Read, 'Write, 'Input and 'Output attribute
1041 -- definition clauses.
1043 function Duplicate_Clause return Boolean;
1044 -- This routine checks if the aspect for U_Ent being given by attribute
1045 -- definition clause N is for an aspect that has already been specified,
1046 -- and if so gives an error message. If there is a duplicate, True is
1047 -- returned, otherwise if there is no error, False is returned.
1049 -----------------------------------
1050 -- Analyze_Stream_TSS_Definition --
1051 -----------------------------------
1053 procedure Analyze_Stream_TSS_Definition (TSS_Nam : TSS_Name_Type) is
1054 Subp : Entity_Id := Empty;
1059 Is_Read : constant Boolean := (TSS_Nam = TSS_Stream_Read);
1061 function Has_Good_Profile (Subp : Entity_Id) return Boolean;
1062 -- Return true if the entity is a subprogram with an appropriate
1063 -- profile for the attribute being defined.
1065 ----------------------
1066 -- Has_Good_Profile --
1067 ----------------------
1069 function Has_Good_Profile (Subp : Entity_Id) return Boolean is
1071 Is_Function : constant Boolean := (TSS_Nam = TSS_Stream_Input);
1072 Expected_Ekind : constant array (Boolean) of Entity_Kind :=
1073 (False => E_Procedure, True => E_Function);
1077 if Ekind (Subp) /= Expected_Ekind (Is_Function) then
1081 F := First_Formal (Subp);
1084 or else Ekind (Etype (F)) /= E_Anonymous_Access_Type
1085 or else Designated_Type (Etype (F)) /=
1086 Class_Wide_Type (RTE (RE_Root_Stream_Type))
1091 if not Is_Function then
1095 Expected_Mode : constant array (Boolean) of Entity_Kind :=
1096 (False => E_In_Parameter,
1097 True => E_Out_Parameter);
1099 if Parameter_Mode (F) /= Expected_Mode (Is_Read) then
1107 Typ := Etype (Subp);
1110 return Base_Type (Typ) = Base_Type (Ent)
1111 and then No (Next_Formal (F));
1112 end Has_Good_Profile;
1114 -- Start of processing for Analyze_Stream_TSS_Definition
1119 if not Is_Type (U_Ent) then
1120 Error_Msg_N ("local name must be a subtype", Nam);
1124 Pnam := TSS (Base_Type (U_Ent), TSS_Nam);
1126 -- If Pnam is present, it can be either inherited from an ancestor
1127 -- type (in which case it is legal to redefine it for this type), or
1128 -- be a previous definition of the attribute for the same type (in
1129 -- which case it is illegal).
1131 -- In the first case, it will have been analyzed already, and we
1132 -- can check that its profile does not match the expected profile
1133 -- for a stream attribute of U_Ent. In the second case, either Pnam
1134 -- has been analyzed (and has the expected profile), or it has not
1135 -- been analyzed yet (case of a type that has not been frozen yet
1136 -- and for which the stream attribute has been set using Set_TSS).
1139 and then (No (First_Entity (Pnam)) or else Has_Good_Profile (Pnam))
1141 Error_Msg_Sloc := Sloc (Pnam);
1142 Error_Msg_Name_1 := Attr;
1143 Error_Msg_N ("% attribute already defined #", Nam);
1149 if Is_Entity_Name (Expr) then
1150 if not Is_Overloaded (Expr) then
1151 if Has_Good_Profile (Entity (Expr)) then
1152 Subp := Entity (Expr);
1156 Get_First_Interp (Expr, I, It);
1157 while Present (It.Nam) loop
1158 if Has_Good_Profile (It.Nam) then
1163 Get_Next_Interp (I, It);
1168 if Present (Subp) then
1169 if Is_Abstract_Subprogram (Subp) then
1170 Error_Msg_N ("stream subprogram must not be abstract", Expr);
1174 Set_Entity (Expr, Subp);
1175 Set_Etype (Expr, Etype (Subp));
1177 New_Stream_Subprogram (N, U_Ent, Subp, TSS_Nam);
1180 Error_Msg_Name_1 := Attr;
1181 Error_Msg_N ("incorrect expression for% attribute", Expr);
1183 end Analyze_Stream_TSS_Definition;
1185 ----------------------
1186 -- Duplicate_Clause --
1187 ----------------------
1189 function Duplicate_Clause return Boolean is
1193 -- Nothing to do if this attribute definition clause comes from an
1194 -- aspect specification, since we could not be duplicating an
1195 -- explicit clause, and we dealt with the case of duplicated aspects
1196 -- in Analyze_Aspect_Specifications.
1198 if From_Aspect_Specification (N) then
1202 -- Otherwise current clause may duplicate previous clause or a
1203 -- previously given aspect specification for the same aspect.
1205 A := Get_Rep_Item_For_Entity (U_Ent, Chars (N));
1208 if Entity (A) = U_Ent then
1209 Error_Msg_Name_1 := Chars (N);
1210 Error_Msg_Sloc := Sloc (A);
1211 Error_Msg_NE ("aspect% for & previously specified#", N, U_Ent);
1217 end Duplicate_Clause;
1219 -- Start of processing for Analyze_Attribute_Definition_Clause
1222 -- Process Ignore_Rep_Clauses option
1224 if Ignore_Rep_Clauses then
1227 -- The following should be ignored. They do not affect legality
1228 -- and may be target dependent. The basic idea of -gnatI is to
1229 -- ignore any rep clauses that may be target dependent but do not
1230 -- affect legality (except possibly to be rejected because they
1231 -- are incompatible with the compilation target).
1233 when Attribute_Alignment |
1234 Attribute_Bit_Order |
1235 Attribute_Component_Size |
1236 Attribute_Machine_Radix |
1237 Attribute_Object_Size |
1240 Attribute_Stream_Size |
1241 Attribute_Value_Size =>
1243 Rewrite (N, Make_Null_Statement (Sloc (N)));
1246 -- The following should not be ignored, because in the first place
1247 -- they are reasonably portable, and should not cause problems in
1248 -- compiling code from another target, and also they do affect
1249 -- legality, e.g. failing to provide a stream attribute for a
1250 -- type may make a program illegal.
1252 when Attribute_External_Tag |
1256 Attribute_Storage_Pool |
1257 Attribute_Storage_Size |
1261 -- Other cases are errors ("attribute& cannot be set with
1262 -- definition clause"), which will be caught below.
1270 Ent := Entity (Nam);
1272 if Rep_Item_Too_Early (Ent, N) then
1276 -- Rep clause applies to full view of incomplete type or private type if
1277 -- we have one (if not, this is a premature use of the type). However,
1278 -- certain semantic checks need to be done on the specified entity (i.e.
1279 -- the private view), so we save it in Ent.
1281 if Is_Private_Type (Ent)
1282 and then Is_Derived_Type (Ent)
1283 and then not Is_Tagged_Type (Ent)
1284 and then No (Full_View (Ent))
1286 -- If this is a private type whose completion is a derivation from
1287 -- another private type, there is no full view, and the attribute
1288 -- belongs to the type itself, not its underlying parent.
1292 elsif Ekind (Ent) = E_Incomplete_Type then
1294 -- The attribute applies to the full view, set the entity of the
1295 -- attribute definition accordingly.
1297 Ent := Underlying_Type (Ent);
1299 Set_Entity (Nam, Ent);
1302 U_Ent := Underlying_Type (Ent);
1305 -- Complete other routine error checks
1307 if Etype (Nam) = Any_Type then
1310 elsif Scope (Ent) /= Current_Scope then
1311 Error_Msg_N ("entity must be declared in this scope", Nam);
1314 elsif No (U_Ent) then
1317 elsif Is_Type (U_Ent)
1318 and then not Is_First_Subtype (U_Ent)
1319 and then Id /= Attribute_Object_Size
1320 and then Id /= Attribute_Value_Size
1321 and then not From_At_Mod (N)
1323 Error_Msg_N ("cannot specify attribute for subtype", Nam);
1327 Set_Entity (N, U_Ent);
1329 -- Switch on particular attribute
1337 -- Address attribute definition clause
1339 when Attribute_Address => Address : begin
1341 -- A little error check, catch for X'Address use X'Address;
1343 if Nkind (Nam) = N_Identifier
1344 and then Nkind (Expr) = N_Attribute_Reference
1345 and then Attribute_Name (Expr) = Name_Address
1346 and then Nkind (Prefix (Expr)) = N_Identifier
1347 and then Chars (Nam) = Chars (Prefix (Expr))
1350 ("address for & is self-referencing", Prefix (Expr), Ent);
1354 -- Not that special case, carry on with analysis of expression
1356 Analyze_And_Resolve (Expr, RTE (RE_Address));
1358 -- Even when ignoring rep clauses we need to indicate that the
1359 -- entity has an address clause and thus it is legal to declare
1362 if Ignore_Rep_Clauses then
1363 if Ekind_In (U_Ent, E_Variable, E_Constant) then
1364 Record_Rep_Item (U_Ent, N);
1370 if Duplicate_Clause then
1373 -- Case of address clause for subprogram
1375 elsif Is_Subprogram (U_Ent) then
1376 if Has_Homonym (U_Ent) then
1378 ("address clause cannot be given " &
1379 "for overloaded subprogram",
1384 -- For subprograms, all address clauses are permitted, and we
1385 -- mark the subprogram as having a deferred freeze so that Gigi
1386 -- will not elaborate it too soon.
1388 -- Above needs more comments, what is too soon about???
1390 Set_Has_Delayed_Freeze (U_Ent);
1392 -- Case of address clause for entry
1394 elsif Ekind (U_Ent) = E_Entry then
1395 if Nkind (Parent (N)) = N_Task_Body then
1397 ("entry address must be specified in task spec", Nam);
1401 -- For entries, we require a constant address
1403 Check_Constant_Address_Clause (Expr, U_Ent);
1405 -- Special checks for task types
1407 if Is_Task_Type (Scope (U_Ent))
1408 and then Comes_From_Source (Scope (U_Ent))
1411 ("?entry address declared for entry in task type", N);
1413 ("\?only one task can be declared of this type", N);
1416 -- Entry address clauses are obsolescent
1418 Check_Restriction (No_Obsolescent_Features, N);
1420 if Warn_On_Obsolescent_Feature then
1422 ("attaching interrupt to task entry is an " &
1423 "obsolescent feature (RM J.7.1)?", N);
1425 ("\use interrupt procedure instead?", N);
1428 -- Case of an address clause for a controlled object which we
1429 -- consider to be erroneous.
1431 elsif Is_Controlled (Etype (U_Ent))
1432 or else Has_Controlled_Component (Etype (U_Ent))
1435 ("?controlled object& must not be overlaid", Nam, U_Ent);
1437 ("\?Program_Error will be raised at run time", Nam);
1438 Insert_Action (Declaration_Node (U_Ent),
1439 Make_Raise_Program_Error (Loc,
1440 Reason => PE_Overlaid_Controlled_Object));
1443 -- Case of address clause for a (non-controlled) object
1446 Ekind (U_Ent) = E_Variable
1448 Ekind (U_Ent) = E_Constant
1451 Expr : constant Node_Id := Expression (N);
1456 -- Exported variables cannot have an address clause, because
1457 -- this cancels the effect of the pragma Export.
1459 if Is_Exported (U_Ent) then
1461 ("cannot export object with address clause", Nam);
1465 Find_Overlaid_Entity (N, O_Ent, Off);
1467 -- Overlaying controlled objects is erroneous
1470 and then (Has_Controlled_Component (Etype (O_Ent))
1471 or else Is_Controlled (Etype (O_Ent)))
1474 ("?cannot overlay with controlled object", Expr);
1476 ("\?Program_Error will be raised at run time", Expr);
1477 Insert_Action (Declaration_Node (U_Ent),
1478 Make_Raise_Program_Error (Loc,
1479 Reason => PE_Overlaid_Controlled_Object));
1482 elsif Present (O_Ent)
1483 and then Ekind (U_Ent) = E_Constant
1484 and then not Is_Constant_Object (O_Ent)
1486 Error_Msg_N ("constant overlays a variable?", Expr);
1488 elsif Present (Renamed_Object (U_Ent)) then
1490 ("address clause not allowed"
1491 & " for a renaming declaration (RM 13.1(6))", Nam);
1494 -- Imported variables can have an address clause, but then
1495 -- the import is pretty meaningless except to suppress
1496 -- initializations, so we do not need such variables to
1497 -- be statically allocated (and in fact it causes trouble
1498 -- if the address clause is a local value).
1500 elsif Is_Imported (U_Ent) then
1501 Set_Is_Statically_Allocated (U_Ent, False);
1504 -- We mark a possible modification of a variable with an
1505 -- address clause, since it is likely aliasing is occurring.
1507 Note_Possible_Modification (Nam, Sure => False);
1509 -- Here we are checking for explicit overlap of one variable
1510 -- by another, and if we find this then mark the overlapped
1511 -- variable as also being volatile to prevent unwanted
1512 -- optimizations. This is a significant pessimization so
1513 -- avoid it when there is an offset, i.e. when the object
1514 -- is composite; they cannot be optimized easily anyway.
1517 and then Is_Object (O_Ent)
1520 Set_Treat_As_Volatile (O_Ent);
1523 -- Legality checks on the address clause for initialized
1524 -- objects is deferred until the freeze point, because
1525 -- a subsequent pragma might indicate that the object is
1526 -- imported and thus not initialized.
1528 Set_Has_Delayed_Freeze (U_Ent);
1530 -- If an initialization call has been generated for this
1531 -- object, it needs to be deferred to after the freeze node
1532 -- we have just now added, otherwise GIGI will see a
1533 -- reference to the variable (as actual to the IP call)
1534 -- before its definition.
1537 Init_Call : constant Node_Id := Find_Init_Call (U_Ent, N);
1539 if Present (Init_Call) then
1541 Append_Freeze_Action (U_Ent, Init_Call);
1545 if Is_Exported (U_Ent) then
1547 ("& cannot be exported if an address clause is given",
1550 ("\define and export a variable " &
1551 "that holds its address instead",
1555 -- Entity has delayed freeze, so we will generate an
1556 -- alignment check at the freeze point unless suppressed.
1558 if not Range_Checks_Suppressed (U_Ent)
1559 and then not Alignment_Checks_Suppressed (U_Ent)
1561 Set_Check_Address_Alignment (N);
1564 -- Kill the size check code, since we are not allocating
1565 -- the variable, it is somewhere else.
1567 Kill_Size_Check_Code (U_Ent);
1569 -- If the address clause is of the form:
1571 -- for Y'Address use X'Address
1575 -- Const : constant Address := X'Address;
1577 -- for Y'Address use Const;
1579 -- then we make an entry in the table for checking the size
1580 -- and alignment of the overlaying variable. We defer this
1581 -- check till after code generation to take full advantage
1582 -- of the annotation done by the back end. This entry is
1583 -- only made if the address clause comes from source.
1584 -- If the entity has a generic type, the check will be
1585 -- performed in the instance if the actual type justifies
1586 -- it, and we do not insert the clause in the table to
1587 -- prevent spurious warnings.
1589 if Address_Clause_Overlay_Warnings
1590 and then Comes_From_Source (N)
1591 and then Present (O_Ent)
1592 and then Is_Object (O_Ent)
1594 if not Is_Generic_Type (Etype (U_Ent)) then
1595 Address_Clause_Checks.Append ((N, U_Ent, O_Ent, Off));
1598 -- If variable overlays a constant view, and we are
1599 -- warning on overlays, then mark the variable as
1600 -- overlaying a constant (we will give warnings later
1601 -- if this variable is assigned).
1603 if Is_Constant_Object (O_Ent)
1604 and then Ekind (U_Ent) = E_Variable
1606 Set_Overlays_Constant (U_Ent);
1611 -- Not a valid entity for an address clause
1614 Error_Msg_N ("address cannot be given for &", Nam);
1622 -- Alignment attribute definition clause
1624 when Attribute_Alignment => Alignment : declare
1625 Align : constant Uint := Get_Alignment_Value (Expr);
1630 if not Is_Type (U_Ent)
1631 and then Ekind (U_Ent) /= E_Variable
1632 and then Ekind (U_Ent) /= E_Constant
1634 Error_Msg_N ("alignment cannot be given for &", Nam);
1636 elsif Duplicate_Clause then
1639 elsif Align /= No_Uint then
1640 Set_Has_Alignment_Clause (U_Ent);
1641 Set_Alignment (U_Ent, Align);
1643 -- For an array type, U_Ent is the first subtype. In that case,
1644 -- also set the alignment of the anonymous base type so that
1645 -- other subtypes (such as the itypes for aggregates of the
1646 -- type) also receive the expected alignment.
1648 if Is_Array_Type (U_Ent) then
1649 Set_Alignment (Base_Type (U_Ent), Align);
1658 -- Bit_Order attribute definition clause
1660 when Attribute_Bit_Order => Bit_Order : declare
1662 if not Is_Record_Type (U_Ent) then
1664 ("Bit_Order can only be defined for record type", Nam);
1666 elsif Duplicate_Clause then
1670 Analyze_And_Resolve (Expr, RTE (RE_Bit_Order));
1672 if Etype (Expr) = Any_Type then
1675 elsif not Is_Static_Expression (Expr) then
1676 Flag_Non_Static_Expr
1677 ("Bit_Order requires static expression!", Expr);
1680 if (Expr_Value (Expr) = 0) /= Bytes_Big_Endian then
1681 Set_Reverse_Bit_Order (U_Ent, True);
1687 --------------------
1688 -- Component_Size --
1689 --------------------
1691 -- Component_Size attribute definition clause
1693 when Attribute_Component_Size => Component_Size_Case : declare
1694 Csize : constant Uint := Static_Integer (Expr);
1698 New_Ctyp : Entity_Id;
1702 if not Is_Array_Type (U_Ent) then
1703 Error_Msg_N ("component size requires array type", Nam);
1707 Btype := Base_Type (U_Ent);
1708 Ctyp := Component_Type (Btype);
1710 if Duplicate_Clause then
1713 elsif Rep_Item_Too_Early (Btype, N) then
1716 elsif Csize /= No_Uint then
1717 Check_Size (Expr, Ctyp, Csize, Biased);
1719 -- For the biased case, build a declaration for a subtype that
1720 -- will be used to represent the biased subtype that reflects
1721 -- the biased representation of components. We need the subtype
1722 -- to get proper conversions on referencing elements of the
1723 -- array. Note: component size clauses are ignored in VM mode.
1725 if VM_Target = No_VM then
1728 Make_Defining_Identifier (Loc,
1730 New_External_Name (Chars (U_Ent), 'C', 0, 'T'));
1733 Make_Subtype_Declaration (Loc,
1734 Defining_Identifier => New_Ctyp,
1735 Subtype_Indication =>
1736 New_Occurrence_Of (Component_Type (Btype), Loc));
1738 Set_Parent (Decl, N);
1739 Analyze (Decl, Suppress => All_Checks);
1741 Set_Has_Delayed_Freeze (New_Ctyp, False);
1742 Set_Esize (New_Ctyp, Csize);
1743 Set_RM_Size (New_Ctyp, Csize);
1744 Init_Alignment (New_Ctyp);
1745 Set_Is_Itype (New_Ctyp, True);
1746 Set_Associated_Node_For_Itype (New_Ctyp, U_Ent);
1748 Set_Component_Type (Btype, New_Ctyp);
1749 Set_Biased (New_Ctyp, N, "component size clause");
1752 Set_Component_Size (Btype, Csize);
1754 -- For VM case, we ignore component size clauses
1757 -- Give a warning unless we are in GNAT mode, in which case
1758 -- the warning is suppressed since it is not useful.
1760 if not GNAT_Mode then
1762 ("?component size ignored in this configuration", N);
1766 -- Deal with warning on overridden size
1768 if Warn_On_Overridden_Size
1769 and then Has_Size_Clause (Ctyp)
1770 and then RM_Size (Ctyp) /= Csize
1773 ("?component size overrides size clause for&",
1777 Set_Has_Component_Size_Clause (Btype, True);
1778 Set_Has_Non_Standard_Rep (Btype, True);
1780 end Component_Size_Case;
1786 when Attribute_External_Tag => External_Tag :
1788 if not Is_Tagged_Type (U_Ent) then
1789 Error_Msg_N ("should be a tagged type", Nam);
1792 if Duplicate_Clause then
1796 Analyze_And_Resolve (Expr, Standard_String);
1798 if not Is_Static_Expression (Expr) then
1799 Flag_Non_Static_Expr
1800 ("static string required for tag name!", Nam);
1803 if VM_Target = No_VM then
1804 Set_Has_External_Tag_Rep_Clause (U_Ent);
1806 Error_Msg_Name_1 := Attr;
1808 ("% attribute unsupported in this configuration", Nam);
1811 if not Is_Library_Level_Entity (U_Ent) then
1813 ("?non-unique external tag supplied for &", N, U_Ent);
1815 ("?\same external tag applies to all subprogram calls", N);
1817 ("?\corresponding internal tag cannot be obtained", N);
1826 when Attribute_Input =>
1827 Analyze_Stream_TSS_Definition (TSS_Stream_Input);
1828 Set_Has_Specified_Stream_Input (Ent);
1834 -- Machine radix attribute definition clause
1836 when Attribute_Machine_Radix => Machine_Radix : declare
1837 Radix : constant Uint := Static_Integer (Expr);
1840 if not Is_Decimal_Fixed_Point_Type (U_Ent) then
1841 Error_Msg_N ("decimal fixed-point type expected for &", Nam);
1843 elsif Duplicate_Clause then
1846 elsif Radix /= No_Uint then
1847 Set_Has_Machine_Radix_Clause (U_Ent);
1848 Set_Has_Non_Standard_Rep (Base_Type (U_Ent));
1852 elsif Radix = 10 then
1853 Set_Machine_Radix_10 (U_Ent);
1855 Error_Msg_N ("machine radix value must be 2 or 10", Expr);
1864 -- Object_Size attribute definition clause
1866 when Attribute_Object_Size => Object_Size : declare
1867 Size : constant Uint := Static_Integer (Expr);
1870 pragma Warnings (Off, Biased);
1873 if not Is_Type (U_Ent) then
1874 Error_Msg_N ("Object_Size cannot be given for &", Nam);
1876 elsif Duplicate_Clause then
1880 Check_Size (Expr, U_Ent, Size, Biased);
1888 UI_Mod (Size, 64) /= 0
1891 ("Object_Size must be 8, 16, 32, or multiple of 64",
1895 Set_Esize (U_Ent, Size);
1896 Set_Has_Object_Size_Clause (U_Ent);
1897 Alignment_Check_For_Esize_Change (U_Ent);
1905 when Attribute_Output =>
1906 Analyze_Stream_TSS_Definition (TSS_Stream_Output);
1907 Set_Has_Specified_Stream_Output (Ent);
1913 when Attribute_Read =>
1914 Analyze_Stream_TSS_Definition (TSS_Stream_Read);
1915 Set_Has_Specified_Stream_Read (Ent);
1921 -- Size attribute definition clause
1923 when Attribute_Size => Size : declare
1924 Size : constant Uint := Static_Integer (Expr);
1931 if Duplicate_Clause then
1934 elsif not Is_Type (U_Ent)
1935 and then Ekind (U_Ent) /= E_Variable
1936 and then Ekind (U_Ent) /= E_Constant
1938 Error_Msg_N ("size cannot be given for &", Nam);
1940 elsif Is_Array_Type (U_Ent)
1941 and then not Is_Constrained (U_Ent)
1944 ("size cannot be given for unconstrained array", Nam);
1946 elsif Size /= No_Uint then
1948 if VM_Target /= No_VM and then not GNAT_Mode then
1950 -- Size clause is not handled properly on VM targets.
1951 -- Display a warning unless we are in GNAT mode, in which
1952 -- case this is useless.
1955 ("?size clauses are ignored in this configuration", N);
1958 if Is_Type (U_Ent) then
1961 Etyp := Etype (U_Ent);
1964 -- Check size, note that Gigi is in charge of checking that the
1965 -- size of an array or record type is OK. Also we do not check
1966 -- the size in the ordinary fixed-point case, since it is too
1967 -- early to do so (there may be subsequent small clause that
1968 -- affects the size). We can check the size if a small clause
1969 -- has already been given.
1971 if not Is_Ordinary_Fixed_Point_Type (U_Ent)
1972 or else Has_Small_Clause (U_Ent)
1974 Check_Size (Expr, Etyp, Size, Biased);
1975 Set_Biased (U_Ent, N, "size clause", Biased);
1978 -- For types set RM_Size and Esize if possible
1980 if Is_Type (U_Ent) then
1981 Set_RM_Size (U_Ent, Size);
1983 -- For scalar types, increase Object_Size to power of 2, but
1984 -- not less than a storage unit in any case (i.e., normally
1985 -- this means it will be byte addressable).
1987 if Is_Scalar_Type (U_Ent) then
1988 if Size <= System_Storage_Unit then
1989 Init_Esize (U_Ent, System_Storage_Unit);
1990 elsif Size <= 16 then
1991 Init_Esize (U_Ent, 16);
1992 elsif Size <= 32 then
1993 Init_Esize (U_Ent, 32);
1995 Set_Esize (U_Ent, (Size + 63) / 64 * 64);
1998 -- For all other types, object size = value size. The
1999 -- backend will adjust as needed.
2002 Set_Esize (U_Ent, Size);
2005 Alignment_Check_For_Esize_Change (U_Ent);
2007 -- For objects, set Esize only
2010 if Is_Elementary_Type (Etyp) then
2011 if Size /= System_Storage_Unit
2013 Size /= System_Storage_Unit * 2
2015 Size /= System_Storage_Unit * 4
2017 Size /= System_Storage_Unit * 8
2019 Error_Msg_Uint_1 := UI_From_Int (System_Storage_Unit);
2020 Error_Msg_Uint_2 := Error_Msg_Uint_1 * 8;
2022 ("size for primitive object must be a power of 2"
2023 & " in the range ^-^", N);
2027 Set_Esize (U_Ent, Size);
2030 Set_Has_Size_Clause (U_Ent);
2038 -- Small attribute definition clause
2040 when Attribute_Small => Small : declare
2041 Implicit_Base : constant Entity_Id := Base_Type (U_Ent);
2045 Analyze_And_Resolve (Expr, Any_Real);
2047 if Etype (Expr) = Any_Type then
2050 elsif not Is_Static_Expression (Expr) then
2051 Flag_Non_Static_Expr
2052 ("small requires static expression!", Expr);
2056 Small := Expr_Value_R (Expr);
2058 if Small <= Ureal_0 then
2059 Error_Msg_N ("small value must be greater than zero", Expr);
2065 if not Is_Ordinary_Fixed_Point_Type (U_Ent) then
2067 ("small requires an ordinary fixed point type", Nam);
2069 elsif Has_Small_Clause (U_Ent) then
2070 Error_Msg_N ("small already given for &", Nam);
2072 elsif Small > Delta_Value (U_Ent) then
2074 ("small value must not be greater then delta value", Nam);
2077 Set_Small_Value (U_Ent, Small);
2078 Set_Small_Value (Implicit_Base, Small);
2079 Set_Has_Small_Clause (U_Ent);
2080 Set_Has_Small_Clause (Implicit_Base);
2081 Set_Has_Non_Standard_Rep (Implicit_Base);
2089 -- Storage_Pool attribute definition clause
2091 when Attribute_Storage_Pool => Storage_Pool : declare
2096 if Ekind (U_Ent) = E_Access_Subprogram_Type then
2098 ("storage pool cannot be given for access-to-subprogram type",
2103 Ekind_In (U_Ent, E_Access_Type, E_General_Access_Type)
2106 ("storage pool can only be given for access types", Nam);
2109 elsif Is_Derived_Type (U_Ent) then
2111 ("storage pool cannot be given for a derived access type",
2114 elsif Duplicate_Clause then
2117 elsif Present (Associated_Storage_Pool (U_Ent)) then
2118 Error_Msg_N ("storage pool already given for &", Nam);
2123 (Expr, Class_Wide_Type (RTE (RE_Root_Storage_Pool)));
2125 if not Denotes_Variable (Expr) then
2126 Error_Msg_N ("storage pool must be a variable", Expr);
2130 if Nkind (Expr) = N_Type_Conversion then
2131 T := Etype (Expression (Expr));
2136 -- The Stack_Bounded_Pool is used internally for implementing
2137 -- access types with a Storage_Size. Since it only work
2138 -- properly when used on one specific type, we need to check
2139 -- that it is not hijacked improperly:
2140 -- type T is access Integer;
2141 -- for T'Storage_Size use n;
2142 -- type Q is access Float;
2143 -- for Q'Storage_Size use T'Storage_Size; -- incorrect
2145 if RTE_Available (RE_Stack_Bounded_Pool)
2146 and then Base_Type (T) = RTE (RE_Stack_Bounded_Pool)
2148 Error_Msg_N ("non-shareable internal Pool", Expr);
2152 -- If the argument is a name that is not an entity name, then
2153 -- we construct a renaming operation to define an entity of
2154 -- type storage pool.
2156 if not Is_Entity_Name (Expr)
2157 and then Is_Object_Reference (Expr)
2159 Pool := Make_Temporary (Loc, 'P', Expr);
2162 Rnode : constant Node_Id :=
2163 Make_Object_Renaming_Declaration (Loc,
2164 Defining_Identifier => Pool,
2166 New_Occurrence_Of (Etype (Expr), Loc),
2170 Insert_Before (N, Rnode);
2172 Set_Associated_Storage_Pool (U_Ent, Pool);
2175 elsif Is_Entity_Name (Expr) then
2176 Pool := Entity (Expr);
2178 -- If pool is a renamed object, get original one. This can
2179 -- happen with an explicit renaming, and within instances.
2181 while Present (Renamed_Object (Pool))
2182 and then Is_Entity_Name (Renamed_Object (Pool))
2184 Pool := Entity (Renamed_Object (Pool));
2187 if Present (Renamed_Object (Pool))
2188 and then Nkind (Renamed_Object (Pool)) = N_Type_Conversion
2189 and then Is_Entity_Name (Expression (Renamed_Object (Pool)))
2191 Pool := Entity (Expression (Renamed_Object (Pool)));
2194 Set_Associated_Storage_Pool (U_Ent, Pool);
2196 elsif Nkind (Expr) = N_Type_Conversion
2197 and then Is_Entity_Name (Expression (Expr))
2198 and then Nkind (Original_Node (Expr)) = N_Attribute_Reference
2200 Pool := Entity (Expression (Expr));
2201 Set_Associated_Storage_Pool (U_Ent, Pool);
2204 Error_Msg_N ("incorrect reference to a Storage Pool", Expr);
2213 -- Storage_Size attribute definition clause
2215 when Attribute_Storage_Size => Storage_Size : declare
2216 Btype : constant Entity_Id := Base_Type (U_Ent);
2220 if Is_Task_Type (U_Ent) then
2221 Check_Restriction (No_Obsolescent_Features, N);
2223 if Warn_On_Obsolescent_Feature then
2225 ("storage size clause for task is an " &
2226 "obsolescent feature (RM J.9)?", N);
2227 Error_Msg_N ("\use Storage_Size pragma instead?", N);
2233 if not Is_Access_Type (U_Ent)
2234 and then Ekind (U_Ent) /= E_Task_Type
2236 Error_Msg_N ("storage size cannot be given for &", Nam);
2238 elsif Is_Access_Type (U_Ent) and Is_Derived_Type (U_Ent) then
2240 ("storage size cannot be given for a derived access type",
2243 elsif Duplicate_Clause then
2247 Analyze_And_Resolve (Expr, Any_Integer);
2249 if Is_Access_Type (U_Ent) then
2250 if Present (Associated_Storage_Pool (U_Ent)) then
2251 Error_Msg_N ("storage pool already given for &", Nam);
2255 if Is_OK_Static_Expression (Expr)
2256 and then Expr_Value (Expr) = 0
2258 Set_No_Pool_Assigned (Btype);
2261 else -- Is_Task_Type (U_Ent)
2262 Sprag := Get_Rep_Pragma (Btype, Name_Storage_Size);
2264 if Present (Sprag) then
2265 Error_Msg_Sloc := Sloc (Sprag);
2267 ("Storage_Size already specified#", Nam);
2272 Set_Has_Storage_Size_Clause (Btype);
2280 when Attribute_Stream_Size => Stream_Size : declare
2281 Size : constant Uint := Static_Integer (Expr);
2284 if Ada_Version <= Ada_95 then
2285 Check_Restriction (No_Implementation_Attributes, N);
2288 if Duplicate_Clause then
2291 elsif Is_Elementary_Type (U_Ent) then
2292 if Size /= System_Storage_Unit
2294 Size /= System_Storage_Unit * 2
2296 Size /= System_Storage_Unit * 4
2298 Size /= System_Storage_Unit * 8
2300 Error_Msg_Uint_1 := UI_From_Int (System_Storage_Unit);
2302 ("stream size for elementary type must be a"
2303 & " power of 2 and at least ^", N);
2305 elsif RM_Size (U_Ent) > Size then
2306 Error_Msg_Uint_1 := RM_Size (U_Ent);
2308 ("stream size for elementary type must be a"
2309 & " power of 2 and at least ^", N);
2312 Set_Has_Stream_Size_Clause (U_Ent);
2315 Error_Msg_N ("Stream_Size cannot be given for &", Nam);
2323 -- Value_Size attribute definition clause
2325 when Attribute_Value_Size => Value_Size : declare
2326 Size : constant Uint := Static_Integer (Expr);
2330 if not Is_Type (U_Ent) then
2331 Error_Msg_N ("Value_Size cannot be given for &", Nam);
2333 elsif Duplicate_Clause then
2336 elsif Is_Array_Type (U_Ent)
2337 and then not Is_Constrained (U_Ent)
2340 ("Value_Size cannot be given for unconstrained array", Nam);
2343 if Is_Elementary_Type (U_Ent) then
2344 Check_Size (Expr, U_Ent, Size, Biased);
2345 Set_Biased (U_Ent, N, "value size clause", Biased);
2348 Set_RM_Size (U_Ent, Size);
2356 when Attribute_Write =>
2357 Analyze_Stream_TSS_Definition (TSS_Stream_Write);
2358 Set_Has_Specified_Stream_Write (Ent);
2360 -- All other attributes cannot be set
2364 ("attribute& cannot be set with definition clause", N);
2367 -- The test for the type being frozen must be performed after
2368 -- any expression the clause has been analyzed since the expression
2369 -- itself might cause freezing that makes the clause illegal.
2371 if Rep_Item_Too_Late (U_Ent, N, FOnly) then
2374 end Analyze_Attribute_Definition_Clause;
2376 ----------------------------
2377 -- Analyze_Code_Statement --
2378 ----------------------------
2380 procedure Analyze_Code_Statement (N : Node_Id) is
2381 HSS : constant Node_Id := Parent (N);
2382 SBody : constant Node_Id := Parent (HSS);
2383 Subp : constant Entity_Id := Current_Scope;
2390 -- Analyze and check we get right type, note that this implements the
2391 -- requirement (RM 13.8(1)) that Machine_Code be with'ed, since that
2392 -- is the only way that Asm_Insn could possibly be visible.
2394 Analyze_And_Resolve (Expression (N));
2396 if Etype (Expression (N)) = Any_Type then
2398 elsif Etype (Expression (N)) /= RTE (RE_Asm_Insn) then
2399 Error_Msg_N ("incorrect type for code statement", N);
2403 Check_Code_Statement (N);
2405 -- Make sure we appear in the handled statement sequence of a
2406 -- subprogram (RM 13.8(3)).
2408 if Nkind (HSS) /= N_Handled_Sequence_Of_Statements
2409 or else Nkind (SBody) /= N_Subprogram_Body
2412 ("code statement can only appear in body of subprogram", N);
2416 -- Do remaining checks (RM 13.8(3)) if not already done
2418 if not Is_Machine_Code_Subprogram (Subp) then
2419 Set_Is_Machine_Code_Subprogram (Subp);
2421 -- No exception handlers allowed
2423 if Present (Exception_Handlers (HSS)) then
2425 ("exception handlers not permitted in machine code subprogram",
2426 First (Exception_Handlers (HSS)));
2429 -- No declarations other than use clauses and pragmas (we allow
2430 -- certain internally generated declarations as well).
2432 Decl := First (Declarations (SBody));
2433 while Present (Decl) loop
2434 DeclO := Original_Node (Decl);
2435 if Comes_From_Source (DeclO)
2436 and not Nkind_In (DeclO, N_Pragma,
2437 N_Use_Package_Clause,
2439 N_Implicit_Label_Declaration)
2442 ("this declaration not allowed in machine code subprogram",
2449 -- No statements other than code statements, pragmas, and labels.
2450 -- Again we allow certain internally generated statements.
2452 Stmt := First (Statements (HSS));
2453 while Present (Stmt) loop
2454 StmtO := Original_Node (Stmt);
2455 if Comes_From_Source (StmtO)
2456 and then not Nkind_In (StmtO, N_Pragma,
2461 ("this statement is not allowed in machine code subprogram",
2468 end Analyze_Code_Statement;
2470 -----------------------------------------------
2471 -- Analyze_Enumeration_Representation_Clause --
2472 -----------------------------------------------
2474 procedure Analyze_Enumeration_Representation_Clause (N : Node_Id) is
2475 Ident : constant Node_Id := Identifier (N);
2476 Aggr : constant Node_Id := Array_Aggregate (N);
2477 Enumtype : Entity_Id;
2483 Err : Boolean := False;
2485 Lo : constant Uint := Expr_Value (Type_Low_Bound (Universal_Integer));
2486 Hi : constant Uint := Expr_Value (Type_High_Bound (Universal_Integer));
2487 -- Allowed range of universal integer (= allowed range of enum lit vals)
2491 -- Minimum and maximum values of entries
2494 -- Pointer to node for literal providing max value
2497 if Ignore_Rep_Clauses then
2501 -- First some basic error checks
2504 Enumtype := Entity (Ident);
2506 if Enumtype = Any_Type
2507 or else Rep_Item_Too_Early (Enumtype, N)
2511 Enumtype := Underlying_Type (Enumtype);
2514 if not Is_Enumeration_Type (Enumtype) then
2516 ("enumeration type required, found}",
2517 Ident, First_Subtype (Enumtype));
2521 -- Ignore rep clause on generic actual type. This will already have
2522 -- been flagged on the template as an error, and this is the safest
2523 -- way to ensure we don't get a junk cascaded message in the instance.
2525 if Is_Generic_Actual_Type (Enumtype) then
2528 -- Type must be in current scope
2530 elsif Scope (Enumtype) /= Current_Scope then
2531 Error_Msg_N ("type must be declared in this scope", Ident);
2534 -- Type must be a first subtype
2536 elsif not Is_First_Subtype (Enumtype) then
2537 Error_Msg_N ("cannot give enumeration rep clause for subtype", N);
2540 -- Ignore duplicate rep clause
2542 elsif Has_Enumeration_Rep_Clause (Enumtype) then
2543 Error_Msg_N ("duplicate enumeration rep clause ignored", N);
2546 -- Don't allow rep clause for standard [wide_[wide_]]character
2548 elsif Is_Standard_Character_Type (Enumtype) then
2549 Error_Msg_N ("enumeration rep clause not allowed for this type", N);
2552 -- Check that the expression is a proper aggregate (no parentheses)
2554 elsif Paren_Count (Aggr) /= 0 then
2556 ("extra parentheses surrounding aggregate not allowed",
2560 -- All tests passed, so set rep clause in place
2563 Set_Has_Enumeration_Rep_Clause (Enumtype);
2564 Set_Has_Enumeration_Rep_Clause (Base_Type (Enumtype));
2567 -- Now we process the aggregate. Note that we don't use the normal
2568 -- aggregate code for this purpose, because we don't want any of the
2569 -- normal expansion activities, and a number of special semantic
2570 -- rules apply (including the component type being any integer type)
2572 Elit := First_Literal (Enumtype);
2574 -- First the positional entries if any
2576 if Present (Expressions (Aggr)) then
2577 Expr := First (Expressions (Aggr));
2578 while Present (Expr) loop
2580 Error_Msg_N ("too many entries in aggregate", Expr);
2584 Val := Static_Integer (Expr);
2586 -- Err signals that we found some incorrect entries processing
2587 -- the list. The final checks for completeness and ordering are
2588 -- skipped in this case.
2590 if Val = No_Uint then
2592 elsif Val < Lo or else Hi < Val then
2593 Error_Msg_N ("value outside permitted range", Expr);
2597 Set_Enumeration_Rep (Elit, Val);
2598 Set_Enumeration_Rep_Expr (Elit, Expr);
2604 -- Now process the named entries if present
2606 if Present (Component_Associations (Aggr)) then
2607 Assoc := First (Component_Associations (Aggr));
2608 while Present (Assoc) loop
2609 Choice := First (Choices (Assoc));
2611 if Present (Next (Choice)) then
2613 ("multiple choice not allowed here", Next (Choice));
2617 if Nkind (Choice) = N_Others_Choice then
2618 Error_Msg_N ("others choice not allowed here", Choice);
2621 elsif Nkind (Choice) = N_Range then
2622 -- ??? should allow zero/one element range here
2623 Error_Msg_N ("range not allowed here", Choice);
2627 Analyze_And_Resolve (Choice, Enumtype);
2629 if Is_Entity_Name (Choice)
2630 and then Is_Type (Entity (Choice))
2632 Error_Msg_N ("subtype name not allowed here", Choice);
2634 -- ??? should allow static subtype with zero/one entry
2636 elsif Etype (Choice) = Base_Type (Enumtype) then
2637 if not Is_Static_Expression (Choice) then
2638 Flag_Non_Static_Expr
2639 ("non-static expression used for choice!", Choice);
2643 Elit := Expr_Value_E (Choice);
2645 if Present (Enumeration_Rep_Expr (Elit)) then
2646 Error_Msg_Sloc := Sloc (Enumeration_Rep_Expr (Elit));
2648 ("representation for& previously given#",
2653 Set_Enumeration_Rep_Expr (Elit, Expression (Assoc));
2655 Expr := Expression (Assoc);
2656 Val := Static_Integer (Expr);
2658 if Val = No_Uint then
2661 elsif Val < Lo or else Hi < Val then
2662 Error_Msg_N ("value outside permitted range", Expr);
2666 Set_Enumeration_Rep (Elit, Val);
2675 -- Aggregate is fully processed. Now we check that a full set of
2676 -- representations was given, and that they are in range and in order.
2677 -- These checks are only done if no other errors occurred.
2683 Elit := First_Literal (Enumtype);
2684 while Present (Elit) loop
2685 if No (Enumeration_Rep_Expr (Elit)) then
2686 Error_Msg_NE ("missing representation for&!", N, Elit);
2689 Val := Enumeration_Rep (Elit);
2691 if Min = No_Uint then
2695 if Val /= No_Uint then
2696 if Max /= No_Uint and then Val <= Max then
2698 ("enumeration value for& not ordered!",
2699 Enumeration_Rep_Expr (Elit), Elit);
2702 Max_Node := Enumeration_Rep_Expr (Elit);
2706 -- If there is at least one literal whose representation is not
2707 -- equal to the Pos value, then note that this enumeration type
2708 -- has a non-standard representation.
2710 if Val /= Enumeration_Pos (Elit) then
2711 Set_Has_Non_Standard_Rep (Base_Type (Enumtype));
2718 -- Now set proper size information
2721 Minsize : Uint := UI_From_Int (Minimum_Size (Enumtype));
2724 if Has_Size_Clause (Enumtype) then
2726 -- All OK, if size is OK now
2728 if RM_Size (Enumtype) >= Minsize then
2732 -- Try if we can get by with biasing
2735 UI_From_Int (Minimum_Size (Enumtype, Biased => True));
2737 -- Error message if even biasing does not work
2739 if RM_Size (Enumtype) < Minsize then
2740 Error_Msg_Uint_1 := RM_Size (Enumtype);
2741 Error_Msg_Uint_2 := Max;
2743 ("previously given size (^) is too small "
2744 & "for this value (^)", Max_Node);
2746 -- If biasing worked, indicate that we now have biased rep
2750 (Enumtype, Size_Clause (Enumtype), "size clause");
2755 Set_RM_Size (Enumtype, Minsize);
2756 Set_Enum_Esize (Enumtype);
2759 Set_RM_Size (Base_Type (Enumtype), RM_Size (Enumtype));
2760 Set_Esize (Base_Type (Enumtype), Esize (Enumtype));
2761 Set_Alignment (Base_Type (Enumtype), Alignment (Enumtype));
2765 -- We repeat the too late test in case it froze itself!
2767 if Rep_Item_Too_Late (Enumtype, N) then
2770 end Analyze_Enumeration_Representation_Clause;
2772 ----------------------------
2773 -- Analyze_Free_Statement --
2774 ----------------------------
2776 procedure Analyze_Free_Statement (N : Node_Id) is
2778 Analyze (Expression (N));
2779 end Analyze_Free_Statement;
2781 ---------------------------
2782 -- Analyze_Freeze_Entity --
2783 ---------------------------
2785 procedure Analyze_Freeze_Entity (N : Node_Id) is
2786 E : constant Entity_Id := Entity (N);
2789 -- Remember that we are processing a freezing entity. Required to
2790 -- ensure correct decoration of internal entities associated with
2791 -- interfaces (see New_Overloaded_Entity).
2793 Inside_Freezing_Actions := Inside_Freezing_Actions + 1;
2795 -- For tagged types covering interfaces add internal entities that link
2796 -- the primitives of the interfaces with the primitives that cover them.
2797 -- Note: These entities were originally generated only when generating
2798 -- code because their main purpose was to provide support to initialize
2799 -- the secondary dispatch tables. They are now generated also when
2800 -- compiling with no code generation to provide ASIS the relationship
2801 -- between interface primitives and tagged type primitives. They are
2802 -- also used to locate primitives covering interfaces when processing
2803 -- generics (see Derive_Subprograms).
2805 if Ada_Version >= Ada_2005
2806 and then Ekind (E) = E_Record_Type
2807 and then Is_Tagged_Type (E)
2808 and then not Is_Interface (E)
2809 and then Has_Interfaces (E)
2811 -- This would be a good common place to call the routine that checks
2812 -- overriding of interface primitives (and thus factorize calls to
2813 -- Check_Abstract_Overriding located at different contexts in the
2814 -- compiler). However, this is not possible because it causes
2815 -- spurious errors in case of late overriding.
2817 Add_Internal_Interface_Entities (E);
2822 if Ekind (E) = E_Record_Type
2823 and then Is_CPP_Class (E)
2824 and then Is_Tagged_Type (E)
2825 and then Tagged_Type_Expansion
2826 and then Expander_Active
2828 if CPP_Num_Prims (E) = 0 then
2830 -- If the CPP type has user defined components then it must import
2831 -- primitives from C++. This is required because if the C++ class
2832 -- has no primitives then the C++ compiler does not added the _tag
2833 -- component to the type.
2835 pragma Assert (Chars (First_Entity (E)) = Name_uTag);
2837 if First_Entity (E) /= Last_Entity (E) then
2839 ("?'C'P'P type must import at least one primitive from C++",
2844 -- Check that all its primitives are abstract or imported from C++.
2845 -- Check also availability of the C++ constructor.
2848 Has_Constructors : constant Boolean := Has_CPP_Constructors (E);
2850 Error_Reported : Boolean := False;
2854 Elmt := First_Elmt (Primitive_Operations (E));
2855 while Present (Elmt) loop
2856 Prim := Node (Elmt);
2858 if Comes_From_Source (Prim) then
2859 if Is_Abstract_Subprogram (Prim) then
2862 elsif not Is_Imported (Prim)
2863 or else Convention (Prim) /= Convention_CPP
2866 ("?primitives of 'C'P'P types must be imported from C++"
2867 & " or abstract", Prim);
2869 elsif not Has_Constructors
2870 and then not Error_Reported
2872 Error_Msg_Name_1 := Chars (E);
2874 ("?'C'P'P constructor required for type %", Prim);
2875 Error_Reported := True;
2884 Inside_Freezing_Actions := Inside_Freezing_Actions - 1;
2885 end Analyze_Freeze_Entity;
2887 ------------------------------------------
2888 -- Analyze_Record_Representation_Clause --
2889 ------------------------------------------
2891 -- Note: we check as much as we can here, but we can't do any checks
2892 -- based on the position values (e.g. overlap checks) until freeze time
2893 -- because especially in Ada 2005 (machine scalar mode), the processing
2894 -- for non-standard bit order can substantially change the positions.
2895 -- See procedure Check_Record_Representation_Clause (called from Freeze)
2896 -- for the remainder of this processing.
2898 procedure Analyze_Record_Representation_Clause (N : Node_Id) is
2899 Ident : constant Node_Id := Identifier (N);
2904 Hbit : Uint := Uint_0;
2908 Rectype : Entity_Id;
2910 CR_Pragma : Node_Id := Empty;
2911 -- Points to N_Pragma node if Complete_Representation pragma present
2914 if Ignore_Rep_Clauses then
2919 Rectype := Entity (Ident);
2921 if Rectype = Any_Type
2922 or else Rep_Item_Too_Early (Rectype, N)
2926 Rectype := Underlying_Type (Rectype);
2929 -- First some basic error checks
2931 if not Is_Record_Type (Rectype) then
2933 ("record type required, found}", Ident, First_Subtype (Rectype));
2936 elsif Scope (Rectype) /= Current_Scope then
2937 Error_Msg_N ("type must be declared in this scope", N);
2940 elsif not Is_First_Subtype (Rectype) then
2941 Error_Msg_N ("cannot give record rep clause for subtype", N);
2944 elsif Has_Record_Rep_Clause (Rectype) then
2945 Error_Msg_N ("duplicate record rep clause ignored", N);
2948 elsif Rep_Item_Too_Late (Rectype, N) then
2952 if Present (Mod_Clause (N)) then
2954 Loc : constant Source_Ptr := Sloc (N);
2955 M : constant Node_Id := Mod_Clause (N);
2956 P : constant List_Id := Pragmas_Before (M);
2960 pragma Warnings (Off, Mod_Val);
2963 Check_Restriction (No_Obsolescent_Features, Mod_Clause (N));
2965 if Warn_On_Obsolescent_Feature then
2967 ("mod clause is an obsolescent feature (RM J.8)?", N);
2969 ("\use alignment attribute definition clause instead?", N);
2976 -- In ASIS_Mode mode, expansion is disabled, but we must convert
2977 -- the Mod clause into an alignment clause anyway, so that the
2978 -- back-end can compute and back-annotate properly the size and
2979 -- alignment of types that may include this record.
2981 -- This seems dubious, this destroys the source tree in a manner
2982 -- not detectable by ASIS ???
2984 if Operating_Mode = Check_Semantics
2988 Make_Attribute_Definition_Clause (Loc,
2989 Name => New_Reference_To (Base_Type (Rectype), Loc),
2990 Chars => Name_Alignment,
2991 Expression => Relocate_Node (Expression (M)));
2993 Set_From_At_Mod (AtM_Nod);
2994 Insert_After (N, AtM_Nod);
2995 Mod_Val := Get_Alignment_Value (Expression (AtM_Nod));
2996 Set_Mod_Clause (N, Empty);
2999 -- Get the alignment value to perform error checking
3001 Mod_Val := Get_Alignment_Value (Expression (M));
3006 -- For untagged types, clear any existing component clauses for the
3007 -- type. If the type is derived, this is what allows us to override
3008 -- a rep clause for the parent. For type extensions, the representation
3009 -- of the inherited components is inherited, so we want to keep previous
3010 -- component clauses for completeness.
3012 if not Is_Tagged_Type (Rectype) then
3013 Comp := First_Component_Or_Discriminant (Rectype);
3014 while Present (Comp) loop
3015 Set_Component_Clause (Comp, Empty);
3016 Next_Component_Or_Discriminant (Comp);
3020 -- All done if no component clauses
3022 CC := First (Component_Clauses (N));
3028 -- A representation like this applies to the base type
3030 Set_Has_Record_Rep_Clause (Base_Type (Rectype));
3031 Set_Has_Non_Standard_Rep (Base_Type (Rectype));
3032 Set_Has_Specified_Layout (Base_Type (Rectype));
3034 -- Process the component clauses
3036 while Present (CC) loop
3040 if Nkind (CC) = N_Pragma then
3043 -- The only pragma of interest is Complete_Representation
3045 if Pragma_Name (CC) = Name_Complete_Representation then
3049 -- Processing for real component clause
3052 Posit := Static_Integer (Position (CC));
3053 Fbit := Static_Integer (First_Bit (CC));
3054 Lbit := Static_Integer (Last_Bit (CC));
3057 and then Fbit /= No_Uint
3058 and then Lbit /= No_Uint
3062 ("position cannot be negative", Position (CC));
3066 ("first bit cannot be negative", First_Bit (CC));
3068 -- The Last_Bit specified in a component clause must not be
3069 -- less than the First_Bit minus one (RM-13.5.1(10)).
3071 elsif Lbit < Fbit - 1 then
3073 ("last bit cannot be less than first bit minus one",
3076 -- Values look OK, so find the corresponding record component
3077 -- Even though the syntax allows an attribute reference for
3078 -- implementation-defined components, GNAT does not allow the
3079 -- tag to get an explicit position.
3081 elsif Nkind (Component_Name (CC)) = N_Attribute_Reference then
3082 if Attribute_Name (Component_Name (CC)) = Name_Tag then
3083 Error_Msg_N ("position of tag cannot be specified", CC);
3085 Error_Msg_N ("illegal component name", CC);
3089 Comp := First_Entity (Rectype);
3090 while Present (Comp) loop
3091 exit when Chars (Comp) = Chars (Component_Name (CC));
3097 -- Maybe component of base type that is absent from
3098 -- statically constrained first subtype.
3100 Comp := First_Entity (Base_Type (Rectype));
3101 while Present (Comp) loop
3102 exit when Chars (Comp) = Chars (Component_Name (CC));
3109 ("component clause is for non-existent field", CC);
3111 -- Ada 2012 (AI05-0026): Any name that denotes a
3112 -- discriminant of an object of an unchecked union type
3113 -- shall not occur within a record_representation_clause.
3115 -- The general restriction of using record rep clauses on
3116 -- Unchecked_Union types has now been lifted. Since it is
3117 -- possible to introduce a record rep clause which mentions
3118 -- the discriminant of an Unchecked_Union in non-Ada 2012
3119 -- code, this check is applied to all versions of the
3122 elsif Ekind (Comp) = E_Discriminant
3123 and then Is_Unchecked_Union (Rectype)
3126 ("cannot reference discriminant of Unchecked_Union",
3127 Component_Name (CC));
3129 elsif Present (Component_Clause (Comp)) then
3131 -- Diagnose duplicate rep clause, or check consistency
3132 -- if this is an inherited component. In a double fault,
3133 -- there may be a duplicate inconsistent clause for an
3134 -- inherited component.
3136 if Scope (Original_Record_Component (Comp)) = Rectype
3137 or else Parent (Component_Clause (Comp)) = N
3139 Error_Msg_Sloc := Sloc (Component_Clause (Comp));
3140 Error_Msg_N ("component clause previously given#", CC);
3144 Rep1 : constant Node_Id := Component_Clause (Comp);
3146 if Intval (Position (Rep1)) /=
3147 Intval (Position (CC))
3148 or else Intval (First_Bit (Rep1)) /=
3149 Intval (First_Bit (CC))
3150 or else Intval (Last_Bit (Rep1)) /=
3151 Intval (Last_Bit (CC))
3153 Error_Msg_N ("component clause inconsistent "
3154 & "with representation of ancestor", CC);
3155 elsif Warn_On_Redundant_Constructs then
3156 Error_Msg_N ("?redundant component clause "
3157 & "for inherited component!", CC);
3162 -- Normal case where this is the first component clause we
3163 -- have seen for this entity, so set it up properly.
3166 -- Make reference for field in record rep clause and set
3167 -- appropriate entity field in the field identifier.
3170 (Comp, Component_Name (CC), Set_Ref => False);
3171 Set_Entity (Component_Name (CC), Comp);
3173 -- Update Fbit and Lbit to the actual bit number
3175 Fbit := Fbit + UI_From_Int (SSU) * Posit;
3176 Lbit := Lbit + UI_From_Int (SSU) * Posit;
3178 if Has_Size_Clause (Rectype)
3179 and then Esize (Rectype) <= Lbit
3182 ("bit number out of range of specified size",
3185 Set_Component_Clause (Comp, CC);
3186 Set_Component_Bit_Offset (Comp, Fbit);
3187 Set_Esize (Comp, 1 + (Lbit - Fbit));
3188 Set_Normalized_First_Bit (Comp, Fbit mod SSU);
3189 Set_Normalized_Position (Comp, Fbit / SSU);
3191 if Warn_On_Overridden_Size
3192 and then Has_Size_Clause (Etype (Comp))
3193 and then RM_Size (Etype (Comp)) /= Esize (Comp)
3196 ("?component size overrides size clause for&",
3197 Component_Name (CC), Etype (Comp));
3200 -- This information is also set in the corresponding
3201 -- component of the base type, found by accessing the
3202 -- Original_Record_Component link if it is present.
3204 Ocomp := Original_Record_Component (Comp);
3211 (Component_Name (CC),
3217 (Comp, First_Node (CC), "component clause", Biased);
3219 if Present (Ocomp) then
3220 Set_Component_Clause (Ocomp, CC);
3221 Set_Component_Bit_Offset (Ocomp, Fbit);
3222 Set_Normalized_First_Bit (Ocomp, Fbit mod SSU);
3223 Set_Normalized_Position (Ocomp, Fbit / SSU);
3224 Set_Esize (Ocomp, 1 + (Lbit - Fbit));
3226 Set_Normalized_Position_Max
3227 (Ocomp, Normalized_Position (Ocomp));
3229 -- Note: we don't use Set_Biased here, because we
3230 -- already gave a warning above if needed, and we
3231 -- would get a duplicate for the same name here.
3233 Set_Has_Biased_Representation
3234 (Ocomp, Has_Biased_Representation (Comp));
3237 if Esize (Comp) < 0 then
3238 Error_Msg_N ("component size is negative", CC);
3249 -- Check missing components if Complete_Representation pragma appeared
3251 if Present (CR_Pragma) then
3252 Comp := First_Component_Or_Discriminant (Rectype);
3253 while Present (Comp) loop
3254 if No (Component_Clause (Comp)) then
3256 ("missing component clause for &", CR_Pragma, Comp);
3259 Next_Component_Or_Discriminant (Comp);
3262 -- If no Complete_Representation pragma, warn if missing components
3264 elsif Warn_On_Unrepped_Components then
3266 Num_Repped_Components : Nat := 0;
3267 Num_Unrepped_Components : Nat := 0;
3270 -- First count number of repped and unrepped components
3272 Comp := First_Component_Or_Discriminant (Rectype);
3273 while Present (Comp) loop
3274 if Present (Component_Clause (Comp)) then
3275 Num_Repped_Components := Num_Repped_Components + 1;
3277 Num_Unrepped_Components := Num_Unrepped_Components + 1;
3280 Next_Component_Or_Discriminant (Comp);
3283 -- We are only interested in the case where there is at least one
3284 -- unrepped component, and at least half the components have rep
3285 -- clauses. We figure that if less than half have them, then the
3286 -- partial rep clause is really intentional. If the component
3287 -- type has no underlying type set at this point (as for a generic
3288 -- formal type), we don't know enough to give a warning on the
3291 if Num_Unrepped_Components > 0
3292 and then Num_Unrepped_Components < Num_Repped_Components
3294 Comp := First_Component_Or_Discriminant (Rectype);
3295 while Present (Comp) loop
3296 if No (Component_Clause (Comp))
3297 and then Comes_From_Source (Comp)
3298 and then Present (Underlying_Type (Etype (Comp)))
3299 and then (Is_Scalar_Type (Underlying_Type (Etype (Comp)))
3300 or else Size_Known_At_Compile_Time
3301 (Underlying_Type (Etype (Comp))))
3302 and then not Has_Warnings_Off (Rectype)
3304 Error_Msg_Sloc := Sloc (Comp);
3306 ("?no component clause given for & declared #",
3310 Next_Component_Or_Discriminant (Comp);
3315 end Analyze_Record_Representation_Clause;
3317 -----------------------------------
3318 -- Check_Constant_Address_Clause --
3319 -----------------------------------
3321 procedure Check_Constant_Address_Clause
3325 procedure Check_At_Constant_Address (Nod : Node_Id);
3326 -- Checks that the given node N represents a name whose 'Address is
3327 -- constant (in the same sense as OK_Constant_Address_Clause, i.e. the
3328 -- address value is the same at the point of declaration of U_Ent and at
3329 -- the time of elaboration of the address clause.
3331 procedure Check_Expr_Constants (Nod : Node_Id);
3332 -- Checks that Nod meets the requirements for a constant address clause
3333 -- in the sense of the enclosing procedure.
3335 procedure Check_List_Constants (Lst : List_Id);
3336 -- Check that all elements of list Lst meet the requirements for a
3337 -- constant address clause in the sense of the enclosing procedure.
3339 -------------------------------
3340 -- Check_At_Constant_Address --
3341 -------------------------------
3343 procedure Check_At_Constant_Address (Nod : Node_Id) is
3345 if Is_Entity_Name (Nod) then
3346 if Present (Address_Clause (Entity ((Nod)))) then
3348 ("invalid address clause for initialized object &!",
3351 ("address for& cannot" &
3352 " depend on another address clause! (RM 13.1(22))!",
3355 elsif In_Same_Source_Unit (Entity (Nod), U_Ent)
3356 and then Sloc (U_Ent) < Sloc (Entity (Nod))
3359 ("invalid address clause for initialized object &!",
3361 Error_Msg_Node_2 := U_Ent;
3363 ("\& must be defined before & (RM 13.1(22))!",
3367 elsif Nkind (Nod) = N_Selected_Component then
3369 T : constant Entity_Id := Etype (Prefix (Nod));
3372 if (Is_Record_Type (T)
3373 and then Has_Discriminants (T))
3376 and then Is_Record_Type (Designated_Type (T))
3377 and then Has_Discriminants (Designated_Type (T)))
3380 ("invalid address clause for initialized object &!",
3383 ("\address cannot depend on component" &
3384 " of discriminated record (RM 13.1(22))!",
3387 Check_At_Constant_Address (Prefix (Nod));
3391 elsif Nkind (Nod) = N_Indexed_Component then
3392 Check_At_Constant_Address (Prefix (Nod));
3393 Check_List_Constants (Expressions (Nod));
3396 Check_Expr_Constants (Nod);
3398 end Check_At_Constant_Address;
3400 --------------------------
3401 -- Check_Expr_Constants --
3402 --------------------------
3404 procedure Check_Expr_Constants (Nod : Node_Id) is
3405 Loc_U_Ent : constant Source_Ptr := Sloc (U_Ent);
3406 Ent : Entity_Id := Empty;
3409 if Nkind (Nod) in N_Has_Etype
3410 and then Etype (Nod) = Any_Type
3416 when N_Empty | N_Error =>
3419 when N_Identifier | N_Expanded_Name =>
3420 Ent := Entity (Nod);
3422 -- We need to look at the original node if it is different
3423 -- from the node, since we may have rewritten things and
3424 -- substituted an identifier representing the rewrite.
3426 if Original_Node (Nod) /= Nod then
3427 Check_Expr_Constants (Original_Node (Nod));
3429 -- If the node is an object declaration without initial
3430 -- value, some code has been expanded, and the expression
3431 -- is not constant, even if the constituents might be
3432 -- acceptable, as in A'Address + offset.
3434 if Ekind (Ent) = E_Variable
3436 Nkind (Declaration_Node (Ent)) = N_Object_Declaration
3438 No (Expression (Declaration_Node (Ent)))
3441 ("invalid address clause for initialized object &!",
3444 -- If entity is constant, it may be the result of expanding
3445 -- a check. We must verify that its declaration appears
3446 -- before the object in question, else we also reject the
3449 elsif Ekind (Ent) = E_Constant
3450 and then In_Same_Source_Unit (Ent, U_Ent)
3451 and then Sloc (Ent) > Loc_U_Ent
3454 ("invalid address clause for initialized object &!",
3461 -- Otherwise look at the identifier and see if it is OK
3463 if Ekind_In (Ent, E_Named_Integer, E_Named_Real)
3464 or else Is_Type (Ent)
3469 Ekind (Ent) = E_Constant
3471 Ekind (Ent) = E_In_Parameter
3473 -- This is the case where we must have Ent defined before
3474 -- U_Ent. Clearly if they are in different units this
3475 -- requirement is met since the unit containing Ent is
3476 -- already processed.
3478 if not In_Same_Source_Unit (Ent, U_Ent) then
3481 -- Otherwise location of Ent must be before the location
3482 -- of U_Ent, that's what prior defined means.
3484 elsif Sloc (Ent) < Loc_U_Ent then
3489 ("invalid address clause for initialized object &!",
3491 Error_Msg_Node_2 := U_Ent;
3493 ("\& must be defined before & (RM 13.1(22))!",
3497 elsif Nkind (Original_Node (Nod)) = N_Function_Call then
3498 Check_Expr_Constants (Original_Node (Nod));
3502 ("invalid address clause for initialized object &!",
3505 if Comes_From_Source (Ent) then
3507 ("\reference to variable& not allowed"
3508 & " (RM 13.1(22))!", Nod, Ent);
3511 ("non-static expression not allowed"
3512 & " (RM 13.1(22))!", Nod);
3516 when N_Integer_Literal =>
3518 -- If this is a rewritten unchecked conversion, in a system
3519 -- where Address is an integer type, always use the base type
3520 -- for a literal value. This is user-friendly and prevents
3521 -- order-of-elaboration issues with instances of unchecked
3524 if Nkind (Original_Node (Nod)) = N_Function_Call then
3525 Set_Etype (Nod, Base_Type (Etype (Nod)));
3528 when N_Real_Literal |
3530 N_Character_Literal =>
3534 Check_Expr_Constants (Low_Bound (Nod));
3535 Check_Expr_Constants (High_Bound (Nod));
3537 when N_Explicit_Dereference =>
3538 Check_Expr_Constants (Prefix (Nod));
3540 when N_Indexed_Component =>
3541 Check_Expr_Constants (Prefix (Nod));
3542 Check_List_Constants (Expressions (Nod));
3545 Check_Expr_Constants (Prefix (Nod));
3546 Check_Expr_Constants (Discrete_Range (Nod));
3548 when N_Selected_Component =>
3549 Check_Expr_Constants (Prefix (Nod));
3551 when N_Attribute_Reference =>
3552 if Attribute_Name (Nod) = Name_Address
3554 Attribute_Name (Nod) = Name_Access
3556 Attribute_Name (Nod) = Name_Unchecked_Access
3558 Attribute_Name (Nod) = Name_Unrestricted_Access
3560 Check_At_Constant_Address (Prefix (Nod));
3563 Check_Expr_Constants (Prefix (Nod));
3564 Check_List_Constants (Expressions (Nod));
3568 Check_List_Constants (Component_Associations (Nod));
3569 Check_List_Constants (Expressions (Nod));
3571 when N_Component_Association =>
3572 Check_Expr_Constants (Expression (Nod));
3574 when N_Extension_Aggregate =>
3575 Check_Expr_Constants (Ancestor_Part (Nod));
3576 Check_List_Constants (Component_Associations (Nod));
3577 Check_List_Constants (Expressions (Nod));
3582 when N_Binary_Op | N_Short_Circuit | N_Membership_Test =>
3583 Check_Expr_Constants (Left_Opnd (Nod));
3584 Check_Expr_Constants (Right_Opnd (Nod));
3587 Check_Expr_Constants (Right_Opnd (Nod));
3589 when N_Type_Conversion |
3590 N_Qualified_Expression |
3592 Check_Expr_Constants (Expression (Nod));
3594 when N_Unchecked_Type_Conversion =>
3595 Check_Expr_Constants (Expression (Nod));
3597 -- If this is a rewritten unchecked conversion, subtypes in
3598 -- this node are those created within the instance. To avoid
3599 -- order of elaboration issues, replace them with their base
3600 -- types. Note that address clauses can cause order of
3601 -- elaboration problems because they are elaborated by the
3602 -- back-end at the point of definition, and may mention
3603 -- entities declared in between (as long as everything is
3604 -- static). It is user-friendly to allow unchecked conversions
3607 if Nkind (Original_Node (Nod)) = N_Function_Call then
3608 Set_Etype (Expression (Nod),
3609 Base_Type (Etype (Expression (Nod))));
3610 Set_Etype (Nod, Base_Type (Etype (Nod)));
3613 when N_Function_Call =>
3614 if not Is_Pure (Entity (Name (Nod))) then
3616 ("invalid address clause for initialized object &!",
3620 ("\function & is not pure (RM 13.1(22))!",
3621 Nod, Entity (Name (Nod)));
3624 Check_List_Constants (Parameter_Associations (Nod));
3627 when N_Parameter_Association =>
3628 Check_Expr_Constants (Explicit_Actual_Parameter (Nod));
3632 ("invalid address clause for initialized object &!",
3635 ("\must be constant defined before& (RM 13.1(22))!",
3638 end Check_Expr_Constants;
3640 --------------------------
3641 -- Check_List_Constants --
3642 --------------------------
3644 procedure Check_List_Constants (Lst : List_Id) is
3648 if Present (Lst) then
3649 Nod1 := First (Lst);
3650 while Present (Nod1) loop
3651 Check_Expr_Constants (Nod1);
3655 end Check_List_Constants;
3657 -- Start of processing for Check_Constant_Address_Clause
3660 -- If rep_clauses are to be ignored, no need for legality checks. In
3661 -- particular, no need to pester user about rep clauses that violate
3662 -- the rule on constant addresses, given that these clauses will be
3663 -- removed by Freeze before they reach the back end.
3665 if not Ignore_Rep_Clauses then
3666 Check_Expr_Constants (Expr);
3668 end Check_Constant_Address_Clause;
3670 ----------------------------------------
3671 -- Check_Record_Representation_Clause --
3672 ----------------------------------------
3674 procedure Check_Record_Representation_Clause (N : Node_Id) is
3675 Loc : constant Source_Ptr := Sloc (N);
3676 Ident : constant Node_Id := Identifier (N);
3677 Rectype : Entity_Id;
3682 Hbit : Uint := Uint_0;
3686 Max_Bit_So_Far : Uint;
3687 -- Records the maximum bit position so far. If all field positions
3688 -- are monotonically increasing, then we can skip the circuit for
3689 -- checking for overlap, since no overlap is possible.
3691 Tagged_Parent : Entity_Id := Empty;
3692 -- This is set in the case of a derived tagged type for which we have
3693 -- Is_Fully_Repped_Tagged_Type True (indicating that all components are
3694 -- positioned by record representation clauses). In this case we must
3695 -- check for overlap between components of this tagged type, and the
3696 -- components of its parent. Tagged_Parent will point to this parent
3697 -- type. For all other cases Tagged_Parent is left set to Empty.
3699 Parent_Last_Bit : Uint;
3700 -- Relevant only if Tagged_Parent is set, Parent_Last_Bit indicates the
3701 -- last bit position for any field in the parent type. We only need to
3702 -- check overlap for fields starting below this point.
3704 Overlap_Check_Required : Boolean;
3705 -- Used to keep track of whether or not an overlap check is required
3707 Overlap_Detected : Boolean := False;
3708 -- Set True if an overlap is detected
3710 Ccount : Natural := 0;
3711 -- Number of component clauses in record rep clause
3713 procedure Check_Component_Overlap (C1_Ent, C2_Ent : Entity_Id);
3714 -- Given two entities for record components or discriminants, checks
3715 -- if they have overlapping component clauses and issues errors if so.
3717 procedure Find_Component;
3718 -- Finds component entity corresponding to current component clause (in
3719 -- CC), and sets Comp to the entity, and Fbit/Lbit to the zero origin
3720 -- start/stop bits for the field. If there is no matching component or
3721 -- if the matching component does not have a component clause, then
3722 -- that's an error and Comp is set to Empty, but no error message is
3723 -- issued, since the message was already given. Comp is also set to
3724 -- Empty if the current "component clause" is in fact a pragma.
3726 -----------------------------
3727 -- Check_Component_Overlap --
3728 -----------------------------
3730 procedure Check_Component_Overlap (C1_Ent, C2_Ent : Entity_Id) is
3731 CC1 : constant Node_Id := Component_Clause (C1_Ent);
3732 CC2 : constant Node_Id := Component_Clause (C2_Ent);
3735 if Present (CC1) and then Present (CC2) then
3737 -- Exclude odd case where we have two tag fields in the same
3738 -- record, both at location zero. This seems a bit strange, but
3739 -- it seems to happen in some circumstances, perhaps on an error.
3741 if Chars (C1_Ent) = Name_uTag
3743 Chars (C2_Ent) = Name_uTag
3748 -- Here we check if the two fields overlap
3751 S1 : constant Uint := Component_Bit_Offset (C1_Ent);
3752 S2 : constant Uint := Component_Bit_Offset (C2_Ent);
3753 E1 : constant Uint := S1 + Esize (C1_Ent);
3754 E2 : constant Uint := S2 + Esize (C2_Ent);
3757 if E2 <= S1 or else E1 <= S2 then
3760 Error_Msg_Node_2 := Component_Name (CC2);
3761 Error_Msg_Sloc := Sloc (Error_Msg_Node_2);
3762 Error_Msg_Node_1 := Component_Name (CC1);
3764 ("component& overlaps & #", Component_Name (CC1));
3765 Overlap_Detected := True;
3769 end Check_Component_Overlap;
3771 --------------------
3772 -- Find_Component --
3773 --------------------
3775 procedure Find_Component is
3777 procedure Search_Component (R : Entity_Id);
3778 -- Search components of R for a match. If found, Comp is set.
3780 ----------------------
3781 -- Search_Component --
3782 ----------------------
3784 procedure Search_Component (R : Entity_Id) is
3786 Comp := First_Component_Or_Discriminant (R);
3787 while Present (Comp) loop
3789 -- Ignore error of attribute name for component name (we
3790 -- already gave an error message for this, so no need to
3793 if Nkind (Component_Name (CC)) = N_Attribute_Reference then
3796 exit when Chars (Comp) = Chars (Component_Name (CC));
3799 Next_Component_Or_Discriminant (Comp);
3801 end Search_Component;
3803 -- Start of processing for Find_Component
3806 -- Return with Comp set to Empty if we have a pragma
3808 if Nkind (CC) = N_Pragma then
3813 -- Search current record for matching component
3815 Search_Component (Rectype);
3817 -- If not found, maybe component of base type that is absent from
3818 -- statically constrained first subtype.
3821 Search_Component (Base_Type (Rectype));
3824 -- If no component, or the component does not reference the component
3825 -- clause in question, then there was some previous error for which
3826 -- we already gave a message, so just return with Comp Empty.
3829 or else Component_Clause (Comp) /= CC
3833 -- Normal case where we have a component clause
3836 Fbit := Component_Bit_Offset (Comp);
3837 Lbit := Fbit + Esize (Comp) - 1;
3841 -- Start of processing for Check_Record_Representation_Clause
3845 Rectype := Entity (Ident);
3847 if Rectype = Any_Type then
3850 Rectype := Underlying_Type (Rectype);
3853 -- See if we have a fully repped derived tagged type
3856 PS : constant Entity_Id := Parent_Subtype (Rectype);
3859 if Present (PS) and then Is_Fully_Repped_Tagged_Type (PS) then
3860 Tagged_Parent := PS;
3862 -- Find maximum bit of any component of the parent type
3864 Parent_Last_Bit := UI_From_Int (System_Address_Size - 1);
3865 Pcomp := First_Entity (Tagged_Parent);
3866 while Present (Pcomp) loop
3867 if Ekind_In (Pcomp, E_Discriminant, E_Component) then
3868 if Component_Bit_Offset (Pcomp) /= No_Uint
3869 and then Known_Static_Esize (Pcomp)
3874 Component_Bit_Offset (Pcomp) + Esize (Pcomp) - 1);
3877 Next_Entity (Pcomp);
3883 -- All done if no component clauses
3885 CC := First (Component_Clauses (N));
3891 -- If a tag is present, then create a component clause that places it
3892 -- at the start of the record (otherwise gigi may place it after other
3893 -- fields that have rep clauses).
3895 Fent := First_Entity (Rectype);
3897 if Nkind (Fent) = N_Defining_Identifier
3898 and then Chars (Fent) = Name_uTag
3900 Set_Component_Bit_Offset (Fent, Uint_0);
3901 Set_Normalized_Position (Fent, Uint_0);
3902 Set_Normalized_First_Bit (Fent, Uint_0);
3903 Set_Normalized_Position_Max (Fent, Uint_0);
3904 Init_Esize (Fent, System_Address_Size);
3906 Set_Component_Clause (Fent,
3907 Make_Component_Clause (Loc,
3909 Make_Identifier (Loc,
3910 Chars => Name_uTag),
3913 Make_Integer_Literal (Loc,
3917 Make_Integer_Literal (Loc,
3921 Make_Integer_Literal (Loc,
3922 UI_From_Int (System_Address_Size))));
3924 Ccount := Ccount + 1;
3927 Max_Bit_So_Far := Uint_Minus_1;
3928 Overlap_Check_Required := False;
3930 -- Process the component clauses
3932 while Present (CC) loop
3935 if Present (Comp) then
3936 Ccount := Ccount + 1;
3938 -- We need a full overlap check if record positions non-monotonic
3940 if Fbit <= Max_Bit_So_Far then
3941 Overlap_Check_Required := True;
3944 Max_Bit_So_Far := Lbit;
3946 -- Check bit position out of range of specified size
3948 if Has_Size_Clause (Rectype)
3949 and then Esize (Rectype) <= Lbit
3952 ("bit number out of range of specified size",
3955 -- Check for overlap with tag field
3958 if Is_Tagged_Type (Rectype)
3959 and then Fbit < System_Address_Size
3962 ("component overlaps tag field of&",
3963 Component_Name (CC), Rectype);
3964 Overlap_Detected := True;
3972 -- Check parent overlap if component might overlap parent field
3974 if Present (Tagged_Parent)
3975 and then Fbit <= Parent_Last_Bit
3977 Pcomp := First_Component_Or_Discriminant (Tagged_Parent);
3978 while Present (Pcomp) loop
3979 if not Is_Tag (Pcomp)
3980 and then Chars (Pcomp) /= Name_uParent
3982 Check_Component_Overlap (Comp, Pcomp);
3985 Next_Component_Or_Discriminant (Pcomp);
3993 -- Now that we have processed all the component clauses, check for
3994 -- overlap. We have to leave this till last, since the components can
3995 -- appear in any arbitrary order in the representation clause.
3997 -- We do not need this check if all specified ranges were monotonic,
3998 -- as recorded by Overlap_Check_Required being False at this stage.
4000 -- This first section checks if there are any overlapping entries at
4001 -- all. It does this by sorting all entries and then seeing if there are
4002 -- any overlaps. If there are none, then that is decisive, but if there
4003 -- are overlaps, they may still be OK (they may result from fields in
4004 -- different variants).
4006 if Overlap_Check_Required then
4007 Overlap_Check1 : declare
4009 OC_Fbit : array (0 .. Ccount) of Uint;
4010 -- First-bit values for component clauses, the value is the offset
4011 -- of the first bit of the field from start of record. The zero
4012 -- entry is for use in sorting.
4014 OC_Lbit : array (0 .. Ccount) of Uint;
4015 -- Last-bit values for component clauses, the value is the offset
4016 -- of the last bit of the field from start of record. The zero
4017 -- entry is for use in sorting.
4019 OC_Count : Natural := 0;
4020 -- Count of entries in OC_Fbit and OC_Lbit
4022 function OC_Lt (Op1, Op2 : Natural) return Boolean;
4023 -- Compare routine for Sort
4025 procedure OC_Move (From : Natural; To : Natural);
4026 -- Move routine for Sort
4028 package Sorting is new GNAT.Heap_Sort_G (OC_Move, OC_Lt);
4034 function OC_Lt (Op1, Op2 : Natural) return Boolean is
4036 return OC_Fbit (Op1) < OC_Fbit (Op2);
4043 procedure OC_Move (From : Natural; To : Natural) is
4045 OC_Fbit (To) := OC_Fbit (From);
4046 OC_Lbit (To) := OC_Lbit (From);
4049 -- Start of processing for Overlap_Check
4052 CC := First (Component_Clauses (N));
4053 while Present (CC) loop
4055 -- Exclude component clause already marked in error
4057 if not Error_Posted (CC) then
4060 if Present (Comp) then
4061 OC_Count := OC_Count + 1;
4062 OC_Fbit (OC_Count) := Fbit;
4063 OC_Lbit (OC_Count) := Lbit;
4070 Sorting.Sort (OC_Count);
4072 Overlap_Check_Required := False;
4073 for J in 1 .. OC_Count - 1 loop
4074 if OC_Lbit (J) >= OC_Fbit (J + 1) then
4075 Overlap_Check_Required := True;
4082 -- If Overlap_Check_Required is still True, then we have to do the full
4083 -- scale overlap check, since we have at least two fields that do
4084 -- overlap, and we need to know if that is OK since they are in
4085 -- different variant, or whether we have a definite problem.
4087 if Overlap_Check_Required then
4088 Overlap_Check2 : declare
4089 C1_Ent, C2_Ent : Entity_Id;
4090 -- Entities of components being checked for overlap
4093 -- Component_List node whose Component_Items are being checked
4096 -- Component declaration for component being checked
4099 C1_Ent := First_Entity (Base_Type (Rectype));
4101 -- Loop through all components in record. For each component check
4102 -- for overlap with any of the preceding elements on the component
4103 -- list containing the component and also, if the component is in
4104 -- a variant, check against components outside the case structure.
4105 -- This latter test is repeated recursively up the variant tree.
4107 Main_Component_Loop : while Present (C1_Ent) loop
4108 if not Ekind_In (C1_Ent, E_Component, E_Discriminant) then
4109 goto Continue_Main_Component_Loop;
4112 -- Skip overlap check if entity has no declaration node. This
4113 -- happens with discriminants in constrained derived types.
4114 -- Possibly we are missing some checks as a result, but that
4115 -- does not seem terribly serious.
4117 if No (Declaration_Node (C1_Ent)) then
4118 goto Continue_Main_Component_Loop;
4121 Clist := Parent (List_Containing (Declaration_Node (C1_Ent)));
4123 -- Loop through component lists that need checking. Check the
4124 -- current component list and all lists in variants above us.
4126 Component_List_Loop : loop
4128 -- If derived type definition, go to full declaration
4129 -- If at outer level, check discriminants if there are any.
4131 if Nkind (Clist) = N_Derived_Type_Definition then
4132 Clist := Parent (Clist);
4135 -- Outer level of record definition, check discriminants
4137 if Nkind_In (Clist, N_Full_Type_Declaration,
4138 N_Private_Type_Declaration)
4140 if Has_Discriminants (Defining_Identifier (Clist)) then
4142 First_Discriminant (Defining_Identifier (Clist));
4143 while Present (C2_Ent) loop
4144 exit when C1_Ent = C2_Ent;
4145 Check_Component_Overlap (C1_Ent, C2_Ent);
4146 Next_Discriminant (C2_Ent);
4150 -- Record extension case
4152 elsif Nkind (Clist) = N_Derived_Type_Definition then
4155 -- Otherwise check one component list
4158 Citem := First (Component_Items (Clist));
4159 while Present (Citem) loop
4160 if Nkind (Citem) = N_Component_Declaration then
4161 C2_Ent := Defining_Identifier (Citem);
4162 exit when C1_Ent = C2_Ent;
4163 Check_Component_Overlap (C1_Ent, C2_Ent);
4170 -- Check for variants above us (the parent of the Clist can
4171 -- be a variant, in which case its parent is a variant part,
4172 -- and the parent of the variant part is a component list
4173 -- whose components must all be checked against the current
4174 -- component for overlap).
4176 if Nkind (Parent (Clist)) = N_Variant then
4177 Clist := Parent (Parent (Parent (Clist)));
4179 -- Check for possible discriminant part in record, this
4180 -- is treated essentially as another level in the
4181 -- recursion. For this case the parent of the component
4182 -- list is the record definition, and its parent is the
4183 -- full type declaration containing the discriminant
4186 elsif Nkind (Parent (Clist)) = N_Record_Definition then
4187 Clist := Parent (Parent ((Clist)));
4189 -- If neither of these two cases, we are at the top of
4193 exit Component_List_Loop;
4195 end loop Component_List_Loop;
4197 <<Continue_Main_Component_Loop>>
4198 Next_Entity (C1_Ent);
4200 end loop Main_Component_Loop;
4204 -- The following circuit deals with warning on record holes (gaps). We
4205 -- skip this check if overlap was detected, since it makes sense for the
4206 -- programmer to fix this illegality before worrying about warnings.
4208 if not Overlap_Detected and Warn_On_Record_Holes then
4209 Record_Hole_Check : declare
4210 Decl : constant Node_Id := Declaration_Node (Base_Type (Rectype));
4211 -- Full declaration of record type
4213 procedure Check_Component_List
4217 -- Check component list CL for holes. The starting bit should be
4218 -- Sbit. which is zero for the main record component list and set
4219 -- appropriately for recursive calls for variants. DS is set to
4220 -- a list of discriminant specifications to be included in the
4221 -- consideration of components. It is No_List if none to consider.
4223 --------------------------
4224 -- Check_Component_List --
4225 --------------------------
4227 procedure Check_Component_List
4235 Compl := Integer (List_Length (Component_Items (CL)));
4237 if DS /= No_List then
4238 Compl := Compl + Integer (List_Length (DS));
4242 Comps : array (Natural range 0 .. Compl) of Entity_Id;
4243 -- Gather components (zero entry is for sort routine)
4245 Ncomps : Natural := 0;
4246 -- Number of entries stored in Comps (starting at Comps (1))
4249 -- One component item or discriminant specification
4252 -- Starting bit for next component
4260 function Lt (Op1, Op2 : Natural) return Boolean;
4261 -- Compare routine for Sort
4263 procedure Move (From : Natural; To : Natural);
4264 -- Move routine for Sort
4266 package Sorting is new GNAT.Heap_Sort_G (Move, Lt);
4272 function Lt (Op1, Op2 : Natural) return Boolean is
4274 return Component_Bit_Offset (Comps (Op1))
4276 Component_Bit_Offset (Comps (Op2));
4283 procedure Move (From : Natural; To : Natural) is
4285 Comps (To) := Comps (From);
4289 -- Gather discriminants into Comp
4291 if DS /= No_List then
4292 Citem := First (DS);
4293 while Present (Citem) loop
4294 if Nkind (Citem) = N_Discriminant_Specification then
4296 Ent : constant Entity_Id :=
4297 Defining_Identifier (Citem);
4299 if Ekind (Ent) = E_Discriminant then
4300 Ncomps := Ncomps + 1;
4301 Comps (Ncomps) := Ent;
4310 -- Gather component entities into Comp
4312 Citem := First (Component_Items (CL));
4313 while Present (Citem) loop
4314 if Nkind (Citem) = N_Component_Declaration then
4315 Ncomps := Ncomps + 1;
4316 Comps (Ncomps) := Defining_Identifier (Citem);
4322 -- Now sort the component entities based on the first bit.
4323 -- Note we already know there are no overlapping components.
4325 Sorting.Sort (Ncomps);
4327 -- Loop through entries checking for holes
4330 for J in 1 .. Ncomps loop
4332 Error_Msg_Uint_1 := Component_Bit_Offset (CEnt) - Nbit;
4334 if Error_Msg_Uint_1 > 0 then
4336 ("?^-bit gap before component&",
4337 Component_Name (Component_Clause (CEnt)), CEnt);
4340 Nbit := Component_Bit_Offset (CEnt) + Esize (CEnt);
4343 -- Process variant parts recursively if present
4345 if Present (Variant_Part (CL)) then
4346 Variant := First (Variants (Variant_Part (CL)));
4347 while Present (Variant) loop
4348 Check_Component_List
4349 (Component_List (Variant), Nbit, No_List);
4354 end Check_Component_List;
4356 -- Start of processing for Record_Hole_Check
4363 if Is_Tagged_Type (Rectype) then
4364 Sbit := UI_From_Int (System_Address_Size);
4369 if Nkind (Decl) = N_Full_Type_Declaration
4370 and then Nkind (Type_Definition (Decl)) = N_Record_Definition
4372 Check_Component_List
4373 (Component_List (Type_Definition (Decl)),
4375 Discriminant_Specifications (Decl));
4378 end Record_Hole_Check;
4381 -- For records that have component clauses for all components, and whose
4382 -- size is less than or equal to 32, we need to know the size in the
4383 -- front end to activate possible packed array processing where the
4384 -- component type is a record.
4386 -- At this stage Hbit + 1 represents the first unused bit from all the
4387 -- component clauses processed, so if the component clauses are
4388 -- complete, then this is the length of the record.
4390 -- For records longer than System.Storage_Unit, and for those where not
4391 -- all components have component clauses, the back end determines the
4392 -- length (it may for example be appropriate to round up the size
4393 -- to some convenient boundary, based on alignment considerations, etc).
4395 if Unknown_RM_Size (Rectype) and then Hbit + 1 <= 32 then
4397 -- Nothing to do if at least one component has no component clause
4399 Comp := First_Component_Or_Discriminant (Rectype);
4400 while Present (Comp) loop
4401 exit when No (Component_Clause (Comp));
4402 Next_Component_Or_Discriminant (Comp);
4405 -- If we fall out of loop, all components have component clauses
4406 -- and so we can set the size to the maximum value.
4409 Set_RM_Size (Rectype, Hbit + 1);
4412 end Check_Record_Representation_Clause;
4418 procedure Check_Size
4422 Biased : out Boolean)
4424 UT : constant Entity_Id := Underlying_Type (T);
4430 -- Dismiss cases for generic types or types with previous errors
4433 or else UT = Any_Type
4434 or else Is_Generic_Type (UT)
4435 or else Is_Generic_Type (Root_Type (UT))
4439 -- Check case of bit packed array
4441 elsif Is_Array_Type (UT)
4442 and then Known_Static_Component_Size (UT)
4443 and then Is_Bit_Packed_Array (UT)
4451 Asiz := Component_Size (UT);
4452 Indx := First_Index (UT);
4454 Ityp := Etype (Indx);
4456 -- If non-static bound, then we are not in the business of
4457 -- trying to check the length, and indeed an error will be
4458 -- issued elsewhere, since sizes of non-static array types
4459 -- cannot be set implicitly or explicitly.
4461 if not Is_Static_Subtype (Ityp) then
4465 -- Otherwise accumulate next dimension
4467 Asiz := Asiz * (Expr_Value (Type_High_Bound (Ityp)) -
4468 Expr_Value (Type_Low_Bound (Ityp)) +
4472 exit when No (Indx);
4478 Error_Msg_Uint_1 := Asiz;
4480 ("size for& too small, minimum allowed is ^", N, T);
4481 Set_Esize (T, Asiz);
4482 Set_RM_Size (T, Asiz);
4486 -- All other composite types are ignored
4488 elsif Is_Composite_Type (UT) then
4491 -- For fixed-point types, don't check minimum if type is not frozen,
4492 -- since we don't know all the characteristics of the type that can
4493 -- affect the size (e.g. a specified small) till freeze time.
4495 elsif Is_Fixed_Point_Type (UT)
4496 and then not Is_Frozen (UT)
4500 -- Cases for which a minimum check is required
4503 -- Ignore if specified size is correct for the type
4505 if Known_Esize (UT) and then Siz = Esize (UT) then
4509 -- Otherwise get minimum size
4511 M := UI_From_Int (Minimum_Size (UT));
4515 -- Size is less than minimum size, but one possibility remains
4516 -- that we can manage with the new size if we bias the type.
4518 M := UI_From_Int (Minimum_Size (UT, Biased => True));
4521 Error_Msg_Uint_1 := M;
4523 ("size for& too small, minimum allowed is ^", N, T);
4533 -------------------------
4534 -- Get_Alignment_Value --
4535 -------------------------
4537 function Get_Alignment_Value (Expr : Node_Id) return Uint is
4538 Align : constant Uint := Static_Integer (Expr);
4541 if Align = No_Uint then
4544 elsif Align <= 0 then
4545 Error_Msg_N ("alignment value must be positive", Expr);
4549 for J in Int range 0 .. 64 loop
4551 M : constant Uint := Uint_2 ** J;
4554 exit when M = Align;
4558 ("alignment value must be power of 2", Expr);
4566 end Get_Alignment_Value;
4572 procedure Initialize is
4574 Address_Clause_Checks.Init;
4575 Independence_Checks.Init;
4576 Unchecked_Conversions.Init;
4579 -------------------------
4580 -- Is_Operational_Item --
4581 -------------------------
4583 function Is_Operational_Item (N : Node_Id) return Boolean is
4585 if Nkind (N) /= N_Attribute_Definition_Clause then
4589 Id : constant Attribute_Id := Get_Attribute_Id (Chars (N));
4591 return Id = Attribute_Input
4592 or else Id = Attribute_Output
4593 or else Id = Attribute_Read
4594 or else Id = Attribute_Write
4595 or else Id = Attribute_External_Tag;
4598 end Is_Operational_Item;
4604 function Minimum_Size
4606 Biased : Boolean := False) return Nat
4608 Lo : Uint := No_Uint;
4609 Hi : Uint := No_Uint;
4610 LoR : Ureal := No_Ureal;
4611 HiR : Ureal := No_Ureal;
4612 LoSet : Boolean := False;
4613 HiSet : Boolean := False;
4617 R_Typ : constant Entity_Id := Root_Type (T);
4620 -- If bad type, return 0
4622 if T = Any_Type then
4625 -- For generic types, just return zero. There cannot be any legitimate
4626 -- need to know such a size, but this routine may be called with a
4627 -- generic type as part of normal processing.
4629 elsif Is_Generic_Type (R_Typ)
4630 or else R_Typ = Any_Type
4634 -- Access types. Normally an access type cannot have a size smaller
4635 -- than the size of System.Address. The exception is on VMS, where
4636 -- we have short and long addresses, and it is possible for an access
4637 -- type to have a short address size (and thus be less than the size
4638 -- of System.Address itself). We simply skip the check for VMS, and
4639 -- leave it to the back end to do the check.
4641 elsif Is_Access_Type (T) then
4642 if OpenVMS_On_Target then
4645 return System_Address_Size;
4648 -- Floating-point types
4650 elsif Is_Floating_Point_Type (T) then
4651 return UI_To_Int (Esize (R_Typ));
4655 elsif Is_Discrete_Type (T) then
4657 -- The following loop is looking for the nearest compile time known
4658 -- bounds following the ancestor subtype chain. The idea is to find
4659 -- the most restrictive known bounds information.
4663 if Ancest = Any_Type or else Etype (Ancest) = Any_Type then
4668 if Compile_Time_Known_Value (Type_Low_Bound (Ancest)) then
4669 Lo := Expr_Rep_Value (Type_Low_Bound (Ancest));
4676 if Compile_Time_Known_Value (Type_High_Bound (Ancest)) then
4677 Hi := Expr_Rep_Value (Type_High_Bound (Ancest));
4683 Ancest := Ancestor_Subtype (Ancest);
4686 Ancest := Base_Type (T);
4688 if Is_Generic_Type (Ancest) then
4694 -- Fixed-point types. We can't simply use Expr_Value to get the
4695 -- Corresponding_Integer_Value values of the bounds, since these do not
4696 -- get set till the type is frozen, and this routine can be called
4697 -- before the type is frozen. Similarly the test for bounds being static
4698 -- needs to include the case where we have unanalyzed real literals for
4701 elsif Is_Fixed_Point_Type (T) then
4703 -- The following loop is looking for the nearest compile time known
4704 -- bounds following the ancestor subtype chain. The idea is to find
4705 -- the most restrictive known bounds information.
4709 if Ancest = Any_Type or else Etype (Ancest) = Any_Type then
4713 -- Note: In the following two tests for LoSet and HiSet, it may
4714 -- seem redundant to test for N_Real_Literal here since normally
4715 -- one would assume that the test for the value being known at
4716 -- compile time includes this case. However, there is a glitch.
4717 -- If the real literal comes from folding a non-static expression,
4718 -- then we don't consider any non- static expression to be known
4719 -- at compile time if we are in configurable run time mode (needed
4720 -- in some cases to give a clearer definition of what is and what
4721 -- is not accepted). So the test is indeed needed. Without it, we
4722 -- would set neither Lo_Set nor Hi_Set and get an infinite loop.
4725 if Nkind (Type_Low_Bound (Ancest)) = N_Real_Literal
4726 or else Compile_Time_Known_Value (Type_Low_Bound (Ancest))
4728 LoR := Expr_Value_R (Type_Low_Bound (Ancest));
4735 if Nkind (Type_High_Bound (Ancest)) = N_Real_Literal
4736 or else Compile_Time_Known_Value (Type_High_Bound (Ancest))
4738 HiR := Expr_Value_R (Type_High_Bound (Ancest));
4744 Ancest := Ancestor_Subtype (Ancest);
4747 Ancest := Base_Type (T);
4749 if Is_Generic_Type (Ancest) then
4755 Lo := UR_To_Uint (LoR / Small_Value (T));
4756 Hi := UR_To_Uint (HiR / Small_Value (T));
4758 -- No other types allowed
4761 raise Program_Error;
4764 -- Fall through with Hi and Lo set. Deal with biased case
4767 and then not Is_Fixed_Point_Type (T)
4768 and then not (Is_Enumeration_Type (T)
4769 and then Has_Non_Standard_Rep (T)))
4770 or else Has_Biased_Representation (T)
4776 -- Signed case. Note that we consider types like range 1 .. -1 to be
4777 -- signed for the purpose of computing the size, since the bounds have
4778 -- to be accommodated in the base type.
4780 if Lo < 0 or else Hi < 0 then
4784 -- S = size, B = 2 ** (size - 1) (can accommodate -B .. +(B - 1))
4785 -- Note that we accommodate the case where the bounds cross. This
4786 -- can happen either because of the way the bounds are declared
4787 -- or because of the algorithm in Freeze_Fixed_Point_Type.
4801 -- If both bounds are positive, make sure that both are represen-
4802 -- table in the case where the bounds are crossed. This can happen
4803 -- either because of the way the bounds are declared, or because of
4804 -- the algorithm in Freeze_Fixed_Point_Type.
4810 -- S = size, (can accommodate 0 .. (2**size - 1))
4813 while Hi >= Uint_2 ** S loop
4821 ---------------------------
4822 -- New_Stream_Subprogram --
4823 ---------------------------
4825 procedure New_Stream_Subprogram
4829 Nam : TSS_Name_Type)
4831 Loc : constant Source_Ptr := Sloc (N);
4832 Sname : constant Name_Id := Make_TSS_Name (Base_Type (Ent), Nam);
4833 Subp_Id : Entity_Id;
4834 Subp_Decl : Node_Id;
4838 Defer_Declaration : constant Boolean :=
4839 Is_Tagged_Type (Ent) or else Is_Private_Type (Ent);
4840 -- For a tagged type, there is a declaration for each stream attribute
4841 -- at the freeze point, and we must generate only a completion of this
4842 -- declaration. We do the same for private types, because the full view
4843 -- might be tagged. Otherwise we generate a declaration at the point of
4844 -- the attribute definition clause.
4846 function Build_Spec return Node_Id;
4847 -- Used for declaration and renaming declaration, so that this is
4848 -- treated as a renaming_as_body.
4854 function Build_Spec return Node_Id is
4855 Out_P : constant Boolean := (Nam = TSS_Stream_Read);
4858 T_Ref : constant Node_Id := New_Reference_To (Etyp, Loc);
4861 Subp_Id := Make_Defining_Identifier (Loc, Sname);
4863 -- S : access Root_Stream_Type'Class
4865 Formals := New_List (
4866 Make_Parameter_Specification (Loc,
4867 Defining_Identifier =>
4868 Make_Defining_Identifier (Loc, Name_S),
4870 Make_Access_Definition (Loc,
4873 Designated_Type (Etype (F)), Loc))));
4875 if Nam = TSS_Stream_Input then
4876 Spec := Make_Function_Specification (Loc,
4877 Defining_Unit_Name => Subp_Id,
4878 Parameter_Specifications => Formals,
4879 Result_Definition => T_Ref);
4884 Make_Parameter_Specification (Loc,
4885 Defining_Identifier => Make_Defining_Identifier (Loc, Name_V),
4886 Out_Present => Out_P,
4887 Parameter_Type => T_Ref));
4890 Make_Procedure_Specification (Loc,
4891 Defining_Unit_Name => Subp_Id,
4892 Parameter_Specifications => Formals);
4898 -- Start of processing for New_Stream_Subprogram
4901 F := First_Formal (Subp);
4903 if Ekind (Subp) = E_Procedure then
4904 Etyp := Etype (Next_Formal (F));
4906 Etyp := Etype (Subp);
4909 -- Prepare subprogram declaration and insert it as an action on the
4910 -- clause node. The visibility for this entity is used to test for
4911 -- visibility of the attribute definition clause (in the sense of
4912 -- 8.3(23) as amended by AI-195).
4914 if not Defer_Declaration then
4916 Make_Subprogram_Declaration (Loc,
4917 Specification => Build_Spec);
4919 -- For a tagged type, there is always a visible declaration for each
4920 -- stream TSS (it is a predefined primitive operation), and the
4921 -- completion of this declaration occurs at the freeze point, which is
4922 -- not always visible at places where the attribute definition clause is
4923 -- visible. So, we create a dummy entity here for the purpose of
4924 -- tracking the visibility of the attribute definition clause itself.
4928 Make_Defining_Identifier (Loc,
4929 Chars => New_External_Name (Sname, 'V'));
4931 Make_Object_Declaration (Loc,
4932 Defining_Identifier => Subp_Id,
4933 Object_Definition => New_Occurrence_Of (Standard_Boolean, Loc));
4936 Insert_Action (N, Subp_Decl);
4937 Set_Entity (N, Subp_Id);
4940 Make_Subprogram_Renaming_Declaration (Loc,
4941 Specification => Build_Spec,
4942 Name => New_Reference_To (Subp, Loc));
4944 if Defer_Declaration then
4945 Set_TSS (Base_Type (Ent), Subp_Id);
4947 Insert_Action (N, Subp_Decl);
4948 Copy_TSS (Subp_Id, Base_Type (Ent));
4950 end New_Stream_Subprogram;
4952 ------------------------
4953 -- Rep_Item_Too_Early --
4954 ------------------------
4956 function Rep_Item_Too_Early (T : Entity_Id; N : Node_Id) return Boolean is
4958 -- Cannot apply non-operational rep items to generic types
4960 if Is_Operational_Item (N) then
4964 and then Is_Generic_Type (Root_Type (T))
4966 Error_Msg_N ("representation item not allowed for generic type", N);
4970 -- Otherwise check for incomplete type
4972 if Is_Incomplete_Or_Private_Type (T)
4973 and then No (Underlying_Type (T))
4976 ("representation item must be after full type declaration", N);
4979 -- If the type has incomplete components, a representation clause is
4980 -- illegal but stream attributes and Convention pragmas are correct.
4982 elsif Has_Private_Component (T) then
4983 if Nkind (N) = N_Pragma then
4987 ("representation item must appear after type is fully defined",
4994 end Rep_Item_Too_Early;
4996 -----------------------
4997 -- Rep_Item_Too_Late --
4998 -----------------------
5000 function Rep_Item_Too_Late
5003 FOnly : Boolean := False) return Boolean
5006 Parent_Type : Entity_Id;
5009 -- Output the too late message. Note that this is not considered a
5010 -- serious error, since the effect is simply that we ignore the
5011 -- representation clause in this case.
5017 procedure Too_Late is
5019 Error_Msg_N ("|representation item appears too late!", N);
5022 -- Start of processing for Rep_Item_Too_Late
5025 -- If this is from an aspect that was delayed till the freeze point,
5026 -- then we skip this check entirely, since it is not required and
5027 -- furthermore can generate false errors. Also we don't need to chain
5028 -- the item into the rep item chain in that case, it is already there!
5030 if Nkind_In (N, N_Attribute_Definition_Clause, N_Pragma)
5031 and then Is_Delayed_Aspect (N)
5036 -- First make sure entity is not frozen (RM 13.1(9)). Exclude imported
5037 -- types, which may be frozen if they appear in a representation clause
5038 -- for a local type.
5041 and then not From_With_Type (T)
5044 S := First_Subtype (T);
5046 if Present (Freeze_Node (S)) then
5048 ("?no more representation items for }", Freeze_Node (S), S);
5053 -- Check for case of non-tagged derived type whose parent either has
5054 -- primitive operations, or is a by reference type (RM 13.1(10)).
5058 and then Is_Derived_Type (T)
5059 and then not Is_Tagged_Type (T)
5061 Parent_Type := Etype (Base_Type (T));
5063 if Has_Primitive_Operations (Parent_Type) then
5066 ("primitive operations already defined for&!", N, Parent_Type);
5069 elsif Is_By_Reference_Type (Parent_Type) then
5072 ("parent type & is a by reference type!", N, Parent_Type);
5077 -- No error, link item into head of chain of rep items for the entity,
5078 -- but avoid chaining if we have an overloadable entity, and the pragma
5079 -- is one that can apply to multiple overloaded entities.
5081 if Is_Overloadable (T)
5082 and then Nkind (N) = N_Pragma
5085 Pname : constant Name_Id := Pragma_Name (N);
5087 if Pname = Name_Convention or else
5088 Pname = Name_Import or else
5089 Pname = Name_Export or else
5090 Pname = Name_External or else
5091 Pname = Name_Interface
5098 Record_Rep_Item (T, N);
5100 end Rep_Item_Too_Late;
5102 -------------------------
5103 -- Same_Representation --
5104 -------------------------
5106 function Same_Representation (Typ1, Typ2 : Entity_Id) return Boolean is
5107 T1 : constant Entity_Id := Underlying_Type (Typ1);
5108 T2 : constant Entity_Id := Underlying_Type (Typ2);
5111 -- A quick check, if base types are the same, then we definitely have
5112 -- the same representation, because the subtype specific representation
5113 -- attributes (Size and Alignment) do not affect representation from
5114 -- the point of view of this test.
5116 if Base_Type (T1) = Base_Type (T2) then
5119 elsif Is_Private_Type (Base_Type (T2))
5120 and then Base_Type (T1) = Full_View (Base_Type (T2))
5125 -- Tagged types never have differing representations
5127 if Is_Tagged_Type (T1) then
5131 -- Representations are definitely different if conventions differ
5133 if Convention (T1) /= Convention (T2) then
5137 -- Representations are different if component alignments differ
5139 if (Is_Record_Type (T1) or else Is_Array_Type (T1))
5141 (Is_Record_Type (T2) or else Is_Array_Type (T2))
5142 and then Component_Alignment (T1) /= Component_Alignment (T2)
5147 -- For arrays, the only real issue is component size. If we know the
5148 -- component size for both arrays, and it is the same, then that's
5149 -- good enough to know we don't have a change of representation.
5151 if Is_Array_Type (T1) then
5152 if Known_Component_Size (T1)
5153 and then Known_Component_Size (T2)
5154 and then Component_Size (T1) = Component_Size (T2)
5160 -- Types definitely have same representation if neither has non-standard
5161 -- representation since default representations are always consistent.
5162 -- If only one has non-standard representation, and the other does not,
5163 -- then we consider that they do not have the same representation. They
5164 -- might, but there is no way of telling early enough.
5166 if Has_Non_Standard_Rep (T1) then
5167 if not Has_Non_Standard_Rep (T2) then
5171 return not Has_Non_Standard_Rep (T2);
5174 -- Here the two types both have non-standard representation, and we need
5175 -- to determine if they have the same non-standard representation.
5177 -- For arrays, we simply need to test if the component sizes are the
5178 -- same. Pragma Pack is reflected in modified component sizes, so this
5179 -- check also deals with pragma Pack.
5181 if Is_Array_Type (T1) then
5182 return Component_Size (T1) = Component_Size (T2);
5184 -- Tagged types always have the same representation, because it is not
5185 -- possible to specify different representations for common fields.
5187 elsif Is_Tagged_Type (T1) then
5190 -- Case of record types
5192 elsif Is_Record_Type (T1) then
5194 -- Packed status must conform
5196 if Is_Packed (T1) /= Is_Packed (T2) then
5199 -- Otherwise we must check components. Typ2 maybe a constrained
5200 -- subtype with fewer components, so we compare the components
5201 -- of the base types.
5204 Record_Case : declare
5205 CD1, CD2 : Entity_Id;
5207 function Same_Rep return Boolean;
5208 -- CD1 and CD2 are either components or discriminants. This
5209 -- function tests whether the two have the same representation
5215 function Same_Rep return Boolean is
5217 if No (Component_Clause (CD1)) then
5218 return No (Component_Clause (CD2));
5222 Present (Component_Clause (CD2))
5224 Component_Bit_Offset (CD1) = Component_Bit_Offset (CD2)
5226 Esize (CD1) = Esize (CD2);
5230 -- Start of processing for Record_Case
5233 if Has_Discriminants (T1) then
5234 CD1 := First_Discriminant (T1);
5235 CD2 := First_Discriminant (T2);
5237 -- The number of discriminants may be different if the
5238 -- derived type has fewer (constrained by values). The
5239 -- invisible discriminants retain the representation of
5240 -- the original, so the discrepancy does not per se
5241 -- indicate a different representation.
5244 and then Present (CD2)
5246 if not Same_Rep then
5249 Next_Discriminant (CD1);
5250 Next_Discriminant (CD2);
5255 CD1 := First_Component (Underlying_Type (Base_Type (T1)));
5256 CD2 := First_Component (Underlying_Type (Base_Type (T2)));
5258 while Present (CD1) loop
5259 if not Same_Rep then
5262 Next_Component (CD1);
5263 Next_Component (CD2);
5271 -- For enumeration types, we must check each literal to see if the
5272 -- representation is the same. Note that we do not permit enumeration
5273 -- representation clauses for Character and Wide_Character, so these
5274 -- cases were already dealt with.
5276 elsif Is_Enumeration_Type (T1) then
5277 Enumeration_Case : declare
5281 L1 := First_Literal (T1);
5282 L2 := First_Literal (T2);
5284 while Present (L1) loop
5285 if Enumeration_Rep (L1) /= Enumeration_Rep (L2) then
5295 end Enumeration_Case;
5297 -- Any other types have the same representation for these purposes
5302 end Same_Representation;
5308 procedure Set_Biased
5312 Biased : Boolean := True)
5316 Set_Has_Biased_Representation (E);
5318 if Warn_On_Biased_Representation then
5320 ("?" & Msg & " forces biased representation for&", N, E);
5325 --------------------
5326 -- Set_Enum_Esize --
5327 --------------------
5329 procedure Set_Enum_Esize (T : Entity_Id) is
5337 -- Find the minimum standard size (8,16,32,64) that fits
5339 Lo := Enumeration_Rep (Entity (Type_Low_Bound (T)));
5340 Hi := Enumeration_Rep (Entity (Type_High_Bound (T)));
5343 if Lo >= -Uint_2**07 and then Hi < Uint_2**07 then
5344 Sz := Standard_Character_Size; -- May be > 8 on some targets
5346 elsif Lo >= -Uint_2**15 and then Hi < Uint_2**15 then
5349 elsif Lo >= -Uint_2**31 and then Hi < Uint_2**31 then
5352 else pragma Assert (Lo >= -Uint_2**63 and then Hi < Uint_2**63);
5357 if Hi < Uint_2**08 then
5358 Sz := Standard_Character_Size; -- May be > 8 on some targets
5360 elsif Hi < Uint_2**16 then
5363 elsif Hi < Uint_2**32 then
5366 else pragma Assert (Hi < Uint_2**63);
5371 -- That minimum is the proper size unless we have a foreign convention
5372 -- and the size required is 32 or less, in which case we bump the size
5373 -- up to 32. This is required for C and C++ and seems reasonable for
5374 -- all other foreign conventions.
5376 if Has_Foreign_Convention (T)
5377 and then Esize (T) < Standard_Integer_Size
5379 Init_Esize (T, Standard_Integer_Size);
5385 ------------------------------
5386 -- Validate_Address_Clauses --
5387 ------------------------------
5389 procedure Validate_Address_Clauses is
5391 for J in Address_Clause_Checks.First .. Address_Clause_Checks.Last loop
5393 ACCR : Address_Clause_Check_Record
5394 renames Address_Clause_Checks.Table (J);
5405 -- Skip processing of this entry if warning already posted
5407 if not Address_Warning_Posted (ACCR.N) then
5409 Expr := Original_Node (Expression (ACCR.N));
5413 X_Alignment := Alignment (ACCR.X);
5414 Y_Alignment := Alignment (ACCR.Y);
5416 -- Similarly obtain sizes
5418 X_Size := Esize (ACCR.X);
5419 Y_Size := Esize (ACCR.Y);
5421 -- Check for large object overlaying smaller one
5424 and then X_Size > Uint_0
5425 and then X_Size > Y_Size
5428 ("?& overlays smaller object", ACCR.N, ACCR.X);
5430 ("\?program execution may be erroneous", ACCR.N);
5431 Error_Msg_Uint_1 := X_Size;
5433 ("\?size of & is ^", ACCR.N, ACCR.X);
5434 Error_Msg_Uint_1 := Y_Size;
5436 ("\?size of & is ^", ACCR.N, ACCR.Y);
5438 -- Check for inadequate alignment, both of the base object
5439 -- and of the offset, if any.
5441 -- Note: we do not check the alignment if we gave a size
5442 -- warning, since it would likely be redundant.
5444 elsif Y_Alignment /= Uint_0
5445 and then (Y_Alignment < X_Alignment
5448 Nkind (Expr) = N_Attribute_Reference
5450 Attribute_Name (Expr) = Name_Address
5452 Has_Compatible_Alignment
5453 (ACCR.X, Prefix (Expr))
5454 /= Known_Compatible))
5457 ("?specified address for& may be inconsistent "
5461 ("\?program execution may be erroneous (RM 13.3(27))",
5463 Error_Msg_Uint_1 := X_Alignment;
5465 ("\?alignment of & is ^",
5467 Error_Msg_Uint_1 := Y_Alignment;
5469 ("\?alignment of & is ^",
5471 if Y_Alignment >= X_Alignment then
5473 ("\?but offset is not multiple of alignment",
5480 end Validate_Address_Clauses;
5482 ---------------------------
5483 -- Validate_Independence --
5484 ---------------------------
5486 procedure Validate_Independence is
5487 SU : constant Uint := UI_From_Int (System_Storage_Unit);
5495 procedure Check_Array_Type (Atyp : Entity_Id);
5496 -- Checks if the array type Atyp has independent components, and
5497 -- if not, outputs an appropriate set of error messages.
5499 procedure No_Independence;
5500 -- Output message that independence cannot be guaranteed
5502 function OK_Component (C : Entity_Id) return Boolean;
5503 -- Checks one component to see if it is independently accessible, and
5504 -- if so yields True, otherwise yields False if independent access
5505 -- cannot be guaranteed. This is a conservative routine, it only
5506 -- returns True if it knows for sure, it returns False if it knows
5507 -- there is a problem, or it cannot be sure there is no problem.
5509 procedure Reason_Bad_Component (C : Entity_Id);
5510 -- Outputs continuation message if a reason can be determined for
5511 -- the component C being bad.
5513 ----------------------
5514 -- Check_Array_Type --
5515 ----------------------
5517 procedure Check_Array_Type (Atyp : Entity_Id) is
5518 Ctyp : constant Entity_Id := Component_Type (Atyp);
5521 -- OK if no alignment clause, no pack, and no component size
5523 if not Has_Component_Size_Clause (Atyp)
5524 and then not Has_Alignment_Clause (Atyp)
5525 and then not Is_Packed (Atyp)
5530 -- Check actual component size
5532 if not Known_Component_Size (Atyp)
5533 or else not (Addressable (Component_Size (Atyp))
5534 and then Component_Size (Atyp) < 64)
5535 or else Component_Size (Atyp) mod Esize (Ctyp) /= 0
5539 -- Bad component size, check reason
5541 if Has_Component_Size_Clause (Atyp) then
5543 Get_Attribute_Definition_Clause
5544 (Atyp, Attribute_Component_Size);
5547 Error_Msg_Sloc := Sloc (P);
5548 Error_Msg_N ("\because of Component_Size clause#", N);
5553 if Is_Packed (Atyp) then
5554 P := Get_Rep_Pragma (Atyp, Name_Pack);
5557 Error_Msg_Sloc := Sloc (P);
5558 Error_Msg_N ("\because of pragma Pack#", N);
5563 -- No reason found, just return
5568 -- Array type is OK independence-wise
5571 end Check_Array_Type;
5573 ---------------------
5574 -- No_Independence --
5575 ---------------------
5577 procedure No_Independence is
5579 if Pragma_Name (N) = Name_Independent then
5581 ("independence cannot be guaranteed for&", N, E);
5584 ("independent components cannot be guaranteed for&", N, E);
5586 end No_Independence;
5592 function OK_Component (C : Entity_Id) return Boolean is
5593 Rec : constant Entity_Id := Scope (C);
5594 Ctyp : constant Entity_Id := Etype (C);
5597 -- OK if no component clause, no Pack, and no alignment clause
5599 if No (Component_Clause (C))
5600 and then not Is_Packed (Rec)
5601 and then not Has_Alignment_Clause (Rec)
5606 -- Here we look at the actual component layout. A component is
5607 -- addressable if its size is a multiple of the Esize of the
5608 -- component type, and its starting position in the record has
5609 -- appropriate alignment, and the record itself has appropriate
5610 -- alignment to guarantee the component alignment.
5612 -- Make sure sizes are static, always assume the worst for any
5613 -- cases where we cannot check static values.
5615 if not (Known_Static_Esize (C)
5616 and then Known_Static_Esize (Ctyp))
5621 -- Size of component must be addressable or greater than 64 bits
5622 -- and a multiple of bytes.
5624 if not Addressable (Esize (C))
5625 and then Esize (C) < Uint_64
5630 -- Check size is proper multiple
5632 if Esize (C) mod Esize (Ctyp) /= 0 then
5636 -- Check alignment of component is OK
5638 if not Known_Component_Bit_Offset (C)
5639 or else Component_Bit_Offset (C) < Uint_0
5640 or else Component_Bit_Offset (C) mod Esize (Ctyp) /= 0
5645 -- Check alignment of record type is OK
5647 if not Known_Alignment (Rec)
5648 or else (Alignment (Rec) * SU) mod Esize (Ctyp) /= 0
5653 -- All tests passed, component is addressable
5658 --------------------------
5659 -- Reason_Bad_Component --
5660 --------------------------
5662 procedure Reason_Bad_Component (C : Entity_Id) is
5663 Rec : constant Entity_Id := Scope (C);
5664 Ctyp : constant Entity_Id := Etype (C);
5667 -- If component clause present assume that's the problem
5669 if Present (Component_Clause (C)) then
5670 Error_Msg_Sloc := Sloc (Component_Clause (C));
5671 Error_Msg_N ("\because of Component_Clause#", N);
5675 -- If pragma Pack clause present, assume that's the problem
5677 if Is_Packed (Rec) then
5678 P := Get_Rep_Pragma (Rec, Name_Pack);
5681 Error_Msg_Sloc := Sloc (P);
5682 Error_Msg_N ("\because of pragma Pack#", N);
5687 -- See if record has bad alignment clause
5689 if Has_Alignment_Clause (Rec)
5690 and then Known_Alignment (Rec)
5691 and then (Alignment (Rec) * SU) mod Esize (Ctyp) /= 0
5693 P := Get_Attribute_Definition_Clause (Rec, Attribute_Alignment);
5696 Error_Msg_Sloc := Sloc (P);
5697 Error_Msg_N ("\because of Alignment clause#", N);
5701 -- Couldn't find a reason, so return without a message
5704 end Reason_Bad_Component;
5706 -- Start of processing for Validate_Independence
5709 for J in Independence_Checks.First .. Independence_Checks.Last loop
5710 N := Independence_Checks.Table (J).N;
5711 E := Independence_Checks.Table (J).E;
5712 IC := Pragma_Name (N) = Name_Independent_Components;
5714 -- Deal with component case
5716 if Ekind (E) = E_Discriminant or else Ekind (E) = E_Component then
5717 if not OK_Component (E) then
5719 Reason_Bad_Component (E);
5724 -- Deal with record with Independent_Components
5726 if IC and then Is_Record_Type (E) then
5727 Comp := First_Component_Or_Discriminant (E);
5728 while Present (Comp) loop
5729 if not OK_Component (Comp) then
5731 Reason_Bad_Component (Comp);
5735 Next_Component_Or_Discriminant (Comp);
5739 -- Deal with address clause case
5741 if Is_Object (E) then
5742 Addr := Address_Clause (E);
5744 if Present (Addr) then
5746 Error_Msg_Sloc := Sloc (Addr);
5747 Error_Msg_N ("\because of Address clause#", N);
5752 -- Deal with independent components for array type
5754 if IC and then Is_Array_Type (E) then
5755 Check_Array_Type (E);
5758 -- Deal with independent components for array object
5760 if IC and then Is_Object (E) and then Is_Array_Type (Etype (E)) then
5761 Check_Array_Type (Etype (E));
5766 end Validate_Independence;
5768 -----------------------------------
5769 -- Validate_Unchecked_Conversion --
5770 -----------------------------------
5772 procedure Validate_Unchecked_Conversion
5774 Act_Unit : Entity_Id)
5781 -- Obtain source and target types. Note that we call Ancestor_Subtype
5782 -- here because the processing for generic instantiation always makes
5783 -- subtypes, and we want the original frozen actual types.
5785 -- If we are dealing with private types, then do the check on their
5786 -- fully declared counterparts if the full declarations have been
5787 -- encountered (they don't have to be visible, but they must exist!)
5789 Source := Ancestor_Subtype (Etype (First_Formal (Act_Unit)));
5791 if Is_Private_Type (Source)
5792 and then Present (Underlying_Type (Source))
5794 Source := Underlying_Type (Source);
5797 Target := Ancestor_Subtype (Etype (Act_Unit));
5799 -- If either type is generic, the instantiation happens within a generic
5800 -- unit, and there is nothing to check. The proper check
5801 -- will happen when the enclosing generic is instantiated.
5803 if Is_Generic_Type (Source) or else Is_Generic_Type (Target) then
5807 if Is_Private_Type (Target)
5808 and then Present (Underlying_Type (Target))
5810 Target := Underlying_Type (Target);
5813 -- Source may be unconstrained array, but not target
5815 if Is_Array_Type (Target)
5816 and then not Is_Constrained (Target)
5819 ("unchecked conversion to unconstrained array not allowed", N);
5823 -- Warn if conversion between two different convention pointers
5825 if Is_Access_Type (Target)
5826 and then Is_Access_Type (Source)
5827 and then Convention (Target) /= Convention (Source)
5828 and then Warn_On_Unchecked_Conversion
5830 -- Give warnings for subprogram pointers only on most targets. The
5831 -- exception is VMS, where data pointers can have different lengths
5832 -- depending on the pointer convention.
5834 if Is_Access_Subprogram_Type (Target)
5835 or else Is_Access_Subprogram_Type (Source)
5836 or else OpenVMS_On_Target
5839 ("?conversion between pointers with different conventions!", N);
5843 -- Warn if one of the operands is Ada.Calendar.Time. Do not emit a
5844 -- warning when compiling GNAT-related sources.
5846 if Warn_On_Unchecked_Conversion
5847 and then not In_Predefined_Unit (N)
5848 and then RTU_Loaded (Ada_Calendar)
5850 (Chars (Source) = Name_Time
5852 Chars (Target) = Name_Time)
5854 -- If Ada.Calendar is loaded and the name of one of the operands is
5855 -- Time, there is a good chance that this is Ada.Calendar.Time.
5858 Calendar_Time : constant Entity_Id :=
5859 Full_View (RTE (RO_CA_Time));
5861 pragma Assert (Present (Calendar_Time));
5863 if Source = Calendar_Time
5864 or else Target = Calendar_Time
5867 ("?representation of 'Time values may change between " &
5868 "'G'N'A'T versions", N);
5873 -- Make entry in unchecked conversion table for later processing by
5874 -- Validate_Unchecked_Conversions, which will check sizes and alignments
5875 -- (using values set by the back-end where possible). This is only done
5876 -- if the appropriate warning is active.
5878 if Warn_On_Unchecked_Conversion then
5879 Unchecked_Conversions.Append
5880 (New_Val => UC_Entry'
5885 -- If both sizes are known statically now, then back end annotation
5886 -- is not required to do a proper check but if either size is not
5887 -- known statically, then we need the annotation.
5889 if Known_Static_RM_Size (Source)
5890 and then Known_Static_RM_Size (Target)
5894 Back_Annotate_Rep_Info := True;
5898 -- If unchecked conversion to access type, and access type is declared
5899 -- in the same unit as the unchecked conversion, then set the
5900 -- No_Strict_Aliasing flag (no strict aliasing is implicit in this
5903 if Is_Access_Type (Target) and then
5904 In_Same_Source_Unit (Target, N)
5906 Set_No_Strict_Aliasing (Implementation_Base_Type (Target));
5909 -- Generate N_Validate_Unchecked_Conversion node for back end in
5910 -- case the back end needs to perform special validation checks.
5912 -- Shouldn't this be in Exp_Ch13, since the check only gets done
5913 -- if we have full expansion and the back end is called ???
5916 Make_Validate_Unchecked_Conversion (Sloc (N));
5917 Set_Source_Type (Vnode, Source);
5918 Set_Target_Type (Vnode, Target);
5920 -- If the unchecked conversion node is in a list, just insert before it.
5921 -- If not we have some strange case, not worth bothering about.
5923 if Is_List_Member (N) then
5924 Insert_After (N, Vnode);
5926 end Validate_Unchecked_Conversion;
5928 ------------------------------------
5929 -- Validate_Unchecked_Conversions --
5930 ------------------------------------
5932 procedure Validate_Unchecked_Conversions is
5934 for N in Unchecked_Conversions.First .. Unchecked_Conversions.Last loop
5936 T : UC_Entry renames Unchecked_Conversions.Table (N);
5938 Eloc : constant Source_Ptr := T.Eloc;
5939 Source : constant Entity_Id := T.Source;
5940 Target : constant Entity_Id := T.Target;
5946 -- This validation check, which warns if we have unequal sizes for
5947 -- unchecked conversion, and thus potentially implementation
5948 -- dependent semantics, is one of the few occasions on which we
5949 -- use the official RM size instead of Esize. See description in
5950 -- Einfo "Handling of Type'Size Values" for details.
5952 if Serious_Errors_Detected = 0
5953 and then Known_Static_RM_Size (Source)
5954 and then Known_Static_RM_Size (Target)
5956 -- Don't do the check if warnings off for either type, note the
5957 -- deliberate use of OR here instead of OR ELSE to get the flag
5958 -- Warnings_Off_Used set for both types if appropriate.
5960 and then not (Has_Warnings_Off (Source)
5962 Has_Warnings_Off (Target))
5964 Source_Siz := RM_Size (Source);
5965 Target_Siz := RM_Size (Target);
5967 if Source_Siz /= Target_Siz then
5969 ("?types for unchecked conversion have different sizes!",
5972 if All_Errors_Mode then
5973 Error_Msg_Name_1 := Chars (Source);
5974 Error_Msg_Uint_1 := Source_Siz;
5975 Error_Msg_Name_2 := Chars (Target);
5976 Error_Msg_Uint_2 := Target_Siz;
5977 Error_Msg ("\size of % is ^, size of % is ^?", Eloc);
5979 Error_Msg_Uint_1 := UI_Abs (Source_Siz - Target_Siz);
5981 if Is_Discrete_Type (Source)
5982 and then Is_Discrete_Type (Target)
5984 if Source_Siz > Target_Siz then
5986 ("\?^ high order bits of source will be ignored!",
5989 elsif Is_Unsigned_Type (Source) then
5991 ("\?source will be extended with ^ high order " &
5992 "zero bits?!", Eloc);
5996 ("\?source will be extended with ^ high order " &
6001 elsif Source_Siz < Target_Siz then
6002 if Is_Discrete_Type (Target) then
6003 if Bytes_Big_Endian then
6005 ("\?target value will include ^ undefined " &
6010 ("\?target value will include ^ undefined " &
6017 ("\?^ trailing bits of target value will be " &
6018 "undefined!", Eloc);
6021 else pragma Assert (Source_Siz > Target_Siz);
6023 ("\?^ trailing bits of source will be ignored!",
6030 -- If both types are access types, we need to check the alignment.
6031 -- If the alignment of both is specified, we can do it here.
6033 if Serious_Errors_Detected = 0
6034 and then Ekind (Source) in Access_Kind
6035 and then Ekind (Target) in Access_Kind
6036 and then Target_Strict_Alignment
6037 and then Present (Designated_Type (Source))
6038 and then Present (Designated_Type (Target))
6041 D_Source : constant Entity_Id := Designated_Type (Source);
6042 D_Target : constant Entity_Id := Designated_Type (Target);
6045 if Known_Alignment (D_Source)
6046 and then Known_Alignment (D_Target)
6049 Source_Align : constant Uint := Alignment (D_Source);
6050 Target_Align : constant Uint := Alignment (D_Target);
6053 if Source_Align < Target_Align
6054 and then not Is_Tagged_Type (D_Source)
6056 -- Suppress warning if warnings suppressed on either
6057 -- type or either designated type. Note the use of
6058 -- OR here instead of OR ELSE. That is intentional,
6059 -- we would like to set flag Warnings_Off_Used in
6060 -- all types for which warnings are suppressed.
6062 and then not (Has_Warnings_Off (D_Source)
6064 Has_Warnings_Off (D_Target)
6066 Has_Warnings_Off (Source)
6068 Has_Warnings_Off (Target))
6070 Error_Msg_Uint_1 := Target_Align;
6071 Error_Msg_Uint_2 := Source_Align;
6072 Error_Msg_Node_1 := D_Target;
6073 Error_Msg_Node_2 := D_Source;
6075 ("?alignment of & (^) is stricter than " &
6076 "alignment of & (^)!", Eloc);
6078 ("\?resulting access value may have invalid " &
6079 "alignment!", Eloc);
6087 end Validate_Unchecked_Conversions;