Merge remote-tracking branch 'origin/4.8' into master

Change-Id: I6ecd3732a147960681c6135e8752cbd046bad65b
This commit is contained in:
Orgad Shaneh
2018-10-12 17:21:14 +03:00
185 changed files with 4302 additions and 1493 deletions

View File

@@ -26,7 +26,6 @@
#pragma once
#include "filestatus.h"
#include "symbolsvisitorbase.h"
#include "sourcedependency.h"
#include "sourcelocationsutils.h"
#include "sourcelocationentry.h"
@@ -34,6 +33,8 @@
#include "symbolentry.h"
#include "usedmacro.h"
#include <collectusedmacrosandsourcespreprocessorcallbacks.h>
#include <filepath.h>
#include <filepathid.h>
@@ -44,7 +45,7 @@
namespace ClangBackEnd {
class CollectMacrosPreprocessorCallbacks final : public clang::PPCallbacks,
public SymbolsVisitorBase
public CollectUsedMacrosAndSourcesPreprocessorCallbacksBase
{
public:
CollectMacrosPreprocessorCallbacks(SymbolEntries &symbolEntries,
@@ -57,21 +58,23 @@ public:
const clang::SourceManager &sourceManager,
std::shared_ptr<clang::Preprocessor> &&preprocessor,
SourcesManager &sourcesManager)
: SymbolsVisitorBase(filePathCache, &sourceManager, sourcesManager),
m_preprocessor(std::move(preprocessor)),
m_sourceDependencies(sourceDependencies),
: CollectUsedMacrosAndSourcesPreprocessorCallbacksBase(usedMacros,
filePathCache,
sourceManager,
sourcesManager,
std::move(preprocessor),
sourceDependencies,
sourceFiles,
fileStatuses),
m_symbolEntries(symbolEntries),
m_sourceLocationEntries(sourceLocationEntries),
m_sourceFiles(sourceFiles),
m_usedMacros(usedMacros),
m_fileStatuses(fileStatuses)
m_sourceLocationEntries(sourceLocationEntries)
{
}
void FileChanged(clang::SourceLocation sourceLocation,
clang::PPCallbacks::FileChangeReason reason,
clang::SrcMgr::CharacteristicKind,
clang::FileID)
clang::FileID) override
{
if (reason == clang::PPCallbacks::EnterFile)
{
@@ -170,56 +173,6 @@ public:
m_sourcesManager.updateModifiedTimeStamps();
}
void filterOutHeaderGuards()
{
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_maybeUsedMacros.erase(partitionPoint, m_maybeUsedMacros.end());
}
void mergeUsedMacros()
{
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 addUsedMacro(UsedMacro &&usedMacro, UsedMacros &usedMacros)
{
if (!usedMacro.filePathId.isValid())
return;
auto found = std::lower_bound(usedMacros.begin(),
usedMacros.end(), usedMacro);
if (found == usedMacros.end() || *found != usedMacro)
usedMacros.insert(found, std::move(usedMacro));
}
void addUsedMacro(const clang::Token &macroNameToken,
const clang::MacroDefinition &macroDefinition)
{
if (isInSystemHeader(macroNameToken.getLocation()))
return;
clang::MacroInfo *macroInfo = macroDefinition.getMacroInfo();
UsedMacro usedMacro{macroNameToken.getIdentifierInfo()->getName(),
filePathId(macroNameToken.getLocation())};
if (macroInfo)
addUsedMacro(std::move(usedMacro), m_usedMacros);
else
addUsedMacro(std::move(usedMacro), m_maybeUsedMacros);
}
static const clang::MacroInfo *firstMacroInfo(const clang::MacroDirective *macroDirective)
{
if (macroDirective) {
@@ -235,11 +188,6 @@ public:
return nullptr;
}
bool isInSystemHeader(clang::SourceLocation sourceLocation) const
{
return m_sourceManager->isInSystemHeader(sourceLocation);
}
void addMacroAsSymbol(const clang::Token &macroNameToken,
const clang::MacroInfo *macroInfo,
SourceLocationKind symbolType)
@@ -272,53 +220,11 @@ public:
}
}
void addSourceFile(const clang::FileEntry *fileEntry)
{
auto id = filePathId(fileEntry);
auto found = std::lower_bound(m_sourceFiles.begin(), m_sourceFiles.end(), id);
if (found == m_sourceFiles.end() || *found != id)
m_sourceFiles.insert(found, id);
}
void addFileStatus(const clang::FileEntry *fileEntry)
{
auto id = filePathId(fileEntry);
auto found = std::lower_bound(m_fileStatuses.begin(),
m_fileStatuses.end(),
id,
[] (const auto &first, const auto &second) {
return first.filePathId < second;
});
if (found == m_fileStatuses.end() || found->filePathId != id) {
m_fileStatuses.emplace(found,
id,
fileEntry->getSize(),
fileEntry->getModificationTime(),
fileEntry->isInPCH());
}
}
void addSourceDependency(const clang::FileEntry *file, clang::SourceLocation includeLocation)
{
auto includeFilePathId = filePathId(includeLocation);
auto includedFilePathId = filePathId(file);
m_sourceDependencies.emplace_back(includeFilePathId, includedFilePathId);
}
private:
UsedMacros m_maybeUsedMacros;
std::shared_ptr<clang::Preprocessor> m_preprocessor;
SourceDependencies &m_sourceDependencies;
SymbolEntries &m_symbolEntries;
SourceLocationEntries &m_sourceLocationEntries;
FilePathIds &m_sourceFiles;
UsedMacros &m_usedMacros;
FileStatuses &m_fileStatuses;
bool m_skipInclude = false;
};

View File

@@ -70,6 +70,7 @@ public:
m_sourceFiles.clear();
m_usedMacros.clear();
m_fileStatuses.clear();
m_sourceDependencies.clear();
}
const UsedMacros &usedMacros() const