Move core of Interpreter::GetIncludePaths into Utils library.
Add optional stream for Interpreter::DumpIncludePath. This allows for easier debugging of include path during different stages of startup. Signed-off-by: Vassil Vassilev <vvasilev@cern.ch>
This commit is contained in:
parent
ea25014f1f
commit
998ca7af13
@ -385,12 +385,15 @@ namespace cling {
|
||||
/// a new include path region (e.g. "-cxx-isystem"). Also, flags
|
||||
/// defining header search behavior will be included in incpaths, e.g.
|
||||
/// "-nostdinc".
|
||||
///
|
||||
void GetIncludePaths(llvm::SmallVectorImpl<std::string>& incpaths,
|
||||
bool withSystem, bool withFlags);
|
||||
|
||||
///\brief Prints the current include paths that are used.
|
||||
///
|
||||
void DumpIncludePath();
|
||||
///\param[in] S - stream to dump to or nullptr for default (llvm::outs)
|
||||
///
|
||||
void DumpIncludePath(llvm::raw_ostream* S = nullptr);
|
||||
|
||||
///\brief Store the interpreter state in files
|
||||
/// Store the AST, the included files and the lookup tables
|
||||
|
@ -12,6 +12,15 @@
|
||||
|
||||
#include "llvm/ADT/SmallVector.h"
|
||||
#include "llvm/ADT/StringRef.h"
|
||||
#include <string>
|
||||
|
||||
namespace llvm {
|
||||
class raw_ostream;
|
||||
}
|
||||
|
||||
namespace clang {
|
||||
class HeaderSearchOptions;
|
||||
}
|
||||
|
||||
namespace cling {
|
||||
namespace utils {
|
||||
@ -31,6 +40,37 @@ namespace cling {
|
||||
llvm::SmallVectorImpl<llvm::StringRef>& Paths,
|
||||
bool EarlyOut = false,
|
||||
llvm::StringRef Delim = llvm::StringRef(":"));
|
||||
|
||||
///\brief Copies the current include paths into the HeaderSearchOptions.
|
||||
///
|
||||
///\param[in] Opts - HeaderSearchOptions to read from
|
||||
///\param[out] Paths - Vector to output elements into
|
||||
///\param[in] WithSystem - if true, incpaths will also contain system
|
||||
/// include paths (framework, STL etc).
|
||||
///\param[in] WithFlags - if true, each element in incpaths will be prefixed
|
||||
/// with a "-I" or similar, and some entries of incpaths will signal
|
||||
/// a new include path region (e.g. "-cxx-isystem"). Also, flags
|
||||
/// defining header search behavior will be included in incpaths, e.g.
|
||||
/// "-nostdinc".
|
||||
///
|
||||
void CopyIncludePaths(const clang::HeaderSearchOptions& Opts,
|
||||
llvm::SmallVectorImpl<std::string>& Paths,
|
||||
bool WithSystem, bool WithFlags);
|
||||
|
||||
///\brief Prints the current include paths into the HeaderSearchOptions.
|
||||
///
|
||||
///\param[in] Opts - HeaderSearchOptions to read from
|
||||
///\param[in] Out - Stream to dump to
|
||||
///\param[in] WithSystem - dump contain system paths (framework, STL etc).
|
||||
///\param[in] WithFlags - if true, each line will be prefixed
|
||||
/// with a "-I" or similar, and some entries of incpaths will signal
|
||||
/// a new include path region (e.g. "-cxx-isystem"). Also, flags
|
||||
/// defining header search behavior will be included in incpaths, e.g.
|
||||
/// "-nostdinc".
|
||||
///
|
||||
void DumpIncludePaths(const clang::HeaderSearchOptions& Opts,
|
||||
llvm::raw_ostream& Out,
|
||||
bool WithSystem, bool WithFlags);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -28,9 +28,9 @@
|
||||
#include "cling/Interpreter/LookupHelper.h"
|
||||
#include "cling/Interpreter/Transaction.h"
|
||||
#include "cling/Interpreter/Value.h"
|
||||
#include "cling/Interpreter/AutoloadCallback.h"
|
||||
#include "cling/Utils/AST.h"
|
||||
#include "cling/Utils/SourceNormalization.h"
|
||||
#include "cling/Interpreter/AutoloadCallback.h"
|
||||
|
||||
#include "clang/AST/ASTContext.h"
|
||||
#include "clang/AST/GlobalDecl.h"
|
||||
@ -388,13 +388,9 @@ namespace cling {
|
||||
PP.getTargetInfo().getTriple());
|
||||
}
|
||||
|
||||
void Interpreter::DumpIncludePath() {
|
||||
llvm::SmallVector<std::string, 100> IncPaths;
|
||||
GetIncludePaths(IncPaths, true /*withSystem*/, true /*withFlags*/);
|
||||
// print'em all
|
||||
for (unsigned i = 0; i < IncPaths.size(); ++i) {
|
||||
llvm::errs() << IncPaths[i] <<"\n";
|
||||
}
|
||||
void Interpreter::DumpIncludePath(llvm::raw_ostream* S) {
|
||||
utils::DumpIncludePaths(getCI()->getHeaderSearchOpts(), S ? *S : llvm::outs(),
|
||||
true /*withSystem*/, true /*withFlags*/);
|
||||
}
|
||||
|
||||
void Interpreter::storeInterpreterState(const std::string& name) const {
|
||||
@ -433,89 +429,10 @@ namespace cling {
|
||||
}
|
||||
|
||||
|
||||
// Adapted from clang/lib/Frontend/CompilerInvocation.cpp
|
||||
void Interpreter::GetIncludePaths(llvm::SmallVectorImpl<std::string>& incpaths,
|
||||
bool withSystem, bool withFlags) {
|
||||
const HeaderSearchOptions Opts(getCI()->getHeaderSearchOpts());
|
||||
|
||||
if (withFlags && Opts.Sysroot != "/") {
|
||||
incpaths.push_back("-isysroot");
|
||||
incpaths.push_back(Opts.Sysroot);
|
||||
}
|
||||
|
||||
/// User specified include entries.
|
||||
for (unsigned i = 0, e = Opts.UserEntries.size(); i != e; ++i) {
|
||||
const HeaderSearchOptions::Entry &E = Opts.UserEntries[i];
|
||||
if (E.IsFramework && E.Group != frontend::Angled)
|
||||
llvm::report_fatal_error("Invalid option set!");
|
||||
switch (E.Group) {
|
||||
case frontend::After:
|
||||
if (withFlags) incpaths.push_back("-idirafter");
|
||||
break;
|
||||
|
||||
case frontend::Quoted:
|
||||
if (withFlags) incpaths.push_back("-iquote");
|
||||
break;
|
||||
|
||||
case frontend::System:
|
||||
if (!withSystem) continue;
|
||||
if (withFlags) incpaths.push_back("-isystem");
|
||||
break;
|
||||
|
||||
case frontend::IndexHeaderMap:
|
||||
if (!withSystem) continue;
|
||||
if (withFlags) incpaths.push_back("-index-header-map");
|
||||
if (withFlags) incpaths.push_back(E.IsFramework? "-F" : "-I");
|
||||
break;
|
||||
|
||||
case frontend::CSystem:
|
||||
if (!withSystem) continue;
|
||||
if (withFlags) incpaths.push_back("-c-isystem");
|
||||
break;
|
||||
|
||||
case frontend::ExternCSystem:
|
||||
if (!withSystem) continue;
|
||||
if (withFlags) incpaths.push_back("-extern-c-isystem");
|
||||
break;
|
||||
|
||||
case frontend::CXXSystem:
|
||||
if (!withSystem) continue;
|
||||
if (withFlags) incpaths.push_back("-cxx-isystem");
|
||||
break;
|
||||
|
||||
case frontend::ObjCSystem:
|
||||
if (!withSystem) continue;
|
||||
if (withFlags) incpaths.push_back("-objc-isystem");
|
||||
break;
|
||||
|
||||
case frontend::ObjCXXSystem:
|
||||
if (!withSystem) continue;
|
||||
if (withFlags) incpaths.push_back("-objcxx-isystem");
|
||||
break;
|
||||
|
||||
case frontend::Angled:
|
||||
if (withFlags) incpaths.push_back(E.IsFramework ? "-F" : "-I");
|
||||
break;
|
||||
}
|
||||
incpaths.push_back(E.Path);
|
||||
}
|
||||
|
||||
if (withSystem && !Opts.ResourceDir.empty()) {
|
||||
if (withFlags) incpaths.push_back("-resource-dir");
|
||||
incpaths.push_back(Opts.ResourceDir);
|
||||
}
|
||||
if (withSystem && withFlags && !Opts.ModuleCachePath.empty()) {
|
||||
incpaths.push_back("-fmodule-cache-path");
|
||||
incpaths.push_back(Opts.ModuleCachePath);
|
||||
}
|
||||
if (withSystem && withFlags && !Opts.UseStandardSystemIncludes)
|
||||
incpaths.push_back("-nostdinc");
|
||||
if (withSystem && withFlags && !Opts.UseStandardCXXIncludes)
|
||||
incpaths.push_back("-nostdinc++");
|
||||
if (withSystem && withFlags && Opts.UseLibcxx)
|
||||
incpaths.push_back("-stdlib=libc++");
|
||||
if (withSystem && withFlags && Opts.Verbose)
|
||||
incpaths.push_back("-v");
|
||||
utils::CopyIncludePaths(getCI()->getHeaderSearchOpts(), incpaths,
|
||||
withSystem, withFlags);
|
||||
}
|
||||
|
||||
CompilerInstance* Interpreter::getCI() const {
|
||||
|
@ -8,11 +8,112 @@
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include "cling/Utils/Paths.h"
|
||||
#include "clang/Lex/HeaderSearchOptions.h"
|
||||
#include "llvm/Support/ErrorHandling.h"
|
||||
#include "llvm/Support/FileSystem.h"
|
||||
#include "llvm/Support/raw_ostream.h"
|
||||
|
||||
namespace cling {
|
||||
namespace utils {
|
||||
|
||||
using namespace clang;
|
||||
|
||||
// Adapted from clang/lib/Frontend/CompilerInvocation.cpp
|
||||
|
||||
void CopyIncludePaths(const clang::HeaderSearchOptions& Opts,
|
||||
llvm::SmallVectorImpl<std::string>& incpaths,
|
||||
bool withSystem, bool withFlags) {
|
||||
if (withFlags && Opts.Sysroot != "/") {
|
||||
incpaths.push_back("-isysroot");
|
||||
incpaths.push_back(Opts.Sysroot);
|
||||
}
|
||||
|
||||
/// User specified include entries.
|
||||
for (unsigned i = 0, e = Opts.UserEntries.size(); i != e; ++i) {
|
||||
const HeaderSearchOptions::Entry &E = Opts.UserEntries[i];
|
||||
if (E.IsFramework && E.Group != frontend::Angled)
|
||||
llvm::report_fatal_error("Invalid option set!");
|
||||
switch (E.Group) {
|
||||
case frontend::After:
|
||||
if (withFlags) incpaths.push_back("-idirafter");
|
||||
break;
|
||||
|
||||
case frontend::Quoted:
|
||||
if (withFlags) incpaths.push_back("-iquote");
|
||||
break;
|
||||
|
||||
case frontend::System:
|
||||
if (!withSystem) continue;
|
||||
if (withFlags) incpaths.push_back("-isystem");
|
||||
break;
|
||||
|
||||
case frontend::IndexHeaderMap:
|
||||
if (!withSystem) continue;
|
||||
if (withFlags) incpaths.push_back("-index-header-map");
|
||||
if (withFlags) incpaths.push_back(E.IsFramework? "-F" : "-I");
|
||||
break;
|
||||
|
||||
case frontend::CSystem:
|
||||
if (!withSystem) continue;
|
||||
if (withFlags) incpaths.push_back("-c-isystem");
|
||||
break;
|
||||
|
||||
case frontend::ExternCSystem:
|
||||
if (!withSystem) continue;
|
||||
if (withFlags) incpaths.push_back("-extern-c-isystem");
|
||||
break;
|
||||
|
||||
case frontend::CXXSystem:
|
||||
if (!withSystem) continue;
|
||||
if (withFlags) incpaths.push_back("-cxx-isystem");
|
||||
break;
|
||||
|
||||
case frontend::ObjCSystem:
|
||||
if (!withSystem) continue;
|
||||
if (withFlags) incpaths.push_back("-objc-isystem");
|
||||
break;
|
||||
|
||||
case frontend::ObjCXXSystem:
|
||||
if (!withSystem) continue;
|
||||
if (withFlags) incpaths.push_back("-objcxx-isystem");
|
||||
break;
|
||||
|
||||
case frontend::Angled:
|
||||
if (withFlags) incpaths.push_back(E.IsFramework ? "-F" : "-I");
|
||||
break;
|
||||
}
|
||||
incpaths.push_back(E.Path);
|
||||
}
|
||||
|
||||
if (withSystem && !Opts.ResourceDir.empty()) {
|
||||
if (withFlags) incpaths.push_back("-resource-dir");
|
||||
incpaths.push_back(Opts.ResourceDir);
|
||||
}
|
||||
if (withSystem && withFlags && !Opts.ModuleCachePath.empty()) {
|
||||
incpaths.push_back("-fmodule-cache-path");
|
||||
incpaths.push_back(Opts.ModuleCachePath);
|
||||
}
|
||||
if (withSystem && withFlags && !Opts.UseStandardSystemIncludes)
|
||||
incpaths.push_back("-nostdinc");
|
||||
if (withSystem && withFlags && !Opts.UseStandardCXXIncludes)
|
||||
incpaths.push_back("-nostdinc++");
|
||||
if (withSystem && withFlags && Opts.UseLibcxx)
|
||||
incpaths.push_back("-stdlib=libc++");
|
||||
if (withSystem && withFlags && Opts.Verbose)
|
||||
incpaths.push_back("-v");
|
||||
}
|
||||
|
||||
void DumpIncludePaths(const clang::HeaderSearchOptions& Opts,
|
||||
llvm::raw_ostream& Out,
|
||||
bool WithSystem, bool WithFlags) {
|
||||
llvm::SmallVector<std::string, 100> IncPaths;
|
||||
CopyIncludePaths(Opts, IncPaths, WithSystem, WithFlags);
|
||||
// print'em all
|
||||
for (unsigned i = 0; i < IncPaths.size(); ++i) {
|
||||
Out << IncPaths[i] <<"\n";
|
||||
}
|
||||
}
|
||||
|
||||
bool SplitPaths(llvm::StringRef PathStr,
|
||||
llvm::SmallVectorImpl<llvm::StringRef>& Paths, bool EarlyOut,
|
||||
llvm::StringRef Delim) {
|
||||
@ -36,6 +137,6 @@ bool SplitPaths(llvm::StringRef PathStr,
|
||||
|
||||
return AllExisted;
|
||||
}
|
||||
|
||||
|
||||
} // namespace utils
|
||||
} // namespace cling
|
||||
|
Loading…
x
Reference in New Issue
Block a user