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

Added failing IndexCPPTemplateResolutionTest._testSFINAE_a test.

This commit is contained in:
Sergey Prigogin 2012-08-12 17:25:57 -07:00
parent c479c6ccb7
commit aaa0f85bb3
3 changed files with 180 additions and 64 deletions

View file

@ -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 * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * 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.CCorePlugin;
import org.eclipse.cdt.core.dom.IPDOMManager; import org.eclipse.cdt.core.dom.IPDOMManager;
import org.eclipse.cdt.core.dom.ast.ASTTypeUtil; 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.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNodeSelector; import org.eclipse.cdt.core.dom.ast.IASTNodeSelector;
@ -216,18 +217,6 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase {
return strategy.getIndex(); 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) { protected static void assertVariable(IBinding b, String qn, Class expType, String expTypeQN) {
assertInstance(b, IVariable.class); assertInstance(b, IVariable.class);
IVariable variable = (IVariable) b; IVariable variable = (IVariable) b;
@ -251,6 +240,52 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase {
} }
} }
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 { class SinglePDOMTestFirstASTStrategy implements ITestStrategy {
private IIndex index; private IIndex index;
private ICProject cproject; private ICProject cproject;

View file

@ -8,6 +8,7 @@
* Contributors: * Contributors:
* Markus Schorn - initial API and implementation * Markus Schorn - initial API and implementation
* Andrew Ferguson (Symbian) * Andrew Ferguson (Symbian)
* Sergey Prigogin (Google)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.index.tests; 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.CPPTemplateTypeArgument;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ClassTypeHelper; 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.ICPPInstanceCache;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
/** /**

View file

@ -8,6 +8,7 @@
* Contributors: * Contributors:
* Andrew Ferguson (Symbian) - Initial implementation * Andrew Ferguson (Symbian) - Initial implementation
* Markus Schorn (Wind River Systems) * Markus Schorn (Wind River Systems)
* Sergey Prigogin (Google)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.index.tests; package org.eclipse.cdt.internal.index.tests;
@ -1954,4 +1955,84 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa
ITypedef tdef= getBindingFromASTName("type t;", 4, ITypedef.class); ITypedef tdef= getBindingFromASTName("type t;", 4, ITypedef.class);
assertEquals("int", ASTTypeUtil.getType(tdef, true)); 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();
}
} }