From 85b56d1d8af80dac8a3456970b0ba8117df04b9b Mon Sep 17 00:00:00 2001 From: Markus Schorn Date: Mon, 1 Feb 2010 16:20:25 +0000 Subject: [PATCH] Bug 300019: Using declaration targeting more than two declarations --- .../tests/IndexCPPBindingResolutionBugs.java | 23 ++++++++++- .../core/pdom/dom/cpp/PDOMCPPNamespace.java | 16 ++++---- .../pdom/dom/cpp/PDOMCPPUsingDeclaration.java | 40 +++++++++++++------ 3 files changed, 57 insertions(+), 22 deletions(-) diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPBindingResolutionBugs.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPBindingResolutionBugs.java index e0c63b385cd..f23cc4b791e 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPBindingResolutionBugs.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPBindingResolutionBugs.java @@ -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); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPNamespace.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPNamespace.java index 8920a8ac323..a90b94bd49a 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPNamespace.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPNamespace.java @@ -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); + result = visitor.getBindings(); } - 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= fileSet.filterFileLocalBindings(result); } - result = (IBinding[]) ArrayUtil.addAll(IBinding.class, result, bindings); } catch (CoreException e) { CCorePlugin.log(e); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPUsingDeclaration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPUsingDeclaration.java index d02e328b181..ec2ef333467 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPUsingDeclaration.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPUsingDeclaration.java @@ -1,20 +1,25 @@ /******************************************************************************* - * 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 * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Sergey Prigogin (Google) - initial API and implementation + * 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 targets= new LinkedHashSet(); + 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