1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-01 06:05:24 +02:00

Bug 300019: Using declaration targeting more than two declarations

This commit is contained in:
Markus Schorn 2010-02-01 16:20:25 +00:00
parent c5c2bf67b8
commit 85b56d1d8a
3 changed files with 57 additions and 22 deletions

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2006, 2009 Wind River Systems, Inc. and others.
* Copyright (c) 2006, 2010 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
@ -1154,4 +1154,25 @@ public class IndexCPPBindingResolutionBugs extends IndexBindingResolutionTestBas
public void testLateDefinitionOfInheritance_Bug292749() throws Exception {
getBindingFromASTName("useBase(x.d", 7, ICPPFunction.class);
}
// namespace one {
// void fx();
// void fx(int);
// void fx(int, int);
// }
// namespace two {
// using one::fx;
// }
// #include "header.h"
// void test() {
// two::fx();
// two::fx(1);
// two::fx(1,1);
// }
public void testUsingDeclaration_Bug300019() throws Exception {
getBindingFromASTName("fx();", 2, ICPPFunction.class);
getBindingFromASTName("fx(1);", 2, ICPPFunction.class);
getBindingFromASTName("fx(1,1);", 2, ICPPFunction.class);
}
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2006, 2009 QNX Software Systems and others.
* Copyright (c) 2006, 2010 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
@ -147,16 +147,16 @@ class PDOMCPPNamespace extends PDOMCPPBinding
IBinding[] result = null;
try {
if (!prefixLookup) {
return getBindingsViaCache(name.getLookupKey());
}
result= getBindingsViaCache(name.getLookupKey());
} else {
BindingCollector visitor= new BindingCollector(getLinkage(), name.getLookupKey(),
IndexFilter.CPP_DECLARED_OR_IMPLICIT_NO_INSTANCE, prefixLookup, !prefixLookup);
getIndex().accept(visitor);
IBinding[] bindings = visitor.getBindings();
if (fileSet != null) {
bindings= fileSet.filterFileLocalBindings(bindings);
result = visitor.getBindings();
}
if (fileSet != null) {
result= fileSet.filterFileLocalBindings(result);
}
result = (IBinding[]) ArrayUtil.addAll(IBinding.class, result, bindings);
} catch (CoreException e) {
CCorePlugin.log(e);
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2008, 2009 Google, Inc and others.
* Copyright (c) 2008, 2010 Google, 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
@ -7,14 +7,19 @@
*
* Contributors:
* Sergey Prigogin (Google) - initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.internal.core.pdom.dom.cpp;
import java.util.LinkedHashSet;
import java.util.Set;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDeclaration;
import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.internal.core.index.IIndexCPPBindingConstants;
import org.eclipse.cdt.internal.core.pdom.db.Database;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMLinkage;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode;
@ -43,14 +48,24 @@ class PDOMCPPUsingDeclaration extends PDOMCPPBinding implements ICPPUsingDeclara
public PDOMCPPUsingDeclaration(PDOMLinkage linkage, PDOMNode parent, ICPPUsingDeclaration using)
throws CoreException {
super(linkage, parent, using.getNameCharArray());
IBinding[] delegates= using.getDelegates();
long nextRecord = 0;
for (int i = delegates.length; --i >= 0;) {
PDOMCPPUsingDeclaration simpleUsing = i > 0 ?
new PDOMCPPUsingDeclaration(linkage, parent, getNameCharArray()) : this;
simpleUsing.setTargetBinding(parent.getLinkage(), delegates[i]);
getDB().putRecPtr(record + NEXT_DELEGATE, nextRecord);
nextRecord = simpleUsing.getRecord();
final Database db = getDB();
final char[] name = using.getNameCharArray();
Set<PDOMBinding> targets= new LinkedHashSet<PDOMBinding>();
PDOMCPPUsingDeclaration last= null;
for (IBinding delegate : using.getDelegates()) {
PDOMBinding target = getLinkage().adaptBinding(delegate);
if (target != null && targets.add(target)) {
if (last == null) {
setTargetBinding(linkage, target);
last= this;
} else {
PDOMCPPUsingDeclaration next= new PDOMCPPUsingDeclaration(linkage, parent, name);
next.setTargetBinding(linkage, target);
db.putRecPtr(last.getRecord() + NEXT_DELEGATE, next.record);
last= next;
}
}
}
}
@ -62,9 +77,8 @@ class PDOMCPPUsingDeclaration extends PDOMCPPBinding implements ICPPUsingDeclara
super(linkage, parent, name);
}
private void setTargetBinding(PDOMLinkage linkage, IBinding delegate) throws CoreException {
PDOMBinding target = getLinkage().adaptBinding(delegate);
getDB().putRecPtr(record + TARGET_BINDING, target != null ? target.getRecord() : 0);
private void setTargetBinding(PDOMLinkage linkage, PDOMBinding delegate) throws CoreException {
getDB().putRecPtr(record + TARGET_BINDING, delegate != null ? delegate.getRecord() : 0);
}
@Override