/
sourcelocation_gen.go
208 lines (183 loc) · 6.95 KB
/
sourcelocation_gen.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
package clang
// #include "./clang-c/Index.h"
// #include "go-clang.h"
import "C"
// SourceLocation identifies a specific source location within a translation
// unit.
//
// Use clang_getExpansionLocation() or clang_getSpellingLocation()
// to map a source location to a particular file, line, and column.
type SourceLocation struct {
c C.CXSourceLocation
}
// GetNullLocation retrieve a NULL (invalid) source location.
func NewNullLocation() SourceLocation {
return SourceLocation{C.clang_getNullLocation()}
}
// EqualLocations determine whether two source locations, which must refer into
// the same translation unit, refer to exactly the same point in the source
// code.
//
// Returns non-zero if the source locations refer to the same location, zero
// if they refer to different locations.
func (sl SourceLocation) Equal(sl2 SourceLocation) bool {
o := C.clang_equalLocations(sl.c, sl2.c)
return o != C.uint(0)
}
// IsInSystemHeader returns non-zero if the given source location is in a system header.
func (sl SourceLocation) IsInSystemHeader() bool {
o := C.clang_Location_isInSystemHeader(sl.c)
return o != C.int(0)
}
// IsFromMainFile returns non-zero if the given source location is in the main file of the corresponding translation unit.
func (sl SourceLocation) IsFromMainFile() bool {
o := C.clang_Location_isFromMainFile(sl.c)
return o != C.int(0)
}
// GetRange retrieve a source range given the beginning and ending source locations.
func (sl SourceLocation) Range(end SourceLocation) SourceRange {
return SourceRange{C.clang_getRange(sl.c, end.c)}
}
// GetExpansionLocation retrieve the file, line, column, and offset represented by
// the given source location.
//
// If the location refers into a macro expansion, retrieves the
// location of the macro expansion.
//
// Parameter location the location within a source file that will be decomposed
// into its parts.
//
// Parameter file [out] if non-NULL, will be set to the file to which the given
// source location points.
//
// Parameter line [out] if non-NULL, will be set to the line to which the given
// source location points.
//
// Parameter column [out] if non-NULL, will be set to the column to which the given
// source location points.
//
// Parameter offset [out] if non-NULL, will be set to the offset into the
// buffer to which the given source location points.
func (sl SourceLocation) ExpansionLocation() (File, uint32, uint32, uint32) {
var file File
var line C.uint
var column C.uint
var offset C.uint
C.clang_getExpansionLocation(sl.c, &file.c, &line, &column, &offset)
return file, uint32(line), uint32(column), uint32(offset)
}
// GetPresumedLocation retrieve the file, line and column represented by the given source
// location, as specified in a # line directive.
//
// Example: given the following source code in a file somefile.c
//
// #123 "dummy.c" 1
//
// static int func(void)
// {
// return 0;
// }
//
// the location information returned by this function would be
//
// File: dummy.c Line: 124 Column: 12
//
// whereas clang_getExpansionLocation would have returned
//
// File: somefile.c Line: 3 Column: 12
//
// Parameter location the location within a source file that will be decomposed
// into its parts.
//
// Parameter filename [out] if non-NULL, will be set to the filename of the
// source location. Note that filenames returned will be for "virtual" files,
// which don't necessarily exist on the machine running clang - e.g. when
// parsing preprocessed output obtained from a different environment. If
// a non-NULL value is passed in, remember to dispose of the returned value
// using clang_disposeString() once you've finished with it. For an invalid
// source location, an empty string is returned.
//
// Parameter line [out] if non-NULL, will be set to the line number of the
// source location. For an invalid source location, zero is returned.
//
// Parameter column [out] if non-NULL, will be set to the column number of the
// source location. For an invalid source location, zero is returned.
func (sl SourceLocation) PresumedLocation() (string, uint32, uint32) {
var filename cxstring
defer filename.Dispose()
var line C.uint
var column C.uint
C.clang_getPresumedLocation(sl.c, &filename.c, &line, &column)
return filename.String(), uint32(line), uint32(column)
}
// GetInstantiationLocation legacy API to retrieve the file, line, column, and offset represented
// by the given source location.
//
// This interface has been replaced by the newer interface
// #clang_getExpansionLocation(). See that interface's documentation for
// details.
func (sl SourceLocation) InstantiationLocation() (File, uint32, uint32, uint32) {
var file File
var line C.uint
var column C.uint
var offset C.uint
C.clang_getInstantiationLocation(sl.c, &file.c, &line, &column, &offset)
return file, uint32(line), uint32(column), uint32(offset)
}
// GetSpellingLocation retrieve the file, line, column, and offset represented by
// the given source location.
//
// If the location refers into a macro instantiation, return where the
// location was originally spelled in the source file.
//
// Parameter location the location within a source file that will be decomposed
// into its parts.
//
// Parameter file [out] if non-NULL, will be set to the file to which the given
// source location points.
//
// Parameter line [out] if non-NULL, will be set to the line to which the given
// source location points.
//
// Parameter column [out] if non-NULL, will be set to the column to which the given
// source location points.
//
// Parameter offset [out] if non-NULL, will be set to the offset into the
// buffer to which the given source location points.
func (sl SourceLocation) SpellingLocation() (File, uint32, uint32, uint32) {
var file File
var line C.uint
var column C.uint
var offset C.uint
C.clang_getSpellingLocation(sl.c, &file.c, &line, &column, &offset)
return file, uint32(line), uint32(column), uint32(offset)
}
// GetFileLocation retrieve the file, line, column, and offset represented by
// the given source location.
//
// If the location refers into a macro expansion, return where the macro was
// expanded or where the macro argument was written, if the location points at
// a macro argument.
//
// Parameter location the location within a source file that will be decomposed
// into its parts.
//
// Parameter file [out] if non-NULL, will be set to the file to which the given
// source location points.
//
// Parameter line [out] if non-NULL, will be set to the line to which the given
// source location points.
//
// Parameter column [out] if non-NULL, will be set to the column to which the given
// source location points.
//
// Parameter offset [out] if non-NULL, will be set to the offset into the
// buffer to which the given source location points.
func (sl SourceLocation) FileLocation() (File, uint32, uint32, uint32) {
var file File
var line C.uint
var column C.uint
var offset C.uint
C.clang_getFileLocation(sl.c, &file.c, &line, &column, &offset)
return file, uint32(line), uint32(column), uint32(offset)
}