Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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 <ROOT/RConfig.hxx>
17#include "RConfigure.h"
18#include <stdlib.h>
19#ifdef R__WIN32
20#ifndef UNDNAME_COMPLETE
21#define UNDNAME_COMPLETE 0x0000
22#endif
23extern "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#include <typeinfo>
35
36#include "ESTLType.h"
37
38#ifdef R__OLDHPACC
39namespace 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>
48namespace 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
58namespace cling {
59 class Interpreter;
60}
61namespace ROOT {
62 namespace TMetaUtils {
63 class TNormalizedCtxt;
64 }
65}
66#include "ROOT/RStringView.hxx"
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
73namespace TClassEdit {
74
75 enum EModType {
76 kNone = 0,
79 kDropAlloc = 1<<2,
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*/,
134 bool /* dropstd */ = true) = 0;
135 virtual void ShuttingDownSignal() = 0;
136 };
137
138 struct TSplitType {
139
140 const char *fName; // Original spelling of the name.
141 std::vector<std::string> fElements;
142 int fNestedLocation; // Stores the location of the tail (nested names) in nestedLoc (0 indicates no tail).
143
144 TSplitType(const char *type2split, EModType mode = TClassEdit::kNone);
145
146 int IsSTLCont(int testAlloc=0) const;
147 ROOT::ESTLType IsInSTL() const;
148 void ShortType(std::string &answer, int mode);
149 bool IsTemplate();
150
151 private:
152 TSplitType(const TSplitType&) = delete;
153 TSplitType &operator=(const TSplitType &) = delete;
154 };
155
157
158 std::string CleanType (const char *typeDesc,int mode = 0,const char **tail = nullptr);
159 inline bool IsArtificial(std::string_view name) { return name.find('@') != name.npos; }
160 inline bool IsArtificial(ROOT::Internal::TStringView name) {return IsArtificial(std::string_view(name)); }
161 bool IsDefAlloc(const char *alloc, const char *classname);
162 bool IsDefAlloc(const char *alloc, const char *keyclassname, const char *valueclassname);
163 bool IsDefComp (const char *comp , const char *classname);
164 bool IsDefPred(const char *predname, const char *classname);
165 bool IsDefHash(const char *hashname, const char *classname);
166 bool IsInterpreterDetail(const char *type);
167 bool IsSTLBitset(const char *type);
168 ROOT::ESTLType UnderlyingIsSTLCont(std::string_view type);
170 ROOT::ESTLType IsSTLCont (std::string_view type);
172 int IsSTLCont (const char *type,int testAlloc);
173 bool IsStdClass(const char *type);
174 bool IsVectorBool(const char *name);
175 void GetNormalizedName(std::string &norm_name, std::string_view name);
176 inline void GetNormalizedName (std::string &norm_name, ROOT::Internal::TStringView name) { return GetNormalizedName(norm_name, std::string_view(name)); }
177 std::string GetLong64_Name(const char *original);
178 std::string GetLong64_Name(const std::string& original);
179 int GetSplit (const char *type, std::vector<std::string> &output, int &nestedLoc, EModType mode = TClassEdit::kNone);
180 ROOT::ESTLType STLKind(std::string_view type); //Kind of stl container
181 inline ROOT::ESTLType STLKind(ROOT::Internal::TStringView type) { return STLKind(std::string_view(type)); }
182 int STLArgs (int kind); //Min number of arguments without allocator
183 std::string ResolveTypedef(const char *tname, bool resolveAll = false);
184 std::string ShortType (const char *typeDesc, int mode);
185 std::string InsertStd(const char *tname);
186 const char* GetUnqualifiedName(const char*name);
187 inline bool IsUniquePtr(std::string_view name) {return 0 == name.compare(0, 11, "unique_ptr<");}
188 inline bool IsUniquePtr(ROOT::Internal::TStringView name) {return IsUniquePtr(std::string_view(name)); }
189 inline bool IsStdArray(std::string_view name) {return 0 == name.compare(0, 6, "array<");}
190 inline bool IsStdArray(ROOT::Internal::TStringView name) {return IsStdArray(std::string_view(name)); }
191 inline bool IsStdPair(std::string_view name)
192 {
193 return 0 == name.compare(0, 10, "std::pair<") || 0 == name.compare(0, 5, "pair<");
194 }
195 inline bool IsStdPair(ROOT::Internal::TStringView name) {return IsStdPair(std::string_view(name)); }
196 inline bool IsStdPairBase(std::string_view name)
197 {
198 return 0 == name.compare(0, 17, "std::__pair_base<") || 0 == name.compare(0, 12, "__pair_base<");
199 }
200 inline bool IsStdPairBase(ROOT::Internal::TStringView name) {return IsStdPairBase(std::string_view(name)); }
201 inline std::string GetUniquePtrType(std::string_view name)
202 {
203 // Find the first template parameter
204 std::vector<std::string> v;
205 int i;
206 GetSplit(name.data(), v, i);
207 return v[1];
208 }
209 inline std::string GetUniquePtrType(ROOT::Internal::TStringView name) {return GetUniquePtrType(std::string_view(name)); }
210 std::string GetNameForIO(const std::string& templateInstanceName,
212 bool* hasChanged = nullptr);
213 bool GetStdArrayProperties(const char* typeName,
214 std::string& typeNameBuf,
215 std::array<int, 5>& maxIndices,
216 int& ndim);
217
218 inline char* DemangleName(const char* mangled_name, int& errorCode)
219 {
220 // Demangle in a portable way the name.
221 // IMPORTANT: The caller is responsible for freeing the returned const char*
222
223 errorCode=0;
224#ifdef R__WIN32
225 char *demangled_name = __unDName(0, mangled_name, 0, malloc, free, UNDNAME_COMPLETE);
226 if (!demangled_name) {
227 errorCode = -1;
228 return nullptr;
229 }
230 std::string demangledName = demangled_name;
231 if (demangledName.compare(0, 6, "class ") == 0)
232 demangledName.erase(0, 6);
233 else if (demangledName.compare(0, 7, "struct ") == 0)
234 demangledName.erase(0, 7);
235 strcpy(demangled_name, demangledName.c_str());
236#else
237 char *demangled_name = abi::__cxa_demangle(mangled_name, nullptr, nullptr, &errorCode);
238 if (!demangled_name || errorCode) {
239 free(demangled_name);
240 return nullptr;
241 }
242#endif
243 return demangled_name;
244 }
245 char* DemangleTypeIdName(const std::type_info& ti, int& errorCode);
246
247
248 /// Result of splitting a function declaration into
249 /// fReturnType fScopeName::fFunctionName<fFunctionTemplateArguments>(fFunctionParameters)
251 /// Return type of the function, might be empty if the function declaration string did not provide it.
252 std::string fReturnType;
253
254 /// Name of the scope qualification of the function, possibly empty
255 std::string fScopeName;
256
257 /// Name of the function
258 std::string fFunctionName;
259
260 /// Template arguments of the function template specialization, if any; will contain one element "" for
261 /// `function<>()`
262 std::vector<std::string> fFunctionTemplateArguments;
263
264 /// Function parameters.
265 std::vector<std::string> fFunctionParameters;
266 };
267
268 /// Split a function declaration into its different parts.
269 bool SplitFunction(std::string_view decl, FunctionSplitInfo &result);
270}
271
272#endif
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t result
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
Option_t Option_t TPoint TPoint const char mode
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
char name[80]
Definition TGX11.cxx:110
#define free
Definition civetweb.c:1539
#define malloc
Definition civetweb.c:1536
virtual bool GetPartiallyDesugaredNameWithScopeHandling(const std::string &, std::string &, bool=true)=0
virtual bool IsAlreadyPartiallyDesugaredName(const std::string &, const std::string &)=0
virtual bool IsDeclaredScope(const std::string &, bool &)=0
virtual void GetPartiallyDesugaredName(std::string &)=0
virtual bool ExistingTypeCheck(const std::string &, std::string &)=0
This file contains a specialised ROOT message handler to test for diagnostic in unit tests.
ESTLType
Definition ESTLType.h:28
@ kSTLbitset
Definition ESTLType.h:37
@ kSTLmap
Definition ESTLType.h:33
@ kSTLunorderedmultiset
Definition ESTLType.h:43
@ kSTLend
Definition ESTLType.h:47
@ kSTLset
Definition ESTLType.h:35
@ kSTLmultiset
Definition ESTLType.h:36
@ kSTLdeque
Definition ESTLType.h:32
@ kSTLvector
Definition ESTLType.h:30
@ kSTLunorderedmultimap
Definition ESTLType.h:45
@ kSTLunorderedset
Definition ESTLType.h:42
@ kSTLlist
Definition ESTLType.h:31
@ kSTLforwardlist
Definition ESTLType.h:41
@ kSTLunorderedmap
Definition ESTLType.h:44
@ kNotSTL
Definition ESTLType.h:29
@ kSTLmultimap
Definition ESTLType.h:34
ROOT::ESTLType STLKind(std::string_view type)
Converts STL container name to number.
bool IsStdPairBase(std::string_view name)
Definition TClassEdit.h:196
bool IsDefComp(const char *comp, const char *classname)
return whether or not 'compare' is the STL default comparator for type 'classname'
std::string ResolveTypedef(const char *tname, bool resolveAll=false)
@ kUnorderedMultiSet
Definition TClassEdit.h:104
@ kUnorderedMultiMap
Definition TClassEdit.h:106
bool IsStdArray(std::string_view name)
Definition TClassEdit.h:189
bool IsStdClass(const char *type)
return true if the class belongs to the std namespace
bool IsDefHash(const char *hashname, const char *classname)
return whether or not 'hashname' is the STL default hash for type 'classname'
bool IsStdPair(std::string_view name)
Definition TClassEdit.h:191
bool IsInterpreterDetail(const char *type)
Return true if the type is one the interpreter details which are only forward declared (ClassInfo_t e...
std::string InsertStd(const char *tname)
bool SplitFunction(std::string_view decl, FunctionSplitInfo &result)
Split a function declaration into its different parts.
std::string GetLong64_Name(const char *original)
Replace 'long long' and 'unsigned long long' by 'Long64_t' and 'ULong64_t'.
bool IsDefPred(const char *predname, const char *classname)
return whether or not 'predname' is the STL default predicate for type 'classname'
char * DemangleTypeIdName(const std::type_info &ti, int &errorCode)
Demangle in a portable way the type id name.
const char * GetUnqualifiedName(const char *name)
Return the start of the unqualified name include in 'original'.
std::string GetUniquePtrType(std::string_view name)
Definition TClassEdit.h:201
bool IsVectorBool(const char *name)
void Init(TClassEdit::TInterpreterLookupHelper *helper)
ROOT::ESTLType IsSTLCont(std::string_view type)
type : type name: vector<list<classA,allocator>,allocator> result: 0 : not stl container code of cont...
std::string CleanType(const char *typeDesc, int mode=0, const char **tail=nullptr)
Cleanup type description, redundant blanks removed and redundant tail ignored return *tail = pointer ...
std::string ShortType(const char *typeDesc, int mode)
Return the absolute type of typeDesc.
char * DemangleName(const char *mangled_name, int &errorCode)
Definition TClassEdit.h:218
bool IsArtificial(std::string_view name)
Definition TClassEdit.h:159
bool GetStdArrayProperties(const char *typeName, std::string &typeNameBuf, std::array< int, 5 > &maxIndices, int &ndim)
std::string GetNameForIO(const std::string &templateInstanceName, TClassEdit::EModType mode=TClassEdit::kNone, bool *hasChanged=nullptr)
int STLArgs(int kind)
Return number of arguments for STL container before allocator.
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.
void GetNormalizedName(std::string &norm_name, std::string_view name)
Return the normalized name.
bool IsDefAlloc(const char *alloc, const char *classname)
return whether or not 'allocname' is the STL default allocator for type 'classname'
bool IsUniquePtr(std::string_view name)
Definition TClassEdit.h:187
@ kDropDefaultAlloc
Definition TClassEdit.h:78
@ kResolveTypedef
Definition TClassEdit.h:88
@ kInnedMostClass
Definition TClassEdit.h:81
@ kDropComparator
Definition TClassEdit.h:83
@ kDropAllDefault
Definition TClassEdit.h:84
@ kKeepOuterConst
Definition TClassEdit.h:87
@ kDropStlDefault
Definition TClassEdit.h:82
bool IsSTLBitset(const char *type)
Return true is the name is std::bitset<number> or bitset<number>
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 *)
Result of splitting a function declaration into fReturnType fScopeName::fFunctionName<fFunctionTempla...
Definition TClassEdit.h:250
std::string fFunctionName
Name of the function.
Definition TClassEdit.h:258
std::vector< std::string > fFunctionTemplateArguments
Template arguments of the function template specialization, if any; will contain one element "" for f...
Definition TClassEdit.h:262
std::string fScopeName
Name of the scope qualification of the function, possibly empty.
Definition TClassEdit.h:255
std::vector< std::string > fFunctionParameters
Function parameters.
Definition TClassEdit.h:265
std::string fReturnType
Return type of the function, might be empty if the function declaration string did not provide it.
Definition TClassEdit.h:252
TSplitType(const TSplitType &)=delete
bool IsTemplate()
Check if the type is a template.
int IsSTLCont(int testAlloc=0) const
type : type name: vector<list<classA,allocator>,allocator> testAlloc: if true, we test allocator,...
std::vector< std::string > fElements
Definition TClassEdit.h:141
ROOT::ESTLType IsInSTL() const
type : type name: vector<list<classA,allocator>,allocator>[::iterator] result: 0 : not stl container ...
TSplitType & operator=(const TSplitType &)=delete
void ShortType(std::string &answer, int mode)
Return the absolute type of typeDesc into the string answ.
static void output()