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"
9 // This class implements the Linemap interface defined by the
12 class Gcc_linemap
: public Linemap
21 start_file(const char* file_name
, unsigned int line_begin
);
24 start_line(unsigned int line_number
, unsigned int line_size
);
27 get_location(unsigned int column
);
34 get_predeclared_location();
37 get_unknown_location();
40 is_predeclared(Location
);
46 // Whether we are currently reading a file.
50 Linemap
* Linemap::instance_
= NULL
;
52 // Start getting locations from a new file.
55 Gcc_linemap::start_file(const char *file_name
, unsigned line_begin
)
58 linemap_add(line_table
, LC_LEAVE
, 0, NULL
, 0);
59 linemap_add(line_table
, LC_ENTER
, 0, file_name
, line_begin
);
60 this->in_file_
= true;
63 // Stop getting locations.
68 linemap_add(line_table
, LC_LEAVE
, 0, NULL
, 0);
69 this->in_file_
= false;
75 Gcc_linemap::start_line(unsigned lineno
, unsigned linesize
)
77 linemap_line_start(line_table
, lineno
, linesize
);
83 Gcc_linemap::get_location(unsigned column
)
85 return Location(linemap_position_for_column(line_table
, column
));
88 // Get the unknown location.
91 Gcc_linemap::get_unknown_location()
93 return Location(UNKNOWN_LOCATION
);
96 // Get the predeclared location.
99 Gcc_linemap::get_predeclared_location()
101 return Location(BUILTINS_LOCATION
);
104 // Return whether a location is the predeclared location.
107 Gcc_linemap::is_predeclared(Location loc
)
109 return loc
.gcc_location() == BUILTINS_LOCATION
;
112 // Return whether a location is the unknown location.
115 Gcc_linemap::is_unknown(Location loc
)
117 return loc
.gcc_location() == UNKNOWN_LOCATION
;
120 // Return the Linemap to use for the gcc backend.
125 return new Gcc_linemap
;