Logo ROOT   6.08/02
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 #include "TKey.h"
74 #include "ClingRAII.h"
75 
76 #include "clang/AST/ASTContext.h"
77 #include "clang/AST/Decl.h"
78 #include "clang/AST/DeclarationName.h"
79 #include "clang/AST/GlobalDecl.h"
80 #include "clang/AST/RecordLayout.h"
81 #include "clang/AST/RecursiveASTVisitor.h"
82 #include "clang/AST/Type.h"
83 #include "clang/Basic/SourceLocation.h"
84 #include "clang/Basic/Specifiers.h"
85 #include "clang/Basic/TargetInfo.h"
86 #include "clang/CodeGen/ModuleBuilder.h"
87 #include "clang/Frontend/CompilerInstance.h"
88 #include "clang/Frontend/FrontendDiagnostic.h"
89 #include "clang/Lex/HeaderSearch.h"
90 #include "clang/Lex/Preprocessor.h"
91 #include "clang/Sema/Lookup.h"
92 #include "clang/Sema/Sema.h"
93 #include "clang/Parse/Parser.h"
94 
95 #include "cling/Interpreter/ClangInternalState.h"
96 #include "cling/Interpreter/DynamicLibraryManager.h"
97 #include "cling/Interpreter/Interpreter.h"
98 #include "cling/Interpreter/LookupHelper.h"
99 #include "cling/Interpreter/Value.h"
100 #include "cling/Interpreter/Transaction.h"
101 #include "cling/MetaProcessor/MetaProcessor.h"
102 #include "cling/Utils/AST.h"
103 #include "cling/Utils/ParserStateRAII.h"
104 #include "cling/Utils/SourceNormalization.h"
105 #include "cling/Interpreter/Exception.h"
106 
107 #include "llvm/IR/GlobalValue.h"
108 #include "llvm/IR/Module.h"
109 
110 #include "llvm/Support/DynamicLibrary.h"
111 #include "llvm/Support/raw_ostream.h"
112 #include "llvm/Support/Path.h"
113 
114 #include <algorithm>
115 #include <iostream>
116 #include <cassert>
117 #include <map>
118 #include <set>
119 #include <stdexcept>
120 #include <stdint.h>
121 #include <fstream>
122 #include <sstream>
123 #include <string>
124 #include <typeinfo>
125 #include <unordered_map>
126 #include <utility>
127 #include <vector>
128 
129 #ifndef R__WIN32
130 #include <cxxabi.h>
131 #define R__DLLEXPORT
132 #endif
133 #include <limits.h>
134 #include <stdio.h>
135 
136 #ifdef __APPLE__
137 #include <dlfcn.h>
138 #include <mach-o/dyld.h>
139 #endif // __APPLE__
140 
141 #ifdef R__UNIX
142 #include <dlfcn.h>
143 #endif
144 
145 #if defined(__CYGWIN__)
146 #include <sys/cygwin.h>
147 #define HMODULE void *
148 extern "C" {
149  __declspec(dllimport) void * __stdcall GetCurrentProcess();
150  __declspec(dllimport) bool __stdcall EnumProcessModules(void *, void **, unsigned long, unsigned long *);
151  __declspec(dllimport) unsigned long __stdcall GetModuleFileNameExW(void *, void *, wchar_t *, unsigned long);
152 }
153 #endif
154 
155 // Fragment copied from LLVM's raw_ostream.cpp
156 #if defined(_MSC_VER)
157 #ifndef STDIN_FILENO
158 # define STDIN_FILENO 0
159 #endif
160 #ifndef STDOUT_FILENO
161 # define STDOUT_FILENO 1
162 #endif
163 #ifndef STDERR_FILENO
164 # define STDERR_FILENO 2
165 #endif
166 #ifndef R__WIN32
167 //#if defined(HAVE_UNISTD_H)
168 # include <unistd.h>
169 //#endif
170 #else
171 #include "Windows4Root.h"
172 #include <Psapi.h>
173 #undef GetModuleFileName
174 #define RTLD_DEFAULT ((void *)::GetModuleHandle(NULL))
175 #define dlsym(library, function_name) ::GetProcAddress((HMODULE)library, function_name)
176 #define dlopen(library_name, flags) ::LoadLibrary(library_name)
177 #define dlclose(library) ::FreeLibrary((HMODULE)library)
178 #define R__DLLEXPORT __declspec(dllexport)
179 #endif
180 #endif
181 
182 //______________________________________________________________________________
183 // Infrastructure to detect and react to libCling being teared down.
184 //
185 namespace {
186  class TCling_UnloadMarker {
187  public:
188  ~TCling_UnloadMarker() {
191  }
192  }
193  };
194  static TCling_UnloadMarker gTClingUnloadMarker;
195 }
196 
197 
198 
199 //______________________________________________________________________________
200 // These functions are helpers for debugging issues with non-LLVMDEV builds.
201 //
202 clang::DeclContext* TCling__DEBUG__getDeclContext(clang::Decl* D) {
203  return D->getDeclContext();
204 }
205 clang::NamespaceDecl* TCling__DEBUG__DCtoNamespace(clang::DeclContext* DC) {
206  return llvm::dyn_cast<clang::NamespaceDecl>(DC);
207 }
208 clang::RecordDecl* TCling__DEBUG__DCtoRecordDecl(clang::DeclContext* DC) {
209  return llvm::dyn_cast<clang::RecordDecl>(DC);
210 }
211 void TCling__DEBUG__dump(clang::DeclContext* DC) {
212  return DC->dumpDeclContext();
213 }
214 void TCling__DEBUG__dump(clang::Decl* D) {
215  return D->dump();
216 }
217 void TCling__DEBUG__dump(clang::FunctionDecl* FD) {
218  return FD->dump();
219 }
221  return ((clang::Decl*)D)->dump();
222 }
223 void TCling__DEBUG__printName(clang::Decl* D) {
224  if (clang::NamedDecl* ND = llvm::dyn_cast<clang::NamedDecl>(D)) {
225  std::string name;
226  {
227  llvm::raw_string_ostream OS(name);
228  ND->getNameForDiagnostic(OS, D->getASTContext().getPrintingPolicy(),
229  true /*Qualified*/);
230  }
231  printf("%s\n", name.c_str());
232  }
233 }
234 //______________________________________________________________________________
235 // These functions are helpers for testing issues directly rather than
236 // relying on side effects.
237 // This is used for the test for ROOT-7462/ROOT-6070
238 bool TCling__TEST_isInvalidDecl(clang::Decl* D) {
239  return D->isInvalidDecl();
240 }
241 bool TCling__TEST_isInvalidDecl(ClassInfo_t *input) {
242  TClingClassInfo *info( (TClingClassInfo*) input);
243  assert(info && info->IsValid());
244  return info->GetDecl()->isInvalidDecl();
245 }
246 
247 using namespace std;
248 using namespace clang;
249 using namespace ROOT;
250 
251 namespace {
252  static const std::string gInterpreterClassDef = R"ICF( #undef ClassDef #define ClassDef(name, id) \ _ClassDefInterp_(name,id,virtual,) \ static int DeclFileLine() { return __LINE__; } #undef ClassDefNV #define ClassDefNV(name, id) \ _ClassDefInterp_(name,id,,) \ static int DeclFileLine() { return __LINE__; } #undef ClassDefOverride #define ClassDefOverride(name, id) \ _ClassDefInterp_(name,id,,override) \ static int DeclFileLine() { return __LINE__; } )ICF";
253 
254  static const std::string gNonInterpreterClassDef = R"ICF( #define __ROOTCLING__ 1 #undef ClassDef #define ClassDef(name,id) \ _ClassDef_(name,id,virtual,) \ static int DeclFileLine() { return __LINE__; } #undef ClassDefNV #define ClassDefNV(name, id)\ _ClassDef_(name,id,,)\ static int DeclFileLine() { return __LINE__; } #undef ClassDefOverride #define ClassDefOverride(name, id)\ _ClassDef_(name,id,,override)\ static int DeclFileLine() { return __LINE__; } )ICF";
255 
256 // The macros below use ::Error, so let's ensure it is included
257  static const std::string gClassDefInterpMacro = R"ICF( #ifndef ROOT_TError #include "TError.h" #endif #define _ClassDefInterp_(name,id,virtual_keyword, overrd) \ private: \ public: \ static TClass *Class() { static TClass* sIsA = 0; if (!sIsA) sIsA = TClass::GetClass(#name); return sIsA; } \ static const char *Class_Name() { return #name; } \ static Version_t Class_Version() { return id; } \ static TClass *Dictionary() { return 0; } \ virtual_keyword TClass *IsA() const overrd { return name::Class(); } \ virtual_keyword void ShowMembers(TMemberInspector&insp) const overrd { ::ROOT::Class_ShowMembers(name::Class(), this, insp); } \ virtual_keyword void Streamer(TBuffer&) overrd { ::Error("Streamer", "Cannot stream interpreted class."); } \ void StreamerNVirtual(TBuffer&ClassDef_StreamerNVirtual_b) { name::Streamer(ClassDef_StreamerNVirtual_b); } \ static const char *DeclFileName() { return __FILE__; } \ static int ImplFileLine() { return 0; } \ static const char *ImplFileName() { return __FILE__; } )ICF";
258 }
259 R__EXTERN int optind;
260 
261 // The functions are used to bridge cling/clang/llvm compiled with no-rtti and
262 // ROOT (which uses rtti)
263 
264 //______________________________________________________________________________
265 
266 // Class extracting recursively every Enum type defined for a class.
267 class EnumVisitor : public RecursiveASTVisitor<EnumVisitor> {
268 private:
269  llvm::SmallVector<EnumDecl*,128> &fClassEnums;
270 public:
271  EnumVisitor(llvm::SmallVector<EnumDecl*,128> &enums) : fClassEnums(enums)
272  {}
273 
274  bool TraverseStmt(Stmt*) {
275  // Don't descend into function bodies.
276  return true;
277  }
278 
279  bool shouldVisitTemplateInstantiations() const { return true; }
280 
281  bool TraverseClassTemplateDecl(ClassTemplateDecl*) {
282  // Don't descend into templates (but only instances thereof).
283  return true; // returning false will abort the in-depth traversal.
284  }
285 
286  bool TraverseClassTemplatePartialSpecializationDecl(ClassTemplatePartialSpecializationDecl*) {
287  // Don't descend into templates partial specialization (but only instances thereof).
288  return true; // returning false will abort the in-depth traversal.
289  }
290 
291  bool VisitEnumDecl(EnumDecl *TEnumD) {
292  if (!TEnumD->getDeclContext()->isDependentContext())
293  fClassEnums.push_back(TEnumD);
294  return true; // returning false will abort the in-depth traversal.
295  }
296 };
297 
298 ////////////////////////////////////////////////////////////////////////////////
299 /// Print a StackTrace!
300 
301 extern "C"
303  gSystem->StackTrace();
304 }
306 ////////////////////////////////////////////////////////////////////////////////
307 /// Update TClingClassInfo for a class (e.g. upon seeing a definition).
308 
309 static void TCling__UpdateClassInfo(const NamedDecl* TD)
310 {
311  static Bool_t entered = kFALSE;
312  static vector<const NamedDecl*> updateList;
313  Bool_t topLevel;
314 
315  if (entered) topLevel = kFALSE;
316  else {
317  entered = kTRUE;
318  topLevel = kTRUE;
319  }
320  if (topLevel) {
321  ((TCling*)gInterpreter)->UpdateClassInfoWithDecl(TD);
322  } else {
323  // If we are called indirectly from within another call to
324  // TCling::UpdateClassInfo, we delay the update until the dictionary loading
325  // is finished (i.e. when we return to the top level TCling::UpdateClassInfo).
326  // This allows for the dictionary to be fully populated when we actually
327  // update the TClass object. The updating of the TClass sometimes
328  // (STL containers and when there is an emulated class) forces the building
329  // of the TClass object's real data (which needs the dictionary info).
330  updateList.push_back(TD);
331  }
332  if (topLevel) {
333  while (!updateList.empty()) {
334  ((TCling*)gInterpreter)->UpdateClassInfoWithDecl(updateList.back());
335  updateList.pop_back();
336  }
337  entered = kFALSE;
338  }
339 }
340 
341 void TCling::UpdateEnumConstants(TEnum* enumObj, TClass* cl) const {
342  const clang::Decl* D = static_cast<const clang::Decl*>(enumObj->GetDeclId());
343  if(const clang::EnumDecl* ED = dyn_cast<clang::EnumDecl>(D)) {
344  // Add the constants to the enum type.
345  for (EnumDecl::enumerator_iterator EDI = ED->enumerator_begin(),
346  EDE = ED->enumerator_end(); EDI != EDE; ++EDI) {
347  // Get name of the enum type.
348  std::string constbuf;
349  if (const NamedDecl* END = llvm::dyn_cast<NamedDecl>(*EDI)) {
350  PrintingPolicy Policy((*EDI)->getASTContext().getPrintingPolicy());
351  llvm::raw_string_ostream stream(constbuf);
352  // Don't trigger fopen of the source file to count lines:
353  Policy.AnonymousTagLocations = false;
354  (END)->getNameForDiagnostic(stream, Policy, /*Qualified=*/false);
355  }
356  const char* constantName = constbuf.c_str();
357 
358  // Get value of the constant.
359  Long64_t value;
360  const llvm::APSInt valAPSInt = (*EDI)->getInitVal();
361  if (valAPSInt.isSigned()) {
362  value = valAPSInt.getSExtValue();
363  } else {
364  value = valAPSInt.getZExtValue();
365  }
366 
367  // Create the TEnumConstant or update it if existing
368  TEnumConstant* enumConstant = nullptr;
369  TClingClassInfo* tcCInfo = (TClingClassInfo*)(cl ? cl->GetClassInfo() : 0);
370  TClingDataMemberInfo* tcDmInfo = new TClingDataMemberInfo(fInterpreter, *EDI, tcCInfo);
371  DataMemberInfo_t* dmInfo = (DataMemberInfo_t*) tcDmInfo;
372  if (TObject* encAsTObj = enumObj->GetConstants()->FindObject(constantName)){
373  ((TEnumConstant*)encAsTObj)->Update(dmInfo);
374  } else {
375  enumConstant = new TEnumConstant(dmInfo, constantName, value, enumObj);
376  }
377 
378  // Add the global constants to the list of Globals.
379  if (!cl) {
380  TCollection* globals = gROOT->GetListOfGlobals(false);
381  if (!globals->FindObject(constantName)) {
382  globals->Add(enumConstant);
383  }
384  }
385  }
386  }
387 }
388 
389 TEnum* TCling::CreateEnum(void *VD, TClass *cl) const
390 {
391  // Handle new enum declaration for either global and nested enums.
392 
393  // Create the enum type.
394  TEnum* enumType = 0;
395  const clang::Decl* D = static_cast<const clang::Decl*>(VD);
396  std::string buf;
397  if (const EnumDecl* ED = llvm::dyn_cast<EnumDecl>(D)) {
398  // Get name of the enum type.
399  PrintingPolicy Policy(ED->getASTContext().getPrintingPolicy());
400  llvm::raw_string_ostream stream(buf);
401  // Don't trigger fopen of the source file to count lines:
402  Policy.AnonymousTagLocations = false;
403  ED->getNameForDiagnostic(stream, Policy, /*Qualified=*/false);
404  // If the enum is unnamed we do not add it to the list of enums i.e unusable.
405  }
406  if (buf.empty()) {
407  return 0;
408  }
409  const char* name = buf.c_str();
410  enumType = new TEnum(name, VD, cl);
411  UpdateEnumConstants(enumType, cl);
412 
413  return enumType;
414 }
415 
416 void TCling::HandleNewDecl(const void* DV, bool isDeserialized, std::set<TClass*> &modifiedTClasses) {
417  // Handle new declaration.
418  // Record the modified class, struct and namespaces in 'modifiedTClasses'.
419 
420  const clang::Decl* D = static_cast<const clang::Decl*>(DV);
421 
422  if (!D->isCanonicalDecl() && !isa<clang::NamespaceDecl>(D)
423  && !dyn_cast<clang::RecordDecl>(D)) return;
424 
425  if (isa<clang::FunctionDecl>(D->getDeclContext())
426  || isa<clang::TagDecl>(D->getDeclContext()))
427  return;
428 
429  // Don't list templates.
430  if (const clang::CXXRecordDecl* RD = dyn_cast<clang::CXXRecordDecl>(D)) {
431  if (RD->getDescribedClassTemplate())
432  return;
433  } else if (const clang::FunctionDecl* FD = dyn_cast<clang::FunctionDecl>(D)) {
434  if (FD->getDescribedFunctionTemplate())
435  return;
436  }
437 
438  if (const RecordDecl *TD = dyn_cast<RecordDecl>(D)) {
439  if (TD->isCanonicalDecl() || TD->isThisDeclarationADefinition())
441  }
442  else if (const NamedDecl *ND = dyn_cast<NamedDecl>(D)) {
443 
444  if (const TagDecl *TD = dyn_cast<TagDecl>(D)) {
445  // Mostly just for EnumDecl (the other TagDecl are handled
446  // by the 'RecordDecl' if statement.
448  } else if (const NamespaceDecl* NSD = dyn_cast<NamespaceDecl>(D)) {
450  }
451 
452  // While classes are read completely (except for function template instances,
453  // enum, data (and functions) can be added to namespaces at any time.
454  // [this section can be removed when both the list of data member and the list
455  // of enums has been update to be active list]
456  if (const NamespaceDecl* NCtx = dyn_cast<NamespaceDecl>(ND->getDeclContext())) {
457  if (NCtx->getIdentifier()) {
458  // No need to load the TClass: if there is something to update then
459  // it must already exist.
460  std::string NCtxName;
461  PrintingPolicy Policy(NCtx->getASTContext().getPrintingPolicy());
462  llvm::raw_string_ostream stream(NCtxName);
463  // Don't trigger fopen of the source file to count lines:
464  Policy.AnonymousTagLocations = false;
465  NCtx->getNameForDiagnostic(stream, Policy, /*Qualified=*/true);
466 
467  TClass* cl = (TClass*)gROOT->GetListOfClasses()->FindObject(NCtxName.c_str());
468  if (cl) {
469  modifiedTClasses.insert(cl);
470  }
471  }
472  return;
473  }
474 
475  // We care about declarations on the global scope.
476  if (!isa<TranslationUnitDecl>(ND->getDeclContext()))
477  return;
478 
479  // Enums are lazyly created, thus we don not need to handle them here.
480  if (isa<EnumDecl>(ND))
481  return;
482 
483  // ROOT says that global is enum(lazylycreated)/var/field declared on the global
484  // scope.
485  if (!(isa<VarDecl>(ND)))
486  return;
487 
488  // Skip if already in the list.
489  if (gROOT->GetListOfGlobals()->FindObject(ND->getNameAsString().c_str()))
490  return;
491 
492  // Put the global constants and global enums in the corresponding lists.
493  gROOT->GetListOfGlobals()->Add(new TGlobal((DataMemberInfo_t *)
494  new TClingDataMemberInfo(fInterpreter,
495  cast<ValueDecl>(ND), 0)));
496  }
497 }
498 
499 extern "C"
501 {
502  // We are sure in this context of the type of the interpreter
503  normCtxt = &( (TCling*) gInterpreter)->GetNormalizedContext();
504 }
505 
506 extern "C"
507 void TCling__UpdateListsOnCommitted(const cling::Transaction &T, cling::Interpreter*) {
508 
509  ((TCling*)gCling)->UpdateListsOnCommitted(T);
510 }
511 
512 extern "C"
513 void TCling__UpdateListsOnUnloaded(const cling::Transaction &T) {
514 
515  ((TCling*)gCling)->UpdateListsOnUnloaded(T);
516 }
517 void TCling__TransactionRollback(const cling::Transaction &T) {
518 
519  ((TCling*)gCling)->TransactionRollback(T);
520 }
521 extern "C" void TCling__LibraryLoadedRTTI(const void* dyLibHandle,
522  const char* canonicalName) {
523 
524  ((TCling*)gCling)->LibraryLoaded(dyLibHandle, canonicalName);
525 }
526 
527 extern "C" void TCling__LibraryUnloadedRTTI(const void* dyLibHandle,
528  const char* canonicalName) {
529 
530  ((TCling*)gCling)->LibraryUnloaded(dyLibHandle, canonicalName);
531 }
532 
533 
534 extern "C"
535 TObject* TCling__GetObjectAddress(const char *Name, void *&LookupCtx) {
536  return ((TCling*)gCling)->GetObjectAddress(Name, LookupCtx);
537 }
538 
539 extern "C" const Decl* TCling__GetObjectDecl(TObject *obj) {
540  return ((TClingClassInfo*)obj->IsA()->GetClassInfo())->GetDecl();
541 }
542 
543 extern "C" R__DLLEXPORT TInterpreter *CreateInterpreter(void* interpLibHandle)
544 {
545  cling::DynamicLibraryManager::ExposeHiddenSharedLibrarySymbols(interpLibHandle);
546  return new TCling("C++", "cling C++ Interpreter");
547 }
548 
549 extern "C" R__DLLEXPORT void DestroyInterpreter(TInterpreter *interp)
550 {
551  delete interp;
552 }
554 // Load library containing specified class. Returns 0 in case of error
555 // and 1 in case if success.
556 extern "C" int TCling__AutoLoadCallback(const char* className)
557 {
558  return ((TCling*)gCling)->AutoLoad(className);
559 }
560 
561 extern "C" int TCling__AutoParseCallback(const char* className)
562 {
563  return ((TCling*)gCling)->AutoParse(className);
564 }
565 
566 extern "C" const char* TCling__GetClassSharedLibs(const char* className)
567 {
568  return ((TCling*)gCling)->GetClassSharedLibs(className);
569 }
570 
571 // // Returns 0 for failure 1 for success
572 // extern "C" int TCling__IsAutoLoadNamespaceCandidate(const char* name)
573 // {
574 // return ((TCling*)gCling)->IsAutoLoadNamespaceCandidate(name);
575 // }
576 
577 // Returns 0 for failure 1 for success
578 extern "C" int TCling__IsAutoLoadNamespaceCandidate(const clang::NamespaceDecl* nsDecl)
579 {
580  return ((TCling*)gCling)->IsAutoLoadNamespaceCandidate(nsDecl);
581 }
582 
583 extern "C" int TCling__CompileMacro(const char *fileName, const char *options)
584 {
585  string file(fileName);
586  string opt(options);
587  return gSystem->CompileMacro(file.c_str(), opt.c_str());
588 }
590 extern "C" void TCling__SplitAclicMode(const char* fileName, string &mode,
591  string &args, string &io, string &fname)
592 {
593  string file(fileName);
594  TString f, amode, arguments, aclicio;
595  f = gSystem->SplitAclicMode(file.c_str(), amode, arguments, aclicio);
596  mode = amode.Data(); args = arguments.Data();
597  io = aclicio.Data(); fname = f.Data();
598 }
599 
600 //______________________________________________________________________________
601 //
602 //
603 //
604 
605 #ifdef R__WIN32
606 extern "C" {
607  char *__unDName(char *demangled, const char *mangled, int out_len,
608  void * (* pAlloc )(size_t), void (* pFree )(void *),
609  unsigned short int flags);
610 }
611 #endif
613 ////////////////////////////////////////////////////////////////////////////////
614 /// Find a template decl within N nested namespaces, 0<=N<inf
615 /// Assumes 1 and only 1 template present and 1 and only 1 entity contained
616 /// by the namespace. Example: ns1::ns2::..::nsN::myTemplate
617 /// Returns nullptr in case of error
618 
619 static clang::ClassTemplateDecl* FindTemplateInNamespace(clang::Decl* decl)
620 {
621  using namespace clang;
622  if (NamespaceDecl* nsd = llvm::dyn_cast<NamespaceDecl>(decl)){
623  return FindTemplateInNamespace(*nsd->decls_begin());
624  }
625 
626  if (ClassTemplateDecl* ctd = llvm::dyn_cast<ClassTemplateDecl>(decl)){
627  return ctd;
628  }
630  return nullptr; // something went wrong.
631 }
632 
633 ////////////////////////////////////////////////////////////////////////////////
634 /// Autoload a library provided the mangled name of a missing symbol.
635 
636 void* llvmLazyFunctionCreator(const std::string& mangled_name)
637 {
638  return ((TCling*)gCling)->LazyFunctionCreatorAutoload(mangled_name);
639 }
640 
641 //______________________________________________________________________________
642 //
643 //
644 //
645 
646 int TCling_GenerateDictionary(const std::vector<std::string> &classes,
647  const std::vector<std::string> &headers,
648  const std::vector<std::string> &fwdDecls,
649  const std::vector<std::string> &unknown)
650 {
651  //This function automatically creates the "LinkDef.h" file for templated
652  //classes then executes CompileMacro on it.
653  //The name of the file depends on the class name, and it's not generated again
654  //if the file exist.
655  if (classes.empty()) {
656  return 0;
657  }
658  // Use the name of the first class as the main name.
659  const std::string& className = classes[0];
660  //(0) prepare file name
661  TString fileName = "AutoDict_";
662  std::string::const_iterator sIt;
663  for (sIt = className.begin(); sIt != className.end(); sIt++) {
664  if (*sIt == '<' || *sIt == '>' ||
665  *sIt == ' ' || *sIt == '*' ||
666  *sIt == ',' || *sIt == '&' ||
667  *sIt == ':') {
668  fileName += '_';
669  }
670  else {
671  fileName += *sIt;
672  }
673  }
674  if (classes.size() > 1) {
675  Int_t chk = 0;
676  std::vector<std::string>::const_iterator it = classes.begin();
677  while ((++it) != classes.end()) {
678  for (UInt_t cursor = 0; cursor != it->length(); ++cursor) {
679  chk = chk * 3 + it->at(cursor);
680  }
681  }
682  fileName += TString::Format("_%u", chk);
683  }
684  fileName += ".cxx";
685  if (gSystem->AccessPathName(fileName) != 0) {
686  //file does not exist
687  //(1) prepare file data
688  // If STL, also request iterators' operators.
689  // vector is special: we need to check whether
690  // vector::iterator is a typedef to pointer or a
691  // class.
692  static const std::set<std::string> sSTLTypes {
693  "vector","list","forward_list","deque","map","unordered_map","multimap",
694  "unordered_multimap","set","unordered_set","multiset","unordered_multiset",
695  "queue","priority_queue","stack","iterator"};
696  std::vector<std::string>::const_iterator it;
697  std::string fileContent("");
698  for (it = headers.begin(); it != headers.end(); ++it) {
699  fileContent += "#include \"" + *it + "\"\n";
700  }
701  for (it = unknown.begin(); it != unknown.end(); ++it) {
702  TClass* cl = TClass::GetClass(it->c_str());
703  if (cl && cl->GetDeclFileName()) {
704  TString header(gSystem->BaseName(cl->GetDeclFileName()));
705  TString dir(gSystem->DirName(cl->GetDeclFileName()));
706  TString dirbase(gSystem->BaseName(dir));
707  while (dirbase.Length() && dirbase != "."
708  && dirbase != "include" && dirbase != "inc"
709  && dirbase != "prec_stl") {
710  gSystem->PrependPathName(dirbase, header);
711  dir = gSystem->DirName(dir);
712  }
713  fileContent += TString("#include \"") + header + "\"\n";
714  }
715  }
716  for (it = fwdDecls.begin(); it != fwdDecls.end(); ++it) {
717  fileContent += "class " + *it + ";\n";
718  }
719  fileContent += "#ifdef __CINT__ \n";
720  fileContent += "#pragma link C++ nestedclasses;\n";
721  fileContent += "#pragma link C++ nestedtypedefs;\n";
722  for (it = classes.begin(); it != classes.end(); ++it) {
723  std::string n(*it);
724  size_t posTemplate = n.find('<');
725  std::set<std::string>::const_iterator iSTLType = sSTLTypes.end();
726  if (posTemplate != std::string::npos) {
727  n.erase(posTemplate, std::string::npos);
728  if (n.compare(0, 5, "std::") == 0) {
729  n.erase(0, 5);
730  }
731  iSTLType = sSTLTypes.find(n);
732  }
733  fileContent += "#pragma link C++ class ";
734  fileContent += *it + "+;\n" ;
735  fileContent += "#pragma link C++ class ";
736  if (iSTLType != sSTLTypes.end()) {
737  // STL class; we cannot (and don't need to) store iterators;
738  // their shadow and the compiler's version don't agree. So
739  // don't ask for the '+'
740  fileContent += *it + "::*;\n" ;
741  }
742  else {
743  // Not an STL class; we need to allow the I/O of contained
744  // classes (now that we have a dictionary for them).
745  fileContent += *it + "::*+;\n" ;
746  }
747  std::string oprLink("#pragma link C++ operators ");
748  oprLink += *it;
749  // Don't! Requests e.g. op<(const vector<T>&, const vector<T>&):
750  // fileContent += oprLink + ";\n";
751  if (iSTLType != sSTLTypes.end()) {
752  if (n == "vector") {
753  fileContent += "#ifdef G__VECTOR_HAS_CLASS_ITERATOR\n";
754  }
755  fileContent += oprLink + "::iterator;\n";
756  fileContent += oprLink + "::const_iterator;\n";
757  fileContent += oprLink + "::reverse_iterator;\n";
758  if (n == "vector") {
759  fileContent += "#endif\n";
760  }
761  }
762  }
763  fileContent += "#endif\n";
764  //end(1)
765  //(2) prepare the file
766  FILE* filePointer;
767  filePointer = fopen(fileName, "w");
768  if (filePointer == NULL) {
769  //can't open a file
770  return 1;
771  }
772  //end(2)
773  //write data into the file
774  fprintf(filePointer, "%s", fileContent.c_str());
775  fclose(filePointer);
776  }
777  //(3) checking if we can compile a macro, if not then cleaning
778  Int_t oldErrorIgnoreLevel = gErrorIgnoreLevel;
779  gErrorIgnoreLevel = kWarning; // no "Info: creating library..."
780  Int_t ret = gSystem->CompileMacro(fileName, "k");
781  gErrorIgnoreLevel = oldErrorIgnoreLevel;
782  if (ret == 0) { //can't compile a macro
783  return 2;
784  }
785  //end(3)
786  return 0;
787 }
788 
789 int TCling_GenerateDictionary(const std::string& className,
790  const std::vector<std::string> &headers,
791  const std::vector<std::string> &fwdDecls,
792  const std::vector<std::string> &unknown)
793 {
794  //This function automatically creates the "LinkDef.h" file for templated
795  //classes then executes CompileMacro on it.
796  //The name of the file depends on the class name, and it's not generated again
797  //if the file exist.
798  std::vector<std::string> classes;
799  classes.push_back(className);
800  return TCling_GenerateDictionary(classes, headers, fwdDecls, unknown);
801 }
802 
803 //______________________________________________________________________________
804 //
805 //
806 //
807 
808 // It is a "fantom" method to synchronize user keyboard input
809 // and ROOT prompt line (for WIN32)
810 const char* fantomline = "TRint::EndOfLineAction();";
811 
812 //______________________________________________________________________________
813 //
814 //
815 //
816 
817 void* TCling::fgSetOfSpecials = 0;
818 
819 //______________________________________________________________________________
820 //
821 // llvm error handler through exceptions; see also cling/UserInterface
822 //
823 namespace {
824  // Handle fatal llvm errors by throwing an exception.
825  // Yes, throwing exceptions in error handlers is bad.
826  // Doing nothing is pretty terrible, too.
827  void exceptionErrorHandler(void * /*user_data*/,
828  const std::string& reason,
829  bool /*gen_crash_diag*/) {
830  throw std::runtime_error(std::string(">>> Interpreter compilation error:\n") + reason);
831  }
832 }
833 
834 //______________________________________________________________________________
835 //
836 //
837 //
838 
839 ////////////////////////////////////////////////////////////////////////////////
840 
841 namespace{
842  // An instance of this class causes the diagnostics of clang to be suppressed
843  // during its lifetime
844  class clangDiagSuppr {
845  public:
846  clangDiagSuppr(clang::DiagnosticsEngine& diag): fDiagEngine(diag){
847  fOldDiagValue = fDiagEngine.getIgnoreAllWarnings();
848  fDiagEngine.setIgnoreAllWarnings(true);
849  }
850 
851  ~clangDiagSuppr() {
852  fDiagEngine.setIgnoreAllWarnings(fOldDiagValue);
853  }
854  private:
855  clang::DiagnosticsEngine& fDiagEngine;
856  bool fOldDiagValue;
857  };
858 
859 }
860 
861 ////////////////////////////////////////////////////////////////////////////////
862 /// Allow calling autoparsing from TMetaUtils
863 bool TClingLookupHelper__AutoParse(const char *cname)
864 {
865  return gCling->AutoParse(cname);
866 }
867 
868 ////////////////////////////////////////////////////////////////////////////////
869 /// Try hard to avoid looking up in the Cling database as this could enduce
870 /// an unwanted autoparsing.
871 
872 bool TClingLookupHelper__ExistingTypeCheck(const std::string &tname,
873  std::string &result)
874 {
875  result.clear();
876 
877  unsigned long offset = 0;
878  if (strncmp(tname.c_str(), "const ", 6) == 0) {
879  offset = 6;
880  }
881  unsigned long end = tname.length();
882  while( end && (tname[end-1]=='&' || tname[end-1]=='*' || tname[end-1]==']') ) {
883  if ( tname[end-1]==']' ) {
884  --end;
885  while ( end && tname[end-1]!='[' ) --end;
886  }
887  --end;
888  }
889  std::string innerbuf;
890  const char *inner;
891  if (end != tname.length()) {
892  innerbuf = tname.substr(offset,end-offset);
893  inner = innerbuf.c_str();
894  } else {
895  inner = tname.c_str()+offset;
896  }
897 
898  //if (strchr(tname.c_str(),'[')!=0) fprintf(stderr,"DEBUG: checking on %s vs %s %lu %lu\n",tname.c_str(),inner,offset,end);
899  if (gROOT->GetListOfClasses()->FindObject(inner)
900  || TClassTable::Check(inner,result) ) {
901  // This is a known class.
902  return true;
903  }
904 
905  THashTable *typeTable = dynamic_cast<THashTable*>( gROOT->GetListOfTypes() );
906  TDataType *type = (TDataType *)typeTable->THashTable::FindObject( inner );
907  if (type) {
908  // This is a raw type and an already loaded typedef.
909  const char *newname = type->GetFullTypeName();
910  if (type->GetType() == kLong64_t) {
911  newname = "Long64_t";
912  } else if (type->GetType() == kULong64_t) {
913  newname = "ULong64_t";
914  }
915  if (strcmp(inner,newname) == 0) {
916  return true;
917  }
918  if (offset) result = "const ";
919  result += newname;
920  if ( end != tname.length() ) {
921  result += tname.substr(end,tname.length()-end);
922  }
923  if (result == tname) result.clear();
924  return true;
925  }
926 
927  // Check if the name is an enumerator
928  const auto lastPos = TClassEdit::GetUnqualifiedName(inner);
929  if (lastPos != inner) // Main switch: case 1 - scoped enum, case 2 global enum
930  {
931  // We have a scope
932  // All of this C gymnastic is to avoid allocations on the heap
933  const auto enName = lastPos;
934  const auto scopeNameSize = ((Long64_t)lastPos - (Long64_t)inner) / sizeof(decltype(*lastPos)) - 2;
935  char *scopeName = new char[scopeNameSize + 1];
936  strncpy(scopeName, inner, scopeNameSize);
937  scopeName[scopeNameSize] = '\0';
938  // Check if the scope is in the list of classes
939  if (auto scope = static_cast<TClass *>(gROOT->GetListOfClasses()->FindObject(scopeName))) {
940  auto enumTable = dynamic_cast<const THashList *>(scope->GetListOfEnums(false));
941  if (enumTable && enumTable->THashList::FindObject(enName)) return true;
942  }
943  // It may still be in one of the loaded protoclasses
944  else if (auto scope = static_cast<TProtoClass *>(gClassTable->GetProtoNorm(scopeName))) {
945  auto listOfEnums = scope->GetListOfEnums();
946  if (listOfEnums) { // it could be null: no enumerators in the protoclass
947  auto enumTable = dynamic_cast<const THashList *>(listOfEnums);
948  if (enumTable && enumTable->THashList::FindObject(enName)) return true;
949  }
950  }
951  delete [] scopeName;
952  } else
953  {
954  // We don't have any scope: this could only be a global enum
955  auto enumTable = dynamic_cast<const THashList *>(gROOT->GetListOfEnums());
956  if (enumTable && enumTable->THashList::FindObject(inner)) return true;
957  }
958 
959  if (gCling->GetClassSharedLibs(inner))
960  {
961  // This is a class name.
962  return true;
963  }
964 
965  return false;
966 }
967 
968 ////////////////////////////////////////////////////////////////////////////////
969 
971 {
972  fContent.reserve(size);
973 }
974 
975 ////////////////////////////////////////////////////////////////////////////////
976 
977 inline const char *TCling::TUniqueString::Data()
978 {
979  return fContent.c_str();
980 }
981 
982 ////////////////////////////////////////////////////////////////////////////////
983 /// Append string to the storage if not added already.
984 
985 inline bool TCling::TUniqueString::Append(const std::string& str)
986 {
987  bool notPresent = fLinesHashSet.emplace(fHashFunc(str)).second;
988  if (notPresent){
989  fContent+=str;
990  }
991  return notPresent;
992 }
993 
994 ////////////////////////////////////////////////////////////////////////////////
995 /// Initialize the cling interpreter interface.
996 
997 TCling::TCling(const char *name, const char *title)
998 : TInterpreter(name, title), fGlobalsListSerial(-1), fInterpreter(0),
999  fMetaProcessor(0), fNormalizedCtxt(0), fPrevLoadedDynLibInfo(0),
1000  fClingCallbacks(0), fAutoLoadCallBack(0),
1001  fTransactionCount(0), fHeaderParsingOnDemand(true), fIsAutoParsingSuspended(kFALSE)
1002 {
1003  // rootcling also uses TCling for generating the dictionary ROOT files.
1004  bool fromRootCling = dlsym(RTLD_DEFAULT, "usedToIdentifyRootClingByDlSym");
1005 
1006  llvm::install_fatal_error_handler(&exceptionErrorHandler);
1007 
1008  fTemporaries = new std::vector<cling::Value>();
1009 
1010  std::vector<std::string> clingArgsStorage;
1011  clingArgsStorage.push_back("cling4root");
1012 
1013  // rootcling sets its arguments through TROOT::GetExtraInterpreterArgs().
1014  if (!fromRootCling) {
1017  // Add -I early so ASTReader can find the headers.
1018  std::string interpInclude(TROOT::GetEtcDir());
1019  clingArgsStorage.push_back("-I" + interpInclude);
1020 
1021  // Add include path to etc/cling. FIXME: This is a short term solution. The
1022  // llvm/clang header files shouldn't be there at all. We have to get rid of
1023  // that dependency and avoid copying the header files.
1024  clingArgsStorage.push_back("-I" + interpInclude + "/cling");
1025 
1026  // Add the root include directory and etc/ to list searched by default.
1027  clingArgsStorage.push_back(std::string("-I" + TROOT::GetIncludeDir()));
1028 
1029  // Add the current path to the include path
1030  // TCling::AddIncludePath(".");
1032  std::string pchFilename = interpInclude + "/allDict.cxx.pch";
1033  if (gSystem->Getenv("ROOT_PCH")) {
1034  pchFilename = gSystem->Getenv("ROOT_PCH");
1035  }
1036  clingArgsStorage.push_back("-include-pch");
1037  clingArgsStorage.push_back(pchFilename);
1038 
1039  // clingArgsStorage.push_back("-Xclang");
1040  // clingArgsStorage.push_back("-fmodules");
1041 
1042  clingArgsStorage.push_back("-Wno-undefined-inline");
1043  clingArgsStorage.push_back("-fsigned-char");
1044  }
1045 
1046  std::vector<const char*> interpArgs;
1047  for (std::vector<std::string>::const_iterator iArg = clingArgsStorage.begin(),
1048  eArg = clingArgsStorage.end(); iArg != eArg; ++iArg)
1049  interpArgs.push_back(iArg->c_str());
1050 
1051 #ifdef R__EXTERN_LLVMDIR
1052  TString llvmResourceDir = R__EXTERN_LLVMDIR;
1053 #else
1054  TString llvmResourceDir = TROOT::GetEtcDir() + "/cling";
1055 #endif
1056  // Add statically injected extra arguments, usually coming from rootcling.
1057  for (const char** extraArgs = TROOT::GetExtraInterpreterArgs();
1058  extraArgs && *extraArgs; ++extraArgs) {
1059  if (!strcmp(*extraArgs, "-resource-dir")) {
1060  // Take the next arg as the llvm resource directory.
1061  llvmResourceDir = *(++extraArgs);
1062  } else {
1063  interpArgs.push_back(*extraArgs);
1064  }
1065  }
1066 
1067  fInterpreter = new cling::Interpreter(interpArgs.size(),
1068  &(interpArgs[0]),
1069  llvmResourceDir);
1070 
1071  if (!fromRootCling) {
1072  fInterpreter->installLazyFunctionCreator(llvmLazyFunctionCreator);
1073  }
1074 
1075  // Don't check whether modules' files exist.
1076  fInterpreter->getCI()->getPreprocessorOpts().DisablePCHValidation = true;
1077 
1078  // Until we can disable autoloading during Sema::CorrectTypo() we have
1079  // to disable spell checking.
1080  fInterpreter->getCI()->getLangOpts().SpellChecking = false;
1081 
1082 
1083  // We need stream that doesn't close its file descriptor, thus we are not
1084  // using llvm::outs. Keeping file descriptor open we will be able to use
1085  // the results in pipes (Savannah #99234).
1086  static llvm::raw_fd_ostream fMPOuts (STDOUT_FILENO, /*ShouldClose*/false);
1087  fMetaProcessor = new cling::MetaProcessor(*fInterpreter, fMPOuts);
1088 
1089  // For the list to also include string, we have to include it now.
1090  // rootcling does parts already if needed, e.g. genreflex does not want using
1091  // namespace std.
1092  if (fromRootCling) {
1093  fInterpreter->declare("#include \"RtypesCore.h\"\n"
1094  "#include <string>\n"
1095  "using std::string;");
1096  } else {
1097  fInterpreter->declare("#include \"Rtypes.h\"\n"
1098  + gClassDefInterpMacro + "\n"
1099  + gInterpreterClassDef + "\n"
1100  + "#undef ClassImp\n"
1101  "#define ClassImp(X)\n"
1102  "#include <string>\n"
1103  "using namespace std;");
1104  }
1105 
1106  // We are now ready (enough is loaded) to init the list of opaque typedefs.
1107  fNormalizedCtxt = new ROOT::TMetaUtils::TNormalizedCtxt(fInterpreter->getLookupHelper());
1109  TClassEdit::Init(fLookupHelper);
1110 
1111  // Initialize the cling interpreter interface.
1112  fMore = 0;
1113  fPrompt[0] = 0;
1114  fMapfile = 0;
1115 // fMapNamespaces = 0;
1116  fRootmapFiles = 0;
1117  fLockProcessLine = kTRUE;
1118 
1119  fAllowLibLoad = !fromRootCling;
1120  // Disallow auto-parsing in rootcling
1121  fIsAutoParsingSuspended = fromRootCling;
1122  // Disable the autoloader until it is explicitly enabled.
1123  SetClassAutoloading(false);
1124 
1125  ResetAll();
1126 #ifndef R__WIN32
1127  //optind = 1; // make sure getopt() works in the main program
1128 #endif // R__WIN32
1129 
1130  // Enable dynamic lookup
1131  if (!fromRootCling) {
1132  fInterpreter->enableDynamicLookup();
1133  }
1134 
1135  // Attach cling callbacks last; they might need TROOT::fInterpreter
1136  // and should thus not be triggered during the equivalent of
1137  // TROOT::fInterpreter = new TCling;
1138  std::unique_ptr<TClingCallbacks>
1139  clingCallbacks(new TClingCallbacks(fInterpreter));
1140  fClingCallbacks = clingCallbacks.get();
1141  fClingCallbacks->SetAutoParsingSuspended(fIsAutoParsingSuspended);
1142  fInterpreter->setCallbacks(std::move(clingCallbacks));
1143 
1144 }
1145 
1146 
1147 ////////////////////////////////////////////////////////////////////////////////
1148 /// Destroy the interpreter interface.
1149 
1151 {
1152  delete fMapfile;
1153 // delete fMapNamespaces;
1154  delete fRootmapFiles;
1155  delete fMetaProcessor;
1156  delete fTemporaries;
1157  delete fNormalizedCtxt;
1158  delete fInterpreter;
1159  delete fLookupHelper;
1160  gCling = 0;
1161 #if defined(R__MUST_REVISIT)
1162 #if R__MUST_REVISIT(6,2)
1163  Warning("~TCling", "Interface not available yet.");
1164 #ifdef R__COMPLETE_MEM_TERMINATION
1165  // remove all cling objects
1166 #endif
1167 #endif
1168 #endif
1169  //--
1170 }
1171 
1172 ////////////////////////////////////////////////////////////////////////////////
1173 /// Initialize the interpreter, once TROOT::fInterpreter is set.
1174 
1175 void TCling::Initialize()
1176 {
1178 }
1179 
1180 ////////////////////////////////////////////////////////////////////////////////
1181 /// Wrapper around dladdr (and friends)
1182 
1183 static const char *FindLibraryName(void (*func)())
1184 {
1185 #if defined(__CYGWIN__) && defined(__GNUC__)
1186  return 0;
1187 #elif defined(G__WIN32)
1188  MEMORY_BASIC_INFORMATION mbi;
1189  if (!VirtualQuery (func, &mbi, sizeof (mbi)))
1190  {
1191  return 0;
1192  }
1193 
1194  HMODULE hMod = (HMODULE) mbi.AllocationBase;
1195  TTHREAD_TLS_ARRAY(char, MAX_PATH, moduleName);
1197  if (!GetModuleFileNameA (hMod, moduleName, sizeof (moduleName)))
1198  {
1199  return 0;
1200  }
1201  return moduleName;
1202 #else
1203  Dl_info info;
1204  if (dladdr((void*)func,&info)==0) {
1205  // Not in a known share library, let's give up
1206  return 0;
1207  } else {
1208  //fprintf(stdout,"Found address in %s\n",info.dli_fname);
1209  return info.dli_fname;
1210  }
1211 #endif
1212 
1213 }
1214 
1215 ////////////////////////////////////////////////////////////////////////////////
1216 /// Helper to initialize TVirtualStreamerInfo's factor early.
1217 /// Use static initialization to insure only one TStreamerInfo is created.
1218 static bool R__InitStreamerInfoFactory()
1219 {
1220  // Use lambda since SetFactory return void.
1221  auto setFactory = []() {
1223  return kTRUE;
1224  };
1225  static bool doneFactory = setFactory();
1226  return doneFactory; // avoid unused variable warning.
1227 }
1228 
1230 ////////////////////////////////////////////////////////////////////////////////
1231 /// Tries to load a PCM; returns true on success.
1232 
1233 bool TCling::LoadPCM(TString pcmFileName,
1234  const char** headers,
1235  void (*triggerFunc)()) const {
1236  // pcmFileName is an intentional copy; updated by FindFile() below.
1237 
1238  TString searchPath;
1239 
1240  if (triggerFunc) {
1241  const char *libraryName = FindLibraryName(triggerFunc);
1242  if (libraryName) {
1243  searchPath = llvm::sys::path::parent_path(libraryName);
1244 #ifdef R__WIN32
1245  searchPath += ";";
1246 #else
1247  searchPath += ":";
1248 #endif
1249  }
1250  }
1251  // Note: if we know where the library is, we probably shouldn't even
1252  // look in other places.
1253  searchPath.Append( gSystem->GetDynamicPath() );
1254 
1255  if (!gSystem->FindFile(searchPath, pcmFileName))
1256  return kFALSE;
1257 
1258  // Prevent the ROOT-PCMs hitting this during auto-load during
1259  // JITting - which will cause recursive compilation.
1260  // Avoid to call the plugin manager at all.
1262 
1263  if (gROOT->IsRootFile(pcmFileName)) {
1264  Int_t oldDebug = gDebug;
1265  if (gDebug > 5) {
1266  gDebug -= 5;
1267  ::Info("TCling::LoadPCM", "Loading ROOT PCM %s", pcmFileName.Data());
1268  } else {
1269  gDebug = 0;
1270  }
1271 
1272  TDirectory::TContext ctxt;
1273 
1274  TFile *pcmFile = new TFile(pcmFileName+"?filetype=pcm","READ");
1275 
1276  auto listOfKeys = pcmFile->GetListOfKeys();
1277 
1278  // This is an empty pcm
1279  if (
1280  listOfKeys &&
1281  (
1282  (listOfKeys->GetSize() == 0) || // Nothing here, or
1283  (
1284  (listOfKeys->GetSize() == 1) && // only one, and
1285  !strcmp(((TKey*)listOfKeys->At(0))->GetName(), "EMPTY") // name is EMPTY
1286  )
1287  )
1288  ) {
1289  delete pcmFile;
1290  gDebug = oldDebug;
1291  return kTRUE;
1292  }
1293 
1294  TObjArray *protoClasses;
1295  if (gDebug > 1)
1296  ::Info("TCling::LoadPCM","reading protoclasses for %s \n",pcmFileName.Data());
1297 
1298  pcmFile->GetObject("__ProtoClasses", protoClasses);
1299 
1300  if (protoClasses) {
1301  for (auto obj : *protoClasses) {
1302  TProtoClass * proto = (TProtoClass*)obj;
1303  TClassTable::Add(proto);
1304  }
1305  // Now that all TClass-es know how to set them up we can update
1306  // existing TClasses, which might cause the creation of e.g. TBaseClass
1307  // objects which in turn requires the creation of TClasses, that could
1308  // come from the PCH, but maybe later in the loop. Instead of resolving
1309  // a dependency graph the addition to the TClassTable above allows us
1310  // to create these dependent TClasses as needed below.
1311  for (auto proto : *protoClasses) {
1312  if (TClass* existingCl
1313  = (TClass*)gROOT->GetListOfClasses()->FindObject(proto->GetName())) {
1314  // We have an existing TClass object. It might be emulated
1315  // or interpreted; we now have more information available.
1316  // Make that available.
1317  if (existingCl->GetState() != TClass::kHasTClassInit) {
1318  DictFuncPtr_t dict = gClassTable->GetDict(proto->GetName());
1319  if (!dict) {
1320  ::Error("TCling::LoadPCM", "Inconsistent TClassTable for %s",
1321  proto->GetName());
1322  } else {
1323  // This will replace the existing TClass.
1324  TClass *ncl = (*dict)();
1325  if (ncl) ncl->PostLoadCheck();
1326 
1327  }
1328  }
1329  }
1330  }
1331 
1332  protoClasses->Clear(); // Ownership was transfered to TClassTable.
1333  delete protoClasses;
1334  }
1335 
1336  TObjArray *dataTypes;
1337  pcmFile->GetObject("__Typedefs", dataTypes);
1338  if (dataTypes) {
1339  for (auto typedf: *dataTypes)
1340  gROOT->GetListOfTypes()->Add(typedf);
1341  dataTypes->Clear(); // Ownership was transfered to TListOfTypes.
1342  delete dataTypes;
1343  }
1344 
1345  TObjArray *enums;
1346  pcmFile->GetObject("__Enums", enums);
1347  if (enums) {
1348  // Cache the pointers
1349  auto listOfGlobals = gROOT->GetListOfGlobals();
1350  auto listOfEnums = dynamic_cast<THashList*>(gROOT->GetListOfEnums());
1351  // Loop on enums and then on enum constants
1352  for (auto selEnum: *enums){
1353  const char* enumScope = selEnum->GetTitle();
1354  const char* enumName = selEnum->GetName();
1355  if (strcmp(enumScope,"") == 0){
1356  // This is a global enum and is added to the
1357  // list of enums and its constants to the list of globals
1358  if (!listOfEnums->THashList::FindObject(enumName)){
1359  ((TEnum*) selEnum)->SetClass(nullptr);
1360  listOfEnums->Add(selEnum);
1361  }
1362  for (auto enumConstant: *static_cast<TEnum*>(selEnum)->GetConstants()){
1363  if (!listOfGlobals->FindObject(enumConstant)){
1364  listOfGlobals->Add(enumConstant);
1365  }
1366  }
1367  }
1368  else {
1369  // This enum is in a namespace. A TClass entry is bootstrapped if
1370  // none exists yet and the enum is added to it
1371  TClass* nsTClassEntry = TClass::GetClass(enumScope);
1372  if (!nsTClassEntry){
1373  nsTClassEntry = new TClass(enumScope,0,TClass::kNamespaceForMeta, true);
1374  }
1375  auto listOfEnums = nsTClassEntry->fEnums.load();
1376  if (!listOfEnums) {
1377  if ( (kIsClass | kIsStruct | kIsUnion) & nsTClassEntry->Property() ) {
1378  // For this case, the list will be immutable once constructed
1379  // (i.e. in this case, by the end of this routine).
1380  listOfEnums = nsTClassEntry->fEnums = new TListOfEnums(nsTClassEntry);
1381  } else {
1382  //namespaces can have enums added to them
1383  listOfEnums = nsTClassEntry->fEnums = new TListOfEnumsWithLock(nsTClassEntry);
1384  }
1385  }
1386  if (listOfEnums && !listOfEnums->THashList::FindObject(enumName)){
1387  ((TEnum*) selEnum)->SetClass(nsTClassEntry);
1388  listOfEnums->Add(selEnum);
1389  }
1390  }
1391  }
1392  enums->Clear();
1393  delete enums;
1394  }
1395 
1396  delete pcmFile;
1397 
1398  gDebug = oldDebug;
1399  } else {
1400  if (gDebug > 5)
1401  ::Info("TCling::LoadPCM", "Loading clang PCM %s", pcmFileName.Data());
1402 
1403  }
1404  // Note: Declaring the relationship between the module (pcm) and the header
1405  // probably does not yet make sense since the pcm is 'only' a root file.
1406  // We also have to review if we still need to do this with the delay loading.
1407  // clang::CompilerInstance* CI = fInterpreter->getCI();
1408  // ROOT::TMetaUtils::declareModuleMap(CI, pcmFileName, headers);
1409  return kTRUE;
1410 }
1411 
1412 //______________________________________________________________________________
1413 
1414 namespace {
1415  using namespace clang;
1416 
1417  class ExtLexicalStorageAdder: public RecursiveASTVisitor<ExtLexicalStorageAdder>{
1418  // This class is to be considered an helper for autoparsing.
1419  // It visits the AST and marks all classes (in all of their redeclarations)
1420  // with the setHasExternalLexicalStorage method.
1421  public:
1422  bool VisitRecordDecl(clang::RecordDecl* rcd){
1423  if (gDebug > 2)
1424  Info("ExtLexicalStorageAdder",
1425  "Adding external lexical storage to class %s",
1426  rcd->getNameAsString().c_str());
1427  auto reDeclPtr = rcd->getMostRecentDecl();
1428  do {
1429  reDeclPtr->setHasExternalLexicalStorage();
1430  } while ((reDeclPtr = reDeclPtr->getPreviousDecl()));
1431 
1432  return false;
1433  }
1434  };
1435 
1436 
1437 }
1438 
1439 ////////////////////////////////////////////////////////////////////////////////
1440 /// Inject the module named "modulename" into cling; load all headers.
1441 /// headers is a 0-terminated array of header files to #include after
1442 /// loading the module. The module is searched for in all $LD_LIBRARY_PATH
1443 /// entries (or %PATH% on Windows).
1444 /// This function gets called by the static initialization of dictionary
1445 /// libraries.
1446 /// The payload code is injected "as is" in the interpreter.
1447 /// The value of 'triggerFunc' is used to find the shared library location.
1448 
1449 void TCling::RegisterModule(const char* modulename,
1450  const char** headers,
1451  const char** includePaths,
1452  const char* payloadCode,
1453  const char* fwdDeclsCode,
1454  void (*triggerFunc)(),
1455  const FwdDeclArgsToKeepCollection_t& fwdDeclsArgToSkip,
1456  const char** classesHeaders,
1457  Bool_t lateRegistration /*=false*/)
1458 {
1459  // rootcling also uses TCling for generating the dictionary ROOT files.
1460  static const bool fromRootCling = dlsym(RTLD_DEFAULT, "usedToIdentifyRootClingByDlSym");
1461  // We need the dictionary initialization but we don't want to inject the
1462  // declarations into the interpreter, except for those we really need for
1463  // I/O; see rootcling.cxx after the call to TCling__GetInterpreter().
1464  if (fromRootCling) return;
1465 
1466  // Treat Aclic Libs in a special way. Do not delay the parsing.
1467  bool hasHeaderParsingOnDemand = fHeaderParsingOnDemand;
1468  bool isACLiC = false;
1469  if (hasHeaderParsingOnDemand &&
1470  strstr(modulename, "_ACLiC_dict") != nullptr){
1471  if (gDebug>1)
1472  Info("TCling::RegisterModule",
1473  "Header parsing on demand is active but this is an Aclic library. Disabling it for this library.");
1474  hasHeaderParsingOnDemand = false;
1475  isACLiC = true;
1476  }
1477 
1478 
1479  // Make sure we relookup symbols that were search for before we loaded
1480  // their autoparse information. We could be more subtil and remove only
1481  // the failed one or only the one in this module, but for now this is
1482  // better than nothing.
1483  fLookedUpClasses.clear();
1484 
1485  // Make sure we do not set off autoloading or autoparsing during the
1486  // module registration!
1487  Int_t oldAutoloadValue = SetClassAutoloading(false);
1488 
1489  TString pcmFileName(ROOT::TMetaUtils::GetModuleFileName(modulename).c_str());
1490 
1491  for (const char** inclPath = includePaths; *inclPath; ++inclPath) {
1492  TCling::AddIncludePath(*inclPath);
1493  }
1494  cling::Transaction* T = 0;
1495  // Put the template decls and the number of arguments to skip in the TNormalizedCtxt
1496  for (auto& fwdDeclArgToSkipPair : fwdDeclsArgToSkip){
1497  const std::string& fwdDecl = fwdDeclArgToSkipPair.first;
1498  const int nArgsToSkip = fwdDeclArgToSkipPair.second;
1499  auto compRes = fInterpreter->declare(fwdDecl.c_str(), &T);
1500  assert(cling::Interpreter::kSuccess == compRes &&
1501  "A fwd declaration could not be compiled");
1502  if (compRes!=cling::Interpreter::kSuccess){
1503  Warning("TCling::RegisterModule",
1504  "Problems in declaring string '%s' were encountered.",
1505  fwdDecl.c_str()) ;
1506  continue;
1507  }
1508 
1509  // Drill through namespaces recursively until the template is found
1510  if(ClassTemplateDecl* TD = FindTemplateInNamespace(T->getFirstDecl().getSingleDecl())){
1511  fNormalizedCtxt->AddTemplAndNargsToKeep(TD->getCanonicalDecl(), nArgsToSkip);
1512  }
1513 
1514  }
1515 
1516  // FIXME: Remove #define __ROOTCLING__ once PCMs are there.
1517  // This is used to give Sema the same view on ACLiC'ed files (which
1518  // are then #included through the dictionary) as rootcling had.
1519  TString code = gNonInterpreterClassDef;
1520  code += payloadCode;
1521 
1522  const char* dyLibName = nullptr;
1523  // If this call happens after dlopen has finished (i.e. late registration)
1524  // there is no need to dlopen the library recursively. See ROOT-8437 where
1525  // the dyLibName would correspond to the binary.
1526  if (!lateRegistration) {
1527  // We need to open the dictionary shared library, to resolve symbols
1528  // requested by the JIT from it: as the library is currently being dlopen'ed,
1529  // its symbols are not yet reachable from the process.
1530  // Recursive dlopen seems to work just fine.
1531  dyLibName = FindLibraryName(triggerFunc);
1532  if (dyLibName) {
1533  // We were able to determine the library name.
1534  void* dyLibHandle = dlopen(dyLibName, RTLD_LAZY | RTLD_GLOBAL);
1535  if (!dyLibHandle) {
1536 #ifdef R__WIN32
1537  char dyLibError[1000];
1538  FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(),
1539  MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), dyLibError,
1540  sizeof(dyLibError), NULL);
1541 #else
1542  const char* dyLibError = dlerror();
1543  if (dyLibError)
1544 #endif
1545  {
1546  if (gDebug > 0) {
1547  ::Info("TCling::RegisterModule",
1548  "Cannot open shared library %s for dictionary %s:\n %s",
1549  dyLibName, modulename, dyLibError);
1550  }
1551  }
1552  dyLibName = 0;
1553  } else {
1554  fRegisterModuleDyLibs.push_back(dyLibHandle);
1555  } // if (!dyLibHandle) .. else
1556  } // if (dyLibName)
1557  } // if (!lateRegistration)
1558 
1559  if (hasHeaderParsingOnDemand && fwdDeclsCode){
1560  // We now parse the forward declarations. All the classes are then modified
1561  // in order for them to have an external lexical storage.
1562  std::string fwdDeclsCodeLessEnums;
1563  {
1564  // Search for enum forward decls and only declare them if no
1565  // declaration exists yet.
1566  std::string fwdDeclsLine;
1567  std::istringstream fwdDeclsCodeStr(fwdDeclsCode);
1568  std::vector<std::string> scope;
1569  while (std::getline(fwdDeclsCodeStr, fwdDeclsLine)) {
1570  if (fwdDeclsLine.find("namespace ") == 0
1571  || fwdDeclsLine.find("inline namespace ") == 0) {
1572  // skip leading "namespace ", trailing " {"
1573  scope.push_back(fwdDeclsLine.substr(10,
1574  fwdDeclsLine.length() - 10 - 2));
1575  } else if (fwdDeclsLine == "}") {
1576  scope.pop_back();
1577  } else if (fwdDeclsLine.find("enum __attribute__((annotate(\"") == 0) {
1578  clang::DeclContext* DC = 0;
1579  for (auto &&aScope: scope) {
1580  DC = cling::utils::Lookup::Namespace(&fInterpreter->getSema(), aScope.c_str(), DC);
1581  if (!DC) {
1582  // No decl context means we have to fwd declare the enum.
1583  break;
1584  }
1585  }
1586  if (scope.empty() || DC) {
1587  // We know the scope; let's look for the enum.
1588  size_t posEnumName = fwdDeclsLine.find("\"))) ", 32);
1589  R__ASSERT(posEnumName != std::string::npos && "Inconsistent enum fwd decl!");
1590  posEnumName += 5; // skip "\"))) "
1591  while (isspace(fwdDeclsLine[posEnumName]))
1592  ++posEnumName;
1593  size_t posEnumNameEnd = fwdDeclsLine.find(" : ", posEnumName);
1594  R__ASSERT(posEnumNameEnd != std::string::npos && "Inconsistent enum fwd decl (end)!");
1595  while (isspace(fwdDeclsLine[posEnumNameEnd]))
1596  --posEnumNameEnd;
1597  // posEnumNameEnd now points to the last character of the name.
1598 
1599  std::string enumName = fwdDeclsLine.substr(posEnumName,
1600  posEnumNameEnd - posEnumName + 1);
1601 
1602  if (clang::NamedDecl* enumDecl
1603  = cling::utils::Lookup::Named(&fInterpreter->getSema(),
1604  enumName.c_str(), DC)) {
1605  // We have an existing enum decl (forward or definition);
1606  // skip this.
1607  R__ASSERT(llvm::dyn_cast<clang::EnumDecl>(enumDecl) && "not an enum decl!");
1608  (void)enumDecl;
1609  continue;
1610  }
1611  }
1612  }
1613  fwdDeclsCodeLessEnums += fwdDeclsLine + "\n";
1614  }
1615  }
1616 
1617  if (fwdDeclsCodeLessEnums.size() != 0){ // Avoid the overhead if nothing is to be declared
1618  auto compRes = fInterpreter->declare(fwdDeclsCodeLessEnums, &T);
1619  assert(cling::Interpreter::kSuccess == compRes &&
1620  "The forward declarations could not be compiled");
1621  if (compRes!=cling::Interpreter::kSuccess){
1622  Warning("TCling::RegisterModule",
1623  "Problems in compiling forward declarations for module %s: '%s'",
1624  modulename, fwdDeclsCodeLessEnums.c_str()) ;
1625  }
1626  else if (T){
1627  // Loop over all decls in the transaction and go through them all
1628  // to mark them properly.
1629  // In order to do that, we first iterate over all the DelayedCallInfos
1630  // within the transaction. Then we loop over all Decls in the DeclGroupRef
1631  // contained in the DelayedCallInfos. For each decl, we traverse.
1632  ExtLexicalStorageAdder elsa;
1633  for (auto dciIt = T->decls_begin();dciIt!=T->decls_end();dciIt++){
1634  cling::Transaction::DelayCallInfo& dci = *dciIt;
1635  for(auto dit = dci.m_DGR.begin(); dit != dci.m_DGR.end(); ++dit) {
1636  clang::Decl* declPtr = *dit;
1637  elsa.TraverseDecl(declPtr);
1638  }
1639  }
1640  }
1641  }
1642 
1643  // Now we register all the headers necessary for the class
1644  // Typical format of the array:
1645  // {"A", "classes.h", "@",
1646  // "vector<A>", "vector", "@",
1647  // "myClass", payloadCode, "@",
1648  // nullptr};
1649 
1650  std::string temp;
1651  for (const char** classesHeader = classesHeaders; *classesHeader; ++classesHeader) {
1652  temp=*classesHeader;
1653 
1654  size_t theTemplateHash = 0;
1655  bool addTemplate = false;
1656  size_t posTemplate = temp.find('<');
1657  if (posTemplate != std::string::npos) {
1658  // Add an entry for the template itself.
1659  std::string templateName = temp.substr(0, posTemplate);
1660  theTemplateHash = fStringHashFunction(templateName);
1661  addTemplate = true;
1662  }
1663  size_t theHash = fStringHashFunction(temp);
1664  classesHeader++;
1665  for (const char** classesHeader_inner = classesHeader; 0!=strcmp(*classesHeader_inner,"@"); ++classesHeader_inner,++classesHeader){
1666  // This is done in order to distinguish headers from files and from the payloadCode
1667  if (payloadCode == *classesHeader_inner ){
1668  fPayloads.insert(theHash);
1669  if (addTemplate) fPayloads.insert(theTemplateHash);
1670  }
1671  if (gDebug > 2)
1672  Info("TCling::RegisterModule",
1673  "Adding a header for %s", temp.c_str());
1674  fClassesHeadersMap[theHash].push_back(*classesHeader_inner);
1675  if (addTemplate) {
1676  if (fClassesHeadersMap.find(theTemplateHash) == fClassesHeadersMap.end()) {
1677  fClassesHeadersMap[theTemplateHash].push_back(*classesHeader_inner);
1678  }
1679  addTemplate = false;
1680  }
1681  }
1682  }
1683  }
1684 
1685 
1686  if (strcmp(modulename,"libCore")!=0 && strcmp(modulename,"libRint")!=0
1687  && strcmp(modulename,"libThread")!=0 && strcmp(modulename,"libRIO")!=0
1688  && strcmp(modulename,"libcomplexDict")!=0 && strcmp(modulename,"libdequeDict")!=0
1689  && strcmp(modulename,"liblistDict")!=0 && strcmp(modulename,"libforward_listDict")!=0
1690  && strcmp(modulename,"libvectorDict")!=0
1691  && strcmp(modulename,"libmapDict")!=0 && strcmp(modulename,"libmultimap2Dict")!=0
1692  && strcmp(modulename,"libmap2Dict")!=0 && strcmp(modulename,"libmultimapDict")!=0
1693  && strcmp(modulename,"libsetDict")!=0 && strcmp(modulename,"libmultisetDict")!=0
1694  && strcmp(modulename,"libunordered_setDict")!=0 && strcmp(modulename,"libunordered_multisetDict")!=0
1695  && strcmp(modulename,"libunordered_mapDict")!=0 && strcmp(modulename,"libunordered_multimapDict")!=0
1696  && strcmp(modulename,"libvalarrayDict")!=0
1697  && strcmp(modulename,"G__GenVector32")!=0 && strcmp(modulename,"G__Smatrix32")!=0
1698 
1699  ) {
1700  // No pcm for now for libCore or libRint, the info is in the pch.
1701  if (!LoadPCM(pcmFileName, headers, triggerFunc)) {
1702  ::Error("TCling::RegisterModule", "cannot find dictionary module %s",
1703  ROOT::TMetaUtils::GetModuleFileName(modulename).c_str());
1704  }
1705  }
1706 
1707  bool oldValue = false;
1708  if (fClingCallbacks)
1709  oldValue = SetClassAutoloading(false);
1710 
1711  { // scope within which diagnostics are de-activated
1712  // For now we disable diagnostics because we saw them already at
1713  // dictionary generation time. That won't be an issue with the PCMs.
1714 
1715  clangDiagSuppr diagSuppr(fInterpreter->getSema().getDiagnostics());
1716 
1717 #if defined(R__MUST_REVISIT)
1718 #if R__MUST_REVISIT(6,2)
1719  Warning("TCling::RegisterModule","Diagnostics suppression should be gone by now.");
1720 #endif
1721 #endif
1722 
1723  if (!hasHeaderParsingOnDemand){
1724  SuspendAutoParsing autoParseRaii(this);
1725 
1726  const cling::Transaction* watermark = fInterpreter->getLastTransaction();
1727  cling::Interpreter::CompilationResult compRes = fInterpreter->parseForModule(code.Data());
1728  if (isACLiC) {
1729  // Register an unload point.
1730  fMetaProcessor->registerUnloadPoint(watermark, headers[0]);
1731  }
1732 
1733  assert(cling::Interpreter::kSuccess == compRes &&
1734  "Payload code of a dictionary could not be parsed correctly.");
1735  if (compRes!=cling::Interpreter::kSuccess) {
1736  Warning("TCling::RegisterModule",
1737  "Problems declaring payload for module %s.", modulename) ;
1738  }
1739  }
1740  }
1741 
1742  // Now that all the header have been registered/compiled, let's
1743  // make sure to 'reset' the TClass that have a class init in this module
1744  // but already had their type information available (using information/header
1745  // loaded from other modules or from class rules).
1746  if (!hasHeaderParsingOnDemand) {
1747  // This code is likely to be superseded by the similar code in LoadPCM,
1748  // and have been disabled, (inadvertently or awkwardly) by
1749  // commit 7903f09f3beea69e82ffba29f59fb2d656a4fd54 (Refactor the routines used for header parsing on demand)
1750  // whereas it seems that a more semantically correct conditional would have
1751  // been 'if this module does not have a rootpcm'.
1752  // Note: this need to be review when the clang pcm are being installed.
1753  // #if defined(R__MUST_REVISIT)
1754  while (!fClassesToUpdate.empty()) {
1755  TClass *oldcl = fClassesToUpdate.back().first;
1756  if (oldcl->GetState() != TClass::kHasTClassInit) {
1757  // if (gDebug > 2) Info("RegisterModule", "Forcing TClass init for %s", oldcl->GetName());
1758  DictFuncPtr_t dict = fClassesToUpdate.back().second;
1759  fClassesToUpdate.pop_back();
1760  // Calling func could manipulate the list so, let maintain the list
1761  // then call the dictionary function.
1762  TClass *ncl = dict();
1763  if (ncl) ncl->PostLoadCheck();
1764  } else {
1765  fClassesToUpdate.pop_back();
1766  }
1767  }
1768  }
1769 
1770  if (fClingCallbacks)
1771  SetClassAutoloading(oldValue);
1772 
1773  if (!hasHeaderParsingOnDemand) {
1774  // __ROOTCLING__ might be pulled in through PCH
1775  fInterpreter->declare("#ifdef __ROOTCLING__\n"
1776  "#undef __ROOTCLING__\n"
1777  + gInterpreterClassDef +
1778  "#endif");
1779  }
1780 
1781  if (dyLibName) {
1782  void* dyLibHandle = fRegisterModuleDyLibs.back();
1783  fRegisterModuleDyLibs.pop_back();
1784  dlclose(dyLibHandle);
1785  }
1786 
1787  SetClassAutoloading(oldAutoloadValue);
1788 }
1789 
1790 ////////////////////////////////////////////////////////////////////////////////
1791 /// Register classes that already existed prior to their dictionary loading
1792 /// and that already had a ClassInfo (and thus would not be refresh via
1793 /// UpdateClassInfo.
1794 
1796 {
1797  fClassesToUpdate.push_back(std::make_pair(oldcl,dict));
1798 }
1799 
1800 ////////////////////////////////////////////////////////////////////////////////
1801 /// If the dictionary is loaded, we can remove the class from the list
1802 /// (otherwise the class might be loaded twice).
1803 
1804 void TCling::UnRegisterTClassUpdate(const TClass *oldcl)
1805 {
1806  typedef std::vector<std::pair<TClass*,DictFuncPtr_t> >::iterator iterator;
1807  iterator stop = fClassesToUpdate.end();
1808  for(iterator i = fClassesToUpdate.begin();
1809  i != stop;
1810  ++i)
1811  {
1812  if ( i->first == oldcl ) {
1813  fClassesToUpdate.erase(i);
1814  return;
1815  }
1816  }
1817 }
1818 
1819 ////////////////////////////////////////////////////////////////////////////////
1820 /// Let cling process a command line.
1821 ///
1822 /// If the command is executed and the error is 0, then the return value
1823 /// is the int value corresponding to the result of the executed command
1824 /// (float and double return values will be truncated).
1825 ///
1826 
1827 // Method for handling the interpreter exceptions.
1828 // the MetaProcessor is passing in as argument to teh function, because
1829 // cling::Interpreter::CompilationResult is a nested class and it cannot be
1830 // forward declared, thus this method cannot be a static member function
1831 // of TCling.
1832 
1833 static int HandleInterpreterException(cling::MetaProcessor* metaProcessor,
1834  const char* input_line,
1835  cling::Interpreter::CompilationResult& compRes,
1836  cling::Value* result)
1837 {
1838  try {
1839  return metaProcessor->process(input_line, compRes, result);
1840  }
1841  catch (cling::InvalidDerefException& ex)
1842  {
1843  Error("HandleInterpreterException", "%s.\n%s", ex.what(), "Execution of your code was aborted.");
1844  ex.diagnose();
1845  }
1846  return 0;
1847 }
1848 
1849 ////////////////////////////////////////////////////////////////////////////////
1851 bool TCling::DiagnoseIfInterpreterException(const std::exception &e) const
1852 {
1853  if (auto ie = dynamic_cast<const cling::InterpreterException*>(&e)) {
1854  ie->diagnose();
1855  return true;
1856  }
1857  return false;
1858 }
1859 
1860 ////////////////////////////////////////////////////////////////////////////////
1861 
1862 Long_t TCling::ProcessLine(const char* line, EErrorCode* error/*=0*/)
1863 {
1864  // Copy the passed line, it comes from a static buffer in TApplication
1865  // which can be reentered through the Cling evaluation routines,
1866  // which would overwrite the static buffer and we would forget what we
1867  // were doing.
1868  //
1869  TString sLine(line);
1870  if (strstr(line,fantomline)) {
1871  // End-Of-Line action
1872  // See the comment (copied from above):
1873  // It is a "fantom" method to synchronize user keyboard input
1874  // and ROOT prompt line (for WIN32)
1875  // and is implemented by
1876  if (gApplication) {
1877  if (gApplication->IsCmdThread()) {
1880  if (!gInterpreterMutex)
1882  gGlobalMutex->UnLock();
1883  }
1885  gROOT->SetLineIsProcessing();
1886 
1888 
1889  gROOT->SetLineHasBeenProcessed();
1890  }
1891  }
1892  return 0;
1893  }
1894 
1896  gGlobalMutex->Lock();
1899  gGlobalMutex->UnLock();
1900  }
1902  gROOT->SetLineIsProcessing();
1903 
1904  struct InterpreterFlagsRAII {
1905  cling::Interpreter* fInterpreter;
1906  bool fWasDynamicLookupEnabled;
1907 
1908  InterpreterFlagsRAII(cling::Interpreter* interp):
1909  fInterpreter(interp),
1910  fWasDynamicLookupEnabled(interp->isDynamicLookupEnabled())
1911  {
1912  fInterpreter->enableDynamicLookup(true);
1913  }
1914  ~InterpreterFlagsRAII() {
1915  fInterpreter->enableDynamicLookup(fWasDynamicLookupEnabled);
1916  gROOT->SetLineHasBeenProcessed();
1917  }
1918  } interpreterFlagsRAII(fInterpreter);
1919 
1920  // A non-zero returned value means the given line was
1921  // not a complete statement.
1922  int indent = 0;
1923  // This will hold the resulting value of the evaluation the given line.
1925  cling::Interpreter::CompilationResult compRes = cling::Interpreter::kSuccess;
1926  if (!strncmp(sLine.Data(), ".L", 2) || !strncmp(sLine.Data(), ".x", 2) ||
1927  !strncmp(sLine.Data(), ".X", 2)) {
1928  // If there was a trailing "+", then CINT compiled the code above,
1929  // and we will need to strip the "+" before passing the line to cling.
1930  TString mod_line(sLine);
1931  TString aclicMode;
1932  TString arguments;
1933  TString io;
1934  TString fname = gSystem->SplitAclicMode(sLine.Data() + 3,
1935  aclicMode, arguments, io);
1936  if (aclicMode.Length()) {
1937  // Remove the leading '+'
1938  R__ASSERT(aclicMode[0]=='+' && "ACLiC mode must start with a +");
1939  aclicMode[0]='k'; // We always want to keep the .so around.
1940  if (aclicMode[1]=='+') {
1941  // We have a 2nd +
1942  aclicMode[1]='f'; // We want to force the recompilation.
1943  }
1944  if (!gSystem->CompileMacro(fname,aclicMode)) {
1945  // ACLiC failed.
1946  compRes = cling::Interpreter::kFailure;
1947  } else {
1948  if (strncmp(sLine.Data(), ".L", 2) != 0) {
1949  // if execution was requested.
1950 
1951  if (arguments.Length()==0) {
1952  arguments = "()";
1953  }
1954  // We need to remove the extension.
1955  Ssiz_t ext = fname.Last('.');
1956  if (ext != kNPOS) {
1957  fname.Remove(ext);
1958  }
1959  const char *function = gSystem->BaseName(fname);
1960  mod_line = function + arguments + io;
1961  cling::MetaProcessor::MaybeRedirectOutputRAII RAII(fMetaProcessor);
1962  indent = HandleInterpreterException(fMetaProcessor, mod_line, compRes, &result);
1963  }
1964  }
1965  } else {
1966  // not ACLiC
1967  size_t unnamedMacroOpenCurly;
1968  {
1969  std::string code;
1970  std::string codeline;
1971  std::ifstream in(fname);
1972  while (in) {
1973  std::getline(in, codeline);
1974  code += codeline + "\n";
1975  }
1976  unnamedMacroOpenCurly
1977  = cling::utils::isUnnamedMacro(code, fInterpreter->getCI()->getLangOpts());
1978  }
1979 
1980  fCurExecutingMacros.push_back(fname);
1981  cling::MetaProcessor::MaybeRedirectOutputRAII RAII(fMetaProcessor);
1982  if (unnamedMacroOpenCurly != std::string::npos) {
1983  compRes = fMetaProcessor->readInputFromFile(fname.Data(), &result,
1984  unnamedMacroOpenCurly);
1985  } else {
1986  // No DynLookup for .x, .L of named macros.
1987  fInterpreter->enableDynamicLookup(false);
1988  indent = HandleInterpreterException(fMetaProcessor, mod_line, compRes, &result);
1989  }
1990  fCurExecutingMacros.pop_back();
1991  }
1992  } // .L / .X / .x
1993  else {
1994  if (0!=strncmp(sLine.Data(), ".autodict ",10) && sLine != ".autodict") {
1995  // explicitly ignore .autodict without having to support it
1996  // in cling.
1997  cling::MetaProcessor::MaybeRedirectOutputRAII RAII(fMetaProcessor);
1998 
1999  // Turn off autoparsing if this is an include directive
2000  bool isInclusionDirective = sLine.Contains("\n#include") || sLine.BeginsWith("#include");
2001  if (isInclusionDirective) {
2002  SuspendAutoParsing autoParseRaii(this);
2003  indent = HandleInterpreterException(fMetaProcessor, sLine, compRes, &result);
2004  } else {
2005  indent = HandleInterpreterException(fMetaProcessor, sLine, compRes, &result);
2006  }
2007  }
2008  }
2009  if (result.isValid())
2010  RegisterTemporary(result);
2011  if (indent) {
2012  if (error)
2013  *error = kProcessing;
2014  return 0;
2015  }
2016  if (error) {
2017  switch (compRes) {
2018  case cling::Interpreter::kSuccess: *error = kNoError; break;
2019  case cling::Interpreter::kFailure: *error = kRecoverable; break;
2020  case cling::Interpreter::kMoreInputExpected: *error = kProcessing; break;
2021  }
2022  }
2023  if (compRes == cling::Interpreter::kSuccess
2024  && result.isValid()
2025  && !result.isVoid())
2026  {
2027  gROOT->SetLineHasBeenProcessed();
2028  return result.simplisticCastAs<long>();
2029  }
2030  gROOT->SetLineHasBeenProcessed();
2031  return 0;
2032 }
2033 
2034 ////////////////////////////////////////////////////////////////////////////////
2035 /// No-op; see TRint instead.
2036 
2037 void TCling::PrintIntro()
2038 {
2039 }
2040 
2041 ////////////////////////////////////////////////////////////////////////////////
2042 /// Add the given path to the list of directories in which the interpreter
2043 /// looks for include files. Only one path item can be specified at a
2044 /// time, i.e. "path1:path2" is NOT supported.
2045 
2046 void TCling::AddIncludePath(const char *path)
2047 {
2049  // Favorite source of annoyance: gSystem->AddIncludePath() needs "-I",
2050  // gCling->AddIncludePath() does not! Work around that inconsistency:
2051  if (path[0] == '-' && path[1] == 'I')
2052  path += 2;
2053 
2054  fInterpreter->AddIncludePath(path);
2055 }
2056 
2057 ////////////////////////////////////////////////////////////////////////////////
2058 /// Visit all members over members, recursing over base classes.
2059 
2060 void TCling::InspectMembers(TMemberInspector& insp, const void* obj,
2061  const TClass* cl, Bool_t isTransient)
2062 {
2066  }
2067 
2068  if (!cl || cl->GetCollectionProxy()) {
2069  // We do not need to investigate the content of the STL
2070  // collection, they are opaque to us (and details are
2071  // uninteresting).
2072  return;
2073  }
2074 
2075  static const TClassRef clRefString("std::string");
2076  if (clRefString == cl) {
2077  // We stream std::string without going through members..
2078  return;
2079  }
2080 
2081  const char* cobj = (const char*) obj; // for ptr arithmetics
2082 
2083  // Treat the case of std::complex in a special manner. We want to enforce
2084  // the layout of a stl implementation independent class, which is the
2085  // complex as implemented in ROOT5.
2086 
2087  // A simple lambda to simplify the code
2088  auto inspInspect = [&] (ptrdiff_t offset){
2089  insp.Inspect(const_cast<TClass*>(cl), insp.GetParent(), "_real", cobj, isTransient);
2090  insp.Inspect(const_cast<TClass*>(cl), insp.GetParent(), "_imag", cobj + offset, isTransient);
2091  };
2093  auto complexType = TClassEdit::GetComplexType(cl->GetName());
2094  switch(complexType) {
2096  {
2097  break;
2098  }
2100  {
2101  inspInspect(sizeof(float));
2102  return;
2103  }
2105  {
2106  inspInspect(sizeof(double));
2107  return;
2108  }
2110  {
2111  inspInspect(sizeof(int));
2112  return;
2113  }
2115  {
2116  inspInspect(sizeof(long));
2117  return;
2118  }
2119  }
2120 
2121  static clang::PrintingPolicy
2122  printPol(fInterpreter->getCI()->getLangOpts());
2123  if (printPol.Indentation) {
2124  // not yet initialized
2125  printPol.Indentation = 0;
2126  printPol.SuppressInitializers = true;
2127  }
2128 
2129  const char* clname = cl->GetName();
2130  // Printf("Inspecting class %s\n", clname);
2131 
2132  const clang::ASTContext& astContext = fInterpreter->getCI()->getASTContext();
2133  const clang::Decl *scopeDecl = 0;
2134  const clang::Type *recordType = 0;
2135 
2136  if (cl->GetClassInfo()) {
2137  TClingClassInfo * clingCI = (TClingClassInfo *)cl->GetClassInfo();
2138  scopeDecl = clingCI->GetDecl();
2139  recordType = clingCI->GetType();
2140  } else {
2141  const cling::LookupHelper& lh = fInterpreter->getLookupHelper();
2142  // Diags will complain about private classes:
2143  scopeDecl = lh.findScope(clname, cling::LookupHelper::NoDiagnostics,
2144  &recordType);
2145  }
2146  if (!scopeDecl) {
2147  Error("InspectMembers", "Cannot find Decl for class %s", clname);
2148  return;
2149  }
2150  const clang::CXXRecordDecl* recordDecl
2151  = llvm::dyn_cast<const clang::CXXRecordDecl>(scopeDecl);
2152  if (!recordDecl) {
2153  Error("InspectMembers", "Cannot find Decl for class %s is not a CXXRecordDecl.", clname);
2154  return;
2155  }
2156 
2157  {
2158  // Force possible deserializations first. We need to have no pending
2159  // Transaction when passing control flow to the inspector below (ROOT-7779).
2160  cling::Interpreter::PushTransactionRAII deserRAII(fInterpreter);
2161 
2162  astContext.getASTRecordLayout(recordDecl);
2163 
2164  for (clang::RecordDecl::field_iterator iField = recordDecl->field_begin(),
2165  eField = recordDecl->field_end(); iField != eField; ++iField) {}
2166  }
2167 
2168  const clang::ASTRecordLayout& recLayout
2169  = astContext.getASTRecordLayout(recordDecl);
2170 
2171  // TVirtualCollectionProxy *proxy = cl->GetCollectionProxy();
2172  // if (proxy && ( proxy->GetProperties() & TVirtualCollectionProxy::kIsEmulated ) ) {
2173  // Error("InspectMembers","The TClass for %s has an emulated proxy but we are looking at a compiled version of the collection!\n",
2174  // cl->GetName());
2175  // }
2176  if (cl->Size() != recLayout.getSize().getQuantity()) {
2177  Error("InspectMembers","TClass and cling disagree on the size of the class %s, respectively %d %lld\n",
2178  cl->GetName(),cl->Size(),(Long64_t)recLayout.getSize().getQuantity());
2179  }
2180 
2181  unsigned iNField = 0;
2182  // iterate over fields
2183  // FieldDecls are non-static, else it would be a VarDecl.
2184  for (clang::RecordDecl::field_iterator iField = recordDecl->field_begin(),
2185  eField = recordDecl->field_end(); iField != eField;
2186  ++iField, ++iNField) {
2187 
2188 
2189  clang::QualType memberQT = iField->getType();
2190  if (recordType) {
2191  // if (we_need_to_do_the_subst_because_the_class_is_a_template_instance_of_double32_t)
2192  memberQT = ROOT::TMetaUtils::ReSubstTemplateArg(memberQT, recordType);
2193  }
2194  memberQT = cling::utils::Transform::GetPartiallyDesugaredType(astContext, memberQT, fNormalizedCtxt->GetConfig(), false /* fully qualify */);
2195  if (memberQT.isNull()) {
2196  std::string memberName;
2197  llvm::raw_string_ostream stream(memberName);
2198  // Don't trigger fopen of the source file to count lines:
2199  printPol.AnonymousTagLocations = false;
2200  iField->getNameForDiagnostic(stream, printPol, true /*fqi*/);
2201  stream.flush();
2202  Error("InspectMembers",
2203  "Cannot retrieve QualType for member %s while inspecting class %s",
2204  memberName.c_str(), clname);
2205  continue; // skip member
2206  }
2207  const clang::Type* memType = memberQT.getTypePtr();
2208  if (!memType) {
2209  std::string memberName;
2210  llvm::raw_string_ostream stream(memberName);
2211  // Don't trigger fopen of the source file to count lines:
2212  printPol.AnonymousTagLocations = false;
2213  iField->getNameForDiagnostic(stream, printPol, true /*fqi*/);
2214  stream.flush();
2215  Error("InspectMembers",
2216  "Cannot retrieve Type for member %s while inspecting class %s",
2217  memberName.c_str(), clname);
2218  continue; // skip member
2219  }
2220 
2221  const clang::Type* memNonPtrType = memType;
2222  Bool_t ispointer = false;
2223  if (memNonPtrType->isPointerType()) {
2224  ispointer = true;
2225  clang::QualType ptrQT
2226  = memNonPtrType->getAs<clang::PointerType>()->getPointeeType();
2227  if (recordType) {
2228  // if (we_need_to_do_the_subst_because_the_class_is_a_template_instance_of_double32_t)
2229  ptrQT = ROOT::TMetaUtils::ReSubstTemplateArg(ptrQT, recordType);
2230  }
2231  ptrQT = cling::utils::Transform::GetPartiallyDesugaredType(astContext, ptrQT, fNormalizedCtxt->GetConfig(), false /* fully qualify */);
2232  if (ptrQT.isNull()) {
2233  std::string memberName;
2234  llvm::raw_string_ostream stream(memberName);
2235  // Don't trigger fopen of the source file to count lines:
2236  printPol.AnonymousTagLocations = false;
2237  iField->getNameForDiagnostic(stream, printPol, true /*fqi*/);
2238  stream.flush();
2239  Error("InspectMembers",
2240  "Cannot retrieve pointee Type for member %s while inspecting class %s",
2241  memberName.c_str(), clname);
2242  continue; // skip member
2243  }
2244  memNonPtrType = ptrQT.getTypePtr();
2245  }
2246 
2247  // assemble array size(s): "[12][4][]"
2248  llvm::SmallString<8> arraySize;
2249  const clang::ArrayType* arrType = memNonPtrType->getAsArrayTypeUnsafe();
2250  unsigned arrLevel = 0;
2251  bool haveErrorDueToArray = false;
2252  while (arrType) {
2253  ++arrLevel;
2254  arraySize += '[';
2255  const clang::ConstantArrayType* constArrType =
2256  clang::dyn_cast<clang::ConstantArrayType>(arrType);
2257  if (constArrType) {
2258  constArrType->getSize().toStringUnsigned(arraySize);
2259  }
2260  arraySize += ']';
2261  clang::QualType subArrQT = arrType->getElementType();
2262  if (subArrQT.isNull()) {
2263  std::string memberName;
2264  llvm::raw_string_ostream stream(memberName);
2265  // Don't trigger fopen of the source file to count lines:
2266  printPol.AnonymousTagLocations = false;
2267  iField->getNameForDiagnostic(stream, printPol, true /*fqi*/);
2268  stream.flush();
2269  Error("InspectMembers",
2270  "Cannot retrieve QualType for array level %d (i.e. element type of %s) for member %s while inspecting class %s",
2271  arrLevel, subArrQT.getAsString(printPol).c_str(),
2272  memberName.c_str(), clname);
2273  haveErrorDueToArray = true;
2274  break;
2275  }
2276  arrType = subArrQT.getTypePtr()->getAsArrayTypeUnsafe();
2277  }
2278  if (haveErrorDueToArray) {
2279  continue; // skip member
2280  }
2281 
2282  // construct member name
2283  std::string fieldName;
2284  if (memType->isPointerType()) {
2285  fieldName = "*";
2286  }
2287 
2288  // Check if this field has a custom ioname, if not, just use the one of the decl
2289  std::string ioname(iField->getName());
2291  fieldName += ioname;
2292  fieldName += arraySize;
2293 
2294  // get member offset
2295  // NOTE currently we do not support bitfield and do not support
2296  // member that are not aligned on 'bit' boundaries.
2297  clang::CharUnits offset(astContext.toCharUnitsFromBits(recLayout.getFieldOffset(iNField)));
2298  ptrdiff_t fieldOffset = offset.getQuantity();
2299 
2300  // R__insp.Inspect(R__cl, R__insp.GetParent(), "fBits[2]", fBits);
2301  // R__insp.Inspect(R__cl, R__insp.GetParent(), "fName", &fName);
2302  // R__insp.InspectMember(fName, "fName.");
2303  // R__insp.Inspect(R__cl, R__insp.GetParent(), "*fClass", &fClass);
2304 
2305  // If the class has a custom streamer and the type of the filed is a
2306  // private enum, struct or class, skip it.
2307  if (!insp.IsTreatingNonAccessibleTypes()){
2308  auto iFiledQtype = iField->getType();
2309  if (auto tagDecl = iFiledQtype->getAsTagDecl()){
2310  auto declAccess = tagDecl->getAccess();
2311  if (declAccess == AS_private || declAccess == AS_protected) {
2312  continue;
2313  }
2314  }
2315  }
2316 
2317  insp.Inspect(const_cast<TClass*>(cl), insp.GetParent(), fieldName.c_str(), cobj + fieldOffset, isTransient);
2318 
2319  if (!ispointer) {
2320  const clang::CXXRecordDecl* fieldRecDecl = memNonPtrType->getAsCXXRecordDecl();
2321  if (fieldRecDecl) {
2322  // nested objects get an extra call to InspectMember
2323  // R__insp.InspectMember("FileStat_t", (void*)&fFileStat, "fFileStat.", false);
2324  std::string sFieldRecName;
2325  if (!ROOT::TMetaUtils::ExtractAttrPropertyFromName(*fieldRecDecl,"iotype",sFieldRecName)){
2327  clang::QualType(memNonPtrType,0),
2328  *fInterpreter,
2329  *fNormalizedCtxt);
2330  }
2331 
2332  TDataMember* mbr = cl->GetDataMember(ioname.c_str());
2333  // if we can not find the member (which should not really happen),
2334  // let's consider it transient.
2335  Bool_t transient = isTransient || !mbr || !mbr->IsPersistent();
2336 
2337  insp.InspectMember(sFieldRecName.c_str(), cobj + fieldOffset,
2338  (fieldName + '.').c_str(), transient);
2339 
2340  }
2341  }
2342  } // loop over fields
2343 
2344  // inspect bases
2345  // TNamed::ShowMembers(R__insp);
2346  unsigned iNBase = 0;
2347  for (clang::CXXRecordDecl::base_class_const_iterator iBase
2348  = recordDecl->bases_begin(), eBase = recordDecl->bases_end();
2349  iBase != eBase; ++iBase, ++iNBase) {
2350  clang::QualType baseQT = iBase->getType();
2351  if (baseQT.isNull()) {
2352  Error("InspectMembers",
2353  "Cannot find QualType for base number %d while inspecting class %s",
2354  iNBase, clname);
2355  continue;
2356  }
2357  const clang::CXXRecordDecl* baseDecl
2358  = baseQT->getAsCXXRecordDecl();
2359  if (!baseDecl) {
2360  Error("InspectMembers",
2361  "Cannot find CXXRecordDecl for base number %d while inspecting class %s",
2362  iNBase, clname);
2363  continue;
2364  }
2365  TClass* baseCl=nullptr;
2366  std::string sBaseName;
2367  // Try with the DeclId
2368  std::vector<TClass*> foundClasses;
2369  TClass::GetClass(static_cast<DeclId_t>(baseDecl), foundClasses);
2370  if (foundClasses.size()==1){
2371  baseCl=foundClasses[0];
2372  } else {
2373  // Try with the normalised Name, as a fallback
2374  if (!baseCl){
2376  baseQT,
2377  *fInterpreter,
2378  *fNormalizedCtxt);
2379  baseCl = TClass::GetClass(sBaseName.c_str());
2380  }
2381  }
2382 
2383  if (!baseCl){
2384  std::string qualNameForDiag;
2385  ROOT::TMetaUtils::GetQualifiedName(qualNameForDiag, *baseDecl);
2386  Error("InspectMembers",
2387  "Cannot find TClass for base class %s", qualNameForDiag.c_str() );
2388  continue;
2389  }
2390 
2391  int64_t baseOffset;
2392  if (iBase->isVirtual()) {
2394  if (!isTransient) {
2395  Error("InspectMembers",
2396  "Base %s of class %s is virtual but no object provided",
2397  sBaseName.c_str(), clname);
2398  }
2400  } else {
2401  // We have an object to determine the vbase offset.
2403  TClingClassInfo* baseCi = (TClingClassInfo*)baseCl->GetClassInfo();
2404  if (ci && baseCi) {
2405  baseOffset = ci->GetBaseOffset(baseCi, const_cast<void*>(obj),
2406  true /*isDerivedObj*/);
2407  if (baseOffset == -1) {
2408  Error("InspectMembers",
2409  "Error calculating offset of virtual base %s of class %s",
2410  sBaseName.c_str(), clname);
2411  }
2412  } else {
2413  Error("InspectMembers",
2414  "Cannot calculate offset of virtual base %s of class %s",
2415  sBaseName.c_str(), clname);
2416  continue;
2417  }
2418  }
2419  } else {
2420  baseOffset = recLayout.getBaseClassOffset(baseDecl).getQuantity();
2421  }
2422  // TOFIX: baseCl can be null here!
2423  if (baseCl->IsLoaded()) {
2424  // For loaded class, CallShowMember will (especially for TObject)
2425  // call the virtual ShowMember rather than the class specific version
2426  // resulting in an infinite recursion.
2427  InspectMembers(insp, cobj + baseOffset, baseCl, isTransient);
2428  } else {
2429  baseCl->CallShowMembers(cobj + baseOffset,
2430  insp, isTransient);
2431  }
2432  } // loop over bases
2433 }
2434 
2435 ////////////////////////////////////////////////////////////////////////////////
2436 /// Reset the interpreter internal state in case a previous action was not correctly
2437 /// terminated.
2438 
2439 void TCling::ClearFileBusy()
2440 {
2441  // No-op there is not equivalent state (to be cleared) in Cling.
2442 }
2443 
2444 ////////////////////////////////////////////////////////////////////////////////
2445 /// Delete existing temporary values.
2446 
2447 void TCling::ClearStack()
2448 {
2449  // No-op for cling due to cling::Value.
2450 }
2451 
2452 ////////////////////////////////////////////////////////////////////////////////
2453 /// Declare code to the interpreter, without any of the interpreter actions
2454 /// that could trigger a re-interpretation of the code. I.e. make cling
2455 /// behave like a compiler: no dynamic lookup, no input wrapping for
2456 /// subsequent execution, no automatic provision of declarations but just a
2457 /// plain #include.
2458 /// Returns true on success, false on failure.
2459 
2460 bool TCling::Declare(const char* code)
2461 {
2463 
2464  int oldload = SetClassAutoloading(0);
2465  SuspendAutoParsing autoParseRaii(this);
2466 
2467  bool oldDynLookup = fInterpreter->isDynamicLookupEnabled();
2468  fInterpreter->enableDynamicLookup(false);
2469  bool oldRawInput = fInterpreter->isRawInputEnabled();
2470  fInterpreter->enableRawInput(true);
2471 
2472  Bool_t ret = LoadText(code);
2473 
2474  fInterpreter->enableRawInput(oldRawInput);
2475  fInterpreter->enableDynamicLookup(oldDynLookup);
2476  SetClassAutoloading(oldload);
2477  return ret;
2478 }
2479 
2480 ////////////////////////////////////////////////////////////////////////////////
2481 /// Enable the automatic loading of shared libraries when a class
2482 /// is used that is stored in a not yet loaded library. Uses the
2483 /// information stored in the class/library map (typically
2484 /// $ROOTSYS/etc/system.rootmap).
2487 {
2488  if (fAllowLibLoad) {
2489  LoadLibraryMap();
2490  SetClassAutoloading(true);
2491  }
2492 }
2494 ////////////////////////////////////////////////////////////////////////////////
2495 /// It calls a "fantom" method to synchronize user keyboard input
2496 /// and ROOT prompt line.
2497 
2499 {
2500  ProcessLineSynch(fantomline);
2501 }
2502 
2503 ////////////////////////////////////////////////////////////////////////////////
2504 /// Return true if the file has already been loaded by cint.
2505 /// We will try in this order:
2506 /// actual filename
2507 /// filename as a path relative to
2508 /// the include path
2509 /// the shared library path
2510 
2511 Bool_t TCling::IsLoaded(const char* filename) const
2512 {
2514 
2515  //FIXME: if we use llvm::sys::fs::make_absolute all this can go away. See
2516  // cling::DynamicLibraryManager.
2517 
2518  std::string file_name = filename;
2519  size_t at = std::string::npos;
2520  while ((at = file_name.find("/./")) != std::string::npos)
2521  file_name.replace(at, 3, "/");
2522 
2523  std::string filesStr = "";
2524  llvm::raw_string_ostream filesOS(filesStr);
2525  clang::SourceManager &SM = fInterpreter->getCI()->getSourceManager();
2526  cling::ClangInternalState::printIncludedFiles(filesOS, SM);
2527  filesOS.flush();
2528 
2529  llvm::SmallVector<llvm::StringRef, 100> files;
2530  llvm::StringRef(filesStr).split(files, "\n");
2531 
2532  std::set<std::string> fileMap;
2533  // Fill fileMap; return early on exact match.
2534  for (llvm::SmallVector<llvm::StringRef, 100>::const_iterator
2535  iF = files.begin(), iE = files.end(); iF != iE; ++iF) {
2536  if ((*iF) == file_name.c_str()) return kTRUE; // exact match
2537  fileMap.insert(*iF);
2538  }
2539 
2540  if (fileMap.empty()) return kFALSE;
2541 
2542  // Check MacroPath.
2543  TString sFilename(file_name.c_str());
2545  && fileMap.count(sFilename.Data())) {
2546  return kTRUE;
2547  }
2548 
2549  // Check IncludePath.
2550  TString incPath = gSystem->GetIncludePath(); // of the form -Idir1 -Idir2 -Idir3
2551  incPath.Append(":").Prepend(" "); // to match " -I" (note leading ' ')
2552  incPath.ReplaceAll(" -I", ":"); // of form :dir1 :dir2:dir3
2553  while (incPath.Index(" :") != -1) {
2554  incPath.ReplaceAll(" :", ":");
2555  }
2556  incPath.Prepend(".:");
2557  sFilename = file_name.c_str();
2558  if (gSystem->FindFile(incPath, sFilename, kReadPermission)
2559  && fileMap.count(sFilename.Data())) {
2560  return kTRUE;
2561  }
2562 
2563  // Check shared library.
2564  sFilename = file_name.c_str();
2565  const char *found = gSystem->FindDynamicLibrary(sFilename, kTRUE);
2566  cling::DynamicLibraryManager* dyLibManager
2567  = fInterpreter->getDynamicLibraryManager();
2568  if (found) {
2569  if (dyLibManager->isLibraryLoaded(found)) {
2570  return kTRUE;
2571  }
2572  }
2573  //FIXME: We must use the cling::Interpreter::lookupFileOrLibrary iface.
2574  const clang::DirectoryLookup *CurDir = 0;
2575  clang::Preprocessor &PP = fInterpreter->getCI()->getPreprocessor();
2576  clang::HeaderSearch &HS = PP.getHeaderSearchInfo();
2577  const clang::FileEntry *FE = HS.LookupFile(file_name.c_str(),
2578  clang::SourceLocation(),
2579  /*isAngled*/ false,
2580  /*FromDir*/ 0, CurDir,
2581  clang::ArrayRef<std::pair<const clang::FileEntry *,
2582  const clang::DirectoryEntry *>>(),
2583  /*SearchPath*/ 0,
2584  /*RelativePath*/ 0,
2585  /*RequestingModule*/ 0,
2586  /*SuggestedModule*/ 0,
2587  /*SkipCache*/ false,
2588  /*BuildSystemModule*/ false,
2589  /*OpenFile*/ false,
2590  /*CacheFail*/ false);
2591  if (FE && FE->isValid()) {
2592  // check in the source manager if the file is actually loaded
2593  clang::SourceManager &SM = fInterpreter->getCI()->getSourceManager();
2594  // this works only with header (and source) files...
2595  clang::FileID FID = SM.translateFile(FE);
2596  if (!FID.isInvalid() && FID.getHashValue() == 0)
2597  return kFALSE;
2598  else {
2599  clang::SrcMgr::SLocEntry SLocE = SM.getSLocEntry(FID);
2600  if (SLocE.isFile() && SLocE.getFile().getContentCache()->getRawBuffer() == 0)
2601  return kFALSE;
2602  if (!FID.isInvalid())
2603  return kTRUE;
2604  }
2605  // ...then check shared library again, but with full path now
2606  sFilename = FE->getName();
2607  if (gSystem->FindDynamicLibrary(sFilename, kTRUE)
2608  && fileMap.count(sFilename.Data())) {
2609  return kTRUE;
2610  }
2611  }
2612  return kFALSE;
2613 }
2614 
2615 ////////////////////////////////////////////////////////////////////////////////
2616 
2618 {
2619 #if defined(R__WIN32) || defined(__CYGWIN__)
2620  HMODULE hModules[1024];
2621  void *hProcess;
2622  unsigned long cbModules;
2623  unsigned int i;
2624  hProcess = (void *)::GetCurrentProcess();
2625  ::EnumProcessModules(hProcess, hModules, sizeof(hModules), &cbModules);
2626  // start at 1 to skip the executable itself
2627  for (i = 1; i < (cbModules / sizeof(void *)); i++) {
2628  static const int bufsize = 260;
2629  wchar_t winname[bufsize];
2630  char posixname[bufsize];
2631  ::GetModuleFileNameExW(hProcess, hModules[i], winname, bufsize);
2632 #if defined(__CYGWIN__)
2633  cygwin_conv_path(CCP_WIN_W_TO_POSIX, winname, posixname, bufsize);
2634 #else
2635  std::wstring wpath = winname;
2636  std::replace(wpath.begin(), wpath.end(), '\\', '/');
2637  string path(wpath.begin(), wpath.end());
2638  strncpy(posixname, path.c_str(), bufsize);
2639 #endif
2640  if (!fSharedLibs.Contains(posixname)) {
2641  RegisterLoadedSharedLibrary(posixname);
2642  }
2643  }
2644 #elif defined(R__MACOSX)
2645  // fPrevLoadedDynLibInfo stores the *next* image index to look at
2646  uint32_t imageIndex = (uint32_t) (size_t) fPrevLoadedDynLibInfo;
2647  const char* imageName = 0;
2648  while ((imageName = _dyld_get_image_name(imageIndex))) {
2649  // Skip binary
2650  if (imageIndex > 0)
2651  RegisterLoadedSharedLibrary(imageName);
2652  ++imageIndex;
2653  }
2654  fPrevLoadedDynLibInfo = (void*)(size_t)imageIndex;
2655 #elif defined(R__LINUX)
2656  struct PointerNo4 {
2657  void* fSkip[3];
2658  void* fPtr;
2659  };
2660  struct LinkMap {
2661  void* fAddr;
2662  const char* fName;
2663  void* fLd;
2664  LinkMap* fNext;
2665  LinkMap* fPrev;
2666  };
2667  if (!fPrevLoadedDynLibInfo || fPrevLoadedDynLibInfo == (void*)(size_t)-1) {
2668  PointerNo4* procLinkMap = (PointerNo4*)dlopen(0, RTLD_LAZY | RTLD_GLOBAL);
2669  // 4th pointer of 4th pointer is the linkmap.
2670  // See http://syprog.blogspot.fr/2011/12/listing-loaded-shared-objects-in-linux.html
2671  LinkMap* linkMap = (LinkMap*) ((PointerNo4*)procLinkMap->fPtr)->fPtr;
2672  RegisterLoadedSharedLibrary(linkMap->fName);
2673  fPrevLoadedDynLibInfo = linkMap;
2674  // reduce use count of link map structure:
2675  dlclose(procLinkMap);
2676  }
2677 
2678  LinkMap* iDyLib = (LinkMap*)fPrevLoadedDynLibInfo;
2679  while (iDyLib->fNext) {
2680  iDyLib = iDyLib->fNext;
2681  RegisterLoadedSharedLibrary(iDyLib->fName);
2682  }
2683  fPrevLoadedDynLibInfo = iDyLib;
2684 #else
2685  Error("TCling::UpdateListOfLoadedSharedLibraries",
2686  "Platform not supported!");
2687 #endif
2688 }
2689 
2690 ////////////////////////////////////////////////////////////////////////////////
2691 /// Register a new shared library name with the interpreter; add it to
2692 /// fSharedLibs.
2693 
2694 void TCling::RegisterLoadedSharedLibrary(const char* filename)
2695 {
2696  // Ignore NULL filenames, aka "the process".
2697  if (!filename) return;
2698 
2699  // Tell the interpreter that this library is available; all libraries can be
2700  // used to resolve symbols.
2701  cling::DynamicLibraryManager* DLM = fInterpreter->getDynamicLibraryManager();
2702  if (!DLM->isLibraryLoaded(filename)) {
2703  DLM->loadLibrary(filename, true /*permanent*/);
2704  }
2705 
2706 #if defined(R__MACOSX)
2707  // Check that this is not a system library
2708  if (!strncmp(filename, "/usr/lib/system/", 16)
2709  || !strncmp(filename, "/usr/lib/libc++", 15)
2710  || !strncmp(filename, "/System/Library/Frameworks/", 27)
2711  || !strncmp(filename, "/System/Library/PrivateFrameworks/", 34)
2712  || !strncmp(filename, "/System/Library/CoreServices/", 29)
2713  || !strcmp(filename, "cl_kernels") // yepp, no directory
2714  || strstr(filename, "/usr/lib/libSystem")
2715  || strstr(filename, "/usr/lib/libstdc++")
2716  || strstr(filename, "/usr/lib/libicucore")
2717  || strstr(filename, "/usr/lib/libbsm")
2718  || strstr(filename, "/usr/lib/libobjc")
2719  || strstr(filename, "/usr/lib/libresolv")
2720  || strstr(filename, "/usr/lib/libauto")
2721  || strstr(filename, "/usr/lib/libcups")
2722  || strstr(filename, "/usr/lib/libDiagnosticMessagesClient")
2723  || strstr(filename, "/usr/lib/liblangid")
2724  || strstr(filename, "/usr/lib/libCRFSuite")
2725  || strstr(filename, "/usr/lib/libpam")
2726  || strstr(filename, "/usr/lib/libOpenScriptingUtil")
2727  || strstr(filename, "/usr/lib/libextension"))
2728  return;
2729 #elif defined(__CYGWIN__)
2730  // Check that this is not a system library
2731  static const int bufsize = 260;
2732  char posixwindir[bufsize];
2733  char *windir = getenv("WINDIR");
2734  if (windir)
2735  cygwin_conv_path(CCP_WIN_A_TO_POSIX, windir, posixwindir, bufsize);
2736  else
2737  snprintf(posixwindir, sizeof(posixwindir), "/Windows/");
2738  if (strstr(filename, posixwindir) ||
2739  strstr(filename, "/usr/bin/cyg"))
2740  return;
2741 #elif defined(R__WIN32)
2742  if (strstr(filename, "/Windows/"))
2743  return;
2744 #elif defined (R__LINUX)
2745  if (strstr(filename, "/ld-linux")
2746  || strstr(filename, "linux-gnu/")
2747  || strstr(filename, "/libstdc++.")
2748  || strstr(filename, "/libgcc")
2749  || strstr(filename, "/libc.")
2750  || strstr(filename, "/libdl.")
2751  || strstr(filename, "/libm."))
2752  return;
2753 #endif
2754  // Update string of available libraries.
2755  if (!fSharedLibs.IsNull()) {
2756  fSharedLibs.Append(" ");
2757  }
2758  fSharedLibs.Append(filename);
2759 }
2760 
2761 ////////////////////////////////////////////////////////////////////////////////
2762 /// Load a library file in cling's memory.
2763 /// if 'system' is true, the library is never unloaded.
2764 /// Return 0 on success, -1 on failure.
2765 
2766 Int_t TCling::Load(const char* filename, Bool_t system)
2767 {
2768  if (!fAllowLibLoad) {
2769  Error("Load","Trying to load library (%s) from rootcling.",filename);
2770  return -1;
2771  }
2772 
2773  // Used to return 0 on success, 1 on duplicate, -1 on failure, -2 on "fatal".
2775  cling::DynamicLibraryManager* DLM = fInterpreter->getDynamicLibraryManager();
2776  std::string canonLib = DLM->lookupLibrary(filename);
2777  cling::DynamicLibraryManager::LoadLibResult res
2778  = cling::DynamicLibraryManager::kLoadLibNotFound;
2779  if (!canonLib.empty()) {
2780  if (system)
2781  res = DLM->loadLibrary(filename, system);
2782  else {
2783  // For the non system libs, we'd like to be able to unload them.
2784  // FIXME: Here we lose the information about kLoadLibAlreadyLoaded case.
2785  cling::Interpreter::CompilationResult compRes;
2786  cling::MetaProcessor::MaybeRedirectOutputRAII RAII(fMetaProcessor);
2787  HandleInterpreterException(fMetaProcessor, Form(".L %s", canonLib.c_str()), compRes, /*cling::Value*/0);
2788  if (compRes == cling::Interpreter::kSuccess)
2789  res = cling::DynamicLibraryManager::kLoadLibSuccess;
2790  }
2791  }
2792 
2793  if (res == cling::DynamicLibraryManager::kLoadLibSuccess) {
2795  }
2796  switch (res) {
2797  case cling::DynamicLibraryManager::kLoadLibSuccess: return 0;
2798  case cling::DynamicLibraryManager::kLoadLibAlreadyLoaded: return 1;
2799  default: break;
2800  };
2801  return -1;
2802 }
2803 
2804 ////////////////////////////////////////////////////////////////////////////////
2805 /// Load a macro file in cling's memory.
2806 
2807 void TCling::LoadMacro(const char* filename, EErrorCode* error)
2808 {
2809  ProcessLine(Form(".L %s", filename), error);
2810 }
2811 
2812 ////////////////////////////////////////////////////////////////////////////////
2813 /// Let cling process a command line asynch.
2814 
2815 Long_t TCling::ProcessLineAsynch(const char* line, EErrorCode* error)
2816 {
2817  return ProcessLine(line, error);
2818 }
2819 
2820 ////////////////////////////////////////////////////////////////////////////////
2821 /// Let cling process a command line synchronously, i.e we are waiting
2822 /// it will be finished.
2823 
2824 Long_t TCling::ProcessLineSynch(const char* line, EErrorCode* error)
2825 {
2827  if (gApplication) {
2828  if (gApplication->IsCmdThread()) {
2829  return ProcessLine(line, error);
2830  }
2831  return 0;
2832  }
2833  return ProcessLine(line, error);
2834 }
2835 
2836 ////////////////////////////////////////////////////////////////////////////////
2837 /// Directly execute an executable statement (e.g. "func()", "3+5", etc.
2838 /// however not declarations, like "Int_t x;").
2839 
2840 Long_t TCling::Calc(const char* line, EErrorCode* error)
2841 {
2842 #ifdef R__WIN32
2843  // Test on ApplicationImp not being 0 is needed because only at end of
2844  // TApplication ctor the IsLineProcessing flag is set to 0, so before
2845  // we can not use it.
2847  while (gROOT->IsLineProcessing() && !gApplication) {
2848  Warning("Calc", "waiting for cling thread to free");
2849  gSystem->Sleep(500);
2850  }
2851  gROOT->SetLineIsProcessing();
2852  }
2853 #endif // R__WIN32
2855  if (error) {
2856  *error = TInterpreter::kNoError;
2857  }
2858  cling::Value valRef;
2859  cling::Interpreter::CompilationResult cr = fInterpreter->evaluate(line, valRef);
2860  if (cr != cling::Interpreter::kSuccess) {
2861  // Failure in compilation.
2862  if (error) {
2863  // Note: Yes these codes are weird.
2864  *error = TInterpreter::kRecoverable;
2865  }
2866  return 0L;
2867  }
2868  if (!valRef.isValid()) {
2869  // Failure at runtime.
2870  if (error) {
2871  // Note: Yes these codes are weird.
2872  *error = TInterpreter::kDangerous;
2873  }
2874  return 0L;
2875  }
2876 
2877  if (valRef.isVoid()) {
2878  return 0;
2879  }
2880 
2881  RegisterTemporary(valRef);
2882 #ifdef R__WIN32
2884  gROOT->SetLineHasBeenProcessed();
2885  }
2886 #endif // R__WIN32
2887  return valRef.simplisticCastAs<long>();
2888 }
2889 
2890 ////////////////////////////////////////////////////////////////////////////////
2891 /// Set a getline function to call when input is needed.
2892 
2893 void TCling::SetGetline(const char * (*getlineFunc)(const char* prompt),
2894  void (*histaddFunc)(const char* line))
2895 {
2896  // If cling offers a replacement for G__pause(), it would need to
2897  // also offer a way to customize at least the history recording.
2898 
2899 #if defined(R__MUST_REVISIT)
2900 #if R__MUST_REVISIT(6,2)
2901  Warning("SetGetline","Cling should support the equivalent of SetGetlineFunc(getlineFunc, histaddFunc)");
2902 #endif
2903 #endif
2904 }
2905 
2906 ////////////////////////////////////////////////////////////////////////////////
2907 /// Helper function to increase the internal Cling count of transactions
2908 /// that change the AST.
2909 
2910 Bool_t TCling::HandleNewTransaction(const cling::Transaction &T)
2911 {
2913 
2914  if ((std::distance(T.decls_begin(), T.decls_end()) != 1)
2915  || T.deserialized_decls_begin() != T.deserialized_decls_end()
2916  || T.macros_begin() != T.macros_end()
2917  || ((!T.getFirstDecl().isNull()) && ((*T.getFirstDecl().begin()) != T.getWrapperFD()))) {
2919  return true;
2920  }
2921  return false;
2922 }
2923 
2924 ////////////////////////////////////////////////////////////////////////////////
2925 /// Delete object from cling symbol table so it can not be used anymore.
2926 /// cling objects are always on the heap.
2927 
2929 {
2931  // Note that fgSetOfSpecials is supposed to be updated by TClingCallbacks::tryFindROOTSpecialInternal
2932  // (but isn't at the moment).
2933  if (obj->IsOnHeap() && fgSetOfSpecials && !((std::set<TObject*>*)fgSetOfSpecials)->empty()) {
2934  std::set<TObject*>::iterator iSpecial = ((std::set<TObject*>*)fgSetOfSpecials)->find(obj);
2935  if (iSpecial != ((std::set<TObject*>*)fgSetOfSpecials)->end()) {
2936  DeleteGlobal(obj);
2937  ((std::set<TObject*>*)fgSetOfSpecials)->erase(iSpecial);
2938  }
2939  }
2940 }
2941 
2942 ////////////////////////////////////////////////////////////////////////////////
2943 /// Pressing Ctrl+C should forward here. In the case where we have had
2944 /// continuation requested we must reset it.
2945 
2946 void TCling::Reset()
2947 {
2948  fMetaProcessor->cancelContinuation();
2949  // Reset the Cling state to the state saved by the last call to
2950  // TCling::SaveContext().
2951 #if defined(R__MUST_REVISIT)
2952 #if R__MUST_REVISIT(6,2)
2954  Warning("Reset","Cling should support the equivalent of scratch_upto(&fDictPos)");
2955 #endif
2956 #endif
2957 }
2958 
2959 ////////////////////////////////////////////////////////////////////////////////
2960 /// Reset the Cling state to its initial state.
2961 
2962 void TCling::ResetAll()
2963 {
2964 #if defined(R__MUST_REVISIT)
2965 #if R__MUST_REVISIT(6,2)
2967  Warning("ResetAll","Cling should support the equivalent of complete reset (unload everything but the startup decls.");
2968 #endif
2969 #endif
2970 }
2971 
2972 ////////////////////////////////////////////////////////////////////////////////
2973 /// Reset in Cling the list of global variables to the state saved by the last
2974 /// call to TCling::SaveGlobalsContext().
2975 ///
2976 /// Note: Right now, all we do is run the global destructors.
2977 
2978 void TCling::ResetGlobals()
2979 {
2981  // TODO:
2982  // Here we should iterate over the transactions (N-3) and revert.
2983  // N-3 because the first three internal to cling.
2984 
2985  fInterpreter->runAndRemoveStaticDestructors();
2986 }
2987 
2988 ////////////////////////////////////////////////////////////////////////////////
2989 /// Reset the Cling 'user' global objects/variables state to the state saved by the last
2990 /// call to TCling::SaveGlobalsContext().
2991 
2992 void TCling::ResetGlobalVar(void* obj)
2993 {
2994 #if defined(R__MUST_REVISIT)
2995 #if R__MUST_REVISIT(6,2)
2997  Warning("ResetGlobalVar","Cling should support the equivalent of resetglobalvar(obj)");
2998 #endif
2999 #endif
3000 }
3001 
3002 ////////////////////////////////////////////////////////////////////////////////
3003 /// Rewind Cling dictionary to the point where it was before executing
3004 /// the current macro. This function is typically called after SEGV or
3005 /// ctlr-C after doing a longjmp back to the prompt.
3006 
3009 #if defined(R__MUST_REVISIT)
3010 #if R__MUST_REVISIT(6,2)
3012  Warning("RewindDictionary","Cling should provide a way to revert transaction similar to rewinddictionary()");
3013 #endif
3014 #endif
3015 }
3016 
3017 ////////////////////////////////////////////////////////////////////////////////
3018 /// Delete obj from Cling symbol table so it cannot be accessed anymore.
3019 /// Returns 1 in case of success and 0 in case object was not in table.
3020 
3021 Int_t TCling::DeleteGlobal(void* obj)
3022 {
3023 #if defined(R__MUST_REVISIT)
3024 #if R__MUST_REVISIT(6,2)
3026  Warning("DeleteGlobal","Cling should provide the equivalent of deleteglobal(obj), see also DeleteVariable.");
3027 #endif
3028 #endif
3029  return 0;
3030 }
3031 
3032 ////////////////////////////////////////////////////////////////////////////////
3033 /// Undeclare obj called name.
3034 /// Returns 1 in case of success, 0 for failure.
3035 
3036 Int_t TCling::DeleteVariable(const char* name)
3037 {
3038 #if defined(R__MUST_REVISIT)
3039 #if R__MUST_REVISIT(6,2)
3040  Warning("DeleteVariable","should do more that just reseting the value to zero");
3041 #endif
3042 #endif
3043 
3045  llvm::StringRef srName(name);
3046  const char* unscopedName = name;
3047  llvm::StringRef::size_type posScope = srName.rfind("::");
3048  const clang::DeclContext* declCtx = 0;
3049  if (posScope != llvm::StringRef::npos) {
3050  const cling::LookupHelper& lh = fInterpreter->getLookupHelper();
3051  const clang::Decl* scopeDecl
3052  = lh.findScope(srName.substr(0, posScope),
3053  cling::LookupHelper::WithDiagnostics);
3054  if (!scopeDecl) {
3055  Error("DeleteVariable", "Cannot find enclosing scope for variable %s",
3056  name);
3057  return 0;
3058  }
3059  declCtx = llvm::dyn_cast<clang::DeclContext>(scopeDecl);
3060  if (!declCtx) {
3061  Error("DeleteVariable",
3062  "Enclosing scope for variable %s is not a declaration context",
3063  name);
3064  return 0;
3065  }
3066  unscopedName += posScope + 2;
3067  }
3068  clang::NamedDecl* nVarDecl
3069  = cling::utils::Lookup::Named(&fInterpreter->getSema(), unscopedName, declCtx);
3070  if (!nVarDecl) {
3071  Error("DeleteVariable", "Unknown variable %s", name);
3072  return 0;
3073  }
3074  clang::VarDecl* varDecl = llvm::dyn_cast<clang::VarDecl>(nVarDecl);
3075  if (!varDecl) {
3076  Error("DeleteVariable", "Entity %s is not a variable", name);
3077  return 0;
3078  }
3079 
3080  clang::QualType qType = varDecl->getType();
3081  const clang::Type* type = qType->getUnqualifiedDesugaredType();
3082  // Cannot set a reference's address to nullptr; the JIT can place it
3083  // into read-only memory (ROOT-7100).
3084  if (type->isPointerType()) {
3085  int** ppInt = (int**)fInterpreter->getAddressOfGlobal(GlobalDecl(varDecl));
3086  // set pointer to invalid.
3087  if (ppInt) *ppInt = 0;
3088  }
3089  return 1;
3090 }
3091 
3092 ////////////////////////////////////////////////////////////////////////////////
3093 /// Save the current Cling state.
3094 
3095 void TCling::SaveContext()
3096 {
3097 #if defined(R__MUST_REVISIT)
3098 #if R__MUST_REVISIT(6,2)
3100  Warning("SaveContext","Cling should provide a way to record a state watermark similar to store_dictposition(&fDictPos)");
3101 #endif
3102 #endif
3103 }
3104 
3105 ////////////////////////////////////////////////////////////////////////////////
3106 /// Save the current Cling state of global objects.
3107 
3109 {
3110 #if defined(R__MUST_REVISIT)
3111 #if R__MUST_REVISIT(6,2)
3113  Warning("SaveGlobalsContext","Cling should provide a way to record a watermark for the list of global variable similar to store_dictposition(&fDictPosGlobals)");
3114 #endif
3115 #endif
3116 }
3117 
3118 ////////////////////////////////////////////////////////////////////////////////
3119 /// No op: see TClingCallbacks (used to update the list of globals)
3120 
3122 {
3123 }
3124 
3125 ////////////////////////////////////////////////////////////////////////////////
3126 /// No op: see TClingCallbacks (used to update the list of global functions)
3127 
3129 {
3130 }
3131 
3132 ////////////////////////////////////////////////////////////////////////////////
3133 /// No op: see TClingCallbacks (used to update the list of types)
3134 
3136 {
3137 }
3138 
3139 ////////////////////////////////////////////////////////////////////////////////
3140 /// Check in what order the member of a tuple are layout.
3141 enum class ETupleOrdering {
3142  kAscending,
3143  kDescending,
3144  kUnexpected
3145 };
3146 
3147 struct AlternateTupleIntDoubleAsc
3148 {
3149  Int_t _0;
3150  Double_t _1;
3151 };
3152 
3153 struct AlternateTupleIntDoubleDes
3155  Double_t _1;
3156  Int_t _0;
3157 };
3158 
3160 {
3161  std::tuple<int,double> value;
3162  AlternateTupleIntDoubleAsc asc;
3163  AlternateTupleIntDoubleDes des;
3164 
3165  size_t offset0 = ((char*)&(std::get<0>(value))) - ((char*)&value);
3166  size_t offset1 = ((char*)&(std::get<1>(value))) - ((char*)&value);
3168  size_t ascOffset0 = ((char*)&(asc._0)) - ((char*)&asc);
3169  size_t ascOffset1 = ((char*)&(asc._1)) - ((char*)&asc);
3170 
3171  size_t desOffset0 = ((char*)&(des._0)) - ((char*)&des);
3172  size_t desOffset1 = ((char*)&(des._1)) - ((char*)&des);
3173 
3174  if (offset0 == ascOffset0 && offset1 == ascOffset1) {
3176  } else if (offset0 == desOffset0 && offset1 == desOffset1) {
3178  } else {
3180  }
3182 
3183 std::string AtlernateTuple(const char *classname)
3184 {
3185  TClassEdit::TSplitType tupleContent(classname);
3186  std::string alternateName = "TEmulatedTuple";
3187  alternateName.append( classname + 5 );
3188 
3189  std::string guard_name;
3190  ROOT::TMetaUtils::GetCppName(guard_name,alternateName.c_str());
3191  std::ostringstream guard;
3192  guard << "ROOT_INTERNAL_TEmulated_";
3193  guard << guard_name;
3194 
3195  std::ostringstream alternateTuple;
3196  alternateTuple << "#ifndef " << guard.str() << "\n";
3197  alternateTuple << "#define " << guard.str() << "\n";
3198  alternateTuple << "namespace ROOT { namespace Internal {\n";
3199  alternateTuple << "template <class... Types> struct TEmulatedTuple;\n";
3200  alternateTuple << "template <> struct " << alternateName << " {\n";
3201 
3202  // This could also be a compile time choice ...
3203  switch(IsTupleAscending()) {
3205  unsigned int nMember = 0;
3206  auto iter = tupleContent.fElements.begin() + 1; // Skip the template name (tuple)
3207  auto theEnd = tupleContent.fElements.end() - 1; // skip the 'stars'.
3208  while (iter != theEnd) {
3209  alternateTuple << " " << *iter << " _" << nMember << ";\n";
3210  ++iter;
3211  ++nMember;
3212  }
3213  break;
3214  }
3216  unsigned int nMember = tupleContent.fElements.size() - 3;
3217  auto iter = tupleContent.fElements.rbegin() + 1; // Skip the template name (tuple)
3218  auto theEnd = tupleContent.fElements.rend() - 1; // skip the 'stars'.
3219  while (iter != theEnd) {
3220  alternateTuple << " " << *iter << " _" << nMember << ";\n";
3221  ++iter;
3222  --nMember;
3223  }
3224  break;
3225  }
3227  Fatal("TCling::SetClassInfo::AtlernateTuple",
3228  "Layout of std::tuple on this platform is unexpected.");
3229  break;
3230  }
3231  }
3232 
3233  alternateTuple << "};\n";
3234  alternateTuple << "}}\n";
3235  alternateTuple << "#endif\n";
3236  if (!gCling->Declare(alternateTuple.str().c_str())) {
3237  Error("Load","Could not declare %s",alternateName.c_str());
3238  return "";
3239  }
3240  alternateName = "ROOT::Internal::" + alternateName;
3241  return alternateName;
3242 }
3243 
3244 ////////////////////////////////////////////////////////////////////////////////
3245 /// Set pointer to the TClingClassInfo in TClass.
3246 /// If 'reload' is true, (attempt to) generate a new ClassInfo even if we
3247 /// already have one.
3248 
3249 void TCling::SetClassInfo(TClass* cl, Bool_t reload)
3250 {
3252  if (cl->fClassInfo && !reload) {
3253  return;
3254  }
3255  //Remove the decl_id from the DeclIdToTClass map
3256  TClingClassInfo* TClinginfo = (TClingClassInfo*) cl->fClassInfo;
3257  if (TClinginfo) {
3258  TClass::RemoveClassDeclId(TClinginfo->GetDeclId());
3259  }
3260  delete TClinginfo;
3261  cl->fClassInfo = 0;
3262  std::string name(cl->GetName());
3263 
3264  // Handle the special case of 'tuple' where we ignore the real implementation
3265  // details and just overlay a 'simpler'/'simplistic' version that is easy
3266  // for the I/O to understand and handle.
3267  if (strncmp(cl->GetName(),"tuple<",strlen("tuple<"))==0) {
3268 
3269  name = AtlernateTuple(cl->GetName());
3270 
3271  }
3272 
3273  TClingClassInfo* info = new TClingClassInfo(fInterpreter, name.c_str());
3274  if (!info->IsValid()) {
3275  if (cl->fState != TClass::kHasTClassInit) {
3276  if (cl->fStreamerInfo->GetEntries() != 0) {
3277  cl->fState = TClass::kEmulated;
3278  } else {
3280  }
3281  }
3282  delete info;
3283  return;
3284  }
3285  cl->fClassInfo = (ClassInfo_t*)info; // Note: We are transferring ownership here.
3286  // In case a class contains an external enum, the enum will be seen as a
3287  // class. We must detect this special case and make the class a Zombie.
3288  // Here we assume that a class has at least one method.
3289  // We can NOT call TClass::Property from here, because this method
3290  // assumes that the TClass is well formed to do a lot of information
3291  // caching. The method SetClassInfo (i.e. here) is usually called during
3292  // the building phase of the TClass, hence it is NOT well formed yet.
3293  Bool_t zombieCandidate = kFALSE;
3294  if (
3295  info->IsValid() &&
3296  !(info->Property() & (kIsClass | kIsStruct | kIsNamespace))
3297  ) {
3298  zombieCandidate = kTRUE;
3299  }
3300  if (!info->IsLoaded()) {
3301  if (info->Property() & (kIsNamespace)) {
3302  // Namespaces can have info but no corresponding CINT dictionary
3303  // because they are auto-created if one of their contained
3304  // classes has a dictionary.
3305  zombieCandidate = kTRUE;
3306  }
3307  // this happens when no dictionary is available
3308  delete info;
3309  cl->fClassInfo = 0;
3310  }
3311  if (zombieCandidate && !cl->GetCollectionType()) {
3312  cl->MakeZombie();
3313  }
3314  // If we reach here, the info was valid (See early returns).
3315  if (cl->fState != TClass::kHasTClassInit) {
3316  if (cl->fClassInfo) {
3319  } else {
3320 // if (TClassEdit::IsSTLCont(cl->GetName()) {
3321 // There will be an emulated collection proxy, is that the same?
3322 // cl->fState = TClass::kEmulated;
3323 // } else {
3324  if (cl->fStreamerInfo->GetEntries() != 0) {
3325  cl->fState = TClass::kEmulated;
3326  } else {
3328  }
3329 // }
3330  }
3331  }
3332  if (cl->fClassInfo) {
3333  TClass::AddClassToDeclIdMap(((TClingClassInfo*)cl->fClassInfo)->GetDeclId(), cl);
3334  }
3335 }
3336 
3337 ////////////////////////////////////////////////////////////////////////////////
3338 /// Checks if an entity with the specified name is defined in Cling.
3339 /// Returns kFALSE if the entity is not defined.
3340 /// By default, structs, namespaces, classes, enums and unions are looked for.
3341 /// If the flag isClassOrNamespaceOnly is true, classes, structs and
3342 /// namespaces only are considered. I.e. if the name is an enum or a union,
3343 /// the returned value is false.
3344 ///
3345 /// In the case where the class is not loaded and belongs to a namespace
3346 /// or is nested, looking for the full class name is outputting a lots of
3347 /// (expected) error messages. Currently the only way to avoid this is to
3348 /// specifically check that each level of nesting is already loaded.
3349 /// In case of templates the idea is that everything between the outer
3350 /// '<' and '>' has to be skipped, e.g.: aap<pippo<noot>::klaas>::a_class
3351 
3352 Bool_t TCling::CheckClassInfo(const char* name, Bool_t autoload, Bool_t isClassOrNamespaceOnly /* = kFALSE*/ )
3353 {
3355  static const char *anonEnum = "anonymous enum ";
3356  static const int cmplen = strlen(anonEnum);
3357 
3358  if (0 == strncmp(name,anonEnum,cmplen)) {
3359  return kFALSE;
3360  }
3361 
3362  // Avoid the double search below in case the name is a fundamental type
3363  // or typedef to a fundamental type.
3364  THashTable *typeTable = dynamic_cast<THashTable*>( gROOT->GetListOfTypes() );
3365  TDataType *fundType = (TDataType *)typeTable->THashTable::FindObject( name );
3366 
3367  if (fundType && fundType->GetType() < TVirtualStreamerInfo::kObject
3368  && fundType->GetType() > 0) {
3369  // Fundamental type, no a class.
3370  return kFALSE;
3371  }
3372 
3373  // Migrated from within TClass::GetClass
3374  // If we want to know if a class or a namespace with this name exists in the
3375  // interpreter and this is an enum in the type system, before or after loading
3376  // according to the autoload function argument, return false.
3377  if (isClassOrNamespaceOnly &&
3378  TEnum::GetEnum(name, autoload ? TEnum::kAutoload : TEnum::kNone)) return false;
3379 
3380  const char *classname = name;
3381 
3382  int storeAutoload = SetClassAutoloading(autoload);
3383 
3384  // First we want to check whether the decl exist, but _without_
3385  // generating any template instantiation. However, the lookup
3386  // still will create a forward declaration of the class template instance
3387  // if it exist. In this case, the return value of findScope will still
3388  // be zero but the type will be initialized.
3389  // Note in the corresponding code in ROOT 5, CINT was not instantiating
3390  // this forward declaration.
3391  const cling::LookupHelper& lh = fInterpreter->getLookupHelper();
3392  const clang::Type *type = 0;
3393  const clang::Decl *decl
3394  = lh.findScope(classname,
3395  gDebug > 5 ? cling::LookupHelper::WithDiagnostics
3396  : cling::LookupHelper::NoDiagnostics,
3397  &type, /* intantiateTemplate= */ false );
3398  if (!decl) {
3399  std::string buf = TClassEdit::InsertStd(classname);
3400  decl = lh.findScope(buf,
3401  gDebug > 5 ? cling::LookupHelper::WithDiagnostics
3402  : cling::LookupHelper::NoDiagnostics,
3403  &type,false);
3404  }
3405 
3406  if (type) {
3407  // If decl==0 and the type is valid, then we have a forward declaration.
3408  if (!decl) {
3409  // If we have a forward declaration for a class template instantiation,
3410  // we want to ignore it if it was produced/induced by the call to
3411  // findScope, however we can not distinguish those from the
3412  // instantiation induce by 'soft' use (and thus also induce by the
3413  // same underlying code paths)
3414  // ['soft' use = use not requiring a complete definition]
3415  // So to reduce the amount of disruption to the existing code we
3416  // would just ignore those for STL collection, for which we really
3417  // need to have the compiled collection proxy (and thus the TClass
3418  // bootstrap).
3419  clang::ClassTemplateSpecializationDecl *tmpltDecl =
3420  llvm::dyn_cast_or_null<clang::ClassTemplateSpecializationDecl>
3421  (type->getAsCXXRecordDecl());
3422  if (tmpltDecl && !tmpltDecl->getPointOfInstantiation().isValid()) {
3423  // Since the point of instantiation is invalid, we 'guess' that
3424  // the 'instantiation' of the forwarded type appended in
3425  // findscope.
3426  if (ROOT::TMetaUtils::IsSTLCont(*tmpltDecl)) {
3427  // For STL Collection we return false.
3428  SetClassAutoloading(storeAutoload);
3429  return kFALSE;
3430  }
3431  }
3432  }
3433  TClingClassInfo tci(fInterpreter, *type);
3434  if (!tci.IsValid()) {
3435  SetClassAutoloading(storeAutoload);
3436  return kFALSE;
3437  }
3438  auto propertiesMask = isClassOrNamespaceOnly ? kIsClass | kIsStruct | kIsNamespace :
3440 
3441  if (tci.Property() & propertiesMask) {
3442  // We are now sure that the entry is not in fact an autoload entry.
3443  SetClassAutoloading(storeAutoload);
3444  return kTRUE;
3445  }
3446  }
3447 
3448  SetClassAutoloading(storeAutoload);
3449  return (decl);
3450 
3451  // Setting up iterator part of TClingTypedefInfo is too slow.
3452  // Copy the lookup code instead:
3453  /*
3454  TClingTypedefInfo t(fInterpreter, name);
3455  if (t.IsValid() && !(t.Property() & kIsFundamental)) {
3456  delete[] classname;
3457  SetClassAutoloading(storeAutoload);
3458  return kTRUE;
3459  }
3460  */
3461 
3462 // const clang::Decl *decl = lh.findScope(name);
3463 // if (!decl) {
3464 // std::string buf = TClassEdit::InsertStd(name);
3465 // decl = lh.findScope(buf);
3466 // }
3467 
3468 // SetClassAutoloading(storeAutoload);
3469 // return (decl);
3470 }
3471 
3472 ////////////////////////////////////////////////////////////////////////////////
3473 /// Return true if there is a class template by the given name ...
3474 
3475 Bool_t TCling::CheckClassTemplate(const char *name)
3476 {
3477  const cling::LookupHelper& lh = fInterpreter->getLookupHelper();
3478  const clang::Decl *decl
3479  = lh.findClassTemplate(name,
3480  gDebug > 5 ? cling::LookupHelper::WithDiagnostics
3481  : cling::LookupHelper::NoDiagnostics);
3482  if (!decl) {
3483  std::string strname = "std::";
3484  strname += name;
3485  decl = lh.findClassTemplate(strname,
3486  gDebug > 5 ? cling::LookupHelper::WithDiagnostics
3487  : cling::LookupHelper::NoDiagnostics);
3488  }
3489  return 0 != decl;
3490 }
3491 
3492 ////////////////////////////////////////////////////////////////////////////////
3493 /// Create list of pointers to base class(es) for TClass cl.
3494 
3496 {
3498  if (cl->fBase) {
3499  return;
3500  }
3502  if (!tci) return;
3504  TList *listOfBase = new TList;
3505  while (t.Next()) {
3506  // if name cannot be obtained no use to put in list
3507  if (t.IsValid() && t.Name()) {
3509  listOfBase->Add(new TBaseClass((BaseClassInfo_t *)a, cl));
3510  }
3511  }
3512  // Now that is complete, publish it.
3513  cl->fBase = listOfBase;
3514 }
3515 
3516 ////////////////////////////////////////////////////////////////////////////////
3517 /// Create list of pointers to enums for TClass cl.
3518 
3519 void TCling::LoadEnums(TListOfEnums& enumList) const
3520 {
3522 
3523  const Decl * D;
3524  TClass* cl = enumList.GetClass();
3525  if (cl) {
3526  D = ((TClingClassInfo*)cl->GetClassInfo())->GetDecl();
3527  }
3528  else {
3529  D = fInterpreter->getCI()->getASTContext().getTranslationUnitDecl();
3530  }
3531  // Iterate on the decl of the class and get the enums.
3532  if (const clang::DeclContext* DC = dyn_cast<clang::DeclContext>(D)) {
3533  cling::Interpreter::PushTransactionRAII deserRAII(fInterpreter);
3534  // Collect all contexts of the namespace.
3535  llvm::SmallVector< DeclContext *, 4> allDeclContexts;
3536  const_cast< clang::DeclContext *>(DC)->collectAllContexts(allDeclContexts);
3537  for (llvm::SmallVector<DeclContext*, 4>::iterator declIter = allDeclContexts.begin(), declEnd = allDeclContexts.end();
3538  declIter != declEnd; ++declIter) {
3539  // Iterate on all decls for each context.
3540  for (clang::DeclContext::decl_iterator DI = (*declIter)->decls_begin(),
3541  DE = (*declIter)->decls_end(); DI != DE; ++DI) {
3542  if (const clang::EnumDecl* ED = dyn_cast<clang::EnumDecl>(*DI)) {
3543  // Get name of the enum type.
3544  std::string buf;
3545  PrintingPolicy Policy(ED->getASTContext().getPrintingPolicy());
3546  llvm::raw_string_ostream stream(buf);
3547  // Don't trigger fopen of the source file to count lines:
3548  Policy.AnonymousTagLocations = false;
3549  ED->getNameForDiagnostic(stream, Policy, /*Qualified=*/false);
3550  stream.flush();
3551  // If the enum is unnamed we do not add it to the list of enums i.e unusable.
3552  if (!buf.empty()) {
3553  const char* name = buf.c_str();
3554  // Add the enum to the list of loaded enums.
3555  enumList.Get(ED, name);
3556  }
3557  }
3558  }
3559  }
3560  }
3561 }
3562 
3563 ////////////////////////////////////////////////////////////////////////////////
3564 /// Create list of pointers to function templates for TClass cl.
3566 void TCling::LoadFunctionTemplates(TClass* cl) const
3567 {
3569 
3570  const Decl * D;
3571  TListOfFunctionTemplates* funcTempList;
3572  if (cl) {
3573  D = ((TClingClassInfo*)cl->GetClassInfo())->GetDecl();
3574  funcTempList = (TListOfFunctionTemplates*)cl->GetListOfFunctionTemplates(false);
3575  }
3576  else {
3577  D = fInterpreter->getCI()->getASTContext().getTranslationUnitDecl();
3578  funcTempList = (TListOfFunctionTemplates*)gROOT->GetListOfFunctionTemplates();
3579  }
3580  // Iterate on the decl of the class and get the enums.
3581  if (const clang::DeclContext* DC = dyn_cast<clang::DeclContext>(D)) {
3582  cling::Interpreter::PushTransactionRAII deserRAII(fInterpreter);
3583  // Collect all contexts of the namespace.
3584  llvm::SmallVector< DeclContext *, 4> allDeclContexts;
3585  const_cast< clang::DeclContext *>(DC)->collectAllContexts(allDeclContexts);
3586  for (llvm::SmallVector<DeclContext*, 4>::iterator declIter = allDeclContexts.begin(),
3587  declEnd = allDeclContexts.end(); declIter != declEnd; ++declIter) {
3588  // Iterate on all decls for each context.
3589  for (clang::DeclContext::decl_iterator DI = (*declIter)->decls_begin(),
3590  DE = (*declIter)->decls_end(); DI != DE; ++DI) {
3591  if (const clang::FunctionTemplateDecl* FTD = dyn_cast<clang::FunctionTemplateDecl>(*DI)) {
3592  funcTempList->Get(FTD);
3593  }
3594  }
3595  }
3596  }
3597 }
3598 ////////////////////////////////////////////////////////////////////////////////
3599 /// Create list of pointers to data members for TClass cl.
3600 /// This is now a nop. The creation and updating is handled in
3601 /// TListOfDataMembers.
3602 
3604 {
3605 }
3606 
3607 ////////////////////////////////////////////////////////////////////////////////
3608 /// Create list of pointers to methods for TClass cl.
3609 /// This is now a nop. The creation and updating is handled in
3610 /// TListOfFunctions.
3611 
3613 {
3614 }
3615 
3616 ////////////////////////////////////////////////////////////////////////////////
3617 /// Update the list of pointers to method for TClass cl
3618 /// This is now a nop. The creation and updating is handled in
3619 /// TListOfFunctions.
3620 
3621 void TCling::UpdateListOfMethods(TClass* cl) const
3622 {
3623 }
3624 
3625 ////////////////////////////////////////////////////////////////////////////////
3626 /// Update the list of pointers to data members for TClass cl
3627 /// This is now a nop. The creation and updating is handled in
3628 /// TListOfDataMembers.
3629 
3631 {
3632 }
3633 
3634 ////////////////////////////////////////////////////////////////////////////////
3635 /// Create list of pointers to method arguments for TMethod m.
3636 
3638 {
3640  if (m->fMethodArgs) {
3641  return;
3642  }
3643  TList *arglist = new TList;
3645  while (t.Next()) {
3646  if (t.IsValid()) {
3648  arglist->Add(new TMethodArg((MethodArgInfo_t*)a, m));
3649  }
3650  }
3651  m->fMethodArgs = arglist;
3652 }
3653 
3654 
3655 ////////////////////////////////////////////////////////////////////////////////
3656 /// Generate a TClass for the given class.
3657 /// Since the caller has already check the ClassInfo, let it give use the
3658 /// result (via the value of emulation) rather than recalculate it.
3659 
3660 TClass *TCling::GenerateTClass(const char *classname, Bool_t emulation, Bool_t silent /* = kFALSE */)
3661 {
3662 // For now the following line would lead to the (unwanted) instantiation
3663 // of class template. This could/would need to be resurrected only if
3664 // we re-introduce so sort of automatic instantiation. However this would
3665 // have to include carefull look at the template parameter to avoid
3666 // creating instance we can not really use (if the parameter are only forward
3667 // declaration or do not have all the necessary interfaces).
3668 
3669  // TClingClassInfo tci(fInterpreter, classname);
3670  // if (1 || !tci.IsValid()) {
3671 
3672  Version_t version = 1;
3673  if (TClassEdit::IsSTLCont(classname)) {
3674  version = TClass::GetClass("TVirtualStreamerInfo")->GetClassVersion();
3675  }
3676  TClass *cl = new TClass(classname, version, silent);
3677  if (emulation) {
3679  } else {
3680  // Set the class version if the class is versioned.
3681  // Note that we cannot just call CLASS::Class_Version() as we might not have
3682  // an execution engine (when invoked from rootcling).
3684  // Do not call cl->GetClassVersion(), it has side effects!
3685  Version_t oldvers = cl->fClassVersion;
3686  if (oldvers == version && cl->GetClassInfo()) {
3687  // We have a version and it might need an update.
3688  Version_t newvers = oldvers;
3690  if (llvm::isa<clang::NamespaceDecl>(cli->GetDecl())) {
3691  // Namespaces don't have class versions.
3692  return cl;
3693  }
3694  TClingMethodInfo mi = cli->GetMethod("Class_Version", "", 0 /*poffset*/,
3697  if (!mi.IsValid()) {
3698  if (cl->TestBit(TClass::kIsTObject)) {
3699  Error("GenerateTClass",
3700  "Cannot find %s::Class_Version()! Class version might be wrong.",
3701  cl->GetName());
3702  }
3703  return cl;
3704  }
3705  newvers = ROOT::TMetaUtils::GetClassVersion(llvm::dyn_cast<clang::RecordDecl>(cli->GetDecl()),
3707  if (newvers == -1) {
3708  // Didn't manage to determine the class version from the AST.
3709  // Use runtime instead.
3710  if ((mi.Property() & kIsStatic)
3711  && !fInterpreter->isInSyntaxOnlyMode()) {
3712  // This better be a static function.
3714  callfunc.SetFunc(&mi);
3715  newvers = callfunc.ExecInt(0);
3716  } else {
3717  Error("GenerateTClass",
3718  "Cannot invoke %s::Class_Version()! Class version might be wrong.",
3719  cl->GetName());
3720  }
3721  }
3722  if (newvers != oldvers) {
3723  cl->fClassVersion = newvers;
3724  cl->fStreamerInfo->Expand(newvers + 2 + 10);
3725  }
3726  }
3727  }
3728 
3729  return cl;
3730 
3731 // } else {
3732 // return GenerateTClass(&tci,silent);
3733 // }
3734 }
3735 
3736 #if 0
3737 ////////////////////////////////////////////////////////////////////////////////
3738 
3739 static void GenerateTClass_GatherInnerIncludes(cling::Interpreter *interp, TString &includes,TClingClassInfo *info)
3740 {
3741  includes += info->FileName();
3742 
3743  const clang::ClassTemplateSpecializationDecl *templateCl
3744  = llvm::dyn_cast<clang::ClassTemplateSpecializationDecl>(info->GetDecl());
3745  if (templateCl) {
3746  for(unsigned int i=0; i < templateCl->getTemplateArgs().size(); ++i) {
3747  const clang::TemplateArgument &arg( templateCl->getTemplateArgs().get(i) );
3748  if (arg.getKind() == clang::TemplateArgument::Type) {
3749  const clang::Type *uType = ROOT::TMetaUtils::GetUnderlyingType( arg.getAsType() );
3750 
3751  if (!uType->isFundamentalType() && !uType->isEnumeralType()) {
3752  // We really need a header file.
3753  const clang::CXXRecordDecl *argdecl = uType->getAsCXXRecordDecl();
3754  if (argdecl) {
3755  includes += ";";
3756  TClingClassInfo subinfo(interp,*(argdecl->getASTContext().getRecordType(argdecl).getTypePtr()));
3757  GenerateTClass_GatherInnerIncludes(interp, includes, &subinfo);
3758  } else {
3759  std::string Result;
3760  llvm::raw_string_ostream OS(Result);
3761  arg.print(argdecl->getASTContext().getPrintingPolicy(),OS);
3762  Warning("TCling::GenerateTClass","Missing header file for %s",OS.str().c_str());
3763  }
3764  }
3765  }
3766  }
3767  }
3768 }
3769 #endif
3770 
3771 ////////////////////////////////////////////////////////////////////////////////
3772 /// Generate a TClass for the given class.
3773 
3774 TClass *TCling::GenerateTClass(ClassInfo_t *classinfo, Bool_t silent /* = kFALSE */)
3775 {
3776  TClingClassInfo *info = (TClingClassInfo*)classinfo;
3777  if (!info || !info->IsValid()) {
3778  Fatal("GenerateTClass","Requires a valid ClassInfo object");
3779  return 0;
3780  }
3781  // We are in the case where we have AST nodes for this class.
3782  TClass *cl = 0;
3783  std::string classname;
3784  info->FullName(classname,*fNormalizedCtxt); // Could we use Name()?
3785  if (TClassEdit::IsSTLCont(classname.c_str())) {
3786 #if 0
3787  Info("GenerateTClass","Will (try to) generate the compiled TClass for %s.",classname.c_str());
3788  // We need to build up the list of required headers, by
3789  // looking at each template arguments.
3790  TString includes;
3791  GenerateTClass_GatherInnerIncludes(fInterpreter,includes,info);
3792 
3793  if (0 == GenerateDictionary(classname.c_str(),includes)) {
3794  // 0 means success.
3795  cl = TClass::LoadClass(classnam.c_str(), silent);
3796  if (cl == 0) {
3797  Error("GenerateTClass","Even though the dictionary generation for %s seemed successful we can't find the TClass bootstrap!",classname.c_str());
3798  }
3799  }
3800 #endif
3801  if (cl == 0) {
3802  int version = TClass::GetClass("TVirtualStreamerInfo")->GetClassVersion();
3803  cl = new TClass(classinfo, version, 0, 0, -1, -1, silent);
3805  }
3806  } else {
3807  // For regular class, just create a TClass on the fly ...
3808  // Not quite useful yet, but that what CINT used to do anyway.
3809  cl = new TClass(classinfo, 1, 0, 0, -1, -1, silent);
3810  }
3811  // Add the new TClass to the map of declid and TClass*.
3812  if (cl) {
3814  }
3815  return cl;
3816 }
3817 
3818 ////////////////////////////////////////////////////////////////////////////////
3819 /// Generate the dictionary for the C++ classes listed in the first
3820 /// argument (in a semi-colon separated list).
3821 /// 'includes' contains a semi-colon separated list of file to
3822 /// #include in the dictionary.
3823 /// For example:
3824 /// ~~~ {.cpp}
3825 /// gInterpreter->GenerateDictionary("vector<vector<float> >;list<vector<float> >","list;vector");
3826 /// ~~~
3827 /// or
3828 /// ~~~ {.cpp}
3829 /// gInterpreter->GenerateDictionary("myclass","myclass.h;myhelper.h");
3830 /// ~~~
3831 
3832 Int_t TCling::GenerateDictionary(const char* classes, const char* includes /* = 0 */, const char* /* options = 0 */)
3833 {
3834  if (classes == 0 || classes[0] == 0) {
3835  return 0;
3836  }
3837  // Split the input list
3838  std::vector<std::string> listClasses;
3839  for (
3840  const char* current = classes, *prev = classes;
3841  *current != 0;
3842  ++current
3843  ) {
3844  if (*current == ';') {
3845  listClasses.push_back(std::string(prev, current - prev));
3846  prev = current + 1;
3847  }
3848  else if (*(current + 1) == 0) {
3849  listClasses.push_back(std::string(prev, current + 1 - prev));
3850  prev = current + 1;
3851  }
3852  }
3853  std::vector<std::string> listIncludes;
3854  for (
3855  const char* current = includes, *prev = includes;
3856  *current != 0;
3857  ++current
3858  ) {
3859  if (*current == ';') {
3860  listIncludes.push_back(std::string(prev, current - prev));
3861  prev = current + 1;
3862  }
3863  else if (*(current + 1) == 0) {
3864  listIncludes.push_back(std::string(prev, current + 1 - prev));
3865  prev = current + 1;
3866  }
3867  }
3868  // Generate the temporary dictionary file
3869  return TCling_GenerateDictionary(listClasses, listIncludes,
3870  std::vector<std::string>(), std::vector<std::string>());
3871 }
3872 
3873 ////////////////////////////////////////////////////////////////////////////////
3874 /// Return pointer to cling Decl of global/static variable that is located
3875 /// at the address given by addr.
3876 
3877 TInterpreter::DeclId_t TCling::GetDataMember(ClassInfo_t *opaque_cl, const char *name) const
3880  DeclId_t d;
3881  TClingClassInfo *cl = (TClingClassInfo*)opaque_cl;
3882 
3883  if (cl) {
3884  d = cl->GetDataMember(name);
3885  // We check if the decl of the data member has an annotation which indicates
3886  // an ioname.
3887  // In case this is true, if the name requested is not the ioname, we
3888  // return 0, as if the member did not exist. In some sense we override
3889  // the information in the TClassInfo instance, isolating the typesystem in
3890  // TClass from the one in the AST.
3891  if (const ValueDecl* decl = (const ValueDecl*) d){
3892  std::string ioName;
3893  bool hasIoName = ROOT::TMetaUtils::ExtractAttrPropertyFromName(*decl,"ioname",ioName);
3894  if (hasIoName && ioName != name) return 0;
3895  }
3896  }
3897  else {
3899  d = gcl.GetDataMember(name);
3900  }
3901  return d;
3902 }
3903 
3904 ////////////////////////////////////////////////////////////////////////////////
3905 /// Return pointer to cling Decl of global/static variable that is located
3906 /// at the address given by addr.
3907 
3908 TInterpreter::DeclId_t TCling::GetEnum(TClass *cl, const char *name) const
3909 {
3911 
3912  const clang::Decl* possibleEnum = 0;
3913  // FInd the context of the decl.
3914  if (cl) {
3916  if (cci) {
3917  const clang::DeclContext* dc = 0;
3918  if (const clang::Decl* D = cci->GetDecl()) {
3919  if (!(dc = dyn_cast<clang::NamespaceDecl>(D))) {
3920  dc = dyn_cast<clang::RecordDecl>(D);
3921  }
3922  }
3923  if (dc) {
3924  // If it is a data member enum.
3925  possibleEnum = cling::utils::Lookup::Named(&fInterpreter->getSema(), name, dc);
3926  } else {
3927  Error("TCling::GetEnum", "DeclContext not found for %s .\n", name);
3928  }
3929  }
3930  } else {
3931  // If it is a global enum.
3932  possibleEnum = cling::utils::Lookup::Named(&fInterpreter->getSema(), name);
3933  }
3934  if (possibleEnum && (possibleEnum != (clang::Decl*)-1)
3935  && isa<clang::EnumDecl>(possibleEnum)) {
3936  return possibleEnum;
3937  }
3938  return 0;
3939 }
3940 
3941 ////////////////////////////////////////////////////////////////////////////////
3942 /// Return pointer to cling DeclId for a global value
3943 
3944 TInterpreter::DeclId_t TCling::GetDeclId( const llvm::GlobalValue *gv ) const
3945 {
3946  if (!gv) return 0;
3947 
3948  llvm::StringRef mangled_name = gv->getName();
3949 
3950  int err = 0;
3951  char* demangled_name_c = TClassEdit::DemangleName(mangled_name.str().c_str(), err);
3952  if (err) {
3953  if (err == -2) {
3954  // It might simply be an unmangled global name.
3955  DeclId_t d;
3957  d = gcl.GetDataMember(mangled_name.str().c_str());
3958  return d;
3959  }
3960  return 0;
3961  }
3962 
3963  std::string scopename(demangled_name_c);
3964  free(demangled_name_c);
3965 
3966  //
3967  // Separate out the class or namespace part of the
3968  // function name.
3969  //
3970  std::string dataname;
3971 
3972  if (!strncmp(scopename.c_str(), "typeinfo for ", sizeof("typeinfo for ")-1)) {
3973  scopename.erase(0, sizeof("typeinfo for ")-1);
3974  } else if (!strncmp(scopename.c_str(), "vtable for ", sizeof("vtable for ")-1)) {
3975  scopename.erase(0, sizeof("vtable for ")-1);
3976  } else {
3977  // See if it is a function
3978  std::string::size_type pos = scopename.rfind('(');
3979  if (pos != std::string::npos) {
3980  return 0;
3981  }
3982  // Separate the scope and member name
3983  pos = scopename.rfind(':');
3984  if (pos != std::string::npos) {
3985  if ((pos != 0) && (scopename[pos-1] == ':')) {
3986  dataname = scopename.substr(pos+1);
3987  scopename.erase(pos-1);
3988  }
3989  } else {
3990  scopename.clear();
3991  dataname = scopename;
3992  }
3993  }
3994  //fprintf(stderr, "name: '%s'\n", name.c_str());
3995  // Now we have the class or namespace name, so do the lookup.
3996 
3997 
3998  DeclId_t d;
3999  if (scopename.size()) {
4000  TClingClassInfo cl(fInterpreter,scopename.c_str());
4001  d = cl.GetDataMember(dataname.c_str());
4002  }
4003  else {
4005  d = gcl.GetDataMember(dataname.c_str());
4006  }
4007  return d;
4008 }
4009 
4010 ////////////////////////////////////////////////////////////////////////////////
4011 /// NOT IMPLEMENTED.
4012 
4013 TInterpreter::DeclId_t TCling::GetDataMemberWithValue(const void *ptrvalue) const
4014 {
4015  Error("GetDataMemberWithValue()", "not implemented");
4016  return 0;
4017 }
4018 
4019 ////////////////////////////////////////////////////////////////////////////////
4020 /// Return pointer to cling DeclId for a data member with a given name.
4021 
4023 {
4024  // NOT IMPLEMENTED.
4025  Error("GetDataMemberAtAddr()", "not implemented");
4026  return 0;
4027 }
4028 
4029 ////////////////////////////////////////////////////////////////////////////////
4030 /// Return the cling mangled name for a method of a class with parameters
4031 /// params (params is a string of actual arguments, not formal ones). If the
4032 /// class is 0 the global function list will be searched.
4033 
4034 TString TCling::GetMangledName(TClass* cl, const char* method,
4035  const char* params, Bool_t objectIsConst /* = kFALSE */)
4036 {
4039  if (cl) {
4040  Long_t offset;
4041  func.SetFunc((TClingClassInfo*)cl->GetClassInfo(), method, params, objectIsConst,
4042  &offset);
4043  }
4044  else {
4046  Long_t offset;
4047  func.SetFunc(&gcl, method, params, &offset);
4048  }
4049  TClingMethodInfo* mi = (TClingMethodInfo*) func.FactoryMethod();
4050  if (!mi) return "";
4051  TString mangled_name( mi->GetMangledName() );
4052  delete mi;
4053  return mangled_name;
4054 }
4055 
4056 ////////////////////////////////////////////////////////////////////////////////
4057 /// Return the cling mangled name for a method of a class with a certain
4058 /// prototype, i.e. "char*,int,float". If the class is 0 the global function
4059 /// list will be searched.
4060 
4061 TString TCling::GetMangledNameWithPrototype(TClass* cl, const char* method,
4062  const char* proto, Bool_t objectIsConst /* = kFALSE */,
4063  EFunctionMatchMode mode /* = kConversionMatch */)
4064 {
4066  if (cl) {
4067  return ((TClingClassInfo*)cl->GetClassInfo())->
4068  GetMethod(method, proto, objectIsConst, 0 /*poffset*/, mode).GetMangledName();
4069  }
4071  return gcl.GetMethod(method, proto, objectIsConst, 0 /*poffset*/, mode).GetMangledName();
4072 }
4073 
4074 ////////////////////////////////////////////////////////////////////////////////
4075 /// Return pointer to cling interface function for a method of a class with
4076 /// parameters params (params is a string of actual arguments, not formal
4077 /// ones). If the class is 0 the global function list will be searched.
4078 
4079 void* TCling::GetInterfaceMethod(TClass* cl, const char* method,
4080  const char* params, Bool_t objectIsConst /* = kFALSE */)
4081 {
4084  if (cl) {
4085  Long_t offset;
4086  func.SetFunc((TClingClassInfo*)cl->GetClassInfo(), method, params, objectIsConst,
4087  &offset);
4088  }
4089  else {
4091  Long_t offset;
4092  func.SetFunc(&gcl, method, params, &offset);
4093  }
4094  return (void*) func.InterfaceMethod();
4095 }
4096 
4097 ////////////////////////////////////////////////////////////////////////////////
4098 /// Return pointer to cling interface function for a method of a class with
4099 /// a certain name.
4100 
4101 TInterpreter::DeclId_t TCling::GetFunction(ClassInfo_t *opaque_cl, const char* method)
4102 {
4104  DeclId_t f;
4105  TClingClassInfo *cl = (TClingClassInfo*)opaque_cl;
4106  if (cl) {
4107  f = cl->GetMethod(method).GetDeclId();
4108  }
4109  else {
4111  f = gcl.GetMethod(method).GetDeclId();
4112  }
4113  return f;
4114 
4115 }
4116 
4117 ////////////////////////////////////////////////////////////////////////////////
4118 /// Insert overloads of name in cl to res.
4119 
4120 void TCling::GetFunctionOverloads(ClassInfo_t *cl, const char *funcname,
4121  std::vector<DeclId_t>& res) const
4122 {
4123  clang::Sema& S = fInterpreter->getSema();
4124  const clang::Decl* CtxDecl
4125  = cl ? (const clang::Decl*)((TClingClassInfo*)cl)->GetDeclId():
4126  S.Context.getTranslationUnitDecl();
4127  const clang::DeclContext*
4128  DeclCtx = llvm::dyn_cast<const clang::RecordDecl>(CtxDecl);
4129  if (!DeclCtx)
4130  DeclCtx = dyn_cast<clang::NamespaceDecl>(CtxDecl);
4131  if (!DeclCtx) return;
4132  clang::DeclarationName DName
4133  = &S.Context.Idents.get(funcname);
4134  clang::LookupResult R(S, DName, clang::SourceLocation(),
4135  Sema::LookupOrdinaryName, clang::Sema::ForRedeclaration);
4136  S.LookupQualifiedName(R, const_cast<DeclContext*>(DeclCtx));
4137  if (R.empty()) return;
4138  R.resolveKind();
4139  res.reserve(res.size() + (R.end() - R.begin()));
4140  for (clang::LookupResult::iterator IR = R.begin(), ER = R.end();
4141  IR != ER; ++IR) {
4142  if (const clang::FunctionDecl* FD
4143  = llvm::dyn_cast<const clang::FunctionDecl>(*IR)) {
4144  if (!FD->getDescribedFunctionTemplate()) {
4145  res.push_back(FD);
4146  }
4147  }
4148  }
4149 }
4150 
4151 ////////////////////////////////////////////////////////////////////////////////
4152 /// Return pointer to cling interface function for a method of a class with
4153 /// a certain prototype, i.e. "char*,int,float". If the class is 0 the global
4154 /// function list will be searched.
4155 
4156 void* TCling::GetInterfaceMethodWithPrototype(TClass* cl, const char* method,
4157  const char* proto,
4158  Bool_t objectIsConst /* = kFALSE */,
4159  EFunctionMatchMode mode /* = kConversionMatch */)
4160 {
4162  void* f;
4163  if (cl) {
4164  f = ((TClingClassInfo*)cl->GetClassInfo())->
4165  GetMethod(method, proto, objectIsConst, 0 /*poffset*/, mode).InterfaceMethod(*fNormalizedCtxt);
4166  }
4167  else {
4169  f = gcl.GetMethod(method, proto, objectIsConst, 0 /*poffset*/, mode).InterfaceMethod(*fNormalizedCtxt);
4170  }
4171  return f;
4172 }
4173 
4174 ////////////////////////////////////////////////////////////////////////////////
4175 /// Return pointer to cling DeclId for a method of a class with
4176 /// a certain prototype, i.e. "char*,int,float". If the class is 0 the global
4177 /// function list will be searched.
4178 
4179 TInterpreter::DeclId_t TCling::GetFunctionWithValues(ClassInfo_t *opaque_cl, const char* method,
4180  const char* params,
4181  Bool_t objectIsConst /* = kFALSE */)
4182 {
4184  DeclId_t f;
4185  TClingClassInfo *cl = (TClingClassInfo*)opaque_cl;
4186  if (cl) {
4187  f = cl->GetMethodWithArgs(method, params, objectIsConst, 0 /*poffset*/).GetDeclId();
4188  }
4189  else {
4191  f = gcl.GetMethod(method, params, objectIsConst, 0 /*poffset*/).GetDeclId();
4192  }
4193  return f;
4194 }
4195 
4196 ////////////////////////////////////////////////////////////////////////////////
4197 /// Return pointer to cling interface function for a method of a class with
4198 /// a certain prototype, i.e. "char*,int,float". If the class is 0 the global
4199 /// function list will be searched.
4200 
4201 TInterpreter::DeclId_t TCling::GetFunctionWithPrototype(ClassInfo_t *opaque_cl, const char* method,
4202  const char* proto,
4203  Bool_t objectIsConst /* = kFALSE */,
4204  EFunctionMatchMode mode /* = kConversionMatch */)
4205 {
4207  DeclId_t f;
4208  TClingClassInfo *cl = (TClingClassInfo*)opaque_cl;
4209  if (cl) {
4210  f = cl->GetMethod(method, proto, objectIsConst, 0 /*poffset*/, mode).GetDeclId();
4211  }
4212  else {
4214  f = gcl.GetMethod(method, proto, objectIsConst, 0 /*poffset*/, mode).GetDeclId();
4215  }
4216  return f;
4217 }
4218 
4219 ////////////////////////////////////////////////////////////////////////////////
4220 /// Return pointer to cling interface function for a method of a class with
4221 /// a certain name.
4222 
4223 TInterpreter::DeclId_t TCling::GetFunctionTemplate(ClassInfo_t *opaque_cl, const char* name)
4224 {
4226  DeclId_t f;
4227  TClingClassInfo *cl = (TClingClassInfo*)opaque_cl;
4228  if (cl) {
4229  f = cl->GetFunctionTemplate(name);
4230  }
4231  else {
4233  f = gcl.GetFunctionTemplate(name);
4234  }
4235  return f;
4236 
4237 }
4238 
4239 ////////////////////////////////////////////////////////////////////////////////
4240 /// The 'name' is known to the interpreter, this function returns
4241 /// the internal version of this name (usually just resolving typedefs)
4242 /// This is used in particular to synchronize between the name used
4243 /// by rootcling and by the run-time environment (TClass)
4244 /// Return 0 if the name is not known.
4245 
4246 void TCling::GetInterpreterTypeName(const char* name, std::string &output, Bool_t full)
4248  output.clear();
4249 
4251 
4252  TClingClassInfo cl(fInterpreter, name);
4253  if (!cl.IsValid()) {
4254  return ;
4255  }
4256  if (full) {
4257  cl.FullName(output,*fNormalizedCtxt);
4258  return;
4259  }
4260  // Well well well, for backward compatibility we need to act a bit too
4261  // much like CINT.
4263  splitname.ShortType(output, TClassEdit::kDropStd );
4264 
4265  return;
4266 }
4267 
4268 ////////////////////////////////////////////////////////////////////////////////
4269 /// Execute a global function with arguments params.
4270 ///
4271 /// FIXME: The cint-based version of this code does not check if the
4272 /// SetFunc() call works, and does not do any real checking
4273 /// for errors from the Exec() call. It did fetch the most
4274 /// recent cint security error and return that in error, but
4275 /// this does not really translate well to cling/clang. We
4276 /// should enhance these interfaces so that we can report
4277 /// compilation and runtime errors properly.
4278 
4279 void TCling::Execute(const char* function, const char* params, int* error)
4280 {
4282  if (error) {
4283  *error = TInterpreter::kNoError;
4284  }
4286  Long_t offset = 0L;
4288  func.SetFunc(&cl, function, params, &offset);
4289  func.Exec(0);
4290 }
4291 
4292 ////////////////////////////////////////////////////////////////////////////////
4293 /// Execute a method from class cl with arguments params.
4294 ///
4295 /// FIXME: The cint-based version of this code does not check if the
4296 /// SetFunc() call works, and does not do any real checking
4297 /// for errors from the Exec() call. It did fetch the most
4298 /// recent cint security error and return that in error, but
4299 /// this does not really translate well to cling/clang. We
4300 /// should enhance these interfaces so that we can report
4301 /// compilation and runtime errors properly.
4302 
4303 void TCling::Execute(TObject* obj, TClass* cl, const char* method,
4304  const char* params, Bool_t objectIsConst, int* error)
4305 {
4307  if (error) {
4308  *error = TInterpreter::kNoError;
4309  }
4310  // If the actual class of this object inherits 2nd (or more) from TObject,
4311  // 'obj' is unlikely to be the start of the object (as described by IsA()),
4312  // hence gInterpreter->Execute will improperly correct the offset.
4313  void* addr = cl->DynamicCast(TObject::Class(), obj, kFALSE);
4314  Long_t offset = 0L;
4316  func.SetFunc((TClingClassInfo*)cl->GetClassInfo(), method, params, objectIsConst, &offset);
4317  void* address = (void*)((Long_t)addr + offset);
4318  func.Exec(address);
4319 }
4320 
4321 ////////////////////////////////////////////////////////////////////////////////
4322 
4323 void TCling::Execute(TObject* obj, TClass* cl, const char* method,
4324  const char* params, int* error)
4326  Execute(obj,cl,method,params,false,error);
4327 }
4328 
4329 ////////////////////////////////////////////////////////////////////////////////
4330 /// Execute a method from class cl with the arguments in array params
4331 /// (params[0] ... params[n] = array of TObjString parameters).
4332 /// Convert the TObjArray array of TObjString parameters to a character
4333 /// string of comma separated parameters.
4334 /// The parameters of type 'char' are enclosed in double quotes and all
4335 /// internal quotes are escaped.
4336 
4337 void TCling::Execute(TObject* obj, TClass* cl, TMethod* method,
4338  TObjArray* params, int* error)
4339 {
4340  if (!method) {
4341  Error("Execute", "No method was defined");
4342  return;
4343  }
4344  TList* argList = method->GetListOfMethodArgs();
4345  // Check number of actual parameters against of expected formal ones
4346 
4347  Int_t nparms = argList->LastIndex() + 1;
4348  Int_t argc = params ? params->GetEntries() : 0;
4350  if (argc > nparms) {
4351  Error("Execute","Too many parameters to call %s, got %d but expected at most %d.",method->GetName(),argc,nparms);
4352  return;
4353  }
4354  if (nparms != argc) {
4355  // Let's see if the 'missing' argument are all defaulted.
4356  // if nparms==0 then either we stopped earlier either argc is also zero and we can't reach here.
4357  assert(nparms > 0);
4358 
4359  TMethodArg *arg = (TMethodArg *) argList->At( 0 );
4360  if (arg && arg->GetDefault() && arg->GetDefault()[0]) {
4361  // There is a default value for the first missing
4362  // argument, so we are fine.
4363  } else {
4364  Int_t firstDefault = -1;
4365  for (Int_t i = 0; i < nparms; i ++) {
4366  arg = (TMethodArg *) argList->At( i );
4367  if (arg && arg->GetDefault() && arg->GetDefault()[0]) {
4368  firstDefault = i;
4369  break;
4370  }
4371  }
4372  if (firstDefault >= 0) {
4373  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);
4374  } else {
4375  Error("Execute","Too few arguments to call %s, got only %d but expected %d.",method->GetName(),argc,nparms);
4376  }
4377  return;
4378  }
4379  }
4380 
4381  const char* listpar = "";
4382  TString complete(10);
4383  if (params) {
4384  // Create a character string of parameters from TObjArray
4385  TIter next(params);
4386  for (Int_t i = 0; i < argc; i ++) {
4387  TMethodArg* arg = (TMethodArg*) argList->At(i);
4389  TObjString* nxtpar = (TObjString*) next();
4390  if (i) {
4391  complete += ',';
4392  }
4393  if (strstr(type.TrueName(*fNormalizedCtxt), "char")) {
4394  TString chpar('\"');
4395  chpar += (nxtpar->String()).ReplaceAll("\"", "\\\"");
4396  // At this point we have to check if string contains \\"
4397  // and apply some more sophisticated parser. Not implemented yet!
4398  complete += chpar;
4399  complete += '\"';
4400  }
4401  else {
4402  complete += nxtpar->String();
4403  }
4404  }
4405  listpar = complete.Data();
4406  }
4407 
4408  // And now execute it.
4410  if (error) {
4411  *error = TInterpreter::kNoError;
4412  }
4413  // If the actual class of this object inherits 2nd (or more) from TObject,
4414  // 'obj' is unlikely to be the start of the object (as described by IsA()),
4415  // hence gInterpreter->Execute will improperly correct the offset.
4416  void* addr = cl->DynamicCast(TObject::Class(), obj, kFALSE);
4418  TClingMethodInfo *minfo = (TClingMethodInfo*)method->fInfo;
4419  func.Init(minfo);
4420  func.SetArgs(listpar);
4421  // Now calculate the 'this' pointer offset for the method
4422  // when starting from the class described by cl.
4423  const CXXMethodDecl * mdecl = dyn_cast<CXXMethodDecl>(minfo->GetMethodDecl());
4424  Long_t offset = ((TClingClassInfo*)cl->GetClassInfo())->GetOffset(mdecl);
4425  void* address = (void*)((Long_t)addr + offset);
4426  func.Exec(address);
4427 }
4428 
4429 ////////////////////////////////////////////////////////////////////////////////
4430 
4431 void TCling::ExecuteWithArgsAndReturn(TMethod* method, void* address,
4432  const void* args[] /*=0*/,
4433  int nargs /*=0*/,
4434  void* ret/*= 0*/) const
4435 {
4436  if (!method) {
4437  Error("ExecuteWithArgsAndReturn", "No method was defined");
4438  return;
4439  }
4440 
4441  TClingMethodInfo* minfo = (TClingMethodInfo*) method->fInfo;
4443  func.ExecWithArgsAndReturn(address, args, nargs, ret);
4444 }
4445 
4446 ////////////////////////////////////////////////////////////////////////////////
4447 /// Execute a cling macro.
4448 
4449 Long_t TCling::ExecuteMacro(const char* filename, EErrorCode* error)
4450 {
4452  fCurExecutingMacros.push_back(filename);
4453  Long_t result = TApplication::ExecuteFile(filename, (int*)error);
4454  fCurExecutingMacros.pop_back();
4455  return result;
4456 }
4457 
4458 ////////////////////////////////////////////////////////////////////////////////
4459 /// Return the file name of the current un-included interpreted file.
4460 /// See the documentation for GetCurrentMacroName().
4461 
4462 const char* TCling::GetTopLevelMacroName() const
4463 {
4464  Warning("GetTopLevelMacroName", "Must change return type!");
4465  return fCurExecutingMacros.back();
4466 }
4467 
4468 ////////////////////////////////////////////////////////////////////////////////
4469 /// Return the file name of the currently interpreted file,
4470 /// included or not. Example to illustrate the difference between
4471 /// GetCurrentMacroName() and GetTopLevelMacroName():
4472 /// ~~~ {.cpp}
4473 /// void inclfile() {
4474 /// std::cout << "In inclfile.C" << std::endl;
4475 /// std::cout << " TCling::GetCurrentMacroName() returns " <<
4476 /// TCling::GetCurrentMacroName() << std::endl;
4477 /// std::cout << " TCling::GetTopLevelMacroName() returns " <<
4478 /// TCling::GetTopLevelMacroName() << std::endl;
4479 /// }
4480 /// ~~~
4481 /// ~~~ {.cpp}
4482 /// void mymacro() {
4483 /// std::cout << "In mymacro.C" << std::endl;
4484 /// std::cout << " TCling::GetCurrentMacroName() returns " <<
4485 /// TCling::GetCurrentMacroName() << std::endl;
4486 /// std::cout << " TCling::GetTopLevelMacroName() returns " <<
4487 /// TCling::GetTopLevelMacroName() << std::endl;
4488 /// std::cout << " Now calling inclfile..." << std::endl;
4489 /// gInterpreter->ProcessLine(".x inclfile.C");;
4490 /// }
4491 /// ~~~
4492 /// Running mymacro.C will print:
4493 ///
4494 /// ~~~ {.cpp}
4495 /// root [0] .x mymacro.C
4496 /// ~~~
4497 /// In mymacro.C
4498 /// ~~~ {.cpp}
4499 /// TCling::GetCurrentMacroName() returns ./mymacro.C
4500 /// TCling::GetTopLevelMacroName() returns ./mymacro.C
4501 /// ~~~
4502 /// Now calling inclfile...
4503 /// In inclfile.h
4504 /// ~~~ {.cpp}
4505 /// TCling::GetCurrentMacroName() returns inclfile.C
4506 /// TCling::GetTopLevelMacroName() returns ./mymacro.C
4507 /// ~~~
4509 const char* TCling::GetCurrentMacroName() const
4510 {
4511 #if defined(R__MUST_REVISIT)
4512 #if R__MUST_REVISIT(6,0)
4513  Warning("GetCurrentMacroName", "Must change return type!");
4514 #endif
4515 #endif
4516  return fCurExecutingMacros.back();
4517 }
4518 
4519 ////////////////////////////////////////////////////////////////////////////////
4520 /// Return the absolute type of typeDesc.
4521 /// E.g.: typeDesc = "class TNamed**", returns "TNamed".
4522 /// You need to use the result immediately before it is being overwritten.
4523 
4524 const char* TCling::TypeName(const char* typeDesc)
4525 {
4526  TTHREAD_TLS(char*) t = 0;
4527  TTHREAD_TLS(unsigned int) tlen = 0;
4528 
4529  unsigned int dlen = strlen(typeDesc);
4530  if (dlen > tlen) {
4531  delete[] t;
4532  t = new char[dlen + 1];
4533  tlen = dlen;
4534  }
4535  const char* s, *template_start;
4536  if (!strstr(typeDesc, "(*)(")) {
4537  s = strchr(typeDesc, ' ');
4538  template_start = strchr(typeDesc, '<');
4539  if (!strcmp(typeDesc, "long long")) {
4540  strlcpy(t, typeDesc, dlen + 1);
4541  }
4542  else if (!strncmp(typeDesc, "unsigned ", s + 1 - typeDesc)) {
4543  strlcpy(t, typeDesc, dlen + 1);
4544  }
4545  // s is the position of the second 'word' (if any)
4546  // except in the case of templates where there will be a space
4547  // just before any closing '>': eg.
4548  // TObj<std::vector<UShort_t,__malloc_alloc_template<0> > >*
4549  else if (s && (template_start == 0 || (s < template_start))) {
4550  strlcpy(t, s + 1, dlen + 1);
4551  }
4552  else {
4553  strlcpy(t, typeDesc, dlen + 1);
4554  }
4555  }
4556  else {
4557  strlcpy(t, typeDesc, dlen + 1);
4558  }
4559  int l = strlen(t);
4560  while (l > 0 && (t[l - 1] == '*' || t[l - 1] == '&')) {
4561  t[--l] = 0;
4562  }
4563  return t;
4564 }
4565 
4566 ////////////////////////////////////////////////////////////////////////////////
4567 /// Read and parse a rootmapfile in its new format, and return 0 in case of
4568 /// success, -1 if the file has already been read, and -3 in case its format
4569 /// is the old one (e.g. containing "Library.ClassName")
4571 int TCling::ReadRootmapFile(const char *rootmapfile, TUniqueString *uniqueString)
4572 {
4573  // For "class ", "namespace ", "typedef ", "header ", "enum ", "var " respectively
4574  const std::map<char, unsigned int> keyLenMap = {{'c',6},{'n',10},{'t',8},{'h',7},{'e',5},{'v',4}};
4575 
4576  if (rootmapfile && *rootmapfile) {
4577 
4578  // Add content of a specific rootmap file
4579  if (fRootmapFiles->FindObject(rootmapfile)) return -1;
4580  std::ifstream file(rootmapfile);
4581  std::string line; line.reserve(200);
4582  std::string lib_name; line.reserve(100);
4583  bool newFormat=false;
4584  while (getline(file, line, '\n')) {
4585  if (!newFormat &&
4586  (strstr(line.c_str(),"Library.")!=nullptr || strstr(line.c_str(),"Declare.")!=nullptr)) {
4587  file.close();
4588  return -3; // old format
4589  }
4590  newFormat=true;
4591 
4592  if (line.compare(0, 9, "{ decls }") == 0) {
4593  // forward declarations
4594 
4595  while (getline(file, line, '\n')) {
4596  if (line[0] == '[') break;
4597  uniqueString->Append(line);
4598  }
4599  }
4600  const char firstChar=line[0];
4601  if (firstChar == '[') {
4602  // new section (library)
4603  auto brpos = line.find(']');
4604  if (brpos == string::npos) continue;
4605  lib_name = line.substr(1, brpos-1);
4606  size_t nspaces = 0;
4607  while( lib_name[nspaces] == ' ' ) ++nspaces;
4608  if (nspaces) lib_name.replace(0, nspaces, "");
4609  if (gDebug > 3) {
4610  TString lib_nameTstr(lib_name.c_str());
4611  TObjArray* tokens = lib_nameTstr.Tokenize(" ");
4612  const char* lib = ((TObjString *)tokens->At(0))->GetName();
4613  const char* wlib = gSystem->DynamicPathName(lib, kTRUE);
4614  if (wlib) {
4615  Info("ReadRootmapFile", "new section for %s", lib_nameTstr.Data());
4616  }
4617  else {
4618  Info("ReadRootmapFile", "section for %s (library does not exist)", lib_nameTstr.Data());
4619  }
4620  delete[] wlib;
4621  delete tokens;
4622  }
4623  }
4624  else {
4625  auto keyLenIt = keyLenMap.find(firstChar);
4626  if (keyLenIt == keyLenMap.end()) continue;
4627  unsigned int keyLen = keyLenIt->second;
4628  // Do not make a copy, just start after the key
4629  const char *keyname = line.c_str()+keyLen;
4630  if (gDebug > 6)
4631  Info("ReadRootmapFile", "class %s in %s", keyname, lib_name.c_str());
4632  TEnvRec* isThere = fMapfile->Lookup(keyname);
4633  if (isThere){
4634  if(lib_name != isThere->GetValue()){ // the same key for two different libs
4635  if (firstChar == 'n') {
4636  if (gDebug > 3)
4637  Info("ReadRootmapFile", "namespace %s found in %s is already in %s",
4638  keyname, lib_name.c_str(), isThere->GetValue());
4639  } else if (firstChar == 'h'){ // it is a header: add the libname to the list of libs to be loaded.
4640  lib_name+=" ";
4641  lib_name+=isThere->GetValue();
4642  fMapfile->SetValue(keyname, lib_name.c_str());
4643  }
4644  else if (!TClassEdit::IsSTLCont(keyname)) {
4645  Warning("ReadRootmapFile", "%s %s found in %s is already in %s", line.substr(0, keyLen).c_str(),
4646  keyname, lib_name.c_str(), isThere->GetValue());
4647  }
4648  } else { // the same key for the same lib
4649  if (gDebug > 3)
4650  Info("ReadRootmapFile","Key %s was already defined for %s", keyname, lib_name.c_str());
4651  }
4652 
4653  } else {
4654  fMapfile->SetValue(keyname, lib_name.c_str());
4655  }
4656  }
4657  }
4658  file.close();
4659  }
4660 
4661  return 0;
4662 }
4663 
4664 ////////////////////////////////////////////////////////////////////////////////
4665 /// Create a resource table and read the (possibly) three resource files, i.e
4666 /// $ROOTSYS/etc/system<name> (or ROOTETCDIR/system<name>), $HOME/<name> and
4667 /// ./<name>. ROOT always reads ".rootrc" (in TROOT::InitSystem()). You can
4668 /// read additional user defined resource files by creating additional TEnv
4669 /// objects. By setting the shell variable ROOTENV_NO_HOME=1 the reading of
4670 /// the $HOME/<name> resource file will be skipped. This might be useful in
4671 /// case the home directory resides on an automounted remote file system
4672 /// and one wants to avoid the file system from being mounted.
4673 
4674 void TCling::InitRootmapFile(const char *name)
4675 {
4677 
4678  fMapfile->SetRcName(name);
4679 
4680  TString sname = "system";
4681  sname += name;
4682  char *s = gSystem->ConcatFileName(TROOT::GetEtcDir(), sname);
4683 
4684  Int_t ret = ReadRootmapFile(s);
4685  if (ret == -3) // old format
4687  delete [] s;
4688  if (!gSystem->Getenv("ROOTENV_NO_HOME")) {
4690  ret = ReadRootmapFile(s);
4691  if (ret == -3) // old format
4692  fMapfile->ReadFile(s, kEnvUser);
4693  delete [] s;
4694  if (strcmp(gSystem->HomeDirectory(), gSystem->WorkingDirectory())) {
4695  ret = ReadRootmapFile(name);
4696  if (ret == -3) // old format
4697  fMapfile->ReadFile(name, kEnvLocal);
4698  }
4699  } else {
4700  ret = ReadRootmapFile(name);
4701  if (ret == -3) // old format
4702  fMapfile->ReadFile(name, kEnvLocal);
4703  }
4704  fMapfile->IgnoreDuplicates(ignore);
4705 }
4706 
4707 
4708 namespace {
4709  using namespace clang;
4710 
4711  class ExtVisibleStorageAdder: public RecursiveASTVisitor<ExtVisibleStorageAdder>{
4712  // This class is to be considered an helper for autoloading.
4713  // It is a recursive visitor is used to inspect namespaces coming from
4714  // forward declarations in rootmaps and to set the external visible
4715  // storage flag for them.
4716  public:
4717  ExtVisibleStorageAdder(std::unordered_set<const NamespaceDecl*>& nsSet): fNSSet(nsSet) {};
4718  bool VisitNamespaceDecl(NamespaceDecl* nsDecl) {
4719  // We want to enable the external lookup for this namespace
4720  // because it may shadow the lookup of other names contained
4721  // in that namespace
4722  nsDecl->setHasExternalVisibleStorage();
4723  fNSSet.insert(nsDecl);
4724  return true;
4725  }
4726  private:
4727  std::unordered_set<const NamespaceDecl*>& fNSSet;
4728 
4729  };
4730 }
4731 
4732 ////////////////////////////////////////////////////////////////////////////////
4733 /// Load map between class and library. If rootmapfile is specified a
4734 /// specific rootmap file can be added (typically used by ACLiC).
4735 /// In case of error -1 is returned, 0 otherwise.
4736 /// The interpreter uses this information to automatically load the shared
4737 /// library for a class (autoload mechanism), see the AutoLoad() methods below.
4738 
4739 Int_t TCling::LoadLibraryMap(const char* rootmapfile)
4740 {
4742  // open the [system].rootmap files
4743  if (!fMapfile) {
4744  fMapfile = new TEnv();
4746 // fMapNamespaces = new THashTable();
4747 // fMapNamespaces->SetOwner();
4748  fRootmapFiles = new TObjArray;
4750  InitRootmapFile(".rootmap");
4751  }
4752 
4753  // Prepare a list of all forward declarations for cling
4754  // For some experiments it is easily as big as 500k characters. To be on the
4755  // safe side, we go for 1M.
4756  TUniqueString uniqueString(1048576);
4757 
4758  // Load all rootmap files in the dynamic load path ((DY)LD_LIBRARY_PATH, etc.).
4759  // A rootmap file must end with the string ".rootmap".
4760  TString ldpath = gSystem->GetDynamicPath();
4761  if (ldpath != fRootmapLoadPath) {
4762  fRootmapLoadPath = ldpath;
4763 #ifdef WIN32
4764  TObjArray* paths = ldpath.Tokenize(";");
4765 #else
4766  TObjArray* paths = ldpath.Tokenize(":");
4767 #endif
4768  TString d;
4769  for (Int_t i = 0; i < paths->GetEntriesFast(); i++) {
4770  d = ((TObjString *)paths->At(i))->GetString();
4771  // check if directory already scanned
4772  Int_t skip = 0;
4773  for (Int_t j = 0; j < i; j++) {
4774  TString pd = ((TObjString *)paths->At(j))->GetString();
4775  if (pd == d) {
4776  skip++;
4777  break;
4778  }
4779  }
4780  if (!skip) {
4781  void* dirp = gSystem->OpenDirectory(d);
4782  if (dirp) {
4783  if (gDebug > 3) {
4784  Info("LoadLibraryMap", "%s", d.Data());
4785  }
4786  const char* f1;
4787  while ((f1 = gSystem->GetDirEntry(dirp))) {
4788  TString f = f1;
4789  if (f.EndsWith(".rootmap")) {
4790  TString p;
4791  p = d + "/" + f;
4793  if (!fRootmapFiles->FindObject(f) && f != ".rootmap") {
4794  if (gDebug > 4) {
4795  Info("LoadLibraryMap", " rootmap file: %s", p.Data());
4796  }
4797  Int_t ret = ReadRootmapFile(p,&uniqueString);
4798  if (ret == 0)
4799  fRootmapFiles->Add(new TNamed(gSystem->BaseName(f), p.Data()));
4800  if (ret == -3) {
4801  // old format
4803  fRootmapFiles->Add(new TNamed(f, p));
4804  }
4805  }
4806  // else {
4807  // fprintf(stderr,"Reject %s because %s is already there\n",p.Data(),f.Data());
4808  // fRootmapFiles->FindObject(f)->ls();
4809  // }
4810  }
4811  }
4812  if (f.BeginsWith("rootmap")) {
4813  TString p;
4814  p = d + "/" + f;
4815  FileStat_t stat;
4816  if (gSystem->GetPathInfo(p, stat) == 0 && R_ISREG(stat.fMode)) {
4817  Warning("LoadLibraryMap", "please rename %s to end with \".rootmap\"", p.Data());
4818  }
4819  }
4820  }
4821  }
4822  gSystem->FreeDirectory(dirp);
4823  }
4824  }
4825  delete paths;
4826  if (!fMapfile->GetTable()->GetEntries()) {
4827  return -1;
4828  }
4829  }
4830  if (rootmapfile && *rootmapfile) {
4831  Int_t res = ReadRootmapFile(rootmapfile, &uniqueString);
4832  if (res == 0) {
4833  //TString p = gSystem->ConcatFileName(gSystem->pwd(), rootmapfile);
4834  //fRootmapFiles->Add(new TNamed(gSystem->BaseName(rootmapfile), p.Data()));
4835  fRootmapFiles->Add(new TNamed(gSystem->BaseName(rootmapfile), rootmapfile));
4836  }
4837  else if (res == -3) {
4838  // old format
4840  fMapfile->ReadFile(rootmapfile, kEnvGlobal);
4841  fRootmapFiles->Add(new TNamed(gSystem->BaseName(rootmapfile), rootmapfile));
4842  fMapfile->IgnoreDuplicates(ignore);
4843  }
4844  }
4845  TEnvRec* rec;
4846  TIter next(fMapfile->GetTable());
4847  while ((rec = (TEnvRec*) next())) {
4848  TString cls = rec->GetName();
4849  if (!strncmp(cls.Data(), "Library.", 8) && cls.Length() > 8) {
4850  // get the first lib from the list of lib and dependent libs
4851  TString libs = rec->GetValue();
4852  if (libs == "") {
4853  continue;
4854  }
4855  TString delim(" ");
4856  TObjArray* tokens = libs.Tokenize(delim);
4857  const char* lib = ((TObjString*)tokens->At(0))->GetName();
4858  // convert "@@" to "::", we used "@@" because TEnv
4859  // considers "::" a terminator
4860  cls.Remove(0, 8);
4861  cls.ReplaceAll("@@", "::");
4862  // convert "-" to " ", since class names may have
4863  // blanks and TEnv considers a blank a terminator
4864  cls.ReplaceAll("-", " ");
4865  if (gDebug > 6) {
4866  const char* wlib = gSystem->DynamicPathName(lib, kTRUE);
4867  if (wlib) {
4868  Info("LoadLibraryMap", "class %s in %s", cls.Data(), wlib);
4869  }
4870  else {
4871  Info("LoadLibraryMap", "class %s in %s (library does not exist)", cls.Data(), lib);
4872  }
4873  delete[] wlib;
4874  }
4875  // Fill in the namespace candidate list
4876 // Ssiz_t last = cls.Last(':');
4877 // if (last != kNPOS) {
4878 // // Please note that the funny op overload does substring.
4879 // TString namespaceCand = cls(0, last - 1);
4880 // // This is a reference to a substring that lives in fMapfile
4881 // if (!fMapNamespaces->FindObject(namespaceCand.Data()))
4882 // fMapNamespaces->Add(new TNamed(namespaceCand.Data(), ""));
4883 // }
4884  delete tokens;
4885  }
4886  else if (!strncmp(cls.Data(), "Declare.", 8) && cls.Length() > 8) {
4887  cls.Remove(0, 8);
4888  // convert "-" to " ", since class names may have
4889  // blanks and TEnv considers a blank a terminator
4890  cls.ReplaceAll("-", " ");
4891  fInterpreter->declare(cls.Data());
4892  }
4893  }
4894 
4895  // Process the forward declarations collected
4896  cling::Transaction* T = nullptr;
4897  auto compRes= fInterpreter->declare(uniqueString.Data(), &T);
4898  assert(cling::Interpreter::kSuccess == compRes && "A declaration in a rootmap could not be compiled");
4899 
4900  if (compRes!=cling::Interpreter::kSuccess){
4901  Warning("LoadLibraryMap",
4902  "Problems in %s declaring '%s' were encountered.", rootmapfile, uniqueString.Data()) ;
4903  }
4904 
4905  if (T){
4906  ExtVisibleStorageAdder evsAdder(fNSFromRootmaps);
4907  for (auto declIt = T->decls_begin(); declIt < T->decls_end(); ++declIt) {
4908  if (declIt->m_DGR.isSingleDecl()) {
4909  if (Decl* D = declIt->m_DGR.getSingleDecl()) {
4910  if (NamespaceDecl* NSD = dyn_cast<NamespaceDecl>(D)) {
4911  evsAdder.TraverseDecl(NSD);
4912  }
4913  }
4914  }
4915  }
4916  }
4917 
4918  // clear duplicates
4919 
4920  return 0;
4921 }
4922 
4923 ////////////////////////////////////////////////////////////////////////////////
4924 /// Scan again along the dynamic path for library maps. Entries for the loaded
4925 /// shared libraries are unloaded first. This can be useful after reseting
4926 /// the dynamic path through TSystem::SetDynamicPath()
4927 /// In case of error -1 is returned, 0 otherwise.
4928 
4930 {
4932  LoadLibraryMap();
4933  return 0;
4934 }
4935 
4936 ////////////////////////////////////////////////////////////////////////////////
4937 /// Reload the library map entries coming from all the loaded shared libraries,
4938 /// after first unloading the current ones.
4939 /// In case of error -1 is returned, 0 otherwise.
4940 
4942 {
4943  const TString sharedLibLStr = GetSharedLibs();
4944  const TObjArray* sharedLibL = sharedLibLStr.Tokenize(" ");
4945  const Int_t nrSharedLibs = sharedLibL->GetEntriesFast();
4946  for (Int_t ilib = 0; ilib < nrSharedLibs; ilib++) {
4947  const TString sharedLibStr = ((TObjString*)sharedLibL->At(ilib))->GetString();
4948  const TString sharedLibBaseStr = gSystem->BaseName(sharedLibStr);
4949  const Int_t ret = UnloadLibraryMap(sharedLibBaseStr);
4950  if (ret < 0) {
4951  continue;
4952  }
4953  TString rootMapBaseStr = sharedLibBaseStr;
4954  if (sharedLibBaseStr.EndsWith(".dll")) {
4955  rootMapBaseStr.ReplaceAll(".dll", "");
4956  }
4957  else if (sharedLibBaseStr.EndsWith(".DLL")) {
4958  rootMapBaseStr.ReplaceAll(".DLL", "");
4959  }
4960  else if (sharedLibBaseStr.EndsWith(".so")) {
4961  rootMapBaseStr.ReplaceAll(".so", "");
4962  }
4963  else if (sharedLibBaseStr.EndsWith(".sl")) {
4964  rootMapBaseStr.ReplaceAll(".sl", "");
4965  }
4966  else if (sharedLibBaseStr.EndsWith(".dl")) {
4967  rootMapBaseStr.ReplaceAll(".dl", "");
4968  }
4969  else if (sharedLibBaseStr.EndsWith(".a")) {
4970  rootMapBaseStr.ReplaceAll(".a", "");
4971  }
4972  else {
4973  Error("ReloadAllSharedLibraryMaps", "Unknown library type %s", sharedLibBaseStr.Data());
4974  delete sharedLibL;
4975  return -1;
4976  }
4977  rootMapBaseStr += ".rootmap";
4978  const char* rootMap = gSystem->Which(gSystem->GetDynamicPath(), rootMapBaseStr);
4979  if (!rootMap) {
4980  Error("ReloadAllSharedLibraryMaps", "Could not find rootmap %s in path", rootMap);
4981  delete[] rootMap;
4982  delete sharedLibL;
4983  return -1;
4984  }
4985  const Int_t status = LoadLibraryMap(rootMap);
4986  if (status < 0) {
4987  Error("ReloadAllSharedLibraryMaps", "Error loading map %s", rootMap);
4988  delete[] rootMap;
4989  delete sharedLibL;
4990  return -1;
4991  }
4992  delete[] rootMap;
4993  }
4994  delete sharedLibL;
4995  return 0;
4996 }
4997 
4998 ////////////////////////////////////////////////////////////////////////////////
4999 /// Unload the library map entries coming from all the loaded shared libraries.
5000 /// Returns 0 if succesful
5001 
5003 {
5004  const TString sharedLibLStr = GetSharedLibs();
5005  const TObjArray* sharedLibL = sharedLibLStr.Tokenize(" ");
5006  for (Int_t ilib = 0; ilib < sharedLibL->GetEntriesFast(); ilib++) {
5007  const TString sharedLibStr = ((TObjString*)sharedLibL->At(ilib))->GetString();
5008  const TString sharedLibBaseStr = gSystem->BaseName(sharedLibStr);
5009  UnloadLibraryMap(sharedLibBaseStr);
5010  }
5011  delete sharedLibL;
5012  return 0;
5013 }
5014 
5015 ////////////////////////////////////////////////////////////////////////////////
5016 /// Unload library map entries coming from the specified library.
5017 /// Returns -1 in case no entries for the specified library were found,
5018 /// 0 otherwise.
5019 
5020 Int_t TCling::UnloadLibraryMap(const char* library)
5021 {
5022  if (!fMapfile || !library || !*library) {
5023  return 0;
5024  }
5025  TString libname(library);
5026  Ssiz_t idx = libname.Last('.');
5027  if (idx != kNPOS) {
5028  libname.Remove(idx);
5029  }
5030  size_t len = libname.Length();
5031  TEnvRec *rec;
5032  TIter next(fMapfile->GetTable());
5034  Int_t ret = 0;
5035  while ((rec = (TEnvRec *) next())) {
5036  TString cls = rec->GetName();
5037  if (cls.Length() > 2) {
5038  // get the first lib from the list of lib and dependent libs
5039  TString libs = rec->GetValue();
5040  if (libs == "") {
5041  continue;
5042  }
5043  TString delim(" ");
5044  TObjArray* tokens = libs.Tokenize(delim);
5045  const char* lib = ((TObjString *)tokens->At(0))->GetName();
5046  if (!strncmp(cls.Data(), "Library.", 8) && cls.Length() > 8) {
5047  // convert "@@" to "::", we used "@@" because TEnv
5048  // considers "::" a terminator
5049  cls.Remove(0, 8);
5050  cls.ReplaceAll("@@", "::");
5051  // convert "-" to " ", since class names may have
5052  // blanks and TEnv considers a blank a terminator
5053  cls.ReplaceAll("-", " ");
5054  }
5055  if (!strncmp(lib, libname.Data(), len)) {
5056  if (fMapfile->GetTable()->Remove(rec) == 0) {
5057  Error("UnloadLibraryMap", "entry for <%s, %s> not found in library map table", cls.Data(), lib);
5058  ret = -1;
5059  }
5060  }
5061  delete tokens;
5062  }
5063  }
5064  if (ret >= 0) {
5065  TString library_rootmap(library);
5066  if (!library_rootmap.EndsWith(".rootmap"))
5067  library_rootmap.Append(".rootmap");
5068  TNamed* mfile = 0;
5069  while ((mfile = (TNamed *)fRootmapFiles->FindObject(library_rootmap))) {
5070  fRootmapFiles->Remove(mfile);
5071  delete mfile;
5072  }
5074  }
5075  return ret;
5076 }
5077 
5078 ////////////////////////////////////////////////////////////////////////////////
5079 /// Register the autoloading information for a class.
5080 /// libs is a space separated list of libraries.
5081 
5082 Int_t TCling::SetClassSharedLibs(const char *cls, const char *libs)
5083 {
5084  if (!cls || !*cls)
5085  return 0;
5086 
5087  TString key = TString("Library.") + cls;
5088  // convert "::" to "@@", we used "@@" because TEnv
5089  // considers "::" a terminator
5090  key.ReplaceAll("::", "@@");
5091  // convert "-" to " ", since class names may have
5092  // blanks and TEnv considers a blank a terminator
5093  key.ReplaceAll(" ", "-");
5094 
5096  if (!fMapfile) {
5097  fMapfile = new TEnv();
5099 // fMapNamespaces = new THashTable();
5100 // fMapNamespaces->SetOwner();
5101 
5102  fRootmapFiles = new TObjArray;
5104 
5105  InitRootmapFile(".rootmap");
5106  }
5107  //fMapfile->SetValue(key, libs);
5108  fMapfile->SetValue(cls, libs);
5109  return 1;
5110 }
5111 
5112 ////////////////////////////////////////////////////////////////////////////////
5113 /// Demangle the name (from the typeinfo) and then request the class
5114 /// via the usual name based interface (TClass::GetClass).
5115 
5116 TClass *TCling::GetClass(const std::type_info& typeinfo, Bool_t load) const
5117 {
5118  int err = 0;
5119  char* demangled_name = TClassEdit::DemangleTypeIdName(typeinfo, err);
5120  if (err) return 0;
5121  TClass* theClass = TClass::GetClass(demangled_name, load, kTRUE);
5122  free(demangled_name);
5123  return theClass;
5124 }
5125 
5126 ////////////////////////////////////////////////////////////////////////////////
5127 /// Load library containing the specified class. Returns 0 in case of error
5128 /// and 1 in case if success.
5129 
5130 Int_t TCling::AutoLoad(const std::type_info& typeinfo, Bool_t knowDictNotLoaded /* = kFALSE */)
5131 {
5132  int err = 0;
5133  char* demangled_name_c = TClassEdit::DemangleTypeIdName(typeinfo, err);
5134  if (err) {
5135  return 0;
5136  }
5137 
5138  std::string demangled_name(demangled_name_c);
5139  free(demangled_name_c);
5140 
5141  // AutoLoad expects (because TClass::GetClass already prepares it that way) a
5142  // shortened name.
5143  TClassEdit::TSplitType splitname( demangled_name.c_str(), (TClassEdit::EModType)(TClassEdit::kLong64 | TClassEdit::kDropStd) );
5144  splitname.ShortType(demangled_name, TClassEdit::kDropStlDefault | TClassEdit::kDropStd);
5145 
5146  // No need to worry about typedef, they aren't any ... but there are
5147  // inlined namespaces ...
5148 
5149  Int_t result = AutoLoad(demangled_name.c_str());
5150  if (result == 0) {
5151  demangled_name = TClassEdit::GetLong64_Name(demangled_name);
5152  result = AutoLoad(demangled_name.c_str(), knowDictNotLoaded);
5153  }
5154 
5155  return result;
5156 }
5157 
5158 ////////////////////////////////////////////////////////////////////////////////
5159 /// Load library containing the specified class. Returns 0 in case of error
5160 /// and 1 in case if success.
5161 
5162 Int_t TCling::AutoLoad(const char *cls, Bool_t knowDictNotLoaded /* = kFALSE */)
5163 {
5165 
5166  if (!knowDictNotLoaded && gClassTable->GetDictNorm(cls)) {
5167  // The library is already loaded as the class's dictionary is known.
5168  // Return success.
5169  // Note: the name (cls) is expected to be normalized as it comes either
5170  // from a callbacks (that can/should calculate the normalized name from the
5171  // decl) or from TClass::GetClass (which does also calculate the normalized
5172  // name).
5173  return 1;
5174  }
5175 
5176  if (gDebug > 2) {
5177  Info("TCling::AutoLoad",
5178  "Trying to autoload for %s", cls);
5179  }
5180 
5181  Int_t status = 0;
5182  if (!gROOT || !gInterpreter || gROOT->TestBit(TObject::kInvalidObject)) {
5183  if (gDebug > 2) {
5184  Info("TCling::AutoLoad",
5185  "Disabled due to gROOT or gInterpreter being invalid/not ready (the class name is %s)", cls);
5186  }
5187  return status;
5188  }
5189  if (!fAllowLibLoad) {
5190  // Never load any library from rootcling/genreflex.
5191  if (gDebug > 2) {
5192  Info("TCling::AutoLoad",
5193  "Explicitly disabled (the class name is %s)", cls);
5194  }
5195  return 0;
5196  }
5197  // Prevent the recursion when the library dictionary are loaded.
5198  Int_t oldvalue = SetClassAutoloading(false);
5199  // Try using externally provided callback first.
5200  if (fAutoLoadCallBack) {
5201  int success = (*(AutoLoadCallBack_t)fAutoLoadCallBack)(cls);
5202  if (success) {
5203  SetClassAutoloading(oldvalue);
5204  return success;
5205  }
5206  }
5207  // lookup class to find list of dependent libraries
5208  TString deplibs = GetClassSharedLibs(cls);
5209  if (!deplibs.IsNull()) {
5210  TString delim(" ");
5211  TObjArray* tokens = deplibs.Tokenize(delim);
5212  for (Int_t i = (tokens->GetEntriesFast() - 1); i > 0; --i) {
5213  const char* deplib = ((TObjString*)tokens->At(i))->GetName();
5214  if (gROOT->LoadClass(cls, deplib) == 0) {
5215  if (gDebug > 0) {
5216  Info("TCling::AutoLoad",
5217  "loaded dependent library %s for %s", deplib, cls);
5218  }
5219  }
5220  else {
5221  Error("TCling::AutoLoad",
5222  "failure loading dependent library %s for %s",
5223  deplib, cls);
5224  }
5225  }
5226  const char* lib = ((TObjString*)tokens->At(0))->GetName();
5227  if (lib && lib[0]) {
5228  if (gROOT->LoadClass(cls, lib) == 0) {
5229  if (gDebug > 0) {
5230  Info("TCling::AutoLoad",
5231  "loaded library %s for %s", lib, cls);
5232  }
5233  status = 1;
5234  }
5235  else {
5236  Error("TCling::AutoLoad",
5237  "failure loading library %s for %s", lib, cls);
5238  }
5239  }
5240  delete tokens;
5241  }
5242 
5243  SetClassAutoloading(oldvalue);
5244  return status;
5245 }
5246 
5247 ////////////////////////////////////////////////////////////////////////////////
5248 /// Parse the payload or header.
5249 
5250 static cling::Interpreter::CompilationResult ExecAutoParse(const char *what,
5251  Bool_t header,
5252  cling::Interpreter *interpreter)
5253 {
5254  std::string code = gNonInterpreterClassDef ;
5255  if (!header) {
5256  // This is the complete header file content and not the
5257  // name of a header.
5258  code += what;
5259 
5260  } else {
5261  code += ("#include \"");
5262  code += what;
5263  code += "\"\n";
5264  }
5265  code += ("#ifdef __ROOTCLING__\n"
5266  "#undef __ROOTCLING__\n"
5267  + gInterpreterClassDef +
5268  "#endif");
5269 
5270  cling::Interpreter::CompilationResult cr;
5271  {
5272  // scope within which diagnostics are de-activated
5273  // For now we disable diagnostics because we saw them already at
5274  // dictionary generation time. That won't be an issue with the PCMs.
5275 
5276  Sema &SemaR = interpreter->getSema();
5277  ROOT::Internal::ParsingStateRAII parsingStateRAII(interpreter->getParser(), SemaR);
5278  clangDiagSuppr diagSuppr(SemaR.getDiagnostics());
5279 
5280  #if defined(R__MUST_REVISIT)
5281  #if R__MUST_REVISIT(6,2)
5282  Warning("TCling::RegisterModule","Diagnostics suppression should be gone by now.");
5283  #endif
5284  #endif
5285 
5286  cr = interpreter->parseForModule(code);
5287  }
5288  return cr;
5289 }
5290 
5291 ////////////////////////////////////////////////////////////////////////////////
5292 /// Helper routine for TCling::AutoParse implementing the actual call to the
5293 /// parser and looping over template parameters (if
5294 /// any) and when they don't have a registered header to autoparse,
5295 /// recurse over their template parameters.
5296 ///
5297 /// Returns the number of header parsed.
5298 
5299 UInt_t TCling::AutoParseImplRecurse(const char *cls, bool topLevel)
5300 {
5301  // We assume the lock has already been taken.
5302  // R__LOCKGUARD(gInterpreterMutex);
5303 
5304  Int_t nHheadersParsed = 0;
5305 
5306  // Loop on the possible autoparse keys
5307  bool skipFirstEntry = false;
5308  std::vector<std::string> autoparseKeys;
5309  if (strchr(cls, '<')) {
5310  int nestedLoc = 0;
5311  TClassEdit::GetSplit(cls, autoparseKeys, nestedLoc, TClassEdit::kDropTrailStar);
5312  // Check if we can skip the name of the template in the autoparses
5313  // Take all the scopes one by one. If all of them are in the AST, we do not
5314  // need to autoparse for that particular template.
5315  if (!autoparseKeys.empty()){
5316  TString templateName(autoparseKeys[0]);
5317  auto tokens = templateName.Tokenize("::");
5318  clang::NamedDecl* previousScopeAsNamedDecl = nullptr;
5319  clang::DeclContext* previousScopeAsContext = fInterpreter->getCI()->getASTContext().getTranslationUnitDecl();
5320  if (TClassEdit::IsStdClass(cls))
5321  previousScopeAsContext = fInterpreter->getSema().getStdNamespace();
5322  for (auto const scopeObj : *tokens){
5323  auto scopeName = ((TObjString*) scopeObj)->String().Data();
5324  previousScopeAsNamedDecl = cling::utils::Lookup::Named(&fInterpreter->getSema(), scopeName, previousScopeAsContext);
5325  // Check if we have multiple nodes in the AST with this name
5326  if ((clang::NamedDecl*)-1 == previousScopeAsNamedDecl) break;
5327  previousScopeAsContext = llvm::dyn_cast_or_null<clang::DeclContext>(previousScopeAsNamedDecl);
5328  if (!previousScopeAsContext) break; // this is not a context
5329  }
5330  delete tokens;
5331  // Now, let's check if the last scope, the template, has a definition, i.e. it's not a fwd decl
5332  if ((clang::NamedDecl*)-1 != previousScopeAsNamedDecl) {
5333  if (auto templateDecl = llvm::dyn_cast_or_null<clang::ClassTemplateDecl>(previousScopeAsNamedDecl)) {
5334  if (auto templatedDecl = templateDecl->getTemplatedDecl()) {
5335  skipFirstEntry = nullptr != templatedDecl->getDefinition();
5336  }
5337  }
5338  }
5339 
5340  }
5341  }
5342  if (topLevel) autoparseKeys.emplace_back(cls);
5343 
5344  for (const auto & apKeyStr : autoparseKeys) {
5345  if (skipFirstEntry) {
5346  skipFirstEntry=false;
5347  continue;
5348  }
5349  if (apKeyStr.empty()) continue;
5350  const char *apKey = apKeyStr.c_str();
5351  std::size_t normNameHash(fStringHashFunction(apKey));
5352  // If the class was not looked up
5353  if (gDebug > 1) {
5354  Info("TCling::AutoParse",
5355  "Starting autoparse for %s\n", apKey);
5356  }
5357  if (fLookedUpClasses.insert(normNameHash).second) {
5358  auto const &iter = fClassesHeadersMap.find(normNameHash);
5359  if (iter != fClassesHeadersMap.end()) {
5360  const cling::Transaction *T = fInterpreter->getCurrentTransaction();
5361  fTransactionHeadersMap.insert({T,normNameHash});
5362  auto const &hNamesPtrs = iter->second;
5363  if (gDebug > 1) {
5364  Info("TCling::AutoParse",
5365  "We can proceed for %s. We have %s headers.", apKey, std::to_string(hNamesPtrs.size()).c_str());
5366  }
5367  for (auto & hName : hNamesPtrs) {
5368  if (fParsedPayloadsAddresses.count(hName) == 1) continue;
5369  if (0 != fPayloads.count(normNameHash)) {
5370  float initRSSval=0.f, initVSIZEval=0.f;
5371  (void) initRSSval; // Avoid unused var warning
5372  (void) initVSIZEval;
5373  if (gDebug > 0) {
5374  Info("AutoParse",
5375  "Parsing full payload for %s", apKey);
5376  ProcInfo_t info;
5377  gSystem->GetProcInfo(&info);
5378  initRSSval = 1e-3*info.fMemResident;
5379  initVSIZEval = 1e-3*info.fMemVirtual;
5380  }
5381  auto cRes = ExecAutoParse(hName, kFALSE, fInterpreter);
5382  if (cRes != cling::Interpreter::kSuccess) {
5383  if (hName[0] == '\n')
5384  Error("AutoParse", "Error parsing payload code for class %s with content:\n%s", apKey, hName);
5385  } else {
5386  fParsedPayloadsAddresses.insert(hName);
5387  nHheadersParsed++;
5388  if (gDebug > 0){
5389  ProcInfo_t info;
5390  gSystem->GetProcInfo(&info);
5391  float endRSSval = 1e-3*info.fMemResident;
5392  float endVSIZEval = 1e-3*info.fMemVirtual;
5393  Info("Autoparse", ">>> RSS key %s - before %.3f MB - after %.3f MB - delta %.3f MB", apKey, initRSSval, endRSSval, endRSSval-initRSSval);
5394  Info("Autoparse", ">>> VSIZE key %s - before %.3f MB - after %.3f MB - delta %.3f MB", apKey, initVSIZEval, endVSIZEval, endVSIZEval-initVSIZEval);
5395  }
5396  }
5397  } else if (!IsLoaded(hName)) {
5398  if (gDebug > 0) {
5399  Info("AutoParse",
5400  "Parsing single header %s", hName);
5401  }
5402  auto cRes = ExecAutoParse(hName, kTRUE, fInterpreter);
5403  if (cRes != cling::Interpreter::kSuccess) {
5404  Error("AutoParse", "Error parsing headerfile %s for class %s.", hName, apKey);
5405  } else {
5406  nHheadersParsed++;
5407  }
5408  }
5409  }
5410  }
5411  else {
5412  // There is no header registered for this class, if this a
5413  // template, it will be instantiated if/when it is requested
5414  // and if we do no load/parse its components we might end up
5415  // not using an eventual specialization.
5416  if (strchr(apKey, '<')) {
5417  nHheadersParsed += AutoParseImplRecurse(apKey, false);
5418  }
5419  }
5420  }
5421  }
5422 
5423  return nHheadersParsed;
5424 
5425 }
5426 
5427 ////////////////////////////////////////////////////////////////////////////////
5428 /// Parse the headers relative to the class
5429 /// Returns 1 in case of success, 0 in case of failure
5430 
5431 Int_t TCling::AutoParse(const char *cls)
5432 {
5434 
5437  return AutoLoad(cls);
5438  } else {
5439  return 0;
5440  }
5441  }
5442 
5443  if (gDebug > 1) {
5444  Info("TCling::AutoParse",
5445  "Trying to autoparse for %s", cls);
5446  }
5447 
5448  // The catalogue of headers is in the dictionary
5450  && !gClassTable->GetDictNorm(cls)) {
5451  // Need RAII against recursive (dictionary payload) parsing (ROOT-8445).
5452  ROOT::Internal::ParsingStateRAII parsingStateRAII(fInterpreter->getParser(),
5453  fInterpreter->getSema());
5454  AutoLoad(cls, true /*knowDictNotLoaded*/);
5455  }
5456 
5457  // Prevent the recursion when the library dictionary are loaded.
5458  Int_t oldAutoloadValue = SetClassAutoloading(false);
5459 
5460  // No recursive header parsing on demand; we require headers to be standalone.
5461  SuspendAutoParsing autoParseRAII(this);
5462 
5463  Int_t nHheadersParsed = AutoParseImplRecurse(cls,/*topLevel=*/ true);
5464 
5465  if (nHheadersParsed != 0) {
5466  while (!fClassesToUpdate.empty()) {
5467  TClass *oldcl = fClassesToUpdate.back().first;
5468  if (oldcl->GetState() != TClass::kHasTClassInit) {
5469  // if (gDebug > 2) Info("RegisterModule", "Forcing TClass init for %s", oldcl->GetName());
5470  DictFuncPtr_t dict = fClassesToUpdate.back().second;
5471  fClassesToUpdate.pop_back();
5472  // Calling func could manipulate the list so, let maintain the list
5473  // then call the dictionary function.
5474  TClass *ncl = dict();
5475  if (ncl) ncl->PostLoadCheck();
5476  } else {
5477  fClassesToUpdate.pop_back();
5478  }
5479  }
5480  }
5481 
5482  SetClassAutoloading(oldAutoloadValue);
5483 
5484  return nHheadersParsed > 0 ? 1 : 0;
5485 }
5486 
5487 
5488 ////////////////////////////////////////////////////////////////////////////////
5489 /// Autoload a library based on a missing symbol.
5490 
5491 void* TCling::LazyFunctionCreatorAutoload(const std::string& mangled_name) {
5492  // First see whether the symbol is in the library that we are currently
5493  // loading. It will have access to the symbols of its dependent libraries,
5494  // thus checking "back()" is sufficient.
5495  if (!fRegisterModuleDyLibs.empty()) {
5496  if (void* addr = dlsym(fRegisterModuleDyLibs.back(),
5497  mangled_name.c_str())) {
5498  return addr;
5499  }
5500  }
5501 
5502  int err = 0;
5503  char* demangled_name_c = TClassEdit::DemangleName(mangled_name.c_str(), err);
5504  if (err) {
5505  return 0;
5506  }
5507 
5508  std::string name(demangled_name_c);
5509  free(demangled_name_c);
5510 
5511  //fprintf(stderr, "demangled name: '%s'\n", demangled_name);
5512  //
5513  // Separate out the class or namespace part of the
5514  // function name.
5515  //
5516 
5517  if (!strncmp(name.c_str(), "typeinfo for ", sizeof("typeinfo for ")-1)) {
5518  name.erase(0, sizeof("typeinfo for ")-1);
5519  } else if (!strncmp(name.c_str(), "vtable for ", sizeof("vtable for ")-1)) {
5520  name.erase(0, sizeof("vtable for ")-1);
5521  } else if (!strncmp(name.c_str(), "operator", sizeof("operator")-1)
5522  && !isalnum(name[sizeof("operator")])) {
5523  // operator...(A, B) - let's try with A!
5524  name.erase(0, sizeof("operator")-1);
5525  std::string::size_type pos = name.rfind('(');
5526  if (pos != std::string::npos) {
5527  name.erase(0, pos + 1);
5528  pos = name.find(",");
5529  if (pos != std::string::npos) {
5530  // remove next arg up to end, leaving only the first argument type.
5531  name.erase(pos);
5532  }
5533  pos = name.rfind(" const");
5534  if (pos != std::string::npos) {
5535  name.erase(pos, strlen(" const"));
5536  }
5537  while (!name.empty() && strchr("&*", name.back()))
5538  name.erase(name.length() - 1);
5539  }
5540  } else {
5541  // Remove the function arguments.
5542  std::string::size_type pos = name.rfind('(');
5543  if (pos != std::string::npos) {
5544  name.erase(pos);
5545  }
5546  // Remove the function name.
5547  pos = name.rfind(':');
5548  if (pos != std::string::npos) {
5549  if ((pos != 0) && (name[pos-1] == ':')) {
5550  name.erase(pos-1);
5551  }
5552  }
5553  }
5554  //fprintf(stderr, "name: '%s'\n", name.c_str());
5555  // Now we have the class or namespace name, so do the lookup.
5556  TString libs = GetClassSharedLibs(name.c_str());
5557  if (libs.IsNull()) {
5558  // Not found in the map, all done.
5559  return 0;
5560  }
5561  //fprintf(stderr, "library: %s\n", iter->second.c_str());
5562  // Now we have the name of the libraries to load, so load them.
5563 
5564  TString lib;
5565  Ssiz_t posLib = 0;
5566  while (libs.Tokenize(lib, posLib)) {
5567  if (gSystem->Load(lib, "", kFALSE /*system*/) < 0) {
5568  // The library load failed, all done.
5569  //fprintf(stderr, "load failed: %s\n", errmsg.c_str());
5570  return 0;
5571  }
5572  }
5573 
5574  //fprintf(stderr, "load succeeded.\n");
5575  // Get the address of the function being called.
5576  void* addr = llvm::sys::DynamicLibrary::SearchForAddressOfSymbol(mangled_name.c_str());
5577  //fprintf(stderr, "addr: %016lx\n", reinterpret_cast<unsigned long>(addr));
5578  return addr;
5579 }
5580 
5581 ////////////////////////////////////////////////////////////////////////////////
5582 
5584 {
5585 // if (fMapNamespaces){
5586 // return fMapNamespaces->FindObject(name);
5587 // }
5588  return false;
5589 }
5590 
5591 ////////////////////////////////////////////////////////////////////////////////
5592 
5593 Bool_t TCling::IsAutoLoadNamespaceCandidate(const clang::NamespaceDecl* nsDecl)
5594 {
5595  return fNSFromRootmaps.count(nsDecl) != 0;
5596 }
5597 
5598 ////////////////////////////////////////////////////////////////////////////////
5599 /// Internal function. Inform a TClass about its new TagDecl or NamespaceDecl.
5600 
5601 void TCling::UpdateClassInfoWithDecl(const void* vTD)
5602 {
5603  const NamedDecl* ND = static_cast<const NamedDecl*>(vTD);
5604  const TagDecl* td = dyn_cast<TagDecl>(ND);
5605  std::string name;
5606  TagDecl* tdDef = 0;
5607  if (td) {
5608  tdDef = td->getDefinition();
5609  // Let's pass the decl to the TClass only if it has a definition.
5610  if (!tdDef) return;
5611  td = tdDef;
5612  ND = td;
5613 
5614  if (llvm::isa<clang::FunctionDecl>(td->getDeclContext())) {
5615  // Ignore declaration within a function.
5616  return;
5617  }
5618  clang::QualType type( td->getTypeForDecl(), 0 );
5619 
5620  auto declName=ND->getNameAsString();
5621  if (!TClass::HasNoInfoOrEmuOrFwdDeclaredDecl(declName.c_str())){
5622 // 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 );
5623  return;
5624  }
5625 
5627  } else {
5628  name = ND->getNameAsString();
5629  }
5630 
5631  // Supposedly we are being called while something is being
5632  // loaded ... let's now tell the autoloader to do the work
5633  // yet another time.
5634  int storedAutoloading = SetClassAutoloading(false);
5635  // FIXME: There can be more than one TClass for a single decl.
5636  // for example vector<double> and vector<Double32_t>
5637  TClass* cl = (TClass*)gROOT->GetListOfClasses()->FindObject(name.c_str());
5638  if (cl && GetModTClasses().find(cl) == GetModTClasses().end()) {
5640  if (cci) {
5641  // If we only had a forward declaration then update the
5642  // TClingClassInfo with the definition if we have it now.
5643  const TagDecl* tdOld = llvm::dyn_cast_or_null<TagDecl>(cci->GetDecl());
5644  if (!tdOld || (tdDef && tdDef != tdOld)) {
5645  cl->ResetCaches();
5647  if (td) {
5648  // It's a tag decl, not a namespace decl.
5649  cci->Init(*cci->GetType());
5651  }
5652  }
5653  } else if (!cl->TestBit(TClass::kLoading) && !cl->fHasRootPcmInfo) {
5654  cl->ResetCaches();
5655  // yes, this is almost a waste of time, but we do need to lookup
5656  // the 'type' corresponding to the TClass anyway in order to
5657  // preserve the opaque typedefs (Double32_t)
5658  cl->fClassInfo = (ClassInfo_t *)new TClingClassInfo(fInterpreter, cl->GetName());
5659  // We now need to update the state and bits.
5660  if (cl->fState != TClass::kHasTClassInit) {
5661  // if (!cl->fClassInfo->IsValid()) cl->fState = TClass::kForwardDeclared; else
5664  }
5665  TClass::AddClassToDeclIdMap(((TClingClassInfo*)(cl->fClassInfo))->GetDeclId(), cl);
5666  }
5667  }
5668  SetClassAutoloading(storedAutoloading);
5669 }
5670 
5671 ////////////////////////////////////////////////////////////////////////////////
5672 /// No op: see TClingCallbacks
5673 
5674 void TCling::UpdateClassInfo(char* item, Long_t tagnum)
5675 {
5676 }
5677 
5678 //______________________________________________________________________________
5679 //FIXME: Factor out that function in TClass, because TClass does it already twice
5680 void TCling::UpdateClassInfoWork(const char* item)
5681 {
5682  // This is a no-op as part of the API.
5683  // TCling uses UpdateClassInfoWithDecl() instead.
5684 }
5685 
5686 ////////////////////////////////////////////////////////////////////////////////
5687 /// Update all canvases at end the terminal input command.
5688 
5690 {
5691  TIter next(gROOT->GetListOfCanvases());
5692  TVirtualPad* canvas;
5693  while ((canvas = (TVirtualPad*)next())) {
5694  canvas->Update();
5695  }
5696 }
5697 
5698 ////////////////////////////////////////////////////////////////////////////////
5699 
5700 void TCling::UpdateListsOnCommitted(const cling::Transaction &T) {
5701  std::set<TClass*> modifiedTClasses; // TClasses that require update after this transaction
5702 
5703  // If the transaction does not contain anything we can return earlier.
5704  if (!HandleNewTransaction(T)) return;
5705 
5706  bool isTUTransaction = false;
5707  if (!T.empty() && T.decls_begin() + 1 == T.decls_end() && !T.hasNestedTransactions()) {
5708  clang::Decl* FirstDecl = *(T.decls_begin()->m_DGR.begin());
5709  if (llvm::isa<clang::TranslationUnitDecl>(FirstDecl)) {
5710  // The is the first transaction, we have to expose to meta
5711  // what's already in the AST.
5712  isTUTransaction = true;
5713  }
5714  }
5715 
5716  std::set<const void*> TransactionDeclSet;
5717  if (!isTUTransaction && T.decls_end() - T.decls_begin()) {
5718  const clang::Decl* WrapperFD = T.getWrapperFD();
5719  for (cling::Transaction::const_iterator I = T.decls_begin(), E = T.decls_end();
5720  I != E; ++I) {
5721  if (I->m_Call != cling::Transaction::kCCIHandleTopLevelDecl
5722  && I->m_Call != cling::Transaction::kCCIHandleTagDeclDefinition)
5723  continue;
5724 
5725  for (DeclGroupRef::const_iterator DI = I->m_DGR.begin(),
5726  DE = I->m_DGR.end(); DI != DE; ++DI) {
5727  if (*DI == WrapperFD)
5728  continue;
5729  TransactionDeclSet.insert(*DI);
5730  ((TCling*)gCling)->HandleNewDecl(*DI, false, modifiedTClasses);
5731  }
5732  }
5733  }
5734 
5735  // The above might trigger more decls to be deserialized.
5736  // Thus the iteration over the deserialized decls must be last.
5737  for (cling::Transaction::const_iterator I = T.deserialized_decls_begin(),
5738  E = T.deserialized_decls_end(); I != E; ++I) {
5739  for (DeclGroupRef::const_iterator DI = I->m_DGR.begin(),
5740  DE = I->m_DGR.end(); DI != DE; ++DI)
5741  if (TransactionDeclSet.find(*DI) == TransactionDeclSet.end()) {
5742  //FIXME: HandleNewDecl should take DeclGroupRef
5743  ((TCling*)gCling)->HandleNewDecl(*DI, /*isDeserialized*/true,
5744  modifiedTClasses);
5745  }
5746  }
5747 
5748 
5749  // When fully building the reflection info in TClass, a deserialization
5750  // could be triggered, which may result in request for building the
5751  // reflection info for the same TClass. This in turn will clear the caches
5752  // for the TClass in-flight and cause null ptr derefs.
5753  // FIXME: This is a quick fix, solving most of the issues. The actual
5754  // question is: Shouldn't TClass provide a lock mechanism on update or lock
5755  // itself until the update is done.
5756  //
5757  std::vector<TClass*> modifiedTClassesDiff(modifiedTClasses.size());
5758  std::vector<TClass*>::iterator it;
5759  it = set_difference(modifiedTClasses.begin(), modifiedTClasses.end(),
5760  ((TCling*)gCling)->GetModTClasses().begin(),
5761  ((TCling*)gCling)->GetModTClasses().end(),
5762  modifiedTClassesDiff.begin());
5763  modifiedTClassesDiff.resize(it - modifiedTClassesDiff.begin());
5764 
5765  // Lock the TClass for updates
5766  ((TCling*)gCling)->GetModTClasses().insert(modifiedTClassesDiff.begin(),
5767  modifiedTClassesDiff.end());
5768  for (std::vector<TClass*>::const_iterator I = modifiedTClassesDiff.begin(),
5769  E = modifiedTClassesDiff.end(); I != E; ++I) {
5770  // Make sure the TClass has not been deleted.
5771  if (!gROOT->GetListOfClasses()->FindObject(*I)) {
5772  continue;
5773  }
5774  // Could trigger deserialization of decls.
5775  cling::Interpreter::PushTransactionRAII RAII(fInterpreter);
5776  // Unlock the TClass for updates
5777  ((TCling*)gCling)->GetModTClasses().erase(*I);
5778 
5779  }
5780 }
5781 
5782 ////////////////////////////////////////////////////////////////////////////////
5783 /// Helper function to go through the members of a class or namespace and unload them.
5784 
5785 void TCling::UnloadClassMembers(TClass* cl, const clang::DeclContext* DC) {
5786 
5787  TDataMember* var = 0;
5788  TFunction* function = 0;
5789  TEnum* e = 0;
5790  TFunctionTemplate* functiontemplate = 0;
5792  TListOfFunctions* functions = (TListOfFunctions*)cl->GetListOfMethods();
5793  TListOfEnums* enums = (TListOfEnums*)cl->GetListOfEnums();
5795  for (DeclContext::decl_iterator RI = DC->decls_begin(), RE = DC->decls_end(); RI != RE; ++RI) {
5796  if (isa<VarDecl>(*RI) || isa<FieldDecl>(*RI)) {
5797  const clang::ValueDecl* VD = dyn_cast<ValueDecl>(*RI);
5798  var = (TDataMember*)datamembers->FindObject(VD->getNameAsString().c_str());
5799  if (var) {
5800  // Unload the global by setting the DataMemberInfo_t to 0
5801  datamembers->Unload(var);
5802  var->Update(0);
5803  }
5804  } else if (const FunctionDecl* FD = dyn_cast<FunctionDecl>(*RI)) {
5805  function = (TFunction*)functions->FindObject(FD->getNameAsString().c_str());
5806  if (function) {
5807  functions->Unload(function);
5808  function->Update(0);
5809  }
5810  } else if (const EnumDecl* ED = dyn_cast<EnumDecl>(*RI)) {
5811  e = (TEnum*)enums->FindObject(ED->getNameAsString().c_str());
5812  if (e) {
5813  TIter iEnumConst(e->GetConstants());
5814  while (TEnumConstant* enumConst = (TEnumConstant*)iEnumConst()) {
5815  // Since the enum is already created and valid that ensures us that
5816  // we have the enum constants created as well.
5817  enumConst = (TEnumConstant*)datamembers->FindObject(enumConst->GetName());
5818  if (enumConst && enumConst->IsValid()) {
5819  datamembers->Unload(enumConst);
5820  enumConst->Update(0);
5821  }
5822  }
5823  enums->Unload(e);
5824  e->Update(0);
5825  }
5826  } else if (const FunctionTemplateDecl* FTD = dyn_cast<FunctionTemplateDecl>(*RI)) {
5827  functiontemplate = (TFunctionTemplate*)functiontemplates->FindObject(FTD->getNameAsString().c_str());
5828  if (functiontemplate) {
5829  functiontemplates->Unload(functiontemplate);
5830  functiontemplate->Update(0);
5831  }
5832  }
5833  }
5834 }
5835 
5836 ////////////////////////////////////////////////////////////////////////////////
5837 
5838 void TCling::UpdateListsOnUnloaded(const cling::Transaction &T)
5839 {
5841 
5842  // Unload the objects from the lists and update the objects' state.
5843  TListOfFunctions* functions = (TListOfFunctions*)gROOT->GetListOfGlobalFunctions();
5844  TListOfFunctionTemplates* functiontemplates = (TListOfFunctionTemplates*)gROOT->GetListOfFunctionTemplates();
5845  TListOfEnums* enums = (TListOfEnums*)gROOT->GetListOfEnums();
5846  TListOfDataMembers* globals = (TListOfDataMembers*)gROOT->GetListOfGlobals();
5847  cling::Transaction::const_nested_iterator iNested = T.nested_begin();
5848  for(cling::Transaction::const_iterator I = T.decls_begin(), E = T.decls_end();
5849  I != E; ++I) {
5850  if (I->m_Call == cling::Transaction::kCCIHandleVTable)
5851  continue;
5852 
5853  if (I->m_Call == cling::Transaction::kCCINone) {
5854  UpdateListsOnUnloaded(**iNested);
5855  ++iNested;
5856  continue;
5857  }
5858 
5859  for (DeclGroupRef::const_iterator DI = I->m_DGR.begin(),
5860  DE = I->m_DGR.end(); DI != DE; ++DI) {
5861 
5862  // Do not mark a decl as unloaded if we are going to keep it
5863  // (because it comes from the pch) ...
5864  if ( (*DI)->isFromASTFile() )
5865  continue;
5866 
5867  // Deal with global variables and global enum constants.
5868  if (isa<VarDecl>(*DI) || isa<EnumConstantDecl>(*DI)) {
5869  TObject *obj = globals->Find((TListOfDataMembers::DeclId_t)*DI);
5870  if (globals->GetClass()) {
5871  TDataMember* var = dynamic_cast<TDataMember*>(obj);
5872  if (var && var->IsValid()) {
5873  // Unload the global by setting the DataMemberInfo_t to 0
5874  globals->Unload(var);
5875  var->Update(0);
5876  }
5877  } else {
5878  TGlobal *g = dynamic_cast<TGlobal*>(obj);
5879  if (g && g->IsValid()) {
5880  // Unload the global by setting the DataMemberInfo_t to 0
5881  globals->Unload(g);
5882  g->Update(0);
5883  }
5884  }
5885  // Deal with global functions.
5886  } else if (const FunctionDecl* FD = dyn_cast<FunctionDecl>(*DI)) {
5887  TFunction* function = (TFunction*)functions->Find((TListOfFunctions::DeclId_t)FD);
5888  if (function && function->IsValid()) {
5889  functions->Unload(function);
5890  function->Update(0);
5891  }
5892  // Deal with global function templates.
5893  } else if (const FunctionTemplateDecl* FTD = dyn_cast<FunctionTemplateDecl>(*DI)) {
5894  TFunctionTemplate* functiontemplate = (TFunctionTemplate*)functiontemplates->FindObject(FTD->getNameAsString().c_str());
5895  if (functiontemplate) {
5896  functiontemplates->Unload(functiontemplate);
5897  functiontemplate->Update(0);
5898  }
5899  // Deal with global enums.
5900  } else if (const EnumDecl* ED = dyn_cast<EnumDecl>(*DI)) {
5901  if (TEnum* e = (TEnum*)enums->Find((TListOfEnums::DeclId_t)ED)) {
5902  globals = (TListOfDataMembers*)gROOT->GetListOfGlobals();
5903  TIter iEnumConst(e->GetConstants());
5904  while (TEnumConstant* enumConst = (TEnumConstant*)iEnumConst()) {
5905  // Since the enum is already created and valid that ensures us that
5906  // we have the enum constants created as well.
5907  enumConst = (TEnumConstant*)globals->FindObject(enumConst->GetName());
5908  if (enumConst) {
5909  globals->Unload(enumConst);
5910  enumConst->Update(0);
5911  }
5912  }
5913  enums->Unload(e);
5914  e->Update(0);
5915  }
5916  // Deal with classes. Unload the class and the data members will be not accessible anymore
5917  // Cannot declare the members in a different declaration like redeclarable namespaces.
5918  } else if (const clang::RecordDecl* RD = dyn_cast<RecordDecl>(*DI)) {
5919  std::vector<TClass*> vectTClass;
5920  // Only update the TClass if the definition is being unloaded.
5921  if (RD->isCompleteDefinition()) {
5922  if (TClass::GetClass(RD, vectTClass)) {
5923  for (std::vector<TClass*>::iterator CI = vectTClass.begin(), CE = vectTClass.end();
5924  CI != CE; ++CI) {
5925  UnloadClassMembers((*CI), RD);
5926  (*CI)->ResetClassInfo();
5927  }
5928  }
5929  }
5930  // Deal with namespaces. Unload the members of the current redeclaration only.
5931  } else if (const clang::NamespaceDecl* ND = dyn_cast<NamespaceDecl>(*DI)) {
5932  std::vector<TClass*> vectTClass;
5933  if (TClass::GetClass(ND->getCanonicalDecl(), vectTClass)) {
5934  for (std::vector<TClass*>::iterator CI = vectTClass.begin(), CE = vectTClass.end();
5935  CI != CE; ++CI) {
5936  UnloadClassMembers((*CI), ND);
5937  if (ND->isOriginalNamespace()) {
5938  (*CI)->ResetClassInfo();
5939  }
5940  }
5941  }
5942  }
5943  }
5944  }
5945 }
5946 
5947 ////////////////////////////////////////////////////////////////////////////////
5948 // If an autoparse was done during a transaction and that it is rolled back,
5949 // we need to make sure the next request for the same autoparse will be
5950 // honored.
5951 void TCling::TransactionRollback(const cling::Transaction &T) {
5952  auto const &triter = fTransactionHeadersMap.find(&T);
5953  if (triter != fTransactionHeadersMap.end()) {
5954  std::size_t normNameHash = triter->second;
5955 
5956  fLookedUpClasses.erase(normNameHash);
5957 
5958  auto const &iter = fClassesHeadersMap.find(normNameHash);
5959  if (iter != fClassesHeadersMap.end()) {
5960  auto const &hNamesPtrs = iter->second;
5961  for (auto &hName : hNamesPtrs) {
5962  if (gDebug > 0) {
5963  Info("TransactionRollback",
5964  "Restoring ability to autoaparse: %s", hName);
5965  }
5966  fParsedPayloadsAddresses.erase(hName);
5967  }
5968  }
5969  }
5970 }
5971 
5972 ////////////////////////////////////////////////////////////////////////////////
5973 
5974 void TCling::LibraryLoaded(const void* dyLibHandle, const char* canonicalName) {
5975 // UpdateListOfLoadedSharedLibraries();
5976 }
5977 
5978 ////////////////////////////////////////////////////////////////////////////////
5979 
5980 void TCling::LibraryUnloaded(const void* dyLibHandle, const char* canonicalName) {
5982  fSharedLibs = "";
5983 }
5984 
5985 ////////////////////////////////////////////////////////////////////////////////
5986 /// Return the list of shared libraries loaded into the process.
5987 
5988 const char* TCling::GetSharedLibs()
5989 {
5990  if (!fPrevLoadedDynLibInfo && fSharedLibs.IsNull())
5992  return fSharedLibs;
5993 }
5994 
5995 ////////////////////////////////////////////////////////////////////////////////
5996 /// Get the list of shared libraries containing the code for class cls.
5997 /// The first library in the list is the one containing the class, the
5998 /// others are the libraries the first one depends on. Returns 0
5999 /// in case the library is not found.
6000 
6001 const char* TCling::GetClassSharedLibs(const char* cls)
6002 {
6003  if (!cls || !*cls) {
6004  return 0;
6005  }
6006  // lookup class to find list of libraries
6007  if (fMapfile) {
6008  TEnvRec* libs_record = 0;
6009  libs_record = fMapfile->Lookup(cls);
6010  if (libs_record) {
6011  const char* libs = libs_record->GetValue();
6012  return (*libs) ? libs : 0;
6013  }
6014  else {
6015  // Try the old format...
6016  TString c = TString("Library.") + cls;
6017  // convert "::" to "@@", we used "@@" because TEnv
6018  // considers "::" a terminator
6019  c.ReplaceAll("::", "@@");
6020  // convert "-" to " ", since class names may have
6021  // blanks and TEnv considers a blank a terminator
6022  c.ReplaceAll(" ", "-");
6023  // Use TEnv::Lookup here as the rootmap file must start with Library.
6024  // and do not support using any stars (so we do not need to waste time
6025  // with the search made by TEnv::GetValue).
6026  TEnvRec* libs_record = 0;
6027  libs_record = fMapfile->Lookup(c);
6028  if (libs_record) {
6029  const char* libs = libs_record->GetValue();
6030  return (*libs) ? libs : 0;
6031  }
6032  }
6033  }
6034  return 0;
6035 }
6036 
6037 ////////////////////////////////////////////////////////////////////////////////
6038 /// Get the list a libraries on which the specified lib depends. The
6039 /// returned string contains as first element the lib itself.
6040 /// Returns 0 in case the lib does not exist or does not have
6041 /// any dependencies.
6042 
6043 const char* TCling::GetSharedLibDeps(const char* lib)
6044 {
6045  if (!fMapfile || !lib || !lib[0]) {
6046  return 0;
6047  }
6048  TString libname(lib);
6049  Ssiz_t idx = libname.Last('.');
6050  if (idx != kNPOS) {
6051  libname.Remove(idx);
6052  }
6053  TEnvRec* rec;
6054  TIter next(fMapfile->GetTable());
6055  size_t len = libname.Length();
6056  while ((rec = (TEnvRec*) next())) {
6057  const char* libs = rec->GetValue();
6058  if (!strncmp(libs, libname.Data(), len) && strlen(libs) >= len
6059  && (!libs[len] || libs[len] == ' ' || libs[len] == '.')) {
6060  return libs;
6061  }
6062  }
6063  return 0;
6064 }
6065 
6066 ////////////////////////////////////////////////////////////////////////////////
6067 /// If error messages are disabled, the interpreter should suppress its
6068 /// failures and warning messages from stdout.
6069 
6071 {
6072 #if defined(R__MUST_REVISIT)
6073 #if R__MUST_REVISIT(6,2)
6074  Warning("IsErrorMessagesEnabled", "Interface not available yet.");
6075 #endif
6076 #endif
6077  return kTRUE;
6078 }
6079 
6080 ////////////////////////////////////////////////////////////////////////////////
6081 /// If error messages are disabled, the interpreter should suppress its
6082 /// failures and warning messages from stdout. Return the previous state.
6083 
6085 {
6086 #if defined(R__MUST_REVISIT)
6087 #if R__MUST_REVISIT(6,2)
6088  Warning("SetErrorMessages", "Interface not available yet.");
6089 #endif
6090 #endif
6092 }
6093 
6094 ////////////////////////////////////////////////////////////////////////////////
6095 /// Refresh the list of include paths known to the interpreter and return it
6096 /// with -I prepended.
6097 
6098 const char* TCling::GetIncludePath()
6099 {
6101 
6102  fIncludePath = "";
6103 
6104  llvm::SmallVector<std::string, 10> includePaths;//Why 10? Hell if I know.
6105  //false - no system header, true - with flags.
6106  fInterpreter->GetIncludePaths(includePaths, false, true);
6107  if (const size_t nPaths = includePaths.size()) {
6108  assert(!(nPaths & 1) && "GetIncludePath, number of paths and options is not equal");
6109 
6110  for (size_t i = 0; i < nPaths; i += 2) {
6111  if (i)
6112  fIncludePath.Append(' ');
6113  fIncludePath.Append(includePaths[i].c_str());
6114 
6115  if (includePaths[i] != "-I")
6116  fIncludePath.Append(' ');
6117  fIncludePath.Append('"');
6118  fIncludePath.Append(includePaths[i + 1], includePaths[i + 1].length());
6119  fIncludePath.Append('"');
6120  }
6121  }
6122 
6123  return fIncludePath;
6124 }
6125 
6126 ////////////////////////////////////////////////////////////////////////////////
6127 /// Return the directory containing CINT's stl cintdlls.
6128 
6129 const char* TCling::GetSTLIncludePath() const
6131  return "";
6132 }
6133 
6134 //______________________________________________________________________________
6135 // M I S C
6136 //______________________________________________________________________________
6137 
6138 int TCling::DisplayClass(FILE* /*fout*/, const char* /*name*/, int /*base*/, int /*start*/) const
6139 {
6140  // Interface to cling function
6141  return 0;
6142 }
6143 
6144 ////////////////////////////////////////////////////////////////////////////////
6145 /// Interface to cling function
6146 
6147 int TCling::DisplayIncludePath(FILE *fout) const
6148 {
6149  assert(fout != 0 && "DisplayIncludePath, 'fout' parameter is null");
6150 
6151  llvm::SmallVector<std::string, 10> includePaths;//Why 10? Hell if I know.
6152  //false - no system header, true - with flags.
6153  fInterpreter->GetIncludePaths(includePaths, false, true);
6154  if (const size_t nPaths = includePaths.size()) {
6155  assert(!(nPaths & 1) && "DisplayIncludePath, number of paths and options is not equal");
6156 
6157  std::string allIncludes("include path:");
6158  for (size_t i = 0; i < nPaths; i += 2) {
6159  allIncludes += ' ';
6160  allIncludes += includePaths[i];
6161 
6162  if (includePaths[i] != "-I")
6163  allIncludes += ' ';
6164  allIncludes += includePaths[i + 1];
6165  }
6166 
6167  fprintf(fout, "%s\n", allIncludes.c_str());
6168  }
6169 
6170  return 0;
6171 }
6172 
6173 ////////////////////////////////////////////////////////////////////////////////
6174 /// Interface to cling function
6176 void* TCling::FindSym(const char* entry) const
6177 {
6178  return fInterpreter->getAddressOfGlobal(entry);
6179 }
6180 
6181 ////////////////////////////////////////////////////////////////////////////////
6182 /// Let the interpreter issue a generic error, and set its error state.
6183 
6184 void TCling::GenericError(const char* error) const
6185 {
6186 #if defined(R__MUST_REVISIT)
6187 #if R__MUST_REVISIT(6,2)
6188  Warning("GenericError","Interface not available yet.");
6189 #endif
6190 #endif
6191 }
6192 
6193 ////////////////////////////////////////////////////////////////////////////////
6194 /// This routines used to return the address of the internal wrapper
6195 /// function (of the interpreter) that was used to call *all* the
6196 /// interpreted functions that were bytecode compiled (no longer
6197 /// interpreted line by line). In Cling, there is no such
6198 /// wrapper function.
6199 /// In practice this routines was use to decipher whether the
6200 /// pointer returns by InterfaceMethod could be used to uniquely
6201 /// represent the function. In Cling if the function is in a
6202 /// useable state (its compiled version is available), this is
6203 /// always the case.
6204 /// See TClass::GetMethod.
6205 
6207 {
6208  return 0;
6209 }
6210 
6211 ////////////////////////////////////////////////////////////////////////////////
6212 /// Interface to the CINT global object pointer which was controlling the
6213 /// behavior of the wrapper around the calls to operator new and the constructor
6214 /// and operator delete and the destructor.
6215 
6216 Long_t TCling::Getgvp() const
6217 {
6218  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.");
6219  return 0;
6220 }
6221 
6222 ////////////////////////////////////////////////////////////////////////////////
6223 
6224 const char* TCling::Getp2f2funcname(void*) const
6225 {
6226  Error("Getp2f2funcname", "Will not be implemented: "
6227  "all function pointers are compiled!");
6228  return NULL;
6229 }
6231 ////////////////////////////////////////////////////////////////////////////////
6232 /// Interface to cling function
6233 
6234 int TCling::GetSecurityError() const
6235 {
6236 #if defined(R__MUST_REVISIT)
6237 #if R__MUST_REVISIT(6,2)
6238  Warning("GetSecurityError", "Interface not available yet.");
6239 #endif
6240 #endif
6241  return 0;
6242 }
6243 
6244 ////////////////////////////////////////////////////////////////////////////////
6245 /// Load a source file or library called path into the interpreter.
6246 
6247 int TCling::LoadFile(const char* path) const
6248 {
6249  cling::Interpreter::CompilationResult compRes;
6250  cling::MetaProcessor::MaybeRedirectOutputRAII RAII(fMetaProcessor);
6251  HandleInterpreterException(fMetaProcessor, TString::Format(".L %s", path), compRes, /*cling::Value*/0);
6252  return compRes == cling::Interpreter::kFailure;
6253 }
6254 
6255 ////////////////////////////////////////////////////////////////////////////////
6256 /// Load the declarations from text into the interpreter.
6257 /// Note that this cannot be (top level) statements; text must contain
6258 /// top level declarations.
6259 /// Returns true on success, false on failure.
6260 
6261 Bool_t TCling::LoadText(const char* text) const
6263  return (fInterpreter->declare(text) == cling::Interpreter::kSuccess);
6264 }
6265 
6266 ////////////////////////////////////////////////////////////////////////////////
6267 /// Interface to cling function
6268 
6269 const char* TCling::MapCppName(const char* name) const
6271  TTHREAD_TLS_DECL(std::string,buffer);
6272  ROOT::TMetaUtils::GetCppName(buffer,name);
6273  return buffer.c_str();
6274 }
6275 
6276 ////////////////////////////////////////////////////////////////////////////////
6277 /// [Place holder for Mutex Lock]
6278 /// Provide the interpreter with a way to
6279 /// acquire a lock used to protect critical section
6280 /// of its code (non-thread safe parts).
6281 
6282 void TCling::SetAlloclockfunc(void (* /* p */ )()) const
6283 {
6284  // nothing to do for now.
6285 }
6286 
6287 ////////////////////////////////////////////////////////////////////////////////
6288 /// [Place holder for Mutex Unlock] Provide the interpreter with a way to
6289 /// release a lock used to protect critical section
6290 /// of its code (non-thread safe parts).
6291 
6292 void TCling::SetAllocunlockfunc(void (* /* p */ )()) const
6294  // nothing to do for now.
6295 }
6296 
6297 ////////////////////////////////////////////////////////////////////////////////
6298 /// Enable/Disable the Autoloading of libraries.
6299 /// Returns the old value, i.e whether it was enabled or not.
6300 
6301 int TCling::SetClassAutoloading(int autoload) const
6302 {
6303  if (!autoload && !fClingCallbacks) return false;
6304  if (!fAllowLibLoad) return false;
6305 
6306  assert(fClingCallbacks && "We must have callbacks!");
6309  return oldVal;
6310 }
6311 
6312 ////////////////////////////////////////////////////////////////////////////////
6313 /// Enable/Disable the Autoparsing of headers.
6314 /// Returns the old value, i.e whether it was enabled or not.
6316 int TCling::SetClassAutoparsing(int autoparse)
6317 {
6318  bool oldVal = fHeaderParsingOnDemand;
6319  fHeaderParsingOnDemand = autoparse;
6320  return oldVal;
6321 }
6322 
6323 ////////////////////////////////////////////////////////////////////////////////
6324 /// Suspend the Autoparsing of headers.
6325 /// Returns the old value, i.e whether it was suspended or not.
6326 
6329  fIsAutoParsingSuspended = value;
6331  return old;
6332 }
6333 
6334 ////////////////////////////////////////////////////////////////////////////////
6335 /// Set a callback to receive error messages.
6336 
6337 void TCling::SetErrmsgcallback(void* p) const
6339 #if defined(R__MUST_REVISIT)
6340 #if R__MUST_REVISIT(6,2)
6341  Warning("SetErrmsgcallback", "Interface not available yet.");
6342 #endif
6343 #endif
6344 }
6345 
6346 ////////////////////////////////////////////////////////////////////////////////
6347 /// Interface to the cling global object pointer which was controlling the
6348 /// behavior of the wrapper around the calls to operator new and the constructor
6349 /// and operator delete and the destructor.
6350 
6351 void TCling::Setgvp(Long_t gvp) const
6352 {
6353  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.");
6354 
6355 }
6356 
6357 ////////////////////////////////////////////////////////////////////////////////
6358 
6359 void TCling::SetRTLD_NOW() const
6360 {
6361  Error("SetRTLD_NOW()", "Will never be implemented! Don't use!");
6363 
6364 ////////////////////////////////////////////////////////////////////////////////
6365 
6366 void TCling::SetRTLD_LAZY() const
6367 {
6368  Error("SetRTLD_LAZY()", "Will never be implemented! Don't use!");
6369 }
6370 
6371 ////////////////////////////////////////////////////////////////////////////////
6372 /// Create / close a scope for temporaries. No-op for cling; use
6373 /// cling::Value instead.
6374 
6375 void TCling::SetTempLevel(int val) const
6376 {
6377 }
6378 
6379 ////////////////////////////////////////////////////////////////////////////////
6380 
6381 int TCling::UnloadFile(const char* path) const
6382 {
6383  cling::DynamicLibraryManager* DLM = fInterpreter->getDynamicLibraryManager();
6384  std::string canonical = DLM->lookupLibrary(path);
6385  if (canonical.empty()) {
6386  canonical = path;
6387  }
6388  // Unload a shared library or a source file.
6389  cling::Interpreter::CompilationResult compRes;
6390  cling::MetaProcessor::MaybeRedirectOutputRAII RAII(fMetaProcessor);
6391  HandleInterpreterException(fMetaProcessor, Form(".U %s", canonical.c_str()), compRes, /*cling::Value*/0);
6392  return compRes == cling::Interpreter::kFailure;
6393 }
6394 
6395 ////////////////////////////////////////////////////////////////////////////////
6396 /// The created temporary must be deleted by the caller.
6399 {
6400  TClingValue *val = new TClingValue;
6401  return val;
6402 }
6403 
6404 ////////////////////////////////////////////////////////////////////////////////
6405 /// The call to Cling's tab complition.
6406 
6407 void TCling::CodeComplete(const std::string& line, size_t& cursor,
6408  std::vector<std::string>& completions)
6409 {
6410  fInterpreter->codeComplete(line, cursor, completions);
6411 }
6413 ////////////////////////////////////////////////////////////////////////////////
6414 /// Get the interpreter value corresponding to the statement.
6415 int TCling::Evaluate(const char* code, TInterpreterValue& value)
6416 {
6417  auto V = reinterpret_cast<cling::Value*>(value.GetValAddr());
6418  auto interpreter = this->GetInterpreter();
6419  auto compRes = interpreter->evaluate(code, *V);
6420  return compRes!=cling::Interpreter::kSuccess ? 0 : 1 ;
6422 
6423 ////////////////////////////////////////////////////////////////////////////////
6424 
6426 {
6427  using namespace cling;
6428  const Value* V = reinterpret_cast<const Value*>(value.GetValAddr());
6429  RegisterTemporary(*V);
6430 }
6431 
6432 ////////////////////////////////////////////////////////////////////////////////
6433 /// Register value as a temporary, extending its lifetime to that of the
6434 /// interpreter. This is needed for TCling's compatibility interfaces
6435 /// returning long - the address of the temporary objects.
6436 /// As such, "simple" types don't need to be stored; they are returned by
6437 /// value; only pointers / references / objects need to be stored.
6438 
6439 void TCling::RegisterTemporary(const cling::Value& value)
6440 {
6441  if (value.isValid() && value.needsManagedAllocation()) {
6443  fTemporaries->push_back(value);
6444  }
6445 }
6446 
6447 ////////////////////////////////////////////////////////////////////////////////
6448 /// If the interpreter encounters Name, check whether that is an object ROOT
6449 /// could retrieve. To not re-read objects from disk, cache the name/object
6450 /// pair for a given LookupCtx.
6451 
6452 TObject* TCling::GetObjectAddress(const char *Name, void *&LookupCtx)
6454  cling::Interpreter *interpreter = ((TCling*)gCling)->GetInterpreter();
6455 
6456  // The call to FindSpecialObject might induces any kind of use
6457  // of the interpreter ... (library loading, function calling, etc.)
6458  // ... and we _know_ we are in the middle of parsing, so let's make
6459  // sure to save the state and then restore it.
6460 
6461  if (gDirectory) {
6462  auto iSpecObjMap = fSpecialObjectMaps.find(gDirectory);
6463  if (iSpecObjMap != fSpecialObjectMaps.end()) {
6464  auto iSpecObj = iSpecObjMap->second.find(Name);
6465  if (iSpecObj != iSpecObjMap->second.end()) {
6466  LookupCtx = gDirectory;
6467  return iSpecObj->second;
6468  }
6469  }
6470  }
6472  // Save state of the PP
6473  Sema &SemaR = interpreter->getSema();
6474  ASTContext& C = SemaR.getASTContext();
6475  Preprocessor &PP = SemaR.getPreprocessor();
6476  Parser& P = const_cast<Parser&>(interpreter->getParser());
6477  Preprocessor::CleanupAndRestoreCacheRAII cleanupRAII(PP);
6478  Parser::ParserCurTokRestoreRAII savedCurToken(P);
6479  // After we have saved the token reset the current one to something which
6480  // is safe (semi colon usually means empty decl)
6481  Token& Tok = const_cast<Token&>(P.getCurToken());
6482  Tok.setKind(tok::semi);
6483 
6484  // We can't PushDeclContext, because we go up and the routine that pops
6485  // the DeclContext assumes that we drill down always.
6486  // We have to be on the global context. At that point we are in a
6487  // wrapper function so the parent context must be the global.
6488  Sema::ContextAndScopeRAII pushedDCAndS(SemaR, C.getTranslationUnitDecl(),
6489  SemaR.TUScope);
6490 
6491  TObject* specObj = gROOT->FindSpecialObject(Name, LookupCtx);
6492  if (specObj) {
6493  if (!LookupCtx) {
6494  Error("GetObjectAddress", "Got a special object without LookupCtx!");
6495  } else {
6496  fSpecialObjectMaps[LookupCtx][Name] = specObj;
6497  }
6498  }
6499  return specObj;
6500 }
6501 
6502 ////////////////////////////////////////////////////////////////////////////////
6503 /// Inject function as a friend into klass.
6504 /// With function being f in void f() {new N::PrivKlass(); } this enables
6505 /// I/O of non-public classes.
6506 
6507 void TCling::AddFriendToClass(clang::FunctionDecl* function,
6508  clang::CXXRecordDecl* klass) const
6509 {
6510  using namespace clang;
6511  ASTContext& Ctx = klass->getASTContext();
6512  FriendDecl::FriendUnion friendUnion(function);
6513  // one dummy object for the source location
6514  SourceLocation sl;
6515  FriendDecl* friendDecl = FriendDecl::Create(Ctx, klass, sl, friendUnion, sl);
6516  klass->pushFriendDecl(friendDecl);
6517 }
6518 
6519 //______________________________________________________________________________
6520 //
6521 // DeclId getter.
6522 //
6523 
6524 ////////////////////////////////////////////////////////////////////////////////
6525 /// Return a unique identifier of the declaration represented by the
6526 /// CallFunc
6527 
6529 {
6530  if (func) return ((TClingCallFunc*)func)->GetDecl()->getCanonicalDecl();
6531  return 0;
6532 }
6533 
6534 ////////////////////////////////////////////////////////////////////////////////
6535 /// Return a (almost) unique identifier of the declaration represented by the
6536 /// ClassInfo. In ROOT, this identifier can point to more than one TClass
6537 /// when the underlying class is a template instance involving one of the
6538 /// opaque typedef.
6539 
6540 TInterpreter::DeclId_t TCling::GetDeclId(ClassInfo_t* cinfo) const
6541 {
6542  if (cinfo) return ((TClingClassInfo*)cinfo)->GetDeclId();
6543  return 0;
6544 }
6545 
6546 ////////////////////////////////////////////////////////////////////////////////
6547 /// Return a unique identifier of the declaration represented by the
6548 /// MethodInfo
6549 
6550 TInterpreter::DeclId_t TCling::GetDeclId(DataMemberInfo_t* data) const
6551 {
6552  if (data) return ((TClingDataMemberInfo*)data)->GetDeclId();
6553  return 0;
6554 }
6555 
6556 ////////////////////////////////////////////////////////////////////////////////
6557 /// Return a unique identifier of the declaration represented by the
6558 /// MethodInfo
6559 
6560 TInterpreter::DeclId_t TCling::GetDeclId(MethodInfo_t* method) const
6561 {
6562  if (method) return ((TClingMethodInfo*)method)->GetDeclId();
6563  return 0;
6564 }
6565 
6566 ////////////////////////////////////////////////////////////////////////////////
6567 /// Return a unique identifier of the declaration represented by the
6568 /// TypedefInfo
6569 
6570 TInterpreter::DeclId_t TCling::GetDeclId(TypedefInfo_t* tinfo) const
6571 {
6572  if (tinfo) return ((TClingTypedefInfo*)tinfo)->GetDecl()->getCanonicalDecl();
6573  return 0;
6575 
6576 //______________________________________________________________________________
6577 //
6578 // CallFunc interface
6579 //
6580 
6581 ////////////////////////////////////////////////////////////////////////////////
6582 
6583 void TCling::CallFunc_Delete(CallFunc_t* func) const
6584 {
6585  delete (TClingCallFunc*) func;
6587 
6588 ////////////////////////////////////////////////////////////////////////////////
6589 
6590 void TCling::CallFunc_Exec(CallFunc_t* func, void* address) const
6591 {
6592  TClingCallFunc* f = (TClingCallFunc*) func;
6593  f->Exec(address);
6594 }
6595 
6596 ////////////////////////////////////////////////////////////////////////////////
6597 
6598 void TCling::CallFunc_Exec(CallFunc_t* func, void* address, TInterpreterValue& val) const
6599 {
6600  TClingCallFunc* f = (TClingCallFunc*) func;
6601  f->Exec(address, &val);
6602 }
6603 
6604 ////////////////////////////////////////////////////////////////////////////////
6605 
6606 void TCling::CallFunc_ExecWithReturn(CallFunc_t* func, void* address, void* ret) const
6607 {
6608  TClingCallFunc* f = (TClingCallFunc*) func;
6609  f->ExecWithReturn(address, ret);
6610 }
6611 
6612 ////////////////////////////////////////////////////////////////////////////////
6613 
6614 void TCling::CallFunc_ExecWithArgsAndReturn(CallFunc_t* func, void* address,
6615  const void* args[] /*=0*/,
6616  int nargs /*=0*/,
6617  void* ret/*=0*/) const
6618 {
6619  TClingCallFunc* f = (TClingCallFunc*) func;
6620  f->ExecWithArgsAndReturn(address, args, nargs, ret);
6621 }
6622 
6623 ////////////////////////////////////////////////////////////////////////////////
6624 
6625 Long_t TCling::CallFunc_ExecInt(CallFunc_t* func, void* address) const
6626 {
6627  TClingCallFunc* f = (TClingCallFunc*) func;
6628  return f->ExecInt(address);
6630 
6631 ////////////////////////////////////////////////////////////////////////////////
6632 
6633 Long64_t TCling::CallFunc_ExecInt64(CallFunc_t* func, void* address) const
6634 {
6635  TClingCallFunc* f = (TClingCallFunc*) func;
6636  return f->ExecInt64(address);
6637 }
6638 
6639 ////////////////////////////////////////////////////////////////////////////////
6640 
6641 Double_t TCling::CallFunc_ExecDouble(CallFunc_t* func, void* address) const
6642 {
6643  TClingCallFunc* f = (TClingCallFunc*) func;
6644  return f->ExecDouble(address);
6645 }
6646 
6647 ////////////////////////////////////////////////////////////////////////////////
6648 
6649 CallFunc_t* TCling::CallFunc_Factory() const
6650 {
6652  return (CallFunc_t*) new TClingCallFunc(fInterpreter,*fNormalizedCtxt);
6653 }
6654 
6655 ////////////////////////////////////////////////////////////////////////////////
6656 
6657 CallFunc_t* TCling::CallFunc_FactoryCopy(CallFunc_t* func) const
6658 {
6659  return (CallFunc_t*) new TClingCallFunc(*(TClingCallFunc*)func);
6661 
6662 ////////////////////////////////////////////////////////////////////////////////
6663 
6664 MethodInfo_t* TCling::CallFunc_FactoryMethod(CallFunc_t* func) const
6665 {
6666  TClingCallFunc* f = (TClingCallFunc*) func;
6667  return (MethodInfo_t*) f->FactoryMethod();
6668 }
6669 
6670 ////////////////////////////////////////////////////////////////////////////////
6672 void TCling::CallFunc_IgnoreExtraArgs(CallFunc_t* func, bool ignore) const
6673 {
6674  TClingCallFunc* f = (TClingCallFunc*) func;
6675  f->IgnoreExtraArgs(ignore);
6676 }
6677 
6678 ////////////////////////////////////////////////////////////////////////////////
6680 void TCling::CallFunc_Init(CallFunc_t* func) const
6681 {
6683  TClingCallFunc* f = (TClingCallFunc*) func;
6684  f->Init();
6685 }
6686 
6687 ////////////////////////////////////////////////////////////////////////////////
6688 
6689 bool TCling::CallFunc_IsValid(CallFunc_t* func) const
6690 {
6691  TClingCallFunc* f = (TClingCallFunc*) func;
6692  return f->IsValid();
6693 }
6694 
6695 ////////////////////////////////////////////////////////////////////////////////
6696 
6698 TCling::CallFunc_IFacePtr(CallFunc_t * func) const
6699 {
6700  TClingCallFunc* f = (TClingCallFunc*) func;
6701  return f->IFacePtr();
6702 }
6704 ////////////////////////////////////////////////////////////////////////////////
6705 
6706 void TCling::CallFunc_ResetArg(CallFunc_t* func) const
6707 {
6708  TClingCallFunc* f = (TClingCallFunc*) func;
6709  f->ResetArg();
6711 
6712 ////////////////////////////////////////////////////////////////////////////////
6713 
6714 void TCling::CallFunc_SetArg(CallFunc_t* func, Long_t param) const
6715 {
6716  TClingCallFunc* f = (TClingCallFunc*) func;
6717  f->SetArg(param);
6719 
6720 ////////////////////////////////////////////////////////////////////////////////
6721 
6722 void TCling::CallFunc_SetArg(CallFunc_t* func, ULong_t param) const
6723 {
6724  TClingCallFunc* f = (TClingCallFunc*) func;
6725  f->SetArg(param);
6727 
6728 ////////////////////////////////////////////////////////////////////////////////
6729 
6730 void TCling::CallFunc_SetArg(CallFunc_t* func, Float_t param) const
6731 {
6732  TClingCallFunc* f = (TClingCallFunc*) func;
6733  f->SetArg(param);
6734 }
6736 ////////////////////////////////////////////////////////////////////////////////
6737 
6738 void TCling::CallFunc_SetArg(CallFunc_t* func, Double_t param) const
6739 {
6740  TClingCallFunc* f = (TClingCallFunc*) func;
6741  f->SetArg(param);
6742 }
6743 
6744 ////////////////////////////////////////////////////////////////////////////////
6745 
6746 void TCling::CallFunc_SetArg(CallFunc_t* func, Long64_t param) const
6747 {
6748  TClingCallFunc* f = (TClingCallFunc*) func;
6749  f->SetArg(param);
6750 }
6751 
6752 ////////////////////////////////////////////////////////////////////////////////
6753 
6754 void TCling::CallFunc_SetArg(CallFunc_t* func, ULong64_t param) const
6755 {
6756  TClingCallFunc* f = (TClingCallFunc*) func;
6757  f->SetArg(param);
6758 }
6759 
6760 ////////////////////////////////////////////////////////////////////////////////
6761 
6762 void TCling::CallFunc_SetArgArray(CallFunc_t* func, Long_t* paramArr, Int_t nparam) const
6763 {
6764  TClingCallFunc* f = (TClingCallFunc*) func;
6765  f->SetArgArray(paramArr, nparam);
6766 }
6767 
6768 ////////////////////////////////////////////////////////////////////////////////
6769 
6770 void TCling::CallFunc_SetArgs(CallFunc_t* func, const char* param) const
6771 {
6772  TClingCallFunc* f = (TClingCallFunc*) func;
6773  f->SetArgs(param);
6774 }
6775 
6776 ////////////////////////////////////////////////////////////////////////////////
6777 
6778 void TCling::CallFunc_SetFunc(CallFunc_t* func, ClassInfo_t* info, const char* method, const char* params, Long_t* offset) const
6779 {
6780  TClingCallFunc* f = (TClingCallFunc*) func;
6781  TClingClassInfo* ci = (TClingClassInfo*) info;
6782  f->SetFunc(ci, method, params, offset);
6783 }
6785 ////////////////////////////////////////////////////////////////////////////////
6786 
6787 void TCling::CallFunc_SetFunc(CallFunc_t* func, ClassInfo_t* info, const char* method, const char* params, bool objectIsConst, Long_t* offset) const
6788 {
6789  TClingCallFunc* f = (TClingCallFunc*) func;
6790  TClingClassInfo* ci = (TClingClassInfo*) info;
6791  f->SetFunc(ci, method, params, objectIsConst, offset);
6793 ////////////////////////////////////////////////////////////////////////////////
6794 
6795 void TCling::CallFunc_SetFunc(CallFunc_t* func, MethodInfo_t* info) const
6796 {
6797  TClingCallFunc* f = (TClingCallFunc*) func;
6798  TClingMethodInfo* minfo = (TClingMethodInfo*) info;
6799  f->SetFunc(minfo);
6801 
6802 ////////////////////////////////////////////////////////////////////////////////
6803 /// Interface to cling function
6804 
6805 void TCling::CallFunc_SetFuncProto(CallFunc_t* func, ClassInfo_t* info, const char* method, const char* proto, Long_t* offset, EFunctionMatchMode mode /* = kConversionMatch */) const
6806 {
6807  TClingCallFunc* f = (TClingCallFunc*) func;
6809  f->SetFuncProto(ci, method, proto, offset, mode);
6810 }
6811 
6812 ////////////////////////////////////////////////////////////////////////////////
6813 /// Interface to cling function
6814 
6815 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
6817  TClingCallFunc* f = (TClingCallFunc*) func;
6818  TClingClassInfo* ci = (TClingClassInfo*) info;
6819  f->SetFuncProto(ci, method, proto, objectIsConst, offset, mode);
6820 }
6821 
6822 ////////////////////////////////////////////////////////////////////////////////
6823 /// Interface to cling function
6825 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
6826 {
6827  TClingCallFunc* f = (TClingCallFunc*) func;
6828  TClingClassInfo* ci = (TClingClassInfo*) info;
6829  llvm::SmallVector<clang::QualType, 4> funcProto;
6830  for (std::vector<TypeInfo_t*>::const_iterator iter = proto.begin(), end = proto.end();
6831  iter != end; ++iter) {
6832  funcProto.push_back( ((TClingTypeInfo*)(*iter))->GetQualType() );
6833  }
6834  f->SetFuncProto(ci, method, funcProto, offset, mode);
6835 }
6836 
6837 ////////////////////////////////////////////////////////////////////////////////
6838 /// Interface to cling function
6839 
6840 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
6842  TClingCallFunc* f = (TClingCallFunc*) func;
6843  TClingClassInfo* ci = (TClingClassInfo*) info;
6844  llvm::SmallVector<clang::QualType, 4> funcProto;
6845  for (std::vector<TypeInfo_t*>::const_iterator iter = proto.begin(), end = proto.end();
6846  iter != end; ++iter) {
6847  funcProto.push_back( ((TClingTypeInfo*)(*iter))->GetQualType() );
6848  }
6849  f->SetFuncProto(ci, method, funcProto, objectIsConst, offset, mode);
6850 }
6852 //______________________________________________________________________________
6853 //
6854 // ClassInfo interface
6855 //
6856 
6857 ////////////////////////////////////////////////////////////////////////////////
6858 /// Return true if the entity pointed to by 'declid' is declared in
6859 /// the context described by 'info'. If info is null, look into the
6860 /// global scope (translation unit scope).
6862 Bool_t TCling::ClassInfo_Contains(ClassInfo_t *info, DeclId_t declid) const
6863 {
6864  if (!declid) return kFALSE;
6865 
6866  const clang::Decl *scope;
6867  if (info) scope = ((TClingClassInfo*)info)->GetDecl();
6868  else scope = fInterpreter->getCI()->getASTContext().getTranslationUnitDecl();
6869 
6870  const clang::Decl *decl = reinterpret_cast<const clang::Decl*>(declid);
6871  const clang::DeclContext *ctxt = clang::Decl::castToDeclContext(scope);
6872  if (!decl || !ctxt) return kFALSE;
6873  if (decl->getDeclContext()->Equals(ctxt))
6874  return kTRUE;
6875  else if (decl->getDeclContext()->isTransparentContext() &&
6876  decl->getDeclContext()->getParent()->Equals(ctxt))
6877  return kTRUE;
6878  return kFALSE;
6879 }
6880 
6881 ////////////////////////////////////////////////////////////////////////////////
6882 
6883 Long_t TCling::ClassInfo_ClassProperty(ClassInfo_t* cinfo) const
6884 {
6885  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
6886  return TClinginfo->ClassProperty();
6887 }
6888 
6889 ////////////////////////////////////////////////////////////////////////////////
6890 
6891 void TCling::ClassInfo_Delete(ClassInfo_t* cinfo) const
6892 {
6893  delete (TClingClassInfo*) cinfo;
6894 }
6895 
6896 ////////////////////////////////////////////////////////////////////////////////
6897 
6898 void TCling::ClassInfo_Delete(ClassInfo_t* cinfo, void* arena) const
6899 {
6900  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
6901  TClinginfo->Delete(arena,*fNormalizedCtxt);
6902 }
6903 
6904 ////////////////////////////////////////////////////////////////////////////////
6905 
6906 void TCling::ClassInfo_DeleteArray(ClassInfo_t* cinfo, void* arena, bool dtorOnly) const
6907 {
6908  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
6909  TClinginfo->DeleteArray(arena, dtorOnly,*fNormalizedCtxt);
6910 }
6911 
6912 ////////////////////////////////////////////////////////////////////////////////
6913 
6914 void TCling::ClassInfo_Destruct(ClassInfo_t* cinfo, void* arena) const
6915 {
6916  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
6917  TClinginfo->Destruct(arena,*fNormalizedCtxt);
6918 }
6919 
6920 ////////////////////////////////////////////////////////////////////////////////
6921 
6922 ClassInfo_t* TCling::ClassInfo_Factory(Bool_t all) const
6923 {
6925  return (ClassInfo_t*) new TClingClassInfo(fInterpreter, all);
6926 }
6927 
6928 ////////////////////////////////////////////////////////////////////////////////
6930 ClassInfo_t* TCling::ClassInfo_Factory(ClassInfo_t* cinfo) const
6931 {
6932  return (ClassInfo_t*) new TClingClassInfo(*(TClingClassInfo*)cinfo);
6933 }
6934 
6935 ////////////////////////////////////////////////////////////////////////////////
6936 
6937 ClassInfo_t* TCling::ClassInfo_Factory(const char* name) const
6938 {
6940  return (ClassInfo_t*) new TClingClassInfo(fInterpreter, name);
6941 }
6942 
6943 ////////////////////////////////////////////////////////////////////////////////
6945 int TCling::ClassInfo_GetMethodNArg(ClassInfo_t* cinfo, const char* method, const char* proto, Bool_t objectIsConst /* = false */, EFunctionMatchMode mode /* = kConversionMatch */) const
6946 {
6947  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
6948  return TClinginfo->GetMethodNArg(method, proto, objectIsConst, mode);
6949 }
6950 
6951 ////////////////////////////////////////////////////////////////////////////////
6953 bool TCling::ClassInfo_HasDefaultConstructor(ClassInfo_t* cinfo) const
6954 {
6955  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
6956  return TClinginfo->HasDefaultConstructor();
6957 }
6958 
6959 ////////////////////////////////////////////////////////////////////////////////
6961 bool TCling::ClassInfo_HasMethod(ClassInfo_t* cinfo, const char* name) const
6962 {
6963  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
6964  return TClinginfo->HasMethod(name);
6965 }
6966 
6967 ////////////////////////////////////////////////////////////////////////////////
6969 void TCling::ClassInfo_Init(ClassInfo_t* cinfo, const char* name) const
6970 {
6972  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
6973  TClinginfo->Init(name);
6974 }
6975 
6976 ////////////////////////////////////////////////////////////////////////////////
6977 
6978 void TCling::ClassInfo_Init(ClassInfo_t* cinfo, int tagnum) const
6979 {
6981  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
6982  TClinginfo->Init(tagnum);
6984 
6985 ////////////////////////////////////////////////////////////////////////////////
6986 
6987 bool TCling::ClassInfo_IsBase(ClassInfo_t* cinfo, const char* name) const
6988 {
6989  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
6990  return TClinginfo->IsBase(name);
6992 
6993 ////////////////////////////////////////////////////////////////////////////////
6994 
6995 bool TCling::ClassInfo_IsEnum(const char* name) const
6996 {
6997  return TClingClassInfo::IsEnum(fInterpreter, name);
6998 }
7000 ////////////////////////////////////////////////////////////////////////////////
7001 
7002 bool TCling::ClassInfo_IsLoaded(ClassInfo_t* cinfo) const
7003 {
7004  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
7005  return TClinginfo->IsLoaded();
7006 }
7008 ////////////////////////////////////////////////////////////////////////////////
7009 
7010 bool TCling::ClassInfo_IsValid(ClassInfo_t* cinfo) const
7011 {
7012  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
7013  return TClinginfo->IsValid();
7014 }
7016 ////////////////////////////////////////////////////////////////////////////////
7017 
7018 bool TCling::ClassInfo_IsValidMethod(ClassInfo_t* cinfo, const char* method, const char* proto, Long_t* offset, EFunctionMatchMode mode /* = kConversionMatch */) const
7019 {
7020  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
7021  return TClinginfo->IsValidMethod(method, proto, false, offset, mode);
7022 }
7023 
7024 ////////////////////////////////////////////////////////////////////////////////
7025 
7026 bool TCling::ClassInfo_IsValidMethod(ClassInfo_t* cinfo, const char* method, const char* proto, Bool_t objectIsConst, Long_t* offset, EFunctionMatchMode mode /* = kConversionMatch */) const
7027 {
7028  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
7029  return TClinginfo->IsValidMethod(method, proto, objectIsConst, offset, mode);
7030 }
7031 
7032 ////////////////////////////////////////////////////////////////////////////////
7034 int TCling::ClassInfo_Next(ClassInfo_t* cinfo) const
7035 {
7036  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
7037  return TClinginfo->Next();
7038 }
7039 
7040 ////////////////////////////////////////////////////////////////////////////////
7042 void* TCling::ClassInfo_New(ClassInfo_t* cinfo) const
7043 {
7044  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
7045  return TClinginfo->New(*fNormalizedCtxt);
7046 }
7047 
7048 ////////////////////////////////////////////////////////////////////////////////
7049 
7050 void* TCling::ClassInfo_New(ClassInfo_t* cinfo, int n) const
7051 {
7052  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
7053  return TClinginfo->New(n,*fNormalizedCtxt);
7054 }
7055 
7056 ////////////////////////////////////////////////////////////////////////////////
7057 
7058 void* TCling::ClassInfo_New(ClassInfo_t* cinfo, int n, void* arena) const
7059 {
7060  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
7061  return TClinginfo->New(n, arena,*fNormalizedCtxt);
7062 }
7063 
7064 ////////////////////////////////////////////////////////////////////////////////
7065 
7066 void* TCling::ClassInfo_New(ClassInfo_t* cinfo, void* arena) const
7067 {
7068  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
7069  return TClinginfo->New(arena,*fNormalizedCtxt);
7070 }
7071 
7072 ////////////////////////////////////////////////////////////////////////////////
7073 
7074 Long_t TCling::ClassInfo_Property(ClassInfo_t* cinfo) const
7075 {
7076  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
7077  return TClinginfo->Property();
7078 }
7079 
7080 ////////////////////////////////////////////////////////////////////////////////
7081 
7082 int TCling::ClassInfo_Size(ClassInfo_t* cinfo) const
7083 {
7084  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
7085  return TClinginfo->Size();
7086 }
7087 
7088 ////////////////////////////////////////////////////////////////////////////////
7089 
7090 Long_t TCling::ClassInfo_Tagnum(ClassInfo_t* cinfo) const
7091 {
7092  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
7093  return TClinginfo->Tagnum();
7094 }
7095 
7096 ////////////////////////////////////////////////////////////////////////////////
7097 
7098 const char* TCling::ClassInfo_FileName(ClassInfo_t* cinfo) const
7099 {
7100  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
7101  return TClinginfo->FileName();
7102 }
7103 
7104 ////////////////////////////////////////////////////////////////////////////////
7105 
7106 const char* TCling::ClassInfo_FullName(ClassInfo_t* cinfo) const
7107 {
7108  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
7109  TTHREAD_TLS_DECL(std::string,output);
7110  TClinginfo->FullName(output,*fNormalizedCtxt);
7111  return output.c_str();
7113 
7114 ////////////////////////////////////////////////////////////////////////////////
7115 
7116 const char* TCling::ClassInfo_Name(ClassInfo_t* cinfo) const
7117 {
7118  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
7119  return TClinginfo->Name();
7121 
7122 ////////////////////////////////////////////////////////////////////////////////
7123 
7124 const char* TCling::ClassInfo_Title(ClassInfo_t* cinfo) const
7125 {
7126  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
7127  return TClinginfo->Title();
7129 
7130 ////////////////////////////////////////////////////////////////////////////////
7131 
7132 const char* TCling::ClassInfo_TmpltName(ClassInfo_t* cinfo) const
7133 {
7134  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
7135  return TClinginfo->TmpltName();
7137 
7138 
7139 
7140 //______________________________________________________________________________
7141 //
7142 // BaseClassInfo interface
7143 //
7145 ////////////////////////////////////////////////////////////////////////////////
7146 
7147 void TCling::BaseClassInfo_Delete(BaseClassInfo_t* bcinfo) const
7148 {
7149  delete(TClingBaseClassInfo*) bcinfo;
7150 }
7151 
7152 ////////////////////////////////////////////////////////////////////////////////
7153 
7154 BaseClassInfo_t* TCling::BaseClassInfo_Factory(ClassInfo_t* cinfo) const
7155 {
7157  TClingClassInfo* TClinginfo = (TClingClassInfo*) cinfo;
7158  return (BaseClassInfo_t*) new TClingBaseClassInfo(fInterpreter, TClinginfo);
7159 }
7160 
7161 ////////////////////////////////////////////////////////////////////////////////
7163 BaseClassInfo_t* TCling::BaseClassInfo_Factory(ClassInfo_t* derived,
7164  ClassInfo_t* base) const
7165 {
7167  TClingClassInfo* TClinginfo = (TClingClassInfo*) derived;
7168  TClingClassInfo* TClinginfoBase = (TClingClassInfo*) base;
7169  return (BaseClassInfo_t*) new TClingBaseClassInfo(fInterpreter, TClinginfo, TClinginfoBase);
7171 
7172 ////////////////////////////////////////////////////////////////////////////////
7173 
7174 int TCling::BaseClassInfo_Next(BaseClassInfo_t* bcinfo) const
7175 {
7176  TClingBaseClassInfo* TClinginfo = (TClingBaseClassInfo*) bcinfo;
7177  return TClinginfo->Next();
7179 
7180 ////////////////////////////////////////////////////////////////////////////////
7181 
7182 int TCling::BaseClassInfo_Next(BaseClassInfo_t* bcinfo, int onlyDirect) const
7183 {
7184  TClingBaseClassInfo* TClinginfo = (TClingBaseClassInfo*) bcinfo;
7185  return TClinginfo->Next(onlyDirect);
7186 }
7187 
7188 ////////////////////////////////////////////////////////////////////////////////
7189 
7190 Long_t TCling::BaseClassInfo_Offset(BaseClassInfo_t* toBaseClassInfo, void * address, bool isDerivedObject) const
7191 {
7192  TClingBaseClassInfo* TClinginfo = (TClingBaseClassInfo*) toBaseClassInfo;
7193  return TClinginfo->Offset(address, isDerivedObject);
7194 }
7195 
7196 ////////////////////////////////////////////////////////////////////////////////
7197 
7198 Long_t TCling::ClassInfo_GetBaseOffset(ClassInfo_t* fromDerived, ClassInfo_t* toBase, void * address, bool isDerivedObject) const
7199 {
7200  TClingClassInfo* TClinginfo = (TClingClassInfo*) fromDerived;
7201  TClingClassInfo* TClinginfoBase = (TClingClassInfo*) toBase;
7202  // Offset to the class itself.
7203  if (TClinginfo->GetDecl() == TClinginfoBase->GetDecl()) {
7204  return 0;
7205  }
7206  return TClinginfo->GetBaseOffset(TClinginfoBase, address, isDerivedObject);
7207 }
7208 
7209 ////////////////////////////////////////////////////////////////////////////////
7210 
7211 Long_t TCling::BaseClassInfo_Property(BaseClassInfo_t* bcinfo) const
7212 {
7213  TClingBaseClassInfo* TClinginfo = (TClingBaseClassInfo*) bcinfo;
7214  return TClinginfo->Property();
7215 }
7216 
7217 ////////////////////////////////////////////////////////////////////////////////
7218 
7219 ClassInfo_t *TCling::BaseClassInfo_ClassInfo(BaseClassInfo_t *bcinfo) const
7221  TClingBaseClassInfo* TClinginfo = (TClingBaseClassInfo*) bcinfo;
7222  return (ClassInfo_t *)TClinginfo->GetBase();
7223 }
7224 
7225 ////////////////////////////////////////////////////////////////////////////////
7226 
7227 Long_t TCling::BaseClassInfo_Tagnum(BaseClassInfo_t* bcinfo) const
7229  TClingBaseClassInfo* TClinginfo = (TClingBaseClassInfo*) bcinfo;
7230  return TClinginfo->Tagnum();
7231 }
7232 
7233 ////////////////////////////////////////////////////////////////////////////////
7234 
7235 const char* TCling::BaseClassInfo_FullName(BaseClassInfo_t* bcinfo) const
7237  TClingBaseClassInfo* TClinginfo = (TClingBaseClassInfo*) bcinfo;
7238  TTHREAD_TLS_DECL(std::string,output);
7239  TClinginfo->FullName(output,*fNormalizedCtxt);
7240  return output.c_str();
7241 }
7242 
7243 ////////////////////////////////////////////////////////////////////////////////
7245 const char* TCling::BaseClassInfo_Name(BaseClassInfo_t* bcinfo) const
7246 {
7247  TClingBaseClassInfo* TClinginfo = (TClingBaseClassInfo*) bcinfo;
7248  return TClinginfo->Name();
7249 }
7250 
7251 ////////////////////////////////////////////////////////////////////////////////
7252 
7253 const char* TCling::BaseClassInfo_TmpltName(BaseClassInfo_t* bcinfo) const
7254 {
7255  TClingBaseClassInfo* TClinginfo = (TClingBaseClassInfo*) bcinfo;
7256  return TClinginfo->TmpltName();
7258 
7259 //______________________________________________________________________________
7260 //
7261 // DataMemberInfo interface
7262 //
7263 
7264 ////////////////////////////////////////////////////////////////////////////////
7266 int TCling::DataMemberInfo_ArrayDim(DataMemberInfo_t* dminfo) const
7267 {
7268  TClingDataMemberInfo* TClinginfo = (TClingDataMemberInfo*) dminfo;
7269  return TClinginfo->ArrayDim();
7270 }
7271 
7272 ////////////////////////////////////////////////////////////////////////////////
7274 void TCling::DataMemberInfo_Delete(DataMemberInfo_t* dminfo) const
7275 {
7276  delete(TClingDataMemberInfo*) dminfo;
7277 }
7278 
7279 ////////////////////////////////////////////////////////////////////////////////
7280 
7281 DataMemberInfo_t* TCling::DataMemberInfo_Factory(ClassInfo_t* clinfo /*= 0*/) const
7282 {
7284  TClingClassInfo* TClingclass_info = (TClingClassInfo*) clinfo;
7285  return (DataMemberInfo_t*) new TClingDataMemberInfo(fInterpreter, TClingclass_info);
7286 }
7287 
7288 ////////////////////////////////////////////////////////////////////////////////
7289 
7290 DataMemberInfo_t* TCling::DataMemberInfo_Factory(DeclId_t declid, ClassInfo_t* clinfo) const
7293  const clang::Decl* decl = reinterpret_cast<const clang::Decl*>(declid);
7294  const clang::ValueDecl* vd = llvm::dyn_cast_or_null<clang::ValueDecl>(decl);
7295  return (DataMemberInfo_t*) new TClingDataMemberInfo(fInterpreter, vd, (TClingClassInfo*)clinfo);
7296 }
7297 
7298 ////////////////////////////////////////////////////////////////////////////////
7300 DataMemberInfo_t* TCling::DataMemberInfo_FactoryCopy(DataMemberInfo_t* dminfo) const
7301 {
7302  TClingDataMemberInfo* TClinginfo = (TClingDataMemberInfo*) dminfo;
7303  return (DataMemberInfo_t*) new TClingDataMemberInfo(*TClinginfo);
7304 }
7305 
7306 ////////////////////////////////////////////////////////////////////////////////
7307 
7308 bool TCling::DataMemberInfo_IsValid(DataMemberInfo_t* dminfo) const
7309 {
7310  TClingDataMemberInfo* TClinginfo = (TClingDataMemberInfo*) dminfo;
7311  return TClinginfo->IsValid();
7313 
7314 ////////////////////////////////////////////////////////////////////////////////
7315 
7316 int TCling::DataMemberInfo_MaxIndex(DataMemberInfo_t* dminfo, Int_t dim) const
7317 {
7318  TClingDataMemberInfo* TClinginfo = (TClingDataMemberInfo*) dminfo;
7319  return TClinginfo->MaxIndex(dim);
7321 
7322 ////////////////////////////////////////////////////////////////////////////////
7323 
7324 int TCling::DataMemberInfo_Next(DataMemberInfo_t* dminfo) const
7325 {
7326  TClingDataMemberInfo* TClinginfo = (TClingDataMemberInfo*) dminfo;
7327  return TClinginfo->Next();
7328 }
7329 
7330 ////////////////////////////////////////////////////////////////////////////////
7331 
7332 Long_t TCling::DataMemberInfo_Offset(DataMemberInfo_t* dminfo) const
7333 {
7334  TClingDataMemberInfo* TClinginfo = (TClingDataMemberInfo*) dminfo;
7335  return TClinginfo->Offset();
7337 
7338 ////////////////////////////////////////////////////////////////////////////////
7339 
7340 Long_t TCling::DataMemberInfo_Property(DataMemberInfo_t* dminfo) const
7341 {
7342  TClingDataMemberInfo* TClinginfo = (TClingDataMemberInfo*) dminfo;
7343  return TClinginfo->Property();
7344 }
7345 
7346 ////////////////////////////////////////////////////////////////////////////////
7347 
7348 Long_t TCling::DataMemberInfo_TypeProperty(DataMemberInfo_t* dminfo) const
7349 {
7350  TClingDataMemberInfo* TClinginfo = (TClingDataMemberInfo*) dminfo;
7351  return TClinginfo->TypeProperty();
7352 }
7353 
7354 ////////////////////////////////////////////////////////////////////////////////
7355 
7356 int TCling::DataMemberInfo_TypeSize(DataMemberInfo_t* dminfo) const
7357 {
7358  TClingDataMemberInfo* TClinginfo = (TClingDataMemberInfo*) dminfo;
7359  return TClinginfo->TypeSize();
7360 }
7361 
7362 ////////////////////////////////////////////////////////////////////////////////
7363 
7364 const char* TCling::DataMemberInfo_TypeName(DataMemberInfo_t* dminfo) const
7365 {
7366  TClingDataMemberInfo* TClinginfo = (TClingDataMemberInfo*) dminfo;
7367  return TClinginfo->TypeName();
7368 }
7369 
7370 ////////////////////////////////////////////////////////////////////////////////
7371 
7372 const char* TCling::DataMemberInfo_TypeTrueName(DataMemberInfo_t* dminfo) const
7373 {
7374  TClingDataMemberInfo* TClinginfo = (TClingDataMemberInfo*) dminfo;
7375  return TClinginfo->TypeTrueName(*fNormalizedCtxt);
7376 }
7377 
7378 ////////////////////////////////////////////////////////////////////////////////
7379 
7380 const char* TCling::DataMemberInfo_Name(DataMemberInfo_t* dminfo) const
7381 {
7382  TClingDataMemberInfo* TClinginfo = (TClingDataMemberInfo*) dminfo;
7383  return TClinginfo->Name();
7384 }
7385 
7386 ////////////////////////////////////////////////////////////////////////////////
7387 
7388 const char* TCling::DataMemberInfo_Title(DataMemberInfo_t* dminfo) const
7389 {
7390  TClingDataMemberInfo* TClinginfo = (TClingDataMemberInfo*) dminfo;
7391  return TClinginfo->Title();
7392 }
7393 
7394 ////////////////////////////////////////////////////////////////////////////////
7395 
7396 const char* TCling::DataMemberInfo_ValidArrayIndex(DataMemberInfo_t* dminfo) const
7397 {
7398  TTHREAD_TLS_DECL(std::string,result);
7399 
7400  TClingDataMemberInfo* TClinginfo = (TClingDataMemberInfo*) dminfo;
7401  result = TClinginfo->ValidArrayIndex().str();
7402  return result.c_str();
7403 }
7404 
7405 ////////////////////////////////////////////////////////////////////////////////
7406 
7407 void TCling::SetDeclAttr(DeclId_t declId, const char* attribute)
7408 {
7409  Decl* decl = static_cast<Decl*>(const_cast<void*>(declId));
7410  ASTContext &C = decl->getASTContext();
7411  SourceRange commentRange; // this is a fake comment range
7412  decl->addAttr( new (C) AnnotateAttr( commentRange, C, attribute, 0 ) );
7413 }
7414 
7415 //______________________________________________________________________________
7416 //
7417 // Function Template interface
7418 //
7419 
7420 ////////////////////////////////////////////////////////////////////////////////
7421 
7422 static void ConstructorName(std::string &name, const clang::NamedDecl *decl,
7423  cling::Interpreter &interp,
7424  const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt)
7425 {
7426  const clang::TypeDecl* td = llvm::dyn_cast<clang::TypeDecl>(decl->getDeclContext());
7427  if (!td) return;
7428 
7429  clang::QualType qualType(td->getTypeForDecl(),0);
7430  ROOT::TMetaUtils::GetNormalizedName(name, qualType, interp, normCtxt);
7431  unsigned int level = 0;
7432  for(size_t cursor = name.length()-1; cursor != 0; --cursor) {
7433  if (name[cursor] == '>') ++level;
7434  else if (name[cursor] == '<' && level) --level;
7435  else if (level == 0 && name[cursor] == ':') {
7436  name.erase(0,cursor+1);
7437  break;
7438  }
7439  }
7440 }
7441 
7442 ////////////////////////////////////////////////////////////////////////////////
7443 
7444 void TCling::GetFunctionName(const clang::FunctionDecl *decl, std::string &output) const
7445 {
7446  output.clear();
7447  if (llvm::isa<clang::CXXConstructorDecl>(decl))
7448  {
7449  ConstructorName(output, decl, *fInterpreter, *fNormalizedCtxt);
7450 
7451  } else if (llvm::isa<clang::CXXDestructorDecl>(decl))
7452  {
7454  output.insert(output.begin(), '~');
7455  } else {
7456  llvm::raw_string_ostream stream(output);
7457  auto printPolicy = decl->getASTContext().getPrintingPolicy();
7458  // Don't trigger fopen of the source file to count lines:
7459  printPolicy.AnonymousTagLocations = false;
7460  decl->getNameForDiagnostic(stream, printPolicy, /*Qualified=*/false);
7461  }
7462 }
7463 
7464 ////////////////////////////////////////////////////////////////////////////////
7465 /// Return a unique identifier of the declaration represented by the
7466 /// FuncTempInfo
7467 
7468 TInterpreter::DeclId_t TCling::GetDeclId(FuncTempInfo_t *info) const
7469 {
7470  return (DeclId_t)info;
7471 }
7472 
7473 ////////////////////////////////////////////////////////////////////////////////
7474 /// Delete the FuncTempInfo_t
7475 
7476 void TCling::FuncTempInfo_Delete(FuncTempInfo_t * /* ft_info */) const
7477 {
7478  // Currently the address of ft_info is actually the decl itself,
7479  // so we have nothing to do.
7480 }
7481 
7482 ////////////////////////////////////////////////////////////////////////////////
7483 /// Construct a FuncTempInfo_t
7484 
7485 FuncTempInfo_t *TCling::FuncTempInfo_Factory(DeclId_t declid) const
7486 {
7487  // Currently the address of ft_info is actually the decl itself,
7488  // so we have nothing to do.
7489 
7490  return (FuncTempInfo_t*)const_cast<void*>(declid);
7491 }
7492 
7493 ////////////////////////////////////////////////////////////////////////////////
7494 /// Construct a FuncTempInfo_t
7495 
7496 FuncTempInfo_t *TCling::FuncTempInfo_FactoryCopy(FuncTempInfo_t *ft_info) const
7497 {
7498  // Currently the address of ft_info is actually the decl itself,
7499  // so we have nothing to do.
7500 
7501  return (FuncTempInfo_t*)ft_info;
7502 }
7503 
7504 ////////////////////////////////////////////////////////////////////////////////
7505 /// Check validity of a FuncTempInfo_t
7506 
7507 Bool_t TCling::FuncTempInfo_IsValid(FuncTempInfo_t *t_info) const
7508 {
7509  // Currently the address of ft_info is actually the decl itself,
7510  // so we have nothing to do.
7511 
7512  return t_info != 0;
7513 }
7515 ////////////////////////////////////////////////////////////////////////////////
7516 /// Return the maximum number of template arguments of the
7517 /// function template described by ft_info.
7518 
7519 UInt_t TCling::FuncTempInfo_TemplateNargs(FuncTempInfo_t *ft_info) const
7520 {
7521  if (!ft_info) return 0;
7522  const clang::FunctionTemplateDecl *ft = (const clang::FunctionTemplateDecl*)ft_info;
7523  return ft->getTemplateParameters()->size();
7524 }
7525 
7526 ////////////////////////////////////////////////////////////////////////////////
7527 /// Return the number of required template arguments of the
7528 /// function template described by ft_info.
7529 
7530 UInt_t TCling::FuncTempInfo_TemplateMinReqArgs(FuncTempInfo_t *ft_info) const
7532  if (!ft_info) return 0;
7533  const clang::FunctionTemplateDecl *ft = (clang::FunctionTemplateDecl*)ft_info;
7534  return ft->getTemplateParameters()->getMinRequiredArguments();
7535 }
7536 
7537 ////////////////////////////////////////////////////////////////////////////////
7538 /// Return the property of the function template.
7539 
7540 Long_t TCling::FuncTempInfo_Property(FuncTempInfo_t *ft_info) const
7541 {
7542  if (!ft_info) return 0;
7543 
7544  long property = 0L;
7545  property |= kIsCompiled;
7546 
7547  const clang::FunctionTemplateDecl *ft = (clang::FunctionTemplateDecl*)ft_info;
7548 
7549  switch (ft->getAccess()) {
7550  case clang::AS_public:
7551  property |= kIsPublic;
7552  break;
7553  case clang::AS_protected:
7554  property |= kIsProtected;
7555  break;
7556  case clang::AS_private:
7557  property |= kIsPrivate;
7558  break;
7559  case clang::AS_none:
7560  if (ft->getDeclContext()->isNamespace())
7561  property |= kIsPublic;
7562  break;
7563  default:
7564  // IMPOSSIBLE
7565  break;
7566  }
7567 
7568  const clang::FunctionDecl *fd = ft->getTemplatedDecl();
7569  if (const clang::CXXMethodDecl *md =
7570  llvm::dyn_cast<clang::CXXMethodDecl>(fd)) {
7571  if (md->getTypeQualifiers() & clang::Qualifiers::Const) {
7572  property |= kIsConstant | kIsConstMethod;
7573  }
7574  if (md->isVirtual()) {
7575  property |= kIsVirtual;
7576  }
7577  if (md->isPure()) {
7578  property |= kIsPureVirtual;
7579  }
7580  if (const clang::CXXConstructorDecl *cd =
7581  llvm::dyn_cast<clang::CXXConstructorDecl>(md)) {
7582  if (cd->isExplicit()) {
7583  property |= kIsExplicit;
7584  }
7585  }
7586  else if (const clang::CXXConversionDecl *cd =
7587  llvm::dyn_cast<clang::CXXConversionDecl>(md)) {
7588  if (cd->isExplicit()) {
7589  property |= kIsExplicit;
7590  }
7591  }
7592  }
7593  return property;
7594 }
7595 
7596 ////////////////////////////////////////////////////////////////////////////////
7597 /// Return the name of this function template.
7598 
7599 void TCling::FuncTempInfo_Name(FuncTempInfo_t *ft_info, TString &output) const
7600 {
7601  output.Clear();
7602  if (!ft_info) return;
7603  const clang::FunctionTemplateDecl *ft = (clang::FunctionTemplateDecl*)ft_info;
7604  std::string buf;
7605  GetFunctionName(ft->getTemplatedDecl(), buf);
7606  output = buf;
7607 }
7608 
7609 ////////////////////////////////////////////////////////////////////////////////
7610 /// Return the comments associates with this function template.
7611 
7612 void TCling::FuncTempInfo_Title(FuncTempInfo_t *ft_info, TString &output) const
7613 {
7614  output.Clear();
7615  if (!ft_info) return;
7616  const clang::FunctionTemplateDecl *ft = (const clang::FunctionTemplateDecl*)ft_info;
7617 
7618  // Iterate over the redeclarations, we can have multiple definitions in the
7619  // redecl chain (came from merging of pcms).
7620  if (const RedeclarableTemplateDecl *AnnotFD
7621  = ROOT::TMetaUtils::GetAnnotatedRedeclarable((const RedeclarableTemplateDecl*)ft)) {
7622  if (AnnotateAttr *A = AnnotFD->getAttr<AnnotateAttr>()) {
7623  output = A->getAnnotation().str();
7624  return;
7625  }
7626  }
7627  if (!ft->isFromASTFile()) {
7628  // Try to get the comment from the header file if present
7629  // but not for decls from AST file, where rootcling would have
7630  // created an annotation
7631  output = ROOT::TMetaUtils::GetComment(*ft).str();
7632  }
7633 }
7634 
7635 
7636 //______________________________________________________________________________
7637 //
7638 // MethodInfo interface
7639 //
7640 
7641 ////////////////////////////////////////////////////////////////////////////////
7642 /// Interface to cling function
7643 
7644 void TCling::MethodInfo_Delete(MethodInfo_t* minfo) const
7646  delete(TClingMethodInfo*) minfo;
7647 }
7648 
7649 ////////////////////////////////////////////////////////////////////////////////
7650 
7651 void TCling::MethodInfo_CreateSignature(MethodInfo_t* minfo, TString& signature) const
7652 {
7653  TClingMethodInfo* info = (TClingMethodInfo*) minfo;
7654  info->CreateSignature(signature);
7655 }
7656 
7657 ////////////////////////////////////////////////////////////////////////////////
7659 MethodInfo_t* TCling::MethodInfo_Factory() const
7660 {
7662  return (MethodInfo_t*) new TClingMethodInfo(fInterpreter);
7663 }
7664 
7665 ////////////////////////////////////////////////////////////////////////////////
7666 
7667 MethodInfo_t* TCling::MethodInfo_Factory(ClassInfo_t* clinfo) const
7668 {
7670  return (MethodInfo_t*) new TClingMethodInfo(fInterpreter, (TClingClassInfo*)clinfo);
7671 }
7672 
7673 ////////////////////////////////////////////////////////////////////////////////
7674 
7675 MethodInfo_t* TCling::MethodInfo_Factory(DeclId_t declid) const
7676 {
7677  const clang::Decl* decl = reinterpret_cast<const clang::Decl*>(declid);
7679  const clang::FunctionDecl* fd = llvm::dyn_cast_or_null<clang::FunctionDecl>(decl);
7680  return (MethodInfo_t*) new TClingMethodInfo(fInterpreter, fd);
7681 }
7682 
7683 ////////////////////////////////////////////////////////////////////////////////
7684 
7685 MethodInfo_t* TCling::MethodInfo_FactoryCopy(MethodInfo_t* minfo) const
7686 {
7687  return (MethodInfo_t*) new TClingMethodInfo(*(TClingMethodInfo*)minfo);
7688 }
7689 
7690 ////////////////////////////////////////////////////////////////////////////////
7691 
7692 void* TCling::MethodInfo_InterfaceMethod(MethodInfo_t* minfo) const
7693 {
7694  TClingMethodInfo* info = (TClingMethodInfo*) minfo;
7695  return info->InterfaceMethod(*fNormalizedCtxt);
7696 }
7698 ////////////////////////////////////////////////////////////////////////////////
7699 
7700 bool TCling::MethodInfo_IsValid(MethodInfo_t* minfo) const
7701 {
7702  TClingMethodInfo* info = (TClingMethodInfo*) minfo;
7703  return info->IsValid();
7704 }
7706 ////////////////////////////////////////////////////////////////////////////////
7707 
7708 int TCling::MethodInfo_NArg(MethodInfo_t* minfo) const
7709 {
7710  TClingMethodInfo* info = (TClingMethodInfo*) minfo;
7711  return info->NArg();
7712 }
7714 ////////////////////////////////////////////////////////////////////////////////
7715 
7716 int TCling::MethodInfo_NDefaultArg(MethodInfo_t* minfo) const
7717 {
7718  TClingMethodInfo* info = (TClingMethodInfo*) minfo;
7719  return info->NDefaultArg();
7720 }
7722 ////////////////////////////////////////////////////////////////////////////////
7723 
7724 int TCling::MethodInfo_Next(MethodInfo_t* minfo) const
7725 {
7726  TClingMethodInfo* info = (TClingMethodInfo*) minfo;
7727  return info->Next();
7728 }
7729 
7730 ////////////////////////////////////////////////////////////////////////////////
7732 Long_t TCling::MethodInfo_Property(MethodInfo_t* minfo) const
7733 {
7734  TClingMethodInfo* info = (TClingMethodInfo*) minfo;
7735  return info->Property();
7736 }
7737 
7738 ////////////////////////////////////////////////////////////////////////////////
7739 
7740 Long_t TCling::MethodInfo_ExtraProperty(MethodInfo_t* minfo) const
7741 {
7742  TClingMethodInfo* info = (TClingMethodInfo*) minfo;
7743  return info->ExtraProperty();
7744 }
7745 
7746 ////////////////////////////////////////////////////////////////////////////////
7747 
7748 TypeInfo_t* TCling::MethodInfo_Type(MethodInfo_t* minfo) const
7749 {
7750  TClingMethodInfo* info = (TClingMethodInfo*) minfo;
7751  return (TypeInfo_t*)info->Type();
7752 }
7753 
7754 ////////////////////////////////////////////////////////////////////////////////
7755 
7756 const char* TCling::MethodInfo_GetMangledName(MethodInfo_t* minfo) const
7757 {
7758  TClingMethodInfo* info = (TClingMethodInfo*) minfo;
7759  TTHREAD_TLS_DECL(TString, mangled_name);
7760  mangled_name = info->GetMangledName();
7761  return mangled_name;
7763 
7764 ////////////////////////////////////////////////////////////////////////////////
7765 
7766 const char* TCling::MethodInfo_GetPrototype(MethodInfo_t* minfo) const
7767 {
7768  TClingMethodInfo* info = (TClingMethodInfo*) minfo;
7769  return info->GetPrototype(*fNormalizedCtxt);
7771 
7772 ////////////////////////////////////////////////////////////////////////////////
7773 
7774 const char* TCling::MethodInfo_Name(MethodInfo_t* minfo) const
7775 {
7776  TClingMethodInfo* info = (TClingMethodInfo*) minfo;
7777  return info->Name(*fNormalizedCtxt);
7779 
7780 ////////////////////////////////////////////////////////////////////////////////
7781 
7782 const char* TCling::MethodInfo_TypeName(MethodInfo_t* minfo) const
7783 {
7784  TClingMethodInfo* info = (TClingMethodInfo*) minfo;
7785  return info->TypeName();
7787 
7788 ////////////////////////////////////////////////////////////////////////////////
7789 
7790 std::string TCling::MethodInfo_TypeNormalizedName(MethodInfo_t* minfo) const
7791 {
7792  TClingMethodInfo* info = (TClingMethodInfo*) minfo;
7793  if (info && info->IsValid())
7795  else
7796  return "";
7797 }
7798 
7799 ////////////////////////////////////////////////////////////////////////////////
7800 
7801 const char* TCling::MethodInfo_Title(MethodInfo_t* minfo) const
7803  TClingMethodInfo* info = (TClingMethodInfo*) minfo;
7804  return info->Title();
7805 }
7806 
7807 ////////////////////////////////////////////////////////////////////////////////
7808 
7810 {
7811  if (func) {
7812  return MethodInfo_MethodCallReturnType(func->fInfo);
7813  } else {
7814  return EReturnType::kOther;
7815  }
7816 }
7817 
7818 ////////////////////////////////////////////////////////////////////////////////
7819 
7820 auto TCling::MethodInfo_MethodCallReturnType(MethodInfo_t* minfo) const -> EReturnType
7821 {
7822  TClingMethodInfo* info = (TClingMethodInfo*) minfo;
7823  if (info && info->IsValid()) {
7824  TClingTypeInfo *typeinfo = info->Type();
7825  clang::QualType QT( typeinfo->GetQualType().getCanonicalType() );
7826  if (QT->isEnumeralType()) {
7827  return EReturnType::kLong;
7828  } else if (QT->isPointerType()) {
7829  // Look for char*
7830  QT = llvm::cast<clang::PointerType>(QT)->getPointeeType();
7831  if ( QT->isCharType() ) {
7832  return EReturnType::kString;
7833  } else {
7834  return EReturnType::kOther;
7835  }
7836  } else if ( QT->isFloatingType() ) {
7837  int sz = typeinfo->Size();
7838  if (sz == 4 || sz == 8) {
7839  // Support only float and double.
7840  return EReturnType::kDouble;
7841  } else {
7842  return EReturnType::kOther;
7843  }
7844  } else if ( QT->isIntegerType() ) {
7845  int sz = typeinfo->Size();
7846  if (sz <= 8) {
7847  // Support only up to long long ... but
7848  // FIXME the TMethodCall::Execute only
7849  // return long (4 bytes) ...
7850  // The v5 implementation of TMethodCall::ReturnType
7851  // was not making the distinction so we let it go
7852  // as is for now, but we really need to upgrade
7853  // TMethodCall::Execute ...
7854  return EReturnType::kLong;
7855  } else {
7856  return EReturnType::kOther;
7857  }
7858  } else {
7859  return EReturnType::kOther;
7860  }
7861  } else {
7862  return EReturnType::kOther;
7863  }
7864 }
7865 
7866 //______________________________________________________________________________
7867 //
7868 // MethodArgInfo interface
7869 //
7870 
7871 ////////////////////////////////////////////////////////////////////////////////
7872 
7873 void TCling::MethodArgInfo_Delete(MethodArgInfo_t* marginfo) const
7874 {
7875  delete(TClingMethodArgInfo*) marginfo;
7876 }
7877 
7878 ////////////////////////////////////////////////////////////////////////////////
7879 
7880 MethodArgInfo_t* TCling::MethodArgInfo_Factory() const
7881 {
7883  return (MethodArgInfo_t*) new TClingMethodArgInfo(fInterpreter);
7884 }
7885 
7886 ////////////////////////////////////////////////////////////////////////////////
7887 
7888 MethodArgInfo_t* TCling::MethodArgInfo_Factory(MethodInfo_t *minfo) const
7889 {
7891  return (MethodArgInfo_t*) new TClingMethodArgInfo(fInterpreter, (TClingMethodInfo*)minfo);
7892 }
7893 
7894 ////////////////////////////////////////////////////////////////////////////////
7895 
7896 MethodArgInfo_t* TCling::MethodArgInfo_FactoryCopy(MethodArgInfo_t* marginfo) const
7897 {
7898  return (MethodArgInfo_t*)
7899  new TClingMethodArgInfo(*(TClingMethodArgInfo*)marginfo);
7900 }
7901 
7902 ////////////////////////////////////////////////////////////////////////////////
7903 
7904 bool TCling::MethodArgInfo_IsValid(MethodArgInfo_t* marginfo) const
7905 {
7906  TClingMethodArgInfo* info = (TClingMethodArgInfo*) marginfo;
7907  return info->IsValid();
7908 }
7909 
7910 ////////////////////////////////////////////////////////////////////////////////
7911 
7912 int TCling::MethodArgInfo_Next(MethodArgInfo_t* marginfo) const
7913 {
7914  TClingMethodArgInfo* info = (TClingMethodArgInfo*) marginfo;
7915  return info->Next();
7916 }
7917 
7918 ////////////////////////////////////////////////////////////////////////////////
7920 Long_t TCling::MethodArgInfo_Property(MethodArgInfo_t* marginfo) const
7921 {
7922  TClingMethodArgInfo* info = (TClingMethodArgInfo*) marginfo;
7923  return info->Property();
7924 }
7925 
7926 ////////////////////////////////////////////////////////////////////////////////
7927 
7928 const char* TCling::MethodArgInfo_DefaultValue(MethodArgInfo_t* marginfo) const
7929 {
7930  TClingMethodArgInfo* info = (TClingMethodArgInfo*) marginfo;
7931  return info->DefaultValue();
7932 }
7933 
7934 ////////////////////////////////////////////////////////////////////////////////
7935 
7936 const char* TCling::MethodArgInfo_Name(MethodArgInfo_t* marginfo) const
7937 {
7938  TClingMethodArgInfo* info = (TClingMethodArgInfo*) marginfo;
7939  return info->Name();
7940 }
7941 
7942 ////////////////////////////////////////////////////////////////////////////////
7943 
7944 const char* TCling::MethodArgInfo_TypeName(MethodArgInfo_t* marginfo) const
7945 {
7946  TClingMethodArgInfo* info = (TClingMethodArgInfo*) marginfo;
7947  return info->TypeName();
7948 }
7949 
7950 ////////////////////////////////////////////////////////////////////////////////
7951 
7952 std::string TCling::MethodArgInfo_TypeNormalizedName(MethodArgInfo_t* marginfo) const
7953 {
7954  TClingMethodArgInfo* info = (TClingMethodArgInfo*) marginfo;
7955  return info->Type()->NormalizedName(*fNormalizedCtxt);
7956 }
7957 
7958 //______________________________________________________________________________
7959 //
7960 // TypeInfo interface
7961 //
7962 
7963 ////////////////////////////////////////////////////////////////////////////////
7964 
7965 void TCling::TypeInfo_Delete(TypeInfo_t* tinfo) const
7967  delete (TClingTypeInfo*) tinfo;
7968 }
7969 
7970 ////////////////////////////////////////////////////////////////////////////////
7971 
7972 TypeInfo_t* TCling::TypeInfo_Factory() const
7973 {
7975  return (TypeInfo_t*) new TClingTypeInfo(fInterpreter);
7976 }
7977 
7978 ////////////////////////////////////////////////////////////////////////////////
7979 
7980 TypeInfo_t* TCling::TypeInfo_Factory(const char *name) const
7981 {
7983  return (TypeInfo_t*) new TClingTypeInfo(fInterpreter, name);
7984 }
7985 
7986 ////////////////////////////////////////////////////////////////////////////////
7987 
7988 TypeInfo_t* TCling::TypeInfo_FactoryCopy(TypeInfo_t* tinfo) const
7989 {
7990  return (TypeInfo_t*) new TClingTypeInfo(*(TClingTypeInfo*)tinfo);
7991 }
7992 
7993 ////////////////////////////////////////////////////////////////////////////////
7994 
7995 void TCling::TypeInfo_Init(TypeInfo_t* tinfo, const char* name) const
7996 {
7998  TClingTypeInfo* TClinginfo = (TClingTypeInfo*) tinfo;
7999  TClinginfo->Init(name);
8000 }
8001 
8002 ////////////////////////////////////////////////////////////////////////////////
8003 
8004 bool TCling::TypeInfo_IsValid(TypeInfo_t* tinfo) const
8005 {
8006  TClingTypeInfo* TClinginfo = (TClingTypeInfo*) tinfo;
8007  return TClinginfo->IsValid();
8008 }
8009 
8010 ////////////////////////////////////////////////////////////////////////////////
8012 const char* TCling::TypeInfo_Name(TypeInfo_t* tinfo) const
8013 {
8014  TClingTypeInfo* TClinginfo = (TClingTypeInfo*) tinfo;
8015  return TClinginfo->Name();
8016 }
8017 
8018 ////////////////////////////////////////////////////////////////////////////////
8019 
8020 Long_t TCling::TypeInfo_Property(TypeInfo_t* tinfo) const
8021 {
8022  TClingTypeInfo* TClinginfo = (TClingTypeInfo*) tinfo;
8023  return TClinginfo->Property();
8024 }
8025 
8026 ////////////////////////////////////////////////////////////////////////////////
8027 
8028 int TCling::TypeInfo_RefType(TypeInfo_t* tinfo) const
8029 {
8030  TClingTypeInfo* TClinginfo = (TClingTypeInfo*) tinfo;
8031  return TClinginfo->RefType();
8032 }
8033 
8034 ////////////////////////////////////////////////////////////////////////////////
8035 
8036 int TCling::TypeInfo_Size(TypeInfo_t* tinfo) const
8037 {
8038  TClingTypeInfo* TClinginfo = (TClingTypeInfo*) tinfo;
8039  return TClinginfo->Size();
8040 }
8042 ////////////////////////////////////////////////////////////////////////////////
8043 
8044 const char* TCling::TypeInfo_TrueName(TypeInfo_t* tinfo) const
8045 {
8046  TClingTypeInfo* TClinginfo = (TClingTypeInfo*) tinfo;
8047  return TClinginfo->TrueName(*fNormalizedCtxt);
8048 }
8049 
8051 //______________________________________________________________________________
8052 //
8053 // TypedefInfo interface
8054 //
8055 
8056 ////////////////////////////////////////////////////////////////////////////////
8057 
8058 void TCling::TypedefInfo_Delete(TypedefInfo_t* tinfo) const
8059 {
8060  delete(TClingTypedefInfo*) tinfo;
8061 }
8062 
8063 ////////////////////////////////////////////////////////////////////////////////
8064 
8065 TypedefInfo_t* TCling::TypedefInfo_Factory() const
8068  return (TypedefInfo_t*) new TClingTypedefInfo(fInterpreter);
8069 }
8070 
8071 ////////////////////////////////////////////////////////////////////////////////
8072 
8073 TypedefInfo_t* TCling::TypedefInfo_Factory(const char *name) const
8076  return (TypedefInfo_t*) new TClingTypedefInfo(fInterpreter, name);
8077 }
8078 
8079 ////////////////////////////////////////////////////////////////////////////////
8080 
8081 TypedefInfo_t* TCling::TypedefInfo_FactoryCopy(TypedefInfo_t* tinfo) const
8083  return (TypedefInfo_t*) new TClingTypedefInfo(*(TClingTypedefInfo*)tinfo);
8084 }
8085 
8086 ////////////////////////////////////////////////////////////////////////////////
8087 
8088 void TCling::TypedefInfo_Init(TypedefInfo_t* tinfo,
8089  const char* name) const
8092  TClingTypedefInfo* TClinginfo = (TClingTypedefInfo*) tinfo;
8093  TClinginfo->Init(name);
8094 }
8095 
8096 ////////////////////////////////////////////////////////////////////////////////
8097 
8098 bool TCling::TypedefInfo_IsValid(TypedefInfo_t* tinfo) const
8099 {
8100  TClingTypedefInfo* TClinginfo = (TClingTypedefInfo*) tinfo;
8101  return TClinginfo->IsValid();
8102 }
8103 
8104 ////////////////////////////////////////////////////////////////////////////////
8105 
8106 Int_t TCling::TypedefInfo_Next(TypedefInfo_t* tinfo) const
8107 {
8108  TClingTypedefInfo* TClinginfo = (TClingTypedefInfo*) tinfo;
8109  return TClinginfo->Next();
8110 }
8112 ////////////////////////////////////////////////////////////////////////////////
8113 
8114 Long_t TCling::TypedefInfo_Property(TypedefInfo_t* tinfo) const
8115 {
8116  TClingTypedefInfo* TClinginfo = (TClingTypedefInfo*) tinfo;
8117  return TClinginfo->Property();
8118 }
8120 ////////////////////////////////////////////////////////////////////////////////
8121 
8122 int TCling::TypedefInfo_Size(TypedefInfo_t* tinfo) const
8123 {
8124  TClingTypedefInfo* TClinginfo = (TClingTypedefInfo*) tinfo;
8125  return TClinginfo->Size();
8126 }
8128 ////////////////////////////////////////////////////////////////////////////////
8129 
8130 const char* TCling::TypedefInfo_TrueName(TypedefInfo_t* tinfo) const
8131 {
8132  TClingTypedefInfo* TClinginfo = (TClingTypedefInfo*) tinfo;
8133  return TClinginfo->TrueName(*fNormalizedCtxt);
8135 
8136 ////////////////////////////////////////////////////////////////////////////////
8137 
8138 const char* TCling::TypedefInfo_Name(TypedefInfo_t* tinfo) const
8139 {
8140  TClingTypedefInfo* TClinginfo = (TClingTypedefInfo*) tinfo;
8141  return TClinginfo->Name();
8142 }
8143 
8144 ////////////////////////////////////////////////////////////////////////////////
8145 
8146 const char* TCling::TypedefInfo_Title(TypedefInfo_t* tinfo) const
8147 {
8148  TClingTypedefInfo* TClinginfo = (TClingTypedefInfo*) tinfo;
8149  return TClinginfo->Title();
8150 }
8151 
EState GetState() const
Definition: TClass.h:443
int TCling__AutoLoadCallback(const char *className)
Definition: TCling.cxx:602
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:7926
Describe Streamer information for one class version.
Definition: TStreamerInfo.h:47
for(Int_t i=0;i< n;i++)
Definition: legend1.C:18
const char * GetIncludePath()
Refresh the list of include paths known to the interpreter and return it with -I prepended.
Definition: TCling.cxx:6144
void ResetCaches()
To clean out all caches.
Definition: TClass.cxx:3960
virtual Long_t MethodInfo_Property(MethodInfo_t *minfo) const
Definition: TCling.cxx:7778
virtual Long_t ClassInfo_ClassProperty(ClassInfo_t *info) const
Definition: TCling.cxx:6929
virtual const char * BaseName(const char *pathname)
Base name of a file name. Base name of /user/root is root.
Definition: TSystem.cxx:929
virtual Int_t GetEntries() const
Definition: TCollection.h:92
virtual Bool_t AccessPathName(const char *path, EAccessMode mode=kFileExists)
Returns FALSE if one can access a file using the specified access mode.
Definition: TSystem.cxx:1265
virtual void SetTempLevel(int val) const
Create / close a scope for temporaries.
Definition: TCling.cxx:6421
const clang::FunctionTemplateDecl * GetFunctionTemplate(const char *fname) const
virtual void SetRcName(const char *name)
Definition: TEnv.h:149
ETupleOrdering
Check in what order the member of a tuple are layout.
Definition: TCling.cxx:3187
TObject * GetObjectAddress(const char *Name, void *&LookupCtx)
If the interpreter encounters Name, check whether that is an object ROOT could retrieve.
Definition: TCling.cxx:6498
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:4068
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:4064
int TCling__IsAutoLoadNamespaceCandidate(const clang::NamespaceDecl *nsDecl)
Definition: TCling.cxx:624
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:629
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:4125
static clang::ClassTemplateDecl * FindTemplateInNamespace(clang::Decl *decl)
Find a template decl within N nested namespaces, 0&lt;=N&lt;inf Assumes 1 and only 1 template present and 1...
Definition: TCling.cxx:665
virtual void SetRTLD_NOW() const
Definition: TCling.cxx:6405
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:4225
void TransactionRollback(const cling::Transaction &T)
Definition: TCling.cxx:5997
virtual int TypedefInfo_Size(TypedefInfo_t *tinfo) const
Definition: TCling.cxx:8168
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:6338
Bool_t IsOnHeap() const
Definition: TObject.h:119
void AddTemplAndNargsToKeep(const clang::ClassTemplateDecl *templ, unsigned int i)
Definition: TMetaUtils.cxx:333
virtual bool ClassInfo_HasDefaultConstructor(ClassInfo_t *info) const
Definition: TCling.cxx:6999
ROOT::ESTLType IsSTLCont(std::string_view type)
type : type name: vector&lt;list&lt;classA,allocator&gt;,allocator&gt; result: 0 : not stl container code of cont...
void LibraryLoaded(const void *dyLibHandle, const char *canonicalName)
Definition: TCling.cxx:6020
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:2956
virtual CallFuncIFacePtr_t CallFunc_IFacePtr(CallFunc_t *func) const
Definition: TCling.cxx:6744
void TCling__UpdateListsOnCommitted(const cling::Transaction &T, cling::Interpreter *)
Definition: TCling.cxx:553
virtual void PostLoadCheck()
Do the initialization that can only be done after the CINT dictionary has been fully populated and ca...
Definition: TClass.cxx:5580
virtual void BaseClassInfo_Delete(BaseClassInfo_t *bcinfo) const
Definition: TCling.cxx:7193
virtual DataMemberInfo_t * DataMemberInfo_Factory(ClassInfo_t *clinfo=0) const
Definition: TCling.cxx:7327
virtual bool CallFunc_IsValid(CallFunc_t *func) const
Definition: TCling.cxx:6735
static void ConstructorName(std::string &name, const clang::NamedDecl *decl, cling::Interpreter &interp, const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt)
Definition: TCling.cxx:7468
R__EXTERN Int_t gErrorIgnoreLevel
Definition: TError.h:107
virtual int ClassInfo_Next(ClassInfo_t *info) const
Definition: TCling.cxx:7080
bool IsLoaded() const
virtual const char * WorkingDirectory()
Return working directory.
Definition: TSystem.cxx:866
virtual Int_t UnLock()=0
virtual const char * DataMemberInfo_TypeName(DataMemberInfo_t *dminfo) const
Definition: TCling.cxx:7410
virtual void CallFunc_ExecWithReturn(CallFunc_t *func, void *address, void *ret) const
Definition: TCling.cxx:6652
virtual void StackTrace()
Print a stack trace.
Definition: TSystem.cxx:737
std::map< SpecialObjectLookupCtx_t, SpecialObjectMap_t > fSpecialObjectMaps
Definition: TCling.h:143
virtual TypedefInfo_t * TypedefInfo_FactoryCopy(TypedefInfo_t *tinfo) const
Definition: TCling.cxx:8127
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:2654
static cling::Interpreter::CompilationResult ExecAutoParse(const char *what, Bool_t header, cling::Interpreter *interpreter)
Parse the payload or header.
Definition: TCling.cxx:5296
TLine * line
void Fatal(const char *location, const char *msgfmt,...)
bool IsValid() const
void RegisterLoadedSharedLibrary(const char *name)
Register a new shared library name with the interpreter; add it to fSharedLibs.
Definition: TCling.cxx:2740
Collectable string class.
Definition: TObjString.h:32
float Float_t
Definition: RtypesCore.h:53
static void AddClassToDeclIdMap(TDictionary::DeclId_t id, TClass *cl)
static: Add a TClass* to the map of classes.
Definition: TClass.cxx:478
const char * Name() const
virtual DeclId_t GetEnum(TClass *cl, const char *name) const
Return pointer to cling Decl of global/static variable that is located at the address given by addr...
Definition: TCling.cxx:3954
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:5746
TDictionary::DeclId_t DeclId_t
Definition: TInterpreter.h:251
virtual int BaseClassInfo_Next(BaseClassInfo_t *bcinfo) const
Definition: TCling.cxx:7220
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:682
TEnum * Find(DeclId_t id) const
Return the TEnum corresponding to the Decl &#39;id&#39; or NULL if it does not exist.
Dictionary for function template This class describes one single function template.
double ExecDouble(void *address)
void Init(const char *name)
virtual TypeInfo_t * TypeInfo_FactoryCopy(TypeInfo_t *) const
Definition: TCling.cxx:8034
All ROOT classes may have RTTI (run time type identification) support added.
Definition: TDataMember.h:33
int GetSplit(const char *type, std::vector< std::string > &output, int &nestedLoc, EModType mode=TClassEdit::kNone)
Stores in output (after emptying it) the split type.
Definition: TClassEdit.cxx:938
virtual void MethodInfo_CreateSignature(MethodInfo_t *minfo, TString &signature) const
Definition: TCling.cxx:7697
static TProtoClass * GetProtoNorm(const char *cname)
Given the class normalized name returns the TClassProto object for the class.
TObject * FindObject(const char *name) const
Find object using its name.
Definition: THashList.cxx:213
A collection of TFunction objects designed for fast access given a DeclId_t and for keep track of TFu...
double T(double x)
Definition: ChebyshevPol.h:34
int GetMethodNArg(const char *method, const char *proto, Bool_t objectIsConst, ROOT::EFunctionMatchMode mode=ROOT::kConversionMatch) const
R__EXTERN TVirtualMutex * gInterpreterMutex
Definition: TInterpreter.h:46
bool TClingLookupHelper__ExistingTypeCheck(const std::string &tname, std::string &result)
Try hard to avoid looking up in the Cling database as this could enduce an unwanted autoparsing...
Definition: TCling.cxx:918
TList * GetListOfEnums(Bool_t load=kTRUE)
Return a list containing the TEnums of a class.
Definition: TClass.cxx:3493
const char * Name() const
bool HasMethod(const char *name) const
void Init(const char *name)
Lookup named typedef and reset the iterator to point to it.
std::atomic< TListOfEnums * > fEnums
Definition: TClass.h:185
virtual CallFunc_t * CallFunc_FactoryCopy(CallFunc_t *func) const
Definition: TCling.cxx:6703
int GetPathInfo(const char *path, Long_t *id, Long_t *size, Long_t *flags, Long_t *modtime)
Get info about a file: id, size, flags, modification time.
Definition: TSystem.cxx:1363
virtual void Update()=0
void SetFunc(const TClingClassInfo *info, const char *method, const char *arglist, long *poffset)
void Destruct(void *arena, const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt) const
virtual const char * MethodInfo_Title(MethodInfo_t *minfo) const
Definition: TCling.cxx:7847
void SetArgArray(long *argArr, int narg)
cling::MetaProcessor * fMetaProcessor
Definition: TCling.h:121
virtual int DataMemberInfo_TypeSize(DataMemberInfo_t *dminfo) const
Definition: TCling.cxx:7402
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.: &quot;class TDirectory*&quot;.
Definition: TDataType.cxx:175
Persistent version of a TClass.
Definition: TProtoClass.h:37
virtual void SetRTLD_LAZY() const
Definition: TCling.cxx:6412
Emulation of the CINT DataMemberInfo class.
Small helper to keep current directory context.
TEnum * Get(DeclId_t id, const char *name)
Return (after creating it if necessary) the TEnum describing the enum corresponding to the Decl &#39;id&#39;...
std::atomic< Bool_t > fHasRootPcmInfo
C++ Property of the class (is abstract, has virtual table, etc.)
Definition: TClass.h:230
TClass * GenerateTClass(const char *classname, Bool_t emulation, Bool_t silent=kFALSE)
Generate a TClass for the given class.
Definition: TCling.cxx:3706
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
Definition: TObject.cxx:899
Int_t LastIndex() const
void UpdateListOfGlobals()
No op: see TClingCallbacks (used to update the list of globals)
Definition: TCling.cxx:3167
void UpdateListOfGlobalFunctions()
No op: see TClingCallbacks (used to update the list of global functions)
Definition: TCling.cxx:3174
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:7998
const char * Name() const
void SaveContext()
Save the current Cling state.
Definition: TCling.cxx:3141
virtual MethodInfo_t * CallFunc_FactoryMethod(CallFunc_t *func) const
Definition: TCling.cxx:6710
cling::Interpreter * fInterpreter
Definition: TCling.h:120
virtual ClassInfo_t * ClassInfo_Factory(Bool_t all=kTRUE) const
Definition: TCling.cxx:6968
virtual const char * HomeDirectory(const char *userName=0)
Return the user&#39;s home directory.
Definition: TSystem.cxx:882
void SetArg(long arg)
static void RemoveClassDeclId(TDictionary::DeclId_t id)
Definition: TClass.cxx:503
Long_t Property() const
Set TObject::fBits and fStreamerType to cache information about the class.
Definition: TClass.cxx:5661
virtual BaseClassInfo_t * BaseClassInfo_Factory(ClassInfo_t *info) const
Definition: TCling.cxx:7200
const char * GetClassSharedLibs(const char *cls)
Get the list of shared libraries containing the code for class cls.
Definition: TCling.cxx:6047
const char * GetValue() const
Definition: TEnv.h:114
void TCling__DEBUG__dump(clang::DeclContext *DC)
Definition: TCling.cxx:211
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:7690
virtual void CallFunc_SetArgArray(CallFunc_t *func, Long_t *paramArr, Int_t nparam) const
Definition: TCling.cxx:6808
virtual const char * TypedefInfo_TrueName(TypedefInfo_t *tinfo) const
Definition: TCling.cxx:8176
Bool_t IsPersistent() const
Definition: TDataMember.h:89
#define R__ASSERT(e)
Definition: TError.h:98
void TCling__UpdateListsOnUnloaded(const cling::Transaction &T)
Definition: TCling.cxx:559
#define gROOT
Definition: TROOT.h:379
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:3549
bool LoadPCM(TString pcmFileName, const char **headers, void(*triggerFunc)()) const
Tries to load a PCM; returns true on success.
Definition: TCling.cxx:1279
clang::QualType ReSubstTemplateArg(clang::QualType input, const clang::Type *instance)
Check if &#39;input&#39; or any of its template parameter was substituted when instantiating the class templa...
virtual Bool_t IsTreatingNonAccessibleTypes()
virtual FuncTempInfo_t * FuncTempInfo_FactoryCopy(FuncTempInfo_t *) const
Construct a FuncTempInfo_t.
Definition: TCling.cxx:7542
void FullName(std::string &output, const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt) const
Int_t Load(const char *filenam, Bool_t system=kFALSE)
Load a library file in cling&#39;s memory.
Definition: TCling.cxx:2812
virtual int Load(const char *module, const char *entry="", Bool_t system=kFALSE)
Load a shared library.
Definition: TSystem.cxx:1818
The TEnv class reads config files, by default named .rootrc.
Definition: TEnv.h:128
std::string InsertStd(const char *tname)
clang::DeclContext * TCling__DEBUG__getDeclContext(clang::Decl *D)
Definition: TCling.cxx:202
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:5162
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:4080
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:1879
static Bool_t HasNoInfoOrEmuOrFwdDeclaredDecl(const char *)
Definition: TClass.cxx:3171
bool HasDefaultConstructor() const
virtual TApplicationImp * GetApplicationImp()
Definition: TApplication.h:137
int Int_t
Definition: RtypesCore.h:41
TClingMethodInfo GetMethod(const char *fname) const
TClingTypeInfo * Type() const
virtual const char * DirName(const char *pathname)
Return the directory name in pathname.
Definition: TSystem.cxx:997
bool Bool_t
Definition: RtypesCore.h:59
virtual const char * MethodInfo_GetMangledName(MethodInfo_t *minfo) const
Definition: TCling.cxx:7802
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:7565
TArc * a
Definition: textangle.C:12
virtual int DisplayIncludePath(FILE *fout) const
Interface to cling function.
Definition: TCling.cxx:6193
const Bool_t kFALSE
Definition: Rtypes.h:92
void * fPrevLoadedDynLibInfo
Definition: TCling.h:127
#define gInterpreter
Definition: TInterpreter.h:517
const char * fantomline
Definition: TCling.cxx:856
virtual char * Which(const char *search, const char *file, EAccessMode mode=kFileExists)
Find location of file in a search path.
Definition: TSystem.cxx:1511
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, Bool_t lateRegistration=false)
Inject the module named &quot;modulename&quot; into cling; load all headers.
Definition: TCling.cxx:1495
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:7291
virtual void TypeInfo_Delete(TypeInfo_t *tinfo) const
Definition: TCling.cxx:8011
virtual Long_t CallFunc_ExecInt(CallFunc_t *func, void *address) const
Definition: TCling.cxx:6671
Int_t DeleteVariable(const char *name)
Undeclare obj called name.
Definition: TCling.cxx:3082
virtual int SetClassAutoparsing(int)
Enable/Disable the Autoparsing of headers.
Definition: TCling.cxx:6362
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:6293
const char * TrueName(const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt) const
Get the name of the underlying type of the current typedef.
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:8041
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:4107
std::vector< cling::Value > * fTemporaries
Definition: TCling.h:123
virtual ~TCling()
Destroy the interpreter interface.
Definition: TCling.cxx:1196
const char * Class
Definition: TXMLSetup.cxx:64
virtual const char * DataMemberInfo_Title(DataMemberInfo_t *dminfo) const
Definition: TCling.cxx:7434
virtual void LoadFunctionTemplates(TClass *cl) const
Create list of pointers to function templates for TClass cl.
Definition: TCling.cxx:3612
virtual Long_t CINT not applicable to cling return
Definition: TInterpreter.h:214
void GetCppName(std::string &output, const char *input)
Return (in the argument &#39;output&#39;) a mangled version of the C++ symbol/type (pass as &#39;input&#39;) that can...
virtual bool MethodArgInfo_IsValid(MethodArgInfo_t *marginfo) const
Definition: TCling.cxx:7950
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:7386
virtual Long_t TypedefInfo_Property(TypedefInfo_t *tinfo) const
Definition: TCling.cxx:8160
virtual void * ClassInfo_New(ClassInfo_t *info) const
Definition: TCling.cxx:7088
const clang::Type * GetType() const
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:6184
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:4508
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
static const TString & GetIncludeDir()
Get the include directory in the installation. Static utility function.
Definition: TROOT.cxx:2734
virtual int GetProcInfo(ProcInfo_t *info) const
Returns cpu and memory used by this process into the ProcInfo_t structure.
Definition: TSystem.cxx:2458
RAII used to store Parser, Sema, Preprocessor state for recursive parsing.
Definition: ClingRAII.h:22
MethodInfo_t * fInfo
Definition: TFunction.h:36
Bool_t R_ISREG(Int_t mode)
Definition: TSystem.h:129
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition: TObject.cxx:739
virtual void SetDeclAttr(DeclId_t, const char *)
Definition: TCling.cxx:7453
virtual bool ClassInfo_IsValidMethod(ClassInfo_t *info, const char *method, const char *proto, Long_t *offset, ROOT::EFunctionMatchMode=ROOT::kConversionMatch) const
Definition: TCling.cxx:7064
virtual int DataMemberInfo_MaxIndex(DataMemberInfo_t *dminfo, Int_t dim) const
Definition: TCling.cxx:7362
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:4325
virtual const char * FindFile(const char *search, TString &file, EAccessMode mode=kFileExists)
Find location of file in a search path.
Definition: TSystem.cxx:1501
const char * GetSharedLibDeps(const char *lib)
Get the list a libraries on which the specified lib depends.
Definition: TCling.cxx:6089
const char * Name
Definition: TXMLSetup.cxx:67
virtual bool DiagnoseIfInterpreterException(const std::exception &e) const
Definition: TCling.cxx:1897
static const char * GetMacroPath()
Get macro search path. Static utility function.
Definition: TROOT.cxx:2549
bool ExtractAttrPropertyFromName(const clang::Decl &decl, const std::string &propName, std::string &propValue)
This routine counts on the &quot;propName&lt;separator&gt;propValue&quot; 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:727
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:6252
static void Add(const char *cname, Version_t id, const std::type_info &info, DictFuncPtr_t dict, Int_t pragmabits)
Add a class to the class table (this is a static function).
virtual void MethodArgInfo_Delete(MethodArgInfo_t *marginfo) const
Definition: TCling.cxx:7919
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:8074
void AddFriendToClass(clang::FunctionDecl *, clang::CXXRecordDecl *) const
Inject function as a friend into klass.
Definition: TCling.cxx:6553
virtual Long_t BaseClassInfo_Offset(BaseClassInfo_t *toBaseClassInfo, void *address, bool isDerivedObject) const
Definition: TCling.cxx:7236
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:220
Int_t UnloadLibraryMap(const char *library)
Unload library map entries coming from the specified library.
Definition: TCling.cxx:5066
virtual void Fatal(const char *method, const char *msgfmt,...) const
Issue fatal error message.
Definition: TObject.cxx:953
virtual TEnum * CreateEnum(void *VD, TClass *cl) const
Definition: TCling.cxx:435
virtual void GenericError(const char *error) const
Let the interpreter issue a generic error, and set its error state.
Definition: TCling.cxx:6230
void ClearStack()
Delete existing temporary values.
Definition: TCling.cxx:2493
virtual const char * GetDirEntry(void *dirp)
Get a directory entry. Returns 0 if no more entries.
Definition: TSystem.cxx:848
virtual void ClassInfo_Init(ClassInfo_t *info, const char *funcname) const
Definition: TCling.cxx:7015
void ResetAll()
Reset the Cling state to its initial state.
Definition: TCling.cxx:3008
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:4617
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:6726
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:3878
THashTable implements a hash table to store TObject&#39;s.
Definition: THashTable.h:39
const char * TCling__GetClassSharedLibs(const char *className)
Definition: TCling.cxx:612
clang::NamespaceDecl * TCling__DEBUG__DCtoNamespace(clang::DeclContext *DC)
Definition: TCling.cxx:205
const Config_t & GetConfig() const
Definition: TMetaUtils.cxx:327
void ExecuteWithArgsAndReturn(TMethod *method, void *address, const void *args[]=0, int nargs=0, void *ret=0) const
Definition: TCling.cxx:4477
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:3923
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString...
Definition: TString.cxx:2335
virtual TypedefInfo_t * TypedefInfo_Factory() const
Definition: TCling.cxx:8111
virtual Long_t BaseClassInfo_Property(BaseClassInfo_t *bcinfo) const
Definition: TCling.cxx:7257
virtual void Sleep(UInt_t milliSec)
Sleep milliSec milli seconds.
Definition: TSystem.cxx:442
THashList implements a hybrid collection class consisting of a hash table and a list to store TObject...
Definition: THashList.h:36
Bool_t CheckClassInfo(const char *name, Bool_t autoload, Bool_t isClassOrNamespaceOnly=kFALSE)
Checks if an entity with the specified name is defined in Cling.
Definition: TCling.cxx:3398
std::atomic< TList * > fBase
Definition: TClass.h:182
virtual void CallFunc_Exec(CallFunc_t *func, void *address) const
Definition: TCling.cxx:6636
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:2506
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:7576
void ShortType(std::string &answer, int mode)
Return the absolute type of typeDesc into the string answ.
Definition: TClassEdit.cxx:198
void GetInterpreterTypeName(const char *name, std::string &output, Bool_t full=kFALSE)
The &#39;name&#39; is known to the interpreter, this function returns the internal version of this name (usua...
Definition: TCling.cxx:4292
The TNamed class is the base class for all named ROOT classes.
Definition: TNamed.h:33
void SetObjectValidity(EObjectPointerState val)
const char * Title()
void CreateListOfDataMembers(TClass *cl) const
Create list of pointers to data members for TClass cl.
Definition: TCling.cxx:3649
void SetArgs(const char *args)
char * DemangleName(const char *mangled_name, int &errorCode)
Definition: TClassEdit.h:197
void * GetInterfaceMethodWithPrototype(TClass *cl, const char *method, const char *proto, Bool_t objectIsConst=kFALSE, ROOT::EFunctionMatchMode mode=ROOT::kConversionMatch)
Return pointer to cling interface function for a method of a class with a certain prototype...
Definition: TCling.cxx:4202
virtual void ClassInfo_DeleteArray(ClassInfo_t *info, void *arena, bool dtorOnly) const
Definition: TCling.cxx:6952
long ClassProperty() const
DeclId_t GetFunctionWithPrototype(ClassInfo_t *cl, const char *method, const char *proto, Bool_t objectIsConst=kFALSE, ROOT::EFunctionMatchMode mode=ROOT::kConversionMatch)
Return pointer to cling interface function for a method of a class with a certain prototype...
Definition: TCling.cxx:4247
void Init(TClassEdit::TInterpreterLookupHelper *helper)
Definition: TClassEdit.cxx:119
virtual MethodInfo_t * MethodInfo_FactoryCopy(MethodInfo_t *minfo) const
Definition: TCling.cxx:7731
void ClearFileBusy()
Reset the interpreter internal state in case a previous action was not correctly terminated.
Definition: TCling.cxx:2485
virtual Int_t Lock()=0
static void UpdateClassInfo(char *name, Long_t tagnum)
No op: see TClingCallbacks.
Definition: TCling.cxx:5720
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:3541
virtual const char * GetDynamicPath()
Return the dynamic path (used to find shared libraries).
Definition: TSystem.cxx:1757
virtual Long_t DataMemberInfo_Offset(DataMemberInfo_t *dminfo) const
Definition: TCling.cxx:7378
TString fSharedLibs
Definition: TCling.h:104
virtual Bool_t Declare(const char *code)=0
virtual const char CINT not applicable to cling
Definition: TInterpreter.h:218
bool Append(const std::string &str)
Append string to the storage if not added already.
Definition: TCling.cxx:1031
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 &quot;filename&quot;...
Definition: TSystem.cxx:2804
virtual const char * ClassInfo_FileName(ClassInfo_t *info) const
Definition: TCling.cxx:7144
virtual const char * TypeInfo_Name(TypeInfo_t *) const
Definition: TCling.cxx:8058
virtual const char * Getenv(const char *env)
Get environment variable.
Definition: TSystem.cxx:1627
virtual const char * MapCppName(const char *) const
Interface to cling function.
Definition: TCling.cxx:6315
TEnv * fMapfile
Definition: TCling.h:108
EFunctionMatchMode
Definition: TDictionary.h:155
void Info(const char *location, const char *msgfmt,...)
static bool IsEnum(cling::Interpreter *interp, const char *name)
virtual const char * PrependPathName(const char *dir, TString &name)
Concatenate a directory and a file name.
Definition: TSystem.cxx:1055
virtual const char * GetCurrentMacroName() const
Return the file name of the currently interpreted file, included or not.
Definition: TCling.cxx:4555
virtual int SetClassAutoloading(int) const
Enable/Disable the Autoloading of libraries.
Definition: TCling.cxx:6347
ULong64_t fTransactionCount
Definition: TCling.h:138
const char * GetDefault() const
Get default value of method argument.
Definition: TMethodArg.cxx:58
virtual bool ClassInfo_IsBase(ClassInfo_t *info, const char *name) const
Definition: TCling.cxx:7033
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:7244
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:4147
virtual int MethodInfo_NArg(MethodInfo_t *minfo) const
Definition: TCling.cxx:7754
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:6397
const char * TypeName() const
Long_t ProcessLine(const char *line, EErrorCode *error=0)
Definition: TCling.cxx:1908
virtual Long_t ClassInfo_Property(ClassInfo_t *info) const
Definition: TCling.cxx:7120
virtual bool Update(DataMemberInfo_t *info)
Update the TFunction to reflect the new info.
R__EXTERN int optind
Definition: TCling.cxx:305
Emulation of the CINT TypeInfo class.
virtual int TypedefInfo_Next(TypedefInfo_t *tinfo) const
Definition: TCling.cxx:8152
virtual bool TypeInfo_IsValid(TypeInfo_t *tinfo) const
Definition: TCling.cxx:8050
cling::Interpreter * GetInterpreter()
Definition: TCling.h:160
Book space in a file, create I/O buffers, to fill them, (un)compress them.
Definition: TKey.h:30
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:925
clang::RecordDecl * TCling__DEBUG__DCtoRecordDecl(clang::DeclContext *DC)
Definition: TCling.cxx:208
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:784
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:3990
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:5048
void InitRootmapFile(const char *name)
Create a resource table and read the (possibly) three resource files, i.e $ROOTSYS/etc/system&lt;name&gt; (...
Definition: TCling.cxx:4720
std::string GetModuleFileName(const char *moduleName)
Return the dictionary file name for a module.
std::string GetLong64_Name(const char *original)
Replace &#39;long long&#39; and &#39;unsigned long long&#39; by &#39;Long64_t&#39; and &#39;ULong64_t&#39;.
Definition: TClassEdit.cxx:817
void InspectMembers(TMemberInspector &, const void *obj, const TClass *cl, Bool_t isTransient)
Visit all members over members, recursing over base classes.
Definition: TCling.cxx:2106
void Error(const char *location, const char *msgfmt,...)
virtual bool ClassInfo_IsEnum(const char *name) const
Definition: TCling.cxx:7041
static void TCling__UpdateClassInfo(const NamedDecl *TD)
Update TClingClassInfo for a class (e.g. upon seeing a definition).
Definition: TCling.cxx:355
void * InterfaceMethod()
void TCling__DEBUG__printName(clang::Decl *D)
Definition: TCling.cxx:223
EComplexType GetComplexType(const char *)
Definition: TClassEdit.cxx:97
long ExtraProperty() const
virtual Long_t DataMemberInfo_TypeProperty(DataMemberInfo_t *dminfo) const
Definition: TCling.cxx:7394
TCppMethod_t GetMethod(TCppScope_t scope, TCppIndex_t imeth)
Definition: Cppyy.cxx:722
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:131
void PrintIntro()
No-op; see TRint instead.
Definition: TCling.cxx:2083
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:583
const Decl * TCling__GetObjectDecl(TObject *obj)
Definition: TCling.cxx:585
R__EXTERN TROOT * gROOTLocal
Definition: TROOT.h:376
void UpdateListOfTypes()
No op: see TClingCallbacks (used to update the list of types)
Definition: TCling.cxx:3181
virtual const char * TypeInfo_TrueName(TypeInfo_t *tinfo) const
Definition: TCling.cxx:8090
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:7836
const char * Name() const
RooArgSet S(const RooAbsArg &v1)
Definition: TEnv.h:91
const char * TmpltName() const
UInt_t AutoParseImplRecurse(const char *cls, bool topLevel)
Helper routine for TCling::AutoParse implementing the actual call to the parser and looping over temp...
Definition: TCling.cxx:5345
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:6816
const char * TmpltName() const
void Init(const char *name)
bool TCling__TEST_isInvalidDecl(clang::Decl *D)
Definition: TCling.cxx:238
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:5477
virtual bool MethodInfo_IsValid(MethodInfo_t *minfo) const
Definition: TCling.cxx:7746
int MaxIndex(int dim) const
void TCling__SplitAclicMode(const char *fileName, string &mode, string &args, string &io, string &fname)
Definition: TCling.cxx:636
std::vector< std::string > fElements
Definition: TClassEdit.h:140
static double C[]
const char * GetName() const
Returns name of object.
Definition: TEnv.h:113
int Size() const
virtual Long_t TypeInfo_Property(TypeInfo_t *tinfo) const
Definition: TCling.cxx:8066
Emulation of the CINT BaseClassInfo class.
TClingMethodInfo * FactoryMethod() const
R__EXTERN TSystem * gSystem
Definition: TSystem.h:549
if object ctor succeeded but object should not be used
Definition: TObject.h:63
void * InterfaceMethod(const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt) const
virtual const char * DataMemberInfo_TypeTrueName(DataMemberInfo_t *dminfo) const
Definition: TCling.cxx:7418
ptrdiff_t Offset(void *address=0, bool isDerivedObject=true) const
virtual void GetFunctionName(const clang::FunctionDecl *decl, std::string &name) const
Definition: TCling.cxx:7490
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:3565
std::set< TClass * > & GetModTClasses()
Definition: TCling.h:510
virtual int TypeInfo_Size(TypeInfo_t *tinfo) const
Definition: TCling.cxx:8082
static void UpdateAllCanvases()
Update all canvases at end the terminal input command.
Definition: TCling.cxx:5735
const clang::FunctionDecl * GetMethodDecl() const
const char * TrueName(const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt) const
Return the normalized name of the type (i.e.
ClassInfo_t * GetClassInfo() const
Definition: TClass.h:391
virtual CallFunc_t * CallFunc_Factory() const
Definition: TCling.cxx:6695
Long_t fMemVirtual
Definition: TSystem.h:207
const char * DefaultValue() const
const T * GetAnnotatedRedeclarable(const T *Redecl)
Definition: TMetaUtils.h:612
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:538
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:6130
int TCling__AutoParseCallback(const char *className)
Definition: TCling.cxx:607
virtual const char * DataMemberInfo_ValidArrayIndex(DataMemberInfo_t *dminfo) const
Definition: TCling.cxx:7442
void SaveGlobalsContext()
Save the current Cling state of global objects.
Definition: TCling.cxx:3154
void UpdateClassInfoWithDecl(const void *vTD)
Internal function. Inform a TClass about its new TagDecl or NamespaceDecl.
Definition: TCling.cxx:5647
unsigned int UInt_t
Definition: RtypesCore.h:42
virtual Long_t BaseClassInfo_Tagnum(BaseClassInfo_t *bcinfo) const
Definition: TCling.cxx:7273
Bool_t TestBit(UInt_t f) const
Definition: TObject.h:157
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:7170
void UpdateListOfLoadedSharedLibraries()
Definition: TCling.cxx:2663
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:6824
static double P[]
virtual TypeInfo_t * MethodInfo_Type(MethodInfo_t *minfo) const
Definition: TCling.cxx:7794
Long_t Calc(const char *line, EErrorCode *error=0)
Directly execute an executable statement (e.g.
Definition: TCling.cxx:2886
Double_t E()
Definition: TMath.h:54
Int_t RescanLibraryMap()
Scan again along the dynamic path for library maps.
Definition: TCling.cxx:4975
ROOT::ESTLType IsSTLCont(const clang::RecordDecl &cl)
type : type name: vector&lt;list&lt;classA,allocator&gt;,allocator&gt; 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:6270
virtual bool TypedefInfo_IsValid(TypedefInfo_t *tinfo) const
Definition: TCling.cxx:8144
virtual Bool_t LoadText(const char *text) const
Load the declarations from text into the interpreter.
Definition: TCling.cxx:6307
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:7770
clang::QualType GetQualType() const
const std::string sname
Definition: testIO.cxx:45
virtual int MethodInfo_NDefaultArg(MethodInfo_t *minfo) const
Definition: TCling.cxx:7762
virtual int MethodArgInfo_Next(MethodArgInfo_t *marginfo) const
Definition: TCling.cxx:7958
void TCling__PrintStackTrace()
Print a StackTrace!
Definition: TCling.cxx:348
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:5537
Version_t GetClassVersion() const
Definition: TClass.h:382
Long_t ExecuteMacro(const char *filename, EErrorCode *error=0)
Execute a cling macro.
Definition: TCling.cxx:4495
virtual void Initialize()
Initialize the interpreter, once TROOT::fInterpreter is set.
Definition: TCling.cxx:1221
Bool_t CheckClassTemplate(const char *name)
Return true if there is a class template by the given name ...
Definition: TCling.cxx:3521
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:6851
void Warning(const char *location, const char *msgfmt,...)
void SetPathsForRelocatability(std::vector< std::string > &clingArgs)
Organise the parameters for cling in order to guarantee relocatability It treats the gcc toolchain an...
TString fName
Definition: TNamed.h:36
bool IsStdClass(const char *type)
return true if the class belongs to the std namespace
virtual void FreeDirectory(void *dirp)
Free a directory.
Definition: TSystem.cxx:840
virtual const char * MethodInfo_GetPrototype(MethodInfo_t *minfo) const
Definition: TCling.cxx:7812
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:6660
TObject * TCling__GetObjectAddress(const char *Name, void *&LookupCtx)
Definition: TCling.cxx:581
virtual Bool_t FuncTempInfo_IsValid(FuncTempInfo_t *) const
Check validity of a FuncTempInfo_t.
Definition: TCling.cxx:7553
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:2532
Type
enumeration specifying the integration types.
Bool_t fLockProcessLine
Definition: TCling.h:117
R__DLLEXPORT void DestroyInterpreter(TInterpreter *interp)
Definition: TCling.cxx:595
bool IsAutoloadingEnabled()
const char * TypeName() const
TDictionary::DeclId_t DeclId_t
Definition: TListOfEnums.h:63
#define R__LOCKGUARD2(mutex)
virtual void CallFunc_Delete(CallFunc_t *func) const
Definition: TCling.cxx:6629
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:2104
std::unordered_set< const clang::NamespaceDecl * > fNSFromRootmaps
Definition: TCling.h:115
virtual const char * BaseClassInfo_FullName(BaseClassInfo_t *bcinfo) const
Definition: TCling.cxx:7281
virtual MethodInfo_t * MethodInfo_Factory() const
Definition: TCling.cxx:7705
void TCling__GetNormalizedContext(const ROOT::TMetaUtils::TNormalizedCtxt *&normCtxt)
Definition: TCling.cxx:546
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:1960
void EndOfLineAction()
It calls a &quot;fantom&quot; method to synchronize user keyboard input and ROOT prompt line.
Definition: TCling.cxx:2544
std::string GetMangledName() const
const char * Name(const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt) const
long Long_t
Definition: RtypesCore.h:50
Bool_t IsLoaded() const
Return true if the shared library of this class is currently in the a process&#39;s memory.
Definition: TClass.cxx:5535
void SetClassInfo(TClass *cl, Bool_t reload=kFALSE)
Set pointer to the TClingClassInfo in TClass.
Definition: TCling.cxx:3295
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:7974
virtual const char * ClassInfo_Name(ClassInfo_t *info) const
Definition: TCling.cxx:7162
virtual const char * GetIncludePath()
Get the list of include path.
Definition: TSystem.cxx:3798
virtual bool DataMemberInfo_IsValid(DataMemberInfo_t *dminfo) const
Definition: TCling.cxx:7354
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:692
TInterpreterValue * CreateTemporary()
The created temporary must be deleted by the caller.
Definition: TCling.cxx:6444
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:4166
void UpdateListsOnUnloaded(const cling::Transaction &T)
Definition: TCling.cxx:5884
virtual FuncTempInfo_t * FuncTempInfo_Factory(DeclId_t declid) const
Construct a FuncTempInfo_t.
Definition: TCling.cxx:7531
TObjArray * fStreamerInfo
Definition: TClass.h:179
double f(double x)
virtual void FuncTempInfo_Title(FuncTempInfo_t *, TString &name) const
Return the comments associates with this function template.
Definition: TCling.cxx:7658
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:3676
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:5831
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:567
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:1946
TText * text
static DictFuncPtr_t GetDict(const char *cname)
Given the class name returns the Dictionary() function of a class (uses hash of name).
virtual Bool_t ClassInfo_Contains(ClassInfo_t *info, DeclId_t declid) const
Return true if the entity pointed to by &#39;declid&#39; is declared in the context described by &#39;info&#39;...
Definition: TCling.cxx:6908
TFunction * Find(DeclId_t id) const
Return the TMethod or TFunction describing the function corresponding to the Decl &#39;id&#39;...
virtual const char * DataMemberInfo_Name(DataMemberInfo_t *dminfo) const
Definition: TCling.cxx:7426
void Unload()
Mark &#39;all func&#39; as being unloaded.
virtual int DataMemberInfo_ArrayDim(DataMemberInfo_t *dminfo) const
Definition: TCling.cxx:7312
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:1841
Bool_t IsAutoLoadNamespaceCandidate(const char *name)
Definition: TCling.cxx:5629
virtual void CallFunc_ResetArg(CallFunc_t *func) const
Definition: TCling.cxx:6752
virtual void FuncTempInfo_Delete(FuncTempInfo_t *) const
Delete the FuncTempInfo_t.
Definition: TCling.cxx:7522
TDictionary::DeclId_t DeclId_t
void DeleteArray(void *arena, bool dtorOnly, const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt) const
int type
Definition: TGX11.cxx:120
void ResetGlobalVar(void *obj)
Reset the Cling &#39;user&#39; global objects/variables state to the state saved by the last call to TCling::...
Definition: TCling.cxx:3038
unsigned long long ULong64_t
Definition: RtypesCore.h:70
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:4269
TNamed()
Definition: TNamed.h:40
#define free
Definition: civetweb.c:821
unsigned long ULong_t
Definition: RtypesCore.h:51
static const TString & GetEtcDir()
Get the sysconfig directory in the installation. Static utility function.
Definition: TROOT.cxx:2755
virtual Long64_t CallFunc_ExecInt64(CallFunc_t *func, void *address) const
Definition: TCling.cxx:6679
void Reset()
Pressing Ctrl+C should forward here.
Definition: TCling.cxx:2992
Int_t LoadLibraryMap(const char *rootmapfile=0)
Load map between class and library.
Definition: TCling.cxx:4785
void CreateListOfMethodArgs(TFunction *m) const
Create list of pointers to method arguments for TMethod m.
Definition: TCling.cxx:3683
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:5208
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:830
you should not use this method at all Int_t Int_t Double_t Double_t Double_t e
Definition: TRolke.cxx:630
virtual int GetSecurityError() const
Interface to cling function.
Definition: TCling.cxx:6280
#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:7738
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:2939
friend class SuspendAutoParsing
Definition: TInterpreter.h:56
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:2872
virtual void ClassInfo_Delete(ClassInfo_t *info) const
Definition: TCling.cxx:6937
void Delete(void *arena, const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt) const
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:4987
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:5379
void UpdateListOfMethods(TClass *cl) const
Update the list of pointers to method for TClass cl This is now a nop.
Definition: TCling.cxx:3667
TVirtualCollectionProxy * GetCollectionProxy() const
Return the proxy describing the collection (if any).
Definition: TClass.cxx:2801
void * New(const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt) const
virtual const char * TypedefInfo_Name(TypedefInfo_t *tinfo) const
Definition: TCling.cxx:8184
void RecursiveRemove(TObject *obj)
Delete object from cling symbol table so it can not be used anymore.
Definition: TCling.cxx:2974
TDataMember * GetDataMember(const char *datamember) const
Return pointer to datamember object with name &quot;datamember&quot;.
Definition: TClass.cxx:3212
virtual int ClassInfo_Size(ClassInfo_t *info) const
Definition: TCling.cxx:7128
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:1850
virtual Double_t CallFunc_ExecDouble(CallFunc_t *func, void *address) const
Definition: TCling.cxx:6687
TString fIncludePath
Definition: TCling.h:106
Mother of all ROOT objects.
Definition: TObject.h:37
virtual bool ClassInfo_HasMethod(ClassInfo_t *info, const char *name) const
Definition: TCling.cxx:7007
void TCling__LibraryUnloadedRTTI(const void *dyLibHandle, const char *canonicalName)
Definition: TCling.cxx:573
virtual Long_t MethodArgInfo_Property(MethodArgInfo_t *marginfo) const
Definition: TCling.cxx:7966
void RegisterTemporary(const TInterpreterValue &value)
Definition: TCling.cxx:6471
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:6262
#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:462
typedef void((*Func_t)())
Version_t fClassVersion
Definition: TClass.h:201
void Unload()
Mark &#39;all func&#39; as being unloaded.
const char * GetDeclFileName() const
Definition: TClass.h:386
virtual bool ClassInfo_IsLoaded(ClassInfo_t *info) const
Definition: TCling.cxx:7048
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:4059
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:7820
const char * GetUnqualifiedName(const char *name)
Return the start of the unqualified name include in &#39;original&#39;.
Definition: TClassEdit.cxx:851
const char * GetFullTypeName() const
Get full type description of method argument, e.g.: &quot;class TDirectory*&quot;.
Definition: TMethodArg.cxx:75
void Unload()
Mark &#39;all func&#39; as being unloaded.
A collection of TEnum objects designed for fast access given a DeclId_t and for keep track of TEnum t...
Definition: TListOfEnums.h:36
TDictionary::DeclId_t DeclId_t
ClassInfo_t * fClassInfo
Definition: TClass.h:202
const char * Data()
Definition: TCling.cxx:1023
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
long Property() const
virtual bool ClassInfo_IsValid(ClassInfo_t *info) const
Definition: TCling.cxx:7056
void ReplaceAll(std::string &str, const std::string &from, const std::string &to, bool recurse=false)
virtual Long_t ClassInfo_Tagnum(ClassInfo_t *info) const
Definition: TCling.cxx:7136
Bool_t fHeaderParsingOnDemand
Definition: TCling.h:147
virtual Long_t MethodInfo_ExtraProperty(MethodInfo_t *minfo) const
Definition: TCling.cxx:7786
void MakeZombie()
Definition: TObject.h:47
Each ROOT class (see TClass) has a linked list of methods.
Definition: TMethod.h:40
std::vector< std::pair< TClass *, DictFuncPtr_t > > fClassesToUpdate
Definition: TCling.h:136
std::string AtlernateTuple(const char *classname)
Definition: TCling.cxx:3229
virtual void CallFunc_IgnoreExtraArgs(CallFunc_t *func, bool ignore) const
Definition: TCling.cxx:6718
virtual const char * GetSTLIncludePath() const
Return the directory containing CINT&#39;s stl cintdlls.
Definition: TCling.cxx:6175
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:7828
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:5128
#define snprintf
Definition: civetweb.c:822
Bool_t IsLoaded(const char *filename) const
Return true if the file has already been loaded by cint.
Definition: TCling.cxx:2557
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:6960
virtual const char * ClassInfo_FullName(ClassInfo_t *info) const
Definition: TCling.cxx:7152
virtual void UpdateEnumConstants(TEnum *enumObj, TClass *cl) const
Definition: TCling.cxx:387
virtual void * OpenDirectory(const char *name)
Open a directory. Returns 0 if directory does not exist.
Definition: TSystem.cxx:831
const char * proto
Definition: civetweb.c:11652
R__EXTERN Int_t gDebug
Definition: Rtypes.h:128
ROOT::ESTLType GetCollectionType() const
Return the &#39;type&#39; of the STL the TClass is representing.
Definition: TClass.cxx:2790
Bool_t SetSuspendAutoParsing(Bool_t value)
Suspend the Autoparsing of headers.
Definition: TCling.cxx:6373
virtual const char * BaseClassInfo_TmpltName(BaseClassInfo_t *bcinfo) const
Definition: TCling.cxx:7299
virtual const char * MethodArgInfo_Name(MethodArgInfo_t *marginfo) const
Definition: TCling.cxx:7982
virtual const char * ClassInfo_TmpltName(ClassInfo_t *info) const
Definition: TCling.cxx:7178
int RefType() const
static const std::string ioname("ioname")
virtual int Evaluate(const char *, TInterpreterValue &)
Get the interpreter value corresponding to the statement.
Definition: TCling.cxx:6461
static bool R__InitStreamerInfoFactory()
Helper to initialize TVirtualStreamerInfo&#39;s factor early.
Definition: TCling.cxx:1264
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:6116
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:5726
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:4629
void ResetBit(UInt_t f)
Definition: TObject.h:156
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:909
std::hash< std::string > fStringHashFunction
Definition: TCling.h:114
virtual void TypedefInfo_Init(TypedefInfo_t *tinfo, const char *name) const
Definition: TCling.cxx:8134
const char * GetSharedLibs()
Return the list of shared libraries loaded into the process.
Definition: TCling.cxx:6034
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:1229
virtual EReturnType MethodInfo_MethodCallReturnType(MethodInfo_t *minfo) const
Definition: TCling.cxx:7866
R__EXTERN TInterpreter * gCling
Definition: TInterpreter.h:519
R__DLLEXPORT TInterpreter * CreateInterpreter(void *interpLibHandle)
Definition: TCling.cxx:589
virtual void * FindSym(const char *entry) const
Interface to cling function.
Definition: TCling.cxx:6222
void CodeComplete(const std::string &, size_t &, std::vector< std::string > &)
The call to Cling&#39;s tab complition.
Definition: TCling.cxx:6453
virtual void Compress()
Remove empty slots from array.
Definition: TObjArray.cxx:309
#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:2861
virtual void DataMemberInfo_Delete(DataMemberInfo_t *dminfo) const
Definition: TCling.cxx:7320
const Bool_t kTRUE
Definition: Rtypes.h:91
void TCling__TransactionRollback(const cling::Transaction &T)
Definition: TCling.cxx:563
virtual const char * GetTitle() const
Returns title of object.
Definition: TObject.cxx:460
TList * GetListOfMethods(Bool_t load=kTRUE)
Return list containing the TMethods of a class.
Definition: TClass.cxx:3598
std::string NormalizedName(const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt) const
Return the normalized name of the type (i.e.
void Unload()
Mark &#39;all func&#39; as being unloaded.
virtual char * ConcatFileName(const char *dir, const char *name)
Concatenate a directory and a file name. User must delete returned string.
Definition: TSystem.cxx:1045
void LoadMacro(const char *filename, EErrorCode *error=0)
Load a macro file in cling&#39;s memory.
Definition: TCling.cxx:2853
virtual ClassInfo_t * BaseClassInfo_ClassInfo(BaseClassInfo_t *) const
Definition: TCling.cxx:7265
static DictFuncPtr_t GetDictNorm(const char *cname)
Given the normalized class name returns the Dictionary() function of a class (uses hash of name)...
static ETupleOrdering IsTupleAscending()
Definition: TCling.cxx:3205
const char * TypeName(const char *typeDesc)
Return the absolute type of typeDesc.
Definition: TCling.cxx:4570
virtual EReturnType MethodCallReturnType(TFunction *func) const
Definition: TCling.cxx:7855
static char * skip(char **buf, const char *delimiters)
Definition: civetweb.c:2039
Double_t ex[n]
Definition: legend1.C:17
void LibraryUnloaded(const void *dyLibHandle, const char *canonicalName)
Definition: TCling.cxx:6026
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:3053
virtual MethodArgInfo_t * MethodArgInfo_FactoryCopy(MethodArgInfo_t *marginfo) const
Definition: TCling.cxx:7942
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:2092
void CreateListOfMethods(TClass *cl) const
Create list of pointers to methods for TClass cl.
Definition: TCling.cxx:3658
Int_t DeleteGlobal(void *obj)
Delete obj from Cling symbol table so it cannot be accessed anymore.
Definition: TCling.cxx:3067
TRandom3 R
a TMatrixD.
Definition: testIO.cxx:28
virtual TypeInfo_t * TypeInfo_Factory() const
Definition: TCling.cxx:8018
virtual const char * MethodArgInfo_TypeName(MethodArgInfo_t *marginfo) const
Definition: TCling.cxx:7990
TDictionary::DeclId_t GetDeclId() const
virtual void SetErrmsgcallback(void *p) const
Set a callback to receive error messages.
Definition: TCling.cxx:6383
void ResetGlobals()
Reset in Cling the list of global variables to the state saved by the last call to TCling::SaveGlobal...
Definition: TCling.cxx:3024
virtual const char * TypedefInfo_Title(TypedefInfo_t *tinfo) const
Definition: TCling.cxx:8192
char name[80]
Definition: TGX11.cxx:109
Int_t Size() const
Return size of object of this class.
Definition: TClass.cxx:5334
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:6328
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:6760
if(line.BeginsWith("/*"))
Definition: HLFactory.cxx:443
virtual Long_t FuncTempInfo_Property(FuncTempInfo_t *) const
Return the property of the function template.
Definition: TCling.cxx:7586
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:7346
void ExecWithReturn(void *address, void *ret=0)
virtual int UnloadFile(const char *path) const
Definition: TCling.cxx:6427
virtual int DataMemberInfo_Next(DataMemberInfo_t *dminfo) const
Definition: TCling.cxx:7370
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:2870
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:6991
TList * GetListOfFunctionTemplates(Bool_t load=kTRUE)
Return list containing the TEnums of a class.
Definition: TClass.cxx:3584
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:7645
virtual void TypedefInfo_Delete(TypedefInfo_t *tinfo) const
Definition: TCling.cxx:8104
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition: TObject.cxx:911