ROOT  6.06/09
Reference Guide
TCling.cxx
Go to the documentation of this file.
1 // @(#)root/meta:$Id$
2 // vim: sw=3 ts=3 expandtab foldmethod=indent
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2012, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 /** \class TCling
13 
14 This class defines an interface to the cling C++ interpreter.
15 
16 Cling is a full ANSI compliant C++-11 interpreter based on
17 clang/LLVM technology.
18 */
19 
20 #include "TCling.h"
21 
22 #include "TClingBaseClassInfo.h"
23 #include "TClingCallFunc.h"
24 #include "TClingClassInfo.h"
25 #include "TClingDataMemberInfo.h"
26 #include "TClingMethodArgInfo.h"
27 #include "TClingMethodInfo.h"
28 #include "TClingTypedefInfo.h"
29 #include "TClingTypeInfo.h"
30 #include "TClingValue.h"
31 
32 #include "TROOT.h"
33 #include "TApplication.h"
34 #include "TGlobal.h"
35 #include "TDataType.h"
36 #include "TClass.h"
37 #include "TClassEdit.h"
38 #include "TClassTable.h"
39 #include "TClingCallbacks.h"
40 #include "TBaseClass.h"
41 #include "TDataMember.h"
42 #include "TMemberInspector.h"
43 #include "TMethod.h"
44 #include "TMethodArg.h"
45 #include "TFunctionTemplate.h"
46 #include "TObjArray.h"
47 #include "TObjString.h"
48 #include "TString.h"
49 #include "THashList.h"
50 #include "TOrdCollection.h"
51 #include "TVirtualPad.h"
52 #include "TSystem.h"
53 #include "TVirtualMutex.h"
54 #include "TError.h"
55 #include "TEnv.h"
56 #include "TEnum.h"
57 #include "TEnumConstant.h"
58 #include "THashTable.h"
59 #include "RConfigure.h"
60 #include "compiledata.h"
61 #include "TMetaUtils.h"
63 #include "TVirtualStreamerInfo.h"
64 #include "TListOfDataMembers.h"
65 #include "TListOfEnums.h"
66 #include "TListOfEnumsWithLock.h"
67 #include "TListOfFunctions.h"
69 #include "TProtoClass.h"
70 #include "TStreamerInfo.h" // This is here to avoid to use the plugin manager
71 #include "ThreadLocalStorage.h"
72 #include "TFile.h"
73 #include "TKey.h"
74 
75 #include "clang/AST/ASTContext.h"
76 #include "clang/AST/Decl.h"
77 #include "clang/AST/DeclarationName.h"
78 #include "clang/AST/GlobalDecl.h"
79 #include "clang/AST/RecordLayout.h"
80 #include "clang/AST/RecursiveASTVisitor.h"
81 #include "clang/AST/Type.h"
82 #include "clang/Basic/SourceLocation.h"
83 #include "clang/Basic/Specifiers.h"
84 #include "clang/Basic/TargetInfo.h"
85 #include "clang/CodeGen/ModuleBuilder.h"
86 #include "clang/Frontend/CompilerInstance.h"
87 #include "clang/Frontend/FrontendDiagnostic.h"
88 #include "clang/Lex/HeaderSearch.h"
89 #include "clang/Lex/Preprocessor.h"
90 #include "clang/Sema/Lookup.h"
91 #include "clang/Sema/Sema.h"
92 #include "clang/Parse/Parser.h"
93 
94 #include "cling/Interpreter/ClangInternalState.h"
95 #include "cling/Interpreter/DynamicLibraryManager.h"
96 #include "cling/Interpreter/Interpreter.h"
97 #include "cling/Interpreter/LookupHelper.h"
98 #include "cling/Interpreter/Value.h"
99 #include "cling/Interpreter/Transaction.h"
100 #include "cling/MetaProcessor/MetaProcessor.h"
101 #include "cling/Utils/AST.h"
102 
103 #include "llvm/IR/GlobalValue.h"
104 #include "llvm/IR/Module.h"
105 
106 #include "llvm/Support/DynamicLibrary.h"
107 #include "llvm/Support/raw_ostream.h"
108 #include "llvm/Support/Path.h"
109 
110 #include <algorithm>
111 #include <iostream>
112 #include <cassert>
113 #include <map>
114 #include <set>
115 #include <stdexcept>
116 #include <stdint.h>
117 #include <fstream>
118 #include <sstream>
119 #include <string>
120 #include <typeinfo>
121 #include <unordered_map>
122 #include <utility>
123 #include <vector>
124 
125 #ifndef R__WIN32
126 #include <cxxabi.h>
127 #define R__DLLEXPORT
128 #endif
129 #include <limits.h>
130 #include <stdio.h>
131 
132 #ifdef __APPLE__
133 #include <dlfcn.h>
134 #include <mach-o/dyld.h>
135 #endif // __APPLE__
136 
137 #ifdef R__UNIX
138 #include <dlfcn.h>
139 #endif
140 
141 #if defined(__CYGWIN__)
142 #include <sys/cygwin.h>
143 #define HMODULE void *
144 extern "C" {
145  __declspec(dllimport) void * __stdcall GetCurrentProcess();
146  __declspec(dllimport) bool __stdcall EnumProcessModules(void *, void **, unsigned long, unsigned long *);
147  __declspec(dllimport) unsigned long __stdcall GetModuleFileNameExW(void *, void *, wchar_t *, unsigned long);
148 }
149 #endif
150 
151 // Fragment copied from LLVM's raw_ostream.cpp
152 #if defined(_MSC_VER)
153 #ifndef STDIN_FILENO
154 # define STDIN_FILENO 0
155 #endif
156 #ifndef STDOUT_FILENO
157 # define STDOUT_FILENO 1
158 #endif
159 #ifndef STDERR_FILENO
160 # define STDERR_FILENO 2
161 #endif
162 #ifndef R__WIN32
163 //#if defined(HAVE_UNISTD_H)
164 # include <unistd.h>
165 //#endif
166 #else
167 #include "Windows4Root.h"
168 #include <Psapi.h>
169 #undef GetModuleFileName
170 #define RTLD_DEFAULT ((void *)::GetModuleHandle(NULL))
171 #define dlsym(library, function_name) ::GetProcAddress((HMODULE)library, function_name)
172 #define dlopen(library_name, flags) ::LoadLibrary(library_name)
173 #define dlclose(library) ::FreeLibrary((HMODULE)library)
174 #define R__DLLEXPORT __declspec(dllexport)
175 #endif
176 #endif
177 
178 //______________________________________________________________________________
179 // Infrastructure to detect and react to libCling being teared down.
180 //
181 namespace {
182  class TCling_UnloadMarker {
183  public:
184  ~TCling_UnloadMarker() {
187  }
188  }
189  };
190  static TCling_UnloadMarker gTClingUnloadMarker;
191 }
192 
193 
194 
195 //______________________________________________________________________________
196 // These functions are helpers for debugging issues with non-LLVMDEV builds.
197 //
198 clang::DeclContext* TCling__DEBUG__getDeclContext(clang::Decl* D) {
199  return D->getDeclContext();
200 }
201 clang::NamespaceDecl* TCling__DEBUG__DCtoNamespace(clang::DeclContext* DC) {
202  return llvm::dyn_cast<clang::NamespaceDecl>(DC);
203 }
204 clang::RecordDecl* TCling__DEBUG__DCtoRecordDecl(clang::DeclContext* DC) {
205  return llvm::dyn_cast<clang::RecordDecl>(DC);
206 }
207 void TCling__DEBUG__dump(clang::DeclContext* DC) {
208  return DC->dumpDeclContext();
209 }
210 void TCling__DEBUG__dump(clang::Decl* D) {
211  return D->dump();
212 }
213 void TCling__DEBUG__dump(clang::FunctionDecl* FD) {
214  return FD->dump();
215 }
217  return ((clang::Decl*)D)->dump();
218 }
219 void TCling__DEBUG__printName(clang::Decl* D) {
220  if (clang::NamedDecl* ND = llvm::dyn_cast<clang::NamedDecl>(D)) {
221  std::string name;
222  {
223  llvm::raw_string_ostream OS(name);
224  ND->getNameForDiagnostic(OS, D->getASTContext().getPrintingPolicy(),
225  true /*Qualified*/);
226  }
227  printf("%s\n", name.c_str());
228  }
229 }
230 //______________________________________________________________________________
231 // These functions are helpers for testing issues directly rather than
232 // relying on side effects.
233 // This is used for the test for ROOT-7462/ROOT-6070
234 bool TCling__TEST_isInvalidDecl(clang::Decl* D) {
235  return D->isInvalidDecl();
236 }
237 bool TCling__TEST_isInvalidDecl(ClassInfo_t *input) {
238  TClingClassInfo *info( (TClingClassInfo*) input);
239  assert(info && info->IsValid());
240  return info->GetDecl()->isInvalidDecl();
241 }
242 
243 using namespace std;
244 using namespace clang;
245 using namespace ROOT;
246 
247 namespace {
248  static const std::string gInterpreterClassDef = R"ICF(
249 #undef ClassDef
250 #define ClassDef(name, id) \
251 _ClassDefInterp_(name,id,virtual,) \
252 static int DeclFileLine() { return __LINE__; }
253 #undef ClassDefNV
254 #define ClassDefNV(name, id) \
255 _ClassDefInterp_(name,id,,) \
256 static int DeclFileLine() { return __LINE__; }
257 #undef ClassDefOverride
258 #define ClassDefOverride(name, id) \
259 _ClassDefInterp_(name,id,,override) \
260 static int DeclFileLine() { return __LINE__; }
261 )ICF";
262 
263  static const std::string gNonInterpreterClassDef = R"ICF(
264 #define __ROOTCLING__ 1
265 #undef ClassDef
266 #define ClassDef(name,id) \
267 _ClassDef_(name,id,virtual,) \
268 static int DeclFileLine() { return __LINE__; }
269 #undef ClassDefNV
270 #define ClassDefNV(name, id)\
271 _ClassDef_(name,id,,)\
272 static int DeclFileLine() { return __LINE__; }
273 #undef ClassDefOverride
274 #define ClassDefOverride(name, id)\
275 _ClassDef_(name,id,,override)\
276 static int DeclFileLine() { return __LINE__; }
277 )ICF";
278 
279 // The macros below use ::Error, so let's ensure it is included
280  static const std::string gClassDefInterpMacro = R"ICF(
281 #ifndef ROOT_TError
282 #include "TError.h"
283 #endif
284 
285 #define _ClassDefInterp_(name,id,virtual_keyword, overrd) \
286 private: \
287 public: \
288  static TClass *Class() { static TClass* sIsA = 0; if (!sIsA) sIsA = TClass::GetClass(#name); return sIsA; } \
289  static const char *Class_Name() { return #name; } \
290  static Version_t Class_Version() { return id; } \
291  static TClass *Dictionary() { return 0; } \
292  virtual_keyword TClass *IsA() const overrd { return name::Class(); } \
293  virtual_keyword void ShowMembers(TMemberInspector&insp) const overrd { ::ROOT::Class_ShowMembers(name::Class(), this, insp); } \
294  virtual_keyword void Streamer(TBuffer&) overrd { ::Error("Streamer", "Cannot stream interpreted class."); } \
295  void StreamerNVirtual(TBuffer&ClassDef_StreamerNVirtual_b) { name::Streamer(ClassDef_StreamerNVirtual_b); } \
296  static const char *DeclFileName() { return __FILE__; } \
297  static int ImplFileLine() { return 0; } \
298  static const char *ImplFileName() { return __FILE__; }
299 )ICF";
300 }
302 
303 // The functions are used to bridge cling/clang/llvm compiled with no-rtti and
304 // ROOT (which uses rtti)
305 
306 //______________________________________________________________________________
307 
308 // Class extracting recursively every Enum type defined for a class.
309 class EnumVisitor : public RecursiveASTVisitor<EnumVisitor> {
310 private:
311  llvm::SmallVector<EnumDecl*,128> &fClassEnums;
312 public:
313  EnumVisitor(llvm::SmallVector<EnumDecl*,128> &enums) : fClassEnums(enums)
314  {}
315 
316  bool TraverseStmt(Stmt*) {
317  // Don't descend into function bodies.
318  return true;
319  }
320 
321  bool shouldVisitTemplateInstantiations() const { return true; }
322 
323  bool TraverseClassTemplateDecl(ClassTemplateDecl*) {
324  // Don't descend into templates (but only instances thereof).
325  return true; // returning false will abort the in-depth traversal.
326  }
327 
328  bool TraverseClassTemplatePartialSpecializationDecl(ClassTemplatePartialSpecializationDecl*) {
329  // Don't descend into templates partial specialization (but only instances thereof).
330  return true; // returning false will abort the in-depth traversal.
331  }
332 
333  bool VisitEnumDecl(EnumDecl *TEnumD) {
334  if (!TEnumD->getDeclContext()->isDependentContext())
335  fClassEnums.push_back(TEnumD);
336  return true; // returning false will abort the in-depth traversal.
337  }
338 };
339 
340 ////////////////////////////////////////////////////////////////////////////////
341 /// Update TClingClassInfo for a class (e.g. upon seeing a definition).
342 
343 static void TCling__UpdateClassInfo(const NamedDecl* TD)
344 {
345  static Bool_t entered = kFALSE;
346  static vector<const NamedDecl*> updateList;
347  Bool_t topLevel;
348 
349  if (entered) topLevel = kFALSE;
350  else {
351  entered = kTRUE;
352  topLevel = kTRUE;
353  }
354  if (topLevel) {
355  ((TCling*)gInterpreter)->UpdateClassInfoWithDecl(TD);
356  } else {
357  // If we are called indirectly from within another call to
358  // TCling::UpdateClassInfo, we delay the update until the dictionary loading
359  // is finished (i.e. when we return to the top level TCling::UpdateClassInfo).
360  // This allows for the dictionary to be fully populated when we actually
361  // update the TClass object. The updating of the TClass sometimes
362  // (STL containers and when there is an emulated class) forces the building
363  // of the TClass object's real data (which needs the dictionary info).
364  updateList.push_back(TD);
365  }
366  if (topLevel) {
367  while (!updateList.empty()) {
368  ((TCling*)gInterpreter)->UpdateClassInfoWithDecl(updateList.back());
369  updateList.pop_back();
370  }
371  entered = kFALSE;
372  }
373 }
374 
375 void TCling::UpdateEnumConstants(TEnum* enumObj, TClass* cl) const {
376  const clang::Decl* D = static_cast<const clang::Decl*>(enumObj->GetDeclId());
377  if(const clang::EnumDecl* ED = dyn_cast<clang::EnumDecl>(D)) {
378  // Add the constants to the enum type.
379  for (EnumDecl::enumerator_iterator EDI = ED->enumerator_begin(),
380  EDE = ED->enumerator_end(); EDI != EDE; ++EDI) {
381  // Get name of the enum type.
382  std::string constbuf;
383  if (const NamedDecl* END = llvm::dyn_cast<NamedDecl>(*EDI)) {
384  PrintingPolicy Policy((*EDI)->getASTContext().getPrintingPolicy());
385  llvm::raw_string_ostream stream(constbuf);
386  (END)->getNameForDiagnostic(stream, Policy, /*Qualified=*/false);
387  }
388  const char* constantName = constbuf.c_str();
389 
390  // Get value of the constant.
391  Long64_t value;
392  const llvm::APSInt valAPSInt = (*EDI)->getInitVal();
393  if (valAPSInt.isSigned()) {
394  value = valAPSInt.getSExtValue();
395  } else {
396  value = valAPSInt.getZExtValue();
397  }
398 
399  // Create the TEnumConstant or update it if existing
400  TEnumConstant* enumConstant = nullptr;
401  TClingClassInfo* tcCInfo = (TClingClassInfo*)(cl ? cl->GetClassInfo() : 0);
402  TClingDataMemberInfo* tcDmInfo = new TClingDataMemberInfo(fInterpreter, *EDI, tcCInfo);
403  DataMemberInfo_t* dmInfo = (DataMemberInfo_t*) tcDmInfo;
404  if (TObject* encAsTObj = enumObj->GetConstants()->FindObject(constantName)){
405  ((TEnumConstant*)encAsTObj)->Update(dmInfo);
406  } else {
407  enumConstant = new TEnumConstant(dmInfo, constantName, value, enumObj);
408  }
409 
410  // Add the global constants to the list of Globals.
411  if (!cl) {
412  TCollection* globals = gROOT->GetListOfGlobals(false);
413  if (!globals->FindObject(constantName)) {
414  globals->Add(enumConstant);
415  }
416  }
417  }
418  }
419 }
420 
421 TEnum* TCling::CreateEnum(void *VD, TClass *cl) const
422 {
423  // Handle new enum declaration for either global and nested enums.
424 
425  // Create the enum type.
426  TEnum* enumType = 0;
427  const clang::Decl* D = static_cast<const clang::Decl*>(VD);
428  std::string buf;
429  if (const EnumDecl* ED = llvm::dyn_cast<EnumDecl>(D)) {
430  // Get name of the enum type.
431  PrintingPolicy Policy(ED->getASTContext().getPrintingPolicy());
432  llvm::raw_string_ostream stream(buf);
433  ED->getNameForDiagnostic(stream, Policy, /*Qualified=*/false);
434  // If the enum is unnamed we do not add it to the list of enums i.e unusable.
435  }
436  if (buf.empty()) {
437  return 0;
438  }
439  const char* name = buf.c_str();
440  if (cl) {
441  enumType = new TEnum(name, VD, cl);
442  } else {
443  enumType = new TEnum(name, VD, cl);
444  }
445  UpdateEnumConstants(enumType, cl);
446 
447  return enumType;
448 }
449 
450 void TCling::HandleNewDecl(const void* DV, bool isDeserialized, std::set<TClass*> &modifiedTClasses) {
451  // Handle new declaration.
452  // Record the modified class, struct and namespaces in 'modifiedTClasses'.
453 
454  const clang::Decl* D = static_cast<const clang::Decl*>(DV);
455 
456  if (!D->isCanonicalDecl() && !isa<clang::NamespaceDecl>(D)
457  && !dyn_cast<clang::RecordDecl>(D)) return;
458 
459  if (isa<clang::FunctionDecl>(D->getDeclContext())
460  || isa<clang::TagDecl>(D->getDeclContext()))
461  return;
462 
463  // Don't list templates.
464  if (const clang::CXXRecordDecl* RD = dyn_cast<clang::CXXRecordDecl>(D)) {
465  if (RD->getDescribedClassTemplate())
466  return;
467  } else if (const clang::FunctionDecl* FD = dyn_cast<clang::FunctionDecl>(D)) {
468  if (FD->getDescribedFunctionTemplate())
469  return;
470  }
471 
472  if (const RecordDecl *TD = dyn_cast<RecordDecl>(D)) {
473  if (TD->isCanonicalDecl() || TD->isThisDeclarationADefinition())
475  }
476  else if (const NamedDecl *ND = dyn_cast<NamedDecl>(D)) {
477 
478  if (const TagDecl *TD = dyn_cast<TagDecl>(D)) {
479  // Mostly just for EnumDecl (the other TagDecl are handled
480  // by the 'RecordDecl' if statement.
482  } else if (const NamespaceDecl* NSD = dyn_cast<NamespaceDecl>(D)) {
484  }
485 
486  // While classes are read completely (except for function template instances,
487  // enum, data (and functions) can be added to namespaces at any time.
488  // [this section can be removed when both the list of data member and the list
489  // of enums has been update to be active list]
490  if (const NamespaceDecl* NCtx = dyn_cast<NamespaceDecl>(ND->getDeclContext())) {
491  if (NCtx->getIdentifier()) {
492  // No need to load the TClass: if there is something to update then
493  // it must already exist.
494  std::string NCtxName;
495  PrintingPolicy Policy(NCtx->getASTContext().getPrintingPolicy());
496  llvm::raw_string_ostream stream(NCtxName);
497  NCtx->getNameForDiagnostic(stream, Policy, /*Qualified=*/true);
498 
499  TClass* cl = (TClass*)gROOT->GetListOfClasses()->FindObject(NCtxName.c_str());
500  if (cl) {
501  modifiedTClasses.insert(cl);
502  }
503  }
504  return;
505  }
506 
507  // We care about declarations on the global scope.
508  if (!isa<TranslationUnitDecl>(ND->getDeclContext()))
509  return;
510 
511  // Enums are lazyly created, thus we don not need to handle them here.
512  if (isa<EnumDecl>(ND))
513  return;
514 
515  // ROOT says that global is enum(lazylycreated)/var/field declared on the global
516  // scope.
517  if (!(isa<VarDecl>(ND)))
518  return;
519 
520  // Skip if already in the list.
521  if (gROOT->GetListOfGlobals()->FindObject(ND->getNameAsString().c_str()))
522  return;
523 
524  // Put the global constants and global enums in the corresponding lists.
525  gROOT->GetListOfGlobals()->Add(new TGlobal((DataMemberInfo_t *)
526  new TClingDataMemberInfo(fInterpreter,
527  cast<ValueDecl>(ND), 0)));
528  }
529 }
530 
531 extern "C"
533 {
534  // We are sure in this context of the type of the interpreter
535  normCtxt = &( (TCling*) gInterpreter)->GetNormalizedContext();
536 }
537 
538 extern "C"
539 void TCling__UpdateListsOnCommitted(const cling::Transaction &T, cling::Interpreter*) {
540 
541  ((TCling*)gCling)->UpdateListsOnCommitted(T);
542 }
543 
544 extern "C"
545 void TCling__UpdateListsOnUnloaded(const cling::Transaction &T) {
546 
547  ((TCling*)gCling)->UpdateListsOnUnloaded(T);
548 }
549 void TCling__TransactionRollback(const cling::Transaction &T) {
550 
551  ((TCling*)gCling)->TransactionRollback(T);
552 }
553 extern "C" void TCling__LibraryLoadedRTTI(const void* dyLibHandle,
554  const char* canonicalName) {
555 
556  ((TCling*)gCling)->LibraryLoaded(dyLibHandle, canonicalName);
557 }
558 
559 extern "C" void TCling__LibraryUnloadedRTTI(const void* dyLibHandle,
560  const char* canonicalName) {
561 
562  ((TCling*)gCling)->LibraryUnloaded(dyLibHandle, canonicalName);
563 }
564 
565 
566 extern "C"
567 TObject* TCling__GetObjectAddress(const char *Name, void *&LookupCtx) {
568  return ((TCling*)gCling)->GetObjectAddress(Name, LookupCtx);
569 }
570 
571 extern "C" const Decl* TCling__GetObjectDecl(TObject *obj) {
572  return ((TClingClassInfo*)obj->IsA()->GetClassInfo())->GetDecl();
573 }
574 
575 extern "C" R__DLLEXPORT TInterpreter *CreateInterpreter(void* interpLibHandle)
576 {
577  cling::DynamicLibraryManager::ExposeHiddenSharedLibrarySymbols(interpLibHandle);
578  return new TCling("C++", "cling C++ Interpreter");
579 }
580 
582 {
583  delete interp;
584 }
585 
586 // Load library containing specified class. Returns 0 in case of error
587 // and 1 in case if success.
588 extern "C" int TCling__AutoLoadCallback(const char* className)
589 {
590  return ((TCling*)gCling)->AutoLoad(className);
591 }
592 
593 extern "C" int TCling__AutoParseCallback(const char* className)
594 {
595  return ((TCling*)gCling)->AutoParse(className);
596 }
597 
598 extern "C" const char* TCling__GetClassSharedLibs(const char* className)
599 {
600  return ((TCling*)gCling)->GetClassSharedLibs(className);
601 }
602 
603 // // Returns 0 for failure 1 for success
604 // extern "C" int TCling__IsAutoLoadNamespaceCandidate(const char* name)
605 // {
606 // return ((TCling*)gCling)->IsAutoLoadNamespaceCandidate(name);
607 // }
608 
609 // Returns 0 for failure 1 for success
610 extern "C" int TCling__IsAutoLoadNamespaceCandidate(const clang::NamespaceDecl* nsDecl)
611 {
612  return ((TCling*)gCling)->IsAutoLoadNamespaceCandidate(nsDecl);
613 }
614 
615 extern "C" int TCling__CompileMacro(const char *fileName, const char *options)
616 {
617  string file(fileName);
618  string opt(options);
619  return gSystem->CompileMacro(file.c_str(), opt.c_str());
620 }
621 
622 extern "C" void TCling__SplitAclicMode(const char* fileName, string &mode,
623  string &args, string &io, string &fname)
624 {
625  string file(fileName);
626  TString f, amode, arguments, aclicio;
627  f = gSystem->SplitAclicMode(file.c_str(), amode, arguments, aclicio);
628  mode = amode.Data(); args = arguments.Data();
629  io = aclicio.Data(); fname = f.Data();
630 }
631 
632 //______________________________________________________________________________
633 //
634 //
635 //
636 
637 #ifdef R__WIN32
638 extern "C" {
639  char *__unDName(char *demangled, const char *mangled, int out_len,
640  void * (* pAlloc )(size_t), void (* pFree )(void *),
641  unsigned short int flags);
642 }
643 #endif
644 
645 ////////////////////////////////////////////////////////////////////////////////
646 /// Find a template decl within N nested namespaces, 0<=N<inf
647 /// Assumes 1 and only 1 template present and 1 and only 1 entity contained
648 /// by the namespace. Example: ns1::ns2::..::nsN::myTemplate
649 /// Returns nullptr in case of error
650 
651 static clang::ClassTemplateDecl* FindTemplateInNamespace(clang::Decl* decl)
652 {
653  using namespace clang;
654  if (NamespaceDecl* nsd = llvm::dyn_cast<NamespaceDecl>(decl)){
655  return FindTemplateInNamespace(*nsd->decls_begin());
656  }
657 
658  if (ClassTemplateDecl* ctd = llvm::dyn_cast<ClassTemplateDecl>(decl)){
659  return ctd;
660  }
661 
662  return nullptr; // something went wrong.
663 }
664 
665 ////////////////////////////////////////////////////////////////////////////////
666 /// Autoload a library provided the mangled name of a missing symbol.
667 
668 void* llvmLazyFunctionCreator(const std::string& mangled_name)
669 {
670  return ((TCling*)gCling)->LazyFunctionCreatorAutoload(mangled_name);
671 }
672 
673 //______________________________________________________________________________
674 //
675 //
676 //
677 
678 int TCling_GenerateDictionary(const std::vector<std::string> &classes,
679  const std::vector<std::string> &headers,
680  const std::vector<std::string> &fwdDecls,
681  const std::vector<std::string> &unknown)
682 {
683  //This function automatically creates the "LinkDef.h" file for templated
684  //classes then executes CompileMacro on it.
685  //The name of the file depends on the class name, and it's not generated again
686  //if the file exist.
687  if (classes.empty()) {
688  return 0;
689  }
690  // Use the name of the first class as the main name.
691  const std::string& className = classes[0];
692  //(0) prepare file name
693  TString fileName = "AutoDict_";
694  std::string::const_iterator sIt;
695  for (sIt = className.begin(); sIt != className.end(); sIt++) {
696  if (*sIt == '<' || *sIt == '>' ||
697  *sIt == ' ' || *sIt == '*' ||
698  *sIt == ',' || *sIt == '&' ||
699  *sIt == ':') {
700  fileName += '_';
701  }
702  else {
703  fileName += *sIt;
704  }
705  }
706  if (classes.size() > 1) {
707  Int_t chk = 0;
708  std::vector<std::string>::const_iterator it = classes.begin();
709  while ((++it) != classes.end()) {
710  for (UInt_t cursor = 0; cursor != it->length(); ++cursor) {
711  chk = chk * 3 + it->at(cursor);
712  }
713  }
714  fileName += TString::Format("_%u", chk);
715  }
716  fileName += ".cxx";
717  if (gSystem->AccessPathName(fileName) != 0) {
718  //file does not exist
719  //(1) prepare file data
720  // If STL, also request iterators' operators.
721  // vector is special: we need to check whether
722  // vector::iterator is a typedef to pointer or a
723  // class.
724  static const std::set<std::string> sSTLTypes {"vector","list","unordered_list","deque","map","multimap","set","unordered_set","multiset","queue","priority_queue","stack","iterator"};
725  std::vector<std::string>::const_iterator it;
726  std::string fileContent("");
727  for (it = headers.begin(); it != headers.end(); ++it) {
728  fileContent += "#include \"" + *it + "\"\n";
729  }
730  for (it = unknown.begin(); it != unknown.end(); ++it) {
731  TClass* cl = TClass::GetClass(it->c_str());
732  if (cl && cl->GetDeclFileName()) {
733  TString header(gSystem->BaseName(cl->GetDeclFileName()));
734  TString dir(gSystem->DirName(cl->GetDeclFileName()));
735  TString dirbase(gSystem->BaseName(dir));
736  while (dirbase.Length() && dirbase != "."
737  && dirbase != "include" && dirbase != "inc"
738  && dirbase != "prec_stl") {
739  gSystem->PrependPathName(dirbase, header);
740  dir = gSystem->DirName(dir);
741  }
742  fileContent += TString("#include \"") + header + "\"\n";
743  }
744  }
745  for (it = fwdDecls.begin(); it != fwdDecls.end(); ++it) {
746  fileContent += "class " + *it + ";\n";
747  }
748  fileContent += "#ifdef __CINT__ \n";
749  fileContent += "#pragma link C++ nestedclasses;\n";
750  fileContent += "#pragma link C++ nestedtypedefs;\n";
751  for (it = classes.begin(); it != classes.end(); ++it) {
752  std::string n(*it);
753  size_t posTemplate = n.find('<');
754  std::set<std::string>::const_iterator iSTLType = sSTLTypes.end();
755  if (posTemplate != std::string::npos) {
756  n.erase(posTemplate, std::string::npos);
757  if (n.compare(0, 5, "std::") == 0) {
758  n.erase(0, 5);
759  }
760  iSTLType = sSTLTypes.find(n);
761  }
762  fileContent += "#pragma link C++ class ";
763  fileContent += *it + "+;\n" ;
764  fileContent += "#pragma link C++ class ";
765  if (iSTLType != sSTLTypes.end()) {
766  // STL class; we cannot (and don't need to) store iterators;
767  // their shadow and the compiler's version don't agree. So
768  // don't ask for the '+'
769  fileContent += *it + "::*;\n" ;
770  }
771  else {
772  // Not an STL class; we need to allow the I/O of contained
773  // classes (now that we have a dictionary for them).
774  fileContent += *it + "::*+;\n" ;
775  }
776  std::string oprLink("#pragma link C++ operators ");
777  oprLink += *it;
778  // Don't! Requests e.g. op<(const vector<T>&, const vector<T>&):
779  // fileContent += oprLink + ";\n";
780  if (iSTLType != sSTLTypes.end()) {
781  if (n == "vector") {
782  fileContent += "#ifdef G__VECTOR_HAS_CLASS_ITERATOR\n";
783  }
784  fileContent += oprLink + "::iterator;\n";
785  fileContent += oprLink + "::const_iterator;\n";
786  fileContent += oprLink + "::reverse_iterator;\n";
787  if (n == "vector") {
788  fileContent += "#endif\n";
789  }
790  }
791  }
792  fileContent += "#endif\n";
793  //end(1)
794  //(2) prepare the file
795  FILE* filePointer;
796  filePointer = fopen(fileName, "w");
797  if (filePointer == NULL) {
798  //can't open a file
799  return 1;
800  }
801  //end(2)
802  //write data into the file
803  fprintf(filePointer, "%s", fileContent.c_str());
804  fclose(filePointer);
805  }
806  //(3) checking if we can compile a macro, if not then cleaning
807  Int_t oldErrorIgnoreLevel = gErrorIgnoreLevel;
808  gErrorIgnoreLevel = kWarning; // no "Info: creating library..."
809  Int_t ret = gSystem->CompileMacro(fileName, "k");
810  gErrorIgnoreLevel = oldErrorIgnoreLevel;
811  if (ret == 0) { //can't compile a macro
812  return 2;
813  }
814  //end(3)
815  return 0;
816 }
817 
818 int TCling_GenerateDictionary(const std::string& className,
819  const std::vector<std::string> &headers,
820  const std::vector<std::string> &fwdDecls,
821  const std::vector<std::string> &unknown)
822 {
823  //This function automatically creates the "LinkDef.h" file for templated
824  //classes then executes CompileMacro on it.
825  //The name of the file depends on the class name, and it's not generated again
826  //if the file exist.
827  std::vector<std::string> classes;
828  classes.push_back(className);
829  return TCling_GenerateDictionary(classes, headers, fwdDecls, unknown);
830 }
831 
832 //______________________________________________________________________________
833 //
834 //
835 //
836 
837 // It is a "fantom" method to synchronize user keyboard input
838 // and ROOT prompt line (for WIN32)
839 const char* fantomline = "TRint::EndOfLineAction();";
840 
841 //______________________________________________________________________________
842 //
843 //
844 //
845 
846 void* TCling::fgSetOfSpecials = 0;
847 
848 //______________________________________________________________________________
849 //
850 // llvm error handler through exceptions; see also cling/UserInterface
851 //
852 namespace {
853  // Handle fatal llvm errors by throwing an exception.
854  // Yes, throwing exceptions in error handlers is bad.
855  // Doing nothing is pretty terrible, too.
856  void exceptionErrorHandler(void * /*user_data*/,
857  const std::string& reason,
858  bool /*gen_crash_diag*/) {
859  throw std::runtime_error(std::string(">>> Interpreter compilation error:\n") + reason);
860  }
861 }
862 
863 //______________________________________________________________________________
864 //
865 //
866 //
867 
868 ////////////////////////////////////////////////////////////////////////////////
869 
870 namespace{
871  // An instance of this class causes the diagnostics of clang to be suppressed
872  // during its lifetime
873  class clangDiagSuppr {
874  public:
875  clangDiagSuppr(clang::DiagnosticsEngine& diag): fDiagEngine(diag){
876  fOldDiagValue = fDiagEngine.getIgnoreAllWarnings();
877  fDiagEngine.setIgnoreAllWarnings(true);
878  }
879 
880  ~clangDiagSuppr() {
881  fDiagEngine.setIgnoreAllWarnings(fOldDiagValue);
882  }
883  private:
884  clang::DiagnosticsEngine& fDiagEngine;
885  bool fOldDiagValue;
886  };
887 
888 }
889 
890 ////////////////////////////////////////////////////////////////////////////////
891 /// Allow calling autoparsing from TMetaUtils
892 bool TClingLookupHelper__AutoParse(const char *cname)
893 {
894  return gCling->AutoParse(cname);
895 }
896 
897 ////////////////////////////////////////////////////////////////////////////////
898 /// Try hard to avoid looking up in the Cling database as this could enduce
899 /// an unwanted autoparsing.
900 
901 bool TClingLookupHelper__ExistingTypeCheck(const std::string &tname,
902  std::string &result)
903 {
904  result.clear();
905 
906  unsigned long offset = 0;
907  if (strncmp(tname.c_str(), "const ", 6) == 0) {
908  offset = 6;
909  }
910  unsigned long end = tname.length();
911  while( end && (tname[end-1]=='&' || tname[end-1]=='*' || tname[end-1]==']') ) {
912  if ( tname[end-1]==']' ) {
913  --end;
914  while ( end && tname[end-1]!='[' ) --end;
915  }
916  --end;
917  }
918  std::string innerbuf;
919  const char *inner;
920  if (end != tname.length()) {
921  innerbuf = tname.substr(offset,end-offset);
922  inner = innerbuf.c_str();
923  } else {
924  inner = tname.c_str()+offset;
925  }
926 
927  //if (strchr(tname.c_str(),'[')!=0) fprintf(stderr,"DEBUG: checking on %s vs %s %lu %lu\n",tname.c_str(),inner,offset,end);
928  if (gROOT->GetListOfClasses()->FindObject(inner)
929  || TClassTable::Check(inner,result) ) {
930  // This is a known class.
931  return true;
932  }
933 
934  THashTable *typeTable = dynamic_cast<THashTable*>( gROOT->GetListOfTypes() );
935  TDataType *type = (TDataType *)typeTable->THashTable::FindObject( inner );
936  if (type) {
937  // This is a raw type and an already loaded typedef.
938  const char *newname = type->GetFullTypeName();
939  if (type->GetType() == kLong64_t) {
940  newname = "Long64_t";
941  } else if (type->GetType() == kULong64_t) {
942  newname = "ULong64_t";
943  }
944  if (strcmp(inner,newname) == 0) {
945  return true;
946  }
947  if (offset) result = "const ";
948  result += newname;
949  if ( end != tname.length() ) {
950  result += tname.substr(end,tname.length()-end);
951  }
952  if (result == tname) result.clear();
953  return true;
954  }
955 
956  // Check if the name is an enumerator
957  const auto lastPos = TClassEdit::GetUnqualifiedName(inner);
958  if (lastPos != inner) // Main switch: case 1 - scoped enum, case 2 global enum
959  {
960  // We have a scope
961  // All of this C gymnastic is to avoid allocations on the heap
962  const auto enName = lastPos;
963  const auto scopeNameSize = ((Long64_t)lastPos - (Long64_t)inner) / sizeof(decltype(*lastPos)) - 2;
964 #ifdef R__WIN32
965  char *scopeName = new char[scopeNameSize + 1];
966 #else
967  char scopeName[scopeNameSize + 1]; // on the stack, +1 for the terminating character '\0'
968 #endif
969  strncpy(scopeName, inner, scopeNameSize);
970  scopeName[scopeNameSize] = '\0';
971  // Check if the scope is in the list of classes
972  if (auto scope = static_cast<TClass *>(gROOT->GetListOfClasses()->FindObject(scopeName))) {
973  auto enumTable = dynamic_cast<const THashList *>(scope->GetListOfEnums(false));
974  if (enumTable && enumTable->THashList::FindObject(enName)) return true;
975  }
976  // It may still be in one of the loaded protoclasses
977  else if (auto scope = static_cast<TProtoClass *>(gClassTable->GetProtoNorm(scopeName))) {
978  auto listOfEnums = scope->GetListOfEnums();
979  if (listOfEnums) { // it could be null: no enumerators in the protoclass
980  auto enumTable = dynamic_cast<const THashList *>(listOfEnums);
981  if (enumTable && enumTable->THashList::FindObject(enName)) return true;
982  }
983  }
984 #ifdef R__WIN32
985  delete [] scopeName;
986 #endif
987  } else
988  {
989  // We don't have any scope: this could only be a global enum
990  auto enumTable = dynamic_cast<const THashList *>(gROOT->GetListOfEnums());
991  if (enumTable && enumTable->THashList::FindObject(inner)) return true;
992  }
993 
994  if (gCling->GetClassSharedLibs(inner))
995  {
996  // This is a class name.
997  return true;
998  }
999 
1000  return false;
1001 }
1002 
1003 ////////////////////////////////////////////////////////////////////////////////
1004 
1006 {
1007  fContent.reserve(size);
1008 }
1009 
1010 ////////////////////////////////////////////////////////////////////////////////
1011 
1012 inline const char *TCling::TUniqueString::Data()
1013 {
1014  return fContent.c_str();
1015 }
1016 
1017 ////////////////////////////////////////////////////////////////////////////////
1018 /// Append string to the storage if not added already.
1019 
1020 inline bool TCling::TUniqueString::Append(const std::string& str)
1021 {
1022  bool notPresent = fLinesHashSet.emplace(fHashFunc(str)).second;
1023  if (notPresent){
1024  fContent+=str;
1025  }
1026  return notPresent;
1027 }
1028 
1029 ////////////////////////////////////////////////////////////////////////////////
1030 /// Initialize the cling interpreter interface.
1031 
1032 TCling::TCling(const char *name, const char *title)
1033 : TInterpreter(name, title), fGlobalsListSerial(-1), fInterpreter(0),
1034  fMetaProcessor(0), fNormalizedCtxt(0), fPrevLoadedDynLibInfo(0),
1035  fClingCallbacks(0), fAutoLoadCallBack(0),
1036  fTransactionCount(0), fHeaderParsingOnDemand(true), fIsAutoParsingSuspended(kFALSE)
1037 {
1038  // rootcling also uses TCling for generating the dictionary ROOT files.
1039  bool fromRootCling = dlsym(RTLD_DEFAULT, "usedToIdentifyRootClingByDlSym");
1040 
1041  llvm::install_fatal_error_handler(&exceptionErrorHandler);
1042 
1043  fTemporaries = new std::vector<cling::Value>();
1044 
1045  std::vector<std::string> clingArgsStorage;
1046  clingArgsStorage.push_back("cling4root");
1047 
1048  std::string interpInclude;
1049  // rootcling sets its arguments through TROOT::GetExtraInterpreterArgs().
1050  if (!fromRootCling) {
1052 
1053  interpInclude = ROOT::TMetaUtils::GetInterpreterExtraIncludePath(false);
1054  clingArgsStorage.push_back(interpInclude);
1055 
1056  std::string pchFilename = interpInclude.substr(2) + "/allDict.cxx.pch";
1057  if (gSystem->Getenv("ROOT_PCH")) {
1058  pchFilename = gSystem->Getenv("ROOT_PCH");
1059  }
1060  clingArgsStorage.push_back("-include-pch");
1061  clingArgsStorage.push_back(pchFilename);
1062 
1063  // clingArgsStorage.push_back("-Xclang");
1064  // clingArgsStorage.push_back("-fmodules");
1065 
1066  std::string include;
1067 #ifndef ROOTINCDIR
1068  include = gSystem->Getenv("ROOTSYS");
1069  include += "/include";
1070 #else // ROOTINCDIR
1071  include = ROOTINCDIR;
1072 #endif // ROOTINCDIR
1073  clingArgsStorage.push_back("-I");
1074  clingArgsStorage.push_back(include);
1075  clingArgsStorage.push_back("-Wno-undefined-inline");
1076  clingArgsStorage.push_back("-fsigned-char");
1077  }
1078 
1079  std::vector<const char*> interpArgs;
1080  for (std::vector<std::string>::const_iterator iArg = clingArgsStorage.begin(),
1081  eArg = clingArgsStorage.end(); iArg != eArg; ++iArg)
1082  interpArgs.push_back(iArg->c_str());
1083 
1084  std::string llvmResourceDir = ROOT::TMetaUtils::GetLLVMResourceDir(false);
1085  // Add statically injected extra arguments, usually coming from rootcling.
1086  for (const char** extraArgs = TROOT::GetExtraInterpreterArgs();
1087  extraArgs && *extraArgs; ++extraArgs) {
1088  if (!strcmp(*extraArgs, "-resource-dir")) {
1089  // Take the next arg as the llvm resource directory.
1090  llvmResourceDir = *(++extraArgs);
1091  } else {
1092  interpArgs.push_back(*extraArgs);
1093  }
1094  }
1095 
1096  fInterpreter = new cling::Interpreter(interpArgs.size(),
1097  &(interpArgs[0]),
1098  llvmResourceDir.c_str());
1099 
1100  if (!fromRootCling) {
1101  fInterpreter->installLazyFunctionCreator(llvmLazyFunctionCreator);
1102 
1103  // Add include path to etc/cling. FIXME: This is a short term solution. The
1104  // llvm/clang header files shouldn't be there at all. We have to get rid of
1105  // that dependency and avoid copying the header files.
1106  // Use explicit TCling::AddIncludePath() to avoid vtable: we're in the c'tor!
1107  TCling::AddIncludePath((interpInclude.substr(2) + "/cling").c_str());
1108 
1109  // Add the current path to the include path
1110  // TCling::AddIncludePath(".");
1111 
1112  // Add the root include directory and etc/ to list searched by default.
1114  }
1115 
1116  // Don't check whether modules' files exist.
1117  fInterpreter->getCI()->getPreprocessorOpts().DisablePCHValidation = true;
1118 
1119  // Until we can disable autoloading during Sema::CorrectTypo() we have
1120  // to disable spell checking.
1121  fInterpreter->getCI()->getLangOpts().SpellChecking = false;
1122 
1123 
1124  // We need stream that doesn't close its file descriptor, thus we are not
1125  // using llvm::outs. Keeping file descriptor open we will be able to use
1126  // the results in pipes (Savannah #99234).
1127  static llvm::raw_fd_ostream fMPOuts (STDOUT_FILENO, /*ShouldClose*/false);
1128  fMetaProcessor = new cling::MetaProcessor(*fInterpreter, fMPOuts);
1129 
1130  // For the list to also include string, we have to include it now.
1131  // rootcling does parts already if needed, e.g. genreflex does not want using
1132  // namespace std.
1133  if (fromRootCling) {
1134  fInterpreter->declare("#include \"RtypesCore.h\"\n"
1135  "#include <string>\n"
1136  "using std::string;");
1137  } else {
1138  fInterpreter->declare("#include \"Rtypes.h\"\n"
1139  + gClassDefInterpMacro + "\n"
1140  + gInterpreterClassDef + "\n"
1141  + "#undef ClassImp\n"
1142  "#define ClassImp(X)\n"
1143  "#include <string>\n"
1144  "using namespace std;");
1145  }
1146 
1147  // We are now ready (enough is loaded) to init the list of opaque typedefs.
1150  TClassEdit::Init(fLookupHelper);
1151 
1152  // Initialize the cling interpreter interface.
1153  fMore = 0;
1154  fPrompt[0] = 0;
1155  fMapfile = 0;
1156 // fMapNamespaces = 0;
1157  fRootmapFiles = 0;
1159 
1160  fAllowLibLoad = !fromRootCling;
1161  // Disallow auto-parsing in rootcling
1162  fIsAutoParsingSuspended = fromRootCling;
1163  // Disable the autoloader until it is explicitly enabled.
1164  SetClassAutoloading(false);
1165 
1166  ResetAll();
1167 #ifndef R__WIN32
1168  //optind = 1; // make sure getopt() works in the main program
1169 #endif // R__WIN32
1170 
1171  // Attach cling callbacks
1172  std::unique_ptr<TClingCallbacks>
1173  clingCallbacks(new TClingCallbacks(fInterpreter));
1174  fClingCallbacks = clingCallbacks.get();
1176  fInterpreter->setCallbacks(std::move(clingCallbacks));
1177 
1178  if (!fromRootCling) {
1179  fInterpreter->enableDynamicLookup();
1180  }
1181 }
1182 
1183 
1184 ////////////////////////////////////////////////////////////////////////////////
1185 /// Destroy the interpreter interface.
1186 
1188 {
1189  delete fMapfile;
1190 // delete fMapNamespaces;
1191  delete fRootmapFiles;
1192  delete fMetaProcessor;
1193  delete fTemporaries;
1194  delete fNormalizedCtxt;
1195  delete fInterpreter;
1196  delete fLookupHelper;
1197  gCling = 0;
1198 #if defined(R__MUST_REVISIT)
1199 #if R__MUST_REVISIT(6,2)
1200  Warning("~TCling", "Interface not available yet.");
1201 #ifdef R__COMPLETE_MEM_TERMINATION
1202  // remove all cling objects
1203 #endif
1204 #endif
1205 #endif
1206  //--
1207 }
1208 
1209 ////////////////////////////////////////////////////////////////////////////////
1210 /// Initialize the interpreter, once TROOT::fInterpreter is set.
1211 
1213 {
1215 }
1216 
1217 ////////////////////////////////////////////////////////////////////////////////
1218 /// Wrapper around dladdr (and friends)
1219 
1220 static const char *FindLibraryName(void (*func)())
1221 {
1222 #if defined(__CYGWIN__) && defined(__GNUC__)
1223  return 0;
1224 #elif defined(G__WIN32)
1225  MEMORY_BASIC_INFORMATION mbi;
1226  if (!VirtualQuery (func, &mbi, sizeof (mbi)))
1227  {
1228  return 0;
1229  }
1230 
1231  HMODULE hMod = (HMODULE) mbi.AllocationBase;
1232  TTHREAD_TLS_ARRAY(char, MAX_PATH, moduleName);
1233 
1234  if (!GetModuleFileNameA (hMod, moduleName, sizeof (moduleName)))
1235  {
1236  return 0;
1237  }
1238  return moduleName;
1239 #else
1240  Dl_info info;
1241  if (dladdr((void*)func,&info)==0) {
1242  // Not in a known share library, let's give up
1243  return 0;
1244  } else {
1245  //fprintf(stdout,"Found address in %s\n",info.dli_fname);
1246  return info.dli_fname;
1247  }
1248 #endif
1249 
1250 }
1251 
1252 ////////////////////////////////////////////////////////////////////////////////
1253 /// Helper to initialize TVirtualStreamerInfo's factor early.
1254 /// Use static initialization to insure only one TStreamerInfo is created.
1256 {
1257  // Use lambda since SetFactory return void.
1258  auto setFactory = []() {
1260  return kTRUE;
1261  };
1262  static bool doneFactory = setFactory();
1263  return doneFactory; // avoid unused variable warning.
1264 }
1265 
1266 
1267 ////////////////////////////////////////////////////////////////////////////////
1268 /// Tries to load a PCM; returns true on success.
1269 
1270 bool TCling::LoadPCM(TString pcmFileName,
1271  const char** headers,
1272  void (*triggerFunc)()) const {
1273  // pcmFileName is an intentional copy; updated by FindFile() below.
1274 
1275  TString searchPath;
1276 
1277  if (triggerFunc) {
1278  const char *libraryName = FindLibraryName(triggerFunc);
1279  if (libraryName) {
1280  searchPath = llvm::sys::path::parent_path(libraryName);
1281 #ifdef R__WIN32
1282  searchPath += ";";
1283 #else
1284  searchPath += ":";
1285 #endif
1286  }
1287  }
1288  // Note: if we know where the library is, we probably shouldn't even
1289  // look in other places.
1290  searchPath.Append( gSystem->GetDynamicPath() );
1291 
1292  if (!gSystem->FindFile(searchPath, pcmFileName))
1293  return kFALSE;
1294 
1295  // Prevent the ROOT-PCMs hitting this during auto-load during
1296  // JITting - which will cause recursive compilation.
1297  // Avoid to call the plugin manager at all.
1299 
1300  if (gROOT->IsRootFile(pcmFileName)) {
1301  Int_t oldDebug = gDebug;
1302  if (gDebug > 5) {
1303  gDebug -= 5;
1304  ::Info("TCling::LoadPCM", "Loading ROOT PCM %s", pcmFileName.Data());
1305  } else {
1306  gDebug = 0;
1307  }
1308 
1309  TDirectory::TContext ctxt;
1310 
1311  TFile *pcmFile = new TFile(pcmFileName+"?filetype=pcm","READ");
1312 
1313  auto listOfKeys = pcmFile->GetListOfKeys();
1314 
1315  // This is an empty pcm
1316  if (
1317  listOfKeys &&
1318  (
1319  (listOfKeys->GetSize() == 0) || // Nothing here, or
1320  (
1321  (listOfKeys->GetSize() == 1) && // only one, and
1322  !strcmp(((TKey*)listOfKeys->At(0))->GetName(), "EMPTY") // name is EMPTY
1323  )
1324  )
1325  ) {
1326  delete pcmFile;
1327  gDebug = oldDebug;
1328  return kTRUE;
1329  }
1330 
1331  TObjArray *protoClasses;
1332  if (gDebug > 1)
1333  ::Info("TCling::LoadPCM","reading protoclasses for %s \n",pcmFileName.Data());
1334 
1335  pcmFile->GetObject("__ProtoClasses", protoClasses);
1336 
1337  if (protoClasses) {
1338  for (auto obj : *protoClasses) {
1339  TProtoClass * proto = (TProtoClass*)obj;
1340  TClassTable::Add(proto);
1341  }
1342  // Now that all TClass-es know how to set them up we can update
1343  // existing TClasses, which might cause the creation of e.g. TBaseClass
1344  // objects which in turn requires the creation of TClasses, that could
1345  // come from the PCH, but maybe later in the loop. Instead of resolving
1346  // a dependency graph the addition to the TClassTable above allows us
1347  // to create these dependent TClasses as needed below.
1348  for (auto proto : *protoClasses) {
1349  if (TClass* existingCl
1350  = (TClass*)gROOT->GetListOfClasses()->FindObject(proto->GetName())) {
1351  // We have an existing TClass object. It might be emulated
1352  // or interpreted; we now have more information available.
1353  // Make that available.
1354  if (existingCl->GetState() != TClass::kHasTClassInit) {
1355  DictFuncPtr_t dict = gClassTable->GetDict(proto->GetName());
1356  if (!dict) {
1357  ::Error("TCling::LoadPCM", "Inconsistent TClassTable for %s",
1358  proto->GetName());
1359  } else {
1360  // This will replace the existing TClass.
1361  TClass *ncl = (*dict)();
1362  if (ncl) ncl->PostLoadCheck();
1363 
1364  }
1365  }
1366  }
1367  }
1368 
1369  protoClasses->Clear(); // Ownership was transfered to TClassTable.
1370  delete protoClasses;
1371  }
1372 
1373  TObjArray *dataTypes;
1374  pcmFile->GetObject("__Typedefs", dataTypes);
1375  if (dataTypes) {
1376  for (auto typedf: *dataTypes)
1377  gROOT->GetListOfTypes()->Add(typedf);
1378  dataTypes->Clear(); // Ownership was transfered to TListOfTypes.
1379  delete dataTypes;
1380  }
1381 
1382  TObjArray *enums;
1383  pcmFile->GetObject("__Enums", enums);
1384  if (enums) {
1385  // Cache the pointers
1386  auto listOfGlobals = gROOT->GetListOfGlobals();
1387  auto listOfEnums = dynamic_cast<THashList*>(gROOT->GetListOfEnums());
1388  // Loop on enums and then on enum constants
1389  for (auto selEnum: *enums){
1390  const char* enumScope = selEnum->GetTitle();
1391  const char* enumName = selEnum->GetName();
1392  if (strcmp(enumScope,"") == 0){
1393  // This is a global enum and is added to the
1394  // list of enums and its constants to the list of globals
1395  if (!listOfEnums->THashList::FindObject(enumName)){
1396  ((TEnum*) selEnum)->SetClass(nullptr);
1397  listOfEnums->Add(selEnum);
1398  }
1399  for (auto enumConstant: *static_cast<TEnum*>(selEnum)->GetConstants()){
1400  if (!listOfGlobals->FindObject(enumConstant)){
1401  listOfGlobals->Add(enumConstant);
1402  }
1403  }
1404  }
1405  else {
1406  // This enum is in a namespace. A TClass entry is bootstrapped if
1407  // none exists yet and the enum is added to it
1408  TClass* nsTClassEntry = TClass::GetClass(enumScope);
1409  if (!nsTClassEntry){
1410  nsTClassEntry = new TClass(enumScope,0,TClass::kNamespaceForMeta, true);
1411  }
1412  auto listOfEnums = nsTClassEntry->fEnums.load();
1413  if (!listOfEnums) {
1414  if ( (kIsClass | kIsStruct | kIsUnion) & nsTClassEntry->Property() ) {
1415  // For this case, the list will be immutable once constructed
1416  // (i.e. in this case, by the end of this routine).
1417  listOfEnums = nsTClassEntry->fEnums = new TListOfEnums(nsTClassEntry);
1418  } else {
1419  //namespaces can have enums added to them
1420  listOfEnums = nsTClassEntry->fEnums = new TListOfEnumsWithLock(nsTClassEntry);
1421  }
1422  }
1423  if (listOfEnums && !listOfEnums->THashList::FindObject(enumName)){
1424  ((TEnum*) selEnum)->SetClass(nsTClassEntry);
1425  listOfEnums->Add(selEnum);
1426  }
1427  }
1428  }
1429  enums->Clear();
1430  delete enums;
1431  }
1432 
1433  delete pcmFile;
1434 
1435  gDebug = oldDebug;
1436  } else {
1437  if (gDebug > 5)
1438  ::Info("TCling::LoadPCM", "Loading clang PCM %s", pcmFileName.Data());
1439 
1440  }
1441  // Note: Declaring the relationship between the module (pcm) and the header
1442  // probably does not yet make sense since the pcm is 'only' a root file.
1443  // We also have to review if we still need to do this with the delay loading.
1444  // clang::CompilerInstance* CI = fInterpreter->getCI();
1445  // ROOT::TMetaUtils::declareModuleMap(CI, pcmFileName, headers);
1446  return kTRUE;
1447 }
1448 
1449 //______________________________________________________________________________
1450 
1451 namespace {
1452  using namespace clang;
1453 
1454  class ExtLexicalStorageAdder: public RecursiveASTVisitor<ExtLexicalStorageAdder>{
1455  // This class is to be considered an helper for autoparsing.
1456  // It visits the AST and marks all classes (in all of their redeclarations)
1457  // with the setHasExternalLexicalStorage method.
1458  public:
1459  bool VisitRecordDecl(clang::RecordDecl* rcd){
1460  if (gDebug > 2)
1461  Info("ExtLexicalStorageAdder",
1462  "Adding external lexical storage to class %s",
1463  rcd->getNameAsString().c_str());
1464  auto reDeclPtr = rcd->getMostRecentDecl();
1465  do {
1466  reDeclPtr->setHasExternalLexicalStorage();
1467  } while ((reDeclPtr = reDeclPtr->getPreviousDecl()));
1468 
1469  return false;
1470  }
1471  };
1472 
1473 
1474 }
1475 
1476 ////////////////////////////////////////////////////////////////////////////////
1477 /// Inject the module named "modulename" into cling; load all headers.
1478 /// headers is a 0-terminated array of header files to #include after
1479 /// loading the module. The module is searched for in all $LD_LIBRARY_PATH
1480 /// entries (or %PATH% on Windows).
1481 /// This function gets called by the static initialization of dictionary
1482 /// libraries.
1483 /// The payload code is injected "as is" in the interpreter.
1484 /// The value of 'triggerFunc' is used to find the shared library location.
1485 
1486 void TCling::RegisterModule(const char* modulename,
1487  const char** headers,
1488  const char** includePaths,
1489  const char* payloadCode,
1490  const char* fwdDeclsCode,
1491  void (*triggerFunc)(),
1492  const FwdDeclArgsToKeepCollection_t& fwdDeclsArgToSkip,
1493  const char** classesHeaders)
1494 {
1495  // rootcling also uses TCling for generating the dictionary ROOT files.
1496  static const bool fromRootCling = dlsym(RTLD_DEFAULT, "usedToIdentifyRootClingByDlSym");
1497  // We need the dictionary initialization but we don't want to inject the
1498  // declarations into the interpreter, except for those we really need for
1499  // I/O; see rootcling.cxx after the call to TCling__GetInterpreter().
1500  if (fromRootCling) return;
1501 
1502  // Treat Aclic Libs in a special way. Do not delay the parsing.
1503  bool hasHeaderParsingOnDemand = fHeaderParsingOnDemand;
1504  bool isACLiC = false;
1505  if (hasHeaderParsingOnDemand &&
1506  strstr(modulename, "_ACLiC_dict") != nullptr){
1507  if (gDebug>1)
1508  Info("TCling::RegisterModule",
1509  "Header parsing on demand is active but this is an Aclic library. Disabling it for this library.");
1510  hasHeaderParsingOnDemand = false;
1511  isACLiC = true;
1512  }
1513 
1514 
1515  // Make sure we relookup symbols that were search for before we loaded
1516  // their autoparse information. We could be more subtil and remove only
1517  // the failed one or only the one in this module, but for now this is
1518  // better than nothing.
1519  fLookedUpClasses.clear();
1520 
1521  // Make sure we do not set off autoloading or autoparsing during the
1522  // module registration!
1523  Int_t oldAutoloadValue = SetClassAutoloading(false);
1524 
1525  TString pcmFileName(ROOT::TMetaUtils::GetModuleFileName(modulename).c_str());
1526 
1527  for (const char** inclPath = includePaths; *inclPath; ++inclPath) {
1528  TCling::AddIncludePath(*inclPath);
1529  }
1530  cling::Transaction* T = 0;
1531  // Put the template decls and the number of arguments to skip in the TNormalizedCtxt
1532  for (auto& fwdDeclArgToSkipPair : fwdDeclsArgToSkip){
1533  const std::string& fwdDecl = fwdDeclArgToSkipPair.first;
1534  const int nArgsToSkip = fwdDeclArgToSkipPair.second;
1535  auto compRes = fInterpreter->declare(fwdDecl.c_str(), &T);
1536  assert(cling::Interpreter::kSuccess == compRes &&
1537  "A fwd declaration could not be compiled");
1538  if (compRes!=cling::Interpreter::kSuccess){
1539  Warning("TCling::RegisterModule",
1540  "Problems in declaring string '%s' were encountered.",
1541  fwdDecl.c_str()) ;
1542  continue;
1543  }
1544 
1545  // Drill through namespaces recursively until the template is found
1546  if(ClassTemplateDecl* TD = FindTemplateInNamespace(T->getFirstDecl().getSingleDecl())){
1547  fNormalizedCtxt->AddTemplAndNargsToKeep(TD->getCanonicalDecl(), nArgsToSkip);
1548  }
1549 
1550  }
1551 
1552  // FIXME: Remove #define __ROOTCLING__ once PCMs are there.
1553  // This is used to give Sema the same view on ACLiC'ed files (which
1554  // are then #included through the dictionary) as rootcling had.
1555  TString code = gNonInterpreterClassDef;
1556  code += payloadCode;
1557 
1558  // We need to open the dictionary shared library, to resolve symbols
1559  // requested by the JIT from it: as the library is currently being dlopen'ed,
1560  // its symbols are not yet reachable from the process.
1561  // Recursive dlopen seems to work just fine.
1562  const char* dyLibName = FindLibraryName(triggerFunc);
1563  if (dyLibName) {
1564  // We were able to determine the library name.
1565  void* dyLibHandle = dlopen(dyLibName, RTLD_LAZY | RTLD_GLOBAL);
1566  if (!dyLibHandle) {
1567 #ifdef R__WIN32
1568  char dyLibError[1000];
1569  FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(),
1570  MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), dyLibError,
1571  sizeof(dyLibError), NULL);
1572  {
1573 #else
1574  const char* dyLibError = dlerror();
1575  if (dyLibError) {
1576 #endif
1577  if (gDebug > 0) {
1578  ::Info("TCling::RegisterModule",
1579  "Cannot open shared library %s for dictionary %s:\n %s",
1580  dyLibName, modulename, dyLibError);
1581  }
1582  }
1583  dyLibName = 0;
1584  } else {
1585  fRegisterModuleDyLibs.push_back(dyLibHandle);
1586  }
1587  }
1588 
1589  if (hasHeaderParsingOnDemand && fwdDeclsCode){
1590  // We now parse the forward declarations. All the classes are then modified
1591  // in order for them to have an external lexical storage.
1592  std::string fwdDeclsCodeLessEnums;
1593  {
1594  // Search for enum forward decls and only declare them if no
1595  // declaration exists yet.
1596  std::string fwdDeclsLine;
1597  std::istringstream fwdDeclsCodeStr(fwdDeclsCode);
1598  std::vector<std::string> scope;
1599  while (std::getline(fwdDeclsCodeStr, fwdDeclsLine)) {
1600  if (fwdDeclsLine.find("namespace ") == 0
1601  || fwdDeclsLine.find("inline namespace ") == 0) {
1602  // skip leading "namespace ", trailing " {"
1603  scope.push_back(fwdDeclsLine.substr(10,
1604  fwdDeclsLine.length() - 10 - 2));
1605  } else if (fwdDeclsLine == "}") {
1606  scope.pop_back();
1607  } else if (fwdDeclsLine.find("enum __attribute__((annotate(\"") == 0) {
1608  clang::DeclContext* DC = 0;
1609  for (auto &&aScope: scope) {
1610  DC = cling::utils::Lookup::Namespace(&fInterpreter->getSema(), aScope.c_str(), DC);
1611  if (!DC) {
1612  // No decl context means we have to fwd declare the enum.
1613  break;
1614  }
1615  }
1616  if (scope.empty() || DC) {
1617  // We know the scope; let's look for the enum.
1618  size_t posEnumName = fwdDeclsLine.find("\"))) ", 32);
1619  R__ASSERT(posEnumName != std::string::npos && "Inconsistent enum fwd decl!");
1620  posEnumName += 5; // skip "\"))) "
1621  while (isspace(fwdDeclsLine[posEnumName]))
1622  ++posEnumName;
1623  size_t posEnumNameEnd = fwdDeclsLine.find(" : ", posEnumName);
1624  R__ASSERT(posEnumNameEnd != std::string::npos && "Inconsistent enum fwd decl (end)!");
1625  while (isspace(fwdDeclsLine[posEnumNameEnd]))
1626  --posEnumNameEnd;
1627  // posEnumNameEnd now points to the last character of the name.
1628 
1629  std::string enumName = fwdDeclsLine.substr(posEnumName,
1630  posEnumNameEnd - posEnumName + 1);
1631 
1632  if (clang::NamedDecl* enumDecl
1633  = cling::utils::Lookup::Named(&fInterpreter->getSema(),
1634  enumName.c_str(), DC)) {
1635  // We have an existing enum decl (forward or definition);
1636  // skip this.
1637  R__ASSERT(llvm::dyn_cast<clang::EnumDecl>(enumDecl) && "not an enum decl!");
1638  (void)enumDecl;
1639  continue;
1640  }
1641  }
1642  }
1643  fwdDeclsCodeLessEnums += fwdDeclsLine + "\n";
1644  }
1645  }
1646 
1647  if (fwdDeclsCodeLessEnums.size() != 0){ // Avoid the overhead if nothing is to be declared
1648  auto compRes = fInterpreter->declare(fwdDeclsCodeLessEnums, &T);
1649  assert(cling::Interpreter::kSuccess == compRes &&
1650  "The forward declarations could not be compiled");
1651  if (compRes!=cling::Interpreter::kSuccess){
1652  Warning("TCling::RegisterModule",
1653  "Problems in compiling forward declarations for module %s: '%s'",
1654  modulename, fwdDeclsCodeLessEnums.c_str()) ;
1655  }
1656  else if (T){
1657  // Loop over all decls in the transaction and go through them all
1658  // to mark them properly.
1659  // In order to do that, we first iterate over all the DelayedCallInfos
1660  // within the transaction. Then we loop over all Decls in the DeclGroupRef
1661  // contained in the DelayedCallInfos. For each decl, we traverse.
1662  ExtLexicalStorageAdder elsa;
1663  for (auto dciIt = T->decls_begin();dciIt!=T->decls_end();dciIt++){
1664  cling::Transaction::DelayCallInfo& dci = *dciIt;
1665  for(auto dit = dci.m_DGR.begin(); dit != dci.m_DGR.end(); ++dit) {
1666  clang::Decl* declPtr = *dit;
1667  elsa.TraverseDecl(declPtr);
1668  }
1669  }
1670  }
1671  }
1672 
1673  // Now we register all the headers necessary for the class
1674  // Typical format of the array:
1675  // {"A", "classes.h", "@",
1676  // "vector<A>", "vector", "@",
1677  // "myClass", payloadCode, "@",
1678  // nullptr};
1679 
1680  std::string temp;
1681  for (const char** classesHeader = classesHeaders; *classesHeader; ++classesHeader) {
1682  temp=*classesHeader;
1683 
1684  size_t theTemplateHash = 0;
1685  bool addTemplate = false;
1686  size_t posTemplate = temp.find('<');
1687  if (posTemplate != std::string::npos) {
1688  // Add an entry for the template itself.
1689  std::string templateName = temp.substr(0, posTemplate);
1690  theTemplateHash = fStringHashFunction(templateName);
1691  addTemplate = true;
1692  }
1693  size_t theHash = fStringHashFunction(temp);
1694  classesHeader++;
1695  for (const char** classesHeader_inner = classesHeader; 0!=strcmp(*classesHeader_inner,"@"); ++classesHeader_inner,++classesHeader){
1696  // This is done in order to distinguish headers from files and from the payloadCode
1697  if (payloadCode == *classesHeader_inner ){
1698  fPayloads.insert(theHash);
1699  if (addTemplate) fPayloads.insert(theTemplateHash);
1700  }
1701  if (gDebug > 2)
1702  Info("TCling::RegisterModule",
1703  "Adding a header for %s", temp.c_str());
1704  fClassesHeadersMap[theHash].push_back(*classesHeader_inner);
1705  if (addTemplate) {
1706  if (fClassesHeadersMap.find(theTemplateHash) == fClassesHeadersMap.end()) {
1707  fClassesHeadersMap[theTemplateHash].push_back(*classesHeader_inner);
1708  }
1709  addTemplate = false;
1710  }
1711  }
1712  }
1713  }
1714 
1715 
1716  if (strcmp(modulename,"libCore")!=0 && strcmp(modulename,"libRint")!=0
1717  && strcmp(modulename,"libThread")!=0 && strcmp(modulename,"libRIO")!=0
1718  && strcmp(modulename,"libcomplexDict")!=0 && strcmp(modulename,"libdequeDict")!=0
1719  && strcmp(modulename,"liblistDict")!=0 && strcmp(modulename,"libforward_listDict")!=0
1720  && strcmp(modulename,"libvectorDict")!=0
1721  && strcmp(modulename,"libmapDict")!=0 && strcmp(modulename,"libmultimap2Dict")!=0
1722  && strcmp(modulename,"libmap2Dict")!=0 && strcmp(modulename,"libmultimapDict")!=0
1723  && strcmp(modulename,"libsetDict")!=0 && strcmp(modulename,"libmultisetDict")!=0
1724  && strcmp(modulename,"libunordered_setDict")!=0 && strcmp(modulename,"libunordered_multisetDict")!=0
1725  && strcmp(modulename,"libunordered_mapDict")!=0 && strcmp(modulename,"libunordered_multimapDict")!=0
1726  && strcmp(modulename,"libvalarrayDict")!=0
1727  && strcmp(modulename,"G__GenVector32")!=0 && strcmp(modulename,"G__Smatrix32")!=0
1728 
1729  ) {
1730  // No pcm for now for libCore or libRint, the info is in the pch.
1731  if (!LoadPCM(pcmFileName, headers, triggerFunc)) {
1732  ::Error("TCling::RegisterModule", "cannot find dictionary module %s",
1733  ROOT::TMetaUtils::GetModuleFileName(modulename).c_str());
1734  }
1735  }
1736 
1737  bool oldValue = false;
1738  if (fClingCallbacks)
1739  oldValue = SetClassAutoloading(false);
1740 
1741  { // scope within which diagnostics are de-activated
1742  // For now we disable diagnostics because we saw them already at
1743  // dictionary generation time. That won't be an issue with the PCMs.
1744 
1745  clangDiagSuppr diagSuppr(fInterpreter->getSema().getDiagnostics());
1746 
1747 #if defined(R__MUST_REVISIT)
1748 #if R__MUST_REVISIT(6,2)
1749  Warning("TCling::RegisterModule","Diagnostics suppression should be gone by now.");
1750 #endif
1751 #endif
1752 
1753  if (!hasHeaderParsingOnDemand){
1754  const cling::Transaction* watermark = fInterpreter->getLastTransaction();
1755  cling::Interpreter::CompilationResult compRes = fInterpreter->parseForModule(code.Data());
1756  if (isACLiC) {
1757  // Register an unload point.
1758  fMetaProcessor->registerUnloadPoint(watermark, headers[0]);
1759  }
1760 
1761  assert(cling::Interpreter::kSuccess == compRes &&
1762  "Payload code of a dictionary could not be parsed correctly.");
1763  if (compRes!=cling::Interpreter::kSuccess) {
1764  Warning("TCling::RegisterModule",
1765  "Problems declaring payload for module %s.", modulename) ;
1766  }
1767  }
1768  }
1769 
1770  // Now that all the header have been registered/compiled, let's
1771  // make sure to 'reset' the TClass that have a class init in this module
1772  // but already had their type information available (using information/header
1773  // loaded from other modules or from class rules).
1774  if (!hasHeaderParsingOnDemand) {
1775  // This code is likely to be superseded by the similar code in LoadPCM,
1776  // and have been disabled, (inadvertently or awkwardly) by
1777  // commit 7903f09f3beea69e82ffba29f59fb2d656a4fd54 (Refactor the routines used for header parsing on demand)
1778  // whereas it seems that a more semantically correct conditional would have
1779  // been 'if this module does not have a rootpcm'.
1780  // Note: this need to be review when the clang pcm are being installed.
1781  // #if defined(R__MUST_REVISIT)
1782  while (!fClassesToUpdate.empty()) {
1783  TClass *oldcl = fClassesToUpdate.back().first;
1784  if (oldcl->GetState() != TClass::kHasTClassInit) {
1785  // if (gDebug > 2) Info("RegisterModule", "Forcing TClass init for %s", oldcl->GetName());
1786  DictFuncPtr_t dict = fClassesToUpdate.back().second;
1787  fClassesToUpdate.pop_back();
1788  // Calling func could manipulate the list so, let maintain the list
1789  // then call the dictionary function.
1790  TClass *ncl = dict();
1791  if (ncl) ncl->PostLoadCheck();
1792  } else {
1793  fClassesToUpdate.pop_back();
1794  }
1795  }
1796  }
1797 
1798  if (fClingCallbacks)
1799  SetClassAutoloading(oldValue);
1800 
1801  if (!hasHeaderParsingOnDemand) {
1802  // __ROOTCLING__ might be pulled in through PCH
1803  fInterpreter->declare("#ifdef __ROOTCLING__\n"
1804  "#undef __ROOTCLING__\n"
1805  + gInterpreterClassDef +
1806  "#endif");
1807  }
1808 
1809  if (dyLibName) {
1810  void* dyLibHandle = fRegisterModuleDyLibs.back();
1811  fRegisterModuleDyLibs.pop_back();
1812  dlclose(dyLibHandle);
1813  }
1814 
1815  SetClassAutoloading(oldAutoloadValue);
1816 }
1817 
1818 ////////////////////////////////////////////////////////////////////////////////
1819 /// Register classes that already existed prior to their dictionary loading
1820 /// and that already had a ClassInfo (and thus would not be refresh via
1821 /// UpdateClassInfo.
1822 
1824 {
1825  fClassesToUpdate.push_back(std::make_pair(oldcl,dict));
1826 }
1827 
1828 ////////////////////////////////////////////////////////////////////////////////
1829 /// If the dictionary is loaded, we can remove the class from the list
1830 /// (otherwise the class might be loaded twice).
1831 
1833 {
1834  typedef std::vector<std::pair<TClass*,DictFuncPtr_t> >::iterator iterator;
1835  iterator stop = fClassesToUpdate.end();
1836  for(iterator i = fClassesToUpdate.begin();
1837  i != stop;
1838  ++i)
1839  {
1840  if ( i->first == oldcl ) {
1841  fClassesToUpdate.erase(i);
1842  return;
1843  }
1844  }
1845 }
1846 
1847 ////////////////////////////////////////////////////////////////////////////////
1848 /// Let cling process a command line.
1849 ///
1850 /// If the command is executed and the error is 0, then the return value
1851 /// is the int value corresponding to the result of the executed command
1852 /// (float and double return values will be truncated).
1853 ///
1854 
1855 Long_t TCling::ProcessLine(const char* line, EErrorCode* error/*=0*/)
1856 {
1857  // Copy the passed line, it comes from a static buffer in TApplication
1858  // which can be reentered through the Cling evaluation routines,
1859  // which would overwrite the static buffer and we would forget what we
1860  // were doing.
1861  //
1862  TString sLine(line);
1863  if (strstr(line,fantomline)) {
1864  // End-Of-Line action
1865  // See the comment (copied from above):
1866  // It is a "fantom" method to synchronize user keyboard input
1867  // and ROOT prompt line (for WIN32)
1868  // and is implemented by
1869  if (gApplication) {
1870  if (gApplication->IsCmdThread()) {
1872  gGlobalMutex->Lock();
1873  if (!gInterpreterMutex)
1875  gGlobalMutex->UnLock();
1876  }
1878  gROOT->SetLineIsProcessing();
1879 
1881 
1882  gROOT->SetLineHasBeenProcessed();
1883  }
1884  }
1885  return 0;
1886  }
1887 
1889  gGlobalMutex->Lock();
1890  if (!gInterpreterMutex)
1892  gGlobalMutex->UnLock();
1893  }
1895  gROOT->SetLineIsProcessing();
1896 
1897  struct InterpreterFlagsRAII_t {
1898  cling::Interpreter* fInterpreter;
1899  bool fWasDynamicLookupEnabled;
1900 
1901  InterpreterFlagsRAII_t(cling::Interpreter* interp):
1902  fInterpreter(interp),
1903  fWasDynamicLookupEnabled(interp->isDynamicLookupEnabled())
1904  {
1905  fInterpreter->enableDynamicLookup(true);
1906  }
1907  ~InterpreterFlagsRAII_t() {
1908  fInterpreter->enableDynamicLookup(fWasDynamicLookupEnabled);
1909  }
1910  } interpreterFlagsRAII(fInterpreter);
1911 
1912  // A non-zero returned value means the given line was
1913  // not a complete statement.
1914  int indent = 0;
1915  // This will hold the resulting value of the evaluation the given line.
1917  cling::Interpreter::CompilationResult compRes = cling::Interpreter::kSuccess;
1918  if (!strncmp(sLine.Data(), ".L", 2) || !strncmp(sLine.Data(), ".x", 2) ||
1919  !strncmp(sLine.Data(), ".X", 2)) {
1920  // If there was a trailing "+", then CINT compiled the code above,
1921  // and we will need to strip the "+" before passing the line to cling.
1922  TString mod_line(sLine);
1923  TString aclicMode;
1924  TString arguments;
1925  TString io;
1926  TString fname = gSystem->SplitAclicMode(sLine.Data() + 3,
1927  aclicMode, arguments, io);
1928  if (aclicMode.Length()) {
1929  // Remove the leading '+'
1930  R__ASSERT(aclicMode[0]=='+' && "ACLiC mode must start with a +");
1931  aclicMode[0]='k'; // We always want to keep the .so around.
1932  if (aclicMode[1]=='+') {
1933  // We have a 2nd +
1934  aclicMode[1]='f'; // We want to force the recompilation.
1935  }
1936  if (!gSystem->CompileMacro(fname,aclicMode)) {
1937  // ACLiC failed.
1938  compRes = cling::Interpreter::kFailure;
1939  } else {
1940  if (strncmp(sLine.Data(), ".L", 2) != 0) {
1941  // if execution was requested.
1942 
1943  if (arguments.Length()==0) {
1944  arguments = "()";
1945  }
1946  // We need to remove the extension.
1947  Ssiz_t ext = fname.Last('.');
1948  if (ext != kNPOS) {
1949  fname.Remove(ext);
1950  }
1951  const char *function = gSystem->BaseName(fname);
1952  mod_line = function + arguments + io;
1953  cling::MetaProcessor::MaybeRedirectOutputRAII RAII(fMetaProcessor);
1954  indent = fMetaProcessor->process(mod_line, compRes, &result);
1955  }
1956  }
1957  } else {
1958  // not ACLiC
1959  bool unnamedMacro = false;
1960  {
1961  std::string line;
1962  std::ifstream in(fname);
1963  static const char whitespace[] = " \t\r\n";
1964  while (in) {
1965  std::getline(in, line);
1966  std::string::size_type posNonWS = line.find_first_not_of(whitespace);
1967  if (posNonWS == std::string::npos) continue;
1968  if (line[posNonWS] == '/' && line[posNonWS + 1] == '/')
1969  // Too bad, we only suppose C++ comments here.
1970  continue;
1971  unnamedMacro = (line[posNonWS] == '{');
1972  break;
1973  }
1974  }
1975 
1976  fCurExecutingMacros.push_back(fname);
1977  cling::MetaProcessor::MaybeRedirectOutputRAII RAII(fMetaProcessor);
1978  if (unnamedMacro) {
1979  compRes = fMetaProcessor->readInputFromFile(fname.Data(), &result,
1980  true /*ignoreOutmostBlock*/);
1981  } else {
1982  // No DynLookup for .x, .L of named macros.
1983  fInterpreter->enableDynamicLookup(false);
1984  indent = fMetaProcessor->process(mod_line, compRes, &result);
1985  }
1986  fCurExecutingMacros.pop_back();
1987  }
1988  } // .L / .X / .x
1989  else {
1990  if (0!=strncmp(sLine.Data(), ".autodict ",10) && sLine != ".autodict") {
1991  // explicitly ignore .autodict without having to support it
1992  // in cling.
1993  cling::MetaProcessor::MaybeRedirectOutputRAII RAII(fMetaProcessor);
1994 
1995  // Turn off autoparsing if this is an include directive
1996  bool isInclusionDirective = sLine.Contains("\n#include") || sLine.BeginsWith("#include");
1997  if (isInclusionDirective) {
1998  SuspendAutoParsing autoParseRaii(this);
1999  indent = fMetaProcessor->process(sLine, compRes, &result);
2000  } else {
2001  indent = fMetaProcessor->process(sLine, compRes, &result);
2002  }
2003  }
2004  }
2005  if (result.isValid())
2006  RegisterTemporary(result);
2007  if (indent) {
2008  if (error)
2009  *error = kProcessing;
2010  return 0;
2011  }
2012  if (error) {
2013  switch (compRes) {
2014  case cling::Interpreter::kSuccess: *error = kNoError; break;
2015  case cling::Interpreter::kFailure: *error = kRecoverable; break;
2016  case cling::Interpreter::kMoreInputExpected: *error = kProcessing; break;
2017  }
2018  }
2019  if (compRes == cling::Interpreter::kSuccess
2020  && result.isValid()
2021  && !result.isVoid())
2022  {
2023  gROOT->SetLineHasBeenProcessed();
2024  return result.simplisticCastAs<long>();
2025  }
2026  gROOT->SetLineHasBeenProcessed();
2027  return 0;
2028 }
2029 
2030 ////////////////////////////////////////////////////////////////////////////////
2031 /// No-op; see TRint instead.
2032 
2034 {
2035 }
2036 
2037 ////////////////////////////////////////////////////////////////////////////////
2038 /// Add the given path to the list of directories in which the interpreter
2039 /// looks for include files. Only one path item can be specified at a
2040 /// time, i.e. "path1:path2" is not supported.
2041 
2042 void TCling::AddIncludePath(const char *path)
2043 {
2045  fInterpreter->AddIncludePath(path);
2046 }
2047 
2048 ////////////////////////////////////////////////////////////////////////////////
2049 /// Visit all members over members, recursing over base classes.
2050 
2052  const TClass* cl, Bool_t isTransient)
2053 {
2057  }
2058 
2059  if (!cl || cl->GetCollectionProxy()) {
2060  // We do not need to investigate the content of the STL
2061  // collection, they are opaque to us (and details are
2062  // uninteresting).
2063  return;
2064  }
2065 
2066  static const TClassRef clRefString("std::string");
2067  if (clRefString == cl) {
2068  // We stream std::string without going through members..
2069  return;
2070  }
2071 
2072  const char* cobj = (const char*) obj; // for ptr arithmetics
2073 
2074  // Treat the case of std::complex in a special manner. We want to enforce
2075  // the layout of a stl implementation independent class, which is the
2076  // complex as implemented in ROOT5.
2077 
2078  // A simple lambda to simplify the code
2079  auto inspInspect = [&] (ptrdiff_t offset){
2080  insp.Inspect(const_cast<TClass*>(cl), insp.GetParent(), "_real", cobj, isTransient);
2081  insp.Inspect(const_cast<TClass*>(cl), insp.GetParent(), "_imag", cobj + offset, isTransient);
2082  };
2083 
2084  auto complexType = TClassEdit::GetComplexType(cl->GetName());
2085  switch(complexType) {
2087  {
2088  break;
2089  }
2091  {
2092  inspInspect(sizeof(float));
2093  return;
2094  }
2096  {
2097  inspInspect(sizeof(double));
2098  return;
2099  }
2101  {
2102  inspInspect(sizeof(int));
2103  return;
2104  }
2106  {
2107  inspInspect(sizeof(long));
2108  return;
2109  }
2110  }
2111 
2112  static clang::PrintingPolicy
2113  printPol(fInterpreter->getCI()->getLangOpts());
2114  if (printPol.Indentation) {
2115  // not yet initialized
2116  printPol.Indentation = 0;
2117  printPol.SuppressInitializers = true;
2118  }
2119 
2120  const char* clname = cl->GetName();
2121  // Printf("Inspecting class %s\n", clname);
2122 
2123  const clang::ASTContext& astContext = fInterpreter->getCI()->getASTContext();
2124  const clang::Decl *scopeDecl = 0;
2125  const clang::Type *recordType = 0;
2126 
2127  if (cl->GetClassInfo()) {
2128  TClingClassInfo * clingCI = (TClingClassInfo *)cl->GetClassInfo();
2129  scopeDecl = clingCI->GetDecl();
2130  recordType = clingCI->GetType();
2131  } else {
2132  const cling::LookupHelper& lh = fInterpreter->getLookupHelper();
2133  // Diags will complain about private classes:
2134  scopeDecl = lh.findScope(clname, cling::LookupHelper::NoDiagnostics,
2135  &recordType);
2136  }
2137  if (!scopeDecl) {
2138  Error("InspectMembers", "Cannot find Decl for class %s", clname);
2139  return;
2140  }
2141  const clang::CXXRecordDecl* recordDecl
2142  = llvm::dyn_cast<const clang::CXXRecordDecl>(scopeDecl);
2143  if (!recordDecl) {
2144  Error("InspectMembers", "Cannot find Decl for class %s is not a CXXRecordDecl.", clname);
2145  return;
2146  }
2147 
2148  {
2149  // Force possible deserializations first. We need to have no pending
2150  // Transaction when passing control flow to the inspector below (ROOT-7779).
2151  cling::Interpreter::PushTransactionRAII deserRAII(fInterpreter);
2152 
2153  astContext.getASTRecordLayout(recordDecl);
2154 
2155  for (clang::RecordDecl::field_iterator iField = recordDecl->field_begin(),
2156  eField = recordDecl->field_end(); iField != eField; ++iField) {}
2157  }
2158 
2159  const clang::ASTRecordLayout& recLayout
2160  = astContext.getASTRecordLayout(recordDecl);
2161 
2162  // TVirtualCollectionProxy *proxy = cl->GetCollectionProxy();
2163  // if (proxy && ( proxy->GetProperties() & TVirtualCollectionProxy::kIsEmulated ) ) {
2164  // Error("InspectMembers","The TClass for %s has an emulated proxy but we are looking at a compiled version of the collection!\n",
2165  // cl->GetName());
2166  // }
2167  if (cl->Size() != recLayout.getSize().getQuantity()) {
2168  Error("InspectMembers","TClass and cling disagree on the size of the class %s, respectively %d %lld\n",
2169  cl->GetName(),cl->Size(),(Long64_t)recLayout.getSize().getQuantity());
2170  }
2171 
2172  unsigned iNField = 0;
2173  // iterate over fields
2174  // FieldDecls are non-static, else it would be a VarDecl.
2175  for (clang::RecordDecl::field_iterator iField = recordDecl->field_begin(),
2176  eField = recordDecl->field_end(); iField != eField;
2177  ++iField, ++iNField) {
2178 
2179 
2180  clang::QualType memberQT = iField->getType();
2181  if (recordType) {
2182  // if (we_need_to_do_the_subst_because_the_class_is_a_template_instance_of_double32_t)
2183  memberQT = ROOT::TMetaUtils::ReSubstTemplateArg(memberQT, recordType);
2184  }
2185  memberQT = cling::utils::Transform::GetPartiallyDesugaredType(astContext, memberQT, fNormalizedCtxt->GetConfig(), false /* fully qualify */);
2186  if (memberQT.isNull()) {
2187  std::string memberName;
2188  llvm::raw_string_ostream stream(memberName);
2189  iField->getNameForDiagnostic(stream, printPol, true /*fqi*/);
2190  stream.flush();
2191  Error("InspectMembers",
2192  "Cannot retrieve QualType for member %s while inspecting class %s",
2193  memberName.c_str(), clname);
2194  continue; // skip member
2195  }
2196  const clang::Type* memType = memberQT.getTypePtr();
2197  if (!memType) {
2198  std::string memberName;
2199  llvm::raw_string_ostream stream(memberName);
2200  iField->getNameForDiagnostic(stream, printPol, true /*fqi*/);
2201  stream.flush();
2202  Error("InspectMembers",
2203  "Cannot retrieve Type for member %s while inspecting class %s",
2204  memberName.c_str(), clname);
2205  continue; // skip member
2206  }
2207 
2208  const clang::Type* memNonPtrType = memType;
2209  Bool_t ispointer = false;
2210  if (memNonPtrType->isPointerType()) {
2211  ispointer = true;
2212  clang::QualType ptrQT
2213  = memNonPtrType->getAs<clang::PointerType>()->getPointeeType();
2214  if (recordType) {
2215  // if (we_need_to_do_the_subst_because_the_class_is_a_template_instance_of_double32_t)
2216  ptrQT = ROOT::TMetaUtils::ReSubstTemplateArg(ptrQT, recordType);
2217  }
2218  ptrQT = cling::utils::Transform::GetPartiallyDesugaredType(astContext, ptrQT, fNormalizedCtxt->GetConfig(), false /* fully qualify */);
2219  if (ptrQT.isNull()) {
2220  std::string memberName;
2221  llvm::raw_string_ostream stream(memberName);
2222  iField->getNameForDiagnostic(stream, printPol, true /*fqi*/);
2223  stream.flush();
2224  Error("InspectMembers",
2225  "Cannot retrieve pointee Type for member %s while inspecting class %s",
2226  memberName.c_str(), clname);
2227  continue; // skip member
2228  }
2229  memNonPtrType = ptrQT.getTypePtr();
2230  }
2231 
2232  // assemble array size(s): "[12][4][]"
2233  llvm::SmallString<8> arraySize;
2234  const clang::ArrayType* arrType = memNonPtrType->getAsArrayTypeUnsafe();
2235  unsigned arrLevel = 0;
2236  bool haveErrorDueToArray = false;
2237  while (arrType) {
2238  ++arrLevel;
2239  arraySize += '[';
2240  const clang::ConstantArrayType* constArrType =
2241  clang::dyn_cast<clang::ConstantArrayType>(arrType);
2242  if (constArrType) {
2243  constArrType->getSize().toStringUnsigned(arraySize);
2244  }
2245  arraySize += ']';
2246  clang::QualType subArrQT = arrType->getElementType();
2247  if (subArrQT.isNull()) {
2248  std::string memberName;
2249  llvm::raw_string_ostream stream(memberName);
2250  iField->getNameForDiagnostic(stream, printPol, true /*fqi*/);
2251  stream.flush();
2252  Error("InspectMembers",
2253  "Cannot retrieve QualType for array level %d (i.e. element type of %s) for member %s while inspecting class %s",
2254  arrLevel, subArrQT.getAsString(printPol).c_str(),
2255  memberName.c_str(), clname);
2256  haveErrorDueToArray = true;
2257  break;
2258  }
2259  arrType = subArrQT.getTypePtr()->getAsArrayTypeUnsafe();
2260  }
2261  if (haveErrorDueToArray) {
2262  continue; // skip member
2263  }
2264 
2265  // construct member name
2266  std::string fieldName;
2267  if (memType->isPointerType()) {
2268  fieldName = "*";
2269  }
2270 
2271  // Check if this field has a custom ioname, if not, just use the one of the decl
2272  std::string ioname(iField->getName());
2274  fieldName += ioname;
2275  fieldName += arraySize;
2276 
2277  // get member offset
2278  // NOTE currently we do not support bitfield and do not support
2279  // member that are not aligned on 'bit' boundaries.
2280  clang::CharUnits offset(astContext.toCharUnitsFromBits(recLayout.getFieldOffset(iNField)));
2281  ptrdiff_t fieldOffset = offset.getQuantity();
2282 
2283  // R__insp.Inspect(R__cl, R__insp.GetParent(), "fBits[2]", fBits);
2284  // R__insp.Inspect(R__cl, R__insp.GetParent(), "fName", &fName);
2285  // R__insp.InspectMember(fName, "fName.");
2286  // R__insp.Inspect(R__cl, R__insp.GetParent(), "*fClass", &fClass);
2287 
2288  // If the class has a custom streamer and the type of the filed is a
2289  // private enum, struct or class, skip it.
2290  if (!insp.IsTreatingNonAccessibleTypes()){
2291  auto iFiledQtype = iField->getType();
2292  if (auto tagDecl = iFiledQtype->getAsTagDecl()){
2293  auto declAccess = tagDecl->getAccess();
2294  if (declAccess == AS_private || declAccess == AS_protected) {
2295  continue;
2296  }
2297  }
2298  }
2299 
2300  insp.Inspect(const_cast<TClass*>(cl), insp.GetParent(), fieldName.c_str(), cobj + fieldOffset, isTransient);
2301 
2302  if (!ispointer) {
2303  const clang::CXXRecordDecl* fieldRecDecl = memNonPtrType->getAsCXXRecordDecl();
2304  if (fieldRecDecl) {
2305  // nested objects get an extra call to InspectMember
2306  // R__insp.InspectMember("FileStat_t", (void*)&fFileStat, "fFileStat.", false);
2307  std::string sFieldRecName;
2308  if (!ROOT::TMetaUtils::ExtractAttrPropertyFromName(*fieldRecDecl,"iotype",sFieldRecName)){
2310  clang::QualType(memNonPtrType,0),
2311  *fInterpreter,
2312  *fNormalizedCtxt);
2313  }
2314 
2315  TDataMember* mbr = cl->GetDataMember(ioname.c_str());
2316  // if we can not find the member (which should not really happen),
2317  // let's consider it transient.
2318  Bool_t transient = isTransient || !mbr || !mbr->IsPersistent();
2319 
2320  insp.InspectMember(sFieldRecName.c_str(), cobj + fieldOffset,
2321  (fieldName + '.').c_str(), transient);
2322 
2323  }
2324  }
2325  } // loop over fields
2326 
2327  // inspect bases
2328  // TNamed::ShowMembers(R__insp);
2329  unsigned iNBase = 0;
2330  for (clang::CXXRecordDecl::base_class_const_iterator iBase
2331  = recordDecl->bases_begin(), eBase = recordDecl->bases_end();
2332  iBase != eBase; ++iBase, ++iNBase) {
2333  clang::QualType baseQT = iBase->getType();
2334  if (baseQT.isNull()) {
2335  Error("InspectMembers",
2336  "Cannot find QualType for base number %d while inspecting class %s",
2337  iNBase, clname);
2338  continue;
2339  }
2340  const clang::CXXRecordDecl* baseDecl
2341  = baseQT->getAsCXXRecordDecl();
2342  if (!baseDecl) {
2343  Error("InspectMembers",
2344  "Cannot find CXXRecordDecl for base number %d while inspecting class %s",
2345  iNBase, clname);
2346  continue;
2347  }
2348  TClass* baseCl=nullptr;
2349  std::string sBaseName;
2350  // Try with the DeclId
2351  std::vector<TClass*> foundClasses;
2352  TClass::GetClass(static_cast<DeclId_t>(baseDecl), foundClasses);
2353  if (foundClasses.size()==1){
2354  baseCl=foundClasses[0];
2355  } else {
2356  // Try with the normalised Name, as a fallback
2357  if (!baseCl){
2359  baseQT,
2360  *fInterpreter,
2361  *fNormalizedCtxt);
2362  baseCl = TClass::GetClass(sBaseName.c_str());
2363  }
2364  }
2365 
2366  if (!baseCl){
2367  std::string qualNameForDiag;
2368  ROOT::TMetaUtils::GetQualifiedName(qualNameForDiag, *baseDecl);
2369  Error("InspectMembers",
2370  "Cannot find TClass for base class %s", qualNameForDiag.c_str() );
2371  continue;
2372  }
2373 
2374  int64_t baseOffset;
2375  if (iBase->isVirtual()) {
2377  if (!isTransient) {
2378  Error("InspectMembers",
2379  "Base %s of class %s is virtual but no object provided",
2380  sBaseName.c_str(), clname);
2381  }
2383  } else {
2384  // We have an object to determine the vbase offset.
2386  TClingClassInfo* baseCi = (TClingClassInfo*)baseCl->GetClassInfo();
2387  if (ci && baseCi) {
2388  baseOffset = ci->GetBaseOffset(baseCi, const_cast<void*>(obj),
2389  true /*isDerivedObj*/);
2390  if (baseOffset == -1) {
2391  Error("InspectMembers",
2392  "Error calculating offset of virtual base %s of class %s",
2393  sBaseName.c_str(), clname);
2394  }
2395  } else {
2396  Error("InspectMembers",
2397  "Cannot calculate offset of virtual base %s of class %s",
2398  sBaseName.c_str(), clname);
2399  continue;
2400  }
2401  }
2402  } else {
2403  baseOffset = recLayout.getBaseClassOffset(baseDecl).getQuantity();
2404  }
2405  // TOFIX: baseCl can be null here!
2406  if (baseCl->IsLoaded()) {
2407  // For loaded class, CallShowMember will (especially for TObject)
2408  // call the virtual ShowMember rather than the class specific version
2409  // resulting in an infinite recursion.
2410  InspectMembers(insp, cobj + baseOffset, baseCl, isTransient);
2411  } else {
2412  baseCl->CallShowMembers(cobj + baseOffset,
2413  insp, isTransient);
2414  }
2415  } // loop over bases
2416 }
2417 
2418 ////////////////////////////////////////////////////////////////////////////////
2419 /// Reset the interpreter internal state in case a previous action was not correctly
2420 /// terminated.
2421 
2423 {
2424  // No-op there is not equivalent state (to be cleared) in Cling.
2425 }
2426 
2427 ////////////////////////////////////////////////////////////////////////////////
2428 /// Delete existing temporary values.
2429 
2431 {
2432  // No-op for cling due to cling::Value.
2433 }
2434 
2435 ////////////////////////////////////////////////////////////////////////////////
2436 /// Declare code to the interpreter, without any of the interpreter actions
2437 /// that could trigger a re-interpretation of the code. I.e. make cling
2438 /// behave like a compiler: no dynamic lookup, no input wrapping for
2439 /// subsequent execution, no automatic provision of declarations but just a
2440 /// plain #include.
2441 /// Returns true on success, false on failure.
2442 
2443 bool TCling::Declare(const char* code)
2444 {
2446 
2447  int oldload = SetClassAutoloading(0);
2448  SuspendAutoParsing autoParseRaii(this);
2449 
2450  bool oldDynLookup = fInterpreter->isDynamicLookupEnabled();
2451  fInterpreter->enableDynamicLookup(false);
2452  bool oldRawInput = fInterpreter->isRawInputEnabled();
2453  fInterpreter->enableRawInput(true);
2454 
2455  Bool_t ret = LoadText(code);
2456 
2457  fInterpreter->enableRawInput(oldRawInput);
2458  fInterpreter->enableDynamicLookup(oldDynLookup);
2459  SetClassAutoloading(oldload);
2460  return ret;
2461 }
2462 
2463 ////////////////////////////////////////////////////////////////////////////////
2464 /// Enable the automatic loading of shared libraries when a class
2465 /// is used that is stored in a not yet loaded library. Uses the
2466 /// information stored in the class/library map (typically
2467 /// $ROOTSYS/etc/system.rootmap).
2468 
2470 {
2471  if (fAllowLibLoad) {
2472  LoadLibraryMap();
2473  SetClassAutoloading(true);
2474  }
2475 }
2476 
2477 ////////////////////////////////////////////////////////////////////////////////
2478 /// It calls a "fantom" method to synchronize user keyboard input
2479 /// and ROOT prompt line.
2480 
2482 {
2483  ProcessLineSynch(fantomline);
2484 }
2485 
2486 ////////////////////////////////////////////////////////////////////////////////
2487 /// Return true if the file has already been loaded by cint.
2488 /// We will try in this order:
2489 /// actual filename
2490 /// filename as a path relative to
2491 /// the include path
2492 /// the shared library path
2493 
2495 {
2497 
2498  //FIXME: if we use llvm::sys::fs::make_absolute all this can go away. See
2499  // cling::DynamicLibraryManager.
2500 
2501  std::string file_name = filename;
2502  size_t at = std::string::npos;
2503  while ((at = file_name.find("/./")) != std::string::npos)
2504  file_name.replace(at, 3, "/");
2505 
2506  std::string filesStr = "";
2507  llvm::raw_string_ostream filesOS(filesStr);
2508  clang::SourceManager &SM = fInterpreter->getCI()->getSourceManager();
2509  cling::ClangInternalState::printIncludedFiles(filesOS, SM);
2510  filesOS.flush();
2511 
2512  llvm::SmallVector<llvm::StringRef, 100> files;
2513  llvm::StringRef(filesStr).split(files, "\n");
2514 
2515  std::set<std::string> fileMap;
2516  // Fill fileMap; return early on exact match.
2517  for (llvm::SmallVector<llvm::StringRef, 100>::const_iterator
2518  iF = files.begin(), iE = files.end(); iF != iE; ++iF) {
2519  if ((*iF) == file_name.c_str()) return kTRUE; // exact match
2520  fileMap.insert(*iF);
2521  }
2522 
2523  if (fileMap.empty()) return kFALSE;
2524 
2525  // Check MacroPath.
2526  TString sFilename(file_name.c_str());
2528  && fileMap.count(sFilename.Data())) {
2529  return kTRUE;
2530  }
2531 
2532  // Check IncludePath.
2533  TString incPath = gSystem->GetIncludePath(); // of the form -Idir1 -Idir2 -Idir3
2534  incPath.Append(":").Prepend(" "); // to match " -I" (note leading ' ')
2535  incPath.ReplaceAll(" -I", ":"); // of form :dir1 :dir2:dir3
2536  while (incPath.Index(" :") != -1) {
2537  incPath.ReplaceAll(" :", ":");
2538  }
2539  incPath.Prepend(".:");
2540  sFilename = file_name.c_str();
2541  if (gSystem->FindFile(incPath, sFilename, kReadPermission)
2542  && fileMap.count(sFilename.Data())) {
2543  return kTRUE;
2544  }
2545 
2546  // Check shared library.
2547  sFilename = file_name.c_str();
2548  const char *found = gSystem->FindDynamicLibrary(sFilename, kTRUE);
2549  cling::DynamicLibraryManager* dyLibManager
2550  = fInterpreter->getDynamicLibraryManager();
2551  if (found) {
2552  if (dyLibManager->isLibraryLoaded(found)) {
2553  return kTRUE;
2554  }
2555  }
2556  //FIXME: We must use the cling::Interpreter::lookupFileOrLibrary iface.
2557  const clang::DirectoryLookup *CurDir = 0;
2558  clang::Preprocessor &PP = fInterpreter->getCI()->getPreprocessor();
2559  clang::HeaderSearch &HS = PP.getHeaderSearchInfo();
2560  const clang::FileEntry *FE = HS.LookupFile(file_name.c_str(),
2561  clang::SourceLocation(),
2562  /*isAngled*/ false,
2563  /*FromDir*/ 0, CurDir,
2564  clang::ArrayRef<std::pair<const clang::FileEntry *,
2565  const clang::DirectoryEntry *>>(),
2566  /*SearchPath*/ 0,
2567  /*RelativePath*/ 0,
2568  /*SuggestedModule*/ 0,
2569  /*SkipCache*/ false,
2570  /*OpenFile*/ false,
2571  /*CacheFail*/ false);
2572  if (FE && FE->isValid()) {
2573  // check in the source manager if the file is actually loaded
2574  clang::SourceManager &SM = fInterpreter->getCI()->getSourceManager();
2575  // this works only with header (and source) files...
2576  clang::FileID FID = SM.translateFile(FE);
2577  if (!FID.isInvalid() && FID.getHashValue() == 0)
2578  return kFALSE;
2579  else {
2580  clang::SrcMgr::SLocEntry SLocE = SM.getSLocEntry(FID);
2581  if (SLocE.isFile() && SLocE.getFile().getContentCache()->getRawBuffer() == 0)
2582  return kFALSE;
2583  if (!FID.isInvalid())
2584  return kTRUE;
2585  }
2586  // ...then check shared library again, but with full path now
2587  sFilename = FE->getName();
2588  if (gSystem->FindDynamicLibrary(sFilename, kTRUE)
2589  && fileMap.count(sFilename.Data())) {
2590  return kTRUE;
2591  }
2592  }
2593  return kFALSE;
2594 }
2595 
2596 ////////////////////////////////////////////////////////////////////////////////
2597 
2599 {
2600 #if defined(R__WIN32) || defined(__CYGWIN__)
2601  HMODULE hModules[1024];
2602  void *hProcess;
2603  unsigned long cbModules;
2604  unsigned int i;
2605  hProcess = (void *)::GetCurrentProcess();
2606  ::EnumProcessModules(hProcess, hModules, sizeof(hModules), &cbModules);
2607  // start at 1 to skip the executable itself
2608  for (i = 1; i < (cbModules / sizeof(void *)); i++) {
2609  static const int bufsize = 260;
2610  wchar_t winname[bufsize];
2611  char posixname[bufsize];
2612  ::GetModuleFileNameExW(hProcess, hModules[i], winname, bufsize);
2613 #if defined(__CYGWIN__)
2614  cygwin_conv_path(CCP_WIN_W_TO_POSIX, winname, posixname, bufsize);
2615 #else
2616  std::wstring wpath = winname;
2617  std::replace(wpath.begin(), wpath.end(), '\\', '/');
2618  string path(wpath.begin(), wpath.end());
2619  strncpy(posixname, path.c_str(), bufsize);
2620 #endif
2621  if (!fSharedLibs.Contains(posixname)) {
2622  RegisterLoadedSharedLibrary(posixname);
2623  }
2624  }
2625 #elif defined(R__MACOSX)
2626  // fPrevLoadedDynLibInfo stores the *next* image index to look at
2627  uint32_t imageIndex = (uint32_t) (size_t) fPrevLoadedDynLibInfo;
2628  const char* imageName = 0;
2629  while ((imageName = _dyld_get_image_name(imageIndex))) {
2630  // Skip binary
2631  if (imageIndex > 0)
2632  RegisterLoadedSharedLibrary(imageName);
2633  ++imageIndex;
2634  }
2635  fPrevLoadedDynLibInfo = (void*)(size_t)imageIndex;
2636 #elif defined(R__LINUX)
2637  struct PointerNo4_t {
2638  void* fSkip[3];
2639  void* fPtr;
2640  };
2641  struct LinkMap_t {
2642  void* fAddr;
2643  const char* fName;
2644  void* fLd;
2645  LinkMap_t* fNext;
2646  LinkMap_t* fPrev;
2647  };
2648  if (!fPrevLoadedDynLibInfo || fPrevLoadedDynLibInfo == (void*)(size_t)-1) {
2649  PointerNo4_t* procLinkMap = (PointerNo4_t*)dlopen(0, RTLD_LAZY | RTLD_GLOBAL);
2650  // 4th pointer of 4th pointer is the linkmap.
2651  // See http://syprog.blogspot.fr/2011/12/listing-loaded-shared-objects-in-linux.html
2652  LinkMap_t* linkMap = (LinkMap_t*) ((PointerNo4_t*)procLinkMap->fPtr)->fPtr;
2653  RegisterLoadedSharedLibrary(linkMap->fName);
2654  fPrevLoadedDynLibInfo = linkMap;
2655  }
2656 
2657  LinkMap_t* iDyLib = (LinkMap_t*)fPrevLoadedDynLibInfo;
2658  while (iDyLib->fNext) {
2659  iDyLib = iDyLib->fNext;
2660  RegisterLoadedSharedLibrary(iDyLib->fName);
2661  }
2662  fPrevLoadedDynLibInfo = iDyLib;
2663 #else
2664  Error("TCling::UpdateListOfLoadedSharedLibraries",
2665  "Platform not supported!");
2666 #endif
2667 }
2668 
2669 ////////////////////////////////////////////////////////////////////////////////
2670 /// Register a new shared library name with the interpreter; add it to
2671 /// fSharedLibs.
2672 
2674 {
2675  // Ignore NULL filenames, aka "the process".
2676  if (!filename) return;
2677 
2678  // Tell the interpreter that this library is available; all libraries can be
2679  // used to resolve symbols.
2680  cling::DynamicLibraryManager* DLM = fInterpreter->getDynamicLibraryManager();
2681  if (!DLM->isLibraryLoaded(filename)) {
2682  DLM->loadLibrary(filename, true /*permanent*/);
2683  }
2684 
2685 #if defined(R__MACOSX)
2686  // Check that this is not a system library
2687  if (!strncmp(filename, "/usr/lib/system/", 16)
2688  || !strncmp(filename, "/usr/lib/libc++", 15)
2689  || !strncmp(filename, "/System/Library/Frameworks/", 27)
2690  || !strncmp(filename, "/System/Library/PrivateFrameworks/", 34)
2691  || !strncmp(filename, "/System/Library/CoreServices/", 29)
2692  || !strcmp(filename, "cl_kernels") // yepp, no directory
2693  || strstr(filename, "/usr/lib/libSystem")
2694  || strstr(filename, "/usr/lib/libstdc++")
2695  || strstr(filename, "/usr/lib/libicucore")
2696  || strstr(filename, "/usr/lib/libbsm")
2697  || strstr(filename, "/usr/lib/libobjc")
2698  || strstr(filename, "/usr/lib/libresolv")
2699  || strstr(filename, "/usr/lib/libauto")
2700  || strstr(filename, "/usr/lib/libcups")
2701  || strstr(filename, "/usr/lib/libDiagnosticMessagesClient")
2702  || strstr(filename, "/usr/lib/liblangid")
2703  || strstr(filename, "/usr/lib/libCRFSuite")
2704  || strstr(filename, "/usr/lib/libpam")
2705  || strstr(filename, "/usr/lib/libOpenScriptingUtil")
2706  || strstr(filename, "/usr/lib/libextension"))
2707  return;
2708 #elif defined(__CYGWIN__)
2709  // Check that this is not a system library
2710  static const int bufsize = 260;
2711  char posixwindir[bufsize];
2712  char *windir = getenv("WINDIR");
2713  if (windir)
2714  cygwin_conv_path(CCP_WIN_A_TO_POSIX, windir, posixwindir, bufsize);
2715  else
2716  snprintf(posixwindir, sizeof(posixwindir), "/Windows/");
2717  if (strstr(filename, posixwindir) ||
2718  strstr(filename, "/usr/bin/cyg"))
2719  return;
2720 #elif defined(R__WIN32)
2721  if (strstr(filename, "/Windows/"))
2722  return;
2723 #elif defined (R__LINUX)
2724  if (strstr(filename, "/ld-linux")
2725  || strstr(filename, "linux-gnu/")
2726  || strstr(filename, "/libstdc++.")
2727  || strstr(filename, "/libgcc")
2728  || strstr(filename, "/libc.")
2729  || strstr(filename, "/libdl.")
2730  || strstr(filename, "/libm."))
2731  return;
2732 #endif
2733  // Update string of available libraries.
2734  if (!fSharedLibs.IsNull()) {
2735  fSharedLibs.Append(" ");
2736  }
2737  fSharedLibs.Append(filename);
2738 }
2739 
2740 ////////////////////////////////////////////////////////////////////////////////
2741 /// Load a library file in cling's memory.
2742 /// if 'system' is true, the library is never unloaded.
2743 /// Return 0 on success, -1 on failure.
2744 
2745 Int_t TCling::Load(const char* filename, Bool_t system)
2746 {
2747  if (!fAllowLibLoad) {
2748  Error("Load","Trying to load library (%s) from rootcling.",filename);
2749  return -1;
2750  }
2751 
2752  // Used to return 0 on success, 1 on duplicate, -1 on failure, -2 on "fatal".
2754  cling::DynamicLibraryManager* DLM = fInterpreter->getDynamicLibraryManager();
2755  std::string canonLib = DLM->lookupLibrary(filename);
2756  cling::DynamicLibraryManager::LoadLibResult res
2757  = cling::DynamicLibraryManager::kLoadLibNotFound;
2758  if (!canonLib.empty()) {
2759  if (system)
2760  res = DLM->loadLibrary(filename, system);
2761  else {
2762  // For the non system libs, we'd like to be able to unload them.
2763  // FIXME: Here we lose the information about kLoadLibAlreadyLoaded case.
2764  cling::Interpreter::CompilationResult compRes;
2765  cling::MetaProcessor::MaybeRedirectOutputRAII RAII(fMetaProcessor);
2766  fMetaProcessor->process(Form(".L %s", canonLib.c_str()), compRes, /*cling::Value*/0);
2767  if (compRes == cling::Interpreter::kSuccess)
2768  res = cling::DynamicLibraryManager::kLoadLibSuccess;
2769  }
2770  }
2771 
2772  if (res == cling::DynamicLibraryManager::kLoadLibSuccess) {
2774  }
2775  switch (res) {
2776  case cling::DynamicLibraryManager::kLoadLibSuccess: return 0;
2777  case cling::DynamicLibraryManager::kLoadLibAlreadyLoaded: return 1;
2778  default: break;
2779  };
2780  return -1;
2781 }
2782 
2783 ////////////////////////////////////////////////////////////////////////////////
2784 /// Load a macro file in cling's memory.
2785 
2786 void TCling::LoadMacro(const char* filename, EErrorCode* error)
2787 {
2788  ProcessLine(Form(".L %s", filename), error);
2789 }
2790 
2791 ////////////////////////////////////////////////////////////////////////////////
2792 /// Let cling process a command line asynch.
2793 
2795 {
2796  return ProcessLine(line, error);
2797 }
2798 
2799 ////////////////////////////////////////////////////////////////////////////////
2800 /// Let cling process a command line synchronously, i.e we are waiting
2801 /// it will be finished.
2802 
2804 {
2806  if (gApplication) {
2807  if (gApplication->IsCmdThread()) {
2808  return ProcessLine(line, error);
2809  }
2810  return 0;
2811  }
2812  return ProcessLine(line, error);
2813 }
2814 
2815 ////////////////////////////////////////////////////////////////////////////////
2816 /// Directly execute an executable statement (e.g. "func()", "3+5", etc.
2817 /// however not declarations, like "Int_t x;").
2818 
2819 Long_t TCling::Calc(const char* line, EErrorCode* error)
2820 {
2821 #ifdef R__WIN32
2822  // Test on ApplicationImp not being 0 is needed because only at end of
2823  // TApplication ctor the IsLineProcessing flag is set to 0, so before
2824  // we can not use it.
2826  while (gROOT->IsLineProcessing() && !gApplication) {
2827  Warning("Calc", "waiting for cling thread to free");
2828  gSystem->Sleep(500);
2829  }
2830  gROOT->SetLineIsProcessing();
2831  }
2832 #endif // R__WIN32
2834  if (error) {
2835  *error = TInterpreter::kNoError;
2836  }
2837  cling::Value valRef;
2838  cling::Interpreter::CompilationResult cr = fInterpreter->evaluate(line, valRef);
2839  if (cr != cling::Interpreter::kSuccess) {
2840  // Failure in compilation.
2841  if (error) {
2842  // Note: Yes these codes are weird.
2843  *error = TInterpreter::kRecoverable;
2844  }
2845  return 0L;
2846  }
2847  if (!valRef.isValid()) {
2848  // Failure at runtime.
2849  if (error) {
2850  // Note: Yes these codes are weird.
2851  *error = TInterpreter::kDangerous;
2852  }
2853  return 0L;
2854  }
2855 
2856  if (valRef.isVoid()) {
2857  return 0;
2858  }
2859 
2860  RegisterTemporary(valRef);
2861 #ifdef R__WIN32
2863  gROOT->SetLineHasBeenProcessed();
2864  }
2865 #endif // R__WIN32
2866  return valRef.simplisticCastAs<long>();
2867 }
2868 
2869 ////////////////////////////////////////////////////////////////////////////////
2870 /// Set a getline function to call when input is needed.
2871 
2872 void TCling::SetGetline(const char * (*getlineFunc)(const char* prompt),
2873  void (*histaddFunc)(const char* line))
2874 {
2875  // If cling offers a replacement for G__pause(), it would need to
2876  // also offer a way to customize at least the history recording.
2877 
2878 #if defined(R__MUST_REVISIT)
2879 #if R__MUST_REVISIT(6,2)
2880  Warning("SetGetline","Cling should support the equivalent of SetGetlineFunc(getlineFunc, histaddFunc)");
2881 #endif
2882 #endif
2883 }
2884 
2885 ////////////////////////////////////////////////////////////////////////////////
2886 /// Helper function to increase the internal Cling count of transactions
2887 /// that change the AST.
2888 
2889 Bool_t TCling::HandleNewTransaction(const cling::Transaction &T)
2890 {
2892 
2893  if ((std::distance(T.decls_begin(), T.decls_end()) != 1)
2894  || T.deserialized_decls_begin() != T.deserialized_decls_end()
2895  || T.macros_begin() != T.macros_end()
2896  || ((!T.getFirstDecl().isNull()) && ((*T.getFirstDecl().begin()) != T.getWrapperFD()))) {
2898  return true;
2899  }
2900  return false;
2901 }
2902 
2903 ////////////////////////////////////////////////////////////////////////////////
2904 /// Delete object from cling symbol table so it can not be used anymore.
2905 /// cling objects are always on the heap.
2906 
2908 {
2910  // Note that fgSetOfSpecials is supposed to be updated by TClingCallbacks::tryFindROOTSpecialInternal
2911  // (but isn't at the moment).
2912  if (obj->IsOnHeap() && fgSetOfSpecials && !((std::set<TObject*>*)fgSetOfSpecials)->empty()) {
2913  std::set<TObject*>::iterator iSpecial = ((std::set<TObject*>*)fgSetOfSpecials)->find(obj);
2914  if (iSpecial != ((std::set<TObject*>*)fgSetOfSpecials)->end()) {
2915  DeleteGlobal(obj);
2916  ((std::set<TObject*>*)fgSetOfSpecials)->erase(iSpecial);
2917  }
2918  }
2919 }
2920 
2921 ////////////////////////////////////////////////////////////////////////////////
2922 /// Pressing Ctrl+C should forward here. In the case where we have had
2923 /// continuation requested we must reset it.
2924 
2926 {
2927  fMetaProcessor->cancelContinuation();
2928  // Reset the Cling state to the state saved by the last call to
2929  // TCling::SaveContext().
2930 #if defined(R__MUST_REVISIT)
2931 #if R__MUST_REVISIT(6,2)
2933  Warning("Reset","Cling should support the equivalent of scratch_upto(&fDictPos)");
2934 #endif
2935 #endif
2936 }
2937 
2938 ////////////////////////////////////////////////////////////////////////////////
2939 /// Reset the Cling state to its initial state.
2940 
2942 {
2943 #if defined(R__MUST_REVISIT)
2944 #if R__MUST_REVISIT(6,2)
2946  Warning("ResetAll","Cling should support the equivalent of complete reset (unload everything but the startup decls.");
2947 #endif
2948 #endif
2949 }
2950 
2951 ////////////////////////////////////////////////////////////////////////////////
2952 /// Reset in Cling the list of global variables to the state saved by the last
2953 /// call to TCling::SaveGlobalsContext().
2954 ///
2955 /// Note: Right now, all we do is run the global destructors.
2956 
2958 {
2960  // TODO:
2961  // Here we should iterate over the transactions (N-3) and revert.
2962  // N-3 because the first three internal to cling.
2963 
2964  fInterpreter->runAndRemoveStaticDestructors();
2965 }
2966 
2967 ////////////////////////////////////////////////////////////////////////////////
2968 /// Reset the Cling 'user' global objects/variables state to the state saved by the last
2969 /// call to TCling::SaveGlobalsContext().
2970 
2972 {
2973 #if defined(R__MUST_REVISIT)
2974 #if R__MUST_REVISIT(6,2)
2976  Warning("ResetGlobalVar","Cling should support the equivalent of resetglobalvar(obj)");
2977 #endif
2978 #endif
2979 }
2980 
2981 ////////////////////////////////////////////////////////////////////////////////
2982 /// Rewind Cling dictionary to the point where it was before executing
2983 /// the current macro. This function is typically called after SEGV or
2984 /// ctlr-C after doing a longjmp back to the prompt.
2985 
2987 {
2988 #if defined(R__MUST_REVISIT)
2989 #if R__MUST_REVISIT(6,2)
2991  Warning("RewindDictionary","Cling should provide a way to revert transaction similar to rewinddictionary()");
2992 #endif
2993 #endif
2994 }
2995 
2996 ////////////////////////////////////////////////////////////////////////////////
2997 /// Delete obj from Cling symbol table so it cannot be accessed anymore.
2998 /// Returns 1 in case of success and 0 in case object was not in table.
2999 
3001 {
3002 #if defined(R__MUST_REVISIT)
3003 #if R__MUST_REVISIT(6,2)
3005  Warning("DeleteGlobal","Cling should provide the equivalent of deleteglobal(obj), see also DeleteVariable.");
3006 #endif
3007 #endif
3008  return 0;
3009 }
3010 
3011 ////////////////////////////////////////////////////////////////////////////////
3012 /// Undeclare obj called name.
3013 /// Returns 1 in case of success, 0 for failure.
3014 
3016 {
3017 #if defined(R__MUST_REVISIT)
3018 #if R__MUST_REVISIT(6,2)
3019  Warning("DeleteVariable","should do more that just reseting the value to zero");
3020 #endif
3021 #endif
3022 
3024  llvm::StringRef srName(name);
3025  const char* unscopedName = name;
3026  llvm::StringRef::size_type posScope = srName.rfind("::");
3027  const clang::DeclContext* declCtx = 0;
3028  if (posScope != llvm::StringRef::npos) {
3029  const cling::LookupHelper& lh = fInterpreter->getLookupHelper();
3030  const clang::Decl* scopeDecl
3031  = lh.findScope(srName.substr(0, posScope),
3032  cling::LookupHelper::WithDiagnostics);
3033  if (!scopeDecl) {
3034  Error("DeleteVariable", "Cannot find enclosing scope for variable %s",
3035  name);
3036  return 0;
3037  }
3038  declCtx = llvm::dyn_cast<clang::DeclContext>(scopeDecl);
3039  if (!declCtx) {
3040  Error("DeleteVariable",
3041  "Enclosing scope for variable %s is not a declaration context",
3042  name);
3043  return 0;
3044  }
3045  unscopedName += posScope + 2;
3046  }
3047  clang::NamedDecl* nVarDecl
3048  = cling::utils::Lookup::Named(&fInterpreter->getSema(), unscopedName, declCtx);
3049  if (!nVarDecl) {
3050  Error("DeleteVariable", "Unknown variable %s", name);
3051  return 0;
3052  }
3053  clang::VarDecl* varDecl = llvm::dyn_cast<clang::VarDecl>(nVarDecl);
3054  if (!varDecl) {
3055  Error("DeleteVariable", "Entity %s is not a variable", name);
3056  return 0;
3057  }
3058 
3059  clang::QualType qType = varDecl->getType();
3060  const clang::Type* type = qType->getUnqualifiedDesugaredType();
3061  // Cannot set a reference's address to nullptr; the JIT can place it
3062  // into read-only memory (ROOT-7100).
3063  if (type->isPointerType()) {
3064  int** ppInt = (int**)fInterpreter->getAddressOfGlobal(GlobalDecl(varDecl));
3065  // set pointer to invalid.
3066  if (ppInt) *ppInt = 0;
3067  }
3068  return 1;
3069 }
3070 
3071 ////////////////////////////////////////////////////////////////////////////////
3072 /// Save the current Cling state.
3073 
3075 {
3076 #if defined(R__MUST_REVISIT)
3077 #if R__MUST_REVISIT(6,2)
3079  Warning("SaveContext","Cling should provide a way to record a state watermark similar to store_dictposition(&fDictPos)");
3080 #endif
3081 #endif
3082 }
3083 
3084 ////////////////////////////////////////////////////////////////////////////////
3085 /// Save the current Cling state of global objects.
3086 
3088 {
3089 #if defined(R__MUST_REVISIT)
3090 #if R__MUST_REVISIT(6,2)
3092  Warning("SaveGlobalsContext","Cling should provide a way to record a watermark for the list of global variable similar to store_dictposition(&fDictPosGlobals)");
3093 #endif
3094 #endif
3095 }
3096 
3097 ////////////////////////////////////////////////////////////////////////////////
3098 /// No op: see TClingCallbacks (used to update the list of globals)
3099 
3101 {
3102 }
3103 
3104 ////////////////////////////////////////////////////////////////////////////////
3105 /// No op: see TClingCallbacks (used to update the list of global functions)
3106 
3108 {
3109 }
3110 
3111 ////////////////////////////////////////////////////////////////////////////////
3112 /// No op: see TClingCallbacks (used to update the list of types)
3113 
3115 {
3116 }
3117 
3118 ////////////////////////////////////////////////////////////////////////////////
3119 /// Set pointer to the TClingClassInfo in TClass.
3120 /// If 'reload' is true, (attempt to) generate a new ClassInfo even if we
3121 /// already have one.
3122 
3124 {
3126  if (cl->fClassInfo && !reload) {
3127  return;
3128  }
3129  //Remove the decl_id from the DeclIdToTClass map
3130  TClingClassInfo* TClinginfo = (TClingClassInfo*) cl->fClassInfo;
3131  if (TClinginfo) {
3132  TClass::RemoveClassDeclId(TClinginfo->GetDeclId());
3133  }
3134  delete TClinginfo;
3135  cl->fClassInfo = 0;
3136  std::string name(cl->GetName());
3137  TClingClassInfo* info = new TClingClassInfo(fInterpreter, name.c_str());
3138  if (!info->IsValid()) {
3139  if (cl->fState != TClass::kHasTClassInit) {
3140  if (cl->fStreamerInfo->GetEntries() != 0) {
3141  cl->fState = TClass::kEmulated;
3142  } else {
3144  }
3145  }
3146  delete info;
3147  return;
3148  }
3149  cl->fClassInfo = (ClassInfo_t*)info; // Note: We are transferring ownership here.
3150  // In case a class contains an external enum, the enum will be seen as a
3151  // class. We must detect this special case and make the class a Zombie.
3152  // Here we assume that a class has at least one method.
3153  // We can NOT call TClass::Property from here, because this method
3154  // assumes that the TClass is well formed to do a lot of information
3155  // caching. The method SetClassInfo (i.e. here) is usually called during
3156  // the building phase of the TClass, hence it is NOT well formed yet.
3157  Bool_t zombieCandidate = kFALSE;
3158  if (
3159  info->IsValid() &&
3160  !(info->Property() & (kIsClass | kIsStruct | kIsNamespace))
3161  ) {
3162  zombieCandidate = kTRUE;
3163  }
3164  if (!info->IsLoaded()) {
3165  if (info->Property() & (kIsNamespace)) {
3166  // Namespaces can have info but no corresponding CINT dictionary
3167  // because they are auto-created if one of their contained
3168  // classes has a dictionary.
3169  zombieCandidate = kTRUE;
3170  }
3171  // this happens when no dictionary is available
3172  delete info;
3173  cl->fClassInfo = 0;
3174  }
3175  if (zombieCandidate && !cl->GetCollectionType()) {
3176  cl->MakeZombie();
3177  }
3178  // If we reach here, the info was valid (See early returns).
3179  if (cl->fState != TClass::kHasTClassInit) {
3180  if (cl->fClassInfo) {
3183  } else {
3184 // if (TClassEdit::IsSTLCont(cl->GetName()) {
3185 // There will be an emulated collection proxy, is that the same?
3186 // cl->fState = TClass::kEmulated;
3187 // } else {
3188  if (cl->fStreamerInfo->GetEntries() != 0) {
3189  cl->fState = TClass::kEmulated;
3190  } else {
3192  }
3193 // }
3194  }
3195  }
3196  if (cl->fClassInfo) {
3197  TClass::AddClassToDeclIdMap(((TClingClassInfo*)cl->fClassInfo)->GetDeclId(), cl);
3198  }
3199 }
3200 
3201 ////////////////////////////////////////////////////////////////////////////////
3202 /// Checks if an entity with the specified name is defined in Cling.
3203 /// Returns kFALSE if the entity is not defined.
3204 /// By default, structs, namespaces, classes, enums and unions are looked for.
3205 /// If the flag isClassOrNamespaceOnly is true, classes, structs and
3206 /// namespaces only are considered. I.e. if the name is an enum or a union,
3207 /// the returned value is false.
3208 ///
3209 /// In the case where the class is not loaded and belongs to a namespace
3210 /// or is nested, looking for the full class name is outputting a lots of
3211 /// (expected) error messages. Currently the only way to avoid this is to
3212 /// specifically check that each level of nesting is already loaded.
3213 /// In case of templates the idea is that everything between the outer
3214 /// '<' and '>' has to be skipped, e.g.: aap<pippo<noot>::klaas>::a_class
3215 
3216 Bool_t TCling::CheckClassInfo(const char* name, Bool_t autoload, Bool_t isClassOrNamespaceOnly /* = kFALSE*/ )
3217 {
3219  static const char *anonEnum = "anonymous enum ";
3220  static const int cmplen = strlen(anonEnum);
3221 
3222  if (0 == strncmp(name,anonEnum,cmplen)) {
3223  return kFALSE;
3224  }
3225 
3226  // Avoid the double search below in case the name is a fundamental type
3227  // or typedef to a fundamental type.
3228  THashTable *typeTable = dynamic_cast<THashTable*>( gROOT->GetListOfTypes() );
3229  TDataType *fundType = (TDataType *)typeTable->THashTable::FindObject( name );
3230 
3231  if (fundType && fundType->GetType() < TVirtualStreamerInfo::kObject
3232  && fundType->GetType() > 0) {
3233  // Fundamental type, no a class.
3234  return kFALSE;
3235  }
3236 
3237  // Migrated from within TClass::GetClass
3238  // If we want to know if a class or a namespace with this name exists in the
3239  // interpreter and this is an enum in the type system, before or after loading
3240  // according to the autoload function argument, return false.
3241  if (isClassOrNamespaceOnly &&
3242  TEnum::GetEnum(name, autoload ? TEnum::kAutoload : TEnum::kNone)) return false;
3243 
3244  const char *classname = name;
3245 
3246  int storeAutoload = SetClassAutoloading(autoload);
3247 
3248  // First we want to check whether the decl exist, but _without_
3249  // generating any template instantiation. However, the lookup
3250  // still will create a forward declaration of the class template instance
3251  // if it exist. In this case, the return value of findScope will still
3252  // be zero but the type will be initialized.
3253  // Note in the corresponding code in ROOT 5, CINT was not instantiating
3254  // this forward declaration.
3255  const cling::LookupHelper& lh = fInterpreter->getLookupHelper();
3256  const clang::Type *type = 0;
3257  const clang::Decl *decl
3258  = lh.findScope(classname,
3259  gDebug > 5 ? cling::LookupHelper::WithDiagnostics
3260  : cling::LookupHelper::NoDiagnostics,
3261  &type, /* intantiateTemplate= */ false );
3262  if (!decl) {
3263  std::string buf = TClassEdit::InsertStd(classname);
3264  decl = lh.findScope(buf,
3265  gDebug > 5 ? cling::LookupHelper::WithDiagnostics
3266  : cling::LookupHelper::NoDiagnostics,
3267  &type,false);
3268  }
3269 
3270  if (type) {
3271  // If decl==0 and the type is valid, then we have a forward declaration.
3272  if (!decl) {
3273  // If we have a forward declaration for a class template instantiation,
3274  // we want to ignore it if it was produced/induced by the call to
3275  // findScope, however we can not distinguish those from the
3276  // instantiation induce by 'soft' use (and thus also induce by the
3277  // same underlying code paths)
3278  // ['soft' use = use not requiring a complete definition]
3279  // So to reduce the amount of disruption to the existing code we
3280  // would just ignore those for STL collection, for which we really
3281  // need to have the compiled collection proxy (and thus the TClass
3282  // bootstrap).
3283  clang::ClassTemplateSpecializationDecl *tmpltDecl =
3284  llvm::dyn_cast_or_null<clang::ClassTemplateSpecializationDecl>
3285  (type->getAsCXXRecordDecl());
3286  if (tmpltDecl && !tmpltDecl->getPointOfInstantiation().isValid()) {
3287  // Since the point of instantiation is invalid, we 'guess' that
3288  // the 'instantiation' of the forwarded type appended in
3289  // findscope.
3290  if (ROOT::TMetaUtils::IsSTLCont(*tmpltDecl)) {
3291  // For STL Collection we return false.
3292  SetClassAutoloading(storeAutoload);
3293  return kFALSE;
3294  }
3295  }
3296  }
3297  TClingClassInfo tci(fInterpreter, *type);
3298  if (!tci.IsValid()) {
3299  SetClassAutoloading(storeAutoload);
3300  return kFALSE;
3301  }
3302  auto propertiesMask = isClassOrNamespaceOnly ? kIsClass | kIsStruct | kIsNamespace :
3304 
3305  if (tci.Property() & propertiesMask) {
3306  // We are now sure that the entry is not in fact an autoload entry.
3307  SetClassAutoloading(storeAutoload);
3308  return kTRUE;
3309  }
3310  }
3311 
3312  SetClassAutoloading(storeAutoload);
3313  return (decl);
3314 
3315  // Setting up iterator part of TClingTypedefInfo is too slow.
3316  // Copy the lookup code instead:
3317  /*
3318  TClingTypedefInfo t(fInterpreter, name);
3319  if (t.IsValid() && !(t.Property() & kIsFundamental)) {
3320  delete[] classname;
3321  SetClassAutoloading(storeAutoload);
3322  return kTRUE;
3323  }
3324  */
3325 
3326 // const clang::Decl *decl = lh.findScope(name);
3327 // if (!decl) {
3328 // std::string buf = TClassEdit::InsertStd(name);
3329 // decl = lh.findScope(buf);
3330 // }
3331 
3332 // SetClassAutoloading(storeAutoload);
3333 // return (decl);
3334 }
3335 
3336 ////////////////////////////////////////////////////////////////////////////////
3337 /// Return true if there is a class template by the given name ...
3338 
3340 {
3341  const cling::LookupHelper& lh = fInterpreter->getLookupHelper();
3342  const clang::Decl *decl
3343  = lh.findClassTemplate(name,
3344  gDebug > 5 ? cling::LookupHelper::WithDiagnostics
3345  : cling::LookupHelper::NoDiagnostics);
3346  if (!decl) {
3347  std::string strname = "std::";
3348  strname += name;
3349  decl = lh.findClassTemplate(strname,
3350  gDebug > 5 ? cling::LookupHelper::WithDiagnostics
3351  : cling::LookupHelper::NoDiagnostics);
3352  }
3353  return 0 != decl;
3354 }
3355 
3356 ////////////////////////////////////////////////////////////////////////////////
3357 /// Create list of pointers to base class(es) for TClass cl.
3358 
3360 {
3362  if (cl->fBase) {
3363  return;
3364  }
3366  if (!tci) return;
3368  TList *listOfBase = new TList;
3369  while (t.Next()) {
3370  // if name cannot be obtained no use to put in list
3371  if (t.IsValid() && t.Name()) {
3373  listOfBase->Add(new TBaseClass((BaseClassInfo_t *)a, cl));
3374  }
3375  }
3376  // Now that is complete, publish it.
3377  cl->fBase = listOfBase;
3378 }
3379 
3380 ////////////////////////////////////////////////////////////////////////////////
3381 /// Create list of pointers to enums for TClass cl.
3382 
3383 void TCling::LoadEnums(TListOfEnums& enumList) const
3384 {
3386 
3387  const Decl * D;
3388  TClass* cl = enumList.GetClass();
3389  if (cl) {
3390  D = ((TClingClassInfo*)cl->GetClassInfo())->GetDecl();
3391  }
3392  else {
3393  D = fInterpreter->getCI()->getASTContext().getTranslationUnitDecl();
3394  }
3395  // Iterate on the decl of the class and get the enums.
3396  if (const clang::DeclContext* DC = dyn_cast<clang::DeclContext>(D)) {
3397  cling::Interpreter::PushTransactionRAII deserRAII(fInterpreter);
3398  // Collect all contexts of the namespace.
3399  llvm::SmallVector< DeclContext *, 4> allDeclContexts;
3400  const_cast< clang::DeclContext *>(DC)->collectAllContexts(allDeclContexts);
3401  for (llvm::SmallVector<DeclContext*, 4>::iterator declIter = allDeclContexts.begin(), declEnd = allDeclContexts.end();
3402  declIter != declEnd; ++declIter) {
3403  // Iterate on all decls for each context.
3404  for (clang::DeclContext::decl_iterator DI = (*declIter)->decls_begin(),
3405  DE = (*declIter)->decls_end(); DI != DE; ++DI) {
3406  if (const clang::EnumDecl* ED = dyn_cast<clang::EnumDecl>(*DI)) {
3407  // Get name of the enum type.
3408  std::string buf;
3409  PrintingPolicy Policy(ED->getASTContext().getPrintingPolicy());
3410  llvm::raw_string_ostream stream(buf);
3411  ED->getNameForDiagnostic(stream, Policy, /*Qualified=*/false);
3412  stream.flush();
3413  // If the enum is unnamed we do not add it to the list of enums i.e unusable.
3414  if (!buf.empty()) {
3415  const char* name = buf.c_str();
3416  // Add the enum to the list of loaded enums.
3417  enumList.Get(ED, name);
3418  }
3419  }
3420  }
3421  }
3422  }
3423 }
3424 
3425 ////////////////////////////////////////////////////////////////////////////////
3426 /// Create list of pointers to function templates for TClass cl.
3427 
3429 {
3431 
3432  const Decl * D;
3433  TListOfFunctionTemplates* funcTempList;
3434  if (cl) {
3435  D = ((TClingClassInfo*)cl->GetClassInfo())->GetDecl();
3436  funcTempList = (TListOfFunctionTemplates*)cl->GetListOfFunctionTemplates(false);
3437  }
3438  else {
3439  D = fInterpreter->getCI()->getASTContext().getTranslationUnitDecl();
3440  funcTempList = (TListOfFunctionTemplates*)gROOT->GetListOfFunctionTemplates();
3441  }
3442  // Iterate on the decl of the class and get the enums.
3443  if (const clang::DeclContext* DC = dyn_cast<clang::DeclContext>(D)) {
3444  cling::Interpreter::PushTransactionRAII deserRAII(fInterpreter);
3445  // Collect all contexts of the namespace.
3446  llvm::SmallVector< DeclContext *, 4> allDeclContexts;
3447  const_cast< clang::DeclContext *>(DC)->collectAllContexts(allDeclContexts);
3448  for (llvm::SmallVector<DeclContext*, 4>::iterator declIter = allDeclContexts.begin(),
3449  declEnd = allDeclContexts.end(); declIter != declEnd; ++declIter) {
3450  // Iterate on all decls for each context.
3451  for (clang::DeclContext::decl_iterator DI = (*declIter)->decls_begin(),
3452  DE = (*declIter)->decls_end(); DI != DE; ++DI) {
3453  if (const clang::FunctionTemplateDecl* FTD = dyn_cast<clang::FunctionTemplateDecl>(*DI)) {
3454  funcTempList->Get(FTD);
3455  }
3456  }
3457  }
3458  }
3459 }
3460 ////////////////////////////////////////////////////////////////////////////////
3461 /// Create list of pointers to data members for TClass cl.
3462 /// This is now a nop. The creation and updating is handled in
3463 /// TListOfDataMembers.
3464 
3466 {
3467 }
3468 
3469 ////////////////////////////////////////////////////////////////////////////////
3470 /// Create list of pointers to methods for TClass cl.
3471 /// This is now a nop. The creation and updating is handled in
3472 /// TListOfFunctions.
3473 
3475 {
3476 }
3477 
3478 ////////////////////////////////////////////////////////////////////////////////
3479 /// Update the list of pointers to method for TClass cl
3480 /// This is now a nop. The creation and updating is handled in
3481 /// TListOfFunctions.
3482 
3484 {
3485 }
3486 
3487 ////////////////////////////////////////////////////////////////////////////////
3488 /// Update the list of pointers to data members for TClass cl
3489 /// This is now a nop. The creation and updating is handled in
3490 /// TListOfDataMembers.
3491 
3493 {
3494 }
3495 
3496 ////////////////////////////////////////////////////////////////////////////////
3497 /// Create list of pointers to method arguments for TMethod m.
3498 
3500 {
3502  if (m->fMethodArgs) {
3503  return;
3504  }
3505  TList *arglist = new TList;
3507  while (t.Next()) {
3508  if (t.IsValid()) {
3510  arglist->Add(new TMethodArg((MethodArgInfo_t*)a, m));
3511  }
3512  }
3513  m->fMethodArgs = arglist;
3514 }
3515 
3516 
3517 ////////////////////////////////////////////////////////////////////////////////
3518 /// Generate a TClass for the given class.
3519 /// Since the caller has already check the ClassInfo, let it give use the
3520 /// result (via the value of emulation) rather than recalculate it.
3521 
3522 TClass *TCling::GenerateTClass(const char *classname, Bool_t emulation, Bool_t silent /* = kFALSE */)
3523 {
3524 // For now the following line would lead to the (unwanted) instantiation
3525 // of class template. This could/would need to be resurrected only if
3526 // we re-introduce so sort of automatic instantiation. However this would
3527 // have to include carefull look at the template parameter to avoid
3528 // creating instance we can not really use (if the parameter are only forward
3529 // declaration or do not have all the necessary interfaces).
3530 
3531  // TClingClassInfo tci(fInterpreter, classname);
3532  // if (1 || !tci.IsValid()) {
3533 
3534  Version_t version = 1;
3535  if (TClassEdit::IsSTLCont(classname)) {
3536  version = TClass::GetClass("TVirtualStreamerInfo")->GetClassVersion();
3537  }
3538  TClass *cl = new TClass(classname, version, silent);
3539  if (emulation) {
3541  } else {
3542  // Set the class version if the class is versioned.
3543  // Note that we cannot just call CLASS::Class_Version() as we might not have
3544  // an execution engine (when invoked from rootcling).
3545 
3546  // Do not call cl->GetClassVersion(), it has side effects!
3547  Version_t oldvers = cl->fClassVersion;
3548  if (oldvers == version && cl->GetClassInfo()) {
3549  // We have a version and it might need an update.
3550  Version_t newvers = oldvers;
3552  if (llvm::isa<clang::NamespaceDecl>(cli->GetDecl())) {
3553  // Namespaces don't have class versions.
3554  return cl;
3555  }
3556  TClingMethodInfo mi = cli->GetMethod("Class_Version", "", 0 /*poffset*/,
3559  if (!mi.IsValid()) {
3560  if (cl->TestBit(TClass::kIsTObject)) {
3561  Error("GenerateTClass",
3562  "Cannot find %s::Class_Version()! Class version might be wrong.",
3563  cl->GetName());
3564  }
3565  return cl;
3566  }
3567  newvers = ROOT::TMetaUtils::GetClassVersion(llvm::dyn_cast<clang::RecordDecl>(cli->GetDecl()),
3568  *fInterpreter);
3569  if (newvers == -1) {
3570  // Didn't manage to determine the class version from the AST.
3571  // Use runtime instead.
3572  if ((mi.Property() & kIsStatic)
3573  && !fInterpreter->isInSyntaxOnlyMode()) {
3574  // This better be a static function.
3576  callfunc.SetFunc(&mi);
3577  newvers = callfunc.ExecInt(0);
3578  } else {
3579  Error("GenerateTClass",
3580  "Cannot invoke %s::Class_Version()! Class version might be wrong.",
3581  cl->GetName());
3582  }
3583  }
3584  if (newvers != oldvers) {
3585  cl->fClassVersion = newvers;
3586  cl->fStreamerInfo->Expand(newvers + 2 + 10);
3587  }
3588  }
3589  }
3590 
3591  return cl;
3592 
3593 // } else {
3594 // return GenerateTClass(&tci,silent);
3595 // }
3596 }
3597 
3598 #if 0
3599 ////////////////////////////////////////////////////////////////////////////////
3600 
3601 static void GenerateTClass_GatherInnerIncludes(cling::Interpreter *interp, TString &includes,TClingClassInfo *info)
3602 {
3603  includes += info->FileName();
3604 
3605  const clang::ClassTemplateSpecializationDecl *templateCl
3606  = llvm::dyn_cast<clang::ClassTemplateSpecializationDecl>(info->GetDecl());
3607  if (templateCl) {
3608  for(unsigned int i=0; i < templateCl->getTemplateArgs().size(); ++i) {
3609  const clang::TemplateArgument &arg( templateCl->getTemplateArgs().get(i) );
3610  if (arg.getKind() == clang::TemplateArgument::Type) {
3611  const clang::Type *uType = ROOT::TMetaUtils::GetUnderlyingType( arg.getAsType() );
3612 
3613  if (!uType->isFundamentalType() && !uType->isEnumeralType()) {
3614  // We really need a header file.
3615  const clang::CXXRecordDecl *argdecl = uType->getAsCXXRecordDecl();
3616  if (argdecl) {
3617  includes += ";";
3618  TClingClassInfo subinfo(interp,*(argdecl->getASTContext().getRecordType(argdecl).getTypePtr()));
3619  GenerateTClass_GatherInnerIncludes(interp, includes, &subinfo);
3620  } else {
3621  std::string Result;
3622  llvm::raw_string_ostream OS(Result);
3623  arg.print(argdecl->getASTContext().getPrintingPolicy(),OS);
3624  Warning("TCling::GenerateTClass","Missing header file for %s",OS.str().c_str());
3625  }
3626  }
3627  }
3628  }
3629  }
3630 }
3631 #endif
3632 
3633 ////////////////////////////////////////////////////////////////////////////////
3634 /// Generate a TClass for the given class.
3635 
3636 TClass *TCling::GenerateTClass(ClassInfo_t *classinfo, Bool_t silent /* = kFALSE */)
3637 {
3638  TClingClassInfo *info = (TClingClassInfo*)classinfo;
3639  if (!info || !info->IsValid()) {
3640  Fatal("GenerateTClass","Requires a valid ClassInfo object");
3641  return 0;
3642  }
3643  // We are in the case where we have AST nodes for this class.
3644  TClass *cl = 0;
3645  std::string classname;
3646  info->FullName(classname,*fNormalizedCtxt); // Could we use Name()?
3647  if (TClassEdit::IsSTLCont(classname.c_str())) {
3648 #if 0
3649  Info("GenerateTClass","Will (try to) generate the compiled TClass for %s.",classname.c_str());
3650  // We need to build up the list of required headers, by
3651  // looking at each template arguments.
3652  TString includes;
3653  GenerateTClass_GatherInnerIncludes(fInterpreter,includes,info);
3654 
3655  if (0 == GenerateDictionary(classname.c_str(),includes)) {
3656  // 0 means success.
3657  cl = TClass::LoadClass(classnam.c_str(), silent);
3658  if (cl == 0) {
3659  Error("GenerateTClass","Even though the dictionary generation for %s seemed successful we can't find the TClass bootstrap!",classname.c_str());
3660  }
3661  }
3662 #endif
3663  if (cl == 0) {
3664  int version = TClass::GetClass("TVirtualStreamerInfo")->GetClassVersion();
3665  cl = new TClass(classinfo, version, 0, 0, -1, -1, silent);
3667  }
3668  } else {
3669  // For regular class, just create a TClass on the fly ...
3670  // Not quite useful yet, but that what CINT used to do anyway.
3671  cl = new TClass(classinfo, 1, 0, 0, -1, -1, silent);
3672  }
3673  // Add the new TClass to the map of declid and TClass*.
3674  if (cl) {
3676  }
3677  return cl;
3678 }
3679 
3680 ////////////////////////////////////////////////////////////////////////////////
3681 /// Generate the dictionary for the C++ classes listed in the first
3682 /// argument (in a semi-colon separated list).
3683 /// 'includes' contains a semi-colon separated list of file to
3684 /// #include in the dictionary.
3685 /// For example:
3686 /// ~~~ {.cpp}
3687 /// gInterpreter->GenerateDictionary("vector<vector<float> >;list<vector<float> >","list;vector");
3688 /// ~~~
3689 /// or
3690 /// ~~~ {.cpp}
3691 /// gInterpreter->GenerateDictionary("myclass","myclass.h;myhelper.h");
3692 /// ~~~
3693 
3694 Int_t TCling::GenerateDictionary(const char* classes, const char* includes /* = 0 */, const char* /* options = 0 */)
3695 {
3696  if (classes == 0 || classes[0] == 0) {
3697  return 0;
3698  }
3699  // Split the input list
3700  std::vector<std::string> listClasses;
3701  for (
3702  const char* current = classes, *prev = classes;
3703  *current != 0;
3704  ++current
3705  ) {
3706  if (*current == ';') {
3707  listClasses.push_back(std::string(prev, current - prev));
3708  prev = current + 1;
3709  }
3710  else if (*(current + 1) == 0) {
3711  listClasses.push_back(std::string(prev, current + 1 - prev));
3712  prev = current + 1;
3713  }
3714  }
3715  std::vector<std::string> listIncludes;
3716  for (
3717  const char* current = includes, *prev = includes;
3718  *current != 0;
3719  ++current
3720  ) {
3721  if (*current == ';') {
3722  listIncludes.push_back(std::string(prev, current - prev));
3723  prev = current + 1;
3724  }
3725  else if (*(current + 1) == 0) {
3726  listIncludes.push_back(std::string(prev, current + 1 - prev));
3727  prev = current + 1;
3728  }
3729  }
3730  // Generate the temporary dictionary file
3731  return TCling_GenerateDictionary(listClasses, listIncludes,
3732  std::vector<std::string>(), std::vector<std::string>());
3733 }
3734 
3735 ////////////////////////////////////////////////////////////////////////////////
3736 /// Return pointer to cling Decl of global/static variable that is located
3737 /// at the address given by addr.
3738 
3739 TInterpreter::DeclId_t TCling::GetDataMember(ClassInfo_t *opaque_cl, const char *name) const
3740 {
3742  DeclId_t d;
3743  TClingClassInfo *cl = (TClingClassInfo*)opaque_cl;
3744 
3745  if (cl) {
3746  d = cl->GetDataMember(name);
3747  // We check if the decl of the data member has an annotation which indicates
3748  // an ioname.
3749  // In case this is true, if the name requested is not the ioname, we
3750  // return 0, as if the member did not exist. In some sense we override
3751  // the information in the TClassInfo instance, isolating the typesystem in
3752  // TClass from the one in the AST.
3753  if (const ValueDecl* decl = (const ValueDecl*) d){
3754  std::string ioName;
3755  bool hasIoName = ROOT::TMetaUtils::ExtractAttrPropertyFromName(*decl,"ioname",ioName);
3756  if (hasIoName && ioName != name) return 0;
3757  }
3758  }
3759  else {
3761  d = gcl.GetDataMember(name);
3762  }
3763  return d;
3764 }
3765 
3766 ////////////////////////////////////////////////////////////////////////////////
3767 /// Return pointer to cling Decl of global/static variable that is located
3768 /// at the address given by addr.
3769 
3771 {
3773 
3774  const clang::Decl* possibleEnum = 0;
3775  // FInd the context of the decl.
3776  if (cl) {
3778  if (cci) {
3779  const clang::DeclContext* dc = 0;
3780  if (const clang::Decl* D = cci->GetDecl()) {
3781  if (!(dc = dyn_cast<clang::NamespaceDecl>(D))) {
3782  dc = dyn_cast<clang::RecordDecl>(D);
3783  }
3784  }
3785  if (dc) {
3786  // If it is a data member enum.
3787  possibleEnum = cling::utils::Lookup::Named(&fInterpreter->getSema(), name, dc);
3788  } else {
3789  Error("TCling::GetEnum", "DeclContext not found for %s .\n", name);
3790  }
3791  }
3792  } else {
3793  // If it is a global enum.
3794  possibleEnum = cling::utils::Lookup::Named(&fInterpreter->getSema(), name);
3795  }
3796  if (possibleEnum && (possibleEnum != (clang::Decl*)-1)
3797  && isa<clang::EnumDecl>(possibleEnum)) {
3798  return possibleEnum;
3799  }
3800  return 0;
3801 }
3802 
3803 ////////////////////////////////////////////////////////////////////////////////
3804 /// Return pointer to cling DeclId for a global value
3805 
3806 TInterpreter::DeclId_t TCling::GetDeclId( const llvm::GlobalValue *gv ) const
3807 {
3808  if (!gv) return 0;
3809 
3810  llvm::StringRef mangled_name = gv->getName();
3811 
3812  int err = 0;
3813  char* demangled_name_c = TClassEdit::DemangleName(mangled_name.str().c_str(), err);
3814  if (err) {
3815  if (err == -2) {
3816  // It might simply be an unmangled global name.
3817  DeclId_t d;
3819  d = gcl.GetDataMember(mangled_name.str().c_str());
3820  return d;
3821  }
3822  return 0;
3823  }
3824 
3825  std::string scopename(demangled_name_c);
3826  free(demangled_name_c);
3827 
3828  //
3829  // Separate out the class or namespace part of the
3830  // function name.
3831  //
3832  std::string dataname;
3833 
3834  if (!strncmp(scopename.c_str(), "typeinfo for ", sizeof("typeinfo for ")-1)) {
3835  scopename.erase(0, sizeof("typeinfo for ")-1);
3836  } if (!strncmp(scopename.c_str(), "vtable for ", sizeof("vtable for ")-1)) {
3837  scopename.erase(0, sizeof("vtable for ")-1);
3838  } else {
3839  // See if it is a function
3840  std::string::size_type pos = scopename.rfind('(');
3841  if (pos != std::string::npos) {
3842  return 0;
3843  }
3844  // Separate the scope and member name
3845  pos = scopename.rfind(':');
3846  if (pos != std::string::npos) {
3847  if ((pos != 0) && (scopename[pos-1] == ':')) {
3848  dataname = scopename.substr(pos+1);
3849  scopename.erase(pos-1);
3850  }
3851  } else {
3852  scopename.clear();
3853  dataname = scopename;
3854  }
3855  }
3856  //fprintf(stderr, "name: '%s'\n", name.c_str());
3857  // Now we have the class or namespace name, so do the lookup.
3858 
3859 
3860  DeclId_t d;
3861  if (scopename.size()) {
3862  TClingClassInfo cl(fInterpreter,scopename.c_str());
3863  d = cl.GetDataMember(dataname.c_str());
3864  }
3865  else {
3867  d = gcl.GetDataMember(dataname.c_str());
3868  }
3869  return d;
3870 }
3871 
3872 ////////////////////////////////////////////////////////////////////////////////
3873 /// NOT IMPLEMENTED.
3874 
3876 {
3877  Error("GetDataMemberWithValue()", "not implemented");
3878  return 0;
3879 }
3880 
3881 ////////////////////////////////////////////////////////////////////////////////
3882 /// Return pointer to cling DeclId for a data member with a given name.
3883 
3885 {
3886  // NOT IMPLEMENTED.
3887  Error("GetDataMemberAtAddr()", "not implemented");
3888  return 0;
3889 }
3890 
3891 ////////////////////////////////////////////////////////////////////////////////
3892 /// Return the cling mangled name for a method of a class with parameters
3893 /// params (params is a string of actual arguments, not formal ones). If the
3894 /// class is 0 the global function list will be searched.
3895 
3896 TString TCling::GetMangledName(TClass* cl, const char* method,
3897  const char* params, Bool_t objectIsConst /* = kFALSE */)
3898 {
3901  if (cl) {
3902  Long_t offset;
3903  func.SetFunc((TClingClassInfo*)cl->GetClassInfo(), method, params, objectIsConst,
3904  &offset);
3905  }
3906  else {
3908  Long_t offset;
3909  func.SetFunc(&gcl, method, params, &offset);
3910  }
3912  if (!mi) return "";
3913  TString mangled_name( mi->GetMangledName() );
3914  delete mi;
3915  return mangled_name;
3916 }
3917 
3918 ////////////////////////////////////////////////////////////////////////////////
3919 /// Return the cling mangled name for a method of a class with a certain
3920 /// prototype, i.e. "char*,int,float". If the class is 0 the global function
3921 /// list will be searched.
3922 
3924  const char* proto, Bool_t objectIsConst /* = kFALSE */,
3925  EFunctionMatchMode mode /* = kConversionMatch */)
3926 {
3928  if (cl) {
3929  return ((TClingClassInfo*)cl->GetClassInfo())->
3930  GetMethod(method, proto, objectIsConst, 0 /*poffset*/, mode).GetMangledName();
3931  }
3933  return gcl.GetMethod(method, proto, objectIsConst, 0 /*poffset*/, mode).GetMangledName();
3934 }
3935 
3936 ////////////////////////////////////////////////////////////////////////////////
3937 /// Return pointer to cling interface function for a method of a class with
3938 /// parameters params (params is a string of actual arguments, not formal
3939 /// ones). If the class is 0 the global function list will be searched.
3940 
3941 void* TCling::GetInterfaceMethod(TClass* cl, const char* method,
3942  const char* params, Bool_t objectIsConst /* = kFALSE */)
3943 {
3946  if (cl) {
3947  Long_t offset;
3948  func.SetFunc((TClingClassInfo*)cl->GetClassInfo(), method, params, objectIsConst,
3949  &offset);
3950  }
3951  else {
3953  Long_t offset;
3954  func.SetFunc(&gcl, method, params, &offset);
3955  }
3956  return (void*) func.InterfaceMethod();
3957 }
3958 
3959 ////////////////////////////////////////////////////////////////////////////////
3960 /// Return pointer to cling interface function for a method of a class with
3961 /// a certain name.
3962 
3963 TInterpreter::DeclId_t TCling::GetFunction(ClassInfo_t *opaque_cl, const char* method)
3964 {
3966  DeclId_t f;
3967  TClingClassInfo *cl = (TClingClassInfo*)opaque_cl;
3968  if (cl) {
3969  f = cl->GetMethod(method).GetDeclId();
3970  }
3971  else {
3973  f = gcl.GetMethod(method).GetDeclId();
3974  }
3975  return f;
3976 
3977 }
3978 
3979 ////////////////////////////////////////////////////////////////////////////////
3980 /// Insert overloads of name in cl to res.
3981 
3982 void TCling::GetFunctionOverloads(ClassInfo_t *cl, const char *funcname,
3983  std::vector<DeclId_t>& res) const
3984 {
3985  clang::Sema& S = fInterpreter->getSema();
3986  const clang::Decl* CtxDecl
3987  = cl ? (const clang::Decl*)((TClingClassInfo*)cl)->GetDeclId():
3988  S.Context.getTranslationUnitDecl();
3989  const clang::DeclContext*
3990  DeclCtx = llvm::dyn_cast<const clang::RecordDecl>(CtxDecl);
3991  if (!DeclCtx)
3992  DeclCtx = dyn_cast<clang::NamespaceDecl>(CtxDecl);
3993  if (!DeclCtx) return;
3994  clang::DeclarationName DName
3995  = &S.Context.Idents.get(funcname);
3996  clang::LookupResult R(S, DName, clang::SourceLocation(),
3997  Sema::LookupOrdinaryName, clang::Sema::ForRedeclaration);
3998  S.LookupQualifiedName(R, const_cast<DeclContext*>(DeclCtx));
3999  if (R.empty()) return;
4000  R.resolveKind();
4001  res.reserve(res.size() + (R.end() - R.begin()));
4002  for (clang::LookupResult::iterator IR = R.begin(), ER = R.end();
4003  IR != ER; ++IR) {
4004  if (const clang::FunctionDecl* FD
4005  = llvm::dyn_cast<const clang::FunctionDecl>(*IR)) {
4006  if (!FD->getDescribedFunctionTemplate()) {
4007  res.push_back(FD);
4008  }
4009  }
4010  }
4011 }
4012 
4013 ////////////////////////////////////////////////////////////////////////////////
4014 /// Return pointer to cling interface function for a method of a class with
4015 /// a certain prototype, i.e. "char*,int,float". If the class is 0 the global
4016 /// function list will be searched.
4017 
4018 void* TCling::GetInterfaceMethodWithPrototype(TClass* cl, const char* method,
4019  const char* proto,
4020  Bool_t objectIsConst /* = kFALSE */,
4021  EFunctionMatchMode mode /* = kConversionMatch */)
4022 {
4024  void* f;
4025  if (cl) {
4026  f = ((TClingClassInfo*)cl->GetClassInfo())->
4027  GetMethod(method, proto, objectIsConst, 0 /*poffset*/, mode).InterfaceMethod(*fNormalizedCtxt);
4028  }
4029  else {
4031  f = gcl.GetMethod(method, proto, objectIsConst, 0 /*poffset*/, mode).InterfaceMethod(*fNormalizedCtxt);
4032  }
4033  return f;
4034 }
4035 
4036 ////////////////////////////////////////////////////////////////////////////////
4037 /// Return pointer to cling DeclId for a method of a class with
4038 /// a certain prototype, i.e. "char*,int,float". If the class is 0 the global
4039 /// function list will be searched.
4040 
4041 TInterpreter::DeclId_t TCling::GetFunctionWithValues(ClassInfo_t *opaque_cl, const char* method,
4042  const char* params,
4043  Bool_t objectIsConst /* = kFALSE */)
4044 {
4046  DeclId_t f;
4047  TClingClassInfo *cl = (TClingClassInfo*)opaque_cl;
4048  if (cl) {
4049  f = cl->GetMethodWithArgs(method, params, objectIsConst, 0 /*poffset*/).GetDeclId();
4050  }
4051  else {
4053  f = gcl.GetMethod(method, params, objectIsConst, 0 /*poffset*/).GetDeclId();
4054  }
4055  return f;
4056 }
4057 
4058 ////////////////////////////////////////////////////////////////////////////////
4059 /// Return pointer to cling interface function for a method of a class with
4060 /// a certain prototype, i.e. "char*,int,float". If the class is 0 the global
4061 /// function list will be searched.
4062 
4063 TInterpreter::DeclId_t TCling::GetFunctionWithPrototype(ClassInfo_t *opaque_cl, const char* method,
4064  const char* proto,
4065  Bool_t objectIsConst /* = kFALSE */,
4066  EFunctionMatchMode mode /* = kConversionMatch */)
4067 {
4069  DeclId_t f;
4070  TClingClassInfo *cl = (TClingClassInfo*)opaque_cl;
4071  if (cl) {
4072  f = cl->GetMethod(method, proto, objectIsConst, 0 /*poffset*/, mode).GetDeclId();
4073  }
4074  else {
4076  f = gcl.GetMethod(method, proto, objectIsConst, 0 /*poffset*/, mode).GetDeclId();
4077  }
4078  return f;
4079 }
4080 
4081 ////////////////////////////////////////////////////////////////////////////////
4082 /// Return pointer to cling interface function for a method of a class with
4083 /// a certain name.
4084 
4085 TInterpreter::DeclId_t TCling::GetFunctionTemplate(ClassInfo_t *opaque_cl, const char* name)
4086 {
4088  DeclId_t f;
4089  TClingClassInfo *cl = (TClingClassInfo*)opaque_cl;
4090  if (cl) {
4091  f = cl->GetFunctionTemplate(name);
4092  }
4093  else {
4095  f = gcl.GetFunctionTemplate(name);
4096  }
4097  return f;
4098 
4099 }
4100 
4101 ////////////////////////////////////////////////////////////////////////////////
4102 /// The 'name' is known to the interpreter, this function returns
4103 /// the internal version of this name (usually just resolving typedefs)
4104 /// This is used in particular to synchronize between the name used
4105 /// by rootcling and by the run-time environment (TClass)
4106 /// Return 0 if the name is not known.
4107 
4108 void TCling::GetInterpreterTypeName(const char* name, std::string &output, Bool_t full)
4109 {
4110  output.clear();
4111 
4113 
4114  TClingClassInfo cl(fInterpreter, name);
4115  if (!cl.IsValid()) {
4116  return ;
4117  }
4118  if (full) {
4119  cl.FullName(output,*fNormalizedCtxt);
4120  return;
4121  }
4122  // Well well well, for backward compatibility we need to act a bit too
4123  // much like CINT.
4125  splitname.ShortType(output, TClassEdit::kDropStd );
4126 
4127  return;
4128 }
4129 
4130 ////////////////////////////////////////////////////////////////////////////////
4131 /// Execute a global function with arguments params.
4132 ///
4133 /// FIXME: The cint-based version of this code does not check if the
4134 /// SetFunc() call works, and does not do any real checking
4135 /// for errors from the Exec() call. It did fetch the most
4136 /// recent cint security error and return that in error, but
4137 /// this does not really translate well to cling/clang. We
4138 /// should enhance these interfaces so that we can report
4139 /// compilation and runtime errors properly.
4140 
4141 void TCling::Execute(const char* function, const char* params, int* error)
4142 {
4144  if (error) {
4145  *error = TInterpreter::kNoError;
4146  }
4148  Long_t offset = 0L;
4150  func.SetFunc(&cl, function, params, &offset);
4151  func.Exec(0);
4152 }
4153 
4154 ////////////////////////////////////////////////////////////////////////////////
4155 /// Execute a method from class cl with arguments params.
4156 ///
4157 /// FIXME: The cint-based version of this code does not check if the
4158 /// SetFunc() call works, and does not do any real checking
4159 /// for errors from the Exec() call. It did fetch the most
4160 /// recent cint security error and return that in error, but
4161 /// this does not really translate well to cling/clang. We
4162 /// should enhance these interfaces so that we can report
4163 /// compilation and runtime errors properly.
4164 
4165 void TCling::Execute(TObject* obj, TClass* cl, const char* method,
4166  const char* params, Bool_t objectIsConst, int* error)
4167 {
4169  if (error) {
4170  *error = TInterpreter::kNoError;
4171  }
4172  // If the actual class of this object inherits 2nd (or more) from TObject,
4173  // 'obj' is unlikely to be the start of the object (as described by IsA()),
4174  // hence gInterpreter->Execute will improperly correct the offset.
4175  void* addr = cl->DynamicCast(TObject::Class(), obj, kFALSE);
4176  Long_t offset = 0L;
4178  func.SetFunc((TClingClassInfo*)cl->GetClassInfo(), method, params, objectIsConst, &offset);
4179  void* address = (void*)((Long_t)addr + offset);
4180  func.Exec(address);
4181 }
4182 
4183 ////////////////////////////////////////////////////////////////////////////////
4184 
4185 void TCling::Execute(TObject* obj, TClass* cl, const char* method,
4186  const char* params, int* error)
4187 {
4188  Execute(obj,cl,method,params,false,error);
4189 }
4190 
4191 ////////////////////////////////////////////////////////////////////////////////
4192 /// Execute a method from class cl with the arguments in array params
4193 /// (params[0] ... params[n] = array of TObjString parameters).
4194 /// Convert the TObjArray array of TObjString parameters to a character
4195 /// string of comma separated parameters.
4196 /// The parameters of type 'char' are enclosed in double quotes and all
4197 /// internal quotes are escaped.
4198 
4200  TObjArray* params, int* error)
4201 {
4202  if (!method) {
4203  Error("Execute", "No method was defined");
4204  return;
4205  }
4206  TList* argList = method->GetListOfMethodArgs();
4207  // Check number of actual parameters against of expected formal ones
4208 
4209  Int_t nparms = argList->LastIndex() + 1;
4210  Int_t argc = params ? params->GetEntries() : 0;
4211 
4212  if (argc > nparms) {
4213  Error("Execute","Too many parameters to call %s, got %d but expected at most %d.",method->GetName(),argc,nparms);
4214  return;
4215  }
4216  if (nparms != argc) {
4217  // Let's see if the 'missing' argument are all defaulted.
4218  // if nparms==0 then either we stopped earlier either argc is also zero and we can't reach here.
4219  assert(nparms > 0);
4220 
4221  TMethodArg *arg = (TMethodArg *) argList->At( 0 );
4222  if (arg && arg->GetDefault() && arg->GetDefault()[0]) {
4223  // There is a default value for the first missing
4224  // argument, so we are fine.
4225  } else {
4226  Int_t firstDefault = -1;
4227  for (Int_t i = 0; i < nparms; i ++) {
4228  arg = (TMethodArg *) argList->At( i );
4229  if (arg && arg->GetDefault() && arg->GetDefault()[0]) {
4230  firstDefault = i;
4231  break;
4232  }
4233  }
4234  if (firstDefault >= 0) {
4235  Error("Execute","Too few arguments to call %s, got only %d but expected at least %d and at most %d.",method->GetName(),argc,firstDefault,nparms);
4236  } else {
4237  Error("Execute","Too few arguments to call %s, got only %d but expected %d.",method->GetName(),argc,nparms);
4238  }
4239  return;
4240  }
4241  }
4242 
4243  const char* listpar = "";
4244  TString complete(10);
4245  if (params) {
4246  // Create a character string of parameters from TObjArray
4247  TIter next(params);
4248  for (Int_t i = 0; i < argc; i ++) {
4249  TMethodArg* arg = (TMethodArg*) argList->At(i);
4251  TObjString* nxtpar = (TObjString*) next();
4252  if (i) {
4253  complete += ',';
4254  }
4255  if (strstr(type.TrueName(*fNormalizedCtxt), "char")) {
4256  TString chpar('\"');
4257  chpar += (nxtpar->String()).ReplaceAll("\"", "\\\"");
4258  // At this point we have to check if string contains \\"
4259  // and apply some more sophisticated parser. Not implemented yet!
4260  complete += chpar;
4261  complete += '\"';
4262  }
4263  else {
4264  complete += nxtpar->String();
4265  }
4266  }
4267  listpar = complete.Data();
4268  }
4269 
4270  // And now execute it.
4272  if (error) {
4273  *error = TInterpreter::kNoError;
4274  }
4275  // If the actual class of this object inherits 2nd (or more) from TObject,
4276  // 'obj' is unlikely to be the start of the object (as described by IsA()),
4277  // hence gInterpreter->Execute will improperly correct the offset.
4278  void* addr = cl->DynamicCast(TObject::Class(), obj, kFALSE);
4280  TClingMethodInfo *minfo = (TClingMethodInfo*)method->fInfo;
4281  func.Init(minfo);
4282  func.SetArgs(listpar);
4283  // Now calculate the 'this' pointer offset for the method
4284  // when starting from the class described by cl.
4285  const CXXMethodDecl * mdecl = dyn_cast<CXXMethodDecl>(minfo->GetMethodDecl());
4286  Long_t offset = ((TClingClassInfo*)cl->GetClassInfo())->GetOffset(mdecl);
4287  void* address = (void*)((Long_t)addr + offset);
4288  func.Exec(address);
4289 }
4290 
4291 ////////////////////////////////////////////////////////////////////////////////
4292 
4293 void TCling::ExecuteWithArgsAndReturn(TMethod* method, void* address,
4294  const void* args[] /*=0*/,
4295  int nargs /*=0*/,
4296  void* ret/*= 0*/) const
4297 {
4298  if (!method) {
4299  Error("ExecuteWithArgsAndReturn", "No method was defined");
4300  return;
4301  }
4302 
4303  TClingMethodInfo* minfo = (TClingMethodInfo*) method->fInfo;
4305  func.ExecWithArgsAndReturn(address, args, nargs, ret);
4306 }
4307 
4308 ////////////////////////////////////////////////////////////////////////////////
4309 /// Execute a cling macro.
4310 
4312 {
4314  fCurExecutingMacros.push_back(filename);
4315  Long_t result = TApplication::ExecuteFile(filename, (int*)error);
4316  fCurExecutingMacros.pop_back();
4317  return result;
4318 }
4319 
4320 ////////////////////////////////////////////////////////////////////////////////
4321 /// Return the file name of the current un-included interpreted file.
4322 /// See the documentation for GetCurrentMacroName().
4323 
4324 const char* TCling::GetTopLevelMacroName() const
4325 {
4326  Warning("GetTopLevelMacroName", "Must change return type!");
4327  return fCurExecutingMacros.back();
4328 }
4329 
4330 ////////////////////////////////////////////////////////////////////////////////
4331 /// Return the file name of the currently interpreted file,
4332 /// included or not. Example to illustrate the difference between
4333 /// GetCurrentMacroName() and GetTopLevelMacroName():
4334 /// ~~~ {.cpp}
4335 /// void inclfile() {
4336 /// std::cout << "In inclfile.C" << std::endl;
4337 /// std::cout << " TCling::GetCurrentMacroName() returns " <<
4338 /// TCling::GetCurrentMacroName() << std::endl;
4339 /// std::cout << " TCling::GetTopLevelMacroName() returns " <<
4340 /// TCling::GetTopLevelMacroName() << std::endl;
4341 /// }
4342 /// ~~~
4343 /// ~~~ {.cpp}
4344 /// void mymacro() {
4345 /// std::cout << "In mymacro.C" << std::endl;
4346 /// std::cout << " TCling::GetCurrentMacroName() returns " <<
4347 /// TCling::GetCurrentMacroName() << std::endl;
4348 /// std::cout << " TCling::GetTopLevelMacroName() returns " <<
4349 /// TCling::GetTopLevelMacroName() << std::endl;
4350 /// std::cout << " Now calling inclfile..." << std::endl;
4351 /// gInterpreter->ProcessLine(".x inclfile.C");;
4352 /// }
4353 /// ~~~
4354 /// Running mymacro.C will print:
4355 ///
4356 /// ~~~ {.cpp}
4357 /// root [0] .x mymacro.C
4358 /// ~~~
4359 /// In mymacro.C
4360 /// ~~~ {.cpp}
4361 /// TCling::GetCurrentMacroName() returns ./mymacro.C
4362 /// TCling::GetTopLevelMacroName() returns ./mymacro.C
4363 /// ~~~
4364 /// Now calling inclfile...
4365 /// In inclfile.h
4366 /// ~~~ {.cpp}
4367 /// TCling::GetCurrentMacroName() returns inclfile.C
4368 /// TCling::GetTopLevelMacroName() returns ./mymacro.C
4369 /// ~~~
4370 
4371 const char* TCling::GetCurrentMacroName() const
4372 {
4373 #if defined(R__MUST_REVISIT)
4374 #if R__MUST_REVISIT(6,0)
4375  Warning("GetCurrentMacroName", "Must change return type!");
4376 #endif
4377 #endif
4378  return fCurExecutingMacros.back();
4379 }
4380 
4381 ////////////////////////////////////////////////////////////////////////////////
4382 /// Return the absolute type of typeDesc.
4383 /// E.g.: typeDesc = "class TNamed**", returns "TNamed".
4384 /// You need to use the result immediately before it is being overwritten.
4385 
4386 const char* TCling::TypeName(const char* typeDesc)
4387 {
4388  TTHREAD_TLS(char*) t = 0;
4389  TTHREAD_TLS(unsigned int) tlen = 0;
4390 
4391  unsigned int dlen = strlen(typeDesc);
4392  if (dlen > tlen) {
4393  delete[] t;
4394  t = new char[dlen + 1];
4395  tlen = dlen;
4396  }
4397  const char* s, *template_start;
4398  if (!strstr(typeDesc, "(*)(")) {
4399  s = strchr(typeDesc, ' ');
4400  template_start = strchr(typeDesc, '<');
4401  if (!strcmp(typeDesc, "long long")) {
4402  strlcpy(t, typeDesc, dlen + 1);
4403  }
4404  else if (!strncmp(typeDesc, "unsigned ", s + 1 - typeDesc)) {
4405  strlcpy(t, typeDesc, dlen + 1);
4406  }
4407  // s is the position of the second 'word' (if any)
4408  // except in the case of templates where there will be a space
4409  // just before any closing '>': eg.
4410  // TObj<std::vector<UShort_t,__malloc_alloc_template<0> > >*
4411  else if (s && (template_start == 0 || (s < template_start))) {
4412  strlcpy(t, s + 1, dlen + 1);
4413  }
4414  else {
4415  strlcpy(t, typeDesc, dlen + 1);
4416  }
4417  }
4418  else {
4419  strlcpy(t, typeDesc, dlen + 1);
4420  }
4421  int l = strlen(t);
4422  while (l > 0 && (t[l - 1] == '*' || t[l - 1] == '&')) {
4423  t[--l] = 0;
4424  }
4425  return t;
4426 }
4427 
4428 ////////////////////////////////////////////////////////////////////////////////
4429 /// Read and parse a rootmapfile in its new format, and return 0 in case of
4430 /// success, -1 if the file has already been read, and -3 in case its format
4431 /// is the old one (e.g. containing "Library.ClassName")
4432 
4433 int TCling::ReadRootmapFile(const char *rootmapfile, TUniqueString *uniqueString)
4434 {
4435  // For "class ", "namespace ", "typedef ", "header ", "enum " respectively
4436  const std::map<char, unsigned int> keyLenMap = {{'c',6},{'n',10},{'t',8},{'h',7},{'e',5}};
4437 
4438  if (rootmapfile && *rootmapfile) {
4439 
4440  // Add content of a specific rootmap file
4441  if (fRootmapFiles->FindObject(rootmapfile)) return -1;
4442  std::ifstream file(rootmapfile);
4443  std::string line; line.reserve(200);
4444  std::string lib_name; line.reserve(100);
4445  bool newFormat=false;
4446  while (getline(file, line, '\n')) {
4447  if (!newFormat &&
4448  (strstr(line.c_str(),"Library.")!=nullptr || strstr(line.c_str(),"Declare.")!=nullptr)) {
4449  file.close();
4450  return -3; // old format
4451  }
4452  newFormat=true;
4453 
4454  if (line.compare(0, 9, "{ decls }") == 0) {
4455  // forward declarations
4456 
4457  while (getline(file, line, '\n')) {
4458  if (line[0] == '[') break;
4459  uniqueString->Append(line);
4460  }
4461  }
4462  const char firstChar=line[0];
4463  if (firstChar == '[') {
4464  // new section (library)
4465  auto brpos = line.find(']');
4466  if (brpos == string::npos) continue;
4467  lib_name = line.substr(1, brpos-1);
4468  size_t nspaces = 0;
4469  while( lib_name[nspaces] == ' ' ) ++nspaces;
4470  if (nspaces) lib_name.replace(0, nspaces, "");
4471  if (gDebug > 3) {
4472  TString lib_nameTstr(lib_name.c_str());
4473  TObjArray* tokens = lib_nameTstr.Tokenize(" ");
4474  const char* lib = ((TObjString *)tokens->At(0))->GetName();
4475  const char* wlib = gSystem->DynamicPathName(lib, kTRUE);
4476  if (wlib) {
4477  Info("ReadRootmapFile", "new section for %s", lib_nameTstr.Data());
4478  }
4479  else {
4480  Info("ReadRootmapFile", "section for %s (library does not exist)", lib_nameTstr.Data());
4481  }
4482  delete[] wlib;
4483  delete tokens;
4484  }
4485  }
4486  else {
4487  auto keyLenIt = keyLenMap.find(firstChar);
4488  if (keyLenIt == keyLenMap.end()) continue;
4489  unsigned int keyLen = keyLenIt->second;
4490  // Do not make a copy, just start after the key
4491  const char *keyname = line.c_str()+keyLen;
4492  if (gDebug > 6)
4493  Info("ReadRootmapFile", "class %s in %s", keyname, lib_name.c_str());
4494  TEnvRec* isThere = fMapfile->Lookup(keyname);
4495  if (isThere){
4496  if(lib_name != isThere->GetValue()){ // the same key for two different libs
4497  if (firstChar == 'n') {
4498  if (gDebug > 3)
4499  Info("ReadRootmapFile", "namespace %s found in %s is already in %s",
4500  keyname, lib_name.c_str(), isThere->GetValue());
4501  } else if (firstChar == 'h'){ // it is a header: add the libname to the list of libs to be loaded.
4502  lib_name+=" ";
4503  lib_name+=isThere->GetValue();
4504  fMapfile->SetValue(keyname, lib_name.c_str());
4505  }
4506  else if (!TClassEdit::IsSTLCont(keyname)) {
4507  Warning("ReadRootmapFile", "%s %s found in %s is already in %s", line.substr(0, keyLen).c_str(),
4508  keyname, lib_name.c_str(), isThere->GetValue());
4509  }
4510  } else { // the same key for the same lib
4511  if (gDebug > 3)
4512  Info("ReadRootmapFile","Key %s was already defined for %s", keyname, lib_name.c_str());
4513  }
4514 
4515  } else {
4516  fMapfile->SetValue(keyname, lib_name.c_str());
4517  }
4518  }
4519  }
4520  file.close();
4521  }
4522 
4523  return 0;
4524 }
4525 
4526 ////////////////////////////////////////////////////////////////////////////////
4527 /// Create a resource table and read the (possibly) three resource files, i.e
4528 /// $ROOTSYS/etc/system<name> (or ROOTETCDIR/system<name>), $HOME/<name> and
4529 /// ./<name>. ROOT always reads ".rootrc" (in TROOT::InitSystem()). You can
4530 /// read additional user defined resource files by creating additional TEnv
4531 /// objects. By setting the shell variable ROOTENV_NO_HOME=1 the reading of
4532 /// the $HOME/<name> resource file will be skipped. This might be useful in
4533 /// case the home directory resides on an automounted remote file system
4534 /// and one wants to avoid the file system from being mounted.
4535 
4537 {
4539 
4540  fMapfile->SetRcName(name);
4541 
4542  TString sname = "system";
4543  sname += name;
4544 #ifdef ROOTETCDIR
4545  char *s = gSystem->ConcatFileName(ROOTETCDIR, sname);
4546 #else
4547  TString etc = gRootDir;
4548 #ifdef WIN32
4549  etc += "\\etc";
4550 #else
4551  etc += "/etc";
4552 #endif
4553 #if defined(R__MACOSX) && (TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR)
4554  // on iOS etc does not exist and system<name> resides in $ROOTSYS
4555  etc = gRootDir;
4556 #endif
4557  char *s = gSystem->ConcatFileName(etc, sname);
4558 #endif
4559 
4560  Int_t ret = ReadRootmapFile(s);
4561  if (ret == -3) // old format
4563  delete [] s;
4564  if (!gSystem->Getenv("ROOTENV_NO_HOME")) {
4566  ret = ReadRootmapFile(s);
4567  if (ret == -3) // old format
4568  fMapfile->ReadFile(s, kEnvUser);
4569  delete [] s;
4570  if (strcmp(gSystem->HomeDirectory(), gSystem->WorkingDirectory())) {
4571  ret = ReadRootmapFile(name);
4572  if (ret == -3) // old format
4573  fMapfile->ReadFile(name, kEnvLocal);
4574  }
4575  } else {
4576  ret = ReadRootmapFile(name);
4577  if (ret == -3) // old format
4578  fMapfile->ReadFile(name, kEnvLocal);
4579  }
4580  fMapfile->IgnoreDuplicates(ignore);
4581 }
4582 
4583 
4584 namespace {
4585  using namespace clang;
4586 
4587  class ExtVisibleStorageAdder: public RecursiveASTVisitor<ExtVisibleStorageAdder>{
4588  // This class is to be considered an helper for autoloading.
4589  // It is a recursive visitor is used to inspect namespaces coming from
4590  // forward declarations in rootmaps and to set the external visible
4591  // storage flag for them.
4592  public:
4593  ExtVisibleStorageAdder(std::unordered_set<const NamespaceDecl*>& nsSet): fNSSet(nsSet) {};
4594  bool VisitNamespaceDecl(NamespaceDecl* nsDecl) {
4595  // We want to enable the external lookup for this namespace
4596  // because it may shadow the lookup of other names contained
4597  // in that namespace
4598  nsDecl->setHasExternalVisibleStorage();
4599  fNSSet.insert(nsDecl);
4600  return true;
4601  }
4602  private:
4603  std::unordered_set<const NamespaceDecl*>& fNSSet;
4604 
4605  };
4606 }
4607 
4608 ////////////////////////////////////////////////////////////////////////////////
4609 /// Load map between class and library. If rootmapfile is specified a
4610 /// specific rootmap file can be added (typically used by ACLiC).
4611 /// In case of error -1 is returned, 0 otherwise.
4612 /// The interpreter uses this information to automatically load the shared
4613 /// library for a class (autoload mechanism), see the AutoLoad() methods below.
4614 
4615 Int_t TCling::LoadLibraryMap(const char* rootmapfile)
4616 {
4618  // open the [system].rootmap files
4619  if (!fMapfile) {
4620  fMapfile = new TEnv();
4622 // fMapNamespaces = new THashTable();
4623 // fMapNamespaces->SetOwner();
4624  fRootmapFiles = new TObjArray;
4626  InitRootmapFile(".rootmap");
4627  }
4628 
4629  // Prepare a list of all forward declarations for cling
4630  // For some experiments it is easily as big as 500k characters. To be on the
4631  // safe side, we go for 1M.
4632  TUniqueString uniqueString(1048576);
4633 
4634  // Load all rootmap files in the dynamic load path ((DY)LD_LIBRARY_PATH, etc.).
4635  // A rootmap file must end with the string ".rootmap".
4636  TString ldpath = gSystem->GetDynamicPath();
4637  if (ldpath != fRootmapLoadPath) {
4638  fRootmapLoadPath = ldpath;
4639 #ifdef WIN32
4640  TObjArray* paths = ldpath.Tokenize(";");
4641 #else
4642  TObjArray* paths = ldpath.Tokenize(":");
4643 #endif
4644  TString d;
4645  for (Int_t i = 0; i < paths->GetEntriesFast(); i++) {
4646  d = ((TObjString *)paths->At(i))->GetString();
4647  // check if directory already scanned
4648  Int_t skip = 0;
4649  for (Int_t j = 0; j < i; j++) {
4650  TString pd = ((TObjString *)paths->At(j))->GetString();
4651  if (pd == d) {
4652  skip++;
4653  break;
4654  }
4655  }
4656  if (!skip) {
4657  void* dirp = gSystem->OpenDirectory(d);
4658  if (dirp) {
4659  if (gDebug > 3) {
4660  Info("LoadLibraryMap", "%s", d.Data());
4661  }
4662  const char* f1;
4663  while ((f1 = gSystem->GetDirEntry(dirp))) {
4664  TString f = f1;
4665  if (f.EndsWith(".rootmap")) {
4666  TString p;
4667  p = d + "/" + f;
4669  if (!fRootmapFiles->FindObject(f) && f != ".rootmap") {
4670  if (gDebug > 4) {
4671  Info("LoadLibraryMap", " rootmap file: %s", p.Data());
4672  }
4673  Int_t ret = ReadRootmapFile(p,&uniqueString);
4674  if (ret == 0)
4675  fRootmapFiles->Add(new TNamed(gSystem->BaseName(f), p.Data()));
4676  if (ret == -3) {
4677  // old format
4679  fRootmapFiles->Add(new TNamed(f, p));
4680  }
4681  }
4682  // else {
4683  // fprintf(stderr,"Reject %s because %s is already there\n",p.Data(),f.Data());
4684  // fRootmapFiles->FindObject(f)->ls();
4685  // }
4686  }
4687  }
4688  if (f.BeginsWith("rootmap")) {
4689  TString p;
4690  p = d + "/" + f;
4691  FileStat_t stat;
4692  if (gSystem->GetPathInfo(p, stat) == 0 && R_ISREG(stat.fMode)) {
4693  Warning("LoadLibraryMap", "please rename %s to end with \".rootmap\"", p.Data());
4694  }
4695  }
4696  }
4697  }
4698  gSystem->FreeDirectory(dirp);
4699  }
4700  }
4701  delete paths;
4702  if (!fMapfile->GetTable()->GetEntries()) {
4703  return -1;
4704  }
4705  }
4706  if (rootmapfile && *rootmapfile) {
4707  Int_t res = ReadRootmapFile(rootmapfile, &uniqueString);
4708  if (res == 0) {
4709  //TString p = gSystem->ConcatFileName(gSystem->pwd(), rootmapfile);
4710  //fRootmapFiles->Add(new TNamed(gSystem->BaseName(rootmapfile), p.Data()));
4711  fRootmapFiles->Add(new TNamed(gSystem->BaseName(rootmapfile), rootmapfile));
4712  }
4713  else if (res == -3) {
4714  // old format
4716  fMapfile->ReadFile(rootmapfile, kEnvGlobal);
4717  fRootmapFiles->Add(new TNamed(gSystem->BaseName(rootmapfile), rootmapfile));
4718  fMapfile->IgnoreDuplicates(ignore);
4719  }
4720  }
4721  TEnvRec* rec;
4723  while ((rec = (TEnvRec*) next())) {
4724  TString cls = rec->GetName();
4725  if (!strncmp(cls.Data(), "Library.", 8) && cls.Length() > 8) {
4726  // get the first lib from the list of lib and dependent libs
4727  TString libs = rec->GetValue();
4728  if (libs == "") {
4729  continue;
4730  }
4731  TString delim(" ");
4732  TObjArray* tokens = libs.Tokenize(delim);
4733  const char* lib = ((TObjString*)tokens->At(0))->GetName();
4734  // convert "@@" to "::", we used "@@" because TEnv
4735  // considers "::" a terminator
4736  cls.Remove(0, 8);
4737  cls.ReplaceAll("@@", "::");
4738  // convert "-" to " ", since class names may have
4739  // blanks and TEnv considers a blank a terminator
4740  cls.ReplaceAll("-", " ");
4741  if (gDebug > 6) {
4742  const char* wlib = gSystem->DynamicPathName(lib, kTRUE);
4743  if (wlib) {
4744  Info("LoadLibraryMap", "class %s in %s", cls.Data(), wlib);
4745  }
4746  else {
4747  Info("LoadLibraryMap", "class %s in %s (library does not exist)", cls.Data(), lib);
4748  }
4749  delete[] wlib;
4750  }
4751  // Fill in the namespace candidate list
4752 // Ssiz_t last = cls.Last(':');
4753 // if (last != kNPOS) {
4754 // // Please note that the funny op overload does substring.
4755 // TString namespaceCand = cls(0, last - 1);
4756 // // This is a reference to a substring that lives in fMapfile
4757 // if (!fMapNamespaces->FindObject(namespaceCand.Data()))
4758 // fMapNamespaces->Add(new TNamed(namespaceCand.Data(), ""));
4759 // }
4760  delete tokens;
4761  }
4762  else if (!strncmp(cls.Data(), "Declare.", 8) && cls.Length() > 8) {
4763  cls.Remove(0, 8);
4764  // convert "-" to " ", since class names may have
4765  // blanks and TEnv considers a blank a terminator
4766  cls.ReplaceAll("-", " ");
4767  fInterpreter->declare(cls.Data());
4768  }
4769  }
4770 
4771  // Process the forward declarations collected
4772  cling::Transaction* T = nullptr;
4773  auto compRes= fInterpreter->declare(uniqueString.Data(), &T);
4774  assert(cling::Interpreter::kSuccess == compRes && "A declaration in a rootmap could not be compiled");
4775 
4776  if (compRes!=cling::Interpreter::kSuccess){
4777  Warning("LoadLibraryMap",
4778  "Problems in %s declaring '%s' were encountered.", rootmapfile, uniqueString.Data()) ;
4779  }
4780 
4781  if (T){
4782  ExtVisibleStorageAdder evsAdder(fNSFromRootmaps);
4783  for (auto declIt = T->decls_begin(); declIt < T->decls_end(); ++declIt) {
4784  if (declIt->m_DGR.isSingleDecl()) {
4785  if (Decl* D = declIt->m_DGR.getSingleDecl()) {
4786  if (NamespaceDecl* NSD = dyn_cast<NamespaceDecl>(D)) {
4787  evsAdder.TraverseDecl(NSD);
4788  }
4789  }
4790  }
4791  }
4792  }
4793 
4794  // clear duplicates
4795 
4796  return 0;
4797 }
4798 
4799 ////////////////////////////////////////////////////////////////////////////////
4800 /// Scan again along the dynamic path for library maps. Entries for the loaded
4801 /// shared libraries are unloaded first. This can be useful after reseting
4802 /// the dynamic path through TSystem::SetDynamicPath()
4803 /// In case of error -1 is returned, 0 otherwise.
4804 
4806 {
4808  LoadLibraryMap();
4809  return 0;
4810 }
4811 
4812 ////////////////////////////////////////////////////////////////////////////////
4813 /// Reload the library map entries coming from all the loaded shared libraries,
4814 /// after first unloading the current ones.
4815 /// In case of error -1 is returned, 0 otherwise.
4816 
4818 {
4819  const TString sharedLibLStr = GetSharedLibs();
4820  const TObjArray* sharedLibL = sharedLibLStr.Tokenize(" ");
4821  const Int_t nrSharedLibs = sharedLibL->GetEntriesFast();
4822  for (Int_t ilib = 0; ilib < nrSharedLibs; ilib++) {
4823  const TString sharedLibStr = ((TObjString*)sharedLibL->At(ilib))->GetString();
4824  const TString sharedLibBaseStr = gSystem->BaseName(sharedLibStr);
4825  const Int_t ret = UnloadLibraryMap(sharedLibBaseStr);
4826  if (ret < 0) {
4827  continue;
4828  }
4829  TString rootMapBaseStr = sharedLibBaseStr;
4830  if (sharedLibBaseStr.EndsWith(".dll")) {
4831  rootMapBaseStr.ReplaceAll(".dll", "");
4832  }
4833  else if (sharedLibBaseStr.EndsWith(".DLL")) {
4834  rootMapBaseStr.ReplaceAll(".DLL", "");
4835  }
4836  else if (sharedLibBaseStr.EndsWith(".so")) {
4837  rootMapBaseStr.ReplaceAll(".so", "");
4838  }
4839  else if (sharedLibBaseStr.EndsWith(".sl")) {
4840  rootMapBaseStr.ReplaceAll(".sl", "");
4841  }
4842  else if (sharedLibBaseStr.EndsWith(".dl")) {
4843  rootMapBaseStr.ReplaceAll(".dl", "");
4844  }
4845  else if (sharedLibBaseStr.EndsWith(".a")) {
4846  rootMapBaseStr.ReplaceAll(".a", "");
4847  }
4848  else {
4849  Error("ReloadAllSharedLibraryMaps", "Unknown library type %s", sharedLibBaseStr.Data());
4850  delete sharedLibL;
4851  return -1;
4852  }
4853  rootMapBaseStr += ".rootmap";
4854  const char* rootMap = gSystem->Which(gSystem->GetDynamicPath(), rootMapBaseStr);
4855  if (!rootMap) {
4856  Error("ReloadAllSharedLibraryMaps", "Could not find rootmap %s in path", rootMap);
4857  delete[] rootMap;
4858  delete sharedLibL;
4859  return -1;
4860  }
4861  const Int_t status = LoadLibraryMap(rootMap);
4862  if (status < 0) {
4863  Error("ReloadAllSharedLibraryMaps", "Error loading map %s", rootMap);
4864  delete[] rootMap;
4865  delete sharedLibL;
4866  return -1;
4867  }
4868  delete[] rootMap;
4869  }
4870  delete sharedLibL;
4871  return 0;
4872 }
4873 
4874 ////////////////////////////////////////////////////////////////////////////////
4875 /// Unload the library map entries coming from all the loaded shared libraries.
4876 /// Returns 0 if succesful
4877 
4879 {
4880  const TString sharedLibLStr = GetSharedLibs();
4881  const TObjArray* sharedLibL = sharedLibLStr.Tokenize(" ");
4882  for (Int_t ilib = 0; ilib < sharedLibL->GetEntriesFast(); ilib++) {
4883  const TString sharedLibStr = ((TObjString*)sharedLibL->At(ilib))->GetString();
4884  const TString sharedLibBaseStr = gSystem->BaseName(sharedLibStr);
4885  UnloadLibraryMap(sharedLibBaseStr);
4886  }
4887  delete sharedLibL;
4888  return 0;
4889 }
4890 
4891 ////////////////////////////////////////////////////////////////////////////////
4892 /// Unload library map entries coming from the specified library.
4893 /// Returns -1 in case no entries for the specified library were found,
4894 /// 0 otherwise.
4895 
4896 Int_t TCling::UnloadLibraryMap(const char* library)
4897 {
4898  if (!fMapfile || !library || !*library) {
4899  return 0;
4900  }
4901  TString libname(library);
4902  Ssiz_t idx = libname.Last('.');
4903  if (idx != kNPOS) {
4904  libname.Remove(idx);
4905  }
4906  size_t len = libname.Length();
4907  TEnvRec *rec;
4910  Int_t ret = 0;
4911  while ((rec = (TEnvRec *) next())) {
4912  TString cls = rec->GetName();
4913  if (cls.Length() > 2) {
4914  // get the first lib from the list of lib and dependent libs
4915  TString libs = rec->GetValue();
4916  if (libs == "") {
4917  continue;
4918  }
4919  TString delim(" ");
4920  TObjArray* tokens = libs.Tokenize(delim);
4921  const char* lib = ((TObjString *)tokens->At(0))->GetName();
4922  if (!strncmp(cls.Data(), "Library.", 8) && cls.Length() > 8) {
4923  // convert "@@" to "::", we used "@@" because TEnv
4924  // considers "::" a terminator
4925  cls.Remove(0, 8);
4926  cls.ReplaceAll("@@", "::");
4927  // convert "-" to " ", since class names may have
4928  // blanks and TEnv considers a blank a terminator
4929  cls.ReplaceAll("-", " ");
4930  }
4931  if (!strncmp(lib, libname.Data(), len)) {
4932  if (fMapfile->GetTable()->Remove(rec) == 0) {
4933  Error("UnloadLibraryMap", "entry for <%s, %s> not found in library map table", cls.Data(), lib);
4934  ret = -1;
4935  }
4936  }
4937  delete tokens;
4938  }
4939  }
4940  if (ret >= 0) {
4941  TString library_rootmap(library);
4942  if (!library_rootmap.EndsWith(".rootmap"))
4943  library_rootmap.Append(".rootmap");
4944  TNamed* mfile = 0;
4945  while ((mfile = (TNamed *)fRootmapFiles->FindObject(library_rootmap))) {
4946  fRootmapFiles->Remove(mfile);
4947  delete mfile;
4948  }
4950  }
4951  return ret;
4952 }
4953 
4954 ////////////////////////////////////////////////////////////////////////////////
4955 /// Register the autoloading information for a class.
4956 /// libs is a space separated list of libraries.
4957 
4958 Int_t TCling::SetClassSharedLibs(const char *cls, const char *libs)
4959 {
4960  if (!cls || !*cls)
4961  return 0;
4962 
4963  TString key = TString("Library.") + cls;
4964  // convert "::" to "@@", we used "@@" because TEnv
4965  // considers "::" a terminator
4966  key.ReplaceAll("::", "@@");
4967  // convert "-" to " ", since class names may have
4968  // blanks and TEnv considers a blank a terminator
4969  key.ReplaceAll(" ", "-");
4970 
4972  if (!fMapfile) {
4973  fMapfile = new TEnv();
4975 // fMapNamespaces = new THashTable();
4976 // fMapNamespaces->SetOwner();
4977 
4978  fRootmapFiles = new TObjArray;
4980 
4981  InitRootmapFile(".rootmap");
4982  }
4983  //fMapfile->SetValue(key, libs);
4984  fMapfile->SetValue(cls, libs);
4985  return 1;
4986 }
4987 
4988 ////////////////////////////////////////////////////////////////////////////////
4989 /// Demangle the name (from the typeinfo) and then request the class
4990 /// via the usual name based interface (TClass::GetClass).
4991 
4992 TClass *TCling::GetClass(const std::type_info& typeinfo, Bool_t load) const
4993 {
4994  int err = 0;
4995  char* demangled_name = TClassEdit::DemangleTypeIdName(typeinfo, err);
4996  if (err) return 0;
4997  TClass* theClass = TClass::GetClass(demangled_name, load, kTRUE);
4998  free(demangled_name);
4999  return theClass;
5000 }
5001 
5002 ////////////////////////////////////////////////////////////////////////////////
5003 /// Load library containing the specified class. Returns 0 in case of error
5004 /// and 1 in case if success.
5005 
5006 Int_t TCling::AutoLoad(const std::type_info& typeinfo, Bool_t knowDictNotLoaded /* = kFALSE */)
5007 {
5008  int err = 0;
5009  char* demangled_name_c = TClassEdit::DemangleTypeIdName(typeinfo, err);
5010  if (err) {
5011  return 0;
5012  }
5013 
5014  std::string demangled_name(demangled_name_c);
5015  free(demangled_name_c);
5016 
5017  // AutoLoad expects (because TClass::GetClass already prepares it that way) a
5018  // shortened name.
5019  TClassEdit::TSplitType splitname( demangled_name.c_str(), (TClassEdit::EModType)(TClassEdit::kLong64 | TClassEdit::kDropStd) );
5020  splitname.ShortType(demangled_name, TClassEdit::kDropStlDefault | TClassEdit::kDropStd);
5021 
5022  // No need to worry about typedef, they aren't any ... but there are
5023  // inlined namespaces ...
5024 
5025  Int_t result = AutoLoad(demangled_name.c_str());
5026  if (result == 0) {
5027  demangled_name = TClassEdit::GetLong64_Name(demangled_name);
5028  result = AutoLoad(demangled_name.c_str(), knowDictNotLoaded);
5029  }
5030 
5031  return result;
5032 }
5033 
5034 ////////////////////////////////////////////////////////////////////////////////
5035 /// Load library containing the specified class. Returns 0 in case of error
5036 /// and 1 in case if success.
5037 
5038 Int_t TCling::AutoLoad(const char *cls, Bool_t knowDictNotLoaded /* = kFALSE */)
5039 {
5041 
5042  if (!knowDictNotLoaded && gClassTable->GetDictNorm(cls)) {
5043  // The library is already loaded as the class's dictionary is known.
5044  // Return success.
5045  // Note: the name (cls) is expected to be normalized as it comes either
5046  // from a callbacks (that can/should calculate the normalized name from the
5047  // decl) or from TClass::GetClass (which does also calculate the normalized
5048  // name).
5049  return 1;
5050  }
5051 
5052  if (gDebug > 2) {
5053  Info("TCling::AutoLoad",
5054  "Trying to autoload for %s", cls);
5055  }
5056 
5057  Int_t status = 0;
5058  if (!gROOT || !gInterpreter || gROOT->TestBit(TObject::kInvalidObject)) {
5059  if (gDebug > 2) {
5060  Info("TCling::AutoLoad",
5061  "Disabled due to gROOT or gInterpreter being invalid/not ready (the class name is %s)", cls);
5062  }
5063  return status;
5064  }
5065  if (!fAllowLibLoad) {
5066  // Never load any library from rootcling/genreflex.
5067  if (gDebug > 2) {
5068  Info("TCling::AutoLoad",
5069  "Explicitly disabled (the class name is %s)", cls);
5070  }
5071  return 0;
5072  }
5073  // Prevent the recursion when the library dictionary are loaded.
5074  Int_t oldvalue = SetClassAutoloading(false);
5075  // Try using externally provided callback first.
5076  if (fAutoLoadCallBack) {
5077  int success = (*(AutoLoadCallBack_t)fAutoLoadCallBack)(cls);
5078  if (success) {
5079  SetClassAutoloading(oldvalue);
5080  return success;
5081  }
5082  }
5083  // lookup class to find list of dependent libraries
5084  TString deplibs = GetClassSharedLibs(cls);
5085  if (!deplibs.IsNull()) {
5086  TString delim(" ");
5087  TObjArray* tokens = deplibs.Tokenize(delim);
5088  for (Int_t i = (tokens->GetEntriesFast() - 1); i > 0; --i) {
5089  const char* deplib = ((TObjString*)tokens->At(i))->GetName();
5090  if (gROOT->LoadClass(cls, deplib) == 0) {
5091  if (gDebug > 0) {
5092  Info("TCling::AutoLoad",
5093  "loaded dependent library %s for %s", deplib, cls);
5094  }
5095  }
5096  else {
5097  Error("TCling::AutoLoad",
5098  "failure loading dependent library %s for %s",
5099  deplib, cls);
5100  }
5101  }
5102  const char* lib = ((TObjString*)tokens->At(0))->GetName();
5103  if (lib && lib[0]) {
5104  if (gROOT->LoadClass(cls, lib) == 0) {
5105  if (gDebug > 0) {
5106  Info("TCling::AutoLoad",
5107  "loaded library %s for %s", lib, cls);
5108  }
5109  status = 1;
5110  }
5111  else {
5112  Error("TCling::AutoLoad",
5113  "failure loading library %s for %s", lib, cls);
5114  }
5115  }
5116  delete tokens;
5117  }
5118 
5119  SetClassAutoloading(oldvalue);
5120  return status;
5121 }
5122 
5123 ////////////////////////////////////////////////////////////////////////////////
5124 /// Parse the payload or header.
5125 
5126 static cling::Interpreter::CompilationResult ExecAutoParse(const char *what,
5127  Bool_t header,
5128  cling::Interpreter *interpreter)
5129 {
5130  // Save state of the PP
5131  Sema &SemaR = interpreter->getSema();
5132  ASTContext& C = SemaR.getASTContext();
5133  Preprocessor &PP = SemaR.getPreprocessor();
5134  Parser& P = const_cast<Parser&>(interpreter->getParser());
5135  Preprocessor::CleanupAndRestoreCacheRAII cleanupRAII(PP);
5136  Parser::ParserCurTokRestoreRAII savedCurToken(P);
5137  // After we have saved the token reset the current one to something which
5138  // is safe (semi colon usually means empty decl)
5139  Token& Tok = const_cast<Token&>(P.getCurToken());
5140  Tok.setKind(tok::semi);
5141 
5142  // We can't PushDeclContext, because we go up and the routine that pops
5143  // the DeclContext assumes that we drill down always.
5144  // We have to be on the global context. At that point we are in a
5145  // wrapper function so the parent context must be the global.
5146  Sema::ContextAndScopeRAII pushedDCAndS(SemaR, C.getTranslationUnitDecl(),
5147  SemaR.TUScope);
5148  std::string code = gNonInterpreterClassDef ;
5149  if (!header) {
5150  // This is the complete header file content and not the
5151  // name of a header.
5152  code += what;
5153 
5154  } else {
5155  code += ("#include \"");
5156  code += what;
5157  code += "\"\n";
5158  }
5159  code += ("#ifdef __ROOTCLING__\n"
5160  "#undef __ROOTCLING__\n"
5161  + gInterpreterClassDef +
5162  "#endif");
5163 
5164  cling::Interpreter::CompilationResult cr;
5165  {
5166  // scope within which diagnostics are de-activated
5167  // For now we disable diagnostics because we saw them already at
5168  // dictionary generation time. That won't be an issue with the PCMs.
5169 
5170  clangDiagSuppr diagSuppr(SemaR.getDiagnostics());
5171 
5172  #if defined(R__MUST_REVISIT)
5173  #if R__MUST_REVISIT(6,2)
5174  Warning("TCling::RegisterModule","Diagnostics suppression should be gone by now.");
5175  #endif
5176  #endif
5177 
5178  cr = interpreter->parseForModule(code);
5179  }
5180  return cr;
5181 }
5182 
5183 ////////////////////////////////////////////////////////////////////////////////
5184 /// Helper routine for TCling::AutoParse implementing the actual call to the
5185 /// parser and looping over template parameters (if
5186 /// any) and when they don't have a registered header to autoparse,
5187 /// recurse over their template parameters.
5188 ///
5189 /// Returns the number of header parsed.
5190 
5191 UInt_t TCling::AutoParseImplRecurse(const char *cls, bool topLevel)
5192 {
5193  // We assume the lock has already been taken.
5194  // R__LOCKGUARD(gInterpreterMutex);
5195 
5196  Int_t nHheadersParsed = 0;
5197 
5198  // Loop on the possible autoparse keys
5199  bool skipFirstEntry = false;
5200  std::vector<std::string> autoparseKeys;
5201  if (strchr(cls, '<')) {
5202  int nestedLoc = 0;
5203  TClassEdit::GetSplit(cls, autoparseKeys, nestedLoc, TClassEdit::kDropTrailStar);
5204  // Check if we can skip the name of the template in the autoparses
5205  // Take all the scopes one by one. If all of them are in the AST, we do not
5206  // need to autoparse for that particular template.
5207  if (!autoparseKeys.empty()){
5208  TString templateName(autoparseKeys[0]);
5209  auto tokens = templateName.Tokenize("::");
5210  clang::NamedDecl* previousScopeAsNamedDecl = nullptr;
5211  clang::DeclContext* previousScopeAsContext = nullptr;
5212  for (auto const & scopeObj : *tokens){
5213  auto scopeName = ((TObjString*) scopeObj)->String().Data();
5214  previousScopeAsNamedDecl = cling::utils::Lookup::Named(&fInterpreter->getSema(), scopeName, previousScopeAsContext);
5215  // Check if we have multiple nodes in the AST with this name
5216  if ((clang::NamedDecl*)-1 == previousScopeAsNamedDecl) break;
5217  previousScopeAsContext = llvm::dyn_cast_or_null<clang::DeclContext>(previousScopeAsNamedDecl);
5218  if (!previousScopeAsContext) break; // this is not a context
5219  }
5220  delete tokens;
5221  // Now, let's check if the last scope, the template, has a definition, i.e. it's not a fwd decl
5222  if (auto templateDecl = llvm::dyn_cast_or_null<clang::ClassTemplateDecl>(previousScopeAsNamedDecl)) {
5223  if (auto templatedDecl = templateDecl->getTemplatedDecl()) {
5224  skipFirstEntry = nullptr != templatedDecl->getDefinition();
5225  }
5226  }
5227 
5228  }
5229  }
5230  if (topLevel) autoparseKeys.emplace_back(cls);
5231 
5232  for (const auto & apKeyStr : autoparseKeys) {
5233  if (skipFirstEntry) {
5234  skipFirstEntry=false;
5235  continue;
5236  }
5237  if (apKeyStr.empty()) continue;
5238  const char *apKey = apKeyStr.c_str();
5239  std::size_t normNameHash(fStringHashFunction(apKey));
5240  // If the class was not looked up
5241  if (gDebug > 1) {
5242  Info("TCling::AutoParse",
5243  "Starting autoparse for %s\n", apKey);
5244  }
5245  if (fLookedUpClasses.insert(normNameHash).second) {
5246  auto const &iter = fClassesHeadersMap.find(normNameHash);
5247  if (iter != fClassesHeadersMap.end()) {
5248  const cling::Transaction *T = fInterpreter->getCurrentTransaction();
5249  fTransactionHeadersMap.insert({T,normNameHash});
5250  auto const &hNamesPtrs = iter->second;
5251  if (gDebug > 1) {
5252  Info("TCling::AutoParse",
5253  "We can proceed for %s. We have %s headers.", apKey, std::to_string(hNamesPtrs.size()).c_str());
5254  }
5255  for (auto & hName : hNamesPtrs) {
5256  if (fParsedPayloadsAddresses.count(hName) == 1) continue;
5257  if (0 != fPayloads.count(normNameHash)) {
5258  float initRSSval=0.f, initVSIZEval=0.f;
5259  (void) initRSSval; // Avoid unused var warning
5260  (void) initVSIZEval;
5261  if (gDebug > 0) {
5262  Info("AutoParse",
5263  "Parsing full payload for %s", apKey);
5264  ProcInfo_t info;
5265  gSystem->GetProcInfo(&info);
5266  initRSSval = 1e-3*info.fMemResident;
5267  initVSIZEval = 1e-3*info.fMemVirtual;
5268  }
5269  auto cRes = ExecAutoParse(hName, kFALSE, fInterpreter);
5270  if (cRes != cling::Interpreter::kSuccess) {
5271  if (hName[0] == '\n')
5272  Error("AutoParse", "Error parsing payload code for class %s with content:\n%s", apKey, hName);
5273  } else {
5274  fParsedPayloadsAddresses.insert(hName);
5275  nHheadersParsed++;
5276  if (gDebug > 0){
5277  ProcInfo_t info;
5278  gSystem->GetProcInfo(&info);
5279  float endRSSval = 1e-3*info.fMemResident;
5280  float endVSIZEval = 1e-3*info.fMemVirtual;
5281  Info("Autoparse", ">>> RSS key %s - before %.3f MB - after %.3f MB - delta %.3f MB", apKey, initRSSval, endRSSval, endRSSval-initRSSval);
5282  Info("Autoparse", ">>> VSIZE key %s - before %.3f MB - after %.3f MB - delta %.3f MB", apKey, initVSIZEval, endVSIZEval, endVSIZEval-initVSIZEval);
5283  }
5284  }
5285  } else if (!IsLoaded(hName)) {
5286  if (gDebug > 0) {
5287  Info("AutoParse",
5288  "Parsing single header %s", hName);
5289  }
5290  auto cRes = ExecAutoParse(hName, kTRUE, fInterpreter);
5291  if (cRes != cling::Interpreter::kSuccess) {
5292  Error("AutoParse", "Error parsing headerfile %s for class %s.", hName, apKey);
5293  } else {
5294  nHheadersParsed++;
5295  }
5296  }
5297  }
5298  }
5299  else {
5300  // There is no header registered for this class, if this a
5301  // template, it will be instantiated if/when it is requested
5302  // and if we do no load/parse its components we might end up
5303  // not using an eventual specialization.
5304  if (strchr(apKey, '<')) {
5305  nHheadersParsed += AutoParseImplRecurse(apKey, false);
5306  }
5307  }
5308  }
5309  }
5310 
5311  return nHheadersParsed;
5312 
5313 }
5314 
5315 ////////////////////////////////////////////////////////////////////////////////
5316 /// Parse the headers relative to the class
5317 /// Returns 1 in case of success, 0 in case of failure
5318 
5319 Int_t TCling::AutoParse(const char *cls)
5320 {
5322 
5325  return AutoLoad(cls);
5326  } else {
5327  return 0;
5328  }
5329  }
5330 
5331  if (gDebug > 1) {
5332  Info("TCling::AutoParse",
5333  "Trying to autoparse for %s", cls);
5334  }
5335 
5336  // The catalogue of headers is in the dictionary
5338  AutoLoad(cls);
5339  }
5340 
5341  // Prevent the recursion when the library dictionary are loaded.
5342  Int_t oldAutoloadValue = SetClassAutoloading(false);
5343 
5344  // No recursive header parsing on demand; we require headers to be standalone.
5345  SuspendAutoParsing autoParseRAII(this);
5346 
5347  Int_t nHheadersParsed = AutoParseImplRecurse(cls,/*topLevel=*/ true);
5348 
5349  if (nHheadersParsed != 0) {
5350  while (!fClassesToUpdate.empty()) {
5351  TClass *oldcl = fClassesToUpdate.back().first;
5352  if (oldcl->GetState() != TClass::kHasTClassInit) {
5353  // if (gDebug > 2) Info("RegisterModule", "Forcing TClass init for %s", oldcl->GetName());
5354  DictFuncPtr_t dict = fClassesToUpdate.back().second;
5355  fClassesToUpdate.pop_back();
5356  // Calling func could manipulate the list so, let maintain the list
5357  // then call the dictionary function.
5358  TClass *ncl = dict();
5359  if (ncl) ncl->PostLoadCheck();
5360  } else {
5361  fClassesToUpdate.pop_back();
5362  }
5363  }
5364  }
5365 
5366  SetClassAutoloading(oldAutoloadValue);
5367 
5368  return nHheadersParsed > 0 ? 1 : 0;
5369 }
5370 
5371 
5372 ////////////////////////////////////////////////////////////////////////////////
5373 /// Autoload a library based on a missing symbol.
5374 
5375 void* TCling::LazyFunctionCreatorAutoload(const std::string& mangled_name) {
5376  // First see whether the symbol is in the library that we are currently
5377  // loading. It will have access to the symbols of its dependent libraries,
5378  // thus checking "back()" is sufficient.
5379  if (!fRegisterModuleDyLibs.empty()) {
5380  if (void* addr = dlsym(fRegisterModuleDyLibs.back(),
5381  mangled_name.c_str())) {
5382  return addr;
5383  }
5384  }
5385 
5386  int err = 0;
5387  char* demangled_name_c = TClassEdit::DemangleName(mangled_name.c_str(), err);
5388  if (err) {
5389  return 0;
5390  }
5391 
5392  std::string name(demangled_name_c);
5393  free(demangled_name_c);
5394 
5395  //fprintf(stderr, "demangled name: '%s'\n", demangled_name);
5396  //
5397  // Separate out the class or namespace part of the
5398  // function name.
5399  //
5400 
5401  if (!strncmp(name.c_str(), "typeinfo for ", sizeof("typeinfo for ")-1)) {
5402  name.erase(0, sizeof("typeinfo for ")-1);
5403  } else if (!strncmp(name.c_str(), "vtable for ", sizeof("vtable for ")-1)) {
5404  name.erase(0, sizeof("vtable for ")-1);
5405  } else if (!strncmp(name.c_str(), "operator", sizeof("operator")-1)
5406  && !isalnum(name[sizeof("operator")])) {
5407  // operator...(A, B) - let's try with A!
5408  name.erase(0, sizeof("operator")-1);
5409  std::string::size_type pos = name.rfind('(');
5410  if (pos != std::string::npos) {
5411  name.erase(0, pos + 1);
5412  pos = name.find(",");
5413  if (pos != std::string::npos) {
5414  // remove next arg up to end, leaving only the first argument type.
5415  name.erase(pos);
5416  }
5417  pos = name.rfind(" const");
5418  if (pos != std::string::npos) {
5419  name.erase(pos, strlen(" const"));
5420  }
5421  while (!name.empty() && strchr("&*", name.back()))
5422  name.erase(name.length() - 1);
5423  }
5424  } else {
5425  // Remove the function arguments.
5426  std::string::size_type pos = name.rfind('(');
5427  if (pos != std::string::npos) {
5428  name.erase(pos);
5429  }
5430  // Remove the function name.
5431  pos = name.rfind(':');
5432  if (pos != std::string::npos) {
5433  if ((pos != 0) && (name[pos-1] == ':')) {
5434  name.erase(pos-1);
5435  }
5436  }
5437  }
5438  //fprintf(stderr, "name: '%s'\n", name.c_str());
5439  // Now we have the class or namespace name, so do the lookup.
5440  TString libs = GetClassSharedLibs(name.c_str());
5441  if (libs.IsNull()) {
5442  // Not found in the map, all done.
5443  return 0;
5444  }
5445  //fprintf(stderr, "library: %s\n", iter->second.c_str());
5446  // Now we have the name of the libraries to load, so load them.
5447 
5448  TString lib;
5449  Ssiz_t posLib = 0;
5450  while (libs.Tokenize(lib, posLib)) {
5451  if (gSystem->Load(lib, "", kFALSE /*system*/) < 0) {
5452  // The library load failed, all done.
5453  //fprintf(stderr, "load failed: %s\n", errmsg.c_str());
5454  return 0;
5455  }
5456  }
5457 
5458  //fprintf(stderr, "load succeeded.\n");
5459  // Get the address of the function being called.
5460  void* addr = llvm::sys::DynamicLibrary::SearchForAddressOfSymbol(mangled_name.c_str());
5461  //fprintf(stderr, "addr: %016lx\n", reinterpret_cast<unsigned long>(addr));
5462  return addr;
5463 }
5464 
5465 ////////////////////////////////////////////////////////////////////////////////
5466 
5468 {
5469 // if (fMapNamespaces){
5470 // return fMapNamespaces->FindObject(name);
5471 // }
5472  return false;
5473 }
5474 
5475 ////////////////////////////////////////////////////////////////////////////////
5476 
5477 Bool_t TCling::IsAutoLoadNamespaceCandidate(const clang::NamespaceDecl* nsDecl)
5478 {
5479  return fNSFromRootmaps.count(nsDecl) != 0;
5480 }
5481 
5482 ////////////////////////////////////////////////////////////////////////////////
5483 /// Internal function. Inform a TClass about its new TagDecl or NamespaceDecl.
5484 
5485 void TCling::UpdateClassInfoWithDecl(const void* vTD)
5486 {
5487  const NamedDecl* ND = static_cast<const NamedDecl*>(vTD);
5488  const TagDecl* td = dyn_cast<TagDecl>(ND);
5489  std::string name;
5490  TagDecl* tdDef = 0;
5491  if (td) {
5492  tdDef = td->getDefinition();
5493  // Let's pass the decl to the TClass only if it has a definition.
5494  if (!tdDef) return;
5495  td = tdDef;
5496  ND = td;
5497 
5498  if (llvm::isa<clang::FunctionDecl>(td->getDeclContext())) {
5499  // Ignore declaration within a function.
5500  return;
5501  }
5502  clang::QualType type( td->getTypeForDecl(), 0 );
5503 
5504  auto declName=ND->getNameAsString();
5505  if (!TClass::HasNoInfoOrEmuOrFwdDeclaredDecl(declName.c_str())){
5506 // printf ("Impossible to find a TClassEntry in kNoInfo or kEmulated the decl of which would be called %s. Skip w/o building the normalized name.\n",declName );
5507  return;
5508  }
5509 
5511  } else {
5512  name = ND->getNameAsString();
5513  }
5514 
5515  // Supposedly we are being called while something is being
5516  // loaded ... let's now tell the autoloader to do the work
5517  // yet another time.
5518  int storedAutoloading = SetClassAutoloading(false);
5519  // FIXME: There can be more than one TClass for a single decl.
5520  // for example vector<double> and vector<Double32_t>
5521  TClass* cl = (TClass*)gROOT->GetListOfClasses()->FindObject(name.c_str());
5522  if (cl && GetModTClasses().find(cl) == GetModTClasses().end()) {
5524  if (cci) {
5525  // If we only had a forward declaration then update the
5526  // TClingClassInfo with the definition if we have it now.
5527  const TagDecl* tdOld = llvm::dyn_cast_or_null<TagDecl>(cci->GetDecl());
5528  if (!tdOld || (tdDef && tdDef != tdOld)) {
5529  cl->ResetCaches();
5531  if (td) {
5532  // It's a tag decl, not a namespace decl.
5533  cci->Init(*cci->GetType());
5535  }
5536  }
5537  } else if (!cl->TestBit(TClass::kLoading) && !cl->fHasRootPcmInfo) {
5538  cl->ResetCaches();
5539  // yes, this is almost a waste of time, but we do need to lookup
5540  // the 'type' corresponding to the TClass anyway in order to
5541  // preserve the opaque typedefs (Double32_t)
5542  cl->fClassInfo = (ClassInfo_t *)new TClingClassInfo(fInterpreter, cl->GetName());
5543  // We now need to update the state and bits.
5544  if (cl->fState != TClass::kHasTClassInit) {
5545  // if (!cl->fClassInfo->IsValid()) cl->fState = TClass::kForwardDeclared; else
5548  }
5549  TClass::AddClassToDeclIdMap(((TClingClassInfo*)(cl->fClassInfo))->GetDeclId(), cl);
5550  }
5551  }
5552  SetClassAutoloading(storedAutoloading);
5553 }
5554 
5555 ////////////////////////////////////////////////////////////////////////////////
5556 /// No op: see TClingCallbacks
5557 
5558 void TCling::UpdateClassInfo(char* item, Long_t tagnum)
5559 {
5560 }
5561 
5562 //______________________________________________________________________________
5563 //FIXME: Factor out that function in TClass, because TClass does it already twice
5564 void TCling::UpdateClassInfoWork(const char* item)
5565 {
5566  // This is a no-op as part of the API.
5567  // TCling uses UpdateClassInfoWithDecl() instead.
5568 }
5569 
5570 ////////////////////////////////////////////////////////////////////////////////
5571 /// Update all canvases at end the terminal input command.
5572 
5574 {
5575  TIter next(gROOT->GetListOfCanvases());
5576  TVirtualPad* canvas;
5577  while ((canvas = (TVirtualPad*)next())) {
5578  canvas->Update();
5579  }
5580 }
5581 
5582 ////////////////////////////////////////////////////////////////////////////////
5583 
5584 void TCling::UpdateListsOnCommitted(const cling::Transaction &T) {
5585  std::set<TClass*> modifiedTClasses; // TClasses that require update after this transaction
5586 
5587  // If the transaction does not contain anything we can return earlier.
5588  if (!HandleNewTransaction(T)) return;
5589 
5590  bool isTUTransaction = false;
5591  if (T.decls_end()-T.decls_begin() == 1 && !T.hasNestedTransactions()) {
5592  clang::Decl* FirstDecl = *(T.decls_begin()->m_DGR.begin());
5593  if (clang::TranslationUnitDecl* TU
5594  = dyn_cast<clang::TranslationUnitDecl>(FirstDecl)) {
5595  // The is the first transaction, we have to expose to meta
5596  // what's already in the AST.
5597  isTUTransaction = true;
5598 
5599  // FIXME: don't load the world. Really, don't. Maybe
5600  // instead smarten TROOT::GetListOfWhateveros() which
5601  // currently is a THashList but could be a
5602  // TInterpreterLookupCollection, one that reimplements
5603  // TCollection::FindObject(name) and performs a lookup
5604  // if not found in its T(Hash)List.
5605  cling::Interpreter::PushTransactionRAII RAII(fInterpreter);
5606  for (clang::DeclContext::decl_iterator TUI = TU->decls_begin(),
5607  TUE = TU->decls_end(); TUI != TUE; ++TUI)
5608  ((TCling*)gCling)->HandleNewDecl(*TUI, (*TUI)->isFromASTFile(),modifiedTClasses);
5609  }
5610  }
5611 
5612  std::set<const void*> TransactionDeclSet;
5613  if (!isTUTransaction && T.decls_end() - T.decls_begin()) {
5614  const clang::Decl* WrapperFD = T.getWrapperFD();
5615  for (cling::Transaction::const_iterator I = T.decls_begin(), E = T.decls_end();
5616  I != E; ++I) {
5617  if (I->m_Call != cling::Transaction::kCCIHandleTopLevelDecl
5618  && I->m_Call != cling::Transaction::kCCIHandleTagDeclDefinition)
5619  continue;
5620 
5621  for (DeclGroupRef::const_iterator DI = I->m_DGR.begin(),
5622  DE = I->m_DGR.end(); DI != DE; ++DI) {
5623  if (*DI == WrapperFD)
5624  continue;
5625  TransactionDeclSet.insert(*DI);
5626  ((TCling*)gCling)->HandleNewDecl(*DI, false, modifiedTClasses);
5627  }
5628  }
5629  }
5630 
5631  // The above might trigger more decls to be deserialized.
5632  // Thus the iteration over the deserialized decls must be last.
5633  for (cling::Transaction::const_iterator I = T.deserialized_decls_begin(),
5634  E = T.deserialized_decls_end(); I != E; ++I) {
5635  for (DeclGroupRef::const_iterator DI = I->m_DGR.begin(),
5636  DE = I->m_DGR.end(); DI != DE; ++DI)
5637  if (TransactionDeclSet.find(*DI) == TransactionDeclSet.end()) {
5638  //FIXME: HandleNewDecl should take DeclGroupRef
5639  ((TCling*)gCling)->HandleNewDecl(*DI, /*isDeserialized*/true,
5640  modifiedTClasses);
5641  }
5642  }
5643 
5644 
5645  // When fully building the reflection info in TClass, a deserialization
5646  // could be triggered, which may result in request for building the
5647  // reflection info for the same TClass. This in turn will clear the caches
5648  // for the TClass in-flight and cause null ptr derefs.
5649  // FIXME: This is a quick fix, solving most of the issues. The actual
5650  // question is: Shouldn't TClass provide a lock mechanism on update or lock
5651  // itself until the update is done.
5652  //
5653  std::vector<TClass*> modifiedTClassesDiff(modifiedTClasses.size());
5654  std::vector<TClass*>::iterator it;
5655  it = set_difference(modifiedTClasses.begin(), modifiedTClasses.end(),
5656  ((TCling*)gCling)->GetModTClasses().begin(),
5657  ((TCling*)gCling)->GetModTClasses().end(),
5658  modifiedTClassesDiff.begin());
5659  modifiedTClassesDiff.resize(it - modifiedTClassesDiff.begin());
5660 
5661  // Lock the TClass for updates
5662  ((TCling*)gCling)->GetModTClasses().insert(modifiedTClassesDiff.begin(),
5663  modifiedTClassesDiff.end());
5664  for (std::vector<TClass*>::const_iterator I = modifiedTClassesDiff.begin(),
5665  E = modifiedTClassesDiff.end(); I != E; ++I) {
5666  // Make sure the TClass has not been deleted.
5667  if (!gROOT->GetListOfClasses()->FindObject(*I)) {
5668  continue;
5669  }
5670  // Could trigger deserialization of decls.
5671  cling::Interpreter::PushTransactionRAII RAII(fInterpreter);
5672  // Unlock the TClass for updates
5673  ((TCling*)gCling)->GetModTClasses().erase(*I);
5674 
5675  }
5676 }
5677 
5678 ////////////////////////////////////////////////////////////////////////////////
5679 /// Helper function to go through the members of a class or namespace and unload them.
5680 
5681 void TCling::UnloadClassMembers(TClass* cl, const clang::DeclContext* DC) {
5682 
5683  TDataMember* var = 0;
5684  TFunction* function = 0;
5685  TEnum* e = 0;
5686  TFunctionTemplate* functiontemplate = 0;
5688  TListOfFunctions* functions = (TListOfFunctions*)cl->GetListOfMethods();
5689  TListOfEnums* enums = (TListOfEnums*)cl->GetListOfEnums();
5691  for (DeclContext::decl_iterator RI = DC->decls_begin(), RE = DC->decls_end(); RI != RE; ++RI) {
5692  if (isa<VarDecl>(*RI) || isa<FieldDecl>(*RI)) {
5693  const clang::ValueDecl* VD = dyn_cast<ValueDecl>(*RI);
5694  var = (TDataMember*)datamembers->FindObject(VD->getNameAsString().c_str());
5695  if (var) {
5696  // Unload the global by setting the DataMemberInfo_t to 0
5697  datamembers->Unload(var);
5698  var->Update(0);
5699  }
5700  } else if (const FunctionDecl* FD = dyn_cast<FunctionDecl>(*RI)) {
5701  function = (TFunction*)functions->FindObject(FD->getNameAsString().c_str());
5702  if (function) {
5703  functions->Unload(function);
5704  function->Update(0);
5705  }
5706  } else if (const EnumDecl* ED = dyn_cast<EnumDecl>(*RI)) {
5707  e = (TEnum*)enums->FindObject(ED->getNameAsString().c_str());
5708  if (e) {
5709  TIter iEnumConst(e->GetConstants());
5710  while (TEnumConstant* enumConst = (TEnumConstant*)iEnumConst()) {
5711  // Since the enum is already created and valid that ensures us that
5712  // we have the enum constants created as well.
5713  enumConst = (TEnumConstant*)datamembers->FindObject(enumConst->GetName());
5714  if (enumConst && enumConst->IsValid()) {
5715  datamembers->Unload(enumConst);
5716  enumConst->Update(0);
5717  }
5718  }
5719  enums->Unload(e);
5720  e->Update(0);
5721  }
5722  } else if (const FunctionTemplateDecl* FTD = dyn_cast<FunctionTemplateDecl>(*RI)) {
5723  functiontemplate = (TFunctionTemplate*)functiontemplates->FindObject(FTD->getNameAsString().c_str());
5724  if (functiontemplate) {
5725  functiontemplates->Unload(functiontemplate);
5726  functiontemplate->Update(0);
5727  }
5728  }
5729  }
5730 }
5731 
5732 ////////////////////////////////////////////////////////////////////////////////
5733 
5734 void TCling::UpdateListsOnUnloaded(const cling::Transaction &T)
5735 {
5737 
5738  // Unload the objects from the lists and update the objects' state.
5739  TListOfFunctions* functions = (TListOfFunctions*)gROOT->GetListOfGlobalFunctions();
5740  TListOfFunctionTemplates* functiontemplates = (TListOfFunctionTemplates*)gROOT->GetListOfFunctionTemplates();
5741  TListOfEnums* enums = (TListOfEnums*)gROOT->GetListOfEnums();
5742  TListOfDataMembers* globals = (TListOfDataMembers*)gROOT->GetListOfGlobals();
5743  cling::Transaction::const_nested_iterator iNested = T.nested_begin();
5744  for(cling::Transaction::const_iterator I = T.decls_begin(), E = T.decls_end();
5745  I != E; ++I) {
5746  if (I->m_Call == cling::Transaction::kCCIHandleVTable)
5747  continue;
5748 
5749  if (I->m_Call == cling::Transaction::kCCINone) {
5750  UpdateListsOnUnloaded(**iNested);
5751  ++iNested;
5752  continue;
5753  }
5754 
5755  for (DeclGroupRef::const_iterator DI = I->m_DGR.begin(),
5756  DE = I->m_DGR.end(); DI != DE; ++DI) {
5757 
5758  // Do not mark a decl as unloaded if we are going to keep it
5759  // (because it comes from the pch) ...
5760  if ( (*DI)->isFromASTFile() )
5761  continue;
5762 
5763  // Deal with global variables and global enum constants.
5764  if (isa<VarDecl>(*DI) || isa<EnumConstantDecl>(*DI)) {
5765  TObject *obj = globals->Find((TListOfDataMembers::DeclId_t)*DI);
5766  if (globals->GetClass()) {
5767  TDataMember* var = dynamic_cast<TDataMember*>(obj);
5768  if (var && var->IsValid()) {
5769  // Unload the global by setting the DataMemberInfo_t to 0
5770  globals->Unload(var);
5771  var->Update(0);
5772  }
5773  } else {
5774  TGlobal *g = dynamic_cast<TGlobal*>(obj);
5775  if (g && g->IsValid()) {
5776  // Unload the global by setting the DataMemberInfo_t to 0
5777  globals->Unload(g);
5778  g->Update(0);
5779  }
5780  }
5781  // Deal with global functions.
5782  } else if (const FunctionDecl* FD = dyn_cast<FunctionDecl>(*DI)) {
5783  TFunction* function = (TFunction*)functions->Find((TListOfFunctions::DeclId_t)FD);
5784  if (function && function->IsValid()) {
5785  functions->Unload(function);
5786  function->Update(0);
5787  }
5788  // Deal with global function templates.
5789  } else if (const FunctionTemplateDecl* FTD = dyn_cast<FunctionTemplateDecl>(*DI)) {
5790  TFunctionTemplate* functiontemplate = (TFunctionTemplate*)functiontemplates->FindObject(FTD->getNameAsString().c_str());
5791  if (functiontemplate) {
5792  functiontemplates->Unload(functiontemplate);
5793  functiontemplate->Update(0);
5794  }
5795  // Deal with global enums.
5796  } else if (const EnumDecl* ED = dyn_cast<EnumDecl>(*DI)) {
5797  if (TEnum* e = (TEnum*)enums->Find((TListOfEnums::DeclId_t)ED)) {
5798  globals = (TListOfDataMembers*)gROOT->GetListOfGlobals();
5799  TIter iEnumConst(e->GetConstants());
5800  while (TEnumConstant* enumConst = (TEnumConstant*)iEnumConst()) {
5801  // Since the enum is already created and valid that ensures us that
5802  // we have the enum constants created as well.
5803  enumConst = (TEnumConstant*)globals->FindObject(enumConst->GetName());
5804  if (enumConst) {
5805  globals->Unload(enumConst);
5806  enumConst->Update(0);
5807  }
5808  }
5809  enums->Unload(e);
5810  e->Update(0);
5811  }
5812  // Deal with classes. Unload the class and the data members will be not accessible anymore
5813  // Cannot declare the members in a different declaration like redeclarable namespaces.
5814  } else if (const clang::RecordDecl* RD = dyn_cast<RecordDecl>(*DI)) {
5815  std::vector<TClass*> vectTClass;
5816  // Only update the TClass if the definition is being unloaded.
5817  if (RD->isCompleteDefinition()) {
5818  if (TClass::GetClass(RD, vectTClass)) {
5819  for (std::vector<TClass*>::iterator CI = vectTClass.begin(), CE = vectTClass.end();
5820  CI != CE; ++CI) {
5821  UnloadClassMembers((*CI), RD);
5822  (*CI)->ResetClassInfo();
5823  }
5824  }
5825  }
5826  // Deal with namespaces. Unload the members of the current redeclaration only.
5827  } else if (const clang::NamespaceDecl* ND = dyn_cast<NamespaceDecl>(*DI)) {
5828  std::vector<TClass*> vectTClass;
5829  if (TClass::GetClass(ND->getCanonicalDecl(), vectTClass)) {
5830  for (std::vector<TClass*>::iterator CI = vectTClass.begin(), CE = vectTClass.end();
5831  CI != CE; ++CI) {
5832  UnloadClassMembers((*CI), ND);
5833  if (ND->isOriginalNamespace()) {
5834  (*CI)->ResetClassInfo();
5835  }
5836  }
5837  }
5838  }
5839  }
5840  }
5841 }
5842 
5843 ////////////////////////////////////////////////////////////////////////////////
5844 // If an autoparse was done during a transaction and that it is rolled back,
5845 // we need to make sure the next request for the same autoparse will be
5846 // honored.
5847 void TCling::TransactionRollback(const cling::Transaction &T) {
5848  auto const &triter = fTransactionHeadersMap.find(&T);
5849  if (triter != fTransactionHeadersMap.end()) {
5850  std::size_t normNameHash = triter->second;
5851 
5852  fLookedUpClasses.erase(normNameHash);
5853 
5854  auto const &iter = fClassesHeadersMap.find(normNameHash);
5855  if (iter != fClassesHeadersMap.end()) {
5856  auto const &hNamesPtrs = iter->second;
5857  for (auto &hName : hNamesPtrs) {
5858  if (gDebug > 0) {
5859  Info("TransactionRollback",
5860  "Restoring ability to autoaparse: %s", hName);
5861  }
5862  fParsedPayloadsAddresses.erase(hName);
5863  }
5864  }
5865  }
5866 }
5867 
5868 ////////////////////////////////////////////////////////////////////////////////
5869 
5870 void TCling::LibraryLoaded(const void* dyLibHandle, const char* canonicalName) {
5871 // UpdateListOfLoadedSharedLibraries();
5872 }
5873 
5874 ////////////////////////////////////////////////////////////////////////////////
5875 
5876 void TCling::LibraryUnloaded(const void* dyLibHandle, const char* canonicalName) {
5878  fSharedLibs = "";
5879 }
5880 
5881 ////////////////////////////////////////////////////////////////////////////////
5882 /// Return the list of shared libraries loaded into the process.
5883 
5885 {
5888  return fSharedLibs;
5889 }
5890 
5891 ////////////////////////////////////////////////////////////////////////////////
5892 /// Get the list of shared libraries containing the code for class cls.
5893 /// The first library in the list is the one containing the class, the
5894 /// others are the libraries the first one depends on. Returns 0
5895 /// in case the library is not found.
5896 
5897 const char* TCling::GetClassSharedLibs(const char* cls)
5898 {
5899  if (!cls || !*cls) {
5900  return 0;
5901  }
5902  // lookup class to find list of libraries
5903  if (fMapfile) {
5904  TEnvRec* libs_record = 0;
5905  libs_record = fMapfile->Lookup(cls);
5906  if (libs_record) {
5907  const char* libs = libs_record->GetValue();
5908  return (*libs) ? libs : 0;
5909  }
5910  else {
5911  // Try the old format...
5912  TString c = TString("Library.") + cls;
5913  // convert "::" to "@@", we used "@@" because TEnv
5914  // considers "::" a terminator
5915  c.ReplaceAll("::", "@@");
5916  // convert "-" to " ", since class names may have
5917  // blanks and TEnv considers a blank a terminator
5918  c.ReplaceAll(" ", "-");
5919  // Use TEnv::Lookup here as the rootmap file must start with Library.
5920  // and do not support using any stars (so we do not need to waste time
5921  // with the search made by TEnv::GetValue).
5922  TEnvRec* libs_record = 0;
5923  libs_record = fMapfile->Lookup(c);
5924  if (libs_record) {
5925  const char* libs = libs_record->GetValue();
5926  return (*libs) ? libs : 0;
5927  }
5928  }
5929  }
5930  return 0;
5931 }
5932 
5933 ////////////////////////////////////////////////////////////////////////////////
5934 /// Get the list a libraries on which the specified lib depends. The
5935 /// returned string contains as first element the lib itself.
5936 /// Returns 0 in case the lib does not exist or does not have
5937 /// any dependencies.
5938 
5939 const char* TCling::GetSharedLibDeps(const char* lib)
5940 {
5941  if (!fMapfile || !lib || !lib[0]) {
5942  return 0;
5943  }
5944  TString libname(lib);
5945  Ssiz_t idx = libname.Last('.');
5946  if (idx != kNPOS) {
5947  libname.Remove(idx);
5948  }
5949  TEnvRec* rec;
5951  size_t len = libname.Length();
5952  while ((rec = (TEnvRec*) next())) {
5953  const char* libs = rec->GetValue();
5954  if (!strncmp(libs, libname.Data(), len) && strlen(libs) >= len
5955  && (!libs[len] || libs[len] == ' ' || libs[len] == '.')) {
5956  return libs;
5957  }
5958  }
5959  return 0;
5960 }
5961 
5962 ////////////////////////////////////////////////////////////////////////////////
5963 /// If error messages are disabled, the interpreter should suppress its
5964 /// failures and warning messages from stdout.
5965 
5967 {
5968 #if defined(R__MUST_REVISIT)
5969 #if R__MUST_REVISIT(6,2)
5970  Warning("IsErrorMessagesEnabled", "Interface not available yet.");
5971 #endif
5972 #endif
5973  return kTRUE;
5974 }
5975 
5976 ////////////////////////////////////////////////////////////////////////////////
5977 /// If error messages are disabled, the interpreter should suppress its
5978 /// failures and warning messages from stdout. Return the previous state.
5979 
5981 {
5982 #if defined(R__MUST_REVISIT)
5983 #if R__MUST_REVISIT(6,2)
5984  Warning("SetErrorMessages", "Interface not available yet.");
5985 #endif
5986 #endif
5988 }
5989 
5990 ////////////////////////////////////////////////////////////////////////////////
5991 /// Refresh the list of include paths known to the interpreter and return it
5992 /// with -I prepended.
5993 
5995 {
5997 
5998  fIncludePath = "";
5999 
6000  llvm::SmallVector<std::string, 10> includePaths;//Why 10? Hell if I know.
6001  //false - no system header, true - with flags.
6002  fInterpreter->GetIncludePaths(includePaths, false, true);
6003  if (const size_t nPaths = includePaths.size()) {
6004  assert(!(nPaths & 1) && "GetIncludePath, number of paths and options is not equal");
6005 
6006  for (size_t i = 0; i < nPaths; i += 2) {
6007  if (i)
6008  fIncludePath.Append(' ');
6009  fIncludePath.Append(includePaths[i].c_str());
6010 
6011  if (includePaths[i] != "-I")
6012  fIncludePath.Append(' ');
6013  fIncludePath.Append('"');
6014  fIncludePath.Append(includePaths[i + 1], includePaths[i + 1].length());
6015  fIncludePath.Append('"');
6016  }
6017  }
6018 
6019  return fIncludePath;
6020 }
6021 
6022 ////////////////////////////////////////////////////////////////////////////////
6023 /// Return the directory containing CINT's stl cintdlls.
6024 
6025 const char* TCling::GetSTLIncludePath() const
6026 {
6027  return "";
6028 }
6029 
6030 //______________________________________________________________________________
6031 // M I S C
6032 //______________________________________________________________________________
6033 
6034 int TCling::DisplayClass(FILE* /*fout*/, const char* /*name*/, int /*base*/, int /*start*/) const
6035 {
6036  // Interface to cling function
6037  return 0;
6038 }
6039 
6040 ////////////////////////////////////////////////////////////////////////////////
6041 /// Interface to cling function
6042 
6043 int TCling::DisplayIncludePath(FILE *fout) const
6044 {
6045  assert(fout != 0 && "DisplayIncludePath, 'fout' parameter is null");
6046 
6047  llvm::SmallVector<std::string, 10> includePaths;//Why 10? Hell if I know.
6048  //false - no system header, true - with flags.
6049  fInterpreter->GetIncludePaths(includePaths, false, true);
6050  if (const size_t nPaths = includePaths.size()) {
6051  assert(!(nPaths & 1) && "DisplayIncludePath, number of paths and options is not equal");
6052 
6053  std::string allIncludes("include path:");
6054  for (size_t i = 0; i < nPaths; i += 2) {
6055  allIncludes += ' ';
6056  allIncludes += includePaths[i];
6057 
6058  if (includePaths[i] != "-I")
6059  allIncludes += ' ';
6060  allIncludes += includePaths[i + 1];
6061  }
6062 
6063  fprintf(fout, "%s\n", allIncludes.c_str());
6064  }
6065 
6066  return 0;
6067 }
6068 
6069 ////////////////////////////////////////////////////////////////////////////////
6070 /// Interface to cling function
6071 
6072 void* TCling::FindSym(const char* entry) const
6073 {
6074  return fInterpreter->getAddressOfGlobal(entry);
6075 }
6076 
6077 ////////////////////////////////////////////////////////////////////////////////
6078 /// Let the interpreter issue a generic error, and set its error state.
6079 
6080 void TCling::GenericError(const char* error) const
6081 {
6082 #if defined(R__MUST_REVISIT)
6083 #if R__MUST_REVISIT(6,2)
6084  Warning("GenericError","Interface not available yet.");
6085 #endif
6086 #endif
6087 }
6088 
6089 ////////////////////////////////////////////////////////////////////////////////
6090 /// This routines used to return the address of the internal wrapper
6091 /// function (of the interpreter) that was used to call *all* the
6092 /// interpreted functions that were bytecode compiled (no longer
6093 /// interpreted line by line). In Cling, there is no such
6094 /// wrapper function.
6095 /// In practice this routines was use to decipher whether the
6096 /// pointer returns by InterfaceMethod could be used to uniquely
6097 /// represent the function. In Cling if the function is in a
6098 /// useable state (its compiled version is available), this is
6099 /// always the case.
6100 /// See TClass::GetMethod.
6101 
6103 {
6104  return 0;
6105 }
6106 
6107 ////////////////////////////////////////////////////////////////////////////////
6108 /// Interface to the CINT global object pointer which was controlling the
6109 /// behavior of the wrapper around the calls to operator new and the constructor
6110 /// and operator delete and the destructor.
6111 
6113 {
6114  Error("Getgvp","This was controlling the behavior of the wrappers for object construction and destruction.\nThis is now a nop and likely change the behavior of the calling routines.");
6115  return 0;
6116 }
6117 
6118 ////////////////////////////////////////////////////////////////////////////////
6119 
6120 const char* TCling::Getp2f2funcname(void*) const
6121 {
6122  Error("Getp2f2funcname", "Will not be implemented: "
6123  "all function pointers are compiled!");
6124  return NULL;
6125 }
6126 
6127 ////////////////////////////////////////////////////////////////////////////////
6128 /// Interface to cling function
6129 
6131 {
6132 #if defined(R__MUST_REVISIT)
6133 #if R__MUST_REVISIT(6,2)
6134  Warning("GetSecurityError", "Interface not available yet.");
6135 #endif
6136 #endif
6137  return 0;
6138 }
6139 
6140 ////////////////////////////////////////////////////////////////////////////////
6141 /// Load a source file or library called path into the interpreter.
6142 
6143 int TCling::LoadFile(const char* path) const
6144 {
6145  cling::Interpreter::CompilationResult compRes;
6146  cling::MetaProcessor::MaybeRedirectOutputRAII RAII(fMetaProcessor);
6147  fMetaProcessor->process(TString::Format(".L %s", path), compRes, /*cling::Value*/0);
6148  return compRes == cling::Interpreter::kFailure;
6149 }
6150 
6151 ////////////////////////////////////////////////////////////////////////////////
6152 /// Load the declarations from text into the interpreter.
6153 /// Note that this cannot be (top level) statements; text must contain
6154 /// top level declarations.
6155 /// Returns true on success, false on failure.
6156 
6157 Bool_t TCling::LoadText(const char* text) const
6158 {
6159  return (fInterpreter->declare(text) == cling::Interpreter::kSuccess);
6160 }
6161 
6162 ////////////////////////////////////////////////////////////////////////////////
6163 /// Interface to cling function
6164 
6165 const char* TCling::MapCppName(const char* name) const
6166 {
6167  TTHREAD_TLS_DECL(std::string,buffer);
6168  ROOT::TMetaUtils::GetCppName(buffer,name);
6169  return buffer.c_str();
6170 }
6171 
6172 ////////////////////////////////////////////////////////////////////////////////
6173 /// [Place holder for Mutex Lock]
6174 /// Provide the interpreter with a way to
6175 /// acquire a lock used to protect critical section
6176 /// of its code (non-thread safe parts).
6177 
6178 void TCling::SetAlloclockfunc(void (* /* p */ )()) const
6179 {
6180  // nothing to do for now.
6181 }
6182 
6183 ////////////////////////////////////////////////////////////////////////////////
6184 /// [Place holder for Mutex Unlock] Provide the interpreter with a way to
6185 /// release a lock used to protect critical section
6186 /// of its code (non-thread safe parts).
6187 
6188 void TCling::SetAllocunlockfunc(void (* /* p */ )()) const
6189 {
6190  // nothing to do for now.
6191 }
6192 
6193 ////////////////////////////////////////////////////////////////////////////////
6194 /// Enable/Disable the Autoloading of libraries.
6195 /// Returns the old value, i.e whether it was enabled or not.
6196 
6197 int TCling::SetClassAutoloading(int autoload) const
6198 {
6199  if (!autoload && !fClingCallbacks) return false;
6200  if (!fAllowLibLoad) return false;
6201 
6202  assert(fClingCallbacks && "We must have callbacks!");
6203  bool oldVal = fClingCallbacks->IsAutoloadingEnabled();
6205  return oldVal;
6206 }
6207 
6208 ////////////////////////////////////////////////////////////////////////////////
6209 /// Enable/Disable the Autoparsing of headers.
6210 /// Returns the old value, i.e whether it was enabled or not.
6211 
6213 {
6214  bool oldVal = fHeaderParsingOnDemand;
6215  fHeaderParsingOnDemand = autoparse;
6216  return oldVal;
6217 }
6218 
6219 ////////////////////////////////////////////////////////////////////////////////
6220 /// Suspend the Autoparsing of headers.
6221 /// Returns the old value, i.e whether it was suspended or not.
6222 
6227  return old;
6228 }
6229 
6230 ////////////////////////////////////////////////////////////////////////////////
6231 /// Set a callback to receive error messages.
6232 
6233 void TCling::SetErrmsgcallback(void* p) const
6234 {
6235 #if defined(R__MUST_REVISIT)
6236 #if R__MUST_REVISIT(6,2)
6237  Warning("SetErrmsgcallback", "Interface not available yet.");
6238 #endif
6239 #endif
6240 }
6241 
6242 ////////////////////////////////////////////////////////////////////////////////
6243 /// Interface to the cling global object pointer which was controlling the
6244 /// behavior of the wrapper around the calls to operator new and the constructor
6245 /// and operator delete and the destructor.
6246 
6247 void TCling::Setgvp(Long_t gvp) const
6248 {
6249  Error("Setgvp","This was controlling the behavior of the wrappers for object construction and destruction.\nThis is now a nop and likely change the behavior of the calling routines.");
6250 
6251 }
6252 
6253 ////////////////////////////////////////////////////////////////////////////////
6254 
6256 {
6257  Error("SetRTLD_NOW()", "Will never be implemented! Don't use!");
6258 }
6259 
6260 ////////////////////////////////////////////////////////////////////////////////
6261 
6263 {
6264  Error("SetRTLD_LAZY()", "Will never be implemented! Don't use!");
6265 }
6266 
6267 ////////////////////////////////////////////////////////////////////////////////
6268 /// Create / close a scope for temporaries. No-op for cling; use
6269 /// cling::Value instead.
6270 
6271 void TCling::SetTempLevel(int val) const
6272 {
6273 }
6274 
6275 ////////////////////////////////////////////////////////////////////////////////
6276 
6277 int TCling::UnloadFile(const char* path) const
6278 {
6279  cling::DynamicLibraryManager* DLM = fInterpreter->getDynamicLibraryManager();
6280  std::string canonical = DLM->lookupLibrary(path);
6281  if (canonical.empty()) {
6282  canonical = path;
6283  }
6284  // Unload a shared library or a source file.
6285  cling::Interpreter::CompilationResult compRes;
6286  cling::MetaProcessor::MaybeRedirectOutputRAII RAII(fMetaProcessor);
6287  fMetaProcessor->process(Form(".U %s", canonical.c_str()), compRes, /*cling::Value*/0);
6288  return compRes == cling::Interpreter::kFailure;
6289 }
6290 
6291 ////////////////////////////////////////////////////////////////////////////////
6292 /// The created temporary must be deleted by the caller.
6293 
6295 {
6296  TClingValue *val = new TClingValue;
6297  return val;
6298 }
6299 
6300 ////////////////////////////////////////////////////////////////////////////////
6301 
6303 {
6304  using namespace cling;
6305  const Value* V = reinterpret_cast<const Value*>(value.GetValAddr());
6306  RegisterTemporary(*V);
6307 }
6308 
6309 ////////////////////////////////////////////////////////////////////////////////
6310 /// Register value as a temporary, extending its lifetime to that of the
6311 /// interpreter. This is needed for TCling's compatibility interfaces
6312 /// returning long - the address of the temporary objects.
6313 /// As such, "simple" types don't need to be stored; they are returned by
6314 /// value; only pointers / references / objects need to be stored.
6315 
6317 {
6318  if (value.isValid() && value.needsManagedAllocation()) {
6320  fTemporaries->push_back(value);
6321  }
6322 }
6323 
6324 ////////////////////////////////////////////////////////////////////////////////
6325 /// If the interpreter encounters Name, check whether that is an object ROOT
6326 /// could retrieve. To not re-read objects from disk, cache the name/object
6327 /// pair for a given LookupCtx.
6328 
6329 TObject* TCling::GetObjectAddress(const char *Name, void *&LookupCtx)
6330 {
6331  cling::Interpreter *interpreter = ((TCling*)gCling)->GetInterpreter();
6332 
6333  // The call to FindSpecialObject might induces any kind of use
6334  // of the interpreter ... (library loading, function calling, etc.)
6335  // ... and we _know_ we are in the middle of parsing, so let's make
6336  // sure to save the state and then restore it.
6337 
6338  if (gDirectory) {
6339  auto iSpecObjMap = fSpecialObjectMaps.find(gDirectory);
6340  if (iSpecObjMap != fSpecialObjectMaps.end()) {
6341  auto iSpecObj = iSpecObjMap->second.find(Name);
6342  if (iSpecObj != iSpecObjMap->second.end()) {
6343  LookupCtx = gDirectory;
6344  return iSpecObj->second;
6345  }
6346  }
6347  }
6348 
6349  // Save state of the PP
6350  Sema &SemaR = interpreter->getSema();
6351  ASTContext& C = SemaR.getASTContext();
6352  Preprocessor &PP = SemaR.getPreprocessor();
6353  Parser& P = const_cast<Parser&>(interpreter->getParser());
6354  Preprocessor::CleanupAndRestoreCacheRAII cleanupRAII(PP);
6355  Parser::ParserCurTokRestoreRAII savedCurToken(P);
6356  // After we have saved the token reset the current one to something which
6357  // is safe (semi colon usually means empty decl)
6358  Token& Tok = const_cast<Token&>(P.getCurToken());
6359  Tok.setKind(tok::semi);
6360 
6361  // We can't PushDeclContext, because we go up and the routine that pops
6362  // the DeclContext assumes that we drill down always.
6363  // We have to be on the global context. At that point we are in a
6364  // wrapper function so the parent context must be the global.
6365  Sema::ContextAndScopeRAII pushedDCAndS(SemaR, C.getTranslationUnitDecl(),
6366  SemaR.TUScope);
6367 
6368  TObject* specObj = gROOT->FindSpecialObject(Name, LookupCtx);
6369  if (specObj) {
6370  if (!LookupCtx) {
6371  Error("GetObjectAddress", "Got a special object without LookupCtx!");
6372  } else {
6373  fSpecialObjectMaps[LookupCtx][Name] = specObj;
6374  }
6375  }
6376  return specObj;
6377 }
6378 
6379 ////////////////////////////////////////////////////////////////////////////////
6380 /// Inject function as a friend into klass.
6381 /// With function being f in void f() {new N::PrivKlass(); } this enables
6382 /// I/O of non-public classes.
6383 
6384 void TCling::AddFriendToClass(clang::FunctionDecl* function,
6385  clang::CXXRecordDecl* klass) const
6386 {
6387  using namespace clang;
6388  ASTContext& Ctx = klass->getASTContext();
6389  FriendDecl::FriendUnion friendUnion(function);
6390  // one dummy object for the source location
6391  SourceLocation sl;
6392  FriendDecl* friendDecl = FriendDecl::Create(Ctx, klass, sl, friendUnion, sl);
6393  klass->pushFriendDecl(friendDecl);
6394 }
6395 
6396 //______________________________________________________________________________
6397 //
6398 // DeclId getter.
6399 //
6400 
6401 ////////////////////////////////////////////////////////////////////////////////
6402 /// Return a unique identifier of the declaration represented by the
6403 /// CallFunc
6404 
6406 {
6407  if (func) return ((TClingCallFunc*)func)->GetDecl()->getCanonicalDecl();
6408  return 0;
6409 }
6410 
6411 ////////////////////////////////////////////////////////////////////////////////
6412 /// Return a (almost) unique identifier of the declaration represented by the
6413 /// ClassInfo. In ROOT, this identifier can point to more than one TClass
6414 /// when the underlying class is a template instance involving one of the
6415 /// opaque typedef.
6416 
6418 {
6419  if (cinfo) return ((TClingClassInfo*)cinfo)->GetDeclId();
6420  return 0;
6421 }
6422 
6423 ////////////////////////////////////////////////////////////////////////////////
6424 /// Return a unique identifier of the declaration represented by the
6425 /// MethodInfo
6426 
6427 TInterpreter::DeclId_t TCling::GetDeclId(DataMemberInfo_t* data) const
6428 {
6429  if (data) return ((TClingDataMemberInfo*)data)->GetDeclId();
6430  return 0;
6431 }
6432 
6433 ////////////////////////////////////////////////////////////////////////////////
6434 /// Return a unique identifier of the declaration represented by the
6435 /// MethodInfo
6436 
6437 TInterpreter::DeclId_t TCling::GetDeclId(MethodInfo_t* method) const
6438 {
6439  if (method) return ((TClingMethodInfo*)method)->GetDeclId();
6440  return 0;
6441 }
6442 
6443 ////////////////////////////////////////////////////////////////////////////////
6444 /// Return a unique identifier of the declaration represented by the
6445 /// TypedefInfo
6446 
6447 TInterpreter::DeclId_t TCling::GetDeclId(TypedefInfo_t* tinfo) const
6448 {
6449  if (tinfo) return ((TClingTypedefInfo*)tinfo)->GetDecl()->getCanonicalDecl();
6450  return 0;
6451 }
6452 
6453 //______________________________________________________________________________
6454 //
6455 // CallFunc interface
6456 //
6457 
6458 ////////////////////////////////////////////////////////////////////////////////
6459 
6460 void TCling::CallFunc_Delete(CallFunc_t* func) const
6461 {
6462  delete (TClingCallFunc*) func;
6463 }
6464 
6465 ////////////////////////////////////////////////////////////////////////////////
6466 
6467 void TCling::CallFunc_Exec(CallFunc_t* func, void* address) const
6468 {
6469  TClingCallFunc* f = (TClingCallFunc*) func;
6470  f->Exec(address);
6471 }
6472 
6473 ////////////////////////////////////////////////////////////////////////////////
6474 
6475 void TCling::CallFunc_Exec(CallFunc_t* func, void* address, TInterpreterValue& val) const
6476 {
6477  TClingCallFunc* f = (TClingCallFunc*) func;
6478  f->Exec(address, &val);
6479 }
6480 
6481 ////////////////////////////////////////////////////////////////////////////////
6482 
6483 void TCling::CallFunc_ExecWithReturn(CallFunc_t* func, void* address, void* ret) const
6484 {
6485  TClingCallFunc* f = (TClingCallFunc*) func;
6486  f->ExecWithReturn(address, ret);
6487 }
6488 
6489 ////////////////////////////////////////////////////////////////////////////////
6490 
6491 void TCling::CallFunc_ExecWithArgsAndReturn(CallFunc_t* func, void* address,
6492  const void* args[] /*=0*/,
6493  int nargs /*=0*/,
6494  void* ret/*=0*/) const
6495 {
6496  TClingCallFunc* f = (TClingCallFunc*) func;
6497  f->ExecWithArgsAndReturn(address, args, nargs, ret);
6498 }
6499 
6500 ////////////////////////////////////////////////////////////////////////////////
6501 
6502 Long_t TCling::CallFunc_ExecInt(CallFunc_t* func, void* address) const
6503 {
6504  TClingCallFunc* f = (TClingCallFunc*) func;
6505  return f->ExecInt(address);
6506 }
6507 
6508 ////////////////////////////////////////////////////////////////////////////////
6509 
6510 Long64_t TCling::CallFunc_ExecInt64(CallFunc_t* func, void* address) const
6511 {
6512  TClingCallFunc* f = (TClingCallFunc*) func;
6513  return f->ExecInt64(address);
6514 }
6515 
6516 ////////////////////////////////////////////////////////////////////////////////
6517 
6518 Double_t TCling::CallFunc_ExecDouble(CallFunc_t* func, void* address) const
6519 {
6520  TClingCallFunc* f = (TClingCallFunc*) func;
6521  return f->ExecDouble(address);
6522 }
6523 
6524 ////////////////////////////////////////////////////////////////////////////////
6525 
6526 CallFunc_t* TCling::CallFunc_Factory() const
6527 {
6529  return (CallFunc_t*) new TClingCallFunc(fInterpreter,*fNormalizedCtxt);
6530 }
6531 
6532 ////////////////////////////////////////////////////////////////////////////////
6533 
6534 CallFunc_t* TCling::CallFunc_FactoryCopy(CallFunc_t* func) const
6535 {
6536  return (CallFunc_t*) new TClingCallFunc(*(TClingCallFunc*)func);
6537 }
6538 
6539 ////////////////////////////////////////////////////////////////////////////////
6540 
6541 MethodInfo_t* TCling::CallFunc_FactoryMethod(CallFunc_t* func) const
6542 {
6543  TClingCallFunc* f = (TClingCallFunc*) func;
6544  return (MethodInfo_t*) f->FactoryMethod();
6545 }
6546 
6547 ////////////////////////////////////////////////////////////////////////////////
6548 
6549 void TCling::CallFunc_IgnoreExtraArgs(CallFunc_t* func, bool ignore) const
6550 {
6551  TClingCallFunc* f = (TClingCallFunc*) func;
6552  f->IgnoreExtraArgs(ignore);
6553 }
6554 
6555 ////////////////////////////////////////////////////////////////////////////////
6556 
6557 void TCling::CallFunc_Init(CallFunc_t* func) const
6558 {
6560  TClingCallFunc* f = (TClingCallFunc*) func;
6561  f->Init();
6562 }
6563 
6564 ////////////////////////////////////////////////////////////////////////////////
6565 
6566 bool TCling::CallFunc_IsValid(CallFunc_t* func) const
6567 {
6568  TClingCallFunc* f = (TClingCallFunc*) func;
6569  return f->IsValid();
6570 }
6571 
6572 ////////////////////////////////////////////////////////////////////////////////
6573 
6575 TCling::CallFunc_IFacePtr(CallFunc_t * func) const
6576 {
6577  TClingCallFunc* f = (TClingCallFunc*) func;
6578  return f->IFacePtr();
6579 }
6580 
6581 ////////////////////////////////////////////////////////////////////////////////
6582 
6583 void TCling::CallFunc_ResetArg(CallFunc_t* func) const
6584 {
6585  TClingCallFunc* f = (TClingCallFunc*) func;
6586  f->ResetArg();
6587 }
6588 
6589 ////////////////////////////////////////////////////////////////////////////////
6590 
6591 void TCling::CallFunc_SetArg(CallFunc_t* func, Long_t param) const
6592 {
6593  TClingCallFunc* f = (TClingCallFunc*) func;
6594  f->SetArg(param);
6595 }
6596 
6597 ////////////////////////////////////////////////////////////////////////////////
6598 
6599 void TCling::CallFunc_SetArg(CallFunc_t* func, ULong_t param) const
6600 {
6601  TClingCallFunc* f = (TClingCallFunc*) func;
6602  f->SetArg(param);
6603 }
6604 
6605 ////////////////////////////////////////////////////////////////////////////////
6606 
6607 void TCling::CallFunc_SetArg(CallFunc_t* func, Float_t param) const
6608 {
6609  TClingCallFunc* f = (TClingCallFunc*) func;
6610  f->SetArg(param);
6611 }
6612 
6613 ////////////////////////////////////////////////////////////////////////////////
6614 
6615 void TCling::CallFunc_SetArg(CallFunc_t* func, Double_t param) const
6616 {
6617  TClingCallFunc* f = (TClingCallFunc*) func;
6618  f->SetArg(param);
6619 }
6620 
6621 ////////////////////////////////////////////////////////////////////////////////
6622 
6623 void TCling::CallFunc_SetArg(CallFunc_t* func, Long64_t param) const
6624 {
6625  TClingCallFunc* f = (TClingCallFunc*) func;
6626  f->SetArg(param);
6627 }
6628 
6629 ////////////////////////////////////////////////////////////////////////////////
6630 
6631 void TCling::CallFunc_SetArg(CallFunc_t* func, ULong64_t param) const
6632 {
6633  TClingCallFunc* f = (TClingCallFunc*) func;
6634  f->SetArg(param);
6635 }
6636 
6637 ////////////////////////////////////////////////////////////////////////////////
6638 
6639 void TCling::CallFunc_SetArgArray(CallFunc_t* func, Long_t* paramArr, Int_t nparam) const
6640 {
6641  TClingCallFunc* f = (TClingCallFunc*) func;
6642  f->SetArgArray(paramArr, nparam);
6643 }
6644 
6645 ////////////////////////////////////////////////////////////////////////////////
6646 
6647 void TCling::CallFunc_SetArgs(CallFunc_t* func, const char* param) const
6648 {
6649  TClingCallFunc* f = (TClingCallFunc*) func;
6650  f->SetArgs(param);
6651 }
6652 
6653 ////////////////////////////////////////////////////////////////////////////////
6654 
6655 void TCling::CallFunc_SetFunc(CallFunc_t* func, ClassInfo_t* info, const char* method, const char* params, Long_t* offset) const
6656 {
6657  TClingCallFunc* f = (TClingCallFunc*) func;
6658  TClingClassInfo* ci = (TClingClassInfo*) info;
6659  f->SetFunc(ci, method, params, offset);
6660 }
6661 
6662 ////////////////////////////////////////////////////////////////////////////////
6663 
6664 void TCling::CallFunc_SetFunc(CallFunc_t* func, ClassInfo_t* info, const char* method, const char* params, bool objectIsConst, Long_t* offset) const
6665 {
6666  TClingCallFunc* f = (TClingCallFunc*) func;
6667  TClingClassInfo* ci = (TClingClassInfo*) info;
6668  f->SetFunc(ci, method, params, objectIsConst, offset);
6669 }
6670 ////////////////////////////////////////////////////////////////////////////////
6671 
6672 void TCling::CallFunc_SetFunc(CallFunc_t* func, MethodInfo_t* info) const
6673 {
6674  TClingCallFunc* f = (TClingCallFunc*) func;
6675  TClingMethodInfo* minfo = (TClingMethodInfo*) info;
6676  f->SetFunc(minfo);
6677 }
6678 
6679 ////////////////////////////////////////////////////////////////////////////////
6680 /// Interface to cling function
6681 
6682 void TCling::CallFunc_SetFuncProto(CallFunc_t* func, ClassInfo_t* info, const char* method, const char* proto, Long_t* offset, EFunctionMatchMode mode /* = kConversionMatch */) const
6683 {
6684  TClingCallFunc* f = (TClingCallFunc*) func;
6685  TClingClassInfo* ci = (TClingClassInfo*) info;
6686  f->SetFuncProto(ci, method, proto, offset, mode);
6687 }
6688 
6689 ////////////////////////////////////////////////////////////////////////////////
6690 /// Interface to cling function
6691 
6692 void TCling::CallFunc_SetFuncProto(CallFunc_t* func, ClassInfo_t* info, const char* method, const char* proto, bool objectIsConst, Long_t* offset, EFunctionMatchMode mode /* = kConversionMatch */) const
6693 {
6694  TClingCallFunc* f = (TClingCallFunc*) func;
6695  TClingClassInfo* ci = (TClingClassInfo*) info;
6696  f->SetFuncProto(ci, method, proto, objectIsConst, offset, mode);
6697 }
6698 
6699 ////////////////////////////////////////////////////////////////////////////////
6700 /// Interface to cling function
6701 
6702 void TCling::CallFunc_SetFuncProto(CallFunc_t* func, ClassInfo_t* info, const char* method, const std::vector<TypeInfo_t*> &proto, Long_t* offset, EFunctionMatchMode mode /* = kConversionMatch */) const
6703 {
6704  TClingCallFunc* f = (TClingCallFunc*) func;
6705  TClingClassInfo* ci = (TClingClassInfo*) info;
6706  llvm::SmallVector<clang::QualType, 4> funcProto;
6707  for (std::vector<TypeInfo_t*>::const_iterator iter = proto.begin(), end = proto.end();
6708  iter != end; ++iter) {
6709  funcProto.push_back( ((TClingTypeInfo*)(*iter))->GetQualType() );
6710  }
6711  f->SetFuncProto(ci, method, funcProto, offset, mode);
6712 }
6713 
6714 ////////////////////////////////////////////////////////////////////////////////
6715 /// Interface to cling function
6716 
6717 void TCling::CallFunc_SetFuncProto(CallFunc_t* func, ClassInfo_t* info, const char* method, const std::vector<TypeInfo_t*> &proto, bool objectIsConst, Long_t* offset, EFunctionMatchMode mode /* = kConversionMatch */) const
6718 {
6719  TClingCallFunc* f = (TClingCallFunc*) func;
6720  TClingClassInfo* ci = (TClingClassInfo*) info;
6721  llvm::SmallVector<clang::QualType, 4> funcProto;
6722  for (std::vector<TypeInfo_t*>::const_iterator iter = proto.begin(), end = proto.end();
6723  iter != end; ++iter) {
6724  funcProto.push_back( ((TClingTypeInfo*)(*iter))->GetQualType() );
6725  }
6726  f->SetFuncProto(ci, method, funcProto, objectIsConst, offset, mode);
6727 }
6728 
6729 //______________________________________________________________________________
6730 //
6731 // ClassInfo interface
6732 //
6733 
6734 ////////////////////////////////////////////////////////////////////////////////
6735 /// Return true if the entity pointed to by 'declid' is declared in
6736 /// the context described by 'info'. If info is null, look into the
6737 /// global scope (translation unit scope).
6738 
6739 Bool_t TCling::ClassInfo_Contains(ClassInfo_t *info, DeclId_t declid) const
6740 {
6741  if (!declid) return kFALSE;
6742 
6743  const clang::Decl *scope;
6744  if (info) scope = ((TClingClassInfo*)info)->GetDecl();
6745  else scope = fInterpreter->getCI()->getASTContext().getTranslationUnitDecl();
6746 
6747  const clang::Decl *decl = reinterpret_cast<const clang::Decl*>(declid);
6748  const clang::DeclContext *ctxt = clang::Decl::castToDeclContext(scope);
6749  if (!decl || !ctxt) return kFALSE;
6750  if (decl->getDeclContext()->Equals(ctxt))
6751  return kTRUE;
6752  else if (decl->getDeclContext()->isTransparentContext() &&
6753  decl->getDeclContext()->getParent()->Equals(ctxt))
6754  return kTRUE;
6755  return kFALSE;
6756 }
6757 
6758 ////////////////////////////////////////////////////////////////////////////////
6759 
6760 Long_t TCling::ClassInfo_ClassProperty(ClassInfo_t* cinfo) const
6761 {
6762  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
6763  return TClinginfo->ClassProperty();
6764 }
6765 
6766 ////////////////////////////////////////////////////////////////////////////////
6767 
6768 void TCling::ClassInfo_Delete(ClassInfo_t* cinfo) const
6769 {
6770  delete (TClingClassInfo*) cinfo;
6771 }
6772 
6773 ////////////////////////////////////////////////////////////////////////////////
6774 
6775 void TCling::ClassInfo_Delete(ClassInfo_t* cinfo, void* arena) const
6776 {
6777  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
6778  TClinginfo->Delete(arena,*fNormalizedCtxt);
6779 }
6780 
6781 ////////////////////////////////////////////////////////////////////////////////
6782 
6783 void TCling::ClassInfo_DeleteArray(ClassInfo_t* cinfo, void* arena, bool dtorOnly) const
6784 {
6785  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
6786  TClinginfo->DeleteArray(arena, dtorOnly,*fNormalizedCtxt);
6787 }
6788 
6789 ////////////////////////////////////////////////////////////////////////////////
6790 
6791 void TCling::ClassInfo_Destruct(ClassInfo_t* cinfo, void* arena) const
6792 {
6793  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
6794  TClinginfo->Destruct(arena,*fNormalizedCtxt);
6795 }
6796 
6797 ////////////////////////////////////////////////////////////////////////////////
6798 
6799 ClassInfo_t* TCling::ClassInfo_Factory(Bool_t all) const
6800 {
6802  return (ClassInfo_t*) new TClingClassInfo(fInterpreter, all);
6803 }
6804 
6805 ////////////////////////////////////////////////////////////////////////////////
6806 
6807 ClassInfo_t* TCling::ClassInfo_Factory(ClassInfo_t* cinfo) const
6808 {
6809  return (ClassInfo_t*) new TClingClassInfo(*(TClingClassInfo*)cinfo);
6810 }
6811 
6812 ////////////////////////////////////////////////////////////////////////////////
6813 
6814 ClassInfo_t* TCling::ClassInfo_Factory(const char* name) const
6815 {
6817  return (ClassInfo_t*) new TClingClassInfo(fInterpreter, name);
6818 }
6819 
6820 ////////////////////////////////////////////////////////////////////////////////
6821 
6822 int TCling::ClassInfo_GetMethodNArg(ClassInfo_t* cinfo, const char* method, const char* proto, Bool_t objectIsConst /* = false */, EFunctionMatchMode mode /* = kConversionMatch */) const
6823 {
6824  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
6825  return TClinginfo->GetMethodNArg(method, proto, objectIsConst, mode);
6826 }
6827 
6828 ////////////////////////////////////////////////////////////////////////////////
6829 
6830 bool TCling::ClassInfo_HasDefaultConstructor(ClassInfo_t* cinfo) const
6831 {
6832  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
6833  return TClinginfo->HasDefaultConstructor();
6834 }
6835 
6836 ////////////////////////////////////////////////////////////////////////////////
6837 
6838 bool TCling::ClassInfo_HasMethod(ClassInfo_t* cinfo, const char* name) const
6839 {
6840  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
6841  return TClinginfo->HasMethod(name);
6842 }
6843 
6844 ////////////////////////////////////////////////////////////////////////////////
6845 
6846 void TCling::ClassInfo_Init(ClassInfo_t* cinfo, const char* name) const
6847 {
6849  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
6850  TClinginfo->Init(name);
6851 }
6852 
6853 ////////////////////////////////////////////////////////////////////////////////
6854 
6855 void TCling::ClassInfo_Init(ClassInfo_t* cinfo, int tagnum) const
6856 {
6858  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
6859  TClinginfo->Init(tagnum);
6860 }
6861 
6862 ////////////////////////////////////////////////////////////////////////////////
6863 
6864 bool TCling::ClassInfo_IsBase(ClassInfo_t* cinfo, const char* name) const
6865 {
6866  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
6867  return TClinginfo->IsBase(name);
6868 }
6869 
6870 ////////////////////////////////////////////////////////////////////////////////
6871 
6872 bool TCling::ClassInfo_IsEnum(const char* name) const
6873 {
6874  return TClingClassInfo::IsEnum(fInterpreter, name);
6875 }
6876 
6877 ////////////////////////////////////////////////////////////////////////////////
6878 
6879 bool TCling::ClassInfo_IsLoaded(ClassInfo_t* cinfo) const
6880 {
6881  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
6882  return TClinginfo->IsLoaded();
6883 }
6884 
6885 ////////////////////////////////////////////////////////////////////////////////
6886 
6887 bool TCling::ClassInfo_IsValid(ClassInfo_t* cinfo) const
6888 {
6889  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
6890  return TClinginfo->IsValid();
6891 }
6892 
6893 ////////////////////////////////////////////////////////////////////////////////
6894 
6895 bool TCling::ClassInfo_IsValidMethod(ClassInfo_t* cinfo, const char* method, const char* proto, Long_t* offset, EFunctionMatchMode mode /* = kConversionMatch */) const
6896 {
6897  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
6898  return TClinginfo->IsValidMethod(method, proto, false, offset, mode);
6899 }
6900 
6901 ////////////////////////////////////////////////////////////////////////////////
6902 
6903 bool TCling::ClassInfo_IsValidMethod(ClassInfo_t* cinfo, const char* method, const char* proto, Bool_t objectIsConst, Long_t* offset, EFunctionMatchMode mode /* = kConversionMatch */) const
6904 {
6905  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
6906  return TClinginfo->IsValidMethod(method, proto, objectIsConst, offset, mode);
6907 }
6908 
6909 ////////////////////////////////////////////////////////////////////////////////
6910 
6911 int TCling::ClassInfo_Next(ClassInfo_t* cinfo) const
6912 {
6913  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
6914  return TClinginfo->Next();
6915 }
6916 
6917 ////////////////////////////////////////////////////////////////////////////////
6918 
6919 void* TCling::ClassInfo_New(ClassInfo_t* cinfo) const
6920 {
6921  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
6922  return TClinginfo->New(*fNormalizedCtxt);
6923 }
6924 
6925 ////////////////////////////////////////////////////////////////////////////////
6926 
6927 void* TCling::ClassInfo_New(ClassInfo_t* cinfo, int n) const
6928 {
6929  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
6930  return TClinginfo->New(n,*fNormalizedCtxt);
6931 }
6932 
6933 ////////////////////////////////////////////////////////////////////////////////
6934 
6935 void* TCling::ClassInfo_New(ClassInfo_t* cinfo, int n, void* arena) const
6936 {
6937  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
6938  return TClinginfo->New(n, arena,*fNormalizedCtxt);
6939 }
6940 
6941 ////////////////////////////////////////////////////////////////////////////////
6942 
6943 void* TCling::ClassInfo_New(ClassInfo_t* cinfo, void* arena) const
6944 {
6945  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
6946  return TClinginfo->New(arena,*fNormalizedCtxt);
6947 }
6948 
6949 ////////////////////////////////////////////////////////////////////////////////
6950 
6951 Long_t TCling::ClassInfo_Property(ClassInfo_t* cinfo) const
6952 {
6953  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
6954  return TClinginfo->Property();
6955 }
6956 
6957 ////////////////////////////////////////////////////////////////////////////////
6958 
6959 int TCling::ClassInfo_Size(ClassInfo_t* cinfo) const
6960 {
6961  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
6962  return TClinginfo->Size();
6963 }
6964 
6965 ////////////////////////////////////////////////////////////////////////////////
6966 
6967 Long_t TCling::ClassInfo_Tagnum(ClassInfo_t* cinfo) const
6968 {
6969  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
6970  return TClinginfo->Tagnum();
6971 }
6972 
6973 ////////////////////////////////////////////////////////////////////////////////
6974 
6975 const char* TCling::ClassInfo_FileName(ClassInfo_t* cinfo) const
6976 {
6977  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
6978  return TClinginfo->FileName();
6979 }
6980 
6981 ////////////////////////////////////////////////////////////////////////////////
6982 
6983 const char* TCling::ClassInfo_FullName(ClassInfo_t* cinfo) const
6984 {
6985  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
6986  TTHREAD_TLS_DECL(std::string,output);
6987  TClinginfo->FullName(output,*fNormalizedCtxt);
6988  return output.c_str();
6989 }
6990 
6991 ////////////////////////////////////////////////////////////////////////////////
6992 
6993 const char* TCling::ClassInfo_Name(ClassInfo_t* cinfo) const
6994 {
6995  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
6996  return TClinginfo->Name();
6997 }
6998 
6999 ////////////////////////////////////////////////////////////////////////////////
7000 
7001 const char* TCling::ClassInfo_Title(ClassInfo_t* cinfo) const
7002 {
7003  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
7004  return TClinginfo->Title();
7005 }
7006 
7007 ////////////////////////////////////////////////////////////////////////////////
7008 
7009 const char* TCling::ClassInfo_TmpltName(ClassInfo_t* cinfo) const
7010 {
7011  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
7012  return TClinginfo->TmpltName();
7013 }
7014 
7015 
7016 
7017 //______________________________________________________________________________
7018 //
7019 // BaseClassInfo interface
7020 //
7021 
7022 ////////////////////////////////////////////////////////////////////////////////
7023 
7024 void TCling::BaseClassInfo_Delete(BaseClassInfo_t* bcinfo) const
7025 {
7026  delete(TClingBaseClassInfo*) bcinfo;
7027 }
7028 
7029 ////////////////////////////////////////////////////////////////////////////////
7030 
7031 BaseClassInfo_t* TCling::BaseClassInfo_Factory(ClassInfo_t* cinfo) const
7032 {
7034  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
7035  return (BaseClassInfo_t*) new TClingBaseClassInfo(fInterpreter, TClinginfo);
7036 }
7037 
7038 ////////////////////////////////////////////////////////////////////////////////
7039 
7040 BaseClassInfo_t* TCling::BaseClassInfo_Factory(ClassInfo_t* derived,
7041  ClassInfo_t* base) const
7042 {
7044  TClingClassInfo* TClinginfo = (TClingClassInfo*) derived;
7045  TClingClassInfo* TClinginfoBase = (TClingClassInfo*) base;
7046  return (BaseClassInfo_t*) new TClingBaseClassInfo(fInterpreter, TClinginfo, TClinginfoBase);
7047 }
7048 
7049 ////////////////////////////////////////////////////////////////////////////////
7050 
7051 int TCling::BaseClassInfo_Next(BaseClassInfo_t* bcinfo) const
7052 {
7053  TClingBaseClassInfo* TClinginfo = (TClingBaseClassInfo*) bcinfo;
7054  return TClinginfo->Next();
7055 }
7056 
7057 ////////////////////////////////////////////////////////////////////////////////
7058 
7059 int TCling::BaseClassInfo_Next(BaseClassInfo_t* bcinfo, int onlyDirect) const
7060 {
7061  TClingBaseClassInfo* TClinginfo = (TClingBaseClassInfo*) bcinfo;
7062  return TClinginfo->Next(onlyDirect);
7063 }
7064 
7065 ////////////////////////////////////////////////////////////////////////////////
7066 
7067 Long_t TCling::BaseClassInfo_Offset(BaseClassInfo_t* toBaseClassInfo, void * address, bool isDerivedObject) const
7068 {
7069  TClingBaseClassInfo* TClinginfo = (TClingBaseClassInfo*) toBaseClassInfo;
7070  return TClinginfo->Offset(address, isDerivedObject);
7071 }
7072 
7073 ////////////////////////////////////////////////////////////////////////////////
7074 
7075 Long_t TCling::ClassInfo_GetBaseOffset(ClassInfo_t* fromDerived, ClassInfo_t* toBase, void * address, bool isDerivedObject) const
7076 {
7077  TClingClassInfo* TClinginfo = (TClingClassInfo*) fromDerived;
7078  TClingClassInfo* TClinginfoBase = (TClingClassInfo*) toBase;
7079  // Offset to the class itself.
7080  if (TClinginfo->GetDecl() == TClinginfoBase->GetDecl()) {
7081  return 0;
7082  }
7083  return TClinginfo->GetBaseOffset(TClinginfoBase, address, isDerivedObject);
7084 }
7085 
7086 ////////////////////////////////////////////////////////////////////////////////
7087 
7088 Long_t TCling::BaseClassInfo_Property(BaseClassInfo_t* bcinfo) const
7089 {
7090  TClingBaseClassInfo* TClinginfo = (TClingBaseClassInfo*) bcinfo;
7091  return TClinginfo->Property();
7092 }
7093 
7094 ////////////////////////////////////////////////////////////////////////////////
7095 
7096 ClassInfo_t *TCling::BaseClassInfo_ClassInfo(BaseClassInfo_t *bcinfo) const
7097 {
7098  TClingBaseClassInfo* TClinginfo = (TClingBaseClassInfo*) bcinfo;
7099  return (ClassInfo_t *)TClinginfo->GetBase();
7100 }
7101 
7102 ////////////////////////////////////////////////////////////////////////////////
7103 
7104 Long_t TCling::BaseClassInfo_Tagnum(BaseClassInfo_t* bcinfo) const
7105 {
7106  TClingBaseClassInfo* TClinginfo = (TClingBaseClassInfo*) bcinfo;
7107  return TClinginfo->Tagnum();
7108 }
7109 
7110 ////////////////////////////////////////////////////////////////////////////////
7111 
7112 const char* TCling::BaseClassInfo_FullName(BaseClassInfo_t* bcinfo) const
7113 {
7114  TClingBaseClassInfo* TClinginfo = (TClingBaseClassInfo*) bcinfo;
7115  TTHREAD_TLS_DECL(std::string,output);
7116  TClinginfo->FullName(output,*fNormalizedCtxt);
7117  return output.c_str();
7118 }
7119 
7120 ////////////////////////////////////////////////////////////////////////////////
7121 
7122 const char* TCling::BaseClassInfo_Name(BaseClassInfo_t* bcinfo) const
7123 {
7124  TClingBaseClassInfo* TClinginfo = (TClingBaseClassInfo*) bcinfo;
7125  return TClinginfo->Name();
7126 }
7127 
7128 ////////////////////////////////////////////////////////////////////////////////
7129 
7130 const char* TCling::BaseClassInfo_TmpltName(BaseClassInfo_t* bcinfo) const
7131 {
7132  TClingBaseClassInfo* TClinginfo = (TClingBaseClassInfo*) bcinfo;
7133  return TClinginfo->TmpltName();
7134 }
7135 
7136 //______________________________________________________________________________
7137 //
7138 // DataMemberInfo interface
7139 //
7140 
7141 ////////////////////////////////////////////////////////////////////////////////
7142 
7143 int TCling::DataMemberInfo_ArrayDim(DataMemberInfo_t* dminfo) const
7144 {
7145  TClingDataMemberInfo* TClinginfo = (TClingDataMemberInfo*) dminfo;
7146  return TClinginfo->ArrayDim();
7147 }
7148 
7149 ////////////////////////////////////////////////////////////////////////////////
7150 
7151 void TCling::DataMemberInfo_Delete(DataMemberInfo_t* dminfo) const
7152 {
7153  delete(TClingDataMemberInfo*) dminfo;
7154 }
7155 
7156 ////////////////////////////////////////////////////////////////////////////////
7157 
7158 DataMemberInfo_t* TCling::DataMemberInfo_Factory(ClassInfo_t* clinfo /*= 0*/) const
7159 {
7161  TClingClassInfo* TClingclass_info = (TClingClassInfo*) clinfo;
7162  return (DataMemberInfo_t*) new TClingDataMemberInfo(fInterpreter, TClingclass_info);
7163 }
7164 
7165 ////////////////////////////////////////////////////////////////////////////////
7166 
7167 DataMemberInfo_t* TCling::DataMemberInfo_Factory(DeclId_t declid, ClassInfo_t* clinfo) const
7168 {
7170  const clang::Decl* decl = reinterpret_cast<const clang::Decl*>(declid);
7171  const clang::ValueDecl* vd = llvm::dyn_cast_or_null<clang::ValueDecl>(decl);
7172  return (DataMemberInfo_t*) new TClingDataMemberInfo(fInterpreter, vd, (TClingClassInfo*)clinfo);
7173 }
7174 
7175 ////////////////////////////////////////////////////////////////////////////////
7176 
7177 DataMemberInfo_t* TCling::DataMemberInfo_FactoryCopy(DataMemberInfo_t* dminfo) const
7178 {
7179  TClingDataMemberInfo* TClinginfo = (TClingDataMemberInfo*) dminfo;
7180  return (DataMemberInfo_t*) new TClingDataMemberInfo(*TClinginfo);
7181 }
7182 
7183 ////////////////////////////////////////////////////////////////////////////////
7184 
7185 bool TCling::DataMemberInfo_IsValid(DataMemberInfo_t* dminfo) const
7186 {
7187  TClingDataMemberInfo* TClinginfo = (TClingDataMemberInfo*) dminfo;
7188  return TClinginfo->IsValid();
7189 }
7190 
7191 ////////////////////////////////////////////////////////////////////////////////
7192 
7193 int TCling::DataMemberInfo_MaxIndex(DataMemberInfo_t* dminfo, Int_t dim) const
7194 {
7195  TClingDataMemberInfo* TClinginfo = (TClingDataMemberInfo*) dminfo;
7196  return TClinginfo->MaxIndex(dim);
7197 }
7198 
7199 ////////////////////////////////////////////////////////////////////////////////
7200 
7201 int TCling::DataMemberInfo_Next(DataMemberInfo_t* dminfo) const
7202 {
7203  TClingDataMemberInfo* TClinginfo = (TClingDataMemberInfo*) dminfo;
7204  return TClinginfo->Next();
7205 }
7206 
7207 ////////////////////////////////////////////////////////////////////////////////
7208 
7209 Long_t TCling::DataMemberInfo_Offset(DataMemberInfo_t* dminfo) const
7210 {
7211  TClingDataMemberInfo* TClinginfo = (TClingDataMemberInfo*) dminfo;
7212  return TClinginfo->Offset();
7213 }
7214 
7215 ////////////////////////////////////////////////////////////////////////////////
7216 
7217 Long_t TCling::DataMemberInfo_Property(DataMemberInfo_t* dminfo) const
7218 {
7219  TClingDataMemberInfo* TClinginfo = (TClingDataMemberInfo*) dminfo;
7220  return TClinginfo->Property();
7221 }
7222 
7223 ////////////////////////////////////////////////////////////////////////////////
7224 
7225 Long_t TCling::DataMemberInfo_TypeProperty(DataMemberInfo_t* dminfo) const
7226 {
7227  TClingDataMemberInfo* TClinginfo = (TClingDataMemberInfo*) dminfo;
7228  return TClinginfo->TypeProperty();
7229 }
7230 
7231 ////////////////////////////////////////////////////////////////////////////////
7232 
7233 int TCling::DataMemberInfo_TypeSize(DataMemberInfo_t* dminfo) const
7234 {
7235  TClingDataMemberInfo* TClinginfo = (TClingDataMemberInfo*) dminfo;
7236  return TClinginfo->TypeSize();
7237 }
7238 
7239 ////////////////////////////////////////////////////////////////////////////////
7240 
7241 const char* TCling::DataMemberInfo_TypeName(DataMemberInfo_t* dminfo) const
7242 {
7243  TClingDataMemberInfo* TClinginfo = (TClingDataMemberInfo*) dminfo;
7244  return TClinginfo->TypeName();
7245 }
7246 
7247 ////////////////////////////////////////////////////////////////////////////////
7248 
7249 const char* TCling::DataMemberInfo_TypeTrueName(DataMemberInfo_t* dminfo) const
7250 {
7251  TClingDataMemberInfo* TClinginfo = (TClingDataMemberInfo*) dminfo;
7252  return TClinginfo->TypeTrueName(*fNormalizedCtxt);
7253 }
7254 
7255 ////////////////////////////////////////////////////////////////////////////////
7256 
7257 const char* TCling::DataMemberInfo_Name(DataMemberInfo_t* dminfo) const
7258 {
7259  TClingDataMemberInfo* TClinginfo = (TClingDataMemberInfo*) dminfo;
7260  return TClinginfo->Name();
7261 }
7262 
7263 ////////////////////////////////////////////////////////////////////////////////
7264 
7265 const char* TCling::DataMemberInfo_Title(DataMemberInfo_t* dminfo) const
7266 {
7267  TClingDataMemberInfo* TClinginfo = (TClingDataMemberInfo*) dminfo;
7268  return TClinginfo->Title();
7269 }
7270 
7271 ////////////////////////////////////////////////////////////////////////////////
7272 
7273 const char* TCling::DataMemberInfo_ValidArrayIndex(DataMemberInfo_t* dminfo) const
7274 {
7275  TTHREAD_TLS_DECL(std::string,result);
7276 
7277  TClingDataMemberInfo* TClinginfo = (TClingDataMemberInfo*) dminfo;
7278  result = TClinginfo->ValidArrayIndex().str();
7279  return result.c_str();
7280 }
7281 
7282 ////////////////////////////////////////////////////////////////////////////////
7283 
7284 void TCling::SetDeclAttr(DeclId_t declId, const char* attribute)
7285 {
7286  Decl* decl = static_cast<Decl*>(const_cast<void*>(declId));
7287  ASTContext &C = decl->getASTContext();
7288  SourceRange commentRange; // this is a fake comment range
7289  decl->addAttr( new (C) AnnotateAttr( commentRange, C, attribute, 0 ) );
7290 }
7291 
7292 //______________________________________________________________________________
7293 //
7294 // Function Template interface
7295 //
7296 
7297 ////////////////////////////////////////////////////////////////////////////////
7298 
7299 static void ConstructorName(std::string &name, const clang::NamedDecl *decl,
7300  cling::Interpreter &interp,
7301  const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt)
7302 {
7303  const clang::TypeDecl* td = llvm::dyn_cast<clang::TypeDecl>(decl->getDeclContext());
7304  if (!td) return;
7305 
7306  clang::QualType qualType(td->getTypeForDecl(),0);
7307  ROOT::TMetaUtils::GetNormalizedName(name, qualType, interp, normCtxt);
7308  unsigned int level = 0;
7309  for(size_t cursor = name.length()-1; cursor != 0; --cursor) {
7310  if (name[cursor] == '>') ++level;
7311  else if (name[cursor] == '<' && level) --level;
7312  else if (level == 0 && name[cursor] == ':') {
7313  name.erase(0,cursor+1);
7314  break;
7315  }
7316  }
7317 }
7318 
7319 ////////////////////////////////////////////////////////////////////////////////
7320 
7321 void TCling::GetFunctionName(const clang::FunctionDecl *decl, std::string &output) const
7322 {
7323  output.clear();
7324  if (llvm::isa<clang::CXXConstructorDecl>(decl))
7325  {
7326  ConstructorName(output, decl, *fInterpreter, *fNormalizedCtxt);
7327 
7328  } else if (llvm::isa<clang::CXXDestructorDecl>(decl))
7329  {
7330  ConstructorName(output, decl, *fInterpreter, *fNormalizedCtxt);
7331  output.insert(output.begin(), '~');
7332  } else {
7333  llvm::raw_string_ostream stream(output);
7334  decl->getNameForDiagnostic(stream, decl->getASTContext().getPrintingPolicy(), /*Qualified=*/false);
7335  }
7336 }
7337 
7338 ////////////////////////////////////////////////////////////////////////////////
7339 /// Return a unique identifier of the declaration represented by the
7340 /// FuncTempInfo
7341 
7342 TInterpreter::DeclId_t TCling::GetDeclId(FuncTempInfo_t *info) const
7343 {
7344  return (DeclId_t)info;
7345 }
7346 
7347 ////////////////////////////////////////////////////////////////////////////////
7348 /// Delete the FuncTempInfo_t
7349 
7350 void TCling::FuncTempInfo_Delete(FuncTempInfo_t * /* ft_info */) const
7351 {
7352  // Currently the address of ft_info is actually the decl itself,
7353  // so we have nothing to do.
7354 }
7355 
7356 ////////////////////////////////////////////////////////////////////////////////
7357 /// Construct a FuncTempInfo_t
7358 
7359 FuncTempInfo_t *TCling::FuncTempInfo_Factory(DeclId_t declid) const
7360 {
7361  // Currently the address of ft_info is actually the decl itself,
7362  // so we have nothing to do.
7363 
7364  return (FuncTempInfo_t*)const_cast<void*>(declid);
7365 }
7366 
7367 ////////////////////////////////////////////////////////////////////////////////
7368 /// Construct a FuncTempInfo_t
7369 
7370 FuncTempInfo_t *TCling::FuncTempInfo_FactoryCopy(FuncTempInfo_t *ft_info) const
7371 {
7372  // Currently the address of ft_info is actually the decl itself,
7373  // so we have nothing to do.
7374 
7375  return (FuncTempInfo_t*)ft_info;
7376 }
7377 
7378 ////////////////////////////////////////////////////////////////////////////////
7379 /// Check validity of a FuncTempInfo_t
7380 
7381 Bool_t TCling::FuncTempInfo_IsValid(FuncTempInfo_t *t_info) const
7382 {
7383  // Currently the address of ft_info is actually the decl itself,
7384  // so we have nothing to do.
7385 
7386  return t_info != 0;
7387 }
7388 
7389 ////////////////////////////////////////////////////////////////////////////////
7390 /// Return the maximum number of template arguments of the
7391 /// function template described by ft_info.
7392 
7393 UInt_t TCling::FuncTempInfo_TemplateNargs(FuncTempInfo_t *ft_info) const
7394 {
7395  if (!ft_info) return 0;
7396  const clang::FunctionTemplateDecl *ft = (const clang::FunctionTemplateDecl*)ft_info;
7397  return ft->getTemplateParameters()->size();
7398 }
7399 
7400 ////////////////////////////////////////////////////////////////////////////////
7401 /// Return the number of required template arguments of the
7402 /// function template described by ft_info.
7403 
7404 UInt_t TCling::FuncTempInfo_TemplateMinReqArgs(FuncTempInfo_t *ft_info) const
7405 {
7406  if (!ft_info) return 0;
7407  const clang::FunctionTemplateDecl *ft = (clang::FunctionTemplateDecl*)ft_info;
7408  return ft->getTemplateParameters()->getMinRequiredArguments();
7409 }
7410 
7411 ////////////////////////////////////////////////////////////////////////////////
7412 /// Return the property of the function template.
7413 
7414 Long_t TCling::FuncTempInfo_Property(FuncTempInfo_t *ft_info) const
7415 {
7416  if (!ft_info) return 0;
7417 
7418  long property = 0L;
7419  property |= kIsCompiled;
7420 
7421  const clang::FunctionTemplateDecl *ft = (clang::FunctionTemplateDecl*)ft_info;
7422 
7423  switch (ft->getAccess()) {
7424  case clang::AS_public:
7425  property |= kIsPublic;
7426  break;
7427  case clang::AS_protected:
7428  property |= kIsProtected;
7429  break;
7430  case clang::AS_private:
7431  property |= kIsPrivate;
7432  break;
7433  case clang::AS_none:
7434  if (ft->getDeclContext()->isNamespace())
7435  property |= kIsPublic;
7436  break;
7437  default:
7438  // IMPOSSIBLE
7439  break;
7440  }
7441 
7442  const clang::FunctionDecl *fd = ft->getTemplatedDecl();
7443  if (const clang::CXXMethodDecl *md =
7444  llvm::dyn_cast<clang::CXXMethodDecl>(fd)) {
7445  if (md->getTypeQualifiers() & clang::Qualifiers::Const) {
7446  property |= kIsConstant | kIsConstMethod;
7447  }
7448  if (md->isVirtual()) {
7449  property |= kIsVirtual;
7450  }
7451  if (md->isPure()) {
7452  property |= kIsPureVirtual;
7453  }
7454  if (const clang::CXXConstructorDecl *cd =
7455  llvm::dyn_cast<clang::CXXConstructorDecl>(md)) {
7456  if (cd->isExplicit()) {
7457  property |= kIsExplicit;
7458  }
7459  }
7460  else if (const clang::CXXConversionDecl *cd =
7461  llvm::dyn_cast<clang::CXXConversionDecl>(md)) {
7462  if (cd->isExplicit()) {
7463  property |= kIsExplicit;
7464  }
7465  }
7466  }
7467  return property;
7468 }
7469 
7470 ////////////////////////////////////////////////////////////////////////////////
7471 /// Return the name of this function template.
7472 
7473 void TCling::FuncTempInfo_Name(FuncTempInfo_t *ft_info, TString &output) const
7474 {
7475  output.Clear();
7476  if (!ft_info) return;
7477  const clang::FunctionTemplateDecl *ft = (clang::FunctionTemplateDecl*)ft_info;
7478  std::string buf;
7479  GetFunctionName(ft->getTemplatedDecl(), buf);
7480  output = buf;
7481 }
7482 
7483 ////////////////////////////////////////////////////////////////////////////////
7484 /// Return the comments associates with this function template.
7485 
7486 void TCling::FuncTempInfo_Title(FuncTempInfo_t *ft_info, TString &output) const
7487 {
7488  output.Clear();
7489  if (!ft_info) return;
7490  const clang::FunctionTemplateDecl *ft = (const clang::FunctionTemplateDecl*)ft_info;
7491 
7492  // Iterate over the redeclarations, we can have multiple definitions in the
7493  // redecl chain (came from merging of pcms).
7494  if (const RedeclarableTemplateDecl *AnnotFD
7495  = ROOT::TMetaUtils::GetAnnotatedRedeclarable((const RedeclarableTemplateDecl*)ft)) {
7496  if (AnnotateAttr *A = AnnotFD->getAttr<AnnotateAttr>()) {
7497  output = A->getAnnotation().str();
7498  return;
7499  }
7500  }
7501  if (!ft->isFromASTFile()) {
7502  // Try to get the comment from the header file if present
7503  // but not for decls from AST file, where rootcling would have
7504  // created an annotation
7505  output = ROOT::TMetaUtils::GetComment(*ft).str();
7506  }
7507 }
7508 
7509 
7510 //______________________________________________________________________________
7511 //
7512 // MethodInfo interface
7513 //
7514 
7515 ////////////////////////////////////////////////////////////////////////////////
7516 /// Interface to cling function
7517 
7518 void TCling::MethodInfo_Delete(MethodInfo_t* minfo) const
7519 {
7520  delete(TClingMethodInfo*) minfo;
7521 }
7522 
7523 ////////////////////////////////////////////////////////////////////////////////
7524 
7525 void TCling::MethodInfo_CreateSignature(MethodInfo_t* minfo, TString& signature) const
7526 {
7527  TClingMethodInfo* info = (TClingMethodInfo*) minfo;
7528  info->CreateSignature(signature);
7529 }
7530 
7531 ////////////////////////////////////////////////////////////////////////////////
7532 
7533 MethodInfo_t* TCling::MethodInfo_Factory() const
7534 {
7536  return (MethodInfo_t*) new TClingMethodInfo(fInterpreter);
7537 }
7538 
7539 ////////////////////////////////////////////////////////////////////////////////
7540 
7541 MethodInfo_t* TCling::MethodInfo_Factory(ClassInfo_t* clinfo) const
7542 {
7544  return (MethodInfo_t*) new TClingMethodInfo(fInterpreter, (TClingClassInfo*)clinfo);
7545 }
7546 
7547 ////////////////////////////////////////////////////////////////////////////////
7548 
7549 MethodInfo_t* TCling::MethodInfo_Factory(DeclId_t declid) const
7550 {
7551  const clang::Decl* decl = reinterpret_cast<const clang::Decl*>(declid);
7553  const clang::FunctionDecl* fd = llvm::dyn_cast_or_null<clang::FunctionDecl>(decl);
7554  return (MethodInfo_t*) new TClingMethodInfo(fInterpreter, fd);
7555 }
7556 
7557 ////////////////////////////////////////////////////////////////////////////////
7558 
7559 MethodInfo_t* TCling::MethodInfo_FactoryCopy(MethodInfo_t* minfo) const
7560 {
7561  return (MethodInfo_t*) new TClingMethodInfo(*(TClingMethodInfo*)minfo);
7562 }
7563 
7564 ////////////////////////////////////////////////////////////////////////////////
7565 
7566 void* TCling::MethodInfo_InterfaceMethod(MethodInfo_t* minfo) const
7567 {
7568  TClingMethodInfo* info = (TClingMethodInfo*) minfo;
7569  return info->InterfaceMethod(*fNormalizedCtxt);
7570 }
7571 
7572 ////////////////////////////////////////////////////////////////////////////////
7573 
7574 bool TCling::MethodInfo_IsValid(MethodInfo_t* minfo) const
7575 {
7576  TClingMethodInfo* info = (TClingMethodInfo*) minfo;
7577  return info->IsValid();
7578 }
7579 
7580 ////////////////////////////////////////////////////////////////////////////////
7581 
7582 int TCling::MethodInfo_NArg(MethodInfo_t* minfo) const
7583 {
7584  TClingMethodInfo* info = (TClingMethodInfo*) minfo;
7585  return info->NArg();
7586 }
7587 
7588 ////////////////////////////////////////////////////////////////////////////////
7589 
7590 int TCling::MethodInfo_NDefaultArg(MethodInfo_t* minfo) const
7591 {
7592  TClingMethodInfo* info = (TClingMethodInfo*) minfo;
7593  return info->NDefaultArg();
7594 }
7595 
7596 ////////////////////////////////////////////////////////////////////////////////
7597 
7598 int TCling::MethodInfo_Next(MethodInfo_t* minfo) const
7599 {
7600  TClingMethodInfo* info = (TClingMethodInfo*) minfo;
7601  return info->Next();
7602 }
7603 
7604 ////////////////////////////////////////////////////////////////////////////////
7605 
7606 Long_t TCling::MethodInfo_Property(MethodInfo_t* minfo) const
7607 {
7608  TClingMethodInfo* info = (TClingMethodInfo*) minfo;
7609  return info->Property();
7610 }
7611 
7612 ////////////////////////////////////////////////////////////////////////////////
7613 
7614 Long_t TCling::MethodInfo_ExtraProperty(MethodInfo_t* minfo) const
7615 {
7616  TClingMethodInfo* info = (TClingMethodInfo*) minfo;
7617  return info->ExtraProperty();
7618 }
7619 
7620 ////////////////////////////////////////////////////////////////////////////////
7621 
7622 TypeInfo_t* TCling::MethodInfo_Type(MethodInfo_t* minfo) const
7623 {
7624  TClingMethodInfo* info = (TClingMethodInfo*) minfo;
7625  return (TypeInfo_t*)info->Type();
7626 }
7627 
7628 ////////////////////////////////////////////////////////////////////////////////
7629 
7630 const char* TCling::MethodInfo_GetMangledName(MethodInfo_t* minfo) const
7631 {
7632  TClingMethodInfo* info = (TClingMethodInfo*) minfo;
7633  TTHREAD_TLS_DECL(TString, mangled_name);
7634  mangled_name = info->GetMangledName();
7635  return mangled_name;
7636 }
7637 
7638 ////////////////////////////////////////////////////////////////////////////////
7639 
7640 const char* TCling::MethodInfo_GetPrototype(MethodInfo_t* minfo) const
7641 {
7642  TClingMethodInfo* info = (TClingMethodInfo*) minfo;
7643  return info->GetPrototype(*fNormalizedCtxt);
7644 }
7645 
7646 ////////////////////////////////////////////////////////////////////////////////
7647 
7648 const char* TCling::MethodInfo_Name(MethodInfo_t* minfo) const
7649 {
7650  TClingMethodInfo* info = (TClingMethodInfo*) minfo;
7651  return info->Name(*fNormalizedCtxt);
7652 }
7653 
7654 ////////////////////////////////////////////////////////////////////////////////
7655 
7656 const char* TCling::MethodInfo_TypeName(MethodInfo_t* minfo) const
7657 {
7658  TClingMethodInfo* info = (TClingMethodInfo*) minfo;
7659  return info->TypeName();
7660 }
7661 
7662 ////////////////////////////////////////////////////////////////////////////////
7663 
7664 std::string TCling::MethodInfo_TypeNormalizedName(MethodInfo_t* minfo) const
7665 {
7666  TClingMethodInfo* info = (TClingMethodInfo*) minfo;
7667  if (info && info->IsValid())
7668  return info->Type()->NormalizedName(*fNormalizedCtxt);
7669  else
7670  return "";
7671 }
7672 
7673 ////////////////////////////////////////////////////////////////////////////////
7674 
7675 const char* TCling::MethodInfo_Title(MethodInfo_t* minfo) const
7676 {
7677  TClingMethodInfo* info = (TClingMethodInfo*) minfo;
7678  return info->Title();
7679 }
7680 
7681 ////////////////////////////////////////////////////////////////////////////////
7682 
7684 {
7685  if (func) {
7686  return MethodInfo_MethodCallReturnType(func->fInfo);
7687  } else {
7688  return EReturnType::kOther;
7689  }
7690 }
7691 
7692 ////////////////////////////////////////////////////////////////////////////////
7693 
7694 auto TCling::MethodInfo_MethodCallReturnType(MethodInfo_t* minfo) const -> EReturnType
7695 {
7696  TClingMethodInfo* info = (TClingMethodInfo*) minfo;
7697  if (info && info->IsValid()) {
7698  TClingTypeInfo *typeinfo = info->Type();
7699  clang::QualType QT( typeinfo->GetQualType().getCanonicalType() );
7700  if (QT->isEnumeralType()) {
7701  return EReturnType::kLong;
7702  } else if (QT->isPointerType()) {
7703  // Look for char*
7704  QT = llvm::cast<clang::PointerType>(QT)->getPointeeType();
7705  if ( QT->isCharType() ) {
7706  return EReturnType::kString;
7707  } else {
7708  return EReturnType::kOther;
7709  }
7710  } else if ( QT->isFloatingType() ) {
7711  int sz = typeinfo->Size();
7712  if (sz == 4 || sz == 8) {
7713  // Support only float and double.
7714  return EReturnType::kDouble;
7715  } else {
7716  return EReturnType::kOther;
7717  }
7718  } else if ( QT->isIntegerType() ) {
7719  int sz = typeinfo->Size();
7720  if (sz <= 8) {
7721  // Support only up to long long ... but
7722  // FIXME the TMethodCall::Execute only
7723  // return long (4 bytes) ...
7724  // The v5 implementation of TMethodCall::ReturnType
7725  // was not making the distinction so we let it go
7726  // as is for now, but we really need to upgrade
7727  // TMethodCall::Execute ...
7728  return EReturnType::kLong;
7729  } else {
7730  return EReturnType::kOther;
7731  }
7732  } else {
7733  return EReturnType::kOther;
7734  }
7735  } else {
7736  return EReturnType::kOther;
7737  }
7738 }
7739 
7740 //______________________________________________________________________________
7741 //
7742 // MethodArgInfo interface
7743 //
7744 
7745 ////////////////////////////////////////////////////////////////////////////////
7746 
7747 void TCling::MethodArgInfo_Delete(MethodArgInfo_t* marginfo) const
7748 {
7749  delete(TClingMethodArgInfo*) marginfo;
7750 }
7751 
7752 ////////////////////////////////////////////////////////////////////////////////
7753 
7754 MethodArgInfo_t* TCling::MethodArgInfo_Factory() const
7755 {
7757  return (MethodArgInfo_t*) new TClingMethodArgInfo(fInterpreter);
7758 }
7759 
7760 ////////////////////////////////////////////////////////////////////////////////
7761 
7762 MethodArgInfo_t* TCling::MethodArgInfo_Factory(MethodInfo_t *minfo) const
7763 {
7765  return (MethodArgInfo_t*) new TClingMethodArgInfo(fInterpreter, (TClingMethodInfo*)minfo);
7766 }
7767 
7768 ////////////////////////////////////////////////////////////////////////////////
7769 
7770 MethodArgInfo_t* TCling::MethodArgInfo_FactoryCopy(MethodArgInfo_t* marginfo) const
7771 {
7772  return (MethodArgInfo_t*)
7773  new TClingMethodArgInfo(*(TClingMethodArgInfo*)marginfo);
7774 }
7775 
7776 ////////////////////////////////////////////////////////////////////////////////
7777 
7778 bool TCling::MethodArgInfo_IsValid(MethodArgInfo_t* marginfo) const
7779 {
7780  TClingMethodArgInfo* info = (TClingMethodArgInfo*) marginfo;
7781  return info->IsValid();
7782 }
7783 
7784 ////////////////////////////////////////////////////////////////////////////////
7785 
7786 int TCling::MethodArgInfo_Next(MethodArgInfo_t* marginfo) const
7787 {
7788  TClingMethodArgInfo* info = (TClingMethodArgInfo*) marginfo;
7789  return info->Next();
7790 }
7791 
7792 ////////////////////////////////////////////////////////////////////////////////
7793 
7794 Long_t TCling::MethodArgInfo_Property(MethodArgInfo_t* marginfo) const
7795 {
7796  TClingMethodArgInfo* info = (TClingMethodArgInfo*) marginfo;
7797  return info->Property();
7798 }
7799 
7800 ////////////////////////////////////////////////////////////////////////////////
7801 
7802 const char* TCling::MethodArgInfo_DefaultValue(MethodArgInfo_t* marginfo) const
7803 {
7804  TClingMethodArgInfo* info = (TClingMethodArgInfo*) marginfo;
7805  return info->DefaultValue();
7806 }
7807 
7808 ////////////////////////////////////////////////////////////////////////////////
7809 
7810 const char* TCling::MethodArgInfo_Name(MethodArgInfo_t* marginfo) const
7811 {
7812  TClingMethodArgInfo* info = (TClingMethodArgInfo*) marginfo;
7813  return info->Name();
7814 }
7815 
7816 ////////////////////////////////////////////////////////////////////////////////
7817 
7818 const char* TCling::MethodArgInfo_TypeName(MethodArgInfo_t* marginfo) const
7819 {
7820  TClingMethodArgInfo* info = (TClingMethodArgInfo*) marginfo;
7821  return info->TypeName();
7822 }
7823 
7824 ////////////////////////////////////////////////////////////////////////////////
7825 
7826 std::string TCling::MethodArgInfo_TypeNormalizedName(MethodArgInfo_t* marginfo) const
7827 {
7828  TClingMethodArgInfo* info = (TClingMethodArgInfo*) marginfo;
7829  return info->Type()->NormalizedName(*fNormalizedCtxt);
7830 }
7831 
7832 //______________________________________________________________________________
7833 //
7834 // TypeInfo interface
7835 //
7836 
7837 ////////////////////////////////////////////////////////////////////////////////
7838 
7839 void TCling::TypeInfo_Delete(TypeInfo_t* tinfo) const
7840 {
7841  delete (TClingTypeInfo*) tinfo;
7842 }
7843 
7844 ////////////////////////////////////////////////////////////////////////////////
7845 
7846 TypeInfo_t* TCling::TypeInfo_Factory() const
7847 {
7849  return (TypeInfo_t*) new TClingTypeInfo(fInterpreter);
7850 }
7851 
7852 ////////////////////////////////////////////////////////////////////////////////
7853 
7854 TypeInfo_t* TCling::TypeInfo_Factory(const char *name) const
7855 {
7857  return (TypeInfo_t*) new TClingTypeInfo(fInterpreter, name);
7858 }
7859 
7860 ////////////////////////////////////////////////////////////////////////////////
7861 
7862 TypeInfo_t* TCling::TypeInfo_FactoryCopy(TypeInfo_t* tinfo) const
7863 {
7864  return (TypeInfo_t*) new TClingTypeInfo(*(TClingTypeInfo*)tinfo);
7865 }
7866 
7867 ////////////////////////////////////////////////////////////////////////////////
7868 
7869 void TCling::TypeInfo_Init(TypeInfo_t* tinfo, const char* name) const
7870 {
7872  TClingTypeInfo* TClinginfo = (TClingTypeInfo*) tinfo;
7873  TClinginfo->Init(name);
7874 }
7875 
7876 ////////////////////////////////////////////////////////////////////////////////
7877 
7878 bool TCling::TypeInfo_IsValid(TypeInfo_t* tinfo) const
7879 {
7880  TClingTypeInfo* TClinginfo = (TClingTypeInfo*) tinfo;
7881  return TClinginfo->IsValid();
7882 }
7883 
7884 ////////////////////////////////////////////////////////////////////////////////
7885 
7886 const char* TCling::TypeInfo_Name(TypeInfo_t* tinfo) const
7887 {
7888  TClingTypeInfo* TClinginfo = (TClingTypeInfo*) tinfo;
7889  return TClinginfo->Name();
7890 }
7891 
7892 ////////////////////////////////////////////////////////////////////////////////
7893 
7894 Long_t TCling::TypeInfo_Property(TypeInfo_t* tinfo) const
7895 {
7896  TClingTypeInfo* TClinginfo = (TClingTypeInfo*) tinfo;
7897  return TClinginfo->Property();
7898 }
7899 
7900 ////////////////////////////////////////////////////////////////////////////////
7901 
7902 int TCling::TypeInfo_RefType(TypeInfo_t* tinfo) const
7903 {
7904  TClingTypeInfo* TClinginfo = (TClingTypeInfo*) tinfo;
7905  return TClinginfo->RefType();
7906 }
7907 
7908 ////////////////////////////////////////////////////////////////////////////////
7909 
7910 int TCling::TypeInfo_Size(TypeInfo_t* tinfo) const
7911 {
7912  TClingTypeInfo* TClinginfo = (TClingTypeInfo*) tinfo;
7913  return TClinginfo->Size();
7914 }
7915 
7916 ////////////////////////////////////////////////////////////////////////////////
7917 
7918 const char* TCling::TypeInfo_TrueName(TypeInfo_t* tinfo) const
7919 {
7920  TClingTypeInfo* TClinginfo = (TClingTypeInfo*) tinfo;
7921  return TClinginfo->TrueName(*fNormalizedCtxt);
7922 }
7923 
7924 
7925 //______________________________________________________________________________
7926 //
7927 // TypedefInfo interface
7928 //
7929 
7930 ////////////////////////////////////////////////////////////////////////////////
7931 
7932 void TCling::TypedefInfo_Delete(TypedefInfo_t* tinfo) const
7933 {
7934  delete(TClingTypedefInfo*) tinfo;
7935 }
7936 
7937 ////////////////////////////////////////////////////////////////////////////////
7938 
7939 TypedefInfo_t* TCling::TypedefInfo_Factory() const
7940 {
7942  return (TypedefInfo_t*) new TClingTypedefInfo(fInterpreter);
7943 }
7944 
7945 ////////////////////////////////////////////////////////////////////////////////
7946 
7947 TypedefInfo_t* TCling::TypedefInfo_Factory(const char *name) const
7948 {
7950  return (TypedefInfo_t*) new TClingTypedefInfo(fInterpreter, name);
7951 }
7952 
7953 ////////////////////////////////////////////////////////////////////////////////
7954 
7955 TypedefInfo_t* TCling::TypedefInfo_FactoryCopy(TypedefInfo_t* tinfo) const
7956 {
7957  return (TypedefInfo_t*) new TClingTypedefInfo(*(TClingTypedefInfo*)tinfo);
7958 }
7959 
7960 ////////////////////////////////////////////////////////////////////////////////
7961 
7962 void TCling::TypedefInfo_Init(TypedefInfo_t* tinfo,
7963  const char* name) const
7964 {
7966  TClingTypedefInfo* TClinginfo = (TClingTypedefInfo*) tinfo;
7967  TClinginfo->Init(name);
7968 }
7969 
7970 ////////////////////////////////////////////////////////////////////////////////
7971 
7972 bool TCling::TypedefInfo_IsValid(TypedefInfo_t* tinfo) const
7973 {
7974  TClingTypedefInfo* TClinginfo = (TClingTypedefInfo*) tinfo;
7975  return TClinginfo->IsValid();
7976 }
7977 
7978 ////////////////////////////////////////////////////////////////////////////////
7979 
7980 Int_t TCling::TypedefInfo_Next(TypedefInfo_t* tinfo) const
7981 {
7982  TClingTypedefInfo* TClinginfo = (TClingTypedefInfo*) tinfo;
7983  return TClinginfo->Next();
7984 }
7985 
7986 ////////////////////////////////////////////////////////////////////////////////
7987 
7988 Long_t TCling::TypedefInfo_Property(TypedefInfo_t* tinfo) const
7989 {
7990  TClingTypedefInfo* TClinginfo = (TClingTypedefInfo*) tinfo;
7991  return TClinginfo->Property();
7992 }
7993 
7994 ////////////////////////////////////////////////////////////////////////////////
7995 
7996 int TCling::TypedefInfo_Size(TypedefInfo_t* tinfo) const
7997 {
7998  TClingTypedefInfo* TClinginfo = (TClingTypedefInfo*) tinfo;
7999  return TClinginfo->Size();
8000 }
8001 
8002 ////////////////////////////////////////////////////////////////////////////////
8003 
8004 const char* TCling::TypedefInfo_TrueName(TypedefInfo_t* tinfo) const
8005 {
8006  TClingTypedefInfo* TClinginfo = (TClingTypedefInfo*) tinfo;
8007  return TClinginfo->TrueName(*fNormalizedCtxt);
8008 }
8009 
8010 ////////////////////////////////////////////////////////////////////////////////
8011 
8012 const char* TCling::TypedefInfo_Name(TypedefInfo_t* tinfo) const
8013 {
8014  TClingTypedefInfo* TClinginfo = (TClingTypedefInfo*) tinfo;
8015  return TClinginfo->Name();
8016 }
8017 
8018 ////////////////////////////////////////////////////////////////////////////////
8019 
8020 const char* TCling::TypedefInfo_Title(TypedefInfo_t* tinfo) const
8021 {
8022  TClingTypedefInfo* TClinginfo = (TClingTypedefInfo*) tinfo;
8023  return TClinginfo->Title();
8024 }
EState GetState() const
Definition: TClass.h:443
int TCling__AutoLoadCallback(const char *className)
Definition: TCling.cxx:588
virtual TObject * FindObject(const TObject *obj) const
Find object using its hash value (returned by its Hash() member).
virtual MethodArgInfo_t * MethodArgInfo_Factory() const
Definition: TCling.cxx:7754
Describe Streamer information for one class version.
Definition: TStreamerInfo.h:47
const char * GetIncludePath()
Refresh the list of include paths known to the interpreter and return it with -I prepended.
Definition: TCling.cxx:5994
void ResetCaches()
To clean out all caches.
Definition: TClass.cxx:3951
virtual Long_t MethodInfo_Property(MethodInfo_t *minfo) const
Definition: TCling.cxx:7606
virtual Long_t ClassInfo_ClassProperty(ClassInfo_t *info) const
Definition: TCling.cxx:6760
virtual const char * BaseName(const char *pathname)
Base name of a file name. Base name of /user/root is root.
Definition: TSystem.cxx:928
virtual Int_t GetEntries() const
Definition: TCollection.h:92
virtual Bool_t AccessPathName(const char *path, EAccessMode mode=kFileExists)
Returns FALSE if one can access a file using the specified access mode.
Definition: TSystem.cxx:1265
virtual void SetTempLevel(int val) const
Create / close a scope for temporaries.
Definition: TCling.cxx:6271
const clang::FunctionTemplateDecl * GetFunctionTemplate(const char *fname) const
Ssiz_t Last(char c) const
Find last occurrence of a character c.
Definition: TString.cxx:864
virtual void SetRcName(const char *name)
Definition: TEnv.h:149
TObject * GetObjectAddress(const char *Name, void *&LookupCtx)
If the interpreter encounters Name, check whether that is an object ROOT could retrieve.
Definition: TCling.cxx:6329
A collection of TDataMember objects designed for fast access given a DeclId_t and for keep track of T...
The TEnum class implements the enum type.
Definition: TEnum.h:42
virtual DeclId_t GetDataMemberAtAddr(const void *addr) const
Return pointer to cling DeclId for a data member with a given name.
Definition: TCling.cxx:3884
virtual TString SplitAclicMode(const char *filename, TString &mode, TString &args, TString &io) const
This method split a filename of the form: ~~~ {.cpp} [path/]macro.C[+|++[k|f|g|O|c|s|d|v|-]][(args)]...
Definition: TSystem.cxx:4071
int TCling__IsAutoLoadNamespaceCandidate(const clang::NamespaceDecl *nsDecl)
Definition: TCling.cxx:610
This class defines an abstract interface to a generic command line interpreter.
Definition: TInterpreter.h:50
int TCling__CompileMacro(const char *fileName, const char *options)
Definition: TCling.cxx:615
int GetClassVersion(const clang::RecordDecl *cl, const cling::Interpreter &interp)
Return the version number of the class or -1 if the function Class_Version does not exist...
An array of TObjects.
Definition: TObjArray.h:39
const char * Name() const
void * GetInterfaceMethod(TClass *cl, const char *method, const char *params, Bool_t objectIsConst=kFALSE)
Return pointer to cling interface function for a method of a class with parameters params (params is ...
Definition: TCling.cxx:3941
static clang::ClassTemplateDecl * FindTemplateInNamespace(clang::Decl *decl)
Find a template decl within N nested namespaces, 0<=N
Definition: TCling.cxx:651
virtual void SetRTLD_NOW() const
Definition: TCling.cxx:6255
DeclId_t GetFunctionWithValues(ClassInfo_t *cl, const char *method, const char *params, Bool_t objectIsConst=kFALSE)
Return pointer to cling DeclId for a method of a class with a certain prototype, i.e.
Definition: TCling.cxx:4041
void TransactionRollback(const cling::Transaction &T)
Definition: TCling.cxx:5847
virtual int TypedefInfo_Size(TypedefInfo_t *tinfo) const
Definition: TCling.cxx:7996
virtual TVirtualMutex * Factory(Bool_t=kFALSE)=0
virtual void SetAllocunlockfunc(void(*)()) const
[Place holder for Mutex Unlock] Provide the interpreter with a way to release a lock used to protect ...
Definition: TCling.cxx:6188
Bool_t IsOnHeap() const
Definition: TObject.h:140
void AddTemplAndNargsToKeep(const clang::ClassTemplateDecl *templ, unsigned int i)
Definition: TMetaUtils.cxx:341
virtual bool ClassInfo_HasDefaultConstructor(ClassInfo_t *info) const
Definition: TCling.cxx:6830
ROOT::ESTLType IsSTLCont(std::string_view type)
type : type name: vector,allocator> result: 0 : not stl container code of cont...
void LibraryLoaded(const void *dyLibHandle, const char *canonicalName)
Definition: TCling.cxx:5870
long long Long64_t
Definition: RtypesCore.h:69
Bool_t HandleNewTransaction(const cling::Transaction &T)
Helper function to increase the internal Cling count of transactions that change the AST...
Definition: TCling.cxx:2889
virtual CallFuncIFacePtr_t CallFunc_IFacePtr(CallFunc_t *func) const
Definition: TCling.cxx:6575
void TCling__UpdateListsOnCommitted(const cling::Transaction &T, cling::Interpreter *)
Definition: TCling.cxx:539
virtual void PostLoadCheck()
Do the initialization that can only be done after the CINT dictionary has been fully populated and ca...
Definition: TClass.cxx:5571
virtual void BaseClassInfo_Delete(BaseClassInfo_t *bcinfo) const
Definition: TCling.cxx:7024
virtual DataMemberInfo_t * DataMemberInfo_Factory(ClassInfo_t *clinfo=0) const
Definition: TCling.cxx:7158
virtual bool CallFunc_IsValid(CallFunc_t *func) const
Definition: TCling.cxx:6566
static void ConstructorName(std::string &name, const clang::NamedDecl *decl, cling::Interpreter &interp, const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt)
Definition: TCling.cxx:7299
R__EXTERN Int_t gErrorIgnoreLevel
Definition: TError.h:107
virtual int ClassInfo_Next(ClassInfo_t *info) const
Definition: TCling.cxx:6911
bool IsLoaded() const
virtual const char * WorkingDirectory()
Return working directory.
Definition: TSystem.cxx:865
virtual Int_t UnLock()=0
virtual const char * DataMemberInfo_TypeName(DataMemberInfo_t *dminfo) const
Definition: TCling.cxx:7241
virtual void CallFunc_ExecWithReturn(CallFunc_t *func, void *address, void *ret) const
Definition: TCling.cxx:6483
Namespace for new ROOT classes and functions.
Definition: ROOT.py:1
std::map< SpecialObjectLookupCtx_t, SpecialObjectMap_t > fSpecialObjectMaps
Definition: TCling.h:143
virtual TypedefInfo_t * TypedefInfo_FactoryCopy(TypedefInfo_t *tinfo) const
Definition: TCling.cxx:7955
void Update(DeclId_t id)
Definition: TEnum.cxx:101
short Version_t
Definition: RtypesCore.h:61
virtual TObject * FindObject(const char *name) const
Find an object in this collection using its name.
static Bool_t Check(const char *cname, std::string &normname)
Int_t GetType() const
Definition: TDataType.h:70
static const char **& GetExtraInterpreterArgs()
Definition: TROOT.cxx:2519
static cling::Interpreter::CompilationResult ExecAutoParse(const char *what, Bool_t header, cling::Interpreter *interpreter)
Parse the payload or header.
Definition: TCling.cxx:5126
ClassImp(TSeqCollection) Int_t TSeqCollection TIter next(this)
Return index of object in collection.
Ssiz_t Length() const
Definition: TString.h:390
TLine * line
bool IsValid() const
void RegisterLoadedSharedLibrary(const char *name)
Register a new shared library name with the interpreter; add it to fSharedLibs.
Definition: TCling.cxx:2673
Collectable string class.
Definition: TObjString.h:32
float Float_t
Definition: RtypesCore.h:53
static void AddClassToDeclIdMap(TDictionary::DeclId_t id, TClass *cl)
static: Add a TClass* to the map of classes.
Definition: TClass.cxx:467
const char * Name() const
virtual DeclId_t GetEnum(TClass *cl, const char *name) const
Return pointer to cling Decl of global/static variable that is located at the address given by addr...
Definition: TCling.cxx:3770
R__EXTERN TClassTable * gClassTable
Definition: TClassTable.h:97
TClass * GetClass() const
const char * GetPrototype(const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt) const
Definition: TEnv.h:76
void UpdateListsOnCommitted(const cling::Transaction &T)
Definition: TCling.cxx:5584
TDictionary::DeclId_t DeclId_t
Definition: TInterpreter.h:236
virtual int BaseClassInfo_Next(BaseClassInfo_t *bcinfo) const
Definition: TCling.cxx:7051
RooArgList L(const RooAbsArg &v1)
void * llvmLazyFunctionCreator(const std::string &mangled_name)
Autoload a library provided the mangled name of a missing symbol.
Definition: TCling.cxx:668
TEnum * Find(DeclId_t id) const
Return the TEnum corresponding to the Decl 'id' or NULL if it does not exist.
Dictionary for function template This class describes one single function template.
double ExecDouble(void *address)
void Init(const char *name)
virtual TypeInfo_t * TypeInfo_FactoryCopy(TypeInfo_t *) const
Definition: TCling.cxx:7862
All ROOT classes may have RTTI (run time type identification) support added.
Definition: TDataMember.h:33
int GetSplit(const char *type, std::vector< std::string > &output, int &nestedLoc, EModType mode=TClassEdit::kNone)
Stores in output (after emptying it) the splited type.
Definition: TClassEdit.cxx:937
virtual void MethodInfo_CreateSignature(MethodInfo_t *minfo, TString &signature) const
Definition: TCling.cxx:7525
static TProtoClass * GetProtoNorm(const char *cname)
Given the class normalized name returns the TClassProto object for the class.
TObject * FindObject(const char *name) const
Find object using its name.
Definition: THashList.cxx:212
A collection of TFunction objects designed for fast access given a DeclId_t and for keep track of TFu...
double T(double x)
Definition: ChebyshevPol.h:34
int GetMethodNArg(const char *method, const char *proto, Bool_t objectIsConst, ROOT::EFunctionMatchMode mode=ROOT::kConversionMatch) const
R__EXTERN TVirtualMutex * gInterpreterMutex
Definition: TInterpreter.h:46
bool TClingLookupHelper__ExistingTypeCheck(const std::string &tname, std::string &result)
Try hard to avoid looking up in the Cling database as this could enduce an unwanted autoparsing...
Definition: TCling.cxx:901
TList * GetListOfEnums(Bool_t load=kTRUE)
Return list containing the TEnums of a class.
Definition: TClass.cxx:3488
TString & ReplaceAll(const TString &s1, const TString &s2)
Definition: TString.h:635
const char * Name() const
bool HasMethod(const char *name) const
void Init(const char *name)
Lookup named typedef and reset the iterator to point to it.
#define assert(cond)
Definition: unittest.h:542
std::atomic< TListOfEnums * > fEnums
Definition: TClass.h:185
virtual CallFunc_t * CallFunc_FactoryCopy(CallFunc_t *func) const
Definition: TCling.cxx:6534
int GetPathInfo(const char *path, Long_t *id, Long_t *size, Long_t *flags, Long_t *modtime)
Get info about a file: id, size, flags, modification time.
Definition: TSystem.cxx:1363
virtual void Update()=0
#define gDirectory
Definition: TDirectory.h:218
void SetFunc(const TClingClassInfo *info, const char *method, const char *arglist, long *poffset)
void Destruct(void *arena, const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt) const
Double_t distance(const TPoint2 &p1, const TPoint2 &p2)
Definition: CsgOps.cxx:467
virtual const char * MethodInfo_Title(MethodInfo_t *minfo) const
Definition: TCling.cxx:7675
void SetArgArray(long *argArr, int narg)
virtual TList * GetListOfKeys() const
cling::MetaProcessor * fMetaProcessor
Definition: TCling.h:121
virtual int DataMemberInfo_TypeSize(DataMemberInfo_t *dminfo) const
Definition: TCling.cxx:7233
virtual void SetOwner(Bool_t enable=kTRUE)
Set whether this collection is the owner (enable==true) of its content.
const char * GetFullTypeName() const
Get full type description of typedef, e,g.: "class TDirectory*".
Definition: TDataType.cxx:175
Persistent version of a TClass.
Definition: TProtoClass.h:37
virtual void SetRTLD_LAZY() const
Definition: TCling.cxx:6262
Emulation of the CINT DataMemberInfo class.
TEnum * Get(DeclId_t id, const char *name)
Return (after creating it if necessary) the TEnum describing the enum corresponding to the Decl 'id'...
std::atomic< Bool_t > fHasRootPcmInfo
C++ Property of the class (is abstract, has virtual table, etc.)
Definition: TClass.h:230
TClass * GenerateTClass(const char *classname, Bool_t emulation, Bool_t silent=kFALSE)
Generate a TClass for the given class.
Definition: TCling.cxx:3522
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
Definition: TObject.cxx:892
Int_t LastIndex() const
void UpdateListOfGlobals()
No op: see TClingCallbacks (used to update the list of globals)
Definition: TCling.cxx:3100
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format...
Definition: TFile.h:45
void UpdateListOfGlobalFunctions()
No op: see TClingCallbacks (used to update the list of global functions)
Definition: TCling.cxx:3107
Emulation of the CINT MethodInfo class.
int NDefaultArg() const
ptrdiff_t GetBaseOffset(TClingClassInfo *toBase, void *address, bool isDerivedObject)
virtual std::string MethodArgInfo_TypeNormalizedName(MethodArgInfo_t *marginfo) const
Definition: TCling.cxx:7826
const char * Name() const
void SaveContext()
Save the current Cling state.
Definition: TCling.cxx:3074
virtual MethodInfo_t * CallFunc_FactoryMethod(CallFunc_t *func) const
Definition: TCling.cxx:6541
cling::Interpreter * fInterpreter
Definition: TCling.h:120
virtual ClassInfo_t * ClassInfo_Factory(Bool_t all=kTRUE) const
Definition: TCling.cxx:6799
virtual const char * HomeDirectory(const char *userName=0)
Return the user's home directory.
Definition: TSystem.cxx:881
void SetArg(long arg)
static void RemoveClassDeclId(TDictionary::DeclId_t id)
Definition: TClass.cxx:492
Long_t Property() const
Set TObject::fBits and fStreamerType to cache information about the class.
Definition: TClass.cxx:5652
virtual BaseClassInfo_t * BaseClassInfo_Factory(ClassInfo_t *info) const
Definition: TCling.cxx:7031
const char * GetClassSharedLibs(const char *cls)
Get the list of shared libraries containing the code for class cls.
Definition: TCling.cxx:5897
const char * GetValue() const
Definition: TEnv.h:114
void TCling__DEBUG__dump(clang::DeclContext *DC)
Definition: TCling.cxx:207
const TClingTypeInfo * Type() const
virtual TObject * FindObject(const char *name) const
Specialize FindObject to do search for the a function just by name or create it if its not already in...
virtual void MethodInfo_Delete(MethodInfo_t *minfo) const
Interface to cling function.
Definition: TCling.cxx:7518
virtual void CallFunc_SetArgArray(CallFunc_t *func, Long_t *paramArr, Int_t nparam) const
Definition: TCling.cxx:6639
virtual const char * TypedefInfo_TrueName(TypedefInfo_t *tinfo) const
Definition: TCling.cxx:8004
static const char * filename()
Bool_t IsPersistent() const
Definition: TDataMember.h:89
#define R__ASSERT(e)
Definition: TError.h:98
std::string GetLLVMResourceDir(bool rootbuild)
Return the LLVM / clang resource directory.
void TCling__UpdateListsOnUnloaded(const cling::Transaction &T)
Definition: TCling.cxx:545
#define gROOT
Definition: TROOT.h:340
virtual TObject * Remove(TObject *obj)
Remove object from array.
Definition: TObjArray.cxx:652
TList * GetListOfDataMembers(Bool_t load=kTRUE)
Return list containing the TDataMembers of a class.
Definition: TClass.cxx:3539
bool LoadPCM(TString pcmFileName, const char **headers, void(*triggerFunc)()) const
Tries to load a PCM; returns true on success.
Definition: TCling.cxx:1270
clang::QualType ReSubstTemplateArg(clang::QualType input, const clang::Type *instance)
Check if 'input' or any of its template parameter was substituted when instantiating the class templa...
virtual Bool_t IsTreatingNonAccessibleTypes()
virtual FuncTempInfo_t * FuncTempInfo_FactoryCopy(FuncTempInfo_t *) const
Construct a FuncTempInfo_t.
Definition: TCling.cxx:7370
void FullName(std::string &output, const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt) const
Int_t Load(const char *filenam, Bool_t system=kFALSE)
Load a library file in cling's memory.
Definition: TCling.cxx:2745
virtual int Load(const char *module, const char *entry="", Bool_t system=kFALSE)
Load a shared library.
Definition: TSystem.cxx:1818
The TEnv class reads config files, by default named .rootrc.
Definition: TEnv.h:128
std::string InsertStd(const char *tname)
Basic string class.
Definition: TString.h:137
clang::DeclContext * TCling__DEBUG__getDeclContext(clang::Decl *D)
Definition: TCling.cxx:198
TClass * GetClass(const std::type_info &typeinfo, Bool_t load) const
Demangle the name (from the typeinfo) and then request the class via the usual name based interface (...
Definition: TCling.cxx:4992
ROOT::TMetaUtils::TNormalizedCtxt * fNormalizedCtxt
Definition: TCling.h:124
TString GetMangledName(TClass *cl, const char *method, const char *params, Bool_t objectIsConst=kFALSE)
Return the cling mangled name for a method of a class with parameters params (params is a string of a...
Definition: TCling.cxx:3896
static Bool_t HasNoInfoOrEmuOrFwdDeclaredDecl(const char *)
Definition: TClass.cxx:3180
bool HasDefaultConstructor() const
virtual TApplicationImp * GetApplicationImp()
Definition: TApplication.h:137
TAlienJobStatus * status
Definition: TAlienJob.cxx:51
int Int_t
Definition: RtypesCore.h:41
TClingMethodInfo GetMethod(const char *fname) const
TClingTypeInfo * Type() const
virtual const char * DirName(const char *pathname)
Return the directory name in pathname.
Definition: TSystem.cxx:996
bool Bool_t
Definition: RtypesCore.h:59
virtual const char * MethodInfo_GetMangledName(MethodInfo_t *minfo) const
Definition: TCling.cxx:7630
virtual UInt_t FuncTempInfo_TemplateNargs(FuncTempInfo_t *) const
Return the maximum number of template arguments of the function template described by ft_info...
Definition: TCling.cxx:7393
TArc * a
Definition: textangle.C:12
virtual int DisplayIncludePath(FILE *fout) const
Interface to cling function.
Definition: TCling.cxx:6043
std::vector< std::pair< std::string, int > > FwdDeclArgsToKeepCollection_t
Definition: TInterpreter.h:108
const Bool_t kFALSE
Definition: Rtypes.h:92
void * fPrevLoadedDynLibInfo
Definition: TCling.h:127
#define gInterpreter
Definition: TInterpreter.h:502
virtual char * Which(const char *search, const char *file, EAccessMode mode=kFileExists)
Find location of file in a search path.
Definition: TSystem.cxx:1511
Each ROOT method (see TMethod) has a linked list of its arguments.
Definition: TMethodArg.h:33
virtual const char * BaseClassInfo_Name(BaseClassInfo_t *bcinfo) const
Definition: TCling.cxx:7122
virtual void TypeInfo_Delete(TypeInfo_t *tinfo) const
Definition: TCling.cxx:7839
virtual Long_t CallFunc_ExecInt(CallFunc_t *func, void *address) const
Definition: TCling.cxx:6502
Int_t DeleteVariable(const char *name)
Undeclare obj called name.
Definition: TCling.cxx:3015
virtual int SetClassAutoparsing(int)
Enable/Disable the Autoparsing of headers.
Definition: TCling.cxx:6212
long Tagnum() const
STL namespace.
Int_t GetEntriesFast() const
Definition: TObjArray.h:66
llvm::StringRef ValidArrayIndex() const
virtual int LoadFile(const char *path) const
Load a source file or library called path into the interpreter.
Definition: TCling.cxx:6143
const char * TrueName(const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt) const
Get the name of the underlying type of the current typedef.
TString & Prepend(const char *cs)
Definition: TString.h:604
void SetAutoParsingSuspended(bool val=true)
R__EXTERN TApplication * gApplication
Definition: TApplication.h:171
Abstract base class for accessing the data-members of a class.
const char * FileName()
virtual void TypeInfo_Init(TypeInfo_t *tinfo, const char *funcname) const
Definition: TCling.cxx:7869
TString GetMangledNameWithPrototype(TClass *cl, const char *method, const char *proto, Bool_t objectIsConst=kFALSE, ROOT::EFunctionMatchMode mode=ROOT::kConversionMatch)
Return the cling mangled name for a method of a class with a certain prototype, i.e.
Definition: TCling.cxx:3923
std::vector< cling::Value > * fTemporaries
Definition: TCling.h:123
virtual ~TCling()
Destroy the interpreter interface.
Definition: TCling.cxx:1187
virtual const char * DataMemberInfo_Title(DataMemberInfo_t *dminfo) const
Definition: TCling.cxx:7265
virtual void LoadFunctionTemplates(TClass *cl) const
Create list of pointers to function templates for TClass cl.
Definition: TCling.cxx:3428
void GetCppName(std::string &output, const char *input)
Return (in the argument 'output') a mangled version of the C++ symbol/type (pass as 'input') that can...
virtual bool MethodArgInfo_IsValid(MethodArgInfo_t *marginfo) const
Definition: TCling.cxx:7778
const char * Title()
virtual bool Update(FuncTempInfo_t *info)
Update the TFunctionTemplate to reflect the new info.
virtual Long_t DataMemberInfo_Property(DataMemberInfo_t *dminfo) const
Definition: TCling.cxx:7217
virtual Long_t TypedefInfo_Property(TypedefInfo_t *tinfo) const
Definition: TCling.cxx:7988
virtual void * ClassInfo_New(ClassInfo_t *info) const
Definition: TCling.cxx:6919
size_t
Definition: TBuffer.cxx:28
const clang::Type * GetType() const
Bool_t BeginsWith(const char *s, ECaseCompare cmp=kExact) const
Definition: TString.h:558
static double A[]
Emulation of the CINT CallFunc class.
virtual int DisplayClass(FILE *fout, const char *name, int base, int start) const
Definition: TCling.cxx:6034
void GetQualifiedName(std::string &qual_name, const clang::QualType &type, const clang::NamedDecl &forcontext)
Main implementation relying on GetFullyQualifiedTypeName All other GetQualifiedName functions leverag...
virtual const char * GetTopLevelMacroName() const
Return the file name of the current un-included interpreted file.
Definition: TCling.cxx:4324
virtual TObject * At(Int_t idx) const
Returns the object at position idx. Returns 0 if idx is out of range.
Definition: TList.cxx:310
virtual int GetProcInfo(ProcInfo_t *info) const
Returns cpu and memory used by this process into the ProcInfo_t structure.
Definition: TSystem.cxx:2443
TObject Int_t at
MethodInfo_t * fInfo
Definition: TFunction.h:36
Bool_t R_ISREG(Int_t mode)
Definition: TSystem.h:129
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition: TObject.cxx:732
virtual void SetDeclAttr(DeclId_t, const char *)
Definition: TCling.cxx:7284
virtual bool ClassInfo_IsValidMethod(ClassInfo_t *info, const char *method, const char *proto, Long_t *offset, ROOT::EFunctionMatchMode=ROOT::kConversionMatch) const
Definition: TCling.cxx:6895
virtual int DataMemberInfo_MaxIndex(DataMemberInfo_t *dminfo, Int_t dim) const
Definition: TCling.cxx:7193
V GetOffset(E val1, E val2, V iso)
void Execute(const char *function, const char *params, int *error=0)
Execute a global function with arguments params.
Definition: TCling.cxx:4141
virtual const char * FindFile(const char *search, TString &file, EAccessMode mode=kFileExists)
Find location of file in a search path.
Definition: TSystem.cxx:1501
const char * GetSharedLibDeps(const char *lib)
Get the list a libraries on which the specified lib depends.
Definition: TCling.cxx:5939
const char * Name
Definition: TXMLSetup.cxx:67
static const char * GetMacroPath()
Get macro search path. Static utility function.
Definition: TROOT.cxx:2406
bool ExtractAttrPropertyFromName(const clang::Decl &decl, const std::string &propName, std::string &propValue)
This routine counts on the "propNamepropValue" format.
virtual void SetValue(const char *name, const char *value, EEnvLevel level=kEnvChange, const char *type=0)
Set the value of a resource or create a new resource.
Definition: TEnv.cxx:749
std::set< size_t > fPayloads
Definition: TCling.h:112
TDictionary * Find(DeclId_t id) const
Return (after creating it if necessary) the TDataMember describing the data member corresponding to t...
Int_t fMode
Definition: TSystem.h:138
const TSeqCollection * GetConstants() const
Definition: TEnum.h:66
virtual Long_t GetExecByteCode() const
This routines used to return the address of the internal wrapper function (of the interpreter) that w...
Definition: TCling.cxx:6102
virtual void MethodArgInfo_Delete(MethodArgInfo_t *marginfo) const
Definition: TCling.cxx:7747
std::vector< const char * > fCurExecutingMacros
Definition: TCling.h:139
Bool_t IsValid()
Return true if this data member object is pointing to a currently loaded data member.
virtual int TypeInfo_RefType(TypeInfo_t *) const
Definition: TCling.cxx:7902
const char * Data() const
Definition: TString.h:349
void AddFriendToClass(clang::FunctionDecl *, clang::CXXRecordDecl *) const
Inject function as a friend into klass.
Definition: TCling.cxx:6384
virtual Long_t BaseClassInfo_Offset(BaseClassInfo_t *toBaseClassInfo, void *address, bool isDerivedObject) const
Definition: TCling.cxx:7067
virtual TObject * FindObject(const char *name) const
Find an object in this collection using its name.
Definition: TObjArray.cxx:395
void TCling__DEBUG__decl_dump(void *D)
Definition: TCling.cxx:216
Int_t UnloadLibraryMap(const char *library)
Unload library map entries coming from the specified library.
Definition: TCling.cxx:4896
virtual void Fatal(const char *method, const char *msgfmt,...) const
Issue fatal error message.
Definition: TObject.cxx:946
virtual TEnum * CreateEnum(void *VD, TClass *cl) const
Definition: TCling.cxx:421
virtual void GenericError(const char *error) const
Let the interpreter issue a generic error, and set its error state.
Definition: TCling.cxx:6080
void ClearStack()
Delete existing temporary values.
Definition: TCling.cxx:2430
virtual const char * GetDirEntry(void *dirp)
Get a directory entry. Returns 0 if no more entries.
Definition: TSystem.cxx:847
virtual void ClassInfo_Init(ClassInfo_t *info, const char *funcname) const
Definition: TCling.cxx:6846
void ResetAll()
Reset the Cling state to its initial state.
Definition: TCling.cxx:2941
void Exec(void *address, TInterpreterValue *interpVal=0)
int ReadRootmapFile(const char *rootmapfile, TUniqueString *uniqueString=nullptr)
Read and parse a rootmapfile in its new format, and return 0 in case of success, -1 if the file has a...
Definition: TCling.cxx:4433
const clang::Type * GetUnderlyingType(clang::QualType type)
Return the base/underlying type of a chain of array or pointers type.
int Next()
Increment the iterator.
void CreateSignature(TString &signature) const
virtual void CallFunc_Init(CallFunc_t *func) const
Definition: TCling.cxx:6557
TInterpreter::CallFuncIFacePtr_t IFacePtr()
Int_t GenerateDictionary(const char *classes, const char *includes=0, const char *options=0)
Generate the dictionary for the C++ classes listed in the first argument (in a semi-colon separated l...
Definition: TCling.cxx:3694
THashTable implements a hash table to store TObject's.
Definition: THashTable.h:39
const char * TCling__GetClassSharedLibs(const char *className)
Definition: TCling.cxx:598
clang::NamespaceDecl * TCling__DEBUG__DCtoNamespace(clang::DeclContext *DC)
Definition: TCling.cxx:201
const Config_t & GetConfig() const
Definition: TMetaUtils.cxx:335
void ExecuteWithArgsAndReturn(TMethod *method, void *address, const void *args[]=0, int nargs=0, void *ret=0) const
Definition: TCling.cxx:4293
virtual DeclId_t GetDataMember(ClassInfo_t *cl, const char *name) const
Return pointer to cling Decl of global/static variable that is located at the address given by addr...
Definition: TCling.cxx:3739
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString...
Definition: TString.cxx:2334
virtual TypedefInfo_t * TypedefInfo_Factory() const
Definition: TCling.cxx:7939
virtual Long_t BaseClassInfo_Property(BaseClassInfo_t *bcinfo) const
Definition: TCling.cxx:7088
Vc_ALWAYS_INLINE void free(T *p)
Frees memory that was allocated with Vc::malloc.
Definition: memory.h:94
void Class()
Definition: Class.C:29
virtual void Sleep(UInt_t milliSec)
Sleep milliSec milli seconds.
Definition: TSystem.cxx:441
THashList implements a hybrid collection class consisting of a hash table and a list to store TObject...
Definition: THashList.h:36
Bool_t CheckClassInfo(const char *name, Bool_t autoload, Bool_t isClassOrNamespaceOnly=kFALSE)
Checks if an entity with the specified name is defined in Cling.
Definition: TCling.cxx:3216
std::atomic< TList * > fBase
Definition: TClass.h:182
virtual void CallFunc_Exec(CallFunc_t *func, void *address) const
Definition: TCling.cxx:6467
Bool_t Declare(const char *code)
Declare code to the interpreter, without any of the interpreter actions that could trigger a re-inter...
Definition: TCling.cxx:2443
std::map< const cling::Transaction *, size_t > fTransactionHeadersMap
Definition: TCling.h:110
virtual UInt_t FuncTempInfo_TemplateMinReqArgs(FuncTempInfo_t *) const
Return the number of required template arguments of the function template described by ft_info...
Definition: TCling.cxx:7404
void ShortType(std::string &answer, int mode)
Return the absolute type of typeDesc into the string answ.
Definition: TClassEdit.cxx:197
void GetInterpreterTypeName(const char *name, std::string &output, Bool_t full=kFALSE)
The 'name' is known to the interpreter, this function returns the internal version of this name (usua...
Definition: TCling.cxx:4108
The TNamed class is the base class for all named ROOT classes.
Definition: TNamed.h:33
void SetObjectValidity(EObjectPointerState val)
const char * Title()
void CreateListOfDataMembers(TClass *cl) const
Create list of pointers to data members for TClass cl.
Definition: TCling.cxx:3465
void SetArgs(const char *args)
char * DemangleName(const char *mangled_name, int &errorCode)
Definition: TClassEdit.h:178
void * GetInterfaceMethodWithPrototype(TClass *cl, const char *method, const char *proto, Bool_t objectIsConst=kFALSE, ROOT::EFunctionMatchMode mode=ROOT::kConversionMatch)
Return pointer to cling interface function for a method of a class with a certain prototype...
Definition: TCling.cxx:4018
UChar_t mod R__LOCKGUARD2(gSrvAuthenticateMutex)
virtual void ClassInfo_DeleteArray(ClassInfo_t *info, void *arena, bool dtorOnly) const
Definition: TCling.cxx:6783
long ClassProperty() const
DeclId_t GetFunctionWithPrototype(ClassInfo_t *cl, const char *method, const char *proto, Bool_t objectIsConst=kFALSE, ROOT::EFunctionMatchMode mode=ROOT::kConversionMatch)
Return pointer to cling interface function for a method of a class with a certain prototype...
Definition: TCling.cxx:4063
void Init(TClassEdit::TInterpreterLookupHelper *helper)
Definition: TClassEdit.cxx:118
virtual MethodInfo_t * MethodInfo_FactoryCopy(MethodInfo_t *minfo) const
Definition: TCling.cxx:7559
void ClearFileBusy()
Reset the interpreter internal state in case a previous action was not correctly terminated.
Definition: TCling.cxx:2422
virtual Int_t Lock()=0
static void UpdateClassInfo(char *name, Long_t tagnum)
No op: see TClingCallbacks.
Definition: TCling.cxx:5558
TClass * GetClass() const
Definition: TListOfEnums.h:66
void CreateListOfBaseClasses(TClass *cl) const
Create list of pointers to base class(es) for TClass cl.
Definition: TCling.cxx:3359
virtual const char * GetDynamicPath()
Return the dynamic path (used to find shared libraries).
Definition: TSystem.cxx:1757
virtual Long_t DataMemberInfo_Offset(DataMemberInfo_t *dminfo) const
Definition: TCling.cxx:7209
TString fSharedLibs
Definition: TCling.h:104
std::map< std::string, std::string >::const_iterator iter
Definition: TAlienJob.cxx:54
void Clear()
Clear string without changing its capacity.
Definition: TString.cxx:1139
bool Append(const std::string &str)
Append string to the storage if not added already.
Definition: TCling.cxx:1020
virtual int CompileMacro(const char *filename, Option_t *opt="", const char *library_name="", const char *build_dir="", UInt_t dirmode=0)
This method compiles and loads a shared library containing the code from the file "filename"...
Definition: TSystem.cxx:2788
virtual const char * ClassInfo_FileName(ClassInfo_t *info) const
Definition: TCling.cxx:6975
virtual const char * TypeInfo_Name(TypeInfo_t *) const
Definition: TCling.cxx:7886
virtual const char * Getenv(const char *env)
Get environment variable.
Definition: TSystem.cxx:1627
virtual const char * MapCppName(const char *) const
Interface to cling function.
Definition: TCling.cxx:6165
if(pyself &&pyself!=Py_None)
TEnv * fMapfile
Definition: TCling.h:108
EFunctionMatchMode
Definition: TDictionary.h:155
void Info(const char *location, const char *msgfmt,...)
TString & Append(const char *cs)
Definition: TString.h:492
static bool IsEnum(cling::Interpreter *interp, const char *name)
virtual const char * PrependPathName(const char *dir, TString &name)
Concatenate a directory and a file name.
Definition: TSystem.cxx:1054
virtual const char * GetCurrentMacroName() const
Return the file name of the currently interpreted file, included or not.
Definition: TCling.cxx:4371
virtual int SetClassAutoloading(int) const
Enable/Disable the Autoloading of libraries.
Definition: TCling.cxx:6197
ULong64_t fTransactionCount
Definition: TCling.h:138
const char * GetDefault() const
Get default value of method argument.
Definition: TMethodArg.cxx:58
virtual bool ClassInfo_IsBase(ClassInfo_t *info, const char *name) const
Definition: TCling.cxx:6864
char * DemangleTypeIdName(const std::type_info &ti, int &errorCode)
Demangle in a portable way the type id name.
virtual Long_t ClassInfo_GetBaseOffset(ClassInfo_t *fromDerived, ClassInfo_t *toBase, void *address, bool isDerivedObject) const
Definition: TCling.cxx:7075
DeclId_t GetFunction(ClassInfo_t *cl, const char *funcname)
Return pointer to cling interface function for a method of a class with a certain name...
Definition: TCling.cxx:3963
virtual int MethodInfo_NArg(MethodInfo_t *minfo) const
Definition: TCling.cxx:7582
bool IsValid() const
long Property() const
Return a bit mask of metadata about the current typedef.
virtual void Setgvp(Long_t) const
Interface to the cling global object pointer which was controlling the behavior of the wrapper around...
Definition: TCling.cxx:6247
const char * TypeName() const
Long_t ProcessLine(const char *line, EErrorCode *error=0)
Let cling process a command line.
Definition: TCling.cxx:1855
virtual Long_t ClassInfo_Property(ClassInfo_t *info) const
Definition: TCling.cxx:6951
virtual bool Update(DataMemberInfo_t *info)
Update the TFunction to reflect the new info.
R__EXTERN int optind
Definition: TCling.cxx:301
static void Add(const char *cname, Version_t id, const type_info &info, DictFuncPtr_t dict, Int_t pragmabits)
Add a class to the class table (this is a static function).
Emulation of the CINT TypeInfo class.
virtual int TypedefInfo_Next(TypedefInfo_t *tinfo) const
Definition: TCling.cxx:7980
virtual bool TypeInfo_IsValid(TypeInfo_t *tinfo) const
Definition: TCling.cxx:7878
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:918
clang::RecordDecl * TCling__DEBUG__DCtoRecordDecl(clang::DeclContext *DC)
Definition: TCling.cxx:204
This class defines an interface to the cling C++ interpreter.
Definition: TCling.h:92
Bool_t IgnoreDuplicates(Bool_t ignore)
If set to true, no warnings in case of duplicates are issued.
Definition: TEnv.cxx:806
TClass *(* DictFuncPtr_t)()
Definition: Rtypes.h:75
TVirtualPad is an abstract base class for the Pad and Canvas classes.
Definition: TVirtualPad.h:59
DeclId_t GetDeclId(const llvm::GlobalValue *gv) const
Return pointer to cling DeclId for a global value.
Definition: TCling.cxx:3806
def Namespace(name)
Definition: cppyy.py:193
const char * TypeTrueName(const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt) const
Int_t UnloadAllSharedLibraryMaps()
Unload the library map entries coming from all the loaded shared libraries.
Definition: TCling.cxx:4878
void InitRootmapFile(const char *name)
Create a resource table and read the (possibly) three resource files, i.e $ROOTSYS/etc/system (...
Definition: TCling.cxx:4536
std::string GetModuleFileName(const char *moduleName)
Return the dictionary file name for a module.
std::string GetInterpreterExtraIncludePath(bool rootbuild)
Return the -I needed to find RuntimeUniverse.h.
std::string GetLong64_Name(const char *original)
Replace 'long long' and 'unsigned long long' by 'Long64_t' and 'ULong64_t'.
Definition: TClassEdit.cxx:816
void InspectMembers(TMemberInspector &, const void *obj, const TClass *cl, Bool_t isTransient)
Visit all members over members, recursing over base classes.
Definition: TCling.cxx:2051
virtual bool ClassInfo_IsEnum(const char *name) const
Definition: TCling.cxx:6872
static void TCling__UpdateClassInfo(const NamedDecl *TD)
Update TClingClassInfo for a class (e.g. upon seeing a definition).
Definition: TCling.cxx:343
void * InterfaceMethod()
void TCling__DEBUG__printName(clang::Decl *D)
Definition: TCling.cxx:219
EComplexType GetComplexType(const char *)
Definition: TClassEdit.cxx:96
long ExtraProperty() const
void GetObject(const char *namecycle, T *&ptr)
virtual Long_t DataMemberInfo_TypeProperty(DataMemberInfo_t *dminfo) const
Definition: TCling.cxx:7225
TCppMethod_t GetMethod(TCppScope_t scope, TCppIndex_t imeth)
Definition: Cppyy.cxx:701
A doubly linked list.
Definition: TList.h:47
static const char * what
Definition: stlLoader.cc:6
virtual Bool_t IsCmdThread()
Definition: TApplication.h:136
#define R__DLLEXPORT
Definition: TCling.cxx:127
void PrintIntro()
No-op; see TRint instead.
Definition: TCling.cxx:2033
TString fRootmapLoadPath
Definition: TCling.h:107
R__EXTERN TVirtualMutex * gGlobalMutex
Definition: TVirtualMutex.h:29
virtual Int_t ReadFile(const char *fname, EEnvLevel level)
Read and parse the resource file for a certain level.
Definition: TEnv.cxx:595
const Decl * TCling__GetObjectDecl(TObject *obj)
Definition: TCling.cxx:571
R__EXTERN TROOT * gROOTLocal
Definition: TROOT.h:337
void UpdateListOfTypes()
No op: see TClingCallbacks (used to update the list of types)
Definition: TCling.cxx:3114
virtual const char * TypeInfo_TrueName(TypeInfo_t *tinfo) const
Definition: TCling.cxx:7918
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, etc.) and adding default template argument for all types except the STL collections where we remove the default template argument if any.
virtual std::string MethodInfo_TypeNormalizedName(MethodInfo_t *minfo) const
Definition: TCling.cxx:7664
const char * Name() const
Definition: TEnv.h:91
const char * TmpltName() const
UInt_t AutoParseImplRecurse(const char *cls, bool topLevel)
Helper routine for TCling::AutoParse implementing the actual call to the parser and looping over temp...
Definition: TCling.cxx:5191
virtual TList * GetListOfMethodArgs()
Returns methodarg list and additionally updates fDataMember in TMethod by calling FindDataMember();...
Definition: TMethod.cxx:305
virtual void CallFunc_SetArgs(CallFunc_t *func, const char *param) const
Definition: TCling.cxx:6647
const char * TmpltName() const
void Init(const char *name)
void function(const char *name_, T fun, const char *docstring=0)
Definition: RExports.h:159
bool TCling__TEST_isInvalidDecl(clang::Decl *D)
Definition: TCling.cxx:234
TClingClassInfo * GetBase() const
std::vector< void * > fRegisterModuleDyLibs
Definition: TCling.h:128
TFunctionTemplate * Get(DeclId_t id)
Return (after creating it if necessary) the TMethod or TFunction describing the function correspondin...
Int_t AutoParse(const char *cls)
Parse the headers relative to the class Returns 1 in case of success, 0 in case of failure...
Definition: TCling.cxx:5319
virtual bool MethodInfo_IsValid(MethodInfo_t *minfo) const
Definition: TCling.cxx:7574
int MaxIndex(int dim) const
void TCling__SplitAclicMode(const char *fileName, string &mode, string &args, string &io, string &fname)
Definition: TCling.cxx:622
static double C[]
const char * GetName() const
Returns name of object.
Definition: TEnv.h:113
int Size() const
virtual Long_t TypeInfo_Property(TypeInfo_t *tinfo) const
Definition: TCling.cxx:7894
Bool_t EndsWith(const char *pat, ECaseCompare cmp=kExact) const
Return true if string ends with the specified string.
Definition: TString.cxx:2220
Emulation of the CINT BaseClassInfo class.
TClingMethodInfo * FactoryMethod() const
Double_t length(const TVector2 &v)
Definition: CsgOps.cxx:347
R__EXTERN TSystem * gSystem
Definition: TSystem.h:549
return
Definition: TBase64.cxx:62
void * InterfaceMethod(const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt) const
virtual const char * DataMemberInfo_TypeTrueName(DataMemberInfo_t *dminfo) const
Definition: TCling.cxx:7249
ptrdiff_t Offset(void *address=0, bool isDerivedObject=true) const
virtual void GetFunctionName(const clang::FunctionDecl *decl, std::string &name) const
Definition: TCling.cxx:7321
Basic data type descriptor (datatype information is obtained from CINT).
Definition: TDataType.h:46
void SetFuncProto(const TClingClassInfo *info, const char *method, const char *proto, long *poffset, ROOT::EFunctionMatchMode mode=ROOT::kConversionMatch)
virtual void LoadEnums(TListOfEnums &cl) const
Create list of pointers to enums for TClass cl.
Definition: TCling.cxx:3383
std::set< TClass * > & GetModTClasses()
Definition: TCling.h:505
virtual int TypeInfo_Size(TypeInfo_t *tinfo) const
Definition: TCling.cxx:7910
static void UpdateAllCanvases()
Update all canvases at end the terminal input command.
Definition: TCling.cxx:5573
const clang::FunctionDecl * GetMethodDecl() const
const char * TrueName(const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt) const
Return the normalized name of the type (i.e.
ClassInfo_t * GetClassInfo() const
Definition: TClass.h:391
virtual CallFunc_t * CallFunc_Factory() const
Definition: TCling.cxx:6526
Long_t fMemVirtual
Definition: TSystem.h:207
const char * DefaultValue() const
const T * GetAnnotatedRedeclarable(const T *Redecl)
Definition: TMetaUtils.h:617
static Long_t ExecuteFile(const char *file, Int_t *error=0, Bool_t keep=kFALSE)
Execute a file containing a C++ macro (static method).
virtual TEnvRec * Lookup(const char *n)
Loop over all resource records and return the one with name.
Definition: TEnv.cxx:550
TObject * Remove(TObject *obj)
Remove object from the list.
Definition: THashList.cxx:284
virtual Int_t AutoParse(const char *cls)=0
Collection abstract base class.
Definition: TCollection.h:48
Bool_t SetErrorMessages(Bool_t enable=kTRUE)
If error messages are disabled, the interpreter should suppress its failures and warning messages fro...
Definition: TCling.cxx:5980
int TCling__AutoParseCallback(const char *className)
Definition: TCling.cxx:593
virtual const char * DataMemberInfo_ValidArrayIndex(DataMemberInfo_t *dminfo) const
Definition: TCling.cxx:7273
void SaveGlobalsContext()
Save the current Cling state of global objects.
Definition: TCling.cxx:3087
void UpdateClassInfoWithDecl(const void *vTD)
Internal function. Inform a TClass about its new TagDecl or NamespaceDecl.
Definition: TCling.cxx:5485
unsigned int UInt_t
Definition: RtypesCore.h:42
virtual Long_t BaseClassInfo_Tagnum(BaseClassInfo_t *bcinfo) const
Definition: TCling.cxx:7104
Bool_t TestBit(UInt_t f) const
Definition: TObject.h:173
virtual Bool_t IsValid()
Return true if this global object is pointing to a currently loaded global.
Definition: TGlobal.cxx:131
TMarker * m
Definition: textangle.C:8
virtual const char * ClassInfo_Title(ClassInfo_t *info) const
Definition: TCling.cxx:7001
void UpdateListOfLoadedSharedLibraries()
Definition: TCling.cxx:2598
char * Form(const char *fmt,...)
virtual void CallFunc_SetFunc(CallFunc_t *func, ClassInfo_t *info, const char *method, const char *params, Long_t *Offset) const
Definition: TCling.cxx:6655
virtual TypeInfo_t * MethodInfo_Type(MethodInfo_t *minfo) const
Definition: TCling.cxx:7622
Long_t Calc(const char *line, EErrorCode *error=0)
Directly execute an executable statement (e.g.
Definition: TCling.cxx:2819
Double_t E()
Definition: TMath.h:54
Int_t RescanLibraryMap()
Scan again along the dynamic path for library maps.
Definition: TCling.cxx:4805
ROOT::ESTLType IsSTLCont(const clang::RecordDecl &cl)
type : type name: vector,allocator> result: 0 : not stl container abs(result):...
TLine * l
Definition: textangle.C:4
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:51
The TEnumConstant class implements the constants of the enum type.
Definition: TEnumConstant.h:33
virtual const char * Getp2f2funcname(void *receiver) const
Definition: TCling.cxx:6120
virtual bool TypedefInfo_IsValid(TypedefInfo_t *tinfo) const
Definition: TCling.cxx:7972
virtual Bool_t LoadText(const char *text) const
Load the declarations from text into the interpreter.
Definition: TCling.cxx:6157
The ROOT global object gROOT contains a list of all defined classes.
Definition: TClass.h:81
virtual int MethodInfo_Next(MethodInfo_t *minfo) const
Definition: TCling.cxx:7598
clang::QualType GetQualType() const
const std::string sname
Definition: testIO.cxx:45
virtual int MethodInfo_NDefaultArg(MethodInfo_t *minfo) const
Definition: TCling.cxx:7590
virtual int MethodArgInfo_Next(MethodArgInfo_t *marginfo) const
Definition: TCling.cxx:7786
const Int_t kWarning
Definition: TError.h:40
Global variables class (global variables are obtained from CINT).
Definition: TGlobal.h:29
Definition: TEnv.h:77
void * LazyFunctionCreatorAutoload(const std::string &mangled_name)
Autoload a library based on a missing symbol.
Definition: TCling.cxx:5375
Version_t GetClassVersion() const
Definition: TClass.h:382
Bool_t IsNull() const
Definition: TString.h:387
Long_t ExecuteMacro(const char *filename, EErrorCode *error=0)
Execute a cling macro.
Definition: TCling.cxx:4311
virtual void Initialize()
Initialize the interpreter, once TROOT::fInterpreter is set.
Definition: TCling.cxx:1212
Bool_t CheckClassTemplate(const char *name)
Return true if there is a class template by the given name ...
Definition: TCling.cxx:3339
static void indent(ostringstream &buf, int indent_level)
THashList * GetTable() const
Definition: TEnv.h:144
virtual void CallFunc_SetFuncProto(CallFunc_t *func, ClassInfo_t *info, const char *method, const char *proto, Long_t *Offset, ROOT::EFunctionMatchMode mode=ROOT::kConversionMatch) const
Interface to cling function.
Definition: TCling.cxx:6682
void SetPathsForRelocatability(std::vector< std::string > &clingArgs)
Organise the parameters for cling in order to guarantee relocatability It treats the gcc toolchain an...
Long64_t entry
TString fName
Definition: TNamed.h:36
virtual void FreeDirectory(void *dirp)
Free a directory.
Definition: TSystem.cxx:839
virtual const char * MethodInfo_GetPrototype(MethodInfo_t *minfo) const
Definition: TCling.cxx:7640
TDictionary::DeclId_t GetDeclId() const
virtual void CallFunc_ExecWithArgsAndReturn(CallFunc_t *func, void *address, const void *args[]=0, int nargs=0, void *ret=0) const
Definition: TCling.cxx:6491
TObject * TCling__GetObjectAddress(const char *Name, void *&LookupCtx)
Definition: TCling.cxx:567
virtual Bool_t FuncTempInfo_IsValid(FuncTempInfo_t *) const
Check validity of a FuncTempInfo_t.
Definition: TCling.cxx:7381
TObjArray * Tokenize(const TString &delim) const
This function is used to isolate sequential tokens in a TString.
Definition: TString.cxx:2240
Each class (see TClass) has a linked list of its base class(es).
Definition: TBaseClass.h:35
const char * Name() const
Get the name of the current typedef.
void EnableAutoLoading()
Enable the automatic loading of shared libraries when a class is used that is stored in a not yet loa...
Definition: TCling.cxx:2469
Type
enumeration specifying the integration types.
Bool_t fLockProcessLine
Definition: TCling.h:117
R__DLLEXPORT void DestroyInterpreter(TInterpreter *interp)
Definition: TCling.cxx:581
bool IsAutoloadingEnabled()
const char * TypeName() const
TDictionary::DeclId_t DeclId_t
Definition: TListOfEnums.h:63
virtual void CallFunc_Delete(CallFunc_t *func) const
Definition: TCling.cxx:6460
Bool_t CallShowMembers(const void *obj, TMemberInspector &insp, Bool_t isTransient=kFALSE) const
Call ShowMembers() on the obj of this class type, passing insp and parent.
Definition: TClass.cxx:2111
std::unordered_set< const clang::NamespaceDecl * > fNSFromRootmaps
Definition: TCling.h:115
virtual const char * BaseClassInfo_FullName(BaseClassInfo_t *bcinfo) const
Definition: TCling.cxx:7112
virtual MethodInfo_t * MethodInfo_Factory() const
Definition: TCling.cxx:7533
void TCling__GetNormalizedContext(const ROOT::TMetaUtils::TNormalizedCtxt *&normCtxt)
Definition: TCling.cxx:532
int Size() const
Return the size in bytes of the underlying type of the current typedef.
virtual const char * FindDynamicLibrary(TString &lib, Bool_t quiet=kFALSE)
Find a dynamic library using the system search paths.
Definition: TSystem.cxx:1972
void EndOfLineAction()
It calls a "fantom" method to synchronize user keyboard input and ROOT prompt line.
Definition: TCling.cxx:2481
std::string GetMangledName() const
TString & Remove(Ssiz_t pos)
Definition: TString.h:616
const char * Name(const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt) const
long Long_t
Definition: RtypesCore.h:50
Bool_t IsLoaded() const
Return true if the shared library of this class is currently in the a process's memory.
Definition: TClass.cxx:5526
void SetClassInfo(TClass *cl, Bool_t reload=kFALSE)
Set pointer to the TClingClassInfo in TClass.
Definition: TCling.cxx:3123
int Ssiz_t
Definition: RtypesCore.h:63
Emulation of the CINT TypedefInfo class.
const clang::Decl * GetDecl() const
const char * TypeName() const
A collection of TEnum objects designed for fast access given a DeclId_t and for keep track of TEnum t...
int(* AutoLoadCallBack_t)(const char *)
Definition: TInterpreter.h:107
virtual const char * MethodArgInfo_DefaultValue(MethodArgInfo_t *marginfo) const
Definition: TCling.cxx:7802
virtual const char * ClassInfo_Name(ClassInfo_t *info) const
Definition: TCling.cxx:6993
virtual const char * GetIncludePath()
Get the list of include path.
Definition: TSystem.cxx:3805
virtual bool DataMemberInfo_IsValid(DataMemberInfo_t *dminfo) const
Definition: TCling.cxx:7185
int TCling_GenerateDictionary(const std::vector< std::string > &classes, const std::vector< std::string > &headers, const std::vector< std::string > &fwdDecls, const std::vector< std::string > &unknown)
Definition: TCling.cxx:678
TInterpreterValue * CreateTemporary()
The created temporary must be deleted by the caller.
Definition: TCling.cxx:6294
void GetFunctionOverloads(ClassInfo_t *cl, const char *funcname, std::vector< DeclId_t > &res) const
Insert overloads of name in cl to res.
Definition: TCling.cxx:3982
void UpdateListsOnUnloaded(const cling::Transaction &T)
Definition: TCling.cxx:5734
virtual FuncTempInfo_t * FuncTempInfo_Factory(DeclId_t declid) const
Construct a FuncTempInfo_t.
Definition: TCling.cxx:7359
TObjArray * fStreamerInfo
Definition: TClass.h:179
double f(double x)
virtual void FuncTempInfo_Title(FuncTempInfo_t *, TString &name) const
Return the comments associates with this function template.
Definition: TCling.cxx:7486
std::set< size_t > fLookedUpClasses
Definition: TCling.h:111
void UpdateListOfDataMembers(TClass *cl) const
Update the list of pointers to data members for TClass cl This is now a nop.
Definition: TCling.cxx:3492
MyComplex< T > P(MyComplex< T > z, T c_real, T c_imag)
[MyComplex]
Definition: mandel.cpp:155
const char * GetParent() const
void UnloadClassMembers(TClass *cl, const clang::DeclContext *DC)
Helper function to go through the members of a class or namespace and unload them.
Definition: TCling.cxx:5681
virtual const void * GetValAddr() const =0
EState fState
cached of the streaming method to use
Definition: TClass.h:237
void TCling__LibraryLoadedRTTI(const void *dyLibHandle, const char *canonicalName)
Definition: TCling.cxx:553
double Double_t
Definition: RtypesCore.h:55
Emulation of the CINT MethodInfo class.
char * DynamicPathName(const char *lib, Bool_t quiet=kFALSE)
Find a dynamic library called lib using the system search paths.
Definition: TSystem.cxx:1958
TText * text
static DictFuncPtr_t GetDict(const char *cname)
Given the class name returns the Dictionary() function of a class (uses hash of name).
virtual Bool_t ClassInfo_Contains(ClassInfo_t *info, DeclId_t declid) const
Return true if the entity pointed to by 'declid' is declared in the context described by 'info'...
Definition: TCling.cxx:6739
Definition: TCling.h:48
TFunction * Find(DeclId_t id) const
Return the TMethod or TFunction describing the function corresponding to the Decl 'id'...
virtual const char * DataMemberInfo_Name(DataMemberInfo_t *dminfo) const
Definition: TCling.cxx:7257
void Unload()
Mark 'all func' as being unloaded.
virtual int DataMemberInfo_ArrayDim(DataMemberInfo_t *dminfo) const
Definition: TCling.cxx:7143
void RegisterTClassUpdate(TClass *oldcl, DictFuncPtr_t dict)
Register classes that already existed prior to their dictionary loading and that already had a ClassI...
Definition: TCling.cxx:1823
Bool_t IsAutoLoadNamespaceCandidate(const char *name)
Definition: TCling.cxx:5467
virtual void CallFunc_ResetArg(CallFunc_t *func) const
Definition: TCling.cxx:6583
virtual void FuncTempInfo_Delete(FuncTempInfo_t *) const
Delete the FuncTempInfo_t.
Definition: TCling.cxx:7350
TDictionary::DeclId_t DeclId_t
void DeleteArray(void *arena, bool dtorOnly, const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt) const
int type
Definition: TGX11.cxx:120
static const float S
Definition: mandel.cpp:113
void ResetGlobalVar(void *obj)
Reset the Cling 'user' global objects/variables state to the state saved by the last call to TCling::...
Definition: TCling.cxx:2971
unsigned long long ULong64_t
Definition: RtypesCore.h:70
Definition: TDatime.h:114
ClassImp(TMCParticle) void TMCParticle printf(": p=(%7.3f,%7.3f,%9.3f) ;", fPx, fPy, fPz)
DeclId_t GetFunctionTemplate(ClassInfo_t *cl, const char *funcname)
Return pointer to cling interface function for a method of a class with a certain name...
Definition: TCling.cxx:4085
TNamed()
Definition: TNamed.h:40
unsigned long ULong_t
Definition: RtypesCore.h:51
virtual Long64_t CallFunc_ExecInt64(CallFunc_t *func, void *address) const
Definition: TCling.cxx:6510
void Reset()
Pressing Ctrl+C should forward here.
Definition: TCling.cxx:2925
Int_t LoadLibraryMap(const char *rootmapfile=0)
Load map between class and library.
Definition: TCling.cxx:4615
void CreateListOfMethodArgs(TFunction *m) const
Create list of pointers to method arguments for TMethod m.
Definition: TCling.cxx:3499
Bool_t fAllowLibLoad
Definition: TCling.h:118
TObjArray * fRootmapFiles
Definition: TCling.h:116
double func(double *x, double *p)
Definition: stressTF1.cxx:213
void * fAutoLoadCallBack
Definition: TCling.h:137
virtual void Expand(Int_t newSize)
Expand or shrink the array to newSize elements.
Definition: TObjArray.cxx:369
std::set< const char * > fParsedPayloadsAddresses
Definition: TCling.h:113
ROOT::TMetaUtils::TClingLookupHelper * fLookupHelper
Definition: TCling.h:125
void FullName(std::string &output, const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt) const
TClingCallbacks * fClingCallbacks
Definition: TCling.h:129
Int_t AutoLoad(const char *classname, Bool_t knowDictNotLoaded=kFALSE)
Load library containing the specified class.
Definition: TCling.cxx:5038
Emulation of the CINT ClassInfo class.
EObjectPointerState GetObjectValidity() const
virtual ~TROOT()
Clean up and free resources used by ROOT (files, network sockets, shared memory segments, etc.).
Definition: TROOT.cxx:661
virtual int GetSecurityError() const
Interface to cling function.
Definition: TCling.cxx:6130
#define R__LOCKGUARD(mutex)
void InspectMember(const T &obj, const char *name, Bool_t isTransient)
Int_t GetEntries() const
Return the number of objects in array (i.e.
Definition: TObjArray.cxx:493
long Property() const
virtual void Add(TObject *obj)=0
virtual void * MethodInfo_InterfaceMethod(MethodInfo_t *minfo) const
Definition: TCling.cxx:7566
void SetGetline(const char *(*getlineFunc)(const char *prompt), void(*histaddFunc)(const char *line))
Set a getline function to call when input is needed.
Definition: TCling.cxx:2872
const clang::ValueDecl * GetDataMember(const char *name) const
static TClass * GetClass(const char *name, Bool_t load=kTRUE, Bool_t silent=kFALSE)
Static method returning pointer to TClass of the specified class name.
Definition: TClass.cxx:2881
char fPrompt[64]
Definition: TCling.h:101
virtual void ClassInfo_Delete(ClassInfo_t *info) const
Definition: TCling.cxx:6768
void Delete(void *arena, const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt) const
void RegisterModule(const char *modulename, const char **headers, const char **includePaths, const char *payloadCode, const char *fwdDeclsCode, void(*triggerFunc)(), const FwdDeclArgsToKeepCollection_t &fwdDeclsArgToSkip, const char **classesHeaders)
Inject the module named "modulename" into cling; load all headers.
Definition: TCling.cxx:1486
virtual bool Update(DataMemberInfo_t *info)
Update the TFunction to reflect the new info.
Definition: TGlobal.cxx:160
Int_t ReloadAllSharedLibraryMaps()
Reload the library map entries coming from all the loaded shared libraries, after first unloading the...
Definition: TCling.cxx:4817
virtual TObject * FindObject(const char *name) const
Specialize FindObject to do search for the a data member just by name or create it if its not already...
static TClass * LoadClass(const char *requestedname, Bool_t silent)
Helper function used by TClass::GetClass().
Definition: TClass.cxx:5370
void UpdateListOfMethods(TClass *cl) const
Update the list of pointers to method for TClass cl This is now a nop.
Definition: TCling.cxx:3483
TVirtualCollectionProxy * GetCollectionProxy() const
Return the proxy describing the collection (if any).
Definition: TClass.cxx:2810
void * New(const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt) const
#define name(a, b)
Definition: linkTestLib0.cpp:5
virtual const char * TypedefInfo_Name(TypedefInfo_t *tinfo) const
Definition: TCling.cxx:8012
void RecursiveRemove(TObject *obj)
Delete object from cling symbol table so it can not be used anymore.
Definition: TCling.cxx:2907
TDataMember * GetDataMember(const char *datamember) const
Return pointer to datamember object with name "datamember".
Definition: TClass.cxx:3221
virtual int ClassInfo_Size(ClassInfo_t *info) const
Definition: TCling.cxx:6959
void UnRegisterTClassUpdate(const TClass *oldcl)
If the dictionary is loaded, we can remove the class from the list (otherwise the class might be load...
Definition: TCling.cxx:1832
virtual Double_t CallFunc_ExecDouble(CallFunc_t *func, void *address) const
Definition: TCling.cxx:6518
TString fIncludePath
Definition: TCling.h:106
Mother of all ROOT objects.
Definition: TObject.h:58
virtual bool ClassInfo_HasMethod(ClassInfo_t *info, const char *name) const
Definition: TCling.cxx:6838
void TCling__LibraryUnloadedRTTI(const void *dyLibHandle, const char *canonicalName)
Definition: TCling.cxx:559
virtual Long_t MethodArgInfo_Property(MethodArgInfo_t *marginfo) const
Definition: TCling.cxx:7794
void RegisterTemporary(const TInterpreterValue &value)
Definition: TCling.cxx:6302
virtual void Inspect(TClass *cl, const char *parent, const char *name, const void *addr)
virtual Long_t Getgvp() const
Interface to the CINT global object pointer which was controlling the behavior of the wrapper around ...
Definition: TCling.cxx:6112
#define R__EXTERN
Definition: DllImport.h:27
TClassRef is used to implement a permanent reference to a TClass object.
Definition: TClassRef.h:33
void HandleNewDecl(const void *DV, bool isDeserialized, std::set< TClass * > &modifiedClasses)
Definition: TCling.cxx:450
typedef void((*Func_t)())
Version_t fClassVersion
Definition: TClass.h:201
void Unload()
Mark 'all func' as being unloaded.
const char * GetDeclFileName() const
Definition: TClass.h:386
virtual bool ClassInfo_IsLoaded(ClassInfo_t *info) const
Definition: TCling.cxx:6879
static TEnum * GetEnum(const std::type_info &ti, ESearchAction sa=kALoadAndInterpLookup)
Definition: TEnum.cxx:108
virtual DeclId_t GetDataMemberWithValue(const void *ptrvalue) const
NOT IMPLEMENTED.
Definition: TCling.cxx:3875
void SetAutoloadingEnabled(bool val=true)
llvm::StringRef GetComment(const clang::Decl &decl, clang::SourceLocation *loc=0)
Returns the comment (// striped away), annotating declaration in a meaningful for ROOT IO way...
Bridge between cling::Value and ROOT.
Definition: TClingValue.h:38
virtual const char * MethodInfo_Name(MethodInfo_t *minfo) const
Definition: TCling.cxx:7648
const char * GetUnqualifiedName(const char *name)
Return the start of the unqualified name include in 'original'.
Definition: TClassEdit.cxx:850
const char * GetFullTypeName() const
Get full type description of method argument, e.g.: "class TDirectory*".
Definition: TMethodArg.cxx:75
void Unload()
Mark 'all func' as being unloaded.
A collection of TEnum objects designed for fast access given a DeclId_t and for keep track of TEnum t...
Definition: TListOfEnums.h:36
TDictionary::DeclId_t DeclId_t
ClassInfo_t * fClassInfo
Definition: TClass.h:202
const char * Data()
Definition: TCling.cxx:1012
virtual void Add(TObject *obj)
Definition: TList.h:81
const Ssiz_t kNPOS
Definition: Rtypes.h:115
TClingMethodInfo GetMethodWithArgs(const char *fname, const char *arglist, long *poffset, ROOT::EFunctionMatchMode mode=ROOT::kConversionMatch, EInheritanceMode imode=kWithInheritance) const
virtual bool ClassInfo_IsValid(ClassInfo_t *info) const
Definition: TCling.cxx:6887
long Property() const
void ReplaceAll(std::string &str, const std::string &from, const std::string &to, bool recurse=false)
std::string GetROOTIncludeDir(bool rootbuild)
virtual Long_t ClassInfo_Tagnum(ClassInfo_t *info) const
Definition: TCling.cxx:6967
R__EXTERN const char * gRootDir
Definition: TSystem.h:233
Bool_t fHeaderParsingOnDemand
Definition: TCling.h:147
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition: TString.h:567
virtual Long_t MethodInfo_ExtraProperty(MethodInfo_t *minfo) const
Definition: TCling.cxx:7614
void MakeZombie()
Definition: TObject.h:68
Each ROOT class (see TClass) has a linked list of methods.
Definition: TMethod.h:40
std::vector< std::pair< TClass *, DictFuncPtr_t > > fClassesToUpdate
Definition: TCling.h:136
virtual void CallFunc_IgnoreExtraArgs(CallFunc_t *func, bool ignore) const
Definition: TCling.cxx:6549
virtual const char * GetSTLIncludePath() const
Return the directory containing CINT's stl cintdlls.
Definition: TCling.cxx:6025
static void * fgSetOfSpecials
Definition: TCling.h:95
TF1 * f1
Definition: legend1.C:11
virtual const char * MethodInfo_TypeName(MethodInfo_t *minfo) const
Definition: TCling.cxx:7656
static void SetFactory(TVirtualStreamerInfo *factory)
static function: Set the StreamerInfo factory
long ExecInt(void *address)
#define NULL
Definition: Rtypes.h:82
Int_t SetClassSharedLibs(const char *cls, const char *libs)
Register the autoloading information for a class.
Definition: TCling.cxx:4958
Bool_t IsLoaded(const char *filename) const
Return true if the file has already been loaded by cint.
Definition: TCling.cxx:2494
bool IsValid() const
Return true if the current iterator position is valid.
virtual void ClassInfo_Destruct(ClassInfo_t *info, void *arena) const
Definition: TCling.cxx:6791
virtual const char * ClassInfo_FullName(ClassInfo_t *info) const
Definition: TCling.cxx:6983
virtual void UpdateEnumConstants(TEnum *enumObj, TClass *cl) const
Definition: TCling.cxx:375
virtual void * OpenDirectory(const char *name)
Open a directory. Returns 0 if directory does not exist.
Definition: TSystem.cxx:830
R__EXTERN Int_t gDebug
Definition: Rtypes.h:128
ROOT::ESTLType GetCollectionType() const
Return the 'type' of the STL the TClass is representing.
Definition: TClass.cxx:2799
Bool_t SetSuspendAutoParsing(Bool_t value)
Suspend the Autoparsing of headers.
Definition: TCling.cxx:6223
virtual const char * BaseClassInfo_TmpltName(BaseClassInfo_t *bcinfo) const
Definition: TCling.cxx:7130
virtual const char * MethodArgInfo_Name(MethodArgInfo_t *marginfo) const
Definition: TCling.cxx:7810
Int_t fMore
Definition: TCling.h:99
virtual const char * ClassInfo_TmpltName(ClassInfo_t *info) const
Definition: TCling.cxx:7009
int RefType() const
static const std::string ioname("ioname")
static bool R__InitStreamerInfoFactory()
Helper to initialize TVirtualStreamerInfo's factor early.
Definition: TCling.cxx:1255
void Add(TObject *obj)
Definition: TObjArray.h:75
Bool_t IsErrorMessagesEnabled() const
If error messages are disabled, the interpreter should suppress its failures and warning messages fro...
Definition: TCling.cxx:5966
void IgnoreExtraArgs(bool ignore)
long Property() const
Bool_t fIsAutoParsingSuspended
Definition: TCling.h:148
double result[121]
static void UpdateClassInfoWork(const char *name)
Definition: TCling.cxx:5564
void * DynamicCast(const TClass *base, void *obj, Bool_t up=kTRUE)
Cast obj of this class type up to baseclass cl if up is true.
Definition: TClass.cxx:4620
void ResetBit(UInt_t f)
Definition: TObject.h:172
A collection of TFunction objects designed for fast access given a DeclId_t and for keep track of TFu...
bool TClingLookupHelper__AutoParse(const char *cname)
Allow calling autoparsing from TMetaUtils.
Definition: TCling.cxx:892
std::hash< std::string > fStringHashFunction
Definition: TCling.h:114
virtual void TypedefInfo_Init(TypedefInfo_t *tinfo, const char *name) const
Definition: TCling.cxx:7962
const char * GetSharedLibs()
Return the list of shared libraries loaded into the process.
Definition: TCling.cxx:5884
TObject * At(Int_t idx) const
Definition: TObjArray.h:167
bool IsBase(const char *name) const
static const char * FindLibraryName(void(*func)())
Wrapper around dladdr (and friends)
Definition: TCling.cxx:1220
virtual EReturnType MethodInfo_MethodCallReturnType(MethodInfo_t *minfo) const
Definition: TCling.cxx:7694
R__EXTERN TInterpreter * gCling
Definition: TInterpreter.h:504
R__DLLEXPORT TInterpreter * CreateInterpreter(void *interpLibHandle)
Definition: TCling.cxx:575
virtual void * FindSym(const char *entry) const
Interface to cling function.
Definition: TCling.cxx:6072
virtual void Compress()
Remove empty slots from array.
Definition: TObjArray.cxx:308
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
Definition: TString.h:582
#define I(x, y, z)
bool IsValidMethod(const char *method, const char *proto, Bool_t objectIsConst, long *offset, ROOT::EFunctionMatchMode mode=ROOT::kConversionMatch) const
Long_t ProcessLineAsynch(const char *line, EErrorCode *error=0)
Let cling process a command line asynch.
Definition: TCling.cxx:2794
static void output(int code)
Definition: gifencode.c:226
virtual void DataMemberInfo_Delete(DataMemberInfo_t *dminfo) const
Definition: TCling.cxx:7151
const Bool_t kTRUE
Definition: Rtypes.h:91
void TCling__TransactionRollback(const cling::Transaction &T)
Definition: TCling.cxx:549
virtual const char * GetTitle() const
Returns title of object.
Definition: TObject.cxx:459
TObject * obj
TList * GetListOfMethods(Bool_t load=kTRUE)
Return list containing the TMethods of a class.
Definition: TClass.cxx:3588
std::string NormalizedName(const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt) const
Return the normalized name of the type (i.e.
float value
Definition: math.cpp:443
void Unload()
Mark 'all func' as being unloaded.
virtual char * ConcatFileName(const char *dir, const char *name)
Concatenate a directory and a file name. User must delete returned string.
Definition: TSystem.cxx:1044
void LoadMacro(const char *filename, EErrorCode *error=0)
Load a macro file in cling's memory.
Definition: TCling.cxx:2786
virtual ClassInfo_t * BaseClassInfo_ClassInfo(BaseClassInfo_t *) const
Definition: TCling.cxx:7096
static DictFuncPtr_t GetDictNorm(const char *cname)
Given the normalized class name returns the Dictionary() function of a class (uses hash of name)...
const char * TypeName(const char *typeDesc)
Return the absolute type of typeDesc.
Definition: TCling.cxx:4386
virtual EReturnType MethodCallReturnType(TFunction *func) const
Definition: TCling.cxx:7683
static char * skip(char **buf, const char *delimiters)
Definition: civetweb.c:1014
void LibraryUnloaded(const void *dyLibHandle, const char *canonicalName)
Definition: TCling.cxx:5876
const Int_t n
Definition: legend1.C:16
bool IsValid() const
void RewindDictionary()
Rewind Cling dictionary to the point where it was before executing the current macro.
Definition: TCling.cxx:2986
virtual MethodArgInfo_t * MethodArgInfo_FactoryCopy(MethodArgInfo_t *marginfo) const
Definition: TCling.cxx:7770
void AddIncludePath(const char *path)
Add the given path to the list of directories in which the interpreter looks for include files...
Definition: TCling.cxx:2042
void CreateListOfMethods(TClass *cl) const
Create list of pointers to methods for TClass cl.
Definition: TCling.cxx:3474
Int_t DeleteGlobal(void *obj)
Delete obj from Cling symbol table so it cannot be accessed anymore.
Definition: TCling.cxx:3000
TRandom3 R
a TMatrixD.
Definition: testIO.cxx:28
virtual TypeInfo_t * TypeInfo_Factory() const
Definition: TCling.cxx:7846
virtual const char * MethodArgInfo_TypeName(MethodArgInfo_t *marginfo) const
Definition: TCling.cxx:7818
TDictionary::DeclId_t GetDeclId() const
virtual void SetErrmsgcallback(void *p) const
Set a callback to receive error messages.
Definition: TCling.cxx:6233
void ResetGlobals()
Reset in Cling the list of global variables to the state saved by the last call to TCling::SaveGlobal...
Definition: TCling.cxx:2957
virtual const char * TypedefInfo_Title(TypedefInfo_t *tinfo) const
Definition: TCling.cxx:8020
Int_t Size() const
Return size of object of this class.
Definition: TClass.cxx:5325
Long_t fMemResident
Definition: TSystem.h:206
virtual void SetAlloclockfunc(void(*)()) const
[Place holder for Mutex Lock] Provide the interpreter with a way to acquire a lock used to protect cr...
Definition: TCling.cxx:6178
bool IsValid() const
void ExecWithArgsAndReturn(void *address, const void *args[]=0, int nargs=0, void *ret=0)
virtual void CallFunc_SetArg(CallFunc_t *func, Long_t param) const
Definition: TCling.cxx:6591
virtual Long_t FuncTempInfo_Property(FuncTempInfo_t *) const
Return the property of the function template.
Definition: TCling.cxx:7414
const char * Value
Definition: TXMLSetup.cxx:73
DeclId_t GetDeclId() const
Definition: TEnum.h:72
virtual DataMemberInfo_t * DataMemberInfo_FactoryCopy(DataMemberInfo_t *dminfo) const
Definition: TCling.cxx:7177
void ExecWithReturn(void *address, void *ret=0)
virtual int UnloadFile(const char *path) const
Definition: TCling.cxx:6277
virtual int DataMemberInfo_Next(DataMemberInfo_t *dminfo) const
Definition: TCling.cxx:7201
std::map< size_t, std::vector< const char * > > fClassesHeadersMap
Definition: TCling.h:109
Long_t ProcessLineSynch(const char *line, EErrorCode *error=0)
Let cling process a command line synchronously, i.e we are waiting it will be finished.
Definition: TCling.cxx:2803
virtual int ClassInfo_GetMethodNArg(ClassInfo_t *info, const char *method, const char *proto, Bool_t objectIsConst=false, ROOT::EFunctionMatchMode mode=ROOT::kConversionMatch) const
Definition: TCling.cxx:6822
TList * GetListOfFunctionTemplates(Bool_t load=kTRUE)
Return list containing the TEnums of a class.
Definition: TClass.cxx:3574
virtual const char * GetClassSharedLibs(const char *cls)=0
long long ExecInt64(void *address)
virtual void FuncTempInfo_Name(FuncTempInfo_t *, TString &name) const
Return the name of this function template.
Definition: TCling.cxx:7473
virtual void TypedefInfo_Delete(TypedefInfo_t *tinfo) const
Definition: TCling.cxx:7932
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition: TObject.cxx:904