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:
@@ -4,7 +4,8 @@
|
||||
<TabWidth>4</TabWidth>
|
||||
<FontName>Courier</FontName>
|
||||
<FontSize>12</FontSize>
|
||||
<LinkColor>222 222 222 100</LinkColor>
|
||||
<LinkColor>235 235 235 255</LinkColor>
|
||||
<ScopeColor>215 230 240 100</ScopeColor>
|
||||
<ActiveLinkColor>210 240 70 100</ActiveLinkColor>
|
||||
</code>
|
||||
</config>
|
||||
|
||||
+18
-15
@@ -1,18 +1,3 @@
|
||||
/*
|
||||
class e
|
||||
{
|
||||
};
|
||||
class x: public e
|
||||
{
|
||||
};
|
||||
struct y;
|
||||
enum z;
|
||||
|
||||
x foox();
|
||||
y fooy();
|
||||
z fooz();
|
||||
*/
|
||||
|
||||
const bool *ab(int abc, int bca);
|
||||
|
||||
bool const *abc(int a, int b);
|
||||
@@ -86,4 +71,22 @@ private:
|
||||
int m_valuable;
|
||||
};
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace noname
|
||||
{
|
||||
struct V
|
||||
{
|
||||
int x;
|
||||
int y;
|
||||
};
|
||||
}
|
||||
|
||||
enum E
|
||||
{
|
||||
X,
|
||||
Y
|
||||
};
|
||||
}
|
||||
|
||||
typedef A* D;
|
||||
|
||||
@@ -292,6 +292,8 @@ void QtCodeSnippet::createAnnotations(const TokenLocationFile& locationFile)
|
||||
}
|
||||
|
||||
annotation.tokenId = location->getTokenId();
|
||||
annotation.isScope = location->getType() == TokenLocation::LOCATION_SCOPE;
|
||||
|
||||
m_annotations.push_back(annotation);
|
||||
}
|
||||
);
|
||||
@@ -311,6 +313,10 @@ void QtCodeSnippet::annotateText()
|
||||
{
|
||||
color = ApplicationSettings::getInstance()->getCodeActiveLinkColor();
|
||||
}
|
||||
else if (annotation.isScope)
|
||||
{
|
||||
color = ApplicationSettings::getInstance()->getCodeScopeColor();
|
||||
}
|
||||
else
|
||||
{
|
||||
color = ApplicationSettings::getInstance()->getCodeLinkColor();
|
||||
|
||||
@@ -75,6 +75,7 @@ private:
|
||||
int start;
|
||||
int end;
|
||||
Id tokenId;
|
||||
bool isScope;
|
||||
};
|
||||
|
||||
void createAnnotations(const TokenLocationFile& locationFile);
|
||||
|
||||
@@ -51,9 +51,19 @@ Colori ApplicationSettings::getCodeLinkColor() const
|
||||
return Colori::fromString(getValue<std::string>("code/LinkColor", Colori(255, 255, 0, 100).toString()));
|
||||
}
|
||||
|
||||
void ApplicationSettings::setCodeLinkColor(Colori codeLinkColor)
|
||||
void ApplicationSettings::setCodeLinkColor(Colori color)
|
||||
{
|
||||
setValue<std::string>("code/LinkColor", codeLinkColor.toString());
|
||||
setValue<std::string>("code/LinkColor", color.toString());
|
||||
}
|
||||
|
||||
Colori ApplicationSettings::getCodeScopeColor() const
|
||||
{
|
||||
return Colori::fromString(getValue<std::string>("code/ScopeColor", Colori(255, 255, 0, 100).toString()));
|
||||
}
|
||||
|
||||
void ApplicationSettings::setCodeScopeColor(Colori color)
|
||||
{
|
||||
setValue<std::string>("code/ScopeColor", color.toString());
|
||||
}
|
||||
|
||||
Colori ApplicationSettings::getCodeActiveLinkColor() const
|
||||
@@ -61,9 +71,9 @@ Colori ApplicationSettings::getCodeActiveLinkColor() const
|
||||
return Colori::fromString(getValue<std::string>("code/ActiveLinkColor", Colori(0, 255, 0, 100).toString()));
|
||||
}
|
||||
|
||||
void ApplicationSettings::setCodeActiveLinkColor(Colori codeLinkColor)
|
||||
void ApplicationSettings::setCodeActiveLinkColor(Colori color)
|
||||
{
|
||||
setValue<std::string>("code/ActiveLinkColor", codeLinkColor.toString());
|
||||
setValue<std::string>("code/ActiveLinkColor", color.toString());
|
||||
}
|
||||
|
||||
ApplicationSettings::ApplicationSettings()
|
||||
|
||||
@@ -22,10 +22,13 @@ public:
|
||||
void setCodeFontSize(int codeFontSize);
|
||||
|
||||
Colori getCodeLinkColor() const;
|
||||
void setCodeLinkColor(Colori codeLinkColor);
|
||||
void setCodeLinkColor(Colori color);
|
||||
|
||||
Colori getCodeScopeColor() const;
|
||||
void setCodeScopeColor(Colori color);
|
||||
|
||||
Colori getCodeActiveLinkColor() const;
|
||||
void setCodeActiveLinkColor(Colori codeLinkColor);
|
||||
void setCodeActiveLinkColor(Colori color);
|
||||
|
||||
private:
|
||||
ApplicationSettings();
|
||||
|
||||
@@ -49,22 +49,26 @@ void Storage::onTypedefParsed(
|
||||
addTypeEdge(node, Edge::EDGE_TYPEDEF_OF, underlyingType);
|
||||
}
|
||||
|
||||
void Storage::onClassParsed(const ParseLocation& location, const std::string& fullName, AccessType access)
|
||||
void Storage::onClassParsed(
|
||||
const ParseLocation& location, const std::string& fullName, AccessType access, const ParseLocation& scopeLocation)
|
||||
{
|
||||
log("class", fullName, location);
|
||||
|
||||
Node* node = m_graph.createNodeHierarchy(Node::NODE_CLASS, fullName);
|
||||
addAccess(node, access);
|
||||
addTokenLocation(node, location);
|
||||
addTokenLocation(node, scopeLocation, true);
|
||||
}
|
||||
|
||||
void Storage::onStructParsed(const ParseLocation& location, const std::string& fullName, AccessType access)
|
||||
void Storage::onStructParsed(
|
||||
const ParseLocation& location, const std::string& fullName, AccessType access, const ParseLocation& scopeLocation)
|
||||
{
|
||||
log("struct", fullName, location);
|
||||
|
||||
Node* node = m_graph.createNodeHierarchy(Node::NODE_STRUCT, fullName);
|
||||
addAccess(node, access);
|
||||
addTokenLocation(node, location);
|
||||
addTokenLocation(node, scopeLocation, true);
|
||||
}
|
||||
|
||||
void Storage::onGlobalVariableParsed(const ParseLocation& location, const ParseVariable& variable)
|
||||
@@ -106,7 +110,7 @@ void Storage::onFieldParsed(const ParseLocation& location, const ParseVariable&
|
||||
|
||||
void Storage::onFunctionParsed(
|
||||
const ParseLocation& location, const std::string& fullName, const ParseTypeUsage& returnType,
|
||||
const std::vector<ParseTypeUsage>& parameters
|
||||
const std::vector<ParseTypeUsage>& parameters, const ParseLocation& scopeLocation
|
||||
)
|
||||
{
|
||||
log("function", fullName, location);
|
||||
@@ -116,6 +120,7 @@ void Storage::onFunctionParsed(
|
||||
ParserClient::functionSignatureStr(returnType.dataType, fullName, parameters, false)
|
||||
);
|
||||
addTokenLocation(node, location);
|
||||
addTokenLocation(node, scopeLocation, true);
|
||||
|
||||
addTypeEdge(node, Edge::EDGE_RETURN_TYPE_OF, returnType);
|
||||
for (const ParseTypeUsage& parameter : parameters)
|
||||
@@ -127,7 +132,7 @@ void Storage::onFunctionParsed(
|
||||
void Storage::onMethodParsed(
|
||||
const ParseLocation& location, const std::string& fullName, const ParseTypeUsage& returnType,
|
||||
const std::vector<ParseTypeUsage>& parameters, AccessType access, AbstractionType abstraction,
|
||||
bool isConst, bool isStatic
|
||||
bool isConst, bool isStatic, const ParseLocation& scopeLocation
|
||||
)
|
||||
{
|
||||
log("method", fullName, location);
|
||||
@@ -155,6 +160,7 @@ void Storage::onMethodParsed(
|
||||
addAccess(node, access);
|
||||
|
||||
addTokenLocation(node, location);
|
||||
addTokenLocation(node, scopeLocation, true);
|
||||
|
||||
addTypeEdge(node, Edge::EDGE_RETURN_TYPE_OF, returnType);
|
||||
for (const ParseTypeUsage& parameter : parameters)
|
||||
@@ -163,21 +169,25 @@ void Storage::onMethodParsed(
|
||||
}
|
||||
}
|
||||
|
||||
void Storage::onNamespaceParsed(const ParseLocation& location, const std::string& fullName)
|
||||
void Storage::onNamespaceParsed(
|
||||
const ParseLocation& location, const std::string& fullName, const ParseLocation& scopeLocation)
|
||||
{
|
||||
log("namespace", fullName, location);
|
||||
|
||||
Node* node = m_graph.createNodeHierarchy(Node::NODE_NAMESPACE, fullName);
|
||||
addTokenLocation(node, location);
|
||||
addTokenLocation(node, scopeLocation, true);
|
||||
}
|
||||
|
||||
void Storage::onEnumParsed(const ParseLocation& location, const std::string& fullName, AccessType access)
|
||||
void Storage::onEnumParsed(
|
||||
const ParseLocation& location, const std::string& fullName, AccessType access, const ParseLocation& scopeLocation)
|
||||
{
|
||||
log("enum", fullName, location);
|
||||
|
||||
Node* node = m_graph.createNodeHierarchy(Node::NODE_ENUM, fullName);
|
||||
addAccess(node, access);
|
||||
addTokenLocation(node, location);
|
||||
addTokenLocation(node, scopeLocation, true);
|
||||
}
|
||||
|
||||
void Storage::onEnumFieldParsed(const ParseLocation& location, const std::string& fullName)
|
||||
@@ -595,7 +605,7 @@ Edge* Storage::addTypeEdge(Node* node, Edge::EdgeType edgeType, const ParseTypeU
|
||||
return edge;
|
||||
}
|
||||
|
||||
TokenLocation* Storage::addTokenLocation(Token* token, const ParseLocation& loc)
|
||||
TokenLocation* Storage::addTokenLocation(Token* token, const ParseLocation& loc, bool isScope)
|
||||
{
|
||||
if (!loc.isValid())
|
||||
{
|
||||
@@ -608,6 +618,11 @@ TokenLocation* Storage::addTokenLocation(Token* token, const ParseLocation& loc)
|
||||
loc.endLineNumber, loc.endColumnNumber
|
||||
);
|
||||
|
||||
if (isScope)
|
||||
{
|
||||
location->setType(TokenLocation::LOCATION_SCOPE);
|
||||
}
|
||||
|
||||
token->addLocationId(location->getId());
|
||||
return location;
|
||||
}
|
||||
|
||||
+11
-7
@@ -30,25 +30,29 @@ public:
|
||||
const ParseLocation& location, const std::string& fullName, const DataType& underlyingType,
|
||||
AccessType access
|
||||
);
|
||||
virtual void onClassParsed(const ParseLocation& location, const std::string& fullName, AccessType access);
|
||||
virtual void onStructParsed(const ParseLocation& location, const std::string& fullName, AccessType access);
|
||||
virtual void onClassParsed(
|
||||
const ParseLocation& location, const std::string& fullName, AccessType access, const ParseLocation& scopeLocation);
|
||||
virtual void onStructParsed(
|
||||
const ParseLocation& location, const std::string& fullName, AccessType access, const ParseLocation& scopeLocation);
|
||||
|
||||
virtual void onGlobalVariableParsed(const ParseLocation& location, const ParseVariable& variable);
|
||||
virtual void onFieldParsed(const ParseLocation& location, const ParseVariable& variable, AccessType access);
|
||||
|
||||
virtual void onFunctionParsed(
|
||||
const ParseLocation& location, const std::string& fullName, const ParseTypeUsage& returnType,
|
||||
const std::vector<ParseTypeUsage>& parameters
|
||||
const std::vector<ParseTypeUsage>& parameters, const ParseLocation& scopeLocation
|
||||
);
|
||||
virtual void onMethodParsed(
|
||||
const ParseLocation& location, const std::string& fullName, const ParseTypeUsage& returnType,
|
||||
const std::vector<ParseTypeUsage>& parameters, AccessType access, AbstractionType abstraction,
|
||||
bool isConst, bool isStatic
|
||||
bool isConst, bool isStatic, const ParseLocation& scopeLocation
|
||||
);
|
||||
|
||||
virtual void onNamespaceParsed(const ParseLocation& location, const std::string& fullName);
|
||||
virtual void onNamespaceParsed(
|
||||
const ParseLocation& location, const std::string& fullName, const ParseLocation& scopeLocation);
|
||||
|
||||
virtual void onEnumParsed(const ParseLocation& location, const std::string& fullName, AccessType access);
|
||||
virtual void onEnumParsed(
|
||||
const ParseLocation& location, const std::string& fullName, AccessType access, const ParseLocation& scopeLocation);
|
||||
virtual void onEnumFieldParsed(const ParseLocation& location, const std::string& fullName);
|
||||
|
||||
virtual void onInheritanceParsed(
|
||||
@@ -96,7 +100,7 @@ private:
|
||||
TokenComponentAccess* addAccess(Node* node, ParserClient::AccessType access);
|
||||
Edge* addTypeEdge(Node* node, Edge::EdgeType edgeType, const DataType& type);
|
||||
Edge* addTypeEdge(Node* node, Edge::EdgeType edgeType, const ParseTypeUsage& typeUsage);
|
||||
TokenLocation* addTokenLocation(Token* token, const ParseLocation& location);
|
||||
TokenLocation* addTokenLocation(Token* token, const ParseLocation& location, bool isScope = false);
|
||||
|
||||
void log(std::string type, std::string str, const ParseLocation& location) const;
|
||||
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -1,9 +1,18 @@
|
||||
#include "data/parser/ParseLocation.h"
|
||||
|
||||
ParseLocation::ParseLocation()
|
||||
: filePath("")
|
||||
, startLineNumber(0)
|
||||
, startColumnNumber(0)
|
||||
, endLineNumber(0)
|
||||
, endColumnNumber(0)
|
||||
{
|
||||
}
|
||||
|
||||
ParseLocation::ParseLocation(
|
||||
const std::string& filePath,
|
||||
unsigned int startLineNumber, unsigned int startColumnNumber,
|
||||
unsigned int endLineNumber, unsigned int endColumnNumber
|
||||
uint startLineNumber, uint startColumnNumber,
|
||||
uint endLineNumber, uint endColumnNumber
|
||||
)
|
||||
: filePath(filePath)
|
||||
, startLineNumber(startLineNumber)
|
||||
|
||||
@@ -3,20 +3,24 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "utility/types.h"
|
||||
|
||||
struct ParseLocation
|
||||
{
|
||||
ParseLocation();
|
||||
ParseLocation(
|
||||
const std::string& filePath,
|
||||
unsigned int startLineNumber, unsigned int startColumnNumber,
|
||||
unsigned int endLineNumber, unsigned int endColumnNumber);
|
||||
uint startLineNumber, uint startColumnNumber,
|
||||
uint endLineNumber, uint endColumnNumber
|
||||
);
|
||||
|
||||
bool isValid() const;
|
||||
|
||||
const std::string filePath;
|
||||
unsigned int startLineNumber;
|
||||
unsigned int startColumnNumber;
|
||||
unsigned int endLineNumber;
|
||||
unsigned int endColumnNumber;
|
||||
uint startLineNumber;
|
||||
uint startColumnNumber;
|
||||
uint endLineNumber;
|
||||
uint endColumnNumber;
|
||||
};
|
||||
|
||||
#endif // PARSE_LOCATION_H
|
||||
|
||||
@@ -56,11 +56,33 @@ std::string ParserClient::addConstPrefix(const std::string& str, bool isConst, b
|
||||
std::string ParserClient::addLocationSuffix(const std::string& str, const ParseLocation& location)
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << str << " <" << location.startLineNumber << ":" << location.startColumnNumber << " ";
|
||||
ss << str;
|
||||
ss << " <" << location.startLineNumber << ":" << location.startColumnNumber << " ";
|
||||
ss << location.endLineNumber << ":" << location.endColumnNumber << ">";
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
std::string ParserClient::addLocationSuffix(
|
||||
const std::string& str, const ParseLocation& location, const ParseLocation& scopeLocation
|
||||
){
|
||||
if (!location.isValid())
|
||||
{
|
||||
return addLocationSuffix(str, scopeLocation);
|
||||
}
|
||||
else if (!scopeLocation.isValid())
|
||||
{
|
||||
return addLocationSuffix(str, location);
|
||||
}
|
||||
|
||||
std::stringstream ss;
|
||||
ss << str;
|
||||
ss << " <" << scopeLocation.startLineNumber << ":" << scopeLocation.startColumnNumber;
|
||||
ss << " <" << location.startLineNumber << ":" << location.startColumnNumber << " ";
|
||||
ss << location.endLineNumber << ":" << location.endColumnNumber << "> ";
|
||||
ss << scopeLocation.endLineNumber << ":" << scopeLocation.endColumnNumber << ">";
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
std::string ParserClient::variableStr(const ParseVariable& variable)
|
||||
{
|
||||
std::string str = variable.type.dataType.getFullTypeName() + " " + variable.fullName;
|
||||
|
||||
@@ -30,6 +30,9 @@ public:
|
||||
static std::string addStaticPrefix(const std::string& str, bool isStatic);
|
||||
static std::string addConstPrefix(const std::string& str, bool isConst, bool atFront);
|
||||
static std::string addLocationSuffix(const std::string& str, const ParseLocation& location);
|
||||
static std::string addLocationSuffix(
|
||||
const std::string& str, const ParseLocation& location, const ParseLocation& scopeLocation);
|
||||
|
||||
static std::string variableStr(const ParseVariable& variable);
|
||||
static std::string parameterStr(const std::vector<ParseTypeUsage> parameters);
|
||||
static std::string functionStr(
|
||||
@@ -51,23 +54,30 @@ public:
|
||||
virtual void onTypedefParsed(
|
||||
const ParseLocation& location, const std::string& fullName, const DataType& underlyingType,
|
||||
AccessType access) = 0;
|
||||
virtual void onClassParsed(const ParseLocation& location, const std::string& fullName, AccessType access) = 0;
|
||||
virtual void onStructParsed(const ParseLocation& location, const std::string& fullName, AccessType access) = 0;
|
||||
virtual void onClassParsed(
|
||||
const ParseLocation& location, const std::string& fullName, AccessType access,
|
||||
const ParseLocation& scopeLocation) = 0;
|
||||
virtual void onStructParsed(
|
||||
const ParseLocation& location, const std::string& fullName, AccessType access,
|
||||
const ParseLocation& scopeLocation) = 0;
|
||||
|
||||
virtual void onGlobalVariableParsed(const ParseLocation& location, const ParseVariable& variable) = 0;
|
||||
virtual void onFieldParsed(const ParseLocation& location, const ParseVariable& variable, AccessType access) = 0;
|
||||
|
||||
virtual void onFunctionParsed(
|
||||
const ParseLocation& location, const std::string& fullName, const ParseTypeUsage& returnType,
|
||||
const std::vector<ParseTypeUsage>& parameters) = 0;
|
||||
const std::vector<ParseTypeUsage>& parameters, const ParseLocation& scopeLocation) = 0;
|
||||
virtual void onMethodParsed(
|
||||
const ParseLocation& location, const std::string& fullName, const ParseTypeUsage& returnType,
|
||||
const std::vector<ParseTypeUsage>& parameters, AccessType access, AbstractionType abstraction,
|
||||
bool isConst, bool isStatic) = 0;
|
||||
bool isConst, bool isStatic, const ParseLocation& scopeLocation) = 0;
|
||||
|
||||
virtual void onNamespaceParsed(const ParseLocation& location, const std::string& fullName) = 0;
|
||||
virtual void onNamespaceParsed(
|
||||
const ParseLocation& location, const std::string& fullName, const ParseLocation& scopeLocation) = 0;
|
||||
|
||||
virtual void onEnumParsed(const ParseLocation& location, const std::string& fullName, AccessType access) = 0;
|
||||
virtual void onEnumParsed(
|
||||
const ParseLocation& location, const std::string& fullName, AccessType access,
|
||||
const ParseLocation& scopeLocation) = 0;
|
||||
virtual void onEnumFieldParsed(const ParseLocation& location, const std::string& fullName) = 0;
|
||||
|
||||
virtual void onInheritanceParsed(
|
||||
|
||||
@@ -44,9 +44,10 @@ bool ASTVisitor::VisitCXXRecordDecl(clang::CXXRecordDecl* declaration)
|
||||
if (declaration->isClass())
|
||||
{
|
||||
m_client->onClassParsed(
|
||||
getParseLocation(declaration->getSourceRange()),
|
||||
getParseLocationForNamedDecl(declaration),
|
||||
declaration->getQualifiedNameAsString(),
|
||||
convertAccessType(declaration->getAccess())
|
||||
convertAccessType(declaration->getAccess()),
|
||||
getParseLocationOfRecordBody(declaration)
|
||||
);
|
||||
|
||||
if (declaration->hasDefinition() && declaration->getNumBases())
|
||||
@@ -65,9 +66,10 @@ bool ASTVisitor::VisitCXXRecordDecl(clang::CXXRecordDecl* declaration)
|
||||
else if (declaration->isStruct())
|
||||
{
|
||||
m_client->onStructParsed(
|
||||
getParseLocation(declaration->getSourceRange()),
|
||||
getParseLocationForNamedDecl(declaration),
|
||||
declaration->getQualifiedNameAsString(),
|
||||
convertAccessType(declaration->getAccess())
|
||||
convertAccessType(declaration->getAccess()),
|
||||
getParseLocationOfRecordBody(declaration)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -138,10 +140,11 @@ bool ASTVisitor::VisitFunctionDecl(clang::FunctionDecl* declaration)
|
||||
if (hasValidLocation(declaration))
|
||||
{
|
||||
m_client->onFunctionParsed(
|
||||
getParseLocation(declaration->getSourceRange()),
|
||||
getParseLocationForNamedDecl(declaration),
|
||||
declaration->getQualifiedNameAsString(),
|
||||
getParseTypeUsageOfReturnType(declaration),
|
||||
getParameters(declaration)
|
||||
getParameters(declaration),
|
||||
getParseLocationOfFunctionBody(declaration)
|
||||
);
|
||||
|
||||
if (declaration->hasBody() && declaration->isThisDeclarationADefinition())
|
||||
@@ -169,14 +172,15 @@ bool ASTVisitor::VisitCXXMethodDecl(clang::CXXMethodDecl* declaration)
|
||||
}
|
||||
|
||||
m_client->onMethodParsed(
|
||||
getParseLocation(declaration->getSourceRange()),
|
||||
getParseLocationForNamedDecl(declaration),
|
||||
declaration->getQualifiedNameAsString(),
|
||||
getParseTypeUsageOfReturnType(declaration),
|
||||
getParameters(declaration),
|
||||
convertAccessType(declaration->getAccess()),
|
||||
abstraction,
|
||||
declaration->isConst(),
|
||||
declaration->isStatic()
|
||||
declaration->isStatic(),
|
||||
getParseLocationOfFunctionBody(declaration)
|
||||
);
|
||||
|
||||
if (declaration->hasBody() && declaration->isThisDeclarationADefinition())
|
||||
@@ -211,8 +215,9 @@ bool ASTVisitor::VisitNamespaceDecl(clang::NamespaceDecl* declaration)
|
||||
if (hasValidLocation(declaration))
|
||||
{
|
||||
m_client->onNamespaceParsed(
|
||||
getParseLocation(declaration->getSourceRange()),
|
||||
declaration->getQualifiedNameAsString()
|
||||
declaration->isAnonymousNamespace() ? ParseLocation() : getParseLocationForNamedDecl(declaration),
|
||||
declaration->getQualifiedNameAsString(),
|
||||
getParseLocation(declaration->getSourceRange())
|
||||
);
|
||||
}
|
||||
|
||||
@@ -224,9 +229,10 @@ bool ASTVisitor::VisitEnumDecl(clang::EnumDecl* declaration)
|
||||
if (hasValidLocation(declaration))
|
||||
{
|
||||
m_client->onEnumParsed(
|
||||
getParseLocation(declaration->getSourceRange()),
|
||||
getParseLocationForNamedDecl(declaration),
|
||||
declaration->getQualifiedNameAsString(),
|
||||
convertAccessType(declaration->getAccess())
|
||||
convertAccessType(declaration->getAccess()),
|
||||
getParseLocation(declaration->getSourceRange())
|
||||
);
|
||||
}
|
||||
|
||||
@@ -316,7 +322,7 @@ ParseLocation ASTVisitor::getParseLocation(const clang::SourceRange& sourceRange
|
||||
{
|
||||
if (sourceRange.isInvalid())
|
||||
{
|
||||
return ParseLocation("", 0, 0, 0, 0);
|
||||
return ParseLocation();
|
||||
}
|
||||
|
||||
const clang::SourceManager& sourceManager = m_context->getSourceManager();
|
||||
@@ -346,6 +352,26 @@ ParseLocation ASTVisitor::getParseLocationForNamedDecl(clang::NamedDecl* decl) c
|
||||
);
|
||||
}
|
||||
|
||||
ParseLocation ASTVisitor::getParseLocationOfFunctionBody(clang::FunctionDecl* decl) const
|
||||
{
|
||||
if (decl->hasBody() && decl->isThisDeclarationADefinition())
|
||||
{
|
||||
return getParseLocation(decl->getSourceRange());
|
||||
}
|
||||
|
||||
return ParseLocation();
|
||||
}
|
||||
|
||||
ParseLocation ASTVisitor::getParseLocationOfRecordBody(clang::CXXRecordDecl* decl) const
|
||||
{
|
||||
if (decl->hasDefinition() && decl->isThisDeclarationADefinition())
|
||||
{
|
||||
return getParseLocation(decl->getDefinition()->getSourceRange());
|
||||
}
|
||||
|
||||
return ParseLocation();
|
||||
}
|
||||
|
||||
ParseVariable ASTVisitor::getParseVariable(clang::DeclaratorDecl* declaration) const
|
||||
{
|
||||
bool isStatic = false;
|
||||
|
||||
@@ -48,6 +48,8 @@ private:
|
||||
bool hasValidLocation(const clang::Decl* declaration) const;
|
||||
ParseLocation getParseLocation(const clang::SourceRange& sourceRange) const;
|
||||
ParseLocation getParseLocationForNamedDecl(clang::NamedDecl* decl) const;
|
||||
ParseLocation getParseLocationOfFunctionBody(clang::FunctionDecl* decl) const;
|
||||
ParseLocation getParseLocationOfRecordBody(clang::CXXRecordDecl* decl) const;
|
||||
ParseVariable getParseVariable(clang::DeclaratorDecl* declaration) const;
|
||||
ParseTypeUsage getParseTypeUsage(clang::DeclaratorDecl* declaration) const;
|
||||
ParseTypeUsage getParseTypeUsageOfReturnType(clang::FunctionDecl* declaration) const;
|
||||
|
||||
@@ -21,7 +21,7 @@ public:
|
||||
);
|
||||
|
||||
TS_ASSERT_EQUALS(client->classes.size(), 1);
|
||||
TS_ASSERT_EQUALS(client->classes[0], "A <1:1 3:1>");
|
||||
TS_ASSERT_EQUALS(client->classes[0], "A <1:1 <1:7 1:7> 3:1>");
|
||||
}
|
||||
|
||||
void test_cxx_parser_finds_global_class_forward_declaration()
|
||||
@@ -31,7 +31,7 @@ public:
|
||||
);
|
||||
|
||||
TS_ASSERT_EQUALS(client->classes.size(), 1);
|
||||
TS_ASSERT_EQUALS(client->classes[0], "A <1:1 1:7>");
|
||||
TS_ASSERT_EQUALS(client->classes[0], "A <1:7 1:7>");
|
||||
}
|
||||
|
||||
void test_cxx_parser_finds_nested_class_definition()
|
||||
@@ -45,8 +45,8 @@ public:
|
||||
);
|
||||
|
||||
TS_ASSERT_EQUALS(client->classes.size(), 2);
|
||||
TS_ASSERT_EQUALS(client->classes[0], "A <1:1 5:1>");
|
||||
TS_ASSERT_EQUALS(client->classes[1], "public A::B <4:2 4:8>");
|
||||
TS_ASSERT_EQUALS(client->classes[0], "A <1:1 <1:7 1:7> 5:1>");
|
||||
TS_ASSERT_EQUALS(client->classes[1], "public A::B <4:8 4:8>");
|
||||
}
|
||||
|
||||
void test_cxx_parser_finds_class_definition_in_namespace()
|
||||
@@ -59,7 +59,7 @@ public:
|
||||
);
|
||||
|
||||
TS_ASSERT_EQUALS(client->classes.size(), 1);
|
||||
TS_ASSERT_EQUALS(client->classes[0], "a::B <3:2 3:8>");
|
||||
TS_ASSERT_EQUALS(client->classes[0], "a::B <3:8 3:8>");
|
||||
}
|
||||
|
||||
void test_cxx_parser_finds_global_struct_definition()
|
||||
@@ -71,7 +71,7 @@ public:
|
||||
);
|
||||
|
||||
TS_ASSERT_EQUALS(client->structs.size(), 1);
|
||||
TS_ASSERT_EQUALS(client->structs[0], "A <1:1 3:1>");
|
||||
TS_ASSERT_EQUALS(client->structs[0], "A <1:1 <1:8 1:8> 3:1>");
|
||||
}
|
||||
|
||||
void test_cxx_parser_finds_global_struct_forward_declaration()
|
||||
@@ -81,7 +81,7 @@ public:
|
||||
);
|
||||
|
||||
TS_ASSERT_EQUALS(client->structs.size(), 1);
|
||||
TS_ASSERT_EQUALS(client->structs[0], "A <1:1 1:8>");
|
||||
TS_ASSERT_EQUALS(client->structs[0], "A <1:8 1:8>");
|
||||
}
|
||||
|
||||
void test_cxx_parser_finds_struct_definition_in_class()
|
||||
@@ -96,7 +96,7 @@ public:
|
||||
);
|
||||
|
||||
TS_ASSERT_EQUALS(client->structs.size(), 1);
|
||||
TS_ASSERT_EQUALS(client->structs[0], "private A::B <3:2 5:2>");
|
||||
TS_ASSERT_EQUALS(client->structs[0], "private A::B <3:2 <3:9 3:9> 5:2>");
|
||||
}
|
||||
|
||||
void test_cxx_parser_finds_struct_definition_in_namespace()
|
||||
@@ -111,7 +111,7 @@ public:
|
||||
);
|
||||
|
||||
TS_ASSERT_EQUALS(client->structs.size(), 1);
|
||||
TS_ASSERT_EQUALS(client->structs[0], "A::B <3:2 5:2>");
|
||||
TS_ASSERT_EQUALS(client->structs[0], "A::B <3:2 <3:9 3:9> 5:2>");
|
||||
}
|
||||
|
||||
void test_cxx_parser_finds_variable_definitions_in_global_scope()
|
||||
@@ -198,7 +198,7 @@ public:
|
||||
);
|
||||
|
||||
TS_ASSERT_EQUALS(client->functions.size(), 1);
|
||||
TS_ASSERT_EQUALS(client->functions[0], "int ceil(float) <1:1 4:1>");
|
||||
TS_ASSERT_EQUALS(client->functions[0], "int ceil(float) <1:1 <1:5 1:8> 4:1>");
|
||||
}
|
||||
|
||||
void test_cxx_parser_finds_function_in_anonymous_namespace()
|
||||
@@ -211,7 +211,7 @@ public:
|
||||
);
|
||||
|
||||
TS_ASSERT_EQUALS(client->functions.size(), 1);
|
||||
TS_ASSERT_EQUALS(client->functions[0], "int (anonymous namespace)::sum(int, int) <3:2 3:22>");
|
||||
TS_ASSERT_EQUALS(client->functions[0], "int (anonymous namespace)::sum(int, int) <3:6 3:8>");
|
||||
}
|
||||
|
||||
void test_cxx_parser_finds_method_declaration()
|
||||
@@ -225,7 +225,7 @@ public:
|
||||
);
|
||||
|
||||
TS_ASSERT_EQUALS(client->methods.size(), 1);
|
||||
TS_ASSERT_EQUALS(client->methods[0], "public void B::B() <4:2 4:4>");
|
||||
TS_ASSERT_EQUALS(client->methods[0], "public void B::B() <4:2 4:2>");
|
||||
}
|
||||
|
||||
void test_cxx_parser_finds_method_declaration_and_definition()
|
||||
@@ -242,8 +242,8 @@ public:
|
||||
);
|
||||
|
||||
TS_ASSERT_EQUALS(client->methods.size(), 2);
|
||||
TS_ASSERT_EQUALS(client->methods[0], "public void B::B() <4:2 4:4>");
|
||||
TS_ASSERT_EQUALS(client->methods[1], "public void B::B() <6:1 8:1>");
|
||||
TS_ASSERT_EQUALS(client->methods[0], "public void B::B() <4:2 4:2>");
|
||||
TS_ASSERT_EQUALS(client->methods[1], "public void B::B() <6:1 <6:4 6:4> 8:1>");
|
||||
}
|
||||
|
||||
void test_cxx_parser_finds_pure_virtual_method()
|
||||
@@ -257,7 +257,7 @@ public:
|
||||
);
|
||||
|
||||
TS_ASSERT_EQUALS(client->methods.size(), 1);
|
||||
TS_ASSERT_EQUALS(client->methods[0], "protected pure virtual void B::process() <4:2 4:27>");
|
||||
TS_ASSERT_EQUALS(client->methods[0], "protected pure virtual void B::process() <4:15 4:21>");
|
||||
}
|
||||
|
||||
void test_cxx_parser_finds_method_declared_in_nested_class()
|
||||
@@ -273,7 +273,7 @@ public:
|
||||
);
|
||||
|
||||
TS_ASSERT_EQUALS(client->methods.size(), 1);
|
||||
TS_ASSERT_EQUALS(client->methods[0], "private _Bool B::C::isGreat() const <5:3 5:18>");
|
||||
TS_ASSERT_EQUALS(client->methods[0], "private _Bool B::C::isGreat() const <5:8 5:14>");
|
||||
}
|
||||
|
||||
void test_cxx_parser_finds_named_namespace()
|
||||
@@ -285,7 +285,7 @@ public:
|
||||
);
|
||||
|
||||
TS_ASSERT_EQUALS(client->namespaces.size(), 1);
|
||||
TS_ASSERT_EQUALS(client->namespaces[0], "A <1:1 3:1>");
|
||||
TS_ASSERT_EQUALS(client->namespaces[0], "A <1:1 <1:11 1:11> 3:1>");
|
||||
}
|
||||
|
||||
void test_cxx_parser_finds_anonymous_namespace()
|
||||
@@ -309,7 +309,7 @@ public:
|
||||
);
|
||||
|
||||
TS_ASSERT_EQUALS(client->enums.size(), 1);
|
||||
TS_ASSERT_EQUALS(client->enums[0], "E <1:1 3:1>");
|
||||
TS_ASSERT_EQUALS(client->enums[0], "E <1:1 <1:6 1:6> 3:1>");
|
||||
}
|
||||
|
||||
void test_cxx_parser_finds_enum_defined_in_class()
|
||||
@@ -325,7 +325,7 @@ public:
|
||||
);
|
||||
|
||||
TS_ASSERT_EQUALS(client->enums.size(), 1);
|
||||
TS_ASSERT_EQUALS(client->enums[0], "public B::Z <4:2 6:2>");
|
||||
TS_ASSERT_EQUALS(client->enums[0], "public B::Z <4:2 <4:7 4:7> 6:2>");
|
||||
}
|
||||
|
||||
void test_cxx_parser_finds_enum_defined_in_namespace()
|
||||
@@ -340,7 +340,7 @@ public:
|
||||
);
|
||||
|
||||
TS_ASSERT_EQUALS(client->enums.size(), 1);
|
||||
TS_ASSERT_EQUALS(client->enums[0], "n::Z <3:2 5:2>");
|
||||
TS_ASSERT_EQUALS(client->enums[0], "n::Z <3:2 <3:7 3:7> 5:2>");
|
||||
}
|
||||
|
||||
void test_cxx_parser_finds_enum_field_in_global_enum()
|
||||
@@ -805,14 +805,18 @@ private:
|
||||
typedefs.push_back(addLocationSuffix(str, location));
|
||||
}
|
||||
|
||||
virtual void onClassParsed(const ParseLocation& location, const std::string& fullName, AccessType access)
|
||||
virtual void onClassParsed(
|
||||
const ParseLocation& location, const std::string& fullName, AccessType access,
|
||||
const ParseLocation& scopeLocation)
|
||||
{
|
||||
classes.push_back(addLocationSuffix(addAccessPrefix(fullName, access), location));
|
||||
classes.push_back(addLocationSuffix(addAccessPrefix(fullName, access), location, scopeLocation));
|
||||
}
|
||||
|
||||
virtual void onStructParsed(const ParseLocation& location, const std::string& fullName, AccessType access)
|
||||
virtual void onStructParsed(
|
||||
const ParseLocation& location, const std::string& fullName, AccessType access,
|
||||
const ParseLocation& scopeLocation)
|
||||
{
|
||||
structs.push_back(addLocationSuffix(addAccessPrefix(fullName, access), location));
|
||||
structs.push_back(addLocationSuffix(addAccessPrefix(fullName, access), location, scopeLocation));
|
||||
}
|
||||
|
||||
virtual void onGlobalVariableParsed(const ParseLocation& location, const ParseVariable& variable)
|
||||
@@ -827,10 +831,10 @@ private:
|
||||
|
||||
virtual void onFunctionParsed(
|
||||
const ParseLocation& location, const std::string& fullName, const ParseTypeUsage& returnType,
|
||||
const std::vector<ParseTypeUsage>& parameters
|
||||
const std::vector<ParseTypeUsage>& parameters, const ParseLocation& scopeLocation
|
||||
){
|
||||
std::string str = functionStr(returnType.dataType, fullName, parameters, false);
|
||||
functions.push_back(addLocationSuffix(str, location));
|
||||
functions.push_back(addLocationSuffix(str, location, scopeLocation));
|
||||
|
||||
addTypeUse(returnType);
|
||||
for (const ParseTypeUsage& parameter : parameters)
|
||||
@@ -842,13 +846,13 @@ private:
|
||||
virtual void onMethodParsed(
|
||||
const ParseLocation& location, const std::string& fullName, const ParseTypeUsage& returnType,
|
||||
const std::vector<ParseTypeUsage>& parameters, AccessType access, AbstractionType abstraction,
|
||||
bool isConst, bool isStatic
|
||||
bool isConst, bool isStatic, const ParseLocation& scopeLocation
|
||||
)
|
||||
{
|
||||
std::string str = functionStr(returnType.dataType, fullName, parameters, isConst);
|
||||
str = addStaticPrefix(addAbstractionPrefix(str, abstraction), isStatic);
|
||||
str = addAccessPrefix(str, access);
|
||||
str = addLocationSuffix(str, location);
|
||||
str = addLocationSuffix(str, location, scopeLocation);
|
||||
methods.push_back(str);
|
||||
|
||||
addTypeUse(returnType);
|
||||
@@ -858,14 +862,17 @@ private:
|
||||
}
|
||||
}
|
||||
|
||||
virtual void onNamespaceParsed(const ParseLocation& location, const std::string& fullName)
|
||||
virtual void onNamespaceParsed(
|
||||
const ParseLocation& location, const std::string& fullName, const ParseLocation& scopeLocation)
|
||||
{
|
||||
namespaces.push_back(addLocationSuffix(fullName, location));
|
||||
namespaces.push_back(addLocationSuffix(fullName, location, scopeLocation));
|
||||
}
|
||||
|
||||
virtual void onEnumParsed(const ParseLocation& location, const std::string& fullName, AccessType access)
|
||||
virtual void onEnumParsed(
|
||||
const ParseLocation& location, const std::string& fullName, AccessType access,
|
||||
const ParseLocation& scopeLocation)
|
||||
{
|
||||
enums.push_back(addLocationSuffix(addAccessPrefix(fullName, access), location));
|
||||
enums.push_back(addLocationSuffix(addAccessPrefix(fullName, access), location, scopeLocation));
|
||||
}
|
||||
|
||||
virtual void onEnumFieldParsed(const ParseLocation& location, const std::string& fullName)
|
||||
|
||||
Reference in New Issue
Block a user