Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:11:36

0001 // @(#)root/metautils:$Id$
0002 // Author: Victor Perev   10/04/2003
0003 //         Philippe Canal 05/2004
0004 
0005 /*************************************************************************
0006  * Copyright (C) 1995-2003, Rene Brun and Fons Rademakers.               *
0007  * All rights reserved.                                                  *
0008  *                                                                       *
0009  * For the licensing terms see $ROOTSYS/LICENSE.                         *
0010  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
0011  *************************************************************************/
0012 
0013 #ifndef ROOT_TClassEdit
0014 #define ROOT_TClassEdit
0015 
0016 #include <ROOT/RConfig.hxx>
0017 #include "RConfigure.h"
0018 #include <stdlib.h>
0019 #ifdef R__WIN32
0020 #ifndef UNDNAME_COMPLETE
0021 #define UNDNAME_COMPLETE 0x0000
0022 #endif
0023 extern "C" {
0024    char *__unDName(char *demangled, const char *mangled, int out_len,
0025                    void * (* pAlloc )(size_t), void (* pFree )(void *),
0026                    unsigned short int flags);
0027 }
0028 #else
0029 #include <cxxabi.h>
0030 #endif
0031 #include <string>
0032 #include <vector>
0033 #include <array>
0034 #include <typeinfo>
0035 
0036 #include "ESTLType.h"
0037 
0038 #ifdef R__OLDHPACC
0039 namespace std {
0040    using ::string;
0041    using ::vector;
0042 }
0043 #endif
0044 
0045 #if defined(__CYGWIN__)
0046 // std::to_string is missing on cygwin with gcc 4.8.2-2 and 4.8.3
0047 #include <sstream>
0048 namespace std {
0049   template <typename T>
0050   string to_string(T value) {
0051     ostringstream os;
0052     os << value;
0053     return os.str();
0054   }
0055 }
0056 #endif
0057 
0058 namespace cling {
0059    class Interpreter;
0060 }
0061 namespace ROOT {
0062    namespace TMetaUtils {
0063       class TNormalizedCtxt;
0064    }
0065 }
0066 #include <string_view>
0067 
0068 // TClassEdit is used to manipulate class and type names.
0069 //
0070 // This class does not dependent on any other ROOT facility
0071 // so that it can be used by rootcint.
0072 
0073 namespace TClassEdit {
0074 
0075    enum EModType {
0076       kNone             = 0,
0077       kDropTrailStar    = 1<<0,
0078       kDropDefaultAlloc = 1<<1,
0079       kDropAlloc        = 1<<2,
0080       kInnerClass       = 1<<3,
0081       kInnedMostClass   = 1<<4,
0082       kDropStlDefault   = 1<<5, /* implies kDropDefaultAlloc */
0083       kDropComparator   = 1<<6, /* if the class has a comparator, drops BOTH the comparator and the Allocator */
0084       kDropAllDefault   = 1<<7, /* Drop default template parameter even in non STL classes */
0085       kLong64           = 1<<8, /* replace all 'long long' with Long64_t. */
0086       kDropStd          = 1<<9, /* Drop any std:: */
0087       kKeepOuterConst   = 1<<10,/* Make sure to keep the const keyword even outside the template parameters */
0088       kResolveTypedef   = 1<<11,/* Strip all typedef except Double32_t and co. */
0089       kDropPredicate    = 1<<12,/* Drop the predicate if applies to the collection */
0090       kDropHash         = 1<<13 /* Drop the hash if applies to the collection */
0091    };
0092 
0093    enum ESTLType {
0094       kNotSTL            = ROOT::kNotSTL,
0095       kVector            = ROOT::kSTLvector,
0096       kList              = ROOT::kSTLlist,
0097       kForwardlist       = ROOT::kSTLforwardlist,
0098       kDeque             = ROOT::kSTLdeque,
0099       kMap               = ROOT::kSTLmap,
0100       kMultiMap          = ROOT::kSTLmultimap,
0101       kSet               = ROOT::kSTLset,
0102       kMultiSet          = ROOT::kSTLmultiset,
0103       kUnorderedSet      = ROOT::kSTLunorderedset,
0104       kUnorderedMultiSet = ROOT::kSTLunorderedmultiset,
0105       kUnorderedMap      = ROOT::kSTLunorderedmap,
0106       kUnorderedMultiMap = ROOT::kSTLunorderedmultimap,
0107       kBitSet            = ROOT::kSTLbitset,
0108       kEnd               = ROOT::kSTLend
0109    };
0110 
0111    enum class EComplexType : short {
0112       kNone,
0113       kDouble,
0114       kFloat,
0115       kInt,
0116       kLong
0117    };
0118 
0119    EComplexType GetComplexType(const char*);
0120 
0121    class TInterpreterLookupHelper {
0122    public:
0123       TInterpreterLookupHelper() { }
0124       virtual ~TInterpreterLookupHelper();
0125 
0126       virtual bool ExistingTypeCheck(const std::string & /*tname*/,
0127                                      std::string & /*result*/) = 0;
0128       virtual void GetPartiallyDesugaredName(std::string & /*nameLong*/) = 0;
0129       virtual bool IsAlreadyPartiallyDesugaredName(const std::string & /*nondef*/,
0130                                                    const std::string & /*nameLong*/) = 0;
0131       virtual bool IsDeclaredScope(const std::string & /*base*/, bool & /*isInlined*/) = 0;
0132       virtual bool GetPartiallyDesugaredNameWithScopeHandling(const std::string & /*tname*/,
0133                                                               std::string & /*result*/,
0134                                                               bool /* dropstd */ = true) = 0;
0135       virtual void ShuttingDownSignal() = 0;
0136    };
0137 
0138    struct TSplitType {
0139 
0140       const char *fName; // Original spelling of the name.
0141       std::vector<std::string> fElements;
0142       int fNestedLocation; // Stores the location of the tail (nested names) in nestedLoc (0 indicates no tail).
0143 
0144       TSplitType(const char *type2split, EModType mode = TClassEdit::kNone);
0145 
0146       int  IsSTLCont(int testAlloc=0) const;
0147       ROOT::ESTLType  IsInSTL() const;
0148       void ShortType(std::string &answer, int mode);
0149       bool IsTemplate();
0150 
0151    private:
0152       TSplitType(const TSplitType&) = delete;
0153       TSplitType &operator=(const TSplitType &) = delete;
0154    };
0155 
0156    void        Init(TClassEdit::TInterpreterLookupHelper *helper);
0157 
0158    std::string CleanType (const char *typeDesc,int mode = 0,const char **tail = nullptr);
0159    inline bool IsArtificial(std::string_view name) { return name.find('@') != name.npos; }
0160    bool        IsDefAlloc(const char *alloc, const char *classname);
0161    bool        IsDefAlloc(const char *alloc, const char *keyclassname, const char *valueclassname);
0162    bool        IsDefComp (const char *comp , const char *classname);
0163    bool        IsDefPred(const char *predname, const char *classname);
0164    bool        IsDefHash(const char *hashname, const char *classname);
0165    bool        IsInterpreterDetail(const char *type);
0166    bool        IsSTLBitset(const char *type);
0167    ROOT::ESTLType UnderlyingIsSTLCont(std::string_view type);
0168    ROOT::ESTLType IsSTLCont (std::string_view type);
0169    int         IsSTLCont (const char *type,int testAlloc);
0170    bool        IsStdClass(const char *type);
0171    bool        IsVectorBool(const char *name);
0172    void        GetNormalizedName(std::string &norm_name, std::string_view name);
0173    std::string GetLong64_Name(const char *original);
0174    std::string GetLong64_Name(const std::string& original);
0175    int         GetSplit  (const char *type, std::vector<std::string> &output, int &nestedLoc, EModType mode = TClassEdit::kNone);
0176    ROOT::ESTLType STLKind(std::string_view type);    //Kind of stl container
0177    int         STLArgs   (int kind);            //Min number of arguments without allocator
0178    std::string ResolveTypedef(const char *tname, bool resolveAll = false);
0179    std::string ShortType (const char *typeDesc, int mode);
0180    std::string InsertStd(const char *tname);
0181    const char* GetUnqualifiedName(const char*name);
0182    inline bool IsUniquePtr(std::string_view name) {return 0 == name.compare(0, 11, "unique_ptr<");}
0183    inline bool IsStdArray(std::string_view name) {return 0 == name.compare(0, 6, "array<");}
0184    inline bool IsStdPair(std::string_view name)
0185    {
0186       return 0 == name.compare(0, 10, "std::pair<") || 0 == name.compare(0, 5, "pair<");
0187    }
0188    inline bool IsStdPairBase(std::string_view name)
0189    {
0190       return 0 == name.compare(0, 17, "std::__pair_base<") || 0 == name.compare(0, 12, "__pair_base<");
0191    }
0192    inline std::string GetUniquePtrType(std::string_view name)
0193    {
0194       // Find the first template parameter
0195       std::vector<std::string> v;
0196       int i;
0197       GetSplit(name.data(), v, i);
0198       return v[1];
0199    }
0200    std::string GetNameForIO(const std::string& templateInstanceName,
0201                            TClassEdit::EModType mode = TClassEdit::kNone,
0202                            bool* hasChanged = nullptr);
0203    bool GetStdArrayProperties(const char* typeName,
0204                               std::string& typeNameBuf,
0205                               std::array<int, 5>& maxIndices,
0206                               int& ndim);
0207 
0208    inline char* DemangleName(const char* mangled_name, int& errorCode)
0209    {
0210    // Demangle in a portable way the name.
0211    // IMPORTANT: The caller is responsible for freeing the returned const char*
0212 
0213    errorCode=0;
0214 #ifdef R__WIN32
0215    char *demangled_name = __unDName(0, mangled_name, 0, malloc, free, UNDNAME_COMPLETE);
0216    if (!demangled_name) {
0217       errorCode = -1;
0218       return nullptr;
0219    }
0220    std::string demangledName = demangled_name;
0221    if (demangledName.compare(0, 6, "class ") == 0)
0222       demangledName.erase(0, 6);
0223    else if (demangledName.compare(0, 7, "struct ") == 0)
0224       demangledName.erase(0, 7);
0225    strcpy(demangled_name, demangledName.c_str());
0226 #else
0227    char *demangled_name = abi::__cxa_demangle(mangled_name, nullptr, nullptr, &errorCode);
0228    if (!demangled_name || errorCode) {
0229       free(demangled_name);
0230       return nullptr;
0231    }
0232 #endif
0233    return demangled_name;
0234    }
0235    char* DemangleTypeIdName(const std::type_info& ti, int& errorCode);
0236 
0237 
0238    /// Result of splitting a function declaration into
0239    /// fReturnType fScopeName::fFunctionName<fFunctionTemplateArguments>(fFunctionParameters)
0240    struct FunctionSplitInfo {
0241       /// Return type of the function, might be empty if the function declaration string did not provide it.
0242       std::string fReturnType;
0243 
0244       /// Name of the scope qualification of the function, possibly empty
0245       std::string fScopeName;
0246 
0247       /// Name of the function
0248       std::string fFunctionName;
0249 
0250       /// Template arguments of the function template specialization, if any; will contain one element "" for
0251       /// `function<>()`
0252       std::vector<std::string> fFunctionTemplateArguments;
0253 
0254       /// Function parameters.
0255       std::vector<std::string> fFunctionParameters;
0256    };
0257 
0258    /// Split a function declaration into its different parts.
0259    bool SplitFunction(std::string_view decl, FunctionSplitInfo &result);
0260 }
0261 
0262 #endif