mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-08 02:06:01 +02:00
Bug 467358 - NPE in CVisitor.getContainingBlockItem
Change-Id: I5f682df17b9e85539cfb033699d8d1346ead6a25
(cherry picked from commit 1573d6467d
)
This commit is contained in:
parent
323c3119e7
commit
cfd440afca
2 changed files with 17 additions and 18 deletions
|
@ -1064,20 +1064,22 @@ public class CVisitor extends ASTQueries {
|
|||
}
|
||||
|
||||
private static IASTNode getContainingBlockItem(IASTNode node) {
|
||||
IASTNode parent = node.getParent();
|
||||
for (IASTNode parent = node.getParent(); parent != null; parent = parent.getParent()) {
|
||||
if (parent instanceof IASTDeclaration) {
|
||||
IASTNode p = parent.getParent();
|
||||
if (p instanceof IASTDeclarationStatement)
|
||||
return p;
|
||||
return parent;
|
||||
} else if (parent instanceof IASTCompoundStatement || // parent is something that can contain a declaration
|
||||
}
|
||||
if (parent instanceof IASTCompoundStatement || // parent is something that can contain a declaration
|
||||
parent instanceof IASTTranslationUnit ||
|
||||
parent instanceof IASTForStatement ||
|
||||
parent instanceof IASTFunctionDeclarator) {
|
||||
return node;
|
||||
}
|
||||
|
||||
return getContainingBlockItem(parent);
|
||||
node = parent;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1362,10 +1362,8 @@ public class CPPVisitor extends ASTQueries {
|
|||
public static IASTNode getContainingBlockItem(IASTNode node) {
|
||||
if (node == null) return null;
|
||||
if (node.getPropertyInParent() == null) return null;
|
||||
IASTNode parent = node.getParent();
|
||||
if (parent == null)
|
||||
return null;
|
||||
while (parent != null) {
|
||||
|
||||
for (IASTNode parent = node.getParent(); parent != null; parent = parent.getParent()) {
|
||||
if (parent instanceof IASTDeclaration) {
|
||||
IASTNode p = parent.getParent();
|
||||
if (p instanceof IASTDeclarationStatement)
|
||||
|
@ -1387,7 +1385,6 @@ public class CPPVisitor extends ASTQueries {
|
|||
return parent;
|
||||
}
|
||||
node = parent;
|
||||
parent = node.getParent();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue