Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSergey Prigogin2012-08-13 00:25:57 +0000
committerSergey Prigogin2012-08-14 22:49:26 +0000
commite13f1ed5ece59c7cfbab03efb5ff7c2b064d6a45 (patch)
treeb8e715724e1386fb75e3c3bac1b62d0c94bdec0c
parent88fb29136e20e57da5675a7b4d283ecd4d2b4353 (diff)
downloadorg.eclipse.cdt-e13f1ed5ece59c7cfbab03efb5ff7c2b064d6a45.tar.gz
org.eclipse.cdt-e13f1ed5ece59c7cfbab03efb5ff7c2b064d6a45.tar.xz
org.eclipse.cdt-e13f1ed5ece59c7cfbab03efb5ff7c2b064d6a45.zip
Added failing IndexCPPTemplateResolutionTest._testSFINAE_a test.
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexBindingResolutionTestBase.java139
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPBindingResolutionBugs.java6
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPTemplateResolutionTest.java81
3 files changed, 171 insertions, 55 deletions
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexBindingResolutionTestBase.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexBindingResolutionTestBase.java
index 64cb7063c1f..1ceb2d2ba5d 100644
--- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexBindingResolutionTestBase.java
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexBindingResolutionTestBase.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2010 Symbian Software Systems and others.
+ * Copyright (c) 2006, 2012 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
@@ -20,6 +20,7 @@ import java.util.List;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.IPDOMManager;
import org.eclipse.cdt.core.dom.ast.ASTTypeUtil;
+import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNodeSelector;
@@ -59,30 +60,30 @@ import org.osgi.framework.Bundle;
* is backed by the PDOM), it must be possible to resolve which binding a name
* in the AST is referring to. If the binding is not defined in the AST fragment
* then it is assumed to have come from a file which is already indexed.
- *
+ *
* This class is for testing the process by which bindings are looked up in
* the PDOM purely from AST information (i.e. without a real binding from the DOM)
*/
public abstract class IndexBindingResolutionTestBase extends BaseTestCase {
private static final boolean DEBUG= false;
protected ITestStrategy strategy;
-
+
public void setStrategy(ITestStrategy strategy) {
this.strategy = strategy;
}
-
+
@Override
protected void setUp() throws Exception {
super.setUp();
strategy.setUp();
}
-
+
@Override
protected void tearDown() throws Exception {
strategy.tearDown();
super.tearDown();
}
-
+
protected IASTName findName(String section, int len) {
if (len == 0)
len= section.length();
@@ -97,10 +98,10 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase {
return name;
}
}
-
+
return null;
}
-
+
/**
* Attempts to get an IBinding from the initial specified number of characters
* from the specified code fragment. Fails the test if
@@ -122,25 +123,25 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase {
IASTName name= findName(section, len);
assertNotNull("Name not found for \"" + section + "\"", name);
assertEquals(section.substring(0, len), name.getRawSignature());
-
+
IBinding binding = name.resolveBinding();
assertNotNull("No binding for " + name.getRawSignature(), binding);
assertFalse("Binding is a ProblemBinding for name \"" + name.getRawSignature() + "\"", IProblemBinding.class.isAssignableFrom(name.resolveBinding().getClass()));
assertInstance(binding, clazz, cs);
return clazz.cast(binding);
}
-
+
/*
* @see IndexBindingResolutionTestBase#getBindingFromASTName(Class, String, int)
*/
protected <T extends IBinding> T getBindingFromASTName(String section, int len) {
if (len <= 0)
len += section.length();
-
+
IASTName name= findName(section, len);
assertNotNull("Name not found for \"" + section + "\"", name);
assertEquals(section.substring(0, len), name.getRawSignature());
-
+
IBinding binding = name.resolveBinding();
assertNotNull("No binding for " + name.getRawSignature(), binding);
assertFalse("Binding is a ProblemBinding for name \"" + name.getRawSignature() + "\"", IProblemBinding.class.isAssignableFrom(name.resolveBinding().getClass()));
@@ -157,17 +158,17 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase {
IASTName name= findName(section, len);
assertNotNull("Name not found for \"" + section + "\"", name);
assertEquals(section.substring(0, len), name.getRawSignature());
-
+
IBinding binding = name.resolveBinding();
assertNotNull("No binding for " + name.getRawSignature(), binding);
assertTrue("Binding is not a ProblemBinding for name \"" + name.getRawSignature() + "\"", IProblemBinding.class.isAssignableFrom(name.resolveBinding().getClass()));
return name.resolveBinding();
}
-
+
protected static void assertQNEquals(String expectedQN, IBinding b) {
assertInstance(b, IBinding.class);
if (b instanceof ICPPBinding) {
- assertEquals(expectedQN, ASTTypeUtil.getQualifiedName((ICPPBinding)b));
+ assertEquals(expectedQN, ASTTypeUtil.getQualifiedName((ICPPBinding) b));
} else {
assertEquals(expectedQN, b.getName());
}
@@ -175,7 +176,7 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase {
protected IType getVariableType(IBinding binding) throws DOMException {
assertTrue(binding instanceof IVariable);
- return ((IVariable)binding).getType();
+ return ((IVariable) binding).getType();
}
protected IType getPtrType(IBinding binding) throws DOMException {
@@ -195,8 +196,8 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase {
// assert function is IFunctionType
IFunctionType ft = (IFunctionType) function;
assertTrue(ICPPClassType.class.isInstance((ft.getParameterTypes()[index])));
- assertEquals(compositeTypeKey, ((ICPPClassType)ft.getParameterTypes()[index]).getKey());
- assertEquals(qn, ASTTypeUtil.getQualifiedName((ICPPClassType)ft.getParameterTypes()[index]));
+ assertEquals(compositeTypeKey, ((ICPPClassType) ft.getParameterTypes()[index]).getKey());
+ assertEquals(qn, ASTTypeUtil.getQualifiedName((ICPPClassType) ft.getParameterTypes()[index]));
}
protected static <T> T assertInstance(Object o, Class<T> clazz, Class ... cs) {
@@ -207,7 +208,7 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase {
}
return clazz.cast(o);
}
-
+
protected String readTaggedComment(final String tag) throws IOException {
return TestSourceReader.readTaggedComment(CTestPlugin.getDefault().getBundle(), "parser", getClass(), tag);
}
@@ -216,18 +217,6 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase {
return strategy.getIndex();
}
- interface ITestStrategy {
- IIndex getIndex();
- void setUp() throws Exception;
- void tearDown() throws Exception;
- public int getAstCount();
- public IASTTranslationUnit getAst(int index);
- public StringBuilder getAstSource(int index);
- public StringBuilder[] getTestData();
- public ICProject getCProject();
- public boolean isCompositeIndex();
- }
-
protected static void assertVariable(IBinding b, String qn, Class expType, String expTypeQN) {
assertInstance(b, IVariable.class);
IVariable variable = (IVariable) b;
@@ -239,18 +228,64 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase {
assertQNEquals(expTypeQN, (IBinding) type);
}
}
-
+
protected static void assertTypeContainer(IType conType, String expQN, Class containerType, Class expContainedType, String expContainedTypeQN) {
assertInstance(conType, ITypeContainer.class);
assertInstance(conType, containerType);
- IType containedType= ((ITypeContainer)conType).getType();
+ IType containedType= ((ITypeContainer) conType).getType();
assertInstance(containedType, expContainedType);
if (expContainedTypeQN != null) {
assertInstance(containedType, IBinding.class);
assertQNEquals(expContainedTypeQN, (IBinding) containedType);
}
}
-
+
+ final protected void checkBindings() throws Exception {
+ for (int i = 0; i < strategy.getAstCount(); i++) {
+ IASTTranslationUnit ast = strategy.getAst(i);
+ CNameCollector col = new CNameCollector();
+ ast.accept(col);
+ for (IASTName n : col.nameList) {
+ assertFalse("ProblemBinding for " + n.getRawSignature(), n.resolveBinding() instanceof IProblemBinding);
+ }
+ }
+ }
+
+ static protected class CNameCollector extends ASTVisitor {
+ {
+ shouldVisitNames = true;
+ }
+ public List<IASTName> nameList = new ArrayList<IASTName>();
+
+ @Override
+ public int visit(IASTName name) {
+ nameList.add(name);
+ return PROCESS_CONTINUE;
+ }
+
+ public IASTName getName(int idx) {
+ if (idx < 0 || idx >= nameList.size())
+ return null;
+ return nameList.get(idx);
+ }
+
+ public int size() {
+ return nameList.size();
+ }
+ }
+
+ interface ITestStrategy {
+ IIndex getIndex();
+ void setUp() throws Exception;
+ void tearDown() throws Exception;
+ public int getAstCount();
+ public IASTTranslationUnit getAst(int index);
+ public StringBuilder getAstSource(int index);
+ public StringBuilder[] getTestData();
+ public ICProject getCProject();
+ public boolean isCompositeIndex();
+ }
+
class SinglePDOMTestFirstASTStrategy implements ITestStrategy {
private IIndex index;
private ICProject cproject;
@@ -266,7 +301,7 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase {
public ICProject getCProject() {
return cproject;
}
-
+
@Override
public StringBuilder[] getTestData() {
return testData;
@@ -293,7 +328,7 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase {
@Override
public void setUp() throws Exception {
- cproject = cpp ? CProjectHelper.createCCProject(getName() + System.currentTimeMillis(), "bin", IPDOMManager.ID_NO_INDEXER)
+ cproject = cpp ? CProjectHelper.createCCProject(getName() + System.currentTimeMillis(), "bin", IPDOMManager.ID_NO_INDEXER)
: CProjectHelper.createCProject(getName() + System.currentTimeMillis(), "bin", IPDOMManager.ID_NO_INDEXER);
Bundle b = CTestPlugin.getDefault().getBundle();
testData = TestSourceReader.getContentsForTest(b, "parser", IndexBindingResolutionTestBase.this.getClass(), getName(), 2);
@@ -330,7 +365,7 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase {
public IIndex getIndex() {
return index;
}
-
+
@Override
public boolean isCompositeIndex() {
return false;
@@ -379,7 +414,7 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase {
@Override
public void setUp() throws Exception {
- cproject = cpp ? CProjectHelper.createCCProject(getName()+System.currentTimeMillis(), "bin", IPDOMManager.ID_NO_INDEXER)
+ cproject = cpp ? CProjectHelper.createCCProject(getName()+System.currentTimeMillis(), "bin", IPDOMManager.ID_NO_INDEXER)
: CProjectHelper.createCProject(getName()+System.currentTimeMillis(), "bin", IPDOMManager.ID_NO_INDEXER);
Bundle b = CTestPlugin.getDefault().getBundle();
testData = TestSourceReader.getContentsForTest(b, "parser", IndexBindingResolutionTestBase.this.getClass(), getName(), 2);
@@ -390,7 +425,7 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase {
IFile cppfile= TestSourceReader.createFile(cproject.getProject(), new Path("references.c" + (cpp ? "pp" : "")), testData[1].toString());
assertTrue(CCorePlugin.getIndexManager().joinIndexer(360000, new NullProgressMonitor()));
-
+
if (DEBUG) {
System.out.println("Project PDOM: " + getName());
((PDOM)CCoreInternals.getPDOMManager().getPDOM(cproject)).accept(new PDOMPrettyPrinter());
@@ -416,7 +451,7 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase {
public IIndex getIndex() {
return index;
}
-
+
@Override
public boolean isCompositeIndex() {
return false;
@@ -472,7 +507,7 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase {
@Override
public void setUp() throws Exception {
- cproject = cpp ? CProjectHelper.createCCProject(getName() + System.currentTimeMillis(), "bin", IPDOMManager.ID_NO_INDEXER)
+ cproject = cpp ? CProjectHelper.createCCProject(getName() + System.currentTimeMillis(), "bin", IPDOMManager.ID_NO_INDEXER)
: CProjectHelper.createCProject(getName() + System.currentTimeMillis(), "bin", IPDOMManager.ID_NO_INDEXER);
Bundle b = CTestPlugin.getDefault().getBundle();
testData = TestSourceReader.getContentsForTest(b, "parser", IndexBindingResolutionTestBase.this.getClass(), getName(), 0);
@@ -499,7 +534,7 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase {
}
CCorePlugin.getIndexManager().setIndexerId(cproject, IPDOMManager.ID_FAST_INDEXER);
assertTrue(CCorePlugin.getIndexManager().joinIndexer(360000, new NullProgressMonitor()));
-
+
if (DEBUG) {
System.out.println("Project PDOM: " + getName());
((PDOM) CCoreInternals.getPDOMManager().getPDOM(cproject)).accept(new PDOMPrettyPrinter());
@@ -527,7 +562,7 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase {
public IIndex getIndex() {
return index;
}
-
+
@Override
public boolean isCompositeIndex() {
return false;
@@ -549,7 +584,7 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase {
public ICProject getCProject() {
return cproject;
}
-
+
@Override
public void tearDown() throws Exception {
if (index != null) {
@@ -582,7 +617,7 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase {
IndexerPreferences.set(cproject.getProject(), IndexerPreferences.KEY_INDEXER_ID, IPDOMManager.ID_FAST_INDEXER);
CCorePlugin.getIndexManager().reindex(cproject);
assertTrue(CCorePlugin.getIndexManager().joinIndexer(360000, new NullProgressMonitor()));
-
+
if (DEBUG) {
System.out.println("Online: "+getName());
((PDOM)CCoreInternals.getPDOMManager().getPDOM(cproject)).accept(new PDOMPrettyPrinter());
@@ -598,17 +633,17 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase {
: CProjectHelper.createCProject("ReferencedContent"+System.currentTimeMillis(), "bin", IPDOMManager.ID_NO_INDEXER);
String content = testData[0].toString();
IFile file = TestSourceReader.createFile(referenced.getProject(), new Path("header.h"), content);
-
+
IndexerPreferences.set(referenced.getProject(), IndexerPreferences.KEY_INDEXER_ID, IPDOMManager.ID_FAST_INDEXER);
CCorePlugin.getIndexManager().reindex(referenced);
-
+
assertTrue(CCorePlugin.getIndexManager().joinIndexer(360000, new NullProgressMonitor()));
-
+
if (DEBUG) {
System.out.println("Referenced: "+getName());
((PDOM)CCoreInternals.getPDOMManager().getPDOM(referenced)).accept(new PDOMPrettyPrinter());
}
-
+
return referenced;
}
@@ -640,7 +675,7 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase {
public StringBuilder[] getTestData() {
return testData;
}
-
+
@Override
public boolean isCompositeIndex() {
return true;
@@ -650,7 +685,7 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase {
/**
* When a test is failing only for the strategy where the test data is split over
* multiple index fragments, we artificially fail the single fragment strategy also.
- * This is not ideal, but as both strategies behavior are typically the same, is
+ * This is not ideal, but as both strategies behavior are typically the same, is
* quite rare.
*/
protected void fakeFailForSingle() {
@@ -662,7 +697,7 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase {
/**
* When a test is failing only for the strategy where the test data is not split over
* multiple index fragments, we artificially fail the single fragment strategy also.
- * This is not ideal, but as both strategies behavior are typically the same, is
+ * This is not ideal, but as both strategies behavior are typically the same, is
* quite rare.
*/
protected void fakeFailForMultiProject() {
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPBindingResolutionBugs.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPBindingResolutionBugs.java
index 05fc01240ba..de0b1a2065f 100644
--- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPBindingResolutionBugs.java
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPBindingResolutionBugs.java
@@ -6,8 +6,9 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * Markus Schorn - initial API and implementation
- * Andrew Ferguson (Symbian)
+ * Markus Schorn - initial API and implementation
+ * Andrew Ferguson (Symbian)
+ * Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.internal.index.tests;
@@ -58,7 +59,6 @@ import org.eclipse.cdt.core.parser.util.ObjectMap;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateTypeArgument;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ClassTypeHelper;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInstanceCache;
-import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil;
import org.eclipse.core.runtime.CoreException;
/**
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPTemplateResolutionTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPTemplateResolutionTest.java
index 64423a8ab91..5aafb47c898 100644
--- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPTemplateResolutionTest.java
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPTemplateResolutionTest.java
@@ -8,6 +8,7 @@
* Contributors:
* Andrew Ferguson (Symbian) - Initial implementation
* Markus Schorn (Wind River Systems)
+ * Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.internal.index.tests;
@@ -1954,4 +1955,84 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa
ITypedef tdef= getBindingFromASTName("type t;", 4, ITypedef.class);
assertEquals("int", ASTTypeUtil.getType(tdef, true));
}
+
+ // template<typename T, T v>
+ // struct integral_constant {
+ // static constexpr T value = v;
+ // typedef T value_type;
+ // typedef integral_constant<T, v> type;
+ // };
+ //
+ // typedef integral_constant<bool, true> true_type;
+ //
+ // typedef integral_constant<bool, false> false_type;
+ //
+ // template<typename T>
+ // class helper {
+ // typedef char one;
+ // typedef struct { char arr[2]; } two;
+ // template<typename U> struct Wrap_type {};
+ // template<typename U> static one test(Wrap_type<typename U::category>*);
+ // template<typename U> static two test(...);
+ // public: static const bool value = sizeof(test<T>(0)) == 1;
+ // };
+ //
+ // template<typename T>
+ // struct has_category : integral_constant<bool, helper<T>::value> {};
+ //
+ // template<typename Iterator, bool = has_category<Iterator>::value>
+ // struct traits {};
+ //
+ // template<typename Iterator>
+ // struct traits<Iterator, true> {
+ // typedef typename Iterator::value_type value_type;
+ // };
+ //
+ // struct tag {};
+
+ // struct C {
+ // typedef int value_type;
+ // typedef tag category;
+ // };
+ //
+ // template<typename It, typename Val = typename traits<It>::value_type>
+ // class A {
+ // };
+ //
+ // typedef A<C> type;
+ public void _testSFINAE_a() throws Exception {
+ checkBindings();
+ }
+
+ // template <bool B, typename T = void> struct enable_if { typedef T type; };
+ // template <typename T> struct enable_if<false, T> {};
+ //
+ // template <typename T> struct is_int { static const bool value = false; };
+ // template <> struct is_int<int> { static const bool value = true; };
+ //
+ // template <typename T> struct is_double { static const bool value = false; };
+ // template <> struct is_double<double> { static const bool value = true; };
+ //
+ // template <typename T, typename Enabled = void>
+ // struct A {
+ // static int get() { return 0; }
+ // };
+ //
+ // template<typename T>
+ // struct A<T, typename enable_if<is_double<T>::value>::type> {
+ // static int get() { return 1; }
+ // };
+ //
+ // template <typename T>
+ // struct A<T, typename enable_if<is_int<T>::value>::type> {
+ // static int get() { return 2; }
+ // };
+
+ // void test() {
+ // A<double>::get();
+ // A<int>::get();
+ // }
+ public void testSFINAE_b() throws Exception {
+ checkBindings();
+ }
}

Back to the top