2016-08-04 15:26:53 +02:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
|
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator.
|
|
|
|
|
**
|
|
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
|
|
|
|
**
|
|
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
|
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "symbolfinder.h"
|
|
|
|
|
|
2016-11-23 13:13:38 +01:00
|
|
|
#include "locationsourcefilecallbacks.h"
|
2016-08-04 15:26:53 +02:00
|
|
|
#include "symbollocationfinderaction.h"
|
|
|
|
|
|
|
|
|
|
namespace ClangBackEnd {
|
|
|
|
|
|
2017-09-21 11:43:59 +02:00
|
|
|
SymbolFinder::SymbolFinder(uint line, uint column, FilePathCachingInterface &filePathCache)
|
|
|
|
|
: m_usrFindingAction(line, column),
|
|
|
|
|
m_symbolLocationFinderAction(filePathCache),
|
|
|
|
|
m_sourceFileCallbacks(line, column, filePathCache)
|
2016-08-04 15:26:53 +02:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SymbolFinder::findSymbol()
|
|
|
|
|
{
|
2016-11-15 15:38:12 +01:00
|
|
|
clang::tooling::ClangTool tool = createTool();
|
2016-08-04 15:26:53 +02:00
|
|
|
|
2017-09-21 11:43:59 +02:00
|
|
|
tool.run(clang::tooling::newFrontendActionFactory(&m_usrFindingAction, &m_sourceFileCallbacks).get());
|
2016-08-04 15:26:53 +02:00
|
|
|
|
2017-09-21 11:43:59 +02:00
|
|
|
if (m_sourceFileCallbacks.hasSourceLocations()) {
|
|
|
|
|
m_sourceLocations_ = m_sourceFileCallbacks.takeSourceLocations();
|
|
|
|
|
m_symbolName = m_sourceFileCallbacks.takeSymbolName();
|
2016-08-04 15:26:53 +02:00
|
|
|
} else {
|
2017-09-21 11:43:59 +02:00
|
|
|
m_symbolLocationFinderAction.setUnifiedSymbolResolutions(m_usrFindingAction.takeUnifiedSymbolResolutions());
|
2016-08-04 15:26:53 +02:00
|
|
|
|
2017-09-21 11:43:59 +02:00
|
|
|
tool.run(clang::tooling::newFrontendActionFactory(&m_symbolLocationFinderAction).get());
|
2016-08-04 15:26:53 +02:00
|
|
|
|
2017-09-21 11:43:59 +02:00
|
|
|
m_sourceLocations_ = m_symbolLocationFinderAction.takeSourceLocations();
|
|
|
|
|
m_symbolName = m_usrFindingAction.takeSymbolName();
|
2016-08-04 15:26:53 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Utils::SmallString SymbolFinder::takeSymbolName()
|
|
|
|
|
{
|
2017-09-21 11:43:59 +02:00
|
|
|
return std::move(m_symbolName);
|
2016-08-04 15:26:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const std::vector<USRName> &SymbolFinder::unifiedSymbolResolutions()
|
|
|
|
|
{
|
2017-09-21 11:43:59 +02:00
|
|
|
return m_symbolLocationFinderAction.unifiedSymbolResolutions();
|
2016-08-04 15:26:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const SourceLocationsContainer &SymbolFinder::sourceLocations() const
|
|
|
|
|
{
|
2017-09-21 11:43:59 +02:00
|
|
|
return m_sourceLocations_;
|
2016-08-04 15:26:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SourceLocationsContainer SymbolFinder::takeSourceLocations()
|
|
|
|
|
{
|
2017-09-21 11:43:59 +02:00
|
|
|
return std::move(m_sourceLocations_);
|
2016-08-04 15:26:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace ClangBackEnd
|