OSDN Git Service

Daily bump.
[pf3gnuchains/gcc-fork.git] / gcc / go / go-linemap.cc
1 // go-linemap.cc -- GCC implementation of Linemap.
2
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.
6
7 #include "go-linemap.h"
8
9 // This class implements the Linemap interface defined by the
10 // frontend.
11
12 class Gcc_linemap : public Linemap
13 {
14  public:
15   Gcc_linemap()
16     : Linemap(),
17       in_file_(false)
18   { }
19
20   void
21   start_file(const char* file_name, unsigned int line_begin);
22
23   void
24   start_line(unsigned int line_number, unsigned int line_size);
25
26   Location
27   get_location(unsigned int column);
28
29   void
30   stop();
31
32  protected:
33   Location
34   get_predeclared_location();
35
36   Location
37   get_unknown_location();
38
39   bool
40   is_predeclared(Location);
41
42   bool
43   is_unknown(Location);
44
45  private:
46   // Whether we are currently reading a file.
47   bool in_file_;
48 };
49
50 Linemap* Linemap::instance_ = NULL;
51
52 // Start getting locations from a new file.
53
54 void
55 Gcc_linemap::start_file(const char *file_name, unsigned line_begin)
56 {
57   if (this->in_file_)
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;
61 }
62
63 // Stop getting locations.
64
65 void
66 Gcc_linemap::stop()
67 {
68   linemap_add(line_table, LC_LEAVE, 0, NULL, 0);
69   this->in_file_ = false;
70 }
71
72 // Start a new line.
73
74 void
75 Gcc_linemap::start_line(unsigned lineno, unsigned linesize)
76 {
77   linemap_line_start(line_table, lineno, linesize);
78 }
79
80 // Get a location.
81
82 Location
83 Gcc_linemap::get_location(unsigned column)
84 {
85   return Location(linemap_position_for_column(line_table, column));
86 }
87
88 // Get the unknown location.
89
90 Location
91 Gcc_linemap::get_unknown_location()
92 {
93   return Location(UNKNOWN_LOCATION);
94 }
95
96 // Get the predeclared location.
97
98 Location
99 Gcc_linemap::get_predeclared_location()
100 {
101   return Location(BUILTINS_LOCATION);
102 }
103
104 // Return whether a location is the predeclared location.
105
106 bool
107 Gcc_linemap::is_predeclared(Location loc)
108 {
109   return loc.gcc_location() == BUILTINS_LOCATION;
110 }
111
112 // Return whether a location is the unknown location.
113
114 bool
115 Gcc_linemap::is_unknown(Location loc)
116 {
117   return loc.gcc_location() == UNKNOWN_LOCATION;
118 }
119
120 // Return the Linemap to use for the gcc backend.
121
122 Linemap*
123 go_get_linemap()
124 {
125   return new Gcc_linemap;
126 }