diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/clang/Basic/SourceLocation.h | 57 | ||||
-rw-r--r-- | include/clang/Basic/SourceManager.h | 20 | ||||
-rw-r--r-- | include/clang/Driver/TextDiagnosticPrinter.h | 4 |
3 files changed, 58 insertions, 23 deletions
diff --git a/include/clang/Basic/SourceLocation.h b/include/clang/Basic/SourceLocation.h index 6da9a87ee3..31fbc0218b 100644 --- a/include/clang/Basic/SourceLocation.h +++ b/include/clang/Basic/SourceLocation.h @@ -133,6 +133,8 @@ public: /// ReadVal - Read a SourceLocation object from Bitcode. static SourceLocation ReadVal(llvm::Deserializer& D); + + void dump(const SourceManager &SM) const; }; inline bool operator==(const SourceLocation &LHS, const SourceLocation &RHS) { @@ -182,13 +184,13 @@ public: explicit FullSourceLoc(SourceLocation Loc, SourceManager &SM) : SourceLocation(Loc), SrcMgr(&SM) {} - SourceManager& getManager() { - assert (SrcMgr && "SourceManager is NULL."); + SourceManager &getManager() { + assert(SrcMgr && "SourceManager is NULL."); return *SrcMgr; } - const SourceManager& getManager() const { - assert (SrcMgr && "SourceManager is NULL."); + const SourceManager &getManager() const { + assert(SrcMgr && "SourceManager is NULL."); return *SrcMgr; } @@ -196,7 +198,6 @@ public: FullSourceLoc getInstantiationLoc() const; FullSourceLoc getSpellingLoc() const; - FullSourceLoc getIncludeLoc() const; unsigned getLineNumber() const; unsigned getColumnNumber() const; @@ -211,13 +212,11 @@ public: const llvm::MemoryBuffer* getBuffer() const; - const char* getSourceName() const; - bool isInSystemHeader() const; /// Prints information about this FullSourceLoc to stderr. Useful for /// debugging. - void dump() const; + void dump() const { SourceLocation::dump(*SrcMgr); } friend inline bool operator==(const FullSourceLoc &LHS, const FullSourceLoc &RHS) { @@ -231,7 +230,47 @@ public: } }; - + +/// PresumedLoc - This class represents an unpacked "presumed" location which +/// can be presented to the user. A 'presumed' location can be modified by +/// #line and GNU line marker directives and is always the instantiation point +/// of a normal location. +/// +/// You can get a PresumedLoc from a SourceLocation with SourceManager. +class PresumedLoc { + const char *Filename; + unsigned Line, Col; + SourceLocation IncludeLoc; +public: + PresumedLoc() : Filename(0) {} + PresumedLoc(const char *FN, unsigned Ln, unsigned Co, SourceLocation IL) + : Filename(FN), Line(Ln), Col(Co), IncludeLoc(IL) { + } + + /// isInvalid - Return true if this object is invalid or uninitialized. This + /// occurs when created with invalid source locations or when walking off + /// the top of a #include stack. + bool isInvalid() const { return Filename == 0; } + bool isValid() const { return Filename != 0; } + + /// getFilename - Return the presumed filename of this location. This can be + /// affected by #line etc. + const char *getFilename() const { return Filename; } + + /// getLine - Return the presumed line number of this location. This can be + /// affected by #line etc. + unsigned getLine() const { return Line; } + + /// getColumn - Return the presumed column number of this location. This can + /// not be affected by #line, but is packaged here for convenience. + unsigned getColumn() const { return Col; } + + /// getIncludeLoc - Return the presumed include location of this location. + /// This can be affected by GNU linemarker directives. + SourceLocation getIncludeLoc() const { return IncludeLoc; } +}; + + } // end namespace clang namespace llvm { diff --git a/include/clang/Basic/SourceManager.h b/include/clang/Basic/SourceManager.h index dab3badea2..a63ef79037 100644 --- a/include/clang/Basic/SourceManager.h +++ b/include/clang/Basic/SourceManager.h @@ -404,14 +404,6 @@ public: return SourceLocation::getFileLoc(FileOffset); } - /// getIncludeLoc - Return the location of the #include for the specified - /// SourceLocation. If this is a macro expansion, this transparently figures - /// out which file includes the file being expanded into. - SourceLocation getIncludeLoc(SourceLocation ID) const { - return getSLocEntry(getFileID(getInstantiationLoc(ID))) - .getFile().getIncludeLoc(); - } - /// Given a SourceLocation object, return the instantiation location /// referenced by the ID. SourceLocation getInstantiationLoc(SourceLocation Loc) const { @@ -518,10 +510,14 @@ public: return getSLocEntry(FID).getFile().getFileCharacteristic(); } - /// getSourceName - This method returns the name of the file or buffer that - /// the SourceLocation specifies. This can be modified with #line directives, - /// etc. - const char *getSourceName(SourceLocation Loc) const; + /// getPresumedLoc - This method returns the "presumed" location of a + /// SourceLocation specifies. A "presumed location" can be modified by #line + /// or GNU line marker directives. This provides a view on the data that a + /// user should see in diagnostics, for example. + /// + /// Note that a presumed location is always given as the instantiation point + /// of an instantiation location, not at the spelling location. + PresumedLoc getPresumedLoc(SourceLocation Loc) const; diff --git a/include/clang/Driver/TextDiagnosticPrinter.h b/include/clang/Driver/TextDiagnosticPrinter.h index 550c337b50..b49094dcb1 100644 --- a/include/clang/Driver/TextDiagnosticPrinter.h +++ b/include/clang/Driver/TextDiagnosticPrinter.h @@ -26,7 +26,7 @@ namespace clang { class SourceManager; class TextDiagnosticPrinter : public DiagnosticClient { - FullSourceLoc LastWarningLoc; + SourceLocation LastWarningLoc; FullSourceLoc LastLoc; llvm::raw_ostream &OS; bool ShowColumn; @@ -36,7 +36,7 @@ public: bool caretDiagnistics = true) : OS(os), ShowColumn(showColumn), CaretDiagnostics(caretDiagnistics) {} - void PrintIncludeStack(FullSourceLoc Pos); + void PrintIncludeStack(SourceLocation Loc, const SourceManager &SM); void HighlightRange(const SourceRange &R, const SourceManager& SrcMgr, |