2002-04-02 David S. Miller <davem@redhat.com>
[official-gcc.git] / gcc / ada / sinput-d.adb
blob9b2124947a19851baa6022774494600146e7a2f9
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- S I N P U T . D --
6 -- --
7 -- B o d y --
8 -- --
9 -- --
10 -- Copyright (C) 2001, Free Software Foundation, Inc. --
11 -- --
12 -- GNAT is free software; you can redistribute it and/or modify it under --
13 -- terms of the GNU General Public License as published by the Free Soft- --
14 -- ware Foundation; either version 2, or (at your option) any later ver- --
15 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
16 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
17 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
18 -- for more details. You should have received a copy of the GNU General --
19 -- Public License distributed with GNAT; see file COPYING. If not, write --
20 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
21 -- MA 02111-1307, USA. --
22 -- --
23 -- GNAT was originally developed by the GNAT team at New York University. --
24 -- It is now maintained by Ada Core Technologies Inc (http://www.gnat.com). --
25 -- --
26 ------------------------------------------------------------------------------
28 with Osint; use Osint;
29 with Osint.C; use Osint.C;
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 S : Source_File_Record renames Source_File.Table (Dfile);
42 Src : Source_Buffer_Ptr;
44 begin
45 Trim_Lines_Table (Dfile);
46 Close_Debug_File;
48 -- Now we need to read the file that we wrote and store it
49 -- in memory for subsequent access.
51 Read_Source_File
52 (S.Debug_Source_Name, S.Source_First, S.Source_Last, Src);
53 S.Source_Text := Src;
54 end Close_Debug_Source;
56 -------------------------
57 -- Create_Debug_Source --
58 -------------------------
60 procedure Create_Debug_Source
61 (Source : Source_File_Index;
62 Loc : out Source_Ptr)
64 begin
65 Loc := Source_File.Table (Source_File.Last).Source_Last + 1;
66 Source_File.Increment_Last;
67 Dfile := Source_File.Last;
69 declare
70 S : Source_File_Record renames Source_File.Table (Dfile);
72 begin
73 S := Source_File.Table (Source);
74 S.Debug_Source_Name := Create_Debug_File (S.File_Name);
75 S.Source_First := Loc;
76 S.Source_Last := Loc;
77 S.Lines_Table := null;
78 S.Last_Source_Line := 1;
80 -- Allocate lines table, guess that it needs to be three times
81 -- bigger than the original source (in number of lines).
83 Alloc_Line_Tables
84 (S, Int (Source_File.Table (Source).Last_Source_Line * 3));
85 S.Lines_Table (1) := Loc;
86 end;
87 end Create_Debug_Source;
89 ----------------------
90 -- Write_Debug_Line --
91 ----------------------
93 procedure Write_Debug_Line (Str : String; Loc : in out Source_Ptr) is
94 S : Source_File_Record renames Source_File.Table (Dfile);
96 begin
97 -- Ignore write request if null line at start of file
99 if Str'Length = 0 and then Loc = S.Source_First then
100 return;
102 -- Here we write the line, and update the source record entry
104 else
105 Write_Debug_Info (Str (Str'First .. Str'Last - 1));
106 Add_Line_Tables_Entry (S, Loc);
107 Loc := Loc - 1 + Source_Ptr (Str'Length + Debug_File_Eol_Length);
108 S.Source_Last := Loc;
109 end if;
110 end Write_Debug_Line;
112 end Sinput.D;