|
|
@ -43,31 +43,38 @@ public class VirtualLockUsageChecker extends SquidCheck<Grammar> { |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void visitNode(AstNode astNode) { |
|
|
|
public void visitNode(AstNode astNode) { |
|
|
|
String varName = astNode.getFirstDescendant(CxxGrammarImpl.declaratorId).getTokenOriginalValue(); |
|
|
|
AstNode descendant = astNode.getFirstDescendant(CxxGrammarImpl.declaratorId); |
|
|
|
|
|
|
|
if(descendant != null){ |
|
|
|
|
|
|
|
String varName = descendant.getTokenValue(); |
|
|
|
|
|
|
|
|
|
|
|
for (String keyword : keywords) { |
|
|
|
for (String keyword : keywords) { |
|
|
|
if (varName.equals(keyword) && (!caches.equals(keyword) || !caches.get(keyword).equals(varName))) { |
|
|
|
if (varName.equals(keyword) && (!caches.equals(keyword) || !caches.get(keyword).equals(varName))) { |
|
|
|
caches.putIfAbsent(keyword, new HashMap<>()); |
|
|
|
caches.putIfAbsent(keyword, new HashMap<>()); |
|
|
|
caches.get(keyword).put(varName, astNode); |
|
|
|
caches.get(keyword).put(varName, astNode); |
|
|
|
processNode(astNode, keyword); |
|
|
|
processNode(astNode, keyword); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void processNode(AstNode astNode, String keyword) { |
|
|
|
private void processNode(AstNode astNode, String keyword) { |
|
|
|
String varName = astNode.getFirstDescendant(CxxGrammarImpl.declaratorId).getTokenOriginalValue(); |
|
|
|
AstNode descendant = astNode.getFirstDescendant(CxxGrammarImpl.declaratorId); |
|
|
|
|
|
|
|
if (descendant != null){ |
|
|
|
|
|
|
|
String varName = descendant.getTokenValue(); |
|
|
|
|
|
|
|
|
|
|
|
AstNode currentNode = astNode.getNextAstNode(); |
|
|
|
AstNode currentNode = astNode.getNextAstNode(); |
|
|
|
while (currentNode != null) { |
|
|
|
while (currentNode != null) { |
|
|
|
AstNode callNode = currentNode.getFirstDescendant(CxxGrammarImpl.postfixExpression); |
|
|
|
AstNode callNode = currentNode.getFirstDescendant(CxxGrammarImpl.postfixExpression); |
|
|
|
if (callNode != null && callNode.getTokenOriginalValue().equalsIgnoreCase("VirtualLock")) { |
|
|
|
if (callNode != null && callNode.getTokenValue().equalsIgnoreCase("VirtualLock")) { |
|
|
|
List<AstNode> paramList = callNode.getDescendants(CxxGrammarImpl.expressionList); |
|
|
|
List<AstNode> paramList = callNode.getDescendants(CxxGrammarImpl.expressionList); |
|
|
|
if (paramList.stream().anyMatch(item -> item.getTokenOriginalValue().contains(keyword))) { |
|
|
|
if (paramList.stream().anyMatch(item -> item.getTokenValue().contains(keyword))) { |
|
|
|
caches.get(keyword).remove(varName); |
|
|
|
caches.get(keyword).remove(varName); |
|
|
|
break; |
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
currentNode = currentNode.getNextSibling(); |
|
|
|
} |
|
|
|
} |
|
|
|
currentNode = currentNode.getNextSibling(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|