forked from qt-creator/qt-creator
Clang: Rename defineName in macroName
Change-Id: Iaf8da991032e5ed4726384c051290a77887351fa Reviewed-by: Ivan Donchevskii <ivan.donchevskii@qt.io>
This commit is contained in:
@@ -14,8 +14,8 @@ HEADERS += \
|
||||
$$PWD/symbolindexinginterface.h \
|
||||
$$PWD/collectmacrospreprocessorcallbacks.h \
|
||||
$$PWD/projectpartentry.h \
|
||||
$$PWD/useddefines.h \
|
||||
$$PWD/symbolsvisitorbase.h
|
||||
$$PWD/symbolsvisitorbase.h \
|
||||
$$PWD/usedmacro.h
|
||||
|
||||
!isEmpty(LIBTOOLING_LIBS) {
|
||||
SOURCES += \
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
#include "sourcelocationsutils.h"
|
||||
#include "sourcelocationentry.h"
|
||||
#include "symbolentry.h"
|
||||
#include "useddefines.h"
|
||||
#include "usedmacro.h"
|
||||
|
||||
#include <filepath.h>
|
||||
#include <filepathid.h>
|
||||
@@ -47,7 +47,7 @@ public:
|
||||
CollectMacrosPreprocessorCallbacks(SymbolEntries &symbolEntries,
|
||||
SourceLocationEntries &sourceLocationEntries,
|
||||
FilePathIds &sourceFiles,
|
||||
UsedDefines &usedDefines,
|
||||
UsedMacros &usedMacros,
|
||||
FilePathCachingInterface &filePathCache,
|
||||
const clang::SourceManager &sourceManager,
|
||||
std::shared_ptr<clang::Preprocessor> &&preprocessor)
|
||||
@@ -56,7 +56,7 @@ public:
|
||||
m_symbolEntries(symbolEntries),
|
||||
m_sourceLocationEntries(sourceLocationEntries),
|
||||
m_sourceFiles(sourceFiles),
|
||||
m_usedDefines(usedDefines)
|
||||
m_usedMacros(usedMacros)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -87,7 +87,7 @@ public:
|
||||
const clang::Token ¯oNameToken,
|
||||
const clang::MacroDefinition ¯oDefinition) override
|
||||
{
|
||||
addUsedDefine(macroNameToken, macroDefinition);
|
||||
addUsedMacro(macroNameToken, macroDefinition);
|
||||
addMacroAsSymbol(macroNameToken,
|
||||
firstMacroInfo(macroDefinition.getLocalDirective()),
|
||||
SymbolType::MacroUsage);
|
||||
@@ -97,7 +97,7 @@ public:
|
||||
const clang::Token ¯oNameToken,
|
||||
const clang::MacroDefinition ¯oDefinition) override
|
||||
{
|
||||
addUsedDefine( macroNameToken, macroDefinition);
|
||||
addUsedMacro( macroNameToken, macroDefinition);
|
||||
addMacroAsSymbol(macroNameToken,
|
||||
firstMacroInfo(macroDefinition.getLocalDirective()),
|
||||
SymbolType::MacroUsage);
|
||||
@@ -107,7 +107,7 @@ public:
|
||||
const clang::MacroDefinition ¯oDefinition,
|
||||
clang::SourceRange) override
|
||||
{
|
||||
addUsedDefine(macroNameToken, macroDefinition);
|
||||
addUsedMacro(macroNameToken, macroDefinition);
|
||||
addMacroAsSymbol(macroNameToken,
|
||||
firstMacroInfo(macroDefinition.getLocalDirective()),
|
||||
SymbolType::MacroUsage);
|
||||
@@ -133,7 +133,7 @@ public:
|
||||
clang::SourceRange,
|
||||
const clang::MacroArgs *) override
|
||||
{
|
||||
addUsedDefine(macroNameToken, macroDefinition);
|
||||
addUsedMacro(macroNameToken, macroDefinition);
|
||||
addMacroAsSymbol(macroNameToken,
|
||||
firstMacroInfo(macroDefinition.getLocalDirective()),
|
||||
SymbolType::MacroUsage);
|
||||
@@ -142,63 +142,63 @@ public:
|
||||
void EndOfMainFile() override
|
||||
{
|
||||
filterOutHeaderGuards();
|
||||
mergeUsedDefines();
|
||||
mergeUsedMacros();
|
||||
filterOutExports();
|
||||
}
|
||||
|
||||
void filterOutHeaderGuards()
|
||||
{
|
||||
auto partitionPoint = std::stable_partition(m_maybeUsedDefines.begin(),
|
||||
m_maybeUsedDefines.end(),
|
||||
[&] (const UsedDefine &usedDefine) {
|
||||
llvm::StringRef id{usedDefine.defineName.data(), usedDefine.defineName.size()};
|
||||
auto partitionPoint = std::stable_partition(m_maybeUsedMacros.begin(),
|
||||
m_maybeUsedMacros.end(),
|
||||
[&] (const UsedMacro &usedMacro) {
|
||||
llvm::StringRef id{usedMacro.macroName.data(), usedMacro.macroName.size()};
|
||||
clang::IdentifierInfo &identifierInfo = m_preprocessor->getIdentifierTable().get(id);
|
||||
clang::MacroInfo *macroInfo = m_preprocessor->getMacroInfo(&identifierInfo);
|
||||
return !macroInfo || !macroInfo->isUsedForHeaderGuard();
|
||||
});
|
||||
|
||||
m_maybeUsedDefines.erase(partitionPoint, m_maybeUsedDefines.end());
|
||||
m_maybeUsedMacros.erase(partitionPoint, m_maybeUsedMacros.end());
|
||||
}
|
||||
|
||||
void filterOutExports()
|
||||
{
|
||||
auto partitionPoint = std::stable_partition(m_usedDefines.begin(),
|
||||
m_usedDefines.end(),
|
||||
[&] (const UsedDefine &usedDefine) {
|
||||
return !usedDefine.defineName.contains("EXPORT");
|
||||
auto partitionPoint = std::stable_partition(m_usedMacros.begin(),
|
||||
m_usedMacros.end(),
|
||||
[&] (const UsedMacro &usedMacro) {
|
||||
return !usedMacro.macroName.contains("EXPORT");
|
||||
});
|
||||
|
||||
m_usedDefines.erase(partitionPoint, m_usedDefines.end());
|
||||
m_usedMacros.erase(partitionPoint, m_usedMacros.end());
|
||||
}
|
||||
|
||||
void mergeUsedDefines()
|
||||
void mergeUsedMacros()
|
||||
{
|
||||
m_usedDefines.reserve(m_usedDefines.size() + m_maybeUsedDefines.size());
|
||||
auto insertionPoint = m_usedDefines.insert(m_usedDefines.end(),
|
||||
m_maybeUsedDefines.begin(),
|
||||
m_maybeUsedDefines.end());
|
||||
std::inplace_merge(m_usedDefines.begin(), insertionPoint, m_usedDefines.end());
|
||||
m_usedMacros.reserve(m_usedMacros.size() + m_maybeUsedMacros.size());
|
||||
auto insertionPoint = m_usedMacros.insert(m_usedMacros.end(),
|
||||
m_maybeUsedMacros.begin(),
|
||||
m_maybeUsedMacros.end());
|
||||
std::inplace_merge(m_usedMacros.begin(), insertionPoint, m_usedMacros.end());
|
||||
}
|
||||
|
||||
static void addUsedDefine(UsedDefine &&usedDefine, UsedDefines &usedDefines)
|
||||
static void addUsedMacro(UsedMacro &&usedMacro, UsedMacros &usedMacros)
|
||||
{
|
||||
auto found = std::lower_bound(usedDefines.begin(),
|
||||
usedDefines.end(), usedDefine);
|
||||
auto found = std::lower_bound(usedMacros.begin(),
|
||||
usedMacros.end(), usedMacro);
|
||||
|
||||
if (found == usedDefines.end() || *found != usedDefine)
|
||||
usedDefines.insert(found, std::move(usedDefine));
|
||||
if (found == usedMacros.end() || *found != usedMacro)
|
||||
usedMacros.insert(found, std::move(usedMacro));
|
||||
}
|
||||
|
||||
void addUsedDefine(const clang::Token ¯oNameToken,
|
||||
void addUsedMacro(const clang::Token ¯oNameToken,
|
||||
const clang::MacroDefinition ¯oDefinition)
|
||||
{
|
||||
clang::MacroInfo *macroInfo = macroDefinition.getMacroInfo();
|
||||
UsedDefine usedDefine{macroNameToken.getIdentifierInfo()->getName(),
|
||||
UsedMacro usedMacro{macroNameToken.getIdentifierInfo()->getName(),
|
||||
filePathId(macroNameToken.getLocation())};
|
||||
if (macroInfo)
|
||||
addUsedDefine(std::move(usedDefine), m_usedDefines);
|
||||
addUsedMacro(std::move(usedMacro), m_usedMacros);
|
||||
else
|
||||
addUsedDefine(std::move(usedDefine), m_maybeUsedDefines);
|
||||
addUsedMacro(std::move(usedMacro), m_maybeUsedMacros);
|
||||
}
|
||||
|
||||
static const clang::MacroInfo *firstMacroInfo(const clang::MacroDirective *macroDirective)
|
||||
@@ -258,12 +258,12 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
UsedDefines m_maybeUsedDefines;
|
||||
UsedMacros m_maybeUsedMacros;
|
||||
std::shared_ptr<clang::Preprocessor> m_preprocessor;
|
||||
SymbolEntries &m_symbolEntries;
|
||||
SourceLocationEntries &m_sourceLocationEntries;
|
||||
FilePathIds &m_sourceFiles;
|
||||
UsedDefines &m_usedDefines;
|
||||
UsedMacros &m_usedMacros;
|
||||
bool m_skipInclude = false;
|
||||
};
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ bool CollectMacrosSourceFileCallbacks::handleBeginSource(clang::CompilerInstance
|
||||
m_symbolEntries,
|
||||
m_sourceLocationEntries,
|
||||
m_sourceFiles,
|
||||
m_usedDefines,
|
||||
m_usedMacros,
|
||||
m_filePathCache,
|
||||
compilerInstance.getSourceManager(),
|
||||
compilerInstance.getPreprocessorPtr());
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
|
||||
#include "sourcelocationentry.h"
|
||||
#include "symbolentry.h"
|
||||
#include "useddefines.h"
|
||||
#include "usedmacro.h"
|
||||
|
||||
#include <filepathcachinginterface.h>
|
||||
|
||||
@@ -64,14 +64,14 @@ public:
|
||||
m_sourceFiles.clear();
|
||||
}
|
||||
|
||||
const UsedDefines &usedDefines() const
|
||||
const UsedMacros &usedMacros() const
|
||||
{
|
||||
return m_usedDefines;
|
||||
return m_usedMacros;
|
||||
}
|
||||
|
||||
private:
|
||||
FilePathIds m_sourceFiles;
|
||||
UsedDefines m_usedDefines;
|
||||
UsedMacros m_usedMacros;
|
||||
SymbolEntries &m_symbolEntries;
|
||||
SourceLocationEntries &m_sourceLocationEntries;
|
||||
FilePathCachingInterface &m_filePathCache;
|
||||
|
||||
@@ -81,14 +81,14 @@ public:
|
||||
return table;
|
||||
}
|
||||
|
||||
Sqlite::Table createNewUsedDefinesTable() const
|
||||
Sqlite::Table createNewUsedMacrosTable() const
|
||||
{
|
||||
Sqlite::Table table;
|
||||
table.setName("newUsedDefines");
|
||||
table.setName("newUsedMacros");
|
||||
table.setUseTemporaryTable(true);
|
||||
const Sqlite::Column &sourceIdColumn = table.addColumn("sourceId", Sqlite::ColumnType::Integer);
|
||||
const Sqlite::Column &defineNameColumn = table.addColumn("defineName", Sqlite::ColumnType::Text);
|
||||
table.addIndex({sourceIdColumn, defineNameColumn});
|
||||
const Sqlite::Column ¯oNameColumn = table.addColumn("macroName", Sqlite::ColumnType::Text);
|
||||
table.addIndex({sourceIdColumn, macroNameColumn});
|
||||
|
||||
table.initialize(database);
|
||||
|
||||
@@ -100,7 +100,7 @@ public:
|
||||
Database &database;
|
||||
Sqlite::Table newSymbolsTablet{createNewSymbolsTable()};
|
||||
Sqlite::Table newLocationsTable{createNewLocationsTable()};
|
||||
Sqlite::Table newUsedDefineTable{createNewUsedDefinesTable()};
|
||||
Sqlite::Table newUsedMacroTable{createNewUsedMacrosTable()};
|
||||
WriteStatement insertSymbolsToNewSymbolsStatement{
|
||||
"INSERT INTO newSymbols(temporarySymbolId, usr, symbolName) VALUES(?,?,?)",
|
||||
database};
|
||||
@@ -166,20 +166,20 @@ public:
|
||||
"SELECT compilerArguments FROM projectParts WHERE projectPartId = (SELECT projectPartId FROM projectPartsSources WHERE sourceId = ?)",
|
||||
database
|
||||
};
|
||||
WriteStatement insertIntoNewUsedDefinesStatement{
|
||||
"INSERT INTO newUsedDefines(sourceId, defineName) VALUES (?,?)",
|
||||
WriteStatement insertIntoNewUsedMacrosStatement{
|
||||
"INSERT INTO newUsedMacros(sourceId, macroName) VALUES (?,?)",
|
||||
database
|
||||
};
|
||||
WriteStatement syncNewUsedDefinesStatement{
|
||||
"INSERT INTO usedDefines(sourceId, defineName) SELECT sourceId, defineName FROM newUsedDefines WHERE NOT EXISTS (SELECT sourceId FROM usedDefines WHERE usedDefines.sourceId == newUsedDefines.sourceId AND usedDefines.defineName == newUsedDefines.defineName)",
|
||||
WriteStatement syncNewUsedMacrosStatement{
|
||||
"INSERT INTO usedMacros(sourceId, macroName) SELECT sourceId, macroName FROM newUsedMacros WHERE NOT EXISTS (SELECT sourceId FROM usedMacros WHERE usedMacros.sourceId == newUsedMacros.sourceId AND usedMacros.macroName == newUsedMacros.macroName)",
|
||||
database
|
||||
};
|
||||
WriteStatement deleteOutdatedUsedDefinesStatement{
|
||||
"DELETE FROM usedDefines WHERE sourceId IN (SELECT sourceId FROM newUsedDefines) AND NOT EXISTS (SELECT sourceId FROM newUsedDefines WHERE newUsedDefines.sourceId == usedDefines.sourceId AND newUsedDefines.defineName == usedDefines.defineName)",
|
||||
WriteStatement deleteOutdatedUsedMacrosStatement{
|
||||
"DELETE FROM usedMacros WHERE sourceId IN (SELECT sourceId FROM newUsedMacros) AND NOT EXISTS (SELECT sourceId FROM newUsedMacros WHERE newUsedMacros.sourceId == usedMacros.sourceId AND newUsedMacros.macroName == usedMacros.macroName)",
|
||||
database
|
||||
};
|
||||
WriteStatement deleteNewUsedDefinesTableStatement{
|
||||
"DELETE FROM newUsedDefines",
|
||||
WriteStatement deleteNewUsedMacrosTableStatement{
|
||||
"DELETE FROM newUsedMacros",
|
||||
database
|
||||
};
|
||||
};
|
||||
|
||||
@@ -68,7 +68,7 @@ void SymbolIndexer::updateProjectPart(V2::ProjectPartContainer &&projectPart,
|
||||
m_symbolStorage.updateProjectPartSources(projectPart.projectPartId(),
|
||||
m_symbolsCollector.sourceFiles());
|
||||
|
||||
m_symbolStorage.insertOrUpdateUsedDefines(m_symbolsCollector.usedDefines());
|
||||
m_symbolStorage.insertOrUpdateUsedMacros(m_symbolsCollector.usedMacros());
|
||||
|
||||
transaction.commit();
|
||||
|
||||
|
||||
@@ -77,9 +77,9 @@ const FilePathIds &SymbolsCollector::sourceFiles() const
|
||||
return m_collectMacrosSourceFileCallbacks.sourceFiles();
|
||||
}
|
||||
|
||||
const UsedDefines &SymbolsCollector::usedDefines() const
|
||||
const UsedMacros &SymbolsCollector::usedMacros() const
|
||||
{
|
||||
return m_collectMacrosSourceFileCallbacks.usedDefines();
|
||||
return m_collectMacrosSourceFileCallbacks.usedMacros();
|
||||
}
|
||||
|
||||
} // namespace ClangBackEnd
|
||||
|
||||
@@ -51,7 +51,7 @@ public:
|
||||
const SymbolEntries &symbols() const override;
|
||||
const SourceLocationEntries &sourceLocations() const override;
|
||||
const FilePathIds &sourceFiles() const override;
|
||||
const UsedDefines &usedDefines() const override;
|
||||
const UsedMacros &usedMacros() const override;
|
||||
|
||||
private:
|
||||
ClangTool m_clangTool;
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
|
||||
#include "symbolentry.h"
|
||||
#include "sourcelocationentry.h"
|
||||
#include "useddefines.h"
|
||||
#include "usedmacro.h"
|
||||
|
||||
#include <filecontainerv2.h>
|
||||
|
||||
@@ -53,7 +53,7 @@ public:
|
||||
virtual const SymbolEntries &symbols() const = 0;
|
||||
virtual const SourceLocationEntries &sourceLocations() const = 0;
|
||||
virtual const FilePathIds &sourceFiles() const = 0;
|
||||
virtual const UsedDefines &usedDefines() const = 0;
|
||||
virtual const UsedMacros &usedMacros() const = 0;
|
||||
};
|
||||
|
||||
} // namespace ClangBackEnd
|
||||
|
||||
@@ -81,15 +81,15 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
void insertOrUpdateUsedDefines(const UsedDefines &usedDefines) override
|
||||
void insertOrUpdateUsedMacros(const UsedMacros &usedMacros) override
|
||||
{
|
||||
WriteStatement &insertStatement = m_statementFactory.insertIntoNewUsedDefinesStatement;
|
||||
for (const UsedDefine &usedDefine : usedDefines)
|
||||
insertStatement.write(usedDefine.filePathId.filePathId, usedDefine.defineName);
|
||||
WriteStatement &insertStatement = m_statementFactory.insertIntoNewUsedMacrosStatement;
|
||||
for (const UsedMacro &usedMacro : usedMacros)
|
||||
insertStatement.write(usedMacro.filePathId.filePathId, usedMacro.macroName);
|
||||
|
||||
m_statementFactory.syncNewUsedDefinesStatement.execute();
|
||||
m_statementFactory.deleteOutdatedUsedDefinesStatement.execute();
|
||||
m_statementFactory.deleteNewUsedDefinesTableStatement.execute();
|
||||
m_statementFactory.syncNewUsedMacrosStatement.execute();
|
||||
m_statementFactory.deleteOutdatedUsedMacrosStatement.execute();
|
||||
m_statementFactory.deleteNewUsedMacrosTableStatement.execute();
|
||||
}
|
||||
|
||||
void updateProjectPartSources(Utils::SmallStringView projectPartName,
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
#include "projectpartentry.h"
|
||||
#include "sourcelocationentry.h"
|
||||
#include "symbolentry.h"
|
||||
#include "useddefines.h"
|
||||
#include "usedmacro.h"
|
||||
|
||||
#include <sqlitetransaction.h>
|
||||
|
||||
@@ -48,7 +48,7 @@ public:
|
||||
const Utils::SmallStringVector &commandLineArguments) = 0;
|
||||
virtual void updateProjectPartSources(Utils::SmallStringView projectPartName,
|
||||
const FilePathIds &sourceFilePathIds) = 0;
|
||||
virtual void insertOrUpdateUsedDefines(const UsedDefines &usedDefines) = 0;
|
||||
virtual void insertOrUpdateUsedMacros(const UsedMacros &usedMacros) = 0;
|
||||
};
|
||||
|
||||
} // namespace ClangBackEnd
|
||||
|
||||
@@ -33,35 +33,35 @@
|
||||
|
||||
namespace ClangBackEnd {
|
||||
|
||||
class UsedDefine
|
||||
class UsedMacro
|
||||
{
|
||||
public:
|
||||
constexpr UsedDefine() = default;
|
||||
UsedDefine(Utils::SmallStringView defineName, FilePathId filePathId)
|
||||
: defineName(defineName),
|
||||
constexpr UsedMacro() = default;
|
||||
UsedMacro(Utils::SmallStringView macroName, FilePathId filePathId)
|
||||
: macroName(macroName),
|
||||
filePathId(filePathId)
|
||||
{}
|
||||
|
||||
friend bool operator<(const UsedDefine &first, const UsedDefine &second)
|
||||
friend bool operator<(const UsedMacro &first, const UsedMacro &second)
|
||||
{
|
||||
return std::tie(first.filePathId, first.defineName)
|
||||
< std::tie(second.filePathId, second.defineName);
|
||||
return std::tie(first.filePathId, first.macroName)
|
||||
< std::tie(second.filePathId, second.macroName);
|
||||
}
|
||||
|
||||
friend bool operator==(const UsedDefine &first, const UsedDefine &second)
|
||||
friend bool operator==(const UsedMacro &first, const UsedMacro &second)
|
||||
{
|
||||
return first.filePathId == second.filePathId && first.defineName == second.defineName;
|
||||
return first.filePathId == second.filePathId && first.macroName == second.macroName;
|
||||
}
|
||||
|
||||
friend bool operator!=(const UsedDefine &first, const UsedDefine &second)
|
||||
friend bool operator!=(const UsedMacro &first, const UsedMacro &second)
|
||||
{
|
||||
return !(first == second);
|
||||
}
|
||||
public:
|
||||
Utils::SmallString defineName;
|
||||
Utils::SmallString macroName;
|
||||
FilePathId filePathId;
|
||||
};
|
||||
|
||||
using UsedDefines = std::vector<UsedDefine>;
|
||||
using UsedMacros = std::vector<UsedMacro>;
|
||||
|
||||
} // ClangBackEnd
|
||||
Reference in New Issue
Block a user