File tree 2 files changed +19
-4
lines changed
2 files changed +19
-4
lines changed Original file line number Diff line number Diff line change @@ -159,7 +159,16 @@ unsigned SourceManager::getColumnNumber(SourceLocation IncludePos) const {
159
159
// / line offsets for the SourceBuffer, so this is not cheap: use only when
160
160
// / about to emit a diagnostic.
161
161
unsigned SourceManager::getLineNumber (SourceLocation IncludePos) {
162
- FileInfo *FileInfo = getFileInfo (IncludePos.getFileID ());
162
+ unsigned FileID = IncludePos.getFileID ();
163
+ // If this is a macro, we need to get the instantiation location.
164
+ const SrcMgr::FileIDInfo *FIDInfo = getFIDInfo (FileID);
165
+ if (FIDInfo->IDType == SrcMgr::FileIDInfo::MacroExpansion) {
166
+ IncludePos = FIDInfo->IncludeLoc ;
167
+ FileID = IncludePos.getFileID ();
168
+ FIDInfo = getFIDInfo (FileID);
169
+ }
170
+
171
+ FileInfo *FileInfo = getFileInfo (FileID);
163
172
164
173
// If this is the first use of line information for this buffer, compute the
165
174
// / SourceLineCache for it on demand.
Original file line number Diff line number Diff line change @@ -258,16 +258,22 @@ class SourceManager {
258
258
259
259
// / Return the InfoRec structure for the specified FileID. This is always the
260
260
// / physical reference for the ID.
261
- const SrcMgr::InfoRec *getInfoRec (unsigned FileID) const {
262
- const SrcMgr::FileIDInfo *FIDInfo = getFIDInfo (FileID);
263
-
261
+ const SrcMgr::InfoRec *getInfoRec (const SrcMgr::FileIDInfo *FIDInfo) const {
264
262
// For Macros, the physical loc is specified by the MacroTokenFileID.
265
263
if (FIDInfo->IDType == SrcMgr::FileIDInfo::MacroExpansion)
266
264
FIDInfo = &FileIDs[FIDInfo->u .MacroTokenFileID -1 ];
267
265
268
266
return FIDInfo->getNormalBufferInfo ();
269
267
}
268
+ const SrcMgr::InfoRec *getInfoRec (unsigned FileID) const {
269
+ return getInfoRec (getFIDInfo (FileID));
270
+ }
270
271
272
+ SrcMgr::FileInfo *getFileInfo (const SrcMgr::FileIDInfo *FIDInfo) const {
273
+ if (const SrcMgr::InfoRec *IR = getInfoRec (FIDInfo))
274
+ return const_cast <SrcMgr::FileInfo *>(&IR->second );
275
+ return 0 ;
276
+ }
271
277
SrcMgr::FileInfo *getFileInfo (unsigned FileID) const {
272
278
if (const SrcMgr::InfoRec *IR = getInfoRec (FileID))
273
279
return const_cast <SrcMgr::FileInfo *>(&IR->second );
You can’t perform that action at this time.
0 commit comments