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

Removes a workaround in PDOMCPPLinkage.getAdaptedParent().

This commit is contained in:
Markus Schorn 2008-05-15 12:05:51 +00:00
parent 9f420bc917
commit 4a256b8f16
7 changed files with 58 additions and 38 deletions

View file

@ -234,7 +234,7 @@ public class CPPTemplateTemplateParameter extends CPPTemplateParameter implement
} }
public IASTName getUnknownName() { public IASTName getUnknownName() {
return null; return new CPPASTName(getNameCharArray());
} }
public ICPPUnknownBinding getUnknownContainerBinding() { public ICPPUnknownBinding getUnknownContainerBinding() {

View file

@ -72,7 +72,7 @@ public class CPPTemplateTypeParameter extends CPPTemplateParameter implements
} }
public IASTName getUnknownName() { public IASTName getUnknownName() {
return null; return new CPPASTName(getNameCharArray());
} }
public ICPPUnknownBinding getUnknownContainerBinding() { public ICPPUnknownBinding getUnknownContainerBinding() {

View file

@ -13,6 +13,7 @@ package org.eclipse.cdt.internal.core.index.composite.cpp;
import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IArrayType; import org.eclipse.cdt.core.dom.ast.IArrayType;
import org.eclipse.cdt.core.dom.ast.IBasicType; import org.eclipse.cdt.core.dom.ast.IBasicType;
import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IBinding;
@ -52,6 +53,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPVariable;
import org.eclipse.cdt.core.index.IIndex; import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.index.IIndexBinding; import org.eclipse.cdt.core.index.IIndexBinding;
import org.eclipse.cdt.core.index.IIndexMacroContainer; import org.eclipse.cdt.core.index.IIndexMacroContainer;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalUnknownScope;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownClassInstance; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownClassInstance;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownClassType; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownClassType;
import org.eclipse.cdt.internal.core.index.CIndex; import org.eclipse.cdt.internal.core.index.CIndex;
@ -76,16 +78,15 @@ public class CPPCompositesFactory extends AbstractCompositeFactory {
* @see org.eclipse.cdt.internal.core.index.composite.cpp.ICompositesFactory#getCompositeScope(org.eclipse.cdt.core.index.IIndex, org.eclipse.cdt.core.dom.ast.IScope) * @see org.eclipse.cdt.internal.core.index.composite.cpp.ICompositesFactory#getCompositeScope(org.eclipse.cdt.core.index.IIndex, org.eclipse.cdt.core.dom.ast.IScope)
*/ */
public IIndexScope getCompositeScope(IIndexScope rscope) { public IIndexScope getCompositeScope(IIndexScope rscope) {
IIndexScope result;
try { try {
if (rscope == null) { if (rscope == null) {
return null; return null;
} else if (rscope instanceof ICPPClassScope) { }
if (rscope instanceof ICPPClassScope) {
ICPPClassScope classScope = (ICPPClassScope) rscope; ICPPClassScope classScope = (ICPPClassScope) rscope;
result = new CompositeCPPClassScope(this, return new CompositeCPPClassScope(this, findOneBinding(classScope.getClassType()));
findOneBinding(classScope.getClassType())); }
} else if (rscope instanceof ICPPNamespaceScope) { if (rscope instanceof ICPPNamespaceScope) {
ICPPNamespace[] namespaces; ICPPNamespace[] namespaces;
if (rscope instanceof CompositeCPPNamespace) { if (rscope instanceof CompositeCPPNamespace) {
// avoid duplicating the search // avoid duplicating the search
@ -94,17 +95,23 @@ public class CPPCompositesFactory extends AbstractCompositeFactory {
namespaces = getNamespaces(rscope.getScopeBinding()); namespaces = getNamespaces(rscope.getScopeBinding());
} }
return new CompositeCPPNamespaceScope(this, namespaces); return new CompositeCPPNamespaceScope(this, namespaces);
} else if (rscope instanceof ICPPTemplateScope) {
return new CompositeCPPTemplateScope(this, (ICPPTemplateScope) rscope);
} else {
throw new CompositingNotImplementedError(rscope.getClass().getName());
} }
if (rscope instanceof ICPPTemplateScope) {
return new CompositeCPPTemplateScope(this, (ICPPTemplateScope) rscope);
}
if (rscope instanceof ICPPInternalUnknownScope) {
ICPPInternalUnknownScope uscope= (ICPPInternalUnknownScope) rscope;
final ICPPBinding binding = uscope.getScopeBinding();
return new CompositeCPPUnknownScope((CompositeCPPBinding) getCompositeBinding((IIndexFragmentBinding) binding), (IASTName) uscope.getPhysicalNode());
}
throw new CompositingNotImplementedError(rscope.getClass().getName());
} catch(CoreException ce) { } catch(CoreException ce) {
CCorePlugin.log(ce); CCorePlugin.log(ce);
throw new CompositingNotImplementedError(ce.getMessage()); throw new CompositingNotImplementedError(ce.getMessage());
} catch(DOMException ce) {
CCorePlugin.log(ce);
throw new CompositingNotImplementedError(ce.getMessage());
} }
return result;
} }
/* (non-Javadoc) /* (non-Javadoc)

View file

@ -17,6 +17,7 @@ import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope; import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateTypeParameter; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateTypeParameter;
import org.eclipse.cdt.core.parser.util.ObjectMap; import org.eclipse.cdt.core.parser.util.ObjectMap;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTName;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownBinding; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownBinding;
import org.eclipse.cdt.internal.core.index.IIndexType; import org.eclipse.cdt.internal.core.index.IIndexType;
import org.eclipse.cdt.internal.core.index.composite.ICompositesFactory; import org.eclipse.cdt.internal.core.index.composite.ICompositesFactory;
@ -24,6 +25,8 @@ import org.eclipse.cdt.internal.core.index.composite.ICompositesFactory;
public class CompositeCPPTemplateTypeParameter extends CompositeCPPBinding public class CompositeCPPTemplateTypeParameter extends CompositeCPPBinding
implements ICPPTemplateTypeParameter, ICPPUnknownBinding, IIndexType { implements ICPPTemplateTypeParameter, ICPPUnknownBinding, IIndexType {
private ICPPScope unknownScope;
public CompositeCPPTemplateTypeParameter(ICompositesFactory cf, ICPPTemplateTypeParameter binding) { public CompositeCPPTemplateTypeParameter(ICompositesFactory cf, ICPPTemplateTypeParameter binding) {
super(cf, binding); super(cf, binding);
} }
@ -43,7 +46,10 @@ public class CompositeCPPTemplateTypeParameter extends CompositeCPPBinding
} }
public ICPPScope getUnknownScope() { public ICPPScope getUnknownScope() {
return null; if (unknownScope == null) {
unknownScope= new CompositeCPPUnknownScope(this, getUnknownName());
}
return unknownScope;
} }
public IBinding resolvePartially(ICPPUnknownBinding parentBinding, ObjectMap argMap, ICPPScope instantiationScope) { public IBinding resolvePartially(ICPPUnknownBinding parentBinding, ObjectMap argMap, ICPPScope instantiationScope) {
@ -52,7 +58,7 @@ public class CompositeCPPTemplateTypeParameter extends CompositeCPPBinding
} }
public IASTName getUnknownName() { public IASTName getUnknownName() {
return null; return new CPPASTName(getNameCharArray());
} }
public ICPPUnknownBinding getUnknownContainerBinding() { public ICPPUnknownBinding getUnknownContainerBinding() {

View file

@ -25,6 +25,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance;
import org.eclipse.cdt.core.index.IIndexBinding; import org.eclipse.cdt.core.index.IIndexBinding;
import org.eclipse.cdt.core.index.IIndexFileSet; import org.eclipse.cdt.core.index.IIndexFileSet;
import org.eclipse.cdt.core.parser.util.CharArrayUtils; import org.eclipse.cdt.core.parser.util.CharArrayUtils;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownBinding;
import org.eclipse.cdt.internal.core.index.IIndexFragment; import org.eclipse.cdt.internal.core.index.IIndexFragment;
import org.eclipse.cdt.internal.core.index.IIndexFragmentBinding; import org.eclipse.cdt.internal.core.index.IIndexFragmentBinding;
import org.eclipse.cdt.internal.core.index.IIndexFragmentBindingComparator; import org.eclipse.cdt.internal.core.index.IIndexFragmentBindingComparator;
@ -209,6 +210,11 @@ public abstract class PDOMBinding extends PDOMNamedNode implements IIndexFragmen
if (parent instanceof IIndexScope) { if (parent instanceof IIndexScope) {
return (IIndexScope) parent; return (IIndexScope) parent;
} }
// unknown bindings don't always implement the scope directly
if (parent instanceof ICPPUnknownBinding) {
return (IIndexScope) ((ICPPUnknownBinding) parent).getUnknownScope();
}
} catch (DOMException e) {
} catch (CoreException ce) { } catch (CoreException ce) {
CCorePlugin.log(ce); CCorePlugin.log(ce);
} }
@ -251,14 +257,14 @@ public abstract class PDOMBinding extends PDOMNamedNode implements IIndexFragmen
protected static String getConstantNameForValue(PDOMLinkage linkage, int value) { protected static String getConstantNameForValue(PDOMLinkage linkage, int value) {
Class<? extends PDOMLinkage> c= linkage.getClass(); Class<? extends PDOMLinkage> c= linkage.getClass();
Field[] fields= c.getFields(); Field[] fields= c.getFields();
for (int i = 0; i < fields.length; i++) { for (Field field : fields) {
try { try {
fields[i].setAccessible(true); field.setAccessible(true);
if ((fields[i].getModifiers() & Modifier.STATIC) != 0) { if ((field.getModifiers() & Modifier.STATIC) != 0) {
if (int.class.equals(fields[i].getType())) { if (int.class.equals(field.getType())) {
int fvalue= fields[i].getInt(null); int fvalue= field.getInt(null);
if (fvalue == value) if (fvalue == value)
return fields[i].getName(); return field.getName();
} }
} }
} catch (IllegalAccessException iae) { } catch (IllegalAccessException iae) {

View file

@ -70,7 +70,6 @@ import org.eclipse.cdt.internal.core.Util;
import org.eclipse.cdt.internal.core.dom.parser.ASTInternal; import org.eclipse.cdt.internal.core.dom.parser.ASTInternal;
import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding; import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPBlockScope; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPBlockScope;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPDeferredClassInstance;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalUnknownScope; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalUnknownScope;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownBinding; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownBinding;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownClassInstance; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownClassInstance;
@ -528,12 +527,6 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants {
} else if (binding instanceof ICPPClassType) { } else if (binding instanceof ICPPClassType) {
return CPP_DEFERRED_CLASS_INSTANCE; return CPP_DEFERRED_CLASS_INSTANCE;
} }
} else if (binding instanceof ICPPUnknownBinding) {
if (binding instanceof ICPPUnknownClassInstance) {
return CPP_UNKNOWN_CLASS_INSTANCE;
} else if (binding instanceof ICPPUnknownClassType) {
return CPP_UNKNOWN_CLASS_TYPE;
}
} else if (binding instanceof ICPPTemplateInstance) { } else if (binding instanceof ICPPTemplateInstance) {
if (binding instanceof ICPPConstructor) { if (binding instanceof ICPPConstructor) {
return CPP_CONSTRUCTOR_INSTANCE; return CPP_CONSTRUCTOR_INSTANCE;
@ -602,6 +595,12 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants {
return CPP_FUNCTION_TYPE; return CPP_FUNCTION_TYPE;
} else if (binding instanceof ICPPFunction) { } else if (binding instanceof ICPPFunction) {
return CPPFUNCTION; return CPPFUNCTION;
} else if (binding instanceof ICPPUnknownBinding) {
if (binding instanceof ICPPUnknownClassInstance) {
return CPP_UNKNOWN_CLASS_INSTANCE;
} else if (binding instanceof ICPPUnknownClassType) {
return CPP_UNKNOWN_CLASS_TYPE;
}
} else if (binding instanceof ICPPClassTemplate) { } else if (binding instanceof ICPPClassTemplate) {
// this must be before class type // this must be before class type
return CPP_CLASS_TEMPLATE; return CPP_CLASS_TEMPLATE;
@ -670,7 +669,7 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants {
} }
if (parent instanceof IPDOMMemberOwner) { if (parent instanceof IPDOMMemberOwner) {
int localToFileRec= getLocalToFileRec(parent, binding); int localToFileRec= getLocalToFileRec(parent, binding);
return CPPFindBinding.findBinding(parent, this, binding, localToFileRec); return CPPFindBinding.findBinding(parent, this, binding, localToFileRec, parent instanceof ICPPSpecialization);
} }
return null; return null;
} }
@ -693,12 +692,7 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants {
// all instances are stored with their template definition // all instances are stored with their template definition
if (binding instanceof ICPPTemplateInstance) { if (binding instanceof ICPPTemplateInstance) {
scopeBinding= ((ICPPTemplateInstance) binding).getTemplateDefinition(); scopeBinding= ((ICPPTemplateInstance) binding).getTemplateDefinition();
} else if (binding instanceof ICPPUnknownClassType && } else {
binding instanceof ICPPDeferredClassInstance == false) {
// the parent of an unknown class can be a template parameter, which is not a scope
scopeBinding= ((ICPPUnknownClassType) binding).getUnknownContainerBinding();
}
else {
IScope scope = binding.getScope(); IScope scope = binding.getScope();
if (scope instanceof ICPPTemplateScope if (scope instanceof ICPPTemplateScope
&& binding instanceof ICPPTemplateParameter == false && binding instanceof ICPPTemplateParameter == false

View file

@ -25,6 +25,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateTypeParameter;
import org.eclipse.cdt.core.parser.util.ObjectMap; import org.eclipse.cdt.core.parser.util.ObjectMap;
import org.eclipse.cdt.internal.core.Util; import org.eclipse.cdt.internal.core.Util;
import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding; import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTName;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownBinding; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownBinding;
import org.eclipse.cdt.internal.core.index.IIndexCPPBindingConstants; import org.eclipse.cdt.internal.core.index.IIndexCPPBindingConstants;
import org.eclipse.cdt.internal.core.index.IIndexType; import org.eclipse.cdt.internal.core.index.IIndexType;
@ -48,6 +49,7 @@ class PDOMCPPTemplateTypeParameter extends PDOMCPPBinding implements IPDOMMember
*/ */
@SuppressWarnings("hiding") @SuppressWarnings("hiding")
protected static final int RECORD_SIZE = PDOMCPPBinding.RECORD_SIZE + 8; protected static final int RECORD_SIZE = PDOMCPPBinding.RECORD_SIZE + 8;
private ICPPScope fUnknownScope;
public PDOMCPPTemplateTypeParameter(PDOM pdom, PDOMNode parent, public PDOMCPPTemplateTypeParameter(PDOM pdom, PDOMNode parent,
ICPPTemplateTypeParameter param) throws CoreException { ICPPTemplateTypeParameter param) throws CoreException {
@ -141,13 +143,18 @@ class PDOMCPPTemplateTypeParameter extends PDOMCPPBinding implements IPDOMMember
public ICPPScope getUnknownScope() { public ICPPScope getUnknownScope() {
return null; if (fUnknownScope == null) {
fUnknownScope= new PDOMCPPUnknownScope(this, new CPPASTName(getNameCharArray()));
}
return fUnknownScope;
} }
public IBinding resolvePartially(ICPPUnknownBinding parentBinding, ObjectMap argMap, ICPPScope instantiationScope) { fail(); return null;} public IBinding resolvePartially(ICPPUnknownBinding parentBinding, ObjectMap argMap, ICPPScope instantiationScope) {
public IASTName getUnknownName() {
return null; return null;
} }
public IASTName getUnknownName() {
return new CPPASTName(getNameCharArray());
}
public ICPPUnknownBinding getUnknownContainerBinding() { public ICPPUnknownBinding getUnknownContainerBinding() {
return null; return null;
} }