Logo ROOT  
Reference Guide
TClingCallFunc.cxx
Go to the documentation of this file.
1 // root/core/meta
2 // vim: sw=3
3 // Author: Paul Russo 30/07/2012
4 // Author: Vassil Vassilev 9/02/2013
5 
6 /*************************************************************************
7  * Copyright (C) 1995-2013, Rene Brun and Fons Rademakers. *
8  * All rights reserved. *
9  * *
10  * For the licensing terms see $ROOTSYS/LICENSE. *
11  * For the list of contributors see $ROOTSYS/README/CREDITS. *
12  *************************************************************************/
13 
14 /** \class TClingCallFunc
15 Emulation of the CINT CallFunc class.
16 
17 The CINT C++ interpreter provides an interface for calling
18 functions through the generated wrappers in dictionaries with
19 the CallFunc class. This class provides the same functionality,
20 using an interface as close as possible to CallFunc but the
21 function metadata and calling service comes from the Cling
22 C++ interpreter and the Clang C++ compiler, not CINT.
23 */
24 
25 #include "TClingCallFunc.h"
26 
27 #include "TClingClassInfo.h"
28 #include "TClingMethodInfo.h"
29 #include "TInterpreterValue.h"
30 #include "TClingUtils.h"
31 
32 #include "TError.h"
33 #include "TCling.h"
34 
35 #include "cling/Interpreter/CompilationOptions.h"
36 #include "cling/Interpreter/Interpreter.h"
37 #include "cling/Interpreter/LookupHelper.h"
38 #include "cling/Interpreter/Transaction.h"
39 #include "cling/Interpreter/Value.h"
40 #include "cling/Utils/AST.h"
41 
42 #include "clang/AST/ASTContext.h"
43 #include "clang/AST/Decl.h"
44 #include "clang/AST/DeclCXX.h"
45 #include "clang/AST/GlobalDecl.h"
46 #include "clang/AST/PrettyPrinter.h"
47 #include "clang/AST/RecordLayout.h"
48 #include "clang/AST/Type.h"
49 #include "clang/Frontend/CompilerInstance.h"
50 #include "clang/Lex/Preprocessor.h"
51 #include "clang/Sema/Sema.h"
52 #include "clang/Sema/Lookup.h"
53 
54 #include "llvm/ADT/APInt.h"
55 #include "llvm/ExecutionEngine/ExecutionEngine.h"
56 #include "llvm/ExecutionEngine/GenericValue.h"
57 #include "llvm/Support/Casting.h"
58 #include "llvm/Support/raw_ostream.h"
59 #include "llvm/IR/LLVMContext.h"
60 #include "llvm/IR/DerivedTypes.h"
61 #include "llvm/IR/Function.h"
62 #include "llvm/IR/GlobalValue.h"
63 #include "llvm/IR/Module.h"
64 #include "llvm/IR/Type.h"
65 
66 #include "clang/Sema/SemaInternal.h"
67 
68 #include <map>
69 #include <string>
70 #include <sstream>
71 
72 using namespace ROOT;
73 using namespace llvm;
74 using namespace clang;
75 using namespace std;
76 
77 static unsigned long long gWrapperSerial = 0LL;
78 static const string kIndentString(" ");
79 
80 static map<const FunctionDecl *, void *> gWrapperStore;
81 static map<const Decl *, void *> gCtorWrapperStore;
82 static map<const Decl *, void *> gDtorWrapperStore;
83 
84 static
85 inline
86 void
87 indent(ostringstream &buf, int indent_level)
88 {
89  for (int i = 0; i < indent_level; ++i) {
90  buf << kIndentString;
91  }
92 }
93 
94 static
95 void
96 EvaluateExpr(cling::Interpreter &interp, const Expr *E, cling::Value &V)
97 {
98  // Evaluate an Expr* and return its cling::Value
99  ASTContext &C = interp.getCI()->getASTContext();
100  APSInt res;
101  if (E->EvaluateAsInt(res, C, /*AllowSideEffects*/Expr::SE_NoSideEffects)) {
102  // IntTy or maybe better E->getType()?
103  V = cling::Value(C.IntTy, interp);
104  // We must use the correct signedness otherwise the zero extension
105  // fails if the actual type is strictly less than long long.
106  if (res.isSigned())
107  V.getLL() = res.getSExtValue();
108  else
109  V.getULL() = res.getZExtValue();
110  return;
111  }
112  // TODO: Build a wrapper around the expression to avoid decompilation and
113  // compilation and other string operations.
114  PrintingPolicy Policy(C.getPrintingPolicy());
115  Policy.SuppressTagKeyword = true;
116  Policy.SuppressUnwrittenScope = false;
117  Policy.SuppressInitializers = false;
118  Policy.AnonymousTagLocations = false;
119  string buf;
120  raw_string_ostream out(buf);
121  E->printPretty(out, /*Helper=*/0, Policy, /*Indentation=*/0);
122  out << ';'; // no value printing
123  out.flush();
124  // Evaluate() will set V to invalid if evaluation fails.
125  interp.evaluate(buf, V);
126 }
127 
128 namespace {
129  template <typename returnType>
130  returnType sv_to(const cling::Value &val)
131  {
132  QualType QT = val.getType().getCanonicalType();
133  if (const BuiltinType *BT =
134  dyn_cast<BuiltinType>(&*QT)) {
135  //
136  // WARNING!!!
137  //
138  // This switch is organized in order-of-declaration
139  // so that the produced assembly code is optimal.
140  // Do not reorder!
141  //
142  switch (BT->getKind()) {
143  case BuiltinType::Void:
144  // CINT used to expect a result of 0.
145  return (returnType) 0;
146  break;
147  //
148  // Unsigned Types
149  //
150  case BuiltinType::Bool:
151  case BuiltinType::Char_U: // char on targets where it is unsigned
152  case BuiltinType::UChar:
153  return (returnType) val.getULL();
154  break;
155 
156  case BuiltinType::WChar_U:
157  // wchar_t on targets where it is unsigned
158  // The standard doesn't allow to specify signednedd of wchar_t
159  // thus this maps simply to wchar_t.
160  return (returnType)(wchar_t) val.getULL();
161  break;
162 
163  case BuiltinType::Char16:
164  case BuiltinType::Char32:
165  case BuiltinType::UShort:
166  case BuiltinType::UInt:
167  case BuiltinType::ULong:
168  case BuiltinType::ULongLong:
169  return (returnType) val.getULL();
170  break;
171 
172  case BuiltinType::UInt128:
173  // __uint128_t
174  break;
175 
176  //
177  // Signed Types
178  //
179  case BuiltinType::Char_S: // char on targets where it is signed
180  case BuiltinType::SChar:
181  return (returnType) val.getLL();
182  break;
183 
184  case BuiltinType::WChar_S:
185  // wchar_t on targets where it is signed
186  // The standard doesn't allow to specify signednedd of wchar_t
187  // thus this maps simply to wchar_t.
188  return (returnType)(wchar_t) val.getLL();
189  break;
190 
191  case BuiltinType::Short:
192  case BuiltinType::Int:
193  case BuiltinType::Long:
194  case BuiltinType::LongLong:
195  return (returnType) val.getLL();
196  break;
197 
198  case BuiltinType::Int128:
199  break;
200 
201  case BuiltinType::Half:
202  // half in OpenCL, __fp16 in ARM NEON
203  break;
204 
205  case BuiltinType::Float:
206  return (returnType) val.getFloat();
207  break;
208  case BuiltinType::Double:
209  return (returnType) val.getDouble();
210  break;
211  case BuiltinType::LongDouble:
212  return (returnType) val.getLongDouble();
213  break;
214 
215  case BuiltinType::NullPtr:
216  return (returnType) 0;
217  break;
218 
219  default:
220  break;
221  }
222  }
223  if (QT->isPointerType() || QT->isArrayType() || QT->isRecordType() ||
224  QT->isReferenceType()) {
225  return (returnType)(long) val.getPtr();
226  }
227  if (const EnumType *ET = dyn_cast<EnumType>(&*QT)) {
228  if (ET->getDecl()->getIntegerType()->hasSignedIntegerRepresentation())
229  return (returnType) val.getLL();
230  else
231  return (returnType) val.getULL();
232  }
233  if (QT->isMemberPointerType()) {
234  const MemberPointerType *MPT = QT->getAs<MemberPointerType>();
235  if (MPT->isMemberDataPointer()) {
236  return (returnType)(ptrdiff_t)val.getPtr();
237  }
238  return (returnType)(long) val.getPtr();
239  }
240  ::Error("TClingCallFunc::sv_to", "Invalid Type!");
241  QT->dump();
242  return 0;
243  }
244 
245  static
246  long long sv_to_long_long(const cling::Value &val)
247  {
248  return sv_to<long long>(val);
249  }
250  static
251  unsigned long long sv_to_ulong_long(const cling::Value &val)
252  {
253  return sv_to<unsigned long long>(val);
254  }
255 
256 } // unnamed namespace.
257 
259 {
260  // This function is non-const to use caching overload of GetDecl()!
261  return GetDecl()->getMinRequiredArguments();
262 }
263 
264 void *TClingCallFunc::compile_wrapper(const string &wrapper_name, const string &wrapper,
265  bool withAccessControl/*=true*/)
266 {
267  return fInterp->compileFunction(wrapper_name, wrapper, false /*ifUnique*/,
268  withAccessControl);
269 }
270 
271 void TClingCallFunc::collect_type_info(QualType &QT, ostringstream &typedefbuf, std::ostringstream &callbuf,
272  string &type_name, EReferenceType &refType, bool &isPointer, int indent_level,
273  bool forArgument)
274 {
275  //
276  // Collect information about type type of a function parameter
277  // needed for building the wrapper function.
278  //
279  const FunctionDecl *FD = GetDecl();
280  PrintingPolicy Policy(FD->getASTContext().getPrintingPolicy());
281  refType = kNotReference;
282  if (QT->isRecordType() && forArgument) {
283  ROOT::TMetaUtils::GetNormalizedName(type_name, QT, *fInterp, fNormCtxt);
284  return;
285  }
286  if (QT->isFunctionPointerType()) {
287  string fp_typedef_name;
288  {
289  ostringstream nm;
290  nm << "FP" << gWrapperSerial++;
291  type_name = nm.str();
292  raw_string_ostream OS(fp_typedef_name);
293  QT.print(OS, Policy, type_name);
294  OS.flush();
295  }
296  for (int i = 0; i < indent_level; ++i) {
297  typedefbuf << kIndentString;
298  }
299  typedefbuf << "typedef " << fp_typedef_name << ";\n";
300  return;
301  } else if (QT->isMemberPointerType()) {
302  string mp_typedef_name;
303  {
304  ostringstream nm;
305  nm << "MP" << gWrapperSerial++;
306  type_name = nm.str();
307  raw_string_ostream OS(mp_typedef_name);
308  QT.print(OS, Policy, type_name);
309  OS.flush();
310  }
311  for (int i = 0; i < indent_level; ++i) {
312  typedefbuf << kIndentString;
313  }
314  typedefbuf << "typedef " << mp_typedef_name << ";\n";
315  return;
316  } else if (QT->isPointerType()) {
317  isPointer = true;
318  QT = cast<clang::PointerType>(QT)->getPointeeType();
319  } else if (QT->isReferenceType()) {
320  if (QT->isRValueReferenceType()) refType = kRValueReference;
321  else refType = kLValueReference;
322  QT = cast<ReferenceType>(QT)->getPointeeType();
323  }
324  // Fall through for the array type to deal with reference/pointer ro array type.
325  if (QT->isArrayType()) {
326  string ar_typedef_name;
327  {
328  ostringstream ar;
329  ar << "AR" << gWrapperSerial++;
330  type_name = ar.str();
331  raw_string_ostream OS(ar_typedef_name);
332  QT.print(OS, Policy, type_name);
333  OS.flush();
334  }
335  for (int i = 0; i < indent_level; ++i) {
336  typedefbuf << kIndentString;
337  }
338  typedefbuf << "typedef " << ar_typedef_name << ";\n";
339  return;
340  }
341  ROOT::TMetaUtils::GetNormalizedName(type_name, QT, *fInterp, fNormCtxt);
342 }
343 
344 void TClingCallFunc::make_narg_ctor(const unsigned N, ostringstream &typedefbuf,
345  ostringstream &callbuf, const string &class_name,
346  int indent_level)
347 {
348  // Make a code string that follows this pattern:
349  //
350  // new ClassName(args...)
351  //
352  const FunctionDecl *FD = GetDecl();
353 
354  callbuf << "new " << class_name << "(";
355  for (unsigned i = 0U; i < N; ++i) {
356  const ParmVarDecl *PVD = FD->getParamDecl(i);
357  QualType Ty = PVD->getType();
358  QualType QT = Ty.getCanonicalType();
359  string type_name;
360  EReferenceType refType = kNotReference;
361  bool isPointer = false;
362  collect_type_info(QT, typedefbuf, callbuf, type_name,
363  refType, isPointer, indent_level, true);
364  if (i) {
365  callbuf << ',';
366  if (i % 2) {
367  callbuf << ' ';
368  } else {
369  callbuf << "\n";
370  for (int j = 0; j <= indent_level; ++j) {
371  callbuf << kIndentString;
372  }
373  }
374  }
375  if (refType != kNotReference) {
376  callbuf << "(" << type_name.c_str() <<
377  (refType == kLValueReference ? "&" : "&&") << ")*(" << type_name.c_str() << "*)args["
378  << i << "]";
379  } else if (isPointer) {
380  callbuf << "*(" << type_name.c_str() << "**)args["
381  << i << "]";
382  } else {
383  callbuf << "*(" << type_name.c_str() << "*)args[" << i << "]";
384  }
385  }
386  callbuf << ")";
387 }
388 
389 void TClingCallFunc::make_narg_call(const std::string &return_type, const unsigned N, ostringstream &typedefbuf,
390  ostringstream &callbuf, const string &class_name, int indent_level)
391 {
392  //
393  // Make a code string that follows this pattern:
394  //
395  // ((<class>*)obj)-><method>(*(<arg-i-type>*)args[i], ...)
396  //
397  const FunctionDecl *FD = GetDecl();
398 
399  // Sometimes it's necessary that we cast the function we want to call first
400  // to its explicit function type before calling it. This is supposed to prevent
401  // that we accidentially ending up in a function that is not the one we're
402  // supposed to call here (e.g. because the C++ function lookup decides to take
403  // another function that better fits).
404  // This method has some problems, e.g. when we call a function with default
405  // arguments and we don't provide all arguments, we would fail with this pattern.
406  // Same applies with member methods which seem to cause parse failures even when
407  // we supply the object parameter.
408  // Therefore we only use it in cases where we know it works and set this variable
409  // to true when we do.
410  bool ShouldCastFunction = !isa<CXXMethodDecl>(FD) && N == FD->getNumParams();
411  if (ShouldCastFunction) {
412  callbuf << "(";
413  callbuf << "(";
414  callbuf << return_type << " (&)";
415  {
416  callbuf << "(";
417  for (unsigned i = 0U; i < N; ++i) {
418  if (i) {
419  callbuf << ',';
420  if (i % 2) {
421  callbuf << ' ';
422  } else {
423  callbuf << "\n";
424  for (int j = 0; j <= indent_level; ++j) {
425  callbuf << kIndentString;
426  }
427  }
428  }
429  const ParmVarDecl *PVD = FD->getParamDecl(i);
430  QualType Ty = PVD->getType();
431  QualType QT = Ty.getCanonicalType();
432  std::string arg_type;
433  ROOT::TMetaUtils::GetNormalizedName(arg_type, QT, *fInterp, fNormCtxt);
434  callbuf << arg_type;
435  }
436  if (FD->isVariadic())
437  callbuf << ", ...";
438  callbuf << ")";
439  }
440 
441  callbuf << ")";
442  }
443 
444  if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(FD)) {
445  // This is a class, struct, or union member.
446  if (MD->isConst())
447  callbuf << "((const " << class_name << "*)obj)->";
448  else
449  callbuf << "((" << class_name << "*)obj)->";
450  } else if (const NamedDecl *ND =
451  dyn_cast<NamedDecl>(FD->getDeclContext())) {
452  // This is a namespace member.
453  (void) ND;
454  callbuf << class_name << "::";
455  }
456  // callbuf << fMethod->Name() << "(";
457  {
458  std::string name;
459  {
460  llvm::raw_string_ostream stream(name);
461  FD->getNameForDiagnostic(stream, FD->getASTContext().getPrintingPolicy(), /*Qualified=*/false);
462  }
463  callbuf << name;
464  }
465  if (ShouldCastFunction) callbuf << ")";
466 
467  callbuf << "(";
468  for (unsigned i = 0U; i < N; ++i) {
469  const ParmVarDecl *PVD = FD->getParamDecl(i);
470  QualType Ty = PVD->getType();
471  QualType QT = Ty.getCanonicalType();
472  string type_name;
473  EReferenceType refType = kNotReference;
474  bool isPointer = false;
475  collect_type_info(QT, typedefbuf, callbuf, type_name, refType, isPointer, indent_level, true);
476 
477  if (i) {
478  callbuf << ',';
479  if (i % 2) {
480  callbuf << ' ';
481  } else {
482  callbuf << "\n";
483  for (int j = 0; j <= indent_level; ++j) {
484  callbuf << kIndentString;
485  }
486  }
487  }
488 
489  if (refType != kNotReference) {
490  callbuf << "(" << type_name.c_str() <<
491  (refType == kLValueReference ? "&" : "&&") << ")*(" << type_name.c_str() << "*)args["
492  << i << "]";
493  } else if (isPointer) {
494  callbuf << "*(" << type_name.c_str() << "**)args["
495  << i << "]";
496  } else {
497  // pointer falls back to non-pointer case; the argument preserves
498  // the "pointerness" (i.e. doesn't reference the value).
499  callbuf << "*(" << type_name.c_str() << "*)args[" << i << "]";
500  }
501  }
502  callbuf << ")";
503 }
504 
505 void TClingCallFunc::make_narg_ctor_with_return(const unsigned N, const string &class_name,
506  ostringstream &buf, int indent_level)
507 {
508  // Make a code string that follows this pattern:
509  //
510  // if (ret) {
511  // (*(ClassName**)ret) = new ClassName(args...);
512  // }
513  // else {
514  // new ClassName(args...);
515  // }
516  //
517  for (int i = 0; i < indent_level; ++i) {
518  buf << kIndentString;
519  }
520  buf << "if (ret) {\n";
521  ++indent_level;
522  {
523  ostringstream typedefbuf;
524  ostringstream callbuf;
525  //
526  // Write the return value assignment part.
527  //
528  for (int i = 0; i < indent_level; ++i) {
529  callbuf << kIndentString;
530  }
531  callbuf << "(*(" << class_name << "**)ret) = ";
532  //
533  // Write the actual new expression.
534  //
535  make_narg_ctor(N, typedefbuf, callbuf, class_name, indent_level);
536  //
537  // End the new expression statement.
538  //
539  callbuf << ";\n";
540  for (int i = 0; i < indent_level; ++i) {
541  callbuf << kIndentString;
542  }
543  callbuf << "return;\n";
544  //
545  // Output the whole new expression and return statement.
546  //
547  buf << typedefbuf.str() << callbuf.str();
548  }
549  --indent_level;
550  for (int i = 0; i < indent_level; ++i) {
551  buf << kIndentString;
552  }
553  buf << "}\n";
554  for (int i = 0; i < indent_level; ++i) {
555  buf << kIndentString;
556  }
557  buf << "else {\n";
558  ++indent_level;
559  {
560  ostringstream typedefbuf;
561  ostringstream callbuf;
562  for (int i = 0; i < indent_level; ++i) {
563  callbuf << kIndentString;
564  }
565  make_narg_ctor(N, typedefbuf, callbuf, class_name, indent_level);
566  callbuf << ";\n";
567  for (int i = 0; i < indent_level; ++i) {
568  callbuf << kIndentString;
569  }
570  callbuf << "return;\n";
571  buf << typedefbuf.str() << callbuf.str();
572  }
573  --indent_level;
574  for (int i = 0; i < indent_level; ++i) {
575  buf << kIndentString;
576  }
577  buf << "}\n";
578 }
579 
580 int TClingCallFunc::get_wrapper_code(std::string &wrapper_name, std::string &wrapper)
581 {
582  const FunctionDecl *FD = GetDecl();
583  assert(FD && "generate_wrapper called without a function decl!");
584  ASTContext &Context = FD->getASTContext();
585  PrintingPolicy Policy(Context.getPrintingPolicy());
586  //
587  // Get the class or namespace name.
588  //
589  string class_name;
590  if (const TypeDecl *TD = dyn_cast<TypeDecl>(FD->getDeclContext())) {
591  // This is a class, struct, or union member.
592  QualType QT(TD->getTypeForDecl(), 0);
593  ROOT::TMetaUtils::GetNormalizedName(class_name, QT, *fInterp, fNormCtxt);
594  } else if (const NamedDecl *ND = dyn_cast<NamedDecl>(FD->getDeclContext())) {
595  // This is a namespace member.
596  raw_string_ostream stream(class_name);
597  ND->getNameForDiagnostic(stream, Policy, /*Qualified=*/true);
598  stream.flush();
599  }
600  //
601  // Check to make sure that we can
602  // instantiate and codegen this function.
603  //
604  bool needInstantiation = false;
605  const FunctionDecl *Definition = 0;
606  if (!FD->isDefined(Definition)) {
607  FunctionDecl::TemplatedKind TK = FD->getTemplatedKind();
608  switch (TK) {
609  case FunctionDecl::TK_NonTemplate: {
610  // Ordinary function, not a template specialization.
611  // Note: This might be ok, the body might be defined
612  // in a library, and all we have seen is the
613  // header file.
614  //::Error("TClingCallFunc::make_wrapper",
615  // "Cannot make wrapper for a function which is "
616  // "declared but not defined!");
617  // return 0;
618  } break;
619  case FunctionDecl::TK_FunctionTemplate: {
620  // This decl is actually a function template,
621  // not a function at all.
622  ::Error("TClingCallFunc::make_wrapper", "Cannot make wrapper for a function template!");
623  return 0;
624  } break;
625  case FunctionDecl::TK_MemberSpecialization: {
626  // This function is the result of instantiating an ordinary
627  // member function of a class template, or of instantiating
628  // an ordinary member function of a class member of a class
629  // template, or of specializing a member function template
630  // of a class template, or of specializing a member function
631  // template of a class member of a class template.
632  if (!FD->isTemplateInstantiation()) {
633  // We are either TSK_Undeclared or
634  // TSK_ExplicitSpecialization.
635  // Note: This might be ok, the body might be defined
636  // in a library, and all we have seen is the
637  // header file.
638  //::Error("TClingCallFunc::make_wrapper",
639  // "Cannot make wrapper for a function template "
640  // "explicit specialization which is declared "
641  // "but not defined!");
642  // return 0;
643  break;
644  }
645  const FunctionDecl *Pattern = FD->getTemplateInstantiationPattern();
646  if (!Pattern) {
647  ::Error("TClingCallFunc::make_wrapper", "Cannot make wrapper for a member function "
648  "instantiation with no pattern!");
649  return 0;
650  }
651  FunctionDecl::TemplatedKind PTK = Pattern->getTemplatedKind();
652  TemplateSpecializationKind PTSK = Pattern->getTemplateSpecializationKind();
653  if (
654  // The pattern is an ordinary member function.
655  (PTK == FunctionDecl::TK_NonTemplate) ||
656  // The pattern is an explicit specialization, and
657  // so is not a template.
658  ((PTK != FunctionDecl::TK_FunctionTemplate) &&
659  ((PTSK == TSK_Undeclared) || (PTSK == TSK_ExplicitSpecialization)))) {
660  // Note: This might be ok, the body might be defined
661  // in a library, and all we have seen is the
662  // header file.
663  break;
664  } else if (!Pattern->hasBody()) {
665  ::Error("TClingCallFunc::make_wrapper", "Cannot make wrapper for a member function "
666  "instantiation with no body!");
667  return 0;
668  }
669  if (FD->isImplicitlyInstantiable()) {
670  needInstantiation = true;
671  }
672  } break;
673  case FunctionDecl::TK_FunctionTemplateSpecialization: {
674  // This function is the result of instantiating a function
675  // template or possibly an explicit specialization of a
676  // function template. Could be a namespace scope function or a
677  // member function.
678  if (!FD->isTemplateInstantiation()) {
679  // We are either TSK_Undeclared or
680  // TSK_ExplicitSpecialization.
681  // Note: This might be ok, the body might be defined
682  // in a library, and all we have seen is the
683  // header file.
684  //::Error("TClingCallFunc::make_wrapper",
685  // "Cannot make wrapper for a function template "
686  // "explicit specialization which is declared "
687  // "but not defined!");
688  // return 0;
689  break;
690  }
691  const FunctionDecl *Pattern = FD->getTemplateInstantiationPattern();
692  if (!Pattern) {
693  ::Error("TClingCallFunc::make_wrapper", "Cannot make wrapper for a function template"
694  "instantiation with no pattern!");
695  return 0;
696  }
697  FunctionDecl::TemplatedKind PTK = Pattern->getTemplatedKind();
698  TemplateSpecializationKind PTSK = Pattern->getTemplateSpecializationKind();
699  if (
700  // The pattern is an ordinary member function.
701  (PTK == FunctionDecl::TK_NonTemplate) ||
702  // The pattern is an explicit specialization, and
703  // so is not a template.
704  ((PTK != FunctionDecl::TK_FunctionTemplate) &&
705  ((PTSK == TSK_Undeclared) || (PTSK == TSK_ExplicitSpecialization)))) {
706  // Note: This might be ok, the body might be defined
707  // in a library, and all we have seen is the
708  // header file.
709  break;
710  }
711  if (!Pattern->hasBody()) {
712  ::Error("TClingCallFunc::make_wrapper", "Cannot make wrapper for a function template"
713  "instantiation with no body!");
714  return 0;
715  }
716  if (FD->isImplicitlyInstantiable()) {
717  needInstantiation = true;
718  }
719  } break;
720  case FunctionDecl::TK_DependentFunctionTemplateSpecialization: {
721  // This function is the result of instantiating or
722  // specializing a member function of a class template,
723  // or a member function of a class member of a class template,
724  // or a member function template of a class template, or a
725  // member function template of a class member of a class
726  // template where at least some part of the function is
727  // dependent on a template argument.
728  if (!FD->isTemplateInstantiation()) {
729  // We are either TSK_Undeclared or
730  // TSK_ExplicitSpecialization.
731  // Note: This might be ok, the body might be defined
732  // in a library, and all we have seen is the
733  // header file.
734  //::Error("TClingCallFunc::make_wrapper",
735  // "Cannot make wrapper for a dependent function "
736  // "template explicit specialization which is declared "
737  // "but not defined!");
738  // return 0;
739  break;
740  }
741  const FunctionDecl *Pattern = FD->getTemplateInstantiationPattern();
742  if (!Pattern) {
743  ::Error("TClingCallFunc::make_wrapper", "Cannot make wrapper for a dependent function template"
744  "instantiation with no pattern!");
745  return 0;
746  }
747  FunctionDecl::TemplatedKind PTK = Pattern->getTemplatedKind();
748  TemplateSpecializationKind PTSK = Pattern->getTemplateSpecializationKind();
749  if (
750  // The pattern is an ordinary member function.
751  (PTK == FunctionDecl::TK_NonTemplate) ||
752  // The pattern is an explicit specialization, and
753  // so is not a template.
754  ((PTK != FunctionDecl::TK_FunctionTemplate) &&
755  ((PTSK == TSK_Undeclared) || (PTSK == TSK_ExplicitSpecialization)))) {
756  // Note: This might be ok, the body might be defined
757  // in a library, and all we have seen is the
758  // header file.
759  break;
760  }
761  if (!Pattern->hasBody()) {
762  ::Error("TClingCallFunc::make_wrapper", "Cannot make wrapper for a dependent function template"
763  "instantiation with no body!");
764  return 0;
765  }
766  if (FD->isImplicitlyInstantiable()) {
767  needInstantiation = true;
768  }
769  } break;
770  default: {
771  // Will only happen if clang implementation changes.
772  // Protect ourselves in case that happens.
773  ::Error("TClingCallFunc::make_wrapper", "Unhandled template kind!");
774  return 0;
775  } break;
776  }
777  // We do not set needInstantiation to true in these cases:
778  //
779  // isInvalidDecl()
780  // TSK_Undeclared
781  // TSK_ExplicitInstantiationDefinition
782  // TSK_ExplicitSpecialization && !getClassScopeSpecializationPattern()
783  // TSK_ExplicitInstantiationDeclaration &&
784  // getTemplateInstantiationPattern() &&
785  // PatternDecl->hasBody() &&
786  // !PatternDecl->isInlined()
787  //
788  // Set it true in these cases:
789  //
790  // TSK_ImplicitInstantiation
791  // TSK_ExplicitInstantiationDeclaration && (!getPatternDecl() ||
792  // !PatternDecl->hasBody() || PatternDecl->isInlined())
793  //
794  }
795  if (needInstantiation) {
796  clang::FunctionDecl *FDmod = const_cast<clang::FunctionDecl *>(FD);
797  clang::Sema &S = fInterp->getSema();
798  // Could trigger deserialization of decls.
799  cling::Interpreter::PushTransactionRAII RAII(fInterp);
800  S.InstantiateFunctionDefinition(SourceLocation(), FDmod,
801  /*Recursive=*/true,
802  /*DefinitionRequired=*/true);
803  if (!FD->isDefined(Definition)) {
804  ::Error("TClingCallFunc::make_wrapper", "Failed to force template instantiation!");
805  return 0;
806  }
807  }
808  if (Definition) {
809  FunctionDecl::TemplatedKind TK = Definition->getTemplatedKind();
810  switch (TK) {
811  case FunctionDecl::TK_NonTemplate: {
812  // Ordinary function, not a template specialization.
813  if (Definition->isDeleted()) {
814  ::Error("TClingCallFunc::make_wrapper", "Cannot make wrapper for a deleted function!");
815  return 0;
816  } else if (Definition->isLateTemplateParsed()) {
817  ::Error("TClingCallFunc::make_wrapper", "Cannot make wrapper for a late template parsed "
818  "function!");
819  return 0;
820  }
821  // else if (Definition->isDefaulted()) {
822  // // Might not have a body, but we can still use it.
823  //}
824  // else {
825  // // Has a body.
826  //}
827  } break;
828  case FunctionDecl::TK_FunctionTemplate: {
829  // This decl is actually a function template,
830  // not a function at all.
831  ::Error("TClingCallFunc::make_wrapper", "Cannot make wrapper for a function template!");
832  return 0;
833  } break;
834  case FunctionDecl::TK_MemberSpecialization: {
835  // This function is the result of instantiating an ordinary
836  // member function of a class template or of a member class
837  // of a class template.
838  if (Definition->isDeleted()) {
839  ::Error("TClingCallFunc::make_wrapper", "Cannot make wrapper for a deleted member function "
840  "of a specialization!");
841  return 0;
842  } else if (Definition->isLateTemplateParsed()) {
843  ::Error("TClingCallFunc::make_wrapper", "Cannot make wrapper for a late template parsed "
844  "member function of a specialization!");
845  return 0;
846  }
847  // else if (Definition->isDefaulted()) {
848  // // Might not have a body, but we can still use it.
849  //}
850  // else {
851  // // Has a body.
852  //}
853  } break;
854  case FunctionDecl::TK_FunctionTemplateSpecialization: {
855  // This function is the result of instantiating a function
856  // template or possibly an explicit specialization of a
857  // function template. Could be a namespace scope function or a
858  // member function.
859  if (Definition->isDeleted()) {
860  ::Error("TClingCallFunc::make_wrapper", "Cannot make wrapper for a deleted function "
861  "template specialization!");
862  return 0;
863  } else if (Definition->isLateTemplateParsed()) {
864  ::Error("TClingCallFunc::make_wrapper", "Cannot make wrapper for a late template parsed "
865  "function template specialization!");
866  return 0;
867  }
868  // else if (Definition->isDefaulted()) {
869  // // Might not have a body, but we can still use it.
870  //}
871  // else {
872  // // Has a body.
873  //}
874  } break;
875  case FunctionDecl::TK_DependentFunctionTemplateSpecialization: {
876  // This function is the result of instantiating or
877  // specializing a member function of a class template,
878  // or a member function of a class member of a class template,
879  // or a member function template of a class template, or a
880  // member function template of a class member of a class
881  // template where at least some part of the function is
882  // dependent on a template argument.
883  if (Definition->isDeleted()) {
884  ::Error("TClingCallFunc::make_wrapper", "Cannot make wrapper for a deleted dependent function "
885  "template specialization!");
886  return 0;
887  } else if (Definition->isLateTemplateParsed()) {
888  ::Error("TClingCallFunc::make_wrapper", "Cannot make wrapper for a late template parsed "
889  "dependent function template specialization!");
890  return 0;
891  }
892  // else if (Definition->isDefaulted()) {
893  // // Might not have a body, but we can still use it.
894  //}
895  // else {
896  // // Has a body.
897  //}
898  } break;
899  default: {
900  // Will only happen if clang implementation changes.
901  // Protect ourselves in case that happens.
902  ::Error("TClingCallFunc::make_wrapper", "Unhandled template kind!");
903  return 0;
904  } break;
905  }
906  }
907  unsigned min_args = GetMinRequiredArguments();
908  unsigned num_params = FD->getNumParams();
909  //
910  // Make the wrapper name.
911  //
912  {
913  ostringstream buf;
914  buf << "__cf";
915  // const NamedDecl* ND = dyn_cast<NamedDecl>(FD);
916  // string mn;
917  // fInterp->maybeMangleDeclName(ND, mn);
918  // buf << '_' << mn;
919  buf << '_' << gWrapperSerial++;
920  wrapper_name = buf.str();
921  }
922  //
923  // Write the wrapper code.
924  // FIXME: this should be synthesized into the AST!
925  //
926  int indent_level = 0;
927  ostringstream buf;
928  buf << "#pragma clang diagnostic push\n"
929  "#pragma clang diagnostic ignored \"-Wformat-security\"\n"
930  "__attribute__((used)) "
931  "extern \"C\" void ";
932  buf << wrapper_name;
933  buf << "(void* obj, int nargs, void** args, void* ret)\n"
934  "{\n";
935  ++indent_level;
936  if (min_args == num_params) {
937  // No parameters with defaults.
938  make_narg_call_with_return(num_params, class_name, buf, indent_level);
939  } else {
940  // We need one function call clause compiled for every
941  // possible number of arguments per call.
942  for (unsigned N = min_args; N <= num_params; ++N) {
943  for (int i = 0; i < indent_level; ++i) {
944  buf << kIndentString;
945  }
946  buf << "if (nargs == " << N << ") {\n";
947  ++indent_level;
948  make_narg_call_with_return(N, class_name, buf, indent_level);
949  --indent_level;
950  for (int i = 0; i < indent_level; ++i) {
951  buf << kIndentString;
952  }
953  buf << "}\n";
954  }
955  }
956  --indent_level;
957  buf << "}\n"
958  "#pragma clang diagnostic pop";
959  wrapper = buf.str();
960  return 1;
961 }
962 
963 void TClingCallFunc::make_narg_call_with_return(const unsigned N, const string &class_name,
964  ostringstream &buf, int indent_level)
965 {
966  // Make a code string that follows this pattern:
967  //
968  // if (ret) {
969  // new (ret) (return_type) ((class_name*)obj)->func(args...);
970  // }
971  // else {
972  // ((class_name*)obj)->func(args...);
973  // }
974  //
975  const FunctionDecl *FD = GetDecl();
976  if (const CXXConstructorDecl *CD = dyn_cast<CXXConstructorDecl>(FD)) {
977  (void) CD;
978  make_narg_ctor_with_return(N, class_name, buf, indent_level);
979  return;
980  }
981  QualType QT = FD->getReturnType().getCanonicalType();
982  if (QT->isVoidType()) {
983  ostringstream typedefbuf;
984  ostringstream callbuf;
985  for (int i = 0; i < indent_level; ++i) {
986  callbuf << kIndentString;
987  }
988  make_narg_call("void", N, typedefbuf, callbuf, class_name, indent_level);
989  callbuf << ";\n";
990  for (int i = 0; i < indent_level; ++i) {
991  callbuf << kIndentString;
992  }
993  callbuf << "return;\n";
994  buf << typedefbuf.str() << callbuf.str();
995  } else {
996  for (int i = 0; i < indent_level; ++i) {
997  buf << kIndentString;
998  }
999 
1000  string type_name;
1001  EReferenceType refType = kNotReference;
1002  bool isPointer = false;
1003 
1004  buf << "if (ret) {\n";
1005  ++indent_level;
1006  {
1007  ostringstream typedefbuf;
1008  ostringstream callbuf;
1009  //
1010  // Write the placement part of the placement new.
1011  //
1012  for (int i = 0; i < indent_level; ++i) {
1013  callbuf << kIndentString;
1014  }
1015  callbuf << "new (ret) ";
1016  collect_type_info(QT, typedefbuf, callbuf, type_name,
1017  refType, isPointer, indent_level, false);
1018  //
1019  // Write the type part of the placement new.
1020  //
1021  callbuf << "(" << type_name.c_str();
1022  if (refType != kNotReference) {
1023  callbuf << "*) (&";
1024  type_name += "&";
1025  } else if (isPointer) {
1026  callbuf << "*) (";
1027  type_name += "*";
1028  } else {
1029  callbuf << ") (";
1030  }
1031  //
1032  // Write the actual function call.
1033  //
1034  make_narg_call(type_name, N, typedefbuf, callbuf, class_name, indent_level);
1035  //
1036  // End the placement new.
1037  //
1038  callbuf << ");\n";
1039  for (int i = 0; i < indent_level; ++i) {
1040  callbuf << kIndentString;
1041  }
1042  callbuf << "return;\n";
1043  //
1044  // Output the whole placement new expression and return statement.
1045  //
1046  buf << typedefbuf.str() << callbuf.str();
1047  }
1048  --indent_level;
1049  for (int i = 0; i < indent_level; ++i) {
1050  buf << kIndentString;
1051  }
1052  buf << "}\n";
1053  for (int i = 0; i < indent_level; ++i) {
1054  buf << kIndentString;
1055  }
1056  buf << "else {\n";
1057  ++indent_level;
1058  {
1059  ostringstream typedefbuf;
1060  ostringstream callbuf;
1061  for (int i = 0; i < indent_level; ++i) {
1062  callbuf << kIndentString;
1063  }
1064  make_narg_call(type_name, N, typedefbuf, callbuf, class_name, indent_level);
1065  callbuf << ";\n";
1066  for (int i = 0; i < indent_level; ++i) {
1067  callbuf << kIndentString;
1068  }
1069  callbuf << "return;\n";
1070  buf << typedefbuf.str() << callbuf.str();
1071  }
1072  --indent_level;
1073  for (int i = 0; i < indent_level; ++i) {
1074  buf << kIndentString;
1075  }
1076  buf << "}\n";
1077  }
1078 }
1079 
1081 {
1083 
1084  const FunctionDecl *FD = GetDecl();
1085  string wrapper_name;
1086  string wrapper;
1087 
1088  if (get_wrapper_code(wrapper_name, wrapper) == 0) return 0;
1089 
1090  //fprintf(stderr, "%s\n", wrapper.c_str());
1091  //
1092  // Compile the wrapper code.
1093  //
1094  void *F = compile_wrapper(wrapper_name, wrapper);
1095  if (F) {
1096  gWrapperStore.insert(make_pair(FD, F));
1097  } else {
1098  ::Error("TClingCallFunc::make_wrapper",
1099  "Failed to compile\n ==== SOURCE BEGIN ====\n%s\n ==== SOURCE END ====",
1100  wrapper.c_str());
1101  }
1102  return (tcling_callfunc_Wrapper_t)F;
1103 }
1104 
1106  ROOT::TMetaUtils::EIOCtorCategory kind, const std::string &type_name)
1107 {
1108  // Make a code string that follows this pattern:
1109  //
1110  // void
1111  // unique_wrapper_ddd(void** ret, void* arena, unsigned long nary)
1112  // {
1113  // if (!arena) {
1114  // if (!nary) {
1115  // *ret = new ClassName;
1116  // }
1117  // else {
1118  // *ret = new ClassName[nary];
1119  // }
1120  // }
1121  // else {
1122  // if (!nary) {
1123  // *ret = new (arena) ClassName;
1124  // }
1125  // else {
1126  // *ret = new (arena) ClassName[nary];
1127  // }
1128  // }
1129  // }
1130  //
1131  // When I/O constructor used:
1132  //
1133  // void
1134  // unique_wrapper_ddd(void** ret, void* arena, unsigned long nary)
1135  // {
1136  // if (!arena) {
1137  // if (!nary) {
1138  // *ret = new ClassName((TRootIOCtor*)nullptr);
1139  // }
1140  // else {
1141  // char *buf = malloc(nary * sizeof(ClassName));
1142  // for (int k=0;k<nary;++k)
1143  // new (buf + k * sizeof(ClassName)) ClassName((TRootIOCtor*)nullptr);
1144  // *ret = buf;
1145  // }
1146  // }
1147  // else {
1148  // if (!nary) {
1149  // *ret = new (arena) ClassName((TRootIOCtor*)nullptr);
1150  // }
1151  // else {
1152  // for (int k=0;k<nary;++k)
1153  // new ((char *) arena + k * sizeof(ClassName)) ClassName((TRootIOCtor*)nullptr);
1154  // *ret = arena;
1155  // }
1156  // }
1157  // }
1158  //
1159  //
1160  // Note:
1161  //
1162  // If the class is of POD type, the form:
1163  //
1164  // new ClassName;
1165  //
1166  // does not initialize the object at all, and the form:
1167  //
1168  // new ClassName();
1169  //
1170  // default-initializes the object.
1171  //
1172  // We are using the form without parentheses because that is what
1173  // CINT did.
1174  //
1175  //--
1176  ASTContext &Context = info->GetDecl()->getASTContext();
1177  PrintingPolicy Policy(Context.getPrintingPolicy());
1178  Policy.SuppressTagKeyword = true;
1179  Policy.SuppressUnwrittenScope = true;
1180  //
1181  // Get the class or namespace name.
1182  //
1183  string class_name;
1184  if (const TypeDecl *TD = dyn_cast<TypeDecl>(info->GetDecl())) {
1185  // This is a class, struct, or union member.
1186  QualType QT(TD->getTypeForDecl(), 0);
1187  ROOT::TMetaUtils::GetNormalizedName(class_name, QT, *fInterp, fNormCtxt);
1188  } else if (const NamedDecl *ND = dyn_cast<NamedDecl>(info->GetDecl())) {
1189  // This is a namespace member.
1190  raw_string_ostream stream(class_name);
1191  ND->getNameForDiagnostic(stream, Policy, /*Qualified=*/true);
1192  stream.flush();
1193  }
1194 
1195 
1196  //
1197  // Make the wrapper name.
1198  //
1199  string wrapper_name;
1200  {
1201  ostringstream buf;
1202  buf << "__ctor";
1203  //const NamedDecl* ND = dyn_cast<NamedDecl>(FD);
1204  //string mn;
1205  //fInterp->maybeMangleDeclName(ND, mn);
1206  //buf << '_dtor_' << mn;
1207  buf << '_' << gWrapperSerial++;
1208  wrapper_name = buf.str();
1209  }
1210 
1211  string constr_arg;
1213  constr_arg = string("((") + type_name + "*)nullptr)";
1215  constr_arg = string("(*((") + type_name + "*)arena))";
1216 
1217  //
1218  // Write the wrapper code.
1219  //
1220  int indent_level = 0;
1221  ostringstream buf;
1222  buf << "__attribute__((used)) ";
1223  buf << "extern \"C\" void ";
1224  buf << wrapper_name;
1225  buf << "(void** ret, void* arena, unsigned long nary)\n";
1226  buf << "{\n";
1227 
1228  // if (!arena) {
1229  // if (!nary) {
1230  // *ret = new ClassName;
1231  // }
1232  // else {
1233  // *ret = new ClassName[nary];
1234  // }
1235  // }
1236  indent(buf, ++indent_level);
1237  buf << "if (!arena) {\n";
1238  indent(buf, ++indent_level);
1239  buf << "if (!nary) {\n";
1240  indent(buf, ++indent_level);
1241  buf << "*ret = new " << class_name << constr_arg << ";\n";
1242  indent(buf, --indent_level);
1243  buf << "}\n";
1244  indent(buf, indent_level);
1245  buf << "else {\n";
1246  indent(buf, ++indent_level);
1247  if (constr_arg.empty()) {
1248  buf << "*ret = new " << class_name << "[nary];\n";
1249  } else {
1250  buf << "char *buf = (char *) malloc(nary * sizeof(" << class_name << "));\n";
1251  indent(buf, indent_level);
1252  buf << "for (int k=0;k<nary;++k)\n";
1253  indent(buf, ++indent_level);
1254  buf << "new (buf + k * sizeof(" << class_name << ")) " << class_name << constr_arg << ";\n";
1255  indent(buf, --indent_level);
1256  buf << "*ret = buf;\n";
1257  }
1258  indent(buf, --indent_level);
1259  buf << "}\n";
1260  indent(buf, --indent_level);
1261  buf << "}\n";
1262  // else {
1263  // if (!nary) {
1264  // *ret = new (arena) ClassName;
1265  // }
1266  // else {
1267  // *ret = new (arena) ClassName[nary];
1268  // }
1269  // }
1270  indent(buf, indent_level);
1271  buf << "else {\n";
1272  indent(buf, ++indent_level);
1273  buf << "if (!nary) {\n";
1274  indent(buf, ++indent_level);
1275  buf << "*ret = new (arena) " << class_name << constr_arg << ";\n";
1276  indent(buf, --indent_level);
1277  buf << "}\n";
1278  indent(buf, indent_level);
1279  buf << "else {\n";
1280  indent(buf, ++indent_level);
1281  if (constr_arg.empty()) {
1282  buf << "*ret = new (arena) " << class_name << "[nary];\n";
1283  } else {
1284  buf << "for (int k=0;k<nary;++k)\n";
1285  indent(buf, ++indent_level);
1286  buf << "new ((char *) arena + k * sizeof(" << class_name << ")) " << class_name << constr_arg << ";\n";
1287  indent(buf, --indent_level);
1288  buf << "*ret = arena;\n";
1289  }
1290  indent(buf, --indent_level);
1291  buf << "}\n";
1292  indent(buf, --indent_level);
1293  buf << "}\n";
1294  // End wrapper.
1295  --indent_level;
1296  buf << "}\n";
1297  // Done.
1298  string wrapper(buf.str());
1299  //fprintf(stderr, "%s\n", wrapper.c_str());
1300  //
1301  // Compile the wrapper code.
1302  //
1303  void *F = compile_wrapper(wrapper_name, wrapper,
1304  /*withAccessControl=*/false);
1305  if (F) {
1306  gCtorWrapperStore.insert(make_pair(info->GetDecl(), F));
1307  } else {
1308  ::Error("TClingCallFunc::make_ctor_wrapper",
1309  "Failed to compile\n ==== SOURCE BEGIN ====\n%s\n ==== SOURCE END ====",
1310  wrapper.c_str());
1311  }
1313 }
1314 
1317 {
1318  // Make a code string that follows this pattern:
1319  //
1320  // void
1321  // unique_wrapper_ddd(void* obj, unsigned long nary, int withFree)
1322  // {
1323  // if (withFree) {
1324  // if (!nary) {
1325  // delete (ClassName*) obj;
1326  // }
1327  // else {
1328  // delete[] (ClassName*) obj;
1329  // }
1330  // }
1331  // else {
1332  // typedef ClassName DtorName;
1333  // if (!nary) {
1334  // ((ClassName*)obj)->~DtorName();
1335  // }
1336  // else {
1337  // for (unsigned long i = nary - 1; i > -1; --i) {
1338  // (((ClassName*)obj)+i)->~DtorName();
1339  // }
1340  // }
1341  // }
1342  // }
1343  //
1344  //--
1345  ASTContext &Context = info->GetDecl()->getASTContext();
1346  PrintingPolicy Policy(Context.getPrintingPolicy());
1347  Policy.SuppressTagKeyword = true;
1348  Policy.SuppressUnwrittenScope = true;
1349  //
1350  // Get the class or namespace name.
1351  //
1352  string class_name;
1353  if (const TypeDecl *TD = dyn_cast<TypeDecl>(info->GetDecl())) {
1354  // This is a class, struct, or union member.
1355  QualType QT(TD->getTypeForDecl(), 0);
1356  ROOT::TMetaUtils::GetNormalizedName(class_name, QT, *fInterp, fNormCtxt);
1357  } else if (const NamedDecl *ND = dyn_cast<NamedDecl>(info->GetDecl())) {
1358  // This is a namespace member.
1359  raw_string_ostream stream(class_name);
1360  ND->getNameForDiagnostic(stream, Policy, /*Qualified=*/true);
1361  stream.flush();
1362  }
1363  //
1364  // Make the wrapper name.
1365  //
1366  string wrapper_name;
1367  {
1368  ostringstream buf;
1369  buf << "__dtor";
1370  //const NamedDecl* ND = dyn_cast<NamedDecl>(FD);
1371  //string mn;
1372  //fInterp->maybeMangleDeclName(ND, mn);
1373  //buf << '_dtor_' << mn;
1374  buf << '_' << gWrapperSerial++;
1375  wrapper_name = buf.str();
1376  }
1377  //
1378  // Write the wrapper code.
1379  //
1380  int indent_level = 0;
1381  ostringstream buf;
1382  buf << "__attribute__((used)) ";
1383  buf << "extern \"C\" void ";
1384  buf << wrapper_name;
1385  buf << "(void* obj, unsigned long nary, int withFree)\n";
1386  buf << "{\n";
1387  // if (withFree) {
1388  // if (!nary) {
1389  // delete (ClassName*) obj;
1390  // }
1391  // else {
1392  // delete[] (ClassName*) obj;
1393  // }
1394  // }
1395  ++indent_level;
1396  indent(buf, indent_level);
1397  buf << "if (withFree) {\n";
1398  ++indent_level;
1399  indent(buf, indent_level);
1400  buf << "if (!nary) {\n";
1401  ++indent_level;
1402  indent(buf, indent_level);
1403  buf << "delete (" << class_name << "*) obj;\n";
1404  --indent_level;
1405  indent(buf, indent_level);
1406  buf << "}\n";
1407  indent(buf, indent_level);
1408  buf << "else {\n";
1409  ++indent_level;
1410  indent(buf, indent_level);
1411  buf << "delete[] (" << class_name << "*) obj;\n";
1412  --indent_level;
1413  indent(buf, indent_level);
1414  buf << "}\n";
1415  --indent_level;
1416  indent(buf, indent_level);
1417  buf << "}\n";
1418  // else {
1419  // typedef ClassName Nm;
1420  // if (!nary) {
1421  // ((Nm*)obj)->~Nm();
1422  // }
1423  // else {
1424  // for (unsigned long i = nary - 1; i > -1; --i) {
1425  // (((Nm*)obj)+i)->~Nm();
1426  // }
1427  // }
1428  // }
1429  indent(buf, indent_level);
1430  buf << "else {\n";
1431  ++indent_level;
1432  indent(buf, indent_level);
1433  buf << "typedef " << class_name << " Nm;\n";
1434  buf << "if (!nary) {\n";
1435  ++indent_level;
1436  indent(buf, indent_level);
1437  buf << "((Nm*)obj)->~Nm();\n";
1438  --indent_level;
1439  indent(buf, indent_level);
1440  buf << "}\n";
1441  indent(buf, indent_level);
1442  buf << "else {\n";
1443  ++indent_level;
1444  indent(buf, indent_level);
1445  buf << "do {\n";
1446  ++indent_level;
1447  indent(buf, indent_level);
1448  buf << "(((Nm*)obj)+(--nary))->~Nm();\n";
1449  --indent_level;
1450  indent(buf, indent_level);
1451  buf << "} while (nary);\n";
1452  --indent_level;
1453  indent(buf, indent_level);
1454  buf << "}\n";
1455  --indent_level;
1456  indent(buf, indent_level);
1457  buf << "}\n";
1458  // End wrapper.
1459  --indent_level;
1460  buf << "}\n";
1461  // Done.
1462  string wrapper(buf.str());
1463  //fprintf(stderr, "%s\n", wrapper.c_str());
1464  //
1465  // Compile the wrapper code.
1466  //
1467  void *F = compile_wrapper(wrapper_name, wrapper,
1468  /*withAccessControl=*/false);
1469  if (F) {
1470  gDtorWrapperStore.insert(make_pair(info->GetDecl(), F));
1471  } else {
1472  ::Error("TClingCallFunc::make_dtor_wrapper",
1473  "Failed to compile\n ==== SOURCE BEGIN ====\n%s\n ==== SOURCE END ====",
1474  wrapper.c_str());
1475  }
1476 
1478 }
1479 
1480 class ValHolder {
1481 public:
1482  union {
1483  long double ldbl;
1484  double dbl;
1485  float flt;
1486  //__uint128_t ui128;
1487  //__int128_t i128;
1488  unsigned long long ull;
1489  long long ll;
1490  unsigned long ul;
1491  long l;
1492  unsigned int ui;
1493  int i;
1494  unsigned short us;
1495  short s;
1496  //char32_t c32;
1497  //char16_t c16;
1498  //unsigned wchar_t uwc; - non-standard
1499  wchar_t wc;
1500  unsigned char uc;
1501  signed char sc;
1502  char c;
1503  bool b;
1504  void *vp;
1505  } u;
1506 };
1507 
1508 void TClingCallFunc::exec(void *address, void *ret)
1509 {
1510  SmallVector<ValHolder, 8> vh_ary;
1511  SmallVector<void *, 8> vp_ary;
1512 
1513  unsigned num_args = fArgVals.size();
1514  {
1516 
1517  const FunctionDecl *FD = GetDecl();
1518 
1519  //
1520  // Convert the arguments from cling::Value to their
1521  // actual type and store them in a holder for passing to the
1522  // wrapper function by pointer to value.
1523  //
1524  unsigned num_params = FD->getNumParams();
1525 
1526  if (num_args < GetMinRequiredArguments()) {
1527  ::Error("TClingCallFunc::exec",
1528  "Not enough arguments provided for %s (%d instead of the minimum %d)",
1529  fMethod->Name(),
1530  num_args, (int)GetMinRequiredArguments());
1531  return;
1532  }
1533  if (address == 0 && dyn_cast<CXXMethodDecl>(FD)
1534  && !(dyn_cast<CXXMethodDecl>(FD))->isStatic()
1535  && !dyn_cast<CXXConstructorDecl>(FD)) {
1536  ::Error("TClingCallFunc::exec",
1537  "The method %s is called without an object.",
1538  fMethod->Name());
1539  return;
1540  }
1541  vh_ary.reserve(num_args);
1542  vp_ary.reserve(num_args);
1543  for (unsigned i = 0U; i < num_args; ++i) {
1544  QualType Ty;
1545  if (i < num_params) {
1546  const ParmVarDecl *PVD = FD->getParamDecl(i);
1547  Ty = PVD->getType();
1548  } else {
1549  Ty = fArgVals[i].getType();
1550  }
1551  QualType QT = Ty.getCanonicalType();
1552  if (const BuiltinType *BT =
1553  dyn_cast<BuiltinType>(&*QT)) {
1554  //
1555  // WARNING!!!
1556  //
1557  // This switch is organized in order-of-declaration
1558  // so that the produced assembly code is optimal.
1559  // Do not reorder!
1560  //
1561  switch (BT->getKind()) {
1562  //
1563  // Builtin Types
1564  //
1565  case BuiltinType::Void: {
1566  // void
1567  ::Error("TClingCallFunc::exec(void*)",
1568  "Invalid type 'Void'!");
1569  return;
1570  }
1571  break;
1572  //
1573  // Unsigned Types
1574  //
1575  case BuiltinType::Bool: {
1576  // bool
1577  ValHolder vh;
1578  vh.u.b = (bool) sv_to_ulong_long(fArgVals[i]);
1579  vh_ary.push_back(vh);
1580  vp_ary.push_back(&vh_ary.back());
1581  }
1582  break;
1583  case BuiltinType::Char_U: {
1584  // char on targets where it is unsigned
1585  ValHolder vh;
1586  vh.u.c = (char) sv_to_ulong_long(fArgVals[i]);
1587  vh_ary.push_back(vh);
1588  vp_ary.push_back(&vh_ary.back());
1589  }
1590  break;
1591  case BuiltinType::UChar: {
1592  // unsigned char
1593  ValHolder vh;
1594  vh.u.uc = (unsigned char) sv_to_ulong_long(fArgVals[i]);
1595  vh_ary.push_back(vh);
1596  vp_ary.push_back(&vh_ary.back());
1597  }
1598  break;
1599  case BuiltinType::WChar_U: {
1600  // wchar_t on targets where it is unsigned.
1601  // The standard doesn't allow to specify signednedd of wchar_t
1602  // thus this maps simply to wchar_t.
1603  ValHolder vh;
1604  vh.u.wc = (wchar_t) sv_to_ulong_long(fArgVals[i]);
1605  vh_ary.push_back(vh);
1606  vp_ary.push_back(&vh_ary.back());
1607  }
1608  break;
1609  case BuiltinType::Char16: {
1610  // char16_t
1611  //ValHolder vh;
1612  //vh.u.c16 = (char16_t) sv_to_ulong_long(fArgVals[i]);
1613  //vh_ary.push_back(vh);
1614  //vp_ary.push_back(&vh_ary.back());
1615  }
1616  break;
1617  case BuiltinType::Char32: {
1618  // char32_t
1619  //ValHolder vh;
1620  //vh.u.c32 = (char32_t) sv_to_ulong_long(fArgVals[i]);
1621  //vh_ary.push_back(vh);
1622  //vp_ary.push_back(&vh_ary.back());
1623  }
1624  break;
1625  case BuiltinType::UShort: {
1626  // unsigned short
1627  ValHolder vh;
1628  vh.u.us = (unsigned short) sv_to_ulong_long(fArgVals[i]);
1629  vh_ary.push_back(vh);
1630  vp_ary.push_back(&vh_ary.back());
1631  }
1632  break;
1633  case BuiltinType::UInt: {
1634  // unsigned int
1635  ValHolder vh;
1636  vh.u.ui = (unsigned int) sv_to_ulong_long(fArgVals[i]);
1637  vh_ary.push_back(vh);
1638  vp_ary.push_back(&vh_ary.back());
1639  }
1640  break;
1641  case BuiltinType::ULong: {
1642  // unsigned long
1643  ValHolder vh;
1644  vh.u.ul = (unsigned long) sv_to_ulong_long(fArgVals[i]);
1645  vh_ary.push_back(vh);
1646  vp_ary.push_back(&vh_ary.back());
1647  }
1648  break;
1649  case BuiltinType::ULongLong: {
1650  // unsigned long long
1651  ValHolder vh;
1652  vh.u.ull = (unsigned long long) sv_to_ulong_long(fArgVals[i]);
1653  vh_ary.push_back(vh);
1654  vp_ary.push_back(&vh_ary.back());
1655  }
1656  break;
1657  case BuiltinType::UInt128: {
1658  // __uint128_t
1659  }
1660  break;
1661  //
1662  // Signed Types
1663  //
1664  //
1665  // Signed Types
1666  //
1667  case BuiltinType::Char_S: {
1668  // char on targets where it is signed
1669  ValHolder vh;
1670  vh.u.c = (char) sv_to_long_long(fArgVals[i]);
1671  vh_ary.push_back(vh);
1672  vp_ary.push_back(&vh_ary.back());
1673  }
1674  break;
1675  case BuiltinType::SChar: {
1676  // signed char
1677  ValHolder vh;
1678  vh.u.sc = (signed char) sv_to_long_long(fArgVals[i]);
1679  vh_ary.push_back(vh);
1680  vp_ary.push_back(&vh_ary.back());
1681  }
1682  break;
1683  case BuiltinType::WChar_S: {
1684  // wchar_t on targets where it is signed.
1685  // The standard doesn't allow to specify signednedd of wchar_t
1686  // thus this maps simply to wchar_t.
1687  ValHolder vh;
1688  vh.u.wc = (wchar_t) sv_to_long_long(fArgVals[i]);
1689  vh_ary.push_back(vh);
1690  vp_ary.push_back(&vh_ary.back());
1691  }
1692  break;
1693  case BuiltinType::Short: {
1694  // short
1695  ValHolder vh;
1696  vh.u.s = (short) sv_to_long_long(fArgVals[i]);
1697  vh_ary.push_back(vh);
1698  vp_ary.push_back(&vh_ary.back());
1699  }
1700  break;
1701  case BuiltinType::Int: {
1702  // int
1703  ValHolder vh;
1704  vh.u.i = (int) sv_to_long_long(fArgVals[i]);
1705  vh_ary.push_back(vh);
1706  vp_ary.push_back(&vh_ary.back());
1707  }
1708  break;
1709  case BuiltinType::Long: {
1710  // long
1711  ValHolder vh;
1712  vh.u.l = (long) sv_to_long_long(fArgVals[i]);
1713  vh_ary.push_back(vh);
1714  vp_ary.push_back(&vh_ary.back());
1715  }
1716  break;
1717  case BuiltinType::LongLong: {
1718  // long long
1719  ValHolder vh;
1720  vh.u.ll = (long long) sv_to_long_long(fArgVals[i]);
1721  vh_ary.push_back(vh);
1722  vp_ary.push_back(&vh_ary.back());
1723  }
1724  break;
1725  case BuiltinType::Int128: {
1726  // __int128_t
1727  ::Error("TClingCallFunc::exec(void*)",
1728  "Invalid type 'Int128'!");
1729  return;
1730  }
1731  break;
1732  case BuiltinType::Half: {
1733  // half in OpenCL, __fp16 in ARM NEON
1734  ::Error("TClingCallFunc::exec(void*)",
1735  "Invalid type 'Half'!");
1736  return;
1737  }
1738  break;
1739  case BuiltinType::Float: {
1740  // float
1741  ValHolder vh;
1742  vh.u.flt = sv_to<float>(fArgVals[i]);
1743  vh_ary.push_back(vh);
1744  vp_ary.push_back(&vh_ary.back());
1745  }
1746  break;
1747  case BuiltinType::Double: {
1748  // double
1749  ValHolder vh;
1750  vh.u.dbl = sv_to<double>(fArgVals[i]);
1751  vh_ary.push_back(vh);
1752  vp_ary.push_back(&vh_ary.back());
1753  }
1754  break;
1755  case BuiltinType::LongDouble: {
1756  // long double
1757  ValHolder vh;
1758  vh.u.ldbl = sv_to<long double>(fArgVals[i]);
1759  vh_ary.push_back(vh);
1760  vp_ary.push_back(&vh_ary.back());
1761  }
1762  break;
1763  //
1764  // Language-Specific Types
1765  //
1766  case BuiltinType::NullPtr: {
1767  // C++11 nullptr
1768  ValHolder vh;
1769  vh.u.vp = fArgVals[i].getPtr();
1770  vh_ary.push_back(vh);
1771  vp_ary.push_back(&vh_ary.back());
1772  }
1773  break;
1774  default: {
1775  // There should be no others. This is here in case
1776  // this changes in the future.
1777  ::Error("TClingCallFunc::exec(void*)",
1778  "Unhandled builtin type!");
1779  QT->dump();
1780  return;
1781  }
1782  break;
1783  }
1784  } else if (QT->isReferenceType()) {
1785  // the argument is already a pointer value (point to the same thing
1786  // as the reference.
1787  vp_ary.push_back((void *) sv_to_ulong_long(fArgVals[i]));
1788  } else if (QT->isPointerType() || QT->isArrayType()) {
1789  ValHolder vh;
1790  vh.u.vp = (void *) sv_to_ulong_long(fArgVals[i]);
1791  vh_ary.push_back(vh);
1792  vp_ary.push_back(&vh_ary.back());
1793  } else if (QT->isRecordType()) {
1794  // the argument is already a pointer value (pointing to object passed
1795  // by value).
1796  vp_ary.push_back((void *) sv_to_ulong_long(fArgVals[i]));
1797  } else if (const EnumType *ET =
1798  dyn_cast<EnumType>(&*QT)) {
1799  // Note: We may need to worry about the underlying type
1800  // of the enum here.
1801  (void) ET;
1802  ValHolder vh;
1803  vh.u.i = (int) sv_to_long_long(fArgVals[i]);
1804  vh_ary.push_back(vh);
1805  vp_ary.push_back(&vh_ary.back());
1806  } else if (QT->isMemberPointerType()) {
1807  ValHolder vh;
1808  vh.u.vp = (void *) sv_to_ulong_long(fArgVals[i]);
1809  vh_ary.push_back(vh);
1810  vp_ary.push_back(&vh_ary.back());
1811  } else {
1812  ::Error("TClingCallFunc::exec(void*)",
1813  "Invalid type (unrecognized)!");
1814  QT->dump();
1815  return;
1816  }
1817  }
1818  } // End of scope holding the lock
1819  (*fWrapper)(address, (int)num_args, (void **)vp_ary.data(), ret);
1820 }
1821 
1822 template <typename T>
1823 void TClingCallFunc::execWithLL(void *address, cling::Value *val)
1824 {
1825  T ret; // leave uninit for valgrind's sake!
1826  exec(address, &ret);
1827  val->getLL() = ret;
1828 }
1829 
1830 template <typename T>
1832 {
1833  T ret; // leave uninit for valgrind's sake!
1834  exec(address, &ret);
1835  val->getULL() = ret;
1836 }
1837 
1838 // Handle integral types.
1839 template <class T>
1841 {
1842  ret = cling::Value::Create<T>(QT.getAsOpaquePtr(), *fInterp);
1843  static_assert(std::is_integral<T>::value, "Must be called with integral T");
1844  if (std::is_signed<T>::value)
1845  return [this](void* address, cling::Value& ret) { execWithLL<T>(address, &ret); };
1846  else
1847  return [this](void* address, cling::Value& ret) { execWithULL<T>(address, &ret); };
1848 }
1849 
1850 // Handle builtin types.
1852 TClingCallFunc::InitRetAndExecBuiltin(QualType QT, const clang::BuiltinType *BT, cling::Value &ret) {
1853  switch (BT->getKind()) {
1854  case BuiltinType::Void: {
1855  ret = cling::Value::Create<void>(QT.getAsOpaquePtr(), *fInterp);
1856  return [this](void* address, cling::Value& ret) { exec(address, 0); };
1857  break;
1858  }
1859 
1860  //
1861  // Unsigned Types
1862  //
1863  case BuiltinType::Bool:
1864  return InitRetAndExecIntegral<bool>(QT, ret);
1865  break;
1866  case BuiltinType::Char_U: // char on targets where it is unsigned
1867  case BuiltinType::UChar:
1868  return InitRetAndExecIntegral<char>(QT, ret);
1869  break;
1870  case BuiltinType::WChar_U:
1871  return InitRetAndExecIntegral<wchar_t>(QT, ret);
1872  break;
1873  case BuiltinType::Char16:
1874  ::Error("TClingCallFunc::InitRetAndExecBuiltin",
1875  "Invalid type 'char16_t'!");
1876  return {};
1877  break;
1878  case BuiltinType::Char32:
1879  ::Error("TClingCallFunc::InitRetAndExecBuiltin",
1880  "Invalid type 'char32_t'!");
1881  return {};
1882  break;
1883  case BuiltinType::UShort:
1884  return InitRetAndExecIntegral<unsigned short>(QT, ret);
1885  break;
1886  case BuiltinType::UInt:
1887  return InitRetAndExecIntegral<unsigned int>(QT, ret);
1888  break;
1889  case BuiltinType::ULong:
1890  return InitRetAndExecIntegral<unsigned long>(QT, ret);
1891  break;
1892  case BuiltinType::ULongLong:
1893  return InitRetAndExecIntegral<unsigned long long>(QT, ret);
1894  break;
1895  case BuiltinType::UInt128: {
1896  ::Error("TClingCallFunc::InitRetAndExecBuiltin",
1897  "Invalid type '__uint128_t'!");
1898  return {};
1899  }
1900  break;
1901 
1902  //
1903  // Signed Types
1904  //
1905  case BuiltinType::Char_S: // char on targets where it is signed
1906  case BuiltinType::SChar:
1907  return InitRetAndExecIntegral<signed char>(QT, ret);
1908  break;
1909  case BuiltinType::WChar_S:
1910  // wchar_t on targets where it is signed.
1911  // The standard doesn't allow to specify signednedd of wchar_t
1912  // thus this maps simply to wchar_t.
1913  return InitRetAndExecIntegral<wchar_t>(QT, ret);
1914  break;
1915  case BuiltinType::Short:
1916  return InitRetAndExecIntegral<short>(QT, ret);
1917  break;
1918  case BuiltinType::Int:
1919  return InitRetAndExecIntegral<int>(QT, ret);
1920  break;
1921  case BuiltinType::Long:
1922  return InitRetAndExecIntegral<long>(QT, ret);
1923  break;
1924  case BuiltinType::LongLong:
1925  return InitRetAndExecIntegral<long long>(QT, ret);
1926  break;
1927  case BuiltinType::Int128:
1928  ::Error("TClingCallFunc::InitRetAndExecBuiltin",
1929  "Invalid type '__int128_t'!");
1930  return {};
1931  break;
1932  case BuiltinType::Half:
1933  // half in OpenCL, __fp16 in ARM NEON
1934  ::Error("TClingCallFunc::InitRetAndExecBuiltin",
1935  "Invalid type 'Half'!");
1936  return {};
1937  break;
1938  case BuiltinType::Float: {
1939  ret = cling::Value::Create<float>(QT.getAsOpaquePtr(), *fInterp);
1940  return [this](void* address, cling::Value& ret) { exec(address, &ret.getFloat()); };
1941  break;
1942  }
1943  case BuiltinType::Double: {
1944  ret = cling::Value::Create<double>(QT.getAsOpaquePtr(), *fInterp);
1945  return [this](void* address, cling::Value& ret) { exec(address, &ret.getDouble()); };
1946  break;
1947  }
1948  case BuiltinType::LongDouble: {
1949  ret = cling::Value::Create<long double>(QT.getAsOpaquePtr(), *fInterp);
1950  return [this](void* address, cling::Value& ret) { exec(address, &ret.getLongDouble()); };
1951  break;
1952  }
1953  //
1954  // Language-Specific Types
1955  //
1956  case BuiltinType::NullPtr:
1957  // C++11 nullptr
1958  ::Error("TClingCallFunc::InitRetAndExecBuiltin",
1959  "Invalid type 'nullptr'!");
1960  return {};
1961  break;
1962  default:
1963  break;
1964  }
1965  return {};
1966 }
1967 
1968 
1971  if (QT->isReferenceType()) {
1972  ret = cling::Value(QT, *fInterp);
1973  return [this](void* address, cling::Value& ret) { exec(address, &ret.getPtr()); };
1974  } else if (QT->isMemberPointerType()) {
1975  const MemberPointerType *MPT = QT->getAs<MemberPointerType>();
1976  if (MPT->isMemberDataPointer()) {
1977  // A member data pointer is a actually a struct with one
1978  // member of ptrdiff_t, the offset from the base of the object
1979  // storage to the storage for the designated data member.
1980  // But that's not relevant: we use it as a non-builtin, allocated
1981  // type.
1982  ret = cling::Value(QT, *fInterp);
1983  return [this](void* address, cling::Value& ret) { exec(address, ret.getPtr()); };
1984  }
1985  // We are a function member pointer.
1986  ret = cling::Value(QT, *fInterp);
1987  return [this](void* address, cling::Value& ret) { exec(address, &ret.getPtr()); };
1988  } else if (QT->isPointerType() || QT->isArrayType()) {
1989  // Note: ArrayType is an illegal function return value type.
1990  ret = cling::Value::Create<void*>(QT.getAsOpaquePtr(), *fInterp);
1991  return [this](void* address, cling::Value& ret) { exec(address, &ret.getPtr()); };
1992  } else if (QT->isRecordType()) {
1993  ret = cling::Value(QT, *fInterp);
1994  return [this](void* address, cling::Value& ret) { exec(address, ret.getPtr()); };
1995  } else if (const EnumType *ET = dyn_cast<EnumType>(&*QT)) {
1996  // Note: We may need to worry about the underlying type
1997  // of the enum here.
1998  (void) ET;
1999  ret = cling::Value(QT, *fInterp);
2000  return [this](void* address, cling::Value& ret) { execWithLL<int>(address, &ret); };
2001  } else if (const BuiltinType *BT = dyn_cast<BuiltinType>(&*QT)) {
2002  return InitRetAndExecBuiltin(QT, BT, ret);
2003  }
2004  ::Error("TClingCallFunc::exec_with_valref_return",
2005  "Unrecognized return type!");
2006  QT->dump();
2007  return {};
2008 }
2009 
2011 TClingCallFunc::InitRetAndExec(const clang::FunctionDecl *FD, cling::Value &ret) {
2012  if (const CXXConstructorDecl *CD = dyn_cast<CXXConstructorDecl>(FD)) {
2013  ASTContext &Context = FD->getASTContext();
2014  const TypeDecl *TD = dyn_cast<TypeDecl>(CD->getDeclContext());
2015  QualType ClassTy(TD->getTypeForDecl(), 0);
2016  QualType QT = Context.getLValueReferenceType(ClassTy);
2017  ret = cling::Value(QT, *fInterp);
2018  // Store the new()'ed address in getPtr()
2019  return [this](void* address, cling::Value& ret) { exec(address, &ret.getPtr()); };
2020  } else {
2021  QualType QT = FD->getReturnType().getCanonicalType();
2022  return InitRetAndExecNoCtor(QT, ret);
2023  }
2024 }
2025 
2027 {
2028  if (!ret) {
2029  exec(address, 0);
2030  return;
2031  }
2032  std::function<void(void*, cling::Value&)> execFunc;
2033 
2034  /* Release lock during user function execution*/
2035  {
2037  execFunc = InitRetAndExec(GetDecl(), *ret);
2038  }
2039 
2040  if (execFunc)
2041  execFunc(address, *ret);
2042  return;
2043 }
2044 
2045 void TClingCallFunc::EvaluateArgList(const string &ArgList)
2046 {
2048 
2049  SmallVector<Expr *, 4> exprs;
2050  fInterp->getLookupHelper().findArgList(ArgList, exprs,
2051  gDebug > 5 ? cling::LookupHelper::WithDiagnostics
2052  : cling::LookupHelper::NoDiagnostics);
2053  for (SmallVectorImpl<Expr *>::const_iterator I = exprs.begin(),
2054  E = exprs.end(); I != E; ++I) {
2055  cling::Value val;
2056  EvaluateExpr(*fInterp, *I, val);
2057  if (!val.isValid()) {
2058  // Bad expression, all done.
2059  ::Error("TClingCallFunc::EvaluateArgList",
2060  "Bad expression in parameter %d of '%s'!",
2061  (int)(I - exprs.begin()),
2062  ArgList.c_str());
2063  return;
2064  }
2065  fArgVals.push_back(val);
2066  }
2067 }
2068 
2069 void TClingCallFunc::Exec(void *address, TInterpreterValue *interpVal/*=0*/)
2070 {
2071  IFacePtr();
2072  if (!fWrapper) {
2073  ::Error("TClingCallFunc::Exec(address, interpVal)",
2074  "Called with no wrapper, not implemented!");
2075  return;
2076  }
2077  if (!interpVal) {
2078  exec(address, 0);
2079  return;
2080  }
2081  cling::Value *val = reinterpret_cast<cling::Value *>(interpVal->GetValAddr());
2082  exec_with_valref_return(address, val);
2083 }
2084 
2085 template <typename T>
2086 T TClingCallFunc::ExecT(void *address)
2087 {
2088  IFacePtr();
2089  if (!fWrapper) {
2090  ::Error("TClingCallFunc::ExecT",
2091  "Called with no wrapper, not implemented!");
2092  return 0;
2093  }
2094  cling::Value ret;
2095  exec_with_valref_return(address, &ret);
2096  if (!ret.isValid()) {
2097  // Sometimes we are called on a function returning void!
2098  return 0;
2099  }
2100 
2101  if (fReturnIsRecordType)
2102  ((TCling *)gCling)->RegisterTemporary(ret);
2103  return sv_to<T>(ret);
2104 }
2105 
2107 {
2108  return ExecT<long>(address);
2109 }
2110 
2111 long long TClingCallFunc::ExecInt64(void *address)
2112 {
2113  return ExecT<long long>(address);
2114 }
2115 
2116 double TClingCallFunc::ExecDouble(void *address)
2117 {
2118  return ExecT<double>(address);
2119 }
2120 
2121 void TClingCallFunc::ExecWithArgsAndReturn(void *address, const void *args[] /*= 0*/,
2122  int nargs /*= 0*/, void *ret/*= 0*/)
2123 {
2124  IFacePtr();
2125  if (!fWrapper) {
2126  ::Error("TClingCallFunc::ExecWithArgsAndReturn(address, args, ret)",
2127  "Called with no wrapper, not implemented!");
2128  return;
2129  }
2130  (*fWrapper)(address, nargs, const_cast<void **>(args), ret);
2131 }
2132 
2133 void TClingCallFunc::ExecWithReturn(void *address, void *ret/*= 0*/)
2134 {
2135  IFacePtr();
2136  if (!fWrapper) {
2137  ::Error("TClingCallFunc::ExecWithReturn(address, ret)",
2138  "Called with no wrapper, not implemented!");
2139  return;
2140  }
2141  exec(address, ret);
2142 }
2143 
2146  const std::string &type_name,
2147  void *address /*=0*/, unsigned long nary /*= 0UL*/)
2148 {
2149  if (!info->IsValid()) {
2150  ::Error("TClingCallFunc::ExecDefaultConstructor", "Invalid class info!");
2151  return nullptr;
2152  }
2153  tcling_callfunc_ctor_Wrapper_t wrapper = nullptr;
2154  {
2156  auto D = info->GetDecl();
2157  //if (!info->HasDefaultConstructor()) {
2158  // // FIXME: We might have a ROOT ioctor, we might
2159  // // have to check for that here.
2160  // ::Error("TClingCallFunc::ExecDefaultConstructor",
2161  // "Class has no default constructor: %s",
2162  // info->Name());
2163  // return 0;
2164  //}
2165  auto I = gCtorWrapperStore.find(D);
2166  if (I != gCtorWrapperStore.end()) {
2167  wrapper = (tcling_callfunc_ctor_Wrapper_t) I->second;
2168  } else {
2169  wrapper = make_ctor_wrapper(info, kind, type_name);
2170  }
2171  }
2172  if (!wrapper) {
2173  ::Error("TClingCallFunc::ExecDefaultConstructor",
2174  "Called with no wrapper, not implemented!");
2175  return nullptr;
2176  }
2177  void *obj = 0;
2178  (*wrapper)(&obj, address, nary);
2179  return obj;
2180 }
2181 
2182 void TClingCallFunc::ExecDestructor(const TClingClassInfo *info, void *address /*=0*/,
2183  unsigned long nary /*= 0UL*/, bool withFree /*= true*/)
2184 {
2185  if (!info->IsValid()) {
2186  ::Error("TClingCallFunc::ExecDestructor", "Invalid class info!");
2187  return;
2188  }
2189 
2190  tcling_callfunc_dtor_Wrapper_t wrapper = 0;
2191  {
2193  const Decl *D = info->GetDecl();
2194  map<const Decl *, void *>::iterator I = gDtorWrapperStore.find(D);
2195  if (I != gDtorWrapperStore.end()) {
2196  wrapper = (tcling_callfunc_dtor_Wrapper_t) I->second;
2197  } else {
2198  wrapper = make_dtor_wrapper(info);
2199  }
2200  }
2201  if (!wrapper) {
2202  ::Error("TClingCallFunc::ExecDestructor",
2203  "Called with no wrapper, not implemented!");
2204  return;
2205  }
2206  (*wrapper)(address, nary, withFree);
2207 }
2208 
2211 {
2212  return new TClingMethodInfo(*fMethod);
2213 }
2214 
2216 {
2217  fMethod.reset();
2218  fWrapper = 0;
2219  fDecl = nullptr;
2220  fMinRequiredArguments = -1;
2221  ResetArg();
2222 }
2223 
2225 {
2226  Init();
2227  fMethod = std::unique_ptr<TClingMethodInfo>(new TClingMethodInfo(minfo));
2228 }
2229 
2230 void TClingCallFunc::Init(std::unique_ptr<TClingMethodInfo> minfo)
2231 {
2232  Init();
2233  fMethod = std::move(minfo);
2234 }
2235 
2237 {
2238  if (!IsValid()) {
2239  return 0;
2240  }
2241  if (!fWrapper) {
2242  const FunctionDecl *decl = GetDecl();
2243 
2245  map<const FunctionDecl *, void *>::iterator I = gWrapperStore.find(decl);
2246  if (I != gWrapperStore.end()) {
2247  fWrapper = (tcling_callfunc_Wrapper_t) I->second;
2248  } else {
2249  fWrapper = make_wrapper();
2250  }
2251  }
2252  return (void *)fWrapper;
2253 }
2254 
2256 {
2257  if (!fMethod) {
2258  return false;
2259  }
2260  return fMethod->IsValid();
2261 }
2262 
2264 {
2265  if (!IsValid()) {
2266  ::Error("TClingCallFunc::IFacePtr(kind)",
2267  "Attempt to get interface while invalid.");
2269  }
2270  if (!fWrapper) {
2271  const FunctionDecl *decl = GetDecl();
2272 
2274  map<const FunctionDecl *, void *>::iterator I = gWrapperStore.find(decl);
2275  if (I != gWrapperStore.end()) {
2276  fWrapper = (tcling_callfunc_Wrapper_t) I->second;
2277  } else {
2278  fWrapper = make_wrapper();
2279  }
2280 
2281  fReturnIsRecordType = decl->getReturnType().getCanonicalType()->isRecordType();
2282  }
2283  return TInterpreter::CallFuncIFacePtr_t(fWrapper);
2284 }
2285 
2286 
2288 {
2289  fArgVals.clear();
2290 }
2291 
2292 void TClingCallFunc::SetArg(unsigned long param)
2293 {
2294  const ASTContext &C = fInterp->getCI()->getASTContext();
2295  fArgVals.push_back(cling::Value(C.UnsignedLongTy, *fInterp));
2296  fArgVals.back().getLL() = param;
2297 }
2298 
2299 void TClingCallFunc::SetArg(long param)
2300 {
2301  const ASTContext &C = fInterp->getCI()->getASTContext();
2302  fArgVals.push_back(cling::Value(C.LongTy, *fInterp));
2303  fArgVals.back().getLL() = param;
2304 }
2305 
2306 void TClingCallFunc::SetArg(float param)
2307 {
2308  const ASTContext &C = fInterp->getCI()->getASTContext();
2309  fArgVals.push_back(cling::Value(C.FloatTy, *fInterp));
2310  fArgVals.back().getFloat() = param;
2311 }
2312 
2313 void TClingCallFunc::SetArg(double param)
2314 {
2315  const ASTContext &C = fInterp->getCI()->getASTContext();
2316  fArgVals.push_back(cling::Value(C.DoubleTy, *fInterp));
2317  fArgVals.back().getDouble() = param;
2318 }
2319 
2320 void TClingCallFunc::SetArg(long long param)
2321 {
2322  const ASTContext &C = fInterp->getCI()->getASTContext();
2323  fArgVals.push_back(cling::Value(C.LongLongTy, *fInterp));
2324  fArgVals.back().getLL() = param;
2325 }
2326 
2327 void TClingCallFunc::SetArg(unsigned long long param)
2328 {
2329  const ASTContext &C = fInterp->getCI()->getASTContext();
2330  fArgVals.push_back(cling::Value(C.UnsignedLongLongTy, *fInterp));
2331  fArgVals.back().getULL() = param;
2332 }
2333 
2334 void TClingCallFunc::SetArgArray(long *paramArr, int nparam)
2335 {
2336  ResetArg();
2337  for (int i = 0; i < nparam; ++i) {
2338  SetArg(paramArr[i]);
2339  }
2340 }
2341 
2342 void TClingCallFunc::SetArgs(const char *params)
2343 {
2344  ResetArg();
2345  EvaluateArgList(params);
2346 }
2347 
2348 void TClingCallFunc::SetFunc(const TClingClassInfo *info, const char *method, const char *arglist,
2349  long *poffset)
2350 {
2351  SetFunc(info, method, arglist, false, poffset);
2352 }
2353 
2354 void TClingCallFunc::SetFunc(const TClingClassInfo *info, const char *method, const char *arglist,
2355  bool objectIsConst, long *poffset)
2356 {
2357  Init(std::unique_ptr<TClingMethodInfo>(new TClingMethodInfo(fInterp)));
2358  if (poffset) {
2359  *poffset = 0L;
2360  }
2361  ResetArg();
2362  if (!info->IsValid()) {
2363  ::Error("TClingCallFunc::SetFunc", "Class info is invalid!");
2364  return;
2365  }
2366  if (!strcmp(arglist, ")")) {
2367  // CINT accepted a single right paren as meaning no arguments.
2368  arglist = "";
2369  }
2370  *fMethod = info->GetMethodWithArgs(method, arglist, objectIsConst, poffset);
2371  if (!fMethod->IsValid()) {
2372  //::Error("TClingCallFunc::SetFunc", "Could not find method %s(%s)", method,
2373  // arglist);
2374  return;
2375  }
2376  // FIXME: The arglist was already parsed by the lookup, we should
2377  // enhance the lookup to return the resulting expression
2378  // list so we do not need to parse it again here.
2379  EvaluateArgList(arglist);
2380 }
2381 
2383 {
2384  Init(std::unique_ptr<TClingMethodInfo>(new TClingMethodInfo(*info)));
2385  ResetArg();
2386  if (!fMethod->IsValid()) {
2387  return;
2388  }
2389 }
2390 
2391 void TClingCallFunc::SetFuncProto(const TClingClassInfo *info, const char *method,
2392  const char *proto, long *poffset,
2393  EFunctionMatchMode mode/*=kConversionMatch*/)
2394 {
2395  SetFuncProto(info, method, proto, false, poffset, mode);
2396 }
2397 
2398 void TClingCallFunc::SetFuncProto(const TClingClassInfo *info, const char *method,
2399  const char *proto, bool objectIsConst, long *poffset,
2400  EFunctionMatchMode mode/*=kConversionMatch*/)
2401 {
2402  Init(std::unique_ptr<TClingMethodInfo>(new TClingMethodInfo(fInterp)));
2403  if (poffset) {
2404  *poffset = 0L;
2405  }
2406  ResetArg();
2407  if (!info->IsValid()) {
2408  ::Error("TClingCallFunc::SetFuncProto", "Class info is invalid!");
2409  return;
2410  }
2411  *fMethod = info->GetMethod(method, proto, objectIsConst, poffset, mode);
2412  if (!fMethod->IsValid()) {
2413  //::Error("TClingCallFunc::SetFuncProto", "Could not find method %s(%s)",
2414  // method, proto);
2415  return;
2416  }
2417 }
2418 
2419 void TClingCallFunc::SetFuncProto(const TClingClassInfo *info, const char *method,
2420  const llvm::SmallVectorImpl<clang::QualType> &proto, long *poffset,
2421  EFunctionMatchMode mode/*=kConversionMatch*/)
2422 {
2423  SetFuncProto(info, method, proto, false, poffset, mode);
2424 }
2425 
2426 void TClingCallFunc::SetFuncProto(const TClingClassInfo *info, const char *method,
2427  const llvm::SmallVectorImpl<clang::QualType> &proto,
2428  bool objectIsConst, long *poffset,
2429  EFunctionMatchMode mode/*=kConversionMatch*/)
2430 {
2431  Init(std::unique_ptr<TClingMethodInfo>(new TClingMethodInfo(fInterp)));
2432  if (poffset) {
2433  *poffset = 0L;
2434  }
2435  ResetArg();
2436  if (!info->IsValid()) {
2437  ::Error("TClingCallFunc::SetFuncProto", "Class info is invalid!");
2438  return;
2439  }
2440  *fMethod = info->GetMethod(method, proto, objectIsConst, poffset, mode);
2441  if (!fMethod->IsValid()) {
2442  //::Error("TClingCallFunc::SetFuncProto", "Could not find method %s(%s)",
2443  // method, proto);
2444  return;
2445  }
2446 }
2447 
c
#define c(i)
Definition: RSha256.hxx:119
l
auto * l
Definition: textangle.C:4
TClingCallFunc::InitRetAndExecBuiltin
ExecWithRetFunc_t InitRetAndExecBuiltin(clang::QualType QT, const clang::BuiltinType *BT, cling::Value &ret)
Definition: TClingCallFunc.cxx:1852
TClingCallFunc::execWithULL
void execWithULL(void *address, cling::Value *val)
Definition: TClingCallFunc.cxx:1831
TClingCallFunc::make_narg_call
void make_narg_call(const std::string &return_type, const unsigned N, std::ostringstream &typedefbuf, std::ostringstream &callbuf, const std::string &class_name, int indent_level)
Definition: TClingCallFunc.cxx:389
TClingCallFunc::InitRetAndExecNoCtor
ExecWithRetFunc_t InitRetAndExecNoCtor(clang::QualType QT, cling::Value &ret)
Definition: TClingCallFunc.cxx:1970
sqlio::Bool
const char * Bool
Definition: TSQLStructure.cxx:69
llvm
Definition: TString.h:850
TClingCallFunc::make_wrapper
tcling_callfunc_Wrapper_t make_wrapper()
Definition: TClingCallFunc.cxx:1080
TClingCallFunc::execWithLL
void execWithLL(void *address, cling::Value *val)
Definition: TClingCallFunc.cxx:1823
TClingCallFunc::IsValid
bool IsValid() const
Definition: TClingCallFunc.cxx:2255
TClingCallFunc::exec_with_valref_return
void exec_with_valref_return(void *address, cling::Value *ret)
Definition: TClingCallFunc.cxx:2026
TClingCallFunc::ExecWithRetFunc_t
std::function< void(void *address, cling::Value &ret)> ExecWithRetFunc_t
Definition: TClingCallFunc.h:88
TCling.h
TClingCallFunc::compile_wrapper
void * compile_wrapper(const std::string &wrapper_name, const std::string &wrapper, bool withAccessControl=true)
Definition: TClingCallFunc.cxx:264
TClingCallFunc::make_narg_ctor_with_return
void make_narg_ctor_with_return(const unsigned N, const std::string &class_name, std::ostringstream &buf, int indent_level)
Definition: TClingCallFunc.cxx:505
F
#define F(x, y, z)
TClingMethodInfo.h
TClingCallFunc::ExecDestructor
void ExecDestructor(const TClingClassInfo *info, void *address=nullptr, unsigned long nary=0UL, bool withFree=true)
Definition: TClingCallFunc.cxx:2182
TInterpreterValue.h
TClingCallFunc::ExecDefaultConstructor
void * ExecDefaultConstructor(const TClingClassInfo *info, ROOT::TMetaUtils::EIOCtorCategory kind, const std::string &type_name, void *address=nullptr, unsigned long nary=0UL)
Definition: TClingCallFunc.cxx:2144
TClingCallFunc::make_dtor_wrapper
tcling_callfunc_dtor_Wrapper_t make_dtor_wrapper(const TClingClassInfo *info)
Definition: TClingCallFunc.cxx:1316
TClingCallFunc::SetArg
void SetArg(long arg)
Definition: TClingCallFunc.cxx:2299
TGeant4Unit::s
static constexpr double s
Definition: TGeant4SystemOfUnits.h:168
TClingCallFunc::ExecDouble
double ExecDouble(void *address)
Definition: TClingCallFunc.cxx:2116
N
#define N
TClingCallFunc::SetFunc
void SetFunc(const TClingClassInfo *info, const char *method, const char *arglist, long *poffset)
Definition: TClingCallFunc.cxx:2348
indent
static void indent(ostringstream &buf, int indent_level)
Definition: TClingCallFunc.cxx:87
RooFitShortHand::S
RooArgSet S(const RooAbsArg &v1)
Definition: RooGlobalFunc.cxx:348
long
long
Definition: Converters.cxx:858
gWrapperSerial
static unsigned long long gWrapperSerial
Definition: TClingCallFunc.cxx:77
sqlio::UInt
const char * UInt
Definition: TSQLStructure.cxx:79
gDtorWrapperStore
static map< const Decl *, void * > gDtorWrapperStore
Definition: TClingCallFunc.cxx:82
TCling
Definition: TCling.h:101
R__LOCKGUARD_CLING
#define R__LOCKGUARD_CLING(mutex)
Definition: TInterpreter.h:50
tcling_callfunc_Wrapper_t
void(* tcling_callfunc_Wrapper_t)(void *, int, void **, void *)
Definition: TClingCallFunc.h:55
ROOT::TMetaUtils::GetNormalizedName
void GetNormalizedName(std::string &norm_name, const clang::QualType &type, const cling::Interpreter &interpreter, const TNormalizedCtxt &normCtxt)
Return the type name normalized for ROOT, keeping only the ROOT opaque typedef (Double32_t,...
Definition: TClingUtils.cxx:4036
gWrapperStore
static map< const FunctionDecl *, void * > gWrapperStore
Definition: TClingCallFunc.cxx:80
b
#define b(i)
Definition: RSha256.hxx:118
ROOT::TMetaUtils::EIOCtorCategory::kIORefType
@ kIORefType
bool
TClingClassInfo::GetMethodWithArgs
TClingMethodInfo GetMethodWithArgs(const char *fname, const char *arglist, long *poffset, ROOT::EFunctionMatchMode mode=ROOT::kConversionMatch, EInheritanceMode imode=kWithInheritance) const
Definition: TClingClassInfo.cxx:497
TClingCallFunc::make_ctor_wrapper
tcling_callfunc_ctor_Wrapper_t make_ctor_wrapper(const TClingClassInfo *, ROOT::TMetaUtils::EIOCtorCategory, const std::string &)
Definition: TClingCallFunc.cxx:1105
gCtorWrapperStore
static map< const Decl *, void * > gCtorWrapperStore
Definition: TClingCallFunc.cxx:81
ROOT::Math::Cephes::C
static double C[]
Definition: SpecFuncCephes.cxx:187
TGeant4Unit::L
static constexpr double L
Definition: TGeant4SystemOfUnits.h:123
TClingClassInfo.h
sqlio::Double
const char * Double
Definition: TSQLStructure.cxx:76
TInterpreter::CallFuncIFacePtr_t
Definition: TInterpreter.h:85
sqlio::Int
const char * Int
Definition: TSQLStructure.cxx:72
TClingCallFunc::FactoryMethod
TClingMethodInfo * FactoryMethod() const
Definition: TClingCallFunc.cxx:2210
kIndentString
static const string kIndentString(" ")
TClingMethodInfo
Definition: TClingMethodInfo.h:56
TClingCallFunc::EReferenceType
EReferenceType
Definition: TClingCallFunc.h:82
TClingCallFunc::SetArgs
void SetArgs(const char *args)
Definition: TClingCallFunc.cxx:2342
sqlio::UShort
const char * UShort
Definition: TSQLStructure.cxx:78
gInterpreterMutex
R__EXTERN TVirtualMutex * gInterpreterMutex
Definition: TInterpreter.h:43
TGeant4Unit::us
static constexpr double us
Definition: TGeant4SystemOfUnits.h:170
xmlio::Value
const char * Value
Definition: TXMLSetup.cxx:79
sqlio::Short
const char * Short
Definition: TSQLStructure.cxx:71
tcling_callfunc_ctor_Wrapper_t
void(* tcling_callfunc_ctor_Wrapper_t)(void **, void *, unsigned long)
Definition: TClingCallFunc.h:56
sqlio::Long
const char * Long
Definition: TSQLStructure.cxx:73
TClingCallFunc::get_wrapper_code
int get_wrapper_code(std::string &wrapper_name, std::string &wrapper)
Definition: TClingCallFunc.cxx:580
ROOT::R::function
void function(const Char_t *name_, T fun, const Char_t *docstring=0)
Definition: RExports.h:151
gDebug
R__EXTERN Int_t gDebug
Definition: RtypesCore.h:119
Long_t
long Long_t
Definition: RtypesCore.h:54
TClingClassInfo
Definition: TClingClassInfo.h:58
TClingCallFunc.h
TClingCallFunc::EvaluateArgList
void EvaluateArgList(const std::string &ArgList)
Definition: TClingCallFunc.cxx:2045
tcling_callfunc_dtor_Wrapper_t
void(* tcling_callfunc_dtor_Wrapper_t)(void *, unsigned long, int)
Definition: TClingCallFunc.h:57
TClingClassInfo::GetMethod
TClingMethodInfo GetMethod(const char *fname) const
Definition: TClingClassInfo.cxx:290
TClingCallFunc::make_narg_call_with_return
void make_narg_call_with_return(const unsigned N, const std::string &class_name, std::ostringstream &buf, int indent_level)
Definition: TClingCallFunc.cxx:963
TClingCallFunc::ExecWithReturn
void ExecWithReturn(void *address, void *ret=nullptr)
Definition: TClingCallFunc.cxx:2133
TClingCallFunc::InterfaceMethod
void * InterfaceMethod()
Definition: TClingCallFunc.cxx:2236
TClingCallFunc::Exec
void Exec(void *address, TInterpreterValue *interpVal=0)
Definition: TClingCallFunc.cxx:2069
void
typedef void((*Func_t)())
TClingCallFunc::ExecT
T ExecT(void *address)
Definition: TClingCallFunc.cxx:2086
TClingCallFunc::make_narg_ctor
void make_narg_ctor(const unsigned N, std::ostringstream &typedefbuf, std::ostringstream &callbuf, const std::string &class_name, int indent_level)
Definition: TClingCallFunc.cxx:344
TClingDeclInfo::IsValid
virtual bool IsValid() const
Definition: TClingDeclInfo.h:41
ROOT::EFunctionMatchMode
EFunctionMatchMode
Definition: TDictionary.h:155
ROOT::TMetaUtils::EIOCtorCategory
EIOCtorCategory
Definition: TClingUtils.h:359
EvaluateExpr
static void EvaluateExpr(cling::Interpreter &interp, const Expr *E, cling::Value &V)
Definition: TClingCallFunc.cxx:96
sqlio::UChar
const char * UChar
Definition: TSQLStructure.cxx:77
TClingCallFunc::CalculateMinRequiredArguments
size_t CalculateMinRequiredArguments()
Definition: TClingCallFunc.cxx:258
sqlio::Float
const char * Float
Definition: TSQLStructure.cxx:75
TClingCallFunc::Init
void Init()
Definition: TClingCallFunc.cxx:2215
proto
const char * proto
Definition: civetweb.c:16604
TInterpreterValue
Definition: TInterpreterValue.h:32
TClingCallFunc::SetFuncProto
void SetFuncProto(const TClingClassInfo *info, const char *method, const char *proto, long *poffset, ROOT::EFunctionMatchMode mode=ROOT::kConversionMatch)
Definition: TClingCallFunc.cxx:2391
Pattern
Definition: Pattern.h:7
TClingCallFunc::SetArgArray
void SetArgArray(long *argArr, int narg)
Definition: TClingCallFunc.cxx:2334
sqlio::ULong
const char * ULong
Definition: TSQLStructure.cxx:80
TInterpreterValue::GetValAddr
virtual const void * GetValAddr() const =0
short
l unsigned short
Definition: Converters.cxx:862
clang
Definition: BaseSelectionRule.h:29
gCling
R__EXTERN TInterpreter * gCling
Definition: TInterpreter.h:559
TClassEdit::Init
void Init(TClassEdit::TInterpreterLookupHelper *helper)
Definition: TClassEdit.cxx:154
name
char name[80]
Definition: TGX11.cxx:110
ROOT::TMetaUtils::EIOCtorCategory::kIOPtrType
@ kIOPtrType
ROOT::Math::Chebyshev::T
double T(double x)
Definition: ChebyshevPol.h:52
TClingUtils.h
TClingCallFunc::InitRetAndExec
ExecWithRetFunc_t InitRetAndExec(const clang::FunctionDecl *FD, cling::Value &ret)
Definition: TClingCallFunc.cxx:2011
TClingCallFunc::exec
void exec(void *address, void *ret)
Definition: TClingCallFunc.cxx:1508
I
#define I(x, y, z)
TClingCallFunc::ExecWithArgsAndReturn
void ExecWithArgsAndReturn(void *address, const void *args[]=0, int nargs=0, void *ret=0)
Definition: TClingCallFunc.cxx:2121
TClingDeclInfo::GetDecl
virtual const clang::Decl * GetDecl() const
Definition: TClingDeclInfo.h:37
TGeant4Unit::nm
static constexpr double nm
Definition: TGeant4SystemOfUnits.h:111
TClingCallFunc::collect_type_info
void collect_type_info(clang::QualType &QT, std::ostringstream &typedefbuf, std::ostringstream &callbuf, std::string &type_name, EReferenceType &refType, bool &isPointer, int indent_level, bool forArgument)
Definition: TClingCallFunc.cxx:271
TClingCallFunc::ExecInt64
long long ExecInt64(void *address)
Definition: TClingCallFunc.cxx:2111
TClingCallFunc::InitRetAndExecIntegral
ExecWithRetFunc_t InitRetAndExecIntegral(clang::QualType QT, cling::Value &ret)
TClingCallFunc::ExecInt
long ExecInt(void *address)
Definition: TClingCallFunc.cxx:2106
ROOT
VSD Structures.
Definition: StringConv.hxx:21
TMath::E
constexpr Double_t E()
Base of natural log:
Definition: TMath.h:102
int
TClingCallFunc::IFacePtr
TInterpreter::CallFuncIFacePtr_t IFacePtr()
Definition: TClingCallFunc.cxx:2263
Error
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
Definition: TError.cxx:187
TError.h
TClingCallFunc::ResetArg
void ResetArg()
Definition: TClingCallFunc.cxx:2287