diff options
author | Chandler Carruth <chandlerc@gmail.com> | 2011-12-09 01:33:57 +0000 |
---|---|---|
committer | Chandler Carruth <chandlerc@gmail.com> | 2011-12-09 01:33:57 +0000 |
commit | cb381eac84e5a14a8c7e7654eadbe1d3d54d795c (patch) | |
tree | 79354d3a59629119df845f6f1162b6a4baf72ee0 /lib | |
parent | 5a477dbf7589f516effe56fa2ed7d4680b5c1094 (diff) |
Move a free function from the Frontend library into the Lex library as
part of HeaderSearch. This function just normalizes filenames for use
inside of a synthetic include directive, but it is used in both the
Frontend and Serialization libraries so it needs a common home.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@146227 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Frontend/InitPreprocessor.cpp | 29 | ||||
-rw-r--r-- | lib/Lex/HeaderSearch.cpp | 23 | ||||
-rw-r--r-- | lib/Serialization/ASTReader.cpp | 4 |
3 files changed, 30 insertions, 26 deletions
diff --git a/lib/Frontend/InitPreprocessor.cpp b/lib/Frontend/InitPreprocessor.cpp index d0a87bd888..61d1748686 100644 --- a/lib/Frontend/InitPreprocessor.cpp +++ b/lib/Frontend/InitPreprocessor.cpp @@ -18,6 +18,7 @@ #include "clang/Frontend/FrontendDiagnostic.h" #include "clang/Frontend/FrontendOptions.h" #include "clang/Frontend/PreprocessorOptions.h" +#include "clang/Lex/HeaderSearch.h" #include "clang/Lex/Preprocessor.h" #include "clang/Basic/FileManager.h" #include "clang/Basic/SourceManager.h" @@ -48,39 +49,19 @@ static void DefineBuiltinMacro(MacroBuilder &Builder, StringRef Macro, } } -std::string clang::NormalizeDashIncludePath(StringRef File, - FileManager &FileMgr) { - // Implicit include paths should be resolved relative to the current - // working directory first, and then use the regular header search - // mechanism. The proper way to handle this is to have the - // predefines buffer located at the current working directory, but - // it has no file entry. For now, workaround this by using an - // absolute path if we find the file here, and otherwise letting - // header search handle it. - llvm::SmallString<128> Path(File); - llvm::sys::fs::make_absolute(Path); - bool exists; - if (llvm::sys::fs::exists(Path.str(), exists) || !exists) - Path = File; - else if (exists) - FileMgr.getFile(File); - - return Lexer::Stringify(Path.str()); -} - /// AddImplicitInclude - Add an implicit #include of the specified file to the /// predefines buffer. static void AddImplicitInclude(MacroBuilder &Builder, StringRef File, FileManager &FileMgr) { - Builder.append("#include \"" + - Twine(NormalizeDashIncludePath(File, FileMgr)) + "\""); + Builder.append(Twine("#include \"") + + HeaderSearch::NormalizeDashIncludePath(File, FileMgr) + "\""); } static void AddImplicitIncludeMacros(MacroBuilder &Builder, StringRef File, FileManager &FileMgr) { - Builder.append("#__include_macros \"" + - Twine(NormalizeDashIncludePath(File, FileMgr)) + "\""); + Builder.append(Twine("#__include_macros \"") + + HeaderSearch::NormalizeDashIncludePath(File, FileMgr) + "\""); // Marker token to stop the __include_macros fetch loop. Builder.append("##"); // ##? } diff --git a/lib/Lex/HeaderSearch.cpp b/lib/Lex/HeaderSearch.cpp index b0668c53a4..0071ff533c 100644 --- a/lib/Lex/HeaderSearch.cpp +++ b/lib/Lex/HeaderSearch.cpp @@ -13,6 +13,7 @@ #include "clang/Lex/HeaderSearch.h" #include "clang/Lex/HeaderMap.h" +#include "clang/Lex/Lexer.h" #include "clang/Basic/Diagnostic.h" #include "clang/Basic/FileManager.h" #include "clang/Basic/IdentifierTable.h" @@ -619,6 +620,28 @@ LookupSubframeworkHeader(StringRef Filename, return FE; } +/// \brief Helper static function to normalize a path for injection into +/// a synthetic header. +/*static*/ std::string +HeaderSearch::NormalizeDashIncludePath(StringRef File, FileManager &FileMgr) { + // Implicit include paths should be resolved relative to the current + // working directory first, and then use the regular header search + // mechanism. The proper way to handle this is to have the + // predefines buffer located at the current working directory, but + // it has no file entry. For now, workaround this by using an + // absolute path if we find the file here, and otherwise letting + // header search handle it. + llvm::SmallString<128> Path(File); + llvm::sys::fs::make_absolute(Path); + bool exists; + if (llvm::sys::fs::exists(Path.str(), exists) || !exists) + Path = File; + else if (exists) + FileMgr.getFile(File); + + return Lexer::Stringify(Path.str()); +} + //===----------------------------------------------------------------------===// // File Info Management. //===----------------------------------------------------------------------===// diff --git a/lib/Serialization/ASTReader.cpp b/lib/Serialization/ASTReader.cpp index 27dda857f5..c7393e4c78 100644 --- a/lib/Serialization/ASTReader.cpp +++ b/lib/Serialization/ASTReader.cpp @@ -17,7 +17,6 @@ #include "clang/Serialization/SerializationDiagnostic.h" #include "ASTCommon.h" #include "ASTReaderInternals.h" -#include "clang/Frontend/Utils.h" #include "clang/Sema/Sema.h" #include "clang/Sema/Scope.h" #include "clang/AST/ASTConsumer.h" @@ -195,7 +194,8 @@ bool PCHValidator::ReadPredefinesBuffer(const PCHPredefinesBlocks &Buffers, // below. llvm::SmallString<256> PCHInclude; PCHInclude += "#include \""; - PCHInclude += NormalizeDashIncludePath(OriginalFileName, FileMgr); + PCHInclude += HeaderSearch::NormalizeDashIncludePath(OriginalFileName, + FileMgr); PCHInclude += "\"\n"; std::pair<StringRef,StringRef> Split = StringRef(PP.getPredefines()).split(PCHInclude.str()); |