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

Fix for bug 203385.

This commit is contained in:
Sergey Prigogin 2008-01-27 01:21:49 +00:00
parent ceb1b0efad
commit b44d607a4f
8 changed files with 210 additions and 67 deletions

View file

@ -157,7 +157,7 @@ public abstract class IndexCPPBindingResolutionTest extends IndexBindingResoluti
// b::A aa;
// b::B bb;
public void _testUsingTypeDirective_177917_2() {
public void testUsingTypeDirective_177917_2() {
IBinding b0= getBindingFromASTName("A aa", 1);
IBinding b1= getBindingFromASTName("B bb", 1);
}

View file

@ -55,5 +55,5 @@ public interface IIndexCPPBindingConstants {
int CPP_TEMPLATE_TYPE_PARAMETER= IIndexBindingConstants.LAST_CONSTANT + 38;
int CPP_FUNCTION_TYPE= IIndexBindingConstants.LAST_CONSTANT + 39;
int GPPBASICTYPE = IIndexBindingConstants.LAST_CONSTANT + 40;
int CPP_USING_DECLARATION= IIndexBindingConstants.LAST_CONSTANT + 41;
}

View file

@ -22,30 +22,7 @@ import org.eclipse.cdt.core.dom.ast.IQualifierType;
import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.ITypedef;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassTemplate;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassTemplatePartialSpecialization;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPDeferredTemplateInstance;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPField;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionTemplate;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceAlias;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPParameter;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPPointerToMemberType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPReferenceType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateDefinition;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateTypeParameter;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPVariable;
import org.eclipse.cdt.core.dom.ast.cpp.*;
import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.index.IIndexBinding;
import org.eclipse.cdt.internal.core.index.CIndex;
@ -253,6 +230,8 @@ public class CPPCompositesFactory extends AbstractCompositeFactory implements IC
} else if(binding instanceof ICPPNamespace) {
ICPPNamespace[] ns = getNamespaces(binding);
result = ns.length == 0 ? null : new CompositeCPPNamespace(this, ns);
} else if (binding instanceof ICPPUsingDeclaration) {
result = new CompositeCPPUsingDeclaration(this, (ICPPUsingDeclaration) binding);
} else if(binding instanceof IEnumeration) {
IEnumeration def = (IEnumeration) findOneDefinition(binding);
result = def == null ? null : new CompositeCPPEnumeration(this, def);

View file

@ -0,0 +1,47 @@
/*******************************************************************************
* Copyright (c) 2007 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
*******************************************************************************/
package org.eclipse.cdt.internal.core.index.composite.cpp;
import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPDelegate;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDeclaration;
import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTName;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPDelegateCreator;
import org.eclipse.cdt.internal.core.index.IIndexFragmentBinding;
import org.eclipse.cdt.internal.core.index.composite.ICompositesFactory;
class CompositeCPPUsingDeclaration extends CompositeCPPBinding implements ICPPUsingDeclaration {
public CompositeCPPUsingDeclaration(ICompositesFactory cf, ICPPUsingDeclaration using) {
super(cf, using);
}
public IBinding[] getMemberBindings() throws DOMException {
fail(); return null;
}
public ICPPDelegate[] getDelegates() throws DOMException {
ICPPDelegate[] delegates = ((ICPPUsingDeclaration) rbinding).getDelegates();
ICPPDelegate[] composites = new ICPPDelegate[delegates.length];
int j = 0;
for (int i = 0; i < delegates.length; i++) {
IBinding binding = delegates[i].getBinding();
if (binding instanceof IIndexFragmentBinding) {
binding = cf.getCompositeBinding((IIndexFragmentBinding) binding);
if (binding instanceof ICPPDelegateCreator) {
composites[j++] = ((ICPPDelegateCreator) binding).createDelegate(new CPPASTName(getNameCharArray()));
}
}
}
return (ICPPDelegate[]) ArrayUtil.trim(ICPPDelegate.class, composites);
}
}

View file

@ -35,12 +35,14 @@ import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.IVariable;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPDeferredTemplateInstance;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceAlias;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateDefinition;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDeclaration;
import org.eclipse.cdt.core.index.IIndexBinding;
import org.eclipse.cdt.core.index.IIndexLinkage;
import org.eclipse.cdt.internal.core.Util;
@ -129,8 +131,7 @@ public abstract class PDOMLinkage extends PDOMNamedNode implements IIndexLinkage
public void accept(final IPDOMVisitor visitor) throws CoreException {
if (visitor instanceof IBTreeVisitor) {
getIndex().accept((IBTreeVisitor) visitor);
}
else {
} else {
getIndex().accept(new IBTreeVisitor() {
public int compare(int record) throws CoreException {
return 0;
@ -257,8 +258,7 @@ public abstract class PDOMLinkage extends PDOMNamedNode implements IIndexLinkage
IBinding scopeBinding = null;
if (binding instanceof ICPPTemplateInstance) {
scopeBinding = ((ICPPTemplateInstance)binding).getTemplateDefinition();
}
else {
} else {
IScope scope = binding.getScope();
if (scope == null) {
if (binding instanceof ICPPDeferredTemplateInstance) {
@ -288,8 +288,8 @@ public abstract class PDOMLinkage extends PDOMNamedNode implements IIndexLinkage
return null;
}
if(scope instanceof IIndexScope) {
if(scope instanceof CompositeScope) { // we special case for performance
if (scope instanceof IIndexScope) {
if (scope instanceof CompositeScope) { // we special case for performance
return adaptBinding(((CompositeScope)scope).getRawScopeBinding());
} else {
return adaptBinding(((IIndexScope) scope).getScopeBinding());
@ -315,15 +315,12 @@ public abstract class PDOMLinkage extends PDOMNamedNode implements IIndexLinkage
IASTNode scopeNode = ASTInternal.getPhysicalNodeOfScope(scope);
if (scopeNode instanceof IASTCompoundStatement) {
return null;
}
else if (scopeNode instanceof IASTTranslationUnit) {
} else if (scopeNode instanceof IASTTranslationUnit) {
return this;
}
else {
} else {
if (scope instanceof ICPPClassScope) {
scopeBinding = ((ICPPClassScope)scope).getClassType();
}
else {
} else {
IName scopeName = scope.getScopeName();
if (scopeName instanceof IASTName) {
scopeBinding = ((IASTName) scopeName).resolveBinding();
@ -341,8 +338,7 @@ public abstract class PDOMLinkage extends PDOMNamedNode implements IIndexLinkage
if (scopePDOMBinding != null)
return scopePDOMBinding;
}
}
catch (DOMException e) {
} catch (DOMException e) {
throw new CoreException(Util.createStatus(e));
}
return null;
@ -360,10 +356,12 @@ public abstract class PDOMLinkage extends PDOMNamedNode implements IIndexLinkage
if (!(binding instanceof IField)) {
isFileLocal= ASTInternal.isStatic((IVariable) binding);
}
}
else if (binding instanceof IFunction) {
} else if (binding instanceof IFunction) {
IFunction f= (IFunction) binding;
isFileLocal= ASTInternal.isStatic(f, false);
} else if (binding instanceof ICPPUsingDeclaration ||
binding instanceof ICPPNamespaceAlias) {
isFileLocal= true;
}
if (isFileLocal) {
@ -382,7 +380,7 @@ public abstract class PDOMLinkage extends PDOMNamedNode implements IIndexLinkage
/**
* Callback informing the linkage that a name has been added. This is
* used to do addtional processing, like establishing inheritance relationships.
* used to do additional processing, like establishing inheritance relationships.
* @param pdomName the name that was inserted into the linkage
* @param name the name that caused the insertion
* @throws CoreException
@ -402,7 +400,7 @@ public abstract class PDOMLinkage extends PDOMNamedNode implements IIndexLinkage
/**
* Callback informing the linkage that a name is about to be deleted. This is
* used to do addtional processing, like removing inheritance relationships.
* used to do additional processing, like removing inheritance relationships.
* @param pdomName the name that was inserted into the linkage
* @param name the name that caused the insertion
* @throws CoreException
@ -453,5 +451,4 @@ public abstract class PDOMLinkage extends PDOMNamedNode implements IIndexLinkage
public void delete(PDOMLinkage linkage) throws CoreException {
assert false; // no need to delete linkages.
}
}

View file

@ -93,11 +93,11 @@ class PDOMCLinkage extends PDOMLinkage implements IIndexCBindingConstants {
} else if (binding instanceof IFunction) {
IFunction func= (IFunction) binding;
pdomBinding = new PDOMCFunction(pdom, parent, func);
} else if (binding instanceof ICompositeType)
} else if (binding instanceof ICompositeType) {
pdomBinding = new PDOMCStructure(pdom, parent, (ICompositeType) binding);
else if (binding instanceof IEnumeration)
} else if (binding instanceof IEnumeration) {
pdomBinding = new PDOMCEnumeration(pdom, parent, (IEnumeration) binding);
else if (binding instanceof IEnumerator) {
} else if (binding instanceof IEnumerator) {
try {
IEnumeration enumeration = (IEnumeration)((IEnumerator)binding).getType();
PDOMBinding pdomEnumeration = adaptBinding(enumeration);
@ -106,10 +106,11 @@ class PDOMCLinkage extends PDOMLinkage implements IIndexCBindingConstants {
} catch (DOMException e) {
throw new CoreException(Util.createStatus(e));
}
} else if (binding instanceof ITypedef)
} else if (binding instanceof ITypedef) {
pdomBinding = new PDOMCTypedef(pdom, parent, (ITypedef)binding);
}
if (pdomBinding!=null) {
if (pdomBinding != null) {
pdomBinding.setLocalToFile(getLocalToFile(binding));
parent.addChild(pdomBinding);
afterAddBinding(pdomBinding);

View file

@ -38,7 +38,6 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassTemplatePartialSpecialization;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPDeferredTemplateInstance;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPDelegate;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPField;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionTemplate;
@ -390,19 +389,22 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants {
pdomBinding = new PDOMCPPNamespaceAlias(pdom, parent, (ICPPNamespaceAlias) binding);
} else if (binding instanceof ICPPNamespace) {
pdomBinding = new PDOMCPPNamespace(pdom, parent, (ICPPNamespace) binding);
} else if (binding instanceof ICPPUsingDeclaration) {
pdomBinding = new PDOMCPPUsingDeclaration(pdom, parent, (ICPPUsingDeclaration) binding);
} else if (binding instanceof IEnumeration) {
pdomBinding = new PDOMCPPEnumeration(pdom, parent, (IEnumeration) binding);
} else if (binding instanceof IEnumerator) {
IEnumeration enumeration = (IEnumeration)((IEnumerator)binding).getType();
PDOMBinding pdomEnumeration = adaptBinding(enumeration);
if (pdomEnumeration instanceof PDOMCPPEnumeration)
if (pdomEnumeration instanceof PDOMCPPEnumeration) {
pdomBinding = new PDOMCPPEnumerator(pdom, parent, (IEnumerator) binding,
(PDOMCPPEnumeration)pdomEnumeration);
}
} else if (binding instanceof ITypedef) {
pdomBinding = new PDOMCPPTypedef(pdom, parent, (ITypedef)binding);
}
if(pdomBinding!=null) {
if (pdomBinding != null) {
pdomBinding.setLocalToFile(getLocalToFile(binding));
parent.addChild(pdomBinding);
afterAddBinding(pdomBinding);
@ -441,8 +443,7 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants {
PDOMBinding pdomBinding= adaptBinding(method);
if (pdomBinding == null) {
addBinding(type, method);
}
else {
} else {
if (!pdomBinding.hasDefinition()) {
pdomBinding.update(this, method);
}
@ -534,6 +535,8 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants {
return CPPNAMESPACEALIAS;
else if (binding instanceof ICPPNamespace)
return CPPNAMESPACE;
else if (binding instanceof ICPPUsingDeclaration)
return CPP_USING_DECLARATION;
else if (binding instanceof IEnumeration)
return CPPENUMERATION;
else if (binding instanceof IEnumerator)
@ -549,21 +552,10 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants {
*/
@Override
public PDOMBinding doAdaptBinding(IBinding binding, int localToFileRec) throws CoreException {
if (binding instanceof ICPPUsingDeclaration) {
try {
ICPPDelegate[] delegates = ((ICPPUsingDeclaration)binding).getDelegates();
if (delegates.length == 0)
return null;
// TODO - if there are more than one delegate, we have no way of knowing which one...
return adaptBinding(delegates[0].getBinding());
} catch (DOMException e) {
return null;
}
}
PDOMNode parent = getAdaptedParent(binding, false);
if (parent == this) {
return CPPFindBinding.findBinding(getIndex(), this, binding, localToFileRec);
}
}
if (parent instanceof PDOMCPPNamespace) {
return CPPFindBinding.findBinding(((PDOMCPPNamespace)parent).getIndex(), this, binding, localToFileRec);
}
@ -656,6 +648,8 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants {
return new PDOMCPPNamespace(pdom, record);
case CPPNAMESPACEALIAS:
return new PDOMCPPNamespaceAlias(pdom, record);
case CPP_USING_DECLARATION:
return new PDOMCPPUsingDeclaration(pdom, record);
case GPPBASICTYPE:
return new PDOMGPPBasicType(pdom, record);
case CPPBASICTYPE:

View file

@ -0,0 +1,125 @@
/*******************************************************************************
* Copyright (c) 2007 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
*******************************************************************************/
package org.eclipse.cdt.internal.core.pdom.dom.cpp;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPDelegate;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDeclaration;
import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTName;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPDelegateCreator;
import org.eclipse.cdt.internal.core.index.IIndexCPPBindingConstants;
import org.eclipse.cdt.internal.core.pdom.PDOM;
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;
import org.eclipse.core.runtime.CoreException;
/**
* Represents "using" declaration in PDOM. A single "using" declaration resolving to multiple
* objects, e.g. functions with the same name but different signatures, is represented by multiple
* chained PDOMCPPUsingDeclaration records.
*
* @see ICPPUsingDeclaration
*/
class PDOMCPPUsingDeclaration extends PDOMCPPBinding implements ICPPUsingDeclaration {
private static final int TARGET_BINDING = PDOMCPPBinding.RECORD_SIZE + 0;
// Using declarations for functions may have multiple delegates. We model such case
// by creating a chain of PDOMCPPUsingDeclaration objects linked by NEXT_DELEGATE field.
private static final int NEXT_DELEGATE = PDOMCPPBinding.RECORD_SIZE + 4;
protected static final int RECORD_SIZE = PDOMCPPBinding.RECORD_SIZE + 8;
private ICPPDelegate[] delegates;
public PDOMCPPUsingDeclaration(PDOM pdom, PDOMNode parent, ICPPUsingDeclaration using)
throws CoreException {
super(pdom, parent, using.getNameCharArray());
ICPPDelegate[] delegates;
try {
delegates = using.getDelegates();
} catch (DOMException e) {
CCorePlugin.log(e);
return;
}
int nextRecord = 0;
for (int i = delegates.length; --i >= 0;) {
PDOMCPPUsingDeclaration simpleUsing = i > 0 ?
new PDOMCPPUsingDeclaration(pdom, parent, getNameCharArray()) : this;
simpleUsing.setTargetBinding(parent.getLinkageImpl(), delegates[i]);
pdom.getDB().putInt(record + NEXT_DELEGATE, nextRecord);
nextRecord = simpleUsing.getRecord();
}
}
public PDOMCPPUsingDeclaration(PDOM pdom, int record) {
super(pdom, record);
}
private PDOMCPPUsingDeclaration(PDOM pdom, PDOMNode parent, char[] name) throws CoreException {
super(pdom, parent, name);
}
private void setTargetBinding(PDOMLinkage linkage, ICPPDelegate delegate) throws CoreException {
PDOMBinding target = getLinkageImpl().adaptBinding(delegate.getBinding());
pdom.getDB().putInt(record + TARGET_BINDING, target != null ? target.getRecord() : 0);
}
protected int getRecordSize() {
return RECORD_SIZE;
}
public int getNodeType() {
return IIndexCPPBindingConstants.CPP_USING_DECLARATION;
}
public ICPPDelegate[] getDelegates() {
if (delegates == null) {
delegates = new ICPPDelegate[1];
int i = 0;
PDOMCPPUsingDeclaration alias = this;
try {
do {
IBinding binding = alias.getBinding();
if (binding instanceof ICPPDelegateCreator) {
ICPPDelegate delegate = ((ICPPDelegateCreator) binding).createDelegate(new CPPASTName(getNameCharArray()));
ArrayUtil.append(ICPPDelegate.class, delegates, i++, delegate);
}
} while ((alias = alias.getNext()) != null);
} catch (CoreException e) {
CCorePlugin.log(e);
}
delegates = (ICPPDelegate[]) ArrayUtil.trim(ICPPDelegate.class, delegates);
}
return delegates;
}
private PDOMCPPUsingDeclaration getNext() throws CoreException {
int nextRecord = pdom.getDB().getInt(record + NEXT_DELEGATE);
return nextRecord != 0 ? new PDOMCPPUsingDeclaration(pdom, nextRecord) : null;
}
private IBinding getBinding() {
try {
return (IBinding) getLinkageImpl().getNode(
getPDOM().getDB().getInt(record + TARGET_BINDING));
} catch (CoreException e) {
CCorePlugin.log(e);
}
return null;
}
public boolean hasDeclaration() throws CoreException {
// TODO(sprigogin) I'm not sure if returning unconditional true is legitimate,
// but I couldn't figure out a better way to satisfy DeclaredBindingsFilter#acceptBinding.
return true;
}
}