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