Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,11 @@ private void visitDeclaratorList(AstNode declaratorList) {
return;
}

// ignore friend declarations
if (isFriendDeclaration(declaratorList)) {
return;
}

AstNode declaration = declaratorList
.getFirstAncestor(CxxGrammarImpl.declaration);

Expand All @@ -210,6 +215,36 @@ private void visitDeclaratorList(AstNode declaratorList) {
}
}

private boolean isFriendDeclaration(AstNode declaratorList) {
AstNode simpleDeclNode = declaratorList
.getFirstAncestor(CxxGrammarImpl.simpleDeclaration);

if (simpleDeclNode == null) {
LOG.warn("No simple declaration found for declarator list at {}",
declaratorList.getTokenLine());
return false;
}

AstNode simpleDeclSpecifierSeq = simpleDeclNode
.getFirstChild(CxxGrammarImpl.simpleDeclSpecifierSeq);

if (simpleDeclSpecifierSeq == null) {
return false;
}

List<AstNode> declSpecifiers = simpleDeclSpecifierSeq
.getChildren(CxxGrammarImpl.declSpecifier);

for (AstNode declSpecifier : declSpecifiers) {
AstNode friendNode = declSpecifier.getFirstChild(CxxKeyword.FRIEND);
if (friendNode != null) {
return true;
}
}

return false;
}

private void visitSingleDeclarator(AstNode declaration,
AstNode declarator) {

Expand Down
5 changes: 5 additions & 0 deletions cxx-squid/src/test/resources/metrics/public_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ class testClass

int attr1, //!< attr1 doc
attr2; ///< attr2 doc

// ignore friend declaration
template<typename S> friend S& operator<<(S&, A const&);

friend class friendClass;
protected:
/**
protectedMethod doc
Expand Down