/usr/share/ada/adainclude/asis/a4g-a_output.adb is in libasis2014-dev 2014-4.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 | ------------------------------------------------------------------------------
-- --
-- ASIS-for-GNAT IMPLEMENTATION COMPONENTS --
-- --
-- A 4 G . A _ O U T P U T --
-- --
-- B o d y --
-- --
-- Copyright (C) 1995-2012, Free Software Foundation, Inc. --
-- --
-- ASIS-for-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 --
-- Software Foundation; either version 2, or (at your option) any later --
-- version. ASIS-for-GNAT is distributed in the hope that it will be use- --
-- ful, but WITHOUT ANY WARRANTY; without even the implied warranty of MER- --
-- CHANTABILITY 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 ASIS-for-GNAT; see file --
-- COPYING. If not, write to the Free Software Foundation, 51 Franklin --
-- Street, Fifth Floor, Boston, MA 02110-1301, USA. --
-- --
-- --
-- --
-- --
-- --
-- --
-- --
-- --
-- ASIS-for-GNAT was originally developed by the ASIS-for-GNAT team at the --
-- Software Engineering Laboratory of the Swiss Federal Institute of --
-- Technology (LGL-EPFL) in Lausanne, Switzerland, in cooperation with the --
-- Scientific Research Computer Center of Moscow State University (SRCC --
-- MSU), Russia, with funding partially provided by grants from the Swiss --
-- National Science Foundation and the Swiss Academy of Engineering --
-- Sciences. ASIS-for-GNAT is now maintained by AdaCore --
-- (http://www.adacore.com). --
-- --
------------------------------------------------------------------------------
with Ada.Characters.Handling;
with Ada.Exceptions; use Ada.Exceptions;
with Ada.Strings.Fixed; use Ada.Strings.Fixed;
-- with Asis.Text; use Asis.Text;
with Asis.Elements; use Asis.Elements;
with A4G.A_Debug; use A4G.A_Debug;
with A4G.A_Types; use A4G.A_Types;
with A4G.Int_Knds; use A4G.Int_Knds;
with A4G.Contt; use A4G.Contt;
with A4G.Contt.UT; use A4G.Contt.UT;
with A4G.Contt.TT; use A4G.Contt.TT;
with A4G.A_Opt; use A4G.A_Opt;
with A4G.Vcheck; use A4G.Vcheck;
with Asis.Extensions;
with Asis.Iterator;
with Asis.Set_Get; use Asis.Set_Get;
with Asis.Text;
with Atree; use Atree;
with Namet; use Namet;
with Output; use Output;
with Sinfo; use Sinfo;
with Sinput; use Sinput;
package body A4G.A_Output is
LT : String renames A4G.A_Types.ASIS_Line_Terminator;
---------
-- Add --
---------
procedure Add (Phrase : String) is
begin
if Debug_Buffer_Len = Max_Debug_Buffer_Len then
return;
end if;
for I in Phrase'Range loop
Debug_Buffer_Len := Debug_Buffer_Len + 1;
Debug_Buffer (Debug_Buffer_Len) := Phrase (I);
if Debug_Buffer_Len = Max_Debug_Buffer_Len then
exit;
end if;
end loop;
end Add;
------------------
-- ASIS_Warning --
------------------
procedure ASIS_Warning
(Message : String;
Error : Asis.Errors.Error_Kinds := Not_An_Error)
is
begin
case ASIS_Warning_Mode is
when Suppress =>
null;
when Normal =>
Set_Standard_Error;
Write_Str ("ASIS warning: ");
Write_Eol;
Write_Str (Message);
Write_Eol;
Set_Standard_Output;
when Treat_As_Error =>
-- ??? Raise_ASIS_Failed should be revised to use like that
Raise_ASIS_Failed (
Argument => Nil_Element,
Diagnosis => Message,
Stat => Error);
end case;
end ASIS_Warning;
--------------------------------------
-- Debug_String (Compilation Unit) --
--------------------------------------
-- SHOULD BE REVISED USING Debug_Buffer!!!
function Debug_String (CUnit : Compilation_Unit) return String is
LT : String renames A4G.A_Types.ASIS_Line_Terminator;
U : Unit_Id;
C : Context_Id;
begin
U := Get_Unit_Id (CUnit);
C := Encl_Cont_Id (CUnit);
if No (U) then
return "This is a Nil Compilation Unit";
else
Reset_Context (C);
return LT &
"Unit Id: " & Unit_Id'Image (U) & LT
&
" Unit name: " & Unit_Name (CUnit) & LT
&
" Kind: " & Asis.Unit_Kinds'Image (Kind (C, U)) & LT
&
" Class: " & Asis.Unit_Classes'Image (Class (C, U)) & LT
&
" Origin: " & Asis.Unit_Origins'Image (Origin (C, U)) & LT
&
" Enclosing Context Id: " & Context_Id'Image (C) & LT
&
" Is consistent: " & Boolean'Image (Is_Consistent (C, U)) & LT
&
"-------------------------------------------------";
end if;
end Debug_String;
procedure Debug_String
(CUnit : Compilation_Unit;
No_Abort : Boolean := False)
is
LT : String renames A4G.A_Types.ASIS_Line_Terminator;
U : Unit_Id;
C : Context_Id;
begin
Debug_Buffer_Len := 0;
U := Get_Unit_Id (CUnit);
C := Encl_Cont_Id (CUnit);
if No (U) then
Add ("This is a Nil Compilation Unit");
else
Reset_Context (C);
Add (LT);
Add ("Unit Id: " & Unit_Id'Image (U) & LT);
Add (" Unit name: " & Unit_Name (CUnit) & LT);
Add (" Kind: " & Asis.Unit_Kinds'Image (Kind (C, U)) & LT);
Add (" Class: " & Asis.Unit_Classes'Image (Class (C, U)) & LT);
Add (" Origin: " & Asis.Unit_Origins'Image (Origin (C, U)) & LT);
Add (" Enclosing Context Id: " & Context_Id'Image (C) & LT);
Add (" Is consistent: " &
Boolean'Image (Is_Consistent (C, U)) & LT);
Add ("-------------------------------------------------");
end if;
exception
when Ex : others =>
if No_Abort then
Add (LT & "Can not complete the unit debug image because of" & LT);
Add (Exception_Information (Ex));
else
raise;
end if;
end Debug_String;
-----------------------------
-- Debug_String (Context) --
-----------------------------
-- SHOULD BE REVISED USING Debug_Buffer!!!
function Debug_String (Cont : Context) return String is
LT : String renames A4G.A_Types.ASIS_Line_Terminator;
C : constant Context_Id := Get_Cont_Id (Cont);
Debug_String_Prefix : constant String :=
"Context Id: " & Context_Id'Image (C) & LT;
begin
if C = Non_Associated then
return Debug_String_Prefix
& " This Context has never been associated";
elsif not Is_Associated (C) and then
not Is_Opened (C)
then
return Debug_String_Prefix
& " This Context is dissociated at the moment";
elsif not Is_Opened (C) then
-- here Is_Associated (C)
return Debug_String_Prefix
& " This Context has associations," & LT
& " but it is closed at the moment";
else -- here Is_Associated (C) and Is_Opened (C)
return Debug_String_Prefix
&
" This Context is opened at the moment" & LT
&
" All tree files: "
& Tree_Id'Image (Last_Tree (C) - First_Tree_Id + 1) & LT
&
" All units: "
& Unit_Id'Image (Last_Unit - First_Unit_Id + 1) & LT
&
" Existing specs : "
& Natural'Image (Lib_Unit_Decls (C)) & LT
&
" Existing bodies: "
& Natural'Image (Comp_Unit_Bodies (C)) & LT
&
" Nonexistent units:"
& Natural'Image (Natural (Last_Unit - First_Unit_Id + 1) -
(Lib_Unit_Decls (C) + Comp_Unit_Bodies (C)))
& LT
& "=================";
end if;
end Debug_String;
-----------------------------
-- Debug_String (Element) --
-----------------------------
procedure Debug_String
(E : Element;
No_Abort : Boolean := False)
is
E_Kind : constant Internal_Element_Kinds := Int_Kind (E);
E_Kind_Image : constant String := Internal_Element_Kinds'Image (E_Kind);
E_Unit : constant Asis.Compilation_Unit := Encl_Unit (E);
E_Unit_Class : constant Unit_Classes := Class (E_Unit);
N : constant Node_Id := Node (E);
R_N : constant Node_Id := R_Node (E);
N_F_1 : constant Node_Id := Node_Field_1 (E);
N_F_2 : constant Node_Id := Node_Field_2 (E);
C : constant Context_Id := Encl_Cont_Id (E);
T : constant Tree_Id := Encl_Tree (E);
begin
Debug_Buffer_Len := 0;
if Is_Nil (E) then
Add ("This is a Nil Element");
else
Add (E_Kind_Image);
Add (LT & "located in ");
Add (Unit_Name (E_Unit));
if E_Unit_Class = A_Separate_Body then
Add (" (subunit, Unit_Id =");
elsif E_Unit_Class = A_Public_Declaration or else
E_Unit_Class = A_Private_Declaration
then
Add (" (spec, Unit_Id =");
else
Add (" (body, Unit_Id =");
end if;
Add (Unit_Id'Image (Encl_Unit_Id (E)));
Add (", Context_Id =");
Add (Context_Id'Image (C));
Add (")" & LT);
if not (Debug_Flag_I) then
Add ("text position :");
-- if not Is_Text_Available (E) then
-- Creating the source location from the element node. We
-- cannot safely use Element_Span here because in case of a
-- bug in a structural query this may result in curcling of
-- query blow-ups.
if Sloc (N) <= No_Location then
Add (" not available");
Add (LT);
else
Add (" ");
declare
use Ada.Strings;
P : Source_Ptr;
Sindex : Source_File_Index;
Instance_Depth : Natural := 0;
procedure Enter_Sloc;
-- For the current value of P, adds to the debug string
-- the string of the form file_name:line_number. Also
-- computes Sindex as the Id of the sourse file of P.
procedure Enter_Sloc is
F_Name : File_Name_Type;
begin
Sindex := Get_Source_File_Index (P);
F_Name := File_Name (Sindex);
Get_Name_String (F_Name);
Add (Name_Buffer (1 .. Name_Len) & ":");
Add (Trim (Get_Physical_Line_Number (P)'Img, Both));
Add (":");
Add (Trim (Get_Column_Number (P)'Img, Both));
end Enter_Sloc;
begin
P := Sloc (N);
Enter_Sloc;
P := Instantiation (Sindex);
while P /= No_Location loop
Add ("[");
Instance_Depth := Instance_Depth + 1;
Enter_Sloc;
P := Instantiation (Sindex);
end loop;
for J in 1 .. Instance_Depth loop
Add ("]");
end loop;
Add (LT);
end;
end if;
-- else
-- declare
-- Arg_Span : Span;
-- FL : String_Ptr;
-- LL : String_Ptr;
-- FC : String_Ptr;
-- LC : String_Ptr;
-- begin
-- -- this operation is potentially dangerous - it may
-- -- change the tree (In fact, it should not, if we
-- -- take into account the typical conditions when
-- -- this routine is called
-- Arg_Span := Element_Span (E);
-- FL := new String'(Line_Number'Image (Arg_Span.First_Line));
-- LL := new String'(Line_Number'Image (Arg_Span.Last_Line));
-- FC := new String'(Character_Position'Image
-- (Arg_Span.First_Column));
-- LC := new String'(Character_Position'Image
-- (Arg_Span.Last_Column));
-- Add (FL.all);
-- Add (" :");
-- Add (FC.all);
-- Add (" -");
-- Add (LL.all);
-- Add (" :");
-- Add (LC.all);
-- Add (LT);
-- end;
-- end if;
end if;
Add (" Nodes:" & LT);
Add (" Node :" & Node_Id'Image (N));
Add (" - " & Node_Kind'Image (Nkind (N)) & LT);
Add (" R_Node :" & Node_Id'Image (R_N));
Add (" - " & Node_Kind'Image (Nkind (R_N)) & LT);
Add (" Node_Field_1 :" & Node_Id'Image (N_F_1));
Add (" - " & Node_Kind'Image (Nkind (N_F_1)) & LT);
Add (" Node_Field_2 :" & Node_Id'Image (N_F_2));
Add (" - " & Node_Kind'Image (Nkind (N_F_2)) & LT);
Add (" Rel_Sloc :");
Add (Source_Ptr'Image (Rel_Sloc (E)) & LT);
if Special_Case (E) /= Not_A_Special_Case then
Add (" Special Case : ");
Add (Special_Cases'Image (Special_Case (E)) & LT);
end if;
if Special_Case (E) = Stand_Char_Literal or else
Character_Code (E) /= 0
then
Add (" Character_Code :");
Add (Char_Code'Image (Character_Code (E)) & LT);
end if;
case Normalization_Case (E) is
when Is_Normalized =>
Add (" Normalized" & LT);
when Is_Normalized_Defaulted =>
Add (" Normalized (with default value)" & LT);
when Is_Normalized_Defaulted_For_Box =>
Add (" Normalized (with default value computed for box)"
& LT);
when Is_Normalized_Defaulted_Null_Procedure =>
Add (" Normalized (with default null procedure)"
& LT);
when Is_Not_Normalized =>
null;
end case;
if Parenth_Count (E) > 0 then
Add (" Parenth_Count :");
Add (Nat'Image (Parenth_Count (E)) & LT);
end if;
if Is_From_Implicit (E) then
Add (" Is implicit" & LT);
end if;
if Is_From_Inherited (E) then
Add (" Is inherited" & LT);
end if;
if Is_From_Instance (E) then
Add (" Is from instance" & LT);
end if;
Add (" obtained from the tree ");
if Present (T) then
Get_Name_String (C, T);
Add (A_Name_Buffer (1 .. A_Name_Len));
Add (" (Tree_Id =" & Tree_Id'Image (T) & ")");
else
Add (" <nil tree>");
end if;
end if;
exception
when Ex : others =>
if No_Abort then
Add (LT & "Can not complete the unit debug image because of" & LT);
Add (Exception_Information (Ex));
else
raise;
end if;
end Debug_String;
-------------------
-- Write_Element --
-------------------
procedure Write_Element (E : Element; Indentation : Natural := 0) is
use Ada.Characters.Handling, Asis.Text;
procedure Indent_Str (S : String; Indentation : Natural);
-- Write S with the given Indentation. S may contain multiple lines
-- separated by LF.
procedure Indent_Str (S : String; Indentation : Natural) is
-- We avoid trailing blanks in blank lines
Prev : Character := ASCII.LF;
begin
if S /= "" then
for X in S'Range loop
declare
Next : constant Character := S (X);
begin
if Prev = ASCII.LF and then Next /= ASCII.LF then
Write_Str ((1 .. Indentation => ' '));
end if;
Write_Char (Next);
Prev := Next;
end;
end loop;
end if;
end Indent_Str;
begin
Debug_String (E);
Indent_Str (Debug_Buffer (1 .. Debug_Buffer_Len), Indentation);
Write_Eol;
Indent_Str ("Source:", Indentation);
Write_Eol;
Indent_Str (To_String (Element_Image (E)), Indentation);
Write_Eol;
Indent_Str ("------------------------------------------------",
Indentation);
Write_Eol;
end Write_Element;
procedure we (E : Element) is
begin
Write_Element (E);
end we;
------------------------
-- Write_Element_Tree --
------------------------
Indentation : Natural := Natural'Last;
Indentation_Amount : constant Natural := 4;
procedure Write_Element_Tree (E : Element) is
pragma Assert (Indentation = Natural'Last);
use Asis.Extensions;
State : No_State := Not_Used;
procedure Pre_Operation
(Element : Asis.Element;
Control : in out Traverse_Control;
State : in out No_State);
procedure Post_Operation
(Element : Asis.Element;
Control : in out Traverse_Control;
State : in out No_State);
procedure Pre_Operation
(Element : Asis.Element;
Control : in out Traverse_Control;
State : in out No_State) is
pragma Unreferenced (Control);
pragma Unreferenced (State);
begin
Write_Element (Element, Indentation);
Indentation := Indentation + Indentation_Amount;
end Pre_Operation;
procedure Post_Operation
(Element : Asis.Element;
Control : in out Traverse_Control;
State : in out No_State) is
pragma Unreferenced (Element);
pragma Unreferenced (Control);
pragma Unreferenced (State);
begin
Indentation := Indentation - Indentation_Amount;
end Post_Operation;
procedure Traverse is new Asis.Iterator.Traverse_Element
(State_Information => No_State);
Control : Traverse_Control := Continue;
begin
Indentation := 0;
Traverse (E, Control, State);
Indentation := Natural'Last;
end Write_Element_Tree;
procedure wt (E : Element) is
begin
Write_Element_Tree (E);
end wt;
----------------
-- Write_Node --
----------------
procedure Write_Node (N : Node_Id; Prefix : String := "") is
begin
Write_Str (Prefix);
Write_Str ("Node_Id = ");
Write_Int (Int (N));
Write_Eol;
Write_Str (Prefix);
Write_Str ("Nkind = ");
Write_Str (Node_Kind'Image (Nkind (N)));
Write_Eol;
Write_Str (Prefix);
Write_Str ("Rewrite_Sub value : ");
Write_Str (Boolean'Image (Is_Rewrite_Substitution (N)));
Write_Eol;
Write_Str (Prefix);
Write_Str ("Rewrite_Ins value : ");
Write_Str (Boolean'Image (Is_Rewrite_Insertion (N)));
Write_Eol;
Write_Str (Prefix);
Write_Str ("Comes_From_Source value : ");
Write_Str (Boolean'Image (Comes_From_Source (N)));
Write_Eol;
if Original_Node (N) = N then
Write_Str (Prefix);
Write_Str (" Node is unchanged");
Write_Eol;
elsif Original_Node (N) = Empty then
Write_Str (Prefix);
Write_Str (" Node has been inserted");
Write_Eol;
else
Write_Str (Prefix);
Write_Str (" Node has been rewritten");
Write_Eol;
Write_Node (N => Original_Node (N),
Prefix => Write_Node.Prefix & " Original node -> ");
end if;
Write_Eol;
end Write_Node;
end A4G.A_Output;
|