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 Decl *, 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>(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 ///////////////////////////////////////////////////////////////////////////////
581 // Returns the DeclContext corresponding to fMethod's Decl.
582 // \Note that this might be a FunctionDecl or a UsingShadowDecl; we use the
583 // DeclContext of the UsingShadowDecl e.g. for constructing a derived class
584 // object, even if invoking a function made available by a using declaration
585 // of a constructor of a base class (ROOT-11010).
586 
587 const clang::DeclContext *TClingCallFunc::GetDeclContext() const {
588  return fMethod->GetDecl()->getDeclContext();
589 }
590 
591 int TClingCallFunc::get_wrapper_code(std::string &wrapper_name, std::string &wrapper)
592 {
593  const FunctionDecl *FD = GetDecl();
594  assert(FD && "generate_wrapper called without a function decl!");
595  ASTContext &Context = FD->getASTContext();
596  PrintingPolicy Policy(Context.getPrintingPolicy());
597  //
598  // Get the class or namespace name.
599  //
600  string class_name;
601  const clang::DeclContext *DC = GetDeclContext();
602  if (const TypeDecl *TD = dyn_cast<TypeDecl>(DC)) {
603  // This is a class, struct, or union member.
604  QualType QT(TD->getTypeForDecl(), 0);
605  ROOT::TMetaUtils::GetNormalizedName(class_name, QT, *fInterp, fNormCtxt);
606  } else if (const NamedDecl *ND = dyn_cast<NamedDecl>(DC)) {
607  // This is a namespace member.
608  raw_string_ostream stream(class_name);
609  ND->getNameForDiagnostic(stream, Policy, /*Qualified=*/true);
610  stream.flush();
611  }
612  //
613  // Check to make sure that we can
614  // instantiate and codegen this function.
615  //
616  bool needInstantiation = false;
617  const FunctionDecl *Definition = 0;
618  if (!FD->isDefined(Definition)) {
619  FunctionDecl::TemplatedKind TK = FD->getTemplatedKind();
620  switch (TK) {
621  case FunctionDecl::TK_NonTemplate: {
622  // Ordinary function, not a template specialization.
623  // Note: This might be ok, the body might be defined
624  // in a library, and all we have seen is the
625  // header file.
626  //::Error("TClingCallFunc::make_wrapper",
627  // "Cannot make wrapper for a function which is "
628  // "declared but not defined!");
629  // return 0;
630  } break;
631  case FunctionDecl::TK_FunctionTemplate: {
632  // This decl is actually a function template,
633  // not a function at all.
634  ::Error("TClingCallFunc::make_wrapper", "Cannot make wrapper for a function template!");
635  return 0;
636  } break;
637  case FunctionDecl::TK_MemberSpecialization: {
638  // This function is the result of instantiating an ordinary
639  // member function of a class template, or of instantiating
640  // an ordinary member function of a class member of a class
641  // template, or of specializing a member function template
642  // of a class template, or of specializing a member function
643  // template of a class member of a class template.
644  if (!FD->isTemplateInstantiation()) {
645  // We are either TSK_Undeclared or
646  // TSK_ExplicitSpecialization.
647  // Note: This might be ok, the body might be defined
648  // in a library, and all we have seen is the
649  // header file.
650  //::Error("TClingCallFunc::make_wrapper",
651  // "Cannot make wrapper for a function template "
652  // "explicit specialization which is declared "
653  // "but not defined!");
654  // return 0;
655  break;
656  }
657  const FunctionDecl *Pattern = FD->getTemplateInstantiationPattern();
658  if (!Pattern) {
659  ::Error("TClingCallFunc::make_wrapper", "Cannot make wrapper for a member function "
660  "instantiation with no pattern!");
661  return 0;
662  }
663  FunctionDecl::TemplatedKind PTK = Pattern->getTemplatedKind();
664  TemplateSpecializationKind PTSK = Pattern->getTemplateSpecializationKind();
665  if (
666  // The pattern is an ordinary member function.
667  (PTK == FunctionDecl::TK_NonTemplate) ||
668  // The pattern is an explicit specialization, and
669  // so is not a template.
670  ((PTK != FunctionDecl::TK_FunctionTemplate) &&
671  ((PTSK == TSK_Undeclared) || (PTSK == TSK_ExplicitSpecialization)))) {
672  // Note: This might be ok, the body might be defined
673  // in a library, and all we have seen is the
674  // header file.
675  break;
676  } else if (!Pattern->hasBody()) {
677  ::Error("TClingCallFunc::make_wrapper", "Cannot make wrapper for a member function "
678  "instantiation with no body!");
679  return 0;
680  }
681  if (FD->isImplicitlyInstantiable()) {
682  needInstantiation = true;
683  }
684  } break;
685  case FunctionDecl::TK_FunctionTemplateSpecialization: {
686  // This function is the result of instantiating a function
687  // template or possibly an explicit specialization of a
688  // function template. Could be a namespace scope function or a
689  // member function.
690  if (!FD->isTemplateInstantiation()) {
691  // We are either TSK_Undeclared or
692  // TSK_ExplicitSpecialization.
693  // Note: This might be ok, the body might be defined
694  // in a library, and all we have seen is the
695  // header file.
696  //::Error("TClingCallFunc::make_wrapper",
697  // "Cannot make wrapper for a function template "
698  // "explicit specialization which is declared "
699  // "but not defined!");
700  // return 0;
701  break;
702  }
703  const FunctionDecl *Pattern = FD->getTemplateInstantiationPattern();
704  if (!Pattern) {
705  ::Error("TClingCallFunc::make_wrapper", "Cannot make wrapper for a function template"
706  "instantiation with no pattern!");
707  return 0;
708  }
709  FunctionDecl::TemplatedKind PTK = Pattern->getTemplatedKind();
710  TemplateSpecializationKind PTSK = Pattern->getTemplateSpecializationKind();
711  if (
712  // The pattern is an ordinary member function.
713  (PTK == FunctionDecl::TK_NonTemplate) ||
714  // The pattern is an explicit specialization, and
715  // so is not a template.
716  ((PTK != FunctionDecl::TK_FunctionTemplate) &&
717  ((PTSK == TSK_Undeclared) || (PTSK == TSK_ExplicitSpecialization)))) {
718  // Note: This might be ok, the body might be defined
719  // in a library, and all we have seen is the
720  // header file.
721  break;
722  }
723  if (!Pattern->hasBody()) {
724  ::Error("TClingCallFunc::make_wrapper", "Cannot make wrapper for a function template"
725  "instantiation with no body!");
726  return 0;
727  }
728  if (FD->isImplicitlyInstantiable()) {
729  needInstantiation = true;
730  }
731  } break;
732  case FunctionDecl::TK_DependentFunctionTemplateSpecialization: {
733  // This function is the result of instantiating or
734  // specializing a member function of a class template,
735  // or a member function of a class member of a class template,
736  // or a member function template of a class template, or a
737  // member function template of a class member of a class
738  // template where at least some part of the function is
739  // dependent on a template argument.
740  if (!FD->isTemplateInstantiation()) {
741  // We are either TSK_Undeclared or
742  // TSK_ExplicitSpecialization.
743  // Note: This might be ok, the body might be defined
744  // in a library, and all we have seen is the
745  // header file.
746  //::Error("TClingCallFunc::make_wrapper",
747  // "Cannot make wrapper for a dependent function "
748  // "template explicit specialization which is declared "
749  // "but not defined!");
750  // return 0;
751  break;
752  }
753  const FunctionDecl *Pattern = FD->getTemplateInstantiationPattern();
754  if (!Pattern) {
755  ::Error("TClingCallFunc::make_wrapper", "Cannot make wrapper for a dependent function template"
756  "instantiation with no pattern!");
757  return 0;
758  }
759  FunctionDecl::TemplatedKind PTK = Pattern->getTemplatedKind();
760  TemplateSpecializationKind PTSK = Pattern->getTemplateSpecializationKind();
761  if (
762  // The pattern is an ordinary member function.
763  (PTK == FunctionDecl::TK_NonTemplate) ||
764  // The pattern is an explicit specialization, and
765  // so is not a template.
766  ((PTK != FunctionDecl::TK_FunctionTemplate) &&
767  ((PTSK == TSK_Undeclared) || (PTSK == TSK_ExplicitSpecialization)))) {
768  // Note: This might be ok, the body might be defined
769  // in a library, and all we have seen is the
770  // header file.
771  break;
772  }
773  if (!Pattern->hasBody()) {
774  ::Error("TClingCallFunc::make_wrapper", "Cannot make wrapper for a dependent function template"
775  "instantiation with no body!");
776  return 0;
777  }
778  if (FD->isImplicitlyInstantiable()) {
779  needInstantiation = true;
780  }
781  } break;
782  default: {
783  // Will only happen if clang implementation changes.
784  // Protect ourselves in case that happens.
785  ::Error("TClingCallFunc::make_wrapper", "Unhandled template kind!");
786  return 0;
787  } break;
788  }
789  // We do not set needInstantiation to true in these cases:
790  //
791  // isInvalidDecl()
792  // TSK_Undeclared
793  // TSK_ExplicitInstantiationDefinition
794  // TSK_ExplicitSpecialization && !getClassScopeSpecializationPattern()
795  // TSK_ExplicitInstantiationDeclaration &&
796  // getTemplateInstantiationPattern() &&
797  // PatternDecl->hasBody() &&
798  // !PatternDecl->isInlined()
799  //
800  // Set it true in these cases:
801  //
802  // TSK_ImplicitInstantiation
803  // TSK_ExplicitInstantiationDeclaration && (!getPatternDecl() ||
804  // !PatternDecl->hasBody() || PatternDecl->isInlined())
805  //
806  }
807  if (needInstantiation) {
808  clang::FunctionDecl *FDmod = const_cast<clang::FunctionDecl *>(FD);
809  clang::Sema &S = fInterp->getSema();
810  // Could trigger deserialization of decls.
811  cling::Interpreter::PushTransactionRAII RAII(fInterp);
812  S.InstantiateFunctionDefinition(SourceLocation(), FDmod,
813  /*Recursive=*/true,
814  /*DefinitionRequired=*/true);
815  if (!FD->isDefined(Definition)) {
816  ::Error("TClingCallFunc::make_wrapper", "Failed to force template instantiation!");
817  return 0;
818  }
819  }
820  if (Definition) {
821  FunctionDecl::TemplatedKind TK = Definition->getTemplatedKind();
822  switch (TK) {
823  case FunctionDecl::TK_NonTemplate: {
824  // Ordinary function, not a template specialization.
825  if (Definition->isDeleted()) {
826  ::Error("TClingCallFunc::make_wrapper", "Cannot make wrapper for a deleted function!");
827  return 0;
828  } else if (Definition->isLateTemplateParsed()) {
829  ::Error("TClingCallFunc::make_wrapper", "Cannot make wrapper for a late template parsed "
830  "function!");
831  return 0;
832  }
833  // else if (Definition->isDefaulted()) {
834  // // Might not have a body, but we can still use it.
835  //}
836  // else {
837  // // Has a body.
838  //}
839  } break;
840  case FunctionDecl::TK_FunctionTemplate: {
841  // This decl is actually a function template,
842  // not a function at all.
843  ::Error("TClingCallFunc::make_wrapper", "Cannot make wrapper for a function template!");
844  return 0;
845  } break;
846  case FunctionDecl::TK_MemberSpecialization: {
847  // This function is the result of instantiating an ordinary
848  // member function of a class template or of a member class
849  // of a class template.
850  if (Definition->isDeleted()) {
851  ::Error("TClingCallFunc::make_wrapper", "Cannot make wrapper for a deleted member function "
852  "of a specialization!");
853  return 0;
854  } else if (Definition->isLateTemplateParsed()) {
855  ::Error("TClingCallFunc::make_wrapper", "Cannot make wrapper for a late template parsed "
856  "member function of a specialization!");
857  return 0;
858  }
859  // else if (Definition->isDefaulted()) {
860  // // Might not have a body, but we can still use it.
861  //}
862  // else {
863  // // Has a body.
864  //}
865  } break;
866  case FunctionDecl::TK_FunctionTemplateSpecialization: {
867  // This function is the result of instantiating a function
868  // template or possibly an explicit specialization of a
869  // function template. Could be a namespace scope function or a
870  // member function.
871  if (Definition->isDeleted()) {
872  ::Error("TClingCallFunc::make_wrapper", "Cannot make wrapper for a deleted function "
873  "template specialization!");
874  return 0;
875  } else if (Definition->isLateTemplateParsed()) {
876  ::Error("TClingCallFunc::make_wrapper", "Cannot make wrapper for a late template parsed "
877  "function template specialization!");
878  return 0;
879  }
880  // else if (Definition->isDefaulted()) {
881  // // Might not have a body, but we can still use it.
882  //}
883  // else {
884  // // Has a body.
885  //}
886  } break;
887  case FunctionDecl::TK_DependentFunctionTemplateSpecialization: {
888  // This function is the result of instantiating or
889  // specializing a member function of a class template,
890  // or a member function of a class member of a class template,
891  // or a member function template of a class template, or a
892  // member function template of a class member of a class
893  // template where at least some part of the function is
894  // dependent on a template argument.
895  if (Definition->isDeleted()) {
896  ::Error("TClingCallFunc::make_wrapper", "Cannot make wrapper for a deleted dependent function "
897  "template specialization!");
898  return 0;
899  } else if (Definition->isLateTemplateParsed()) {
900  ::Error("TClingCallFunc::make_wrapper", "Cannot make wrapper for a late template parsed "
901  "dependent function template specialization!");
902  return 0;
903  }
904  // else if (Definition->isDefaulted()) {
905  // // Might not have a body, but we can still use it.
906  //}
907  // else {
908  // // Has a body.
909  //}
910  } break;
911  default: {
912  // Will only happen if clang implementation changes.
913  // Protect ourselves in case that happens.
914  ::Error("TClingCallFunc::make_wrapper", "Unhandled template kind!");
915  return 0;
916  } break;
917  }
918  }
919  unsigned min_args = GetMinRequiredArguments();
920  unsigned num_params = FD->getNumParams();
921  //
922  // Make the wrapper name.
923  //
924  {
925  ostringstream buf;
926  buf << "__cf";
927  // const NamedDecl* ND = dyn_cast<NamedDecl>(FD);
928  // string mn;
929  // fInterp->maybeMangleDeclName(ND, mn);
930  // buf << '_' << mn;
931  buf << '_' << gWrapperSerial++;
932  wrapper_name = buf.str();
933  }
934  //
935  // Write the wrapper code.
936  // FIXME: this should be synthesized into the AST!
937  //
938  int indent_level = 0;
939  ostringstream buf;
940  buf << "#pragma clang diagnostic push\n"
941  "#pragma clang diagnostic ignored \"-Wformat-security\"\n"
942  "__attribute__((used)) "
943  "extern \"C\" void ";
944  buf << wrapper_name;
945  buf << "(void* obj, int nargs, void** args, void* ret)\n"
946  "{\n";
947  ++indent_level;
948  if (min_args == num_params) {
949  // No parameters with defaults.
950  make_narg_call_with_return(num_params, class_name, buf, indent_level);
951  } else {
952  // We need one function call clause compiled for every
953  // possible number of arguments per call.
954  for (unsigned N = min_args; N <= num_params; ++N) {
955  for (int i = 0; i < indent_level; ++i) {
956  buf << kIndentString;
957  }
958  buf << "if (nargs == " << N << ") {\n";
959  ++indent_level;
960  make_narg_call_with_return(N, class_name, buf, indent_level);
961  --indent_level;
962  for (int i = 0; i < indent_level; ++i) {
963  buf << kIndentString;
964  }
965  buf << "}\n";
966  }
967  }
968  --indent_level;
969  buf << "}\n"
970  "#pragma clang diagnostic pop";
971  wrapper = buf.str();
972  return 1;
973 }
974 
975 void TClingCallFunc::make_narg_call_with_return(const unsigned N, const string &class_name,
976  ostringstream &buf, int indent_level)
977 {
978  // Make a code string that follows this pattern:
979  //
980  // if (ret) {
981  // new (ret) (return_type) ((class_name*)obj)->func(args...);
982  // }
983  // else {
984  // ((class_name*)obj)->func(args...);
985  // }
986  //
987  const FunctionDecl *FD = GetDecl();
988  if (const CXXConstructorDecl *CD = dyn_cast<CXXConstructorDecl>(FD)) {
989  if (N <= 1 && llvm::isa<UsingShadowDecl>(GetFunctionOrShadowDecl())) {
990  auto SpecMemKind = fInterp->getSema().getSpecialMember(CD);
991  if ((N == 0 && SpecMemKind == clang::Sema::CXXDefaultConstructor) ||
992  (N == 1 &&
993  (SpecMemKind == clang::Sema::CXXCopyConstructor || SpecMemKind == clang::Sema::CXXMoveConstructor))) {
994  // Using declarations cannot inject special members; do not call them
995  // as such. This might happen by using `Base(Base&, int = 12)`, which
996  // is fine to be called as `Derived d(someBase, 42)` but not as
997  // copy constructor of `Derived`.
998  return;
999  }
1000  }
1001  make_narg_ctor_with_return(N, class_name, buf, indent_level);
1002  return;
1003  }
1004  QualType QT = FD->getReturnType().getCanonicalType();
1005  if (QT->isVoidType()) {
1006  ostringstream typedefbuf;
1007  ostringstream callbuf;
1008  for (int i = 0; i < indent_level; ++i) {
1009  callbuf << kIndentString;
1010  }
1011  make_narg_call("void", N, typedefbuf, callbuf, class_name, indent_level);
1012  callbuf << ";\n";
1013  for (int i = 0; i < indent_level; ++i) {
1014  callbuf << kIndentString;
1015  }
1016  callbuf << "return;\n";
1017  buf << typedefbuf.str() << callbuf.str();
1018  } else {
1019  for (int i = 0; i < indent_level; ++i) {
1020  buf << kIndentString;
1021  }
1022 
1023  string type_name;
1024  EReferenceType refType = kNotReference;
1025  bool isPointer = false;
1026 
1027  buf << "if (ret) {\n";
1028  ++indent_level;
1029  {
1030  ostringstream typedefbuf;
1031  ostringstream callbuf;
1032  //
1033  // Write the placement part of the placement new.
1034  //
1035  for (int i = 0; i < indent_level; ++i) {
1036  callbuf << kIndentString;
1037  }
1038  callbuf << "new (ret) ";
1039  collect_type_info(QT, typedefbuf, callbuf, type_name,
1040  refType, isPointer, indent_level, false);
1041  //
1042  // Write the type part of the placement new.
1043  //
1044  callbuf << "(" << type_name.c_str();
1045  if (refType != kNotReference) {
1046  callbuf << "*) (&";
1047  type_name += "&";
1048  } else if (isPointer) {
1049  callbuf << "*) (";
1050  type_name += "*";
1051  } else {
1052  callbuf << ") (";
1053  }
1054  //
1055  // Write the actual function call.
1056  //
1057  make_narg_call(type_name, N, typedefbuf, callbuf, class_name, indent_level);
1058  //
1059  // End the placement new.
1060  //
1061  callbuf << ");\n";
1062  for (int i = 0; i < indent_level; ++i) {
1063  callbuf << kIndentString;
1064  }
1065  callbuf << "return;\n";
1066  //
1067  // Output the whole placement new expression and return statement.
1068  //
1069  buf << typedefbuf.str() << callbuf.str();
1070  }
1071  --indent_level;
1072  for (int i = 0; i < indent_level; ++i) {
1073  buf << kIndentString;
1074  }
1075  buf << "}\n";
1076  for (int i = 0; i < indent_level; ++i) {
1077  buf << kIndentString;
1078  }
1079  buf << "else {\n";
1080  ++indent_level;
1081  {
1082  ostringstream typedefbuf;
1083  ostringstream callbuf;
1084  for (int i = 0; i < indent_level; ++i) {
1085  callbuf << kIndentString;
1086  }
1087  make_narg_call(type_name, N, typedefbuf, callbuf, class_name, indent_level);
1088  callbuf << ";\n";
1089  for (int i = 0; i < indent_level; ++i) {
1090  callbuf << kIndentString;
1091  }
1092  callbuf << "return;\n";
1093  buf << typedefbuf.str() << callbuf.str();
1094  }
1095  --indent_level;
1096  for (int i = 0; i < indent_level; ++i) {
1097  buf << kIndentString;
1098  }
1099  buf << "}\n";
1100  }
1101 }
1102 
1104 {
1106 
1107  const Decl *D = GetFunctionOrShadowDecl();
1108  string wrapper_name;
1109  string wrapper;
1110 
1111  if (get_wrapper_code(wrapper_name, wrapper) == 0) return 0;
1112 
1113  //fprintf(stderr, "%s\n", wrapper.c_str());
1114  //
1115  // Compile the wrapper code.
1116  //
1117  void *F = compile_wrapper(wrapper_name, wrapper);
1118  if (F) {
1119  gWrapperStore.insert(make_pair(D, F));
1120  } else {
1121  ::Error("TClingCallFunc::make_wrapper",
1122  "Failed to compile\n ==== SOURCE BEGIN ====\n%s\n ==== SOURCE END ====",
1123  wrapper.c_str());
1124  }
1125  return (tcling_callfunc_Wrapper_t)F;
1126 }
1127 
1129  ROOT::TMetaUtils::EIOCtorCategory kind, const std::string &type_name)
1130 {
1131  // Make a code string that follows this pattern:
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;
1139  // }
1140  // else {
1141  // *ret = new ClassName[nary];
1142  // }
1143  // }
1144  // else {
1145  // if (!nary) {
1146  // *ret = new (arena) ClassName;
1147  // }
1148  // else {
1149  // *ret = new (arena) ClassName[nary];
1150  // }
1151  // }
1152  // }
1153  //
1154  // When I/O constructor used:
1155  //
1156  // void
1157  // unique_wrapper_ddd(void** ret, void* arena, unsigned long nary)
1158  // {
1159  // if (!arena) {
1160  // if (!nary) {
1161  // *ret = new ClassName((TRootIOCtor*)nullptr);
1162  // }
1163  // else {
1164  // char *buf = malloc(nary * sizeof(ClassName));
1165  // for (int k=0;k<nary;++k)
1166  // new (buf + k * sizeof(ClassName)) ClassName((TRootIOCtor*)nullptr);
1167  // *ret = buf;
1168  // }
1169  // }
1170  // else {
1171  // if (!nary) {
1172  // *ret = new (arena) ClassName((TRootIOCtor*)nullptr);
1173  // }
1174  // else {
1175  // for (int k=0;k<nary;++k)
1176  // new ((char *) arena + k * sizeof(ClassName)) ClassName((TRootIOCtor*)nullptr);
1177  // *ret = arena;
1178  // }
1179  // }
1180  // }
1181  //
1182  //
1183  // Note:
1184  //
1185  // If the class is of POD type, the form:
1186  //
1187  // new ClassName;
1188  //
1189  // does not initialize the object at all, and the form:
1190  //
1191  // new ClassName();
1192  //
1193  // default-initializes the object.
1194  //
1195  // We are using the form without parentheses because that is what
1196  // CINT did.
1197  //
1198  //--
1199  ASTContext &Context = info->GetDecl()->getASTContext();
1200  PrintingPolicy Policy(Context.getPrintingPolicy());
1201  Policy.SuppressTagKeyword = true;
1202  Policy.SuppressUnwrittenScope = true;
1203  //
1204  // Get the class or namespace name.
1205  //
1206  string class_name;
1207  if (const TypeDecl *TD = dyn_cast<TypeDecl>(info->GetDecl())) {
1208  // This is a class, struct, or union member.
1209  QualType QT(TD->getTypeForDecl(), 0);
1210  ROOT::TMetaUtils::GetNormalizedName(class_name, QT, *fInterp, fNormCtxt);
1211  } else if (const NamedDecl *ND = dyn_cast<NamedDecl>(info->GetDecl())) {
1212  // This is a namespace member.
1213  raw_string_ostream stream(class_name);
1214  ND->getNameForDiagnostic(stream, Policy, /*Qualified=*/true);
1215  stream.flush();
1216  }
1217 
1218 
1219  //
1220  // Make the wrapper name.
1221  //
1222  string wrapper_name;
1223  {
1224  ostringstream buf;
1225  buf << "__ctor";
1226  //const NamedDecl* ND = dyn_cast<NamedDecl>(FD);
1227  //string mn;
1228  //fInterp->maybeMangleDeclName(ND, mn);
1229  //buf << '_dtor_' << mn;
1230  buf << '_' << gWrapperSerial++;
1231  wrapper_name = buf.str();
1232  }
1233 
1234  string constr_arg;
1236  constr_arg = string("((") + type_name + "*)nullptr)";
1238  constr_arg = string("(*((") + type_name + "*)arena))";
1239 
1240  //
1241  // Write the wrapper code.
1242  //
1243  int indent_level = 0;
1244  ostringstream buf;
1245  buf << "__attribute__((used)) ";
1246  buf << "extern \"C\" void ";
1247  buf << wrapper_name;
1248  buf << "(void** ret, void* arena, unsigned long nary)\n";
1249  buf << "{\n";
1250 
1251  // if (!arena) {
1252  // if (!nary) {
1253  // *ret = new ClassName;
1254  // }
1255  // else {
1256  // *ret = new ClassName[nary];
1257  // }
1258  // }
1259  indent(buf, ++indent_level);
1260  buf << "if (!arena) {\n";
1261  indent(buf, ++indent_level);
1262  buf << "if (!nary) {\n";
1263  indent(buf, ++indent_level);
1264  buf << "*ret = new " << class_name << constr_arg << ";\n";
1265  indent(buf, --indent_level);
1266  buf << "}\n";
1267  indent(buf, indent_level);
1268  buf << "else {\n";
1269  indent(buf, ++indent_level);
1270  if (constr_arg.empty()) {
1271  buf << "*ret = new " << class_name << "[nary];\n";
1272  } else {
1273  buf << "char *buf = (char *) malloc(nary * sizeof(" << class_name << "));\n";
1274  indent(buf, indent_level);
1275  buf << "for (int k=0;k<nary;++k)\n";
1276  indent(buf, ++indent_level);
1277  buf << "new (buf + k * sizeof(" << class_name << ")) " << class_name << constr_arg << ";\n";
1278  indent(buf, --indent_level);
1279  buf << "*ret = buf;\n";
1280  }
1281  indent(buf, --indent_level);
1282  buf << "}\n";
1283  indent(buf, --indent_level);
1284  buf << "}\n";
1285  // else {
1286  // if (!nary) {
1287  // *ret = new (arena) ClassName;
1288  // }
1289  // else {
1290  // *ret = new (arena) ClassName[nary];
1291  // }
1292  // }
1293  indent(buf, indent_level);
1294  buf << "else {\n";
1295  indent(buf, ++indent_level);
1296  buf << "if (!nary) {\n";
1297  indent(buf, ++indent_level);
1298  buf << "*ret = new (arena) " << class_name << constr_arg << ";\n";
1299  indent(buf, --indent_level);
1300  buf << "}\n";
1301  indent(buf, indent_level);
1302  buf << "else {\n";
1303  indent(buf, ++indent_level);
1304  if (constr_arg.empty()) {
1305  buf << "*ret = new (arena) " << class_name << "[nary];\n";
1306  } else {
1307  buf << "for (int k=0;k<nary;++k)\n";
1308  indent(buf, ++indent_level);
1309  buf << "new ((char *) arena + k * sizeof(" << class_name << ")) " << class_name << constr_arg << ";\n";
1310  indent(buf, --indent_level);
1311  buf << "*ret = arena;\n";
1312  }
1313  indent(buf, --indent_level);
1314  buf << "}\n";
1315  indent(buf, --indent_level);
1316  buf << "}\n";
1317  // End wrapper.
1318  --indent_level;
1319  buf << "}\n";
1320  // Done.
1321  string wrapper(buf.str());
1322  //fprintf(stderr, "%s\n", wrapper.c_str());
1323  //
1324  // Compile the wrapper code.
1325  //
1326  void *F = compile_wrapper(wrapper_name, wrapper,
1327  /*withAccessControl=*/false);
1328  if (F) {
1329  gCtorWrapperStore.insert(make_pair(info->GetDecl(), F));
1330  } else {
1331  ::Error("TClingCallFunc::make_ctor_wrapper",
1332  "Failed to compile\n ==== SOURCE BEGIN ====\n%s\n ==== SOURCE END ====",
1333  wrapper.c_str());
1334  }
1336 }
1337 
1340 {
1341  // Make a code string that follows this pattern:
1342  //
1343  // void
1344  // unique_wrapper_ddd(void* obj, unsigned long nary, int withFree)
1345  // {
1346  // if (withFree) {
1347  // if (!nary) {
1348  // delete (ClassName*) obj;
1349  // }
1350  // else {
1351  // delete[] (ClassName*) obj;
1352  // }
1353  // }
1354  // else {
1355  // typedef ClassName DtorName;
1356  // if (!nary) {
1357  // ((ClassName*)obj)->~DtorName();
1358  // }
1359  // else {
1360  // for (unsigned long i = nary - 1; i > -1; --i) {
1361  // (((ClassName*)obj)+i)->~DtorName();
1362  // }
1363  // }
1364  // }
1365  // }
1366  //
1367  //--
1368  ASTContext &Context = info->GetDecl()->getASTContext();
1369  PrintingPolicy Policy(Context.getPrintingPolicy());
1370  Policy.SuppressTagKeyword = true;
1371  Policy.SuppressUnwrittenScope = true;
1372  //
1373  // Get the class or namespace name.
1374  //
1375  string class_name;
1376  if (const TypeDecl *TD = dyn_cast<TypeDecl>(info->GetDecl())) {
1377  // This is a class, struct, or union member.
1378  QualType QT(TD->getTypeForDecl(), 0);
1379  ROOT::TMetaUtils::GetNormalizedName(class_name, QT, *fInterp, fNormCtxt);
1380  } else if (const NamedDecl *ND = dyn_cast<NamedDecl>(info->GetDecl())) {
1381  // This is a namespace member.
1382  raw_string_ostream stream(class_name);
1383  ND->getNameForDiagnostic(stream, Policy, /*Qualified=*/true);
1384  stream.flush();
1385  }
1386  //
1387  // Make the wrapper name.
1388  //
1389  string wrapper_name;
1390  {
1391  ostringstream buf;
1392  buf << "__dtor";
1393  //const NamedDecl* ND = dyn_cast<NamedDecl>(FD);
1394  //string mn;
1395  //fInterp->maybeMangleDeclName(ND, mn);
1396  //buf << '_dtor_' << mn;
1397  buf << '_' << gWrapperSerial++;
1398  wrapper_name = buf.str();
1399  }
1400  //
1401  // Write the wrapper code.
1402  //
1403  int indent_level = 0;
1404  ostringstream buf;
1405  buf << "__attribute__((used)) ";
1406  buf << "extern \"C\" void ";
1407  buf << wrapper_name;
1408  buf << "(void* obj, unsigned long nary, int withFree)\n";
1409  buf << "{\n";
1410  // if (withFree) {
1411  // if (!nary) {
1412  // delete (ClassName*) obj;
1413  // }
1414  // else {
1415  // delete[] (ClassName*) obj;
1416  // }
1417  // }
1418  ++indent_level;
1419  indent(buf, indent_level);
1420  buf << "if (withFree) {\n";
1421  ++indent_level;
1422  indent(buf, indent_level);
1423  buf << "if (!nary) {\n";
1424  ++indent_level;
1425  indent(buf, indent_level);
1426  buf << "delete (" << class_name << "*) obj;\n";
1427  --indent_level;
1428  indent(buf, indent_level);
1429  buf << "}\n";
1430  indent(buf, indent_level);
1431  buf << "else {\n";
1432  ++indent_level;
1433  indent(buf, indent_level);
1434  buf << "delete[] (" << class_name << "*) obj;\n";
1435  --indent_level;
1436  indent(buf, indent_level);
1437  buf << "}\n";
1438  --indent_level;
1439  indent(buf, indent_level);
1440  buf << "}\n";
1441  // else {
1442  // typedef ClassName Nm;
1443  // if (!nary) {
1444  // ((Nm*)obj)->~Nm();
1445  // }
1446  // else {
1447  // for (unsigned long i = nary - 1; i > -1; --i) {
1448  // (((Nm*)obj)+i)->~Nm();
1449  // }
1450  // }
1451  // }
1452  indent(buf, indent_level);
1453  buf << "else {\n";
1454  ++indent_level;
1455  indent(buf, indent_level);
1456  buf << "typedef " << class_name << " Nm;\n";
1457  buf << "if (!nary) {\n";
1458  ++indent_level;
1459  indent(buf, indent_level);
1460  buf << "((Nm*)obj)->~Nm();\n";
1461  --indent_level;
1462  indent(buf, indent_level);
1463  buf << "}\n";
1464  indent(buf, indent_level);
1465  buf << "else {\n";
1466  ++indent_level;
1467  indent(buf, indent_level);
1468  buf << "do {\n";
1469  ++indent_level;
1470  indent(buf, indent_level);
1471  buf << "(((Nm*)obj)+(--nary))->~Nm();\n";
1472  --indent_level;
1473  indent(buf, indent_level);
1474  buf << "} while (nary);\n";
1475  --indent_level;
1476  indent(buf, indent_level);
1477  buf << "}\n";
1478  --indent_level;
1479  indent(buf, indent_level);
1480  buf << "}\n";
1481  // End wrapper.
1482  --indent_level;
1483  buf << "}\n";
1484  // Done.
1485  string wrapper(buf.str());
1486  //fprintf(stderr, "%s\n", wrapper.c_str());
1487  //
1488  // Compile the wrapper code.
1489  //
1490  void *F = compile_wrapper(wrapper_name, wrapper,
1491  /*withAccessControl=*/false);
1492  if (F) {
1493  gDtorWrapperStore.insert(make_pair(info->GetDecl(), F));
1494  } else {
1495  ::Error("TClingCallFunc::make_dtor_wrapper",
1496  "Failed to compile\n ==== SOURCE BEGIN ====\n%s\n ==== SOURCE END ====",
1497  wrapper.c_str());
1498  }
1499 
1501 }
1502 
1503 class ValHolder {
1504 public:
1505  union {
1506  long double ldbl;
1507  double dbl;
1508  float flt;
1509  //__uint128_t ui128;
1510  //__int128_t i128;
1511  unsigned long long ull;
1512  long long ll;
1513  unsigned long ul;
1514  long l;
1515  unsigned int ui;
1516  int i;
1517  unsigned short us;
1518  short s;
1519  //char32_t c32;
1520  //char16_t c16;
1521  //unsigned wchar_t uwc; - non-standard
1522  wchar_t wc;
1523  unsigned char uc;
1524  signed char sc;
1525  char c;
1526  bool b;
1527  void *vp;
1528  } u;
1529 };
1530 
1531 void TClingCallFunc::exec(void *address, void *ret)
1532 {
1533  SmallVector<ValHolder, 8> vh_ary;
1534  SmallVector<void *, 8> vp_ary;
1535 
1536  unsigned num_args = fArgVals.size();
1537  {
1539 
1540  const FunctionDecl *FD = GetDecl();
1541 
1542  //
1543  // Convert the arguments from cling::Value to their
1544  // actual type and store them in a holder for passing to the
1545  // wrapper function by pointer to value.
1546  //
1547  unsigned num_params = FD->getNumParams();
1548 
1549  if (num_args < GetMinRequiredArguments()) {
1550  ::Error("TClingCallFunc::exec",
1551  "Not enough arguments provided for %s (%d instead of the minimum %d)",
1552  fMethod->Name(),
1553  num_args, (int)GetMinRequiredArguments());
1554  return;
1555  }
1556  if (address == 0 && dyn_cast<CXXMethodDecl>(FD)
1557  && !(dyn_cast<CXXMethodDecl>(FD))->isStatic()
1558  && !dyn_cast<CXXConstructorDecl>(FD)) {
1559  ::Error("TClingCallFunc::exec",
1560  "The method %s is called without an object.",
1561  fMethod->Name());
1562  return;
1563  }
1564  vh_ary.reserve(num_args);
1565  vp_ary.reserve(num_args);
1566  for (unsigned i = 0U; i < num_args; ++i) {
1567  QualType Ty;
1568  if (i < num_params) {
1569  const ParmVarDecl *PVD = FD->getParamDecl(i);
1570  Ty = PVD->getType();
1571  } else {
1572  Ty = fArgVals[i].getType();
1573  }
1574  QualType QT = Ty.getCanonicalType();
1575  if (const BuiltinType *BT =
1576  dyn_cast<BuiltinType>(&*QT)) {
1577  //
1578  // WARNING!!!
1579  //
1580  // This switch is organized in order-of-declaration
1581  // so that the produced assembly code is optimal.
1582  // Do not reorder!
1583  //
1584  switch (BT->getKind()) {
1585  //
1586  // Builtin Types
1587  //
1588  case BuiltinType::Void: {
1589  // void
1590  ::Error("TClingCallFunc::exec(void*)",
1591  "Invalid type 'Void'!");
1592  return;
1593  }
1594  break;
1595  //
1596  // Unsigned Types
1597  //
1598  case BuiltinType::Bool: {
1599  // bool
1600  ValHolder vh;
1601  vh.u.b = (bool) sv_to_ulong_long(fArgVals[i]);
1602  vh_ary.push_back(vh);
1603  vp_ary.push_back(&vh_ary.back());
1604  }
1605  break;
1606  case BuiltinType::Char_U: {
1607  // char on targets where it is unsigned
1608  ValHolder vh;
1609  vh.u.c = (char) sv_to_ulong_long(fArgVals[i]);
1610  vh_ary.push_back(vh);
1611  vp_ary.push_back(&vh_ary.back());
1612  }
1613  break;
1614  case BuiltinType::UChar: {
1615  // unsigned char
1616  ValHolder vh;
1617  vh.u.uc = (unsigned char) sv_to_ulong_long(fArgVals[i]);
1618  vh_ary.push_back(vh);
1619  vp_ary.push_back(&vh_ary.back());
1620  }
1621  break;
1622  case BuiltinType::WChar_U: {
1623  // wchar_t on targets where it is unsigned.
1624  // The standard doesn't allow to specify signednedd of wchar_t
1625  // thus this maps simply to wchar_t.
1626  ValHolder vh;
1627  vh.u.wc = (wchar_t) sv_to_ulong_long(fArgVals[i]);
1628  vh_ary.push_back(vh);
1629  vp_ary.push_back(&vh_ary.back());
1630  }
1631  break;
1632  case BuiltinType::Char16: {
1633  // char16_t
1634  //ValHolder vh;
1635  //vh.u.c16 = (char16_t) sv_to_ulong_long(fArgVals[i]);
1636  //vh_ary.push_back(vh);
1637  //vp_ary.push_back(&vh_ary.back());
1638  }
1639  break;
1640  case BuiltinType::Char32: {
1641  // char32_t
1642  //ValHolder vh;
1643  //vh.u.c32 = (char32_t) sv_to_ulong_long(fArgVals[i]);
1644  //vh_ary.push_back(vh);
1645  //vp_ary.push_back(&vh_ary.back());
1646  }
1647  break;
1648  case BuiltinType::UShort: {
1649  // unsigned short
1650  ValHolder vh;
1651  vh.u.us = (unsigned short) sv_to_ulong_long(fArgVals[i]);
1652  vh_ary.push_back(vh);
1653  vp_ary.push_back(&vh_ary.back());
1654  }
1655  break;
1656  case BuiltinType::UInt: {
1657  // unsigned int
1658  ValHolder vh;
1659  vh.u.ui = (unsigned int) sv_to_ulong_long(fArgVals[i]);
1660  vh_ary.push_back(vh);
1661  vp_ary.push_back(&vh_ary.back());
1662  }
1663  break;
1664  case BuiltinType::ULong: {
1665  // unsigned long
1666  ValHolder vh;
1667  vh.u.ul = (unsigned long) sv_to_ulong_long(fArgVals[i]);
1668  vh_ary.push_back(vh);
1669  vp_ary.push_back(&vh_ary.back());
1670  }
1671  break;
1672  case BuiltinType::ULongLong: {
1673  // unsigned long long
1674  ValHolder vh;
1675  vh.u.ull = (unsigned long long) sv_to_ulong_long(fArgVals[i]);
1676  vh_ary.push_back(vh);
1677  vp_ary.push_back(&vh_ary.back());
1678  }
1679  break;
1680  case BuiltinType::UInt128: {
1681  // __uint128_t
1682  }
1683  break;
1684  //
1685  // Signed Types
1686  //
1687  //
1688  // Signed Types
1689  //
1690  case BuiltinType::Char_S: {
1691  // char on targets where it is signed
1692  ValHolder vh;
1693  vh.u.c = (char) sv_to_long_long(fArgVals[i]);
1694  vh_ary.push_back(vh);
1695  vp_ary.push_back(&vh_ary.back());
1696  }
1697  break;
1698  case BuiltinType::SChar: {
1699  // signed char
1700  ValHolder vh;
1701  vh.u.sc = (signed char) sv_to_long_long(fArgVals[i]);
1702  vh_ary.push_back(vh);
1703  vp_ary.push_back(&vh_ary.back());
1704  }
1705  break;
1706  case BuiltinType::WChar_S: {
1707  // wchar_t on targets where it is signed.
1708  // The standard doesn't allow to specify signednedd of wchar_t
1709  // thus this maps simply to wchar_t.
1710  ValHolder vh;
1711  vh.u.wc = (wchar_t) sv_to_long_long(fArgVals[i]);
1712  vh_ary.push_back(vh);
1713  vp_ary.push_back(&vh_ary.back());
1714  }
1715  break;
1716  case BuiltinType::Short: {
1717  // short
1718  ValHolder vh;
1719  vh.u.s = (short) sv_to_long_long(fArgVals[i]);
1720  vh_ary.push_back(vh);
1721  vp_ary.push_back(&vh_ary.back());
1722  }
1723  break;
1724  case BuiltinType::Int: {
1725  // int
1726  ValHolder vh;
1727  vh.u.i = (int) sv_to_long_long(fArgVals[i]);
1728  vh_ary.push_back(vh);
1729  vp_ary.push_back(&vh_ary.back());
1730  }
1731  break;
1732  case BuiltinType::Long: {
1733  // long
1734  ValHolder vh;
1735  vh.u.l = (long) sv_to_long_long(fArgVals[i]);
1736  vh_ary.push_back(vh);
1737  vp_ary.push_back(&vh_ary.back());
1738  }
1739  break;
1740  case BuiltinType::LongLong: {
1741  // long long
1742  ValHolder vh;
1743  vh.u.ll = (long long) sv_to_long_long(fArgVals[i]);
1744  vh_ary.push_back(vh);
1745  vp_ary.push_back(&vh_ary.back());
1746  }
1747  break;
1748  case BuiltinType::Int128: {
1749  // __int128_t
1750  ::Error("TClingCallFunc::exec(void*)",
1751  "Invalid type 'Int128'!");
1752  return;
1753  }
1754  break;
1755  case BuiltinType::Half: {
1756  // half in OpenCL, __fp16 in ARM NEON
1757  ::Error("TClingCallFunc::exec(void*)",
1758  "Invalid type 'Half'!");
1759  return;
1760  }
1761  break;
1762  case BuiltinType::Float: {
1763  // float
1764  ValHolder vh;
1765  vh.u.flt = sv_to<float>(fArgVals[i]);
1766  vh_ary.push_back(vh);
1767  vp_ary.push_back(&vh_ary.back());
1768  }
1769  break;
1770  case BuiltinType::Double: {
1771  // double
1772  ValHolder vh;
1773  vh.u.dbl = sv_to<double>(fArgVals[i]);
1774  vh_ary.push_back(vh);
1775  vp_ary.push_back(&vh_ary.back());
1776  }
1777  break;
1778  case BuiltinType::LongDouble: {
1779  // long double
1780  ValHolder vh;
1781  vh.u.ldbl = sv_to<long double>(fArgVals[i]);
1782  vh_ary.push_back(vh);
1783  vp_ary.push_back(&vh_ary.back());
1784  }
1785  break;
1786  //
1787  // Language-Specific Types
1788  //
1789  case BuiltinType::NullPtr: {
1790  // C++11 nullptr
1791  ValHolder vh;
1792  vh.u.vp = fArgVals[i].getPtr();
1793  vh_ary.push_back(vh);
1794  vp_ary.push_back(&vh_ary.back());
1795  }
1796  break;
1797  default: {
1798  // There should be no others. This is here in case
1799  // this changes in the future.
1800  ::Error("TClingCallFunc::exec(void*)",
1801  "Unhandled builtin type!");
1802  QT->dump();
1803  return;
1804  }
1805  break;
1806  }
1807  } else if (QT->isReferenceType()) {
1808  // the argument is already a pointer value (point to the same thing
1809  // as the reference.
1810  vp_ary.push_back((void *) sv_to_ulong_long(fArgVals[i]));
1811  } else if (QT->isPointerType() || QT->isArrayType()) {
1812  ValHolder vh;
1813  vh.u.vp = (void *) sv_to_ulong_long(fArgVals[i]);
1814  vh_ary.push_back(vh);
1815  vp_ary.push_back(&vh_ary.back());
1816  } else if (QT->isRecordType()) {
1817  // the argument is already a pointer value (pointing to object passed
1818  // by value).
1819  vp_ary.push_back((void *) sv_to_ulong_long(fArgVals[i]));
1820  } else if (const EnumType *ET =
1821  dyn_cast<EnumType>(&*QT)) {
1822  // Note: We may need to worry about the underlying type
1823  // of the enum here.
1824  (void) ET;
1825  ValHolder vh;
1826  vh.u.i = (int) sv_to_long_long(fArgVals[i]);
1827  vh_ary.push_back(vh);
1828  vp_ary.push_back(&vh_ary.back());
1829  } else if (QT->isMemberPointerType()) {
1830  ValHolder vh;
1831  vh.u.vp = (void *) sv_to_ulong_long(fArgVals[i]);
1832  vh_ary.push_back(vh);
1833  vp_ary.push_back(&vh_ary.back());
1834  } else {
1835  ::Error("TClingCallFunc::exec(void*)",
1836  "Invalid type (unrecognized)!");
1837  QT->dump();
1838  return;
1839  }
1840  }
1841  } // End of scope holding the lock
1842  (*fWrapper)(address, (int)num_args, (void **)vp_ary.data(), ret);
1843 }
1844 
1845 template <typename T>
1846 void TClingCallFunc::execWithLL(void *address, cling::Value *val)
1847 {
1848  T ret; // leave uninit for valgrind's sake!
1849  exec(address, &ret);
1850  val->getLL() = ret;
1851 }
1852 
1853 template <typename T>
1855 {
1856  T ret; // leave uninit for valgrind's sake!
1857  exec(address, &ret);
1858  val->getULL() = ret;
1859 }
1860 
1861 // Handle integral types.
1862 template <class T>
1864 {
1865  ret = cling::Value::Create<T>(QT.getAsOpaquePtr(), *fInterp);
1866  static_assert(std::is_integral<T>::value, "Must be called with integral T");
1867  if (std::is_signed<T>::value)
1868  return [this](void* address, cling::Value& ret) { execWithLL<T>(address, &ret); };
1869  else
1870  return [this](void* address, cling::Value& ret) { execWithULL<T>(address, &ret); };
1871 }
1872 
1873 // Handle builtin types.
1875 TClingCallFunc::InitRetAndExecBuiltin(QualType QT, const clang::BuiltinType *BT, cling::Value &ret) {
1876  switch (BT->getKind()) {
1877  case BuiltinType::Void: {
1878  ret = cling::Value::Create<void>(QT.getAsOpaquePtr(), *fInterp);
1879  return [this](void* address, cling::Value& ret) { exec(address, 0); };
1880  break;
1881  }
1882 
1883  //
1884  // Unsigned Types
1885  //
1886  case BuiltinType::Bool:
1887  return InitRetAndExecIntegral<bool>(QT, ret);
1888  break;
1889  case BuiltinType::Char_U: // char on targets where it is unsigned
1890  case BuiltinType::UChar:
1891  return InitRetAndExecIntegral<char>(QT, ret);
1892  break;
1893  case BuiltinType::WChar_U:
1894  return InitRetAndExecIntegral<wchar_t>(QT, ret);
1895  break;
1896  case BuiltinType::Char16:
1897  ::Error("TClingCallFunc::InitRetAndExecBuiltin",
1898  "Invalid type 'char16_t'!");
1899  return {};
1900  break;
1901  case BuiltinType::Char32:
1902  ::Error("TClingCallFunc::InitRetAndExecBuiltin",
1903  "Invalid type 'char32_t'!");
1904  return {};
1905  break;
1906  case BuiltinType::UShort:
1907  return InitRetAndExecIntegral<unsigned short>(QT, ret);
1908  break;
1909  case BuiltinType::UInt:
1910  return InitRetAndExecIntegral<unsigned int>(QT, ret);
1911  break;
1912  case BuiltinType::ULong:
1913  return InitRetAndExecIntegral<unsigned long>(QT, ret);
1914  break;
1915  case BuiltinType::ULongLong:
1916  return InitRetAndExecIntegral<unsigned long long>(QT, ret);
1917  break;
1918  case BuiltinType::UInt128: {
1919  ::Error("TClingCallFunc::InitRetAndExecBuiltin",
1920  "Invalid type '__uint128_t'!");
1921  return {};
1922  }
1923  break;
1924 
1925  //
1926  // Signed Types
1927  //
1928  case BuiltinType::Char_S: // char on targets where it is signed
1929  case BuiltinType::SChar:
1930  return InitRetAndExecIntegral<signed char>(QT, ret);
1931  break;
1932  case BuiltinType::WChar_S:
1933  // wchar_t on targets where it is signed.
1934  // The standard doesn't allow to specify signednedd of wchar_t
1935  // thus this maps simply to wchar_t.
1936  return InitRetAndExecIntegral<wchar_t>(QT, ret);
1937  break;
1938  case BuiltinType::Short:
1939  return InitRetAndExecIntegral<short>(QT, ret);
1940  break;
1941  case BuiltinType::Int:
1942  return InitRetAndExecIntegral<int>(QT, ret);
1943  break;
1944  case BuiltinType::Long:
1945  return InitRetAndExecIntegral<long>(QT, ret);
1946  break;
1947  case BuiltinType::LongLong:
1948  return InitRetAndExecIntegral<long long>(QT, ret);
1949  break;
1950  case BuiltinType::Int128:
1951  ::Error("TClingCallFunc::InitRetAndExecBuiltin",
1952  "Invalid type '__int128_t'!");
1953  return {};
1954  break;
1955  case BuiltinType::Half:
1956  // half in OpenCL, __fp16 in ARM NEON
1957  ::Error("TClingCallFunc::InitRetAndExecBuiltin",
1958  "Invalid type 'Half'!");
1959  return {};
1960  break;
1961  case BuiltinType::Float: {
1962  ret = cling::Value::Create<float>(QT.getAsOpaquePtr(), *fInterp);
1963  return [this](void* address, cling::Value& ret) { exec(address, &ret.getFloat()); };
1964  break;
1965  }
1966  case BuiltinType::Double: {
1967  ret = cling::Value::Create<double>(QT.getAsOpaquePtr(), *fInterp);
1968  return [this](void* address, cling::Value& ret) { exec(address, &ret.getDouble()); };
1969  break;
1970  }
1971  case BuiltinType::LongDouble: {
1972  ret = cling::Value::Create<long double>(QT.getAsOpaquePtr(), *fInterp);
1973  return [this](void* address, cling::Value& ret) { exec(address, &ret.getLongDouble()); };
1974  break;
1975  }
1976  //
1977  // Language-Specific Types
1978  //
1979  case BuiltinType::NullPtr:
1980  // C++11 nullptr
1981  ::Error("TClingCallFunc::InitRetAndExecBuiltin",
1982  "Invalid type 'nullptr'!");
1983  return {};
1984  break;
1985  default:
1986  break;
1987  }
1988  return {};
1989 }
1990 
1991 
1994  if (QT->isReferenceType()) {
1995  ret = cling::Value(QT, *fInterp);
1996  return [this](void* address, cling::Value& ret) { exec(address, &ret.getPtr()); };
1997  } else if (QT->isMemberPointerType()) {
1998  const MemberPointerType *MPT = QT->getAs<MemberPointerType>();
1999  if (MPT->isMemberDataPointer()) {
2000  // A member data pointer is a actually a struct with one
2001  // member of ptrdiff_t, the offset from the base of the object
2002  // storage to the storage for the designated data member.
2003  // But that's not relevant: we use it as a non-builtin, allocated
2004  // type.
2005  ret = cling::Value(QT, *fInterp);
2006  return [this](void* address, cling::Value& ret) { exec(address, ret.getPtr()); };
2007  }
2008  // We are a function member pointer.
2009  ret = cling::Value(QT, *fInterp);
2010  return [this](void* address, cling::Value& ret) { exec(address, &ret.getPtr()); };
2011  } else if (QT->isPointerType() || QT->isArrayType()) {
2012  // Note: ArrayType is an illegal function return value type.
2013  ret = cling::Value::Create<void*>(QT.getAsOpaquePtr(), *fInterp);
2014  return [this](void* address, cling::Value& ret) { exec(address, &ret.getPtr()); };
2015  } else if (QT->isRecordType()) {
2016  ret = cling::Value(QT, *fInterp);
2017  return [this](void* address, cling::Value& ret) { exec(address, ret.getPtr()); };
2018  } else if (const EnumType *ET = dyn_cast<EnumType>(&*QT)) {
2019  // Note: We may need to worry about the underlying type
2020  // of the enum here.
2021  (void) ET;
2022  ret = cling::Value(QT, *fInterp);
2023  return [this](void* address, cling::Value& ret) { execWithLL<int>(address, &ret); };
2024  } else if (const BuiltinType *BT = dyn_cast<BuiltinType>(&*QT)) {
2025  return InitRetAndExecBuiltin(QT, BT, ret);
2026  }
2027  ::Error("TClingCallFunc::exec_with_valref_return",
2028  "Unrecognized return type!");
2029  QT->dump();
2030  return {};
2031 }
2032 
2034 TClingCallFunc::InitRetAndExec(const clang::FunctionDecl *FD, cling::Value &ret) {
2035  if (llvm::isa<CXXConstructorDecl>(FD)) {
2036  ASTContext &Context = FD->getASTContext();
2037  const TypeDecl *TD = dyn_cast<TypeDecl>(GetDeclContext());
2038  QualType ClassTy(TD->getTypeForDecl(), 0);
2039  QualType QT = Context.getLValueReferenceType(ClassTy);
2040  ret = cling::Value(QT, *fInterp);
2041  // Store the new()'ed address in getPtr()
2042  return [this](void* address, cling::Value& ret) { exec(address, &ret.getPtr()); };
2043  } else {
2044  QualType QT = FD->getReturnType().getCanonicalType();
2045  return InitRetAndExecNoCtor(QT, ret);
2046  }
2047 }
2048 
2050 {
2051  if (!ret) {
2052  exec(address, 0);
2053  return;
2054  }
2055  std::function<void(void*, cling::Value&)> execFunc;
2056 
2057  /* Release lock during user function execution*/
2058  {
2060  execFunc = InitRetAndExec(GetDecl(), *ret);
2061  }
2062 
2063  if (execFunc)
2064  execFunc(address, *ret);
2065  return;
2066 }
2067 
2068 void TClingCallFunc::EvaluateArgList(const string &ArgList)
2069 {
2071 
2072  SmallVector<Expr *, 4> exprs;
2073  fInterp->getLookupHelper().findArgList(ArgList, exprs,
2074  gDebug > 5 ? cling::LookupHelper::WithDiagnostics
2075  : cling::LookupHelper::NoDiagnostics);
2076  for (SmallVectorImpl<Expr *>::const_iterator I = exprs.begin(),
2077  E = exprs.end(); I != E; ++I) {
2078  cling::Value val;
2079  EvaluateExpr(*fInterp, *I, val);
2080  if (!val.isValid()) {
2081  // Bad expression, all done.
2082  ::Error("TClingCallFunc::EvaluateArgList",
2083  "Bad expression in parameter %d of '%s'!",
2084  (int)(I - exprs.begin()),
2085  ArgList.c_str());
2086  return;
2087  }
2088  fArgVals.push_back(val);
2089  }
2090 }
2091 
2092 void TClingCallFunc::Exec(void *address, TInterpreterValue *interpVal/*=0*/)
2093 {
2094  IFacePtr();
2095  if (!fWrapper) {
2096  ::Error("TClingCallFunc::Exec(address, interpVal)",
2097  "Called with no wrapper, not implemented!");
2098  return;
2099  }
2100  if (!interpVal) {
2101  exec(address, 0);
2102  return;
2103  }
2104  cling::Value *val = reinterpret_cast<cling::Value *>(interpVal->GetValAddr());
2105  exec_with_valref_return(address, val);
2106 }
2107 
2108 template <typename T>
2109 T TClingCallFunc::ExecT(void *address)
2110 {
2111  IFacePtr();
2112  if (!fWrapper) {
2113  ::Error("TClingCallFunc::ExecT",
2114  "Called with no wrapper, not implemented!");
2115  return 0;
2116  }
2117  cling::Value ret;
2118  exec_with_valref_return(address, &ret);
2119  if (!ret.isValid()) {
2120  // Sometimes we are called on a function returning void!
2121  return 0;
2122  }
2123 
2124  if (fReturnIsRecordType)
2125  ((TCling *)gCling)->RegisterTemporary(ret);
2126  return sv_to<T>(ret);
2127 }
2128 
2130 {
2131  return ExecT<long>(address);
2132 }
2133 
2134 long long TClingCallFunc::ExecInt64(void *address)
2135 {
2136  return ExecT<long long>(address);
2137 }
2138 
2139 double TClingCallFunc::ExecDouble(void *address)
2140 {
2141  return ExecT<double>(address);
2142 }
2143 
2144 void TClingCallFunc::ExecWithArgsAndReturn(void *address, const void *args[] /*= 0*/,
2145  int nargs /*= 0*/, void *ret/*= 0*/)
2146 {
2147  IFacePtr();
2148  if (!fWrapper) {
2149  ::Error("TClingCallFunc::ExecWithArgsAndReturn(address, args, ret)",
2150  "Called with no wrapper, not implemented!");
2151  return;
2152  }
2153  (*fWrapper)(address, nargs, const_cast<void **>(args), ret);
2154 }
2155 
2156 void TClingCallFunc::ExecWithReturn(void *address, void *ret/*= 0*/)
2157 {
2158  IFacePtr();
2159  if (!fWrapper) {
2160  ::Error("TClingCallFunc::ExecWithReturn(address, ret)",
2161  "Called with no wrapper, not implemented!");
2162  return;
2163  }
2164  exec(address, ret);
2165 }
2166 
2169  const std::string &type_name,
2170  void *address /*=0*/, unsigned long nary /*= 0UL*/)
2171 {
2172  if (!info->IsValid()) {
2173  ::Error("TClingCallFunc::ExecDefaultConstructor", "Invalid class info!");
2174  return nullptr;
2175  }
2176  tcling_callfunc_ctor_Wrapper_t wrapper = nullptr;
2177  {
2179  auto D = info->GetDecl();
2180  //if (!info->HasDefaultConstructor()) {
2181  // // FIXME: We might have a ROOT ioctor, we might
2182  // // have to check for that here.
2183  // ::Error("TClingCallFunc::ExecDefaultConstructor",
2184  // "Class has no default constructor: %s",
2185  // info->Name());
2186  // return 0;
2187  //}
2188  auto I = gCtorWrapperStore.find(D);
2189  if (I != gCtorWrapperStore.end()) {
2190  wrapper = (tcling_callfunc_ctor_Wrapper_t) I->second;
2191  } else {
2192  wrapper = make_ctor_wrapper(info, kind, type_name);
2193  }
2194  }
2195  if (!wrapper) {
2196  ::Error("TClingCallFunc::ExecDefaultConstructor",
2197  "Called with no wrapper, not implemented!");
2198  return nullptr;
2199  }
2200  void *obj = 0;
2201  (*wrapper)(&obj, address, nary);
2202  return obj;
2203 }
2204 
2205 void TClingCallFunc::ExecDestructor(const TClingClassInfo *info, void *address /*=0*/,
2206  unsigned long nary /*= 0UL*/, bool withFree /*= true*/)
2207 {
2208  if (!info->IsValid()) {
2209  ::Error("TClingCallFunc::ExecDestructor", "Invalid class info!");
2210  return;
2211  }
2212 
2213  tcling_callfunc_dtor_Wrapper_t wrapper = 0;
2214  {
2216  const Decl *D = info->GetDecl();
2217  map<const Decl *, void *>::iterator I = gDtorWrapperStore.find(D);
2218  if (I != gDtorWrapperStore.end()) {
2219  wrapper = (tcling_callfunc_dtor_Wrapper_t) I->second;
2220  } else {
2221  wrapper = make_dtor_wrapper(info);
2222  }
2223  }
2224  if (!wrapper) {
2225  ::Error("TClingCallFunc::ExecDestructor",
2226  "Called with no wrapper, not implemented!");
2227  return;
2228  }
2229  (*wrapper)(address, nary, withFree);
2230 }
2231 
2234 {
2235  return new TClingMethodInfo(*fMethod);
2236 }
2237 
2239 {
2240  fMethod.reset();
2241  fWrapper = 0;
2242  fDecl = nullptr;
2243  fMinRequiredArguments = -1;
2244  ResetArg();
2245 }
2246 
2248 {
2249  Init();
2250  fMethod = std::unique_ptr<TClingMethodInfo>(new TClingMethodInfo(minfo));
2251 }
2252 
2253 void TClingCallFunc::Init(std::unique_ptr<TClingMethodInfo> minfo)
2254 {
2255  Init();
2256  fMethod = std::move(minfo);
2257 }
2258 
2260 {
2261  if (!IsValid()) {
2262  return 0;
2263  }
2264  if (!fWrapper) {
2265  const Decl *decl = GetFunctionOrShadowDecl();
2266 
2268  map<const Decl *, void *>::iterator I = gWrapperStore.find(decl);
2269  if (I != gWrapperStore.end()) {
2270  fWrapper = (tcling_callfunc_Wrapper_t) I->second;
2271  } else {
2272  fWrapper = make_wrapper();
2273  }
2274  }
2275  return (void *)fWrapper;
2276 }
2277 
2279 {
2280  if (!fMethod) {
2281  return false;
2282  }
2283  return fMethod->IsValid();
2284 }
2285 
2287 {
2288  if (!IsValid()) {
2289  ::Error("TClingCallFunc::IFacePtr(kind)",
2290  "Attempt to get interface while invalid.");
2292  }
2293  if (!fWrapper) {
2294  const Decl *decl = GetFunctionOrShadowDecl();
2295 
2297  map<const Decl *, void *>::iterator I = gWrapperStore.find(decl);
2298  if (I != gWrapperStore.end()) {
2299  fWrapper = (tcling_callfunc_Wrapper_t) I->second;
2300  } else {
2301  fWrapper = make_wrapper();
2302  }
2303 
2304  fReturnIsRecordType = GetDecl()->getReturnType().getCanonicalType()->isRecordType();
2305  }
2306  return TInterpreter::CallFuncIFacePtr_t(fWrapper);
2307 }
2308 
2309 
2311 {
2312  fArgVals.clear();
2313 }
2314 
2315 void TClingCallFunc::SetArg(unsigned long param)
2316 {
2317  const ASTContext &C = fInterp->getCI()->getASTContext();
2318  fArgVals.push_back(cling::Value(C.UnsignedLongTy, *fInterp));
2319  fArgVals.back().getLL() = param;
2320 }
2321 
2322 void TClingCallFunc::SetArg(long param)
2323 {
2324  const ASTContext &C = fInterp->getCI()->getASTContext();
2325  fArgVals.push_back(cling::Value(C.LongTy, *fInterp));
2326  fArgVals.back().getLL() = param;
2327 }
2328 
2329 void TClingCallFunc::SetArg(float param)
2330 {
2331  const ASTContext &C = fInterp->getCI()->getASTContext();
2332  fArgVals.push_back(cling::Value(C.FloatTy, *fInterp));
2333  fArgVals.back().getFloat() = param;
2334 }
2335 
2336 void TClingCallFunc::SetArg(double param)
2337 {
2338  const ASTContext &C = fInterp->getCI()->getASTContext();
2339  fArgVals.push_back(cling::Value(C.DoubleTy, *fInterp));
2340  fArgVals.back().getDouble() = param;
2341 }
2342 
2343 void TClingCallFunc::SetArg(long long param)
2344 {
2345  const ASTContext &C = fInterp->getCI()->getASTContext();
2346  fArgVals.push_back(cling::Value(C.LongLongTy, *fInterp));
2347  fArgVals.back().getLL() = param;
2348 }
2349 
2350 void TClingCallFunc::SetArg(unsigned long long param)
2351 {
2352  const ASTContext &C = fInterp->getCI()->getASTContext();
2353  fArgVals.push_back(cling::Value(C.UnsignedLongLongTy, *fInterp));
2354  fArgVals.back().getULL() = param;
2355 }
2356 
2357 void TClingCallFunc::SetArgArray(long *paramArr, int nparam)
2358 {
2359  ResetArg();
2360  for (int i = 0; i < nparam; ++i) {
2361  SetArg(paramArr[i]);
2362  }
2363 }
2364 
2365 void TClingCallFunc::SetArgs(const char *params)
2366 {
2367  ResetArg();
2368  EvaluateArgList(params);
2369 }
2370 
2371 void TClingCallFunc::SetFunc(const TClingClassInfo *info, const char *method, const char *arglist,
2372  long *poffset)
2373 {
2374  SetFunc(info, method, arglist, false, poffset);
2375 }
2376 
2377 void TClingCallFunc::SetFunc(const TClingClassInfo *info, const char *method, const char *arglist,
2378  bool objectIsConst, long *poffset)
2379 {
2380  Init(std::unique_ptr<TClingMethodInfo>(new TClingMethodInfo(fInterp)));
2381  if (poffset) {
2382  *poffset = 0L;
2383  }
2384  ResetArg();
2385  if (!info->IsValid()) {
2386  ::Error("TClingCallFunc::SetFunc", "Class info is invalid!");
2387  return;
2388  }
2389  if (!strcmp(arglist, ")")) {
2390  // CINT accepted a single right paren as meaning no arguments.
2391  arglist = "";
2392  }
2393  *fMethod = info->GetMethodWithArgs(method, arglist, objectIsConst, poffset);
2394  if (!fMethod->IsValid()) {
2395  //::Error("TClingCallFunc::SetFunc", "Could not find method %s(%s)", method,
2396  // arglist);
2397  return;
2398  }
2399  // FIXME: The arglist was already parsed by the lookup, we should
2400  // enhance the lookup to return the resulting expression
2401  // list so we do not need to parse it again here.
2402  EvaluateArgList(arglist);
2403 }
2404 
2406 {
2407  Init(std::unique_ptr<TClingMethodInfo>(new TClingMethodInfo(*info)));
2408  ResetArg();
2409  if (!fMethod->IsValid()) {
2410  return;
2411  }
2412 }
2413 
2414 void TClingCallFunc::SetFuncProto(const TClingClassInfo *info, const char *method,
2415  const char *proto, long *poffset,
2416  EFunctionMatchMode mode/*=kConversionMatch*/)
2417 {
2418  SetFuncProto(info, method, proto, false, poffset, mode);
2419 }
2420 
2421 void TClingCallFunc::SetFuncProto(const TClingClassInfo *info, const char *method,
2422  const char *proto, bool objectIsConst, long *poffset,
2423  EFunctionMatchMode mode/*=kConversionMatch*/)
2424 {
2425  Init(std::unique_ptr<TClingMethodInfo>(new TClingMethodInfo(fInterp)));
2426  if (poffset) {
2427  *poffset = 0L;
2428  }
2429  ResetArg();
2430  if (!info->IsValid()) {
2431  ::Error("TClingCallFunc::SetFuncProto", "Class info is invalid!");
2432  return;
2433  }
2434  *fMethod = info->GetMethod(method, proto, objectIsConst, poffset, mode);
2435  if (!fMethod->IsValid()) {
2436  //::Error("TClingCallFunc::SetFuncProto", "Could not find method %s(%s)",
2437  // method, proto);
2438  return;
2439  }
2440 }
2441 
2442 void TClingCallFunc::SetFuncProto(const TClingClassInfo *info, const char *method,
2443  const llvm::SmallVectorImpl<clang::QualType> &proto, long *poffset,
2444  EFunctionMatchMode mode/*=kConversionMatch*/)
2445 {
2446  SetFuncProto(info, method, proto, false, poffset, mode);
2447 }
2448 
2449 void TClingCallFunc::SetFuncProto(const TClingClassInfo *info, const char *method,
2450  const llvm::SmallVectorImpl<clang::QualType> &proto,
2451  bool objectIsConst, long *poffset,
2452  EFunctionMatchMode mode/*=kConversionMatch*/)
2453 {
2454  Init(std::unique_ptr<TClingMethodInfo>(new TClingMethodInfo(fInterp)));
2455  if (poffset) {
2456  *poffset = 0L;
2457  }
2458  ResetArg();
2459  if (!info->IsValid()) {
2460  ::Error("TClingCallFunc::SetFuncProto", "Class info is invalid!");
2461  return;
2462  }
2463  *fMethod = info->GetMethod(method, proto, objectIsConst, poffset, mode);
2464  if (!fMethod->IsValid()) {
2465  //::Error("TClingCallFunc::SetFuncProto", "Could not find method %s(%s)",
2466  // method, proto);
2467  return;
2468  }
2469 }
2470 
c
#define c(i)
Definition: RSha256.hxx:101
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:1875
TClingCallFunc::execWithULL
void execWithULL(void *address, cling::Value *val)
Definition: TClingCallFunc.cxx:1854
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:1993
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:1103
TClingCallFunc::execWithLL
void execWithLL(void *address, cling::Value *val)
Definition: TClingCallFunc.cxx:1846
TClingCallFunc::IsValid
bool IsValid() const
Definition: TClingCallFunc.cxx:2278
TClingCallFunc::exec_with_valref_return
void exec_with_valref_return(void *address, cling::Value *ret)
Definition: TClingCallFunc.cxx:2049
TClingCallFunc::ExecWithRetFunc_t
std::function< void(void *address, cling::Value &ret)> ExecWithRetFunc_t
Definition: TClingCallFunc.h:89
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:2205
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:2167
TClingCallFunc::make_dtor_wrapper
tcling_callfunc_dtor_Wrapper_t make_dtor_wrapper(const TClingClassInfo *info)
Definition: TClingCallFunc.cxx:1339
TClingCallFunc::SetArg
void SetArg(long arg)
Definition: TClingCallFunc.cxx:2322
TGeant4Unit::s
static constexpr double s
Definition: TGeant4SystemOfUnits.h:162
TClingCallFunc::ExecDouble
double ExecDouble(void *address)
Definition: TClingCallFunc.cxx:2139
N
#define N
TClingCallFunc::SetFunc
void SetFunc(const TClingClassInfo *info, const char *method, const char *arglist, long *poffset)
Definition: TClingCallFunc.cxx:2371
indent
static void indent(ostringstream &buf, int indent_level)
Definition: TClingCallFunc.cxx:87
RooFitShortHand::S
RooArgSet S(const RooAbsArg &v1)
Definition: RooGlobalFunc.cxx:354
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
This class defines an interface to the cling C++ interpreter.
Definition: TCling.h:102
R__LOCKGUARD_CLING
#define R__LOCKGUARD_CLING(mutex)
Definition: TInterpreter.h:51
tcling_callfunc_Wrapper_t
void(* tcling_callfunc_Wrapper_t)(void *, int, void **, void *)
Definition: TClingCallFunc.h:56
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
b
#define b(i)
Definition: RSha256.hxx:100
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:1128
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:117
TClingClassInfo.h
sqlio::Double
const char * Double
Definition: TSQLStructure.cxx:76
TInterpreter::CallFuncIFacePtr_t
Definition: TInterpreter.h:86
sqlio::Int
const char * Int
Definition: TSQLStructure.cxx:72
TClingCallFunc::FactoryMethod
TClingMethodInfo * FactoryMethod() const
Definition: TClingCallFunc.cxx:2233
kIndentString
static const string kIndentString(" ")
TClingMethodInfo
Emulation of the CINT MethodInfo class.
Definition: TClingMethodInfo.h:124
TClingCallFunc::EReferenceType
EReferenceType
Definition: TClingCallFunc.h:83
TClingCallFunc::SetArgs
void SetArgs(const char *args)
Definition: TClingCallFunc.cxx:2365
sqlio::UShort
const char * UShort
Definition: TSQLStructure.cxx:78
gInterpreterMutex
R__EXTERN TVirtualMutex * gInterpreterMutex
Definition: TInterpreter.h:44
TGeant4Unit::us
static constexpr double us
Definition: TGeant4SystemOfUnits.h:164
xmlio::Value
const char * Value
Definition: TXMLSetup.cxx:73
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:57
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:591
ROOT::R::function
void function(const Char_t *name_, T fun, const Char_t *docstring=0)
Definition: RExports.h:151
Long_t
long Long_t
Definition: RtypesCore.h:54
TClingClassInfo
Emulation of the CINT ClassInfo class.
Definition: TClingClassInfo.h:58
TClingCallFunc.h
gDebug
Int_t gDebug
Definition: TROOT.cxx:590
TClingCallFunc::EvaluateArgList
void EvaluateArgList(const std::string &ArgList)
Definition: TClingCallFunc.cxx:2068
tcling_callfunc_dtor_Wrapper_t
void(* tcling_callfunc_dtor_Wrapper_t)(void *, unsigned long, int)
Definition: TClingCallFunc.h:58
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:975
TClingCallFunc::ExecWithReturn
void ExecWithReturn(void *address, void *ret=nullptr)
Definition: TClingCallFunc.cxx:2156
TClingCallFunc::InterfaceMethod
void * InterfaceMethod()
Definition: TClingCallFunc.cxx:2259
TClingCallFunc::Exec
void Exec(void *address, TInterpreterValue *interpVal=0)
Definition: TClingCallFunc.cxx:2092
void
typedef void((*Func_t)())
TClingCallFunc::ExecT
T ExecT(void *address)
Definition: TClingCallFunc.cxx:2109
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:160
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:2238
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:2414
Pattern
Definition: Pattern.h:8
TClingCallFunc::SetArgArray
void SetArgArray(long *argArr, int narg)
Definition: TClingCallFunc.cxx:2357
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:561
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:34
TClingUtils.h
TClingCallFunc::GetDeclContext
const clang::DeclContext * GetDeclContext() const
Definition: TClingCallFunc.cxx:587
TClingCallFunc::InitRetAndExec
ExecWithRetFunc_t InitRetAndExec(const clang::FunctionDecl *FD, cling::Value &ret)
Definition: TClingCallFunc.cxx:2034
TClingCallFunc::exec
void exec(void *address, void *ret)
Definition: TClingCallFunc.cxx:1531
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:2144
gWrapperStore
static map< const Decl *, void * > gWrapperStore
Definition: TClingCallFunc.cxx:80
TClingDeclInfo::GetDecl
virtual const clang::Decl * GetDecl() const
Definition: TClingDeclInfo.h:37
TGeant4Unit::nm
static constexpr double nm
Definition: TGeant4SystemOfUnits.h:105
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:2134
TClingCallFunc::InitRetAndExecIntegral
ExecWithRetFunc_t InitRetAndExecIntegral(clang::QualType QT, cling::Value &ret)
TClingCallFunc::ExecInt
long ExecInt(void *address)
Definition: TClingCallFunc.cxx:2129
ROOT
VSD Structures.
Definition: StringConv.hxx:21
TMath::E
constexpr Double_t E()
Base of natural log:
Definition: TMath.h:96
int
TClingCallFunc::IFacePtr
TInterpreter::CallFuncIFacePtr_t IFacePtr()
Definition: TClingCallFunc.cxx:2286
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:2310