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:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user