mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-08 10:16:03 +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) {
|
private static IASTNode getContainingBlockItem(IASTNode node) {
|
||||||
IASTNode parent = node.getParent();
|
for (IASTNode parent = node.getParent(); parent != null; parent = parent.getParent()) {
|
||||||
if (parent instanceof IASTDeclaration) {
|
if (parent instanceof IASTDeclaration) {
|
||||||
IASTNode p = parent.getParent();
|
IASTNode p = parent.getParent();
|
||||||
if (p instanceof IASTDeclarationStatement)
|
if (p instanceof IASTDeclarationStatement)
|
||||||
return p;
|
return p;
|
||||||
return parent;
|
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 IASTTranslationUnit ||
|
||||||
parent instanceof IASTForStatement ||
|
parent instanceof IASTForStatement ||
|
||||||
parent instanceof IASTFunctionDeclarator) {
|
parent instanceof IASTFunctionDeclarator) {
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
node = parent;
|
||||||
return getContainingBlockItem(parent);
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1362,10 +1362,8 @@ public class CPPVisitor extends ASTQueries {
|
||||||
public static IASTNode getContainingBlockItem(IASTNode node) {
|
public static IASTNode getContainingBlockItem(IASTNode node) {
|
||||||
if (node == null) return null;
|
if (node == null) return null;
|
||||||
if (node.getPropertyInParent() == null) return null;
|
if (node.getPropertyInParent() == null) return null;
|
||||||
IASTNode parent = node.getParent();
|
|
||||||
if (parent == null)
|
for (IASTNode parent = node.getParent(); parent != null; parent = parent.getParent()) {
|
||||||
return null;
|
|
||||||
while (parent != null) {
|
|
||||||
if (parent instanceof IASTDeclaration) {
|
if (parent instanceof IASTDeclaration) {
|
||||||
IASTNode p = parent.getParent();
|
IASTNode p = parent.getParent();
|
||||||
if (p instanceof IASTDeclarationStatement)
|
if (p instanceof IASTDeclarationStatement)
|
||||||
|
@ -1387,7 +1385,6 @@ public class CPPVisitor extends ASTQueries {
|
||||||
return parent;
|
return parent;
|
||||||
}
|
}
|
||||||
node = parent;
|
node = parent;
|
||||||
parent = node.getParent();
|
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue