1 // go-linemap.cc -- GCC implementation of Linemap.
3 // Copyright 2011 The Go Authors. All rights reserved.
4 // Use of this source code is governed by a BSD-style
5 // license that can be found in the LICENSE file.
7 #include "go-linemap.h"
11 // This class implements the Linemap interface defined by the
14 class Gcc_linemap
: public Linemap
23 start_file(const char* file_name
, unsigned int line_begin
);
26 start_line(unsigned int line_number
, unsigned int line_size
);
29 get_location(unsigned int column
);
38 location_line(Location
);
42 get_predeclared_location();
45 get_unknown_location();
48 is_predeclared(Location
);
54 // Whether we are currently reading a file.
58 Linemap
* Linemap::instance_
= NULL
;
60 // Start getting locations from a new file.
63 Gcc_linemap::start_file(const char *file_name
, unsigned line_begin
)
66 linemap_add(line_table
, LC_LEAVE
, 0, NULL
, 0);
67 linemap_add(line_table
, LC_ENTER
, 0, file_name
, line_begin
);
68 this->in_file_
= true;
71 // Stringify a location
74 Gcc_linemap::to_string(Location location
)
76 const line_map_ordinary
*lmo
;
77 source_location resolved_location
;
79 // Screen out unknown and predeclared locations; produce output
80 // only for simple file:line locations.
82 linemap_resolve_location (line_table
, location
.gcc_location(),
83 LRK_SPELLING_LOCATION
, &lmo
);
84 if (lmo
== NULL
|| resolved_location
< RESERVED_LOCATION_COUNT
)
86 const char *path
= LINEMAP_FILE (lmo
);
90 // Strip the source file down to the base file, to reduce clutter.
92 ss
<< lbasename(path
) << ":" << SOURCE_LINE (lmo
, location
.gcc_location());
96 // Return the line number for a given location (for debugging dumps)
98 Gcc_linemap::location_line(Location loc
)
100 return LOCATION_LINE(loc
.gcc_location());
103 // Stop getting locations.
108 linemap_add(line_table
, LC_LEAVE
, 0, NULL
, 0);
109 this->in_file_
= false;
115 Gcc_linemap::start_line(unsigned lineno
, unsigned linesize
)
117 linemap_line_start(line_table
, lineno
, linesize
);
123 Gcc_linemap::get_location(unsigned column
)
125 return Location(linemap_position_for_column(line_table
, column
));
128 // Get the unknown location.
131 Gcc_linemap::get_unknown_location()
133 return Location(UNKNOWN_LOCATION
);
136 // Get the predeclared location.
139 Gcc_linemap::get_predeclared_location()
141 return Location(BUILTINS_LOCATION
);
144 // Return whether a location is the predeclared location.
147 Gcc_linemap::is_predeclared(Location loc
)
149 return loc
.gcc_location() == BUILTINS_LOCATION
;
152 // Return whether a location is the unknown location.
155 Gcc_linemap::is_unknown(Location loc
)
157 return loc
.gcc_location() == UNKNOWN_LOCATION
;
160 // Return the Linemap to use for the gcc backend.
165 return new Gcc_linemap
;