ROOT  6.06/08
Reference Guide
TCling.cxx
Go to the documentation of this file.
1 // @(#)root/meta:$Id$
2 // vim: sw=3 ts=3 expandtab foldmethod=indent
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2012, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 /** \class TCling
13 
14 This class defines an interface to the cling C++ interpreter.
15 
16 Cling is a full ANSI compliant C++-11 interpreter based on
17 clang/LLVM technology.
18 */
19 
20 #include "TCling.h"
21 
22 #include "TClingBaseClassInfo.h"
23 #include "TClingCallFunc.h"
24 #include "TClingClassInfo.h"
25 #include "TClingDataMemberInfo.h"
26 #include "TClingMethodArgInfo.h"
27 #include "TClingMethodInfo.h"
28 #include "TClingTypedefInfo.h"
29 #include "TClingTypeInfo.h"
30 #include "TClingValue.h"
31 
32 #include "TROOT.h"
33 #include "TApplication.h"
34 #include "TGlobal.h"
35 #include "TDataType.h"
36 #include "TClass.h"
37 #include "TClassEdit.h"
38 #include "TClassTable.h"
39 #include "TClingCallbacks.h"
40 #include "TBaseClass.h"
41 #include "TDataMember.h"
42 #include "TMemberInspector.h"
43 #include "TMethod.h"
44 #include "TMethodArg.h"
45 #include "TFunctionTemplate.h"
46 #include "TObjArray.h"
47 #include "TObjString.h"
48 #include "TString.h"
49 #include "THashList.h"
50 #include "TOrdCollection.h"
51 #include "TVirtualPad.h"
52 #include "TSystem.h"
53 #include "TVirtualMutex.h"
54 #include "TError.h"
55 #include "TEnv.h"
56 #include "TEnum.h"
57 #include "TEnumConstant.h"
58 #include "THashTable.h"
59 #include "RConfigure.h"
60 #include "compiledata.h"
61 #include "TMetaUtils.h"
63 #include "TVirtualStreamerInfo.h"
64 #include "TListOfDataMembers.h"
65 #include "TListOfEnums.h"
66 #include "TListOfEnumsWithLock.h"
67 #include "TListOfFunctions.h"
69 #include "TProtoClass.h"
70 #include "TStreamerInfo.h" // This is here to avoid to use the plugin manager
71 #include "ThreadLocalStorage.h"
72 #include "TFile.h"
73 #include "TKey.h"
74 
75 #include "clang/AST/ASTContext.h"
76 #include "clang/AST/Decl.h"
77 #include "clang/AST/DeclarationName.h"
78 #include "clang/AST/GlobalDecl.h"
79 #include "clang/AST/RecordLayout.h"
80 #include "clang/AST/RecursiveASTVisitor.h"
81 #include "clang/AST/Type.h"
82 #include "clang/Basic/SourceLocation.h"
83 #include "clang/Basic/Specifiers.h"
84 #include "clang/Basic/TargetInfo.h"
85 #include "clang/CodeGen/ModuleBuilder.h"
86 #include "clang/Frontend/CompilerInstance.h"
87 #include "clang/Frontend/FrontendDiagnostic.h"
88 #include "clang/Lex/HeaderSearch.h"
89 #include "clang/Lex/Preprocessor.h"
90 #include "clang/Sema/Lookup.h"
91 #include "clang/Sema/Sema.h"
92 #include "clang/Parse/Parser.h"
93 
94 #include "cling/Interpreter/ClangInternalState.h"
95 #include "cling/Interpreter/DynamicLibraryManager.h"
96 #include "cling/Interpreter/Interpreter.h"
97 #include "cling/Interpreter/LookupHelper.h"
98 #include "cling/Interpreter/Value.h"
99 #include "cling/Interpreter/Transaction.h"
100 #include "cling/MetaProcessor/MetaProcessor.h"
101 #include "cling/Utils/AST.h"
102 
103 #include "llvm/IR/GlobalValue.h"
104 #include "llvm/IR/Module.h"
105 
106 #include "llvm/Support/DynamicLibrary.h"
107 #include "llvm/Support/raw_ostream.h"
108 #include "llvm/Support/Path.h"
109 
110 #include <algorithm>
111 #include <iostream>
112 #include <cassert>
113 #include <map>
114 #include <set>
115 #include <stdexcept>
116 #include <stdint.h>
117 #include <fstream>
118 #include <sstream>
119 #include <string>
120 #include <typeinfo>
121 #include <unordered_map>
122 #include <utility>
123 #include <vector>
124 
125 #ifndef R__WIN32
126 #include <cxxabi.h>
127 #define R__DLLEXPORT
128 #endif
129 #include <limits.h>
130 #include <stdio.h>
131 
132 #ifdef __APPLE__
133 #include <dlfcn.h>
134 #include <mach-o/dyld.h>
135 #endif // __APPLE__
136 
137 #ifdef R__UNIX
138 #include <dlfcn.h>
139 #endif
140 
141 #if defined(__CYGWIN__)
142 #include <sys/cygwin.h>
143 #define HMODULE void *
144 extern "C" {
145  __declspec(dllimport) void * __stdcall GetCurrentProcess();
146  __declspec(dllimport) bool __stdcall EnumProcessModules(void *, void **, unsigned long, unsigned long *);
147  __declspec(dllimport) unsigned long __stdcall GetModuleFileNameExW(void *, void *, wchar_t *, unsigned long);
148 }
149 #endif
150 
151 // Fragment copied from LLVM's raw_ostream.cpp
152 #if defined(_MSC_VER)
153 #ifndef STDIN_FILENO
154 # define STDIN_FILENO 0
155 #endif
156 #ifndef STDOUT_FILENO
157 # define STDOUT_FILENO 1
158 #endif
159 #ifndef STDERR_FILENO
160 # define STDERR_FILENO 2
161 #endif
162 #ifndef R__WIN32
163 //#if defined(HAVE_UNISTD_H)
164 # include <unistd.h>
165 //#endif
166 #else
167 #include "Windows4Root.h"
168 #include <Psapi.h>
169 #undef GetModuleFileName
170 #define RTLD_DEFAULT ((void *)::GetModuleHandle(NULL))
171 #define dlsym(library, function_name) ::GetProcAddress((HMODULE)library, function_name)
172 #define dlopen(library_name, flags) ::LoadLibrary(library_name)
173 #define dlclose(library) ::FreeLibrary((HMODULE)library)
174 #define R__DLLEXPORT __declspec(dllexport)
175 #endif
176 #endif
177 
178 //______________________________________________________________________________
179 // Infrastructure to detect and react to libCling being teared down.
180 //
181 namespace {
182  class TCling_UnloadMarker {
183  public:
184  ~TCling_UnloadMarker() {
187  }
188  }
189  };
190  static TCling_UnloadMarker gTClingUnloadMarker;
191 }
192 
193 
194 
195 //______________________________________________________________________________
196 // These functions are helpers for debugging issues with non-LLVMDEV builds.
197 //
198 clang::DeclContext* TCling__DEBUG__getDeclContext(clang::Decl* D) {
199  return D->getDeclContext();
200 }
201 clang::NamespaceDecl* TCling__DEBUG__DCtoNamespace(clang::DeclContext* DC) {
202  return llvm::dyn_cast<clang::NamespaceDecl>(DC);
203 }
204 clang::RecordDecl* TCling__DEBUG__DCtoRecordDecl(clang::DeclContext* DC) {
205  return llvm::dyn_cast<clang::RecordDecl>(DC);
206 }
207 void TCling__DEBUG__dump(clang::DeclContext* DC) {
208  return DC->dumpDeclContext();
209 }
210 void TCling__DEBUG__dump(clang::Decl* D) {
211  return D->dump();
212 }
213 void TCling__DEBUG__dump(clang::FunctionDecl* FD) {
214  return FD->dump();
215 }
217  return ((clang::Decl*)D)->dump();
218 }
219 void TCling__DEBUG__printName(clang::Decl* D) {
220  if (clang::NamedDecl* ND = llvm::dyn_cast<clang::NamedDecl>(D)) {
221  std::string name;
222  {
223  llvm::raw_string_ostream OS(name);
224  ND->getNameForDiagnostic(OS, D->getASTContext().getPrintingPolicy(),
225  true /*Qualified*/);
226  }
227  printf("%s\n", name.c_str());
228  }
229 }
230 //______________________________________________________________________________
231 // These functions are helpers for testing issues directly rather than
232 // relying on side effects.
233 // This is used for the test for ROOT-7462/ROOT-6070
234 bool TCling__TEST_isInvalidDecl(clang::Decl* D) {
235  return D->isInvalidDecl();
236 }
237 bool TCling__TEST_isInvalidDecl(ClassInfo_t *input) {
238  TClingClassInfo *info( (TClingClassInfo*) input);
239  assert(info && info->IsValid());
240  return info->GetDecl()->isInvalidDecl();
241 }
242 
243 using namespace std;
244 using namespace clang;
245 using namespace ROOT;
246 
247 namespace {
248  static const std::string gInterpreterClassDef = R"ICF(
249 #undef ClassDef
250 #define ClassDef(name, id) \
251 _ClassDefInterp_(name,id,virtual,) \
252 static int DeclFileLine() { return __LINE__; }
253 #undef ClassDefNV
254 #define ClassDefNV(name, id) \
255 _ClassDefInterp_(name,id,,) \
256 static int DeclFileLine() { return __LINE__; }
257 #undef ClassDefOverride
258 #define ClassDefOverride(name, id) \
259 _ClassDefInterp_(name,id,,override) \
260 static int DeclFileLine() { return __LINE__; }
261 )ICF";
262 
263  static const std::string gNonInterpreterClassDef = R"ICF(
264 #define __ROOTCLING__ 1
265 #undef ClassDef
266 #define ClassDef(name,id) \
267 _ClassDef_(name,id,virtual,) \
268 static int DeclFileLine() { return __LINE__; }
269 #undef ClassDefNV
270 #define ClassDefNV(name, id)\
271 _ClassDef_(name,id,,)\
272 static int DeclFileLine() { return __LINE__; }
273 #undef ClassDefOverride
274 #define ClassDefOverride(name, id)\
275 _ClassDef_(name,id,,override)\
276 static int DeclFileLine() { return __LINE__; }
277 )ICF";
278 
279 // The macros below use ::Error, so let's ensure it is included
280  static const std::string gClassDefInterpMacro = R"ICF(
281 #ifndef ROOT_TError
282 #include "TError.h"
283 #endif
284 
285 #define _ClassDefInterp_(name,id,virtual_keyword, overrd) \
286 private: \
287 public: \
288  static TClass *Class() { static TClass* sIsA = 0; if (!sIsA) sIsA = TClass::GetClass(#name); return sIsA; } \
289  static const char *Class_Name() { return #name; } \
290  static Version_t Class_Version() { return id; } \
291  static TClass *Dictionary() { return 0; } \
292  virtual_keyword TClass *IsA() const overrd { return name::Class(); } \
293  virtual_keyword void ShowMembers(TMemberInspector&insp) const overrd { ::ROOT::Class_ShowMembers(name::Class(), this, insp); } \
294  virtual_keyword void Streamer(TBuffer&) overrd { ::Error("Streamer", "Cannot stream interpreted class."); } \
295  void StreamerNVirtual(TBuffer&ClassDef_StreamerNVirtual_b) { name::Streamer(ClassDef_StreamerNVirtual_b); } \
296  static const char *DeclFileName() { return __FILE__; } \
297  static int ImplFileLine() { return 0; } \
298  static const char *ImplFileName() { return __FILE__; }
299 )ICF";
300 }
302 
303 // The functions are used to bridge cling/clang/llvm compiled with no-rtti and
304 // ROOT (which uses rtti)
305 
306 //______________________________________________________________________________
307 
308 // Class extracting recursively every Enum type defined for a class.
309 class EnumVisitor : public RecursiveASTVisitor<EnumVisitor> {
310 private:
311  llvm::SmallVector<EnumDecl*,128> &fClassEnums;
312 public:
313  EnumVisitor(llvm::SmallVector<EnumDecl*,128> &enums) : fClassEnums(enums)
314  {}
315 
316  bool TraverseStmt(Stmt*) {
317  // Don't descend into function bodies.
318  return true;
319  }
320 
321  bool shouldVisitTemplateInstantiations() const { return true; }
322 
323  bool TraverseClassTemplateDecl(ClassTemplateDecl*) {
324  // Don't descend into templates (but only instances thereof).
325  return true; // returning false will abort the in-depth traversal.
326  }
327 
328  bool TraverseClassTemplatePartialSpecializationDecl(ClassTemplatePartialSpecializationDecl*) {
329  // Don't descend into templates partial specialization (but only instances thereof).
330  return true; // returning false will abort the in-depth traversal.
331  }
332 
333  bool VisitEnumDecl(EnumDecl *TEnumD) {
334  if (!TEnumD->getDeclContext()->isDependentContext())
335  fClassEnums.push_back(TEnumD);
336  return true; // returning false will abort the in-depth traversal.
337  }
338 };
339 
340 ////////////////////////////////////////////////////////////////////////////////
341 /// Update TClingClassInfo for a class (e.g. upon seeing a definition).
342 
343 static void TCling__UpdateClassInfo(const NamedDecl* TD)
344 {
345  static Bool_t entered = kFALSE;
346  static vector<const NamedDecl*> updateList;
347  Bool_t topLevel;
348 
349  if (entered) topLevel = kFALSE;
350  else {
351  entered = kTRUE;
352  topLevel = kTRUE;
353  }
354  if (topLevel) {
355  ((TCling*)gInterpreter)->UpdateClassInfoWithDecl(TD);
356  } else {
357  // If we are called indirectly from within another call to
358  // TCling::UpdateClassInfo, we delay the update until the dictionary loading
359  // is finished (i.e. when we return to the top level TCling::UpdateClassInfo).
360  // This allows for the dictionary to be fully populated when we actually
361  // update the TClass object. The updating of the TClass sometimes
362  // (STL containers and when there is an emulated class) forces the building
363  // of the TClass object's real data (which needs the dictionary info).
364  updateList.push_back(TD);
365  }
366  if (topLevel) {
367  while (!updateList.empty()) {
368  ((TCling*)gInterpreter)->UpdateClassInfoWithDecl(updateList.back());
369  updateList.pop_back();
370  }
371  entered = kFALSE;
372  }
373 }
374 
375 void TCling::UpdateEnumConstants(TEnum* enumObj, TClass* cl) const {
376  const clang::Decl* D = static_cast<const clang::Decl*>(enumObj->GetDeclId());
377  if(const clang::EnumDecl* ED = dyn_cast<clang::EnumDecl>(D)) {
378  // Add the constants to the enum type.
379  for (EnumDecl::enumerator_iterator EDI = ED->enumerator_begin(),
380  EDE = ED->enumerator_end(); EDI != EDE; ++EDI) {
381  // Get name of the enum type.
382  std::string constbuf;
383  if (const NamedDecl* END = llvm::dyn_cast<NamedDecl>(*EDI)) {
384  PrintingPolicy Policy((*EDI)->getASTContext().getPrintingPolicy());
385  llvm::raw_string_ostream stream(constbuf);
386  (END)->getNameForDiagnostic(stream, Policy, /*Qualified=*/false);
387  }
388  const char* constantName = constbuf.c_str();
389 
390  // Get value of the constant.
391  Long64_t value;
392  const llvm::APSInt valAPSInt = (*EDI)->getInitVal();
393  if (valAPSInt.isSigned()) {
394  value = valAPSInt.getSExtValue();
395  } else {
396  value = valAPSInt.getZExtValue();
397  }
398 
399  // Create the TEnumConstant or update it if existing
400  TEnumConstant* enumConstant = nullptr;
401  TClingClassInfo* tcCInfo = (TClingClassInfo*)(cl ? cl->GetClassInfo() : 0);
402  TClingDataMemberInfo* tcDmInfo = new TClingDataMemberInfo(fInterpreter, *EDI, tcCInfo);
403  DataMemberInfo_t* dmInfo = (DataMemberInfo_t*) tcDmInfo;
404  if (TObject* encAsTObj = enumObj->GetConstants()->FindObject(constantName)){
405  ((TEnumConstant*)encAsTObj)->Update(dmInfo);
406  } else {
407  enumConstant = new TEnumConstant(dmInfo, constantName, value, enumObj);
408  }
409 
410  // Add the global constants to the list of Globals.
411  if (!cl) {
412  TCollection* globals = gROOT->GetListOfGlobals(false);
413  if (!globals->FindObject(constantName)) {
414  globals->Add(enumConstant);
415  }
416  }
417  }
418  }
419 }
420 
421 TEnum* TCling::CreateEnum(void *VD, TClass *cl) const
422 {
423  // Handle new enum declaration for either global and nested enums.
424 
425  // Create the enum type.
426  TEnum* enumType = 0;
427  const clang::Decl* D = static_cast<const clang::Decl*>(VD);
428  std::string buf;
429  if (const EnumDecl* ED = llvm::dyn_cast<EnumDecl>(D)) {
430  // Get name of the enum type.
431  PrintingPolicy Policy(ED->getASTContext().getPrintingPolicy());
432  llvm::raw_string_ostream stream(buf);
433  ED->getNameForDiagnostic(stream, Policy, /*Qualified=*/false);
434  // If the enum is unnamed we do not add it to the list of enums i.e unusable.
435  }
436  if (buf.empty()) {
437  return 0;
438  }
439  const char* name = buf.c_str();
440  if (cl) {
441  enumType = new TEnum(name, VD, cl);
442  } else {
443  enumType = new TEnum(name, VD, cl);
444  }
445  UpdateEnumConstants(enumType, cl);
446 
447  return enumType;
448 }
449 
450 void TCling::HandleNewDecl(const void* DV, bool isDeserialized, std::set<TClass*> &modifiedTClasses) {
451  // Handle new declaration.
452  // Record the modified class, struct and namespaces in 'modifiedTClasses'.
453 
454  const clang::Decl* D = static_cast<const clang::Decl*>(DV);
455 
456  if (!D->isCanonicalDecl() && !isa<clang::NamespaceDecl>(D)
457  && !dyn_cast<clang::RecordDecl>(D)) return;
458 
459  if (isa<clang::FunctionDecl>(D->getDeclContext())
460  || isa<clang::TagDecl>(D->getDeclContext()))
461  return;
462 
463  // Don't list templates.
464  if (const clang::CXXRecordDecl* RD = dyn_cast<clang::CXXRecordDecl>(D)) {
465  if (RD->getDescribedClassTemplate())
466  return;
467  } else if (const clang::FunctionDecl* FD = dyn_cast<clang::FunctionDecl>(D)) {
468  if (FD->getDescribedFunctionTemplate())
469  return;
470  }
471 
472  if (const RecordDecl *TD = dyn_cast<RecordDecl>(D)) {
473  if (TD->isCanonicalDecl() || TD->isThisDeclarationADefinition())
475  }
476  else if (const NamedDecl *ND = dyn_cast<NamedDecl>(D)) {
477 
478  if (const TagDecl *TD = dyn_cast<TagDecl>(D)) {
479  // Mostly just for EnumDecl (the other TagDecl are handled
480  // by the 'RecordDecl' if statement.
482  } else if (const NamespaceDecl* NSD = dyn_cast<NamespaceDecl>(D)) {
484  }
485 
486  // While classes are read completely (except for function template instances,
487  // enum, data (and functions) can be added to namespaces at any time.
488  // [this section can be removed when both the list of data member and the list
489  // of enums has been update to be active list]
490  if (const NamespaceDecl* NCtx = dyn_cast<NamespaceDecl>(ND->getDeclContext())) {
491  if (NCtx->getIdentifier()) {
492  // No need to load the TClass: if there is something to update then
493  // it must already exist.
494  std::string NCtxName;
495  PrintingPolicy Policy(NCtx->getASTContext().getPrintingPolicy());
496  llvm::raw_string_ostream stream(NCtxName);
497  NCtx->getNameForDiagnostic(stream, Policy, /*Qualified=*/true);
498 
499  TClass* cl = (TClass*)gROOT->GetListOfClasses()->FindObject(NCtxName.c_str());
500  if (cl) {
501  modifiedTClasses.insert(cl);
502  }
503  }
504  return;
505  }
506 
507  // We care about declarations on the global scope.
508  if (!isa<TranslationUnitDecl>(ND->getDeclContext()))
509  return;
510 
511  // Enums are lazyly created, thus we don not need to handle them here.
512  if (isa<EnumDecl>(ND))
513  return;
514 
515  // ROOT says that global is enum(lazylycreated)/var/field declared on the global
516  // scope.
517  if (!(isa<VarDecl>(ND)))
518  return;
519 
520  // Skip if already in the list.
521  if (gROOT->GetListOfGlobals()->FindObject(ND->getNameAsString().c_str()))
522  return;
523 
524  // Put the global constants and global enums in the corresponding lists.
525  gROOT->GetListOfGlobals()->Add(new TGlobal((DataMemberInfo_t *)
526  new TClingDataMemberInfo(fInterpreter,
527  cast<ValueDecl>(ND), 0)));
528  }
529 }
530 
531 extern "C"
533 {
534  // We are sure in this context of the type of the interpreter
535  normCtxt = &( (TCling*) gInterpreter)->GetNormalizedContext();
536 }
537 
538 extern "C"
539 void TCling__UpdateListsOnCommitted(const cling::Transaction &T, cling::Interpreter*) {
540 
541  ((TCling*)gCling)->UpdateListsOnCommitted(T);
542 }
543 
544 extern "C"
545 void TCling__UpdateListsOnUnloaded(const cling::Transaction &T) {
546 
547  ((TCling*)gCling)->UpdateListsOnUnloaded(T);
548 }
549 void TCling__TransactionRollback(const cling::Transaction &T) {
550 
551  ((TCling*)gCling)->TransactionRollback(T);
552 }
553 extern "C" void TCling__LibraryLoadedRTTI(const void* dyLibHandle,
554  const char* canonicalName) {
555 
556  ((TCling*)gCling)->LibraryLoaded(dyLibHandle, canonicalName);
557 }
558 
559 extern "C" void TCling__LibraryUnloadedRTTI(const void* dyLibHandle,
560  const char* canonicalName) {
561 
562  ((TCling*)gCling)->LibraryUnloaded(dyLibHandle, canonicalName);
563 }
564 
565 
566 extern "C"
567 TObject* TCling__GetObjectAddress(const char *Name, void *&LookupCtx) {
568  return ((TCling*)gCling)->GetObjectAddress(Name, LookupCtx);
569 }
570 
571 extern "C" const Decl* TCling__GetObjectDecl(TObject *obj) {
572  return ((TClingClassInfo*)obj->IsA()->GetClassInfo())->GetDecl();
573 }
574 
575 extern "C" R__DLLEXPORT TInterpreter *CreateInterpreter(void* interpLibHandle)
576 {
577  cling::DynamicLibraryManager::ExposeHiddenSharedLibrarySymbols(interpLibHandle);
578  return new TCling("C++", "cling C++ Interpreter");
579 }
580 
582 {
583  delete interp;
584 }
585 
586 // Load library containing specified class. Returns 0 in case of error
587 // and 1 in case if success.
588 extern "C" int TCling__AutoLoadCallback(const char* className)
589 {
590  return ((TCling*)gCling)->AutoLoad(className);
591 }
592 
593 extern "C" int TCling__AutoParseCallback(const char* className)
594 {
595  return ((TCling*)gCling)->AutoParse(className);
596 }
597 
598 extern "C" const char* TCling__GetClassSharedLibs(const char* className)
599 {
600  return ((TCling*)gCling)->GetClassSharedLibs(className);
601 }
602 
603 // // Returns 0 for failure 1 for success
604 // extern "C" int TCling__IsAutoLoadNamespaceCandidate(const char* name)
605 // {
606 // return ((TCling*)gCling)->IsAutoLoadNamespaceCandidate(name);
607 // }
608 
609 // Returns 0 for failure 1 for success
610 extern "C" int TCling__IsAutoLoadNamespaceCandidate(const clang::NamespaceDecl* nsDecl)
611 {
612  return ((TCling*)gCling)->IsAutoLoadNamespaceCandidate(nsDecl);
613 }
614 
615 extern "C" int TCling__CompileMacro(const char *fileName, const char *options)
616 {
617  string file(fileName);
618  string opt(options);
619  return gSystem->CompileMacro(file.c_str(), opt.c_str());
620 }
621 
622 extern "C" void TCling__SplitAclicMode(const char* fileName, string &mode,
623  string &args, string &io, string &fname)
624 {
625  string file(fileName);
626  TString f, amode, arguments, aclicio;
627  f = gSystem->SplitAclicMode(file.c_str(), amode, arguments, aclicio);
628  mode = amode.Data(); args = arguments.Data();
629  io = aclicio.Data(); fname = f.Data();
630 }
631 
632 //______________________________________________________________________________
633 //
634 //
635 //
636 
637 #ifdef R__WIN32
638 extern "C" {
639  char *__unDName(char *demangled, const char *mangled, int out_len,
640  void * (* pAlloc )(size_t), void (* pFree )(void *),
641  unsigned short int flags);
642 }
643 #endif
644 
645 ////////////////////////////////////////////////////////////////////////////////
646 /// Find a template decl within N nested namespaces, 0<=N<inf
647 /// Assumes 1 and only 1 template present and 1 and only 1 entity contained
648 /// by the namespace. Example: ns1::ns2::..::nsN::myTemplate
649 /// Returns nullptr in case of error
650 
651 static clang::ClassTemplateDecl* FindTemplateInNamespace(clang::Decl* decl)
652 {
653  using namespace clang;
654  if (NamespaceDecl* nsd = llvm::dyn_cast<NamespaceDecl>(decl)){
655  return FindTemplateInNamespace(*nsd->decls_begin());
656  }
657 
658  if (ClassTemplateDecl* ctd = llvm::dyn_cast<ClassTemplateDecl>(decl)){
659  return ctd;
660  }
661 
662  return nullptr; // something went wrong.
663 }
664 
665 ////////////////////////////////////////////////////////////////////////////////
666 /// Autoload a library provided the mangled name of a missing symbol.
667 
668 void* llvmLazyFunctionCreator(const std::string& mangled_name)
669 {
670  return ((TCling*)gCling)->LazyFunctionCreatorAutoload(mangled_name);
671 }
672 
673 //______________________________________________________________________________
674 //
675 //
676 //
677 
678 int TCling_GenerateDictionary(const std::vector<std::string> &classes,
679  const std::vector<std::string> &headers,
680  const std::vector<std::string> &fwdDecls,
681  const std::vector<std::string> &unknown)
682 {
683  //This function automatically creates the "LinkDef.h" file for templated
684  //classes then executes CompileMacro on it.
685  //The name of the file depends on the class name, and it's not generated again
686  //if the file exist.
687  if (classes.empty()) {
688  return 0;
689  }
690  // Use the name of the first class as the main name.
691  const std::string& className = classes[0];
692  //(0) prepare file name
693  TString fileName = "AutoDict_";
694  std::string::const_iterator sIt;
695  for (sIt = className.begin(); sIt != className.end(); sIt++) {
696  if (*sIt == '<' || *sIt == '>' ||
697  *sIt == ' ' || *sIt == '*' ||
698  *sIt == ',' || *sIt == '&' ||
699  *sIt == ':') {
700  fileName += '_';
701  }
702  else {
703  fileName += *sIt;
704  }
705  }
706  if (classes.size() > 1) {
707  Int_t chk = 0;
708  std::vector<std::string>::const_iterator it = classes.begin();
709  while ((++it) != classes.end()) {
710  for (UInt_t cursor = 0; cursor != it->length(); ++cursor) {
711  chk = chk * 3 + it->at(cursor);
712  }
713  }
714  fileName += TString::Format("_%u", chk);
715  }
716  fileName += ".cxx";
717  if (gSystem->AccessPathName(fileName) != 0) {
718  //file does not exist
719  //(1) prepare file data
720  // If STL, also request iterators' operators.
721  // vector is special: we need to check whether
722  // vector::iterator is a typedef to pointer or a
723  // class.
724  static const std::set<std::string> sSTLTypes {"vector","list","unordered_list","deque","map","multimap","set","unordered_set","multiset","queue","priority_queue","stack","iterator"};
725  std::vector<std::string>::const_iterator it;
726  std::string fileContent("");
727  for (it = headers.begin(); it != headers.end(); ++it) {
728  fileContent += "#include \"" + *it + "\"\n";
729  }
730  for (it = unknown.begin(); it != unknown.end(); ++it) {
731  TClass* cl = TClass::GetClass(it->c_str());
732  if (cl && cl->GetDeclFileName()) {
733  TString header(gSystem->BaseName(cl->GetDeclFileName()));
734  TString dir(gSystem->DirName(cl->GetDeclFileName()));
735  TString dirbase(gSystem->BaseName(dir));
736  while (dirbase.Length() && dirbase != "."
737  && dirbase != "include" && dirbase != "inc"
738  && dirbase != "prec_stl") {
739  gSystem->PrependPathName(dirbase, header);
740  dir = gSystem->DirName(dir);
741  }
742  fileContent += TString("#include \"") + header + "\"\n";
743  }
744  }
745  for (it = fwdDecls.begin(); it != fwdDecls.end(); ++it) {
746  fileContent += "class " + *it + ";\n";
747  }
748  fileContent += "#ifdef __CINT__ \n";
749  fileContent += "#pragma link C++ nestedclasses;\n";
750  fileContent += "#pragma link C++ nestedtypedefs;\n";
751  for (it = classes.begin(); it != classes.end(); ++it) {
752  std::string n(*it);
753  size_t posTemplate = n.find('<');
754  std::set<std::string>::const_iterator iSTLType = sSTLTypes.end();
755  if (posTemplate != std::string::npos) {
756  n.erase(posTemplate, std::string::npos);
757  if (n.compare(0, 5, "std::") == 0) {
758  n.erase(0, 5);
759  }
760  iSTLType = sSTLTypes.find(n);
761  }
762  fileContent += "#pragma link C++ class ";
763  fileContent += *it + "+;\n" ;
764  fileContent += "#pragma link C++ class ";
765  if (iSTLType != sSTLTypes.end()) {
766  // STL class; we cannot (and don't need to) store iterators;
767  // their shadow and the compiler's version don't agree. So
768  // don't ask for the '+'
769  fileContent += *it + "::*;\n" ;
770  }
771  else {
772  // Not an STL class; we need to allow the I/O of contained
773  // classes (now that we have a dictionary for them).
774  fileContent += *it + "::*+;\n" ;
775  }
776  std::string oprLink("#pragma link C++ operators ");
777  oprLink += *it;
778  // Don't! Requests e.g. op<(const vector<T>&, const vector<T>&):
779  // fileContent += oprLink + ";\n";
780  if (iSTLType != sSTLTypes.end()) {
781  if (n == "vector") {
782  fileContent += "#ifdef G__VECTOR_HAS_CLASS_ITERATOR\n";
783  }
784  fileContent += oprLink + "::iterator;\n";
785  fileContent += oprLink + "::const_iterator;\n";
786  fileContent += oprLink + "::reverse_iterator;\n";
787  if (n == "vector") {
788  fileContent += "#endif\n";
789  }
790  }
791  }
792  fileContent += "#endif\n";
793  //end(1)
794  //(2) prepare the file
795  FILE* filePointer;
796  filePointer = fopen(fileName, "w");
797  if (filePointer == NULL) {
798  //can't open a file
799  return 1;
800  }
801  //end(2)
802  //write data into the file
803  fprintf(filePointer, "%s", fileContent.c_str());
804  fclose(filePointer);
805  }
806  //(3) checking if we can compile a macro, if not then cleaning
807  Int_t oldErrorIgnoreLevel = gErrorIgnoreLevel;
808  gErrorIgnoreLevel = kWarning; // no "Info: creating library..."
809  Int_t ret = gSystem->CompileMacro(fileName, "k");
810  gErrorIgnoreLevel = oldErrorIgnoreLevel;
811  if (ret == 0) { //can't compile a macro
812  return 2;
813  }
814  //end(3)
815  return 0;
816 }
817 
818 int TCling_GenerateDictionary(const std::string& className,
819  const std::vector<std::string> &headers,
820  const std::vector<std::string> &fwdDecls,
821  const std::vector<std::string> &unknown)
822 {
823  //This function automatically creates the "LinkDef.h" file for templated
824  //classes then executes CompileMacro on it.
825  //The name of the file depends on the class name, and it's not generated again
826  //if the file exist.
827  std::vector<std::string> classes;
828  classes.push_back(className);
829  return TCling_GenerateDictionary(classes, headers, fwdDecls, unknown);
830 }
831 
832 //______________________________________________________________________________
833 //
834 //
835 //
836 
837 // It is a "fantom" method to synchronize user keyboard input
838 // and ROOT prompt line (for WIN32)
839 const char* fantomline = "TRint::EndOfLineAction();";
840 
841 //______________________________________________________________________________
842 //
843 //
844 //
845 
846 void* TCling::fgSetOfSpecials = 0;
847 
848 //______________________________________________________________________________
849 //
850 // llvm error handler through exceptions; see also cling/UserInterface
851 //
852 namespace {
853  // Handle fatal llvm errors by throwing an exception.
854  // Yes, throwing exceptions in error handlers is bad.
855  // Doing nothing is pretty terrible, too.
856  void exceptionErrorHandler(void * /*user_data*/,
857  const std::string& reason,
858  bool /*gen_crash_diag*/) {
859  throw std::runtime_error(std::string(">>> Interpreter compilation error:\n") + reason);
860  }
861 }
862 
863 //______________________________________________________________________________
864 //
865 //
866 //
867 
868 ////////////////////////////////////////////////////////////////////////////////
869 
870 namespace{
871  // An instance of this class causes the diagnostics of clang to be suppressed
872  // during its lifetime
873  class clangDiagSuppr {
874  public:
875  clangDiagSuppr(clang::DiagnosticsEngine& diag): fDiagEngine(diag){
876  fOldDiagValue = fDiagEngine.getIgnoreAllWarnings();
877  fDiagEngine.setIgnoreAllWarnings(true);
878  }
879 
880  ~clangDiagSuppr() {
881  fDiagEngine.setIgnoreAllWarnings(fOldDiagValue);
882  }
883  private:
884  clang::DiagnosticsEngine& fDiagEngine;
885  bool fOldDiagValue;
886  };
887 
888 }
889 
890 ////////////////////////////////////////////////////////////////////////////////
891 /// Allow calling autoparsing from TMetaUtils
892 bool TClingLookupHelper__AutoParse(const char *cname)
893 {
894  return gCling->AutoParse(cname);
895 }
896 
897 ////////////////////////////////////////////////////////////////////////////////
898 /// Try hard to avoid looking up in the Cling database as this could enduce
899 /// an unwanted autoparsing.
900 
901 bool TClingLookupHelper__ExistingTypeCheck(const std::string &tname,
902  std::string &result)
903 {
904  result.clear();
905 
906  unsigned long offset = 0;
907  if (strncmp(tname.c_str(), "const ", 6) == 0) {
908  offset = 6;
909  }
910  unsigned long end = tname.length();
911  while( end && (tname[end-1]=='&' || tname[end-1]=='*' || tname[end-1]==']') ) {
912  if ( tname[end-1]==']' ) {
913  --end;
914  while ( end && tname[end-1]!='[' ) --end;
915  }
916  --end;
917  }
918  std::string innerbuf;
919  const char *inner;
920  if (end != tname.length()) {
921  innerbuf = tname.substr(offset,end-offset);
922  inner = innerbuf.c_str();
923  } else {
924  inner = tname.c_str()+offset;
925  }
926 
927  //if (strchr(tname.c_str(),'[')!=0) fprintf(stderr,"DEBUG: checking on %s vs %s %lu %lu\n",tname.c_str(),inner,offset,end);
928  if (gROOT->GetListOfClasses()->FindObject(inner)
929  || TClassTable::Check(inner,result) ) {
930  // This is a known class.
931  return true;
932  }
933 
934  THashTable *typeTable = dynamic_cast<THashTable*>( gROOT->GetListOfTypes() );
935  TDataType *type = (TDataType *)typeTable->THashTable::FindObject( inner );
936  if (type) {
937  // This is a raw type and an already loaded typedef.
938  const char *newname = type->GetFullTypeName();
939  if (type->GetType() == kLong64_t) {
940  newname = "Long64_t";
941  } else if (type->GetType() == kULong64_t) {
942  newname = "ULong64_t";
943  }
944  if (strcmp(inner,newname) == 0) {
945  return true;
946  }
947  if (offset) result = "const ";
948  result += newname;
949  if ( end != tname.length() ) {
950  result += tname.substr(end,tname.length()-end);
951  }
952  if (result == tname) result.clear();
953  return true;
954  }
955 
956  // Check if the name is an enumerator
957  const auto lastPos = TClassEdit::GetUnqualifiedName(inner);
958  if (lastPos != inner) // Main switch: case 1 - scoped enum, case 2 global enum
959  {
960  // We have a scope
961  // All of this C gymnastic is to avoid allocations on the heap
962  const auto enName = lastPos;
963  const auto scopeNameSize = ((Long64_t)lastPos - (Long64_t)inner) / sizeof(decltype(*lastPos)) - 2;
964 #ifdef R__WIN32
965  char *scopeName = new char[scopeNameSize + 1];
966 #else
967  char scopeName[scopeNameSize + 1]; // on the stack, +1 for the terminating character '\0'
968 #endif
969  strncpy(scopeName, inner, scopeNameSize);
970  scopeName[scopeNameSize] = '\0';
971  // Check if the scope is in the list of classes
972  if (auto scope = static_cast<TClass *>(gROOT->GetListOfClasses()->FindObject(scopeName))) {
973  auto enumTable = dynamic_cast<const THashList *>(scope->GetListOfEnums(false));
974  if (enumTable && enumTable->THashList::FindObject(enName)) return true;
975  }
976  // It may still be in one of the loaded protoclasses
977  else if (auto scope = static_cast<TProtoClass *>(gClassTable->GetProtoNorm(scopeName))) {
978  auto listOfEnums = scope->GetListOfEnums();
979  if (listOfEnums) { // it could be null: no enumerators in the protoclass
980  auto enumTable = dynamic_cast<const THashList *>(listOfEnums);
981  if (enumTable && enumTable->THashList::FindObject(enName)) return true;
982  }
983  }
984 #ifdef R__WIN32
985  delete [] scopeName;
986 #endif
987  } else
988  {
989  // We don't have any scope: this could only be a global enum
990  auto enumTable = dynamic_cast<const THashList *>(gROOT->GetListOfEnums());
991  if (enumTable && enumTable->THashList::FindObject(inner)) return true;
992  }
993 
994  if (gCling->GetClassSharedLibs(inner))
995  {
996  // This is a class name.
997  return true;
998  }
999 
1000  return false;
1001 }
1002 
1003 ////////////////////////////////////////////////////////////////////////////////
1004 
1006 {
1007  fContent.reserve(size);
1008 }
1009 
1010 ////////////////////////////////////////////////////////////////////////////////
1011 
1012 inline const char *TCling::TUniqueString::Data()
1013 {
1014  return fContent.c_str();
1015 }
1016 
1017 ////////////////////////////////////////////////////////////////////////////////
1018 /// Append string to the storage if not added already.
1019 
1020 inline bool TCling::TUniqueString::Append(const std::string& str)
1021 {
1022  bool notPresent = fLinesHashSet.emplace(fHashFunc(str)).second;
1023  if (notPresent){
1024  fContent+=str;
1025  }
1026  return notPresent;
1027 }
1028 
1029 ////////////////////////////////////////////////////////////////////////////////
1030 /// Initialize the cling interpreter interface.
1031 
1032 TCling::TCling(const char *name, const char *title)
1033 : TInterpreter(name, title), fGlobalsListSerial(-1), fInterpreter(0),
1034  fMetaProcessor(0), fNormalizedCtxt(0), fPrevLoadedDynLibInfo(0),
1035  fClingCallbacks(0), fAutoLoadCallBack(0),
1036  fTransactionCount(0), fHeaderParsingOnDemand(true), fIsAutoParsingSuspended(kFALSE)
1037 {
1038  // rootcling also uses TCling for generating the dictionary ROOT files.
1039  bool fromRootCling = dlsym(RTLD_DEFAULT, "usedToIdentifyRootClingByDlSym");
1040 
1041  llvm::install_fatal_error_handler(&exceptionErrorHandler);
1042 
1043  fTemporaries = new std::vector<cling::Value>();
1044 
1045  std::vector<std::string> clingArgsStorage;
1046  clingArgsStorage.push_back("cling4root");
1047 
1048  std::string interpInclude;
1049  // rootcling sets its arguments through TROOT::GetExtraInterpreterArgs().
1050  if (!fromRootCling) {
1052 
1053  interpInclude = TROOT::GetEtcDir();
1054  clingArgsStorage.push_back("-I" + interpInclude);
1055 
1056  std::string pchFilename = interpInclude + "/allDict.cxx.pch";
1057  if (gSystem->Getenv("ROOT_PCH")) {
1058  pchFilename = gSystem->Getenv("ROOT_PCH");
1059  }
1060  clingArgsStorage.push_back("-include-pch");
1061  clingArgsStorage.push_back(pchFilename);
1062 
1063  // clingArgsStorage.push_back("-Xclang");
1064  // clingArgsStorage.push_back("-fmodules");
1065 
1066  std::string include;
1067  include = TROOT::GetIncludeDir();
1068  clingArgsStorage.push_back("-I" + include);
1069  clingArgsStorage.push_back("-Wno-undefined-inline");
1070  clingArgsStorage.push_back("-fsigned-char");
1071  }
1072 
1073  std::vector<const char*> interpArgs;
1074  for (std::vector<std::string>::const_iterator iArg = clingArgsStorage.begin(),
1075  eArg = clingArgsStorage.end(); iArg != eArg; ++iArg)
1076  interpArgs.push_back(iArg->c_str());
1077 
1078 #ifdef R__EXTERN_LLVMDIR
1079  TString llvmResourceDir = R__EXTERN_LLVMDIR;
1080 #else
1081  TString llvmResourceDir = TROOT::GetEtcDir() + "/cling";
1082 #endif
1083  // Add statically injected extra arguments, usually coming from rootcling.
1084  for (const char** extraArgs = TROOT::GetExtraInterpreterArgs();
1085  extraArgs && *extraArgs; ++extraArgs) {
1086  if (!strcmp(*extraArgs, "-resource-dir")) {
1087  // Take the next arg as the llvm resource directory.
1088  llvmResourceDir = *(++extraArgs);
1089  } else {
1090  interpArgs.push_back(*extraArgs);
1091  }
1092  }
1093 
1094  fInterpreter = new cling::Interpreter(interpArgs.size(),
1095  &(interpArgs[0]),
1096  llvmResourceDir);
1097 
1098  if (!fromRootCling) {
1099  fInterpreter->installLazyFunctionCreator(llvmLazyFunctionCreator);
1100 
1101  // Add include path to etc/cling. FIXME: This is a short term solution. The
1102  // llvm/clang header files shouldn't be there at all. We have to get rid of
1103  // that dependency and avoid copying the header files.
1104  // Use explicit TCling::AddIncludePath() to avoid vtable: we're in the c'tor!
1105  TCling::AddIncludePath((interpInclude + "/cling").c_str());
1106 
1107  // Add the current path to the include path
1108  // TCling::AddIncludePath(".");
1109 
1110  // Add the root include directory and etc/ to list searched by default.
1112  }
1113 
1114  // Don't check whether modules' files exist.
1115  fInterpreter->getCI()->getPreprocessorOpts().DisablePCHValidation = true;
1116 
1117  // Until we can disable autoloading during Sema::CorrectTypo() we have
1118  // to disable spell checking.
1119  fInterpreter->getCI()->getLangOpts().SpellChecking = false;
1120 
1121 
1122  // We need stream that doesn't close its file descriptor, thus we are not
1123  // using llvm::outs. Keeping file descriptor open we will be able to use
1124  // the results in pipes (Savannah #99234).
1125  static llvm::raw_fd_ostream fMPOuts (STDOUT_FILENO, /*ShouldClose*/false);
1126  fMetaProcessor = new cling::MetaProcessor(*fInterpreter, fMPOuts);
1127 
1128  // For the list to also include string, we have to include it now.
1129  // rootcling does parts already if needed, e.g. genreflex does not want using
1130  // namespace std.
1131  if (fromRootCling) {
1132  fInterpreter->declare("#include \"RtypesCore.h\"\n"
1133  "#include <string>\n"
1134  "using std::string;");
1135  } else {
1136  fInterpreter->declare("#include \"Rtypes.h\"\n"
1137  + gClassDefInterpMacro + "\n"
1138  + gInterpreterClassDef + "\n"
1139  + "#undef ClassImp\n"
1140  "#define ClassImp(X)\n"
1141  "#include <string>\n"
1142  "using namespace std;");
1143  }
1144 
1145  // We are now ready (enough is loaded) to init the list of opaque typedefs.
1148  TClassEdit::Init(fLookupHelper);
1149 
1150  // Initialize the cling interpreter interface.
1151  fMore = 0;
1152  fPrompt[0] = 0;
1153  fMapfile = 0;
1154 // fMapNamespaces = 0;
1155  fRootmapFiles = 0;
1157 
1158  fAllowLibLoad = !fromRootCling;
1159  // Disallow auto-parsing in rootcling
1160  fIsAutoParsingSuspended = fromRootCling;
1161  // Disable the autoloader until it is explicitly enabled.
1162  SetClassAutoloading(false);
1163 
1164  ResetAll();
1165 #ifndef R__WIN32
1166  //optind = 1; // make sure getopt() works in the main program
1167 #endif // R__WIN32
1168 
1169  // Attach cling callbacks
1170  std::unique_ptr<TClingCallbacks>
1171  clingCallbacks(new TClingCallbacks(fInterpreter));
1172  fClingCallbacks = clingCallbacks.get();
1174  fInterpreter->setCallbacks(std::move(clingCallbacks));
1175 
1176  if (!fromRootCling) {
1177  fInterpreter->enableDynamicLookup();
1178  }
1179 }
1180 
1181 
1182 ////////////////////////////////////////////////////////////////////////////////
1183 /// Destroy the interpreter interface.
1184 
1186 {
1187  delete fMapfile;
1188 // delete fMapNamespaces;
1189  delete fRootmapFiles;
1190  delete fMetaProcessor;
1191  delete fTemporaries;
1192  delete fNormalizedCtxt;
1193  delete fInterpreter;
1194  delete fLookupHelper;
1195  gCling = 0;
1196 #if defined(R__MUST_REVISIT)
1197 #if R__MUST_REVISIT(6,2)
1198  Warning("~TCling", "Interface not available yet.");
1199 #ifdef R__COMPLETE_MEM_TERMINATION
1200  // remove all cling objects
1201 #endif
1202 #endif
1203 #endif
1204  //--
1205 }
1206 
1207 ////////////////////////////////////////////////////////////////////////////////
1208 /// Initialize the interpreter, once TROOT::fInterpreter is set.
1209 
1211 {
1213 }
1214 
1215 ////////////////////////////////////////////////////////////////////////////////
1216 /// Wrapper around dladdr (and friends)
1217 
1218 static const char *FindLibraryName(void (*func)())
1219 {
1220 #if defined(__CYGWIN__) && defined(__GNUC__)
1221  return 0;
1222 #elif defined(G__WIN32)
1223  MEMORY_BASIC_INFORMATION mbi;
1224  if (!VirtualQuery (func, &mbi, sizeof (mbi)))
1225  {
1226  return 0;
1227  }
1228 
1229  HMODULE hMod = (HMODULE) mbi.AllocationBase;
1230  TTHREAD_TLS_ARRAY(char, MAX_PATH, moduleName);
1231 
1232  if (!GetModuleFileNameA (hMod, moduleName, sizeof (moduleName)))
1233  {
1234  return 0;
1235  }
1236  return moduleName;
1237 #else
1238  Dl_info info;
1239  if (dladdr((void*)func,&info)==0) {
1240  // Not in a known share library, let's give up
1241  return 0;
1242  } else {
1243  //fprintf(stdout,"Found address in %s\n",info.dli_fname);
1244  return info.dli_fname;
1245  }
1246 #endif
1247 
1248 }
1249 
1250 ////////////////////////////////////////////////////////////////////////////////
1251 /// Helper to initialize TVirtualStreamerInfo's factor early.
1252 /// Use static initialization to insure only one TStreamerInfo is created.
1254 {
1255  // Use lambda since SetFactory return void.
1256  auto setFactory = []() {
1258  return kTRUE;
1259  };
1260  static bool doneFactory = setFactory();
1261  return doneFactory; // avoid unused variable warning.
1262 }
1263 
1264 
1265 ////////////////////////////////////////////////////////////////////////////////
1266 /// Tries to load a PCM; returns true on success.
1267 
1268 bool TCling::LoadPCM(TString pcmFileName,
1269  const char** headers,
1270  void (*triggerFunc)()) const {
1271  // pcmFileName is an intentional copy; updated by FindFile() below.
1272 
1273  TString searchPath;
1274 
1275  if (triggerFunc) {
1276  const char *libraryName = FindLibraryName(triggerFunc);
1277  if (libraryName) {
1278  searchPath = llvm::sys::path::parent_path(libraryName);
1279 #ifdef R__WIN32
1280  searchPath += ";";
1281 #else
1282  searchPath += ":";
1283 #endif
1284  }
1285  }
1286  // Note: if we know where the library is, we probably shouldn't even
1287  // look in other places.
1288  searchPath.Append( gSystem->GetDynamicPath() );
1289 
1290  if (!gSystem->FindFile(searchPath, pcmFileName))
1291  return kFALSE;
1292 
1293  // Prevent the ROOT-PCMs hitting this during auto-load during
1294  // JITting - which will cause recursive compilation.
1295  // Avoid to call the plugin manager at all.
1297 
1298  if (gROOT->IsRootFile(pcmFileName)) {
1299  Int_t oldDebug = gDebug;
1300  if (gDebug > 5) {
1301  gDebug -= 5;
1302  ::Info("TCling::LoadPCM", "Loading ROOT PCM %s", pcmFileName.Data());
1303  } else {
1304  gDebug = 0;
1305  }
1306 
1307  TDirectory::TContext ctxt;
1308 
1309  TFile *pcmFile = new TFile(pcmFileName+"?filetype=pcm","READ");
1310 
1311  auto listOfKeys = pcmFile->GetListOfKeys();
1312 
1313  // This is an empty pcm
1314  if (
1315  listOfKeys &&
1316  (
1317  (listOfKeys->GetSize() == 0) || // Nothing here, or
1318  (
1319  (listOfKeys->GetSize() == 1) && // only one, and
1320  !strcmp(((TKey*)listOfKeys->At(0))->GetName(), "EMPTY") // name is EMPTY
1321  )
1322  )
1323  ) {
1324  delete pcmFile;
1325  gDebug = oldDebug;
1326  return kTRUE;
1327  }
1328 
1329  TObjArray *protoClasses;
1330  if (gDebug > 1)
1331  ::Info("TCling::LoadPCM","reading protoclasses for %s \n",pcmFileName.Data());
1332 
1333  pcmFile->GetObject("__ProtoClasses", protoClasses);
1334 
1335  if (protoClasses) {
1336  for (auto obj : *protoClasses) {
1337  TProtoClass * proto = (TProtoClass*)obj;
1338  TClassTable::Add(proto);
1339  }
1340  // Now that all TClass-es know how to set them up we can update
1341  // existing TClasses, which might cause the creation of e.g. TBaseClass
1342  // objects which in turn requires the creation of TClasses, that could
1343  // come from the PCH, but maybe later in the loop. Instead of resolving
1344  // a dependency graph the addition to the TClassTable above allows us
1345  // to create these dependent TClasses as needed below.
1346  for (auto proto : *protoClasses) {
1347  if (TClass* existingCl
1348  = (TClass*)gROOT->GetListOfClasses()->FindObject(proto->GetName())) {
1349  // We have an existing TClass object. It might be emulated
1350  // or interpreted; we now have more information available.
1351  // Make that available.
1352  if (existingCl->GetState() != TClass::kHasTClassInit) {
1353  DictFuncPtr_t dict = gClassTable->GetDict(proto->GetName());
1354  if (!dict) {
1355  ::Error("TCling::LoadPCM", "Inconsistent TClassTable for %s",
1356  proto->GetName());
1357  } else {
1358  // This will replace the existing TClass.
1359  TClass *ncl = (*dict)();
1360  if (ncl) ncl->PostLoadCheck();
1361 
1362  }
1363  }
1364  }
1365  }
1366 
1367  protoClasses->Clear(); // Ownership was transfered to TClassTable.
1368  delete protoClasses;
1369  }
1370 
1371  TObjArray *dataTypes;
1372  pcmFile->GetObject("__Typedefs", dataTypes);
1373  if (dataTypes) {
1374  for (auto typedf: *dataTypes)
1375  gROOT->GetListOfTypes()->Add(typedf);
1376  dataTypes->Clear(); // Ownership was transfered to TListOfTypes.
1377  delete dataTypes;
1378  }
1379 
1380  TObjArray *enums;
1381  pcmFile->GetObject("__Enums", enums);
1382  if (enums) {
1383  // Cache the pointers
1384  auto listOfGlobals = gROOT->GetListOfGlobals();
1385  auto listOfEnums = dynamic_cast<THashList*>(gROOT->GetListOfEnums());
1386  // Loop on enums and then on enum constants
1387  for (auto selEnum: *enums){
1388  const char* enumScope = selEnum->GetTitle();
1389  const char* enumName = selEnum->GetName();
1390  if (strcmp(enumScope,"") == 0){
1391  // This is a global enum and is added to the
1392  // list of enums and its constants to the list of globals
1393  if (!listOfEnums->THashList::FindObject(enumName)){
1394  ((TEnum*) selEnum)->SetClass(nullptr);
1395  listOfEnums->Add(selEnum);
1396  }
1397  for (auto enumConstant: *static_cast<TEnum*>(selEnum)->GetConstants()){
1398  if (!listOfGlobals->FindObject(enumConstant)){
1399  listOfGlobals->Add(enumConstant);
1400  }
1401  }
1402  }
1403  else {
1404  // This enum is in a namespace. A TClass entry is bootstrapped if
1405  // none exists yet and the enum is added to it
1406  TClass* nsTClassEntry = TClass::GetClass(enumScope);
1407  if (!nsTClassEntry){
1408  nsTClassEntry = new TClass(enumScope,0,TClass::kNamespaceForMeta, true);
1409  }
1410  auto listOfEnums = nsTClassEntry->fEnums.load();
1411  if (!listOfEnums) {
1412  if ( (kIsClass | kIsStruct | kIsUnion) & nsTClassEntry->Property() ) {
1413  // For this case, the list will be immutable once constructed
1414  // (i.e. in this case, by the end of this routine).
1415  listOfEnums = nsTClassEntry->fEnums = new TListOfEnums(nsTClassEntry);
1416  } else {
1417  //namespaces can have enums added to them
1418  listOfEnums = nsTClassEntry->fEnums = new TListOfEnumsWithLock(nsTClassEntry);
1419  }
1420  }
1421  if (listOfEnums && !listOfEnums->THashList::FindObject(enumName)){
1422  ((TEnum*) selEnum)->SetClass(nsTClassEntry);
1423  listOfEnums->Add(selEnum);
1424  }
1425  }
1426  }
1427  enums->Clear();
1428  delete enums;
1429  }
1430 
1431  delete pcmFile;
1432 
1433  gDebug = oldDebug;
1434  } else {
1435  if (gDebug > 5)
1436  ::Info("TCling::LoadPCM", "Loading clang PCM %s", pcmFileName.Data());
1437 
1438  }
1439  // Note: Declaring the relationship between the module (pcm) and the header
1440  // probably does not yet make sense since the pcm is 'only' a root file.
1441  // We also have to review if we still need to do this with the delay loading.
1442  // clang::CompilerInstance* CI = fInterpreter->getCI();
1443  // ROOT::TMetaUtils::declareModuleMap(CI, pcmFileName, headers);
1444  return kTRUE;
1445 }
1446 
1447 //______________________________________________________________________________
1448 
1449 namespace {
1450  using namespace clang;
1451 
1452  class ExtLexicalStorageAdder: public RecursiveASTVisitor<ExtLexicalStorageAdder>{
1453  // This class is to be considered an helper for autoparsing.
1454  // It visits the AST and marks all classes (in all of their redeclarations)
1455  // with the setHasExternalLexicalStorage method.
1456  public:
1457  bool VisitRecordDecl(clang::RecordDecl* rcd){
1458  if (gDebug > 2)
1459  Info("ExtLexicalStorageAdder",
1460  "Adding external lexical storage to class %s",
1461  rcd->getNameAsString().c_str());
1462  auto reDeclPtr = rcd->getMostRecentDecl();
1463  do {
1464  reDeclPtr->setHasExternalLexicalStorage();
1465  } while ((reDeclPtr = reDeclPtr->getPreviousDecl()));
1466 
1467  return false;
1468  }
1469  };
1470 
1471 
1472 }
1473 
1474 ////////////////////////////////////////////////////////////////////////////////
1475 /// Inject the module named "modulename" into cling; load all headers.
1476 /// headers is a 0-terminated array of header files to #include after
1477 /// loading the module. The module is searched for in all $LD_LIBRARY_PATH
1478 /// entries (or %PATH% on Windows).
1479 /// This function gets called by the static initialization of dictionary
1480 /// libraries.
1481 /// The payload code is injected "as is" in the interpreter.
1482 /// The value of 'triggerFunc' is used to find the shared library location.
1483 
1484 void TCling::RegisterModule(const char* modulename,
1485  const char** headers,
1486  const char** includePaths,
1487  const char* payloadCode,
1488  const char* fwdDeclsCode,
1489  void (*triggerFunc)(),
1490  const FwdDeclArgsToKeepCollection_t& fwdDeclsArgToSkip,
1491  const char** classesHeaders)
1492 {
1493  // rootcling also uses TCling for generating the dictionary ROOT files.
1494  static const bool fromRootCling = dlsym(RTLD_DEFAULT, "usedToIdentifyRootClingByDlSym");
1495  // We need the dictionary initialization but we don't want to inject the
1496  // declarations into the interpreter, except for those we really need for
1497  // I/O; see rootcling.cxx after the call to TCling__GetInterpreter().
1498  if (fromRootCling) return;
1499 
1500  // Treat Aclic Libs in a special way. Do not delay the parsing.
1501  bool hasHeaderParsingOnDemand = fHeaderParsingOnDemand;
1502  bool isACLiC = false;
1503  if (hasHeaderParsingOnDemand &&
1504  strstr(modulename, "_ACLiC_dict") != nullptr){
1505  if (gDebug>1)
1506  Info("TCling::RegisterModule",
1507  "Header parsing on demand is active but this is an Aclic library. Disabling it for this library.");
1508  hasHeaderParsingOnDemand = false;
1509  isACLiC = true;
1510  }
1511 
1512 
1513  // Make sure we relookup symbols that were search for before we loaded
1514  // their autoparse information. We could be more subtil and remove only
1515  // the failed one or only the one in this module, but for now this is
1516  // better than nothing.
1517  fLookedUpClasses.clear();
1518 
1519  // Make sure we do not set off autoloading or autoparsing during the
1520  // module registration!
1521  Int_t oldAutoloadValue = SetClassAutoloading(false);
1522 
1523  TString pcmFileName(ROOT::TMetaUtils::GetModuleFileName(modulename).c_str());
1524 
1525  for (const char** inclPath = includePaths; *inclPath; ++inclPath) {
1526  TCling::AddIncludePath(*inclPath);
1527  }
1528  cling::Transaction* T = 0;
1529  // Put the template decls and the number of arguments to skip in the TNormalizedCtxt
1530  for (auto& fwdDeclArgToSkipPair : fwdDeclsArgToSkip){
1531  const std::string& fwdDecl = fwdDeclArgToSkipPair.first;
1532  const int nArgsToSkip = fwdDeclArgToSkipPair.second;
1533  auto compRes = fInterpreter->declare(fwdDecl.c_str(), &T);
1534  assert(cling::Interpreter::kSuccess == compRes &&
1535  "A fwd declaration could not be compiled");
1536  if (compRes!=cling::Interpreter::kSuccess){
1537  Warning("TCling::RegisterModule",
1538  "Problems in declaring string '%s' were encountered.",
1539  fwdDecl.c_str()) ;
1540  continue;
1541  }
1542 
1543  // Drill through namespaces recursively until the template is found
1544  if(ClassTemplateDecl* TD = FindTemplateInNamespace(T->getFirstDecl().getSingleDecl())){
1545  fNormalizedCtxt->AddTemplAndNargsToKeep(TD->getCanonicalDecl(), nArgsToSkip);
1546  }
1547 
1548  }
1549 
1550  // FIXME: Remove #define __ROOTCLING__ once PCMs are there.
1551  // This is used to give Sema the same view on ACLiC'ed files (which
1552  // are then #included through the dictionary) as rootcling had.
1553  TString code = gNonInterpreterClassDef;
1554  code += payloadCode;
1555 
1556  // We need to open the dictionary shared library, to resolve symbols
1557  // requested by the JIT from it: as the library is currently being dlopen'ed,
1558  // its symbols are not yet reachable from the process.
1559  // Recursive dlopen seems to work just fine.
1560  const char* dyLibName = FindLibraryName(triggerFunc);
1561  if (dyLibName) {
1562  // We were able to determine the library name.
1563  void* dyLibHandle = dlopen(dyLibName, RTLD_LAZY | RTLD_GLOBAL);
1564  if (!dyLibHandle) {
1565 #ifdef R__WIN32
1566  char dyLibError[1000];
1567  FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(),
1568  MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), dyLibError,
1569  sizeof(dyLibError), NULL);
1570  {
1571 #else
1572  const char* dyLibError = dlerror();
1573  if (dyLibError) {
1574 #endif
1575  if (gDebug > 0) {
1576  ::Info("TCling::RegisterModule",
1577  "Cannot open shared library %s for dictionary %s:\n %s",
1578  dyLibName, modulename, dyLibError);
1579  }
1580  }
1581  dyLibName = 0;
1582  } else {
1583  fRegisterModuleDyLibs.push_back(dyLibHandle);
1584  }
1585  }
1586 
1587  if (hasHeaderParsingOnDemand && fwdDeclsCode){
1588  // We now parse the forward declarations. All the classes are then modified
1589  // in order for them to have an external lexical storage.
1590  std::string fwdDeclsCodeLessEnums;
1591  {
1592  // Search for enum forward decls and only declare them if no
1593  // declaration exists yet.
1594  std::string fwdDeclsLine;
1595  std::istringstream fwdDeclsCodeStr(fwdDeclsCode);
1596  std::vector<std::string> scope;
1597  while (std::getline(fwdDeclsCodeStr, fwdDeclsLine)) {
1598  if (fwdDeclsLine.find("namespace ") == 0
1599  || fwdDeclsLine.find("inline namespace ") == 0) {
1600  // skip leading "namespace ", trailing " {"
1601  scope.push_back(fwdDeclsLine.substr(10,
1602  fwdDeclsLine.length() - 10 - 2));
1603  } else if (fwdDeclsLine == "}") {
1604  scope.pop_back();
1605  } else if (fwdDeclsLine.find("enum __attribute__((annotate(\"") == 0) {
1606  clang::DeclContext* DC = 0;
1607  for (auto &&aScope: scope) {
1608  DC = cling::utils::Lookup::Namespace(&fInterpreter->getSema(), aScope.c_str(), DC);
1609  if (!DC) {
1610  // No decl context means we have to fwd declare the enum.
1611  break;
1612  }
1613  }
1614  if (scope.empty() || DC) {
1615  // We know the scope; let's look for the enum.
1616  size_t posEnumName = fwdDeclsLine.find("\"))) ", 32);
1617  R__ASSERT(posEnumName != std::string::npos && "Inconsistent enum fwd decl!");
1618  posEnumName += 5; // skip "\"))) "
1619  while (isspace(fwdDeclsLine[posEnumName]))
1620  ++posEnumName;
1621  size_t posEnumNameEnd = fwdDeclsLine.find(" : ", posEnumName);
1622  R__ASSERT(posEnumNameEnd != std::string::npos && "Inconsistent enum fwd decl (end)!");
1623  while (isspace(fwdDeclsLine[posEnumNameEnd]))
1624  --posEnumNameEnd;
1625  // posEnumNameEnd now points to the last character of the name.
1626 
1627  std::string enumName = fwdDeclsLine.substr(posEnumName,
1628  posEnumNameEnd - posEnumName + 1);
1629 
1630  if (clang::NamedDecl* enumDecl
1631  = cling::utils::Lookup::Named(&fInterpreter->getSema(),
1632  enumName.c_str(), DC)) {
1633  // We have an existing enum decl (forward or definition);
1634  // skip this.
1635  R__ASSERT(llvm::dyn_cast<clang::EnumDecl>(enumDecl) && "not an enum decl!");
1636  (void)enumDecl;
1637  continue;
1638  }
1639  }
1640  }
1641  fwdDeclsCodeLessEnums += fwdDeclsLine + "\n";
1642  }
1643  }
1644 
1645  if (fwdDeclsCodeLessEnums.size() != 0){ // Avoid the overhead if nothing is to be declared
1646  auto compRes = fInterpreter->declare(fwdDeclsCodeLessEnums, &T);
1647  assert(cling::Interpreter::kSuccess == compRes &&
1648  "The forward declarations could not be compiled");
1649  if (compRes!=cling::Interpreter::kSuccess){
1650  Warning("TCling::RegisterModule",
1651  "Problems in compiling forward declarations for module %s: '%s'",
1652  modulename, fwdDeclsCodeLessEnums.c_str()) ;
1653  }
1654  else if (T){
1655  // Loop over all decls in the transaction and go through them all
1656  // to mark them properly.
1657  // In order to do that, we first iterate over all the DelayedCallInfos
1658  // within the transaction. Then we loop over all Decls in the DeclGroupRef
1659  // contained in the DelayedCallInfos. For each decl, we traverse.
1660  ExtLexicalStorageAdder elsa;
1661  for (auto dciIt = T->decls_begin();dciIt!=T->decls_end();dciIt++){
1662  cling::Transaction::DelayCallInfo& dci = *dciIt;
1663  for(auto dit = dci.m_DGR.begin(); dit != dci.m_DGR.end(); ++dit) {
1664  clang::Decl* declPtr = *dit;
1665  elsa.TraverseDecl(declPtr);
1666  }
1667  }
1668  }
1669  }
1670 
1671  // Now we register all the headers necessary for the class
1672  // Typical format of the array:
1673  // {"A", "classes.h", "@",
1674  // "vector<A>", "vector", "@",
1675  // "myClass", payloadCode, "@",
1676  // nullptr};
1677 
1678  std::string temp;
1679  for (const char** classesHeader = classesHeaders; *classesHeader; ++classesHeader) {
1680  temp=*classesHeader;
1681 
1682  size_t theTemplateHash = 0;
1683  bool addTemplate = false;
1684  size_t posTemplate = temp.find('<');
1685  if (posTemplate != std::string::npos) {
1686  // Add an entry for the template itself.
1687  std::string templateName = temp.substr(0, posTemplate);
1688  theTemplateHash = fStringHashFunction(templateName);
1689  addTemplate = true;
1690  }
1691  size_t theHash = fStringHashFunction(temp);
1692  classesHeader++;
1693  for (const char** classesHeader_inner = classesHeader; 0!=strcmp(*classesHeader_inner,"@"); ++classesHeader_inner,++classesHeader){
1694  // This is done in order to distinguish headers from files and from the payloadCode
1695  if (payloadCode == *classesHeader_inner ){
1696  fPayloads.insert(theHash);
1697  if (addTemplate) fPayloads.insert(theTemplateHash);
1698  }
1699  if (gDebug > 2)
1700  Info("TCling::RegisterModule",
1701  "Adding a header for %s", temp.c_str());
1702  fClassesHeadersMap[theHash].push_back(*classesHeader_inner);
1703  if (addTemplate) {
1704  if (fClassesHeadersMap.find(theTemplateHash) == fClassesHeadersMap.end()) {
1705  fClassesHeadersMap[theTemplateHash].push_back(*classesHeader_inner);
1706  }
1707  addTemplate = false;
1708  }
1709  }
1710  }
1711  }
1712 
1713 
1714  if (strcmp(modulename,"libCore")!=0 && strcmp(modulename,"libRint")!=0
1715  && strcmp(modulename,"libThread")!=0 && strcmp(modulename,"libRIO")!=0
1716  && strcmp(modulename,"libcomplexDict")!=0 && strcmp(modulename,"libdequeDict")!=0
1717  && strcmp(modulename,"liblistDict")!=0 && strcmp(modulename,"libforward_listDict")!=0
1718  && strcmp(modulename,"libvectorDict")!=0
1719  && strcmp(modulename,"libmapDict")!=0 && strcmp(modulename,"libmultimap2Dict")!=0
1720  && strcmp(modulename,"libmap2Dict")!=0 && strcmp(modulename,"libmultimapDict")!=0
1721  && strcmp(modulename,"libsetDict")!=0 && strcmp(modulename,"libmultisetDict")!=0
1722  && strcmp(modulename,"libunordered_setDict")!=0 && strcmp(modulename,"libunordered_multisetDict")!=0
1723  && strcmp(modulename,"libunordered_mapDict")!=0 && strcmp(modulename,"libunordered_multimapDict")!=0
1724  && strcmp(modulename,"libvalarrayDict")!=0
1725  && strcmp(modulename,"G__GenVector32")!=0 && strcmp(modulename,"G__Smatrix32")!=0
1726 
1727  ) {
1728  // No pcm for now for libCore or libRint, the info is in the pch.
1729  if (!LoadPCM(pcmFileName, headers, triggerFunc)) {
1730  ::Error("TCling::RegisterModule", "cannot find dictionary module %s",
1731  ROOT::TMetaUtils::GetModuleFileName(modulename).c_str());
1732  }
1733  }
1734 
1735  bool oldValue = false;
1736  if (fClingCallbacks)
1737  oldValue = SetClassAutoloading(false);
1738 
1739  { // scope within which diagnostics are de-activated
1740  // For now we disable diagnostics because we saw them already at
1741  // dictionary generation time. That won't be an issue with the PCMs.
1742 
1743  clangDiagSuppr diagSuppr(fInterpreter->getSema().getDiagnostics());
1744 
1745 #if defined(R__MUST_REVISIT)
1746 #if R__MUST_REVISIT(6,2)
1747  Warning("TCling::RegisterModule","Diagnostics suppression should be gone by now.");
1748 #endif
1749 #endif
1750 
1751  if (!hasHeaderParsingOnDemand){
1752  const cling::Transaction* watermark = fInterpreter->getLastTransaction();
1753  cling::Interpreter::CompilationResult compRes = fInterpreter->parseForModule(code.Data());
1754  if (isACLiC) {
1755  // Register an unload point.
1756  fMetaProcessor->registerUnloadPoint(watermark, headers[0]);
1757  }
1758 
1759  assert(cling::Interpreter::kSuccess == compRes &&
1760  "Payload code of a dictionary could not be parsed correctly.");
1761  if (compRes!=cling::Interpreter::kSuccess) {
1762  Warning("TCling::RegisterModule",
1763  "Problems declaring payload for module %s.", modulename) ;
1764  }
1765  }
1766  }
1767 
1768  // Now that all the header have been registered/compiled, let's
1769  // make sure to 'reset' the TClass that have a class init in this module
1770  // but already had their type information available (using information/header
1771  // loaded from other modules or from class rules).
1772  if (!hasHeaderParsingOnDemand) {
1773  // This code is likely to be superseded by the similar code in LoadPCM,
1774  // and have been disabled, (inadvertently or awkwardly) by
1775  // commit 7903f09f3beea69e82ffba29f59fb2d656a4fd54 (Refactor the routines used for header parsing on demand)
1776  // whereas it seems that a more semantically correct conditional would have
1777  // been 'if this module does not have a rootpcm'.
1778  // Note: this need to be review when the clang pcm are being installed.
1779  // #if defined(R__MUST_REVISIT)
1780  while (!fClassesToUpdate.empty()) {
1781  TClass *oldcl = fClassesToUpdate.back().first;
1782  if (oldcl->GetState() != TClass::kHasTClassInit) {
1783  // if (gDebug > 2) Info("RegisterModule", "Forcing TClass init for %s", oldcl->GetName());
1784  DictFuncPtr_t dict = fClassesToUpdate.back().second;
1785  fClassesToUpdate.pop_back();
1786  // Calling func could manipulate the list so, let maintain the list
1787  // then call the dictionary function.
1788  TClass *ncl = dict();
1789  if (ncl) ncl->PostLoadCheck();
1790  } else {
1791  fClassesToUpdate.pop_back();
1792  }
1793  }
1794  }
1795 
1796  if (fClingCallbacks)
1797  SetClassAutoloading(oldValue);
1798 
1799  if (!hasHeaderParsingOnDemand) {
1800  // __ROOTCLING__ might be pulled in through PCH
1801  fInterpreter->declare("#ifdef __ROOTCLING__\n"
1802  "#undef __ROOTCLING__\n"
1803  + gInterpreterClassDef +
1804  "#endif");
1805  }
1806 
1807  if (dyLibName) {
1808  void* dyLibHandle = fRegisterModuleDyLibs.back();
1809  fRegisterModuleDyLibs.pop_back();
1810  dlclose(dyLibHandle);
1811  }
1812 
1813  SetClassAutoloading(oldAutoloadValue);
1814 }
1815 
1816 ////////////////////////////////////////////////////////////////////////////////
1817 /// Register classes that already existed prior to their dictionary loading
1818 /// and that already had a ClassInfo (and thus would not be refresh via
1819 /// UpdateClassInfo.
1820 
1822 {
1823  fClassesToUpdate.push_back(std::make_pair(oldcl,dict));
1824 }
1825 
1826 ////////////////////////////////////////////////////////////////////////////////
1827 /// If the dictionary is loaded, we can remove the class from the list
1828 /// (otherwise the class might be loaded twice).
1829 
1831 {
1832  typedef std::vector<std::pair<TClass*,DictFuncPtr_t> >::iterator iterator;
1833  iterator stop = fClassesToUpdate.end();
1834  for(iterator i = fClassesToUpdate.begin();
1835  i != stop;
1836  ++i)
1837  {
1838  if ( i->first == oldcl ) {
1839  fClassesToUpdate.erase(i);
1840  return;
1841  }
1842  }
1843 }
1844 
1845 ////////////////////////////////////////////////////////////////////////////////
1846 /// Let cling process a command line.
1847 ///
1848 /// If the command is executed and the error is 0, then the return value
1849 /// is the int value corresponding to the result of the executed command
1850 /// (float and double return values will be truncated).
1851 ///
1852 
1853 Long_t TCling::ProcessLine(const char* line, EErrorCode* error/*=0*/)
1854 {
1855  // Copy the passed line, it comes from a static buffer in TApplication
1856  // which can be reentered through the Cling evaluation routines,
1857  // which would overwrite the static buffer and we would forget what we
1858  // were doing.
1859  //
1860  TString sLine(line);
1861  if (strstr(line,fantomline)) {
1862  // End-Of-Line action
1863  // See the comment (copied from above):
1864  // It is a "fantom" method to synchronize user keyboard input
1865  // and ROOT prompt line (for WIN32)
1866  // and is implemented by
1867  if (gApplication) {
1868  if (gApplication->IsCmdThread()) {
1870  gGlobalMutex->Lock();
1871  if (!gInterpreterMutex)
1873  gGlobalMutex->UnLock();
1874  }
1876  gROOT->SetLineIsProcessing();
1877 
1879 
1880  gROOT->SetLineHasBeenProcessed();
1881  }
1882  }
1883  return 0;
1884  }
1885 
1887  gGlobalMutex->Lock();
1888  if (!gInterpreterMutex)
1890  gGlobalMutex->UnLock();
1891  }
1893  gROOT->SetLineIsProcessing();
1894 
1895  struct InterpreterFlagsRAII_t {
1896  cling::Interpreter* fInterpreter;
1897  bool fWasDynamicLookupEnabled;
1898 
1899  InterpreterFlagsRAII_t(cling::Interpreter* interp):
1900  fInterpreter(interp),
1901  fWasDynamicLookupEnabled(interp->isDynamicLookupEnabled())
1902  {
1903  fInterpreter->enableDynamicLookup(true);
1904  }
1905  ~InterpreterFlagsRAII_t() {
1906  fInterpreter->enableDynamicLookup(fWasDynamicLookupEnabled);
1907  }
1908  } interpreterFlagsRAII(fInterpreter);
1909 
1910  // A non-zero returned value means the given line was
1911  // not a complete statement.
1912  int indent = 0;
1913  // This will hold the resulting value of the evaluation the given line.
1915  cling::Interpreter::CompilationResult compRes = cling::Interpreter::kSuccess;
1916  if (!strncmp(sLine.Data(), ".L", 2) || !strncmp(sLine.Data(), ".x", 2) ||
1917  !strncmp(sLine.Data(), ".X", 2)) {
1918  // If there was a trailing "+", then CINT compiled the code above,
1919  // and we will need to strip the "+" before passing the line to cling.
1920  TString mod_line(sLine);
1921  TString aclicMode;
1922  TString arguments;
1923  TString io;
1924  TString fname = gSystem->SplitAclicMode(sLine.Data() + 3,
1925  aclicMode, arguments, io);
1926  if (aclicMode.Length()) {
1927  // Remove the leading '+'
1928  R__ASSERT(aclicMode[0]=='+' && "ACLiC mode must start with a +");
1929  aclicMode[0]='k'; // We always want to keep the .so around.
1930  if (aclicMode[1]=='+') {
1931  // We have a 2nd +
1932  aclicMode[1]='f'; // We want to force the recompilation.
1933  }
1934  if (!gSystem->CompileMacro(fname,aclicMode)) {
1935  // ACLiC failed.
1936  compRes = cling::Interpreter::kFailure;
1937  } else {
1938  if (strncmp(sLine.Data(), ".L", 2) != 0) {
1939  // if execution was requested.
1940 
1941  if (arguments.Length()==0) {
1942  arguments = "()";
1943  }
1944  // We need to remove the extension.
1945  Ssiz_t ext = fname.Last('.');
1946  if (ext != kNPOS) {
1947  fname.Remove(ext);
1948  }
1949  const char *function = gSystem->BaseName(fname);
1950  mod_line = function + arguments + io;
1951  cling::MetaProcessor::MaybeRedirectOutputRAII RAII(fMetaProcessor);
1952  indent = fMetaProcessor->process(mod_line, compRes, &result);
1953  }
1954  }
1955  } else {
1956  // not ACLiC
1957  bool unnamedMacro = false;
1958  {
1959  std::string line;
1960  std::ifstream in(fname);
1961  static const char whitespace[] = " \t\r\n";
1962  while (in) {
1963  std::getline(in, line);
1964  std::string::size_type posNonWS = line.find_first_not_of(whitespace);
1965  if (posNonWS == std::string::npos) continue;
1966  if (line[posNonWS] == '/' && line[posNonWS + 1] == '/')
1967  // Too bad, we only suppose C++ comments here.
1968  continue;
1969  unnamedMacro = (line[posNonWS] == '{');
1970  break;
1971  }
1972  }
1973 
1974  fCurExecutingMacros.push_back(fname);
1975  cling::MetaProcessor::MaybeRedirectOutputRAII RAII(fMetaProcessor);
1976  if (unnamedMacro) {
1977  compRes = fMetaProcessor->readInputFromFile(fname.Data(), &result,
1978  true /*ignoreOutmostBlock*/);
1979  } else {
1980  // No DynLookup for .x, .L of named macros.
1981  fInterpreter->enableDynamicLookup(false);
1982  indent = fMetaProcessor->process(mod_line, compRes, &result);
1983  }
1984  fCurExecutingMacros.pop_back();
1985  }
1986  } // .L / .X / .x
1987  else {
1988  if (0!=strncmp(sLine.Data(), ".autodict ",10) && sLine != ".autodict") {
1989  // explicitly ignore .autodict without having to support it
1990  // in cling.
1991  cling::MetaProcessor::MaybeRedirectOutputRAII RAII(fMetaProcessor);
1992 
1993  // Turn off autoparsing if this is an include directive
1994  bool isInclusionDirective = sLine.Contains("\n#include") || sLine.BeginsWith("#include");
1995  if (isInclusionDirective) {
1996  SuspendAutoParsing autoParseRaii(this);
1997  indent = fMetaProcessor->process(sLine, compRes, &result);
1998  } else {
1999  indent = fMetaProcessor->process(sLine, compRes, &result);
2000  }
2001  }
2002  }
2003  if (result.isValid())
2004  RegisterTemporary(result);
2005  if (indent) {
2006  if (error)
2007  *error = kProcessing;
2008  return 0;
2009  }
2010  if (error) {
2011  switch (compRes) {
2012  case cling::Interpreter::kSuccess: *error = kNoError; break;
2013  case cling::Interpreter::kFailure: *error = kRecoverable; break;
2014  case cling::Interpreter::kMoreInputExpected: *error = kProcessing; break;
2015  }
2016  }
2017  if (compRes == cling::Interpreter::kSuccess
2018  && result.isValid()
2019  && !result.isVoid())
2020  {
2021  gROOT->SetLineHasBeenProcessed();
2022  return result.simplisticCastAs<long>();
2023  }
2024  gROOT->SetLineHasBeenProcessed();
2025  return 0;
2026 }
2027 
2028 ////////////////////////////////////////////////////////////////////////////////
2029 /// No-op; see TRint instead.
2030 
2032 {
2033 }
2034 
2035 ////////////////////////////////////////////////////////////////////////////////
2036 /// Add the given path to the list of directories in which the interpreter
2037 /// looks for include files. Only one path item can be specified at a
2038 /// time, i.e. "path1:path2" is not supported.
2039 
2040 void TCling::AddIncludePath(const char *path)
2041 {
2043  fInterpreter->AddIncludePath(path);
2044 }
2045 
2046 ////////////////////////////////////////////////////////////////////////////////
2047 /// Visit all members over members, recursing over base classes.
2048 
2049 void TCling::InspectMembers(TMemberInspector& insp, const void* obj,
2050  const TClass* cl, Bool_t isTransient)
2051 {
2055  }
2056 
2057  if (!cl || cl->GetCollectionProxy()) {
2058  // We do not need to investigate the content of the STL
2059  // collection, they are opaque to us (and details are
2060  // uninteresting).
2061  return;
2062  }
2063 
2064  static const TClassRef clRefString("std::string");
2065  if (clRefString == cl) {
2066  // We stream std::string without going through members..
2067  return;
2068  }
2069 
2070  const char* cobj = (const char*) obj; // for ptr arithmetics
2071 
2072  // Treat the case of std::complex in a special manner. We want to enforce
2073  // the layout of a stl implementation independent class, which is the
2074  // complex as implemented in ROOT5.
2075 
2076  // A simple lambda to simplify the code
2077  auto inspInspect = [&] (ptrdiff_t offset){
2078  insp.Inspect(const_cast<TClass*>(cl), insp.GetParent(), "_real", cobj, isTransient);
2079  insp.Inspect(const_cast<TClass*>(cl), insp.GetParent(), "_imag", cobj + offset, isTransient);
2080  };
2081 
2082  auto complexType = TClassEdit::GetComplexType(cl->GetName());
2083  switch(complexType) {
2085  {
2086  break;
2087  }
2089  {
2090  inspInspect(sizeof(float));
2091  return;
2092  }
2094  {
2095  inspInspect(sizeof(double));
2096  return;
2097  }
2099  {
2100  inspInspect(sizeof(int));
2101  return;
2102  }
2104  {
2105  inspInspect(sizeof(long));
2106  return;
2107  }
2108  }
2109 
2110  static clang::PrintingPolicy
2111  printPol(fInterpreter->getCI()->getLangOpts());
2112  if (printPol.Indentation) {
2113  // not yet initialized
2114  printPol.Indentation = 0;
2115  printPol.SuppressInitializers = true;
2116  }
2117 
2118  const char* clname = cl->GetName();
2119  // Printf("Inspecting class %s\n", clname);
2120 
2121  const clang::ASTContext& astContext = fInterpreter->getCI()->getASTContext();
2122  const clang::Decl *scopeDecl = 0;
2123  const clang::Type *recordType = 0;
2124 
2125  if (cl->GetClassInfo()) {
2126  TClingClassInfo * clingCI = (TClingClassInfo *)cl->GetClassInfo();
2127  scopeDecl = clingCI->GetDecl();
2128  recordType = clingCI->GetType();
2129  } else {
2130  const cling::LookupHelper& lh = fInterpreter->getLookupHelper();
2131  // Diags will complain about private classes:
2132  scopeDecl = lh.findScope(clname, cling::LookupHelper::NoDiagnostics,
2133  &recordType);
2134  }
2135  if (!scopeDecl) {
2136  Error("InspectMembers", "Cannot find Decl for class %s", clname);
2137  return;
2138  }
2139  const clang::CXXRecordDecl* recordDecl
2140  = llvm::dyn_cast<const clang::CXXRecordDecl>(scopeDecl);
2141  if (!recordDecl) {
2142  Error("InspectMembers", "Cannot find Decl for class %s is not a CXXRecordDecl.", clname);
2143  return;
2144  }
2145 
2146  {
2147  // Force possible deserializations first. We need to have no pending
2148  // Transaction when passing control flow to the inspector below (ROOT-7779).
2149  cling::Interpreter::PushTransactionRAII deserRAII(fInterpreter);
2150 
2151  astContext.getASTRecordLayout(recordDecl);
2152 
2153  for (clang::RecordDecl::field_iterator iField = recordDecl->field_begin(),
2154  eField = recordDecl->field_end(); iField != eField; ++iField) {}
2155  }
2156 
2157  const clang::ASTRecordLayout& recLayout
2158  = astContext.getASTRecordLayout(recordDecl);
2159 
2160  // TVirtualCollectionProxy *proxy = cl->GetCollectionProxy();
2161  // if (proxy && ( proxy->GetProperties() & TVirtualCollectionProxy::kIsEmulated ) ) {
2162  // Error("InspectMembers","The TClass for %s has an emulated proxy but we are looking at a compiled version of the collection!\n",
2163  // cl->GetName());
2164  // }
2165  if (cl->Size() != recLayout.getSize().getQuantity()) {
2166  Error("InspectMembers","TClass and cling disagree on the size of the class %s, respectively %d %lld\n",
2167  cl->GetName(),cl->Size(),(Long64_t)recLayout.getSize().getQuantity());
2168  }
2169 
2170  unsigned iNField = 0;
2171  // iterate over fields
2172  // FieldDecls are non-static, else it would be a VarDecl.
2173  for (clang::RecordDecl::field_iterator iField = recordDecl->field_begin(),
2174  eField = recordDecl->field_end(); iField != eField;
2175  ++iField, ++iNField) {
2176 
2177 
2178  clang::QualType memberQT = iField->getType();
2179  if (recordType) {
2180  // if (we_need_to_do_the_subst_because_the_class_is_a_template_instance_of_double32_t)
2181  memberQT = ROOT::TMetaUtils::ReSubstTemplateArg(memberQT, recordType);
2182  }
2183  memberQT = cling::utils::Transform::GetPartiallyDesugaredType(astContext, memberQT, fNormalizedCtxt->GetConfig(), false /* fully qualify */);
2184  if (memberQT.isNull()) {
2185  std::string memberName;
2186  llvm::raw_string_ostream stream(memberName);
2187  iField->getNameForDiagnostic(stream, printPol, true /*fqi*/);
2188  stream.flush();
2189  Error("InspectMembers",
2190  "Cannot retrieve QualType for member %s while inspecting class %s",
2191  memberName.c_str(), clname);
2192  continue; // skip member
2193  }
2194  const clang::Type* memType = memberQT.getTypePtr();
2195  if (!memType) {
2196  std::string memberName;
2197  llvm::raw_string_ostream stream(memberName);
2198  iField->getNameForDiagnostic(stream, printPol, true /*fqi*/);
2199  stream.flush();
2200  Error("InspectMembers",
2201  "Cannot retrieve Type for member %s while inspecting class %s",
2202  memberName.c_str(), clname);
2203  continue; // skip member
2204  }
2205 
2206  const clang::Type* memNonPtrType = memType;
2207  Bool_t ispointer = false;
2208  if (memNonPtrType->isPointerType()) {
2209  ispointer = true;
2210  clang::QualType ptrQT
2211  = memNonPtrType->getAs<clang::PointerType>()->getPointeeType();
2212  if (recordType) {
2213  // if (we_need_to_do_the_subst_because_the_class_is_a_template_instance_of_double32_t)
2214  ptrQT = ROOT::TMetaUtils::ReSubstTemplateArg(ptrQT, recordType);
2215  }
2216  ptrQT = cling::utils::Transform::GetPartiallyDesugaredType(astContext, ptrQT, fNormalizedCtxt->GetConfig(), false /* fully qualify */);
2217  if (ptrQT.isNull()) {
2218  std::string memberName;
2219  llvm::raw_string_ostream stream(memberName);
2220  iField->getNameForDiagnostic(stream, printPol, true /*fqi*/);
2221  stream.flush();
2222  Error("InspectMembers",
2223  "Cannot retrieve pointee Type for member %s while inspecting class %s",
2224  memberName.c_str(), clname);
2225  continue; // skip member
2226  }
2227  memNonPtrType = ptrQT.getTypePtr();
2228  }
2229 
2230  // assemble array size(s): "[12][4][]"
2231  llvm::SmallString<8> arraySize;
2232  const clang::ArrayType* arrType = memNonPtrType->getAsArrayTypeUnsafe();
2233  unsigned arrLevel = 0;
2234  bool haveErrorDueToArray = false;
2235  while (arrType) {
2236  ++arrLevel;
2237  arraySize += '[';
2238  const clang::ConstantArrayType* constArrType =
2239  clang::dyn_cast<clang::ConstantArrayType>(arrType);
2240  if (constArrType) {
2241  constArrType->getSize().toStringUnsigned(arraySize);
2242  }
2243  arraySize += ']';
2244  clang::QualType subArrQT = arrType->getElementType();
2245  if (subArrQT.isNull()) {
2246  std::string memberName;
2247  llvm::raw_string_ostream stream(memberName);
2248  iField->getNameForDiagnostic(stream, printPol, true /*fqi*/);
2249  stream.flush();
2250  Error("InspectMembers",
2251  "Cannot retrieve QualType for array level %d (i.e. element type of %s) for member %s while inspecting class %s",
2252  arrLevel, subArrQT.getAsString(printPol).c_str(),
2253  memberName.c_str(), clname);
2254  haveErrorDueToArray = true;
2255  break;
2256  }
2257  arrType = subArrQT.getTypePtr()->getAsArrayTypeUnsafe();
2258  }
2259  if (haveErrorDueToArray) {
2260  continue; // skip member
2261  }
2262 
2263  // construct member name
2264  std::string fieldName;
2265  if (memType->isPointerType()) {
2266  fieldName = "*";
2267  }
2268 
2269  // Check if this field has a custom ioname, if not, just use the one of the decl
2270  std::string ioname(iField->getName());
2272  fieldName += ioname;
2273  fieldName += arraySize;
2274 
2275  // get member offset
2276  // NOTE currently we do not support bitfield and do not support
2277  // member that are not aligned on 'bit' boundaries.
2278  clang::CharUnits offset(astContext.toCharUnitsFromBits(recLayout.getFieldOffset(iNField)));
2279  ptrdiff_t fieldOffset = offset.getQuantity();
2280 
2281  // R__insp.Inspect(R__cl, R__insp.GetParent(), "fBits[2]", fBits);
2282  // R__insp.Inspect(R__cl, R__insp.GetParent(), "fName", &fName);
2283  // R__insp.InspectMember(fName, "fName.");
2284  // R__insp.Inspect(R__cl, R__insp.GetParent(), "*fClass", &fClass);
2285 
2286  // If the class has a custom streamer and the type of the filed is a
2287  // private enum, struct or class, skip it.
2288  if (!insp.IsTreatingNonAccessibleTypes()){
2289  auto iFiledQtype = iField->getType();
2290  if (auto tagDecl = iFiledQtype->getAsTagDecl()){
2291  auto declAccess = tagDecl->getAccess();
2292  if (declAccess == AS_private || declAccess == AS_protected) {
2293  continue;
2294  }
2295  }
2296  }
2297 
2298  insp.Inspect(const_cast<TClass*>(cl), insp.GetParent(), fieldName.c_str(), cobj + fieldOffset, isTransient);
2299 
2300  if (!ispointer) {
2301  const clang::CXXRecordDecl* fieldRecDecl = memNonPtrType->getAsCXXRecordDecl();
2302  if (fieldRecDecl) {
2303  // nested objects get an extra call to InspectMember
2304  // R__insp.InspectMember("FileStat_t", (void*)&fFileStat, "fFileStat.", false);
2305  std::string sFieldRecName;
2306  if (!ROOT::TMetaUtils::ExtractAttrPropertyFromName(*fieldRecDecl,"iotype",sFieldRecName)){
2308  clang::QualType(memNonPtrType,0),
2309  *fInterpreter,
2310  *fNormalizedCtxt);
2311  }
2312 
2313  TDataMember* mbr = cl->GetDataMember(ioname.c_str());
2314  // if we can not find the member (which should not really happen),
2315  // let's consider it transient.
2316  Bool_t transient = isTransient || !mbr || !mbr->IsPersistent();
2317 
2318  insp.InspectMember(sFieldRecName.c_str(), cobj + fieldOffset,
2319  (fieldName + '.').c_str(), transient);
2320 
2321  }
2322  }
2323  } // loop over fields
2324 
2325  // inspect bases
2326  // TNamed::ShowMembers(R__insp);
2327  unsigned iNBase = 0;
2328  for (clang::CXXRecordDecl::base_class_const_iterator iBase
2329  = recordDecl->bases_begin(), eBase = recordDecl->bases_end();
2330  iBase != eBase; ++iBase, ++iNBase) {
2331  clang::QualType baseQT = iBase->getType();
2332  if (baseQT.isNull()) {
2333  Error("InspectMembers",
2334  "Cannot find QualType for base number %d while inspecting class %s",
2335  iNBase, clname);
2336  continue;
2337  }
2338  const clang::CXXRecordDecl* baseDecl
2339  = baseQT->getAsCXXRecordDecl();
2340  if (!baseDecl) {
2341  Error("InspectMembers",
2342  "Cannot find CXXRecordDecl for base number %d while inspecting class %s",
2343  iNBase, clname);
2344  continue;
2345  }
2346  TClass* baseCl=nullptr;
2347  std::string sBaseName;
2348  // Try with the DeclId
2349  std::vector<TClass*> foundClasses;
2350  TClass::GetClass(static_cast<DeclId_t>(baseDecl), foundClasses);
2351  if (foundClasses.size()==1){
2352  baseCl=foundClasses[0];
2353  } else {
2354  // Try with the normalised Name, as a fallback
2355  if (!baseCl){
2357  baseQT,
2358  *fInterpreter,
2359  *fNormalizedCtxt);
2360  baseCl = TClass::GetClass(sBaseName.c_str());
2361  }
2362  }
2363 
2364  if (!baseCl){
2365  std::string qualNameForDiag;
2366  ROOT::TMetaUtils::GetQualifiedName(qualNameForDiag, *baseDecl);
2367  Error("InspectMembers",
2368  "Cannot find TClass for base class %s", qualNameForDiag.c_str() );
2369  continue;
2370  }
2371 
2372  int64_t baseOffset;
2373  if (iBase->isVirtual()) {
2375  if (!isTransient) {
2376  Error("InspectMembers",
2377  "Base %s of class %s is virtual but no object provided",
2378  sBaseName.c_str(), clname);
2379  }
2381  } else {
2382  // We have an object to determine the vbase offset.
2384  TClingClassInfo* baseCi = (TClingClassInfo*)baseCl->GetClassInfo();
2385  if (ci && baseCi) {
2386  baseOffset = ci->GetBaseOffset(baseCi, const_cast<void*>(obj),
2387  true /*isDerivedObj*/);
2388  if (baseOffset == -1) {
2389  Error("InspectMembers",
2390  "Error calculating offset of virtual base %s of class %s",
2391  sBaseName.c_str(), clname);
2392  }
2393  } else {
2394  Error("InspectMembers",
2395  "Cannot calculate offset of virtual base %s of class %s",
2396  sBaseName.c_str(), clname);
2397  continue;
2398  }
2399  }
2400  } else {
2401  baseOffset = recLayout.getBaseClassOffset(baseDecl).getQuantity();
2402  }
2403  // TOFIX: baseCl can be null here!
2404  if (baseCl->IsLoaded()) {
2405  // For loaded class, CallShowMember will (especially for TObject)
2406  // call the virtual ShowMember rather than the class specific version
2407  // resulting in an infinite recursion.
2408  InspectMembers(insp, cobj + baseOffset, baseCl, isTransient);
2409  } else {
2410  baseCl->CallShowMembers(cobj + baseOffset,
2411  insp, isTransient);
2412  }
2413  } // loop over bases
2414 }
2415 
2416 ////////////////////////////////////////////////////////////////////////////////
2417 /// Reset the interpreter internal state in case a previous action was not correctly
2418 /// terminated.
2419 
2421 {
2422  // No-op there is not equivalent state (to be cleared) in Cling.
2423 }
2424 
2425 ////////////////////////////////////////////////////////////////////////////////
2426 /// Delete existing temporary values.
2427 
2429 {
2430  // No-op for cling due to cling::Value.
2431 }
2432 
2433 ////////////////////////////////////////////////////////////////////////////////
2434 /// Declare code to the interpreter, without any of the interpreter actions
2435 /// that could trigger a re-interpretation of the code. I.e. make cling
2436 /// behave like a compiler: no dynamic lookup, no input wrapping for
2437 /// subsequent execution, no automatic provision of declarations but just a
2438 /// plain #include.
2439 /// Returns true on success, false on failure.
2440 
2441 bool TCling::Declare(const char* code)
2442 {
2444 
2445  int oldload = SetClassAutoloading(0);
2446  SuspendAutoParsing autoParseRaii(this);
2447 
2448  bool oldDynLookup = fInterpreter->isDynamicLookupEnabled();
2449  fInterpreter->enableDynamicLookup(false);
2450  bool oldRawInput = fInterpreter->isRawInputEnabled();
2451  fInterpreter->enableRawInput(true);
2452 
2453  Bool_t ret = LoadText(code);
2454 
2455  fInterpreter->enableRawInput(oldRawInput);
2456  fInterpreter->enableDynamicLookup(oldDynLookup);
2457  SetClassAutoloading(oldload);
2458  return ret;
2459 }
2460 
2461 ////////////////////////////////////////////////////////////////////////////////
2462 /// Enable the automatic loading of shared libraries when a class
2463 /// is used that is stored in a not yet loaded library. Uses the
2464 /// information stored in the class/library map (typically
2465 /// $ROOTSYS/etc/system.rootmap).
2466 
2468 {
2469  if (fAllowLibLoad) {
2470  LoadLibraryMap();
2471  SetClassAutoloading(true);
2472  }
2473 }
2474 
2475 ////////////////////////////////////////////////////////////////////////////////
2476 /// It calls a "fantom" method to synchronize user keyboard input
2477 /// and ROOT prompt line.
2478 
2480 {
2481  ProcessLineSynch(fantomline);
2482 }
2483 
2484 ////////////////////////////////////////////////////////////////////////////////
2485 /// Return true if the file has already been loaded by cint.
2486 /// We will try in this order:
2487 /// actual filename
2488 /// filename as a path relative to
2489 /// the include path
2490 /// the shared library path
2491 
2493 {
2495 
2496  //FIXME: if we use llvm::sys::fs::make_absolute all this can go away. See
2497  // cling::DynamicLibraryManager.
2498 
2499  std::string file_name = filename;
2500  size_t at = std::string::npos;
2501  while ((at = file_name.find("/./")) != std::string::npos)
2502  file_name.replace(at, 3, "/");
2503 
2504  std::string filesStr = "";
2505  llvm::raw_string_ostream filesOS(filesStr);
2506  clang::SourceManager &SM = fInterpreter->getCI()->getSourceManager();
2507  cling::ClangInternalState::printIncludedFiles(filesOS, SM);
2508  filesOS.flush();
2509 
2510  llvm::SmallVector<llvm::StringRef, 100> files;
2511  llvm::StringRef(filesStr).split(files, "\n");
2512 
2513  std::set<std::string> fileMap;
2514  // Fill fileMap; return early on exact match.
2515  for (llvm::SmallVector<llvm::StringRef, 100>::const_iterator
2516  iF = files.begin(), iE = files.end(); iF != iE; ++iF) {
2517  if ((*iF) == file_name.c_str()) return kTRUE; // exact match
2518  fileMap.insert(*iF);
2519  }
2520 
2521  if (fileMap.empty()) return kFALSE;
2522 
2523  // Check MacroPath.
2524  TString sFilename(file_name.c_str());
2526  && fileMap.count(sFilename.Data())) {
2527  return kTRUE;
2528  }
2529 
2530  // Check IncludePath.
2531  TString incPath = gSystem->GetIncludePath(); // of the form -Idir1 -Idir2 -Idir3
2532  incPath.Append(":").Prepend(" "); // to match " -I" (note leading ' ')
2533  incPath.ReplaceAll(" -I", ":"); // of form :dir1 :dir2:dir3
2534  while (incPath.Index(" :") != -1) {
2535  incPath.ReplaceAll(" :", ":");
2536  }
2537  incPath.Prepend(".:");
2538  sFilename = file_name.c_str();
2539  if (gSystem->FindFile(incPath, sFilename, kReadPermission)
2540  && fileMap.count(sFilename.Data())) {
2541  return kTRUE;
2542  }
2543 
2544  // Check shared library.
2545  sFilename = file_name.c_str();
2546  const char *found = gSystem->FindDynamicLibrary(sFilename, kTRUE);
2547  cling::DynamicLibraryManager* dyLibManager
2548  = fInterpreter->getDynamicLibraryManager();
2549  if (found) {
2550  if (dyLibManager->isLibraryLoaded(found)) {
2551  return kTRUE;
2552  }
2553  }
2554  //FIXME: We must use the cling::Interpreter::lookupFileOrLibrary iface.
2555  const clang::DirectoryLookup *CurDir = 0;
2556  clang::Preprocessor &PP = fInterpreter->getCI()->getPreprocessor();
2557  clang::HeaderSearch &HS = PP.getHeaderSearchInfo();
2558  const clang::FileEntry *FE = HS.LookupFile(file_name.c_str(),
2559  clang::SourceLocation(),
2560  /*isAngled*/ false,
2561  /*FromDir*/ 0, CurDir,
2562  clang::ArrayRef<std::pair<const clang::FileEntry *,
2563  const clang::DirectoryEntry *>>(),
2564  /*SearchPath*/ 0,
2565  /*RelativePath*/ 0,
2566  /*SuggestedModule*/ 0,
2567  /*SkipCache*/ false,
2568  /*OpenFile*/ false,
2569  /*CacheFail*/ false);
2570  if (FE && FE->isValid()) {
2571  // check in the source manager if the file is actually loaded
2572  clang::SourceManager &SM = fInterpreter->getCI()->getSourceManager();
2573  // this works only with header (and source) files...
2574  clang::FileID FID = SM.translateFile(FE);
2575  if (!FID.isInvalid() && FID.getHashValue() == 0)
2576  return kFALSE;
2577  else {
2578  clang::SrcMgr::SLocEntry SLocE = SM.getSLocEntry(FID);
2579  if (SLocE.isFile() && SLocE.getFile().getContentCache()->getRawBuffer() == 0)
2580  return kFALSE;
2581  if (!FID.isInvalid())
2582  return kTRUE;
2583  }
2584  // ...then check shared library again, but with full path now
2585  sFilename = FE->getName();
2586  if (gSystem->FindDynamicLibrary(sFilename, kTRUE)
2587  && fileMap.count(sFilename.Data())) {
2588  return kTRUE;
2589  }
2590  }
2591  return kFALSE;
2592 }
2593 
2594 ////////////////////////////////////////////////////////////////////////////////
2595 
2597 {
2598 #if defined(R__WIN32) || defined(__CYGWIN__)
2599  HMODULE hModules[1024];
2600  void *hProcess;
2601  unsigned long cbModules;
2602  unsigned int i;
2603  hProcess = (void *)::GetCurrentProcess();
2604  ::EnumProcessModules(hProcess, hModules, sizeof(hModules), &cbModules);
2605  // start at 1 to skip the executable itself
2606  for (i = 1; i < (cbModules / sizeof(void *)); i++) {
2607  static const int bufsize = 260;
2608  wchar_t winname[bufsize];
2609  char posixname[bufsize];
2610  ::GetModuleFileNameExW(hProcess, hModules[i], winname, bufsize);
2611 #if defined(__CYGWIN__)
2612  cygwin_conv_path(CCP_WIN_W_TO_POSIX, winname, posixname, bufsize);
2613 #else
2614  std::wstring wpath = winname;
2615  std::replace(wpath.begin(), wpath.end(), '\\', '/');
2616  string path(wpath.begin(), wpath.end());
2617  strncpy(posixname, path.c_str(), bufsize);
2618 #endif
2619  if (!fSharedLibs.Contains(posixname)) {
2620  RegisterLoadedSharedLibrary(posixname);
2621  }
2622  }
2623 #elif defined(R__MACOSX)
2624  // fPrevLoadedDynLibInfo stores the *next* image index to look at
2625  uint32_t imageIndex = (uint32_t) (size_t) fPrevLoadedDynLibInfo;
2626  const char* imageName = 0;
2627  while ((imageName = _dyld_get_image_name(imageIndex))) {
2628  // Skip binary
2629  if (imageIndex > 0)
2630  RegisterLoadedSharedLibrary(imageName);
2631  ++imageIndex;
2632  }
2633  fPrevLoadedDynLibInfo = (void*)(size_t)imageIndex;
2634 #elif defined(R__LINUX)
2635  struct PointerNo4_t {
2636  void* fSkip[3];
2637  void* fPtr;
2638  };
2639  struct LinkMap_t {
2640  void* fAddr;
2641  const char* fName;
2642  void* fLd;
2643  LinkMap_t* fNext;
2644  LinkMap_t* fPrev;
2645  };
2646  if (!fPrevLoadedDynLibInfo || fPrevLoadedDynLibInfo == (void*)(size_t)-1) {
2647  PointerNo4_t* procLinkMap = (PointerNo4_t*)dlopen(0, RTLD_LAZY | RTLD_GLOBAL);
2648  // 4th pointer of 4th pointer is the linkmap.
2649  // See http://syprog.blogspot.fr/2011/12/listing-loaded-shared-objects-in-linux.html
2650  LinkMap_t* linkMap = (LinkMap_t*) ((PointerNo4_t*)procLinkMap->fPtr)->fPtr;
2651  RegisterLoadedSharedLibrary(linkMap->fName);
2652  fPrevLoadedDynLibInfo = linkMap;
2653  }
2654 
2655  LinkMap_t* iDyLib = (LinkMap_t*)fPrevLoadedDynLibInfo;
2656  while (iDyLib->fNext) {
2657  iDyLib = iDyLib->fNext;
2658  RegisterLoadedSharedLibrary(iDyLib->fName);
2659  }
2660  fPrevLoadedDynLibInfo = iDyLib;
2661 #else
2662  Error("TCling::UpdateListOfLoadedSharedLibraries",
2663  "Platform not supported!");
2664 #endif
2665 }
2666 
2667 ////////////////////////////////////////////////////////////////////////////////
2668 /// Register a new shared library name with the interpreter; add it to
2669 /// fSharedLibs.
2670 
2672 {
2673  // Ignore NULL filenames, aka "the process".
2674  if (!filename) return;
2675 
2676  // Tell the interpreter that this library is available; all libraries can be
2677  // used to resolve symbols.
2678  cling::DynamicLibraryManager* DLM = fInterpreter->getDynamicLibraryManager();
2679  if (!DLM->isLibraryLoaded(filename)) {
2680  DLM->loadLibrary(filename, true /*permanent*/);
2681  }
2682 
2683 #if defined(R__MACOSX)
2684  // Check that this is not a system library
2685  if (!strncmp(filename, "/usr/lib/system/", 16)
2686  || !strncmp(filename, "/usr/lib/libc++", 15)
2687  || !strncmp(filename, "/System/Library/Frameworks/", 27)
2688  || !strncmp(filename, "/System/Library/PrivateFrameworks/", 34)
2689  || !strncmp(filename, "/System/Library/CoreServices/", 29)
2690  || !strcmp(filename, "cl_kernels") // yepp, no directory
2691  || strstr(filename, "/usr/lib/libSystem")
2692  || strstr(filename, "/usr/lib/libstdc++")
2693  || strstr(filename, "/usr/lib/libicucore")
2694  || strstr(filename, "/usr/lib/libbsm")
2695  || strstr(filename, "/usr/lib/libobjc")
2696  || strstr(filename, "/usr/lib/libresolv")
2697  || strstr(filename, "/usr/lib/libauto")
2698  || strstr(filename, "/usr/lib/libcups")
2699  || strstr(filename, "/usr/lib/libDiagnosticMessagesClient")
2700  || strstr(filename, "/usr/lib/liblangid")
2701  || strstr(filename, "/usr/lib/libCRFSuite")
2702  || strstr(filename, "/usr/lib/libpam")
2703  || strstr(filename, "/usr/lib/libOpenScriptingUtil")
2704  || strstr(filename, "/usr/lib/libextension"))
2705  return;
2706 #elif defined(__CYGWIN__)
2707  // Check that this is not a system library
2708  static const int bufsize = 260;
2709  char posixwindir[bufsize];
2710  char *windir = getenv("WINDIR");
2711  if (windir)
2712  cygwin_conv_path(CCP_WIN_A_TO_POSIX, windir, posixwindir, bufsize);
2713  else
2714  snprintf(posixwindir, sizeof(posixwindir), "/Windows/");
2715  if (strstr(filename, posixwindir) ||
2716  strstr(filename, "/usr/bin/cyg"))
2717  return;
2718 #elif defined(R__WIN32)
2719  if (strstr(filename, "/Windows/"))
2720  return;
2721 #elif defined (R__LINUX)
2722  if (strstr(filename, "/ld-linux")
2723  || strstr(filename, "linux-gnu/")
2724  || strstr(filename, "/libstdc++.")
2725  || strstr(filename, "/libgcc")
2726  || strstr(filename, "/libc.")
2727  || strstr(filename, "/libdl.")
2728  || strstr(filename, "/libm."))
2729  return;
2730 #endif
2731  // Update string of available libraries.
2732  if (!fSharedLibs.IsNull()) {
2733  fSharedLibs.Append(" ");
2734  }
2735  fSharedLibs.Append(filename);
2736 }
2737 
2738 ////////////////////////////////////////////////////////////////////////////////
2739 /// Load a library file in cling's memory.
2740 /// if 'system' is true, the library is never unloaded.
2741 /// Return 0 on success, -1 on failure.
2742 
2743 Int_t TCling::Load(const char* filename, Bool_t system)
2744 {
2745  if (!fAllowLibLoad) {
2746  Error("Load","Trying to load library (%s) from rootcling.",filename);
2747  return -1;
2748  }
2749 
2750  // Used to return 0 on success, 1 on duplicate, -1 on failure, -2 on "fatal".
2752  cling::DynamicLibraryManager* DLM = fInterpreter->getDynamicLibraryManager();
2753  std::string canonLib = DLM->lookupLibrary(filename);
2754  cling::DynamicLibraryManager::LoadLibResult res
2755  = cling::DynamicLibraryManager::kLoadLibNotFound;
2756  if (!canonLib.empty()) {
2757  if (system)
2758  res = DLM->loadLibrary(filename, system);
2759  else {
2760  // For the non system libs, we'd like to be able to unload them.
2761  // FIXME: Here we lose the information about kLoadLibAlreadyLoaded case.
2762  cling::Interpreter::CompilationResult compRes;
2763  cling::MetaProcessor::MaybeRedirectOutputRAII RAII(fMetaProcessor);
2764  fMetaProcessor->process(Form(".L %s", canonLib.c_str()), compRes, /*cling::Value*/0);
2765  if (compRes == cling::Interpreter::kSuccess)
2766  res = cling::DynamicLibraryManager::kLoadLibSuccess;
2767  }
2768  }
2769 
2770  if (res == cling::DynamicLibraryManager::kLoadLibSuccess) {
2772  }
2773  switch (res) {
2774  case cling::DynamicLibraryManager::kLoadLibSuccess: return 0;
2775  case cling::DynamicLibraryManager::kLoadLibAlreadyLoaded: return 1;
2776  default: break;
2777  };
2778  return -1;
2779 }
2780 
2781 ////////////////////////////////////////////////////////////////////////////////
2782 /// Load a macro file in cling's memory.
2783 
2784 void TCling::LoadMacro(const char* filename, EErrorCode* error)
2785 {
2786  ProcessLine(Form(".L %s", filename), error);
2787 }
2788 
2789 ////////////////////////////////////////////////////////////////////////////////
2790 /// Let cling process a command line asynch.
2791 
2793 {
2794  return ProcessLine(line, error);
2795 }
2796 
2797 ////////////////////////////////////////////////////////////////////////////////
2798 /// Let cling process a command line synchronously, i.e we are waiting
2799 /// it will be finished.
2800 
2802 {
2804  if (gApplication) {
2805  if (gApplication->IsCmdThread()) {
2806  return ProcessLine(line, error);
2807  }
2808  return 0;
2809  }
2810  return ProcessLine(line, error);
2811 }
2812 
2813 ////////////////////////////////////////////////////////////////////////////////
2814 /// Directly execute an executable statement (e.g. "func()", "3+5", etc.
2815 /// however not declarations, like "Int_t x;").
2816 
2817 Long_t TCling::Calc(const char* line, EErrorCode* error)
2818 {
2819 #ifdef R__WIN32
2820  // Test on ApplicationImp not being 0 is needed because only at end of
2821  // TApplication ctor the IsLineProcessing flag is set to 0, so before
2822  // we can not use it.
2824  while (gROOT->IsLineProcessing() && !gApplication) {
2825  Warning("Calc", "waiting for cling thread to free");
2826  gSystem->Sleep(500);
2827  }
2828  gROOT->SetLineIsProcessing();
2829  }
2830 #endif // R__WIN32
2832  if (error) {
2833  *error = TInterpreter::kNoError;
2834  }
2835  cling::Value valRef;
2836  cling::Interpreter::CompilationResult cr = fInterpreter->evaluate(line, valRef);
2837  if (cr != cling::Interpreter::kSuccess) {
2838  // Failure in compilation.
2839  if (error) {
2840  // Note: Yes these codes are weird.
2841  *error = TInterpreter::kRecoverable;
2842  }
2843  return 0L;
2844  }
2845  if (!valRef.isValid()) {
2846  // Failure at runtime.
2847  if (error) {
2848  // Note: Yes these codes are weird.
2849  *error = TInterpreter::kDangerous;
2850  }
2851  return 0L;
2852  }
2853 
2854  if (valRef.isVoid()) {
2855  return 0;
2856  }
2857 
2858  RegisterTemporary(valRef);
2859 #ifdef R__WIN32
2861  gROOT->SetLineHasBeenProcessed();
2862  }
2863 #endif // R__WIN32
2864  return valRef.simplisticCastAs<long>();
2865 }
2866 
2867 ////////////////////////////////////////////////////////////////////////////////
2868 /// Set a getline function to call when input is needed.
2869 
2870 void TCling::SetGetline(const char * (*getlineFunc)(const char* prompt),
2871  void (*histaddFunc)(const char* line))
2872 {
2873  // If cling offers a replacement for G__pause(), it would need to
2874  // also offer a way to customize at least the history recording.
2875 
2876 #if defined(R__MUST_REVISIT)
2877 #if R__MUST_REVISIT(6,2)
2878  Warning("SetGetline","Cling should support the equivalent of SetGetlineFunc(getlineFunc, histaddFunc)");
2879 #endif
2880 #endif
2881 }
2882 
2883 ////////////////////////////////////////////////////////////////////////////////
2884 /// Helper function to increase the internal Cling count of transactions
2885 /// that change the AST.
2886 
2887 Bool_t TCling::HandleNewTransaction(const cling::Transaction &T)
2888 {
2890 
2891  if ((std::distance(T.decls_begin(), T.decls_end()) != 1)
2892  || T.deserialized_decls_begin() != T.deserialized_decls_end()
2893  || T.macros_begin() != T.macros_end()
2894  || ((!T.getFirstDecl().isNull()) && ((*T.getFirstDecl().begin()) != T.getWrapperFD()))) {
2896  return true;
2897  }
2898  return false;
2899 }
2900 
2901 ////////////////////////////////////////////////////////////////////////////////
2902 /// Delete object from cling symbol table so it can not be used anymore.
2903 /// cling objects are always on the heap.
2904 
2906 {
2908  // Note that fgSetOfSpecials is supposed to be updated by TClingCallbacks::tryFindROOTSpecialInternal
2909  // (but isn't at the moment).
2910  if (obj->IsOnHeap() && fgSetOfSpecials && !((std::set<TObject*>*)fgSetOfSpecials)->empty()) {
2911  std::set<TObject*>::iterator iSpecial = ((std::set<TObject*>*)fgSetOfSpecials)->find(obj);
2912  if (iSpecial != ((std::set<TObject*>*)fgSetOfSpecials)->end()) {
2913  DeleteGlobal(obj);
2914  ((std::set<TObject*>*)fgSetOfSpecials)->erase(iSpecial);
2915  }
2916  }
2917 }
2918 
2919 ////////////////////////////////////////////////////////////////////////////////
2920 /// Pressing Ctrl+C should forward here. In the case where we have had
2921 /// continuation requested we must reset it.
2922 
2924 {
2925  fMetaProcessor->cancelContinuation();
2926  // Reset the Cling state to the state saved by the last call to
2927  // TCling::SaveContext().
2928 #if defined(R__MUST_REVISIT)
2929 #if R__MUST_REVISIT(6,2)
2931  Warning("Reset","Cling should support the equivalent of scratch_upto(&fDictPos)");
2932 #endif
2933 #endif
2934 }
2935 
2936 ////////////////////////////////////////////////////////////////////////////////
2937 /// Reset the Cling state to its initial state.
2938 
2940 {
2941 #if defined(R__MUST_REVISIT)
2942 #if R__MUST_REVISIT(6,2)
2944  Warning("ResetAll","Cling should support the equivalent of complete reset (unload everything but the startup decls.");
2945 #endif
2946 #endif
2947 }
2948 
2949 ////////////////////////////////////////////////////////////////////////////////
2950 /// Reset in Cling the list of global variables to the state saved by the last
2951 /// call to TCling::SaveGlobalsContext().
2952 ///
2953 /// Note: Right now, all we do is run the global destructors.
2954 
2956 {
2958  // TODO:
2959  // Here we should iterate over the transactions (N-3) and revert.
2960  // N-3 because the first three internal to cling.
2961 
2962  fInterpreter->runAndRemoveStaticDestructors();
2963 }
2964 
2965 ////////////////////////////////////////////////////////////////////////////////
2966 /// Reset the Cling 'user' global objects/variables state to the state saved by the last
2967 /// call to TCling::SaveGlobalsContext().
2968 
2969 void TCling::ResetGlobalVar(void* obj)
2970 {
2971 #if defined(R__MUST_REVISIT)
2972 #if R__MUST_REVISIT(6,2)
2974  Warning("ResetGlobalVar","Cling should support the equivalent of resetglobalvar(obj)");
2975 #endif
2976 #endif
2977 }
2978 
2979 ////////////////////////////////////////////////////////////////////////////////
2980 /// Rewind Cling dictionary to the point where it was before executing
2981 /// the current macro. This function is typically called after SEGV or
2982 /// ctlr-C after doing a longjmp back to the prompt.
2983 
2985 {
2986 #if defined(R__MUST_REVISIT)
2987 #if R__MUST_REVISIT(6,2)
2989  Warning("RewindDictionary","Cling should provide a way to revert transaction similar to rewinddictionary()");
2990 #endif
2991 #endif
2992 }
2993 
2994 ////////////////////////////////////////////////////////////////////////////////
2995 /// Delete obj from Cling symbol table so it cannot be accessed anymore.
2996 /// Returns 1 in case of success and 0 in case object was not in table.
2997 
2999 {
3000 #if defined(R__MUST_REVISIT)
3001 #if R__MUST_REVISIT(6,2)
3003  Warning("DeleteGlobal","Cling should provide the equivalent of deleteglobal(obj), see also DeleteVariable.");
3004 #endif
3005 #endif
3006  return 0;
3007 }
3008 
3009 ////////////////////////////////////////////////////////////////////////////////
3010 /// Undeclare obj called name.
3011 /// Returns 1 in case of success, 0 for failure.
3012 
3014 {
3015 #if defined(R__MUST_REVISIT)
3016 #if R__MUST_REVISIT(6,2)
3017  Warning("DeleteVariable","should do more that just reseting the value to zero");
3018 #endif
3019 #endif
3020 
3022  llvm::StringRef srName(name);
3023  const char* unscopedName = name;
3024  llvm::StringRef::size_type posScope = srName.rfind("::");
3025  const clang::DeclContext* declCtx = 0;
3026  if (posScope != llvm::StringRef::npos) {
3027  const cling::LookupHelper& lh = fInterpreter->getLookupHelper();
3028  const clang::Decl* scopeDecl
3029  = lh.findScope(srName.substr(0, posScope),
3030  cling::LookupHelper::WithDiagnostics);
3031  if (!scopeDecl) {
3032  Error("DeleteVariable", "Cannot find enclosing scope for variable %s",
3033  name);
3034  return 0;
3035  }
3036  declCtx = llvm::dyn_cast<clang::DeclContext>(scopeDecl);
3037  if (!declCtx) {
3038  Error("DeleteVariable",
3039  "Enclosing scope for variable %s is not a declaration context",
3040  name);
3041  return 0;
3042  }
3043  unscopedName += posScope + 2;
3044  }
3045  clang::NamedDecl* nVarDecl
3046  = cling::utils::Lookup::Named(&fInterpreter->getSema(), unscopedName, declCtx);
3047  if (!nVarDecl) {
3048  Error("DeleteVariable", "Unknown variable %s", name);
3049  return 0;
3050  }
3051  clang::VarDecl* varDecl = llvm::dyn_cast<clang::VarDecl>(nVarDecl);
3052  if (!varDecl) {
3053  Error("DeleteVariable", "Entity %s is not a variable", name);
3054  return 0;
3055  }
3056 
3057  clang::QualType qType = varDecl->getType();
3058  const clang::Type* type = qType->getUnqualifiedDesugaredType();
3059  // Cannot set a reference's address to nullptr; the JIT can place it
3060  // into read-only memory (ROOT-7100).
3061  if (type->isPointerType()) {
3062  int** ppInt = (int**)fInterpreter->getAddressOfGlobal(GlobalDecl(varDecl));
3063  // set pointer to invalid.
3064  if (ppInt) *ppInt = 0;
3065  }
3066  return 1;
3067 }
3068 
3069 ////////////////////////////////////////////////////////////////////////////////
3070 /// Save the current Cling state.
3071 
3073 {
3074 #if defined(R__MUST_REVISIT)
3075 #if R__MUST_REVISIT(6,2)
3077  Warning("SaveContext","Cling should provide a way to record a state watermark similar to store_dictposition(&fDictPos)");
3078 #endif
3079 #endif
3080 }
3081 
3082 ////////////////////////////////////////////////////////////////////////////////
3083 /// Save the current Cling state of global objects.
3084 
3086 {
3087 #if defined(R__MUST_REVISIT)
3088 #if R__MUST_REVISIT(6,2)
3090  Warning("SaveGlobalsContext","Cling should provide a way to record a watermark for the list of global variable similar to store_dictposition(&fDictPosGlobals)");
3091 #endif
3092 #endif
3093 }
3094 
3095 ////////////////////////////////////////////////////////////////////////////////
3096 /// No op: see TClingCallbacks (used to update the list of globals)
3097 
3099 {
3100 }
3101 
3102 ////////////////////////////////////////////////////////////////////////////////
3103 /// No op: see TClingCallbacks (used to update the list of global functions)
3104 
3106 {
3107 }
3108 
3109 ////////////////////////////////////////////////////////////////////////////////
3110 /// No op: see TClingCallbacks (used to update the list of types)
3111 
3113 {
3114 }
3115 
3116 ////////////////////////////////////////////////////////////////////////////////
3117 /// Set pointer to the TClingClassInfo in TClass.
3118 /// If 'reload' is true, (attempt to) generate a new ClassInfo even if we
3119 /// already have one.
3120 
3122 {
3124  if (cl->fClassInfo && !reload) {
3125  return;
3126  }
3127  //Remove the decl_id from the DeclIdToTClass map
3128  TClingClassInfo* TClinginfo = (TClingClassInfo*) cl->fClassInfo;
3129  if (TClinginfo) {
3130  TClass::RemoveClassDeclId(TClinginfo->GetDeclId());
3131  }
3132  delete TClinginfo;
3133  cl->fClassInfo = 0;
3134  std::string name(cl->GetName());
3135  TClingClassInfo* info = new TClingClassInfo(fInterpreter, name.c_str());
3136  if (!info->IsValid()) {
3137  if (cl->fState != TClass::kHasTClassInit) {
3138  if (cl->fStreamerInfo->GetEntries() != 0) {
3139  cl->fState = TClass::kEmulated;
3140  } else {
3142  }
3143  }
3144  delete info;
3145  return;
3146  }
3147  cl->fClassInfo = (ClassInfo_t*)info; // Note: We are transferring ownership here.
3148  // In case a class contains an external enum, the enum will be seen as a
3149  // class. We must detect this special case and make the class a Zombie.
3150  // Here we assume that a class has at least one method.
3151  // We can NOT call TClass::Property from here, because this method
3152  // assumes that the TClass is well formed to do a lot of information
3153  // caching. The method SetClassInfo (i.e. here) is usually called during
3154  // the building phase of the TClass, hence it is NOT well formed yet.
3155  Bool_t zombieCandidate = kFALSE;
3156  if (
3157  info->IsValid() &&
3158  !(info->Property() & (kIsClass | kIsStruct | kIsNamespace))
3159  ) {
3160  zombieCandidate = kTRUE;
3161  }
3162  if (!info->IsLoaded()) {
3163  if (info->Property() & (kIsNamespace)) {
3164  // Namespaces can have info but no corresponding CINT dictionary
3165  // because they are auto-created if one of their contained
3166  // classes has a dictionary.
3167  zombieCandidate = kTRUE;
3168  }
3169  // this happens when no dictionary is available
3170  delete info;
3171  cl->fClassInfo = 0;
3172  }
3173  if (zombieCandidate && !cl->GetCollectionType()) {
3174  cl->MakeZombie();
3175  }
3176  // If we reach here, the info was valid (See early returns).
3177  if (cl->fState != TClass::kHasTClassInit) {
3178  if (cl->fClassInfo) {
3181  } else {
3182 // if (TClassEdit::IsSTLCont(cl->GetName()) {
3183 // There will be an emulated collection proxy, is that the same?
3184 // cl->fState = TClass::kEmulated;
3185 // } else {
3186  if (cl->fStreamerInfo->GetEntries() != 0) {
3187  cl->fState = TClass::kEmulated;
3188  } else {
3190  }
3191 // }
3192  }
3193  }
3194  if (cl->fClassInfo) {
3195  TClass::AddClassToDeclIdMap(((TClingClassInfo*)cl->fClassInfo)->GetDeclId(), cl);
3196  }
3197 }
3198 
3199 ////////////////////////////////////////////////////////////////////////////////
3200 /// Checks if an entity with the specified name is defined in Cling.
3201 /// Returns kFALSE if the entity is not defined.
3202 /// By default, structs, namespaces, classes, enums and unions are looked for.
3203 /// If the flag isClassOrNamespaceOnly is true, classes, structs and
3204 /// namespaces only are considered. I.e. if the name is an enum or a union,
3205 /// the returned value is false.
3206 ///
3207 /// In the case where the class is not loaded and belongs to a namespace
3208 /// or is nested, looking for the full class name is outputting a lots of
3209 /// (expected) error messages. Currently the only way to avoid this is to
3210 /// specifically check that each level of nesting is already loaded.
3211 /// In case of templates the idea is that everything between the outer
3212 /// '<' and '>' has to be skipped, e.g.: aap<pippo<noot>::klaas>::a_class
3213 
3214 Bool_t TCling::CheckClassInfo(const char* name, Bool_t autoload, Bool_t isClassOrNamespaceOnly /* = kFALSE*/ )
3215 {
3217  static const char *anonEnum = "anonymous enum ";
3218  static const int cmplen = strlen(anonEnum);
3219 
3220  if (0 == strncmp(name,anonEnum,cmplen)) {
3221  return kFALSE;
3222  }
3223 
3224  // Avoid the double search below in case the name is a fundamental type
3225  // or typedef to a fundamental type.
3226  THashTable *typeTable = dynamic_cast<THashTable*>( gROOT->GetListOfTypes() );
3227  TDataType *fundType = (TDataType *)typeTable->THashTable::FindObject( name );
3228 
3229  if (fundType && fundType->GetType() < TVirtualStreamerInfo::kObject
3230  && fundType->GetType() > 0) {
3231  // Fundamental type, no a class.
3232  return kFALSE;
3233  }
3234 
3235  // Migrated from within TClass::GetClass
3236  // If we want to know if a class or a namespace with this name exists in the
3237  // interpreter and this is an enum in the type system, before or after loading
3238  // according to the autoload function argument, return false.
3239  if (isClassOrNamespaceOnly &&
3240  TEnum::GetEnum(name, autoload ? TEnum::kAutoload : TEnum::kNone)) return false;
3241 
3242  const char *classname = name;
3243 
3244  int storeAutoload = SetClassAutoloading(autoload);
3245 
3246  // First we want to check whether the decl exist, but _without_
3247  // generating any template instantiation. However, the lookup
3248  // still will create a forward declaration of the class template instance
3249  // if it exist. In this case, the return value of findScope will still
3250  // be zero but the type will be initialized.
3251  // Note in the corresponding code in ROOT 5, CINT was not instantiating
3252  // this forward declaration.
3253  const cling::LookupHelper& lh = fInterpreter->getLookupHelper();
3254  const clang::Type *type = 0;
3255  const clang::Decl *decl
3256  = lh.findScope(classname,
3257  gDebug > 5 ? cling::LookupHelper::WithDiagnostics
3258  : cling::LookupHelper::NoDiagnostics,
3259  &type, /* intantiateTemplate= */ false );
3260  if (!decl) {
3261  std::string buf = TClassEdit::InsertStd(classname);
3262  decl = lh.findScope(buf,
3263  gDebug > 5 ? cling::LookupHelper::WithDiagnostics
3264  : cling::LookupHelper::NoDiagnostics,
3265  &type,false);
3266  }
3267 
3268  if (type) {
3269  // If decl==0 and the type is valid, then we have a forward declaration.
3270  if (!decl) {
3271  // If we have a forward declaration for a class template instantiation,
3272  // we want to ignore it if it was produced/induced by the call to
3273  // findScope, however we can not distinguish those from the
3274  // instantiation induce by 'soft' use (and thus also induce by the
3275  // same underlying code paths)
3276  // ['soft' use = use not requiring a complete definition]
3277  // So to reduce the amount of disruption to the existing code we
3278  // would just ignore those for STL collection, for which we really
3279  // need to have the compiled collection proxy (and thus the TClass
3280  // bootstrap).
3281  clang::ClassTemplateSpecializationDecl *tmpltDecl =
3282  llvm::dyn_cast_or_null<clang::ClassTemplateSpecializationDecl>
3283  (type->getAsCXXRecordDecl());
3284  if (tmpltDecl && !tmpltDecl->getPointOfInstantiation().isValid()) {
3285  // Since the point of instantiation is invalid, we 'guess' that
3286  // the 'instantiation' of the forwarded type appended in
3287  // findscope.
3288  if (ROOT::TMetaUtils::IsSTLCont(*tmpltDecl)) {
3289  // For STL Collection we return false.
3290  SetClassAutoloading(storeAutoload);
3291  return kFALSE;
3292  }
3293  }
3294  }
3295  TClingClassInfo tci(fInterpreter, *type);
3296  if (!tci.IsValid()) {
3297  SetClassAutoloading(storeAutoload);
3298  return kFALSE;
3299  }
3300  auto propertiesMask = isClassOrNamespaceOnly ? kIsClass | kIsStruct | kIsNamespace :
3302 
3303  if (tci.Property() & propertiesMask) {
3304  // We are now sure that the entry is not in fact an autoload entry.
3305  SetClassAutoloading(storeAutoload);
3306  return kTRUE;
3307  }
3308  }
3309 
3310  SetClassAutoloading(storeAutoload);
3311  return (decl);
3312 
3313  // Setting up iterator part of TClingTypedefInfo is too slow.
3314  // Copy the lookup code instead:
3315  /*
3316  TClingTypedefInfo t(fInterpreter, name);
3317  if (t.IsValid() && !(t.Property() & kIsFundamental)) {
3318  delete[] classname;
3319  SetClassAutoloading(storeAutoload);
3320  return kTRUE;
3321  }
3322  */
3323 
3324 // const clang::Decl *decl = lh.findScope(name);
3325 // if (!decl) {
3326 // std::string buf = TClassEdit::InsertStd(name);
3327 // decl = lh.findScope(buf);
3328 // }
3329 
3330 // SetClassAutoloading(storeAutoload);
3331 // return (decl);
3332 }
3333 
3334 ////////////////////////////////////////////////////////////////////////////////
3335 /// Return true if there is a class template by the given name ...
3336 
3338 {
3339  const cling::LookupHelper& lh = fInterpreter->getLookupHelper();
3340  const clang::Decl *decl
3341  = lh.findClassTemplate(name,
3342  gDebug > 5 ? cling::LookupHelper::WithDiagnostics
3343  : cling::LookupHelper::NoDiagnostics);
3344  if (!decl) {
3345  std::string strname = "std::";
3346  strname += name;
3347  decl = lh.findClassTemplate(strname,
3348  gDebug > 5 ? cling::LookupHelper::WithDiagnostics
3349  : cling::LookupHelper::NoDiagnostics);
3350  }
3351  return 0 != decl;
3352 }
3353 
3354 ////////////////////////////////////////////////////////////////////////////////
3355 /// Create list of pointers to base class(es) for TClass cl.
3356 
3358 {
3360  if (cl->fBase) {
3361  return;
3362  }
3364  if (!tci) return;
3366  TList *listOfBase = new TList;
3367  while (t.Next()) {
3368  // if name cannot be obtained no use to put in list
3369  if (t.IsValid() && t.Name()) {
3371  listOfBase->Add(new TBaseClass((BaseClassInfo_t *)a, cl));
3372  }
3373  }
3374  // Now that is complete, publish it.
3375  cl->fBase = listOfBase;
3376 }
3377 
3378 ////////////////////////////////////////////////////////////////////////////////
3379 /// Create list of pointers to enums for TClass cl.
3380 
3381 void TCling::LoadEnums(TListOfEnums& enumList) const
3382 {
3384 
3385  const Decl * D;
3386  TClass* cl = enumList.GetClass();
3387  if (cl) {
3388  D = ((TClingClassInfo*)cl->GetClassInfo())->GetDecl();
3389  }
3390  else {
3391  D = fInterpreter->getCI()->getASTContext().getTranslationUnitDecl();
3392  }
3393  // Iterate on the decl of the class and get the enums.
3394  if (const clang::DeclContext* DC = dyn_cast<clang::DeclContext>(D)) {
3395  cling::Interpreter::PushTransactionRAII deserRAII(fInterpreter);
3396  // Collect all contexts of the namespace.
3397  llvm::SmallVector< DeclContext *, 4> allDeclContexts;
3398  const_cast< clang::DeclContext *>(DC)->collectAllContexts(allDeclContexts);
3399  for (llvm::SmallVector<DeclContext*, 4>::iterator declIter = allDeclContexts.begin(), declEnd = allDeclContexts.end();
3400  declIter != declEnd; ++declIter) {
3401  // Iterate on all decls for each context.
3402  for (clang::DeclContext::decl_iterator DI = (*declIter)->decls_begin(),
3403  DE = (*declIter)->decls_end(); DI != DE; ++DI) {
3404  if (const clang::EnumDecl* ED = dyn_cast<clang::EnumDecl>(*DI)) {
3405  // Get name of the enum type.
3406  std::string buf;
3407  PrintingPolicy Policy(ED->getASTContext().getPrintingPolicy());
3408  llvm::raw_string_ostream stream(buf);
3409  ED->getNameForDiagnostic(stream, Policy, /*Qualified=*/false);
3410  stream.flush();
3411  // If the enum is unnamed we do not add it to the list of enums i.e unusable.
3412  if (!buf.empty()) {
3413  const char* name = buf.c_str();
3414  // Add the enum to the list of loaded enums.
3415  enumList.Get(ED, name);
3416  }
3417  }
3418  }
3419  }
3420  }
3421 }
3422 
3423 ////////////////////////////////////////////////////////////////////////////////
3424 /// Create list of pointers to function templates for TClass cl.
3425 
3427 {
3429 
3430  const Decl * D;
3431  TListOfFunctionTemplates* funcTempList;
3432  if (cl) {
3433  D = ((TClingClassInfo*)cl->GetClassInfo())->GetDecl();
3434  funcTempList = (TListOfFunctionTemplates*)cl->GetListOfFunctionTemplates(false);
3435  }
3436  else {
3437  D = fInterpreter->getCI()->getASTContext().getTranslationUnitDecl();
3438  funcTempList = (TListOfFunctionTemplates*)gROOT->GetListOfFunctionTemplates();
3439  }
3440  // Iterate on the decl of the class and get the enums.
3441  if (const clang::DeclContext* DC = dyn_cast<clang::DeclContext>(D)) {
3442  cling::Interpreter::PushTransactionRAII deserRAII(fInterpreter);
3443  // Collect all contexts of the namespace.
3444  llvm::SmallVector< DeclContext *, 4> allDeclContexts;
3445  const_cast< clang::DeclContext *>(DC)->collectAllContexts(allDeclContexts);
3446  for (llvm::SmallVector<DeclContext*, 4>::iterator declIter = allDeclContexts.begin(),
3447  declEnd = allDeclContexts.end(); declIter != declEnd; ++declIter) {
3448  // Iterate on all decls for each context.
3449  for (clang::DeclContext::decl_iterator DI = (*declIter)->decls_begin(),
3450  DE = (*declIter)->decls_end(); DI != DE; ++DI) {
3451  if (const clang::FunctionTemplateDecl* FTD = dyn_cast<clang::FunctionTemplateDecl>(*DI)) {
3452  funcTempList->Get(FTD);
3453  }
3454  }
3455  }
3456  }
3457 }
3458 ////////////////////////////////////////////////////////////////////////////////
3459 /// Create list of pointers to data members for TClass cl.
3460 /// This is now a nop. The creation and updating is handled in
3461 /// TListOfDataMembers.
3462 
3464 {
3465 }
3466 
3467 ////////////////////////////////////////////////////////////////////////////////
3468 /// Create list of pointers to methods for TClass cl.
3469 /// This is now a nop. The creation and updating is handled in
3470 /// TListOfFunctions.
3471 
3473 {
3474 }
3475 
3476 ////////////////////////////////////////////////////////////////////////////////
3477 /// Update the list of pointers to method for TClass cl
3478 /// This is now a nop. The creation and updating is handled in
3479 /// TListOfFunctions.
3480 
3482 {
3483 }
3484 
3485 ////////////////////////////////////////////////////////////////////////////////
3486 /// Update the list of pointers to data members for TClass cl
3487 /// This is now a nop. The creation and updating is handled in
3488 /// TListOfDataMembers.
3489 
3491 {
3492 }
3493 
3494 ////////////////////////////////////////////////////////////////////////////////
3495 /// Create list of pointers to method arguments for TMethod m.
3496 
3498 {
3500  if (m->fMethodArgs) {
3501  return;
3502  }
3503  m->fMethodArgs = new TList;
3505  while (t.Next()) {
3506  if (t.IsValid()) {
3508  m->fMethodArgs->Add(new TMethodArg((MethodArgInfo_t*)a, m));
3509  }
3510  }
3511 }
3512 
3513 
3514 ////////////////////////////////////////////////////////////////////////////////
3515 /// Generate a TClass for the given class.
3516 /// Since the caller has already check the ClassInfo, let it give use the
3517 /// result (via the value of emulation) rather than recalculate it.
3518 
3519 TClass *TCling::GenerateTClass(const char *classname, Bool_t emulation, Bool_t silent /* = kFALSE */)
3520 {
3521 // For now the following line would lead to the (unwanted) instantiation
3522 // of class template. This could/would need to be resurrected only if
3523 // we re-introduce so sort of automatic instantiation. However this would
3524 // have to include carefull look at the template parameter to avoid
3525 // creating instance we can not really use (if the parameter are only forward
3526 // declaration or do not have all the necessary interfaces).
3527 
3528  // TClingClassInfo tci(fInterpreter, classname);
3529  // if (1 || !tci.IsValid()) {
3530 
3531  Version_t version = 1;
3532  if (TClassEdit::IsSTLCont(classname)) {
3533  version = TClass::GetClass("TVirtualStreamerInfo")->GetClassVersion();
3534  }
3535  TClass *cl = new TClass(classname, version, silent);
3536  if (emulation) {
3538  } else {
3539  // Set the class version if the class is versioned.
3540  // Note that we cannot just call CLASS::Class_Version() as we might not have
3541  // an execution engine (when invoked from rootcling).
3542 
3543  // Do not call cl->GetClassVersion(), it has side effects!
3544  Version_t oldvers = cl->fClassVersion;
3545  if (oldvers == version && cl->GetClassInfo()) {
3546  // We have a version and it might need an update.
3547  Version_t newvers = oldvers;
3549  if (llvm::isa<clang::NamespaceDecl>(cli->GetDecl())) {
3550  // Namespaces don't have class versions.
3551  return cl;
3552  }
3553  TClingMethodInfo mi = cli->GetMethod("Class_Version", "", 0 /*poffset*/,
3556  if (!mi.IsValid()) {
3557  if (cl->TestBit(TClass::kIsTObject)) {
3558  Error("GenerateTClass",
3559  "Cannot find %s::Class_Version()! Class version might be wrong.",
3560  cl->GetName());
3561  }
3562  return cl;
3563  }
3564  newvers = ROOT::TMetaUtils::GetClassVersion(llvm::dyn_cast<clang::RecordDecl>(cli->GetDecl()),
3565  *fInterpreter);
3566  if (newvers == -1) {
3567  // Didn't manage to determine the class version from the AST.
3568  // Use runtime instead.
3569  if ((mi.Property() & kIsStatic)
3570  && !fInterpreter->isInSyntaxOnlyMode()) {
3571  // This better be a static function.
3573  callfunc.SetFunc(&mi);
3574  newvers = callfunc.ExecInt(0);
3575  } else {
3576  Error("GenerateTClass",
3577  "Cannot invoke %s::Class_Version()! Class version might be wrong.",
3578  cl->GetName());
3579  }
3580  }
3581  if (newvers != oldvers) {
3582  cl->fClassVersion = newvers;
3583  cl->fStreamerInfo->Expand(newvers + 2 + 10);
3584  }
3585  }
3586  }
3587 
3588  return cl;
3589 
3590 // } else {
3591 // return GenerateTClass(&tci,silent);
3592 // }
3593 }
3594 
3595 #if 0
3596 ////////////////////////////////////////////////////////////////////////////////
3597 
3598 static void GenerateTClass_GatherInnerIncludes(cling::Interpreter *interp, TString &includes,TClingClassInfo *info)
3599 {
3600  includes += info->FileName();
3601 
3602  const clang::ClassTemplateSpecializationDecl *templateCl
3603  = llvm::dyn_cast<clang::ClassTemplateSpecializationDecl>(info->GetDecl());
3604  if (templateCl) {
3605  for(unsigned int i=0; i < templateCl->getTemplateArgs().size(); ++i) {
3606  const clang::TemplateArgument &arg( templateCl->getTemplateArgs().get(i) );
3607  if (arg.getKind() == clang::TemplateArgument::Type) {
3608  const clang::Type *uType = ROOT::TMetaUtils::GetUnderlyingType( arg.getAsType() );
3609 
3610  if (!uType->isFundamentalType() && !uType->isEnumeralType()) {
3611  // We really need a header file.
3612  const clang::CXXRecordDecl *argdecl = uType->getAsCXXRecordDecl();
3613  if (argdecl) {
3614  includes += ";";
3615  TClingClassInfo subinfo(interp,*(argdecl->getASTContext().getRecordType(argdecl).getTypePtr()));
3616  GenerateTClass_GatherInnerIncludes(interp, includes, &subinfo);
3617  } else {
3618  std::string Result;
3619  llvm::raw_string_ostream OS(Result);
3620  arg.print(argdecl->getASTContext().getPrintingPolicy(),OS);
3621  Warning("TCling::GenerateTClass","Missing header file for %s",OS.str().c_str());
3622  }
3623  }
3624  }
3625  }
3626  }
3627 }
3628 #endif
3629 
3630 ////////////////////////////////////////////////////////////////////////////////
3631 /// Generate a TClass for the given class.
3632 
3633 TClass *TCling::GenerateTClass(ClassInfo_t *classinfo, Bool_t silent /* = kFALSE */)
3634 {
3635  TClingClassInfo *info = (TClingClassInfo*)classinfo;
3636  if (!info || !info->IsValid()) {
3637  Fatal("GenerateTClass","Requires a valid ClassInfo object");
3638  return 0;
3639  }
3640  // We are in the case where we have AST nodes for this class.
3641  TClass *cl = 0;
3642  std::string classname;
3643  info->FullName(classname,*fNormalizedCtxt); // Could we use Name()?
3644  if (TClassEdit::IsSTLCont(classname.c_str())) {
3645 #if 0
3646  Info("GenerateTClass","Will (try to) generate the compiled TClass for %s.",classname.c_str());
3647  // We need to build up the list of required headers, by
3648  // looking at each template arguments.
3649  TString includes;
3650  GenerateTClass_GatherInnerIncludes(fInterpreter,includes,info);
3651 
3652  if (0 == GenerateDictionary(classname.c_str(),includes)) {
3653  // 0 means success.
3654  cl = TClass::LoadClass(classnam.c_str(), silent);
3655  if (cl == 0) {
3656  Error("GenerateTClass","Even though the dictionary generation for %s seemed successful we can't find the TClass bootstrap!",classname.c_str());
3657  }
3658  }
3659 #endif
3660  if (cl == 0) {
3661  int version = TClass::GetClass("TVirtualStreamerInfo")->GetClassVersion();
3662  cl = new TClass(classinfo, version, 0, 0, -1, -1, silent);
3664  }
3665  } else {
3666  // For regular class, just create a TClass on the fly ...
3667  // Not quite useful yet, but that what CINT used to do anyway.
3668  cl = new TClass(classinfo, 1, 0, 0, -1, -1, silent);
3669  }
3670  // Add the new TClass to the map of declid and TClass*.
3671  if (cl) {
3673  }
3674  return cl;
3675 }
3676 
3677 ////////////////////////////////////////////////////////////////////////////////
3678 /// Generate the dictionary for the C++ classes listed in the first
3679 /// argument (in a semi-colon separated list).
3680 /// 'includes' contains a semi-colon separated list of file to
3681 /// #include in the dictionary.
3682 /// For example:
3683 /// ~~~ {.cpp}
3684 /// gInterpreter->GenerateDictionary("vector<vector<float> >;list<vector<float> >","list;vector");
3685 /// ~~~
3686 /// or
3687 /// ~~~ {.cpp}
3688 /// gInterpreter->GenerateDictionary("myclass","myclass.h;myhelper.h");
3689 /// ~~~
3690 
3691 Int_t TCling::GenerateDictionary(const char* classes, const char* includes /* = 0 */, const char* /* options = 0 */)
3692 {
3693  if (classes == 0 || classes[0] == 0) {
3694  return 0;
3695  }
3696  // Split the input list
3697  std::vector<std::string> listClasses;
3698  for (
3699  const char* current = classes, *prev = classes;
3700  *current != 0;
3701  ++current
3702  ) {
3703  if (*current == ';') {
3704  listClasses.push_back(std::string(prev, current - prev));
3705  prev = current + 1;
3706  }
3707  else if (*(current + 1) == 0) {
3708  listClasses.push_back(std::string(prev, current + 1 - prev));
3709  prev = current + 1;
3710  }
3711  }
3712  std::vector<std::string> listIncludes;
3713  for (
3714  const char* current = includes, *prev = includes;
3715  *current != 0;
3716  ++current
3717  ) {
3718  if (*current == ';') {
3719  listIncludes.push_back(std::string(prev, current - prev));
3720  prev = current + 1;
3721  }
3722  else if (*(current + 1) == 0) {
3723  listIncludes.push_back(std::string(prev, current + 1 - prev));
3724  prev = current + 1;
3725  }
3726  }
3727  // Generate the temporary dictionary file
3728  return TCling_GenerateDictionary(listClasses, listIncludes,
3729  std::vector<std::string>(), std::vector<std::string>());
3730 }
3731 
3732 ////////////////////////////////////////////////////////////////////////////////
3733 /// Return pointer to cling Decl of global/static variable that is located
3734 /// at the address given by addr.
3735 
3736 TInterpreter::DeclId_t TCling::GetDataMember(ClassInfo_t *opaque_cl, const char *name) const
3737 {
3739  DeclId_t d;
3740  TClingClassInfo *cl = (TClingClassInfo*)opaque_cl;
3741 
3742  if (cl) {
3743  d = cl->GetDataMember(name);
3744  // We check if the decl of the data member has an annotation which indicates
3745  // an ioname.
3746  // In case this is true, if the name requested is not the ioname, we
3747  // return 0, as if the member did not exist. In some sense we override
3748  // the information in the TClassInfo instance, isolating the typesystem in
3749  // TClass from the one in the AST.
3750  if (const ValueDecl* decl = (const ValueDecl*) d){
3751  std::string ioName;
3752  bool hasIoName = ROOT::TMetaUtils::ExtractAttrPropertyFromName(*decl,"ioname",ioName);
3753  if (hasIoName && ioName != name) return 0;
3754  }
3755  }
3756  else {
3758  d = gcl.GetDataMember(name);
3759  }
3760  return d;
3761 }
3762 
3763 ////////////////////////////////////////////////////////////////////////////////
3764 /// Return pointer to cling Decl of global/static variable that is located
3765 /// at the address given by addr.
3766 
3768 {
3770 
3771  const clang::Decl* possibleEnum = 0;
3772  // FInd the context of the decl.
3773  if (cl) {
3775  if (cci) {
3776  const clang::DeclContext* dc = 0;
3777  if (const clang::Decl* D = cci->GetDecl()) {
3778  if (!(dc = dyn_cast<clang::NamespaceDecl>(D))) {
3779  dc = dyn_cast<clang::RecordDecl>(D);
3780  }
3781  }
3782  if (dc) {
3783  // If it is a data member enum.
3784  possibleEnum = cling::utils::Lookup::Named(&fInterpreter->getSema(), name, dc);
3785  } else {
3786  Error("TCling::GetEnum", "DeclContext not found for %s .\n", name);
3787  }
3788  }
3789  } else {
3790  // If it is a global enum.
3791  possibleEnum = cling::utils::Lookup::Named(&fInterpreter->getSema(), name);
3792  }
3793  if (possibleEnum && (possibleEnum != (clang::Decl*)-1)
3794  && isa<clang::EnumDecl>(possibleEnum)) {
3795  return possibleEnum;
3796  }
3797  return 0;
3798 }
3799 
3800 ////////////////////////////////////////////////////////////////////////////////
3801 /// Return pointer to cling DeclId for a global value
3802 
3803 TInterpreter::DeclId_t TCling::GetDeclId( const llvm::GlobalValue *gv ) const
3804 {
3805  if (!gv) return 0;
3806 
3807  llvm::StringRef mangled_name = gv->getName();
3808 
3809  int err = 0;
3810  char* demangled_name_c = TClassEdit::DemangleName(mangled_name.str().c_str(), err);
3811  if (err) {
3812  if (err == -2) {
3813  // It might simply be an unmangled global name.
3814  DeclId_t d;
3816  d = gcl.GetDataMember(mangled_name.str().c_str());
3817  return d;
3818  }
3819  return 0;
3820  }
3821 
3822  std::string scopename(demangled_name_c);
3823  free(demangled_name_c);
3824 
3825  //
3826  // Separate out the class or namespace part of the
3827  // function name.
3828  //
3829  std::string dataname;
3830 
3831  if (!strncmp(scopename.c_str(), "typeinfo for ", sizeof("typeinfo for ")-1)) {
3832  scopename.erase(0, sizeof("typeinfo for ")-1);
3833  } if (!strncmp(scopename.c_str(), "vtable for ", sizeof("vtable for ")-1)) {
3834  scopename.erase(0, sizeof("vtable for ")-1);
3835  } else {
3836  // See if it is a function
3837  std::string::size_type pos = scopename.rfind('(');
3838  if (pos != std::string::npos) {
3839  return 0;
3840  }
3841  // Separate the scope and member name
3842  pos = scopename.rfind(':');
3843  if (pos != std::string::npos) {
3844  if ((pos != 0) && (scopename[pos-1] == ':')) {
3845  dataname = scopename.substr(pos+1);
3846  scopename.erase(pos-1);
3847  }
3848  } else {
3849  scopename.clear();
3850  dataname = scopename;
3851  }
3852  }
3853  //fprintf(stderr, "name: '%s'\n", name.c_str());
3854  // Now we have the class or namespace name, so do the lookup.
3855 
3856 
3857  DeclId_t d;
3858  if (scopename.size()) {
3859  TClingClassInfo cl(fInterpreter,scopename.c_str());
3860  d = cl.GetDataMember(dataname.c_str());
3861  }
3862  else {
3864  d = gcl.GetDataMember(dataname.c_str());
3865  }
3866  return d;
3867 }
3868 
3869 ////////////////////////////////////////////////////////////////////////////////
3870 /// NOT IMPLEMENTED.
3871 
3873 {
3874  Error("GetDataMemberWithValue()", "not implemented");
3875  return 0;
3876 }
3877 
3878 ////////////////////////////////////////////////////////////////////////////////
3879 /// Return pointer to cling DeclId for a data member with a given name.
3880 
3882 {
3883  // NOT IMPLEMENTED.
3884  Error("GetDataMemberAtAddr()", "not implemented");
3885  return 0;
3886 }
3887 
3888 ////////////////////////////////////////////////////////////////////////////////
3889 /// Return the cling mangled name for a method of a class with parameters
3890 /// params (params is a string of actual arguments, not formal ones). If the
3891 /// class is 0 the global function list will be searched.
3892 
3893 TString TCling::GetMangledName(TClass* cl, const char* method,
3894  const char* params, Bool_t objectIsConst /* = kFALSE */)
3895 {
3898  if (cl) {
3899  Long_t offset;
3900  func.SetFunc((TClingClassInfo*)cl->GetClassInfo(), method, params, objectIsConst,
3901  &offset);
3902  }
3903  else {
3905  Long_t offset;
3906  func.SetFunc(&gcl, method, params, &offset);
3907  }
3909  if (!mi) return "";
3910  TString mangled_name( mi->GetMangledName() );
3911  delete mi;
3912  return mangled_name;
3913 }
3914 
3915 ////////////////////////////////////////////////////////////////////////////////
3916 /// Return the cling mangled name for a method of a class with a certain
3917 /// prototype, i.e. "char*,int,float". If the class is 0 the global function
3918 /// list will be searched.
3919 
3921  const char* proto, Bool_t objectIsConst /* = kFALSE */,
3922  EFunctionMatchMode mode /* = kConversionMatch */)
3923 {
3925  if (cl) {
3926  return ((TClingClassInfo*)cl->GetClassInfo())->
3927  GetMethod(method, proto, objectIsConst, 0 /*poffset*/, mode).GetMangledName();
3928  }
3930  return gcl.GetMethod(method, proto, objectIsConst, 0 /*poffset*/, mode).GetMangledName();
3931 }
3932 
3933 ////////////////////////////////////////////////////////////////////////////////
3934 /// Return pointer to cling interface function for a method of a class with
3935 /// parameters params (params is a string of actual arguments, not formal
3936 /// ones). If the class is 0 the global function list will be searched.
3937 
3938 void* TCling::GetInterfaceMethod(TClass* cl, const char* method,
3939  const char* params, Bool_t objectIsConst /* = kFALSE */)
3940 {
3943  if (cl) {
3944  Long_t offset;
3945  func.SetFunc((TClingClassInfo*)cl->GetClassInfo(), method, params, objectIsConst,
3946  &offset);
3947  }
3948  else {
3950  Long_t offset;
3951  func.SetFunc(&gcl, method, params, &offset);
3952  }
3953  return (void*) func.InterfaceMethod();
3954 }
3955 
3956 ////////////////////////////////////////////////////////////////////////////////
3957 /// Return pointer to cling interface function for a method of a class with
3958 /// a certain name.
3959 
3960 TInterpreter::DeclId_t TCling::GetFunction(ClassInfo_t *opaque_cl, const char* method)
3961 {
3963  DeclId_t f;
3964  TClingClassInfo *cl = (TClingClassInfo*)opaque_cl;
3965  if (cl) {
3966  f = cl->GetMethod(method).GetDeclId();
3967  }
3968  else {
3970  f = gcl.GetMethod(method).GetDeclId();
3971  }
3972  return f;
3973 
3974 }
3975 
3976 ////////////////////////////////////////////////////////////////////////////////
3977 /// Insert overloads of name in cl to res.
3978 
3979 void TCling::GetFunctionOverloads(ClassInfo_t *cl, const char *funcname,
3980  std::vector<DeclId_t>& res) const
3981 {
3982  clang::Sema& S = fInterpreter->getSema();
3983  const clang::Decl* CtxDecl
3984  = cl ? (const clang::Decl*)((TClingClassInfo*)cl)->GetDeclId():
3985  S.Context.getTranslationUnitDecl();
3986  const clang::DeclContext*
3987  DeclCtx = llvm::dyn_cast<const clang::RecordDecl>(CtxDecl);
3988  if (!DeclCtx)
3989  DeclCtx = dyn_cast<clang::NamespaceDecl>(CtxDecl);
3990  if (!DeclCtx) return;
3991  clang::DeclarationName DName
3992  = &S.Context.Idents.get(funcname);
3993  clang::LookupResult R(S, DName, clang::SourceLocation(),
3994  Sema::LookupOrdinaryName, clang::Sema::ForRedeclaration);
3995  S.LookupQualifiedName(R, const_cast<DeclContext*>(DeclCtx));
3996  if (R.empty()) return;
3997  R.resolveKind();
3998  res.reserve(res.size() + (R.end() - R.begin()));
3999  for (clang::LookupResult::iterator IR = R.begin(), ER = R.end();
4000  IR != ER; ++IR) {
4001  if (const clang::FunctionDecl* FD
4002  = llvm::dyn_cast<const clang::FunctionDecl>(*IR)) {
4003  if (!FD->getDescribedFunctionTemplate()) {
4004  res.push_back(FD);
4005  }
4006  }
4007  }
4008 }
4009 
4010 ////////////////////////////////////////////////////////////////////////////////
4011 /// Return pointer to cling interface function for a method of a class with
4012 /// a certain prototype, i.e. "char*,int,float". If the class is 0 the global
4013 /// function list will be searched.
4014 
4015 void* TCling::GetInterfaceMethodWithPrototype(TClass* cl, const char* method,
4016  const char* proto,
4017  Bool_t objectIsConst /* = kFALSE */,
4018  EFunctionMatchMode mode /* = kConversionMatch */)
4019 {
4021  void* f;
4022  if (cl) {
4023  f = ((TClingClassInfo*)cl->GetClassInfo())->
4024  GetMethod(method, proto, objectIsConst, 0 /*poffset*/, mode).InterfaceMethod(*fNormalizedCtxt);
4025  }
4026  else {
4028  f = gcl.GetMethod(method, proto, objectIsConst, 0 /*poffset*/, mode).InterfaceMethod(*fNormalizedCtxt);
4029  }
4030  return f;
4031 }
4032 
4033 ////////////////////////////////////////////////////////////////////////////////
4034 /// Return pointer to cling DeclId for a method of a class with
4035 /// a certain prototype, i.e. "char*,int,float". If the class is 0 the global
4036 /// function list will be searched.
4037 
4038 TInterpreter::DeclId_t TCling::GetFunctionWithValues(ClassInfo_t *opaque_cl, const char* method,
4039  const char* params,
4040  Bool_t objectIsConst /* = kFALSE */)
4041 {
4043  DeclId_t f;
4044  TClingClassInfo *cl = (TClingClassInfo*)opaque_cl;
4045  if (cl) {
4046  f = cl->GetMethodWithArgs(method, params, objectIsConst, 0 /*poffset*/).GetDeclId();
4047  }
4048  else {
4050  f = gcl.GetMethod(method, params, objectIsConst, 0 /*poffset*/).GetDeclId();
4051  }
4052  return f;
4053 }
4054 
4055 ////////////////////////////////////////////////////////////////////////////////
4056 /// Return pointer to cling interface function for a method of a class with
4057 /// a certain prototype, i.e. "char*,int,float". If the class is 0 the global
4058 /// function list will be searched.
4059 
4060 TInterpreter::DeclId_t TCling::GetFunctionWithPrototype(ClassInfo_t *opaque_cl, const char* method,
4061  const char* proto,
4062  Bool_t objectIsConst /* = kFALSE */,
4063  EFunctionMatchMode mode /* = kConversionMatch */)
4064 {
4066  DeclId_t f;
4067  TClingClassInfo *cl = (TClingClassInfo*)opaque_cl;
4068  if (cl) {
4069  f = cl->GetMethod(method, proto, objectIsConst, 0 /*poffset*/, mode).GetDeclId();
4070  }
4071  else {
4073  f = gcl.GetMethod(method, proto, objectIsConst, 0 /*poffset*/, mode).GetDeclId();
4074  }
4075  return f;
4076 }
4077 
4078 ////////////////////////////////////////////////////////////////////////////////
4079 /// Return pointer to cling interface function for a method of a class with
4080 /// a certain name.
4081 
4082 TInterpreter::DeclId_t TCling::GetFunctionTemplate(ClassInfo_t *opaque_cl, const char* name)
4083 {
4085  DeclId_t f;
4086  TClingClassInfo *cl = (TClingClassInfo*)opaque_cl;
4087  if (cl) {
4088  f = cl->GetFunctionTemplate(name);
4089  }
4090  else {
4092  f = gcl.GetFunctionTemplate(name);
4093  }
4094  return f;
4095 
4096 }
4097 
4098 ////////////////////////////////////////////////////////////////////////////////
4099 /// The 'name' is known to the interpreter, this function returns
4100 /// the internal version of this name (usually just resolving typedefs)
4101 /// This is used in particular to synchronize between the name used
4102 /// by rootcling and by the run-time environment (TClass)
4103 /// Return 0 if the name is not known.
4104 
4105 void TCling::GetInterpreterTypeName(const char* name, std::string &output, Bool_t full)
4106 {
4107  output.clear();
4108 
4110 
4111  TClingClassInfo cl(fInterpreter, name);
4112  if (!cl.IsValid()) {
4113  return ;
4114  }
4115  if (full) {
4116  cl.FullName(output,*fNormalizedCtxt);
4117  return;
4118  }
4119  // Well well well, for backward compatibility we need to act a bit too
4120  // much like CINT.
4122  splitname.ShortType(output, TClassEdit::kDropStd );
4123 
4124  return;
4125 }
4126 
4127 ////////////////////////////////////////////////////////////////////////////////
4128 /// Execute a global function with arguments params.
4129 ///
4130 /// FIXME: The cint-based version of this code does not check if the
4131 /// SetFunc() call works, and does not do any real checking
4132 /// for errors from the Exec() call. It did fetch the most
4133 /// recent cint security error and return that in error, but
4134 /// this does not really translate well to cling/clang. We
4135 /// should enhance these interfaces so that we can report
4136 /// compilation and runtime errors properly.
4137 
4138 void TCling::Execute(const char* function, const char* params, int* error)
4139 {
4141  if (error) {
4142  *error = TInterpreter::kNoError;
4143  }
4145  Long_t offset = 0L;
4147  func.SetFunc(&cl, function, params, &offset);
4148  func.Exec(0);
4149 }
4150 
4151 ////////////////////////////////////////////////////////////////////////////////
4152 /// Execute a method from class cl with arguments params.
4153 ///
4154 /// FIXME: The cint-based version of this code does not check if the
4155 /// SetFunc() call works, and does not do any real checking
4156 /// for errors from the Exec() call. It did fetch the most
4157 /// recent cint security error and return that in error, but
4158 /// this does not really translate well to cling/clang. We
4159 /// should enhance these interfaces so that we can report
4160 /// compilation and runtime errors properly.
4161 
4162 void TCling::Execute(TObject* obj, TClass* cl, const char* method,
4163  const char* params, Bool_t objectIsConst, int* error)
4164 {
4166  if (error) {
4167  *error = TInterpreter::kNoError;
4168  }
4169  // If the actual class of this object inherits 2nd (or more) from TObject,
4170  // 'obj' is unlikely to be the start of the object (as described by IsA()),
4171  // hence gInterpreter->Execute will improperly correct the offset.
4172  void* addr = cl->DynamicCast(TObject::Class(), obj, kFALSE);
4173  Long_t offset = 0L;
4175  func.SetFunc((TClingClassInfo*)cl->GetClassInfo(), method, params, objectIsConst, &offset);
4176  void* address = (void*)((Long_t)addr + offset);
4177  func.Exec(address);
4178 }
4179 
4180 ////////////////////////////////////////////////////////////////////////////////
4181 
4182 void TCling::Execute(TObject* obj, TClass* cl, const char* method,
4183  const char* params, int* error)
4184 {
4185  Execute(obj,cl,method,params,false,error);
4186 }
4187 
4188 ////////////////////////////////////////////////////////////////////////////////
4189 /// Execute a method from class cl with the arguments in array params
4190 /// (params[0] ... params[n] = array of TObjString parameters).
4191 /// Convert the TObjArray array of TObjString parameters to a character
4192 /// string of comma separated parameters.
4193 /// The parameters of type 'char' are enclosed in double quotes and all
4194 /// internal quotes are escaped.
4195 
4196 void TCling::Execute(TObject* obj, TClass* cl, TMethod* method,
4197  TObjArray* params, int* error)
4198 {
4199  if (!method) {
4200  Error("Execute", "No method was defined");
4201  return;
4202  }
4203  TList* argList = method->GetListOfMethodArgs();
4204  // Check number of actual parameters against of expected formal ones
4205 
4206  Int_t nparms = argList->LastIndex() + 1;
4207  Int_t argc = params ? params->GetEntries() : 0;
4208 
4209  if (argc > nparms) {
4210  Error("Execute","Too many parameters to call %s, got %d but expected at most %d.",method->GetName(),argc,nparms);
4211  return;
4212  }
4213  if (nparms != argc) {
4214  // Let's see if the 'missing' argument are all defaulted.
4215  // if nparms==0 then either we stopped earlier either argc is also zero and we can't reach here.
4216  assert(nparms > 0);
4217 
4218  TMethodArg *arg = (TMethodArg *) argList->At( 0 );
4219  if (arg && arg->GetDefault() && arg->GetDefault()[0]) {
4220  // There is a default value for the first missing
4221  // argument, so we are fine.
4222  } else {
4223  Int_t firstDefault = -1;
4224  for (Int_t i = 0; i < nparms; i ++) {
4225  arg = (TMethodArg *) argList->At( i );
4226  if (arg && arg->GetDefault() && arg->GetDefault()[0]) {
4227  firstDefault = i;
4228  break;
4229  }
4230  }
4231  if (firstDefault >= 0) {
4232  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);
4233  } else {
4234  Error("Execute","Too few arguments to call %s, got only %d but expected %d.",method->GetName(),argc,nparms);
4235  }
4236  return;
4237  }
4238  }
4239 
4240  const char* listpar = "";
4241  TString complete(10);
4242  if (params) {
4243  // Create a character string of parameters from TObjArray
4244  TIter next(params);
4245  for (Int_t i = 0; i < argc; i ++) {
4246  TMethodArg* arg = (TMethodArg*) argList->At(i);
4248  TObjString* nxtpar = (TObjString*) next();
4249  if (i) {
4250  complete += ',';
4251  }
4252  if (strstr(type.TrueName(*fNormalizedCtxt), "char")) {
4253  TString chpar('\"');
4254  chpar += (nxtpar->String()).ReplaceAll("\"", "\\\"");
4255  // At this point we have to check if string contains \\"
4256  // and apply some more sophisticated parser. Not implemented yet!
4257  complete += chpar;
4258  complete += '\"';
4259  }
4260  else {
4261  complete += nxtpar->String();
4262  }
4263  }
4264  listpar = complete.Data();
4265  }
4266 
4267  // And now execute it.
4269  if (error) {
4270  *error = TInterpreter::kNoError;
4271  }
4272  // If the actual class of this object inherits 2nd (or more) from TObject,
4273  // 'obj' is unlikely to be the start of the object (as described by IsA()),
4274  // hence gInterpreter->Execute will improperly correct the offset.
4275  void* addr = cl->DynamicCast(TObject::Class(), obj, kFALSE);
4277  TClingMethodInfo *minfo = (TClingMethodInfo*)method->fInfo;
4278  func.Init(minfo);
4279  func.SetArgs(listpar);
4280  // Now calculate the 'this' pointer offset for the method
4281  // when starting from the class described by cl.
4282  const CXXMethodDecl * mdecl = dyn_cast<CXXMethodDecl>(minfo->GetMethodDecl());
4283  Long_t offset = ((TClingClassInfo*)cl->GetClassInfo())->GetOffset(mdecl);
4284  void* address = (void*)((Long_t)addr + offset);
4285  func.Exec(address);
4286 }
4287 
4288 ////////////////////////////////////////////////////////////////////////////////
4289 
4290 void TCling::ExecuteWithArgsAndReturn(TMethod* method, void* address,
4291  const void* args[] /*=0*/,
4292  int nargs /*=0*/,
4293  void* ret/*= 0*/) const
4294 {
4295  if (!method) {
4296  Error("ExecuteWithArgsAndReturn", "No method was defined");
4297  return;
4298  }
4299 
4300  TClingMethodInfo* minfo = (TClingMethodInfo*) method->fInfo;
4302  func.ExecWithArgsAndReturn(address, args, nargs, ret);
4303 }
4304 
4305 ////////////////////////////////////////////////////////////////////////////////
4306 /// Execute a cling macro.
4307 
4309 {
4311  fCurExecutingMacros.push_back(filename);
4312  Long_t result = TApplication::ExecuteFile(filename, (int*)error);
4313  fCurExecutingMacros.pop_back();
4314  return result;
4315 }
4316 
4317 ////////////////////////////////////////////////////////////////////////////////
4318 /// Return the file name of the current un-included interpreted file.
4319 /// See the documentation for GetCurrentMacroName().
4320 
4321 const char* TCling::GetTopLevelMacroName() const
4322 {
4323  Warning("GetTopLevelMacroName", "Must change return type!");
4324  return fCurExecutingMacros.back();
4325 }
4326 
4327 ////////////////////////////////////////////////////////////////////////////////
4328 /// Return the file name of the currently interpreted file,
4329 /// included or not. Example to illustrate the difference between
4330 /// GetCurrentMacroName() and GetTopLevelMacroName():
4331 /// ~~~ {.cpp}
4332 /// void inclfile() {
4333 /// std::cout << "In inclfile.C" << std::endl;
4334 /// std::cout << " TCling::GetCurrentMacroName() returns " <<
4335 /// TCling::GetCurrentMacroName() << std::endl;
4336 /// std::cout << " TCling::GetTopLevelMacroName() returns " <<
4337 /// TCling::GetTopLevelMacroName() << std::endl;
4338 /// }
4339 /// ~~~
4340 /// ~~~ {.cpp}
4341 /// void mymacro() {
4342 /// std::cout << "In mymacro.C" << std::endl;
4343 /// std::cout << " TCling::GetCurrentMacroName() returns " <<
4344 /// TCling::GetCurrentMacroName() << std::endl;
4345 /// std::cout << " TCling::GetTopLevelMacroName() returns " <<
4346 /// TCling::GetTopLevelMacroName() << std::endl;
4347 /// std::cout << " Now calling inclfile..." << std::endl;
4348 /// gInterpreter->ProcessLine(".x inclfile.C");;
4349 /// }
4350 /// ~~~
4351 /// Running mymacro.C will print:
4352 ///
4353 /// ~~~ {.cpp}
4354 /// root [0] .x mymacro.C
4355 /// ~~~
4356 /// In mymacro.C
4357 /// ~~~ {.cpp}
4358 /// TCling::GetCurrentMacroName() returns ./mymacro.C
4359 /// TCling::GetTopLevelMacroName() returns ./mymacro.C
4360 /// ~~~
4361 /// Now calling inclfile...
4362 /// In inclfile.h
4363 /// ~~~ {.cpp}
4364 /// TCling::GetCurrentMacroName() returns inclfile.C
4365 /// TCling::GetTopLevelMacroName() returns ./mymacro.C
4366 /// ~~~
4367 
4368 const char* TCling::GetCurrentMacroName() const
4369 {
4370 #if defined(R__MUST_REVISIT)
4371 #if R__MUST_REVISIT(6,0)
4372  Warning("GetCurrentMacroName", "Must change return type!");
4373 #endif
4374 #endif
4375  return fCurExecutingMacros.back();
4376 }
4377 
4378 ////////////////////////////////////////////////////////////////////////////////
4379 /// Return the absolute type of typeDesc.
4380 /// E.g.: typeDesc = "class TNamed**", returns "TNamed".
4381 /// You need to use the result immediately before it is being overwritten.
4382 
4383 const char* TCling::TypeName(const char* typeDesc)
4384 {
4385  TTHREAD_TLS(char*) t = 0;
4386  TTHREAD_TLS(unsigned int) tlen = 0;
4387 
4388  unsigned int dlen = strlen(typeDesc);
4389  if (dlen > tlen) {
4390  delete[] t;
4391  t = new char[dlen + 1];
4392  tlen = dlen;
4393  }
4394  const char* s, *template_start;
4395  if (!strstr(typeDesc, "(*)(")) {
4396  s = strchr(typeDesc, ' ');
4397  template_start = strchr(typeDesc, '<');
4398  if (!strcmp(typeDesc, "long long")) {
4399  strlcpy(t, typeDesc, dlen + 1);
4400  }
4401  else if (!strncmp(typeDesc, "unsigned ", s + 1 - typeDesc)) {
4402  strlcpy(t, typeDesc, dlen + 1);
4403  }
4404  // s is the position of the second 'word' (if any)
4405  // except in the case of templates where there will be a space
4406  // just before any closing '>': eg.
4407  // TObj<std::vector<UShort_t,__malloc_alloc_template<0> > >*
4408  else if (s && (template_start == 0 || (s < template_start))) {
4409  strlcpy(t, s + 1, dlen + 1);
4410  }
4411  else {
4412  strlcpy(t, typeDesc, dlen + 1);
4413  }
4414  }
4415  else {
4416  strlcpy(t, typeDesc, dlen + 1);
4417  }
4418  int l = strlen(t);
4419  while (l > 0 && (t[l - 1] == '*' || t[l - 1] == '&')) {
4420  t[--l] = 0;
4421  }
4422  return t;
4423 }
4424 
4425 ////////////////////////////////////////////////////////////////////////////////
4426 /// Read and parse a rootmapfile in its new format, and return 0 in case of
4427 /// success, -1 if the file has already been read, and -3 in case its format
4428 /// is the old one (e.g. containing "Library.ClassName")
4429 
4430 int TCling::ReadRootmapFile(const char *rootmapfile, TUniqueString *uniqueString)
4431 {
4432  // For "class ", "namespace ", "typedef ", "header ", "enum " respectively
4433  const std::map<char, unsigned int> keyLenMap = {{'c',6},{'n',10},{'t',8},{'h',7},{'e',5}};
4434 
4435  if (rootmapfile && *rootmapfile) {
4436 
4437  // Add content of a specific rootmap file
4438  if (fRootmapFiles->FindObject(rootmapfile)) return -1;
4439  std::ifstream file(rootmapfile);
4440  std::string line; line.reserve(200);
4441  std::string lib_name; line.reserve(100);
4442  bool newFormat=false;
4443  while (getline(file, line, '\n')) {
4444  if (!newFormat &&
4445  (strstr(line.c_str(),"Library.")!=nullptr || strstr(line.c_str(),"Declare.")!=nullptr)) {
4446  file.close();
4447  return -3; // old format
4448  }
4449  newFormat=true;
4450 
4451  if (line.compare(0, 9, "{ decls }") == 0) {
4452  // forward declarations
4453 
4454  while (getline(file, line, '\n')) {
4455  if (line[0] == '[') break;
4456  uniqueString->Append(line);
4457  }
4458  }
4459  const char firstChar=line[0];
4460  if (firstChar == '[') {
4461  // new section (library)
4462  auto brpos = line.find(']');
4463  if (brpos == string::npos) continue;
4464  lib_name = line.substr(1, brpos-1);
4465  size_t nspaces = 0;
4466  while( lib_name[nspaces] == ' ' ) ++nspaces;
4467  if (nspaces) lib_name.replace(0, nspaces, "");
4468  if (gDebug > 3) {
4469  TString lib_nameTstr(lib_name.c_str());
4470  TObjArray* tokens = lib_nameTstr.Tokenize(" ");
4471  const char* lib = ((TObjString *)tokens->At(0))->GetName();
4472  const char* wlib = gSystem->DynamicPathName(lib, kTRUE);
4473  if (wlib) {
4474  Info("ReadRootmapFile", "new section for %s", lib_nameTstr.Data());
4475  }
4476  else {
4477  Info("ReadRootmapFile", "section for %s (library does not exist)", lib_nameTstr.Data());
4478  }
4479  delete[] wlib;
4480  delete tokens;
4481  }
4482  }
4483  else {
4484  auto keyLenIt = keyLenMap.find(firstChar);
4485  if (keyLenIt == keyLenMap.end()) continue;
4486  unsigned int keyLen = keyLenIt->second;
4487  // Do not make a copy, just start after the key
4488  const char *keyname = line.c_str()+keyLen;
4489  if (gDebug > 6)
4490  Info("ReadRootmapFile", "class %s in %s", keyname, lib_name.c_str());
4491  TEnvRec* isThere = fMapfile->Lookup(keyname);
4492  if (isThere){
4493  if(lib_name != isThere->GetValue()){ // the same key for two different libs
4494  if (firstChar == 'n') {
4495  if (gDebug > 3)
4496  Info("ReadRootmapFile", "namespace %s found in %s is already in %s",
4497  keyname, lib_name.c_str(), isThere->GetValue());
4498  } else if (firstChar == 'h'){ // it is a header: add the libname to the list of libs to be loaded.
4499  lib_name+=" ";
4500  lib_name+=isThere->GetValue();
4501  fMapfile->SetValue(keyname, lib_name.c_str());
4502  }
4503  else if (!TClassEdit::IsSTLCont(keyname)) {
4504  Warning("ReadRootmapFile", "%s %s found in %s is already in %s", line.substr(0, keyLen).c_str(),
4505  keyname, lib_name.c_str(), isThere->GetValue());
4506  }
4507  } else { // the same key for the same lib
4508  if (gDebug > 3)
4509  Info("ReadRootmapFile","Key %s was already defined for %s", keyname, lib_name.c_str());
4510  }
4511 
4512  } else {
4513  fMapfile->SetValue(keyname, lib_name.c_str());
4514  }
4515  }
4516  }
4517  file.close();
4518  }
4519 
4520  return 0;
4521 }
4522 
4523 ////////////////////////////////////////////////////////////////////////////////
4524 /// Create a resource table and read the (possibly) three resource files, i.e
4525 /// $ROOTSYS/etc/system<name> (or ROOTETCDIR/system<name>), $HOME/<name> and
4526 /// ./<name>. ROOT always reads ".rootrc" (in TROOT::InitSystem()). You can
4527 /// read additional user defined resource files by creating additional TEnv
4528 /// objects. By setting the shell variable ROOTENV_NO_HOME=1 the reading of
4529 /// the $HOME/<name> resource file will be skipped. This might be useful in
4530 /// case the home directory resides on an automounted remote file system
4531 /// and one wants to avoid the file system from being mounted.
4532 
4534 {
4536 
4537  fMapfile->SetRcName(name);
4538 
4539  TString sname = "system";
4540  sname += name;
4541  char *s = gSystem->ConcatFileName(TROOT::GetEtcDir(), sname);
4542 
4543  Int_t ret = ReadRootmapFile(s);
4544  if (ret == -3) // old format
4546  delete [] s;
4547  if (!gSystem->Getenv("ROOTENV_NO_HOME")) {
4549  ret = ReadRootmapFile(s);
4550  if (ret == -3) // old format
4551  fMapfile->ReadFile(s, kEnvUser);
4552  delete [] s;
4553  if (strcmp(gSystem->HomeDirectory(), gSystem->WorkingDirectory())) {
4554  ret = ReadRootmapFile(name);
4555  if (ret == -3) // old format
4556  fMapfile->ReadFile(name, kEnvLocal);
4557  }
4558  } else {
4559  ret = ReadRootmapFile(name);
4560  if (ret == -3) // old format
4561  fMapfile->ReadFile(name, kEnvLocal);
4562  }
4563  fMapfile->IgnoreDuplicates(ignore);
4564 }
4565 
4566 
4567 namespace {
4568  using namespace clang;
4569 
4570  class ExtVisibleStorageAdder: public RecursiveASTVisitor<ExtVisibleStorageAdder>{
4571  // This class is to be considered an helper for autoloading.
4572  // It is a recursive visitor is used to inspect namespaces coming from
4573  // forward declarations in rootmaps and to set the external visible
4574  // storage flag for them.
4575  public:
4576  ExtVisibleStorageAdder(std::unordered_set<const NamespaceDecl*>& nsSet): fNSSet(nsSet) {};
4577  bool VisitNamespaceDecl(NamespaceDecl* nsDecl) {
4578  // We want to enable the external lookup for this namespace
4579  // because it may shadow the lookup of other names contained
4580  // in that namespace
4581  nsDecl->setHasExternalVisibleStorage();
4582  fNSSet.insert(nsDecl);
4583  return true;
4584  }
4585  private:
4586  std::unordered_set<const NamespaceDecl*>& fNSSet;
4587 
4588  };
4589 }
4590 
4591 ////////////////////////////////////////////////////////////////////////////////
4592 /// Load map between class and library. If rootmapfile is specified a
4593 /// specific rootmap file can be added (typically used by ACLiC).
4594 /// In case of error -1 is returned, 0 otherwise.
4595 /// The interpreter uses this information to automatically load the shared
4596 /// library for a class (autoload mechanism), see the AutoLoad() methods below.
4597 
4598 Int_t TCling::LoadLibraryMap(const char* rootmapfile)
4599 {
4601  // open the [system].rootmap files
4602  if (!fMapfile) {
4603  fMapfile = new TEnv();
4605 // fMapNamespaces = new THashTable();
4606 // fMapNamespaces->SetOwner();
4607  fRootmapFiles = new TObjArray;
4609  InitRootmapFile(".rootmap");
4610  }
4611 
4612  // Prepare a list of all forward declarations for cling
4613  // For some experiments it is easily as big as 500k characters. To be on the
4614  // safe side, we go for 1M.
4615  TUniqueString uniqueString(1048576);
4616 
4617  // Load all rootmap files in the dynamic load path ((DY)LD_LIBRARY_PATH, etc.).
4618  // A rootmap file must end with the string ".rootmap".
4619  TString ldpath = gSystem->GetDynamicPath();
4620  if (ldpath != fRootmapLoadPath) {
4621  fRootmapLoadPath = ldpath;
4622 #ifdef WIN32
4623  TObjArray* paths = ldpath.Tokenize(";");
4624 #else
4625  TObjArray* paths = ldpath.Tokenize(":");
4626 #endif
4627  TString d;
4628  for (Int_t i = 0; i < paths->GetEntriesFast(); i++) {
4629  d = ((TObjString *)paths->At(i))->GetString();
4630  // check if directory already scanned
4631  Int_t skip = 0;
4632  for (Int_t j = 0; j < i; j++) {
4633  TString pd = ((TObjString *)paths->At(j))->GetString();
4634  if (pd == d) {
4635  skip++;
4636  break;
4637  }
4638  }
4639  if (!skip) {
4640  void* dirp = gSystem->OpenDirectory(d);
4641  if (dirp) {
4642  if (gDebug > 3) {
4643  Info("LoadLibraryMap", "%s", d.Data());
4644  }
4645  const char* f1;
4646  while ((f1 = gSystem->GetDirEntry(dirp))) {
4647  TString f = f1;
4648  if (f.EndsWith(".rootmap")) {
4649  TString p;
4650  p = d + "/" + f;
4652  if (!fRootmapFiles->FindObject(f) && f != ".rootmap") {
4653  if (gDebug > 4) {
4654  Info("LoadLibraryMap", " rootmap file: %s", p.Data());
4655  }
4656  Int_t ret = ReadRootmapFile(p,&uniqueString);
4657  if (ret == 0)
4658  fRootmapFiles->Add(new TNamed(gSystem->BaseName(f), p.Data()));
4659  if (ret == -3) {
4660  // old format
4662  fRootmapFiles->Add(new TNamed(f, p));
4663  }
4664  }
4665  // else {
4666  // fprintf(stderr,"Reject %s because %s is already there\n",p.Data(),f.Data());
4667  // fRootmapFiles->FindObject(f)->ls();
4668  // }
4669  }
4670  }
4671  if (f.BeginsWith("rootmap")) {
4672  TString p;
4673  p = d + "/" + f;
4674  FileStat_t stat;
4675  if (gSystem->GetPathInfo(p, stat) == 0 && R_ISREG(stat.fMode)) {
4676  Warning("LoadLibraryMap", "please rename %s to end with \".rootmap\"", p.Data());
4677  }
4678  }
4679  }
4680  }
4681  gSystem->FreeDirectory(dirp);
4682  }
4683  }
4684  delete paths;
4685  if (!fMapfile->GetTable()->GetEntries()) {
4686  return -1;
4687  }
4688  }
4689  if (rootmapfile && *rootmapfile) {
4690  Int_t res = ReadRootmapFile(rootmapfile, &uniqueString);
4691  if (res == 0) {
4692  //TString p = gSystem->ConcatFileName(gSystem->pwd(), rootmapfile);
4693  //fRootmapFiles->Add(new TNamed(gSystem->BaseName(rootmapfile), p.Data()));
4694  fRootmapFiles->Add(new TNamed(gSystem->BaseName(rootmapfile), rootmapfile));
4695  }
4696  else if (res == -3) {
4697  // old format
4699  fMapfile->ReadFile(rootmapfile, kEnvGlobal);
4700  fRootmapFiles->Add(new TNamed(gSystem->BaseName(rootmapfile), rootmapfile));
4701  fMapfile->IgnoreDuplicates(ignore);
4702  }
4703  }
4704  TEnvRec* rec;
4705  TIter next(fMapfile->GetTable());
4706  while ((rec = (TEnvRec*) next())) {
4707  TString cls = rec->GetName();
4708  if (!strncmp(cls.Data(), "Library.", 8) && cls.Length() > 8) {
4709  // get the first lib from the list of lib and dependent libs
4710  TString libs = rec->GetValue();
4711  if (libs == "") {
4712  continue;
4713  }
4714  TString delim(" ");
4715  TObjArray* tokens = libs.Tokenize(delim);
4716  const char* lib = ((TObjString*)tokens->At(0))->GetName();
4717  // convert "@@" to "::", we used "@@" because TEnv
4718  // considers "::" a terminator
4719  cls.Remove(0, 8);
4720  cls.ReplaceAll("@@", "::");
4721  // convert "-" to " ", since class names may have
4722  // blanks and TEnv considers a blank a terminator
4723  cls.ReplaceAll("-", " ");
4724  if (gDebug > 6) {
4725  const char* wlib = gSystem->DynamicPathName(lib, kTRUE);
4726  if (wlib) {
4727  Info("LoadLibraryMap", "class %s in %s", cls.Data(), wlib);
4728  }
4729  else {
4730  Info("LoadLibraryMap", "class %s in %s (library does not exist)", cls.Data(), lib);
4731  }
4732  delete[] wlib;
4733  }
4734  // Fill in the namespace candidate list
4735 // Ssiz_t last = cls.Last(':');
4736 // if (last != kNPOS) {
4737 // // Please note that the funny op overload does substring.
4738 // TString namespaceCand = cls(0, last - 1);
4739 // // This is a reference to a substring that lives in fMapfile
4740 // if (!fMapNamespaces->FindObject(namespaceCand.Data()))
4741 // fMapNamespaces->Add(new TNamed(namespaceCand.Data(), ""));
4742 // }
4743  delete tokens;
4744  }
4745  else if (!strncmp(cls.Data(), "Declare.", 8) && cls.Length() > 8) {
4746  cls.Remove(0, 8);
4747  // convert "-" to " ", since class names may have
4748  // blanks and TEnv considers a blank a terminator
4749  cls.ReplaceAll("-", " ");
4750  fInterpreter->declare(cls.Data());
4751  }
4752  }
4753 
4754  // Process the forward declarations collected
4755  cling::Transaction* T = nullptr;
4756  auto compRes= fInterpreter->declare(uniqueString.Data(), &T);
4757  assert(cling::Interpreter::kSuccess == compRes && "A declaration in a rootmap could not be compiled");
4758 
4759  if (compRes!=cling::Interpreter::kSuccess){
4760  Warning("LoadLibraryMap",
4761  "Problems in %s declaring '%s' were encountered.", rootmapfile, uniqueString.Data()) ;
4762  }
4763 
4764  if (T){
4765  ExtVisibleStorageAdder evsAdder(fNSFromRootmaps);
4766  for (auto declIt = T->decls_begin(); declIt < T->decls_end(); ++declIt) {
4767  if (declIt->m_DGR.isSingleDecl()) {
4768  if (Decl* D = declIt->m_DGR.getSingleDecl()) {
4769  if (NamespaceDecl* NSD = dyn_cast<NamespaceDecl>(D)) {
4770  evsAdder.TraverseDecl(NSD);
4771  }
4772  }
4773  }
4774  }
4775  }
4776 
4777  // clear duplicates
4778 
4779  return 0;
4780 }
4781 
4782 ////////////////////////////////////////////////////////////////////////////////
4783 /// Scan again along the dynamic path for library maps. Entries for the loaded
4784 /// shared libraries are unloaded first. This can be useful after reseting
4785 /// the dynamic path through TSystem::SetDynamicPath()
4786 /// In case of error -1 is returned, 0 otherwise.
4787 
4789 {
4791  LoadLibraryMap();
4792  return 0;
4793 }
4794 
4795 ////////////////////////////////////////////////////////////////////////////////
4796 /// Reload the library map entries coming from all the loaded shared libraries,
4797 /// after first unloading the current ones.
4798 /// In case of error -1 is returned, 0 otherwise.
4799 
4801 {
4802  const TString sharedLibLStr = GetSharedLibs();
4803  const TObjArray* sharedLibL = sharedLibLStr.Tokenize(" ");
4804  const Int_t nrSharedLibs = sharedLibL->GetEntriesFast();
4805  for (Int_t ilib = 0; ilib < nrSharedLibs; ilib++) {
4806  const TString sharedLibStr = ((TObjString*)sharedLibL->At(ilib))->GetString();
4807  const TString sharedLibBaseStr = gSystem->BaseName(sharedLibStr);
4808  const Int_t ret = UnloadLibraryMap(sharedLibBaseStr);
4809  if (ret < 0) {
4810  continue;
4811  }
4812  TString rootMapBaseStr = sharedLibBaseStr;
4813  if (sharedLibBaseStr.EndsWith(".dll")) {
4814  rootMapBaseStr.ReplaceAll(".dll", "");
4815  }
4816  else if (sharedLibBaseStr.EndsWith(".DLL")) {
4817  rootMapBaseStr.ReplaceAll(".DLL", "");
4818  }
4819  else if (sharedLibBaseStr.EndsWith(".so")) {
4820  rootMapBaseStr.ReplaceAll(".so", "");
4821  }
4822  else if (sharedLibBaseStr.EndsWith(".sl")) {
4823  rootMapBaseStr.ReplaceAll(".sl", "");
4824  }
4825  else if (sharedLibBaseStr.EndsWith(".dl")) {
4826  rootMapBaseStr.ReplaceAll(".dl", "");
4827  }
4828  else if (sharedLibBaseStr.EndsWith(".a")) {
4829  rootMapBaseStr.ReplaceAll(".a", "");
4830  }
4831  else {
4832  Error("ReloadAllSharedLibraryMaps", "Unknown library type %s", sharedLibBaseStr.Data());
4833  delete sharedLibL;
4834  return -1;
4835  }
4836  rootMapBaseStr += ".rootmap";
4837  const char* rootMap = gSystem->Which(gSystem->GetDynamicPath(), rootMapBaseStr);
4838  if (!rootMap) {
4839  Error("ReloadAllSharedLibraryMaps", "Could not find rootmap %s in path", rootMap);
4840  delete[] rootMap;
4841  delete sharedLibL;
4842  return -1;
4843  }
4844  const Int_t status = LoadLibraryMap(rootMap);
4845  if (status < 0) {
4846  Error("ReloadAllSharedLibraryMaps", "Error loading map %s", rootMap);
4847  delete[] rootMap;
4848  delete sharedLibL;
4849  return -1;
4850  }
4851  delete[] rootMap;
4852  }
4853  delete sharedLibL;
4854  return 0;
4855 }
4856 
4857 ////////////////////////////////////////////////////////////////////////////////
4858 /// Unload the library map entries coming from all the loaded shared libraries.
4859 /// Returns 0 if succesful
4860 
4862 {
4863  const TString sharedLibLStr = GetSharedLibs();
4864  const TObjArray* sharedLibL = sharedLibLStr.Tokenize(" ");
4865  for (Int_t ilib = 0; ilib < sharedLibL->GetEntriesFast(); ilib++) {
4866  const TString sharedLibStr = ((TObjString*)sharedLibL->At(ilib))->GetString();
4867  const TString sharedLibBaseStr = gSystem->BaseName(sharedLibStr);
4868  UnloadLibraryMap(sharedLibBaseStr);
4869  }
4870  delete sharedLibL;
4871  return 0;
4872 }
4873 
4874 ////////////////////////////////////////////////////////////////////////////////
4875 /// Unload library map entries coming from the specified library.
4876 /// Returns -1 in case no entries for the specified library were found,
4877 /// 0 otherwise.
4878 
4879 Int_t TCling::UnloadLibraryMap(const char* library)
4880 {
4881  if (!fMapfile || !library || !*library) {
4882  return 0;
4883  }
4884  TString libname(library);
4885  Ssiz_t idx = libname.Last('.');
4886  if (idx != kNPOS) {
4887  libname.Remove(idx);
4888  }
4889  size_t len = libname.Length();
4890  TEnvRec *rec;
4891  TIter next(fMapfile->GetTable());
4893  Int_t ret = 0;
4894  while ((rec = (TEnvRec *) next())) {
4895  TString cls = rec->GetName();
4896  if (cls.Length() > 2) {
4897  // get the first lib from the list of lib and dependent libs
4898  TString libs = rec->GetValue();
4899  if (libs == "") {
4900  continue;
4901  }
4902  TString delim(" ");
4903  TObjArray* tokens = libs.Tokenize(delim);
4904  const char* lib = ((TObjString *)tokens->At(0))->GetName();
4905  if (!strncmp(cls.Data(), "Library.", 8) && cls.Length() > 8) {
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  }
4914  if (!strncmp(lib, libname.Data(), len)) {
4915  if (fMapfile->GetTable()->Remove(rec) == 0) {
4916  Error("UnloadLibraryMap", "entry for <%s, %s> not found in library map table", cls.Data(), lib);
4917  ret = -1;
4918  }
4919  }
4920  delete tokens;
4921  }
4922  }
4923  if (ret >= 0) {
4924  TString library_rootmap(library);
4925  if (!library_rootmap.EndsWith(".rootmap"))
4926  library_rootmap.Append(".rootmap");
4927  TNamed* mfile = 0;
4928  while ((mfile = (TNamed *)fRootmapFiles->FindObject(library_rootmap))) {
4929  fRootmapFiles->Remove(mfile);
4930  delete mfile;
4931  }
4933  }
4934  return ret;
4935 }
4936 
4937 ////////////////////////////////////////////////////////////////////////////////
4938 /// Register the autoloading information for a class.
4939 /// libs is a space separated list of libraries.
4940 
4941 Int_t TCling::SetClassSharedLibs(const char *cls, const char *libs)
4942 {
4943  if (!cls || !*cls)
4944  return 0;
4945 
4946  TString key = TString("Library.") + cls;
4947  // convert "::" to "@@", we used "@@" because TEnv
4948  // considers "::" a terminator
4949  key.ReplaceAll("::", "@@");
4950  // convert "-" to " ", since class names may have
4951  // blanks and TEnv considers a blank a terminator
4952  key.ReplaceAll(" ", "-");
4953 
4955  if (!fMapfile) {
4956  fMapfile = new TEnv();
4958 // fMapNamespaces = new THashTable();
4959 // fMapNamespaces->SetOwner();
4960 
4961  fRootmapFiles = new TObjArray;
4963 
4964  InitRootmapFile(".rootmap");
4965  }
4966  //fMapfile->SetValue(key, libs);
4967  fMapfile->SetValue(cls, libs);
4968  return 1;
4969 }
4970 
4971 ////////////////////////////////////////////////////////////////////////////////
4972 /// Demangle the name (from the typeinfo) and then request the class
4973 /// via the usual name based interface (TClass::GetClass).
4974 
4975 TClass *TCling::GetClass(const std::type_info& typeinfo, Bool_t load) const
4976 {
4977  int err = 0;
4978  char* demangled_name = TClassEdit::DemangleTypeIdName(typeinfo, err);
4979  if (err) return 0;
4980  TClass* theClass = TClass::GetClass(demangled_name, load, kTRUE);
4981  free(demangled_name);
4982  return theClass;
4983 }
4984 
4985 ////////////////////////////////////////////////////////////////////////////////
4986 /// Load library containing the specified class. Returns 0 in case of error
4987 /// and 1 in case if success.
4988 
4989 Int_t TCling::AutoLoad(const std::type_info& typeinfo, Bool_t knowDictNotLoaded /* = kFALSE */)
4990 {
4991  int err = 0;
4992  char* demangled_name_c = TClassEdit::DemangleTypeIdName(typeinfo, err);
4993  if (err) {
4994  return 0;
4995  }
4996 
4997  std::string demangled_name(demangled_name_c);
4998  free(demangled_name_c);
4999 
5000  // AutoLoad expects (because TClass::GetClass already prepares it that way) a
5001  // shortened name.
5002  TClassEdit::TSplitType splitname( demangled_name.c_str(), (TClassEdit::EModType)(TClassEdit::kLong64 | TClassEdit::kDropStd) );
5003  splitname.ShortType(demangled_name, TClassEdit::kDropStlDefault | TClassEdit::kDropStd);
5004 
5005  // No need to worry about typedef, they aren't any ... but there are
5006  // inlined namespaces ...
5007 
5008  Int_t result = AutoLoad(demangled_name.c_str());
5009  if (result == 0) {
5010  demangled_name = TClassEdit::GetLong64_Name(demangled_name);
5011  result = AutoLoad(demangled_name.c_str(), knowDictNotLoaded);
5012  }
5013 
5014  return result;
5015 }
5016 
5017 ////////////////////////////////////////////////////////////////////////////////
5018 /// Load library containing the specified class. Returns 0 in case of error
5019 /// and 1 in case if success.
5020 
5021 Int_t TCling::AutoLoad(const char *cls, Bool_t knowDictNotLoaded /* = kFALSE */)
5022 {
5024 
5025  if (!knowDictNotLoaded && gClassTable->GetDictNorm(cls)) {
5026  // The library is already loaded as the class's dictionary is known.
5027  // Return success.
5028  // Note: the name (cls) is expected to be normalized as it comes either
5029  // from a callbacks (that can/should calculate the normalized name from the
5030  // decl) or from TClass::GetClass (which does also calculate the normalized
5031  // name).
5032  return 1;
5033  }
5034 
5035  if (gDebug > 2) {
5036  Info("TCling::AutoLoad",
5037  "Trying to autoload for %s", cls);
5038  }
5039 
5040  Int_t status = 0;
5041  if (!gROOT || !gInterpreter || gROOT->TestBit(TObject::kInvalidObject)) {
5042  if (gDebug > 2) {
5043  Info("TCling::AutoLoad",
5044  "Disabled due to gROOT or gInterpreter being invalid/not ready (the class name is %s)", cls);
5045  }
5046  return status;
5047  }
5048  if (!fAllowLibLoad) {
5049  // Never load any library from rootcling/genreflex.
5050  if (gDebug > 2) {
5051  Info("TCling::AutoLoad",
5052  "Explicitly disabled (the class name is %s)", cls);
5053  }
5054  return 0;
5055  }
5056  // Prevent the recursion when the library dictionary are loaded.
5057  Int_t oldvalue = SetClassAutoloading(false);
5058  // Try using externally provided callback first.
5059  if (fAutoLoadCallBack) {
5060  int success = (*(AutoLoadCallBack_t)fAutoLoadCallBack)(cls);
5061  if (success) {
5062  SetClassAutoloading(oldvalue);
5063  return success;
5064  }
5065  }
5066  // lookup class to find list of dependent libraries
5067  TString deplibs = GetClassSharedLibs(cls);
5068  if (!deplibs.IsNull()) {
5069  TString delim(" ");
5070  TObjArray* tokens = deplibs.Tokenize(delim);
5071  for (Int_t i = (tokens->GetEntriesFast() - 1); i > 0; --i) {
5072  const char* deplib = ((TObjString*)tokens->At(i))->GetName();
5073  if (gROOT->LoadClass(cls, deplib) == 0) {
5074  if (gDebug > 0) {
5075  Info("TCling::AutoLoad",
5076  "loaded dependent library %s for %s", deplib, cls);
5077  }
5078  }
5079  else {
5080  Error("TCling::AutoLoad",
5081  "failure loading dependent library %s for %s",
5082  deplib, cls);
5083  }
5084  }
5085  const char* lib = ((TObjString*)tokens->At(0))->GetName();
5086  if (lib && lib[0]) {
5087  if (gROOT->LoadClass(cls, lib) == 0) {
5088  if (gDebug > 0) {
5089  Info("TCling::AutoLoad",
5090  "loaded library %s for %s", lib, cls);
5091  }
5092  status = 1;
5093  }
5094  else {
5095  Error("TCling::AutoLoad",
5096  "failure loading library %s for %s", lib, cls);
5097  }
5098  }
5099  delete tokens;
5100  }
5101 
5102  SetClassAutoloading(oldvalue);
5103  return status;
5104 }
5105 
5106 ////////////////////////////////////////////////////////////////////////////////
5107 /// Parse the payload or header.
5108 
5109 static cling::Interpreter::CompilationResult ExecAutoParse(const char *what,
5110  Bool_t header,
5111  cling::Interpreter *interpreter)
5112 {
5113  // Save state of the PP
5114  Sema &SemaR = interpreter->getSema();
5115  ASTContext& C = SemaR.getASTContext();
5116  Preprocessor &PP = SemaR.getPreprocessor();
5117  Parser& P = const_cast<Parser&>(interpreter->getParser());
5118  Preprocessor::CleanupAndRestoreCacheRAII cleanupRAII(PP);
5119  Parser::ParserCurTokRestoreRAII savedCurToken(P);
5120  // After we have saved the token reset the current one to something which
5121  // is safe (semi colon usually means empty decl)
5122  Token& Tok = const_cast<Token&>(P.getCurToken());
5123  Tok.setKind(tok::semi);
5124 
5125  // We can't PushDeclContext, because we go up and the routine that pops
5126  // the DeclContext assumes that we drill down always.
5127  // We have to be on the global context. At that point we are in a
5128  // wrapper function so the parent context must be the global.
5129  Sema::ContextAndScopeRAII pushedDCAndS(SemaR, C.getTranslationUnitDecl(),
5130  SemaR.TUScope);
5131  std::string code = gNonInterpreterClassDef ;
5132  if (!header) {
5133  // This is the complete header file content and not the
5134  // name of a header.
5135  code += what;
5136 
5137  } else {
5138  code += ("#include \"");
5139  code += what;
5140  code += "\"\n";
5141  }
5142  code += ("#ifdef __ROOTCLING__\n"
5143  "#undef __ROOTCLING__\n"
5144  + gInterpreterClassDef +
5145  "#endif");
5146 
5147  cling::Interpreter::CompilationResult cr;
5148  {
5149  // scope within which diagnostics are de-activated
5150  // For now we disable diagnostics because we saw them already at
5151  // dictionary generation time. That won't be an issue with the PCMs.
5152 
5153  clangDiagSuppr diagSuppr(SemaR.getDiagnostics());
5154 
5155  #if defined(R__MUST_REVISIT)
5156  #if R__MUST_REVISIT(6,2)
5157  Warning("TCling::RegisterModule","Diagnostics suppression should be gone by now.");
5158  #endif
5159  #endif
5160 
5161  cr = interpreter->parseForModule(code);
5162  }
5163  return cr;
5164 }
5165 
5166 ////////////////////////////////////////////////////////////////////////////////
5167 /// Helper routine for TCling::AutoParse implementing the actual call to the
5168 /// parser and looping over template parameters (if
5169 /// any) and when they don't have a registered header to autoparse,
5170 /// recurse over their template parameters.
5171 ///
5172 /// Returns the number of header parsed.
5173 
5174 UInt_t TCling::AutoParseImplRecurse(const char *cls, bool topLevel)
5175 {
5176  // We assume the lock has already been taken.
5177  // R__LOCKGUARD(gInterpreterMutex);
5178 
5179  Int_t nHheadersParsed = 0;
5180 
5181  // Loop on the possible autoparse keys
5182  bool skipFirstEntry = false;
5183  std::vector<std::string> autoparseKeys;
5184  if (strchr(cls, '<')) {
5185  int nestedLoc = 0;
5186  TClassEdit::GetSplit(cls, autoparseKeys, nestedLoc, TClassEdit::kDropTrailStar);
5187  // Check if we can skip the name of the template in the autoparses
5188  // Take all the scopes one by one. If all of them are in the AST, we do not
5189  // need to autoparse for that particular template.
5190  if (!autoparseKeys.empty()){
5191  TString templateName(autoparseKeys[0]);
5192  auto tokens = templateName.Tokenize("::");
5193  clang::NamedDecl* previousScopeAsNamedDecl = nullptr;
5194  clang::DeclContext* previousScopeAsContext = nullptr;
5195  for (auto const & scopeObj : *tokens){
5196  auto scopeName = ((TObjString*) scopeObj)->String().Data();
5197  previousScopeAsNamedDecl = cling::utils::Lookup::Named(&fInterpreter->getSema(), scopeName, previousScopeAsContext);
5198  // Check if we have multiple nodes in the AST with this name
5199  if ((clang::NamedDecl*)-1 == previousScopeAsNamedDecl) break;
5200  previousScopeAsContext = llvm::dyn_cast_or_null<clang::DeclContext>(previousScopeAsNamedDecl);
5201  if (!previousScopeAsContext) break; // this is not a context
5202  }
5203  delete tokens;
5204  // Now, let's check if the last scope, the template, has a definition, i.e. it's not a fwd decl
5205  if (auto templateDecl = llvm::dyn_cast_or_null<clang::ClassTemplateDecl>(previousScopeAsNamedDecl)) {
5206  if (auto templatedDecl = templateDecl->getTemplatedDecl()) {
5207  skipFirstEntry = nullptr != templatedDecl->getDefinition();
5208  }
5209  }
5210 
5211  }
5212  }
5213  if (topLevel) autoparseKeys.emplace_back(cls);
5214 
5215  for (const auto & apKeyStr : autoparseKeys) {
5216  if (skipFirstEntry) {
5217  skipFirstEntry=false;
5218  continue;
5219  }
5220  if (apKeyStr.empty()) continue;
5221  const char *apKey = apKeyStr.c_str();
5222  std::size_t normNameHash(fStringHashFunction(apKey));
5223  // If the class was not looked up
5224  if (gDebug > 1) {
5225  Info("TCling::AutoParse",
5226  "Starting autoparse for %s\n", apKey);
5227  }
5228  if (fLookedUpClasses.insert(normNameHash).second) {
5229  auto const &iter = fClassesHeadersMap.find(normNameHash);
5230  if (iter != fClassesHeadersMap.end()) {
5231  const cling::Transaction *T = fInterpreter->getCurrentTransaction();
5232  fTransactionHeadersMap.insert({T,normNameHash});
5233  auto const &hNamesPtrs = iter->second;
5234  if (gDebug > 1) {
5235  Info("TCling::AutoParse",
5236  "We can proceed for %s. We have %s headers.", apKey, std::to_string(hNamesPtrs.size()).c_str());
5237  }
5238  for (auto & hName : hNamesPtrs) {
5239  if (fParsedPayloadsAddresses.count(hName) == 1) continue;
5240  if (0 != fPayloads.count(normNameHash)) {
5241  float initRSSval=0.f, initVSIZEval=0.f;
5242  (void) initRSSval; // Avoid unused var warning
5243  (void) initVSIZEval;
5244  if (gDebug > 0) {
5245  Info("AutoParse",
5246  "Parsing full payload for %s", apKey);
5247  ProcInfo_t info;
5248  gSystem->GetProcInfo(&info);
5249  initRSSval = 1e-3*info.fMemResident;
5250  initVSIZEval = 1e-3*info.fMemVirtual;
5251  }
5252  auto cRes = ExecAutoParse(hName, kFALSE, fInterpreter);
5253  if (cRes != cling::Interpreter::kSuccess) {
5254  if (hName[0] == '\n')
5255  Error("AutoParse", "Error parsing payload code for class %s with content:\n%s", apKey, hName);
5256  } else {
5257  fParsedPayloadsAddresses.insert(hName);
5258  nHheadersParsed++;
5259  if (gDebug > 0){
5260  ProcInfo_t info;
5261  gSystem->GetProcInfo(&info);
5262  float endRSSval = 1e-3*info.fMemResident;
5263  float endVSIZEval = 1e-3*info.fMemVirtual;
5264  Info("Autoparse", ">>> RSS key %s - before %.3f MB - after %.3f MB - delta %.3f MB", apKey, initRSSval, endRSSval, endRSSval-initRSSval);
5265  Info("Autoparse", ">>> VSIZE key %s - before %.3f MB - after %.3f MB - delta %.3f MB", apKey, initVSIZEval, endVSIZEval, endVSIZEval-initVSIZEval);
5266  }
5267  }
5268  } else if (!IsLoaded(hName)) {
5269  if (gDebug > 0) {
5270  Info("AutoParse",
5271  "Parsing single header %s", hName);
5272  }
5273  auto cRes = ExecAutoParse(hName, kTRUE, fInterpreter);
5274  if (cRes != cling::Interpreter::kSuccess) {
5275  Error("AutoParse", "Error parsing headerfile %s for class %s.", hName, apKey);
5276  } else {
5277  nHheadersParsed++;
5278  }
5279  }
5280  }
5281  }
5282  else {
5283  // There is no header registered for this class, if this a
5284  // template, it will be instantiated if/when it is requested
5285  // and if we do no load/parse its components we might end up
5286  // not using an eventual specialization.
5287  if (strchr(apKey, '<')) {
5288  nHheadersParsed += AutoParseImplRecurse(apKey, false);
5289  }
5290  }
5291  }
5292  }
5293 
5294  return nHheadersParsed;
5295 
5296 }
5297 
5298 ////////////////////////////////////////////////////////////////////////////////
5299 /// Parse the headers relative to the class
5300 /// Returns 1 in case of success, 0 in case of failure
5301 
5302 Int_t TCling::AutoParse(const char *cls)
5303 {
5305 
5308  return AutoLoad(cls);
5309  } else {
5310  return 0;
5311  }
5312  }
5313 
5314  if (gDebug > 1) {
5315  Info("TCling::AutoParse",
5316  "Trying to autoparse for %s", cls);
5317  }
5318 
5319  // The catalogue of headers is in the dictionary
5321  AutoLoad(cls);
5322  }
5323 
5324  // Prevent the recursion when the library dictionary are loaded.
5325  Int_t oldAutoloadValue = SetClassAutoloading(false);
5326 
5327  // No recursive header parsing on demand; we require headers to be standalone.
5328  SuspendAutoParsing autoParseRAII(this);
5329 
5330  Int_t nHheadersParsed = AutoParseImplRecurse(cls,/*topLevel=*/ true);
5331 
5332  if (nHheadersParsed != 0) {
5333  while (!fClassesToUpdate.empty()) {
5334  TClass *oldcl = fClassesToUpdate.back().first;
5335  if (oldcl->GetState() != TClass::kHasTClassInit) {
5336  // if (gDebug > 2) Info("RegisterModule", "Forcing TClass init for %s", oldcl->GetName());
5337  DictFuncPtr_t dict = fClassesToUpdate.back().second;
5338  fClassesToUpdate.pop_back();
5339  // Calling func could manipulate the list so, let maintain the list
5340  // then call the dictionary function.
5341  TClass *ncl = dict();
5342  if (ncl) ncl->PostLoadCheck();
5343  } else {
5344  fClassesToUpdate.pop_back();
5345  }
5346  }
5347  }
5348 
5349  SetClassAutoloading(oldAutoloadValue);
5350 
5351  return nHheadersParsed > 0 ? 1 : 0;
5352 }
5353 
5354 
5355 ////////////////////////////////////////////////////////////////////////////////
5356 /// Autoload a library based on a missing symbol.
5357 
5358 void* TCling::LazyFunctionCreatorAutoload(const std::string& mangled_name) {
5359  // First see whether the symbol is in the library that we are currently
5360  // loading. It will have access to the symbols of its dependent libraries,
5361  // thus checking "back()" is sufficient.
5362  if (!fRegisterModuleDyLibs.empty()) {
5363  if (void* addr = dlsym(fRegisterModuleDyLibs.back(),
5364  mangled_name.c_str())) {
5365  return addr;
5366  }
5367  }
5368 
5369  int err = 0;
5370  char* demangled_name_c = TClassEdit::DemangleName(mangled_name.c_str(), err);
5371  if (err) {
5372  return 0;
5373  }
5374 
5375  std::string name(demangled_name_c);
5376  free(demangled_name_c);
5377 
5378  //fprintf(stderr, "demangled name: '%s'\n", demangled_name);
5379  //
5380  // Separate out the class or namespace part of the
5381  // function name.
5382  //
5383 
5384  if (!strncmp(name.c_str(), "typeinfo for ", sizeof("typeinfo for ")-1)) {
5385  name.erase(0, sizeof("typeinfo for ")-1);
5386  } else if (!strncmp(name.c_str(), "vtable for ", sizeof("vtable for ")-1)) {
5387  name.erase(0, sizeof("vtable for ")-1);
5388  } else if (!strncmp(name.c_str(), "operator", sizeof("operator")-1)
5389  && !isalnum(name[sizeof("operator")])) {
5390  // operator...(A, B) - let's try with A!
5391  name.erase(0, sizeof("operator")-1);
5392  std::string::size_type pos = name.rfind('(');
5393  if (pos != std::string::npos) {
5394  name.erase(0, pos + 1);
5395  pos = name.find(",");
5396  if (pos != std::string::npos) {
5397  // remove next arg up to end, leaving only the first argument type.
5398  name.erase(pos);
5399  }
5400  pos = name.rfind(" const");
5401  if (pos != std::string::npos) {
5402  name.erase(pos, strlen(" const"));
5403  }
5404  while (!name.empty() && strchr("&*", name.back()))
5405  name.erase(name.length() - 1);
5406  }
5407  } else {
5408  // Remove the function arguments.
5409  std::string::size_type pos = name.rfind('(');
5410  if (pos != std::string::npos) {
5411  name.erase(pos);
5412  }
5413  // Remove the function name.
5414  pos = name.rfind(':');
5415  if (pos != std::string::npos) {
5416  if ((pos != 0) && (name[pos-1] == ':')) {
5417  name.erase(pos-1);
5418  }
5419  }
5420  }
5421  //fprintf(stderr, "name: '%s'\n", name.c_str());
5422  // Now we have the class or namespace name, so do the lookup.
5423  TString libs = GetClassSharedLibs(name.c_str());
5424  if (libs.IsNull()) {
5425  // Not found in the map, all done.
5426  return 0;
5427  }
5428  //fprintf(stderr, "library: %s\n", iter->second.c_str());
5429  // Now we have the name of the libraries to load, so load them.
5430 
5431  TString lib;
5432  Ssiz_t posLib = 0;
5433  while (libs.Tokenize(lib, posLib)) {
5434  if (gSystem->Load(lib, "", kFALSE /*system*/) < 0) {
5435  // The library load failed, all done.
5436  //fprintf(stderr, "load failed: %s\n", errmsg.c_str());
5437  return 0;
5438  }
5439  }
5440 
5441  //fprintf(stderr, "load succeeded.\n");
5442  // Get the address of the function being called.
5443  void* addr = llvm::sys::DynamicLibrary::SearchForAddressOfSymbol(mangled_name.c_str());
5444  //fprintf(stderr, "addr: %016lx\n", reinterpret_cast<unsigned long>(addr));
5445  return addr;
5446 }
5447 
5448 ////////////////////////////////////////////////////////////////////////////////
5449 
5451 {
5452 // if (fMapNamespaces){
5453 // return fMapNamespaces->FindObject(name);
5454 // }
5455  return false;
5456 }
5457 
5458 ////////////////////////////////////////////////////////////////////////////////
5459 
5460 Bool_t TCling::IsAutoLoadNamespaceCandidate(const clang::NamespaceDecl* nsDecl)
5461 {
5462  return fNSFromRootmaps.count(nsDecl) != 0;
5463 }
5464 
5465 ////////////////////////////////////////////////////////////////////////////////
5466 /// Internal function. Inform a TClass about its new TagDecl or NamespaceDecl.
5467 
5468 void TCling::UpdateClassInfoWithDecl(const void* vTD)
5469 {
5470  const NamedDecl* ND = static_cast<const NamedDecl*>(vTD);
5471  const TagDecl* td = dyn_cast<TagDecl>(ND);
5472  std::string name;
5473  TagDecl* tdDef = 0;
5474  if (td) {
5475  tdDef = td->getDefinition();
5476  // Let's pass the decl to the TClass only if it has a definition.
5477  if (!tdDef) return;
5478  td = tdDef;
5479  ND = td;
5480 
5481  if (llvm::isa<clang::FunctionDecl>(td->getDeclContext())) {
5482  // Ignore declaration within a function.
5483  return;
5484  }
5485  clang::QualType type( td->getTypeForDecl(), 0 );
5486 
5487  auto declName=ND->getNameAsString();
5488  if (!TClass::HasNoInfoOrEmuOrFwdDeclaredDecl(declName.c_str())){
5489 // 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 );
5490  return;
5491  }
5492 
5494  } else {
5495  name = ND->getNameAsString();
5496  }
5497 
5498  // Supposedly we are being called while something is being
5499  // loaded ... let's now tell the autoloader to do the work
5500  // yet another time.
5501  int storedAutoloading = SetClassAutoloading(false);
5502  // FIXME: There can be more than one TClass for a single decl.
5503  // for example vector<double> and vector<Double32_t>
5504  TClass* cl = (TClass*)gROOT->GetListOfClasses()->FindObject(name.c_str());
5505  if (cl && GetModTClasses().find(cl) == GetModTClasses().end()) {
5507  if (cci) {
5508  // If we only had a forward declaration then update the
5509  // TClingClassInfo with the definition if we have it now.
5510  const TagDecl* tdOld = llvm::dyn_cast_or_null<TagDecl>(cci->GetDecl());
5511  if (!tdOld || (tdDef && tdDef != tdOld)) {
5512  cl->ResetCaches();
5514  if (td) {
5515  // It's a tag decl, not a namespace decl.
5516  cci->Init(*cci->GetType());
5518  }
5519  }
5520  } else if (!cl->TestBit(TClass::kLoading) && !cl->fHasRootPcmInfo) {
5521  cl->ResetCaches();
5522  // yes, this is almost a waste of time, but we do need to lookup
5523  // the 'type' corresponding to the TClass anyway in order to
5524  // preserve the opaque typedefs (Double32_t)
5525  cl->fClassInfo = (ClassInfo_t *)new TClingClassInfo(fInterpreter, cl->GetName());
5526  // We now need to update the state and bits.
5527  if (cl->fState != TClass::kHasTClassInit) {
5528  // if (!cl->fClassInfo->IsValid()) cl->fState = TClass::kForwardDeclared; else
5531  }
5532  TClass::AddClassToDeclIdMap(((TClingClassInfo*)(cl->fClassInfo))->GetDeclId(), cl);
5533  }
5534  }
5535  SetClassAutoloading(storedAutoloading);
5536 }
5537 
5538 ////////////////////////////////////////////////////////////////////////////////
5539 /// No op: see TClingCallbacks
5540 
5541 void TCling::UpdateClassInfo(char* item, Long_t tagnum)
5542 {
5543 }
5544 
5545 //______________________________________________________________________________
5546 //FIXME: Factor out that function in TClass, because TClass does it already twice
5547 void TCling::UpdateClassInfoWork(const char* item)
5548 {
5549  // This is a no-op as part of the API.
5550  // TCling uses UpdateClassInfoWithDecl() instead.
5551 }
5552 
5553 ////////////////////////////////////////////////////////////////////////////////
5554 /// Update all canvases at end the terminal input command.
5555 
5557 {
5558  TIter next(gROOT->GetListOfCanvases());
5559  TVirtualPad* canvas;
5560  while ((canvas = (TVirtualPad*)next())) {
5561  canvas->Update();
5562  }
5563 }
5564 
5565 ////////////////////////////////////////////////////////////////////////////////
5566 
5567 void TCling::UpdateListsOnCommitted(const cling::Transaction &T) {
5568  std::set<TClass*> modifiedTClasses; // TClasses that require update after this transaction
5569 
5570  // If the transaction does not contain anything we can return earlier.
5571  if (!HandleNewTransaction(T)) return;
5572 
5573  bool isTUTransaction = false;
5574  if (T.decls_end()-T.decls_begin() == 1 && !T.hasNestedTransactions()) {
5575  clang::Decl* FirstDecl = *(T.decls_begin()->m_DGR.begin());
5576  if (clang::TranslationUnitDecl* TU
5577  = dyn_cast<clang::TranslationUnitDecl>(FirstDecl)) {
5578  // The is the first transaction, we have to expose to meta
5579  // what's already in the AST.
5580  isTUTransaction = true;
5581 
5582  // FIXME: don't load the world. Really, don't. Maybe
5583  // instead smarten TROOT::GetListOfWhateveros() which
5584  // currently is a THashList but could be a
5585  // TInterpreterLookupCollection, one that reimplements
5586  // TCollection::FindObject(name) and performs a lookup
5587  // if not found in its T(Hash)List.
5588  cling::Interpreter::PushTransactionRAII RAII(fInterpreter);
5589  for (clang::DeclContext::decl_iterator TUI = TU->decls_begin(),
5590  TUE = TU->decls_end(); TUI != TUE; ++TUI)
5591  ((TCling*)gCling)->HandleNewDecl(*TUI, (*TUI)->isFromASTFile(),modifiedTClasses);
5592  }
5593  }
5594 
5595  std::set<const void*> TransactionDeclSet;
5596  if (!isTUTransaction && T.decls_end() - T.decls_begin()) {
5597  const clang::Decl* WrapperFD = T.getWrapperFD();
5598  for (cling::Transaction::const_iterator I = T.decls_begin(), E = T.decls_end();
5599  I != E; ++I) {
5600  if (I->m_Call != cling::Transaction::kCCIHandleTopLevelDecl
5601  && I->m_Call != cling::Transaction::kCCIHandleTagDeclDefinition)
5602  continue;
5603 
5604  for (DeclGroupRef::const_iterator DI = I->m_DGR.begin(),
5605  DE = I->m_DGR.end(); DI != DE; ++DI) {
5606  if (*DI == WrapperFD)
5607  continue;
5608  TransactionDeclSet.insert(*DI);
5609  ((TCling*)gCling)->HandleNewDecl(*DI, false, modifiedTClasses);
5610  }
5611  }
5612  }
5613 
5614  // The above might trigger more decls to be deserialized.
5615  // Thus the iteration over the deserialized decls must be last.
5616  for (cling::Transaction::const_iterator I = T.deserialized_decls_begin(),
5617  E = T.deserialized_decls_end(); I != E; ++I) {
5618  for (DeclGroupRef::const_iterator DI = I->m_DGR.begin(),
5619  DE = I->m_DGR.end(); DI != DE; ++DI)
5620  if (TransactionDeclSet.find(*DI) == TransactionDeclSet.end()) {
5621  //FIXME: HandleNewDecl should take DeclGroupRef
5622  ((TCling*)gCling)->HandleNewDecl(*DI, /*isDeserialized*/true,
5623  modifiedTClasses);
5624  }
5625  }
5626 
5627 
5628  // When fully building the reflection info in TClass, a deserialization
5629  // could be triggered, which may result in request for building the
5630  // reflection info for the same TClass. This in turn will clear the caches
5631  // for the TClass in-flight and cause null ptr derefs.
5632  // FIXME: This is a quick fix, solving most of the issues. The actual
5633  // question is: Shouldn't TClass provide a lock mechanism on update or lock
5634  // itself until the update is done.
5635  //
5636  std::vector<TClass*> modifiedTClassesDiff(modifiedTClasses.size());
5637  std::vector<TClass*>::iterator it;
5638  it = set_difference(modifiedTClasses.begin(), modifiedTClasses.end(),
5639  ((TCling*)gCling)->GetModTClasses().begin(),
5640  ((TCling*)gCling)->GetModTClasses().end(),
5641  modifiedTClassesDiff.begin());
5642  modifiedTClassesDiff.resize(it - modifiedTClassesDiff.begin());
5643 
5644  // Lock the TClass for updates
5645  ((TCling*)gCling)->GetModTClasses().insert(modifiedTClassesDiff.begin(),
5646  modifiedTClassesDiff.end());
5647  for (std::vector<TClass*>::const_iterator I = modifiedTClassesDiff.begin(),
5648  E = modifiedTClassesDiff.end(); I != E; ++I) {
5649  // Make sure the TClass has not been deleted.
5650  if (!gROOT->GetListOfClasses()->FindObject(*I)) {
5651  continue;
5652  }
5653  // Could trigger deserialization of decls.
5654  cling::Interpreter::PushTransactionRAII RAII(fInterpreter);
5655  // Unlock the TClass for updates
5656  ((TCling*)gCling)->GetModTClasses().erase(*I);
5657 
5658  }
5659 }
5660 
5661 ////////////////////////////////////////////////////////////////////////////////
5662 /// Helper function to go through the members of a class or namespace and unload them.
5663 
5664 void TCling::UnloadClassMembers(TClass* cl, const clang::DeclContext* DC) {
5665 
5666  TDataMember* var = 0;
5667  TFunction* function = 0;
5668  TEnum* e = 0;
5669  TFunctionTemplate* functiontemplate = 0;
5671  TListOfFunctions* functions = (TListOfFunctions*)cl->GetListOfMethods();
5672  TListOfEnums* enums = (TListOfEnums*)cl->GetListOfEnums();
5674  for (DeclContext::decl_iterator RI = DC->decls_begin(), RE = DC->decls_end(); RI != RE; ++RI) {
5675  if (isa<VarDecl>(*RI) || isa<FieldDecl>(*RI)) {
5676  const clang::ValueDecl* VD = dyn_cast<ValueDecl>(*RI);
5677  var = (TDataMember*)datamembers->FindObject(VD->getNameAsString().c_str());
5678  if (var) {
5679  // Unload the global by setting the DataMemberInfo_t to 0
5680  datamembers->Unload(var);
5681  var->Update(0);
5682  }
5683  } else if (const FunctionDecl* FD = dyn_cast<FunctionDecl>(*RI)) {
5684  function = (TFunction*)functions->FindObject(FD->getNameAsString().c_str());
5685  if (function) {
5686  functions->Unload(function);
5687  function->Update(0);
5688  }
5689  } else if (const EnumDecl* ED = dyn_cast<EnumDecl>(*RI)) {
5690  e = (TEnum*)enums->FindObject(ED->getNameAsString().c_str());
5691  if (e) {
5692  TIter iEnumConst(e->GetConstants());
5693  while (TEnumConstant* enumConst = (TEnumConstant*)iEnumConst()) {
5694  // Since the enum is already created and valid that ensures us that
5695  // we have the enum constants created as well.
5696  enumConst = (TEnumConstant*)datamembers->FindObject(enumConst->GetName());
5697  if (enumConst && enumConst->IsValid()) {
5698  datamembers->Unload(enumConst);
5699  enumConst->Update(0);
5700  }
5701  }
5702  enums->Unload(e);
5703  e->Update(0);
5704  }
5705  } else if (const FunctionTemplateDecl* FTD = dyn_cast<FunctionTemplateDecl>(*RI)) {
5706  functiontemplate = (TFunctionTemplate*)functiontemplates->FindObject(FTD->getNameAsString().c_str());
5707  if (functiontemplate) {
5708  functiontemplates->Unload(functiontemplate);
5709  functiontemplate->Update(0);
5710  }
5711  }
5712  }
5713 }
5714 
5715 ////////////////////////////////////////////////////////////////////////////////
5716 
5717 void TCling::UpdateListsOnUnloaded(const cling::Transaction &T)
5718 {
5720 
5721  // Unload the objects from the lists and update the objects' state.
5722  TListOfFunctions* functions = (TListOfFunctions*)gROOT->GetListOfGlobalFunctions();
5723  TListOfFunctionTemplates* functiontemplates = (TListOfFunctionTemplates*)gROOT->GetListOfFunctionTemplates();
5724  TListOfEnums* enums = (TListOfEnums*)gROOT->GetListOfEnums();
5725  TListOfDataMembers* globals = (TListOfDataMembers*)gROOT->GetListOfGlobals();
5726  cling::Transaction::const_nested_iterator iNested = T.nested_begin();
5727  for(cling::Transaction::const_iterator I = T.decls_begin(), E = T.decls_end();
5728  I != E; ++I) {
5729  if (I->m_Call == cling::Transaction::kCCIHandleVTable)
5730  continue;
5731 
5732  if (I->m_Call == cling::Transaction::kCCINone) {
5733  UpdateListsOnUnloaded(**iNested);
5734  ++iNested;
5735  continue;
5736  }
5737 
5738  for (DeclGroupRef::const_iterator DI = I->m_DGR.begin(),
5739  DE = I->m_DGR.end(); DI != DE; ++DI) {
5740 
5741  // Do not mark a decl as unloaded if we are going to keep it
5742  // (because it comes from the pch) ...
5743  if ( (*DI)->isFromASTFile() )
5744  continue;
5745 
5746  // Deal with global variables and global enum constants.
5747  if (isa<VarDecl>(*DI) || isa<EnumConstantDecl>(*DI)) {
5748  TObject *obj = globals->Find((TListOfDataMembers::DeclId_t)*DI);
5749  if (globals->GetClass()) {
5750  TDataMember* var = dynamic_cast<TDataMember*>(obj);
5751  if (var && var->IsValid()) {
5752  // Unload the global by setting the DataMemberInfo_t to 0
5753  globals->Unload(var);
5754  var->Update(0);
5755  }
5756  } else {
5757  TGlobal *g = dynamic_cast<TGlobal*>(obj);
5758  if (g && g->IsValid()) {
5759  // Unload the global by setting the DataMemberInfo_t to 0
5760  globals->Unload(g);
5761  g->Update(0);
5762  }
5763  }
5764  // Deal with global functions.
5765  } else if (const FunctionDecl* FD = dyn_cast<FunctionDecl>(*DI)) {
5766  TFunction* function = (TFunction*)functions->Find((TListOfFunctions::DeclId_t)FD);
5767  if (function && function->IsValid()) {
5768  functions->Unload(function);
5769  function->Update(0);
5770  }
5771  // Deal with global function templates.
5772  } else if (const FunctionTemplateDecl* FTD = dyn_cast<FunctionTemplateDecl>(*DI)) {
5773  TFunctionTemplate* functiontemplate = (TFunctionTemplate*)functiontemplates->FindObject(FTD->getNameAsString().c_str());
5774  if (functiontemplate) {
5775  functiontemplates->Unload(functiontemplate);
5776  functiontemplate->Update(0);
5777  }
5778  // Deal with global enums.
5779  } else if (const EnumDecl* ED = dyn_cast<EnumDecl>(*DI)) {
5780  if (TEnum* e = (TEnum*)enums->Find((TListOfEnums::DeclId_t)ED)) {
5781  globals = (TListOfDataMembers*)gROOT->GetListOfGlobals();
5782  TIter iEnumConst(e->GetConstants());
5783  while (TEnumConstant* enumConst = (TEnumConstant*)iEnumConst()) {
5784  // Since the enum is already created and valid that ensures us that
5785  // we have the enum constants created as well.
5786  enumConst = (TEnumConstant*)globals->FindObject(enumConst->GetName());
5787  if (enumConst) {
5788  globals->Unload(enumConst);
5789  enumConst->Update(0);
5790  }
5791  }
5792  enums->Unload(e);
5793  e->Update(0);
5794  }
5795  // Deal with classes. Unload the class and the data members will be not accessible anymore
5796  // Cannot declare the members in a different declaration like redeclarable namespaces.
5797  } else if (const clang::RecordDecl* RD = dyn_cast<RecordDecl>(*DI)) {
5798  std::vector<TClass*> vectTClass;
5799  // Only update the TClass if the definition is being unloaded.
5800  if (RD->isCompleteDefinition()) {
5801  if (TClass::GetClass(RD, vectTClass)) {
5802  for (std::vector<TClass*>::iterator CI = vectTClass.begin(), CE = vectTClass.end();
5803  CI != CE; ++CI) {
5804  UnloadClassMembers((*CI), RD);
5805  (*CI)->ResetClassInfo();
5806  }
5807  }
5808  }
5809  // Deal with namespaces. Unload the members of the current redeclaration only.
5810  } else if (const clang::NamespaceDecl* ND = dyn_cast<NamespaceDecl>(*DI)) {
5811  std::vector<TClass*> vectTClass;
5812  if (TClass::GetClass(ND->getCanonicalDecl(), vectTClass)) {
5813  for (std::vector<TClass*>::iterator CI = vectTClass.begin(), CE = vectTClass.end();
5814  CI != CE; ++CI) {
5815  UnloadClassMembers((*CI), ND);
5816  if (ND->isOriginalNamespace()) {
5817  (*CI)->ResetClassInfo();
5818  }
5819  }
5820  }
5821  }
5822  }
5823  }
5824 }
5825 
5826 ////////////////////////////////////////////////////////////////////////////////
5827 // If an autoparse was done during a transaction and that it is rolled back,
5828 // we need to make sure the next request for the same autoparse will be
5829 // honored.
5830 void TCling::TransactionRollback(const cling::Transaction &T) {
5831  auto const &triter = fTransactionHeadersMap.find(&T);
5832  if (triter != fTransactionHeadersMap.end()) {
5833  std::size_t normNameHash = triter->second;
5834 
5835  fLookedUpClasses.erase(normNameHash);
5836 
5837  auto const &iter = fClassesHeadersMap.find(normNameHash);
5838  if (iter != fClassesHeadersMap.end()) {
5839  auto const &hNamesPtrs = iter->second;
5840  for (auto &hName : hNamesPtrs) {
5841  if (gDebug > 0) {
5842  Info("TransactionRollback",
5843  "Restoring ability to autoaparse: %s", hName);
5844  }
5845  fParsedPayloadsAddresses.erase(hName);
5846  }
5847  }
5848  }
5849 }
5850 
5851 ////////////////////////////////////////////////////////////////////////////////
5852 
5853 void TCling::LibraryLoaded(const void* dyLibHandle, const char* canonicalName) {
5854 // UpdateListOfLoadedSharedLibraries();
5855 }
5856 
5857 ////////////////////////////////////////////////////////////////////////////////
5858 
5859 void TCling::LibraryUnloaded(const void* dyLibHandle, const char* canonicalName) {
5861  fSharedLibs = "";
5862 }
5863 
5864 ////////////////////////////////////////////////////////////////////////////////
5865 /// Return the list of shared libraries loaded into the process.
5866 
5868 {
5871  return fSharedLibs;
5872 }
5873 
5874 ////////////////////////////////////////////////////////////////////////////////
5875 /// Get the list of shared libraries containing the code for class cls.
5876 /// The first library in the list is the one containing the class, the
5877 /// others are the libraries the first one depends on. Returns 0
5878 /// in case the library is not found.
5879 
5880 const char* TCling::GetClassSharedLibs(const char* cls)
5881 {
5882  if (!cls || !*cls) {
5883  return 0;
5884  }
5885  // lookup class to find list of libraries
5886  if (fMapfile) {
5887  TEnvRec* libs_record = 0;
5888  libs_record = fMapfile->Lookup(cls);
5889  if (libs_record) {
5890  const char* libs = libs_record->GetValue();
5891  return (*libs) ? libs : 0;
5892  }
5893  else {
5894  // Try the old format...
5895  TString c = TString("Library.") + cls;
5896  // convert "::" to "@@", we used "@@" because TEnv
5897  // considers "::" a terminator
5898  c.ReplaceAll("::", "@@");
5899  // convert "-" to " ", since class names may have
5900  // blanks and TEnv considers a blank a terminator
5901  c.ReplaceAll(" ", "-");
5902  // Use TEnv::Lookup here as the rootmap file must start with Library.
5903  // and do not support using any stars (so we do not need to waste time
5904  // with the search made by TEnv::GetValue).
5905  TEnvRec* libs_record = 0;
5906  libs_record = fMapfile->Lookup(c);
5907  if (libs_record) {
5908  const char* libs = libs_record->GetValue();
5909  return (*libs) ? libs : 0;
5910  }
5911  }
5912  }
5913  return 0;
5914 }
5915 
5916 ////////////////////////////////////////////////////////////////////////////////
5917 /// Get the list a libraries on which the specified lib depends. The
5918 /// returned string contains as first element the lib itself.
5919 /// Returns 0 in case the lib does not exist or does not have
5920 /// any dependencies.
5921 
5922 const char* TCling::GetSharedLibDeps(const char* lib)
5923 {
5924  if (!fMapfile || !lib || !lib[0]) {
5925  return 0;
5926  }
5927  TString libname(lib);
5928  Ssiz_t idx = libname.Last('.');
5929  if (idx != kNPOS) {
5930  libname.Remove(idx);
5931  }
5932  TEnvRec* rec;
5933  TIter next(fMapfile->GetTable());
5934  size_t len = libname.Length();
5935  while ((rec = (TEnvRec*) next())) {
5936  const char* libs = rec->GetValue();
5937  if (!strncmp(libs, libname.Data(), len) && strlen(libs) >= len
5938  && (!libs[len] || libs[len] == ' ' || libs[len] == '.')) {
5939  return libs;
5940  }
5941  }
5942  return 0;
5943 }
5944 
5945 ////////////////////////////////////////////////////////////////////////////////
5946 /// If error messages are disabled, the interpreter should suppress its
5947 /// failures and warning messages from stdout.
5948 
5950 {
5951 #if defined(R__MUST_REVISIT)
5952 #if R__MUST_REVISIT(6,2)
5953  Warning("IsErrorMessagesEnabled", "Interface not available yet.");
5954 #endif
5955 #endif
5956  return kTRUE;
5957 }
5958 
5959 ////////////////////////////////////////////////////////////////////////////////
5960 /// If error messages are disabled, the interpreter should suppress its
5961 /// failures and warning messages from stdout. Return the previous state.
5962 
5964 {
5965 #if defined(R__MUST_REVISIT)
5966 #if R__MUST_REVISIT(6,2)
5967  Warning("SetErrorMessages", "Interface not available yet.");
5968 #endif
5969 #endif
5971 }
5972 
5973 ////////////////////////////////////////////////////////////////////////////////
5974 /// Refresh the list of include paths known to the interpreter and return it
5975 /// with -I prepended.
5976 
5978 {
5980 
5981  fIncludePath = "";
5982 
5983  llvm::SmallVector<std::string, 10> includePaths;//Why 10? Hell if I know.
5984  //false - no system header, true - with flags.
5985  fInterpreter->GetIncludePaths(includePaths, false, true);
5986  if (const size_t nPaths = includePaths.size()) {
5987  assert(!(nPaths & 1) && "GetIncludePath, number of paths and options is not equal");
5988 
5989  for (size_t i = 0; i < nPaths; i += 2) {
5990  if (i)
5991  fIncludePath.Append(' ');
5992  fIncludePath.Append(includePaths[i].c_str());
5993 
5994  if (includePaths[i] != "-I")
5995  fIncludePath.Append(' ');
5996  fIncludePath.Append('"');
5997  fIncludePath.Append(includePaths[i + 1], includePaths[i + 1].length());
5998  fIncludePath.Append('"');
5999  }
6000  }
6001 
6002  return fIncludePath;
6003 }
6004 
6005 ////////////////////////////////////////////////////////////////////////////////
6006 /// Return the directory containing CINT's stl cintdlls.
6007 
6008 const char* TCling::GetSTLIncludePath() const
6009 {
6010  return "";
6011 }
6012 
6013 //______________________________________________________________________________
6014 // M I S C
6015 //______________________________________________________________________________
6016 
6017 int TCling::DisplayClass(FILE* /*fout*/, const char* /*name*/, int /*base*/, int /*start*/) const
6018 {
6019  // Interface to cling function
6020  return 0;
6021 }
6022 
6023 ////////////////////////////////////////////////////////////////////////////////
6024 /// Interface to cling function
6025 
6026 int TCling::DisplayIncludePath(FILE *fout) const
6027 {
6028  assert(fout != 0 && "DisplayIncludePath, 'fout' parameter is null");
6029 
6030  llvm::SmallVector<std::string, 10> includePaths;//Why 10? Hell if I know.
6031  //false - no system header, true - with flags.
6032  fInterpreter->GetIncludePaths(includePaths, false, true);
6033  if (const size_t nPaths = includePaths.size()) {
6034  assert(!(nPaths & 1) && "DisplayIncludePath, number of paths and options is not equal");
6035 
6036  std::string allIncludes("include path:");
6037  for (size_t i = 0; i < nPaths; i += 2) {
6038  allIncludes += ' ';
6039  allIncludes += includePaths[i];
6040 
6041  if (includePaths[i] != "-I")
6042  allIncludes += ' ';
6043  allIncludes += includePaths[i + 1];
6044  }
6045 
6046  fprintf(fout, "%s\n", allIncludes.c_str());
6047  }
6048 
6049  return 0;
6050 }
6051 
6052 ////////////////////////////////////////////////////////////////////////////////
6053 /// Interface to cling function
6054 
6055 void* TCling::FindSym(const char* entry) const
6056 {
6057  return fInterpreter->getAddressOfGlobal(entry);
6058 }
6059 
6060 ////////////////////////////////////////////////////////////////////////////////
6061 /// Let the interpreter issue a generic error, and set its error state.
6062 
6063 void TCling::GenericError(const char* error) const
6064 {
6065 #if defined(R__MUST_REVISIT)
6066 #if R__MUST_REVISIT(6,2)
6067  Warning("GenericError","Interface not available yet.");
6068 #endif
6069 #endif
6070 }
6071 
6072 ////////////////////////////////////////////////////////////////////////////////
6073 /// This routines used to return the address of the internal wrapper
6074 /// function (of the interpreter) that was used to call *all* the
6075 /// interpreted functions that were bytecode compiled (no longer
6076 /// interpreted line by line). In Cling, there is no such
6077 /// wrapper function.
6078 /// In practice this routines was use to decipher whether the
6079 /// pointer returns by InterfaceMethod could be used to uniquely
6080 /// represent the function. In Cling if the function is in a
6081 /// useable state (its compiled version is available), this is
6082 /// always the case.
6083 /// See TClass::GetMethod.
6084 
6086 {
6087  return 0;
6088 }
6089 
6090 ////////////////////////////////////////////////////////////////////////////////
6091 /// Interface to the CINT global object pointer which was controlling the
6092 /// behavior of the wrapper around the calls to operator new and the constructor
6093 /// and operator delete and the destructor.
6094 
6096 {
6097  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.");
6098  return 0;
6099 }
6100 
6101 ////////////////////////////////////////////////////////////////////////////////
6102 
6103 const char* TCling::Getp2f2funcname(void*) const
6104 {
6105  Error("Getp2f2funcname", "Will not be implemented: "
6106  "all function pointers are compiled!");
6107  return NULL;
6108 }
6109 
6110 ////////////////////////////////////////////////////////////////////////////////
6111 /// Interface to cling function
6112 
6114 {
6115 #if defined(R__MUST_REVISIT)
6116 #if R__MUST_REVISIT(6,2)
6117  Warning("GetSecurityError", "Interface not available yet.");
6118 #endif
6119 #endif
6120  return 0;
6121 }
6122 
6123 ////////////////////////////////////////////////////////////////////////////////
6124 /// Load a source file or library called path into the interpreter.
6125 
6126 int TCling::LoadFile(const char* path) const
6127 {
6128  cling::Interpreter::CompilationResult compRes;
6129  cling::MetaProcessor::MaybeRedirectOutputRAII RAII(fMetaProcessor);
6130  fMetaProcessor->process(TString::Format(".L %s", path), compRes, /*cling::Value*/0);
6131  return compRes == cling::Interpreter::kFailure;
6132 }
6133 
6134 ////////////////////////////////////////////////////////////////////////////////
6135 /// Load the declarations from text into the interpreter.
6136 /// Note that this cannot be (top level) statements; text must contain
6137 /// top level declarations.
6138 /// Returns true on success, false on failure.
6139 
6140 Bool_t TCling::LoadText(const char* text) const
6141 {
6142  return (fInterpreter->declare(text) == cling::Interpreter::kSuccess);
6143 }
6144 
6145 ////////////////////////////////////////////////////////////////////////////////
6146 /// Interface to cling function
6147 
6148 const char* TCling::MapCppName(const char* name) const
6149 {
6150  TTHREAD_TLS_DECL(std::string,buffer);
6151  ROOT::TMetaUtils::GetCppName(buffer,name);
6152  return buffer.c_str();
6153 }
6154 
6155 ////////////////////////////////////////////////////////////////////////////////
6156 /// [Place holder for Mutex Lock]
6157 /// Provide the interpreter with a way to
6158 /// acquire a lock used to protect critical section
6159 /// of its code (non-thread safe parts).
6160 
6161 void TCling::SetAlloclockfunc(void (* /* p */ )()) const
6162 {
6163  // nothing to do for now.
6164 }
6165 
6166 ////////////////////////////////////////////////////////////////////////////////
6167 /// [Place holder for Mutex Unlock] Provide the interpreter with a way to
6168 /// release a lock used to protect critical section
6169 /// of its code (non-thread safe parts).
6170 
6171 void TCling::SetAllocunlockfunc(void (* /* p */ )()) const
6172 {
6173  // nothing to do for now.
6174 }
6175 
6176 ////////////////////////////////////////////////////////////////////////////////
6177 /// Enable/Disable the Autoloading of libraries.
6178 /// Returns the old value, i.e whether it was enabled or not.
6179 
6180 int TCling::SetClassAutoloading(int autoload) const
6181 {
6182  if (!autoload && !fClingCallbacks) return false;
6183  if (!fAllowLibLoad) return false;
6184 
6185  assert(fClingCallbacks && "We must have callbacks!");
6186  bool oldVal = fClingCallbacks->IsAutoloadingEnabled();
6188  return oldVal;
6189 }
6190 
6191 ////////////////////////////////////////////////////////////////////////////////
6192 /// Enable/Disable the Autoparsing of headers.
6193 /// Returns the old value, i.e whether it was enabled or not.
6194 
6196 {
6197  bool oldVal = fHeaderParsingOnDemand;
6198  fHeaderParsingOnDemand = autoparse;
6199  return oldVal;
6200 }
6201 
6202 ////////////////////////////////////////////////////////////////////////////////
6203 /// Suspend the Autoparsing of headers.
6204 /// Returns the old value, i.e whether it was suspended or not.
6205 
6210  return old;
6211 }
6212 
6213 ////////////////////////////////////////////////////////////////////////////////
6214 /// Set a callback to receive error messages.
6215 
6216 void TCling::SetErrmsgcallback(void* p) const
6217 {
6218 #if defined(R__MUST_REVISIT)
6219 #if R__MUST_REVISIT(6,2)
6220  Warning("SetErrmsgcallback", "Interface not available yet.");
6221 #endif
6222 #endif
6223 }
6224 
6225 ////////////////////////////////////////////////////////////////////////////////
6226 /// Interface to the cling global object pointer which was controlling the
6227 /// behavior of the wrapper around the calls to operator new and the constructor
6228 /// and operator delete and the destructor.
6229 
6230 void TCling::Setgvp(Long_t gvp) const
6231 {
6232  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.");
6233 
6234 }
6235 
6236 ////////////////////////////////////////////////////////////////////////////////
6237 
6239 {
6240  Error("SetRTLD_NOW()", "Will never be implemented! Don't use!");
6241 }
6242 
6243 ////////////////////////////////////////////////////////////////////////////////
6244 
6246 {
6247  Error("SetRTLD_LAZY()", "Will never be implemented! Don't use!");
6248 }
6249 
6250 ////////////////////////////////////////////////////////////////////////////////
6251 /// Create / close a scope for temporaries. No-op for cling; use
6252 /// cling::Value instead.
6253 
6254 void TCling::SetTempLevel(int val) const
6255 {
6256 }
6257 
6258 ////////////////////////////////////////////////////////////////////////////////
6259 
6260 int TCling::UnloadFile(const char* path) const
6261 {
6262  cling::DynamicLibraryManager* DLM = fInterpreter->getDynamicLibraryManager();
6263  std::string canonical = DLM->lookupLibrary(path);
6264  if (canonical.empty()) {
6265  canonical = path;
6266  }
6267  // Unload a shared library or a source file.
6268  cling::Interpreter::CompilationResult compRes;
6269  cling::MetaProcessor::MaybeRedirectOutputRAII RAII(fMetaProcessor);
6270  fMetaProcessor->process(Form(".U %s", canonical.c_str()), compRes, /*cling::Value*/0);
6271  return compRes == cling::Interpreter::kFailure;
6272 }
6273 
6274 ////////////////////////////////////////////////////////////////////////////////
6275 /// The created temporary must be deleted by the caller.
6276 
6278 {
6279  TClingValue *val = new TClingValue;
6280  return val;
6281 }
6282 
6283 ////////////////////////////////////////////////////////////////////////////////
6284 
6286 {
6287  using namespace cling;
6288  const Value* V = reinterpret_cast<const Value*>(value.GetValAddr());
6289  RegisterTemporary(*V);
6290 }
6291 
6292 ////////////////////////////////////////////////////////////////////////////////
6293 /// Register value as a temporary, extending its lifetime to that of the
6294 /// interpreter. This is needed for TCling's compatibility interfaces
6295 /// returning long - the address of the temporary objects.
6296 /// As such, "simple" types don't need to be stored; they are returned by
6297 /// value; only pointers / references / objects need to be stored.
6298 
6300 {
6301  if (value.isValid() && value.needsManagedAllocation()) {
6303  fTemporaries->push_back(value);
6304  }
6305 }
6306 
6307 ////////////////////////////////////////////////////////////////////////////////
6308 /// If the interpreter encounters Name, check whether that is an object ROOT
6309 /// could retrieve. To not re-read objects from disk, cache the name/object
6310 /// pair for a given LookupCtx.
6311 
6312 TObject* TCling::GetObjectAddress(const char *Name, void *&LookupCtx)
6313 {
6314  cling::Interpreter *interpreter = ((TCling*)gCling)->GetInterpreter();
6315 
6316  // The call to FindSpecialObject might induces any kind of use
6317  // of the interpreter ... (library loading, function calling, etc.)
6318  // ... and we _know_ we are in the middle of parsing, so let's make
6319  // sure to save the state and then restore it.
6320 
6321  if (gDirectory) {
6322  auto iSpecObjMap = fSpecialObjectMaps.find(gDirectory);
6323  if (iSpecObjMap != fSpecialObjectMaps.end()) {
6324  auto iSpecObj = iSpecObjMap->second.find(Name);
6325  if (iSpecObj != iSpecObjMap->second.end()) {
6326  LookupCtx = gDirectory;
6327  return iSpecObj->second;
6328  }
6329  }
6330  }
6331 
6332  // Save state of the PP
6333  Sema &SemaR = interpreter->getSema();
6334  ASTContext& C = SemaR.getASTContext();
6335  Preprocessor &PP = SemaR.getPreprocessor();
6336  Parser& P = const_cast<Parser&>(interpreter->getParser());
6337  Preprocessor::CleanupAndRestoreCacheRAII cleanupRAII(PP);
6338  Parser::ParserCurTokRestoreRAII savedCurToken(P);
6339  // After we have saved the token reset the current one to something which
6340  // is safe (semi colon usually means empty decl)
6341  Token& Tok = const_cast<Token&>(P.getCurToken());
6342  Tok.setKind(tok::semi);
6343 
6344  // We can't PushDeclContext, because we go up and the routine that pops
6345  // the DeclContext assumes that we drill down always.
6346  // We have to be on the global context. At that point we are in a
6347  // wrapper function so the parent context must be the global.
6348  Sema::ContextAndScopeRAII pushedDCAndS(SemaR, C.getTranslationUnitDecl(),
6349  SemaR.TUScope);
6350 
6351  TObject* specObj = gROOT->FindSpecialObject(Name, LookupCtx);
6352  if (specObj) {
6353  if (!LookupCtx) {
6354  Error("GetObjectAddress", "Got a special object without LookupCtx!");
6355  } else {
6356  fSpecialObjectMaps[LookupCtx][Name] = specObj;
6357  }
6358  }
6359  return specObj;
6360 }
6361 
6362 ////////////////////////////////////////////////////////////////////////////////
6363 /// Inject function as a friend into klass.
6364 /// With function being f in void f() {new N::PrivKlass(); } this enables
6365 /// I/O of non-public classes.
6366 
6367 void TCling::AddFriendToClass(clang::FunctionDecl* function,
6368  clang::CXXRecordDecl* klass) const
6369 {
6370  using namespace clang;
6371  ASTContext& Ctx = klass->getASTContext();
6372  FriendDecl::FriendUnion friendUnion(function);
6373  // one dummy object for the source location
6374  SourceLocation sl;
6375  FriendDecl* friendDecl = FriendDecl::Create(Ctx, klass, sl, friendUnion, sl);
6376  klass->pushFriendDecl(friendDecl);
6377 }
6378 
6379 //______________________________________________________________________________
6380 //
6381 // DeclId getter.
6382 //
6383 
6384 ////////////////////////////////////////////////////////////////////////////////
6385 /// Return a unique identifier of the declaration represented by the
6386 /// CallFunc
6387 
6389 {
6390  if (func) return ((TClingCallFunc*)func)->GetDecl()->getCanonicalDecl();
6391  return 0;
6392 }
6393 
6394 ////////////////////////////////////////////////////////////////////////////////
6395 /// Return a (almost) unique identifier of the declaration represented by the
6396 /// ClassInfo. In ROOT, this identifier can point to more than one TClass
6397 /// when the underlying class is a template instance involving one of the
6398 /// opaque typedef.
6399 
6401 {
6402  if (cinfo) return ((TClingClassInfo*)cinfo)->GetDeclId();
6403  return 0;
6404 }
6405 
6406 ////////////////////////////////////////////////////////////////////////////////
6407 /// Return a unique identifier of the declaration represented by the
6408 /// MethodInfo
6409 
6410 TInterpreter::DeclId_t TCling::GetDeclId(DataMemberInfo_t* data) const
6411 {
6412  if (data) return ((TClingDataMemberInfo*)data)->GetDeclId();
6413  return 0;
6414 }
6415 
6416 ////////////////////////////////////////////////////////////////////////////////
6417 /// Return a unique identifier of the declaration represented by the
6418 /// MethodInfo
6419 
6420 TInterpreter::DeclId_t TCling::GetDeclId(MethodInfo_t* method) const
6421 {
6422  if (method) return ((TClingMethodInfo*)method)->GetDeclId();
6423  return 0;
6424 }
6425 
6426 ////////////////////////////////////////////////////////////////////////////////
6427 /// Return a unique identifier of the declaration represented by the
6428 /// TypedefInfo
6429 
6430 TInterpreter::DeclId_t TCling::GetDeclId(TypedefInfo_t* tinfo) const
6431 {
6432  if (tinfo) return ((TClingTypedefInfo*)tinfo)->GetDecl()->getCanonicalDecl();
6433  return 0;
6434 }
6435 
6436 //______________________________________________________________________________
6437 //
6438 // CallFunc interface
6439 //
6440 
6441 ////////////////////////////////////////////////////////////////////////////////
6442 
6443 void TCling::CallFunc_Delete(CallFunc_t* func) const
6444 {
6445  delete (TClingCallFunc*) func;
6446 }
6447 
6448 ////////////////////////////////////////////////////////////////////////////////
6449 
6450 void TCling::CallFunc_Exec(CallFunc_t* func, void* address) const
6451 {
6452  TClingCallFunc* f = (TClingCallFunc*) func;
6453  f->Exec(address);
6454 }
6455 
6456 ////////////////////////////////////////////////////////////////////////////////
6457 
6458 void TCling::CallFunc_Exec(CallFunc_t* func, void* address, TInterpreterValue& val) const
6459 {
6460  TClingCallFunc* f = (TClingCallFunc*) func;
6461  f->Exec(address, &val);
6462 }
6463 
6464 ////////////////////////////////////////////////////////////////////////////////
6465 
6466 void TCling::CallFunc_ExecWithReturn(CallFunc_t* func, void* address, void* ret) const
6467 {
6468  TClingCallFunc* f = (TClingCallFunc*) func;
6469  f->ExecWithReturn(address, ret);
6470 }
6471 
6472 ////////////////////////////////////////////////////////////////////////////////
6473 
6474 void TCling::CallFunc_ExecWithArgsAndReturn(CallFunc_t* func, void* address,
6475  const void* args[] /*=0*/,
6476  int nargs /*=0*/,
6477  void* ret/*=0*/) const
6478 {
6479  TClingCallFunc* f = (TClingCallFunc*) func;
6480  f->ExecWithArgsAndReturn(address, args, nargs, ret);
6481 }
6482 
6483 ////////////////////////////////////////////////////////////////////////////////
6484 
6485 Long_t TCling::CallFunc_ExecInt(CallFunc_t* func, void* address) const
6486 {
6487  TClingCallFunc* f = (TClingCallFunc*) func;
6488  return f->ExecInt(address);
6489 }
6490 
6491 ////////////////////////////////////////////////////////////////////////////////
6492 
6493 Long64_t TCling::CallFunc_ExecInt64(CallFunc_t* func, void* address) const
6494 {
6495  TClingCallFunc* f = (TClingCallFunc*) func;
6496  return f->ExecInt64(address);
6497 }
6498 
6499 ////////////////////////////////////////////////////////////////////////////////
6500 
6501 Double_t TCling::CallFunc_ExecDouble(CallFunc_t* func, void* address) const
6502 {
6503  TClingCallFunc* f = (TClingCallFunc*) func;
6504  return f->ExecDouble(address);
6505 }
6506 
6507 ////////////////////////////////////////////////////////////////////////////////
6508 
6509 CallFunc_t* TCling::CallFunc_Factory() const
6510 {
6512  return (CallFunc_t*) new TClingCallFunc(fInterpreter,*fNormalizedCtxt);
6513 }
6514 
6515 ////////////////////////////////////////////////////////////////////////////////
6516 
6517 CallFunc_t* TCling::CallFunc_FactoryCopy(CallFunc_t* func) const
6518 {
6519  return (CallFunc_t*) new TClingCallFunc(*(TClingCallFunc*)func);
6520 }
6521 
6522 ////////////////////////////////////////////////////////////////////////////////
6523 
6524 MethodInfo_t* TCling::CallFunc_FactoryMethod(CallFunc_t* func) const
6525 {
6526  TClingCallFunc* f = (TClingCallFunc*) func;
6527  return (MethodInfo_t*) f->FactoryMethod();
6528 }
6529 
6530 ////////////////////////////////////////////////////////////////////////////////
6531 
6532 void TCling::CallFunc_IgnoreExtraArgs(CallFunc_t* func, bool ignore) const
6533 {
6534  TClingCallFunc* f = (TClingCallFunc*) func;
6535  f->IgnoreExtraArgs(ignore);
6536 }
6537 
6538 ////////////////////////////////////////////////////////////////////////////////
6539 
6540 void TCling::CallFunc_Init(CallFunc_t* func) const
6541 {
6543  TClingCallFunc* f = (TClingCallFunc*) func;
6544  f->Init();
6545 }
6546 
6547 ////////////////////////////////////////////////////////////////////////////////
6548 
6549 bool TCling::CallFunc_IsValid(CallFunc_t* func) const
6550 {
6551  TClingCallFunc* f = (TClingCallFunc*) func;
6552  return f->IsValid();
6553 }
6554 
6555 ////////////////////////////////////////////////////////////////////////////////
6556 
6558 TCling::CallFunc_IFacePtr(CallFunc_t * func) const
6559 {
6560  TClingCallFunc* f = (TClingCallFunc*) func;
6561  return f->IFacePtr();
6562 }
6563 
6564 ////////////////////////////////////////////////////////////////////////////////
6565 
6566 void TCling::CallFunc_ResetArg(CallFunc_t* func) const
6567 {
6568  TClingCallFunc* f = (TClingCallFunc*) func;
6569  f->ResetArg();
6570 }
6571 
6572 ////////////////////////////////////////////////////////////////////////////////
6573 
6574 void TCling::CallFunc_SetArg(CallFunc_t* func, Long_t param) const
6575 {
6576  TClingCallFunc* f = (TClingCallFunc*) func;
6577  f->SetArg(param);
6578 }
6579 
6580 ////////////////////////////////////////////////////////////////////////////////
6581 
6582 void TCling::CallFunc_SetArg(CallFunc_t* func, ULong_t param) const
6583 {
6584  TClingCallFunc* f = (TClingCallFunc*) func;
6585  f->SetArg(param);
6586 }
6587 
6588 ////////////////////////////////////////////////////////////////////////////////
6589 
6590 void TCling::CallFunc_SetArg(CallFunc_t* func, Float_t param) const
6591 {
6592  TClingCallFunc* f = (TClingCallFunc*) func;
6593  f->SetArg(param);
6594 }
6595 
6596 ////////////////////////////////////////////////////////////////////////////////
6597 
6598 void TCling::CallFunc_SetArg(CallFunc_t* func, Double_t param) const
6599 {
6600  TClingCallFunc* f = (TClingCallFunc*) func;
6601  f->SetArg(param);
6602 }
6603 
6604 ////////////////////////////////////////////////////////////////////////////////
6605 
6606 void TCling::CallFunc_SetArg(CallFunc_t* func, Long64_t param) const
6607 {
6608  TClingCallFunc* f = (TClingCallFunc*) func;
6609  f->SetArg(param);
6610 }
6611 
6612 ////////////////////////////////////////////////////////////////////////////////
6613 
6614 void TCling::CallFunc_SetArg(CallFunc_t* func, ULong64_t param) const
6615 {
6616  TClingCallFunc* f = (TClingCallFunc*) func;
6617  f->SetArg(param);
6618 }
6619 
6620 ////////////////////////////////////////////////////////////////////////////////
6621 
6622 void TCling::CallFunc_SetArgArray(CallFunc_t* func, Long_t* paramArr, Int_t nparam) const
6623 {
6624  TClingCallFunc* f = (TClingCallFunc*) func;
6625  f->SetArgArray(paramArr, nparam);
6626 }
6627 
6628 ////////////////////////////////////////////////////////////////////////////////
6629 
6630 void TCling::CallFunc_SetArgs(CallFunc_t* func, const char* param) const
6631 {
6632  TClingCallFunc* f = (TClingCallFunc*) func;
6633  f->SetArgs(param);
6634 }
6635 
6636 ////////////////////////////////////////////////////////////////////////////////
6637 
6638 void TCling::CallFunc_SetFunc(CallFunc_t* func, ClassInfo_t* info, const char* method, const char* params, Long_t* offset) const
6639 {
6640  TClingCallFunc* f = (TClingCallFunc*) func;
6641  TClingClassInfo* ci = (TClingClassInfo*) info;
6642  f->SetFunc(ci, method, params, offset);
6643 }
6644 
6645 ////////////////////////////////////////////////////////////////////////////////
6646 
6647 void TCling::CallFunc_SetFunc(CallFunc_t* func, ClassInfo_t* info, const char* method, const char* params, bool objectIsConst, Long_t* offset) const
6648 {
6649  TClingCallFunc* f = (TClingCallFunc*) func;
6650  TClingClassInfo* ci = (TClingClassInfo*) info;
6651  f->SetFunc(ci, method, params, objectIsConst, offset);
6652 }
6653 ////////////////////////////////////////////////////////////////////////////////
6654 
6655 void TCling::CallFunc_SetFunc(CallFunc_t* func, MethodInfo_t* info) const
6656 {
6657  TClingCallFunc* f = (TClingCallFunc*) func;
6658  TClingMethodInfo* minfo = (TClingMethodInfo*) info;
6659  f->SetFunc(minfo);
6660 }
6661 
6662 ////////////////////////////////////////////////////////////////////////////////
6663 /// Interface to cling function
6664 
6665 void TCling::CallFunc_SetFuncProto(CallFunc_t* func, ClassInfo_t* info, const char* method, const char* proto, Long_t* offset, EFunctionMatchMode mode /* = kConversionMatch */) const
6666 {
6667  TClingCallFunc* f = (TClingCallFunc*) func;
6668  TClingClassInfo* ci = (TClingClassInfo*) info;
6669  f->SetFuncProto(ci, method, proto, offset, mode);
6670 }
6671 
6672 ////////////////////////////////////////////////////////////////////////////////
6673 /// Interface to cling function
6674 
6675 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
6676 {
6677  TClingCallFunc* f = (TClingCallFunc*) func;
6678  TClingClassInfo* ci = (TClingClassInfo*) info;
6679  f->SetFuncProto(ci, method, proto, objectIsConst, offset, mode);
6680 }
6681 
6682 ////////////////////////////////////////////////////////////////////////////////
6683 /// Interface to cling function
6684 
6685 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
6686 {
6687  TClingCallFunc* f = (TClingCallFunc*) func;
6688  TClingClassInfo* ci = (TClingClassInfo*) info;
6689  llvm::SmallVector<clang::QualType, 4> funcProto;
6690  for (std::vector<TypeInfo_t*>::const_iterator iter = proto.begin(), end = proto.end();
6691  iter != end; ++iter) {
6692  funcProto.push_back( ((TClingTypeInfo*)(*iter))->GetQualType() );
6693  }
6694  f->SetFuncProto(ci, method, funcProto, offset, mode);
6695 }
6696 
6697 ////////////////////////////////////////////////////////////////////////////////
6698 /// Interface to cling function
6699 
6700 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
6701 {
6702  TClingCallFunc* f = (TClingCallFunc*) func;
6703  TClingClassInfo* ci = (TClingClassInfo*) info;
6704  llvm::SmallVector<clang::QualType, 4> funcProto;
6705  for (std::vector<TypeInfo_t*>::const_iterator iter = proto.begin(), end = proto.end();
6706  iter != end; ++iter) {
6707  funcProto.push_back( ((TClingTypeInfo*)(*iter))->GetQualType() );
6708  }
6709  f->SetFuncProto(ci, method, funcProto, objectIsConst, offset, mode);
6710 }
6711 
6712 //______________________________________________________________________________
6713 //
6714 // ClassInfo interface
6715 //
6716 
6717 ////////////////////////////////////////////////////////////////////////////////
6718 /// Return true if the entity pointed to by 'declid' is declared in
6719 /// the context described by 'info'. If info is null, look into the
6720 /// global scope (translation unit scope).
6721 
6722 Bool_t TCling::ClassInfo_Contains(ClassInfo_t *info, DeclId_t declid) const
6723 {
6724  if (!declid) return kFALSE;
6725 
6726  const clang::Decl *scope;
6727  if (info) scope = ((TClingClassInfo*)info)->GetDecl();
6728  else scope = fInterpreter->getCI()->getASTContext().getTranslationUnitDecl();
6729 
6730  const clang::Decl *decl = reinterpret_cast<const clang::Decl*>(declid);
6731  const clang::DeclContext *ctxt = clang::Decl::castToDeclContext(scope);
6732  if (!decl || !ctxt) return kFALSE;
6733  if (decl->getDeclContext()->Equals(ctxt))
6734  return kTRUE;
6735  else if (decl->getDeclContext()->isTransparentContext() &&
6736  decl->getDeclContext()->getParent()->Equals(ctxt))
6737  return kTRUE;
6738  return kFALSE;
6739 }
6740 
6741 ////////////////////////////////////////////////////////////////////////////////
6742 
6743 Long_t TCling::ClassInfo_ClassProperty(ClassInfo_t* cinfo) const
6744 {
6745  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
6746  return TClinginfo->ClassProperty();
6747 }
6748 
6749 ////////////////////////////////////////////////////////////////////////////////
6750 
6751 void TCling::ClassInfo_Delete(ClassInfo_t* cinfo) const
6752 {
6753  delete (TClingClassInfo*) cinfo;
6754 }
6755 
6756 ////////////////////////////////////////////////////////////////////////////////
6757 
6758 void TCling::ClassInfo_Delete(ClassInfo_t* cinfo, void* arena) const
6759 {
6760  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
6761  TClinginfo->Delete(arena,*fNormalizedCtxt);
6762 }
6763 
6764 ////////////////////////////////////////////////////////////////////////////////
6765 
6766 void TCling::ClassInfo_DeleteArray(ClassInfo_t* cinfo, void* arena, bool dtorOnly) const
6767 {
6768  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
6769  TClinginfo->DeleteArray(arena, dtorOnly,*fNormalizedCtxt);
6770 }
6771 
6772 ////////////////////////////////////////////////////////////////////////////////
6773 
6774 void TCling::ClassInfo_Destruct(ClassInfo_t* cinfo, void* arena) const
6775 {
6776  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
6777  TClinginfo->Destruct(arena,*fNormalizedCtxt);
6778 }
6779 
6780 ////////////////////////////////////////////////////////////////////////////////
6781 
6782 ClassInfo_t* TCling::ClassInfo_Factory(Bool_t all) const
6783 {
6785  return (ClassInfo_t*) new TClingClassInfo(fInterpreter, all);
6786 }
6787 
6788 ////////////////////////////////////////////////////////////////////////////////
6789 
6790 ClassInfo_t* TCling::ClassInfo_Factory(ClassInfo_t* cinfo) const
6791 {
6792  return (ClassInfo_t*) new TClingClassInfo(*(TClingClassInfo*)cinfo);
6793 }
6794 
6795 ////////////////////////////////////////////////////////////////////////////////
6796 
6797 ClassInfo_t* TCling::ClassInfo_Factory(const char* name) const
6798 {
6800  return (ClassInfo_t*) new TClingClassInfo(fInterpreter, name);
6801 }
6802 
6803 ////////////////////////////////////////////////////////////////////////////////
6804 
6805 int TCling::ClassInfo_GetMethodNArg(ClassInfo_t* cinfo, const char* method, const char* proto, Bool_t objectIsConst /* = false */, EFunctionMatchMode mode /* = kConversionMatch */) const
6806 {
6807  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
6808  return TClinginfo->GetMethodNArg(method, proto, objectIsConst, mode);
6809 }
6810 
6811 ////////////////////////////////////////////////////////////////////////////////
6812 
6813 bool TCling::ClassInfo_HasDefaultConstructor(ClassInfo_t* cinfo) const
6814 {
6815  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
6816  return TClinginfo->HasDefaultConstructor();
6817 }
6818 
6819 ////////////////////////////////////////////////////////////////////////////////
6820 
6821 bool TCling::ClassInfo_HasMethod(ClassInfo_t* cinfo, const char* name) const
6822 {
6823  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
6824  return TClinginfo->HasMethod(name);
6825 }
6826 
6827 ////////////////////////////////////////////////////////////////////////////////
6828 
6829 void TCling::ClassInfo_Init(ClassInfo_t* cinfo, const char* name) const
6830 {
6832  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
6833  TClinginfo->Init(name);
6834 }
6835 
6836 ////////////////////////////////////////////////////////////////////////////////
6837 
6838 void TCling::ClassInfo_Init(ClassInfo_t* cinfo, int tagnum) const
6839 {
6841  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
6842  TClinginfo->Init(tagnum);
6843 }
6844 
6845 ////////////////////////////////////////////////////////////////////////////////
6846 
6847 bool TCling::ClassInfo_IsBase(ClassInfo_t* cinfo, const char* name) const
6848 {
6849  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
6850  return TClinginfo->IsBase(name);
6851 }
6852 
6853 ////////////////////////////////////////////////////////////////////////////////
6854 
6855 bool TCling::ClassInfo_IsEnum(const char* name) const
6856 {
6857  return TClingClassInfo::IsEnum(fInterpreter, name);
6858 }
6859 
6860 ////////////////////////////////////////////////////////////////////////////////
6861 
6862 bool TCling::ClassInfo_IsLoaded(ClassInfo_t* cinfo) const
6863 {
6864  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
6865  return TClinginfo->IsLoaded();
6866 }
6867 
6868 ////////////////////////////////////////////////////////////////////////////////
6869 
6870 bool TCling::ClassInfo_IsValid(ClassInfo_t* cinfo) const
6871 {
6872  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
6873  return TClinginfo->IsValid();
6874 }
6875 
6876 ////////////////////////////////////////////////////////////////////////////////
6877 
6878 bool TCling::ClassInfo_IsValidMethod(ClassInfo_t* cinfo, const char* method, const char* proto, Long_t* offset, EFunctionMatchMode mode /* = kConversionMatch */) const
6879 {
6880  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
6881  return TClinginfo->IsValidMethod(method, proto, false, offset, mode);
6882 }
6883 
6884 ////////////////////////////////////////////////////////////////////////////////
6885 
6886 bool TCling::ClassInfo_IsValidMethod(ClassInfo_t* cinfo, const char* method, const char* proto, Bool_t objectIsConst, Long_t* offset, EFunctionMatchMode mode /* = kConversionMatch */) const
6887 {
6888  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
6889  return TClinginfo->IsValidMethod(method, proto, objectIsConst, offset, mode);
6890 }
6891 
6892 ////////////////////////////////////////////////////////////////////////////////
6893 
6894 int TCling::ClassInfo_Next(ClassInfo_t* cinfo) const
6895 {
6896  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
6897  return TClinginfo->Next();
6898 }
6899 
6900 ////////////////////////////////////////////////////////////////////////////////
6901 
6902 void* TCling::ClassInfo_New(ClassInfo_t* cinfo) const
6903 {
6904  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
6905  return TClinginfo->New(*fNormalizedCtxt);
6906 }
6907 
6908 ////////////////////////////////////////////////////////////////////////////////
6909 
6910 void* TCling::ClassInfo_New(ClassInfo_t* cinfo, int n) const
6911 {
6912  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
6913  return TClinginfo->New(n,*fNormalizedCtxt);
6914 }
6915 
6916 ////////////////////////////////////////////////////////////////////////////////
6917 
6918 void* TCling::ClassInfo_New(ClassInfo_t* cinfo, int n, void* arena) const
6919 {
6920  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
6921  return TClinginfo->New(n, arena,*fNormalizedCtxt);
6922 }
6923 
6924 ////////////////////////////////////////////////////////////////////////////////
6925 
6926 void* TCling::ClassInfo_New(ClassInfo_t* cinfo, void* arena) const
6927 {
6928  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
6929  return TClinginfo->New(arena,*fNormalizedCtxt);
6930 }
6931 
6932 ////////////////////////////////////////////////////////////////////////////////
6933 
6934 Long_t TCling::ClassInfo_Property(ClassInfo_t* cinfo) const
6935 {
6936  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
6937  return TClinginfo->Property();
6938 }
6939 
6940 ////////////////////////////////////////////////////////////////////////////////
6941 
6942 int TCling::ClassInfo_Size(ClassInfo_t* cinfo) const
6943 {
6944  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
6945  return TClinginfo->Size();
6946 }
6947 
6948 ////////////////////////////////////////////////////////////////////////////////
6949 
6950 Long_t TCling::ClassInfo_Tagnum(ClassInfo_t* cinfo) const
6951 {
6952  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
6953  return TClinginfo->Tagnum();
6954 }
6955 
6956 ////////////////////////////////////////////////////////////////////////////////
6957 
6958 const char* TCling::ClassInfo_FileName(ClassInfo_t* cinfo) const
6959 {
6960  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
6961  return TClinginfo->FileName();
6962 }
6963 
6964 ////////////////////////////////////////////////////////////////////////////////
6965 
6966 const char* TCling::ClassInfo_FullName(ClassInfo_t* cinfo) const
6967 {
6968  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
6969  TTHREAD_TLS_DECL(std::string,output);
6970  TClinginfo->FullName(output,*fNormalizedCtxt);
6971  return output.c_str();
6972 }
6973 
6974 ////////////////////////////////////////////////////////////////////////////////
6975 
6976 const char* TCling::ClassInfo_Name(ClassInfo_t* cinfo) const
6977 {
6978  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
6979  return TClinginfo->Name();
6980 }
6981 
6982 ////////////////////////////////////////////////////////////////////////////////
6983 
6984 const char* TCling::ClassInfo_Title(ClassInfo_t* cinfo) const
6985 {
6986  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
6987  return TClinginfo->Title();
6988 }
6989 
6990 ////////////////////////////////////////////////////////////////////////////////
6991 
6992 const char* TCling::ClassInfo_TmpltName(ClassInfo_t* cinfo) const
6993 {
6994  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
6995  return TClinginfo->TmpltName();
6996 }
6997 
6998 
6999 
7000 //______________________________________________________________________________
7001 //
7002 // BaseClassInfo interface
7003 //
7004 
7005 ////////////////////////////////////////////////////////////////////////////////
7006 
7007 void TCling::BaseClassInfo_Delete(BaseClassInfo_t* bcinfo) const
7008 {
7009  delete(TClingBaseClassInfo*) bcinfo;
7010 }
7011 
7012 ////////////////////////////////////////////////////////////////////////////////
7013 
7014 BaseClassInfo_t* TCling::BaseClassInfo_Factory(ClassInfo_t* cinfo) const
7015 {
7017  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
7018  return (BaseClassInfo_t*) new TClingBaseClassInfo(fInterpreter, TClinginfo);
7019 }
7020 
7021 ////////////////////////////////////////////////////////////////////////////////
7022 
7023 BaseClassInfo_t* TCling::BaseClassInfo_Factory(ClassInfo_t* derived,
7024  ClassInfo_t* base) const
7025 {
7027  TClingClassInfo* TClinginfo = (TClingClassInfo*) derived;
7028  TClingClassInfo* TClinginfoBase = (TClingClassInfo*) base;
7029  return (BaseClassInfo_t*) new TClingBaseClassInfo(fInterpreter, TClinginfo, TClinginfoBase);
7030 }
7031 
7032 ////////////////////////////////////////////////////////////////////////////////
7033 
7034 int TCling::BaseClassInfo_Next(BaseClassInfo_t* bcinfo) const
7035 {
7036  TClingBaseClassInfo* TClinginfo = (TClingBaseClassInfo*) bcinfo;
7037  return TClinginfo->Next();
7038 }
7039 
7040 ////////////////////////////////////////////////////////////////////////////////
7041 
7042 int TCling::BaseClassInfo_Next(BaseClassInfo_t* bcinfo, int onlyDirect) const
7043 {
7044  TClingBaseClassInfo* TClinginfo = (TClingBaseClassInfo*) bcinfo;
7045  return TClinginfo->Next(onlyDirect);
7046 }
7047 
7048 ////////////////////////////////////////////////////////////////////////////////
7049 
7050 Long_t TCling::BaseClassInfo_Offset(BaseClassInfo_t* toBaseClassInfo, void * address, bool isDerivedObject) const
7051 {
7052  TClingBaseClassInfo* TClinginfo = (TClingBaseClassInfo*) toBaseClassInfo;
7053  return TClinginfo->Offset(address, isDerivedObject);
7054 }
7055 
7056 ////////////////////////////////////////////////////////////////////////////////
7057 
7058 Long_t TCling::ClassInfo_GetBaseOffset(ClassInfo_t* fromDerived, ClassInfo_t* toBase, void * address, bool isDerivedObject) const
7059 {
7060  TClingClassInfo* TClinginfo = (TClingClassInfo*) fromDerived;
7061  TClingClassInfo* TClinginfoBase = (TClingClassInfo*) toBase;
7062  // Offset to the class itself.
7063  if (TClinginfo->GetDecl() == TClinginfoBase->GetDecl()) {
7064  return 0;
7065  }
7066  return TClinginfo->GetBaseOffset(TClinginfoBase, address, isDerivedObject);
7067 }
7068 
7069 ////////////////////////////////////////////////////////////////////////////////
7070 
7071 Long_t TCling::BaseClassInfo_Property(BaseClassInfo_t* bcinfo) const
7072 {
7073  TClingBaseClassInfo* TClinginfo = (TClingBaseClassInfo*) bcinfo;
7074  return TClinginfo->Property();
7075 }
7076 
7077 ////////////////////////////////////////////////////////////////////////////////
7078 
7079 ClassInfo_t *TCling::BaseClassInfo_ClassInfo(BaseClassInfo_t *bcinfo) const
7080 {
7081  TClingBaseClassInfo* TClinginfo = (TClingBaseClassInfo*) bcinfo;
7082  return (ClassInfo_t *)TClinginfo->GetBase();
7083 }
7084 
7085 ////////////////////////////////////////////////////////////////////////////////
7086 
7087 Long_t TCling::BaseClassInfo_Tagnum(BaseClassInfo_t* bcinfo) const
7088 {
7089  TClingBaseClassInfo* TClinginfo = (TClingBaseClassInfo*) bcinfo;
7090  return TClinginfo->Tagnum();
7091 }
7092 
7093 ////////////////////////////////////////////////////////////////////////////////
7094 
7095 const char* TCling::BaseClassInfo_FullName(BaseClassInfo_t* bcinfo) const
7096 {
7097  TClingBaseClassInfo* TClinginfo = (TClingBaseClassInfo*) bcinfo;
7098  TTHREAD_TLS_DECL(std::string,output);
7099  TClinginfo->FullName(output,*fNormalizedCtxt);
7100  return output.c_str();
7101 }
7102 
7103 ////////////////////////////////////////////////////////////////////////////////
7104 
7105 const char* TCling::BaseClassInfo_Name(BaseClassInfo_t* bcinfo) const
7106 {
7107  TClingBaseClassInfo* TClinginfo = (TClingBaseClassInfo*) bcinfo;
7108  return TClinginfo->Name();
7109 }
7110 
7111 ////////////////////////////////////////////////////////////////////////////////
7112 
7113 const char* TCling::BaseClassInfo_TmpltName(BaseClassInfo_t* bcinfo) const
7114 {
7115  TClingBaseClassInfo* TClinginfo = (TClingBaseClassInfo*) bcinfo;
7116  return TClinginfo->TmpltName();
7117 }
7118 
7119 //______________________________________________________________________________
7120 //
7121 // DataMemberInfo interface
7122 //
7123 
7124 ////////////////////////////////////////////////////////////////////////////////
7125 
7126 int TCling::DataMemberInfo_ArrayDim(DataMemberInfo_t* dminfo) const
7127 {
7128  TClingDataMemberInfo* TClinginfo = (TClingDataMemberInfo*) dminfo;
7129  return TClinginfo->ArrayDim();
7130 }
7131 
7132 ////////////////////////////////////////////////////////////////////////////////
7133 
7134 void TCling::DataMemberInfo_Delete(DataMemberInfo_t* dminfo) const
7135 {
7136  delete(TClingDataMemberInfo*) dminfo;
7137 }
7138 
7139 ////////////////////////////////////////////////////////////////////////////////
7140 
7141 DataMemberInfo_t* TCling::DataMemberInfo_Factory(ClassInfo_t* clinfo /*= 0*/) const
7142 {
7144  TClingClassInfo* TClingclass_info = (TClingClassInfo*) clinfo;
7145  return (DataMemberInfo_t*) new TClingDataMemberInfo(fInterpreter, TClingclass_info);
7146 }
7147 
7148 ////////////////////////////////////////////////////////////////////////////////
7149 
7150 DataMemberInfo_t* TCling::DataMemberInfo_Factory(DeclId_t declid, ClassInfo_t* clinfo) const
7151 {
7153  const clang::Decl* decl = reinterpret_cast<const clang::Decl*>(declid);
7154  const clang::ValueDecl* vd = llvm::dyn_cast_or_null<clang::ValueDecl>(decl);
7155  return (DataMemberInfo_t*) new TClingDataMemberInfo(fInterpreter, vd, (TClingClassInfo*)clinfo);
7156 }
7157 
7158 ////////////////////////////////////////////////////////////////////////////////
7159 
7160 DataMemberInfo_t* TCling::DataMemberInfo_FactoryCopy(DataMemberInfo_t* dminfo) const
7161 {
7162  TClingDataMemberInfo* TClinginfo = (TClingDataMemberInfo*) dminfo;
7163  return (DataMemberInfo_t*) new TClingDataMemberInfo(*TClinginfo);
7164 }
7165 
7166 ////////////////////////////////////////////////////////////////////////////////
7167 
7168 bool TCling::DataMemberInfo_IsValid(DataMemberInfo_t* dminfo) const
7169 {
7170  TClingDataMemberInfo* TClinginfo = (TClingDataMemberInfo*) dminfo;
7171  return TClinginfo->IsValid();
7172 }
7173 
7174 ////////////////////////////////////////////////////////////////////////////////
7175 
7176 int TCling::DataMemberInfo_MaxIndex(DataMemberInfo_t* dminfo, Int_t dim) const
7177 {
7178  TClingDataMemberInfo* TClinginfo = (TClingDataMemberInfo*) dminfo;
7179  return TClinginfo->MaxIndex(dim);
7180 }
7181 
7182 ////////////////////////////////////////////////////////////////////////////////
7183 
7184 int TCling::DataMemberInfo_Next(DataMemberInfo_t* dminfo) const
7185 {
7186  TClingDataMemberInfo* TClinginfo = (TClingDataMemberInfo*) dminfo;
7187  return TClinginfo->Next();
7188 }
7189 
7190 ////////////////////////////////////////////////////////////////////////////////
7191 
7192 Long_t TCling::DataMemberInfo_Offset(DataMemberInfo_t* dminfo) const
7193 {
7194  TClingDataMemberInfo* TClinginfo = (TClingDataMemberInfo*) dminfo;
7195  return TClinginfo->Offset();
7196 }
7197 
7198 ////////////////////////////////////////////////////////////////////////////////
7199 
7200 Long_t TCling::DataMemberInfo_Property(DataMemberInfo_t* dminfo) const
7201 {
7202  TClingDataMemberInfo* TClinginfo = (TClingDataMemberInfo*) dminfo;
7203  return TClinginfo->Property();
7204 }
7205 
7206 ////////////////////////////////////////////////////////////////////////////////
7207 
7208 Long_t TCling::DataMemberInfo_TypeProperty(DataMemberInfo_t* dminfo) const
7209 {
7210  TClingDataMemberInfo* TClinginfo = (TClingDataMemberInfo*) dminfo;
7211  return TClinginfo->TypeProperty();
7212 }
7213 
7214 ////////////////////////////////////////////////////////////////////////////////
7215 
7216 int TCling::DataMemberInfo_TypeSize(DataMemberInfo_t* dminfo) const
7217 {
7218  TClingDataMemberInfo* TClinginfo = (TClingDataMemberInfo*) dminfo;
7219  return TClinginfo->TypeSize();
7220 }
7221 
7222 ////////////////////////////////////////////////////////////////////////////////
7223 
7224 const char* TCling::DataMemberInfo_TypeName(DataMemberInfo_t* dminfo) const
7225 {
7226  TClingDataMemberInfo* TClinginfo = (TClingDataMemberInfo*) dminfo;
7227  return TClinginfo->TypeName();
7228 }
7229 
7230 ////////////////////////////////////////////////////////////////////////////////
7231 
7232 const char* TCling::DataMemberInfo_TypeTrueName(DataMemberInfo_t* dminfo) const
7233 {
7234  TClingDataMemberInfo* TClinginfo = (TClingDataMemberInfo*) dminfo;
7235  return TClinginfo->TypeTrueName(*fNormalizedCtxt);
7236 }
7237 
7238 ////////////////////////////////////////////////////////////////////////////////
7239 
7240 const char* TCling::DataMemberInfo_Name(DataMemberInfo_t* dminfo) const
7241 {
7242  TClingDataMemberInfo* TClinginfo = (TClingDataMemberInfo*) dminfo;
7243  return TClinginfo->Name();
7244 }
7245 
7246 ////////////////////////////////////////////////////////////////////////////////
7247 
7248 const char* TCling::DataMemberInfo_Title(DataMemberInfo_t* dminfo) const
7249 {
7250  TClingDataMemberInfo* TClinginfo = (TClingDataMemberInfo*) dminfo;
7251  return TClinginfo->Title();
7252 }
7253 
7254 ////////////////////////////////////////////////////////////////////////////////
7255 
7256 const char* TCling::DataMemberInfo_ValidArrayIndex(DataMemberInfo_t* dminfo) const
7257 {
7258  TTHREAD_TLS_DECL(std::string,result);
7259 
7260  TClingDataMemberInfo* TClinginfo = (TClingDataMemberInfo*) dminfo;
7261  result = TClinginfo->ValidArrayIndex().str();
7262  return result.c_str();
7263 }
7264 
7265 ////////////////////////////////////////////////////////////////////////////////
7266 
7267 void TCling::SetDeclAttr(DeclId_t declId, const char* attribute)
7268 {
7269  Decl* decl = static_cast<Decl*>(const_cast<void*>(declId));
7270  ASTContext &C = decl->getASTContext();
7271  SourceRange commentRange; // this is a fake comment range
7272  decl->addAttr( new (C) AnnotateAttr( commentRange, C, attribute, 0 ) );
7273 }
7274 
7275 //______________________________________________________________________________
7276 //
7277 // Function Template interface
7278 //
7279 
7280 ////////////////////////////////////////////////////////////////////////////////
7281 
7282 static void ConstructorName(std::string &name, const clang::NamedDecl *decl,
7283  cling::Interpreter &interp,
7284  const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt)
7285 {
7286  const clang::TypeDecl* td = llvm::dyn_cast<clang::TypeDecl>(decl->getDeclContext());
7287  if (!td) return;
7288 
7289  clang::QualType qualType(td->getTypeForDecl(),0);
7290  ROOT::TMetaUtils::GetNormalizedName(name, qualType, interp, normCtxt);
7291  unsigned int level = 0;
7292  for(size_t cursor = name.length()-1; cursor != 0; --cursor) {
7293  if (name[cursor] == '>') ++level;
7294  else if (name[cursor] == '<' && level) --level;
7295  else if (level == 0 && name[cursor] == ':') {
7296  name.erase(0,cursor+1);
7297  break;
7298  }
7299  }
7300 }
7301 
7302 ////////////////////////////////////////////////////////////////////////////////
7303 
7304 void TCling::GetFunctionName(const clang::FunctionDecl *decl, std::string &output) const
7305 {
7306  output.clear();
7307  if (llvm::isa<clang::CXXConstructorDecl>(decl))
7308  {
7309  ConstructorName(output, decl, *fInterpreter, *fNormalizedCtxt);
7310 
7311  } else if (llvm::isa<clang::CXXDestructorDecl>(decl))
7312  {
7313  ConstructorName(output, decl, *fInterpreter, *fNormalizedCtxt);
7314  output.insert(output.begin(), '~');
7315  } else {
7316  llvm::raw_string_ostream stream(output);
7317  decl->getNameForDiagnostic(stream, decl->getASTContext().getPrintingPolicy(), /*Qualified=*/false);
7318  }
7319 }
7320 
7321 ////////////////////////////////////////////////////////////////////////////////
7322 /// Return a unique identifier of the declaration represented by the
7323 /// FuncTempInfo
7324 
7325 TInterpreter::DeclId_t TCling::GetDeclId(FuncTempInfo_t *info) const
7326 {
7327  return (DeclId_t)info;
7328 }
7329 
7330 ////////////////////////////////////////////////////////////////////////////////
7331 /// Delete the FuncTempInfo_t
7332 
7333 void TCling::FuncTempInfo_Delete(FuncTempInfo_t * /* ft_info */) const
7334 {
7335  // Currently the address of ft_info is actually the decl itself,
7336  // so we have nothing to do.
7337 }
7338 
7339 ////////////////////////////////////////////////////////////////////////////////
7340 /// Construct a FuncTempInfo_t
7341 
7342 FuncTempInfo_t *TCling::FuncTempInfo_Factory(DeclId_t declid) const
7343 {
7344  // Currently the address of ft_info is actually the decl itself,
7345  // so we have nothing to do.
7346 
7347  return (FuncTempInfo_t*)const_cast<void*>(declid);
7348 }
7349 
7350 ////////////////////////////////////////////////////////////////////////////////
7351 /// Construct a FuncTempInfo_t
7352 
7353 FuncTempInfo_t *TCling::FuncTempInfo_FactoryCopy(FuncTempInfo_t *ft_info) const
7354 {
7355  // Currently the address of ft_info is actually the decl itself,
7356  // so we have nothing to do.
7357 
7358  return (FuncTempInfo_t*)ft_info;
7359 }
7360 
7361 ////////////////////////////////////////////////////////////////////////////////
7362 /// Check validity of a FuncTempInfo_t
7363 
7364 Bool_t TCling::FuncTempInfo_IsValid(FuncTempInfo_t *t_info) const
7365 {
7366  // Currently the address of ft_info is actually the decl itself,
7367  // so we have nothing to do.
7368 
7369  return t_info != 0;
7370 }
7371 
7372 ////////////////////////////////////////////////////////////////////////////////
7373 /// Return the maximum number of template arguments of the
7374 /// function template described by ft_info.
7375 
7376 UInt_t TCling::FuncTempInfo_TemplateNargs(FuncTempInfo_t *ft_info) const
7377 {
7378  if (!ft_info) return 0;
7379  const clang::FunctionTemplateDecl *ft = (const clang::FunctionTemplateDecl*)ft_info;
7380  return ft->getTemplateParameters()->size();
7381 }
7382 
7383 ////////////////////////////////////////////////////////////////////////////////
7384 /// Return the number of required template arguments of the
7385 /// function template described by ft_info.
7386 
7387 UInt_t TCling::FuncTempInfo_TemplateMinReqArgs(FuncTempInfo_t *ft_info) const
7388 {
7389  if (!ft_info) return 0;
7390  const clang::FunctionTemplateDecl *ft = (clang::FunctionTemplateDecl*)ft_info;
7391  return ft->getTemplateParameters()->getMinRequiredArguments();
7392 }
7393 
7394 ////////////////////////////////////////////////////////////////////////////////
7395 /// Return the property of the function template.
7396 
7397 Long_t TCling::FuncTempInfo_Property(FuncTempInfo_t *ft_info) const
7398 {
7399  if (!ft_info) return 0;
7400 
7401  long property = 0L;
7402  property |= kIsCompiled;
7403 
7404  const clang::FunctionTemplateDecl *ft = (clang::FunctionTemplateDecl*)ft_info;
7405 
7406  switch (ft->getAccess()) {
7407  case clang::AS_public:
7408  property |= kIsPublic;
7409  break;
7410  case clang::AS_protected:
7411  property |= kIsProtected;
7412  break;
7413  case clang::AS_private:
7414  property |= kIsPrivate;
7415  break;
7416  case clang::AS_none:
7417  if (ft->getDeclContext()->isNamespace())
7418  property |= kIsPublic;
7419  break;
7420  default:
7421  // IMPOSSIBLE
7422  break;
7423  }
7424 
7425  const clang::FunctionDecl *fd = ft->getTemplatedDecl();
7426  if (const clang::CXXMethodDecl *md =
7427  llvm::dyn_cast<clang::CXXMethodDecl>(fd)) {
7428  if (md->getTypeQualifiers() & clang::Qualifiers::Const) {
7429  property |= kIsConstant | kIsConstMethod;
7430  }
7431  if (md->isVirtual()) {
7432  property |= kIsVirtual;
7433  }
7434  if (md->isPure()) {
7435  property |= kIsPureVirtual;
7436  }
7437  if (const clang::CXXConstructorDecl *cd =
7438  llvm::dyn_cast<clang::CXXConstructorDecl>(md)) {
7439  if (cd->isExplicit()) {
7440  property |= kIsExplicit;
7441  }
7442  }
7443  else if (const clang::CXXConversionDecl *cd =
7444  llvm::dyn_cast<clang::CXXConversionDecl>(md)) {
7445  if (cd->isExplicit()) {
7446  property |= kIsExplicit;
7447  }
7448  }
7449  }
7450  return property;
7451 }
7452 
7453 ////////////////////////////////////////////////////////////////////////////////
7454 /// Return the name of this function template.
7455 
7456 void TCling::FuncTempInfo_Name(FuncTempInfo_t *ft_info, TString &output) const
7457 {
7458  output.Clear();
7459  if (!ft_info) return;
7460  const clang::FunctionTemplateDecl *ft = (clang::FunctionTemplateDecl*)ft_info;
7461  std::string buf;
7462  GetFunctionName(ft->getTemplatedDecl(), buf);
7463  output = buf;
7464 }
7465 
7466 ////////////////////////////////////////////////////////////////////////////////
7467 /// Return the comments associates with this function template.
7468 
7469 void TCling::FuncTempInfo_Title(FuncTempInfo_t *ft_info, TString &output) const
7470 {
7471  output.Clear();
7472  if (!ft_info) return;
7473  const clang::FunctionTemplateDecl *ft = (const clang::FunctionTemplateDecl*)ft_info;
7474 
7475  // Iterate over the redeclarations, we can have multiple definitions in the
7476  // redecl chain (came from merging of pcms).
7477  if (const RedeclarableTemplateDecl *AnnotFD
7478  = ROOT::TMetaUtils::GetAnnotatedRedeclarable((const RedeclarableTemplateDecl*)ft)) {
7479  if (AnnotateAttr *A = AnnotFD->getAttr<AnnotateAttr>()) {
7480  output = A->getAnnotation().str();
7481  return;
7482  }
7483  }
7484  if (!ft->isFromASTFile()) {
7485  // Try to get the comment from the header file if present
7486  // but not for decls from AST file, where rootcling would have
7487  // created an annotation
7488  output = ROOT::TMetaUtils::GetComment(*ft).str();
7489  }
7490 }
7491 
7492 
7493 //______________________________________________________________________________
7494 //
7495 // MethodInfo interface
7496 //
7497 
7498 ////////////////////////////////////////////////////////////////////////////////
7499 /// Interface to cling function
7500 
7501 void TCling::MethodInfo_Delete(MethodInfo_t* minfo) const
7502 {
7503  delete(TClingMethodInfo*) minfo;
7504 }
7505 
7506 ////////////////////////////////////////////////////////////////////////////////
7507 
7508 void TCling::MethodInfo_CreateSignature(MethodInfo_t* minfo, TString& signature) const
7509 {
7510  TClingMethodInfo* info = (TClingMethodInfo*) minfo;
7511  info->CreateSignature(signature);
7512 }
7513 
7514 ////////////////////////////////////////////////////////////////////////////////
7515 
7516 MethodInfo_t* TCling::MethodInfo_Factory() const
7517 {
7519  return (MethodInfo_t*) new TClingMethodInfo(fInterpreter);
7520 }
7521 
7522 ////////////////////////////////////////////////////////////////////////////////
7523 
7524 MethodInfo_t* TCling::MethodInfo_Factory(ClassInfo_t* clinfo) const
7525 {
7527  return (MethodInfo_t*) new TClingMethodInfo(fInterpreter, (TClingClassInfo*)clinfo);
7528 }
7529 
7530 ////////////////////////////////////////////////////////////////////////////////
7531 
7532 MethodInfo_t* TCling::MethodInfo_Factory(DeclId_t declid) const
7533 {
7534  const clang::Decl* decl = reinterpret_cast<const clang::Decl*>(declid);
7536  const clang::FunctionDecl* fd = llvm::dyn_cast_or_null<clang::FunctionDecl>(decl);
7537  return (MethodInfo_t*) new TClingMethodInfo(fInterpreter, fd);
7538 }
7539 
7540 ////////////////////////////////////////////////////////////////////////////////
7541 
7542 MethodInfo_t* TCling::MethodInfo_FactoryCopy(MethodInfo_t* minfo) const
7543 {
7544  return (MethodInfo_t*) new TClingMethodInfo(*(TClingMethodInfo*)minfo);
7545 }
7546 
7547 ////////////////////////////////////////////////////////////////////////////////
7548 
7549 void* TCling::MethodInfo_InterfaceMethod(MethodInfo_t* minfo) const
7550 {
7551  TClingMethodInfo* info = (TClingMethodInfo*) minfo;
7552  return info->InterfaceMethod(*fNormalizedCtxt);
7553 }
7554 
7555 ////////////////////////////////////////////////////////////////////////////////
7556 
7557 bool TCling::MethodInfo_IsValid(MethodInfo_t* minfo) const
7558 {
7559  TClingMethodInfo* info = (TClingMethodInfo*) minfo;
7560  return info->IsValid();
7561 }
7562 
7563 ////////////////////////////////////////////////////////////////////////////////
7564 
7565 int TCling::MethodInfo_NArg(MethodInfo_t* minfo) const
7566 {
7567  TClingMethodInfo* info = (TClingMethodInfo*) minfo;
7568  return info->NArg();
7569 }
7570 
7571 ////////////////////////////////////////////////////////////////////////////////
7572 
7573 int TCling::MethodInfo_NDefaultArg(MethodInfo_t* minfo) const
7574 {
7575  TClingMethodInfo* info = (TClingMethodInfo*) minfo;
7576  return info->NDefaultArg();
7577 }
7578 
7579 ////////////////////////////////////////////////////////////////////////////////
7580 
7581 int TCling::MethodInfo_Next(MethodInfo_t* minfo) const
7582 {
7583  TClingMethodInfo* info = (TClingMethodInfo*) minfo;
7584  return info->Next();
7585 }
7586 
7587 ////////////////////////////////////////////////////////////////////////////////
7588 
7589 Long_t TCling::MethodInfo_Property(MethodInfo_t* minfo) const
7590 {
7591  TClingMethodInfo* info = (TClingMethodInfo*) minfo;
7592  return info->Property();
7593 }
7594 
7595 ////////////////////////////////////////////////////////////////////////////////
7596 
7597 Long_t TCling::MethodInfo_ExtraProperty(MethodInfo_t* minfo) const
7598 {
7599  TClingMethodInfo* info = (TClingMethodInfo*) minfo;
7600  return info->ExtraProperty();
7601 }
7602 
7603 ////////////////////////////////////////////////////////////////////////////////
7604 
7605 TypeInfo_t* TCling::MethodInfo_Type(MethodInfo_t* minfo) const
7606 {
7607  TClingMethodInfo* info = (TClingMethodInfo*) minfo;
7608  return (TypeInfo_t*)info->Type();
7609 }
7610 
7611 ////////////////////////////////////////////////////////////////////////////////
7612 
7613 const char* TCling::MethodInfo_GetMangledName(MethodInfo_t* minfo) const
7614 {
7615  TClingMethodInfo* info = (TClingMethodInfo*) minfo;
7616  TTHREAD_TLS_DECL(TString, mangled_name);
7617  mangled_name = info->GetMangledName();
7618  return mangled_name;
7619 }
7620 
7621 ////////////////////////////////////////////////////////////////////////////////
7622 
7623 const char* TCling::MethodInfo_GetPrototype(MethodInfo_t* minfo) const
7624 {
7625  TClingMethodInfo* info = (TClingMethodInfo*) minfo;
7626  return info->GetPrototype(*fNormalizedCtxt);
7627 }
7628 
7629 ////////////////////////////////////////////////////////////////////////////////
7630 
7631 const char* TCling::MethodInfo_Name(MethodInfo_t* minfo) const
7632 {
7633  TClingMethodInfo* info = (TClingMethodInfo*) minfo;
7634  return info->Name(*fNormalizedCtxt);
7635 }
7636 
7637 ////////////////////////////////////////////////////////////////////////////////
7638 
7639 const char* TCling::MethodInfo_TypeName(MethodInfo_t* minfo) const
7640 {
7641  TClingMethodInfo* info = (TClingMethodInfo*) minfo;
7642  return info->TypeName();
7643 }
7644 
7645 ////////////////////////////////////////////////////////////////////////////////
7646 
7647 std::string TCling::MethodInfo_TypeNormalizedName(MethodInfo_t* minfo) const
7648 {
7649  TClingMethodInfo* info = (TClingMethodInfo*) minfo;
7650  if (info && info->IsValid())
7651  return info->Type()->NormalizedName(*fNormalizedCtxt);
7652  else
7653  return "";
7654 }
7655 
7656 ////////////////////////////////////////////////////////////////////////////////
7657 
7658 const char* TCling::MethodInfo_Title(MethodInfo_t* minfo) const
7659 {
7660  TClingMethodInfo* info = (TClingMethodInfo*) minfo;
7661  return info->Title();
7662 }
7663 
7664 ////////////////////////////////////////////////////////////////////////////////
7665 
7667 {
7668  if (func) {
7669  return MethodInfo_MethodCallReturnType(func->fInfo);
7670  } else {
7671  return EReturnType::kOther;
7672  }
7673 }
7674 
7675 ////////////////////////////////////////////////////////////////////////////////
7676 
7677 auto TCling::MethodInfo_MethodCallReturnType(MethodInfo_t* minfo) const -> EReturnType
7678 {
7679  TClingMethodInfo* info = (TClingMethodInfo*) minfo;
7680  if (info && info->IsValid()) {
7681  TClingTypeInfo *typeinfo = info->Type();
7682  clang::QualType QT( typeinfo->GetQualType().getCanonicalType() );
7683  if (QT->isEnumeralType()) {
7684  return EReturnType::kLong;
7685  } else if (QT->isPointerType()) {
7686  // Look for char*
7687  QT = llvm::cast<clang::PointerType>(QT)->getPointeeType();
7688  if ( QT->isCharType() ) {
7689  return EReturnType::kString;
7690  } else {
7691  return EReturnType::kOther;
7692  }
7693  } else if ( QT->isFloatingType() ) {
7694  int sz = typeinfo->Size();
7695  if (sz == 4 || sz == 8) {
7696  // Support only float and double.
7697  return EReturnType::kDouble;
7698  } else {
7699  return EReturnType::kOther;
7700  }
7701  } else if ( QT->isIntegerType() ) {
7702  int sz = typeinfo->Size();
7703  if (sz <= 8) {
7704  // Support only up to long long ... but
7705  // FIXME the TMethodCall::Execute only
7706  // return long (4 bytes) ...
7707  // The v5 implementation of TMethodCall::ReturnType
7708  // was not making the distinction so we let it go
7709  // as is for now, but we really need to upgrade
7710  // TMethodCall::Execute ...
7711  return EReturnType::kLong;
7712  } else {
7713  return EReturnType::kOther;
7714  }
7715  } else {
7716  return EReturnType::kOther;
7717  }
7718  } else {
7719  return EReturnType::kOther;
7720  }
7721 }
7722 
7723 //______________________________________________________________________________
7724 //
7725 // MethodArgInfo interface
7726 //
7727 
7728 ////////////////////////////////////////////////////////////////////////////////
7729 
7730 void TCling::MethodArgInfo_Delete(MethodArgInfo_t* marginfo) const
7731 {
7732  delete(TClingMethodArgInfo*) marginfo;
7733 }
7734 
7735 ////////////////////////////////////////////////////////////////////////////////
7736 
7737 MethodArgInfo_t* TCling::MethodArgInfo_Factory() const
7738 {
7740  return (MethodArgInfo_t*) new TClingMethodArgInfo(fInterpreter);
7741 }
7742 
7743 ////////////////////////////////////////////////////////////////////////////////
7744 
7745 MethodArgInfo_t* TCling::MethodArgInfo_Factory(MethodInfo_t *minfo) const
7746 {
7748  return (MethodArgInfo_t*) new TClingMethodArgInfo(fInterpreter, (TClingMethodInfo*)minfo);
7749 }
7750 
7751 ////////////////////////////////////////////////////////////////////////////////
7752 
7753 MethodArgInfo_t* TCling::MethodArgInfo_FactoryCopy(MethodArgInfo_t* marginfo) const
7754 {
7755  return (MethodArgInfo_t*)
7756  new TClingMethodArgInfo(*(TClingMethodArgInfo*)marginfo);
7757 }
7758 
7759 ////////////////////////////////////////////////////////////////////////////////
7760 
7761 bool TCling::MethodArgInfo_IsValid(MethodArgInfo_t* marginfo) const
7762 {
7763  TClingMethodArgInfo* info = (TClingMethodArgInfo*) marginfo;
7764  return info->IsValid();
7765 }
7766 
7767 ////////////////////////////////////////////////////////////////////////////////
7768 
7769 int TCling::MethodArgInfo_Next(MethodArgInfo_t* marginfo) const
7770 {
7771  TClingMethodArgInfo* info = (TClingMethodArgInfo*) marginfo;
7772  return info->Next();
7773 }
7774 
7775 ////////////////////////////////////////////////////////////////////////////////
7776 
7777 Long_t TCling::MethodArgInfo_Property(MethodArgInfo_t* marginfo) const
7778 {
7779  TClingMethodArgInfo* info = (TClingMethodArgInfo*) marginfo;
7780  return info->Property();
7781 }
7782 
7783 ////////////////////////////////////////////////////////////////////////////////
7784 
7785 const char* TCling::MethodArgInfo_DefaultValue(MethodArgInfo_t* marginfo) const
7786 {
7787  TClingMethodArgInfo* info = (TClingMethodArgInfo*) marginfo;
7788  return info->DefaultValue();
7789 }
7790 
7791 ////////////////////////////////////////////////////////////////////////////////
7792 
7793 const char* TCling::MethodArgInfo_Name(MethodArgInfo_t* marginfo) const
7794 {
7795  TClingMethodArgInfo* info = (TClingMethodArgInfo*) marginfo;
7796  return info->Name();
7797 }
7798 
7799 ////////////////////////////////////////////////////////////////////////////////
7800 
7801 const char* TCling::MethodArgInfo_TypeName(MethodArgInfo_t* marginfo) const
7802 {
7803  TClingMethodArgInfo* info = (TClingMethodArgInfo*) marginfo;
7804  return info->TypeName();
7805 }
7806 
7807 ////////////////////////////////////////////////////////////////////////////////
7808 
7809 std::string TCling::MethodArgInfo_TypeNormalizedName(MethodArgInfo_t* marginfo) const
7810 {
7811  TClingMethodArgInfo* info = (TClingMethodArgInfo*) marginfo;
7812  return info->Type()->NormalizedName(*fNormalizedCtxt);
7813 }
7814 
7815 //______________________________________________________________________________
7816 //
7817 // TypeInfo interface
7818 //
7819 
7820 ////////////////////////////////////////////////////////////////////////////////
7821 
7822 void TCling::TypeInfo_Delete(TypeInfo_t* tinfo) const
7823 {
7824  delete (TClingTypeInfo*) tinfo;
7825 }
7826 
7827 ////////////////////////////////////////////////////////////////////////////////
7828 
7829 TypeInfo_t* TCling::TypeInfo_Factory() const
7830 {
7832  return (TypeInfo_t*) new TClingTypeInfo(fInterpreter);
7833 }
7834 
7835 ////////////////////////////////////////////////////////////////////////////////
7836 
7837 TypeInfo_t* TCling::TypeInfo_Factory(const char *name) const
7838 {
7840  return (TypeInfo_t*) new TClingTypeInfo(fInterpreter, name);
7841 }
7842 
7843 ////////////////////////////////////////////////////////////////////////////////
7844 
7845 TypeInfo_t* TCling::TypeInfo_FactoryCopy(TypeInfo_t* tinfo) const
7846 {
7847  return (TypeInfo_t*) new TClingTypeInfo(*(TClingTypeInfo*)tinfo);
7848 }
7849 
7850 ////////////////////////////////////////////////////////////////////////////////
7851 
7852 void TCling::TypeInfo_Init(TypeInfo_t* tinfo, const char* name) const
7853 {
7855  TClingTypeInfo* TClinginfo = (TClingTypeInfo*) tinfo;
7856  TClinginfo->Init(name);
7857 }
7858 
7859 ////////////////////////////////////////////////////////////////////////////////
7860 
7861 bool TCling::TypeInfo_IsValid(TypeInfo_t* tinfo) const
7862 {
7863  TClingTypeInfo* TClinginfo = (TClingTypeInfo*) tinfo;
7864  return TClinginfo->IsValid();
7865 }
7866 
7867 ////////////////////////////////////////////////////////////////////////////////
7868 
7869 const char* TCling::TypeInfo_Name(TypeInfo_t* tinfo) const
7870 {
7871  TClingTypeInfo* TClinginfo = (TClingTypeInfo*) tinfo;
7872  return TClinginfo->Name();
7873 }
7874 
7875 ////////////////////////////////////////////////////////////////////////////////
7876 
7877 Long_t TCling::TypeInfo_Property(TypeInfo_t* tinfo) const
7878 {
7879  TClingTypeInfo* TClinginfo = (TClingTypeInfo*) tinfo;
7880  return TClinginfo->Property();
7881 }
7882 
7883 ////////////////////////////////////////////////////////////////////////////////
7884 
7885 int TCling::TypeInfo_RefType(TypeInfo_t* tinfo) const
7886 {
7887  TClingTypeInfo* TClinginfo = (TClingTypeInfo*) tinfo;
7888  return TClinginfo->RefType();
7889 }
7890 
7891 ////////////////////////////////////////////////////////////////////////////////
7892 
7893 int TCling::TypeInfo_Size(TypeInfo_t* tinfo) const
7894 {
7895  TClingTypeInfo* TClinginfo = (TClingTypeInfo*) tinfo;
7896  return TClinginfo->Size();
7897 }
7898 
7899 ////////////////////////////////////////////////////////////////////////////////
7900 
7901 const char* TCling::TypeInfo_TrueName(TypeInfo_t* tinfo) const
7902 {
7903  TClingTypeInfo* TClinginfo = (TClingTypeInfo*) tinfo;
7904  return TClinginfo->TrueName(*fNormalizedCtxt);
7905 }
7906 
7907 
7908 //______________________________________________________________________________
7909 //
7910 // TypedefInfo interface
7911 //
7912 
7913 ////////////////////////////////////////////////////////////////////////////////
7914 
7915 void TCling::TypedefInfo_Delete(TypedefInfo_t* tinfo) const
7916 {
7917  delete(TClingTypedefInfo*) tinfo;
7918 }
7919 
7920 ////////////////////////////////////////////////////////////////////////////////
7921 
7922 TypedefInfo_t* TCling::TypedefInfo_Factory() const
7923 {
7925  return (TypedefInfo_t*) new TClingTypedefInfo(fInterpreter);
7926 }
7927 
7928 ////////////////////////////////////////////////////////////////////////////////
7929 
7930 TypedefInfo_t* TCling::TypedefInfo_Factory(const char *name) const
7931 {
7933  return (TypedefInfo_t*) new TClingTypedefInfo(fInterpreter, name);
7934 }
7935 
7936 ////////////////////////////////////////////////////////////////////////////////
7937 
7938 TypedefInfo_t* TCling::TypedefInfo_FactoryCopy(TypedefInfo_t* tinfo) const
7939 {
7940  return (TypedefInfo_t*) new TClingTypedefInfo(*(TClingTypedefInfo*)tinfo);
7941 }
7942 
7943 ////////////////////////////////////////////////////////////////////////////////
7944 
7945 void TCling::TypedefInfo_Init(TypedefInfo_t* tinfo,
7946  const char* name) const
7947 {
7949  TClingTypedefInfo* TClinginfo = (TClingTypedefInfo*) tinfo;
7950  TClinginfo->Init(name);
7951 }
7952 
7953 ////////////////////////////////////////////////////////////////////////////////
7954 
7955 bool TCling::TypedefInfo_IsValid(TypedefInfo_t* tinfo) const
7956 {
7957  TClingTypedefInfo* TClinginfo = (TClingTypedefInfo*) tinfo;
7958  return TClinginfo->IsValid();
7959 }
7960 
7961 ////////////////////////////////////////////////////////////////////////////////
7962 
7963 Int_t TCling::TypedefInfo_Next(TypedefInfo_t* tinfo) const
7964 {
7965  TClingTypedefInfo* TClinginfo = (TClingTypedefInfo*) tinfo;
7966  return TClinginfo->Next();
7967 }
7968 
7969 ////////////////////////////////////////////////////////////////////////////////
7970 
7971 Long_t TCling::TypedefInfo_Property(TypedefInfo_t* tinfo) const
7972 {
7973  TClingTypedefInfo* TClinginfo = (TClingTypedefInfo*) tinfo;
7974  return TClinginfo->Property();
7975 }
7976 
7977 ////////////////////////////////////////////////////////////////////////////////
7978 
7979 int TCling::TypedefInfo_Size(TypedefInfo_t* tinfo) const
7980 {
7981  TClingTypedefInfo* TClinginfo = (TClingTypedefInfo*) tinfo;
7982  return TClinginfo->Size();
7983 }
7984 
7985 ////////////////////////////////////////////////////////////////////////////////
7986 
7987 const char* TCling::TypedefInfo_TrueName(TypedefInfo_t* tinfo) const
7988 {
7989  TClingTypedefInfo* TClinginfo = (TClingTypedefInfo*) tinfo;
7990  return TClinginfo->TrueName(*fNormalizedCtxt);
7991 }
7992 
7993 ////////////////////////////////////////////////////////////////////////////////
7994 
7995 const char* TCling::TypedefInfo_Name(TypedefInfo_t* tinfo) const
7996 {
7997  TClingTypedefInfo* TClinginfo = (TClingTypedefInfo*) tinfo;
7998  return TClinginfo->Name();
7999 }
8000 
8001 ////////////////////////////////////////////////////////////////////////////////
8002 
8003 const char* TCling::TypedefInfo_Title(TypedefInfo_t* tinfo) const
8004 {
8005  TClingTypedefInfo* TClinginfo = (TClingTypedefInfo*) tinfo;
8006  return TClinginfo->Title();
8007 }
int TCling__AutoLoadCallback(const char *className)
Definition: TCling.cxx:588
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:5977
void ResetCaches()
To clean out all caches.
Definition: TClass.cxx:3940
virtual TypeInfo_t * TypeInfo_Factory() const
Definition: TCling.cxx:7829
virtual const char * BaseName(const char *pathname)
Base name of a file name. Base name of /user/root is root.
Definition: TSystem.cxx:928
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:51
const TClingTypeInfo * Type() const
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:1264
const clang::FunctionTemplateDecl * GetFunctionTemplate(const char *fname) const
virtual const char * TypeInfo_Name(TypeInfo_t *) const
Definition: TCling.cxx:7869
virtual Bool_t FuncTempInfo_IsValid(FuncTempInfo_t *) const
Check validity of a FuncTempInfo_t.
Definition: TCling.cxx:7364
virtual void SetRcName(const char *name)
Definition: TEnv.h:149
virtual DeclId_t GetDataMemberAtAddr(const void *addr) const
Return pointer to cling DeclId for a data member with a given name.
Definition: TCling.cxx:3881
TObject * GetObjectAddress(const char *Name, void *&LookupCtx)
If the interpreter encounters Name, check whether that is an object ROOT could retrieve.
Definition: TCling.cxx:6312
virtual Long_t ClassInfo_Tagnum(ClassInfo_t *info) const
Definition: TCling.cxx:6950
bool IsValid() const
virtual int DataMemberInfo_ArrayDim(DataMemberInfo_t *dminfo) const
Definition: TCling.cxx:7126
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
int TCling__IsAutoLoadNamespaceCandidate(const clang::NamespaceDecl *nsDecl)
Definition: TCling.cxx:610
This class defines an abstract interface to a generic command line interpreter.
Definition: TInterpreter.h:50
int TCling__CompileMacro(const char *fileName, const char *options)
Definition: TCling.cxx:615
int GetClassVersion(const clang::RecordDecl *cl, const cling::Interpreter &interp)
Return the version number of the class or -1 if the function Class_Version does not exist...
An array of TObjects.
Definition: TObjArray.h:39
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:3938
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:651
virtual void * MethodInfo_InterfaceMethod(MethodInfo_t *minfo) const
Definition: TCling.cxx:7549
const char * TrueName(const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt) const
Return the normalized name of the type (i.e.
virtual const char * ClassInfo_FullName(ClassInfo_t *info) const
Definition: TCling.cxx:6966
int Size() const
Return the size in bytes of the underlying type of the current typedef.
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:4038
void TransactionRollback(const cling::Transaction &T)
Definition: TCling.cxx:5830
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
Definition: TObject.cxx:892
virtual TVirtualMutex * Factory(Bool_t=kFALSE)=0
void AddTemplAndNargsToKeep(const clang::ClassTemplateDecl *templ, unsigned int i)
Definition: TMetaUtils.cxx:341
virtual const char * BaseClassInfo_FullName(BaseClassInfo_t *bcinfo) const
Definition: TCling.cxx:7095
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:5853
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:2887
bool LoadPCM(TString pcmFileName, const char **headers, void(*triggerFunc)()) const
Tries to load a PCM; returns true on success.
Definition: TCling.cxx:1268
virtual void LoadEnums(TListOfEnums &cl) const
Create list of pointers to enums for TClass cl.
Definition: TCling.cxx:3381
void TCling__UpdateListsOnCommitted(const cling::Transaction &T, cling::Interpreter *)
Definition: TCling.cxx:539
virtual std::string MethodInfo_TypeNormalizedName(MethodInfo_t *minfo) const
Definition: TCling.cxx:7647
virtual void PostLoadCheck()
Do the initialization that can only be done after the CINT dictionary has been fully populated and ca...
Definition: TClass.cxx:5560
DeclId_t GetDeclId(const llvm::GlobalValue *gv) const
Return pointer to cling DeclId for a global value.
Definition: TCling.cxx:3803
virtual Long_t DataMemberInfo_Offset(DataMemberInfo_t *dminfo) const
Definition: TCling.cxx:7192
const char * GetDeclFileName() const
Definition: TClass.h:386
virtual Double_t CallFunc_ExecDouble(CallFunc_t *func, void *address) const
Definition: TCling.cxx:6501
virtual void CallFunc_ResetArg(CallFunc_t *func) const
Definition: TCling.cxx:6566
static void ConstructorName(std::string &name, const clang::NamedDecl *decl, cling::Interpreter &interp, const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt)
Definition: TCling.cxx:7282
R__EXTERN Int_t gErrorIgnoreLevel
Definition: TError.h:107
virtual Long_t MethodInfo_ExtraProperty(MethodInfo_t *minfo) const
Definition: TCling.cxx:7597
virtual const char * WorkingDirectory()
Return working directory.
Definition: TSystem.cxx:865
virtual Int_t UnLock()=0
Namespace for new ROOT classes and functions.
Definition: ROOT.py:1
std::map< SpecialObjectLookupCtx_t, SpecialObjectMap_t > fSpecialObjectMaps
Definition: TCling.h:143
virtual int UnloadFile(const char *path) const
Definition: TCling.cxx:6260
void Update(DeclId_t id)
Definition: TEnum.cxx:101
short Version_t
Definition: RtypesCore.h:61
static Bool_t Check(const char *cname, std::string &normname)
static const char **& GetExtraInterpreterArgs()
Definition: TROOT.cxx:2500
static cling::Interpreter::CompilationResult ExecAutoParse(const char *what, Bool_t header, cling::Interpreter *interpreter)
Parse the payload or header.
Definition: TCling.cxx:5109
TLine * line
void RegisterLoadedSharedLibrary(const char *name)
Register a new shared library name with the interpreter; add it to fSharedLibs.
Definition: TCling.cxx:2671
Collectable string class.
Definition: TObjString.h:32
clang::QualType GetQualType() const
float Float_t
Definition: RtypesCore.h:53
static void AddClassToDeclIdMap(TDictionary::DeclId_t id, TClass *cl)
static: Add a TClass* to the map of classes.
Definition: TClass.cxx:467
R__EXTERN TClassTable * gClassTable
Definition: TClassTable.h:97
Definition: TEnv.h:76
void UpdateListsOnCommitted(const cling::Transaction &T)
Definition: TCling.cxx:5567
TDictionary::DeclId_t DeclId_t
Definition: TInterpreter.h:236
const char * TmpltName() const
RooArgList L(const RooAbsArg &v1)
void * llvmLazyFunctionCreator(const std::string &mangled_name)
Autoload a library provided the mangled name of a missing symbol.
Definition: TCling.cxx:668
Dictionary for function template This class describes one single function template.
const clang::Decl * GetDecl() const
const char * TypeName() const
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:4026
double ExecDouble(void *address)
void Init(const char *name)
All ROOT classes may have RTTI (run time type identification) support added.
Definition: TDataMember.h:33
int GetSplit(const char *type, std::vector< std::string > &output, int &nestedLoc, EModType mode=TClassEdit::kNone)
Stores in output (after emptying it) the splited type.
Definition: TClassEdit.cxx:937
static TProtoClass * GetProtoNorm(const char *cname)
Given the class normalized name returns the TClassProto object for the class.
virtual void ClassInfo_Init(ClassInfo_t *info, const char *funcname) const
Definition: TCling.cxx:6829
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
R__EXTERN TVirtualMutex * gInterpreterMutex
Definition: TInterpreter.h:46
bool TClingLookupHelper__ExistingTypeCheck(const std::string &tname, std::string &result)
Try hard to avoid looking up in the Cling database as this could enduce an unwanted autoparsing...
Definition: TCling.cxx:901
virtual DataMemberInfo_t * DataMemberInfo_Factory(ClassInfo_t *clinfo=0) const
Definition: TCling.cxx:7141
const char * Name() const
TList * GetListOfEnums(Bool_t load=kTRUE)
Return list containing the TEnums of a class.
Definition: TClass.cxx:3478
TString & ReplaceAll(const TString &s1, const TString &s2)
Definition: TString.h:635
virtual bool ClassInfo_HasDefaultConstructor(ClassInfo_t *info) const
Definition: TCling.cxx:6813
void Init(const char *name)
Lookup named typedef and reset the iterator to point to it.
#define assert(cond)
Definition: unittest.h:542
std::atomic< TListOfEnums * > fEnums
Definition: TClass.h:185
llvm::StringRef ValidArrayIndex() const
virtual const char * MethodArgInfo_DefaultValue(MethodArgInfo_t *marginfo) const
Definition: TCling.cxx:7785
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:1362
virtual void Update()=0
TClingMethodInfo GetMethod(const char *fname) const
#define gDirectory
Definition: TDirectory.h:218
Bool_t TestBit(UInt_t f) const
Definition: TObject.h:173
void SetFunc(const TClingClassInfo *info, const char *method, const char *arglist, long *poffset)
Double_t distance(const TPoint2 &p1, const TPoint2 &p2)
Definition: CsgOps.cxx:467
void SetArgArray(long *argArr, int narg)
cling::MetaProcessor * fMetaProcessor
Definition: TCling.h:121
virtual void SetOwner(Bool_t enable=kTRUE)
Set whether this collection is the owner (enable==true) of its content.
const char * Name() const
Get the name of the current typedef.
Persistent version of a TClass.
Definition: TProtoClass.h:37
Emulation of the CINT DataMemberInfo class.
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:7387
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
void CreateListOfBaseClasses(TClass *cl) const
Create list of pointers to base class(es) for TClass cl.
Definition: TCling.cxx:3357
TClass * GenerateTClass(const char *classname, Bool_t emulation, Bool_t silent=kFALSE)
Generate a TClass for the given class.
Definition: TCling.cxx:3519
void UpdateListOfGlobals()
No op: see TClingCallbacks (used to update the list of globals)
Definition: TCling.cxx:3098
virtual MethodInfo_t * MethodInfo_FactoryCopy(MethodInfo_t *minfo) const
Definition: TCling.cxx:7542
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format...
Definition: TFile.h:45
virtual Int_t GetEntries() const
Definition: TCollection.h:92
void UpdateListOfGlobalFunctions()
No op: see TClingCallbacks (used to update the list of global functions)
Definition: TCling.cxx:3105
virtual int SetClassAutoloading(int) const
Enable/Disable the Autoloading of libraries.
Definition: TCling.cxx:6180
Emulation of the CINT MethodInfo class.
ptrdiff_t GetBaseOffset(TClingClassInfo *toBase, void *address, bool isDerivedObject)
void SaveContext()
Save the current Cling state.
Definition: TCling.cxx:3072
virtual const char * MethodInfo_Name(MethodInfo_t *minfo) const
Definition: TCling.cxx:7631
cling::Interpreter * fInterpreter
Definition: TCling.h:120
virtual bool ClassInfo_IsValid(ClassInfo_t *info) const
Definition: TCling.cxx:6870
virtual const char * HomeDirectory(const char *userName=0)
Return the user&#39;s home directory.
Definition: TSystem.cxx:881
void SetArg(long arg)
static void RemoveClassDeclId(TDictionary::DeclId_t id)
Definition: TClass.cxx:492
const char * GetClassSharedLibs(const char *cls)
Get the list of shared libraries containing the code for class cls.
Definition: TCling.cxx:5880
virtual FuncTempInfo_t * FuncTempInfo_Factory(DeclId_t declid) const
Construct a FuncTempInfo_t.
Definition: TCling.cxx:7342
void TCling__DEBUG__dump(clang::DeclContext *DC)
Definition: TCling.cxx:207
const char * DefaultValue() const
long ClassProperty() const
static const char * filename()
#define R__ASSERT(e)
Definition: TError.h:98
void TCling__UpdateListsOnUnloaded(const cling::Transaction &T)
Definition: TCling.cxx:545
#define gROOT
Definition: TROOT.h:352
virtual TObject * Remove(TObject *obj)
Remove object from array.
Definition: TObjArray.cxx:652
TList * GetListOfDataMembers(Bool_t load=kTRUE)
Return list containing the TDataMembers of a class.
Definition: TClass.cxx:3529
Bool_t IsErrorMessagesEnabled() const
If error messages are disabled, the interpreter should suppress its failures and warning messages fro...
Definition: TCling.cxx:5949
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
Definition: TString.h:582
bool HasDefaultConstructor() const
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...
TFunction * Find(DeclId_t id) const
Return the TMethod or TFunction describing the function corresponding to the Decl &#39;id&#39;...
virtual Bool_t IsTreatingNonAccessibleTypes()
virtual int TypedefInfo_Next(TypedefInfo_t *tinfo) const
Definition: TCling.cxx:7963
virtual const char * MapCppName(const char *) const
Interface to cling function.
Definition: TCling.cxx:6148
Int_t Load(const char *filenam, Bool_t system=kFALSE)
Load a library file in cling&#39;s memory.
Definition: TCling.cxx:2743
virtual int Load(const char *module, const char *entry="", Bool_t system=kFALSE)
Load a shared library.
Definition: TSystem.cxx:1817
virtual Long_t ClassInfo_Property(ClassInfo_t *info) const
Definition: TCling.cxx:6934
void * InterfaceMethod(const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt) const
The TEnv class reads config files, by default named .rootrc.
Definition: TEnv.h:128
std::string InsertStd(const char *tname)
Basic string class.
Definition: TString.h:137
clang::DeclContext * TCling__DEBUG__getDeclContext(clang::Decl *D)
Definition: TCling.cxx:198
virtual int MethodInfo_NDefaultArg(MethodInfo_t *minfo) const
Definition: TCling.cxx:7573
TVirtualCollectionProxy * GetCollectionProxy() const
Return the proxy describing the collection (if any).
Definition: TClass.cxx:2800
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:3893
static Bool_t HasNoInfoOrEmuOrFwdDeclaredDecl(const char *)
Definition: TClass.cxx:3170
const char * GetValue() const
Definition: TEnv.h:114
virtual const char * MethodArgInfo_TypeName(MethodArgInfo_t *marginfo) const
Definition: TCling.cxx:7801
virtual TApplicationImp * GetApplicationImp()
Definition: TApplication.h:137
int Int_t
Definition: RtypesCore.h:41
virtual const char * DirName(const char *pathname)
Return the directory name in pathname.
Definition: TSystem.cxx:996
bool Bool_t
Definition: RtypesCore.h:59
virtual void CallFunc_SetArgArray(CallFunc_t *func, Long_t *paramArr, Int_t nparam) const
Definition: TCling.cxx:6622
TArc * a
Definition: textangle.C:12
std::vector< std::pair< std::string, int > > FwdDeclArgsToKeepCollection_t
Definition: TInterpreter.h:108
const Bool_t kFALSE
Definition: Rtypes.h:92
virtual Long_t TypeInfo_Property(TypeInfo_t *tinfo) const
Definition: TCling.cxx:7877
void * fPrevLoadedDynLibInfo
Definition: TCling.h:127
#define gInterpreter
Definition: TInterpreter.h:502
const char * fantomline
Definition: TCling.cxx:839
virtual void GenericError(const char *error) const
Let the interpreter issue a generic error, and set its error state.
Definition: TCling.cxx:6063
virtual char * Which(const char *search, const char *file, EAccessMode mode=kFileExists)
Find location of file in a search path.
Definition: TSystem.cxx:1510
virtual const char * ClassInfo_Title(ClassInfo_t *info) const
Definition: TCling.cxx:6984
virtual void TypeInfo_Delete(TypeInfo_t *tinfo) const
Definition: TCling.cxx:7822
Each ROOT method (see TMethod) has a linked list of its arguments.
Definition: TMethodArg.h:33
virtual void SetTempLevel(int val) const
Create / close a scope for temporaries.
Definition: TCling.cxx:6254
long Property() const
const char * TrueName(const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt) const
Get the name of the underlying type of the current typedef.
virtual bool ClassInfo_HasMethod(ClassInfo_t *info, const char *name) const
Definition: TCling.cxx:6821
Int_t DeleteVariable(const char *name)
Undeclare obj called name.
Definition: TCling.cxx:3013
virtual int SetClassAutoparsing(int)
Enable/Disable the Autoparsing of headers.
Definition: TCling.cxx:6195
virtual ClassInfo_t * ClassInfo_Factory(Bool_t all=kTRUE) const
Definition: TCling.cxx:6782
virtual bool DataMemberInfo_IsValid(DataMemberInfo_t *dminfo) const
Definition: TCling.cxx:7168
STL namespace.
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()
TObject * At(Int_t idx) const
Definition: TObjArray.h:167
Bool_t IsLoaded(const char *filename) const
Return true if the file has already been loaded by cint.
Definition: TCling.cxx:2492
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:3920
std::vector< cling::Value > * fTemporaries
Definition: TCling.h:123
virtual void MethodInfo_CreateSignature(MethodInfo_t *minfo, TString &signature) const
Definition: TCling.cxx:7508
virtual ~TCling()
Destroy the interpreter interface.
Definition: TCling.cxx:1185
virtual void FuncTempInfo_Delete(FuncTempInfo_t *) const
Delete the FuncTempInfo_t.
Definition: TCling.cxx:7333
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...
TObject * FindObject(const char *name) const
Find object using its name.
Definition: THashList.cxx:212
std::string GetMangledName() const
const char * Title()
const char * GetFullTypeName() const
Get full type description of method argument, e.g.: "class TDirectory*".
Definition: TMethodArg.cxx:75
virtual const char * TypeInfo_TrueName(TypeInfo_t *tinfo) const
Definition: TCling.cxx:7901
virtual bool Update(FuncTempInfo_t *info)
Update the TFunctionTemplate to reflect the new info.
void Delete(void *arena, const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt) const
const TSeqCollection * GetConstants() const
Definition: TEnum.h:66
static double A[]
Emulation of the CINT CallFunc class.
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 BaseClassInfo_t * BaseClassInfo_Factory(ClassInfo_t *info) const
Definition: TCling.cxx:7014
static const TString & GetIncludeDir()
Get the include directory in the installation. Static utility function.
Definition: TROOT.cxx:2580
const char * TypeTrueName(const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt) const
MethodInfo_t * fInfo
Definition: TFunction.h:36
Bool_t R_ISREG(Int_t mode)
Definition: TSystem.h:129
DeclId_t GetDeclId() const
Definition: TEnum.h:72
virtual const char * TypedefInfo_TrueName(TypedefInfo_t *tinfo) const
Definition: TCling.cxx:7987
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition: TObject.cxx:732
virtual void SetDeclAttr(DeclId_t, const char *)
Definition: TCling.cxx:7267
virtual const char * TypedefInfo_Title(TypedefInfo_t *tinfo) const
Definition: TCling.cxx:8003
virtual void BaseClassInfo_Delete(BaseClassInfo_t *bcinfo) const
Definition: TCling.cxx:7007
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:4138
virtual const char * FindFile(const char *search, TString &file, EAccessMode mode=kFileExists)
Find location of file in a search path.
Definition: TSystem.cxx:1500
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...
const char * GetSharedLibDeps(const char *lib)
Get the list a libraries on which the specified lib depends.
Definition: TCling.cxx:5922
const char * Name
Definition: TXMLSetup.cxx:67
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:6722
static const char * GetMacroPath()
Get macro search path. Static utility function.
Definition: TROOT.cxx:2395
bool ExtractAttrPropertyFromName(const clang::Decl &decl, const std::string &propName, std::string &propValue)
This routine counts on the "propName<separator>propValue" format.
virtual bool ClassInfo_IsLoaded(ClassInfo_t *info) const
Definition: TCling.cxx:6862
virtual TypeInfo_t * MethodInfo_Type(MethodInfo_t *minfo) const
Definition: TCling.cxx:7605
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:725
virtual Long_t BaseClassInfo_Property(BaseClassInfo_t *bcinfo) const
Definition: TCling.cxx:7071
std::set< size_t > fPayloads
Definition: TCling.h:112
Int_t fMode
Definition: TSystem.h:138
virtual const char * DataMemberInfo_Title(DataMemberInfo_t *dminfo) const
Definition: TCling.cxx:7248
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 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:6171
virtual int TypeInfo_Size(TypeInfo_t *tinfo) const
Definition: TCling.cxx:7893
virtual int DataMemberInfo_TypeSize(DataMemberInfo_t *dminfo) const
Definition: TCling.cxx:7216
virtual TypedefInfo_t * TypedefInfo_FactoryCopy(TypedefInfo_t *tinfo) const
Definition: TCling.cxx:7938
virtual Long64_t CallFunc_ExecInt64(CallFunc_t *func, void *address) const
Definition: TCling.cxx:6493
void TCling__DEBUG__decl_dump(void *D)
Definition: TCling.cxx:216
Int_t UnloadLibraryMap(const char *library)
Unload library map entries coming from the specified library.
Definition: TCling.cxx:4879
void ExecuteWithArgsAndReturn(TMethod *method, void *address, const void *args[]=0, int nargs=0, void *ret=0) const
Definition: TCling.cxx:4290
virtual void SetErrmsgcallback(void *p) const
Set a callback to receive error messages.
Definition: TCling.cxx:6216
void ClearStack()
Delete existing temporary values.
Definition: TCling.cxx:2428
virtual Long_t DataMemberInfo_Property(DataMemberInfo_t *dminfo) const
Definition: TCling.cxx:7200
long Property() const
Return a bit mask of metadata about the current typedef.
virtual const char * GetDirEntry(void *dirp)
Get a directory entry. Returns 0 if no more entries.
Definition: TSystem.cxx:847
void ResetAll()
Reset the Cling state to its initial state.
Definition: TCling.cxx:2939
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:4430
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.
virtual bool MethodArgInfo_IsValid(MethodArgInfo_t *marginfo) const
Definition: TCling.cxx:7761
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:3691
virtual MethodArgInfo_t * MethodArgInfo_FactoryCopy(MethodArgInfo_t *marginfo) const
Definition: TCling.cxx:7753
THashTable implements a hash table to store TObject&#39;s.
Definition: THashTable.h:39
const char * TCling__GetClassSharedLibs(const char *className)
Definition: TCling.cxx:598
clang::NamespaceDecl * TCling__DEBUG__DCtoNamespace(clang::DeclContext *DC)
Definition: TCling.cxx:201
virtual TEnum * CreateEnum(void *VD, TClass *cl) const
Definition: TCling.cxx:421
virtual bool TypeInfo_IsValid(TypeInfo_t *tinfo) const
Definition: TCling.cxx:7861
virtual const char * DataMemberInfo_TypeName(DataMemberInfo_t *dminfo) const
Definition: TCling.cxx:7224
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString...
Definition: TString.cxx:2334
bool IsBase(const char *name) const
Vc_ALWAYS_INLINE void free(T *p)
Frees memory that was allocated with Vc::malloc.
Definition: memory.h:94
void Class()
Definition: Class.C:29
virtual void Sleep(UInt_t milliSec)
Sleep milliSec milli seconds.
Definition: TSystem.cxx:441
THashList implements a hybrid collection class consisting of a hash table and a list to store TObject...
Definition: THashList.h:36
Bool_t CheckClassInfo(const char *name, Bool_t autoload, Bool_t isClassOrNamespaceOnly=kFALSE)
Checks if an entity with the specified name is defined in Cling.
Definition: TCling.cxx:3214
std::atomic< TList * > fBase
Definition: TClass.h:182
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:2441
std::map< const cling::Transaction *, size_t > fTransactionHeadersMap
Definition: TCling.h:110
virtual void MethodArgInfo_Delete(MethodArgInfo_t *marginfo) const
Definition: TCling.cxx:7730
virtual Long_t MethodArgInfo_Property(MethodArgInfo_t *marginfo) const
Definition: TCling.cxx:7777
void ShortType(std::string &answer, int mode)
Return the absolute type of typeDesc into the string answ.
Definition: TClassEdit.cxx:197
void GetInterpreterTypeName(const char *name, std::string &output, Bool_t full=kFALSE)
The &#39;name&#39; is known to the interpreter, this function returns the internal version of this name (usua...
Definition: TCling.cxx:4105
The TNamed class is the base class for all named ROOT classes.
Definition: TNamed.h:33
virtual TObject * FindObject(const char *name) const
Find an object in this collection using its name.
Definition: TObjArray.cxx:395
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:6665
void SetObjectValidity(EObjectPointerState val)
virtual void TypedefInfo_Init(TypedefInfo_t *tinfo, const char *name) const
Definition: TCling.cxx:7945
virtual DataMemberInfo_t * DataMemberInfo_FactoryCopy(DataMemberInfo_t *dminfo) const
Definition: TCling.cxx:7160
const char * Title()
void SetArgs(const char *args)
virtual Long_t MethodInfo_Property(MethodInfo_t *minfo) const
Definition: TCling.cxx:7589
char * DemangleName(const char *mangled_name, int &errorCode)
Definition: TClassEdit.h:178
void * GetInterfaceMethodWithPrototype(TClass *cl, const char *method, const char *proto, Bool_t objectIsConst=kFALSE, ROOT::EFunctionMatchMode mode=ROOT::kConversionMatch)
Return pointer to cling interface function for a method of a class with a certain prototype...
Definition: TCling.cxx:4015
int MaxIndex(int dim) const
virtual ClassInfo_t * BaseClassInfo_ClassInfo(BaseClassInfo_t *) const
Definition: TCling.cxx:7079
bool IsValid() const
void CreateSignature(TString &signature) 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:4060
TClass * GetClass() const
Definition: TListOfEnums.h:66
void Init(TClassEdit::TInterpreterLookupHelper *helper)
Definition: TClassEdit.cxx:118
void ClearFileBusy()
Reset the interpreter internal state in case a previous action was not correctly terminated.
Definition: TCling.cxx:2420
virtual Int_t Lock()=0
static void UpdateClassInfo(char *name, Long_t tagnum)
No op: see TClingCallbacks.
Definition: TCling.cxx:5541
virtual const char * GetDynamicPath()
Return the dynamic path (used to find shared libraries).
Definition: TSystem.cxx:1756
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:5515
const char * TypeName() const
TString fSharedLibs
Definition: TCling.h:104
void Clear()
Clear string without changing its capacity.
Definition: TString.cxx:1139
bool Append(const std::string &str)
Append string to the storage if not added already.
Definition: TCling.cxx:1020
virtual int CompileMacro(const char *filename, Option_t *opt="", const char *library_name="", const char *build_dir="", UInt_t dirmode=0)
This method compiles and loads a shared library containing the code from the file "filename"...
Definition: TSystem.cxx:2767
virtual const char * Getenv(const char *env)
Get environment variable.
Definition: TSystem.cxx:1626
virtual Long_t BaseClassInfo_Tagnum(BaseClassInfo_t *bcinfo) const
Definition: TCling.cxx:7087
TEnv * fMapfile
Definition: TCling.h:108
EFunctionMatchMode
Definition: TDictionary.h:155
EState GetState() const
Definition: TClass.h:443
virtual Long_t TypedefInfo_Property(TypedefInfo_t *tinfo) const
Definition: TCling.cxx:7971
TString & Append(const char *cs)
Definition: TString.h:492
static bool IsEnum(cling::Interpreter *interp, const char *name)
virtual const char * PrependPathName(const char *dir, TString &name)
Concatenate a directory and a file name.
Definition: TSystem.cxx:1054
Bool_t EndsWith(const char *pat, ECaseCompare cmp=kExact) const
Return true if string ends with the specified string.
Definition: TString.cxx:2220
ULong64_t fTransactionCount
Definition: TCling.h:138
ClassInfo_t * GetClassInfo() const
Definition: TClass.h:391
TClass * GetClass() const
char * DemangleTypeIdName(const std::type_info &ti, int &errorCode)
Demangle in a portable way the type id name.
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:3960
virtual int DisplayClass(FILE *fout, const char *name, int base, int start) const
Definition: TCling.cxx:6017
void UpdateListOfMethods(TClass *cl) const
Update the list of pointers to method for TClass cl This is now a nop.
Definition: TCling.cxx:3481
Long_t ProcessLine(const char *line, EErrorCode *error=0)
Let cling process a command line.
Definition: TCling.cxx:1853
virtual bool Update(DataMemberInfo_t *info)
Update the TFunction to reflect the new info.
virtual int DataMemberInfo_MaxIndex(DataMemberInfo_t *dminfo, Int_t dim) const
Definition: TCling.cxx:7176
R__EXTERN int optind
Definition: TCling.cxx:301
static void Add(const char *cname, Version_t id, const type_info &info, DictFuncPtr_t dict, Int_t pragmabits)
Add a class to the class table (this is a static function).
Emulation of the CINT TypeInfo class.
clang::RecordDecl * TCling__DEBUG__DCtoRecordDecl(clang::DeclContext *DC)
Definition: TCling.cxx:204
This class defines an interface to the cling C++ interpreter.
Definition: TCling.h:92
Bool_t IgnoreDuplicates(Bool_t ignore)
If set to true, no warnings in case of duplicates are issued.
Definition: TEnv.cxx:782
TClass *(* DictFuncPtr_t)()
Definition: Rtypes.h:75
bool HasMethod(const char *name) const
virtual const char * DataMemberInfo_Name(DataMemberInfo_t *dminfo) const
Definition: TCling.cxx:7240
virtual int GetSecurityError() const
Interface to cling function.
Definition: TCling.cxx:6113
TVirtualPad is an abstract base class for the Pad and Canvas classes.
Definition: TVirtualPad.h:59
def Namespace(name)
Definition: cppyy.py:193
Int_t UnloadAllSharedLibraryMaps()
Unload the library map entries coming from all the loaded shared libraries.
Definition: TCling.cxx:4861
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:4533
virtual Long_t CallFunc_ExecInt(CallFunc_t *func, void *address) const
Definition: TCling.cxx:6485
std::string GetModuleFileName(const char *moduleName)
Return the dictionary file name for a module.
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:816
void InspectMembers(TMemberInspector &, const void *obj, const TClass *cl, Bool_t isTransient)
Visit all members over members, recursing over base classes.
Definition: TCling.cxx:2049
long ExtraProperty() const
const clang::FunctionDecl * GetMethodDecl() const
static void TCling__UpdateClassInfo(const NamedDecl *TD)
Update TClingClassInfo for a class (e.g. upon seeing a definition).
Definition: TCling.cxx:343
const char * GetPrototype(const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt) const
void * InterfaceMethod()
void TCling__DEBUG__printName(clang::Decl *D)
Definition: TCling.cxx:219
EComplexType GetComplexType(const char *)
Definition: TClassEdit.cxx:96
void GetObject(const char *namecycle, T *&ptr)
virtual const char * TypedefInfo_Name(TypedefInfo_t *tinfo) const
Definition: TCling.cxx:7995
virtual void CallFunc_SetArg(CallFunc_t *func, Long_t param) const
Definition: TCling.cxx:6574
TCppMethod_t GetMethod(TCppScope_t scope, TCppIndex_t imeth)
Definition: Cppyy.cxx:701
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 DeclId_t GetDataMemberWithValue(const void *ptrvalue) const
NOT IMPLEMENTED.
Definition: TCling.cxx:3872
A doubly linked list.
Definition: TList.h:47
static const char * what
Definition: stlLoader.cc:6
virtual Bool_t IsCmdThread()
Definition: TApplication.h:136
#define R__DLLEXPORT
Definition: TCling.cxx:127
const char * Name() const
void PrintIntro()
No-op; see TRint instead.
Definition: TCling.cxx:2031
const clang::ValueDecl * GetDataMember(const char *name) const
TString fRootmapLoadPath
Definition: TCling.h:107
virtual const char * DataMemberInfo_TypeTrueName(DataMemberInfo_t *dminfo) const
Definition: TCling.cxx:7232
R__EXTERN TVirtualMutex * gGlobalMutex
Definition: TVirtualMutex.h:29
Int_t GetType() const
Definition: TDataType.h:70
virtual bool ClassInfo_IsBase(ClassInfo_t *info, const char *name) const
Definition: TCling.cxx:6847
virtual TypedefInfo_t * TypedefInfo_Factory() const
Definition: TCling.cxx:7922
virtual Int_t ReadFile(const char *fname, EEnvLevel level)
Read and parse the resource file for a certain level.
Definition: TEnv.cxx:581
const Decl * TCling__GetObjectDecl(TObject *obj)
Definition: TCling.cxx:571
R__EXTERN TROOT * gROOTLocal
Definition: TROOT.h:349
void UpdateListOfTypes()
No op: see TClingCallbacks (used to update the list of types)
Definition: TCling.cxx:3112
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 TObject * FindObject(const TObject *obj) const
Find object using its hash value (returned by its Hash() member).
const char * TmpltName() const
Definition: TEnv.h:91
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:5174
virtual TList * GetListOfMethodArgs()
Returns methodarg list and additionally updates fDataMember in TMethod by calling FindDataMember();...
Definition: TMethod.cxx:305
virtual Bool_t LoadText(const char *text) const
Load the declarations from text into the interpreter.
Definition: TCling.cxx:6140
void Init(const char *name)
virtual int BaseClassInfo_Next(BaseClassInfo_t *bcinfo) const
Definition: TCling.cxx:7034
void function(const char *name_, T fun, const char *docstring=0)
Definition: RExports.h:159
bool TCling__TEST_isInvalidDecl(clang::Decl *D)
Definition: TCling.cxx:234
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:5302
void TCling__SplitAclicMode(const char *fileName, string &mode, string &args, string &io, string &fname)
Definition: TCling.cxx:622
static double C[]
void DeleteArray(void *arena, bool dtorOnly, const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt) const
Emulation of the CINT BaseClassInfo class.
void FullName(std::string &output, const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt) const
virtual bool MethodInfo_IsValid(MethodInfo_t *minfo) const
Definition: TCling.cxx:7557
Double_t length(const TVector2 &v)
Definition: CsgOps.cxx:347
virtual TypeInfo_t * TypeInfo_FactoryCopy(TypeInfo_t *) const
Definition: TCling.cxx:7845
TClingMethodInfo * FactoryMethod() const
R__EXTERN TSystem * gSystem
Definition: TSystem.h:549
virtual const char * MethodInfo_GetPrototype(MethodInfo_t *minfo) const
Definition: TCling.cxx:7623
virtual const char * GetTopLevelMacroName() const
Return the file name of the current un-included interpreted file.
Definition: TCling.cxx:4321
int GetMethodNArg(const char *method, const char *proto, Bool_t objectIsConst, ROOT::EFunctionMatchMode mode=ROOT::kConversionMatch) const
virtual MethodArgInfo_t * MethodArgInfo_Factory() const
Definition: TCling.cxx:7737
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)
std::set< TClass * > & GetModTClasses()
Definition: TCling.h:505
THashList * GetTable() const
Definition: TEnv.h:144
virtual void CallFunc_SetFunc(CallFunc_t *func, ClassInfo_t *info, const char *method, const char *params, Long_t *Offset) const
Definition: TCling.cxx:6638
virtual CallFunc_t * CallFunc_FactoryCopy(CallFunc_t *func) const
Definition: TCling.cxx:6517
virtual const char * BaseClassInfo_TmpltName(BaseClassInfo_t *bcinfo) const
Definition: TCling.cxx:7113
const char * TypeName() const
virtual Long_t ClassInfo_ClassProperty(ClassInfo_t *info) const
Definition: TCling.cxx:6743
static void UpdateAllCanvases()
Update all canvases at end the terminal input command.
Definition: TCling.cxx:5556
virtual const char * MethodInfo_GetMangledName(MethodInfo_t *minfo) const
Definition: TCling.cxx:7613
virtual void * FindSym(const char *entry) const
Interface to cling function.
Definition: TCling.cxx:6055
const char * GetName() const
Returns name of object.
Definition: TEnv.h:113
virtual int MethodInfo_NArg(MethodInfo_t *minfo) const
Definition: TCling.cxx:7565
Long_t fMemVirtual
Definition: TSystem.h:207
Bool_t BeginsWith(const char *s, ECaseCompare cmp=kExact) const
Definition: TString.h:558
const T * GetAnnotatedRedeclarable(const T *Redecl)
Definition: TMetaUtils.h:601
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:536
virtual const char * GetSTLIncludePath() const
Return the directory containing CINT&#39;s stl cintdlls.
Definition: TCling.cxx:6008
TObject * Remove(TObject *obj)
Remove object from the list.
Definition: THashList.cxx:284
virtual Int_t AutoParse(const char *cls)=0
Collection abstract base class.
Definition: TCollection.h:48
Bool_t SetErrorMessages(Bool_t enable=kTRUE)
If error messages are disabled, the interpreter should suppress its failures and warning messages fro...
Definition: TCling.cxx:5963
int TCling__AutoParseCallback(const char *className)
Definition: TCling.cxx:593
void SaveGlobalsContext()
Save the current Cling state of global objects.
Definition: TCling.cxx:3085
void UpdateClassInfoWithDecl(const void *vTD)
Internal function. Inform a TClass about its new TagDecl or NamespaceDecl.
Definition: TCling.cxx:5468
TDictionary::DeclId_t GetDeclId() const
unsigned int UInt_t
Definition: RtypesCore.h:42
TDictionary::DeclId_t GetDeclId() const
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 Long_t BaseClassInfo_Offset(BaseClassInfo_t *toBaseClassInfo, void *address, bool isDerivedObject) const
Definition: TCling.cxx:7050
Int_t GetEntriesFast() const
Definition: TObjArray.h:66
std::string NormalizedName(const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt) const
Return the normalized name of the type (i.e.
void UpdateListOfLoadedSharedLibraries()
Definition: TCling.cxx:2596
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:918
char * Form(const char *fmt,...)
Ssiz_t Length() const
Definition: TString.h:390
Int_t Size() const
Return size of object of this class.
Definition: TClass.cxx:5314
virtual Long_t ClassInfo_GetBaseOffset(ClassInfo_t *fromDerived, ClassInfo_t *toBase, void *address, bool isDerivedObject) const
Definition: TCling.cxx:7058
Long_t Calc(const char *line, EErrorCode *error=0)
Directly execute an executable statement (e.g.
Definition: TCling.cxx:2817
Double_t E()
Definition: TMath.h:54
Int_t RescanLibraryMap()
Scan again along the dynamic path for library maps.
Definition: TCling.cxx:4788
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
The TEnumConstant class implements the constants of the enum type.
Definition: TEnumConstant.h:33
virtual MethodInfo_t * MethodInfo_Factory() const
Definition: TCling.cxx:7516
The ROOT global object gROOT contains a list of all defined classes.
Definition: TClass.h:81
const std::string sname
Definition: testIO.cxx:45
virtual Long_t FuncTempInfo_Property(FuncTempInfo_t *) const
Return the property of the function template.
Definition: TCling.cxx:7397
const Int_t kWarning
Definition: TError.h:40
ROOT::ESTLType GetCollectionType() const
Return the &#39;type&#39; of the STL the TClass is representing.
Definition: TClass.cxx:2789
virtual TObject * At(Int_t idx) const
Returns the object at position idx. Returns 0 if idx is out of range.
Definition: TList.cxx:310
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:5358
Long_t ExecuteMacro(const char *filename, EErrorCode *error=0)
Execute a cling macro.
Definition: TCling.cxx:4308
virtual void Initialize()
Initialize the interpreter, once TROOT::fInterpreter is set.
Definition: TCling.cxx:1210
Bool_t CheckClassTemplate(const char *name)
Return true if there is a class template by the given name ...
Definition: TCling.cxx:3337
static void indent(ostringstream &buf, int indent_level)
virtual const char * ClassInfo_TmpltName(ClassInfo_t *info) const
Definition: TCling.cxx:6992
virtual const char * Getp2f2funcname(void *receiver) const
Definition: TCling.cxx:6103
Long_t Property() const
Set TObject::fBits and fStreamerType to cache information about the class.
Definition: TClass.cxx:5641
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
virtual void FreeDirectory(void *dirp)
Free a directory.
Definition: TSystem.cxx:839
TObject * TCling__GetObjectAddress(const char *Name, void *&LookupCtx)
Definition: TCling.cxx:567
virtual int ClassInfo_Size(ClassInfo_t *info) const
Definition: TCling.cxx:6942
virtual bool TypedefInfo_IsValid(TypedefInfo_t *tinfo) const
Definition: TCling.cxx:7955
Int_t LastIndex() const
Each class (see TClass) has a linked list of its base class(es).
Definition: TBaseClass.h:35
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:2467
Type
enumeration specifying the integration types.
Bool_t fLockProcessLine
Definition: TCling.h:117
R__DLLEXPORT void DestroyInterpreter(TInterpreter *interp)
Definition: TCling.cxx:581
virtual void UpdateEnumConstants(TEnum *enumObj, TClass *cl) const
Definition: TCling.cxx:375
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:3736
bool IsAutoloadingEnabled()
TDictionary::DeclId_t DeclId_t
Definition: TListOfEnums.h:63
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:6085
#define R__LOCKGUARD2(mutex)
virtual int LoadFile(const char *path) const
Load a source file or library called path into the interpreter.
Definition: TCling.cxx:6126
std::unordered_set< const clang::NamespaceDecl * > fNSFromRootmaps
Definition: TCling.h:115
void TCling__GetNormalizedContext(const ROOT::TMetaUtils::TNormalizedCtxt *&normCtxt)
Definition: TCling.cxx:532
void UpdateListOfDataMembers(TClass *cl) const
Update the list of pointers to data members for TClass cl This is now a nop.
Definition: TCling.cxx:3490
virtual const char * FindDynamicLibrary(TString &lib, Bool_t quiet=kFALSE)
Find a dynamic library using the system search paths.
Definition: TSystem.cxx:1959
void EndOfLineAction()
It calls a "fantom" method to synchronize user keyboard input and ROOT prompt line.
Definition: TCling.cxx:2479
virtual int MethodArgInfo_Next(MethodArgInfo_t *marginfo) const
Definition: TCling.cxx:7769
TString & Remove(Ssiz_t pos)
Definition: TString.h:616
long Long_t
Definition: RtypesCore.h:50
void SetClassInfo(TClass *cl, Bool_t reload=kFALSE)
Set pointer to the TClingClassInfo in TClass.
Definition: TCling.cxx:3121
int Ssiz_t
Definition: RtypesCore.h:63
virtual void FuncTempInfo_Title(FuncTempInfo_t *, TString &name) const
Return the comments associates with this function template.
Definition: TCling.cxx:7469
Emulation of the CINT TypedefInfo class.
void * New(const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt) const
virtual void LoadFunctionTemplates(TClass *cl) const
Create list of pointers to function templates for TClass cl.
Definition: TCling.cxx:3426
A collection of TEnum objects designed for fast access given a DeclId_t and for keep track of TEnum t...
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:2101
Version_t GetClassVersion() const
Definition: TClass.h:382
int(* AutoLoadCallBack_t)(const char *)
Definition: TInterpreter.h:107
TObjArray * Tokenize(const TString &delim) const
This function is used to isolate sequential tokens in a TString.
Definition: TString.cxx:2240
virtual const char * GetIncludePath()
Get the list of include path.
Definition: TSystem.cxx:3760
int TCling_GenerateDictionary(const std::vector< std::string > &classes, const std::vector< std::string > &headers, const std::vector< std::string > &fwdDecls, const std::vector< std::string > &unknown)
Definition: TCling.cxx:678
TInterpreterValue * CreateTemporary()
The created temporary must be deleted by the caller.
Definition: TCling.cxx:6277
void CreateListOfDataMembers(TClass *cl) const
Create list of pointers to data members for TClass cl.
Definition: TCling.cxx:3463
void UpdateListsOnUnloaded(const cling::Transaction &T)
Definition: TCling.cxx:5717
virtual const char * DataMemberInfo_ValidArrayIndex(DataMemberInfo_t *dminfo) const
Definition: TCling.cxx:7256
TObjArray * fStreamerInfo
Definition: TClass.h:179
Bool_t IsOnHeap() const
Definition: TObject.h:140
void CreateListOfMethods(TClass *cl) const
Create list of pointers to methods for TClass cl.
Definition: TCling.cxx:3472
virtual const char * BaseClassInfo_Name(BaseClassInfo_t *bcinfo) const
Definition: TCling.cxx:7105
double f(double x)
std::set< size_t > fLookedUpClasses
Definition: TCling.h:111
virtual void TypedefInfo_Delete(TypedefInfo_t *tinfo) const
Definition: TCling.cxx:7915
const Config_t & GetConfig() const
Definition: TMetaUtils.cxx:335
MyComplex< T > P(MyComplex< T > z, T c_real, T c_imag)
[MyComplex]
Definition: mandel.cpp:155
bool IsValidMethod(const char *method, const char *proto, Bool_t objectIsConst, long *offset, ROOT::EFunctionMatchMode mode=ROOT::kConversionMatch) const
TClingClassInfo * GetBase() 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:5664
virtual const void * GetValAddr() const =0
EState fState
cached of the streaming method to use
Definition: TClass.h:237
void TCling__LibraryLoadedRTTI(const void *dyLibHandle, const char *canonicalName)
Definition: TCling.cxx:553
double Double_t
Definition: RtypesCore.h:55
Emulation of the CINT MethodInfo class.
virtual void SetRTLD_NOW() const
Definition: TCling.cxx:6238
long Property() const
Ssiz_t Last(char c) const
Find last occurrence of a character c.
Definition: TString.cxx:864
bool IsValid() const
Return true if the current iterator position is valid.
char * DynamicPathName(const char *lib, Bool_t quiet=kFALSE)
Find a dynamic library called lib using the system search paths.
Definition: TSystem.cxx:1945
virtual int MethodInfo_Next(MethodInfo_t *minfo) const
Definition: TCling.cxx:7581
TText * text
static DictFuncPtr_t GetDict(const char *cname)
Given the class name returns the Dictionary() function of a class (uses hash of name).
Definition: TCling.h:48
void Unload()
Mark &#39;all func&#39; as being unloaded.
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:6805
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:1821
Bool_t IsAutoLoadNamespaceCandidate(const char *name)
Definition: TCling.cxx:5450
TDictionary::DeclId_t DeclId_t
int type
Definition: TGX11.cxx:120
static const float S
Definition: mandel.cpp:113
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:2969
unsigned long long ULong64_t
Definition: RtypesCore.h:70
Definition: TDatime.h:114
virtual CallFuncIFacePtr_t CallFunc_IFacePtr(CallFunc_t *func) const
Definition: TCling.cxx:6558
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:4082
TNamed()
Definition: TNamed.h:40
const char * GetParent() const
unsigned long ULong_t
Definition: RtypesCore.h:51
static const TString & GetEtcDir()
Get the sysconfig directory in the installation. Static utility function.
Definition: TROOT.cxx:2601
void Reset()
Pressing Ctrl+C should forward here.
Definition: TCling.cxx:2923
Int_t LoadLibraryMap(const char *rootmapfile=0)
Load map between class and library.
Definition: TCling.cxx:4598
Bool_t fAllowLibLoad
Definition: TCling.h:118
TObjArray * fRootmapFiles
Definition: TCling.h:116
double func(double *x, double *p)
Definition: stressTF1.cxx:213
void * fAutoLoadCallBack
Definition: TCling.h:137
virtual void Expand(Int_t newSize)
Expand or shrink the array to newSize elements.
Definition: TObjArray.cxx:369
std::set< const char * > fParsedPayloadsAddresses
Definition: TCling.h:113
ROOT::TMetaUtils::TClingLookupHelper * fLookupHelper
Definition: TCling.h:125
virtual void CallFunc_SetArgs(CallFunc_t *func, const char *param) const
Definition: TCling.cxx:6630
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:5021
EObjectPointerState GetObjectValidity() const
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition: TString.h:567
Emulation of the CINT ClassInfo class.
virtual ~TROOT()
Clean up and free resources used by ROOT (files, network sockets, shared memory segments, etc.).
Definition: TROOT.cxx:677
#define R__LOCKGUARD(mutex)
void InspectMember(const T &obj, const char *name, Bool_t isTransient)
virtual void Add(TObject *obj)=0
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:2870
virtual void CallFunc_IgnoreExtraArgs(CallFunc_t *func, bool ignore) const
Definition: TCling.cxx:6532
virtual EReturnType MethodCallReturnType(TFunction *func) const
Definition: TCling.cxx:7666
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:2871
char fPrompt[64]
Definition: TCling.h:101
int Size() const
ptrdiff_t Offset(void *address=0, bool isDerivedObject=true) 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:1484
virtual bool ClassInfo_IsEnum(const char *name) const
Definition: TCling.cxx:6855
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:4800
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:3979
static TClass * LoadClass(const char *requestedname, Bool_t silent)
Helper function used by TClass::GetClass().
Definition: TClass.cxx:5359
Bool_t IsPersistent() const
Definition: TDataMember.h:89
Bool_t IsNull() const
Definition: TString.h:387
void HandleNewDecl(const void *DV, bool isDeserialized, std::set< TClass *> &modifiedClasses)
Definition: TCling.cxx:450
#define name(a, b)
Definition: linkTestLib0.cpp:5
void RecursiveRemove(TObject *obj)
Delete object from cling symbol table so it can not be used anymore.
Definition: TCling.cxx:2905
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:1830
TString fIncludePath
Definition: TCling.h:106
Mother of all ROOT objects.
Definition: TObject.h:58
void TCling__LibraryUnloadedRTTI(const void *dyLibHandle, const char *canonicalName)
Definition: TCling.cxx:559
void RegisterTemporary(const TInterpreterValue &value)
Definition: TCling.cxx:6285
virtual FuncTempInfo_t * FuncTempInfo_FactoryCopy(FuncTempInfo_t *) const
Construct a FuncTempInfo_t.
Definition: TCling.cxx:7353
virtual void Inspect(TClass *cl, const char *parent, const char *name, const void *addr)
virtual const char * GetCurrentMacroName() const
Return the file name of the currently interpreted file, included or not.
Definition: TCling.cxx:4368
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:4975
virtual const char * MethodArgInfo_Name(MethodArgInfo_t *marginfo) const
Definition: TCling.cxx:7793
#define R__EXTERN
Definition: DllImport.h:27
TClassRef is used to implement a permanent reference to a TClass object.
Definition: TClassRef.h:33
virtual const char * GetTitle() const
Returns title of object.
Definition: TObject.cxx:459
typedef void((*Func_t)())
Version_t fClassVersion
Definition: TClass.h:201
void Unload()
Mark &#39;all func&#39; as being unloaded.
const char * GetFullTypeName() const
Get full type description of typedef, e,g.: "class TDirectory*".
Definition: TDataType.cxx:175
const char * GetDefault() const
Get default value of method argument.
Definition: TMethodArg.cxx:58
static TEnum * GetEnum(const std::type_info &ti, ESearchAction sa=kALoadAndInterpLookup)
Definition: TEnum.cxx:108
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...
virtual int DataMemberInfo_Next(DataMemberInfo_t *dminfo) const
Definition: TCling.cxx:7184
Bridge between cling::Value and ROOT.
Definition: TClingValue.h:38
virtual void TypeInfo_Init(TypeInfo_t *tinfo, const char *funcname) const
Definition: TCling.cxx:7852
void AddFriendToClass(clang::FunctionDecl *, clang::CXXRecordDecl *) const
Inject function as a friend into klass.
Definition: TCling.cxx:6367
int RefType() const
virtual bool ClassInfo_IsValidMethod(ClassInfo_t *info, const char *method, const char *proto, Long_t *offset, ROOT::EFunctionMatchMode=ROOT::kConversionMatch) const
Definition: TCling.cxx:6878
const char * GetUnqualifiedName(const char *name)
Return the start of the unqualified name include in &#39;original&#39;.
Definition: TClassEdit.cxx:850
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:1012
virtual void Add(TObject *obj)
Definition: TList.h:81
const Ssiz_t kNPOS
Definition: Rtypes.h:115
virtual void ClassInfo_DeleteArray(ClassInfo_t *info, void *arena, bool dtorOnly) const
Definition: TCling.cxx:6766
void ReplaceAll(std::string &str, const std::string &from, const std::string &to, bool recurse=false)
virtual const char * MethodInfo_Title(MethodInfo_t *minfo) const
Definition: TCling.cxx:7658
virtual std::string MethodArgInfo_TypeNormalizedName(MethodArgInfo_t *marginfo) const
Definition: TCling.cxx:7809
bool IsValid() const
virtual TList * GetListOfKeys() const
Bool_t fHeaderParsingOnDemand
Definition: TCling.h:147
virtual int ClassInfo_Next(ClassInfo_t *info) const
Definition: TCling.cxx:6894
virtual void CallFunc_Init(CallFunc_t *func) const
Definition: TCling.cxx:6540
void MakeZombie()
Definition: TObject.h:68
virtual void * ClassInfo_New(ClassInfo_t *info) const
Definition: TCling.cxx:6902
const char * Name() const
Each ROOT class (see TClass) has a linked list of methods.
Definition: TMethod.h:40
std::vector< std::pair< TClass *, DictFuncPtr_t > > fClassesToUpdate
Definition: TCling.h:136
virtual Long_t DataMemberInfo_TypeProperty(DataMemberInfo_t *dminfo) const
Definition: TCling.cxx:7208
virtual void CallFunc_ExecWithArgsAndReturn(CallFunc_t *func, void *address, const void *args[]=0, int nargs=0, void *ret=0) const
Definition: TCling.cxx:6474
static void * fgSetOfSpecials
Definition: TCling.h:95
virtual int GetProcInfo(ProcInfo_t *info) const
Returns cpu and memory used by this process into the ProcInfo_t structure.
Definition: TSystem.cxx:2430
TF1 * f1
Definition: legend1.C:11
TDictionary * Find(DeclId_t id) const
Return (after creating it if necessary) the TDataMember describing the data member corresponding to t...
virtual EReturnType MethodInfo_MethodCallReturnType(MethodInfo_t *minfo) const
Definition: TCling.cxx:7677
void Destruct(void *arena, const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt) const
const char * Name() const
static void SetFactory(TVirtualStreamerInfo *factory)
static function: Set the StreamerInfo factory
long ExecInt(void *address)
virtual Long_t Getgvp() const
Interface to the CINT global object pointer which was controlling the behavior of the wrapper around ...
Definition: TCling.cxx:6095
#define NULL
Definition: Rtypes.h:82
virtual void SetRTLD_LAZY() const
Definition: TCling.cxx:6245
Int_t SetClassSharedLibs(const char *cls, const char *libs)
Register the autoloading information for a class.
Definition: TCling.cxx:4941
Int_t GetEntries() const
Return the number of objects in array (i.e.
Definition: TObjArray.cxx:493
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:7376
virtual void GetFunctionName(const clang::FunctionDecl *decl, std::string &name) const
Definition: TCling.cxx:7304
virtual TObject * FindObject(const char *name) const
Find an object in this collection using its name.
virtual void * OpenDirectory(const char *name)
Open a directory. Returns 0 if directory does not exist.
Definition: TSystem.cxx:830
R__EXTERN Int_t gDebug
Definition: Rtypes.h:128
virtual void MethodInfo_Delete(MethodInfo_t *minfo) const
Interface to cling function.
Definition: TCling.cxx:7501
TClingTypeInfo * Type() const
Bool_t SetSuspendAutoParsing(Bool_t value)
Suspend the Autoparsing of headers.
Definition: TCling.cxx:6206
Int_t fMore
Definition: TCling.h:99
virtual void CallFunc_Exec(CallFunc_t *func, void *address) const
Definition: TCling.cxx:6450
static const std::string ioname("ioname")
virtual void ClassInfo_Destruct(ClassInfo_t *info, void *arena) const
Definition: TCling.cxx:6774
static bool R__InitStreamerInfoFactory()
Helper to initialize TVirtualStreamerInfo&#39;s factor early.
Definition: TCling.cxx:1253
void Add(TObject *obj)
Definition: TObjArray.h:75
virtual void CallFunc_Delete(CallFunc_t *func) const
Definition: TCling.cxx:6443
void IgnoreExtraArgs(bool ignore)
virtual int TypedefInfo_Size(TypedefInfo_t *tinfo) const
Definition: TCling.cxx:7979
Bool_t fIsAutoParsingSuspended
Definition: TCling.h:148
double result[121]
TDataMember * GetDataMember(const char *datamember) const
Return pointer to datamember object with name "datamember".
Definition: TClass.cxx:3211
static void UpdateClassInfoWork(const char *name)
Definition: TCling.cxx:5547
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:4609
void ResetBit(UInt_t f)
Definition: TObject.h:172
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:6161
A collection of TFunction objects designed for fast access given a DeclId_t and for keep track of TFu...
bool TClingLookupHelper__AutoParse(const char *cname)
Allow calling autoparsing from TMetaUtils.
Definition: TCling.cxx:892
void FullName(std::string &output, const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt) const
std::hash< std::string > fStringHashFunction
Definition: TCling.h:114
virtual const char * ClassInfo_Name(ClassInfo_t *info) const
Definition: TCling.cxx:6976
const char * GetSharedLibs()
Return the list of shared libraries loaded into the process.
Definition: TCling.cxx:5867
virtual void Fatal(const char *method, const char *msgfmt,...) const
Issue fatal error message.
Definition: TObject.cxx:946
static const char * FindLibraryName(void(*func)())
Wrapper around dladdr (and friends)
Definition: TCling.cxx:1218
R__EXTERN TInterpreter * gCling
Definition: TInterpreter.h:504
R__DLLEXPORT TInterpreter * CreateInterpreter(void *interpLibHandle)
Definition: TCling.cxx:575
virtual void Compress()
Remove empty slots from array.
Definition: TObjArray.cxx:308
#define I(x, y, z)
virtual bool CallFunc_IsValid(CallFunc_t *func) const
Definition: TCling.cxx:6549
bool IsLoaded() const
Long_t ProcessLineAsynch(const char *line, EErrorCode *error=0)
Let cling process a command line asynch.
Definition: TCling.cxx:2792
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:3767
static void output(int code)
Definition: gifencode.c:226
const Bool_t kTRUE
Definition: Rtypes.h:91
void TCling__TransactionRollback(const cling::Transaction &T)
Definition: TCling.cxx:549
virtual void FuncTempInfo_Name(FuncTempInfo_t *, TString &name) const
Return the name of this function template.
Definition: TCling.cxx:7456
virtual const char * MethodInfo_TypeName(MethodInfo_t *minfo) const
Definition: TCling.cxx:7639
const char * Name() const
TList * GetListOfMethods(Bool_t load=kTRUE)
Return list containing the TMethods of a class.
Definition: TClass.cxx:3578
virtual int DisplayIncludePath(FILE *fout) const
Interface to cling function.
Definition: TCling.cxx:6026
float value
Definition: math.cpp:443
virtual const char * ClassInfo_FileName(ClassInfo_t *info) const
Definition: TCling.cxx:6958
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:1044
void LoadMacro(const char *filename, EErrorCode *error=0)
Load a macro file in cling&#39;s memory.
Definition: TCling.cxx:2784
static DictFuncPtr_t GetDictNorm(const char *cname)
Given the normalized class name returns the Dictionary() function of a class (uses hash of name)...
const char * TypeName(const char *typeDesc)
Return the absolute type of typeDesc.
Definition: TCling.cxx:4383
virtual MethodInfo_t * CallFunc_FactoryMethod(CallFunc_t *func) const
Definition: TCling.cxx:6524
return
Definition: HLFactory.cxx:514
static char * skip(char **buf, const char *delimiters)
Definition: civetweb.c:1014
void LibraryUnloaded(const void *dyLibHandle, const char *canonicalName)
Definition: TCling.cxx:5859
const char * Name(const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt) const
const Int_t n
Definition: legend1.C:16
void RewindDictionary()
Rewind Cling dictionary to the point where it was before executing the current macro.
Definition: TCling.cxx:2984
virtual CallFunc_t * CallFunc_Factory() const
Definition: TCling.cxx:6509
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:2040
Int_t DeleteGlobal(void *obj)
Delete obj from Cling symbol table so it cannot be accessed anymore.
Definition: TCling.cxx:2998
TRandom3 R
a TMatrixD.
Definition: testIO.cxx:28
TEnum * Find(DeclId_t id) const
Return the TEnum corresponding to the Decl &#39;id&#39; or NULL if it does not exist.
void ResetGlobals()
Reset in Cling the list of global variables to the state saved by the last call to TCling::SaveGlobal...
Definition: TCling.cxx:2955
virtual int TypeInfo_RefType(TypeInfo_t *) const
Definition: TCling.cxx:7885
Long_t fMemResident
Definition: TSystem.h:206
virtual void CallFunc_ExecWithReturn(CallFunc_t *func, void *address, void *ret) const
Definition: TCling.cxx:6466
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition: TObject.cxx:904
void ExecWithArgsAndReturn(void *address, const void *args[]=0, int nargs=0, void *ret=0)
if(line.BeginsWith("/*"))
Definition: HLFactory.cxx:443
const clang::Type * GetType() const
const char * Value
Definition: TXMLSetup.cxx:73
void CreateListOfMethodArgs(TFunction *m) const
Create list of pointers to method arguments for TMethod m.
Definition: TCling.cxx:3497
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:6230
void ExecWithReturn(void *address, void *ret=0)
virtual void ClassInfo_Delete(ClassInfo_t *info) const
Definition: TCling.cxx:6751
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:2801
const char * Data() const
Definition: TString.h:349
virtual void DataMemberInfo_Delete(DataMemberInfo_t *dminfo) const
Definition: TCling.cxx:7134
TList * GetListOfFunctionTemplates(Bool_t load=kTRUE)
Return list containing the TEnums of a class.
Definition: TClass.cxx:3564
virtual const char * GetClassSharedLibs(const char *cls)=0
TClingMethodInfo GetMethodWithArgs(const char *fname, const char *arglist, long *poffset, ROOT::EFunctionMatchMode mode=ROOT::kConversionMatch, EInheritanceMode imode=kWithInheritance) const
long long ExecInt64(void *address)