ROOT  6.06/09
Reference Guide
TClassEdit.h
Go to the documentation of this file.
1 // @(#)root/metautils:$Id$
2 // Author: Victor Perev 10/04/2003
3 // Philippe Canal 05/2004
4 
5 /*************************************************************************
6  * Copyright (C) 1995-2003, Rene Brun and Fons Rademakers. *
7  * All rights reserved. *
8  * *
9  * For the licensing terms see $ROOTSYS/LICENSE. *
10  * For the list of contributors see $ROOTSYS/README/CREDITS. *
11  *************************************************************************/
12 
13 #ifndef ROOT_TClassEdit
14 #define ROOT_TClassEdit
15 
16 #include "RConfig.h"
17 #include "RConfigure.h"
18 #include <stdlib.h>
19 #ifdef R__WIN32
20 #ifndef UNDNAME_COMPLETE
21 #define UNDNAME_COMPLETE 0x0000
22 #endif
23 extern "C" {
24  char *__unDName(char *demangled, const char *mangled, int out_len,
25  void * (* pAlloc )(size_t), void (* pFree )(void *),
26  unsigned short int flags);
27 }
28 #else
29 #include <cxxabi.h>
30 #endif
31 #include <string>
32 #include <vector>
33 
34 #ifndef ROOT_ESTLType
35 #include "ESTLType.h"
36 #endif
37 
38 #ifdef R__OLDHPACC
39 namespace std {
40  using ::string;
41  using ::vector;
42 }
43 #endif
44 
45 #if defined(__CYGWIN__)
46 // std::to_string is missing on cygwin with gcc 4.8.2-2 and 4.8.3
47 #include <sstream>
48 namespace std {
49  template <typename T>
50  string to_string(T value) {
51  ostringstream os;
52  os << value;
53  return os.str();
54  }
55 }
56 #endif
57 
58 namespace cling {
59  class Interpreter;
60 }
61 namespace ROOT {
62  namespace TMetaUtils {
63  class TNormalizedCtxt;
64  }
65 }
66 #include "RStringView.h"
67 
68 // TClassEdit is used to manipulate class and type names.
69 //
70 // This class does not dependent on any other ROOT facility
71 // so that it can be used by rootcint.
72 
73 namespace TClassEdit {
74 
75  enum EModType {
76  kNone = 0,
79  kDropAlloc = 1<<2,
80  kInnerClass = 1<<3,
82  kDropStlDefault = 1<<5, /* implies kDropDefaultAlloc */
83  kDropComparator = 1<<6, /* if the class has a comparator, drops BOTH the comparator and the Allocator */
84  kDropAllDefault = 1<<7, /* Drop default template parameter even in non STL classes */
85  kLong64 = 1<<8, /* replace all 'long long' with Long64_t. */
86  kDropStd = 1<<9, /* Drop any std:: */
87  kKeepOuterConst = 1<<10,/* Make sure to keep the const keyword even outside the template parameters */
88  kResolveTypedef = 1<<11,/* Strip all typedef except Double32_t and co. */
89  kDropPredicate = 1<<12,/* Drop the predicate if applies to the collection */
90  kDropHash = 1<<13 /* Drop the hash if applies to the collection */
91  };
92 
93  enum ESTLType {
109  };
110 
111  enum class EComplexType : short {
112  kNone,
113  kDouble,
114  kFloat,
115  kInt,
116  kLong
117  };
118 
119  EComplexType GetComplexType(const char*);
120 
122  public:
125 
126  virtual bool ExistingTypeCheck(const std::string & /*tname*/,
127  std::string & /*result*/) = 0;
128  virtual void GetPartiallyDesugaredName(std::string & /*nameLong*/) = 0;
129  virtual bool IsAlreadyPartiallyDesugaredName(const std::string & /*nondef*/,
130  const std::string & /*nameLong*/) = 0;
131  virtual bool IsDeclaredScope(const std::string & /*base*/, bool & /*isInlined*/) = 0;
132  virtual bool GetPartiallyDesugaredNameWithScopeHandling(const std::string & /*tname*/,
133  std::string & /*result*/) = 0;
134  };
135 
136  struct TSplitType {
137 
138  const char *fName; // Original spelling of the name.
139  std::vector<std::string> fElements;
140  int fNestedLocation; // Stores the location of the tail (nested names) in nestedLoc (0 indicates no tail).
141 
142  TSplitType(const char *type2split, EModType mode = TClassEdit::kNone);
143 
144  int IsSTLCont(int testAlloc=0) const;
145  ROOT::ESTLType IsInSTL() const;
146  void ShortType(std::string &answer, int mode);
147 
148  private:
149  TSplitType(const TSplitType&); // intentionally not implemented
150  TSplitType &operator=(const TSplitType &); // intentionally not implemented
151  };
152 
154 
155  std::string CleanType (const char *typeDesc,int mode = 0,const char **tail=0);
156  bool IsDefAlloc(const char *alloc, const char *classname);
157  bool IsDefAlloc(const char *alloc, const char *keyclassname, const char *valueclassname);
158  bool IsDefComp (const char *comp , const char *classname);
159  bool IsDefPred(const char *predname, const char *classname);
160  bool IsDefHash(const char *hashname, const char *classname);
161  bool IsInterpreterDetail(const char *type);
162  bool IsSTLBitset(const char *type);
163  ROOT::ESTLType UnderlyingIsSTLCont(std::string_view type);
164  ROOT::ESTLType IsSTLCont (std::string_view type);
165  int IsSTLCont (const char *type,int testAlloc);
166  bool IsStdClass(const char *type);
167  bool IsVectorBool(const char *name);
168  void GetNormalizedName(std::string &norm_name,std::string_view name);
169  std::string GetLong64_Name(const char *original);
170  std::string GetLong64_Name(const std::string& original);
171  int GetSplit (const char *type, std::vector<std::string> &output, int &nestedLoc, EModType mode = TClassEdit::kNone);
172  ROOT::ESTLType STLKind(std::string_view type); //Kind of stl container
173  int STLArgs (int kind); //Min number of arguments without allocator
174  std::string ResolveTypedef(const char *tname, bool resolveAll = false);
175  std::string ShortType (const char *typeDesc, int mode);
176  std::string InsertStd(const char *tname);
177  const char* GetUnqualifiedName(const char*name);
178  inline char* DemangleName(const char* mangled_name, int& errorCode)
179  {
180  // Demangle in a portable way the name.
181  // IMPORTANT: The caller is responsible for freeing the returned const char*
182 
183  errorCode=0;
184 #ifdef R__WIN32
185  char *demangled_name = __unDName(0, mangled_name, 0, malloc, free, UNDNAME_COMPLETE);
186  if (!demangled_name) {
187  errorCode = -1;
188  return nullptr;
189  }
190 #else
191  char *demangled_name = abi::__cxa_demangle(mangled_name, 0, 0, &errorCode);
192  if (!demangled_name || errorCode) {
193  free(demangled_name);
194  return nullptr;
195  }
196 #endif
197  return demangled_name;
198  }
199  char* DemangleTypeIdName(const std::type_info& ti, int& errorCode);
200 }
201 
202 #endif
ESTLType
Definition: ESTLType.h:28
ROOT::ESTLType IsSTLCont(std::string_view type)
type : type name: vector,allocator> result: 0 : not stl container code of cont...
int IsSTLCont(int testAlloc=0) const
type : type name: vector,allocator> testAlloc: if true, we test allocator...
Definition: TClassEdit.cxx:153
Namespace for new ROOT classes and functions.
Definition: ROOT.py:1
TSplitType & operator=(const TSplitType &)
TSplitType(const char *type2split, EModType mode=TClassEdit::kNone)
default constructor
Definition: TClassEdit.cxx:126
int GetSplit(const char *type, std::vector< std::string > &output, int &nestedLoc, EModType mode=TClassEdit::kNone)
Stores in output (after emptying it) the splited type.
Definition: TClassEdit.cxx:937
ROOT::ESTLType IsInSTL() const
type : type name: vector,allocator>[::iterator] result: 0 : not stl container ...
Definition: TClassEdit.cxx:136
double T(double x)
Definition: ChebyshevPol.h:34
virtual bool GetPartiallyDesugaredNameWithScopeHandling(const std::string &, std::string &)=0
bool IsDefAlloc(const char *alloc, const char *classname)
return whether or not 'allocname' is the STL default allocator for type 'classname' ...
Definition: TClassEdit.cxx:556
std::string CleanType(const char *typeDesc, int mode=0, const char **tail=0)
Cleanup type description, redundant blanks removed and redundant tail ignored return *tail = pointer ...
std::string InsertStd(const char *tname)
virtual bool IsDeclaredScope(const std::string &, bool &)=0
bool IsSTLBitset(const char *type)
Return true is the name is std::bitset or bitset
STL namespace.
Vc_ALWAYS_INLINE void free(T *p)
Frees memory that was allocated with Vc::malloc.
Definition: memory.h:94
int STLArgs(int kind)
Return number of arguments for STL container before allocator.
Definition: TClassEdit.cxx:511
void ShortType(std::string &answer, int mode)
Return the absolute type of typeDesc into the string answ.
Definition: TClassEdit.cxx:197
char * DemangleName(const char *mangled_name, int &errorCode)
Definition: TClassEdit.h:178
const char * fName
Definition: TClassEdit.h:138
void Init(TClassEdit::TInterpreterLookupHelper *helper)
Definition: TClassEdit.cxx:118
std::string ResolveTypedef(const char *tname, bool resolveAll=false)
ROOT::ESTLType STLKind(std::string_view type)
Converts STL container name to number.
Definition: TClassEdit.cxx:467
virtual bool ExistingTypeCheck(const std::string &, std::string &)=0
char * DemangleTypeIdName(const std::type_info &ti, int &errorCode)
Demangle in a portable way the type id name.
bool IsInterpreterDetail(const char *type)
Return true if the type is one the interpreter details which are only forward declared (ClassInfo_t e...
virtual void GetPartiallyDesugaredName(std::string &)=0
std::string GetLong64_Name(const char *original)
Replace 'long long' and 'unsigned long long' by 'Long64_t' and 'ULong64_t'.
Definition: TClassEdit.cxx:816
ROOT::ESTLType UnderlyingIsSTLCont(std::string_view type)
Return the type of STL collection, if any, that is the underlying type of the given type...
EComplexType GetComplexType(const char *)
Definition: TClassEdit.cxx:96
bool IsDefHash(const char *hashname, const char *classname)
return whether or not 'hashname' is the STL default hash for type 'classname'
Definition: TClassEdit.cxx:772
std::vector< std::string > fElements
Definition: TClassEdit.h:139
void GetNormalizedName(std::string &norm_name, std::string_view name)
Return the normalized name.
Definition: TClassEdit.cxx:787
bool IsVectorBool(const char *name)
bool IsStdClass(const char *type)
return true if the class belongs to the std namespace
virtual bool IsAlreadyPartiallyDesugaredName(const std::string &, const std::string &)=0
int type
Definition: TGX11.cxx:120
Definition: TDatime.h:114
bool IsDefComp(const char *comp, const char *classname)
return whether or not 'compare' is the STL default comparator for type 'classname' ...
Definition: TClassEdit.cxx:754
#define name(a, b)
Definition: linkTestLib0.cpp:5
const char * GetUnqualifiedName(const char *name)
Return the start of the unqualified name include in 'original'.
Definition: TClassEdit.cxx:850
std::string ShortType(const char *typeDesc, int mode)
Return the absolute type of typeDesc.
static void output(int code)
Definition: gifencode.c:226
float value
Definition: math.cpp:443
Vc_ALWAYS_INLINE_L T *Vc_ALWAYS_INLINE_R malloc(size_t n)
Allocates memory on the Heap with alignment and padding suitable for vectorized access.
Definition: memory.h:67
bool IsDefPred(const char *predname, const char *classname)
return whether or not 'predname' is the STL default predicate for type 'classname' ...
Definition: TClassEdit.cxx:763