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