data: parsing and saving method overrides
This change parses method overrides and saves them in the Storage with type EDGE_OVERRIDE.
This commit is contained in:
@@ -357,6 +357,18 @@ Id Storage::onInheritanceParsed(
|
||||
return edge->getId();
|
||||
}
|
||||
|
||||
Id Storage::onMethodOverrideParsed(const ParseFunction& base, const ParseFunction& overrider)
|
||||
{
|
||||
log("override", base.getFullName() + " -> " + overrider.getFullName(), ParseLocation());
|
||||
|
||||
Node* baseNode = addNodeHierarchyWithDistinctSignature(Node::NODE_UNDEFINED_FUNCTION, base);
|
||||
Node* overriderNode = addNodeHierarchyWithDistinctSignature(Node::NODE_UNDEFINED_FUNCTION, overrider);
|
||||
|
||||
Edge* edge = m_graph.createEdge(Edge::EDGE_OVERRIDE, baseNode, overriderNode);
|
||||
|
||||
return edge->getId();
|
||||
}
|
||||
|
||||
Id Storage::onCallParsed(const ParseLocation& location, const ParseFunction& caller, const ParseFunction& callee)
|
||||
{
|
||||
log("call", caller.getFullName() + " -> " + callee.getFullName(), location);
|
||||
|
||||
@@ -63,6 +63,7 @@ public:
|
||||
virtual Id onInheritanceParsed(
|
||||
const ParseLocation& location, const std::vector<std::string>& nameHierarchy,
|
||||
const std::vector<std::string>& baseNameHierarchy, AccessType access);
|
||||
virtual Id onMethodOverrideParsed(const ParseFunction& base, const ParseFunction& overrider);
|
||||
virtual Id onCallParsed(
|
||||
const ParseLocation& location, const ParseFunction& caller, const ParseFunction& callee);
|
||||
virtual Id onCallParsed(
|
||||
|
||||
@@ -125,6 +125,8 @@ std::string Edge::getTypeString(EdgeType type) const
|
||||
return "type_usage";
|
||||
case EDGE_INHERITANCE:
|
||||
return "inheritance";
|
||||
case EDGE_OVERRIDE:
|
||||
return "override";
|
||||
case EDGE_CALL:
|
||||
return "call";
|
||||
case EDGE_USAGE:
|
||||
@@ -215,6 +217,14 @@ bool Edge::checkType() const
|
||||
}
|
||||
return true;
|
||||
|
||||
case EDGE_OVERRIDE:
|
||||
if (!m_from->isType(Node::NODE_UNDEFINED_FUNCTION | Node::NODE_METHOD) ||
|
||||
!m_to->isType(Node::NODE_UNDEFINED_FUNCTION | Node::NODE_METHOD))
|
||||
{
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
|
||||
case EDGE_CALL:
|
||||
if (!m_from->isType(variableMask | functionMask) || !m_to->isType(functionMask))
|
||||
{
|
||||
|
||||
@@ -25,13 +25,14 @@ public:
|
||||
EDGE_USAGE = 0x20,
|
||||
EDGE_CALL = 0x40,
|
||||
EDGE_INHERITANCE = 0x80,
|
||||
EDGE_TYPEDEF_OF = 0x100,
|
||||
EDGE_TEMPLATE_PARAMETER_OF = 0x200,
|
||||
EDGE_TEMPLATE_ARGUMENT_OF = 0x400,
|
||||
EDGE_TEMPLATE_DEFAULT_ARGUMENT_OF = 0x800,
|
||||
EDGE_TEMPLATE_SPECIALIZATION_OF = 0x1000,
|
||||
EDGE_OVERRIDE = 0x100,
|
||||
EDGE_TYPEDEF_OF = 0x200,
|
||||
EDGE_TEMPLATE_PARAMETER_OF = 0x400,
|
||||
EDGE_TEMPLATE_ARGUMENT_OF = 0x800,
|
||||
EDGE_TEMPLATE_DEFAULT_ARGUMENT_OF = 0x1000,
|
||||
EDGE_TEMPLATE_SPECIALIZATION_OF = 0x2000,
|
||||
|
||||
EDGE_AGGREGATION = 0x2000
|
||||
EDGE_AGGREGATION = 0x4000
|
||||
};
|
||||
|
||||
Edge(EdgeType type, Node* from, Node* to);
|
||||
|
||||
@@ -82,6 +82,7 @@ public:
|
||||
virtual Id onInheritanceParsed(
|
||||
const ParseLocation& location, const std::vector<std::string>& nameHierarchy,
|
||||
const std::vector<std::string>& baseNameHierarchy, AccessType access) = 0;
|
||||
virtual Id onMethodOverrideParsed(const ParseFunction& base, const ParseFunction& overrider) = 0;
|
||||
virtual Id onCallParsed(
|
||||
const ParseLocation& location, const ParseFunction& caller, const ParseFunction& callee) = 0;
|
||||
virtual Id onCallParsed(
|
||||
|
||||
@@ -180,14 +180,22 @@ bool ASTVisitor::VisitCXXMethodDecl(clang::CXXMethodDecl* declaration)
|
||||
abstraction = ParserClient::ABSTRACTION_VIRTUAL;
|
||||
}
|
||||
|
||||
ParseFunction parseFunction = getParseFunction(declaration);
|
||||
|
||||
m_client->onMethodParsed(
|
||||
getParseLocationForNamedDecl(declaration),
|
||||
getParseFunction(declaration),
|
||||
parseFunction,
|
||||
convertAccessType(declaration->getAccess()),
|
||||
abstraction,
|
||||
getParseLocationOfFunctionBody(declaration)
|
||||
);
|
||||
|
||||
for (clang::CXXMethodDecl::method_iterator it = declaration->begin_overridden_methods();
|
||||
it != declaration->end_overridden_methods(); it++)
|
||||
{
|
||||
m_client->onMethodOverrideParsed(getParseFunction(*it), parseFunction);
|
||||
}
|
||||
|
||||
if (declaration->hasBody() && declaration->getBody() != NULL && declaration->isThisDeclarationADefinition())
|
||||
{
|
||||
ASTBodyVisitor bodyVisitor(this, declaration);
|
||||
@@ -725,7 +733,7 @@ ParseTypeUsage ASTVisitor::getParseTypeUsage(clang::TypeLoc typeLoc, const clang
|
||||
return ParseTypeUsage(parseLocation, dataType);
|
||||
}
|
||||
|
||||
ParseTypeUsage ASTVisitor::getParseTypeUsageOfReturnType(clang::FunctionDecl* declaration) const
|
||||
ParseTypeUsage ASTVisitor::getParseTypeUsageOfReturnType(const clang::FunctionDecl* declaration) const
|
||||
{
|
||||
clang::TypeLoc typeLoc;
|
||||
|
||||
@@ -742,13 +750,13 @@ ParseTypeUsage ASTVisitor::getParseTypeUsageOfReturnType(clang::FunctionDecl* de
|
||||
return getParseTypeUsage(typeLoc, declaration->getReturnType());
|
||||
}
|
||||
|
||||
std::vector<ParseTypeUsage> ASTVisitor::getParameters(clang::FunctionDecl* declaration) const
|
||||
std::vector<ParseTypeUsage> ASTVisitor::getParameters(const clang::FunctionDecl* declaration) const
|
||||
{
|
||||
std::vector<ParseTypeUsage> parameters;
|
||||
|
||||
for (unsigned i = 0; i < declaration->getNumParams(); i++)
|
||||
{
|
||||
clang::ParmVarDecl* paramDecl = declaration->getParamDecl(i);
|
||||
const clang::ParmVarDecl* paramDecl = declaration->getParamDecl(i);
|
||||
if (paramDecl->getTypeSourceInfo())
|
||||
{
|
||||
parameters.push_back(getParseTypeUsage(paramDecl->getTypeSourceInfo()->getTypeLoc(), paramDecl->getType()));
|
||||
@@ -758,13 +766,13 @@ std::vector<ParseTypeUsage> ASTVisitor::getParameters(clang::FunctionDecl* decla
|
||||
return parameters;
|
||||
}
|
||||
|
||||
ParseVariable ASTVisitor::getParseVariable(clang::DeclaratorDecl* declaration) const
|
||||
ParseVariable ASTVisitor::getParseVariable(const clang::DeclaratorDecl* declaration) const
|
||||
{
|
||||
bool isStatic = false;
|
||||
std::vector<std::string> hameHierarchy = utility::getDeclNameHierarchy(declaration);
|
||||
if (clang::isa<clang::VarDecl>(declaration))
|
||||
{
|
||||
clang::VarDecl* varDecl = clang::dyn_cast<clang::VarDecl>(declaration);
|
||||
const clang::VarDecl* varDecl = clang::dyn_cast<const clang::VarDecl>(declaration);
|
||||
isStatic = varDecl->isStaticDataMember() || varDecl->getStorageClass() == clang::SC_Static;
|
||||
}
|
||||
else if (clang::isa<clang::FieldDecl>(declaration))
|
||||
@@ -779,14 +787,14 @@ ParseVariable ASTVisitor::getParseVariable(clang::DeclaratorDecl* declaration) c
|
||||
);
|
||||
}
|
||||
|
||||
ParseFunction ASTVisitor::getParseFunction(clang::FunctionDecl* declaration) const
|
||||
ParseFunction ASTVisitor::getParseFunction(const clang::FunctionDecl* declaration) const
|
||||
{
|
||||
bool isStatic = false;
|
||||
bool isConst = false;
|
||||
|
||||
if (clang::isa<clang::CXXMethodDecl>(declaration))
|
||||
{
|
||||
clang::CXXMethodDecl* methodDecl = clang::dyn_cast<clang::CXXMethodDecl>(declaration);
|
||||
const clang::CXXMethodDecl* methodDecl = clang::dyn_cast<const clang::CXXMethodDecl>(declaration);
|
||||
isStatic = methodDecl->isStatic();
|
||||
isConst = methodDecl->isConst();
|
||||
}
|
||||
|
||||
@@ -68,11 +68,11 @@ private:
|
||||
ParseLocation getParseLocationOfRecordBody(clang::CXXRecordDecl* decl) const;
|
||||
|
||||
ParseTypeUsage getParseTypeUsage(clang::TypeLoc typeLoc, const clang::QualType& type) const;
|
||||
ParseTypeUsage getParseTypeUsageOfReturnType(clang::FunctionDecl* declaration) const;
|
||||
std::vector<ParseTypeUsage> getParameters(clang::FunctionDecl* declaration) const;
|
||||
ParseTypeUsage getParseTypeUsageOfReturnType(const clang::FunctionDecl* declaration) const;
|
||||
std::vector<ParseTypeUsage> getParameters(const clang::FunctionDecl* declaration) const;
|
||||
|
||||
ParseVariable getParseVariable(clang::DeclaratorDecl* declaration) const;
|
||||
ParseFunction getParseFunction(clang::FunctionDecl* declaration) const;
|
||||
ParseVariable getParseVariable(const clang::DeclaratorDecl* declaration) const;
|
||||
ParseFunction getParseFunction(const clang::FunctionDecl* declaration) const;
|
||||
|
||||
clang::ASTContext* m_context;
|
||||
ParserClient* m_client;
|
||||
|
||||
@@ -105,7 +105,7 @@ namespace utility
|
||||
return DataType(typeNameHerarchy, qualifierList, modifierStack);
|
||||
}
|
||||
|
||||
std::vector<std::string> getDeclNameHierarchy(clang::Decl* declaration)
|
||||
std::vector<std::string> getDeclNameHierarchy(const clang::Decl* declaration)
|
||||
{
|
||||
std::vector<std::string> contextNameHierarchy;
|
||||
if (declaration)
|
||||
@@ -114,7 +114,7 @@ namespace utility
|
||||
|
||||
if (clang::isa<clang::NamedDecl>(declaration))
|
||||
{
|
||||
declName = getDeclName(clang::dyn_cast<clang::NamedDecl>(declaration));
|
||||
declName = getDeclName(clang::dyn_cast<const clang::NamedDecl>(declaration));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -133,11 +133,11 @@ namespace utility
|
||||
return contextNameHierarchy;
|
||||
}
|
||||
|
||||
std::vector<std::string> getContextNameHierarchy(clang::DeclContext* declContext)
|
||||
std::vector<std::string> getContextNameHierarchy(const clang::DeclContext* declContext)
|
||||
{
|
||||
std::vector<std::string> contextNameHierarchy;
|
||||
|
||||
clang::DeclContext* parentContext = declContext->getParent();
|
||||
const clang::DeclContext* parentContext = declContext->getParent();
|
||||
if (parentContext)
|
||||
{
|
||||
contextNameHierarchy = getContextNameHierarchy(parentContext);
|
||||
@@ -145,7 +145,7 @@ namespace utility
|
||||
|
||||
if (clang::isa<clang::NamedDecl>(declContext))
|
||||
{
|
||||
std::string declName = getDeclName(clang::dyn_cast<clang::NamedDecl>(declContext));
|
||||
std::string declName = getDeclName(clang::dyn_cast<const clang::NamedDecl>(declContext));
|
||||
if (declName != "")
|
||||
{
|
||||
contextNameHierarchy.push_back(declName);
|
||||
@@ -154,7 +154,7 @@ namespace utility
|
||||
return contextNameHierarchy;
|
||||
}
|
||||
|
||||
std::string getDeclName(clang::NamedDecl* declaration)
|
||||
std::string getDeclName(const clang::NamedDecl* declaration)
|
||||
{
|
||||
std::string declName = declaration->getNameAsString();
|
||||
|
||||
|
||||
@@ -15,9 +15,9 @@ namespace utility
|
||||
{
|
||||
DataType qualTypeToDataType(clang::QualType qualType);
|
||||
|
||||
std::vector<std::string> getDeclNameHierarchy(clang::Decl* declaration);
|
||||
std::vector<std::string> getContextNameHierarchy(clang::DeclContext* declaration);
|
||||
std::string getDeclName(clang::NamedDecl* declaration);
|
||||
std::vector<std::string> getDeclNameHierarchy(const clang::Decl* declaration);
|
||||
std::vector<std::string> getContextNameHierarchy(const clang::DeclContext* declaration);
|
||||
std::string getDeclName(const clang::NamedDecl* declaration);
|
||||
std::vector<std::string> getTemplateSpecializationParentNameHierarchy(clang::ClassTemplateSpecializationDecl* declaration);
|
||||
DataType templateArgumentToDataType(const clang::TemplateArgument& argument);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user