data: Saving TokenLocations in Storage
This change adds structures for saving TokenLocations in the Storage and improves the location derival in the ASTVisitor: * TokenLocation saves an Id of a Token. For each Token two TokenLocations are created for both start- and endpoint. They keep a reference to each other and know whether they are start or end. * TokenLocationLine saves all TokenLocations in a line and the lineNumber. * TokenLocationFile saves all TokenLocationLines of a specific file and the filePath. * TokenLocationCollection saves multiple TokenLocationFiles. * TokenLocation can derive it's lineNumber and filePath through references to first TokenLocationLine and from there to TokenLocationFile.
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
#include "data/graph/Token.h"
|
||||
|
||||
#include "data/location/TokenLocation.h"
|
||||
#include "utility/logging/logging.h"
|
||||
|
||||
Token::Token()
|
||||
: m_id(s_nextId++)
|
||||
{
|
||||
@@ -14,9 +17,33 @@ Id Token::getId() const
|
||||
return m_id;
|
||||
}
|
||||
|
||||
Id Token::s_nextId = 1;
|
||||
const std::vector<Id>& Token::getLocationIds() const
|
||||
{
|
||||
return m_locationIds;
|
||||
}
|
||||
|
||||
void Token::addLocationId(Id locationId)
|
||||
{
|
||||
m_locationIds.push_back(locationId);
|
||||
}
|
||||
|
||||
void Token::removeLocationId(Id locationId)
|
||||
{
|
||||
for (std::vector<Id>::const_iterator it = m_locationIds.begin(); it != m_locationIds.end(); it++)
|
||||
{
|
||||
if (*it == locationId)
|
||||
{
|
||||
m_locationIds.erase(it);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
LOG_ERROR("Location Id was not referenced by this Token.");
|
||||
}
|
||||
|
||||
Token::Token(Id id)
|
||||
: m_id(id)
|
||||
{
|
||||
}
|
||||
|
||||
Id Token::s_nextId = 1;
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#ifndef TOKEN_H
|
||||
#define TOKEN_H
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "utility/types.h"
|
||||
|
||||
class Token
|
||||
@@ -14,6 +16,11 @@ public:
|
||||
virtual bool isNode() const = 0;
|
||||
virtual bool isEdge() const = 0;
|
||||
|
||||
const std::vector<Id>& getLocationIds() const;
|
||||
|
||||
void addLocationId(Id locationId);
|
||||
void removeLocationId(Id locationId);
|
||||
|
||||
protected:
|
||||
// Constructor for plain copies of Node and Edge
|
||||
Token(Id id);
|
||||
@@ -25,6 +32,8 @@ private:
|
||||
void operator=(const Token&);
|
||||
|
||||
const Id m_id;
|
||||
|
||||
std::vector<Id> m_locationIds;
|
||||
};
|
||||
|
||||
#endif // TOKEN_H
|
||||
|
||||
Reference in New Issue
Block a user