Skip to content

Commit 71ae758

Browse files
committed
Add more helper functions
Added: - CreateInterpreter - GetSema - Process - ObjToString
1 parent 84e5da4 commit 71ae758

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

include/clang/Interpreter/InterOp.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,17 +151,25 @@ namespace InterOp {
151151
CallFuncWrapper_t GetFunctionCallWrapper(TInterp_t interp,
152152
TCppFunction_t func);
153153

154+
TInterp_t CreateInterpreter(const char *resource_dir = "");
155+
156+
TCppSema_t GetSema(TInterp_t interp);
157+
154158
void AddSearchPath(TInterp_t interp, const char *dir, bool isUser = true,
155159
bool prepend = false);
156160

157161
void AddIncludePath(TInterp_t interp, const char *dir);
158162

159163
TCppIndex_t Declare(TInterp_t interp, const char *code, bool silent = false);
160164

165+
void Process(TInterp_t interp, const char *code);
166+
161167
const std::string LookupLibrary(TInterp_t interp, const char *lib_name);
162168

163169
bool LoadLibrary(TInterp_t interp, const char *lib_path, bool lookup = true);
164170

171+
std::string ObjToString(TInterp_t interp, const char *type, void *obj);
172+
165173
TCppScope_t InstantiateClassTemplate(TInterp_t interp, const char *tmpl_name);
166174

167175
std::vector<std::string> GetAllCppNames(TCppScope_t scope);

lib/Interpreter/InterOp.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
#include "clang/AST/GlobalDecl.h"
1919
#include "clang/AST/Mangle.h"
2020
#include "clang/AST/RecordLayout.h"
21+
#include "clang/Basic/Version.h"
22+
#include "clang/Config/config.h"
2123
#include "clang/Frontend/CompilerInstance.h"
2224
#include "clang/Sema/Sema.h"
2325
#include "clang/Sema/Lookup.h"
@@ -1828,6 +1830,21 @@ namespace InterOp {
18281830
return 0;
18291831
}
18301832

1833+
TInterp_t CreateInterpreter(const char *resource_dir) {
1834+
std::string MainExecutableName =
1835+
llvm::sys::fs::getMainExecutable(nullptr, nullptr);
1836+
std::vector<const char *> InterpArgv = {"-resource-dir", resource_dir,
1837+
"-std=c++14"};
1838+
InterpArgv.insert(InterpArgv.begin(), MainExecutableName.c_str());
1839+
return (TInterp_t) new cling::Interpreter(InterpArgv.size(), &InterpArgv[0]);
1840+
}
1841+
1842+
TCppSema_t GetSema(TInterp_t interp) {
1843+
auto* I = (cling::Interpreter*)interp;
1844+
1845+
return (TCppSema_t) &I->getSema();
1846+
}
1847+
18311848
void AddSearchPath(TInterp_t interp, const char *dir, bool isUser,
18321849
bool prepend) {
18331850
auto* I = (cling::Interpreter*)interp;
@@ -1870,6 +1887,13 @@ namespace InterOp {
18701887

18711888
return I->declare(code);
18721889
}
1890+
1891+
void Process(TInterp_t interp, const char *code) {
1892+
auto* I = (cling::Interpreter*)interp;
1893+
1894+
I->process(code);
1895+
}
1896+
18731897
const std::string LookupLibrary(TInterp_t interp, const char *lib_name) {
18741898
auto* I = (cling::Interpreter*)interp;
18751899

@@ -1884,6 +1908,11 @@ namespace InterOp {
18841908
return res == cling::Interpreter::kSuccess;
18851909
}
18861910

1911+
std::string ObjToString(TInterp_t interp, const char *type, void *obj) {
1912+
auto* I = (cling::Interpreter*)interp;
1913+
return I->toString(type, obj);
1914+
}
1915+
18871916
TCppScope_t InstantiateClassTemplate(TInterp_t interp, const char *tmpl_name) {
18881917
auto* I = (cling::Interpreter*)interp;
18891918

0 commit comments

Comments
 (0)