@@ -133,18 +133,18 @@ const char *SourceManager::getCharacterData(SourceLocation SL) const {
133
133
// / getColumnNumber - Return the column # for the specified include position.
134
134
// / this is significantly cheaper to compute than the line number. This returns
135
135
// / zero if the column number isn't known.
136
- unsigned SourceManager::getColumnNumber (SourceLocation IncludePos ) const {
137
- unsigned FileID = IncludePos .getFileID ();
136
+ unsigned SourceManager::getColumnNumber (SourceLocation Loc ) const {
137
+ unsigned FileID = Loc .getFileID ();
138
138
if (FileID == 0 ) return 0 ;
139
139
140
140
// If this is a macro, we need to get the instantiation location.
141
141
const SrcMgr::FileIDInfo *FIDInfo = getFIDInfo (FileID);
142
142
if (FIDInfo->IDType == SrcMgr::FileIDInfo::MacroExpansion) {
143
- IncludePos = FIDInfo->IncludeLoc ;
144
- FileID = IncludePos .getFileID ();
143
+ Loc = FIDInfo->IncludeLoc ;
144
+ FileID = Loc .getFileID ();
145
145
}
146
146
147
- unsigned FilePos = getFilePos (IncludePos );
147
+ unsigned FilePos = getFilePos (Loc );
148
148
const SourceBuffer *Buffer = getBuffer (FileID);
149
149
const char *Buf = Buffer->getBufferStart ();
150
150
@@ -154,17 +154,35 @@ unsigned SourceManager::getColumnNumber(SourceLocation IncludePos) const {
154
154
return FilePos-LineStart+1 ;
155
155
}
156
156
157
+ // / getSourceName - This method returns the name of the file or buffer that
158
+ // / the SourceLocation specifies. This can be modified with #line directives,
159
+ // / etc.
160
+ std::string SourceManager::getSourceName (SourceLocation Loc) {
161
+ unsigned FileID = Loc.getFileID ();
162
+ if (FileID == 0 ) return " " ;
163
+
164
+ // If this is a macro, we need to get the instantiation location.
165
+ const SrcMgr::FileIDInfo *FIDInfo = getFIDInfo (FileID);
166
+ if (FIDInfo->IDType == SrcMgr::FileIDInfo::MacroExpansion) {
167
+ Loc = FIDInfo->IncludeLoc ;
168
+ FIDInfo = getFIDInfo (Loc.getFileID ());
169
+ }
170
+
171
+ return getFileInfo (FIDInfo)->Buffer ->getBufferIdentifier ();
172
+ }
173
+
174
+
157
175
// / getLineNumber - Given a SourceLocation, return the physical line number
158
176
// / for the position indicated. This requires building and caching a table of
159
177
// / line offsets for the SourceBuffer, so this is not cheap: use only when
160
178
// / about to emit a diagnostic.
161
- unsigned SourceManager::getLineNumber (SourceLocation IncludePos ) {
162
- unsigned FileID = IncludePos .getFileID ();
179
+ unsigned SourceManager::getLineNumber (SourceLocation Loc ) {
180
+ unsigned FileID = Loc .getFileID ();
163
181
// If this is a macro, we need to get the instantiation location.
164
182
const SrcMgr::FileIDInfo *FIDInfo = getFIDInfo (FileID);
165
183
if (FIDInfo->IDType == SrcMgr::FileIDInfo::MacroExpansion) {
166
- IncludePos = FIDInfo->IncludeLoc ;
167
- FileID = IncludePos .getFileID ();
184
+ Loc = FIDInfo->IncludeLoc ;
185
+ FileID = Loc .getFileID ();
168
186
FIDInfo = getFIDInfo (FileID);
169
187
}
170
188
@@ -226,7 +244,7 @@ unsigned SourceManager::getLineNumber(SourceLocation IncludePos) {
226
244
// type approaches to make good (tight?) initial guesses based on the
227
245
// assumption that all lines are the same average size.
228
246
unsigned *Pos = std::lower_bound (SourceLineCache, SourceLineCache+NumLines,
229
- getFilePos (IncludePos )+1 );
247
+ getFilePos (Loc )+1 );
230
248
return Pos-SourceLineCache;
231
249
}
232
250
0 commit comments