typeinfo.h 8.82 KB
Newer Older
SND\kernelnet_cp's avatar
SND\kernelnet_cp committed
1 2 3 4 5 6 7 8 9
#pragma once

#include <string>

#include <boost/utility.hpp>
#include <boost/shared_ptr.hpp>

#include "kdlib/symengine.h"
#include "kdlib/variant.h"
SND\ussrhero_cp's avatar
SND\ussrhero_cp committed
10
#include "kdlib/dataaccessor.h"
SND\kernelnet_cp's avatar
SND\kernelnet_cp committed
11 12 13 14 15 16 17 18

namespace kdlib {

///////////////////////////////////////////////////////////////////////////////

class TypeInfo;
typedef boost::shared_ptr<TypeInfo>     TypeInfoPtr;

SND\ussrhero_cp's avatar
SND\ussrhero_cp committed
19 20 21
class TypedVar;
typedef boost::shared_ptr<TypedVar>     TypedVarPtr;

SND\kernelnet_cp's avatar
SND\kernelnet_cp committed
22
TypeInfoPtr loadType( const std::wstring &symName );
ussrhero's avatar
ussrhero committed
23 24
TypeInfoPtr loadType( const SymbolPtr &symbol );
TypeInfoPtr loadType( const SymbolPtr &symbolScope, const std::wstring &symbolName ); 
SND\kernelnet_cp's avatar
SND\kernelnet_cp committed
25

SND\kernelnet_cp's avatar
SND\kernelnet_cp committed
26
TypeInfoPtr defineStruct( const std::wstring &structName, size_t align = 0 );
27
TypeInfoPtr defineUnion( const std::wstring& unionName, size_t align = 0 );
SND\ussrhero_cp's avatar
SND\ussrhero_cp committed
28
TypeInfoPtr defineFunction( const TypeInfoPtr& returnType, CallingConventionType callconv = CallConv_NearC);
29

SND\ussrhero_cp's avatar
 
SND\ussrhero_cp committed
30 31
TypeInfoPtr compileType( const std::wstring &sourceCode, const std::wstring& typeName , const std::wstring  &options=L"");

SND\kernelnet_cp's avatar
SND\kernelnet_cp committed
32
size_t getSymbolSize( const std::wstring &name );
SND\kernelnet_cp's avatar
SND\kernelnet_cp committed
33
MEMOFFSET_64 getSymbolOffset( const std::wstring &name );
SND\kernelnet_cp's avatar
SND\kernelnet_cp committed
34
std::wstring findSymbol( MEMOFFSET_64 offset);
SND\kernelnet_cp's avatar
SND\kernelnet_cp committed
35
std::wstring findSymbol( MEMOFFSET_64 offset, MEMDISPLACEMENT &displacement );
SND\kernelnet_cp's avatar
SND\kernelnet_cp committed
36

ussrhero's avatar
ussrhero committed
37
class TypeInfo : public NumConvertable, private boost::noncopyable {
SND\kernelnet_cp's avatar
SND\kernelnet_cp committed
38 39

    friend TypeInfoPtr loadType( const std::wstring &symName );
ussrhero's avatar
ussrhero committed
40 41
    friend TypeInfoPtr loadType( const SymbolPtr &symbol );
    friend TypeInfoPtr loadType( const SymbolPtr &symbolScope, const std::wstring &symbolName ); 
SND\kernelnet_cp's avatar
SND\kernelnet_cp committed
42
    friend size_t getSymbolSize( const std::wstring &name );
SND\kernelnet_cp's avatar
SND\kernelnet_cp committed
43

44 45 46 47 48 49 50 51 52 53

public:

    enum MemberFilter
    {
        DataMember = 0x1,      // include data member
        InheritedMember = 0x2, // include inherited member
        MethodMember = 0x4     // include method
    };

SND\kernelnet_cp's avatar
SND\kernelnet_cp committed
54 55
public:

SND\kernelnet_cp's avatar
SND\kernelnet_cp committed
56 57
    virtual std::wstring str() = 0;

SND\kernelnet_cp's avatar
SND\kernelnet_cp committed
58
    virtual std::wstring getName() = 0;
59
    virtual std::wstring getScopeName() = 0;
60 61
    virtual std::pair<std::wstring, std::wstring> splitName() = 0;

SND\kernelnet_cp's avatar
SND\kernelnet_cp committed
62 63
    virtual size_t getSize() = 0;
    virtual size_t getPtrSize() = 0;
64

65
    virtual TypeInfoPtr ptrTo( size_t ptrSize = 0 ) = 0;
66
    virtual TypeInfoPtr deref() = 0;
67
    virtual TypeInfoPtr arrayOf( size_t size ) = 0;
ussrhero's avatar
ussrhero committed
68
    virtual TypeInfoPtr arrayOf() = 0; // make incomplete array
SND\kernelnet_cp's avatar
SND\kernelnet_cp committed
69 70 71 72 73 74 75 76 77

    virtual bool isArray() = 0;
    virtual bool isPointer() = 0;
    virtual bool isVoid() = 0;
    virtual bool isBase() = 0;
    virtual bool isUserDefined() = 0;
    virtual bool isConstant() = 0;
    virtual bool isEnum() = 0;
    virtual bool isBitField() = 0;
SND\kernelnet_cp's avatar
SND\kernelnet_cp committed
78
    virtual bool isFunction() = 0;
SND\kernelnet_cp's avatar
SND\kernelnet_cp committed
79
    virtual bool isVtbl() = 0;
80
    virtual bool isNoType() = 0;
ussrhero's avatar
ussrhero committed
81
    virtual bool isTemplate() = 0;
82
    virtual bool isIncomplete() = 0;
SND\kernelnet_cp's avatar
SND\kernelnet_cp committed
83 84 85 86 87 88 89

    virtual BITOFFSET getBitOffset() = 0;
    virtual BITOFFSET getBitWidth() = 0;
    virtual TypeInfoPtr getBitType() = 0;

    virtual TypeInfoPtr getElement( const std::wstring &name ) = 0;
    virtual TypeInfoPtr getElement( size_t index ) = 0;
SND\kernelnet_cp's avatar
SND\kernelnet_cp committed
90 91
    virtual MEMOFFSET_REL getElementOffset( const std::wstring &name ) = 0;
    virtual MEMOFFSET_REL getElementOffset( size_t index ) = 0;
SND\kernelnet_cp's avatar
SND\kernelnet_cp committed
92 93 94 95 96
    virtual std::wstring getElementName( size_t index ) = 0;
    virtual size_t getElementIndex( const std::wstring &name ) = 0;
    virtual size_t getElementCount() = 0;
    virtual  MEMOFFSET_64 getElementVa( const std::wstring &name ) = 0;
    virtual  MEMOFFSET_64 getElementVa( size_t index ) = 0;
SND\kernelnet_cp's avatar
SND\kernelnet_cp committed
97
    
SND\kernelnet_cp's avatar
SND\kernelnet_cp committed
98 99 100
    virtual bool isStaticMember( const std::wstring &name ) = 0;
    virtual bool isStaticMember( size_t index ) = 0;

SND\kernelnet_cp's avatar
SND\kernelnet_cp committed
101 102 103
    virtual bool isVirtualMember( const std::wstring &name ) = 0;
    virtual bool isVirtualMember( size_t index ) = 0;

ussrhero's avatar
ussrhero committed
104 105 106
    virtual bool isConstMember(const std::wstring &name) = 0;
    virtual bool isConstMember(size_t index) = 0;

107 108
    virtual bool isInheritedMember(const std::wstring &name) = 0;
    virtual bool isInheritedMember(size_t index) = 0;
SND\ussrhero_cp's avatar
 
SND\ussrhero_cp committed
109

110
    virtual bool isVirtual() = 0;
ussrhero's avatar
ussrhero committed
111

SND\ussrhero_cp's avatar
 
SND\ussrhero_cp committed
112 113 114
    virtual TypeInfoPtr getMethod( const std::wstring &name, const std::wstring&  prototype = L"") = 0;
    virtual TypeInfoPtr getMethod( const std::wstring &name, TypeInfoPtr prototype) = 0;
    virtual TypeInfoPtr getMethod( size_t index ) = 0;
ussrhero's avatar
ussrhero committed
115
    virtual std::wstring getMethodName(size_t index) = 0;
SND\ussrhero_cp's avatar
 
SND\ussrhero_cp committed
116 117 118 119 120 121 122 123 124 125 126 127
    virtual size_t getMethodsCount() = 0;

    virtual TypeInfoPtr getBaseClass( const std::wstring& className) = 0;
    virtual TypeInfoPtr getBaseClass( size_t index ) = 0;
    virtual size_t getBaseClassesCount() = 0;
    virtual MEMOFFSET_REL getBaseClassOffset( const std::wstring &name ) = 0;
    virtual MEMOFFSET_REL getBaseClassOffset( size_t index ) = 0;
    virtual bool isBaseClassVirtual( const std::wstring &name ) = 0;
    virtual bool isBaseClassVirtual( size_t index ) = 0;

    virtual void getBaseClassVirtualDisplacement( const std::wstring &name, MEMOFFSET_32 &virtualBasePtr, size_t &virtualDispIndex, size_t &virtualDispSize ) = 0;
    virtual void getBaseClassVirtualDisplacement( size_t index, MEMOFFSET_32 &virtualBasePtr, size_t &virtualDispIndex, size_t &virtualDispSize ) = 0;
SND\kernelnet_cp's avatar
SND\kernelnet_cp committed
128

SND\kernelnet_cp's avatar
SND\kernelnet_cp committed
129
    virtual void getVirtualDisplacement( const std::wstring& fieldName, MEMOFFSET_32 &virtualBasePtr, size_t &virtualDispIndex, size_t &virtualDispSize ) = 0;
SND\kernelnet_cp's avatar
SND\kernelnet_cp committed
130
    virtual void getVirtualDisplacement( size_t fieldIndex, MEMOFFSET_32 &virtualBasePtr, size_t &virtualDispIndex, size_t &virtualDispSize ) = 0;
SND\kernelnet_cp's avatar
SND\kernelnet_cp committed
131

132 133
    virtual CallingConventionType getCallingConvention() = 0; // <- CallingConventionType
    virtual bool hasThis() = 0;
134
    virtual TypeInfoPtr getReturnType() = 0;
135

ussrhero's avatar
ussrhero committed
136
    virtual void appendField(const std::wstring &fieldName, const TypeInfoPtr &fieldType ) = 0;
SND\kernelnet_cp's avatar
SND\kernelnet_cp committed
137

138 139
    virtual TypeInfoPtr getClassParent() = 0;

140 141 142 143
    // http://msdn.microsoft.com/en-us/library/hx1b6kkd.aspx
    // "Padding and Alignment of Structure Members"
    virtual size_t getAlignReq() = 0;

SND\ussrhero_cp's avatar
 
SND\ussrhero_cp committed
144 145 146 147
    virtual TypeInfoPtr getVTBL() = 0;

    virtual MEMOFFSET_REL getVtblOffset() = 0;

SND\ussrhero_cp's avatar
SND\ussrhero_cp committed
148 149
    virtual TypedVarPtr getVar(const DataAccessorPtr &dataSource) = 0;

ussrhero's avatar
ussrhero committed
150 151 152
    virtual size_t getTemplateArgsCount() = 0;
    virtual std::wstring getTemplateArg(size_t index) = 0;

SND\kernelnet_cp's avatar
SND\kernelnet_cp committed
153 154 155 156
protected:

    static bool isBaseType( const std::wstring &typeName );
    static bool isComplexType( const std::wstring &typeName );
SND\kernelnet_cp's avatar
SND\kernelnet_cp committed
157
    static TypeInfoPtr getTypeInfoFromCache(const std::wstring &typeName );
SND\kernelnet_cp's avatar
SND\kernelnet_cp committed
158

ussrhero's avatar
ussrhero committed
159
    static TypeInfoPtr getBaseTypeInfo( const std::wstring &typeName, size_t ptrSize = 0);
ussrhero's avatar
ussrhero committed
160
    static TypeInfoPtr getBaseTypeInfo( const SymbolPtr &symbolScope );
SND\kernelnet_cp's avatar
SND\kernelnet_cp committed
161

ussrhero's avatar
ussrhero committed
162
    static TypeInfoPtr getComplexTypeInfo( const std::wstring &typeName, const SymbolPtr &symbolScope );
SND\kernelnet_cp's avatar
SND\kernelnet_cp committed
163 164 165 166 167 168 169 170 171 172 173
    static TypeInfoPtr getRecursiveComplexType( const std::wstring &typeName, TypeInfoPtr &lowestType, std::wstring &suffix, size_t ptrSize );

    TypeInfo() 
    {}

    virtual ~TypeInfo() 
    {}
};

///////////////////////////////////////////////////////////////////////////////

ussrhero's avatar
ussrhero committed
174 175 176
class TypeInfoEnumerator;
typedef boost::shared_ptr<TypeInfoEnumerator>     TypeInfoEnumeratorPtr;

SND\ussrhero_cp's avatar
SND\ussrhero_cp committed
177 178 179 180 181 182 183 184
class TypeInfoProvider;
typedef boost::shared_ptr<TypeInfoProvider>     TypeInfoProviderPtr;

class TypeInfoProvider 
{
public:

    virtual TypeInfoPtr getTypeByName(const std::wstring& name) = 0;
ussrhero's avatar
ussrhero committed
185 186
    virtual TypeInfoEnumeratorPtr getTypeEnumerator(const std::wstring& mask = L"") = 0;
};
SND\ussrhero_cp's avatar
SND\ussrhero_cp committed
187

ussrhero's avatar
ussrhero committed
188 189 190
class TypeInfoEnumerator {
public:
    virtual TypeInfoPtr Next() = 0;
SND\ussrhero_cp's avatar
SND\ussrhero_cp committed
191 192 193
};

TypeInfoProviderPtr  getTypeInfoProviderFromSource( const std::wstring&  source, const std::wstring&  opts = L"" );
ussrhero's avatar
ussrhero committed
194
TypeInfoProviderPtr  getTypeInfoProviderFromSource(const std::string&  source, const std::string&  opts = "");
SND\ussrhero_cp's avatar
SND\ussrhero_cp committed
195
TypeInfoProviderPtr  getTypeInfoProviderFromPdb( const std::wstring&  pdbFile, MEMOFFSET_64  loadBase = 0 );
ussrhero's avatar
ussrhero committed
196
TypeInfoProviderPtr  getDefaultTypeInfoProvider();
SND\ussrhero_cp's avatar
SND\ussrhero_cp committed
197 198 199

///////////////////////////////////////////////////////////////////////////////

200 201 202
TypeInfoPtr makeCharConst(char val);
TypeInfoPtr makeShortConst(short val);
TypeInfoPtr makeLongConst(long val);
SND\ussrhero_cp's avatar
SND\ussrhero_cp committed
203
TypeInfoPtr makeLongLongConst(long long val);
204 205 206
TypeInfoPtr makeUCharConst(unsigned char val);
TypeInfoPtr makeUShortConst(unsigned short val);
TypeInfoPtr makeULongConst(unsigned long val);
SND\ussrhero_cp's avatar
SND\ussrhero_cp committed
207
TypeInfoPtr makeULongLongConst(unsigned long long val);
208 209 210 211 212 213 214 215 216
TypeInfoPtr makeIntConst(int val);
TypeInfoPtr makeUIntConst(unsigned int val);
TypeInfoPtr makeFloatConst(float val);
TypeInfoPtr makeDoubleConst(double val);
TypeInfoPtr makeWCharConst(wchar_t val);
TypeInfoPtr makeBoolConst(bool val);

///////////////////////////////////////////////////////////////////////////////

ussrhero's avatar
ussrhero committed
217 218 219 220 221
TypeInfoPtr evalType(const std::wstring& expr, const TypeInfoProviderPtr typeInfoProvider = getDefaultTypeInfoProvider());
TypeInfoPtr evalType(const std::string& expr, const TypeInfoProviderPtr typeInfoProvider = getDefaultTypeInfoProvider());

///////////////////////////////////////////////////////////////////////////////

SND\kernelnet_cp's avatar
SND\kernelnet_cp committed
222
}; // kdlib namespace end