data: Saving TokenLocations of scopes separately
This change parses the TokenLocations of scopes of classes, structs, functions, methods, namespaces and enums and saves them in Storage with type LOCATION_SCOPE. The TokenLocations of these nodes are just their name declarations now. Scope locations are displayed in blue color in the code view.
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
TokenLocation::TokenLocation(Id tokenId, TokenLocationLine* line, unsigned int columnNumber, bool isStart)
|
||||
: m_id(s_locationId++)
|
||||
, m_tokenId(tokenId)
|
||||
, m_type(LOCATION_TOKEN)
|
||||
, m_line(line)
|
||||
, m_columnNumber(columnNumber)
|
||||
, m_other(nullptr)
|
||||
@@ -12,16 +13,28 @@ TokenLocation::TokenLocation(Id tokenId, TokenLocationLine* line, unsigned int c
|
||||
{
|
||||
}
|
||||
|
||||
TokenLocation::TokenLocation(Id id, Id tokenId, TokenLocationLine* line, unsigned int columnNumber, bool isStart)
|
||||
: m_id(id)
|
||||
, m_tokenId(tokenId)
|
||||
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(nullptr)
|
||||
, 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()
|
||||
{
|
||||
}
|
||||
@@ -36,6 +49,16 @@ Id TokenLocation::getTokenId() const
|
||||
return m_tokenId;
|
||||
}
|
||||
|
||||
TokenLocation::LocationType TokenLocation::getType() const
|
||||
{
|
||||
return m_type;
|
||||
}
|
||||
|
||||
void TokenLocation::setType(LocationType type)
|
||||
{
|
||||
m_type = type;
|
||||
}
|
||||
|
||||
TokenLocationLine* TokenLocation::getTokenLocationLine() const
|
||||
{
|
||||
return m_line;
|
||||
@@ -105,11 +128,6 @@ 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)
|
||||
|
||||
@@ -14,13 +14,23 @@ class TokenLocationLine;
|
||||
class TokenLocation
|
||||
{
|
||||
public:
|
||||
enum LocationType
|
||||
{
|
||||
LOCATION_TOKEN,
|
||||
LOCATION_SCOPE
|
||||
};
|
||||
|
||||
TokenLocation(Id tokenId, TokenLocationLine* line, unsigned int columnNumber, bool isStart);
|
||||
TokenLocation(Id id, 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();
|
||||
|
||||
Id getId() const;
|
||||
Id getTokenId() const;
|
||||
|
||||
LocationType getType() const;
|
||||
void setType(LocationType type);
|
||||
|
||||
TokenLocationLine* getTokenLocationLine() const;
|
||||
TokenLocationFile* getTokenLocationFile() const;
|
||||
|
||||
@@ -37,14 +47,14 @@ public:
|
||||
bool isStartTokenLocation() const;
|
||||
bool isEndTokenLocation() const;
|
||||
|
||||
std::shared_ptr<TokenLocation> createPlainCopy(TokenLocationLine* line) const;
|
||||
|
||||
private:
|
||||
static Id s_locationId; // next free own id
|
||||
|
||||
const Id m_id; // own id
|
||||
const Id m_tokenId;
|
||||
|
||||
LocationType m_type;
|
||||
|
||||
TokenLocationLine* const m_line;
|
||||
const unsigned int m_columnNumber;
|
||||
|
||||
|
||||
@@ -48,12 +48,8 @@ TokenLocation* TokenLocationLine::addStartTokenLocation(Id tokenId, unsigned int
|
||||
|
||||
TokenLocation* TokenLocationLine::addEndTokenLocation(TokenLocation* start, unsigned int columnNumber)
|
||||
{
|
||||
std::shared_ptr<TokenLocation> locationPtr = std::make_shared<TokenLocation>(
|
||||
start->getId(), start->getTokenId(), this, columnNumber, false);
|
||||
|
||||
std::shared_ptr<TokenLocation> locationPtr = std::make_shared<TokenLocation>(start, this, columnNumber, false);
|
||||
start->setOtherTokenLocation(locationPtr.get());
|
||||
locationPtr->setOtherTokenLocation(start);
|
||||
|
||||
m_locations.emplace(columnNumber, locationPtr);
|
||||
return locationPtr.get();
|
||||
}
|
||||
@@ -97,7 +93,7 @@ void TokenLocationLine::forEachTokenLocation(std::function<void(TokenLocation*)>
|
||||
|
||||
TokenLocation* TokenLocationLine::addTokenLocationAsPlainCopy(const TokenLocation* location)
|
||||
{
|
||||
std::shared_ptr<TokenLocation> locationPtr = location->createPlainCopy(this);
|
||||
std::shared_ptr<TokenLocation> locationPtr = std::make_shared<TokenLocation>(*location, this);
|
||||
m_locations.emplace(location->getColumnNumber(), locationPtr);
|
||||
return locationPtr.get();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user