Skip to content

Commit bebebcd

Browse files
Implement GetIncludePaths (#311)
Fixes #69
1 parent 34186d6 commit bebebcd

File tree

4 files changed

+51
-0
lines changed

4 files changed

+51
-0
lines changed

include/clang/Interpreter/CppInterOp.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,13 @@ namespace Cpp {
507507
/// GetResourceDir() function.
508508
CPPINTEROP_API void AddIncludePath(const char* dir);
509509

510+
// Gets the currently used include paths
511+
///\param[out] IncludePaths - the list of include paths
512+
///
513+
CPPINTEROP_API void GetIncludePaths(std::vector<std::string>& IncludePaths,
514+
bool withSystem = false,
515+
bool withFlags = false);
516+
510517
/// Only Declares a code snippet in \c code and does not execute it.
511518
///\returns 0 on success
512519
CPPINTEROP_API int Declare(const char* code, bool silent = false);

lib/Interpreter/CppInterOp.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2702,6 +2702,14 @@ namespace Cpp {
27022702
getInterp().AddIncludePath(dir);
27032703
}
27042704

2705+
void GetIncludePaths(std::vector<std::string>& IncludePaths, bool withSystem,
2706+
bool withFlags) {
2707+
llvm::SmallVector<std::string> paths(1);
2708+
getInterp().GetIncludePaths(paths, withSystem, withFlags);
2709+
for (auto& i : paths)
2710+
IncludePaths.push_back(i);
2711+
}
2712+
27052713
namespace {
27062714

27072715
class clangSilent {

lib/Interpreter/CppInterOpInterpreter.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,24 @@ class Interpreter {
381381
return AddIncludePaths(PathsStr, nullptr);
382382
}
383383

384+
///\brief Get the current include paths that are used.
385+
///
386+
///\param[out] incpaths - Pass in a llvm::SmallVector<std::string, N> with
387+
/// sufficiently sized N, to hold the result of the call.
388+
///\param[in] withSystem - if true, incpaths will also contain system
389+
/// include paths (framework, STL etc).
390+
///\param[in] withFlags - if true, each element in incpaths will be prefixed
391+
/// with a "-I" or similar, and some entries of incpaths will signal
392+
/// a new include path region (e.g. "-cxx-isystem"). Also, flags
393+
/// defining header search behavior will be included in incpaths, e.g.
394+
/// "-nostdinc".
395+
///
396+
void GetIncludePaths(llvm::SmallVectorImpl<std::string>& incpaths,
397+
bool withSystem, bool withFlags) const {
398+
utils::CopyIncludePaths(getCI()->getHeaderSearchOpts(), incpaths,
399+
withSystem, withFlags);
400+
}
401+
384402
CompilationResult loadLibrary(const std::string& filename, bool lookup) {
385403
DynamicLibraryManager* DLM = getDynamicLibraryManager();
386404
std::string canonicalLib;

unittests/CppInterOp/InterpreterTest.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,24 @@ TEST(InterpreterTest, DetectSystemCompilerIncludePaths) {
113113
EXPECT_FALSE(includes.empty());
114114
}
115115

116+
TEST(InterpreterTest, GetIncludePaths) {
117+
std::vector<std::string> includes;
118+
Cpp::GetIncludePaths(includes);
119+
EXPECT_FALSE(includes.empty());
120+
121+
size_t len = includes.size();
122+
includes.clear();
123+
Cpp::GetIncludePaths(includes, true, false);
124+
EXPECT_FALSE(includes.empty());
125+
EXPECT_TRUE(includes.size() >= len);
126+
127+
len = includes.size();
128+
includes.clear();
129+
Cpp::GetIncludePaths(includes, true, true);
130+
EXPECT_FALSE(includes.empty());
131+
EXPECT_TRUE(includes.size() >= len);
132+
}
133+
116134
TEST(InterpreterTest, CodeCompletion) {
117135
#if CLANG_VERSION_MAJOR >= 18 || defined(USE_CLING)
118136
Cpp::CreateInterpreter();

0 commit comments

Comments
 (0)