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

Classification of names depending on template parameters, bug 234321.

This commit is contained in:
Markus Schorn 2008-12-03 17:47:34 +00:00
parent dfb6a300d1
commit 09f94f8e51
34 changed files with 468 additions and 518 deletions

View file

@ -23,6 +23,7 @@ import org.eclipse.cdt.core.dom.ast.IASTProblemDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.dom.ast.IASTTypeId; import org.eclipse.cdt.core.dom.ast.IASTTypeId;
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.IFunction; import org.eclipse.cdt.core.dom.ast.IFunction;
import org.eclipse.cdt.core.dom.ast.IProblemBinding; import org.eclipse.cdt.core.dom.ast.IProblemBinding;
import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.IType;
@ -33,6 +34,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateId;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTUsingDeclaration; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTUsingDeclaration;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionTemplate; import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionTemplate;
import org.eclipse.cdt.core.parser.ParserLanguage; import org.eclipse.cdt.core.parser.ParserLanguage;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownBinding;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
/** /**
@ -3850,7 +3852,7 @@ public class AST2CPPSpecTest extends AST2SpecBaseTest {
// S a( f() ); // does not instantiate member template // S a( f() ); // does not instantiate member template
// } // }
public void test12_8s3() throws Exception { public void test12_8s3() throws Exception {
parse(getAboveComment(), ParserLanguage.CPP, false, 0); parse(getAboveComment(), ParserLanguage.CPP, true, 0);
} }
// void h(int()); // void h(int());
@ -4245,7 +4247,7 @@ public class AST2CPPSpecTest extends AST2SpecBaseTest {
// void* p = operator new(sizeof(int)*n); // void* p = operator new(sizeof(int)*n);
// } // }
public void test13_5s4() throws Exception { public void test13_5s4() throws Exception {
parse(getAboveComment(), ParserLanguage.CPP, false, 0); parse(getAboveComment(), ParserLanguage.CPP, true, 0);
} }
// struct B { // struct B {
@ -4268,7 +4270,7 @@ public class AST2CPPSpecTest extends AST2SpecBaseTest {
// // D::operator=(const D&) // // D::operator=(const D&)
// } // }
public void test13_5_3s2() throws Exception { public void test13_5_3s2() throws Exception {
parse(getAboveComment(), ParserLanguage.CPP, false, 0); parse(getAboveComment(), ParserLanguage.CPP, true, 0);
} }
// class X { // class X {
@ -4388,6 +4390,7 @@ public class AST2CPPSpecTest extends AST2SpecBaseTest {
parse(getAboveComment(), ParserLanguage.CPP, false, 0); parse(getAboveComment(), ParserLanguage.CPP, false, 0);
} }
// template<typename T> class complex {};
// template<class T> class Array { // template<class T> class Array {
// T* v; // T* v;
// int sz; // int sz;
@ -4398,8 +4401,7 @@ public class AST2CPPSpecTest extends AST2SpecBaseTest {
// // ... // // ...
// }; // };
// Array<int> v1(20); // Array<int> v1(20);
// typedef complex<double> dcomplex; // complex is a standard // typedef complex<double> dcomplex;
// // library template
// Array<dcomplex> v2(30); // Array<dcomplex> v2(30);
// Array<dcomplex> v3(40); // Array<dcomplex> v3(40);
// void bar() { // void bar() {
@ -4407,7 +4409,7 @@ public class AST2CPPSpecTest extends AST2SpecBaseTest {
// v2[3] = v3.elem(4) = dcomplex(7,8); // v2[3] = v3.elem(4) = dcomplex(7,8);
// } // }
public void test14_3s1() throws Exception { public void test14_3s1() throws Exception {
parse(getAboveComment(), ParserLanguage.CPP, false, 0); parse(getAboveComment(), ParserLanguage.CPP, true, 0);
} }
// template<class T> class X { // template<class T> class X {
@ -4513,6 +4515,8 @@ public class AST2CPPSpecTest extends AST2SpecBaseTest {
parse(getAboveComment(), ParserLanguage.CPP, true, 0); parse(getAboveComment(), ParserLanguage.CPP, true, 0);
} }
// void error(const char*);
// template<class T> class Array { // template<class T> class Array {
// T* v; // T* v;
// int sz; // int sz;
@ -4528,7 +4532,7 @@ public class AST2CPPSpecTest extends AST2SpecBaseTest {
// return v[i]; // return v[i];
// } // }
public void test14_5_1_1s1() throws Exception { public void test14_5_1_1s1() throws Exception {
parse(getAboveComment(), ParserLanguage.CPP, false, 0); parse(getAboveComment(), ParserLanguage.CPP, true, 0);
} }
// void test() { // void test() {
@ -4562,7 +4566,7 @@ public class AST2CPPSpecTest extends AST2SpecBaseTest {
// // ... // // ...
// } // }
public void test14_5_2s1() throws Exception { public void test14_5_2s1() throws Exception {
parse(getAboveComment(), ParserLanguage.CPP, false, 0); parse(getAboveComment(), ParserLanguage.CPP, true, 0);
} }
@ -4592,8 +4596,8 @@ public class AST2CPPSpecTest extends AST2SpecBaseTest {
// ip = a.operator int*(); // explicit call to template operator // ip = a.operator int*(); // explicit call to template operator
// // A::operator int*() // // A::operator int*()
// } // }
public void test14_5_2s5() throws Exception { public void _test14_5_2s5() throws Exception {
parse(getAboveComment(), ParserLanguage.CPP, false, 0); parse(getAboveComment(), ParserLanguage.CPP, true, 0);
} }
// template<class T> class X { // template<class T> class X {
@ -4978,10 +4982,11 @@ public class AST2CPPSpecTest extends AST2SpecBaseTest {
parse(getAboveComment(), ParserLanguage.CPP, true, 0); parse(getAboveComment(), ParserLanguage.CPP, true, 0);
} }
// template<typename T> class Array {};
// template<class T> class X : public Array<T> { }; // template<class T> class X : public Array<T> { };
// template<class T> class Y : public T { }; // template<class T> class Y : public T { };
public void test14_6_1s3b() throws Exception { public void test14_6_1s3b() throws Exception {
parse(getAboveComment(), ParserLanguage.CPP, false, 0); parse(getAboveComment(), ParserLanguage.CPP, true, 0);
} }
// template<class T, int i> class Y { // template<class T, int i> class Y {
@ -5032,6 +5037,7 @@ public class AST2CPPSpecTest extends AST2SpecBaseTest {
parse(getAboveComment(), ParserLanguage.CPP, false, 0); parse(getAboveComment(), ParserLanguage.CPP, false, 0);
} }
// template <typename T> class B {};
// template<class T> struct X : B<T> { // template<class T> struct X : B<T> {
// typename T::A* pa; // typename T::A* pa;
// void f(B<T>* pb) { // void f(B<T>* pb) {
@ -5040,7 +5046,13 @@ public class AST2CPPSpecTest extends AST2SpecBaseTest {
// } // }
// }; // };
public void test14_6_2s2() throws Exception { public void test14_6_2s2() throws Exception {
parse(getAboveComment(), ParserLanguage.CPP, false, 0); final String code = getAboveComment();
parse(code, ParserLanguage.CPP, true, 0);
BindingAssertionHelper bh= new BindingAssertionHelper(code, true);
ICPPUnknownBinding unknown= bh.assertNonProblem("B<T>", 4);
unknown= bh.assertNonProblem("T::A", 4);
unknown= bh.assertNonProblem("B<T>::i", 7);
unknown= bh.assertNonProblem("j", 1);
} }
// typedef double A; // typedef double A;
@ -5050,7 +5062,7 @@ public class AST2CPPSpecTest extends AST2SpecBaseTest {
// template<class T> struct X : B<T> { // template<class T> struct X : B<T> {
// A a; // a has type double // A a; // a has type double
// }; // };
public void test14_6_2s3() throws Exception { // TODO this doesn't compile via g++ ? public void test14_6_2s3() throws Exception {
final String content= getAboveComment(); final String content= getAboveComment();
IASTTranslationUnit tu= parse(content, ParserLanguage.CPP, true, 0); IASTTranslationUnit tu= parse(content, ParserLanguage.CPP, true, 0);
BindingAssertionHelper bh= new BindingAssertionHelper(content, true); BindingAssertionHelper bh= new BindingAssertionHelper(content, true);
@ -5076,7 +5088,13 @@ public class AST2CPPSpecTest extends AST2SpecBaseTest {
// }; // };
// Y<A> ya; // Y<A> ya;
public void test14_6_2s4() throws Exception { public void test14_6_2s4() throws Exception {
parse(getAboveComment(), ParserLanguage.CPP, true, 0); final String content= getAboveComment();
parse(content, ParserLanguage.CPP, true, 0);
BindingAssertionHelper bh= new BindingAssertionHelper(content, true);
IBinding b= bh.assertNonProblem("b;", 1);
assertEquals("Y", b.getOwner().getName());
b= bh.assertNonProblem("a = i", 1);
assertNull(b.getOwner());
} }
// void g(double); // void g(double);

View file

@ -1596,8 +1596,7 @@ public class AST2TemplateTests extends AST2BaseTest {
ICPPFunctionTemplate f = (ICPPFunctionTemplate) col.getName(1).resolveBinding(); ICPPFunctionTemplate f = (ICPPFunctionTemplate) col.getName(1).resolveBinding();
ICPPFunction f2 = (ICPPFunction) col.getName(8).resolveBinding(); ICPPFunction f2 = (ICPPFunction) col.getName(8).resolveBinding();
assertTrue(f2 instanceof ICPPTemplateInstance); assertTrue(f2 instanceof ICPPUnknownBinding);
assertSame(((ICPPTemplateInstance)f2).getTemplateDefinition(), f);
} }
// template < class T > class A {}; // template < class T > class A {};
@ -3414,4 +3413,72 @@ public class AST2TemplateTests extends AST2BaseTest {
assertInstance(a1, ICPPField.class); assertInstance(a1, ICPPField.class);
assertSame(a1, a2); assertSame(a1, a2);
} }
// void f(int); void f(char);
// void g(int);
// template<typename T> void h(T);
// template<typename T> struct A {
// void m(int); void m(char);
// void m() {
// typename T::B b;
// b.func(); b.var;
// f(b); g(b); h(b); m(b);
// }
// };
public void testUnknownReferences_Bug257186() throws Exception {
final String code = getAboveComment();
parseAndCheckBindings(code, ParserLanguage.CPP);
BindingAssertionHelper bh= new BindingAssertionHelper(code, true);
bh.assertNonProblem("func();", 4, ICPPUnknownBinding.class);
bh.assertNonProblem("var;", 3, ICPPUnknownBinding.class);
bh.assertNonProblem("f(b)", 1, ICPPUnknownBinding.class, IFunction.class);
bh.assertNonProblem("h(b)", 1, ICPPUnknownBinding.class, IFunction.class);
bh.assertNonProblem("m(b)", 1, ICPPUnknownBinding.class, IFunction.class);
IFunction g= bh.assertNonProblem("g(b)", 1);
assertFalse(g instanceof ICPPUnknownBinding);
}
// template<typename T> struct A {
// void m() {
// T::b.c;
// T::b.f();
// T::b.f().d;
// T::f1();
// }
// };
public void testTypeOfUnknownReferences_Bug257186a() throws Exception {
final String code = getAboveComment();
parseAndCheckBindings(code, ParserLanguage.CPP);
BindingAssertionHelper bh= new BindingAssertionHelper(code, true);
bh.assertNonProblem("b.c", 1, ICPPUnknownBinding.class);
bh.assertNonProblem("c;", 1, ICPPUnknownBinding.class);
bh.assertNonProblem("f();", 1, ICPPUnknownBinding.class, IFunction.class);
bh.assertNonProblem("f().", 1, ICPPUnknownBinding.class, IFunction.class);
bh.assertNonProblem("d;", 1, ICPPUnknownBinding.class);
bh.assertNonProblem("f1();", 2, ICPPUnknownBinding.class, IFunction.class);
}
// template<typename T> struct A {
// void m() {
// T::b->c;
// T::b->f();
// T::b->f()->d;
// T::f1();
// }
// };
public void testTypeOfUnknownReferences_Bug257186b() throws Exception {
final String code = getAboveComment();
parseAndCheckBindings(code, ParserLanguage.CPP);
BindingAssertionHelper bh= new BindingAssertionHelper(code, true);
bh.assertNonProblem("b->c", 1, ICPPUnknownBinding.class);
bh.assertNonProblem("c;", 1, ICPPUnknownBinding.class);
bh.assertNonProblem("f();", 1, ICPPUnknownBinding.class, IFunction.class);
bh.assertNonProblem("f()->", 1, ICPPUnknownBinding.class, IFunction.class);
bh.assertNonProblem("d;", 1, ICPPUnknownBinding.class);
bh.assertNonProblem("f1();", 2, ICPPUnknownBinding.class, IFunction.class);
}
} }

View file

@ -11,16 +11,11 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.core.dom.ast.cpp; package org.eclipse.cdt.core.dom.ast.cpp;
/** import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPDeferredClassInstance;
* Interface for deferred instances. A deferred instance is not actually instantiated yet,
* because the correct template cannot be selected until all information is available.
*/
public interface ICPPDeferredTemplateInstance extends ICPPTemplateInstance {
/** /**
* Returns an empty map, because template parameters cannot be mapped until * @deprecated use {@link ICPPDeferredClassInstance} instead.
* all of the arguments are resolved.
* @since 5.1
*/ */
public ICPPTemplateParameterMap getTemplateParameterMap(); @Deprecated
public interface ICPPDeferredTemplateInstance extends ICPPTemplateInstance {
} }

View file

@ -111,11 +111,11 @@ public class CPPDeferredClassInstance extends CPPUnknownClass implements ICPPDef
} }
@Override @Override
public ICPPScope getUnknownScope() throws DOMException { public ICPPScope asScope() throws DOMException {
if (fLookupScope != null) if (fLookupScope != null)
return fLookupScope; return fLookupScope;
return super.getUnknownScope(); return super.asScope();
} }
@Override @Override

View file

@ -1,150 +0,0 @@
/*******************************************************************************
* Copyright (c) 2005, 2008 IBM Corporation 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:
* Andrew Niefer (IBM Corporation) - initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IFunction;
import org.eclipse.cdt.core.dom.ast.IFunctionType;
import org.eclipse.cdt.core.dom.ast.IParameter;
import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPDeferredTemplateInstance;
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.ICPPParameter;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateArgument;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateDefinition;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameterMap;
import org.eclipse.cdt.core.parser.util.ObjectMap;
import org.eclipse.cdt.internal.core.dom.parser.ASTInternal;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPTemplates;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
/**
* The deferred function instance collects information about the instantiation until it can
* be carried out.
*/
public class CPPDeferredFunctionInstance extends CPPUnknownBinding implements ICPPFunction, ICPPInternalFunction, ICPPDeferredTemplateInstance {
private ICPPTemplateArgument[] fArguments;
private ICPPFunctionTemplate fFunctionTemplate;
private IParameter [] fParameters;
private IFunctionType fFunctionType;
public CPPDeferredFunctionInstance(ICPPFunctionTemplate template, ICPPTemplateArgument[] arguments) throws DOMException {
super(template.getOwner(), new CPPASTName(template.getNameCharArray()));
fArguments= arguments;
fFunctionTemplate= template;
}
public ICPPTemplateDefinition getTemplateDefinition() {
return fFunctionTemplate;
}
public IBinding getSpecializedBinding() {
return fFunctionTemplate;
}
@Deprecated
public ObjectMap getArgumentMap() {
return ObjectMap.EMPTY_MAP;
}
public ICPPTemplateParameterMap getTemplateParameterMap() {
return CPPTemplateParameterMap.EMPTY;
}
@Deprecated
public IType[] getArguments() {
return CPPTemplates.getArguments(getTemplateArguments());
}
public ICPPTemplateArgument[] getTemplateArguments() {
return fArguments;
}
public IParameter[] getParameters() throws DOMException {
if( fParameters == null ){
IParameter [] params = ((ICPPFunction)getTemplateDefinition()).getParameters();
fParameters = new IParameter[ params.length ];
for (int i = 0; i < params.length; i++) {
fParameters[i] = new CPPParameterSpecialization( (ICPPParameter)params[i], null, CPPTemplateParameterMap.EMPTY);
}
}
return fParameters;
}
public IScope getFunctionScope() {
return null;
}
public IFunctionType getType() throws DOMException {
if( fFunctionType == null ){
IFunctionType ft = ((ICPPFunction)getTemplateDefinition()).getType();
IType returnType = ft.getReturnType();
returnType = CPPTemplates.instantiateType(returnType, getTemplateParameterMap(), null);
fFunctionType = CPPVisitor.createImplicitFunctionType( returnType, getParameters(), null);
}
return fFunctionType;
}
public boolean isStatic() throws DOMException {
return ((ICPPFunction)getTemplateDefinition()).isStatic();
}
public boolean isMutable() throws DOMException {
return ((ICPPFunction)getTemplateDefinition()).isMutable();
}
public boolean isInline() throws DOMException {
return ((ICPPFunction)getTemplateDefinition()).isInline();
}
public boolean isExternC() throws DOMException {
return ((ICPPFunction)getTemplateDefinition()).isExternC();
}
public boolean isExtern() throws DOMException {
return ((ICPPFunction)getTemplateDefinition()).isExtern();
}
public boolean isAuto() throws DOMException {
return ((ICPPFunction)getTemplateDefinition()).isAuto();
}
public boolean isRegister() throws DOMException {
return ((ICPPFunction)getTemplateDefinition()).isRegister();
}
public boolean takesVarArgs() throws DOMException {
return ((ICPPFunction)getTemplateDefinition()).takesVarArgs();
}
public boolean isStatic( boolean resolveAll) {
try {
return ASTInternal.isStatic((IFunction) getTemplateDefinition(), resolveAll);
} catch (DOMException e) {
return false;
}
}
public IBinding resolveParameter(IASTParameterDeclaration param) {
return null;
}
public IType[] getExceptionSpecification() throws DOMException {
return ((ICPPFunction)getTemplateDefinition()).getExceptionSpecification();
}
}

View file

@ -44,7 +44,8 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
* @author aniefer * @author aniefer
*/ */
public class CPPTemplateTemplateParameter extends CPPTemplateParameter implements public class CPPTemplateTemplateParameter extends CPPTemplateParameter implements
ICPPTemplateTemplateParameter, ICPPClassType, ICPPInternalTemplate, ICPPUnknownBinding { ICPPTemplateTemplateParameter, ICPPClassType, ICPPInternalTemplate, ICPPUnknownBinding,
ICPPUnknownType {
private ICPPTemplateParameter[] templateParameters; private ICPPTemplateParameter[] templateParameters;
private ObjectMap instances; private ObjectMap instances;
@ -57,7 +58,7 @@ public class CPPTemplateTemplateParameter extends CPPTemplateParameter implement
super(name); super(name);
} }
public ICPPScope getUnknownScope() { public ICPPScope asScope() {
if (unknownScope == null) { if (unknownScope == null) {
IASTName n = null; IASTName n = null;
IASTNode[] nodes = getDeclarations(); IASTNode[] nodes = getDeclarations();

View file

@ -27,14 +27,14 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
* The standard template parameter (template<typename T> or template<class T>). * The standard template parameter (template<typename T> or template<class T>).
*/ */
public class CPPTemplateTypeParameter extends CPPTemplateParameter implements public class CPPTemplateTypeParameter extends CPPTemplateParameter implements
ICPPTemplateTypeParameter, IType, ICPPUnknownBinding { ICPPTemplateTypeParameter, ICPPUnknownType, ICPPUnknownBinding {
private ICPPScope unknownScope; private ICPPScope unknownScope;
public CPPTemplateTypeParameter(IASTName name) { public CPPTemplateTypeParameter(IASTName name) {
super(name); super(name);
} }
public ICPPScope getUnknownScope() { public ICPPScope asScope() {
if (unknownScope == null) { if (unknownScope == null) {
IASTName n = null; IASTName n = null;
IASTNode[] nodes = getDeclarations(); IASTNode[] nodes = getDeclarations();

View file

@ -29,7 +29,7 @@ import org.eclipse.core.runtime.PlatformObject;
/** /**
* Represents a binding that is unknown because it depends on template arguments. * Represents a binding that is unknown because it depends on template arguments.
*/ */
public abstract class CPPUnknownBinding extends PlatformObject public class CPPUnknownBinding extends PlatformObject
implements ICPPUnknownBinding, ICPPInternalBinding, Cloneable { implements ICPPUnknownBinding, ICPPInternalBinding, Cloneable {
protected IBinding fOwner; protected IBinding fOwner;
private ICPPScope unknownScope; private ICPPScope unknownScope;
@ -80,7 +80,7 @@ public abstract class CPPUnknownBinding extends PlatformObject
public IScope getScope() throws DOMException { public IScope getScope() throws DOMException {
if (fOwner instanceof ICPPUnknownBinding) { if (fOwner instanceof ICPPUnknownBinding) {
return ((ICPPUnknownBinding) fOwner).getUnknownScope(); return ((ICPPUnknownBinding) fOwner).asScope();
} else if (fOwner instanceof ICPPClassType) { } else if (fOwner instanceof ICPPClassType) {
return ((ICPPClassType) fOwner).getCompositeScope(); return ((ICPPClassType) fOwner).getCompositeScope();
} else if (fOwner instanceof ICPPNamespace) { } else if (fOwner instanceof ICPPNamespace) {
@ -91,7 +91,7 @@ public abstract class CPPUnknownBinding extends PlatformObject
return null; return null;
} }
public ICPPScope getUnknownScope() throws DOMException { public ICPPScope asScope() throws DOMException {
if (unknownScope == null) { if (unknownScope == null) {
unknownScope = new CPPUnknownScope(this, name); unknownScope = new CPPUnknownScope(this, name);
} }

View file

@ -6,11 +6,10 @@
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* IBM Corporation - initial API and implementation * Andrew Niefer (IBM Corporation) - initial API and implementation
* Sergey Prigogin (Google) * Sergey Prigogin (Google)
* Markus Schorn (Wind River Systems) * Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp; package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.DOMException;
@ -29,10 +28,11 @@ import org.eclipse.cdt.core.parser.util.CharArrayUtils;
/** /**
* Represents a C++ class, declaration of which is not yet available. * Represents a C++ class, declaration of which is not yet available.
*
* @author aniefer
*/ */
public class CPPUnknownClass extends CPPUnknownBinding implements ICPPUnknownClassType { public class CPPUnknownClass extends CPPUnknownBinding implements ICPPUnknownClassType {
public static CPPUnknownClass createUnnamedInstance() {
return new CPPUnknownClass(null, new CPPASTName());
}
public CPPUnknownClass(IBinding binding, IASTName name) { public CPPUnknownClass(IBinding binding, IASTName name) {
super(binding, name); super(binding, name);
@ -79,7 +79,7 @@ public class CPPUnknownClass extends CPPUnknownBinding implements ICPPUnknownCla
} }
public final IScope getCompositeScope() throws DOMException { public final IScope getCompositeScope() throws DOMException {
return getUnknownScope(); return asScope();
} }
public boolean isSameType(IType type) { public boolean isSameType(IType type) {

View file

@ -0,0 +1,89 @@
/*******************************************************************************
* Copyright (c) 2008 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
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Markus Schorn - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IFunction;
import org.eclipse.cdt.core.dom.ast.IFunctionType;
import org.eclipse.cdt.core.dom.ast.IParameter;
import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction;
/**
* Represents a reference to a (member) function (instance), which cannot be resolved because
* it depends on a template parameter. A compiler would resolve it during instantiation.
*/
public class CPPUnknownFunction extends CPPUnknownBinding implements ICPPFunction {
public static IFunction createForSample(IFunction sample, IASTName name) throws DOMException {
return new CPPUnknownFunction(sample.getOwner(), name.getLastName());
}
private IFunctionType fType;
public CPPUnknownFunction(IBinding owner, IASTName name) {
super(owner, name);
}
public IType[] getExceptionSpecification() throws DOMException {
return null;
}
public boolean isExternC() throws DOMException {
return false;
}
public boolean isInline() throws DOMException {
return false;
}
public boolean isMutable() throws DOMException {
return false;
}
public IScope getFunctionScope() throws DOMException {
return asScope();
}
public IParameter[] getParameters() throws DOMException {
return IParameter.EMPTY_PARAMETER_ARRAY;
}
public IFunctionType getType() throws DOMException {
if (fType == null) {
fType= new CPPUnknownFunctionType();
}
return fType;
}
public boolean isAuto() throws DOMException {
return false;
}
public boolean isExtern() throws DOMException {
return false;
}
public boolean isRegister() throws DOMException {
return false;
}
public boolean isStatic() throws DOMException {
return false;
}
public boolean takesVarArgs() throws DOMException {
return false;
}
}

View file

@ -0,0 +1,22 @@
/*******************************************************************************
* Copyright (c) 2008 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
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Markus Schorn - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ast.IType;
/**
* Models the type of an unknown function.
*/
public class CPPUnknownFunctionType extends CPPFunctionType implements ICPPUnknownType {
CPPUnknownFunctionType() {
super(CPPUnknownClass.createUnnamedInstance(), IType.EMPTY_TYPE_ARRAY);
}
}

View file

@ -16,19 +16,21 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.IName; import org.eclipse.cdt.core.dom.IName;
import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.EScopeKind; import org.eclipse.cdt.core.dom.ast.EScopeKind;
import org.eclipse.cdt.core.dom.ast.IASTFunctionCallExpression;
import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorChainInitializer;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamedTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateId; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateId;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding; import org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding;
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.ICPPTemplateArgument; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier;
import org.eclipse.cdt.core.index.IIndexFileSet; import org.eclipse.cdt.core.index.IIndexFileSet;
import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.core.parser.util.CharArrayObjectMap; import org.eclipse.cdt.core.parser.util.CharArrayObjectMap;
import org.eclipse.cdt.core.parser.util.CharArrayUtils; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPSemantics;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPTemplates;
/** /**
* Models the scope represented by an unknown binding such (e.g.: template type parameter). Used within * Models the scope represented by an unknown binding such (e.g.: template type parameter). Used within
@ -100,55 +102,68 @@ public class CPPUnknownScope implements ICPPScope, ICPPInternalUnknownScope {
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IScope#getBinding(org.eclipse.cdt.core.dom.ast.IASTName, boolean) * @see org.eclipse.cdt.core.dom.ast.IScope#getBinding(org.eclipse.cdt.core.dom.ast.IASTName, boolean)
*/ */
public IBinding getBinding(IASTName name, boolean resolve, IIndexFileSet fileSet) { public IBinding getBinding(final IASTName name, boolean resolve, IIndexFileSet fileSet) {
if (map == null) boolean type= false;
map = new CharArrayObjectMap(2); boolean function= false;
char[] c = name.toCharArray(); if (name.getPropertyInParent() == CPPSemantics.STRING_LOOKUP_PROPERTY) {
if (map.containsKey(c)) { type= true;
return (IBinding) map.get(c); } else {
} IASTName n= name;
IBinding b;
IASTNode parent= name.getParent(); IASTNode parent= name.getParent();
if (parent instanceof ICPPASTTemplateId) { if (parent instanceof ICPPASTTemplateId) {
try { n= (IASTName) parent;
ICPPTemplateArgument[] arguments = CPPTemplates.createTemplateArgumentArray((ICPPASTTemplateId) parent); parent= n.getParent();
b = new CPPUnknownClassInstance(binding, name, arguments);
} catch (DOMException e) {
return e.getProblem();
} }
if (parent instanceof ICPPASTQualifiedName) {
ICPPASTQualifiedName qname= (ICPPASTQualifiedName) parent;
if (qname.getLastName() != n) {
type= true;
} else { } else {
b = new CPPUnknownClass(binding, name); parent= qname.getParent();
}
}
if (!type) {
if (parent instanceof ICPPASTNamedTypeSpecifier ||
parent instanceof ICPPASTBaseSpecifier ||
parent instanceof ICPPASTConstructorChainInitializer) {
type= true;
} else if (parent.getPropertyInParent() == IASTFunctionCallExpression.FUNCTION_NAME) {
function= true;
}
}
} }
name.setBinding(b);
map.put(c, b);
return b;
}
public IBinding[] getBindings(IASTName name, boolean resolve, boolean prefixLookup,
IIndexFileSet fileSet) {
if (map == null) if (map == null)
map = new CharArrayObjectMap(2); map = new CharArrayObjectMap(2);
char[] c = name.toCharArray(); char[] c = name.toCharArray();
IBinding[] o= (IBinding[]) map.get(c);
if (o == null) {
o= new IBinding[3];
map.put(c, o);
}
IBinding[] result = null; int idx= type ? 0 : function ? 1 : 2;
if (prefixLookup) { IBinding result= o[idx];
Object[] keys = map.keyArray(); if (result == null) {
for (Object key2 : keys) { if (type) {
char[] key = (char[]) key2; result= new CPPUnknownClass(binding, name.getLastName());
if (CharArrayUtils.equals(key, 0, c.length, c, true)) { } else if (function) {
result = (IBinding[]) ArrayUtil.append(IBinding.class, result, map.get(key)); result= new CPPUnknownFunction(binding, name.getLastName());
}
}
} else { } else {
result = new IBinding[] { (IBinding) map.get(c) }; result= new CPPUnknownBinding(binding, name.getLastName());
}
o[idx]= result;
}
return result;
} }
result = (IBinding[]) ArrayUtil.trim(IBinding.class, result); public IBinding[] getBindings(IASTName name, boolean resolve, boolean prefixLookup, IIndexFileSet fileSet) {
return result; if (prefixLookup)
return IBinding.EMPTY_BINDING_ARRAY;
return new IBinding[] {getBinding(name, resolve, fileSet)};
} }
/* (non-Javadoc) /* (non-Javadoc)

View file

@ -12,15 +12,23 @@
package org.eclipse.cdt.internal.core.dom.parser.cpp; package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassTemplate; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassTemplate;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPDeferredTemplateInstance; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameterMap;
/** /**
* Interface for deferred class template instances. * Interface for deferred class template instances.
*/ */
public interface ICPPDeferredClassInstance extends ICPPUnknownClassType, ICPPDeferredTemplateInstance { public interface ICPPDeferredClassInstance extends ICPPUnknownClassType, ICPPTemplateInstance {
/** /**
* Returns the class template for the deferred instantiation. * Returns the class template for the deferred instantiation.
*/ */
ICPPClassTemplate getClassTemplate(); ICPPClassTemplate getClassTemplate();
/**
* Returns an empty map, because template parameters cannot be mapped until
* all of the arguments are resolved.
* @since 5.1
*/
public ICPPTemplateParameterMap getTemplateParameterMap();
} }

View file

@ -24,7 +24,7 @@ public interface ICPPUnknownBinding extends ICPPBinding {
* Returns the scope this binding represents. * Returns the scope this binding represents.
* @throws DOMException * @throws DOMException
*/ */
public ICPPScope getUnknownScope() throws DOMException; public ICPPScope asScope() throws DOMException;
/** /**
* Returns a the name of the unknown binding that has to be searched in the parent scope. * Returns a the name of the unknown binding that has to be searched in the parent scope.

View file

@ -19,6 +19,6 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
* This interface should be made public. * This interface should be made public.
* @since 5.0 * @since 5.0
*/ */
public interface ICPPUnknownClassType extends ICPPUnknownBinding, ICPPClassType { public interface ICPPUnknownClassType extends ICPPUnknownBinding, ICPPUnknownType, ICPPClassType {
} }

View file

@ -0,0 +1,20 @@
/*******************************************************************************
* Copyright (c) 2008 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
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Markus Schorn - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ast.IType;
/**
* Marks types that depend on a template parameter and are thus unknown.
*/
public interface ICPPUnknownType extends IType {
}

View file

@ -100,7 +100,6 @@ 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.ICPPClassTemplatePartialSpecialization;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType; 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.ICPPConstructor;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPDeferredTemplateInstance;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction; 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.ICPPFunctionTemplate;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionType;
@ -144,13 +143,16 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPNamespace;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPQualifierType; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPQualifierType;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPReferenceType; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPReferenceType;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPScope; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPScope;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPUnknownScope; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPUnknownBinding;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPUnknownFunction;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPUsingDeclaration; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPUsingDeclaration;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPUsingDirective; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPUsingDirective;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVariable; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVariable;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPDeferredClassInstance; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPDeferredClassInstance;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBinding; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBinding;
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.ICPPUnknownType;
import org.eclipse.cdt.internal.core.dom.parser.cpp.OverloadableOperator; import org.eclipse.cdt.internal.core.dom.parser.cpp.OverloadableOperator;
import org.eclipse.cdt.internal.core.index.IIndexScope; import org.eclipse.cdt.internal.core.index.IIndexScope;
@ -303,7 +305,7 @@ public class CPPSemantics {
ICPPASTTemplateId id = (ICPPASTTemplateId) data.astName; ICPPASTTemplateId id = (ICPPASTTemplateId) data.astName;
ICPPTemplateArgument[] args = CPPTemplates.createTemplateArgumentArray(id); ICPPTemplateArgument[] args = CPPTemplates.createTemplateArgumentArray(id);
IBinding inst= CPPTemplates.instantiate((ICPPClassTemplate) cls, args); IBinding inst= CPPTemplates.instantiate((ICPPClassTemplate) cls, args);
cls = inst instanceof ICPPClassType && !(inst instanceof ICPPDeferredTemplateInstance) ? (ICPPClassType)inst : cls; cls = inst instanceof ICPPClassType && !(inst instanceof ICPPDeferredClassInstance) ? (ICPPClassType)inst : cls;
} }
} }
if (cls != null) { if (cls != null) {
@ -339,8 +341,12 @@ public class CPPSemantics {
} }
// if the lookup in base-classes ran into a deferred instance, use the computed unknown binding. // if the lookup in base-classes ran into a deferred instance, use the computed unknown binding.
if (binding == null && data.unknownBinding != null) { if (binding == null && data.skippedScope != null) {
binding= data.unknownBinding; if (data.functionParameters != null) {
binding= new CPPUnknownFunction(data.skippedScope, name.getLastName());
} else {
binding= new CPPUnknownBinding(data.skippedScope, name.getLastName());
}
} }
if (binding != null) { if (binding != null) {
@ -737,7 +743,7 @@ public class CPPSemantics {
} }
if (!data.usingDirectivesOnly && scope instanceof ICPPClassScope) { if (!data.usingDirectivesOnly && scope instanceof ICPPClassScope) {
mergeResults(data, lookupInParents(data, scope), true); mergeResults(data, lookupInParents(data, scope, ((ICPPClassScope) scope).getClassType()), true);
} }
if (!data.contentAssist && (data.problem != null || data.hasResults())) if (!data.contentAssist && (data.problem != null || data.hasResults()))
@ -794,7 +800,7 @@ public class CPPSemantics {
return (ICPPScope) parentScope; return (ICPPScope) parentScope;
} }
private static Object lookupInParents(LookupData data, ICPPScope lookIn) throws DOMException{ private static Object lookupInParents(LookupData data, ICPPScope lookIn, ICPPClassType overallScope) throws DOMException{
if (lookIn instanceof ICPPClassScope == false) if (lookIn instanceof ICPPClassScope == false)
return null; return null;
@ -826,44 +832,46 @@ public class CPPSemantics {
continue; continue;
IBinding b = base.getBaseClass(); IBinding b = base.getBaseClass();
if (b instanceof ICPPClassType == false) if (!(b instanceof ICPPClassType)) {
// 14.6.2.3 scope is not examined
if (b instanceof ICPPUnknownBinding) {
if (data.skippedScope == null)
data.skippedScope= overallScope;
}
continue; continue;
}
inherited = null; inherited = null;
final ICPPClassType cls = (ICPPClassType) b; final ICPPClassType cls = (ICPPClassType) b;
if (cls instanceof ICPPUnknownBinding) { final ICPPScope classScope = (ICPPScope) cls.getCompositeScope();
if (data.unknownBinding == null) { if (classScope == null || classScope instanceof ICPPInternalUnknownScope) {
data.unknownBinding= cls; // 14.6.2.3 scope is not examined
} if (data.skippedScope == null)
data.skippedScope= overallScope;
continue; continue;
} }
if (!base.isVirtual() || !data.visited.containsKey(classScope)) {
final ICPPScope parent = (ICPPScope) cls.getCompositeScope();
if (parent == null || parent instanceof CPPUnknownScope)
continue;
if (!base.isVirtual() || !data.visited.containsKey(parent)) {
if (base.isVirtual()) { if (base.isVirtual()) {
data.visited.put(parent); data.visited.put(classScope);
} }
//if the inheritanceChain already contains the parent, then that //if the inheritanceChain already contains the parent, then that
//is circular inheritance //is circular inheritance
if (!data.inheritanceChain.containsKey(parent)) { if (!data.inheritanceChain.containsKey(classScope)) {
//is this name define in this scope? //is this name define in this scope?
if (ASTInternal.isFullyCached(parent)) { if (ASTInternal.isFullyCached(classScope)) {
if (data.astName != null && !data.contentAssist) { if (data.astName != null && !data.contentAssist) {
inherited = parent.getBinding(data.astName, true); inherited = classScope.getBinding(data.astName, true);
} else if (data.astName != null) { } else if (data.astName != null) {
inherited = parent.getBindings(data.astName, true, data.prefixLookup); inherited = classScope.getBindings(data.astName, true, data.prefixLookup);
} }
} else { } else {
inherited = lookupInScope(data, parent, null); inherited = lookupInScope(data, classScope, null);
} }
if (inherited == null || data.contentAssist) { if (inherited == null || data.contentAssist) {
Object temp = lookupInParents(data, parent); Object temp = lookupInParents(data, classScope, overallScope);
if (inherited != null) { if (inherited != null) {
inherited = mergePrefixResults(null, inherited, true); inherited = mergePrefixResults(null, inherited, true);
inherited = mergePrefixResults((CharArrayObjectMap)inherited, (CharArrayObjectMap)temp, true); inherited = mergePrefixResults((CharArrayObjectMap)inherited, (CharArrayObjectMap)temp, true);
@ -1863,6 +1871,13 @@ public class CPPSemantics {
functions[i]= null; functions[i]= null;
continue; continue;
} }
if (function instanceof ICPPUnknownBinding) {
if (def) {
functions[i]= null;
}
continue;
}
num = function.getParameters().length; num = function.getParameters().length;
// if there are m arguments in the list, all candidate functions having m parameters // if there are m arguments in the list, all candidate functions having m parameters
@ -1981,21 +1996,27 @@ public class CPPSemantics {
// Reduce our set of candidate functions to only those who have the right number of parameters // Reduce our set of candidate functions to only those who have the right number of parameters
reduceToViable(data, fns); reduceToViable(data, fns);
// deferred function instances cannot be disambiguated. int viableCount= 0;
boolean deferredOnly= true; IFunction firstViable= null;
for (int i = 0; deferredOnly && i < fns.length; i++) { for (IFunction f : fns) {
final IFunction f = fns[i]; if (f != null) {
if (f != null && !(f instanceof ICPPDeferredTemplateInstance)) { if (++viableCount == 1) {
deferredOnly= false; firstViable= f;
} }
} }
if (deferredOnly || data.forFunctionDeclaration()) {
for (IFunction fn : fns) {
if (fn != null) {
return fn;
}
} }
if (firstViable == null)
return null; return null;
if (data.forFunctionDeclaration())
return firstViable;
final IType[] sourceParameters = getSourceParameterTypes(data.functionParameters); // the parameters the function is being called with
if (CPPTemplates.containsDependentType(sourceParameters)) {
if (viableCount == 1)
return firstViable;
return CPPUnknownFunction.createForSample(firstViable, data.astName);
} }
IFunction bestFn = null; // the best function IFunction bestFn = null; // the best function
@ -2016,7 +2037,6 @@ public class CPPSemantics {
boolean currHasAmbiguousParam = false; // currFn has an ambiguous parameter conversion (ok if not bestFn) boolean currHasAmbiguousParam = false; // currFn has an ambiguous parameter conversion (ok if not bestFn)
boolean bestHasAmbiguousParam = false; // bestFn has an ambiguous parameter conversion (not ok, ambiguous) boolean bestHasAmbiguousParam = false; // bestFn has an ambiguous parameter conversion (not ok, ambiguous)
final IType[] sourceParameters = getSourceParameterTypes(data.functionParameters); // the parameters the function is being called with
final boolean sourceVoid = (data.functionParameters == null || data.functionParameters.length == 0); final boolean sourceVoid = (data.functionParameters == null || data.functionParameters.length == 0);
final IType impliedObjectType = data.getImpliedObjectArgument(); final IType impliedObjectType = data.getImpliedObjectArgument();
@ -2400,7 +2420,7 @@ public class CPPSemantics {
IASTExpression owner = fieldReference.getFieldOwner(); IASTExpression owner = fieldReference.getFieldOwner();
IType result= CPPVisitor.getExpressionType(owner); IType result= CPPVisitor.getExpressionType(owner);
if (fieldReference.isPointerDereference()) { if (fieldReference.isPointerDereference() && !(result instanceof ICPPUnknownType)) {
IType type= getUltimateTypeUptoPointers(result); IType type= getUltimateTypeUptoPointers(result);
boolean needCheckClassMemberAccessOperator= true; boolean needCheckClassMemberAccessOperator= true;
if (type instanceof IPointerType) { if (type instanceof IPointerType) {

View file

@ -103,7 +103,6 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPConstructorInstance;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPConstructorSpecialization; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPConstructorSpecialization;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPConstructorTemplateSpecialization; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPConstructorTemplateSpecialization;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPDeferredClassInstance; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPDeferredClassInstance;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPDeferredFunctionInstance;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPFieldSpecialization; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPFieldSpecialization;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPFunctionInstance; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPFunctionInstance;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPFunctionSpecialization; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPFunctionSpecialization;
@ -126,6 +125,7 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateTypeParameter;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTypedefSpecialization; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTypedefSpecialization;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPUnknownClass; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPUnknownClass;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPUnknownClassInstance; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPUnknownClassInstance;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPUnknownFunction;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPASTInternalTemplateDeclaration; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPASTInternalTemplateDeclaration;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPClassSpecializationScope; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPClassSpecializationScope;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPDeferredClassInstance; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPDeferredClassInstance;
@ -135,6 +135,7 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalClassTemplate;
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;
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.dom.parser.cpp.ICPPUnknownType;
/** /**
* Collection of static methods to perform template instantiation, member specialization and * Collection of static methods to perform template instantiation, member specialization and
@ -312,70 +313,25 @@ public class CPPTemplates {
private static IBinding instantiateFunctionTemplate(ICPPFunctionTemplate template, ICPPTemplateArgument[] arguments) private static IBinding instantiateFunctionTemplate(ICPPFunctionTemplate template, ICPPTemplateArgument[] arguments)
throws DOMException { throws DOMException {
ICPPTemplateParameter[] parameters= template.getTemplateParameters();
if (parameters == null || parameters.length == 0)
return null;
final int numParams= parameters.length;
int numArgs = arguments.length;
CPPTemplateParameterMap map = new CPPTemplateParameterMap(numParams);
ICPPTemplateParameter param = null;
ICPPTemplateArgument arg = null;
ICPPTemplateArgument[] actualArgs = new ICPPTemplateArgument[numParams];
boolean argsContainDependentType = false;
for (int i = 0; i < numParams; i++) {
arg= null;
param= parameters[i];
if (i < numArgs) {
arg= arguments[i];
} else {
ICPPTemplateArgument defaultArg= param.getDefaultValue();
if (defaultArg == null) {
return null;
}
arg= instantiateArgument(defaultArg, map, null);
}
arg= CPPTemplates.matchTemplateParameterAndArgument(param, arg, map);
if (arg == null)
return null;
if (!argIsParameter(arg, param)) {
map.put(param, arg);
}
actualArgs[i] = arg;
if (CPPTemplates.isDependentArgument(arg)) {
argsContainDependentType = true;
}
}
if (argsContainDependentType) {
return deferredInstance(template, actualArgs);
}
ICPPTemplateInstance instance= getInstance(template, arguments); ICPPTemplateInstance instance= getInstance(template, arguments);
if (instance != null) { if (instance != null) {
return instance; return instance;
} }
IBinding owner= template.getOwner(); final int length = arguments.length;
instance = CPPTemplates.createInstance(owner, template, map, actualArgs); ICPPTemplateParameter[] parameters= template.getTemplateParameters();
addInstance(template, actualArgs, instance); if (parameters.length != length)
return instance; return null;
CPPTemplateParameterMap map = new CPPTemplateParameterMap(length);
for (int i = 0; i < length; i++) {
map.put(parameters[i], arguments[i]);
} }
private static boolean argIsParameter(ICPPTemplateArgument arg, ICPPTemplateParameter param) { IBinding owner= template.getOwner();
if (param instanceof ICPPTemplateNonTypeParameter) { instance = CPPTemplates.createInstance(owner, template, map, arguments);
return arg.isNonTypeValue() && Value.isTemplateParameter(arg.getNonTypeValue()) == param.getParameterID(); addInstance(template, arguments, instance);
} return instance;
if (param instanceof IType) {
return arg.isTypeValue() && ((IType) param).isSameType(arg.getTypeValue());
}
assert false;
return false;
} }
/** /**
@ -397,23 +353,15 @@ public class CPPTemplates {
} }
} }
private static IBinding deferredInstance(ICPPTemplateDefinition template, ICPPTemplateArgument[] arguments) throws DOMException { private static IBinding deferredInstance(ICPPClassTemplate template, ICPPTemplateArgument[] arguments) throws DOMException {
ICPPTemplateInstance instance= getInstance(template, arguments); ICPPTemplateInstance instance= getInstance(template, arguments);
if (instance != null) if (instance != null)
return instance; return instance;
if (template instanceof ICPPClassTemplate) { instance = new CPPDeferredClassInstance(template, arguments);
instance = new CPPDeferredClassInstance((ICPPClassTemplate) template, arguments);
addInstance(template, arguments, instance); addInstance(template, arguments, instance);
return instance; return instance;
} }
if (template instanceof ICPPFunctionTemplate) {
instance = new CPPDeferredFunctionInstance((ICPPFunctionTemplate) template, arguments);
addInstance(template, arguments, instance);
return instance;
}
return null;
}
/** /**
* Instantiates the template for usage within its own body. May return <code>null</code>. * Instantiates the template for usage within its own body. May return <code>null</code>.
@ -603,15 +551,19 @@ public class CPPTemplates {
IBinding result= null; IBinding result= null;
IASTName templateName = id.getTemplateName(); IASTName templateName = id.getTemplateName();
IBinding template = templateName.resolveBinding(); IBinding template = templateName.resolveBinding();
if (template instanceof ICPPUnknownClassInstance) {
// mstodo we should not get here, rather than that an unknown class
// should be made to an unknown class instance here
return template;
}
if (template instanceof ICPPConstructor) { if (template instanceof ICPPConstructor) {
template= template.getOwner(); template= template.getOwner();
} }
if (template instanceof ICPPUnknownClassType) {
IBinding owner= template.getOwner();
if (owner instanceof ICPPUnknownBinding) {
ICPPTemplateArgument[] args= createTemplateArgumentArray(id);
return new CPPUnknownClassInstance((ICPPUnknownBinding) template.getOwner(), id, args);
}
}
if (!(template instanceof ICPPClassTemplate) || template instanceof ICPPClassTemplatePartialSpecialization) if (!(template instanceof ICPPClassTemplate) || template instanceof ICPPClassTemplatePartialSpecialization)
return new ProblemBinding(id, IProblemBinding.SEMANTIC_INVALID_TYPE, templateName.toCharArray()); return new ProblemBinding(id, IProblemBinding.SEMANTIC_INVALID_TYPE, templateName.toCharArray());
@ -698,6 +650,7 @@ public class CPPTemplates {
if (tmplArg == null) if (tmplArg == null)
return null; return null;
tmplArg= SemanticUtil.getSimplifiedArgument(tmplArg);
map.put(tmplParam, tmplArg); map.put(tmplParam, tmplArg);
result[i]= tmplArg; result[i]= tmplArg;
} }
@ -1423,14 +1376,19 @@ public class CPPTemplates {
return null; return null;
ICPPTemplateArgument[] templateArguments = ICPPTemplateArgument.EMPTY_ARGUMENTS; ICPPTemplateArgument[] templateArguments = ICPPTemplateArgument.EMPTY_ARGUMENTS;
if (name instanceof ICPPASTTemplateId) { final IType[] fnArgs= createTypeArray(functionArguments);
try { try {
if (containsDependentType(fnArgs))
return new IFunction[] {CPPUnknownFunction.createForSample(templates.keyAt(0), name)};
if (name instanceof ICPPASTTemplateId) {
templateArguments = createTemplateArgumentArray((ICPPASTTemplateId) name); templateArguments = createTemplateArgumentArray((ICPPASTTemplateId) name);
if (hasDependentArgument(templateArguments))
return new IFunction[] {CPPUnknownFunction.createForSample(templates.keyAt(0), name)};
}
} catch (DOMException e) { } catch (DOMException e) {
return new IFunction[0]; return new IFunction[0];
} }
}
final IType[] fnArgs= createTypeArray(functionArguments);
IFunction[] instances= null; IFunction[] instances= null;
final int size = templates.size(); final int size = templates.size();
@ -2042,18 +2000,24 @@ public class CPPTemplates {
return Value.isDependentValue(arg.getNonTypeValue()); return Value.isDependentValue(arg.getNonTypeValue());
} }
public static boolean containsDependentType(IType[] ts) {
for (IType t : ts) {
if (isDependentType(t))
return true;
}
return false;
}
public static boolean isDependentType(IType t) { public static boolean isDependentType(IType t) {
try { try {
while (true) { while (true) {
if (t instanceof ICPPTemplateParameter || t instanceof ICPPUnknownBinding) if (t instanceof ICPPUnknownType)
return true; return true;
if (t instanceof ICPPFunctionType) { if (t instanceof ICPPFunctionType) {
final ICPPFunctionType ft = (ICPPFunctionType) t; final ICPPFunctionType ft = (ICPPFunctionType) t;
IType[] types= ft.getParameterTypes(); if (containsDependentType(ft.getParameterTypes()))
for (IType type : types) {
if (isDependentType(type))
return true; return true;
}
t= ft.getReturnType(); t= ft.getReturnType();
} else if (t instanceof ICPPPointerToMemberType) { } else if (t instanceof ICPPPointerToMemberType) {
ICPPPointerToMemberType ptmt= (ICPPPointerToMemberType) t; ICPPPointerToMemberType ptmt= (ICPPPointerToMemberType) t;
@ -2132,10 +2096,8 @@ public class CPPTemplates {
} }
if (unknown instanceof ICPPUnknownClassInstance && result instanceof ICPPTemplateDefinition) { if (unknown instanceof ICPPUnknownClassInstance && result instanceof ICPPTemplateDefinition) {
ICPPTemplateArgument[] newArgs = CPPTemplates.instantiateArguments(((ICPPUnknownClassInstance) unknown).getArguments(), tpMap, within); ICPPTemplateArgument[] newArgs = CPPTemplates.instantiateArguments(((ICPPUnknownClassInstance) unknown).getArguments(), tpMap, within);
if (result instanceof ICPPClassTemplate) if (result instanceof ICPPClassTemplate) {
result = instantiate((ICPPClassTemplate) result, newArgs); result = instantiate((ICPPClassTemplate) result, newArgs);
else if (result instanceof ICPPFunctionTemplate) {
result= instantiateFunctionTemplate((ICPPFunctionTemplate) result, newArgs);
} }
} }
} }

View file

@ -173,6 +173,7 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPQualifierType;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPReferenceType; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPReferenceType;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPScope; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPScope;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTypedef; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTypedef;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPUnknownClass;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVariable; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVariable;
import org.eclipse.cdt.internal.core.dom.parser.cpp.GPPBasicType; import org.eclipse.cdt.internal.core.dom.parser.cpp.GPPBasicType;
import org.eclipse.cdt.internal.core.dom.parser.cpp.GPPPointerToMemberType; import org.eclipse.cdt.internal.core.dom.parser.cpp.GPPPointerToMemberType;
@ -946,7 +947,7 @@ public class CPPVisitor extends ASTQueries {
} else if (binding instanceof ICPPNamespace) { } else if (binding instanceof ICPPNamespace) {
scope= ((ICPPNamespace)binding).getNamespaceScope(); scope= ((ICPPNamespace)binding).getNamespaceScope();
} else if (binding instanceof ICPPUnknownBinding) { } else if (binding instanceof ICPPUnknownBinding) {
scope= ((ICPPUnknownBinding)binding).getUnknownScope(); scope= ((ICPPUnknownBinding)binding).asScope();
} else if (binding instanceof IProblemBinding) { } else if (binding instanceof IProblemBinding) {
if (binding instanceof ICPPScope) if (binding instanceof ICPPScope)
scope= (IScope) binding; scope= (IScope) binding;
@ -971,6 +972,8 @@ public class CPPVisitor extends ASTQueries {
} }
if (type instanceof ICPPClassType) { if (type instanceof ICPPClassType) {
return ((ICPPClassType) type).getCompositeScope(); return ((ICPPClassType) type).getCompositeScope();
} else if (type instanceof ICPPUnknownBinding) {
return ((ICPPUnknownBinding) type).asScope();
} }
} else if (parent instanceof IASTGotoStatement || parent instanceof IASTLabelStatement) { } else if (parent instanceof IASTGotoStatement || parent instanceof IASTLabelStatement) {
while (!(parent instanceof IASTFunctionDefinition)) { while (!(parent instanceof IASTFunctionDefinition)) {
@ -1786,6 +1789,8 @@ public class CPPVisitor extends ASTQueries {
return ((ICPPTemplateNonTypeParameter) binding).getType(); return ((ICPPTemplateNonTypeParameter) binding).getType();
} else if (binding instanceof ICPPClassType) { } else if (binding instanceof ICPPClassType) {
return ((ICPPClassType) binding); return ((ICPPClassType) binding);
} else if (binding instanceof ICPPUnknownBinding) {
return CPPUnknownClass.createUnnamedInstance();
} }
} catch (DOMException e) { } catch (DOMException e) {
return e.getProblem(); return e.getProblem();
@ -2004,6 +2009,8 @@ public class CPPVisitor extends ASTQueries {
return ((IFunction)binding).getType(); return ((IFunction)binding).getType();
else if (binding instanceof IEnumerator) else if (binding instanceof IEnumerator)
return ((IEnumerator)binding).getType(); return ((IEnumerator)binding).getType();
else if (binding instanceof ICPPUnknownBinding)
return CPPUnknownClass.createUnnamedInstance();
} catch (DOMException e) { } catch (DOMException e) {
return e.getProblem(); return e.getProblem();
} }

View file

@ -33,7 +33,6 @@ import org.eclipse.cdt.core.dom.ast.IASTNamedTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration; import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTTypeId; import org.eclipse.cdt.core.dom.ast.IASTTypeId;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IPointerType; import org.eclipse.cdt.core.dom.ast.IPointerType;
import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.IType;
@ -56,6 +55,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTUnaryExpression;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTUsingDeclaration; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTUsingDeclaration;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTUsingDirective; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTUsingDirective;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassScope; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceScope; import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier;
import org.eclipse.cdt.core.parser.util.CharArrayObjectMap; import org.eclipse.cdt.core.parser.util.CharArrayObjectMap;
@ -95,7 +95,7 @@ class LookupData {
public boolean typesOnly = false; public boolean typesOnly = false;
public boolean considerConstructors = false; public boolean considerConstructors = false;
public IBinding unknownBinding= null; public ICPPClassType skippedScope;
public Object foundItems = null; public Object foundItems = null;
public Object[] functionParameters; public Object[] functionParameters;
public ICPPASTTemplateId templateId; public ICPPASTTemplateId templateId;

View file

@ -38,7 +38,6 @@ public interface IIndexCPPBindingConstants {
int CPP_FUNCTION_INSTANCE= IIndexBindingConstants.LAST_CONSTANT + 21; int CPP_FUNCTION_INSTANCE= IIndexBindingConstants.LAST_CONSTANT + 21;
int CPP_METHOD_INSTANCE= IIndexBindingConstants.LAST_CONSTANT + 22; int CPP_METHOD_INSTANCE= IIndexBindingConstants.LAST_CONSTANT + 22;
int CPP_CONSTRUCTOR_INSTANCE= IIndexBindingConstants.LAST_CONSTANT + 23; int CPP_CONSTRUCTOR_INSTANCE= IIndexBindingConstants.LAST_CONSTANT + 23;
int CPP_DEFERRED_FUNCTION_INSTANCE= IIndexBindingConstants.LAST_CONSTANT + 24;
int CPP_CLASS_INSTANCE= IIndexBindingConstants.LAST_CONSTANT + 25; int CPP_CLASS_INSTANCE= IIndexBindingConstants.LAST_CONSTANT + 25;
int CPP_DEFERRED_CLASS_INSTANCE= IIndexBindingConstants.LAST_CONSTANT + 26; int CPP_DEFERRED_CLASS_INSTANCE= IIndexBindingConstants.LAST_CONSTANT + 26;
int CPP_PARAMETER_SPECIALIZATION= IIndexBindingConstants.LAST_CONSTANT + 27; int CPP_PARAMETER_SPECIALIZATION= IIndexBindingConstants.LAST_CONSTANT + 27;

View file

@ -29,7 +29,6 @@ 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.ICPPClassTemplatePartialSpecialization;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType; 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.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.ICPPField;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction; 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.ICPPFunctionTemplate;
@ -183,14 +182,8 @@ public class CPPCompositesFactory extends AbstractCompositeFactory {
result = null; result = null;
} else if (binding instanceof ICPPSpecialization) { } else if (binding instanceof ICPPSpecialization) {
if (binding instanceof ICPPTemplateInstance) { if (binding instanceof ICPPTemplateInstance) {
if (binding instanceof ICPPDeferredTemplateInstance) {
if (binding instanceof ICPPDeferredClassInstance) { if (binding instanceof ICPPDeferredClassInstance) {
return new CompositeCPPDeferredClassInstance(this, (ICPPDeferredClassInstance) findOneBinding(binding)); return new CompositeCPPDeferredClassInstance(this, (ICPPDeferredClassInstance) findOneBinding(binding));
} else if (binding instanceof ICPPFunction) {
return new CompositeCPPDeferredFunctionInstance(this, (ICPPFunction) binding);
} else {
throw new CompositingNotImplementedError("composite binding unavailable for "+binding+" "+binding.getClass()); //$NON-NLS-1$ //$NON-NLS-2$
}
} else { } else {
if (binding instanceof ICPPClassType) { if (binding instanceof ICPPClassType) {
return new CompositeCPPClassInstance(this, (ICPPClassType) findOneBinding(binding)); return new CompositeCPPClassInstance(this, (ICPPClassType) findOneBinding(binding));

View file

@ -57,7 +57,7 @@ public class CompositeCPPDeferredClassInstance extends CompositeCPPClassType imp
return ((ICPPDeferredClassInstance) rbinding).getUnknownName(); return ((ICPPDeferredClassInstance) rbinding).getUnknownName();
} }
public ICPPScope getUnknownScope() throws DOMException { public ICPPScope asScope() throws DOMException {
if (unknownScope == null) { if (unknownScope == null) {
unknownScope= new CompositeCPPUnknownScope(this, getUnknownName()); unknownScope= new CompositeCPPUnknownScope(this, getUnknownName());
} }

View file

@ -1,57 +0,0 @@
/*******************************************************************************
* Copyright (c) 2007, 2008 Symbian 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
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Andrew Ferguson (Symbian) - Initial implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.internal.core.index.composite.cpp;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPDeferredTemplateInstance;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateArgument;
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.ICPPTemplateParameterMap;
import org.eclipse.cdt.core.parser.util.ObjectMap;
import org.eclipse.cdt.internal.core.index.composite.ICompositesFactory;
public class CompositeCPPDeferredFunctionInstance extends CompositeCPPFunction
implements ICPPDeferredTemplateInstance {
public CompositeCPPDeferredFunctionInstance(ICompositesFactory cf, ICPPFunction rbinding) {
super(cf, rbinding);
}
public ICPPTemplateDefinition getTemplateDefinition() {
return TemplateInstanceUtil.getTemplateDefinition(cf, rbinding);
}
public IBinding getSpecializedBinding() {
return TemplateInstanceUtil.getSpecializedBinding(cf, rbinding);
}
public ICPPTemplateArgument[] getTemplateArguments() {
return TemplateInstanceUtil.getTemplateArguments(cf, (ICPPTemplateInstance) rbinding);
}
public ICPPTemplateParameterMap getTemplateParameterMap() {
return TemplateInstanceUtil.getTemplateParameterMap(cf, (ICPPTemplateInstance) rbinding);
}
@Deprecated
public IType[] getArguments() {
return TemplateInstanceUtil.getArguments(cf, (ICPPTemplateInstance) rbinding);
}
@Deprecated
public ObjectMap getArgumentMap() {
return TemplateInstanceUtil.getArgumentMap(cf, rbinding);
}
}

View file

@ -20,11 +20,12 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateTypeParameter; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateTypeParameter;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTName; 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.dom.parser.cpp.ICPPUnknownType;
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;
public class CompositeCPPTemplateTypeParameter extends CompositeCPPBinding public class CompositeCPPTemplateTypeParameter extends CompositeCPPBinding
implements ICPPTemplateTypeParameter, ICPPUnknownBinding, IIndexType { implements ICPPTemplateTypeParameter, ICPPUnknownBinding, ICPPUnknownType, IIndexType {
private ICPPScope unknownScope; private ICPPScope unknownScope;
@ -58,7 +59,7 @@ public class CompositeCPPTemplateTypeParameter extends CompositeCPPBinding
fail(); return null; fail(); return null;
} }
public ICPPScope getUnknownScope() { public ICPPScope asScope() {
if (unknownScope == null) { if (unknownScope == null) {
unknownScope= new CompositeCPPUnknownScope(this, getUnknownName()); unknownScope= new CompositeCPPUnknownScope(this, getUnknownName());
} }

View file

@ -125,7 +125,7 @@ class CompositeCPPUnknownClassType extends CompositeCPPBinding implements ICPPUn
return ((ICPPClassType) rbinding).isSameType(type); return ((ICPPClassType) rbinding).isSameType(type);
} }
public ICPPScope getUnknownScope() { public ICPPScope asScope() {
if (unknownScope == null) { if (unknownScope == null) {
unknownScope= new CompositeCPPUnknownScope(this, getUnknownName()); unknownScope= new CompositeCPPUnknownScope(this, getUnknownName());
} }

View file

@ -39,7 +39,6 @@ import org.eclipse.cdt.core.dom.ast.ITypedef;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateId; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateId;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTUsingDirective; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTUsingDirective;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassTemplate; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassTemplate;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPDeferredTemplateInstance;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace; 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.ICPPNamespaceAlias;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter;
@ -47,6 +46,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBas
import org.eclipse.cdt.core.index.IIndexFileLocation; import org.eclipse.cdt.core.index.IIndexFileLocation;
import org.eclipse.cdt.core.parser.IProblem; import org.eclipse.cdt.core.parser.IProblem;
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.cpp.ICPPUnknownBinding;
import org.eclipse.cdt.internal.core.index.IIndexFragmentFile; import org.eclipse.cdt.internal.core.index.IIndexFragmentFile;
import org.eclipse.cdt.internal.core.index.IWritableIndex; import org.eclipse.cdt.internal.core.index.IWritableIndex;
import org.eclipse.cdt.internal.core.index.IWritableIndex.IncludeInformation; import org.eclipse.cdt.internal.core.index.IWritableIndex.IncludeInformation;
@ -251,7 +251,7 @@ abstract public class PDOMWriter {
} }
} else if (name.isReference()) { } else if (name.isReference()) {
if (binding instanceof ICPPTemplateParameter || if (binding instanceof ICPPTemplateParameter ||
binding instanceof ICPPDeferredTemplateInstance || binding instanceof ICPPUnknownBinding ||
((fSkipReferences & SKIP_TYPE_REFERENCES) != 0 && isTypeReferenceBinding(binding))) { ((fSkipReferences & SKIP_TYPE_REFERENCES) != 0 && isTypeReferenceBinding(binding))) {
if (!isRequiredReference(name)) { if (!isRequiredReference(name)) {
na[0]= null; na[0]= null;

View file

@ -205,7 +205,7 @@ public abstract class PDOMBinding extends PDOMNamedNode implements IPDOMBinding
if (parent instanceof ICPPClassType) { if (parent instanceof ICPPClassType) {
return (IIndexScope) ((ICPPClassType) parent).getCompositeScope(); return (IIndexScope) ((ICPPClassType) parent).getCompositeScope();
} else if (parent instanceof ICPPUnknownBinding) { } else if (parent instanceof ICPPUnknownBinding) {
return (IIndexScope) ((ICPPUnknownBinding) parent).getUnknownScope(); return (IIndexScope) ((ICPPUnknownBinding) parent).asScope();
} }
if (parent instanceof IIndexScope) { if (parent instanceof IIndexScope) {

View file

@ -170,7 +170,7 @@ class PDOMCPPDeferredClassInstance extends PDOMCPPSpecialization implements ICPP
@Override @Override
public Object clone() {fail();return null;} public Object clone() {fail();return null;}
public ICPPScope getUnknownScope() throws DOMException { public ICPPScope asScope() throws DOMException {
if (unknownScope == null) { if (unknownScope == null) {
unknownScope= new PDOMCPPUnknownScope(this, getUnknownName()); unknownScope= new PDOMCPPUnknownScope(this, getUnknownName());
} }

View file

@ -1,52 +0,0 @@
/*******************************************************************************
* Copyright (c) 2007 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
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* QNX - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.core.pdom.dom.cpp;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPDeferredTemplateInstance;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction;
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.PDOMNode;
import org.eclipse.core.runtime.CoreException;
/**
* @author Bryan Wilkinson
*
*/
class PDOMCPPDeferredFunctionInstance extends PDOMCPPFunctionInstance
implements ICPPDeferredTemplateInstance {
/**
* The size in bytes of a PDOMCPPDeferredFunctionInstance record in the database.
*/
@SuppressWarnings("hiding")
protected static final int RECORD_SIZE = PDOMCPPFunctionInstance.RECORD_SIZE + 0;
public PDOMCPPDeferredFunctionInstance(PDOM pdom, PDOMNode parent, ICPPFunction function, PDOMBinding instantiated)
throws CoreException {
super(pdom, parent, function, instantiated);
}
public PDOMCPPDeferredFunctionInstance(PDOM pdom, int bindingRecord) {
super(pdom, bindingRecord);
}
@Override
protected int getRecordSize() {
return RECORD_SIZE;
}
@Override
public int getNodeType() {
return IIndexCPPBindingConstants.CPP_DEFERRED_FUNCTION_INSTANCE;
}
}

View file

@ -44,7 +44,6 @@ 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.ICPPClassTemplatePartialSpecialization;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType; 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.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.ICPPField;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction; 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.ICPPFunctionTemplate;
@ -385,10 +384,8 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants {
private PDOMBinding createSpecialization(PDOMNode parent, PDOMBinding orig, IBinding special) throws CoreException { private PDOMBinding createSpecialization(PDOMNode parent, PDOMBinding orig, IBinding special) throws CoreException {
PDOMBinding result= null; PDOMBinding result= null;
if (special instanceof ICPPDeferredTemplateInstance) { if (special instanceof ICPPDeferredClassInstance) {
if (special instanceof ICPPFunction && orig instanceof ICPPFunctionTemplate) { if (orig instanceof ICPPClassTemplate) {
result= new PDOMCPPDeferredFunctionInstance(pdom, parent, (ICPPFunction) special, orig);
} else if (special instanceof ICPPDeferredClassInstance && orig instanceof ICPPClassTemplate) {
result= new PDOMCPPDeferredClassInstance(pdom, parent, (ICPPDeferredClassInstance) special, orig); result= new PDOMCPPDeferredClassInstance(pdom, parent, (ICPPDeferredClassInstance) special, orig);
} }
} else if (special instanceof ICPPTemplateInstance) { } else if (special instanceof ICPPTemplateInstance) {
@ -476,14 +473,10 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants {
@Override @Override
public int getBindingType(IBinding binding) { public int getBindingType(IBinding binding) {
if (binding instanceof ICPPSpecialization) { if (binding instanceof ICPPSpecialization) {
if (binding instanceof ICPPDeferredTemplateInstance) { if (binding instanceof ICPPTemplateInstance) {
if (binding instanceof ICPPFunction) { if (binding instanceof ICPPDeferredClassInstance) {
return CPP_DEFERRED_FUNCTION_INSTANCE;
} else if (binding instanceof ICPPClassType) {
return CPP_DEFERRED_CLASS_INSTANCE; return CPP_DEFERRED_CLASS_INSTANCE;
} } else if (binding instanceof ICPPConstructor) {
} else if (binding instanceof ICPPTemplateInstance) {
if (binding instanceof ICPPConstructor) {
return CPP_CONSTRUCTOR_INSTANCE; return CPP_CONSTRUCTOR_INSTANCE;
} else if (binding instanceof ICPPMethod) { } else if (binding instanceof ICPPMethod) {
return CPP_METHOD_INSTANCE; return CPP_METHOD_INSTANCE;
@ -800,8 +793,6 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants {
return new PDOMCPPMethodInstance(pdom, record); return new PDOMCPPMethodInstance(pdom, record);
case CPP_CONSTRUCTOR_INSTANCE: case CPP_CONSTRUCTOR_INSTANCE:
return new PDOMCPPConstructorInstance(pdom, record); return new PDOMCPPConstructorInstance(pdom, record);
case CPP_DEFERRED_FUNCTION_INSTANCE:
return new PDOMCPPDeferredFunctionInstance(pdom, record);
case CPP_CLASS_INSTANCE: case CPP_CLASS_INSTANCE:
return new PDOMCPPClassInstance(pdom, record); return new PDOMCPPClassInstance(pdom, record);
case CPP_DEFERRED_CLASS_INSTANCE: case CPP_DEFERRED_CLASS_INSTANCE:

View file

@ -26,6 +26,7 @@ import org.eclipse.cdt.internal.core.Util;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTName; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTName;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateArgument; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateArgument;
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.ICPPUnknownType;
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;
import org.eclipse.cdt.internal.core.pdom.PDOM; import org.eclipse.cdt.internal.core.pdom.PDOM;
@ -39,7 +40,7 @@ import org.eclipse.core.runtime.CoreException;
* Binding for template type parameters in the index. * Binding for template type parameters in the index.
*/ */
class PDOMCPPTemplateTypeParameter extends PDOMCPPBinding implements IPDOMMemberOwner, class PDOMCPPTemplateTypeParameter extends PDOMCPPBinding implements IPDOMMemberOwner,
ICPPTemplateTypeParameter, ICPPUnknownBinding, IIndexType { ICPPTemplateTypeParameter, ICPPUnknownBinding, ICPPUnknownType, IIndexType {
private static final int DEFAULT_TYPE = PDOMCPPBinding.RECORD_SIZE + 0; private static final int DEFAULT_TYPE = PDOMCPPBinding.RECORD_SIZE + 0;
private static final int MEMBERLIST = PDOMCPPBinding.RECORD_SIZE + 4; private static final int MEMBERLIST = PDOMCPPBinding.RECORD_SIZE + 4;
@ -161,7 +162,7 @@ class PDOMCPPTemplateTypeParameter extends PDOMCPPBinding implements IPDOMMember
public Object clone() { fail(); return null; } public Object clone() { fail(); return null; }
public ICPPScope getUnknownScope() { public ICPPScope asScope() {
if (fUnknownScope == null) { if (fUnknownScope == null) {
fUnknownScope= new PDOMCPPUnknownScope(this, new CPPASTName(getNameCharArray())); fUnknownScope= new PDOMCPPUnknownScope(this, new CPPASTName(getNameCharArray()));
} }

View file

@ -122,7 +122,7 @@ class PDOMCPPUnknownClassType extends PDOMCPPBinding implements ICPPClassScope,
return this; return this;
} }
public ICPPScope getUnknownScope() { public ICPPScope asScope() {
if (unknownScope == null) { if (unknownScope == null) {
unknownScope= new PDOMCPPUnknownScope(this, getUnknownName()); unknownScope= new PDOMCPPUnknownScope(this, getUnknownName());
} }

View file

@ -32,7 +32,6 @@ import org.eclipse.cdt.core.dom.ast.ITypedef;
import org.eclipse.cdt.core.dom.ast.IVariable; import org.eclipse.cdt.core.dom.ast.IVariable;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassTemplatePartialSpecialization; 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.ICPPClassType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPDeferredTemplateInstance;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace; import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization; import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateArgument; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateArgument;
@ -43,6 +42,7 @@ import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.model.ITranslationUnit; import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.ui.CUIPlugin; import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPDeferredClassInstance;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMLinkage; import org.eclipse.cdt.internal.core.pdom.dom.PDOMLinkage;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNamedNode; import org.eclipse.cdt.internal.core.pdom.dom.PDOMNamedNode;
@ -93,7 +93,7 @@ public class IndexLabelProvider extends LabelProvider {
if (element instanceof ICPPTemplateInstance) { if (element instanceof ICPPTemplateInstance) {
StringBuffer buffer = null; StringBuffer buffer = null;
if (element instanceof ICPPDeferredTemplateInstance) { if (element instanceof ICPPDeferredClassInstance) {
buffer = new StringBuffer("Dfrd: "); //$NON-NLS-1$ buffer = new StringBuffer("Dfrd: "); //$NON-NLS-1$
} else { } else {
buffer = new StringBuffer("Inst: "); //$NON-NLS-1$ buffer = new StringBuffer("Inst: "); //$NON-NLS-1$