1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-24 01:15:29 +02:00

Preservation of typedefs in template arguments.

This commit is contained in:
Sergey Prigogin 2012-10-24 23:20:21 +02:00
parent 8b36ca271a
commit 86390642d7
9 changed files with 45 additions and 13 deletions

View file

@ -4747,14 +4747,16 @@ public class AST2CPPTests extends AST2BaseTest {
// const_iterator begin() const;
// };
//
// void test(const vector<int>& v) {
// typedef int Element;
//
// void test(const vector<Element>& v) {
// auto it = v.begin();
// }
public void testTypedefPreservation_380498_2() throws Exception {
BindingAssertionHelper ba= getAssertionHelper();
ICPPVariable it = ba.assertNonProblem("it =", "it", ICPPVariable.class);
assertTrue(it.getType() instanceof ITypedef);
assertEquals("vector<int>::const_iterator", ASTTypeUtil.getType(it.getType(), false));
assertEquals("vector<Element>::const_iterator", ASTTypeUtil.getType(it.getType(), false));
}
// int f() {

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -225,10 +225,11 @@ public class PDOM extends PlatformObject implements IPDOM {
* 133.0 - Storing template arguments via direct marshalling, bug 299911.
* 134.0 - Storing unknown bindings via direct marshalling, bug 381824.
* 135.0 - Changed marshalling of EvalUnary, bug 391001.
* 136.0 - Extended CPPTemplateTypeArgument to include the original type, bug 392278.
*/
private static final int MIN_SUPPORTED_VERSION= version(135, 0);
private static final int MAX_SUPPORTED_VERSION= version(135, Short.MAX_VALUE);
private static final int DEFAULT_VERSION = version(135, 0);
private static final int MIN_SUPPORTED_VERSION= version(136, 0);
private static final int MAX_SUPPORTED_VERSION= version(136, Short.MAX_VALUE);
private static final int DEFAULT_VERSION = version(136, 0);
private static int version(int major, int minor) {
return (major << 16) + minor;

View file

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

View file

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