* gcc-interface/trans.c (node_has_volatile_full_access) <N_Identifier>:
[official-gcc.git] / gcc / go / gofrontend / go-linemap.h
blob704efdbfa53f92f6dc2e6ebea05312e19f3d70e0
1 // go-linemap.h -- interface to location tracking -*- C++ -*-
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 #ifndef GO_LINEMAP_H
8 #define GO_LINEMAP_H
10 #include "go-system.h"
12 // The backend must define a type named Location which holds
13 // information about a location in a source file. The only thing the
14 // frontend does with instances of Location is pass them back to the
15 // backend interface. The Location type must be assignable, and it
16 // must be comparable: i.e., it must support operator= and operator<.
17 // The type is normally passed by value rather than by reference, and
18 // it should support that efficiently. The type should be defined in
19 // "go-location.h".
20 #include "go-location.h"
22 // The Linemap class is a pure abstract interface, plus some static
23 // convenience functions. The backend must implement the interface.
25 class Linemap
27 public:
28 Linemap()
30 // Only one instance of Linemap is allowed to exist.
31 go_assert(Linemap::instance_ == NULL);
32 Linemap::instance_ = this;
35 virtual
36 ~Linemap() { Linemap::instance_ = NULL; }
38 // Subsequent Location values will come from the file named
39 // FILE_NAME, starting at LINE_BEGIN. Normally LINE_BEGIN will be
40 // 0, but it will be non-zero if the Go source has a //line comment.
41 virtual void
42 start_file(const char* file_name, unsigned int line_begin) = 0;
44 // Subsequent Location values will come from the line LINE_NUMBER,
45 // in the current file. LINE_SIZE is the size of the line in bytes.
46 // This will normally be called for every line in a source file.
47 virtual void
48 start_line(unsigned int line_number, unsigned int line_size) = 0;
50 // Get a Location representing column position COLUMN on the current
51 // line in the current file.
52 virtual Location
53 get_location(unsigned int column) = 0;
55 // Stop generating Location values. This will be called after all
56 // input files have been read, in case any cleanup is required.
57 virtual void
58 stop() = 0;
60 // Produce a human-readable description of a Location, e.g.
61 // "foo.go:10". Returns an empty string for predeclared, builtin or
62 // unknown locations.
63 virtual std::string
64 to_string(Location) = 0;
66 // Return the line number for a given location (for debugging dumps)
67 virtual int
68 location_line(Location) = 0;
70 protected:
71 // Return a special Location used for predeclared identifiers. This
72 // Location should be different from that for any actual source
73 // file. This location will be used for various different types,
74 // functions, and objects created by the frontend.
75 virtual Location
76 get_predeclared_location() = 0;
78 // Return a special Location which indicates that no actual location
79 // is known. This is used for undefined objects and for errors.
80 virtual Location
81 get_unknown_location() = 0;
83 // Return whether the argument is the Location returned by
84 // get_predeclared_location.
85 virtual bool
86 is_predeclared(Location) = 0;
88 // Return whether the argument is the Location returned by
89 // get_unknown_location.
90 virtual bool
91 is_unknown(Location) = 0;
93 // The single existing instance of Linemap.
94 static Linemap *instance_;
96 public:
97 // Following are convenience static functions, which allow us to
98 // access some virtual functions without explicitly passing around
99 // an instance of Linemap.
101 // Return the special Location used for predeclared identifiers.
102 static Location
103 predeclared_location()
105 go_assert(Linemap::instance_ != NULL);
106 return Linemap::instance_->get_predeclared_location();
109 // Return the special Location used when no location is known.
110 static Location
111 unknown_location()
113 go_assert(Linemap::instance_ != NULL);
114 return Linemap::instance_->get_unknown_location();
117 // Return whether the argument is the special location used for
118 // predeclared identifiers.
119 static bool
120 is_predeclared_location(Location loc)
122 go_assert(Linemap::instance_ != NULL);
123 return Linemap::instance_->is_predeclared(loc);
126 // Return whether the argument is the special location used when no
127 // location is known.
128 static bool
129 is_unknown_location(Location loc)
131 go_assert(Linemap::instance_ != NULL);
132 return Linemap::instance_->is_unknown(loc);
135 // Produce a human-readable description of a Location.
136 static std::string
137 location_to_string(Location loc)
139 go_assert(Linemap::instance_ != NULL);
140 return Linemap::instance_->to_string(loc);
143 // Return line number for location
144 static int
145 location_to_line(Location loc)
147 go_assert(Linemap::instance_ != NULL);
148 return Linemap::instance_->location_line(loc);
152 #endif // !defined(GO_LINEMAP_H)