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:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user