mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-09 17:25:38 +02:00
Fix for 167614, NPE in index-based name resolution.
This commit is contained in:
parent
bae61dd6e4
commit
29dfe7938f
1 changed files with 26 additions and 21 deletions
|
@ -836,19 +836,19 @@ public class CPPSemantics {
|
||||||
IType p = ps[i];
|
IType p = ps[i];
|
||||||
p = getUltimateType( p, true );
|
p = getUltimateType( p, true );
|
||||||
try {
|
try {
|
||||||
getAssociatedScopes( p, namespaces, classes );
|
getAssociatedScopes( p, namespaces, classes, data.astName.getTranslationUnit());
|
||||||
} catch ( DOMException e ) {
|
} catch ( DOMException e ) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return namespaces;
|
return namespaces;
|
||||||
}
|
}
|
||||||
|
|
||||||
static private void getAssociatedScopes( IType t, ObjectSet namespaces, ObjectSet classes ) throws DOMException{
|
static private void getAssociatedScopes( IType t, ObjectSet namespaces, ObjectSet classes, IASTTranslationUnit tu) throws DOMException{
|
||||||
//3.4.2-2
|
//3.4.2-2
|
||||||
if( t instanceof ICPPClassType ){
|
if( t instanceof ICPPClassType ){
|
||||||
if( !classes.containsKey( t ) ){
|
if( !classes.containsKey( t ) ){
|
||||||
classes.put( t );
|
classes.put( t );
|
||||||
IScope scope = getContainingNamespaceScope( (IBinding) t );
|
IScope scope = getContainingNamespaceScope( (IBinding) t, tu);
|
||||||
if( scope != null )
|
if( scope != null )
|
||||||
namespaces.put( scope );
|
namespaces.put( scope );
|
||||||
|
|
||||||
|
@ -859,35 +859,35 @@ public class CPPSemantics {
|
||||||
continue;
|
continue;
|
||||||
IBinding b = bases[i].getBaseClass();
|
IBinding b = bases[i].getBaseClass();
|
||||||
if( b instanceof IType )
|
if( b instanceof IType )
|
||||||
getAssociatedScopes( (IType) b, namespaces, classes );
|
getAssociatedScopes( (IType) b, namespaces, classes, tu);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if( t instanceof IEnumeration ){
|
} else if( t instanceof IEnumeration ){
|
||||||
IScope scope = getContainingNamespaceScope( (IBinding) t );
|
IScope scope = getContainingNamespaceScope( (IBinding) t, tu);
|
||||||
if(scope!=null)
|
if(scope!=null)
|
||||||
namespaces.put(scope);
|
namespaces.put(scope);
|
||||||
} else if( t instanceof IFunctionType ){
|
} else if( t instanceof IFunctionType ){
|
||||||
IFunctionType ft = (IFunctionType) t;
|
IFunctionType ft = (IFunctionType) t;
|
||||||
|
|
||||||
getAssociatedScopes( getUltimateType( ft.getReturnType(), true ), namespaces, classes );
|
getAssociatedScopes( getUltimateType( ft.getReturnType(), true ), namespaces, classes, tu);
|
||||||
IType [] ps = ft.getParameterTypes();
|
IType [] ps = ft.getParameterTypes();
|
||||||
for( int i = 0; i < ps.length; i++ ){
|
for( int i = 0; i < ps.length; i++ ){
|
||||||
getAssociatedScopes( getUltimateType( ps[i], true ), namespaces, classes );
|
getAssociatedScopes( getUltimateType( ps[i], true ), namespaces, classes, tu);
|
||||||
}
|
}
|
||||||
} else if( t instanceof ICPPPointerToMemberType ){
|
} else if( t instanceof ICPPPointerToMemberType ){
|
||||||
IBinding binding = ((ICPPPointerToMemberType)t).getMemberOfClass();
|
IBinding binding = ((ICPPPointerToMemberType)t).getMemberOfClass();
|
||||||
if( binding instanceof IType )
|
if( binding instanceof IType )
|
||||||
getAssociatedScopes( (IType)binding, namespaces, classes );
|
getAssociatedScopes( (IType)binding, namespaces, classes, tu);
|
||||||
getAssociatedScopes( getUltimateType( ((ICPPPointerToMemberType)t).getType(), true ), namespaces, classes );
|
getAssociatedScopes( getUltimateType( ((ICPPPointerToMemberType)t).getType(), true ), namespaces, classes, tu);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
static private ICPPNamespaceScope getContainingNamespaceScope( IBinding binding ) throws DOMException{
|
static private ICPPNamespaceScope getContainingNamespaceScope( IBinding binding, IASTTranslationUnit tu) throws DOMException{
|
||||||
if( binding == null ) return null;
|
if( binding == null ) return null;
|
||||||
IScope scope = binding.getScope();
|
IScope scope = binding.getScope();
|
||||||
while( scope != null && !(scope instanceof ICPPNamespaceScope) ){
|
while( scope != null && !(scope instanceof ICPPNamespaceScope) ){
|
||||||
scope = scope.getParent();
|
scope = getParentScope(scope, tu);
|
||||||
}
|
}
|
||||||
return (ICPPNamespaceScope) scope;
|
return (ICPPNamespaceScope) scope;
|
||||||
}
|
}
|
||||||
|
@ -1092,12 +1092,8 @@ public class CPPSemantics {
|
||||||
if( blockItem != null )
|
if( blockItem != null )
|
||||||
node = blockItem;
|
node = blockItem;
|
||||||
|
|
||||||
ICPPScope parentScope = (ICPPScope) scope.getParent();
|
ICPPScope parentScope = (ICPPScope) getParentScope(scope, node.getTranslationUnit());
|
||||||
// the index cannot return the translation unit as parent scope
|
if( parentScope instanceof ICPPTemplateScope ){
|
||||||
if (parentScope == null && scope instanceof IIndexBinding) {
|
|
||||||
parentScope= (ICPPScope) node.getTranslationUnit().getScope();
|
|
||||||
}
|
|
||||||
else if( parentScope instanceof ICPPTemplateScope ){
|
|
||||||
IASTNode parent = node.getParent();
|
IASTNode parent = node.getParent();
|
||||||
while( parent != null && !(parent instanceof ICPPASTTemplateDeclaration) ){
|
while( parent != null && !(parent instanceof ICPPASTTemplateDeclaration) ){
|
||||||
node = parent;
|
node = parent;
|
||||||
|
@ -1115,6 +1111,15 @@ public class CPPSemantics {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
private static Object lookupInParents( CPPSemantics.LookupData data, ICPPScope lookIn ) throws DOMException{
|
private static Object lookupInParents( CPPSemantics.LookupData data, ICPPScope lookIn ) throws DOMException{
|
||||||
ICPPBase [] bases = null;
|
ICPPBase [] bases = null;
|
||||||
if( lookIn instanceof ICPPClassScope ){
|
if( lookIn instanceof ICPPClassScope ){
|
||||||
|
@ -1330,7 +1335,7 @@ public class CPPSemantics {
|
||||||
|
|
||||||
//namespace are searched at most once
|
//namespace are searched at most once
|
||||||
if( !data.visited.containsKey( temp ) ){
|
if( !data.visited.containsKey( temp ) ){
|
||||||
enclosing = getClosestEnclosingScope( scope, temp );
|
enclosing = getClosestEnclosingScope( scope, temp, data.astName.getTranslationUnit());
|
||||||
|
|
||||||
//data.usingDirectives is a map from enclosing scope to a IScope[]
|
//data.usingDirectives is a map from enclosing scope to a IScope[]
|
||||||
//of namespaces to consider when we reach that enclosing scope
|
//of namespaces to consider when we reach that enclosing scope
|
||||||
|
@ -1345,16 +1350,16 @@ public class CPPSemantics {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static private ICPPScope getClosestEnclosingScope( IScope scope1, IScope scope2 ) throws DOMException{
|
static private ICPPScope getClosestEnclosingScope( IScope scope1, IScope scope2, IASTTranslationUnit tu) throws DOMException{
|
||||||
ObjectSet set = new ObjectSet( 2 );
|
ObjectSet set = new ObjectSet( 2 );
|
||||||
IScope parent = scope1;
|
IScope parent = scope1;
|
||||||
while( parent != null ){
|
while( parent != null ){
|
||||||
set.put( parent );
|
set.put( parent );
|
||||||
parent = parent.getParent();
|
parent = getParentScope(parent, tu);
|
||||||
}
|
}
|
||||||
parent = scope2;
|
parent = scope2;
|
||||||
while( parent != null && !set.containsKey( parent ) ){
|
while( parent != null && !set.containsKey( parent ) ){
|
||||||
parent = parent.getParent();
|
parent = getParentScope(parent, tu);
|
||||||
}
|
}
|
||||||
return (ICPPScope) parent;
|
return (ICPPScope) parent;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue