1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392
|
------------------------------------------------------------------------------
-- --
-- GNAT COMPILER COMPONENTS --
-- --
-- E X P _ D B U G --
-- --
-- B o d y --
-- --
-- $Revision: 1.16 $ --
-- --
-- Copyright (C) 1996-1997 Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 2, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
-- for more details. You should have received a copy of the GNU General --
-- Public License distributed with GNAT; see file COPYING. If not, write --
-- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
-- MA 02111-1307, USA. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- It is now maintained by Ada Core Technologies Inc (http://www.gnat.com). --
-- --
------------------------------------------------------------------------------
with Atree; use Atree;
with Debug; use Debug;
with Einfo; use Einfo;
with Elists; use Elists;
with Exp_Util; use Exp_Util;
with Itypes; use Itypes;
with Namet; use Namet;
with Nlists; use Nlists;
with Nmake; use Nmake;
with Output; use Output;
with Sem_Eval; use Sem_Eval;
with Sem_Util; use Sem_Util;
with Sinfo; use Sinfo;
with Stand; use Stand;
with Tbuild; use Tbuild;
with Urealp; use Urealp;
package body Exp_Dbug is
----------------------
-- Local Procedures --
----------------------
procedure Add_Uint_To_Buffer (U : Uint);
-- Add image of universal integer to Name_Buffer, updating Name_Len
procedure Add_Real_To_Buffer (U : Ureal);
-- Add nnn_ddd to Name_Buffer, where nnn and ddd are integer values of
-- the normalized numerator and denominator of the given real value.
function Bounds_Match_Size (E : Entity_Id) return Boolean;
-- Determine whether the bounds of E match the size of the type. This is
-- used to determine whether encoding is required for a discrete type.
------------------------
-- Add_Real_To_Buffer --
------------------------
procedure Add_Real_To_Buffer (U : Ureal) is
begin
Add_Uint_To_Buffer (Norm_Num (U));
Add_Str_To_Name_Buffer ("_");
Add_Uint_To_Buffer (Norm_Den (U));
end Add_Real_To_Buffer;
------------------------
-- Add_Uint_To_Buffer --
------------------------
procedure Add_Uint_To_Buffer (U : Uint) is
begin
if U < 0 then
Add_Uint_To_Buffer (-U);
Add_Char_To_Name_Buffer ('m');
else
UI_Image (U, Decimal);
Add_Str_To_Name_Buffer (UI_Image_Buffer (1 .. UI_Image_Length));
end if;
end Add_Uint_To_Buffer;
-----------------------
-- Bounds_Match_Size --
-----------------------
function Bounds_Match_Size (E : Entity_Id) return Boolean is
Siz : Uint;
begin
if not Is_OK_Static_Subtype (E) then
return False;
elsif Is_Integer_Type (E)
and then Subtypes_Statically_Match (E, Base_Type (E))
then
return True;
-- Here we check if the static bounds match the natural size, which
-- is the size passed through with the debugging information. This
-- is the Esize rounded up to 8, 16, 32 or 64 as appropriate.
else
if Esize (E) <= 8 then
Siz := Uint_8;
elsif Esize (E) <= 16 then
Siz := Uint_16;
elsif Esize (E) <= 32 then
Siz := Uint_32;
else
Siz := Uint_64;
end if;
if Is_Modular_Integer_Type (E) or else Is_Enumeration_Type (E) then
return
Expr_Rep_Value (Type_Low_Bound (E)) = 0
and then
2 ** Siz - Expr_Rep_Value (Type_High_Bound (E)) = 1;
else
return
Expr_Rep_Value (Type_Low_Bound (E)) + 2 ** (Siz - 1) = 0
and then
2 ** (Siz - 1) - Expr_Rep_Value (Type_High_Bound (E)) = 1;
end if;
end if;
end Bounds_Match_Size;
----------------------------
-- Get_Encoded_Field_Name --
----------------------------
procedure Get_Encoded_Field_Name
(E : Entity_Id;
Align : Nat;
Var : Int)
is
begin
Get_Name_String (Chars (E));
if Var /= 0 then
Add_Str_To_Name_Buffer ("___XVL");
elsif Align /= 0 then
Add_Str_To_Name_Buffer ("___XVA");
end if;
if Align /= 0 then
Add_Nat_To_Name_Buffer (Align);
end if;
Name_Buffer (Name_Len) := Ascii.NUL;
end Get_Encoded_Field_Name;
---------------------------
-- Get_Encoded_Type_Name --
---------------------------
-- Note: see spec for details on encodings
function Get_Encoded_Type_Name (E : Entity_Id) return Boolean is
begin
Name_Len := 0;
-- Fixed-point case
if Is_Fixed_Point_Type (E) then
Add_Str_To_Name_Buffer ("XF_");
Add_Real_To_Buffer (Delta_Value (E));
if Small_Value (E) /= Delta_Value (E) then
Add_Str_To_Name_Buffer ("_");
Add_Real_To_Buffer (Small_Value (E));
end if;
-- Discrete case where bounds do not match size
elsif Is_Discrete_Type (E)
and then not Bounds_Match_Size (E)
then
if Has_Biased_Representation (E) then
Add_Str_To_Name_Buffer ("XB");
else
Add_Str_To_Name_Buffer ("XD");
end if;
declare
Lo : constant Node_Id := Type_Low_Bound (E);
Hi : constant Node_Id := Type_High_Bound (E);
Lo_Stat : constant Boolean := Is_OK_Static_Expression (Lo);
Hi_Stat : constant Boolean := Is_OK_Static_Expression (Hi);
Lo_Discr : constant Boolean :=
Nkind (Lo) = N_Identifier
and then
Ekind (Entity (Lo)) = E_Discriminant;
Hi_Discr : constant Boolean :=
Nkind (Hi) = N_Identifier
and then
Ekind (Entity (Hi)) = E_Discriminant;
Lo_Encode : constant Boolean := Lo_Stat or Lo_Discr;
Hi_Encode : constant Boolean := Hi_Stat or Hi_Discr;
begin
if Lo_Encode or Hi_Encode then
if Lo_Encode then
if Hi_Encode then
Add_Str_To_Name_Buffer ("LU_");
else
Add_Str_To_Name_Buffer ("L_");
end if;
else
Add_Str_To_Name_Buffer ("U_");
end if;
if Lo_Stat then
Add_Uint_To_Buffer (Expr_Rep_Value (Lo));
elsif Lo_Discr then
Get_Name_String_And_Append (Chars (Entity (Lo)));
end if;
if Lo_Encode and Hi_Encode then
Add_Str_To_Name_Buffer ("__");
end if;
if Hi_Stat then
Add_Uint_To_Buffer (Expr_Rep_Value (Hi));
elsif Hi_Discr then
Get_Name_String_And_Append (Chars (Entity (Hi)));
end if;
end if;
end;
-- Variable length record
elsif Is_Record_Type (E)
and then not Size_Known_At_Compile_Time (E)
then
Add_Str_To_Name_Buffer ("XV");
-- For all other cases, the encoded name is the normal type name
else
return False;
end if;
-- If we fall through then the Name_Buffer contains the encoded name
Name_Buffer (Name_Len + 1) := Ascii.Nul;
if Debug_Flag_B then
Write_Str ("**** type ");
Write_Name (Chars (E));
Write_Str (" is encoded as ");
Write_Str (Name_Buffer (1 .. Name_Len));
Write_Eol;
end if;
return True;
end Get_Encoded_Type_Name;
--------------------------
-- Get_Variant_Encoding --
--------------------------
procedure Get_Variant_Encoding (V : Node_Id) is
Choice : Node_Id;
procedure Choice_Val (Typ : Character; Choice : Node_Id);
-- Output encoded value for a single choice value. Typ is the key
-- character ('S', 'F', or 'T') that precedes the choice value.
----------------
-- Choice_Val --
----------------
procedure Choice_Val (Typ : Character; Choice : Node_Id) is
begin
Add_Char_To_Name_Buffer (Typ);
if Nkind (Choice) = N_Integer_Literal then
Add_Uint_To_Buffer (Intval (Choice));
-- Character literal with no entity present (this is the case
-- Standard.Character or Standard.Wide_Character as root type)
elsif Nkind (Choice) = N_Character_Literal
and then No (Entity (Choice))
then
Add_Uint_To_Buffer
(UI_From_Int (Int (Char_Literal_Value (Choice))));
else
declare
Ent : constant Entity_Id := Entity (Choice);
begin
if Ekind (Ent) = E_Enumeration_Literal then
Add_Uint_To_Buffer (Enumeration_Rep (Ent));
else
pragma Assert (Ekind (Ent) = E_Constant);
Choice_Val (Typ, Constant_Value (Ent));
end if;
end;
end if;
end Choice_Val;
-- Start of processing for Get_Variant_Encoding
begin
Name_Len := 0;
Choice := First (Discrete_Choices (V));
while Present (Choice) loop
if Nkind (Choice) = N_Others_Choice then
Add_Char_To_Name_Buffer ('O');
elsif Nkind (Choice) = N_Range then
Choice_Val ('R', Low_Bound (Choice));
Choice_Val ('T', High_Bound (Choice));
elsif Is_Entity_Name (Choice)
and then Is_Type (Entity (Choice))
then
Choice_Val ('R', Type_Low_Bound (Entity (Choice)));
Choice_Val ('T', Type_High_Bound (Entity (Choice)));
elsif Nkind (Choice) = N_Subtype_Indication then
declare
Rang : constant Node_Id :=
Range_Expression (Constraint (Choice));
begin
Choice_Val ('R', Low_Bound (Rang));
Choice_Val ('T', High_Bound (Rang));
end;
else
Choice_Val ('S', Choice);
end if;
Choice := Next (Choice);
end loop;
Name_Buffer (Name_Len + 1) := Ascii.Nul;
if Debug_Flag_B then
declare
VP : constant Node_Id := Parent (V); -- Variant_Part
CL : constant Node_Id := Parent (VP); -- Component_List
RD : constant Node_Id := Parent (CL); -- Record_Definition
FT : constant Node_Id := Parent (RD); -- Full_Type_Declaration
begin
Write_Str ("**** variant for type ");
Write_Name (Chars (Defining_Identifier (FT)));
Write_Str (" is encoded as ");
Write_Str (Name_Buffer (1 .. Name_Len));
Write_Eol;
end;
end if;
end Get_Variant_Encoding;
---------------------------------
-- Make_Packed_Array_Type_Name --
---------------------------------
function Make_Packed_Array_Type_Name
(Typ : Entity_Id;
Csize : Uint)
return Name_Id
is
begin
Get_Name_String (Chars (Typ));
Add_Str_To_Name_Buffer ("___XP");
Add_Uint_To_Buffer (Csize);
return Name_Find;
end Make_Packed_Array_Type_Name;
end Exp_Dbug;
|