Skip to content

Commit

Permalink
Merge pull request #1072 from guwirth/AbstractCxxPublicApiVisitor-fix…
Browse files Browse the repository at this point in the history
…-1067

fix template declaration
  • Loading branch information
guwirth authored Mar 2, 2017
2 parents 5aa147c + 8f33d6b commit 3a22641
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -204,12 +204,12 @@ private void visitDeclaratorList(AstNode declaratorList) {
if (memberDeclaration != null) {
return;
}

// ignore classSpefifier typedefs (classSpefifier at classSpefifier)
if (isTypedef(declaratorList)) {
return;
}

// ignore friend declarations
if (isFriendDeclarationList(declaratorList)) {
return;
Expand Down Expand Up @@ -254,7 +254,7 @@ private boolean isTypedef(AstNode declaratorList) {
}
return false;
}

private boolean isFriendDeclarationList(AstNode declaratorList) {
AstNode simpleDeclNode = declaratorList
.getFirstAncestor(CxxGrammarImpl.simpleDeclaration);
Expand Down Expand Up @@ -353,7 +353,7 @@ private AstNode getTypedefNode(AstNode classSpecifier) {
}
return null;
}

private void visitClassSpecifier(AstNode classSpecifier) {

// check if this is a template specification to adjust documentation node
Expand All @@ -365,7 +365,7 @@ private void visitClassSpecifier(AstNode classSpecifier) {
docNode = classSpecifier;
}
}

// narrow the identifier search scope to classHead
AstNode classHead = classSpecifier
.getFirstDescendant(CxxGrammarImpl.classHead);
Expand Down Expand Up @@ -477,15 +477,18 @@ private boolean isFriendMemberDeclaration(AstNode memberDeclaration) {

return false;
}

private void visitTemplateDeclaration(AstNode templateDeclaration) {

if (isFriendMemberDeclaration(templateDeclaration.getParent())) {
return;
}

String id = templateDeclaration.getFirstDescendant(CxxGrammarImpl.className)
.getTokenValue();
AstNode className = templateDeclaration.getFirstDescendant(CxxGrammarImpl.className);
if (className == null) {
return;
}
String id = className.getTokenValue();

// handle cascaded template declarations
AstNode node = templateDeclaration;
Expand All @@ -498,10 +501,10 @@ private void visitTemplateDeclaration(AstNode templateDeclaration) {
}
node = node.getFirstAncestor(CxxGrammarImpl.templateDeclaration);
} while (node != null);

visitPublicApi(templateDeclaration, id, comments);
}

private void visitFunctionDefinition(AstNode functionDef) {
if (isPublicApiMember(functionDef)) {
// filter out deleted and defaulted methods
Expand Down Expand Up @@ -570,7 +573,7 @@ private void visitMemberDeclarator(AstNode node) {
AstNode container = node.getFirstAncestor(
CxxGrammarImpl.templateDeclaration,
CxxGrammarImpl.classSpecifier);

AstNode docNode = node;
List<Token> comments;

Expand Down Expand Up @@ -629,8 +632,8 @@ private void visitAliasDeclaration(AstNode aliasDeclNode) {
CxxGrammarImpl.classSpecifier);

// An alias declaration inside a function is not part of the public API
if (parent != null && parent.getType() == CxxGrammarImpl.functionDefinition){
return;
if (parent != null && parent.getType() == CxxGrammarImpl.functionDefinition) {
return;
}

if (isPublicApiMember(aliasDeclNode)) {
Expand Down Expand Up @@ -687,7 +690,7 @@ private void visitEnumSpecifier(AstNode enumSpecifierNode) {
if (docNode == null) {
docNode = enumSpecifierNode;
}

visitPublicApi(
enumSpecifierNode, enumId,
getBlockDocumentation(docNode));
Expand Down Expand Up @@ -778,7 +781,7 @@ private static List<Token> getDeclaratorInlineComment(AstNode declarator) {

private static boolean isPublicApiMember(AstNode node) {
AstNode access = node;

// retrieve the accessSpecifier
do {
access = access.getPreviousAstNode();
Expand Down Expand Up @@ -816,9 +819,9 @@ private static boolean isPublicApiMember(AstNode node) {
} else {
LOG.error("isPublicApiMember: failed to get enclosing classSpecifier for node at {}", node.getTokenLine());
return false;
}
}
}

// method or function outside of class
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public void no_doc() throws IOException {

@Test
public void template() throws IOException {
testFile("src/test/resources/metrics/template.h", 13, 4, false);
testFile("src/test/resources/metrics/template.h", 14, 4, false);
}

@Test
Expand Down
7 changes: 7 additions & 0 deletions cxx-squid/src/test/resources/metrics/template.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,10 @@ template <class T>
void TestClass2::functionTest2()
{
}

/**
* @brief issue #1067
*/
struct A {
template<class T> class B;
};

0 comments on commit 3a22641

Please sign in to comment.