Logo ROOT   6.07/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 #include "cling/Utils/SourceNormalization.h"
103 #include "cling/Interpreter/Exception.h"
104 
105 #include "llvm/IR/GlobalValue.h"
106 #include "llvm/IR/Module.h"
107 
108 #include "llvm/Support/DynamicLibrary.h"
109 #include "llvm/Support/raw_ostream.h"
110 #include "llvm/Support/Path.h"
111 
112 #include <algorithm>
113 #include <iostream>
114 #include <cassert>
115 #include <map>
116 #include <set>
117 #include <stdexcept>
118 #include <stdint.h>
119 #include <fstream>
120 #include <sstream>
121 #include <string>
122 #include <typeinfo>
123 #include <unordered_map>
124 #include <utility>
125 #include <vector>
126 
127 #ifndef R__WIN32
128 #include <cxxabi.h>
129 #define R__DLLEXPORT
130 #endif
131 #include <limits.h>
132 #include <stdio.h>
133 
134 #ifdef __APPLE__
135 #include <dlfcn.h>
136 #include <mach-o/dyld.h>
137 #endif // __APPLE__
138 
139 #ifdef R__UNIX
140 #include <dlfcn.h>
141 #endif
142 
143 #if defined(__CYGWIN__)
144 #include <sys/cygwin.h>
145 #define HMODULE void *
146 extern "C" {
147  __declspec(dllimport) void * __stdcall GetCurrentProcess();
148  __declspec(dllimport) bool __stdcall EnumProcessModules(void *, void **, unsigned long, unsigned long *);
149  __declspec(dllimport) unsigned long __stdcall GetModuleFileNameExW(void *, void *, wchar_t *, unsigned long);
150 }
151 #endif
152 
153 // Fragment copied from LLVM's raw_ostream.cpp
154 #if defined(_MSC_VER)
155 #ifndef STDIN_FILENO
156 # define STDIN_FILENO 0
157 #endif
158 #ifndef STDOUT_FILENO
159 # define STDOUT_FILENO 1
160 #endif
161 #ifndef STDERR_FILENO
162 # define STDERR_FILENO 2
163 #endif
164 #ifndef R__WIN32
165 //#if defined(HAVE_UNISTD_H)
166 # include <unistd.h>
167 //#endif
168 #else
169 #include "Windows4Root.h"
170 #include <Psapi.h>
171 #undef GetModuleFileName
172 #define RTLD_DEFAULT ((void *)::GetModuleHandle(NULL))
173 #define dlsym(library, function_name) ::GetProcAddress((HMODULE)library, function_name)
174 #define dlopen(library_name, flags) ::LoadLibrary(library_name)
175 #define dlclose(library) ::FreeLibrary((HMODULE)library)
176 #define R__DLLEXPORT __declspec(dllexport)
177 #endif
178 #endif
179 
180 //______________________________________________________________________________
181 // Infrastructure to detect and react to libCling being teared down.
182 //
183 namespace {
184  class TCling_UnloadMarker {
185  public:
186  ~TCling_UnloadMarker() {
189  }
190  }
191  };
192  static TCling_UnloadMarker gTClingUnloadMarker;
193 }
194 
195 
196 
197 //______________________________________________________________________________
198 // These functions are helpers for debugging issues with non-LLVMDEV builds.
199 //
200 clang::DeclContext* TCling__DEBUG__getDeclContext(clang::Decl* D) {
201  return D->getDeclContext();
202 }
203 clang::NamespaceDecl* TCling__DEBUG__DCtoNamespace(clang::DeclContext* DC) {
204  return llvm::dyn_cast<clang::NamespaceDecl>(DC);
205 }
206 clang::RecordDecl* TCling__DEBUG__DCtoRecordDecl(clang::DeclContext* DC) {
207  return llvm::dyn_cast<clang::RecordDecl>(DC);
208 }
209 void TCling__DEBUG__dump(clang::DeclContext* DC) {
210  return DC->dumpDeclContext();
211 }
212 void TCling__DEBUG__dump(clang::Decl* D) {
213  return D->dump();
214 }
215 void TCling__DEBUG__dump(clang::FunctionDecl* FD) {
216  return FD->dump();
217 }
219  return ((clang::Decl*)D)->dump();
220 }
221 void TCling__DEBUG__printName(clang::Decl* D) {
222  if (clang::NamedDecl* ND = llvm::dyn_cast<clang::NamedDecl>(D)) {
223  std::string name;
224  {
225  llvm::raw_string_ostream OS(name);
226  ND->getNameForDiagnostic(OS, D->getASTContext().getPrintingPolicy(),
227  true /*Qualified*/);
228  }
229  printf("%s\n", name.c_str());
230  }
231 }
232 //______________________________________________________________________________
233 // These functions are helpers for testing issues directly rather than
234 // relying on side effects.
235 // This is used for the test for ROOT-7462/ROOT-6070
236 bool TCling__TEST_isInvalidDecl(clang::Decl* D) {
237  return D->isInvalidDecl();
238 }
239 bool TCling__TEST_isInvalidDecl(ClassInfo_t *input) {
240  TClingClassInfo *info( (TClingClassInfo*) input);
241  assert(info && info->IsValid());
242  return info->GetDecl()->isInvalidDecl();
243 }
244 
245 using namespace std;
246 using namespace clang;
247 using namespace ROOT;
248 
249 namespace {
250  static const std::string gInterpreterClassDef = R"ICF(
251 #undef ClassDef
252 #define ClassDef(name, id) \
253 _ClassDefInterp_(name,id,virtual,) \
254 static int DeclFileLine() { return __LINE__; }
255 #undef ClassDefNV
256 #define ClassDefNV(name, id) \
257 _ClassDefInterp_(name,id,,) \
258 static int DeclFileLine() { return __LINE__; }
259 #undef ClassDefOverride
260 #define ClassDefOverride(name, id) \
261 _ClassDefInterp_(name,id,,override) \
262 static int DeclFileLine() { return __LINE__; }
263 )ICF";
264 
265  static const std::string gNonInterpreterClassDef = R"ICF(
266 #define __ROOTCLING__ 1
267 #undef ClassDef
268 #define ClassDef(name,id) \
269 _ClassDef_(name,id,virtual,) \
270 static int DeclFileLine() { return __LINE__; }
271 #undef ClassDefNV
272 #define ClassDefNV(name, id)\
273 _ClassDef_(name,id,,)\
274 static int DeclFileLine() { return __LINE__; }
275 #undef ClassDefOverride
276 #define ClassDefOverride(name, id)\
277 _ClassDef_(name,id,,override)\
278 static int DeclFileLine() { return __LINE__; }
279 )ICF";
280 
281 // The macros below use ::Error, so let's ensure it is included
282  static const std::string gClassDefInterpMacro = R"ICF(
283 #ifndef ROOT_TError
284 #include "TError.h"
285 #endif
286 
287 #define _ClassDefInterp_(name,id,virtual_keyword, overrd) \
288 private: \
289 public: \
290  static TClass *Class() { static TClass* sIsA = 0; if (!sIsA) sIsA = TClass::GetClass(#name); return sIsA; } \
291  static const char *Class_Name() { return #name; } \
292  static Version_t Class_Version() { return id; } \
293  static TClass *Dictionary() { return 0; } \
294  virtual_keyword TClass *IsA() const overrd { return name::Class(); } \
295  virtual_keyword void ShowMembers(TMemberInspector&insp) const overrd { ::ROOT::Class_ShowMembers(name::Class(), this, insp); } \
296  virtual_keyword void Streamer(TBuffer&) overrd { ::Error("Streamer", "Cannot stream interpreted class."); } \
297  void StreamerNVirtual(TBuffer&ClassDef_StreamerNVirtual_b) { name::Streamer(ClassDef_StreamerNVirtual_b); } \
298  static const char *DeclFileName() { return __FILE__; } \
299  static int ImplFileLine() { return 0; } \
300  static const char *ImplFileName() { return __FILE__; }
301 )ICF";
302 }
304 
305 // The functions are used to bridge cling/clang/llvm compiled with no-rtti and
306 // ROOT (which uses rtti)
307 
308 //______________________________________________________________________________
309 
310 // Class extracting recursively every Enum type defined for a class.
311 class EnumVisitor : public RecursiveASTVisitor<EnumVisitor> {
312 private:
313  llvm::SmallVector<EnumDecl*,128> &fClassEnums;
314 public:
315  EnumVisitor(llvm::SmallVector<EnumDecl*,128> &enums) : fClassEnums(enums)
316  {}
317 
318  bool TraverseStmt(Stmt*) {
319  // Don't descend into function bodies.
320  return true;
321  }
322 
323  bool shouldVisitTemplateInstantiations() const { return true; }
324 
325  bool TraverseClassTemplateDecl(ClassTemplateDecl*) {
326  // Don't descend into templates (but only instances thereof).
327  return true; // returning false will abort the in-depth traversal.
328  }
329 
330  bool TraverseClassTemplatePartialSpecializationDecl(ClassTemplatePartialSpecializationDecl*) {
331  // Don't descend into templates partial specialization (but only instances thereof).
332  return true; // returning false will abort the in-depth traversal.
333  }
334 
335  bool VisitEnumDecl(EnumDecl *TEnumD) {
336  if (!TEnumD->getDeclContext()->isDependentContext())
337  fClassEnums.push_back(TEnumD);
338  return true; // returning false will abort the in-depth traversal.
339  }
340 };
341 
342 ////////////////////////////////////////////////////////////////////////////////
343 /// Print a StackTrace!
344 
345 extern "C"
347  gSystem->StackTrace();
348 }
349 
350 ////////////////////////////////////////////////////////////////////////////////
351 /// Update TClingClassInfo for a class (e.g. upon seeing a definition).
352 
353 static void TCling__UpdateClassInfo(const NamedDecl* TD)
354 {
355  static Bool_t entered = kFALSE;
356  static vector<const NamedDecl*> updateList;
357  Bool_t topLevel;
358 
359  if (entered) topLevel = kFALSE;
360  else {
361  entered = kTRUE;
362  topLevel = kTRUE;
363  }
364  if (topLevel) {
365  ((TCling*)gInterpreter)->UpdateClassInfoWithDecl(TD);
366  } else {
367  // If we are called indirectly from within another call to
368  // TCling::UpdateClassInfo, we delay the update until the dictionary loading
369  // is finished (i.e. when we return to the top level TCling::UpdateClassInfo).
370  // This allows for the dictionary to be fully populated when we actually
371  // update the TClass object. The updating of the TClass sometimes
372  // (STL containers and when there is an emulated class) forces the building
373  // of the TClass object's real data (which needs the dictionary info).
374  updateList.push_back(TD);
375  }
376  if (topLevel) {
377  while (!updateList.empty()) {
378  ((TCling*)gInterpreter)->UpdateClassInfoWithDecl(updateList.back());
379  updateList.pop_back();
380  }
381  entered = kFALSE;
382  }
383 }
384 
385 void TCling::UpdateEnumConstants(TEnum* enumObj, TClass* cl) const {
386  const clang::Decl* D = static_cast<const clang::Decl*>(enumObj->GetDeclId());
387  if(const clang::EnumDecl* ED = dyn_cast<clang::EnumDecl>(D)) {
388  // Add the constants to the enum type.
389  for (EnumDecl::enumerator_iterator EDI = ED->enumerator_begin(),
390  EDE = ED->enumerator_end(); EDI != EDE; ++EDI) {
391  // Get name of the enum type.
392  std::string constbuf;
393  if (const NamedDecl* END = llvm::dyn_cast<NamedDecl>(*EDI)) {
394  PrintingPolicy Policy((*EDI)->getASTContext().getPrintingPolicy());
395  llvm::raw_string_ostream stream(constbuf);
396  // Don't trigger fopen of the source file to count lines:
397  Policy.AnonymousTagLocations = false;
398  (END)->getNameForDiagnostic(stream, Policy, /*Qualified=*/false);
399  }
400  const char* constantName = constbuf.c_str();
401 
402  // Get value of the constant.
403  Long64_t value;
404  const llvm::APSInt valAPSInt = (*EDI)->getInitVal();
405  if (valAPSInt.isSigned()) {
406  value = valAPSInt.getSExtValue();
407  } else {
408  value = valAPSInt.getZExtValue();
409  }
410 
411  // Create the TEnumConstant or update it if existing
412  TEnumConstant* enumConstant = nullptr;
413  TClingClassInfo* tcCInfo = (TClingClassInfo*)(cl ? cl->GetClassInfo() : 0);
414  TClingDataMemberInfo* tcDmInfo = new TClingDataMemberInfo(fInterpreter, *EDI, tcCInfo);
415  DataMemberInfo_t* dmInfo = (DataMemberInfo_t*) tcDmInfo;
416  if (TObject* encAsTObj = enumObj->GetConstants()->FindObject(constantName)){
417  ((TEnumConstant*)encAsTObj)->Update(dmInfo);
418  } else {
419  enumConstant = new TEnumConstant(dmInfo, constantName, value, enumObj);
420  }
421 
422  // Add the global constants to the list of Globals.
423  if (!cl) {
424  TCollection* globals = gROOT->GetListOfGlobals(false);
425  if (!globals->FindObject(constantName)) {
426  globals->Add(enumConstant);
427  }
428  }
429  }
430  }
431 }
432 
433 TEnum* TCling::CreateEnum(void *VD, TClass *cl) const
434 {
435  // Handle new enum declaration for either global and nested enums.
436 
437  // Create the enum type.
438  TEnum* enumType = 0;
439  const clang::Decl* D = static_cast<const clang::Decl*>(VD);
440  std::string buf;
441  if (const EnumDecl* ED = llvm::dyn_cast<EnumDecl>(D)) {
442  // Get name of the enum type.
443  PrintingPolicy Policy(ED->getASTContext().getPrintingPolicy());
444  llvm::raw_string_ostream stream(buf);
445  // Don't trigger fopen of the source file to count lines:
446  Policy.AnonymousTagLocations = false;
447  ED->getNameForDiagnostic(stream, Policy, /*Qualified=*/false);
448  // If the enum is unnamed we do not add it to the list of enums i.e unusable.
449  }
450  if (buf.empty()) {
451  return 0;
452  }
453  const char* name = buf.c_str();
454  enumType = new TEnum(name, VD, cl);
455  UpdateEnumConstants(enumType, cl);
456 
457  return enumType;
458 }
459 
460 void TCling::HandleNewDecl(const void* DV, bool isDeserialized, std::set<TClass*> &modifiedTClasses) {
461  // Handle new declaration.
462  // Record the modified class, struct and namespaces in 'modifiedTClasses'.
463 
464  const clang::Decl* D = static_cast<const clang::Decl*>(DV);
465 
466  if (!D->isCanonicalDecl() && !isa<clang::NamespaceDecl>(D)
467  && !dyn_cast<clang::RecordDecl>(D)) return;
468 
469  if (isa<clang::FunctionDecl>(D->getDeclContext())
470  || isa<clang::TagDecl>(D->getDeclContext()))
471  return;
472 
473  // Don't list templates.
474  if (const clang::CXXRecordDecl* RD = dyn_cast<clang::CXXRecordDecl>(D)) {
475  if (RD->getDescribedClassTemplate())
476  return;
477  } else if (const clang::FunctionDecl* FD = dyn_cast<clang::FunctionDecl>(D)) {
478  if (FD->getDescribedFunctionTemplate())
479  return;
480  }
481 
482  if (const RecordDecl *TD = dyn_cast<RecordDecl>(D)) {
483  if (TD->isCanonicalDecl() || TD->isThisDeclarationADefinition())
485  }
486  else if (const NamedDecl *ND = dyn_cast<NamedDecl>(D)) {
487 
488  if (const TagDecl *TD = dyn_cast<TagDecl>(D)) {
489  // Mostly just for EnumDecl (the other TagDecl are handled
490  // by the 'RecordDecl' if statement.
492  } else if (const NamespaceDecl* NSD = dyn_cast<NamespaceDecl>(D)) {
494  }
495 
496  // While classes are read completely (except for function template instances,
497  // enum, data (and functions) can be added to namespaces at any time.
498  // [this section can be removed when both the list of data member and the list
499  // of enums has been update to be active list]
500  if (const NamespaceDecl* NCtx = dyn_cast<NamespaceDecl>(ND->getDeclContext())) {
501  if (NCtx->getIdentifier()) {
502  // No need to load the TClass: if there is something to update then
503  // it must already exist.
504  std::string NCtxName;
505  PrintingPolicy Policy(NCtx->getASTContext().getPrintingPolicy());
506  llvm::raw_string_ostream stream(NCtxName);
507  // Don't trigger fopen of the source file to count lines:
508  Policy.AnonymousTagLocations = false;
509  NCtx->getNameForDiagnostic(stream, Policy, /*Qualified=*/true);
510 
511  TClass* cl = (TClass*)gROOT->GetListOfClasses()->FindObject(NCtxName.c_str());
512  if (cl) {
513  modifiedTClasses.insert(cl);
514  }
515  }
516  return;
517  }
518 
519  // We care about declarations on the global scope.
520  if (!isa<TranslationUnitDecl>(ND->getDeclContext()))
521  return;
522 
523  // Enums are lazyly created, thus we don not need to handle them here.
524  if (isa<EnumDecl>(ND))
525  return;
526 
527  // ROOT says that global is enum(lazylycreated)/var/field declared on the global
528  // scope.
529  if (!(isa<VarDecl>(ND)))
530  return;
531 
532  // Skip if already in the list.
533  if (gROOT->GetListOfGlobals()->FindObject(ND->getNameAsString().c_str()))
534  return;
535 
536  // Put the global constants and global enums in the corresponding lists.
537  gROOT->GetListOfGlobals()->Add(new TGlobal((DataMemberInfo_t *)
538  new TClingDataMemberInfo(fInterpreter,
539  cast<ValueDecl>(ND), 0)));
540  }
541 }
542 
543 extern "C"
545 {
546  // We are sure in this context of the type of the interpreter
547  normCtxt = &( (TCling*) gInterpreter)->GetNormalizedContext();
548 }
549 
550 extern "C"
551 void TCling__UpdateListsOnCommitted(const cling::Transaction &T, cling::Interpreter*) {
552 
553  ((TCling*)gCling)->UpdateListsOnCommitted(T);
554 }
555 
556 extern "C"
557 void TCling__UpdateListsOnUnloaded(const cling::Transaction &T) {
558 
559  ((TCling*)gCling)->UpdateListsOnUnloaded(T);
560 }
561 void TCling__TransactionRollback(const cling::Transaction &T) {
562 
563  ((TCling*)gCling)->TransactionRollback(T);
564 }
565 extern "C" void TCling__LibraryLoadedRTTI(const void* dyLibHandle,
566  const char* canonicalName) {
567 
568  ((TCling*)gCling)->LibraryLoaded(dyLibHandle, canonicalName);
569 }
570 
571 extern "C" void TCling__LibraryUnloadedRTTI(const void* dyLibHandle,
572  const char* canonicalName) {
573 
574  ((TCling*)gCling)->LibraryUnloaded(dyLibHandle, canonicalName);
575 }
576 
577 
578 extern "C"
579 TObject* TCling__GetObjectAddress(const char *Name, void *&LookupCtx) {
580  return ((TCling*)gCling)->GetObjectAddress(Name, LookupCtx);
581 }
582 
583 extern "C" const Decl* TCling__GetObjectDecl(TObject *obj) {
584  return ((TClingClassInfo*)obj->IsA()->GetClassInfo())->GetDecl();
585 }
586 
587 extern "C" R__DLLEXPORT TInterpreter *CreateInterpreter(void* interpLibHandle)
588 {
589  cling::DynamicLibraryManager::ExposeHiddenSharedLibrarySymbols(interpLibHandle);
590  return new TCling("C++", "cling C++ Interpreter");
591 }
592 
594 {
595  delete interp;
596 }
597 
598 // Load library containing specified class. Returns 0 in case of error
599 // and 1 in case if success.
600 extern "C" int TCling__AutoLoadCallback(const char* className)
601 {
602  return ((TCling*)gCling)->AutoLoad(className);
603 }
604 
605 extern "C" int TCling__AutoParseCallback(const char* className)
606 {
607  return ((TCling*)gCling)->AutoParse(className);
608 }
609 
610 extern "C" const char* TCling__GetClassSharedLibs(const char* className)
611 {
612  return ((TCling*)gCling)->GetClassSharedLibs(className);
613 }
614 
615 // // Returns 0 for failure 1 for success
616 // extern "C" int TCling__IsAutoLoadNamespaceCandidate(const char* name)
617 // {
618 // return ((TCling*)gCling)->IsAutoLoadNamespaceCandidate(name);
619 // }
620 
621 // Returns 0 for failure 1 for success
622 extern "C" int TCling__IsAutoLoadNamespaceCandidate(const clang::NamespaceDecl* nsDecl)
623 {
624  return ((TCling*)gCling)->IsAutoLoadNamespaceCandidate(nsDecl);
625 }
626 
627 extern "C" int TCling__CompileMacro(const char *fileName, const char *options)
628 {
629  string file(fileName);
630  string opt(options);
631  return gSystem->CompileMacro(file.c_str(), opt.c_str());
632 }
633 
634 extern "C" void TCling__SplitAclicMode(const char* fileName, string &mode,
635  string &args, string &io, string &fname)
636 {
637  string file(fileName);
638  TString f, amode, arguments, aclicio;
639  f = gSystem->SplitAclicMode(file.c_str(), amode, arguments, aclicio);
640  mode = amode.Data(); args = arguments.Data();
641  io = aclicio.Data(); fname = f.Data();
642 }
643 
644 //______________________________________________________________________________
645 //
646 //
647 //
648 
649 #ifdef R__WIN32
650 extern "C" {
651  char *__unDName(char *demangled, const char *mangled, int out_len,
652  void * (* pAlloc )(size_t), void (* pFree )(void *),
653  unsigned short int flags);
654 }
655 #endif
656 
657 ////////////////////////////////////////////////////////////////////////////////
658 /// Find a template decl within N nested namespaces, 0<=N<inf
659 /// Assumes 1 and only 1 template present and 1 and only 1 entity contained
660 /// by the namespace. Example: ns1::ns2::..::nsN::myTemplate
661 /// Returns nullptr in case of error
662 
663 static clang::ClassTemplateDecl* FindTemplateInNamespace(clang::Decl* decl)
664 {
665  using namespace clang;
666  if (NamespaceDecl* nsd = llvm::dyn_cast<NamespaceDecl>(decl)){
667  return FindTemplateInNamespace(*nsd->decls_begin());
668  }
669 
670  if (ClassTemplateDecl* ctd = llvm::dyn_cast<ClassTemplateDecl>(decl)){
671  return ctd;
672  }
673 
674  return nullptr; // something went wrong.
675 }
676 
677 ////////////////////////////////////////////////////////////////////////////////
678 /// Autoload a library provided the mangled name of a missing symbol.
679 
680 void* llvmLazyFunctionCreator(const std::string& mangled_name)
681 {
682  return ((TCling*)gCling)->LazyFunctionCreatorAutoload(mangled_name);
683 }
684 
685 //______________________________________________________________________________
686 //
687 //
688 //
689 
690 int TCling_GenerateDictionary(const std::vector<std::string> &classes,
691  const std::vector<std::string> &headers,
692  const std::vector<std::string> &fwdDecls,
693  const std::vector<std::string> &unknown)
694 {
695  //This function automatically creates the "LinkDef.h" file for templated
696  //classes then executes CompileMacro on it.
697  //The name of the file depends on the class name, and it's not generated again
698  //if the file exist.
699  if (classes.empty()) {
700  return 0;
701  }
702  // Use the name of the first class as the main name.
703  const std::string& className = classes[0];
704  //(0) prepare file name
705  TString fileName = "AutoDict_";
706  std::string::const_iterator sIt;
707  for (sIt = className.begin(); sIt != className.end(); sIt++) {
708  if (*sIt == '<' || *sIt == '>' ||
709  *sIt == ' ' || *sIt == '*' ||
710  *sIt == ',' || *sIt == '&' ||
711  *sIt == ':') {
712  fileName += '_';
713  }
714  else {
715  fileName += *sIt;
716  }
717  }
718  if (classes.size() > 1) {
719  Int_t chk = 0;
720  std::vector<std::string>::const_iterator it = classes.begin();
721  while ((++it) != classes.end()) {
722  for (UInt_t cursor = 0; cursor != it->length(); ++cursor) {
723  chk = chk * 3 + it->at(cursor);
724  }
725  }
726  fileName += TString::Format("_%u", chk);
727  }
728  fileName += ".cxx";
729  if (gSystem->AccessPathName(fileName) != 0) {
730  //file does not exist
731  //(1) prepare file data
732  // If STL, also request iterators' operators.
733  // vector is special: we need to check whether
734  // vector::iterator is a typedef to pointer or a
735  // class.
736  static const std::set<std::string> sSTLTypes {
737  "vector","list","forward_list","deque","map","unordered_map","multimap",
738  "unordered_multimap","set","unordered_set","multiset","unordered_multiset",
739  "queue","priority_queue","stack","iterator"};
740  std::vector<std::string>::const_iterator it;
741  std::string fileContent("");
742  for (it = headers.begin(); it != headers.end(); ++it) {
743  fileContent += "#include \"" + *it + "\"\n";
744  }
745  for (it = unknown.begin(); it != unknown.end(); ++it) {
746  TClass* cl = TClass::GetClass(it->c_str());
747  if (cl && cl->GetDeclFileName()) {
748  TString header(gSystem->BaseName(cl->GetDeclFileName()));
749  TString dir(gSystem->DirName(cl->GetDeclFileName()));
750  TString dirbase(gSystem->BaseName(dir));
751  while (dirbase.Length() && dirbase != "."
752  && dirbase != "include" && dirbase != "inc"
753  && dirbase != "prec_stl") {
754  gSystem->PrependPathName(dirbase, header);
755  dir = gSystem->DirName(dir);
756  }
757  fileContent += TString("#include \"") + header + "\"\n";
758  }
759  }
760  for (it = fwdDecls.begin(); it != fwdDecls.end(); ++it) {
761  fileContent += "class " + *it + ";\n";
762  }
763  fileContent += "#ifdef __CINT__ \n";
764  fileContent += "#pragma link C++ nestedclasses;\n";
765  fileContent += "#pragma link C++ nestedtypedefs;\n";
766  for (it = classes.begin(); it != classes.end(); ++it) {
767  std::string n(*it);
768  size_t posTemplate = n.find('<');
769  std::set<std::string>::const_iterator iSTLType = sSTLTypes.end();
770  if (posTemplate != std::string::npos) {
771  n.erase(posTemplate, std::string::npos);
772  if (n.compare(0, 5, "std::") == 0) {
773  n.erase(0, 5);
774  }
775  iSTLType = sSTLTypes.find(n);
776  }
777  fileContent += "#pragma link C++ class ";
778  fileContent += *it + "+;\n" ;
779  fileContent += "#pragma link C++ class ";
780  if (iSTLType != sSTLTypes.end()) {
781  // STL class; we cannot (and don't need to) store iterators;
782  // their shadow and the compiler's version don't agree. So
783  // don't ask for the '+'
784  fileContent += *it + "::*;\n" ;
785  }
786  else {
787  // Not an STL class; we need to allow the I/O of contained
788  // classes (now that we have a dictionary for them).
789  fileContent += *it + "::*+;\n" ;
790  }
791  std::string oprLink("#pragma link C++ operators ");
792  oprLink += *it;
793  // Don't! Requests e.g. op<(const vector<T>&, const vector<T>&):
794  // fileContent += oprLink + ";\n";
795  if (iSTLType != sSTLTypes.end()) {
796  if (n == "vector") {
797  fileContent += "#ifdef G__VECTOR_HAS_CLASS_ITERATOR\n";
798  }
799  fileContent += oprLink + "::iterator;\n";
800  fileContent += oprLink + "::const_iterator;\n";
801  fileContent += oprLink + "::reverse_iterator;\n";
802  if (n == "vector") {
803  fileContent += "#endif\n";
804  }
805  }
806  }
807  fileContent += "#endif\n";
808  //end(1)
809  //(2) prepare the file
810  FILE* filePointer;
811  filePointer = fopen(fileName, "w");
812  if (filePointer == NULL) {
813  //can't open a file
814  return 1;
815  }
816  //end(2)
817  //write data into the file
818  fprintf(filePointer, "%s", fileContent.c_str());
819  fclose(filePointer);
820  }
821  //(3) checking if we can compile a macro, if not then cleaning
822  Int_t oldErrorIgnoreLevel = gErrorIgnoreLevel;
823  gErrorIgnoreLevel = kWarning; // no "Info: creating library..."
824  Int_t ret = gSystem->CompileMacro(fileName, "k");
825  gErrorIgnoreLevel = oldErrorIgnoreLevel;
826  if (ret == 0) { //can't compile a macro
827  return 2;
828  }
829  //end(3)
830  return 0;
831 }
832 
833 int TCling_GenerateDictionary(const std::string& className,
834  const std::vector<std::string> &headers,
835  const std::vector<std::string> &fwdDecls,
836  const std::vector<std::string> &unknown)
837 {
838  //This function automatically creates the "LinkDef.h" file for templated
839  //classes then executes CompileMacro on it.
840  //The name of the file depends on the class name, and it's not generated again
841  //if the file exist.
842  std::vector<std::string> classes;
843  classes.push_back(className);
844  return TCling_GenerateDictionary(classes, headers, fwdDecls, unknown);
845 }
846 
847 //______________________________________________________________________________
848 //
849 //
850 //
851 
852 // It is a "fantom" method to synchronize user keyboard input
853 // and ROOT prompt line (for WIN32)
854 const char* fantomline = "TRint::EndOfLineAction();";
855 
856 //______________________________________________________________________________
857 //
858 //
859 //
860 
861 void* TCling::fgSetOfSpecials = 0;
862 
863 //______________________________________________________________________________
864 //
865 // llvm error handler through exceptions; see also cling/UserInterface
866 //
867 namespace {
868  // Handle fatal llvm errors by throwing an exception.
869  // Yes, throwing exceptions in error handlers is bad.
870  // Doing nothing is pretty terrible, too.
871  void exceptionErrorHandler(void * /*user_data*/,
872  const std::string& reason,
873  bool /*gen_crash_diag*/) {
874  throw std::runtime_error(std::string(">>> Interpreter compilation error:\n") + reason);
875  }
876 }
877 
878 //______________________________________________________________________________
879 //
880 //
881 //
882 
883 ////////////////////////////////////////////////////////////////////////////////
884 
885 namespace{
886  // An instance of this class causes the diagnostics of clang to be suppressed
887  // during its lifetime
888  class clangDiagSuppr {
889  public:
890  clangDiagSuppr(clang::DiagnosticsEngine& diag): fDiagEngine(diag){
891  fOldDiagValue = fDiagEngine.getIgnoreAllWarnings();
892  fDiagEngine.setIgnoreAllWarnings(true);
893  }
894 
895  ~clangDiagSuppr() {
896  fDiagEngine.setIgnoreAllWarnings(fOldDiagValue);
897  }
898  private:
899  clang::DiagnosticsEngine& fDiagEngine;
900  bool fOldDiagValue;
901  };
902 
903 }
904 
905 ////////////////////////////////////////////////////////////////////////////////
906 /// Allow calling autoparsing from TMetaUtils
907 bool TClingLookupHelper__AutoParse(const char *cname)
908 {
909  return gCling->AutoParse(cname);
910 }
911 
912 ////////////////////////////////////////////////////////////////////////////////
913 /// Try hard to avoid looking up in the Cling database as this could enduce
914 /// an unwanted autoparsing.
915 
916 bool TClingLookupHelper__ExistingTypeCheck(const std::string &tname,
917  std::string &result)
918 {
919  result.clear();
920 
921  unsigned long offset = 0;
922  if (strncmp(tname.c_str(), "const ", 6) == 0) {
923  offset = 6;
924  }
925  unsigned long end = tname.length();
926  while( end && (tname[end-1]=='&' || tname[end-1]=='*' || tname[end-1]==']') ) {
927  if ( tname[end-1]==']' ) {
928  --end;
929  while ( end && tname[end-1]!='[' ) --end;
930  }
931  --end;
932  }
933  std::string innerbuf;
934  const char *inner;
935  if (end != tname.length()) {
936  innerbuf = tname.substr(offset,end-offset);
937  inner = innerbuf.c_str();
938  } else {
939  inner = tname.c_str()+offset;
940  }
941 
942  //if (strchr(tname.c_str(),'[')!=0) fprintf(stderr,"DEBUG: checking on %s vs %s %lu %lu\n",tname.c_str(),inner,offset,end);
943  if (gROOT->GetListOfClasses()->FindObject(inner)
944  || TClassTable::Check(inner,result) ) {
945  // This is a known class.
946  return true;
947  }
948 
949  THashTable *typeTable = dynamic_cast<THashTable*>( gROOT->GetListOfTypes() );
950  TDataType *type = (TDataType *)typeTable->THashTable::FindObject( inner );
951  if (type) {
952  // This is a raw type and an already loaded typedef.
953  const char *newname = type->GetFullTypeName();
954  if (type->GetType() == kLong64_t) {
955  newname = "Long64_t";
956  } else if (type->GetType() == kULong64_t) {
957  newname = "ULong64_t";
958  }
959  if (strcmp(inner,newname) == 0) {
960  return true;
961  }
962  if (offset) result = "const ";
963  result += newname;
964  if ( end != tname.length() ) {
965  result += tname.substr(end,tname.length()-end);
966  }
967  if (result == tname) result.clear();
968  return true;
969  }
970 
971  // Check if the name is an enumerator
972  const auto lastPos = TClassEdit::GetUnqualifiedName(inner);
973  if (lastPos != inner) // Main switch: case 1 - scoped enum, case 2 global enum
974  {
975  // We have a scope
976  // All of this C gymnastic is to avoid allocations on the heap
977  const auto enName = lastPos;
978  const auto scopeNameSize = ((Long64_t)lastPos - (Long64_t)inner) / sizeof(decltype(*lastPos)) - 2;
979  char *scopeName = new char[scopeNameSize + 1];
980  strncpy(scopeName, inner, scopeNameSize);
981  scopeName[scopeNameSize] = '\0';
982  // Check if the scope is in the list of classes
983  if (auto scope = static_cast<TClass *>(gROOT->GetListOfClasses()->FindObject(scopeName))) {
984  auto enumTable = dynamic_cast<const THashList *>(scope->GetListOfEnums(false));
985  if (enumTable && enumTable->THashList::FindObject(enName)) return true;
986  }
987  // It may still be in one of the loaded protoclasses
988  else if (auto scope = static_cast<TProtoClass *>(gClassTable->GetProtoNorm(scopeName))) {
989  auto listOfEnums = scope->GetListOfEnums();
990  if (listOfEnums) { // it could be null: no enumerators in the protoclass
991  auto enumTable = dynamic_cast<const THashList *>(listOfEnums);
992  if (enumTable && enumTable->THashList::FindObject(enName)) return true;
993  }
994  }
995  delete [] scopeName;
996  } else
997  {
998  // We don't have any scope: this could only be a global enum
999  auto enumTable = dynamic_cast<const THashList *>(gROOT->GetListOfEnums());
1000  if (enumTable && enumTable->THashList::FindObject(inner)) return true;
1001  }
1002 
1003  if (gCling->GetClassSharedLibs(inner))
1004  {
1005  // This is a class name.
1006  return true;
1007  }
1008 
1009  return false;
1010 }
1011 
1012 ////////////////////////////////////////////////////////////////////////////////
1013 
1015 {
1016  fContent.reserve(size);
1017 }
1018 
1019 ////////////////////////////////////////////////////////////////////////////////
1020 
1021 inline const char *TCling::TUniqueString::Data()
1022 {
1023  return fContent.c_str();
1024 }
1025 
1026 ////////////////////////////////////////////////////////////////////////////////
1027 /// Append string to the storage if not added already.
1028 
1029 inline bool TCling::TUniqueString::Append(const std::string& str)
1030 {
1031  bool notPresent = fLinesHashSet.emplace(fHashFunc(str)).second;
1032  if (notPresent){
1033  fContent+=str;
1034  }
1035  return notPresent;
1036 }
1037 
1038 ////////////////////////////////////////////////////////////////////////////////
1039 /// Initialize the cling interpreter interface.
1040 
1041 TCling::TCling(const char *name, const char *title)
1042 : TInterpreter(name, title), fGlobalsListSerial(-1), fInterpreter(0),
1043  fMetaProcessor(0), fNormalizedCtxt(0), fPrevLoadedDynLibInfo(0),
1044  fClingCallbacks(0), fAutoLoadCallBack(0),
1045  fTransactionCount(0), fHeaderParsingOnDemand(true), fIsAutoParsingSuspended(kFALSE)
1046 {
1047  // rootcling also uses TCling for generating the dictionary ROOT files.
1048  bool fromRootCling = dlsym(RTLD_DEFAULT, "usedToIdentifyRootClingByDlSym");
1049 
1050  llvm::install_fatal_error_handler(&exceptionErrorHandler);
1051 
1052  fTemporaries = new std::vector<cling::Value>();
1053 
1054  std::vector<std::string> clingArgsStorage;
1055  clingArgsStorage.push_back("cling4root");
1056 
1057  std::string interpInclude;
1058  // rootcling sets its arguments through TROOT::GetExtraInterpreterArgs().
1059  if (!fromRootCling) {
1061 
1062  interpInclude = ROOT::TMetaUtils::GetInterpreterExtraIncludePath(false);
1063  clingArgsStorage.push_back(interpInclude);
1064 
1065  std::string pchFilename = interpInclude.substr(2) + "/allDict.cxx.pch";
1066  if (gSystem->Getenv("ROOT_PCH")) {
1067  pchFilename = gSystem->Getenv("ROOT_PCH");
1068  }
1069  clingArgsStorage.push_back("-include-pch");
1070  clingArgsStorage.push_back(pchFilename);
1071 
1072  // clingArgsStorage.push_back("-Xclang");
1073  // clingArgsStorage.push_back("-fmodules");
1074 
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  // Enable dynamic lookup
1172  if (!fromRootCling) {
1173  fInterpreter->enableDynamicLookup();
1174  }
1175 
1176  // Attach cling callbacks last; they might need TROOT::fInterpreter
1177  // and should thus not be triggered during the equivalent of
1178  // TROOT::fInterpreter = new TCling;
1179  std::unique_ptr<TClingCallbacks>
1180  clingCallbacks(new TClingCallbacks(fInterpreter));
1181  fClingCallbacks = clingCallbacks.get();
1183  fInterpreter->setCallbacks(std::move(clingCallbacks));
1184 
1185 }
1186 
1187 
1188 ////////////////////////////////////////////////////////////////////////////////
1189 /// Destroy the interpreter interface.
1190 
1192 {
1193  delete fMapfile;
1194 // delete fMapNamespaces;
1195  delete fRootmapFiles;
1196  delete fMetaProcessor;
1197  delete fTemporaries;
1198  delete fNormalizedCtxt;
1199  delete fInterpreter;
1200  delete fLookupHelper;
1201  gCling = 0;
1202 #if defined(R__MUST_REVISIT)
1203 #if R__MUST_REVISIT(6,2)
1204  Warning("~TCling", "Interface not available yet.");
1205 #ifdef R__COMPLETE_MEM_TERMINATION
1206  // remove all cling objects
1207 #endif
1208 #endif
1209 #endif
1210  //--
1211 }
1212 
1213 ////////////////////////////////////////////////////////////////////////////////
1214 /// Initialize the interpreter, once TROOT::fInterpreter is set.
1215 
1217 {
1219 }
1220 
1221 ////////////////////////////////////////////////////////////////////////////////
1222 /// Wrapper around dladdr (and friends)
1223 
1224 static const char *FindLibraryName(void (*func)())
1225 {
1226 #if defined(__CYGWIN__) && defined(__GNUC__)
1227  return 0;
1228 #elif defined(G__WIN32)
1229  MEMORY_BASIC_INFORMATION mbi;
1230  if (!VirtualQuery (func, &mbi, sizeof (mbi)))
1231  {
1232  return 0;
1233  }
1234 
1235  HMODULE hMod = (HMODULE) mbi.AllocationBase;
1236  TTHREAD_TLS_ARRAY(char, MAX_PATH, moduleName);
1237 
1238  if (!GetModuleFileNameA (hMod, moduleName, sizeof (moduleName)))
1239  {
1240  return 0;
1241  }
1242  return moduleName;
1243 #else
1244  Dl_info info;
1245  if (dladdr((void*)func,&info)==0) {
1246  // Not in a known share library, let's give up
1247  return 0;
1248  } else {
1249  //fprintf(stdout,"Found address in %s\n",info.dli_fname);
1250  return info.dli_fname;
1251  }
1252 #endif
1253 
1254 }
1255 
1256 ////////////////////////////////////////////////////////////////////////////////
1257 /// Helper to initialize TVirtualStreamerInfo's factor early.
1258 /// Use static initialization to insure only one TStreamerInfo is created.
1260 {
1261  // Use lambda since SetFactory return void.
1262  auto setFactory = []() {
1264  return kTRUE;
1265  };
1266  static bool doneFactory = setFactory();
1267  return doneFactory; // avoid unused variable warning.
1268 }
1269 
1270 
1271 ////////////////////////////////////////////////////////////////////////////////
1272 /// Tries to load a PCM; returns true on success.
1273 
1274 bool TCling::LoadPCM(TString pcmFileName,
1275  const char** headers,
1276  void (*triggerFunc)()) const {
1277  // pcmFileName is an intentional copy; updated by FindFile() below.
1278 
1279  TString searchPath;
1280 
1281  if (triggerFunc) {
1282  const char *libraryName = FindLibraryName(triggerFunc);
1283  if (libraryName) {
1284  searchPath = llvm::sys::path::parent_path(libraryName);
1285 #ifdef R__WIN32
1286  searchPath += ";";
1287 #else
1288  searchPath += ":";
1289 #endif
1290  }
1291  }
1292  // Note: if we know where the library is, we probably shouldn't even
1293  // look in other places.
1294  searchPath.Append( gSystem->GetDynamicPath() );
1295 
1296  if (!gSystem->FindFile(searchPath, pcmFileName))
1297  return kFALSE;
1298 
1299  // Prevent the ROOT-PCMs hitting this during auto-load during
1300  // JITting - which will cause recursive compilation.
1301  // Avoid to call the plugin manager at all.
1303 
1304  if (gROOT->IsRootFile(pcmFileName)) {
1305  Int_t oldDebug = gDebug;
1306  if (gDebug > 5) {
1307  gDebug -= 5;
1308  ::Info("TCling::LoadPCM", "Loading ROOT PCM %s", pcmFileName.Data());
1309  } else {
1310  gDebug = 0;
1311  }
1312 
1313  TDirectory::TContext ctxt;
1314 
1315  TFile *pcmFile = new TFile(pcmFileName+"?filetype=pcm","READ");
1316 
1317  auto listOfKeys = pcmFile->GetListOfKeys();
1318 
1319  // This is an empty pcm
1320  if (
1321  listOfKeys &&
1322  (
1323  (listOfKeys->GetSize() == 0) || // Nothing here, or
1324  (
1325  (listOfKeys->GetSize() == 1) && // only one, and
1326  !strcmp(((TKey*)listOfKeys->At(0))->GetName(), "EMPTY") // name is EMPTY
1327  )
1328  )
1329  ) {
1330  delete pcmFile;
1331  gDebug = oldDebug;
1332  return kTRUE;
1333  }
1334 
1335  TObjArray *protoClasses;
1336  if (gDebug > 1)
1337  ::Info("TCling::LoadPCM","reading protoclasses for %s \n",pcmFileName.Data());
1338 
1339  pcmFile->GetObject("__ProtoClasses", protoClasses);
1340 
1341  if (protoClasses) {
1342  for (auto obj : *protoClasses) {
1343  TProtoClass * proto = (TProtoClass*)obj;
1344  TClassTable::Add(proto);
1345  }
1346  // Now that all TClass-es know how to set them up we can update
1347  // existing TClasses, which might cause the creation of e.g. TBaseClass
1348  // objects which in turn requires the creation of TClasses, that could
1349  // come from the PCH, but maybe later in the loop. Instead of resolving
1350  // a dependency graph the addition to the TClassTable above allows us
1351  // to create these dependent TClasses as needed below.
1352  for (auto proto : *protoClasses) {
1353  if (TClass* existingCl
1354  = (TClass*)gROOT->GetListOfClasses()->FindObject(proto->GetName())) {
1355  // We have an existing TClass object. It might be emulated
1356  // or interpreted; we now have more information available.
1357  // Make that available.
1358  if (existingCl->GetState() != TClass::kHasTClassInit) {
1359  DictFuncPtr_t dict = gClassTable->GetDict(proto->GetName());
1360  if (!dict) {
1361  ::Error("TCling::LoadPCM", "Inconsistent TClassTable for %s",
1362  proto->GetName());
1363  } else {
1364  // This will replace the existing TClass.
1365  TClass *ncl = (*dict)();
1366  if (ncl) ncl->PostLoadCheck();
1367 
1368  }
1369  }
1370  }
1371  }
1372 
1373  protoClasses->Clear(); // Ownership was transfered to TClassTable.
1374  delete protoClasses;
1375  }
1376 
1377  TObjArray *dataTypes;
1378  pcmFile->GetObject("__Typedefs", dataTypes);
1379  if (dataTypes) {
1380  for (auto typedf: *dataTypes)
1381  gROOT->GetListOfTypes()->Add(typedf);
1382  dataTypes->Clear(); // Ownership was transfered to TListOfTypes.
1383  delete dataTypes;
1384  }
1385 
1386  TObjArray *enums;
1387  pcmFile->GetObject("__Enums", enums);
1388  if (enums) {
1389  // Cache the pointers
1390  auto listOfGlobals = gROOT->GetListOfGlobals();
1391  auto listOfEnums = dynamic_cast<THashList*>(gROOT->GetListOfEnums());
1392  // Loop on enums and then on enum constants
1393  for (auto selEnum: *enums){
1394  const char* enumScope = selEnum->GetTitle();
1395  const char* enumName = selEnum->GetName();
1396  if (strcmp(enumScope,"") == 0){
1397  // This is a global enum and is added to the
1398  // list of enums and its constants to the list of globals
1399  if (!listOfEnums->THashList::FindObject(enumName)){
1400  ((TEnum*) selEnum)->SetClass(nullptr);
1401  listOfEnums->Add(selEnum);
1402  }
1403  for (auto enumConstant: *static_cast<TEnum*>(selEnum)->GetConstants()){
1404  if (!listOfGlobals->FindObject(enumConstant)){
1405  listOfGlobals->Add(enumConstant);
1406  }
1407  }
1408  }
1409  else {
1410  // This enum is in a namespace. A TClass entry is bootstrapped if
1411  // none exists yet and the enum is added to it
1412  TClass* nsTClassEntry = TClass::GetClass(enumScope);
1413  if (!nsTClassEntry){
1414  nsTClassEntry = new TClass(enumScope,0,TClass::kNamespaceForMeta, true);
1415  }
1416  auto listOfEnums = nsTClassEntry->fEnums.load();
1417  if (!listOfEnums) {
1418  if ( (kIsClass | kIsStruct | kIsUnion) & nsTClassEntry->Property() ) {
1419  // For this case, the list will be immutable once constructed
1420  // (i.e. in this case, by the end of this routine).
1421  listOfEnums = nsTClassEntry->fEnums = new TListOfEnums(nsTClassEntry);
1422  } else {
1423  //namespaces can have enums added to them
1424  listOfEnums = nsTClassEntry->fEnums = new TListOfEnumsWithLock(nsTClassEntry);
1425  }
1426  }
1427  if (listOfEnums && !listOfEnums->THashList::FindObject(enumName)){
1428  ((TEnum*) selEnum)->SetClass(nsTClassEntry);
1429  listOfEnums->Add(selEnum);
1430  }
1431  }
1432  }
1433  enums->Clear();
1434  delete enums;
1435  }
1436 
1437  delete pcmFile;
1438 
1439  gDebug = oldDebug;
1440  } else {
1441  if (gDebug > 5)
1442  ::Info("TCling::LoadPCM", "Loading clang PCM %s", pcmFileName.Data());
1443 
1444  }
1445  // Note: Declaring the relationship between the module (pcm) and the header
1446  // probably does not yet make sense since the pcm is 'only' a root file.
1447  // We also have to review if we still need to do this with the delay loading.
1448  // clang::CompilerInstance* CI = fInterpreter->getCI();
1449  // ROOT::TMetaUtils::declareModuleMap(CI, pcmFileName, headers);
1450  return kTRUE;
1451 }
1452 
1453 //______________________________________________________________________________
1454 
1455 namespace {
1456  using namespace clang;
1457 
1458  class ExtLexicalStorageAdder: public RecursiveASTVisitor<ExtLexicalStorageAdder>{
1459  // This class is to be considered an helper for autoparsing.
1460  // It visits the AST and marks all classes (in all of their redeclarations)
1461  // with the setHasExternalLexicalStorage method.
1462  public:
1463  bool VisitRecordDecl(clang::RecordDecl* rcd){
1464  if (gDebug > 2)
1465  Info("ExtLexicalStorageAdder",
1466  "Adding external lexical storage to class %s",
1467  rcd->getNameAsString().c_str());
1468  auto reDeclPtr = rcd->getMostRecentDecl();
1469  do {
1470  reDeclPtr->setHasExternalLexicalStorage();
1471  } while ((reDeclPtr = reDeclPtr->getPreviousDecl()));
1472 
1473  return false;
1474  }
1475  };
1476 
1477 
1478 }
1479 
1480 ////////////////////////////////////////////////////////////////////////////////
1481 /// Inject the module named "modulename" into cling; load all headers.
1482 /// headers is a 0-terminated array of header files to #include after
1483 /// loading the module. The module is searched for in all $LD_LIBRARY_PATH
1484 /// entries (or %PATH% on Windows).
1485 /// This function gets called by the static initialization of dictionary
1486 /// libraries.
1487 /// The payload code is injected "as is" in the interpreter.
1488 /// The value of 'triggerFunc' is used to find the shared library location.
1489 
1490 void TCling::RegisterModule(const char* modulename,
1491  const char** headers,
1492  const char** includePaths,
1493  const char* payloadCode,
1494  const char* fwdDeclsCode,
1495  void (*triggerFunc)(),
1496  const FwdDeclArgsToKeepCollection_t& fwdDeclsArgToSkip,
1497  const char** classesHeaders)
1498 {
1499  // rootcling also uses TCling for generating the dictionary ROOT files.
1500  static const bool fromRootCling = dlsym(RTLD_DEFAULT, "usedToIdentifyRootClingByDlSym");
1501  // We need the dictionary initialization but we don't want to inject the
1502  // declarations into the interpreter, except for those we really need for
1503  // I/O; see rootcling.cxx after the call to TCling__GetInterpreter().
1504  if (fromRootCling) return;
1505 
1506  // Treat Aclic Libs in a special way. Do not delay the parsing.
1507  bool hasHeaderParsingOnDemand = fHeaderParsingOnDemand;
1508  bool isACLiC = false;
1509  if (hasHeaderParsingOnDemand &&
1510  strstr(modulename, "_ACLiC_dict") != nullptr){
1511  if (gDebug>1)
1512  Info("TCling::RegisterModule",
1513  "Header parsing on demand is active but this is an Aclic library. Disabling it for this library.");
1514  hasHeaderParsingOnDemand = false;
1515  isACLiC = true;
1516  }
1517 
1518 
1519  // Make sure we relookup symbols that were search for before we loaded
1520  // their autoparse information. We could be more subtil and remove only
1521  // the failed one or only the one in this module, but for now this is
1522  // better than nothing.
1523  fLookedUpClasses.clear();
1524 
1525  // Make sure we do not set off autoloading or autoparsing during the
1526  // module registration!
1527  Int_t oldAutoloadValue = SetClassAutoloading(false);
1528 
1529  TString pcmFileName(ROOT::TMetaUtils::GetModuleFileName(modulename).c_str());
1530 
1531  for (const char** inclPath = includePaths; *inclPath; ++inclPath) {
1532  TCling::AddIncludePath(*inclPath);
1533  }
1534  cling::Transaction* T = 0;
1535  // Put the template decls and the number of arguments to skip in the TNormalizedCtxt
1536  for (auto& fwdDeclArgToSkipPair : fwdDeclsArgToSkip){
1537  const std::string& fwdDecl = fwdDeclArgToSkipPair.first;
1538  const int nArgsToSkip = fwdDeclArgToSkipPair.second;
1539  auto compRes = fInterpreter->declare(fwdDecl.c_str(), &T);
1540  assert(cling::Interpreter::kSuccess == compRes &&
1541  "A fwd declaration could not be compiled");
1542  if (compRes!=cling::Interpreter::kSuccess){
1543  Warning("TCling::RegisterModule",
1544  "Problems in declaring string '%s' were encountered.",
1545  fwdDecl.c_str()) ;
1546  continue;
1547  }
1548 
1549  // Drill through namespaces recursively until the template is found
1550  if(ClassTemplateDecl* TD = FindTemplateInNamespace(T->getFirstDecl().getSingleDecl())){
1551  fNormalizedCtxt->AddTemplAndNargsToKeep(TD->getCanonicalDecl(), nArgsToSkip);
1552  }
1553 
1554  }
1555 
1556  // FIXME: Remove #define __ROOTCLING__ once PCMs are there.
1557  // This is used to give Sema the same view on ACLiC'ed files (which
1558  // are then #included through the dictionary) as rootcling had.
1559  TString code = gNonInterpreterClassDef;
1560  code += payloadCode;
1561 
1562  // We need to open the dictionary shared library, to resolve symbols
1563  // requested by the JIT from it: as the library is currently being dlopen'ed,
1564  // its symbols are not yet reachable from the process.
1565  // Recursive dlopen seems to work just fine.
1566  const char* dyLibName = FindLibraryName(triggerFunc);
1567  if (dyLibName) {
1568  // We were able to determine the library name.
1569  void* dyLibHandle = dlopen(dyLibName, RTLD_LAZY | RTLD_GLOBAL);
1570  if (!dyLibHandle) {
1571 #ifdef R__WIN32
1572  char dyLibError[1000];
1573  FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(),
1574  MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), dyLibError,
1575  sizeof(dyLibError), NULL);
1576  {
1577 #else
1578  const char* dyLibError = dlerror();
1579  if (dyLibError) {
1580 #endif
1581  if (gDebug > 0) {
1582  ::Info("TCling::RegisterModule",
1583  "Cannot open shared library %s for dictionary %s:\n %s",
1584  dyLibName, modulename, dyLibError);
1585  }
1586  }
1587  dyLibName = 0;
1588  } else {
1589  fRegisterModuleDyLibs.push_back(dyLibHandle);
1590  }
1591  }
1592 
1593  if (hasHeaderParsingOnDemand && fwdDeclsCode){
1594  // We now parse the forward declarations. All the classes are then modified
1595  // in order for them to have an external lexical storage.
1596  std::string fwdDeclsCodeLessEnums;
1597  {
1598  // Search for enum forward decls and only declare them if no
1599  // declaration exists yet.
1600  std::string fwdDeclsLine;
1601  std::istringstream fwdDeclsCodeStr(fwdDeclsCode);
1602  std::vector<std::string> scope;
1603  while (std::getline(fwdDeclsCodeStr, fwdDeclsLine)) {
1604  if (fwdDeclsLine.find("namespace ") == 0
1605  || fwdDeclsLine.find("inline namespace ") == 0) {
1606  // skip leading "namespace ", trailing " {"
1607  scope.push_back(fwdDeclsLine.substr(10,
1608  fwdDeclsLine.length() - 10 - 2));
1609  } else if (fwdDeclsLine == "}") {
1610  scope.pop_back();
1611  } else if (fwdDeclsLine.find("enum __attribute__((annotate(\"") == 0) {
1612  clang::DeclContext* DC = 0;
1613  for (auto &&aScope: scope) {
1614  DC = cling::utils::Lookup::Namespace(&fInterpreter->getSema(), aScope.c_str(), DC);
1615  if (!DC) {
1616  // No decl context means we have to fwd declare the enum.
1617  break;
1618  }
1619  }
1620  if (scope.empty() || DC) {
1621  // We know the scope; let's look for the enum.
1622  size_t posEnumName = fwdDeclsLine.find("\"))) ", 32);
1623  R__ASSERT(posEnumName != std::string::npos && "Inconsistent enum fwd decl!");
1624  posEnumName += 5; // skip "\"))) "
1625  while (isspace(fwdDeclsLine[posEnumName]))
1626  ++posEnumName;
1627  size_t posEnumNameEnd = fwdDeclsLine.find(" : ", posEnumName);
1628  R__ASSERT(posEnumNameEnd != std::string::npos && "Inconsistent enum fwd decl (end)!");
1629  while (isspace(fwdDeclsLine[posEnumNameEnd]))
1630  --posEnumNameEnd;
1631  // posEnumNameEnd now points to the last character of the name.
1632 
1633  std::string enumName = fwdDeclsLine.substr(posEnumName,
1634  posEnumNameEnd - posEnumName + 1);
1635 
1636  if (clang::NamedDecl* enumDecl
1637  = cling::utils::Lookup::Named(&fInterpreter->getSema(),
1638  enumName.c_str(), DC)) {
1639  // We have an existing enum decl (forward or definition);
1640  // skip this.
1641  R__ASSERT(llvm::dyn_cast<clang::EnumDecl>(enumDecl) && "not an enum decl!");
1642  (void)enumDecl;
1643  continue;
1644  }
1645  }
1646  }
1647  fwdDeclsCodeLessEnums += fwdDeclsLine + "\n";
1648  }
1649  }
1650 
1651  if (fwdDeclsCodeLessEnums.size() != 0){ // Avoid the overhead if nothing is to be declared
1652  auto compRes = fInterpreter->declare(fwdDeclsCodeLessEnums, &T);
1653  assert(cling::Interpreter::kSuccess == compRes &&
1654  "The forward declarations could not be compiled");
1655  if (compRes!=cling::Interpreter::kSuccess){
1656  Warning("TCling::RegisterModule",
1657  "Problems in compiling forward declarations for module %s: '%s'",
1658  modulename, fwdDeclsCodeLessEnums.c_str()) ;
1659  }
1660  else if (T){
1661  // Loop over all decls in the transaction and go through them all
1662  // to mark them properly.
1663  // In order to do that, we first iterate over all the DelayedCallInfos
1664  // within the transaction. Then we loop over all Decls in the DeclGroupRef
1665  // contained in the DelayedCallInfos. For each decl, we traverse.
1666  ExtLexicalStorageAdder elsa;
1667  for (auto dciIt = T->decls_begin();dciIt!=T->decls_end();dciIt++){
1668  cling::Transaction::DelayCallInfo& dci = *dciIt;
1669  for(auto dit = dci.m_DGR.begin(); dit != dci.m_DGR.end(); ++dit) {
1670  clang::Decl* declPtr = *dit;
1671  elsa.TraverseDecl(declPtr);
1672  }
1673  }
1674  }
1675  }
1676 
1677  // Now we register all the headers necessary for the class
1678  // Typical format of the array:
1679  // {"A", "classes.h", "@",
1680  // "vector<A>", "vector", "@",
1681  // "myClass", payloadCode, "@",
1682  // nullptr};
1683 
1684  std::string temp;
1685  for (const char** classesHeader = classesHeaders; *classesHeader; ++classesHeader) {
1686  temp=*classesHeader;
1687 
1688  size_t theTemplateHash = 0;
1689  bool addTemplate = false;
1690  size_t posTemplate = temp.find('<');
1691  if (posTemplate != std::string::npos) {
1692  // Add an entry for the template itself.
1693  std::string templateName = temp.substr(0, posTemplate);
1694  theTemplateHash = fStringHashFunction(templateName);
1695  addTemplate = true;
1696  }
1697  size_t theHash = fStringHashFunction(temp);
1698  classesHeader++;
1699  for (const char** classesHeader_inner = classesHeader; 0!=strcmp(*classesHeader_inner,"@"); ++classesHeader_inner,++classesHeader){
1700  // This is done in order to distinguish headers from files and from the payloadCode
1701  if (payloadCode == *classesHeader_inner ){
1702  fPayloads.insert(theHash);
1703  if (addTemplate) fPayloads.insert(theTemplateHash);
1704  }
1705  if (gDebug > 2)
1706  Info("TCling::RegisterModule",
1707  "Adding a header for %s", temp.c_str());
1708  fClassesHeadersMap[theHash].push_back(*classesHeader_inner);
1709  if (addTemplate) {
1710  if (fClassesHeadersMap.find(theTemplateHash) == fClassesHeadersMap.end()) {
1711  fClassesHeadersMap[theTemplateHash].push_back(*classesHeader_inner);
1712  }
1713  addTemplate = false;
1714  }
1715  }
1716  }
1717  }
1718 
1719 
1720  if (strcmp(modulename,"libCore")!=0 && strcmp(modulename,"libRint")!=0
1721  && strcmp(modulename,"libThread")!=0 && strcmp(modulename,"libRIO")!=0
1722  && strcmp(modulename,"libcomplexDict")!=0 && strcmp(modulename,"libdequeDict")!=0
1723  && strcmp(modulename,"liblistDict")!=0 && strcmp(modulename,"libforward_listDict")!=0
1724  && strcmp(modulename,"libvectorDict")!=0
1725  && strcmp(modulename,"libmapDict")!=0 && strcmp(modulename,"libmultimap2Dict")!=0
1726  && strcmp(modulename,"libmap2Dict")!=0 && strcmp(modulename,"libmultimapDict")!=0
1727  && strcmp(modulename,"libsetDict")!=0 && strcmp(modulename,"libmultisetDict")!=0
1728  && strcmp(modulename,"libunordered_setDict")!=0 && strcmp(modulename,"libunordered_multisetDict")!=0
1729  && strcmp(modulename,"libunordered_mapDict")!=0 && strcmp(modulename,"libunordered_multimapDict")!=0
1730  && strcmp(modulename,"libvalarrayDict")!=0
1731  && strcmp(modulename,"G__GenVector32")!=0 && strcmp(modulename,"G__Smatrix32")!=0
1732 
1733  ) {
1734  // No pcm for now for libCore or libRint, the info is in the pch.
1735  if (!LoadPCM(pcmFileName, headers, triggerFunc)) {
1736  ::Error("TCling::RegisterModule", "cannot find dictionary module %s",
1737  ROOT::TMetaUtils::GetModuleFileName(modulename).c_str());
1738  }
1739  }
1740 
1741  bool oldValue = false;
1742  if (fClingCallbacks)
1743  oldValue = SetClassAutoloading(false);
1744 
1745  { // scope within which diagnostics are de-activated
1746  // For now we disable diagnostics because we saw them already at
1747  // dictionary generation time. That won't be an issue with the PCMs.
1748 
1749  clangDiagSuppr diagSuppr(fInterpreter->getSema().getDiagnostics());
1750 
1751 #if defined(R__MUST_REVISIT)
1752 #if R__MUST_REVISIT(6,2)
1753  Warning("TCling::RegisterModule","Diagnostics suppression should be gone by now.");
1754 #endif
1755 #endif
1756 
1757  if (!hasHeaderParsingOnDemand){
1758  SuspendAutoParsing autoParseRaii(this);
1759 
1760  const cling::Transaction* watermark = fInterpreter->getLastTransaction();
1761  cling::Interpreter::CompilationResult compRes = fInterpreter->parseForModule(code.Data());
1762  if (isACLiC) {
1763  // Register an unload point.
1764  fMetaProcessor->registerUnloadPoint(watermark, headers[0]);
1765  }
1766 
1767  assert(cling::Interpreter::kSuccess == compRes &&
1768  "Payload code of a dictionary could not be parsed correctly.");
1769  if (compRes!=cling::Interpreter::kSuccess) {
1770  Warning("TCling::RegisterModule",
1771  "Problems declaring payload for module %s.", modulename) ;
1772  }
1773  }
1774  }
1775 
1776  // Now that all the header have been registered/compiled, let's
1777  // make sure to 'reset' the TClass that have a class init in this module
1778  // but already had their type information available (using information/header
1779  // loaded from other modules or from class rules).
1780  if (!hasHeaderParsingOnDemand) {
1781  // This code is likely to be superseded by the similar code in LoadPCM,
1782  // and have been disabled, (inadvertently or awkwardly) by
1783  // commit 7903f09f3beea69e82ffba29f59fb2d656a4fd54 (Refactor the routines used for header parsing on demand)
1784  // whereas it seems that a more semantically correct conditional would have
1785  // been 'if this module does not have a rootpcm'.
1786  // Note: this need to be review when the clang pcm are being installed.
1787  // #if defined(R__MUST_REVISIT)
1788  while (!fClassesToUpdate.empty()) {
1789  TClass *oldcl = fClassesToUpdate.back().first;
1790  if (oldcl->GetState() != TClass::kHasTClassInit) {
1791  // if (gDebug > 2) Info("RegisterModule", "Forcing TClass init for %s", oldcl->GetName());
1792  DictFuncPtr_t dict = fClassesToUpdate.back().second;
1793  fClassesToUpdate.pop_back();
1794  // Calling func could manipulate the list so, let maintain the list
1795  // then call the dictionary function.
1796  TClass *ncl = dict();
1797  if (ncl) ncl->PostLoadCheck();
1798  } else {
1799  fClassesToUpdate.pop_back();
1800  }
1801  }
1802  }
1803 
1804  if (fClingCallbacks)
1805  SetClassAutoloading(oldValue);
1806 
1807  if (!hasHeaderParsingOnDemand) {
1808  // __ROOTCLING__ might be pulled in through PCH
1809  fInterpreter->declare("#ifdef __ROOTCLING__\n"
1810  "#undef __ROOTCLING__\n"
1811  + gInterpreterClassDef +
1812  "#endif");
1813  }
1814 
1815  if (dyLibName) {
1816  void* dyLibHandle = fRegisterModuleDyLibs.back();
1817  fRegisterModuleDyLibs.pop_back();
1818  dlclose(dyLibHandle);
1819  }
1820 
1821  SetClassAutoloading(oldAutoloadValue);
1822 }
1823 
1824 ////////////////////////////////////////////////////////////////////////////////
1825 /// Register classes that already existed prior to their dictionary loading
1826 /// and that already had a ClassInfo (and thus would not be refresh via
1827 /// UpdateClassInfo.
1828 
1830 {
1831  fClassesToUpdate.push_back(std::make_pair(oldcl,dict));
1832 }
1833 
1834 ////////////////////////////////////////////////////////////////////////////////
1835 /// If the dictionary is loaded, we can remove the class from the list
1836 /// (otherwise the class might be loaded twice).
1837 
1839 {
1840  typedef std::vector<std::pair<TClass*,DictFuncPtr_t> >::iterator iterator;
1841  iterator stop = fClassesToUpdate.end();
1842  for(iterator i = fClassesToUpdate.begin();
1843  i != stop;
1844  ++i)
1845  {
1846  if ( i->first == oldcl ) {
1847  fClassesToUpdate.erase(i);
1848  return;
1849  }
1850  }
1851 }
1852 
1853 ////////////////////////////////////////////////////////////////////////////////
1854 /// Let cling process a command line.
1855 ///
1856 /// If the command is executed and the error is 0, then the return value
1857 /// is the int value corresponding to the result of the executed command
1858 /// (float and double return values will be truncated).
1859 ///
1860 
1861 // Method for handling the interpreter exceptions.
1862 // the MetaProcessor is passing in as argument to teh function, because
1863 // cling::Interpreter::CompilationResult is a nested class and it cannot be
1864 // forward declared, thus this method cannot be a static member function
1865 // of TCling.
1866 
1867 static int HandleInterpreterException(cling::MetaProcessor* metaProcessor,
1868  const char* input_line,
1869  cling::Interpreter::CompilationResult& compRes,
1871 {
1872  try {
1873  return metaProcessor->process(input_line, compRes, result);
1874  }
1875  catch (cling::InvalidDerefException& ex)
1876  {
1877  Error("HandleInterpreterException", "%s.\n%s", ex.what(), "Execution of your code was aborted.");
1878  ex.diagnose();
1879  }
1880  return 0;
1881 }
1882 
1883 ////////////////////////////////////////////////////////////////////////////////
1884 
1885 bool TCling::DiagnoseIfInterpreterException(const std::exception &e) const
1886 {
1887  if (auto ie = dynamic_cast<const cling::InterpreterException*>(&e)) {
1888  ie->diagnose();
1889  return true;
1890  }
1891  return false;
1892 }
1893 
1894 ////////////////////////////////////////////////////////////////////////////////
1895 
1896 Long_t TCling::ProcessLine(const char* line, EErrorCode* error/*=0*/)
1897 {
1898  // Copy the passed line, it comes from a static buffer in TApplication
1899  // which can be reentered through the Cling evaluation routines,
1900  // which would overwrite the static buffer and we would forget what we
1901  // were doing.
1902  //
1903  TString sLine(line);
1904  if (strstr(line,fantomline)) {
1905  // End-Of-Line action
1906  // See the comment (copied from above):
1907  // It is a "fantom" method to synchronize user keyboard input
1908  // and ROOT prompt line (for WIN32)
1909  // and is implemented by
1910  if (gApplication) {
1911  if (gApplication->IsCmdThread()) {
1913  gGlobalMutex->Lock();
1914  if (!gInterpreterMutex)
1916  gGlobalMutex->UnLock();
1917  }
1919  gROOT->SetLineIsProcessing();
1920 
1922 
1923  gROOT->SetLineHasBeenProcessed();
1924  }
1925  }
1926  return 0;
1927  }
1928 
1930  gGlobalMutex->Lock();
1931  if (!gInterpreterMutex)
1933  gGlobalMutex->UnLock();
1934  }
1936  gROOT->SetLineIsProcessing();
1937 
1938  struct InterpreterFlagsRAII_t {
1939  cling::Interpreter* fInterpreter;
1940  bool fWasDynamicLookupEnabled;
1941 
1942  InterpreterFlagsRAII_t(cling::Interpreter* interp):
1943  fInterpreter(interp),
1944  fWasDynamicLookupEnabled(interp->isDynamicLookupEnabled())
1945  {
1946  fInterpreter->enableDynamicLookup(true);
1947  }
1948  ~InterpreterFlagsRAII_t() {
1949  fInterpreter->enableDynamicLookup(fWasDynamicLookupEnabled);
1950  gROOT->SetLineHasBeenProcessed();
1951  }
1952  } interpreterFlagsRAII(fInterpreter);
1953 
1954  // A non-zero returned value means the given line was
1955  // not a complete statement.
1956  int indent = 0;
1957  // This will hold the resulting value of the evaluation the given line.
1959  cling::Interpreter::CompilationResult compRes = cling::Interpreter::kSuccess;
1960  if (!strncmp(sLine.Data(), ".L", 2) || !strncmp(sLine.Data(), ".x", 2) ||
1961  !strncmp(sLine.Data(), ".X", 2)) {
1962  // If there was a trailing "+", then CINT compiled the code above,
1963  // and we will need to strip the "+" before passing the line to cling.
1964  TString mod_line(sLine);
1965  TString aclicMode;
1966  TString arguments;
1967  TString io;
1968  TString fname = gSystem->SplitAclicMode(sLine.Data() + 3,
1969  aclicMode, arguments, io);
1970  if (aclicMode.Length()) {
1971  // Remove the leading '+'
1972  R__ASSERT(aclicMode[0]=='+' && "ACLiC mode must start with a +");
1973  aclicMode[0]='k'; // We always want to keep the .so around.
1974  if (aclicMode[1]=='+') {
1975  // We have a 2nd +
1976  aclicMode[1]='f'; // We want to force the recompilation.
1977  }
1978  if (!gSystem->CompileMacro(fname,aclicMode)) {
1979  // ACLiC failed.
1980  compRes = cling::Interpreter::kFailure;
1981  } else {
1982  if (strncmp(sLine.Data(), ".L", 2) != 0) {
1983  // if execution was requested.
1984 
1985  if (arguments.Length()==0) {
1986  arguments = "()";
1987  }
1988  // We need to remove the extension.
1989  Ssiz_t ext = fname.Last('.');
1990  if (ext != kNPOS) {
1991  fname.Remove(ext);
1992  }
1993  const char *function = gSystem->BaseName(fname);
1994  mod_line = function + arguments + io;
1995  cling::MetaProcessor::MaybeRedirectOutputRAII RAII(fMetaProcessor);
1996  indent = HandleInterpreterException(fMetaProcessor, mod_line, compRes, &result);
1997  }
1998  }
1999  } else {
2000  // not ACLiC
2001  size_t unnamedMacroOpenCurly;
2002  {
2003  std::string code;
2004  std::string codeline;
2005  std::ifstream in(fname);
2006  while (in) {
2007  std::getline(in, codeline);
2008  code += codeline + "\n";
2009  }
2010  unnamedMacroOpenCurly
2011  = cling::utils::isUnnamedMacro(code, fInterpreter->getCI()->getLangOpts());
2012  }
2013 
2014  fCurExecutingMacros.push_back(fname);
2015  cling::MetaProcessor::MaybeRedirectOutputRAII RAII(fMetaProcessor);
2016  if (unnamedMacroOpenCurly != std::string::npos) {
2017  compRes = fMetaProcessor->readInputFromFile(fname.Data(), &result,
2018  unnamedMacroOpenCurly);
2019  } else {
2020  // No DynLookup for .x, .L of named macros.
2021  fInterpreter->enableDynamicLookup(false);
2022  indent = HandleInterpreterException(fMetaProcessor, mod_line, compRes, &result);
2023  }
2024  fCurExecutingMacros.pop_back();
2025  }
2026  } // .L / .X / .x
2027  else {
2028  if (0!=strncmp(sLine.Data(), ".autodict ",10) && sLine != ".autodict") {
2029  // explicitly ignore .autodict without having to support it
2030  // in cling.
2031  cling::MetaProcessor::MaybeRedirectOutputRAII RAII(fMetaProcessor);
2032 
2033  // Turn off autoparsing if this is an include directive
2034  bool isInclusionDirective = sLine.Contains("\n#include") || sLine.BeginsWith("#include");
2035  if (isInclusionDirective) {
2036  SuspendAutoParsing autoParseRaii(this);
2037  indent = HandleInterpreterException(fMetaProcessor, sLine, compRes, &result);
2038  } else {
2039  indent = HandleInterpreterException(fMetaProcessor, sLine, compRes, &result);
2040  }
2041  }
2042  }
2043  if (result.isValid())
2044  RegisterTemporary(result);
2045  if (indent) {
2046  if (error)
2047  *error = kProcessing;
2048  return 0;
2049  }
2050  if (error) {
2051  switch (compRes) {
2052  case cling::Interpreter::kSuccess: *error = kNoError; break;
2053  case cling::Interpreter::kFailure: *error = kRecoverable; break;
2054  case cling::Interpreter::kMoreInputExpected: *error = kProcessing; break;
2055  }
2056  }
2057  if (compRes == cling::Interpreter::kSuccess
2058  && result.isValid()
2059  && !result.isVoid())
2060  {
2061  gROOT->SetLineHasBeenProcessed();
2062  return result.simplisticCastAs<long>();
2063  }
2064  gROOT->SetLineHasBeenProcessed();
2065  return 0;
2066 }
2067 
2068 ////////////////////////////////////////////////////////////////////////////////
2069 /// No-op; see TRint instead.
2070 
2072 {
2073 }
2074 
2075 ////////////////////////////////////////////////////////////////////////////////
2076 /// Add the given path to the list of directories in which the interpreter
2077 /// looks for include files. Only one path item can be specified at a
2078 /// time, i.e. "path1:path2" is NOT supported.
2079 
2080 void TCling::AddIncludePath(const char *path)
2081 {
2083  // Favorite source of annoyance: gSystem->AddIncludePath() needs "-I",
2084  // gCling->AddIncludePath() does not! Work around that inconsistency:
2085  if (path[0] == '-' && path[1] == 'I')
2086  path += 2;
2087 
2088  fInterpreter->AddIncludePath(path);
2089 }
2090 
2091 ////////////////////////////////////////////////////////////////////////////////
2092 /// Visit all members over members, recursing over base classes.
2093 
2094 void TCling::InspectMembers(TMemberInspector& insp, const void* obj,
2095  const TClass* cl, Bool_t isTransient)
2096 {
2100  }
2101 
2102  if (!cl || cl->GetCollectionProxy()) {
2103  // We do not need to investigate the content of the STL
2104  // collection, they are opaque to us (and details are
2105  // uninteresting).
2106  return;
2107  }
2108 
2109  static const TClassRef clRefString("std::string");
2110  if (clRefString == cl) {
2111  // We stream std::string without going through members..
2112  return;
2113  }
2114 
2115  const char* cobj = (const char*) obj; // for ptr arithmetics
2116 
2117  // Treat the case of std::complex in a special manner. We want to enforce
2118  // the layout of a stl implementation independent class, which is the
2119  // complex as implemented in ROOT5.
2120 
2121  // A simple lambda to simplify the code
2122  auto inspInspect = [&] (ptrdiff_t offset){
2123  insp.Inspect(const_cast<TClass*>(cl), insp.GetParent(), "_real", cobj, isTransient);
2124  insp.Inspect(const_cast<TClass*>(cl), insp.GetParent(), "_imag", cobj + offset, isTransient);
2125  };
2126 
2127  auto complexType = TClassEdit::GetComplexType(cl->GetName());
2128  switch(complexType) {
2130  {
2131  break;
2132  }
2134  {
2135  inspInspect(sizeof(float));
2136  return;
2137  }
2139  {
2140  inspInspect(sizeof(double));
2141  return;
2142  }
2144  {
2145  inspInspect(sizeof(int));
2146  return;
2147  }
2149  {
2150  inspInspect(sizeof(long));
2151  return;
2152  }
2153  }
2154 
2155  static clang::PrintingPolicy
2156  printPol(fInterpreter->getCI()->getLangOpts());
2157  if (printPol.Indentation) {
2158  // not yet initialized
2159  printPol.Indentation = 0;
2160  printPol.SuppressInitializers = true;
2161  }
2162 
2163  const char* clname = cl->GetName();
2164  // Printf("Inspecting class %s\n", clname);
2165 
2166  const clang::ASTContext& astContext = fInterpreter->getCI()->getASTContext();
2167  const clang::Decl *scopeDecl = 0;
2168  const clang::Type *recordType = 0;
2169 
2170  if (cl->GetClassInfo()) {
2171  TClingClassInfo * clingCI = (TClingClassInfo *)cl->GetClassInfo();
2172  scopeDecl = clingCI->GetDecl();
2173  recordType = clingCI->GetType();
2174  } else {
2175  const cling::LookupHelper& lh = fInterpreter->getLookupHelper();
2176  // Diags will complain about private classes:
2177  scopeDecl = lh.findScope(clname, cling::LookupHelper::NoDiagnostics,
2178  &recordType);
2179  }
2180  if (!scopeDecl) {
2181  Error("InspectMembers", "Cannot find Decl for class %s", clname);
2182  return;
2183  }
2184  const clang::CXXRecordDecl* recordDecl
2185  = llvm::dyn_cast<const clang::CXXRecordDecl>(scopeDecl);
2186  if (!recordDecl) {
2187  Error("InspectMembers", "Cannot find Decl for class %s is not a CXXRecordDecl.", clname);
2188  return;
2189  }
2190 
2191  {
2192  // Force possible deserializations first. We need to have no pending
2193  // Transaction when passing control flow to the inspector below (ROOT-7779).
2194  cling::Interpreter::PushTransactionRAII deserRAII(fInterpreter);
2195 
2196  astContext.getASTRecordLayout(recordDecl);
2197 
2198  for (clang::RecordDecl::field_iterator iField = recordDecl->field_begin(),
2199  eField = recordDecl->field_end(); iField != eField; ++iField) {}
2200  }
2201 
2202  const clang::ASTRecordLayout& recLayout
2203  = astContext.getASTRecordLayout(recordDecl);
2204 
2205  // TVirtualCollectionProxy *proxy = cl->GetCollectionProxy();
2206  // if (proxy && ( proxy->GetProperties() & TVirtualCollectionProxy::kIsEmulated ) ) {
2207  // Error("InspectMembers","The TClass for %s has an emulated proxy but we are looking at a compiled version of the collection!\n",
2208  // cl->GetName());
2209  // }
2210  if (cl->Size() != recLayout.getSize().getQuantity()) {
2211  Error("InspectMembers","TClass and cling disagree on the size of the class %s, respectively %d %lld\n",
2212  cl->GetName(),cl->Size(),(Long64_t)recLayout.getSize().getQuantity());
2213  }
2214 
2215  unsigned iNField = 0;
2216  // iterate over fields
2217  // FieldDecls are non-static, else it would be a VarDecl.
2218  for (clang::RecordDecl::field_iterator iField = recordDecl->field_begin(),
2219  eField = recordDecl->field_end(); iField != eField;
2220  ++iField, ++iNField) {
2221 
2222 
2223  clang::QualType memberQT = iField->getType();
2224  if (recordType) {
2225  // if (we_need_to_do_the_subst_because_the_class_is_a_template_instance_of_double32_t)
2226  memberQT = ROOT::TMetaUtils::ReSubstTemplateArg(memberQT, recordType);
2227  }
2228  memberQT = cling::utils::Transform::GetPartiallyDesugaredType(astContext, memberQT, fNormalizedCtxt->GetConfig(), false /* fully qualify */);
2229  if (memberQT.isNull()) {
2230  std::string memberName;
2231  llvm::raw_string_ostream stream(memberName);
2232  // Don't trigger fopen of the source file to count lines:
2233  printPol.AnonymousTagLocations = false;
2234  iField->getNameForDiagnostic(stream, printPol, true /*fqi*/);
2235  stream.flush();
2236  Error("InspectMembers",
2237  "Cannot retrieve QualType for member %s while inspecting class %s",
2238  memberName.c_str(), clname);
2239  continue; // skip member
2240  }
2241  const clang::Type* memType = memberQT.getTypePtr();
2242  if (!memType) {
2243  std::string memberName;
2244  llvm::raw_string_ostream stream(memberName);
2245  // Don't trigger fopen of the source file to count lines:
2246  printPol.AnonymousTagLocations = false;
2247  iField->getNameForDiagnostic(stream, printPol, true /*fqi*/);
2248  stream.flush();
2249  Error("InspectMembers",
2250  "Cannot retrieve Type for member %s while inspecting class %s",
2251  memberName.c_str(), clname);
2252  continue; // skip member
2253  }
2254 
2255  const clang::Type* memNonPtrType = memType;
2256  Bool_t ispointer = false;
2257  if (memNonPtrType->isPointerType()) {
2258  ispointer = true;
2259  clang::QualType ptrQT
2260  = memNonPtrType->getAs<clang::PointerType>()->getPointeeType();
2261  if (recordType) {
2262  // if (we_need_to_do_the_subst_because_the_class_is_a_template_instance_of_double32_t)
2263  ptrQT = ROOT::TMetaUtils::ReSubstTemplateArg(ptrQT, recordType);
2264  }
2265  ptrQT = cling::utils::Transform::GetPartiallyDesugaredType(astContext, ptrQT, fNormalizedCtxt->GetConfig(), false /* fully qualify */);
2266  if (ptrQT.isNull()) {
2267  std::string memberName;
2268  llvm::raw_string_ostream stream(memberName);
2269  // Don't trigger fopen of the source file to count lines:
2270  printPol.AnonymousTagLocations = false;
2271  iField->getNameForDiagnostic(stream, printPol, true /*fqi*/);
2272  stream.flush();
2273  Error("InspectMembers",
2274  "Cannot retrieve pointee Type for member %s while inspecting class %s",
2275  memberName.c_str(), clname);
2276  continue; // skip member
2277  }
2278  memNonPtrType = ptrQT.getTypePtr();
2279  }
2280 
2281  // assemble array size(s): "[12][4][]"
2282  llvm::SmallString<8> arraySize;
2283  const clang::ArrayType* arrType = memNonPtrType->getAsArrayTypeUnsafe();
2284  unsigned arrLevel = 0;
2285  bool haveErrorDueToArray = false;
2286  while (arrType) {
2287  ++arrLevel;
2288  arraySize += '[';
2289  const clang::ConstantArrayType* constArrType =
2290  clang::dyn_cast<clang::ConstantArrayType>(arrType);
2291  if (constArrType) {
2292  constArrType->getSize().toStringUnsigned(arraySize);
2293  }
2294  arraySize += ']';
2295  clang::QualType subArrQT = arrType->getElementType();
2296  if (subArrQT.isNull()) {
2297  std::string memberName;
2298  llvm::raw_string_ostream stream(memberName);
2299  // Don't trigger fopen of the source file to count lines:
2300  printPol.AnonymousTagLocations = false;
2301  iField->getNameForDiagnostic(stream, printPol, true /*fqi*/);
2302  stream.flush();
2303  Error("InspectMembers",
2304  "Cannot retrieve QualType for array level %d (i.e. element type of %s) for member %s while inspecting class %s",
2305  arrLevel, subArrQT.getAsString(printPol).c_str(),
2306  memberName.c_str(), clname);
2307  haveErrorDueToArray = true;
2308  break;
2309  }
2310  arrType = subArrQT.getTypePtr()->getAsArrayTypeUnsafe();
2311  }
2312  if (haveErrorDueToArray) {
2313  continue; // skip member
2314  }
2315 
2316  // construct member name
2317  std::string fieldName;
2318  if (memType->isPointerType()) {
2319  fieldName = "*";
2320  }
2321 
2322  // Check if this field has a custom ioname, if not, just use the one of the decl
2323  std::string ioname(iField->getName());
2325  fieldName += ioname;
2326  fieldName += arraySize;
2327 
2328  // get member offset
2329  // NOTE currently we do not support bitfield and do not support
2330  // member that are not aligned on 'bit' boundaries.
2331  clang::CharUnits offset(astContext.toCharUnitsFromBits(recLayout.getFieldOffset(iNField)));
2332  ptrdiff_t fieldOffset = offset.getQuantity();
2333 
2334  // R__insp.Inspect(R__cl, R__insp.GetParent(), "fBits[2]", fBits);
2335  // R__insp.Inspect(R__cl, R__insp.GetParent(), "fName", &fName);
2336  // R__insp.InspectMember(fName, "fName.");
2337  // R__insp.Inspect(R__cl, R__insp.GetParent(), "*fClass", &fClass);
2338 
2339  // If the class has a custom streamer and the type of the filed is a
2340  // private enum, struct or class, skip it.
2341  if (!insp.IsTreatingNonAccessibleTypes()){
2342  auto iFiledQtype = iField->getType();
2343  if (auto tagDecl = iFiledQtype->getAsTagDecl()){
2344  auto declAccess = tagDecl->getAccess();
2345  if (declAccess == AS_private || declAccess == AS_protected) {
2346  continue;
2347  }
2348  }
2349  }
2350 
2351  insp.Inspect(const_cast<TClass*>(cl), insp.GetParent(), fieldName.c_str(), cobj + fieldOffset, isTransient);
2352 
2353  if (!ispointer) {
2354  const clang::CXXRecordDecl* fieldRecDecl = memNonPtrType->getAsCXXRecordDecl();
2355  if (fieldRecDecl) {
2356  // nested objects get an extra call to InspectMember
2357  // R__insp.InspectMember("FileStat_t", (void*)&fFileStat, "fFileStat.", false);
2358  std::string sFieldRecName;
2359  if (!ROOT::TMetaUtils::ExtractAttrPropertyFromName(*fieldRecDecl,"iotype",sFieldRecName)){
2361  clang::QualType(memNonPtrType,0),
2362  *fInterpreter,
2363  *fNormalizedCtxt);
2364  }
2365 
2366  TDataMember* mbr = cl->GetDataMember(ioname.c_str());
2367  // if we can not find the member (which should not really happen),
2368  // let's consider it transient.
2369  Bool_t transient = isTransient || !mbr || !mbr->IsPersistent();
2370 
2371  insp.InspectMember(sFieldRecName.c_str(), cobj + fieldOffset,
2372  (fieldName + '.').c_str(), transient);
2373 
2374  }
2375  }
2376  } // loop over fields
2377 
2378  // inspect bases
2379  // TNamed::ShowMembers(R__insp);
2380  unsigned iNBase = 0;
2381  for (clang::CXXRecordDecl::base_class_const_iterator iBase
2382  = recordDecl->bases_begin(), eBase = recordDecl->bases_end();
2383  iBase != eBase; ++iBase, ++iNBase) {
2384  clang::QualType baseQT = iBase->getType();
2385  if (baseQT.isNull()) {
2386  Error("InspectMembers",
2387  "Cannot find QualType for base number %d while inspecting class %s",
2388  iNBase, clname);
2389  continue;
2390  }
2391  const clang::CXXRecordDecl* baseDecl
2392  = baseQT->getAsCXXRecordDecl();
2393  if (!baseDecl) {
2394  Error("InspectMembers",
2395  "Cannot find CXXRecordDecl for base number %d while inspecting class %s",
2396  iNBase, clname);
2397  continue;
2398  }
2399  TClass* baseCl=nullptr;
2400  std::string sBaseName;
2401  // Try with the DeclId
2402  std::vector<TClass*> foundClasses;
2403  TClass::GetClass(static_cast<DeclId_t>(baseDecl), foundClasses);
2404  if (foundClasses.size()==1){
2405  baseCl=foundClasses[0];
2406  } else {
2407  // Try with the normalised Name, as a fallback
2408  if (!baseCl){
2410  baseQT,
2411  *fInterpreter,
2412  *fNormalizedCtxt);
2413  baseCl = TClass::GetClass(sBaseName.c_str());
2414  }
2415  }
2416 
2417  if (!baseCl){
2418  std::string qualNameForDiag;
2419  ROOT::TMetaUtils::GetQualifiedName(qualNameForDiag, *baseDecl);
2420  Error("InspectMembers",
2421  "Cannot find TClass for base class %s", qualNameForDiag.c_str() );
2422  continue;
2423  }
2424 
2425  int64_t baseOffset;
2426  if (iBase->isVirtual()) {
2428  if (!isTransient) {
2429  Error("InspectMembers",
2430  "Base %s of class %s is virtual but no object provided",
2431  sBaseName.c_str(), clname);
2432  }
2434  } else {
2435  // We have an object to determine the vbase offset.
2437  TClingClassInfo* baseCi = (TClingClassInfo*)baseCl->GetClassInfo();
2438  if (ci && baseCi) {
2439  baseOffset = ci->GetBaseOffset(baseCi, const_cast<void*>(obj),
2440  true /*isDerivedObj*/);
2441  if (baseOffset == -1) {
2442  Error("InspectMembers",
2443  "Error calculating offset of virtual base %s of class %s",
2444  sBaseName.c_str(), clname);
2445  }
2446  } else {
2447  Error("InspectMembers",
2448  "Cannot calculate offset of virtual base %s of class %s",
2449  sBaseName.c_str(), clname);
2450  continue;
2451  }
2452  }
2453  } else {
2454  baseOffset = recLayout.getBaseClassOffset(baseDecl).getQuantity();
2455  }
2456  // TOFIX: baseCl can be null here!
2457  if (baseCl->IsLoaded()) {
2458  // For loaded class, CallShowMember will (especially for TObject)
2459  // call the virtual ShowMember rather than the class specific version
2460  // resulting in an infinite recursion.
2461  InspectMembers(insp, cobj + baseOffset, baseCl, isTransient);
2462  } else {
2463  baseCl->CallShowMembers(cobj + baseOffset,
2464  insp, isTransient);
2465  }
2466  } // loop over bases
2467 }
2468 
2469 ////////////////////////////////////////////////////////////////////////////////
2470 /// Reset the interpreter internal state in case a previous action was not correctly
2471 /// terminated.
2472 
2474 {
2475  // No-op there is not equivalent state (to be cleared) in Cling.
2476 }
2477 
2478 ////////////////////////////////////////////////////////////////////////////////
2479 /// Delete existing temporary values.
2480 
2482 {
2483  // No-op for cling due to cling::Value.
2484 }
2485 
2486 ////////////////////////////////////////////////////////////////////////////////
2487 /// Declare code to the interpreter, without any of the interpreter actions
2488 /// that could trigger a re-interpretation of the code. I.e. make cling
2489 /// behave like a compiler: no dynamic lookup, no input wrapping for
2490 /// subsequent execution, no automatic provision of declarations but just a
2491 /// plain #include.
2492 /// Returns true on success, false on failure.
2493 
2494 bool TCling::Declare(const char* code)
2495 {
2497 
2498  int oldload = SetClassAutoloading(0);
2499  SuspendAutoParsing autoParseRaii(this);
2500 
2501  bool oldDynLookup = fInterpreter->isDynamicLookupEnabled();
2502  fInterpreter->enableDynamicLookup(false);
2503  bool oldRawInput = fInterpreter->isRawInputEnabled();
2504  fInterpreter->enableRawInput(true);
2505 
2506  Bool_t ret = LoadText(code);
2507 
2508  fInterpreter->enableRawInput(oldRawInput);
2509  fInterpreter->enableDynamicLookup(oldDynLookup);
2510  SetClassAutoloading(oldload);
2511  return ret;
2512 }
2513 
2514 ////////////////////////////////////////////////////////////////////////////////
2515 /// Enable the automatic loading of shared libraries when a class
2516 /// is used that is stored in a not yet loaded library. Uses the
2517 /// information stored in the class/library map (typically
2518 /// $ROOTSYS/etc/system.rootmap).
2519 
2521 {
2522  if (fAllowLibLoad) {
2523  LoadLibraryMap();
2524  SetClassAutoloading(true);
2525  }
2526 }
2527 
2528 ////////////////////////////////////////////////////////////////////////////////
2529 /// It calls a "fantom" method to synchronize user keyboard input
2530 /// and ROOT prompt line.
2531 
2533 {
2535 }
2536 
2537 ////////////////////////////////////////////////////////////////////////////////
2538 /// Return true if the file has already been loaded by cint.
2539 /// We will try in this order:
2540 /// actual filename
2541 /// filename as a path relative to
2542 /// the include path
2543 /// the shared library path
2544 
2545 Bool_t TCling::IsLoaded(const char* filename) const
2546 {
2548 
2549  //FIXME: if we use llvm::sys::fs::make_absolute all this can go away. See
2550  // cling::DynamicLibraryManager.
2551 
2552  std::string file_name = filename;
2553  size_t at = std::string::npos;
2554  while ((at = file_name.find("/./")) != std::string::npos)
2555  file_name.replace(at, 3, "/");
2556 
2557  std::string filesStr = "";
2558  llvm::raw_string_ostream filesOS(filesStr);
2559  clang::SourceManager &SM = fInterpreter->getCI()->getSourceManager();
2560  cling::ClangInternalState::printIncludedFiles(filesOS, SM);
2561  filesOS.flush();
2562 
2563  llvm::SmallVector<llvm::StringRef, 100> files;
2564  llvm::StringRef(filesStr).split(files, "\n");
2565 
2566  std::set<std::string> fileMap;
2567  // Fill fileMap; return early on exact match.
2568  for (llvm::SmallVector<llvm::StringRef, 100>::const_iterator
2569  iF = files.begin(), iE = files.end(); iF != iE; ++iF) {
2570  if ((*iF) == file_name.c_str()) return kTRUE; // exact match
2571  fileMap.insert(*iF);
2572  }
2573 
2574  if (fileMap.empty()) return kFALSE;
2575 
2576  // Check MacroPath.
2577  TString sFilename(file_name.c_str());
2579  && fileMap.count(sFilename.Data())) {
2580  return kTRUE;
2581  }
2582 
2583  // Check IncludePath.
2584  TString incPath = gSystem->GetIncludePath(); // of the form -Idir1 -Idir2 -Idir3
2585  incPath.Append(":").Prepend(" "); // to match " -I" (note leading ' ')
2586  incPath.ReplaceAll(" -I", ":"); // of form :dir1 :dir2:dir3
2587  while (incPath.Index(" :") != -1) {
2588  incPath.ReplaceAll(" :", ":");
2589  }
2590  incPath.Prepend(".:");
2591  sFilename = file_name.c_str();
2592  if (gSystem->FindFile(incPath, sFilename, kReadPermission)
2593  && fileMap.count(sFilename.Data())) {
2594  return kTRUE;
2595  }
2596 
2597  // Check shared library.
2598  sFilename = file_name.c_str();
2599  const char *found = gSystem->FindDynamicLibrary(sFilename, kTRUE);
2600  cling::DynamicLibraryManager* dyLibManager
2601  = fInterpreter->getDynamicLibraryManager();
2602  if (found) {
2603  if (dyLibManager->isLibraryLoaded(found)) {
2604  return kTRUE;
2605  }
2606  }
2607  //FIXME: We must use the cling::Interpreter::lookupFileOrLibrary iface.
2608  const clang::DirectoryLookup *CurDir = 0;
2609  clang::Preprocessor &PP = fInterpreter->getCI()->getPreprocessor();
2610  clang::HeaderSearch &HS = PP.getHeaderSearchInfo();
2611  const clang::FileEntry *FE = HS.LookupFile(file_name.c_str(),
2612  clang::SourceLocation(),
2613  /*isAngled*/ false,
2614  /*FromDir*/ 0, CurDir,
2615  clang::ArrayRef<std::pair<const clang::FileEntry *,
2616  const clang::DirectoryEntry *>>(),
2617  /*SearchPath*/ 0,
2618  /*RelativePath*/ 0,
2619  /*RequestingModule*/ 0,
2620  /*SuggestedModule*/ 0,
2621  /*SkipCache*/ false,
2622  /*BuildSystemModule*/ false,
2623  /*OpenFile*/ false,
2624  /*CacheFail*/ false);
2625  if (FE && FE->isValid()) {
2626  // check in the source manager if the file is actually loaded
2627  clang::SourceManager &SM = fInterpreter->getCI()->getSourceManager();
2628  // this works only with header (and source) files...
2629  clang::FileID FID = SM.translateFile(FE);
2630  if (!FID.isInvalid() && FID.getHashValue() == 0)
2631  return kFALSE;
2632  else {
2633  clang::SrcMgr::SLocEntry SLocE = SM.getSLocEntry(FID);
2634  if (SLocE.isFile() && SLocE.getFile().getContentCache()->getRawBuffer() == 0)
2635  return kFALSE;
2636  if (!FID.isInvalid())
2637  return kTRUE;
2638  }
2639  // ...then check shared library again, but with full path now
2640  sFilename = FE->getName();
2641  if (gSystem->FindDynamicLibrary(sFilename, kTRUE)
2642  && fileMap.count(sFilename.Data())) {
2643  return kTRUE;
2644  }
2645  }
2646  return kFALSE;
2647 }
2648 
2649 ////////////////////////////////////////////////////////////////////////////////
2650 
2652 {
2653 #if defined(R__WIN32) || defined(__CYGWIN__)
2654  HMODULE hModules[1024];
2655  void *hProcess;
2656  unsigned long cbModules;
2657  unsigned int i;
2658  hProcess = (void *)::GetCurrentProcess();
2659  ::EnumProcessModules(hProcess, hModules, sizeof(hModules), &cbModules);
2660  // start at 1 to skip the executable itself
2661  for (i = 1; i < (cbModules / sizeof(void *)); i++) {
2662  static const int bufsize = 260;
2663  wchar_t winname[bufsize];
2664  char posixname[bufsize];
2665  ::GetModuleFileNameExW(hProcess, hModules[i], winname, bufsize);
2666 #if defined(__CYGWIN__)
2667  cygwin_conv_path(CCP_WIN_W_TO_POSIX, winname, posixname, bufsize);
2668 #else
2669  std::wstring wpath = winname;
2670  std::replace(wpath.begin(), wpath.end(), '\\', '/');
2671  string path(wpath.begin(), wpath.end());
2672  strncpy(posixname, path.c_str(), bufsize);
2673 #endif
2674  if (!fSharedLibs.Contains(posixname)) {
2675  RegisterLoadedSharedLibrary(posixname);
2676  }
2677  }
2678 #elif defined(R__MACOSX)
2679  // fPrevLoadedDynLibInfo stores the *next* image index to look at
2680  uint32_t imageIndex = (uint32_t) (size_t) fPrevLoadedDynLibInfo;
2681  const char* imageName = 0;
2682  while ((imageName = _dyld_get_image_name(imageIndex))) {
2683  // Skip binary
2684  if (imageIndex > 0)
2685  RegisterLoadedSharedLibrary(imageName);
2686  ++imageIndex;
2687  }
2688  fPrevLoadedDynLibInfo = (void*)(size_t)imageIndex;
2689 #elif defined(R__LINUX)
2690  struct PointerNo4_t {
2691  void* fSkip[3];
2692  void* fPtr;
2693  };
2694  struct LinkMap_t {
2695  void* fAddr;
2696  const char* fName;
2697  void* fLd;
2698  LinkMap_t* fNext;
2699  LinkMap_t* fPrev;
2700  };
2701  if (!fPrevLoadedDynLibInfo || fPrevLoadedDynLibInfo == (void*)(size_t)-1) {
2702  PointerNo4_t* procLinkMap = (PointerNo4_t*)dlopen(0, RTLD_LAZY | RTLD_GLOBAL);
2703  // 4th pointer of 4th pointer is the linkmap.
2704  // See http://syprog.blogspot.fr/2011/12/listing-loaded-shared-objects-in-linux.html
2705  LinkMap_t* linkMap = (LinkMap_t*) ((PointerNo4_t*)procLinkMap->fPtr)->fPtr;
2706  RegisterLoadedSharedLibrary(linkMap->fName);
2707  fPrevLoadedDynLibInfo = linkMap;
2708  // reduce use count of link map structure:
2709  dlclose(procLinkMap);
2710  }
2711 
2712  LinkMap_t* iDyLib = (LinkMap_t*)fPrevLoadedDynLibInfo;
2713  while (iDyLib->fNext) {
2714  iDyLib = iDyLib->fNext;
2715  RegisterLoadedSharedLibrary(iDyLib->fName);
2716  }
2717  fPrevLoadedDynLibInfo = iDyLib;
2718 #else
2719  Error("TCling::UpdateListOfLoadedSharedLibraries",
2720  "Platform not supported!");
2721 #endif
2722 }
2723 
2724 ////////////////////////////////////////////////////////////////////////////////
2725 /// Register a new shared library name with the interpreter; add it to
2726 /// fSharedLibs.
2727 
2728 void TCling::RegisterLoadedSharedLibrary(const char* filename)
2729 {
2730  // Ignore NULL filenames, aka "the process".
2731  if (!filename) return;
2732 
2733  // Tell the interpreter that this library is available; all libraries can be
2734  // used to resolve symbols.
2735  cling::DynamicLibraryManager* DLM = fInterpreter->getDynamicLibraryManager();
2736  if (!DLM->isLibraryLoaded(filename)) {
2737  DLM->loadLibrary(filename, true /*permanent*/);
2738  }
2739 
2740 #if defined(R__MACOSX)
2741  // Check that this is not a system library
2742  if (!strncmp(filename, "/usr/lib/system/", 16)
2743  || !strncmp(filename, "/usr/lib/libc++", 15)
2744  || !strncmp(filename, "/System/Library/Frameworks/", 27)
2745  || !strncmp(filename, "/System/Library/PrivateFrameworks/", 34)
2746  || !strncmp(filename, "/System/Library/CoreServices/", 29)
2747  || !strcmp(filename, "cl_kernels") // yepp, no directory
2748  || strstr(filename, "/usr/lib/libSystem")
2749  || strstr(filename, "/usr/lib/libstdc++")
2750  || strstr(filename, "/usr/lib/libicucore")
2751  || strstr(filename, "/usr/lib/libbsm")
2752  || strstr(filename, "/usr/lib/libobjc")
2753  || strstr(filename, "/usr/lib/libresolv")
2754  || strstr(filename, "/usr/lib/libauto")
2755  || strstr(filename, "/usr/lib/libcups")
2756  || strstr(filename, "/usr/lib/libDiagnosticMessagesClient")
2757  || strstr(filename, "/usr/lib/liblangid")
2758  || strstr(filename, "/usr/lib/libCRFSuite")
2759  || strstr(filename, "/usr/lib/libpam")
2760  || strstr(filename, "/usr/lib/libOpenScriptingUtil")
2761  || strstr(filename, "/usr/lib/libextension"))
2762  return;
2763 #elif defined(__CYGWIN__)
2764  // Check that this is not a system library
2765  static const int bufsize = 260;
2766  char posixwindir[bufsize];
2767  char *windir = getenv("WINDIR");
2768  if (windir)
2769  cygwin_conv_path(CCP_WIN_A_TO_POSIX, windir, posixwindir, bufsize);
2770  else
2771  snprintf(posixwindir, sizeof(posixwindir), "/Windows/");
2772  if (strstr(filename, posixwindir) ||
2773  strstr(filename, "/usr/bin/cyg"))
2774  return;
2775 #elif defined(R__WIN32)
2776  if (strstr(filename, "/Windows/"))
2777  return;
2778 #elif defined (R__LINUX)
2779  if (strstr(filename, "/ld-linux")
2780  || strstr(filename, "linux-gnu/")
2781  || strstr(filename, "/libstdc++.")
2782  || strstr(filename, "/libgcc")
2783  || strstr(filename, "/libc.")
2784  || strstr(filename, "/libdl.")
2785  || strstr(filename, "/libm."))
2786  return;
2787 #endif
2788  // Update string of available libraries.
2789  if (!fSharedLibs.IsNull()) {
2790  fSharedLibs.Append(" ");
2791  }
2792  fSharedLibs.Append(filename);
2793 }
2794 
2795 ////////////////////////////////////////////////////////////////////////////////
2796 /// Load a library file in cling's memory.
2797 /// if 'system' is true, the library is never unloaded.
2798 /// Return 0 on success, -1 on failure.
2799 
2800 Int_t TCling::Load(const char* filename, Bool_t system)
2801 {
2802  if (!fAllowLibLoad) {
2803  Error("Load","Trying to load library (%s) from rootcling.",filename);
2804  return -1;
2805  }
2806 
2807  // Used to return 0 on success, 1 on duplicate, -1 on failure, -2 on "fatal".
2809  cling::DynamicLibraryManager* DLM = fInterpreter->getDynamicLibraryManager();
2810  std::string canonLib = DLM->lookupLibrary(filename);
2811  cling::DynamicLibraryManager::LoadLibResult res
2812  = cling::DynamicLibraryManager::kLoadLibNotFound;
2813  if (!canonLib.empty()) {
2814  if (system)
2815  res = DLM->loadLibrary(filename, system);
2816  else {
2817  // For the non system libs, we'd like to be able to unload them.
2818  // FIXME: Here we lose the information about kLoadLibAlreadyLoaded case.
2819  cling::Interpreter::CompilationResult compRes;
2820  cling::MetaProcessor::MaybeRedirectOutputRAII RAII(fMetaProcessor);
2821  HandleInterpreterException(fMetaProcessor, Form(".L %s", canonLib.c_str()), compRes, /*cling::Value*/0);
2822  if (compRes == cling::Interpreter::kSuccess)
2823  res = cling::DynamicLibraryManager::kLoadLibSuccess;
2824  }
2825  }
2826 
2827  if (res == cling::DynamicLibraryManager::kLoadLibSuccess) {
2829  }
2830  switch (res) {
2831  case cling::DynamicLibraryManager::kLoadLibSuccess: return 0;
2832  case cling::DynamicLibraryManager::kLoadLibAlreadyLoaded: return 1;
2833  default: break;
2834  };
2835  return -1;
2836 }
2837 
2838 ////////////////////////////////////////////////////////////////////////////////
2839 /// Load a macro file in cling's memory.
2840 
2841 void TCling::LoadMacro(const char* filename, EErrorCode* error)
2842 {
2843  ProcessLine(Form(".L %s", filename), error);
2844 }
2845 
2846 ////////////////////////////////////////////////////////////////////////////////
2847 /// Let cling process a command line asynch.
2848 
2850 {
2851  return ProcessLine(line, error);
2852 }
2853 
2854 ////////////////////////////////////////////////////////////////////////////////
2855 /// Let cling process a command line synchronously, i.e we are waiting
2856 /// it will be finished.
2857 
2859 {
2861  if (gApplication) {
2862  if (gApplication->IsCmdThread()) {
2863  return ProcessLine(line, error);
2864  }
2865  return 0;
2866  }
2867  return ProcessLine(line, error);
2868 }
2869 
2870 ////////////////////////////////////////////////////////////////////////////////
2871 /// Directly execute an executable statement (e.g. "func()", "3+5", etc.
2872 /// however not declarations, like "Int_t x;").
2873 
2874 Long_t TCling::Calc(const char* line, EErrorCode* error)
2875 {
2876 #ifdef R__WIN32
2877  // Test on ApplicationImp not being 0 is needed because only at end of
2878  // TApplication ctor the IsLineProcessing flag is set to 0, so before
2879  // we can not use it.
2881  while (gROOT->IsLineProcessing() && !gApplication) {
2882  Warning("Calc", "waiting for cling thread to free");
2883  gSystem->Sleep(500);
2884  }
2885  gROOT->SetLineIsProcessing();
2886  }
2887 #endif // R__WIN32
2889  if (error) {
2890  *error = TInterpreter::kNoError;
2891  }
2892  cling::Value valRef;
2893  cling::Interpreter::CompilationResult cr = fInterpreter->evaluate(line, valRef);
2894  if (cr != cling::Interpreter::kSuccess) {
2895  // Failure in compilation.
2896  if (error) {
2897  // Note: Yes these codes are weird.
2898  *error = TInterpreter::kRecoverable;
2899  }
2900  return 0L;
2901  }
2902  if (!valRef.isValid()) {
2903  // Failure at runtime.
2904  if (error) {
2905  // Note: Yes these codes are weird.
2906  *error = TInterpreter::kDangerous;
2907  }
2908  return 0L;
2909  }
2910 
2911  if (valRef.isVoid()) {
2912  return 0;
2913  }
2914 
2915  RegisterTemporary(valRef);
2916 #ifdef R__WIN32
2918  gROOT->SetLineHasBeenProcessed();
2919  }
2920 #endif // R__WIN32
2921  return valRef.simplisticCastAs<long>();
2922 }
2923 
2924 ////////////////////////////////////////////////////////////////////////////////
2925 /// Set a getline function to call when input is needed.
2926 
2927 void TCling::SetGetline(const char * (*getlineFunc)(const char* prompt),
2928  void (*histaddFunc)(const char* line))
2929 {
2930  // If cling offers a replacement for G__pause(), it would need to
2931  // also offer a way to customize at least the history recording.
2932 
2933 #if defined(R__MUST_REVISIT)
2934 #if R__MUST_REVISIT(6,2)
2935  Warning("SetGetline","Cling should support the equivalent of SetGetlineFunc(getlineFunc, histaddFunc)");
2936 #endif
2937 #endif
2938 }
2939 
2940 ////////////////////////////////////////////////////////////////////////////////
2941 /// Helper function to increase the internal Cling count of transactions
2942 /// that change the AST.
2943 
2944 Bool_t TCling::HandleNewTransaction(const cling::Transaction &T)
2945 {
2947 
2948  if ((std::distance(T.decls_begin(), T.decls_end()) != 1)
2949  || T.deserialized_decls_begin() != T.deserialized_decls_end()
2950  || T.macros_begin() != T.macros_end()
2951  || ((!T.getFirstDecl().isNull()) && ((*T.getFirstDecl().begin()) != T.getWrapperFD()))) {
2953  return true;
2954  }
2955  return false;
2956 }
2957 
2958 ////////////////////////////////////////////////////////////////////////////////
2959 /// Delete object from cling symbol table so it can not be used anymore.
2960 /// cling objects are always on the heap.
2961 
2963 {
2965  // Note that fgSetOfSpecials is supposed to be updated by TClingCallbacks::tryFindROOTSpecialInternal
2966  // (but isn't at the moment).
2967  if (obj->IsOnHeap() && fgSetOfSpecials && !((std::set<TObject*>*)fgSetOfSpecials)->empty()) {
2968  std::set<TObject*>::iterator iSpecial = ((std::set<TObject*>*)fgSetOfSpecials)->find(obj);
2969  if (iSpecial != ((std::set<TObject*>*)fgSetOfSpecials)->end()) {
2970  DeleteGlobal(obj);
2971  ((std::set<TObject*>*)fgSetOfSpecials)->erase(iSpecial);
2972  }
2973  }
2974 }
2975 
2976 ////////////////////////////////////////////////////////////////////////////////
2977 /// Pressing Ctrl+C should forward here. In the case where we have had
2978 /// continuation requested we must reset it.
2979 
2981 {
2982  fMetaProcessor->cancelContinuation();
2983  // Reset the Cling state to the state saved by the last call to
2984  // TCling::SaveContext().
2985 #if defined(R__MUST_REVISIT)
2986 #if R__MUST_REVISIT(6,2)
2988  Warning("Reset","Cling should support the equivalent of scratch_upto(&fDictPos)");
2989 #endif
2990 #endif
2991 }
2992 
2993 ////////////////////////////////////////////////////////////////////////////////
2994 /// Reset the Cling state to its initial state.
2995 
2997 {
2998 #if defined(R__MUST_REVISIT)
2999 #if R__MUST_REVISIT(6,2)
3001  Warning("ResetAll","Cling should support the equivalent of complete reset (unload everything but the startup decls.");
3002 #endif
3003 #endif
3004 }
3005 
3006 ////////////////////////////////////////////////////////////////////////////////
3007 /// Reset in Cling the list of global variables to the state saved by the last
3008 /// call to TCling::SaveGlobalsContext().
3009 ///
3010 /// Note: Right now, all we do is run the global destructors.
3011 
3013 {
3015  // TODO:
3016  // Here we should iterate over the transactions (N-3) and revert.
3017  // N-3 because the first three internal to cling.
3018 
3019  fInterpreter->runAndRemoveStaticDestructors();
3020 }
3021 
3022 ////////////////////////////////////////////////////////////////////////////////
3023 /// Reset the Cling 'user' global objects/variables state to the state saved by the last
3024 /// call to TCling::SaveGlobalsContext().
3025 
3026 void TCling::ResetGlobalVar(void* obj)
3027 {
3028 #if defined(R__MUST_REVISIT)
3029 #if R__MUST_REVISIT(6,2)
3031  Warning("ResetGlobalVar","Cling should support the equivalent of resetglobalvar(obj)");
3032 #endif
3033 #endif
3034 }
3035 
3036 ////////////////////////////////////////////////////////////////////////////////
3037 /// Rewind Cling dictionary to the point where it was before executing
3038 /// the current macro. This function is typically called after SEGV or
3039 /// ctlr-C after doing a longjmp back to the prompt.
3040 
3042 {
3043 #if defined(R__MUST_REVISIT)
3044 #if R__MUST_REVISIT(6,2)
3046  Warning("RewindDictionary","Cling should provide a way to revert transaction similar to rewinddictionary()");
3047 #endif
3048 #endif
3049 }
3050 
3051 ////////////////////////////////////////////////////////////////////////////////
3052 /// Delete obj from Cling symbol table so it cannot be accessed anymore.
3053 /// Returns 1 in case of success and 0 in case object was not in table.
3054 
3056 {
3057 #if defined(R__MUST_REVISIT)
3058 #if R__MUST_REVISIT(6,2)
3060  Warning("DeleteGlobal","Cling should provide the equivalent of deleteglobal(obj), see also DeleteVariable.");
3061 #endif
3062 #endif
3063  return 0;
3064 }
3065 
3066 ////////////////////////////////////////////////////////////////////////////////
3067 /// Undeclare obj called name.
3068 /// Returns 1 in case of success, 0 for failure.
3069 
3071 {
3072 #if defined(R__MUST_REVISIT)
3073 #if R__MUST_REVISIT(6,2)
3074  Warning("DeleteVariable","should do more that just reseting the value to zero");
3075 #endif
3076 #endif
3077 
3079  llvm::StringRef srName(name);
3080  const char* unscopedName = name;
3081  llvm::StringRef::size_type posScope = srName.rfind("::");
3082  const clang::DeclContext* declCtx = 0;
3083  if (posScope != llvm::StringRef::npos) {
3084  const cling::LookupHelper& lh = fInterpreter->getLookupHelper();
3085  const clang::Decl* scopeDecl
3086  = lh.findScope(srName.substr(0, posScope),
3087  cling::LookupHelper::WithDiagnostics);
3088  if (!scopeDecl) {
3089  Error("DeleteVariable", "Cannot find enclosing scope for variable %s",
3090  name);
3091  return 0;
3092  }
3093  declCtx = llvm::dyn_cast<clang::DeclContext>(scopeDecl);
3094  if (!declCtx) {
3095  Error("DeleteVariable",
3096  "Enclosing scope for variable %s is not a declaration context",
3097  name);
3098  return 0;
3099  }
3100  unscopedName += posScope + 2;
3101  }
3102  clang::NamedDecl* nVarDecl
3103  = cling::utils::Lookup::Named(&fInterpreter->getSema(), unscopedName, declCtx);
3104  if (!nVarDecl) {
3105  Error("DeleteVariable", "Unknown variable %s", name);
3106  return 0;
3107  }
3108  clang::VarDecl* varDecl = llvm::dyn_cast<clang::VarDecl>(nVarDecl);
3109  if (!varDecl) {
3110  Error("DeleteVariable", "Entity %s is not a variable", name);
3111  return 0;
3112  }
3113 
3114  clang::QualType qType = varDecl->getType();
3115  const clang::Type* type = qType->getUnqualifiedDesugaredType();
3116  // Cannot set a reference's address to nullptr; the JIT can place it
3117  // into read-only memory (ROOT-7100).
3118  if (type->isPointerType()) {
3119  int** ppInt = (int**)fInterpreter->getAddressOfGlobal(GlobalDecl(varDecl));
3120  // set pointer to invalid.
3121  if (ppInt) *ppInt = 0;
3122  }
3123  return 1;
3124 }
3125 
3126 ////////////////////////////////////////////////////////////////////////////////
3127 /// Save the current Cling state.
3128 
3130 {
3131 #if defined(R__MUST_REVISIT)
3132 #if R__MUST_REVISIT(6,2)
3134  Warning("SaveContext","Cling should provide a way to record a state watermark similar to store_dictposition(&fDictPos)");
3135 #endif
3136 #endif
3137 }
3138 
3139 ////////////////////////////////////////////////////////////////////////////////
3140 /// Save the current Cling state of global objects.
3141 
3143 {
3144 #if defined(R__MUST_REVISIT)
3145 #if R__MUST_REVISIT(6,2)
3147  Warning("SaveGlobalsContext","Cling should provide a way to record a watermark for the list of global variable similar to store_dictposition(&fDictPosGlobals)");
3148 #endif
3149 #endif
3150 }
3151 
3152 ////////////////////////////////////////////////////////////////////////////////
3153 /// No op: see TClingCallbacks (used to update the list of globals)
3154 
3156 {
3157 }
3158 
3159 ////////////////////////////////////////////////////////////////////////////////
3160 /// No op: see TClingCallbacks (used to update the list of global functions)
3161 
3163 {
3164 }
3165 
3166 ////////////////////////////////////////////////////////////////////////////////
3167 /// No op: see TClingCallbacks (used to update the list of types)
3168 
3170 {
3171 }
3172 
3173 ////////////////////////////////////////////////////////////////////////////////
3174 /// Check in what order the member of a tuple are layout.
3175 enum class ETupleOrdering {
3176  kAscending,
3177  kDescending,
3178  kUnexpected
3179 };
3180 
3181 struct AlternateTupleIntDoubleAsc
3182 {
3183  Int_t _0;
3184  Double_t _1;
3185 };
3186 
3187 struct AlternateTupleIntDoubleDes
3188 {
3189  Double_t _1;
3190  Int_t _0;
3191 };
3192 
3194 {
3195  std::tuple<int,double> value;
3196  AlternateTupleIntDoubleAsc asc;
3197  AlternateTupleIntDoubleDes des;
3198 
3199  size_t offset0 = ((char*)&(std::get<0>(value))) - ((char*)&value);
3200  size_t offset1 = ((char*)&(std::get<1>(value))) - ((char*)&value);
3201 
3202  size_t ascOffset0 = ((char*)&(asc._0)) - ((char*)&asc);
3203  size_t ascOffset1 = ((char*)&(asc._1)) - ((char*)&asc);
3204 
3205  size_t desOffset0 = ((char*)&(des._0)) - ((char*)&des);
3206  size_t desOffset1 = ((char*)&(des._1)) - ((char*)&des);
3207 
3208  if (offset0 == ascOffset0 && offset1 == ascOffset1) {
3210  } else if (offset0 == desOffset0 && offset1 == desOffset1) {
3212  } else {
3214  }
3215 }
3216 
3217 std::string AtlernateTuple(const char *classname)
3218 {
3219  TClassEdit::TSplitType tupleContent(classname);
3220  std::string alternateName = "TEmulatedTuple";
3221  alternateName.append( classname + 5 );
3222 
3223  std::string guard_name;
3224  ROOT::TMetaUtils::GetCppName(guard_name,alternateName.c_str());
3225  std::ostringstream guard;
3226  guard << "ROOT_INTERNAL_TEmulated_";
3227  guard << guard_name;
3228 
3229  std::ostringstream alternateTuple;
3230  alternateTuple << "#ifndef " << guard.str() << "\n";
3231  alternateTuple << "#define " << guard.str() << "\n";
3232  alternateTuple << "namespace ROOT { namespace Internal {\n";
3233  alternateTuple << "template <class... Types> struct TEmulatedTuple;\n";
3234  alternateTuple << "template <> struct " << alternateName << " {\n";
3235 
3236  // This could also be a compile time choice ...
3237  switch(IsTupleAscending()) {
3239  unsigned int nMember = 0;
3240  auto iter = tupleContent.fElements.begin() + 1; // Skip the template name (tuple)
3241  auto theEnd = tupleContent.fElements.end() - 1; // skip the 'stars'.
3242  while (iter != theEnd) {
3243  alternateTuple << " " << *iter << " _" << nMember << ";\n";
3244  ++iter;
3245  ++nMember;
3246  }
3247  break;
3248  }
3250  unsigned int nMember = tupleContent.fElements.size() - 3;
3251  auto iter = tupleContent.fElements.rbegin() + 1; // Skip the template name (tuple)
3252  auto theEnd = tupleContent.fElements.rend() - 1; // skip the 'stars'.
3253  while (iter != theEnd) {
3254  alternateTuple << " " << *iter << " _" << nMember << ";\n";
3255  ++iter;
3256  --nMember;
3257  }
3258  break;
3259  }
3261  Fatal("TCling::SetClassInfo::AtlernateTuple",
3262  "Layout of std::tuple on this platform is unexpected.");
3263  break;
3264  }
3265  }
3266 
3267  alternateTuple << "};\n";
3268  alternateTuple << "}}\n";
3269  alternateTuple << "#endif\n";
3270  if (!gCling->Declare(alternateTuple.str().c_str())) {
3271  Error("Load","Could not declare %s",alternateName.c_str());
3272  return "";
3273  }
3274  alternateName = "ROOT::Internal::" + alternateName;
3275  return alternateName;
3276 }
3277 
3278 ////////////////////////////////////////////////////////////////////////////////
3279 /// Set pointer to the TClingClassInfo in TClass.
3280 /// If 'reload' is true, (attempt to) generate a new ClassInfo even if we
3281 /// already have one.
3282 
3284 {
3286  if (cl->fClassInfo && !reload) {
3287  return;
3288  }
3289  //Remove the decl_id from the DeclIdToTClass map
3290  TClingClassInfo* TClinginfo = (TClingClassInfo*) cl->fClassInfo;
3291  if (TClinginfo) {
3292  TClass::RemoveClassDeclId(TClinginfo->GetDeclId());
3293  }
3294  delete TClinginfo;
3295  cl->fClassInfo = 0;
3296  std::string name(cl->GetName());
3297 
3298  // Handle the special case of 'tuple' where we ignore the real implementation
3299  // details and just overlay a 'simpler'/'simplistic' version that is easy
3300  // for the I/O to understand and handle.
3301  if (strncmp(cl->GetName(),"tuple<",strlen("tuple<"))==0) {
3302 
3303  name = AtlernateTuple(cl->GetName());
3304 
3305  }
3306 
3307  TClingClassInfo* info = new TClingClassInfo(fInterpreter, name.c_str());
3308  if (!info->IsValid()) {
3309  if (cl->fState != TClass::kHasTClassInit) {
3310  if (cl->fStreamerInfo->GetEntries() != 0) {
3311  cl->fState = TClass::kEmulated;
3312  } else {
3314  }
3315  }
3316  delete info;
3317  return;
3318  }
3319  cl->fClassInfo = (ClassInfo_t*)info; // Note: We are transferring ownership here.
3320  // In case a class contains an external enum, the enum will be seen as a
3321  // class. We must detect this special case and make the class a Zombie.
3322  // Here we assume that a class has at least one method.
3323  // We can NOT call TClass::Property from here, because this method
3324  // assumes that the TClass is well formed to do a lot of information
3325  // caching. The method SetClassInfo (i.e. here) is usually called during
3326  // the building phase of the TClass, hence it is NOT well formed yet.
3327  Bool_t zombieCandidate = kFALSE;
3328  if (
3329  info->IsValid() &&
3330  !(info->Property() & (kIsClass | kIsStruct | kIsNamespace))
3331  ) {
3332  zombieCandidate = kTRUE;
3333  }
3334  if (!info->IsLoaded()) {
3335  if (info->Property() & (kIsNamespace)) {
3336  // Namespaces can have info but no corresponding CINT dictionary
3337  // because they are auto-created if one of their contained
3338  // classes has a dictionary.
3339  zombieCandidate = kTRUE;
3340  }
3341  // this happens when no dictionary is available
3342  delete info;
3343  cl->fClassInfo = 0;
3344  }
3345  if (zombieCandidate && !cl->GetCollectionType()) {
3346  cl->MakeZombie();
3347  }
3348  // If we reach here, the info was valid (See early returns).
3349  if (cl->fState != TClass::kHasTClassInit) {
3350  if (cl->fClassInfo) {
3353  } else {
3354 // if (TClassEdit::IsSTLCont(cl->GetName()) {
3355 // There will be an emulated collection proxy, is that the same?
3356 // cl->fState = TClass::kEmulated;
3357 // } else {
3358  if (cl->fStreamerInfo->GetEntries() != 0) {
3359  cl->fState = TClass::kEmulated;
3360  } else {
3362  }
3363 // }
3364  }
3365  }
3366  if (cl->fClassInfo) {
3367  TClass::AddClassToDeclIdMap(((TClingClassInfo*)cl->fClassInfo)->GetDeclId(), cl);
3368  }
3369 }
3370 
3371 ////////////////////////////////////////////////////////////////////////////////
3372 /// Checks if an entity with the specified name is defined in Cling.
3373 /// Returns kFALSE if the entity is not defined.
3374 /// By default, structs, namespaces, classes, enums and unions are looked for.
3375 /// If the flag isClassOrNamespaceOnly is true, classes, structs and
3376 /// namespaces only are considered. I.e. if the name is an enum or a union,
3377 /// the returned value is false.
3378 ///
3379 /// In the case where the class is not loaded and belongs to a namespace
3380 /// or is nested, looking for the full class name is outputting a lots of
3381 /// (expected) error messages. Currently the only way to avoid this is to
3382 /// specifically check that each level of nesting is already loaded.
3383 /// In case of templates the idea is that everything between the outer
3384 /// '<' and '>' has to be skipped, e.g.: aap<pippo<noot>::klaas>::a_class
3385 
3386 Bool_t TCling::CheckClassInfo(const char* name, Bool_t autoload, Bool_t isClassOrNamespaceOnly /* = kFALSE*/ )
3387 {
3389  static const char *anonEnum = "anonymous enum ";
3390  static const int cmplen = strlen(anonEnum);
3391 
3392  if (0 == strncmp(name,anonEnum,cmplen)) {
3393  return kFALSE;
3394  }
3395 
3396  // Avoid the double search below in case the name is a fundamental type
3397  // or typedef to a fundamental type.
3398  THashTable *typeTable = dynamic_cast<THashTable*>( gROOT->GetListOfTypes() );
3399  TDataType *fundType = (TDataType *)typeTable->THashTable::FindObject( name );
3400 
3401  if (fundType && fundType->GetType() < TVirtualStreamerInfo::kObject
3402  && fundType->GetType() > 0) {
3403  // Fundamental type, no a class.
3404  return kFALSE;
3405  }
3406 
3407  // Migrated from within TClass::GetClass
3408  // If we want to know if a class or a namespace with this name exists in the
3409  // interpreter and this is an enum in the type system, before or after loading
3410  // according to the autoload function argument, return false.
3411  if (isClassOrNamespaceOnly &&
3412  TEnum::GetEnum(name, autoload ? TEnum::kAutoload : TEnum::kNone)) return false;
3413 
3414  const char *classname = name;
3415 
3416  int storeAutoload = SetClassAutoloading(autoload);
3417 
3418  // First we want to check whether the decl exist, but _without_
3419  // generating any template instantiation. However, the lookup
3420  // still will create a forward declaration of the class template instance
3421  // if it exist. In this case, the return value of findScope will still
3422  // be zero but the type will be initialized.
3423  // Note in the corresponding code in ROOT 5, CINT was not instantiating
3424  // this forward declaration.
3425  const cling::LookupHelper& lh = fInterpreter->getLookupHelper();
3426  const clang::Type *type = 0;
3427  const clang::Decl *decl
3428  = lh.findScope(classname,
3429  gDebug > 5 ? cling::LookupHelper::WithDiagnostics
3430  : cling::LookupHelper::NoDiagnostics,
3431  &type, /* intantiateTemplate= */ false );
3432  if (!decl) {
3433  std::string buf = TClassEdit::InsertStd(classname);
3434  decl = lh.findScope(buf,
3435  gDebug > 5 ? cling::LookupHelper::WithDiagnostics
3436  : cling::LookupHelper::NoDiagnostics,
3437  &type,false);
3438  }
3439 
3440  if (type) {
3441  // If decl==0 and the type is valid, then we have a forward declaration.
3442  if (!decl) {
3443  // If we have a forward declaration for a class template instantiation,
3444  // we want to ignore it if it was produced/induced by the call to
3445  // findScope, however we can not distinguish those from the
3446  // instantiation induce by 'soft' use (and thus also induce by the
3447  // same underlying code paths)
3448  // ['soft' use = use not requiring a complete definition]
3449  // So to reduce the amount of disruption to the existing code we
3450  // would just ignore those for STL collection, for which we really
3451  // need to have the compiled collection proxy (and thus the TClass
3452  // bootstrap).
3453  clang::ClassTemplateSpecializationDecl *tmpltDecl =
3454  llvm::dyn_cast_or_null<clang::ClassTemplateSpecializationDecl>
3455  (type->getAsCXXRecordDecl());
3456  if (tmpltDecl && !tmpltDecl->getPointOfInstantiation().isValid()) {
3457  // Since the point of instantiation is invalid, we 'guess' that
3458  // the 'instantiation' of the forwarded type appended in
3459  // findscope.
3460  if (ROOT::TMetaUtils::IsSTLCont(*tmpltDecl)) {
3461  // For STL Collection we return false.
3462  SetClassAutoloading(storeAutoload);
3463  return kFALSE;
3464  }
3465  }
3466  }
3467  TClingClassInfo tci(fInterpreter, *type);
3468  if (!tci.IsValid()) {
3469  SetClassAutoloading(storeAutoload);
3470  return kFALSE;
3471  }
3472  auto propertiesMask = isClassOrNamespaceOnly ? kIsClass | kIsStruct | kIsNamespace :
3474 
3475  if (tci.Property() & propertiesMask) {
3476  // We are now sure that the entry is not in fact an autoload entry.
3477  SetClassAutoloading(storeAutoload);
3478  return kTRUE;
3479  }
3480  }
3481 
3482  SetClassAutoloading(storeAutoload);
3483  return (decl);
3484 
3485  // Setting up iterator part of TClingTypedefInfo is too slow.
3486  // Copy the lookup code instead:
3487  /*
3488  TClingTypedefInfo t(fInterpreter, name);
3489  if (t.IsValid() && !(t.Property() & kIsFundamental)) {
3490  delete[] classname;
3491  SetClassAutoloading(storeAutoload);
3492  return kTRUE;
3493  }
3494  */
3495 
3496 // const clang::Decl *decl = lh.findScope(name);
3497 // if (!decl) {
3498 // std::string buf = TClassEdit::InsertStd(name);
3499 // decl = lh.findScope(buf);
3500 // }
3501 
3502 // SetClassAutoloading(storeAutoload);
3503 // return (decl);
3504 }
3505 
3506 ////////////////////////////////////////////////////////////////////////////////
3507 /// Return true if there is a class template by the given name ...
3508 
3510 {
3511  const cling::LookupHelper& lh = fInterpreter->getLookupHelper();
3512  const clang::Decl *decl
3513  = lh.findClassTemplate(name,
3514  gDebug > 5 ? cling::LookupHelper::WithDiagnostics
3515  : cling::LookupHelper::NoDiagnostics);
3516  if (!decl) {
3517  std::string strname = "std::";
3518  strname += name;
3519  decl = lh.findClassTemplate(strname,
3520  gDebug > 5 ? cling::LookupHelper::WithDiagnostics
3521  : cling::LookupHelper::NoDiagnostics);
3522  }
3523  return 0 != decl;
3524 }
3525 
3526 ////////////////////////////////////////////////////////////////////////////////
3527 /// Create list of pointers to base class(es) for TClass cl.
3528 
3530 {
3532  if (cl->fBase) {
3533  return;
3534  }
3536  if (!tci) return;
3538  TList *listOfBase = new TList;
3539  while (t.Next()) {
3540  // if name cannot be obtained no use to put in list
3541  if (t.IsValid() && t.Name()) {
3543  listOfBase->Add(new TBaseClass((BaseClassInfo_t *)a, cl));
3544  }
3545  }
3546  // Now that is complete, publish it.
3547  cl->fBase = listOfBase;
3548 }
3549 
3550 ////////////////////////////////////////////////////////////////////////////////
3551 /// Create list of pointers to enums for TClass cl.
3552 
3553 void TCling::LoadEnums(TListOfEnums& enumList) const
3554 {
3556 
3557  const Decl * D;
3558  TClass* cl = enumList.GetClass();
3559  if (cl) {
3560  D = ((TClingClassInfo*)cl->GetClassInfo())->GetDecl();
3561  }
3562  else {
3563  D = fInterpreter->getCI()->getASTContext().getTranslationUnitDecl();
3564  }
3565  // Iterate on the decl of the class and get the enums.
3566  if (const clang::DeclContext* DC = dyn_cast<clang::DeclContext>(D)) {
3567  cling::Interpreter::PushTransactionRAII deserRAII(fInterpreter);
3568  // Collect all contexts of the namespace.
3569  llvm::SmallVector< DeclContext *, 4> allDeclContexts;
3570  const_cast< clang::DeclContext *>(DC)->collectAllContexts(allDeclContexts);
3571  for (llvm::SmallVector<DeclContext*, 4>::iterator declIter = allDeclContexts.begin(), declEnd = allDeclContexts.end();
3572  declIter != declEnd; ++declIter) {
3573  // Iterate on all decls for each context.
3574  for (clang::DeclContext::decl_iterator DI = (*declIter)->decls_begin(),
3575  DE = (*declIter)->decls_end(); DI != DE; ++DI) {
3576  if (const clang::EnumDecl* ED = dyn_cast<clang::EnumDecl>(*DI)) {
3577  // Get name of the enum type.
3578  std::string buf;
3579  PrintingPolicy Policy(ED->getASTContext().getPrintingPolicy());
3580  llvm::raw_string_ostream stream(buf);
3581  // Don't trigger fopen of the source file to count lines:
3582  Policy.AnonymousTagLocations = false;
3583  ED->getNameForDiagnostic(stream, Policy, /*Qualified=*/false);
3584  stream.flush();
3585  // If the enum is unnamed we do not add it to the list of enums i.e unusable.
3586  if (!buf.empty()) {
3587  const char* name = buf.c_str();
3588  // Add the enum to the list of loaded enums.
3589  enumList.Get(ED, name);
3590  }
3591  }
3592  }
3593  }
3594  }
3595 }
3596 
3597 ////////////////////////////////////////////////////////////////////////////////
3598 /// Create list of pointers to function templates for TClass cl.
3599 
3601 {
3603 
3604  const Decl * D;
3605  TListOfFunctionTemplates* funcTempList;
3606  if (cl) {
3607  D = ((TClingClassInfo*)cl->GetClassInfo())->GetDecl();
3608  funcTempList = (TListOfFunctionTemplates*)cl->GetListOfFunctionTemplates(false);
3609  }
3610  else {
3611  D = fInterpreter->getCI()->getASTContext().getTranslationUnitDecl();
3612  funcTempList = (TListOfFunctionTemplates*)gROOT->GetListOfFunctionTemplates();
3613  }
3614  // Iterate on the decl of the class and get the enums.
3615  if (const clang::DeclContext* DC = dyn_cast<clang::DeclContext>(D)) {
3616  cling::Interpreter::PushTransactionRAII deserRAII(fInterpreter);
3617  // Collect all contexts of the namespace.
3618  llvm::SmallVector< DeclContext *, 4> allDeclContexts;
3619  const_cast< clang::DeclContext *>(DC)->collectAllContexts(allDeclContexts);
3620  for (llvm::SmallVector<DeclContext*, 4>::iterator declIter = allDeclContexts.begin(),
3621  declEnd = allDeclContexts.end(); declIter != declEnd; ++declIter) {
3622  // Iterate on all decls for each context.
3623  for (clang::DeclContext::decl_iterator DI = (*declIter)->decls_begin(),
3624  DE = (*declIter)->decls_end(); DI != DE; ++DI) {
3625  if (const clang::FunctionTemplateDecl* FTD = dyn_cast<clang::FunctionTemplateDecl>(*DI)) {
3626  funcTempList->Get(FTD);
3627  }
3628  }
3629  }
3630  }
3631 }
3632 ////////////////////////////////////////////////////////////////////////////////
3633 /// Create list of pointers to data members for TClass cl.
3634 /// This is now a nop. The creation and updating is handled in
3635 /// TListOfDataMembers.
3636 
3638 {
3639 }
3640 
3641 ////////////////////////////////////////////////////////////////////////////////
3642 /// Create list of pointers to methods for TClass cl.
3643 /// This is now a nop. The creation and updating is handled in
3644 /// TListOfFunctions.
3645 
3647 {
3648 }
3649 
3650 ////////////////////////////////////////////////////////////////////////////////
3651 /// Update the list of pointers to method for TClass cl
3652 /// This is now a nop. The creation and updating is handled in
3653 /// TListOfFunctions.
3654 
3656 {
3657 }
3658 
3659 ////////////////////////////////////////////////////////////////////////////////
3660 /// Update the list of pointers to data members for TClass cl
3661 /// This is now a nop. The creation and updating is handled in
3662 /// TListOfDataMembers.
3663 
3665 {
3666 }
3667 
3668 ////////////////////////////////////////////////////////////////////////////////
3669 /// Create list of pointers to method arguments for TMethod m.
3670 
3672 {
3674  if (m->fMethodArgs) {
3675  return;
3676  }
3677  TList *arglist = new TList;
3679  while (t.Next()) {
3680  if (t.IsValid()) {
3682  arglist->Add(new TMethodArg((MethodArgInfo_t*)a, m));
3683  }
3684  }
3685  m->fMethodArgs = arglist;
3686 }
3687 
3688 
3689 ////////////////////////////////////////////////////////////////////////////////
3690 /// Generate a TClass for the given class.
3691 /// Since the caller has already check the ClassInfo, let it give use the
3692 /// result (via the value of emulation) rather than recalculate it.
3693 
3694 TClass *TCling::GenerateTClass(const char *classname, Bool_t emulation, Bool_t silent /* = kFALSE */)
3695 {
3696 // For now the following line would lead to the (unwanted) instantiation
3697 // of class template. This could/would need to be resurrected only if
3698 // we re-introduce so sort of automatic instantiation. However this would
3699 // have to include carefull look at the template parameter to avoid
3700 // creating instance we can not really use (if the parameter are only forward
3701 // declaration or do not have all the necessary interfaces).
3702 
3703  // TClingClassInfo tci(fInterpreter, classname);
3704  // if (1 || !tci.IsValid()) {
3705 
3706  Version_t version = 1;
3707  if (TClassEdit::IsSTLCont(classname)) {
3708  version = TClass::GetClass("TVirtualStreamerInfo")->GetClassVersion();
3709  }
3710  TClass *cl = new TClass(classname, version, silent);
3711  if (emulation) {
3713  } else {
3714  // Set the class version if the class is versioned.
3715  // Note that we cannot just call CLASS::Class_Version() as we might not have
3716  // an execution engine (when invoked from rootcling).
3717 
3718  // Do not call cl->GetClassVersion(), it has side effects!
3719  Version_t oldvers = cl->fClassVersion;
3720  if (oldvers == version && cl->GetClassInfo()) {
3721  // We have a version and it might need an update.
3722  Version_t newvers = oldvers;
3724  if (llvm::isa<clang::NamespaceDecl>(cli->GetDecl())) {
3725  // Namespaces don't have class versions.
3726  return cl;
3727  }
3728  TClingMethodInfo mi = cli->GetMethod("Class_Version", "", 0 /*poffset*/,
3731  if (!mi.IsValid()) {
3732  if (cl->TestBit(TClass::kIsTObject)) {
3733  Error("GenerateTClass",
3734  "Cannot find %s::Class_Version()! Class version might be wrong.",
3735  cl->GetName());
3736  }
3737  return cl;
3738  }
3739  newvers = ROOT::TMetaUtils::GetClassVersion(llvm::dyn_cast<clang::RecordDecl>(cli->GetDecl()),
3740  *fInterpreter);
3741  if (newvers == -1) {
3742  // Didn't manage to determine the class version from the AST.
3743  // Use runtime instead.
3744  if ((mi.Property() & kIsStatic)
3745  && !fInterpreter->isInSyntaxOnlyMode()) {
3746  // This better be a static function.
3748  callfunc.SetFunc(&mi);
3749  newvers = callfunc.ExecInt(0);
3750  } else {
3751  Error("GenerateTClass",
3752  "Cannot invoke %s::Class_Version()! Class version might be wrong.",
3753  cl->GetName());
3754  }
3755  }
3756  if (newvers != oldvers) {
3757  cl->fClassVersion = newvers;
3758  cl->fStreamerInfo->Expand(newvers + 2 + 10);
3759  }
3760  }
3761  }
3762 
3763  return cl;
3764 
3765 // } else {
3766 // return GenerateTClass(&tci,silent);
3767 // }
3768 }
3769 
3770 #if 0
3771 ////////////////////////////////////////////////////////////////////////////////
3772 
3773 static void GenerateTClass_GatherInnerIncludes(cling::Interpreter *interp, TString &includes,TClingClassInfo *info)
3774 {
3775  includes += info->FileName();
3776 
3777  const clang::ClassTemplateSpecializationDecl *templateCl
3778  = llvm::dyn_cast<clang::ClassTemplateSpecializationDecl>(info->GetDecl());
3779  if (templateCl) {
3780  for(unsigned int i=0; i < templateCl->getTemplateArgs().size(); ++i) {
3781  const clang::TemplateArgument &arg( templateCl->getTemplateArgs().get(i) );
3782  if (arg.getKind() == clang::TemplateArgument::Type) {
3783  const clang::Type *uType = ROOT::TMetaUtils::GetUnderlyingType( arg.getAsType() );
3784 
3785  if (!uType->isFundamentalType() && !uType->isEnumeralType()) {
3786  // We really need a header file.
3787  const clang::CXXRecordDecl *argdecl = uType->getAsCXXRecordDecl();
3788  if (argdecl) {
3789  includes += ";";
3790  TClingClassInfo subinfo(interp,*(argdecl->getASTContext().getRecordType(argdecl).getTypePtr()));
3791  GenerateTClass_GatherInnerIncludes(interp, includes, &subinfo);
3792  } else {
3793  std::string Result;
3794  llvm::raw_string_ostream OS(Result);
3795  arg.print(argdecl->getASTContext().getPrintingPolicy(),OS);
3796  Warning("TCling::GenerateTClass","Missing header file for %s",OS.str().c_str());
3797  }
3798  }
3799  }
3800  }
3801  }
3802 }
3803 #endif
3804 
3805 ////////////////////////////////////////////////////////////////////////////////
3806 /// Generate a TClass for the given class.
3807 
3808 TClass *TCling::GenerateTClass(ClassInfo_t *classinfo, Bool_t silent /* = kFALSE */)
3809 {
3810  TClingClassInfo *info = (TClingClassInfo*)classinfo;
3811  if (!info || !info->IsValid()) {
3812  Fatal("GenerateTClass","Requires a valid ClassInfo object");
3813  return 0;
3814  }
3815  // We are in the case where we have AST nodes for this class.
3816  TClass *cl = 0;
3817  std::string classname;
3818  info->FullName(classname,*fNormalizedCtxt); // Could we use Name()?
3819  if (TClassEdit::IsSTLCont(classname.c_str())) {
3820 #if 0
3821  Info("GenerateTClass","Will (try to) generate the compiled TClass for %s.",classname.c_str());
3822  // We need to build up the list of required headers, by
3823  // looking at each template arguments.
3824  TString includes;
3825  GenerateTClass_GatherInnerIncludes(fInterpreter,includes,info);
3826 
3827  if (0 == GenerateDictionary(classname.c_str(),includes)) {
3828  // 0 means success.
3829  cl = TClass::LoadClass(classnam.c_str(), silent);
3830  if (cl == 0) {
3831  Error("GenerateTClass","Even though the dictionary generation for %s seemed successful we can't find the TClass bootstrap!",classname.c_str());
3832  }
3833  }
3834 #endif
3835  if (cl == 0) {
3836  int version = TClass::GetClass("TVirtualStreamerInfo")->GetClassVersion();
3837  cl = new TClass(classinfo, version, 0, 0, -1, -1, silent);
3839  }
3840  } else {
3841  // For regular class, just create a TClass on the fly ...
3842  // Not quite useful yet, but that what CINT used to do anyway.
3843  cl = new TClass(classinfo, 1, 0, 0, -1, -1, silent);
3844  }
3845  // Add the new TClass to the map of declid and TClass*.
3846  if (cl) {
3848  }
3849  return cl;
3850 }
3851 
3852 ////////////////////////////////////////////////////////////////////////////////
3853 /// Generate the dictionary for the C++ classes listed in the first
3854 /// argument (in a semi-colon separated list).
3855 /// 'includes' contains a semi-colon separated list of file to
3856 /// #include in the dictionary.
3857 /// For example:
3858 /// ~~~ {.cpp}
3859 /// gInterpreter->GenerateDictionary("vector<vector<float> >;list<vector<float> >","list;vector");
3860 /// ~~~
3861 /// or
3862 /// ~~~ {.cpp}
3863 /// gInterpreter->GenerateDictionary("myclass","myclass.h;myhelper.h");
3864 /// ~~~
3865 
3866 Int_t TCling::GenerateDictionary(const char* classes, const char* includes /* = 0 */, const char* /* options = 0 */)
3867 {
3868  if (classes == 0 || classes[0] == 0) {
3869  return 0;
3870  }
3871  // Split the input list
3872  std::vector<std::string> listClasses;
3873  for (
3874  const char* current = classes, *prev = classes;
3875  *current != 0;
3876  ++current
3877  ) {
3878  if (*current == ';') {
3879  listClasses.push_back(std::string(prev, current - prev));
3880  prev = current + 1;
3881  }
3882  else if (*(current + 1) == 0) {
3883  listClasses.push_back(std::string(prev, current + 1 - prev));
3884  prev = current + 1;
3885  }
3886  }
3887  std::vector<std::string> listIncludes;
3888  for (
3889  const char* current = includes, *prev = includes;
3890  *current != 0;
3891  ++current
3892  ) {
3893  if (*current == ';') {
3894  listIncludes.push_back(std::string(prev, current - prev));
3895  prev = current + 1;
3896  }
3897  else if (*(current + 1) == 0) {
3898  listIncludes.push_back(std::string(prev, current + 1 - prev));
3899  prev = current + 1;
3900  }
3901  }
3902  // Generate the temporary dictionary file
3903  return TCling_GenerateDictionary(listClasses, listIncludes,
3904  std::vector<std::string>(), std::vector<std::string>());
3905 }
3906 
3907 ////////////////////////////////////////////////////////////////////////////////
3908 /// Return pointer to cling Decl of global/static variable that is located
3909 /// at the address given by addr.
3910 
3911 TInterpreter::DeclId_t TCling::GetDataMember(ClassInfo_t *opaque_cl, const char *name) const
3912 {
3914  DeclId_t d;
3915  TClingClassInfo *cl = (TClingClassInfo*)opaque_cl;
3916 
3917  if (cl) {
3918  d = cl->GetDataMember(name);
3919  // We check if the decl of the data member has an annotation which indicates
3920  // an ioname.
3921  // In case this is true, if the name requested is not the ioname, we
3922  // return 0, as if the member did not exist. In some sense we override
3923  // the information in the TClassInfo instance, isolating the typesystem in
3924  // TClass from the one in the AST.
3925  if (const ValueDecl* decl = (const ValueDecl*) d){
3926  std::string ioName;
3927  bool hasIoName = ROOT::TMetaUtils::ExtractAttrPropertyFromName(*decl,"ioname",ioName);
3928  if (hasIoName && ioName != name) return 0;
3929  }
3930  }
3931  else {
3933  d = gcl.GetDataMember(name);
3934  }
3935  return d;
3936 }
3937 
3938 ////////////////////////////////////////////////////////////////////////////////
3939 /// Return pointer to cling Decl of global/static variable that is located
3940 /// at the address given by addr.
3941 
3943 {
3945 
3946  const clang::Decl* possibleEnum = 0;
3947  // FInd the context of the decl.
3948  if (cl) {
3950  if (cci) {
3951  const clang::DeclContext* dc = 0;
3952  if (const clang::Decl* D = cci->GetDecl()) {
3953  if (!(dc = dyn_cast<clang::NamespaceDecl>(D))) {
3954  dc = dyn_cast<clang::RecordDecl>(D);
3955  }
3956  }
3957  if (dc) {
3958  // If it is a data member enum.
3959  possibleEnum = cling::utils::Lookup::Named(&fInterpreter->getSema(), name, dc);
3960  } else {
3961  Error("TCling::GetEnum", "DeclContext not found for %s .\n", name);
3962  }
3963  }
3964  } else {
3965  // If it is a global enum.
3966  possibleEnum = cling::utils::Lookup::Named(&fInterpreter->getSema(), name);
3967  }
3968  if (possibleEnum && (possibleEnum != (clang::Decl*)-1)
3969  && isa<clang::EnumDecl>(possibleEnum)) {
3970  return possibleEnum;
3971  }
3972  return 0;
3973 }
3974 
3975 ////////////////////////////////////////////////////////////////////////////////
3976 /// Return pointer to cling DeclId for a global value
3977 
3978 TInterpreter::DeclId_t TCling::GetDeclId( const llvm::GlobalValue *gv ) const
3979 {
3980  if (!gv) return 0;
3981 
3982  llvm::StringRef mangled_name = gv->getName();
3983 
3984  int err = 0;
3985  char* demangled_name_c = TClassEdit::DemangleName(mangled_name.str().c_str(), err);
3986  if (err) {
3987  if (err == -2) {
3988  // It might simply be an unmangled global name.
3989  DeclId_t d;
3991  d = gcl.GetDataMember(mangled_name.str().c_str());
3992  return d;
3993  }
3994  return 0;
3995  }
3996 
3997  std::string scopename(demangled_name_c);
3998  free(demangled_name_c);
3999 
4000  //
4001  // Separate out the class or namespace part of the
4002  // function name.
4003  //
4004  std::string dataname;
4005 
4006  if (!strncmp(scopename.c_str(), "typeinfo for ", sizeof("typeinfo for ")-1)) {
4007  scopename.erase(0, sizeof("typeinfo for ")-1);
4008  } else if (!strncmp(scopename.c_str(), "vtable for ", sizeof("vtable for ")-1)) {
4009  scopename.erase(0, sizeof("vtable for ")-1);
4010  } else {
4011  // See if it is a function
4012  std::string::size_type pos = scopename.rfind('(');
4013  if (pos != std::string::npos) {
4014  return 0;
4015  }
4016  // Separate the scope and member name
4017  pos = scopename.rfind(':');
4018  if (pos != std::string::npos) {
4019  if ((pos != 0) && (scopename[pos-1] == ':')) {
4020  dataname = scopename.substr(pos+1);
4021  scopename.erase(pos-1);
4022  }
4023  } else {
4024  scopename.clear();
4025  dataname = scopename;
4026  }
4027  }
4028  //fprintf(stderr, "name: '%s'\n", name.c_str());
4029  // Now we have the class or namespace name, so do the lookup.
4030 
4031 
4032  DeclId_t d;
4033  if (scopename.size()) {
4034  TClingClassInfo cl(fInterpreter,scopename.c_str());
4035  d = cl.GetDataMember(dataname.c_str());
4036  }
4037  else {
4039  d = gcl.GetDataMember(dataname.c_str());
4040  }
4041  return d;
4042 }
4043 
4044 ////////////////////////////////////////////////////////////////////////////////
4045 /// NOT IMPLEMENTED.
4046 
4048 {
4049  Error("GetDataMemberWithValue()", "not implemented");
4050  return 0;
4051 }
4052 
4053 ////////////////////////////////////////////////////////////////////////////////
4054 /// Return pointer to cling DeclId for a data member with a given name.
4055 
4057 {
4058  // NOT IMPLEMENTED.
4059  Error("GetDataMemberAtAddr()", "not implemented");
4060  return 0;
4061 }
4062 
4063 ////////////////////////////////////////////////////////////////////////////////
4064 /// Return the cling mangled name for a method of a class with parameters
4065 /// params (params is a string of actual arguments, not formal ones). If the
4066 /// class is 0 the global function list will be searched.
4067 
4068 TString TCling::GetMangledName(TClass* cl, const char* method,
4069  const char* params, Bool_t objectIsConst /* = kFALSE */)
4070 {
4073  if (cl) {
4074  Long_t offset;
4075  func.SetFunc((TClingClassInfo*)cl->GetClassInfo(), method, params, objectIsConst,
4076  &offset);
4077  }
4078  else {
4080  Long_t offset;
4081  func.SetFunc(&gcl, method, params, &offset);
4082  }
4084  if (!mi) return "";
4085  TString mangled_name( mi->GetMangledName() );
4086  delete mi;
4087  return mangled_name;
4088 }
4089 
4090 ////////////////////////////////////////////////////////////////////////////////
4091 /// Return the cling mangled name for a method of a class with a certain
4092 /// prototype, i.e. "char*,int,float". If the class is 0 the global function
4093 /// list will be searched.
4094 
4096  const char* proto, Bool_t objectIsConst /* = kFALSE */,
4097  EFunctionMatchMode mode /* = kConversionMatch */)
4098 {
4100  if (cl) {
4101  return ((TClingClassInfo*)cl->GetClassInfo())->
4102  GetMethod(method, proto, objectIsConst, 0 /*poffset*/, mode).GetMangledName();
4103  }
4105  return gcl.GetMethod(method, proto, objectIsConst, 0 /*poffset*/, mode).GetMangledName();
4106 }
4107 
4108 ////////////////////////////////////////////////////////////////////////////////
4109 /// Return pointer to cling interface function for a method of a class with
4110 /// parameters params (params is a string of actual arguments, not formal
4111 /// ones). If the class is 0 the global function list will be searched.
4112 
4113 void* TCling::GetInterfaceMethod(TClass* cl, const char* method,
4114  const char* params, Bool_t objectIsConst /* = kFALSE */)
4115 {
4118  if (cl) {
4119  Long_t offset;
4120  func.SetFunc((TClingClassInfo*)cl->GetClassInfo(), method, params, objectIsConst,
4121  &offset);
4122  }
4123  else {
4125  Long_t offset;
4126  func.SetFunc(&gcl, method, params, &offset);
4127  }
4128  return (void*) func.InterfaceMethod();
4129 }
4130 
4131 ////////////////////////////////////////////////////////////////////////////////
4132 /// Return pointer to cling interface function for a method of a class with
4133 /// a certain name.
4134 
4135 TInterpreter::DeclId_t TCling::GetFunction(ClassInfo_t *opaque_cl, const char* method)
4136 {
4138  DeclId_t f;
4139  TClingClassInfo *cl = (TClingClassInfo*)opaque_cl;
4140  if (cl) {
4141  f = cl->GetMethod(method).GetDeclId();
4142  }
4143  else {
4145  f = gcl.GetMethod(method).GetDeclId();
4146  }
4147  return f;
4148 
4149 }
4150 
4151 ////////////////////////////////////////////////////////////////////////////////
4152 /// Insert overloads of name in cl to res.
4153 
4154 void TCling::GetFunctionOverloads(ClassInfo_t *cl, const char *funcname,
4155  std::vector<DeclId_t>& res) const
4156 {
4157  clang::Sema& S = fInterpreter->getSema();
4158  const clang::Decl* CtxDecl
4159  = cl ? (const clang::Decl*)((TClingClassInfo*)cl)->GetDeclId():
4160  S.Context.getTranslationUnitDecl();
4161  const clang::DeclContext*
4162  DeclCtx = llvm::dyn_cast<const clang::RecordDecl>(CtxDecl);
4163  if (!DeclCtx)
4164  DeclCtx = dyn_cast<clang::NamespaceDecl>(CtxDecl);
4165  if (!DeclCtx) return;
4166  clang::DeclarationName DName
4167  = &S.Context.Idents.get(funcname);
4168  clang::LookupResult R(S, DName, clang::SourceLocation(),
4169  Sema::LookupOrdinaryName, clang::Sema::ForRedeclaration);
4170  S.LookupQualifiedName(R, const_cast<DeclContext*>(DeclCtx));
4171  if (R.empty()) return;
4172  R.resolveKind();
4173  res.reserve(res.size() + (R.end() - R.begin()));
4174  for (clang::LookupResult::iterator IR = R.begin(), ER = R.end();
4175  IR != ER; ++IR) {
4176  if (const clang::FunctionDecl* FD
4177  = llvm::dyn_cast<const clang::FunctionDecl>(*IR)) {
4178  if (!FD->getDescribedFunctionTemplate()) {
4179  res.push_back(FD);
4180  }
4181  }
4182  }
4183 }
4184 
4185 ////////////////////////////////////////////////////////////////////////////////
4186 /// Return pointer to cling interface function for a method of a class with
4187 /// a certain prototype, i.e. "char*,int,float". If the class is 0 the global
4188 /// function list will be searched.
4189 
4190 void* TCling::GetInterfaceMethodWithPrototype(TClass* cl, const char* method,
4191  const char* proto,
4192  Bool_t objectIsConst /* = kFALSE */,
4193  EFunctionMatchMode mode /* = kConversionMatch */)
4194 {
4196  void* f;
4197  if (cl) {
4198  f = ((TClingClassInfo*)cl->GetClassInfo())->
4199  GetMethod(method, proto, objectIsConst, 0 /*poffset*/, mode).InterfaceMethod(*fNormalizedCtxt);
4200  }
4201  else {
4203  f = gcl.GetMethod(method, proto, objectIsConst, 0 /*poffset*/, mode).InterfaceMethod(*fNormalizedCtxt);
4204  }
4205  return f;
4206 }
4207 
4208 ////////////////////////////////////////////////////////////////////////////////
4209 /// Return pointer to cling DeclId for a method of a class with
4210 /// a certain prototype, i.e. "char*,int,float". If the class is 0 the global
4211 /// function list will be searched.
4212 
4213 TInterpreter::DeclId_t TCling::GetFunctionWithValues(ClassInfo_t *opaque_cl, const char* method,
4214  const char* params,
4215  Bool_t objectIsConst /* = kFALSE */)
4216 {
4218  DeclId_t f;
4219  TClingClassInfo *cl = (TClingClassInfo*)opaque_cl;
4220  if (cl) {
4221  f = cl->GetMethodWithArgs(method, params, objectIsConst, 0 /*poffset*/).GetDeclId();
4222  }
4223  else {
4225  f = gcl.GetMethod(method, params, objectIsConst, 0 /*poffset*/).GetDeclId();
4226  }
4227  return f;
4228 }
4229 
4230 ////////////////////////////////////////////////////////////////////////////////
4231 /// Return pointer to cling interface function for a method of a class with
4232 /// a certain prototype, i.e. "char*,int,float". If the class is 0 the global
4233 /// function list will be searched.
4234 
4235 TInterpreter::DeclId_t TCling::GetFunctionWithPrototype(ClassInfo_t *opaque_cl, const char* method,
4236  const char* proto,
4237  Bool_t objectIsConst /* = kFALSE */,
4238  EFunctionMatchMode mode /* = kConversionMatch */)
4239 {
4241  DeclId_t f;
4242  TClingClassInfo *cl = (TClingClassInfo*)opaque_cl;
4243  if (cl) {
4244  f = cl->GetMethod(method, proto, objectIsConst, 0 /*poffset*/, mode).GetDeclId();
4245  }
4246  else {
4248  f = gcl.GetMethod(method, proto, objectIsConst, 0 /*poffset*/, mode).GetDeclId();
4249  }
4250  return f;
4251 }
4252 
4253 ////////////////////////////////////////////////////////////////////////////////
4254 /// Return pointer to cling interface function for a method of a class with
4255 /// a certain name.
4256 
4257 TInterpreter::DeclId_t TCling::GetFunctionTemplate(ClassInfo_t *opaque_cl, const char* name)
4258 {
4260  DeclId_t f;
4261  TClingClassInfo *cl = (TClingClassInfo*)opaque_cl;
4262  if (cl) {
4263  f = cl->GetFunctionTemplate(name);
4264  }
4265  else {
4267  f = gcl.GetFunctionTemplate(name);
4268  }
4269  return f;
4270 
4271 }
4272 
4273 ////////////////////////////////////////////////////////////////////////////////
4274 /// The 'name' is known to the interpreter, this function returns
4275 /// the internal version of this name (usually just resolving typedefs)
4276 /// This is used in particular to synchronize between the name used
4277 /// by rootcling and by the run-time environment (TClass)
4278 /// Return 0 if the name is not known.
4279 
4280 void TCling::GetInterpreterTypeName(const char* name, std::string &output, Bool_t full)
4281 {
4282  output.clear();
4283 
4285 
4286  TClingClassInfo cl(fInterpreter, name);
4287  if (!cl.IsValid()) {
4288  return ;
4289  }
4290  if (full) {
4291  cl.FullName(output,*fNormalizedCtxt);
4292  return;
4293  }
4294  // Well well well, for backward compatibility we need to act a bit too
4295  // much like CINT.
4297  splitname.ShortType(output, TClassEdit::kDropStd );
4298 
4299  return;
4300 }
4301 
4302 ////////////////////////////////////////////////////////////////////////////////
4303 /// Execute a global function with arguments params.
4304 ///
4305 /// FIXME: The cint-based version of this code does not check if the
4306 /// SetFunc() call works, and does not do any real checking
4307 /// for errors from the Exec() call. It did fetch the most
4308 /// recent cint security error and return that in error, but
4309 /// this does not really translate well to cling/clang. We
4310 /// should enhance these interfaces so that we can report
4311 /// compilation and runtime errors properly.
4312 
4313 void TCling::Execute(const char* function, const char* params, int* error)
4314 {
4316  if (error) {
4317  *error = TInterpreter::kNoError;
4318  }
4320  Long_t offset = 0L;
4322  func.SetFunc(&cl, function, params, &offset);
4323  func.Exec(0);
4324 }
4325 
4326 ////////////////////////////////////////////////////////////////////////////////
4327 /// Execute a method from class cl with arguments params.
4328 ///
4329 /// FIXME: The cint-based version of this code does not check if the
4330 /// SetFunc() call works, and does not do any real checking
4331 /// for errors from the Exec() call. It did fetch the most
4332 /// recent cint security error and return that in error, but
4333 /// this does not really translate well to cling/clang. We
4334 /// should enhance these interfaces so that we can report
4335 /// compilation and runtime errors properly.
4336 
4337 void TCling::Execute(TObject* obj, TClass* cl, const char* method,
4338  const char* params, Bool_t objectIsConst, int* error)
4339 {
4341  if (error) {
4342  *error = TInterpreter::kNoError;
4343  }
4344  // If the actual class of this object inherits 2nd (or more) from TObject,
4345  // 'obj' is unlikely to be the start of the object (as described by IsA()),
4346  // hence gInterpreter->Execute will improperly correct the offset.
4347  void* addr = cl->DynamicCast(TObject::Class(), obj, kFALSE);
4348  Long_t offset = 0L;
4350  func.SetFunc((TClingClassInfo*)cl->GetClassInfo(), method, params, objectIsConst, &offset);
4351  void* address = (void*)((Long_t)addr + offset);
4352  func.Exec(address);
4353 }
4354 
4355 ////////////////////////////////////////////////////////////////////////////////
4356 
4357 void TCling::Execute(TObject* obj, TClass* cl, const char* method,
4358  const char* params, int* error)
4359 {
4360  Execute(obj,cl,method,params,false,error);
4361 }
4362 
4363 ////////////////////////////////////////////////////////////////////////////////
4364 /// Execute a method from class cl with the arguments in array params
4365 /// (params[0] ... params[n] = array of TObjString parameters).
4366 /// Convert the TObjArray array of TObjString parameters to a character
4367 /// string of comma separated parameters.
4368 /// The parameters of type 'char' are enclosed in double quotes and all
4369 /// internal quotes are escaped.
4370 
4371 void TCling::Execute(TObject* obj, TClass* cl, TMethod* method,
4372  TObjArray* params, int* error)
4373 {
4374  if (!method) {
4375  Error("Execute", "No method was defined");
4376  return;
4377  }
4378  TList* argList = method->GetListOfMethodArgs();
4379  // Check number of actual parameters against of expected formal ones
4380 
4381  Int_t nparms = argList->LastIndex() + 1;
4382  Int_t argc = params ? params->GetEntries() : 0;
4383 
4384  if (argc > nparms) {
4385  Error("Execute","Too many parameters to call %s, got %d but expected at most %d.",method->GetName(),argc,nparms);
4386  return;
4387  }
4388  if (nparms != argc) {
4389  // Let's see if the 'missing' argument are all defaulted.
4390  // if nparms==0 then either we stopped earlier either argc is also zero and we can't reach here.
4391  assert(nparms > 0);
4392 
4393  TMethodArg *arg = (TMethodArg *) argList->At( 0 );
4394  if (arg && arg->GetDefault() && arg->GetDefault()[0]) {
4395  // There is a default value for the first missing
4396  // argument, so we are fine.
4397  } else {
4398  Int_t firstDefault = -1;
4399  for (Int_t i = 0; i < nparms; i ++) {
4400  arg = (TMethodArg *) argList->At( i );
4401  if (arg && arg->GetDefault() && arg->GetDefault()[0]) {
4402  firstDefault = i;
4403  break;
4404  }
4405  }
4406  if (firstDefault >= 0) {
4407  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);
4408  } else {
4409  Error("Execute","Too few arguments to call %s, got only %d but expected %d.",method->GetName(),argc,nparms);
4410  }
4411  return;
4412  }
4413  }
4414 
4415  const char* listpar = "";
4416  TString complete(10);
4417  if (params) {
4418  // Create a character string of parameters from TObjArray
4419  TIter next(params);
4420  for (Int_t i = 0; i < argc; i ++) {
4421  TMethodArg* arg = (TMethodArg*) argList->At(i);
4423  TObjString* nxtpar = (TObjString*) next();
4424  if (i) {
4425  complete += ',';
4426  }
4427  if (strstr(type.TrueName(*fNormalizedCtxt), "char")) {
4428  TString chpar('\"');
4429  chpar += (nxtpar->String()).ReplaceAll("\"", "\\\"");
4430  // At this point we have to check if string contains \\"
4431  // and apply some more sophisticated parser. Not implemented yet!
4432  complete += chpar;
4433  complete += '\"';
4434  }
4435  else {
4436  complete += nxtpar->String();
4437  }
4438  }
4439  listpar = complete.Data();
4440  }
4441 
4442  // And now execute it.
4444  if (error) {
4445  *error = TInterpreter::kNoError;
4446  }
4447  // If the actual class of this object inherits 2nd (or more) from TObject,
4448  // 'obj' is unlikely to be the start of the object (as described by IsA()),
4449  // hence gInterpreter->Execute will improperly correct the offset.
4450  void* addr = cl->DynamicCast(TObject::Class(), obj, kFALSE);
4452  TClingMethodInfo *minfo = (TClingMethodInfo*)method->fInfo;
4453  func.Init(minfo);
4454  func.SetArgs(listpar);
4455  // Now calculate the 'this' pointer offset for the method
4456  // when starting from the class described by cl.
4457  const CXXMethodDecl * mdecl = dyn_cast<CXXMethodDecl>(minfo->GetMethodDecl());
4458  Long_t offset = ((TClingClassInfo*)cl->GetClassInfo())->GetOffset(mdecl);
4459  void* address = (void*)((Long_t)addr + offset);
4460  func.Exec(address);
4461 }
4462 
4463 ////////////////////////////////////////////////////////////////////////////////
4464 
4465 void TCling::ExecuteWithArgsAndReturn(TMethod* method, void* address,
4466  const void* args[] /*=0*/,
4467  int nargs /*=0*/,
4468  void* ret/*= 0*/) const
4469 {
4470  if (!method) {
4471  Error("ExecuteWithArgsAndReturn", "No method was defined");
4472  return;
4473  }
4474 
4475  TClingMethodInfo* minfo = (TClingMethodInfo*) method->fInfo;
4477  func.ExecWithArgsAndReturn(address, args, nargs, ret);
4478 }
4479 
4480 ////////////////////////////////////////////////////////////////////////////////
4481 /// Execute a cling macro.
4482 
4483 Long_t TCling::ExecuteMacro(const char* filename, EErrorCode* error)
4484 {
4486  fCurExecutingMacros.push_back(filename);
4487  Long_t result = TApplication::ExecuteFile(filename, (int*)error);
4488  fCurExecutingMacros.pop_back();
4489  return result;
4490 }
4491 
4492 ////////////////////////////////////////////////////////////////////////////////
4493 /// Return the file name of the current un-included interpreted file.
4494 /// See the documentation for GetCurrentMacroName().
4495 
4496 const char* TCling::GetTopLevelMacroName() const
4497 {
4498  Warning("GetTopLevelMacroName", "Must change return type!");
4499  return fCurExecutingMacros.back();
4500 }
4501 
4502 ////////////////////////////////////////////////////////////////////////////////
4503 /// Return the file name of the currently interpreted file,
4504 /// included or not. Example to illustrate the difference between
4505 /// GetCurrentMacroName() and GetTopLevelMacroName():
4506 /// ~~~ {.cpp}
4507 /// void inclfile() {
4508 /// std::cout << "In inclfile.C" << std::endl;
4509 /// std::cout << " TCling::GetCurrentMacroName() returns " <<
4510 /// TCling::GetCurrentMacroName() << std::endl;
4511 /// std::cout << " TCling::GetTopLevelMacroName() returns " <<
4512 /// TCling::GetTopLevelMacroName() << std::endl;
4513 /// }
4514 /// ~~~
4515 /// ~~~ {.cpp}
4516 /// void mymacro() {
4517 /// std::cout << "In mymacro.C" << std::endl;
4518 /// std::cout << " TCling::GetCurrentMacroName() returns " <<
4519 /// TCling::GetCurrentMacroName() << std::endl;
4520 /// std::cout << " TCling::GetTopLevelMacroName() returns " <<
4521 /// TCling::GetTopLevelMacroName() << std::endl;
4522 /// std::cout << " Now calling inclfile..." << std::endl;
4523 /// gInterpreter->ProcessLine(".x inclfile.C");;
4524 /// }
4525 /// ~~~
4526 /// Running mymacro.C will print:
4527 ///
4528 /// ~~~ {.cpp}
4529 /// root [0] .x mymacro.C
4530 /// ~~~
4531 /// In mymacro.C
4532 /// ~~~ {.cpp}
4533 /// TCling::GetCurrentMacroName() returns ./mymacro.C
4534 /// TCling::GetTopLevelMacroName() returns ./mymacro.C
4535 /// ~~~
4536 /// Now calling inclfile...
4537 /// In inclfile.h
4538 /// ~~~ {.cpp}
4539 /// TCling::GetCurrentMacroName() returns inclfile.C
4540 /// TCling::GetTopLevelMacroName() returns ./mymacro.C
4541 /// ~~~
4542 
4543 const char* TCling::GetCurrentMacroName() const
4544 {
4545 #if defined(R__MUST_REVISIT)
4546 #if R__MUST_REVISIT(6,0)
4547  Warning("GetCurrentMacroName", "Must change return type!");
4548 #endif
4549 #endif
4550  return fCurExecutingMacros.back();
4551 }
4552 
4553 ////////////////////////////////////////////////////////////////////////////////
4554 /// Return the absolute type of typeDesc.
4555 /// E.g.: typeDesc = "class TNamed**", returns "TNamed".
4556 /// You need to use the result immediately before it is being overwritten.
4557 
4558 const char* TCling::TypeName(const char* typeDesc)
4559 {
4560  TTHREAD_TLS(char*) t = 0;
4561  TTHREAD_TLS(unsigned int) tlen = 0;
4562 
4563  unsigned int dlen = strlen(typeDesc);
4564  if (dlen > tlen) {
4565  delete[] t;
4566  t = new char[dlen + 1];
4567  tlen = dlen;
4568  }
4569  const char* s, *template_start;
4570  if (!strstr(typeDesc, "(*)(")) {
4571  s = strchr(typeDesc, ' ');
4572  template_start = strchr(typeDesc, '<');
4573  if (!strcmp(typeDesc, "long long")) {
4574  strlcpy(t, typeDesc, dlen + 1);
4575  }
4576  else if (!strncmp(typeDesc, "unsigned ", s + 1 - typeDesc)) {
4577  strlcpy(t, typeDesc, dlen + 1);
4578  }
4579  // s is the position of the second 'word' (if any)
4580  // except in the case of templates where there will be a space
4581  // just before any closing '>': eg.
4582  // TObj<std::vector<UShort_t,__malloc_alloc_template<0> > >*
4583  else if (s && (template_start == 0 || (s < template_start))) {
4584  strlcpy(t, s + 1, dlen + 1);
4585  }
4586  else {
4587  strlcpy(t, typeDesc, dlen + 1);
4588  }
4589  }
4590  else {
4591  strlcpy(t, typeDesc, dlen + 1);
4592  }
4593  int l = strlen(t);
4594  while (l > 0 && (t[l - 1] == '*' || t[l - 1] == '&')) {
4595  t[--l] = 0;
4596  }
4597  return t;
4598 }
4599 
4600 ////////////////////////////////////////////////////////////////////////////////
4601 /// Read and parse a rootmapfile in its new format, and return 0 in case of
4602 /// success, -1 if the file has already been read, and -3 in case its format
4603 /// is the old one (e.g. containing "Library.ClassName")
4604 
4605 int TCling::ReadRootmapFile(const char *rootmapfile, TUniqueString *uniqueString)
4606 {
4607  // For "class ", "namespace ", "typedef ", "header ", "enum ", "var " respectively
4608  const std::map<char, unsigned int> keyLenMap = {{'c',6},{'n',10},{'t',8},{'h',7},{'e',5},{'v',4}};
4609 
4610  if (rootmapfile && *rootmapfile) {
4611 
4612  // Add content of a specific rootmap file
4613  if (fRootmapFiles->FindObject(rootmapfile)) return -1;
4614  std::ifstream file(rootmapfile);
4615  std::string line; line.reserve(200);
4616  std::string lib_name; line.reserve(100);
4617  bool newFormat=false;
4618  while (getline(file, line, '\n')) {
4619  if (!newFormat &&
4620  (strstr(line.c_str(),"Library.")!=nullptr || strstr(line.c_str(),"Declare.")!=nullptr)) {
4621  file.close();
4622  return -3; // old format
4623  }
4624  newFormat=true;
4625 
4626  if (line.compare(0, 9, "{ decls }") == 0) {
4627  // forward declarations
4628 
4629  while (getline(file, line, '\n')) {
4630  if (line[0] == '[') break;
4631  uniqueString->Append(line);
4632  }
4633  }
4634  const char firstChar=line[0];
4635  if (firstChar == '[') {
4636  // new section (library)
4637  auto brpos = line.find(']');
4638  if (brpos == string::npos) continue;
4639  lib_name = line.substr(1, brpos-1);
4640  size_t nspaces = 0;
4641  while( lib_name[nspaces] == ' ' ) ++nspaces;
4642  if (nspaces) lib_name.replace(0, nspaces, "");
4643  if (gDebug > 3) {
4644  TString lib_nameTstr(lib_name.c_str());
4645  TObjArray* tokens = lib_nameTstr.Tokenize(" ");
4646  const char* lib = ((TObjString *)tokens->At(0))->GetName();
4647  const char* wlib = gSystem->DynamicPathName(lib, kTRUE);
4648  if (wlib) {
4649  Info("ReadRootmapFile", "new section for %s", lib_nameTstr.Data());
4650  }
4651  else {
4652  Info("ReadRootmapFile", "section for %s (library does not exist)", lib_nameTstr.Data());
4653  }
4654  delete[] wlib;
4655  delete tokens;
4656  }
4657  }
4658  else {
4659  auto keyLenIt = keyLenMap.find(firstChar);
4660  if (keyLenIt == keyLenMap.end()) continue;
4661  unsigned int keyLen = keyLenIt->second;
4662  // Do not make a copy, just start after the key
4663  const char *keyname = line.c_str()+keyLen;
4664  if (gDebug > 6)
4665  Info("ReadRootmapFile", "class %s in %s", keyname, lib_name.c_str());
4666  TEnvRec* isThere = fMapfile->Lookup(keyname);
4667  if (isThere){
4668  if(lib_name != isThere->GetValue()){ // the same key for two different libs
4669  if (firstChar == 'n') {
4670  if (gDebug > 3)
4671  Info("ReadRootmapFile", "namespace %s found in %s is already in %s",
4672  keyname, lib_name.c_str(), isThere->GetValue());
4673  } else if (firstChar == 'h'){ // it is a header: add the libname to the list of libs to be loaded.
4674  lib_name+=" ";
4675  lib_name+=isThere->GetValue();
4676  fMapfile->SetValue(keyname, lib_name.c_str());
4677  }
4678  else if (!TClassEdit::IsSTLCont(keyname)) {
4679  Warning("ReadRootmapFile", "%s %s found in %s is already in %s", line.substr(0, keyLen).c_str(),
4680  keyname, lib_name.c_str(), isThere->GetValue());
4681  }
4682  } else { // the same key for the same lib
4683  if (gDebug > 3)
4684  Info("ReadRootmapFile","Key %s was already defined for %s", keyname, lib_name.c_str());
4685  }
4686 
4687  } else {
4688  fMapfile->SetValue(keyname, lib_name.c_str());
4689  }
4690  }
4691  }
4692  file.close();
4693  }
4694 
4695  return 0;
4696 }
4697 
4698 ////////////////////////////////////////////////////////////////////////////////
4699 /// Create a resource table and read the (possibly) three resource files, i.e
4700 /// $ROOTSYS/etc/system<name> (or ROOTETCDIR/system<name>), $HOME/<name> and
4701 /// ./<name>. ROOT always reads ".rootrc" (in TROOT::InitSystem()). You can
4702 /// read additional user defined resource files by creating additional TEnv
4703 /// objects. By setting the shell variable ROOTENV_NO_HOME=1 the reading of
4704 /// the $HOME/<name> resource file will be skipped. This might be useful in
4705 /// case the home directory resides on an automounted remote file system
4706 /// and one wants to avoid the file system from being mounted.
4707 
4709 {
4711 
4712  fMapfile->SetRcName(name);
4713 
4714  TString sname = "system";
4715  sname += name;
4716 #ifdef ROOTETCDIR
4717  char *s = gSystem->ConcatFileName(ROOTETCDIR, sname);
4718 #else
4719  TString etc = gRootDir;
4720 #ifdef WIN32
4721  etc += "\\etc";
4722 #else
4723  etc += "/etc";
4724 #endif
4725 #if defined(R__MACOSX) && (TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR)
4726  // on iOS etc does not exist and system<name> resides in $ROOTSYS
4727  etc = gRootDir;
4728 #endif
4729  char *s = gSystem->ConcatFileName(etc, sname);
4730 #endif
4731 
4732  Int_t ret = ReadRootmapFile(s);
4733  if (ret == -3) // old format
4735  delete [] s;
4736  if (!gSystem->Getenv("ROOTENV_NO_HOME")) {
4738  ret = ReadRootmapFile(s);
4739  if (ret == -3) // old format
4740  fMapfile->ReadFile(s, kEnvUser);
4741  delete [] s;
4742  if (strcmp(gSystem->HomeDirectory(), gSystem->WorkingDirectory())) {
4743  ret = ReadRootmapFile(name);
4744  if (ret == -3) // old format
4745  fMapfile->ReadFile(name, kEnvLocal);
4746  }
4747  } else {
4748  ret = ReadRootmapFile(name);
4749  if (ret == -3) // old format
4750  fMapfile->ReadFile(name, kEnvLocal);
4751  }
4752  fMapfile->IgnoreDuplicates(ignore);
4753 }
4754 
4755 
4756 namespace {
4757  using namespace clang;
4758 
4759  class ExtVisibleStorageAdder: public RecursiveASTVisitor<ExtVisibleStorageAdder>{
4760  // This class is to be considered an helper for autoloading.
4761  // It is a recursive visitor is used to inspect namespaces coming from
4762  // forward declarations in rootmaps and to set the external visible
4763  // storage flag for them.
4764  public:
4765  ExtVisibleStorageAdder(std::unordered_set<const NamespaceDecl*>& nsSet): fNSSet(nsSet) {};
4766  bool VisitNamespaceDecl(NamespaceDecl* nsDecl) {
4767  // We want to enable the external lookup for this namespace
4768  // because it may shadow the lookup of other names contained
4769  // in that namespace
4770  nsDecl->setHasExternalVisibleStorage();
4771  fNSSet.insert(nsDecl);
4772  return true;
4773  }
4774  private:
4775  std::unordered_set<const NamespaceDecl*>& fNSSet;
4776 
4777  };
4778 }
4779 
4780 ////////////////////////////////////////////////////////////////////////////////
4781 /// Load map between class and library. If rootmapfile is specified a
4782 /// specific rootmap file can be added (typically used by ACLiC).
4783 /// In case of error -1 is returned, 0 otherwise.
4784 /// The interpreter uses this information to automatically load the shared
4785 /// library for a class (autoload mechanism), see the AutoLoad() methods below.
4786 
4787 Int_t TCling::LoadLibraryMap(const char* rootmapfile)
4788 {
4790  // open the [system].rootmap files
4791  if (!fMapfile) {
4792  fMapfile = new TEnv();
4794 // fMapNamespaces = new THashTable();
4795 // fMapNamespaces->SetOwner();
4796  fRootmapFiles = new TObjArray;
4798  InitRootmapFile(".rootmap");
4799  }
4800 
4801  // Prepare a list of all forward declarations for cling
4802  // For some experiments it is easily as big as 500k characters. To be on the
4803  // safe side, we go for 1M.
4804  TUniqueString uniqueString(1048576);
4805 
4806  // Load all rootmap files in the dynamic load path ((DY)LD_LIBRARY_PATH, etc.).
4807  // A rootmap file must end with the string ".rootmap".
4808  TString ldpath = gSystem->GetDynamicPath();
4809  if (ldpath != fRootmapLoadPath) {
4810  fRootmapLoadPath = ldpath;
4811 #ifdef WIN32
4812  TObjArray* paths = ldpath.Tokenize(";");
4813 #else
4814  TObjArray* paths = ldpath.Tokenize(":");
4815 #endif
4816  TString d;
4817  for (Int_t i = 0; i < paths->GetEntriesFast(); i++) {
4818  d = ((TObjString *)paths->At(i))->GetString();
4819  // check if directory already scanned
4820  Int_t skip = 0;
4821  for (Int_t j = 0; j < i; j++) {
4822  TString pd = ((TObjString *)paths->At(j))->GetString();
4823  if (pd == d) {
4824  skip++;
4825  break;
4826  }
4827  }
4828  if (!skip) {
4829  void* dirp = gSystem->OpenDirectory(d);
4830  if (dirp) {
4831  if (gDebug > 3) {
4832  Info("LoadLibraryMap", "%s", d.Data());
4833  }
4834  const char* f1;
4835  while ((f1 = gSystem->GetDirEntry(dirp))) {
4836  TString f = f1;
4837  if (f.EndsWith(".rootmap")) {
4838  TString p;
4839  p = d + "/" + f;
4841  if (!fRootmapFiles->FindObject(f) && f != ".rootmap") {
4842  if (gDebug > 4) {
4843  Info("LoadLibraryMap", " rootmap file: %s", p.Data());
4844  }
4845  Int_t ret = ReadRootmapFile(p,&uniqueString);
4846  if (ret == 0)
4847  fRootmapFiles->Add(new TNamed(gSystem->BaseName(f), p.Data()));
4848  if (ret == -3) {
4849  // old format
4851  fRootmapFiles->Add(new TNamed(f, p));
4852  }
4853  }
4854  // else {
4855  // fprintf(stderr,"Reject %s because %s is already there\n",p.Data(),f.Data());
4856  // fRootmapFiles->FindObject(f)->ls();
4857  // }
4858  }
4859  }
4860  if (f.BeginsWith("rootmap")) {
4861  TString p;
4862  p = d + "/" + f;
4863  FileStat_t stat;
4864  if (gSystem->GetPathInfo(p, stat) == 0 && R_ISREG(stat.fMode)) {
4865  Warning("LoadLibraryMap", "please rename %s to end with \".rootmap\"", p.Data());
4866  }
4867  }
4868  }
4869  }
4870  gSystem->FreeDirectory(dirp);
4871  }
4872  }
4873  delete paths;
4874  if (!fMapfile->GetTable()->GetEntries()) {
4875  return -1;
4876  }
4877  }
4878  if (rootmapfile && *rootmapfile) {
4879  Int_t res = ReadRootmapFile(rootmapfile, &uniqueString);
4880  if (res == 0) {
4881  //TString p = gSystem->ConcatFileName(gSystem->pwd(), rootmapfile);
4882  //fRootmapFiles->Add(new TNamed(gSystem->BaseName(rootmapfile), p.Data()));
4883  fRootmapFiles->Add(new TNamed(gSystem->BaseName(rootmapfile), rootmapfile));
4884  }
4885  else if (res == -3) {
4886  // old format
4888  fMapfile->ReadFile(rootmapfile, kEnvGlobal);
4889  fRootmapFiles->Add(new TNamed(gSystem->BaseName(rootmapfile), rootmapfile));
4890  fMapfile->IgnoreDuplicates(ignore);
4891  }
4892  }
4893  TEnvRec* rec;
4894  TIter next(fMapfile->GetTable());
4895  while ((rec = (TEnvRec*) next())) {
4896  TString cls = rec->GetName();
4897  if (!strncmp(cls.Data(), "Library.", 8) && cls.Length() > 8) {
4898  // get the first lib from the list of lib and dependent libs
4899  TString libs = rec->GetValue();
4900  if (libs == "") {
4901  continue;
4902  }
4903  TString delim(" ");
4904  TObjArray* tokens = libs.Tokenize(delim);
4905  const char* lib = ((TObjString*)tokens->At(0))->GetName();
4906  // convert "@@" to "::", we used "@@" because TEnv
4907  // considers "::" a terminator
4908  cls.Remove(0, 8);
4909  cls.ReplaceAll("@@", "::");
4910  // convert "-" to " ", since class names may have
4911  // blanks and TEnv considers a blank a terminator
4912  cls.ReplaceAll("-", " ");
4913  if (gDebug > 6) {
4914  const char* wlib = gSystem->DynamicPathName(lib, kTRUE);
4915  if (wlib) {
4916  Info("LoadLibraryMap", "class %s in %s", cls.Data(), wlib);
4917  }
4918  else {
4919  Info("LoadLibraryMap", "class %s in %s (library does not exist)", cls.Data(), lib);
4920  }
4921  delete[] wlib;
4922  }
4923  // Fill in the namespace candidate list
4924 // Ssiz_t last = cls.Last(':');
4925 // if (last != kNPOS) {
4926 // // Please note that the funny op overload does substring.
4927 // TString namespaceCand = cls(0, last - 1);
4928 // // This is a reference to a substring that lives in fMapfile
4929 // if (!fMapNamespaces->FindObject(namespaceCand.Data()))
4930 // fMapNamespaces->Add(new TNamed(namespaceCand.Data(), ""));
4931 // }
4932  delete tokens;
4933  }
4934  else if (!strncmp(cls.Data(), "Declare.", 8) && cls.Length() > 8) {
4935  cls.Remove(0, 8);
4936  // convert "-" to " ", since class names may have
4937  // blanks and TEnv considers a blank a terminator
4938  cls.ReplaceAll("-", " ");
4939  fInterpreter->declare(cls.Data());
4940  }
4941  }
4942 
4943  // Process the forward declarations collected
4944  cling::Transaction* T = nullptr;
4945  auto compRes= fInterpreter->declare(uniqueString.Data(), &T);
4946  assert(cling::Interpreter::kSuccess == compRes && "A declaration in a rootmap could not be compiled");
4947 
4948  if (compRes!=cling::Interpreter::kSuccess){
4949  Warning("LoadLibraryMap",
4950  "Problems in %s declaring '%s' were encountered.", rootmapfile, uniqueString.Data()) ;
4951  }
4952 
4953  if (T){
4954  ExtVisibleStorageAdder evsAdder(fNSFromRootmaps);
4955  for (auto declIt = T->decls_begin(); declIt < T->decls_end(); ++declIt) {
4956  if (declIt->m_DGR.isSingleDecl()) {
4957  if (Decl* D = declIt->m_DGR.getSingleDecl()) {
4958  if (NamespaceDecl* NSD = dyn_cast<NamespaceDecl>(D)) {
4959  evsAdder.TraverseDecl(NSD);
4960  }
4961  }
4962  }
4963  }
4964  }
4965 
4966  // clear duplicates
4967 
4968  return 0;
4969 }
4970 
4971 ////////////////////////////////////////////////////////////////////////////////
4972 /// Scan again along the dynamic path for library maps. Entries for the loaded
4973 /// shared libraries are unloaded first. This can be useful after reseting
4974 /// the dynamic path through TSystem::SetDynamicPath()
4975 /// In case of error -1 is returned, 0 otherwise.
4976 
4978 {
4980  LoadLibraryMap();
4981  return 0;
4982 }
4983 
4984 ////////////////////////////////////////////////////////////////////////////////
4985 /// Reload the library map entries coming from all the loaded shared libraries,
4986 /// after first unloading the current ones.
4987 /// In case of error -1 is returned, 0 otherwise.
4988 
4990 {
4991  const TString sharedLibLStr = GetSharedLibs();
4992  const TObjArray* sharedLibL = sharedLibLStr.Tokenize(" ");
4993  const Int_t nrSharedLibs = sharedLibL->GetEntriesFast();
4994  for (Int_t ilib = 0; ilib < nrSharedLibs; ilib++) {
4995  const TString sharedLibStr = ((TObjString*)sharedLibL->At(ilib))->GetString();
4996  const TString sharedLibBaseStr = gSystem->BaseName(sharedLibStr);
4997  const Int_t ret = UnloadLibraryMap(sharedLibBaseStr);
4998  if (ret < 0) {
4999  continue;
5000  }
5001  TString rootMapBaseStr = sharedLibBaseStr;
5002  if (sharedLibBaseStr.EndsWith(".dll")) {
5003  rootMapBaseStr.ReplaceAll(".dll", "");
5004  }
5005  else if (sharedLibBaseStr.EndsWith(".DLL")) {
5006  rootMapBaseStr.ReplaceAll(".DLL", "");
5007  }
5008  else if (sharedLibBaseStr.EndsWith(".so")) {
5009  rootMapBaseStr.ReplaceAll(".so", "");
5010  }
5011  else if (sharedLibBaseStr.EndsWith(".sl")) {
5012  rootMapBaseStr.ReplaceAll(".sl", "");
5013  }
5014  else if (sharedLibBaseStr.EndsWith(".dl")) {
5015  rootMapBaseStr.ReplaceAll(".dl", "");
5016  }
5017  else if (sharedLibBaseStr.EndsWith(".a")) {
5018  rootMapBaseStr.ReplaceAll(".a", "");
5019  }
5020  else {
5021  Error("ReloadAllSharedLibraryMaps", "Unknown library type %s", sharedLibBaseStr.Data());
5022  delete sharedLibL;
5023  return -1;
5024  }
5025  rootMapBaseStr += ".rootmap";
5026  const char* rootMap = gSystem->Which(gSystem->GetDynamicPath(), rootMapBaseStr);
5027  if (!rootMap) {
5028  Error("ReloadAllSharedLibraryMaps", "Could not find rootmap %s in path", rootMap);
5029  delete[] rootMap;
5030  delete sharedLibL;
5031  return -1;
5032  }
5033  const Int_t status = LoadLibraryMap(rootMap);
5034  if (status < 0) {
5035  Error("ReloadAllSharedLibraryMaps", "Error loading map %s", rootMap);
5036  delete[] rootMap;
5037  delete sharedLibL;
5038  return -1;
5039  }
5040  delete[] rootMap;
5041  }
5042  delete sharedLibL;
5043  return 0;
5044 }
5045 
5046 ////////////////////////////////////////////////////////////////////////////////
5047 /// Unload the library map entries coming from all the loaded shared libraries.
5048 /// Returns 0 if succesful
5049 
5051 {
5052  const TString sharedLibLStr = GetSharedLibs();
5053  const TObjArray* sharedLibL = sharedLibLStr.Tokenize(" ");
5054  for (Int_t ilib = 0; ilib < sharedLibL->GetEntriesFast(); ilib++) {
5055  const TString sharedLibStr = ((TObjString*)sharedLibL->At(ilib))->GetString();
5056  const TString sharedLibBaseStr = gSystem->BaseName(sharedLibStr);
5057  UnloadLibraryMap(sharedLibBaseStr);
5058  }
5059  delete sharedLibL;
5060  return 0;
5061 }
5062 
5063 ////////////////////////////////////////////////////////////////////////////////
5064 /// Unload library map entries coming from the specified library.
5065 /// Returns -1 in case no entries for the specified library were found,
5066 /// 0 otherwise.
5067 
5068 Int_t TCling::UnloadLibraryMap(const char* library)
5069 {
5070  if (!fMapfile || !library || !*library) {
5071  return 0;
5072  }
5073  TString libname(library);
5074  Ssiz_t idx = libname.Last('.');
5075  if (idx != kNPOS) {
5076  libname.Remove(idx);
5077  }
5078  size_t len = libname.Length();
5079  TEnvRec *rec;
5080  TIter next(fMapfile->GetTable());
5082  Int_t ret = 0;
5083  while ((rec = (TEnvRec *) next())) {
5084  TString cls = rec->GetName();
5085  if (cls.Length() > 2) {
5086  // get the first lib from the list of lib and dependent libs
5087  TString libs = rec->GetValue();
5088  if (libs == "") {
5089  continue;
5090  }
5091  TString delim(" ");
5092  TObjArray* tokens = libs.Tokenize(delim);
5093  const char* lib = ((TObjString *)tokens->At(0))->GetName();
5094  if (!strncmp(cls.Data(), "Library.", 8) && cls.Length() > 8) {
5095  // convert "@@" to "::", we used "@@" because TEnv
5096  // considers "::" a terminator
5097  cls.Remove(0, 8);
5098  cls.ReplaceAll("@@", "::");
5099  // convert "-" to " ", since class names may have
5100  // blanks and TEnv considers a blank a terminator
5101  cls.ReplaceAll("-", " ");
5102  }
5103  if (!strncmp(lib, libname.Data(), len)) {
5104  if (fMapfile->GetTable()->Remove(rec) == 0) {
5105  Error("UnloadLibraryMap", "entry for <%s, %s> not found in library map table", cls.Data(), lib);
5106  ret = -1;
5107  }
5108  }
5109  delete tokens;
5110  }
5111  }
5112  if (ret >= 0) {
5113  TString library_rootmap(library);
5114  if (!library_rootmap.EndsWith(".rootmap"))
5115  library_rootmap.Append(".rootmap");
5116  TNamed* mfile = 0;
5117  while ((mfile = (TNamed *)fRootmapFiles->FindObject(library_rootmap))) {
5118  fRootmapFiles->Remove(mfile);
5119  delete mfile;
5120  }
5122  }
5123  return ret;
5124 }
5125 
5126 ////////////////////////////////////////////////////////////////////////////////
5127 /// Register the autoloading information for a class.
5128 /// libs is a space separated list of libraries.
5129 
5130 Int_t TCling::SetClassSharedLibs(const char *cls, const char *libs)
5131 {
5132  if (!cls || !*cls)
5133  return 0;
5134 
5135  TString key = TString("Library.") + cls;
5136  // convert "::" to "@@", we used "@@" because TEnv
5137  // considers "::" a terminator
5138  key.ReplaceAll("::", "@@");
5139  // convert "-" to " ", since class names may have
5140  // blanks and TEnv considers a blank a terminator
5141  key.ReplaceAll(" ", "-");
5142 
5144  if (!fMapfile) {
5145  fMapfile = new TEnv();
5147 // fMapNamespaces = new THashTable();
5148 // fMapNamespaces->SetOwner();
5149 
5150  fRootmapFiles = new TObjArray;
5152 
5153  InitRootmapFile(".rootmap");
5154  }
5155  //fMapfile->SetValue(key, libs);
5156  fMapfile->SetValue(cls, libs);
5157  return 1;
5158 }
5159 
5160 ////////////////////////////////////////////////////////////////////////////////
5161 /// Demangle the name (from the typeinfo) and then request the class
5162 /// via the usual name based interface (TClass::GetClass).
5163 
5164 TClass *TCling::GetClass(const std::type_info& typeinfo, Bool_t load) const
5165 {
5166  int err = 0;
5167  char* demangled_name = TClassEdit::DemangleTypeIdName(typeinfo, err);
5168  if (err) return 0;
5169  TClass* theClass = TClass::GetClass(demangled_name, load, kTRUE);
5170  free(demangled_name);
5171  return theClass;
5172 }
5173 
5174 ////////////////////////////////////////////////////////////////////////////////
5175 /// Load library containing the specified class. Returns 0 in case of error
5176 /// and 1 in case if success.
5177 
5178 Int_t TCling::AutoLoad(const std::type_info& typeinfo, Bool_t knowDictNotLoaded /* = kFALSE */)
5179 {
5180  int err = 0;
5181  char* demangled_name_c = TClassEdit::DemangleTypeIdName(typeinfo, err);
5182  if (err) {
5183  return 0;
5184  }
5185 
5186  std::string demangled_name(demangled_name_c);
5187  free(demangled_name_c);
5188 
5189  // AutoLoad expects (because TClass::GetClass already prepares it that way) a
5190  // shortened name.
5191  TClassEdit::TSplitType splitname( demangled_name.c_str(), (TClassEdit::EModType)(TClassEdit::kLong64 | TClassEdit::kDropStd) );
5192  splitname.ShortType(demangled_name, TClassEdit::kDropStlDefault | TClassEdit::kDropStd);
5193 
5194  // No need to worry about typedef, they aren't any ... but there are
5195  // inlined namespaces ...
5196 
5197  Int_t result = AutoLoad(demangled_name.c_str());
5198  if (result == 0) {
5199  demangled_name = TClassEdit::GetLong64_Name(demangled_name);
5200  result = AutoLoad(demangled_name.c_str(), knowDictNotLoaded);
5201  }
5202 
5203  return result;
5204 }
5205 
5206 ////////////////////////////////////////////////////////////////////////////////
5207 /// Load library containing the specified class. Returns 0 in case of error
5208 /// and 1 in case if success.
5209 
5210 Int_t TCling::AutoLoad(const char *cls, Bool_t knowDictNotLoaded /* = kFALSE */)
5211 {
5213 
5214  if (!knowDictNotLoaded && gClassTable->GetDictNorm(cls)) {
5215  // The library is already loaded as the class's dictionary is known.
5216  // Return success.
5217  // Note: the name (cls) is expected to be normalized as it comes either
5218  // from a callbacks (that can/should calculate the normalized name from the
5219  // decl) or from TClass::GetClass (which does also calculate the normalized
5220  // name).
5221  return 1;
5222  }
5223 
5224  if (gDebug > 2) {
5225  Info("TCling::AutoLoad",
5226  "Trying to autoload for %s", cls);
5227  }
5228 
5229  Int_t status = 0;
5230  if (!gROOT || !gInterpreter || gROOT->TestBit(TObject::kInvalidObject)) {
5231  if (gDebug > 2) {
5232  Info("TCling::AutoLoad",
5233  "Disabled due to gROOT or gInterpreter being invalid/not ready (the class name is %s)", cls);
5234  }
5235  return status;
5236  }
5237  if (!fAllowLibLoad) {
5238  // Never load any library from rootcling/genreflex.
5239  if (gDebug > 2) {
5240  Info("TCling::AutoLoad",
5241  "Explicitly disabled (the class name is %s)", cls);
5242  }
5243  return 0;
5244  }
5245  // Prevent the recursion when the library dictionary are loaded.
5246  Int_t oldvalue = SetClassAutoloading(false);
5247  // Try using externally provided callback first.
5248  if (fAutoLoadCallBack) {
5249  int success = (*(AutoLoadCallBack_t)fAutoLoadCallBack)(cls);
5250  if (success) {
5251  SetClassAutoloading(oldvalue);
5252  return success;
5253  }
5254  }
5255  // lookup class to find list of dependent libraries
5256  TString deplibs = GetClassSharedLibs(cls);
5257  if (!deplibs.IsNull()) {
5258  TString delim(" ");
5259  TObjArray* tokens = deplibs.Tokenize(delim);
5260  for (Int_t i = (tokens->GetEntriesFast() - 1); i > 0; --i) {
5261  const char* deplib = ((TObjString*)tokens->At(i))->GetName();
5262  if (gROOT->LoadClass(cls, deplib) == 0) {
5263  if (gDebug > 0) {
5264  Info("TCling::AutoLoad",
5265  "loaded dependent library %s for %s", deplib, cls);
5266  }
5267  }
5268  else {
5269  Error("TCling::AutoLoad",
5270  "failure loading dependent library %s for %s",
5271  deplib, cls);
5272  }
5273  }
5274  const char* lib = ((TObjString*)tokens->At(0))->GetName();
5275  if (lib && lib[0]) {
5276  if (gROOT->LoadClass(cls, lib) == 0) {
5277  if (gDebug > 0) {
5278  Info("TCling::AutoLoad",
5279  "loaded library %s for %s", lib, cls);
5280  }
5281  status = 1;
5282  }
5283  else {
5284  Error("TCling::AutoLoad",
5285  "failure loading library %s for %s", lib, cls);
5286  }
5287  }
5288  delete tokens;
5289  }
5290 
5291  SetClassAutoloading(oldvalue);
5292  return status;
5293 }
5294 
5295 ////////////////////////////////////////////////////////////////////////////////
5296 /// Parse the payload or header.
5297 
5298 static cling::Interpreter::CompilationResult ExecAutoParse(const char *what,
5299  Bool_t header,
5300  cling::Interpreter *interpreter)
5301 {
5302  // Save state of the PP
5303  Sema &SemaR = interpreter->getSema();
5304  ASTContext& C = SemaR.getASTContext();
5305  Preprocessor &PP = SemaR.getPreprocessor();
5306  Parser& P = const_cast<Parser&>(interpreter->getParser());
5307  Preprocessor::CleanupAndRestoreCacheRAII cleanupRAII(PP);
5308  Parser::ParserCurTokRestoreRAII savedCurToken(P);
5309  // After we have saved the token reset the current one to something which
5310  // is safe (semi colon usually means empty decl)
5311  Token& Tok = const_cast<Token&>(P.getCurToken());
5312  Tok.setKind(tok::semi);
5313 
5314  // We can't PushDeclContext, because we go up and the routine that pops
5315  // the DeclContext assumes that we drill down always.
5316  // We have to be on the global context. At that point we are in a
5317  // wrapper function so the parent context must be the global.
5318  Sema::ContextAndScopeRAII pushedDCAndS(SemaR, C.getTranslationUnitDecl(),
5319  SemaR.TUScope);
5320  std::string code = gNonInterpreterClassDef ;
5321  if (!header) {
5322  // This is the complete header file content and not the
5323  // name of a header.
5324  code += what;
5325 
5326  } else {
5327  code += ("#include \"");
5328  code += what;
5329  code += "\"\n";
5330  }
5331  code += ("#ifdef __ROOTCLING__\n"
5332  "#undef __ROOTCLING__\n"
5333  + gInterpreterClassDef +
5334  "#endif");
5335 
5336  cling::Interpreter::CompilationResult cr;
5337  {
5338  // scope within which diagnostics are de-activated
5339  // For now we disable diagnostics because we saw them already at
5340  // dictionary generation time. That won't be an issue with the PCMs.
5341 
5342  clangDiagSuppr diagSuppr(SemaR.getDiagnostics());
5343 
5344  #if defined(R__MUST_REVISIT)
5345  #if R__MUST_REVISIT(6,2)
5346  Warning("TCling::RegisterModule","Diagnostics suppression should be gone by now.");
5347  #endif
5348  #endif
5349 
5350  cr = interpreter->parseForModule(code);
5351  }
5352  return cr;
5353 }
5354 
5355 ////////////////////////////////////////////////////////////////////////////////
5356 /// Helper routine for TCling::AutoParse implementing the actual call to the
5357 /// parser and looping over template parameters (if
5358 /// any) and when they don't have a registered header to autoparse,
5359 /// recurse over their template parameters.
5360 ///
5361 /// Returns the number of header parsed.
5362 
5363 UInt_t TCling::AutoParseImplRecurse(const char *cls, bool topLevel)
5364 {
5365  // We assume the lock has already been taken.
5366  // R__LOCKGUARD(gInterpreterMutex);
5367 
5368  Int_t nHheadersParsed = 0;
5369 
5370  // Loop on the possible autoparse keys
5371  bool skipFirstEntry = false;
5372  std::vector<std::string> autoparseKeys;
5373  if (strchr(cls, '<')) {
5374  int nestedLoc = 0;
5375  TClassEdit::GetSplit(cls, autoparseKeys, nestedLoc, TClassEdit::kDropTrailStar);
5376  // Check if we can skip the name of the template in the autoparses
5377  // Take all the scopes one by one. If all of them are in the AST, we do not
5378  // need to autoparse for that particular template.
5379  if (!autoparseKeys.empty()){
5380  TString templateName(autoparseKeys[0]);
5381  auto tokens = templateName.Tokenize("::");
5382  clang::NamedDecl* previousScopeAsNamedDecl = nullptr;
5383  clang::DeclContext* previousScopeAsContext = fInterpreter->getCI()->getASTContext().getTranslationUnitDecl();
5384  if (TClassEdit::IsStdClass(cls))
5385  previousScopeAsContext = fInterpreter->getSema().getStdNamespace();
5386  for (auto const scopeObj : *tokens){
5387  auto scopeName = ((TObjString*) scopeObj)->String().Data();
5388  previousScopeAsNamedDecl = cling::utils::Lookup::Named(&fInterpreter->getSema(), scopeName, previousScopeAsContext);
5389  // Check if we have multiple nodes in the AST with this name
5390  if ((clang::NamedDecl*)-1 == previousScopeAsNamedDecl) break;
5391  previousScopeAsContext = llvm::dyn_cast_or_null<clang::DeclContext>(previousScopeAsNamedDecl);
5392  if (!previousScopeAsContext) break; // this is not a context
5393  }
5394  delete tokens;
5395  // Now, let's check if the last scope, the template, has a definition, i.e. it's not a fwd decl
5396  if ((clang::NamedDecl*)-1 != previousScopeAsNamedDecl) {
5397  if (auto templateDecl = llvm::dyn_cast_or_null<clang::ClassTemplateDecl>(previousScopeAsNamedDecl)) {
5398  if (auto templatedDecl = templateDecl->getTemplatedDecl()) {
5399  skipFirstEntry = nullptr != templatedDecl->getDefinition();
5400  }
5401  }
5402  }
5403 
5404  }
5405  }
5406  if (topLevel) autoparseKeys.emplace_back(cls);
5407 
5408  for (const auto & apKeyStr : autoparseKeys) {
5409  if (skipFirstEntry) {
5410  skipFirstEntry=false;
5411  continue;
5412  }
5413  if (apKeyStr.empty()) continue;
5414  const char *apKey = apKeyStr.c_str();
5415  std::size_t normNameHash(fStringHashFunction(apKey));
5416  // If the class was not looked up
5417  if (gDebug > 1) {
5418  Info("TCling::AutoParse",
5419  "Starting autoparse for %s\n", apKey);
5420  }
5421  if (fLookedUpClasses.insert(normNameHash).second) {
5422  auto const &iter = fClassesHeadersMap.find(normNameHash);
5423  if (iter != fClassesHeadersMap.end()) {
5424  const cling::Transaction *T = fInterpreter->getCurrentTransaction();
5425  fTransactionHeadersMap.insert({T,normNameHash});
5426  auto const &hNamesPtrs = iter->second;
5427  if (gDebug > 1) {
5428  Info("TCling::AutoParse",
5429  "We can proceed for %s. We have %s headers.", apKey, std::to_string(hNamesPtrs.size()).c_str());
5430  }
5431  for (auto & hName : hNamesPtrs) {
5432  if (fParsedPayloadsAddresses.count(hName) == 1) continue;
5433  if (0 != fPayloads.count(normNameHash)) {
5434  float initRSSval=0.f, initVSIZEval=0.f;
5435  (void) initRSSval; // Avoid unused var warning
5436  (void) initVSIZEval;
5437  if (gDebug > 0) {
5438  Info("AutoParse",
5439  "Parsing full payload for %s", apKey);
5440  ProcInfo_t info;
5441  gSystem->GetProcInfo(&info);
5442  initRSSval = 1e-3*info.fMemResident;
5443  initVSIZEval = 1e-3*info.fMemVirtual;
5444  }
5445  auto cRes = ExecAutoParse(hName, kFALSE, fInterpreter);
5446  if (cRes != cling::Interpreter::kSuccess) {
5447  if (hName[0] == '\n')
5448  Error("AutoParse", "Error parsing payload code for class %s with content:\n%s", apKey, hName);
5449  } else {
5450  fParsedPayloadsAddresses.insert(hName);
5451  nHheadersParsed++;
5452  if (gDebug > 0){
5453  ProcInfo_t info;
5454  gSystem->GetProcInfo(&info);
5455  float endRSSval = 1e-3*info.fMemResident;
5456  float endVSIZEval = 1e-3*info.fMemVirtual;
5457  Info("Autoparse", ">>> RSS key %s - before %.3f MB - after %.3f MB - delta %.3f MB", apKey, initRSSval, endRSSval, endRSSval-initRSSval);
5458  Info("Autoparse", ">>> VSIZE key %s - before %.3f MB - after %.3f MB - delta %.3f MB", apKey, initVSIZEval, endVSIZEval, endVSIZEval-initVSIZEval);
5459  }
5460  }
5461  } else if (!IsLoaded(hName)) {
5462  if (gDebug > 0) {
5463  Info("AutoParse",
5464  "Parsing single header %s", hName);
5465  }
5466  auto cRes = ExecAutoParse(hName, kTRUE, fInterpreter);
5467  if (cRes != cling::Interpreter::kSuccess) {
5468  Error("AutoParse", "Error parsing headerfile %s for class %s.", hName, apKey);
5469  } else {
5470  nHheadersParsed++;
5471  }
5472  }
5473  }
5474  }
5475  else {
5476  // There is no header registered for this class, if this a
5477  // template, it will be instantiated if/when it is requested
5478  // and if we do no load/parse its components we might end up
5479  // not using an eventual specialization.
5480  if (strchr(apKey, '<')) {
5481  nHheadersParsed += AutoParseImplRecurse(apKey, false);
5482  }
5483  }
5484  }
5485  }
5486 
5487  return nHheadersParsed;
5488 
5489 }
5490 
5491 ////////////////////////////////////////////////////////////////////////////////
5492 /// Parse the headers relative to the class
5493 /// Returns 1 in case of success, 0 in case of failure
5494 
5495 Int_t TCling::AutoParse(const char *cls)
5496 {
5498 
5501  return AutoLoad(cls);
5502  } else {
5503  return 0;
5504  }
5505  }
5506 
5507  if (gDebug > 1) {
5508  Info("TCling::AutoParse",
5509  "Trying to autoparse for %s", cls);
5510  }
5511 
5512  // The catalogue of headers is in the dictionary
5514  AutoLoad(cls);
5515  }
5516 
5517  // Prevent the recursion when the library dictionary are loaded.
5518  Int_t oldAutoloadValue = SetClassAutoloading(false);
5519 
5520  // No recursive header parsing on demand; we require headers to be standalone.
5521  SuspendAutoParsing autoParseRAII(this);
5522 
5523  Int_t nHheadersParsed = AutoParseImplRecurse(cls,/*topLevel=*/ true);
5524 
5525  if (nHheadersParsed != 0) {
5526  while (!fClassesToUpdate.empty()) {
5527  TClass *oldcl = fClassesToUpdate.back().first;
5528  if (oldcl->GetState() != TClass::kHasTClassInit) {
5529  // if (gDebug > 2) Info("RegisterModule", "Forcing TClass init for %s", oldcl->GetName());
5530  DictFuncPtr_t dict = fClassesToUpdate.back().second;
5531  fClassesToUpdate.pop_back();
5532  // Calling func could manipulate the list so, let maintain the list
5533  // then call the dictionary function.
5534  TClass *ncl = dict();
5535  if (ncl) ncl->PostLoadCheck();
5536  } else {
5537  fClassesToUpdate.pop_back();
5538  }
5539  }
5540  }
5541 
5542  SetClassAutoloading(oldAutoloadValue);
5543 
5544  return nHheadersParsed > 0 ? 1 : 0;
5545 }
5546 
5547 
5548 ////////////////////////////////////////////////////////////////////////////////
5549 /// Autoload a library based on a missing symbol.
5550 
5551 void* TCling::LazyFunctionCreatorAutoload(const std::string& mangled_name) {
5552  // First see whether the symbol is in the library that we are currently
5553  // loading. It will have access to the symbols of its dependent libraries,
5554  // thus checking "back()" is sufficient.
5555  if (!fRegisterModuleDyLibs.empty()) {
5556  if (void* addr = dlsym(fRegisterModuleDyLibs.back(),
5557  mangled_name.c_str())) {
5558  return addr;
5559  }
5560  }
5561 
5562  int err = 0;
5563  char* demangled_name_c = TClassEdit::DemangleName(mangled_name.c_str(), err);
5564  if (err) {
5565  return 0;
5566  }
5567 
5568  std::string name(demangled_name_c);
5569  free(demangled_name_c);
5570 
5571  //fprintf(stderr, "demangled name: '%s'\n", demangled_name);
5572  //
5573  // Separate out the class or namespace part of the
5574  // function name.
5575  //
5576 
5577  if (!strncmp(name.c_str(), "typeinfo for ", sizeof("typeinfo for ")-1)) {
5578  name.erase(0, sizeof("typeinfo for ")-1);
5579  } else if (!strncmp(name.c_str(), "vtable for ", sizeof("vtable for ")-1)) {
5580  name.erase(0, sizeof("vtable for ")-1);
5581  } else if (!strncmp(name.c_str(), "operator", sizeof("operator")-1)
5582  && !isalnum(name[sizeof("operator")])) {
5583  // operator...(A, B) - let's try with A!
5584  name.erase(0, sizeof("operator")-1);
5585  std::string::size_type pos = name.rfind('(');
5586  if (pos != std::string::npos) {
5587  name.erase(0, pos + 1);
5588  pos = name.find(",");
5589  if (pos != std::string::npos) {
5590  // remove next arg up to end, leaving only the first argument type.
5591  name.erase(pos);
5592  }
5593  pos = name.rfind(" const");
5594  if (pos != std::string::npos) {
5595  name.erase(pos, strlen(" const"));
5596  }
5597  while (!name.empty() && strchr("&*", name.back()))
5598  name.erase(name.length() - 1);
5599  }
5600  } else {
5601  // Remove the function arguments.
5602  std::string::size_type pos = name.rfind('(');
5603  if (pos != std::string::npos) {
5604  name.erase(pos);
5605  }
5606  // Remove the function name.
5607  pos = name.rfind(':');
5608  if (pos != std::string::npos) {
5609  if ((pos != 0) && (name[pos-1] == ':')) {
5610  name.erase(pos-1);
5611  }
5612  }
5613  }
5614  //fprintf(stderr, "name: '%s'\n", name.c_str());
5615  // Now we have the class or namespace name, so do the lookup.
5616  TString libs = GetClassSharedLibs(name.c_str());
5617  if (libs.IsNull()) {
5618  // Not found in the map, all done.
5619  return 0;
5620  }
5621  //fprintf(stderr, "library: %s\n", iter->second.c_str());
5622  // Now we have the name of the libraries to load, so load them.
5623 
5624  TString lib;
5625  Ssiz_t posLib = 0;
5626  while (libs.Tokenize(lib, posLib)) {
5627  if (gSystem->Load(lib, "", kFALSE /*system*/) < 0) {
5628  // The library load failed, all done.
5629  //fprintf(stderr, "load failed: %s\n", errmsg.c_str());
5630  return 0;
5631  }
5632  }
5633 
5634  //fprintf(stderr, "load succeeded.\n");
5635  // Get the address of the function being called.
5636  void* addr = llvm::sys::DynamicLibrary::SearchForAddressOfSymbol(mangled_name.c_str());
5637  //fprintf(stderr, "addr: %016lx\n", reinterpret_cast<unsigned long>(addr));
5638  return addr;
5639 }
5640 
5641 ////////////////////////////////////////////////////////////////////////////////
5642 
5644 {
5645 // if (fMapNamespaces){
5646 // return fMapNamespaces->FindObject(name);
5647 // }
5648  return false;
5649 }
5650 
5651 ////////////////////////////////////////////////////////////////////////////////
5652 
5653 Bool_t TCling::IsAutoLoadNamespaceCandidate(const clang::NamespaceDecl* nsDecl)
5654 {
5655  return fNSFromRootmaps.count(nsDecl) != 0;
5656 }
5657 
5658 ////////////////////////////////////////////////////////////////////////////////
5659 /// Internal function. Inform a TClass about its new TagDecl or NamespaceDecl.
5660 
5661 void TCling::UpdateClassInfoWithDecl(const void* vTD)
5662 {
5663  const NamedDecl* ND = static_cast<const NamedDecl*>(vTD);
5664  const TagDecl* td = dyn_cast<TagDecl>(ND);
5665  std::string name;
5666  TagDecl* tdDef = 0;
5667  if (td) {
5668  tdDef = td->getDefinition();
5669  // Let's pass the decl to the TClass only if it has a definition.
5670  if (!tdDef) return;
5671  td = tdDef;
5672  ND = td;
5673 
5674  if (llvm::isa<clang::FunctionDecl>(td->getDeclContext())) {
5675  // Ignore declaration within a function.
5676  return;
5677  }
5678  clang::QualType type( td->getTypeForDecl(), 0 );
5679 
5680  auto declName=ND->getNameAsString();
5681  if (!TClass::HasNoInfoOrEmuOrFwdDeclaredDecl(declName.c_str())){
5682 // 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 );
5683  return;
5684  }
5685 
5687  } else {
5688  name = ND->getNameAsString();
5689  }
5690 
5691  // Supposedly we are being called while something is being
5692  // loaded ... let's now tell the autoloader to do the work
5693  // yet another time.
5694  int storedAutoloading = SetClassAutoloading(false);
5695  // FIXME: There can be more than one TClass for a single decl.
5696  // for example vector<double> and vector<Double32_t>
5697  TClass* cl = (TClass*)gROOT->GetListOfClasses()->FindObject(name.c_str());
5698  if (cl && GetModTClasses().find(cl) == GetModTClasses().end()) {
5700  if (cci) {
5701  // If we only had a forward declaration then update the
5702  // TClingClassInfo with the definition if we have it now.
5703  const TagDecl* tdOld = llvm::dyn_cast_or_null<TagDecl>(cci->GetDecl());
5704  if (!tdOld || (tdDef && tdDef != tdOld)) {
5705  cl->ResetCaches();
5707  if (td) {
5708  // It's a tag decl, not a namespace decl.
5709  cci->Init(*cci->GetType());
5711  }
5712  }
5713  } else if (!cl->TestBit(TClass::kLoading) && !cl->fHasRootPcmInfo) {
5714  cl->ResetCaches();
5715  // yes, this is almost a waste of time, but we do need to lookup
5716  // the 'type' corresponding to the TClass anyway in order to
5717  // preserve the opaque typedefs (Double32_t)
5718  cl->fClassInfo = (ClassInfo_t *)new TClingClassInfo(fInterpreter, cl->GetName());
5719  // We now need to update the state and bits.
5720  if (cl->fState != TClass::kHasTClassInit) {
5721  // if (!cl->fClassInfo->IsValid()) cl->fState = TClass::kForwardDeclared; else
5724  }
5725  TClass::AddClassToDeclIdMap(((TClingClassInfo*)(cl->fClassInfo))->GetDeclId(), cl);
5726  }
5727  }
5728  SetClassAutoloading(storedAutoloading);
5729 }
5730 
5731 ////////////////////////////////////////////////////////////////////////////////
5732 /// No op: see TClingCallbacks
5733 
5734 void TCling::UpdateClassInfo(char* item, Long_t tagnum)
5735 {
5736 }
5737 
5738 //______________________________________________________________________________
5739 //FIXME: Factor out that function in TClass, because TClass does it already twice
5740 void TCling::UpdateClassInfoWork(const char* item)
5741 {
5742  // This is a no-op as part of the API.
5743  // TCling uses UpdateClassInfoWithDecl() instead.
5744 }
5745 
5746 ////////////////////////////////////////////////////////////////////////////////
5747 /// Update all canvases at end the terminal input command.
5748 
5750 {
5751  TIter next(gROOT->GetListOfCanvases());
5752  TVirtualPad* canvas;
5753  while ((canvas = (TVirtualPad*)next())) {
5754  canvas->Update();
5755  }
5756 }
5757 
5758 ////////////////////////////////////////////////////////////////////////////////
5759 
5760 void TCling::UpdateListsOnCommitted(const cling::Transaction &T) {
5761  std::set<TClass*> modifiedTClasses; // TClasses that require update after this transaction
5762 
5763  // If the transaction does not contain anything we can return earlier.
5764  if (!HandleNewTransaction(T)) return;
5765 
5766  bool isTUTransaction = false;
5767  if (!T.empty() && T.decls_begin() + 1 == T.decls_end() && !T.hasNestedTransactions()) {
5768  clang::Decl* FirstDecl = *(T.decls_begin()->m_DGR.begin());
5769  if (llvm::isa<clang::TranslationUnitDecl>(FirstDecl)) {
5770  // The is the first transaction, we have to expose to meta
5771  // what's already in the AST.
5772  isTUTransaction = true;
5773  }
5774  }
5775 
5776  std::set<const void*> TransactionDeclSet;
5777  if (!isTUTransaction && T.decls_end() - T.decls_begin()) {
5778  const clang::Decl* WrapperFD = T.getWrapperFD();
5779  for (cling::Transaction::const_iterator I = T.decls_begin(), E = T.decls_end();
5780  I != E; ++I) {
5781  if (I->m_Call != cling::Transaction::kCCIHandleTopLevelDecl
5782  && I->m_Call != cling::Transaction::kCCIHandleTagDeclDefinition)
5783  continue;
5784 
5785  for (DeclGroupRef::const_iterator DI = I->m_DGR.begin(),
5786  DE = I->m_DGR.end(); DI != DE; ++DI) {
5787  if (*DI == WrapperFD)
5788  continue;
5789  TransactionDeclSet.insert(*DI);
5790  ((TCling*)gCling)->HandleNewDecl(*DI, false, modifiedTClasses);
5791  }
5792  }
5793  }
5794 
5795  // The above might trigger more decls to be deserialized.
5796  // Thus the iteration over the deserialized decls must be last.
5797  for (cling::Transaction::const_iterator I = T.deserialized_decls_begin(),
5798  E = T.deserialized_decls_end(); I != E; ++I) {
5799  for (DeclGroupRef::const_iterator DI = I->m_DGR.begin(),
5800  DE = I->m_DGR.end(); DI != DE; ++DI)
5801  if (TransactionDeclSet.find(*DI) == TransactionDeclSet.end()) {
5802  //FIXME: HandleNewDecl should take DeclGroupRef
5803  ((TCling*)gCling)->HandleNewDecl(*DI, /*isDeserialized*/true,
5804  modifiedTClasses);
5805  }
5806  }
5807 
5808 
5809  // When fully building the reflection info in TClass, a deserialization
5810  // could be triggered, which may result in request for building the
5811  // reflection info for the same TClass. This in turn will clear the caches
5812  // for the TClass in-flight and cause null ptr derefs.
5813  // FIXME: This is a quick fix, solving most of the issues. The actual
5814  // question is: Shouldn't TClass provide a lock mechanism on update or lock
5815  // itself until the update is done.
5816  //
5817  std::vector<TClass*> modifiedTClassesDiff(modifiedTClasses.size());
5818  std::vector<TClass*>::iterator it;
5819  it = set_difference(modifiedTClasses.begin(), modifiedTClasses.end(),
5820  ((TCling*)gCling)->GetModTClasses().begin(),
5821  ((TCling*)gCling)->GetModTClasses().end(),
5822  modifiedTClassesDiff.begin());
5823  modifiedTClassesDiff.resize(it - modifiedTClassesDiff.begin());
5824 
5825  // Lock the TClass for updates
5826  ((TCling*)gCling)->GetModTClasses().insert(modifiedTClassesDiff.begin(),
5827  modifiedTClassesDiff.end());
5828  for (std::vector<TClass*>::const_iterator I = modifiedTClassesDiff.begin(),
5829  E = modifiedTClassesDiff.end(); I != E; ++I) {
5830  // Make sure the TClass has not been deleted.
5831  if (!gROOT->GetListOfClasses()->FindObject(*I)) {
5832  continue;
5833  }
5834  // Could trigger deserialization of decls.
5835  cling::Interpreter::PushTransactionRAII RAII(fInterpreter);
5836  // Unlock the TClass for updates
5837  ((TCling*)gCling)->GetModTClasses().erase(*I);
5838 
5839  }
5840 }
5841 
5842 ////////////////////////////////////////////////////////////////////////////////
5843 /// Helper function to go through the members of a class or namespace and unload them.
5844 
5845 void TCling::UnloadClassMembers(TClass* cl, const clang::DeclContext* DC) {
5846 
5847  TDataMember* var = 0;
5848  TFunction* function = 0;
5849  TEnum* e = 0;
5850  TFunctionTemplate* functiontemplate = 0;
5852  TListOfFunctions* functions = (TListOfFunctions*)cl->GetListOfMethods();
5853  TListOfEnums* enums = (TListOfEnums*)cl->GetListOfEnums();
5855  for (DeclContext::decl_iterator RI = DC->decls_begin(), RE = DC->decls_end(); RI != RE; ++RI) {
5856  if (isa<VarDecl>(*RI) || isa<FieldDecl>(*RI)) {
5857  const clang::ValueDecl* VD = dyn_cast<ValueDecl>(*RI);
5858  var = (TDataMember*)datamembers->FindObject(VD->getNameAsString().c_str());
5859  if (var) {
5860  // Unload the global by setting the DataMemberInfo_t to 0
5861  datamembers->Unload(var);
5862  var->Update(0);
5863  }
5864  } else if (const FunctionDecl* FD = dyn_cast<FunctionDecl>(*RI)) {
5865  function = (TFunction*)functions->FindObject(FD->getNameAsString().c_str());
5866  if (function) {
5867  functions->Unload(function);
5868  function->Update(0);
5869  }
5870  } else if (const EnumDecl* ED = dyn_cast<EnumDecl>(*RI)) {
5871  e = (TEnum*)enums->FindObject(ED->getNameAsString().c_str());
5872  if (e) {
5873  TIter iEnumConst(e->GetConstants());
5874  while (TEnumConstant* enumConst = (TEnumConstant*)iEnumConst()) {
5875  // Since the enum is already created and valid that ensures us that
5876  // we have the enum constants created as well.
5877  enumConst = (TEnumConstant*)datamembers->FindObject(enumConst->GetName());
5878  if (enumConst && enumConst->IsValid()) {
5879  datamembers->Unload(enumConst);
5880  enumConst->Update(0);
5881  }
5882  }
5883  enums->Unload(e);
5884  e->Update(0);
5885  }
5886  } else if (const FunctionTemplateDecl* FTD = dyn_cast<FunctionTemplateDecl>(*RI)) {
5887  functiontemplate = (TFunctionTemplate*)functiontemplates->FindObject(FTD->getNameAsString().c_str());
5888  if (functiontemplate) {
5889  functiontemplates->Unload(functiontemplate);
5890  functiontemplate->Update(0);
5891  }
5892  }
5893  }
5894 }
5895 
5896 ////////////////////////////////////////////////////////////////////////////////
5897 
5898 void TCling::UpdateListsOnUnloaded(const cling::Transaction &T)
5899 {
5901 
5902  // Unload the objects from the lists and update the objects' state.
5903  TListOfFunctions* functions = (TListOfFunctions*)gROOT->GetListOfGlobalFunctions();
5904  TListOfFunctionTemplates* functiontemplates = (TListOfFunctionTemplates*)gROOT->GetListOfFunctionTemplates();
5905  TListOfEnums* enums = (TListOfEnums*)gROOT->GetListOfEnums();
5906  TListOfDataMembers* globals = (TListOfDataMembers*)gROOT->GetListOfGlobals();
5907  cling::Transaction::const_nested_iterator iNested = T.nested_begin();
5908  for(cling::Transaction::const_iterator I = T.decls_begin(), E = T.decls_end();
5909  I != E; ++I) {
5910  if (I->m_Call == cling::Transaction::kCCIHandleVTable)
5911  continue;
5912 
5913  if (I->m_Call == cling::Transaction::kCCINone) {
5914  UpdateListsOnUnloaded(**iNested);
5915  ++iNested;
5916  continue;
5917  }
5918 
5919  for (DeclGroupRef::const_iterator DI = I->m_DGR.begin(),
5920  DE = I->m_DGR.end(); DI != DE; ++DI) {
5921 
5922  // Do not mark a decl as unloaded if we are going to keep it
5923  // (because it comes from the pch) ...
5924  if ( (*DI)->isFromASTFile() )
5925  continue;
5926 
5927  // Deal with global variables and global enum constants.
5928  if (isa<VarDecl>(*DI) || isa<EnumConstantDecl>(*DI)) {
5929  TObject *obj = globals->Find((TListOfDataMembers::DeclId_t)*DI);
5930  if (globals->GetClass()) {
5931  TDataMember* var = dynamic_cast<TDataMember*>(obj);
5932  if (var && var->IsValid()) {
5933  // Unload the global by setting the DataMemberInfo_t to 0
5934  globals->Unload(var);
5935  var->Update(0);
5936  }
5937  } else {
5938  TGlobal *g = dynamic_cast<TGlobal*>(obj);
5939  if (g && g->IsValid()) {
5940  // Unload the global by setting the DataMemberInfo_t to 0
5941  globals->Unload(g);
5942  g->Update(0);
5943  }
5944  }
5945  // Deal with global functions.
5946  } else if (const FunctionDecl* FD = dyn_cast<FunctionDecl>(*DI)) {
5947  TFunction* function = (TFunction*)functions->Find((TListOfFunctions::DeclId_t)FD);
5948  if (function && function->IsValid()) {
5949  functions->Unload(function);
5950  function->Update(0);
5951  }
5952  // Deal with global function templates.
5953  } else if (const FunctionTemplateDecl* FTD = dyn_cast<FunctionTemplateDecl>(*DI)) {
5954  TFunctionTemplate* functiontemplate = (TFunctionTemplate*)functiontemplates->FindObject(FTD->getNameAsString().c_str());
5955  if (functiontemplate) {
5956  functiontemplates->Unload(functiontemplate);
5957  functiontemplate->Update(0);
5958  }
5959  // Deal with global enums.
5960  } else if (const EnumDecl* ED = dyn_cast<EnumDecl>(*DI)) {
5961  if (TEnum* e = (TEnum*)enums->Find((TListOfEnums::DeclId_t)ED)) {
5962  globals = (TListOfDataMembers*)gROOT->GetListOfGlobals();
5963  TIter iEnumConst(e->GetConstants());
5964  while (TEnumConstant* enumConst = (TEnumConstant*)iEnumConst()) {
5965  // Since the enum is already created and valid that ensures us that
5966  // we have the enum constants created as well.
5967  enumConst = (TEnumConstant*)globals->FindObject(enumConst->GetName());
5968  if (enumConst) {
5969  globals->Unload(enumConst);
5970  enumConst->Update(0);
5971  }
5972  }
5973  enums->Unload(e);
5974  e->Update(0);
5975  }
5976  // Deal with classes. Unload the class and the data members will be not accessible anymore
5977  // Cannot declare the members in a different declaration like redeclarable namespaces.
5978  } else if (const clang::RecordDecl* RD = dyn_cast<RecordDecl>(*DI)) {
5979  std::vector<TClass*> vectTClass;
5980  // Only update the TClass if the definition is being unloaded.
5981  if (RD->isCompleteDefinition()) {
5982  if (TClass::GetClass(RD, vectTClass)) {
5983  for (std::vector<TClass*>::iterator CI = vectTClass.begin(), CE = vectTClass.end();
5984  CI != CE; ++CI) {
5985  UnloadClassMembers((*CI), RD);
5986  (*CI)->ResetClassInfo();
5987  }
5988  }
5989  }
5990  // Deal with namespaces. Unload the members of the current redeclaration only.
5991  } else if (const clang::NamespaceDecl* ND = dyn_cast<NamespaceDecl>(*DI)) {
5992  std::vector<TClass*> vectTClass;
5993  if (TClass::GetClass(ND->getCanonicalDecl(), vectTClass)) {
5994  for (std::vector<TClass*>::iterator CI = vectTClass.begin(), CE = vectTClass.end();
5995  CI != CE; ++CI) {
5996  UnloadClassMembers((*CI), ND);
5997  if (ND->isOriginalNamespace()) {
5998  (*CI)->ResetClassInfo();
5999  }
6000  }
6001  }
6002  }
6003  }
6004  }
6005 }
6006 
6007 ////////////////////////////////////////////////////////////////////////////////
6008 // If an autoparse was done during a transaction and that it is rolled back,
6009 // we need to make sure the next request for the same autoparse will be
6010 // honored.
6011 void TCling::TransactionRollback(const cling::Transaction &T) {
6012  auto const &triter = fTransactionHeadersMap.find(&T);
6013  if (triter != fTransactionHeadersMap.end()) {
6014  std::size_t normNameHash = triter->second;
6015 
6016  fLookedUpClasses.erase(normNameHash);
6017 
6018  auto const &iter = fClassesHeadersMap.find(normNameHash);
6019  if (iter != fClassesHeadersMap.end()) {
6020  auto const &hNamesPtrs = iter->second;
6021  for (auto &hName : hNamesPtrs) {
6022  if (gDebug > 0) {
6023  Info("TransactionRollback",
6024  "Restoring ability to autoaparse: %s", hName);
6025  }
6026  fParsedPayloadsAddresses.erase(hName);
6027  }
6028  }
6029  }
6030 }
6031 
6032 ////////////////////////////////////////////////////////////////////////////////
6033 
6034 void TCling::LibraryLoaded(const void* dyLibHandle, const char* canonicalName) {
6035 // UpdateListOfLoadedSharedLibraries();
6036 }
6037 
6038 ////////////////////////////////////////////////////////////////////////////////
6039 
6040 void TCling::LibraryUnloaded(const void* dyLibHandle, const char* canonicalName) {
6042  fSharedLibs = "";
6043 }
6044 
6045 ////////////////////////////////////////////////////////////////////////////////
6046 /// Return the list of shared libraries loaded into the process.
6047 
6049 {
6052  return fSharedLibs;
6053 }
6054 
6055 ////////////////////////////////////////////////////////////////////////////////
6056 /// Get the list of shared libraries containing the code for class cls.
6057 /// The first library in the list is the one containing the class, the
6058 /// others are the libraries the first one depends on. Returns 0
6059 /// in case the library is not found.
6060 
6061 const char* TCling::GetClassSharedLibs(const char* cls)
6062 {
6063  if (!cls || !*cls) {
6064  return 0;
6065  }
6066  // lookup class to find list of libraries
6067  if (fMapfile) {
6068  TEnvRec* libs_record = 0;
6069  libs_record = fMapfile->Lookup(cls);
6070  if (libs_record) {
6071  const char* libs = libs_record->GetValue();
6072  return (*libs) ? libs : 0;
6073  }
6074  else {
6075  // Try the old format...
6076  TString c = TString("Library.") + cls;
6077  // convert "::" to "@@", we used "@@" because TEnv
6078  // considers "::" a terminator
6079  c.ReplaceAll("::", "@@");
6080  // convert "-" to " ", since class names may have
6081  // blanks and TEnv considers a blank a terminator
6082  c.ReplaceAll(" ", "-");
6083  // Use TEnv::Lookup here as the rootmap file must start with Library.
6084  // and do not support using any stars (so we do not need to waste time
6085  // with the search made by TEnv::GetValue).
6086  TEnvRec* libs_record = 0;
6087  libs_record = fMapfile->Lookup(c);
6088  if (libs_record) {
6089  const char* libs = libs_record->GetValue();
6090  return (*libs) ? libs : 0;
6091  }
6092  }
6093  }
6094  return 0;
6095 }
6096 
6097 ////////////////////////////////////////////////////////////////////////////////
6098 /// Get the list a libraries on which the specified lib depends. The
6099 /// returned string contains as first element the lib itself.
6100 /// Returns 0 in case the lib does not exist or does not have
6101 /// any dependencies.
6102 
6103 const char* TCling::GetSharedLibDeps(const char* lib)
6104 {
6105  if (!fMapfile || !lib || !lib[0]) {
6106  return 0;
6107  }
6108  TString libname(lib);
6109  Ssiz_t idx = libname.Last('.');
6110  if (idx != kNPOS) {
6111  libname.Remove(idx);
6112  }
6113  TEnvRec* rec;
6114  TIter next(fMapfile->GetTable());
6115  size_t len = libname.Length();
6116  while ((rec = (TEnvRec*) next())) {
6117  const char* libs = rec->GetValue();
6118  if (!strncmp(libs, libname.Data(), len) && strlen(libs) >= len
6119  && (!libs[len] || libs[len] == ' ' || libs[len] == '.')) {
6120  return libs;
6121  }
6122  }
6123  return 0;
6124 }
6125 
6126 ////////////////////////////////////////////////////////////////////////////////
6127 /// If error messages are disabled, the interpreter should suppress its
6128 /// failures and warning messages from stdout.
6129 
6131 {
6132 #if defined(R__MUST_REVISIT)
6133 #if R__MUST_REVISIT(6,2)
6134  Warning("IsErrorMessagesEnabled", "Interface not available yet.");
6135 #endif
6136 #endif
6137  return kTRUE;
6138 }
6139 
6140 ////////////////////////////////////////////////////////////////////////////////
6141 /// If error messages are disabled, the interpreter should suppress its
6142 /// failures and warning messages from stdout. Return the previous state.
6143 
6145 {
6146 #if defined(R__MUST_REVISIT)
6147 #if R__MUST_REVISIT(6,2)
6148  Warning("SetErrorMessages", "Interface not available yet.");
6149 #endif
6150 #endif
6152 }
6153 
6154 ////////////////////////////////////////////////////////////////////////////////
6155 /// Refresh the list of include paths known to the interpreter and return it
6156 /// with -I prepended.
6157 
6159 {
6161 
6162  fIncludePath = "";
6163 
6164  llvm::SmallVector<std::string, 10> includePaths;//Why 10? Hell if I know.
6165  //false - no system header, true - with flags.
6166  fInterpreter->GetIncludePaths(includePaths, false, true);
6167  if (const size_t nPaths = includePaths.size()) {
6168  assert(!(nPaths & 1) && "GetIncludePath, number of paths and options is not equal");
6169 
6170  for (size_t i = 0; i < nPaths; i += 2) {
6171  if (i)
6172  fIncludePath.Append(' ');
6173  fIncludePath.Append(includePaths[i].c_str());
6174 
6175  if (includePaths[i] != "-I")
6176  fIncludePath.Append(' ');
6177  fIncludePath.Append('"');
6178  fIncludePath.Append(includePaths[i + 1], includePaths[i + 1].length());
6179  fIncludePath.Append('"');
6180  }
6181  }
6182 
6183  return fIncludePath;
6184 }
6185 
6186 ////////////////////////////////////////////////////////////////////////////////
6187 /// Return the directory containing CINT's stl cintdlls.
6188 
6189 const char* TCling::GetSTLIncludePath() const
6190 {
6191  return "";
6192 }
6193 
6194 //______________________________________________________________________________
6195 // M I S C
6196 //______________________________________________________________________________
6197 
6198 int TCling::DisplayClass(FILE* /*fout*/, const char* /*name*/, int /*base*/, int /*start*/) const
6199 {
6200  // Interface to cling function
6201  return 0;
6202 }
6203 
6204 ////////////////////////////////////////////////////////////////////////////////
6205 /// Interface to cling function
6206 
6207 int TCling::DisplayIncludePath(FILE *fout) const
6208 {
6209  assert(fout != 0 && "DisplayIncludePath, 'fout' parameter is null");
6210 
6211  llvm::SmallVector<std::string, 10> includePaths;//Why 10? Hell if I know.
6212  //false - no system header, true - with flags.
6213  fInterpreter->GetIncludePaths(includePaths, false, true);
6214  if (const size_t nPaths = includePaths.size()) {
6215  assert(!(nPaths & 1) && "DisplayIncludePath, number of paths and options is not equal");
6216 
6217  std::string allIncludes("include path:");
6218  for (size_t i = 0; i < nPaths; i += 2) {
6219  allIncludes += ' ';
6220  allIncludes += includePaths[i];
6221 
6222  if (includePaths[i] != "-I")
6223  allIncludes += ' ';
6224  allIncludes += includePaths[i + 1];
6225  }
6226 
6227  fprintf(fout, "%s\n", allIncludes.c_str());
6228  }
6229 
6230  return 0;
6231 }
6232 
6233 ////////////////////////////////////////////////////////////////////////////////
6234 /// Interface to cling function
6235 
6236 void* TCling::FindSym(const char* entry) const
6237 {
6238  return fInterpreter->getAddressOfGlobal(entry);
6239 }
6240 
6241 ////////////////////////////////////////////////////////////////////////////////
6242 /// Let the interpreter issue a generic error, and set its error state.
6243 
6244 void TCling::GenericError(const char* error) const
6245 {
6246 #if defined(R__MUST_REVISIT)
6247 #if R__MUST_REVISIT(6,2)
6248  Warning("GenericError","Interface not available yet.");
6249 #endif
6250 #endif
6251 }
6252 
6253 ////////////////////////////////////////////////////////////////////////////////
6254 /// This routines used to return the address of the internal wrapper
6255 /// function (of the interpreter) that was used to call *all* the
6256 /// interpreted functions that were bytecode compiled (no longer
6257 /// interpreted line by line). In Cling, there is no such
6258 /// wrapper function.
6259 /// In practice this routines was use to decipher whether the
6260 /// pointer returns by InterfaceMethod could be used to uniquely
6261 /// represent the function. In Cling if the function is in a
6262 /// useable state (its compiled version is available), this is
6263 /// always the case.
6264 /// See TClass::GetMethod.
6265 
6267 {
6268  return 0;
6269 }
6270 
6271 ////////////////////////////////////////////////////////////////////////////////
6272 /// Interface to the CINT global object pointer which was controlling the
6273 /// behavior of the wrapper around the calls to operator new and the constructor
6274 /// and operator delete and the destructor.
6275 
6277 {
6278  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.");
6279  return 0;
6280 }
6281 
6282 ////////////////////////////////////////////////////////////////////////////////
6283 
6284 const char* TCling::Getp2f2funcname(void*) const
6285 {
6286  Error("Getp2f2funcname", "Will not be implemented: "
6287  "all function pointers are compiled!");
6288  return NULL;
6289 }
6290 
6291 ////////////////////////////////////////////////////////////////////////////////
6292 /// Interface to cling function
6293 
6295 {
6296 #if defined(R__MUST_REVISIT)
6297 #if R__MUST_REVISIT(6,2)
6298  Warning("GetSecurityError", "Interface not available yet.");
6299 #endif
6300 #endif
6301  return 0;
6302 }
6303 
6304 ////////////////////////////////////////////////////////////////////////////////
6305 /// Load a source file or library called path into the interpreter.
6306 
6307 int TCling::LoadFile(const char* path) const
6308 {
6309  cling::Interpreter::CompilationResult compRes;
6310  cling::MetaProcessor::MaybeRedirectOutputRAII RAII(fMetaProcessor);
6311  HandleInterpreterException(fMetaProcessor, TString::Format(".L %s", path), compRes, /*cling::Value*/0);
6312  return compRes == cling::Interpreter::kFailure;
6313 }
6314 
6315 ////////////////////////////////////////////////////////////////////////////////
6316 /// Load the declarations from text into the interpreter.
6317 /// Note that this cannot be (top level) statements; text must contain
6318 /// top level declarations.
6319 /// Returns true on success, false on failure.
6320 
6321 Bool_t TCling::LoadText(const char* text) const
6322 {
6323  return (fInterpreter->declare(text) == cling::Interpreter::kSuccess);
6324 }
6325 
6326 ////////////////////////////////////////////////////////////////////////////////
6327 /// Interface to cling function
6328 
6329 const char* TCling::MapCppName(const char* name) const
6330 {
6331  TTHREAD_TLS_DECL(std::string,buffer);
6332  ROOT::TMetaUtils::GetCppName(buffer,name);
6333  return buffer.c_str();
6334 }
6335 
6336 ////////////////////////////////////////////////////////////////////////////////
6337 /// [Place holder for Mutex Lock]
6338 /// Provide the interpreter with a way to
6339 /// acquire a lock used to protect critical section
6340 /// of its code (non-thread safe parts).
6341 
6342 void TCling::SetAlloclockfunc(void (* /* p */ )()) const
6343 {
6344  // nothing to do for now.
6345 }
6346 
6347 ////////////////////////////////////////////////////////////////////////////////
6348 /// [Place holder for Mutex Unlock] Provide the interpreter with a way to
6349 /// release a lock used to protect critical section
6350 /// of its code (non-thread safe parts).
6351 
6352 void TCling::SetAllocunlockfunc(void (* /* p */ )()) const
6353 {
6354  // nothing to do for now.
6355 }
6356 
6357 ////////////////////////////////////////////////////////////////////////////////
6358 /// Enable/Disable the Autoloading of libraries.
6359 /// Returns the old value, i.e whether it was enabled or not.
6360 
6361 int TCling::SetClassAutoloading(int autoload) const
6362 {
6363  if (!autoload && !fClingCallbacks) return false;
6364  if (!fAllowLibLoad) return false;
6365 
6366  assert(fClingCallbacks && "We must have callbacks!");
6367  bool oldVal = fClingCallbacks->IsAutoloadingEnabled();
6369  return oldVal;
6370 }
6371 
6372 ////////////////////////////////////////////////////////////////////////////////
6373 /// Enable/Disable the Autoparsing of headers.
6374 /// Returns the old value, i.e whether it was enabled or not.
6375 
6377 {
6378  bool oldVal = fHeaderParsingOnDemand;
6379  fHeaderParsingOnDemand = autoparse;
6380  return oldVal;
6381 }
6382 
6383 ////////////////////////////////////////////////////////////////////////////////
6384 /// Suspend the Autoparsing of headers.
6385 /// Returns the old value, i.e whether it was suspended or not.
6386 
6389  fIsAutoParsingSuspended = value;
6391  return old;
6392 }
6393 
6394 ////////////////////////////////////////////////////////////////////////////////
6395 /// Set a callback to receive error messages.
6396 
6397 void TCling::SetErrmsgcallback(void* p) const
6398 {
6399 #if defined(R__MUST_REVISIT)
6400 #if R__MUST_REVISIT(6,2)
6401  Warning("SetErrmsgcallback", "Interface not available yet.");
6402 #endif
6403 #endif
6404 }
6405 
6406 ////////////////////////////////////////////////////////////////////////////////
6407 /// Interface to the cling global object pointer which was controlling the
6408 /// behavior of the wrapper around the calls to operator new and the constructor
6409 /// and operator delete and the destructor.
6410 
6411 void TCling::Setgvp(Long_t gvp) const
6412 {
6413  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.");
6414 
6415 }
6416 
6417 ////////////////////////////////////////////////////////////////////////////////
6418 
6420 {
6421  Error("SetRTLD_NOW()", "Will never be implemented! Don't use!");
6422 }
6423 
6424 ////////////////////////////////////////////////////////////////////////////////
6425 
6427 {
6428  Error("SetRTLD_LAZY()", "Will never be implemented! Don't use!");
6429 }
6430 
6431 ////////////////////////////////////////////////////////////////////////////////
6432 /// Create / close a scope for temporaries. No-op for cling; use
6433 /// cling::Value instead.
6434 
6435 void TCling::SetTempLevel(int val) const
6436 {
6437 }
6438 
6439 ////////////////////////////////////////////////////////////////////////////////
6440 
6441 int TCling::UnloadFile(const char* path) const
6442 {
6443  cling::DynamicLibraryManager* DLM = fInterpreter->getDynamicLibraryManager();
6444  std::string canonical = DLM->lookupLibrary(path);
6445  if (canonical.empty()) {
6446  canonical = path;
6447  }
6448  // Unload a shared library or a source file.
6449  cling::Interpreter::CompilationResult compRes;
6450  cling::MetaProcessor::MaybeRedirectOutputRAII RAII(fMetaProcessor);
6451  HandleInterpreterException(fMetaProcessor, Form(".U %s", canonical.c_str()), compRes, /*cling::Value*/0);
6452  return compRes == cling::Interpreter::kFailure;
6453 }
6454 
6455 ////////////////////////////////////////////////////////////////////////////////
6456 /// The created temporary must be deleted by the caller.
6457 
6459 {
6460  TClingValue *val = new TClingValue;
6461  return val;
6462 }
6463 
6464 ////////////////////////////////////////////////////////////////////////////////
6465 /// The call to Cling's tab complition.
6466 
6467 void TCling::CodeComplete(const std::string& line, size_t& cursor,
6468  std::vector<std::string>& completions)
6469 {
6470  fInterpreter->codeComplete(line, cursor, completions);
6471 }
6472 
6473 ////////////////////////////////////////////////////////////////////////////////
6474 
6476 {
6477  using namespace cling;
6478  const Value* V = reinterpret_cast<const Value*>(value.GetValAddr());
6479  RegisterTemporary(*V);
6480 }
6481 
6482 ////////////////////////////////////////////////////////////////////////////////
6483 /// Register value as a temporary, extending its lifetime to that of the
6484 /// interpreter. This is needed for TCling's compatibility interfaces
6485 /// returning long - the address of the temporary objects.
6486 /// As such, "simple" types don't need to be stored; they are returned by
6487 /// value; only pointers / references / objects need to be stored.
6488 
6490 {
6491  if (value.isValid() && value.needsManagedAllocation()) {
6493  fTemporaries->push_back(value);
6494  }
6495 }
6496 
6497 ////////////////////////////////////////////////////////////////////////////////
6498 /// If the interpreter encounters Name, check whether that is an object ROOT
6499 /// could retrieve. To not re-read objects from disk, cache the name/object
6500 /// pair for a given LookupCtx.
6501 
6502 TObject* TCling::GetObjectAddress(const char *Name, void *&LookupCtx)
6503 {
6504  cling::Interpreter *interpreter = ((TCling*)gCling)->GetInterpreter();
6505 
6506  // The call to FindSpecialObject might induces any kind of use
6507  // of the interpreter ... (library loading, function calling, etc.)
6508  // ... and we _know_ we are in the middle of parsing, so let's make
6509  // sure to save the state and then restore it.
6510 
6511  if (gDirectory) {
6512  auto iSpecObjMap = fSpecialObjectMaps.find(gDirectory);
6513  if (iSpecObjMap != fSpecialObjectMaps.end()) {
6514  auto iSpecObj = iSpecObjMap->second.find(Name);
6515  if (iSpecObj != iSpecObjMap->second.end()) {
6516  LookupCtx = gDirectory;
6517  return iSpecObj->second;
6518  }
6519  }
6520  }
6521 
6522  // Save state of the PP
6523  Sema &SemaR = interpreter->getSema();
6524  ASTContext& C = SemaR.getASTContext();
6525  Preprocessor &PP = SemaR.getPreprocessor();
6526  Parser& P = const_cast<Parser&>(interpreter->getParser());
6527  Preprocessor::CleanupAndRestoreCacheRAII cleanupRAII(PP);
6528  Parser::ParserCurTokRestoreRAII savedCurToken(P);
6529  // After we have saved the token reset the current one to something which
6530  // is safe (semi colon usually means empty decl)
6531  Token& Tok = const_cast<Token&>(P.getCurToken());
6532  Tok.setKind(tok::semi);
6533 
6534  // We can't PushDeclContext, because we go up and the routine that pops
6535  // the DeclContext assumes that we drill down always.
6536  // We have to be on the global context. At that point we are in a
6537  // wrapper function so the parent context must be the global.
6538  Sema::ContextAndScopeRAII pushedDCAndS(SemaR, C.getTranslationUnitDecl(),
6539  SemaR.TUScope);
6540 
6541  TObject* specObj = gROOT->FindSpecialObject(Name, LookupCtx);
6542  if (specObj) {
6543  if (!LookupCtx) {
6544  Error("GetObjectAddress", "Got a special object without LookupCtx!");
6545  } else {
6546  fSpecialObjectMaps[LookupCtx][Name] = specObj;
6547  }
6548  }
6549  return specObj;
6550 }
6551 
6552 ////////////////////////////////////////////////////////////////////////////////
6553 /// Inject function as a friend into klass.
6554 /// With function being f in void f() {new N::PrivKlass(); } this enables
6555 /// I/O of non-public classes.
6556 
6557 void TCling::AddFriendToClass(clang::FunctionDecl* function,
6558  clang::CXXRecordDecl* klass) const
6559 {
6560  using namespace clang;
6561  ASTContext& Ctx = klass->getASTContext();
6562  FriendDecl::FriendUnion friendUnion(function);
6563  // one dummy object for the source location
6564  SourceLocation sl;
6565  FriendDecl* friendDecl = FriendDecl::Create(Ctx, klass, sl, friendUnion, sl);
6566  klass->pushFriendDecl(friendDecl);
6567 }
6568 
6569 //______________________________________________________________________________
6570 //
6571 // DeclId getter.
6572 //
6573 
6574 ////////////////////////////////////////////////////////////////////////////////
6575 /// Return a unique identifier of the declaration represented by the
6576 /// CallFunc
6577 
6579 {
6580  if (func) return ((TClingCallFunc*)func)->GetDecl()->getCanonicalDecl();
6581  return 0;
6582 }
6583 
6584 ////////////////////////////////////////////////////////////////////////////////
6585 /// Return a (almost) unique identifier of the declaration represented by the
6586 /// ClassInfo. In ROOT, this identifier can point to more than one TClass
6587 /// when the underlying class is a template instance involving one of the
6588 /// opaque typedef.
6589 
6591 {
6592  if (cinfo) return ((TClingClassInfo*)cinfo)->GetDeclId();
6593  return 0;
6594 }
6595 
6596 ////////////////////////////////////////////////////////////////////////////////
6597 /// Return a unique identifier of the declaration represented by the
6598 /// MethodInfo
6599 
6600 TInterpreter::DeclId_t TCling::GetDeclId(DataMemberInfo_t* data) const
6601 {
6602  if (data) return ((TClingDataMemberInfo*)data)->GetDeclId();
6603  return 0;
6604 }
6605 
6606 ////////////////////////////////////////////////////////////////////////////////
6607 /// Return a unique identifier of the declaration represented by the
6608 /// MethodInfo
6609 
6610 TInterpreter::DeclId_t TCling::GetDeclId(MethodInfo_t* method) const
6611 {
6612  if (method) return ((TClingMethodInfo*)method)->GetDeclId();
6613  return 0;
6614 }
6615 
6616 ////////////////////////////////////////////////////////////////////////////////
6617 /// Return a unique identifier of the declaration represented by the
6618 /// TypedefInfo
6619 
6620 TInterpreter::DeclId_t TCling::GetDeclId(TypedefInfo_t* tinfo) const
6621 {
6622  if (tinfo) return ((TClingTypedefInfo*)tinfo)->GetDecl()->getCanonicalDecl();
6623  return 0;
6624 }
6625 
6626 //______________________________________________________________________________
6627 //
6628 // CallFunc interface
6629 //
6630 
6631 ////////////////////////////////////////////////////////////////////////////////
6632 
6633 void TCling::CallFunc_Delete(CallFunc_t* func) const
6634 {
6635  delete (TClingCallFunc*) func;
6636 }
6637 
6638 ////////////////////////////////////////////////////////////////////////////////
6639 
6640 void TCling::CallFunc_Exec(CallFunc_t* func, void* address) const
6641 {
6642  TClingCallFunc* f = (TClingCallFunc*) func;
6643  f->Exec(address);
6644 }
6645 
6646 ////////////////////////////////////////////////////////////////////////////////
6647 
6648 void TCling::CallFunc_Exec(CallFunc_t* func, void* address, TInterpreterValue& val) const
6649 {
6650  TClingCallFunc* f = (TClingCallFunc*) func;
6651  f->Exec(address, &val);
6652 }
6653 
6654 ////////////////////////////////////////////////////////////////////////////////
6655 
6656 void TCling::CallFunc_ExecWithReturn(CallFunc_t* func, void* address, void* ret) const
6657 {
6658  TClingCallFunc* f = (TClingCallFunc*) func;
6659  f->ExecWithReturn(address, ret);
6660 }
6661 
6662 ////////////////////////////////////////////////////////////////////////////////
6663 
6664 void TCling::CallFunc_ExecWithArgsAndReturn(CallFunc_t* func, void* address,
6665  const void* args[] /*=0*/,
6666  int nargs /*=0*/,
6667  void* ret/*=0*/) const
6668 {
6669  TClingCallFunc* f = (TClingCallFunc*) func;
6670  f->ExecWithArgsAndReturn(address, args, nargs, ret);
6671 }
6672 
6673 ////////////////////////////////////////////////////////////////////////////////
6674 
6675 Long_t TCling::CallFunc_ExecInt(CallFunc_t* func, void* address) const
6676 {
6677  TClingCallFunc* f = (TClingCallFunc*) func;
6678  return f->ExecInt(address);
6679 }
6680 
6681 ////////////////////////////////////////////////////////////////////////////////
6682 
6683 Long64_t TCling::CallFunc_ExecInt64(CallFunc_t* func, void* address) const
6684 {
6685  TClingCallFunc* f = (TClingCallFunc*) func;
6686  return f->ExecInt64(address);
6687 }
6688 
6689 ////////////////////////////////////////////////////////////////////////////////
6690 
6691 Double_t TCling::CallFunc_ExecDouble(CallFunc_t* func, void* address) const
6692 {
6693  TClingCallFunc* f = (TClingCallFunc*) func;
6694  return f->ExecDouble(address);
6695 }
6696 
6697 ////////////////////////////////////////////////////////////////////////////////
6698 
6699 CallFunc_t* TCling::CallFunc_Factory() const
6700 {
6702  return (CallFunc_t*) new TClingCallFunc(fInterpreter,*fNormalizedCtxt);
6703 }
6704 
6705 ////////////////////////////////////////////////////////////////////////////////
6706 
6707 CallFunc_t* TCling::CallFunc_FactoryCopy(CallFunc_t* func) const
6708 {
6709  return (CallFunc_t*) new TClingCallFunc(*(TClingCallFunc*)func);
6710 }
6711 
6712 ////////////////////////////////////////////////////////////////////////////////
6713 
6714 MethodInfo_t* TCling::CallFunc_FactoryMethod(CallFunc_t* func) const
6715 {
6716  TClingCallFunc* f = (TClingCallFunc*) func;
6717  return (MethodInfo_t*) f->FactoryMethod();
6718 }
6719 
6720 ////////////////////////////////////////////////////////////////////////////////
6721 
6722 void TCling::CallFunc_IgnoreExtraArgs(CallFunc_t* func, bool ignore) const
6723 {
6724  TClingCallFunc* f = (TClingCallFunc*) func;
6725  f->IgnoreExtraArgs(ignore);
6726 }
6727 
6728 ////////////////////////////////////////////////////////////////////////////////
6729 
6730 void TCling::CallFunc_Init(CallFunc_t* func) const
6731 {
6733  TClingCallFunc* f = (TClingCallFunc*) func;
6734  f->Init();
6735 }
6736 
6737 ////////////////////////////////////////////////////////////////////////////////
6738 
6739 bool TCling::CallFunc_IsValid(CallFunc_t* func) const
6740 {
6741  TClingCallFunc* f = (TClingCallFunc*) func;
6742  return f->IsValid();
6743 }
6744 
6745 ////////////////////////////////////////////////////////////////////////////////
6746 
6748 TCling::CallFunc_IFacePtr(CallFunc_t * func) const
6749 {
6750  TClingCallFunc* f = (TClingCallFunc*) func;
6751  return f->IFacePtr();
6752 }
6753 
6754 ////////////////////////////////////////////////////////////////////////////////
6755 
6756 void TCling::CallFunc_ResetArg(CallFunc_t* func) const
6757 {
6758  TClingCallFunc* f = (TClingCallFunc*) func;
6759  f->ResetArg();
6760 }
6761 
6762 ////////////////////////////////////////////////////////////////////////////////
6763 
6764 void TCling::CallFunc_SetArg(CallFunc_t* func, Long_t param) const
6765 {
6766  TClingCallFunc* f = (TClingCallFunc*) func;
6767  f->SetArg(param);
6768 }
6769 
6770 ////////////////////////////////////////////////////////////////////////////////
6771 
6772 void TCling::CallFunc_SetArg(CallFunc_t* func, ULong_t param) const
6773 {
6774  TClingCallFunc* f = (TClingCallFunc*) func;
6775  f->SetArg(param);
6776 }
6777 
6778 ////////////////////////////////////////////////////////////////////////////////
6779 
6780 void TCling::CallFunc_SetArg(CallFunc_t* func, Float_t param) const
6781 {
6782  TClingCallFunc* f = (TClingCallFunc*) func;
6783  f->SetArg(param);
6784 }
6785 
6786 ////////////////////////////////////////////////////////////////////////////////
6787 
6788 void TCling::CallFunc_SetArg(CallFunc_t* func, Double_t param) const
6789 {
6790  TClingCallFunc* f = (TClingCallFunc*) func;
6791  f->SetArg(param);
6792 }
6793 
6794 ////////////////////////////////////////////////////////////////////////////////
6795 
6796 void TCling::CallFunc_SetArg(CallFunc_t* func, Long64_t param) const
6797 {
6798  TClingCallFunc* f = (TClingCallFunc*) func;
6799  f->SetArg(param);
6800 }
6801 
6802 ////////////////////////////////////////////////////////////////////////////////
6803 
6804 void TCling::CallFunc_SetArg(CallFunc_t* func, ULong64_t param) const
6805 {
6806  TClingCallFunc* f = (TClingCallFunc*) func;
6807  f->SetArg(param);
6808 }
6809 
6810 ////////////////////////////////////////////////////////////////////////////////
6811 
6812 void TCling::CallFunc_SetArgArray(CallFunc_t* func, Long_t* paramArr, Int_t nparam) const
6813 {
6814  TClingCallFunc* f = (TClingCallFunc*) func;
6815  f->SetArgArray(paramArr, nparam);
6816 }
6817 
6818 ////////////////////////////////////////////////////////////////////////////////
6819 
6820 void TCling::CallFunc_SetArgs(CallFunc_t* func, const char* param) const
6821 {
6822  TClingCallFunc* f = (TClingCallFunc*) func;
6823  f->SetArgs(param);
6824 }
6825 
6826 ////////////////////////////////////////////////////////////////////////////////
6827 
6828 void TCling::CallFunc_SetFunc(CallFunc_t* func, ClassInfo_t* info, const char* method, const char* params, Long_t* offset) const
6829 {
6830  TClingCallFunc* f = (TClingCallFunc*) func;
6831  TClingClassInfo* ci = (TClingClassInfo*) info;
6832  f->SetFunc(ci, method, params, offset);
6833 }
6834 
6835 ////////////////////////////////////////////////////////////////////////////////
6836 
6837 void TCling::CallFunc_SetFunc(CallFunc_t* func, ClassInfo_t* info, const char* method, const char* params, bool objectIsConst, Long_t* offset) const
6838 {
6839  TClingCallFunc* f = (TClingCallFunc*) func;
6840  TClingClassInfo* ci = (TClingClassInfo*) info;
6841  f->SetFunc(ci, method, params, objectIsConst, offset);
6842 }
6843 ////////////////////////////////////////////////////////////////////////////////
6844 
6845 void TCling::CallFunc_SetFunc(CallFunc_t* func, MethodInfo_t* info) const
6846 {
6847  TClingCallFunc* f = (TClingCallFunc*) func;
6848  TClingMethodInfo* minfo = (TClingMethodInfo*) info;
6849  f->SetFunc(minfo);
6850 }
6851 
6852 ////////////////////////////////////////////////////////////////////////////////
6853 /// Interface to cling function
6854 
6855 void TCling::CallFunc_SetFuncProto(CallFunc_t* func, ClassInfo_t* info, const char* method, const char* proto, Long_t* offset, EFunctionMatchMode mode /* = kConversionMatch */) const
6856 {
6857  TClingCallFunc* f = (TClingCallFunc*) func;
6858  TClingClassInfo* ci = (TClingClassInfo*) info;
6859  f->SetFuncProto(ci, method, proto, offset, mode);
6860 }
6861 
6862 ////////////////////////////////////////////////////////////////////////////////
6863 /// Interface to cling function
6864 
6865 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
6866 {
6867  TClingCallFunc* f = (TClingCallFunc*) func;
6868  TClingClassInfo* ci = (TClingClassInfo*) info;
6869  f->SetFuncProto(ci, method, proto, objectIsConst, offset, mode);
6870 }
6871 
6872 ////////////////////////////////////////////////////////////////////////////////
6873 /// Interface to cling function
6874 
6875 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
6876 {
6877  TClingCallFunc* f = (TClingCallFunc*) func;
6878  TClingClassInfo* ci = (TClingClassInfo*) info;
6879  llvm::SmallVector<clang::QualType, 4> funcProto;
6880  for (std::vector<TypeInfo_t*>::const_iterator iter = proto.begin(), end = proto.end();
6881  iter != end; ++iter) {
6882  funcProto.push_back( ((TClingTypeInfo*)(*iter))->GetQualType() );
6883  }
6884  f->SetFuncProto(ci, method, funcProto, offset, mode);
6885 }
6886 
6887 ////////////////////////////////////////////////////////////////////////////////
6888 /// Interface to cling function
6889 
6890 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
6891 {
6892  TClingCallFunc* f = (TClingCallFunc*) func;
6893  TClingClassInfo* ci = (TClingClassInfo*) info;
6894  llvm::SmallVector<clang::QualType, 4> funcProto;
6895  for (std::vector<TypeInfo_t*>::const_iterator iter = proto.begin(), end = proto.end();
6896  iter != end; ++iter) {
6897  funcProto.push_back( ((TClingTypeInfo*)(*iter))->GetQualType() );
6898  }
6899  f->SetFuncProto(ci, method, funcProto, objectIsConst, offset, mode);
6900 }
6901 
6902 //______________________________________________________________________________
6903 //
6904 // ClassInfo interface
6905 //
6906 
6907 ////////////////////////////////////////////////////////////////////////////////
6908 /// Return true if the entity pointed to by 'declid' is declared in
6909 /// the context described by 'info'. If info is null, look into the
6910 /// global scope (translation unit scope).
6911 
6912 Bool_t TCling::ClassInfo_Contains(ClassInfo_t *info, DeclId_t declid) const
6913 {
6914  if (!declid) return kFALSE;
6915 
6916  const clang::Decl *scope;
6917  if (info) scope = ((TClingClassInfo*)info)->GetDecl();
6918  else scope = fInterpreter->getCI()->getASTContext().getTranslationUnitDecl();
6919 
6920  const clang::Decl *decl = reinterpret_cast<const clang::Decl*>(declid);
6921  const clang::DeclContext *ctxt = clang::Decl::castToDeclContext(scope);
6922  if (!decl || !ctxt) return kFALSE;
6923  if (decl->getDeclContext()->Equals(ctxt))
6924  return kTRUE;
6925  else if (decl->getDeclContext()->isTransparentContext() &&
6926  decl->getDeclContext()->getParent()->Equals(ctxt))
6927  return kTRUE;
6928  return kFALSE;
6929 }
6930 
6931 ////////////////////////////////////////////////////////////////////////////////
6932 
6933 Long_t TCling::ClassInfo_ClassProperty(ClassInfo_t* cinfo) const
6934 {
6935  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
6936  return TClinginfo->ClassProperty();
6937 }
6938 
6939 ////////////////////////////////////////////////////////////////////////////////
6940 
6941 void TCling::ClassInfo_Delete(ClassInfo_t* cinfo) const
6942 {
6943  delete (TClingClassInfo*) cinfo;
6944 }
6945 
6946 ////////////////////////////////////////////////////////////////////////////////
6947 
6948 void TCling::ClassInfo_Delete(ClassInfo_t* cinfo, void* arena) const
6949 {
6950  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
6951  TClinginfo->Delete(arena,*fNormalizedCtxt);
6952 }
6953 
6954 ////////////////////////////////////////////////////////////////////////////////
6955 
6956 void TCling::ClassInfo_DeleteArray(ClassInfo_t* cinfo, void* arena, bool dtorOnly) const
6957 {
6958  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
6959  TClinginfo->DeleteArray(arena, dtorOnly,*fNormalizedCtxt);
6960 }
6961 
6962 ////////////////////////////////////////////////////////////////////////////////
6963 
6964 void TCling::ClassInfo_Destruct(ClassInfo_t* cinfo, void* arena) const
6965 {
6966  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
6967  TClinginfo->Destruct(arena,*fNormalizedCtxt);
6968 }
6969 
6970 ////////////////////////////////////////////////////////////////////////////////
6971 
6972 ClassInfo_t* TCling::ClassInfo_Factory(Bool_t all) const
6973 {
6975  return (ClassInfo_t*) new TClingClassInfo(fInterpreter, all);
6976 }
6977 
6978 ////////////////////////////////////////////////////////////////////////////////
6979 
6980 ClassInfo_t* TCling::ClassInfo_Factory(ClassInfo_t* cinfo) const
6981 {
6982  return (ClassInfo_t*) new TClingClassInfo(*(TClingClassInfo*)cinfo);
6983 }
6984 
6985 ////////////////////////////////////////////////////////////////////////////////
6986 
6987 ClassInfo_t* TCling::ClassInfo_Factory(const char* name) const
6988 {
6990  return (ClassInfo_t*) new TClingClassInfo(fInterpreter, name);
6991 }
6992 
6993 ////////////////////////////////////////////////////////////////////////////////
6994 
6995 int TCling::ClassInfo_GetMethodNArg(ClassInfo_t* cinfo, const char* method, const char* proto, Bool_t objectIsConst /* = false */, EFunctionMatchMode mode /* = kConversionMatch */) const
6996 {
6997  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
6998  return TClinginfo->GetMethodNArg(method, proto, objectIsConst, mode);
6999 }
7000 
7001 ////////////////////////////////////////////////////////////////////////////////
7002 
7003 bool TCling::ClassInfo_HasDefaultConstructor(ClassInfo_t* cinfo) const
7004 {
7005  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
7006  return TClinginfo->HasDefaultConstructor();
7007 }
7008 
7009 ////////////////////////////////////////////////////////////////////////////////
7010 
7011 bool TCling::ClassInfo_HasMethod(ClassInfo_t* cinfo, const char* name) const
7012 {
7013  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
7014  return TClinginfo->HasMethod(name);
7015 }
7016 
7017 ////////////////////////////////////////////////////////////////////////////////
7018 
7019 void TCling::ClassInfo_Init(ClassInfo_t* cinfo, const char* name) const
7020 {
7022  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
7023  TClinginfo->Init(name);
7024 }
7025 
7026 ////////////////////////////////////////////////////////////////////////////////
7027 
7028 void TCling::ClassInfo_Init(ClassInfo_t* cinfo, int tagnum) const
7029 {
7031  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
7032  TClinginfo->Init(tagnum);
7033 }
7034 
7035 ////////////////////////////////////////////////////////////////////////////////
7036 
7037 bool TCling::ClassInfo_IsBase(ClassInfo_t* cinfo, const char* name) const
7038 {
7039  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
7040  return TClinginfo->IsBase(name);
7041 }
7042 
7043 ////////////////////////////////////////////////////////////////////////////////
7044 
7045 bool TCling::ClassInfo_IsEnum(const char* name) const
7046 {
7047  return TClingClassInfo::IsEnum(fInterpreter, name);
7048 }
7049 
7050 ////////////////////////////////////////////////////////////////////////////////
7051 
7052 bool TCling::ClassInfo_IsLoaded(ClassInfo_t* cinfo) const
7053 {
7054  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
7055  return TClinginfo->IsLoaded();
7056 }
7057 
7058 ////////////////////////////////////////////////////////////////////////////////
7059 
7060 bool TCling::ClassInfo_IsValid(ClassInfo_t* cinfo) const
7061 {
7062  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
7063  return TClinginfo->IsValid();
7064 }
7065 
7066 ////////////////////////////////////////////////////////////////////////////////
7067 
7068 bool TCling::ClassInfo_IsValidMethod(ClassInfo_t* cinfo, const char* method, const char* proto, Long_t* offset, EFunctionMatchMode mode /* = kConversionMatch */) const
7069 {
7070  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
7071  return TClinginfo->IsValidMethod(method, proto, false, offset, mode);
7072 }
7073 
7074 ////////////////////////////////////////////////////////////////////////////////
7075 
7076 bool TCling::ClassInfo_IsValidMethod(ClassInfo_t* cinfo, const char* method, const char* proto, Bool_t objectIsConst, Long_t* offset, EFunctionMatchMode mode /* = kConversionMatch */) const
7077 {
7078  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
7079  return TClinginfo->IsValidMethod(method, proto, objectIsConst, offset, mode);
7080 }
7081 
7082 ////////////////////////////////////////////////////////////////////////////////
7083 
7084 int TCling::ClassInfo_Next(ClassInfo_t* cinfo) const
7085 {
7086  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
7087  return TClinginfo->Next();
7088 }
7089 
7090 ////////////////////////////////////////////////////////////////////////////////
7091 
7092 void* TCling::ClassInfo_New(ClassInfo_t* cinfo) const
7093 {
7094  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
7095  return TClinginfo->New(*fNormalizedCtxt);
7096 }
7097 
7098 ////////////////////////////////////////////////////////////////////////////////
7099 
7100 void* TCling::ClassInfo_New(ClassInfo_t* cinfo, int n) const
7101 {
7102  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
7103  return TClinginfo->New(n,*fNormalizedCtxt);
7104 }
7105 
7106 ////////////////////////////////////////////////////////////////////////////////
7107 
7108 void* TCling::ClassInfo_New(ClassInfo_t* cinfo, int n, void* arena) const
7109 {
7110  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
7111  return TClinginfo->New(n, arena,*fNormalizedCtxt);
7112 }
7113 
7114 ////////////////////////////////////////////////////////////////////////////////
7115 
7116 void* TCling::ClassInfo_New(ClassInfo_t* cinfo, void* arena) const
7117 {
7118  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
7119  return TClinginfo->New(arena,*fNormalizedCtxt);
7120 }
7121 
7122 ////////////////////////////////////////////////////////////////////////////////
7123 
7124 Long_t TCling::ClassInfo_Property(ClassInfo_t* cinfo) const
7125 {
7126  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
7127  return TClinginfo->Property();
7128 }
7129 
7130 ////////////////////////////////////////////////////////////////////////////////
7131 
7132 int TCling::ClassInfo_Size(ClassInfo_t* cinfo) const
7133 {
7134  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
7135  return TClinginfo->Size();
7136 }
7137 
7138 ////////////////////////////////////////////////////////////////////////////////
7139 
7140 Long_t TCling::ClassInfo_Tagnum(ClassInfo_t* cinfo) const
7141 {
7142  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
7143  return TClinginfo->Tagnum();
7144 }
7145 
7146 ////////////////////////////////////////////////////////////////////////////////
7147 
7148 const char* TCling::ClassInfo_FileName(ClassInfo_t* cinfo) const
7149 {
7150  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
7151  return TClinginfo->FileName();
7152 }
7153 
7154 ////////////////////////////////////////////////////////////////////////////////
7155 
7156 const char* TCling::ClassInfo_FullName(ClassInfo_t* cinfo) const
7157 {
7158  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
7159  TTHREAD_TLS_DECL(std::string,output);
7160  TClinginfo->FullName(output,*fNormalizedCtxt);
7161  return output.c_str();
7162 }
7163 
7164 ////////////////////////////////////////////////////////////////////////////////
7165 
7166 const char* TCling::ClassInfo_Name(ClassInfo_t* cinfo) const
7167 {
7168  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
7169  return TClinginfo->Name();
7170 }
7171 
7172 ////////////////////////////////////////////////////////////////////////////////
7173 
7174 const char* TCling::ClassInfo_Title(ClassInfo_t* cinfo) const
7175 {
7176  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
7177  return TClinginfo->Title();
7178 }
7179 
7180 ////////////////////////////////////////////////////////////////////////////////
7181 
7182 const char* TCling::ClassInfo_TmpltName(ClassInfo_t* cinfo) const
7183 {
7184  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
7185  return TClinginfo->TmpltName();
7186 }
7187 
7188 
7189 
7190 //______________________________________________________________________________
7191 //
7192 // BaseClassInfo interface
7193 //
7194 
7195 ////////////////////////////////////////////////////////////////////////////////
7196 
7197 void TCling::BaseClassInfo_Delete(BaseClassInfo_t* bcinfo) const
7198 {
7199  delete(TClingBaseClassInfo*) bcinfo;
7200 }
7201 
7202 ////////////////////////////////////////////////////////////////////////////////
7203 
7204 BaseClassInfo_t* TCling::BaseClassInfo_Factory(ClassInfo_t* cinfo) const
7205 {
7207  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
7208  return (BaseClassInfo_t*) new TClingBaseClassInfo(fInterpreter, TClinginfo);
7209 }
7210 
7211 ////////////////////////////////////////////////////////////////////////////////
7212 
7213 BaseClassInfo_t* TCling::BaseClassInfo_Factory(ClassInfo_t* derived,
7214  ClassInfo_t* base) const
7215 {
7217  TClingClassInfo* TClinginfo = (TClingClassInfo*) derived;
7218  TClingClassInfo* TClinginfoBase = (TClingClassInfo*) base;
7219  return (BaseClassInfo_t*) new TClingBaseClassInfo(fInterpreter, TClinginfo, TClinginfoBase);
7220 }
7221 
7222 ////////////////////////////////////////////////////////////////////////////////
7223 
7224 int TCling::BaseClassInfo_Next(BaseClassInfo_t* bcinfo) const
7225 {
7226  TClingBaseClassInfo* TClinginfo = (TClingBaseClassInfo*) bcinfo;
7227  return TClinginfo->Next();
7228 }
7229 
7230 ////////////////////////////////////////////////////////////////////////////////
7231 
7232 int TCling::BaseClassInfo_Next(BaseClassInfo_t* bcinfo, int onlyDirect) const
7233 {
7234  TClingBaseClassInfo* TClinginfo = (TClingBaseClassInfo*) bcinfo;
7235  return TClinginfo->Next(onlyDirect);
7236 }
7237 
7238 ////////////////////////////////////////////////////////////////////////////////
7239 
7240 Long_t TCling::BaseClassInfo_Offset(BaseClassInfo_t* toBaseClassInfo, void * address, bool isDerivedObject) const
7241 {
7242  TClingBaseClassInfo* TClinginfo = (TClingBaseClassInfo*) toBaseClassInfo;
7243  return TClinginfo->Offset(address, isDerivedObject);
7244 }
7245 
7246 ////////////////////////////////////////////////////////////////////////////////
7247 
7248 Long_t TCling::ClassInfo_GetBaseOffset(ClassInfo_t* fromDerived, ClassInfo_t* toBase, void * address, bool isDerivedObject) const
7249 {
7250  TClingClassInfo* TClinginfo = (TClingClassInfo*) fromDerived;
7251  TClingClassInfo* TClinginfoBase = (TClingClassInfo*) toBase;
7252  // Offset to the class itself.
7253  if (TClinginfo->GetDecl() == TClinginfoBase->GetDecl()) {
7254  return 0;
7255  }
7256  return TClinginfo->GetBaseOffset(TClinginfoBase, address, isDerivedObject);
7257 }
7258 
7259 ////////////////////////////////////////////////////////////////////////////////
7260 
7261 Long_t TCling::BaseClassInfo_Property(BaseClassInfo_t* bcinfo) const
7262 {
7263  TClingBaseClassInfo* TClinginfo = (TClingBaseClassInfo*) bcinfo;
7264  return TClinginfo->Property();
7265 }
7266 
7267 ////////////////////////////////////////////////////////////////////////////////
7268 
7269 ClassInfo_t *TCling::BaseClassInfo_ClassInfo(BaseClassInfo_t *bcinfo) const
7270 {
7271  TClingBaseClassInfo* TClinginfo = (TClingBaseClassInfo*) bcinfo;
7272  return (ClassInfo_t *)TClinginfo->GetBase();
7273 }
7274 
7275 ////////////////////////////////////////////////////////////////////////////////
7276 
7277 Long_t TCling::BaseClassInfo_Tagnum(BaseClassInfo_t* bcinfo) const
7278 {
7279  TClingBaseClassInfo* TClinginfo = (TClingBaseClassInfo*) bcinfo;
7280  return TClinginfo->Tagnum();
7281 }
7282 
7283 ////////////////////////////////////////////////////////////////////////////////
7284 
7285 const char* TCling::BaseClassInfo_FullName(BaseClassInfo_t* bcinfo) const
7286 {
7287  TClingBaseClassInfo* TClinginfo = (TClingBaseClassInfo*) bcinfo;
7288  TTHREAD_TLS_DECL(std::string,output);
7289  TClinginfo->FullName(output,*fNormalizedCtxt);
7290  return output.c_str();
7291 }
7292 
7293 ////////////////////////////////////////////////////////////////////////////////
7294 
7295 const char* TCling::BaseClassInfo_Name(BaseClassInfo_t* bcinfo) const
7296 {
7297  TClingBaseClassInfo* TClinginfo = (TClingBaseClassInfo*) bcinfo;
7298  return TClinginfo->Name();
7299 }
7300 
7301 ////////////////////////////////////////////////////////////////////////////////
7302 
7303 const char* TCling::BaseClassInfo_TmpltName(BaseClassInfo_t* bcinfo) const
7304 {
7305  TClingBaseClassInfo* TClinginfo = (TClingBaseClassInfo*) bcinfo;
7306  return TClinginfo->TmpltName();
7307 }
7308 
7309 //______________________________________________________________________________
7310 //
7311 // DataMemberInfo interface
7312 //
7313 
7314 ////////////////////////////////////////////////////////////////////////////////
7315 
7316 int TCling::DataMemberInfo_ArrayDim(DataMemberInfo_t* dminfo) const
7317 {
7318  TClingDataMemberInfo* TClinginfo = (TClingDataMemberInfo*) dminfo;
7319  return TClinginfo->ArrayDim();
7320 }
7321 
7322 ////////////////////////////////////////////////////////////////////////////////
7323 
7324 void TCling::DataMemberInfo_Delete(DataMemberInfo_t* dminfo) const
7325 {
7326  delete(TClingDataMemberInfo*) dminfo;
7327 }
7328 
7329 ////////////////////////////////////////////////////////////////////////////////
7330 
7331 DataMemberInfo_t* TCling::DataMemberInfo_Factory(ClassInfo_t* clinfo /*= 0*/) const
7332 {
7334  TClingClassInfo* TClingclass_info = (TClingClassInfo*) clinfo;
7335  return (DataMemberInfo_t*) new TClingDataMemberInfo(fInterpreter, TClingclass_info);
7336 }
7337 
7338 ////////////////////////////////////////////////////////////////////////////////
7339 
7340 DataMemberInfo_t* TCling::DataMemberInfo_Factory(DeclId_t declid, ClassInfo_t* clinfo) const
7341 {
7343  const clang::Decl* decl = reinterpret_cast<const clang::Decl*>(declid);
7344  const clang::ValueDecl* vd = llvm::dyn_cast_or_null<clang::ValueDecl>(decl);
7345  return (DataMemberInfo_t*) new TClingDataMemberInfo(fInterpreter, vd, (TClingClassInfo*)clinfo);
7346 }
7347 
7348 ////////////////////////////////////////////////////////////////////////////////
7349 
7350 DataMemberInfo_t* TCling::DataMemberInfo_FactoryCopy(DataMemberInfo_t* dminfo) const
7351 {
7352  TClingDataMemberInfo* TClinginfo = (TClingDataMemberInfo*) dminfo;
7353  return (DataMemberInfo_t*) new TClingDataMemberInfo(*TClinginfo);
7354 }
7355 
7356 ////////////////////////////////////////////////////////////////////////////////
7357 
7358 bool TCling::DataMemberInfo_IsValid(DataMemberInfo_t* dminfo) const
7359 {
7360  TClingDataMemberInfo* TClinginfo = (TClingDataMemberInfo*) dminfo;
7361  return TClinginfo->IsValid();
7362 }
7363 
7364 ////////////////////////////////////////////////////////////////////////////////
7365 
7366 int TCling::DataMemberInfo_MaxIndex(DataMemberInfo_t* dminfo, Int_t dim) const
7367 {
7368  TClingDataMemberInfo* TClinginfo = (TClingDataMemberInfo*) dminfo;
7369  return TClinginfo->MaxIndex(dim);
7370 }
7371 
7372 ////////////////////////////////////////////////////////////////////////////////
7373 
7374 int TCling::DataMemberInfo_Next(DataMemberInfo_t* dminfo) const
7375 {
7376  TClingDataMemberInfo* TClinginfo = (TClingDataMemberInfo*) dminfo;
7377  return TClinginfo->Next();
7378 }
7379 
7380 ////////////////////////////////////////////////////////////////////////////////
7381 
7382 Long_t TCling::DataMemberInfo_Offset(DataMemberInfo_t* dminfo) const
7383 {
7384  TClingDataMemberInfo* TClinginfo = (TClingDataMemberInfo*) dminfo;
7385  return TClinginfo->Offset();
7386 }
7387 
7388 ////////////////////////////////////////////////////////////////////////////////
7389 
7390 Long_t TCling::DataMemberInfo_Property(DataMemberInfo_t* dminfo) const
7391 {
7392  TClingDataMemberInfo* TClinginfo = (TClingDataMemberInfo*) dminfo;
7393  return TClinginfo->Property();
7394 }
7395 
7396 ////////////////////////////////////////////////////////////////////////////////
7397 
7398 Long_t TCling::DataMemberInfo_TypeProperty(DataMemberInfo_t* dminfo) const
7399 {
7400  TClingDataMemberInfo* TClinginfo = (TClingDataMemberInfo*) dminfo;
7401  return TClinginfo->TypeProperty();
7402 }
7403 
7404 ////////////////////////////////////////////////////////////////////////////////
7405 
7406 int TCling::DataMemberInfo_TypeSize(DataMemberInfo_t* dminfo) const
7407 {
7408  TClingDataMemberInfo* TClinginfo = (TClingDataMemberInfo*) dminfo;
7409  return TClinginfo->TypeSize();
7410 }
7411 
7412 ////////////////////////////////////////////////////////////////////////////////
7413 
7414 const char* TCling::DataMemberInfo_TypeName(DataMemberInfo_t* dminfo) const
7415 {
7416  TClingDataMemberInfo* TClinginfo = (TClingDataMemberInfo*) dminfo;
7417  return TClinginfo->TypeName();
7418 }
7419 
7420 ////////////////////////////////////////////////////////////////////////////////
7421 
7422 const char* TCling::DataMemberInfo_TypeTrueName(DataMemberInfo_t* dminfo) const
7423 {
7424  TClingDataMemberInfo* TClinginfo = (TClingDataMemberInfo*) dminfo;
7425  return TClinginfo->TypeTrueName(*fNormalizedCtxt);
7426 }
7427 
7428 ////////////////////////////////////////////////////////////////////////////////
7429 
7430 const char* TCling::DataMemberInfo_Name(DataMemberInfo_t* dminfo) const
7431 {
7432  TClingDataMemberInfo* TClinginfo = (TClingDataMemberInfo*) dminfo;
7433  return TClinginfo->Name();
7434 }
7435 
7436 ////////////////////////////////////////////////////////////////////////////////
7437 
7438 const char* TCling::DataMemberInfo_Title(DataMemberInfo_t* dminfo) const
7439 {
7440  TClingDataMemberInfo* TClinginfo = (TClingDataMemberInfo*) dminfo;
7441  return TClinginfo->Title();
7442 }
7443 
7444 ////////////////////////////////////////////////////////////////////////////////
7445 
7446 const char* TCling::DataMemberInfo_ValidArrayIndex(DataMemberInfo_t* dminfo) const
7447 {
7448  TTHREAD_TLS_DECL(std::string,result);
7449 
7450  TClingDataMemberInfo* TClinginfo = (TClingDataMemberInfo*) dminfo;
7451  result = TClinginfo->ValidArrayIndex().str();
7452  return result.c_str();
7453 }
7454 
7455 ////////////////////////////////////////////////////////////////////////////////
7456 
7457 void TCling::SetDeclAttr(DeclId_t declId, const char* attribute)
7458 {
7459  Decl* decl = static_cast<Decl*>(const_cast<void*>(declId));
7460  ASTContext &C = decl->getASTContext();
7461  SourceRange commentRange; // this is a fake comment range
7462  decl->addAttr( new (C) AnnotateAttr( commentRange, C, attribute, 0 ) );
7463 }
7464 
7465 //______________________________________________________________________________
7466 //
7467 // Function Template interface
7468 //
7469 
7470 ////////////////////////////////////////////////////////////////////////////////
7471 
7472 static void ConstructorName(std::string &name, const clang::NamedDecl *decl,
7473  cling::Interpreter &interp,
7474  const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt)
7475 {
7476  const clang::TypeDecl* td = llvm::dyn_cast<clang::TypeDecl>(decl->getDeclContext());
7477  if (!td) return;
7478 
7479  clang::QualType qualType(td->getTypeForDecl(),0);
7480  ROOT::TMetaUtils::GetNormalizedName(name, qualType, interp, normCtxt);
7481  unsigned int level = 0;
7482  for(size_t cursor = name.length()-1; cursor != 0; --cursor) {
7483  if (name[cursor] == '>') ++level;
7484  else if (name[cursor] == '<' && level) --level;
7485  else if (level == 0 && name[cursor] == ':') {
7486  name.erase(0,cursor+1);
7487  break;
7488  }
7489  }
7490 }
7491 
7492 ////////////////////////////////////////////////////////////////////////////////
7493 
7494 void TCling::GetFunctionName(const clang::FunctionDecl *decl, std::string &output) const
7495 {
7496  output.clear();
7497  if (llvm::isa<clang::CXXConstructorDecl>(decl))
7498  {
7499  ConstructorName(output, decl, *fInterpreter, *fNormalizedCtxt);
7500 
7501  } else if (llvm::isa<clang::CXXDestructorDecl>(decl))
7502  {
7503  ConstructorName(output, decl, *fInterpreter, *fNormalizedCtxt);
7504  output.insert(output.begin(), '~');
7505  } else {
7506  llvm::raw_string_ostream stream(output);
7507  auto printPolicy = decl->getASTContext().getPrintingPolicy();
7508  // Don't trigger fopen of the source file to count lines:
7509  printPolicy.AnonymousTagLocations = false;
7510  decl->getNameForDiagnostic(stream, printPolicy, /*Qualified=*/false);
7511  }
7512 }
7513 
7514 ////////////////////////////////////////////////////////////////////////////////
7515 /// Return a unique identifier of the declaration represented by the
7516 /// FuncTempInfo
7517 
7518 TInterpreter::DeclId_t TCling::GetDeclId(FuncTempInfo_t *info) const
7519 {
7520  return (DeclId_t)info;
7521 }
7522 
7523 ////////////////////////////////////////////////////////////////////////////////
7524 /// Delete the FuncTempInfo_t
7525 
7526 void TCling::FuncTempInfo_Delete(FuncTempInfo_t * /* ft_info */) const
7527 {
7528  // Currently the address of ft_info is actually the decl itself,
7529  // so we have nothing to do.
7530 }
7531 
7532 ////////////////////////////////////////////////////////////////////////////////
7533 /// Construct a FuncTempInfo_t
7534 
7535 FuncTempInfo_t *TCling::FuncTempInfo_Factory(DeclId_t declid) const
7536 {
7537  // Currently the address of ft_info is actually the decl itself,
7538  // so we have nothing to do.
7539 
7540  return (FuncTempInfo_t*)const_cast<void*>(declid);
7541 }
7542 
7543 ////////////////////////////////////////////////////////////////////////////////
7544 /// Construct a FuncTempInfo_t
7545 
7546 FuncTempInfo_t *TCling::FuncTempInfo_FactoryCopy(FuncTempInfo_t *ft_info) const
7547 {
7548  // Currently the address of ft_info is actually the decl itself,
7549  // so we have nothing to do.
7550 
7551  return (FuncTempInfo_t*)ft_info;
7552 }
7553 
7554 ////////////////////////////////////////////////////////////////////////////////
7555 /// Check validity of a FuncTempInfo_t
7556 
7557 Bool_t TCling::FuncTempInfo_IsValid(FuncTempInfo_t *t_info) const
7558 {
7559  // Currently the address of ft_info is actually the decl itself,
7560  // so we have nothing to do.
7561 
7562  return t_info != 0;
7563 }
7564 
7565 ////////////////////////////////////////////////////////////////////////////////
7566 /// Return the maximum number of template arguments of the
7567 /// function template described by ft_info.
7568 
7569 UInt_t TCling::FuncTempInfo_TemplateNargs(FuncTempInfo_t *ft_info) const
7570 {
7571  if (!ft_info) return 0;
7572  const clang::FunctionTemplateDecl *ft = (const clang::FunctionTemplateDecl*)ft_info;
7573  return ft->getTemplateParameters()->size();
7574 }
7575 
7576 ////////////////////////////////////////////////////////////////////////////////
7577 /// Return the number of required template arguments of the
7578 /// function template described by ft_info.
7579 
7580 UInt_t TCling::FuncTempInfo_TemplateMinReqArgs(FuncTempInfo_t *ft_info) const
7581 {
7582  if (!ft_info) return 0;
7583  const clang::FunctionTemplateDecl *ft = (clang::FunctionTemplateDecl*)ft_info;
7584  return ft->getTemplateParameters()->getMinRequiredArguments();
7585 }
7586 
7587 ////////////////////////////////////////////////////////////////////////////////
7588 /// Return the property of the function template.
7589 
7590 Long_t TCling::FuncTempInfo_Property(FuncTempInfo_t *ft_info) const
7591 {
7592  if (!ft_info) return 0;
7593 
7594  long property = 0L;
7595  property |= kIsCompiled;
7596 
7597  const clang::FunctionTemplateDecl *ft = (clang::FunctionTemplateDecl*)ft_info;
7598 
7599  switch (ft->getAccess()) {
7600  case clang::AS_public:
7601  property |= kIsPublic;
7602  break;
7603  case clang::AS_protected:
7604  property |= kIsProtected;
7605  break;
7606  case clang::AS_private:
7607  property |= kIsPrivate;
7608  break;
7609  case clang::AS_none:
7610  if (ft->getDeclContext()->isNamespace())
7611  property |= kIsPublic;
7612  break;
7613  default:
7614  // IMPOSSIBLE
7615  break;
7616  }
7617 
7618  const clang::FunctionDecl *fd = ft->getTemplatedDecl();
7619  if (const clang::CXXMethodDecl *md =
7620  llvm::dyn_cast<clang::CXXMethodDecl>(fd)) {
7621  if (md->getTypeQualifiers() & clang::Qualifiers::Const) {
7622  property |= kIsConstant | kIsConstMethod;
7623  }
7624  if (md->isVirtual()) {
7625  property |= kIsVirtual;
7626  }
7627  if (md->isPure()) {
7628  property |= kIsPureVirtual;
7629  }
7630  if (const clang::CXXConstructorDecl *cd =
7631  llvm::dyn_cast<clang::CXXConstructorDecl>(md)) {
7632  if (cd->isExplicit()) {
7633  property |= kIsExplicit;
7634  }
7635  }
7636  else if (const clang::CXXConversionDecl *cd =
7637  llvm::dyn_cast<clang::CXXConversionDecl>(md)) {
7638  if (cd->isExplicit()) {
7639  property |= kIsExplicit;
7640  }
7641  }
7642  }
7643  return property;
7644 }
7645 
7646 ////////////////////////////////////////////////////////////////////////////////
7647 /// Return the name of this function template.
7648 
7649 void TCling::FuncTempInfo_Name(FuncTempInfo_t *ft_info, TString &output) const
7650 {
7651  output.Clear();
7652  if (!ft_info) return;
7653  const clang::FunctionTemplateDecl *ft = (clang::FunctionTemplateDecl*)ft_info;
7654  std::string buf;
7655  GetFunctionName(ft->getTemplatedDecl(), buf);
7656  output = buf;
7657 }
7658 
7659 ////////////////////////////////////////////////////////////////////////////////
7660 /// Return the comments associates with this function template.
7661 
7662 void TCling::FuncTempInfo_Title(FuncTempInfo_t *ft_info, TString &output) const
7663 {
7664  output.Clear();
7665  if (!ft_info) return;
7666  const clang::FunctionTemplateDecl *ft = (const clang::FunctionTemplateDecl*)ft_info;
7667 
7668  // Iterate over the redeclarations, we can have multiple definitions in the
7669  // redecl chain (came from merging of pcms).
7670  if (const RedeclarableTemplateDecl *AnnotFD
7671  = ROOT::TMetaUtils::GetAnnotatedRedeclarable((const RedeclarableTemplateDecl*)ft)) {
7672  if (AnnotateAttr *A = AnnotFD->getAttr<AnnotateAttr>()) {
7673  output = A->getAnnotation().str();
7674  return;
7675  }
7676  }
7677  if (!ft->isFromASTFile()) {
7678  // Try to get the comment from the header file if present
7679  // but not for decls from AST file, where rootcling would have
7680  // created an annotation
7681  output = ROOT::TMetaUtils::GetComment(*ft).str();
7682  }
7683 }
7684 
7685 
7686 //______________________________________________________________________________
7687 //
7688 // MethodInfo interface
7689 //
7690 
7691 ////////////////////////////////////////////////////////////////////////////////
7692 /// Interface to cling function
7693 
7694 void TCling::MethodInfo_Delete(MethodInfo_t* minfo) const
7695 {
7696  delete(TClingMethodInfo*) minfo;
7697 }
7698 
7699 ////////////////////////////////////////////////////////////////////////////////
7700 
7701 void TCling::MethodInfo_CreateSignature(MethodInfo_t* minfo, TString& signature) const
7702 {
7703  TClingMethodInfo* info = (TClingMethodInfo*) minfo;
7704  info->CreateSignature(signature);
7705 }
7706 
7707 ////////////////////////////////////////////////////////////////////////////////
7708 
7709 MethodInfo_t* TCling::MethodInfo_Factory() const
7710 {
7712  return (MethodInfo_t*) new TClingMethodInfo(fInterpreter);
7713 }
7714 
7715 ////////////////////////////////////////////////////////////////////////////////
7716 
7717 MethodInfo_t* TCling::MethodInfo_Factory(ClassInfo_t* clinfo) const
7718 {
7720  return (MethodInfo_t*) new TClingMethodInfo(fInterpreter, (TClingClassInfo*)clinfo);
7721 }
7722 
7723 ////////////////////////////////////////////////////////////////////////////////
7724 
7725 MethodInfo_t* TCling::MethodInfo_Factory(DeclId_t declid) const
7726 {
7727  const clang::Decl* decl = reinterpret_cast<const clang::Decl*>(declid);
7729  const clang::FunctionDecl* fd = llvm::dyn_cast_or_null<clang::FunctionDecl>(decl);
7730  return (MethodInfo_t*) new TClingMethodInfo(fInterpreter, fd);
7731 }
7732 
7733 ////////////////////////////////////////////////////////////////////////////////
7734 
7735 MethodInfo_t* TCling::MethodInfo_FactoryCopy(MethodInfo_t* minfo) const
7736 {
7737  return (MethodInfo_t*) new TClingMethodInfo(*(TClingMethodInfo*)minfo);
7738 }
7739 
7740 ////////////////////////////////////////////////////////////////////////////////
7741 
7742 void* TCling::MethodInfo_InterfaceMethod(MethodInfo_t* minfo) const
7743 {
7744  TClingMethodInfo* info = (TClingMethodInfo*) minfo;
7745  return info->InterfaceMethod(*fNormalizedCtxt);
7746 }
7747 
7748 ////////////////////////////////////////////////////////////////////////////////
7749 
7750 bool TCling::MethodInfo_IsValid(MethodInfo_t* minfo) const
7751 {
7752  TClingMethodInfo* info = (TClingMethodInfo*) minfo;
7753  return info->IsValid();
7754 }
7755 
7756 ////////////////////////////////////////////////////////////////////////////////
7757 
7758 int TCling::MethodInfo_NArg(MethodInfo_t* minfo) const
7759 {
7760  TClingMethodInfo* info = (TClingMethodInfo*) minfo;
7761  return info->NArg();
7762 }
7763 
7764 ////////////////////////////////////////////////////////////////////////////////
7765 
7766 int TCling::MethodInfo_NDefaultArg(MethodInfo_t* minfo) const
7767 {
7768  TClingMethodInfo* info = (TClingMethodInfo*) minfo;
7769  return info->NDefaultArg();
7770 }
7771 
7772 ////////////////////////////////////////////////////////////////////////////////
7773 
7774 int TCling::MethodInfo_Next(MethodInfo_t* minfo) const
7775 {
7776  TClingMethodInfo* info = (TClingMethodInfo*) minfo;
7777  return info->Next();
7778 }
7779 
7780 ////////////////////////////////////////////////////////////////////////////////
7781 
7782 Long_t TCling::MethodInfo_Property(MethodInfo_t* minfo) const
7783 {
7784  TClingMethodInfo* info = (TClingMethodInfo*) minfo;
7785  return info->Property();
7786 }
7787 
7788 ////////////////////////////////////////////////////////////////////////////////
7789 
7790 Long_t TCling::MethodInfo_ExtraProperty(MethodInfo_t* minfo) const
7791 {
7792  TClingMethodInfo* info = (TClingMethodInfo*) minfo;
7793  return info->ExtraProperty();
7794 }
7795 
7796 ////////////////////////////////////////////////////////////////////////////////
7797 
7798 TypeInfo_t* TCling::MethodInfo_Type(MethodInfo_t* minfo) const
7799 {
7800  TClingMethodInfo* info = (TClingMethodInfo*) minfo;
7801  return (TypeInfo_t*)info->Type();
7802 }
7803 
7804 ////////////////////////////////////////////////////////////////////////////////
7805 
7806 const char* TCling::MethodInfo_GetMangledName(MethodInfo_t* minfo) const
7807 {
7808  TClingMethodInfo* info = (TClingMethodInfo*) minfo;
7809  TTHREAD_TLS_DECL(TString, mangled_name);
7810  mangled_name = info->GetMangledName();
7811  return mangled_name;
7812 }
7813 
7814 ////////////////////////////////////////////////////////////////////////////////
7815 
7816 const char* TCling::MethodInfo_GetPrototype(MethodInfo_t* minfo) const
7817 {
7818  TClingMethodInfo* info = (TClingMethodInfo*) minfo;
7819  return info->GetPrototype(*fNormalizedCtxt);
7820 }
7821 
7822 ////////////////////////////////////////////////////////////////////////////////
7823 
7824 const char* TCling::MethodInfo_Name(MethodInfo_t* minfo) const
7825 {
7826  TClingMethodInfo* info = (TClingMethodInfo*) minfo;
7827  return info->Name(*fNormalizedCtxt);
7828 }
7829 
7830 ////////////////////////////////////////////////////////////////////////////////
7831 
7832 const char* TCling::MethodInfo_TypeName(MethodInfo_t* minfo) const
7833 {
7834  TClingMethodInfo* info = (TClingMethodInfo*) minfo;
7835  return info->TypeName();
7836 }
7837 
7838 ////////////////////////////////////////////////////////////////////////////////
7839 
7840 std::string TCling::MethodInfo_TypeNormalizedName(MethodInfo_t* minfo) const
7841 {
7842  TClingMethodInfo* info = (TClingMethodInfo*) minfo;
7843  if (info && info->IsValid())
7844  return info->Type()->NormalizedName(*fNormalizedCtxt);
7845  else
7846  return "";
7847 }
7848 
7849 ////////////////////////////////////////////////////////////////////////////////
7850 
7851 const char* TCling::MethodInfo_Title(MethodInfo_t* minfo) const
7852 {
7853  TClingMethodInfo* info = (TClingMethodInfo*) minfo;
7854  return info->Title();
7855 }
7856 
7857 ////////////////////////////////////////////////////////////////////////////////
7858 
7860 {
7861  if (func) {
7862  return MethodInfo_MethodCallReturnType(func->fInfo);
7863  } else {
7864  return EReturnType::kOther;
7865  }
7866 }
7867 
7868 ////////////////////////////////////////////////////////////////////////////////
7869 
7870 auto TCling::MethodInfo_MethodCallReturnType(MethodInfo_t* minfo) const -> EReturnType
7871 {
7872  TClingMethodInfo* info = (TClingMethodInfo*) minfo;
7873  if (info && info->IsValid()) {
7874  TClingTypeInfo *typeinfo = info->Type();
7875  clang::QualType QT( typeinfo->GetQualType().getCanonicalType() );
7876  if (QT->isEnumeralType()) {
7877  return EReturnType::kLong;
7878  } else if (QT->isPointerType()) {
7879  // Look for char*
7880  QT = llvm::cast<clang::PointerType>(QT)->getPointeeType();
7881  if ( QT->isCharType() ) {
7882  return EReturnType::kString;
7883  } else {
7884  return EReturnType::kOther;
7885  }
7886  } else if ( QT->isFloatingType() ) {
7887  int sz = typeinfo->Size();
7888  if (sz == 4 || sz == 8) {
7889  // Support only float and double.
7890  return EReturnType::kDouble;
7891  } else {
7892  return EReturnType::kOther;
7893  }
7894  } else if ( QT->isIntegerType() ) {
7895  int sz = typeinfo->Size();
7896  if (sz <= 8) {
7897  // Support only up to long long ... but
7898  // FIXME the TMethodCall::Execute only
7899  // return long (4 bytes) ...
7900  // The v5 implementation of TMethodCall::ReturnType
7901  // was not making the distinction so we let it go
7902  // as is for now, but we really need to upgrade
7903  // TMethodCall::Execute ...
7904  return EReturnType::kLong;
7905  } else {
7906  return EReturnType::kOther;
7907  }
7908  } else {
7909  return EReturnType::kOther;
7910  }
7911  } else {
7912  return EReturnType::kOther;
7913  }
7914 }
7915 
7916 //______________________________________________________________________________
7917 //
7918 // MethodArgInfo interface
7919 //
7920 
7921 ////////////////////////////////////////////////////////////////////////////////
7922 
7923 void TCling::MethodArgInfo_Delete(MethodArgInfo_t* marginfo) const
7924 {
7925  delete(TClingMethodArgInfo*) marginfo;
7926 }
7927 
7928 ////////////////////////////////////////////////////////////////////////////////
7929 
7930 MethodArgInfo_t* TCling::MethodArgInfo_Factory() const
7931 {
7933  return (MethodArgInfo_t*) new TClingMethodArgInfo(fInterpreter);
7934 }
7935 
7936 ////////////////////////////////////////////////////////////////////////////////
7937 
7938 MethodArgInfo_t* TCling::MethodArgInfo_Factory(MethodInfo_t *minfo) const
7939 {
7941  return (MethodArgInfo_t*) new TClingMethodArgInfo(fInterpreter, (TClingMethodInfo*)minfo);
7942 }
7943 
7944 ////////////////////////////////////////////////////////////////////////////////
7945 
7946 MethodArgInfo_t* TCling::MethodArgInfo_FactoryCopy(MethodArgInfo_t* marginfo) const
7947 {
7948  return (MethodArgInfo_t*)
7949  new TClingMethodArgInfo(*(TClingMethodArgInfo*)marginfo);
7950 }
7951 
7952 ////////////////////////////////////////////////////////////////////////////////
7953 
7954 bool TCling::MethodArgInfo_IsValid(MethodArgInfo_t* marginfo) const
7955 {
7956  TClingMethodArgInfo* info = (TClingMethodArgInfo*) marginfo;
7957  return info->IsValid();
7958 }
7959 
7960 ////////////////////////////////////////////////////////////////////////////////
7961 
7962 int TCling::MethodArgInfo_Next(MethodArgInfo_t* marginfo) const
7963 {
7964  TClingMethodArgInfo* info = (TClingMethodArgInfo*) marginfo;
7965  return info->Next();
7966 }
7967 
7968 ////////////////////////////////////////////////////////////////////////////////
7969 
7970 Long_t TCling::MethodArgInfo_Property(MethodArgInfo_t* marginfo) const
7971 {
7972  TClingMethodArgInfo* info = (TClingMethodArgInfo*) marginfo;
7973  return info->Property();
7974 }
7975 
7976 ////////////////////////////////////////////////////////////////////////////////
7977 
7978 const char* TCling::MethodArgInfo_DefaultValue(MethodArgInfo_t* marginfo) const
7979 {
7980  TClingMethodArgInfo* info = (TClingMethodArgInfo*) marginfo;
7981  return info->DefaultValue();
7982 }
7983 
7984 ////////////////////////////////////////////////////////////////////////////////
7985 
7986 const char* TCling::MethodArgInfo_Name(MethodArgInfo_t* marginfo) const
7987 {
7988  TClingMethodArgInfo* info = (TClingMethodArgInfo*) marginfo;
7989  return info->Name();
7990 }
7991 
7992 ////////////////////////////////////////////////////////////////////////////////
7993 
7994 const char* TCling::MethodArgInfo_TypeName(MethodArgInfo_t* marginfo) const
7995 {
7996  TClingMethodArgInfo* info = (TClingMethodArgInfo*) marginfo;
7997  return info->TypeName();
7998 }
7999 
8000 ////////////////////////////////////////////////////////////////////////////////
8001 
8002 std::string TCling::MethodArgInfo_TypeNormalizedName(MethodArgInfo_t* marginfo) const
8003 {
8004  TClingMethodArgInfo* info = (TClingMethodArgInfo*) marginfo;
8005  return info->Type()->NormalizedName(*fNormalizedCtxt);
8006 }
8007 
8008 //______________________________________________________________________________
8009 //
8010 // TypeInfo interface
8011 //
8012 
8013 ////////////////////////////////////////////////////////////////////////////////
8014 
8015 void TCling::TypeInfo_Delete(TypeInfo_t* tinfo) const
8016 {
8017  delete (TClingTypeInfo*) tinfo;
8018 }
8019 
8020 ////////////////////////////////////////////////////////////////////////////////
8021 
8022 TypeInfo_t* TCling::TypeInfo_Factory() const
8023 {
8025  return (TypeInfo_t*) new TClingTypeInfo(fInterpreter);
8026 }
8027 
8028 ////////////////////////////////////////////////////////////////////////////////
8029 
8030 TypeInfo_t* TCling::TypeInfo_Factory(const char *name) const
8031 {
8033  return (TypeInfo_t*) new TClingTypeInfo(fInterpreter, name);
8034 }
8035 
8036 ////////////////////////////////////////////////////////////////////////////////
8037 
8038 TypeInfo_t* TCling::TypeInfo_FactoryCopy(TypeInfo_t* tinfo) const
8039 {
8040  return (TypeInfo_t*) new TClingTypeInfo(*(TClingTypeInfo*)tinfo);
8041 }
8042 
8043 ////////////////////////////////////////////////////////////////////////////////
8044 
8045 void TCling::TypeInfo_Init(TypeInfo_t* tinfo, const char* name) const
8046 {
8048  TClingTypeInfo* TClinginfo = (TClingTypeInfo*) tinfo;
8049  TClinginfo->Init(name);
8050 }
8051 
8052 ////////////////////////////////////////////////////////////////////////////////
8053 
8054 bool TCling::TypeInfo_IsValid(TypeInfo_t* tinfo) const
8055 {
8056  TClingTypeInfo* TClinginfo = (TClingTypeInfo*) tinfo;
8057  return TClinginfo->IsValid();
8058 }
8059 
8060 ////////////////////////////////////////////////////////////////////////////////
8061 
8062 const char* TCling::TypeInfo_Name(TypeInfo_t* tinfo) const
8063 {
8064  TClingTypeInfo* TClinginfo = (TClingTypeInfo*) tinfo;
8065  return TClinginfo->Name();
8066 }
8067 
8068 ////////////////////////////////////////////////////////////////////////////////
8069 
8070 Long_t TCling::TypeInfo_Property(TypeInfo_t* tinfo) const
8071 {
8072  TClingTypeInfo* TClinginfo = (TClingTypeInfo*) tinfo;
8073  return TClinginfo->Property();
8074 }
8075 
8076 ////////////////////////////////////////////////////////////////////////////////
8077 
8078 int TCling::TypeInfo_RefType(TypeInfo_t* tinfo) const
8079 {
8080  TClingTypeInfo* TClinginfo = (TClingTypeInfo*) tinfo;
8081  return TClinginfo->RefType();
8082 }
8083 
8084 ////////////////////////////////////////////////////////////////////////////////
8085 
8086 int TCling::TypeInfo_Size(TypeInfo_t* tinfo) const
8087 {
8088  TClingTypeInfo* TClinginfo = (TClingTypeInfo*) tinfo;
8089  return TClinginfo->Size();
8090 }
8091 
8092 ////////////////////////////////////////////////////////////////////////////////
8093 
8094 const char* TCling::TypeInfo_TrueName(TypeInfo_t* tinfo) const
8095 {
8096  TClingTypeInfo* TClinginfo = (TClingTypeInfo*) tinfo;
8097  return TClinginfo->TrueName(*fNormalizedCtxt);
8098 }
8099 
8100 
8101 //______________________________________________________________________________
8102 //
8103 // TypedefInfo interface
8104 //
8105 
8106 ////////////////////////////////////////////////////////////////////////////////
8107 
8108 void TCling::TypedefInfo_Delete(TypedefInfo_t* tinfo) const
8109 {
8110  delete(TClingTypedefInfo*) tinfo;
8111 }
8112 
8113 ////////////////////////////////////////////////////////////////////////////////
8114 
8115 TypedefInfo_t* TCling::TypedefInfo_Factory() const
8116 {
8118  return (TypedefInfo_t*) new TClingTypedefInfo(fInterpreter);
8119 }
8120 
8121 ////////////////////////////////////////////////////////////////////////////////
8122 
8123 TypedefInfo_t* TCling::TypedefInfo_Factory(const char *name) const
8124 {
8126  return (TypedefInfo_t*) new TClingTypedefInfo(fInterpreter, name);
8127 }
8128 
8129 ////////////////////////////////////////////////////////////////////////////////
8130 
8131 TypedefInfo_t* TCling::TypedefInfo_FactoryCopy(TypedefInfo_t* tinfo) const
8132 {
8133  return (TypedefInfo_t*) new TClingTypedefInfo(*(TClingTypedefInfo*)tinfo);
8134 }
8135 
8136 ////////////////////////////////////////////////////////////////////////////////
8137 
8138 void TCling::TypedefInfo_Init(TypedefInfo_t* tinfo,
8139  const char* name) const
8140 {
8142  TClingTypedefInfo* TClinginfo = (TClingTypedefInfo*) tinfo;
8143  TClinginfo->Init(name);
8144 }
8145 
8146 ////////////////////////////////////////////////////////////////////////////////
8147 
8148 bool TCling::TypedefInfo_IsValid(TypedefInfo_t* tinfo) const
8149 {
8150  TClingTypedefInfo* TClinginfo = (TClingTypedefInfo*) tinfo;
8151  return TClinginfo->IsValid();
8152 }
8153 
8154 ////////////////////////////////////////////////////////////////////////////////
8155 
8156 Int_t TCling::TypedefInfo_Next(TypedefInfo_t* tinfo) const
8157 {
8158  TClingTypedefInfo* TClinginfo = (TClingTypedefInfo*) tinfo;
8159  return TClinginfo->Next();
8160 }
8161 
8162 ////////////////////////////////////////////////////////////////////////////////
8163 
8164 Long_t TCling::TypedefInfo_Property(TypedefInfo_t* tinfo) const
8165 {
8166  TClingTypedefInfo* TClinginfo = (TClingTypedefInfo*) tinfo;
8167  return TClinginfo->Property();
8168 }
8169 
8170 ////////////////////////////////////////////////////////////////////////////////
8171 
8172 int TCling::TypedefInfo_Size(TypedefInfo_t* tinfo) const
8173 {
8174  TClingTypedefInfo* TClinginfo = (TClingTypedefInfo*) tinfo;
8175  return TClinginfo->Size();
8176 }
8177 
8178 ////////////////////////////////////////////////////////////////////////////////
8179 
8180 const char* TCling::TypedefInfo_TrueName(TypedefInfo_t* tinfo) const
8181 {
8182  TClingTypedefInfo* TClinginfo = (TClingTypedefInfo*) tinfo;
8183  return TClinginfo->TrueName(*fNormalizedCtxt);
8184 }
8185 
8186 ////////////////////////////////////////////////////////////////////////////////
8187 
8188 const char* TCling::TypedefInfo_Name(TypedefInfo_t* tinfo) const
8189 {
8190  TClingTypedefInfo* TClinginfo = (TClingTypedefInfo*) tinfo;
8191  return TClinginfo->Name();
8192 }
8193 
8194 ////////////////////////////////////////////////////////////////////////////////
8195 
8196 const char* TCling::TypedefInfo_Title(TypedefInfo_t* tinfo) const
8197 {
8198  TClingTypedefInfo* TClinginfo = (TClingTypedefInfo*) tinfo;
8199  return TClinginfo->Title();
8200 }
EState GetState() const
Definition: TClass.h:443
int TCling__AutoLoadCallback(const char *className)
Definition: TCling.cxx:600
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:7930
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:6158
void ResetCaches()
To clean out all caches.
Definition: TClass.cxx:3970
virtual Long_t MethodInfo_Property(MethodInfo_t *minfo) const
Definition: TCling.cxx:7782
virtual Long_t ClassInfo_ClassProperty(ClassInfo_t *info) const
Definition: TCling.cxx:6933
virtual const char * BaseName(const char *pathname)
Base name of a file name. Base name of /user/root is root.
Definition: TSystem.cxx:929
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:6435
const clang::FunctionTemplateDecl * GetFunctionTemplate(const char *fname) const
Ssiz_t Last(char c) const
Find last occurrence of a character c.
Definition: TString.cxx:865
virtual void SetRcName(const char *name)
Definition: TEnv.h:149
ETupleOrdering
Check in what order the member of a tuple are layout.
Definition: TCling.cxx:3175
TObject * GetObjectAddress(const char *Name, void *&LookupCtx)
If the interpreter encounters Name, check whether that is an object ROOT could retrieve.
Definition: TCling.cxx:6502
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:4056
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:4081
int TCling__IsAutoLoadNamespaceCandidate(const clang::NamespaceDecl *nsDecl)
Definition: TCling.cxx:622
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:627
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:4113
static clang::ClassTemplateDecl * FindTemplateInNamespace(clang::Decl *decl)
Find a template decl within N nested namespaces, 0<=N<inf Assumes 1 and only 1 template present and 1...
Definition: TCling.cxx:663
virtual void SetRTLD_NOW() const
Definition: TCling.cxx:6419
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:4213
void TransactionRollback(const cling::Transaction &T)
Definition: TCling.cxx:6011
virtual int TypedefInfo_Size(TypedefInfo_t *tinfo) const
Definition: TCling.cxx:8172
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:6352
Bool_t IsOnHeap() const
Definition: TObject.h:126
void AddTemplAndNargsToKeep(const clang::ClassTemplateDecl *templ, unsigned int i)
Definition: TMetaUtils.cxx:333
virtual bool ClassInfo_HasDefaultConstructor(ClassInfo_t *info) const
Definition: TCling.cxx:7003
ROOT::ESTLType IsSTLCont(std::string_view type)
type : type name: vector<list<classA,allocator>,allocator> result: 0 : not stl container code of cont...
void LibraryLoaded(const void *dyLibHandle, const char *canonicalName)
Definition: TCling.cxx:6034
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:2944
virtual CallFuncIFacePtr_t CallFunc_IFacePtr(CallFunc_t *func) const
Definition: TCling.cxx:6748
void TCling__UpdateListsOnCommitted(const cling::Transaction &T, cling::Interpreter *)
Definition: TCling.cxx:551
virtual void PostLoadCheck()
Do the initialization that can only be done after the CINT dictionary has been fully populated and ca...
Definition: TClass.cxx:5590
virtual void BaseClassInfo_Delete(BaseClassInfo_t *bcinfo) const
Definition: TCling.cxx:7197
virtual DataMemberInfo_t * DataMemberInfo_Factory(ClassInfo_t *clinfo=0) const
Definition: TCling.cxx:7331
virtual bool CallFunc_IsValid(CallFunc_t *func) const
Definition: TCling.cxx:6739
static void ConstructorName(std::string &name, const clang::NamedDecl *decl, cling::Interpreter &interp, const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt)
Definition: TCling.cxx:7472
R__EXTERN Int_t gErrorIgnoreLevel
Definition: TError.h:107
virtual int ClassInfo_Next(ClassInfo_t *info) const
Definition: TCling.cxx:7084
bool IsLoaded() const
virtual const char * WorkingDirectory()
Return working directory.
Definition: TSystem.cxx:866
virtual Int_t UnLock()=0
virtual const char * DataMemberInfo_TypeName(DataMemberInfo_t *dminfo) const
Definition: TCling.cxx:7414
virtual void CallFunc_ExecWithReturn(CallFunc_t *func, void *address, void *ret) const
Definition: TCling.cxx:6656
This namespace contains pre-defined functions to be used in conjuction with TExecutor::Map and TExecu...
Definition: StringConv.hxx:21
virtual void StackTrace()
Print a stack trace.
Definition: TSystem.cxx:737
std::map< SpecialObjectLookupCtx_t, SpecialObjectMap_t > fSpecialObjectMaps
Definition: TCling.h:143
virtual TypedefInfo_t * TypedefInfo_FactoryCopy(TypedefInfo_t *tinfo) const
Definition: TCling.cxx:8131
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:2672
static cling::Interpreter::CompilationResult ExecAutoParse(const char *what, Bool_t header, cling::Interpreter *interpreter)
Parse the payload or header.
Definition: TCling.cxx:5298
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:2728
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:478
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:3942
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:5760
TDictionary::DeclId_t DeclId_t
Definition: TInterpreter.h:249
virtual int BaseClassInfo_Next(BaseClassInfo_t *bcinfo) const
Definition: TCling.cxx:7224
return c
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:680
TEnum * Find(DeclId_t id) const
Return the TEnum corresponding to the Decl &#39;id&#39; 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:8038
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 split type.
Definition: TClassEdit.cxx:938
virtual void MethodInfo_CreateSignature(MethodInfo_t *minfo, TString &signature) const
Definition: TCling.cxx:7701
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:213
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:916
TList * GetListOfEnums(Bool_t load=kTRUE)
Return a list containing the TEnums of a class.
Definition: TClass.cxx:3503
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.
std::atomic< TListOfEnums * > fEnums
Definition: TClass.h:185
virtual CallFunc_t * CallFunc_FactoryCopy(CallFunc_t *func) const
Definition: TCling.cxx:6707
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
void SetFunc(const TClingClassInfo *info, const char *method, const char *arglist, long *poffset)
void Destruct(void *arena, const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt) const
virtual const char * MethodInfo_Title(MethodInfo_t *minfo) const
Definition: TCling.cxx:7851
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:7406
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:6426
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 &#39;id&#39;...
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:3694
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
Definition: TObject.cxx:899
Int_t LastIndex() const
void UpdateListOfGlobals()
No op: see TClingCallbacks (used to update the list of globals)
Definition: TCling.cxx:3155
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format...
Definition: TFile.h:50
void UpdateListOfGlobalFunctions()
No op: see TClingCallbacks (used to update the list of global functions)
Definition: TCling.cxx:3162
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:8002
const char * Name() const
void SaveContext()
Save the current Cling state.
Definition: TCling.cxx:3129
virtual MethodInfo_t * CallFunc_FactoryMethod(CallFunc_t *func) const
Definition: TCling.cxx:6714
cling::Interpreter * fInterpreter
Definition: TCling.h:120
virtual ClassInfo_t * ClassInfo_Factory(Bool_t all=kTRUE) const
Definition: TCling.cxx:6972
virtual const char * HomeDirectory(const char *userName=0)
Return the user&#39;s home directory.
Definition: TSystem.cxx:882
void SetArg(long arg)
static void RemoveClassDeclId(TDictionary::DeclId_t id)
Definition: TClass.cxx:503
Long_t Property() const
Set TObject::fBits and fStreamerType to cache information about the class.
Definition: TClass.cxx:5671
virtual BaseClassInfo_t * BaseClassInfo_Factory(ClassInfo_t *info) const
Definition: TCling.cxx:7204
const char * GetClassSharedLibs(const char *cls)
Get the list of shared libraries containing the code for class cls.
Definition: TCling.cxx:6061
const char * GetValue() const
Definition: TEnv.h:114
void TCling__DEBUG__dump(clang::DeclContext *DC)
Definition: TCling.cxx:209
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:7694
virtual void CallFunc_SetArgArray(CallFunc_t *func, Long_t *paramArr, Int_t nparam) const
Definition: TCling.cxx:6812
virtual const char * TypedefInfo_TrueName(TypedefInfo_t *tinfo) const
Definition: TCling.cxx:8180
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:557
#define gROOT
Definition: TROOT.h:364
virtual TObject * Remove(TObject *obj)
Remove object from array.
Definition: TObjArray.cxx:653
TList * GetListOfDataMembers(Bool_t load=kTRUE)
Return list containing the TDataMembers of a class.
Definition: TClass.cxx:3559
bool LoadPCM(TString pcmFileName, const char **headers, void(*triggerFunc)()) const
Tries to load a PCM; returns true on success.
Definition: TCling.cxx:1274
clang::QualType ReSubstTemplateArg(clang::QualType input, const clang::Type *instance)
Check if &#39;input&#39; 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:7546
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&#39;s memory.
Definition: TCling.cxx:2800
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:200
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:5164
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:4068
static int HandleInterpreterException(cling::MetaProcessor *metaProcessor, const char *input_line, cling::Interpreter::CompilationResult &compRes, cling::Value *result)
Let cling process a command line.
Definition: TCling.cxx:1867
static Bool_t HasNoInfoOrEmuOrFwdDeclaredDecl(const char *)
Definition: TClass.cxx:3181
bool HasDefaultConstructor() const
virtual TApplicationImp * GetApplicationImp()
Definition: TApplication.h:137
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:997
bool Bool_t
Definition: RtypesCore.h:59
virtual const char * MethodInfo_GetMangledName(MethodInfo_t *minfo) const
Definition: TCling.cxx:7806
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:7569
TArc * a
Definition: textangle.C:12
virtual int DisplayIncludePath(FILE *fout) const
Interface to cling function.
Definition: TCling.cxx:6207
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:515
const char * fantomline
Definition: TCling.cxx:854
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:7295
virtual void TypeInfo_Delete(TypeInfo_t *tinfo) const
Definition: TCling.cxx:8015
virtual Long_t CallFunc_ExecInt(CallFunc_t *func, void *address) const
Definition: TCling.cxx:6675
Int_t DeleteVariable(const char *name)
Undeclare obj called name.
Definition: TCling.cxx:3070
virtual int SetClassAutoparsing(int)
Enable/Disable the Autoparsing of headers.
Definition: TCling.cxx:6376
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:6307
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:8045
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:4095
std::vector< cling::Value > * fTemporaries
Definition: TCling.h:123
virtual ~TCling()
Destroy the interpreter interface.
Definition: TCling.cxx:1191
const char * Class
Definition: TXMLSetup.cxx:64
virtual const char * DataMemberInfo_Title(DataMemberInfo_t *dminfo) const
Definition: TCling.cxx:7438
virtual void LoadFunctionTemplates(TClass *cl) const
Create list of pointers to function templates for TClass cl.
Definition: TCling.cxx:3600
void GetCppName(std::string &output, const char *input)
Return (in the argument &#39;output&#39;) a mangled version of the C++ symbol/type (pass as &#39;input&#39;) that can...
virtual bool MethodArgInfo_IsValid(MethodArgInfo_t *marginfo) const
Definition: TCling.cxx:7954
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:7390
virtual Long_t TypedefInfo_Property(TypedefInfo_t *tinfo) const
Definition: TCling.cxx:8164
virtual void * ClassInfo_New(ClassInfo_t *info) const
Definition: TCling.cxx:7092
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:6198
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:4496
virtual TObject * At(Int_t idx) const
Returns the object at position idx. Returns 0 if idx is out of range.
Definition: TList.cxx:311
virtual int GetProcInfo(ProcInfo_t *info) const
Returns cpu and memory used by this process into the ProcInfo_t structure.
Definition: TSystem.cxx:2443
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:739
virtual void SetDeclAttr(DeclId_t, const char *)
Definition: TCling.cxx:7457
virtual bool ClassInfo_IsValidMethod(ClassInfo_t *info, const char *method, const char *proto, Long_t *offset, ROOT::EFunctionMatchMode=ROOT::kConversionMatch) const
Definition: TCling.cxx:7068
virtual int DataMemberInfo_MaxIndex(DataMemberInfo_t *dminfo, Int_t dim) const
Definition: TCling.cxx:7366
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:4313
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:6103
const char * Name
Definition: TXMLSetup.cxx:67
virtual bool DiagnoseIfInterpreterException(const std::exception &e) const
Definition: TCling.cxx:1885
static const char * GetMacroPath()
Get macro search path. Static utility function.
Definition: TROOT.cxx:2559
bool ExtractAttrPropertyFromName(const clang::Decl &decl, const std::string &propName, std::string &propValue)
This routine counts on the "propName<separator>propValue" 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:751
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:6266
static void Add(const char *cname, Version_t id, const std::type_info &info, DictFuncPtr_t dict, Int_t pragmabits)
Add a class to the class table (this is a static function).
virtual void MethodArgInfo_Delete(MethodArgInfo_t *marginfo) const
Definition: TCling.cxx:7923
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:8078
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:6557
virtual Long_t BaseClassInfo_Offset(BaseClassInfo_t *toBaseClassInfo, void *address, bool isDerivedObject) const
Definition: TCling.cxx:7240
virtual TObject * FindObject(const char *name) const
Find an object in this collection using its name.
Definition: TObjArray.cxx:396
void TCling__DEBUG__decl_dump(void *D)
Definition: TCling.cxx:218
Int_t UnloadLibraryMap(const char *library)
Unload library map entries coming from the specified library.
Definition: TCling.cxx:5068
virtual void Fatal(const char *method, const char *msgfmt,...) const
Issue fatal error message.
Definition: TObject.cxx:953
virtual TEnum * CreateEnum(void *VD, TClass *cl) const
Definition: TCling.cxx:433
virtual void GenericError(const char *error) const
Let the interpreter issue a generic error, and set its error state.
Definition: TCling.cxx:6244
void ClearStack()
Delete existing temporary values.
Definition: TCling.cxx:2481
virtual const char * GetDirEntry(void *dirp)
Get a directory entry. Returns 0 if no more entries.
Definition: TSystem.cxx:848
virtual void ClassInfo_Init(ClassInfo_t *info, const char *funcname) const
Definition: TCling.cxx:7019
void ResetAll()
Reset the Cling state to its initial state.
Definition: TCling.cxx:2996
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:4605
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:6730
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:3866
THashTable implements a hash table to store TObject&#39;s.
Definition: THashTable.h:39
const char * TCling__GetClassSharedLibs(const char *className)
Definition: TCling.cxx:610
clang::NamespaceDecl * TCling__DEBUG__DCtoNamespace(clang::DeclContext *DC)
Definition: TCling.cxx:203
const Config_t & GetConfig() const
Definition: TMetaUtils.cxx:327
void ExecuteWithArgsAndReturn(TMethod *method, void *address, const void *args[]=0, int nargs=0, void *ret=0) const
Definition: TCling.cxx:4465
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:3911
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:2335
virtual TypedefInfo_t * TypedefInfo_Factory() const
Definition: TCling.cxx:8115
virtual Long_t BaseClassInfo_Property(BaseClassInfo_t *bcinfo) const
Definition: TCling.cxx:7261
virtual void Sleep(UInt_t milliSec)
Sleep milliSec milli seconds.
Definition: TSystem.cxx:442
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:3386
std::atomic< TList * > fBase
Definition: TClass.h:182
virtual void CallFunc_Exec(CallFunc_t *func, void *address) const
Definition: TCling.cxx:6640
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:2494
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:7580
void ShortType(std::string &answer, int mode)
Return the absolute type of typeDesc into the string answ.
Definition: TClassEdit.cxx:198
void GetInterpreterTypeName(const char *name, std::string &output, Bool_t full=kFALSE)
The &#39;name&#39; is known to the interpreter, this function returns the internal version of this name (usua...
Definition: TCling.cxx:4280
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:3637
void SetArgs(const char *args)
char * DemangleName(const char *mangled_name, int &errorCode)
Definition: TClassEdit.h:197
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:4190
virtual void ClassInfo_DeleteArray(ClassInfo_t *info, void *arena, bool dtorOnly) const
Definition: TCling.cxx:6956
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:4235
void Init(TClassEdit::TInterpreterLookupHelper *helper)
Definition: TClassEdit.cxx:119
virtual MethodInfo_t * MethodInfo_FactoryCopy(MethodInfo_t *minfo) const
Definition: TCling.cxx:7735
void ClearFileBusy()
Reset the interpreter internal state in case a previous action was not correctly terminated.
Definition: TCling.cxx:2473
virtual Int_t Lock()=0
static void UpdateClassInfo(char *name, Long_t tagnum)
No op: see TClingCallbacks.
Definition: TCling.cxx:5734
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:3529
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:7382
TString fSharedLibs
Definition: TCling.h:104
void Clear()
Clear string without changing its capacity.
Definition: TString.cxx:1140
virtual Bool_t Declare(const char *code)=0
bool Append(const std::string &str)
Append string to the storage if not added already.
Definition: TCling.cxx:1029
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:2797
virtual const char * ClassInfo_FileName(ClassInfo_t *info) const
Definition: TCling.cxx:7148
virtual const char * TypeInfo_Name(TypeInfo_t *) const
Definition: TCling.cxx:8062
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:6329
TEnv * fMapfile
Definition: TCling.h:108
EFunctionMatchMode
Definition: TDictionary.h:155
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:1055
virtual const char * GetCurrentMacroName() const
Return the file name of the currently interpreted file, included or not.
Definition: TCling.cxx:4543
virtual int SetClassAutoloading(int) const
Enable/Disable the Autoloading of libraries.
Definition: TCling.cxx:6361
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:7037
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:7248
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:4135
virtual int MethodInfo_NArg(MethodInfo_t *minfo) const
Definition: TCling.cxx:7758
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:6411
const char * TypeName() const
Long_t ProcessLine(const char *line, EErrorCode *error=0)
Definition: TCling.cxx:1896
virtual Long_t ClassInfo_Property(ClassInfo_t *info) const
Definition: TCling.cxx:7124
virtual bool Update(DataMemberInfo_t *info)
Update the TFunction to reflect the new info.
R__EXTERN int optind
Definition: TCling.cxx:303
Emulation of the CINT TypeInfo class.
virtual int TypedefInfo_Next(TypedefInfo_t *tinfo) const
Definition: TCling.cxx:8156
virtual bool TypeInfo_IsValid(TypeInfo_t *tinfo) const
Definition: TCling.cxx:8054
Book space in a file, create I/O buffers, to fill them, (un)compress them.
Definition: TKey.h:30
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:925
clang::RecordDecl * TCling__DEBUG__DCtoRecordDecl(clang::DeclContext *DC)
Definition: TCling.cxx:206
TList * fMethodArgs
Definition: TFunction.h:39
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:808
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:3978
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:5050
void InitRootmapFile(const char *name)
Create a resource table and read the (possibly) three resource files, i.e $ROOTSYS/etc/system<name> (...
Definition: TCling.cxx:4708
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 &#39;long long&#39; and &#39;unsigned long long&#39; by &#39;Long64_t&#39; and &#39;ULong64_t&#39;.
Definition: TClassEdit.cxx:817
void InspectMembers(TMemberInspector &, const void *obj, const TClass *cl, Bool_t isTransient)
Visit all members over members, recursing over base classes.
Definition: TCling.cxx:2094
virtual bool ClassInfo_IsEnum(const char *name) const
Definition: TCling.cxx:7045
static void TCling__UpdateClassInfo(const NamedDecl *TD)
Update TClingClassInfo for a class (e.g. upon seeing a definition).
Definition: TCling.cxx:353
void * InterfaceMethod()
void TCling__DEBUG__printName(clang::Decl *D)
Definition: TCling.cxx:221
EComplexType GetComplexType(const char *)
Definition: TClassEdit.cxx:97
long ExtraProperty() const
void GetObject(const char *namecycle, T *&ptr)
virtual Long_t DataMemberInfo_TypeProperty(DataMemberInfo_t *dminfo) const
Definition: TCling.cxx:7398
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:129
void PrintIntro()
No-op; see TRint instead.
Definition: TCling.cxx:2071
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:597
const Decl * TCling__GetObjectDecl(TObject *obj)
Definition: TCling.cxx:583
R__EXTERN TROOT * gROOTLocal
Definition: TROOT.h:361
void UpdateListOfTypes()
No op: see TClingCallbacks (used to update the list of types)
Definition: TCling.cxx:3169
virtual const char * TypeInfo_TrueName(TypeInfo_t *tinfo) const
Definition: TCling.cxx:8094
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:7840
const char * Name() const
RooArgSet S(const RooAbsArg &v1)
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:5363
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:6820
const char * TmpltName() const
void Init(const char *name)
bool TCling__TEST_isInvalidDecl(clang::Decl *D)
Definition: TCling.cxx:236
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:5495
virtual bool MethodInfo_IsValid(MethodInfo_t *minfo) const
Definition: TCling.cxx:7750
int MaxIndex(int dim) const
void TCling__SplitAclicMode(const char *fileName, string &mode, string &args, string &io, string &fname)
Definition: TCling.cxx:634
std::vector< std::string > fElements
Definition: TClassEdit.h:140
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:8070
Bool_t EndsWith(const char *pat, ECaseCompare cmp=kExact) const
Return true if string ends with the specified string.
Definition: TString.cxx:2221
Emulation of the CINT BaseClassInfo class.
TClingMethodInfo * FactoryMethod() const
R__EXTERN TSystem * gSystem
Definition: TSystem.h:549
if object ctor succeeded but object should not be used
Definition: TObject.h:70
void * InterfaceMethod(const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt) const
virtual const char * DataMemberInfo_TypeTrueName(DataMemberInfo_t *dminfo) const
Definition: TCling.cxx:7422
ptrdiff_t Offset(void *address=0, bool isDerivedObject=true) const
virtual void GetFunctionName(const clang::FunctionDecl *decl, std::string &name) const
Definition: TCling.cxx:7494
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:3553
std::set< TClass * > & GetModTClasses()
Definition: TCling.h:508
virtual int TypeInfo_Size(TypeInfo_t *tinfo) const
Definition: TCling.cxx:8086
static void UpdateAllCanvases()
Update all canvases at end the terminal input command.
Definition: TCling.cxx:5749
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:6699
Long_t fMemVirtual
Definition: TSystem.h:207
const char * DefaultValue() const
const T * GetAnnotatedRedeclarable(const T *Redecl)
Definition: TMetaUtils.h:628
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:552
TObject * Remove(TObject *obj)
Remove object from the list.
Definition: THashList.cxx:285
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:6144
int TCling__AutoParseCallback(const char *className)
Definition: TCling.cxx:605
virtual const char * DataMemberInfo_ValidArrayIndex(DataMemberInfo_t *dminfo) const
Definition: TCling.cxx:7446
void SaveGlobalsContext()
Save the current Cling state of global objects.
Definition: TCling.cxx:3142
void UpdateClassInfoWithDecl(const void *vTD)
Internal function. Inform a TClass about its new TagDecl or NamespaceDecl.
Definition: TCling.cxx:5661
unsigned int UInt_t
Definition: RtypesCore.h:42
virtual Long_t BaseClassInfo_Tagnum(BaseClassInfo_t *bcinfo) const
Definition: TCling.cxx:7277
Bool_t TestBit(UInt_t f) const
Definition: TObject.h:159
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:7174
void UpdateListOfLoadedSharedLibraries()
Definition: TCling.cxx:2651
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:6828
static double P[]
virtual TypeInfo_t * MethodInfo_Type(MethodInfo_t *minfo) const
Definition: TCling.cxx:7798
Long_t Calc(const char *line, EErrorCode *error=0)
Directly execute an executable statement (e.g.
Definition: TCling.cxx:2874
Double_t E()
Definition: TMath.h:54
Int_t RescanLibraryMap()
Scan again along the dynamic path for library maps.
Definition: TCling.cxx:4977
ROOT::ESTLType IsSTLCont(const clang::RecordDecl &cl)
type : type name: vector<list<classA,allocator>,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:6284
virtual bool TypedefInfo_IsValid(TypedefInfo_t *tinfo) const
Definition: TCling.cxx:8148
virtual Bool_t LoadText(const char *text) const
Load the declarations from text into the interpreter.
Definition: TCling.cxx:6321
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:7774
clang::QualType GetQualType() const
const std::string sname
Definition: testIO.cxx:45
virtual int MethodInfo_NDefaultArg(MethodInfo_t *minfo) const
Definition: TCling.cxx:7766
virtual int MethodArgInfo_Next(MethodArgInfo_t *marginfo) const
Definition: TCling.cxx:7962
void TCling__PrintStackTrace()
Print a StackTrace!
Definition: TCling.cxx:346
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:5551
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:4483
virtual void Initialize()
Initialize the interpreter, once TROOT::fInterpreter is set.
Definition: TCling.cxx:1216
Bool_t CheckClassTemplate(const char *name)
Return true if there is a class template by the given name ...
Definition: TCling.cxx:3509
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:6855
void SetPathsForRelocatability(std::vector< std::string > &clingArgs)
Organise the parameters for cling in order to guarantee relocatability It treats the gcc toolchain an...
TString fName
Definition: TNamed.h:36
bool IsStdClass(const char *type)
return true if the class belongs to the std namespace
virtual void FreeDirectory(void *dirp)
Free a directory.
Definition: TSystem.cxx:840
virtual const char * MethodInfo_GetPrototype(MethodInfo_t *minfo) const
Definition: TCling.cxx:7816
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:6664
TObject * TCling__GetObjectAddress(const char *Name, void *&LookupCtx)
Definition: TCling.cxx:579
virtual Bool_t FuncTempInfo_IsValid(FuncTempInfo_t *) const
Check validity of a FuncTempInfo_t.
Definition: TCling.cxx:7557
TObjArray * Tokenize(const TString &delim) const
This function is used to isolate sequential tokens in a TString.
Definition: TString.cxx:2241
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:2520
Type
enumeration specifying the integration types.
Bool_t fLockProcessLine
Definition: TCling.h:117
R__DLLEXPORT void DestroyInterpreter(TInterpreter *interp)
Definition: TCling.cxx:593
bool IsAutoloadingEnabled()
const char * TypeName() const
TDictionary::DeclId_t DeclId_t
Definition: TListOfEnums.h:63
#define R__LOCKGUARD2(mutex)
virtual void CallFunc_Delete(CallFunc_t *func) const
Definition: TCling.cxx:6633
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:2114
std::unordered_set< const clang::NamespaceDecl * > fNSFromRootmaps
Definition: TCling.h:115
virtual const char * BaseClassInfo_FullName(BaseClassInfo_t *bcinfo) const
Definition: TCling.cxx:7285
virtual MethodInfo_t * MethodInfo_Factory() const
Definition: TCling.cxx:7709
void TCling__GetNormalizedContext(const ROOT::TMetaUtils::TNormalizedCtxt *&normCtxt)
Definition: TCling.cxx:544
int Size() const
Return the size in bytes of the underlying type of the current typedef.
virtual const void * GetValAddr() const =0
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:2532
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&#39;s memory.
Definition: TClass.cxx:5545
void SetClassInfo(TClass *cl, Bool_t reload=kFALSE)
Set pointer to the TClingClassInfo in TClass.
Definition: TCling.cxx:3283
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:7978
virtual const char * ClassInfo_Name(ClassInfo_t *info) const
Definition: TCling.cxx:7166
virtual const char * GetIncludePath()
Get the list of include path.
Definition: TSystem.cxx:3815
virtual bool DataMemberInfo_IsValid(DataMemberInfo_t *dminfo) const
Definition: TCling.cxx:7358
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:690
TInterpreterValue * CreateTemporary()
The created temporary must be deleted by the caller.
Definition: TCling.cxx:6458
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:4154
void UpdateListsOnUnloaded(const cling::Transaction &T)
Definition: TCling.cxx:5898
virtual FuncTempInfo_t * FuncTempInfo_Factory(DeclId_t declid) const
Construct a FuncTempInfo_t.
Definition: TCling.cxx:7535
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:7662
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:3664
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:5845
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:565
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 &#39;declid&#39; is declared in the context described by &#39;info&#39;...
Definition: TCling.cxx:6912
Definition: TCling.h:48
TFunction * Find(DeclId_t id) const
Return the TMethod or TFunction describing the function corresponding to the Decl &#39;id&#39;...
virtual const char * DataMemberInfo_Name(DataMemberInfo_t *dminfo) const
Definition: TCling.cxx:7430
void Unload()
Mark &#39;all func&#39; as being unloaded.
virtual int DataMemberInfo_ArrayDim(DataMemberInfo_t *dminfo) const
Definition: TCling.cxx:7316
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:1829
Bool_t IsAutoLoadNamespaceCandidate(const char *name)
Definition: TCling.cxx:5643
virtual void CallFunc_ResetArg(CallFunc_t *func) const
Definition: TCling.cxx:6756
virtual void FuncTempInfo_Delete(FuncTempInfo_t *) const
Delete the FuncTempInfo_t.
Definition: TCling.cxx:7526
TDictionary::DeclId_t DeclId_t
void DeleteArray(void *arena, bool dtorOnly, const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt) const
int type
Definition: TGX11.cxx:120
void ResetGlobalVar(void *obj)
Reset the Cling &#39;user&#39; global objects/variables state to the state saved by the last call to TCling::...
Definition: TCling.cxx:3026
unsigned long long ULong64_t
Definition: RtypesCore.h:70
Print a TSeq at the prompt:
Definition: TDatime.h:114
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:4257
TNamed()
Definition: TNamed.h:40
#define free
Definition: civetweb.c:821
unsigned long ULong_t
Definition: RtypesCore.h:51
virtual Long64_t CallFunc_ExecInt64(CallFunc_t *func, void *address) const
Definition: TCling.cxx:6683
void Reset()
Pressing Ctrl+C should forward here.
Definition: TCling.cxx:2980
Int_t LoadLibraryMap(const char *rootmapfile=0)
Load map between class and library.
Definition: TCling.cxx:4787
void CreateListOfMethodArgs(TFunction *m) const
Create list of pointers to method arguments for TMethod m.
Definition: TCling.cxx:3671
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:370
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:5210
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:814
you should not use this method at all Int_t Int_t Double_t Double_t Double_t e
Definition: TRolke.cxx:630
virtual int GetSecurityError() const
Interface to cling function.
Definition: TCling.cxx:6294
#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:494
long Property() const
virtual void Add(TObject *obj)=0
virtual void * MethodInfo_InterfaceMethod(MethodInfo_t *minfo) const
Definition: TCling.cxx:7742
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:2927
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:2882
char fPrompt[64]
Definition: TCling.h:101
virtual void ClassInfo_Delete(ClassInfo_t *info) const
Definition: TCling.cxx:6941
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:1490
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:4989
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:5389
void UpdateListOfMethods(TClass *cl) const
Update the list of pointers to method for TClass cl This is now a nop.
Definition: TCling.cxx:3655
TVirtualCollectionProxy * GetCollectionProxy() const
Return the proxy describing the collection (if any).
Definition: TClass.cxx:2811
void * New(const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt) const
virtual const char * TypedefInfo_Name(TypedefInfo_t *tinfo) const
Definition: TCling.cxx:8188
void RecursiveRemove(TObject *obj)
Delete object from cling symbol table so it can not be used anymore.
Definition: TCling.cxx:2962
TDataMember * GetDataMember(const char *datamember) const
Return pointer to datamember object with name "datamember".
Definition: TClass.cxx:3222
virtual int ClassInfo_Size(ClassInfo_t *info) const
Definition: TCling.cxx:7132
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:1838
virtual Double_t CallFunc_ExecDouble(CallFunc_t *func, void *address) const
Definition: TCling.cxx:6691
TString fIncludePath
Definition: TCling.h:106
Mother of all ROOT objects.
Definition: TObject.h:44
virtual bool ClassInfo_HasMethod(ClassInfo_t *info, const char *name) const
Definition: TCling.cxx:7011
void TCling__LibraryUnloadedRTTI(const void *dyLibHandle, const char *canonicalName)
Definition: TCling.cxx:571
virtual Long_t MethodArgInfo_Property(MethodArgInfo_t *marginfo) const
Definition: TCling.cxx:7970
void RegisterTemporary(const TInterpreterValue &value)
Definition: TCling.cxx:6475
Global functions class (global functions are obtained from CINT).
Definition: TFunction.h:30
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:6276
#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:460
typedef void((*Func_t)())
Version_t fClassVersion
Definition: TClass.h:201
void Unload()
Mark &#39;all func&#39; as being unloaded.
const char * GetDeclFileName() const
Definition: TClass.h:386
virtual bool ClassInfo_IsLoaded(ClassInfo_t *info) const
Definition: TCling.cxx:7052
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:4047
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:7824
const char * GetUnqualifiedName(const char *name)
Return the start of the unqualified name include in &#39;original&#39;.
Definition: TClassEdit.cxx:851
const char * GetFullTypeName() const
Get full type description of method argument, e.g.: "class TDirectory*".
Definition: TMethodArg.cxx:75
void Unload()
Mark &#39;all func&#39; 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:1021
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:7060
long Property() const
void ReplaceAll(std::string &str, const std::string &from, const std::string &to, bool recurse=false)
std::string GetROOTIncludeDir(bool rootbuild)
Definition: file.py:1
virtual Long_t ClassInfo_Tagnum(ClassInfo_t *info) const
Definition: TCling.cxx:7140
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:7790
void MakeZombie()
Definition: TObject.h:54
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
std::string AtlernateTuple(const char *classname)
Definition: TCling.cxx:3217
virtual void CallFunc_IgnoreExtraArgs(CallFunc_t *func, bool ignore) const
Definition: TCling.cxx:6722
virtual const char * GetSTLIncludePath() const
Return the directory containing CINT&#39;s stl cintdlls.
Definition: TCling.cxx:6189
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:7832
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:5130
#define snprintf
Definition: civetweb.c:822
Bool_t IsLoaded(const char *filename) const
Return true if the file has already been loaded by cint.
Definition: TCling.cxx:2545
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:6964
virtual const char * ClassInfo_FullName(ClassInfo_t *info) const
Definition: TCling.cxx:7156
virtual void UpdateEnumConstants(TEnum *enumObj, TClass *cl) const
Definition: TCling.cxx:385
virtual void * OpenDirectory(const char *name)
Open a directory. Returns 0 if directory does not exist.
Definition: TSystem.cxx:831
const char * proto
Definition: civetweb.c:11652
R__EXTERN Int_t gDebug
Definition: Rtypes.h:128
ROOT::ESTLType GetCollectionType() const
Return the &#39;type&#39; of the STL the TClass is representing.
Definition: TClass.cxx:2800
Bool_t SetSuspendAutoParsing(Bool_t value)
Suspend the Autoparsing of headers.
Definition: TCling.cxx:6387
virtual const char * BaseClassInfo_TmpltName(BaseClassInfo_t *bcinfo) const
Definition: TCling.cxx:7303
virtual const char * MethodArgInfo_Name(MethodArgInfo_t *marginfo) const
Definition: TCling.cxx:7986
Int_t fMore
Definition: TCling.h:99
virtual const char * ClassInfo_TmpltName(ClassInfo_t *info) const
Definition: TCling.cxx:7182
int RefType() const
static const std::string ioname("ioname")
static bool R__InitStreamerInfoFactory()
Helper to initialize TVirtualStreamerInfo&#39;s factor early.
Definition: TCling.cxx:1259
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:6130
void IgnoreExtraArgs(bool ignore)
#define gDirectory
Definition: TDirectory.h:221
long Property() const
Bool_t fIsAutoParsingSuspended
Definition: TCling.h:148
double result[121]
static void UpdateClassInfoWork(const char *name)
Definition: TCling.cxx:5740
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:4639
void ResetBit(UInt_t f)
Definition: TObject.h:158
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:907
std::hash< std::string > fStringHashFunction
Definition: TCling.h:114
virtual void TypedefInfo_Init(TypedefInfo_t *tinfo, const char *name) const
Definition: TCling.cxx:8138
const char * GetSharedLibs()
Return the list of shared libraries loaded into the process.
Definition: TCling.cxx:6048
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:1224
virtual EReturnType MethodInfo_MethodCallReturnType(MethodInfo_t *minfo) const
Definition: TCling.cxx:7870
R__EXTERN TInterpreter * gCling
Definition: TInterpreter.h:517
R__DLLEXPORT TInterpreter * CreateInterpreter(void *interpLibHandle)
Definition: TCling.cxx:587
virtual void * FindSym(const char *entry) const
Interface to cling function.
Definition: TCling.cxx:6236
void CodeComplete(const std::string &, size_t &, std::vector< std::string > &)
The call to Cling&#39;s tab complition.
Definition: TCling.cxx:6467
virtual void Compress()
Remove empty slots from array.
Definition: TObjArray.cxx:309
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:2849
static void output(int code)
Definition: gifencode.c:226
virtual void DataMemberInfo_Delete(DataMemberInfo_t *dminfo) const
Definition: TCling.cxx:7324
const Bool_t kTRUE
Definition: Rtypes.h:91
void TCling__TransactionRollback(const cling::Transaction &T)
Definition: TCling.cxx:561
virtual const char * GetTitle() const
Returns title of object.
Definition: TObject.cxx:460
TList * GetListOfMethods(Bool_t load=kTRUE)
Return list containing the TMethods of a class.
Definition: TClass.cxx:3608
std::string NormalizedName(const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt) const
Return the normalized name of the type (i.e.
void Unload()
Mark &#39;all func&#39; 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:1045
void LoadMacro(const char *filename, EErrorCode *error=0)
Load a macro file in cling&#39;s memory.
Definition: TCling.cxx:2841
virtual ClassInfo_t * BaseClassInfo_ClassInfo(BaseClassInfo_t *) const
Definition: TCling.cxx:7269
static DictFuncPtr_t GetDictNorm(const char *cname)
Given the normalized class name returns the Dictionary() function of a class (uses hash of name)...
static ETupleOrdering IsTupleAscending()
Definition: TCling.cxx:3193
const char * TypeName(const char *typeDesc)
Return the absolute type of typeDesc.
Definition: TCling.cxx:4558
virtual EReturnType MethodCallReturnType(TFunction *func) const
Definition: TCling.cxx:7859
return
Definition: HLFactory.cxx:514
static char * skip(char **buf, const char *delimiters)
Definition: civetweb.c:2039
Double_t ex[n]
Definition: legend1.C:17
void LibraryUnloaded(const void *dyLibHandle, const char *canonicalName)
Definition: TCling.cxx:6040
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:3041
virtual MethodArgInfo_t * MethodArgInfo_FactoryCopy(MethodArgInfo_t *marginfo) const
Definition: TCling.cxx:7946
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:2080
void CreateListOfMethods(TClass *cl) const
Create list of pointers to methods for TClass cl.
Definition: TCling.cxx:3646
Int_t DeleteGlobal(void *obj)
Delete obj from Cling symbol table so it cannot be accessed anymore.
Definition: TCling.cxx:3055
TRandom3 R
a TMatrixD.
Definition: testIO.cxx:28
virtual TypeInfo_t * TypeInfo_Factory() const
Definition: TCling.cxx:8022
virtual const char * MethodArgInfo_TypeName(MethodArgInfo_t *marginfo) const
Definition: TCling.cxx:7994
TDictionary::DeclId_t GetDeclId() const
virtual void SetErrmsgcallback(void *p) const
Set a callback to receive error messages.
Definition: TCling.cxx:6397
void ResetGlobals()
Reset in Cling the list of global variables to the state saved by the last call to TCling::SaveGlobal...
Definition: TCling.cxx:3012
virtual const char * TypedefInfo_Title(TypedefInfo_t *tinfo) const
Definition: TCling.cxx:8196
char name[80]
Definition: TGX11.cxx:109
Int_t Size() const
Return size of object of this class.
Definition: TClass.cxx:5344
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:6342
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:6764
if(line.BeginsWith("/*"))
Definition: HLFactory.cxx:443
virtual Long_t FuncTempInfo_Property(FuncTempInfo_t *) const
Return the property of the function template.
Definition: TCling.cxx:7590
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:7350
void ExecWithReturn(void *address, void *ret=0)
virtual int UnloadFile(const char *path) const
Definition: TCling.cxx:6441
virtual int DataMemberInfo_Next(DataMemberInfo_t *dminfo) const
Definition: TCling.cxx:7374
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:2858
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:6995
TList * GetListOfFunctionTemplates(Bool_t load=kTRUE)
Return list containing the TEnums of a class.
Definition: TClass.cxx:3594
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:7649
virtual void TypedefInfo_Delete(TypedefInfo_t *tinfo) const
Definition: TCling.cxx:8108
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition: TObject.cxx:911