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#include <stdexcept>
20#ifdef R__WIN32
21#ifndef UNDNAME_COMPLETE
22#define UNDNAME_COMPLETE 0x0000
23#endif
24extern "C" {
25 char *__unDName(char *demangled, const char *mangled, int out_len,
26 void * (* pAlloc )(size_t), void (* pFree )(void *),
27 unsigned short int flags);
28}
29#else
30#include <cxxabi.h>
31#endif
32#include <string>
33#include <vector>
34#include <array>
35#include <typeinfo>
36
37#include "ESTLType.h"
38
39#ifdef R__OLDHPACC
40namespace 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>
49namespace 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
59namespace cling {
60 class Interpreter;
61}
62namespace ROOT {
63 namespace TMetaUtils {
64 class TNormalizedCtxt;
65 }
66}
67#include <string_view>
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
74namespace TClassEdit {
75
76 enum EModType {
77 kNone = 0,
80 kDropAlloc = 1<<2,
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
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 CheckInClassTable(const std::string &, std::string &) = 0;
128 virtual bool ExistingTypeCheck(const std::string & /*tname*/,
129 std::string & /*result*/) = 0;
130 virtual void GetPartiallyDesugaredName(std::string & /*nameLong*/) = 0;
131 virtual bool IsAlreadyPartiallyDesugaredName(const std::string & /*nondef*/,
132 const std::string & /*nameLong*/) = 0;
133 virtual bool IsDeclaredScope(const std::string & /*base*/, bool & /*isInlined*/) = 0;
134 virtual bool GetPartiallyDesugaredNameWithScopeHandling(const std::string & /*tname*/,
135 std::string & /*result*/,
136 bool /* dropstd */ = true) = 0;
137 virtual void ShuttingDownSignal() = 0;
138 };
139
140 struct TSplitType {
141
142 const char *fName; // Original spelling of the name.
143 std::vector<std::string> fElements;
144 int fNestedLocation; // Stores the location of the tail (nested names) in nestedLoc (0 indicates no tail).
145
147
148 int IsSTLCont(int testAlloc=0) const;
149 ROOT::ESTLType IsInSTL() const;
150 void ShortType(std::string &answer, int mode);
151 bool IsTemplate();
152
153 private:
154 TSplitType(const TSplitType&) = delete;
155 TSplitType &operator=(const TSplitType &) = delete;
156 };
157
158 /// A RAII helper to remove and readd enclosing _Atomic()
159 /// It expects no spaces at the beginning or end of the string
161 public:
162 enum class EBehavior : short {
163 kDetectStripReadd, // Detect if the _Atomic specifier is used, if yes, strip it and re-add it in the dtor
164 kDetectStrip, // Detect if the _Atomic specifier is used, if yes, strip it
165 kReadd, // Re-add the _Atomic specifier in the dtor
166 kNoOp // Do nothing
167 };
168
169 private:
170 std::string &fTypeName;
171 bool fIsAtomic = false;
173 const char *fgPrefix = "_Atomic(";
174
175 public:
177 : fTypeName(typeName), fBehavior(behavior)
178 {
180 return;
181 if (0 == fTypeName.find(fgPrefix)) {
182 fIsAtomic = true;
184 fTypeName.erase(0, 8);
185 if (0 == fTypeName.size() || ')' != fTypeName[fTypeName.size() - 1]) {
186 throw std::runtime_error("Cannot remove substring \")\" at the end of typename \"" + typeName + "\"");
187 }
188 fTypeName.pop_back();
189 }
190 }
191 }
192
193 bool IsAtomic() { return fIsAtomic; }
194
201 };
202
204
205 std::string CleanType (const char *typeDesc,int mode = 0,const char **tail = nullptr);
206 inline bool IsArtificial(std::string_view name) { return name.find('@') != name.npos; }
207 bool IsDefAlloc(const char *alloc, const char *classname);
208 bool IsDefAlloc(const char *alloc, const char *keyclassname, const char *valueclassname);
209 bool IsDefComp (const char *comp , const char *classname);
210 bool IsDefPred(const char *predname, const char *classname);
211 bool IsDefHash(const char *hashname, const char *classname);
212 bool IsInterpreterDetail(const char *type);
213 bool IsSTLBitset(const char *type);
214 ROOT::ESTLType UnderlyingIsSTLCont(std::string_view type);
215 ROOT::ESTLType IsSTLCont (std::string_view type);
216 int IsSTLCont (const char *type,int testAlloc);
217 bool IsStdClass(const char *type);
218 bool IsVectorBool(const char *name);
219 void GetNormalizedName(std::string &norm_name, std::string_view name);
220 std::string GetLong64_Name(const char *original);
221 std::string GetLong64_Name(const std::string& original);
222 int GetSplit (const char *type, std::vector<std::string> &output, int &nestedLoc, EModType mode = TClassEdit::kNone);
223 ROOT::ESTLType STLKind(std::string_view type); //Kind of stl container
224 int STLArgs (int kind); //Min number of arguments without allocator
225 std::string ResolveTypedef(const char *tname, bool resolveAll = false);
226 std::string ShortType (const char *typeDesc, int mode);
227 std::string InsertStd(const char *tname);
228 const char* GetUnqualifiedName(const char*name);
229 inline bool IsUniquePtr(std::string_view name) {return 0 == name.compare(0, 11, "unique_ptr<");}
230 inline bool IsStdArray(std::string_view name) {return 0 == name.compare(0, 6, "array<");}
231 inline bool IsStdPair(std::string_view name)
232 {
233 return 0 == name.compare(0, 10, "std::pair<") || 0 == name.compare(0, 5, "pair<");
234 }
235 inline bool IsStdPairBase(std::string_view name)
236 {
237 return 0 == name.compare(0, 17, "std::__pair_base<") || 0 == name.compare(0, 12, "__pair_base<");
238 }
239 inline std::string GetUniquePtrType(std::string_view name)
240 {
241 // Find the first template parameter
242 std::vector<std::string> v;
243 int i;
244 GetSplit(name.data(), v, i);
245 return v[1];
246 }
247 std::string GetNameForIO(const std::string& templateInstanceName,
249 bool* hasChanged = nullptr);
250 bool GetStdArrayProperties(const char* typeName,
251 std::string& typeNameBuf,
252 std::array<int, 5>& maxIndices,
253 int& ndim);
254
255 inline char* DemangleName(const char* mangled_name, int& errorCode)
256 {
257 // Demangle in a portable way the name.
258 // IMPORTANT: The caller is responsible for freeing the returned const char*
259
260 errorCode=0;
261#ifdef R__WIN32
263 if (!demangled_name) {
264 errorCode = -1;
265 return nullptr;
266 }
267 std::string demangledName = demangled_name;
268 if (demangledName.compare(0, 6, "class ") == 0)
269 demangledName.erase(0, 6);
270 else if (demangledName.compare(0, 7, "struct ") == 0)
271 demangledName.erase(0, 7);
273#else
274 char *demangled_name = abi::__cxa_demangle(mangled_name, nullptr, nullptr, &errorCode);
275 if (!demangled_name || errorCode) {
277 return nullptr;
278 }
279#endif
280 return demangled_name;
281 }
282 char* DemangleTypeIdName(const std::type_info& ti, int& errorCode);
283
284
285 /// Result of splitting a function declaration into
286 /// fReturnType fScopeName::fFunctionName<fFunctionTemplateArguments>(fFunctionParameters)
288 /// Return type of the function, might be empty if the function declaration string did not provide it.
289 std::string fReturnType;
290
291 /// Name of the scope qualification of the function, possibly empty
292 std::string fScopeName;
293
294 /// Name of the function
295 std::string fFunctionName;
296
297 /// Template arguments of the function template specialization, if any; will contain one element "" for
298 /// `function<>()`
299 std::vector<std::string> fFunctionTemplateArguments;
300
301 /// Function parameters.
302 std::vector<std::string> fFunctionParameters;
303 };
304
305 /// Split a function declaration into its different parts.
306 bool SplitFunction(std::string_view decl, FunctionSplitInfo &result);
307}
308
309#endif
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
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
A RAII helper to remove and readd enclosing _Atomic() It expects no spaces at the beginning or end of...
Definition TClassEdit.h:160
AtomicTypeNameHandlerRAII(std::string &typeName, EBehavior behavior=EBehavior::kDetectStripReadd)
Definition TClassEdit.h:176
virtual bool CheckInClassTable(const std::string &, std::string &)=0
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
struct void * fTypeName
Definition cppyy.h:9
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
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:235
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:105
@ kUnorderedMultiMap
Definition TClassEdit.h:107
bool IsStdArray(std::string_view name)
Definition TClassEdit.h:230
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:231
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:239
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:255
bool IsArtificial(std::string_view name)
Definition TClassEdit.h:206
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:229
@ kDropDefaultAlloc
Definition TClassEdit.h:79
@ kResolveTypedef
Definition TClassEdit.h:89
@ kInnedMostClass
Definition TClassEdit.h:82
@ kDropComparator
Definition TClassEdit.h:84
@ kDropAllDefault
Definition TClassEdit.h:85
@ kKeepOuterConst
Definition TClassEdit.h:88
@ kDropStlDefault
Definition TClassEdit.h:83
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:287
std::string fFunctionName
Name of the function.
Definition TClassEdit.h:295
std::vector< std::string > fFunctionTemplateArguments
Template arguments of the function template specialization, if any; will contain one element "" for f...
Definition TClassEdit.h:299
std::string fScopeName
Name of the scope qualification of the function, possibly empty.
Definition TClassEdit.h:292
std::vector< std::string > fFunctionParameters
Function parameters.
Definition TClassEdit.h:302
std::string fReturnType
Return type of the function, might be empty if the function declaration string did not provide it.
Definition TClassEdit.h:289
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,...
TSplitType(const char *type2split, EModType mode=TClassEdit::kNone)
default constructor
std::vector< std::string > fElements
Definition TClassEdit.h:143
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()