1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Fixes remaining recursions in name resolution, bug 252554.

This commit is contained in:
Markus Schorn 2008-11-11 12:00:32 +00:00
parent c656d4d2ee
commit 0700a8fe68
5 changed files with 51 additions and 30 deletions

View file

@ -56,7 +56,7 @@ public class BaseTestCase extends TestCase {
@Override
protected void setUp() throws Exception {
CPPASTNameBase.sAllowRecursionBindings= true;
CPPASTNameBase.sAllowRecursionBindings= false;
}
@Override

View file

@ -142,6 +142,7 @@ public abstract class CPPASTNameBase extends ASTNode implements IASTName {
}
fIsFinal= true;
fResolutionDepth= 0;
}
public void setBinding(IBinding binding) {

View file

@ -170,10 +170,18 @@ public class CPPClassScope extends CPPScope implements ICPPClassScope {
@Override
public void addName(IASTName name) throws DOMException {
if (name instanceof ICPPASTQualifiedName) {
IASTName ln= ((ICPPASTQualifiedName) name).getLastName();
if (CPPVisitor.getContainingScope(name) != CPPVisitor.getContainingScope(ln)) {
return;
// check whether the qualification matches
IBinding b= getClassType();
final ICPPASTQualifiedName qname = (ICPPASTQualifiedName) name;
final IASTName[] names= qname.getNames();
for (int i = names.length-2; i>=0; i--) {
if (b == null || !CharArrayUtils.equals(names[i].toCharArray(), b.getNameCharArray()))
return;
b= b.getOwner();
}
if (qname.isFullyQualified() && b != null)
return;
}
IASTNode parent = name.getParent();
if (parent instanceof IASTDeclarator) {

View file

@ -2566,10 +2566,14 @@ public class CPPSemantics {
}
public static IBinding[] findBindings(IScope scope, String name, boolean qualified) throws DOMException{
return findBindings(scope, name.toCharArray(), qualified);
return findBindings(scope, name.toCharArray(), qualified, null);
}
public static IBinding[] findBindings(IScope scope, char[] name, boolean qualified) throws DOMException{
public static IBinding[] findBindings(IScope scope, char[] name, boolean qualified) throws DOMException {
return findBindings(scope, name, qualified, null);
}
public static IBinding[] findBindings(IScope scope, char[] name, boolean qualified, IASTNode beforeNode) throws DOMException{
CPPASTName astName = new CPPASTName();
astName.setName(name);
astName.setParent(ASTInternal.getPhysicalNodeOfScope(scope));
@ -2577,7 +2581,7 @@ public class CPPSemantics {
LookupData data = new LookupData(astName);
data.forceQualified = qualified;
return standardLookup(data, scope);
return standardLookup(data, scope, beforeNode);
}
public static IBinding[] findBindingsForContentAssist(IASTName name, boolean prefixLookup) {
@ -2628,7 +2632,7 @@ public class CPPSemantics {
return (IBinding[]) ArrayUtil.trim(IBinding.class, result);
}
private static IBinding[] standardLookup(LookupData data, Object start) {
private static IBinding[] standardLookup(LookupData data, Object start, IASTNode beforeNode) {
try {
lookup(data, start);
} catch (DOMException e) {
@ -2639,26 +2643,34 @@ public class CPPSemantics {
if (items == null)
return new IBinding[0];
boolean indexBased= false;
if (beforeNode != null) {
IASTTranslationUnit tu= beforeNode.getTranslationUnit();
if (tu != null && tu.getIndex() != null)
indexBased= true;
}
ObjectSet<IBinding> set = new ObjectSet<IBinding>(items.length);
IBinding binding = null;
for (Object item : items) {
if (item instanceof IASTName) {
binding = ((IASTName) item).resolveBinding();
} else if (item instanceof IBinding) {
binding = (IBinding) item;
} else {
binding = null;
}
if (beforeNode == null || declaredBefore(item, beforeNode, indexBased)) {
if (item instanceof IASTName) {
binding = ((IASTName) item).resolveBinding();
} else if (item instanceof IBinding) {
binding = (IBinding) item;
} else {
binding = null;
}
if (binding != null) {
if (binding instanceof ICPPUsingDeclaration) {
set.addAll(((ICPPUsingDeclaration) binding).getDelegates());
} else if (binding instanceof CPPCompositeBinding) {
set.addAll(((CPPCompositeBinding) binding).getBindings());
} else {
set.put(binding);
}
}
if (binding != null) {
if (binding instanceof ICPPUsingDeclaration) {
set.addAll(((ICPPUsingDeclaration) binding).getDelegates());
} else if (binding instanceof CPPCompositeBinding) {
set.addAll(((CPPCompositeBinding) binding).getBindings());
} else {
set.put(binding);
}
}
}
}
return set.keyArray(IBinding.class);

View file

@ -185,8 +185,8 @@ import org.eclipse.cdt.internal.core.index.IIndexScope;
* @author aniefer
*/
public class CPPVisitor extends ASTQueries {
public static final String SIZE_T = "size_t"; //$NON-NLS-1$
public static final String PTRDIFF_T = "ptrdiff_t"; //$NON-NLS-1$
public static final char[] SIZE_T = "size_t".toCharArray(); //$NON-NLS-1$
public static final char[] PTRDIFF_T = "ptrdiff_t".toCharArray(); //$NON-NLS-1$
public static final String STD = "std"; //$NON-NLS-1$
public static final String TYPE_INFO= "type_info"; //$NON-NLS-1$
@ -1895,7 +1895,7 @@ public class CPPVisitor extends ASTQueries {
if (SemanticUtil.getUltimateTypeViaTypedefs(t1) instanceof IPointerType) {
IScope scope = getContainingScope(expression);
try {
IBinding[] bs = scope.find(PTRDIFF_T);
IBinding[] bs= CPPSemantics.findBindings(scope, PTRDIFF_T, false, expression);
if (bs.length > 0) {
for (IBinding b : bs) {
if (b instanceof IType && CPPSemantics.declaredBefore(b, binary, false)) {
@ -2089,7 +2089,7 @@ public class CPPVisitor extends ASTQueries {
private static IType get_SIZE_T(IASTNode sizeofExpr) {
IScope scope = getContainingScope(sizeofExpr);
try {
IBinding[] bs = scope.find(SIZE_T);
IBinding[] bs = CPPSemantics.findBindings(scope, SIZE_T, false, sizeofExpr);
if (bs.length > 0 && bs[0] instanceof IType) {
return (IType) bs[0];
}