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:
parent
174a5c5112
commit
88a41df697
9 changed files with 42 additions and 10 deletions
|
@ -4801,14 +4801,16 @@ public class AST2CPPTests extends AST2BaseTest {
|
||||||
// const_iterator begin() const;
|
// const_iterator begin() const;
|
||||||
// };
|
// };
|
||||||
//
|
//
|
||||||
// void test(const vector<int>& v) {
|
// typedef int Element;
|
||||||
|
//
|
||||||
|
// 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<int>::const_iterator", ASTTypeUtil.getType(it.getType(), false));
|
assertEquals("vector<Element>::const_iterator", ASTTypeUtil.getType(it.getType(), false));
|
||||||
}
|
}
|
||||||
|
|
||||||
// int f() {
|
// int f() {
|
||||||
|
|
|
@ -183,7 +183,8 @@ public class ASTTypeUtil {
|
||||||
if (val != null) {
|
if (val != null) {
|
||||||
buf.append(val.getSignature());
|
buf.append(val.getSignature());
|
||||||
} else {
|
} else {
|
||||||
appendType(arg.getTypeValue(), normalize, buf);
|
IType type = normalize ? arg.getTypeValue() : arg.getOriginalTypeValue();
|
||||||
|
appendType(type, normalize, buf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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
|
* 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,6 +7,7 @@
|
||||||
*
|
*
|
||||||
* 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,9 +41,17 @@ 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 evaluation object is returned.
|
* the evaluation object is returned.
|
||||||
|
|
|
@ -48,6 +48,11 @@ 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;
|
||||||
|
|
|
@ -22,10 +22,16 @@ 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) {
|
||||||
Assert.isNotNull(type);
|
this(type, type);
|
||||||
fType= type;
|
}
|
||||||
|
|
||||||
|
public CPPTemplateTypeArgument(IType simplifiedType, IType originalType) {
|
||||||
|
Assert.isNotNull(simplifiedType);
|
||||||
|
fType= simplifiedType;
|
||||||
|
fOriginalType= originalType;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -43,6 +49,11 @@ public class CPPTemplateTypeArgument implements ICPPTemplateArgument {
|
||||||
return fType;
|
return fType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IType getOriginalTypeValue() {
|
||||||
|
return fOriginalType;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ICPPEvaluation getNonTypeEvaluation() {
|
public ICPPEvaluation getNonTypeEvaluation() {
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -515,7 +515,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);
|
return new CPPTemplateTypeArgument(newType, arg.getOriginalTypeValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return arg;
|
return arg;
|
||||||
|
|
|
@ -217,6 +217,7 @@ public class PDOM extends PlatformObject implements IPDOM {
|
||||||
* 123.0 - Combined file size and encoding hash code.
|
* 123.0 - Combined file size and encoding hash code.
|
||||||
* 124.0 - GCC attributes and NO_RETURN flag for functions.
|
* 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>>
|
* #125.0# - Indexes for unresolved includes and files indexed with I/O errors. <<CDT 8.1>>
|
||||||
|
<<<<<<< cdt_8_1
|
||||||
<<<<<<< cdt_8_1
|
<<<<<<< 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.
|
||||||
|
|
|
@ -190,6 +190,7 @@ public class TypeMarshalBuffer implements ITypeMarshalBuffer {
|
||||||
arg.getNonTypeEvaluation().marshal(this, true);
|
arg.getNonTypeEvaluation().marshal(this, true);
|
||||||
} else {
|
} else {
|
||||||
marshalType(arg.getTypeValue());
|
marshalType(arg.getTypeValue());
|
||||||
|
marshalType(arg.getOriginalTypeValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -200,7 +201,9 @@ public class TypeMarshalBuffer implements ITypeMarshalBuffer {
|
||||||
return new CPPTemplateNonTypeArgument((ICPPEvaluation) unmarshalEvaluation(), null);
|
return new CPPTemplateNonTypeArgument((ICPPEvaluation) unmarshalEvaluation(), null);
|
||||||
} else {
|
} else {
|
||||||
fPos--;
|
fPos--;
|
||||||
return new CPPTemplateTypeArgument(unmarshalType());
|
IType type = unmarshalType();
|
||||||
|
IType originalType = unmarshalType();
|
||||||
|
return new CPPTemplateTypeArgument(type, originalType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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
|
* 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
|
||||||
|
@ -1328,7 +1328,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<int>::value_type & value) : void" };
|
final String[] expected= { "push_back(const vector<MyType>::value_type & value) : void" };
|
||||||
assertParameterHint(expected);
|
assertParameterHint(expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue