diff options
author | Chris Lattner <sabre@nondot.org> | 2009-02-04 05:33:01 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2009-02-04 05:33:01 +0000 |
commit | 95d9c5e7789d0fe214849fdaac6f3079266592aa (patch) | |
tree | 2b5b592031c01451a67187490490d5accbe536c5 /clang/lib/Basic/SourceManager.cpp | |
parent | 0a1a8d8514c80cd55f7c2c0c7886f71d842f24f8 (diff) | |
download | bcm5719-llvm-95d9c5e7789d0fe214849fdaac6f3079266592aa.tar.gz bcm5719-llvm-95d9c5e7789d0fe214849fdaac6f3079266592aa.zip |
make getFileCharacteristic linetable aware. line markers that
play around with the 'is system header' bit now function correctly.
llvm-svn: 63720
Diffstat (limited to 'clang/lib/Basic/SourceManager.cpp')
-rw-r--r-- | clang/lib/Basic/SourceManager.cpp | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/clang/lib/Basic/SourceManager.cpp b/clang/lib/Basic/SourceManager.cpp index 275d520e044..a77f8535e3c 100644 --- a/clang/lib/Basic/SourceManager.cpp +++ b/clang/lib/Basic/SourceManager.cpp @@ -82,6 +82,7 @@ struct LineEntry { E.FileOffset = Offs; E.LineNo = Line; E.FilenameID = Filename; + E.FileKind = FileKind; return E; } }; @@ -754,6 +755,37 @@ unsigned SourceManager::getSpellingLineNumber(SourceLocation Loc) const { return getLineNumber(LocInfo.first, LocInfo.second); } +/// getFileCharacteristic - return the file characteristic of the specified +/// source location, indicating whether this is a normal file, a system +/// header, or an "implicit extern C" system header. +/// +/// This state can be modified with flags on GNU linemarker directives like: +/// # 4 "foo.h" 3 +/// which changes all source locations in the current file after that to be +/// considered to be from a system header. +SrcMgr::CharacteristicKind +SourceManager::getFileCharacteristic(SourceLocation Loc) const { + assert(!Loc.isInvalid() && "Can't get file characteristic of invalid loc!"); + std::pair<FileID, unsigned> LocInfo = getDecomposedInstantiationLoc(Loc); + const SrcMgr::FileInfo &FI = getSLocEntry(LocInfo.first).getFile(); + + // If there are no #line directives in this file, just return the whole-file + // state. + if (!FI.hasLineDirectives()) + return FI.getFileCharacteristic(); + + assert(LineTable && "Can't have linetable entries without a LineTable!"); + // See if there is a #line directive before the location. + const LineEntry *Entry = + LineTable->FindNearestLineEntry(LocInfo.first.ID, LocInfo.second); + + // If this is before the first line marker, use the file characteristic. + if (!Entry) + return FI.getFileCharacteristic(); + + return Entry->FileKind; +} + /// getPresumedLoc - This method returns the "presumed" location of a /// SourceLocation specifies. A "presumed location" can be modified by #line |