Commit 739aa68c authored by ussrhero's avatar ussrhero
Browse files

supported constant value for struct

parent 0710b0e1
......@@ -88,6 +88,9 @@ public:
virtual bool isVirtualMember( const std::wstring &name ) = 0;
virtual bool isVirtualMember( size_t index ) = 0;
virtual bool isConstMember(const std::wstring &name) = 0;
virtual bool isConstMember(size_t index) = 0;
virtual bool isVirtual() = 0;
virtual TypeInfoPtr getMethod( const std::wstring &name, const std::wstring& prototype = L"") = 0;
......
......@@ -268,6 +268,17 @@ void TypeInfoClangStruct::getRecursiveFields( clang::RecordDecl* recordDecl, MEM
m_fields.push_back( TypeFieldClangField::getStaticField(m_astSession, recordDecl, varDecl) );
continue;
}
clang::EnumDecl * enumDecl = llvm::dyn_cast<clang::EnumDecl>(*declit);
if ( enumDecl )
{
for (clang::EnumDecl::enumerator_iterator enumIt = enumDecl->enumerator_begin(); enumIt != enumDecl->enumerator_end(); ++enumIt)
{
std::string fieldName = enumIt->getNameAsString();
m_fields.push_back(TypeFieldClangEnumField::getField(m_astSession, *enumIt));
}
}
}
}
......@@ -470,6 +481,7 @@ TypeFieldPtr TypeFieldClangEnumField::getField(ClangASTSessionPtr& astSession, c
field->m_decl = EnumDecl;
field->m_astSession = astSession;
field->m_constMember = true;
return TypeFieldPtr(field);
}
......@@ -757,44 +769,44 @@ TypeInfoPtr compileType( const std::wstring& sourceCode, const std::wstring& typ
///////////////////////////////////////////////////////////////////////////////
class ASTBuilderAction : public clang::tooling::ToolAction
{
std::vector<std::unique_ptr<ASTUnit>> &ASTs;
public:
ASTBuilderAction(std::vector<std::unique_ptr<ASTUnit>> &ASTs) : ASTs(ASTs) {}
bool runInvocation(std::shared_ptr<CompilerInvocation> Invocation,
FileManager *Files,
std::shared_ptr<PCHContainerOperations> PCHContainerOps,
DiagnosticConsumer *DiagConsumer) override {
std::unique_ptr<ASTUnit> AST = ASTUnit::LoadFromCompilerInvocation(
Invocation, std::move(PCHContainerOps),
CompilerInstance::createDiagnostics(&Invocation->getDiagnosticOpts(),
DiagConsumer,
/*ShouldOwnClient=*/false),
Files);
if (!AST)
return false;
ASTs.push_back(std::move(AST));
return true;
}
class ASTBuilderAction : public clang::tooling::ToolAction
{
std::vector<std::unique_ptr<ASTUnit>> &ASTs;
public:
ASTBuilderAction(std::vector<std::unique_ptr<ASTUnit>> &ASTs) : ASTs(ASTs) {}
bool runInvocation(std::shared_ptr<CompilerInvocation> Invocation,
FileManager *Files,
std::shared_ptr<PCHContainerOperations> PCHContainerOps,
DiagnosticConsumer *DiagConsumer) override {
std::unique_ptr<ASTUnit> AST = ASTUnit::LoadFromCompilerInvocation(
Invocation, std::move(PCHContainerOps),
CompilerInstance::createDiagnostics(&Invocation->getDiagnosticOpts(),
DiagConsumer,
/*ShouldOwnClient=*/false),
Files);
if (!AST)
return false;
ASTs.push_back(std::move(AST));
return true;
}
};
TypeInfoProviderClang::TypeInfoProviderClang( const std::string& sourceCode, const std::string& compileOptions)
{
std::vector<std::unique_ptr<ASTUnit>> ASTs;
ASTBuilderAction Action(ASTs);
llvm::IntrusiveRefCntPtr<vfs::OverlayFileSystem> OverlayFileSystem(
new vfs::OverlayFileSystem(vfs::getRealFileSystem()));
llvm::IntrusiveRefCntPtr<vfs::InMemoryFileSystem> InMemoryFileSystem(
new vfs::InMemoryFileSystem);
OverlayFileSystem->pushOverlay(InMemoryFileSystem);
llvm::IntrusiveRefCntPtr<FileManager> Files(
new FileManager(FileSystemOptions(), OverlayFileSystem));
std::vector<std::unique_ptr<ASTUnit>> ASTs;
ASTBuilderAction Action(ASTs);
llvm::IntrusiveRefCntPtr<vfs::OverlayFileSystem> OverlayFileSystem(
new vfs::OverlayFileSystem(vfs::getRealFileSystem()));
llvm::IntrusiveRefCntPtr<vfs::InMemoryFileSystem> InMemoryFileSystem(
new vfs::InMemoryFileSystem);
OverlayFileSystem->pushOverlay(InMemoryFileSystem);
llvm::IntrusiveRefCntPtr<FileManager> Files(
new FileManager(FileSystemOptions(), OverlayFileSystem));
std::vector< std::string > args;
args.push_back("clang-tool");
......@@ -805,27 +817,27 @@ TypeInfoProviderClang::TypeInfoProviderClang( const std::string& sourceCode, con
Tokenizer tok(compileOptions, Separator);
std::copy(tok.begin(), tok.end(), std::inserter(args, args.end()));
args.push_back("input.cc");
ToolInvocation toolInvocation(
args,
&Action,
Files.get(),
std::move(std::make_shared< PCHContainerOperations >())
);
InMemoryFileSystem->addFile("input.cc", 0, llvm::MemoryBuffer::getMemBuffer(sourceCode.c_str()));
#ifndef _DEBUG
IgnoringDiagConsumer diagnosticConsumer;
toolInvocation.setDiagnosticConsumer(&diagnosticConsumer);
#endif
std::copy(tok.begin(), tok.end(), std::inserter(args, args.end()));
args.push_back("input.cc");
ToolInvocation toolInvocation(
args,
&Action,
Files.get(),
std::move(std::make_shared< PCHContainerOperations >())
);
InMemoryFileSystem->addFile("input.cc", 0, llvm::MemoryBuffer::getMemBuffer(sourceCode.c_str()));
#ifndef _DEBUG
IgnoringDiagConsumer diagnosticConsumer;
toolInvocation.setDiagnosticConsumer(&diagnosticConsumer);
#endif
toolInvocation.run();
std::unique_ptr<ASTUnit> ast = std::move(ASTs[0]);
......
......@@ -263,7 +263,6 @@ public:
};
class TypeFieldClangEnumField : public TypeField
{
public:
......
......@@ -167,6 +167,14 @@ protected:
NOT_IMPLEMENTED();
}
virtual bool isConstMember(const std::wstring &name) {
NOT_IMPLEMENTED();
}
virtual bool isConstMember(size_t index) {
NOT_IMPLEMENTED();
}
virtual bool isVirtual() {
NOT_IMPLEMENTED();
}
......
......@@ -145,6 +145,11 @@ std::wstring printStructType(TypeInfoPtr& structType)
for ( size_t i = 0; i < fieldCount; ++i )
{
if (structType->isConstMember(i) )
{
continue;
}
else
if ( structType->isStaticMember(i) )
{
sstr << L" =" << std::right << std::setw(10) << std::setfill(L'0') << std::hex << structType->getElementVa(i);
......@@ -1084,6 +1089,32 @@ bool TypeInfoFields::isVirtualMember( size_t index )
return m_fields.lookup( index )->isVirtualMember();
}
///////////////////////////////////////////////////////////////////////////////
bool TypeInfoFields::isConstMember(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->isConstMember();
TypeInfoPtr fieldType = fieldPtr->getTypeInfo();
return fieldType->isConstMember(std::wstring(name, pos + 1));
}
///////////////////////////////////////////////////////////////////////////////
bool TypeInfoFields::isConstMember(size_t index)
{
checkFields();
return m_fields.lookup(index)->isConstMember();
}
///////////////////////////////////////////////////////////////////////////////
......@@ -1126,7 +1157,10 @@ void TypeInfoUdt::getVirtualDisplacement( size_t fieldIndex, MEMOFFSET_32 &virtu
std::wstring TypeInfoUdt::str()
{
return std::wstring(L"class/struct : ") + TypeInfoFields::print();
TypeInfoPtr selfPtr = shared_from_this();
return printStructType(selfPtr);
//return std::wstring(L"class/struct : ") + TypeInfoFields::print();
}
///////////////////////////////////////////////////////////////////////////////
......
......@@ -34,256 +34,326 @@ class TypeInfoImp : public TypeInfo, public boost::enable_shared_from_this<TypeI
{
protected:
virtual std::wstring str() {
std::wstring str() override
{
NOT_IMPLEMENTED();
}
virtual std::wstring getName() {
std::wstring getName() override
{
NOT_IMPLEMENTED();
}
virtual std::wstring getScopeName() {
std::wstring getScopeName() override
{
throw TypeException( getName(), L"type has no scope name" );
}
virtual std::pair<std::wstring, std::wstring> splitName() {
std::pair<std::wstring, std::wstring> splitName() override
{
return std::pair<std::wstring, std::wstring>(getName(), std::wstring());
}
virtual size_t getSize() {
size_t getSize() override
{
NOT_IMPLEMENTED();
}
virtual size_t getPtrSize() {
size_t getPtrSize()override
{
return ptrSize();
}
virtual TypeInfoPtr ptrTo( size_t ptrSize = 0 );
TypeInfoPtr ptrTo( size_t ptrSize = 0 ) override;
virtual TypeInfoPtr deref() {
TypeInfoPtr deref() override
{
throw TypeException( getName(), L"type can not be dereffered" );
}
virtual TypeInfoPtr arrayOf( size_t size );
TypeInfoPtr arrayOf( size_t size ) override;
virtual bool isArray() {
bool isArray() override
{
return false;
}
virtual bool isPointer() {
bool isPointer() override
{
return false;
}
virtual bool isVoid() {
bool isVoid() override
{
return false;
}
virtual bool isBase() {
bool isBase() override
{
return false;
}
virtual bool isUserDefined() {
bool isUserDefined() override
{
return false;
}
virtual bool isEnum() {
bool isEnum() override
{
return false;
}
virtual bool isBitField() {
bool isBitField() override
{
return false;
}
virtual bool isFunction() {
bool isFunction() override
{
return false;
}
virtual bool isVtbl() {
bool isVtbl() override
{
return false;
}
virtual bool isNoType() {
bool isNoType() override
{
return false;
}
virtual bool isConstant() {
bool isConstant() override
{
return m_constant;
}
virtual bool isVirtual() {
bool isVirtual() override
{
throw TypeException( getName(), L"type is not class method" );
}
virtual TypeInfoPtr getElement( const std::wstring &name ) {
TypeInfoPtr getElement( const std::wstring &name ) override
{
throw TypeException( getName(), L" type has no fields or array elements");
}
virtual TypeInfoPtr getElement( size_t index ) {
TypeInfoPtr getElement( size_t index ) override
{
throw TypeException( getName(), L" type has no fields or array elements");
}
virtual MEMOFFSET_REL getElementOffset( const std::wstring &name ) {
MEMOFFSET_REL getElementOffset( const std::wstring &name ) override
{
throw TypeException( getName(), L" type has no fields or array elements");
}
virtual MEMOFFSET_REL getElementOffset( size_t index ) {
MEMOFFSET_REL getElementOffset( size_t index ) override
{
throw TypeException( getName(), L" type has no fields or array elements");
}
virtual size_t getElementCount() {
size_t getElementCount() override
{
throw TypeException( getName(), L" type has no fields or array elements");
}
virtual std::wstring getElementName( size_t index ) {
std::wstring getElementName( size_t index ) override
{
NOT_IMPLEMENTED();
}
virtual size_t getElementIndex( const std::wstring &name ) {
size_t getElementIndex( const std::wstring &name ) override
{
NOT_IMPLEMENTED();
}
virtual BITOFFSET getBitOffset() {
BITOFFSET getBitOffset() override
{
throw TypeException( getName(), L" type is not a bit field");
}
virtual BITOFFSET getBitWidth() {
BITOFFSET getBitWidth() override
{
throw TypeException( getName(), L" type is not a bit field");
}
virtual TypeInfoPtr getBitType() {
TypeInfoPtr getBitType() override
{
throw TypeException( getName(), L" type is not a bit field");
}
virtual MEMOFFSET_64 getElementVa( const std::wstring &name ) {
MEMOFFSET_64 getElementVa( const std::wstring &name ) override
{
throw TypeException( getName(), L"type is not a struct" );
}
virtual MEMOFFSET_64 getElementVa( size_t index ) {
MEMOFFSET_64 getElementVa( size_t index )override
{
throw TypeException( getName(), L"type is not a struct" );
}
virtual bool isStaticMember( const std::wstring &name ) {
bool isStaticMember( const std::wstring &name ) override
{
throw TypeException( getName(), L"type is not a struct" );
}
virtual bool isStaticMember( size_t index ) {
bool isStaticMember( size_t index ) override
{
throw TypeException( getName(), L"type is not a struct" );
}
virtual bool isVirtualMember( const std::wstring &name ) {
bool isVirtualMember( const std::wstring &name ) override
{
throw TypeException( getName(), L"type is not a struct" );
}
virtual bool isVirtualMember( size_t index ) {
bool isVirtualMember( size_t index ) override
{
throw TypeException( getName(), L"type is not a struct" );
}
virtual TypeInfoPtr getMethod( const std::wstring &name, const std::wstring& prototype) {
bool isConstMember(const std::wstring &name) override
{
throw TypeException(getName(), L"type is not a struct");
}
bool isConstMember(size_t index) override
{
throw TypeException(getName(), L"type is not a struct");
}
TypeInfoPtr getMethod( const std::wstring &name, const std::wstring& prototype) override
{
throw TypeException( getName(), L"type has no methods" );
}
virtual TypeInfoPtr getMethod( const std::wstring &name, TypeInfoPtr prototype) {
TypeInfoPtr getMethod( const std::wstring &name, TypeInfoPtr prototype) override
{
throw TypeException( getName(), L"type has no methods" );
}
virtual TypeInfoPtr getMethod( size_t index ) {
TypeInfoPtr getMethod( size_t index ) override
{
throw TypeException( getName(), L"type has no methods" );
}
virtual std::wstring getMethodName(size_t index) {
std::wstring getMethodName(size_t index) override
{
throw TypeException(getName(), L"type has no methods");
}
virtual size_t getMethodsCount() {
size_t getMethodsCount() override
{
throw TypeException( getName(), L"type has no methods" );
}
virtual TypeInfoPtr getBaseClass( const std::wstring& className) {
TypeInfoPtr getBaseClass( const std::wstring& className) override
{
throw TypeException( getName(), L"type has no base class" );
}
virtual TypeInfoPtr getBaseClass( size_t index ) {
TypeInfoPtr getBaseClass( size_t index ) override
{
throw TypeException( getName(), L"type has no base class" );
}
virtual size_t getBaseClassesCount() {
size_t getBaseClassesCount() override
{
throw TypeException( getName(), L"type has no base class" );
}
virtual MEMOFFSET_REL getBaseClassOffset( const std::wstring &name ) {
MEMOFFSET_REL getBaseClassOffset( const std::wstring &name ) override
{
throw TypeException( getName(), L"type has no base class" );
}
virtual MEMOFFSET_REL getBaseClassOffset( size_t index ) {
MEMOFFSET_REL getBaseClassOffset( size_t index ) override
{
throw TypeException( getName(), L"type has no base class" );
}
virtual bool isBaseClassVirtual( const std::wstring &name ) {
bool isBaseClassVirtual( const std::wstring &name ) override
{
throw TypeException( getName(), L"type has no base class" );
}
virtual bool isBaseClassVirtual( size_t index ) {
bool isBaseClassVirtual( size_t index ) override
{
throw TypeException( getName(), L"type has no base class" );
}
virtual void getBaseClassVirtualDisplacement( const std::wstring &name, MEMOFFSET_32 &virtualBasePtr, size_t &virtualDispIndex, size_t &virtualDispSize ) {
void getBaseClassVirtualDisplacement( const std::wstring &name, MEMOFFSET_32 &virtualBasePtr, size_t &virtualDispIndex, size_t &virtualDispSize ) override
{
throw TypeException( getName(), L"type is not virtual inherited" );
}
virtual void getBaseClassVirtualDisplacement( size_t index, MEMOFFSET_32 &virtualBasePtr, size_t &virtualDispIndex, size_t &virtualDispSize ) {
void getBaseClassVirtualDisplacement( size_t index, MEMOFFSET_32 &virtualBasePtr, size_t &virtualDispIndex, size_t &virtualDispSize ) override
{
throw TypeException( getName(), L"type is not virtual inherited" );
}
virtual bool isMethodMember( const std::wstring &name ) {
throw TypeException( getName(), L"type is not a struct" );
}
//bool isMethodMember( const std::wstring &name ) override
//{
// throw TypeException( getName(), L"type is not a struct" );
//}
virtual bool isMethodMember( size_t index ) {
throw TypeException( getName(), L"type is not a struct" );
}
//bool isMethodMember( size_t index ) override
//{
// throw TypeException( getName(), L"type is not a struct" );
//}
virtual void getVirtualDisplacement( const std::wstring& fieldName, MEMOFFSET_32 &virtualBasePtr, size_t &virtualDispIndex, size_t &virtualDispSize ) {
void getVirtualDisplacement( const std::wstring& fieldName, MEMOFFSET_32 &virtualBasePtr, size_t &virtualDispIndex, size_t &virtualDispSize ) override
{
throw TypeException( getName(), L"type is not a struct" );
}
virtual void getVirtualDisplacement( size_t fieldIndex, MEMOFFSET_32 &virtualBasePtr, size_t &virtualDispIndex, size_t &virtualDispSize ) {
void getVirtualDisplacement( size_t fieldIndex, MEMOFFSET_32 &virtualBasePtr, size_t &virtualDispIndex, size_t &virtualDispSize ) override
{
throw TypeException( getName(), L"type is not a struct" );
}
virtual CallingConventionType getCallingConvention() {
CallingConventionType getCallingConvention() override
{
throw TypeException( getName(), L"type is not a function" );
}
virtual bool hasThis() {
bool hasThis() override
{
throw TypeException( getName(), L"type is not a function" );
}
virtual TypeInfoPtr getReturnType() {
TypeInfoPtr getReturnType() override
{
throw TypeException( getName(), L"type is not a function" );
}
virtual void appendField(const std::wstring &fieldName, const TypeInfoPtr &fieldType ) {
void appendField(const std::wstring &fieldName, const TypeInfoPtr &fieldType ) override
{
throw TypeException( getName(), L"type is not editable" );
}
virtual TypeInfoPtr getClassParent() {
TypeInfoPtr getClassParent() override
{
throw TypeException( getName(), L"has no class parent" );
}