mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Fix for 156937, NPE in name resolution.
This commit is contained in:
parent
59db91ccde
commit
9405806525
1 changed files with 21 additions and 7 deletions
|
@ -139,6 +139,7 @@ import org.eclipse.cdt.core.dom.ast.gnu.IGNUASTCompoundStatementExpression;
|
||||||
import org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPASTPointer;
|
import org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPASTPointer;
|
||||||
import org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPASTPointerToMember;
|
import org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPASTPointerToMember;
|
||||||
import org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPASTSimpleDeclSpecifier;
|
import org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPASTSimpleDeclSpecifier;
|
||||||
|
import org.eclipse.cdt.core.index.IIndexBinding;
|
||||||
import org.eclipse.cdt.core.parser.util.ArrayUtil;
|
import org.eclipse.cdt.core.parser.util.ArrayUtil;
|
||||||
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
|
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.ASTInternal;
|
import org.eclipse.cdt.internal.core.dom.parser.ASTInternal;
|
||||||
|
@ -326,7 +327,7 @@ public class CPPVisitor {
|
||||||
ICPPScope parentScope = null;
|
ICPPScope parentScope = null;
|
||||||
try {
|
try {
|
||||||
template = true;
|
template = true;
|
||||||
parentScope = (ICPPScope) scope.getParent();
|
parentScope = (ICPPScope) getParentScope(scope, elabType.getTranslationUnit());
|
||||||
} catch (DOMException e1) {
|
} catch (DOMException e1) {
|
||||||
}
|
}
|
||||||
scope = parentScope;
|
scope = parentScope;
|
||||||
|
@ -337,7 +338,7 @@ public class CPPVisitor {
|
||||||
//the declaration
|
//the declaration
|
||||||
while( scope instanceof ICPPClassScope || scope instanceof ICPPFunctionScope ){
|
while( scope instanceof ICPPClassScope || scope instanceof ICPPFunctionScope ){
|
||||||
try {
|
try {
|
||||||
scope = (ICPPScope) scope.getParent();
|
scope = (ICPPScope) getParentScope(scope, elabType.getTranslationUnit());
|
||||||
} catch (DOMException e1) {
|
} catch (DOMException e1) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -345,7 +346,7 @@ public class CPPVisitor {
|
||||||
if( scope instanceof ICPPClassScope && isFriend && !qualified ){
|
if( scope instanceof ICPPClassScope && isFriend && !qualified ){
|
||||||
try {
|
try {
|
||||||
while( scope instanceof ICPPClassScope )
|
while( scope instanceof ICPPClassScope )
|
||||||
scope = (ICPPScope) scope.getParent();
|
scope = (ICPPScope) getParentScope(scope, elabType.getTranslationUnit());
|
||||||
} catch ( DOMException e1 ) {
|
} catch ( DOMException e1 ) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -380,7 +381,7 @@ public class CPPVisitor {
|
||||||
template = true;
|
template = true;
|
||||||
ICPPScope parentScope = null;
|
ICPPScope parentScope = null;
|
||||||
try {
|
try {
|
||||||
parentScope = (ICPPScope) scope.getParent();
|
parentScope = (ICPPScope) getParentScope(scope, compType.getTranslationUnit());
|
||||||
} catch (DOMException e1) {
|
} catch (DOMException e1) {
|
||||||
}
|
}
|
||||||
scope = parentScope;
|
scope = parentScope;
|
||||||
|
@ -488,7 +489,7 @@ public class CPPVisitor {
|
||||||
ICPPScope parentScope = null;
|
ICPPScope parentScope = null;
|
||||||
try {
|
try {
|
||||||
template = true;
|
template = true;
|
||||||
parentScope = (ICPPScope) scope.getParent();
|
parentScope = (ICPPScope) getParentScope(scope, name.getTranslationUnit());
|
||||||
} catch (DOMException e1) {
|
} catch (DOMException e1) {
|
||||||
}
|
}
|
||||||
scope = parentScope;
|
scope = parentScope;
|
||||||
|
@ -497,7 +498,7 @@ public class CPPVisitor {
|
||||||
ICPPASTDeclSpecifier declSpec = (ICPPASTDeclSpecifier) ((IASTSimpleDeclaration)parent).getDeclSpecifier();
|
ICPPASTDeclSpecifier declSpec = (ICPPASTDeclSpecifier) ((IASTSimpleDeclaration)parent).getDeclSpecifier();
|
||||||
if( declSpec.isFriend() ){
|
if( declSpec.isFriend() ){
|
||||||
try {
|
try {
|
||||||
scope = (ICPPScope) scope.getParent();
|
scope = (ICPPScope) getParentScope(scope, name.getTranslationUnit());
|
||||||
} catch ( DOMException e1 ) {
|
} catch ( DOMException e1 ) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1655,7 +1656,7 @@ public class CPPVisitor {
|
||||||
IScope s = getContainingScope( fName );
|
IScope s = getContainingScope( fName );
|
||||||
ICPPASTFunctionDeclarator dtor = (ICPPASTFunctionDeclarator) def.getDeclarator();
|
ICPPASTFunctionDeclarator dtor = (ICPPASTFunctionDeclarator) def.getDeclarator();
|
||||||
if( s instanceof ICPPTemplateScope )
|
if( s instanceof ICPPTemplateScope )
|
||||||
s = s.getParent();
|
s = getParentScope(s, fName.getTranslationUnit());
|
||||||
if( s instanceof ICPPClassScope ){
|
if( s instanceof ICPPClassScope ){
|
||||||
ICPPClassScope cScope = (ICPPClassScope) s;
|
ICPPClassScope cScope = (ICPPClassScope) s;
|
||||||
IType type = cScope.getClassType();
|
IType type = cScope.getClassType();
|
||||||
|
@ -2011,6 +2012,9 @@ public class CPPVisitor {
|
||||||
if( scope instanceof ICPPTemplateScope )
|
if( scope instanceof ICPPTemplateScope )
|
||||||
scope = (ICPPScope) scope.getParent();
|
scope = (ICPPScope) scope.getParent();
|
||||||
|
|
||||||
|
if (scope == null)
|
||||||
|
break;
|
||||||
|
|
||||||
IName n = scope.getScopeName();
|
IName n = scope.getScopeName();
|
||||||
if( n == null )
|
if( n == null )
|
||||||
break;
|
break;
|
||||||
|
@ -2041,6 +2045,8 @@ public class CPPVisitor {
|
||||||
if( scope instanceof ICPPTemplateScope )
|
if( scope instanceof ICPPTemplateScope )
|
||||||
scope = (ICPPScope) scope.getParent();
|
scope = (ICPPScope) scope.getParent();
|
||||||
|
|
||||||
|
if (scope == null)
|
||||||
|
break;
|
||||||
IName n = scope.getScopeName();
|
IName n = scope.getScopeName();
|
||||||
if( n == null )
|
if( n == null )
|
||||||
break;
|
break;
|
||||||
|
@ -2063,4 +2069,12 @@ public class CPPVisitor {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static IScope getParentScope(IScope scope, IASTTranslationUnit unit) throws DOMException {
|
||||||
|
IScope parentScope= scope.getParent();
|
||||||
|
// the index cannot return the translation unit as parent scope
|
||||||
|
if (parentScope == null && scope instanceof IIndexBinding) {
|
||||||
|
parentScope= unit.getScope();
|
||||||
|
}
|
||||||
|
return parentScope;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue