diff options
author | Douglas Gregor <dgregor@apple.com> | 2012-11-30 21:58:49 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2012-11-30 21:58:49 +0000 |
commit | 6c3254316de2d0d554b19702f4b10117ae46b77b (patch) | |
tree | 41958990afe0593fe4a41235e59999f0ffb2f08d /include/clang | |
parent | bbe89d5670b458fc1e2fff49e96e119ffb1622c8 (diff) |
When we're emitting a diagnostic with a source location in an imported
module, provide a module import stack similar to what we would get for
an include stack, e.g.,
In module 'DependsOnModule' imported from build-fail-notes.m:4:
In module 'Module' imported from DependsOnModule.framework/Headers/DependsOnModule.h:1:
Inputs/Module.framework/Headers/Module.h:15:12: note: previous definition is here
@interface Module
<rdar://problem/12696425>
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@169042 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/clang')
-rw-r--r-- | include/clang/Basic/SourceManager.h | 20 | ||||
-rw-r--r-- | include/clang/Frontend/DiagnosticRenderer.h | 15 | ||||
-rw-r--r-- | include/clang/Frontend/TextDiagnostic.h | 4 | ||||
-rw-r--r-- | include/clang/Serialization/ASTReader.h | 4 |
4 files changed, 41 insertions, 2 deletions
diff --git a/include/clang/Basic/SourceManager.h b/include/clang/Basic/SourceManager.h index bd31c79ba2..d79cbfe5ae 100644 --- a/include/clang/Basic/SourceManager.h +++ b/include/clang/Basic/SourceManager.h @@ -430,6 +430,11 @@ public: /// \returns true if an error occurred that prevented the source-location /// entry from being loaded. virtual bool ReadSLocEntry(int ID) = 0; + + /// \brief Retrieve the module import location and name for the given ID, if + /// in fact it was loaded from a module (rather than, say, a precompiled + /// header). + virtual std::pair<SourceLocation, StringRef> getModuleImportLoc(int ID) = 0; }; @@ -990,6 +995,21 @@ public: return Entry.getFile().getIncludeLoc(); } + // \brief Returns the import location if the given source location is + // located within a module, or an invalid location if the source location + // is within the current translation unit. + std::pair<SourceLocation, StringRef> + getModuleImportLoc(SourceLocation Loc) const { + FileID FID = getFileID(Loc); + + // Positive file IDs are in the current translation unit, and -1 is a + // placeholder. + if (FID.ID >= -1) + return std::make_pair(SourceLocation(), ""); + + return ExternalSLocEntries->getModuleImportLoc(FID.ID); + } + /// \brief Given a SourceLocation object \p Loc, return the expansion /// location referenced by the ID. SourceLocation getExpansionLoc(SourceLocation Loc) const { diff --git a/include/clang/Frontend/DiagnosticRenderer.h b/include/clang/Frontend/DiagnosticRenderer.h index 6ca8d89ec9..f46eb5c500 100644 --- a/include/clang/Frontend/DiagnosticRenderer.h +++ b/include/clang/Frontend/DiagnosticRenderer.h @@ -19,6 +19,7 @@ #include "clang/Basic/Diagnostic.h" #include "clang/Basic/LLVM.h" #include "clang/Basic/SourceLocation.h" +#include "llvm/ADT/Optional.h" #include "llvm/ADT/PointerUnion.h" namespace clang { @@ -92,6 +93,9 @@ protected: virtual void emitIncludeLocation(SourceLocation Loc, PresumedLoc PLoc, const SourceManager &SM) = 0; + virtual void emitImportLocation(SourceLocation Loc, PresumedLoc PLoc, + StringRef ModuleName, + const SourceManager &SM) = 0; virtual void emitBuildingModuleLocation(SourceLocation Loc, PresumedLoc PLoc, StringRef ModuleName, const SourceManager &SM) = 0; @@ -103,9 +107,12 @@ protected: private: - void emitIncludeStack(SourceLocation Loc, DiagnosticsEngine::Level Level, - const SourceManager &SM); + void emitIncludeStack(SourceLocation Loc, PresumedLoc PLoc, + DiagnosticsEngine::Level Level, const SourceManager &SM); void emitIncludeStackRecursively(SourceLocation Loc, const SourceManager &SM); + void emitImportStack(SourceLocation Loc, const SourceManager &SM); + void emitImportStackRecursively(SourceLocation Loc, StringRef ModuleName, + const SourceManager &SM); void emitModuleBuildPath(const SourceManager &SM); void emitMacroExpansionsAndCarets(SourceLocation Loc, DiagnosticsEngine::Level Level, @@ -154,6 +161,10 @@ public: PresumedLoc PLoc, const SourceManager &SM); + virtual void emitImportLocation(SourceLocation Loc, PresumedLoc PLoc, + StringRef ModuleName, + const SourceManager &SM); + virtual void emitBuildingModuleLocation(SourceLocation Loc, PresumedLoc PLoc, StringRef ModuleName, const SourceManager &SM); diff --git a/include/clang/Frontend/TextDiagnostic.h b/include/clang/Frontend/TextDiagnostic.h index 859bec2cfe..bce4e05efc 100644 --- a/include/clang/Frontend/TextDiagnostic.h +++ b/include/clang/Frontend/TextDiagnostic.h @@ -103,6 +103,10 @@ protected: virtual void emitIncludeLocation(SourceLocation Loc, PresumedLoc PLoc, const SourceManager &SM); + virtual void emitImportLocation(SourceLocation Loc, PresumedLoc PLoc, + StringRef ModuleName, + const SourceManager &SM); + virtual void emitBuildingModuleLocation(SourceLocation Loc, PresumedLoc PLoc, StringRef ModuleName, const SourceManager &SM); diff --git a/include/clang/Serialization/ASTReader.h b/include/clang/Serialization/ASTReader.h index 6b3c4f107f..d51917fcb1 100644 --- a/include/clang/Serialization/ASTReader.h +++ b/include/clang/Serialization/ASTReader.h @@ -1546,6 +1546,10 @@ public: /// \brief Read the source location entry with index ID. virtual bool ReadSLocEntry(int ID); + /// \brief Retrieve the module import location and module name for the + /// given source manager entry ID. + virtual std::pair<SourceLocation, StringRef> getModuleImportLoc(int ID); + /// \brief Retrieve the global submodule ID given a module and its local ID /// number. serialization::SubmoduleID |