Commit 739aa68c authored by ussrhero's avatar ussrhero

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();
}
///////////////////////////////////////////////////////////////////////////////
......
This diff is collapsed.
......@@ -527,6 +527,9 @@ TEST_F(ClangTest, NestedEnum)
enum { \
VAL = 1 \
}; \
enum NestedEnum { \
VAL1 = 2 \
}; \
}; \
";
......@@ -534,4 +537,5 @@ TEST_F(ClangTest, NestedEnum)
ASSERT_NO_THROW(testStruct = compileType(srcCode, L"Test"));
EXPECT_EQ(1, *testStruct->getElement(L"VAL"));
EXPECT_EQ(2, *testStruct->getElement(L"VAL1"));
}
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