Logo ROOT   6.08/07
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 #include <array>
34 
35 #ifndef ROOT_ESTLType
36 #include "ESTLType.h"
37 #endif
38 
39 #ifdef R__OLDHPACC
40 namespace std {
41  using ::string;
42  using ::vector;
43 }
44 #endif
45 
46 #if defined(__CYGWIN__)
47 // std::to_string is missing on cygwin with gcc 4.8.2-2 and 4.8.3
48 #include <sstream>
49 namespace std {
50  template <typename T>
51  string to_string(T value) {
52  ostringstream os;
53  os << value;
54  return os.str();
55  }
56 }
57 #endif
58 
59 namespace cling {
60  class Interpreter;
61 }
62 namespace ROOT {
63  namespace TMetaUtils {
64  class TNormalizedCtxt;
65  }
66 }
67 #include "RStringView.h"
68 
69 // TClassEdit is used to manipulate class and type names.
70 //
71 // This class does not dependent on any other ROOT facility
72 // so that it can be used by rootcint.
73 
74 namespace TClassEdit {
75 
76  enum EModType {
77  kNone = 0,
80  kDropAlloc = 1<<2,
81  kInnerClass = 1<<3,
83  kDropStlDefault = 1<<5, /* implies kDropDefaultAlloc */
84  kDropComparator = 1<<6, /* if the class has a comparator, drops BOTH the comparator and the Allocator */
85  kDropAllDefault = 1<<7, /* Drop default template parameter even in non STL classes */
86  kLong64 = 1<<8, /* replace all 'long long' with Long64_t. */
87  kDropStd = 1<<9, /* Drop any std:: */
88  kKeepOuterConst = 1<<10,/* Make sure to keep the const keyword even outside the template parameters */
89  kResolveTypedef = 1<<11,/* Strip all typedef except Double32_t and co. */
90  kDropPredicate = 1<<12,/* Drop the predicate if applies to the collection */
91  kDropHash = 1<<13 /* Drop the hash if applies to the collection */
92  };
93 
94  enum ESTLType {
110  };
111 
112  enum class EComplexType : short {
113  kNone,
114  kDouble,
115  kFloat,
116  kInt,
117  kLong
118  };
119 
120  EComplexType GetComplexType(const char*);
121 
123  public:
126 
127  virtual bool ExistingTypeCheck(const std::string & /*tname*/,
128  std::string & /*result*/) = 0;
129  virtual void GetPartiallyDesugaredName(std::string & /*nameLong*/) = 0;
130  virtual bool IsAlreadyPartiallyDesugaredName(const std::string & /*nondef*/,
131  const std::string & /*nameLong*/) = 0;
132  virtual bool IsDeclaredScope(const std::string & /*base*/, bool & /*isInlined*/) = 0;
133  virtual bool GetPartiallyDesugaredNameWithScopeHandling(const std::string & /*tname*/,
134  std::string & /*result*/) = 0;
135  };
136 
137  struct TSplitType {
138 
139  const char *fName; // Original spelling of the name.
140  std::vector<std::string> fElements;
141  int fNestedLocation; // Stores the location of the tail (nested names) in nestedLoc (0 indicates no tail).
142 
143  TSplitType(const char *type2split, EModType mode = TClassEdit::kNone);
144 
145  int IsSTLCont(int testAlloc=0) const;
146  ROOT::ESTLType IsInSTL() const;
147  void ShortType(std::string &answer, int mode);
148 
149  private:
150  TSplitType(const TSplitType&); // intentionally not implemented
151  TSplitType &operator=(const TSplitType &); // intentionally not implemented
152  };
153 
155 
156  std::string CleanType (const char *typeDesc,int mode = 0,const char **tail=0);
157  bool IsDefAlloc(const char *alloc, const char *classname);
158  bool IsDefAlloc(const char *alloc, const char *keyclassname, const char *valueclassname);
159  bool IsDefComp (const char *comp , const char *classname);
160  bool IsDefPred(const char *predname, const char *classname);
161  bool IsDefHash(const char *hashname, const char *classname);
162  bool IsInterpreterDetail(const char *type);
163  bool IsSTLBitset(const char *type);
166  int IsSTLCont (const char *type,int testAlloc);
167  bool IsStdClass(const char *type);
168  bool IsVectorBool(const char *name);
169  void GetNormalizedName(std::string &norm_name,std::string_view name);
170  std::string GetLong64_Name(const char *original);
171  std::string GetLong64_Name(const std::string& original);
172  int GetSplit (const char *type, std::vector<std::string> &output, int &nestedLoc, EModType mode = TClassEdit::kNone);
173  ROOT::ESTLType STLKind(std::string_view type); //Kind of stl container
174  int STLArgs (int kind); //Min number of arguments without allocator
175  std::string ResolveTypedef(const char *tname, bool resolveAll = false);
176  std::string ShortType (const char *typeDesc, int mode);
177  std::string InsertStd(const char *tname);
178  const char* GetUnqualifiedName(const char*name);
179  inline bool IsUniquePtr(std::string_view name) {return 0 == name.compare(0, 11, "unique_ptr<");}
180  inline bool IsStdArray(std::string_view name) {return 0 == name.compare(0, 6, "array<");}
182  {
183  // Find the first template parameter
184  std::vector<std::string> v;
185  int i;
186  GetSplit(name.data(), v, i);
187  return v[1];
188  }
189  std::string GetNameForIO(const std::string& templateInstanceName,
191  bool* hasChanged = nullptr);
192  bool GetStdArrayProperties(const char* typeName,
193  std::string& typeNameBuf,
194  std::array<int, 5>& maxIndices,
195  int& ndim);
196 
197  inline char* DemangleName(const char* mangled_name, int& errorCode)
198  {
199  // Demangle in a portable way the name.
200  // IMPORTANT: The caller is responsible for freeing the returned const char*
201 
202  errorCode=0;
203 #ifdef R__WIN32
204  char *demangled_name = __unDName(0, mangled_name, 0, malloc, free, UNDNAME_COMPLETE);
205  if (!demangled_name) {
206  errorCode = -1;
207  return nullptr;
208  }
209 #else
210  char *demangled_name = abi::__cxa_demangle(mangled_name, 0, 0, &errorCode);
211  if (!demangled_name || errorCode) {
212  free(demangled_name);
213  return nullptr;
214  }
215 #endif
216  return demangled_name;
217  }
218  char* DemangleTypeIdName(const std::type_info& ti, int& errorCode);
219 }
220 
221 #endif
ESTLType
Definition: ESTLType.h:28
basic_string_view< char > string_view
Definition: RStringView.h:35
This namespace contains pre-defined functions to be used in conjuction with TExecutor::Map and TExecu...
Definition: StringConv.hxx:21
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
double T(double x)
Definition: ChebyshevPol.h:34
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)
bool IsSTLBitset(const char *type)
Return true is the name is std::bitset<number> or bitset<number>
STL namespace.
#define malloc
Definition: civetweb.c:818
int STLArgs(int kind)
Return number of arguments for STL container before allocator.
Definition: TClassEdit.cxx:512
char * DemangleName(const char *mangled_name, int &errorCode)
Definition: TClassEdit.h:197
std::string GetNameForIO(const std::string &templateInstanceName, TClassEdit::EModType mode=TClassEdit::kNone, bool *hasChanged=nullptr)
const char * fName
Definition: TClassEdit.h:139
void Init(TClassEdit::TInterpreterLookupHelper *helper)
Definition: TClassEdit.cxx:119
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:468
char * DemangleTypeIdName(const std::type_info &ti, int &errorCode)
Demangle in a portable way the type id name.
bool IsStdArray(std::string_view name)
Definition: TClassEdit.h:180
bool IsInterpreterDetail(const char *type)
Return true if the type is one the interpreter details which are only forward declared (ClassInfo_t e...
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:97
bool IsDefHash(const char *hashname, const char *classname)
return whether or not &#39;hashname&#39; is the STL default hash for type &#39;classname&#39;
Definition: TClassEdit.cxx:773
std::vector< std::string > fElements
Definition: TClassEdit.h:140
std::string GetLong64_Name(const std::string &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:828
SVector< double, 2 > v
Definition: Dict.h:5
void GetNormalizedName(std::string &norm_name, std::string_view name)
Return the normalized name.
Definition: TClassEdit.cxx:788
bool IsVectorBool(const char *name)
const Handle_t kNone
Definition: GuiTypes.h:89
int IsSTLCont(const char *type, int testAlloc)
type : type name: vector<list<classA,allocator>,allocator> testAlloc: if true, we test allocator...
bool IsStdClass(const char *type)
return true if the class belongs to the std namespace
bool IsDefAlloc(const char *alloc, const char *keyclassname, const char *valueclassname)
return whether or not &#39;allocname&#39; is the STL default allocator for a key of type &#39;keyclassname&#39; and a...
Definition: TClassEdit.cxx:606
int type
Definition: TGX11.cxx:120
Print a TSeq at the prompt:
Definition: TDatime.h:114
#define free
Definition: civetweb.c:821
bool IsDefComp(const char *comp, const char *classname)
return whether or not &#39;compare&#39; is the STL default comparator for type &#39;classname&#39; ...
Definition: TClassEdit.cxx:755
const char * GetUnqualifiedName(const char *name)
Return the start of the unqualified name include in &#39;original&#39;.
Definition: TClassEdit.cxx:851
std::string ShortType(const char *typeDesc, int mode)
Return the absolute type of typeDesc.
bool IsUniquePtr(std::string_view name)
Definition: TClassEdit.h:179
std::string GetUniquePtrType(std::string_view name)
Definition: TClassEdit.h:181
bool GetStdArrayProperties(const char *typeName, std::string &typeNameBuf, std::array< int, 5 > &maxIndices, int &ndim)
char name[80]
Definition: TGX11.cxx:109
bool IsDefPred(const char *predname, const char *classname)
return whether or not &#39;predname&#39; is the STL default predicate for type &#39;classname&#39; ...
Definition: TClassEdit.cxx:764