Clang: Get file informations from symbols collector

We need the same information like file size and the last modification time
to check if a file has changed. This information will be saved to the
database.

Change-Id: Icf8eb9b6553945a563887e11aff9539c9b300b66
Reviewed-by: Ivan Donchevskii <ivan.donchevskii@qt.io>
This commit is contained in:
Marco Bubke
2018-01-29 15:47:53 +01:00
parent 8aef667ad7
commit 70ab43ca62
12 changed files with 152 additions and 4 deletions

View File

@@ -15,7 +15,8 @@ HEADERS += \
$$PWD/collectmacrospreprocessorcallbacks.h \
$$PWD/projectpartentry.h \
$$PWD/symbolsvisitorbase.h \
$$PWD/usedmacro.h
$$PWD/usedmacro.h \
$$PWD/fileinformation.h
!isEmpty(LIBTOOLING_LIBS) {
SOURCES += \

View File

@@ -25,6 +25,7 @@
#pragma once
#include "fileinformation.h"
#include "symbolsvisitorbase.h"
#include "sourcelocationsutils.h"
#include "sourcelocationentry.h"
@@ -48,6 +49,7 @@ public:
SourceLocationEntries &sourceLocationEntries,
FilePathIds &sourceFiles,
UsedMacros &usedMacros,
FileInformations &fileInformations,
FilePathCachingInterface &filePathCache,
const clang::SourceManager &sourceManager,
std::shared_ptr<clang::Preprocessor> &&preprocessor)
@@ -56,10 +58,28 @@ public:
m_symbolEntries(symbolEntries),
m_sourceLocationEntries(sourceLocationEntries),
m_sourceFiles(sourceFiles),
m_usedMacros(usedMacros)
m_usedMacros(usedMacros),
m_fileInformations(fileInformations)
{
}
void FileChanged(clang::SourceLocation sourceLocation,
clang::PPCallbacks::FileChangeReason reason,
clang::SrcMgr::CharacteristicKind,
clang::FileID)
{
if (reason == clang::PPCallbacks::EnterFile)
{
const clang::FileEntry *fileEntry = m_sourceManager.getFileEntryForID(
m_sourceManager.getFileID(sourceLocation));
if (fileEntry) {
m_fileInformations.emplace_back(filePathId(sourceLocation),
fileEntry->getSize(),
fileEntry->getModificationTime());
}
}
}
void InclusionDirective(clang::SourceLocation /*hashLocation*/,
const clang::Token &/*includeToken*/,
llvm::StringRef /*fileName*/,
@@ -264,6 +284,7 @@ private:
SourceLocationEntries &m_sourceLocationEntries;
FilePathIds &m_sourceFiles;
UsedMacros &m_usedMacros;
FileInformations &m_fileInformations;
bool m_skipInclude = false;
};

View File

@@ -38,6 +38,7 @@ bool CollectMacrosSourceFileCallbacks::handleBeginSource(clang::CompilerInstance
m_sourceLocationEntries,
m_sourceFiles,
m_usedMacros,
m_fileInformations,
m_filePathCache,
compilerInstance.getSourceManager(),
compilerInstance.getPreprocessorPtr());

View File

@@ -25,6 +25,7 @@
#pragma once
#include "fileinformation.h"
#include "sourcelocationentry.h"
#include "symbolentry.h"
#include "usedmacro.h"
@@ -69,9 +70,15 @@ public:
return m_usedMacros;
}
const FileInformations &fileInformations() const
{
return m_fileInformations;
}
private:
FilePathIds m_sourceFiles;
UsedMacros m_usedMacros;
FileInformations m_fileInformations;
SymbolEntries &m_symbolEntries;
SourceLocationEntries &m_sourceLocationEntries;
FilePathCachingInterface &m_filePathCache;

View File

@@ -0,0 +1,62 @@
/****************************************************************************
**
** 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 <filepathid.h>
#include <ctime>
#include <sys/types.h>
#include <vector>
namespace ClangBackEnd {
class FileInformation
{
public:
FileInformation(FilePathId filePathId,
off_t size,
std::time_t lastModified)
: filePathId(filePathId),
size(size),
lastModified(lastModified)
{}
friend
bool operator==(const FileInformation &first, const FileInformation &second)
{
return first.filePathId == second.filePathId
&& first.size == second.size
&& first.lastModified == second.lastModified;
}
public:
FilePathId filePathId;
off_t size;
std::time_t lastModified;
};
using FileInformations = std::vector<FileInformation>;
}

View File

@@ -82,4 +82,9 @@ const UsedMacros &SymbolsCollector::usedMacros() const
return m_collectMacrosSourceFileCallbacks.usedMacros();
}
const FileInformations &SymbolsCollector::fileInformations() const
{
return m_collectMacrosSourceFileCallbacks.fileInformations();
}
} // namespace ClangBackEnd

View File

@@ -52,6 +52,7 @@ public:
const SourceLocationEntries &sourceLocations() const override;
const FilePathIds &sourceFiles() const override;
const UsedMacros &usedMacros() const override;
const FileInformations &fileInformations() const override;
private:
ClangTool m_clangTool;

View File

@@ -25,6 +25,7 @@
#pragma once
#include "fileinformation.h"
#include "symbolentry.h"
#include "sourcelocationentry.h"
#include "usedmacro.h"
@@ -54,6 +55,7 @@ public:
virtual const SourceLocationEntries &sourceLocations() const = 0;
virtual const FilePathIds &sourceFiles() const = 0;
virtual const UsedMacros &usedMacros() const = 0;
virtual const FileInformations &fileInformations() const = 0;
};
} // namespace ClangBackEnd