35 #include "cling/Interpreter/Value.h"
37 #include <llvm/ADT/SmallVector.h>
50 class TClingClassInfo;
51 class TInterpreterValue;
53 typedef void (*tcling_callfunc_Wrapper_t)(
void*, int,
void**,
void*);
54 typedef void (*tcling_callfunc_ctor_Wrapper_t)(
void**,
void*,
unsigned long);
55 typedef void (*tcling_callfunc_dtor_Wrapper_t)(
void*,
unsigned long, int);
57 class TClingCallFunc {
62 cling::Interpreter* fInterp;
64 const ROOT::TMetaUtils::TNormalizedCtxt &fNormCtxt;
66 std::unique_ptr<TClingMethodInfo> fMethod;
68 const clang::FunctionDecl *fDecl =
nullptr;
70 size_t fMinRequiredArguments = -1;
72 tcling_callfunc_Wrapper_t fWrapper;
74 mutable llvm::SmallVector<cling::Value, 8> fArgVals;
76 bool fIgnoreExtraArgs : 1;
77 bool fReturnIsRecordType : 1;
86 using ExecWithRetFunc_t = std::function<void(void* address, cling::Value &ret)>;
88 void* compile_wrapper(
const std::string& wrapper_name,
89 const std::string& wrapper,
90 bool withAccessControl =
true);
92 void collect_type_info(clang::QualType& QT, std::ostringstream& typedefbuf,
93 std::ostringstream& callbuf, std::string& type_name,
94 EReferenceType& refType,
bool& isPointer,
int indent_level,
97 void make_narg_call(
const std::string &return_type,
const unsigned N, std::ostringstream &typedefbuf,
98 std::ostringstream &callbuf,
const std::string &class_name,
int indent_level);
100 void make_narg_ctor(
const unsigned N, std::ostringstream& typedefbuf,
101 std::ostringstream& callbuf,
102 const std::string& class_name,
int indent_level);
104 void make_narg_call_with_return(
const unsigned N,
105 const std::string& class_name,
106 std::ostringstream& buf,
int indent_level);
108 void make_narg_ctor_with_return(
const unsigned N,
109 const std::string& class_name,
110 std::ostringstream& buf,
int indent_level);
112 tcling_callfunc_Wrapper_t make_wrapper();
114 tcling_callfunc_ctor_Wrapper_t
115 make_ctor_wrapper(
const TClingClassInfo* info);
117 tcling_callfunc_dtor_Wrapper_t
118 make_dtor_wrapper(
const TClingClassInfo* info);
121 template <
typename T>
122 void execWithLL(
void* address, cling::Value* val);
123 template <
typename T>
124 void execWithULL(
void* address, cling::Value* val);
126 ExecWithRetFunc_t InitRetAndExecIntegral(clang::QualType QT, cling::Value &ret);
128 ExecWithRetFunc_t InitRetAndExecBuiltin(clang::QualType QT,
const clang::BuiltinType *BT, cling::Value &ret);
129 ExecWithRetFunc_t InitRetAndExecNoCtor(clang::QualType QT, cling::Value &ret);
130 ExecWithRetFunc_t InitRetAndExec(
const clang::FunctionDecl *FD, cling::Value &ret);
132 void exec(
void* address,
void* ret);
134 void exec_with_valref_return(
void* address,
136 void EvaluateArgList(
const std::string& ArgList);
138 size_t CalculateMinRequiredArguments();
140 size_t GetMinRequiredArguments() {
141 if (fMinRequiredArguments == (
size_t)-1)
142 fMinRequiredArguments = CalculateMinRequiredArguments();
143 return fMinRequiredArguments;
147 template <
typename T>
148 T ExecT(
void* address);
153 ~TClingCallFunc() =
default;
155 explicit TClingCallFunc(cling::Interpreter *interp,
const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt)
156 : fInterp(interp), fNormCtxt(normCtxt), fWrapper(0), fIgnoreExtraArgs(false), fReturnIsRecordType(false)
158 fMethod = std::unique_ptr<TClingMethodInfo>(
new TClingMethodInfo(interp));
161 explicit TClingCallFunc(
const TClingMethodInfo &minfo,
const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt)
162 : fInterp(minfo.GetInterpreter()), fNormCtxt(normCtxt), fWrapper(0), fIgnoreExtraArgs(false),
163 fReturnIsRecordType(false)
166 fMethod = std::unique_ptr<TClingMethodInfo>(
new TClingMethodInfo(minfo));
169 TClingCallFunc(
const TClingCallFunc &rhs)
170 : fInterp(rhs.fInterp), fNormCtxt(rhs.fNormCtxt), fWrapper(rhs.fWrapper), fArgVals(rhs.fArgVals),
171 fIgnoreExtraArgs(rhs.fIgnoreExtraArgs), fReturnIsRecordType(rhs.fReturnIsRecordType)
173 fMethod = std::unique_ptr<TClingMethodInfo>(
new TClingMethodInfo(*rhs.fMethod));
176 TClingCallFunc &operator=(
const TClingCallFunc &rhs) =
delete;
178 void* ExecDefaultConstructor(
const TClingClassInfo* info,
void* address = 0,
179 unsigned long nary = 0UL);
180 void ExecDestructor(
const TClingClassInfo* info,
void* address = 0,
181 unsigned long nary = 0UL,
bool withFree =
true);
182 void ExecWithReturn(
void* address,
void* ret = 0);
183 void ExecWithArgsAndReturn(
void* address,
184 const void* args[] = 0,
187 void Exec(
void* address, TInterpreterValue* interpVal = 0);
188 long ExecInt(
void* address);
189 long long ExecInt64(
void* address);
190 double ExecDouble(
void* address);
191 TClingMethodInfo* FactoryMethod()
const;
192 void IgnoreExtraArgs(
bool ignore) { fIgnoreExtraArgs = ignore; }
194 void Init(
const TClingMethodInfo&);
195 void Init(std::unique_ptr<TClingMethodInfo>);
196 void Invoke(cling::Value* result = 0)
const;
197 void* InterfaceMethod();
198 bool IsValid()
const;
199 TInterpreter::CallFuncIFacePtr_t IFacePtr();
200 const clang::FunctionDecl *GetDecl() {
202 fDecl = fMethod->GetMethodDecl();
206 int get_wrapper_code(std::string &wrapper_name, std::string &wrapper);
208 const clang::FunctionDecl* GetDecl()
const {
211 return fMethod->GetMethodDecl();
214 void SetArg(
long arg);
215 void SetArg(
unsigned long arg);
216 void SetArg(
float arg);
217 void SetArg(
double arg);
218 void SetArg(
long long arg);
219 void SetArg(
unsigned long long arg);
220 void SetArgArray(
long* argArr,
int narg);
221 void SetArgs(
const char* args);
222 void SetFunc(
const TClingClassInfo* info,
const char* method,
223 const char* arglist,
long* poffset);
224 void SetFunc(
const TClingClassInfo* info,
const char* method,
225 const char* arglist,
bool objectIsConst,
long* poffset);
226 void SetFunc(
const TClingMethodInfo* info);
227 void SetFuncProto(
const TClingClassInfo* info,
const char* method,
228 const char* proto,
long* poffset,
229 ROOT::EFunctionMatchMode mode = ROOT::kConversionMatch);
230 void SetFuncProto(
const TClingClassInfo* info,
const char* method,
231 const char* proto,
bool objectIsConst,
long* poffset,
232 ROOT::EFunctionMatchMode mode = ROOT::kConversionMatch);
233 void SetFuncProto(
const TClingClassInfo* info,
const char* method,
234 const llvm::SmallVectorImpl<clang::QualType>& proto,
236 ROOT::EFunctionMatchMode mode = ROOT::kConversionMatch);
237 void SetFuncProto(
const TClingClassInfo* info,
const char* method,
238 const llvm::SmallVectorImpl<clang::QualType>& proto,
239 bool objectIsConst,
long* poffset,
240 ROOT::EFunctionMatchMode mode = ROOT::kConversionMatch);
243 #endif // ROOT_CallFunc