data: Removed separate comment_location table

* added LocationType LOCATION_COMMENT
* store comment locations within source_locations
This commit is contained in:
Eberhard Graether
2018-10-04 21:21:31 +02:00
parent f060b6042d
commit 9edfdacd72
24 changed files with 80 additions and 408 deletions
-1
View File
@@ -237,7 +237,6 @@ add_files(
data/storage/type/StorageBookmark.h
data/storage/type/StorageBookmarkedEdge.h
data/storage/type/StorageBookmarkedNode.h
data/storage/type/StorageCommentLocation.h
data/storage/type/StorageComponentAccess.h
data/storage/type/StorageEdge.h
data/storage/type/StorageError.h
@@ -630,7 +630,9 @@ std::vector<CodeSnippetParams> CodeController::getSnippetsForFile(
);
std::vector<SnippetMerger::Range> atomicRanges;
m_storageAccess->getCommentLocationsInFile(activeSourceLocations->getFilePath())->forEachStartSourceLocation(
std::shared_ptr<SourceLocationFile> commentLocations =
m_storageAccess->getSourceLocationsOfTypeInFile(activeSourceLocations->getFilePath(), LOCATION_COMMENT);
commentLocations->forEachStartSourceLocation(
[&](SourceLocation* location)
{
atomicRanges.push_back(SnippetMerger::Range(
-2
View File
@@ -73,8 +73,6 @@ public:
virtual std::shared_ptr<SourceLocationFile> getSourceLocationsOfTypeInFile(
const FilePath& filePath, LocationType type) const = 0;
virtual std::shared_ptr<SourceLocationFile> getCommentLocationsInFile(const FilePath& filePath) const = 0;
virtual std::shared_ptr<TextAccess> getFileContent(const FilePath& filePath) const = 0;
virtual FileInfo getFileInfoForFileId(Id id) const = 0;
+40 -42
View File
@@ -16,58 +16,57 @@ void StorageAccessProxy::setSubject(std::weak_ptr<StorageAccess> subject)
#define UNWRAP(...) __VA_ARGS__
#define DEF_GETTER_0(_METHOD_NAME_, _RETURN_TYPE_, _DEFAULT_VALUE_) \
UNWRAP(_RETURN_TYPE_) StorageAccessProxy::_METHOD_NAME_() const \
{ \
if (std::shared_ptr<StorageAccess> subject = m_subject.lock()) \
{ \
return subject->_METHOD_NAME_(); \
} \
return _DEFAULT_VALUE_; \
#define DEF_GETTER_0(_METHOD_NAME_, _RETURN_TYPE_, _DEFAULT_VALUE_) \
UNWRAP(_RETURN_TYPE_) StorageAccessProxy::_METHOD_NAME_() const \
{ \
if (std::shared_ptr<StorageAccess> subject = m_subject.lock()) \
{ \
return subject->_METHOD_NAME_(); \
} \
return _DEFAULT_VALUE_; \
}
#define DEF_GETTER_1(_METHOD_NAME_, _PATAMETER_1_TYPE_, _RETURN_TYPE_, _DEFAULT_VALUE_) \
UNWRAP(_RETURN_TYPE_) StorageAccessProxy::_METHOD_NAME_(_PATAMETER_1_TYPE_ p1) const \
{ \
if (std::shared_ptr<StorageAccess> subject = m_subject.lock()) \
{ \
return subject->_METHOD_NAME_(p1); \
} \
return _DEFAULT_VALUE_; \
#define DEF_GETTER_1(_METHOD_NAME_, _PARAM_1_TYPE_, _RETURN_TYPE_, _DEFAULT_VALUE_) \
UNWRAP(_RETURN_TYPE_) StorageAccessProxy::_METHOD_NAME_(_PARAM_1_TYPE_ p1) const \
{ \
if (std::shared_ptr<StorageAccess> subject = m_subject.lock()) \
{ \
return subject->_METHOD_NAME_(p1); \
} \
return _DEFAULT_VALUE_; \
}
#define DEF_GETTER_2(_METHOD_NAME_, _PATAMETER_1_TYPE_, _PATAMETER_2_TYPE_, _RETURN_TYPE_, _DEFAULT_VALUE_) \
UNWRAP(_RETURN_TYPE_) StorageAccessProxy::_METHOD_NAME_(_PATAMETER_1_TYPE_ p1, _PATAMETER_2_TYPE_ p2) const \
{ \
if (std::shared_ptr<StorageAccess> subject = m_subject.lock()) \
{ \
return subject->_METHOD_NAME_(p1, p2); \
} \
return _DEFAULT_VALUE_; \
#define DEF_GETTER_2(_METHOD_NAME_, _PARAM_1_TYPE_, _PARAM_2_TYPE_, _RETURN_TYPE_, _DEFAULT_VALUE_) \
UNWRAP(_RETURN_TYPE_) StorageAccessProxy::_METHOD_NAME_(_PARAM_1_TYPE_ p1, _PARAM_2_TYPE_ p2) const \
{ \
if (std::shared_ptr<StorageAccess> subject = m_subject.lock()) \
{ \
return subject->_METHOD_NAME_(p1, p2); \
} \
return _DEFAULT_VALUE_; \
}
#define DEF_GETTER_3(_METHOD_NAME_, _PATAMETER_1_TYPE_, _PATAMETER_2_TYPE_, _PATAMETER_3_TYPE_, _RETURN_TYPE_, _DEFAULT_VALUE_) \
UNWRAP(_RETURN_TYPE_) StorageAccessProxy::_METHOD_NAME_(_PATAMETER_1_TYPE_ p1, _PATAMETER_2_TYPE_ p2, _PATAMETER_3_TYPE_ p3) const \
{ \
if (std::shared_ptr<StorageAccess> subject = m_subject.lock()) \
{ \
return subject->_METHOD_NAME_(p1, p2, p3); \
} \
return _DEFAULT_VALUE_; \
#define DEF_GETTER_3(_METHOD_NAME_, _PARAM_1_TYPE_, _PARAM_2_TYPE_, _PARAM_3_TYPE_, _RETURN_TYPE_, _DEFAULT_VALUE_) \
UNWRAP(_RETURN_TYPE_) StorageAccessProxy::_METHOD_NAME_(_PARAM_1_TYPE_ p1, _PARAM_2_TYPE_ p2, _PARAM_3_TYPE_ p3) const \
{ \
if (std::shared_ptr<StorageAccess> subject = m_subject.lock()) \
{ \
return subject->_METHOD_NAME_(p1, p2, p3); \
} \
return _DEFAULT_VALUE_; \
}
#define DEF_GETTER_4(_METHOD_NAME_, _PATAMETER_1_TYPE_, _PATAMETER_2_TYPE_, _PATAMETER_3_TYPE_, _PATAMETER_4_TYPE_, _RETURN_TYPE_, _DEFAULT_VALUE_) \
UNWRAP(_RETURN_TYPE_) StorageAccessProxy::_METHOD_NAME_(_PATAMETER_1_TYPE_ p1, _PATAMETER_2_TYPE_ p2, _PATAMETER_3_TYPE_ p3, _PATAMETER_4_TYPE_ p4) const \
{ \
if (std::shared_ptr<StorageAccess> subject = m_subject.lock()) \
{ \
return subject->_METHOD_NAME_(p1, p2, p3, p4); \
} \
return _DEFAULT_VALUE_; \
#define DEF_GETTER_4(_METHOD_NAME_, _PARAM_1_TYPE_, _PARAM_2_TYPE_, _PARAM_3_TYPE_, _PARAM_4_TYPE_, _RETURN_TYPE_, _DEFAULT_VALUE_) \
UNWRAP(_RETURN_TYPE_) StorageAccessProxy::_METHOD_NAME_(_PARAM_1_TYPE_ p1, _PARAM_2_TYPE_ p2, _PARAM_3_TYPE_ p3, _PARAM_4_TYPE_ p4) const \
{ \
if (std::shared_ptr<StorageAccess> subject = m_subject.lock()) \
{ \
return subject->_METHOD_NAME_(p1, p2, p3, p4); \
} \
return _DEFAULT_VALUE_; \
}
DEF_GETTER_1(getNodeIdForFileNode, const FilePath&, Id, 0)
DEF_GETTER_1(getNodeIdForNameHierarchy, const NameHierarchy&, Id, 0)
DEF_GETTER_1(getNodeIdsForNameHierarchies, const std::vector<NameHierarchy>, std::vector<Id>, {})
@@ -94,7 +93,6 @@ DEF_GETTER_1(getSourceLocationsForLocationIds, const std::vector<Id>&, std::shar
DEF_GETTER_1(getSourceLocationsForFile, const FilePath&, std::shared_ptr<SourceLocationFile>, std::make_shared<SourceLocationFile>(FilePath(), false, false, false))
DEF_GETTER_3(getSourceLocationsForLinesInFile, const FilePath&, size_t, size_t, std::shared_ptr<SourceLocationFile>, std::make_shared<SourceLocationFile>(FilePath(), false, false, false))
DEF_GETTER_2(getSourceLocationsOfTypeInFile, const FilePath&, LocationType, std::shared_ptr<SourceLocationFile>, std::make_shared<SourceLocationFile>(FilePath(), false, false, false))
DEF_GETTER_1(getCommentLocationsInFile, const FilePath&, std::shared_ptr<SourceLocationFile>, std::make_shared<SourceLocationFile>(FilePath(), false, false, false))
DEF_GETTER_1(getFileContent, const FilePath&, std::shared_ptr<TextAccess>, nullptr)
DEF_GETTER_1(getFileInfoForFileId, Id, FileInfo, FileInfo())
DEF_GETTER_1(getFileInfoForFilePath, const FilePath&, FileInfo, FileInfo())
-2
View File
@@ -54,8 +54,6 @@ public:
std::shared_ptr<SourceLocationFile> getSourceLocationsOfTypeInFile(
const FilePath& filePath, LocationType type) const override;
std::shared_ptr<SourceLocationFile> getCommentLocationsInFile(const FilePath& filePath) const override;
std::shared_ptr<TextAccess> getFileContent(const FilePath& filePath) const override;
FileInfo getFileInfoForFileId(Id id) const override;
@@ -65,7 +65,6 @@ void InterprocessIntermediateStorageManager::pushIntermediateStorage(
storage.setStorageSourceLocations(intermediateStorage->getStorageSourceLocations());
storage.setStorageOccurrences(intermediateStorage->getStorageOccurrences());
storage.setStorageComponentAccesses(intermediateStorage->getComponentAccesses());
storage.setStorageCommentLocations(intermediateStorage->getCommentLocations());
storage.setStorageErrors(intermediateStorage->getErrors());
storage.setNextId(intermediateStorage->getNextId());
@@ -96,7 +95,6 @@ std::shared_ptr<IntermediateStorage> InterprocessIntermediateStorageManager::pop
storage->setStorageSourceLocations(sharedIntermediateStorage.getStorageSourceLocations());
storage->setStorageOccurrences(sharedIntermediateStorage.getStorageOccurrences());
storage->setComponentAccesses(sharedIntermediateStorage.getStorageComponentAccesses());
storage->setCommentLocations(sharedIntermediateStorage.getStorageCommentLocations());
storage->setErrors(sharedIntermediateStorage.getStorageErrors());
storage->setNextId(sharedIntermediateStorage.getNextId());
@@ -5,7 +5,6 @@ SharedIntermediateStorage::SharedIntermediateStorage(SharedMemory::Allocator* al
, m_storageSymbols(allocator)
, m_storageOccurrences(allocator)
, m_storageComponentAccesses(allocator)
, m_storageCommentLocations(allocator)
, m_storageNodes(allocator)
, m_storageEdges(allocator)
, m_storageLocalSymbols(allocator)
@@ -200,28 +199,6 @@ void SharedIntermediateStorage::setStorageComponentAccesses(const std::set<Stora
}
}
std::set<StorageCommentLocationData> SharedIntermediateStorage::getStorageCommentLocations() const
{
std::set<StorageCommentLocationData> result;
for (unsigned int i = 0; i < m_storageCommentLocations.size(); i++)
{
result.emplace(fromShared(m_storageCommentLocations[i]));
}
return result;
}
void SharedIntermediateStorage::setStorageCommentLocations(const std::set<StorageCommentLocationData>& commentLocations)
{
m_storageCommentLocations.clear();
for (const StorageCommentLocationData commentLocation : commentLocations)
{
m_storageCommentLocations.push_back(toShared(commentLocation, m_allocator));
}
}
std::vector<StorageErrorData> SharedIntermediateStorage::getStorageErrors() const
{
std::vector<StorageErrorData> result;
@@ -37,9 +37,6 @@ public:
std::set<StorageComponentAccess> getStorageComponentAccesses() const;
void setStorageComponentAccesses(const std::set<StorageComponentAccess>& storageComponentAccesses);
std::set<StorageCommentLocationData> getStorageCommentLocations() const;
void setStorageCommentLocations(const std::set<StorageCommentLocationData>& commentLocations);
std::vector<StorageErrorData> getStorageErrors() const;
void setStorageErrors(const std::vector<StorageErrorData>& errors);
@@ -51,7 +48,6 @@ private:
SharedMemory::Vector<SharedStorageSymbol> m_storageSymbols;
SharedMemory::Vector<SharedStorageOccurrence> m_storageOccurrences;
SharedMemory::Vector<SharedStorageComponentAccess> m_storageComponentAccesses;
SharedMemory::Vector<SharedStorageCommentLocationData> m_storageCommentLocations;
SharedMemory::Vector<SharedStorageNode> m_storageNodes;
SharedMemory::Vector<SharedStorageEdge> m_storageEdges;
SharedMemory::Vector<SharedStorageLocalSymbol> m_storageLocalSymbols;
@@ -1,7 +1,6 @@
#ifndef SHARED_STORAGE_TYPES_H
#define SHARED_STORAGE_TYPES_H
#include "StorageCommentLocation.h"
#include "StorageComponentAccess.h"
#include "StorageEdge.h"
#include "StorageError.h"
@@ -37,7 +36,6 @@ CONVERT_STORAGE_TYPE_TO_SHARED_TYPE( StorageSymbol, SharedStorageSymbol )
CONVERT_STORAGE_TYPE_TO_SHARED_TYPE( StorageSourceLocation, SharedStorageSourceLocation )
CONVERT_STORAGE_TYPE_TO_SHARED_TYPE( StorageOccurrence, SharedStorageOccurrence )
CONVERT_STORAGE_TYPE_TO_SHARED_TYPE( StorageComponentAccess, SharedStorageComponentAccess)
CONVERT_STORAGE_TYPE_TO_SHARED_TYPE( StorageCommentLocationData, SharedStorageCommentLocationData)
struct SharedStorageNode
+2
View File
@@ -19,6 +19,8 @@ LocationType intToLocationType(int value)
return LOCATION_LOCAL_SYMBOL;
case LOCATION_SIGNATURE:
return LOCATION_SIGNATURE;
case LOCATION_COMMENT:
return LOCATION_COMMENT;
case LOCATION_ERROR:
return LOCATION_ERROR;
case LOCATION_FULLTEXT_SEARCH:
+4 -3
View File
@@ -8,9 +8,10 @@ enum LocationType
LOCATION_QUALIFIER = 2,
LOCATION_LOCAL_SYMBOL = 3,
LOCATION_SIGNATURE = 4,
LOCATION_ERROR = 5,
LOCATION_FULLTEXT_SEARCH = 6,
LOCATION_SCREEN_SEARCH = 7
LOCATION_COMMENT = 5,
LOCATION_ERROR = 6,
LOCATION_FULLTEXT_SEARCH = 7,
LOCATION_SCREEN_SEARCH = 8
};
int locationTypeToInt(LocationType type);
+8 -2
View File
@@ -89,12 +89,18 @@ void ParserClientImpl::recordFile(const FilePath& filePath, bool indexed)
void ParserClientImpl::recordComment(const ParseLocation& location)
{
m_storage->addCommentLocation(StorageCommentLocationData(
if (!location.isValid())
{
return;
}
m_storage->addSourceLocation(StorageSourceLocationData(
addFileName(location.filePath),
location.startLineNumber,
location.startColumnNumber,
location.endLineNumber,
location.endColumnNumber
location.endColumnNumber,
locationTypeToInt(LOCATION_COMMENT)
));
}
@@ -24,7 +24,6 @@ void IntermediateStorage::clear()
m_sourceLocations.clear();
m_occurrences.clear();
m_componentAccesses.clear();
m_commentLocations.clear();
m_errorsIndex.clear();
m_errors.clear();
@@ -63,7 +62,6 @@ size_t IntermediateStorage::getByteSize(size_t stringSize) const
}
byteSize += sizeof(StorageEdge) * getStorageEdges().size();
byteSize += sizeof(StorageCommentLocationData) * getCommentLocations().size();
byteSize += sizeof(StorageComponentAccess) * getComponentAccesses().size();
byteSize += sizeof(StorageOccurrence) * getStorageOccurrences().size();
byteSize += sizeof(StorageSymbol) * getStorageSymbols().size();
@@ -259,11 +257,6 @@ void IntermediateStorage::addComponentAccesses(const std::vector<StorageComponen
m_componentAccesses.insert(componentAccesses.begin(), componentAccesses.end());
}
void IntermediateStorage::addCommentLocation(const StorageCommentLocationData& commentLocationData)
{
m_commentLocations.emplace(commentLocationData);
}
void IntermediateStorage::addError(const StorageErrorData& errorData)
{
if (m_errorsIndex.find(errorData) == m_errorsIndex.end())
@@ -313,11 +306,6 @@ const std::set<StorageComponentAccess>& IntermediateStorage::getComponentAccesse
return m_componentAccesses;
}
const std::set<StorageCommentLocationData>& IntermediateStorage::getCommentLocations() const
{
return m_commentLocations;
}
const std::vector<StorageErrorData>& IntermediateStorage::getErrors() const
{
return m_errors;
@@ -381,11 +369,6 @@ void IntermediateStorage::setComponentAccesses(std::set<StorageComponentAccess>
m_componentAccesses = std::move(componentAccesses);
}
void IntermediateStorage::setCommentLocations(std::set<StorageCommentLocationData> commentLocations)
{
m_commentLocations = std::move(commentLocations);
}
void IntermediateStorage::setErrors(std::vector<StorageErrorData> errors)
{
m_errors = std::move(errors);
+2 -16
View File
@@ -5,19 +5,10 @@
#include <map>
#include <set>
#include "StorageCommentLocation.h"
#include "StorageComponentAccess.h"
#include "StorageEdge.h"
#include "StorageError.h"
#include "StorageFile.h"
#include "StorageLocalSymbol.h"
#include "StorageNode.h"
#include "StorageOccurrence.h"
#include "StorageSourceLocation.h"
#include "StorageSymbol.h"
#include "Storage.h"
class IntermediateStorage: public Storage
class IntermediateStorage
: public Storage
{
public:
IntermediateStorage();
@@ -45,7 +36,6 @@ public:
void addOccurrences(const std::vector<StorageOccurrence>& occurrences) override;
void addComponentAccess(const StorageComponentAccess& componentAccess) override;
void addComponentAccesses(const std::vector<StorageComponentAccess>& componentAccesses) override;
void addCommentLocation(const StorageCommentLocationData& commentLocationData) override;
void addError(const StorageErrorData& errorData) override;
const std::vector<StorageNode>& getStorageNodes() const override;
@@ -56,7 +46,6 @@ public:
const std::set<StorageSourceLocation>& getStorageSourceLocations() const override;
const std::set<StorageOccurrence>& getStorageOccurrences() const override;
const std::set<StorageComponentAccess>& getComponentAccesses() const override;
const std::set<StorageCommentLocationData>& getCommentLocations() const override;
const std::vector<StorageErrorData>& getErrors() const override;
void setStorageNodes(std::vector<StorageNode> storageNodes);
@@ -67,7 +56,6 @@ public:
void setStorageSourceLocations(std::set<StorageSourceLocation> storageSourceLocations);
void setStorageOccurrences(std::set<StorageOccurrence> storageOccurrences);
void setComponentAccesses(std::set<StorageComponentAccess> componentAccesses);
void setCommentLocations(std::set<StorageCommentLocationData> commentLocations);
void setErrors(std::vector<StorageErrorData> errors);
Id getNextId() const;
@@ -95,8 +83,6 @@ private:
std::set<StorageComponentAccess> m_componentAccesses;
std::set<StorageCommentLocationData> m_commentLocations;
std::set<StorageErrorData> m_errorsIndex; // this is used to prevent duplicates (unique)
std::vector<StorageErrorData> m_errors;
@@ -138,11 +138,6 @@ void PersistentStorage::addComponentAccesses(const std::vector<StorageComponentA
m_sqliteIndexStorage.addComponentAccesses(componentAccesses);
}
void PersistentStorage::addCommentLocation(const StorageCommentLocationData& data)
{
m_sqliteIndexStorage.addCommentLocation(data);
}
void PersistentStorage::addError(const StorageErrorData& data)
{
m_sqliteIndexStorage.addError(data);
@@ -188,16 +183,6 @@ const std::set<StorageComponentAccess>& PersistentStorage::getComponentAccesses(
return m_storageData.accesses = utility::toSet(m_sqliteIndexStorage.getAll<StorageComponentAccess>());
}
const std::set<StorageCommentLocationData>& PersistentStorage::getCommentLocations() const
{
std::set<StorageCommentLocationData> comments;
for (const StorageCommentLocation& comment : m_sqliteIndexStorage.getAll<StorageCommentLocation>())
{
comments.emplace(comment);
}
return m_storageData.comments = comments;
}
const std::vector<StorageErrorData>& PersistentStorage::getErrors() const
{
std::vector<StorageErrorData> errors;
@@ -1449,29 +1434,6 @@ std::shared_ptr<SourceLocationFile> PersistentStorage::getSourceLocationsOfTypeI
return m_sqliteIndexStorage.getSourceLocationsOfTypeInFile(filePath, type);
}
std::shared_ptr<SourceLocationFile> PersistentStorage::getCommentLocationsInFile(const FilePath& filePath) const
{
TRACE();
const std::shared_ptr<SourceLocationFile> file = std::make_shared<SourceLocationFile>(filePath, false, false, false);
const std::vector<StorageCommentLocation> storageLocations = m_sqliteIndexStorage.getCommentLocationsInFile(filePath);
for (size_t i = 0; i < storageLocations.size(); i++)
{
file->addSourceLocation(
LOCATION_TOKEN,
storageLocations[i].id,
std::vector<Id>(), // comment token location has no element.
storageLocations[i].startLine,
storageLocations[i].startCol,
storageLocations[i].endLine,
storageLocations[i].endCol
);
}
return file;
}
std::shared_ptr<TextAccess> PersistentStorage::getFileContent(const FilePath& filePath) const
{
TRACE();
-5
View File
@@ -34,7 +34,6 @@ public:
void addOccurrences(const std::vector<StorageOccurrence>& occurrences) override;
void addComponentAccess(const StorageComponentAccess& componentAccess) override;
void addComponentAccesses(const std::vector<StorageComponentAccess>& componentAccesses) override;
void addCommentLocation(const StorageCommentLocationData& data) override;
void addError(const StorageErrorData& data) override;
const std::vector<StorageNode>& getStorageNodes() const override;
@@ -45,7 +44,6 @@ public:
const std::set<StorageSourceLocation>& getStorageSourceLocations() const override;
const std::set<StorageOccurrence>& getStorageOccurrences() const override;
const std::set<StorageComponentAccess>& getComponentAccesses() const override;
const std::set<StorageCommentLocationData>& getCommentLocations() const override;
const std::vector<StorageErrorData>& getErrors() const override;
void startInjection() override;
@@ -122,8 +120,6 @@ public:
std::shared_ptr<SourceLocationFile> getSourceLocationsOfTypeInFile(
const FilePath& filePath, LocationType type) const override;
std::shared_ptr<SourceLocationFile> getCommentLocationsInFile(const FilePath& filePath) const override;
std::shared_ptr<TextAccess> getFileContent(const FilePath& filePath) const override;
bool hasContentForFile(const FilePath& filePath) const;
@@ -168,7 +164,6 @@ private:
std::set<StorageSourceLocation> locations;
std::set<StorageOccurrence> occurrences;
std::set<StorageComponentAccess> accesses;
std::set<StorageCommentLocationData> comments;
std::vector<StorageErrorData> errors;
} m_storageData;
-32
View File
@@ -1,18 +1,6 @@
#include "Storage.h"
#include <unordered_map>
#include "logging.h"
#include "StorageCommentLocation.h"
#include "StorageComponentAccess.h"
#include "StorageEdge.h"
#include "StorageError.h"
#include "StorageFile.h"
#include "StorageLocalSymbol.h"
#include "StorageNode.h"
#include "StorageOccurrence.h"
#include "StorageSourceLocation.h"
#include "StorageSymbol.h"
#include "tracing.h"
Storage::Storage()
@@ -261,26 +249,6 @@ void Storage::inject(Storage* injected)
addComponentAccesses(accesses);
}
{
// TRACE("inject comments");
for (const StorageCommentLocationData& location : injected->getCommentLocations())
{
auto it = injectedIdToOwnElementId.find(location.fileNodeId);
if (it != injectedIdToOwnElementId.end())
{
const Id ownFileNodeId = it->second;
addCommentLocation(StorageCommentLocationData(
ownFileNodeId,
location.startLine,
location.startCol,
location.endLine,
location.endCol
));
}
}
}
finishInjection();
}
-3
View File
@@ -6,7 +6,6 @@
#include <set>
#include <string>
#include "StorageCommentLocation.h"
#include "StorageComponentAccess.h"
#include "StorageEdge.h"
#include "StorageError.h"
@@ -39,7 +38,6 @@ public:
virtual void addOccurrences(const std::vector<StorageOccurrence>& occurrences) = 0;
virtual void addComponentAccess(const StorageComponentAccess& componentAccess) = 0;
virtual void addComponentAccesses(const std::vector<StorageComponentAccess>& componentAccesses) = 0;
virtual void addCommentLocation(const StorageCommentLocationData& data) = 0;
virtual void addError(const StorageErrorData& data) = 0;
virtual const std::vector<StorageNode>& getStorageNodes() const = 0;
@@ -50,7 +48,6 @@ public:
virtual const std::set<StorageSourceLocation>& getStorageSourceLocations() const = 0;
virtual const std::set<StorageOccurrence>& getStorageOccurrences() const = 0;
virtual const std::set<StorageComponentAccess>& getComponentAccesses() const = 0;
virtual const std::set<StorageCommentLocationData>& getCommentLocations() const = 0;
virtual const std::vector<StorageErrorData>& getErrors() const = 0;
void inject(Storage* injected);
@@ -11,7 +11,7 @@
#include "SourceLocationCollection.h"
#include "SourceLocationFile.h"
const size_t SqliteIndexStorage::s_storageVersion = 19;
const size_t SqliteIndexStorage::s_storageVersion = 20;
namespace
{
@@ -410,42 +410,6 @@ bool SqliteIndexStorage::addComponentAccesses(const std::vector<StorageComponent
return m_insertComponentAccessBatchStatement.execute(componentAccesses, this);
}
StorageCommentLocation SqliteIndexStorage::addCommentLocation(const StorageCommentLocationData& data)
{
Id id = 0;
{
m_checkCommentLocationExistsStmt.bind(1, int(data.fileNodeId));
m_checkCommentLocationExistsStmt.bind(2, int(data.startLine));
m_checkCommentLocationExistsStmt.bind(3, int(data.startCol));
m_checkCommentLocationExistsStmt.bind(4, int(data.endLine));
m_checkCommentLocationExistsStmt.bind(5, int(data.endCol));
CppSQLite3Query checkQuery = executeQuery(m_checkCommentLocationExistsStmt);
if (!checkQuery.eof() && checkQuery.numFields() > 0)
{
id = checkQuery.getIntField(0, 0);
}
m_checkCommentLocationExistsStmt.reset();
}
if (id == 0)
{
m_insertCommentLocationStmt.bind(1, int(data.fileNodeId));
m_insertCommentLocationStmt.bind(2, int(data.startLine));
m_insertCommentLocationStmt.bind(3, int(data.startCol));
m_insertCommentLocationStmt.bind(4, int(data.endLine));
m_insertCommentLocationStmt.bind(5, int(data.endCol));
const bool success = executeStatement(m_insertCommentLocationStmt);
if (success)
{
id = m_database.lastRowId();
}
}
return StorageCommentLocation(id, data);
}
StorageError SqliteIndexStorage::addError(const StorageErrorData& data)
{
const std::wstring sanitizedMessage = utility::replace(data.message, L"'", L"''");
@@ -874,13 +838,14 @@ std::shared_ptr<SourceLocationFile> SqliteIndexStorage::getSourceLocationsForFil
ret->setIsComplete(file.complete);
ret->setIsIndexed(file.indexed);
std::vector<StorageSourceLocation> sourceLocations =
doGetAll<StorageSourceLocation>("WHERE file_node_id == " + std::to_string(file.id) + " " + query);
std::vector<Id> sourceLocationIds;
std::unordered_map<Id, StorageSourceLocation> sourceLocationIdToData;
for (const StorageSourceLocation& storageLocation:
doGetAll<StorageSourceLocation>("WHERE file_node_id == " + std::to_string(file.id) + " " + query))
sourceLocationIds.reserve(sourceLocations.size());
for (const StorageSourceLocation& storageLocation : sourceLocations)
{
sourceLocationIds.push_back(storageLocation.id);
sourceLocationIdToData[storageLocation.id] = storageLocation;
}
std::map<Id, std::vector<Id>> sourceLocationIdToElementIds;
@@ -889,21 +854,19 @@ std::shared_ptr<SourceLocationFile> SqliteIndexStorage::getSourceLocationsForFil
sourceLocationIdToElementIds[occurrence.sourceLocationId].push_back(occurrence.elementId);
}
for (const std::pair<Id, std::vector<Id>>& p : sourceLocationIdToElementIds)
for (const StorageSourceLocation& location : sourceLocations)
{
auto it = sourceLocationIdToData.find(p.first);
if (it != sourceLocationIdToData.end())
{
ret->addSourceLocation(
intToLocationType(it->second.type),
it->second.id,
p.second,
it->second.startLine,
it->second.startCol,
it->second.endLine,
it->second.endCol
);
}
auto it = sourceLocationIdToElementIds.find(location.id);
ret->addSourceLocation(
intToLocationType(location.type),
location.id,
it != sourceLocationIdToElementIds.end() ? it->second : std::vector<Id>(),
location.startLine,
location.startCol,
location.endLine,
location.endCol
);
}
return ret;
@@ -999,12 +962,6 @@ std::vector<StorageComponentAccess> SqliteIndexStorage::getComponentAccessesByNo
return doGetAll<StorageComponentAccess>("WHERE node_id IN (" + utility::join(utility::toStrings(nodeIds), ',') + ")");
}
std::vector<StorageCommentLocation> SqliteIndexStorage::getCommentLocationsInFile(const FilePath& filePath) const
{
Id fileNodeId = getFileByPath(filePath.wstr()).id;
return doGetAll<StorageCommentLocation>("WHERE file_node_id == " + std::to_string(fileNodeId));
}
int SqliteIndexStorage::getNodeCount() const
{
return executeStatementScalar("SELECT COUNT(*) FROM node;", 0);
@@ -1063,15 +1020,6 @@ std::vector<std::pair<int, SqliteDatabaseIndex>> SqliteIndexStorage::getIndices(
STORAGE_MODE_READ,
SqliteDatabaseIndex("source_location_file_node_id_type_index", "source_location(file_node_id, type)")
));
indices.push_back(std::make_pair(
STORAGE_MODE_WRITE,
SqliteDatabaseIndex("comment_location_all_data_index",
"comment_location(file_node_id, start_line, start_column, end_line, end_column)")
));
indices.push_back(std::make_pair(
STORAGE_MODE_CLEAR,
SqliteDatabaseIndex("comment_location_file_node_id_index", "comment_location(file_node_id)")
));
indices.push_back(std::make_pair(
STORAGE_MODE_WRITE,
SqliteDatabaseIndex("error_all_data_index", "error(message, fatal, file_path, line_number, column_number)")
@@ -1096,7 +1044,6 @@ void SqliteIndexStorage::clearTables()
try
{
m_database.execDML("DROP TABLE IF EXISTS main.error;");
m_database.execDML("DROP TABLE IF EXISTS main.comment_location;");
m_database.execDML("DROP TABLE IF EXISTS main.component_access;");
m_database.execDML("DROP TABLE IF EXISTS main.occurrence;");
m_database.execDML("DROP TABLE IF EXISTS main.source_location;");
@@ -1213,18 +1160,6 @@ void SqliteIndexStorage::setupTables()
"FOREIGN KEY(node_id) REFERENCES node(id) ON DELETE CASCADE);"
);
m_database.execDML(
"CREATE TABLE IF NOT EXISTS comment_location("
"id INTEGER NOT NULL, "
"file_node_id INTEGER, "
"start_line INTEGER, "
"start_column INTEGER, "
"end_line INTEGER, "
"end_column INTEGER, "
"PRIMARY KEY(id), "
"FOREIGN KEY(file_node_id) REFERENCES node(id) ON DELETE CASCADE);"
);
m_database.execDML(
"CREATE TABLE IF NOT EXISTS error("
"id INTEGER NOT NULL, "
@@ -1337,19 +1272,6 @@ void SqliteIndexStorage::setupPrecompiledStatements()
m_insertFileContentStmt = m_database.compileStatement(
"INSERT INTO filecontent(id, content) VALUES(?, ?);"
);
m_checkCommentLocationExistsStmt = m_database.compileStatement(
"SELECT id FROM comment_location WHERE "
"file_node_id = ? AND "
"start_line == ? AND "
"start_column == ? AND "
"end_line == ? AND "
"end_column == ? "
"LIMIT 1;"
);
m_insertCommentLocationStmt = m_database.compileStatement(
"INSERT INTO comment_location(id, file_node_id, start_line, start_column, end_line, end_column) "
"VALUES(NULL, ?, ?, ?, ?, ?);"
);
m_checkErrorExistsStmt = m_database.compileStatement(
"SELECT id FROM error WHERE "
"message = ? AND "
@@ -1574,37 +1496,6 @@ std::vector<StorageComponentAccess> SqliteIndexStorage::doGetAll<StorageComponen
return componentAccesses;
}
template <>
std::vector<StorageCommentLocation> SqliteIndexStorage::doGetAll<StorageCommentLocation>(const std::string& query) const
{
CppSQLite3Query q = executeQuery(
"SELECT id, file_node_id, start_line, start_column, end_line, end_column FROM comment_location " + query + ";"
);
std::vector<StorageCommentLocation> commentLocations;
while (!q.eof())
{
const Id id = q.getIntField(0, 0);
const Id fileNodeId = q.getIntField(1, 0);
const int startLineNumber = q.getIntField(2, -1);
const int startColNumber = q.getIntField(3, -1);
const int endLineNumber = q.getIntField(4, -1);
const int endColNumber = q.getIntField(5, -1);
if (id != 0 && fileNodeId != 0 && startLineNumber != -1 && startColNumber != -1 && endLineNumber != -1 &&
endColNumber != -1)
{
commentLocations.emplace_back(
id, fileNodeId, startLineNumber, startColNumber, endLineNumber, endColNumber
);
}
q.nextRow();
}
return commentLocations;
}
template <>
std::vector<StorageError> SqliteIndexStorage::doGetAll<StorageError>(const std::string& query) const
{
@@ -8,7 +8,6 @@
#include "LocationType.h"
#include "SqliteDatabaseIndex.h"
#include "SqliteStorage.h"
#include "StorageCommentLocation.h"
#include "StorageComponentAccess.h"
#include "StorageEdge.h"
#include "StorageError.h"
@@ -64,7 +63,6 @@ public:
bool addOccurrences(const std::vector<StorageOccurrence>& occurrences);
bool addComponentAccess(const StorageComponentAccess& componentAccess);
bool addComponentAccesses(const std::vector<StorageComponentAccess>& componentAccesses);
StorageCommentLocation addCommentLocation(const StorageCommentLocationData& data);
StorageError addError(const StorageErrorData& data);
void removeElement(Id id);
@@ -122,8 +120,6 @@ public:
StorageComponentAccess getComponentAccessByNodeId(Id memberEdgeId) const;
std::vector<StorageComponentAccess> getComponentAccessesByNodeIds(const std::vector<Id>& memberEdgeIds) const;
std::vector<StorageCommentLocation> getCommentLocationsInFile(const FilePath& filePath) const;
template <typename ResultType>
std::vector<ResultType> getAll() const
{
@@ -306,8 +302,6 @@ private:
CppSQLite3Statement m_insertElementStmt;
CppSQLite3Statement m_insertFileStmt;
CppSQLite3Statement m_insertFileContentStmt;
CppSQLite3Statement m_checkCommentLocationExistsStmt;
CppSQLite3Statement m_insertCommentLocationStmt;
CppSQLite3Statement m_checkErrorExistsStmt;
CppSQLite3Statement m_insertErrorStmt;
};
@@ -332,8 +326,6 @@ std::vector<StorageOccurrence> SqliteIndexStorage::doGetAll<StorageOccurrence>(c
template <>
std::vector<StorageComponentAccess> SqliteIndexStorage::doGetAll<StorageComponentAccess>(const std::string& query) const;
template <>
std::vector<StorageCommentLocation> SqliteIndexStorage::doGetAll<StorageCommentLocation>(const std::string& query) const;
template <>
std::vector<StorageError> SqliteIndexStorage::doGetAll<StorageError>(const std::string& query) const;
#endif // SQLITE_INDEX_STORAGE_H
@@ -1,75 +0,0 @@
#ifndef STORAGE_COMMENT_LOCATION_H
#define STORAGE_COMMENT_LOCATION_H
#include "types.h"
struct StorageCommentLocationData
{
StorageCommentLocationData()
: fileNodeId(0)
, startLine(-1)
, startCol(-1)
, endLine(-1)
, endCol(-1)
{}
StorageCommentLocationData(Id fileNodeId, uint startLine, uint startCol, uint endLine, uint endCol)
: fileNodeId(fileNodeId)
, startLine(startLine)
, startCol(startCol)
, endLine(endLine)
, endCol(endCol)
{}
bool operator<(const StorageCommentLocationData& other) const
{
if (fileNodeId != other.fileNodeId)
{
return fileNodeId < other.fileNodeId;
}
else if (startLine != other.startLine)
{
return startLine < other.startLine;
}
else if (startCol != other.startCol)
{
return startCol < other.startCol;
}
else if (endLine != other.endLine)
{
return endLine < other.endLine;
}
else
{
return endCol < other.endCol;
}
}
Id fileNodeId;
uint startLine;
uint startCol;
uint endLine;
uint endCol;
};
struct StorageCommentLocation: public StorageCommentLocationData
{
StorageCommentLocation()
: StorageCommentLocationData()
, id(0)
{}
StorageCommentLocation(Id id, const StorageCommentLocationData& data)
: StorageCommentLocationData(data)
, id(id)
{}
StorageCommentLocation(Id id, Id fileNodeId, uint startLine, uint startCol, uint endLine, uint endCol)
: StorageCommentLocationData(fileNodeId, startLine, startCol, endLine, endCol)
, id(id)
{}
Id id;
};
#endif // STORAGE_COMMENT_LOCATION_H
+1 -1
View File
@@ -352,7 +352,7 @@ void QtCodeField::createAnnotations(std::shared_ptr<SourceLocationFile> location
locationFile->forEachSourceLocation(
[&](const SourceLocation* location)
{
if (location->getType() == LOCATION_SIGNATURE)
if (location->getType() == LOCATION_SIGNATURE || location->getType() == LOCATION_COMMENT)
{
return;
}
+1 -1
View File
@@ -224,7 +224,7 @@ void QtCodeNavigator::addFile(std::shared_ptr<SourceLocationFile> locationFile,
locationFile->forEachStartSourceLocation(
[&](SourceLocation* location)
{
if (location->isScopeLocation() || location->getType() == LOCATION_SIGNATURE)
if (location->isScopeLocation() || location->getType() == LOCATION_SIGNATURE || location->getType() == LOCATION_COMMENT)
{
return;
}
+1 -1
View File
@@ -229,9 +229,9 @@ private:
std::shared_ptr<JavaEnvironment> m_javaEnvironment;
const int m_id;
FilePath m_currentFilePath;
std::shared_ptr<IndexerStateInfo> m_indexerStateInfo;
const int m_id;
};
#endif // JAVA_PARSER_H