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

Preservation of typedefs in template arguments.

This commit is contained in:
Sergey Prigogin 2012-11-08 14:48:06 -08:00
parent 174a5c5112
commit 88a41df697
9 changed files with 42 additions and 10 deletions

View file

@ -4801,14 +4801,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.
* @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),
* 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

@ -217,6 +217,7 @@ public class PDOM extends PlatformObject implements IPDOM {
* 123.0 - Combined file size and encoding hash code.
* 124.0 - GCC attributes and NO_RETURN flag for functions.
* #125.0# - Indexes for unresolved includes and files indexed with I/O errors. <<CDT 8.1>>
<<<<<<< cdt_8_1
<<<<<<< cdt_8_1
* 126.0 - Dependent expressions, bug 299911.
* 127.0 - Explicit virtual overrides, bug 380623.

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);
}