2017-08-21 12:00:27 +02:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** Copyright (C) 2017 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.
|
|
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include "symbolstorageinterface.h"
|
|
|
|
|
|
2017-08-17 12:44:52 +02:00
|
|
|
#include <sqliteexception.h>
|
2017-08-21 12:00:27 +02:00
|
|
|
#include <sqlitetransaction.h>
|
2017-09-21 11:43:59 +02:00
|
|
|
#include <filepathcachingfwd.h>
|
2017-08-17 12:44:52 +02:00
|
|
|
|
2018-01-22 14:21:01 +01:00
|
|
|
#include <QJsonDocument>
|
|
|
|
|
#include <QJsonArray>
|
|
|
|
|
|
2017-08-21 12:00:27 +02:00
|
|
|
namespace ClangBackEnd {
|
|
|
|
|
|
|
|
|
|
template <typename StatementFactory>
|
2018-01-22 14:21:01 +01:00
|
|
|
class SymbolStorage final : public SymbolStorageInterface
|
2017-08-21 12:00:27 +02:00
|
|
|
{
|
|
|
|
|
using ReadStatement = typename StatementFactory::ReadStatementType;
|
|
|
|
|
using WriteStatement = typename StatementFactory::WriteStatementType;
|
|
|
|
|
using Database = typename StatementFactory::DatabaseType;
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
SymbolStorage(StatementFactory &statementFactory,
|
2017-09-21 11:43:59 +02:00
|
|
|
FilePathCachingInterface &filePathCache)
|
2017-08-21 12:00:27 +02:00
|
|
|
: m_statementFactory(statementFactory),
|
|
|
|
|
m_filePathCache(filePathCache)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void addSymbolsAndSourceLocations(const SymbolEntries &symbolEntries,
|
|
|
|
|
const SourceLocationEntries &sourceLocations) override
|
|
|
|
|
{
|
|
|
|
|
fillTemporarySymbolsTable(symbolEntries);
|
|
|
|
|
fillTemporaryLocationsTable(sourceLocations);
|
|
|
|
|
addNewSymbolsToSymbols();
|
|
|
|
|
syncNewSymbolsFromSymbols();
|
|
|
|
|
syncSymbolsIntoNewLocations();
|
|
|
|
|
deleteAllLocationsFromUpdatedFiles();
|
|
|
|
|
insertNewLocationsInLocations();
|
|
|
|
|
deleteNewSymbolsTable();
|
|
|
|
|
deleteNewLocationsTable();
|
2018-01-22 14:21:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void insertOrUpdateProjectPart(Utils::SmallStringView projectPartName,
|
2018-01-29 12:07:15 +01:00
|
|
|
const Utils::SmallStringVector &commandLineArguments,
|
|
|
|
|
const Utils::SmallStringVector ¯oNames) override
|
2018-01-22 14:21:01 +01:00
|
|
|
{
|
|
|
|
|
m_statementFactory.database.setLastInsertedRowId(-1);
|
|
|
|
|
|
|
|
|
|
Utils::SmallString compilerArguementsAsJson = toJson(commandLineArguments);
|
2018-01-29 12:07:15 +01:00
|
|
|
Utils::SmallString macroNamesAsJson = toJson(macroNames);
|
2018-01-22 14:21:01 +01:00
|
|
|
|
2018-01-24 19:06:58 +01:00
|
|
|
WriteStatement &insertStatement = m_statementFactory.insertProjectPartStatement;
|
2018-01-29 12:07:15 +01:00
|
|
|
insertStatement.write(projectPartName, compilerArguementsAsJson, macroNamesAsJson);
|
2018-01-22 14:21:01 +01:00
|
|
|
|
|
|
|
|
if (m_statementFactory.database.lastInsertedRowId() == -1) {
|
2018-01-24 19:06:58 +01:00
|
|
|
WriteStatement &updateStatement = m_statementFactory.updateProjectPartStatement;
|
2018-01-29 12:07:15 +01:00
|
|
|
updateStatement.write(compilerArguementsAsJson, macroNamesAsJson, projectPartName);
|
2018-01-22 14:21:01 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-25 15:20:47 +01:00
|
|
|
void insertOrUpdateUsedMacros(const UsedMacros &usedMacros) override
|
2018-01-23 18:08:17 +01:00
|
|
|
{
|
2018-01-25 15:20:47 +01:00
|
|
|
WriteStatement &insertStatement = m_statementFactory.insertIntoNewUsedMacrosStatement;
|
|
|
|
|
for (const UsedMacro &usedMacro : usedMacros)
|
|
|
|
|
insertStatement.write(usedMacro.filePathId.filePathId, usedMacro.macroName);
|
2018-01-23 18:08:17 +01:00
|
|
|
|
2018-01-25 15:20:47 +01:00
|
|
|
m_statementFactory.syncNewUsedMacrosStatement.execute();
|
|
|
|
|
m_statementFactory.deleteOutdatedUsedMacrosStatement.execute();
|
|
|
|
|
m_statementFactory.deleteNewUsedMacrosTableStatement.execute();
|
2018-01-23 18:08:17 +01:00
|
|
|
}
|
|
|
|
|
|
2018-01-22 14:21:01 +01:00
|
|
|
void updateProjectPartSources(Utils::SmallStringView projectPartName,
|
|
|
|
|
const FilePathIds &sourceFilePathIds) override
|
|
|
|
|
{
|
2018-01-24 19:06:58 +01:00
|
|
|
ReadStatement &getProjectPartIdStatement = m_statementFactory.getProjectPartIdStatement;
|
2018-01-22 14:21:01 +01:00
|
|
|
int projectPartId = getProjectPartIdStatement.template value<int>(projectPartName).value();
|
|
|
|
|
|
2018-01-24 19:06:58 +01:00
|
|
|
WriteStatement &deleteStatement = m_statementFactory.deleteAllProjectPartsSourcesWithProjectPartIdStatement;
|
2018-01-22 14:21:01 +01:00
|
|
|
deleteStatement.write(projectPartId);
|
|
|
|
|
|
2018-01-24 19:06:58 +01:00
|
|
|
WriteStatement &insertStatement = m_statementFactory.insertProjectPartSourcesStatement;
|
2018-01-22 14:21:01 +01:00
|
|
|
for (const FilePathId &sourceFilePathId : sourceFilePathIds)
|
|
|
|
|
insertStatement.write(projectPartId, sourceFilePathId.filePathId);
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-30 13:31:14 +01:00
|
|
|
void insertFileInformations(const FileInformations &fileInformations)
|
|
|
|
|
{
|
|
|
|
|
WriteStatement &statement = m_statementFactory.insertFileInformations;
|
|
|
|
|
|
|
|
|
|
for (const FileInformation &fileInformation : fileInformations)
|
|
|
|
|
statement.write(fileInformation.filePathId.filePathId,
|
|
|
|
|
fileInformation.size,
|
|
|
|
|
fileInformation.lastModified);
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-22 14:21:01 +01:00
|
|
|
static Utils::SmallString toJson(const Utils::SmallStringVector &strings)
|
|
|
|
|
{
|
|
|
|
|
QJsonDocument document;
|
|
|
|
|
QJsonArray array;
|
|
|
|
|
|
|
|
|
|
std::transform(strings.begin(), strings.end(), std::back_inserter(array), [] (const auto &string) {
|
|
|
|
|
return QJsonValue(string.data());
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
document.setArray(array);
|
2017-08-21 12:00:27 +02:00
|
|
|
|
2018-01-22 14:21:01 +01:00
|
|
|
return document.toJson(QJsonDocument::Compact);
|
2017-08-21 12:00:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void fillTemporarySymbolsTable(const SymbolEntries &symbolEntries)
|
|
|
|
|
{
|
|
|
|
|
WriteStatement &statement = m_statementFactory.insertSymbolsToNewSymbolsStatement;
|
|
|
|
|
|
|
|
|
|
for (const auto &symbolEntry : symbolEntries) {
|
|
|
|
|
statement.write(symbolEntry.first,
|
|
|
|
|
symbolEntry.second.usr,
|
|
|
|
|
symbolEntry.second.symbolName);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void fillTemporaryLocationsTable(const SourceLocationEntries &sourceLocations)
|
|
|
|
|
{
|
|
|
|
|
WriteStatement &statement = m_statementFactory.insertLocationsToNewLocationsStatement;
|
|
|
|
|
|
|
|
|
|
for (const auto &locationsEntry : sourceLocations) {
|
|
|
|
|
statement.write(locationsEntry.symbolId,
|
2018-01-22 14:21:01 +01:00
|
|
|
locationsEntry.lineColumn.line,
|
|
|
|
|
locationsEntry.lineColumn.column,
|
2018-01-17 13:52:33 +01:00
|
|
|
locationsEntry.filePathId.filePathId);
|
2017-08-21 12:00:27 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void addNewSymbolsToSymbols()
|
|
|
|
|
{
|
|
|
|
|
m_statementFactory.addNewSymbolsToSymbolsStatement.execute();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void syncNewSymbolsFromSymbols()
|
|
|
|
|
{
|
|
|
|
|
m_statementFactory.syncNewSymbolsFromSymbolsStatement.execute();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void syncSymbolsIntoNewLocations()
|
|
|
|
|
{
|
|
|
|
|
m_statementFactory.syncSymbolsIntoNewLocationsStatement.execute();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void deleteAllLocationsFromUpdatedFiles()
|
|
|
|
|
{
|
|
|
|
|
m_statementFactory.deleteAllLocationsFromUpdatedFilesStatement.execute();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void insertNewLocationsInLocations()
|
|
|
|
|
{
|
|
|
|
|
m_statementFactory.insertNewLocationsInLocationsStatement.execute();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void deleteNewSymbolsTable()
|
|
|
|
|
{
|
|
|
|
|
m_statementFactory.deleteNewSymbolsTableStatement.execute();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void deleteNewLocationsTable()
|
|
|
|
|
{
|
|
|
|
|
m_statementFactory.deleteNewLocationsTableStatement.execute();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SourceLocationEntries sourceLocations() const
|
|
|
|
|
{
|
|
|
|
|
return SourceLocationEntries();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
StatementFactory &m_statementFactory;
|
2017-09-21 11:43:59 +02:00
|
|
|
FilePathCachingInterface &m_filePathCache;
|
2017-08-21 12:00:27 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace ClangBackEnd
|