logic: code controller

- Renamed MessageActivateTokenLocation to MessageActivateToken, since it uses the Token id (not the TokenLocation id).
- Implemented CodeController to add one snippet for each location where the activated token occurred.
- Added Semaphore to QtThreadedFunctor to prevent an evil race-condition.
- CodeView dispatches message when a token is clicked.
This commit is contained in:
malte_langkabel
2014-07-03 16:03:06 +02:00
parent 4c7bbbe28e
commit 4ae6f4a04a
17 changed files with 183 additions and 44 deletions
+51 -4
View File
@@ -3,6 +3,8 @@
#include <sstream>
#include "data/location/TokenLocation.h"
#include "data/location/TokenLocationFile.h"
#include "data/location/TokenLocationLine.h"
#include "data/parser/ParseLocation.h"
#include "data/parser/ParseVariable.h"
#include "utility/logging/logging.h"
@@ -173,14 +175,59 @@ void Storage::logLocations() const
LOG_INFO(str.str());
}
Token* Storage::getToken(Id tokenId)
Token* Storage::getToken(Id tokenId) const
{
return m_graph.getTokenById(tokenId);
return m_graph.getTokenById(tokenId); // Todo: copy information.
}
TokenLocation* Storage::getTokenLocation(Id locationId)
TokenLocationCollection Storage::getTokenLocationsForTokenId(Id id) const
{
return m_locationCollection.findTokenLocationById(locationId);
TokenLocationCollection ret;
std::vector<Id> locationIds = m_graph.getTokenById(id)->getLocationIds();
for (Id locationId: locationIds)
{
TokenLocation* location = m_locationCollection.findTokenLocationById(locationId);
if (location->getOtherTokenLocation())
{
ret.addTokenLocationAsPlainCopy(location);
ret.addTokenLocationAsPlainCopy(location->getOtherTokenLocation());
}
}
return ret;
}
TokenLocationFile Storage::getTokenLocationsForLinesInFile(
const std::string& fileName, unsigned int firstLineNumber, unsigned int lastLineNumber
) const
{
TokenLocationFile ret(fileName);
TokenLocationFile* locationFile = m_locationCollection.findTokenLocationFileByPath(fileName);
if (locationFile)
{
for (unsigned int i = firstLineNumber; i <= lastLineNumber; i++)
{
TokenLocationLine* locationLine = locationFile->findTokenLocationLineByNumber(i);
if (locationLine)
{
locationLine->forEachTokenLocation([&] (TokenLocation* tokenLocation) -> void {
if (tokenLocation->getOtherTokenLocation() &&
tokenLocation->isStartTokenLocation() &&
tokenLocation->getLineNumber() >= firstLineNumber &&
tokenLocation->getOtherTokenLocation()->isEndTokenLocation() &&
tokenLocation->getOtherTokenLocation()->getLineNumber() <= lastLineNumber)
{
ret.addTokenLocationAsPlainCopy(tokenLocation);
ret.addTokenLocationAsPlainCopy(tokenLocation->getOtherTokenLocation());
}
});
}
}
}
return ret;
}
Edge::AccessType Storage::convertAccessType(ParserClient::AccessType access) const
+10 -3
View File
@@ -10,7 +10,10 @@
#include "data/location/TokenLocationCollection.h"
#include "data/parser/ParserClient.h"
class Storage: public ParserClient, public GraphAccess, public LocationAccess
class Storage
: public ParserClient
, public GraphAccess
, public LocationAccess
{
public:
Storage();
@@ -42,8 +45,12 @@ public:
void logGraph() const;
void logLocations() const;
virtual Token* getToken(Id tokenId);
virtual TokenLocation* getTokenLocation(Id locationId);
virtual Token* getToken(Id tokenId) const;
virtual TokenLocationCollection getTokenLocationsForTokenId(Id locationId) const;
virtual TokenLocationFile getTokenLocationsForLinesInFile(
const std::string& fileName, unsigned int firstLineNumber, unsigned int lastLineNumber
) const;
private:
Edge::AccessType convertAccessType(ParserClient::AccessType access) const;
+1 -1
View File
@@ -10,7 +10,7 @@ class GraphAccess
public:
virtual ~GraphAccess();
virtual Token* getToken(Id tokenId) = 0;
virtual Token* getToken(Id tokenId) const = 0;
};
+8 -3
View File
@@ -1,16 +1,21 @@
#ifndef LOCATION_ACCESS_H
#define LOCATION_ACCESS_H
#include <string>
#include "utility/types.h"
class TokenLocation;
class TokenLocationCollection;
class TokenLocationFile;
class LocationAccess
{
public:
virtual ~LocationAccess();
virtual TokenLocation* getTokenLocation(Id locationId) = 0;
virtual TokenLocationCollection getTokenLocationsForTokenId(Id id) const = 0;
virtual TokenLocationFile getTokenLocationsForLinesInFile(
const std::string& fileName, unsigned int firstLineNumber, unsigned int lastLineNumber
) const = 0;
};
@@ -103,6 +103,22 @@ void TokenLocationCollection::forEachTokenLocationFile(std::function<void(TokenL
}
}
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);
}
}
TokenLocation* TokenLocationCollection::addTokenLocationAsPlainCopy(const TokenLocation* location)
{
const std::string& filePath = location->getTokenLocationLine()->getTokenLocationFile()->getFilePath();
@@ -11,6 +11,7 @@
class TokenLocation;
class TokenLocationFile;
class TokenLocationLine;
class TokenLocationCollection
{
@@ -37,6 +38,8 @@ public:
TokenLocationFile* findTokenLocationFileByPath(const std::string& filePath) const;
void forEachTokenLocationFile(std::function<void(TokenLocationFile*)> func) const;
void forEachTokenLocationLine(std::function<void(TokenLocationLine*)> func) const;
void forEachTokenLocation(std::function<void(TokenLocation*)> func) const;
TokenLocation* addTokenLocationAsPlainCopy(const TokenLocation* location);
@@ -66,6 +66,11 @@ void TokenLocationFile::removeTokenLocation(TokenLocation* location)
}
}
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)
@@ -74,6 +79,14 @@ void TokenLocationFile::forEachTokenLocationLine(std::function<void(TokenLocatio
}
}
void TokenLocationFile::forEachTokenLocation(std::function<void(TokenLocation*)> func) const
{
for (const TokenLocationLinePairType& line : m_lines)
{
line.second->forEachTokenLocation(func);
}
}
TokenLocation* TokenLocationFile::addTokenLocationAsPlainCopy(const TokenLocation* location)
{
unsigned int lineNumber = location->getTokenLocationLine()->getLineNumber();
@@ -32,7 +32,10 @@ public:
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;
TokenLocation* addTokenLocationAsPlainCopy(const TokenLocation* location);