table.adb, [...] (Append): Reimplement in terms of Set_Item.
[gcc.git] / gcc / ada / sinput-d.adb
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-2007, 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 2, 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 COPYING. If not, write --
19 -- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, --
20 -- Boston, MA 02110-1301, USA. --
21 -- --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 -- --
25 ------------------------------------------------------------------------------
26
27 with Osint; use Osint;
28 with Osint.C; use Osint.C;
29
30 package body Sinput.D is
31
32 Dfile : Source_File_Index;
33 -- Index of currently active debug source file
34
35 ------------------------
36 -- Close_Debug_Source --
37 ------------------------
38
39 procedure Close_Debug_Source is
40 S : Source_File_Record renames Source_File.Table (Dfile);
41 Src : Source_Buffer_Ptr;
42
43 begin
44 Trim_Lines_Table (Dfile);
45 Close_Debug_File;
46
47 -- Now we need to read the file that we wrote and store it in memory for
48 -- subsequent access.
49
50 Read_Source_File
51 (S.Full_Debug_Name, S.Source_First, S.Source_Last, Src);
52 S.Source_Text := Src;
53 end Close_Debug_Source;
54
55 -------------------------
56 -- Create_Debug_Source --
57 -------------------------
58
59 procedure Create_Debug_Source
60 (Source : Source_File_Index;
61 Loc : out Source_Ptr)
62 is
63 begin
64 Loc := Source_File.Table (Source_File.Last).Source_Last + 1;
65 Source_File.Append (Source_File.Table (Source));
66 Dfile := Source_File.Last;
67
68 declare
69 S : Source_File_Record renames Source_File.Table (Dfile);
70
71 begin
72 S.Full_Debug_Name := Create_Debug_File (S.File_Name);
73 S.Debug_Source_Name := Strip_Directory (S.Full_Debug_Name);
74 S.Source_First := Loc;
75 S.Source_Last := Loc;
76 S.Lines_Table := null;
77 S.Last_Source_Line := 1;
78
79 -- Allocate lines table, guess that it needs to be three times bigger
80 -- than the original source (in number of lines).
81
82 Alloc_Line_Tables
83 (S, Int (Source_File.Table (Source).Last_Source_Line * 3));
84 S.Lines_Table (1) := Loc;
85 end;
86 end Create_Debug_Source;
87
88 ----------------------
89 -- Write_Debug_Line --
90 ----------------------
91
92 procedure Write_Debug_Line (Str : String; Loc : in out Source_Ptr) is
93 S : Source_File_Record renames Source_File.Table (Dfile);
94
95 begin
96 -- Ignore write request if null line at start of file
97
98 if Str'Length = 0 and then Loc = S.Source_First then
99 return;
100
101 -- Here we write the line, compute the source location for the following
102 -- line, allocate its table entry, and update the source record entry.
103
104 else
105 Write_Debug_Info (Str (Str'First .. Str'Last - 1));
106 Loc := Loc - 1 + Source_Ptr (Str'Length + Debug_File_Eol_Length);
107 Add_Line_Tables_Entry (S, Loc);
108 S.Source_Last := Loc;
109 Set_Source_File_Index_Table (Dfile);
110 end if;
111 end Write_Debug_Line;
112
113 end Sinput.D;