@@ -857,7 +857,7 @@ namespace Cpp {
857
857
858
858
TCppIndex_t GetFunctionRequiredArgs (TCppConstFunction_t func)
859
859
{
860
- auto * D = ( const clang::Decl *) func;
860
+ const auto * D = static_cast < const clang::Decl*>( func) ;
861
861
if (auto * FD = llvm::dyn_cast_or_null<FunctionDecl>(D))
862
862
return FD->getMinRequiredArguments ();
863
863
@@ -923,7 +923,8 @@ namespace Cpp {
923
923
}
924
924
925
925
bool IsFunctionDeleted (TCppConstFunction_t function) {
926
- auto *FD = cast<const FunctionDecl>((const clang::Decl*)function);
926
+ const auto * FD =
927
+ cast<const FunctionDecl>(static_cast <const clang::Decl*>(function));
927
928
return FD->isDeleted ();
928
929
}
929
930
@@ -1054,7 +1055,8 @@ namespace Cpp {
1054
1055
1055
1056
bool IsMethod (TCppConstFunction_t method)
1056
1057
{
1057
- return dyn_cast_or_null<CXXMethodDecl>((const clang::Decl*)method);
1058
+ return dyn_cast_or_null<CXXMethodDecl>(
1059
+ static_cast <const clang::Decl*>(method));
1058
1060
}
1059
1061
1060
1062
bool IsPublicMethod (TCppFunction_t method)
@@ -1073,18 +1075,18 @@ namespace Cpp {
1073
1075
1074
1076
bool IsConstructor (TCppConstFunction_t method)
1075
1077
{
1076
- auto * D = ( const Decl *) method;
1078
+ const auto * D = static_cast < const Decl*>( method) ;
1077
1079
return llvm::isa_and_nonnull<CXXConstructorDecl>(D);
1078
1080
}
1079
1081
1080
1082
bool IsDestructor (TCppConstFunction_t method)
1081
1083
{
1082
- auto * D = ( const Decl *) method;
1084
+ const auto * D = static_cast < const Decl*>( method) ;
1083
1085
return llvm::isa_and_nonnull<CXXDestructorDecl>(D);
1084
1086
}
1085
1087
1086
1088
bool IsStaticMethod (TCppConstFunction_t method) {
1087
- const auto * D = ( const Decl*) method;
1089
+ const auto * D = static_cast < const Decl*>( method) ;
1088
1090
if (auto *CXXMD = llvm::dyn_cast_or_null<CXXMethodDecl>(D)) {
1089
1091
return CXXMD->isStatic ();
1090
1092
}
@@ -1207,13 +1209,11 @@ namespace Cpp {
1207
1209
return 0 ;
1208
1210
}
1209
1211
1210
- intptr_t GetVariableOffset (TCppScope_t var)
1211
- {
1212
- if (!var)
1212
+ intptr_t GetVariableOffset (compat::Interpreter& I, Decl* D) {
1213
+ if (!D)
1213
1214
return 0 ;
1214
1215
1215
- auto *D = (Decl *) var;
1216
- auto &C = getASTContext ();
1216
+ auto & C = I.getSema ().getASTContext ();
1217
1217
1218
1218
if (auto * FD = llvm::dyn_cast<FieldDecl>(D)) {
1219
1219
const clang::RecordDecl* RD = FD->getParent ();
@@ -1242,7 +1242,7 @@ namespace Cpp {
1242
1242
compat::maybeMangleDeclName (GD, mangledName);
1243
1243
void * address = llvm::sys::DynamicLibrary::SearchForAddressOfSymbol (
1244
1244
mangledName.c_str ());
1245
- auto &I = getInterp ();
1245
+
1246
1246
if (!address)
1247
1247
address = I.getAddressOfGlobal (GD);
1248
1248
if (!address) {
@@ -1292,6 +1292,11 @@ namespace Cpp {
1292
1292
return 0 ;
1293
1293
}
1294
1294
1295
+ intptr_t GetVariableOffset (TCppScope_t var) {
1296
+ auto * D = static_cast <Decl*>(var);
1297
+ return GetVariableOffset (getInterp (), D);
1298
+ }
1299
+
1295
1300
// Check if the Access Specifier of the variable matches the provided value.
1296
1301
bool CheckVariableAccess (TCppScope_t var, AccessSpecifier AS)
1297
1302
{
@@ -2574,26 +2579,32 @@ namespace Cpp {
2574
2579
} // namespace
2575
2580
// End of JitCall Helper Functions
2576
2581
2577
- CPPINTEROP_API JitCall MakeFunctionCallable (TCppConstFunction_t func) {
2578
- auto * D = (const clang::Decl*)func;
2579
- if (!D)
2580
- return {};
2582
+ CPPINTEROP_API JitCall MakeFunctionCallable (TInterp_t I,
2583
+ TCppConstFunction_t func) {
2584
+ const auto * D = static_cast <const clang::Decl*>(func);
2585
+ if (!D)
2586
+ return {};
2581
2587
2582
- auto & I = getInterp ();
2583
- // FIXME: Unify with make_wrapper.
2584
- if (auto *Dtor = dyn_cast<CXXDestructorDecl>(D)) {
2585
- if (auto Wrapper = make_dtor_wrapper (I, Dtor->getParent ()))
2586
- return {JitCall::kDestructorCall , Wrapper, Dtor};
2588
+ auto * interp = static_cast <compat::Interpreter*>(I);
2589
+
2590
+ // FIXME: Unify with make_wrapper.
2591
+ if (const auto * Dtor = dyn_cast<CXXDestructorDecl>(D)) {
2592
+ if (auto Wrapper = make_dtor_wrapper (*interp, Dtor->getParent ()))
2593
+ return {JitCall::kDestructorCall , Wrapper, Dtor};
2594
+ // FIXME: else error we failed to compile the wrapper.
2595
+ return {};
2596
+ }
2597
+
2598
+ if (auto Wrapper = make_wrapper (*interp, cast<FunctionDecl>(D))) {
2599
+ return {JitCall::kGenericCall , Wrapper, cast<FunctionDecl>(D)};
2600
+ }
2587
2601
// FIXME: else error we failed to compile the wrapper.
2588
2602
return {};
2589
2603
}
2590
2604
2591
- if ( auto Wrapper = make_wrapper (I, cast<FunctionDecl>(D)) ) {
2592
- return {JitCall:: kGenericCall , Wrapper, cast<FunctionDecl>(D)} ;
2605
+ CPPINTEROP_API JitCall MakeFunctionCallable (TCppConstFunction_t func ) {
2606
+ return MakeFunctionCallable (& getInterp (), func) ;
2593
2607
}
2594
- // FIXME: else error we failed to compile the wrapper.
2595
- return {};
2596
- }
2597
2608
2598
2609
namespace {
2599
2610
static std::string MakeResourcesPath () {
@@ -2842,7 +2853,8 @@ namespace Cpp {
2842
2853
return DLM->searchLibrariesForSymbol (mangled_name, search_system);
2843
2854
}
2844
2855
2845
- bool InsertOrReplaceJitSymbol (const char * linker_mangled_name,
2856
+ bool InsertOrReplaceJitSymbol (compat::Interpreter& I,
2857
+ const char * linker_mangled_name,
2846
2858
uint64_t address) {
2847
2859
// FIXME: This approach is problematic since we could replace a symbol
2848
2860
// whose address was already taken by clients.
@@ -2869,7 +2881,6 @@ namespace Cpp {
2869
2881
using namespace llvm ;
2870
2882
using namespace llvm ::orc;
2871
2883
2872
- auto & I = getInterp ();
2873
2884
auto Symbol = compat::getSymbolAddress (I, linker_mangled_name);
2874
2885
llvm::orc::LLJIT& Jit = *compat::getExecutionEngine (I);
2875
2886
llvm::orc::ExecutionSession& ES = Jit.getExecutionSession ();
@@ -2930,6 +2941,11 @@ namespace Cpp {
2930
2941
return false ;
2931
2942
}
2932
2943
2944
+ bool InsertOrReplaceJitSymbol (const char * linker_mangled_name,
2945
+ uint64_t address) {
2946
+ return InsertOrReplaceJitSymbol (getInterp (), linker_mangled_name, address);
2947
+ }
2948
+
2933
2949
std::string ObjToString (const char *type, void *obj) {
2934
2950
return getInterp ().toString (type, obj);
2935
2951
}
@@ -2979,9 +2995,8 @@ namespace Cpp {
2979
2995
// return C.getElaboratedType(ETK_None, NS, TT);
2980
2996
}
2981
2997
2982
- static Decl* InstantiateTemplate (TemplateDecl* TemplateD,
2983
- ArrayRef<TemplateArgument> TemplateArgs,
2984
- Sema& S) {
2998
+ Decl* InstantiateTemplate (TemplateDecl* TemplateD,
2999
+ ArrayRef<TemplateArgument> TemplateArgs, Sema& S) {
2985
3000
// Create a list of template arguments.
2986
3001
TemplateArgumentListInfo TLI{};
2987
3002
for (auto TA : TemplateArgs)
@@ -2991,10 +3006,11 @@ namespace Cpp {
2991
3006
return InstantiateTemplate (TemplateD, TLI, S);
2992
3007
}
2993
3008
2994
- TCppScope_t InstantiateTemplate (TCppScope_t tmpl,
3009
+ TCppScope_t InstantiateTemplate (compat::Interpreter& I, TCppScope_t tmpl,
2995
3010
const TemplateArgInfo* template_args,
2996
3011
size_t template_args_size) {
2997
- ASTContext &C = getASTContext ();
3012
+ auto & S = I.getSema ();
3013
+ auto & C = S.getASTContext ();
2998
3014
2999
3015
llvm::SmallVector<TemplateArgument> TemplateArgs;
3000
3016
TemplateArgs.reserve (template_args_size);
@@ -3015,9 +3031,16 @@ namespace Cpp {
3015
3031
3016
3032
// We will create a new decl, push a transaction.
3017
3033
#ifdef USE_CLING
3018
- cling::Interpreter::PushTransactionRAII RAII (&getInterp () );
3034
+ cling::Interpreter::PushTransactionRAII RAII (&I );
3019
3035
#endif
3020
- return InstantiateTemplate (TmplD, TemplateArgs, getSema ());
3036
+ return InstantiateTemplate (TmplD, TemplateArgs, S);
3037
+ }
3038
+
3039
+ TCppScope_t InstantiateTemplate (TCppScope_t tmpl,
3040
+ const TemplateArgInfo* template_args,
3041
+ size_t template_args_size) {
3042
+ return InstantiateTemplate (getInterp (), tmpl, template_args,
3043
+ template_args_size);
3021
3044
}
3022
3045
3023
3046
void GetClassTemplateInstantiationArgs (TCppScope_t templ_instance,
@@ -3241,15 +3264,15 @@ namespace Cpp {
3241
3264
}
3242
3265
3243
3266
// FIXME: Add optional arguments to the operator new.
3244
- TCppObject_t Construct (TCppScope_t scope,
3245
- void * arena/* =nullptr*/ ) {
3267
+ TCppObject_t Construct (compat::Interpreter& interp, TCppScope_t scope,
3268
+ void * arena /* =nullptr*/ ) {
3246
3269
auto * Class = (Decl*) scope;
3247
3270
// FIXME: Diagnose.
3248
3271
if (!HasDefaultConstructor (Class))
3249
3272
return nullptr ;
3250
3273
3251
3274
auto * const Ctor = GetDefaultConstructor (Class);
3252
- if (JitCall JC = MakeFunctionCallable (Ctor)) {
3275
+ if (JitCall JC = MakeFunctionCallable (&interp, Ctor)) {
3253
3276
if (arena) {
3254
3277
JC.Invoke (&arena, {}, (void *)~0 ); // Tell Invoke to use placement new.
3255
3278
return arena;
@@ -3262,15 +3285,24 @@ namespace Cpp {
3262
3285
return nullptr ;
3263
3286
}
3264
3287
3265
- void Destruct (TCppObject_t This, TCppScope_t scope, bool withFree /* =true*/ ) {
3266
- Decl* Class = (Decl*)scope;
3267
- if (auto wrapper = make_dtor_wrapper (getInterp (), Class)) {
3288
+ TCppObject_t Construct (TCppScope_t scope, void * arena /* =nullptr*/ ) {
3289
+ return Construct (getInterp (), scope, arena);
3290
+ }
3291
+
3292
+ void Destruct (compat::Interpreter& interp, TCppObject_t This, Decl* Class,
3293
+ bool withFree) {
3294
+ if (auto wrapper = make_dtor_wrapper (interp, Class)) {
3268
3295
(*wrapper)(This, /* nary=*/ 0 , withFree);
3269
3296
return ;
3270
3297
}
3271
3298
// FIXME: Diagnose.
3272
3299
}
3273
3300
3301
+ void Destruct (TCppObject_t This, TCppScope_t scope, bool withFree /* =true*/ ) {
3302
+ auto * Class = static_cast <Decl*>(scope);
3303
+ Destruct (getInterp (), This, Class, withFree);
3304
+ }
3305
+
3274
3306
class StreamCaptureInfo {
3275
3307
std::unique_ptr<FILE, decltype (std::fclose)*> m_TempFile;
3276
3308
int m_FD = -1 ;
0 commit comments