mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-24 09:25:31 +02:00
Reworked parts of template instantiation, fixes bug 236197.
This commit is contained in:
parent
d548722c4e
commit
91778c287b
157 changed files with 3330 additions and 3980 deletions
|
@ -106,7 +106,7 @@ public class AST2CPPSpecFailingTest extends AST2SpecBaseTest {
|
|||
|
||||
// template <int I, int J> A<I+J> f(A<I>, A<J>); // #1
|
||||
// template <int K, int L> A<K+L> f(A<K>, A<L>); // same as #1
|
||||
// template <int I, int J> A<IJ> f(A<I>, A<J>); // different from #1
|
||||
// template <int I, int J> A<I-J> f(A<I>, A<J>); // different from #1
|
||||
public void _test14_5_5_1s5() throws Exception { // TODO raised bug 90683
|
||||
parse(getAboveComment(), ParserLanguage.CPP, true, 0);
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ package org.eclipse.cdt.core.parser.tests.ast2;
|
|||
|
||||
/**
|
||||
* @author dsteffle
|
||||
* mstodo the class should be removed
|
||||
* mstodo- the class should be removed
|
||||
*/
|
||||
public class AST2CSpecFailingTest extends AST2SpecBaseTest {
|
||||
|
||||
|
|
|
@ -2982,13 +2982,18 @@ public class AST2TemplateTests extends AST2BaseTest {
|
|||
// class A {};
|
||||
//
|
||||
// template<>
|
||||
// class C<A, 5> {};
|
||||
// class C<A, 5> {
|
||||
// public: int test;
|
||||
// };
|
||||
//
|
||||
// C<A,5L> ca5L;
|
||||
// void xx() {
|
||||
// ca5L.test= 0;
|
||||
// }
|
||||
public void testIntegralConversionInSpecializationMatching_237914() throws Exception {
|
||||
BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), true);
|
||||
ICPPSpecialization ctps= ba.assertNonProblem("C<A,5L>", 7, ICPPSpecialization.class, ICPPClassType.class);
|
||||
assertFalse(ctps instanceof ICPPTemplateInstance);
|
||||
ba.assertNonProblem("test=", 4, ICPPField.class);
|
||||
}
|
||||
|
||||
// class A {
|
||||
|
|
|
@ -12,6 +12,7 @@ package org.eclipse.cdt.core.parser.tests.scanner;
|
|||
|
||||
import org.eclipse.cdt.core.dom.ILinkage;
|
||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IMacroBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IScope;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
|
@ -77,4 +78,8 @@ final class TestMacro implements IMacroBinding {
|
|||
public boolean isDynamic() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public IBinding getOwner() {
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -131,4 +131,11 @@ public class EmptyIndexFragment implements IIndexFragment {
|
|||
public IIndexFragmentFile[] getAllFiles() {
|
||||
return IIndexFragmentFile.EMPTY_ARRAY;
|
||||
}
|
||||
|
||||
public Object getCachedResult(Object key) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void putCachedResult(Object key, Object newMap) {
|
||||
}
|
||||
}
|
||||
|
|
|
@ -174,7 +174,7 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase {
|
|||
}
|
||||
|
||||
protected static <T> T assertInstance(Object o, Class<T> clazz, Class ... cs) {
|
||||
assertNotNull(o);
|
||||
assertNotNull("Expected "+clazz.getName()+" but got null", o);
|
||||
assertTrue("Expected "+clazz.getName()+" but got "+o.getClass().getName(), clazz.isInstance(o));
|
||||
for(Class c : cs) {
|
||||
assertTrue("Expected "+clazz.getName()+" but got "+o.getClass().getName(), c.isInstance(o));
|
||||
|
|
|
@ -48,7 +48,7 @@ import org.eclipse.cdt.core.index.IIndexBinding;
|
|||
import org.eclipse.cdt.core.index.IIndexMacro;
|
||||
import org.eclipse.cdt.core.index.IndexFilter;
|
||||
import org.eclipse.cdt.core.parser.util.ObjectMap;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalTemplateInstantiator;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInstanceCache;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
|
||||
/**
|
||||
|
@ -211,9 +211,9 @@ public class IndexCPPBindingResolutionBugs extends IndexBindingResolutionTestBas
|
|||
assertInstance(b0, ICPPClassType.class);
|
||||
assertInstance(b1, ICPPClassType.class);
|
||||
assertInstance(b1, ICPPClassTemplate.class);
|
||||
assertInstance(b1, ICPPInternalTemplateInstantiator.class);
|
||||
assertInstance(b1, ICPPInstanceCache.class);
|
||||
|
||||
ICPPInternalTemplateInstantiator ct= (ICPPInternalTemplateInstantiator) b1;
|
||||
ICPPInstanceCache ct= (ICPPInstanceCache) b1;
|
||||
ICPPSpecialization inst= ct.getInstance(new IType[]{(IType)b0});
|
||||
assertInstance(inst, ICPPClassType.class);
|
||||
ICPPClassType c2t= (ICPPClassType) inst;
|
||||
|
|
|
@ -599,7 +599,6 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa
|
|||
// template<typename T>
|
||||
// class A {
|
||||
// T t;
|
||||
// int x;
|
||||
// T foo(T t) { return t; }
|
||||
// void bar(T t, int& x) {}
|
||||
// };
|
||||
|
@ -617,12 +616,15 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa
|
|||
IBinding b0= getBindingFromASTName("A<B> ab", 4);
|
||||
assertInstance(b0, ICPPClassType.class);
|
||||
assertInstance(b0, ICPPSpecialization.class);
|
||||
assertFalse(b0 instanceof ICPPTemplateInstance);
|
||||
|
||||
ICPPClassType ct= (ICPPClassType) b0;
|
||||
ICPPMethod[] dms= ct.getDeclaredMethods();
|
||||
assertEquals(2, dms.length);
|
||||
|
||||
|
||||
// if the specialization was used, we have 2 fields.
|
||||
ICPPField[] fs= ct.getDeclaredFields();
|
||||
assertEquals(2, fs.length);
|
||||
|
||||
ICPPMethod foo= dms[0].getName().equals("foo") ? dms[0] : dms[1];
|
||||
ICPPMethod bar= dms[0].getName().equals("bar") ? dms[0] : dms[1];
|
||||
|
||||
|
@ -637,9 +639,6 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa
|
|||
|
||||
assertInstance(bar.getType().getReturnType(), ICPPBasicType.class);
|
||||
assertEquals(((ICPPBasicType)bar.getType().getReturnType()).getType(), IBasicType.t_void);
|
||||
|
||||
ICPPField[] fs= ct.getDeclaredFields();
|
||||
assertEquals(2, fs.length);
|
||||
}
|
||||
|
||||
// template<typename T> class A {
|
||||
|
@ -1064,11 +1063,12 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa
|
|||
assertTrue(sc0.isSameType(sc1));
|
||||
|
||||
IIndexScope sc2= assertInstance(sc0.getScope(), IIndexScope.class, ICPPTemplateScope.class);
|
||||
assertNull(b0.getScope());
|
||||
assertEquals(sc2.getScopeBinding(), sc1);
|
||||
|
||||
assertInstance(b0.getScope(), ICPPTemplateScope.class);
|
||||
|
||||
assertNotSame(sc2, b0.getScope());
|
||||
assertEquals(sc2.getScopeBinding(), ((IIndexScope)b1.getScope()).getScopeBinding());
|
||||
// template scopes will not be supported in the future, see bug 237026
|
||||
// assertInstance(b0.getScope(), ICPPTemplateScope.class);
|
||||
// assertNotSame(sc2, b0.getScope());
|
||||
}
|
||||
|
||||
// template<typename T>
|
||||
|
|
|
@ -52,6 +52,7 @@ public class CPPClassTemplateTests extends PDOMTestBase {
|
|||
return suite(CPPClassTemplateTests.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
cproject= CProjectHelper.createCCProject("classTemplateTests"+System.currentTimeMillis(), "bin", IPDOMManager.ID_NO_INDEXER);
|
||||
setUpSections(1);
|
||||
|
@ -74,6 +75,7 @@ public class CPPClassTemplateTests extends PDOMTestBase {
|
|||
pdom.acquireReadLock();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
if(pdom!=null) {
|
||||
pdom.releaseReadLock();
|
||||
|
@ -135,7 +137,7 @@ public class CPPClassTemplateTests extends PDOMTestBase {
|
|||
// };
|
||||
public void testSimpleDefinition() throws Exception {
|
||||
assertDeclarationCount(pdom, "D", 1);
|
||||
IIndexFragmentBinding[] b= pdom.findBindings(new char[][] {{'D'}}, IndexFilter.ALL, NPM);
|
||||
IIndexFragmentBinding[] b= pdom.findBindings(new char[][] {{'D'}}, IndexFilter.ALL_DECLARED, NPM);
|
||||
assertEquals(1, b.length);
|
||||
assertTrue(b[0] instanceof ICPPClassTemplate);
|
||||
ICPPClassTemplate ct= (ICPPClassTemplate) b[0];
|
||||
|
@ -154,7 +156,7 @@ public class CPPClassTemplateTests extends PDOMTestBase {
|
|||
// };
|
||||
public void testDefinition() throws Exception {
|
||||
assertDeclarationCount(pdom, "D", 1);
|
||||
IIndexFragmentBinding[] b= pdom.findBindings(new char[][] {{'D'}}, IndexFilter.ALL, NPM);
|
||||
IIndexFragmentBinding[] b= pdom.findBindings(new char[][] {{'D'}}, IndexFilter.ALL_DECLARED, NPM);
|
||||
assertEquals(1, b.length);
|
||||
assertTrue(b[0] instanceof ICPPClassTemplate);
|
||||
ICPPClassTemplate ct= (ICPPClassTemplate) b[0];
|
||||
|
@ -180,7 +182,7 @@ public class CPPClassTemplateTests extends PDOMTestBase {
|
|||
// };
|
||||
public void testDefinition2() throws Exception {
|
||||
assertDeclarationCount(pdom, "E", 1);
|
||||
IIndexFragmentBinding[] b= pdom.findBindings(new char[][] {{'E'}}, IndexFilter.ALL, NPM);
|
||||
IIndexFragmentBinding[] b= pdom.findBindings(new char[][] {{'E'}}, IndexFilter.ALL_DECLARED, NPM);
|
||||
assertEquals(1, b.length);
|
||||
assertTrue(b[0] instanceof ICPPClassTemplate);
|
||||
ICPPClassTemplate ct= (ICPPClassTemplate) b[0];
|
||||
|
@ -266,7 +268,7 @@ public class CPPClassTemplateTests extends PDOMTestBase {
|
|||
|
||||
{
|
||||
// template
|
||||
IIndexFragmentBinding[] b= pdom.findBindings(new char[][] {{'D'}}, IndexFilter.ALL, NPM);
|
||||
IIndexFragmentBinding[] b= pdom.findBindings(new char[][] {{'D'}}, IndexFilter.ALL_DECLARED, NPM);
|
||||
assertEquals(2, b.length);
|
||||
assertTrue(!(b[0] instanceof ICPPClassTemplate) || !(b[1] instanceof ICPPClassTemplate));
|
||||
int i= b[0] instanceof ICPPClassTemplate ? 0 : 1;
|
||||
|
@ -318,6 +320,7 @@ public class CPPClassTemplateTests extends PDOMTestBase {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void assertInstance(Object o, Class c) {
|
||||
assertNotNull(o);
|
||||
assertTrue("Expected "+c.getName()+" but got "+o.getClass().getName(), c.isInstance(o));
|
||||
|
|
|
@ -38,6 +38,7 @@ public class CPPFunctionTemplateTests extends PDOMTestBase {
|
|||
return suite(CPPFunctionTemplateTests.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
cproject= CProjectHelper.createCCProject("functionTemplateTests"+System.currentTimeMillis(), "bin", IPDOMManager.ID_NO_INDEXER);
|
||||
}
|
||||
|
@ -56,6 +57,7 @@ public class CPPFunctionTemplateTests extends PDOMTestBase {
|
|||
pdom.acquireReadLock();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
if(pdom!=null) {
|
||||
pdom.releaseReadLock();
|
||||
|
@ -87,7 +89,7 @@ public class CPPFunctionTemplateTests extends PDOMTestBase {
|
|||
// }
|
||||
public void testSimpleInstantiation() throws Exception {
|
||||
setUpSections(1);
|
||||
IBinding[] bs= pdom.findBindings(new char[][]{"foo".toCharArray()}, IndexFilter.ALL, NPM);
|
||||
IBinding[] bs= pdom.findBindings(new char[][]{"foo".toCharArray()}, IndexFilter.ALL_DECLARED, NPM);
|
||||
assertEquals(2, bs.length);
|
||||
assertInstance(bs[0], ICPPFunctionTemplate.class);
|
||||
assertInstance(bs[1], ICPPFunctionTemplate.class);
|
||||
|
|
|
@ -27,7 +27,6 @@ import org.eclipse.cdt.internal.core.pdom.PDOM;
|
|||
import org.eclipse.cdt.internal.core.pdom.db.IBTreeVisitor;
|
||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
|
||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode;
|
||||
import org.eclipse.cdt.internal.core.pdom.dom.cpp.PDOMCPPClassTemplate;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
|
||||
/**
|
||||
|
@ -39,9 +38,9 @@ public class PDOMPrettyPrinter implements IPDOMVisitor {
|
|||
final String step = " "; //$NON-NLS-1$
|
||||
|
||||
public void leave(IPDOMNode node) throws CoreException {
|
||||
if (node instanceof PDOMCPPClassTemplate) {
|
||||
((PDOMCPPClassTemplate) node).specializationsAccept(this);
|
||||
}
|
||||
// if (node instanceof PDOMCPPClassTemplate) {
|
||||
// ((PDOMCPPClassTemplate) node).specializationsAccept(this);
|
||||
// }
|
||||
if(indent.length()>=step.length())
|
||||
indent.setLength(indent.length()-step.length());
|
||||
}
|
||||
|
|
|
@ -118,7 +118,7 @@ public class PDOMTestBase extends BaseTestCase {
|
|||
for (int i = 0; i < segments.length; i++) {
|
||||
pattern[i] = Pattern.compile(segments[i]);
|
||||
}
|
||||
return pdom.findBindings(pattern, true, IndexFilter.ALL, PROGRESS);
|
||||
return pdom.findBindings(pattern, true, IndexFilter.ALL_DECLARED, PROGRESS);
|
||||
}
|
||||
|
||||
protected IBinding[] findUnqualifiedName(PDOM pdom, String name) throws CoreException {
|
||||
|
|
|
@ -1,50 +1,69 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2004, 2006 IBM Corporation and others.
|
||||
* Copyright (c) 2004, 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:
|
||||
* IBM - Initial API and implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
* IBM - Initial API and implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.core.dom.ast;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ILinkage;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateDefinition;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDeclaration;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IAdaptable;
|
||||
|
||||
/**
|
||||
* Represents the semantics of a name found in the AST or the index.
|
||||
* @author Doug Schaefer
|
||||
*
|
||||
* @noimplement This interface is not intended to be implemented by clients.
|
||||
*/
|
||||
public interface IBinding extends IAdaptable {
|
||||
public static final IBinding[] EMPTY_BINDING_ARRAY = new IBinding[0];
|
||||
/**
|
||||
* The name of the binding.
|
||||
*
|
||||
* @return name
|
||||
* Returns the unqualified name of the binding as a string.
|
||||
*/
|
||||
public String getName();
|
||||
|
||||
/**
|
||||
* The name of the binding.
|
||||
*
|
||||
* @return name
|
||||
*/
|
||||
/**
|
||||
* Returns the unqualified name of the binding as an array of characters.
|
||||
*/
|
||||
public char[] getNameCharArray();
|
||||
|
||||
/**
|
||||
* Every name has a scope.
|
||||
*
|
||||
* @return the scope of this name
|
||||
*/
|
||||
public IScope getScope() throws DOMException;
|
||||
|
||||
/**
|
||||
* Every binding has a linkage.
|
||||
* Returns the linkage the binding belongs to. C++-declarations declared as
|
||||
* extern "C" will still return c++-linkage.
|
||||
*/
|
||||
public ILinkage getLinkage() throws CoreException;
|
||||
|
||||
|
||||
/**
|
||||
* Returns the binding that owns this binding, or <code>null</code> if there is no owner.
|
||||
* <p>
|
||||
* The owner is determined as follows:
|
||||
* <br> {@link ICPPUsingDeclaration}: the owner depends on where the declaration is found, within a
|
||||
* function or method, a class-type, a namespace or on global scope.
|
||||
* <br> {@link ICPPTemplateParameter}: the owner is the {@link ICPPTemplateDefinition}.
|
||||
* <br> for all other bindings the owner depends on where the binding can be defined (it could be
|
||||
* declared else where).
|
||||
* <p> Possible owners are:
|
||||
* <br> {@link IFunction}: for parameters, local types, variables, enumerators, labels and using declarations;
|
||||
* <br> {@link ICompositeType}: for class-, struct- and union-members, even if the composite type is anonymous;
|
||||
* also for enumerators and using declarations;
|
||||
* <br> {@link ICPPNamespace}: for global types, functions, variables, enumerators, namespaces and using declarations;
|
||||
* <br> <code>null</code>: for types, functions, variables, enumerators, namespaces and using declarations;
|
||||
* @since 5.1
|
||||
*/
|
||||
public IBinding getOwner() throws DOMException;
|
||||
|
||||
/**
|
||||
* Returns the parent scope for this binding. A binding may have declarations in multiple scopes,
|
||||
* this method returns the scope where the binding would potentially be defined.
|
||||
*/
|
||||
public IScope getScope() throws DOMException;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
/*******************************************************************************
|
||||
* 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.core.dom.ast.cpp;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
|
||||
/**
|
||||
* Specializations of all sorts of class types.
|
||||
* @since 5.1
|
||||
*/
|
||||
public interface ICPPClassSpecialization extends ICPPSpecialization, ICPPClassType {
|
||||
|
||||
ICPPClassType getSpecializedBinding();
|
||||
|
||||
/**
|
||||
* Creates a specialized binding for a member of the original class. The result is
|
||||
* a member of this class specialization.
|
||||
*/
|
||||
IBinding specializeMember(IBinding binding);
|
||||
}
|
|
@ -20,11 +20,15 @@ import org.eclipse.cdt.core.dom.ast.IType;
|
|||
* An instance of a class template will also implement ICPPClassType and similarly
|
||||
* a function template instance will also implement ICPPFunction (or even ICPPMethod
|
||||
* or ICPPConstructor as appropriate)
|
||||
*
|
||||
* @author aniefer
|
||||
*
|
||||
* @noimplement This interface is not intended to be implemented by clients.
|
||||
*/
|
||||
public interface ICPPTemplateInstance extends ICPPSpecialization {
|
||||
|
||||
/**
|
||||
* @since 5.1
|
||||
*/
|
||||
ICPPTemplateInstance[] EMPTY_TEMPLATE_INSTANCE_ARRAY = {};
|
||||
|
||||
/**
|
||||
* get the template that this was instantiated from
|
||||
*/
|
||||
|
|
|
@ -8,26 +8,17 @@
|
|||
* Contributors:
|
||||
* Markus Schorn - initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.core.index;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
|
||||
/**
|
||||
* Represents the semantics of a name in the index.
|
||||
*
|
||||
* <p>
|
||||
* This interface is not intended to be implemented by clients.
|
||||
* </p>
|
||||
* <p>
|
||||
* <strong>EXPERIMENTAL</strong>. This class or interface has been added as
|
||||
* part of a work in progress. There is no guarantee that this API will work or
|
||||
* that it will remain the same. Please do not use this API without consulting
|
||||
* with the CDT team.
|
||||
* </p>
|
||||
*
|
||||
* @since 4.0
|
||||
*
|
||||
* @noimplement This interface is not intended to be implemented by clients.
|
||||
*/
|
||||
public interface IIndexBinding extends IBinding {
|
||||
IIndexBinding[] EMPTY_INDEX_BINDING_ARRAY = new IIndexBinding[0];
|
||||
|
@ -51,4 +42,10 @@ public interface IIndexBinding extends IBinding {
|
|||
* is used to model static files, static variables.
|
||||
*/
|
||||
IIndexFile getLocalToFile() throws CoreException;
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* @since 5.1
|
||||
*/
|
||||
IIndexBinding getOwner() throws DOMException;
|
||||
}
|
||||
|
|
|
@ -21,12 +21,6 @@ import org.eclipse.core.runtime.CoreException;
|
|||
/**
|
||||
* Can be subclassed and used for queries in the index.
|
||||
* @since 4.0
|
||||
* <p>
|
||||
* <strong>EXPERIMENTAL</strong>. This class or interface has been added as
|
||||
* part of a work in progress. There is no guarantee that this API will
|
||||
* work or that it will remain the same. Please do not use this API without
|
||||
* consulting with the CDT team.
|
||||
* </p>
|
||||
*/
|
||||
|
||||
abstract public class IndexFilter {
|
||||
|
@ -34,6 +28,10 @@ abstract public class IndexFilter {
|
|||
public static final IndexFilter ALL_DECLARED = getDeclaredBindingFilter(-1, false);
|
||||
public static final IndexFilter ALL_DECLARED_OR_IMPLICIT = getDeclaredBindingFilter(-1, true);
|
||||
public static final IndexFilter CPP_DECLARED_OR_IMPLICIT= getDeclaredBindingFilter(ILinkage.CPP_LINKAGE_ID, true);
|
||||
/**
|
||||
* @since 5.1
|
||||
*/
|
||||
public static final IndexFilter CPP_DECLARED_OR_IMPLICIT_NO_INSTANCE= getDeclaredBindingFilter(ILinkage.CPP_LINKAGE_ID, true, false);
|
||||
public static final IndexFilter C_DECLARED_OR_IMPLICIT= getDeclaredBindingFilter(ILinkage.C_LINKAGE_ID, true);
|
||||
|
||||
/**
|
||||
|
@ -59,7 +57,19 @@ abstract public class IndexFilter {
|
|||
* @return an IndexFilter instance
|
||||
*/
|
||||
public static IndexFilter getDeclaredBindingFilter(final int linkageID, boolean acceptImplicit) {
|
||||
return new DeclaredBindingsFilter(linkageID, acceptImplicit);
|
||||
return new DeclaredBindingsFilter(linkageID, acceptImplicit, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an IndexFilter that filters out bindings without declarations and those
|
||||
* from linkages other than that specified.
|
||||
* @param linkageID the id of the linkage whose bindings should be retained, or -1
|
||||
* to accept all linkages.
|
||||
* @return an IndexFilter instance
|
||||
* @since 5.1
|
||||
*/
|
||||
public static IndexFilter getDeclaredBindingFilter(final int linkageID, boolean acceptImplicit, boolean allowInstances) {
|
||||
return new DeclaredBindingsFilter(linkageID, acceptImplicit, allowInstances);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -2380,6 +2380,10 @@ public class GCCBuiltinSymbolProvider implements IBuiltinBindingsProvider {
|
|||
public ILinkage getLinkage() {
|
||||
return Linkage.C_LINKAGE;
|
||||
}
|
||||
|
||||
public IBinding getOwner() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
static public class CPPBuiltinParameter extends PlatformObject implements ICPPParameter {
|
||||
|
@ -2468,5 +2472,9 @@ public class GCCBuiltinSymbolProvider implements IBuiltinBindingsProvider {
|
|||
public ILinkage getLinkage() {
|
||||
return Linkage.CPP_LINKAGE;
|
||||
}
|
||||
|
||||
public IBinding getOwner() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -236,4 +236,8 @@ public class ProblemBinding extends PlatformObject implements IProblemBinding, I
|
|||
public String toString() {
|
||||
return getMessage();
|
||||
}
|
||||
|
||||
public IBinding getOwner() throws DOMException {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,19 +9,17 @@
|
|||
* IBM Corporation - initial API and implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
*******************************************************************************/
|
||||
|
||||
/*
|
||||
* Created on Nov 23, 2004
|
||||
*/
|
||||
package org.eclipse.cdt.internal.core.dom.parser.c;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ILinkage;
|
||||
import org.eclipse.cdt.core.dom.ast.ASTNodeProperty;
|
||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTElaboratedTypeSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IEnumeration;
|
||||
import org.eclipse.cdt.core.dom.ast.IEnumerator;
|
||||
import org.eclipse.cdt.core.dom.ast.IProblemBinding;
|
||||
|
@ -173,4 +171,13 @@ public class CEnumeration extends PlatformObject implements IEnumeration, ICInte
|
|||
public IASTNode getDefinition() {
|
||||
return definition;
|
||||
}
|
||||
|
||||
public IBinding getOwner() throws DOMException {
|
||||
IASTNode node= definition;
|
||||
if (node == null && declarations != null && declarations.length > 0) {
|
||||
node= declarations[0];
|
||||
}
|
||||
// either local or global, never part of structs
|
||||
return CVisitor.findEnclosingFunction(node);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2004, 2006 IBM Corporation and others.
|
||||
* Copyright (c) 2004, 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
|
||||
|
@ -9,10 +9,6 @@
|
|||
* IBM Corporation - initial API and implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
*******************************************************************************/
|
||||
|
||||
/*
|
||||
* Created on Nov 23, 2004
|
||||
*/
|
||||
package org.eclipse.cdt.internal.core.dom.parser.c;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ILinkage;
|
||||
|
@ -20,6 +16,7 @@ import org.eclipse.cdt.core.dom.ast.DOMException;
|
|||
import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IEnumeration;
|
||||
import org.eclipse.cdt.core.dom.ast.IEnumerator;
|
||||
import org.eclipse.cdt.core.dom.ast.IScope;
|
||||
|
@ -82,4 +79,8 @@ public class CEnumerator extends PlatformObject implements IEnumerator {
|
|||
public ILinkage getLinkage() {
|
||||
return Linkage.C_LINKAGE;
|
||||
}
|
||||
|
||||
public IBinding getOwner() throws DOMException {
|
||||
return CVisitor.findEnclosingFunction(enumeratorName);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2004, 2006 IBM Corporation and others.
|
||||
* Copyright (c) 2004, 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
|
||||
|
@ -9,21 +9,17 @@
|
|||
* IBM Corporation - initial API and implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
*******************************************************************************/
|
||||
|
||||
/*
|
||||
* Created on Jan 26, 2005
|
||||
*/
|
||||
package org.eclipse.cdt.internal.core.dom.parser.c;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ILinkage;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IScope;
|
||||
import org.eclipse.cdt.core.dom.ast.IType;
|
||||
import org.eclipse.cdt.core.dom.ast.IVariable;
|
||||
import org.eclipse.cdt.core.dom.ast.c.ICExternalBinding;
|
||||
import org.eclipse.cdt.internal.core.dom.Linkage;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.PlatformObject;
|
||||
|
||||
/**
|
||||
|
@ -96,7 +92,11 @@ public class CExternalVariable extends PlatformObject implements ICExternalBindi
|
|||
return false;
|
||||
}
|
||||
|
||||
public ILinkage getLinkage() throws CoreException {
|
||||
public ILinkage getLinkage() {
|
||||
return Linkage.C_LINKAGE;
|
||||
}
|
||||
|
||||
public IBinding getOwner() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
package org.eclipse.cdt.internal.core.dom.parser.c;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ILinkage;
|
||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
||||
|
@ -34,12 +35,10 @@ import org.eclipse.cdt.core.dom.ast.gnu.c.ICASTKnRFunctionDeclarator;
|
|||
import org.eclipse.cdt.core.parser.util.ArrayUtil;
|
||||
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
|
||||
import org.eclipse.cdt.internal.core.dom.Linkage;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.PlatformObject;
|
||||
|
||||
/**
|
||||
* Created on Nov 5, 2004
|
||||
* @author aniefer
|
||||
* Represents a function.
|
||||
*/
|
||||
public class CFunction extends PlatformObject implements IFunction, ICInternalFunction {
|
||||
private IASTStandardFunctionDeclarator [] declarators = null;
|
||||
|
@ -458,7 +457,7 @@ public class CFunction extends PlatformObject implements IFunction, ICInternalFu
|
|||
bits &= ~FULLY_RESOLVED;
|
||||
}
|
||||
|
||||
public ILinkage getLinkage() throws CoreException {
|
||||
public ILinkage getLinkage() {
|
||||
return Linkage.C_LINKAGE;
|
||||
}
|
||||
|
||||
|
@ -469,4 +468,8 @@ public class CFunction extends PlatformObject implements IFunction, ICInternalFu
|
|||
public IASTNode getDefinition() {
|
||||
return definition;
|
||||
}
|
||||
|
||||
public IBinding getOwner() throws DOMException {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,23 +1,25 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2005, 2006 IBM Corporation and others.
|
||||
* 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:
|
||||
* IBM Rational Software - Initial API and implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
* IBM Rational Software - Initial API and implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.dom.parser.c;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ILinkage;
|
||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTElaboratedTypeSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IParameter;
|
||||
import org.eclipse.cdt.core.dom.ast.IScope;
|
||||
import org.eclipse.cdt.core.dom.ast.IType;
|
||||
|
@ -27,8 +29,6 @@ import org.eclipse.core.runtime.PlatformObject;
|
|||
|
||||
/**
|
||||
* A K&R C parameter.
|
||||
*
|
||||
* @author dsteffle
|
||||
*/
|
||||
public class CKnRParameter extends PlatformObject implements IParameter {
|
||||
final private IASTDeclaration declaration;
|
||||
|
@ -121,4 +121,8 @@ public class CKnRParameter extends PlatformObject implements IParameter {
|
|||
public ILinkage getLinkage() {
|
||||
return Linkage.C_LINKAGE;
|
||||
}
|
||||
|
||||
public IBinding getOwner() throws DOMException {
|
||||
return CVisitor.findEnclosingFunction(declaration);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2004, 2006 IBM Corporation and others.
|
||||
* Copyright (c) 2004, 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
|
||||
|
@ -9,10 +9,6 @@
|
|||
* IBM Corporation - initial API and implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
*******************************************************************************/
|
||||
|
||||
/*
|
||||
* Created on Nov 17, 2004
|
||||
*/
|
||||
package org.eclipse.cdt.internal.core.dom.parser.c;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ILinkage;
|
||||
|
@ -20,6 +16,7 @@ import org.eclipse.cdt.core.dom.ast.DOMException;
|
|||
import org.eclipse.cdt.core.dom.ast.IASTLabelStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.ILabel;
|
||||
import org.eclipse.cdt.core.dom.ast.IScope;
|
||||
import org.eclipse.cdt.internal.core.dom.Linkage;
|
||||
|
@ -27,7 +24,7 @@ import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding;
|
|||
import org.eclipse.core.runtime.PlatformObject;
|
||||
|
||||
/**
|
||||
* @author aniefer
|
||||
* Represents a label.
|
||||
*/
|
||||
public class CLabel extends PlatformObject implements ILabel {
|
||||
|
||||
|
@ -77,4 +74,8 @@ public class CLabel extends PlatformObject implements ILabel {
|
|||
public ILinkage getLinkage() {
|
||||
return Linkage.C_LINKAGE;
|
||||
}
|
||||
|
||||
public IBinding getOwner() throws DOMException {
|
||||
return CVisitor.findEnclosingFunction(labelStatement);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,15 +1,14 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2004, 2006 IBM Corporation and others.
|
||||
* Copyright (c) 2004, 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:
|
||||
* IBM Rational Software - Initial API and implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
* IBM Rational Software - Initial API and implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.internal.core.dom.parser.c;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ILinkage;
|
||||
|
@ -23,6 +22,7 @@ import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
|
|||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IParameter;
|
||||
import org.eclipse.cdt.core.dom.ast.IScope;
|
||||
import org.eclipse.cdt.core.dom.ast.IType;
|
||||
|
@ -33,8 +33,7 @@ import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding;
|
|||
import org.eclipse.core.runtime.PlatformObject;
|
||||
|
||||
/**
|
||||
* Created on Nov 5, 2004
|
||||
* @author aniefer
|
||||
* Represents the parameter of a function.
|
||||
*/
|
||||
public class CParameter extends PlatformObject implements IParameter {
|
||||
public static class CParameterProblem extends ProblemBinding implements IParameter {
|
||||
|
@ -191,4 +190,11 @@ public class CParameter extends PlatformObject implements IParameter {
|
|||
public ILinkage getLinkage() {
|
||||
return Linkage.C_LINKAGE;
|
||||
}
|
||||
|
||||
public IBinding getOwner() throws DOMException {
|
||||
if (declarations == null || declarations.length == 0)
|
||||
return null;
|
||||
|
||||
return CVisitor.findEnclosingFunction(declarations[0]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,10 +6,9 @@
|
|||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Rational Software - Initial API and implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
* IBM Rational Software - Initial API and implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.internal.core.dom.parser.c;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ILinkage;
|
||||
|
@ -40,8 +39,7 @@ import org.eclipse.cdt.internal.core.index.IIndexType;
|
|||
import org.eclipse.core.runtime.PlatformObject;
|
||||
|
||||
/**
|
||||
* Created on Nov 8, 2004
|
||||
* @author aniefer
|
||||
* Represents structs and unions.
|
||||
*/
|
||||
public class CStructure extends PlatformObject implements ICompositeType, ICInternalBinding {
|
||||
|
||||
|
@ -275,4 +273,14 @@ public class CStructure extends PlatformObject implements ICompositeType, ICInte
|
|||
public IASTNode getDefinition() {
|
||||
return definition;
|
||||
}
|
||||
|
||||
public IBinding getOwner() throws DOMException {
|
||||
IASTNode node= definition;
|
||||
if (node == null) {
|
||||
if (declarations != null && declarations.length > 0) {
|
||||
node= declarations[0];
|
||||
}
|
||||
}
|
||||
return CVisitor.findEnclosingFunction(node); // local or global
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@ import org.eclipse.cdt.core.dom.ast.DOMException;
|
|||
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IScope;
|
||||
import org.eclipse.cdt.core.dom.ast.IType;
|
||||
import org.eclipse.cdt.core.dom.ast.ITypedef;
|
||||
|
@ -24,8 +25,7 @@ import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer;
|
|||
import org.eclipse.core.runtime.PlatformObject;
|
||||
|
||||
/**
|
||||
* Created on Nov 8, 2004
|
||||
* @author aniefer
|
||||
* Represents a typedef.
|
||||
*/
|
||||
public class CTypedef extends PlatformObject implements ITypedef, ITypeContainer, ICInternalBinding {
|
||||
private final IASTName name;
|
||||
|
@ -113,4 +113,8 @@ public class CTypedef extends PlatformObject implements ITypedef, ITypeContainer
|
|||
public IASTNode getDefinition() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public IBinding getOwner() throws DOMException {
|
||||
return CVisitor.findEnclosingFunction(name);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,7 +9,6 @@
|
|||
* IBM Rational Software - Initial API and implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.internal.core.dom.parser.c;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ILinkage;
|
||||
|
@ -20,6 +19,7 @@ import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
|||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IScope;
|
||||
import org.eclipse.cdt.core.dom.ast.IType;
|
||||
import org.eclipse.cdt.core.dom.ast.IVariable;
|
||||
|
@ -29,8 +29,7 @@ import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding;
|
|||
import org.eclipse.core.runtime.PlatformObject;
|
||||
|
||||
/**
|
||||
* Created on Nov 5, 2004
|
||||
* @author aniefer
|
||||
* Represents a global or a local variable.
|
||||
*/
|
||||
public class CVariable extends PlatformObject implements IVariable, ICInternalVariable {
|
||||
public static class CVariableProblem extends ProblemBinding implements IVariable {
|
||||
|
@ -146,4 +145,10 @@ public class CVariable extends PlatformObject implements IVariable, ICInternalVa
|
|||
public IASTNode getDefinition() {
|
||||
return getPhysicalNode();
|
||||
}
|
||||
public IBinding getOwner() throws DOMException {
|
||||
if (declarations == null || declarations.length == 0)
|
||||
return null;
|
||||
|
||||
return CVisitor.findDeclarationOwner(declarations[0], true);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2205,4 +2205,64 @@ public class CVisitor {
|
|||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Searches for the function enclosing the given node. May return <code>null</code>.
|
||||
*/
|
||||
public static IBinding findEnclosingFunction(IASTNode node) {
|
||||
while(node != null && node instanceof IASTFunctionDefinition == false) {
|
||||
node= node.getParent();
|
||||
}
|
||||
if (node == null)
|
||||
return null;
|
||||
|
||||
IASTDeclarator dtor= findInnermostDeclarator(((IASTFunctionDefinition) node).getDeclarator());
|
||||
if (dtor != null) {
|
||||
IASTName name= dtor.getName();
|
||||
if (name != null) {
|
||||
return name.resolveBinding();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Searches for the first function, struct or union enclosing the declaration the provided
|
||||
* node belongs to and returns the binding for it. Returns <code>null</code>, if the declaration is not
|
||||
* enclosed by any of the above constructs.
|
||||
*/
|
||||
public static IBinding findDeclarationOwner(IASTNode node, boolean allowFunction) {
|
||||
// search for declaration
|
||||
while (node instanceof IASTDeclaration == false) {
|
||||
if (node == null)
|
||||
return null;
|
||||
|
||||
node= node.getParent();
|
||||
}
|
||||
|
||||
// search for enclosing binding
|
||||
IASTName name= null;
|
||||
node= node.getParent();
|
||||
for (; node != null; node= node.getParent()) {
|
||||
if (node instanceof IASTFunctionDefinition) {
|
||||
if (!allowFunction)
|
||||
continue;
|
||||
|
||||
IASTDeclarator dtor= findInnermostDeclarator(((IASTFunctionDefinition) node).getDeclarator());
|
||||
if (dtor != null) {
|
||||
name= dtor.getName();
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (node instanceof IASTCompositeTypeSpecifier) {
|
||||
name= ((IASTCompositeTypeSpecifier) node).getName();
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (name == null)
|
||||
return null;
|
||||
|
||||
return name.resolveBinding();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,161 @@
|
|||
/*******************************************************************************
|
||||
* 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:
|
||||
* IBM - Initial API and implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
* Bryan Wilkinson (QNX)
|
||||
* Andrew Ferguson (Symbian)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
||||
|
||||
import org.eclipse.cdt.core.dom.IName;
|
||||
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.IScope;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassSpecialization;
|
||||
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.ICPPMethod;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace;
|
||||
import org.eclipse.cdt.core.index.IIndexFileSet;
|
||||
import org.eclipse.cdt.core.parser.util.ArrayUtil;
|
||||
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPSemantics;
|
||||
|
||||
/**
|
||||
* Base class for all specialization scopes
|
||||
*/
|
||||
public class AbstractCPPClassSpecializationScope implements ICPPClassSpecializationScope {
|
||||
final private ICPPClassSpecialization specialClass;
|
||||
|
||||
public AbstractCPPClassSpecializationScope(ICPPClassSpecialization specialization) {
|
||||
this.specialClass= specialization;
|
||||
}
|
||||
|
||||
public ICPPClassType getOriginalClassType() {
|
||||
return specialClass.getSpecializedBinding();
|
||||
}
|
||||
|
||||
public final IBinding getBinding(IASTName name, boolean resolve) throws DOMException {
|
||||
return getBinding(name, resolve, IIndexFileSet.EMPTY);
|
||||
}
|
||||
|
||||
public final IBinding[] getBindings(IASTName name, boolean resolve, boolean prefix) throws DOMException {
|
||||
return getBindings(name, resolve, prefix, IIndexFileSet.EMPTY);
|
||||
}
|
||||
|
||||
public IBinding getBinding(IASTName name, boolean forceResolve, IIndexFileSet fileSet) throws DOMException {
|
||||
char[] c = name.toCharArray();
|
||||
|
||||
if (CharArrayUtils.equals(c, specialClass.getNameCharArray()) && !CPPClassScope.isConstructorReference(name)) {
|
||||
return specialClass;
|
||||
}
|
||||
|
||||
ICPPClassType specialized = specialClass.getSpecializedBinding();
|
||||
IScope classScope = specialized.getCompositeScope();
|
||||
IBinding[] bindings = classScope != null ? classScope.getBindings(name, forceResolve, false) : null;
|
||||
|
||||
if (bindings == null)
|
||||
return null;
|
||||
|
||||
IBinding[] specs = new IBinding[0];
|
||||
for (IBinding binding : bindings) {
|
||||
specs = (IBinding[]) ArrayUtil.append(IBinding.class, specs, specialClass.specializeMember(binding));
|
||||
}
|
||||
specs = (IBinding[]) ArrayUtil.trim(IBinding.class, specs);
|
||||
return CPPSemantics.resolveAmbiguities(name, specs);
|
||||
}
|
||||
|
||||
public IBinding[] getBindings(IASTName name, boolean forceResolve, boolean prefixLookup,
|
||||
IIndexFileSet fileSet) throws DOMException {
|
||||
char[] c = name.toCharArray();
|
||||
IBinding[] result = null;
|
||||
|
||||
if ((!prefixLookup && CharArrayUtils.equals(c, specialClass.getNameCharArray())) ||
|
||||
(prefixLookup && CharArrayUtils.equals(specialClass.getNameCharArray(), 0, c.length, c, true))) {
|
||||
result = new IBinding[] { specialClass };
|
||||
}
|
||||
|
||||
ICPPClassType specialized = specialClass.getSpecializedBinding();
|
||||
IScope classScope = specialized.getCompositeScope();
|
||||
IBinding[] bindings = classScope != null ?
|
||||
classScope.getBindings(name, forceResolve, prefixLookup, fileSet) : null;
|
||||
|
||||
if (bindings != null) {
|
||||
for (IBinding binding : bindings) {
|
||||
result = (IBinding[]) ArrayUtil.append(IBinding.class, result, specialClass.specializeMember(binding));
|
||||
}
|
||||
}
|
||||
|
||||
return (IBinding[]) ArrayUtil.trim(IBinding.class, result);
|
||||
}
|
||||
|
||||
public ICPPClassSpecialization getClassType() {
|
||||
return specialClass;
|
||||
}
|
||||
|
||||
public ICPPMethod[] getImplicitMethods() {
|
||||
// Implicit methods shouldn't have implicit specializations
|
||||
return ICPPMethod.EMPTY_CPPMETHOD_ARRAY;
|
||||
}
|
||||
|
||||
public IName getScopeName() {
|
||||
if (specialClass instanceof ICPPInternalBinding)
|
||||
return (IASTName) ((ICPPInternalBinding) specialClass).getDefinition();
|
||||
//TODO: get the scope name for non-internal bindings
|
||||
return null;
|
||||
}
|
||||
|
||||
public ICPPConstructor[] getConstructors() throws DOMException {
|
||||
ICPPClassType specialized = specialClass.getSpecializedBinding();
|
||||
ICPPConstructor[] bindings = specialized.getConstructors();
|
||||
|
||||
if (bindings == null) return ICPPConstructor.EMPTY_CONSTRUCTOR_ARRAY;
|
||||
|
||||
ICPPConstructor[] specs = new ICPPConstructor[0];
|
||||
for (ICPPConstructor binding : bindings) {
|
||||
specs = (ICPPConstructor[]) ArrayUtil.append(ICPPConstructor.class, specs, specialClass.specializeMember(binding));
|
||||
}
|
||||
return (ICPPConstructor[]) ArrayUtil.trim(ICPPConstructor.class, specs);
|
||||
}
|
||||
|
||||
public ICPPMethod[] getDeclaredMethods() throws DOMException {
|
||||
ICPPClassType specialized = specialClass.getSpecializedBinding();
|
||||
ICPPMethod[] bindings = specialized.getDeclaredMethods();
|
||||
|
||||
if (bindings == null) return ICPPMethod.EMPTY_CPPMETHOD_ARRAY;
|
||||
|
||||
ICPPMethod[] specs = new ICPPMethod[0];
|
||||
for (ICPPMethod binding : bindings) {
|
||||
specs = (ICPPMethod[]) ArrayUtil.append(ICPPMethod.class, specs, specialClass.specializeMember(binding));
|
||||
}
|
||||
return (ICPPMethod[]) ArrayUtil.trim(ICPPMethod.class, specs);
|
||||
}
|
||||
|
||||
public IScope getParent() throws DOMException {
|
||||
IBinding binding= specialClass.getOwner();
|
||||
if (binding instanceof ICPPClassType) {
|
||||
return ((ICPPClassType) binding).getCompositeScope();
|
||||
}
|
||||
if (binding instanceof ICPPNamespace) {
|
||||
return ((ICPPNamespace) binding).getNamespaceScope();
|
||||
}
|
||||
return getOriginalClassType().getScope();
|
||||
}
|
||||
|
||||
public IBinding[] find(String name) throws DOMException {
|
||||
return CPPSemantics.findBindings(this, name, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
IName name = getScopeName();
|
||||
return name != null ? name.toString() : String.valueOf(specialClass);
|
||||
}
|
||||
}
|
|
@ -13,143 +13,41 @@
|
|||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
||||
|
||||
import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.getUltimateType;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
import org.eclipse.cdt.core.dom.ast.ASTTypeUtil;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IField;
|
||||
import org.eclipse.cdt.core.dom.ast.IScope;
|
||||
import org.eclipse.cdt.core.dom.ast.IType;
|
||||
import org.eclipse.cdt.core.dom.ast.ITypedef;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBase;
|
||||
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.ICPPField;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateDefinition;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance;
|
||||
import org.eclipse.cdt.core.parser.util.ArrayUtil;
|
||||
import org.eclipse.cdt.core.parser.util.ObjectMap;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPTemplates;
|
||||
|
||||
/**
|
||||
* @author aniefer
|
||||
*/
|
||||
public class CPPClassInstance extends CPPInstance implements ICPPClassType {
|
||||
private CPPClassSpecializationScope instanceScope;
|
||||
public class CPPClassInstance extends CPPClassSpecialization implements ICPPTemplateInstance {
|
||||
private IType[] arguments;
|
||||
|
||||
public CPPClassInstance(ICPPScope scope, IBinding decl, ObjectMap argMap, IType[] args) {
|
||||
super(scope, decl, argMap, args);
|
||||
public CPPClassInstance(IBinding owner, ICPPClassType orig, ObjectMap argMap, IType[] args) {
|
||||
super(orig, owner, argMap);
|
||||
this.arguments= args;
|
||||
}
|
||||
|
||||
public ICPPBase[] getBases() throws DOMException {
|
||||
ICPPClassType cls = (ICPPClassType) getSpecializedBinding();
|
||||
if (cls != null) {
|
||||
ICPPBase[] result = null;
|
||||
ICPPBase[] bindings = cls.getBases();
|
||||
for (ICPPBase binding : bindings) {
|
||||
ICPPBase specBinding = (ICPPBase) ((ICPPInternalBase) binding).clone();
|
||||
IBinding base = binding.getBaseClass();
|
||||
if (base instanceof IType) {
|
||||
IType specBase = CPPTemplates.instantiateType((IType) base, argumentMap, instanceScope);
|
||||
specBase = getUltimateType(specBase, false);
|
||||
if (specBase instanceof IBinding) {
|
||||
((ICPPInternalBase) specBinding).setBaseClass((IBinding) specBase);
|
||||
}
|
||||
result = (ICPPBase[]) ArrayUtil.append(ICPPBase.class, result, specBinding);
|
||||
}
|
||||
}
|
||||
return (ICPPBase[]) ArrayUtil.trim(ICPPBase.class, result);
|
||||
}
|
||||
return ICPPBase.EMPTY_BASE_ARRAY;
|
||||
public ICPPTemplateDefinition getTemplateDefinition() {
|
||||
return (ICPPTemplateDefinition) getSpecializedBinding();
|
||||
}
|
||||
|
||||
public IField[] getFields() throws DOMException {
|
||||
return null;
|
||||
}
|
||||
|
||||
public IField findField(String name) throws DOMException {
|
||||
return null;
|
||||
}
|
||||
|
||||
public ICPPField[] getDeclaredFields() throws DOMException {
|
||||
return null;
|
||||
}
|
||||
|
||||
public ICPPMethod[] getMethods() throws DOMException {
|
||||
return CPPClassType.getMethods(this);
|
||||
}
|
||||
|
||||
public ICPPMethod[] getAllDeclaredMethods() throws DOMException {
|
||||
return null;
|
||||
}
|
||||
|
||||
public ICPPMethod[] getDeclaredMethods() throws DOMException {
|
||||
CPPClassSpecializationScope scope = (CPPClassSpecializationScope) getCompositeScope();
|
||||
if (scope.isFullyCached())
|
||||
return scope.getDeclaredMethods();
|
||||
return ICPPMethod.EMPTY_CPPMETHOD_ARRAY;
|
||||
}
|
||||
|
||||
public ICPPConstructor[] getConstructors() throws DOMException {
|
||||
CPPClassSpecializationScope scope = (CPPClassSpecializationScope) getCompositeScope();
|
||||
if (scope.isFullyCached())
|
||||
return scope.getConstructors();
|
||||
return ICPPConstructor.EMPTY_CONSTRUCTOR_ARRAY;
|
||||
}
|
||||
|
||||
public IBinding[] getFriends() throws DOMException {
|
||||
return null;
|
||||
}
|
||||
|
||||
public int getKey() throws DOMException {
|
||||
return ((ICPPClassType) getSpecializedBinding()).getKey();
|
||||
}
|
||||
|
||||
public IScope getCompositeScope() {
|
||||
if (instanceScope == null) {
|
||||
instanceScope = new CPPClassSpecializationScope(this);
|
||||
}
|
||||
return instanceScope;
|
||||
public IType[] getArguments() {
|
||||
return arguments;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* For debug purposes only
|
||||
*/
|
||||
@Override
|
||||
public Object clone() {
|
||||
return this;
|
||||
public String toString() {
|
||||
return getName() + " <" + ASTTypeUtil.getTypeListString(arguments) + ">"; //$NON-NLS-1$ //$NON-NLS-2$
|
||||
}
|
||||
|
||||
public boolean isSameType(IType type) {
|
||||
if (type == this)
|
||||
return true;
|
||||
if (type instanceof ITypedef)
|
||||
return type.isSameType(this);
|
||||
|
||||
if (type instanceof ICPPTemplateInstance) {
|
||||
ICPPClassType ct1= (ICPPClassType) getSpecializedBinding();
|
||||
ICPPClassType ct2= (ICPPClassType) ((ICPPTemplateInstance) type).getTemplateDefinition();
|
||||
if (!ct1.isSameType(ct2))
|
||||
return false;
|
||||
|
||||
ObjectMap m1 = getArgumentMap();
|
||||
ObjectMap m2 = ((ICPPTemplateInstance) type).getArgumentMap();
|
||||
if (m1 == null || m2 == null || m1.size() != m2.size())
|
||||
return false;
|
||||
for (int i = 0; i < m1.size(); i++) {
|
||||
IType t1 = (IType) m1.getAt(i);
|
||||
IType t2 = (IType) m2.getAt(i);
|
||||
if (!CPPTemplates.isSameTemplateArgument(t1, t2))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public ICPPClassType[] getNestedClasses() throws DOMException {
|
||||
return ICPPClassType.EMPTY_CLASS_ARRAY;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
return obj instanceof ICPPClassType && isSameType((ICPPClassType) obj);
|
||||
|
|
|
@ -30,11 +30,11 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateDeclaration;
|
|||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTUsingDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBase;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassScope;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassSpecialization;
|
||||
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.ICPPField;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier;
|
||||
import org.eclipse.cdt.core.parser.util.ArrayUtil;
|
||||
|
@ -49,17 +49,30 @@ import org.eclipse.cdt.internal.core.index.IIndexType;
|
|||
* @author aniefer
|
||||
*
|
||||
*/
|
||||
public class CPPClassSpecialization extends CPPSpecialization implements
|
||||
ICPPClassType {
|
||||
public class CPPClassSpecialization extends CPPSpecialization implements ICPPClassSpecialization {
|
||||
|
||||
private IScope specScope;
|
||||
private ObjectMap specializationMap= ObjectMap.EMPTY_MAP;
|
||||
|
||||
public CPPClassSpecialization(ICPPClassType specialized, IBinding owner, ObjectMap argumentMap) {
|
||||
super(specialized, owner, argumentMap);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param specialized
|
||||
* @param scope
|
||||
*/
|
||||
public CPPClassSpecialization(IBinding specialized, ICPPScope scope, ObjectMap argumentMap) {
|
||||
super(specialized, scope, argumentMap);
|
||||
@Override
|
||||
public ICPPClassType getSpecializedBinding() {
|
||||
return (ICPPClassType) super.getSpecializedBinding();
|
||||
}
|
||||
|
||||
public IBinding specializeMember(IBinding original) {
|
||||
IBinding result= (IBinding) specializationMap.get(original);
|
||||
if (result == null) {
|
||||
result= CPPTemplates.createSpecialization(this, original, argumentMap);
|
||||
if (specializationMap == ObjectMap.EMPTY_MAP)
|
||||
specializationMap = new ObjectMap(2);
|
||||
specializationMap.put(original, result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private ICPPASTCompositeTypeSpecifier getCompositeTypeSpecifier(){
|
||||
|
@ -80,12 +93,12 @@ public class CPPClassSpecialization extends CPPSpecialization implements
|
|||
public ICPPBase[] getBases() throws DOMException {
|
||||
if( getDefinition() == null ){
|
||||
ICPPBase[] result = null;
|
||||
ICPPBase[] bindings = ((ICPPClassType)getSpecializedBinding()).getBases();
|
||||
ICPPBase[] bindings = (getSpecializedBinding()).getBases();
|
||||
for (ICPPBase binding : bindings) {
|
||||
ICPPBase specBinding = (ICPPBase) ((ICPPInternalBase)binding).clone();
|
||||
IBinding base = binding.getBaseClass();
|
||||
if (base instanceof IType) {
|
||||
IType specBase = CPPTemplates.instantiateType((IType) base, argumentMap, specScope);
|
||||
IType specBase= specializeType((IType) base);
|
||||
specBase = SemanticUtil.getUltimateType(specBase, false);
|
||||
if (specBase instanceof IBinding && !(specBase instanceof IProblemBinding)) {
|
||||
((ICPPInternalBase)specBinding).setBaseClass((IBinding)specBase);
|
||||
|
@ -105,7 +118,7 @@ public class CPPClassSpecialization extends CPPSpecialization implements
|
|||
bindings[i] = new CPPBaseClause(bases[i]);
|
||||
IBinding base = bindings[i].getBaseClass();
|
||||
if (base instanceof IType) {
|
||||
IType specBase = CPPTemplates.instantiateType((IType) base, argumentMap, specScope);
|
||||
IType specBase = specializeType((IType) base);
|
||||
if (specBase instanceof ICPPClassType) {
|
||||
((CPPBaseClause) bindings[i]).setBaseClass((ICPPClassType) specBase);
|
||||
}
|
||||
|
@ -252,7 +265,7 @@ public class CPPClassSpecialization extends CPPSpecialization implements
|
|||
if (getDefinition() != null)
|
||||
return getCompositeTypeSpecifier().getKey();
|
||||
|
||||
return ((ICPPClassType)getSpecializedBinding()).getKey();
|
||||
return (getSpecializedBinding()).getKey();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
@ -279,7 +292,7 @@ public class CPPClassSpecialization extends CPPSpecialization implements
|
|||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.IType#isSameType(org.eclipse.cdt.core.dom.ast.IType)
|
||||
*/
|
||||
public boolean isSameType(IType type) {
|
||||
public final boolean isSameType(IType type) {
|
||||
if( type == this )
|
||||
return true;
|
||||
if( type instanceof ITypedef || type instanceof IIndexType )
|
||||
|
|
|
@ -13,170 +13,25 @@
|
|||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
||||
|
||||
import org.eclipse.cdt.core.dom.IName;
|
||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IScope;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassScope;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassTemplatePartialSpecialization;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassSpecialization;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization;
|
||||
import org.eclipse.cdt.core.index.IIndexFileSet;
|
||||
import org.eclipse.cdt.core.parser.util.ArrayUtil;
|
||||
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
|
||||
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.IASTInternalScope;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPSemantics;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPTemplates;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
|
||||
|
||||
/**
|
||||
* @author aniefer
|
||||
*/
|
||||
public class CPPClassSpecializationScope implements ICPPClassSpecializationScope, IASTInternalScope {
|
||||
private ObjectMap instanceMap = ObjectMap.EMPTY_MAP;
|
||||
final private ICPPSpecialization specialization;
|
||||
public class CPPClassSpecializationScope extends AbstractCPPClassSpecializationScope implements IASTInternalScope {
|
||||
|
||||
public CPPClassSpecializationScope(ICPPSpecialization specialization) {
|
||||
this.specialization = specialization;
|
||||
public CPPClassSpecializationScope(ICPPClassSpecialization specialization) {
|
||||
super(specialization);
|
||||
}
|
||||
|
||||
public ICPPClassType getOriginalClassType() {
|
||||
return (ICPPClassType) specialization.getSpecializedBinding();
|
||||
}
|
||||
|
||||
public IBinding getInstance(IBinding binding) {
|
||||
if (instanceMap.containsKey(binding)) {
|
||||
return (IBinding) instanceMap.get(binding);
|
||||
} else if (!(binding instanceof ICPPClassTemplatePartialSpecialization)) {
|
||||
IBinding spec = CPPTemplates.createSpecialization(this, binding, specialization.getArgumentMap());
|
||||
if (instanceMap == ObjectMap.EMPTY_MAP)
|
||||
instanceMap = new ObjectMap(2);
|
||||
instanceMap.put(binding, spec);
|
||||
return spec;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public final IBinding getBinding(IASTName name, boolean resolve) throws DOMException {
|
||||
return getBinding(name, resolve, IIndexFileSet.EMPTY);
|
||||
}
|
||||
|
||||
public final IBinding[] getBindings(IASTName name, boolean resolve, boolean prefix) throws DOMException {
|
||||
return getBindings(name, resolve, prefix, IIndexFileSet.EMPTY);
|
||||
}
|
||||
|
||||
public IBinding getBinding(IASTName name, boolean forceResolve, IIndexFileSet fileSet) throws DOMException {
|
||||
char[] c = name.toCharArray();
|
||||
|
||||
if (CharArrayUtils.equals(c, specialization.getNameCharArray()) &&
|
||||
!CPPClassScope.isConstructorReference(name)) {
|
||||
return specialization;
|
||||
}
|
||||
|
||||
ICPPClassType specialized = (ICPPClassType) specialization.getSpecializedBinding();
|
||||
IScope classScope = specialized.getCompositeScope();
|
||||
IBinding[] bindings = classScope != null ? classScope.getBindings(name, forceResolve, false) : null;
|
||||
|
||||
if (bindings == null)
|
||||
return null;
|
||||
|
||||
IBinding[] specs = new IBinding[0];
|
||||
for (IBinding binding : bindings) {
|
||||
specs = (IBinding[]) ArrayUtil.append(IBinding.class, specs, getInstance(binding));
|
||||
}
|
||||
specs = (IBinding[]) ArrayUtil.trim(IBinding.class, specs);
|
||||
return CPPSemantics.resolveAmbiguities(name, specs);
|
||||
}
|
||||
|
||||
public IBinding[] getBindings(IASTName name, boolean forceResolve, boolean prefixLookup,
|
||||
IIndexFileSet fileSet) throws DOMException {
|
||||
char[] c = name.toCharArray();
|
||||
IBinding[] result = null;
|
||||
|
||||
if ((!prefixLookup && CharArrayUtils.equals(c, specialization.getNameCharArray())) ||
|
||||
(prefixLookup && CharArrayUtils.equals(specialization.getNameCharArray(), 0, c.length, c, true))) {
|
||||
result = new IBinding[] { specialization };
|
||||
}
|
||||
|
||||
ICPPClassType specialized = (ICPPClassType) specialization.getSpecializedBinding();
|
||||
IScope classScope = specialized.getCompositeScope();
|
||||
IBinding[] bindings = classScope != null ?
|
||||
classScope.getBindings(name, forceResolve, prefixLookup, fileSet) : null;
|
||||
|
||||
if (bindings != null) {
|
||||
for (IBinding binding : bindings) {
|
||||
result = (IBinding[]) ArrayUtil.append(IBinding.class, result, getInstance(binding));
|
||||
}
|
||||
}
|
||||
|
||||
return (IBinding[]) ArrayUtil.trim(IBinding.class, result);
|
||||
}
|
||||
|
||||
public ICPPClassType getClassType() {
|
||||
return (ICPPClassType) specialization;
|
||||
}
|
||||
|
||||
public ICPPMethod[] getImplicitMethods() {
|
||||
// Implicit methods shouldn't have implicit specializations
|
||||
return ICPPMethod.EMPTY_CPPMETHOD_ARRAY;
|
||||
}
|
||||
|
||||
public IName getScopeName() {
|
||||
if (specialization instanceof ICPPInternalBinding)
|
||||
return (IASTName) ((ICPPInternalBinding) specialization).getDefinition();
|
||||
//TODO: get the scope name for non-internal bindings
|
||||
return null;
|
||||
}
|
||||
|
||||
protected ICPPConstructor[] getConstructors() throws DOMException {
|
||||
ICPPClassType specialized = (ICPPClassType) specialization.getSpecializedBinding();
|
||||
ICPPConstructor[] bindings = specialized.getConstructors();
|
||||
|
||||
if (bindings == null) return ICPPConstructor.EMPTY_CONSTRUCTOR_ARRAY;
|
||||
|
||||
ICPPConstructor[] specs = new ICPPConstructor[0];
|
||||
for (ICPPConstructor binding : bindings) {
|
||||
specs = (ICPPConstructor[]) ArrayUtil.append(ICPPConstructor.class, specs, getInstance(binding));
|
||||
}
|
||||
return (ICPPConstructor[]) ArrayUtil.trim(ICPPConstructor.class, specs);
|
||||
}
|
||||
|
||||
protected ICPPMethod[] getDeclaredMethods() throws DOMException {
|
||||
ICPPClassType specialized = (ICPPClassType) specialization.getSpecializedBinding();
|
||||
ICPPMethod[] bindings = specialized.getDeclaredMethods();
|
||||
|
||||
if (bindings == null) return ICPPMethod.EMPTY_CPPMETHOD_ARRAY;
|
||||
|
||||
ICPPMethod[] specs = new ICPPMethod[0];
|
||||
for (ICPPMethod binding : bindings) {
|
||||
specs = (ICPPMethod[]) ArrayUtil.append(ICPPMethod.class, specs, getInstance(binding));
|
||||
}
|
||||
return (ICPPMethod[]) ArrayUtil.trim(ICPPMethod.class, specs);
|
||||
}
|
||||
|
||||
public IScope getParent() throws DOMException {
|
||||
ICPPClassType cls = getOriginalClassType();
|
||||
ICPPClassScope scope = (ICPPClassScope)cls.getCompositeScope();
|
||||
if (scope != null)
|
||||
return scope.getParent();
|
||||
if (cls instanceof ICPPInternalBinding) {
|
||||
IASTNode[] nds = ((ICPPInternalBinding)cls).getDeclarations();
|
||||
if (nds != null && nds.length > 0)
|
||||
return CPPVisitor.getContainingScope(nds[0]);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public IBinding[] find(String name) throws DOMException {
|
||||
return CPPSemantics.findBindings(this, name, false);
|
||||
}
|
||||
|
||||
public boolean isFullyCached() throws DOMException {
|
||||
ICPPScope origScope = (ICPPScope) getOriginalClassType().getCompositeScope();
|
||||
|
@ -196,10 +51,4 @@ public class CPPClassSpecializationScope implements ICPPClassSpecializationScope
|
|||
public IASTNode getPhysicalNode() { return null; }
|
||||
public void removeBinding(IBinding binding) {}
|
||||
public void addBinding(IBinding binding) {}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
IName name = getScopeName();
|
||||
return name != null ? name.toString() : String.valueOf(specialization);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,16 +39,13 @@ 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.ICPPField;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization;
|
||||
import org.eclipse.cdt.core.parser.util.ArrayUtil;
|
||||
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
|
||||
import org.eclipse.cdt.core.parser.util.ObjectMap;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
|
||||
import org.eclipse.cdt.internal.core.index.IIndexType;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author aniefer
|
||||
* Represents a class template.
|
||||
*/
|
||||
public class CPPClassTemplate extends CPPTemplateDefinition implements
|
||||
ICPPClassTemplate, ICPPClassType, ICPPInternalClassTemplate,
|
||||
|
@ -116,16 +113,6 @@ public class CPPClassTemplate extends CPPTemplateDefinition implements
|
|||
this.mixin= new ClassTypeMixin(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ICPPSpecialization deferredInstance(ObjectMap argMap, IType[] arguments) {
|
||||
ICPPSpecialization instance = getInstance(arguments);
|
||||
if (instance == null) {
|
||||
instance = new CPPDeferredClassInstance(this, argMap, arguments);
|
||||
addSpecialization(arguments, instance);
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
public void checkForDefinition() {
|
||||
FindDefinitionAction action = new FindDefinitionAction();
|
||||
IASTNode node = CPPVisitor.getContainingBlockItem(declarations[0]).getParent();
|
||||
|
|
|
@ -17,13 +17,10 @@ import org.eclipse.cdt.core.dom.ast.IType;
|
|||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateId;
|
||||
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.ICPPScope;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter;
|
||||
import org.eclipse.cdt.core.parser.util.ObjectMap;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPTemplates;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil;
|
||||
|
||||
/**
|
||||
* @author aniefer
|
||||
|
@ -58,35 +55,6 @@ public class CPPClassTemplatePartialSpecialization extends CPPClassTemplate impl
|
|||
return (ICPPClassTemplate) id.getTemplateName().resolveBinding();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBinding instantiate( IType [] args ){
|
||||
args= SemanticUtil.getSimplifiedTypes(args);
|
||||
ICPPSpecialization instance = getInstance( args );
|
||||
if( instance != null ){
|
||||
return instance;
|
||||
}
|
||||
|
||||
ObjectMap argMap= CPPTemplates.deduceTemplateArguments(getArguments(), args, true);
|
||||
if (argMap == null)
|
||||
return null;
|
||||
|
||||
if (CPPTemplates.containsDependentArg(argMap)) {
|
||||
return deferredInstance(argMap, args);
|
||||
}
|
||||
|
||||
ICPPTemplateParameter [] params = getTemplateParameters();
|
||||
int numParams = params.length;
|
||||
for( int i = 0; i < numParams; i++ ){
|
||||
if( params[i] instanceof IType && !argMap.containsKey( params[i] ) )
|
||||
return null;
|
||||
}
|
||||
|
||||
instance = (ICPPTemplateInstance) CPPTemplates.createInstance( (ICPPScope) getScope(), this, argMap, args );
|
||||
addSpecialization( args, instance );
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
public IBinding getSpecializedBinding() {
|
||||
return getPrimaryClassTemplate();
|
||||
}
|
||||
|
|
|
@ -13,35 +13,25 @@
|
|||
package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IProblemBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IType;
|
||||
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.ICPPScope;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateDefinition;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter;
|
||||
import org.eclipse.cdt.core.parser.util.ObjectMap;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPTemplates;
|
||||
|
||||
/**
|
||||
* @author aniefer
|
||||
*
|
||||
* Represents a specialization of a class-template
|
||||
*/
|
||||
public class CPPClassTemplateSpecialization extends CPPClassSpecialization
|
||||
implements ICPPClassTemplate, ICPPInternalClassTemplate {
|
||||
|
||||
private ObjectMap instances = null;
|
||||
|
||||
/**
|
||||
* @param specialized
|
||||
* @param scope
|
||||
* @param argumentMap
|
||||
*/
|
||||
public CPPClassTemplateSpecialization(IBinding specialized, ICPPScope scope,
|
||||
ObjectMap argumentMap) {
|
||||
super(specialized, scope, argumentMap);
|
||||
public CPPClassTemplateSpecialization(ICPPClassTemplate orig, ICPPClassType owner, ObjectMap argumentMap) {
|
||||
super(orig, owner, argumentMap);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
@ -59,67 +49,42 @@ public class CPPClassTemplateSpecialization extends CPPClassSpecialization
|
|||
return template.getTemplateParameters();
|
||||
}
|
||||
|
||||
public void addSpecialization(IType[] arguments, ICPPSpecialization specialization) {
|
||||
public void addInstance(IType[] arguments, ICPPTemplateInstance instance) {
|
||||
if (instances == null)
|
||||
instances = new ObjectMap(2);
|
||||
instances.put(arguments, specialization);
|
||||
instances.put(arguments, instance);
|
||||
}
|
||||
|
||||
public ICPPSpecialization getInstance(IType[] arguments) {
|
||||
if (instances == null)
|
||||
return null;
|
||||
|
||||
int found = -1;
|
||||
for (int i = 0; i < instances.size(); i++) {
|
||||
IType[] args = (IType[]) instances.keyAt(i);
|
||||
if (args.length == arguments.length) {
|
||||
int j = 0;
|
||||
for(; j < args.length; j++) {
|
||||
if (!CPPTemplates.isSameTemplateArgument(args[j], arguments[j]))
|
||||
break;
|
||||
}
|
||||
if (j == args.length) {
|
||||
found = i;
|
||||
break;
|
||||
public ICPPTemplateInstance getInstance(IType[] arguments) {
|
||||
if (instances != null) {
|
||||
loop: for (int i=0; i < instances.size(); i++) {
|
||||
IType[] args = (IType[]) instances.keyAt(i);
|
||||
if (args.length == arguments.length) {
|
||||
for (int j=0; j < args.length; j++) {
|
||||
if (!CPPTemplates.isSameTemplateArgument(args[j], arguments[j])) {
|
||||
continue loop;
|
||||
}
|
||||
}
|
||||
return (ICPPTemplateInstance) instances.getAt(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (found != -1) {
|
||||
return (ICPPSpecialization) instances.getAt(found);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public IBinding instantiate(IType[] arguments) {
|
||||
ICPPTemplateDefinition template = null;
|
||||
|
||||
try {
|
||||
template = CPPTemplates.matchTemplatePartialSpecialization(this, arguments);
|
||||
} catch (DOMException e) {
|
||||
return e.getProblem();
|
||||
public ICPPTemplateInstance[] getAllInstances() {
|
||||
if (instances != null) {
|
||||
ICPPTemplateInstance[] result= new ICPPTemplateInstance[instances.size()];
|
||||
for (int i=0; i < instances.size(); i++) {
|
||||
result[i]= (ICPPTemplateInstance) instances.getAt(i);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
if (template instanceof IProblemBinding) {
|
||||
return template;
|
||||
}
|
||||
if (template != null && template instanceof ICPPClassTemplatePartialSpecialization) {
|
||||
return ((ICPPInternalTemplateInstantiator) template).instantiate(arguments);
|
||||
}
|
||||
|
||||
return CPPTemplates.instantiateTemplate(this, arguments, argumentMap);
|
||||
}
|
||||
|
||||
public ICPPSpecialization deferredInstance(ObjectMap argMap, IType[] arguments) {
|
||||
ICPPSpecialization instance = getInstance(arguments);
|
||||
if (instance == null) {
|
||||
instance = new CPPDeferredClassInstance(this, argMap, arguments);
|
||||
addSpecialization(arguments, instance);
|
||||
}
|
||||
return instance;
|
||||
return ICPPTemplateInstance.EMPTY_TEMPLATE_INSTANCE_ARRAY;
|
||||
}
|
||||
|
||||
public void addPartialSpecialization(ICPPClassTemplatePartialSpecialization spec) {
|
||||
//should not occur
|
||||
//should not occur mstodo- why not??
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -458,4 +458,8 @@ public class CPPClassType extends PlatformObject implements ICPPInternalClassTyp
|
|||
public String toString() {
|
||||
return getName();
|
||||
}
|
||||
|
||||
public IBinding getOwner() throws DOMException {
|
||||
return CPPVisitor.findDeclarationOwner(definition != null ? definition : declarations[0], true);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2004, 2006 IBM Corporation and others.
|
||||
* Copyright (c) 2004, 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
|
||||
|
@ -21,7 +21,6 @@ import org.eclipse.cdt.core.dom.ast.IBinding;
|
|||
import org.eclipse.cdt.core.dom.ast.IScope;
|
||||
import org.eclipse.cdt.core.parser.util.ArrayUtil;
|
||||
import org.eclipse.cdt.internal.core.dom.Linkage;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.PlatformObject;
|
||||
|
||||
/**
|
||||
|
@ -56,6 +55,10 @@ public class CPPCompositeBinding extends PlatformObject implements IBinding {
|
|||
return bindings[0].getScope();
|
||||
}
|
||||
|
||||
public IBinding getOwner() throws DOMException {
|
||||
return bindings[0].getOwner();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.IBinding#getPhysicalNode()
|
||||
*/
|
||||
|
@ -70,7 +73,7 @@ public class CPPCompositeBinding extends PlatformObject implements IBinding {
|
|||
return bindings;
|
||||
}
|
||||
|
||||
public ILinkage getLinkage() throws CoreException {
|
||||
public ILinkage getLinkage() {
|
||||
return Linkage.CPP_LINKAGE;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,20 +1,20 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2007 QNX Software Systems and others.
|
||||
* Copyright (c) 2007, 2008 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
|
||||
* QNX - 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.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IType;
|
||||
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.ICPPScope;
|
||||
import org.eclipse.cdt.core.parser.util.ObjectMap;
|
||||
|
||||
/**
|
||||
|
@ -24,14 +24,8 @@ import org.eclipse.cdt.core.parser.util.ObjectMap;
|
|||
public class CPPConstructorInstance extends CPPMethodInstance implements
|
||||
ICPPConstructor {
|
||||
|
||||
/**
|
||||
* @param scope
|
||||
* @param orig
|
||||
* @param argMap
|
||||
* @param args
|
||||
*/
|
||||
public CPPConstructorInstance(ICPPScope scope, IBinding orig, ObjectMap argMap, IType[] args) {
|
||||
super(scope, orig, argMap, args);
|
||||
public CPPConstructorInstance(ICPPClassType owner, ICPPConstructor orig, ObjectMap argMap, IType[] args) {
|
||||
super(owner, orig, argMap, args);
|
||||
}
|
||||
|
||||
public boolean isExplicit() throws DOMException {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*************************************************************************
|
||||
* Copyright (c) 2005 IBM Corporation and others.
|
||||
* 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
|
||||
|
@ -7,33 +7,24 @@
|
|||
*
|
||||
* Contributors:
|
||||
* IBM Corporation - initial API and implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
*******************************************************************************/
|
||||
/*
|
||||
* Created on June 14, 2005
|
||||
*/
|
||||
|
||||
package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope;
|
||||
import org.eclipse.cdt.core.parser.util.ObjectMap;
|
||||
|
||||
/**
|
||||
* @author aniefer
|
||||
*
|
||||
* Specialization of a constructor for a class-template or class-template specialization
|
||||
*/
|
||||
public class CPPConstructorSpecialization extends CPPMethodSpecialization
|
||||
implements ICPPConstructor {
|
||||
|
||||
/**
|
||||
* @param orig
|
||||
* @param scope
|
||||
* @param argMap
|
||||
*/
|
||||
public CPPConstructorSpecialization(IBinding orig, ICPPScope scope, ObjectMap argMap) {
|
||||
super(orig, scope, argMap);
|
||||
public CPPConstructorSpecialization(IBinding orig, ICPPClassType owner, ObjectMap argMap) {
|
||||
super(orig, owner, argMap);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
@ -42,5 +33,4 @@ public class CPPConstructorSpecialization extends CPPMethodSpecialization
|
|||
public boolean isExplicit() throws DOMException {
|
||||
return ((ICPPConstructor)getSpecializedBinding()).isExplicit();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,39 +1,30 @@
|
|||
/*************************************************************************
|
||||
* Copyright (c) 2005 IBM Corporation and others.
|
||||
* 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:
|
||||
* IBM Corporation - initial API and implementation
|
||||
* IBM Corporation - initial API and implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
*******************************************************************************/
|
||||
/*
|
||||
* Created on June 14, 2005
|
||||
*/
|
||||
package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope;
|
||||
import org.eclipse.cdt.core.parser.util.ObjectMap;
|
||||
|
||||
/**
|
||||
* @author aniefer
|
||||
*
|
||||
* Specialization of a constructor template
|
||||
*/
|
||||
public class CPPConstructorTemplateSpecialization extends
|
||||
CPPMethodTemplateSpecialization implements ICPPConstructor {
|
||||
public class CPPConstructorTemplateSpecialization extends CPPMethodTemplateSpecialization implements ICPPConstructor {
|
||||
|
||||
/**
|
||||
* @param specialized
|
||||
* @param scope
|
||||
* @param argumentMap
|
||||
*/
|
||||
public CPPConstructorTemplateSpecialization(IBinding specialized,
|
||||
ICPPScope scope, ObjectMap argumentMap) {
|
||||
super(specialized, scope, argumentMap);
|
||||
ICPPClassType owner, ObjectMap argumentMap) {
|
||||
super(specialized, owner, argumentMap);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
@ -42,5 +33,4 @@ public class CPPConstructorTemplateSpecialization extends
|
|||
public boolean isExplicit() throws DOMException {
|
||||
return ((ICPPConstructor)getSpecializedBinding()).isExplicit();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -18,31 +18,26 @@ import org.eclipse.cdt.core.dom.ast.IScope;
|
|||
import org.eclipse.cdt.core.dom.ast.IType;
|
||||
import org.eclipse.cdt.core.dom.ast.ITypedef;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassTemplate;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateDefinition;
|
||||
import org.eclipse.cdt.core.parser.util.ObjectMap;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPTemplates;
|
||||
|
||||
/**
|
||||
* Represents a partially instantiated class template, where instance arguments contain at least one
|
||||
* template type parameter.
|
||||
*
|
||||
* @author aniefer
|
||||
* Represents a instantiation that cannot be performed because of dependent arguments or an unknown template.
|
||||
*/
|
||||
public class CPPDeferredClassInstance extends CPPUnknownClass implements ICPPDeferredClassInstance {
|
||||
|
||||
private final IType[] fArguments;
|
||||
private final ObjectMap fArgmap;
|
||||
private final ICPPClassTemplate fClassTemplate;
|
||||
|
||||
public CPPDeferredClassInstance(ICPPClassTemplate orig, ObjectMap argMap, IType[] arguments) {
|
||||
super(orig);
|
||||
fArgmap= argMap;
|
||||
public CPPDeferredClassInstance(ICPPClassTemplate template, IType[] arguments) throws DOMException {
|
||||
super(template.getOwner(), new CPPASTName(template.getNameCharArray()));
|
||||
|
||||
fArguments= arguments;
|
||||
fClassTemplate= orig;
|
||||
fClassTemplate= template;
|
||||
}
|
||||
|
||||
private ICPPClassTemplate getClassTemplate() {
|
||||
public ICPPClassTemplate getClassTemplate() {
|
||||
return (ICPPClassTemplate) getSpecializedBinding();
|
||||
}
|
||||
|
||||
|
@ -100,25 +95,8 @@ public class CPPDeferredClassInstance extends CPPUnknownClass implements ICPPDef
|
|||
}
|
||||
|
||||
public ObjectMap getArgumentMap() {
|
||||
return fArgmap;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBinding resolvePartially(ICPPUnknownBinding parentBinding, ObjectMap argMap, ICPPScope instantiationScope) {
|
||||
IType[] arguments = getArguments();
|
||||
IType[] newArgs = CPPTemplates.instantiateTypes(arguments, argMap, instantiationScope);
|
||||
|
||||
boolean changed= arguments != newArgs;
|
||||
ICPPClassTemplate classTemplate = getClassTemplate();
|
||||
if (argMap.containsKey(classTemplate)) {
|
||||
classTemplate = (ICPPClassTemplate) argMap.get(classTemplate);
|
||||
changed= true;
|
||||
}
|
||||
|
||||
if (!changed) {
|
||||
return this;
|
||||
}
|
||||
return ((ICPPInternalTemplateInstantiator) classTemplate).instantiate(newArgs);
|
||||
// mstodo- compute argmap
|
||||
return null;
|
||||
}
|
||||
|
||||
public IBinding getSpecializedBinding() {
|
||||
|
|
|
@ -33,71 +33,79 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
|
|||
/**
|
||||
* @author aniefer
|
||||
*/
|
||||
public class CPPDeferredFunctionInstance extends CPPInstance implements ICPPFunction, ICPPInternalFunction, ICPPDeferredTemplateInstance {
|
||||
private IParameter [] parameters;
|
||||
private IType[] arguments;
|
||||
private IFunctionType functionType;
|
||||
public class CPPDeferredFunctionInstance extends CPPUnknownBinding implements ICPPFunction, ICPPInternalFunction, ICPPDeferredTemplateInstance {
|
||||
private IType[] fArguments;
|
||||
private ICPPFunctionTemplate fFunctionTemplate;
|
||||
|
||||
private ObjectMap fArgmap;
|
||||
private IParameter [] fParameters;
|
||||
private IFunctionType fFunctionType;
|
||||
|
||||
public CPPDeferredFunctionInstance( ICPPFunctionTemplate template, IType[] arguments ) {
|
||||
super( null, template, null, arguments );
|
||||
this.arguments = arguments;
|
||||
this.argumentMap = createArgumentMap( arguments );
|
||||
public CPPDeferredFunctionInstance( ICPPFunctionTemplate template, IType[] arguments ) throws DOMException {
|
||||
super(template.getOwner(), new CPPASTName(template.getNameCharArray()));
|
||||
fArguments= arguments;
|
||||
fFunctionTemplate= template;
|
||||
}
|
||||
|
||||
private ObjectMap createArgumentMap( IType [] args ){
|
||||
ICPPTemplateDefinition template = getTemplateDefinition();
|
||||
ICPPTemplateParameter [] params;
|
||||
try {
|
||||
params = template.getTemplateParameters();
|
||||
} catch (DOMException e) {
|
||||
return null;
|
||||
}
|
||||
ObjectMap map = new ObjectMap( params.length );
|
||||
for( int i = 0; i < params.length; i++ ){
|
||||
if( i < args.length )
|
||||
map.put( params[i], args[i] );
|
||||
}
|
||||
return map;
|
||||
public ICPPTemplateDefinition getTemplateDefinition() {
|
||||
return fFunctionTemplate;
|
||||
}
|
||||
|
||||
public IBinding getSpecializedBinding() {
|
||||
return fFunctionTemplate;
|
||||
}
|
||||
|
||||
public ObjectMap getArgumentMap() {
|
||||
if (fArgmap == null) {
|
||||
fArgmap= ObjectMap.EMPTY_MAP;
|
||||
try {
|
||||
ICPPTemplateParameter[] params= fFunctionTemplate.getTemplateParameters();
|
||||
ObjectMap result= new ObjectMap(params.length);
|
||||
for (int i=0; i < params.length; i++) {
|
||||
if (i < fArguments.length) {
|
||||
result.put(params[i], fArguments[i]);
|
||||
}
|
||||
}
|
||||
fArgmap= result;
|
||||
} catch (DOMException e) {
|
||||
}
|
||||
}
|
||||
return fArgmap;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public IType[] getArguments() {
|
||||
return arguments;
|
||||
return fArguments;
|
||||
}
|
||||
|
||||
public IParameter[] getParameters() throws DOMException {
|
||||
if( getArgumentMap() == null )
|
||||
ObjectMap map= getArgumentMap();
|
||||
if (map == null || map.isEmpty()) {
|
||||
return ((ICPPFunction)getTemplateDefinition()).getParameters();
|
||||
if( parameters == null ){
|
||||
}
|
||||
if( fParameters == null ){
|
||||
IParameter [] params = ((ICPPFunction)getTemplateDefinition()).getParameters();
|
||||
parameters = new IParameter[ params.length ];
|
||||
fParameters = new IParameter[ params.length ];
|
||||
for (int i = 0; i < params.length; i++) {
|
||||
parameters[i] = new CPPParameterSpecialization( (ICPPParameter)params[i], null, getArgumentMap() );
|
||||
fParameters[i] = new CPPParameterSpecialization( (ICPPParameter)params[i], null, getArgumentMap() );
|
||||
}
|
||||
}
|
||||
|
||||
return parameters;
|
||||
|
||||
return fParameters;
|
||||
}
|
||||
|
||||
|
||||
public IScope getFunctionScope() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public IFunctionType getType() throws DOMException {
|
||||
if( functionType == null ){
|
||||
if( fFunctionType == null ){
|
||||
IFunctionType ft = ((ICPPFunction)getTemplateDefinition()).getType();
|
||||
IType returnType = ft.getReturnType();
|
||||
// mstodo- is that necessary?
|
||||
returnType = CPPTemplates.instantiateType( returnType, getArgumentMap(), null);
|
||||
functionType = CPPVisitor.createImplicitFunctionType( returnType, getParameters(), null);
|
||||
fFunctionType = CPPVisitor.createImplicitFunctionType( returnType, getParameters(), null);
|
||||
}
|
||||
|
||||
return functionType;
|
||||
return fFunctionType;
|
||||
}
|
||||
|
||||
|
||||
|
@ -141,8 +149,7 @@ public class CPPDeferredFunctionInstance extends CPPInstance implements ICPPFunc
|
|||
}
|
||||
}
|
||||
|
||||
public IBinding resolveParameter( IASTParameterDeclaration param ) {
|
||||
// TODO Auto-generated method stub
|
||||
public IBinding resolveParameter(IASTParameterDeclaration param) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@ import org.eclipse.cdt.core.dom.ast.DOMException;
|
|||
import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IEnumeration;
|
||||
import org.eclipse.cdt.core.dom.ast.IEnumerator;
|
||||
import org.eclipse.cdt.core.dom.ast.IScope;
|
||||
|
@ -103,17 +104,12 @@ public class CPPEnumeration extends PlatformObject implements IEnumeration, ICPP
|
|||
}
|
||||
|
||||
public void addDefinition(IASTNode node) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
public void addDeclaration(IASTNode node) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
public void removeDeclaration(IASTNode node) {
|
||||
|
||||
}
|
||||
|
||||
public boolean isSameType( IType type ) {
|
||||
|
@ -127,4 +123,8 @@ public class CPPEnumeration extends PlatformObject implements IEnumeration, ICPP
|
|||
public ILinkage getLinkage() {
|
||||
return Linkage.CPP_LINKAGE;
|
||||
}
|
||||
|
||||
public IBinding getOwner() throws DOMException {
|
||||
return CPPVisitor.findDeclarationOwner(enumName, true);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@ import org.eclipse.cdt.core.dom.ast.DOMException;
|
|||
import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IEnumeration;
|
||||
import org.eclipse.cdt.core.dom.ast.IEnumerator;
|
||||
import org.eclipse.cdt.core.dom.ast.IScope;
|
||||
|
@ -119,23 +120,17 @@ public class CPPEnumerator extends PlatformObject implements IEnumerator, ICPPIn
|
|||
return true;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBinding#addDefinition(org.eclipse.cdt.core.dom.ast.IASTNode)
|
||||
*/
|
||||
public void addDefinition(IASTNode node) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBinding#addDeclaration(org.eclipse.cdt.core.dom.ast.IASTNode)
|
||||
*/
|
||||
public void addDeclaration(IASTNode node) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
public ILinkage getLinkage() {
|
||||
return Linkage.CPP_LINKAGE;
|
||||
}
|
||||
|
||||
public IBinding getOwner() throws DOMException {
|
||||
return CPPVisitor.findDeclarationOwner(enumName, true);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,9 +17,7 @@ import org.eclipse.cdt.core.dom.ast.ICompositeType;
|
|||
import org.eclipse.cdt.core.dom.ast.IType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPField;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope;
|
||||
import org.eclipse.cdt.core.parser.util.ObjectMap;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPTemplates;
|
||||
|
||||
/**
|
||||
* @author aniefer
|
||||
|
@ -27,8 +25,8 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPTemplates;
|
|||
public class CPPFieldSpecialization extends CPPSpecialization implements ICPPField {
|
||||
private IType type = null;
|
||||
|
||||
public CPPFieldSpecialization( IBinding orig, ICPPScope scope, ObjectMap argMap ) {
|
||||
super(orig, scope, argMap);
|
||||
public CPPFieldSpecialization( IBinding orig, ICPPClassType owner, ObjectMap argMap ) {
|
||||
super(orig, owner, argMap);
|
||||
}
|
||||
|
||||
private ICPPField getField() {
|
||||
|
@ -44,8 +42,8 @@ public class CPPFieldSpecialization extends CPPSpecialization implements ICPPFie
|
|||
}
|
||||
|
||||
public IType getType() throws DOMException {
|
||||
if( type == null ){
|
||||
type = CPPTemplates.instantiateType( getField().getType(), argumentMap, getScope());
|
||||
if (type == null) {
|
||||
type= specializeType(getField().getType());
|
||||
}
|
||||
return type;
|
||||
}
|
||||
|
|
|
@ -539,4 +539,8 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt
|
|||
result.append(t != null ? ASTTypeUtil.getParameterTypeString(t) : "()"); //$NON-NLS-1$
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
public IBinding getOwner() throws DOMException {
|
||||
return CPPVisitor.findNameOwner(getASTName(), false);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,147 +12,44 @@
|
|||
package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.dom.ast.ASTTypeUtil;
|
||||
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.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;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPParameter;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateDefinition;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance;
|
||||
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;
|
||||
|
||||
/**
|
||||
* @author aniefer
|
||||
*/
|
||||
public class CPPFunctionInstance extends CPPInstance implements ICPPFunction, ICPPInternalFunction {
|
||||
private IFunctionType type = null;
|
||||
private IParameter [] parameters = null;
|
||||
/**
|
||||
* @param scope
|
||||
* @param orig
|
||||
* @param argMap
|
||||
* @param args
|
||||
*/
|
||||
public CPPFunctionInstance(ICPPScope scope, IBinding orig, ObjectMap argMap, IType[] args) {
|
||||
super(scope, orig, argMap, args);
|
||||
public class CPPFunctionInstance extends CPPFunctionSpecialization implements ICPPTemplateInstance {
|
||||
private IType[] arguments;
|
||||
|
||||
public CPPFunctionInstance(IBinding owner, ICPPFunction orig, ObjectMap argMap, IType[] args) {
|
||||
super(orig, owner, argMap);
|
||||
this.arguments = args;
|
||||
}
|
||||
|
||||
public ICPPTemplateDefinition getTemplateDefinition() {
|
||||
return (ICPPTemplateDefinition) getSpecializedBinding();
|
||||
}
|
||||
|
||||
public IType[] getArguments() {
|
||||
return arguments;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.IFunction#getParameters()
|
||||
* For debug purposes only
|
||||
*/
|
||||
public IParameter[] getParameters() throws DOMException {
|
||||
if( parameters == null ){
|
||||
IParameter [] params = ((ICPPFunction)getTemplateDefinition()).getParameters();
|
||||
parameters = new IParameter[ params.length ];
|
||||
for (int i = 0; i < params.length; i++) {
|
||||
parameters[i] = new CPPParameterSpecialization( (ICPPParameter)params[i], null, getArgumentMap() );
|
||||
}
|
||||
}
|
||||
|
||||
return parameters;
|
||||
@Override
|
||||
public String toString() {
|
||||
return getName() + " <" + ASTTypeUtil.getTypeListString(arguments) + ">"; //$NON-NLS-1$ //$NON-NLS-2$
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.IFunction#getFunctionScope()
|
||||
*/
|
||||
public IScope getFunctionScope() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.IFunction#getType()
|
||||
*/
|
||||
public IFunctionType getType() throws DOMException {
|
||||
if( type == null ){
|
||||
type = (IFunctionType) CPPTemplates.instantiateType( ((ICPPFunction)getTemplateDefinition()).getType(), getArgumentMap(), getScope() );
|
||||
}
|
||||
return type;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.IFunction#isStatic()
|
||||
*/
|
||||
public boolean isStatic() throws DOMException {
|
||||
return ((ICPPFunction)getTemplateDefinition()).isStatic();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction#isMutable()
|
||||
*/
|
||||
public boolean isMutable() throws DOMException {
|
||||
return ((ICPPFunction)getTemplateDefinition()).isMutable();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction#isInline()
|
||||
*/
|
||||
public boolean isInline() throws DOMException {
|
||||
return ((ICPPFunction)getTemplateDefinition()).isInline();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction#isInline()
|
||||
*/
|
||||
public boolean isExternC() throws DOMException {
|
||||
return ((ICPPFunction)getTemplateDefinition()).isExternC();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.IFunction#isExtern()
|
||||
*/
|
||||
public boolean isExtern() throws DOMException {
|
||||
return ((ICPPFunction)getTemplateDefinition()).isExtern();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.IFunction#isAuto()
|
||||
*/
|
||||
public boolean isAuto() throws DOMException {
|
||||
return ((ICPPFunction)getTemplateDefinition()).isAuto();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.IFunction#isRegister()
|
||||
*/
|
||||
public boolean isRegister() throws DOMException {
|
||||
return ((ICPPFunction)getTemplateDefinition()).isRegister();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.IFunction#takesVarArgs()
|
||||
*/
|
||||
public boolean takesVarArgs() throws DOMException {
|
||||
return ((ICPPFunction)getTemplateDefinition()).takesVarArgs();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalFunction#isStatic(boolean)
|
||||
*/
|
||||
public boolean isStatic( boolean resolveAll ) {
|
||||
ICPPFunction func = (ICPPFunction) getTemplateDefinition();
|
||||
try {
|
||||
return ASTInternal.isStatic(func, resolveAll);
|
||||
} catch (DOMException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalFunction#resolveParameter(org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration)
|
||||
*/
|
||||
public IBinding resolveParameter( IASTParameterDeclaration param ) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if( (obj instanceof ICPPTemplateInstance) && (obj instanceof ICPPFunction)){
|
||||
|
|
|
@ -27,10 +27,8 @@ import org.eclipse.cdt.core.dom.ast.IScope;
|
|||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPParameter;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope;
|
||||
import org.eclipse.cdt.core.index.IIndexBinding;
|
||||
import org.eclipse.cdt.core.parser.util.ObjectMap;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPTemplates;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
|
||||
|
||||
/**
|
||||
|
@ -40,8 +38,8 @@ public class CPPFunctionSpecialization extends CPPSpecialization implements ICPP
|
|||
private IFunctionType type = null;
|
||||
private IParameter[] specializedParams = null;
|
||||
|
||||
public CPPFunctionSpecialization(IBinding orig, ICPPScope scope, ObjectMap argMap) {
|
||||
super(orig, scope, argMap);
|
||||
public CPPFunctionSpecialization(IBinding orig, IBinding owner, ObjectMap argMap) {
|
||||
super(orig, owner, argMap);
|
||||
}
|
||||
|
||||
private ICPPFunction getFunction() {
|
||||
|
@ -55,7 +53,7 @@ public class CPPFunctionSpecialization extends CPPSpecialization implements ICPP
|
|||
specializedParams = new IParameter[params.length];
|
||||
for (int i = 0; i < params.length; i++) {
|
||||
specializedParams[i] = new CPPParameterSpecialization((ICPPParameter)params[i],
|
||||
(ICPPScope) getScope(), argumentMap);
|
||||
this, argumentMap);
|
||||
}
|
||||
}
|
||||
return specializedParams;
|
||||
|
@ -74,8 +72,7 @@ public class CPPFunctionSpecialization extends CPPSpecialization implements ICPP
|
|||
public IFunctionType getType() throws DOMException {
|
||||
if (type == null) {
|
||||
ICPPFunction function = (ICPPFunction) getSpecializedBinding();
|
||||
type = function.getType();
|
||||
type = (IFunctionType) CPPTemplates.instantiateType(type, argumentMap, getScope());
|
||||
type = (IFunctionType) specializeType(function.getType());
|
||||
}
|
||||
|
||||
return type;
|
||||
|
|
|
@ -32,9 +32,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator;
|
|||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassTemplatePartialSpecialization;
|
||||
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.ICPPSpecialization;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter;
|
||||
import org.eclipse.cdt.core.parser.util.ObjectMap;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
|
||||
|
||||
|
@ -255,17 +253,6 @@ public class CPPFunctionTemplate extends CPPTemplateDefinition implements ICPPFu
|
|||
return binding;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ICPPSpecialization deferredInstance(ObjectMap argMap, IType[] arguments) {
|
||||
ICPPSpecialization instance = getInstance( arguments );
|
||||
if( instance == null ){
|
||||
instance = new CPPDeferredFunctionInstance( this, arguments );
|
||||
addSpecialization( arguments, instance );
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
public boolean isStatic() {
|
||||
return hasStorageClass( IASTDeclSpecifier.sc_static);
|
||||
}
|
||||
|
|
|
@ -14,9 +14,9 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
|||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionTemplate;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter;
|
||||
import org.eclipse.cdt.core.parser.util.ObjectMap;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPTemplates;
|
||||
|
@ -30,8 +30,8 @@ public class CPPFunctionTemplateSpecialization extends CPPFunctionSpecialization
|
|||
|
||||
private ObjectMap instances = null;
|
||||
|
||||
public CPPFunctionTemplateSpecialization(IBinding specialized, ICPPScope scope, ObjectMap argumentMap) {
|
||||
super(specialized, scope, argumentMap);
|
||||
public CPPFunctionTemplateSpecialization(IBinding specialized, ICPPClassType owner, ObjectMap argumentMap) {
|
||||
super(specialized, owner, argumentMap);
|
||||
}
|
||||
|
||||
public ICPPTemplateParameter[] getTemplateParameters() throws DOMException {
|
||||
|
@ -39,42 +39,37 @@ public class CPPFunctionTemplateSpecialization extends CPPFunctionSpecialization
|
|||
return template.getTemplateParameters();
|
||||
}
|
||||
|
||||
public void addSpecialization(IType[] arguments, ICPPSpecialization specialization) {
|
||||
if( instances == null )
|
||||
public final void addInstance(IType[] arguments, ICPPTemplateInstance instance) {
|
||||
if (instances == null)
|
||||
instances = new ObjectMap(2);
|
||||
instances.put( arguments, specialization );
|
||||
instances.put(arguments, instance);
|
||||
}
|
||||
|
||||
public ICPPSpecialization getInstance( IType [] arguments ) {
|
||||
if( instances == null )
|
||||
return null;
|
||||
|
||||
int found = -1;
|
||||
for( int i = 0; i < instances.size(); i++ ){
|
||||
IType [] args = (IType[]) instances.keyAt( i );
|
||||
if( args.length == arguments.length ){
|
||||
int j = 0;
|
||||
for(; j < args.length; j++) {
|
||||
if(!CPPTemplates.isSameTemplateArgument(args[j], arguments[j]))
|
||||
break;
|
||||
}
|
||||
if( j == args.length ){
|
||||
found = i;
|
||||
break;
|
||||
|
||||
public final ICPPTemplateInstance getInstance(IType[] arguments) {
|
||||
if (instances != null) {
|
||||
loop: for (int i=0; i < instances.size(); i++) {
|
||||
IType[] args = (IType[]) instances.keyAt(i);
|
||||
if (args.length == arguments.length) {
|
||||
for (int j=0; j < args.length; j++) {
|
||||
if (!CPPTemplates.isSameTemplateArgument(args[j], arguments[j])) {
|
||||
continue loop;
|
||||
}
|
||||
}
|
||||
return (ICPPTemplateInstance) instances.getAt(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
if( found != -1 ){
|
||||
return (ICPPSpecialization) instances.getAt(found);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public IBinding instantiate(IType[] arguments) {
|
||||
return CPPTemplates.instantiateTemplate( this, arguments, argumentMap );
|
||||
}
|
||||
|
||||
public ICPPSpecialization deferredInstance(ObjectMap argMap, IType[] arguments) {
|
||||
return null;
|
||||
public ICPPTemplateInstance[] getAllInstances() {
|
||||
if (instances != null) {
|
||||
ICPPTemplateInstance[] result= new ICPPTemplateInstance[instances.size()];
|
||||
for (int i=0; i < instances.size(); i++) {
|
||||
result[i]= (ICPPTemplateInstance) instances.getAt(i);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
return ICPPTemplateInstance.EMPTY_TEMPLATE_INSTANCE_ARRAY;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -139,4 +139,9 @@ public class CPPImplicitFunction extends CPPFunction {
|
|||
public boolean takesVarArgs() {
|
||||
return takesVarArgs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBinding getOwner() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@ import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
|
|||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.IBasicType;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IFunctionType;
|
||||
import org.eclipse.cdt.core.dom.ast.IParameter;
|
||||
import org.eclipse.cdt.core.dom.ast.IType;
|
||||
|
@ -66,7 +67,7 @@ public class CPPImplicitMethod extends CPPImplicitFunction implements ICPPMethod
|
|||
return ICPPASTVisibilityLabel.v_public;
|
||||
}
|
||||
|
||||
public ICPPClassType getClassOwner() throws DOMException {
|
||||
public ICPPClassType getClassOwner() {
|
||||
ICPPClassScope scope = (ICPPClassScope)getScope();
|
||||
return scope.getClassType();
|
||||
}
|
||||
|
@ -169,4 +170,9 @@ public class CPPImplicitMethod extends CPPImplicitFunction implements ICPPMethod
|
|||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBinding getOwner() {
|
||||
return getClassOwner();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,56 +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:
|
||||
* IBM - Initial API and implementation
|
||||
*******************************************************************************/
|
||||
/*
|
||||
* Created on Mar 28, 2005
|
||||
*/
|
||||
package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.ASTTypeUtil;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
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.ICPPTemplateDefinition;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance;
|
||||
import org.eclipse.cdt.core.parser.util.ObjectMap;
|
||||
|
||||
/**
|
||||
* @author aniefer
|
||||
*/
|
||||
public abstract class CPPInstance extends CPPSpecialization implements ICPPTemplateInstance {
|
||||
private IType[] arguments;
|
||||
|
||||
public CPPInstance(ICPPScope scope, IBinding orig, ObjectMap argMap, IType[] arguments) {
|
||||
super(orig, scope, argMap);
|
||||
this.arguments = arguments;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPInstance#getTemplate()
|
||||
*/
|
||||
public ICPPTemplateDefinition getTemplateDefinition() {
|
||||
return (ICPPTemplateDefinition) getSpecializedBinding();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance#getArguments()
|
||||
*/
|
||||
public IType[] getArguments() {
|
||||
return arguments;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* For debug purposes only
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return getName() + " <" + ASTTypeUtil.getTypeListString(arguments) + ">"; //$NON-NLS-1$ //$NON-NLS-2$
|
||||
}
|
||||
}
|
|
@ -12,9 +12,11 @@
|
|||
package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ILinkage;
|
||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTLabelStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.ILabel;
|
||||
import org.eclipse.cdt.core.dom.ast.IScope;
|
||||
import org.eclipse.cdt.internal.core.dom.Linkage;
|
||||
|
@ -82,20 +84,18 @@ public class CPPLabel extends PlatformObject implements ILabel, ICPPInternalBind
|
|||
}
|
||||
|
||||
public void addDefinition(IASTNode node) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
public void addDeclaration(IASTNode node) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
public void removeDeclaration(IASTNode node) {
|
||||
|
||||
}
|
||||
|
||||
public ILinkage getLinkage() {
|
||||
return Linkage.CPP_LINKAGE;
|
||||
}
|
||||
|
||||
public IBinding getOwner() throws DOMException {
|
||||
return CPPVisitor.findEnclosingFunction(statement);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,25 +1,20 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2005, 2006 IBM Corporation and others.
|
||||
* 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:
|
||||
* IBM - Initial API and implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
* IBM - Initial API and implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
*******************************************************************************/
|
||||
/*
|
||||
* Created on Mar 29, 2005
|
||||
*/
|
||||
package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope;
|
||||
import org.eclipse.cdt.core.parser.util.ObjectMap;
|
||||
|
||||
/**
|
||||
|
@ -27,14 +22,8 @@ import org.eclipse.cdt.core.parser.util.ObjectMap;
|
|||
*/
|
||||
public class CPPMethodInstance extends CPPFunctionInstance implements ICPPMethod {
|
||||
|
||||
/**
|
||||
* @param scope
|
||||
* @param orig
|
||||
* @param argMap
|
||||
* @param args
|
||||
*/
|
||||
public CPPMethodInstance(ICPPScope scope, IBinding orig, ObjectMap argMap, IType[] args) {
|
||||
super(scope, orig, argMap, args);
|
||||
public CPPMethodInstance(ICPPClassType owner, ICPPMethod orig, ObjectMap argMap, IType[] args) {
|
||||
super(owner, orig, argMap, args);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
@ -45,7 +34,7 @@ public class CPPMethodInstance extends CPPFunctionInstance implements ICPPMethod
|
|||
}
|
||||
|
||||
public ICPPClassType getClassOwner() throws DOMException {
|
||||
return ((ICPPMethod)getTemplateDefinition()).getClassOwner();
|
||||
return (ICPPClassType) getOwner();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
@ -69,5 +58,4 @@ public class CPPMethodInstance extends CPPFunctionInstance implements ICPPMethod
|
|||
public boolean isImplicit() {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -17,12 +17,9 @@ import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
|
|||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IScope;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeclSpecifier;
|
||||
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.ICPPMethod;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope;
|
||||
import org.eclipse.cdt.core.parser.util.ObjectMap;
|
||||
|
||||
/**
|
||||
|
@ -32,8 +29,8 @@ import org.eclipse.cdt.core.parser.util.ObjectMap;
|
|||
public class CPPMethodSpecialization extends CPPFunctionSpecialization
|
||||
implements ICPPMethod {
|
||||
|
||||
public CPPMethodSpecialization(IBinding orig, ICPPScope scope, ObjectMap argMap ) {
|
||||
super(orig, scope, argMap );
|
||||
public CPPMethodSpecialization(IBinding orig, ICPPClassType owner, ObjectMap argMap ) {
|
||||
super(orig, owner, argMap );
|
||||
}
|
||||
|
||||
public boolean isVirtual() throws DOMException {
|
||||
|
@ -67,11 +64,7 @@ public class CPPMethodSpecialization extends CPPFunctionSpecialization
|
|||
}
|
||||
|
||||
public ICPPClassType getClassOwner() throws DOMException {
|
||||
IScope scope= getScope();
|
||||
if (scope instanceof ICPPClassScope) {
|
||||
return ((ICPPClassScope) scope).getClassType();
|
||||
}
|
||||
return null;
|
||||
return (ICPPClassType) getOwner();
|
||||
}
|
||||
|
||||
public boolean isDestructor() {
|
||||
|
|
|
@ -13,12 +13,8 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
|||
|
||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IScope;
|
||||
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.ICPPMethod;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateScope;
|
||||
import org.eclipse.cdt.core.parser.util.ObjectMap;
|
||||
|
||||
/**
|
||||
|
@ -28,14 +24,9 @@ import org.eclipse.cdt.core.parser.util.ObjectMap;
|
|||
public class CPPMethodTemplateSpecialization extends
|
||||
CPPFunctionTemplateSpecialization implements ICPPMethod {
|
||||
|
||||
/**
|
||||
* @param specialized
|
||||
* @param scope
|
||||
* @param argumentMap
|
||||
*/
|
||||
public CPPMethodTemplateSpecialization(IBinding specialized,
|
||||
ICPPScope scope, ObjectMap argumentMap) {
|
||||
super(specialized, scope, argumentMap);
|
||||
ICPPClassType owner, ObjectMap argumentMap) {
|
||||
super(specialized, owner, argumentMap);
|
||||
}
|
||||
|
||||
public boolean isVirtual() {
|
||||
|
@ -51,14 +42,7 @@ public class CPPMethodTemplateSpecialization extends
|
|||
}
|
||||
|
||||
public ICPPClassType getClassOwner() throws DOMException {
|
||||
IScope scope= getScope();
|
||||
if (scope instanceof ICPPTemplateScope) {
|
||||
scope= scope.getParent();
|
||||
}
|
||||
if( scope instanceof ICPPClassScope ){
|
||||
return ((ICPPClassScope)scope).getClassType();
|
||||
}
|
||||
return null;
|
||||
return (ICPPClassType) getOwner();
|
||||
}
|
||||
|
||||
public boolean isDestructor() {
|
||||
|
|
|
@ -356,4 +356,11 @@ public class CPPNamespace extends PlatformObject implements ICPPNamespace, ICPPI
|
|||
}
|
||||
return ASTStringUtil.join(names, String.valueOf(Keywords.cpCOLONCOLON));
|
||||
}
|
||||
|
||||
public IBinding getOwner() throws DOMException {
|
||||
if (namespaceDefinitions != null && namespaceDefinitions.length > 0) {
|
||||
return CPPVisitor.findDeclarationOwner(namespaceDefinitions[0], false);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -103,4 +103,8 @@ public class CPPNamespaceAlias extends PlatformObject implements ICPPNamespaceAl
|
|||
public ILinkage getLinkage() {
|
||||
return Linkage.CPP_LINKAGE;
|
||||
}
|
||||
|
||||
public IBinding getOwner() throws DOMException {
|
||||
return CPPVisitor.findDeclarationOwner(alias, false);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@ import org.eclipse.cdt.core.dom.ast.IASTInitializer;
|
|||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IScope;
|
||||
import org.eclipse.cdt.core.dom.ast.IType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPParameter;
|
||||
|
@ -296,4 +297,8 @@ public class CPPParameter extends PlatformObject implements ICPPParameter, ICPPI
|
|||
String name = getName();
|
||||
return name.length() != 0 ? name : "<unnamed>"; //$NON-NLS-1$
|
||||
}
|
||||
|
||||
public IBinding getOwner() throws DOMException {
|
||||
return CPPVisitor.findEnclosingFunction(declarations[0]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,11 +12,10 @@
|
|||
package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPParameter;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope;
|
||||
import org.eclipse.cdt.core.parser.util.ObjectMap;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPTemplates;
|
||||
|
||||
/**
|
||||
* @author aniefer
|
||||
|
@ -24,13 +23,8 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPTemplates;
|
|||
public class CPPParameterSpecialization extends CPPSpecialization implements ICPPParameter {
|
||||
private IType type = null;
|
||||
|
||||
/**
|
||||
* @param scope
|
||||
* @param orig
|
||||
* @param argMap
|
||||
*/
|
||||
public CPPParameterSpecialization(ICPPParameter orig, ICPPScope scope, ObjectMap argMap) {
|
||||
super( orig, scope, argMap );
|
||||
public CPPParameterSpecialization(ICPPParameter orig, IBinding owner, ObjectMap argMap) {
|
||||
super(orig, owner, argMap);
|
||||
}
|
||||
|
||||
private ICPPParameter getParameter(){
|
||||
|
@ -42,7 +36,7 @@ public class CPPParameterSpecialization extends CPPSpecialization implements ICP
|
|||
*/
|
||||
public IType getType() throws DOMException {
|
||||
if( type == null ){
|
||||
type = CPPTemplates.instantiateType( getParameter().getType(), argumentMap, getScope());
|
||||
type= specializeType(getParameter().getType());
|
||||
}
|
||||
return type;
|
||||
}
|
||||
|
|
|
@ -142,7 +142,7 @@ abstract public class CPPScope implements ICPPScope, IASTInternalScope {
|
|||
if (physicalNode instanceof IASTTranslationUnit) {
|
||||
try {
|
||||
IBinding[] bindings= index.findBindings(name.toCharArray(),
|
||||
IndexFilter.CPP_DECLARED_OR_IMPLICIT, NPM);
|
||||
IndexFilter.CPP_DECLARED_OR_IMPLICIT_NO_INSTANCE, NPM);
|
||||
if (fileSet != null) {
|
||||
bindings= fileSet.filterFileLocalBindings(bindings);
|
||||
}
|
||||
|
@ -238,7 +238,7 @@ abstract public class CPPScope implements ICPPScope, IASTInternalScope {
|
|||
if (index != null) {
|
||||
if (physicalNode instanceof IASTTranslationUnit) {
|
||||
try {
|
||||
IndexFilter filter = IndexFilter.CPP_DECLARED_OR_IMPLICIT;
|
||||
IndexFilter filter = IndexFilter.CPP_DECLARED_OR_IMPLICIT_NO_INSTANCE;
|
||||
IBinding[] bindings = prefixLookup ?
|
||||
index.findBindingsForPrefix(name.toCharArray(), true, filter, null) :
|
||||
index.findBindings(name.toCharArray(), filter, null);
|
||||
|
|
|
@ -20,43 +20,44 @@ import org.eclipse.cdt.core.dom.ast.DOMException;
|
|||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IScope;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope;
|
||||
import org.eclipse.cdt.core.dom.ast.IType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassSpecialization;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization;
|
||||
import org.eclipse.cdt.core.parser.util.ArrayUtil;
|
||||
import org.eclipse.cdt.core.parser.util.ObjectMap;
|
||||
import org.eclipse.cdt.internal.core.dom.Linkage;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPTemplates;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
|
||||
import org.eclipse.core.runtime.PlatformObject;
|
||||
|
||||
/**
|
||||
* @author aniefer
|
||||
*/
|
||||
public abstract class CPPSpecialization extends PlatformObject
|
||||
implements ICPPSpecialization, ICPPInternalBinding {
|
||||
public abstract class CPPSpecialization extends PlatformObject implements ICPPSpecialization, ICPPInternalBinding {
|
||||
private IBinding owner;
|
||||
private IBinding specialized;
|
||||
private ICPPScope scope;
|
||||
protected ObjectMap argumentMap;
|
||||
|
||||
private IASTNode definition;
|
||||
private IASTNode[] declarations;
|
||||
|
||||
public CPPSpecialization(IBinding specialized, ICPPScope scope, ObjectMap argumentMap) {
|
||||
|
||||
public CPPSpecialization(IBinding specialized, IBinding owner, ObjectMap argumentMap) {
|
||||
this.specialized = specialized;
|
||||
this.scope = scope;
|
||||
this.owner = owner;
|
||||
this.argumentMap = argumentMap;
|
||||
|
||||
if (specialized instanceof ICPPInternalBinding) {
|
||||
definition = ((ICPPInternalBinding) specialized).getDefinition();
|
||||
IASTNode[] decls = ((ICPPInternalBinding) specialized).getDeclarations();
|
||||
if (decls != null && decls.length > 0)
|
||||
declarations = new IASTNode[] { decls[0] };
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization#getSpecializedBinding()
|
||||
*/
|
||||
protected IType specializeType(IType type) throws DOMException {
|
||||
if (owner instanceof ICPPClassSpecialization) {
|
||||
return CPPTemplates.instantiateType(type, argumentMap, (ICPPClassSpecialization) owner);
|
||||
} else {
|
||||
return CPPTemplates.instantiateType(type, argumentMap, null);
|
||||
}
|
||||
}
|
||||
|
||||
public IBinding getSpecializedBinding() {
|
||||
return specialized;
|
||||
}
|
||||
|
@ -103,8 +104,24 @@ public abstract class CPPSpecialization extends PlatformObject
|
|||
return specialized.getNameCharArray();
|
||||
}
|
||||
|
||||
public IScope getScope() {
|
||||
return scope;
|
||||
public IBinding getOwner() {
|
||||
return owner;
|
||||
}
|
||||
|
||||
public IScope getScope() throws DOMException {
|
||||
if (owner instanceof ICPPClassType) {
|
||||
return ((ICPPClassType) owner).getCompositeScope();
|
||||
} else if (owner instanceof ICPPNamespace) {
|
||||
return ((ICPPNamespace) owner).getNamespaceScope();
|
||||
} else if (owner instanceof ICPPFunction) {
|
||||
return ((ICPPFunction) owner).getFunctionScope();
|
||||
}
|
||||
if (definition != null)
|
||||
return CPPVisitor.getContainingScope(definition);
|
||||
if (declarations != null && declarations.length > 0)
|
||||
return CPPVisitor.getContainingScope(declarations[0]);
|
||||
|
||||
return specialized.getScope();
|
||||
}
|
||||
|
||||
public String[] getQualifiedName() {
|
||||
|
|
|
@ -21,7 +21,6 @@ import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
|
|||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IProblemBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IScope;
|
||||
import org.eclipse.cdt.core.dom.ast.IType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier;
|
||||
|
@ -30,12 +29,10 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTParameterDeclaration;
|
|||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTSimpleTypeTemplateParameter;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateId;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateParameter;
|
||||
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.ICPPSpecialization;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateDefinition;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter;
|
||||
import org.eclipse.cdt.core.parser.util.ArrayUtil;
|
||||
import org.eclipse.cdt.core.parser.util.ObjectMap;
|
||||
|
@ -77,7 +74,7 @@ public abstract class CPPTemplateDefinition extends PlatformObject implements IC
|
|||
|
||||
private ICPPTemplateParameter[] templateParameters;
|
||||
private ObjectMap instances;
|
||||
|
||||
|
||||
public CPPTemplateDefinition(IASTName name) {
|
||||
if (name != null) {
|
||||
ASTNodeProperty prop = name.getPropertyInParent();
|
||||
|
@ -100,71 +97,41 @@ public abstract class CPPTemplateDefinition extends PlatformObject implements IC
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
public abstract ICPPSpecialization deferredInstance(ObjectMap argMap, IType[] arguments);
|
||||
|
||||
public IBinding instantiate(ICPPASTTemplateId id) {
|
||||
IType[] types = CPPTemplates.createTemplateArgumentArray(id);
|
||||
return instantiate(types);
|
||||
}
|
||||
|
||||
public IBinding instantiate(IType[] arguments) {
|
||||
ICPPTemplateDefinition template = null;
|
||||
if (this instanceof ICPPClassTemplate) {
|
||||
try {
|
||||
template = CPPTemplates.matchTemplatePartialSpecialization((ICPPClassTemplate) this, arguments);
|
||||
} catch (DOMException e) {
|
||||
return e.getProblem();
|
||||
}
|
||||
}
|
||||
|
||||
if (template instanceof IProblemBinding) {
|
||||
return template;
|
||||
}
|
||||
if (template != null && template instanceof ICPPClassTemplatePartialSpecialization) {
|
||||
return ((ICPPInternalTemplateInstantiator)template).instantiate(arguments);
|
||||
}
|
||||
|
||||
return CPPTemplates.instantiateTemplate(this, arguments, null);
|
||||
}
|
||||
|
||||
public ICPPSpecialization getInstance(IType[] arguments) {
|
||||
public final void addInstance(IType[] arguments, ICPPTemplateInstance instance) {
|
||||
if (instances == null)
|
||||
return null;
|
||||
|
||||
int found = -1;
|
||||
for (int i = 0; i < instances.size(); i++) {
|
||||
IType[] args = (IType[]) instances.keyAt(i);
|
||||
if (args.length == arguments.length) {
|
||||
int j = 0;
|
||||
for (; j < args.length; j++) {
|
||||
if (!CPPTemplates.isSameTemplateArgument(args[j], arguments[j]))
|
||||
break;
|
||||
}
|
||||
if (j == args.length) {
|
||||
found = i;
|
||||
break;
|
||||
instances = new ObjectMap(2);
|
||||
instances.put(arguments, instance);
|
||||
}
|
||||
|
||||
public final ICPPTemplateInstance getInstance(IType[] arguments) {
|
||||
if (instances != null) {
|
||||
loop: for (int i=0; i < instances.size(); i++) {
|
||||
IType[] args = (IType[]) instances.keyAt(i);
|
||||
if (args.length == arguments.length) {
|
||||
for (int j=0; j < args.length; j++) {
|
||||
if (!CPPTemplates.isSameTemplateArgument(args[j], arguments[j])) {
|
||||
continue loop;
|
||||
}
|
||||
}
|
||||
return (ICPPTemplateInstance) instances.getAt(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (found != -1) {
|
||||
return (ICPPSpecialization) instances.getAt(found);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void addSpecialization(IType[] types, ICPPSpecialization spec) {
|
||||
if (types == null)
|
||||
return;
|
||||
for (IType type : types) {
|
||||
if (type == null)
|
||||
return;
|
||||
public ICPPTemplateInstance[] getAllInstances() {
|
||||
if (instances != null) {
|
||||
ICPPTemplateInstance[] result= new ICPPTemplateInstance[instances.size()];
|
||||
for (int i=0; i < instances.size(); i++) {
|
||||
result[i]= (ICPPTemplateInstance) instances.getAt(i);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
if (instances == null)
|
||||
instances = new ObjectMap(2);
|
||||
instances.put(types, spec);
|
||||
return ICPPTemplateInstance.EMPTY_TEMPLATE_INSTANCE_ARRAY;
|
||||
}
|
||||
|
||||
|
||||
public IBinding resolveTemplateParameter(ICPPASTTemplateParameter templateParameter) {
|
||||
IASTName name = CPPTemplates.getTemplateParameterName(templateParameter);
|
||||
IASTName preferredName= name;
|
||||
|
@ -231,7 +198,11 @@ public abstract class CPPTemplateDefinition extends PlatformObject implements IC
|
|||
}
|
||||
|
||||
public IASTName getTemplateName() {
|
||||
return definition != null ? definition : declarations[0];
|
||||
if (definition != null)
|
||||
return definition;
|
||||
if (declarations != null && declarations.length > 0)
|
||||
return declarations[0];
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
@ -383,4 +354,12 @@ public abstract class CPPTemplateDefinition extends PlatformObject implements IC
|
|||
public ILinkage getLinkage() {
|
||||
return Linkage.CPP_LINKAGE;
|
||||
}
|
||||
|
||||
public final IBinding getOwner() {
|
||||
IASTName templateName= getTemplateName();
|
||||
if (templateName == null)
|
||||
return null;
|
||||
|
||||
return CPPVisitor.findNameOwner(templateName, false);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,20 +6,24 @@
|
|||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM - Initial API and implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
* IBM - Initial API and implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ILinkage;
|
||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IScope;
|
||||
import org.eclipse.cdt.core.dom.ast.IType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateParameter;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter;
|
||||
import org.eclipse.cdt.core.parser.util.ArrayUtil;
|
||||
import org.eclipse.cdt.internal.core.dom.Linkage;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPTemplates;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
|
||||
import org.eclipse.core.runtime.PlatformObject;
|
||||
|
||||
|
@ -143,5 +147,20 @@ public class CPPTemplateParameter extends PlatformObject implements ICPPTemplate
|
|||
@Override
|
||||
public String toString() {
|
||||
return getName();
|
||||
}
|
||||
|
||||
public IBinding getOwner() throws DOMException {
|
||||
if (declarations == null || declarations.length == 0)
|
||||
return null;
|
||||
|
||||
IASTNode node= declarations[0];
|
||||
while (node instanceof ICPPASTTemplateParameter == false) {
|
||||
if (node == null)
|
||||
return null;
|
||||
|
||||
node= node.getParent();
|
||||
}
|
||||
|
||||
return CPPTemplates.getContainingTemplate((ICPPASTTemplateParameter) node);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor;
|
|||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPField;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateTemplateParameter;
|
||||
import org.eclipse.cdt.core.parser.util.ArrayUtil;
|
||||
|
@ -182,63 +182,45 @@ public class CPPTemplateTemplateParameter extends CPPTemplateParameter implement
|
|||
return ICPPClassTemplatePartialSpecialization.EMPTY_PARTIAL_SPECIALIZATION_ARRAY;
|
||||
}
|
||||
|
||||
public IBinding instantiate(IType[] arguments) {
|
||||
return deferredInstance(null, arguments);
|
||||
}
|
||||
|
||||
public ICPPSpecialization deferredInstance(ObjectMap argMap, IType[] arguments) {
|
||||
ICPPSpecialization instance = getInstance(arguments);
|
||||
if (instance == null) {
|
||||
instance = new CPPDeferredClassInstance(this, argMap, arguments);
|
||||
addSpecialization(arguments, instance);
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
public ICPPSpecialization getInstance(IType[] arguments) {
|
||||
public final void addInstance(IType[] arguments, ICPPTemplateInstance instance) {
|
||||
if (instances == null)
|
||||
return null;
|
||||
|
||||
int found = -1;
|
||||
for (int i = 0; i < instances.size(); i++) {
|
||||
IType[] args = (IType[]) instances.keyAt(i);
|
||||
if (args.length == arguments.length) {
|
||||
int j = 0;
|
||||
for (; j < args.length; j++) {
|
||||
if (!(args[j].isSameType(arguments[j])))
|
||||
break;
|
||||
}
|
||||
if (j == args.length) {
|
||||
found = i;
|
||||
break;
|
||||
instances = new ObjectMap(2);
|
||||
instances.put(arguments, instance);
|
||||
}
|
||||
|
||||
public final ICPPTemplateInstance getInstance(IType[] arguments) {
|
||||
if (instances != null) {
|
||||
loop: for (int i=0; i < instances.size(); i++) {
|
||||
IType[] args = (IType[]) instances.keyAt(i);
|
||||
if (args.length == arguments.length) {
|
||||
for (int j=0; j < args.length; j++) {
|
||||
if (!CPPTemplates.isSameTemplateArgument(args[j], arguments[j])) {
|
||||
continue loop;
|
||||
}
|
||||
}
|
||||
return (ICPPTemplateInstance) instances.getAt(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (found != -1) {
|
||||
return (ICPPSpecialization) instances.getAt(found);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void addSpecialization(IType[] types, ICPPSpecialization spec) {
|
||||
if (instances == null)
|
||||
instances = new ObjectMap(2);
|
||||
instances.put(types, spec);
|
||||
|
||||
public ICPPTemplateInstance[] getAllInstances() {
|
||||
if (instances != null) {
|
||||
ICPPTemplateInstance[] result= new ICPPTemplateInstance[instances.size()];
|
||||
for (int i=0; i < instances.size(); i++) {
|
||||
result[i]= (ICPPTemplateInstance) instances.getAt(i);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
return ICPPTemplateInstance.EMPTY_TEMPLATE_INSTANCE_ARRAY;
|
||||
}
|
||||
|
||||
public ICPPClassType[] getNestedClasses() {
|
||||
return ICPPClassType.EMPTY_CLASS_ARRAY;
|
||||
}
|
||||
|
||||
public IBinding resolvePartially(ICPPUnknownBinding parentBinding, ObjectMap argMap, ICPPScope instantiationScope) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public IASTName getUnknownName() {
|
||||
return new CPPASTName(getNameCharArray());
|
||||
}
|
||||
|
||||
public ICPPUnknownBinding getUnknownContainerBinding() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,13 +14,11 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
|||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTypeId;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IType;
|
||||
import org.eclipse.cdt.core.dom.ast.ITypedef;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTSimpleTypeTemplateParameter;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateTypeParameter;
|
||||
import org.eclipse.cdt.core.parser.util.ObjectMap;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
|
||||
import org.eclipse.cdt.internal.core.index.IIndexType;
|
||||
|
||||
|
@ -66,16 +64,7 @@ public class CPPTemplateTypeParameter extends CPPTemplateParameter implements
|
|||
return false;
|
||||
}
|
||||
|
||||
public IBinding resolvePartially(ICPPUnknownBinding parentBinding, ObjectMap argMap, ICPPScope instantiationScope) {
|
||||
// Cannot do resolution here since the result is not necessarily a binding.
|
||||
return null;
|
||||
}
|
||||
|
||||
public IASTName getUnknownName() {
|
||||
return new CPPASTName(getNameCharArray());
|
||||
}
|
||||
|
||||
public ICPPUnknownBinding getUnknownContainerBinding() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@ import org.eclipse.cdt.core.dom.ast.DOMException;
|
|||
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IScope;
|
||||
import org.eclipse.cdt.core.dom.ast.IType;
|
||||
import org.eclipse.cdt.core.dom.ast.ITypedef;
|
||||
|
@ -210,4 +211,11 @@ public class CPPTypedef extends PlatformObject implements ITypedef, ITypeContain
|
|||
public String toString() {
|
||||
return getName();
|
||||
}
|
||||
|
||||
public IBinding getOwner() throws DOMException {
|
||||
if (declarations != null && declarations.length > 0) {
|
||||
return CPPVisitor.findDeclarationOwner(declarations[0], true);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,11 +18,10 @@ import org.eclipse.cdt.core.dom.ast.IBinding;
|
|||
import org.eclipse.cdt.core.dom.ast.IProblemBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IType;
|
||||
import org.eclipse.cdt.core.dom.ast.ITypedef;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
|
||||
import org.eclipse.cdt.core.parser.util.ObjectMap;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPTemplates;
|
||||
import org.eclipse.core.runtime.Assert;
|
||||
|
||||
/**
|
||||
|
@ -41,13 +40,8 @@ public class CPPTypedefSpecialization extends CPPSpecialization implements IType
|
|||
private IType type;
|
||||
private int fResolutionDepth;
|
||||
|
||||
/**
|
||||
* @param specialized
|
||||
* @param scope
|
||||
* @param argumentMap
|
||||
*/
|
||||
public CPPTypedefSpecialization(IBinding specialized, ICPPScope scope, ObjectMap argumentMap) {
|
||||
super(specialized, scope, argumentMap);
|
||||
public CPPTypedefSpecialization(IBinding specialized, ICPPClassType owner, ObjectMap argumentMap) {
|
||||
super(specialized, owner, argumentMap);
|
||||
}
|
||||
|
||||
private ITypedef getTypedef() {
|
||||
|
@ -63,7 +57,7 @@ public class CPPTypedefSpecialization extends CPPSpecialization implements IType
|
|||
if (++fResolutionDepth > MAX_RESOLUTION_DEPTH) {
|
||||
type = new RecursionResolvingBinding(getDefinition(), getNameCharArray());
|
||||
} else {
|
||||
type = CPPTemplates.instantiateType(getTypedef().getType(), argumentMap, getScope());
|
||||
type= specializeType(getTypedef().getType());
|
||||
// A typedef pointing to itself is a sure recipe for an infinite loop -- replace
|
||||
// with a problem binding.
|
||||
if (type instanceof CPPTypedefSpecialization &&
|
||||
|
|
|
@ -16,30 +16,29 @@ import org.eclipse.cdt.core.dom.ILinkage;
|
|||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IScope;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateDefinition;
|
||||
import org.eclipse.cdt.internal.core.dom.Linkage;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
|
||||
import org.eclipse.core.runtime.PlatformObject;
|
||||
|
||||
/**
|
||||
* @author aniefer
|
||||
* Represents a binding that is unknown because it depends on template arguments.
|
||||
*/
|
||||
public abstract class CPPUnknownBinding extends PlatformObject
|
||||
implements ICPPUnknownBinding, ICPPInternalBinding, Cloneable {
|
||||
protected IBinding fOwner;
|
||||
private ICPPScope unknownScope;
|
||||
protected ICPPUnknownBinding unknownContainerBinding;
|
||||
protected IASTName name;
|
||||
|
||||
public CPPUnknownBinding(ICPPUnknownBinding scopeBinding, IASTName name) {
|
||||
public CPPUnknownBinding(IBinding owner, IASTName name) {
|
||||
super();
|
||||
this.name = name;
|
||||
this.unknownContainerBinding = scopeBinding;
|
||||
}
|
||||
|
||||
public CPPUnknownBinding(ICPPTemplateDefinition templateDef) {
|
||||
this.name= new CPPASTName(templateDef.getNameCharArray());
|
||||
fOwner= owner;
|
||||
}
|
||||
|
||||
public IASTNode[] getDeclarations() {
|
||||
|
@ -80,9 +79,15 @@ public abstract class CPPUnknownBinding extends PlatformObject
|
|||
}
|
||||
|
||||
public IScope getScope() throws DOMException {
|
||||
if (unknownContainerBinding != null) {
|
||||
return unknownContainerBinding.getUnknownScope();
|
||||
}
|
||||
if (fOwner instanceof ICPPUnknownBinding) {
|
||||
return ((ICPPUnknownBinding) fOwner).getUnknownScope();
|
||||
} else if (fOwner instanceof ICPPClassType) {
|
||||
return ((ICPPClassType) fOwner).getCompositeScope();
|
||||
} else if (fOwner instanceof ICPPNamespace) {
|
||||
return ((ICPPNamespace) fOwner).getNamespaceScope();
|
||||
} else if (fOwner instanceof ICPPFunction) {
|
||||
return ((ICPPFunction) fOwner).getFunctionScope();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -115,7 +120,7 @@ public abstract class CPPUnknownBinding extends PlatformObject
|
|||
return name;
|
||||
}
|
||||
|
||||
public ICPPUnknownBinding getUnknownContainerBinding() {
|
||||
return unknownContainerBinding;
|
||||
public IBinding getOwner() {
|
||||
return fOwner;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,14 +21,11 @@ import org.eclipse.cdt.core.dom.ast.IScope;
|
|||
import org.eclipse.cdt.core.dom.ast.IType;
|
||||
import org.eclipse.cdt.core.dom.ast.ITypedef;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBase;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassTemplate;
|
||||
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.ICPPField;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope;
|
||||
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
|
||||
import org.eclipse.cdt.core.parser.util.ObjectMap;
|
||||
|
||||
/**
|
||||
* Represents a C++ class, declaration of which is not yet available.
|
||||
|
@ -37,12 +34,8 @@ import org.eclipse.cdt.core.parser.util.ObjectMap;
|
|||
*/
|
||||
public class CPPUnknownClass extends CPPUnknownBinding implements ICPPUnknownClassType {
|
||||
|
||||
public CPPUnknownClass(ICPPUnknownBinding scopeBinding, IASTName name) {
|
||||
super(scopeBinding, name);
|
||||
}
|
||||
|
||||
protected CPPUnknownClass(ICPPClassTemplate template) {
|
||||
super(template);
|
||||
public CPPUnknownClass(IBinding binding, IASTName name) {
|
||||
super(binding, name);
|
||||
}
|
||||
|
||||
public ICPPBase[] getBases() {
|
||||
|
@ -101,10 +94,13 @@ public class CPPUnknownClass extends CPPUnknownBinding implements ICPPUnknownCla
|
|||
&& type instanceof ICPPDeferredClassInstance == false) {
|
||||
ICPPUnknownClassType rhs= (ICPPUnknownClassType) type;
|
||||
if (CharArrayUtils.equals(getNameCharArray(), rhs.getNameCharArray())) {
|
||||
final ICPPUnknownBinding lhsContainer = getUnknownContainerBinding();
|
||||
final ICPPUnknownBinding rhsContainer = rhs.getUnknownContainerBinding();
|
||||
if (lhsContainer instanceof IType && rhsContainer instanceof IType) {
|
||||
return ((IType)lhsContainer).isSameType((IType) rhsContainer);
|
||||
try {
|
||||
final IBinding lhsContainer = getOwner();
|
||||
final IBinding rhsContainer = rhs.getOwner();
|
||||
if (lhsContainer instanceof IType && rhsContainer instanceof IType) {
|
||||
return ((IType)lhsContainer).isSameType((IType) rhsContainer);
|
||||
}
|
||||
} catch (DOMException e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -114,11 +110,4 @@ public class CPPUnknownClass extends CPPUnknownBinding implements ICPPUnknownCla
|
|||
public ICPPClassType[] getNestedClasses() {
|
||||
return ICPPClassType.EMPTY_CLASS_ARRAY;
|
||||
}
|
||||
|
||||
public IBinding resolvePartially(ICPPUnknownBinding parentBinding, ObjectMap argMap, ICPPScope instantiationScope) {
|
||||
if (parentBinding == this.unknownContainerBinding) {
|
||||
return this;
|
||||
}
|
||||
return new CPPUnknownClass(parentBinding, name);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,13 +11,12 @@
|
|||
package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.ASTTypeUtil;
|
||||
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.IType;
|
||||
import org.eclipse.cdt.core.dom.ast.ITypedef;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope;
|
||||
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
|
||||
import org.eclipse.cdt.core.parser.util.ObjectMap;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPTemplates;
|
||||
|
||||
/*
|
||||
|
@ -37,15 +36,6 @@ public class CPPUnknownClassInstance extends CPPUnknownClass implements ICPPUnkn
|
|||
return arguments;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBinding resolvePartially(ICPPUnknownBinding parentBinding, ObjectMap argMap, ICPPScope instantiationScope) {
|
||||
IType[] newArgs = CPPTemplates.instantiateTypes(arguments, argMap, instantiationScope);
|
||||
if (parentBinding == unknownContainerBinding && newArgs == arguments) {
|
||||
return this;
|
||||
}
|
||||
return new CPPUnknownClassInstance(parentBinding, name, newArgs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getName() + " <" + ASTTypeUtil.getTypeListString(arguments) + ">"; //$NON-NLS-1$ //$NON-NLS-2$
|
||||
|
@ -77,10 +67,13 @@ public class CPPUnknownClassInstance extends CPPUnknownClass implements ICPPUnkn
|
|||
return false;
|
||||
}
|
||||
}
|
||||
final ICPPUnknownBinding lhsContainer = getUnknownContainerBinding();
|
||||
final ICPPUnknownBinding rhsContainer = rhs.getUnknownContainerBinding();
|
||||
if (lhsContainer instanceof IType && rhsContainer instanceof IType) {
|
||||
return (((IType)lhsContainer).isSameType((IType) rhsContainer));
|
||||
try {
|
||||
final IBinding lhsContainer = getOwner();
|
||||
final IBinding rhsContainer = rhs.getOwner();
|
||||
if (lhsContainer instanceof IType && rhsContainer instanceof IType) {
|
||||
return (((IType)lhsContainer).isSameType((IType) rhsContainer));
|
||||
}
|
||||
} catch (DOMException e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -99,4 +99,8 @@ public class CPPUsingDeclaration extends PlatformObject implements ICPPUsingDecl
|
|||
public ILinkage getLinkage() {
|
||||
return Linkage.CPP_LINKAGE;
|
||||
}
|
||||
|
||||
public IBinding getOwner() {
|
||||
return CPPVisitor.findDeclarationOwner(name, true);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@ import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
|||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IScope;
|
||||
import org.eclipse.cdt.core.dom.ast.IType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier;
|
||||
|
@ -346,4 +347,9 @@ public class CPPVariable extends PlatformObject implements ICPPVariable, ICPPInt
|
|||
public ILinkage getLinkage() {
|
||||
return Linkage.CPP_LINKAGE;
|
||||
}
|
||||
|
||||
public IBinding getOwner() throws DOMException {
|
||||
IASTName node= definition != null ? definition : declarations[0];
|
||||
return CPPVisitor.findNameOwner(node, !hasStorageClass(IASTDeclSpecifier.sc_extern));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,9 +10,12 @@
|
|||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassScope;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassSpecialization;
|
||||
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.ICPPMethod;
|
||||
|
||||
/**
|
||||
* Composite scope of a class specialization. Supports creating instances for bindings found
|
||||
|
@ -27,8 +30,17 @@ public interface ICPPClassSpecializationScope extends ICPPClassScope {
|
|||
ICPPClassType getOriginalClassType();
|
||||
|
||||
/**
|
||||
* Returns the instance for a binding that belongs to the scope of the original
|
||||
* class type.
|
||||
* The specialized class.
|
||||
*/
|
||||
IBinding getInstance(IBinding original);
|
||||
ICPPClassSpecialization getClassType();
|
||||
|
||||
/**
|
||||
* Computes constructors off specialized class.
|
||||
*/
|
||||
ICPPConstructor[] getConstructors() throws DOMException;
|
||||
|
||||
/**
|
||||
* Computes the declared methods off the specialized class.
|
||||
*/
|
||||
ICPPMethod[] getDeclaredMethods() throws DOMException;
|
||||
}
|
||||
|
|
|
@ -11,10 +11,16 @@
|
|||
*******************************************************************************/
|
||||
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.ICPPDeferredTemplateInstance;
|
||||
|
||||
/**
|
||||
* Interface for deferred class template instances.
|
||||
*/
|
||||
public interface ICPPDeferredClassInstance extends ICPPUnknownClassType, ICPPDeferredTemplateInstance {
|
||||
|
||||
/**
|
||||
* Returns the class template for the deferred instantiation.
|
||||
*/
|
||||
ICPPClassTemplate getClassTemplate();
|
||||
}
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2007, 2008 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
|
||||
* Sergey Prigogin (Google)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance;
|
||||
|
||||
|
||||
/**
|
||||
* Caches instances per template, the template definitions need to implement this interface
|
||||
*/
|
||||
public interface ICPPInstanceCache {
|
||||
|
||||
/**
|
||||
* Attempts to cache an instance with this template
|
||||
*/
|
||||
public void addInstance(IType[] arguments, ICPPTemplateInstance instance);
|
||||
|
||||
/**
|
||||
* Attempts to get a cached instance from this template
|
||||
*/
|
||||
public ICPPTemplateInstance getInstance(IType[] arguments);
|
||||
|
||||
/**
|
||||
* Returns an array of all cached instances
|
||||
*/
|
||||
public ICPPTemplateInstance[] getAllInstances();
|
||||
}
|
|
@ -6,20 +6,13 @@
|
|||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM - Initial API and implementation
|
||||
* /
|
||||
* IBM - Initial API and implementation
|
||||
*******************************************************************************/
|
||||
/*
|
||||
* Created on Apr 29, 2005
|
||||
*/
|
||||
package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization;
|
||||
|
||||
/**
|
||||
* @author aniefer
|
||||
* Interface for templates from the ast.
|
||||
*/
|
||||
public interface ICPPInternalTemplate extends ICPPInternalBinding, ICPPInternalTemplateInstantiator {
|
||||
public void addSpecialization(IType[] arguments, ICPPSpecialization specialization);
|
||||
public interface ICPPInternalTemplate extends ICPPInternalBinding, ICPPInstanceCache {
|
||||
}
|
||||
|
|
|
@ -1,29 +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
|
||||
* Sergey Prigogin (Google)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.dom.parser.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.ICPPSpecialization;
|
||||
import org.eclipse.cdt.core.parser.util.ObjectMap;
|
||||
|
||||
/**
|
||||
* @author Bryan Wilkinson
|
||||
*/
|
||||
public interface ICPPInternalTemplateInstantiator {
|
||||
|
||||
public IBinding instantiate(IType[] arguments);
|
||||
|
||||
public ICPPSpecialization deferredInstance(ObjectMap argMap, IType[] arguments);
|
||||
|
||||
public ICPPSpecialization getInstance(IType[] arguments);
|
||||
}
|
|
@ -12,28 +12,14 @@ 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.cpp.ICPPBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPDeferredTemplateInstance;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope;
|
||||
import org.eclipse.cdt.core.parser.util.ObjectMap;
|
||||
|
||||
/**
|
||||
* Represents a binding found within a template definition that cannot be resolved until
|
||||
* the template gets instantiated.
|
||||
*
|
||||
* This interface should be made public
|
||||
* @since 5.0
|
||||
* Represents the binding for a dependent name within a template declaration.
|
||||
*/
|
||||
public interface ICPPUnknownBinding extends ICPPBinding {
|
||||
|
||||
/**
|
||||
* Returns the binding of the unknown scope containing this binding, or <code>null</code> if the container is not unknown
|
||||
* (applies for {@link ICPPDeferredTemplateInstance}).
|
||||
* @since 5.0
|
||||
*/
|
||||
public ICPPUnknownBinding getUnknownContainerBinding();
|
||||
|
||||
/**
|
||||
* Returns the scope this binding represents.
|
||||
* @throws DOMException
|
||||
|
@ -45,16 +31,4 @@ public interface ICPPUnknownBinding extends ICPPBinding {
|
|||
* The ast-node may not be rooted in an ast-tree. May be <code>null</code>.
|
||||
*/
|
||||
public IASTName getUnknownName();
|
||||
|
||||
/**
|
||||
* Resolves unknown type to another unknown type that is a step closer to the final
|
||||
* name resolution.
|
||||
* @param parentBinding a new parent binding, usually a result of partial resolution
|
||||
* of the original parent binding, or <code>null</code> for deferred template
|
||||
* instantiations.
|
||||
* @param argMap template argument map.
|
||||
* @param instantiationScope the scope in which the current instantiation takes place, may be <code>null</code>.
|
||||
* @return a partially resolved, but still unknown, binding.
|
||||
*/
|
||||
public IBinding resolvePartially(ICPPUnknownBinding parentBinding, ObjectMap argMap, ICPPScope instantiationScope);
|
||||
}
|
||||
|
|
|
@ -135,7 +135,6 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTIdExpression;
|
|||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTName;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTTranslationUnit;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPBasicType;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPClassType;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPCompositeBinding;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPNamespace;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPQualifierType;
|
||||
|
@ -146,7 +145,6 @@ 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.CPPVariable;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBinding;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalTemplateInstantiator;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownBinding;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.OverloadableOperator;
|
||||
import org.eclipse.cdt.internal.core.index.IIndexScope;
|
||||
|
@ -216,8 +214,7 @@ public class CPPSemantics {
|
|||
if (data.checkAssociatedScopes()) {
|
||||
//3.4.2 argument dependent name lookup, aka Koenig lookup
|
||||
try {
|
||||
IScope scope = (binding != null) ? binding.getScope() : null;
|
||||
if (scope == null || !(scope instanceof ICPPClassScope)) {
|
||||
if (binding == null || binding.getOwner() instanceof ICPPClassType == false) {
|
||||
data.ignoreUsingDirectives = true;
|
||||
data.forceQualified = true;
|
||||
for (int i = 0; i < data.associated.size(); i++) {
|
||||
|
@ -286,11 +283,13 @@ public class CPPSemantics {
|
|||
|
||||
if (binding instanceof ICPPClassType && data.considerConstructors) {
|
||||
ICPPClassType cls = (ICPPClassType) binding;
|
||||
if (data.astName instanceof ICPPASTTemplateId && cls instanceof ICPPTemplateDefinition) {
|
||||
ICPPASTTemplateId id = (ICPPASTTemplateId) data.astName;
|
||||
IType[] args = CPPTemplates.createTemplateArgumentArray(id);
|
||||
IBinding inst = ((ICPPInternalTemplateInstantiator)cls).instantiate(args);
|
||||
cls = inst instanceof ICPPClassType && !(inst instanceof ICPPDeferredTemplateInstance) ? (ICPPClassType)inst : cls;
|
||||
if (data.astName instanceof ICPPASTTemplateId && cls instanceof ICPPClassTemplate) {
|
||||
if (data.tu != null) {
|
||||
ICPPASTTemplateId id = (ICPPASTTemplateId) data.astName;
|
||||
IType[] args = CPPTemplates.createTemplateArgumentArray(id);
|
||||
IBinding inst= CPPTemplates.instantiate((ICPPClassTemplate) cls, args);
|
||||
cls = inst instanceof ICPPClassType && !(inst instanceof ICPPDeferredTemplateInstance) ? (ICPPClassType)inst : cls;
|
||||
}
|
||||
}
|
||||
if (cls != null) {
|
||||
try {
|
||||
|
@ -1937,21 +1936,13 @@ public class CPPSemantics {
|
|||
|
||||
final IType[] result = new IType[ptypes.length + 1];
|
||||
System.arraycopy(ptypes, 0, result, 1, ptypes.length);
|
||||
IScope scope = fn.getScope();
|
||||
if (scope instanceof ICPPTemplateScope)
|
||||
scope = scope.getParent();
|
||||
ICPPClassType cls = null;
|
||||
if (scope instanceof ICPPClassScope) {
|
||||
cls = ((ICPPClassScope)scope).getClassType();
|
||||
} else {
|
||||
cls = new CPPClassType.CPPClassTypeProblem(ASTInternal.getPhysicalNodeOfScope(scope), IProblemBinding.SEMANTIC_BAD_SCOPE, fn.getNameCharArray());
|
||||
}
|
||||
if (cls instanceof ICPPClassTemplate) {
|
||||
IBinding within = CPPTemplates.instantiateWithinClassTemplate((ICPPClassTemplate) cls);
|
||||
ICPPClassType owner= ((ICPPMethod) fn).getClassOwner();
|
||||
if (owner instanceof ICPPClassTemplate) {
|
||||
IBinding within= CPPTemplates.instantiateWithinClassTemplate((ICPPClassTemplate) owner);
|
||||
if (within instanceof ICPPClassType)
|
||||
cls = (ICPPClassType)within;
|
||||
owner = (ICPPClassType)within;
|
||||
}
|
||||
IType implicitType = cls;
|
||||
IType implicitType= owner;
|
||||
if (ftype.isConst() || ftype.isVolatile()) {
|
||||
implicitType = new CPPQualifierType(implicitType, ftype.isConst(), ftype.isVolatile());
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -19,7 +19,6 @@ import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUti
|
|||
import java.math.BigInteger;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.dom.IName;
|
||||
import org.eclipse.cdt.core.dom.ast.ASTNodeProperty;
|
||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTArrayDeclarator;
|
||||
|
@ -131,7 +130,6 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionScope;
|
|||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceScope;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPPointerToMemberType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPReferenceType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope;
|
||||
|
@ -319,10 +317,11 @@ public class CPPVisitor {
|
|||
ICPPScope scope = (ICPPScope) getContainingScope(specifier);
|
||||
IBinding enumeration;
|
||||
try {
|
||||
enumeration = scope.getBinding(specifier.getName(), false);
|
||||
final IASTName name = specifier.getName();
|
||||
enumeration = scope.getBinding(name, false);
|
||||
if (enumeration == null || !(enumeration instanceof IEnumeration)) {
|
||||
enumeration = new CPPEnumeration(specifier.getName());
|
||||
ASTInternal.addName(scope, specifier.getName());
|
||||
enumeration = new CPPEnumeration(name);
|
||||
ASTInternal.addName(scope, name);
|
||||
}
|
||||
} catch (DOMException e) {
|
||||
enumeration = e.getProblem();
|
||||
|
@ -439,10 +438,10 @@ public class CPPVisitor {
|
|||
scope = parentScope;
|
||||
}
|
||||
IBinding binding = null;
|
||||
if (name instanceof ICPPASTTemplateId) {
|
||||
return CPPTemplates.createClassSpecialization(compType);
|
||||
}
|
||||
try {
|
||||
if (name instanceof ICPPASTTemplateId) {
|
||||
return CPPTemplates.createExplicitClassSpecialization(compType);
|
||||
}
|
||||
if (name.toCharArray().length > 0 && scope != null) //can't lookup anonymous things
|
||||
binding = scope.getBinding(name, false);
|
||||
if (!(binding instanceof ICPPInternalBinding) || !(binding instanceof ICPPClassType)) {
|
||||
|
@ -542,7 +541,11 @@ public class CPPVisitor {
|
|||
return CPPSemantics.resolveBinding(name);
|
||||
} else if (prop == ICPPASTTemplateSpecialization.OWNED_DECLARATION ||
|
||||
prop == ICPPASTExplicitTemplateInstantiation.OWNED_DECLARATION) {
|
||||
return CPPTemplates.createFunctionSpecialization(name);
|
||||
try {
|
||||
return CPPTemplates.createFunctionSpecialization(name);
|
||||
} catch (DOMException e) {
|
||||
return e.getProblem();
|
||||
}
|
||||
} else if (prop == ICPPASTTemplateDeclaration.PARAMETER) {
|
||||
return CPPTemplates.createBinding((ICPPASTTemplateParameter) parent);
|
||||
}
|
||||
|
@ -1759,14 +1762,14 @@ public class CPPVisitor {
|
|||
}
|
||||
if (node instanceof IASTFunctionDeclarator) {
|
||||
ICPPASTFunctionDeclarator dtor = (ICPPASTFunctionDeclarator) node;
|
||||
IASTName fName = findInnermostDeclarator(dtor).getName();
|
||||
if (fName instanceof ICPPASTQualifiedName) {
|
||||
IASTName[] ns = ((ICPPASTQualifiedName)fName).getNames();
|
||||
fName = ns[ns.length - 1];
|
||||
IASTName funcName = findInnermostDeclarator(dtor).getName();
|
||||
if (funcName instanceof ICPPASTQualifiedName) {
|
||||
IASTName[] ns = ((ICPPASTQualifiedName)funcName).getNames();
|
||||
funcName = ns[ns.length - 1];
|
||||
}
|
||||
IScope s = getContainingScope(fName);
|
||||
IScope s = getContainingScope(funcName);
|
||||
if (s instanceof ICPPTemplateScope)
|
||||
s = getParentScope(s, fName.getTranslationUnit());
|
||||
s = getParentScope(s, funcName.getTranslationUnit());
|
||||
if (s instanceof ICPPClassScope) {
|
||||
ICPPClassScope cScope = (ICPPClassScope) s;
|
||||
IType type = cScope.getClassType();
|
||||
|
@ -1840,12 +1843,9 @@ public class CPPVisitor {
|
|||
IBinding binding = resolveBinding(expression);
|
||||
if (binding instanceof ICPPConstructor) {
|
||||
try {
|
||||
IScope scope= binding.getScope();
|
||||
if (scope instanceof ICPPTemplateScope && ! (scope instanceof ICPPClassScope)) {
|
||||
scope= scope.getParent();
|
||||
}
|
||||
if (scope instanceof ICPPClassScope) {
|
||||
return ((ICPPClassScope) scope).getClassType();
|
||||
IBinding owner= binding.getOwner();
|
||||
if (owner instanceof ICPPClassType) {
|
||||
return (ICPPClassType) owner;
|
||||
}
|
||||
} catch (DOMException e) {
|
||||
return e.getProblem();
|
||||
|
@ -2236,67 +2236,55 @@ public class CPPVisitor {
|
|||
}
|
||||
|
||||
public static String[] getQualifiedName(IBinding binding) {
|
||||
IName[] ns = null;
|
||||
String[] ns = null;
|
||||
try {
|
||||
ICPPScope scope = (ICPPScope) binding.getScope();
|
||||
while (scope != null) {
|
||||
if (scope instanceof ICPPTemplateScope)
|
||||
scope = (ICPPScope) scope.getParent();
|
||||
|
||||
if (scope == null)
|
||||
break;
|
||||
|
||||
IName n = scope.getScopeName();
|
||||
IBinding owner= binding.getOwner();
|
||||
while (owner != null) {
|
||||
String n= owner.getName();
|
||||
if (n == null)
|
||||
break;
|
||||
if (scope instanceof ICPPBlockScope || scope instanceof ICPPFunctionScope)
|
||||
break;
|
||||
if (scope instanceof ICPPNamespaceScope && scope.getScopeName().toCharArray().length == 0)
|
||||
if (owner instanceof ICPPFunction)
|
||||
break;
|
||||
if (owner instanceof ICPPNamespace && n.length() == 0)
|
||||
continue;
|
||||
|
||||
ns = (IName[]) ArrayUtil.append(IName.class, ns, n);
|
||||
scope = (ICPPScope) scope.getParent();
|
||||
ns = (String[]) ArrayUtil.append(String.class, ns, n);
|
||||
owner = owner.getOwner();
|
||||
}
|
||||
} catch (DOMException e) {
|
||||
}
|
||||
ns = (IName[]) ArrayUtil.trim(IName.class, ns);
|
||||
ns = (String[]) ArrayUtil.trim(String.class, ns);
|
||||
String[] result = new String[ns.length + 1];
|
||||
for (int i = ns.length - 1; i >= 0; i--) {
|
||||
result[ns.length - i - 1] = ns[i].toString();
|
||||
result[ns.length - i - 1] = ns[i];
|
||||
}
|
||||
result[ns.length] = binding.getName();
|
||||
result[ns.length]= binding.getName();
|
||||
return result;
|
||||
}
|
||||
|
||||
public static char[][] getQualifiedNameCharArray(IBinding binding) {
|
||||
IName[] ns = null;
|
||||
try {
|
||||
ICPPScope scope = (ICPPScope) binding.getScope();
|
||||
while (scope != null) {
|
||||
if (scope instanceof ICPPTemplateScope)
|
||||
scope = (ICPPScope) scope.getParent();
|
||||
|
||||
if (scope == null)
|
||||
break;
|
||||
IName n = scope.getScopeName();
|
||||
char[][] ns = null;
|
||||
try {
|
||||
for (IBinding owner= binding.getOwner(); owner != null; owner= owner.getOwner()) {
|
||||
char[] n= owner.getNameCharArray();
|
||||
if (n == null)
|
||||
break;
|
||||
if (scope instanceof ICPPBlockScope || scope instanceof ICPPFunctionScope)
|
||||
if (owner instanceof ICPPFunction)
|
||||
break;
|
||||
if (scope instanceof ICPPNamespaceScope && scope.getScopeName().toCharArray().length == 0)
|
||||
break;
|
||||
|
||||
ns = (IName[]) ArrayUtil.append(IName.class, ns, n);
|
||||
scope = (ICPPScope) scope.getParent();
|
||||
if (owner instanceof ICPPNamespace && n.length == 0)
|
||||
continue;
|
||||
|
||||
ns = (char[][]) ArrayUtil.append(n.getClass(), ns, n);
|
||||
}
|
||||
} catch (DOMException e) {
|
||||
}
|
||||
ns = (IName[]) ArrayUtil.trim(IName.class, ns);
|
||||
final char[] bname = binding.getNameCharArray();
|
||||
ns = (char[][]) ArrayUtil.trim(bname.getClass(), ns);
|
||||
char[][] result = new char[ns.length + 1][];
|
||||
for (int i = ns.length - 1; i >= 0; i--) {
|
||||
result[ns.length - i - 1] = ns[i].toCharArray();
|
||||
result[ns.length - i - 1] = ns[i];
|
||||
}
|
||||
result[ns.length] = binding.getNameCharArray();
|
||||
result[ns.length]= bname;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -2479,4 +2467,81 @@ public class CPPVisitor {
|
|||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Searches for the function enclosing the given node. May return <code>null</code>.
|
||||
*/
|
||||
public static IBinding findEnclosingFunction(IASTNode node) {
|
||||
while(node != null && node instanceof IASTFunctionDefinition == false) {
|
||||
node= node.getParent();
|
||||
}
|
||||
if (node == null)
|
||||
return null;
|
||||
|
||||
IASTDeclarator dtor= findInnermostDeclarator(((IASTFunctionDefinition) node).getDeclarator());
|
||||
if (dtor != null) {
|
||||
IASTName name= dtor.getName();
|
||||
if (name != null) {
|
||||
return name.resolveBinding();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static IBinding findNameOwner(IASTName name, boolean allowFunction) {
|
||||
IASTNode node= name;
|
||||
while (node instanceof IASTName) {
|
||||
if (node instanceof ICPPASTQualifiedName) {
|
||||
IASTName[] qn= ((ICPPASTQualifiedName) node).getNames();
|
||||
if (qn.length < 2)
|
||||
return null;
|
||||
return qn[qn.length-2].resolveBinding();
|
||||
}
|
||||
node= node.getParent();
|
||||
}
|
||||
return findDeclarationOwner(node, allowFunction);
|
||||
}
|
||||
|
||||
/**
|
||||
* Searches for the first function, class or namespace enclosing the declaration the provided
|
||||
* node belongs to and returns the binding for it. Returns <code>null</code>, if the declaration is not
|
||||
* enclosed by any of the above constructs.
|
||||
*/
|
||||
public static IBinding findDeclarationOwner(IASTNode node, boolean allowFunction) {
|
||||
// search for declaration
|
||||
while (node instanceof IASTDeclaration == false) {
|
||||
if (node == null)
|
||||
return null;
|
||||
|
||||
node= node.getParent();
|
||||
}
|
||||
|
||||
// search for enclosing binding
|
||||
IASTName name= null;
|
||||
node= node.getParent();
|
||||
for (; node != null; node= node.getParent()) {
|
||||
if (node instanceof IASTFunctionDefinition) {
|
||||
if (!allowFunction)
|
||||
continue;
|
||||
|
||||
IASTDeclarator dtor= findInnermostDeclarator(((IASTFunctionDefinition) node).getDeclarator());
|
||||
if (dtor != null) {
|
||||
name= dtor.getName();
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (node instanceof IASTCompositeTypeSpecifier) {
|
||||
name= ((IASTCompositeTypeSpecifier) node).getName();
|
||||
break;
|
||||
}
|
||||
if (node instanceof ICPPASTNamespaceDefinition) {
|
||||
name= ((ICPPASTNamespaceDefinition) node).getName();
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (name == null)
|
||||
return null;
|
||||
|
||||
return name.resolveBinding();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@ package org.eclipse.cdt.internal.core.index;
|
|||
|
||||
import org.eclipse.cdt.core.dom.ILinkage;
|
||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IScope;
|
||||
import org.eclipse.cdt.core.dom.ast.IType;
|
||||
import org.eclipse.cdt.core.dom.ast.ITypedef;
|
||||
|
@ -47,6 +48,9 @@ public class CPPTypedefClone implements ITypedef, ITypeContainer, IIndexType, IC
|
|||
public IScope getScope() throws DOMException {
|
||||
return delegate.getScope();
|
||||
}
|
||||
public IBinding getOwner() throws DOMException {
|
||||
return delegate.getOwner();
|
||||
}
|
||||
@SuppressWarnings("unchecked")
|
||||
public Object getAdapter(Class adapter) {
|
||||
return delegate.getAdapter(adapter);
|
||||
|
|
|
@ -16,26 +16,23 @@ import org.eclipse.cdt.core.dom.ILinkage;
|
|||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance;
|
||||
import org.eclipse.cdt.core.index.IndexFilter;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
|
||||
public class DeclaredBindingsFilter extends IndexFilter {
|
||||
final private int fLinkageID;
|
||||
final private boolean fAcceptImplicit;
|
||||
final private boolean fAcceptSpecializations;
|
||||
final private boolean fAllowInstances;
|
||||
|
||||
public DeclaredBindingsFilter() {
|
||||
this(-1, false);
|
||||
}
|
||||
|
||||
public DeclaredBindingsFilter(int linkageID, boolean acceptImplicit) {
|
||||
this(linkageID, acceptImplicit, acceptImplicit /* assume specializations should behave like implicit bindings*/);
|
||||
this(-1, false, true);
|
||||
}
|
||||
|
||||
public DeclaredBindingsFilter(int linkageID, boolean acceptImplicit, boolean acceptSpecializations) {
|
||||
public DeclaredBindingsFilter(int linkageID, boolean acceptImplicit, boolean allowInstances) {
|
||||
fLinkageID= linkageID;
|
||||
fAcceptImplicit= acceptImplicit;
|
||||
fAcceptSpecializations= acceptSpecializations;
|
||||
fAllowInstances= allowInstances;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -45,16 +42,20 @@ public class DeclaredBindingsFilter extends IndexFilter {
|
|||
|
||||
@Override
|
||||
public boolean acceptBinding(IBinding binding) throws CoreException {
|
||||
if (!fAllowInstances && binding instanceof ICPPTemplateInstance)
|
||||
return false;
|
||||
|
||||
if (binding instanceof IIndexFragmentBinding) {
|
||||
return ((IIndexFragmentBinding) binding).hasDeclaration()
|
||||
|| (fAcceptImplicit && isImplicit(binding))
|
||||
|| (fAcceptSpecializations && binding instanceof ICPPSpecialization);
|
||||
|| (fAcceptImplicit && isImplicit(binding));
|
||||
}
|
||||
// composite bindings don't support that kind of check.
|
||||
return fAcceptImplicit || !isImplicit(binding);
|
||||
}
|
||||
|
||||
private boolean isImplicit(IBinding binding) {
|
||||
if (binding instanceof ICPPSpecialization)
|
||||
return true;
|
||||
if (binding instanceof ICPPMethod) {
|
||||
return ((ICPPMethod) binding).isImplicit();
|
||||
}
|
||||
|
|
|
@ -254,4 +254,16 @@ public interface IIndexFragment {
|
|||
* @return an array of all files contained in this index.
|
||||
*/
|
||||
IIndexFragmentFile[] getAllFiles() throws CoreException;
|
||||
|
||||
/**
|
||||
* Caches an object with the key, the cache must be cleared at latest when the fragment no
|
||||
* longer holds a locks.
|
||||
*/
|
||||
void putCachedResult(Object key, Object value);
|
||||
|
||||
/**
|
||||
* Returns a previously cached object, the cache is cleared at latest when the fragment no
|
||||
* longer holds a locks.
|
||||
*/
|
||||
Object getCachedResult(Object key);
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
package org.eclipse.cdt.internal.core.index;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ILinkage;
|
||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
import org.eclipse.cdt.core.index.IIndexBinding;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
|
||||
|
@ -50,4 +51,16 @@ public interface IIndexFragmentBinding extends IIndexBinding {
|
|||
* Returns the scope that contains this binding, or <code>null</code> for bindings in global scope.
|
||||
*/
|
||||
IIndexScope getScope();
|
||||
|
||||
/**
|
||||
* @since 5.1
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
IIndexFragmentBinding getOwner() throws DOMException;
|
||||
|
||||
/**
|
||||
* Returns a unique id for the binding within the fragment
|
||||
* @since 5.1
|
||||
*/
|
||||
int getId();
|
||||
}
|
|
@ -17,22 +17,16 @@ import java.util.Collections;
|
|||
import java.util.List;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.dom.IName;
|
||||
import org.eclipse.cdt.core.dom.ast.ASTTypeUtil;
|
||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
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.IFunctionType;
|
||||
import org.eclipse.cdt.core.dom.ast.IScope;
|
||||
import org.eclipse.cdt.core.dom.ast.IType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassTemplatePartialSpecialization;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateDefinition;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter;
|
||||
import org.eclipse.cdt.core.parser.util.ObjectMap;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
|
||||
/**
|
||||
|
@ -60,19 +54,6 @@ public class IndexCPPSignatureUtil {
|
|||
} else if (binding instanceof ICPPClassTemplatePartialSpecialization) {
|
||||
ICPPClassTemplatePartialSpecialization partial = (ICPPClassTemplatePartialSpecialization) binding;
|
||||
buffer.append(getTemplateArgString(partial.getArguments(), false));
|
||||
} else if (binding instanceof ICPPSpecialization) {
|
||||
ICPPSpecialization spec = (ICPPSpecialization) binding;
|
||||
if (!(spec instanceof ICPPTemplateDefinition)
|
||||
&& spec.getSpecializedBinding() instanceof ICPPTemplateDefinition) {
|
||||
ICPPTemplateDefinition template = (ICPPTemplateDefinition) spec.getSpecializedBinding();
|
||||
ICPPTemplateParameter[] params = template.getTemplateParameters();
|
||||
ObjectMap argMap = spec.getArgumentMap();
|
||||
IType[] args = new IType[params.length];
|
||||
for (int i = 0; i < params.length; i++) {
|
||||
args[i] = (IType) argMap.get(params[i]);
|
||||
}
|
||||
buffer.append(getTemplateArgString(args, false));
|
||||
}
|
||||
}
|
||||
|
||||
if (binding instanceof IFunction) {
|
||||
|
@ -103,27 +84,19 @@ public class IndexCPPSignatureUtil {
|
|||
final IType type = types[i];
|
||||
if (qualifyTemplateParameters && type instanceof ICPPTemplateParameter) {
|
||||
List<IBinding> parents = new ArrayList<IBinding>();
|
||||
IScope parentScope= ((ICPPTemplateParameter) type).getScope();
|
||||
IBinding lastBinding= null;
|
||||
while (parentScope != null) {
|
||||
IBinding binding = getBindingForScope(parentScope);
|
||||
if (binding != null) {
|
||||
// template definitions are returned as binding for template scope and
|
||||
// the class/function scope.
|
||||
if (!binding.equals(lastBinding)) {
|
||||
parents.add(lastBinding= binding);
|
||||
}
|
||||
}
|
||||
parentScope= parentScope.getParent();
|
||||
IBinding parent= ((ICPPTemplateParameter) type).getOwner();
|
||||
while (parent != null) {
|
||||
parents.add(parent);
|
||||
parent= parent.getOwner();
|
||||
}
|
||||
//identical template parameters from different template specializations must have unique signatures
|
||||
Collections.reverse(parents);
|
||||
for (IBinding binding : parents) {
|
||||
if (binding != null) {
|
||||
buffer.append(binding.getNameCharArray());
|
||||
if (binding instanceof ICPPSpecialization) {
|
||||
ICPPSpecialization spec= (ICPPSpecialization) binding;
|
||||
appendTemplateArgs(spec.getArgumentMap().valueArray(), buffer);
|
||||
if (binding instanceof ICPPTemplateInstance) {
|
||||
ICPPTemplateInstance inst= (ICPPTemplateInstance) binding;
|
||||
appendTemplateArgs(inst.getArguments(), buffer);
|
||||
}
|
||||
buffer.append("::"); //$NON-NLS-1$
|
||||
}
|
||||
|
@ -137,20 +110,6 @@ public class IndexCPPSignatureUtil {
|
|||
return buffer.toString();
|
||||
}
|
||||
|
||||
private static IBinding getBindingForScope(IScope parentScope) throws DOMException {
|
||||
IBinding binding= null;
|
||||
if (parentScope instanceof IIndexScope) {
|
||||
binding= ((IIndexScope)parentScope).getScopeBinding();
|
||||
}
|
||||
else {
|
||||
final IName scopeName = parentScope.getScopeName();
|
||||
if (scopeName instanceof IASTName) {
|
||||
binding= ((IASTName) scopeName).resolveBinding();
|
||||
}
|
||||
}
|
||||
return binding;
|
||||
}
|
||||
|
||||
private static void appendTemplateArgs(Object[] values, StringBuilder buffer) {
|
||||
boolean needcomma= false;
|
||||
buffer.append('<');
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
package org.eclipse.cdt.internal.core.index.composite;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ILinkage;
|
||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
import org.eclipse.cdt.core.index.IIndexBinding;
|
||||
import org.eclipse.cdt.core.index.IIndexFile;
|
||||
import org.eclipse.cdt.internal.core.index.IIndexFragmentBinding;
|
||||
|
@ -111,4 +112,16 @@ public abstract class CompositeIndexBinding implements IIndexBinding {
|
|||
public int hashCode() {
|
||||
return rbinding.hashCode();
|
||||
}
|
||||
|
||||
public IIndexBinding getOwner() throws DOMException {
|
||||
final IIndexFragmentBinding owner= rbinding.getOwner();
|
||||
if (owner == null)
|
||||
return null;
|
||||
|
||||
return cf.getCompositeBinding(owner);
|
||||
}
|
||||
|
||||
public IIndexBinding getRawBinding() {
|
||||
return rbinding;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@ import org.eclipse.cdt.core.CCorePlugin;
|
|||
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.cpp.ICPPClassType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization;
|
||||
import org.eclipse.cdt.core.index.IIndexFileSet;
|
||||
import org.eclipse.cdt.core.index.IIndexName;
|
||||
|
@ -53,8 +54,13 @@ public abstract class CompositeScope implements IIndexScope {
|
|||
}
|
||||
|
||||
public IIndexName getScopeName() {
|
||||
if(rbinding instanceof IIndexScope)
|
||||
return ((IIndexScope) rbinding).getScopeName();
|
||||
try {
|
||||
if(rbinding instanceof IIndexScope)
|
||||
return ((IIndexScope) rbinding).getScopeName();
|
||||
if(rbinding instanceof ICPPClassType)
|
||||
return (IIndexName) ((ICPPClassType) rbinding).getCompositeScope().getScopeName();
|
||||
} catch (DOMException e) {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
@ -53,6 +53,8 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPVariable;
|
|||
import org.eclipse.cdt.core.index.IIndex;
|
||||
import org.eclipse.cdt.core.index.IIndexBinding;
|
||||
import org.eclipse.cdt.core.index.IIndexMacroContainer;
|
||||
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.ICPPInternalUnknownScope;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownClassInstance;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownClassType;
|
||||
|
@ -66,6 +68,7 @@ import org.eclipse.cdt.internal.core.index.composite.CompositeMacroContainer;
|
|||
import org.eclipse.cdt.internal.core.index.composite.CompositePointerType;
|
||||
import org.eclipse.cdt.internal.core.index.composite.CompositeQualifierType;
|
||||
import org.eclipse.cdt.internal.core.index.composite.CompositingNotImplementedError;
|
||||
import org.eclipse.cdt.internal.core.index.composite.ICompositesFactory;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
|
||||
public class CPPCompositesFactory extends AbstractCompositeFactory {
|
||||
|
@ -83,6 +86,9 @@ public class CPPCompositesFactory extends AbstractCompositeFactory {
|
|||
return null;
|
||||
}
|
||||
if (rscope instanceof ICPPClassScope) {
|
||||
if (rscope instanceof ICPPClassSpecializationScope) {
|
||||
return new CompositeCPPClassSpecializationScope(this, (IIndexFragmentBinding) rscope.getScopeBinding());
|
||||
}
|
||||
ICPPClassScope classScope = (ICPPClassScope) rscope;
|
||||
return new CompositeCPPClassScope(this, findOneBinding(classScope.getClassType()));
|
||||
}
|
||||
|
@ -182,8 +188,8 @@ public class CPPCompositesFactory extends AbstractCompositeFactory {
|
|||
} else if (binding instanceof ICPPSpecialization) {
|
||||
if (binding instanceof ICPPTemplateInstance) {
|
||||
if (binding instanceof ICPPDeferredTemplateInstance) {
|
||||
if (binding instanceof ICPPClassType) {
|
||||
return new CompositeCPPDeferredClassInstance(this, (ICPPClassType) findOneBinding(binding));
|
||||
if (binding instanceof ICPPDeferredClassInstance) {
|
||||
return new CompositeCPPDeferredClassInstance(this, (ICPPDeferredClassInstance) findOneBinding(binding));
|
||||
} else if (binding instanceof ICPPFunction) {
|
||||
return new CompositeCPPDeferredFunctionInstance(this, (ICPPFunction) binding);
|
||||
} else {
|
||||
|
@ -301,4 +307,39 @@ public class CPPCompositesFactory extends AbstractCompositeFactory {
|
|||
|
||||
return result;
|
||||
}
|
||||
|
||||
private static class Key {
|
||||
final long i;
|
||||
final int j;
|
||||
final int k;
|
||||
public Key(long id1, int id2, int id3) {
|
||||
i= id1;
|
||||
j= id2;
|
||||
k= id3;
|
||||
}
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + (int) (i ^ (i >>> 32));
|
||||
result = prime * result + j;
|
||||
result = prime * result + k;
|
||||
return result;
|
||||
}
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof Key) {
|
||||
Key other = (Key) obj;
|
||||
return i == other.i && j == other.j && k == other.k;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static Object createInstanceCacheKey(ICompositesFactory cf,IIndexFragmentBinding rbinding) {
|
||||
return new Key(Thread.currentThread().getId(), cf.hashCode(), rbinding.getId());
|
||||
}
|
||||
public static Object createSpecializationKey(ICompositesFactory cf,IIndexFragmentBinding rbinding) {
|
||||
return new Key(Thread.currentThread().getId(), cf.hashCode(), rbinding.getId()+1);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,47 +11,30 @@
|
|||
package org.eclipse.cdt.internal.core.index.composite.cpp;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IScope;
|
||||
import org.eclipse.cdt.core.dom.ast.IType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBase;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateDefinition;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance;
|
||||
import org.eclipse.cdt.core.index.IIndexBinding;
|
||||
import org.eclipse.cdt.core.parser.util.ObjectMap;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPTemplates;
|
||||
import org.eclipse.cdt.internal.core.index.IIndexScope;
|
||||
import org.eclipse.cdt.internal.core.index.composite.ICompositesFactory;
|
||||
|
||||
public class CompositeCPPClassInstance extends CompositeCPPClassType
|
||||
implements ICPPTemplateInstance, ICPPSpecialization {
|
||||
public class CompositeCPPClassInstance extends CompositeCPPClassSpecialization implements ICPPTemplateInstance {
|
||||
|
||||
public CompositeCPPClassInstance(ICompositesFactory cf, ICPPClassType rbinding) {
|
||||
super(cf, rbinding);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ICPPMethod[] getDeclaredMethods() throws DOMException {
|
||||
ICPPClassType specialized = (ICPPClassType) getSpecializedBinding();
|
||||
ICPPMethod[] bindings = specialized.getDeclaredMethods();
|
||||
for (int i = 0; i < bindings.length; i++) {
|
||||
bindings[i]= (ICPPMethod) CPPTemplates.createSpecialization((ICPPScope)getScope(), (IIndexBinding) bindings[i], getArgumentMap());
|
||||
}
|
||||
return bindings;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IScope getCompositeScope() throws DOMException {
|
||||
return new CompositeCPPClassSpecializationScope(cf, rbinding);
|
||||
return cf.getCompositeScope((IIndexScope) ((ICPPClassType) rbinding).getCompositeScope());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectMap getArgumentMap() { return TemplateInstanceUtil.getArgumentMap(cf, rbinding); }
|
||||
public IBinding getSpecializedBinding() { return TemplateInstanceUtil.getSpecializedBinding(cf, rbinding); }
|
||||
@Override
|
||||
public ICPPClassType getSpecializedBinding() { return (ICPPClassType) TemplateInstanceUtil.getSpecializedBinding(cf, rbinding); }
|
||||
public IType[] getArguments() { return TemplateInstanceUtil.getArguments(cf, (ICPPTemplateInstance) rbinding); }
|
||||
public ICPPTemplateDefinition getTemplateDefinition() { return TemplateInstanceUtil.getTemplateDefinition(cf, rbinding); }
|
||||
@Override
|
||||
public ICPPBase[] getBases() throws DOMException { return CPPTemplates.getBases(this); }
|
||||
}
|
||||
|
|
|
@ -10,14 +10,28 @@
|
|||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.index.composite.cpp;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IScope;
|
||||
import org.eclipse.cdt.core.dom.ast.IType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBase;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassSpecialization;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
|
||||
import org.eclipse.cdt.core.parser.util.ArrayUtil;
|
||||
import org.eclipse.cdt.core.parser.util.ObjectMap;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPClassSpecializationScope;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBase;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPTemplates;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil;
|
||||
import org.eclipse.cdt.internal.core.index.IIndexFragment;
|
||||
import org.eclipse.cdt.internal.core.index.composite.ICompositesFactory;
|
||||
|
||||
public class CompositeCPPClassSpecialization extends CompositeCPPClassType implements ICPPSpecialization {
|
||||
public class CompositeCPPClassSpecialization extends CompositeCPPClassType implements ICPPClassSpecialization {
|
||||
|
||||
private ObjectMap specializationMap= null;
|
||||
|
||||
public CompositeCPPClassSpecialization(ICompositesFactory cf, ICPPClassType rbinding) {
|
||||
super(cf, rbinding);
|
||||
}
|
||||
|
@ -26,7 +40,74 @@ public class CompositeCPPClassSpecialization extends CompositeCPPClassType imple
|
|||
return TemplateInstanceUtil.getArgumentMap(cf, rbinding);
|
||||
}
|
||||
|
||||
public IBinding getSpecializedBinding() {
|
||||
return TemplateInstanceUtil.getSpecializedBinding(cf, rbinding);
|
||||
public ICPPClassType getSpecializedBinding() {
|
||||
return (ICPPClassType) TemplateInstanceUtil.getSpecializedBinding(cf, rbinding);
|
||||
}
|
||||
|
||||
public IBinding specializeMember(IBinding original) {
|
||||
if (specializationMap == null) {
|
||||
final Object key= CPPCompositesFactory.createSpecializationKey(cf, rbinding);
|
||||
final IIndexFragment frag= rbinding.getFragment();
|
||||
Object cached= frag.getCachedResult(key);
|
||||
if (cached instanceof ObjectMap) {
|
||||
specializationMap= (ObjectMap) cached;
|
||||
} else {
|
||||
final ObjectMap newMap= new ObjectMap(2);
|
||||
frag.putCachedResult(key, newMap);
|
||||
specializationMap= newMap;
|
||||
}
|
||||
}
|
||||
IBinding result= (IBinding) specializationMap.get(original);
|
||||
if (result == null) {
|
||||
result= CPPTemplates.createSpecialization(this, original, getArgumentMap());
|
||||
specializationMap.put(original, result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ICPPBase[] getBases() throws DOMException {
|
||||
IScope scope= getCompositeScope();
|
||||
if (scope instanceof ICPPClassSpecializationScope) {
|
||||
// this is an implicit specialization
|
||||
final ICPPBase[] pdomBases = (getSpecializedBinding()).getBases();
|
||||
if (pdomBases != null) {
|
||||
ICPPBase[] result = null;
|
||||
for (ICPPBase origBase : pdomBases) {
|
||||
ICPPBase specBase = (ICPPBase) ((ICPPInternalBase)origBase).clone();
|
||||
IBinding origClass = origBase.getBaseClass();
|
||||
if (origClass instanceof IType) {
|
||||
IType specClass = CPPTemplates.instantiateType((IType) origClass, getArgumentMap(), this);
|
||||
specClass = SemanticUtil.getUltimateType(specClass, true);
|
||||
if (specClass instanceof IBinding) {
|
||||
((ICPPInternalBase)specBase).setBaseClass((IBinding) specClass);
|
||||
}
|
||||
result = (ICPPBase[]) ArrayUtil.append(ICPPBase.class, result, specBase);
|
||||
}
|
||||
}
|
||||
|
||||
return (ICPPBase[]) ArrayUtil.trim(ICPPBase.class, result);
|
||||
}
|
||||
return ICPPBase.EMPTY_BASE_ARRAY;
|
||||
}
|
||||
return super.getBases();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ICPPConstructor[] getConstructors() throws DOMException {
|
||||
IScope scope= getCompositeScope();
|
||||
if (scope instanceof ICPPClassSpecializationScope) {
|
||||
return ((ICPPClassSpecializationScope) scope).getConstructors();
|
||||
}
|
||||
return super.getConstructors();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ICPPMethod[] getDeclaredMethods() throws DOMException {
|
||||
IScope scope= getCompositeScope();
|
||||
if (scope instanceof ICPPClassSpecializationScope) {
|
||||
return ((ICPPClassSpecializationScope) scope).getDeclaredMethods();
|
||||
}
|
||||
return super.getDeclaredMethods();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,108 +13,76 @@ package org.eclipse.cdt.internal.core.index.composite.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.IScope;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassTemplatePartialSpecialization;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassSpecialization;
|
||||
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.ICPPMethod;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization;
|
||||
import org.eclipse.cdt.core.index.IIndexBinding;
|
||||
import org.eclipse.cdt.core.index.IIndexFileSet;
|
||||
import org.eclipse.cdt.core.parser.util.ArrayUtil;
|
||||
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
|
||||
import org.eclipse.cdt.core.parser.util.ObjectMap;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPClassScope;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.AbstractCPPClassSpecializationScope;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPClassSpecializationScope;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPSemantics;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPTemplates;
|
||||
import org.eclipse.cdt.internal.core.index.IIndexFragmentBinding;
|
||||
import org.eclipse.cdt.internal.core.index.composite.CompositeScope;
|
||||
import org.eclipse.cdt.internal.core.index.composite.ICompositesFactory;
|
||||
|
||||
public class CompositeCPPClassSpecializationScope extends CompositeCPPClassScope implements ICPPClassSpecializationScope {
|
||||
private ObjectMap instanceMap = ObjectMap.EMPTY_MAP;
|
||||
|
||||
public class CompositeCPPClassSpecializationScope extends CompositeScope implements ICPPClassSpecializationScope {
|
||||
private ICPPClassSpecializationScope fDelegate;
|
||||
|
||||
public CompositeCPPClassSpecializationScope(ICompositesFactory cf, IIndexFragmentBinding rbinding) {
|
||||
super(cf, rbinding);
|
||||
}
|
||||
|
||||
private ICPPSpecialization specialization() {
|
||||
return (ICPPSpecialization) cf.getCompositeBinding(rbinding);
|
||||
private ICPPClassSpecialization specialization() {
|
||||
return (ICPPClassSpecialization) cf.getCompositeBinding(rbinding);
|
||||
}
|
||||
|
||||
public ICPPClassType getOriginalClassType() {
|
||||
return (ICPPClassType) specialization().getSpecializedBinding();
|
||||
return specialization().getSpecializedBinding();
|
||||
}
|
||||
|
||||
public ICPPClassSpecialization getClassType() {
|
||||
return (ICPPClassSpecialization) cf.getCompositeBinding(rbinding);
|
||||
}
|
||||
|
||||
public IIndexBinding getScopeBinding() {
|
||||
return (IIndexBinding) getClassType();
|
||||
}
|
||||
|
||||
private void createDelegate() {
|
||||
if (fDelegate == null) {
|
||||
fDelegate= new AbstractCPPClassSpecializationScope(specialization()) {};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ICPPMethod[] getImplicitMethods() {
|
||||
// Implicit methods shouldn't have implicit specializations
|
||||
return ICPPMethod.EMPTY_CPPMETHOD_ARRAY;
|
||||
createDelegate();
|
||||
return fDelegate.getImplicitMethods();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBinding[] find(String name) throws DOMException {
|
||||
return CPPSemantics.findBindings(this, name, false);
|
||||
createDelegate();
|
||||
return fDelegate.find(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBinding getBinding(IASTName name, boolean resolve, IIndexFileSet acceptLocalBindings) throws DOMException {
|
||||
char[] c = name.toCharArray();
|
||||
|
||||
if (CharArrayUtils.equals(c, specialization().getNameCharArray()) &&
|
||||
!CPPClassScope.isConstructorReference(name)) {
|
||||
return specialization();
|
||||
}
|
||||
|
||||
ICPPClassType specialized = (ICPPClassType) specialization().getSpecializedBinding();
|
||||
IScope classScope = specialized.getCompositeScope();
|
||||
IBinding[] bindings = classScope != null ? classScope.getBindings(name, resolve, false) : null;
|
||||
|
||||
if (bindings == null)
|
||||
return null;
|
||||
|
||||
IBinding[] specs = new IBinding[0];
|
||||
for (IBinding binding : bindings) {
|
||||
specs = (IBinding[]) ArrayUtil.append(IBinding.class, specs, getInstance(binding));
|
||||
}
|
||||
specs = (IBinding[]) ArrayUtil.trim(IBinding.class, specs);
|
||||
return CPPSemantics.resolveAmbiguities(name, specs);
|
||||
public IBinding getBinding(IASTName name, boolean resolve, IIndexFileSet acceptLocalBindings)
|
||||
throws DOMException {
|
||||
createDelegate();
|
||||
return fDelegate.getBinding(name, resolve, acceptLocalBindings);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBinding[] getBindings(IASTName name, boolean forceResolve, boolean prefixLookup,
|
||||
IIndexFileSet fileSet) throws DOMException {
|
||||
char[] c = name.toCharArray();
|
||||
IBinding[] result = null;
|
||||
|
||||
if ((!prefixLookup && CharArrayUtils.equals(c, specialization().getNameCharArray())) ||
|
||||
(prefixLookup && CharArrayUtils.equals(specialization().getNameCharArray(), 0, c.length, c, true))) {
|
||||
result = new IBinding[] { specialization() };
|
||||
}
|
||||
|
||||
ICPPClassType specialized = (ICPPClassType) specialization().getSpecializedBinding();
|
||||
IScope classScope = specialized.getCompositeScope();
|
||||
IBinding[] bindings = classScope != null ?
|
||||
classScope.getBindings(name, forceResolve, prefixLookup, fileSet) : null;
|
||||
|
||||
if (bindings != null) {
|
||||
for (IBinding binding : bindings) {
|
||||
result = (IBinding[]) ArrayUtil.append(IBinding.class, result, getInstance(binding));
|
||||
}
|
||||
}
|
||||
|
||||
return (IBinding[]) ArrayUtil.trim(IBinding.class, result);
|
||||
public IBinding[] getBindings(IASTName name, boolean resolve, boolean prefixLookup,
|
||||
IIndexFileSet acceptLocalBindings) throws DOMException {
|
||||
createDelegate();
|
||||
return fDelegate.getBindings(name, resolve, prefixLookup, acceptLocalBindings);
|
||||
}
|
||||
|
||||
public IBinding getInstance(IBinding binding) {
|
||||
if (instanceMap.containsKey(binding)) {
|
||||
return (IBinding) instanceMap.get(binding);
|
||||
} else if (!(binding instanceof ICPPClassTemplatePartialSpecialization)) {
|
||||
IBinding spec = CPPTemplates.createSpecialization(this, binding, specialization().getArgumentMap());
|
||||
if (instanceMap == ObjectMap.EMPTY_MAP)
|
||||
instanceMap = new ObjectMap(2);
|
||||
instanceMap.put(binding, spec);
|
||||
return spec;
|
||||
}
|
||||
return null;
|
||||
|
||||
public ICPPConstructor[] getConstructors() throws DOMException {
|
||||
createDelegate();
|
||||
return fDelegate.getConstructors();
|
||||
}
|
||||
|
||||
public ICPPMethod[] getDeclaredMethods() throws DOMException {
|
||||
createDelegate();
|
||||
return fDelegate.getDeclaredMethods();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,26 +13,21 @@ package org.eclipse.cdt.internal.core.index.composite.cpp;
|
|||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IProblemBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassTemplate;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassTemplatePartialSpecialization;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateDefinition;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter;
|
||||
import org.eclipse.cdt.core.parser.util.ArrayUtil;
|
||||
import org.eclipse.cdt.core.parser.util.ObjectMap;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalTemplateInstantiator;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPTemplates;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInstanceCache;
|
||||
import org.eclipse.cdt.internal.core.index.CIndex;
|
||||
import org.eclipse.cdt.internal.core.index.IIndexFragmentBinding;
|
||||
import org.eclipse.cdt.internal.core.index.composite.ICompositesFactory;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
|
||||
public class CompositeCPPClassTemplate extends CompositeCPPClassType
|
||||
implements ICPPClassTemplate, ICPPInternalTemplateInstantiator {
|
||||
implements ICPPClassTemplate, ICPPInstanceCache {
|
||||
|
||||
public CompositeCPPClassTemplate(ICompositesFactory cf, ICPPClassType ct) {
|
||||
super(cf, ct);
|
||||
|
@ -65,28 +60,15 @@ public class CompositeCPPClassTemplate extends CompositeCPPClassType
|
|||
return result;
|
||||
}
|
||||
|
||||
public ICPPSpecialization deferredInstance(ObjectMap argMap, IType[] arguments) {
|
||||
return InternalTemplateInstantiatorUtil.deferredInstance(argMap, arguments, cf, rbinding);
|
||||
public ICPPTemplateInstance getInstance(IType[] arguments) {
|
||||
return CompositeInstanceCache.getCache(cf, rbinding).getInstance(arguments);
|
||||
}
|
||||
|
||||
public ICPPSpecialization getInstance(IType[] arguments) {
|
||||
return InternalTemplateInstantiatorUtil.getInstance(arguments, cf, this);
|
||||
public void addInstance(IType[] arguments, ICPPTemplateInstance instance) {
|
||||
CompositeInstanceCache.getCache(cf, rbinding).addInstance(arguments, instance);
|
||||
}
|
||||
|
||||
public IBinding instantiate(IType[] arguments) {
|
||||
ICPPTemplateDefinition template = null;
|
||||
try {
|
||||
template = CPPTemplates.matchTemplatePartialSpecialization(this, arguments);
|
||||
} catch (DOMException e) {
|
||||
return e.getProblem();
|
||||
}
|
||||
|
||||
if( template instanceof IProblemBinding )
|
||||
return template;
|
||||
if( template != null && template instanceof ICPPClassTemplatePartialSpecialization ){
|
||||
return ((ICPPInternalTemplateInstantiator)template).instantiate( arguments );
|
||||
}
|
||||
|
||||
return CPPTemplates.instantiateTemplate(this, arguments, null);
|
||||
public ICPPTemplateInstance[] getAllInstances() {
|
||||
return CompositeInstanceCache.getCache(cf, rbinding).getAllInstances();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2007 Symbian Software Systems and others.
|
||||
* 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
|
||||
* Andrew Ferguson (Symbian) - Initial implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.index.composite.cpp;
|
||||
|
||||
|
@ -36,6 +36,4 @@ public class CompositeCPPClassTemplatePartialSpecialization extends CompositeCPP
|
|||
public ObjectMap getArgumentMap() { return TemplateInstanceUtil.getArgumentMap(cf, rbinding); }
|
||||
public IBinding getSpecializedBinding() { return TemplateInstanceUtil.getSpecializedBinding(cf, rbinding); }
|
||||
public int getSignatureHash() throws CoreException { return ((IPDOMOverloader) rbinding).getSignatureHash(); }
|
||||
@Override
|
||||
public IBinding instantiate(IType[] args) { return InternalTemplateInstantiatorUtil.instantiate(args, cf, rbinding); }
|
||||
}
|
||||
|
|
|
@ -12,20 +12,18 @@
|
|||
package org.eclipse.cdt.internal.core.index.composite.cpp;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassTemplate;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassTemplatePartialSpecialization;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter;
|
||||
import org.eclipse.cdt.core.parser.util.ObjectMap;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalTemplateInstantiator;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInstanceCache;
|
||||
import org.eclipse.cdt.internal.core.index.IIndexFragmentBinding;
|
||||
import org.eclipse.cdt.internal.core.index.composite.ICompositesFactory;
|
||||
|
||||
public class CompositeCPPClassTemplateSpecialization extends
|
||||
CompositeCPPClassSpecialization implements ICPPClassTemplate, ICPPInternalTemplateInstantiator{
|
||||
CompositeCPPClassSpecialization implements ICPPClassTemplate, ICPPInstanceCache{
|
||||
|
||||
public CompositeCPPClassTemplateSpecialization(ICompositesFactory cf, ICPPClassType rbinding) {
|
||||
super(cf, rbinding);
|
||||
|
@ -48,15 +46,15 @@ CompositeCPPClassSpecialization implements ICPPClassTemplate, ICPPInternalTempla
|
|||
return result;
|
||||
}
|
||||
|
||||
public ICPPSpecialization deferredInstance(ObjectMap argMap, IType[] arguments) {
|
||||
return InternalTemplateInstantiatorUtil.deferredInstance(argMap, arguments, cf, rbinding);
|
||||
public ICPPTemplateInstance getInstance(IType[] arguments) {
|
||||
return CompositeInstanceCache.getCache(cf, rbinding).getInstance(arguments);
|
||||
}
|
||||
|
||||
public ICPPSpecialization getInstance(IType[] arguments) {
|
||||
return InternalTemplateInstantiatorUtil.getInstance(arguments, cf, this);
|
||||
public void addInstance(IType[] arguments, ICPPTemplateInstance instance) {
|
||||
CompositeInstanceCache.getCache(cf, rbinding).addInstance(arguments, instance);
|
||||
}
|
||||
|
||||
public IBinding instantiate(IType[] arguments) {
|
||||
return InternalTemplateInstantiatorUtil.instantiate(arguments, cf, rbinding);
|
||||
public ICPPTemplateInstance[] getAllInstances() {
|
||||
return CompositeInstanceCache.getCache(cf, rbinding).getAllInstances();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,17 +15,13 @@ 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.IType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassTemplate;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateDefinition;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance;
|
||||
import org.eclipse.cdt.core.parser.util.ObjectMap;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPDeferredClassInstance;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalTemplateInstantiator;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownBinding;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownClassType;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPTemplates;
|
||||
import org.eclipse.cdt.internal.core.index.IIndexFragmentBinding;
|
||||
import org.eclipse.cdt.internal.core.index.composite.ICompositesFactory;
|
||||
|
||||
|
@ -33,7 +29,7 @@ public class CompositeCPPDeferredClassInstance extends CompositeCPPClassType imp
|
|||
|
||||
private ICPPScope unknownScope;
|
||||
|
||||
public CompositeCPPDeferredClassInstance(ICompositesFactory cf, ICPPClassType rbinding) {
|
||||
public CompositeCPPDeferredClassInstance(ICompositesFactory cf, ICPPDeferredClassInstance rbinding) {
|
||||
super(cf, rbinding);
|
||||
}
|
||||
|
||||
|
@ -52,11 +48,7 @@ public class CompositeCPPDeferredClassInstance extends CompositeCPPClassType imp
|
|||
public IBinding getSpecializedBinding() { return TemplateInstanceUtil.getSpecializedBinding(cf, rbinding); }
|
||||
|
||||
public IASTName getUnknownName() {
|
||||
return ((ICPPUnknownClassType) rbinding).getUnknownName();
|
||||
}
|
||||
|
||||
public ICPPUnknownBinding getUnknownContainerBinding() {
|
||||
return null;
|
||||
return ((ICPPDeferredClassInstance) rbinding).getUnknownName();
|
||||
}
|
||||
|
||||
public ICPPScope getUnknownScope() throws DOMException {
|
||||
|
@ -66,13 +58,7 @@ public class CompositeCPPDeferredClassInstance extends CompositeCPPClassType imp
|
|||
return unknownScope;
|
||||
}
|
||||
|
||||
public IBinding resolvePartially(ICPPUnknownBinding parentBinding, ObjectMap argMap, ICPPScope instantiationScope) {
|
||||
IType[] arguments = getArguments();
|
||||
IType[] newArgs = CPPTemplates.instantiateTypes(arguments, argMap, instantiationScope);
|
||||
if (arguments == newArgs) {
|
||||
return this;
|
||||
}
|
||||
|
||||
return ((ICPPInternalTemplateInstantiator)getTemplateDefinition()).instantiate( newArgs );
|
||||
public ICPPClassTemplate getClassTemplate() {
|
||||
return (ICPPClassTemplate) cf.getCompositeBinding((IIndexFragmentBinding) ((ICPPDeferredClassInstance) rbinding).getClassTemplate());
|
||||
}
|
||||
}
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Reference in a new issue