]> granicus.if.org Git - clang/commitdiff
Add HeaderSearchOptions class, for packaging the information needed to
authorDaniel Dunbar <daniel@zuster.org>
Sat, 7 Nov 2009 04:20:50 +0000 (04:20 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Sat, 7 Nov 2009 04:20:50 +0000 (04:20 +0000)
initialize HeaderSearch. Not used yet.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@86338 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Frontend/HeaderSearchOptions.h [new file with mode: 0644]
include/clang/Frontend/InitHeaderSearch.h
lib/Frontend/InitHeaderSearch.cpp

diff --git a/include/clang/Frontend/HeaderSearchOptions.h b/include/clang/Frontend/HeaderSearchOptions.h
new file mode 100644 (file)
index 0000000..dc222c1
--- /dev/null
@@ -0,0 +1,83 @@
+//===--- HeaderSearchOptions.h ----------------------------------*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_CLANG_FRONTEND_HEADERSEARCHOPTIONS_H
+#define LLVM_CLANG_FRONTEND_HEADERSEARCHOPTIONS_H
+
+// FIXME: Drop this dependency.
+#include "clang/Frontend/InitHeaderSearch.h"
+#include "llvm/ADT/StringRef.h"
+
+namespace clang {
+
+/// HeaderSearchOptions - Helper class for storing options related to the
+/// initialization of the HeaderSearch object.
+class HeaderSearchOptions {
+public:
+  struct Entry {
+    std::string Path;
+    InitHeaderSearch::IncludeDirGroup Group;
+    unsigned IsCXXAware : 1;
+    unsigned IsUserSupplied : 1;
+    unsigned IsFramework : 1;
+    unsigned IgnoreSysRoot : 1;
+
+    Entry(llvm::StringRef _Path, InitHeaderSearch::IncludeDirGroup _Group,
+          bool _IsCXXAware, bool _IsUserSupplied, bool _IsFramework,
+          bool _IgnoreSysRoot)
+      : Path(_Path), Group(_Group), IsCXXAware(_IsCXXAware),
+        IsUserSupplied(_IsUserSupplied), IsFramework(_IsFramework),
+        IgnoreSysRoot(_IgnoreSysRoot) {}
+  };
+
+  /// If non-empty, the directory to use as a "virtual system root" for include
+  /// paths.
+  std::string Sysroot;
+
+  /// User specified include entries.
+  std::vector<Entry> UserEntries;
+
+  /// A (system-path) delimited list of include paths to be added from the
+  /// environment following the user specified includes (but prior to builtin
+  /// and standard includes). This is parsed in the same manner as the CPATH
+  /// environment variable for gcc.
+  std::string EnvIncPath;
+
+  /// A (system-path) delimited list of include paths to be added from the
+  /// environment following the user specified includes and the \see EnvIncPath
+  /// includes (but prior to builtin and standard includes). This is parsed in
+  /// the same manner as the CPATH environment variable for gcc.
+  std::string LangEnvIncPath;
+
+  /// If non-empty, the path to the compiler builtin include directory, which
+  /// will be searched following the user and environment includes.
+  std::string BuiltinIncludePath;
+
+  /// Include the system standard include search directories.
+  unsigned UseStandardIncludes : 1;
+
+  /// Whether header search information should be output as for -v.
+  unsigned Verbose : 1;
+
+public:
+  HeaderSearchOptions(llvm::StringRef _Sysroot)
+    : Sysroot(_Sysroot), UseStandardIncludes(true) {}
+
+  /// AddPath - Add the \arg Path path to the specified \arg Group list.
+  void AddPath(llvm::StringRef Path, InitHeaderSearch::IncludeDirGroup Group,
+               bool IsCXXAware, bool IsUserSupplied,
+               bool IsFramework, bool IgnoreSysRoot = false) {
+    UserEntries.push_back(Entry(Path, Group, IsCXXAware, IsUserSupplied,
+                                IsFramework, IgnoreSysRoot));
+  }
+};
+
+} // end namespace clang
+
+#endif
index 261a912e2ce494b2095a7f096896696e27364a75..7900253d8461ef01d3c3a7ed5c10b25b92862ca6 100644 (file)
@@ -23,6 +23,7 @@
 namespace clang {
 
 class HeaderSearch;
+class HeaderSearchOptions;
 class LangOptions;
 
 /// InitHeaderSearch - This class makes it easier to set the search paths of
@@ -86,6 +87,10 @@ public:
   void Realize();
 };
 
+void ApplyHeaderSearchOptions(const HeaderSearchOptions &HSOpts,
+                              HeaderSearch &HS, const LangOptions &Lang,
+                              const llvm::Triple &triple);
+
 } // end namespace clang
 
 #endif
index 0ca6e0b830c69fee7bef57463d68bc848bab8f6f..989829895d3a5e9a938f7a36b7d64484fa6d1389 100644 (file)
 //===----------------------------------------------------------------------===//
 
 #include "clang/Frontend/InitHeaderSearch.h"
-#include "clang/Lex/HeaderSearch.h"
 #include "clang/Basic/FileManager.h"
 #include "clang/Basic/LangOptions.h"
+#include "clang/Frontend/HeaderSearchOptions.h"
+#include "clang/Lex/HeaderSearch.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/SmallPtrSet.h"
 #include "llvm/Support/raw_ostream.h"
@@ -580,3 +581,32 @@ void InitHeaderSearch::Realize() {
     fprintf(stderr, "End of search list.\n");
   }
 }
+
+void clang::ApplyHeaderSearchOptions(const HeaderSearchOptions &HSOpts,
+                                     HeaderSearch &HS, const LangOptions &Lang,
+                                     const llvm::Triple &Triple) {
+  InitHeaderSearch Init(HS, HSOpts.Verbose, HSOpts.Sysroot);
+
+  // Add the user defined entries.
+  for (unsigned i = 0, e = HSOpts.UserEntries.size(); i != e; ++i) {
+    const HeaderSearchOptions::Entry &E = HSOpts.UserEntries[i];
+    Init.AddPath(E.Path, E.Group, E.IsCXXAware, E.IsUserSupplied, E.IsFramework,
+                 E.IgnoreSysRoot);
+  }
+
+  // Add entries from CPATH and friends.
+  Init.AddDelimitedPaths(HSOpts.EnvIncPath.c_str());
+  Init.AddDelimitedPaths(HSOpts.LangEnvIncPath.c_str());
+
+  if (!HSOpts.BuiltinIncludePath.empty()) {
+    // Ignore the sys root, we *always* look for clang headers relative to
+    // supplied path.
+    Init.AddPath(HSOpts.BuiltinIncludePath, InitHeaderSearch::System,
+                 false, false, false, /*IgnoreSysRoot=*/ true);
+  }
+
+  if (!HSOpts.UseStandardIncludes)
+    Init.AddDefaultSystemIncludePaths(Lang, Triple);
+
+  Init.Realize();
+}