diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2016-04-27 21:57:05 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2016-04-27 21:57:05 +0000 |
commit | 4eb8393c636b5525ac92ee0ac8efcf263e0a2541 (patch) | |
tree | 4e85116ed26bc9b32d45f3fc6002ec97899023b2 /clang/include | |
parent | 575ad8c2e13d6099f67d9d5e816fad8968c6e900 (diff) | |
download | bcm5719-llvm-4eb8393c636b5525ac92ee0ac8efcf263e0a2541.tar.gz bcm5719-llvm-4eb8393c636b5525ac92ee0ac8efcf263e0a2541.zip |
[modules] When diagnosing a missing module import, suggest adding a #include if
the current language doesn't have an import syntax and we can figure out a
suitable file to include.
llvm-svn: 267802
Diffstat (limited to 'clang/include')
-rw-r--r-- | clang/include/clang/Basic/DiagnosticSemaKinds.td | 4 | ||||
-rw-r--r-- | clang/include/clang/Lex/HeaderSearch.h | 11 | ||||
-rw-r--r-- | clang/include/clang/Lex/ModuleMap.h | 6 | ||||
-rw-r--r-- | clang/include/clang/Lex/Preprocessor.h | 13 |
4 files changed, 31 insertions, 3 deletions
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index 4e2a0349645..afa741077c3 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -8262,6 +8262,10 @@ def err_module_private_local_class : Error< def err_module_unimported_use : Error< "%select{declaration|definition|default argument}0 of %1 must be imported " "from module '%2' before it is required">; +def err_module_unimported_use_header : Error< + "missing '#include %3'; " + "%select{declaration|definition|default argument}0 of %1 must be imported " + "from module '%2' before it is required">; def err_module_unimported_use_multiple : Error< "%select{declaration|definition|default argument}0 of %1 must be imported " "from one of the following modules before it is required:%2">; diff --git a/clang/include/clang/Lex/HeaderSearch.h b/clang/include/clang/Lex/HeaderSearch.h index 6d592e19c06..458f07e5e44 100644 --- a/clang/include/clang/Lex/HeaderSearch.h +++ b/clang/include/clang/Lex/HeaderSearch.h @@ -634,13 +634,18 @@ public: /// \brief Retrieve a uniqued framework name. StringRef getUniqueFrameworkName(StringRef Framework); + /// \brief Suggest a path by which the specified file could be found, for + /// use in diagnostics to suggest a #include. + /// + /// \param IsSystem If non-null, filled in to indicate whether the suggested + /// path is relative to a system header directory. + std::string suggestPathToFileForDiagnostics(const FileEntry *File, + bool *IsSystem = nullptr); + void PrintStats(); size_t getTotalMemory() const; - static std::string NormalizeDashIncludePath(StringRef File, - FileManager &FileMgr); - private: /// \brief Describes what happened when we tried to load a module map file. enum LoadModuleMapResult { diff --git a/clang/include/clang/Lex/ModuleMap.h b/clang/include/clang/Lex/ModuleMap.h index d8d374b622b..b8cfb8faa8d 100644 --- a/clang/include/clang/Lex/ModuleMap.h +++ b/clang/include/clang/Lex/ModuleMap.h @@ -130,6 +130,12 @@ public: return getModule()->isAvailable(); } + /// \brief Whether this header is accessible from the specified module. + bool isAccessibleFrom(Module *M) const { + return !(getRole() & PrivateHeader) || + (M && M->getTopLevelModule() == getModule()->getTopLevelModule()); + } + // \brief Whether this known header is valid (i.e., it has an // associated module). explicit operator bool() const { diff --git a/clang/include/clang/Lex/Preprocessor.h b/clang/include/clang/Lex/Preprocessor.h index 817c09fcdbc..30cc37f6f88 100644 --- a/clang/include/clang/Lex/Preprocessor.h +++ b/clang/include/clang/Lex/Preprocessor.h @@ -1891,6 +1891,19 @@ public: /// directly or indirectly. Module *getModuleContainingLocation(SourceLocation Loc); + /// \brief We want to produce a diagnostic at location IncLoc concerning a + /// missing module import. + /// + /// \param IncLoc The location at which the missing import was detected. + /// \param MLoc A location within the desired module at which some desired + /// effect occurred (eg, where a desired entity was declared). + /// + /// \return A file that can be #included to import a module containing MLoc. + /// Null if no such file could be determined or if a #include is not + /// appropriate. + const FileEntry *getModuleHeaderToIncludeForDiagnostics(SourceLocation IncLoc, + SourceLocation MLoc); + private: // Macro handling. void HandleDefineDirective(Token &Tok, bool ImmediatelyAfterTopLevelIfndef); |