diff --git a/bin/app/data/ApplicationSettings.xml b/bin/app/data/ApplicationSettings.xml
index e6b93f98..f8aab3de 100644
--- a/bin/app/data/ApplicationSettings.xml
+++ b/bin/app/data/ApplicationSettings.xml
@@ -4,7 +4,8 @@
4
Courier
12
- 222 222 222 100
+ 235 235 235 255
+ 215 230 240 100
210 240 70 100
diff --git a/bin/app/data/src/header.h b/bin/app/data/src/header.h
index 33d387b5..8db34d1e 100644
--- a/bin/app/data/src/header.h
+++ b/bin/app/data/src/header.h
@@ -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;
diff --git a/src/app/qt/element/QtCodeSnippet.cpp b/src/app/qt/element/QtCodeSnippet.cpp
index 44b649fc..6eaf3376 100644
--- a/src/app/qt/element/QtCodeSnippet.cpp
+++ b/src/app/qt/element/QtCodeSnippet.cpp
@@ -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();
diff --git a/src/app/qt/element/QtCodeSnippet.h b/src/app/qt/element/QtCodeSnippet.h
index 8cf683d9..c4b902e0 100644
--- a/src/app/qt/element/QtCodeSnippet.h
+++ b/src/app/qt/element/QtCodeSnippet.h
@@ -75,6 +75,7 @@ private:
int start;
int end;
Id tokenId;
+ bool isScope;
};
void createAnnotations(const TokenLocationFile& locationFile);
diff --git a/src/lib/ApplicationSettings.cpp b/src/lib/ApplicationSettings.cpp
index 88771f97..142b8c41 100644
--- a/src/lib/ApplicationSettings.cpp
+++ b/src/lib/ApplicationSettings.cpp
@@ -51,9 +51,19 @@ Colori ApplicationSettings::getCodeLinkColor() const
return Colori::fromString(getValue("code/LinkColor", Colori(255, 255, 0, 100).toString()));
}
-void ApplicationSettings::setCodeLinkColor(Colori codeLinkColor)
+void ApplicationSettings::setCodeLinkColor(Colori color)
{
- setValue("code/LinkColor", codeLinkColor.toString());
+ setValue("code/LinkColor", color.toString());
+}
+
+Colori ApplicationSettings::getCodeScopeColor() const
+{
+ return Colori::fromString(getValue("code/ScopeColor", Colori(255, 255, 0, 100).toString()));
+}
+
+void ApplicationSettings::setCodeScopeColor(Colori color)
+{
+ setValue("code/ScopeColor", color.toString());
}
Colori ApplicationSettings::getCodeActiveLinkColor() const
@@ -61,9 +71,9 @@ Colori ApplicationSettings::getCodeActiveLinkColor() const
return Colori::fromString(getValue("code/ActiveLinkColor", Colori(0, 255, 0, 100).toString()));
}
-void ApplicationSettings::setCodeActiveLinkColor(Colori codeLinkColor)
+void ApplicationSettings::setCodeActiveLinkColor(Colori color)
{
- setValue("code/ActiveLinkColor", codeLinkColor.toString());
+ setValue("code/ActiveLinkColor", color.toString());
}
ApplicationSettings::ApplicationSettings()
diff --git a/src/lib/ApplicationSettings.h b/src/lib/ApplicationSettings.h
index 5f878782..3a513dc9 100644
--- a/src/lib/ApplicationSettings.h
+++ b/src/lib/ApplicationSettings.h
@@ -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();
diff --git a/src/lib/data/Storage.cpp b/src/lib/data/Storage.cpp
index da22b247..8565c46e 100644
--- a/src/lib/data/Storage.cpp
+++ b/src/lib/data/Storage.cpp
@@ -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& parameters
+ const std::vector& 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& 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;
}
diff --git a/src/lib/data/Storage.h b/src/lib/data/Storage.h
index 21a3ea5c..e90c7076 100644
--- a/src/lib/data/Storage.h
+++ b/src/lib/data/Storage.h
@@ -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& parameters
+ const std::vector& parameters, const ParseLocation& scopeLocation
);
virtual void onMethodParsed(
const ParseLocation& location, const std::string& fullName, const ParseTypeUsage& returnType,
const std::vector& 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;
diff --git a/src/lib/data/location/TokenLocation.cpp b/src/lib/data/location/TokenLocation.cpp
index 078cb386..ab61f2a8 100644
--- a/src/lib/data/location/TokenLocation.cpp
+++ b/src/lib/data/location/TokenLocation.cpp
@@ -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::createPlainCopy(TokenLocationLine* line) const
-{
- return std::shared_ptr(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)
diff --git a/src/lib/data/location/TokenLocation.h b/src/lib/data/location/TokenLocation.h
index 8a9f7d1e..58f51164 100644
--- a/src/lib/data/location/TokenLocation.h
+++ b/src/lib/data/location/TokenLocation.h
@@ -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 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;
diff --git a/src/lib/data/location/TokenLocationLine.cpp b/src/lib/data/location/TokenLocationLine.cpp
index 81ba5c50..f8b44dbd 100644
--- a/src/lib/data/location/TokenLocationLine.cpp
+++ b/src/lib/data/location/TokenLocationLine.cpp
@@ -48,12 +48,8 @@ TokenLocation* TokenLocationLine::addStartTokenLocation(Id tokenId, unsigned int
TokenLocation* TokenLocationLine::addEndTokenLocation(TokenLocation* start, unsigned int columnNumber)
{
- std::shared_ptr locationPtr = std::make_shared(
- start->getId(), start->getTokenId(), this, columnNumber, false);
-
+ std::shared_ptr locationPtr = std::make_shared(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
TokenLocation* TokenLocationLine::addTokenLocationAsPlainCopy(const TokenLocation* location)
{
- std::shared_ptr locationPtr = location->createPlainCopy(this);
+ std::shared_ptr locationPtr = std::make_shared(*location, this);
m_locations.emplace(location->getColumnNumber(), locationPtr);
return locationPtr.get();
}
diff --git a/src/lib/data/parser/ParseLocation.cpp b/src/lib/data/parser/ParseLocation.cpp
index 818bcf99..b2e9e27e 100644
--- a/src/lib/data/parser/ParseLocation.cpp
+++ b/src/lib/data/parser/ParseLocation.cpp
@@ -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)
diff --git a/src/lib/data/parser/ParseLocation.h b/src/lib/data/parser/ParseLocation.h
index 559db785..9092c359 100644
--- a/src/lib/data/parser/ParseLocation.h
+++ b/src/lib/data/parser/ParseLocation.h
@@ -3,20 +3,24 @@
#include
+#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
diff --git a/src/lib/data/parser/ParserClient.cpp b/src/lib/data/parser/ParserClient.cpp
index f9df09d7..2a4a4513 100644
--- a/src/lib/data/parser/ParserClient.cpp
+++ b/src/lib/data/parser/ParserClient.cpp
@@ -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;
diff --git a/src/lib/data/parser/ParserClient.h b/src/lib/data/parser/ParserClient.h
index bcbe841e..42f43006 100644
--- a/src/lib/data/parser/ParserClient.h
+++ b/src/lib/data/parser/ParserClient.h
@@ -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 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& parameters) = 0;
+ const std::vector& parameters, const ParseLocation& scopeLocation) = 0;
virtual void onMethodParsed(
const ParseLocation& location, const std::string& fullName, const ParseTypeUsage& returnType,
const std::vector& 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(
diff --git a/src/lib/data/parser/cxx/ASTVisitor.cpp b/src/lib/data/parser/cxx/ASTVisitor.cpp
index 628d9485..8f634bec 100644
--- a/src/lib/data/parser/cxx/ASTVisitor.cpp
+++ b/src/lib/data/parser/cxx/ASTVisitor.cpp
@@ -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;
diff --git a/src/lib/data/parser/cxx/ASTVisitor.h b/src/lib/data/parser/cxx/ASTVisitor.h
index 716582c6..f82ce81c 100644
--- a/src/lib/data/parser/cxx/ASTVisitor.h
+++ b/src/lib/data/parser/cxx/ASTVisitor.h
@@ -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;
diff --git a/src/test/CxxParserTestSuite.h b/src/test/CxxParserTestSuite.h
index 9316bb74..1300906f 100644
--- a/src/test/CxxParserTestSuite.h
+++ b/src/test/CxxParserTestSuite.h
@@ -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& parameters
+ const std::vector& 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& 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)