Commits (1)
......@@ -193,7 +193,7 @@ class SymbolProvider;
typedef boost::shared_ptr<SymbolProvider> SymbolProviderPtr;
class SymbolEnumerator;
typedef boost::shared_ptr< SymbolEnumerator> SymbolEnumeratorPtr;
typedef boost::shared_ptr<SymbolEnumerator> SymbolEnumeratorPtr;
class SymbolProvider {
public:
......@@ -202,7 +202,10 @@ public:
class SymbolEnumerator {
public:
virtual std::wstring Next() = 0;
virtual bool Next() = 0;
virtual std::wstring getName() = 0;
virtual MEMOFFSET_64 getOffset() = 0;
virtual TypeInfoPtr getType() = 0;
};
TypeInfoProviderPtr getTypeInfoProviderFromSource( const std::wstring& source, const std::wstring& opts = L"" );
......
......@@ -719,7 +719,7 @@ class FuncVisitor : public RecursiveASTVisitor<FuncVisitor>
public:
FuncVisitor(ClangASTSessionPtr& astSession, std::vector<std::string>& symbols) :
FuncVisitor(ClangASTSessionPtr& astSession, SymbolList& symbols) :
m_session(astSession),
m_symbols(symbols)
{}
......@@ -735,7 +735,7 @@ public:
if ( Declaration->getTemplatedKind() == FunctionDecl::TemplatedKind::TK_FunctionTemplate )
return true;
m_symbols.push_back(getFunctionNameFromDecl(Declaration));
m_symbols.push_back(std::make_pair(getFunctionNameFromDecl(Declaration), Declaration));
} catch(TypeException& )
{}
......@@ -747,7 +747,7 @@ private:
ClangASTSessionPtr m_session;
std::vector<std::string> &m_symbols;
SymbolList &m_symbols;
};
///////////////////////////////////////////////////////////////////////////////
......@@ -954,36 +954,56 @@ SymbolProviderClang::SymbolProviderClang(const std::string& sourceCode, const s
std::unique_ptr<ASTUnit> ast = std::move(ASTs[0]);
auto astSession = ClangASTSession::getASTSession(ast);
m_astSession = ClangASTSession::getASTSession(ast);
FuncVisitor visitor(astSession, m_symbols);
FuncVisitor visitor(m_astSession, m_symbols);
visitor.TraverseDecl(astSession->getASTContext().getTranslationUnitDecl());
visitor.TraverseDecl(m_astSession->getASTContext().getTranslationUnitDecl());
}
///////////////////////////////////////////////////////////////////////////////
SymbolEnumeratorPtr SymbolProviderClang::getSymbolEnumerator(const std::wstring& mask)
{
return SymbolEnumeratorPtr(new SymbolEnumeratorClang(mask, shared_from_this()));
return SymbolEnumeratorPtr(new SymbolEnumeratorClang(wstrToStr(mask), shared_from_this()));
}
///////////////////////////////////////////////////////////////////////////////
std::wstring SymbolEnumeratorClang::Next()
bool SymbolEnumeratorClang::Next()
{
const auto& symbols = m_symbolProvider->m_symbols;
while (m_index < symbols.size())
while (m_index + 1 < symbols.size() )
{
const auto& sym = symbols[m_index++];
if (m_mask.empty() || fnmatch(m_mask, sym))
return strToWStr(sym);
const auto& sym = symbols[++m_index];
if (m_mask.empty() || fnmatch(m_mask, sym.first))
{
return true;
}
}
return L"";
return std::wstring();
return false;
}
///////////////////////////////////////////////////////////////////////////////
std::wstring SymbolEnumeratorClang::getName()
{
return strToWStr(m_symbolProvider->m_symbols[m_index].first);
}
///////////////////////////////////////////////////////////////////////////////
MEMOFFSET_64 SymbolEnumeratorClang::getOffset()
{
return 0;
}
///////////////////////////////////////////////////////////////////////////////
TypeInfoPtr SymbolEnumeratorClang::getType()
{
return TypeInfoPtr(new TypeInfoClangFunc(m_symbolProvider->m_astSession, m_symbolProvider->m_symbols[m_index].second));
}
///////////////////////////////////////////////////////////////////////////////
......
......@@ -402,6 +402,8 @@ private:
class SymbolEnumeratorClang;
using SymbolList = std::vector<std::pair<std::string, clang::FunctionDecl*> >;
class SymbolProviderClang : public SymbolProvider, public boost::enable_shared_from_this< SymbolProviderClang>
{
......@@ -417,7 +419,7 @@ private:
ClangASTSessionPtr m_astSession;
std::vector<std::string> m_symbols;
SymbolList m_symbols;
};
......@@ -426,15 +428,18 @@ class SymbolEnumeratorClang : public SymbolEnumerator
public:
SymbolEnumeratorClang(const std::wstring& mask, const boost::shared_ptr<SymbolProviderClang>& clangProvider) :
SymbolEnumeratorClang(const std::string& mask, const boost::shared_ptr<SymbolProviderClang>& clangProvider) :
m_symbolProvider(clangProvider),
m_index(0),
m_mask(wstrToStr(mask))
m_index(-1),
m_mask(mask)
{}
private:
std::wstring Next() override;
virtual bool Next() override;
virtual std::wstring getName() override;
virtual MEMOFFSET_64 getOffset() override;
virtual TypeInfoPtr getType() override;
private:
......
......@@ -570,11 +570,12 @@ TEST_F(ClangTest, EnumFuncNames)
auto symEnum = getSymbolProviderFromSource(srcCode)->getSymbolEnumerator();
std::wstring symbol;
std::vector<std::wstring> symbols;
while ( !(symbol = symEnum->Next()).empty() )
std::vector<std::wstring> types;
while (symEnum->Next())
{
symbols.push_back(symbol);
symbols.push_back(symEnum->getName());
types.push_back(symEnum->getType()->getName());
}
EXPECT_EQ( std::vector<std::wstring>({
......@@ -584,6 +585,14 @@ TEST_F(ClangTest, EnumFuncNames)
L"testns::func3",
L"testcls::method"
}), symbols);
EXPECT_EQ(std::vector<std::wstring>({
L"Void(__cdecl)(Int4B, Char)",
L"Void(__cdecl)()",
L"Int4B(__cdecl)()",
L"Char(__cdecl)()",
kdlib::is64bitSystem() ? L"Void(__cdecl testcls::)(Int4B)" : L"Void(__thiscall testcls::)(Int4B)"
}), types );
}
TEST_F(ClangTest, Func)
......