[gcc/testsuite]
[official-gcc.git] / gcc / ada / sinput-d.adb
blobc9c128b8bbfdfa0199ba21fc4bfdd277b1f55101
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- S I N P U T . D --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 2002-2017, Free Software Foundation, Inc. --
10 -- --
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. --
20 -- --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
23 -- --
24 ------------------------------------------------------------------------------
26 with Debug; use Debug;
27 with Osint; use Osint;
28 with Osint.C; use Osint.C;
29 with Output; use Output;
31 package body Sinput.D is
33 Dfile : Source_File_Index;
34 -- Index of currently active debug source file
36 ------------------------
37 -- Close_Debug_Source --
38 ------------------------
40 procedure Close_Debug_Source is
41 SFR : Source_File_Record renames Source_File.Table (Dfile);
42 Src : Source_Buffer_Ptr;
43 begin
44 Trim_Lines_Table (Dfile);
45 Close_Debug_File;
47 -- Now we need to read the file that we wrote and store it in memory for
48 -- subsequent access.
50 Read_Source_File
51 (SFR.Full_Debug_Name, SFR.Source_First, SFR.Source_Last, Src);
52 SFR.Source_Text := Src;
53 pragma Assert (SFR.Source_Text'First = SFR.Source_First);
54 pragma Assert (SFR.Source_Text'Last = SFR.Source_Last);
55 end Close_Debug_Source;
57 -------------------------
58 -- Create_Debug_Source --
59 -------------------------
61 procedure Create_Debug_Source
62 (Source : Source_File_Index;
63 Loc : out Source_Ptr)
65 begin
66 Loc :=
67 ((Source_File.Table (Source_File.Last).Source_Last + Source_Align) /
68 Source_Align) * Source_Align;
69 Source_File.Append (Source_File.Table (Source));
70 Dfile := Source_File.Last;
72 declare
73 S : Source_File_Record renames Source_File.Table (Dfile);
75 begin
76 S.Index := Dfile;
77 S.Full_Debug_Name := Create_Debug_File (S.File_Name);
78 S.Debug_Source_Name := Strip_Directory (S.Full_Debug_Name);
79 S.Source_Text := null;
80 S.Source_First := Loc;
81 S.Source_Last := Loc;
82 S.Lines_Table := null;
83 S.Last_Source_Line := 1;
85 -- Allocate lines table, guess that it needs to be three times bigger
86 -- than the original source (in number of lines).
88 Alloc_Line_Tables
89 (S, Int (Source_File.Table (Source).Last_Source_Line * 3));
90 S.Lines_Table (1) := Loc;
92 if Debug_Flag_L then
93 Write_Str ("Sinput.D.Create_Debug_Source: created source ");
94 Write_Int (Int (Dfile));
95 Write_Str (" for ");
96 Write_Str (Get_Name_String (S.Full_Debug_Name));
97 Write_Line ("");
98 end if;
99 end;
100 end Create_Debug_Source;
102 ----------------------
103 -- Write_Debug_Line --
104 ----------------------
106 procedure Write_Debug_Line (Str : String; Loc : in out Source_Ptr) is
107 S : Source_File_Record renames Source_File.Table (Dfile);
109 begin
110 -- Ignore write request if null line at start of file
112 if Str'Length = 0 and then Loc = S.Source_First then
113 return;
115 -- Here we write the line, compute the source location for the following
116 -- line, allocate its table entry, and update the source record entry.
118 else
119 Write_Debug_Info (Str (Str'First .. Str'Last - 1));
120 Loc := Loc - 1 + Source_Ptr (Str'Length + Debug_File_Eol_Length);
121 Add_Line_Tables_Entry (S, Loc);
122 S.Source_Last := Loc;
123 Set_Source_File_Index_Table (Dfile);
124 end if;
125 end Write_Debug_Line;
127 end Sinput.D;