adadecode.c, [...]: New files.
[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 -- $Revision$
10 -- --
11 -- Copyright (C) 2001, Free Software Foundation, Inc. --
12 -- --
13 -- GNAT is free software; you can redistribute it and/or modify it under --
14 -- terms of the GNU General Public License as published by the Free Soft- --
15 -- ware Foundation; either version 2, or (at your option) any later ver- --
16 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
17 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
18 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
19 -- for more details. You should have received a copy of the GNU General --
20 -- Public License distributed with GNAT; see file COPYING. If not, write --
21 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
22 -- MA 02111-1307, USA. --
23 -- --
24 -- GNAT was originally developed by the GNAT team at New York University. --
25 -- It is now maintained by Ada Core Technologies Inc (http://www.gnat.com). --
26 -- --
27 ------------------------------------------------------------------------------
28
29 with Osint; use Osint;
30 with Osint.C; use Osint.C;
31
32 package body Sinput.D is
33
34 Dfile : Source_File_Index;
35 -- Index of currently active debug source file
36
37 ------------------------
38 -- Close_Debug_Source --
39 ------------------------
40
41 procedure Close_Debug_Source is
42 S : Source_File_Record renames Source_File.Table (Dfile);
43 Src : Source_Buffer_Ptr;
44
45 begin
46 Trim_Lines_Table (Dfile);
47 Close_Debug_File;
48
49 -- Now we need to read the file that we wrote and store it
50 -- in memory for subsequent access.
51
52 Read_Source_File
53 (S.Debug_Source_Name, S.Source_First, S.Source_Last, Src);
54 S.Source_Text := Src;
55 end Close_Debug_Source;
56
57 -------------------------
58 -- Create_Debug_Source --
59 -------------------------
60
61 procedure Create_Debug_Source
62 (Source : Source_File_Index;
63 Loc : out Source_Ptr)
64 is
65 begin
66 Loc := Source_File.Table (Source_File.Last).Source_Last + 1;
67 Source_File.Increment_Last;
68 Dfile := Source_File.Last;
69
70 declare
71 S : Source_File_Record renames Source_File.Table (Dfile);
72
73 begin
74 S := Source_File.Table (Source);
75 S.Debug_Source_Name := Create_Debug_File (S.File_Name);
76 S.Source_First := Loc;
77 S.Source_Last := Loc;
78 S.Lines_Table := null;
79 S.Last_Source_Line := 1;
80
81 -- Allocate lines table, guess that it needs to be three times
82 -- bigger than the original source (in number of lines).
83
84 Alloc_Line_Tables
85 (S, Int (Source_File.Table (Source).Last_Source_Line * 3));
86 S.Lines_Table (1) := Loc;
87 end;
88 end Create_Debug_Source;
89
90 ----------------------
91 -- Write_Debug_Line --
92 ----------------------
93
94 procedure Write_Debug_Line (Str : String; Loc : in out Source_Ptr) is
95 S : Source_File_Record renames Source_File.Table (Dfile);
96
97 begin
98 -- Ignore write request if null line at start of file
99
100 if Str'Length = 0 and then Loc = S.Source_First then
101 return;
102
103 -- Here we write the line, and update the source record entry
104
105 else
106 Write_Debug_Info (Str (Str'First .. Str'Last - 1));
107 Add_Line_Tables_Entry (S, Loc);
108 Loc := Loc - 1 + Source_Ptr (Str'Length + Debug_File_Eol_Length);
109 S.Source_Last := Loc;
110 end if;
111 end Write_Debug_Line;
112
113 end Sinput.D;