src: Refactored TokenLocation classes to SourceLocation classes
* Removed TokenLocationLine * decoupled TokenLocationFile from TokenLocationCollection * save vector of Token ids to SourceLocation * refactored SourceLocationFile::getFilteredByLines() * refactored snippet creation
This commit is contained in:
@@ -21,14 +21,14 @@ NetworkProtocolHelper.cpp ERROR: Failed to parse message, invalid type token: fo
|
||||
NetworkProtocolHelper.cpp ERROR: Failed to parse setActiveToken message, invalid token count
|
||||
Settings.cpp WARNING: File for Settings not found: data/SettingsTestSuite/wrong_settings.xml
|
||||
Settings.cpp WARNING: File for Settings not found: data/SettingsTestSuite/wrong_settings.xml
|
||||
SourceLocationCollection.cpp ERROR: SourceLocation has wrong boundaries: file.c 2:3 2:1
|
||||
SourceLocationCollection.cpp ERROR: SourceLocation has wrong boundaries: file.c 4:1 1:10
|
||||
TextAccess.cpp ERROR: Could not open file path/to/test.h
|
||||
TextAccess.cpp WARNING: Index 'firstLine' has to be lower or equal index 'lastLine', is 3 > 2
|
||||
TextAccess.cpp WARNING: Tried to access index 10. Maximum index is 8
|
||||
TextAccess.cpp WARNING: Tried to access index 10. Maximum index is 8
|
||||
TextAccess.cpp WARNING: Line numbers start with one, is 0
|
||||
TextAccess.cpp WARNING: Line numbers start with one, is 0
|
||||
TokenLocationCollection.cpp ERROR: TokenLocation has wrong boundaries: file.c 2:3 2:1
|
||||
TokenLocationCollection.cpp ERROR: TokenLocation has wrong boundaries: file.c 4:1 1:10
|
||||
INFO: Indexer - indexing source file: input.cc
|
||||
INFO: Indexer - indexing source file: input.cc
|
||||
INFO: Indexer - indexing source file: input.cc
|
||||
|
||||
@@ -154,14 +154,12 @@ add_files(
|
||||
|
||||
data/location/LocationType.cpp
|
||||
data/location/LocationType.h
|
||||
data/location/TokenLocation.cpp
|
||||
data/location/TokenLocation.h
|
||||
data/location/TokenLocationCollection.cpp
|
||||
data/location/TokenLocationCollection.h
|
||||
data/location/TokenLocationFile.cpp
|
||||
data/location/TokenLocationFile.h
|
||||
data/location/TokenLocationLine.cpp
|
||||
data/location/TokenLocationLine.h
|
||||
data/location/SourceLocation.cpp
|
||||
data/location/SourceLocation.h
|
||||
data/location/SourceLocationCollection.cpp
|
||||
data/location/SourceLocationCollection.h
|
||||
data/location/SourceLocationFile.cpp
|
||||
data/location/SourceLocationFile.h
|
||||
|
||||
data/name/NameElement.cpp
|
||||
data/name/NameElement.h
|
||||
@@ -300,7 +298,7 @@ add_files(
|
||||
utility/messaging/type/MessageActivateFile.h
|
||||
utility/messaging/type/MessageActivateLocalSymbols.h
|
||||
utility/messaging/type/MessageActivateNodes.h
|
||||
utility/messaging/type/MessageActivateTokenLocations.h
|
||||
utility/messaging/type/MessageActivateSourceLocations.h
|
||||
utility/messaging/type/MessageActivateTokenIds.h
|
||||
utility/messaging/type/MessageActivateTokens.h
|
||||
utility/messaging/type/MessageActivateWindow.h
|
||||
|
||||
@@ -141,7 +141,7 @@ void ActivationController::handleMessage(MessageActivateTokenIds* message)
|
||||
m.dispatchImmediately();
|
||||
}
|
||||
|
||||
void ActivationController::handleMessage(MessageActivateTokenLocations* message)
|
||||
void ActivationController::handleMessage(MessageActivateSourceLocations* message)
|
||||
{
|
||||
MessageActivateNodes m;
|
||||
for (Id nodeId : m_storageAccess->getNodeIdsForLocationIds(message->locationIds))
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
#include "utility/messaging/type/MessageActivateFile.h"
|
||||
#include "utility/messaging/type/MessageActivateNodes.h"
|
||||
#include "utility/messaging/type/MessageActivateTokenIds.h"
|
||||
#include "utility/messaging/type/MessageActivateTokenLocations.h"
|
||||
#include "utility/messaging/type/MessageActivateSourceLocations.h"
|
||||
#include "utility/messaging/type/MessageResetZoom.h"
|
||||
#include "utility/messaging/type/MessageSearch.h"
|
||||
#include "utility/messaging/type/MessageZoom.h"
|
||||
@@ -23,7 +23,7 @@ class ActivationController
|
||||
, public MessageListener<MessageActivateFile>
|
||||
, public MessageListener<MessageActivateNodes>
|
||||
, public MessageListener<MessageActivateTokenIds>
|
||||
, public MessageListener<MessageActivateTokenLocations>
|
||||
, public MessageListener<MessageActivateSourceLocations>
|
||||
, public MessageListener<MessageResetZoom>
|
||||
, public MessageListener<MessageSearch>
|
||||
, public MessageListener<MessageZoom>
|
||||
@@ -40,7 +40,7 @@ private:
|
||||
virtual void handleMessage(MessageActivateNodes* message);
|
||||
virtual void handleMessage(MessageSearch* message);
|
||||
virtual void handleMessage(MessageActivateTokenIds* message);
|
||||
virtual void handleMessage(MessageActivateTokenLocations* message);
|
||||
virtual void handleMessage(MessageActivateSourceLocations* message);
|
||||
virtual void handleMessage(MessageResetZoom* message);
|
||||
virtual void handleMessage(MessageZoom* message);
|
||||
|
||||
|
||||
@@ -5,10 +5,6 @@
|
||||
#include "data/access/StorageAccess.h"
|
||||
#include "data/bookmark/Bookmark.h"
|
||||
|
||||
#include "data/location/TokenLocation.h"
|
||||
#include "data/location/TokenLocationCollection.h"
|
||||
#include "data/location/TokenLocationFile.h"
|
||||
|
||||
#include "utility/messaging/type/MessageActivateEdge.h"
|
||||
#include "utility/messaging/type/MessageActivateNodes.h"
|
||||
|
||||
|
||||
@@ -9,10 +9,9 @@
|
||||
#include "utility/utilityString.h"
|
||||
|
||||
#include "data/access/StorageAccess.h"
|
||||
#include "data/location/TokenLocation.h"
|
||||
#include "data/location/TokenLocationCollection.h"
|
||||
#include "data/location/TokenLocationFile.h"
|
||||
#include "data/location/TokenLocationLine.h"
|
||||
#include "data/location/SourceLocation.h"
|
||||
#include "data/location/SourceLocationCollection.h"
|
||||
#include "data/location/SourceLocationFile.h"
|
||||
#include "settings/ApplicationSettings.h"
|
||||
#include "Application.h"
|
||||
|
||||
@@ -20,6 +19,7 @@ CodeController::CodeController(StorageAccess* storageAccess)
|
||||
: m_storageAccess(storageAccess)
|
||||
, m_scrollToDefinition(false)
|
||||
, m_scrollToValue(-1)
|
||||
, m_scrollToLine(0)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -49,8 +49,7 @@ void CodeController::handleMessage(MessageActivateAll* message)
|
||||
|
||||
statsSnippet.reduced = true;
|
||||
|
||||
statsSnippet.locationFile = std::make_shared<TokenLocationFile>(FilePath());
|
||||
statsSnippet.locationFile->isWholeCopy = true;
|
||||
statsSnippet.locationFile = std::make_shared<SourceLocationFile>(FilePath(), true);
|
||||
|
||||
std::vector<std::string> description = getProjectDescription(statsSnippet.locationFile.get());
|
||||
|
||||
@@ -125,7 +124,7 @@ void CodeController::handleMessage(MessageActivateTokens* message)
|
||||
|
||||
if (message->isEdge)
|
||||
{
|
||||
std::shared_ptr<TokenLocationCollection> collection = m_storageAccess->getTokenLocationsForTokenIds(activeTokenIds);
|
||||
std::shared_ptr<SourceLocationCollection> collection = m_storageAccess->getSourceLocationsForTokenIds(activeTokenIds);
|
||||
view->showActiveSnippet(activeTokenIds, collection, message->isLast());
|
||||
}
|
||||
else if (message->keepContent())
|
||||
@@ -139,16 +138,16 @@ void CodeController::handleMessage(MessageActivateTokens* message)
|
||||
}
|
||||
else
|
||||
{
|
||||
m_collection = m_storageAccess->getTokenLocationsForTokenIds(activeTokenIds);
|
||||
m_collection = m_storageAccess->getSourceLocationsForTokenIds(activeTokenIds);
|
||||
view->showCodeSnippets(
|
||||
getSnippetsForActiveTokenLocations(m_collection.get(), declarationId),
|
||||
getSnippetsForActiveSourceLocations(m_collection.get(), declarationId),
|
||||
activeTokenIds,
|
||||
!message->isReplayed() || message->isReplayCleared()
|
||||
);
|
||||
m_scrollToDefinition = !message->isReplayed() || message->isReplayCleared();
|
||||
|
||||
size_t fileCount = m_collection->getTokenLocationFileCount();
|
||||
size_t referenceCount = m_collection->getTokenLocationCount();
|
||||
size_t fileCount = m_collection->getSourceLocationFileCount();
|
||||
size_t referenceCount = m_collection->getSourceLocationCount();
|
||||
|
||||
std::stringstream ss;
|
||||
|
||||
@@ -201,7 +200,7 @@ void CodeController::handleMessage(MessageChangeFileView* message)
|
||||
case MessageChangeFileView::FILE_SNIPPETS:
|
||||
if (message->needsData && inListMode)
|
||||
{
|
||||
std::shared_ptr<TokenLocationFile> file = m_collection->getTokenLocationFileByPath(message->filePath);
|
||||
std::shared_ptr<SourceLocationFile> file = m_collection->getSourceLocationFileByPath(message->filePath);
|
||||
if (!file)
|
||||
{
|
||||
return;
|
||||
@@ -209,7 +208,7 @@ void CodeController::handleMessage(MessageChangeFileView* message)
|
||||
|
||||
if (message->showErrors)
|
||||
{
|
||||
file->isWholeCopy = false;
|
||||
file->setIsWhole(false);
|
||||
}
|
||||
|
||||
view->addCodeSnippets(getSnippetsForFile(file, !message->showErrors), false);
|
||||
@@ -231,25 +230,25 @@ void CodeController::handleMessage(MessageChangeFileView* message)
|
||||
|
||||
if (message->showErrors)
|
||||
{
|
||||
params.locationFile = m_collection->getTokenLocationFileByPath(message->filePath);
|
||||
params.locationFile = m_collection->getSourceLocationFileByPath(message->filePath);
|
||||
if (!params.locationFile)
|
||||
{
|
||||
return;
|
||||
}
|
||||
params.locationFile->isWholeCopy = true;
|
||||
params.locationFile->setIsWhole(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::shared_ptr<TokenLocationFile> file =
|
||||
m_storageAccess->getTokenLocationsForFile(message->filePath.str());
|
||||
std::shared_ptr<SourceLocationFile> file =
|
||||
m_storageAccess->getSourceLocationsForFile(message->filePath.str());
|
||||
|
||||
TokenLocationFile* activeLocations = m_collection->findTokenLocationFileByPath(message->filePath);
|
||||
SourceLocationFile* activeLocations = m_collection->getSourceLocationFileByPath(message->filePath).get();
|
||||
if (activeLocations)
|
||||
{
|
||||
activeLocations->forEachTokenLocation(
|
||||
[&file](TokenLocation* location)
|
||||
activeLocations->forEachSourceLocation(
|
||||
[&file](SourceLocation* location)
|
||||
{
|
||||
file->addTokenLocationAsPlainCopy(location);
|
||||
file->addSourceLocationCopy(location);
|
||||
}
|
||||
);
|
||||
}
|
||||
@@ -316,11 +315,18 @@ void CodeController::handleMessage(MessageCodeViewExpandedInitialFiles* message)
|
||||
getView()->scrollToValue(m_scrollToValue, m_scrollInListMode);
|
||||
m_scrollToValue = -1;
|
||||
}
|
||||
|
||||
if (m_scrollToLine)
|
||||
{
|
||||
getView()->scrollToLine(m_scrollToFilePath, m_scrollToLine);
|
||||
m_scrollToLine = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void CodeController::handleMessage(MessageScrollToLine* message)
|
||||
{
|
||||
getView()->scrollToLine(message->filePath, message->line);
|
||||
m_scrollToFilePath = message->filePath;
|
||||
m_scrollToLine = message->line;
|
||||
|
||||
if (message->isModified)
|
||||
{
|
||||
@@ -355,7 +361,7 @@ void CodeController::handleMessage(MessageShowErrors* message)
|
||||
if (!view->showsErrors() || !message->errorId)
|
||||
{
|
||||
std::vector<ErrorInfo> errors;
|
||||
m_collection = m_storageAccess->getErrorTokenLocations(&errors);
|
||||
m_collection = m_storageAccess->getErrorSourceLocations(&errors);
|
||||
std::vector<CodeSnippetParams> snippets = getSnippetsForCollection(m_collection);
|
||||
|
||||
view->clear();
|
||||
@@ -388,18 +394,18 @@ void CodeController::handleMessage(MessageShowScope* message)
|
||||
{
|
||||
TRACE("code scope");
|
||||
|
||||
std::shared_ptr<TokenLocationCollection> collection =
|
||||
m_storageAccess->getTokenLocationsForLocationIds(std::vector<Id>(1, message->scopeLocationId));
|
||||
std::shared_ptr<SourceLocationCollection> collection =
|
||||
m_storageAccess->getSourceLocationsForLocationIds({message->scopeLocationId});
|
||||
|
||||
TokenLocation* location = collection->findTokenLocationById(message->scopeLocationId);
|
||||
if (!location || !location->isScopeTokenLocation() || !location->getOtherTokenLocation())
|
||||
SourceLocation* location = collection->getSourceLocationById(message->scopeLocationId);
|
||||
if (!location || !location->isScopeLocation() || !location->getOtherLocation())
|
||||
{
|
||||
LOG_ERROR("MessageShowScope did not contain a valid scope location id");
|
||||
return;
|
||||
}
|
||||
|
||||
std::vector<CodeSnippetParams> snippets =
|
||||
getSnippetsForFile(collection->getTokenLocationFiles().begin()->second, true);
|
||||
getSnippetsForFile(collection->getSourceLocationFiles().begin()->second, true);
|
||||
if (snippets.size() != 1)
|
||||
{
|
||||
LOG_ERROR("MessageShowScope didn't result in one single snippet to be created");
|
||||
@@ -408,19 +414,19 @@ void CodeController::handleMessage(MessageShowScope* message)
|
||||
|
||||
if (message->showErrors)
|
||||
{
|
||||
snippets[0].locationFile = m_collection->getTokenLocationFileByPath(snippets[0].locationFile->getFilePath());
|
||||
snippets[0].locationFile = m_collection->getSourceLocationFileByPath(snippets[0].locationFile->getFilePath());
|
||||
}
|
||||
else
|
||||
{
|
||||
TokenLocationFile* activeLocations =
|
||||
m_collection->findTokenLocationFileByPath(snippets[0].locationFile->getFilePath());
|
||||
SourceLocationFile* activeLocations =
|
||||
m_collection->getSourceLocationFileByPath(snippets[0].locationFile->getFilePath()).get();
|
||||
if (activeLocations)
|
||||
{
|
||||
std::shared_ptr<TokenLocationFile> file = snippets[0].locationFile;
|
||||
activeLocations->forEachTokenLocation(
|
||||
[&file](TokenLocation* location)
|
||||
std::shared_ptr<SourceLocationFile> file = snippets[0].locationFile;
|
||||
activeLocations->forEachSourceLocation(
|
||||
[&file](SourceLocation* location)
|
||||
{
|
||||
file->addTokenLocationAsPlainCopy(location);
|
||||
file->addSourceLocationCopy(location);
|
||||
}
|
||||
);
|
||||
}
|
||||
@@ -451,27 +457,32 @@ void CodeController::showContents(MessageBase* message)
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<CodeSnippetParams> CodeController::getSnippetsForActiveTokenLocations(
|
||||
const TokenLocationCollection* collection, Id declarationId
|
||||
std::vector<CodeSnippetParams> CodeController::getSnippetsForActiveSourceLocations(
|
||||
const SourceLocationCollection* collection, Id declarationId
|
||||
) const {
|
||||
TRACE();
|
||||
|
||||
std::vector<CodeSnippetParams> snippets;
|
||||
collection->forEachTokenLocationFile(
|
||||
[&](std::shared_ptr<TokenLocationFile> file) -> void
|
||||
collection->forEachSourceLocationFile(
|
||||
[&](std::shared_ptr<SourceLocationFile> file) -> void
|
||||
{
|
||||
bool isDeclarationFile = false;
|
||||
bool isDefinitionFile = false;
|
||||
file->forEachTokenLocation(
|
||||
[&](TokenLocation* location)
|
||||
file->forEachSourceLocation(
|
||||
[&](SourceLocation* location)
|
||||
{
|
||||
if (location->getTokenId() == declarationId)
|
||||
for (Id i : location->getTokenIds())
|
||||
{
|
||||
isDeclarationFile = true;
|
||||
|
||||
if (location->getType() == LOCATION_SCOPE)
|
||||
if (i == declarationId)
|
||||
{
|
||||
isDefinitionFile = true;
|
||||
isDeclarationFile = true;
|
||||
|
||||
if (location->getType() == LOCATION_SCOPE)
|
||||
{
|
||||
isDefinitionFile = true;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -479,7 +490,7 @@ std::vector<CodeSnippetParams> CodeController::getSnippetsForActiveTokenLocation
|
||||
|
||||
CodeSnippetParams params;
|
||||
params.locationFile = file;
|
||||
params.refCount = file->getUnscopedStartTokenLocationCount();
|
||||
params.refCount = file->getUnscopedStartLocationCount();
|
||||
|
||||
params.isDeclaration = isDeclarationFile;
|
||||
params.isDefinition = isDefinitionFile;
|
||||
@@ -497,17 +508,17 @@ std::vector<CodeSnippetParams> CodeController::getSnippetsForActiveTokenLocation
|
||||
}
|
||||
|
||||
std::vector<CodeSnippetParams> CodeController::getSnippetsForCollection(
|
||||
std::shared_ptr<TokenLocationCollection> collection, bool addTokenLocations
|
||||
std::shared_ptr<SourceLocationCollection> collection, bool addSourceLocations
|
||||
) const
|
||||
{
|
||||
std::vector<CodeSnippetParams> snippets;
|
||||
|
||||
collection->forEachTokenLocationFile(
|
||||
[&](std::shared_ptr<TokenLocationFile> file) -> void
|
||||
collection->forEachSourceLocationFile(
|
||||
[&](std::shared_ptr<SourceLocationFile> file) -> void
|
||||
{
|
||||
CodeSnippetParams params;
|
||||
params.locationFile = file;
|
||||
params.refCount = file->getUnscopedStartTokenLocationCount();
|
||||
params.refCount = file->getUnscopedStartLocationCount();
|
||||
|
||||
params.isCollapsed = true;
|
||||
snippets.push_back(params);
|
||||
@@ -520,39 +531,19 @@ std::vector<CodeSnippetParams> CodeController::getSnippetsForCollection(
|
||||
}
|
||||
|
||||
std::vector<CodeSnippetParams> CodeController::getSnippetsForFile(
|
||||
std::shared_ptr<TokenLocationFile> activeTokenLocations, bool addTokenLocations
|
||||
std::shared_ptr<SourceLocationFile> activeSourceLocations, bool addSourceLocations
|
||||
) const
|
||||
{
|
||||
TRACE();
|
||||
|
||||
std::shared_ptr<TextAccess> textAccess = m_storageAccess->getFileContent(activeTokenLocations->getFilePath());
|
||||
std::shared_ptr<TokenLocationFile> scopeLocations
|
||||
= std::make_shared<TokenLocationFile>(activeTokenLocations->getFilePath().str());
|
||||
|
||||
std::shared_ptr<TokenLocationFile> fileLocations =
|
||||
m_storageAccess->getTokenLocationsForFile(activeTokenLocations->getFilePath().str());
|
||||
|
||||
fileLocations->forEachStartTokenLocation(
|
||||
[&](TokenLocation* startLoc) -> void
|
||||
{
|
||||
if (startLoc->getType() == LOCATION_SCOPE)
|
||||
{
|
||||
TokenLocation* endLoc = startLoc->getOtherTokenLocation();
|
||||
TokenLocation* scopeLoc = scopeLocations->addTokenLocation(
|
||||
startLoc->getId(),
|
||||
startLoc->getTokenId(),
|
||||
startLoc->getLineNumber(),
|
||||
startLoc->getColumnNumber(),
|
||||
endLoc->getLineNumber(),
|
||||
endLoc->getColumnNumber());
|
||||
scopeLoc->setType(LOCATION_SCOPE);
|
||||
}
|
||||
}
|
||||
);
|
||||
std::shared_ptr<SourceLocationFile> fileLocations =
|
||||
m_storageAccess->getSourceLocationsForFile(activeSourceLocations->getFilePath());
|
||||
std::shared_ptr<SourceLocationFile> scopeLocations = fileLocations->getFilteredByType(LOCATION_SCOPE);
|
||||
|
||||
std::shared_ptr<TextAccess> textAccess = m_storageAccess->getFileContent(activeSourceLocations->getFilePath());
|
||||
std::deque<SnippetMerger::Range> ranges;
|
||||
|
||||
if (activeTokenLocations->isWholeCopy)
|
||||
if (activeSourceLocations->isWhole())
|
||||
{
|
||||
ranges.push_back(SnippetMerger::Range(
|
||||
SnippetMerger::Border(1, true),
|
||||
@@ -563,20 +554,20 @@ std::vector<CodeSnippetParams> CodeController::getSnippetsForFile(
|
||||
{
|
||||
SnippetMerger fileScopedMerger(1, textAccess->getLineCount());
|
||||
std::map<int, std::shared_ptr<SnippetMerger>> mergers;
|
||||
activeTokenLocations->forEachStartTokenLocation(
|
||||
[&](TokenLocation* location)
|
||||
activeSourceLocations->forEachStartSourceLocation(
|
||||
[&](SourceLocation* location)
|
||||
{
|
||||
buildMergerHierarchy(location, scopeLocations, fileScopedMerger, mergers);
|
||||
}
|
||||
);
|
||||
|
||||
std::vector<SnippetMerger::Range> atomicRanges;
|
||||
m_storageAccess->getCommentLocationsInFile(activeTokenLocations->getFilePath())->forEachStartTokenLocation(
|
||||
[&](TokenLocation* location)
|
||||
m_storageAccess->getCommentLocationsInFile(activeSourceLocations->getFilePath())->forEachStartSourceLocation(
|
||||
[&](SourceLocation* location)
|
||||
{
|
||||
atomicRanges.push_back(SnippetMerger::Range(
|
||||
SnippetMerger::Border(location->getLineNumber(), false),
|
||||
SnippetMerger::Border(location->getOtherTokenLocation()->getLineNumber(), false)
|
||||
SnippetMerger::Border(location->getOtherLocation()->getLineNumber(), false)
|
||||
));
|
||||
}
|
||||
);
|
||||
@@ -591,57 +582,55 @@ std::vector<CodeSnippetParams> CodeController::getSnippetsForFile(
|
||||
for (const SnippetMerger::Range& range: ranges)
|
||||
{
|
||||
CodeSnippetParams params;
|
||||
params.locationFile = activeTokenLocations;
|
||||
params.refCount = activeTokenLocations->getUnscopedStartTokenLocationCount();
|
||||
params.refCount = activeSourceLocations->getUnscopedStartLocationCount();
|
||||
|
||||
params.startLineNumber = std::max<int>(1, range.start.row - (range.start.strong ? 0 : snippetExpandRange));
|
||||
params.endLineNumber =
|
||||
std::min<int>(textAccess->getLineCount(), range.end.row + (range.end.strong ? 0 : snippetExpandRange));
|
||||
|
||||
std::shared_ptr<TokenLocationFile> tempFile =
|
||||
fileLocations->getFilteredByLines(params.startLineNumber, params.endLineNumber);
|
||||
TokenLocationLine* firstUsedLine = nullptr;
|
||||
for (size_t i = params.startLineNumber; i <= params.endLineNumber && firstUsedLine == nullptr; i++)
|
||||
{
|
||||
firstUsedLine = tempFile->findTokenLocationLineByNumber(i);
|
||||
}
|
||||
|
||||
params.locationFile = activeSourceLocations->getFilteredByLines(params.startLineNumber, params.endLineNumber);
|
||||
params.titleId = 0;
|
||||
if (firstUsedLine && firstUsedLine->getTokenLocations().size())
|
||||
params.footerId = 0;
|
||||
|
||||
std::shared_ptr<SourceLocationFile> tempFile =
|
||||
fileLocations->getFilteredByLines(params.startLineNumber, params.endLineNumber);
|
||||
|
||||
const SourceLocation* firstSourceLocation =
|
||||
tempFile->getSourceLocations().size() ? tempFile->getSourceLocations().begin()->get() : nullptr;
|
||||
|
||||
if (firstSourceLocation)
|
||||
{
|
||||
getTokenLocationOfParentScope(
|
||||
firstUsedLine->getTokenLocations().begin()->second.get(),
|
||||
scopeLocations
|
||||
)->forEachStartTokenLocation( // this TokenLocationFile only contains a single StartTokenLocation.
|
||||
[&](TokenLocation* location)
|
||||
// this SourceLocationFile only contains a single StartSourceLocation.
|
||||
getSourceLocationOfParentScope(firstSourceLocation, scopeLocations)->forEachStartSourceLocation(
|
||||
[&](SourceLocation* location)
|
||||
{
|
||||
params.title = m_storageAccess->getNameHierarchyForNodeId(location->getTokenId()).getQualifiedName();
|
||||
params.titleId = location->getId();
|
||||
if (location->getTokenIds().size())
|
||||
{
|
||||
params.title = m_storageAccess->getNameHierarchyForNodeId(location->getTokenIds()[0]).getQualifiedName();
|
||||
params.titleId = location->getLocationId();
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
if (!activeTokenLocations->isWholeCopy && params.titleId == 0)
|
||||
if (!activeSourceLocations->isWhole() && params.titleId == 0)
|
||||
{
|
||||
params.title = activeTokenLocations->getFilePath().str();
|
||||
params.title = activeSourceLocations->getFilePath().str();
|
||||
}
|
||||
|
||||
TokenLocationLine* lastUsedLine = nullptr;
|
||||
for (size_t i = params.endLineNumber; i >= params.startLineNumber && lastUsedLine == nullptr; i--)
|
||||
const SourceLocation* lastSourceLocation =
|
||||
tempFile->getSourceLocations().size() ? tempFile->getSourceLocations().rbegin()->get() : nullptr;
|
||||
if (lastSourceLocation)
|
||||
{
|
||||
lastUsedLine = tempFile->findTokenLocationLineByNumber(i);
|
||||
}
|
||||
|
||||
params.footerId = 0;
|
||||
if (lastUsedLine && lastUsedLine->getTokenLocations().size())
|
||||
{
|
||||
getTokenLocationOfParentScope(
|
||||
lastUsedLine->getTokenLocations().begin()->second.get(),
|
||||
scopeLocations
|
||||
)->forEachStartTokenLocation( // this TokenLocationFile only contains a single StartTokenLocation.
|
||||
[&](TokenLocation* location)
|
||||
// this SourceLocationFile only contains a single StartSourceLocation.
|
||||
getSourceLocationOfParentScope(lastSourceLocation, scopeLocations)->forEachStartSourceLocation(
|
||||
[&](SourceLocation* location)
|
||||
{
|
||||
params.footer = m_storageAccess->getNameHierarchyForNodeId(location->getTokenId()).getQualifiedName();
|
||||
params.footerId = location->getId();
|
||||
if (location->getTokenIds().size())
|
||||
{
|
||||
params.footer = m_storageAccess->getNameHierarchyForNodeId(location->getTokenIds()[0]).getQualifiedName();
|
||||
params.footerId = location->getLocationId();
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
@@ -654,17 +643,17 @@ std::vector<CodeSnippetParams> CodeController::getSnippetsForFile(
|
||||
snippets.push_back(params);
|
||||
}
|
||||
|
||||
if (addTokenLocations && !activeTokenLocations->isWholeCopy)
|
||||
if (addSourceLocations && !activeSourceLocations->isWhole())
|
||||
{
|
||||
for (CodeSnippetParams& params : snippets)
|
||||
{
|
||||
std::shared_ptr<TokenLocationFile> lines =
|
||||
std::shared_ptr<SourceLocationFile> lines =
|
||||
fileLocations->getFilteredByLines(params.startLineNumber, params.endLineNumber);
|
||||
|
||||
params.locationFile->forEachTokenLocation(
|
||||
[&lines](TokenLocation* location)
|
||||
params.locationFile->forEachSourceLocation(
|
||||
[&lines](SourceLocation* location)
|
||||
{
|
||||
lines->addTokenLocationAsPlainCopy(location);
|
||||
lines->addSourceLocationCopy(location);
|
||||
}
|
||||
);
|
||||
|
||||
@@ -676,34 +665,33 @@ std::vector<CodeSnippetParams> CodeController::getSnippetsForFile(
|
||||
}
|
||||
|
||||
std::shared_ptr<SnippetMerger> CodeController::buildMergerHierarchy(
|
||||
TokenLocation* location,
|
||||
std::shared_ptr<TokenLocationFile> scopeLocations,
|
||||
SourceLocation* location,
|
||||
std::shared_ptr<SourceLocationFile> scopeLocations,
|
||||
SnippetMerger& fileScopedMerger,
|
||||
std::map<int, std::shared_ptr<SnippetMerger>>& mergers
|
||||
) const
|
||||
{
|
||||
const TokenLocation* currentLocation = location;
|
||||
std::shared_ptr<SnippetMerger> currentMerger = std::make_shared<SnippetMerger>(
|
||||
currentLocation->getStartTokenLocation()->getLineNumber(),
|
||||
currentLocation->getEndTokenLocation()->getLineNumber()
|
||||
location->getStartLocation()->getLineNumber(),
|
||||
location->getEndLocation()->getLineNumber()
|
||||
);
|
||||
|
||||
std::shared_ptr<TokenLocationFile> locationFile = getTokenLocationOfParentScope(currentLocation, scopeLocations);
|
||||
if (locationFile->getTokenLocationLineCount() == 0)
|
||||
std::shared_ptr<SourceLocationFile> locationFile = getSourceLocationOfParentScope(location, scopeLocations);
|
||||
if (locationFile->getSourceLocationCount() == 0)
|
||||
{
|
||||
fileScopedMerger.addChild(currentMerger);
|
||||
return currentMerger;
|
||||
}
|
||||
|
||||
std::shared_ptr<SnippetMerger> nextMerger;
|
||||
locationFile->forEachStartTokenLocation( // contains just 1 start location
|
||||
[&](TokenLocation* scopeLocation)
|
||||
locationFile->forEachStartSourceLocation( // contains just 1 start location
|
||||
[&](SourceLocation* scopeLocation)
|
||||
{
|
||||
std::map<int, std::shared_ptr<SnippetMerger>>::iterator it = mergers.find(scopeLocation->getId());
|
||||
std::map<int, std::shared_ptr<SnippetMerger>>::iterator it = mergers.find(scopeLocation->getLocationId());
|
||||
if (it == mergers.end())
|
||||
{
|
||||
nextMerger = buildMergerHierarchy(scopeLocation, scopeLocations, fileScopedMerger, mergers);
|
||||
mergers[scopeLocation->getId()] = nextMerger;
|
||||
mergers[scopeLocation->getLocationId()] = nextMerger;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -715,44 +703,43 @@ std::shared_ptr<SnippetMerger> CodeController::buildMergerHierarchy(
|
||||
return currentMerger;
|
||||
}
|
||||
|
||||
std::shared_ptr<TokenLocationFile> CodeController::getTokenLocationOfParentScope(
|
||||
const TokenLocation* location,
|
||||
std::shared_ptr<TokenLocationFile> scopeLocations
|
||||
std::shared_ptr<SourceLocationFile> CodeController::getSourceLocationOfParentScope(
|
||||
const SourceLocation* location,
|
||||
std::shared_ptr<SourceLocationFile> scopeLocations
|
||||
) const
|
||||
{
|
||||
const TokenLocation* parent = location;
|
||||
const FilePath filePath = location->getFilePath();
|
||||
const SourceLocation* parent = nullptr;
|
||||
|
||||
scopeLocations->forEachStartTokenLocation(
|
||||
[&](TokenLocation* tokenLocation) -> void
|
||||
scopeLocations->forEachStartSourceLocation(
|
||||
[&](SourceLocation* scopeLocation) -> void
|
||||
{
|
||||
if ((*tokenLocation) < *(location->getStartTokenLocation()) &&
|
||||
(*tokenLocation->getEndTokenLocation()) > *(location->getEndTokenLocation()))
|
||||
if (location->getStartLocation() && *scopeLocation == *location->getStartLocation() &&
|
||||
location->getEndLocation() && *scopeLocation->getEndLocation() == *location->getEndLocation())
|
||||
{
|
||||
if (parent == location)
|
||||
{
|
||||
parent = tokenLocation;
|
||||
}
|
||||
// since tokenLocation is a start location the > location indicates the scope
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(*scopeLocation > *location) &&
|
||||
!(*scopeLocation->getEndLocation() < *location) &&
|
||||
// since scopeLocation is a start location the > location indicates the scope
|
||||
// that is closer to the child.
|
||||
else if ((*tokenLocation) > *parent)
|
||||
{
|
||||
parent = tokenLocation;
|
||||
}
|
||||
(!parent || *scopeLocation > *parent))
|
||||
{
|
||||
parent = scopeLocation;
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
std::shared_ptr<TokenLocationFile> file = std::make_shared<TokenLocationFile>(filePath);
|
||||
if (parent != location)
|
||||
std::shared_ptr<SourceLocationFile> file = std::make_shared<SourceLocationFile>(location->getFilePath(), false);
|
||||
if (parent)
|
||||
{
|
||||
file->addTokenLocationAsPlainCopy(parent);
|
||||
file->addTokenLocationAsPlainCopy(parent->getOtherTokenLocation());
|
||||
file->addSourceLocationCopy(parent);
|
||||
file->addSourceLocationCopy(parent->getOtherLocation());
|
||||
}
|
||||
return file;
|
||||
}
|
||||
|
||||
std::vector<std::string> CodeController::getProjectDescription(TokenLocationFile* locationFile) const
|
||||
std::vector<std::string> CodeController::getProjectDescription(SourceLocationFile* locationFile) const
|
||||
{
|
||||
Project* currentProject = Application::getInstance()->getCurrentProject().get();
|
||||
if (!currentProject)
|
||||
@@ -797,8 +784,8 @@ std::vector<std::string> CodeController::getProjectDescription(TokenLocationFile
|
||||
if (tokenId > 0)
|
||||
{
|
||||
line.replace(posA, posB - posA + 1, nameString);
|
||||
locationFile->addTokenLocation(
|
||||
0, tokenId,
|
||||
locationFile->addSourceLocation(
|
||||
LOCATION_TOKEN, 0, {tokenId},
|
||||
startLineNumber + i, posA + 1,
|
||||
startLineNumber + i, posA + nameString.size()
|
||||
);
|
||||
|
||||
@@ -27,9 +27,9 @@
|
||||
#include "component/view/CodeView.h"
|
||||
|
||||
class StorageAccess;
|
||||
class TokenLocation;
|
||||
class TokenLocationCollection;
|
||||
class TokenLocationFile;
|
||||
class SourceLocation;
|
||||
class SourceLocationCollection;
|
||||
class SourceLocationFile;
|
||||
|
||||
class CodeController
|
||||
: public Controller
|
||||
@@ -78,29 +78,31 @@ private:
|
||||
|
||||
void showContents(MessageBase* message);
|
||||
|
||||
std::vector<CodeSnippetParams> getSnippetsForActiveTokenLocations(
|
||||
const TokenLocationCollection* collection, Id declarationId) const;
|
||||
std::vector<CodeSnippetParams> getSnippetsForActiveSourceLocations(
|
||||
const SourceLocationCollection* collection, Id declarationId) const;
|
||||
std::vector<CodeSnippetParams> getSnippetsForCollection(
|
||||
std::shared_ptr<TokenLocationCollection> collection, bool addTokenLocations = false) const;
|
||||
std::shared_ptr<SourceLocationCollection> collection, bool addSourceLocations = false) const;
|
||||
std::vector<CodeSnippetParams> getSnippetsForFile(
|
||||
std::shared_ptr<TokenLocationFile> file, bool addTokenLocations = false) const;
|
||||
std::shared_ptr<SourceLocationFile> file, bool addSourceLocations = false) const;
|
||||
|
||||
std::shared_ptr<SnippetMerger> buildMergerHierarchy(
|
||||
TokenLocation* location, std::shared_ptr<TokenLocationFile> context, SnippetMerger& fileScopedMerger,
|
||||
SourceLocation* location, std::shared_ptr<SourceLocationFile> context, SnippetMerger& fileScopedMerger,
|
||||
std::map<int, std::shared_ptr<SnippetMerger>>& mergers) const;
|
||||
std::shared_ptr<TokenLocationFile> getTokenLocationOfParentScope(
|
||||
const TokenLocation* location, std::shared_ptr<TokenLocationFile> context) const;
|
||||
std::shared_ptr<SourceLocationFile> getSourceLocationOfParentScope(
|
||||
const SourceLocation* location, std::shared_ptr<SourceLocationFile> context) const;
|
||||
|
||||
std::vector<std::string> getProjectDescription(TokenLocationFile* locationFile) const;
|
||||
std::vector<std::string> getProjectDescription(SourceLocationFile* locationFile) const;
|
||||
|
||||
void addModificationTimes(std::vector<CodeSnippetParams>& snippets) const;
|
||||
|
||||
StorageAccess* m_storageAccess;
|
||||
mutable std::shared_ptr<TokenLocationCollection> m_collection;
|
||||
mutable std::shared_ptr<SourceLocationCollection> m_collection;
|
||||
|
||||
bool m_scrollToDefinition;
|
||||
int m_scrollToValue;
|
||||
bool m_scrollInListMode;
|
||||
FilePath m_scrollToFilePath;
|
||||
size_t m_scrollToLine;
|
||||
};
|
||||
|
||||
#endif // CODE_CONTROLLER_H
|
||||
|
||||
@@ -1,12 +1,7 @@
|
||||
#include "IDECommunicationController.h"
|
||||
|
||||
#include "data/access/StorageAccess.h"
|
||||
#include "data/location/TokenLocationFile.h"
|
||||
#include "data/location/TokenLocation.h"
|
||||
#include "settings/ApplicationSettings.h"
|
||||
|
||||
#include "utility/file/FileSystem.h"
|
||||
#include "utility/messaging/type/MessageActivateTokenLocations.h"
|
||||
#include "utility/messaging/type/MessageActivateSourceLocations.h"
|
||||
#include "utility/messaging/type/MessageActivateWindow.h"
|
||||
#include "utility/messaging/type/MessageDispatchWhenLicenseValid.h"
|
||||
#include "utility/messaging/type/MessageProjectNew.h"
|
||||
@@ -14,6 +9,10 @@
|
||||
#include "utility/messaging/type/MessageActivateFile.h"
|
||||
#include "utility/messaging/type/MessagePingReceived.h"
|
||||
|
||||
#include "data/access/StorageAccess.h"
|
||||
#include "data/location/SourceLocationFile.h"
|
||||
#include "settings/ApplicationSettings.h"
|
||||
|
||||
IDECommunicationController::IDECommunicationController(StorageAccess* storageAccess)
|
||||
: m_storageAccess(storageAccess)
|
||||
, m_enabled(true)
|
||||
@@ -86,21 +85,22 @@ void IDECommunicationController::handleSetActiveTokenMessage(
|
||||
== m_storageAccess->getFileInfoForFilePath(message.fileLocation).lastWriteTime)
|
||||
{
|
||||
// file was not modified
|
||||
std::shared_ptr<TokenLocationFile> tokenLocationFile = m_storageAccess->getTokenLocationsForLinesInFile(
|
||||
std::shared_ptr<SourceLocationFile> sourceLocationFile = m_storageAccess->getSourceLocationsForLinesInFile(
|
||||
message.fileLocation, message.row, message.row
|
||||
);
|
||||
|
||||
std::vector<Id> selectedLocationIds;
|
||||
tokenLocationFile->forEachStartTokenLocation(
|
||||
[&](TokenLocation* startLocation)
|
||||
sourceLocationFile->forEachStartSourceLocation(
|
||||
[&selectedLocationIds, &cursorColumn](SourceLocation* startLocation)
|
||||
{
|
||||
TokenLocation* endLocation = startLocation->getEndTokenLocation();
|
||||
const SourceLocation* endLocation = startLocation->getEndLocation();
|
||||
|
||||
if (!startLocation->isScopeTokenLocation()
|
||||
if (!startLocation->isScopeLocation()
|
||||
&& startLocation->getLineNumber() == endLocation->getLineNumber()
|
||||
&& startLocation->getColumnNumber() <= cursorColumn
|
||||
&& endLocation->getColumnNumber() + 1 >= cursorColumn)
|
||||
{
|
||||
selectedLocationIds.push_back(startLocation->getId());
|
||||
selectedLocationIds.push_back(startLocation->getLocationId());
|
||||
}
|
||||
}
|
||||
);
|
||||
@@ -110,7 +110,7 @@ void IDECommunicationController::handleSetActiveTokenMessage(
|
||||
MessageStatus("Activating source location from plug-in succeeded: " + message.fileLocation + ", row: " +
|
||||
std::to_string(message.row) + ", col: " + std::to_string(message.column)).dispatch();
|
||||
|
||||
MessageActivateTokenLocations(selectedLocationIds).dispatch();
|
||||
MessageActivateSourceLocations(selectedLocationIds).dispatch();
|
||||
MessageActivateWindow().dispatch();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
#include "component/view/View.h"
|
||||
|
||||
class CodeController;
|
||||
class TokenLocationCollection;
|
||||
class SourceLocationCollection;
|
||||
|
||||
class CodeView
|
||||
: public View
|
||||
@@ -41,7 +41,7 @@ public:
|
||||
virtual void setFileState(const FilePath filePath, FileState state) = 0;
|
||||
|
||||
virtual void showActiveSnippet(
|
||||
const std::vector<Id>& activeTokenIds, std::shared_ptr<TokenLocationCollection> collection, bool scrollTo) = 0;
|
||||
const std::vector<Id>& activeTokenIds, std::shared_ptr<SourceLocationCollection> collection, bool scrollTo) = 0;
|
||||
virtual void showActiveTokenIds(const std::vector<Id>& activeTokenIds) = 0;
|
||||
virtual void showActiveLocalSymbolIds(const std::vector<Id>& activeLocalSymbolIds) = 0;
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#include "component/view/helper/CodeSnippetParams.h"
|
||||
|
||||
#include "data/location/TokenLocationFile.h"
|
||||
#include "data/location/SourceLocationFile.h"
|
||||
|
||||
CodeSnippetParams::CodeSnippetParams()
|
||||
: startLineNumber(0)
|
||||
@@ -39,11 +39,11 @@ bool CodeSnippetParams::sort(const CodeSnippetParams& a, const CodeSnippetParams
|
||||
}
|
||||
|
||||
// sort whole files
|
||||
if (a.locationFile->isWholeCopy && !b.locationFile->isWholeCopy)
|
||||
if (a.locationFile->isWhole() && !b.locationFile->isWhole())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else if (!a.locationFile->isWholeCopy && b.locationFile->isWholeCopy)
|
||||
else if (!a.locationFile->isWhole() && b.locationFile->isWhole())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#include "utility/TimePoint.h"
|
||||
#include "utility/types.h"
|
||||
|
||||
class TokenLocationFile;
|
||||
class SourceLocationFile;
|
||||
|
||||
struct CodeSnippetParams
|
||||
{
|
||||
@@ -26,7 +26,7 @@ struct CodeSnippetParams
|
||||
Id footerId;
|
||||
TimePoint modificationTime;
|
||||
|
||||
std::shared_ptr<TokenLocationFile> locationFile;
|
||||
std::shared_ptr<SourceLocationFile> locationFile;
|
||||
|
||||
int refCount;
|
||||
|
||||
|
||||
@@ -20,9 +20,8 @@
|
||||
#include "data/graph/token_component/TokenComponentFilePath.h"
|
||||
#include "data/graph/token_component/TokenComponentSignature.h"
|
||||
#include "data/graph/Graph.h"
|
||||
#include "data/location/TokenLocation.h"
|
||||
#include "data/location/TokenLocationFile.h"
|
||||
#include "data/location/TokenLocationLine.h"
|
||||
#include "data/location/SourceLocationCollection.h"
|
||||
#include "data/location/SourceLocationFile.h"
|
||||
#include "data/parser/ParseLocation.h"
|
||||
|
||||
PersistentStorage::PersistentStorage(const FilePath& dbPath)
|
||||
@@ -530,13 +529,13 @@ bool PersistentStorage::checkEdgeExists(Id edgeId) const
|
||||
return m_sqliteStorage.checkEdgeExists(edgeId);
|
||||
}
|
||||
|
||||
std::shared_ptr<TokenLocationCollection> PersistentStorage::getFullTextSearchLocations(
|
||||
std::shared_ptr<SourceLocationCollection> PersistentStorage::getFullTextSearchLocations(
|
||||
const std::string& searchTerm, bool caseSensitive
|
||||
) const
|
||||
{
|
||||
TRACE();
|
||||
|
||||
std::shared_ptr<TokenLocationCollection> collection = std::make_shared<TokenLocationCollection>();
|
||||
std::shared_ptr<SourceLocationCollection> collection = std::make_shared<SourceLocationCollection>();
|
||||
if (!searchTerm.size())
|
||||
{
|
||||
return collection;
|
||||
@@ -554,20 +553,17 @@ std::shared_ptr<TokenLocationCollection> PersistentStorage::getFullTextSearchLoc
|
||||
).dispatch();
|
||||
|
||||
std::vector<FullTextSearchResult> hits = m_fullTextSearchIndex.searchForTerm(searchTerm);
|
||||
|
||||
int termLength = searchTerm.length();
|
||||
FilePath filepath;
|
||||
std::shared_ptr<TextAccess> file;
|
||||
ParseLocation location;
|
||||
|
||||
for (size_t i = 0; i < hits.size(); i++)
|
||||
{
|
||||
filepath = getFileNodePath(hits[i].fileId);
|
||||
file = getFileContent(filepath);
|
||||
FilePath filePath = getFileNodePath(hits[i].fileId);
|
||||
std::shared_ptr<TextAccess> fileContent = getFileContent(filePath);
|
||||
|
||||
int charsInPreviousLines = 0;
|
||||
int lineNumber = 1;
|
||||
std::string line;
|
||||
line = file->getLine(lineNumber);
|
||||
line = fileContent->getLine(lineNumber);
|
||||
|
||||
for (int pos : hits[i].positions)
|
||||
{
|
||||
@@ -576,8 +572,10 @@ std::shared_ptr<TokenLocationCollection> PersistentStorage::getFullTextSearchLoc
|
||||
{
|
||||
lineNumber++;
|
||||
charsInPreviousLines += line.length();
|
||||
line = file->getLine(lineNumber);
|
||||
line = fileContent->getLine(lineNumber);
|
||||
}
|
||||
|
||||
ParseLocation location;
|
||||
location.startLineNumber = lineNumber;
|
||||
location.startColumnNumber = pos - charsInPreviousLines + 1;
|
||||
|
||||
@@ -593,7 +591,7 @@ std::shared_ptr<TokenLocationCollection> PersistentStorage::getFullTextSearchLoc
|
||||
{
|
||||
lineNumber++;
|
||||
charsInPreviousLines += line.length();
|
||||
line = file->getLine(lineNumber);
|
||||
line = fileContent->getLine(lineNumber);
|
||||
}
|
||||
|
||||
location.endLineNumber = lineNumber;
|
||||
@@ -602,24 +600,25 @@ std::shared_ptr<TokenLocationCollection> PersistentStorage::getFullTextSearchLoc
|
||||
if ( addHit )
|
||||
{
|
||||
// Set first bit to 1 to avoid collisions
|
||||
Id locationId = ~(~size_t(0) >> 1) + collection->getTokenLocationCount();
|
||||
Id locationId = ~(~size_t(0) >> 1) + collection->getSourceLocationCount();
|
||||
|
||||
collection->addTokenLocation(
|
||||
collection->addSourceLocation(
|
||||
LOCATION_FULLTEXT,
|
||||
locationId,
|
||||
0,
|
||||
filepath,
|
||||
std::vector<Id>(),
|
||||
filePath,
|
||||
location.startLineNumber,
|
||||
location.startColumnNumber,
|
||||
location.endLineNumber,
|
||||
location.endColumnNumber
|
||||
)->setType(LOCATION_FULLTEXT);
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
MessageStatus(
|
||||
std::to_string(collection->getTokenLocationCount()) + " results in " +
|
||||
std::to_string(collection->getTokenLocationFileCount()) + " files for fulltext search (case-" +
|
||||
std::to_string(collection->getSourceLocationCount()) + " results in " +
|
||||
std::to_string(collection->getSourceLocationFileCount()) + " files for fulltext search (case-" +
|
||||
(caseSensitive ? "sensitive" : "insensitive") + "): " + searchTerm,
|
||||
false, false
|
||||
).dispatch();
|
||||
@@ -1085,33 +1084,34 @@ std::vector<Id> PersistentStorage::getNodeIdsForLocationIds(const std::vector<Id
|
||||
return utility::toVector(edgeIds);
|
||||
}
|
||||
|
||||
std::shared_ptr<TokenLocationCollection> PersistentStorage::getTokenLocationsForTokenIds(
|
||||
std::shared_ptr<SourceLocationCollection> PersistentStorage::getSourceLocationsForTokenIds(
|
||||
const std::vector<Id>& tokenIds) const
|
||||
{
|
||||
TRACE();
|
||||
|
||||
std::shared_ptr<TokenLocationCollection> collection = std::make_shared<TokenLocationCollection>();
|
||||
|
||||
std::vector<Id> fileIds;
|
||||
std::vector<Id> nonFileIds;
|
||||
|
||||
for (const Id tokenId : tokenIds)
|
||||
{
|
||||
if (!getFileNodePath(tokenId).empty())
|
||||
{
|
||||
fileIds.push_back(tokenId);
|
||||
}
|
||||
else
|
||||
if (getFileNodePath(tokenId).empty())
|
||||
{
|
||||
nonFileIds.push_back(tokenId);
|
||||
}
|
||||
else
|
||||
{
|
||||
fileIds.push_back(tokenId);
|
||||
}
|
||||
}
|
||||
|
||||
for (StorageFile file: m_sqliteStorage.getAllByIds<StorageFile>(fileIds))
|
||||
std::shared_ptr<SourceLocationCollection> collection = std::make_shared<SourceLocationCollection>();
|
||||
|
||||
for (const StorageFile& file : m_sqliteStorage.getAllByIds<StorageFile>(fileIds))
|
||||
{
|
||||
collection->addTokenLocationFile(m_sqliteStorage.getTokenLocationsForFile(file.filePath));
|
||||
collection->addSourceLocationFile(m_sqliteStorage.getSourceLocationsForFile(file.filePath));
|
||||
}
|
||||
|
||||
if (nonFileIds.size())
|
||||
{
|
||||
std::vector<Id> locationIds;
|
||||
std::unordered_map<Id, Id> locationIdToElementIdMap;
|
||||
@@ -1126,81 +1126,83 @@ std::shared_ptr<TokenLocationCollection> PersistentStorage::getTokenLocationsFor
|
||||
auto it = locationIdToElementIdMap.find(sourceLocation.id);
|
||||
if (it != locationIdToElementIdMap.end())
|
||||
{
|
||||
TokenLocation* tokenLocation = collection->addTokenLocation(
|
||||
collection->addSourceLocation(
|
||||
intToLocationType(sourceLocation.type),
|
||||
sourceLocation.id,
|
||||
it->second,
|
||||
std::vector<Id>(1, it->second),
|
||||
getFileNodePath(sourceLocation.fileNodeId),
|
||||
sourceLocation.startLine,
|
||||
sourceLocation.startCol,
|
||||
sourceLocation.endLine,
|
||||
sourceLocation.endCol
|
||||
);
|
||||
|
||||
if (tokenLocation)
|
||||
{
|
||||
tokenLocation->setType(intToLocationType(sourceLocation.type));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return collection;
|
||||
}
|
||||
|
||||
std::shared_ptr<TokenLocationCollection> PersistentStorage::getTokenLocationsForLocationIds(
|
||||
std::shared_ptr<SourceLocationCollection> PersistentStorage::getSourceLocationsForLocationIds(
|
||||
const std::vector<Id>& locationIds
|
||||
) const
|
||||
{
|
||||
TRACE();
|
||||
|
||||
std::shared_ptr<TokenLocationCollection> collection = std::make_shared<TokenLocationCollection>();
|
||||
std::shared_ptr<SourceLocationCollection> collection = std::make_shared<SourceLocationCollection>();
|
||||
|
||||
for (StorageSourceLocation location: m_sqliteStorage.getAllByIds<StorageSourceLocation>(locationIds))
|
||||
{
|
||||
for (const StorageOccurrence& occurrences: m_sqliteStorage.getOccurrencesForLocationId(location.id))
|
||||
std::vector<Id> elementIds;
|
||||
for (const StorageOccurrence& occurrence: m_sqliteStorage.getOccurrencesForLocationId(location.id))
|
||||
{
|
||||
collection->addTokenLocation(
|
||||
location.id,
|
||||
occurrences.elementId,
|
||||
getFileNodePath(location.fileNodeId),
|
||||
location.startLine,
|
||||
location.startCol,
|
||||
location.endLine,
|
||||
location.endCol
|
||||
)->setType(intToLocationType(location.type));
|
||||
elementIds.push_back(occurrence.elementId);
|
||||
}
|
||||
|
||||
collection->addSourceLocation(
|
||||
intToLocationType(location.type),
|
||||
location.id,
|
||||
elementIds,
|
||||
getFileNodePath(location.fileNodeId),
|
||||
location.startLine,
|
||||
location.startCol,
|
||||
location.endLine,
|
||||
location.endCol
|
||||
);
|
||||
}
|
||||
|
||||
return collection;
|
||||
}
|
||||
|
||||
std::shared_ptr<TokenLocationFile> PersistentStorage::getTokenLocationsForFile(const std::string& filePath) const
|
||||
std::shared_ptr<SourceLocationFile> PersistentStorage::getSourceLocationsForFile(const FilePath& filePath) const
|
||||
{
|
||||
TRACE();
|
||||
|
||||
return m_sqliteStorage.getTokenLocationsForFile(filePath);
|
||||
return m_sqliteStorage.getSourceLocationsForFile(filePath);
|
||||
}
|
||||
|
||||
std::shared_ptr<TokenLocationFile> PersistentStorage::getTokenLocationsForLinesInFile(
|
||||
std::shared_ptr<SourceLocationFile> PersistentStorage::getSourceLocationsForLinesInFile(
|
||||
const std::string& filePath, uint firstLineNumber, uint lastLineNumber
|
||||
) const
|
||||
{
|
||||
TRACE();
|
||||
|
||||
return getTokenLocationsForFile(filePath)->getFilteredByLines(firstLineNumber, lastLineNumber);
|
||||
return getSourceLocationsForFile(filePath)->getFilteredByLines(firstLineNumber, lastLineNumber);
|
||||
}
|
||||
|
||||
std::shared_ptr<TokenLocationFile> PersistentStorage::getCommentLocationsInFile(const FilePath& filePath) const
|
||||
std::shared_ptr<SourceLocationFile> PersistentStorage::getCommentLocationsInFile(const FilePath& filePath) const
|
||||
{
|
||||
TRACE();
|
||||
|
||||
std::shared_ptr<TokenLocationFile> file = std::make_shared<TokenLocationFile>(filePath);
|
||||
std::shared_ptr<SourceLocationFile> file = std::make_shared<SourceLocationFile>(filePath, false);
|
||||
|
||||
std::vector<StorageCommentLocation> storageLocations = m_sqliteStorage.getCommentLocationsInFile(filePath);
|
||||
for (size_t i = 0; i < storageLocations.size(); i++)
|
||||
{
|
||||
file->addTokenLocation(
|
||||
file->addSourceLocation(
|
||||
LOCATION_TOKEN,
|
||||
storageLocations[i].id,
|
||||
0, // comment token location has no element.
|
||||
std::vector<Id>(), // comment token location has no element.
|
||||
storageLocations[i].startLine,
|
||||
storageLocations[i].startCol,
|
||||
storageLocations[i].endLine,
|
||||
@@ -1283,11 +1285,11 @@ std::vector<ErrorInfo> PersistentStorage::getErrors() const
|
||||
return filteredErrors;
|
||||
}
|
||||
|
||||
std::shared_ptr<TokenLocationCollection> PersistentStorage::getErrorTokenLocations(std::vector<ErrorInfo>* errors) const
|
||||
std::shared_ptr<SourceLocationCollection> PersistentStorage::getErrorSourceLocations(std::vector<ErrorInfo>* errors) const
|
||||
{
|
||||
TRACE();
|
||||
|
||||
std::shared_ptr<TokenLocationCollection> errorCollection = std::make_shared<TokenLocationCollection>();
|
||||
std::shared_ptr<SourceLocationCollection> errorCollection = std::make_shared<SourceLocationCollection>();
|
||||
for (const ErrorInfo& error : m_sqliteStorage.getAll<StorageError>())
|
||||
{
|
||||
if (m_errorFilter.filter(error))
|
||||
@@ -1297,9 +1299,16 @@ std::shared_ptr<TokenLocationCollection> PersistentStorage::getErrorTokenLocatio
|
||||
// Set first bit to 1 to avoid collisions
|
||||
Id locationId = ~(~size_t(0) >> 1) + error.id;
|
||||
|
||||
errorCollection->addTokenLocation(
|
||||
locationId, error.id, error.filePath, error.lineNumber, error.columnNumber, error.lineNumber, error.columnNumber
|
||||
)->setType(LOCATION_ERROR);
|
||||
errorCollection->addSourceLocation(
|
||||
LOCATION_ERROR,
|
||||
locationId,
|
||||
std::vector<Id>(1, error.id),
|
||||
error.filePath,
|
||||
error.lineNumber,
|
||||
error.columnNumber,
|
||||
error.lineNumber,
|
||||
error.columnNumber
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
#include "data/access/StorageAccess.h"
|
||||
#include "data/fulltextsearch/FullTextSearchIndex.h"
|
||||
#include "data/graph/token_component/TokenComponentAccess.h"
|
||||
#include "data/location/TokenLocationCollection.h"
|
||||
#include "data/parser/ParserClient.h"
|
||||
#include "data/parser/ParseLocation.h"
|
||||
#include "data/search/SearchIndex.h"
|
||||
@@ -111,8 +110,9 @@ public:
|
||||
virtual StorageEdge getEdgeById(Id edgeId) const;
|
||||
virtual bool checkEdgeExists(Id edgeId) const;
|
||||
|
||||
virtual std::shared_ptr<TokenLocationCollection> getFullTextSearchLocations(
|
||||
const std::string& searchTerm, bool caseSensitive) const;
|
||||
virtual std::shared_ptr<SourceLocationCollection> getFullTextSearchLocations(
|
||||
const std::string& searchTerm, bool caseSensitive) const;
|
||||
|
||||
virtual std::vector<SearchMatch> getAutocompletionMatches(const std::string& query) const;
|
||||
std::vector<SearchMatch> getAutocompletionSymbolMatches(const std::string& query, size_t maxResultsCount) const;
|
||||
std::vector<SearchMatch> getAutocompletionFileMatches(const std::string& query, size_t maxResultsCount) const;
|
||||
@@ -125,18 +125,15 @@ public:
|
||||
virtual std::vector<Id> getActiveTokenIdsForId(Id tokenId, Id* declarationId) const;
|
||||
virtual std::vector<Id> getNodeIdsForLocationIds(const std::vector<Id>& locationIds) const;
|
||||
|
||||
virtual std::shared_ptr<TokenLocationCollection> getTokenLocationsForTokenIds(
|
||||
const std::vector<Id>& tokenIds
|
||||
) const;
|
||||
virtual std::shared_ptr<TokenLocationCollection> getTokenLocationsForLocationIds(
|
||||
const std::vector<Id>& locationIds
|
||||
) const;
|
||||
virtual std::shared_ptr<TokenLocationFile> getTokenLocationsForFile(const std::string& filePath) const;
|
||||
virtual std::shared_ptr<TokenLocationFile> getTokenLocationsForLinesInFile(
|
||||
virtual std::shared_ptr<SourceLocationCollection> getSourceLocationsForTokenIds(const std::vector<Id>& tokenIds) const;
|
||||
virtual std::shared_ptr<SourceLocationCollection> getSourceLocationsForLocationIds(const std::vector<Id>& locationIds) const;
|
||||
|
||||
virtual std::shared_ptr<SourceLocationFile> getSourceLocationsForFile(const FilePath& filePath) const;
|
||||
virtual std::shared_ptr<SourceLocationFile> getSourceLocationsForLinesInFile(
|
||||
const std::string& filePath, uint firstLineNumber, uint lastLineNumber
|
||||
) const;
|
||||
|
||||
virtual std::shared_ptr<TokenLocationFile> getCommentLocationsInFile(const FilePath& filePath) const;
|
||||
virtual std::shared_ptr<SourceLocationFile> getCommentLocationsInFile(const FilePath& filePath) const;
|
||||
|
||||
virtual std::shared_ptr<TextAccess> getFileContent(const FilePath& filePath) const;
|
||||
|
||||
@@ -148,7 +145,7 @@ public:
|
||||
virtual ErrorCountInfo getErrorCount() const;
|
||||
virtual std::vector<ErrorInfo> getErrors() const;
|
||||
|
||||
virtual std::shared_ptr<TokenLocationCollection> getErrorTokenLocations(std::vector<ErrorInfo>* errors) const;
|
||||
virtual std::shared_ptr<SourceLocationCollection> getErrorSourceLocations(std::vector<ErrorInfo>* errors) const;
|
||||
|
||||
private:
|
||||
Id getFileNodeId(const FilePath& filePath) const;
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
#include <unordered_map>
|
||||
|
||||
#include "data/graph/Node.h"
|
||||
#include "data/location/TokenLocation.h"
|
||||
#include "data/parser/ParseLocation.h"
|
||||
#include "utility/logging/logging.h"
|
||||
#include "utility/text/TextAccess.h"
|
||||
@@ -847,9 +846,9 @@ StorageSourceLocation SqliteStorage::getSourceLocationByAll(const Id fileNodeId,
|
||||
);
|
||||
}
|
||||
|
||||
std::shared_ptr<TokenLocationFile> SqliteStorage::getTokenLocationsForFile(const FilePath& filePath) const
|
||||
std::shared_ptr<SourceLocationFile> SqliteStorage::getSourceLocationsForFile(const FilePath& filePath) const
|
||||
{
|
||||
std::shared_ptr<TokenLocationFile> ret = std::make_shared<TokenLocationFile>(filePath);
|
||||
std::shared_ptr<SourceLocationFile> ret = std::make_shared<SourceLocationFile>(filePath, true);
|
||||
|
||||
const Id fileNodeId = getFileByPath(filePath.str()).id;
|
||||
if (fileNodeId == 0) // early out
|
||||
@@ -865,25 +864,29 @@ std::shared_ptr<TokenLocationFile> SqliteStorage::getTokenLocationsForFile(const
|
||||
sourceLocationIdToData[storageLocation.id] = storageLocation;
|
||||
}
|
||||
|
||||
std::map<Id, std::vector<Id>> sourceLocationIdToElementIds;
|
||||
for (const StorageOccurrence& occurrence: getOccurrencesForLocationIds(sourceLocationIds))
|
||||
{
|
||||
auto it = sourceLocationIdToData.find(occurrence.sourceLocationId);
|
||||
sourceLocationIdToElementIds[occurrence.sourceLocationId].push_back(occurrence.elementId);
|
||||
}
|
||||
|
||||
for (const std::pair<Id, std::vector<Id>>& p : sourceLocationIdToElementIds)
|
||||
{
|
||||
auto it = sourceLocationIdToData.find(p.first);
|
||||
if (it != sourceLocationIdToData.end())
|
||||
{
|
||||
TokenLocation* loc = ret->addTokenLocation(
|
||||
it->second.id, //e.first.id,
|
||||
occurrence.elementId,
|
||||
ret->addSourceLocation(
|
||||
intToLocationType(it->second.type),
|
||||
it->second.id,
|
||||
p.second,
|
||||
it->second.startLine,
|
||||
it->second.startCol,
|
||||
it->second.endLine,
|
||||
it->second.endCol
|
||||
);
|
||||
loc->setType(intToLocationType(it->second.type));
|
||||
}
|
||||
}
|
||||
|
||||
ret->isWholeCopy = true;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
@@ -10,8 +10,7 @@
|
||||
#include "data/bookmark/BookmarkCategory.h"
|
||||
#include "data/bookmark/EdgeBookmark.h"
|
||||
#include "data/bookmark/NodeBookmark.h"
|
||||
#include "data/location/TokenLocationFile.h"
|
||||
#include "data/location/TokenLocationCollection.h"
|
||||
#include "data/location/SourceLocationFile.h"
|
||||
#include "data/name/NameHierarchy.h"
|
||||
#include "data/StorageTypes.h"
|
||||
#include "data/SqliteIndex.h"
|
||||
@@ -115,7 +114,7 @@ public:
|
||||
void setNodeType(int type, Id nodeId);
|
||||
|
||||
StorageSourceLocation getSourceLocationByAll(const Id fileNodeId, const uint startLine, const uint startCol, const uint endLine, const uint endCol, const int type) const;
|
||||
std::shared_ptr<TokenLocationFile> getTokenLocationsForFile(const FilePath& filePath) const;
|
||||
std::shared_ptr<SourceLocationFile> getSourceLocationsForFile(const FilePath& filePath) const;
|
||||
|
||||
std::vector<StorageOccurrence> getOccurrencesForLocationId(Id locationId) const;
|
||||
std::vector<StorageOccurrence> getOccurrencesForLocationIds(const std::vector<Id>& locationIds) const;
|
||||
|
||||
@@ -21,10 +21,9 @@
|
||||
#include "data/StorageStats.h"
|
||||
|
||||
class Graph;
|
||||
class SourceLocationCollection;
|
||||
class SourceLocationFile;
|
||||
class TextAccess;
|
||||
class TokenLocation;
|
||||
class TokenLocationCollection;
|
||||
class TokenLocationFile;
|
||||
|
||||
class StorageAccess
|
||||
{
|
||||
@@ -46,7 +45,7 @@ public:
|
||||
virtual StorageEdge getEdgeById(Id edgeId) const = 0;
|
||||
virtual bool checkEdgeExists(Id edgeId) const = 0;
|
||||
|
||||
virtual std::shared_ptr<TokenLocationCollection> getFullTextSearchLocations(
|
||||
virtual std::shared_ptr<SourceLocationCollection> getFullTextSearchLocations(
|
||||
const std::string& searchTerm, bool caseSensitive) const = 0;
|
||||
virtual std::vector<SearchMatch> getAutocompletionMatches(const std::string& query) const = 0;
|
||||
virtual std::vector<SearchMatch> getSearchMatchesForTokenIds(const std::vector<Id>& tokenIds) const = 0;
|
||||
@@ -57,15 +56,15 @@ public:
|
||||
virtual std::vector<Id> getActiveTokenIdsForId(Id tokenId, Id* declarationId) const = 0;
|
||||
virtual std::vector<Id> getNodeIdsForLocationIds(const std::vector<Id>& locationIds) const = 0;
|
||||
|
||||
virtual std::shared_ptr<TokenLocationCollection> getTokenLocationsForTokenIds(
|
||||
const std::vector<Id>& tokenIds) const = 0;
|
||||
virtual std::shared_ptr<TokenLocationCollection> getTokenLocationsForLocationIds(
|
||||
const std::vector<Id>& locationIds) const = 0;
|
||||
virtual std::shared_ptr<TokenLocationFile> getTokenLocationsForFile(const std::string& filePath) const = 0;
|
||||
virtual std::shared_ptr<TokenLocationFile> getTokenLocationsForLinesInFile(
|
||||
virtual std::shared_ptr<SourceLocationCollection> getSourceLocationsForTokenIds(
|
||||
const std::vector<Id>& tokenIds) const = 0;
|
||||
virtual std::shared_ptr<SourceLocationCollection> getSourceLocationsForLocationIds(
|
||||
const std::vector<Id>& locationIds) const = 0;
|
||||
virtual std::shared_ptr<SourceLocationFile> getSourceLocationsForFile(const FilePath& filePath) const = 0;
|
||||
virtual std::shared_ptr<SourceLocationFile> getSourceLocationsForLinesInFile(
|
||||
const std::string& filePath, uint firstLineNumber, uint lastLineNumber) const = 0;
|
||||
|
||||
virtual std::shared_ptr<TokenLocationFile> getCommentLocationsInFile(const FilePath& filePath) const = 0;
|
||||
virtual std::shared_ptr<SourceLocationFile> getCommentLocationsInFile(const FilePath& filePath) const = 0;
|
||||
|
||||
virtual std::shared_ptr<TextAccess> getFileContent(const FilePath& filePath) const = 0;
|
||||
|
||||
@@ -77,7 +76,7 @@ public:
|
||||
virtual ErrorCountInfo getErrorCount() const = 0;
|
||||
virtual std::vector<ErrorInfo> getErrors() const = 0;
|
||||
|
||||
virtual std::shared_ptr<TokenLocationCollection> getErrorTokenLocations(std::vector<ErrorInfo>* errors) const = 0;
|
||||
virtual std::shared_ptr<SourceLocationCollection> getErrorSourceLocations(std::vector<ErrorInfo>* errors) const = 0;
|
||||
|
||||
virtual void setErrorFilter(const ErrorFilter& filter);
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#include "data/access/StorageAccessProxy.h"
|
||||
|
||||
#include "data/graph/Graph.h"
|
||||
#include "data/location/TokenLocationCollection.h"
|
||||
#include "data/location/TokenLocationFile.h"
|
||||
#include "data/location/SourceLocationCollection.h"
|
||||
#include "data/location/SourceLocationFile.h"
|
||||
|
||||
#include "utility/logging/logging.h"
|
||||
#include "utility/file/FileInfo.h"
|
||||
@@ -133,7 +133,7 @@ bool StorageAccessProxy::checkEdgeExists(Id edgeId) const
|
||||
return false;
|
||||
}
|
||||
|
||||
std::shared_ptr<TokenLocationCollection> StorageAccessProxy::getFullTextSearchLocations(
|
||||
std::shared_ptr<SourceLocationCollection> StorageAccessProxy::getFullTextSearchLocations(
|
||||
const std::string &searchTerm, bool caseSensitive) const
|
||||
{
|
||||
if (hasSubject())
|
||||
@@ -141,7 +141,7 @@ std::shared_ptr<TokenLocationCollection> StorageAccessProxy::getFullTextSearchLo
|
||||
return m_subject->getFullTextSearchLocations(searchTerm, caseSensitive);
|
||||
}
|
||||
|
||||
return std::make_shared<TokenLocationCollection>();
|
||||
return std::make_shared<SourceLocationCollection>();
|
||||
}
|
||||
|
||||
std::vector<SearchMatch> StorageAccessProxy::getAutocompletionMatches(const std::string& query) const
|
||||
@@ -204,58 +204,58 @@ std::vector<Id> StorageAccessProxy::getNodeIdsForLocationIds(const std::vector<I
|
||||
return std::vector<Id>();
|
||||
}
|
||||
|
||||
std::shared_ptr<TokenLocationCollection> StorageAccessProxy::getTokenLocationsForTokenIds(
|
||||
std::shared_ptr<SourceLocationCollection> StorageAccessProxy::getSourceLocationsForTokenIds(
|
||||
const std::vector<Id>& tokenIds) const
|
||||
{
|
||||
if (hasSubject())
|
||||
{
|
||||
return m_subject->getTokenLocationsForTokenIds(tokenIds);
|
||||
return m_subject->getSourceLocationsForTokenIds(tokenIds);
|
||||
}
|
||||
|
||||
return std::make_shared<TokenLocationCollection>();
|
||||
return std::make_shared<SourceLocationCollection>();
|
||||
}
|
||||
|
||||
std::shared_ptr<TokenLocationCollection> StorageAccessProxy::getTokenLocationsForLocationIds(
|
||||
std::shared_ptr<SourceLocationCollection> StorageAccessProxy::getSourceLocationsForLocationIds(
|
||||
const std::vector<Id>& locationIds) const
|
||||
{
|
||||
if (hasSubject())
|
||||
{
|
||||
return m_subject->getTokenLocationsForLocationIds(locationIds);
|
||||
return m_subject->getSourceLocationsForLocationIds(locationIds);
|
||||
}
|
||||
|
||||
return std::make_shared<TokenLocationCollection>();
|
||||
return std::make_shared<SourceLocationCollection>();
|
||||
}
|
||||
|
||||
std::shared_ptr<TokenLocationFile> StorageAccessProxy::getTokenLocationsForFile(const std::string& filePath) const
|
||||
std::shared_ptr<SourceLocationFile> StorageAccessProxy::getSourceLocationsForFile(const FilePath& filePath) const
|
||||
{
|
||||
if (hasSubject())
|
||||
{
|
||||
return m_subject->getTokenLocationsForFile(filePath);
|
||||
return m_subject->getSourceLocationsForFile(filePath);
|
||||
}
|
||||
|
||||
return std::make_shared<TokenLocationFile>("");
|
||||
return std::make_shared<SourceLocationFile>("", false);
|
||||
}
|
||||
|
||||
std::shared_ptr<TokenLocationFile> StorageAccessProxy::getTokenLocationsForLinesInFile(
|
||||
std::shared_ptr<SourceLocationFile> StorageAccessProxy::getSourceLocationsForLinesInFile(
|
||||
const std::string& filePath, uint firstLineNumber, uint lastLineNumber
|
||||
) const
|
||||
{
|
||||
if (hasSubject())
|
||||
{
|
||||
return m_subject->getTokenLocationsForLinesInFile(filePath, firstLineNumber, lastLineNumber);
|
||||
return m_subject->getSourceLocationsForLinesInFile(filePath, firstLineNumber, lastLineNumber);
|
||||
}
|
||||
|
||||
return std::make_shared<TokenLocationFile>("");
|
||||
return std::make_shared<SourceLocationFile>("", false);
|
||||
}
|
||||
|
||||
std::shared_ptr<TokenLocationFile> StorageAccessProxy::getCommentLocationsInFile(const FilePath& filePath) const
|
||||
std::shared_ptr<SourceLocationFile> StorageAccessProxy::getCommentLocationsInFile(const FilePath& filePath) const
|
||||
{
|
||||
if (hasSubject())
|
||||
{
|
||||
return m_subject->getCommentLocationsInFile(filePath);
|
||||
}
|
||||
|
||||
return std::make_shared<TokenLocationFile>("");
|
||||
return std::make_shared<SourceLocationFile>("", false);
|
||||
}
|
||||
|
||||
std::shared_ptr<TextAccess> StorageAccessProxy::getFileContent(const FilePath& filePath) const
|
||||
@@ -319,14 +319,14 @@ std::vector<ErrorInfo> StorageAccessProxy::getErrors() const
|
||||
return std::vector<ErrorInfo>();
|
||||
}
|
||||
|
||||
std::shared_ptr<TokenLocationCollection> StorageAccessProxy::getErrorTokenLocations(std::vector<ErrorInfo>* errors) const
|
||||
std::shared_ptr<SourceLocationCollection> StorageAccessProxy::getErrorSourceLocations(std::vector<ErrorInfo>* errors) const
|
||||
{
|
||||
if (hasSubject())
|
||||
{
|
||||
return m_subject->getErrorTokenLocations(errors);
|
||||
return m_subject->getErrorSourceLocations(errors);
|
||||
}
|
||||
|
||||
return std::make_shared<TokenLocationCollection>();
|
||||
return std::make_shared<SourceLocationCollection>();
|
||||
}
|
||||
|
||||
Id StorageAccessProxy::addNodeBookmark(const NodeBookmark& bookmark)
|
||||
|
||||
@@ -33,7 +33,7 @@ public:
|
||||
virtual StorageEdge getEdgeById(Id edgeId) const;
|
||||
virtual bool checkEdgeExists(Id edgeId) const;
|
||||
|
||||
virtual std::shared_ptr<TokenLocationCollection> getFullTextSearchLocations(
|
||||
virtual std::shared_ptr<SourceLocationCollection> getFullTextSearchLocations(
|
||||
const std::string& searchTerm, bool caseSensitive) const;
|
||||
virtual std::vector<SearchMatch> getAutocompletionMatches(const std::string& query) const;
|
||||
virtual std::vector<SearchMatch> getSearchMatchesForTokenIds(const std::vector<Id>& tokenIds) const;
|
||||
@@ -44,18 +44,18 @@ public:
|
||||
virtual std::vector<Id> getActiveTokenIdsForId(Id tokenId, Id* declarationId) const;
|
||||
virtual std::vector<Id> getNodeIdsForLocationIds(const std::vector<Id>& locationIds) const;
|
||||
|
||||
virtual std::shared_ptr<TokenLocationCollection> getTokenLocationsForTokenIds(
|
||||
virtual std::shared_ptr<SourceLocationCollection> getSourceLocationsForTokenIds(
|
||||
const std::vector<Id>& tokenIds
|
||||
) const;
|
||||
virtual std::shared_ptr<TokenLocationCollection> getTokenLocationsForLocationIds(
|
||||
virtual std::shared_ptr<SourceLocationCollection> getSourceLocationsForLocationIds(
|
||||
const std::vector<Id>& locationIds
|
||||
) const;
|
||||
virtual std::shared_ptr<TokenLocationFile> getTokenLocationsForFile(const std::string& filePath) const;
|
||||
virtual std::shared_ptr<TokenLocationFile> getTokenLocationsForLinesInFile(
|
||||
virtual std::shared_ptr<SourceLocationFile> getSourceLocationsForFile(const FilePath& filePath) const;
|
||||
virtual std::shared_ptr<SourceLocationFile> getSourceLocationsForLinesInFile(
|
||||
const std::string& filePath, uint firstLineNumber, uint lastLineNumber
|
||||
) const;
|
||||
|
||||
virtual std::shared_ptr<TokenLocationFile> getCommentLocationsInFile(const FilePath& filePath) const;
|
||||
virtual std::shared_ptr<SourceLocationFile> getCommentLocationsInFile(const FilePath& filePath) const;
|
||||
|
||||
virtual std::shared_ptr<TextAccess> getFileContent(const FilePath& filePath) const;
|
||||
|
||||
@@ -67,7 +67,7 @@ public:
|
||||
virtual ErrorCountInfo getErrorCount() const;
|
||||
virtual std::vector<ErrorInfo> getErrors() const;
|
||||
|
||||
virtual std::shared_ptr<TokenLocationCollection> getErrorTokenLocations(std::vector<ErrorInfo>* errors) const;
|
||||
virtual std::shared_ptr<SourceLocationCollection> getErrorSourceLocations(std::vector<ErrorInfo>* errors) const;
|
||||
|
||||
virtual Id addNodeBookmark(const NodeBookmark& bookmark);
|
||||
virtual Id addEdgeBookmark(const EdgeBookmark& bookmark);
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
#include "data/graph/Token.h"
|
||||
|
||||
#include "data/location/TokenLocation.h"
|
||||
#include "utility/logging/logging.h"
|
||||
|
||||
Token::Token(Id id)
|
||||
|
||||
@@ -0,0 +1,205 @@
|
||||
#include "data/location/SourceLocation.h"
|
||||
|
||||
#include "data/location/SourceLocationFile.h"
|
||||
|
||||
SourceLocation::SourceLocation(
|
||||
SourceLocationFile* file,
|
||||
LocationType type,
|
||||
Id locationId,
|
||||
std::vector<Id> tokenIds,
|
||||
size_t lineNumber,
|
||||
size_t columnNumber,
|
||||
bool isStart
|
||||
)
|
||||
: m_file(file)
|
||||
, m_type(type)
|
||||
, m_locationId(locationId)
|
||||
, m_tokenIds(tokenIds)
|
||||
, m_lineNumber(lineNumber)
|
||||
, m_columnNumber(columnNumber)
|
||||
, m_other(nullptr)
|
||||
, m_isStart(isStart)
|
||||
{
|
||||
}
|
||||
|
||||
SourceLocation::SourceLocation(SourceLocation* other, size_t lineNumber, size_t columnNumber)
|
||||
: m_file(other->m_file)
|
||||
, m_type(other->m_type)
|
||||
, m_locationId(other->m_locationId)
|
||||
, m_tokenIds(other->m_tokenIds)
|
||||
, m_lineNumber(lineNumber)
|
||||
, m_columnNumber(columnNumber)
|
||||
, m_other(other)
|
||||
, m_isStart(!other->m_isStart)
|
||||
{
|
||||
other->setOtherLocation(this);
|
||||
}
|
||||
|
||||
SourceLocation::SourceLocation(const SourceLocation* other, SourceLocationFile* file)
|
||||
: m_file(file)
|
||||
, m_type(other->m_type)
|
||||
, m_locationId(other->m_locationId)
|
||||
, m_tokenIds(other->m_tokenIds)
|
||||
, m_lineNumber(other->m_lineNumber)
|
||||
, m_columnNumber(other->m_columnNumber)
|
||||
, m_other(nullptr)
|
||||
, m_isStart(other->m_isStart)
|
||||
{
|
||||
}
|
||||
|
||||
SourceLocation::~SourceLocation()
|
||||
{
|
||||
}
|
||||
|
||||
bool SourceLocation::operator==(const SourceLocation& rhs) const
|
||||
{
|
||||
return (
|
||||
getLineNumber() == rhs.getLineNumber() &&
|
||||
getColumnNumber() == rhs.getColumnNumber() &&
|
||||
getLocationId() == rhs.getLocationId() &&
|
||||
getType() == rhs.getType()
|
||||
);
|
||||
}
|
||||
|
||||
bool SourceLocation::operator<(const SourceLocation& rhs) const
|
||||
{
|
||||
if (getLineNumber() != rhs.getLineNumber())
|
||||
{
|
||||
return getLineNumber() < rhs.getLineNumber();
|
||||
}
|
||||
|
||||
if (getColumnNumber() != rhs.getColumnNumber())
|
||||
{
|
||||
return getColumnNumber() < rhs.getColumnNumber();
|
||||
}
|
||||
|
||||
return getLocationId() < rhs.getLocationId();
|
||||
}
|
||||
|
||||
bool SourceLocation::operator>(const SourceLocation& rhs) const
|
||||
{
|
||||
if (getLineNumber() != rhs.getLineNumber())
|
||||
{
|
||||
return getLineNumber() > rhs.getLineNumber();
|
||||
}
|
||||
|
||||
if (getColumnNumber() != rhs.getColumnNumber())
|
||||
{
|
||||
return getColumnNumber() > rhs.getColumnNumber();
|
||||
}
|
||||
|
||||
return getLocationId() > rhs.getLocationId();
|
||||
}
|
||||
|
||||
SourceLocationFile* SourceLocation::getSourceLocationFile() const
|
||||
{
|
||||
return m_file;
|
||||
}
|
||||
|
||||
Id SourceLocation::getLocationId() const
|
||||
{
|
||||
return m_locationId;
|
||||
}
|
||||
|
||||
const std::vector<Id>& SourceLocation::getTokenIds() const
|
||||
{
|
||||
return m_tokenIds;
|
||||
}
|
||||
|
||||
LocationType SourceLocation::getType() const
|
||||
{
|
||||
return m_type;
|
||||
}
|
||||
|
||||
size_t SourceLocation::getColumnNumber() const
|
||||
{
|
||||
return m_columnNumber;
|
||||
}
|
||||
|
||||
size_t SourceLocation::getLineNumber() const
|
||||
{
|
||||
return m_lineNumber;
|
||||
}
|
||||
|
||||
const FilePath& SourceLocation::getFilePath() const
|
||||
{
|
||||
return m_file->getFilePath();
|
||||
}
|
||||
|
||||
const SourceLocation* SourceLocation::getOtherLocation() const
|
||||
{
|
||||
return m_other;
|
||||
}
|
||||
|
||||
void SourceLocation::setOtherLocation(SourceLocation* other)
|
||||
{
|
||||
m_other = other;
|
||||
}
|
||||
|
||||
const SourceLocation* SourceLocation::getStartLocation() const
|
||||
{
|
||||
if (m_isStart)
|
||||
{
|
||||
return this;
|
||||
}
|
||||
else
|
||||
{
|
||||
return m_other;
|
||||
}
|
||||
}
|
||||
|
||||
const SourceLocation* SourceLocation::getEndLocation() const
|
||||
{
|
||||
if (!m_isStart)
|
||||
{
|
||||
return this;
|
||||
}
|
||||
else
|
||||
{
|
||||
return m_other;
|
||||
}
|
||||
}
|
||||
|
||||
bool SourceLocation::isStartLocation() const
|
||||
{
|
||||
return m_isStart;
|
||||
}
|
||||
|
||||
bool SourceLocation::isEndLocation() const
|
||||
{
|
||||
return !m_isStart;
|
||||
}
|
||||
|
||||
bool SourceLocation::isScopeLocation() const
|
||||
{
|
||||
return m_type == LOCATION_SCOPE;
|
||||
}
|
||||
|
||||
bool SourceLocation::isFullTextSearchMatch() const
|
||||
{
|
||||
return m_type == LOCATION_FULLTEXT;
|
||||
}
|
||||
|
||||
std::ostream& operator<<(std::ostream& ostream, const SourceLocation& location)
|
||||
{
|
||||
if (location.isStartLocation())
|
||||
{
|
||||
ostream << '<';
|
||||
}
|
||||
|
||||
ostream << location.getColumnNumber() << ":[ ";
|
||||
for (Id tokenId : location.getTokenIds())
|
||||
{
|
||||
ostream << '\b' << tokenId << ' ';
|
||||
}
|
||||
|
||||
ostream << "\b]";
|
||||
|
||||
if (location.isEndLocation())
|
||||
{
|
||||
ostream << '>';
|
||||
}
|
||||
|
||||
ostream << ' ';
|
||||
return ostream;
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
#ifndef SOURCE_LOCATION_H
|
||||
#define SOURCE_LOCATION_H
|
||||
|
||||
#include <ostream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "data/location/LocationType.h"
|
||||
#include "utility/types.h"
|
||||
|
||||
class FilePath;
|
||||
class SourceLocationFile;
|
||||
|
||||
class SourceLocation
|
||||
{
|
||||
public:
|
||||
SourceLocation(SourceLocationFile* file, LocationType type, Id locationId, std::vector<Id> tokenIds,
|
||||
size_t lineNumber, size_t columnNumber, bool isStart);
|
||||
SourceLocation(SourceLocation* other, size_t lineNumber, size_t columnNumber);
|
||||
SourceLocation(const SourceLocation* other, SourceLocationFile* file);
|
||||
virtual ~SourceLocation();
|
||||
|
||||
bool operator==(const SourceLocation& rhs) const;
|
||||
bool operator<(const SourceLocation& rhs) const;
|
||||
bool operator>(const SourceLocation& rhs) const;
|
||||
|
||||
SourceLocationFile* getSourceLocationFile() const;
|
||||
|
||||
Id getLocationId() const;
|
||||
const std::vector<Id>& getTokenIds() const;
|
||||
LocationType getType() const;
|
||||
|
||||
size_t getColumnNumber() const;
|
||||
size_t getLineNumber() const;
|
||||
const FilePath& getFilePath() const;
|
||||
|
||||
const SourceLocation* getOtherLocation() const;
|
||||
void setOtherLocation(SourceLocation* other);
|
||||
|
||||
const SourceLocation* getStartLocation() const;
|
||||
const SourceLocation* getEndLocation() const;
|
||||
|
||||
bool isStartLocation() const;
|
||||
bool isEndLocation() const;
|
||||
|
||||
bool isScopeLocation() const;
|
||||
bool isFullTextSearchMatch() const;
|
||||
|
||||
private:
|
||||
SourceLocationFile* m_file;
|
||||
|
||||
LocationType m_type;
|
||||
|
||||
const Id m_locationId;
|
||||
const std::vector<Id> m_tokenIds;
|
||||
|
||||
const size_t m_lineNumber;
|
||||
const size_t m_columnNumber;
|
||||
|
||||
SourceLocation* m_other;
|
||||
const bool m_isStart;
|
||||
};
|
||||
|
||||
std::ostream& operator<<(std::ostream& ostream, const SourceLocation& location);
|
||||
|
||||
#endif // SOURCE_LOCATION_H
|
||||
@@ -0,0 +1,129 @@
|
||||
#include "data/location/SourceLocationCollection.h"
|
||||
|
||||
#include "data/location/SourceLocationFile.h"
|
||||
#include "utility/logging/logging.h"
|
||||
|
||||
SourceLocationCollection::SourceLocationCollection()
|
||||
{
|
||||
}
|
||||
|
||||
SourceLocationCollection::~SourceLocationCollection()
|
||||
{
|
||||
}
|
||||
|
||||
const std::map<FilePath, std::shared_ptr<SourceLocationFile>>& SourceLocationCollection::getSourceLocationFiles() const
|
||||
{
|
||||
return m_files;
|
||||
}
|
||||
|
||||
size_t SourceLocationCollection::getSourceLocationCount() const
|
||||
{
|
||||
size_t count = 0;
|
||||
for (auto p : m_files)
|
||||
{
|
||||
count += p.second->getSourceLocationCount();
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
size_t SourceLocationCollection::getSourceLocationFileCount() const
|
||||
{
|
||||
return m_files.size();
|
||||
}
|
||||
|
||||
std::shared_ptr<SourceLocationFile> SourceLocationCollection::getSourceLocationFileByPath(const FilePath& filePath) const
|
||||
{
|
||||
std::map<FilePath, std::shared_ptr<SourceLocationFile>>::const_iterator it = m_files.find(filePath);
|
||||
if (it != m_files.end())
|
||||
{
|
||||
return it->second;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
SourceLocation* SourceLocationCollection::getSourceLocationById(Id locationId) const
|
||||
{
|
||||
for (auto p : m_files)
|
||||
{
|
||||
SourceLocation* location = p.second->getSourceLocationById(locationId);
|
||||
if (location)
|
||||
{
|
||||
return location;
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
SourceLocation* SourceLocationCollection::addSourceLocation(
|
||||
LocationType type, Id locationId, std::vector<Id> tokenIds, const FilePath& filePath,
|
||||
size_t startLineNumber, size_t startColumnNumber,
|
||||
size_t endLineNumber, size_t endColumnNumber)
|
||||
{
|
||||
if (startLineNumber > endLineNumber || (startLineNumber == endLineNumber && startColumnNumber > endColumnNumber))
|
||||
{
|
||||
LOG_ERROR_STREAM(<< "SourceLocation has wrong boundaries: " << filePath.str() << " "
|
||||
<< startLineNumber << ":" << startColumnNumber << " "
|
||||
<< endLineNumber << ":" << endColumnNumber);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
SourceLocationFile* file = createSourceLocationFile(filePath);
|
||||
if (file->isWhole())
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return file->addSourceLocation(type, locationId, tokenIds, startLineNumber, startColumnNumber, endLineNumber, endColumnNumber);
|
||||
}
|
||||
|
||||
SourceLocation* SourceLocationCollection::addSourceLocationCopy(SourceLocation* location)
|
||||
{
|
||||
return createSourceLocationFile(location->getFilePath())->addSourceLocationCopy(location);
|
||||
}
|
||||
|
||||
void SourceLocationCollection::addSourceLocationFile(std::shared_ptr<SourceLocationFile> file)
|
||||
{
|
||||
m_files.emplace(file->getFilePath(), file);
|
||||
}
|
||||
|
||||
void SourceLocationCollection::forEachSourceLocationFile(
|
||||
std::function<void(std::shared_ptr<SourceLocationFile>)> func) const
|
||||
{
|
||||
for (auto p : m_files)
|
||||
{
|
||||
func(p.second);
|
||||
}
|
||||
}
|
||||
|
||||
void SourceLocationCollection::forEachSourceLocation(std::function<void(SourceLocation*)> func) const
|
||||
{
|
||||
for (auto p : m_files)
|
||||
{
|
||||
p.second->forEachSourceLocation(func);
|
||||
}
|
||||
}
|
||||
|
||||
SourceLocationFile* SourceLocationCollection::createSourceLocationFile(const FilePath& filePath)
|
||||
{
|
||||
SourceLocationFile* file = getSourceLocationFileByPath(filePath).get();
|
||||
if (file)
|
||||
{
|
||||
return file;
|
||||
}
|
||||
|
||||
std::shared_ptr<SourceLocationFile> filePtr = std::make_shared<SourceLocationFile>(filePath, false);
|
||||
m_files.emplace(filePath, filePtr);
|
||||
return filePtr.get();
|
||||
}
|
||||
|
||||
std::ostream& operator<<(std::ostream& ostream, const SourceLocationCollection& base)
|
||||
{
|
||||
ostream << "Locations:\n";
|
||||
base.forEachSourceLocationFile([&ostream](std::shared_ptr<SourceLocationFile> f)
|
||||
{
|
||||
ostream << *(f.get());
|
||||
});
|
||||
return ostream;
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
#ifndef SOURCE_LOCATION_COLLECTION_H
|
||||
#define SOURCE_LOCATION_COLLECTION_H
|
||||
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <ostream>
|
||||
#include <vector>
|
||||
|
||||
#include "data/location/LocationType.h"
|
||||
#include "utility/types.h"
|
||||
|
||||
class FilePath;
|
||||
class SourceLocation;
|
||||
class SourceLocationFile;
|
||||
|
||||
class SourceLocationCollection
|
||||
{
|
||||
public:
|
||||
SourceLocationCollection();
|
||||
virtual ~SourceLocationCollection();
|
||||
|
||||
const std::map<FilePath, std::shared_ptr<SourceLocationFile>>& getSourceLocationFiles() const;
|
||||
|
||||
size_t getSourceLocationCount() const;
|
||||
size_t getSourceLocationFileCount() const;
|
||||
|
||||
std::shared_ptr<SourceLocationFile> getSourceLocationFileByPath(const FilePath& filePath) const;
|
||||
SourceLocation* getSourceLocationById(Id locationId) const;
|
||||
|
||||
SourceLocation* addSourceLocation(
|
||||
LocationType type, Id locationId, std::vector<Id> tokenIds, const FilePath& filePath,
|
||||
size_t startLineNumber, size_t startColumnNumber,
|
||||
size_t endLineNumber, size_t endColumnNumber);
|
||||
SourceLocation* addSourceLocationCopy(SourceLocation* location);
|
||||
|
||||
void addSourceLocationFile(std::shared_ptr<SourceLocationFile> file);
|
||||
|
||||
void forEachSourceLocationFile(std::function<void(std::shared_ptr<SourceLocationFile>)> func) const;
|
||||
void forEachSourceLocation(std::function<void(SourceLocation*)> func) const;
|
||||
|
||||
private:
|
||||
SourceLocationFile* createSourceLocationFile(const FilePath& filePath);
|
||||
|
||||
std::map<FilePath, std::shared_ptr<SourceLocationFile>> m_files;
|
||||
};
|
||||
|
||||
std::ostream& operator<<(std::ostream& ostream, const SourceLocationCollection& base);
|
||||
|
||||
#endif // SOURCE_LOCATION_COLLECTION_H
|
||||
@@ -0,0 +1,215 @@
|
||||
#include "data/location/SourceLocationFile.h"
|
||||
|
||||
SourceLocationFile::SourceLocationFile(const FilePath& filePath, bool isWhole)
|
||||
: m_filePath(filePath)
|
||||
, m_isWhole(isWhole)
|
||||
{
|
||||
}
|
||||
|
||||
SourceLocationFile::~SourceLocationFile()
|
||||
{
|
||||
}
|
||||
|
||||
const FilePath& SourceLocationFile::getFilePath() const
|
||||
{
|
||||
return m_filePath;
|
||||
}
|
||||
|
||||
void SourceLocationFile::setIsWhole(bool isWhole)
|
||||
{
|
||||
m_isWhole = isWhole;
|
||||
}
|
||||
|
||||
bool SourceLocationFile::isWhole() const
|
||||
{
|
||||
return m_isWhole;
|
||||
}
|
||||
|
||||
const std::multiset<std::shared_ptr<SourceLocation>, SourceLocationFile::LocationComp>& SourceLocationFile::getSourceLocations() const
|
||||
{
|
||||
return m_locations;
|
||||
}
|
||||
|
||||
size_t SourceLocationFile::getSourceLocationCount() const
|
||||
{
|
||||
return m_locationIndex.size();
|
||||
}
|
||||
|
||||
size_t SourceLocationFile::getUnscopedStartLocationCount() const
|
||||
{
|
||||
size_t count = 0;
|
||||
for (std::shared_ptr<SourceLocation> location : m_locations)
|
||||
{
|
||||
if (location->isStartLocation() && !location->isScopeLocation())
|
||||
{
|
||||
count++;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
SourceLocation* SourceLocationFile::addSourceLocation(
|
||||
LocationType type, Id locationId, std::vector<Id> tokenIds,
|
||||
size_t startLineNumber, size_t startColumnNumber,
|
||||
size_t endLineNumber, size_t endColumnNumber)
|
||||
{
|
||||
std::shared_ptr<SourceLocation> start =
|
||||
std::make_shared<SourceLocation>(this, type, locationId, tokenIds, startLineNumber, startColumnNumber, true);
|
||||
std::shared_ptr<SourceLocation> end = std::make_shared<SourceLocation>(start.get(), endLineNumber, endColumnNumber);
|
||||
|
||||
m_locations.insert(start);
|
||||
m_locations.insert(end);
|
||||
|
||||
m_locationIndex.emplace(start->getLocationId(), start.get());
|
||||
|
||||
return start.get();
|
||||
}
|
||||
|
||||
SourceLocation* SourceLocationFile::addSourceLocationCopy(const SourceLocation* location)
|
||||
{
|
||||
// Check whether this location was already added or if the other SourceLocation was added.
|
||||
SourceLocation* oldLocation = getSourceLocationById(location->getLocationId());
|
||||
if (oldLocation)
|
||||
{
|
||||
if (oldLocation->isStartLocation() == location->isStartLocation())
|
||||
{
|
||||
return oldLocation;
|
||||
}
|
||||
|
||||
const SourceLocation* otherOldLocation = oldLocation->getOtherLocation();
|
||||
if (otherOldLocation && otherOldLocation->isStartLocation() == location->isStartLocation())
|
||||
{
|
||||
return const_cast<SourceLocation*>(otherOldLocation);
|
||||
}
|
||||
}
|
||||
|
||||
std::shared_ptr<SourceLocation> copy = std::make_shared<SourceLocation>(location, this);
|
||||
m_locations.insert(copy);
|
||||
m_locationIndex.emplace(copy->getLocationId(), copy.get());
|
||||
|
||||
// If the old location was added before, then link them with each other.
|
||||
if (oldLocation)
|
||||
{
|
||||
oldLocation->setOtherLocation(copy.get());
|
||||
copy->setOtherLocation(oldLocation);
|
||||
}
|
||||
|
||||
return copy.get();
|
||||
}
|
||||
|
||||
SourceLocation* SourceLocationFile::getSourceLocationById(Id locationId) const
|
||||
{
|
||||
std::map<Id, SourceLocation*>::const_iterator it = m_locationIndex.find(locationId);
|
||||
|
||||
if (it != m_locationIndex.end())
|
||||
{
|
||||
return it->second;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void SourceLocationFile::forEachSourceLocation(std::function<void(SourceLocation*)> func) const
|
||||
{
|
||||
for (std::shared_ptr<SourceLocation> location : m_locations)
|
||||
{
|
||||
func(location.get());
|
||||
}
|
||||
}
|
||||
|
||||
void SourceLocationFile::forEachStartSourceLocation(std::function<void(SourceLocation*)> func) const
|
||||
{
|
||||
for (std::shared_ptr<SourceLocation> location : m_locations)
|
||||
{
|
||||
if (location->isStartLocation())
|
||||
{
|
||||
func(location.get());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SourceLocationFile::forEachEndSourceLocation(std::function<void(SourceLocation*)> func) const
|
||||
{
|
||||
for (std::shared_ptr<SourceLocation> location : m_locations)
|
||||
{
|
||||
if (location->isEndLocation())
|
||||
{
|
||||
func(location.get());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::shared_ptr<SourceLocationFile> SourceLocationFile::getFilteredByLines(size_t firstLineNumber, size_t lastLineNumber) const
|
||||
{
|
||||
std::shared_ptr<SourceLocationFile> ret = std::make_shared<SourceLocationFile>(getFilePath(), false);
|
||||
|
||||
for (std::shared_ptr<SourceLocation> location : m_locations)
|
||||
{
|
||||
if (location->getLineNumber() >= firstLineNumber && location->getLineNumber() <= lastLineNumber)
|
||||
{
|
||||
ret->addSourceLocationCopy(location.get());
|
||||
}
|
||||
}
|
||||
|
||||
if (isWhole() && ret->getSourceLocationCount() == getSourceLocationCount())
|
||||
{
|
||||
ret->setIsWhole(true);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::shared_ptr<SourceLocationFile> SourceLocationFile::getFilteredByType(LocationType type) const
|
||||
{
|
||||
std::shared_ptr<SourceLocationFile> ret = std::make_shared<SourceLocationFile>(getFilePath(), false);
|
||||
|
||||
for (std::shared_ptr<SourceLocation> location : m_locations)
|
||||
{
|
||||
if (location->getType() == type)
|
||||
{
|
||||
ret->addSourceLocationCopy(location.get());
|
||||
}
|
||||
}
|
||||
|
||||
if (isWhole() && ret->getSourceLocationCount() == getSourceLocationCount())
|
||||
{
|
||||
ret->setIsWhole(true);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::ostream& operator<<(std::ostream& ostream, const SourceLocationFile& file)
|
||||
{
|
||||
ostream << "file \"" << file.getFilePath().str() << "\"";
|
||||
|
||||
size_t line = 0;
|
||||
file.forEachSourceLocation(
|
||||
[&ostream, &line](SourceLocation* location)
|
||||
{
|
||||
if (location->getLineNumber() != line)
|
||||
{
|
||||
while (line < location->getLineNumber())
|
||||
{
|
||||
if (!line)
|
||||
{
|
||||
line = location->getLineNumber();
|
||||
}
|
||||
else
|
||||
{
|
||||
line++;
|
||||
}
|
||||
|
||||
ostream << '\n' << line;
|
||||
}
|
||||
|
||||
ostream << ": ";
|
||||
}
|
||||
|
||||
ostream << *location;
|
||||
}
|
||||
);
|
||||
|
||||
ostream << '\n';
|
||||
return ostream;
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
#ifndef SOURCE_LOCATION_FILE_H
|
||||
#define SOURCE_LOCATION_FILE_H
|
||||
|
||||
#include <map>
|
||||
#include <ostream>
|
||||
#include <set>
|
||||
|
||||
#include "data/location/LocationType.h"
|
||||
#include "data/location/SourceLocation.h"
|
||||
#include "utility/file/FilePath.h"
|
||||
#include "utility/types.h"
|
||||
|
||||
class SourceLocationFile
|
||||
{
|
||||
public:
|
||||
struct LocationComp
|
||||
{
|
||||
bool operator()(const std::shared_ptr<SourceLocation>& lhs, const std::shared_ptr<SourceLocation>& rhs) const
|
||||
{
|
||||
return *(lhs.get()) < *(rhs.get());
|
||||
}
|
||||
};
|
||||
|
||||
SourceLocationFile(const FilePath& filePath, bool isWhole);
|
||||
virtual ~SourceLocationFile();
|
||||
|
||||
const FilePath& getFilePath() const;
|
||||
|
||||
void setIsWhole(bool isWhole);
|
||||
bool isWhole() const;
|
||||
|
||||
const std::multiset<std::shared_ptr<SourceLocation>, LocationComp>& getSourceLocations() const;
|
||||
|
||||
size_t getSourceLocationCount() const;
|
||||
size_t getUnscopedStartLocationCount() const;
|
||||
|
||||
SourceLocation* addSourceLocation(
|
||||
LocationType type, Id locationId, std::vector<Id> tokenIds,
|
||||
size_t startLineNumber, size_t startColumnNumber,
|
||||
size_t endLineNumber, size_t endColumnNumber);
|
||||
SourceLocation* addSourceLocationCopy(const SourceLocation* location);
|
||||
|
||||
SourceLocation* getSourceLocationById(Id locationId) const;
|
||||
|
||||
void forEachSourceLocation(std::function<void(SourceLocation*)> func) const;
|
||||
void forEachStartSourceLocation(std::function<void(SourceLocation*)> func) const;
|
||||
void forEachEndSourceLocation(std::function<void(SourceLocation*)> func) const;
|
||||
|
||||
std::shared_ptr<SourceLocationFile> getFilteredByLines(size_t firstLineNumber, size_t lastLineNumber) const;
|
||||
std::shared_ptr<SourceLocationFile> getFilteredByType(LocationType type) const;
|
||||
|
||||
private:
|
||||
const FilePath m_filePath;
|
||||
bool m_isWhole;
|
||||
|
||||
std::multiset<std::shared_ptr<SourceLocation>, LocationComp> m_locations;
|
||||
std::map<Id, SourceLocation*> m_locationIndex;
|
||||
};
|
||||
|
||||
std::ostream& operator<<(std::ostream& ostream, const SourceLocationFile& base);
|
||||
|
||||
#endif // SOURCE_LOCATION_FILE_H
|
||||
@@ -1,206 +0,0 @@
|
||||
#include "data/location/TokenLocation.h"
|
||||
|
||||
#include "data/location/TokenLocationLine.h"
|
||||
|
||||
TokenLocation::TokenLocation(Id locationId, Id tokenId, TokenLocationLine* line, unsigned int columnNumber, bool isStart)
|
||||
: m_id(locationId)
|
||||
, m_tokenId(tokenId)
|
||||
, m_type(LOCATION_TOKEN)
|
||||
, m_line(line)
|
||||
, m_columnNumber(columnNumber)
|
||||
, m_other(nullptr)
|
||||
, m_isStart(isStart)
|
||||
{
|
||||
}
|
||||
|
||||
TokenLocation::TokenLocation(TokenLocation *other, TokenLocationLine* line, unsigned int columnNumber, bool isStart)
|
||||
: m_id(other->m_id)
|
||||
, m_tokenId(other->m_tokenId)
|
||||
, m_type(other->m_type)
|
||||
, m_line(line)
|
||||
, m_columnNumber(columnNumber)
|
||||
, m_other(other)
|
||||
, m_isStart(isStart)
|
||||
{
|
||||
}
|
||||
|
||||
TokenLocation::TokenLocation(const TokenLocation& other, TokenLocationLine* line)
|
||||
: m_id(other.m_id)
|
||||
, m_tokenId(other.m_tokenId)
|
||||
, m_type(other.m_type)
|
||||
, m_line(line)
|
||||
, m_columnNumber(other.m_columnNumber)
|
||||
, m_other(nullptr)
|
||||
, m_isStart(other.m_isStart)
|
||||
{
|
||||
}
|
||||
|
||||
TokenLocation::~TokenLocation()
|
||||
{
|
||||
}
|
||||
|
||||
bool TokenLocation::operator<(const TokenLocation& rhs) const
|
||||
{
|
||||
return (
|
||||
getLineNumber() < rhs.getLineNumber() || (
|
||||
getLineNumber() == rhs.getLineNumber() &&
|
||||
getColumnNumber() < rhs.getColumnNumber()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
bool TokenLocation::operator>(const TokenLocation& rhs) const
|
||||
{
|
||||
return (
|
||||
getLineNumber() > rhs.getLineNumber() || (
|
||||
getLineNumber() == rhs.getLineNumber() &&
|
||||
getColumnNumber() > rhs.getColumnNumber()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
Id TokenLocation::getId() const
|
||||
{
|
||||
return m_id;
|
||||
}
|
||||
|
||||
Id TokenLocation::getTokenId() const
|
||||
{
|
||||
return m_tokenId;
|
||||
}
|
||||
|
||||
LocationType TokenLocation::getType() const
|
||||
{
|
||||
return m_type;
|
||||
}
|
||||
|
||||
void TokenLocation::setType(LocationType type)
|
||||
{
|
||||
m_type = type;
|
||||
|
||||
if (m_other)
|
||||
{
|
||||
m_other->m_type = type;
|
||||
}
|
||||
}
|
||||
|
||||
TokenLocationLine* TokenLocation::getTokenLocationLine() const
|
||||
{
|
||||
return m_line;
|
||||
}
|
||||
|
||||
TokenLocationFile* TokenLocation::getTokenLocationFile() const
|
||||
{
|
||||
return m_line->getTokenLocationFile();
|
||||
}
|
||||
|
||||
unsigned int TokenLocation::getColumnNumber() const
|
||||
{
|
||||
return m_columnNumber;
|
||||
}
|
||||
|
||||
unsigned int TokenLocation::getLineNumber() const
|
||||
{
|
||||
return m_line->getLineNumber();
|
||||
}
|
||||
|
||||
const FilePath& TokenLocation::getFilePath() const
|
||||
{
|
||||
return m_line->getFilePath();
|
||||
}
|
||||
|
||||
TokenLocation* TokenLocation::getOtherTokenLocation() const
|
||||
{
|
||||
return m_other;
|
||||
}
|
||||
|
||||
void TokenLocation::setOtherTokenLocation(TokenLocation* location)
|
||||
{
|
||||
m_other = location;
|
||||
}
|
||||
|
||||
TokenLocation* TokenLocation::getStartTokenLocation()
|
||||
{
|
||||
if (m_isStart)
|
||||
{
|
||||
return this;
|
||||
}
|
||||
else
|
||||
{
|
||||
return m_other;
|
||||
}
|
||||
}
|
||||
|
||||
TokenLocation* TokenLocation::getEndTokenLocation()
|
||||
{
|
||||
if (!m_isStart)
|
||||
{
|
||||
return this;
|
||||
}
|
||||
else
|
||||
{
|
||||
return m_other;
|
||||
}
|
||||
}
|
||||
|
||||
const TokenLocation* TokenLocation::getStartTokenLocation() const
|
||||
{
|
||||
if (m_isStart)
|
||||
{
|
||||
return this;
|
||||
}
|
||||
else
|
||||
{
|
||||
return m_other;
|
||||
}
|
||||
}
|
||||
|
||||
const TokenLocation* TokenLocation::getEndTokenLocation() const
|
||||
{
|
||||
if (!m_isStart)
|
||||
{
|
||||
return this;
|
||||
}
|
||||
else
|
||||
{
|
||||
return m_other;
|
||||
}
|
||||
}
|
||||
|
||||
bool TokenLocation::isStartTokenLocation() const
|
||||
{
|
||||
return m_isStart;
|
||||
}
|
||||
|
||||
bool TokenLocation::isEndTokenLocation() const
|
||||
{
|
||||
return !m_isStart;
|
||||
}
|
||||
|
||||
bool TokenLocation::isScopeTokenLocation() const
|
||||
{
|
||||
return m_type == LOCATION_SCOPE;
|
||||
}
|
||||
|
||||
bool TokenLocation::isFullTextSearchMatch() const
|
||||
{
|
||||
return m_type == LOCATION_FULLTEXT;
|
||||
}
|
||||
|
||||
std::ostream& operator<<(std::ostream& ostream, const TokenLocation& location)
|
||||
{
|
||||
if ((&location)->isStartTokenLocation())
|
||||
{
|
||||
ostream << "<";
|
||||
}
|
||||
|
||||
ostream << location.getColumnNumber() << ":[" << location.getTokenId() << "]";
|
||||
|
||||
if ((&location)->isEndTokenLocation())
|
||||
{
|
||||
ostream << ">";
|
||||
}
|
||||
|
||||
ostream << " ";
|
||||
return ostream;
|
||||
}
|
||||
@@ -1,70 +0,0 @@
|
||||
#ifndef TOKEN_LOCATION_H
|
||||
#define TOKEN_LOCATION_H
|
||||
|
||||
#include <memory>
|
||||
#include <ostream>
|
||||
#include <string>
|
||||
|
||||
#include "data/location/LocationType.h"
|
||||
#include "utility/file/FilePath.h"
|
||||
#include "utility/types.h"
|
||||
|
||||
class Token;
|
||||
class TokenLocationFile;
|
||||
class TokenLocationLine;
|
||||
|
||||
class TokenLocation
|
||||
{
|
||||
public:
|
||||
TokenLocation(Id locationId, Id tokenId, TokenLocationLine* line, unsigned int columnNumber, bool isStart);
|
||||
TokenLocation(TokenLocation* other, TokenLocationLine* line, unsigned int columnNumber, bool isStart);
|
||||
TokenLocation(const TokenLocation& other, TokenLocationLine* line);
|
||||
~TokenLocation();
|
||||
|
||||
bool operator<(const TokenLocation& rhs) const;
|
||||
bool operator>(const TokenLocation& rhs) const;
|
||||
|
||||
Id getId() const;
|
||||
Id getTokenId() const;
|
||||
|
||||
LocationType getType() const;
|
||||
void setType(LocationType type);
|
||||
|
||||
TokenLocationLine* getTokenLocationLine() const;
|
||||
TokenLocationFile* getTokenLocationFile() const;
|
||||
|
||||
unsigned int getColumnNumber() const;
|
||||
unsigned int getLineNumber() const;
|
||||
const FilePath& getFilePath() const;
|
||||
|
||||
TokenLocation* getOtherTokenLocation() const;
|
||||
void setOtherTokenLocation(TokenLocation* location);
|
||||
|
||||
TokenLocation* getStartTokenLocation();
|
||||
TokenLocation* getEndTokenLocation();
|
||||
|
||||
const TokenLocation* getStartTokenLocation() const;
|
||||
const TokenLocation* getEndTokenLocation() const;
|
||||
|
||||
bool isStartTokenLocation() const;
|
||||
bool isEndTokenLocation() const;
|
||||
|
||||
bool isScopeTokenLocation() const;
|
||||
bool isFullTextSearchMatch() const;
|
||||
|
||||
private:
|
||||
const Id m_id; // own id
|
||||
const Id m_tokenId;
|
||||
|
||||
LocationType m_type;
|
||||
|
||||
TokenLocationLine* const m_line;
|
||||
const unsigned int m_columnNumber;
|
||||
|
||||
TokenLocation* m_other;
|
||||
const bool m_isStart;
|
||||
};
|
||||
|
||||
std::ostream& operator<<(std::ostream& ostream, const TokenLocation& location);
|
||||
|
||||
#endif // TOKEN_LOCATION_H
|
||||
@@ -1,233 +0,0 @@
|
||||
#include "data/location/TokenLocationCollection.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include "utility/file/FileSystem.h"
|
||||
#include "utility/logging/logging.h"
|
||||
|
||||
#include "data/location/TokenLocation.h"
|
||||
#include "data/location/TokenLocationFile.h"
|
||||
#include "data/location/TokenLocationLine.h"
|
||||
|
||||
TokenLocationCollection::TokenLocationCollection()
|
||||
{
|
||||
}
|
||||
|
||||
TokenLocationCollection::~TokenLocationCollection()
|
||||
{
|
||||
}
|
||||
|
||||
const TokenLocationCollection::TokenLocationFileMapType& TokenLocationCollection::getTokenLocationFiles() const
|
||||
{
|
||||
return m_files;
|
||||
}
|
||||
|
||||
const std::map<Id, TokenLocation*>& TokenLocationCollection::getTokenLocations() const
|
||||
{
|
||||
return m_locations;
|
||||
}
|
||||
|
||||
std::shared_ptr<TokenLocationFile> TokenLocationCollection::getTokenLocationFileByPath(const FilePath& filePath) const
|
||||
{
|
||||
std::map<FilePath, std::shared_ptr<TokenLocationFile>>::const_iterator it = m_files.find(filePath);
|
||||
if (it != m_files.end())
|
||||
{
|
||||
return it->second;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
size_t TokenLocationCollection::getTokenLocationFileCount() const
|
||||
{
|
||||
return m_files.size();
|
||||
}
|
||||
|
||||
size_t TokenLocationCollection::getTokenLocationLineCount() const
|
||||
{
|
||||
size_t count = 0;
|
||||
|
||||
for (const TokenLocationFilePairType& file : m_files)
|
||||
{
|
||||
count += file.second->getTokenLocationLineCount();
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
size_t TokenLocationCollection::getTokenLocationCount() const
|
||||
{
|
||||
return m_locations.size();
|
||||
}
|
||||
|
||||
TokenLocation* TokenLocationCollection::addTokenLocation(
|
||||
Id locationId, Id tokenId, const FilePath& filePath,
|
||||
unsigned int startLineNumber, unsigned int startColumnNumber,
|
||||
unsigned int endLineNumber, unsigned int endColumnNumber)
|
||||
{
|
||||
if (startLineNumber > endLineNumber || (startLineNumber == endLineNumber && startColumnNumber > endColumnNumber))
|
||||
{
|
||||
LOG_ERROR_STREAM(<< "TokenLocation has wrong boundaries: "<< filePath.str() << " "
|
||||
<< startLineNumber << ":" << startColumnNumber << " "
|
||||
<< endLineNumber << ":" << endColumnNumber);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
TokenLocation* location = findTokenLocationById(locationId);
|
||||
if (location)
|
||||
{
|
||||
return location;
|
||||
}
|
||||
|
||||
TokenLocationFile* file = createTokenLocationFile(filePath);
|
||||
location = file->addTokenLocation(
|
||||
locationId, tokenId, startLineNumber, startColumnNumber, endLineNumber, endColumnNumber);
|
||||
|
||||
m_locations.emplace(location->getId(), location);
|
||||
return location;
|
||||
}
|
||||
|
||||
void TokenLocationCollection::removeTokenLocation(TokenLocation* location)
|
||||
{
|
||||
if (!location || !findTokenLocationById(location->getId()))
|
||||
{
|
||||
LOG_ERROR("TokenLocation is not part of this TokenLocationCollection.");
|
||||
return;
|
||||
}
|
||||
|
||||
m_locations.erase(location->getId());
|
||||
|
||||
TokenLocationFile* file = location->getTokenLocationFile();
|
||||
file->removeTokenLocation(location);
|
||||
|
||||
if (!file->getTokenLocationLineCount())
|
||||
{
|
||||
m_files.erase(file->getFilePath());
|
||||
}
|
||||
}
|
||||
|
||||
TokenLocationFile* TokenLocationCollection::addTokenLocationFile(std::shared_ptr<TokenLocationFile> locationFile)
|
||||
{
|
||||
TokenLocationFile* file = findTokenLocationFileByPath(locationFile->getFilePath());
|
||||
if (file)
|
||||
{
|
||||
LOG_ERROR("TokenLocationFile with same path already exists.");
|
||||
return file;
|
||||
}
|
||||
|
||||
m_files.emplace(locationFile->getFilePath(), locationFile);
|
||||
locationFile->forEachTokenLocation(
|
||||
[this, &file](TokenLocation* tokenLocation) -> void
|
||||
{
|
||||
m_locations.emplace(tokenLocation->getId(), tokenLocation);
|
||||
}
|
||||
);
|
||||
return locationFile.get();
|
||||
}
|
||||
|
||||
void TokenLocationCollection::removeTokenLocationFile(TokenLocationFile* file)
|
||||
{
|
||||
file->forEachTokenLocation(
|
||||
[&](TokenLocation* location)
|
||||
{
|
||||
m_locations.erase(location->getId());
|
||||
}
|
||||
);
|
||||
|
||||
m_files.erase(file->getFilePath());
|
||||
}
|
||||
|
||||
TokenLocation* TokenLocationCollection::findTokenLocationById(Id id) const
|
||||
{
|
||||
std::map<Id, TokenLocation*>::const_iterator it = m_locations.find(id);
|
||||
|
||||
if (it != m_locations.end())
|
||||
{
|
||||
return it->second;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
TokenLocationFile* TokenLocationCollection::findTokenLocationFileByPath(const FilePath& filePath) const
|
||||
{
|
||||
return getTokenLocationFileByPath(filePath).get();
|
||||
}
|
||||
|
||||
void TokenLocationCollection::forEachTokenLocationFile(
|
||||
std::function<void(std::shared_ptr<TokenLocationFile>)> func) const
|
||||
{
|
||||
for (const TokenLocationFilePairType& file : m_files)
|
||||
{
|
||||
func(file.second);
|
||||
}
|
||||
}
|
||||
|
||||
void TokenLocationCollection::forEachTokenLocationLine(std::function<void(TokenLocationLine*)> func) const
|
||||
{
|
||||
for (const TokenLocationFilePairType& file : m_files)
|
||||
{
|
||||
file.second->forEachTokenLocationLine(func);
|
||||
}
|
||||
}
|
||||
|
||||
void TokenLocationCollection::forEachTokenLocation(std::function<void(TokenLocation*)> func) const
|
||||
{
|
||||
for (const TokenLocationFilePairType& file : m_files)
|
||||
{
|
||||
file.second->forEachTokenLocation(func);
|
||||
}
|
||||
}
|
||||
|
||||
TokenLocationFile* TokenLocationCollection::addTokenLocationFileAsPlainCopy(const TokenLocationFile* locationFile)
|
||||
{
|
||||
TokenLocationFile* file = createTokenLocationFile(locationFile->getFilePath());
|
||||
locationFile->forEachTokenLocation(
|
||||
[this, &file](TokenLocation* tokenLocation) -> void
|
||||
{
|
||||
TokenLocation* copy = file->addTokenLocationAsPlainCopy(tokenLocation);
|
||||
m_locations.emplace(copy->getId(), copy);
|
||||
}
|
||||
);
|
||||
return file;
|
||||
}
|
||||
|
||||
TokenLocation* TokenLocationCollection::addTokenLocationAsPlainCopy(const TokenLocation* location)
|
||||
{
|
||||
const FilePath& filePath = location->getTokenLocationLine()->getTokenLocationFile()->getFilePath();
|
||||
TokenLocationFile* file = createTokenLocationFile(filePath);
|
||||
TokenLocation* copy = file->addTokenLocationAsPlainCopy(location);
|
||||
|
||||
m_locations.emplace(copy->getId(), copy);
|
||||
return copy;
|
||||
}
|
||||
|
||||
void TokenLocationCollection::clear()
|
||||
{
|
||||
m_locations.clear();
|
||||
m_files.clear();
|
||||
}
|
||||
|
||||
TokenLocationFile* TokenLocationCollection::createTokenLocationFile(const FilePath& filePath)
|
||||
{
|
||||
TokenLocationFile* file = findTokenLocationFileByPath(filePath);
|
||||
|
||||
if (file)
|
||||
{
|
||||
return file;
|
||||
}
|
||||
|
||||
std::shared_ptr<TokenLocationFile> filePtr = std::make_shared<TokenLocationFile>(filePath);
|
||||
m_files.emplace(filePath, filePtr);
|
||||
return filePtr.get();
|
||||
}
|
||||
|
||||
std::ostream& operator<<(std::ostream& ostream, const TokenLocationCollection& base)
|
||||
{
|
||||
ostream << "Locations:\n";
|
||||
base.forEachTokenLocationFile([&ostream](std::shared_ptr<TokenLocationFile> f)
|
||||
{
|
||||
ostream << *(f.get());
|
||||
});
|
||||
return ostream;
|
||||
}
|
||||
@@ -1,65 +0,0 @@
|
||||
#ifndef TOKEN_LOCATION_COLLECTION_H
|
||||
#define TOKEN_LOCATION_COLLECTION_H
|
||||
|
||||
#include <functional>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <ostream>
|
||||
#include <string>
|
||||
|
||||
#include "utility/file/FilePath.h"
|
||||
#include "utility/types.h"
|
||||
|
||||
class TokenLocation;
|
||||
class TokenLocationFile;
|
||||
class TokenLocationLine;
|
||||
|
||||
class TokenLocationCollection
|
||||
{
|
||||
public:
|
||||
typedef std::map<FilePath, std::shared_ptr<TokenLocationFile> > TokenLocationFileMapType;
|
||||
typedef std::pair<FilePath, std::shared_ptr<TokenLocationFile> > TokenLocationFilePairType;
|
||||
|
||||
TokenLocationCollection();
|
||||
~TokenLocationCollection();
|
||||
|
||||
const TokenLocationFileMapType& getTokenLocationFiles() const;
|
||||
const std::map<Id, TokenLocation*>& getTokenLocations() const;
|
||||
|
||||
std::shared_ptr<TokenLocationFile> getTokenLocationFileByPath(const FilePath& filePath) const;
|
||||
|
||||
size_t getTokenLocationFileCount() const;
|
||||
size_t getTokenLocationLineCount() const;
|
||||
size_t getTokenLocationCount() const;
|
||||
|
||||
TokenLocation* addTokenLocation(
|
||||
Id locationId, Id tokenId, const FilePath& filePath,
|
||||
unsigned int startLineNumber, unsigned int startColumnNumber,
|
||||
unsigned int endLineNumber, unsigned int endColumnNumber);
|
||||
void removeTokenLocation(TokenLocation* location);
|
||||
|
||||
TokenLocationFile* addTokenLocationFile(std::shared_ptr<TokenLocationFile> locationFile);
|
||||
void removeTokenLocationFile(TokenLocationFile* file);
|
||||
|
||||
TokenLocation* findTokenLocationById(Id id) const;
|
||||
TokenLocationFile* findTokenLocationFileByPath(const FilePath& filePath) const;
|
||||
|
||||
void forEachTokenLocationFile(std::function<void(std::shared_ptr<TokenLocationFile>)> func) const;
|
||||
void forEachTokenLocationLine(std::function<void(TokenLocationLine*)> func) const;
|
||||
void forEachTokenLocation(std::function<void(TokenLocation*)> func) const;
|
||||
|
||||
TokenLocationFile* addTokenLocationFileAsPlainCopy(const TokenLocationFile* locationFile);
|
||||
TokenLocation* addTokenLocationAsPlainCopy(const TokenLocation* location);
|
||||
|
||||
void clear();
|
||||
|
||||
private:
|
||||
TokenLocationFile* createTokenLocationFile(const FilePath& filePath);
|
||||
|
||||
TokenLocationFileMapType m_files;
|
||||
std::map<Id, TokenLocation*> m_locations;
|
||||
};
|
||||
|
||||
std::ostream& operator<<(std::ostream& ostream, const TokenLocationCollection& base);
|
||||
|
||||
#endif // TOKEN_LOCATION_COLLECTION_H
|
||||
@@ -1,260 +0,0 @@
|
||||
#include "data/location/TokenLocationFile.h"
|
||||
|
||||
#include <set>
|
||||
|
||||
#include "utility/logging/logging.h"
|
||||
#include "utility/types.h"
|
||||
|
||||
#include "data/location/TokenLocation.h"
|
||||
#include "data/location/TokenLocationLine.h"
|
||||
|
||||
TokenLocationFile::TokenLocationFile(const FilePath& filePath)
|
||||
: isWholeCopy(false)
|
||||
, m_filePath(filePath)
|
||||
{
|
||||
}
|
||||
|
||||
TokenLocationFile::~TokenLocationFile()
|
||||
{
|
||||
}
|
||||
|
||||
const TokenLocationFile::TokenLocationLineMapType& TokenLocationFile::getTokenLocationLines() const
|
||||
{
|
||||
return m_lines;
|
||||
}
|
||||
|
||||
size_t TokenLocationFile::getTokenLocationLineCount() const
|
||||
{
|
||||
return m_lines.size();
|
||||
}
|
||||
|
||||
size_t TokenLocationFile::getUnscopedStartTokenLocationCount() const
|
||||
{
|
||||
size_t count = 0;
|
||||
for (const TokenLocationLinePairType& line : m_lines)
|
||||
{
|
||||
line.second->forEachStartTokenLocation(
|
||||
[&count](TokenLocation* location)
|
||||
{
|
||||
if (!location->isScopeTokenLocation())
|
||||
{
|
||||
count++;
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
const FilePath& TokenLocationFile::getFilePath() const
|
||||
{
|
||||
return m_filePath;
|
||||
}
|
||||
|
||||
TokenLocation* TokenLocationFile::addTokenLocation(
|
||||
Id locationId, Id tokenId,
|
||||
unsigned int startLineNumber, unsigned int startColumnNumber,
|
||||
unsigned int endLineNumber, unsigned int endColumnNumber)
|
||||
{
|
||||
TokenLocationLine* line = createTokenLocationLine(startLineNumber);
|
||||
|
||||
TokenLocation* start = line->addStartTokenLocation(locationId, tokenId, startColumnNumber);
|
||||
|
||||
if (startLineNumber != endLineNumber)
|
||||
{
|
||||
line = createTokenLocationLine(endLineNumber);
|
||||
}
|
||||
|
||||
line->addEndTokenLocation(start, endColumnNumber);
|
||||
|
||||
return start;
|
||||
}
|
||||
|
||||
void TokenLocationFile::removeTokenLocation(TokenLocation* location)
|
||||
{
|
||||
TokenLocationLine* line = location->getTokenLocationLine();
|
||||
|
||||
TokenLocation* otherLocation = location->getOtherTokenLocation();
|
||||
TokenLocationLine* otherLine = otherLocation->getTokenLocationLine();
|
||||
|
||||
line->removeTokenLocation(location);
|
||||
if (!line->getTokenLocationCount())
|
||||
{
|
||||
m_lines.erase(line->getLineNumber());
|
||||
}
|
||||
|
||||
otherLine->removeTokenLocation(otherLocation);
|
||||
if (!otherLine->getTokenLocationCount())
|
||||
{
|
||||
m_lines.erase(otherLine->getLineNumber());
|
||||
}
|
||||
}
|
||||
|
||||
TokenLocationLine* TokenLocationFile::findTokenLocationLineByNumber(unsigned int lineNumber) const
|
||||
{
|
||||
return findTokenLocationLine(lineNumber);
|
||||
}
|
||||
|
||||
void TokenLocationFile::forEachTokenLocationLine(std::function<void(TokenLocationLine*)> func) const
|
||||
{
|
||||
for (const TokenLocationLinePairType& line : m_lines)
|
||||
{
|
||||
func(line.second.get());
|
||||
}
|
||||
}
|
||||
|
||||
void TokenLocationFile::forEachTokenLocation(std::function<void(TokenLocation*)> func) const
|
||||
{
|
||||
for (const TokenLocationLinePairType& line : m_lines)
|
||||
{
|
||||
line.second->forEachTokenLocation(func);
|
||||
}
|
||||
}
|
||||
|
||||
void TokenLocationFile::forEachStartTokenLocation(std::function<void(TokenLocation*)> func) const
|
||||
{
|
||||
for (const TokenLocationLinePairType& line : m_lines)
|
||||
{
|
||||
line.second->forEachStartTokenLocation(func);
|
||||
}
|
||||
}
|
||||
|
||||
void TokenLocationFile::forEachEndTokenLocation(std::function<void(TokenLocation*)> func) const
|
||||
{
|
||||
for (const TokenLocationLinePairType& line : m_lines)
|
||||
{
|
||||
line.second->forEachEndTokenLocation(func);
|
||||
}
|
||||
}
|
||||
|
||||
TokenLocation* TokenLocationFile::addTokenLocationAsPlainCopy(const TokenLocation* location)
|
||||
{
|
||||
unsigned int lineNumber = location->getLineNumber();
|
||||
TokenLocationLine* line = createTokenLocationLine(lineNumber);
|
||||
|
||||
// Check whether this location was already added or if the other TokenLocation was added.
|
||||
TokenLocation* otherLocation = line->getTokenLocationById(location->getId());
|
||||
if (otherLocation)
|
||||
{
|
||||
if (otherLocation->isStartTokenLocation() == location->isStartTokenLocation())
|
||||
{
|
||||
// The location was already added.
|
||||
return otherLocation;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Look for the other location in it's line.
|
||||
unsigned int otherLineNumber = location->getOtherTokenLocation()->getLineNumber();
|
||||
if (lineNumber != otherLineNumber)
|
||||
{
|
||||
TokenLocationLine* otherLine = findTokenLocationLine(otherLineNumber);
|
||||
if (otherLine)
|
||||
{
|
||||
otherLocation = otherLine->getTokenLocationById(location->getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TokenLocation* copy = line->addTokenLocationAsPlainCopy(location);
|
||||
|
||||
// If the other location was added before, then link them with each other.
|
||||
if (otherLocation)
|
||||
{
|
||||
otherLocation->setOtherTokenLocation(copy);
|
||||
copy->setOtherTokenLocation(otherLocation);
|
||||
}
|
||||
|
||||
return copy;
|
||||
}
|
||||
|
||||
std::shared_ptr<TokenLocationFile> TokenLocationFile::getFilteredByLines(unsigned int firstLineNumber, unsigned int lastLineNumber) const
|
||||
{
|
||||
std::shared_ptr<TokenLocationFile> ret = std::make_shared<TokenLocationFile>(getFilePath().str());
|
||||
|
||||
if (getTokenLocationLines().size() == 0)
|
||||
{
|
||||
return ret;
|
||||
}
|
||||
|
||||
uint endLineNumber = getTokenLocationLines().rbegin()->first;
|
||||
std::set<Id> addedLocationIds;
|
||||
for (uint i = firstLineNumber; i <= endLineNumber; i++)
|
||||
{
|
||||
TokenLocationLine* locationLine = findTokenLocationLineByNumber(i);
|
||||
if (!locationLine)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (locationLine->getLineNumber() <= lastLineNumber)
|
||||
{
|
||||
locationLine->forEachTokenLocation(
|
||||
[&](TokenLocation* tokenLocation) -> void
|
||||
{
|
||||
const Id tokenId = tokenLocation->getId();
|
||||
if (addedLocationIds.find(tokenId) == addedLocationIds.end())
|
||||
{
|
||||
ret->addTokenLocationAsPlainCopy(tokenLocation->getStartTokenLocation());
|
||||
ret->addTokenLocationAsPlainCopy(tokenLocation->getEndTokenLocation());
|
||||
addedLocationIds.insert(tokenId);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Save start locations of TokenLocations that span accross the line range.
|
||||
locationLine->forEachTokenLocation(
|
||||
[&](TokenLocation* tokenLocation) -> void
|
||||
{
|
||||
if (tokenLocation->isEndTokenLocation() &&
|
||||
tokenLocation->getStartTokenLocation()->getLineNumber() < firstLineNumber)
|
||||
{
|
||||
ret->addTokenLocationAsPlainCopy(tokenLocation->getStartTokenLocation());
|
||||
ret->addTokenLocationAsPlainCopy(tokenLocation->getEndTokenLocation());
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
TokenLocationLine* TokenLocationFile::findTokenLocationLine(unsigned int lineNumber) const
|
||||
{
|
||||
TokenLocationLineMapType::const_iterator it = m_lines.find(lineNumber);
|
||||
|
||||
if (it != m_lines.end())
|
||||
{
|
||||
return it->second.get();
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
TokenLocationLine* TokenLocationFile::createTokenLocationLine(unsigned int lineNumber)
|
||||
{
|
||||
TokenLocationLine* line = findTokenLocationLine(lineNumber);
|
||||
|
||||
if (line)
|
||||
{
|
||||
return line;
|
||||
}
|
||||
|
||||
std::shared_ptr<TokenLocationLine> linePtr = std::make_shared<TokenLocationLine>(this, lineNumber);
|
||||
m_lines.emplace(lineNumber, linePtr);
|
||||
return linePtr.get();
|
||||
}
|
||||
|
||||
std::ostream& operator<<(std::ostream& ostream, const TokenLocationFile& file)
|
||||
{
|
||||
ostream << "file \"" << file.getFilePath().str() << "\"\n";
|
||||
file.forEachTokenLocationLine([&ostream](TokenLocationLine* l)
|
||||
{
|
||||
ostream << *l << '\n';
|
||||
});
|
||||
return ostream;
|
||||
}
|
||||
|
||||
@@ -1,60 +0,0 @@
|
||||
#ifndef TOKEN_LOCATION_FILE_H
|
||||
#define TOKEN_LOCATION_FILE_H
|
||||
|
||||
#include <functional>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <ostream>
|
||||
#include <string>
|
||||
|
||||
#include "utility/file/FilePath.h"
|
||||
#include "utility/types.h"
|
||||
|
||||
class TokenLocation;
|
||||
class TokenLocationLine;
|
||||
|
||||
class TokenLocationFile
|
||||
{
|
||||
public:
|
||||
typedef std::map<unsigned int, std::shared_ptr<TokenLocationLine>> TokenLocationLineMapType;
|
||||
typedef std::pair<unsigned int, std::shared_ptr<TokenLocationLine>> TokenLocationLinePairType;
|
||||
|
||||
TokenLocationFile(const FilePath& filePath);
|
||||
~TokenLocationFile();
|
||||
|
||||
const TokenLocationLineMapType& getTokenLocationLines() const;
|
||||
size_t getTokenLocationLineCount() const;
|
||||
size_t getUnscopedStartTokenLocationCount() const;
|
||||
|
||||
const FilePath& getFilePath() const;
|
||||
|
||||
TokenLocation* addTokenLocation(
|
||||
Id locationId, Id tokenId,
|
||||
unsigned int startLineNumber, unsigned int startColumnNumber,
|
||||
unsigned int endLineNumber, unsigned int endColumnNumber);
|
||||
void removeTokenLocation(TokenLocation* location);
|
||||
|
||||
TokenLocationLine* findTokenLocationLineByNumber(unsigned int lineNumber) const;
|
||||
|
||||
void forEachTokenLocationLine(std::function<void(TokenLocationLine*)> func) const;
|
||||
void forEachTokenLocation(std::function<void(TokenLocation*)> func) const;
|
||||
void forEachStartTokenLocation(std::function<void(TokenLocation*)> func) const;
|
||||
void forEachEndTokenLocation(std::function<void(TokenLocation*)> func) const;
|
||||
|
||||
TokenLocation* addTokenLocationAsPlainCopy(const TokenLocation* location);
|
||||
|
||||
std::shared_ptr<TokenLocationFile> getFilteredByLines(unsigned int firstLineNumber, unsigned int lastLineNumber) const;
|
||||
|
||||
bool isWholeCopy;
|
||||
|
||||
private:
|
||||
TokenLocationLine* findTokenLocationLine(unsigned int lineNumber) const;
|
||||
TokenLocationLine* createTokenLocationLine(unsigned int lineNumber);
|
||||
|
||||
std::map<unsigned int, std::shared_ptr<TokenLocationLine> > m_lines;
|
||||
FilePath m_filePath;
|
||||
};
|
||||
|
||||
std::ostream& operator<<(std::ostream& ostream, const TokenLocationFile& file);
|
||||
|
||||
#endif // TOKEN_LOCATION_FILE_H
|
||||
@@ -1,131 +0,0 @@
|
||||
#include "data/location/TokenLocationLine.h"
|
||||
|
||||
#include "data/location/TokenLocation.h"
|
||||
#include "data/location/TokenLocationFile.h"
|
||||
#include "utility/logging/logging.h"
|
||||
|
||||
TokenLocationLine::TokenLocationLine(TokenLocationFile* file, unsigned int lineNumber)
|
||||
: m_file(file)
|
||||
, m_lineNumber(lineNumber)
|
||||
{
|
||||
}
|
||||
|
||||
TokenLocationLine::~TokenLocationLine()
|
||||
{
|
||||
}
|
||||
|
||||
const TokenLocationLine::TokenLocationMapType& TokenLocationLine::getTokenLocations() const
|
||||
{
|
||||
return m_locations;
|
||||
}
|
||||
|
||||
size_t TokenLocationLine::getTokenLocationCount() const
|
||||
{
|
||||
return m_locations.size();
|
||||
}
|
||||
|
||||
TokenLocationFile* TokenLocationLine::getTokenLocationFile() const
|
||||
{
|
||||
return m_file;
|
||||
}
|
||||
|
||||
const FilePath& TokenLocationLine::getFilePath() const
|
||||
{
|
||||
return m_file->getFilePath();
|
||||
}
|
||||
|
||||
unsigned int TokenLocationLine::getLineNumber() const
|
||||
{
|
||||
return m_lineNumber;
|
||||
}
|
||||
|
||||
TokenLocation* TokenLocationLine::addStartTokenLocation(Id locationId, Id tokenId, unsigned int columnNumber)
|
||||
{
|
||||
std::shared_ptr<TokenLocation> locationPtr = std::make_shared<TokenLocation>(locationId, tokenId, this, columnNumber, true);
|
||||
m_locations.emplace(columnNumber, locationPtr);
|
||||
return locationPtr.get();
|
||||
}
|
||||
|
||||
TokenLocation* TokenLocationLine::addEndTokenLocation(TokenLocation* start, unsigned int columnNumber)
|
||||
{
|
||||
std::shared_ptr<TokenLocation> locationPtr = std::make_shared<TokenLocation>(start, this, columnNumber, false);
|
||||
start->setOtherTokenLocation(locationPtr.get());
|
||||
m_locations.emplace(columnNumber, locationPtr);
|
||||
return locationPtr.get();
|
||||
}
|
||||
|
||||
void TokenLocationLine::removeTokenLocation(TokenLocation* location)
|
||||
{
|
||||
TokenLocationMapType::iterator it = m_locations.find(location->getColumnNumber());
|
||||
|
||||
while (it->first == location->getColumnNumber())
|
||||
{
|
||||
if (it->second.get() == location)
|
||||
{
|
||||
m_locations.erase(it);
|
||||
return;
|
||||
}
|
||||
it++;
|
||||
}
|
||||
|
||||
LOG_ERROR("TokenLocation can't be removed, it's not part of the TokenLocationLine.");
|
||||
}
|
||||
|
||||
TokenLocation* TokenLocationLine::getTokenLocationById(Id id) const
|
||||
{
|
||||
for (const TokenLocationPairType& p : m_locations)
|
||||
{
|
||||
if (p.second->getId() == id)
|
||||
{
|
||||
return p.second.get();
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void TokenLocationLine::forEachTokenLocation(std::function<void(TokenLocation*)> func) const
|
||||
{
|
||||
for (const TokenLocationPairType& location : m_locations)
|
||||
{
|
||||
func(location.second.get());
|
||||
}
|
||||
}
|
||||
|
||||
void TokenLocationLine::forEachStartTokenLocation(std::function<void(TokenLocation*)> func) const
|
||||
{
|
||||
for (const TokenLocationPairType& location : m_locations)
|
||||
{
|
||||
if (location.second->isStartTokenLocation())
|
||||
{
|
||||
func(location.second.get());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TokenLocationLine::forEachEndTokenLocation(std::function<void(TokenLocation*)> func) const
|
||||
{
|
||||
for (const TokenLocationPairType& location : m_locations)
|
||||
{
|
||||
if (location.second->isEndTokenLocation())
|
||||
{
|
||||
func(location.second.get());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TokenLocation* TokenLocationLine::addTokenLocationAsPlainCopy(const TokenLocation* location)
|
||||
{
|
||||
std::shared_ptr<TokenLocation> locationPtr = std::make_shared<TokenLocation>(*location, this);
|
||||
m_locations.emplace(location->getColumnNumber(), locationPtr);
|
||||
return locationPtr.get();
|
||||
}
|
||||
|
||||
std::ostream& operator<<(std::ostream& ostream, const TokenLocationLine& line)
|
||||
{
|
||||
ostream << line.getLineNumber() << ": ";
|
||||
line.forEachTokenLocation([&ostream](TokenLocation* l)
|
||||
{
|
||||
ostream << *l;
|
||||
});
|
||||
return ostream;
|
||||
}
|
||||
@@ -1,54 +0,0 @@
|
||||
#ifndef TOKEN_LOCATION_LINE_H
|
||||
#define TOKEN_LOCATION_LINE_H
|
||||
|
||||
#include <functional>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <ostream>
|
||||
#include <string>
|
||||
|
||||
#include "utility/file/FilePath.h"
|
||||
#include "utility/types.h"
|
||||
|
||||
class TokenLocation;
|
||||
class TokenLocationFile;
|
||||
|
||||
class TokenLocationLine
|
||||
{
|
||||
public:
|
||||
typedef std::multimap<unsigned int, std::shared_ptr<TokenLocation> > TokenLocationMapType;
|
||||
typedef std::pair<unsigned int, std::shared_ptr<TokenLocation> > TokenLocationPairType;
|
||||
|
||||
TokenLocationLine(TokenLocationFile* file, unsigned int lineNumber);
|
||||
~TokenLocationLine();
|
||||
|
||||
const TokenLocationMapType& getTokenLocations() const;
|
||||
size_t getTokenLocationCount() const;
|
||||
|
||||
TokenLocationFile* getTokenLocationFile() const;
|
||||
const FilePath& getFilePath() const;
|
||||
|
||||
unsigned int getLineNumber() const;
|
||||
|
||||
TokenLocation* addStartTokenLocation(Id locationId, Id tokenId, unsigned int columnNumber);
|
||||
TokenLocation* addEndTokenLocation(TokenLocation* start, unsigned int columnNumber);
|
||||
void removeTokenLocation(TokenLocation* location);
|
||||
|
||||
TokenLocation* getTokenLocationById(Id id) const;
|
||||
|
||||
void forEachTokenLocation(std::function<void(TokenLocation*)> func) const;
|
||||
void forEachStartTokenLocation(std::function<void(TokenLocation*)> func) const;
|
||||
void forEachEndTokenLocation(std::function<void(TokenLocation*)> func) const;
|
||||
|
||||
TokenLocation* addTokenLocationAsPlainCopy(const TokenLocation* location);
|
||||
|
||||
private:
|
||||
TokenLocationMapType m_locations;
|
||||
|
||||
TokenLocationFile* const m_file;
|
||||
const unsigned int m_lineNumber;
|
||||
};
|
||||
|
||||
std::ostream& operator<<(std::ostream& ostream, const TokenLocationLine& line);
|
||||
|
||||
#endif // TOKEN_LOCATION_LINE_H
|
||||
@@ -1,11 +1,11 @@
|
||||
#include "data/parser/ParserClientImpl.h"
|
||||
|
||||
#include "data/parser/ParseLocation.h"
|
||||
#include "data/graph/Node.h"
|
||||
#include "data/graph/Edge.h"
|
||||
#include "data/graph/Node.h"
|
||||
#include "data/location/LocationType.h"
|
||||
#include "data/parser/ParseLocation.h"
|
||||
#include "utility/logging/logging.h"
|
||||
#include "utility/utility.h"
|
||||
#include "data/location/TokenLocation.h"
|
||||
|
||||
ParserClientImpl::ParserClientImpl()
|
||||
{
|
||||
|
||||
@@ -3,14 +3,14 @@
|
||||
|
||||
#include <set>
|
||||
|
||||
#include "data/graph/Node.h"
|
||||
#include "data/parser/ParserClient.h"
|
||||
#include "data/IntermediateStorage.h"
|
||||
#include "data/graph/token_component/TokenComponentAccess.h"
|
||||
|
||||
#include "data/DefinitionKind.h"
|
||||
#include "data/graph/Node.h"
|
||||
#include "data/graph/token_component/TokenComponentAccess.h"
|
||||
#include "data/IntermediateStorage.h"
|
||||
#include "data/parser/ParserClient.h"
|
||||
|
||||
class ParserClientImpl: public ParserClient
|
||||
class ParserClientImpl
|
||||
: public ParserClient
|
||||
{
|
||||
public:
|
||||
ParserClientImpl();
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
#ifndef MESSAGE_ACTIVATE_SOURCE_LOCATIONS_H
|
||||
#define MESSAGE_ACTIVATE_SOURCE_LOCATIONS_H
|
||||
|
||||
#include "utility/messaging/Message.h"
|
||||
#include "utility/types.h"
|
||||
|
||||
class MessageActivateSourceLocations
|
||||
: public Message<MessageActivateSourceLocations>
|
||||
{
|
||||
public:
|
||||
MessageActivateSourceLocations(const std::vector<Id>& locationIds)
|
||||
: locationIds(locationIds)
|
||||
{
|
||||
}
|
||||
|
||||
static const std::string getStaticType()
|
||||
{
|
||||
return "MessageActivateSourceLocations";
|
||||
}
|
||||
|
||||
virtual void print(std::ostream& os) const
|
||||
{
|
||||
for (const Id& id : locationIds)
|
||||
{
|
||||
os << id << " ";
|
||||
}
|
||||
}
|
||||
|
||||
const std::vector<Id> locationIds;
|
||||
};
|
||||
|
||||
#endif // MESSAGE_ACTIVATE_SOURCE_LOCATIONS_H
|
||||
@@ -1,32 +0,0 @@
|
||||
#ifndef MESSAGE_ACTIVATE_TOKEN_LOCATIONS_H
|
||||
#define MESSAGE_ACTIVATE_TOKEN_LOCATIONS_H
|
||||
|
||||
#include "utility/messaging/Message.h"
|
||||
#include "utility/types.h"
|
||||
|
||||
class MessageActivateTokenLocations
|
||||
: public Message<MessageActivateTokenLocations>
|
||||
{
|
||||
public:
|
||||
MessageActivateTokenLocations(const std::vector<Id>& locationIds)
|
||||
: locationIds(locationIds)
|
||||
{
|
||||
}
|
||||
|
||||
static const std::string getStaticType()
|
||||
{
|
||||
return "MessageActivateTokenLocations";
|
||||
}
|
||||
|
||||
virtual void print(std::ostream& os) const
|
||||
{
|
||||
for (const Id& id : locationIds)
|
||||
{
|
||||
os << id << " ";
|
||||
}
|
||||
}
|
||||
|
||||
const std::vector<Id> locationIds;
|
||||
};
|
||||
|
||||
#endif // MESSAGE_ACTIVATE_TOKEN_LOCATIONS_H
|
||||
@@ -84,6 +84,14 @@ namespace utility
|
||||
return false;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool shareElement(const std::set<T>& a, const std::set<T>& b)
|
||||
{
|
||||
std::set<T> c(a.begin(), a.end());
|
||||
c.insert(b.begin(), b.end());
|
||||
return a.size() + b.size() != c.size();
|
||||
}
|
||||
|
||||
bool intersectionPoint(Vec2f a1, Vec2f b1, Vec2f a2, Vec2f b2, Vec2f* i);
|
||||
|
||||
size_t digits(size_t n);
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
#include <QToolTip>
|
||||
|
||||
#include "utility/messaging/type/MessageActivateLocalSymbols.h"
|
||||
#include "utility/messaging/type/MessageActivateTokenLocations.h"
|
||||
#include "utility/messaging/type/MessageActivateSourceLocations.h"
|
||||
#include "utility/messaging/type/MessageActivateTokenIds.h"
|
||||
#include "utility/messaging/type/MessageFocusIn.h"
|
||||
#include "utility/messaging/type/MessageFocusOut.h"
|
||||
@@ -20,8 +20,8 @@
|
||||
#include "utility/messaging/type/MessageShowErrors.h"
|
||||
#include "utility/utility.h"
|
||||
|
||||
#include "data/location/TokenLocation.h"
|
||||
#include "data/location/TokenLocationFile.h"
|
||||
#include "data/location/SourceLocation.h"
|
||||
#include "data/location/SourceLocationFile.h"
|
||||
#include "qt/element/QtCodeNavigator.h"
|
||||
#include "qt/utility/QtContextMenu.h"
|
||||
#include "qt/utility/QtHighlighter.h"
|
||||
@@ -83,7 +83,7 @@ void QtCodeArea::clearAnnotationColors()
|
||||
QtCodeArea::QtCodeArea(
|
||||
uint startLineNumber,
|
||||
const std::string& code,
|
||||
std::shared_ptr<TokenLocationFile> locationFile,
|
||||
std::shared_ptr<SourceLocationFile> locationFile,
|
||||
QtCodeNavigator* navigator,
|
||||
QWidget* parent
|
||||
)
|
||||
@@ -197,7 +197,7 @@ uint QtCodeArea::getEndLineNumber() const
|
||||
return m_startLineNumber + blockCount() - 1;
|
||||
}
|
||||
|
||||
std::shared_ptr<TokenLocationFile> QtCodeArea::getTokenLocationFile() const
|
||||
std::shared_ptr<SourceLocationFile> QtCodeArea::getSourceLocationFile() const
|
||||
{
|
||||
return m_locationFile;
|
||||
}
|
||||
@@ -301,7 +301,7 @@ uint QtCodeArea::getStartLineNumberOfFirstActiveLocationOfTokenId(Id tokenId) co
|
||||
{
|
||||
if (annotation.locationType == LocationType::LOCATION_TOKEN && annotation.isActive)
|
||||
{
|
||||
if (annotation.tokenId == tokenId)
|
||||
if (annotation.tokenIds.find(tokenId) != annotation.tokenIds.end())
|
||||
{
|
||||
if (!firstActiveLine || firstActiveLine == annotation.startLine)
|
||||
{
|
||||
@@ -326,12 +326,10 @@ Id QtCodeArea::getLocationIdOfFirstActiveLocationOfTokenId(Id tokenId) const
|
||||
{
|
||||
for (const Annotation& annotation : m_annotations)
|
||||
{
|
||||
if (annotation.locationType == LocationType::LOCATION_TOKEN && annotation.isActive)
|
||||
if (annotation.locationType == LocationType::LOCATION_TOKEN && annotation.isActive &&
|
||||
annotation.tokenIds.find(tokenId) != annotation.tokenIds.end())
|
||||
{
|
||||
if (annotation.tokenId == tokenId)
|
||||
{
|
||||
return annotation.locationId;
|
||||
}
|
||||
return annotation.locationId;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -525,7 +523,7 @@ void QtCodeArea::mouseReleaseEvent(QMouseEvent* event)
|
||||
}
|
||||
else
|
||||
{
|
||||
activateTokenLocations(annotations);
|
||||
activateSourceLocations(annotations);
|
||||
activateLocalSymbols(annotations);
|
||||
}
|
||||
}
|
||||
@@ -577,9 +575,9 @@ void QtCodeArea::mouseMoveEvent(QMouseEvent* event)
|
||||
|
||||
setHoveredAnnotations(annotations);
|
||||
|
||||
if (m_navigator->hasErrors() && annotations.size() == 1)
|
||||
if (m_navigator->hasErrors() && annotations.size() == 1 && annotations[0]->tokenIds.size())
|
||||
{
|
||||
std::string errorMessage = m_navigator->getErrorMessageForId(annotations[0]->tokenId);
|
||||
std::string errorMessage = m_navigator->getErrorMessageForId(*annotations[0]->tokenIds.begin());
|
||||
QToolTip::showText(event->globalPos(), QString::fromStdString(errorMessage));
|
||||
}
|
||||
}
|
||||
@@ -681,9 +679,9 @@ std::vector<const QtCodeArea::Annotation*> QtCodeArea::getInteractiveAnnotations
|
||||
return annotations;
|
||||
}
|
||||
|
||||
void QtCodeArea::activateTokenLocations(const std::vector<const Annotation*>& annotations)
|
||||
void QtCodeArea::activateSourceLocations(const std::vector<const Annotation*>& annotations)
|
||||
{
|
||||
std::vector<Id> tokenLocationIds;
|
||||
std::vector<Id> locationIds;
|
||||
std::set<Id> tokenIds;
|
||||
|
||||
bool allActive = true;
|
||||
@@ -698,20 +696,21 @@ void QtCodeArea::activateTokenLocations(const std::vector<const Annotation*>& an
|
||||
|
||||
if (annotation->locationId > 0)
|
||||
{
|
||||
tokenLocationIds.push_back(annotation->locationId);
|
||||
locationIds.push_back(annotation->locationId);
|
||||
}
|
||||
if (annotation->tokenId > 0)
|
||||
|
||||
if (annotation->tokenIds.size())
|
||||
{
|
||||
tokenIds.insert(annotation->tokenId);
|
||||
tokenIds.insert(annotation->tokenIds.begin(), annotation->tokenIds.end());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!allActive)
|
||||
{
|
||||
if (tokenLocationIds.size())
|
||||
if (locationIds.size())
|
||||
{
|
||||
MessageActivateTokenLocations(tokenLocationIds).dispatch();
|
||||
MessageActivateSourceLocations(locationIds).dispatch();
|
||||
}
|
||||
else if (tokenIds.size()) // fallback for links in project description
|
||||
{
|
||||
@@ -734,9 +733,9 @@ void QtCodeArea::activateLocalSymbols(const std::vector<const Annotation*>& anno
|
||||
allActive = false;
|
||||
}
|
||||
|
||||
if (annotation->tokenId > 0)
|
||||
if (annotation->tokenIds.size())
|
||||
{
|
||||
localSymbolIds.push_back(annotation->tokenId);
|
||||
localSymbolIds.insert(localSymbolIds.end(), annotation->tokenIds.begin(), annotation->tokenIds.end());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -752,9 +751,9 @@ void QtCodeArea::activateErrors(const std::vector<const Annotation*>& annotation
|
||||
std::vector<Id> errorIds;
|
||||
for (const Annotation* annotation : annotations)
|
||||
{
|
||||
if (annotation->locationType == LOCATION_ERROR && annotation->tokenId > 0)
|
||||
if (annotation->locationType == LOCATION_ERROR && annotation->tokenIds.size())
|
||||
{
|
||||
errorIds.push_back(annotation->tokenId);
|
||||
errorIds.insert(errorIds.end(), annotation->tokenIds.begin(), annotation->tokenIds.end());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -764,58 +763,61 @@ void QtCodeArea::activateErrors(const std::vector<const Annotation*>& annotation
|
||||
}
|
||||
}
|
||||
|
||||
void QtCodeArea::createAnnotations(std::shared_ptr<TokenLocationFile> locationFile)
|
||||
void QtCodeArea::createAnnotations(std::shared_ptr<SourceLocationFile> locationFile)
|
||||
{
|
||||
locationFile->forEachStartTokenLocation(
|
||||
[&](TokenLocation* startLocation)
|
||||
uint endLineNumber = getEndLineNumber();
|
||||
std::set<Id> locationIds;
|
||||
|
||||
locationFile->forEachSourceLocation(
|
||||
[&](const SourceLocation* location)
|
||||
{
|
||||
if (locationIds.find(location->getLocationId()) != locationIds.end())
|
||||
{
|
||||
return;
|
||||
}
|
||||
locationIds.insert(location->getLocationId());
|
||||
|
||||
Annotation annotation;
|
||||
uint endLineNumber = getEndLineNumber();
|
||||
if (startLocation->getLineNumber() <= endLineNumber)
|
||||
|
||||
const SourceLocation* startLocation = location->getStartLocation();
|
||||
if (!startLocation || startLocation->getLineNumber() < m_startLineNumber)
|
||||
{
|
||||
if (startLocation->getLineNumber() < m_startLineNumber)
|
||||
{
|
||||
annotation.start = startTextEditPosition();
|
||||
annotation.startLine = m_startLineNumber;
|
||||
annotation.startCol = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
annotation.start = toTextEditPosition(startLocation->getLineNumber(), startLocation->getColumnNumber() - 1);
|
||||
annotation.startLine = startLocation->getLineNumber();
|
||||
annotation.startCol = startLocation->getColumnNumber() - 1;
|
||||
}
|
||||
annotation.start = startTextEditPosition();
|
||||
annotation.startLine = m_startLineNumber;
|
||||
annotation.startCol = 0;
|
||||
}
|
||||
else if (startLocation->getLineNumber() <= endLineNumber)
|
||||
{
|
||||
annotation.start = toTextEditPosition(startLocation->getLineNumber(), startLocation->getColumnNumber() - 1);
|
||||
annotation.startLine = startLocation->getLineNumber();
|
||||
annotation.startCol = startLocation->getColumnNumber() - 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
TokenLocation* endLocation = startLocation->getEndTokenLocation();
|
||||
if (endLocation->getLineNumber() >= m_startLineNumber)
|
||||
const SourceLocation* endLocation = location->getEndLocation();
|
||||
if (!endLocation || endLocation->getLineNumber() > endLineNumber)
|
||||
{
|
||||
if (endLocation->getLineNumber() > endLineNumber)
|
||||
{
|
||||
annotation.end = endTextEditPosition();
|
||||
annotation.endLine = endLineNumber;
|
||||
annotation.endCol = m_lineLengths[document()->blockCount() - 1];
|
||||
}
|
||||
else
|
||||
{
|
||||
annotation.end = toTextEditPosition(endLocation->getLineNumber(), endLocation->getColumnNumber());
|
||||
annotation.endLine = endLocation->getLineNumber();
|
||||
annotation.endCol = endLocation->getColumnNumber();
|
||||
}
|
||||
annotation.end = endTextEditPosition();
|
||||
annotation.endLine = endLineNumber;
|
||||
annotation.endCol = m_lineLengths[document()->blockCount() - 1];
|
||||
}
|
||||
else if (endLocation->getLineNumber() >= m_startLineNumber)
|
||||
{
|
||||
annotation.end = toTextEditPosition(endLocation->getLineNumber(), endLocation->getColumnNumber());
|
||||
annotation.endLine = endLocation->getLineNumber();
|
||||
annotation.endCol = endLocation->getColumnNumber();
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
annotation.tokenId = startLocation->getTokenId();
|
||||
annotation.locationId = startLocation->getId();
|
||||
|
||||
annotation.locationType = startLocation->getType();
|
||||
annotation.tokenIds.insert(location->getTokenIds().begin(), location->getTokenIds().end());
|
||||
annotation.locationId = location->getLocationId();
|
||||
annotation.locationType = location->getType();
|
||||
|
||||
annotation.isActive = false;
|
||||
annotation.isFocused = false;
|
||||
@@ -827,12 +829,12 @@ void QtCodeArea::createAnnotations(std::shared_ptr<TokenLocationFile> locationFi
|
||||
|
||||
void QtCodeArea::annotateText()
|
||||
{
|
||||
const std::vector<Id>& currentActiveTokenIds = m_navigator->getCurrentActiveTokenIds();
|
||||
const std::vector<Id>& currentActiveLocationIds = m_navigator->getCurrentActiveLocationIds();
|
||||
const std::set<Id>& currentActiveTokenIds = m_navigator->getCurrentActiveTokenIds();
|
||||
const std::set<Id>& currentActiveLocationIds = m_navigator->getCurrentActiveLocationIds();
|
||||
|
||||
const std::vector<Id>& activeTokenIds = m_navigator->getActiveTokenIds();
|
||||
const std::vector<Id>& activeLocalSymbolIds = m_navigator->getActiveLocalSymbolIds();
|
||||
const std::vector<Id>& focusIds = m_navigator->getFocusedTokenIds();
|
||||
const std::set<Id>& activeTokenIds = m_navigator->getActiveTokenIds();
|
||||
const std::set<Id>& activeLocalSymbolIds = m_navigator->getActiveLocalSymbolIds();
|
||||
const std::set<Id>& focusIds = m_navigator->getFocusedTokenIds();
|
||||
|
||||
bool needsUpdate = false;
|
||||
for (Annotation& annotation: m_annotations)
|
||||
@@ -842,15 +844,16 @@ void QtCodeArea::annotateText()
|
||||
const AnnotationColor& oldColor = getAnnotationColorForAnnotation(annotation);
|
||||
|
||||
annotation.isActive = (
|
||||
std::find(currentActiveTokenIds.begin(), currentActiveTokenIds.end(), annotation.tokenId) != currentActiveTokenIds.end() ||
|
||||
std::find(currentActiveLocationIds.begin(), currentActiveLocationIds.end(), annotation.locationId) != currentActiveLocationIds.end() ||
|
||||
std::find(activeLocalSymbolIds.begin(), activeLocalSymbolIds.end(), annotation.tokenId) != activeLocalSymbolIds.end()
|
||||
utility::shareElement(currentActiveTokenIds, annotation.tokenIds) ||
|
||||
utility::shareElement(activeLocalSymbolIds, annotation.tokenIds) ||
|
||||
currentActiveLocationIds.find(annotation.locationId) != currentActiveLocationIds.end()
|
||||
);
|
||||
|
||||
if (!annotation.isActive)
|
||||
{
|
||||
annotation.isFocused = (
|
||||
std::find(focusIds.begin(), focusIds.end(), annotation.tokenId) != focusIds.end() ||
|
||||
std::find(activeTokenIds.begin(), activeTokenIds.end(), annotation.tokenId) != activeTokenIds.end()
|
||||
utility::shareElement(focusIds, annotation.tokenIds) ||
|
||||
utility::shareElement(activeTokenIds, annotation.tokenIds)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -862,7 +865,7 @@ void QtCodeArea::annotateText()
|
||||
bool isDuplicateAnnotation = false;
|
||||
for (Annotation* a : m_colorChangedAnnotations)
|
||||
{
|
||||
if (a->start == annotation.start && a->end == annotation.end && a->tokenId != annotation.tokenId)
|
||||
if (a->start == annotation.start && a->end == annotation.end && a->locationId != annotation.locationId)
|
||||
{
|
||||
isDuplicateAnnotation = true;
|
||||
break;
|
||||
@@ -909,7 +912,7 @@ void QtCodeArea::setHoveredAnnotations(const std::vector<const Annotation*>& ann
|
||||
std::vector<Id> tokenIds;
|
||||
for (const Annotation* annotation : m_hoveredAnnotations)
|
||||
{
|
||||
tokenIds.push_back(annotation->tokenId);
|
||||
tokenIds.insert(tokenIds.end(), annotation->tokenIds.begin(), annotation->tokenIds.end());
|
||||
}
|
||||
|
||||
MessageFocusOut(tokenIds).dispatch();
|
||||
@@ -922,7 +925,7 @@ void QtCodeArea::setHoveredAnnotations(const std::vector<const Annotation*>& ann
|
||||
std::vector<Id> tokenIds;
|
||||
for (const Annotation* annotation : annotations)
|
||||
{
|
||||
tokenIds.push_back(annotation->tokenId);
|
||||
tokenIds.insert(tokenIds.end(), annotation->tokenIds.begin(), annotation->tokenIds.end());
|
||||
}
|
||||
|
||||
MessageFocusIn(tokenIds).dispatch();
|
||||
|
||||
@@ -18,8 +18,8 @@ class QSize;
|
||||
class QtCodeNavigator;
|
||||
class QtHighlighter;
|
||||
class QWidget;
|
||||
class TokenLocation;
|
||||
class TokenLocationFile;
|
||||
class SourceLocation;
|
||||
class SourceLocationFile;
|
||||
|
||||
|
||||
class MouseWheelOverScrollbarFilter
|
||||
@@ -62,7 +62,7 @@ public:
|
||||
QtCodeArea(
|
||||
uint startLineNumber,
|
||||
const std::string& code,
|
||||
std::shared_ptr<TokenLocationFile> locationFile,
|
||||
std::shared_ptr<SourceLocationFile> locationFile,
|
||||
QtCodeNavigator* navigator,
|
||||
QWidget* parent = nullptr
|
||||
);
|
||||
@@ -73,7 +73,7 @@ public:
|
||||
uint getStartLineNumber() const;
|
||||
uint getEndLineNumber() const;
|
||||
|
||||
std::shared_ptr<TokenLocationFile> getTokenLocationFile() const;
|
||||
std::shared_ptr<SourceLocationFile> getSourceLocationFile() const;
|
||||
|
||||
void lineNumberAreaPaintEvent(QPaintEvent* event);
|
||||
int lineNumberDigits() const;
|
||||
@@ -127,7 +127,7 @@ private:
|
||||
int start;
|
||||
int end;
|
||||
|
||||
Id tokenId;
|
||||
std::set<Id> tokenIds;
|
||||
Id locationId;
|
||||
|
||||
LocationType locationType;
|
||||
@@ -146,11 +146,11 @@ private:
|
||||
};
|
||||
|
||||
std::vector<const Annotation*> getInteractiveAnnotationsForPosition(int pos) const;
|
||||
void activateTokenLocations(const std::vector<const Annotation*>& annotations);
|
||||
void activateSourceLocations(const std::vector<const Annotation*>& annotations);
|
||||
void activateLocalSymbols(const std::vector<const Annotation*>& annotations);
|
||||
void activateErrors(const std::vector<const Annotation*>& annotations);
|
||||
|
||||
void createAnnotations(std::shared_ptr<TokenLocationFile> locationFile);
|
||||
void createAnnotations(std::shared_ptr<SourceLocationFile> locationFile);
|
||||
void annotateText();
|
||||
|
||||
void setHoveredAnnotations(const std::vector<const Annotation*>& annotations);
|
||||
@@ -180,7 +180,7 @@ private:
|
||||
const uint m_startLineNumber;
|
||||
const std::string m_code;
|
||||
|
||||
std::shared_ptr<TokenLocationFile> m_locationFile;
|
||||
std::shared_ptr<SourceLocationFile> m_locationFile;
|
||||
|
||||
std::vector<Annotation> m_annotations;
|
||||
std::vector<const Annotation*> m_hoveredAnnotations;
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
#include "utility/messaging/type/MessageChangeFileView.h"
|
||||
|
||||
#include "data/location/TokenLocationFile.h"
|
||||
#include "data/location/SourceLocationFile.h"
|
||||
#include "qt/element/QtCodeFileTitleButton.h"
|
||||
#include "qt/element/QtCodeNavigator.h"
|
||||
#include "qt/element/QtCodeSnippet.h"
|
||||
@@ -120,7 +120,7 @@ QtCodeSnippet* QtCodeFile::addCodeSnippet(const CodeSnippetParams& params)
|
||||
|
||||
m_snippetLayout->addWidget(snippet.get());
|
||||
|
||||
if (params.locationFile->isWholeCopy)
|
||||
if (params.locationFile->isWhole())
|
||||
{
|
||||
snippet->setProperty("isFirst", true);
|
||||
snippet->setProperty("isLast", true);
|
||||
@@ -186,7 +186,6 @@ QtCodeSnippet* QtCodeFile::insertCodeSnippet(const CodeSnippetParams& params)
|
||||
m_snippets.insert(m_snippets.begin() + i, snippet);
|
||||
|
||||
setSnippets();
|
||||
updateRefCount(params.refCount);
|
||||
|
||||
return snippet.get();
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
#include "utility/file/FileSystem.h"
|
||||
|
||||
#include "data/location/TokenLocationFile.h"
|
||||
#include "data/location/SourceLocationFile.h"
|
||||
#include "qt/element/QtCodeFile.h"
|
||||
#include "qt/element/QtCodeNavigator.h"
|
||||
#include "qt/element/QtCodeSnippet.h"
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
#include "utility/messaging/type/MessageChangeFileView.h"
|
||||
#include "utility/ResourcePaths.h"
|
||||
|
||||
#include "data/location/TokenLocationFile.h"
|
||||
#include "data/location/SourceLocationFile.h"
|
||||
#include "qt/element/QtCodeArea.h"
|
||||
#include "qt/element/QtCodeFileTitleButton.h"
|
||||
#include "qt/element/QtCodeNavigator.h"
|
||||
@@ -86,7 +86,7 @@ void QtCodeFileSingle::clearCache()
|
||||
|
||||
void QtCodeFileSingle::addCodeSnippet(const CodeSnippetParams& params, bool insert)
|
||||
{
|
||||
if (!params.locationFile->isWholeCopy)
|
||||
if (!params.locationFile->isWhole())
|
||||
{
|
||||
LOG_ERROR("Snippet params passed are not for whole file.");
|
||||
return;
|
||||
|
||||
@@ -12,9 +12,9 @@
|
||||
#include "utility/messaging/type/MessageScrollCode.h"
|
||||
#include "utility/ResourcePaths.h"
|
||||
|
||||
#include "data/location/TokenLocation.h"
|
||||
#include "data/location/TokenLocationCollection.h"
|
||||
#include "data/location/TokenLocationFile.h"
|
||||
#include "data/location/SourceLocation.h"
|
||||
#include "data/location/SourceLocationCollection.h"
|
||||
#include "data/location/SourceLocationFile.h"
|
||||
#include "qt/element/QtCodeFile.h"
|
||||
#include "qt/element/QtCodeSnippet.h"
|
||||
#include "qt/utility/QtDeviceScaledPixmap.h"
|
||||
@@ -25,6 +25,7 @@
|
||||
QtCodeNavigator::QtCodeNavigator(QWidget* parent)
|
||||
: QWidget(parent)
|
||||
, m_mode(MODE_NONE)
|
||||
, m_activeTokenId(0)
|
||||
, m_value(0)
|
||||
, m_refIndex(0)
|
||||
, m_singleHasNewFile(false)
|
||||
@@ -149,34 +150,33 @@ void QtCodeNavigator::addCodeSnippet(const CodeSnippetParams& params, bool inser
|
||||
}
|
||||
}
|
||||
|
||||
void QtCodeNavigator::addFile(std::shared_ptr<TokenLocationFile> locationFile, int refCount, TimePoint modificationTime)
|
||||
void QtCodeNavigator::addFile(std::shared_ptr<SourceLocationFile> locationFile, int refCount, TimePoint modificationTime)
|
||||
{
|
||||
m_list->addFile(locationFile->getFilePath(), locationFile->isWholeCopy, refCount, modificationTime);
|
||||
m_list->addFile(locationFile->getFilePath(), locationFile->isWhole(), refCount, modificationTime);
|
||||
|
||||
if (locationFile->isWholeCopy)
|
||||
if (locationFile->isWhole())
|
||||
{
|
||||
Reference ref;
|
||||
ref.filePath = locationFile->getFilePath();
|
||||
ref.tokenId = 0;
|
||||
ref.locationId = 0;
|
||||
ref.locationType = LOCATION_TOKEN;
|
||||
|
||||
m_references.push_back(ref);
|
||||
}
|
||||
else
|
||||
{
|
||||
locationFile->forEachStartTokenLocation(
|
||||
[&](TokenLocation* location)
|
||||
locationFile->forEachStartSourceLocation(
|
||||
[&](SourceLocation* location)
|
||||
{
|
||||
if (!location->isScopeTokenLocation())
|
||||
if (!location->isScopeLocation())
|
||||
{
|
||||
Reference ref;
|
||||
ref.filePath = location->getFilePath();
|
||||
ref.tokenId = location->getTokenId();
|
||||
ref.locationId = location->getId();
|
||||
ref.locationType = location->getType();
|
||||
for (Id i : location->getTokenIds())
|
||||
{
|
||||
Reference ref;
|
||||
ref.filePath = location->getFilePath();
|
||||
ref.tokenId = i;
|
||||
ref.locationId = location->getLocationId();
|
||||
ref.locationType = location->getType();
|
||||
|
||||
m_references.push_back(ref);
|
||||
m_references.push_back(ref);
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
@@ -207,6 +207,8 @@ void QtCodeNavigator::clearCodeSnippets()
|
||||
m_focusedTokenIds.clear();
|
||||
m_errorInfos.clear();
|
||||
|
||||
m_activeTokenId = 0;
|
||||
|
||||
if (m_references.size() && m_references[0].locationType != LOCATION_TOKEN)
|
||||
{
|
||||
clearCaches();
|
||||
@@ -224,29 +226,29 @@ void QtCodeNavigator::clearCaches()
|
||||
m_single->clearCache();
|
||||
}
|
||||
|
||||
const std::vector<Id>& QtCodeNavigator::getCurrentActiveTokenIds() const
|
||||
const std::set<Id>& QtCodeNavigator::getCurrentActiveTokenIds() const
|
||||
{
|
||||
return m_currentActiveTokenIds;
|
||||
}
|
||||
|
||||
void QtCodeNavigator::setCurrentActiveTokenIds(const std::vector<Id>& currentActiveTokenIds)
|
||||
{
|
||||
m_currentActiveTokenIds = currentActiveTokenIds;
|
||||
m_currentActiveTokenIds = std::set<Id>(currentActiveTokenIds.begin(), currentActiveTokenIds.end());
|
||||
m_currentActiveLocationIds.clear();
|
||||
}
|
||||
|
||||
const std::vector<Id>& QtCodeNavigator::getCurrentActiveLocationIds() const
|
||||
const std::set<Id>& QtCodeNavigator::getCurrentActiveLocationIds() const
|
||||
{
|
||||
return m_currentActiveLocationIds;
|
||||
}
|
||||
|
||||
void QtCodeNavigator::setCurrentActiveLocationIds(const std::vector<Id>& currentActiveLocationIds)
|
||||
{
|
||||
m_currentActiveLocationIds = currentActiveLocationIds;
|
||||
m_currentActiveLocationIds = std::set<Id>(currentActiveLocationIds.begin(), currentActiveLocationIds.end());
|
||||
m_currentActiveTokenIds.clear();
|
||||
}
|
||||
|
||||
const std::vector<Id>& QtCodeNavigator::getActiveTokenIds() const
|
||||
const std::set<Id>& QtCodeNavigator::getActiveTokenIds() const
|
||||
{
|
||||
return m_activeTokenIds;
|
||||
}
|
||||
@@ -255,28 +257,30 @@ void QtCodeNavigator::setActiveTokenIds(const std::vector<Id>& activeTokenIds)
|
||||
{
|
||||
setCurrentActiveTokenIds(activeTokenIds);
|
||||
|
||||
m_activeTokenIds = activeTokenIds;
|
||||
m_activeTokenIds = std::set<Id>(activeTokenIds.begin(), activeTokenIds.end());
|
||||
m_activeTokenId = activeTokenIds.size() ? activeTokenIds[0] : 0;
|
||||
|
||||
m_activeLocalSymbolIds.clear();
|
||||
}
|
||||
|
||||
const std::vector<Id>& QtCodeNavigator::getActiveLocalSymbolIds() const
|
||||
const std::set<Id>& QtCodeNavigator::getActiveLocalSymbolIds() const
|
||||
{
|
||||
return m_activeLocalSymbolIds;
|
||||
}
|
||||
|
||||
void QtCodeNavigator::setActiveLocalSymbolIds(const std::vector<Id>& activeLocalSymbolIds)
|
||||
{
|
||||
m_activeLocalSymbolIds = activeLocalSymbolIds;
|
||||
m_activeLocalSymbolIds = std::set<Id>(activeLocalSymbolIds.begin(), activeLocalSymbolIds.end());
|
||||
}
|
||||
|
||||
const std::vector<Id>& QtCodeNavigator::getFocusedTokenIds() const
|
||||
const std::set<Id>& QtCodeNavigator::getFocusedTokenIds() const
|
||||
{
|
||||
return m_focusedTokenIds;
|
||||
}
|
||||
|
||||
void QtCodeNavigator::setFocusedTokenIds(const std::vector<Id>& focusedTokenIds)
|
||||
{
|
||||
m_focusedTokenIds = focusedTokenIds;
|
||||
m_focusedTokenIds = std::set<Id>(focusedTokenIds.begin(), focusedTokenIds.end());
|
||||
}
|
||||
|
||||
std::string QtCodeNavigator::getErrorMessageForId(Id errorId) const
|
||||
@@ -326,7 +330,7 @@ bool QtCodeNavigator::isInListMode() const
|
||||
}
|
||||
|
||||
void QtCodeNavigator::showActiveSnippet(
|
||||
const std::vector<Id>& activeTokenIds, std::shared_ptr<TokenLocationCollection> collection, bool scrollTo)
|
||||
const std::vector<Id>& activeTokenIds, std::shared_ptr<SourceLocationCollection> collection, bool scrollTo)
|
||||
{
|
||||
if (activeTokenIds.size() != 1)
|
||||
{
|
||||
@@ -363,21 +367,31 @@ void QtCodeNavigator::showActiveSnippet(
|
||||
std::set<FilePath> filePathsToExpand;
|
||||
if (!locationIds.size())
|
||||
{
|
||||
collection->forEachTokenLocation(
|
||||
[&](TokenLocation* location)
|
||||
collection->forEachSourceLocation(
|
||||
[&](SourceLocation* location)
|
||||
{
|
||||
if (location->getTokenId() != tokenId)
|
||||
bool foundId = false;
|
||||
for (Id i : location->getTokenIds())
|
||||
{
|
||||
if (i == tokenId)
|
||||
{
|
||||
foundId = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!foundId)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
locationIds.push_back(location->getId());
|
||||
locationIds.push_back(location->getLocationId());
|
||||
filePathsToExpand.insert(location->getFilePath());
|
||||
|
||||
if (!firstReference.tokenId || filePathOrder[location->getFilePath()] < filePathOrder[firstReference.filePath])
|
||||
{
|
||||
firstReference.tokenId = location->getTokenId();
|
||||
firstReference.locationId = location->getId();
|
||||
firstReference.tokenId = tokenId;
|
||||
firstReference.locationId = location->getLocationId();
|
||||
firstReference.filePath = location->getFilePath();
|
||||
}
|
||||
}
|
||||
@@ -534,6 +548,7 @@ void QtCodeNavigator::scrollToValue(int value, bool inListMode)
|
||||
void QtCodeNavigator::scrollToLine(const FilePath& filePath, unsigned int line)
|
||||
{
|
||||
requestScroll(filePath, line, 0, false, false);
|
||||
emit scrollRequest();
|
||||
}
|
||||
|
||||
void QtCodeNavigator::scrollToDefinition(bool ignoreActiveReference)
|
||||
@@ -565,16 +580,14 @@ void QtCodeNavigator::scrollToDefinition(bool ignoreActiveReference)
|
||||
return;
|
||||
}
|
||||
|
||||
if (!m_activeTokenIds.size())
|
||||
if (!m_activeTokenId)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Id tokenId = m_activeTokenIds[0]; // The first active tokenId is the one of the active symbol itself.
|
||||
|
||||
if (m_mode == MODE_LIST)
|
||||
{
|
||||
std::pair<QtCodeSnippet*, uint> result = m_list->getFirstSnippetWithActiveLocation(tokenId);
|
||||
std::pair<QtCodeSnippet*, uint> result = m_list->getFirstSnippetWithActiveLocation(m_activeTokenId);
|
||||
if (result.first != nullptr)
|
||||
{
|
||||
requestScroll(result.first->getFile()->getFilePath(), result.second, 0, false, true);
|
||||
@@ -583,7 +596,7 @@ void QtCodeNavigator::scrollToDefinition(bool ignoreActiveReference)
|
||||
}
|
||||
else
|
||||
{
|
||||
Id locationId = m_single->getLocationIdOfFirstActiveLocationOfTokenId(tokenId);
|
||||
Id locationId = m_single->getLocationIdOfFirstActiveLocationOfTokenId(m_activeTokenId);
|
||||
if (locationId)
|
||||
{
|
||||
for (size_t i = 0; i < m_references.size(); i++)
|
||||
@@ -630,6 +643,9 @@ void QtCodeNavigator::requestScroll(const FilePath& filePath, uint lineNumber, I
|
||||
}
|
||||
}
|
||||
|
||||
// std::cout << "scroll request: " << req.filePath.str() << " " << req.lineNumber << " " << req.locationId;
|
||||
// std::cout << " " << req.animated << " " << req.onTop << std::endl;
|
||||
|
||||
m_scrollRequest = req;
|
||||
|
||||
m_singleHasNewFile = false;
|
||||
|
||||
@@ -17,8 +17,8 @@
|
||||
|
||||
class QLabel;
|
||||
class QPushButton;
|
||||
class TokenLocationCollection;
|
||||
class TokenLocationFile;
|
||||
class SourceLocationCollection;
|
||||
class SourceLocationFile;
|
||||
|
||||
class QtCodeNavigator
|
||||
: public QWidget
|
||||
@@ -35,7 +35,7 @@ public:
|
||||
virtual ~QtCodeNavigator();
|
||||
|
||||
void addCodeSnippet(const CodeSnippetParams& params, bool insert = false);
|
||||
void addFile(std::shared_ptr<TokenLocationFile> locationFile, int refCount, TimePoint modificationTime);
|
||||
void addFile(std::shared_ptr<SourceLocationFile> locationFile, int refCount, TimePoint modificationTime);
|
||||
|
||||
void addedFiles();
|
||||
|
||||
@@ -43,19 +43,19 @@ public:
|
||||
void clearCodeSnippets();
|
||||
void clearCaches();
|
||||
|
||||
const std::vector<Id>& getCurrentActiveTokenIds() const;
|
||||
const std::set<Id>& getCurrentActiveTokenIds() const;
|
||||
void setCurrentActiveTokenIds(const std::vector<Id>& currentActiveTokenIds);
|
||||
|
||||
const std::vector<Id>& getCurrentActiveLocationIds() const;
|
||||
const std::set<Id>& getCurrentActiveLocationIds() const;
|
||||
void setCurrentActiveLocationIds(const std::vector<Id>& currentActiveLocationIds);
|
||||
|
||||
const std::vector<Id>& getActiveTokenIds() const;
|
||||
const std::set<Id>& getActiveTokenIds() const;
|
||||
void setActiveTokenIds(const std::vector<Id>& activeTokenIds);
|
||||
|
||||
const std::vector<Id>& getActiveLocalSymbolIds() const;
|
||||
const std::set<Id>& getActiveLocalSymbolIds() const;
|
||||
void setActiveLocalSymbolIds(const std::vector<Id>& activeLocalSymbolIds);
|
||||
|
||||
const std::vector<Id>& getFocusedTokenIds() const;
|
||||
const std::set<Id>& getFocusedTokenIds() const;
|
||||
void setFocusedTokenIds(const std::vector<Id>& focusedTokenIds);
|
||||
|
||||
std::string getErrorMessageForId(Id errorId) const;
|
||||
@@ -67,7 +67,7 @@ public:
|
||||
bool isInListMode() const;
|
||||
|
||||
void showActiveSnippet(
|
||||
const std::vector<Id>& activeTokenIds, std::shared_ptr<TokenLocationCollection> collection, bool scrollTo);
|
||||
const std::vector<Id>& activeTokenIds, std::shared_ptr<SourceLocationCollection> collection, bool scrollTo);
|
||||
|
||||
void focusTokenIds(const std::vector<Id>& focusedTokenIds);
|
||||
void defocusTokenIds();
|
||||
@@ -119,6 +119,7 @@ private:
|
||||
Reference()
|
||||
: tokenId(0)
|
||||
, locationId(0)
|
||||
, locationType(LOCATION_TOKEN)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -163,14 +164,16 @@ private:
|
||||
|
||||
Mode m_mode;
|
||||
|
||||
std::vector<Id> m_currentActiveTokenIds;
|
||||
std::vector<Id> m_currentActiveLocationIds;
|
||||
std::set<Id> m_currentActiveTokenIds;
|
||||
std::set<Id> m_currentActiveLocationIds;
|
||||
|
||||
std::vector<Id> m_activeTokenIds;
|
||||
std::vector<Id> m_activeLocalSymbolIds;
|
||||
std::vector<Id> m_focusedTokenIds;
|
||||
std::set<Id> m_activeTokenIds;
|
||||
std::set<Id> m_activeLocalSymbolIds;
|
||||
std::set<Id> m_focusedTokenIds;
|
||||
std::map<Id, ErrorInfo> m_errorInfos;
|
||||
|
||||
Id m_activeTokenId;
|
||||
|
||||
int m_value;
|
||||
|
||||
QPushButton* m_listButton;
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
#include "utility/messaging/type/MessageShowScope.h"
|
||||
#include "utility/text/TextAccess.h"
|
||||
|
||||
#include "data/location/TokenLocationFile.h"
|
||||
#include "data/location/SourceLocationFile.h"
|
||||
#include "qt/element/QtCodeNavigator.h"
|
||||
#include "qt/element/QtCodeFile.h"
|
||||
|
||||
@@ -17,22 +17,22 @@ std::shared_ptr<QtCodeSnippet> QtCodeSnippet::merged(
|
||||
QtCodeSnippet* first = a->getStartLineNumber() < b->getStartLineNumber() ? a : b;
|
||||
QtCodeSnippet* second = a->getStartLineNumber() > b->getStartLineNumber() ? a : b;
|
||||
|
||||
TokenLocationFile* aFile = a->m_codeArea->getTokenLocationFile().get();
|
||||
TokenLocationFile* bFile = b->m_codeArea->getTokenLocationFile().get();
|
||||
SourceLocationFile* aFile = a->m_codeArea->getSourceLocationFile().get();
|
||||
SourceLocationFile* bFile = b->m_codeArea->getSourceLocationFile().get();
|
||||
|
||||
std::shared_ptr<TokenLocationFile> locationFile = std::make_shared<TokenLocationFile>(aFile->getFilePath());
|
||||
std::shared_ptr<SourceLocationFile> locationFile = std::make_shared<SourceLocationFile>(aFile->getFilePath(), aFile->isWhole());
|
||||
|
||||
aFile->forEachTokenLocation(
|
||||
[&locationFile](TokenLocation* loc)
|
||||
aFile->forEachSourceLocation(
|
||||
[&locationFile](SourceLocation* loc)
|
||||
{
|
||||
locationFile->addTokenLocationAsPlainCopy(loc);
|
||||
locationFile->addSourceLocationCopy(loc);
|
||||
}
|
||||
);
|
||||
|
||||
bFile->forEachTokenLocation(
|
||||
[&locationFile](TokenLocation* loc)
|
||||
bFile->forEachSourceLocation(
|
||||
[&locationFile](SourceLocation* loc)
|
||||
{
|
||||
locationFile->addTokenLocationAsPlainCopy(loc);
|
||||
locationFile->addSourceLocationCopy(loc);
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ class QBoxLayout;
|
||||
class QPushButton;
|
||||
class QtCodeFile;
|
||||
class QtCodeNavigator;
|
||||
class TokenLocationFile;
|
||||
class SourceLocationFile;
|
||||
|
||||
class QtCodeSnippet
|
||||
: public QFrame
|
||||
|
||||
@@ -105,7 +105,7 @@ void QtCodeView::setFileState(const FilePath filePath, FileState state)
|
||||
}
|
||||
|
||||
void QtCodeView::showActiveSnippet(
|
||||
const std::vector<Id>& activeTokenIds, std::shared_ptr<TokenLocationCollection> collection, bool scrollTo)
|
||||
const std::vector<Id>& activeTokenIds, std::shared_ptr<SourceLocationCollection> collection, bool scrollTo)
|
||||
{
|
||||
m_doShowActiveSnippetFunctor(activeTokenIds, collection, scrollTo);
|
||||
}
|
||||
@@ -241,7 +241,7 @@ void QtCodeView::doSetFileState(const FilePath filePath, FileState state)
|
||||
}
|
||||
|
||||
void QtCodeView::doShowActiveSnippet(
|
||||
const std::vector<Id>& activeTokenIds, std::shared_ptr<TokenLocationCollection> collection, bool scrollTo)
|
||||
const std::vector<Id>& activeTokenIds, std::shared_ptr<SourceLocationCollection> collection, bool scrollTo)
|
||||
{
|
||||
m_widget->showActiveSnippet(activeTokenIds, collection, scrollTo);
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ public:
|
||||
virtual void setFileState(const FilePath filePath, FileState state);
|
||||
|
||||
virtual void showActiveSnippet(
|
||||
const std::vector<Id>& activeTokenIds, std::shared_ptr<TokenLocationCollection> collection, bool scrollTo);
|
||||
const std::vector<Id>& activeTokenIds, std::shared_ptr<SourceLocationCollection> collection, bool scrollTo);
|
||||
virtual void showActiveTokenIds(const std::vector<Id>& activeTokenIds);
|
||||
virtual void showActiveLocalSymbolIds(const std::vector<Id>& activeLocalSymbolIds);
|
||||
|
||||
@@ -62,7 +62,7 @@ private:
|
||||
void doSetFileState(const FilePath filePath, FileState state);
|
||||
|
||||
void doShowActiveSnippet(
|
||||
const std::vector<Id>& activeTokenIds, std::shared_ptr<TokenLocationCollection> collection, bool scrollTo);
|
||||
const std::vector<Id>& activeTokenIds, std::shared_ptr<SourceLocationCollection> collection, bool scrollTo);
|
||||
void doShowActiveTokenIds(const std::vector<Id>& activeTokenIds);
|
||||
void doShowActiveLocalSymbolIds(const std::vector<Id>& localSymbolIds);
|
||||
|
||||
@@ -73,7 +73,7 @@ private:
|
||||
QtThreadedFunctor<const std::vector<CodeSnippetParams>&, const std::vector<Id>&, bool> m_showCodeSnippetsFunctor;
|
||||
QtThreadedFunctor<const std::vector<CodeSnippetParams>&, bool> m_addCodeSnippetsFunctor;
|
||||
QtThreadedFunctor<const FilePath, FileState> m_setFileStateFunctor;
|
||||
QtThreadedFunctor<const std::vector<Id>&, std::shared_ptr<TokenLocationCollection>, bool> m_doShowActiveSnippetFunctor;
|
||||
QtThreadedFunctor<const std::vector<Id>&, std::shared_ptr<SourceLocationCollection>, bool> m_doShowActiveSnippetFunctor;
|
||||
QtThreadedFunctor<const std::vector<Id>&> m_doShowActiveTokenIdsFunctor;
|
||||
QtThreadedFunctor<const std::vector<Id>&> m_doShowActiveLocalSymbolIdsFunctor;
|
||||
QtThreadedFunctor<const std::vector<Id>&> m_focusTokenIdsFunctor;
|
||||
|
||||
@@ -23,11 +23,11 @@ add_files(
|
||||
SettingsTestSuite.h
|
||||
SettingsMigratorTestSuite.h
|
||||
SearchIndexTestSuite.h
|
||||
SourceLocationCollectionTestSuite.h
|
||||
SqliteStorageTestSuite.h
|
||||
StorageTestSuite.h
|
||||
TaskSchedulerTestSuite.h
|
||||
TextAccessTestSuite.h
|
||||
TokenLocationCollectionTestSuite.h
|
||||
UtilityStringTestSuite.h
|
||||
Vector2TestSuite.h
|
||||
JavaParserTestSuite.h
|
||||
|
||||
@@ -0,0 +1,170 @@
|
||||
#include "cxxtest/TestSuite.h"
|
||||
|
||||
#include "data/location/SourceLocation.h"
|
||||
#include "data/location/SourceLocationCollection.h"
|
||||
#include "data/location/SourceLocationFile.h"
|
||||
|
||||
class SourceLocationCollectionTestSuite : public CxxTest::TestSuite
|
||||
{
|
||||
public:
|
||||
void test_source_locations_get_created_with_other_end()
|
||||
{
|
||||
SourceLocationCollection collection;
|
||||
const SourceLocation* a = collection.addSourceLocation(LOCATION_TOKEN, 1, {1}, "file.c", 2, 3, 4, 5);
|
||||
|
||||
TS_ASSERT(a);
|
||||
TS_ASSERT(a->isStartLocation());
|
||||
TS_ASSERT(!a->isEndLocation());
|
||||
|
||||
const SourceLocation* b = a->getOtherLocation();
|
||||
|
||||
TS_ASSERT(b);
|
||||
TS_ASSERT(!b->isStartLocation());
|
||||
TS_ASSERT(b->isEndLocation());
|
||||
|
||||
TS_ASSERT_EQUALS(a, b->getOtherLocation());
|
||||
TS_ASSERT_EQUALS(a, b->getStartLocation());
|
||||
TS_ASSERT_EQUALS(a, a->getStartLocation());
|
||||
TS_ASSERT_EQUALS(b, a->getEndLocation());
|
||||
TS_ASSERT_EQUALS(b, b->getEndLocation());
|
||||
}
|
||||
|
||||
void test_source_locations_do_not_get_created_with_wrong_input()
|
||||
{
|
||||
SourceLocationCollection collection;
|
||||
SourceLocation* a = collection.addSourceLocation(LOCATION_TOKEN, 1, {1}, "file.c", 2, 3, 2, 1);
|
||||
SourceLocation* b = collection.addSourceLocation(LOCATION_TOKEN, 2, {1}, "file.c", 4, 1, 1, 10);
|
||||
|
||||
TS_ASSERT(!a);
|
||||
TS_ASSERT(!b);
|
||||
}
|
||||
|
||||
void test_source_locations_get_unique_id_but_both_ends_have_the_same()
|
||||
{
|
||||
SourceLocationCollection collection;
|
||||
SourceLocation* a = collection.addSourceLocation(LOCATION_TOKEN, 1, {1}, "file.c", 1, 1, 1, 1);
|
||||
SourceLocation* b = collection.addSourceLocation(LOCATION_TOKEN, 2, {2}, "file.c", 1, 1, 1, 1);
|
||||
SourceLocation* c = collection.addSourceLocation(LOCATION_TOKEN, 3, {3}, "file.c", 1, 1, 1, 1);
|
||||
|
||||
TS_ASSERT_EQUALS(1, collection.getSourceLocationFileCount());
|
||||
TS_ASSERT_EQUALS(3, collection.getSourceLocationCount());
|
||||
|
||||
TS_ASSERT_EQUALS(a->getLocationId(), 1);
|
||||
TS_ASSERT_EQUALS(b->getLocationId(), 2);
|
||||
TS_ASSERT_EQUALS(c->getLocationId(), 3);
|
||||
|
||||
TS_ASSERT_DIFFERS(a->getLocationId(), b->getLocationId());
|
||||
TS_ASSERT_DIFFERS(b->getLocationId(), c->getLocationId());
|
||||
TS_ASSERT_DIFFERS(c->getLocationId(), a->getLocationId());
|
||||
|
||||
TS_ASSERT_EQUALS(a->getLocationId(), a->getOtherLocation()->getLocationId());
|
||||
TS_ASSERT_EQUALS(b->getLocationId(), b->getOtherLocation()->getLocationId());
|
||||
TS_ASSERT_EQUALS(c->getLocationId(), c->getOtherLocation()->getLocationId());
|
||||
}
|
||||
|
||||
void test_source_locations_have_right_file_path_line_column_and_token_id()
|
||||
{
|
||||
SourceLocationCollection collection;
|
||||
SourceLocation* a = collection.addSourceLocation(LOCATION_TOKEN, 1, {1}, "file.c", 2, 3, 4, 5);
|
||||
|
||||
TS_ASSERT_EQUALS(1, a->getTokenIds()[0]);
|
||||
TS_ASSERT_EQUALS(2, a->getLineNumber());
|
||||
TS_ASSERT_EQUALS(3, a->getColumnNumber());
|
||||
TS_ASSERT_EQUALS(4, a->getOtherLocation()->getLineNumber());
|
||||
TS_ASSERT_EQUALS(5, a->getOtherLocation()->getColumnNumber());
|
||||
TS_ASSERT_EQUALS("file.c", a->getFilePath().str());
|
||||
}
|
||||
|
||||
void test_finding_source_locations_by_id()
|
||||
{
|
||||
SourceLocationCollection collection;
|
||||
SourceLocation* a = collection.addSourceLocation(LOCATION_TOKEN, 1, {1}, "file.c", 2, 3, 4, 5);
|
||||
SourceLocation* b = collection.addSourceLocation(LOCATION_TOKEN, 2, {6}, "file.c", 7, 8, 9, 10);
|
||||
|
||||
TS_ASSERT_EQUALS(a, collection.getSourceLocationById(a->getLocationId()));
|
||||
TS_ASSERT_EQUALS(b, collection.getSourceLocationById(b->getLocationId()));
|
||||
}
|
||||
|
||||
void test_creating_plain_copy_of_all_locations_in_line_range()
|
||||
{
|
||||
SourceLocationCollection collection;
|
||||
SourceLocation* a = collection.addSourceLocation(LOCATION_TOKEN, 1, {1}, "file.c", 2, 3, 4, 5);
|
||||
SourceLocation* b = collection.addSourceLocation(LOCATION_TOKEN, 2, {1}, "file.c", 3, 3, 4, 5);
|
||||
SourceLocation* c = collection.addSourceLocation(LOCATION_TOKEN, 3, {1}, "file.c", 1, 3, 5, 5);
|
||||
SourceLocation* d = collection.addSourceLocation(LOCATION_TOKEN, 4, {1}, "file.c", 1, 5, 4, 5);
|
||||
|
||||
Id ida = a->getLocationId();
|
||||
Id idb = b->getLocationId();
|
||||
Id idc = c->getLocationId();
|
||||
Id idd = d->getLocationId();
|
||||
|
||||
unsigned int fromLine = 2;
|
||||
unsigned int toLine = 4;
|
||||
|
||||
SourceLocationCollection copy;
|
||||
SourceLocation* x = collection.getSourceLocationById(ida);
|
||||
|
||||
x->getSourceLocationFile()->forEachSourceLocation(
|
||||
[©, fromLine, toLine](SourceLocation* location)
|
||||
{
|
||||
if (location->getLineNumber() >= fromLine && location->getLineNumber() <= toLine)
|
||||
{
|
||||
copy.addSourceLocationCopy(location);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
TS_ASSERT_EQUALS(1, copy.getSourceLocationFileCount());
|
||||
TS_ASSERT_EQUALS(3, copy.getSourceLocationCount());
|
||||
|
||||
TS_ASSERT(copy.getSourceLocationById(ida));
|
||||
TS_ASSERT(copy.getSourceLocationById(idb));
|
||||
TS_ASSERT(!copy.getSourceLocationById(idc));
|
||||
TS_ASSERT(copy.getSourceLocationById(idd));
|
||||
|
||||
TS_ASSERT_DIFFERS(a, copy.getSourceLocationById(ida));
|
||||
TS_ASSERT_DIFFERS(d, copy.getSourceLocationById(idd));
|
||||
|
||||
TS_ASSERT(copy.getSourceLocationById(ida)->getStartLocation());
|
||||
TS_ASSERT(copy.getSourceLocationById(ida)->getEndLocation());
|
||||
|
||||
TS_ASSERT(!copy.getSourceLocationById(idd)->getStartLocation());
|
||||
TS_ASSERT(copy.getSourceLocationById(idd)->getEndLocation());
|
||||
}
|
||||
|
||||
void test_get_source_locations_filtered_by_lines()
|
||||
{
|
||||
SourceLocationCollection collection;
|
||||
SourceLocation* a = collection.addSourceLocation(LOCATION_TOKEN, 1, {1}, "file.c", 1, 3, 1, 5);
|
||||
SourceLocation* b = collection.addSourceLocation(LOCATION_TOKEN, 2, {1}, "file.c", 1, 3, 2, 5);
|
||||
SourceLocation* c = collection.addSourceLocation(LOCATION_TOKEN, 3, {1}, "file.c", 2, 3, 2, 5);
|
||||
SourceLocation* d = collection.addSourceLocation(LOCATION_TOKEN, 4, {1}, "file.c", 3, 3, 4, 5);
|
||||
SourceLocation* e = collection.addSourceLocation(LOCATION_TOKEN, 5, {1}, "file.c", 3, 5, 5, 5);
|
||||
SourceLocation* f = collection.addSourceLocation(LOCATION_TOKEN, 6, {1}, "file.c", 1, 5, 5, 5);
|
||||
SourceLocation* g = collection.addSourceLocation(LOCATION_TOKEN, 7, {1}, "file.c", 5, 5, 5, 5);
|
||||
|
||||
SourceLocationCollection copy;
|
||||
copy.addSourceLocationFile(
|
||||
collection.getSourceLocationById(a->getLocationId())->getSourceLocationFile()->getFilteredByLines(2, 4));
|
||||
|
||||
TS_ASSERT_EQUALS(1, copy.getSourceLocationFileCount());
|
||||
TS_ASSERT_EQUALS(4, copy.getSourceLocationCount());
|
||||
|
||||
TS_ASSERT(!copy.getSourceLocationById(a->getLocationId()));
|
||||
TS_ASSERT(copy.getSourceLocationById(b->getLocationId()));
|
||||
TS_ASSERT(copy.getSourceLocationById(c->getLocationId()));
|
||||
TS_ASSERT(copy.getSourceLocationById(d->getLocationId()));
|
||||
TS_ASSERT(copy.getSourceLocationById(e->getLocationId()));
|
||||
TS_ASSERT(!copy.getSourceLocationById(f->getLocationId()));
|
||||
TS_ASSERT(!copy.getSourceLocationById(g->getLocationId()));
|
||||
|
||||
TS_ASSERT_DIFFERS(b, copy.getSourceLocationById(b->getLocationId()));
|
||||
TS_ASSERT_DIFFERS(c, copy.getSourceLocationById(c->getLocationId()));
|
||||
|
||||
TS_ASSERT(!copy.getSourceLocationById(b->getLocationId())->getStartLocation());
|
||||
TS_ASSERT(copy.getSourceLocationById(b->getLocationId())->getEndLocation());
|
||||
|
||||
TS_ASSERT(copy.getSourceLocationById(e->getLocationId())->getStartLocation());
|
||||
TS_ASSERT(!copy.getSourceLocationById(e->getLocationId())->getEndLocation());
|
||||
}
|
||||
};
|
||||
@@ -5,7 +5,6 @@
|
||||
#include "data/graph/token_component/TokenComponentAbstraction.h"
|
||||
#include "data/graph/token_component/TokenComponentAccess.h"
|
||||
#include "data/graph/token_component/TokenComponentStatic.h"
|
||||
#include "data/location/TokenLocation.h"
|
||||
#include "data/parser/ParseLocation.h"
|
||||
#include "data/PersistentStorage.h"
|
||||
|
||||
@@ -238,13 +237,6 @@ private:
|
||||
clear();
|
||||
}
|
||||
|
||||
std::shared_ptr<TokenLocationCollection> getLocationCollectionForTokenId(Id id) const
|
||||
{
|
||||
std::vector<Id> tokenIds;
|
||||
tokenIds.push_back(id);
|
||||
return getTokenLocationsForTokenIds(tokenIds);
|
||||
}
|
||||
|
||||
//const size_t getNodeCount() const
|
||||
//{
|
||||
// return getGraph().getNodeCount();
|
||||
@@ -268,14 +260,6 @@ private:
|
||||
return ParseLocation(m_filePath, 1, locationId, 1, locationId);
|
||||
}
|
||||
|
||||
bool isValidLocation(TokenLocation* location, Id locationId) const
|
||||
{
|
||||
return
|
||||
location->getFilePath() == m_filePath &&
|
||||
location->getLineNumber() == 1 &&
|
||||
location->getColumnNumber() == locationId;
|
||||
}
|
||||
|
||||
NameHierarchy createFunctionNameHierarchy(std::string ret, std::string name, std::string parameters) const
|
||||
{
|
||||
NameHierarchy nameHierarchy = createNameHierarchy(name);
|
||||
|
||||
@@ -1,162 +0,0 @@
|
||||
#include "cxxtest/TestSuite.h"
|
||||
|
||||
#include "data/location/TokenLocation.h"
|
||||
#include "data/location/TokenLocationCollection.h"
|
||||
#include "data/location/TokenLocationFile.h"
|
||||
#include "data/location/TokenLocationLine.h"
|
||||
|
||||
class TokenLocationCollectionTestSuite : public CxxTest::TestSuite
|
||||
{
|
||||
public:
|
||||
void test_token_locations_get_created_with_other_end()
|
||||
{
|
||||
TokenLocationCollection collection;
|
||||
TokenLocation* a = collection.addTokenLocation(1, 1, "file.c", 2, 3, 4, 5);
|
||||
|
||||
TS_ASSERT(a);
|
||||
TS_ASSERT(a->isStartTokenLocation());
|
||||
TS_ASSERT(!a->isEndTokenLocation());
|
||||
|
||||
TokenLocation* b = a->getOtherTokenLocation();
|
||||
|
||||
TS_ASSERT(b);
|
||||
TS_ASSERT(!b->isStartTokenLocation());
|
||||
TS_ASSERT(b->isEndTokenLocation());
|
||||
|
||||
TS_ASSERT_EQUALS(a, b->getOtherTokenLocation());
|
||||
TS_ASSERT_EQUALS(a, b->getStartTokenLocation());
|
||||
TS_ASSERT_EQUALS(a, a->getStartTokenLocation());
|
||||
TS_ASSERT_EQUALS(b, a->getEndTokenLocation());
|
||||
TS_ASSERT_EQUALS(b, b->getEndTokenLocation());
|
||||
}
|
||||
|
||||
void test_token_locations_do_not_get_created_with_wrong_input()
|
||||
{
|
||||
TokenLocationCollection collection;
|
||||
TokenLocation* a = collection.addTokenLocation(1, 1, "file.c", 2, 3, 2, 1);
|
||||
TokenLocation* b = collection.addTokenLocation(2, 1, "file.c", 4, 1, 1, 10);
|
||||
|
||||
TS_ASSERT(!a);
|
||||
TS_ASSERT(!b);
|
||||
}
|
||||
|
||||
void test_token_locations_get_unique_id_but_both_ends_have_the_same()
|
||||
{
|
||||
TokenLocationCollection collection;
|
||||
TokenLocation* a = collection.addTokenLocation(1, 1, "file.c", 1, 1, 1, 1);
|
||||
TokenLocation* b = collection.addTokenLocation(2, 2, "file.c", 1, 1, 1, 1);
|
||||
TokenLocation* c = collection.addTokenLocation(3, 3, "file.c", 1, 1, 1, 1);
|
||||
|
||||
TS_ASSERT_EQUALS(1, collection.getTokenLocationFileCount());
|
||||
TS_ASSERT_EQUALS(3, collection.getTokenLocationCount());
|
||||
|
||||
TS_ASSERT_DIFFERS(a->getId(), b->getId());
|
||||
TS_ASSERT_DIFFERS(b->getId(), c->getId());
|
||||
TS_ASSERT_DIFFERS(c->getId(), a->getId());
|
||||
|
||||
TS_ASSERT_EQUALS(a->getId(), a->getOtherTokenLocation()->getId());
|
||||
TS_ASSERT_EQUALS(b->getId(), b->getOtherTokenLocation()->getId());
|
||||
TS_ASSERT_EQUALS(c->getId(), c->getOtherTokenLocation()->getId());
|
||||
}
|
||||
|
||||
void test_token_locations_have_right_file_path_line_column_and_token_id()
|
||||
{
|
||||
TokenLocationCollection collection;
|
||||
TokenLocation* a = collection.addTokenLocation(1, 1, "file.c", 2, 3, 4, 5);
|
||||
|
||||
TS_ASSERT_EQUALS(1, a->getTokenId());
|
||||
TS_ASSERT_EQUALS(2, a->getLineNumber());
|
||||
TS_ASSERT_EQUALS(3, a->getColumnNumber());
|
||||
TS_ASSERT_EQUALS(4, a->getOtherTokenLocation()->getLineNumber());
|
||||
TS_ASSERT_EQUALS(5, a->getOtherTokenLocation()->getColumnNumber());
|
||||
TS_ASSERT_EQUALS("file.c", a->getFilePath().str());
|
||||
}
|
||||
|
||||
void test_finding_token_locations_by_id()
|
||||
{
|
||||
TokenLocationCollection collection;
|
||||
TokenLocation* a = collection.addTokenLocation(1, 1, "file.c", 2, 3, 4, 5);
|
||||
TokenLocation* b = collection.addTokenLocation(2, 6, "file.c", 7, 8, 9, 10);
|
||||
|
||||
TS_ASSERT_EQUALS(a, collection.findTokenLocationById(a->getId()));
|
||||
TS_ASSERT_EQUALS(b, collection.findTokenLocationById(b->getId()));
|
||||
}
|
||||
|
||||
void test_removing_token_locations()
|
||||
{
|
||||
TokenLocationCollection collection;
|
||||
TokenLocation* a = collection.addTokenLocation(1, 1, "file.c", 2, 3, 4, 5);
|
||||
TokenLocation* b = collection.addTokenLocation(2, 1, "file.c", 3, 3, 4, 5);
|
||||
TokenLocation* c = collection.addTokenLocation(3, 1, "file.c", 1, 3, 5, 5);
|
||||
TokenLocation* d = collection.addTokenLocation(4, 1, "file2.c", 1, 3, 5, 5);
|
||||
|
||||
TS_ASSERT_EQUALS(2, collection.getTokenLocationFileCount());
|
||||
TS_ASSERT_EQUALS(4, collection.getTokenLocationCount());
|
||||
TS_ASSERT_EQUALS(5, c->getTokenLocationFile()->getTokenLocationLineCount());
|
||||
|
||||
Id ida = a->getId();
|
||||
Id idb = b->getId();
|
||||
Id idc = c->getId();
|
||||
|
||||
collection.removeTokenLocation(a);
|
||||
collection.removeTokenLocation(b->getOtherTokenLocation());
|
||||
collection.removeTokenLocation(d);
|
||||
|
||||
TS_ASSERT(!collection.findTokenLocationById(ida));
|
||||
TS_ASSERT(!collection.findTokenLocationById(idb));
|
||||
TS_ASSERT_EQUALS(c, collection.findTokenLocationById(idc));
|
||||
|
||||
TS_ASSERT_EQUALS(1, collection.getTokenLocationFileCount());
|
||||
TS_ASSERT_EQUALS(1, collection.getTokenLocationCount());
|
||||
TS_ASSERT_EQUALS(2, c->getTokenLocationFile()->getTokenLocationLineCount());
|
||||
}
|
||||
|
||||
void test_creating_plain_copy_of_all_locations_in_line_range()
|
||||
{
|
||||
TokenLocationCollection collection;
|
||||
TokenLocation* a = collection.addTokenLocation(1, 1, "file.c", 2, 3, 4, 5);
|
||||
TokenLocation* b = collection.addTokenLocation(2, 1, "file.c", 3, 3, 4, 5);
|
||||
TokenLocation* c = collection.addTokenLocation(3, 1, "file.c", 1, 3, 5, 5);
|
||||
TokenLocation* d = collection.addTokenLocation(4, 1, "file.c", 1, 5, 4, 5);
|
||||
|
||||
Id ida = a->getId();
|
||||
Id idb = b->getId();
|
||||
Id idc = c->getId();
|
||||
Id idd = d->getId();
|
||||
|
||||
unsigned int fromLine = 2;
|
||||
unsigned int toLine = 4;
|
||||
|
||||
TokenLocationCollection copy;
|
||||
TokenLocation* x = collection.findTokenLocationById(ida);
|
||||
|
||||
x->getTokenLocationFile()->forEachTokenLocationLine([©, fromLine, toLine](TokenLocationLine* line)
|
||||
{
|
||||
unsigned int l = line->getLineNumber();
|
||||
if (l >= fromLine && l <= toLine)
|
||||
{
|
||||
line->forEachTokenLocation([©](TokenLocation* location)
|
||||
{
|
||||
copy.addTokenLocationAsPlainCopy(location);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
TS_ASSERT_EQUALS(1, copy.getTokenLocationFileCount());
|
||||
TS_ASSERT_EQUALS(3, copy.getTokenLocationCount());
|
||||
|
||||
TS_ASSERT(copy.findTokenLocationById(ida));
|
||||
TS_ASSERT(copy.findTokenLocationById(idb));
|
||||
TS_ASSERT(!copy.findTokenLocationById(idc));
|
||||
TS_ASSERT(copy.findTokenLocationById(idd));
|
||||
|
||||
TS_ASSERT_DIFFERS(a, copy.findTokenLocationById(ida));
|
||||
TS_ASSERT_DIFFERS(d, copy.findTokenLocationById(idd));
|
||||
|
||||
TS_ASSERT(copy.findTokenLocationById(ida)->getStartTokenLocation());
|
||||
TS_ASSERT(copy.findTokenLocationById(ida)->getEndTokenLocation());
|
||||
|
||||
TS_ASSERT(!copy.findTokenLocationById(idd)->getStartTokenLocation());
|
||||
TS_ASSERT(copy.findTokenLocationById(idd)->getEndTokenLocation());
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user