ROOT  6.06/08
Reference Guide
TMetaUtils.h
Go to the documentation of this file.
1 // @(#)root/metautils:$Id$
2 // Author: Axel Naumann, Nov 2011
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2011, 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 #ifndef ROOT_TMetaUtils
13 #define ROOT_TMetaUtils
14 
15 #include "RConversionRuleParser.h"
16 
17 #include <set>
18 #include <string>
19 #include <unordered_set>
20 
21 //#include <atomic>
22 #include <stdlib.h>
23 
24 namespace llvm {
25  class StringRef;
26 }
27 
28 namespace clang {
29  class ASTContext;
30  class Attr;
31  class ClassTemplateDecl;
32  class ClassTemplateSpecializationDecl;
33  class CompilerInstance;
34  class CXXBaseSpecifier;
35  class CXXRecordDecl;
36  class Decl;
37  class DeclContext;
38  class DeclaratorDecl;
39  class FieldDecl;
40  class FunctionDecl;
41  class Module;
42  class NamedDecl;
43  class ParmVarDecl;
44  class PresumedLoc;
45  class QualType;
46  class RecordDecl;
47  class SourceLocation;
48  class TagDecl;
49  class TemplateDecl;
50  class TemplateName;
51  class TemplateArgument;
52  class TemplateArgumentList;
53  class TemplateParameterList;
54  class Type;
55  class TypeDecl;
56  class TypedefNameDecl;
57  struct PrintingPolicy;
58 }
59 
60 namespace cling {
61  class Interpreter;
62  class LookupHelper;
63  namespace utils {
64  namespace Transform {
65  struct Config;
66  }
67  }
68 }
69 
70 // For ROOT::ESTLType
71 #include "ESTLType.h"
72 
73 // for TClassEdit::TInterpreterLookupHelper
74 #include "TClassEdit.h"
75 
76 #ifndef ROOT_Varargs
77 #include "Varargs.h"
78 #endif
79 
80 namespace ROOT {
81  namespace TMetaUtils {
82 
83 // Forward Declarations --------------------------------------------------------
84 class AnnotatedRecordDecl;
85 
86 // Constants, typedefs and Enums -----------------------------------------------
87 
88 // Convention for the ROOT relevant properties
89 namespace propNames{
90  static const std::string separator("@@@");
91  static const std::string iotype("iotype");
92  static const std::string name("name");
93  static const std::string pattern("pattern");
94  static const std::string ioname("ioname");
95  static const std::string comment("comment");
96  static const std::string nArgsToKeep("nArgsToKeep");
97  static const std::string persistent("persistent");
98  static const std::string transient("transient");
99 }
100 
101 extern int gErrorIgnoreLevel;
102 
103 // Get the array index information for a data member.
105 
107  const cling::Interpreter &interp,
108  const TNormalizedCtxt &normCtxt,
109  std::ostream& dictStream,
110  bool isAutoStreamer);
111 
112 const int kInfo = 0;
113 const int kNote = 500;
114 const int kThrowOnWarning = 999;
115 const int kWarning = 1000;
116 const int kError = 2000;
117 const int kSysError = 3000;
118 const int kFatal = 4000;
119 const int kMaxLen = 1024;
120 
121 // Classes ---------------------------------------------------------------------
122 class TNormalizedCtxtImpl;
123 
124 //______________________________________________________________________________
126 private:
127  TNormalizedCtxtImpl* fImpl;
128 public:
129  using Config_t = cling::utils::Transform::Config;
130  using TypesCont_t = std::set<const clang::Type*>;
131  using TemplPtrIntMap_t = std::map<const clang::ClassTemplateDecl*, int>;
132 
133  TNormalizedCtxt(const cling::LookupHelper &lh);
134  TNormalizedCtxt(const TNormalizedCtxt& other);
135  ~TNormalizedCtxt();
136  const Config_t& GetConfig() const;
137  const TypesCont_t &GetTypeWithAlternative() const;
138 
139  void AddTemplAndNargsToKeep(const clang::ClassTemplateDecl* templ, unsigned int i);
140  int GetNargsToKeep(const clang::ClassTemplateDecl* templ) const;
141  const TemplPtrIntMap_t GetTemplNargsToKeepMap() const;
142  void keepTypedef(const cling::LookupHelper &lh, const char* name,
143  bool replace = false);
144 };
145 
146 //______________________________________________________________________________
148 public:
149  typedef bool (*ExistingTypeCheck_t)(const std::string &tname, std::string &result);
150  typedef bool (*AutoParse_t)(const char *name);
151 
152 private:
153  cling::Interpreter *fInterpreter;
155  ExistingTypeCheck_t fExistingTypeCheck;
156  AutoParse_t fAutoParse;
157  const int *fPDebug; // debug flag, might change at runtime thus *
158  bool WantDiags() const { return fPDebug && *fPDebug > 5; }
159 
160 public:
161  TClingLookupHelper(cling::Interpreter &interpreter, TNormalizedCtxt &normCtxt,
162  ExistingTypeCheck_t existingTypeCheck,
163  AutoParse_t autoParse,
164  const int *pgDebug = 0);
165  virtual ~TClingLookupHelper() { /* we're not owner */ }
166 
167  virtual bool ExistingTypeCheck(const std::string &tname, std::string &result);
168  virtual void GetPartiallyDesugaredName(std::string &nameLong);
169  virtual bool IsAlreadyPartiallyDesugaredName(const std::string &nondef, const std::string &nameLong);
170  virtual bool IsDeclaredScope(const std::string &base, bool &isInlined);
171  virtual bool GetPartiallyDesugaredNameWithScopeHandling(const std::string &tname, std::string &result);
172 };
173 
174 //______________________________________________________________________________
176 private:
178  const clang::RecordDecl* fDecl;
179  std::string fRequestedName;
180  std::string fNormalizedName;
186 
187 public:
188  enum ERootFlag {
189  kNoStreamer = 0x01,
190  kNoInputOperator = 0x02,
191  kUseByteCount = 0x04,
192  kStreamerInfo = 0x04,
193  kHasVersion = 0x08
194  };
195 
196  AnnotatedRecordDecl(long index,
197  const clang::RecordDecl *decl,
198  bool rStreamerInfo,
199  bool rNoStreamer,
200  bool rRequestNoInputOperator,
201  bool rRequestOnlyTClass,
202  int rRequestedVersionNumber,
203  const cling::Interpreter &interpret,
204  const TNormalizedCtxt &normCtxt);
205 
206  AnnotatedRecordDecl(long index,
207  const clang::RecordDecl *decl,
208  const char *requestName,
209  bool rStreamerInfo,
210  bool rNoStreamer,
211  bool rRequestNoInputOperator,
212  bool rRequestOnlyTClass,
213  int rRequestedVersionNumber,
214  const cling::Interpreter &interpret,
215  const TNormalizedCtxt &normCtxt);
216 
217  AnnotatedRecordDecl(long index,
218  const clang::Type *requestedType,
219  const clang::RecordDecl *decl,
220  const char *requestedName,
221  bool rStreamerInfo,
222  bool rNoStreamer,
223  bool rRequestNoInputOperator,
224  bool rRequestOnlyTClass,
225  int rRequestedVersionNumber,
226  const cling::Interpreter &interpret,
227  const TNormalizedCtxt &normCtxt);
228 
229  AnnotatedRecordDecl(long index,
230  const clang::Type *requestedType,
231  const clang::RecordDecl *decl,
232  const char *requestedName,
233  unsigned int nTemplateArgsToSkip,
234  bool rStreamerInfo,
235  bool rNoStreamer,
236  bool rRequestNoInputOperator,
237  bool rRequestOnlyTClass,
238  int rRequestedVersionNumber,
239  const cling::Interpreter &interpret,
240  const TNormalizedCtxt &normCtxt);
241 
243  // Nothing to do we do not own the pointer;
244  }
245 
246 
247  long GetRuleIndex() const { return fRuleIndex; }
248 
249  const char *GetRequestedName() const { return fRequestedName.c_str(); }
250  const char *GetNormalizedName() const { return fNormalizedName.c_str(); }
251  bool HasClassVersion() const { return fRequestedVersionNumber >=0 ; }
252  bool RequestStreamerInfo() const {
253  // Equivalent to CINT's cl.RootFlag() & G__USEBYTECOUNT
254  return fRequestStreamerInfo;
255  }
256  bool RequestNoInputOperator() const { return fRequestNoInputOperator; }
257  bool RequestNoStreamer() const { return fRequestNoStreamer; }
258  bool RequestOnlyTClass() const { return fRequestOnlyTClass; }
259  int RequestedVersionNumber() const { return fRequestedVersionNumber; }
260  int RootFlag() const {
261  // Return the request (streamerInfo, has_version, etc.) combined in a single
262  // int. See RScanner::AnnotatedRecordDecl::ERootFlag.
263  int result = 0;
264  if (fRequestNoStreamer) result = kNoStreamer;
265  if (fRequestNoInputOperator) result |= kNoInputOperator;
266  if (fRequestStreamerInfo) result |= kStreamerInfo;
267  if (fRequestedVersionNumber > -1) result |= kHasVersion;
268  return result;
269  }
270  const clang::RecordDecl* GetRecordDecl() const { return fDecl; }
271 
272  operator clang::RecordDecl const *() const {
273  return fDecl;
274  }
275 
276  bool operator<(const AnnotatedRecordDecl& right) const
277  {
278  return fRuleIndex < right.fRuleIndex;
279  }
280 
281  struct CompareByName {
282  bool operator() (const AnnotatedRecordDecl& right, const AnnotatedRecordDecl& left)
283  {
284  return left.fNormalizedName < right.fNormalizedName;
285  }
286  };
287 };
288 
289 //______________________________________________________________________________
291 private:
292  const std::string fArgTypeName;
293  const clang::CXXRecordDecl *fArgType;
294 
295 public:
296  RConstructorType(const char *type_of_arg, const cling::Interpreter&);
297 
298  const char *GetName() const ;
299  const clang::CXXRecordDecl *GetType() const;
300 };
301 typedef std::list<RConstructorType> RConstructorTypes;
302 
303 // Functions -------------------------------------------------------------------
304 
305 //_____________________________________________________________________________
306 unsigned int GetNumberOfWarningsAndErrors();
307 
308 //______________________________________________________________________________
309 int extractAttrString(clang::Attr* attribute, std::string& attrString);
310 
311 //______________________________________________________________________________
312 int extractPropertyNameValFromString(const std::string attributeStr,std::string& attrName, std::string& attrValue);
313 
314 //______________________________________________________________________________
315 int extractPropertyNameVal(clang::Attr* attribute, std::string& attrName, std::string& attrValue);
316 
317 //______________________________________________________________________________
318 bool ExtractAttrPropertyFromName(const clang::Decl& decl,
319  const std::string& propName,
320  std::string& propValue);
321 
322 //______________________________________________________________________________
323 bool ExtractAttrIntPropertyFromName(const clang::Decl& decl,
324  const std::string& propName,
325  int& propValue);
326 
327 //______________________________________________________________________________
328 bool RequireCompleteType(const cling::Interpreter &interp, const clang::CXXRecordDecl *cl);
329 
330 //______________________________________________________________________________
331 bool RequireCompleteType(const cling::Interpreter &interp, clang::SourceLocation Loc, clang::QualType Type);
332 
333 //______________________________________________________________________________
334 // Add default template parameters.
335 clang::QualType AddDefaultParameters(clang::QualType instanceType,
336  const cling::Interpreter &interpret,
337  const TNormalizedCtxt &normCtxt);
338 
339 //______________________________________________________________________________
340 llvm::StringRef DataMemberInfo__ValidArrayIndex(const clang::DeclaratorDecl &m, int *errnum = 0, llvm::StringRef *errstr = 0);
341 
342 enum class EIOCtorCategory : short {kAbsent, kDefault, kIOPtrType, kIORefType};
343 
344 //______________________________________________________________________________
345 EIOCtorCategory CheckConstructor(const clang::CXXRecordDecl*, const RConstructorType&, const cling::Interpreter& interp);
346 
347 //______________________________________________________________________________
348 const clang::FunctionDecl* ClassInfo__HasMethod(const clang::DeclContext *cl, char const*, const cling::Interpreter& interp);
349 
350 //______________________________________________________________________________
351 void CreateNameTypeMap(clang::CXXRecordDecl const&, std::map<std::string, ROOT::Internal::TSchemaType, std::less<std::string>, std::allocator<std::pair<std::string const, ROOT::Internal::TSchemaType> > >&);
352 
353 //______________________________________________________________________________
354 int ElementStreamer(std::ostream& finalString,
355  const clang::NamedDecl &forcontext,
356  const clang::QualType &qti,
357  const char *t,
358  int rwmode,
359  const cling::Interpreter &interp,
360  const char *tcl=0);
361 
362 //______________________________________________________________________________
363 bool IsBase(const clang::CXXRecordDecl *cl, const clang::CXXRecordDecl *base, const clang::CXXRecordDecl *context,const cling::Interpreter &interp);
364 
365 //______________________________________________________________________________
366 bool IsBase(const clang::FieldDecl &m, const char* basename, const cling::Interpreter &interp);
367 
368 //______________________________________________________________________________
369 bool HasCustomOperatorNewArrayPlacement(clang::RecordDecl const&, const cling::Interpreter &interp);
370 
371 //______________________________________________________________________________
372 bool HasCustomOperatorNewPlacement(char const*, clang::RecordDecl const&, const cling::Interpreter&);
373 
374 //______________________________________________________________________________
375 bool HasCustomOperatorNewPlacement(clang::RecordDecl const&, const cling::Interpreter&);
376 
377 //______________________________________________________________________________
378 bool HasDirectoryAutoAdd(clang::CXXRecordDecl const*, const cling::Interpreter&);
379 
380 //______________________________________________________________________________
381 bool HasIOConstructor(clang::CXXRecordDecl const*, std::string&, const RConstructorTypes&, const cling::Interpreter&);
382 
383 //______________________________________________________________________________
384 bool HasNewMerge(clang::CXXRecordDecl const*, const cling::Interpreter&);
385 
386 //______________________________________________________________________________
387 bool HasOldMerge(clang::CXXRecordDecl const*, const cling::Interpreter&);
388 
389 //______________________________________________________________________________
390 bool hasOpaqueTypedef(clang::QualType instanceType, const TNormalizedCtxt &normCtxt);
391 
392 //______________________________________________________________________________
393 bool hasOpaqueTypedef(const AnnotatedRecordDecl &cl, const cling::Interpreter &interp, const TNormalizedCtxt &normCtxt);
394 
395 //______________________________________________________________________________
396 bool HasResetAfterMerge(clang::CXXRecordDecl const*, const cling::Interpreter&);
397 
398 //______________________________________________________________________________
399 bool NeedDestructor(clang::CXXRecordDecl const*);
400 
401 //______________________________________________________________________________
402 bool NeedTemplateKeyword(clang::CXXRecordDecl const*);
403 
404 //______________________________________________________________________________
405 bool CheckPublicFuncWithProto(clang::CXXRecordDecl const*, char const*, char const*,
406  const cling::Interpreter&, bool diagnose);
407 
408 //______________________________________________________________________________
409 long GetLineNumber(clang::Decl const*);
410 
411 //______________________________________________________________________________
412 bool GetNameWithinNamespace(std::string&, std::string&, std::string&, clang::CXXRecordDecl const*);
413 
414 //______________________________________________________________________________
415 void GetQualifiedName(std::string &qual_name, const clang::QualType &type, const clang::NamedDecl &forcontext);
416 
417 //----
418 std::string GetQualifiedName(const clang::QualType &type, const clang::NamedDecl &forcontext);
419 
420 //______________________________________________________________________________
421 void GetQualifiedName(std::string &qual_name, const clang::Type &type, const clang::NamedDecl &forcontext);
422 
423 //----
424 std::string GetQualifiedName(const clang::Type &type, const clang::NamedDecl &forcontext);
425 
426 //______________________________________________________________________________
427 void GetQualifiedName(std::string &qual_name, const clang::NamedDecl &nd);
428 
429 //----
430 std::string GetQualifiedName(const clang::NamedDecl &nd);
431 
432 //______________________________________________________________________________
433 void GetQualifiedName(std::string &qual_name, const AnnotatedRecordDecl &annotated);
434 
435 //----
436 std::string GetQualifiedName(const AnnotatedRecordDecl &annotated);
437 
438 //______________________________________________________________________________
439 void GetQualifiedName(std::string &qual_name, const clang::RecordDecl &recordDecl);
440 
441 //----
442 std::string GetQualifiedName(const clang::RecordDecl &recordDecl);
443 
444 //______________________________________________________________________________
445 int WriteNamespaceHeader(std::ostream&, const clang::RecordDecl *);
446 
447 //______________________________________________________________________________
448 int WriteNamespaceHeader(std::ostream&, const clang::DeclContext *);
449 
450 //______________________________________________________________________________
451 void WritePointersSTL(const AnnotatedRecordDecl &cl, const cling::Interpreter &interp, const TNormalizedCtxt &normCtxt);
452 
453 //______________________________________________________________________________
454 int GetClassVersion(const clang::RecordDecl *cl, const cling::Interpreter &interp);
455 
456 //______________________________________________________________________________
457 int IsSTLContainer(const AnnotatedRecordDecl &annotated);
458 
459 //______________________________________________________________________________
460 ROOT::ESTLType IsSTLContainer(const clang::FieldDecl &m);
461 
462 //______________________________________________________________________________
463 int IsSTLContainer(const clang::CXXBaseSpecifier &base);
464 
465 //______________________________________________________________________________
466 const char *ShortTypeName(const char *typeDesc);
467 
468 //______________________________________________________________________________
469 std::string ShortTypeName(const clang::FieldDecl &m);
470 
471 //______________________________________________________________________________
472 bool IsStreamableObject(const clang::FieldDecl &m, const cling::Interpreter& interp);
473 
474 //______________________________________________________________________________
475 clang::RecordDecl *GetUnderlyingRecordDecl(clang::QualType type);
476 
477 //______________________________________________________________________________
478 std::string TrueName(const clang::FieldDecl &m);
479 
480 //______________________________________________________________________________
481 const clang::CXXRecordDecl *ScopeSearch(const char *name,
482  const cling::Interpreter &gInterp,
483  bool diagnose,
484  const clang::Type** resultType);
485 
486 //______________________________________________________________________________
487 void WriteAuxFunctions(std::ostream& finalString,
488  const AnnotatedRecordDecl &cl,
489  const clang::CXXRecordDecl *decl,
490  const cling::Interpreter &interp,
491  const RConstructorTypes& ctorTypes,
492  const TNormalizedCtxt &normCtxt);
493 
494 
495 //______________________________________________________________________________
496 const clang::FunctionDecl *GetFuncWithProto(const clang::Decl* cinfo,
497  const char *method,
498  const char *proto,
499  const cling::Interpreter &gInterp,
500  bool diagnose);
501 
502 //______________________________________________________________________________
503 void WriteClassCode(CallWriteStreamer_t WriteStreamerFunc,
504  const AnnotatedRecordDecl &cl,
505  const cling::Interpreter &interp,
506  const TNormalizedCtxt &normCtxt,
507  std::ostream& finalString,
508  const RConstructorTypes& ctorTypes,
509  bool isGenreflex);
510 
511 //______________________________________________________________________________
512 void WriteClassInit(std::ostream& finalString,
513  const AnnotatedRecordDecl &cl,
514  const clang::CXXRecordDecl *decl,
515  const cling::Interpreter &interp,
516  const TNormalizedCtxt &normCtxt,
517  const RConstructorTypes& ctorTypes,
518  bool& needCollectionProxy);
519 
520 //______________________________________________________________________________
522  const clang::CXXRecordDecl* clxx,
523  const cling::Interpreter &interp,
524  const TNormalizedCtxt &normCtxt);
525 
526 //______________________________________________________________________________
528  const clang::CXXRecordDecl* clxx,
529  const cling::Interpreter &interp,
530  const TNormalizedCtxt &normCtxt);
531 
532 //______________________________________________________________________________
533 // Return the header file to be included to declare the Decl
534 llvm::StringRef GetFileName(const clang::Decl& decl,
535  const cling::Interpreter& interp);
536 
537 //______________________________________________________________________________
538 // Return the dictionary file name for a module
539 std::string GetModuleFileName(const char* moduleName);
540 
541 //______________________________________________________________________________
542 // Declare a virtual module.map to clang. Returns Module on success.
543 clang::Module* declareModuleMap(clang::CompilerInstance* CI,
544  const char* moduleFileName,
545  const char* headers[]);
546 
547 //______________________________________________________________________________
548 // Return (in the argument 'output') a mangled version of the C++ symbol/type (pass as 'input')
549 // that can be used in C++ as a variable name.
550 void GetCppName(std::string &output, const char *input);
551 
552 //______________________________________________________________________________
553 // Return the type with all parts fully qualified (most typedefs),
554 // including template arguments, appended to name.
555 void GetFullyQualifiedTypeName(std::string &name, const clang::QualType &type, const cling::Interpreter &interpreter);
556 
557 //______________________________________________________________________________
558 // Return the type with all parts fully qualified (most typedefs),
559 // including template arguments, appended to name, without using the interpreter
560 void GetFullyQualifiedTypeName(std::string &name, const clang::QualType &type, const clang::ASTContext &);
561 
562 //______________________________________________________________________________
563 // Return the type normalized for ROOT,
564 // keeping only the ROOT opaque typedef (Double32_t, etc.) and
565 // adding default template argument for all types except those explicitly
566 // requested to be drop by the user.
567 // Default template for STL collections are not yet removed by this routine.
568 clang::QualType GetNormalizedType(const clang::QualType &type, const cling::Interpreter &interpreter, const TNormalizedCtxt &normCtxt);
569 
570 //______________________________________________________________________________
571 // Return the type name normalized for ROOT,
572 // keeping only the ROOT opaque typedef (Double32_t, etc.) and
573 // adding default template argument for all types except the STL collections
574 // where we remove the default template argument if any.
575 void GetNormalizedName(std::string &norm_name, const clang::QualType &type, const cling::Interpreter &interpreter, const TNormalizedCtxt &normCtxt);
576 
577 //______________________________________________________________________________
578 // Alternative signature
579 void GetNormalizedName(std::string &norm_name,
580  const clang::TypeDecl* typeDecl,
581  const cling::Interpreter &interpreter);
582 
583 //______________________________________________________________________________
584 // Returns comment in a meaningful way
585 llvm::StringRef GetComment(const clang::Decl &decl, clang::SourceLocation *loc = 0);
586 
587 //______________________________________________________________________________
588 // Returns the comment of the ClassDef macro
589 llvm::StringRef GetClassComment(const clang::CXXRecordDecl &decl, clang::SourceLocation *loc, const cling::Interpreter &interpreter);
590 
591 //______________________________________________________________________________
592 // Return the base/underlying type of a chain of array or pointers type.
593 const clang::Type *GetUnderlyingType(clang::QualType type);
594 
595 //______________________________________________________________________________
596 // Scans the redeclaration chain for an annotation.
597 //
598 // returns 0 if no annotation was found.
599 //
600 template<typename T>
601 const T* GetAnnotatedRedeclarable(const T* Redecl) {
602  if (!Redecl)
603  return 0;
604 
605  Redecl = Redecl->getMostRecentDecl();
606  while (Redecl && !Redecl->hasAttrs())
607  Redecl = Redecl->getPreviousDecl();
608 
609  return Redecl;
610 }
611 
612 //______________________________________________________________________________
613 // Overload the template for typedefs, because they don't contain
614 // isThisDeclarationADefinition method. (Use inline to avoid violating ODR)
615 const clang::TypedefNameDecl* GetAnnotatedRedeclarable(const clang::TypedefNameDecl* TND);
616 
617 //______________________________________________________________________________
618 // Overload the template for tags, because we only check definitions.
619 const clang::TagDecl* GetAnnotatedRedeclarable(const clang::TagDecl* TND);
620 
621 //______________________________________________________________________________
622 // Return true if the decl is part of the std namespace.
623 bool IsStdClass(const clang::RecordDecl &cl);
624 
625 //______________________________________________________________________________
626 // Return true, if the decl is part of the std namespace and we want
627 // its default parameter dropped.
628 bool IsStdDropDefaultClass(const clang::RecordDecl &cl);
629 
630 //______________________________________________________________________________
631 // See if the CXXRecordDecl matches the current of any of the previous CXXRecordDecls
632 bool MatchWithDeclOrAnyOfPrevious(const clang::CXXRecordDecl &cl, const clang::CXXRecordDecl &currentCl);
633 
634 //______________________________________________________________________________
635 // Return true if the decl is of type
636 bool IsOfType(const clang::CXXRecordDecl &cl, const std::string& type, const cling::LookupHelper& lh);
637 
638 //______________________________________________________________________________
639 // Return which kind of STL container the decl is, if any.
640 ROOT::ESTLType IsSTLCont(const clang::RecordDecl &cl);
641 
642 //______________________________________________________________________________
643 // Check if 'input' or any of its template parameter was substituted when
644 // instantiating the class template instance and replace it with the
645 // partially sugared type we have from 'instance'.
646 clang::QualType ReSubstTemplateArg(clang::QualType input, const clang::Type *instance);
647 
648 //______________________________________________________________________________
649 // Remove the last n template arguments from the name
650 int RemoveTemplateArgsFromName(std::string& name, unsigned int);
651 
652 //______________________________________________________________________________
653 clang::TemplateName ExtractTemplateNameFromQualType(const clang::QualType& qt);
654 
655 //______________________________________________________________________________
656 bool QualType2Template(const clang::QualType& qt,
657  clang::ClassTemplateDecl*& ctd,
658  clang::ClassTemplateSpecializationDecl*& ctsd);
659 
660 //______________________________________________________________________________
661 clang::ClassTemplateDecl* QualType2ClassTemplateDecl(const clang::QualType& qt);
662 
663 //______________________________________________________________________________
664 // Extract the namespaces enclosing a DeclContext
665 void ExtractCtxtEnclosingNameSpaces(const clang::DeclContext&,
666  std::list<std::pair<std::string,bool> >&);
667 //______________________________________________________________________________
668 void ExtractEnclosingNameSpaces(const clang::Decl&,
669  std::list<std::pair<std::string,bool> >&);
670 
671 //______________________________________________________________________________
672 const clang::RecordDecl* ExtractEnclosingScopes(const clang::Decl& decl,
673  std::list<std::pair<std::string,unsigned int> >& enclosingSc);
674 //______________________________________________________________________________
675 // Kind of stl container
676 ROOT::ESTLType STLKind(const llvm::StringRef type);
677 
678 //______________________________________________________________________________
679 // Set the toolchain and the include paths for relocatability
680 void SetPathsForRelocatability(std::vector<std::string>& clingArgs);
681 
682 //______________________________________________________________________________
683 void ReplaceAll(std::string& str, const std::string& from, const std::string& to, bool recurse=false);
684 
685 // Functions for the printouts -------------------------------------------------
686 
687 //______________________________________________________________________________
688 void LevelPrint(bool prefix, int level, const char *location, const char *fmt, va_list ap);
689 
690 //______________________________________________________________________________
691 void Error(const char *location, const char *va_(fmt), ...);
692 
693 //______________________________________________________________________________
694 void SysError(const char *location, const char *va_(fmt), ...);
695 
696 //______________________________________________________________________________
697 void Info(const char *location, const char *va_(fmt), ...);
698 
699 //______________________________________________________________________________
700 void Warning(const char *location, const char *va_(fmt), ...);
701 
702 //______________________________________________________________________________
703 void Fatal(const char *location, const char *va_(fmt), ...);
704 
705 //______________________________________________________________________________
706 const std::string& GetPathSeparator();
707 
708 //______________________________________________________________________________
709 bool EndsWith(const std::string &theString, const std::string &theSubstring);
710 
711 //______________________________________________________________________________
712 bool BeginsWith(const std::string &theString, const std::string &theSubstring);
713 
714 //______________________________________________________________________________
715 namespace AST2SourceTools {
716 
717 //______________________________________________________________________________
718 const std::string Decls2FwdDecls(const std::vector<const clang::Decl*> &decls,
719  bool (*ignoreFiles)(const clang::PresumedLoc&) ,
720  const cling::Interpreter& interp);
721 
722 //______________________________________________________________________________
723 int PrepareArgsForFwdDecl(std::string& templateArgs,
724  const clang::TemplateParameterList& tmplParamList,
725  const cling::Interpreter& interpreter);
726 
727 //______________________________________________________________________________
728 int EncloseInNamespaces(const clang::Decl& decl, std::string& defString);
729 
730 //______________________________________________________________________________
731 const clang::RecordDecl* EncloseInScopes(const clang::Decl& decl, std::string& defString);
732 
733 //______________________________________________________________________________
734 int FwdDeclFromRcdDecl(const clang::RecordDecl& recordDecl,
735  const cling::Interpreter& interpreter,
736  std::string& defString,
737  bool acceptStl=false);
738 
739 //______________________________________________________________________________
740 int FwdDeclFromTmplDecl(const clang::TemplateDecl& tmplDecl,
741  const cling::Interpreter& interpreter,
742  std::string& defString);
743 //______________________________________________________________________________
744 int GetDefArg(const clang::ParmVarDecl& par, std::string& valAsString, const clang::PrintingPolicy& pp);
745 
746 //______________________________________________________________________________
747 int FwdDeclFromFcnDecl(const clang::FunctionDecl& fcnDecl,
748  const cling::Interpreter& interpreter,
749  std::string& defString);
750 //______________________________________________________________________________
751 int FwdDeclFromTypeDefNameDecl(const clang::TypedefNameDecl& tdnDecl,
752  const cling::Interpreter& interpreter,
753  std::string& fwdDeclString,
754  std::unordered_set<std::string>* fwdDeclSet=nullptr);
755 
756 } // namespace AST2SourceTools
757 
758 } // namespace TMetaUtils
759 
760 } // namespace ROOT
761 
762 #endif // ROOT_TMetaUtils
bool NeedTemplateKeyword(clang::CXXRecordDecl const *)
void CreateNameTypeMap(clang::CXXRecordDecl const &, std::map< std::string, ROOT::Internal::TSchemaType, std::less< std::string >, std::allocator< std::pair< std::string const, ROOT::Internal::TSchemaType > > > &)
const clang::RecordDecl * ExtractEnclosingScopes(const clang::Decl &decl, std::list< std::pair< std::string, unsigned int > > &enclosingSc)
Extract the names and types of containing scopes.
double par[1]
Definition: unuranDistr.cxx:38
int extractPropertyNameValFromString(const std::string attributeStr, std::string &attrName, std::string &attrValue)
static const std::string nArgsToKeep("nArgsToKeep")
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...
ESTLType
Definition: ESTLType.h:28
bool IsStreamableObject(const clang::FieldDecl &m, const cling::Interpreter &interp)
bool IsBase(const clang::FieldDecl &m, const char *basename, const cling::Interpreter &interp)
Definition: TMetaUtils.cxx:776
int GetDefArg(const clang::ParmVarDecl &par, std::string &valAsString, const clang::PrintingPolicy &pp)
Get the default value as string.
Definition: TString.h:780
const int kNote
Definition: TMetaUtils.h:113
bool hasOpaqueTypedef(const AnnotatedRecordDecl &cl, const cling::Interpreter &interp, const TNormalizedCtxt &normCtxt)
Return true if any of the argument is or contains a double32.
llvm::StringRef GetFileName(const clang::Decl &decl, const cling::Interpreter &interp)
Return the header file to be included to declare the Decl.
Namespace for new ROOT classes and functions.
Definition: ROOT.py:1
cling::Interpreter * gInterp
cling::Interpreter * fInterpreter
Definition: TMetaUtils.h:153
long GetLineNumber(clang::Decl const *)
It looks like the template specialization decl actually contains less information on the location of ...
bool CheckPublicFuncWithProto(clang::CXXRecordDecl const *, char const *, char const *, const cling::Interpreter &, bool diagnose)
Return true, if the function (defined by the name and prototype) exists and is public.
static const std::string comment("comment")
void Error(const char *location, const char *va_(fmt),...)
Use this function in case an error occured.
double T(double x)
Definition: ChebyshevPol.h:34
const clang::TagDecl * GetAnnotatedRedeclarable(const clang::TagDecl *TND)
std::map< const clang::ClassTemplateDecl *, int > TemplPtrIntMap_t
Definition: TMetaUtils.h:131
clang::RecordDecl * GetUnderlyingRecordDecl(clang::QualType type)
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...
llvm::StringRef DataMemberInfo__ValidArrayIndex(const clang::DeclaratorDecl &m, int *errnum=0, llvm::StringRef *errstr=0)
ValidArrayIndex return a static string (so use it or copy it immediatly, do not call GrabIndex twice ...
const char * GetRequestedName() const
Definition: TMetaUtils.h:249
static const std::string iotype("iotype")
Type GetType(const std::string &Name)
Definition: Systematics.cxx:34
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...
unsigned int GetNumberOfWarningsAndErrors()
Definition: TMetaUtils.cxx:67
TRObject operator()(const T1 &t1) const
bool ExtractAttrPropertyFromName(const clang::Decl &decl, const std::string &propName, std::string &propValue)
This routine counts on the "propName<separator>propValue" format.
int RemoveTemplateArgsFromName(std::string &name, unsigned int)
Remove the last n template arguments from the name.
DataMemberInfo__ValidArrayIndex_error_code
Definition: TMetaUtils.h:104
int extractAttrString(clang::Attr *attribute, std::string &attrString)
Extract attr string.
ExistingTypeCheck_t fExistingTypeCheck
Definition: TMetaUtils.h:155
bool HasDirectoryAutoAdd(clang::CXXRecordDecl const *, const cling::Interpreter &)
Return true if the class has a method DirectoryAutoAdd(TDirectory *)
const clang::Type * GetUnderlyingType(clang::QualType type)
Return the base/underlying type of a chain of array or pointers type.
bool HasCustomConvStreamerMemberFunction(const AnnotatedRecordDecl &cl, const clang::CXXRecordDecl *clxx, const cling::Interpreter &interp, const TNormalizedCtxt &normCtxt)
Return true if the class has a custom member function streamer.
const Int_t kSysError
Definition: TError.h:43
static const std::string separator("@@@")
bool MatchWithDeclOrAnyOfPrevious(const clang::CXXRecordDecl &cl, const clang::CXXRecordDecl &currentCl)
This is a recursive function.
int FwdDeclFromTypeDefNameDecl(const clang::TypedefNameDecl &tdnDecl, const cling::Interpreter &interpreter, std::string &fwdDeclString, std::unordered_set< std::string > *fwdDeclSet=nullptr)
Extract "forward declaration" of a typedef.
const int kThrowOnWarning
Definition: TMetaUtils.h:114
const Int_t kFatal
Definition: TError.h:44
bool BeginsWith(const std::string &theString, const std::string &theSubstring)
bool IsStdDropDefaultClass(const clang::RecordDecl &cl)
Return true, if the decl is part of the std namespace and we want its default parameter dropped...
int FwdDeclFromRcdDecl(const clang::RecordDecl &recordDecl, const cling::Interpreter &interpreter, std::string &defString, bool acceptStl=false)
Convert a rcd decl to its fwd decl If this is a template specialisation, treat in the proper way...
static const std::string pattern("pattern")
#define va_(arg)
Definition: Varargs.h:41
std::string GetQualifiedName(const clang::RecordDecl &recordDecl)
int IsSTLContainer(const clang::CXXBaseSpecifier &base)
Is this an STL container?
bool HasNewMerge(clang::CXXRecordDecl const *, const cling::Interpreter &)
Return true if the class has a method Merge(TCollection*,TFileMergeInfo*)
bool IsStdClass(const clang::RecordDecl &cl)
Return true, if the decl is part of the std namespace.
const char * GetNormalizedName() const
Definition: TMetaUtils.h:250
std::string GetModuleFileName(const char *moduleName)
Return the dictionary file name for a module.
int EncloseInNamespaces(const clang::Decl &decl, std::string &defString)
Take the namespaces which enclose the decl and put them around the definition string.
bool RequireCompleteType(const cling::Interpreter &interp, clang::SourceLocation Loc, clang::QualType Type)
Definition: TMetaUtils.cxx:741
void WriteClassInit(std::ostream &finalString, const AnnotatedRecordDecl &cl, const clang::CXXRecordDecl *decl, const cling::Interpreter &interp, const TNormalizedCtxt &normCtxt, const RConstructorTypes &ctorTypes, bool &needCollectionProxy)
FIXME: a function of ~300 lines!
void WritePointersSTL(const AnnotatedRecordDecl &cl, const cling::Interpreter &interp, const TNormalizedCtxt &normCtxt)
Write interface function for STL members.
void Info(const char *location, const char *va_(fmt),...)
Use this function for informational messages.
void WriteAuxFunctions(std::ostream &finalString, const AnnotatedRecordDecl &cl, const clang::CXXRecordDecl *decl, const cling::Interpreter &interp, const RConstructorTypes &ctorTypes, const TNormalizedCtxt &normCtxt)
std::string NormalizedName; GetNormalizedName(NormalizedName, decl->getASTContext().getTypeDeclType(decl), interp, normCtxt);
bool operator<(const AnnotatedRecordDecl &right) const
Definition: TMetaUtils.h:276
int extractPropertyNameVal(clang::Attr *attribute, std::string &attrName, std::string &attrValue)
const clang::FunctionDecl * GetFuncWithProto(const clang::Decl *cinfo, const char *method, const char *proto, const cling::Interpreter &gInterp, bool diagnose)
bool HasOldMerge(clang::CXXRecordDecl const *, const cling::Interpreter &)
Return true if the class has a method Merge(TCollection*)
void(* CallWriteStreamer_t)(const AnnotatedRecordDecl &cl, const cling::Interpreter &interp, const TNormalizedCtxt &normCtxt, std::ostream &dictStream, bool isAutoStreamer)
Definition: TMetaUtils.h:106
int FwdDeclFromTmplDecl(const clang::TemplateDecl &tmplDecl, const cling::Interpreter &interpreter, std::string &defString)
Convert a tmplt decl to its fwd decl.
bool ExtractAttrIntPropertyFromName(const clang::Decl &decl, const std::string &propName, int &propValue)
This routine counts on the "propName<separator>propValue" format.
std::list< RConstructorType > RConstructorTypes
Definition: TMetaUtils.h:301
const std::string & GetPathSeparator()
Return the separator suitable for this platform.
int PrepareArgsForFwdDecl(std::string &templateArgs, const clang::TemplateParameterList &tmplParamList, const cling::Interpreter &interpreter)
Loop over the template parameters and build a string for template arguments using the fully qualified...
const std::string Decls2FwdDecls(const std::vector< const clang::Decl *> &decls, bool(*ignoreFiles)(const clang::PresumedLoc &), const cling::Interpreter &interp)
const Int_t kInfo
Definition: TError.h:39
std::string TrueName(const clang::FieldDecl &m)
TrueName strips the typedefs and array dimensions.
const clang::RecordDecl * EncloseInScopes(const clang::Decl &decl, std::string &defString)
Take the scopes which enclose the decl and put them around the definition string. ...
bool HasCustomStreamerMemberFunction(const AnnotatedRecordDecl &cl, const clang::CXXRecordDecl *clxx, const cling::Interpreter &interp, const TNormalizedCtxt &normCtxt)
Return true if the class has a custom member function streamer.
ROOT::ESTLType STLKind(const llvm::StringRef type)
Converts STL container name to number. vector -> 1, etc..
const clang::CXXRecordDecl * ScopeSearch(const char *name, const cling::Interpreter &gInterp, bool diagnose, const clang::Type **resultType)
Return the scope corresponding to &#39;name&#39; or std::&#39;name&#39;.
Definition: TMetaUtils.cxx:710
TMarker * m
Definition: textangle.C:8
const int kMaxLen
Definition: TMetaUtils.h:119
ROOT::ESTLType IsSTLCont(const clang::RecordDecl &cl)
type : type name: vector<list<classA,allocator>,allocator> result: 0 : not stl container abs(result):...
const clang::FunctionDecl * ClassInfo__HasMethod(const clang::DeclContext *cl, char const *, const cling::Interpreter &interp)
Definition: TMetaUtils.cxx:696
std::set< const clang::Type * > TypesCont_t
Definition: TMetaUtils.h:130
const Int_t kWarning
Definition: TError.h:40
static const std::string name("name")
void SetPathsForRelocatability(std::vector< std::string > &clingArgs)
Organise the parameters for cling in order to guarantee relocatability It treats the gcc toolchain an...
Type
enumeration specifying the integration types.
bool NeedDestructor(clang::CXXRecordDecl const *)
const clang::RecordDecl * fDecl
Definition: TMetaUtils.h:178
const clang::RecordDecl * GetRecordDecl() const
Definition: TMetaUtils.h:270
void ExtractCtxtEnclosingNameSpaces(const clang::DeclContext &, std::list< std::pair< std::string, bool > > &)
Extract enclosing namespaces recusrively.
bool HasCustomOperatorNewPlacement(clang::RecordDecl const &, const cling::Interpreter &)
return true if we can find a custom operator new with placement
Definition: TCling.h:48
static const std::string persistent("persistent")
EIOCtorCategory CheckConstructor(const clang::CXXRecordDecl *, const RConstructorType &, const cling::Interpreter &interp)
Definition: TMetaUtils.cxx:973
int type
Definition: TGX11.cxx:120
Definition: TDatime.h:114
std::string ShortTypeName(const clang::FieldDecl &m)
Return the absolute type of typeDesc.
llvm::StringRef GetClassComment(const clang::CXXRecordDecl &decl, clang::SourceLocation *loc, const cling::Interpreter &interpreter)
Return the class comment after the ClassDef: class MyClass { ...
int FwdDeclFromFcnDecl(const clang::FunctionDecl &fcnDecl, const cling::Interpreter &interpreter, std::string &defString)
void Warning(const char *location, const char *va_(fmt),...)
Use this function in warning situations.
bool GetNameWithinNamespace(std::string &, std::string &, std::string &, clang::CXXRecordDecl const *)
Return true if one of the class&#39; enclosing scope is a namespace and set fullname to the fully qualifi...
void SysError(const char *location, const char *va_(fmt),...)
Use this function in case a system (OS or GUI) related error occured.
bool EndsWith(const std::string &theString, const std::string &theSubstring)
void GetFullyQualifiedTypeName(std::string &name, const clang::QualType &type, const clang::ASTContext &)
cling::utils::Transform::Config Config_t
Definition: TMetaUtils.h:129
int ElementStreamer(std::ostream &finalString, const clang::NamedDecl &forcontext, const clang::QualType &qti, const char *t, int rwmode, const cling::Interpreter &interp, const char *tcl=0)
Definition: TMetaUtils.cxx:795
void LevelPrint(bool prefix, int level, const char *location, const char *fmt, va_list ap)
typedef void((*Func_t)())
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...
clang::Module * declareModuleMap(clang::CompilerInstance *CI, const char *moduleFileName, const char *headers[])
Declare a virtual module.map to clang. Returns Module on success.
void ReplaceAll(std::string &str, const std::string &from, const std::string &to, bool recurse=false)
void GetNormalizedName(std::string &norm_name, const clang::TypeDecl *typeDecl, const cling::Interpreter &interpreter)
const Int_t kError
Definition: TError.h:41
clang::TemplateName ExtractTemplateNameFromQualType(const clang::QualType &qt)
These manipulations are necessary because a template specialisation type does not inherit from a reco...
bool QualType2Template(const clang::QualType &qt, clang::ClassTemplateDecl *&ctd, clang::ClassTemplateSpecializationDecl *&ctsd)
Get the template specialisation decl and template decl behind the qualtype Returns true if successful...
int WriteNamespaceHeader(std::ostream &, const clang::DeclContext *)
Write all the necessary opening part of the namespace and return the number of closing brackets neede...
static const std::string ioname("ioname")
bool HasCustomOperatorNewArrayPlacement(clang::RecordDecl const &, const cling::Interpreter &interp)
return true if we can find a custom operator new with placement
double result[121]
bool IsOfType(const clang::CXXRecordDecl &cl, const std::string &type, const cling::LookupHelper &lh)
void WriteClassCode(CallWriteStreamer_t WriteStreamerFunc, const AnnotatedRecordDecl &cl, const cling::Interpreter &interp, const TNormalizedCtxt &normCtxt, std::ostream &finalString, const RConstructorTypes &ctorTypes, bool isGenreflex)
Generate the code of the class If the requestor is genreflex, request the new streamer format...
static void output(int code)
Definition: gifencode.c:226
const clang::CXXRecordDecl * fArgType
Definition: TMetaUtils.h:293
bool HasResetAfterMerge(clang::CXXRecordDecl const *, const cling::Interpreter &)
Return true if the class has a method ResetAfterMerge(TFileMergeInfo *)
clang::ClassTemplateDecl * QualType2ClassTemplateDecl(const clang::QualType &qt)
Extract from a qualtype the class template if this makes sense.
bool HasIOConstructor(clang::CXXRecordDecl const *, std::string &, const RConstructorTypes &, const cling::Interpreter &)
return true if we can find an constructor calleable without any arguments or with one the IOCtor spec...
void ExtractEnclosingNameSpaces(const clang::Decl &, std::list< std::pair< std::string, bool > > &)
Extract the immediately outer namespace and then launch the recursion.
clang::QualType GetNormalizedType(const clang::QualType &type, const cling::Interpreter &interpreter, const TNormalizedCtxt &normCtxt)
Return the type normalized for ROOT, keeping only the ROOT opaque typedef (Double32_t, etc.) and adding default template argument for all types except those explicitly requested to be drop by the user.
void Fatal(const char *location, const char *va_(fmt),...)
Use this function in case of a fatal error. It will abort the program.
TNormalizedCtxtImpl * fImpl
Definition: TMetaUtils.h:127
clang::QualType AddDefaultParameters(clang::QualType instanceType, const cling::Interpreter &interpret, const TNormalizedCtxt &normCtxt)
Add any unspecified template parameters to the class template instance, mentioned anywhere in the typ...