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