ROOT  6.06/04
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 
74 #include "clang/AST/ASTContext.h"
75 #include "clang/AST/Decl.h"
76 #include "clang/AST/DeclarationName.h"
77 #include "clang/AST/GlobalDecl.h"
78 #include "clang/AST/RecordLayout.h"
79 #include "clang/AST/RecursiveASTVisitor.h"
80 #include "clang/AST/Type.h"
81 #include "clang/Basic/SourceLocation.h"
82 #include "clang/Basic/Specifiers.h"
83 #include "clang/Basic/TargetInfo.h"
84 #include "clang/CodeGen/ModuleBuilder.h"
85 #include "clang/Frontend/CompilerInstance.h"
86 #include "clang/Frontend/FrontendDiagnostic.h"
87 #include "clang/Lex/HeaderSearch.h"
88 #include "clang/Lex/Preprocessor.h"
89 #include "clang/Sema/Lookup.h"
90 #include "clang/Sema/Sema.h"
91 #include "clang/Parse/Parser.h"
92 
93 #include "cling/Interpreter/ClangInternalState.h"
94 #include "cling/Interpreter/DynamicLibraryManager.h"
95 #include "cling/Interpreter/Interpreter.h"
96 #include "cling/Interpreter/LookupHelper.h"
97 #include "cling/Interpreter/Value.h"
98 #include "cling/Interpreter/Transaction.h"
99 #include "cling/MetaProcessor/MetaProcessor.h"
100 #include "cling/Utils/AST.h"
101 
102 #include "llvm/IR/GlobalValue.h"
103 #include "llvm/IR/Module.h"
104 
105 #include "llvm/Support/DynamicLibrary.h"
106 #include "llvm/Support/raw_ostream.h"
107 #include "llvm/Support/Path.h"
108 
109 #include <algorithm>
110 #include <iostream>
111 #include <cassert>
112 #include <map>
113 #include <set>
114 #include <stdexcept>
115 #include <stdint.h>
116 #include <fstream>
117 #include <sstream>
118 #include <string>
119 #include <typeinfo>
120 #include <unordered_map>
121 #include <utility>
122 #include <vector>
123 
124 #ifndef R__WIN32
125 #include <cxxabi.h>
126 #define R__DLLEXPORT
127 #endif
128 #include <limits.h>
129 #include <stdio.h>
130 
131 #ifdef __APPLE__
132 #include <dlfcn.h>
133 #include <mach-o/dyld.h>
134 #endif // __APPLE__
135 
136 #ifdef R__UNIX
137 #include <dlfcn.h>
138 #endif
139 
140 #if defined(__CYGWIN__)
141 #include <sys/cygwin.h>
142 #define HMODULE void *
143 extern "C" {
144  __declspec(dllimport) void * __stdcall GetCurrentProcess();
145  __declspec(dllimport) bool __stdcall EnumProcessModules(void *, void **, unsigned long, unsigned long *);
146  __declspec(dllimport) unsigned long __stdcall GetModuleFileNameExW(void *, void *, wchar_t *, unsigned long);
147 }
148 #endif
149 
150 // Fragment copied from LLVM's raw_ostream.cpp
151 #if defined(_MSC_VER)
152 #ifndef STDIN_FILENO
153 # define STDIN_FILENO 0
154 #endif
155 #ifndef STDOUT_FILENO
156 # define STDOUT_FILENO 1
157 #endif
158 #ifndef STDERR_FILENO
159 # define STDERR_FILENO 2
160 #endif
161 #ifndef R__WIN32
162 //#if defined(HAVE_UNISTD_H)
163 # include <unistd.h>
164 //#endif
165 #else
166 #include "Windows4Root.h"
167 #include <Psapi.h>
168 #undef GetModuleFileName
169 #define RTLD_DEFAULT ((void *)::GetModuleHandle(NULL))
170 #define dlsym(library, function_name) ::GetProcAddress((HMODULE)library, function_name)
171 #define dlopen(library_name, flags) ::LoadLibrary(library_name)
172 #define dlclose(library) ::FreeLibrary((HMODULE)library)
173 #define R__DLLEXPORT __declspec(dllexport)
174 #endif
175 #endif
176 
177 //______________________________________________________________________________
178 // Infrastructure to detect and react to libCling being teared down.
179 //
180 namespace {
181  class TCling_UnloadMarker {
182  public:
183  ~TCling_UnloadMarker() {
186  }
187  }
188  };
189  static TCling_UnloadMarker gTClingUnloadMarker;
190 }
191 
192 
193 
194 //______________________________________________________________________________
195 // These functions are helpers for debugging issues with non-LLVMDEV builds.
196 //
197 clang::DeclContext* TCling__DEBUG__getDeclContext(clang::Decl* D) {
198  return D->getDeclContext();
199 }
200 clang::NamespaceDecl* TCling__DEBUG__DCtoNamespace(clang::DeclContext* DC) {
201  return llvm::dyn_cast<clang::NamespaceDecl>(DC);
202 }
203 clang::RecordDecl* TCling__DEBUG__DCtoRecordDecl(clang::DeclContext* DC) {
204  return llvm::dyn_cast<clang::RecordDecl>(DC);
205 }
206 void TCling__DEBUG__dump(clang::DeclContext* DC) {
207  return DC->dumpDeclContext();
208 }
209 void TCling__DEBUG__dump(clang::Decl* D) {
210  return D->dump();
211 }
212 void TCling__DEBUG__dump(clang::FunctionDecl* FD) {
213  return FD->dump();
214 }
216  return ((clang::Decl*)D)->dump();
217 }
218 void TCling__DEBUG__printName(clang::Decl* D) {
219  if (clang::NamedDecl* ND = llvm::dyn_cast<clang::NamedDecl>(D)) {
220  std::string name;
221  {
222  llvm::raw_string_ostream OS(name);
223  ND->getNameForDiagnostic(OS, D->getASTContext().getPrintingPolicy(),
224  true /*Qualified*/);
225  }
226  printf("%s\n", name.c_str());
227  }
228 }
229 //______________________________________________________________________________
230 // These functions are helpers for testing issues directly rather than
231 // relying on side effects.
232 // This is used for the test for ROOT-7462/ROOT-6070
233 bool TCling__TEST_isInvalidDecl(clang::Decl* D) {
234  return D->isInvalidDecl();
235 }
236 bool TCling__TEST_isInvalidDecl(ClassInfo_t *input) {
237  TClingClassInfo *info( (TClingClassInfo*) input);
238  assert(info && info->IsValid());
239  return info->GetDecl()->isInvalidDecl();
240 }
241 
242 using namespace std;
243 using namespace clang;
244 using namespace ROOT;
245 
246 namespace {
247  static const std::string gInterpreterClassDef = R"ICF(
248 #undef ClassDef
249 #define ClassDef(name, id) \
250 _ClassDefInterp_(name,id,virtual,) \
251 static int DeclFileLine() { return __LINE__; }
252 #undef ClassDefNV
253 #define ClassDefNV(name, id) \
254 _ClassDefInterp_(name,id,,) \
255 static int DeclFileLine() { return __LINE__; }
256 #undef ClassDefOverride
257 #define ClassDefOverride(name, id) \
258 _ClassDefInterp_(name,id,,override) \
259 static int DeclFileLine() { return __LINE__; }
260 )ICF";
261 
262  static const std::string gNonInterpreterClassDef = R"ICF(
263 #define __ROOTCLING__ 1
264 #undef ClassDef
265 #define ClassDef(name,id) \
266 _ClassDef_(name,id,virtual,) \
267 static int DeclFileLine() { return __LINE__; }
268 #undef ClassDefNV
269 #define ClassDefNV(name, id)\
270 _ClassDef_(name,id,,)\
271 static int DeclFileLine() { return __LINE__; }
272 #undef ClassDefOverride
273 #define ClassDefOverride(name, id)\
274 _ClassDef_(name,id,,override)\
275 static int DeclFileLine() { return __LINE__; }
276 )ICF";
277 
278 // The macros below use ::Error, so let's ensure it is included
279  static const std::string gClassDefInterpMacro = R"ICF(
280 #ifndef ROOT_TError
281 #include "TError.h"
282 #endif
283 
284 #define _ClassDefInterp_(name,id,virtual_keyword, overrd) \
285 private: \
286 public: \
287  static TClass *Class() { static TClass* sIsA = 0; if (!sIsA) sIsA = TClass::GetClass(#name); return sIsA; } \
288  static const char *Class_Name() { return #name; } \
289  static Version_t Class_Version() { return id; } \
290  static TClass *Dictionary() { return 0; } \
291  virtual_keyword TClass *IsA() const overrd { return name::Class(); } \
292  virtual_keyword void ShowMembers(TMemberInspector&insp) const overrd { ::ROOT::Class_ShowMembers(name::Class(), this, insp); } \
293  virtual_keyword void Streamer(TBuffer&) overrd { ::Error("Streamer", "Cannot stream interpreted class."); } \
294  void StreamerNVirtual(TBuffer&ClassDef_StreamerNVirtual_b) { name::Streamer(ClassDef_StreamerNVirtual_b); } \
295  static const char *DeclFileName() { return __FILE__; } \
296  static int ImplFileLine() { return 0; } \
297  static const char *ImplFileName() { return __FILE__; }
298 )ICF";
299 }
301 
302 // The functions are used to bridge cling/clang/llvm compiled with no-rtti and
303 // ROOT (which uses rtti)
304 
305 //______________________________________________________________________________
306 
307 // Class extracting recursively every Enum type defined for a class.
308 class EnumVisitor : public RecursiveASTVisitor<EnumVisitor> {
309 private:
310  llvm::SmallVector<EnumDecl*,128> &fClassEnums;
311 public:
312  EnumVisitor(llvm::SmallVector<EnumDecl*,128> &enums) : fClassEnums(enums)
313  {}
314 
315  bool TraverseStmt(Stmt*) {
316  // Don't descend into function bodies.
317  return true;
318  }
319 
320  bool shouldVisitTemplateInstantiations() const { return true; }
321 
322  bool TraverseClassTemplateDecl(ClassTemplateDecl*) {
323  // Don't descend into templates (but only instances thereof).
324  return true; // returning false will abort the in-depth traversal.
325  }
326 
327  bool TraverseClassTemplatePartialSpecializationDecl(ClassTemplatePartialSpecializationDecl*) {
328  // Don't descend into templates partial specialization (but only instances thereof).
329  return true; // returning false will abort the in-depth traversal.
330  }
331 
332  bool VisitEnumDecl(EnumDecl *TEnumD) {
333  if (!TEnumD->getDeclContext()->isDependentContext())
334  fClassEnums.push_back(TEnumD);
335  return true; // returning false will abort the in-depth traversal.
336  }
337 };
338 
339 ////////////////////////////////////////////////////////////////////////////////
340 /// Update TClingClassInfo for a class (e.g. upon seeing a definition).
341 
342 static void TCling__UpdateClassInfo(const NamedDecl* TD)
343 {
344  static Bool_t entered = kFALSE;
345  static vector<const NamedDecl*> updateList;
346  Bool_t topLevel;
347 
348  if (entered) topLevel = kFALSE;
349  else {
350  entered = kTRUE;
351  topLevel = kTRUE;
352  }
353  if (topLevel) {
354  ((TCling*)gInterpreter)->UpdateClassInfoWithDecl(TD);
355  } else {
356  // If we are called indirectly from within another call to
357  // TCling::UpdateClassInfo, we delay the update until the dictionary loading
358  // is finished (i.e. when we return to the top level TCling::UpdateClassInfo).
359  // This allows for the dictionary to be fully populated when we actually
360  // update the TClass object. The updating of the TClass sometimes
361  // (STL containers and when there is an emulated class) forces the building
362  // of the TClass object's real data (which needs the dictionary info).
363  updateList.push_back(TD);
364  }
365  if (topLevel) {
366  while (!updateList.empty()) {
367  ((TCling*)gInterpreter)->UpdateClassInfoWithDecl(updateList.back());
368  updateList.pop_back();
369  }
370  entered = kFALSE;
371  }
372 }
373 
374 void TCling::UpdateEnumConstants(TEnum* enumObj, TClass* cl) const {
375  const clang::Decl* D = static_cast<const clang::Decl*>(enumObj->GetDeclId());
376  if(const clang::EnumDecl* ED = dyn_cast<clang::EnumDecl>(D)) {
377  // Add the constants to the enum type.
378  for (EnumDecl::enumerator_iterator EDI = ED->enumerator_begin(),
379  EDE = ED->enumerator_end(); EDI != EDE; ++EDI) {
380  // Get name of the enum type.
381  std::string constbuf;
382  if (const NamedDecl* END = llvm::dyn_cast<NamedDecl>(*EDI)) {
383  PrintingPolicy Policy((*EDI)->getASTContext().getPrintingPolicy());
384  llvm::raw_string_ostream stream(constbuf);
385  (END)->getNameForDiagnostic(stream, Policy, /*Qualified=*/false);
386  }
387  const char* constantName = constbuf.c_str();
388 
389  // Get value of the constant.
390  Long64_t value;
391  const llvm::APSInt valAPSInt = (*EDI)->getInitVal();
392  if (valAPSInt.isSigned()) {
393  value = valAPSInt.getSExtValue();
394  } else {
395  value = valAPSInt.getZExtValue();
396  }
397 
398  // Create the TEnumConstant or update it if existing
399  TEnumConstant* enumConstant = nullptr;
400  TClingClassInfo* tcCInfo = (TClingClassInfo*)(cl ? cl->GetClassInfo() : 0);
401  TClingDataMemberInfo* tcDmInfo = new TClingDataMemberInfo(fInterpreter, *EDI, tcCInfo);
402  DataMemberInfo_t* dmInfo = (DataMemberInfo_t*) tcDmInfo;
403  if (TObject* encAsTObj = enumObj->GetConstants()->FindObject(constantName)){
404  ((TEnumConstant*)encAsTObj)->Update(dmInfo);
405  } else {
406  enumConstant = new TEnumConstant(dmInfo, constantName, value, enumObj);
407  }
408 
409  // Add the global constants to the list of Globals.
410  if (!cl) {
411  TCollection* globals = gROOT->GetListOfGlobals(false);
412  if (!globals->FindObject(constantName)) {
413  globals->Add(enumConstant);
414  }
415  }
416  }
417  }
418 }
419 
420 TEnum* TCling::CreateEnum(void *VD, TClass *cl) const
421 {
422  // Handle new enum declaration for either global and nested enums.
423 
424  // Create the enum type.
425  TEnum* enumType = 0;
426  const clang::Decl* D = static_cast<const clang::Decl*>(VD);
427  std::string buf;
428  if (const EnumDecl* ED = llvm::dyn_cast<EnumDecl>(D)) {
429  // Get name of the enum type.
430  PrintingPolicy Policy(ED->getASTContext().getPrintingPolicy());
431  llvm::raw_string_ostream stream(buf);
432  ED->getNameForDiagnostic(stream, Policy, /*Qualified=*/false);
433  // If the enum is unnamed we do not add it to the list of enums i.e unusable.
434  }
435  if (buf.empty()) {
436  return 0;
437  }
438  const char* name = buf.c_str();
439  if (cl) {
440  enumType = new TEnum(name, VD, cl);
441  } else {
442  enumType = new TEnum(name, VD, cl);
443  }
444  UpdateEnumConstants(enumType, cl);
445 
446  return enumType;
447 }
448 
449 void TCling::HandleNewDecl(const void* DV, bool isDeserialized, std::set<TClass*> &modifiedTClasses) {
450  // Handle new declaration.
451  // Record the modified class, struct and namespaces in 'modifiedTClasses'.
452 
453  const clang::Decl* D = static_cast<const clang::Decl*>(DV);
454 
455  if (!D->isCanonicalDecl() && !isa<clang::NamespaceDecl>(D)
456  && !dyn_cast<clang::RecordDecl>(D)) return;
457 
458  if (isa<clang::FunctionDecl>(D->getDeclContext())
459  || isa<clang::TagDecl>(D->getDeclContext()))
460  return;
461 
462  // Don't list templates.
463  if (const clang::CXXRecordDecl* RD = dyn_cast<clang::CXXRecordDecl>(D)) {
464  if (RD->getDescribedClassTemplate())
465  return;
466  } else if (const clang::FunctionDecl* FD = dyn_cast<clang::FunctionDecl>(D)) {
467  if (FD->getDescribedFunctionTemplate())
468  return;
469  }
470 
471  if (const RecordDecl *TD = dyn_cast<RecordDecl>(D)) {
472  if (TD->isCanonicalDecl() || TD->isThisDeclarationADefinition())
474  }
475  else if (const NamedDecl *ND = dyn_cast<NamedDecl>(D)) {
476 
477  if (const TagDecl *TD = dyn_cast<TagDecl>(D)) {
478  // Mostly just for EnumDecl (the other TagDecl are handled
479  // by the 'RecordDecl' if statement.
481  } else if (const NamespaceDecl* NSD = dyn_cast<NamespaceDecl>(D)) {
483  }
484 
485  // While classes are read completely (except for function template instances,
486  // enum, data (and functions) can be added to namespaces at any time.
487  // [this section can be removed when both the list of data member and the list
488  // of enums has been update to be active list]
489  if (const NamespaceDecl* NCtx = dyn_cast<NamespaceDecl>(ND->getDeclContext())) {
490  if (NCtx->getIdentifier()) {
491  // No need to load the TClass: if there is something to update then
492  // it must already exist.
493  std::string NCtxName;
494  PrintingPolicy Policy(NCtx->getASTContext().getPrintingPolicy());
495  llvm::raw_string_ostream stream(NCtxName);
496  NCtx->getNameForDiagnostic(stream, Policy, /*Qualified=*/true);
497 
498  TClass* cl = (TClass*)gROOT->GetListOfClasses()->FindObject(NCtxName.c_str());
499  if (cl) {
500  modifiedTClasses.insert(cl);
501  }
502  }
503  return;
504  }
505 
506  // We care about declarations on the global scope.
507  if (!isa<TranslationUnitDecl>(ND->getDeclContext()))
508  return;
509 
510  // Enums are lazyly created, thus we don not need to handle them here.
511  if (isa<EnumDecl>(ND))
512  return;
513 
514  // ROOT says that global is enum(lazylycreated)/var/field declared on the global
515  // scope.
516  if (!(isa<VarDecl>(ND)))
517  return;
518 
519  // Skip if already in the list.
520  if (gROOT->GetListOfGlobals()->FindObject(ND->getNameAsString().c_str()))
521  return;
522 
523  // Put the global constants and global enums in the corresponding lists.
524  gROOT->GetListOfGlobals()->Add(new TGlobal((DataMemberInfo_t *)
525  new TClingDataMemberInfo(fInterpreter,
526  cast<ValueDecl>(ND), 0)));
527  }
528 }
529 
530 extern "C"
532 {
533  // We are sure in this context of the type of the interpreter
534  normCtxt = &( (TCling*) gInterpreter)->GetNormalizedContext();
535 }
536 
537 extern "C"
538 void TCling__UpdateListsOnCommitted(const cling::Transaction &T, cling::Interpreter*) {
539 
540  ((TCling*)gCling)->UpdateListsOnCommitted(T);
541 }
542 
543 extern "C"
544 void TCling__UpdateListsOnUnloaded(const cling::Transaction &T) {
545 
546  ((TCling*)gCling)->UpdateListsOnUnloaded(T);
547 }
548 void TCling__TransactionRollback(const cling::Transaction &T) {
549 
550  ((TCling*)gCling)->TransactionRollback(T);
551 }
552 extern "C" void TCling__LibraryLoadedRTTI(const void* dyLibHandle,
553  const char* canonicalName) {
554 
555  ((TCling*)gCling)->LibraryLoaded(dyLibHandle, canonicalName);
556 }
557 
558 extern "C" void TCling__LibraryUnloadedRTTI(const void* dyLibHandle,
559  const char* canonicalName) {
560 
561  ((TCling*)gCling)->LibraryUnloaded(dyLibHandle, canonicalName);
562 }
563 
564 
565 extern "C"
566 TObject* TCling__GetObjectAddress(const char *Name, void *&LookupCtx) {
567  return ((TCling*)gCling)->GetObjectAddress(Name, LookupCtx);
568 }
569 
570 extern "C" const Decl* TCling__GetObjectDecl(TObject *obj) {
571  return ((TClingClassInfo*)obj->IsA()->GetClassInfo())->GetDecl();
572 }
573 
574 extern "C" R__DLLEXPORT TInterpreter *CreateInterpreter(void* interpLibHandle)
575 {
576  cling::DynamicLibraryManager::ExposeHiddenSharedLibrarySymbols(interpLibHandle);
577  return new TCling("C++", "cling C++ Interpreter");
578 }
579 
581 {
582  delete interp;
583 }
584 
585 // Load library containing specified class. Returns 0 in case of error
586 // and 1 in case if success.
587 extern "C" int TCling__AutoLoadCallback(const char* className)
588 {
589  return ((TCling*)gCling)->AutoLoad(className);
590 }
591 
592 extern "C" int TCling__AutoParseCallback(const char* className)
593 {
594  return ((TCling*)gCling)->AutoParse(className);
595 }
596 
597 extern "C" const char* TCling__GetClassSharedLibs(const char* className)
598 {
599  return ((TCling*)gCling)->GetClassSharedLibs(className);
600 }
601 
602 // // Returns 0 for failure 1 for success
603 // extern "C" int TCling__IsAutoLoadNamespaceCandidate(const char* name)
604 // {
605 // return ((TCling*)gCling)->IsAutoLoadNamespaceCandidate(name);
606 // }
607 
608 // Returns 0 for failure 1 for success
609 extern "C" int TCling__IsAutoLoadNamespaceCandidate(const clang::NamespaceDecl* nsDecl)
610 {
611  return ((TCling*)gCling)->IsAutoLoadNamespaceCandidate(nsDecl);
612 }
613 
614 extern "C" int TCling__CompileMacro(const char *fileName, const char *options)
615 {
616  string file(fileName);
617  string opt(options);
618  return gSystem->CompileMacro(file.c_str(), opt.c_str());
619 }
620 
621 extern "C" void TCling__SplitAclicMode(const char* fileName, string &mode,
622  string &args, string &io, string &fname)
623 {
624  string file(fileName);
625  TString f, amode, arguments, aclicio;
626  f = gSystem->SplitAclicMode(file.c_str(), amode, arguments, aclicio);
627  mode = amode.Data(); args = arguments.Data();
628  io = aclicio.Data(); fname = f.Data();
629 }
630 
631 //______________________________________________________________________________
632 //
633 //
634 //
635 
636 #ifdef R__WIN32
637 extern "C" {
638  char *__unDName(char *demangled, const char *mangled, int out_len,
639  void * (* pAlloc )(size_t), void (* pFree )(void *),
640  unsigned short int flags);
641 }
642 #endif
643 
644 ////////////////////////////////////////////////////////////////////////////////
645 /// Find a template decl within N nested namespaces, 0<=N<inf
646 /// Assumes 1 and only 1 template present and 1 and only 1 entity contained
647 /// by the namespace. Example: ns1::ns2::..::nsN::myTemplate
648 /// Returns nullptr in case of error
649 
650 static clang::ClassTemplateDecl* FindTemplateInNamespace(clang::Decl* decl)
651 {
652  using namespace clang;
653  if (NamespaceDecl* nsd = llvm::dyn_cast<NamespaceDecl>(decl)){
654  return FindTemplateInNamespace(*nsd->decls_begin());
655  }
656 
657  if (ClassTemplateDecl* ctd = llvm::dyn_cast<ClassTemplateDecl>(decl)){
658  return ctd;
659  }
660 
661  return nullptr; // something went wrong.
662 }
663 
664 ////////////////////////////////////////////////////////////////////////////////
665 /// Autoload a library provided the mangled name of a missing symbol.
666 
667 void* llvmLazyFunctionCreator(const std::string& mangled_name)
668 {
669  return ((TCling*)gCling)->LazyFunctionCreatorAutoload(mangled_name);
670 }
671 
672 //______________________________________________________________________________
673 //
674 //
675 //
676 
677 int TCling_GenerateDictionary(const std::vector<std::string> &classes,
678  const std::vector<std::string> &headers,
679  const std::vector<std::string> &fwdDecls,
680  const std::vector<std::string> &unknown)
681 {
682  //This function automatically creates the "LinkDef.h" file for templated
683  //classes then executes CompileMacro on it.
684  //The name of the file depends on the class name, and it's not generated again
685  //if the file exist.
686  if (classes.empty()) {
687  return 0;
688  }
689  // Use the name of the first class as the main name.
690  const std::string& className = classes[0];
691  //(0) prepare file name
692  TString fileName = "AutoDict_";
693  std::string::const_iterator sIt;
694  for (sIt = className.begin(); sIt != className.end(); sIt++) {
695  if (*sIt == '<' || *sIt == '>' ||
696  *sIt == ' ' || *sIt == '*' ||
697  *sIt == ',' || *sIt == '&' ||
698  *sIt == ':') {
699  fileName += '_';
700  }
701  else {
702  fileName += *sIt;
703  }
704  }
705  if (classes.size() > 1) {
706  Int_t chk = 0;
707  std::vector<std::string>::const_iterator it = classes.begin();
708  while ((++it) != classes.end()) {
709  for (UInt_t cursor = 0; cursor != it->length(); ++cursor) {
710  chk = chk * 3 + it->at(cursor);
711  }
712  }
713  fileName += TString::Format("_%u", chk);
714  }
715  fileName += ".cxx";
716  if (gSystem->AccessPathName(fileName) != 0) {
717  //file does not exist
718  //(1) prepare file data
719  // If STL, also request iterators' operators.
720  // vector is special: we need to check whether
721  // vector::iterator is a typedef to pointer or a
722  // class.
723  static const std::set<std::string> sSTLTypes {"vector","list","unordered_list","deque","map","multimap","set","unordered_set","multiset","queue","priority_queue","stack","iterator"};
724  std::vector<std::string>::const_iterator it;
725  std::string fileContent("");
726  for (it = headers.begin(); it != headers.end(); ++it) {
727  fileContent += "#include \"" + *it + "\"\n";
728  }
729  for (it = unknown.begin(); it != unknown.end(); ++it) {
730  TClass* cl = TClass::GetClass(it->c_str());
731  if (cl && cl->GetDeclFileName()) {
732  TString header(gSystem->BaseName(cl->GetDeclFileName()));
733  TString dir(gSystem->DirName(cl->GetDeclFileName()));
734  TString dirbase(gSystem->BaseName(dir));
735  while (dirbase.Length() && dirbase != "."
736  && dirbase != "include" && dirbase != "inc"
737  && dirbase != "prec_stl") {
738  gSystem->PrependPathName(dirbase, header);
739  dir = gSystem->DirName(dir);
740  }
741  fileContent += TString("#include \"") + header + "\"\n";
742  }
743  }
744  for (it = fwdDecls.begin(); it != fwdDecls.end(); ++it) {
745  fileContent += "class " + *it + ";\n";
746  }
747  fileContent += "#ifdef __CINT__ \n";
748  fileContent += "#pragma link C++ nestedclasses;\n";
749  fileContent += "#pragma link C++ nestedtypedefs;\n";
750  for (it = classes.begin(); it != classes.end(); ++it) {
751  std::string n(*it);
752  size_t posTemplate = n.find('<');
753  std::set<std::string>::const_iterator iSTLType = sSTLTypes.end();
754  if (posTemplate != std::string::npos) {
755  n.erase(posTemplate, std::string::npos);
756  if (n.compare(0, 5, "std::") == 0) {
757  n.erase(0, 5);
758  }
759  iSTLType = sSTLTypes.find(n);
760  }
761  fileContent += "#pragma link C++ class ";
762  fileContent += *it + "+;\n" ;
763  fileContent += "#pragma link C++ class ";
764  if (iSTLType != sSTLTypes.end()) {
765  // STL class; we cannot (and don't need to) store iterators;
766  // their shadow and the compiler's version don't agree. So
767  // don't ask for the '+'
768  fileContent += *it + "::*;\n" ;
769  }
770  else {
771  // Not an STL class; we need to allow the I/O of contained
772  // classes (now that we have a dictionary for them).
773  fileContent += *it + "::*+;\n" ;
774  }
775  std::string oprLink("#pragma link C++ operators ");
776  oprLink += *it;
777  // Don't! Requests e.g. op<(const vector<T>&, const vector<T>&):
778  // fileContent += oprLink + ";\n";
779  if (iSTLType != sSTLTypes.end()) {
780  if (n == "vector") {
781  fileContent += "#ifdef G__VECTOR_HAS_CLASS_ITERATOR\n";
782  }
783  fileContent += oprLink + "::iterator;\n";
784  fileContent += oprLink + "::const_iterator;\n";
785  fileContent += oprLink + "::reverse_iterator;\n";
786  if (n == "vector") {
787  fileContent += "#endif\n";
788  }
789  }
790  }
791  fileContent += "#endif\n";
792  //end(1)
793  //(2) prepare the file
794  FILE* filePointer;
795  filePointer = fopen(fileName, "w");
796  if (filePointer == NULL) {
797  //can't open a file
798  return 1;
799  }
800  //end(2)
801  //write data into the file
802  fprintf(filePointer, "%s", fileContent.c_str());
803  fclose(filePointer);
804  }
805  //(3) checking if we can compile a macro, if not then cleaning
806  Int_t oldErrorIgnoreLevel = gErrorIgnoreLevel;
807  gErrorIgnoreLevel = kWarning; // no "Info: creating library..."
808  Int_t ret = gSystem->CompileMacro(fileName, "k");
809  gErrorIgnoreLevel = oldErrorIgnoreLevel;
810  if (ret == 0) { //can't compile a macro
811  return 2;
812  }
813  //end(3)
814  return 0;
815 }
816 
817 int TCling_GenerateDictionary(const std::string& className,
818  const std::vector<std::string> &headers,
819  const std::vector<std::string> &fwdDecls,
820  const std::vector<std::string> &unknown)
821 {
822  //This function automatically creates the "LinkDef.h" file for templated
823  //classes then executes CompileMacro on it.
824  //The name of the file depends on the class name, and it's not generated again
825  //if the file exist.
826  std::vector<std::string> classes;
827  classes.push_back(className);
828  return TCling_GenerateDictionary(classes, headers, fwdDecls, unknown);
829 }
830 
831 //______________________________________________________________________________
832 //
833 //
834 //
835 
836 // It is a "fantom" method to synchronize user keyboard input
837 // and ROOT prompt line (for WIN32)
838 const char* fantomline = "TRint::EndOfLineAction();";
839 
840 //______________________________________________________________________________
841 //
842 //
843 //
844 
845 void* TCling::fgSetOfSpecials = 0;
846 
847 //______________________________________________________________________________
848 //
849 // llvm error handler through exceptions; see also cling/UserInterface
850 //
851 namespace {
852  // Handle fatal llvm errors by throwing an exception.
853  // Yes, throwing exceptions in error handlers is bad.
854  // Doing nothing is pretty terrible, too.
855  void exceptionErrorHandler(void * /*user_data*/,
856  const std::string& reason,
857  bool /*gen_crash_diag*/) {
858  throw std::runtime_error(std::string(">>> Interpreter compilation error:\n") + reason);
859  }
860 }
861 
862 //______________________________________________________________________________
863 //
864 //
865 //
866 
867 ////////////////////////////////////////////////////////////////////////////////
868 
869 namespace{
870  // An instance of this class causes the diagnostics of clang to be suppressed
871  // during its lifetime
872  class clangDiagSuppr {
873  public:
874  clangDiagSuppr(clang::DiagnosticsEngine& diag): fDiagEngine(diag){
875  fOldDiagValue = fDiagEngine.getIgnoreAllWarnings();
876  fDiagEngine.setIgnoreAllWarnings(true);
877  }
878 
879  ~clangDiagSuppr() {
880  fDiagEngine.setIgnoreAllWarnings(fOldDiagValue);
881  }
882  private:
883  clang::DiagnosticsEngine& fDiagEngine;
884  bool fOldDiagValue;
885  };
886 
887 }
888 
889 ////////////////////////////////////////////////////////////////////////////////
890 /// Allow calling autoparsing from TMetaUtils
891 bool TClingLookupHelper__AutoParse(const char *cname)
892 {
893  return gCling->AutoParse(cname);
894 }
895 
896 ////////////////////////////////////////////////////////////////////////////////
897 /// Try hard to avoid looking up in the Cling database as this could enduce
898 /// an unwanted autoparsing.
899 
900 bool TClingLookupHelper__ExistingTypeCheck(const std::string &tname,
901  std::string &result)
902 {
903  result.clear();
904 
905  unsigned long offset = 0;
906  if (strncmp(tname.c_str(), "const ", 6) == 0) {
907  offset = 6;
908  }
909  unsigned long end = tname.length();
910  while( end && (tname[end-1]=='&' || tname[end-1]=='*' || tname[end-1]==']') ) {
911  if ( tname[end-1]==']' ) {
912  --end;
913  while ( end && tname[end-1]!='[' ) --end;
914  }
915  --end;
916  }
917  std::string innerbuf;
918  const char *inner;
919  if (end != tname.length()) {
920  innerbuf = tname.substr(offset,end-offset);
921  inner = innerbuf.c_str();
922  } else {
923  inner = tname.c_str()+offset;
924  }
925 
926  //if (strchr(tname.c_str(),'[')!=0) fprintf(stderr,"DEBUG: checking on %s vs %s %lu %lu\n",tname.c_str(),inner,offset,end);
927  if (gROOT->GetListOfClasses()->FindObject(inner)
928  || TClassTable::Check(inner,result) ) {
929  // This is a known class.
930  return true;
931  }
932 
933  THashTable *typeTable = dynamic_cast<THashTable*>( gROOT->GetListOfTypes() );
934  TDataType *type = (TDataType *)typeTable->THashTable::FindObject( inner );
935  if (type) {
936  // This is a raw type and an already loaded typedef.
937  const char *newname = type->GetFullTypeName();
938  if (type->GetType() == kLong64_t) {
939  newname = "Long64_t";
940  } else if (type->GetType() == kULong64_t) {
941  newname = "ULong64_t";
942  }
943  if (strcmp(inner,newname) == 0) {
944  return true;
945  }
946  if (offset) result = "const ";
947  result += newname;
948  if ( end != tname.length() ) {
949  result += tname.substr(end,tname.length()-end);
950  }
951  if (result == tname) result.clear();
952  return true;
953  }
954 
955  // Check if the name is an enumerator
956  const auto lastPos = TClassEdit::GetUnqualifiedName(inner);
957  if (lastPos != inner) // Main switch: case 1 - scoped enum, case 2 global enum
958  {
959  // We have a scope
960  // All of this C gymnastic is to avoid allocations on the heap
961  const auto enName = lastPos;
962  const auto scopeNameSize = ((Long64_t)lastPos - (Long64_t)inner) / sizeof(decltype(*lastPos)) - 2;
963 #ifdef R__WIN32
964  char *scopeName = new char[scopeNameSize + 1];
965 #else
966  char scopeName[scopeNameSize + 1]; // on the stack, +1 for the terminating character '\0'
967 #endif
968  strncpy(scopeName, inner, scopeNameSize);
969  scopeName[scopeNameSize] = '\0';
970  // Check if the scope is in the list of classes
971  if (auto scope = static_cast<TClass *>(gROOT->GetListOfClasses()->FindObject(scopeName))) {
972  auto enumTable = dynamic_cast<const THashList *>(scope->GetListOfEnums(false));
973  if (enumTable && enumTable->THashList::FindObject(enName)) return true;
974  }
975  // It may still be in one of the loaded protoclasses
976  else if (auto scope = static_cast<TProtoClass *>(gClassTable->GetProtoNorm(scopeName))) {
977  auto listOfEnums = scope->GetListOfEnums();
978  if (listOfEnums) { // it could be null: no enumerators in the protoclass
979  auto enumTable = dynamic_cast<const THashList *>(listOfEnums);
980  if (enumTable && enumTable->THashList::FindObject(enName)) return true;
981  }
982  }
983 #ifdef R__WIN32
984  delete [] scopeName;
985 #endif
986  } else
987  {
988  // We don't have any scope: this could only be a global enum
989  auto enumTable = dynamic_cast<const THashList *>(gROOT->GetListOfEnums());
990  if (enumTable && enumTable->THashList::FindObject(inner)) return true;
991  }
992 
993  if (gCling->GetClassSharedLibs(inner))
994  {
995  // This is a class name.
996  return true;
997  }
998 
999  return false;
1000 }
1001 
1002 ////////////////////////////////////////////////////////////////////////////////
1003 
1005 {
1006  fContent.reserve(size);
1007 }
1008 
1009 ////////////////////////////////////////////////////////////////////////////////
1010 
1011 inline const char *TCling::TUniqueString::Data()
1012 {
1013  return fContent.c_str();
1014 }
1015 
1016 ////////////////////////////////////////////////////////////////////////////////
1017 /// Append string to the storage if not added already.
1018 
1019 inline bool TCling::TUniqueString::Append(const std::string& str)
1020 {
1021  bool notPresent = fLinesHashSet.emplace(fHashFunc(str)).second;
1022  if (notPresent){
1023  fContent+=str;
1024  }
1025  return notPresent;
1026 }
1027 
1028 ////////////////////////////////////////////////////////////////////////////////
1029 /// Initialize the cling interpreter interface.
1030 
1031 TCling::TCling(const char *name, const char *title)
1032 : TInterpreter(name, title), fGlobalsListSerial(-1), fInterpreter(0),
1033  fMetaProcessor(0), fNormalizedCtxt(0), fPrevLoadedDynLibInfo(0),
1034  fClingCallbacks(0), fAutoLoadCallBack(0),
1035  fTransactionCount(0), fHeaderParsingOnDemand(true), fIsAutoParsingSuspended(kFALSE)
1036 {
1037  // rootcling also uses TCling for generating the dictionary ROOT files.
1038  bool fromRootCling = dlsym(RTLD_DEFAULT, "usedToIdentifyRootClingByDlSym");
1039 
1040  llvm::install_fatal_error_handler(&exceptionErrorHandler);
1041 
1042  fTemporaries = new std::vector<cling::Value>();
1043 
1044  std::vector<std::string> clingArgsStorage;
1045  clingArgsStorage.push_back("cling4root");
1046 
1047  std::string interpInclude;
1048  // rootcling sets its arguments through TROOT::GetExtraInterpreterArgs().
1049  if (!fromRootCling) {
1051 
1052  interpInclude = TROOT::GetEtcDir();
1053  clingArgsStorage.push_back("-I" + interpInclude);
1054 
1055  std::string pchFilename = interpInclude + "/allDict.cxx.pch";
1056  if (gSystem->Getenv("ROOT_PCH")) {
1057  pchFilename = gSystem->Getenv("ROOT_PCH");
1058  }
1059  clingArgsStorage.push_back("-include-pch");
1060  clingArgsStorage.push_back(pchFilename);
1061 
1062  // clingArgsStorage.push_back("-Xclang");
1063  // clingArgsStorage.push_back("-fmodules");
1064 
1065  std::string include;
1066  include = TROOT::GetIncludeDir();
1067  clingArgsStorage.push_back("-I" + include);
1068  clingArgsStorage.push_back("-Wno-undefined-inline");
1069  clingArgsStorage.push_back("-fsigned-char");
1070  }
1071 
1072  std::vector<const char*> interpArgs;
1073  for (std::vector<std::string>::const_iterator iArg = clingArgsStorage.begin(),
1074  eArg = clingArgsStorage.end(); iArg != eArg; ++iArg)
1075  interpArgs.push_back(iArg->c_str());
1076 
1077 #ifdef R__EXTERN_LLVMDIR
1078  TString llvmResourceDir = R__EXTERN_LLVMDIR;
1079 #else
1080  TString llvmResourceDir = TROOT::GetEtcDir() + "/cling";
1081 #endif
1082  // Add statically injected extra arguments, usually coming from rootcling.
1083  for (const char** extraArgs = TROOT::GetExtraInterpreterArgs();
1084  extraArgs && *extraArgs; ++extraArgs) {
1085  if (!strcmp(*extraArgs, "-resource-dir")) {
1086  // Take the next arg as the llvm resource directory.
1087  llvmResourceDir = *(++extraArgs);
1088  } else {
1089  interpArgs.push_back(*extraArgs);
1090  }
1091  }
1092 
1093  fInterpreter = new cling::Interpreter(interpArgs.size(),
1094  &(interpArgs[0]),
1095  llvmResourceDir);
1096 
1097  if (!fromRootCling) {
1098  fInterpreter->installLazyFunctionCreator(llvmLazyFunctionCreator);
1099 
1100  // Add include path to etc/cling. FIXME: This is a short term solution. The
1101  // llvm/clang header files shouldn't be there at all. We have to get rid of
1102  // that dependency and avoid copying the header files.
1103  // Use explicit TCling::AddIncludePath() to avoid vtable: we're in the c'tor!
1104  TCling::AddIncludePath((interpInclude + "/cling").c_str());
1105 
1106  // Add the current path to the include path
1107  // TCling::AddIncludePath(".");
1108 
1109  // Add the root include directory and etc/ to list searched by default.
1111  }
1112 
1113  // Don't check whether modules' files exist.
1114  fInterpreter->getCI()->getPreprocessorOpts().DisablePCHValidation = true;
1115 
1116  // Until we can disable autoloading during Sema::CorrectTypo() we have
1117  // to disable spell checking.
1118  fInterpreter->getCI()->getLangOpts().SpellChecking = false;
1119 
1120 
1121  // We need stream that doesn't close its file descriptor, thus we are not
1122  // using llvm::outs. Keeping file descriptor open we will be able to use
1123  // the results in pipes (Savannah #99234).
1124  static llvm::raw_fd_ostream fMPOuts (STDOUT_FILENO, /*ShouldClose*/false);
1125  fMetaProcessor = new cling::MetaProcessor(*fInterpreter, fMPOuts);
1126 
1127  // For the list to also include string, we have to include it now.
1128  // rootcling does parts already if needed, e.g. genreflex does not want using
1129  // namespace std.
1130  if (fromRootCling) {
1131  fInterpreter->declare("#include \"RtypesCore.h\"\n"
1132  "#include <string>\n"
1133  "using std::string;");
1134  } else {
1135  fInterpreter->declare("#include \"Rtypes.h\"\n"
1136  + gClassDefInterpMacro + "\n"
1137  + gInterpreterClassDef + "\n"
1138  + "#undef ClassImp\n"
1139  "#define ClassImp(X)\n"
1140  "#include <string>\n"
1141  "using namespace std;");
1142  }
1143 
1144  // We are now ready (enough is loaded) to init the list of opaque typedefs.
1147  TClassEdit::Init(fLookupHelper);
1148 
1149  // Initialize the cling interpreter interface.
1150  fMore = 0;
1151  fPrompt[0] = 0;
1152  fMapfile = 0;
1153 // fMapNamespaces = 0;
1154  fRootmapFiles = 0;
1156 
1157  fAllowLibLoad = !fromRootCling;
1158  // Disallow auto-parsing in rootcling
1159  fIsAutoParsingSuspended = fromRootCling;
1160  // Disable the autoloader until it is explicitly enabled.
1161  SetClassAutoloading(false);
1162 
1163  ResetAll();
1164 #ifndef R__WIN32
1165  //optind = 1; // make sure getopt() works in the main program
1166 #endif // R__WIN32
1167 
1168  // Attach cling callbacks
1169  std::unique_ptr<TClingCallbacks>
1170  clingCallbacks(new TClingCallbacks(fInterpreter));
1171  fClingCallbacks = clingCallbacks.get();
1173  fInterpreter->setCallbacks(std::move(clingCallbacks));
1174 
1175  if (!fromRootCling) {
1176  fInterpreter->enableDynamicLookup();
1177  }
1178 }
1179 
1180 
1181 ////////////////////////////////////////////////////////////////////////////////
1182 /// Destroy the interpreter interface.
1183 
1185 {
1186  delete fMapfile;
1187 // delete fMapNamespaces;
1188  delete fRootmapFiles;
1189  delete fMetaProcessor;
1190  delete fTemporaries;
1191  delete fNormalizedCtxt;
1192  delete fInterpreter;
1193  delete fLookupHelper;
1194  gCling = 0;
1195 #if defined(R__MUST_REVISIT)
1196 #if R__MUST_REVISIT(6,2)
1197  Warning("~TCling", "Interface not available yet.");
1198 #ifdef R__COMPLETE_MEM_TERMINATION
1199  // remove all cling objects
1200 #endif
1201 #endif
1202 #endif
1203  //--
1204 }
1205 
1206 ////////////////////////////////////////////////////////////////////////////////
1207 /// Initialize the interpreter, once TROOT::fInterpreter is set.
1208 
1210 {
1212 }
1213 
1214 ////////////////////////////////////////////////////////////////////////////////
1215 /// Wrapper around dladdr (and friends)
1216 
1217 static const char *FindLibraryName(void (*func)())
1218 {
1219 #if defined(__CYGWIN__) && defined(__GNUC__)
1220  return 0;
1221 #elif defined(G__WIN32)
1222  MEMORY_BASIC_INFORMATION mbi;
1223  if (!VirtualQuery (func, &mbi, sizeof (mbi)))
1224  {
1225  return 0;
1226  }
1227 
1228  HMODULE hMod = (HMODULE) mbi.AllocationBase;
1229  TTHREAD_TLS_ARRAY(char, MAX_PATH, moduleName);
1230 
1231  if (!GetModuleFileNameA (hMod, moduleName, sizeof (moduleName)))
1232  {
1233  return 0;
1234  }
1235  return moduleName;
1236 #else
1237  Dl_info info;
1238  if (dladdr((void*)func,&info)==0) {
1239  // Not in a known share library, let's give up
1240  return 0;
1241  } else {
1242  //fprintf(stdout,"Found address in %s\n",info.dli_fname);
1243  return info.dli_fname;
1244  }
1245 #endif
1246 
1247 }
1248 
1249 ////////////////////////////////////////////////////////////////////////////////
1250 /// Helper to initialize TVirtualStreamerInfo's factor early.
1251 /// Use static initialization to insure only one TStreamerInfo is created.
1253 {
1254  // Use lambda since SetFactory return void.
1255  auto setFactory = []() {
1257  return kTRUE;
1258  };
1259  static bool doneFactory = setFactory();
1260  return doneFactory; // avoid unused variable warning.
1261 }
1262 
1263 
1264 ////////////////////////////////////////////////////////////////////////////////
1265 /// Tries to load a PCM; returns true on success.
1266 
1267 bool TCling::LoadPCM(TString pcmFileName,
1268  const char** headers,
1269  void (*triggerFunc)()) const {
1270  // pcmFileName is an intentional copy; updated by FindFile() below.
1271 
1272  TString searchPath;
1273 
1274  if (triggerFunc) {
1275  const char *libraryName = FindLibraryName(triggerFunc);
1276  if (libraryName) {
1277  searchPath = llvm::sys::path::parent_path(libraryName);
1278 #ifdef R__WIN32
1279  searchPath += ";";
1280 #else
1281  searchPath += ":";
1282 #endif
1283  }
1284  }
1285  // Note: if we know where the library is, we probably shouldn't even
1286  // look in other places.
1287  searchPath.Append( gSystem->GetDynamicPath() );
1288 
1289  if (!gSystem->FindFile(searchPath, pcmFileName))
1290  return kFALSE;
1291 
1292  // Prevent the ROOT-PCMs hitting this during auto-load during
1293  // JITting - which will cause recursive compilation.
1294  // Avoid to call the plugin manager at all.
1296 
1297  if (gROOT->IsRootFile(pcmFileName)) {
1298  Int_t oldDebug = gDebug;
1299  if (gDebug > 5) {
1300  gDebug -= 5;
1301  ::Info("TCling::LoadPCM", "Loading ROOT PCM %s", pcmFileName.Data());
1302  } else {
1303  gDebug = 0;
1304  }
1305 
1306  TDirectory::TContext ctxt;
1307 
1308  TFile *pcmFile = new TFile(pcmFileName+"?filetype=pcm","READ");
1309 
1310  auto listOfKeys = pcmFile->GetListOfKeys();
1311 
1312  // This is an empty pcm
1313  if (listOfKeys && listOfKeys->GetSize() == 0) {
1314  delete pcmFile;
1315  gDebug = oldDebug;
1316  return kTRUE;
1317  }
1318 
1319  TObjArray *protoClasses;
1320  if (gDebug > 1)
1321  ::Info("TCling::LoadPCM","reading protoclasses for %s \n",pcmFileName.Data());
1322 
1323  pcmFile->GetObject("__ProtoClasses", protoClasses);
1324 
1325  if (protoClasses) {
1326  for (auto obj : *protoClasses) {
1327  TProtoClass * proto = (TProtoClass*)obj;
1328  TClassTable::Add(proto);
1329  }
1330  // Now that all TClass-es know how to set them up we can update
1331  // existing TClasses, which might cause the creation of e.g. TBaseClass
1332  // objects which in turn requires the creation of TClasses, that could
1333  // come from the PCH, but maybe later in the loop. Instead of resolving
1334  // a dependency graph the addition to the TClassTable above allows us
1335  // to create these dependent TClasses as needed below.
1336  for (auto proto : *protoClasses) {
1337  if (TClass* existingCl
1338  = (TClass*)gROOT->GetListOfClasses()->FindObject(proto->GetName())) {
1339  // We have an existing TClass object. It might be emulated
1340  // or interpreted; we now have more information available.
1341  // Make that available.
1342  if (existingCl->GetState() != TClass::kHasTClassInit) {
1343  DictFuncPtr_t dict = gClassTable->GetDict(proto->GetName());
1344  if (!dict) {
1345  ::Error("TCling::LoadPCM", "Inconsistent TClassTable for %s",
1346  proto->GetName());
1347  } else {
1348  // This will replace the existing TClass.
1349  TClass *ncl = (*dict)();
1350  if (ncl) ncl->PostLoadCheck();
1351 
1352  }
1353  }
1354  }
1355  }
1356 
1357  protoClasses->Clear(); // Ownership was transfered to TClassTable.
1358  delete protoClasses;
1359  }
1360 
1361  TObjArray *dataTypes;
1362  pcmFile->GetObject("__Typedefs", dataTypes);
1363  if (dataTypes) {
1364  for (auto typedf: *dataTypes)
1365  gROOT->GetListOfTypes()->Add(typedf);
1366  dataTypes->Clear(); // Ownership was transfered to TListOfTypes.
1367  delete dataTypes;
1368  }
1369 
1370  TObjArray *enums;
1371  pcmFile->GetObject("__Enums", enums);
1372  if (enums) {
1373  // Cache the pointers
1374  auto listOfGlobals = gROOT->GetListOfGlobals();
1375  auto listOfEnums = dynamic_cast<THashList*>(gROOT->GetListOfEnums());
1376  // Loop on enums and then on enum constants
1377  for (auto selEnum: *enums){
1378  const char* enumScope = selEnum->GetTitle();
1379  const char* enumName = selEnum->GetName();
1380  if (strcmp(enumScope,"") == 0){
1381  // This is a global enum and is added to the
1382  // list of enums and its constants to the list of globals
1383  if (!listOfEnums->THashList::FindObject(enumName)){
1384  ((TEnum*) selEnum)->SetClass(nullptr);
1385  listOfEnums->Add(selEnum);
1386  }
1387  for (auto enumConstant: *static_cast<TEnum*>(selEnum)->GetConstants()){
1388  if (!listOfGlobals->FindObject(enumConstant)){
1389  listOfGlobals->Add(enumConstant);
1390  }
1391  }
1392  }
1393  else {
1394  // This enum is in a namespace. A TClass entry is bootstrapped if
1395  // none exists yet and the enum is added to it
1396  TClass* nsTClassEntry = TClass::GetClass(enumScope);
1397  if (!nsTClassEntry){
1398  nsTClassEntry = new TClass(enumScope,0,TClass::kNamespaceForMeta, true);
1399  }
1400  auto listOfEnums = nsTClassEntry->fEnums.load();
1401  if (!listOfEnums) {
1402  if ( (kIsClass | kIsStruct | kIsUnion) & nsTClassEntry->Property() ) {
1403  // For this case, the list will be immutable once constructed
1404  // (i.e. in this case, by the end of this routine).
1405  listOfEnums = nsTClassEntry->fEnums = new TListOfEnums(nsTClassEntry);
1406  } else {
1407  //namespaces can have enums added to them
1408  listOfEnums = nsTClassEntry->fEnums = new TListOfEnumsWithLock(nsTClassEntry);
1409  }
1410  }
1411  if (listOfEnums && !listOfEnums->THashList::FindObject(enumName)){
1412  ((TEnum*) selEnum)->SetClass(nsTClassEntry);
1413  listOfEnums->Add(selEnum);
1414  }
1415  }
1416  }
1417  enums->Clear();
1418  delete enums;
1419  }
1420 
1421  delete pcmFile;
1422 
1423  gDebug = oldDebug;
1424  } else {
1425  if (gDebug > 5)
1426  ::Info("TCling::LoadPCM", "Loading clang PCM %s", pcmFileName.Data());
1427 
1428  }
1429  // Note: Declaring the relationship between the module (pcm) and the header
1430  // probably does not yet make sense since the pcm is 'only' a root file.
1431  // We also have to review if we still need to do this with the delay loading.
1432  // clang::CompilerInstance* CI = fInterpreter->getCI();
1433  // ROOT::TMetaUtils::declareModuleMap(CI, pcmFileName, headers);
1434  return kTRUE;
1435 }
1436 
1437 //______________________________________________________________________________
1438 
1439 namespace {
1440  using namespace clang;
1441 
1442  class ExtLexicalStorageAdder: public RecursiveASTVisitor<ExtLexicalStorageAdder>{
1443  // This class is to be considered an helper for autoparsing.
1444  // It visits the AST and marks all classes (in all of their redeclarations)
1445  // with the setHasExternalLexicalStorage method.
1446  public:
1447  bool VisitRecordDecl(clang::RecordDecl* rcd){
1448  if (gDebug > 2)
1449  Info("ExtLexicalStorageAdder",
1450  "Adding external lexical storage to class %s",
1451  rcd->getNameAsString().c_str());
1452  auto reDeclPtr = rcd->getMostRecentDecl();
1453  do {
1454  reDeclPtr->setHasExternalLexicalStorage();
1455  } while ((reDeclPtr = reDeclPtr->getPreviousDecl()));
1456 
1457  return false;
1458  }
1459  };
1460 
1461 
1462 }
1463 
1464 ////////////////////////////////////////////////////////////////////////////////
1465 /// Inject the module named "modulename" into cling; load all headers.
1466 /// headers is a 0-terminated array of header files to #include after
1467 /// loading the module. The module is searched for in all $LD_LIBRARY_PATH
1468 /// entries (or %PATH% on Windows).
1469 /// This function gets called by the static initialization of dictionary
1470 /// libraries.
1471 /// The payload code is injected "as is" in the interpreter.
1472 /// The value of 'triggerFunc' is used to find the shared library location.
1473 
1474 void TCling::RegisterModule(const char* modulename,
1475  const char** headers,
1476  const char** includePaths,
1477  const char* payloadCode,
1478  const char* fwdDeclsCode,
1479  void (*triggerFunc)(),
1480  const FwdDeclArgsToKeepCollection_t& fwdDeclsArgToSkip,
1481  const char** classesHeaders)
1482 {
1483  // rootcling also uses TCling for generating the dictionary ROOT files.
1484  static const bool fromRootCling = dlsym(RTLD_DEFAULT, "usedToIdentifyRootClingByDlSym");
1485  // We need the dictionary initialization but we don't want to inject the
1486  // declarations into the interpreter, except for those we really need for
1487  // I/O; see rootcling.cxx after the call to TCling__GetInterpreter().
1488  if (fromRootCling) return;
1489 
1490  // Treat Aclic Libs in a special way. Do not delay the parsing.
1491  bool hasHeaderParsingOnDemand = fHeaderParsingOnDemand;
1492  bool isACLiC = false;
1493  if (hasHeaderParsingOnDemand &&
1494  strstr(modulename, "_ACLiC_dict") != nullptr){
1495  if (gDebug>1)
1496  Info("TCling::RegisterModule",
1497  "Header parsing on demand is active but this is an Aclic library. Disabling it for this library.");
1498  hasHeaderParsingOnDemand = false;
1499  isACLiC = true;
1500  }
1501 
1502 
1503  // Make sure we relookup symbols that were search for before we loaded
1504  // their autoparse information. We could be more subtil and remove only
1505  // the failed one or only the one in this module, but for now this is
1506  // better than nothing.
1507  fLookedUpClasses.clear();
1508 
1509  // Make sure we do not set off autoloading or autoparsing during the
1510  // module registration!
1511  Int_t oldAutoloadValue = SetClassAutoloading(false);
1512 
1513  TString pcmFileName(ROOT::TMetaUtils::GetModuleFileName(modulename).c_str());
1514 
1515  for (const char** inclPath = includePaths; *inclPath; ++inclPath) {
1516  TCling::AddIncludePath(*inclPath);
1517  }
1518  cling::Transaction* T = 0;
1519  // Put the template decls and the number of arguments to skip in the TNormalizedCtxt
1520  for (auto& fwdDeclArgToSkipPair : fwdDeclsArgToSkip){
1521  const std::string& fwdDecl = fwdDeclArgToSkipPair.first;
1522  const int nArgsToSkip = fwdDeclArgToSkipPair.second;
1523  auto compRes = fInterpreter->declare(fwdDecl.c_str(), &T);
1524  assert(cling::Interpreter::kSuccess == compRes &&
1525  "A fwd declaration could not be compiled");
1526  if (compRes!=cling::Interpreter::kSuccess){
1527  Warning("TCling::RegisterModule",
1528  "Problems in declaring string '%s' were encountered.",
1529  fwdDecl.c_str()) ;
1530  continue;
1531  }
1532 
1533  // Drill through namespaces recursively until the template is found
1534  if(ClassTemplateDecl* TD = FindTemplateInNamespace(T->getFirstDecl().getSingleDecl())){
1535  fNormalizedCtxt->AddTemplAndNargsToKeep(TD->getCanonicalDecl(), nArgsToSkip);
1536  }
1537 
1538  }
1539 
1540  // FIXME: Remove #define __ROOTCLING__ once PCMs are there.
1541  // This is used to give Sema the same view on ACLiC'ed files (which
1542  // are then #included through the dictionary) as rootcling had.
1543  TString code = gNonInterpreterClassDef;
1544  code += payloadCode;
1545 
1546  // We need to open the dictionary shared library, to resolve symbols
1547  // requested by the JIT from it: as the library is currently being dlopen'ed,
1548  // its symbols are not yet reachable from the process.
1549  // Recursive dlopen seems to work just fine.
1550  const char* dyLibName = FindLibraryName(triggerFunc);
1551  if (dyLibName) {
1552  // We were able to determine the library name.
1553  void* dyLibHandle = dlopen(dyLibName, RTLD_LAZY | RTLD_GLOBAL);
1554  if (!dyLibHandle) {
1555 #ifdef R__WIN32
1556  char dyLibError[1000];
1557  FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(),
1558  MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), dyLibError,
1559  sizeof(dyLibError), NULL);
1560  {
1561 #else
1562  const char* dyLibError = dlerror();
1563  if (dyLibError) {
1564 #endif
1565  if (gDebug > 0) {
1566  ::Info("TCling::RegisterModule",
1567  "Cannot open shared library %s for dictionary %s:\n %s",
1568  dyLibName, modulename, dyLibError);
1569  }
1570  }
1571  dyLibName = 0;
1572  } else {
1573  fRegisterModuleDyLibs.push_back(dyLibHandle);
1574  }
1575  }
1576 
1577  if (hasHeaderParsingOnDemand && fwdDeclsCode){
1578  // We now parse the forward declarations. All the classes are then modified
1579  // in order for them to have an external lexical storage.
1580  std::string fwdDeclsCodeLessEnums;
1581  {
1582  // Search for enum forward decls and only declare them if no
1583  // declaration exists yet.
1584  std::string fwdDeclsLine;
1585  std::istringstream fwdDeclsCodeStr(fwdDeclsCode);
1586  std::vector<std::string> scope;
1587  while (std::getline(fwdDeclsCodeStr, fwdDeclsLine)) {
1588  if (fwdDeclsLine.find("namespace ") == 0
1589  || fwdDeclsLine.find("inline namespace ") == 0) {
1590  // skip leading "namespace ", trailing " {"
1591  scope.push_back(fwdDeclsLine.substr(10,
1592  fwdDeclsLine.length() - 10 - 2));
1593  } else if (fwdDeclsLine == "}") {
1594  scope.pop_back();
1595  } else if (fwdDeclsLine.find("enum __attribute__((annotate(\"") == 0) {
1596  clang::DeclContext* DC = 0;
1597  for (auto &&aScope: scope) {
1598  DC = cling::utils::Lookup::Namespace(&fInterpreter->getSema(), aScope.c_str(), DC);
1599  if (!DC) {
1600  // No decl context means we have to fwd declare the enum.
1601  break;
1602  }
1603  }
1604  if (scope.empty() || DC) {
1605  // We know the scope; let's look for the enum.
1606  size_t posEnumName = fwdDeclsLine.find("\"))) ", 32);
1607  R__ASSERT(posEnumName != std::string::npos && "Inconsistent enum fwd decl!");
1608  posEnumName += 5; // skip "\"))) "
1609  while (isspace(fwdDeclsLine[posEnumName]))
1610  ++posEnumName;
1611  size_t posEnumNameEnd = fwdDeclsLine.find(" : ", posEnumName);
1612  R__ASSERT(posEnumNameEnd != std::string::npos && "Inconsistent enum fwd decl (end)!");
1613  while (isspace(fwdDeclsLine[posEnumNameEnd]))
1614  --posEnumNameEnd;
1615  // posEnumNameEnd now points to the last character of the name.
1616 
1617  std::string enumName = fwdDeclsLine.substr(posEnumName,
1618  posEnumNameEnd - posEnumName + 1);
1619 
1620  if (clang::NamedDecl* enumDecl
1621  = cling::utils::Lookup::Named(&fInterpreter->getSema(),
1622  enumName.c_str(), DC)) {
1623  // We have an existing enum decl (forward or definition);
1624  // skip this.
1625  R__ASSERT(llvm::dyn_cast<clang::EnumDecl>(enumDecl) && "not an enum decl!");
1626  (void)enumDecl;
1627  continue;
1628  }
1629  }
1630  }
1631  fwdDeclsCodeLessEnums += fwdDeclsLine + "\n";
1632  }
1633  }
1634 
1635  if (fwdDeclsCodeLessEnums.size() != 0){ // Avoid the overhead if nothing is to be declared
1636  auto compRes = fInterpreter->declare(fwdDeclsCodeLessEnums, &T);
1637  assert(cling::Interpreter::kSuccess == compRes &&
1638  "The forward declarations could not be compiled");
1639  if (compRes!=cling::Interpreter::kSuccess){
1640  Warning("TCling::RegisterModule",
1641  "Problems in compiling forward declarations for module %s: '%s'",
1642  modulename, fwdDeclsCodeLessEnums.c_str()) ;
1643  }
1644  else if (T){
1645  // Loop over all decls in the transaction and go through them all
1646  // to mark them properly.
1647  // In order to do that, we first iterate over all the DelayedCallInfos
1648  // within the transaction. Then we loop over all Decls in the DeclGroupRef
1649  // contained in the DelayedCallInfos. For each decl, we traverse.
1650  ExtLexicalStorageAdder elsa;
1651  for (auto dciIt = T->decls_begin();dciIt!=T->decls_end();dciIt++){
1652  cling::Transaction::DelayCallInfo& dci = *dciIt;
1653  for(auto dit = dci.m_DGR.begin(); dit != dci.m_DGR.end(); ++dit) {
1654  clang::Decl* declPtr = *dit;
1655  elsa.TraverseDecl(declPtr);
1656  }
1657  }
1658  }
1659  }
1660 
1661  // Now we register all the headers necessary for the class
1662  // Typical format of the array:
1663  // {"A", "classes.h", "@",
1664  // "vector<A>", "vector", "@",
1665  // "myClass", payloadCode, "@",
1666  // nullptr};
1667 
1668  std::string temp;
1669  for (const char** classesHeader = classesHeaders; *classesHeader; ++classesHeader) {
1670  temp=*classesHeader;
1671 
1672  size_t theTemplateHash = 0;
1673  bool addTemplate = false;
1674  size_t posTemplate = temp.find('<');
1675  if (posTemplate != std::string::npos) {
1676  // Add an entry for the template itself.
1677  std::string templateName = temp.substr(0, posTemplate);
1678  theTemplateHash = fStringHashFunction(templateName);
1679  addTemplate = true;
1680  }
1681  size_t theHash = fStringHashFunction(temp);
1682  classesHeader++;
1683  for (const char** classesHeader_inner = classesHeader; 0!=strcmp(*classesHeader_inner,"@"); ++classesHeader_inner,++classesHeader){
1684  // This is done in order to distinguish headers from files and from the payloadCode
1685  if (payloadCode == *classesHeader_inner ){
1686  fPayloads.insert(theHash);
1687  if (addTemplate) fPayloads.insert(theTemplateHash);
1688  }
1689  if (gDebug > 2)
1690  Info("TCling::RegisterModule",
1691  "Adding a header for %s", temp.c_str());
1692  fClassesHeadersMap[theHash].push_back(*classesHeader_inner);
1693  if (addTemplate) {
1694  if (fClassesHeadersMap.find(theTemplateHash) == fClassesHeadersMap.end()) {
1695  fClassesHeadersMap[theTemplateHash].push_back(*classesHeader_inner);
1696  }
1697  addTemplate = false;
1698  }
1699  }
1700  }
1701  }
1702 
1703 
1704  if (strcmp(modulename,"libCore")!=0 && strcmp(modulename,"libRint")!=0
1705  && strcmp(modulename,"libThread")!=0 && strcmp(modulename,"libRIO")!=0
1706  && strcmp(modulename,"libcomplexDict")!=0 && strcmp(modulename,"libdequeDict")!=0
1707  && strcmp(modulename,"liblistDict")!=0 && strcmp(modulename,"libforward_listDict")!=0
1708  && strcmp(modulename,"libvectorDict")!=0
1709  && strcmp(modulename,"libmapDict")!=0 && strcmp(modulename,"libmultimap2Dict")!=0
1710  && strcmp(modulename,"libmap2Dict")!=0 && strcmp(modulename,"libmultimapDict")!=0
1711  && strcmp(modulename,"libsetDict")!=0 && strcmp(modulename,"libmultisetDict")!=0
1712  && strcmp(modulename,"libunordered_setDict")!=0 && strcmp(modulename,"libunordered_multisetDict")!=0
1713  && strcmp(modulename,"libunordered_mapDict")!=0 && strcmp(modulename,"libunordered_multimapDict")!=0
1714  && strcmp(modulename,"libvalarrayDict")!=0
1715  && strcmp(modulename,"G__GenVector32")!=0 && strcmp(modulename,"G__Smatrix32")!=0
1716 
1717  ) {
1718  // No pcm for now for libCore or libRint, the info is in the pch.
1719  if (!LoadPCM(pcmFileName, headers, triggerFunc)) {
1720  ::Error("TCling::RegisterModule", "cannot find dictionary module %s",
1721  ROOT::TMetaUtils::GetModuleFileName(modulename).c_str());
1722  }
1723  }
1724 
1725  bool oldValue = false;
1726  if (fClingCallbacks)
1727  oldValue = SetClassAutoloading(false);
1728 
1729  { // scope within which diagnostics are de-activated
1730  // For now we disable diagnostics because we saw them already at
1731  // dictionary generation time. That won't be an issue with the PCMs.
1732 
1733  clangDiagSuppr diagSuppr(fInterpreter->getSema().getDiagnostics());
1734 
1735 #if defined(R__MUST_REVISIT)
1736 #if R__MUST_REVISIT(6,2)
1737  Warning("TCling::RegisterModule","Diagnostics suppression should be gone by now.");
1738 #endif
1739 #endif
1740 
1741  if (!hasHeaderParsingOnDemand){
1742  const cling::Transaction* watermark = fInterpreter->getLastTransaction();
1743  cling::Interpreter::CompilationResult compRes = fInterpreter->parseForModule(code.Data());
1744  if (isACLiC) {
1745  // Register an unload point.
1746  fMetaProcessor->registerUnloadPoint(watermark, headers[0]);
1747  }
1748 
1749  assert(cling::Interpreter::kSuccess == compRes &&
1750  "Payload code of a dictionary could not be parsed correctly.");
1751  if (compRes!=cling::Interpreter::kSuccess) {
1752  Warning("TCling::RegisterModule",
1753  "Problems declaring payload for module %s.", modulename) ;
1754  }
1755  }
1756  }
1757 
1758  // Now that all the header have been registered/compiled, let's
1759  // make sure to 'reset' the TClass that have a class init in this module
1760  // but already had their type information available (using information/header
1761  // loaded from other modules or from class rules).
1762  if (!hasHeaderParsingOnDemand) {
1763  // This code is likely to be superseded by the similar code in LoadPCM,
1764  // and have been disabled, (inadvertently or awkwardly) by
1765  // commit 7903f09f3beea69e82ffba29f59fb2d656a4fd54 (Refactor the routines used for header parsing on demand)
1766  // whereas it seems that a more semantically correct conditional would have
1767  // been 'if this module does not have a rootpcm'.
1768  // Note: this need to be review when the clang pcm are being installed.
1769  // #if defined(R__MUST_REVISIT)
1770  while (!fClassesToUpdate.empty()) {
1771  TClass *oldcl = fClassesToUpdate.back().first;
1772  if (oldcl->GetState() != TClass::kHasTClassInit) {
1773  // if (gDebug > 2) Info("RegisterModule", "Forcing TClass init for %s", oldcl->GetName());
1774  DictFuncPtr_t dict = fClassesToUpdate.back().second;
1775  fClassesToUpdate.pop_back();
1776  // Calling func could manipulate the list so, let maintain the list
1777  // then call the dictionary function.
1778  TClass *ncl = dict();
1779  if (ncl) ncl->PostLoadCheck();
1780  } else {
1781  fClassesToUpdate.pop_back();
1782  }
1783  }
1784  }
1785 
1786  if (fClingCallbacks)
1787  SetClassAutoloading(oldValue);
1788 
1789  if (!hasHeaderParsingOnDemand) {
1790  // __ROOTCLING__ might be pulled in through PCH
1791  fInterpreter->declare("#ifdef __ROOTCLING__\n"
1792  "#undef __ROOTCLING__\n"
1793  + gInterpreterClassDef +
1794  "#endif");
1795  }
1796 
1797  if (dyLibName) {
1798  void* dyLibHandle = fRegisterModuleDyLibs.back();
1799  fRegisterModuleDyLibs.pop_back();
1800  dlclose(dyLibHandle);
1801  }
1802 
1803  SetClassAutoloading(oldAutoloadValue);
1804 }
1805 
1806 ////////////////////////////////////////////////////////////////////////////////
1807 /// Register classes that already existed prior to their dictionary loading
1808 /// and that already had a ClassInfo (and thus would not be refresh via
1809 /// UpdateClassInfo.
1810 
1812 {
1813  fClassesToUpdate.push_back(std::make_pair(oldcl,dict));
1814 }
1815 
1816 ////////////////////////////////////////////////////////////////////////////////
1817 /// If the dictionary is loaded, we can remove the class from the list
1818 /// (otherwise the class might be loaded twice).
1819 
1821 {
1822  typedef std::vector<std::pair<TClass*,DictFuncPtr_t> >::iterator iterator;
1823  iterator stop = fClassesToUpdate.end();
1824  for(iterator i = fClassesToUpdate.begin();
1825  i != stop;
1826  ++i)
1827  {
1828  if ( i->first == oldcl ) {
1829  fClassesToUpdate.erase(i);
1830  return;
1831  }
1832  }
1833 }
1834 
1835 ////////////////////////////////////////////////////////////////////////////////
1836 /// Let cling process a command line.
1837 ///
1838 /// If the command is executed and the error is 0, then the return value
1839 /// is the int value corresponding to the result of the executed command
1840 /// (float and double return values will be truncated).
1841 ///
1842 
1843 Long_t TCling::ProcessLine(const char* line, EErrorCode* error/*=0*/)
1844 {
1845  // Copy the passed line, it comes from a static buffer in TApplication
1846  // which can be reentered through the Cling evaluation routines,
1847  // which would overwrite the static buffer and we would forget what we
1848  // were doing.
1849  //
1850  TString sLine(line);
1851  if (strstr(line,fantomline)) {
1852  // End-Of-Line action
1853  // See the comment (copied from above):
1854  // It is a "fantom" method to synchronize user keyboard input
1855  // and ROOT prompt line (for WIN32)
1856  // and is implemented by
1857  if (gApplication) {
1858  if (gApplication->IsCmdThread()) {
1860  gGlobalMutex->Lock();
1861  if (!gInterpreterMutex)
1863  gGlobalMutex->UnLock();
1864  }
1866  gROOT->SetLineIsProcessing();
1867 
1869 
1870  gROOT->SetLineHasBeenProcessed();
1871  }
1872  }
1873  return 0;
1874  }
1875 
1877  gGlobalMutex->Lock();
1878  if (!gInterpreterMutex)
1880  gGlobalMutex->UnLock();
1881  }
1883  gROOT->SetLineIsProcessing();
1884 
1885  struct InterpreterFlagsRAII_t {
1886  cling::Interpreter* fInterpreter;
1887  bool fWasDynamicLookupEnabled;
1888 
1889  InterpreterFlagsRAII_t(cling::Interpreter* interp):
1890  fInterpreter(interp),
1891  fWasDynamicLookupEnabled(interp->isDynamicLookupEnabled())
1892  {
1893  fInterpreter->enableDynamicLookup(true);
1894  }
1895  ~InterpreterFlagsRAII_t() {
1896  fInterpreter->enableDynamicLookup(fWasDynamicLookupEnabled);
1897  }
1898  } interpreterFlagsRAII(fInterpreter);
1899 
1900  // A non-zero returned value means the given line was
1901  // not a complete statement.
1902  int indent = 0;
1903  // This will hold the resulting value of the evaluation the given line.
1905  cling::Interpreter::CompilationResult compRes = cling::Interpreter::kSuccess;
1906  if (!strncmp(sLine.Data(), ".L", 2) || !strncmp(sLine.Data(), ".x", 2) ||
1907  !strncmp(sLine.Data(), ".X", 2)) {
1908  // If there was a trailing "+", then CINT compiled the code above,
1909  // and we will need to strip the "+" before passing the line to cling.
1910  TString mod_line(sLine);
1911  TString aclicMode;
1912  TString arguments;
1913  TString io;
1914  TString fname = gSystem->SplitAclicMode(sLine.Data() + 3,
1915  aclicMode, arguments, io);
1916  if (aclicMode.Length()) {
1917  // Remove the leading '+'
1918  R__ASSERT(aclicMode[0]=='+' && "ACLiC mode must start with a +");
1919  aclicMode[0]='k'; // We always want to keep the .so around.
1920  if (aclicMode[1]=='+') {
1921  // We have a 2nd +
1922  aclicMode[1]='f'; // We want to force the recompilation.
1923  }
1924  if (!gSystem->CompileMacro(fname,aclicMode)) {
1925  // ACLiC failed.
1926  compRes = cling::Interpreter::kFailure;
1927  } else {
1928  if (strncmp(sLine.Data(), ".L", 2) != 0) {
1929  // if execution was requested.
1930 
1931  if (arguments.Length()==0) {
1932  arguments = "()";
1933  }
1934  // We need to remove the extension.
1935  Ssiz_t ext = fname.Last('.');
1936  if (ext != kNPOS) {
1937  fname.Remove(ext);
1938  }
1939  const char *function = gSystem->BaseName(fname);
1940  mod_line = function + arguments + io;
1941  cling::MetaProcessor::MaybeRedirectOutputRAII RAII(fMetaProcessor);
1942  indent = fMetaProcessor->process(mod_line, compRes, &result);
1943  }
1944  }
1945  } else {
1946  // not ACLiC
1947  bool unnamedMacro = false;
1948  {
1949  std::string line;
1950  std::ifstream in(fname);
1951  static const char whitespace[] = " \t\r\n";
1952  while (in) {
1953  std::getline(in, line);
1954  std::string::size_type posNonWS = line.find_first_not_of(whitespace);
1955  if (posNonWS == std::string::npos) continue;
1956  if (line[posNonWS] == '/' && line[posNonWS + 1] == '/')
1957  // Too bad, we only suppose C++ comments here.
1958  continue;
1959  unnamedMacro = (line[posNonWS] == '{');
1960  break;
1961  }
1962  }
1963 
1964  fCurExecutingMacros.push_back(fname);
1965  cling::MetaProcessor::MaybeRedirectOutputRAII RAII(fMetaProcessor);
1966  if (unnamedMacro) {
1967  compRes = fMetaProcessor->readInputFromFile(fname.Data(), &result,
1968  true /*ignoreOutmostBlock*/);
1969  } else {
1970  // No DynLookup for .x, .L of named macros.
1971  fInterpreter->enableDynamicLookup(false);
1972  indent = fMetaProcessor->process(mod_line, compRes, &result);
1973  }
1974  fCurExecutingMacros.pop_back();
1975  }
1976  } // .L / .X / .x
1977  else {
1978  if (0!=strncmp(sLine.Data(), ".autodict ",10) && sLine != ".autodict") {
1979  // explicitly ignore .autodict without having to support it
1980  // in cling.
1981  cling::MetaProcessor::MaybeRedirectOutputRAII RAII(fMetaProcessor);
1982 
1983  // Turn off autoparsing if this is an include directive
1984  bool isInclusionDirective = sLine.Contains("\n#include");
1985  if (isInclusionDirective) {
1986  SuspendAutoParsing autoParseRaii(this);
1987  indent = fMetaProcessor->process(sLine, compRes, &result);
1988  } else {
1989  indent = fMetaProcessor->process(sLine, compRes, &result);
1990  }
1991  }
1992  }
1993  if (result.isValid())
1994  RegisterTemporary(result);
1995  if (indent) {
1996  if (error)
1997  *error = kProcessing;
1998  return 0;
1999  }
2000  if (error) {
2001  switch (compRes) {
2002  case cling::Interpreter::kSuccess: *error = kNoError; break;
2003  case cling::Interpreter::kFailure: *error = kRecoverable; break;
2004  case cling::Interpreter::kMoreInputExpected: *error = kProcessing; break;
2005  }
2006  }
2007  if (compRes == cling::Interpreter::kSuccess
2008  && result.isValid()
2009  && !result.isVoid())
2010  {
2011  gROOT->SetLineHasBeenProcessed();
2012  return result.simplisticCastAs<long>();
2013  }
2014  gROOT->SetLineHasBeenProcessed();
2015  return 0;
2016 }
2017 
2018 ////////////////////////////////////////////////////////////////////////////////
2019 /// No-op; see TRint instead.
2020 
2022 {
2023 }
2024 
2025 ////////////////////////////////////////////////////////////////////////////////
2026 /// Add the given path to the list of directories in which the interpreter
2027 /// looks for include files. Only one path item can be specified at a
2028 /// time, i.e. "path1:path2" is not supported.
2029 
2030 void TCling::AddIncludePath(const char *path)
2031 {
2033  fInterpreter->AddIncludePath(path);
2034 }
2035 
2036 ////////////////////////////////////////////////////////////////////////////////
2037 /// Visit all members over members, recursing over base classes.
2038 
2039 void TCling::InspectMembers(TMemberInspector& insp, const void* obj,
2040  const TClass* cl, Bool_t isTransient)
2041 {
2045  }
2046 
2047  if (!cl || cl->GetCollectionProxy()) {
2048  // We do not need to investigate the content of the STL
2049  // collection, they are opaque to us (and details are
2050  // uninteresting).
2051  return;
2052  }
2053 
2054  static const TClassRef clRefString("std::string");
2055  if (clRefString == cl) {
2056  // We stream std::string without going through members..
2057  return;
2058  }
2059 
2060  const char* cobj = (const char*) obj; // for ptr arithmetics
2061 
2062  // Treat the case of std::complex in a special manner. We want to enforce
2063  // the layout of a stl implementation independent class, which is the
2064  // complex as implemented in ROOT5.
2065 
2066  // A simple lambda to simplify the code
2067  auto inspInspect = [&] (ptrdiff_t offset){
2068  insp.Inspect(const_cast<TClass*>(cl), insp.GetParent(), "_real", cobj, isTransient);
2069  insp.Inspect(const_cast<TClass*>(cl), insp.GetParent(), "_imag", cobj + offset, isTransient);
2070  };
2071 
2072  auto complexType = TClassEdit::GetComplexType(cl->GetName());
2073  switch(complexType) {
2075  {
2076  break;
2077  }
2079  {
2080  inspInspect(sizeof(float));
2081  return;
2082  }
2084  {
2085  inspInspect(sizeof(double));
2086  return;
2087  }
2089  {
2090  inspInspect(sizeof(int));
2091  return;
2092  }
2094  {
2095  inspInspect(sizeof(long));
2096  return;
2097  }
2098  }
2099 
2100  static clang::PrintingPolicy
2101  printPol(fInterpreter->getCI()->getLangOpts());
2102  if (printPol.Indentation) {
2103  // not yet initialized
2104  printPol.Indentation = 0;
2105  printPol.SuppressInitializers = true;
2106  }
2107 
2108  const char* clname = cl->GetName();
2109  // Printf("Inspecting class %s\n", clname);
2110 
2111  const clang::ASTContext& astContext = fInterpreter->getCI()->getASTContext();
2112  const clang::Decl *scopeDecl = 0;
2113  const clang::Type *recordType = 0;
2114 
2115  if (cl->GetClassInfo()) {
2116  TClingClassInfo * clingCI = (TClingClassInfo *)cl->GetClassInfo();
2117  scopeDecl = clingCI->GetDecl();
2118  recordType = clingCI->GetType();
2119  } else {
2120  const cling::LookupHelper& lh = fInterpreter->getLookupHelper();
2121  // Diags will complain about private classes:
2122  scopeDecl = lh.findScope(clname, cling::LookupHelper::NoDiagnostics,
2123  &recordType);
2124  }
2125  if (!scopeDecl) {
2126  Error("InspectMembers", "Cannot find Decl for class %s", clname);
2127  return;
2128  }
2129  const clang::CXXRecordDecl* recordDecl
2130  = llvm::dyn_cast<const clang::CXXRecordDecl>(scopeDecl);
2131  if (!recordDecl) {
2132  Error("InspectMembers", "Cannot find Decl for class %s is not a CXXRecordDecl.", clname);
2133  return;
2134  }
2135 
2136  {
2137  // Force possible deserializations first. We need to have no pending
2138  // Transaction when passing control flow to the inspector below (ROOT-7779).
2139  cling::Interpreter::PushTransactionRAII deserRAII(fInterpreter);
2140 
2141  astContext.getASTRecordLayout(recordDecl);
2142 
2143  for (clang::RecordDecl::field_iterator iField = recordDecl->field_begin(),
2144  eField = recordDecl->field_end(); iField != eField; ++iField) {}
2145  }
2146 
2147  const clang::ASTRecordLayout& recLayout
2148  = astContext.getASTRecordLayout(recordDecl);
2149 
2150  // TVirtualCollectionProxy *proxy = cl->GetCollectionProxy();
2151  // if (proxy && ( proxy->GetProperties() & TVirtualCollectionProxy::kIsEmulated ) ) {
2152  // Error("InspectMembers","The TClass for %s has an emulated proxy but we are looking at a compiled version of the collection!\n",
2153  // cl->GetName());
2154  // }
2155  if (cl->Size() != recLayout.getSize().getQuantity()) {
2156  Error("InspectMembers","TClass and cling disagree on the size of the class %s, respectively %d %lld\n",
2157  cl->GetName(),cl->Size(),(Long64_t)recLayout.getSize().getQuantity());
2158  }
2159 
2160  unsigned iNField = 0;
2161  // iterate over fields
2162  // FieldDecls are non-static, else it would be a VarDecl.
2163  for (clang::RecordDecl::field_iterator iField = recordDecl->field_begin(),
2164  eField = recordDecl->field_end(); iField != eField;
2165  ++iField, ++iNField) {
2166 
2167 
2168  clang::QualType memberQT = iField->getType();
2169  if (recordType) {
2170  // if (we_need_to_do_the_subst_because_the_class_is_a_template_instance_of_double32_t)
2171  memberQT = ROOT::TMetaUtils::ReSubstTemplateArg(memberQT, recordType);
2172  }
2173  memberQT = cling::utils::Transform::GetPartiallyDesugaredType(astContext, memberQT, fNormalizedCtxt->GetConfig(), false /* fully qualify */);
2174  if (memberQT.isNull()) {
2175  std::string memberName;
2176  llvm::raw_string_ostream stream(memberName);
2177  iField->getNameForDiagnostic(stream, printPol, true /*fqi*/);
2178  stream.flush();
2179  Error("InspectMembers",
2180  "Cannot retrieve QualType for member %s while inspecting class %s",
2181  memberName.c_str(), clname);
2182  continue; // skip member
2183  }
2184  const clang::Type* memType = memberQT.getTypePtr();
2185  if (!memType) {
2186  std::string memberName;
2187  llvm::raw_string_ostream stream(memberName);
2188  iField->getNameForDiagnostic(stream, printPol, true /*fqi*/);
2189  stream.flush();
2190  Error("InspectMembers",
2191  "Cannot retrieve Type for member %s while inspecting class %s",
2192  memberName.c_str(), clname);
2193  continue; // skip member
2194  }
2195 
2196  const clang::Type* memNonPtrType = memType;
2197  Bool_t ispointer = false;
2198  if (memNonPtrType->isPointerType()) {
2199  ispointer = true;
2200  clang::QualType ptrQT
2201  = memNonPtrType->getAs<clang::PointerType>()->getPointeeType();
2202  if (recordType) {
2203  // if (we_need_to_do_the_subst_because_the_class_is_a_template_instance_of_double32_t)
2204  ptrQT = ROOT::TMetaUtils::ReSubstTemplateArg(ptrQT, recordType);
2205  }
2206  ptrQT = cling::utils::Transform::GetPartiallyDesugaredType(astContext, ptrQT, fNormalizedCtxt->GetConfig(), false /* fully qualify */);
2207  if (ptrQT.isNull()) {
2208  std::string memberName;
2209  llvm::raw_string_ostream stream(memberName);
2210  iField->getNameForDiagnostic(stream, printPol, true /*fqi*/);
2211  stream.flush();
2212  Error("InspectMembers",
2213  "Cannot retrieve pointee Type for member %s while inspecting class %s",
2214  memberName.c_str(), clname);
2215  continue; // skip member
2216  }
2217  memNonPtrType = ptrQT.getTypePtr();
2218  }
2219 
2220  // assemble array size(s): "[12][4][]"
2221  llvm::SmallString<8> arraySize;
2222  const clang::ArrayType* arrType = memNonPtrType->getAsArrayTypeUnsafe();
2223  unsigned arrLevel = 0;
2224  bool haveErrorDueToArray = false;
2225  while (arrType) {
2226  ++arrLevel;
2227  arraySize += '[';
2228  const clang::ConstantArrayType* constArrType =
2229  clang::dyn_cast<clang::ConstantArrayType>(arrType);
2230  if (constArrType) {
2231  constArrType->getSize().toStringUnsigned(arraySize);
2232  }
2233  arraySize += ']';
2234  clang::QualType subArrQT = arrType->getElementType();
2235  if (subArrQT.isNull()) {
2236  std::string memberName;
2237  llvm::raw_string_ostream stream(memberName);
2238  iField->getNameForDiagnostic(stream, printPol, true /*fqi*/);
2239  stream.flush();
2240  Error("InspectMembers",
2241  "Cannot retrieve QualType for array level %d (i.e. element type of %s) for member %s while inspecting class %s",
2242  arrLevel, subArrQT.getAsString(printPol).c_str(),
2243  memberName.c_str(), clname);
2244  haveErrorDueToArray = true;
2245  break;
2246  }
2247  arrType = subArrQT.getTypePtr()->getAsArrayTypeUnsafe();
2248  }
2249  if (haveErrorDueToArray) {
2250  continue; // skip member
2251  }
2252 
2253  // construct member name
2254  std::string fieldName;
2255  if (memType->isPointerType()) {
2256  fieldName = "*";
2257  }
2258 
2259  // Check if this field has a custom ioname, if not, just use the one of the decl
2260  std::string ioname(iField->getName());
2262  fieldName += ioname;
2263  fieldName += arraySize;
2264 
2265  // get member offset
2266  // NOTE currently we do not support bitfield and do not support
2267  // member that are not aligned on 'bit' boundaries.
2268  clang::CharUnits offset(astContext.toCharUnitsFromBits(recLayout.getFieldOffset(iNField)));
2269  ptrdiff_t fieldOffset = offset.getQuantity();
2270 
2271  // R__insp.Inspect(R__cl, R__insp.GetParent(), "fBits[2]", fBits);
2272  // R__insp.Inspect(R__cl, R__insp.GetParent(), "fName", &fName);
2273  // R__insp.InspectMember(fName, "fName.");
2274  // R__insp.Inspect(R__cl, R__insp.GetParent(), "*fClass", &fClass);
2275 
2276  // If the class has a custom streamer and the type of the filed is a
2277  // private enum, struct or class, skip it.
2278  if (!insp.IsTreatingNonAccessibleTypes()){
2279  auto iFiledQtype = iField->getType();
2280  if (auto tagDecl = iFiledQtype->getAsTagDecl()){
2281  auto declAccess = tagDecl->getAccess();
2282  if (declAccess == AS_private || declAccess == AS_protected) {
2283  continue;
2284  }
2285  }
2286  }
2287 
2288  insp.Inspect(const_cast<TClass*>(cl), insp.GetParent(), fieldName.c_str(), cobj + fieldOffset, isTransient);
2289 
2290  if (!ispointer) {
2291  const clang::CXXRecordDecl* fieldRecDecl = memNonPtrType->getAsCXXRecordDecl();
2292  if (fieldRecDecl) {
2293  // nested objects get an extra call to InspectMember
2294  // R__insp.InspectMember("FileStat_t", (void*)&fFileStat, "fFileStat.", false);
2295  std::string sFieldRecName;
2296  if (!ROOT::TMetaUtils::ExtractAttrPropertyFromName(*fieldRecDecl,"iotype",sFieldRecName)){
2298  clang::QualType(memNonPtrType,0),
2299  *fInterpreter,
2300  *fNormalizedCtxt);
2301  }
2302 
2303  TDataMember* mbr = cl->GetDataMember(ioname.c_str());
2304  // if we can not find the member (which should not really happen),
2305  // let's consider it transient.
2306  Bool_t transient = isTransient || !mbr || !mbr->IsPersistent();
2307 
2308  insp.InspectMember(sFieldRecName.c_str(), cobj + fieldOffset,
2309  (fieldName + '.').c_str(), transient);
2310 
2311  }
2312  }
2313  } // loop over fields
2314 
2315  // inspect bases
2316  // TNamed::ShowMembers(R__insp);
2317  unsigned iNBase = 0;
2318  for (clang::CXXRecordDecl::base_class_const_iterator iBase
2319  = recordDecl->bases_begin(), eBase = recordDecl->bases_end();
2320  iBase != eBase; ++iBase, ++iNBase) {
2321  clang::QualType baseQT = iBase->getType();
2322  if (baseQT.isNull()) {
2323  Error("InspectMembers",
2324  "Cannot find QualType for base number %d while inspecting class %s",
2325  iNBase, clname);
2326  continue;
2327  }
2328  const clang::CXXRecordDecl* baseDecl
2329  = baseQT->getAsCXXRecordDecl();
2330  if (!baseDecl) {
2331  Error("InspectMembers",
2332  "Cannot find CXXRecordDecl for base number %d while inspecting class %s",
2333  iNBase, clname);
2334  continue;
2335  }
2336  TClass* baseCl=nullptr;
2337  std::string sBaseName;
2338  // Try with the DeclId
2339  std::vector<TClass*> foundClasses;
2340  TClass::GetClass(static_cast<DeclId_t>(baseDecl), foundClasses);
2341  if (foundClasses.size()==1){
2342  baseCl=foundClasses[0];
2343  } else {
2344  // Try with the normalised Name, as a fallback
2345  if (!baseCl){
2347  baseQT,
2348  *fInterpreter,
2349  *fNormalizedCtxt);
2350  baseCl = TClass::GetClass(sBaseName.c_str());
2351  }
2352  }
2353 
2354  if (!baseCl){
2355  std::string qualNameForDiag;
2356  ROOT::TMetaUtils::GetQualifiedName(qualNameForDiag, *baseDecl);
2357  Error("InspectMembers",
2358  "Cannot find TClass for base class %s", qualNameForDiag.c_str() );
2359  continue;
2360  }
2361 
2362  int64_t baseOffset;
2363  if (iBase->isVirtual()) {
2365  if (!isTransient) {
2366  Error("InspectMembers",
2367  "Base %s of class %s is virtual but no object provided",
2368  sBaseName.c_str(), clname);
2369  }
2371  } else {
2372  // We have an object to determine the vbase offset.
2374  TClingClassInfo* baseCi = (TClingClassInfo*)baseCl->GetClassInfo();
2375  if (ci && baseCi) {
2376  baseOffset = ci->GetBaseOffset(baseCi, const_cast<void*>(obj),
2377  true /*isDerivedObj*/);
2378  if (baseOffset == -1) {
2379  Error("InspectMembers",
2380  "Error calculating offset of virtual base %s of class %s",
2381  sBaseName.c_str(), clname);
2382  }
2383  } else {
2384  Error("InspectMembers",
2385  "Cannot calculate offset of virtual base %s of class %s",
2386  sBaseName.c_str(), clname);
2387  continue;
2388  }
2389  }
2390  } else {
2391  baseOffset = recLayout.getBaseClassOffset(baseDecl).getQuantity();
2392  }
2393  // TOFIX: baseCl can be null here!
2394  if (baseCl->IsLoaded()) {
2395  // For loaded class, CallShowMember will (especially for TObject)
2396  // call the virtual ShowMember rather than the class specific version
2397  // resulting in an infinite recursion.
2398  InspectMembers(insp, cobj + baseOffset, baseCl, isTransient);
2399  } else {
2400  baseCl->CallShowMembers(cobj + baseOffset,
2401  insp, isTransient);
2402  }
2403  } // loop over bases
2404 }
2405 
2406 ////////////////////////////////////////////////////////////////////////////////
2407 /// Reset the interpreter internal state in case a previous action was not correctly
2408 /// terminated.
2409 
2411 {
2412  // No-op there is not equivalent state (to be cleared) in Cling.
2413 }
2414 
2415 ////////////////////////////////////////////////////////////////////////////////
2416 /// Delete existing temporary values.
2417 
2419 {
2420  // No-op for cling due to cling::Value.
2421 }
2422 
2423 ////////////////////////////////////////////////////////////////////////////////
2424 /// Declare code to the interpreter, without any of the interpreter actions
2425 /// that could trigger a re-interpretation of the code. I.e. make cling
2426 /// behave like a compiler: no dynamic lookup, no input wrapping for
2427 /// subsequent execution, no automatic provision of declarations but just a
2428 /// plain #include.
2429 /// Returns true on success, false on failure.
2430 
2431 bool TCling::Declare(const char* code)
2432 {
2434 
2435  int oldload = SetClassAutoloading(0);
2436  SuspendAutoParsing autoParseRaii(this);
2437 
2438  bool oldDynLookup = fInterpreter->isDynamicLookupEnabled();
2439  fInterpreter->enableDynamicLookup(false);
2440  bool oldRawInput = fInterpreter->isRawInputEnabled();
2441  fInterpreter->enableRawInput(true);
2442 
2443  Bool_t ret = LoadText(code);
2444 
2445  fInterpreter->enableRawInput(oldRawInput);
2446  fInterpreter->enableDynamicLookup(oldDynLookup);
2447  SetClassAutoloading(oldload);
2448  return ret;
2449 }
2450 
2451 ////////////////////////////////////////////////////////////////////////////////
2452 /// Enable the automatic loading of shared libraries when a class
2453 /// is used that is stored in a not yet loaded library. Uses the
2454 /// information stored in the class/library map (typically
2455 /// $ROOTSYS/etc/system.rootmap).
2456 
2458 {
2459  if (fAllowLibLoad) {
2460  LoadLibraryMap();
2461  SetClassAutoloading(true);
2462  }
2463 }
2464 
2465 ////////////////////////////////////////////////////////////////////////////////
2466 /// It calls a "fantom" method to synchronize user keyboard input
2467 /// and ROOT prompt line.
2468 
2470 {
2471  ProcessLineSynch(fantomline);
2472 }
2473 
2474 ////////////////////////////////////////////////////////////////////////////////
2475 /// Return true if the file has already been loaded by cint.
2476 /// We will try in this order:
2477 /// actual filename
2478 /// filename as a path relative to
2479 /// the include path
2480 /// the shared library path
2481 
2483 {
2485 
2486  //FIXME: if we use llvm::sys::fs::make_absolute all this can go away. See
2487  // cling::DynamicLibraryManager.
2488 
2489  std::string file_name = filename;
2490  size_t at = std::string::npos;
2491  while ((at = file_name.find("/./")) != std::string::npos)
2492  file_name.replace(at, 3, "/");
2493 
2494  std::string filesStr = "";
2495  llvm::raw_string_ostream filesOS(filesStr);
2496  clang::SourceManager &SM = fInterpreter->getCI()->getSourceManager();
2497  cling::ClangInternalState::printIncludedFiles(filesOS, SM);
2498  filesOS.flush();
2499 
2500  llvm::SmallVector<llvm::StringRef, 100> files;
2501  llvm::StringRef(filesStr).split(files, "\n");
2502 
2503  std::set<std::string> fileMap;
2504  // Fill fileMap; return early on exact match.
2505  for (llvm::SmallVector<llvm::StringRef, 100>::const_iterator
2506  iF = files.begin(), iE = files.end(); iF != iE; ++iF) {
2507  if ((*iF) == file_name.c_str()) return kTRUE; // exact match
2508  fileMap.insert(*iF);
2509  }
2510 
2511  if (fileMap.empty()) return kFALSE;
2512 
2513  // Check MacroPath.
2514  TString sFilename(file_name.c_str());
2516  && fileMap.count(sFilename.Data())) {
2517  return kTRUE;
2518  }
2519 
2520  // Check IncludePath.
2521  TString incPath = gSystem->GetIncludePath(); // of the form -Idir1 -Idir2 -Idir3
2522  incPath.Append(":").Prepend(" "); // to match " -I" (note leading ' ')
2523  incPath.ReplaceAll(" -I", ":"); // of form :dir1 :dir2:dir3
2524  while (incPath.Index(" :") != -1) {
2525  incPath.ReplaceAll(" :", ":");
2526  }
2527  incPath.Prepend(".:");
2528  sFilename = file_name.c_str();
2529  if (gSystem->FindFile(incPath, sFilename, kReadPermission)
2530  && fileMap.count(sFilename.Data())) {
2531  return kTRUE;
2532  }
2533 
2534  // Check shared library.
2535  sFilename = file_name.c_str();
2536  const char *found = gSystem->FindDynamicLibrary(sFilename, kTRUE);
2537  cling::DynamicLibraryManager* dyLibManager
2538  = fInterpreter->getDynamicLibraryManager();
2539  if (found) {
2540  if (dyLibManager->isLibraryLoaded(found)) {
2541  return kTRUE;
2542  }
2543  }
2544  //FIXME: We must use the cling::Interpreter::lookupFileOrLibrary iface.
2545  const clang::DirectoryLookup *CurDir = 0;
2546  clang::Preprocessor &PP = fInterpreter->getCI()->getPreprocessor();
2547  clang::HeaderSearch &HS = PP.getHeaderSearchInfo();
2548  const clang::FileEntry *FE = HS.LookupFile(file_name.c_str(),
2549  clang::SourceLocation(),
2550  /*isAngled*/ false,
2551  /*FromDir*/ 0, CurDir,
2552  clang::ArrayRef<std::pair<const clang::FileEntry *,
2553  const clang::DirectoryEntry *>>(),
2554  /*SearchPath*/ 0,
2555  /*RelativePath*/ 0,
2556  /*SuggestedModule*/ 0,
2557  /*SkipCache*/ false,
2558  /*OpenFile*/ false,
2559  /*CacheFail*/ false);
2560  if (FE && FE->isValid()) {
2561  // check in the source manager if the file is actually loaded
2562  clang::SourceManager &SM = fInterpreter->getCI()->getSourceManager();
2563  // this works only with header (and source) files...
2564  clang::FileID FID = SM.translateFile(FE);
2565  if (!FID.isInvalid() && FID.getHashValue() == 0)
2566  return kFALSE;
2567  else {
2568  clang::SrcMgr::SLocEntry SLocE = SM.getSLocEntry(FID);
2569  if (SLocE.isFile() && SLocE.getFile().getContentCache()->getRawBuffer() == 0)
2570  return kFALSE;
2571  if (!FID.isInvalid())
2572  return kTRUE;
2573  }
2574  // ...then check shared library again, but with full path now
2575  sFilename = FE->getName();
2576  if (gSystem->FindDynamicLibrary(sFilename, kTRUE)
2577  && fileMap.count(sFilename.Data())) {
2578  return kTRUE;
2579  }
2580  }
2581  return kFALSE;
2582 }
2583 
2584 ////////////////////////////////////////////////////////////////////////////////
2585 
2587 {
2588 #if defined(R__WIN32) || defined(__CYGWIN__)
2589  HMODULE hModules[1024];
2590  void *hProcess;
2591  unsigned long cbModules;
2592  unsigned int i;
2593  hProcess = (void *)::GetCurrentProcess();
2594  ::EnumProcessModules(hProcess, hModules, sizeof(hModules), &cbModules);
2595  // start at 1 to skip the executable itself
2596  for (i = 1; i < (cbModules / sizeof(void *)); i++) {
2597  static const int bufsize = 260;
2598  wchar_t winname[bufsize];
2599  char posixname[bufsize];
2600  ::GetModuleFileNameExW(hProcess, hModules[i], winname, bufsize);
2601 #if defined(__CYGWIN__)
2602  cygwin_conv_path(CCP_WIN_W_TO_POSIX, winname, posixname, bufsize);
2603 #else
2604  std::wstring wpath = winname;
2605  std::replace(wpath.begin(), wpath.end(), '\\', '/');
2606  string path(wpath.begin(), wpath.end());
2607  strncpy(posixname, path.c_str(), bufsize);
2608 #endif
2609  if (!fSharedLibs.Contains(posixname)) {
2610  RegisterLoadedSharedLibrary(posixname);
2611  }
2612  }
2613 #elif defined(R__MACOSX)
2614  // fPrevLoadedDynLibInfo stores the *next* image index to look at
2615  uint32_t imageIndex = (uint32_t) (size_t) fPrevLoadedDynLibInfo;
2616  const char* imageName = 0;
2617  while ((imageName = _dyld_get_image_name(imageIndex))) {
2618  // Skip binary
2619  if (imageIndex > 0)
2620  RegisterLoadedSharedLibrary(imageName);
2621  ++imageIndex;
2622  }
2623  fPrevLoadedDynLibInfo = (void*)(size_t)imageIndex;
2624 #elif defined(R__LINUX)
2625  struct PointerNo4_t {
2626  void* fSkip[3];
2627  void* fPtr;
2628  };
2629  struct LinkMap_t {
2630  void* fAddr;
2631  const char* fName;
2632  void* fLd;
2633  LinkMap_t* fNext;
2634  LinkMap_t* fPrev;
2635  };
2636  if (!fPrevLoadedDynLibInfo || fPrevLoadedDynLibInfo == (void*)(size_t)-1) {
2637  PointerNo4_t* procLinkMap = (PointerNo4_t*)dlopen(0, RTLD_LAZY | RTLD_GLOBAL);
2638  // 4th pointer of 4th pointer is the linkmap.
2639  // See http://syprog.blogspot.fr/2011/12/listing-loaded-shared-objects-in-linux.html
2640  LinkMap_t* linkMap = (LinkMap_t*) ((PointerNo4_t*)procLinkMap->fPtr)->fPtr;
2641  RegisterLoadedSharedLibrary(linkMap->fName);
2642  fPrevLoadedDynLibInfo = linkMap;
2643  }
2644 
2645  LinkMap_t* iDyLib = (LinkMap_t*)fPrevLoadedDynLibInfo;
2646  while (iDyLib->fNext) {
2647  iDyLib = iDyLib->fNext;
2648  RegisterLoadedSharedLibrary(iDyLib->fName);
2649  }
2650  fPrevLoadedDynLibInfo = iDyLib;
2651 #else
2652  Error("TCling::UpdateListOfLoadedSharedLibraries",
2653  "Platform not supported!");
2654 #endif
2655 }
2656 
2657 ////////////////////////////////////////////////////////////////////////////////
2658 /// Register a new shared library name with the interpreter; add it to
2659 /// fSharedLibs.
2660 
2662 {
2663  // Ignore NULL filenames, aka "the process".
2664  if (!filename) return;
2665 
2666  // Tell the interpreter that this library is available; all libraries can be
2667  // used to resolve symbols.
2668  cling::DynamicLibraryManager* DLM = fInterpreter->getDynamicLibraryManager();
2669  if (!DLM->isLibraryLoaded(filename)) {
2670  DLM->loadLibrary(filename, true /*permanent*/);
2671  }
2672 
2673 #if defined(R__MACOSX)
2674  // Check that this is not a system library
2675  if (!strncmp(filename, "/usr/lib/system/", 16)
2676  || !strncmp(filename, "/usr/lib/libc++", 15)
2677  || !strncmp(filename, "/System/Library/Frameworks/", 27)
2678  || !strncmp(filename, "/System/Library/PrivateFrameworks/", 34)
2679  || !strncmp(filename, "/System/Library/CoreServices/", 29)
2680  || !strcmp(filename, "cl_kernels") // yepp, no directory
2681  || strstr(filename, "/usr/lib/libSystem")
2682  || strstr(filename, "/usr/lib/libstdc++")
2683  || strstr(filename, "/usr/lib/libicucore")
2684  || strstr(filename, "/usr/lib/libbsm")
2685  || strstr(filename, "/usr/lib/libobjc")
2686  || strstr(filename, "/usr/lib/libresolv")
2687  || strstr(filename, "/usr/lib/libauto")
2688  || strstr(filename, "/usr/lib/libcups")
2689  || strstr(filename, "/usr/lib/libDiagnosticMessagesClient")
2690  || strstr(filename, "/usr/lib/liblangid")
2691  || strstr(filename, "/usr/lib/libCRFSuite")
2692  || strstr(filename, "/usr/lib/libpam")
2693  || strstr(filename, "/usr/lib/libOpenScriptingUtil")
2694  || strstr(filename, "/usr/lib/libextension"))
2695  return;
2696 #elif defined(__CYGWIN__)
2697  // Check that this is not a system library
2698  static const int bufsize = 260;
2699  char posixwindir[bufsize];
2700  char *windir = getenv("WINDIR");
2701  if (windir)
2702  cygwin_conv_path(CCP_WIN_A_TO_POSIX, windir, posixwindir, bufsize);
2703  else
2704  snprintf(posixwindir, sizeof(posixwindir), "/Windows/");
2705  if (strstr(filename, posixwindir) ||
2706  strstr(filename, "/usr/bin/cyg"))
2707  return;
2708 #elif defined(R__WIN32)
2709  if (strstr(filename, "/Windows/"))
2710  return;
2711 #elif defined (R__LINUX)
2712  if (strstr(filename, "/ld-linux")
2713  || strstr(filename, "linux-gnu/")
2714  || strstr(filename, "/libstdc++.")
2715  || strstr(filename, "/libgcc")
2716  || strstr(filename, "/libc.")
2717  || strstr(filename, "/libdl.")
2718  || strstr(filename, "/libm."))
2719  return;
2720 #endif
2721  // Update string of available libraries.
2722  if (!fSharedLibs.IsNull()) {
2723  fSharedLibs.Append(" ");
2724  }
2725  fSharedLibs.Append(filename);
2726 }
2727 
2728 ////////////////////////////////////////////////////////////////////////////////
2729 /// Load a library file in cling's memory.
2730 /// if 'system' is true, the library is never unloaded.
2731 /// Return 0 on success, -1 on failure.
2732 
2733 Int_t TCling::Load(const char* filename, Bool_t system)
2734 {
2735  if (!fAllowLibLoad) {
2736  Error("Load","Trying to load library (%s) from rootcling.",filename);
2737  return -1;
2738  }
2739 
2740  // Used to return 0 on success, 1 on duplicate, -1 on failure, -2 on "fatal".
2742  cling::DynamicLibraryManager* DLM = fInterpreter->getDynamicLibraryManager();
2743  std::string canonLib = DLM->lookupLibrary(filename);
2744  cling::DynamicLibraryManager::LoadLibResult res
2745  = cling::DynamicLibraryManager::kLoadLibNotFound;
2746  if (!canonLib.empty()) {
2747  if (system)
2748  res = DLM->loadLibrary(filename, system);
2749  else {
2750  // For the non system libs, we'd like to be able to unload them.
2751  // FIXME: Here we lose the information about kLoadLibAlreadyLoaded case.
2752  cling::Interpreter::CompilationResult compRes;
2753  cling::MetaProcessor::MaybeRedirectOutputRAII RAII(fMetaProcessor);
2754  fMetaProcessor->process(Form(".L %s", canonLib.c_str()), compRes, /*cling::Value*/0);
2755  if (compRes == cling::Interpreter::kSuccess)
2756  res = cling::DynamicLibraryManager::kLoadLibSuccess;
2757  }
2758  }
2759 
2760  if (res == cling::DynamicLibraryManager::kLoadLibSuccess) {
2762  }
2763  switch (res) {
2764  case cling::DynamicLibraryManager::kLoadLibSuccess: return 0;
2765  case cling::DynamicLibraryManager::kLoadLibAlreadyLoaded: return 1;
2766  default: break;
2767  };
2768  return -1;
2769 }
2770 
2771 ////////////////////////////////////////////////////////////////////////////////
2772 /// Load a macro file in cling's memory.
2773 
2774 void TCling::LoadMacro(const char* filename, EErrorCode* error)
2775 {
2776  ProcessLine(Form(".L %s", filename), error);
2777 }
2778 
2779 ////////////////////////////////////////////////////////////////////////////////
2780 /// Let cling process a command line asynch.
2781 
2783 {
2784  return ProcessLine(line, error);
2785 }
2786 
2787 ////////////////////////////////////////////////////////////////////////////////
2788 /// Let cling process a command line synchronously, i.e we are waiting
2789 /// it will be finished.
2790 
2792 {
2794  if (gApplication) {
2795  if (gApplication->IsCmdThread()) {
2796  return ProcessLine(line, error);
2797  }
2798  return 0;
2799  }
2800  return ProcessLine(line, error);
2801 }
2802 
2803 ////////////////////////////////////////////////////////////////////////////////
2804 /// Directly execute an executable statement (e.g. "func()", "3+5", etc.
2805 /// however not declarations, like "Int_t x;").
2806 
2807 Long_t TCling::Calc(const char* line, EErrorCode* error)
2808 {
2809 #ifdef R__WIN32
2810  // Test on ApplicationImp not being 0 is needed because only at end of
2811  // TApplication ctor the IsLineProcessing flag is set to 0, so before
2812  // we can not use it.
2814  while (gROOT->IsLineProcessing() && !gApplication) {
2815  Warning("Calc", "waiting for cling thread to free");
2816  gSystem->Sleep(500);
2817  }
2818  gROOT->SetLineIsProcessing();
2819  }
2820 #endif // R__WIN32
2822  if (error) {
2823  *error = TInterpreter::kNoError;
2824  }
2825  cling::Value valRef;
2826  cling::Interpreter::CompilationResult cr = fInterpreter->evaluate(line, valRef);
2827  if (cr != cling::Interpreter::kSuccess) {
2828  // Failure in compilation.
2829  if (error) {
2830  // Note: Yes these codes are weird.
2831  *error = TInterpreter::kRecoverable;
2832  }
2833  return 0L;
2834  }
2835  if (!valRef.isValid()) {
2836  // Failure at runtime.
2837  if (error) {
2838  // Note: Yes these codes are weird.
2839  *error = TInterpreter::kDangerous;
2840  }
2841  return 0L;
2842  }
2843 
2844  if (valRef.isVoid()) {
2845  return 0;
2846  }
2847 
2848  RegisterTemporary(valRef);
2849 #ifdef R__WIN32
2851  gROOT->SetLineHasBeenProcessed();
2852  }
2853 #endif // R__WIN32
2854  return valRef.simplisticCastAs<long>();
2855 }
2856 
2857 ////////////////////////////////////////////////////////////////////////////////
2858 /// Set a getline function to call when input is needed.
2859 
2860 void TCling::SetGetline(const char * (*getlineFunc)(const char* prompt),
2861  void (*histaddFunc)(const char* line))
2862 {
2863  // If cling offers a replacement for G__pause(), it would need to
2864  // also offer a way to customize at least the history recording.
2865 
2866 #if defined(R__MUST_REVISIT)
2867 #if R__MUST_REVISIT(6,2)
2868  Warning("SetGetline","Cling should support the equivalent of SetGetlineFunc(getlineFunc, histaddFunc)");
2869 #endif
2870 #endif
2871 }
2872 
2873 ////////////////////////////////////////////////////////////////////////////////
2874 /// Helper function to increase the internal Cling count of transactions
2875 /// that change the AST.
2876 
2877 Bool_t TCling::HandleNewTransaction(const cling::Transaction &T)
2878 {
2880 
2881  if ((std::distance(T.decls_begin(), T.decls_end()) != 1)
2882  || T.deserialized_decls_begin() != T.deserialized_decls_end()
2883  || T.macros_begin() != T.macros_end()
2884  || ((!T.getFirstDecl().isNull()) && ((*T.getFirstDecl().begin()) != T.getWrapperFD()))) {
2886  return true;
2887  }
2888  return false;
2889 }
2890 
2891 ////////////////////////////////////////////////////////////////////////////////
2892 /// Delete object from cling symbol table so it can not be used anymore.
2893 /// cling objects are always on the heap.
2894 
2896 {
2898  // Note that fgSetOfSpecials is supposed to be updated by TClingCallbacks::tryFindROOTSpecialInternal
2899  // (but isn't at the moment).
2900  if (obj->IsOnHeap() && fgSetOfSpecials && !((std::set<TObject*>*)fgSetOfSpecials)->empty()) {
2901  std::set<TObject*>::iterator iSpecial = ((std::set<TObject*>*)fgSetOfSpecials)->find(obj);
2902  if (iSpecial != ((std::set<TObject*>*)fgSetOfSpecials)->end()) {
2903  DeleteGlobal(obj);
2904  ((std::set<TObject*>*)fgSetOfSpecials)->erase(iSpecial);
2905  }
2906  }
2907 }
2908 
2909 ////////////////////////////////////////////////////////////////////////////////
2910 /// Pressing Ctrl+C should forward here. In the case where we have had
2911 /// continuation requested we must reset it.
2912 
2914 {
2915  fMetaProcessor->cancelContinuation();
2916  // Reset the Cling state to the state saved by the last call to
2917  // TCling::SaveContext().
2918 #if defined(R__MUST_REVISIT)
2919 #if R__MUST_REVISIT(6,2)
2921  Warning("Reset","Cling should support the equivalent of scratch_upto(&fDictPos)");
2922 #endif
2923 #endif
2924 }
2925 
2926 ////////////////////////////////////////////////////////////////////////////////
2927 /// Reset the Cling state to its initial state.
2928 
2930 {
2931 #if defined(R__MUST_REVISIT)
2932 #if R__MUST_REVISIT(6,2)
2934  Warning("ResetAll","Cling should support the equivalent of complete reset (unload everything but the startup decls.");
2935 #endif
2936 #endif
2937 }
2938 
2939 ////////////////////////////////////////////////////////////////////////////////
2940 /// Reset in Cling the list of global variables to the state saved by the last
2941 /// call to TCling::SaveGlobalsContext().
2942 ///
2943 /// Note: Right now, all we do is run the global destructors.
2944 
2946 {
2948  // TODO:
2949  // Here we should iterate over the transactions (N-3) and revert.
2950  // N-3 because the first three internal to cling.
2951 
2952  fInterpreter->runAndRemoveStaticDestructors();
2953 }
2954 
2955 ////////////////////////////////////////////////////////////////////////////////
2956 /// Reset the Cling 'user' global objects/variables state to the state saved by the last
2957 /// call to TCling::SaveGlobalsContext().
2958 
2959 void TCling::ResetGlobalVar(void* obj)
2960 {
2961 #if defined(R__MUST_REVISIT)
2962 #if R__MUST_REVISIT(6,2)
2964  Warning("ResetGlobalVar","Cling should support the equivalent of resetglobalvar(obj)");
2965 #endif
2966 #endif
2967 }
2968 
2969 ////////////////////////////////////////////////////////////////////////////////
2970 /// Rewind Cling dictionary to the point where it was before executing
2971 /// the current macro. This function is typically called after SEGV or
2972 /// ctlr-C after doing a longjmp back to the prompt.
2973 
2975 {
2976 #if defined(R__MUST_REVISIT)
2977 #if R__MUST_REVISIT(6,2)
2979  Warning("RewindDictionary","Cling should provide a way to revert transaction similar to rewinddictionary()");
2980 #endif
2981 #endif
2982 }
2983 
2984 ////////////////////////////////////////////////////////////////////////////////
2985 /// Delete obj from Cling symbol table so it cannot be accessed anymore.
2986 /// Returns 1 in case of success and 0 in case object was not in table.
2987 
2989 {
2990 #if defined(R__MUST_REVISIT)
2991 #if R__MUST_REVISIT(6,2)
2993  Warning("DeleteGlobal","Cling should provide the equivalent of deleteglobal(obj), see also DeleteVariable.");
2994 #endif
2995 #endif
2996  return 0;
2997 }
2998 
2999 ////////////////////////////////////////////////////////////////////////////////
3000 /// Undeclare obj called name.
3001 /// Returns 1 in case of success, 0 for failure.
3002 
3004 {
3005 #if defined(R__MUST_REVISIT)
3006 #if R__MUST_REVISIT(6,2)
3007  Warning("DeleteVariable","should do more that just reseting the value to zero");
3008 #endif
3009 #endif
3010 
3012  llvm::StringRef srName(name);
3013  const char* unscopedName = name;
3014  llvm::StringRef::size_type posScope = srName.rfind("::");
3015  const clang::DeclContext* declCtx = 0;
3016  if (posScope != llvm::StringRef::npos) {
3017  const cling::LookupHelper& lh = fInterpreter->getLookupHelper();
3018  const clang::Decl* scopeDecl
3019  = lh.findScope(srName.substr(0, posScope),
3020  cling::LookupHelper::WithDiagnostics);
3021  if (!scopeDecl) {
3022  Error("DeleteVariable", "Cannot find enclosing scope for variable %s",
3023  name);
3024  return 0;
3025  }
3026  declCtx = llvm::dyn_cast<clang::DeclContext>(scopeDecl);
3027  if (!declCtx) {
3028  Error("DeleteVariable",
3029  "Enclosing scope for variable %s is not a declaration context",
3030  name);
3031  return 0;
3032  }
3033  unscopedName += posScope + 2;
3034  }
3035  clang::NamedDecl* nVarDecl
3036  = cling::utils::Lookup::Named(&fInterpreter->getSema(), unscopedName, declCtx);
3037  if (!nVarDecl) {
3038  Error("DeleteVariable", "Unknown variable %s", name);
3039  return 0;
3040  }
3041  clang::VarDecl* varDecl = llvm::dyn_cast<clang::VarDecl>(nVarDecl);
3042  if (!varDecl) {
3043  Error("DeleteVariable", "Entity %s is not a variable", name);
3044  return 0;
3045  }
3046 
3047  clang::QualType qType = varDecl->getType();
3048  const clang::Type* type = qType->getUnqualifiedDesugaredType();
3049  // Cannot set a reference's address to nullptr; the JIT can place it
3050  // into read-only memory (ROOT-7100).
3051  if (type->isPointerType()) {
3052  int** ppInt = (int**)fInterpreter->getAddressOfGlobal(GlobalDecl(varDecl));
3053  // set pointer to invalid.
3054  if (ppInt) *ppInt = 0;
3055  }
3056  return 1;
3057 }
3058 
3059 ////////////////////////////////////////////////////////////////////////////////
3060 /// Save the current Cling state.
3061 
3063 {
3064 #if defined(R__MUST_REVISIT)
3065 #if R__MUST_REVISIT(6,2)
3067  Warning("SaveContext","Cling should provide a way to record a state watermark similar to store_dictposition(&fDictPos)");
3068 #endif
3069 #endif
3070 }
3071 
3072 ////////////////////////////////////////////////////////////////////////////////
3073 /// Save the current Cling state of global objects.
3074 
3076 {
3077 #if defined(R__MUST_REVISIT)
3078 #if R__MUST_REVISIT(6,2)
3080  Warning("SaveGlobalsContext","Cling should provide a way to record a watermark for the list of global variable similar to store_dictposition(&fDictPosGlobals)");
3081 #endif
3082 #endif
3083 }
3084 
3085 ////////////////////////////////////////////////////////////////////////////////
3086 /// No op: see TClingCallbacks (used to update the list of globals)
3087 
3089 {
3090 }
3091 
3092 ////////////////////////////////////////////////////////////////////////////////
3093 /// No op: see TClingCallbacks (used to update the list of global functions)
3094 
3096 {
3097 }
3098 
3099 ////////////////////////////////////////////////////////////////////////////////
3100 /// No op: see TClingCallbacks (used to update the list of types)
3101 
3103 {
3104 }
3105 
3106 ////////////////////////////////////////////////////////////////////////////////
3107 /// Set pointer to the TClingClassInfo in TClass.
3108 /// If 'reload' is true, (attempt to) generate a new ClassInfo even if we
3109 /// already have one.
3110 
3112 {
3114  if (cl->fClassInfo && !reload) {
3115  return;
3116  }
3117  //Remove the decl_id from the DeclIdToTClass map
3118  TClingClassInfo* TClinginfo = (TClingClassInfo*) cl->fClassInfo;
3119  if (TClinginfo) {
3120  TClass::RemoveClassDeclId(TClinginfo->GetDeclId());
3121  }
3122  delete TClinginfo;
3123  cl->fClassInfo = 0;
3124  std::string name(cl->GetName());
3125  TClingClassInfo* info = new TClingClassInfo(fInterpreter, name.c_str());
3126  if (!info->IsValid()) {
3127  if (cl->fState != TClass::kHasTClassInit) {
3128  if (cl->fStreamerInfo->GetEntries() != 0) {
3129  cl->fState = TClass::kEmulated;
3130  } else {
3132  }
3133  }
3134  delete info;
3135  return;
3136  }
3137  cl->fClassInfo = (ClassInfo_t*)info; // Note: We are transferring ownership here.
3138  // In case a class contains an external enum, the enum will be seen as a
3139  // class. We must detect this special case and make the class a Zombie.
3140  // Here we assume that a class has at least one method.
3141  // We can NOT call TClass::Property from here, because this method
3142  // assumes that the TClass is well formed to do a lot of information
3143  // caching. The method SetClassInfo (i.e. here) is usually called during
3144  // the building phase of the TClass, hence it is NOT well formed yet.
3145  Bool_t zombieCandidate = kFALSE;
3146  if (
3147  info->IsValid() &&
3148  !(info->Property() & (kIsClass | kIsStruct | kIsNamespace))
3149  ) {
3150  zombieCandidate = kTRUE;
3151  }
3152  if (!info->IsLoaded()) {
3153  if (info->Property() & (kIsNamespace)) {
3154  // Namespaces can have info but no corresponding CINT dictionary
3155  // because they are auto-created if one of their contained
3156  // classes has a dictionary.
3157  zombieCandidate = kTRUE;
3158  }
3159  // this happens when no dictionary is available
3160  delete info;
3161  cl->fClassInfo = 0;
3162  }
3163  if (zombieCandidate && !cl->GetCollectionType()) {
3164  cl->MakeZombie();
3165  }
3166  // If we reach here, the info was valid (See early returns).
3167  if (cl->fState != TClass::kHasTClassInit) {
3168  if (cl->fClassInfo) {
3171  } else {
3172 // if (TClassEdit::IsSTLCont(cl->GetName()) {
3173 // There will be an emulated collection proxy, is that the same?
3174 // cl->fState = TClass::kEmulated;
3175 // } else {
3176  if (cl->fStreamerInfo->GetEntries() != 0) {
3177  cl->fState = TClass::kEmulated;
3178  } else {
3180  }
3181 // }
3182  }
3183  }
3184  if (cl->fClassInfo) {
3185  TClass::AddClassToDeclIdMap(((TClingClassInfo*)cl->fClassInfo)->GetDeclId(), cl);
3186  }
3187 }
3188 
3189 ////////////////////////////////////////////////////////////////////////////////
3190 /// Checks if an entity with the specified name is defined in Cling.
3191 /// Returns kFALSE if the entity is not defined.
3192 /// By default, structs, namespaces, classes, enums and unions are looked for.
3193 /// If the flag isClassOrNamespaceOnly is true, classes, structs and
3194 /// namespaces only are considered. I.e. if the name is an enum or a union,
3195 /// the returned value is false.
3196 ///
3197 /// In the case where the class is not loaded and belongs to a namespace
3198 /// or is nested, looking for the full class name is outputting a lots of
3199 /// (expected) error messages. Currently the only way to avoid this is to
3200 /// specifically check that each level of nesting is already loaded.
3201 /// In case of templates the idea is that everything between the outer
3202 /// '<' and '>' has to be skipped, e.g.: aap<pippo<noot>::klaas>::a_class
3203 
3204 Bool_t TCling::CheckClassInfo(const char* name, Bool_t autoload, Bool_t isClassOrNamespaceOnly /* = kFALSE*/ )
3205 {
3207  static const char *anonEnum = "anonymous enum ";
3208  static const int cmplen = strlen(anonEnum);
3209 
3210  if (0 == strncmp(name,anonEnum,cmplen)) {
3211  return kFALSE;
3212  }
3213 
3214  // Avoid the double search below in case the name is a fundamental type
3215  // or typedef to a fundamental type.
3216  THashTable *typeTable = dynamic_cast<THashTable*>( gROOT->GetListOfTypes() );
3217  TDataType *fundType = (TDataType *)typeTable->THashTable::FindObject( name );
3218 
3219  if (fundType && fundType->GetType() < TVirtualStreamerInfo::kObject
3220  && fundType->GetType() > 0) {
3221  // Fundamental type, no a class.
3222  return kFALSE;
3223  }
3224 
3225  // Migrated from within TClass::GetClass
3226  // If we want to know if a class or a namespace with this name exists in the
3227  // interpreter and this is an enum in the type system, before or after loading
3228  // according to the autoload function argument, return false.
3229  if (isClassOrNamespaceOnly &&
3230  TEnum::GetEnum(name, autoload ? TEnum::kAutoload : TEnum::kNone)) return false;
3231 
3232  const char *classname = name;
3233 
3234  int storeAutoload = SetClassAutoloading(autoload);
3235 
3236  // First we want to check whether the decl exist, but _without_
3237  // generating any template instantiation. However, the lookup
3238  // still will create a forward declaration of the class template instance
3239  // if it exist. In this case, the return value of findScope will still
3240  // be zero but the type will be initialized.
3241  // Note in the corresponding code in ROOT 5, CINT was not instantiating
3242  // this forward declaration.
3243  const cling::LookupHelper& lh = fInterpreter->getLookupHelper();
3244  const clang::Type *type = 0;
3245  const clang::Decl *decl
3246  = lh.findScope(classname,
3247  gDebug > 5 ? cling::LookupHelper::WithDiagnostics
3248  : cling::LookupHelper::NoDiagnostics,
3249  &type, /* intantiateTemplate= */ false );
3250  if (!decl) {
3251  std::string buf = TClassEdit::InsertStd(classname);
3252  decl = lh.findScope(buf,
3253  gDebug > 5 ? cling::LookupHelper::WithDiagnostics
3254  : cling::LookupHelper::NoDiagnostics,
3255  &type,false);
3256  }
3257 
3258  if (type) {
3259  // If decl==0 and the type is valid, then we have a forward declaration.
3260  if (!decl) {
3261  // If we have a forward declaration for a class template instantiation,
3262  // we want to ignore it if it was produced/induced by the call to
3263  // findScope, however we can not distinguish those from the
3264  // instantiation induce by 'soft' use (and thus also induce by the
3265  // same underlying code paths)
3266  // ['soft' use = use not requiring a complete definition]
3267  // So to reduce the amount of disruption to the existing code we
3268  // would just ignore those for STL collection, for which we really
3269  // need to have the compiled collection proxy (and thus the TClass
3270  // bootstrap).
3271  clang::ClassTemplateSpecializationDecl *tmpltDecl =
3272  llvm::dyn_cast_or_null<clang::ClassTemplateSpecializationDecl>
3273  (type->getAsCXXRecordDecl());
3274  if (tmpltDecl && !tmpltDecl->getPointOfInstantiation().isValid()) {
3275  // Since the point of instantiation is invalid, we 'guess' that
3276  // the 'instantiation' of the forwarded type appended in
3277  // findscope.
3278  if (ROOT::TMetaUtils::IsSTLCont(*tmpltDecl)) {
3279  // For STL Collection we return false.
3280  SetClassAutoloading(storeAutoload);
3281  return kFALSE;
3282  }
3283  }
3284  }
3285  TClingClassInfo tci(fInterpreter, *type);
3286  if (!tci.IsValid()) {
3287  SetClassAutoloading(storeAutoload);
3288  return kFALSE;
3289  }
3290  auto propertiesMask = isClassOrNamespaceOnly ? kIsClass | kIsStruct | kIsNamespace :
3292 
3293  if (tci.Property() & propertiesMask) {
3294  // We are now sure that the entry is not in fact an autoload entry.
3295  SetClassAutoloading(storeAutoload);
3296  return kTRUE;
3297  }
3298  }
3299 
3300  SetClassAutoloading(storeAutoload);
3301  return (decl);
3302 
3303  // Setting up iterator part of TClingTypedefInfo is too slow.
3304  // Copy the lookup code instead:
3305  /*
3306  TClingTypedefInfo t(fInterpreter, name);
3307  if (t.IsValid() && !(t.Property() & kIsFundamental)) {
3308  delete[] classname;
3309  SetClassAutoloading(storeAutoload);
3310  return kTRUE;
3311  }
3312  */
3313 
3314 // const clang::Decl *decl = lh.findScope(name);
3315 // if (!decl) {
3316 // std::string buf = TClassEdit::InsertStd(name);
3317 // decl = lh.findScope(buf);
3318 // }
3319 
3320 // SetClassAutoloading(storeAutoload);
3321 // return (decl);
3322 }
3323 
3324 ////////////////////////////////////////////////////////////////////////////////
3325 /// Return true if there is a class template by the given name ...
3326 
3328 {
3329  const cling::LookupHelper& lh = fInterpreter->getLookupHelper();
3330  const clang::Decl *decl
3331  = lh.findClassTemplate(name,
3332  gDebug > 5 ? cling::LookupHelper::WithDiagnostics
3333  : cling::LookupHelper::NoDiagnostics);
3334  if (!decl) {
3335  std::string strname = "std::";
3336  strname += name;
3337  decl = lh.findClassTemplate(strname,
3338  gDebug > 5 ? cling::LookupHelper::WithDiagnostics
3339  : cling::LookupHelper::NoDiagnostics);
3340  }
3341  return 0 != decl;
3342 }
3343 
3344 ////////////////////////////////////////////////////////////////////////////////
3345 /// Create list of pointers to base class(es) for TClass cl.
3346 
3348 {
3350  if (cl->fBase) {
3351  return;
3352  }
3354  if (!tci) return;
3356  // This is put here since TClingBaseClassInfo can trigger a
3357  // TClass::ResetCaches, which deallocates cl->fBase
3358  cl->fBase = new TList;
3359  while (t.Next()) {
3360  // if name cannot be obtained no use to put in list
3361  if (t.IsValid() && t.Name()) {
3363  cl->fBase->Add(new TBaseClass((BaseClassInfo_t *)a, cl));
3364  }
3365  }
3366 }
3367 
3368 ////////////////////////////////////////////////////////////////////////////////
3369 /// Create list of pointers to enums for TClass cl.
3370 
3371 void TCling::LoadEnums(TListOfEnums& enumList) const
3372 {
3374 
3375  const Decl * D;
3376  TClass* cl = enumList.GetClass();
3377  if (cl) {
3378  D = ((TClingClassInfo*)cl->GetClassInfo())->GetDecl();
3379  }
3380  else {
3381  D = fInterpreter->getCI()->getASTContext().getTranslationUnitDecl();
3382  }
3383  // Iterate on the decl of the class and get the enums.
3384  if (const clang::DeclContext* DC = dyn_cast<clang::DeclContext>(D)) {
3385  cling::Interpreter::PushTransactionRAII deserRAII(fInterpreter);
3386  // Collect all contexts of the namespace.
3387  llvm::SmallVector< DeclContext *, 4> allDeclContexts;
3388  const_cast< clang::DeclContext *>(DC)->collectAllContexts(allDeclContexts);
3389  for (llvm::SmallVector<DeclContext*, 4>::iterator declIter = allDeclContexts.begin(), declEnd = allDeclContexts.end();
3390  declIter != declEnd; ++declIter) {
3391  // Iterate on all decls for each context.
3392  for (clang::DeclContext::decl_iterator DI = (*declIter)->decls_begin(),
3393  DE = (*declIter)->decls_end(); DI != DE; ++DI) {
3394  if (const clang::EnumDecl* ED = dyn_cast<clang::EnumDecl>(*DI)) {
3395  // Get name of the enum type.
3396  std::string buf;
3397  PrintingPolicy Policy(ED->getASTContext().getPrintingPolicy());
3398  llvm::raw_string_ostream stream(buf);
3399  ED->getNameForDiagnostic(stream, Policy, /*Qualified=*/false);
3400  stream.flush();
3401  // If the enum is unnamed we do not add it to the list of enums i.e unusable.
3402  if (!buf.empty()) {
3403  const char* name = buf.c_str();
3404  // Add the enum to the list of loaded enums.
3405  enumList.Get(ED, name);
3406  }
3407  }
3408  }
3409  }
3410  }
3411 }
3412 
3413 ////////////////////////////////////////////////////////////////////////////////
3414 /// Create list of pointers to function templates for TClass cl.
3415 
3417 {
3419 
3420  const Decl * D;
3421  TListOfFunctionTemplates* funcTempList;
3422  if (cl) {
3423  D = ((TClingClassInfo*)cl->GetClassInfo())->GetDecl();
3424  funcTempList = (TListOfFunctionTemplates*)cl->GetListOfFunctionTemplates(false);
3425  }
3426  else {
3427  D = fInterpreter->getCI()->getASTContext().getTranslationUnitDecl();
3428  funcTempList = (TListOfFunctionTemplates*)gROOT->GetListOfFunctionTemplates();
3429  }
3430  // Iterate on the decl of the class and get the enums.
3431  if (const clang::DeclContext* DC = dyn_cast<clang::DeclContext>(D)) {
3432  cling::Interpreter::PushTransactionRAII deserRAII(fInterpreter);
3433  // Collect all contexts of the namespace.
3434  llvm::SmallVector< DeclContext *, 4> allDeclContexts;
3435  const_cast< clang::DeclContext *>(DC)->collectAllContexts(allDeclContexts);
3436  for (llvm::SmallVector<DeclContext*, 4>::iterator declIter = allDeclContexts.begin(),
3437  declEnd = allDeclContexts.end(); declIter != declEnd; ++declIter) {
3438  // Iterate on all decls for each context.
3439  for (clang::DeclContext::decl_iterator DI = (*declIter)->decls_begin(),
3440  DE = (*declIter)->decls_end(); DI != DE; ++DI) {
3441  if (const clang::FunctionTemplateDecl* FTD = dyn_cast<clang::FunctionTemplateDecl>(*DI)) {
3442  funcTempList->Get(FTD);
3443  }
3444  }
3445  }
3446  }
3447 }
3448 ////////////////////////////////////////////////////////////////////////////////
3449 /// Create list of pointers to data members for TClass cl.
3450 /// This is now a nop. The creation and updating is handled in
3451 /// TListOfDataMembers.
3452 
3454 {
3455 }
3456 
3457 ////////////////////////////////////////////////////////////////////////////////
3458 /// Create list of pointers to methods for TClass cl.
3459 /// This is now a nop. The creation and updating is handled in
3460 /// TListOfFunctions.
3461 
3463 {
3464 }
3465 
3466 ////////////////////////////////////////////////////////////////////////////////
3467 /// Update the list of pointers to method for TClass cl
3468 /// This is now a nop. The creation and updating is handled in
3469 /// TListOfFunctions.
3470 
3472 {
3473 }
3474 
3475 ////////////////////////////////////////////////////////////////////////////////
3476 /// Update the list of pointers to data members for TClass cl
3477 /// This is now a nop. The creation and updating is handled in
3478 /// TListOfDataMembers.
3479 
3481 {
3482 }
3483 
3484 ////////////////////////////////////////////////////////////////////////////////
3485 /// Create list of pointers to method arguments for TMethod m.
3486 
3488 {
3490  if (m->fMethodArgs) {
3491  return;
3492  }
3493  m->fMethodArgs = new TList;
3495  while (t.Next()) {
3496  if (t.IsValid()) {
3498  m->fMethodArgs->Add(new TMethodArg((MethodArgInfo_t*)a, m));
3499  }
3500  }
3501 }
3502 
3503 
3504 ////////////////////////////////////////////////////////////////////////////////
3505 /// Generate a TClass for the given class.
3506 /// Since the caller has already check the ClassInfo, let it give use the
3507 /// result (via the value of emulation) rather than recalculate it.
3508 
3509 TClass *TCling::GenerateTClass(const char *classname, Bool_t emulation, Bool_t silent /* = kFALSE */)
3510 {
3511 // For now the following line would lead to the (unwanted) instantiation
3512 // of class template. This could/would need to be resurrected only if
3513 // we re-introduce so sort of automatic instantiation. However this would
3514 // have to include carefull look at the template parameter to avoid
3515 // creating instance we can not really use (if the parameter are only forward
3516 // declaration or do not have all the necessary interfaces).
3517 
3518  // TClingClassInfo tci(fInterpreter, classname);
3519  // if (1 || !tci.IsValid()) {
3520 
3521  Version_t version = 1;
3522  if (TClassEdit::IsSTLCont(classname)) {
3523  version = TClass::GetClass("TVirtualStreamerInfo")->GetClassVersion();
3524  }
3525  TClass *cl = new TClass(classname, version, silent);
3526  if (emulation) {
3528  } else {
3529  // Set the class version if the class is versioned.
3530  // Note that we cannot just call CLASS::Class_Version() as we might not have
3531  // an execution engine (when invoked from rootcling).
3532 
3533  // Do not call cl->GetClassVersion(), it has side effects!
3534  Version_t oldvers = cl->fClassVersion;
3535  if (oldvers == version && cl->GetClassInfo()) {
3536  // We have a version and it might need an update.
3537  Version_t newvers = oldvers;
3539  if (llvm::isa<clang::NamespaceDecl>(cli->GetDecl())) {
3540  // Namespaces don't have class versions.
3541  return cl;
3542  }
3543  TClingMethodInfo mi = cli->GetMethod("Class_Version", "", 0 /*poffset*/,
3546  if (!mi.IsValid()) {
3547  if (cl->TestBit(TClass::kIsTObject)) {
3548  Error("GenerateTClass",
3549  "Cannot find %s::Class_Version()! Class version might be wrong.",
3550  cl->GetName());
3551  }
3552  return cl;
3553  }
3554  newvers = ROOT::TMetaUtils::GetClassVersion(llvm::dyn_cast<clang::RecordDecl>(cli->GetDecl()),
3555  *fInterpreter);
3556  if (newvers == -1) {
3557  // Didn't manage to determine the class version from the AST.
3558  // Use runtime instead.
3559  if ((mi.Property() & kIsStatic)
3560  && !fInterpreter->isInSyntaxOnlyMode()) {
3561  // This better be a static function.
3563  callfunc.SetFunc(&mi);
3564  newvers = callfunc.ExecInt(0);
3565  } else {
3566  Error("GenerateTClass",
3567  "Cannot invoke %s::Class_Version()! Class version might be wrong.",
3568  cl->GetName());
3569  }
3570  }
3571  if (newvers != oldvers) {
3572  cl->fClassVersion = newvers;
3573  cl->fStreamerInfo->Expand(newvers + 2 + 10);
3574  }
3575  }
3576  }
3577 
3578  return cl;
3579 
3580 // } else {
3581 // return GenerateTClass(&tci,silent);
3582 // }
3583 }
3584 
3585 #if 0
3586 ////////////////////////////////////////////////////////////////////////////////
3587 
3588 static void GenerateTClass_GatherInnerIncludes(cling::Interpreter *interp, TString &includes,TClingClassInfo *info)
3589 {
3590  includes += info->FileName();
3591 
3592  const clang::ClassTemplateSpecializationDecl *templateCl
3593  = llvm::dyn_cast<clang::ClassTemplateSpecializationDecl>(info->GetDecl());
3594  if (templateCl) {
3595  for(unsigned int i=0; i < templateCl->getTemplateArgs().size(); ++i) {
3596  const clang::TemplateArgument &arg( templateCl->getTemplateArgs().get(i) );
3597  if (arg.getKind() == clang::TemplateArgument::Type) {
3598  const clang::Type *uType = ROOT::TMetaUtils::GetUnderlyingType( arg.getAsType() );
3599 
3600  if (!uType->isFundamentalType() && !uType->isEnumeralType()) {
3601  // We really need a header file.
3602  const clang::CXXRecordDecl *argdecl = uType->getAsCXXRecordDecl();
3603  if (argdecl) {
3604  includes += ";";
3605  TClingClassInfo subinfo(interp,*(argdecl->getASTContext().getRecordType(argdecl).getTypePtr()));
3606  GenerateTClass_GatherInnerIncludes(interp, includes, &subinfo);
3607  } else {
3608  std::string Result;
3609  llvm::raw_string_ostream OS(Result);
3610  arg.print(argdecl->getASTContext().getPrintingPolicy(),OS);
3611  Warning("TCling::GenerateTClass","Missing header file for %s",OS.str().c_str());
3612  }
3613  }
3614  }
3615  }
3616  }
3617 }
3618 #endif
3619 
3620 ////////////////////////////////////////////////////////////////////////////////
3621 /// Generate a TClass for the given class.
3622 
3623 TClass *TCling::GenerateTClass(ClassInfo_t *classinfo, Bool_t silent /* = kFALSE */)
3624 {
3625  TClingClassInfo *info = (TClingClassInfo*)classinfo;
3626  if (!info || !info->IsValid()) {
3627  Fatal("GenerateTClass","Requires a valid ClassInfo object");
3628  return 0;
3629  }
3630  // We are in the case where we have AST nodes for this class.
3631  TClass *cl = 0;
3632  std::string classname;
3633  info->FullName(classname,*fNormalizedCtxt); // Could we use Name()?
3634  if (TClassEdit::IsSTLCont(classname.c_str())) {
3635 #if 0
3636  Info("GenerateTClass","Will (try to) generate the compiled TClass for %s.",classname.c_str());
3637  // We need to build up the list of required headers, by
3638  // looking at each template arguments.
3639  TString includes;
3640  GenerateTClass_GatherInnerIncludes(fInterpreter,includes,info);
3641 
3642  if (0 == GenerateDictionary(classname.c_str(),includes)) {
3643  // 0 means success.
3644  cl = TClass::LoadClass(classnam.c_str(), silent);
3645  if (cl == 0) {
3646  Error("GenerateTClass","Even though the dictionary generation for %s seemed successful we can't find the TClass bootstrap!",classname.c_str());
3647  }
3648  }
3649 #endif
3650  if (cl == 0) {
3651  int version = TClass::GetClass("TVirtualStreamerInfo")->GetClassVersion();
3652  cl = new TClass(classinfo, version, 0, 0, -1, -1, silent);
3654  }
3655  } else {
3656  // For regular class, just create a TClass on the fly ...
3657  // Not quite useful yet, but that what CINT used to do anyway.
3658  cl = new TClass(classinfo, 1, 0, 0, -1, -1, silent);
3659  }
3660  // Add the new TClass to the map of declid and TClass*.
3661  if (cl) {
3663  }
3664  return cl;
3665 }
3666 
3667 ////////////////////////////////////////////////////////////////////////////////
3668 /// Generate the dictionary for the C++ classes listed in the first
3669 /// argument (in a semi-colon separated list).
3670 /// 'includes' contains a semi-colon separated list of file to
3671 /// #include in the dictionary.
3672 /// For example:
3673 /// ~~~ {.cpp}
3674 /// gInterpreter->GenerateDictionary("vector<vector<float> >;list<vector<float> >","list;vector");
3675 /// ~~~
3676 /// or
3677 /// ~~~ {.cpp}
3678 /// gInterpreter->GenerateDictionary("myclass","myclass.h;myhelper.h");
3679 /// ~~~
3680 
3681 Int_t TCling::GenerateDictionary(const char* classes, const char* includes /* = 0 */, const char* /* options = 0 */)
3682 {
3683  if (classes == 0 || classes[0] == 0) {
3684  return 0;
3685  }
3686  // Split the input list
3687  std::vector<std::string> listClasses;
3688  for (
3689  const char* current = classes, *prev = classes;
3690  *current != 0;
3691  ++current
3692  ) {
3693  if (*current == ';') {
3694  listClasses.push_back(std::string(prev, current - prev));
3695  prev = current + 1;
3696  }
3697  else if (*(current + 1) == 0) {
3698  listClasses.push_back(std::string(prev, current + 1 - prev));
3699  prev = current + 1;
3700  }
3701  }
3702  std::vector<std::string> listIncludes;
3703  for (
3704  const char* current = includes, *prev = includes;
3705  *current != 0;
3706  ++current
3707  ) {
3708  if (*current == ';') {
3709  listIncludes.push_back(std::string(prev, current - prev));
3710  prev = current + 1;
3711  }
3712  else if (*(current + 1) == 0) {
3713  listIncludes.push_back(std::string(prev, current + 1 - prev));
3714  prev = current + 1;
3715  }
3716  }
3717  // Generate the temporary dictionary file
3718  return TCling_GenerateDictionary(listClasses, listIncludes,
3719  std::vector<std::string>(), std::vector<std::string>());
3720 }
3721 
3722 ////////////////////////////////////////////////////////////////////////////////
3723 /// Return pointer to cling Decl of global/static variable that is located
3724 /// at the address given by addr.
3725 
3726 TInterpreter::DeclId_t TCling::GetDataMember(ClassInfo_t *opaque_cl, const char *name) const
3727 {
3729  DeclId_t d;
3730  TClingClassInfo *cl = (TClingClassInfo*)opaque_cl;
3731 
3732  if (cl) {
3733  d = cl->GetDataMember(name);
3734  // We check if the decl of the data member has an annotation which indicates
3735  // an ioname.
3736  // In case this is true, if the name requested is not the ioname, we
3737  // return 0, as if the member did not exist. In some sense we override
3738  // the information in the TClassInfo instance, isolating the typesystem in
3739  // TClass from the one in the AST.
3740  if (const ValueDecl* decl = (const ValueDecl*) d){
3741  std::string ioName;
3742  bool hasIoName = ROOT::TMetaUtils::ExtractAttrPropertyFromName(*decl,"ioname",ioName);
3743  if (hasIoName && ioName != name) return 0;
3744  }
3745  }
3746  else {
3748  d = gcl.GetDataMember(name);
3749  }
3750  return d;
3751 }
3752 
3753 ////////////////////////////////////////////////////////////////////////////////
3754 /// Return pointer to cling Decl of global/static variable that is located
3755 /// at the address given by addr.
3756 
3758 {
3760 
3761  const clang::Decl* possibleEnum = 0;
3762  // FInd the context of the decl.
3763  if (cl) {
3765  if (cci) {
3766  const clang::DeclContext* dc = 0;
3767  if (const clang::Decl* D = cci->GetDecl()) {
3768  if (!(dc = dyn_cast<clang::NamespaceDecl>(D))) {
3769  dc = dyn_cast<clang::RecordDecl>(D);
3770  }
3771  }
3772  if (dc) {
3773  // If it is a data member enum.
3774  possibleEnum = cling::utils::Lookup::Named(&fInterpreter->getSema(), name, dc);
3775  } else {
3776  Error("TCling::GetEnum", "DeclContext not found for %s .\n", name);
3777  }
3778  }
3779  } else {
3780  // If it is a global enum.
3781  possibleEnum = cling::utils::Lookup::Named(&fInterpreter->getSema(), name);
3782  }
3783  if (possibleEnum && (possibleEnum != (clang::Decl*)-1)
3784  && isa<clang::EnumDecl>(possibleEnum)) {
3785  return possibleEnum;
3786  }
3787  return 0;
3788 }
3789 
3790 ////////////////////////////////////////////////////////////////////////////////
3791 /// Return pointer to cling DeclId for a global value
3792 
3793 TInterpreter::DeclId_t TCling::GetDeclId( const llvm::GlobalValue *gv ) const
3794 {
3795  if (!gv) return 0;
3796 
3797  llvm::StringRef mangled_name = gv->getName();
3798 
3799  int err = 0;
3800  char* demangled_name_c = TClassEdit::DemangleName(mangled_name.str().c_str(), err);
3801  if (err) {
3802  if (err == -2) {
3803  // It might simply be an unmangled global name.
3804  DeclId_t d;
3806  d = gcl.GetDataMember(mangled_name.str().c_str());
3807  return d;
3808  }
3809  return 0;
3810  }
3811 
3812  std::string scopename(demangled_name_c);
3813  free(demangled_name_c);
3814 
3815  //
3816  // Separate out the class or namespace part of the
3817  // function name.
3818  //
3819  std::string dataname;
3820 
3821  if (!strncmp(scopename.c_str(), "typeinfo for ", sizeof("typeinfo for ")-1)) {
3822  scopename.erase(0, sizeof("typeinfo for ")-1);
3823  } if (!strncmp(scopename.c_str(), "vtable for ", sizeof("vtable for ")-1)) {
3824  scopename.erase(0, sizeof("vtable for ")-1);
3825  } else {
3826  // See if it is a function
3827  std::string::size_type pos = scopename.rfind('(');
3828  if (pos != std::string::npos) {
3829  return 0;
3830  }
3831  // Separate the scope and member name
3832  pos = scopename.rfind(':');
3833  if (pos != std::string::npos) {
3834  if ((pos != 0) && (scopename[pos-1] == ':')) {
3835  dataname = scopename.substr(pos+1);
3836  scopename.erase(pos-1);
3837  }
3838  } else {
3839  scopename.clear();
3840  dataname = scopename;
3841  }
3842  }
3843  //fprintf(stderr, "name: '%s'\n", name.c_str());
3844  // Now we have the class or namespace name, so do the lookup.
3845 
3846 
3847  DeclId_t d;
3848  if (scopename.size()) {
3849  TClingClassInfo cl(fInterpreter,scopename.c_str());
3850  d = cl.GetDataMember(dataname.c_str());
3851  }
3852  else {
3854  d = gcl.GetDataMember(dataname.c_str());
3855  }
3856  return d;
3857 }
3858 
3859 ////////////////////////////////////////////////////////////////////////////////
3860 /// NOT IMPLEMENTED.
3861 
3863 {
3864  Error("GetDataMemberWithValue()", "not implemented");
3865  return 0;
3866 }
3867 
3868 ////////////////////////////////////////////////////////////////////////////////
3869 /// Return pointer to cling DeclId for a data member with a given name.
3870 
3872 {
3873  // NOT IMPLEMENTED.
3874  Error("GetDataMemberAtAddr()", "not implemented");
3875  return 0;
3876 }
3877 
3878 ////////////////////////////////////////////////////////////////////////////////
3879 /// Return the cling mangled name for a method of a class with parameters
3880 /// params (params is a string of actual arguments, not formal ones). If the
3881 /// class is 0 the global function list will be searched.
3882 
3883 TString TCling::GetMangledName(TClass* cl, const char* method,
3884  const char* params, Bool_t objectIsConst /* = kFALSE */)
3885 {
3888  if (cl) {
3889  Long_t offset;
3890  func.SetFunc((TClingClassInfo*)cl->GetClassInfo(), method, params, objectIsConst,
3891  &offset);
3892  }
3893  else {
3895  Long_t offset;
3896  func.SetFunc(&gcl, method, params, &offset);
3897  }
3899  if (!mi) return "";
3900  TString mangled_name( mi->GetMangledName() );
3901  delete mi;
3902  return mangled_name;
3903 }
3904 
3905 ////////////////////////////////////////////////////////////////////////////////
3906 /// Return the cling mangled name for a method of a class with a certain
3907 /// prototype, i.e. "char*,int,float". If the class is 0 the global function
3908 /// list will be searched.
3909 
3911  const char* proto, Bool_t objectIsConst /* = kFALSE */,
3912  EFunctionMatchMode mode /* = kConversionMatch */)
3913 {
3915  if (cl) {
3916  return ((TClingClassInfo*)cl->GetClassInfo())->
3917  GetMethod(method, proto, objectIsConst, 0 /*poffset*/, mode).GetMangledName();
3918  }
3920  return gcl.GetMethod(method, proto, objectIsConst, 0 /*poffset*/, mode).GetMangledName();
3921 }
3922 
3923 ////////////////////////////////////////////////////////////////////////////////
3924 /// Return pointer to cling interface function for a method of a class with
3925 /// parameters params (params is a string of actual arguments, not formal
3926 /// ones). If the class is 0 the global function list will be searched.
3927 
3928 void* TCling::GetInterfaceMethod(TClass* cl, const char* method,
3929  const char* params, Bool_t objectIsConst /* = kFALSE */)
3930 {
3933  if (cl) {
3934  Long_t offset;
3935  func.SetFunc((TClingClassInfo*)cl->GetClassInfo(), method, params, objectIsConst,
3936  &offset);
3937  }
3938  else {
3940  Long_t offset;
3941  func.SetFunc(&gcl, method, params, &offset);
3942  }
3943  return (void*) func.InterfaceMethod();
3944 }
3945 
3946 ////////////////////////////////////////////////////////////////////////////////
3947 /// Return pointer to cling interface function for a method of a class with
3948 /// a certain name.
3949 
3950 TInterpreter::DeclId_t TCling::GetFunction(ClassInfo_t *opaque_cl, const char* method)
3951 {
3953  DeclId_t f;
3954  TClingClassInfo *cl = (TClingClassInfo*)opaque_cl;
3955  if (cl) {
3956  f = cl->GetMethod(method).GetDeclId();
3957  }
3958  else {
3960  f = gcl.GetMethod(method).GetDeclId();
3961  }
3962  return f;
3963 
3964 }
3965 
3966 ////////////////////////////////////////////////////////////////////////////////
3967 /// Insert overloads of name in cl to res.
3968 
3969 void TCling::GetFunctionOverloads(ClassInfo_t *cl, const char *funcname,
3970  std::vector<DeclId_t>& res) const
3971 {
3972  clang::Sema& S = fInterpreter->getSema();
3973  const clang::Decl* CtxDecl
3974  = cl ? (const clang::Decl*)((TClingClassInfo*)cl)->GetDeclId():
3975  S.Context.getTranslationUnitDecl();
3976  const clang::DeclContext*
3977  DeclCtx = llvm::dyn_cast<const clang::RecordDecl>(CtxDecl);
3978  if (!DeclCtx)
3979  DeclCtx = dyn_cast<clang::NamespaceDecl>(CtxDecl);
3980  if (!DeclCtx) return;
3981  clang::DeclarationName DName
3982  = &S.Context.Idents.get(funcname);
3983  clang::LookupResult R(S, DName, clang::SourceLocation(),
3984  Sema::LookupOrdinaryName, clang::Sema::ForRedeclaration);
3985  S.LookupQualifiedName(R, const_cast<DeclContext*>(DeclCtx));
3986  if (R.empty()) return;
3987  R.resolveKind();
3988  res.reserve(res.size() + (R.end() - R.begin()));
3989  for (clang::LookupResult::iterator IR = R.begin(), ER = R.end();
3990  IR != ER; ++IR) {
3991  if (const clang::FunctionDecl* FD
3992  = llvm::dyn_cast<const clang::FunctionDecl>(*IR)) {
3993  if (!FD->getDescribedFunctionTemplate()) {
3994  res.push_back(FD);
3995  }
3996  }
3997  }
3998 }
3999 
4000 ////////////////////////////////////////////////////////////////////////////////
4001 /// Return pointer to cling interface function for a method of a class with
4002 /// a certain prototype, i.e. "char*,int,float". If the class is 0 the global
4003 /// function list will be searched.
4004 
4005 void* TCling::GetInterfaceMethodWithPrototype(TClass* cl, const char* method,
4006  const char* proto,
4007  Bool_t objectIsConst /* = kFALSE */,
4008  EFunctionMatchMode mode /* = kConversionMatch */)
4009 {
4011  void* f;
4012  if (cl) {
4013  f = ((TClingClassInfo*)cl->GetClassInfo())->
4014  GetMethod(method, proto, objectIsConst, 0 /*poffset*/, mode).InterfaceMethod(*fNormalizedCtxt);
4015  }
4016  else {
4018  f = gcl.GetMethod(method, proto, objectIsConst, 0 /*poffset*/, mode).InterfaceMethod(*fNormalizedCtxt);
4019  }
4020  return f;
4021 }
4022 
4023 ////////////////////////////////////////////////////////////////////////////////
4024 /// Return pointer to cling DeclId for a method of a class with
4025 /// a certain prototype, i.e. "char*,int,float". If the class is 0 the global
4026 /// function list will be searched.
4027 
4028 TInterpreter::DeclId_t TCling::GetFunctionWithValues(ClassInfo_t *opaque_cl, const char* method,
4029  const char* params,
4030  Bool_t objectIsConst /* = kFALSE */)
4031 {
4033  DeclId_t f;
4034  TClingClassInfo *cl = (TClingClassInfo*)opaque_cl;
4035  if (cl) {
4036  f = cl->GetMethodWithArgs(method, params, objectIsConst, 0 /*poffset*/).GetDeclId();
4037  }
4038  else {
4040  f = gcl.GetMethod(method, params, objectIsConst, 0 /*poffset*/).GetDeclId();
4041  }
4042  return f;
4043 }
4044 
4045 ////////////////////////////////////////////////////////////////////////////////
4046 /// Return pointer to cling interface function for a method of a class with
4047 /// a certain prototype, i.e. "char*,int,float". If the class is 0 the global
4048 /// function list will be searched.
4049 
4050 TInterpreter::DeclId_t TCling::GetFunctionWithPrototype(ClassInfo_t *opaque_cl, const char* method,
4051  const char* proto,
4052  Bool_t objectIsConst /* = kFALSE */,
4053  EFunctionMatchMode mode /* = kConversionMatch */)
4054 {
4056  DeclId_t f;
4057  TClingClassInfo *cl = (TClingClassInfo*)opaque_cl;
4058  if (cl) {
4059  f = cl->GetMethod(method, proto, objectIsConst, 0 /*poffset*/, mode).GetDeclId();
4060  }
4061  else {
4063  f = gcl.GetMethod(method, proto, objectIsConst, 0 /*poffset*/, mode).GetDeclId();
4064  }
4065  return f;
4066 }
4067 
4068 ////////////////////////////////////////////////////////////////////////////////
4069 /// Return pointer to cling interface function for a method of a class with
4070 /// a certain name.
4071 
4072 TInterpreter::DeclId_t TCling::GetFunctionTemplate(ClassInfo_t *opaque_cl, const char* name)
4073 {
4075  DeclId_t f;
4076  TClingClassInfo *cl = (TClingClassInfo*)opaque_cl;
4077  if (cl) {
4078  f = cl->GetFunctionTemplate(name);
4079  }
4080  else {
4082  f = gcl.GetFunctionTemplate(name);
4083  }
4084  return f;
4085 
4086 }
4087 
4088 ////////////////////////////////////////////////////////////////////////////////
4089 /// The 'name' is known to the interpreter, this function returns
4090 /// the internal version of this name (usually just resolving typedefs)
4091 /// This is used in particular to synchronize between the name used
4092 /// by rootcling and by the run-time environment (TClass)
4093 /// Return 0 if the name is not known.
4094 
4095 void TCling::GetInterpreterTypeName(const char* name, std::string &output, Bool_t full)
4096 {
4097  output.clear();
4098 
4100 
4101  TClingClassInfo cl(fInterpreter, name);
4102  if (!cl.IsValid()) {
4103  return ;
4104  }
4105  if (full) {
4106  cl.FullName(output,*fNormalizedCtxt);
4107  return;
4108  }
4109  // Well well well, for backward compatibility we need to act a bit too
4110  // much like CINT.
4112  splitname.ShortType(output, TClassEdit::kDropStd );
4113 
4114  return;
4115 }
4116 
4117 ////////////////////////////////////////////////////////////////////////////////
4118 /// Execute a global function with arguments params.
4119 ///
4120 /// FIXME: The cint-based version of this code does not check if the
4121 /// SetFunc() call works, and does not do any real checking
4122 /// for errors from the Exec() call. It did fetch the most
4123 /// recent cint security error and return that in error, but
4124 /// this does not really translate well to cling/clang. We
4125 /// should enhance these interfaces so that we can report
4126 /// compilation and runtime errors properly.
4127 
4128 void TCling::Execute(const char* function, const char* params, int* error)
4129 {
4131  if (error) {
4132  *error = TInterpreter::kNoError;
4133  }
4135  Long_t offset = 0L;
4137  func.SetFunc(&cl, function, params, &offset);
4138  func.Exec(0);
4139 }
4140 
4141 ////////////////////////////////////////////////////////////////////////////////
4142 /// Execute a method from class cl with arguments params.
4143 ///
4144 /// FIXME: The cint-based version of this code does not check if the
4145 /// SetFunc() call works, and does not do any real checking
4146 /// for errors from the Exec() call. It did fetch the most
4147 /// recent cint security error and return that in error, but
4148 /// this does not really translate well to cling/clang. We
4149 /// should enhance these interfaces so that we can report
4150 /// compilation and runtime errors properly.
4151 
4152 void TCling::Execute(TObject* obj, TClass* cl, const char* method,
4153  const char* params, Bool_t objectIsConst, int* error)
4154 {
4156  if (error) {
4157  *error = TInterpreter::kNoError;
4158  }
4159  // If the actual class of this object inherits 2nd (or more) from TObject,
4160  // 'obj' is unlikely to be the start of the object (as described by IsA()),
4161  // hence gInterpreter->Execute will improperly correct the offset.
4162  void* addr = cl->DynamicCast(TObject::Class(), obj, kFALSE);
4163  Long_t offset = 0L;
4165  func.SetFunc((TClingClassInfo*)cl->GetClassInfo(), method, params, objectIsConst, &offset);
4166  void* address = (void*)((Long_t)addr + offset);
4167  func.Exec(address);
4168 }
4169 
4170 ////////////////////////////////////////////////////////////////////////////////
4171 
4172 void TCling::Execute(TObject* obj, TClass* cl, const char* method,
4173  const char* params, int* error)
4174 {
4175  Execute(obj,cl,method,params,false,error);
4176 }
4177 
4178 ////////////////////////////////////////////////////////////////////////////////
4179 /// Execute a method from class cl with the arguments in array params
4180 /// (params[0] ... params[n] = array of TObjString parameters).
4181 /// Convert the TObjArray array of TObjString parameters to a character
4182 /// string of comma separated parameters.
4183 /// The parameters of type 'char' are enclosed in double quotes and all
4184 /// internal quotes are escaped.
4185 
4186 void TCling::Execute(TObject* obj, TClass* cl, TMethod* method,
4187  TObjArray* params, int* error)
4188 {
4189  if (!method) {
4190  Error("Execute", "No method was defined");
4191  return;
4192  }
4193  TList* argList = method->GetListOfMethodArgs();
4194  // Check number of actual parameters against of expected formal ones
4195 
4196  Int_t nparms = argList->LastIndex() + 1;
4197  Int_t argc = params ? params->GetEntries() : 0;
4198 
4199  if (argc > nparms) {
4200  Error("Execute","Too many parameters to call %s, got %d but expected at most %d.",method->GetName(),argc,nparms);
4201  return;
4202  }
4203  if (nparms != argc) {
4204  // Let's see if the 'missing' argument are all defaulted.
4205  // if nparms==0 then either we stopped earlier either argc is also zero and we can't reach here.
4206  assert(nparms > 0);
4207 
4208  TMethodArg *arg = (TMethodArg *) argList->At( 0 );
4209  if (arg && arg->GetDefault() && arg->GetDefault()[0]) {
4210  // There is a default value for the first missing
4211  // argument, so we are fine.
4212  } else {
4213  Int_t firstDefault = -1;
4214  for (Int_t i = 0; i < nparms; i ++) {
4215  arg = (TMethodArg *) argList->At( i );
4216  if (arg && arg->GetDefault() && arg->GetDefault()[0]) {
4217  firstDefault = i;
4218  break;
4219  }
4220  }
4221  if (firstDefault >= 0) {
4222  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);
4223  } else {
4224  Error("Execute","Too few arguments to call %s, got only %d but expected %d.",method->GetName(),argc,nparms);
4225  }
4226  return;
4227  }
4228  }
4229 
4230  const char* listpar = "";
4231  TString complete(10);
4232  if (params) {
4233  // Create a character string of parameters from TObjArray
4234  TIter next(params);
4235  for (Int_t i = 0; i < argc; i ++) {
4236  TMethodArg* arg = (TMethodArg*) argList->At(i);
4238  TObjString* nxtpar = (TObjString*) next();
4239  if (i) {
4240  complete += ',';
4241  }
4242  if (strstr(type.TrueName(*fNormalizedCtxt), "char")) {
4243  TString chpar('\"');
4244  chpar += (nxtpar->String()).ReplaceAll("\"", "\\\"");
4245  // At this point we have to check if string contains \\"
4246  // and apply some more sophisticated parser. Not implemented yet!
4247  complete += chpar;
4248  complete += '\"';
4249  }
4250  else {
4251  complete += nxtpar->String();
4252  }
4253  }
4254  listpar = complete.Data();
4255  }
4256 
4257  // And now execute it.
4259  if (error) {
4260  *error = TInterpreter::kNoError;
4261  }
4262  // If the actual class of this object inherits 2nd (or more) from TObject,
4263  // 'obj' is unlikely to be the start of the object (as described by IsA()),
4264  // hence gInterpreter->Execute will improperly correct the offset.
4265  void* addr = cl->DynamicCast(TObject::Class(), obj, kFALSE);
4267  TClingMethodInfo *minfo = (TClingMethodInfo*)method->fInfo;
4268  func.Init(minfo);
4269  func.SetArgs(listpar);
4270  // Now calculate the 'this' pointer offset for the method
4271  // when starting from the class described by cl.
4272  const CXXMethodDecl * mdecl = dyn_cast<CXXMethodDecl>(minfo->GetMethodDecl());
4273  Long_t offset = ((TClingClassInfo*)cl->GetClassInfo())->GetOffset(mdecl);
4274  void* address = (void*)((Long_t)addr + offset);
4275  func.Exec(address);
4276 }
4277 
4278 ////////////////////////////////////////////////////////////////////////////////
4279 
4280 void TCling::ExecuteWithArgsAndReturn(TMethod* method, void* address,
4281  const void* args[] /*=0*/,
4282  int nargs /*=0*/,
4283  void* ret/*= 0*/) const
4284 {
4285  if (!method) {
4286  Error("ExecuteWithArgsAndReturn", "No method was defined");
4287  return;
4288  }
4289 
4290  TClingMethodInfo* minfo = (TClingMethodInfo*) method->fInfo;
4292  func.ExecWithArgsAndReturn(address, args, nargs, ret);
4293 }
4294 
4295 ////////////////////////////////////////////////////////////////////////////////
4296 /// Execute a cling macro.
4297 
4299 {
4301  fCurExecutingMacros.push_back(filename);
4302  Long_t result = TApplication::ExecuteFile(filename, (int*)error);
4303  fCurExecutingMacros.pop_back();
4304  return result;
4305 }
4306 
4307 ////////////////////////////////////////////////////////////////////////////////
4308 /// Return the file name of the current un-included interpreted file.
4309 /// See the documentation for GetCurrentMacroName().
4310 
4311 const char* TCling::GetTopLevelMacroName() const
4312 {
4313  Warning("GetTopLevelMacroName", "Must change return type!");
4314  return fCurExecutingMacros.back();
4315 }
4316 
4317 ////////////////////////////////////////////////////////////////////////////////
4318 /// Return the file name of the currently interpreted file,
4319 /// included or not. Example to illustrate the difference between
4320 /// GetCurrentMacroName() and GetTopLevelMacroName():
4321 /// ~~~ {.cpp}
4322 /// void inclfile() {
4323 /// std::cout << "In inclfile.C" << std::endl;
4324 /// std::cout << " TCling::GetCurrentMacroName() returns " <<
4325 /// TCling::GetCurrentMacroName() << std::endl;
4326 /// std::cout << " TCling::GetTopLevelMacroName() returns " <<
4327 /// TCling::GetTopLevelMacroName() << std::endl;
4328 /// }
4329 /// ~~~
4330 /// ~~~ {.cpp}
4331 /// void mymacro() {
4332 /// std::cout << "In mymacro.C" << std::endl;
4333 /// std::cout << " TCling::GetCurrentMacroName() returns " <<
4334 /// TCling::GetCurrentMacroName() << std::endl;
4335 /// std::cout << " TCling::GetTopLevelMacroName() returns " <<
4336 /// TCling::GetTopLevelMacroName() << std::endl;
4337 /// std::cout << " Now calling inclfile..." << std::endl;
4338 /// gInterpreter->ProcessLine(".x inclfile.C");;
4339 /// }
4340 /// ~~~
4341 /// Running mymacro.C will print:
4342 ///
4343 /// ~~~ {.cpp}
4344 /// root [0] .x mymacro.C
4345 /// ~~~
4346 /// In mymacro.C
4347 /// ~~~ {.cpp}
4348 /// TCling::GetCurrentMacroName() returns ./mymacro.C
4349 /// TCling::GetTopLevelMacroName() returns ./mymacro.C
4350 /// ~~~
4351 /// Now calling inclfile...
4352 /// In inclfile.h
4353 /// ~~~ {.cpp}
4354 /// TCling::GetCurrentMacroName() returns inclfile.C
4355 /// TCling::GetTopLevelMacroName() returns ./mymacro.C
4356 /// ~~~
4357 
4358 const char* TCling::GetCurrentMacroName() const
4359 {
4360 #if defined(R__MUST_REVISIT)
4361 #if R__MUST_REVISIT(6,0)
4362  Warning("GetCurrentMacroName", "Must change return type!");
4363 #endif
4364 #endif
4365  return fCurExecutingMacros.back();
4366 }
4367 
4368 ////////////////////////////////////////////////////////////////////////////////
4369 /// Return the absolute type of typeDesc.
4370 /// E.g.: typeDesc = "class TNamed**", returns "TNamed".
4371 /// You need to use the result immediately before it is being overwritten.
4372 
4373 const char* TCling::TypeName(const char* typeDesc)
4374 {
4375  TTHREAD_TLS(char*) t = 0;
4376  TTHREAD_TLS(unsigned int) tlen = 0;
4377 
4378  unsigned int dlen = strlen(typeDesc);
4379  if (dlen > tlen) {
4380  delete[] t;
4381  t = new char[dlen + 1];
4382  tlen = dlen;
4383  }
4384  const char* s, *template_start;
4385  if (!strstr(typeDesc, "(*)(")) {
4386  s = strchr(typeDesc, ' ');
4387  template_start = strchr(typeDesc, '<');
4388  if (!strcmp(typeDesc, "long long")) {
4389  strlcpy(t, typeDesc, dlen + 1);
4390  }
4391  else if (!strncmp(typeDesc, "unsigned ", s + 1 - typeDesc)) {
4392  strlcpy(t, typeDesc, dlen + 1);
4393  }
4394  // s is the position of the second 'word' (if any)
4395  // except in the case of templates where there will be a space
4396  // just before any closing '>': eg.
4397  // TObj<std::vector<UShort_t,__malloc_alloc_template<0> > >*
4398  else if (s && (template_start == 0 || (s < template_start))) {
4399  strlcpy(t, s + 1, dlen + 1);
4400  }
4401  else {
4402  strlcpy(t, typeDesc, dlen + 1);
4403  }
4404  }
4405  else {
4406  strlcpy(t, typeDesc, dlen + 1);
4407  }
4408  int l = strlen(t);
4409  while (l > 0 && (t[l - 1] == '*' || t[l - 1] == '&')) {
4410  t[--l] = 0;
4411  }
4412  return t;
4413 }
4414 
4415 ////////////////////////////////////////////////////////////////////////////////
4416 /// Read and parse a rootmapfile in its new format, and return 0 in case of
4417 /// success, -1 if the file has already been read, and -3 in case its format
4418 /// is the old one (e.g. containing "Library.ClassName")
4419 
4420 int TCling::ReadRootmapFile(const char *rootmapfile, TUniqueString *uniqueString)
4421 {
4422  // For "class ", "namespace ", "typedef ", "header ", "enum " respectively
4423  const std::map<char, unsigned int> keyLenMap = {{'c',6},{'n',10},{'t',8},{'h',7},{'e',5}};
4424 
4425  if (rootmapfile && *rootmapfile) {
4426 
4427  // Add content of a specific rootmap file
4428  if (fRootmapFiles->FindObject(rootmapfile)) return -1;
4429  std::ifstream file(rootmapfile);
4430  std::string line; line.reserve(200);
4431  std::string lib_name; line.reserve(100);
4432  bool newFormat=false;
4433  while (getline(file, line, '\n')) {
4434  if (!newFormat &&
4435  (strstr(line.c_str(),"Library.")!=nullptr || strstr(line.c_str(),"Declare.")!=nullptr)) {
4436  file.close();
4437  return -3; // old format
4438  }
4439  newFormat=true;
4440 
4441  if (line.compare(0, 9, "{ decls }") == 0) {
4442  // forward declarations
4443 
4444  while (getline(file, line, '\n')) {
4445  if (line[0] == '[') break;
4446  uniqueString->Append(line);
4447  }
4448  }
4449  const char firstChar=line[0];
4450  if (firstChar == '[') {
4451  // new section (library)
4452  auto brpos = line.find(']');
4453  if (brpos == string::npos) continue;
4454  lib_name = line.substr(1, brpos-1);
4455  size_t nspaces = 0;
4456  while( lib_name[nspaces] == ' ' ) ++nspaces;
4457  if (nspaces) lib_name.replace(0, nspaces, "");
4458  if (gDebug > 3) {
4459  TString lib_nameTstr(lib_name.c_str());
4460  TObjArray* tokens = lib_nameTstr.Tokenize(" ");
4461  const char* lib = ((TObjString *)tokens->At(0))->GetName();
4462  const char* wlib = gSystem->DynamicPathName(lib, kTRUE);
4463  if (wlib) {
4464  Info("ReadRootmapFile", "new section for %s", lib_nameTstr.Data());
4465  }
4466  else {
4467  Info("ReadRootmapFile", "section for %s (library does not exist)", lib_nameTstr.Data());
4468  }
4469  delete[] wlib;
4470  delete tokens;
4471  }
4472  }
4473  else {
4474  auto keyLenIt = keyLenMap.find(firstChar);
4475  if (keyLenIt == keyLenMap.end()) continue;
4476  unsigned int keyLen = keyLenIt->second;
4477  // Do not make a copy, just start after the key
4478  const char *keyname = line.c_str()+keyLen;
4479  if (gDebug > 6)
4480  Info("ReadRootmapFile", "class %s in %s", keyname, lib_name.c_str());
4481  TEnvRec* isThere = fMapfile->Lookup(keyname);
4482  if (isThere){
4483  if(lib_name != isThere->GetValue()){ // the same key for two different libs
4484  if (firstChar == 'n') {
4485  if (gDebug > 3)
4486  Info("ReadRootmapFile", "namespace %s found in %s is already in %s",
4487  keyname, lib_name.c_str(), isThere->GetValue());
4488  } else if (firstChar == 'h'){ // it is a header: add the libname to the list of libs to be loaded.
4489  lib_name+=" ";
4490  lib_name+=isThere->GetValue();
4491  fMapfile->SetValue(keyname, lib_name.c_str());
4492  }
4493  else if (!TClassEdit::IsSTLCont(keyname)) {
4494  Warning("ReadRootmapFile", "%s %s found in %s is already in %s", line.substr(0, keyLen).c_str(),
4495  keyname, lib_name.c_str(), isThere->GetValue());
4496  }
4497  } else { // the same key for the same lib
4498  if (gDebug > 3)
4499  Info("ReadRootmapFile","Key %s was already defined for %s", keyname, lib_name.c_str());
4500  }
4501 
4502  } else {
4503  fMapfile->SetValue(keyname, lib_name.c_str());
4504  }
4505  }
4506  }
4507  file.close();
4508  }
4509 
4510  return 0;
4511 }
4512 
4513 ////////////////////////////////////////////////////////////////////////////////
4514 /// Create a resource table and read the (possibly) three resource files, i.e
4515 /// $ROOTSYS/etc/system<name> (or ROOTETCDIR/system<name>), $HOME/<name> and
4516 /// ./<name>. ROOT always reads ".rootrc" (in TROOT::InitSystem()). You can
4517 /// read additional user defined resource files by creating additional TEnv
4518 /// objects. By setting the shell variable ROOTENV_NO_HOME=1 the reading of
4519 /// the $HOME/<name> resource file will be skipped. This might be useful in
4520 /// case the home directory resides on an automounted remote file system
4521 /// and one wants to avoid the file system from being mounted.
4522 
4524 {
4526 
4527  fMapfile->SetRcName(name);
4528 
4529  TString sname = "system";
4530  sname += name;
4531  char *s = gSystem->ConcatFileName(TROOT::GetEtcDir(), sname);
4532 
4533  Int_t ret = ReadRootmapFile(s);
4534  if (ret == -3) // old format
4536  delete [] s;
4537  if (!gSystem->Getenv("ROOTENV_NO_HOME")) {
4539  ret = ReadRootmapFile(s);
4540  if (ret == -3) // old format
4541  fMapfile->ReadFile(s, kEnvUser);
4542  delete [] s;
4543  if (strcmp(gSystem->HomeDirectory(), gSystem->WorkingDirectory())) {
4544  ret = ReadRootmapFile(name);
4545  if (ret == -3) // old format
4546  fMapfile->ReadFile(name, kEnvLocal);
4547  }
4548  } else {
4549  ret = ReadRootmapFile(name);
4550  if (ret == -3) // old format
4551  fMapfile->ReadFile(name, kEnvLocal);
4552  }
4553  fMapfile->IgnoreDuplicates(ignore);
4554 }
4555 
4556 
4557 namespace {
4558  using namespace clang;
4559 
4560  class ExtVisibleStorageAdder: public RecursiveASTVisitor<ExtVisibleStorageAdder>{
4561  // This class is to be considered an helper for autoloading.
4562  // It is a recursive visitor is used to inspect namespaces coming from
4563  // forward declarations in rootmaps and to set the external visible
4564  // storage flag for them.
4565  public:
4566  ExtVisibleStorageAdder(std::unordered_set<const NamespaceDecl*>& nsSet): fNSSet(nsSet) {};
4567  bool VisitNamespaceDecl(NamespaceDecl* nsDecl) {
4568  // We want to enable the external lookup for this namespace
4569  // because it may shadow the lookup of other names contained
4570  // in that namespace
4571  nsDecl->setHasExternalVisibleStorage();
4572  fNSSet.insert(nsDecl);
4573  return true;
4574  }
4575  private:
4576  std::unordered_set<const NamespaceDecl*>& fNSSet;
4577 
4578  };
4579 }
4580 
4581 ////////////////////////////////////////////////////////////////////////////////
4582 /// Load map between class and library. If rootmapfile is specified a
4583 /// specific rootmap file can be added (typically used by ACLiC).
4584 /// In case of error -1 is returned, 0 otherwise.
4585 /// The interpreter uses this information to automatically load the shared
4586 /// library for a class (autoload mechanism), see the AutoLoad() methods below.
4587 
4588 Int_t TCling::LoadLibraryMap(const char* rootmapfile)
4589 {
4591  // open the [system].rootmap files
4592  if (!fMapfile) {
4593  fMapfile = new TEnv();
4595 // fMapNamespaces = new THashTable();
4596 // fMapNamespaces->SetOwner();
4597  fRootmapFiles = new TObjArray;
4599  InitRootmapFile(".rootmap");
4600  }
4601 
4602  // Prepare a list of all forward declarations for cling
4603  // For some experiments it is easily as big as 500k characters. To be on the
4604  // safe side, we go for 1M.
4605  TUniqueString uniqueString(1048576);
4606 
4607  // Load all rootmap files in the dynamic load path ((DY)LD_LIBRARY_PATH, etc.).
4608  // A rootmap file must end with the string ".rootmap".
4609  TString ldpath = gSystem->GetDynamicPath();
4610  if (ldpath != fRootmapLoadPath) {
4611  fRootmapLoadPath = ldpath;
4612 #ifdef WIN32
4613  TObjArray* paths = ldpath.Tokenize(";");
4614 #else
4615  TObjArray* paths = ldpath.Tokenize(":");
4616 #endif
4617  TString d;
4618  for (Int_t i = 0; i < paths->GetEntriesFast(); i++) {
4619  d = ((TObjString *)paths->At(i))->GetString();
4620  // check if directory already scanned
4621  Int_t skip = 0;
4622  for (Int_t j = 0; j < i; j++) {
4623  TString pd = ((TObjString *)paths->At(j))->GetString();
4624  if (pd == d) {
4625  skip++;
4626  break;
4627  }
4628  }
4629  if (!skip) {
4630  void* dirp = gSystem->OpenDirectory(d);
4631  if (dirp) {
4632  if (gDebug > 3) {
4633  Info("LoadLibraryMap", "%s", d.Data());
4634  }
4635  const char* f1;
4636  while ((f1 = gSystem->GetDirEntry(dirp))) {
4637  TString f = f1;
4638  if (f.EndsWith(".rootmap")) {
4639  TString p;
4640  p = d + "/" + f;
4642  if (!fRootmapFiles->FindObject(f) && f != ".rootmap") {
4643  if (gDebug > 4) {
4644  Info("LoadLibraryMap", " rootmap file: %s", p.Data());
4645  }
4646  Int_t ret = ReadRootmapFile(p,&uniqueString);
4647  if (ret == 0)
4648  fRootmapFiles->Add(new TNamed(gSystem->BaseName(f), p.Data()));
4649  if (ret == -3) {
4650  // old format
4652  fRootmapFiles->Add(new TNamed(f, p));
4653  }
4654  }
4655  // else {
4656  // fprintf(stderr,"Reject %s because %s is already there\n",p.Data(),f.Data());
4657  // fRootmapFiles->FindObject(f)->ls();
4658  // }
4659  }
4660  }
4661  if (f.BeginsWith("rootmap")) {
4662  TString p;
4663  p = d + "/" + f;
4664  FileStat_t stat;
4665  if (gSystem->GetPathInfo(p, stat) == 0 && R_ISREG(stat.fMode)) {
4666  Warning("LoadLibraryMap", "please rename %s to end with \".rootmap\"", p.Data());
4667  }
4668  }
4669  }
4670  }
4671  gSystem->FreeDirectory(dirp);
4672  }
4673  }
4674  delete paths;
4675  if (!fMapfile->GetTable()->GetEntries()) {
4676  return -1;
4677  }
4678  }
4679  if (rootmapfile && *rootmapfile) {
4680  Int_t res = ReadRootmapFile(rootmapfile, &uniqueString);
4681  if (res == 0) {
4682  //TString p = gSystem->ConcatFileName(gSystem->pwd(), rootmapfile);
4683  //fRootmapFiles->Add(new TNamed(gSystem->BaseName(rootmapfile), p.Data()));
4684  fRootmapFiles->Add(new TNamed(gSystem->BaseName(rootmapfile), rootmapfile));
4685  }
4686  else if (res == -3) {
4687  // old format
4689  fMapfile->ReadFile(rootmapfile, kEnvGlobal);
4690  fRootmapFiles->Add(new TNamed(gSystem->BaseName(rootmapfile), rootmapfile));
4691  fMapfile->IgnoreDuplicates(ignore);
4692  }
4693  }
4694  TEnvRec* rec;
4695  TIter next(fMapfile->GetTable());
4696  while ((rec = (TEnvRec*) next())) {
4697  TString cls = rec->GetName();
4698  if (!strncmp(cls.Data(), "Library.", 8) && cls.Length() > 8) {
4699  // get the first lib from the list of lib and dependent libs
4700  TString libs = rec->GetValue();
4701  if (libs == "") {
4702  continue;
4703  }
4704  TString delim(" ");
4705  TObjArray* tokens = libs.Tokenize(delim);
4706  const char* lib = ((TObjString*)tokens->At(0))->GetName();
4707  // convert "@@" to "::", we used "@@" because TEnv
4708  // considers "::" a terminator
4709  cls.Remove(0, 8);
4710  cls.ReplaceAll("@@", "::");
4711  // convert "-" to " ", since class names may have
4712  // blanks and TEnv considers a blank a terminator
4713  cls.ReplaceAll("-", " ");
4714  if (gDebug > 6) {
4715  const char* wlib = gSystem->DynamicPathName(lib, kTRUE);
4716  if (wlib) {
4717  Info("LoadLibraryMap", "class %s in %s", cls.Data(), wlib);
4718  }
4719  else {
4720  Info("LoadLibraryMap", "class %s in %s (library does not exist)", cls.Data(), lib);
4721  }
4722  delete[] wlib;
4723  }
4724  // Fill in the namespace candidate list
4725 // Ssiz_t last = cls.Last(':');
4726 // if (last != kNPOS) {
4727 // // Please note that the funny op overload does substring.
4728 // TString namespaceCand = cls(0, last - 1);
4729 // // This is a reference to a substring that lives in fMapfile
4730 // if (!fMapNamespaces->FindObject(namespaceCand.Data()))
4731 // fMapNamespaces->Add(new TNamed(namespaceCand.Data(), ""));
4732 // }
4733  delete tokens;
4734  }
4735  else if (!strncmp(cls.Data(), "Declare.", 8) && cls.Length() > 8) {
4736  cls.Remove(0, 8);
4737  // convert "-" to " ", since class names may have
4738  // blanks and TEnv considers a blank a terminator
4739  cls.ReplaceAll("-", " ");
4740  fInterpreter->declare(cls.Data());
4741  }
4742  }
4743 
4744  // Process the forward declarations collected
4745  cling::Transaction* T = nullptr;
4746  auto compRes= fInterpreter->declare(uniqueString.Data(), &T);
4747  assert(cling::Interpreter::kSuccess == compRes && "A declaration in a rootmap could not be compiled");
4748 
4749  if (compRes!=cling::Interpreter::kSuccess){
4750  Warning("LoadLibraryMap",
4751  "Problems in %s declaring '%s' were encountered.", rootmapfile, uniqueString.Data()) ;
4752  }
4753 
4754  if (T){
4755  ExtVisibleStorageAdder evsAdder(fNSFromRootmaps);
4756  for (auto declIt = T->decls_begin(); declIt < T->decls_end(); ++declIt) {
4757  if (declIt->m_DGR.isSingleDecl()) {
4758  if (Decl* D = declIt->m_DGR.getSingleDecl()) {
4759  if (NamespaceDecl* NSD = dyn_cast<NamespaceDecl>(D)) {
4760  evsAdder.TraverseDecl(NSD);
4761  }
4762  }
4763  }
4764  }
4765  }
4766 
4767  // clear duplicates
4768 
4769  return 0;
4770 }
4771 
4772 ////////////////////////////////////////////////////////////////////////////////
4773 /// Scan again along the dynamic path for library maps. Entries for the loaded
4774 /// shared libraries are unloaded first. This can be useful after reseting
4775 /// the dynamic path through TSystem::SetDynamicPath()
4776 /// In case of error -1 is returned, 0 otherwise.
4777 
4779 {
4781  LoadLibraryMap();
4782  return 0;
4783 }
4784 
4785 ////////////////////////////////////////////////////////////////////////////////
4786 /// Reload the library map entries coming from all the loaded shared libraries,
4787 /// after first unloading the current ones.
4788 /// In case of error -1 is returned, 0 otherwise.
4789 
4791 {
4792  const TString sharedLibLStr = GetSharedLibs();
4793  const TObjArray* sharedLibL = sharedLibLStr.Tokenize(" ");
4794  const Int_t nrSharedLibs = sharedLibL->GetEntriesFast();
4795  for (Int_t ilib = 0; ilib < nrSharedLibs; ilib++) {
4796  const TString sharedLibStr = ((TObjString*)sharedLibL->At(ilib))->GetString();
4797  const TString sharedLibBaseStr = gSystem->BaseName(sharedLibStr);
4798  const Int_t ret = UnloadLibraryMap(sharedLibBaseStr);
4799  if (ret < 0) {
4800  continue;
4801  }
4802  TString rootMapBaseStr = sharedLibBaseStr;
4803  if (sharedLibBaseStr.EndsWith(".dll")) {
4804  rootMapBaseStr.ReplaceAll(".dll", "");
4805  }
4806  else if (sharedLibBaseStr.EndsWith(".DLL")) {
4807  rootMapBaseStr.ReplaceAll(".DLL", "");
4808  }
4809  else if (sharedLibBaseStr.EndsWith(".so")) {
4810  rootMapBaseStr.ReplaceAll(".so", "");
4811  }
4812  else if (sharedLibBaseStr.EndsWith(".sl")) {
4813  rootMapBaseStr.ReplaceAll(".sl", "");
4814  }
4815  else if (sharedLibBaseStr.EndsWith(".dl")) {
4816  rootMapBaseStr.ReplaceAll(".dl", "");
4817  }
4818  else if (sharedLibBaseStr.EndsWith(".a")) {
4819  rootMapBaseStr.ReplaceAll(".a", "");
4820  }
4821  else {
4822  Error("ReloadAllSharedLibraryMaps", "Unknown library type %s", sharedLibBaseStr.Data());
4823  delete sharedLibL;
4824  return -1;
4825  }
4826  rootMapBaseStr += ".rootmap";
4827  const char* rootMap = gSystem->Which(gSystem->GetDynamicPath(), rootMapBaseStr);
4828  if (!rootMap) {
4829  Error("ReloadAllSharedLibraryMaps", "Could not find rootmap %s in path", rootMap);
4830  delete[] rootMap;
4831  delete sharedLibL;
4832  return -1;
4833  }
4834  const Int_t status = LoadLibraryMap(rootMap);
4835  if (status < 0) {
4836  Error("ReloadAllSharedLibraryMaps", "Error loading map %s", rootMap);
4837  delete[] rootMap;
4838  delete sharedLibL;
4839  return -1;
4840  }
4841  delete[] rootMap;
4842  }
4843  delete sharedLibL;
4844  return 0;
4845 }
4846 
4847 ////////////////////////////////////////////////////////////////////////////////
4848 /// Unload the library map entries coming from all the loaded shared libraries.
4849 /// Returns 0 if succesful
4850 
4852 {
4853  const TString sharedLibLStr = GetSharedLibs();
4854  const TObjArray* sharedLibL = sharedLibLStr.Tokenize(" ");
4855  for (Int_t ilib = 0; ilib < sharedLibL->GetEntriesFast(); ilib++) {
4856  const TString sharedLibStr = ((TObjString*)sharedLibL->At(ilib))->GetString();
4857  const TString sharedLibBaseStr = gSystem->BaseName(sharedLibStr);
4858  UnloadLibraryMap(sharedLibBaseStr);
4859  }
4860  delete sharedLibL;
4861  return 0;
4862 }
4863 
4864 ////////////////////////////////////////////////////////////////////////////////
4865 /// Unload library map entries coming from the specified library.
4866 /// Returns -1 in case no entries for the specified library were found,
4867 /// 0 otherwise.
4868 
4869 Int_t TCling::UnloadLibraryMap(const char* library)
4870 {
4871  if (!fMapfile || !library || !*library) {
4872  return 0;
4873  }
4874  TString libname(library);
4875  Ssiz_t idx = libname.Last('.');
4876  if (idx != kNPOS) {
4877  libname.Remove(idx);
4878  }
4879  size_t len = libname.Length();
4880  TEnvRec *rec;
4881  TIter next(fMapfile->GetTable());
4883  Int_t ret = 0;
4884  while ((rec = (TEnvRec *) next())) {
4885  TString cls = rec->GetName();
4886  if (cls.Length() > 2) {
4887  // get the first lib from the list of lib and dependent libs
4888  TString libs = rec->GetValue();
4889  if (libs == "") {
4890  continue;
4891  }
4892  TString delim(" ");
4893  TObjArray* tokens = libs.Tokenize(delim);
4894  const char* lib = ((TObjString *)tokens->At(0))->GetName();
4895  if (!strncmp(cls.Data(), "Library.", 8) && cls.Length() > 8) {
4896  // convert "@@" to "::", we used "@@" because TEnv
4897  // considers "::" a terminator
4898  cls.Remove(0, 8);
4899  cls.ReplaceAll("@@", "::");
4900  // convert "-" to " ", since class names may have
4901  // blanks and TEnv considers a blank a terminator
4902  cls.ReplaceAll("-", " ");
4903  }
4904  if (!strncmp(lib, libname.Data(), len)) {
4905  if (fMapfile->GetTable()->Remove(rec) == 0) {
4906  Error("UnloadLibraryMap", "entry for <%s, %s> not found in library map table", cls.Data(), lib);
4907  ret = -1;
4908  }
4909  }
4910  delete tokens;
4911  }
4912  }
4913  if (ret >= 0) {
4914  TString library_rootmap(library);
4915  if (!library_rootmap.EndsWith(".rootmap"))
4916  library_rootmap.Append(".rootmap");
4917  TNamed* mfile = 0;
4918  while ((mfile = (TNamed *)fRootmapFiles->FindObject(library_rootmap))) {
4919  fRootmapFiles->Remove(mfile);
4920  delete mfile;
4921  }
4923  }
4924  return ret;
4925 }
4926 
4927 ////////////////////////////////////////////////////////////////////////////////
4928 /// Register the autoloading information for a class.
4929 /// libs is a space separated list of libraries.
4930 
4931 Int_t TCling::SetClassSharedLibs(const char *cls, const char *libs)
4932 {
4933  if (!cls || !*cls)
4934  return 0;
4935 
4936  TString key = TString("Library.") + cls;
4937  // convert "::" to "@@", we used "@@" because TEnv
4938  // considers "::" a terminator
4939  key.ReplaceAll("::", "@@");
4940  // convert "-" to " ", since class names may have
4941  // blanks and TEnv considers a blank a terminator
4942  key.ReplaceAll(" ", "-");
4943 
4945  if (!fMapfile) {
4946  fMapfile = new TEnv();
4948 // fMapNamespaces = new THashTable();
4949 // fMapNamespaces->SetOwner();
4950 
4951  fRootmapFiles = new TObjArray;
4953 
4954  InitRootmapFile(".rootmap");
4955  }
4956  //fMapfile->SetValue(key, libs);
4957  fMapfile->SetValue(cls, libs);
4958  return 1;
4959 }
4960 
4961 ////////////////////////////////////////////////////////////////////////////////
4962 /// Demangle the name (from the typeinfo) and then request the class
4963 /// via the usual name based interface (TClass::GetClass).
4964 
4965 TClass *TCling::GetClass(const std::type_info& typeinfo, Bool_t load) const
4966 {
4967  int err = 0;
4968  char* demangled_name = TClassEdit::DemangleTypeIdName(typeinfo, err);
4969  if (err) return 0;
4970  TClass* theClass = TClass::GetClass(demangled_name, load, kTRUE);
4971  free(demangled_name);
4972  return theClass;
4973 }
4974 
4975 ////////////////////////////////////////////////////////////////////////////////
4976 /// Load library containing the specified class. Returns 0 in case of error
4977 /// and 1 in case if success.
4978 
4979 Int_t TCling::AutoLoad(const std::type_info& typeinfo, Bool_t knowDictNotLoaded /* = kFALSE */)
4980 {
4981  int err = 0;
4982  char* demangled_name_c = TClassEdit::DemangleTypeIdName(typeinfo, err);
4983  if (err) {
4984  return 0;
4985  }
4986 
4987  std::string demangled_name(demangled_name_c);
4988  free(demangled_name_c);
4989 
4990  // AutoLoad expects (because TClass::GetClass already prepares it that way) a
4991  // shortened name.
4992  TClassEdit::TSplitType splitname( demangled_name.c_str(), (TClassEdit::EModType)(TClassEdit::kLong64 | TClassEdit::kDropStd) );
4993  splitname.ShortType(demangled_name, TClassEdit::kDropStlDefault | TClassEdit::kDropStd);
4994 
4995  // No need to worry about typedef, they aren't any ... but there are
4996  // inlined namespaces ...
4997 
4998  Int_t result = AutoLoad(demangled_name.c_str());
4999  if (result == 0) {
5000  demangled_name = TClassEdit::GetLong64_Name(demangled_name);
5001  result = AutoLoad(demangled_name.c_str(), knowDictNotLoaded);
5002  }
5003 
5004  return result;
5005 }
5006 
5007 ////////////////////////////////////////////////////////////////////////////////
5008 /// Load library containing the specified class. Returns 0 in case of error
5009 /// and 1 in case if success.
5010 
5011 Int_t TCling::AutoLoad(const char *cls, Bool_t knowDictNotLoaded /* = kFALSE */)
5012 {
5014 
5015  if (!knowDictNotLoaded && gClassTable->GetDictNorm(cls)) {
5016  // The library is already loaded as the class's dictionary is known.
5017  // Return success.
5018  // Note: the name (cls) is expected to be normalized as it comes either
5019  // from a callbacks (that can/should calculate the normalized name from the
5020  // decl) or from TClass::GetClass (which does also calculate the normalized
5021  // name).
5022  return 1;
5023  }
5024 
5025  if (gDebug > 2) {
5026  Info("TCling::AutoLoad",
5027  "Trying to autoload for %s", cls);
5028  }
5029 
5030  Int_t status = 0;
5031  if (!gROOT || !gInterpreter || gROOT->TestBit(TObject::kInvalidObject)) {
5032  if (gDebug > 2) {
5033  Info("TCling::AutoLoad",
5034  "Disabled due to gROOT or gInterpreter being invalid/not ready (the class name is %s)", cls);
5035  }
5036  return status;
5037  }
5038  if (!fAllowLibLoad) {
5039  // Never load any library from rootcling/genreflex.
5040  if (gDebug > 2) {
5041  Info("TCling::AutoLoad",
5042  "Explicitly disabled (the class name is %s)", cls);
5043  }
5044  return 0;
5045  }
5046  // Prevent the recursion when the library dictionary are loaded.
5047  Int_t oldvalue = SetClassAutoloading(false);
5048  // Try using externally provided callback first.
5049  if (fAutoLoadCallBack) {
5050  int success = (*(AutoLoadCallBack_t)fAutoLoadCallBack)(cls);
5051  if (success) {
5052  SetClassAutoloading(oldvalue);
5053  return success;
5054  }
5055  }
5056  // lookup class to find list of dependent libraries
5057  TString deplibs = GetClassSharedLibs(cls);
5058  if (!deplibs.IsNull()) {
5059  TString delim(" ");
5060  TObjArray* tokens = deplibs.Tokenize(delim);
5061  for (Int_t i = (tokens->GetEntriesFast() - 1); i > 0; --i) {
5062  const char* deplib = ((TObjString*)tokens->At(i))->GetName();
5063  if (gROOT->LoadClass(cls, deplib) == 0) {
5064  if (gDebug > 0) {
5065  Info("TCling::AutoLoad",
5066  "loaded dependent library %s for %s", deplib, cls);
5067  }
5068  }
5069  else {
5070  Error("TCling::AutoLoad",
5071  "failure loading dependent library %s for %s",
5072  deplib, cls);
5073  }
5074  }
5075  const char* lib = ((TObjString*)tokens->At(0))->GetName();
5076  if (lib && lib[0]) {
5077  if (gROOT->LoadClass(cls, lib) == 0) {
5078  if (gDebug > 0) {
5079  Info("TCling::AutoLoad",
5080  "loaded library %s for %s", lib, cls);
5081  }
5082  status = 1;
5083  }
5084  else {
5085  Error("TCling::AutoLoad",
5086  "failure loading library %s for %s", lib, cls);
5087  }
5088  }
5089  delete tokens;
5090  }
5091 
5092  SetClassAutoloading(oldvalue);
5093  return status;
5094 }
5095 
5096 ////////////////////////////////////////////////////////////////////////////////
5097 /// Parse the payload or header.
5098 
5099 static cling::Interpreter::CompilationResult ExecAutoParse(const char *what,
5100  Bool_t header,
5101  cling::Interpreter *interpreter)
5102 {
5103  // Save state of the PP
5104  Sema &SemaR = interpreter->getSema();
5105  ASTContext& C = SemaR.getASTContext();
5106  Preprocessor &PP = SemaR.getPreprocessor();
5107  Parser& P = const_cast<Parser&>(interpreter->getParser());
5108  Preprocessor::CleanupAndRestoreCacheRAII cleanupRAII(PP);
5109  Parser::ParserCurTokRestoreRAII savedCurToken(P);
5110  // After we have saved the token reset the current one to something which
5111  // is safe (semi colon usually means empty decl)
5112  Token& Tok = const_cast<Token&>(P.getCurToken());
5113  Tok.setKind(tok::semi);
5114 
5115  // We can't PushDeclContext, because we go up and the routine that pops
5116  // the DeclContext assumes that we drill down always.
5117  // We have to be on the global context. At that point we are in a
5118  // wrapper function so the parent context must be the global.
5119  Sema::ContextAndScopeRAII pushedDCAndS(SemaR, C.getTranslationUnitDecl(),
5120  SemaR.TUScope);
5121  std::string code = gNonInterpreterClassDef ;
5122  if (!header) {
5123  // This is the complete header file content and not the
5124  // name of a header.
5125  code += what;
5126 
5127  } else {
5128  code += ("#include \"");
5129  code += what;
5130  code += "\"\n";
5131  }
5132  code += ("#ifdef __ROOTCLING__\n"
5133  "#undef __ROOTCLING__\n"
5134  + gInterpreterClassDef +
5135  "#endif");
5136 
5137  cling::Interpreter::CompilationResult cr;
5138  {
5139  // scope within which diagnostics are de-activated
5140  // For now we disable diagnostics because we saw them already at
5141  // dictionary generation time. That won't be an issue with the PCMs.
5142 
5143  clangDiagSuppr diagSuppr(SemaR.getDiagnostics());
5144 
5145  #if defined(R__MUST_REVISIT)
5146  #if R__MUST_REVISIT(6,2)
5147  Warning("TCling::RegisterModule","Diagnostics suppression should be gone by now.");
5148  #endif
5149  #endif
5150 
5151  cr = interpreter->parseForModule(code);
5152  }
5153  return cr;
5154 }
5155 
5156 ////////////////////////////////////////////////////////////////////////////////
5157 /// Helper routine for TCling::AutoParse implementing the actual call to the
5158 /// parser and looping over template parameters (if
5159 /// any) and when they don't have a registered header to autoparse,
5160 /// recurse over their template parameters.
5161 ///
5162 /// Returns the number of header parsed.
5163 
5164 UInt_t TCling::AutoParseImplRecurse(const char *cls, bool topLevel)
5165 {
5166  // We assume the lock has already been taken.
5167  // R__LOCKGUARD(gInterpreterMutex);
5168 
5169  Int_t nHheadersParsed = 0;
5170 
5171  // Loop on the possible autoparse keys
5172  bool skipFirstEntry = false;
5173  std::vector<std::string> autoparseKeys;
5174  if (strchr(cls, '<')) {
5175  int nestedLoc = 0;
5176  TClassEdit::GetSplit(cls, autoparseKeys, nestedLoc, TClassEdit::kDropTrailStar);
5177  // Check if we can skip the name of the template in the autoparses
5178  // Take all the scopes one by one. If all of them are in the AST, we do not
5179  // need to autoparse for that particular template.
5180  if (!autoparseKeys.empty()){
5181  TString templateName(autoparseKeys[0]);
5182  auto tokens = templateName.Tokenize("::");
5183  clang::NamedDecl* previousScopeAsNamedDecl = nullptr;
5184  clang::DeclContext* previousScopeAsContext = nullptr;
5185  for (auto const & scopeObj : *tokens){
5186  auto scopeName = ((TObjString*) scopeObj)->String().Data();
5187  previousScopeAsNamedDecl = cling::utils::Lookup::Named(&fInterpreter->getSema(), scopeName, previousScopeAsContext);
5188  // Check if we have multiple nodes in the AST with this name
5189  if ((clang::NamedDecl*)-1 == previousScopeAsNamedDecl) break;
5190  previousScopeAsContext = llvm::dyn_cast_or_null<clang::DeclContext>(previousScopeAsNamedDecl);
5191  if (!previousScopeAsContext) break; // this is not a context
5192  }
5193  delete tokens;
5194  // Now, let's check if the last scope, the template, has a definition, i.e. it's not a fwd decl
5195  if (auto templateDecl = llvm::dyn_cast_or_null<clang::ClassTemplateDecl>(previousScopeAsNamedDecl)) {
5196  if (auto templatedDecl = templateDecl->getTemplatedDecl()) {
5197  skipFirstEntry = nullptr != templatedDecl->getDefinition();
5198  }
5199  }
5200 
5201  }
5202  }
5203  if (topLevel) autoparseKeys.emplace_back(cls);
5204 
5205  for (const auto & apKeyStr : autoparseKeys) {
5206  if (skipFirstEntry) {
5207  skipFirstEntry=false;
5208  continue;
5209  }
5210  if (apKeyStr.empty()) continue;
5211  const char *apKey = apKeyStr.c_str();
5212  std::size_t normNameHash(fStringHashFunction(apKey));
5213  // If the class was not looked up
5214  if (gDebug > 1) {
5215  Info("TCling::AutoParse",
5216  "Starting autoparse for %s\n", apKey);
5217  }
5218  if (fLookedUpClasses.insert(normNameHash).second) {
5219  auto const &iter = fClassesHeadersMap.find(normNameHash);
5220  if (iter != fClassesHeadersMap.end()) {
5221  const cling::Transaction *T = fInterpreter->getCurrentTransaction();
5222  fTransactionHeadersMap.insert({T,normNameHash});
5223  auto const &hNamesPtrs = iter->second;
5224  if (gDebug > 1) {
5225  Info("TCling::AutoParse",
5226  "We can proceed for %s. We have %s headers.", apKey, std::to_string(hNamesPtrs.size()).c_str());
5227  }
5228  for (auto & hName : hNamesPtrs) {
5229  if (fParsedPayloadsAddresses.count(hName) == 1) continue;
5230  if (0 != fPayloads.count(normNameHash)) {
5231  float initRSSval=0.f, initVSIZEval=0.f;
5232  (void) initRSSval; // Avoid unused var warning
5233  (void) initVSIZEval;
5234  if (gDebug > 0) {
5235  Info("AutoParse",
5236  "Parsing full payload for %s", apKey);
5237  ProcInfo_t info;
5238  gSystem->GetProcInfo(&info);
5239  initRSSval = 1e-3*info.fMemResident;
5240  initVSIZEval = 1e-3*info.fMemVirtual;
5241  }
5242  auto cRes = ExecAutoParse(hName, kFALSE, fInterpreter);
5243  if (cRes != cling::Interpreter::kSuccess) {
5244  if (hName[0] == '\n')
5245  Error("AutoParse", "Error parsing payload code for class %s with content:\n%s", apKey, hName);
5246  } else {
5247  fParsedPayloadsAddresses.insert(hName);
5248  nHheadersParsed++;
5249  if (gDebug > 0){
5250  ProcInfo_t info;
5251  gSystem->GetProcInfo(&info);
5252  float endRSSval = 1e-3*info.fMemResident;
5253  float endVSIZEval = 1e-3*info.fMemVirtual;
5254  Info("Autoparse", ">>> RSS key %s - before %.3f MB - after %.3f MB - delta %.3f MB", apKey, initRSSval, endRSSval, endRSSval-initRSSval);
5255  Info("Autoparse", ">>> VSIZE key %s - before %.3f MB - after %.3f MB - delta %.3f MB", apKey, initVSIZEval, endVSIZEval, endVSIZEval-initVSIZEval);
5256  }
5257  }
5258  } else if (!IsLoaded(hName)) {
5259  if (gDebug > 0) {
5260  Info("AutoParse",
5261  "Parsing single header %s", hName);
5262  }
5263  auto cRes = ExecAutoParse(hName, kTRUE, fInterpreter);
5264  if (cRes != cling::Interpreter::kSuccess) {
5265  Error("AutoParse", "Error parsing headerfile %s for class %s.", hName, apKey);
5266  } else {
5267  nHheadersParsed++;
5268  }
5269  }
5270  }
5271  }
5272  else {
5273  // There is no header registered for this class, if this a
5274  // template, it will be instantiated if/when it is requested
5275  // and if we do no load/parse its components we might end up
5276  // not using an eventual specialization.
5277  if (strchr(apKey, '<')) {
5278  nHheadersParsed += AutoParseImplRecurse(apKey, false);
5279  }
5280  }
5281  }
5282  }
5283 
5284  return nHheadersParsed;
5285 
5286 }
5287 
5288 ////////////////////////////////////////////////////////////////////////////////
5289 /// Parse the headers relative to the class
5290 /// Returns 1 in case of success, 0 in case of failure
5291 
5292 Int_t TCling::AutoParse(const char *cls)
5293 {
5295 
5298  return AutoLoad(cls);
5299  } else {
5300  return 0;
5301  }
5302  }
5303 
5304  if (gDebug > 1) {
5305  Info("TCling::AutoParse",
5306  "Trying to autoparse for %s", cls);
5307  }
5308 
5309  // The catalogue of headers is in the dictionary
5311  AutoLoad(cls);
5312  }
5313 
5314  // Prevent the recursion when the library dictionary are loaded.
5315  Int_t oldAutoloadValue = SetClassAutoloading(false);
5316 
5317  // No recursive header parsing on demand; we require headers to be standalone.
5318  SuspendAutoParsing autoParseRAII(this);
5319 
5320  Int_t nHheadersParsed = AutoParseImplRecurse(cls,/*topLevel=*/ true);
5321 
5322  if (nHheadersParsed != 0) {
5323  while (!fClassesToUpdate.empty()) {
5324  TClass *oldcl = fClassesToUpdate.back().first;
5325  if (oldcl->GetState() != TClass::kHasTClassInit) {
5326  // if (gDebug > 2) Info("RegisterModule", "Forcing TClass init for %s", oldcl->GetName());
5327  DictFuncPtr_t dict = fClassesToUpdate.back().second;
5328  fClassesToUpdate.pop_back();
5329  // Calling func could manipulate the list so, let maintain the list
5330  // then call the dictionary function.
5331  TClass *ncl = dict();
5332  if (ncl) ncl->PostLoadCheck();
5333  } else {
5334  fClassesToUpdate.pop_back();
5335  }
5336  }
5337  }
5338 
5339  SetClassAutoloading(oldAutoloadValue);
5340 
5341  return nHheadersParsed > 0 ? 1 : 0;
5342 }
5343 
5344 
5345 ////////////////////////////////////////////////////////////////////////////////
5346 /// Autoload a library based on a missing symbol.
5347 
5348 void* TCling::LazyFunctionCreatorAutoload(const std::string& mangled_name) {
5349  // First see whether the symbol is in the library that we are currently
5350  // loading. It will have access to the symbols of its dependent libraries,
5351  // thus checking "back()" is sufficient.
5352  if (!fRegisterModuleDyLibs.empty()) {
5353  if (void* addr = dlsym(fRegisterModuleDyLibs.back(),
5354  mangled_name.c_str())) {
5355  return addr;
5356  }
5357  }
5358 
5359  int err = 0;
5360  char* demangled_name_c = TClassEdit::DemangleName(mangled_name.c_str(), err);
5361  if (err) {
5362  return 0;
5363  }
5364 
5365  std::string name(demangled_name_c);
5366  free(demangled_name_c);
5367 
5368  //fprintf(stderr, "demangled name: '%s'\n", demangled_name);
5369  //
5370  // Separate out the class or namespace part of the
5371  // function name.
5372  //
5373 
5374  if (!strncmp(name.c_str(), "typeinfo for ", sizeof("typeinfo for ")-1)) {
5375  name.erase(0, sizeof("typeinfo for ")-1);
5376  } else if (!strncmp(name.c_str(), "vtable for ", sizeof("vtable for ")-1)) {
5377  name.erase(0, sizeof("vtable for ")-1);
5378  } else if (!strncmp(name.c_str(), "operator", sizeof("operator")-1)
5379  && !isalnum(name[sizeof("operator")])) {
5380  // operator...(A, B) - let's try with A!
5381  name.erase(0, sizeof("operator")-1);
5382  std::string::size_type pos = name.rfind('(');
5383  if (pos != std::string::npos) {
5384  name.erase(0, pos + 1);
5385  pos = name.find(",");
5386  if (pos != std::string::npos) {
5387  // remove next arg up to end, leaving only the first argument type.
5388  name.erase(pos);
5389  }
5390  pos = name.rfind(" const");
5391  if (pos != std::string::npos) {
5392  name.erase(pos, strlen(" const"));
5393  }
5394  while (!name.empty() && strchr("&*", name.back()))
5395  name.erase(name.length() - 1);
5396  }
5397  } else {
5398  // Remove the function arguments.
5399  std::string::size_type pos = name.rfind('(');
5400  if (pos != std::string::npos) {
5401  name.erase(pos);
5402  }
5403  // Remove the function name.
5404  pos = name.rfind(':');
5405  if (pos != std::string::npos) {
5406  if ((pos != 0) && (name[pos-1] == ':')) {
5407  name.erase(pos-1);
5408  }
5409  }
5410  }
5411  //fprintf(stderr, "name: '%s'\n", name.c_str());
5412  // Now we have the class or namespace name, so do the lookup.
5413  TString libs = GetClassSharedLibs(name.c_str());
5414  if (libs.IsNull()) {
5415  // Not found in the map, all done.
5416  return 0;
5417  }
5418  //fprintf(stderr, "library: %s\n", iter->second.c_str());
5419  // Now we have the name of the libraries to load, so load them.
5420 
5421  TString lib;
5422  Ssiz_t posLib = 0;
5423  while (libs.Tokenize(lib, posLib)) {
5424  if (gSystem->Load(lib, "", kFALSE /*system*/) < 0) {
5425  // The library load failed, all done.
5426  //fprintf(stderr, "load failed: %s\n", errmsg.c_str());
5427  return 0;
5428  }
5429  }
5430 
5431  //fprintf(stderr, "load succeeded.\n");
5432  // Get the address of the function being called.
5433  void* addr = llvm::sys::DynamicLibrary::SearchForAddressOfSymbol(mangled_name.c_str());
5434  //fprintf(stderr, "addr: %016lx\n", reinterpret_cast<unsigned long>(addr));
5435  return addr;
5436 }
5437 
5438 ////////////////////////////////////////////////////////////////////////////////
5439 
5441 {
5442 // if (fMapNamespaces){
5443 // return fMapNamespaces->FindObject(name);
5444 // }
5445  return false;
5446 }
5447 
5448 ////////////////////////////////////////////////////////////////////////////////
5449 
5450 Bool_t TCling::IsAutoLoadNamespaceCandidate(const clang::NamespaceDecl* nsDecl)
5451 {
5452  return fNSFromRootmaps.count(nsDecl) != 0;
5453 }
5454 
5455 ////////////////////////////////////////////////////////////////////////////////
5456 /// Internal function. Inform a TClass about its new TagDecl or NamespaceDecl.
5457 
5458 void TCling::UpdateClassInfoWithDecl(const void* vTD)
5459 {
5460  const NamedDecl* ND = static_cast<const NamedDecl*>(vTD);
5461  const TagDecl* td = dyn_cast<TagDecl>(ND);
5462  std::string name;
5463  TagDecl* tdDef = 0;
5464  if (td) {
5465  tdDef = td->getDefinition();
5466  // Let's pass the decl to the TClass only if it has a definition.
5467  if (!tdDef) return;
5468  td = tdDef;
5469  ND = td;
5470 
5471  if (llvm::isa<clang::FunctionDecl>(td->getDeclContext())) {
5472  // Ignore declaration within a function.
5473  return;
5474  }
5475  clang::QualType type( td->getTypeForDecl(), 0 );
5476 
5477  auto declName=ND->getNameAsString();
5478  if (!TClass::HasNoInfoOrEmuOrFwdDeclaredDecl(declName.c_str())){
5479 // 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 );
5480  return;
5481  }
5482 
5484  } else {
5485  name = ND->getNameAsString();
5486  }
5487 
5488  // Supposedly we are being called while something is being
5489  // loaded ... let's now tell the autoloader to do the work
5490  // yet another time.
5491  int storedAutoloading = SetClassAutoloading(false);
5492  // FIXME: There can be more than one TClass for a single decl.
5493  // for example vector<double> and vector<Double32_t>
5494  TClass* cl = (TClass*)gROOT->GetListOfClasses()->FindObject(name.c_str());
5495  if (cl && GetModTClasses().find(cl) == GetModTClasses().end()) {
5497  if (cci) {
5498  // If we only had a forward declaration then update the
5499  // TClingClassInfo with the definition if we have it now.
5500  const TagDecl* tdOld = llvm::dyn_cast_or_null<TagDecl>(cci->GetDecl());
5501  if (!tdOld || (tdDef && tdDef != tdOld)) {
5502  cl->ResetCaches();
5504  if (td) {
5505  // It's a tag decl, not a namespace decl.
5506  cci->Init(*cci->GetType());
5508  }
5509  }
5510  } else if (!cl->TestBit(TClass::kLoading) && !cl->fHasRootPcmInfo) {
5511  cl->ResetCaches();
5512  // yes, this is almost a waste of time, but we do need to lookup
5513  // the 'type' corresponding to the TClass anyway in order to
5514  // preserve the opaque typedefs (Double32_t)
5515  cl->fClassInfo = (ClassInfo_t *)new TClingClassInfo(fInterpreter, cl->GetName());
5516  // We now need to update the state and bits.
5517  if (cl->fState != TClass::kHasTClassInit) {
5518  // if (!cl->fClassInfo->IsValid()) cl->fState = TClass::kForwardDeclared; else
5521  }
5522  TClass::AddClassToDeclIdMap(((TClingClassInfo*)(cl->fClassInfo))->GetDeclId(), cl);
5523  }
5524  }
5525  SetClassAutoloading(storedAutoloading);
5526 }
5527 
5528 ////////////////////////////////////////////////////////////////////////////////
5529 /// No op: see TClingCallbacks
5530 
5531 void TCling::UpdateClassInfo(char* item, Long_t tagnum)
5532 {
5533 }
5534 
5535 //______________________________________________________________________________
5536 //FIXME: Factor out that function in TClass, because TClass does it already twice
5537 void TCling::UpdateClassInfoWork(const char* item)
5538 {
5539  // This is a no-op as part of the API.
5540  // TCling uses UpdateClassInfoWithDecl() instead.
5541 }
5542 
5543 ////////////////////////////////////////////////////////////////////////////////
5544 /// Update all canvases at end the terminal input command.
5545 
5547 {
5548  TIter next(gROOT->GetListOfCanvases());
5549  TVirtualPad* canvas;
5550  while ((canvas = (TVirtualPad*)next())) {
5551  canvas->Update();
5552  }
5553 }
5554 
5555 ////////////////////////////////////////////////////////////////////////////////
5556 
5557 void TCling::UpdateListsOnCommitted(const cling::Transaction &T) {
5558  std::set<TClass*> modifiedTClasses; // TClasses that require update after this transaction
5559 
5560  // If the transaction does not contain anything we can return earlier.
5561  if (!HandleNewTransaction(T)) return;
5562 
5563  bool isTUTransaction = false;
5564  if (T.decls_end()-T.decls_begin() == 1 && !T.hasNestedTransactions()) {
5565  clang::Decl* FirstDecl = *(T.decls_begin()->m_DGR.begin());
5566  if (clang::TranslationUnitDecl* TU
5567  = dyn_cast<clang::TranslationUnitDecl>(FirstDecl)) {
5568  // The is the first transaction, we have to expose to meta
5569  // what's already in the AST.
5570  isTUTransaction = true;
5571 
5572  // FIXME: don't load the world. Really, don't. Maybe
5573  // instead smarten TROOT::GetListOfWhateveros() which
5574  // currently is a THashList but could be a
5575  // TInterpreterLookupCollection, one that reimplements
5576  // TCollection::FindObject(name) and performs a lookup
5577  // if not found in its T(Hash)List.
5578  cling::Interpreter::PushTransactionRAII RAII(fInterpreter);
5579  for (clang::DeclContext::decl_iterator TUI = TU->decls_begin(),
5580  TUE = TU->decls_end(); TUI != TUE; ++TUI)
5581  ((TCling*)gCling)->HandleNewDecl(*TUI, (*TUI)->isFromASTFile(),modifiedTClasses);
5582  }
5583  }
5584 
5585  std::set<const void*> TransactionDeclSet;
5586  if (!isTUTransaction && T.decls_end() - T.decls_begin()) {
5587  const clang::Decl* WrapperFD = T.getWrapperFD();
5588  for (cling::Transaction::const_iterator I = T.decls_begin(), E = T.decls_end();
5589  I != E; ++I) {
5590  if (I->m_Call != cling::Transaction::kCCIHandleTopLevelDecl
5591  && I->m_Call != cling::Transaction::kCCIHandleTagDeclDefinition)
5592  continue;
5593 
5594  for (DeclGroupRef::const_iterator DI = I->m_DGR.begin(),
5595  DE = I->m_DGR.end(); DI != DE; ++DI) {
5596  if (*DI == WrapperFD)
5597  continue;
5598  TransactionDeclSet.insert(*DI);
5599  ((TCling*)gCling)->HandleNewDecl(*DI, false, modifiedTClasses);
5600  }
5601  }
5602  }
5603 
5604  // The above might trigger more decls to be deserialized.
5605  // Thus the iteration over the deserialized decls must be last.
5606  for (cling::Transaction::const_iterator I = T.deserialized_decls_begin(),
5607  E = T.deserialized_decls_end(); I != E; ++I) {
5608  for (DeclGroupRef::const_iterator DI = I->m_DGR.begin(),
5609  DE = I->m_DGR.end(); DI != DE; ++DI)
5610  if (TransactionDeclSet.find(*DI) == TransactionDeclSet.end()) {
5611  //FIXME: HandleNewDecl should take DeclGroupRef
5612  ((TCling*)gCling)->HandleNewDecl(*DI, /*isDeserialized*/true,
5613  modifiedTClasses);
5614  }
5615  }
5616 
5617 
5618  // When fully building the reflection info in TClass, a deserialization
5619  // could be triggered, which may result in request for building the
5620  // reflection info for the same TClass. This in turn will clear the caches
5621  // for the TClass in-flight and cause null ptr derefs.
5622  // FIXME: This is a quick fix, solving most of the issues. The actual
5623  // question is: Shouldn't TClass provide a lock mechanism on update or lock
5624  // itself until the update is done.
5625  //
5626  std::vector<TClass*> modifiedTClassesDiff(modifiedTClasses.size());
5627  std::vector<TClass*>::iterator it;
5628  it = set_difference(modifiedTClasses.begin(), modifiedTClasses.end(),
5629  ((TCling*)gCling)->GetModTClasses().begin(),
5630  ((TCling*)gCling)->GetModTClasses().end(),
5631  modifiedTClassesDiff.begin());
5632  modifiedTClassesDiff.resize(it - modifiedTClassesDiff.begin());
5633 
5634  // Lock the TClass for updates
5635  ((TCling*)gCling)->GetModTClasses().insert(modifiedTClassesDiff.begin(),
5636  modifiedTClassesDiff.end());
5637  for (std::vector<TClass*>::const_iterator I = modifiedTClassesDiff.begin(),
5638  E = modifiedTClassesDiff.end(); I != E; ++I) {
5639  // Make sure the TClass has not been deleted.
5640  if (!gROOT->GetListOfClasses()->FindObject(*I)) {
5641  continue;
5642  }
5643  // Could trigger deserialization of decls.
5644  cling::Interpreter::PushTransactionRAII RAII(fInterpreter);
5645  // Unlock the TClass for updates
5646  ((TCling*)gCling)->GetModTClasses().erase(*I);
5647 
5648  }
5649 }
5650 
5651 ////////////////////////////////////////////////////////////////////////////////
5652 /// Helper function to go through the members of a class or namespace and unload them.
5653 
5654 void TCling::UnloadClassMembers(TClass* cl, const clang::DeclContext* DC) {
5655 
5656  TDataMember* var = 0;
5657  TFunction* function = 0;
5658  TEnum* e = 0;
5659  TFunctionTemplate* functiontemplate = 0;
5661  TListOfFunctions* functions = (TListOfFunctions*)cl->GetListOfMethods();
5662  TListOfEnums* enums = (TListOfEnums*)cl->GetListOfEnums();
5664  for (DeclContext::decl_iterator RI = DC->decls_begin(), RE = DC->decls_end(); RI != RE; ++RI) {
5665  if (isa<VarDecl>(*RI) || isa<FieldDecl>(*RI)) {
5666  const clang::ValueDecl* VD = dyn_cast<ValueDecl>(*RI);
5667  var = (TDataMember*)datamembers->FindObject(VD->getNameAsString().c_str());
5668  if (var) {
5669  // Unload the global by setting the DataMemberInfo_t to 0
5670  datamembers->Unload(var);
5671  var->Update(0);
5672  }
5673  } else if (const FunctionDecl* FD = dyn_cast<FunctionDecl>(*RI)) {
5674  function = (TFunction*)functions->FindObject(FD->getNameAsString().c_str());
5675  if (function) {
5676  functions->Unload(function);
5677  function->Update(0);
5678  }
5679  } else if (const EnumDecl* ED = dyn_cast<EnumDecl>(*RI)) {
5680  e = (TEnum*)enums->FindObject(ED->getNameAsString().c_str());
5681  if (e) {
5682  TIter iEnumConst(e->GetConstants());
5683  while (TEnumConstant* enumConst = (TEnumConstant*)iEnumConst()) {
5684  // Since the enum is already created and valid that ensures us that
5685  // we have the enum constants created as well.
5686  enumConst = (TEnumConstant*)datamembers->FindObject(enumConst->GetName());
5687  if (enumConst && enumConst->IsValid()) {
5688  datamembers->Unload(enumConst);
5689  enumConst->Update(0);
5690  }
5691  }
5692  enums->Unload(e);
5693  e->Update(0);
5694  }
5695  } else if (const FunctionTemplateDecl* FTD = dyn_cast<FunctionTemplateDecl>(*RI)) {
5696  functiontemplate = (TFunctionTemplate*)functiontemplates->FindObject(FTD->getNameAsString().c_str());
5697  if (functiontemplate) {
5698  functiontemplates->Unload(functiontemplate);
5699  functiontemplate->Update(0);
5700  }
5701  }
5702  }
5703 }
5704 
5705 ////////////////////////////////////////////////////////////////////////////////
5706 
5707 void TCling::UpdateListsOnUnloaded(const cling::Transaction &T)
5708 {
5710 
5711  // Unload the objects from the lists and update the objects' state.
5712  TListOfFunctions* functions = (TListOfFunctions*)gROOT->GetListOfGlobalFunctions();
5713  TListOfFunctionTemplates* functiontemplates = (TListOfFunctionTemplates*)gROOT->GetListOfFunctionTemplates();
5714  TListOfEnums* enums = (TListOfEnums*)gROOT->GetListOfEnums();
5715  TListOfDataMembers* globals = (TListOfDataMembers*)gROOT->GetListOfGlobals();
5716  cling::Transaction::const_nested_iterator iNested = T.nested_begin();
5717  for(cling::Transaction::const_iterator I = T.decls_begin(), E = T.decls_end();
5718  I != E; ++I) {
5719  if (I->m_Call == cling::Transaction::kCCIHandleVTable)
5720  continue;
5721 
5722  if (I->m_Call == cling::Transaction::kCCINone) {
5723  UpdateListsOnUnloaded(**iNested);
5724  ++iNested;
5725  continue;
5726  }
5727 
5728  for (DeclGroupRef::const_iterator DI = I->m_DGR.begin(),
5729  DE = I->m_DGR.end(); DI != DE; ++DI) {
5730 
5731  // Do not mark a decl as unloaded if we are going to keep it
5732  // (because it comes from the pch) ...
5733  if ( (*DI)->isFromASTFile() )
5734  continue;
5735 
5736  // Deal with global variables and global enum constants.
5737  if (isa<VarDecl>(*DI) || isa<EnumConstantDecl>(*DI)) {
5738  TObject *obj = globals->Find((TListOfDataMembers::DeclId_t)*DI);
5739  if (globals->GetClass()) {
5740  TDataMember* var = dynamic_cast<TDataMember*>(obj);
5741  if (var && var->IsValid()) {
5742  // Unload the global by setting the DataMemberInfo_t to 0
5743  globals->Unload(var);
5744  var->Update(0);
5745  }
5746  } else {
5747  TGlobal *g = dynamic_cast<TGlobal*>(obj);
5748  if (g && g->IsValid()) {
5749  // Unload the global by setting the DataMemberInfo_t to 0
5750  globals->Unload(g);
5751  g->Update(0);
5752  }
5753  }
5754  // Deal with global functions.
5755  } else if (const FunctionDecl* FD = dyn_cast<FunctionDecl>(*DI)) {
5756  TFunction* function = (TFunction*)functions->Find((TListOfFunctions::DeclId_t)FD);
5757  if (function && function->IsValid()) {
5758  functions->Unload(function);
5759  function->Update(0);
5760  }
5761  // Deal with global function templates.
5762  } else if (const FunctionTemplateDecl* FTD = dyn_cast<FunctionTemplateDecl>(*DI)) {
5763  TFunctionTemplate* functiontemplate = (TFunctionTemplate*)functiontemplates->FindObject(FTD->getNameAsString().c_str());
5764  if (functiontemplate) {
5765  functiontemplates->Unload(functiontemplate);
5766  functiontemplate->Update(0);
5767  }
5768  // Deal with global enums.
5769  } else if (const EnumDecl* ED = dyn_cast<EnumDecl>(*DI)) {
5770  if (TEnum* e = (TEnum*)enums->Find((TListOfEnums::DeclId_t)ED)) {
5771  globals = (TListOfDataMembers*)gROOT->GetListOfGlobals();
5772  TIter iEnumConst(e->GetConstants());
5773  while (TEnumConstant* enumConst = (TEnumConstant*)iEnumConst()) {
5774  // Since the enum is already created and valid that ensures us that
5775  // we have the enum constants created as well.
5776  enumConst = (TEnumConstant*)globals->FindObject(enumConst->GetName());
5777  if (enumConst) {
5778  globals->Unload(enumConst);
5779  enumConst->Update(0);
5780  }
5781  }
5782  enums->Unload(e);
5783  e->Update(0);
5784  }
5785  // Deal with classes. Unload the class and the data members will be not accessible anymore
5786  // Cannot declare the members in a different declaration like redeclarable namespaces.
5787  } else if (const clang::RecordDecl* RD = dyn_cast<RecordDecl>(*DI)) {
5788  std::vector<TClass*> vectTClass;
5789  // Only update the TClass if the definition is being unloaded.
5790  if (RD->isCompleteDefinition()) {
5791  if (TClass::GetClass(RD, vectTClass)) {
5792  for (std::vector<TClass*>::iterator CI = vectTClass.begin(), CE = vectTClass.end();
5793  CI != CE; ++CI) {
5794  UnloadClassMembers((*CI), RD);
5795  (*CI)->ResetClassInfo();
5796  }
5797  }
5798  }
5799  // Deal with namespaces. Unload the members of the current redeclaration only.
5800  } else if (const clang::NamespaceDecl* ND = dyn_cast<NamespaceDecl>(*DI)) {
5801  std::vector<TClass*> vectTClass;
5802  if (TClass::GetClass(ND->getCanonicalDecl(), vectTClass)) {
5803  for (std::vector<TClass*>::iterator CI = vectTClass.begin(), CE = vectTClass.end();
5804  CI != CE; ++CI) {
5805  UnloadClassMembers((*CI), ND);
5806  if (ND->isOriginalNamespace()) {
5807  (*CI)->ResetClassInfo();
5808  }
5809  }
5810  }
5811  }
5812  }
5813  }
5814 }
5815 
5816 ////////////////////////////////////////////////////////////////////////////////
5817 // If an autoparse was done during a transaction and that it is rolled back,
5818 // we need to make sure the next request for the same autoparse will be
5819 // honored.
5820 void TCling::TransactionRollback(const cling::Transaction &T) {
5821  auto const &triter = fTransactionHeadersMap.find(&T);
5822  if (triter != fTransactionHeadersMap.end()) {
5823  std::size_t normNameHash = triter->second;
5824 
5825  fLookedUpClasses.erase(normNameHash);
5826 
5827  auto const &iter = fClassesHeadersMap.find(normNameHash);
5828  if (iter != fClassesHeadersMap.end()) {
5829  auto const &hNamesPtrs = iter->second;
5830  for (auto &hName : hNamesPtrs) {
5831  if (gDebug > 0) {
5832  Info("TransactionRollback",
5833  "Restoring ability to autoaparse: %s", hName);
5834  }
5835  fParsedPayloadsAddresses.erase(hName);
5836  }
5837  }
5838  }
5839 }
5840 
5841 ////////////////////////////////////////////////////////////////////////////////
5842 
5843 void TCling::LibraryLoaded(const void* dyLibHandle, const char* canonicalName) {
5844 // UpdateListOfLoadedSharedLibraries();
5845 }
5846 
5847 ////////////////////////////////////////////////////////////////////////////////
5848 
5849 void TCling::LibraryUnloaded(const void* dyLibHandle, const char* canonicalName) {
5851  fSharedLibs = "";
5852 }
5853 
5854 ////////////////////////////////////////////////////////////////////////////////
5855 /// Return the list of shared libraries loaded into the process.
5856 
5858 {
5861  return fSharedLibs;
5862 }
5863 
5864 ////////////////////////////////////////////////////////////////////////////////
5865 /// Get the list of shared libraries containing the code for class cls.
5866 /// The first library in the list is the one containing the class, the
5867 /// others are the libraries the first one depends on. Returns 0
5868 /// in case the library is not found.
5869 
5870 const char* TCling::GetClassSharedLibs(const char* cls)
5871 {
5872  if (!cls || !*cls) {
5873  return 0;
5874  }
5875  // lookup class to find list of libraries
5876  if (fMapfile) {
5877  TEnvRec* libs_record = 0;
5878  libs_record = fMapfile->Lookup(cls);
5879  if (libs_record) {
5880  const char* libs = libs_record->GetValue();
5881  return (*libs) ? libs : 0;
5882  }
5883  else {
5884  // Try the old format...
5885  TString c = TString("Library.") + cls;
5886  // convert "::" to "@@", we used "@@" because TEnv
5887  // considers "::" a terminator
5888  c.ReplaceAll("::", "@@");
5889  // convert "-" to " ", since class names may have
5890  // blanks and TEnv considers a blank a terminator
5891  c.ReplaceAll(" ", "-");
5892  // Use TEnv::Lookup here as the rootmap file must start with Library.
5893  // and do not support using any stars (so we do not need to waste time
5894  // with the search made by TEnv::GetValue).
5895  TEnvRec* libs_record = 0;
5896  libs_record = fMapfile->Lookup(c);
5897  if (libs_record) {
5898  const char* libs = libs_record->GetValue();
5899  return (*libs) ? libs : 0;
5900  }
5901  }
5902  }
5903  return 0;
5904 }
5905 
5906 ////////////////////////////////////////////////////////////////////////////////
5907 /// Get the list a libraries on which the specified lib depends. The
5908 /// returned string contains as first element the lib itself.
5909 /// Returns 0 in case the lib does not exist or does not have
5910 /// any dependencies.
5911 
5912 const char* TCling::GetSharedLibDeps(const char* lib)
5913 {
5914  if (!fMapfile || !lib || !lib[0]) {
5915  return 0;
5916  }
5917  TString libname(lib);
5918  Ssiz_t idx = libname.Last('.');
5919  if (idx != kNPOS) {
5920  libname.Remove(idx);
5921  }
5922  TEnvRec* rec;
5923  TIter next(fMapfile->GetTable());
5924  size_t len = libname.Length();
5925  while ((rec = (TEnvRec*) next())) {
5926  const char* libs = rec->GetValue();
5927  if (!strncmp(libs, libname.Data(), len) && strlen(libs) >= len
5928  && (!libs[len] || libs[len] == ' ' || libs[len] == '.')) {
5929  return libs;
5930  }
5931  }
5932  return 0;
5933 }
5934 
5935 ////////////////////////////////////////////////////////////////////////////////
5936 /// If error messages are disabled, the interpreter should suppress its
5937 /// failures and warning messages from stdout.
5938 
5940 {
5941 #if defined(R__MUST_REVISIT)
5942 #if R__MUST_REVISIT(6,2)
5943  Warning("IsErrorMessagesEnabled", "Interface not available yet.");
5944 #endif
5945 #endif
5946  return kTRUE;
5947 }
5948 
5949 ////////////////////////////////////////////////////////////////////////////////
5950 /// If error messages are disabled, the interpreter should suppress its
5951 /// failures and warning messages from stdout. Return the previous state.
5952 
5954 {
5955 #if defined(R__MUST_REVISIT)
5956 #if R__MUST_REVISIT(6,2)
5957  Warning("SetErrorMessages", "Interface not available yet.");
5958 #endif
5959 #endif
5961 }
5962 
5963 ////////////////////////////////////////////////////////////////////////////////
5964 /// Refresh the list of include paths known to the interpreter and return it
5965 /// with -I prepended.
5966 
5968 {
5970 
5971  fIncludePath = "";
5972 
5973  llvm::SmallVector<std::string, 10> includePaths;//Why 10? Hell if I know.
5974  //false - no system header, true - with flags.
5975  fInterpreter->GetIncludePaths(includePaths, false, true);
5976  if (const size_t nPaths = includePaths.size()) {
5977  assert(!(nPaths & 1) && "GetIncludePath, number of paths and options is not equal");
5978 
5979  for (size_t i = 0; i < nPaths; i += 2) {
5980  if (i)
5981  fIncludePath.Append(' ');
5982  fIncludePath.Append(includePaths[i].c_str());
5983 
5984  if (includePaths[i] != "-I")
5985  fIncludePath.Append(' ');
5986  fIncludePath.Append('"');
5987  fIncludePath.Append(includePaths[i + 1], includePaths[i + 1].length());
5988  fIncludePath.Append('"');
5989  }
5990  }
5991 
5992  return fIncludePath;
5993 }
5994 
5995 ////////////////////////////////////////////////////////////////////////////////
5996 /// Return the directory containing CINT's stl cintdlls.
5997 
5998 const char* TCling::GetSTLIncludePath() const
5999 {
6000  return "";
6001 }
6002 
6003 //______________________________________________________________________________
6004 // M I S C
6005 //______________________________________________________________________________
6006 
6007 int TCling::DisplayClass(FILE* /*fout*/, const char* /*name*/, int /*base*/, int /*start*/) const
6008 {
6009  // Interface to cling function
6010  return 0;
6011 }
6012 
6013 ////////////////////////////////////////////////////////////////////////////////
6014 /// Interface to cling function
6015 
6016 int TCling::DisplayIncludePath(FILE *fout) const
6017 {
6018  assert(fout != 0 && "DisplayIncludePath, 'fout' parameter is null");
6019 
6020  llvm::SmallVector<std::string, 10> includePaths;//Why 10? Hell if I know.
6021  //false - no system header, true - with flags.
6022  fInterpreter->GetIncludePaths(includePaths, false, true);
6023  if (const size_t nPaths = includePaths.size()) {
6024  assert(!(nPaths & 1) && "DisplayIncludePath, number of paths and options is not equal");
6025 
6026  std::string allIncludes("include path:");
6027  for (size_t i = 0; i < nPaths; i += 2) {
6028  allIncludes += ' ';
6029  allIncludes += includePaths[i];
6030 
6031  if (includePaths[i] != "-I")
6032  allIncludes += ' ';
6033  allIncludes += includePaths[i + 1];
6034  }
6035 
6036  fprintf(fout, "%s\n", allIncludes.c_str());
6037  }
6038 
6039  return 0;
6040 }
6041 
6042 ////////////////////////////////////////////////////////////////////////////////
6043 /// Interface to cling function
6044 
6045 void* TCling::FindSym(const char* entry) const
6046 {
6047  return fInterpreter->getAddressOfGlobal(entry);
6048 }
6049 
6050 ////////////////////////////////////////////////////////////////////////////////
6051 /// Let the interpreter issue a generic error, and set its error state.
6052 
6053 void TCling::GenericError(const char* error) const
6054 {
6055 #if defined(R__MUST_REVISIT)
6056 #if R__MUST_REVISIT(6,2)
6057  Warning("GenericError","Interface not available yet.");
6058 #endif
6059 #endif
6060 }
6061 
6062 ////////////////////////////////////////////////////////////////////////////////
6063 /// This routines used to return the address of the internal wrapper
6064 /// function (of the interpreter) that was used to call *all* the
6065 /// interpreted functions that were bytecode compiled (no longer
6066 /// interpreted line by line). In Cling, there is no such
6067 /// wrapper function.
6068 /// In practice this routines was use to decipher whether the
6069 /// pointer returns by InterfaceMethod could be used to uniquely
6070 /// represent the function. In Cling if the function is in a
6071 /// useable state (its compiled version is available), this is
6072 /// always the case.
6073 /// See TClass::GetMethod.
6074 
6076 {
6077  return 0;
6078 }
6079 
6080 ////////////////////////////////////////////////////////////////////////////////
6081 /// Interface to the CINT global object pointer which was controlling the
6082 /// behavior of the wrapper around the calls to operator new and the constructor
6083 /// and operator delete and the destructor.
6084 
6086 {
6087  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.");
6088  return 0;
6089 }
6090 
6091 ////////////////////////////////////////////////////////////////////////////////
6092 
6093 const char* TCling::Getp2f2funcname(void*) const
6094 {
6095  Error("Getp2f2funcname", "Will not be implemented: "
6096  "all function pointers are compiled!");
6097  return NULL;
6098 }
6099 
6100 ////////////////////////////////////////////////////////////////////////////////
6101 /// Interface to cling function
6102 
6104 {
6105 #if defined(R__MUST_REVISIT)
6106 #if R__MUST_REVISIT(6,2)
6107  Warning("GetSecurityError", "Interface not available yet.");
6108 #endif
6109 #endif
6110  return 0;
6111 }
6112 
6113 ////////////////////////////////////////////////////////////////////////////////
6114 /// Load a source file or library called path into the interpreter.
6115 
6116 int TCling::LoadFile(const char* path) const
6117 {
6118  cling::Interpreter::CompilationResult compRes;
6119  cling::MetaProcessor::MaybeRedirectOutputRAII RAII(fMetaProcessor);
6120  fMetaProcessor->process(TString::Format(".L %s", path), compRes, /*cling::Value*/0);
6121  return compRes == cling::Interpreter::kFailure;
6122 }
6123 
6124 ////////////////////////////////////////////////////////////////////////////////
6125 /// Load the declarations from text into the interpreter.
6126 /// Note that this cannot be (top level) statements; text must contain
6127 /// top level declarations.
6128 /// Returns true on success, false on failure.
6129 
6130 Bool_t TCling::LoadText(const char* text) const
6131 {
6132  return (fInterpreter->declare(text) == cling::Interpreter::kSuccess);
6133 }
6134 
6135 ////////////////////////////////////////////////////////////////////////////////
6136 /// Interface to cling function
6137 
6138 const char* TCling::MapCppName(const char* name) const
6139 {
6140  TTHREAD_TLS_DECL(std::string,buffer);
6141  ROOT::TMetaUtils::GetCppName(buffer,name);
6142  return buffer.c_str();
6143 }
6144 
6145 ////////////////////////////////////////////////////////////////////////////////
6146 /// [Place holder for Mutex Lock]
6147 /// Provide the interpreter with a way to
6148 /// acquire a lock used to protect critical section
6149 /// of its code (non-thread safe parts).
6150 
6151 void TCling::SetAlloclockfunc(void (* /* p */ )()) const
6152 {
6153  // nothing to do for now.
6154 }
6155 
6156 ////////////////////////////////////////////////////////////////////////////////
6157 /// [Place holder for Mutex Unlock] Provide the interpreter with a way to
6158 /// release a lock used to protect critical section
6159 /// of its code (non-thread safe parts).
6160 
6161 void TCling::SetAllocunlockfunc(void (* /* p */ )()) const
6162 {
6163  // nothing to do for now.
6164 }
6165 
6166 ////////////////////////////////////////////////////////////////////////////////
6167 /// Enable/Disable the Autoloading of libraries.
6168 /// Returns the old value, i.e whether it was enabled or not.
6169 
6170 int TCling::SetClassAutoloading(int autoload) const
6171 {
6172  if (!autoload && !fClingCallbacks) return false;
6173  if (!fAllowLibLoad) return false;
6174 
6175  assert(fClingCallbacks && "We must have callbacks!");
6176  bool oldVal = fClingCallbacks->IsAutoloadingEnabled();
6178  return oldVal;
6179 }
6180 
6181 ////////////////////////////////////////////////////////////////////////////////
6182 /// Enable/Disable the Autoparsing of headers.
6183 /// Returns the old value, i.e whether it was enabled or not.
6184 
6186 {
6187  bool oldVal = fHeaderParsingOnDemand;
6188  fHeaderParsingOnDemand = autoparse;
6189  return oldVal;
6190 }
6191 
6192 ////////////////////////////////////////////////////////////////////////////////
6193 /// Suspend the Autoparsing of headers.
6194 /// Returns the old value, i.e whether it was suspended or not.
6195 
6200  return old;
6201 }
6202 
6203 ////////////////////////////////////////////////////////////////////////////////
6204 /// Set a callback to receive error messages.
6205 
6206 void TCling::SetErrmsgcallback(void* p) const
6207 {
6208 #if defined(R__MUST_REVISIT)
6209 #if R__MUST_REVISIT(6,2)
6210  Warning("SetErrmsgcallback", "Interface not available yet.");
6211 #endif
6212 #endif
6213 }
6214 
6215 ////////////////////////////////////////////////////////////////////////////////
6216 /// Interface to the cling global object pointer which was controlling the
6217 /// behavior of the wrapper around the calls to operator new and the constructor
6218 /// and operator delete and the destructor.
6219 
6220 void TCling::Setgvp(Long_t gvp) const
6221 {
6222  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.");
6223 
6224 }
6225 
6226 ////////////////////////////////////////////////////////////////////////////////
6227 
6229 {
6230  Error("SetRTLD_NOW()", "Will never be implemented! Don't use!");
6231 }
6232 
6233 ////////////////////////////////////////////////////////////////////////////////
6234 
6236 {
6237  Error("SetRTLD_LAZY()", "Will never be implemented! Don't use!");
6238 }
6239 
6240 ////////////////////////////////////////////////////////////////////////////////
6241 /// Create / close a scope for temporaries. No-op for cling; use
6242 /// cling::Value instead.
6243 
6244 void TCling::SetTempLevel(int val) const
6245 {
6246 }
6247 
6248 ////////////////////////////////////////////////////////////////////////////////
6249 
6250 int TCling::UnloadFile(const char* path) const
6251 {
6252  cling::DynamicLibraryManager* DLM = fInterpreter->getDynamicLibraryManager();
6253  std::string canonical = DLM->lookupLibrary(path);
6254  if (canonical.empty()) {
6255  canonical = path;
6256  }
6257  // Unload a shared library or a source file.
6258  cling::Interpreter::CompilationResult compRes;
6259  cling::MetaProcessor::MaybeRedirectOutputRAII RAII(fMetaProcessor);
6260  fMetaProcessor->process(Form(".U %s", canonical.c_str()), compRes, /*cling::Value*/0);
6261  return compRes == cling::Interpreter::kFailure;
6262 }
6263 
6264 ////////////////////////////////////////////////////////////////////////////////
6265 /// The created temporary must be deleted by the caller.
6266 
6268 {
6269  TClingValue *val = new TClingValue;
6270  return val;
6271 }
6272 
6273 ////////////////////////////////////////////////////////////////////////////////
6274 
6276 {
6277  using namespace cling;
6278  const Value* V = reinterpret_cast<const Value*>(value.GetValAddr());
6279  RegisterTemporary(*V);
6280 }
6281 
6282 ////////////////////////////////////////////////////////////////////////////////
6283 /// Register value as a temporary, extending its lifetime to that of the
6284 /// interpreter. This is needed for TCling's compatibility interfaces
6285 /// returning long - the address of the temporary objects.
6286 /// As such, "simple" types don't need to be stored; they are returned by
6287 /// value; only pointers / references / objects need to be stored.
6288 
6290 {
6291  if (value.isValid() && value.needsManagedAllocation()) {
6293  fTemporaries->push_back(value);
6294  }
6295 }
6296 
6297 ////////////////////////////////////////////////////////////////////////////////
6298 /// If the interpreter encounters Name, check whether that is an object ROOT
6299 /// could retrieve. To not re-read objects from disk, cache the name/object
6300 /// pair for a given LookupCtx.
6301 
6302 TObject* TCling::GetObjectAddress(const char *Name, void *&LookupCtx)
6303 {
6304  cling::Interpreter *interpreter = ((TCling*)gCling)->GetInterpreter();
6305 
6306  // The call to FindSpecialObject might induces any kind of use
6307  // of the interpreter ... (library loading, function calling, etc.)
6308  // ... and we _know_ we are in the middle of parsing, so let's make
6309  // sure to save the state and then restore it.
6310 
6311  if (gDirectory) {
6312  auto iSpecObjMap = fSpecialObjectMaps.find(gDirectory);
6313  if (iSpecObjMap != fSpecialObjectMaps.end()) {
6314  auto iSpecObj = iSpecObjMap->second.find(Name);
6315  if (iSpecObj != iSpecObjMap->second.end()) {
6316  LookupCtx = gDirectory;
6317  return iSpecObj->second;
6318  }
6319  }
6320  }
6321 
6322  // Save state of the PP
6323  Sema &SemaR = interpreter->getSema();
6324  ASTContext& C = SemaR.getASTContext();
6325  Preprocessor &PP = SemaR.getPreprocessor();
6326  Parser& P = const_cast<Parser&>(interpreter->getParser());
6327  Preprocessor::CleanupAndRestoreCacheRAII cleanupRAII(PP);
6328  Parser::ParserCurTokRestoreRAII savedCurToken(P);
6329  // After we have saved the token reset the current one to something which
6330  // is safe (semi colon usually means empty decl)
6331  Token& Tok = const_cast<Token&>(P.getCurToken());
6332  Tok.setKind(tok::semi);
6333 
6334  // We can't PushDeclContext, because we go up and the routine that pops
6335  // the DeclContext assumes that we drill down always.
6336  // We have to be on the global context. At that point we are in a
6337  // wrapper function so the parent context must be the global.
6338  Sema::ContextAndScopeRAII pushedDCAndS(SemaR, C.getTranslationUnitDecl(),
6339  SemaR.TUScope);
6340 
6341  TObject* specObj = gROOT->FindSpecialObject(Name, LookupCtx);
6342  if (specObj) {
6343  if (!LookupCtx) {
6344  Error("GetObjectAddress", "Got a special object without LookupCtx!");
6345  } else {
6346  fSpecialObjectMaps[LookupCtx][Name] = specObj;
6347  }
6348  }
6349  return specObj;
6350 }
6351 
6352 ////////////////////////////////////////////////////////////////////////////////
6353 /// Inject function as a friend into klass.
6354 /// With function being f in void f() {new N::PrivKlass(); } this enables
6355 /// I/O of non-public classes.
6356 
6357 void TCling::AddFriendToClass(clang::FunctionDecl* function,
6358  clang::CXXRecordDecl* klass) const
6359 {
6360  using namespace clang;
6361  ASTContext& Ctx = klass->getASTContext();
6362  FriendDecl::FriendUnion friendUnion(function);
6363  // one dummy object for the source location
6364  SourceLocation sl;
6365  FriendDecl* friendDecl = FriendDecl::Create(Ctx, klass, sl, friendUnion, sl);
6366  klass->pushFriendDecl(friendDecl);
6367 }
6368 
6369 //______________________________________________________________________________
6370 //
6371 // DeclId getter.
6372 //
6373 
6374 ////////////////////////////////////////////////////////////////////////////////
6375 /// Return a unique identifier of the declaration represented by the
6376 /// CallFunc
6377 
6379 {
6380  if (func) return ((TClingCallFunc*)func)->GetDecl()->getCanonicalDecl();
6381  return 0;
6382 }
6383 
6384 ////////////////////////////////////////////////////////////////////////////////
6385 /// Return a (almost) unique identifier of the declaration represented by the
6386 /// ClassInfo. In ROOT, this identifier can point to more than one TClass
6387 /// when the underlying class is a template instance involving one of the
6388 /// opaque typedef.
6389 
6391 {
6392  if (cinfo) return ((TClingClassInfo*)cinfo)->GetDeclId();
6393  return 0;
6394 }
6395 
6396 ////////////////////////////////////////////////////////////////////////////////
6397 /// Return a unique identifier of the declaration represented by the
6398 /// MethodInfo
6399 
6400 TInterpreter::DeclId_t TCling::GetDeclId(DataMemberInfo_t* data) const
6401 {
6402  if (data) return ((TClingDataMemberInfo*)data)->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(MethodInfo_t* method) const
6411 {
6412  if (method) return ((TClingMethodInfo*)method)->GetDeclId();
6413  return 0;
6414 }
6415 
6416 ////////////////////////////////////////////////////////////////////////////////
6417 /// Return a unique identifier of the declaration represented by the
6418 /// TypedefInfo
6419 
6420 TInterpreter::DeclId_t TCling::GetDeclId(TypedefInfo_t* tinfo) const
6421 {
6422  if (tinfo) return ((TClingTypedefInfo*)tinfo)->GetDecl()->getCanonicalDecl();
6423  return 0;
6424 }
6425 
6426 //______________________________________________________________________________
6427 //
6428 // CallFunc interface
6429 //
6430 
6431 ////////////////////////////////////////////////////////////////////////////////
6432 
6433 void TCling::CallFunc_Delete(CallFunc_t* func) const
6434 {
6435  delete (TClingCallFunc*) func;
6436 }
6437 
6438 ////////////////////////////////////////////////////////////////////////////////
6439 
6440 void TCling::CallFunc_Exec(CallFunc_t* func, void* address) const
6441 {
6442  TClingCallFunc* f = (TClingCallFunc*) func;
6443  f->Exec(address);
6444 }
6445 
6446 ////////////////////////////////////////////////////////////////////////////////
6447 
6448 void TCling::CallFunc_Exec(CallFunc_t* func, void* address, TInterpreterValue& val) const
6449 {
6450  TClingCallFunc* f = (TClingCallFunc*) func;
6451  f->Exec(address, &val);
6452 }
6453 
6454 ////////////////////////////////////////////////////////////////////////////////
6455 
6456 void TCling::CallFunc_ExecWithReturn(CallFunc_t* func, void* address, void* ret) const
6457 {
6458  TClingCallFunc* f = (TClingCallFunc*) func;
6459  f->ExecWithReturn(address, ret);
6460 }
6461 
6462 ////////////////////////////////////////////////////////////////////////////////
6463 
6464 void TCling::CallFunc_ExecWithArgsAndReturn(CallFunc_t* func, void* address,
6465  const void* args[] /*=0*/,
6466  int nargs /*=0*/,
6467  void* ret/*=0*/) const
6468 {
6469  TClingCallFunc* f = (TClingCallFunc*) func;
6470  f->ExecWithArgsAndReturn(address, args, nargs, ret);
6471 }
6472 
6473 ////////////////////////////////////////////////////////////////////////////////
6474 
6475 Long_t TCling::CallFunc_ExecInt(CallFunc_t* func, void* address) const
6476 {
6477  TClingCallFunc* f = (TClingCallFunc*) func;
6478  return f->ExecInt(address);
6479 }
6480 
6481 ////////////////////////////////////////////////////////////////////////////////
6482 
6483 Long64_t TCling::CallFunc_ExecInt64(CallFunc_t* func, void* address) const
6484 {
6485  TClingCallFunc* f = (TClingCallFunc*) func;
6486  return f->ExecInt64(address);
6487 }
6488 
6489 ////////////////////////////////////////////////////////////////////////////////
6490 
6491 Double_t TCling::CallFunc_ExecDouble(CallFunc_t* func, void* address) const
6492 {
6493  TClingCallFunc* f = (TClingCallFunc*) func;
6494  return f->ExecDouble(address);
6495 }
6496 
6497 ////////////////////////////////////////////////////////////////////////////////
6498 
6499 CallFunc_t* TCling::CallFunc_Factory() const
6500 {
6502  return (CallFunc_t*) new TClingCallFunc(fInterpreter,*fNormalizedCtxt);
6503 }
6504 
6505 ////////////////////////////////////////////////////////////////////////////////
6506 
6507 CallFunc_t* TCling::CallFunc_FactoryCopy(CallFunc_t* func) const
6508 {
6509  return (CallFunc_t*) new TClingCallFunc(*(TClingCallFunc*)func);
6510 }
6511 
6512 ////////////////////////////////////////////////////////////////////////////////
6513 
6514 MethodInfo_t* TCling::CallFunc_FactoryMethod(CallFunc_t* func) const
6515 {
6516  TClingCallFunc* f = (TClingCallFunc*) func;
6517  return (MethodInfo_t*) f->FactoryMethod();
6518 }
6519 
6520 ////////////////////////////////////////////////////////////////////////////////
6521 
6522 void TCling::CallFunc_IgnoreExtraArgs(CallFunc_t* func, bool ignore) const
6523 {
6524  TClingCallFunc* f = (TClingCallFunc*) func;
6525  f->IgnoreExtraArgs(ignore);
6526 }
6527 
6528 ////////////////////////////////////////////////////////////////////////////////
6529 
6530 void TCling::CallFunc_Init(CallFunc_t* func) const
6531 {
6533  TClingCallFunc* f = (TClingCallFunc*) func;
6534  f->Init();
6535 }
6536 
6537 ////////////////////////////////////////////////////////////////////////////////
6538 
6539 bool TCling::CallFunc_IsValid(CallFunc_t* func) const
6540 {
6541  TClingCallFunc* f = (TClingCallFunc*) func;
6542  return f->IsValid();
6543 }
6544 
6545 ////////////////////////////////////////////////////////////////////////////////
6546 
6548 TCling::CallFunc_IFacePtr(CallFunc_t * func) const
6549 {
6550  TClingCallFunc* f = (TClingCallFunc*) func;
6551  return f->IFacePtr();
6552 }
6553 
6554 ////////////////////////////////////////////////////////////////////////////////
6555 
6556 void TCling::CallFunc_ResetArg(CallFunc_t* func) const
6557 {
6558  TClingCallFunc* f = (TClingCallFunc*) func;
6559  f->ResetArg();
6560 }
6561 
6562 ////////////////////////////////////////////////////////////////////////////////
6563 
6564 void TCling::CallFunc_SetArg(CallFunc_t* func, Long_t param) const
6565 {
6566  TClingCallFunc* f = (TClingCallFunc*) func;
6567  f->SetArg(param);
6568 }
6569 
6570 ////////////////////////////////////////////////////////////////////////////////
6571 
6572 void TCling::CallFunc_SetArg(CallFunc_t* func, ULong_t param) const
6573 {
6574  TClingCallFunc* f = (TClingCallFunc*) func;
6575  f->SetArg(param);
6576 }
6577 
6578 ////////////////////////////////////////////////////////////////////////////////
6579 
6580 void TCling::CallFunc_SetArg(CallFunc_t* func, Float_t param) const
6581 {
6582  TClingCallFunc* f = (TClingCallFunc*) func;
6583  f->SetArg(param);
6584 }
6585 
6586 ////////////////////////////////////////////////////////////////////////////////
6587 
6588 void TCling::CallFunc_SetArg(CallFunc_t* func, Double_t param) const
6589 {
6590  TClingCallFunc* f = (TClingCallFunc*) func;
6591  f->SetArg(param);
6592 }
6593 
6594 ////////////////////////////////////////////////////////////////////////////////
6595 
6596 void TCling::CallFunc_SetArg(CallFunc_t* func, Long64_t param) const
6597 {
6598  TClingCallFunc* f = (TClingCallFunc*) func;
6599  f->SetArg(param);
6600 }
6601 
6602 ////////////////////////////////////////////////////////////////////////////////
6603 
6604 void TCling::CallFunc_SetArg(CallFunc_t* func, ULong64_t param) const
6605 {
6606  TClingCallFunc* f = (TClingCallFunc*) func;
6607  f->SetArg(param);
6608 }
6609 
6610 ////////////////////////////////////////////////////////////////////////////////
6611 
6612 void TCling::CallFunc_SetArgArray(CallFunc_t* func, Long_t* paramArr, Int_t nparam) const
6613 {
6614  TClingCallFunc* f = (TClingCallFunc*) func;
6615  f->SetArgArray(paramArr, nparam);
6616 }
6617 
6618 ////////////////////////////////////////////////////////////////////////////////
6619 
6620 void TCling::CallFunc_SetArgs(CallFunc_t* func, const char* param) const
6621 {
6622  TClingCallFunc* f = (TClingCallFunc*) func;
6623  f->SetArgs(param);
6624 }
6625 
6626 ////////////////////////////////////////////////////////////////////////////////
6627 
6628 void TCling::CallFunc_SetFunc(CallFunc_t* func, ClassInfo_t* info, const char* method, const char* params, Long_t* offset) const
6629 {
6630  TClingCallFunc* f = (TClingCallFunc*) func;
6631  TClingClassInfo* ci = (TClingClassInfo*) info;
6632  f->SetFunc(ci, method, params, offset);
6633 }
6634 
6635 ////////////////////////////////////////////////////////////////////////////////
6636 
6637 void TCling::CallFunc_SetFunc(CallFunc_t* func, ClassInfo_t* info, const char* method, const char* params, bool objectIsConst, Long_t* offset) const
6638 {
6639  TClingCallFunc* f = (TClingCallFunc*) func;
6640  TClingClassInfo* ci = (TClingClassInfo*) info;
6641  f->SetFunc(ci, method, params, objectIsConst, offset);
6642 }
6643 ////////////////////////////////////////////////////////////////////////////////
6644 
6645 void TCling::CallFunc_SetFunc(CallFunc_t* func, MethodInfo_t* info) const
6646 {
6647  TClingCallFunc* f = (TClingCallFunc*) func;
6648  TClingMethodInfo* minfo = (TClingMethodInfo*) info;
6649  f->SetFunc(minfo);
6650 }
6651 
6652 ////////////////////////////////////////////////////////////////////////////////
6653 /// Interface to cling function
6654 
6655 void TCling::CallFunc_SetFuncProto(CallFunc_t* func, ClassInfo_t* info, const char* method, const char* proto, Long_t* offset, EFunctionMatchMode mode /* = kConversionMatch */) const
6656 {
6657  TClingCallFunc* f = (TClingCallFunc*) func;
6658  TClingClassInfo* ci = (TClingClassInfo*) info;
6659  f->SetFuncProto(ci, method, proto, offset, mode);
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, bool objectIsConst, Long_t* offset, EFunctionMatchMode mode /* = kConversionMatch */) const
6666 {
6667  TClingCallFunc* f = (TClingCallFunc*) func;
6668  TClingClassInfo* ci = (TClingClassInfo*) info;
6669  f->SetFuncProto(ci, method, proto, objectIsConst, 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 std::vector<TypeInfo_t*> &proto, Long_t* offset, EFunctionMatchMode mode /* = kConversionMatch */) const
6676 {
6677  TClingCallFunc* f = (TClingCallFunc*) func;
6678  TClingClassInfo* ci = (TClingClassInfo*) info;
6679  llvm::SmallVector<clang::QualType, 4> funcProto;
6680  for (std::vector<TypeInfo_t*>::const_iterator iter = proto.begin(), end = proto.end();
6681  iter != end; ++iter) {
6682  funcProto.push_back( ((TClingTypeInfo*)(*iter))->GetQualType() );
6683  }
6684  f->SetFuncProto(ci, method, funcProto, offset, mode);
6685 }
6686 
6687 ////////////////////////////////////////////////////////////////////////////////
6688 /// Interface to cling function
6689 
6690 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
6691 {
6692  TClingCallFunc* f = (TClingCallFunc*) func;
6693  TClingClassInfo* ci = (TClingClassInfo*) info;
6694  llvm::SmallVector<clang::QualType, 4> funcProto;
6695  for (std::vector<TypeInfo_t*>::const_iterator iter = proto.begin(), end = proto.end();
6696  iter != end; ++iter) {
6697  funcProto.push_back( ((TClingTypeInfo*)(*iter))->GetQualType() );
6698  }
6699  f->SetFuncProto(ci, method, funcProto, objectIsConst, offset, mode);
6700 }
6701 
6702 //______________________________________________________________________________
6703 //
6704 // ClassInfo interface
6705 //
6706 
6707 ////////////////////////////////////////////////////////////////////////////////
6708 /// Return true if the entity pointed to by 'declid' is declared in
6709 /// the context described by 'info'. If info is null, look into the
6710 /// global scope (translation unit scope).
6711 
6712 Bool_t TCling::ClassInfo_Contains(ClassInfo_t *info, DeclId_t declid) const
6713 {
6714  if (!declid) return kFALSE;
6715 
6716  const clang::Decl *scope;
6717  if (info) scope = ((TClingClassInfo*)info)->GetDecl();
6718  else scope = fInterpreter->getCI()->getASTContext().getTranslationUnitDecl();
6719 
6720  const clang::Decl *decl = reinterpret_cast<const clang::Decl*>(declid);
6721  const clang::DeclContext *ctxt = clang::Decl::castToDeclContext(scope);
6722  if (!decl || !ctxt) return kFALSE;
6723  if (decl->getDeclContext()->Equals(ctxt))
6724  return kTRUE;
6725  else if (decl->getDeclContext()->isTransparentContext() &&
6726  decl->getDeclContext()->getParent()->Equals(ctxt))
6727  return kTRUE;
6728  return kFALSE;
6729 }
6730 
6731 ////////////////////////////////////////////////////////////////////////////////
6732 
6733 Long_t TCling::ClassInfo_ClassProperty(ClassInfo_t* cinfo) const
6734 {
6735  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
6736  return TClinginfo->ClassProperty();
6737 }
6738 
6739 ////////////////////////////////////////////////////////////////////////////////
6740 
6741 void TCling::ClassInfo_Delete(ClassInfo_t* cinfo) const
6742 {
6743  delete (TClingClassInfo*) cinfo;
6744 }
6745 
6746 ////////////////////////////////////////////////////////////////////////////////
6747 
6748 void TCling::ClassInfo_Delete(ClassInfo_t* cinfo, void* arena) const
6749 {
6750  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
6751  TClinginfo->Delete(arena,*fNormalizedCtxt);
6752 }
6753 
6754 ////////////////////////////////////////////////////////////////////////////////
6755 
6756 void TCling::ClassInfo_DeleteArray(ClassInfo_t* cinfo, void* arena, bool dtorOnly) const
6757 {
6758  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
6759  TClinginfo->DeleteArray(arena, dtorOnly,*fNormalizedCtxt);
6760 }
6761 
6762 ////////////////////////////////////////////////////////////////////////////////
6763 
6764 void TCling::ClassInfo_Destruct(ClassInfo_t* cinfo, void* arena) const
6765 {
6766  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
6767  TClinginfo->Destruct(arena,*fNormalizedCtxt);
6768 }
6769 
6770 ////////////////////////////////////////////////////////////////////////////////
6771 
6772 ClassInfo_t* TCling::ClassInfo_Factory(Bool_t all) const
6773 {
6775  return (ClassInfo_t*) new TClingClassInfo(fInterpreter, all);
6776 }
6777 
6778 ////////////////////////////////////////////////////////////////////////////////
6779 
6780 ClassInfo_t* TCling::ClassInfo_Factory(ClassInfo_t* cinfo) const
6781 {
6782  return (ClassInfo_t*) new TClingClassInfo(*(TClingClassInfo*)cinfo);
6783 }
6784 
6785 ////////////////////////////////////////////////////////////////////////////////
6786 
6787 ClassInfo_t* TCling::ClassInfo_Factory(const char* name) const
6788 {
6790  return (ClassInfo_t*) new TClingClassInfo(fInterpreter, name);
6791 }
6792 
6793 ////////////////////////////////////////////////////////////////////////////////
6794 
6795 int TCling::ClassInfo_GetMethodNArg(ClassInfo_t* cinfo, const char* method, const char* proto, Bool_t objectIsConst /* = false */, EFunctionMatchMode mode /* = kConversionMatch */) const
6796 {
6797  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
6798  return TClinginfo->GetMethodNArg(method, proto, objectIsConst, mode);
6799 }
6800 
6801 ////////////////////////////////////////////////////////////////////////////////
6802 
6803 bool TCling::ClassInfo_HasDefaultConstructor(ClassInfo_t* cinfo) const
6804 {
6805  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
6806  return TClinginfo->HasDefaultConstructor();
6807 }
6808 
6809 ////////////////////////////////////////////////////////////////////////////////
6810 
6811 bool TCling::ClassInfo_HasMethod(ClassInfo_t* cinfo, const char* name) const
6812 {
6813  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
6814  return TClinginfo->HasMethod(name);
6815 }
6816 
6817 ////////////////////////////////////////////////////////////////////////////////
6818 
6819 void TCling::ClassInfo_Init(ClassInfo_t* cinfo, const char* name) const
6820 {
6822  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
6823  TClinginfo->Init(name);
6824 }
6825 
6826 ////////////////////////////////////////////////////////////////////////////////
6827 
6828 void TCling::ClassInfo_Init(ClassInfo_t* cinfo, int tagnum) const
6829 {
6831  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
6832  TClinginfo->Init(tagnum);
6833 }
6834 
6835 ////////////////////////////////////////////////////////////////////////////////
6836 
6837 bool TCling::ClassInfo_IsBase(ClassInfo_t* cinfo, const char* name) const
6838 {
6839  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
6840  return TClinginfo->IsBase(name);
6841 }
6842 
6843 ////////////////////////////////////////////////////////////////////////////////
6844 
6845 bool TCling::ClassInfo_IsEnum(const char* name) const
6846 {
6847  return TClingClassInfo::IsEnum(fInterpreter, name);
6848 }
6849 
6850 ////////////////////////////////////////////////////////////////////////////////
6851 
6852 bool TCling::ClassInfo_IsLoaded(ClassInfo_t* cinfo) const
6853 {
6854  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
6855  return TClinginfo->IsLoaded();
6856 }
6857 
6858 ////////////////////////////////////////////////////////////////////////////////
6859 
6860 bool TCling::ClassInfo_IsValid(ClassInfo_t* cinfo) const
6861 {
6862  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
6863  return TClinginfo->IsValid();
6864 }
6865 
6866 ////////////////////////////////////////////////////////////////////////////////
6867 
6868 bool TCling::ClassInfo_IsValidMethod(ClassInfo_t* cinfo, const char* method, const char* proto, Long_t* offset, EFunctionMatchMode mode /* = kConversionMatch */) const
6869 {
6870  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
6871  return TClinginfo->IsValidMethod(method, proto, false, offset, mode);
6872 }
6873 
6874 ////////////////////////////////////////////////////////////////////////////////
6875 
6876 bool TCling::ClassInfo_IsValidMethod(ClassInfo_t* cinfo, const char* method, const char* proto, Bool_t objectIsConst, Long_t* offset, EFunctionMatchMode mode /* = kConversionMatch */) const
6877 {
6878  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
6879  return TClinginfo->IsValidMethod(method, proto, objectIsConst, offset, mode);
6880 }
6881 
6882 ////////////////////////////////////////////////////////////////////////////////
6883 
6884 int TCling::ClassInfo_Next(ClassInfo_t* cinfo) const
6885 {
6886  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
6887  return TClinginfo->Next();
6888 }
6889 
6890 ////////////////////////////////////////////////////////////////////////////////
6891 
6892 void* TCling::ClassInfo_New(ClassInfo_t* cinfo) const
6893 {
6894  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
6895  return TClinginfo->New(*fNormalizedCtxt);
6896 }
6897 
6898 ////////////////////////////////////////////////////////////////////////////////
6899 
6900 void* TCling::ClassInfo_New(ClassInfo_t* cinfo, int n) const
6901 {
6902  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
6903  return TClinginfo->New(n,*fNormalizedCtxt);
6904 }
6905 
6906 ////////////////////////////////////////////////////////////////////////////////
6907 
6908 void* TCling::ClassInfo_New(ClassInfo_t* cinfo, int n, void* arena) const
6909 {
6910  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
6911  return TClinginfo->New(n, arena,*fNormalizedCtxt);
6912 }
6913 
6914 ////////////////////////////////////////////////////////////////////////////////
6915 
6916 void* TCling::ClassInfo_New(ClassInfo_t* cinfo, void* arena) const
6917 {
6918  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
6919  return TClinginfo->New(arena,*fNormalizedCtxt);
6920 }
6921 
6922 ////////////////////////////////////////////////////////////////////////////////
6923 
6924 Long_t TCling::ClassInfo_Property(ClassInfo_t* cinfo) const
6925 {
6926  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
6927  return TClinginfo->Property();
6928 }
6929 
6930 ////////////////////////////////////////////////////////////////////////////////
6931 
6932 int TCling::ClassInfo_Size(ClassInfo_t* cinfo) const
6933 {
6934  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
6935  return TClinginfo->Size();
6936 }
6937 
6938 ////////////////////////////////////////////////////////////////////////////////
6939 
6940 Long_t TCling::ClassInfo_Tagnum(ClassInfo_t* cinfo) const
6941 {
6942  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
6943  return TClinginfo->Tagnum();
6944 }
6945 
6946 ////////////////////////////////////////////////////////////////////////////////
6947 
6948 const char* TCling::ClassInfo_FileName(ClassInfo_t* cinfo) const
6949 {
6950  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
6951  return TClinginfo->FileName();
6952 }
6953 
6954 ////////////////////////////////////////////////////////////////////////////////
6955 
6956 const char* TCling::ClassInfo_FullName(ClassInfo_t* cinfo) const
6957 {
6958  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
6959  TTHREAD_TLS_DECL(std::string,output);
6960  TClinginfo->FullName(output,*fNormalizedCtxt);
6961  return output.c_str();
6962 }
6963 
6964 ////////////////////////////////////////////////////////////////////////////////
6965 
6966 const char* TCling::ClassInfo_Name(ClassInfo_t* cinfo) const
6967 {
6968  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
6969  return TClinginfo->Name();
6970 }
6971 
6972 ////////////////////////////////////////////////////////////////////////////////
6973 
6974 const char* TCling::ClassInfo_Title(ClassInfo_t* cinfo) const
6975 {
6976  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
6977  return TClinginfo->Title();
6978 }
6979 
6980 ////////////////////////////////////////////////////////////////////////////////
6981 
6982 const char* TCling::ClassInfo_TmpltName(ClassInfo_t* cinfo) const
6983 {
6984  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
6985  return TClinginfo->TmpltName();
6986 }
6987 
6988 
6989 
6990 //______________________________________________________________________________
6991 //
6992 // BaseClassInfo interface
6993 //
6994 
6995 ////////////////////////////////////////////////////////////////////////////////
6996 
6997 void TCling::BaseClassInfo_Delete(BaseClassInfo_t* bcinfo) const
6998 {
6999  delete(TClingBaseClassInfo*) bcinfo;
7000 }
7001 
7002 ////////////////////////////////////////////////////////////////////////////////
7003 
7004 BaseClassInfo_t* TCling::BaseClassInfo_Factory(ClassInfo_t* cinfo) const
7005 {
7007  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
7008  return (BaseClassInfo_t*) new TClingBaseClassInfo(fInterpreter, TClinginfo);
7009 }
7010 
7011 ////////////////////////////////////////////////////////////////////////////////
7012 
7013 BaseClassInfo_t* TCling::BaseClassInfo_Factory(ClassInfo_t* derived,
7014  ClassInfo_t* base) const
7015 {
7017  TClingClassInfo* TClinginfo = (TClingClassInfo*) derived;
7018  TClingClassInfo* TClinginfoBase = (TClingClassInfo*) base;
7019  return (BaseClassInfo_t*) new TClingBaseClassInfo(fInterpreter, TClinginfo, TClinginfoBase);
7020 }
7021 
7022 ////////////////////////////////////////////////////////////////////////////////
7023 
7024 int TCling::BaseClassInfo_Next(BaseClassInfo_t* bcinfo) const
7025 {
7026  TClingBaseClassInfo* TClinginfo = (TClingBaseClassInfo*) bcinfo;
7027  return TClinginfo->Next();
7028 }
7029 
7030 ////////////////////////////////////////////////////////////////////////////////
7031 
7032 int TCling::BaseClassInfo_Next(BaseClassInfo_t* bcinfo, int onlyDirect) const
7033 {
7034  TClingBaseClassInfo* TClinginfo = (TClingBaseClassInfo*) bcinfo;
7035  return TClinginfo->Next(onlyDirect);
7036 }
7037 
7038 ////////////////////////////////////////////////////////////////////////////////
7039 
7040 Long_t TCling::BaseClassInfo_Offset(BaseClassInfo_t* toBaseClassInfo, void * address, bool isDerivedObject) const
7041 {
7042  TClingBaseClassInfo* TClinginfo = (TClingBaseClassInfo*) toBaseClassInfo;
7043  return TClinginfo->Offset(address, isDerivedObject);
7044 }
7045 
7046 ////////////////////////////////////////////////////////////////////////////////
7047 
7048 Long_t TCling::ClassInfo_GetBaseOffset(ClassInfo_t* fromDerived, ClassInfo_t* toBase, void * address, bool isDerivedObject) const
7049 {
7050  TClingClassInfo* TClinginfo = (TClingClassInfo*) fromDerived;
7051  TClingClassInfo* TClinginfoBase = (TClingClassInfo*) toBase;
7052  // Offset to the class itself.
7053  if (TClinginfo->GetDecl() == TClinginfoBase->GetDecl()) {
7054  return 0;
7055  }
7056  return TClinginfo->GetBaseOffset(TClinginfoBase, address, isDerivedObject);
7057 }
7058 
7059 ////////////////////////////////////////////////////////////////////////////////
7060 
7061 Long_t TCling::BaseClassInfo_Property(BaseClassInfo_t* bcinfo) const
7062 {
7063  TClingBaseClassInfo* TClinginfo = (TClingBaseClassInfo*) bcinfo;
7064  return TClinginfo->Property();
7065 }
7066 
7067 ////////////////////////////////////////////////////////////////////////////////
7068 
7069 ClassInfo_t *TCling::BaseClassInfo_ClassInfo(BaseClassInfo_t *bcinfo) const
7070 {
7071  TClingBaseClassInfo* TClinginfo = (TClingBaseClassInfo*) bcinfo;
7072  return (ClassInfo_t *)TClinginfo->GetBase();
7073 }
7074 
7075 ////////////////////////////////////////////////////////////////////////////////
7076 
7077 Long_t TCling::BaseClassInfo_Tagnum(BaseClassInfo_t* bcinfo) const
7078 {
7079  TClingBaseClassInfo* TClinginfo = (TClingBaseClassInfo*) bcinfo;
7080  return TClinginfo->Tagnum();
7081 }
7082 
7083 ////////////////////////////////////////////////////////////////////////////////
7084 
7085 const char* TCling::BaseClassInfo_FullName(BaseClassInfo_t* bcinfo) const
7086 {
7087  TClingBaseClassInfo* TClinginfo = (TClingBaseClassInfo*) bcinfo;
7088  TTHREAD_TLS_DECL(std::string,output);
7089  TClinginfo->FullName(output,*fNormalizedCtxt);
7090  return output.c_str();
7091 }
7092 
7093 ////////////////////////////////////////////////////////////////////////////////
7094 
7095 const char* TCling::BaseClassInfo_Name(BaseClassInfo_t* bcinfo) const
7096 {
7097  TClingBaseClassInfo* TClinginfo = (TClingBaseClassInfo*) bcinfo;
7098  return TClinginfo->Name();
7099 }
7100 
7101 ////////////////////////////////////////////////////////////////////////////////
7102 
7103 const char* TCling::BaseClassInfo_TmpltName(BaseClassInfo_t* bcinfo) const
7104 {
7105  TClingBaseClassInfo* TClinginfo = (TClingBaseClassInfo*) bcinfo;
7106  return TClinginfo->TmpltName();
7107 }
7108 
7109 //______________________________________________________________________________
7110 //
7111 // DataMemberInfo interface
7112 //
7113 
7114 ////////////////////////////////////////////////////////////////////////////////
7115 
7116 int TCling::DataMemberInfo_ArrayDim(DataMemberInfo_t* dminfo) const
7117 {
7118  TClingDataMemberInfo* TClinginfo = (TClingDataMemberInfo*) dminfo;
7119  return TClinginfo->ArrayDim();
7120 }
7121 
7122 ////////////////////////////////////////////////////////////////////////////////
7123 
7124 void TCling::DataMemberInfo_Delete(DataMemberInfo_t* dminfo) const
7125 {
7126  delete(TClingDataMemberInfo*) dminfo;
7127 }
7128 
7129 ////////////////////////////////////////////////////////////////////////////////
7130 
7131 DataMemberInfo_t* TCling::DataMemberInfo_Factory(ClassInfo_t* clinfo /*= 0*/) const
7132 {
7134  TClingClassInfo* TClingclass_info = (TClingClassInfo*) clinfo;
7135  return (DataMemberInfo_t*) new TClingDataMemberInfo(fInterpreter, TClingclass_info);
7136 }
7137 
7138 ////////////////////////////////////////////////////////////////////////////////
7139 
7140 DataMemberInfo_t* TCling::DataMemberInfo_Factory(DeclId_t declid, ClassInfo_t* clinfo) const
7141 {
7143  const clang::Decl* decl = reinterpret_cast<const clang::Decl*>(declid);
7144  const clang::ValueDecl* vd = llvm::dyn_cast_or_null<clang::ValueDecl>(decl);
7145  return (DataMemberInfo_t*) new TClingDataMemberInfo(fInterpreter, vd, (TClingClassInfo*)clinfo);
7146 }
7147 
7148 ////////////////////////////////////////////////////////////////////////////////
7149 
7150 DataMemberInfo_t* TCling::DataMemberInfo_FactoryCopy(DataMemberInfo_t* dminfo) const
7151 {
7152  TClingDataMemberInfo* TClinginfo = (TClingDataMemberInfo*) dminfo;
7153  return (DataMemberInfo_t*) new TClingDataMemberInfo(*TClinginfo);
7154 }
7155 
7156 ////////////////////////////////////////////////////////////////////////////////
7157 
7158 bool TCling::DataMemberInfo_IsValid(DataMemberInfo_t* dminfo) const
7159 {
7160  TClingDataMemberInfo* TClinginfo = (TClingDataMemberInfo*) dminfo;
7161  return TClinginfo->IsValid();
7162 }
7163 
7164 ////////////////////////////////////////////////////////////////////////////////
7165 
7166 int TCling::DataMemberInfo_MaxIndex(DataMemberInfo_t* dminfo, Int_t dim) const
7167 {
7168  TClingDataMemberInfo* TClinginfo = (TClingDataMemberInfo*) dminfo;
7169  return TClinginfo->MaxIndex(dim);
7170 }
7171 
7172 ////////////////////////////////////////////////////////////////////////////////
7173 
7174 int TCling::DataMemberInfo_Next(DataMemberInfo_t* dminfo) const
7175 {
7176  TClingDataMemberInfo* TClinginfo = (TClingDataMemberInfo*) dminfo;
7177  return TClinginfo->Next();
7178 }
7179 
7180 ////////////////////////////////////////////////////////////////////////////////
7181 
7182 Long_t TCling::DataMemberInfo_Offset(DataMemberInfo_t* dminfo) const
7183 {
7184  TClingDataMemberInfo* TClinginfo = (TClingDataMemberInfo*) dminfo;
7185  return TClinginfo->Offset();
7186 }
7187 
7188 ////////////////////////////////////////////////////////////////////////////////
7189 
7190 Long_t TCling::DataMemberInfo_Property(DataMemberInfo_t* dminfo) const
7191 {
7192  TClingDataMemberInfo* TClinginfo = (TClingDataMemberInfo*) dminfo;
7193  return TClinginfo->Property();
7194 }
7195 
7196 ////////////////////////////////////////////////////////////////////////////////
7197 
7198 Long_t TCling::DataMemberInfo_TypeProperty(DataMemberInfo_t* dminfo) const
7199 {
7200  TClingDataMemberInfo* TClinginfo = (TClingDataMemberInfo*) dminfo;
7201  return TClinginfo->TypeProperty();
7202 }
7203 
7204 ////////////////////////////////////////////////////////////////////////////////
7205 
7206 int TCling::DataMemberInfo_TypeSize(DataMemberInfo_t* dminfo) const
7207 {
7208  TClingDataMemberInfo* TClinginfo = (TClingDataMemberInfo*) dminfo;
7209  return TClinginfo->TypeSize();
7210 }
7211 
7212 ////////////////////////////////////////////////////////////////////////////////
7213 
7214 const char* TCling::DataMemberInfo_TypeName(DataMemberInfo_t* dminfo) const
7215 {
7216  TClingDataMemberInfo* TClinginfo = (TClingDataMemberInfo*) dminfo;
7217  return TClinginfo->TypeName();
7218 }
7219 
7220 ////////////////////////////////////////////////////////////////////////////////
7221 
7222 const char* TCling::DataMemberInfo_TypeTrueName(DataMemberInfo_t* dminfo) const
7223 {
7224  TClingDataMemberInfo* TClinginfo = (TClingDataMemberInfo*) dminfo;
7225  return TClinginfo->TypeTrueName(*fNormalizedCtxt);
7226 }
7227 
7228 ////////////////////////////////////////////////////////////////////////////////
7229 
7230 const char* TCling::DataMemberInfo_Name(DataMemberInfo_t* dminfo) const
7231 {
7232  TClingDataMemberInfo* TClinginfo = (TClingDataMemberInfo*) dminfo;
7233  return TClinginfo->Name();
7234 }
7235 
7236 ////////////////////////////////////////////////////////////////////////////////
7237 
7238 const char* TCling::DataMemberInfo_Title(DataMemberInfo_t* dminfo) const
7239 {
7240  TClingDataMemberInfo* TClinginfo = (TClingDataMemberInfo*) dminfo;
7241  return TClinginfo->Title();
7242 }
7243 
7244 ////////////////////////////////////////////////////////////////////////////////
7245 
7246 const char* TCling::DataMemberInfo_ValidArrayIndex(DataMemberInfo_t* dminfo) const
7247 {
7248  TTHREAD_TLS_DECL(std::string,result);
7249 
7250  TClingDataMemberInfo* TClinginfo = (TClingDataMemberInfo*) dminfo;
7251  result = TClinginfo->ValidArrayIndex().str();
7252  return result.c_str();
7253 }
7254 
7255 ////////////////////////////////////////////////////////////////////////////////
7256 
7257 void TCling::SetDeclAttr(DeclId_t declId, const char* attribute)
7258 {
7259  Decl* decl = static_cast<Decl*>(const_cast<void*>(declId));
7260  ASTContext &C = decl->getASTContext();
7261  SourceRange commentRange; // this is a fake comment range
7262  decl->addAttr( new (C) AnnotateAttr( commentRange, C, attribute, 0 ) );
7263 }
7264 
7265 //______________________________________________________________________________
7266 //
7267 // Function Template interface
7268 //
7269 
7270 ////////////////////////////////////////////////////////////////////////////////
7271 
7272 static void ConstructorName(std::string &name, const clang::NamedDecl *decl,
7273  cling::Interpreter &interp,
7274  const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt)
7275 {
7276  const clang::TypeDecl* td = llvm::dyn_cast<clang::TypeDecl>(decl->getDeclContext());
7277  if (!td) return;
7278 
7279  clang::QualType qualType(td->getTypeForDecl(),0);
7280  ROOT::TMetaUtils::GetNormalizedName(name, qualType, interp, normCtxt);
7281  unsigned int level = 0;
7282  for(size_t cursor = name.length()-1; cursor != 0; --cursor) {
7283  if (name[cursor] == '>') ++level;
7284  else if (name[cursor] == '<' && level) --level;
7285  else if (level == 0 && name[cursor] == ':') {
7286  name.erase(0,cursor+1);
7287  break;
7288  }
7289  }
7290 }
7291 
7292 ////////////////////////////////////////////////////////////////////////////////
7293 
7294 void TCling::GetFunctionName(const clang::FunctionDecl *decl, std::string &output) const
7295 {
7296  output.clear();
7297  if (llvm::isa<clang::CXXConstructorDecl>(decl))
7298  {
7299  ConstructorName(output, decl, *fInterpreter, *fNormalizedCtxt);
7300 
7301  } else if (llvm::isa<clang::CXXDestructorDecl>(decl))
7302  {
7303  ConstructorName(output, decl, *fInterpreter, *fNormalizedCtxt);
7304  output.insert(output.begin(), '~');
7305  } else {
7306  llvm::raw_string_ostream stream(output);
7307  decl->getNameForDiagnostic(stream, decl->getASTContext().getPrintingPolicy(), /*Qualified=*/false);
7308  }
7309 }
7310 
7311 ////////////////////////////////////////////////////////////////////////////////
7312 /// Return a unique identifier of the declaration represented by the
7313 /// FuncTempInfo
7314 
7315 TInterpreter::DeclId_t TCling::GetDeclId(FuncTempInfo_t *info) const
7316 {
7317  return (DeclId_t)info;
7318 }
7319 
7320 ////////////////////////////////////////////////////////////////////////////////
7321 /// Delete the FuncTempInfo_t
7322 
7323 void TCling::FuncTempInfo_Delete(FuncTempInfo_t * /* ft_info */) const
7324 {
7325  // Currently the address of ft_info is actually the decl itself,
7326  // so we have nothing to do.
7327 }
7328 
7329 ////////////////////////////////////////////////////////////////////////////////
7330 /// Construct a FuncTempInfo_t
7331 
7332 FuncTempInfo_t *TCling::FuncTempInfo_Factory(DeclId_t declid) const
7333 {
7334  // Currently the address of ft_info is actually the decl itself,
7335  // so we have nothing to do.
7336 
7337  return (FuncTempInfo_t*)const_cast<void*>(declid);
7338 }
7339 
7340 ////////////////////////////////////////////////////////////////////////////////
7341 /// Construct a FuncTempInfo_t
7342 
7343 FuncTempInfo_t *TCling::FuncTempInfo_FactoryCopy(FuncTempInfo_t *ft_info) const
7344 {
7345  // Currently the address of ft_info is actually the decl itself,
7346  // so we have nothing to do.
7347 
7348  return (FuncTempInfo_t*)ft_info;
7349 }
7350 
7351 ////////////////////////////////////////////////////////////////////////////////
7352 /// Check validity of a FuncTempInfo_t
7353 
7354 Bool_t TCling::FuncTempInfo_IsValid(FuncTempInfo_t *t_info) const
7355 {
7356  // Currently the address of ft_info is actually the decl itself,
7357  // so we have nothing to do.
7358 
7359  return t_info != 0;
7360 }
7361 
7362 ////////////////////////////////////////////////////////////////////////////////
7363 /// Return the maximum number of template arguments of the
7364 /// function template described by ft_info.
7365 
7366 UInt_t TCling::FuncTempInfo_TemplateNargs(FuncTempInfo_t *ft_info) const
7367 {
7368  if (!ft_info) return 0;
7369  const clang::FunctionTemplateDecl *ft = (const clang::FunctionTemplateDecl*)ft_info;
7370  return ft->getTemplateParameters()->size();
7371 }
7372 
7373 ////////////////////////////////////////////////////////////////////////////////
7374 /// Return the number of required template arguments of the
7375 /// function template described by ft_info.
7376 
7377 UInt_t TCling::FuncTempInfo_TemplateMinReqArgs(FuncTempInfo_t *ft_info) const
7378 {
7379  if (!ft_info) return 0;
7380  const clang::FunctionTemplateDecl *ft = (clang::FunctionTemplateDecl*)ft_info;
7381  return ft->getTemplateParameters()->getMinRequiredArguments();
7382 }
7383 
7384 ////////////////////////////////////////////////////////////////////////////////
7385 /// Return the property of the function template.
7386 
7387 Long_t TCling::FuncTempInfo_Property(FuncTempInfo_t *ft_info) const
7388 {
7389  if (!ft_info) return 0;
7390 
7391  long property = 0L;
7392  property |= kIsCompiled;
7393 
7394  const clang::FunctionTemplateDecl *ft = (clang::FunctionTemplateDecl*)ft_info;
7395 
7396  switch (ft->getAccess()) {
7397  case clang::AS_public:
7398  property |= kIsPublic;
7399  break;
7400  case clang::AS_protected:
7401  property |= kIsProtected;
7402  break;
7403  case clang::AS_private:
7404  property |= kIsPrivate;
7405  break;
7406  case clang::AS_none:
7407  if (ft->getDeclContext()->isNamespace())
7408  property |= kIsPublic;
7409  break;
7410  default:
7411  // IMPOSSIBLE
7412  break;
7413  }
7414 
7415  const clang::FunctionDecl *fd = ft->getTemplatedDecl();
7416  if (const clang::CXXMethodDecl *md =
7417  llvm::dyn_cast<clang::CXXMethodDecl>(fd)) {
7418  if (md->getTypeQualifiers() & clang::Qualifiers::Const) {
7419  property |= kIsConstant | kIsConstMethod;
7420  }
7421  if (md->isVirtual()) {
7422  property |= kIsVirtual;
7423  }
7424  if (md->isPure()) {
7425  property |= kIsPureVirtual;
7426  }
7427  if (const clang::CXXConstructorDecl *cd =
7428  llvm::dyn_cast<clang::CXXConstructorDecl>(md)) {
7429  if (cd->isExplicit()) {
7430  property |= kIsExplicit;
7431  }
7432  }
7433  else if (const clang::CXXConversionDecl *cd =
7434  llvm::dyn_cast<clang::CXXConversionDecl>(md)) {
7435  if (cd->isExplicit()) {
7436  property |= kIsExplicit;
7437  }
7438  }
7439  }
7440  return property;
7441 }
7442 
7443 ////////////////////////////////////////////////////////////////////////////////
7444 /// Return the name of this function template.
7445 
7446 void TCling::FuncTempInfo_Name(FuncTempInfo_t *ft_info, TString &output) const
7447 {
7448  output.Clear();
7449  if (!ft_info) return;
7450  const clang::FunctionTemplateDecl *ft = (clang::FunctionTemplateDecl*)ft_info;
7451  std::string buf;
7452  GetFunctionName(ft->getTemplatedDecl(), buf);
7453  output = buf;
7454 }
7455 
7456 ////////////////////////////////////////////////////////////////////////////////
7457 /// Return the comments associates with this function template.
7458 
7459 void TCling::FuncTempInfo_Title(FuncTempInfo_t *ft_info, TString &output) const
7460 {
7461  output.Clear();
7462  if (!ft_info) return;
7463  const clang::FunctionTemplateDecl *ft = (const clang::FunctionTemplateDecl*)ft_info;
7464 
7465  // Iterate over the redeclarations, we can have multiple definitions in the
7466  // redecl chain (came from merging of pcms).
7467  if (const RedeclarableTemplateDecl *AnnotFD
7468  = ROOT::TMetaUtils::GetAnnotatedRedeclarable((const RedeclarableTemplateDecl*)ft)) {
7469  if (AnnotateAttr *A = AnnotFD->getAttr<AnnotateAttr>()) {
7470  output = A->getAnnotation().str();
7471  return;
7472  }
7473  }
7474  if (!ft->isFromASTFile()) {
7475  // Try to get the comment from the header file if present
7476  // but not for decls from AST file, where rootcling would have
7477  // created an annotation
7478  output = ROOT::TMetaUtils::GetComment(*ft).str();
7479  }
7480 }
7481 
7482 
7483 //______________________________________________________________________________
7484 //
7485 // MethodInfo interface
7486 //
7487 
7488 ////////////////////////////////////////////////////////////////////////////////
7489 /// Interface to cling function
7490 
7491 void TCling::MethodInfo_Delete(MethodInfo_t* minfo) const
7492 {
7493  delete(TClingMethodInfo*) minfo;
7494 }
7495 
7496 ////////////////////////////////////////////////////////////////////////////////
7497 
7498 void TCling::MethodInfo_CreateSignature(MethodInfo_t* minfo, TString& signature) const
7499 {
7500  TClingMethodInfo* info = (TClingMethodInfo*) minfo;
7501  info->CreateSignature(signature);
7502 }
7503 
7504 ////////////////////////////////////////////////////////////////////////////////
7505 
7506 MethodInfo_t* TCling::MethodInfo_Factory() const
7507 {
7509  return (MethodInfo_t*) new TClingMethodInfo(fInterpreter);
7510 }
7511 
7512 ////////////////////////////////////////////////////////////////////////////////
7513 
7514 MethodInfo_t* TCling::MethodInfo_Factory(ClassInfo_t* clinfo) const
7515 {
7517  return (MethodInfo_t*) new TClingMethodInfo(fInterpreter, (TClingClassInfo*)clinfo);
7518 }
7519 
7520 ////////////////////////////////////////////////////////////////////////////////
7521 
7522 MethodInfo_t* TCling::MethodInfo_Factory(DeclId_t declid) const
7523 {
7524  const clang::Decl* decl = reinterpret_cast<const clang::Decl*>(declid);
7526  const clang::FunctionDecl* fd = llvm::dyn_cast_or_null<clang::FunctionDecl>(decl);
7527  return (MethodInfo_t*) new TClingMethodInfo(fInterpreter, fd);
7528 }
7529 
7530 ////////////////////////////////////////////////////////////////////////////////
7531 
7532 MethodInfo_t* TCling::MethodInfo_FactoryCopy(MethodInfo_t* minfo) const
7533 {
7534  return (MethodInfo_t*) new TClingMethodInfo(*(TClingMethodInfo*)minfo);
7535 }
7536 
7537 ////////////////////////////////////////////////////////////////////////////////
7538 
7539 void* TCling::MethodInfo_InterfaceMethod(MethodInfo_t* minfo) const
7540 {
7541  TClingMethodInfo* info = (TClingMethodInfo*) minfo;
7542  return info->InterfaceMethod(*fNormalizedCtxt);
7543 }
7544 
7545 ////////////////////////////////////////////////////////////////////////////////
7546 
7547 bool TCling::MethodInfo_IsValid(MethodInfo_t* minfo) const
7548 {
7549  TClingMethodInfo* info = (TClingMethodInfo*) minfo;
7550  return info->IsValid();
7551 }
7552 
7553 ////////////////////////////////////////////////////////////////////////////////
7554 
7555 int TCling::MethodInfo_NArg(MethodInfo_t* minfo) const
7556 {
7557  TClingMethodInfo* info = (TClingMethodInfo*) minfo;
7558  return info->NArg();
7559 }
7560 
7561 ////////////////////////////////////////////////////////////////////////////////
7562 
7563 int TCling::MethodInfo_NDefaultArg(MethodInfo_t* minfo) const
7564 {
7565  TClingMethodInfo* info = (TClingMethodInfo*) minfo;
7566  return info->NDefaultArg();
7567 }
7568 
7569 ////////////////////////////////////////////////////////////////////////////////
7570 
7571 int TCling::MethodInfo_Next(MethodInfo_t* minfo) const
7572 {
7573  TClingMethodInfo* info = (TClingMethodInfo*) minfo;
7574  return info->Next();
7575 }
7576 
7577 ////////////////////////////////////////////////////////////////////////////////
7578 
7579 Long_t TCling::MethodInfo_Property(MethodInfo_t* minfo) const
7580 {
7581  TClingMethodInfo* info = (TClingMethodInfo*) minfo;
7582  return info->Property();
7583 }
7584 
7585 ////////////////////////////////////////////////////////////////////////////////
7586 
7587 Long_t TCling::MethodInfo_ExtraProperty(MethodInfo_t* minfo) const
7588 {
7589  TClingMethodInfo* info = (TClingMethodInfo*) minfo;
7590  return info->ExtraProperty();
7591 }
7592 
7593 ////////////////////////////////////////////////////////////////////////////////
7594 
7595 TypeInfo_t* TCling::MethodInfo_Type(MethodInfo_t* minfo) const
7596 {
7597  TClingMethodInfo* info = (TClingMethodInfo*) minfo;
7598  return (TypeInfo_t*)info->Type();
7599 }
7600 
7601 ////////////////////////////////////////////////////////////////////////////////
7602 
7603 const char* TCling::MethodInfo_GetMangledName(MethodInfo_t* minfo) const
7604 {
7605  TClingMethodInfo* info = (TClingMethodInfo*) minfo;
7606  TTHREAD_TLS_DECL(TString, mangled_name);
7607  mangled_name = info->GetMangledName();
7608  return mangled_name;
7609 }
7610 
7611 ////////////////////////////////////////////////////////////////////////////////
7612 
7613 const char* TCling::MethodInfo_GetPrototype(MethodInfo_t* minfo) const
7614 {
7615  TClingMethodInfo* info = (TClingMethodInfo*) minfo;
7616  return info->GetPrototype(*fNormalizedCtxt);
7617 }
7618 
7619 ////////////////////////////////////////////////////////////////////////////////
7620 
7621 const char* TCling::MethodInfo_Name(MethodInfo_t* minfo) const
7622 {
7623  TClingMethodInfo* info = (TClingMethodInfo*) minfo;
7624  return info->Name(*fNormalizedCtxt);
7625 }
7626 
7627 ////////////////////////////////////////////////////////////////////////////////
7628 
7629 const char* TCling::MethodInfo_TypeName(MethodInfo_t* minfo) const
7630 {
7631  TClingMethodInfo* info = (TClingMethodInfo*) minfo;
7632  return info->TypeName();
7633 }
7634 
7635 ////////////////////////////////////////////////////////////////////////////////
7636 
7637 std::string TCling::MethodInfo_TypeNormalizedName(MethodInfo_t* minfo) const
7638 {
7639  TClingMethodInfo* info = (TClingMethodInfo*) minfo;
7640  if (info && info->IsValid())
7641  return info->Type()->NormalizedName(*fNormalizedCtxt);
7642  else
7643  return "";
7644 }
7645 
7646 ////////////////////////////////////////////////////////////////////////////////
7647 
7648 const char* TCling::MethodInfo_Title(MethodInfo_t* minfo) const
7649 {
7650  TClingMethodInfo* info = (TClingMethodInfo*) minfo;
7651  return info->Title();
7652 }
7653 
7654 ////////////////////////////////////////////////////////////////////////////////
7655 
7657 {
7658  if (func) {
7659  return MethodInfo_MethodCallReturnType(func->fInfo);
7660  } else {
7661  return EReturnType::kOther;
7662  }
7663 }
7664 
7665 ////////////////////////////////////////////////////////////////////////////////
7666 
7667 auto TCling::MethodInfo_MethodCallReturnType(MethodInfo_t* minfo) const -> EReturnType
7668 {
7669  TClingMethodInfo* info = (TClingMethodInfo*) minfo;
7670  if (info && info->IsValid()) {
7671  TClingTypeInfo *typeinfo = info->Type();
7672  clang::QualType QT( typeinfo->GetQualType().getCanonicalType() );
7673  if (QT->isEnumeralType()) {
7674  return EReturnType::kLong;
7675  } else if (QT->isPointerType()) {
7676  // Look for char*
7677  QT = llvm::cast<clang::PointerType>(QT)->getPointeeType();
7678  if ( QT->isCharType() ) {
7679  return EReturnType::kString;
7680  } else {
7681  return EReturnType::kOther;
7682  }
7683  } else if ( QT->isFloatingType() ) {
7684  int sz = typeinfo->Size();
7685  if (sz == 4 || sz == 8) {
7686  // Support only float and double.
7687  return EReturnType::kDouble;
7688  } else {
7689  return EReturnType::kOther;
7690  }
7691  } else if ( QT->isIntegerType() ) {
7692  int sz = typeinfo->Size();
7693  if (sz <= 8) {
7694  // Support only up to long long ... but
7695  // FIXME the TMethodCall::Execute only
7696  // return long (4 bytes) ...
7697  // The v5 implementation of TMethodCall::ReturnType
7698  // was not making the distinction so we let it go
7699  // as is for now, but we really need to upgrade
7700  // TMethodCall::Execute ...
7701  return EReturnType::kLong;
7702  } else {
7703  return EReturnType::kOther;
7704  }
7705  } else {
7706  return EReturnType::kOther;
7707  }
7708  } else {
7709  return EReturnType::kOther;
7710  }
7711 }
7712 
7713 //______________________________________________________________________________
7714 //
7715 // MethodArgInfo interface
7716 //
7717 
7718 ////////////////////////////////////////////////////////////////////////////////
7719 
7720 void TCling::MethodArgInfo_Delete(MethodArgInfo_t* marginfo) const
7721 {
7722  delete(TClingMethodArgInfo*) marginfo;
7723 }
7724 
7725 ////////////////////////////////////////////////////////////////////////////////
7726 
7727 MethodArgInfo_t* TCling::MethodArgInfo_Factory() const
7728 {
7730  return (MethodArgInfo_t*) new TClingMethodArgInfo(fInterpreter);
7731 }
7732 
7733 ////////////////////////////////////////////////////////////////////////////////
7734 
7735 MethodArgInfo_t* TCling::MethodArgInfo_Factory(MethodInfo_t *minfo) const
7736 {
7738  return (MethodArgInfo_t*) new TClingMethodArgInfo(fInterpreter, (TClingMethodInfo*)minfo);
7739 }
7740 
7741 ////////////////////////////////////////////////////////////////////////////////
7742 
7743 MethodArgInfo_t* TCling::MethodArgInfo_FactoryCopy(MethodArgInfo_t* marginfo) const
7744 {
7745  return (MethodArgInfo_t*)
7746  new TClingMethodArgInfo(*(TClingMethodArgInfo*)marginfo);
7747 }
7748 
7749 ////////////////////////////////////////////////////////////////////////////////
7750 
7751 bool TCling::MethodArgInfo_IsValid(MethodArgInfo_t* marginfo) const
7752 {
7753  TClingMethodArgInfo* info = (TClingMethodArgInfo*) marginfo;
7754  return info->IsValid();
7755 }
7756 
7757 ////////////////////////////////////////////////////////////////////////////////
7758 
7759 int TCling::MethodArgInfo_Next(MethodArgInfo_t* marginfo) const
7760 {
7761  TClingMethodArgInfo* info = (TClingMethodArgInfo*) marginfo;
7762  return info->Next();
7763 }
7764 
7765 ////////////////////////////////////////////////////////////////////////////////
7766 
7767 Long_t TCling::MethodArgInfo_Property(MethodArgInfo_t* marginfo) const
7768 {
7769  TClingMethodArgInfo* info = (TClingMethodArgInfo*) marginfo;
7770  return info->Property();
7771 }
7772 
7773 ////////////////////////////////////////////////////////////////////////////////
7774 
7775 const char* TCling::MethodArgInfo_DefaultValue(MethodArgInfo_t* marginfo) const
7776 {
7777  TClingMethodArgInfo* info = (TClingMethodArgInfo*) marginfo;
7778  return info->DefaultValue();
7779 }
7780 
7781 ////////////////////////////////////////////////////////////////////////////////
7782 
7783 const char* TCling::MethodArgInfo_Name(MethodArgInfo_t* marginfo) const
7784 {
7785  TClingMethodArgInfo* info = (TClingMethodArgInfo*) marginfo;
7786  return info->Name();
7787 }
7788 
7789 ////////////////////////////////////////////////////////////////////////////////
7790 
7791 const char* TCling::MethodArgInfo_TypeName(MethodArgInfo_t* marginfo) const
7792 {
7793  TClingMethodArgInfo* info = (TClingMethodArgInfo*) marginfo;
7794  return info->TypeName();
7795 }
7796 
7797 ////////////////////////////////////////////////////////////////////////////////
7798 
7799 std::string TCling::MethodArgInfo_TypeNormalizedName(MethodArgInfo_t* marginfo) const
7800 {
7801  TClingMethodArgInfo* info = (TClingMethodArgInfo*) marginfo;
7802  return info->Type()->NormalizedName(*fNormalizedCtxt);
7803 }
7804 
7805 //______________________________________________________________________________
7806 //
7807 // TypeInfo interface
7808 //
7809 
7810 ////////////////////////////////////////////////////////////////////////////////
7811 
7812 void TCling::TypeInfo_Delete(TypeInfo_t* tinfo) const
7813 {
7814  delete (TClingTypeInfo*) tinfo;
7815 }
7816 
7817 ////////////////////////////////////////////////////////////////////////////////
7818 
7819 TypeInfo_t* TCling::TypeInfo_Factory() const
7820 {
7822  return (TypeInfo_t*) new TClingTypeInfo(fInterpreter);
7823 }
7824 
7825 ////////////////////////////////////////////////////////////////////////////////
7826 
7827 TypeInfo_t* TCling::TypeInfo_Factory(const char *name) const
7828 {
7830  return (TypeInfo_t*) new TClingTypeInfo(fInterpreter, name);
7831 }
7832 
7833 ////////////////////////////////////////////////////////////////////////////////
7834 
7835 TypeInfo_t* TCling::TypeInfo_FactoryCopy(TypeInfo_t* tinfo) const
7836 {
7837  return (TypeInfo_t*) new TClingTypeInfo(*(TClingTypeInfo*)tinfo);
7838 }
7839 
7840 ////////////////////////////////////////////////////////////////////////////////
7841 
7842 void TCling::TypeInfo_Init(TypeInfo_t* tinfo, const char* name) const
7843 {
7845  TClingTypeInfo* TClinginfo = (TClingTypeInfo*) tinfo;
7846  TClinginfo->Init(name);
7847 }
7848 
7849 ////////////////////////////////////////////////////////////////////////////////
7850 
7851 bool TCling::TypeInfo_IsValid(TypeInfo_t* tinfo) const
7852 {
7853  TClingTypeInfo* TClinginfo = (TClingTypeInfo*) tinfo;
7854  return TClinginfo->IsValid();
7855 }
7856 
7857 ////////////////////////////////////////////////////////////////////////////////
7858 
7859 const char* TCling::TypeInfo_Name(TypeInfo_t* tinfo) const
7860 {
7861  TClingTypeInfo* TClinginfo = (TClingTypeInfo*) tinfo;
7862  return TClinginfo->Name();
7863 }
7864 
7865 ////////////////////////////////////////////////////////////////////////////////
7866 
7867 Long_t TCling::TypeInfo_Property(TypeInfo_t* tinfo) const
7868 {
7869  TClingTypeInfo* TClinginfo = (TClingTypeInfo*) tinfo;
7870  return TClinginfo->Property();
7871 }
7872 
7873 ////////////////////////////////////////////////////////////////////////////////
7874 
7875 int TCling::TypeInfo_RefType(TypeInfo_t* tinfo) const
7876 {
7877  TClingTypeInfo* TClinginfo = (TClingTypeInfo*) tinfo;
7878  return TClinginfo->RefType();
7879 }
7880 
7881 ////////////////////////////////////////////////////////////////////////////////
7882 
7883 int TCling::TypeInfo_Size(TypeInfo_t* tinfo) const
7884 {
7885  TClingTypeInfo* TClinginfo = (TClingTypeInfo*) tinfo;
7886  return TClinginfo->Size();
7887 }
7888 
7889 ////////////////////////////////////////////////////////////////////////////////
7890 
7891 const char* TCling::TypeInfo_TrueName(TypeInfo_t* tinfo) const
7892 {
7893  TClingTypeInfo* TClinginfo = (TClingTypeInfo*) tinfo;
7894  return TClinginfo->TrueName(*fNormalizedCtxt);
7895 }
7896 
7897 
7898 //______________________________________________________________________________
7899 //
7900 // TypedefInfo interface
7901 //
7902 
7903 ////////////////////////////////////////////////////////////////////////////////
7904 
7905 void TCling::TypedefInfo_Delete(TypedefInfo_t* tinfo) const
7906 {
7907  delete(TClingTypedefInfo*) tinfo;
7908 }
7909 
7910 ////////////////////////////////////////////////////////////////////////////////
7911 
7912 TypedefInfo_t* TCling::TypedefInfo_Factory() const
7913 {
7915  return (TypedefInfo_t*) new TClingTypedefInfo(fInterpreter);
7916 }
7917 
7918 ////////////////////////////////////////////////////////////////////////////////
7919 
7920 TypedefInfo_t* TCling::TypedefInfo_Factory(const char *name) const
7921 {
7923  return (TypedefInfo_t*) new TClingTypedefInfo(fInterpreter, name);
7924 }
7925 
7926 ////////////////////////////////////////////////////////////////////////////////
7927 
7928 TypedefInfo_t* TCling::TypedefInfo_FactoryCopy(TypedefInfo_t* tinfo) const
7929 {
7930  return (TypedefInfo_t*) new TClingTypedefInfo(*(TClingTypedefInfo*)tinfo);
7931 }
7932 
7933 ////////////////////////////////////////////////////////////////////////////////
7934 
7935 void TCling::TypedefInfo_Init(TypedefInfo_t* tinfo,
7936  const char* name) const
7937 {
7939  TClingTypedefInfo* TClinginfo = (TClingTypedefInfo*) tinfo;
7940  TClinginfo->Init(name);
7941 }
7942 
7943 ////////////////////////////////////////////////////////////////////////////////
7944 
7945 bool TCling::TypedefInfo_IsValid(TypedefInfo_t* tinfo) const
7946 {
7947  TClingTypedefInfo* TClinginfo = (TClingTypedefInfo*) tinfo;
7948  return TClinginfo->IsValid();
7949 }
7950 
7951 ////////////////////////////////////////////////////////////////////////////////
7952 
7953 Int_t TCling::TypedefInfo_Next(TypedefInfo_t* tinfo) const
7954 {
7955  TClingTypedefInfo* TClinginfo = (TClingTypedefInfo*) tinfo;
7956  return TClinginfo->Next();
7957 }
7958 
7959 ////////////////////////////////////////////////////////////////////////////////
7960 
7961 Long_t TCling::TypedefInfo_Property(TypedefInfo_t* tinfo) const
7962 {
7963  TClingTypedefInfo* TClinginfo = (TClingTypedefInfo*) tinfo;
7964  return TClinginfo->Property();
7965 }
7966 
7967 ////////////////////////////////////////////////////////////////////////////////
7968 
7969 int TCling::TypedefInfo_Size(TypedefInfo_t* tinfo) const
7970 {
7971  TClingTypedefInfo* TClinginfo = (TClingTypedefInfo*) tinfo;
7972  return TClinginfo->Size();
7973 }
7974 
7975 ////////////////////////////////////////////////////////////////////////////////
7976 
7977 const char* TCling::TypedefInfo_TrueName(TypedefInfo_t* tinfo) const
7978 {
7979  TClingTypedefInfo* TClinginfo = (TClingTypedefInfo*) tinfo;
7980  return TClinginfo->TrueName(*fNormalizedCtxt);
7981 }
7982 
7983 ////////////////////////////////////////////////////////////////////////////////
7984 
7985 const char* TCling::TypedefInfo_Name(TypedefInfo_t* tinfo) const
7986 {
7987  TClingTypedefInfo* TClinginfo = (TClingTypedefInfo*) tinfo;
7988  return TClinginfo->Name();
7989 }
7990 
7991 ////////////////////////////////////////////////////////////////////////////////
7992 
7993 const char* TCling::TypedefInfo_Title(TypedefInfo_t* tinfo) const
7994 {
7995  TClingTypedefInfo* TClinginfo = (TClingTypedefInfo*) tinfo;
7996  return TClinginfo->Title();
7997 }
EState GetState() const
Definition: TClass.h:443
int TCling__AutoLoadCallback(const char *className)
Definition: TCling.cxx:587
virtual TObject * FindObject(const TObject *obj) const
Find object using its hash value (returned by its Hash() member).
virtual MethodArgInfo_t * MethodArgInfo_Factory() const
Definition: TCling.cxx:7727
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:5967
void ResetCaches()
To clean out all caches.
Definition: TClass.cxx:3940
virtual Long_t MethodInfo_Property(MethodInfo_t *minfo) const
Definition: TCling.cxx:7579
virtual Long_t ClassInfo_ClassProperty(ClassInfo_t *info) const
Definition: TCling.cxx:6733
virtual const char * BaseName(const char *pathname)
Base name of a file name. Base name of /user/root is root.
Definition: TSystem.cxx:912
virtual Int_t GetEntries() const
Definition: TCollection.h:92
virtual Bool_t AccessPathName(const char *path, EAccessMode mode=kFileExists)
Returns FALSE if one can access a file using the specified access mode.
Definition: TSystem.cxx:1213
virtual void SetTempLevel(int val) const
Create / close a scope for temporaries.
Definition: TCling.cxx:6244
const clang::FunctionTemplateDecl * GetFunctionTemplate(const char *fname) const
Ssiz_t Last(char c) const
Find last occurrence of a character c.
Definition: TString.cxx:864
virtual void SetRcName(const char *name)
Definition: TEnv.h:149
TObject * GetObjectAddress(const char *Name, void *&LookupCtx)
If the interpreter encounters Name, check whether that is an object ROOT could retrieve.
Definition: TCling.cxx:6302
A collection of TDataMember objects designed for fast access given a DeclId_t and for keep track of T...
The TEnum class implements the enum type.
Definition: TEnum.h:42
virtual DeclId_t GetDataMemberAtAddr(const void *addr) const
Return pointer to cling DeclId for a data member with a given name.
Definition: TCling.cxx:3871
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:3950
int TCling__IsAutoLoadNamespaceCandidate(const clang::NamespaceDecl *nsDecl)
Definition: TCling.cxx:609
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:614
int GetClassVersion(const clang::RecordDecl *cl, const cling::Interpreter &interp)
Return the version number of the class or -1 if the function Class_Version does not exist...
An array of TObjects.
Definition: TObjArray.h:39
const char * Name() const
void * GetInterfaceMethod(TClass *cl, const char *method, const char *params, Bool_t objectIsConst=kFALSE)
Return pointer to cling interface function for a method of a class with parameters params (params is ...
Definition: TCling.cxx:3928
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:650
virtual void SetRTLD_NOW() const
Definition: TCling.cxx:6228
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:4028
void TransactionRollback(const cling::Transaction &T)
Definition: TCling.cxx:5820
virtual int TypedefInfo_Size(TypedefInfo_t *tinfo) const
Definition: TCling.cxx:7969
virtual TVirtualMutex * Factory(Bool_t=kFALSE)=0
virtual void SetAllocunlockfunc(void(*)()) const
[Place holder for Mutex Unlock] Provide the interpreter with a way to release a lock used to protect ...
Definition: TCling.cxx:6161
Bool_t IsOnHeap() const
Definition: TObject.h:140
void AddTemplAndNargsToKeep(const clang::ClassTemplateDecl *templ, unsigned int i)
Definition: TMetaUtils.cxx:341
virtual bool ClassInfo_HasDefaultConstructor(ClassInfo_t *info) const
Definition: TCling.cxx:6803
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:5843
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:2877
virtual CallFuncIFacePtr_t CallFunc_IFacePtr(CallFunc_t *func) const
Definition: TCling.cxx:6548
void TCling__UpdateListsOnCommitted(const cling::Transaction &T, cling::Interpreter *)
Definition: TCling.cxx:538
virtual void PostLoadCheck()
Do the initialization that can only be done after the CINT dictionary has been fully populated and ca...
Definition: TClass.cxx:5552
virtual void BaseClassInfo_Delete(BaseClassInfo_t *bcinfo) const
Definition: TCling.cxx:6997
virtual DataMemberInfo_t * DataMemberInfo_Factory(ClassInfo_t *clinfo=0) const
Definition: TCling.cxx:7131
virtual bool CallFunc_IsValid(CallFunc_t *func) const
Definition: TCling.cxx:6539
static void ConstructorName(std::string &name, const clang::NamedDecl *decl, cling::Interpreter &interp, const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt)
Definition: TCling.cxx:7272
R__EXTERN Int_t gErrorIgnoreLevel
Definition: TError.h:107
virtual int ClassInfo_Next(ClassInfo_t *info) const
Definition: TCling.cxx:6884
bool IsLoaded() const
virtual const char * WorkingDirectory()
Return working directory.
Definition: TSystem.cxx:865
virtual Int_t UnLock()=0
virtual const char * DataMemberInfo_TypeName(DataMemberInfo_t *dminfo) const
Definition: TCling.cxx:7214
virtual void CallFunc_ExecWithReturn(CallFunc_t *func, void *address, void *ret) const
Definition: TCling.cxx:6456
Namespace for new ROOT classes and functions.
Definition: ROOT.py:1
std::map< SpecialObjectLookupCtx_t, SpecialObjectMap_t > fSpecialObjectMaps
Definition: TCling.h:143
virtual TypedefInfo_t * TypedefInfo_FactoryCopy(TypedefInfo_t *tinfo) const
Definition: TCling.cxx:7928
void Update(DeclId_t id)
Definition: TEnum.cxx:101
short Version_t
Definition: RtypesCore.h:61
virtual TObject * FindObject(const char *name) const
Find an object in this collection using its name.
static Bool_t Check(const char *cname, std::string &normname)
Int_t GetType() const
Definition: TDataType.h:70
static const char **& GetExtraInterpreterArgs()
Definition: TROOT.cxx:2499
static cling::Interpreter::CompilationResult ExecAutoParse(const char *what, Bool_t header, cling::Interpreter *interpreter)
Parse the payload or header.
Definition: TCling.cxx:5099
Ssiz_t Length() const
Definition: TString.h:390
TLine * line
bool IsValid() const
void RegisterLoadedSharedLibrary(const char *name)
Register a new shared library name with the interpreter; add it to fSharedLibs.
Definition: TCling.cxx:2661
Collectable string class.
Definition: TObjString.h:32
float Float_t
Definition: RtypesCore.h:53
static void AddClassToDeclIdMap(TDictionary::DeclId_t id, TClass *cl)
static: Add a TClass* to the map of classes.
Definition: TClass.cxx:467
const char * Name() const
virtual DeclId_t GetEnum(TClass *cl, const char *name) const
Return pointer to cling Decl of global/static variable that is located at the address given by addr...
Definition: TCling.cxx:3757
R__EXTERN TClassTable * gClassTable
Definition: TClassTable.h:97
TClass * GetClass() const
const char * GetPrototype(const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt) const
Definition: TEnv.h:76
void UpdateListsOnCommitted(const cling::Transaction &T)
Definition: TCling.cxx:5557
TDictionary::DeclId_t DeclId_t
Definition: TInterpreter.h:236
virtual int BaseClassInfo_Next(BaseClassInfo_t *bcinfo) const
Definition: TCling.cxx:7024
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:667
TEnum * Find(DeclId_t id) const
Return the TEnum corresponding to the Decl &#39;id&#39; or NULL if it does not exist.
Dictionary for function template This class describes one single function template.
double ExecDouble(void *address)
void Init(const char *name)
virtual TypeInfo_t * TypeInfo_FactoryCopy(TypeInfo_t *) const
Definition: TCling.cxx:7835
All ROOT classes may have RTTI (run time type identification) support added.
Definition: TDataMember.h:33
int GetSplit(const char *type, std::vector< std::string > &output, int &nestedLoc, EModType mode=TClassEdit::kNone)
Stores in output (after emptying it) the splited type.
Definition: TClassEdit.cxx:937
virtual void MethodInfo_CreateSignature(MethodInfo_t *minfo, TString &signature) const
Definition: TCling.cxx:7498
static TProtoClass * GetProtoNorm(const char *cname)
Given the class normalized name returns the TClassProto object for the class.
TObject * FindObject(const char *name) const
Find object using its name.
Definition: THashList.cxx:212
A collection of TFunction objects designed for fast access given a DeclId_t and for keep track of TFu...
double T(double x)
Definition: ChebyshevPol.h:34
int GetMethodNArg(const char *method, const char *proto, Bool_t objectIsConst, ROOT::EFunctionMatchMode mode=ROOT::kConversionMatch) const
R__EXTERN TVirtualMutex * gInterpreterMutex
Definition: TInterpreter.h:46
bool TClingLookupHelper__ExistingTypeCheck(const std::string &tname, std::string &result)
Try hard to avoid looking up in the Cling database as this could enduce an unwanted autoparsing...
Definition: TCling.cxx:900
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
const char * Name() const
bool HasMethod(const char *name) const
void Init(const char *name)
Lookup named typedef and reset the iterator to point to it.
#define assert(cond)
Definition: unittest.h:542
std::atomic< TListOfEnums * > fEnums
Definition: TClass.h:185
virtual CallFunc_t * CallFunc_FactoryCopy(CallFunc_t *func) const
Definition: TCling.cxx:6507
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:1311
virtual void Update()=0
#define gDirectory
Definition: TDirectory.h:218
void SetFunc(const TClingClassInfo *info, const char *method, const char *arglist, long *poffset)
void Destruct(void *arena, const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt) const
Double_t distance(const TPoint2 &p1, const TPoint2 &p2)
Definition: CsgOps.cxx:467
virtual const char * MethodInfo_Title(MethodInfo_t *minfo) const
Definition: TCling.cxx:7648
void SetArgArray(long *argArr, int narg)
virtual TList * GetListOfKeys() const
cling::MetaProcessor * fMetaProcessor
Definition: TCling.h:121
virtual int DataMemberInfo_TypeSize(DataMemberInfo_t *dminfo) const
Definition: TCling.cxx:7206
virtual void SetOwner(Bool_t enable=kTRUE)
Set whether this collection is the owner (enable==true) of its content.
const char * GetFullTypeName() const
Get full type description of typedef, e,g.: "class TDirectory*".
Definition: TDataType.cxx:175
Persistent version of a TClass.
Definition: TProtoClass.h:37
virtual void SetRTLD_LAZY() const
Definition: TCling.cxx:6235
Emulation of the CINT DataMemberInfo class.
TEnum * Get(DeclId_t id, const char *name)
Return (after creating it if necessary) the TEnum describing the enum corresponding to the Decl &#39;id&#39;...
std::atomic< Bool_t > fHasRootPcmInfo
C++ Property of the class (is abstract, has virtual table, etc.)
Definition: TClass.h:230
TClass * GenerateTClass(const char *classname, Bool_t emulation, Bool_t silent=kFALSE)
Generate a TClass for the given class.
Definition: TCling.cxx:3509
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
Definition: TObject.cxx:892
Int_t LastIndex() const
void UpdateListOfGlobals()
No op: see TClingCallbacks (used to update the list of globals)
Definition: TCling.cxx:3088
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format...
Definition: TFile.h:45
void UpdateListOfGlobalFunctions()
No op: see TClingCallbacks (used to update the list of global functions)
Definition: TCling.cxx:3095
Emulation of the CINT MethodInfo class.
int NDefaultArg() const
ptrdiff_t GetBaseOffset(TClingClassInfo *toBase, void *address, bool isDerivedObject)
virtual std::string MethodArgInfo_TypeNormalizedName(MethodArgInfo_t *marginfo) const
Definition: TCling.cxx:7799
const char * Name() const
void SaveContext()
Save the current Cling state.
Definition: TCling.cxx:3062
virtual MethodInfo_t * CallFunc_FactoryMethod(CallFunc_t *func) const
Definition: TCling.cxx:6514
cling::Interpreter * fInterpreter
Definition: TCling.h:120
virtual ClassInfo_t * ClassInfo_Factory(Bool_t all=kTRUE) const
Definition: TCling.cxx:6772
virtual const char * HomeDirectory(const char *userName=0)
Return the user&#39;s home directory.
Definition: TSystem.cxx:873
void SetArg(long arg)
static void RemoveClassDeclId(TDictionary::DeclId_t id)
Definition: TClass.cxx:492
Long_t Property() const
Set TObject::fBits and fStreamerType to cache information about the class.
Definition: TClass.cxx:5631
virtual BaseClassInfo_t * BaseClassInfo_Factory(ClassInfo_t *info) const
Definition: TCling.cxx:7004
const char * GetClassSharedLibs(const char *cls)
Get the list of shared libraries containing the code for class cls.
Definition: TCling.cxx:5870
const char * GetValue() const
Definition: TEnv.h:114
void TCling__DEBUG__dump(clang::DeclContext *DC)
Definition: TCling.cxx:206
const TClingTypeInfo * Type() const
virtual TObject * FindObject(const char *name) const
Specialize FindObject to do search for the a function just by name or create it if its not already in...
virtual void MethodInfo_Delete(MethodInfo_t *minfo) const
Interface to cling function.
Definition: TCling.cxx:7491
virtual void CallFunc_SetArgArray(CallFunc_t *func, Long_t *paramArr, Int_t nparam) const
Definition: TCling.cxx:6612
virtual const char * TypedefInfo_TrueName(TypedefInfo_t *tinfo) const
Definition: TCling.cxx:7977
static const char * filename()
Bool_t IsPersistent() const
Definition: TDataMember.h:89
#define R__ASSERT(e)
Definition: TError.h:98
void TCling__UpdateListsOnUnloaded(const cling::Transaction &T)
Definition: TCling.cxx:544
#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 LoadPCM(TString pcmFileName, const char **headers, void(*triggerFunc)()) const
Tries to load a PCM; returns true on success.
Definition: TCling.cxx:1267
clang::QualType ReSubstTemplateArg(clang::QualType input, const clang::Type *instance)
Check if &#39;input&#39; or any of its template parameter was substituted when instantiating the class templa...
virtual Bool_t IsTreatingNonAccessibleTypes()
virtual FuncTempInfo_t * FuncTempInfo_FactoryCopy(FuncTempInfo_t *) const
Construct a FuncTempInfo_t.
Definition: TCling.cxx:7343
void FullName(std::string &output, const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt) const
Int_t Load(const char *filenam, Bool_t system=kFALSE)
Load a library file in cling&#39;s memory.
Definition: TCling.cxx:2733
virtual int Load(const char *module, const char *entry="", Bool_t system=kFALSE)
Load a shared library.
Definition: TSystem.cxx:1766
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:197
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:4965
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:3883
static Bool_t HasNoInfoOrEmuOrFwdDeclaredDecl(const char *)
Definition: TClass.cxx:3170
bool HasDefaultConstructor() const
virtual TApplicationImp * GetApplicationImp()
Definition: TApplication.h:137
int Int_t
Definition: RtypesCore.h:41
TClingMethodInfo GetMethod(const char *fname) const
TClingTypeInfo * Type() const
virtual const char * DirName(const char *pathname)
Return the directory name in pathname.
Definition: TSystem.cxx:980
bool Bool_t
Definition: RtypesCore.h:59
virtual const char * MethodInfo_GetMangledName(MethodInfo_t *minfo) const
Definition: TCling.cxx:7603
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:7366
TArc * a
Definition: textangle.C:12
virtual int DisplayIncludePath(FILE *fout) const
Interface to cling function.
Definition: TCling.cxx:6016
std::vector< std::pair< std::string, int > > FwdDeclArgsToKeepCollection_t
Definition: TInterpreter.h:108
const Bool_t kFALSE
Definition: Rtypes.h:92
void * fPrevLoadedDynLibInfo
Definition: TCling.h:127
#define gInterpreter
Definition: TInterpreter.h:502
const char * fantomline
Definition: TCling.cxx:838
virtual char * Which(const char *search, const char *file, EAccessMode mode=kFileExists)
Find location of file in a search path.
Definition: TSystem.cxx:1459
Each ROOT method (see TMethod) has a linked list of its arguments.
Definition: TMethodArg.h:33
virtual const char * BaseClassInfo_Name(BaseClassInfo_t *bcinfo) const
Definition: TCling.cxx:7095
virtual void TypeInfo_Delete(TypeInfo_t *tinfo) const
Definition: TCling.cxx:7812
virtual Long_t CallFunc_ExecInt(CallFunc_t *func, void *address) const
Definition: TCling.cxx:6475
Int_t DeleteVariable(const char *name)
Undeclare obj called name.
Definition: TCling.cxx:3003
virtual int SetClassAutoparsing(int)
Enable/Disable the Autoparsing of headers.
Definition: TCling.cxx:6185
long Tagnum() const
STL namespace.
Int_t GetEntriesFast() const
Definition: TObjArray.h:66
llvm::StringRef ValidArrayIndex() const
virtual int LoadFile(const char *path) const
Load a source file or library called path into the interpreter.
Definition: TCling.cxx:6116
const char * TrueName(const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt) const
Get the name of the underlying type of the current typedef.
TString & Prepend(const char *cs)
Definition: TString.h:604
void SetAutoParsingSuspended(bool val=true)
R__EXTERN TApplication * gApplication
Definition: TApplication.h:171
Abstract base class for accessing the data-members of a class.
const char * FileName()
virtual void TypeInfo_Init(TypeInfo_t *tinfo, const char *funcname) const
Definition: TCling.cxx:7842
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:3910
std::vector< cling::Value > * fTemporaries
Definition: TCling.h:123
virtual ~TCling()
Destroy the interpreter interface.
Definition: TCling.cxx:1184
virtual const char * DataMemberInfo_Title(DataMemberInfo_t *dminfo) const
Definition: TCling.cxx:7238
virtual void LoadFunctionTemplates(TClass *cl) const
Create list of pointers to function templates for TClass cl.
Definition: TCling.cxx:3416
void GetCppName(std::string &output, const char *input)
Return (in the argument &#39;output&#39;) a mangled version of the C++ symbol/type (pass as &#39;input&#39;) that can...
virtual bool MethodArgInfo_IsValid(MethodArgInfo_t *marginfo) const
Definition: TCling.cxx:7751
const char * Title()
virtual bool Update(FuncTempInfo_t *info)
Update the TFunctionTemplate to reflect the new info.
virtual Long_t DataMemberInfo_Property(DataMemberInfo_t *dminfo) const
Definition: TCling.cxx:7190
virtual Long_t TypedefInfo_Property(TypedefInfo_t *tinfo) const
Definition: TCling.cxx:7961
virtual void * ClassInfo_New(ClassInfo_t *info) const
Definition: TCling.cxx:6892
const clang::Type * GetType() const
Bool_t BeginsWith(const char *s, ECaseCompare cmp=kExact) const
Definition: TString.h:558
static double A[]
Emulation of the CINT CallFunc class.
virtual int DisplayClass(FILE *fout, const char *name, int base, int start) const
Definition: TCling.cxx:6007
void GetQualifiedName(std::string &qual_name, const clang::QualType &type, const clang::NamedDecl &forcontext)
Main implementation relying on GetFullyQualifiedTypeName All other GetQualifiedName functions leverag...
virtual const char * GetTopLevelMacroName() const
Return the file name of the current un-included interpreted file.
Definition: TCling.cxx:4311
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
static const TString & GetIncludeDir()
Get the include directory in the installation. Static utility function.
Definition: TROOT.cxx:2579
virtual int GetProcInfo(ProcInfo_t *info) const
Returns cpu and memory used by this process into the ProcInfo_t structure.
Definition: TSystem.cxx:2379
MethodInfo_t * fInfo
Definition: TFunction.h:36
Bool_t R_ISREG(Int_t mode)
Definition: TSystem.h:129
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition: TObject.cxx:732
virtual void SetDeclAttr(DeclId_t, const char *)
Definition: TCling.cxx:7257
virtual bool ClassInfo_IsValidMethod(ClassInfo_t *info, const char *method, const char *proto, Long_t *offset, ROOT::EFunctionMatchMode=ROOT::kConversionMatch) const
Definition: TCling.cxx:6868
virtual int DataMemberInfo_MaxIndex(DataMemberInfo_t *dminfo, Int_t dim) const
Definition: TCling.cxx:7166
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:4128
virtual const char * FindFile(const char *search, TString &file, EAccessMode mode=kFileExists)
Find location of file in a search path.
Definition: TSystem.cxx:1449
const char * GetSharedLibDeps(const char *lib)
Get the list a libraries on which the specified lib depends.
Definition: TCling.cxx:5912
const char * Name
Definition: TXMLSetup.cxx:67
static const char * GetMacroPath()
Get macro search path. Static utility function.
Definition: TROOT.cxx:2394
bool ExtractAttrPropertyFromName(const clang::Decl &decl, const std::string &propName, std::string &propValue)
This routine counts on the "propName<separator>propValue" format.
virtual void SetValue(const char *name, const char *value, EEnvLevel level=kEnvChange, const char *type=0)
Set the value of a resource or create a new resource.
Definition: TEnv.cxx:725
std::set< size_t > fPayloads
Definition: TCling.h:112
TDictionary * Find(DeclId_t id) const
Return (after creating it if necessary) the TDataMember describing the data member corresponding to t...
Int_t fMode
Definition: TSystem.h:138
const TSeqCollection * GetConstants() const
Definition: TEnum.h:66
virtual Long_t GetExecByteCode() const
This routines used to return the address of the internal wrapper function (of the interpreter) that w...
Definition: TCling.cxx:6075
virtual void MethodArgInfo_Delete(MethodArgInfo_t *marginfo) const
Definition: TCling.cxx:7720
std::vector< const char * > fCurExecutingMacros
Definition: TCling.h:139
Bool_t IsValid()
Return true if this data member object is pointing to a currently loaded data member.
virtual int TypeInfo_RefType(TypeInfo_t *) const
Definition: TCling.cxx:7875
const char * Data() const
Definition: TString.h:349
void AddFriendToClass(clang::FunctionDecl *, clang::CXXRecordDecl *) const
Inject function as a friend into klass.
Definition: TCling.cxx:6357
virtual Long_t BaseClassInfo_Offset(BaseClassInfo_t *toBaseClassInfo, void *address, bool isDerivedObject) const
Definition: TCling.cxx:7040
virtual TObject * FindObject(const char *name) const
Find an object in this collection using its name.
Definition: TObjArray.cxx:395
void TCling__DEBUG__decl_dump(void *D)
Definition: TCling.cxx:215
Int_t UnloadLibraryMap(const char *library)
Unload library map entries coming from the specified library.
Definition: TCling.cxx:4869
virtual void Fatal(const char *method, const char *msgfmt,...) const
Issue fatal error message.
Definition: TObject.cxx:946
virtual TEnum * CreateEnum(void *VD, TClass *cl) const
Definition: TCling.cxx:420
virtual void GenericError(const char *error) const
Let the interpreter issue a generic error, and set its error state.
Definition: TCling.cxx:6053
void ClearStack()
Delete existing temporary values.
Definition: TCling.cxx:2418
virtual const char * GetDirEntry(void *dirp)
Get a directory entry. Returns 0 if no more entries.
Definition: TSystem.cxx:847
virtual void ClassInfo_Init(ClassInfo_t *info, const char *funcname) const
Definition: TCling.cxx:6819
void ResetAll()
Reset the Cling state to its initial state.
Definition: TCling.cxx:2929
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:4420
const clang::Type * GetUnderlyingType(clang::QualType type)
Return the base/underlying type of a chain of array or pointers type.
int Next()
Increment the iterator.
void CreateSignature(TString &signature) const
virtual void CallFunc_Init(CallFunc_t *func) const
Definition: TCling.cxx:6530
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:3681
THashTable implements a hash table to store TObject&#39;s.
Definition: THashTable.h:39
const char * TCling__GetClassSharedLibs(const char *className)
Definition: TCling.cxx:597
clang::NamespaceDecl * TCling__DEBUG__DCtoNamespace(clang::DeclContext *DC)
Definition: TCling.cxx:200
const Config_t & GetConfig() const
Definition: TMetaUtils.cxx:335
void ExecuteWithArgsAndReturn(TMethod *method, void *address, const void *args[]=0, int nargs=0, void *ret=0) const
Definition: TCling.cxx:4280
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:3726
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString...
Definition: TString.cxx:2334
virtual TypedefInfo_t * TypedefInfo_Factory() const
Definition: TCling.cxx:7912
virtual Long_t BaseClassInfo_Property(BaseClassInfo_t *bcinfo) const
Definition: TCling.cxx:7061
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:3204
virtual void CallFunc_Exec(CallFunc_t *func, void *address) const
Definition: TCling.cxx:6440
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:2431
std::map< const cling::Transaction *, size_t > fTransactionHeadersMap
Definition: TCling.h:110
virtual UInt_t FuncTempInfo_TemplateMinReqArgs(FuncTempInfo_t *) const
Return the number of required template arguments of the function template described by ft_info...
Definition: TCling.cxx:7377
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:4095
The TNamed class is the base class for all named ROOT classes.
Definition: TNamed.h:33
void SetObjectValidity(EObjectPointerState val)
const char * Title()
void CreateListOfDataMembers(TClass *cl) const
Create list of pointers to data members for TClass cl.
Definition: TCling.cxx:3453
void SetArgs(const char *args)
char * DemangleName(const char *mangled_name, int &errorCode)
Definition: TClassEdit.h:178
void * GetInterfaceMethodWithPrototype(TClass *cl, const char *method, const char *proto, Bool_t objectIsConst=kFALSE, ROOT::EFunctionMatchMode mode=ROOT::kConversionMatch)
Return pointer to cling interface function for a method of a class with a certain prototype...
Definition: TCling.cxx:4005
virtual void ClassInfo_DeleteArray(ClassInfo_t *info, void *arena, bool dtorOnly) const
Definition: TCling.cxx:6756
long ClassProperty() const
DeclId_t GetFunctionWithPrototype(ClassInfo_t *cl, const char *method, const char *proto, Bool_t objectIsConst=kFALSE, ROOT::EFunctionMatchMode mode=ROOT::kConversionMatch)
Return pointer to cling interface function for a method of a class with a certain prototype...
Definition: TCling.cxx:4050
void Init(TClassEdit::TInterpreterLookupHelper *helper)
Definition: TClassEdit.cxx:118
virtual MethodInfo_t * MethodInfo_FactoryCopy(MethodInfo_t *minfo) const
Definition: TCling.cxx:7532
void ClearFileBusy()
Reset the interpreter internal state in case a previous action was not correctly terminated.
Definition: TCling.cxx:2410
virtual Int_t Lock()=0
static void UpdateClassInfo(char *name, Long_t tagnum)
No op: see TClingCallbacks.
Definition: TCling.cxx:5531
TClass * GetClass() const
Definition: TListOfEnums.h:66
void CreateListOfBaseClasses(TClass *cl) const
Create list of pointers to base class(es) for TClass cl.
Definition: TCling.cxx:3347
virtual const char * GetDynamicPath()
Return the dynamic path (used to find shared libraries).
Definition: TSystem.cxx:1705
virtual Long_t DataMemberInfo_Offset(DataMemberInfo_t *dminfo) const
Definition: TCling.cxx:7182
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:1019
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:2716
virtual const char * ClassInfo_FileName(ClassInfo_t *info) const
Definition: TCling.cxx:6948
virtual const char * TypeInfo_Name(TypeInfo_t *) const
Definition: TCling.cxx:7859
virtual const char * Getenv(const char *env)
Get environment variable.
Definition: TSystem.cxx:1575
virtual const char * MapCppName(const char *) const
Interface to cling function.
Definition: TCling.cxx:6138
TEnv * fMapfile
Definition: TCling.h:108
EFunctionMatchMode
Definition: TDictionary.h:155
TString & Append(const char *cs)
Definition: TString.h:492
static bool IsEnum(cling::Interpreter *interp, const char *name)
virtual const char * PrependPathName(const char *dir, TString &name)
Concatenate a directory and a file name.
Definition: TSystem.cxx:1038
virtual const char * GetCurrentMacroName() const
Return the file name of the currently interpreted file, included or not.
Definition: TCling.cxx:4358
virtual int SetClassAutoloading(int) const
Enable/Disable the Autoloading of libraries.
Definition: TCling.cxx:6170
ULong64_t fTransactionCount
Definition: TCling.h:138
const char * GetDefault() const
Get default value of method argument.
Definition: TMethodArg.cxx:58
TList * fBase
Definition: TClass.h:182
virtual bool ClassInfo_IsBase(ClassInfo_t *info, const char *name) const
Definition: TCling.cxx:6837
char * DemangleTypeIdName(const std::type_info &ti, int &errorCode)
Demangle in a portable way the type id name.
virtual Long_t ClassInfo_GetBaseOffset(ClassInfo_t *fromDerived, ClassInfo_t *toBase, void *address, bool isDerivedObject) const
Definition: TCling.cxx:7048
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:3950
virtual int MethodInfo_NArg(MethodInfo_t *minfo) const
Definition: TCling.cxx:7555
bool IsValid() const
long Property() const
Return a bit mask of metadata about the current typedef.
virtual void Setgvp(Long_t) const
Interface to the cling global object pointer which was controlling the behavior of the wrapper around...
Definition: TCling.cxx:6220
const char * TypeName() const
Long_t ProcessLine(const char *line, EErrorCode *error=0)
Let cling process a command line.
Definition: TCling.cxx:1843
virtual Long_t ClassInfo_Property(ClassInfo_t *info) const
Definition: TCling.cxx:6924
virtual bool Update(DataMemberInfo_t *info)
Update the TFunction to reflect the new info.
R__EXTERN int optind
Definition: TCling.cxx:300
static void Add(const char *cname, Version_t id, const type_info &info, DictFuncPtr_t dict, Int_t pragmabits)
Add a class to the class table (this is a static function).
Emulation of the CINT TypeInfo class.
virtual int TypedefInfo_Next(TypedefInfo_t *tinfo) const
Definition: TCling.cxx:7953
virtual bool TypeInfo_IsValid(TypeInfo_t *tinfo) const
Definition: TCling.cxx:7851
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:918
clang::RecordDecl * TCling__DEBUG__DCtoRecordDecl(clang::DeclContext *DC)
Definition: TCling.cxx:203
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
TVirtualPad is an abstract base class for the Pad and Canvas classes.
Definition: TVirtualPad.h:59
DeclId_t GetDeclId(const llvm::GlobalValue *gv) const
Return pointer to cling DeclId for a global value.
Definition: TCling.cxx:3793
def Namespace(name)
Definition: cppyy.py:193
const char * TypeTrueName(const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt) const
Int_t UnloadAllSharedLibraryMaps()
Unload the library map entries coming from all the loaded shared libraries.
Definition: TCling.cxx:4851
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:4523
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:2039
virtual bool ClassInfo_IsEnum(const char *name) const
Definition: TCling.cxx:6845
static void TCling__UpdateClassInfo(const NamedDecl *TD)
Update TClingClassInfo for a class (e.g. upon seeing a definition).
Definition: TCling.cxx:342
void * InterfaceMethod()
void TCling__DEBUG__printName(clang::Decl *D)
Definition: TCling.cxx:218
EComplexType GetComplexType(const char *)
Definition: TClassEdit.cxx:96
long ExtraProperty() const
void GetObject(const char *namecycle, T *&ptr)
virtual Long_t DataMemberInfo_TypeProperty(DataMemberInfo_t *dminfo) const
Definition: TCling.cxx:7198
TCppMethod_t GetMethod(TCppScope_t scope, TCppIndex_t imeth)
Definition: Cppyy.cxx:700
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:126
void PrintIntro()
No-op; see TRint instead.
Definition: TCling.cxx:2021
TString fRootmapLoadPath
Definition: TCling.h:107
R__EXTERN TVirtualMutex * gGlobalMutex
Definition: TVirtualMutex.h:29
virtual Int_t ReadFile(const char *fname, EEnvLevel level)
Read and parse the resource file for a certain level.
Definition: TEnv.cxx:581
const Decl * TCling__GetObjectDecl(TObject *obj)
Definition: TCling.cxx:570
R__EXTERN TROOT * gROOTLocal
Definition: TROOT.h:349
void UpdateListOfTypes()
No op: see TClingCallbacks (used to update the list of types)
Definition: TCling.cxx:3102
virtual const char * TypeInfo_TrueName(TypeInfo_t *tinfo) const
Definition: TCling.cxx:7891
void GetNormalizedName(std::string &norm_name, const clang::QualType &type, const cling::Interpreter &interpreter, const TNormalizedCtxt &normCtxt)
Return the type name normalized for ROOT, keeping only the ROOT opaque typedef (Double32_t, etc.) and adding default template argument for all types except the STL collections where we remove the default template argument if any.
virtual std::string MethodInfo_TypeNormalizedName(MethodInfo_t *minfo) const
Definition: TCling.cxx:7637
const char * Name() const
Definition: TEnv.h:91
const char * TmpltName() const
UInt_t AutoParseImplRecurse(const char *cls, bool topLevel)
Helper routine for TCling::AutoParse implementing the actual call to the parser and looping over temp...
Definition: TCling.cxx:5164
virtual TList * GetListOfMethodArgs()
Returns methodarg list and additionally updates fDataMember in TMethod by calling FindDataMember();...
Definition: TMethod.cxx:305
virtual void CallFunc_SetArgs(CallFunc_t *func, const char *param) const
Definition: TCling.cxx:6620
const char * TmpltName() const
void Init(const char *name)
void function(const char *name_, T fun, const char *docstring=0)
Definition: RExports.h:159
bool TCling__TEST_isInvalidDecl(clang::Decl *D)
Definition: TCling.cxx:233
TClingClassInfo * GetBase() const
std::vector< void * > fRegisterModuleDyLibs
Definition: TCling.h:128
TFunctionTemplate * Get(DeclId_t id)
Return (after creating it if necessary) the TMethod or TFunction describing the function correspondin...
Int_t AutoParse(const char *cls)
Parse the headers relative to the class Returns 1 in case of success, 0 in case of failure...
Definition: TCling.cxx:5292
virtual bool MethodInfo_IsValid(MethodInfo_t *minfo) const
Definition: TCling.cxx:7547
int MaxIndex(int dim) const
void TCling__SplitAclicMode(const char *fileName, string &mode, string &args, string &io, string &fname)
Definition: TCling.cxx:621
static double C[]
const char * GetName() const
Returns name of object.
Definition: TEnv.h:113
int Size() const
virtual Long_t TypeInfo_Property(TypeInfo_t *tinfo) const
Definition: TCling.cxx:7867
Bool_t EndsWith(const char *pat, ECaseCompare cmp=kExact) const
Return true if string ends with the specified string.
Definition: TString.cxx:2220
Emulation of the CINT BaseClassInfo class.
TClingMethodInfo * FactoryMethod() const
Double_t length(const TVector2 &v)
Definition: CsgOps.cxx:347
R__EXTERN TSystem * gSystem
Definition: TSystem.h:545
void * InterfaceMethod(const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt) const
virtual const char * DataMemberInfo_TypeTrueName(DataMemberInfo_t *dminfo) const
Definition: TCling.cxx:7222
ptrdiff_t Offset(void *address=0, bool isDerivedObject=true) const
virtual void GetFunctionName(const clang::FunctionDecl *decl, std::string &name) const
Definition: TCling.cxx:7294
Basic data type descriptor (datatype information is obtained from CINT).
Definition: TDataType.h:46
void SetFuncProto(const TClingClassInfo *info, const char *method, const char *proto, long *poffset, ROOT::EFunctionMatchMode mode=ROOT::kConversionMatch)
virtual void LoadEnums(TListOfEnums &cl) const
Create list of pointers to enums for TClass cl.
Definition: TCling.cxx:3371
std::set< TClass * > & GetModTClasses()
Definition: TCling.h:505
virtual int TypeInfo_Size(TypeInfo_t *tinfo) const
Definition: TCling.cxx:7883
static void UpdateAllCanvases()
Update all canvases at end the terminal input command.
Definition: TCling.cxx:5546
const clang::FunctionDecl * GetMethodDecl() const
const char * TrueName(const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt) const
Return the normalized name of the type (i.e.
ClassInfo_t * GetClassInfo() const
Definition: TClass.h:391
virtual CallFunc_t * CallFunc_Factory() const
Definition: TCling.cxx:6499
Long_t fMemVirtual
Definition: TSystem.h:207
const char * DefaultValue() const
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
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:5953
int TCling__AutoParseCallback(const char *className)
Definition: TCling.cxx:592
virtual const char * DataMemberInfo_ValidArrayIndex(DataMemberInfo_t *dminfo) const
Definition: TCling.cxx:7246
void SaveGlobalsContext()
Save the current Cling state of global objects.
Definition: TCling.cxx:3075
void UpdateClassInfoWithDecl(const void *vTD)
Internal function. Inform a TClass about its new TagDecl or NamespaceDecl.
Definition: TCling.cxx:5458
unsigned int UInt_t
Definition: RtypesCore.h:42
virtual Long_t BaseClassInfo_Tagnum(BaseClassInfo_t *bcinfo) const
Definition: TCling.cxx:7077
Bool_t TestBit(UInt_t f) const
Definition: TObject.h:173
virtual Bool_t IsValid()
Return true if this global object is pointing to a currently loaded global.
Definition: TGlobal.cxx:131
TMarker * m
Definition: textangle.C:8
virtual const char * ClassInfo_Title(ClassInfo_t *info) const
Definition: TCling.cxx:6974
void UpdateListOfLoadedSharedLibraries()
Definition: TCling.cxx:2586
char * Form(const char *fmt,...)
virtual void CallFunc_SetFunc(CallFunc_t *func, ClassInfo_t *info, const char *method, const char *params, Long_t *Offset) const
Definition: TCling.cxx:6628
virtual TypeInfo_t * MethodInfo_Type(MethodInfo_t *minfo) const
Definition: TCling.cxx:7595
Long_t Calc(const char *line, EErrorCode *error=0)
Directly execute an executable statement (e.g.
Definition: TCling.cxx:2807
Double_t E()
Definition: TMath.h:54
Int_t RescanLibraryMap()
Scan again along the dynamic path for library maps.
Definition: TCling.cxx:4778
ROOT::ESTLType IsSTLCont(const clang::RecordDecl &cl)
type : type name: vector<list<classA,allocator>,allocator> result: 0 : not stl container abs(result):...
TLine * l
Definition: textangle.C:4
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:51
The TEnumConstant class implements the constants of the enum type.
Definition: TEnumConstant.h:33
virtual const char * Getp2f2funcname(void *receiver) const
Definition: TCling.cxx:6093
virtual bool TypedefInfo_IsValid(TypedefInfo_t *tinfo) const
Definition: TCling.cxx:7945
virtual Bool_t LoadText(const char *text) const
Load the declarations from text into the interpreter.
Definition: TCling.cxx:6130
The ROOT global object gROOT contains a list of all defined classes.
Definition: TClass.h:81
virtual int MethodInfo_Next(MethodInfo_t *minfo) const
Definition: TCling.cxx:7571
clang::QualType GetQualType() const
const std::string sname
Definition: testIO.cxx:45
virtual int MethodInfo_NDefaultArg(MethodInfo_t *minfo) const
Definition: TCling.cxx:7563
virtual int MethodArgInfo_Next(MethodArgInfo_t *marginfo) const
Definition: TCling.cxx:7759
const Int_t kWarning
Definition: TError.h:40
Global variables class (global variables are obtained from CINT).
Definition: TGlobal.h:29
Definition: TEnv.h:77
void * LazyFunctionCreatorAutoload(const std::string &mangled_name)
Autoload a library based on a missing symbol.
Definition: TCling.cxx:5348
Version_t GetClassVersion() const
Definition: TClass.h:382
Bool_t IsNull() const
Definition: TString.h:387
Long_t ExecuteMacro(const char *filename, EErrorCode *error=0)
Execute a cling macro.
Definition: TCling.cxx:4298
virtual void Initialize()
Initialize the interpreter, once TROOT::fInterpreter is set.
Definition: TCling.cxx:1209
Bool_t CheckClassTemplate(const char *name)
Return true if there is a class template by the given name ...
Definition: TCling.cxx:3327
static void indent(ostringstream &buf, int indent_level)
THashList * GetTable() const
Definition: TEnv.h:144
virtual void CallFunc_SetFuncProto(CallFunc_t *func, ClassInfo_t *info, const char *method, const char *proto, Long_t *Offset, ROOT::EFunctionMatchMode mode=ROOT::kConversionMatch) const
Interface to cling function.
Definition: TCling.cxx:6655
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
virtual const char * MethodInfo_GetPrototype(MethodInfo_t *minfo) const
Definition: TCling.cxx:7613
TDictionary::DeclId_t GetDeclId() const
virtual void CallFunc_ExecWithArgsAndReturn(CallFunc_t *func, void *address, const void *args[]=0, int nargs=0, void *ret=0) const
Definition: TCling.cxx:6464
TObject * TCling__GetObjectAddress(const char *Name, void *&LookupCtx)
Definition: TCling.cxx:566
virtual Bool_t FuncTempInfo_IsValid(FuncTempInfo_t *) const
Check validity of a FuncTempInfo_t.
Definition: TCling.cxx:7354
TObjArray * Tokenize(const TString &delim) const
This function is used to isolate sequential tokens in a TString.
Definition: TString.cxx:2240
Each class (see TClass) has a linked list of its base class(es).
Definition: TBaseClass.h:35
const char * Name() const
Get the name of the current typedef.
void EnableAutoLoading()
Enable the automatic loading of shared libraries when a class is used that is stored in a not yet loa...
Definition: TCling.cxx:2457
Type
enumeration specifying the integration types.
Bool_t fLockProcessLine
Definition: TCling.h:117
R__DLLEXPORT void DestroyInterpreter(TInterpreter *interp)
Definition: TCling.cxx:580
bool IsAutoloadingEnabled()
const char * TypeName() const
TDictionary::DeclId_t DeclId_t
Definition: TListOfEnums.h:63
#define R__LOCKGUARD2(mutex)
virtual void CallFunc_Delete(CallFunc_t *func) const
Definition: TCling.cxx:6433
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
std::unordered_set< const clang::NamespaceDecl * > fNSFromRootmaps
Definition: TCling.h:115
virtual const char * BaseClassInfo_FullName(BaseClassInfo_t *bcinfo) const
Definition: TCling.cxx:7085
virtual MethodInfo_t * MethodInfo_Factory() const
Definition: TCling.cxx:7506
void TCling__GetNormalizedContext(const ROOT::TMetaUtils::TNormalizedCtxt *&normCtxt)
Definition: TCling.cxx:531
int Size() const
Return the size in bytes of the underlying type of the current typedef.
virtual const void * GetValAddr() const =0
virtual const char * FindDynamicLibrary(TString &lib, Bool_t quiet=kFALSE)
Find a dynamic library using the system search paths.
Definition: TSystem.cxx:1908
void EndOfLineAction()
It calls a "fantom" method to synchronize user keyboard input and ROOT prompt line.
Definition: TCling.cxx:2469
std::string GetMangledName() const
TString & Remove(Ssiz_t pos)
Definition: TString.h:616
const char * Name(const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt) const
long Long_t
Definition: RtypesCore.h:50
Bool_t IsLoaded() const
Return true if the shared library of this class is currently in the a process&#39;s memory.
Definition: TClass.cxx:5507
void SetClassInfo(TClass *cl, Bool_t reload=kFALSE)
Set pointer to the TClingClassInfo in TClass.
Definition: TCling.cxx:3111
int Ssiz_t
Definition: RtypesCore.h:63
Emulation of the CINT TypedefInfo class.
const clang::Decl * GetDecl() const
const char * TypeName() const
A collection of TEnum objects designed for fast access given a DeclId_t and for keep track of TEnum t...
int(* AutoLoadCallBack_t)(const char *)
Definition: TInterpreter.h:107
virtual const char * MethodArgInfo_DefaultValue(MethodArgInfo_t *marginfo) const
Definition: TCling.cxx:7775
virtual const char * ClassInfo_Name(ClassInfo_t *info) const
Definition: TCling.cxx:6966
virtual const char * GetIncludePath()
Get the list of include path.
Definition: TSystem.cxx:3684
virtual bool DataMemberInfo_IsValid(DataMemberInfo_t *dminfo) const
Definition: TCling.cxx:7158
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:677
TInterpreterValue * CreateTemporary()
The created temporary must be deleted by the caller.
Definition: TCling.cxx:6267
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:3969
void UpdateListsOnUnloaded(const cling::Transaction &T)
Definition: TCling.cxx:5707
virtual FuncTempInfo_t * FuncTempInfo_Factory(DeclId_t declid) const
Construct a FuncTempInfo_t.
Definition: TCling.cxx:7332
TObjArray * fStreamerInfo
Definition: TClass.h:179
double f(double x)
virtual void FuncTempInfo_Title(FuncTempInfo_t *, TString &name) const
Return the comments associates with this function template.
Definition: TCling.cxx:7459
std::set< size_t > fLookedUpClasses
Definition: TCling.h:111
void UpdateListOfDataMembers(TClass *cl) const
Update the list of pointers to data members for TClass cl This is now a nop.
Definition: TCling.cxx:3480
MyComplex< T > P(MyComplex< T > z, T c_real, T c_imag)
[MyComplex]
Definition: mandel.cpp:155
const char * GetParent() const
void UnloadClassMembers(TClass *cl, const clang::DeclContext *DC)
Helper function to go through the members of a class or namespace and unload them.
Definition: TCling.cxx:5654
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:552
double Double_t
Definition: RtypesCore.h:55
Emulation of the CINT MethodInfo class.
char * DynamicPathName(const char *lib, Bool_t quiet=kFALSE)
Find a dynamic library called lib using the system search paths.
Definition: TSystem.cxx:1894
TText * text
static DictFuncPtr_t GetDict(const char *cname)
Given the class name returns the Dictionary() function of a class (uses hash of name).
virtual Bool_t ClassInfo_Contains(ClassInfo_t *info, DeclId_t declid) const
Return true if the entity pointed to by &#39;declid&#39; is declared in the context described by &#39;info&#39;...
Definition: TCling.cxx:6712
Definition: TCling.h:48
TFunction * Find(DeclId_t id) const
Return the TMethod or TFunction describing the function corresponding to the Decl &#39;id&#39;...
virtual const char * DataMemberInfo_Name(DataMemberInfo_t *dminfo) const
Definition: TCling.cxx:7230
void Unload()
Mark &#39;all func&#39; as being unloaded.
virtual int DataMemberInfo_ArrayDim(DataMemberInfo_t *dminfo) const
Definition: TCling.cxx:7116
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:1811
Bool_t IsAutoLoadNamespaceCandidate(const char *name)
Definition: TCling.cxx:5440
virtual void CallFunc_ResetArg(CallFunc_t *func) const
Definition: TCling.cxx:6556
virtual void FuncTempInfo_Delete(FuncTempInfo_t *) const
Delete the FuncTempInfo_t.
Definition: TCling.cxx:7323
TDictionary::DeclId_t DeclId_t
void DeleteArray(void *arena, bool dtorOnly, const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt) const
int type
Definition: TGX11.cxx:120
static const float S
Definition: mandel.cpp:113
void ResetGlobalVar(void *obj)
Reset the Cling &#39;user&#39; global objects/variables state to the state saved by the last call to TCling::...
Definition: TCling.cxx:2959
unsigned long long ULong64_t
Definition: RtypesCore.h:70
Definition: TDatime.h:114
DeclId_t GetFunctionTemplate(ClassInfo_t *cl, const char *funcname)
Return pointer to cling interface function for a method of a class with a certain name...
Definition: TCling.cxx:4072
TNamed()
Definition: TNamed.h:40
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:2600
virtual Long64_t CallFunc_ExecInt64(CallFunc_t *func, void *address) const
Definition: TCling.cxx:6483
void Reset()
Pressing Ctrl+C should forward here.
Definition: TCling.cxx:2913
Int_t LoadLibraryMap(const char *rootmapfile=0)
Load map between class and library.
Definition: TCling.cxx:4588
void CreateListOfMethodArgs(TFunction *m) const
Create list of pointers to method arguments for TMethod m.
Definition: TCling.cxx:3487
Bool_t fAllowLibLoad
Definition: TCling.h:118
TObjArray * fRootmapFiles
Definition: TCling.h:116
double func(double *x, double *p)
Definition: stressTF1.cxx:213
void * fAutoLoadCallBack
Definition: TCling.h:137
virtual void Expand(Int_t newSize)
Expand or shrink the array to newSize elements.
Definition: TObjArray.cxx:369
std::set< const char * > fParsedPayloadsAddresses
Definition: TCling.h:113
ROOT::TMetaUtils::TClingLookupHelper * fLookupHelper
Definition: TCling.h:125
void FullName(std::string &output, const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt) const
TClingCallbacks * fClingCallbacks
Definition: TCling.h:129
Int_t AutoLoad(const char *classname, Bool_t knowDictNotLoaded=kFALSE)
Load library containing the specified class.
Definition: TCling.cxx:5011
Emulation of the CINT ClassInfo class.
EObjectPointerState GetObjectValidity() const
virtual ~TROOT()
Clean up and free resources used by ROOT (files, network sockets, shared memory segments, etc.).
Definition: TROOT.cxx:677
virtual int GetSecurityError() const
Interface to cling function.
Definition: TCling.cxx:6103
#define R__LOCKGUARD(mutex)
void InspectMember(const T &obj, const char *name, Bool_t isTransient)
Int_t GetEntries() const
Return the number of objects in array (i.e.
Definition: TObjArray.cxx:493
long Property() const
virtual void Add(TObject *obj)=0
virtual void * MethodInfo_InterfaceMethod(MethodInfo_t *minfo) const
Definition: TCling.cxx:7539
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:2860
const clang::ValueDecl * GetDataMember(const char *name) const
static TClass * GetClass(const char *name, Bool_t load=kTRUE, Bool_t silent=kFALSE)
Static method returning pointer to TClass of the specified class name.
Definition: TClass.cxx:2871
char fPrompt[64]
Definition: TCling.h:101
virtual void ClassInfo_Delete(ClassInfo_t *info) const
Definition: TCling.cxx:6741
void Delete(void *arena, const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt) const
void RegisterModule(const char *modulename, const char **headers, const char **includePaths, const char *payloadCode, const char *fwdDeclsCode, void(*triggerFunc)(), const FwdDeclArgsToKeepCollection_t &fwdDeclsArgToSkip, const char **classesHeaders)
Inject the module named "modulename" into cling; load all headers.
Definition: TCling.cxx:1474
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:4790
virtual TObject * FindObject(const char *name) const
Specialize FindObject to do search for the a data member just by name or create it if its not already...
static TClass * LoadClass(const char *requestedname, Bool_t silent)
Helper function used by TClass::GetClass().
Definition: TClass.cxx:5359
void UpdateListOfMethods(TClass *cl) const
Update the list of pointers to method for TClass cl This is now a nop.
Definition: TCling.cxx:3471
TVirtualCollectionProxy * GetCollectionProxy() const
Return the proxy describing the collection (if any).
Definition: TClass.cxx:2800
void * New(const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt) const
#define name(a, b)
Definition: linkTestLib0.cpp:5
virtual const char * TypedefInfo_Name(TypedefInfo_t *tinfo) const
Definition: TCling.cxx:7985
void RecursiveRemove(TObject *obj)
Delete object from cling symbol table so it can not be used anymore.
Definition: TCling.cxx:2895
TDataMember * GetDataMember(const char *datamember) const
Return pointer to datamember object with name "datamember".
Definition: TClass.cxx:3211
virtual int ClassInfo_Size(ClassInfo_t *info) const
Definition: TCling.cxx:6932
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:1820
virtual Double_t CallFunc_ExecDouble(CallFunc_t *func, void *address) const
Definition: TCling.cxx:6491
TString fIncludePath
Definition: TCling.h:106
Mother of all ROOT objects.
Definition: TObject.h:58
virtual bool ClassInfo_HasMethod(ClassInfo_t *info, const char *name) const
Definition: TCling.cxx:6811
void TCling__LibraryUnloadedRTTI(const void *dyLibHandle, const char *canonicalName)
Definition: TCling.cxx:558
virtual Long_t MethodArgInfo_Property(MethodArgInfo_t *marginfo) const
Definition: TCling.cxx:7767
void RegisterTemporary(const TInterpreterValue &value)
Definition: TCling.cxx:6275
virtual void Inspect(TClass *cl, const char *parent, const char *name, const void *addr)
virtual Long_t Getgvp() const
Interface to the CINT global object pointer which was controlling the behavior of the wrapper around ...
Definition: TCling.cxx:6085
#define R__EXTERN
Definition: DllImport.h:27
TClassRef is used to implement a permanent reference to a TClass object.
Definition: TClassRef.h:33
void HandleNewDecl(const void *DV, bool isDeserialized, std::set< TClass * > &modifiedClasses)
Definition: TCling.cxx:449
typedef void((*Func_t)())
Version_t fClassVersion
Definition: TClass.h:201
void Unload()
Mark &#39;all func&#39; as being unloaded.
const char * GetDeclFileName() const
Definition: TClass.h:386
virtual bool ClassInfo_IsLoaded(ClassInfo_t *info) const
Definition: TCling.cxx:6852
static TEnum * GetEnum(const std::type_info &ti, ESearchAction sa=kALoadAndInterpLookup)
Definition: TEnum.cxx:108
virtual DeclId_t GetDataMemberWithValue(const void *ptrvalue) const
NOT IMPLEMENTED.
Definition: TCling.cxx:3862
void SetAutoloadingEnabled(bool val=true)
llvm::StringRef GetComment(const clang::Decl &decl, clang::SourceLocation *loc=0)
Returns the comment (// striped away), annotating declaration in a meaningful for ROOT IO way...
Bridge between cling::Value and ROOT.
Definition: TClingValue.h:38
virtual const char * MethodInfo_Name(MethodInfo_t *minfo) const
Definition: TCling.cxx:7621
const char * GetUnqualifiedName(const char *name)
Return the start of the unqualified name include in &#39;original&#39;.
Definition: TClassEdit.cxx:850
const char * GetFullTypeName() const
Get full type description of method argument, e.g.: "class TDirectory*".
Definition: TMethodArg.cxx:75
void Unload()
Mark &#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:1011
virtual void Add(TObject *obj)
Definition: TList.h:81
const Ssiz_t kNPOS
Definition: Rtypes.h:115
TClingMethodInfo GetMethodWithArgs(const char *fname, const char *arglist, long *poffset, ROOT::EFunctionMatchMode mode=ROOT::kConversionMatch, EInheritanceMode imode=kWithInheritance) const
virtual bool ClassInfo_IsValid(ClassInfo_t *info) const
Definition: TCling.cxx:6860
long Property() const
void ReplaceAll(std::string &str, const std::string &from, const std::string &to, bool recurse=false)
virtual Long_t ClassInfo_Tagnum(ClassInfo_t *info) const
Definition: TCling.cxx:6940
Bool_t fHeaderParsingOnDemand
Definition: TCling.h:147
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition: TString.h:567
virtual Long_t MethodInfo_ExtraProperty(MethodInfo_t *minfo) const
Definition: TCling.cxx:7587
void MakeZombie()
Definition: TObject.h:68
Each ROOT class (see TClass) has a linked list of methods.
Definition: TMethod.h:40
std::vector< std::pair< TClass *, DictFuncPtr_t > > fClassesToUpdate
Definition: TCling.h:136
virtual void CallFunc_IgnoreExtraArgs(CallFunc_t *func, bool ignore) const
Definition: TCling.cxx:6522
virtual const char * GetSTLIncludePath() const
Return the directory containing CINT&#39;s stl cintdlls.
Definition: TCling.cxx:5998
static void * fgSetOfSpecials
Definition: TCling.h:95
TF1 * f1
Definition: legend1.C:11
virtual const char * MethodInfo_TypeName(MethodInfo_t *minfo) const
Definition: TCling.cxx:7629
static void SetFactory(TVirtualStreamerInfo *factory)
static function: Set the StreamerInfo factory
long ExecInt(void *address)
#define NULL
Definition: Rtypes.h:82
Int_t SetClassSharedLibs(const char *cls, const char *libs)
Register the autoloading information for a class.
Definition: TCling.cxx:4931
Bool_t IsLoaded(const char *filename) const
Return true if the file has already been loaded by cint.
Definition: TCling.cxx:2482
bool IsValid() const
Return true if the current iterator position is valid.
virtual void ClassInfo_Destruct(ClassInfo_t *info, void *arena) const
Definition: TCling.cxx:6764
virtual const char * ClassInfo_FullName(ClassInfo_t *info) const
Definition: TCling.cxx:6956
virtual void UpdateEnumConstants(TEnum *enumObj, TClass *cl) const
Definition: TCling.cxx:374
virtual void * OpenDirectory(const char *name)
Open a directory. Returns 0 if directory does not exist.
Definition: TSystem.cxx:830
R__EXTERN Int_t gDebug
Definition: Rtypes.h:128
ROOT::ESTLType GetCollectionType() const
Return the &#39;type&#39; of the STL the TClass is representing.
Definition: TClass.cxx:2789
Bool_t SetSuspendAutoParsing(Bool_t value)
Suspend the Autoparsing of headers.
Definition: TCling.cxx:6196
virtual const char * BaseClassInfo_TmpltName(BaseClassInfo_t *bcinfo) const
Definition: TCling.cxx:7103
virtual const char * MethodArgInfo_Name(MethodArgInfo_t *marginfo) const
Definition: TCling.cxx:7783
Int_t fMore
Definition: TCling.h:99
virtual const char * ClassInfo_TmpltName(ClassInfo_t *info) const
Definition: TCling.cxx:6982
int RefType() const
static const std::string ioname("ioname")
static bool R__InitStreamerInfoFactory()
Helper to initialize TVirtualStreamerInfo&#39;s factor early.
Definition: TCling.cxx:1252
void Add(TObject *obj)
Definition: TObjArray.h:75
Bool_t IsErrorMessagesEnabled() const
If error messages are disabled, the interpreter should suppress its failures and warning messages fro...
Definition: TCling.cxx:5939
void IgnoreExtraArgs(bool ignore)
long Property() const
Bool_t fIsAutoParsingSuspended
Definition: TCling.h:148
double result[121]
static void UpdateClassInfoWork(const char *name)
Definition: TCling.cxx:5537
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
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:891
std::hash< std::string > fStringHashFunction
Definition: TCling.h:114
virtual void TypedefInfo_Init(TypedefInfo_t *tinfo, const char *name) const
Definition: TCling.cxx:7935
const char * GetSharedLibs()
Return the list of shared libraries loaded into the process.
Definition: TCling.cxx:5857
TObject * At(Int_t idx) const
Definition: TObjArray.h:167
bool IsBase(const char *name) const
static const char * FindLibraryName(void(*func)())
Wrapper around dladdr (and friends)
Definition: TCling.cxx:1217
virtual EReturnType MethodInfo_MethodCallReturnType(MethodInfo_t *minfo) const
Definition: TCling.cxx:7667
R__EXTERN TInterpreter * gCling
Definition: TInterpreter.h:504
R__DLLEXPORT TInterpreter * CreateInterpreter(void *interpLibHandle)
Definition: TCling.cxx:574
virtual void * FindSym(const char *entry) const
Interface to cling function.
Definition: TCling.cxx:6045
virtual void Compress()
Remove empty slots from array.
Definition: TObjArray.cxx:308
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
Definition: TString.h:582
#define I(x, y, z)
bool IsValidMethod(const char *method, const char *proto, Bool_t objectIsConst, long *offset, ROOT::EFunctionMatchMode mode=ROOT::kConversionMatch) const
Long_t ProcessLineAsynch(const char *line, EErrorCode *error=0)
Let cling process a command line asynch.
Definition: TCling.cxx:2782
static void output(int code)
Definition: gifencode.c:226
virtual void DataMemberInfo_Delete(DataMemberInfo_t *dminfo) const
Definition: TCling.cxx:7124
const Bool_t kTRUE
Definition: Rtypes.h:91
void TCling__TransactionRollback(const cling::Transaction &T)
Definition: TCling.cxx:548
virtual const char * GetTitle() const
Returns title of object.
Definition: TObject.cxx:459
TList * GetListOfMethods(Bool_t load=kTRUE)
Return list containing the TMethods of a class.
Definition: TClass.cxx:3578
std::string NormalizedName(const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt) const
Return the normalized name of the type (i.e.
float value
Definition: math.cpp:443
void Unload()
Mark &#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:1028
void LoadMacro(const char *filename, EErrorCode *error=0)
Load a macro file in cling&#39;s memory.
Definition: TCling.cxx:2774
virtual ClassInfo_t * BaseClassInfo_ClassInfo(BaseClassInfo_t *) const
Definition: TCling.cxx:7069
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:4373
virtual EReturnType MethodCallReturnType(TFunction *func) const
Definition: TCling.cxx:7656
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:5849
const Int_t n
Definition: legend1.C:16
bool IsValid() const
void RewindDictionary()
Rewind Cling dictionary to the point where it was before executing the current macro.
Definition: TCling.cxx:2974
virtual MethodArgInfo_t * MethodArgInfo_FactoryCopy(MethodArgInfo_t *marginfo) const
Definition: TCling.cxx:7743
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:2030
void CreateListOfMethods(TClass *cl) const
Create list of pointers to methods for TClass cl.
Definition: TCling.cxx:3462
Int_t DeleteGlobal(void *obj)
Delete obj from Cling symbol table so it cannot be accessed anymore.
Definition: TCling.cxx:2988
TRandom3 R
a TMatrixD.
Definition: testIO.cxx:28
virtual TypeInfo_t * TypeInfo_Factory() const
Definition: TCling.cxx:7819
virtual const char * MethodArgInfo_TypeName(MethodArgInfo_t *marginfo) const
Definition: TCling.cxx:7791
TDictionary::DeclId_t GetDeclId() const
virtual void SetErrmsgcallback(void *p) const
Set a callback to receive error messages.
Definition: TCling.cxx:6206
void ResetGlobals()
Reset in Cling the list of global variables to the state saved by the last call to TCling::SaveGlobal...
Definition: TCling.cxx:2945
virtual const char * TypedefInfo_Title(TypedefInfo_t *tinfo) const
Definition: TCling.cxx:7993
Int_t Size() const
Return size of object of this class.
Definition: TClass.cxx:5314
Long_t fMemResident
Definition: TSystem.h:206
virtual void SetAlloclockfunc(void(*)()) const
[Place holder for Mutex Lock] Provide the interpreter with a way to acquire a lock used to protect cr...
Definition: TCling.cxx:6151
bool IsValid() const
void ExecWithArgsAndReturn(void *address, const void *args[]=0, int nargs=0, void *ret=0)
virtual void CallFunc_SetArg(CallFunc_t *func, Long_t param) const
Definition: TCling.cxx:6564
if(line.BeginsWith("/*"))
Definition: HLFactory.cxx:443
virtual Long_t FuncTempInfo_Property(FuncTempInfo_t *) const
Return the property of the function template.
Definition: TCling.cxx:7387
const char * Value
Definition: TXMLSetup.cxx:73
DeclId_t GetDeclId() const
Definition: TEnum.h:72
virtual DataMemberInfo_t * DataMemberInfo_FactoryCopy(DataMemberInfo_t *dminfo) const
Definition: TCling.cxx:7150
void ExecWithReturn(void *address, void *ret=0)
virtual int UnloadFile(const char *path) const
Definition: TCling.cxx:6250
virtual int DataMemberInfo_Next(DataMemberInfo_t *dminfo) const
Definition: TCling.cxx:7174
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:2791
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:6795
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
long long ExecInt64(void *address)
virtual void FuncTempInfo_Name(FuncTempInfo_t *, TString &name) const
Return the name of this function template.
Definition: TCling.cxx:7446
virtual void TypedefInfo_Delete(TypedefInfo_t *tinfo) const
Definition: TCling.cxx:7905
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition: TObject.cxx:904