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:
Eberhard Graether
2014-07-01 10:49:12 +02:00
parent e3cf57e2ec
commit cf6d17584f
27 changed files with 1109 additions and 243 deletions
+126
View File
@@ -0,0 +1,126 @@
#include "data/location/TokenLocation.h"
#include "data/location/TokenLocationLine.h"
TokenLocation::TokenLocation(Id tokenId, TokenLocationLine* line, unsigned int columnNumber, bool isStart)
: TokenLocation(s_locationId++, tokenId, line, columnNumber, isStart)
{
}
TokenLocation::TokenLocation(Id id, Id tokenId, TokenLocationLine* line, unsigned int columnNumber, bool isStart)
: m_id(id)
, m_tokenId(tokenId)
, m_line(line)
, m_columnNumber(columnNumber)
, m_other(nullptr)
, m_isStart(isStart)
{
}
TokenLocation::~TokenLocation()
{
}
Id TokenLocation::getId() const
{
return m_id;
}
Id TokenLocation::getTokenId() const
{
return m_tokenId;
}
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 std::string& 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;
}
}
bool TokenLocation::isStartTokenLocation() const
{
return m_isStart;
}
bool TokenLocation::isEndTokenLocation() const
{
return !m_isStart;
}
std::shared_ptr<TokenLocation> TokenLocation::createPlainCopy(TokenLocationLine* line) const
{
return std::shared_ptr<TokenLocation>(new TokenLocation(m_id, m_tokenId, line, m_columnNumber, m_isStart));
}
Id TokenLocation::s_locationId = 1;
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;
}