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

Revert "Preservation of typedefs in template arguments."

This reverts commit 8ec3ab2f94.
This commit is contained in:
Sergey Prigogin 2012-11-08 14:04:50 -08:00
parent d6ad63a4d9
commit 3548fdb678
12 changed files with 27 additions and 104 deletions

View file

@ -4801,57 +4801,14 @@ public class AST2CPPTests extends AST2BaseTest {
// const_iterator begin() const; // const_iterator begin() const;
// }; // };
// //
// typedef int Element; // void test(const vector<int>& v) {
//
// void test(const vector<Element>& v) {
// auto it = v.begin(); // auto it = v.begin();
// } // }
public void testTypedefPreservation_380498_2() throws Exception { public void testTypedefPreservation_380498_2() throws Exception {
BindingAssertionHelper ba= getAssertionHelper(); BindingAssertionHelper ba= getAssertionHelper();
ICPPVariable it = ba.assertNonProblem("it =", "it", ICPPVariable.class); ICPPVariable it = ba.assertNonProblem("it =", "it", ICPPVariable.class);
assertTrue(it.getType() instanceof ITypedef); assertTrue(it.getType() instanceof ITypedef);
assertEquals("vector<Element>::const_iterator", ASTTypeUtil.getType(it.getType(), false)); assertEquals("vector<int>::const_iterator", ASTTypeUtil.getType(it.getType(), false));
}
// template <typename T> class char_traits {};
// template <typename C, typename T = char_traits<C>> class basic_string {};
//
// template<typename _Iterator>
// struct iterator_traits {
// typedef typename _Iterator::reference reference;
// };
//
// template<typename _Tp>
// struct iterator_traits<_Tp*> {
// typedef _Tp& reference;
// };
//
// template<typename _Iterator, typename _Container>
// struct normal_iterator {
// typedef iterator_traits<_Iterator> traits_type;
// typedef typename traits_type::reference reference;
// reference operator*() const;
// };
//
// template <typename T> struct vector {
// typedef T* pointer;
// typedef normal_iterator<pointer, vector> iterator;
// iterator begin();
// iterator end();
// };
//
// typedef basic_string<char> string;
//
// void test() {
// vector<string> v;
// for (auto s : v) {
// }
// }
public void testTypedefPreservation_380498_3() throws Exception {
BindingAssertionHelper ba= getAssertionHelper();
ICPPVariable s = ba.assertNonProblem("s :", "s", ICPPVariable.class);
assertTrue(s.getType() instanceof ITypedef);
assertEquals("string", ASTTypeUtil.getType(s.getType(), false));
} }
// int f() { // int f() {

View file

@ -183,8 +183,7 @@ public class ASTTypeUtil {
if (val != null) { if (val != null) {
buf.append(val.getSignature()); buf.append(val.getSignature());
} else { } else {
IType type = normalize ? arg.getTypeValue() : arg.getOriginalTypeValue(); appendType(arg.getTypeValue(), normalize, buf);
appendType(type, normalize, buf);
} }
} }

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2008, 2012 Wind River Systems, Inc. and others. * Copyright (c) 2008, 2009 Wind River Systems, Inc. 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
@ -7,7 +7,6 @@
* *
* Contributors: * Contributors:
* Markus Schorn - initial API and implementation * Markus Schorn - initial API and implementation
* Sergey Prigogin (Google)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.core.dom.ast.cpp; package org.eclipse.cdt.core.dom.ast.cpp;
@ -40,17 +39,9 @@ public interface ICPPTemplateArgument {
* If this is a type value (suitable for a template type and template template parameters), * If this is a type value (suitable for a template type and template template parameters),
* the type used as a value is returned. * the type used as a value is returned.
* For non-type values, <code>null</code> is returned. * For non-type values, <code>null</code> is returned.
* The returned type has all typedefs resolved.
*/ */
IType getTypeValue(); IType getTypeValue();
/**
* Similar to {@link #getTypeValue()} but returns the original type value before typedef
* resolution.
* @noreference This method is not intended to be referenced by clients.
*/
IType getOriginalTypeValue();
/** /**
* If this is a non-type value (suitable for a template non-type parameters), * If this is a non-type value (suitable for a template non-type parameters),
* the value is returned. * the value is returned.

View file

@ -41,11 +41,6 @@ public class CPPTemplateNonTypeArgument implements ICPPTemplateArgument {
return false; return false;
} }
@Override
public IType getOriginalTypeValue() {
return null;
}
@Override @Override
public boolean isNonTypeValue() { public boolean isNonTypeValue() {
return true; return true;

View file

@ -22,17 +22,10 @@ import org.eclipse.core.runtime.Assert;
*/ */
public class CPPTemplateTypeArgument implements ICPPTemplateArgument { public class CPPTemplateTypeArgument implements ICPPTemplateArgument {
private final IType fType; private final IType fType;
private final IType fOriginalType;
public CPPTemplateTypeArgument(IType type) { public CPPTemplateTypeArgument(IType type) {
this(type, type); Assert.isNotNull(type);
} fType= type;
public CPPTemplateTypeArgument(IType simplifiedType, IType originalType) {
Assert.isNotNull(simplifiedType);
Assert.isNotNull(originalType);
fType= simplifiedType;
fOriginalType= originalType;
} }
@Override @Override
@ -50,11 +43,6 @@ public class CPPTemplateTypeArgument implements ICPPTemplateArgument {
return fType; return fType;
} }
@Override
public IType getOriginalTypeValue() {
return fOriginalType;
}
@Override @Override
public IValue getNonTypeValue() { public IValue getNonTypeValue() {
return null; return null;

View file

@ -1162,7 +1162,7 @@ public class CPPTemplates {
} }
if (arg != null) { if (arg != null) {
IType t= arg.getOriginalTypeValue(); IType t= arg.getTypeValue();
if (t != null) if (t != null)
return t; return t;
} }

View file

@ -13,8 +13,6 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp.semantics;
import static org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory.LVALUE; import static org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory.LVALUE;
import static org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory.PRVALUE; import static org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory.PRVALUE;
import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.TDEF;
import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.getNestedType;
import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTExpression;
@ -296,7 +294,7 @@ public class EvalID extends CPPEvaluation {
} else if (nameOwner instanceof IType) { } else if (nameOwner instanceof IType) {
IType type = CPPTemplates.instantiateType((IType) nameOwner, tpMap, packOffset, within, point); IType type = CPPTemplates.instantiateType((IType) nameOwner, tpMap, packOffset, within, point);
if (type instanceof IBinding) if (type instanceof IBinding)
nameOwner = (IBinding) getNestedType(type, TDEF); nameOwner = (IBinding) type;
} }
if (fieldOwner instanceof IProblemBinding || nameOwner instanceof IProblemBinding) if (fieldOwner instanceof IProblemBinding || nameOwner instanceof IProblemBinding)

View file

@ -512,7 +512,7 @@ public class SemanticUtil {
final IType type= arg.getTypeValue(); final IType type= arg.getTypeValue();
final IType newType= getSimplifiedType(type); final IType newType= getSimplifiedType(type);
if (newType != type) { if (newType != type) {
return new CPPTemplateTypeArgument(newType, arg.getOriginalTypeValue()); return new CPPTemplateTypeArgument(newType);
} }
} }
return arg; return arg;

View file

@ -665,12 +665,11 @@ public class TemplateArgumentDeduction {
return tval.equals(sval); return tval.equals(sval);
} }
return fromType(p.getTypeValue(), a.getOriginalTypeValue(), false, point); return fromType(p.getTypeValue(), a.getTypeValue(), false, point);
} }
private boolean fromType(IType p, IType a, boolean allowCVQConversion, IASTNode point) throws DOMException { private boolean fromType(IType p, IType a, boolean allowCVQConversion, IASTNode point) throws DOMException {
while (p != null) { while (p != null) {
IType argumentTypeBeforeTypedefResolution = a;
while (a instanceof ITypedef) while (a instanceof ITypedef)
a = ((ITypedef) a).getType(); a = ((ITypedef) a).getType();
if (p instanceof IBasicType) { if (p instanceof IBasicType) {
@ -763,7 +762,7 @@ public class TemplateArgumentDeduction {
} }
if (a == null) if (a == null)
return false; return false;
return deduce(((ICPPTemplateParameter) p).getParameterID(), new CPPTemplateTypeArgument(a, argumentTypeBeforeTypedefResolution)); return deduce(((ICPPTemplateParameter)p).getParameterID(), new CPPTemplateTypeArgument(a));
} else if (p instanceof ICPPTemplateInstance) { } else if (p instanceof ICPPTemplateInstance) {
if (!(a instanceof ICPPTemplateInstance)) if (!(a instanceof ICPPTemplateInstance))
return false; return false;

View file

@ -219,11 +219,10 @@ public class PDOM extends PlatformObject implements IPDOM {
* #125.0# - Indexes for unresolved includes and files indexed with I/O errors. <<CDT 8.1>> * #125.0# - Indexes for unresolved includes and files indexed with I/O errors. <<CDT 8.1>>
* 126.0 - Dependent expressions, bug 299911. * 126.0 - Dependent expressions, bug 299911.
* 127.0 - Explicit virtual overrides, bug 380623. * 127.0 - Explicit virtual overrides, bug 380623.
* 128.0 - Extended CPPTemplateTypeArgument to include the original type, bug 392278.
*/ */
private static final int MIN_SUPPORTED_VERSION= version(128, 0); private static final int MIN_SUPPORTED_VERSION= version(127, 0);
private static final int MAX_SUPPORTED_VERSION= version(128, Short.MAX_VALUE); private static final int MAX_SUPPORTED_VERSION= version(127, Short.MAX_VALUE);
private static final int DEFAULT_VERSION = version(128, 0); private static final int DEFAULT_VERSION = version(127, 0);
private static int version(int major, int minor) { private static int version(int major, int minor) {
return (major << 16) + minor; return (major << 16) + minor;

View file

@ -194,7 +194,6 @@ public class TypeMarshalBuffer implements ITypeMarshalBuffer {
((CPPTemplateNonTypeArgument) arg).getEvaluation().marshal(this, true); ((CPPTemplateNonTypeArgument) arg).getEvaluation().marshal(this, true);
} else { } else {
marshalType(arg.getTypeValue()); marshalType(arg.getTypeValue());
marshalType(arg.getOriginalTypeValue());
} }
} }
@ -205,9 +204,7 @@ public class TypeMarshalBuffer implements ITypeMarshalBuffer {
return new CPPTemplateNonTypeArgument((ICPPEvaluation) unmarshalEvaluation()); return new CPPTemplateNonTypeArgument((ICPPEvaluation) unmarshalEvaluation());
} else { } else {
fPos--; fPos--;
IType type = unmarshalType(); return new CPPTemplateTypeArgument(unmarshalType());
IType originalType = unmarshalType();
return new CPPTemplateTypeArgument(type, originalType);
} }
} }

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2006, 2012 Wind River Systems, Inc. and others. * Copyright (c) 2006, 2011 Wind River Systems, Inc. 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
@ -1329,7 +1329,7 @@ public class CompletionTests extends AbstractContentAssistTest {
// v.push_back(/*cursor*/); // v.push_back(/*cursor*/);
// } // }
public void testTypedefSpecialization_Bug307818() throws Exception { public void testTypedefSpecialization_Bug307818() throws Exception {
final String[] expected= { "push_back(const vector<MyType>::value_type & value) : void" }; final String[] expected= { "push_back(const vector<int>::value_type & value) : void" };
assertParameterHint(expected); assertParameterHint(expected);
} }