Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions core/meta/inc/TInterpreter.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ class TInterpreter : public TNamed {
virtual ~TInterpreter() { }

virtual void AddIncludePath(const char *path) = 0;
virtual void SetIncludePath(const char *path) = 0;
virtual void *SetAutoLoadCallBack(void* /*cb*/) { return nullptr; }
virtual void *GetAutoLoadCallBack() const { return nullptr; }
virtual Int_t AutoLoad(const char *classname, Bool_t knowDictNotLoaded = kFALSE) = 0;
Expand Down
17 changes: 17 additions & 0 deletions core/metacling/src/TCling.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -2683,6 +2683,23 @@ void TCling::AddIncludePath(const char *path)
fInterpreter->AddIncludePath(sPath.Data());
}

////////////////////////////////////////////////////////////////////////////////
/// \brief Replaces current list of directories with a single path in which the
/// interpreter looks for include files.
/// \param[in] path The path to the directory.
/// \note Only one path item can be specified at a time, i.e. "path1:path2" is
/// \b NOT supported.
/// \warning Only the path to the directory should be specified, without
/// prepending the \c -I prefix, i.e.
/// <tt>gCling->AddIncludePath("/path/to/my/includes")</tt>. If the
/// \c -I prefix is used it will be ignored.
void TCling::SetIncludePath(const char *path)
{
R__LOCKGUARD(gInterpreterMutex);
fInterpreter->ResetIncludePaths();
AddIncludePath(path);
}

////////////////////////////////////////////////////////////////////////////////
/// Visit all members over members, recursing over base classes.

Expand Down
1 change: 1 addition & 0 deletions core/metacling/src/TCling.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ class TCling final : public TInterpreter {
TCling(const char* name, const char* title, const char* const argv[], void *interpLibHandle);

void AddIncludePath(const char* path) final;
void SetIncludePath(const char* path) final;
void *GetAutoLoadCallBack() const final { return fAutoLoadCallBack; }
void *SetAutoLoadCallBack(void* cb) final { void* prev = fAutoLoadCallBack; fAutoLoadCallBack = cb; return prev; }
Int_t AutoLoad(const char *classname, Bool_t knowDictNotLoaded = kFALSE) final;
Expand Down
6 changes: 5 additions & 1 deletion interpreter/cling/include/cling/Interpreter/Interpreter.h
Original file line number Diff line number Diff line change
Expand Up @@ -438,12 +438,16 @@ namespace cling {
///
bool isUniqueName(llvm::StringRef name);

///\brief Adds multiple include paths separated by a delimter.
///\brief Adds multiple include paths separated by a delimiter.
///
///\param[in] PathsStr - Path(s)
///\param[in] Delim - Delimiter to separate paths or NULL if a single path
///
void AddIncludePaths(llvm::StringRef PathsStr, const char* Delim = ":");

///\brief Unsets preexisting include paths.
///
void ResetIncludePaths();

///\brief Adds a single include path (-I).
///
Expand Down
22 changes: 22 additions & 0 deletions interpreter/cling/lib/Interpreter/Interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,28 @@ namespace cling {
if (m_CUDACompiler)
m_CUDACompiler->getPTXInterpreter()->AddIncludePaths(PathStr, Delm);
}

void Interpreter::ResetIncludePaths() {
CompilerInstance* CI = getCI();
HeaderSearchOptions& HOpts = CI->getHeaderSearchOpts();

Preprocessor& PP = CI->getPreprocessor();
SourceManager& SM = PP.getSourceManager();
FileManager& FM = SM.getFileManager();
HeaderSearch& HSearch = PP.getHeaderSearchInfo();
const bool isFramework = false;
// Remove old entries from Preprocessor
size_t Idx = HOpts.UserEntries.size();
for (const size_t N = HOpts.UserEntries.size(); Idx < N; ++Idx) {
const HeaderSearchOptions::Entry& E = HOpts.UserEntries[Idx];
if (auto DE = FM.getOptionalDirectoryRef(E.Path))
HSearch.RemoveSearchPath(DirectoryLookup(*DE, SrcMgr::C_User, isFramework),
E.Group == frontend::Angled);
}
HOpts.ResetPaths();
if (m_CUDACompiler)
m_CUDACompiler->getPTXInterpreter()->ResetIncludePaths();
}

void Interpreter::AddIncludePath(llvm::StringRef PathsStr) {
return AddIncludePaths(PathsStr, nullptr);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,10 @@ class HeaderSearch {

/// Add an additional search path.
void AddSearchPath(const DirectoryLookup &dir, bool isAngled);


/// Remove search path.
void RemoveSearchPath(const DirectoryLookup &dir, bool isAngled);

/// Add an additional system search path.
void AddSystemSearchPath(const DirectoryLookup &dir) {
SearchDirs.push_back(dir);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,11 @@ class HeaderSearchOptions {
bool IsFramework, bool IgnoreSysRoot) {
UserEntries.emplace_back(Path, Group, IsFramework, IgnoreSysRoot);
}

/// ResetPaths - Removes all paths from the user entries list.
void ResetPaths() {
UserEntries.clear();
}

/// AddSystemHeaderPrefix - Override whether \#include directives naming a
/// path starting with \p Prefix should be considered as naming a system
Expand Down
10 changes: 10 additions & 0 deletions interpreter/llvm-project/clang/lib/Lex/HeaderSearch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,16 @@ void HeaderSearch::AddSearchPath(const DirectoryLookup &dir, bool isAngled) {
SystemDirIdx++;
}

void HeaderSearch::RemoveSearchPath(const DirectoryLookup &dir, bool isAngled) {
auto position = std::find(SearchDirs.begin(), SearchDirs.end(), dir);
auto idx = std::distance(SearchDirs.begin(), position);
SearchDirs.erase(position);
SearchDirsUsage.erase(SearchDirsUsage.begin() + idx);
if (!isAngled)
AngledDirIdx--;
SystemDirIdx--;
}

std::vector<bool> HeaderSearch::computeUserEntryUsage() const {
std::vector<bool> UserEntryUsage(HSOpts->UserEntries.size());
for (unsigned I = 0, E = SearchDirsUsage.size(); I < E; ++I) {
Expand Down
Loading