[cfe-commits] r146227 - in /cfe/trunk: include/clang/Frontend/Utils.h include/clang/Lex/HeaderSearch.h lib/Frontend/InitPreprocessor.cpp lib/Lex/HeaderSearch.cpp lib/Serialization/ASTReader.cpp

Chandler Carruth chandlerc at gmail.com
Thu Dec 8 17:33:57 PST 2011


Author: chandlerc
Date: Thu Dec  8 19:33:57 2011
New Revision: 146227

URL: http://llvm.org/viewvc/llvm-project?rev=146227&view=rev
Log:
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.

Modified:
    cfe/trunk/include/clang/Frontend/Utils.h
    cfe/trunk/include/clang/Lex/HeaderSearch.h
    cfe/trunk/lib/Frontend/InitPreprocessor.cpp
    cfe/trunk/lib/Lex/HeaderSearch.cpp
    cfe/trunk/lib/Serialization/ASTReader.cpp

Modified: cfe/trunk/include/clang/Frontend/Utils.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/Utils.h?rev=146227&r1=146226&r2=146227&view=diff
==============================================================================
--- cfe/trunk/include/clang/Frontend/Utils.h (original)
+++ cfe/trunk/include/clang/Frontend/Utils.h Thu Dec  8 19:33:57 2011
@@ -46,11 +46,6 @@
 class TargetInfo;
 class FrontendOptions;
 
-/// Normalize \arg File for use in a user defined #include directive (in the
-/// predefines buffer).
-std::string NormalizeDashIncludePath(StringRef File,
-                                     FileManager &FileMgr);
-
 /// Apply the header search options to get given HeaderSearch object.
 void ApplyHeaderSearchOptions(HeaderSearch &HS,
                               const HeaderSearchOptions &HSOpts,

Modified: cfe/trunk/include/clang/Lex/HeaderSearch.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/HeaderSearch.h?rev=146227&r1=146226&r2=146227&view=diff
==============================================================================
--- cfe/trunk/include/clang/Lex/HeaderSearch.h (original)
+++ cfe/trunk/include/clang/Lex/HeaderSearch.h Thu Dec  8 19:33:57 2011
@@ -448,6 +448,9 @@
   
   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 {

Modified: cfe/trunk/lib/Frontend/InitPreprocessor.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/InitPreprocessor.cpp?rev=146227&r1=146226&r2=146227&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/InitPreprocessor.cpp (original)
+++ cfe/trunk/lib/Frontend/InitPreprocessor.cpp Thu Dec  8 19:33:57 2011
@@ -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 @@
   }
 }
 
-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("##"); // ##?
 }

Modified: cfe/trunk/lib/Lex/HeaderSearch.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/HeaderSearch.cpp?rev=146227&r1=146226&r2=146227&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/HeaderSearch.cpp (original)
+++ cfe/trunk/lib/Lex/HeaderSearch.cpp Thu Dec  8 19:33:57 2011
@@ -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 @@
   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.
 //===----------------------------------------------------------------------===//

Modified: cfe/trunk/lib/Serialization/ASTReader.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReader.cpp?rev=146227&r1=146226&r2=146227&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTReader.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReader.cpp Thu Dec  8 19:33:57 2011
@@ -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 @@
   // 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());





More information about the cfe-commits mailing list