diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCBindingResolutionBugs.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCBindingResolutionBugs.java index b7f8a04ba6d..4124bdc0396 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCBindingResolutionBugs.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCBindingResolutionBugs.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2008 Wind River Systems, Inc. and others. + * Copyright (c) 2006, 2009 Wind River Systems, Inc. and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -397,4 +397,18 @@ public class IndexCBindingResolutionBugs extends IndexBindingResolutionTestBase assertTrue(params[0].getType() instanceof IBasicType); assertEquals(IBasicType.t_int, ((IBasicType)params[0].getType()).getType()); } + + // typedef struct S S; + // void setValue(S *pSelf, int value); + + // struct S { + // int value; + // }; + // void setValue(S *pSelf, int value) { + // pSelf->value = value; + // } + public void testOpaqueStruct_Bug262719() throws Exception { + IBinding b = getBindingFromASTName("value =", 5); + assertTrue(b instanceof IField); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTInternal.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTInternal.java index 7fe8c4ce1ef..d5d743e3062 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTInternal.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTInternal.java @@ -21,6 +21,8 @@ import org.eclipse.cdt.internal.core.dom.parser.c.ICInternalBinding; import org.eclipse.cdt.internal.core.dom.parser.c.ICInternalFunction; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBinding; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalFunction; +import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding; +import org.eclipse.core.runtime.CoreException; /** * Access to methods on scopes and bindings internal to the parser. @@ -74,7 +76,7 @@ public class ASTInternal { } } - public static String getDeclaredInSourceFileOnly(IBinding binding, boolean requireDefinition) { + public static String getDeclaredInSourceFileOnly(IBinding binding, boolean requireDefinition, PDOMBinding nonLocal) { IASTNode[] decls; IASTNode def; if (binding instanceof ICPPInternalBinding) { @@ -109,6 +111,13 @@ public class ASTInternal { } } } + if (requireDefinition && nonLocal != null) { + try { + if (nonLocal.hasDeclaration()) + return null; + } catch (CoreException e) { + } + } return filePath; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTTranslationUnit.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTTranslationUnit.java index 1f4629147bf..643d223fa9f 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTTranslationUnit.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTTranslationUnit.java @@ -20,8 +20,10 @@ import org.eclipse.cdt.core.dom.ast.IASTDeclaration; import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IBinding; +import org.eclipse.cdt.core.dom.ast.ICompositeType; import org.eclipse.cdt.core.dom.ast.IMacroBinding; import org.eclipse.cdt.core.dom.ast.IScope; +import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.parser.ParserLanguage; import org.eclipse.cdt.core.parser.util.ArrayUtil; import org.eclipse.cdt.internal.core.dom.Linkage; @@ -33,7 +35,11 @@ import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent; */ public class CASTTranslationUnit extends ASTTranslationUnit implements IASTAmbiguityParent { private CScope compilationUnit = null; + private CStructMapper fStructMapper; + public CASTTranslationUnit() { + fStructMapper= new CStructMapper(this); + } public CASTTranslationUnit copy() { CASTTranslationUnit copy = new CASTTranslationUnit(); @@ -109,4 +115,11 @@ public class CASTTranslationUnit extends ASTTranslationUnit implements IASTAmbig } } } + + /** + * Maps structs from the index into this AST. + */ + public IType mapToASTType(ICompositeType type) { + return fStructMapper.mapToAST(type); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CStructMapper.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CStructMapper.java new file mode 100644 index 00000000000..66cfa88a90f --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CStructMapper.java @@ -0,0 +1,76 @@ +/******************************************************************************* + * Copyright (c) 2009 Wind River Systems, Inc. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Markus Schorn - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.internal.core.dom.parser.c; + +import org.eclipse.cdt.core.dom.ast.ASTVisitor; +import org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier; +import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier; +import org.eclipse.cdt.core.dom.ast.IASTDeclaration; +import org.eclipse.cdt.core.dom.ast.IASTName; +import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration; +import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; +import org.eclipse.cdt.core.dom.ast.IBinding; +import org.eclipse.cdt.core.dom.ast.ICompositeType; +import org.eclipse.cdt.core.dom.ast.IType; +import org.eclipse.cdt.core.parser.util.CharArrayMap; + +/** + * Utility to map index bindings to ast bindings. + */ +public class CStructMapper { + private class Visitor extends ASTVisitor { + Visitor() { + shouldVisitDeclarations= true; + } + + @Override + public int visit(IASTDeclaration declaration) { + if (declaration instanceof IASTSimpleDeclaration) { + IASTDeclSpecifier declspec = ((IASTSimpleDeclaration) declaration).getDeclSpecifier(); + if (declspec instanceof IASTCompositeTypeSpecifier) { + IASTCompositeTypeSpecifier cts= (IASTCompositeTypeSpecifier) declspec; + final IASTName name = cts.getName(); + final char[] nameChars = name.toCharArray(); + if (nameChars.length > 0) { + fStructs.put(nameChars, name); + } + return PROCESS_CONTINUE; + } + } + return PROCESS_SKIP; + } + } + + private final IASTTranslationUnit fTranslationUnit; + protected CharArrayMap fStructs; + + public CStructMapper(IASTTranslationUnit tu) { + fTranslationUnit= tu; + } + + public IType mapToAST(ICompositeType type) { + if (fStructs == null) { + fStructs= new CharArrayMap(); + fTranslationUnit.accept(new Visitor()); + } + IASTName name= fStructs.get(type.getNameCharArray()); + if (name != null) { + IBinding b= name.resolveBinding(); + if (b instanceof ICompositeType) { + final ICompositeType mapped = (ICompositeType) b; + if (mapped.isSameType(type)) { + return mapped; + } + } + } + return type; + } +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVisitor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVisitor.java index cdf64496a39..e05a2074d32 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVisitor.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVisitor.java @@ -610,6 +610,9 @@ public class CVisitor extends ASTQueries { } if (type != null && type instanceof ICompositeType) { + if (type instanceof IIndexBinding) { + type= ((CASTTranslationUnit) fieldReference.getTranslationUnit()).mapToASTType((ICompositeType) type); + } if (prefix) { IBinding[] result = null; try { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCastExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCastExpression.java index ad49d8fe8e5..ae24b723bc2 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCastExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCastExpression.java @@ -1,12 +1,13 @@ /******************************************************************************* - * Copyright (c) 2004, 2008 IBM Corporation and others. + * Copyright (c) 2004, 2009 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * IBM - Initial API and implementation + * John Camelon (IBM) - Initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; @@ -19,7 +20,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCastExpression; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor; /** - * @author jcamelon + * Cast expression for c++ */ public class CPPASTCastExpression extends CPPASTUnaryExpression implements ICPPASTCastExpression { @@ -97,6 +98,6 @@ public class CPPASTCastExpression extends CPPASTUnaryExpression implements ICPPA @Override public IType getExpressionType() { - return CPPVisitor.createType(typeId.getDeclSpecifier(), typeId.getAbstractDeclarator()); + return CPPVisitor.createType(typeId.getAbstractDeclarator()); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTranslationUnit.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTranslationUnit.java index 2f5ecb9ed1c..2115dd57c9e 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTranslationUnit.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTranslationUnit.java @@ -25,6 +25,7 @@ import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTranslationUnit; import org.eclipse.cdt.core.dom.ast.cpp.ICPPBasicType; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace; import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceScope; @@ -184,6 +185,10 @@ public class CPPASTTranslationUnit extends ASTTranslationUnit implements ICPPAST public IScope mapToASTScope(IIndexScope scope) { return fScopeMapper.mapToASTScope(scope); } + // bug 262719: class types from the index have to be mapped back to the AST. + public ICPPClassType mapToAST(ICPPClassType binding) { + return fScopeMapper.mapToAST(binding); + } /** * Stores directives from the index into this scope. diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTypeIdInitializerExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTypeIdInitializerExpression.java index ab618f97efb..a40db14f41c 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTypeIdInitializerExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTypeIdInitializerExpression.java @@ -37,6 +37,6 @@ public class CPPASTTypeIdInitializerExpression extends ASTTypeIdInitializerExpre public IType getExpressionType() { final IASTTypeId typeId = getTypeId(); - return CPPVisitor.createType(typeId.getDeclSpecifier(), typeId.getAbstractDeclarator()); + return CPPVisitor.createType(typeId.getAbstractDeclarator()); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPImplicitMethod.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPImplicitMethod.java index 3a3e753a8cb..64fb88e77ff 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPImplicitMethod.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPImplicitMethod.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2008 IBM Corporation and others. + * Copyright (c) 2004, 2009 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -17,6 +17,7 @@ import org.eclipse.cdt.core.dom.ast.IASTDeclaration; import org.eclipse.cdt.core.dom.ast.IASTDeclarator; import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition; import org.eclipse.cdt.core.dom.ast.IASTName; +import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration; import org.eclipse.cdt.core.dom.ast.IBasicType; import org.eclipse.cdt.core.dom.ast.IBinding; @@ -33,6 +34,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod; 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.ASTQueries; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor; /** @@ -45,26 +47,33 @@ public class CPPImplicitMethod extends CPPImplicitFunction implements ICPPMethod } public int getVisibility() throws DOMException { - IASTDeclaration decl = getPrimaryDeclaration(); - if( decl == null ) { - //12.1-5, 12.8-10 Implicitl constructors and assignment operators are public - return ICPPASTVisibilityLabel.v_public; - } + IASTDeclaration decl= getPrimaryDeclaration(); + if (decl == null) { + // 12.1-5, 12.8-10 Implicit constructors and assignment operators are public + return ICPPASTVisibilityLabel.v_public; + } - IASTCompositeTypeSpecifier cls = (IASTCompositeTypeSpecifier) decl.getParent(); - IASTDeclaration [] members = cls.getMembers(); - ICPPASTVisibilityLabel vis = null; - for (IASTDeclaration member : members) { - if( member instanceof ICPPASTVisibilityLabel ) - vis = (ICPPASTVisibilityLabel) member; - else if( member == decl ) - break; - } - if( vis != null ){ - return vis.getVisibility(); - } else if( cls.getKey() == ICPPASTCompositeTypeSpecifier.k_class ){ - return ICPPASTVisibilityLabel.v_private; - } + IASTNode parent= decl.getParent(); + while (parent instanceof ICPPASTTemplateDeclaration) { + decl= (ICPPASTTemplateDeclaration) parent; + parent= parent.getParent(); + } + if (parent instanceof IASTCompositeTypeSpecifier) { + IASTCompositeTypeSpecifier cls = (IASTCompositeTypeSpecifier) decl.getParent(); + IASTDeclaration [] members = cls.getMembers(); + ICPPASTVisibilityLabel vis = null; + for (IASTDeclaration member : members) { + if( member instanceof ICPPASTVisibilityLabel ) + vis = (ICPPASTVisibilityLabel) member; + else if( member == decl ) + break; + } + if( vis != null ){ + return vis.getVisibility(); + } else if( cls.getKey() == ICPPASTCompositeTypeSpecifier.k_class ){ + return ICPPASTVisibilityLabel.v_private; + } + } return ICPPASTVisibilityLabel.v_public; } @@ -73,80 +82,78 @@ public class CPPImplicitMethod extends CPPImplicitFunction implements ICPPMethod return scope.getClassType(); } - public IASTDeclaration getPrimaryDeclaration() throws DOMException{ - //first check if we already know it - if( declarations != null ){ + public IASTDeclaration getPrimaryDeclaration() throws DOMException { + // first check if we already know it + if (declarations != null) { for (ICPPASTFunctionDeclarator dtor : declarations) { - if (dtor == null) + if (dtor == null) break; - - IASTDeclaration decl= (IASTDeclaration) CPPVisitor.findOutermostDeclarator(dtor).getParent(); - if( decl.getParent() instanceof ICPPASTCompositeTypeSpecifier ) + + IASTDeclaration decl = (IASTDeclaration) ASTQueries.findOutermostDeclarator(dtor).getParent(); + IASTNode parent= decl.getParent(); + while (parent instanceof ICPPASTTemplateDeclaration) + parent= parent.getParent(); + if (parent instanceof ICPPASTCompositeTypeSpecifier) return decl; } } - + IFunctionType ftype = getType(); - IType [] params = ftype.getParameterTypes(); - - ICPPASTCompositeTypeSpecifier compSpec = (ICPPASTCompositeTypeSpecifier) ASTInternal.getPhysicalNodeOfScope(getScope()); + IType[] params = ftype.getParameterTypes(); + + ICPPASTCompositeTypeSpecifier compSpec = (ICPPASTCompositeTypeSpecifier) ASTInternal + .getPhysicalNodeOfScope(getScope()); if (compSpec == null) { - return null; + return null; } - IASTDeclaration [] members = compSpec.getMembers(); + IASTDeclaration[] members = compSpec.getMembers(); for (IASTDeclaration member : members) { - IASTDeclarator dtor = null; - IASTDeclarator [] ds = null; - int di = -1; + IASTDeclarator[] ds = null; + while (member instanceof ICPPASTTemplateDeclaration) + member = ((ICPPASTTemplateDeclaration) member).getDeclaration(); - if( member instanceof ICPPASTTemplateDeclaration ) - member = ((ICPPASTTemplateDeclaration) member).getDeclaration(); - if( member instanceof IASTSimpleDeclaration ){ - ds = ((IASTSimpleDeclaration)member).getDeclarators(); - } else if( member instanceof IASTFunctionDefinition ){ - dtor = ((IASTFunctionDefinition) member).getDeclarator(); + if (member instanceof IASTSimpleDeclaration) { + ds = ((IASTSimpleDeclaration) member).getDeclarators(); + } else if (member instanceof IASTFunctionDefinition) { + ds = new IASTDeclarator[] {((IASTFunctionDefinition) member).getDeclarator()}; + } else { + continue; } - if( ds != null && ds.length > 0 ){ - di = 0; - dtor = ds[0]; - while( dtor != null ){ - IASTName name = CPPVisitor.findInnermostDeclarator(dtor).getName(); - if( CPPVisitor.findTypeRelevantDeclarator(dtor) instanceof ICPPASTFunctionDeclarator && - CharArrayUtils.equals( name.getLookupKey(), getNameCharArray() ) ) - { - IType t0= CPPVisitor.createType( dtor ); - boolean ok= false; - if (t0 instanceof IFunctionType) { - IFunctionType t = (IFunctionType) t0; - IType [] ps = t.getParameterTypes(); - if( ps.length == params.length ){ - int idx = 0; - for( ; idx < ps.length && ps[idx] != null; idx++ ){ - if( !ps[idx].isSameType(params[idx]) ) - break; - } - ok= idx == ps.length; + + for (IASTDeclarator dtor : ds) { + IASTName name = ASTQueries.findInnermostDeclarator(dtor).getName(); + if (ASTQueries.findTypeRelevantDeclarator(dtor) instanceof ICPPASTFunctionDeclarator + && CharArrayUtils.equals(name.getLookupKey(), getNameCharArray())) { + IType t0 = CPPVisitor.createType(dtor); + boolean ok = false; + if (t0 instanceof IFunctionType) { + IFunctionType t = (IFunctionType) t0; + IType[] ps = t.getParameterTypes(); + if (ps.length == params.length) { + int idx = 0; + for (; idx < ps.length && ps[idx] != null; idx++) { + if (!ps[idx].isSameType(params[idx])) + break; } - else if (ps.length == 0) { - if (params.length == 1) { - IType t1= params[0]; - ok = (t1 instanceof IBasicType) && ((IBasicType) t1).getType() == IBasicType.t_void; - } + ok = idx == ps.length; + } else if (ps.length == 0) { + if (params.length == 1) { + IType t1 = params[0]; + ok = (t1 instanceof IBasicType) + && ((IBasicType) t1).getType() == IBasicType.t_void; } } - else { - ok= false; - } - if (ok) { - name.setBinding( this ); - if( member instanceof IASTSimpleDeclaration ) - addDeclaration( dtor ); - else if( member instanceof IASTFunctionDefinition ) - addDefinition( dtor ); - return member; - } + } else { + ok = false; + } + if (ok) { + name.setBinding(this); + if (member instanceof IASTSimpleDeclaration) + addDeclaration(dtor); + else if (member instanceof IASTFunctionDefinition) + addDefinition(dtor); + return member; } - dtor = ( di > -1 && ++ di < ds.length ) ? ds[di] : null; } } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPScope.java index ce7dce41f42..fa826455c59 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPScope.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPScope.java @@ -91,6 +91,8 @@ abstract public class CPPScope implements ICPPScope, ICPPASTInternalScope { return; } final char[] c= name.getLookupKey(); + if (c.length == 0) + return; Object o = bindings.get(c); if (o != null) { if (o instanceof ObjectSet) { @@ -304,6 +306,9 @@ abstract public class CPPScope implements ICPPScope, ICPPASTInternalScope { if (bindings == null) bindings = new CharArrayObjectMap(1); char[] c = binding.getNameCharArray(); + if (c.length == 0) { + return; + } Object o = bindings.get(c); if (o != null) { if (o instanceof ObjectSet) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPScopeMapper.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPScopeMapper.java index 2ecf65334c9..02c3d8d4ab7 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPScopeMapper.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPScopeMapper.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008 Wind River Systems, Inc. and others. + * Copyright (c) 2008, 2009 Wind River Systems, Inc. and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -17,16 +17,26 @@ import java.util.List; import java.util.Map; import org.eclipse.cdt.core.dom.IName; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.EScopeKind; +import org.eclipse.cdt.core.dom.ast.IASTASMDeclaration; +import org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier; +import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier; +import org.eclipse.cdt.core.dom.ast.IASTDeclaration; +import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition; import org.eclipse.cdt.core.dom.ast.IASTName; +import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration; import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IScope; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace; import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceScope; import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDirective; import org.eclipse.cdt.core.index.IIndexBinding; import org.eclipse.cdt.core.index.IIndexFileSet; +import org.eclipse.cdt.core.parser.util.ArrayUtil; +import org.eclipse.cdt.core.parser.util.CharArrayMap; import org.eclipse.cdt.internal.core.index.IIndexScope; /** @@ -119,13 +129,44 @@ public class CPPScopeMapper { return fOffset; } } - + /** + * Collector for class definitions. + */ + private class Visitor extends ASTVisitor { + Visitor() { + shouldVisitDeclarations = true; + } + + @Override + public int visit(IASTDeclaration declaration) { + if (declaration instanceof IASTSimpleDeclaration) { + IASTDeclSpecifier declspec = ((IASTSimpleDeclaration) declaration).getDeclSpecifier(); + if (declspec instanceof IASTCompositeTypeSpecifier) { + IASTCompositeTypeSpecifier cts = (IASTCompositeTypeSpecifier) declspec; + final IASTName name = cts.getName(); + final char[] nameChars = name.toCharArray(); + if (nameChars.length > 0) { + IASTName[] names= fClasses.get(nameChars); + names= (IASTName[]) ArrayUtil.append(IASTName.class, names, name); + fClasses.put(nameChars, names); + } + return PROCESS_CONTINUE; + } + return PROCESS_SKIP; + } else if (declaration instanceof IASTASMDeclaration + || declaration instanceof IASTFunctionDefinition) { + return PROCESS_SKIP; + } + return PROCESS_CONTINUE; + } + } private final HashMap fMappedScopes= new HashMap(); private final HashMap fNamespaceWrappers= new HashMap(); private final Map> fPerName= new HashMap>(); private final CPPASTTranslationUnit fTu; + protected CharArrayMap fClasses; public CPPScopeMapper(CPPASTTranslationUnit tu) { @@ -242,4 +283,26 @@ public class CPPScopeMapper { } return scope; } + + public ICPPClassType mapToAST(ICPPClassType type) { + if (fClasses == null) { + fClasses= new CharArrayMap(); + fTu.accept(new Visitor()); + } + IASTName[] names= fClasses.get(type.getNameCharArray()); + if (names != null) { + for (IASTName name : names) { + if (name == null) + break; + IBinding b= name.resolveBinding(); + if (b instanceof ICPPClassType) { + final ICPPClassType mapped = (ICPPClassType) b; + if (mapped.isSameType(type)) { + return mapped; + } + } + } + } + return type; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java index ac2576bac74..2ed05aa2bdc 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java @@ -2102,6 +2102,9 @@ public class CPPSemantics { sourceExp, source, target, isImpliedObject); } + if (cost.rank < 0) + continue function_loop; + currFnCost[j] = cost; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java index df539d8e14a..2ce86c60249 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java @@ -136,6 +136,7 @@ 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.ASTQueries; import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding; +import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTTranslationUnit; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPArrayType; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPBasicType; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPClassTemplate; @@ -353,6 +354,12 @@ public class CPPVisitor extends ASTQueries { parent instanceof IASTTypeId) { binding = CPPSemantics.resolveBinding(elabType.getName()); } + if (binding instanceof IIndexBinding && binding instanceof ICPPClassType) { + binding= ((CPPASTTranslationUnit) elabType.getTranslationUnit()).mapToAST((ICPPClassType) binding); + if (binding instanceof ICPPInternalBinding) { + ((ICPPInternalBinding) binding).addDeclaration(elabType); + } + } if (binding != null && (!(binding instanceof IProblemBinding) || @@ -543,8 +550,34 @@ public class CPPVisitor extends ASTQueries { return b; } + // parameter declarations + if (parent instanceof ICPPASTParameterDeclaration) { + ICPPASTParameterDeclaration param = (ICPPASTParameterDeclaration) parent; + parent = param.getParent(); + if (parent instanceof IASTStandardFunctionDeclarator) { + IASTStandardFunctionDeclarator fdtor = (IASTStandardFunctionDeclarator) param.getParent(); + // if the fdtor does not declare a function we don't create a binding for the parameter. + if (!(findOutermostDeclarator(fdtor).getParent() instanceof IASTDeclaration) || + findTypeRelevantDeclarator(fdtor) != fdtor) + return null; + IBinding temp = findInnermostDeclarator(fdtor).getName().resolveBinding(); + if (temp instanceof ICPPInternalFunction) { + return ((ICPPInternalFunction) temp).resolveParameter(param); + } else if (temp instanceof IProblemBinding) { + //problems with the function, still create binding for the parameter + return new CPPParameter(name); + } else if (temp instanceof IIndexBinding) { + return new CPPParameter(name); + } + return null; + } else if (parent instanceof ICPPASTTemplateDeclaration) { + return CPPTemplates.createBinding(param); + } + return new ProblemBinding(name, IProblemBinding.SEMANTIC_INVALID_TYPE); + } + // function declaration/definition - IBinding binding; + IBinding binding= null; final boolean template= tmplDecl != null; boolean isFriendDecl= false; ICPPScope scope = (ICPPScope) getContainingScope((IASTNode) name); @@ -565,7 +598,9 @@ public class CPPVisitor extends ASTQueries { } } boolean forceResolve= isFriendDecl && name instanceof ICPPASTTemplateId; - binding = (scope != null) ? scope.getBinding(name, forceResolve) : null; + if (name.getLookupKey().length != 0 && scope != null) { + binding = scope.getBinding(name, forceResolve); + } } catch (DOMException e) { return e.getProblem(); } @@ -649,7 +684,7 @@ public class CPPVisitor extends ASTQueries { binding = template ? (ICPPFunction) new CPPFunctionTemplate(name) : new CPPFunction((ICPPASTFunctionDeclarator) funcDeclarator); } - } else if (parent instanceof IASTSimpleDeclaration) { + } else if (simpleDecl != null) { IType t1 = null, t2 = null; if (binding != null && binding instanceof IVariable && !(binding instanceof IIndexBinding)) { t1 = createType(declarator); @@ -665,7 +700,7 @@ public class CPPVisitor extends ASTQueries { } else { binding = new ProblemBinding(name, IProblemBinding.SEMANTIC_INVALID_REDECLARATION); } - } else if (simpleDecl != null && simpleDecl.getParent() instanceof ICPPASTCompositeTypeSpecifier) { + } else if (simpleDecl.getParent() instanceof ICPPASTCompositeTypeSpecifier) { binding = new CPPField(name); } else { binding = new CPPVariable(name); @@ -935,6 +970,9 @@ public class CPPVisitor extends ASTQueries { type= getUltimateTypeUptoPointers(type); } if (type instanceof ICPPClassType) { + if (type instanceof IIndexBinding) { + type= (((CPPASTTranslationUnit) fieldReference.getTranslationUnit())).mapToAST((ICPPClassType) type); + } return ((ICPPClassType) type).getCompositeScope(); } else if (type instanceof ICPPUnknownBinding) { return ((ICPPUnknownBinding) type).asScope(); @@ -1760,11 +1798,6 @@ public class CPPVisitor extends ASTQueries { return basicType; } - public static IType createType(final IASTDeclSpecifier declSpecifier, final IASTDeclarator dtor) { - IType type = createType(declSpecifier); - return createType(type, dtor); - } - public static IType get_type_info(IASTExpression expression) { try { IBinding[] std= expression.getTranslationUnit().getScope().find(STD); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMLinkage.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMLinkage.java index f2fea7cf248..a19690844a6 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMLinkage.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMLinkage.java @@ -1,12 +1,12 @@ /******************************************************************************* - * Copyright (c) 2005, 2008 QNX Software Systems and others. + * Copyright (c) 2005, 2009 QNX Software Systems and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * QNX - Initial API and implementation + * Doug Schaefer (QNX) - Initial API and implementation * Markus Schorn (Wind River Systems) * IBM Corporation * Andrew Ferguson (Symbian) @@ -45,8 +45,6 @@ import org.eclipse.cdt.internal.core.pdom.db.IString; import org.eclipse.core.runtime.CoreException; /** - * @author Doug Schaefer - * * This class represents a collection of symbols that can be linked together at * link time. These are generally global symbols specific to a given language. */ @@ -61,6 +59,7 @@ public abstract class PDOMLinkage extends PDOMNamedNode implements IIndexLinkage @SuppressWarnings("hiding") protected static final int RECORD_SIZE = PDOMNamedNode.RECORD_SIZE + 20; + protected static final int[] FILE_LOCAL_REC_DUMMY = new int[]{0}; // node types protected static final int LINKAGE= 0; // special one for myself @@ -204,13 +203,13 @@ public abstract class PDOMLinkage extends PDOMNamedNode implements IIndexLinkage public abstract PDOMBinding adaptBinding(IBinding binding) throws CoreException; public abstract PDOMBinding addBinding(IASTName name) throws CoreException; - final protected int getLocalToFileRec(PDOMNode parent, IBinding binding) throws CoreException { + final protected int getLocalToFileRec(PDOMNode parent, IBinding binding, PDOMBinding glob) throws CoreException { int rec= 0; if (parent instanceof PDOMBinding) { rec= ((PDOMBinding) parent).getLocalToFileRec(); } if (rec == 0) { - PDOMFile file= getLocalToFile(binding); + PDOMFile file= getLocalToFile(binding, glob); if (file != null) { rec= file.getRecord(); } @@ -218,29 +217,29 @@ public abstract class PDOMLinkage extends PDOMNamedNode implements IIndexLinkage return rec; } - protected PDOMFile getLocalToFile(IBinding binding) throws CoreException { + protected PDOMFile getLocalToFile(IBinding binding, PDOMBinding glob) throws CoreException { if (pdom instanceof WritablePDOM) { final WritablePDOM wpdom= (WritablePDOM) pdom; try { if (binding instanceof IField) { return null; } - boolean checkInSourceOnly= false; + boolean checkIfInSourceOnly= false; boolean requireDefinition= false; if (binding instanceof IVariable) { if (!(binding instanceof IField)) { - checkInSourceOnly= ((IVariable) binding).isStatic(); + checkIfInSourceOnly= ((IVariable) binding).isStatic(); } } else if (binding instanceof IFunction) { IFunction f= (IFunction) binding; - checkInSourceOnly= ASTInternal.isStatic(f, false); + checkIfInSourceOnly= ASTInternal.isStatic(f, false); } else if (binding instanceof ITypedef || binding instanceof ICompositeType || binding instanceof IEnumeration) { - checkInSourceOnly= true; + checkIfInSourceOnly= true; requireDefinition= true; } - if (checkInSourceOnly) { - String path= ASTInternal.getDeclaredInSourceFileOnly(binding, requireDefinition); + if (checkIfInSourceOnly) { + String path= ASTInternal.getDeclaredInSourceFileOnly(binding, requireDefinition, glob); if (path != null) { return wpdom.getFileForASTPath(getLinkageID(), path); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCLinkage.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCLinkage.java index ee2c1fb972c..9dcfa95cca2 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCLinkage.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCLinkage.java @@ -1,12 +1,12 @@ /******************************************************************************* - * Copyright (c) 2006, 2008 QNX Software Systems and others. + * Copyright (c) 2006, 2009 QNX Software Systems and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * QNX - Initial API and implementation + * Doug Schaefer (QNX) - Initial API and implementation * Markus Schorn (Wind River Systems) * IBM Corporation * Andrew Ferguson (Symbian) @@ -43,7 +43,7 @@ import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode; import org.eclipse.core.runtime.CoreException; /** - * @author Doug Schaefer + * Container for c bindings */ class PDOMCLinkage extends PDOMLinkage implements IIndexCBindingConstants { @@ -85,9 +85,10 @@ class PDOMCLinkage extends PDOMLinkage implements IIndexCBindingConstants { if (parent == null) return null; - pdomBinding = adaptBinding(parent, binding); + int[] localToFileHolder= {0}; + pdomBinding = adaptBinding(parent, binding, localToFileHolder); if (pdomBinding == null) { - pdomBinding = createBinding(parent, binding); + pdomBinding = createBinding(parent, binding, localToFileHolder[0]); if (pdomBinding != null) { pdom.putCachedResult(inputBinding, pdomBinding); } @@ -103,9 +104,8 @@ class PDOMCLinkage extends PDOMLinkage implements IIndexCBindingConstants { return pdomBinding; } - private PDOMBinding createBinding(PDOMNode parent, IBinding binding) throws CoreException { + private PDOMBinding createBinding(PDOMNode parent, IBinding binding, int localToFile) throws CoreException { PDOMBinding pdomBinding= null; - PDOMNode inheritFileLocal= parent; if (binding instanceof IField) { // must be before IVariable if (parent instanceof IPDOMMemberOwner) @@ -125,7 +125,6 @@ class PDOMCLinkage extends PDOMLinkage implements IIndexCBindingConstants { IType enumeration= ((IEnumerator)binding).getType(); if (enumeration instanceof IEnumeration) { PDOMBinding pdomEnumeration = adaptBinding((IEnumeration) enumeration); - inheritFileLocal= pdomEnumeration; if (pdomEnumeration instanceof PDOMCEnumeration) pdomBinding = new PDOMCEnumerator(pdom, parent, (IEnumerator) binding, (PDOMCEnumeration)pdomEnumeration); } @@ -137,7 +136,7 @@ class PDOMCLinkage extends PDOMLinkage implements IIndexCBindingConstants { } if (pdomBinding != null) { - pdomBinding.setLocalToFileRec(getLocalToFileRec(inheritFileLocal, binding)); + pdomBinding.setLocalToFileRec(localToFile); parent.addChild(pdomBinding); afterAddBinding(pdomBinding); } @@ -228,10 +227,10 @@ class PDOMCLinkage extends PDOMLinkage implements IIndexCBindingConstants { @Override public final PDOMBinding adaptBinding(final IBinding inputBinding) throws CoreException { - return adaptBinding(null, inputBinding); + return adaptBinding(null, inputBinding, FILE_LOCAL_REC_DUMMY); } - private final PDOMBinding adaptBinding(final PDOMNode parent, IBinding inputBinding) throws CoreException { + private final PDOMBinding adaptBinding(final PDOMNode parent, IBinding inputBinding, int[] localToFileHolder) throws CoreException { if (inputBinding instanceof CompositeIndexBinding) { inputBinding= ((CompositeIndexBinding) inputBinding).getRawBinding(); } @@ -250,14 +249,14 @@ class PDOMCLinkage extends PDOMLinkage implements IIndexCBindingConstants { return null; } - result= doAdaptBinding(parent, binding); + result= doAdaptBinding(parent, binding, localToFileHolder); if (result != null) { pdom.putCachedResult(inputBinding, result); } return result; } - private final PDOMBinding doAdaptBinding(PDOMNode parent, final IBinding binding) throws CoreException { + private final PDOMBinding doAdaptBinding(PDOMNode parent, final IBinding binding, int[] localToFileHolder) throws CoreException { if (parent == null) { parent= getAdaptedParent(binding); } @@ -274,12 +273,24 @@ class PDOMCLinkage extends PDOMLinkage implements IIndexCBindingConstants { } if (parent == this) { - int localToFileRec= getLocalToFileRec(inheritFileLocal, binding); - return FindBinding.findBinding(getIndex(), getPDOM(), binding.getNameCharArray(), new int[] {getBindingType(binding)}, localToFileRec); + final int[] bindingTypes = new int[] {getBindingType(binding)}; + final char[] nameChars = binding.getNameCharArray(); + PDOMBinding nonLocal= FindBinding.findBinding(getIndex(), getPDOM(), nameChars, bindingTypes, 0); + int localToFileRec= getLocalToFileRec(inheritFileLocal, binding, nonLocal); + if (localToFileRec == 0) + return nonLocal; + localToFileHolder[0]= localToFileRec; + return FindBinding.findBinding(getIndex(), getPDOM(), nameChars, bindingTypes, localToFileRec); } if (parent instanceof IPDOMMemberOwner) { - int localToFileRec= getLocalToFileRec(inheritFileLocal, binding); - return FindBinding.findBinding(parent, getPDOM(), binding.getNameCharArray(), new int[] {getBindingType(binding)}, localToFileRec); + final int[] bindingTypes = new int[] {getBindingType(binding)}; + final char[] nameChars = binding.getNameCharArray(); + PDOMBinding nonLocal= FindBinding.findBinding(parent, getPDOM(), nameChars, bindingTypes, 0); + int localToFileRec= getLocalToFileRec(inheritFileLocal, binding, nonLocal); + if (localToFileRec == 0) + return nonLocal; + localToFileHolder[0]= localToFileRec; + return FindBinding.findBinding(parent, getPDOM(), nameChars, bindingTypes, localToFileRec); } return null; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPLinkage.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPLinkage.java index 7311e8afdc6..f5de191ad3c 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPLinkage.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPLinkage.java @@ -76,6 +76,7 @@ import org.eclipse.cdt.internal.core.index.IIndexCPPBindingConstants; import org.eclipse.cdt.internal.core.index.composite.CompositeIndexBinding; import org.eclipse.cdt.internal.core.pdom.PDOM; import org.eclipse.cdt.internal.core.pdom.WritablePDOM; +import org.eclipse.cdt.internal.core.pdom.db.BTree; import org.eclipse.cdt.internal.core.pdom.db.IBTreeComparator; import org.eclipse.cdt.internal.core.pdom.dom.IPDOMMemberOwner; import org.eclipse.cdt.internal.core.pdom.dom.PDOMASTAdapter; @@ -246,12 +247,13 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants { if (parent == null) return null; - pdomBinding = adaptBinding(parent, binding); + int fileLocalRec[]= {0}; + pdomBinding = adaptBinding(parent, binding, fileLocalRec); if (pdomBinding != null) { pdom.putCachedResult(inputBinding, pdomBinding); } else { try { - pdomBinding = createBinding(parent, binding); + pdomBinding = createBinding(parent, binding, fileLocalRec[0]); if (pdomBinding != null) { pdom.putCachedResult(inputBinding, pdomBinding); } @@ -293,9 +295,8 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants { return false; } - PDOMBinding createBinding(PDOMNode parent, IBinding binding) throws CoreException, DOMException { + PDOMBinding createBinding(PDOMNode parent, IBinding binding, int fileLocalRec) throws CoreException, DOMException { PDOMBinding pdomBinding= null; - PDOMNode inheritFileLocal = parent; // template parameters are created directly by their owners. if (binding instanceof ICPPTemplateParameter) @@ -358,7 +359,6 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants { PDOMBinding pdomEnumeration = adaptBinding((IEnumeration) enumeration); if (pdomEnumeration instanceof PDOMCPPEnumeration) { pdomBinding = new PDOMCPPEnumerator(pdom, parent, etor, (PDOMCPPEnumeration)pdomEnumeration); - inheritFileLocal= pdomEnumeration; } } } else if (binding instanceof ITypedef) { @@ -366,7 +366,7 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants { } if (pdomBinding != null) { - pdomBinding.setLocalToFileRec(getLocalToFileRec(inheritFileLocal, binding)); + pdomBinding.setLocalToFileRec(fileLocalRec); parent.addChild(pdomBinding); afterAddBinding(pdomBinding); } @@ -426,6 +426,7 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants { private void addImplicitMethods(PDOMBinding type, ICPPClassType binding) throws CoreException { try { + final int fileLocalRec= type.getLocalToFileRec(); IScope scope = binding.getCompositeScope(); if (scope instanceof ICPPClassScope) { ICPPMethod[] implicit= ((ICPPClassScope) scope).getImplicitMethods(); @@ -433,7 +434,7 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants { if (!(method instanceof IProblemBinding)) { PDOMBinding pdomBinding= adaptBinding(method); if (pdomBinding == null) { - createBinding(type, method); + createBinding(type, method, fileLocalRec); } else if (!pdomBinding.hasDefinition()) { pdomBinding.update(this, method); } @@ -550,10 +551,10 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants { @Override public final PDOMBinding adaptBinding(final IBinding inputBinding) throws CoreException { - return adaptBinding(null, inputBinding); + return adaptBinding(null, inputBinding, FILE_LOCAL_REC_DUMMY); } - private final PDOMBinding adaptBinding(final PDOMNode parent, IBinding inputBinding) throws CoreException { + private final PDOMBinding adaptBinding(final PDOMNode parent, IBinding inputBinding, int[] fileLocalRecHolder) throws CoreException { if (cannotAdapt(inputBinding)) { return null; } @@ -569,7 +570,7 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants { return null; } - result= doAdaptBinding(parent, binding); + result= doAdaptBinding(parent, binding, fileLocalRecHolder); if (result != null) { pdom.putCachedResult(inputBinding, result); } @@ -579,7 +580,7 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants { /** * Find the equivalent binding, or binding place holder within this PDOM */ - private final PDOMBinding doAdaptBinding(PDOMNode parent, IBinding binding) throws CoreException { + private final PDOMBinding doAdaptBinding(PDOMNode parent, IBinding binding, int[] fileLocalRecHolder) throws CoreException { if (parent == null) { parent= adaptOrAddParent(false, binding); } @@ -596,21 +597,33 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants { } if (parent == this) { - int localToFileRec= getLocalToFileRec(inheritFileLocal, binding); - return CPPFindBinding.findBinding(getIndex(), this, binding, localToFileRec); + PDOMBinding glob= CPPFindBinding.findBinding(getIndex(), this, binding, 0); + final int loc= getLocalToFileRec(inheritFileLocal, binding, glob); + if (loc == 0) + return glob; + fileLocalRecHolder[0]= loc; + return CPPFindBinding.findBinding(getIndex(), this, binding, loc); } if (parent instanceof PDOMCPPNamespace) { - int localToFileRec= getLocalToFileRec(inheritFileLocal, binding); - return CPPFindBinding.findBinding(((PDOMCPPNamespace) parent).getIndex(), this, binding, - localToFileRec); + final BTree btree = ((PDOMCPPNamespace) parent).getIndex(); + PDOMBinding glob= CPPFindBinding.findBinding(btree, this, binding, 0); + final int loc= getLocalToFileRec(inheritFileLocal, binding, glob); + if (loc == 0) + return glob; + fileLocalRecHolder[0]= loc; + return CPPFindBinding.findBinding(btree, this, binding, loc); } if (binding instanceof ICPPTemplateParameter && parent instanceof IPDOMCPPTemplateParameterOwner) { return (PDOMBinding) ((IPDOMCPPTemplateParameterOwner) parent).adaptTemplateParameter( (ICPPTemplateParameter) binding); } if (parent instanceof IPDOMMemberOwner) { - int localToFileRec= getLocalToFileRec(inheritFileLocal, binding); - return CPPFindBinding.findBinding(parent, this, binding, localToFileRec); + PDOMBinding glob= CPPFindBinding.findBinding(parent, this, binding, 0); + final int loc= getLocalToFileRec(inheritFileLocal, binding, glob); + if (loc == 0) + return glob; + fileLocalRecHolder[0]= loc; + return CPPFindBinding.findBinding(parent, this, binding, loc); } return null; } @@ -957,7 +970,7 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants { } @Override - protected PDOMFile getLocalToFile(IBinding binding) throws CoreException { + protected PDOMFile getLocalToFile(IBinding binding, PDOMBinding glob) throws CoreException { if (pdom instanceof WritablePDOM) { final WritablePDOM wpdom= (WritablePDOM) pdom; PDOMFile file= null; @@ -967,7 +980,7 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants { file= wpdom.getFileForASTPath(getLinkageID(), path); } } else if (binding instanceof ICPPNamespaceAlias) { - String path= ASTInternal.getDeclaredInSourceFileOnly(binding, false); + String path= ASTInternal.getDeclaredInSourceFileOnly(binding, false, glob); if (path != null) { file= wpdom.getFileForASTPath(getLinkageID(), path); } @@ -977,7 +990,7 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants { IBinding owner= binding.getOwner(); if (owner instanceof ICPPNamespace) { if (owner.getNameCharArray().length == 0) { - String path= ASTInternal.getDeclaredInSourceFileOnly(owner, false); + String path= ASTInternal.getDeclaredInSourceFileOnly(owner, false, glob); if (path != null) { file= wpdom.getFileForASTPath(getLinkageID(), path); } @@ -993,6 +1006,6 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants { if (binding instanceof ICPPMember) { return null; } - return super.getLocalToFile(binding); + return super.getLocalToFile(binding, glob); } }