Commit d2f918fd authored by ussrhero's avatar ussrhero

reworked getTemplateArg method

parent 92e9d98b
......@@ -2,6 +2,7 @@
#include <string>
#include <list>
#include <map>
#pragma pack( push, 4 )
......@@ -448,6 +449,7 @@ extern TemplateStruct<TemplateStruct<int>[4]> g_template4;
////////////////////////////////////////////////////////////////////////////////
extern std::list<int> g_stdIntList;
extern std::map<int, TemplateStruct<int> > g_stdMap;
template<typename T>
struct TestStructTemplate
......
......@@ -205,93 +205,6 @@ TypeInfoPtr evalType(const std::string& expr, const TypeInfoProviderPtr typeInfo
///////////////////////////////////////////////////////////////////////////////
std::list<std::string> getTempalteArgs(const std::string& expr)
{
auto preprocessorOptions = std::make_shared<clang::PreprocessorOptions>();
llvm::IntrusiveRefCntPtr<clang::DiagnosticIDs> diagnosticIDs(new clang::DiagnosticIDs());
auto diagnosticOptions = new clang::DiagnosticOptions();
auto diagnosticConsumer = new clang::IgnoringDiagConsumer();
clang::DiagnosticsEngine diagnosticEngine(diagnosticIDs, diagnosticOptions, diagnosticConsumer);
clang::LangOptions langOptions;
llvm::IntrusiveRefCntPtr<clang::vfs::InMemoryFileSystem> memoryFileSystem(new clang::vfs::InMemoryFileSystem());
memoryFileSystem->addFile("<input>", 0, llvm::MemoryBuffer::getMemBuffer(expr.c_str()));
clang::FileSystemOptions fileSystemOptions;
clang::FileManager fileManager(fileSystemOptions, memoryFileSystem);
clang::SourceManager sourceManager(diagnosticEngine, fileManager);
const clang::FileEntry *pFile = fileManager.getFile("<input>");
clang::FileID fileID = sourceManager.getOrCreateFileID(pFile, clang::SrcMgr::C_User);
sourceManager.setMainFileID(fileID);
clang::MemoryBufferCache memoryBufferCache;
auto headerSearchOptions = std::make_shared<clang::HeaderSearchOptions>();
auto targetOptions = std::make_shared<clang::TargetOptions>();
targetOptions->Triple = llvm::sys::getDefaultTargetTriple();
clang::TargetInfo* targetInfo = clang::TargetInfo::CreateTargetInfo(diagnosticEngine, targetOptions);
clang::HeaderSearch headerSearch(headerSearchOptions, sourceManager, diagnosticEngine, langOptions, targetInfo);
clang::CompilerInstance compilerInstance;
clang::Preprocessor preprocessor(
preprocessorOptions,
diagnosticEngine,
langOptions,
sourceManager,
memoryBufferCache,
headerSearch,
compilerInstance
);
preprocessor.Initialize(*targetInfo);
preprocessor.EnterMainSourceFile();
diagnosticConsumer->BeginSourceFile(langOptions, &preprocessor);
clang::Token token;
std::list<clang::Token> tokens;
do {
preprocessor.Lex(token);
if (diagnosticEngine.hasErrorOccurred())
{
NOT_IMPLEMENTED();
}
tokens.push_back(token);
} while (!token.is(clang::tok::eof));
diagnosticConsumer->EndSourceFile();
TypeEval exprEval(getDefaultScope(), getDefaultTypeInfoProvider(), &tokens);
return exprEval.getTemplateArgList();
}
///////////////////////////////////////////////////////////////////////////////
std::list<std::wstring> getTempalteArgs(const std::wstring& typeName)
{
const std::list<std::string>& argList = getTempalteArgs(wstrToStr(typeName));
std::list<std::wstring> wargLst;
std::for_each(argList.begin(), argList.end(), [&wargLst](const auto& arg) {
wargLst.push_back(strToWStr(arg));
});
return wargLst;
}
///////////////////////////////////////////////////////////////////////////////
ExprEval::ExprEval(const ScopePtr& scope,
const TypeInfoProviderPtr& typeInfoProvider,
std::list<clang::Token>* tokens,
......
This diff is collapsed.
......@@ -28,9 +28,6 @@ std::wstring printStructType(TypeInfoPtr& structType);
std::wstring printPointerType(TypeInfoPtr& ptrType);
std::wstring printEnumType(TypeInfoPtr& enumType);
std::list<std::wstring> getTempalteArgs(const std::wstring& typeName);
std::list<std::string> getTempalteArgs(const std::string& typeName);
///////////////////////////////////////////////////////////////////////////////
class TypeInfoImp : public TypeInfo, public boost::enable_shared_from_this<TypeInfoImp>
......@@ -399,6 +396,8 @@ protected:
return m_constantValue;
}
std::list<std::wstring> getTempalteArgs();
};
......
......@@ -222,4 +222,6 @@ TestStructTemplate<int> g_testStructTemplate;
TestClassTemplate<int> g_testClassTemplate;
TestTemplateTwoTypes<int,TestClassTemplate<int>> g_testTemplateTwoTypes;
TestTemplateTwoValues<2,10> g_testTemplateTwoValues;
ClassNoField<UnusedStruct> g_templateUnusedStruct;
\ No newline at end of file
ClassNoField<UnusedStruct> g_templateUnusedStruct;
std::map<int, TemplateStruct<int> > g_stdMap;
\ No newline at end of file
......@@ -5,24 +5,27 @@
using namespace kdlib;
class NetTest : public NetProcessFixture
typedef ::testing::Types<NetProcessFixture, NetDumpFixture> NetTargetTypes;
template <typename T>
class NetTest : public T
{
};
TYPED_TEST_CASE(NetTest, NetTargetTypes);
TEST_F(NetTest, ProcessIsManaged)
TYPED_TEST(NetTest, ProcessIsManaged)
{
EXPECT_TRUE(TargetProcess::getCurrent()->isManaged());
}
TEST_F(NetTest, NetModuleIsManaged)
TYPED_TEST(NetTest, NetModuleIsManaged)
{
EXPECT_TRUE(m_targetModule->isManaged());
EXPECT_FALSE( loadModule(L"ntdll")->isManaged());
}
TEST_F(NetTest, NetHeap)
TYPED_TEST(NetTest, NetHeap)
{
kdlib::TargetHeapPtr targetHeap;
ASSERT_NO_THROW(targetHeap = TargetProcess::getCurrent()->getManagedHeap());
......@@ -38,20 +41,18 @@ TEST_F(NetTest, NetHeap)
EXPECT_TRUE( heapEnum->next(address, typeName, size) );
}
//TEST_F(NetTest, NetModuleEnumTypes)
//{
// EXPECT_EQ(
// TypeNameList( { L"managedapp.Class1",
// L"managedapp.Class1.Nested",
// L"managedapp.Program" } ),
// m_targetModule->enumTypes() );
//
// EXPECT_EQ(
// TypeNameList( { L"managedapp.Class1",
// L"managedapp.Class1.Nested" } ),
// m_targetModule->enumTypes(L"*Class1*") );
//
//}
TYPED_TEST(NetTest, NetModuleEnumTypes)
{
auto types = m_targetModule->enumTypes();
EXPECT_NE(types.end(), std::find(types.begin(), types.end(), L"managedapp.Class1.Nested"));
EXPECT_EQ(types.end(), std::find(types.begin(), types.end(), L"managedapp.Notexist"));
}
TYPED_TEST(NetTest, DISABLED_GetType)
{
EXPECT_EQ(L"managedapp.Class1", m_targetModule->getTypeByName(L"managedapp.Class1")->getName());
}
//
//TEST_F(NetTest, ClassField)
//{
......
......@@ -719,7 +719,7 @@ TEST_F(TypedVarTest, GetSource)
ASSERT_NO_THROW(funcptr = loadTypedVar(L"classChild::childMethod"));
funcptr->getSourceLine(funcptr->getAddress(), fileName, lineNo);
EXPECT_EQ(286, lineNo);
EXPECT_EQ(287, lineNo);
}
TEST_F(TypedVarTest, StructNestedEnum)
......
......@@ -669,6 +669,17 @@ TEST_F(TypeInfoTest, TemplateArgStdPair)
EXPECT_EQ(3, loadType(L"g_stdIntList")->getElement(L"_Mypair")->getTemplateArgsCount());
}
TEST_F(TypeInfoTest, TemplateArgStdMap)
{
kdlib::TypeInfoPtr stdMap = loadType(L"g_stdMap");
EXPECT_EQ(4, stdMap->getTemplateArgsCount());
EXPECT_EQ(3, stdMap->getElement(L"_Mypair")->getTemplateArgsCount());
EXPECT_EQ(3, stdMap->getElement(L"_Mypair")->getElement(L"_Myval2")->getTemplateArgsCount());
EXPECT_EQ(L"std::allocator<std::_Tree_node<std::pair<int const ,TemplateStruct<int> >,void *> >", stdMap->getElement(L"_Mypair")->getElement(L"_Myval2")->getTemplateArg(0));
EXPECT_EQ(L"1", stdMap->getElement(L"_Mypair")->getElement(L"_Myval2")->getTemplateArg(2));
}
TEST_F(TypeInfoTest, DISABLED_IncomleteStruct)
{
TypeInfoPtr typeInfo;
......
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