@@ -61,10 +61,9 @@ class SourceMgr {
61
61
// / into relatively small files (often smaller than 2^8 or 2^16 bytes),
62
62
// / we select the offset vector element type dynamically based on the
63
63
// / size of Buffer.
64
- using VariableSizeOffsets = PointerUnion<std::vector<uint8_t > *,
65
- std::vector<uint16_t > *,
66
- std::vector<uint32_t > *,
67
- std::vector<uint64_t > *>;
64
+ using VariableSizeOffsets =
65
+ PointerUnion<std::vector<uint8_t > *, std::vector<uint16_t > *,
66
+ std::vector<uint32_t > *, std::vector<uint64_t > *>;
68
67
69
68
// / Vector of offsets into Buffer at which there are line-endings
70
69
// / (lazily populated). Once populated, the '\n' that marks the end of
@@ -74,12 +73,17 @@ class SourceMgr {
74
73
// / offset corresponding to a particular SMLoc).
75
74
mutable VariableSizeOffsets OffsetCache;
76
75
77
- // / Populate \c OffsetCache and look up a given \p Ptr in it, assuming
78
- // / it points somewhere into \c Buffer. The static type parameter \p T
79
- // / must be an unsigned integer type from uint{8,16,32,64}_t large
80
- // / enough to store offsets inside \c Buffer.
81
- template <typename T>
76
+ // / Look up a given \p Ptr in in the buffer, determining which line it came
77
+ // / from.
82
78
unsigned getLineNumber (const char *Ptr ) const ;
79
+ template <typename T>
80
+ unsigned getLineNumberSpecialized (const char *Ptr ) const ;
81
+
82
+ // / Return a pointer to the first character of the specified line number or
83
+ // / null if the line number is invalid.
84
+ const char *getPointerForLineNumber (unsigned LineNo) const ;
85
+ template <typename T>
86
+ const char *getPointerForLineNumberSpecialized (unsigned LineNo) const ;
83
87
84
88
// / This is the location of the parent include, or null if at the top level.
85
89
SMLoc IncludeLoc;
@@ -134,9 +138,7 @@ class SourceMgr {
134
138
return Buffers[i - 1 ].Buffer .get ();
135
139
}
136
140
137
- unsigned getNumBuffers () const {
138
- return Buffers.size ();
139
- }
141
+ unsigned getNumBuffers () const { return Buffers.size (); }
140
142
141
143
unsigned getMainFileID () const {
142
144
assert (getNumBuffers ());
@@ -184,12 +186,16 @@ class SourceMgr {
184
186
std::pair<unsigned , unsigned > getLineAndColumn (SMLoc Loc,
185
187
unsigned BufferID = 0 ) const ;
186
188
189
+ // / Given a line and column number in a mapped buffer, turn it into an SMLoc.
190
+ // / This will return a null SMLoc if the line/column location is invalid.
191
+ SMLoc FindLocForLineAndColumn (unsigned BufferID, unsigned LineNo,
192
+ unsigned ColNo);
193
+
187
194
// / Emit a message about the specified location with the specified string.
188
195
// /
189
196
// / \param ShowColors Display colored messages if output is a terminal and
190
197
// / the default error handler is used.
191
- void PrintMessage (raw_ostream &OS, SMLoc Loc, DiagKind Kind,
192
- const Twine &Msg,
198
+ void PrintMessage (raw_ostream &OS, SMLoc Loc, DiagKind Kind, const Twine &Msg,
193
199
ArrayRef<SMRange> Ranges = None,
194
200
ArrayRef<SMFixIt> FixIts = None,
195
201
bool ShowColors = true ) const ;
@@ -234,13 +240,13 @@ class SMFixIt {
234
240
public:
235
241
// FIXME: Twine.str() is not very efficient.
236
242
SMFixIt (SMLoc Loc, const Twine &Insertion)
237
- : Range(Loc, Loc), Text(Insertion.str()) {
243
+ : Range(Loc, Loc), Text(Insertion.str()) {
238
244
assert (Loc.isValid ());
239
245
}
240
246
241
247
// FIXME: Twine.str() is not very efficient.
242
248
SMFixIt (SMRange R, const Twine &Replacement)
243
- : Range(R), Text(Replacement.str()) {
249
+ : Range(R), Text(Replacement.str()) {
244
250
assert (R.isValid ());
245
251
}
246
252
@@ -274,13 +280,12 @@ class SMDiagnostic {
274
280
SMDiagnostic () = default ;
275
281
// Diagnostic with no location (e.g. file not found, command line arg error).
276
282
SMDiagnostic (StringRef filename, SourceMgr::DiagKind Knd, StringRef Msg)
277
- : Filename(filename), LineNo(-1 ), ColumnNo(-1 ), Kind(Knd), Message(Msg) {}
283
+ : Filename(filename), LineNo(-1 ), ColumnNo(-1 ), Kind(Knd), Message(Msg) {}
278
284
279
285
// Diagnostic with a location.
280
- SMDiagnostic (const SourceMgr &sm, SMLoc L, StringRef FN,
281
- int Line, int Col, SourceMgr::DiagKind Kind,
282
- StringRef Msg, StringRef LineStr,
283
- ArrayRef<std::pair<unsigned ,unsigned >> Ranges,
286
+ SMDiagnostic (const SourceMgr &sm, SMLoc L, StringRef FN, int Line, int Col,
287
+ SourceMgr::DiagKind Kind, StringRef Msg, StringRef LineStr,
288
+ ArrayRef<std::pair<unsigned , unsigned >> Ranges,
284
289
ArrayRef<SMFixIt> FixIts = None);
285
290
286
291
const SourceMgr *getSourceMgr () const { return SM; }
@@ -293,13 +298,9 @@ class SMDiagnostic {
293
298
StringRef getLineContents () const { return LineContents; }
294
299
ArrayRef<std::pair<unsigned , unsigned >> getRanges () const { return Ranges; }
295
300
296
- void addFixIt (const SMFixIt &Hint) {
297
- FixIts.push_back (Hint);
298
- }
301
+ void addFixIt (const SMFixIt &Hint) { FixIts.push_back (Hint); }
299
302
300
- ArrayRef<SMFixIt> getFixIts () const {
301
- return FixIts;
302
- }
303
+ ArrayRef<SMFixIt> getFixIts () const { return FixIts; }
303
304
304
305
void print (const char *ProgName, raw_ostream &S, bool ShowColors = true ,
305
306
bool ShowKindLabel = true ) const ;
0 commit comments