forked from qt-creator/qt-creator
Clang: Introduce CompilerMacro
We want not only the name but the value of the macro too. So we can compare if anything has changed. Change-Id: Ie59caf8cbf54d108f9e15299d25306a406b5c40d Reviewed-by: Ivan Donchevskii <ivan.donchevskii@qt.io>
This commit is contained in:
@@ -205,6 +205,7 @@ HEADERS += \
|
||||
$$PWD/baseserverproxy.h \
|
||||
$$PWD/filepath.h \
|
||||
$$PWD/nativefilepath.h \
|
||||
$$PWD/filepathview.h
|
||||
$$PWD/filepathview.h \
|
||||
$$PWD/compilermacro.h
|
||||
|
||||
contains(QT_CONFIG, reduce_exports):CONFIG += hide_symbols
|
||||
|
||||
78
src/libs/clangsupport/compilermacro.h
Normal file
78
src/libs/clangsupport/compilermacro.h
Normal file
@@ -0,0 +1,78 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** 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 <utils/smallstringio.h>
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace ClangBackEnd {
|
||||
|
||||
class CompilerMacro
|
||||
{
|
||||
public:
|
||||
constexpr CompilerMacro() = default;
|
||||
|
||||
CompilerMacro(Utils::SmallString &&key,
|
||||
Utils::SmallString &&value)
|
||||
: key(std::move(key)),
|
||||
value(std::move(value))
|
||||
{}
|
||||
|
||||
friend QDataStream &operator<<(QDataStream &out, const CompilerMacro &compilerMacro)
|
||||
{
|
||||
out << compilerMacro.key;
|
||||
out << compilerMacro.value;
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
friend QDataStream &operator>>(QDataStream &in, CompilerMacro &compilerMacro)
|
||||
{
|
||||
in >> compilerMacro.key;
|
||||
in >> compilerMacro.value;
|
||||
|
||||
return in;
|
||||
}
|
||||
|
||||
friend bool operator==(const CompilerMacro &first, const CompilerMacro &second)
|
||||
{
|
||||
return first.key == second.key
|
||||
&& first.value == second.value;
|
||||
}
|
||||
|
||||
friend bool operator<(const CompilerMacro &first, const CompilerMacro &second)
|
||||
{
|
||||
return std::tie(first.key, first.value) < std::tie(second.key, second.value);
|
||||
}
|
||||
|
||||
public:
|
||||
Utils::SmallString key;
|
||||
Utils::SmallString value;
|
||||
};
|
||||
|
||||
using CompilerMacros = std::vector<CompilerMacro>;
|
||||
}
|
||||
@@ -27,7 +27,8 @@
|
||||
|
||||
#include "clangsupport_global.h"
|
||||
|
||||
#include <filepathid.h>
|
||||
#include "compilermacro.h"
|
||||
#include "filepathid.h"
|
||||
|
||||
#include <utils/smallstringio.h>
|
||||
|
||||
@@ -40,12 +41,12 @@ public:
|
||||
ProjectPartContainer() = default;
|
||||
ProjectPartContainer(Utils::SmallString &&projectPartId,
|
||||
Utils::SmallStringVector &&arguments,
|
||||
Utils::SmallStringVector &¯oNames,
|
||||
CompilerMacros &&compilerMacros,
|
||||
FilePathIds &&headerPathIds,
|
||||
FilePathIds &&sourcePathIds)
|
||||
: m_projectPartId(std::move(projectPartId)),
|
||||
m_arguments(std::move(arguments)),
|
||||
m_macroNames(std::move(macroNames)),
|
||||
m_compilerMacros(std::move(compilerMacros)),
|
||||
m_headerPathIds(std::move(headerPathIds)),
|
||||
m_sourcePathIds(std::move(sourcePathIds))
|
||||
{
|
||||
@@ -66,9 +67,9 @@ public:
|
||||
return std::move(m_arguments);
|
||||
}
|
||||
|
||||
const Utils::SmallStringVector ¯oNames() const
|
||||
const CompilerMacros &compilerMacros() const
|
||||
{
|
||||
return m_macroNames;
|
||||
return m_compilerMacros;
|
||||
}
|
||||
|
||||
const FilePathIds &sourcePathIds() const
|
||||
@@ -85,7 +86,7 @@ public:
|
||||
{
|
||||
out << container.m_projectPartId;
|
||||
out << container.m_arguments;
|
||||
out << container.m_macroNames;
|
||||
out << container.m_compilerMacros;
|
||||
out << container.m_headerPathIds;
|
||||
out << container.m_sourcePathIds;
|
||||
|
||||
@@ -96,7 +97,7 @@ public:
|
||||
{
|
||||
in >> container.m_projectPartId;
|
||||
in >> container.m_arguments;
|
||||
in >> container.m_macroNames;
|
||||
in >> container.m_compilerMacros;
|
||||
in >> container.m_headerPathIds;
|
||||
in >> container.m_sourcePathIds;
|
||||
|
||||
@@ -107,7 +108,7 @@ public:
|
||||
{
|
||||
return first.m_projectPartId == second.m_projectPartId
|
||||
&& first.m_arguments == second.m_arguments
|
||||
&& first.m_macroNames == second.m_macroNames
|
||||
&& first.m_compilerMacros == second.m_compilerMacros
|
||||
&& first.m_headerPathIds == second.m_headerPathIds
|
||||
&& first.m_sourcePathIds == second.m_sourcePathIds;
|
||||
}
|
||||
@@ -116,12 +117,12 @@ public:
|
||||
{
|
||||
return std::tie(first.m_projectPartId,
|
||||
first.m_arguments,
|
||||
first.m_macroNames,
|
||||
first.m_compilerMacros,
|
||||
first.m_headerPathIds,
|
||||
first.m_sourcePathIds)
|
||||
< std::tie(second.m_projectPartId,
|
||||
second.m_arguments,
|
||||
second.m_macroNames,
|
||||
second.m_compilerMacros,
|
||||
second.m_headerPathIds,
|
||||
second.m_sourcePathIds);
|
||||
}
|
||||
@@ -134,7 +135,7 @@ public:
|
||||
private:
|
||||
Utils::SmallString m_projectPartId;
|
||||
Utils::SmallStringVector m_arguments;
|
||||
Utils::SmallStringVector m_macroNames;
|
||||
CompilerMacros m_compilerMacros;
|
||||
FilePathIds m_headerPathIds;
|
||||
FilePathIds m_sourcePathIds;
|
||||
};
|
||||
|
||||
@@ -115,7 +115,7 @@ public:
|
||||
table.addColumn("projectPartId", Sqlite::ColumnType::Integer, Sqlite::Contraint::PrimaryKey);
|
||||
const Sqlite::Column &projectPartNameColumn = table.addColumn("projectPartName", Sqlite::ColumnType::Text);
|
||||
table.addColumn("compilerArguments", Sqlite::ColumnType::Text);
|
||||
table.addColumn("macroNames", Sqlite::ColumnType::Text);
|
||||
table.addColumn("compilerMacros", Sqlite::ColumnType::Text);
|
||||
table.addIndex({projectPartNameColumn});
|
||||
|
||||
table.initialize(database);
|
||||
|
||||
@@ -121,11 +121,11 @@ QStringList ProjectUpdater::compilerArguments(CppTools::ProjectPart *projectPart
|
||||
return builder.build(CppTools::ProjectFile::CXXHeader, CompilerOptionsBuilder::PchUsage::None);
|
||||
}
|
||||
|
||||
Utils::SmallStringVector ProjectUpdater::createMacroNames(CppTools::ProjectPart *projectPart)
|
||||
ClangBackEnd::CompilerMacros ProjectUpdater::createCompilerMacros(CppTools::ProjectPart *projectPart)
|
||||
{
|
||||
return Utils::transform<Utils::SmallStringVector>(projectPart->projectMacros,
|
||||
[] (const ProjectExplorer::Macro ¯o) {
|
||||
return macro.key;
|
||||
return Utils::transform<ClangBackEnd::CompilerMacros>(projectPart->projectMacros,
|
||||
[] (const ProjectExplorer::Macro ¯o) {
|
||||
return ClangBackEnd::CompilerMacro{macro.key, macro.value};
|
||||
});
|
||||
}
|
||||
|
||||
@@ -139,7 +139,7 @@ ClangBackEnd::V2::ProjectPartContainer ProjectUpdater::toProjectPartContainer(
|
||||
|
||||
return ClangBackEnd::V2::ProjectPartContainer(projectPart->displayName,
|
||||
Utils::SmallStringVector(arguments),
|
||||
createMacroNames(projectPart),
|
||||
createCompilerMacros(projectPart),
|
||||
std::move(headerAndSources.headers),
|
||||
std::move(headerAndSources.sources));
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
|
||||
#include "clangpchmanager_global.h"
|
||||
|
||||
#include <compilermacro.h>
|
||||
#include <filecontainerv2.h>
|
||||
#include <filepathcachinginterface.h>
|
||||
|
||||
@@ -73,7 +74,7 @@ unittest_public:
|
||||
void addToHeaderAndSources(HeaderAndSources &headerAndSources,
|
||||
const CppTools::ProjectFile &projectFile) const;
|
||||
static QStringList compilerArguments(CppTools::ProjectPart *projectPart);
|
||||
static Utils::SmallStringVector createMacroNames(CppTools::ProjectPart *projectPart);
|
||||
static ClangBackEnd::CompilerMacros createCompilerMacros(CppTools::ProjectPart *projectPart);
|
||||
static Utils::PathStringVector createExcludedPaths(
|
||||
const ClangBackEnd::V2::FileContainers &generatedFiles);
|
||||
|
||||
|
||||
@@ -28,8 +28,11 @@
|
||||
#include <utils/algorithm.h>
|
||||
#include <utils/smallstringvector.h>
|
||||
|
||||
#include <compilermacro.h>
|
||||
|
||||
#include <QJsonArray>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
|
||||
namespace ClangBackEnd {
|
||||
|
||||
@@ -37,16 +40,16 @@ class ProjectPartArtefact
|
||||
{
|
||||
public:
|
||||
ProjectPartArtefact(Utils::SmallStringView compilerArgumentsText,
|
||||
Utils::SmallStringView macroNamesText,
|
||||
Utils::SmallStringView compilerMacrosText,
|
||||
int projectPartId)
|
||||
: compilerArguments(toVector(compilerArgumentsText)),
|
||||
macroNames(toVector(macroNamesText)),
|
||||
: compilerArguments(toStringVector(compilerArgumentsText)),
|
||||
compilerMacros(toCompilerMacros(compilerMacrosText)),
|
||||
projectPartId(projectPartId)
|
||||
{
|
||||
}
|
||||
|
||||
static
|
||||
Utils::SmallStringVector toVector(Utils::SmallStringView jsonText)
|
||||
Utils::SmallStringVector toStringVector(Utils::SmallStringView jsonText)
|
||||
{
|
||||
QJsonDocument document = QJsonDocument::fromJson(QByteArray::fromRawData(jsonText.data(),
|
||||
jsonText.size()));
|
||||
@@ -56,16 +59,31 @@ public:
|
||||
});
|
||||
}
|
||||
|
||||
static
|
||||
CompilerMacros toCompilerMacros(Utils::SmallStringView jsonText)
|
||||
{
|
||||
QJsonDocument document = QJsonDocument::fromJson(QByteArray::fromRawData(jsonText.data(),
|
||||
jsonText.size()));
|
||||
QJsonObject object = document.object();
|
||||
CompilerMacros macros;
|
||||
macros.reserve(object.size());
|
||||
|
||||
for (auto current = object.constBegin(); current != object.constEnd(); ++current)
|
||||
macros.emplace_back(current.key(), current.value().toString());
|
||||
|
||||
return macros;
|
||||
}
|
||||
|
||||
friend
|
||||
bool operator==(const ProjectPartArtefact &first, const ProjectPartArtefact &second)
|
||||
{
|
||||
return first.compilerArguments == second.compilerArguments
|
||||
&& first.macroNames == second.macroNames;
|
||||
&& first.compilerMacros == second.compilerMacros;
|
||||
}
|
||||
|
||||
public:
|
||||
Utils::SmallStringVector compilerArguments;
|
||||
Utils::SmallStringVector macroNames;
|
||||
CompilerMacros compilerMacros;
|
||||
int projectPartId = -1;
|
||||
};
|
||||
|
||||
|
||||
@@ -158,11 +158,11 @@ public:
|
||||
database
|
||||
};
|
||||
WriteStatement insertProjectPartStatement{
|
||||
"INSERT OR IGNORE INTO projectParts(projectPartName, compilerArguments, macroNames) VALUES (?,?,?)",
|
||||
"INSERT OR IGNORE INTO projectParts(projectPartName, compilerArguments, compilerMacros) VALUES (?,?,?)",
|
||||
database
|
||||
};
|
||||
WriteStatement updateProjectPartStatement{
|
||||
"UPDATE projectParts SET compilerArguments = ?, macroNames = ? WHERE projectPartName = ?",
|
||||
"UPDATE projectParts SET compilerArguments = ?, compilerMacros = ? WHERE projectPartName = ?",
|
||||
database
|
||||
};
|
||||
ReadStatement getProjectPartIdStatement{
|
||||
@@ -217,8 +217,8 @@ public:
|
||||
"DELETE FROM newSourceDependencies",
|
||||
database
|
||||
};
|
||||
ReadStatement getProjectPartCompilerArgumentsAndMacroNames{
|
||||
"SELECT compilerArguments, macroNames, projectPartId FROM projectParts WHERE projectPartId = (SELECT projectPartId FROM projectPartsSources WHERE sourceId = ?)",
|
||||
ReadStatement getProjectPartCompilerArgumentsAndCompilerMacrosBySourceId{
|
||||
"SELECT compilerArguments, compilerMacros, projectPartId FROM projectParts WHERE projectPartId = (SELECT projectPartId FROM projectPartsSources WHERE sourceId = ?)",
|
||||
database
|
||||
};
|
||||
};
|
||||
|
||||
@@ -65,7 +65,7 @@ void SymbolIndexer::updateProjectPart(V2::ProjectPartContainer &&projectPart,
|
||||
|
||||
m_symbolStorage.insertOrUpdateProjectPart(projectPart.projectPartId(),
|
||||
projectPart.arguments(),
|
||||
projectPart.macroNames());
|
||||
projectPart.compilerMacros());
|
||||
m_symbolStorage.updateProjectPartSources(projectPart.projectPartId(),
|
||||
m_symbolsCollector.sourceFiles());
|
||||
|
||||
|
||||
@@ -31,8 +31,9 @@
|
||||
#include <sqlitetransaction.h>
|
||||
#include <filepathcachingfwd.h>
|
||||
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonArray>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
|
||||
namespace ClangBackEnd {
|
||||
|
||||
@@ -67,25 +68,25 @@ public:
|
||||
|
||||
void insertOrUpdateProjectPart(Utils::SmallStringView projectPartName,
|
||||
const Utils::SmallStringVector &commandLineArguments,
|
||||
const Utils::SmallStringVector ¯oNames) override
|
||||
const CompilerMacros &compilerMacros) override
|
||||
{
|
||||
m_statementFactory.database.setLastInsertedRowId(-1);
|
||||
|
||||
Utils::SmallString compilerArguementsAsJson = toJson(commandLineArguments);
|
||||
Utils::SmallString macroNamesAsJson = toJson(macroNames);
|
||||
Utils::SmallString compilerMacrosAsJson = toJson(compilerMacros);
|
||||
|
||||
WriteStatement &insertStatement = m_statementFactory.insertProjectPartStatement;
|
||||
insertStatement.write(projectPartName, compilerArguementsAsJson, macroNamesAsJson);
|
||||
insertStatement.write(projectPartName, compilerArguementsAsJson, compilerMacrosAsJson);
|
||||
|
||||
if (m_statementFactory.database.lastInsertedRowId() == -1) {
|
||||
WriteStatement &updateStatement = m_statementFactory.updateProjectPartStatement;
|
||||
updateStatement.write(compilerArguementsAsJson, macroNamesAsJson, projectPartName);
|
||||
updateStatement.write(compilerArguementsAsJson, compilerMacrosAsJson, projectPartName);
|
||||
}
|
||||
}
|
||||
|
||||
Utils::optional<ProjectPartArtefact> fetchProjectPartArtefact(FilePathId sourceId) const override
|
||||
{
|
||||
ReadStatement &statement = m_statementFactory.getProjectPartCompilerArgumentsAndMacroNames;
|
||||
ReadStatement &statement = m_statementFactory.getProjectPartCompilerArgumentsAndCompilerMacrosBySourceId;
|
||||
|
||||
return statement.template value<ProjectPartArtefact, 3>(sourceId.filePathId);
|
||||
}
|
||||
@@ -157,6 +158,19 @@ public:
|
||||
return document.toJson(QJsonDocument::Compact);
|
||||
}
|
||||
|
||||
static Utils::SmallString toJson(const CompilerMacros &compilerMacros)
|
||||
{
|
||||
QJsonDocument document;
|
||||
QJsonObject object;
|
||||
|
||||
for (const CompilerMacro ¯o : compilerMacros)
|
||||
object.insert(QString(macro.key), QString(macro.value));
|
||||
|
||||
document.setObject(object);
|
||||
|
||||
return document.toJson(QJsonDocument::Compact);
|
||||
}
|
||||
|
||||
void fillTemporarySymbolsTable(const SymbolEntries &symbolEntries)
|
||||
{
|
||||
WriteStatement &statement = m_statementFactory.insertSymbolsToNewSymbolsStatement;
|
||||
|
||||
@@ -35,6 +35,8 @@
|
||||
|
||||
#include <sqlitetransaction.h>
|
||||
|
||||
#include <compilermacro.h>
|
||||
|
||||
namespace ClangBackEnd {
|
||||
|
||||
class SymbolStorageInterface
|
||||
@@ -49,7 +51,7 @@ public:
|
||||
const SourceLocationEntries &sourceLocations) = 0;
|
||||
virtual void insertOrUpdateProjectPart(Utils::SmallStringView projectPartName,
|
||||
const Utils::SmallStringVector &commandLineArguments,
|
||||
const Utils::SmallStringVector ¯oNames) = 0;
|
||||
const CompilerMacros &compilerMacros) = 0;
|
||||
virtual void updateProjectPartSources(Utils::SmallStringView projectPartName,
|
||||
const FilePathIds &sourceFilePathIds) = 0;
|
||||
virtual void updateProjectPartSources(int projectPartId,
|
||||
|
||||
Reference in New Issue
Block a user