@@ -857,7 +857,7 @@ namespace Cpp {
857857
858858  TCppIndex_t GetFunctionRequiredArgs (TCppConstFunction_t func)
859859  {
860-     auto  * D = ( const  clang::Decl *)  func;
860+     const   auto *  D = static_cast < const  clang::Decl*>( func) ;
861861    if  (auto * FD = llvm::dyn_cast_or_null<FunctionDecl>(D))
862862      return  FD->getMinRequiredArguments ();
863863
@@ -923,7 +923,8 @@ namespace Cpp {
923923  }
924924
925925  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));
927928    return  FD->isDeleted ();
928929  }
929930
@@ -1054,7 +1055,8 @@ namespace Cpp {
10541055
10551056  bool  IsMethod (TCppConstFunction_t method)
10561057  {
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));
10581060  }
10591061
10601062  bool  IsPublicMethod (TCppFunction_t method)
@@ -1073,18 +1075,18 @@ namespace Cpp {
10731075
10741076  bool  IsConstructor (TCppConstFunction_t method)
10751077  {
1076-     auto  * D = ( const  Decl *)  method;
1078+     const   auto *  D = static_cast < const  Decl*>( method) ;
10771079    return  llvm::isa_and_nonnull<CXXConstructorDecl>(D);
10781080  }
10791081
10801082  bool  IsDestructor (TCppConstFunction_t method)
10811083  {
1082-     auto  * D = ( const  Decl *)  method;
1084+     const   auto *  D = static_cast < const  Decl*>( method) ;
10831085    return  llvm::isa_and_nonnull<CXXDestructorDecl>(D);
10841086  }
10851087
10861088  bool  IsStaticMethod (TCppConstFunction_t method) {
1087-     const  auto * D = ( const  Decl*) method;
1089+     const  auto * D = static_cast < const  Decl*>( method) ;
10881090    if  (auto  *CXXMD = llvm::dyn_cast_or_null<CXXMethodDecl>(D)) {
10891091      return  CXXMD->isStatic ();
10901092    }
@@ -1207,13 +1209,11 @@ namespace Cpp {
12071209    return  0 ;
12081210  }
12091211
1210-   intptr_t  GetVariableOffset (TCppScope_t var)
1211-   {
1212-     if  (!var)
1212+   intptr_t  GetVariableOffset (compat::Interpreter& I, Decl* D) {
1213+     if  (!D)
12131214      return  0 ;
12141215
1215-     auto  *D = (Decl *) var;
1216-     auto  &C = getASTContext ();
1216+     auto & C = I.getSema ().getASTContext ();
12171217
12181218    if  (auto * FD = llvm::dyn_cast<FieldDecl>(D)) {
12191219      const  clang::RecordDecl* RD = FD->getParent ();
@@ -1242,7 +1242,7 @@ namespace Cpp {
12421242      compat::maybeMangleDeclName (GD, mangledName);
12431243      void * address = llvm::sys::DynamicLibrary::SearchForAddressOfSymbol (
12441244          mangledName.c_str ());
1245-        auto  &I =  getInterp (); 
1245+ 
12461246      if  (!address)
12471247        address = I.getAddressOfGlobal (GD);
12481248      if  (!address) {
@@ -1292,6 +1292,11 @@ namespace Cpp {
12921292    return  0 ;
12931293  }
12941294
1295+   intptr_t  GetVariableOffset (TCppScope_t var) {
1296+     auto * D = static_cast <Decl*>(var);
1297+     return  GetVariableOffset (getInterp (), D);
1298+   }
1299+ 
12951300  //  Check if the Access Specifier of the variable matches the provided value.
12961301  bool  CheckVariableAccess (TCppScope_t var, AccessSpecifier AS)
12971302  {
@@ -2574,26 +2579,32 @@ namespace Cpp {
25742579    } //  namespace
25752580      //  End of JitCall Helper Functions
25762581
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  {};
25812587
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+       }
25872601      //  FIXME: else error we failed to compile the wrapper.
25882602      return  {};
25892603    }
25902604
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) ;
25932607    }
2594-     //  FIXME: else error we failed to compile the wrapper.
2595-     return  {};
2596-   }
25972608
25982609  namespace  {
25992610  static  std::string MakeResourcesPath () {
@@ -2842,7 +2853,8 @@ namespace Cpp {
28422853    return  DLM->searchLibrariesForSymbol (mangled_name, search_system);
28432854  }
28442855
2845-   bool  InsertOrReplaceJitSymbol (const  char * linker_mangled_name,
2856+   bool  InsertOrReplaceJitSymbol (compat::Interpreter& I,
2857+                                 const  char * linker_mangled_name,
28462858                                uint64_t  address) {
28472859    //  FIXME: This approach is problematic since we could replace a symbol
28482860    //  whose address was already taken by clients.
@@ -2869,7 +2881,6 @@ namespace Cpp {
28692881    using  namespace  llvm ; 
28702882    using  namespace  llvm ::orc; 
28712883
2872-     auto & I = getInterp ();
28732884    auto  Symbol = compat::getSymbolAddress (I, linker_mangled_name);
28742885    llvm::orc::LLJIT& Jit = *compat::getExecutionEngine (I);
28752886    llvm::orc::ExecutionSession& ES = Jit.getExecutionSession ();
@@ -2930,6 +2941,11 @@ namespace Cpp {
29302941    return  false ;
29312942  }
29322943
2944+   bool  InsertOrReplaceJitSymbol (const  char * linker_mangled_name,
2945+                                 uint64_t  address) {
2946+     return  InsertOrReplaceJitSymbol (getInterp (), linker_mangled_name, address);
2947+   }
2948+ 
29332949  std::string ObjToString (const  char  *type, void  *obj) {
29342950    return  getInterp ().toString (type, obj);
29352951  }
@@ -2979,9 +2995,8 @@ namespace Cpp {
29792995    //  return C.getElaboratedType(ETK_None, NS, TT);
29802996  }
29812997
2982-   static  Decl* InstantiateTemplate (TemplateDecl* TemplateD,
2983-                                    ArrayRef<TemplateArgument> TemplateArgs,
2984-                                    Sema& S) {
2998+   Decl* InstantiateTemplate (TemplateDecl* TemplateD,
2999+                             ArrayRef<TemplateArgument> TemplateArgs, Sema& S) {
29853000    //  Create a list of template arguments.
29863001    TemplateArgumentListInfo TLI{};
29873002    for  (auto  TA : TemplateArgs)
@@ -2991,10 +3006,11 @@ namespace Cpp {
29913006    return  InstantiateTemplate (TemplateD, TLI, S);
29923007  }
29933008
2994-   TCppScope_t InstantiateTemplate (TCppScope_t tmpl,
3009+   TCppScope_t InstantiateTemplate (compat::Interpreter& I,  TCppScope_t tmpl,
29953010                                  const  TemplateArgInfo* template_args,
29963011                                  size_t  template_args_size) {
2997-     ASTContext &C = getASTContext ();
3012+     auto & S = I.getSema ();
3013+     auto & C = S.getASTContext ();
29983014
29993015    llvm::SmallVector<TemplateArgument> TemplateArgs;
30003016    TemplateArgs.reserve (template_args_size);
@@ -3015,9 +3031,16 @@ namespace Cpp {
30153031
30163032    //  We will create a new decl, push a transaction.
30173033#ifdef  USE_CLING
3018-     cling::Interpreter::PushTransactionRAII RAII (&getInterp () );
3034+     cling::Interpreter::PushTransactionRAII RAII (&I );
30193035#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);
30213044  }
30223045
30233046  void  GetClassTemplateInstantiationArgs (TCppScope_t templ_instance,
@@ -3241,15 +3264,15 @@ namespace Cpp {
32413264  }
32423265
32433266  //  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*/ 
32463269    auto * Class = (Decl*) scope;
32473270    //  FIXME: Diagnose.
32483271    if  (!HasDefaultConstructor (Class))
32493272      return  nullptr ;
32503273
32513274    auto * const  Ctor = GetDefaultConstructor (Class);
3252-     if  (JitCall JC = MakeFunctionCallable (Ctor)) {
3275+     if  (JitCall JC = MakeFunctionCallable (&interp,  Ctor)) {
32533276      if  (arena) {
32543277        JC.Invoke (&arena, {}, (void *)~0 ); //  Tell Invoke to use placement new.
32553278        return  arena;
@@ -3262,15 +3285,24 @@ namespace Cpp {
32623285    return  nullptr ;
32633286  }
32643287
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)) {
32683295      (*wrapper)(This, /* nary=*/ 0 , withFree);
32693296      return ;
32703297    }
32713298    //  FIXME: Diagnose.
32723299  }
32733300
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+ 
32743306  class  StreamCaptureInfo  {
32753307    std::unique_ptr<FILE, decltype (std::fclose)*> m_TempFile;
32763308    int  m_FD = -1 ;
0 commit comments