Commit 58bd6564 authored by ussrhero's avatar ussrhero
Browse files

added method TypeInfo::isInheritedMember

parent 5fac5778
...@@ -41,6 +41,16 @@ class TypeInfo : public NumConvertable, private boost::noncopyable { ...@@ -41,6 +41,16 @@ class TypeInfo : public NumConvertable, private boost::noncopyable {
friend TypeInfoPtr loadType( const SymbolPtr &symbolScope, const std::wstring &symbolName ); friend TypeInfoPtr loadType( const SymbolPtr &symbolScope, const std::wstring &symbolName );
friend size_t getSymbolSize( const std::wstring &name ); friend size_t getSymbolSize( const std::wstring &name );
public:
enum MemberFilter
{
DataMember = 0x1, // include data member
InheritedMember = 0x2, // include inherited member
MethodMember = 0x4 // include method
};
public: public:
virtual std::wstring str() = 0; virtual std::wstring str() = 0;
...@@ -69,6 +79,7 @@ public: ...@@ -69,6 +79,7 @@ public:
virtual bool isVtbl() = 0; virtual bool isVtbl() = 0;
virtual bool isNoType() = 0; virtual bool isNoType() = 0;
virtual bool isTemplate() = 0; virtual bool isTemplate() = 0;
virtual bool isIncomplete() = 0;
virtual BITOFFSET getBitOffset() = 0; virtual BITOFFSET getBitOffset() = 0;
virtual BITOFFSET getBitWidth() = 0; virtual BITOFFSET getBitWidth() = 0;
...@@ -93,9 +104,10 @@ public: ...@@ -93,9 +104,10 @@ public:
virtual bool isConstMember(const std::wstring &name) = 0; virtual bool isConstMember(const std::wstring &name) = 0;
virtual bool isConstMember(size_t index) = 0; virtual bool isConstMember(size_t index) = 0;
virtual bool isVirtual() = 0; virtual bool isInheritedMember(const std::wstring &name) = 0;
virtual bool isInheritedMember(size_t index) = 0;
virtual bool isIncomplete() = 0; virtual bool isVirtual() = 0;
virtual TypeInfoPtr getMethod( const std::wstring &name, const std::wstring& prototype = L"") = 0; 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( const std::wstring &name, TypeInfoPtr prototype) = 0;
......
...@@ -260,7 +260,11 @@ void TypeInfoClangStruct::getRecursiveFields( clang::RecordDecl* recordDecl, MEM ...@@ -260,7 +260,11 @@ void TypeInfoClangStruct::getRecursiveFields( clang::RecordDecl* recordDecl, MEM
} }
else else
{ {
m_fields.push_back( TypeFieldClangField::getField(m_astSession, recordDecl, fieldDecl, startOffset) );
auto field = TypeFieldClangField::getField(m_astSession, recordDecl, fieldDecl, startOffset);
if (recordDecl != m_decl)
field->setMemberInherited();
m_fields.push_back(field);
continue; continue;
} }
} }
...@@ -268,7 +272,10 @@ void TypeInfoClangStruct::getRecursiveFields( clang::RecordDecl* recordDecl, MEM ...@@ -268,7 +272,10 @@ void TypeInfoClangStruct::getRecursiveFields( clang::RecordDecl* recordDecl, MEM
clang::VarDecl *varDecl = llvm::dyn_cast<clang::VarDecl>(*declit); clang::VarDecl *varDecl = llvm::dyn_cast<clang::VarDecl>(*declit);
if ( varDecl ) if ( varDecl )
{ {
m_fields.push_back( TypeFieldClangField::getStaticField(m_astSession, recordDecl, varDecl) ); auto field = TypeFieldClangField::getStaticField(m_astSession, recordDecl, varDecl);
if (recordDecl != m_decl)
field->setMemberInherited();
m_fields.push_back(field);
continue; continue;
} }
......
...@@ -183,6 +183,14 @@ protected: ...@@ -183,6 +183,14 @@ protected:
NOT_IMPLEMENTED(); NOT_IMPLEMENTED();
} }
virtual bool isInheritedMember(const std::wstring &name) {
NOT_IMPLEMENTED();
}
virtual bool isInheritedMember(size_t index) {
NOT_IMPLEMENTED();
}
virtual bool isVirtual() { virtual bool isVirtual() {
NOT_IMPLEMENTED(); NOT_IMPLEMENTED();
} }
......
...@@ -1159,6 +1159,32 @@ bool TypeInfoFields::isConstMember(size_t index) ...@@ -1159,6 +1159,32 @@ bool TypeInfoFields::isConstMember(size_t index)
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
bool TypeInfoFields::isInheritedMember(const std::wstring &name)
{
checkFields();
size_t pos = name.find_first_of(L'.');
TypeFieldPtr fieldPtr = m_fields.lookup(std::wstring(name, 0, pos));
if (pos == std::wstring::npos)
return fieldPtr->isInheritedMember();
TypeInfoPtr fieldType = fieldPtr->getTypeInfo();
return fieldType->isInheritedMember(std::wstring(name, pos + 1));
}
///////////////////////////////////////////////////////////////////////////////
bool TypeInfoFields::isInheritedMember(size_t index)
{
checkFields();
return m_fields.lookup(index)->isInheritedMember();
}
///////////////////////////////////////////////////////////////////////////////
size_t TypeInfoFields::getAlignReq() size_t TypeInfoFields::getAlignReq()
{ {
size_t alignReq = 1; size_t alignReq = 1;
...@@ -1523,6 +1549,9 @@ void TypeInfoUdt::getFields( ...@@ -1523,6 +1549,9 @@ void TypeInfoUdt::getFields(
throw TypeException(m_name, L"Unsupported field type"); throw TypeException(m_name, L"Unsupported field type");
} }
if (rootSym != m_symbol)
fieldPtr->setMemberInherited();
m_fields.push_back( fieldPtr ); m_fields.push_back( fieldPtr );
} }
else else
......
...@@ -235,6 +235,16 @@ protected: ...@@ -235,6 +235,16 @@ protected:
throw TypeException(getName(), L"type is not a struct"); throw TypeException(getName(), L"type is not a struct");
} }
bool isInheritedMember(const std::wstring &name) override
{
throw TypeException(getName(), L"type is not a struct");
}
bool isInheritedMember(size_t index) override
{
throw TypeException(getName(), L"type is not a struct");
}
TypeInfoPtr getMethod( const std::wstring &name, const std::wstring& prototype) override TypeInfoPtr getMethod( const std::wstring &name, const std::wstring& prototype) override
{ {
throw TypeException( getName(), L"type has no methods" ); throw TypeException( getName(), L"type has no methods" );
...@@ -426,6 +436,8 @@ protected: ...@@ -426,6 +436,8 @@ protected:
bool isVirtualMember( size_t index ) override; bool isVirtualMember( size_t index ) override;
bool isConstMember(const std::wstring &name) override; bool isConstMember(const std::wstring &name) override;
bool isConstMember(size_t index) override; bool isConstMember(size_t index) override;
bool isInheritedMember(const std::wstring &name) override;
bool isInheritedMember(size_t index) override;
virtual size_t getAlignReq(); virtual size_t getAlignReq();
......
...@@ -83,6 +83,16 @@ public: ...@@ -83,6 +83,16 @@ public:
return m_constMember; return m_constMember;
} }
bool isInheritedMember() const
{
return m_inheritedMember;
}
void setMemberInherited()
{
m_inheritedMember = true;
}
MEMOFFSET_64 getStaticOffset() const MEMOFFSET_64 getStaticOffset() const
{ {
if ( m_staticMember ) if ( m_staticMember )
...@@ -119,7 +129,8 @@ protected: ...@@ -119,7 +129,8 @@ protected:
m_staticMember( false ), m_staticMember( false ),
m_virtualMember( false ), m_virtualMember( false ),
m_methodMember(false), m_methodMember(false),
m_constMember(false) m_constMember(false),
m_inheritedMember(false)
{} {}
std::wstring m_name; std::wstring m_name;
...@@ -138,6 +149,7 @@ protected: ...@@ -138,6 +149,7 @@ protected:
bool m_virtualMember; bool m_virtualMember;
bool m_methodMember; bool m_methodMember;
bool m_constMember; bool m_constMember;
bool m_inheritedMember;
}; };
/////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////
......
...@@ -574,4 +574,23 @@ TEST_F(ClangTest, PtrToIncompleteStruct) ...@@ -574,4 +574,23 @@ TEST_F(ClangTest, PtrToIncompleteStruct)
EXPECT_NO_THROW(testStruct->getElement(L"t")->deref()); EXPECT_NO_THROW(testStruct->getElement(L"t")->deref());
EXPECT_TRUE(testStruct->getElement(L"t")->deref()->isIncomplete()); EXPECT_TRUE(testStruct->getElement(L"t")->deref()->isIncomplete());
EXPECT_THROW(testStruct->getElement(L"t")->deref()->getSize(), TypeException); EXPECT_THROW(testStruct->getElement(L"t")->deref()->getSize(), TypeException);
} }
\ No newline at end of file
TEST_F(ClangTest, isInheritedMember)
{
static const wchar_t srcCode[] = L" \
struct Base { \
int mbase; \
}; \
struct Test : Base { \
int mchild; \
}; \
";
TypeInfoPtr testStruct;
ASSERT_NO_THROW(testStruct = compileType(srcCode, L"Test"));
EXPECT_TRUE(testStruct->isInheritedMember(L"mbase"));
EXPECT_FALSE(testStruct->isInheritedMember(L"mchild"));
EXPECT_TRUE(testStruct->isInheritedMember(0));
EXPECT_FALSE(testStruct->isInheritedMember(1));
}
\ No newline at end of file
...@@ -687,3 +687,15 @@ TEST_F(TypeInfoTest, ArrayOfIncomplete) ...@@ -687,3 +687,15 @@ TEST_F(TypeInfoTest, ArrayOfIncomplete)
EXPECT_THROW(typeInfo->arrayOf(1), TypeException); EXPECT_THROW(typeInfo->arrayOf(1), TypeException);
EXPECT_THROW(typeInfo->arrayOf(), TypeException); EXPECT_THROW(typeInfo->arrayOf(), TypeException);
} }
TEST_F(TypeInfoTest, isInheritedMember)
{
TypeInfoPtr typeInfo;
ASSERT_NO_THROW(typeInfo = loadType(L"classChild"));
EXPECT_TRUE(typeInfo->isInheritedMember(L"m_count"));
EXPECT_TRUE(typeInfo->isInheritedMember(L"m_stdstr"));
EXPECT_FALSE(typeInfo->isInheritedMember(L"m_childField"));
EXPECT_FALSE(typeInfo->isInheritedMember(typeInfo->getElementIndex(L"m_staticConst")));
EXPECT_TRUE(typeInfo->isInheritedMember(typeInfo->getElementIndex(L"m_baseField")));
EXPECT_THROW(loadType(L"Int8B[]")->isInheritedMember(0), TypeException);
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment