mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-23 22:52:11 +02:00
Correct determination of default template arguments, bug 281781.
This commit is contained in:
parent
e4a67a4897
commit
aa1e4bd52c
5 changed files with 46 additions and 22 deletions
|
@ -2572,14 +2572,19 @@ public class AST2TemplateTests extends AST2BaseTest {
|
|||
}
|
||||
|
||||
// template<class T, class U> class A;
|
||||
// template<class T, int U> class AI;
|
||||
// template<class T, template<typename V1, typename V2> class U> class AT;
|
||||
//
|
||||
// class B {};
|
||||
//
|
||||
// template<class T, class U = B>
|
||||
// class A {};
|
||||
// template<class T, class U = B> class A {};
|
||||
// template<class T, int U=1> class AI {};
|
||||
// template<class T, template<typename V1, typename V2> class U=A> class AT {};
|
||||
//
|
||||
// A<char> x;
|
||||
public void _testDefaultTemplateParameter_281781() throws Exception {
|
||||
// AI<char> y;
|
||||
// AT<char> z;
|
||||
public void testDefaultTemplateParameter_281781() throws Exception {
|
||||
final String code = getAboveComment();
|
||||
parseAndCheckBindings(code, ParserLanguage.CPP);
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@ import org.eclipse.cdt.core.dom.ast.IASTExpression;
|
|||
import org.eclipse.cdt.core.dom.ast.IASTInitializer;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTInitializerExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IType;
|
||||
import org.eclipse.cdt.core.dom.ast.IValue;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateArgument;
|
||||
|
@ -37,12 +38,20 @@ public class CPPTemplateNonTypeParameter extends CPPTemplateParameter implements
|
|||
}
|
||||
|
||||
public IASTExpression getDefault() {
|
||||
IASTName name = getPrimaryDeclaration();
|
||||
IASTDeclarator dtor = (IASTDeclarator) name.getParent();
|
||||
IASTInitializer initializer = dtor.getInitializer();
|
||||
if( initializer instanceof IASTInitializerExpression )
|
||||
return ((IASTInitializerExpression) initializer).getExpression();
|
||||
IASTName[] nds = getDeclarations();
|
||||
if (nds == null || nds.length == 0)
|
||||
return null;
|
||||
|
||||
for (IASTName name : nds) {
|
||||
IASTNode parent = name.getParent();
|
||||
assert parent instanceof IASTDeclarator;
|
||||
if (parent instanceof IASTDeclarator) {
|
||||
IASTDeclarator dtor = (IASTDeclarator) parent;
|
||||
IASTInitializer initializer = dtor.getInitializer();
|
||||
if (initializer instanceof IASTInitializerExpression)
|
||||
return ((IASTInitializerExpression) initializer).getExpression();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
@ -158,7 +158,7 @@ public abstract class CPPTemplateParameter extends PlatformObject
|
|||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBinding#getDeclarations()
|
||||
*/
|
||||
public IASTNode[] getDeclarations() {
|
||||
public IASTName[] getDeclarations() {
|
||||
return declarations;
|
||||
}
|
||||
|
||||
|
|
|
@ -91,14 +91,19 @@ public class CPPTemplateTemplateParameter extends CPPTemplateParameter implement
|
|||
}
|
||||
|
||||
public IType getDefault() {
|
||||
IASTNode[] nds = getDeclarations();
|
||||
IASTName[] nds = getDeclarations();
|
||||
if (nds == null || nds.length == 0)
|
||||
return null;
|
||||
IASTName name = (IASTName) nds[0];
|
||||
ICPPASTTemplatedTypeTemplateParameter param = (ICPPASTTemplatedTypeTemplateParameter) name.getParent();
|
||||
IASTExpression defaultValue = param.getDefaultValue();
|
||||
if (defaultValue != null)
|
||||
return CPPVisitor.createType(defaultValue);
|
||||
for (IASTName nd : nds) {
|
||||
IASTNode parent = nd.getParent();
|
||||
assert parent instanceof ICPPASTTemplatedTypeTemplateParameter;
|
||||
if (parent instanceof ICPPASTTemplatedTypeTemplateParameter) {
|
||||
ICPPASTTemplatedTypeTemplateParameter param = (ICPPASTTemplatedTypeTemplateParameter) parent;
|
||||
IASTExpression value = param.getDefaultValue();
|
||||
if (value != null)
|
||||
return CPPVisitor.createType(value);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
@ -46,14 +46,19 @@ public class CPPTemplateTypeParameter extends CPPTemplateParameter implements
|
|||
}
|
||||
|
||||
public IType getDefault() {
|
||||
IASTNode[] nds = getDeclarations();
|
||||
IASTName[] nds = getDeclarations();
|
||||
if (nds == null || nds.length == 0)
|
||||
return null;
|
||||
IASTName name = (IASTName) nds[0];
|
||||
ICPPASTSimpleTypeTemplateParameter simple = (ICPPASTSimpleTypeTemplateParameter) name.getParent();
|
||||
for (IASTName nd : nds) {
|
||||
IASTNode parent = nd.getParent();
|
||||
assert parent instanceof ICPPASTSimpleTypeTemplateParameter;
|
||||
if (parent instanceof ICPPASTSimpleTypeTemplateParameter) {
|
||||
ICPPASTSimpleTypeTemplateParameter simple = (ICPPASTSimpleTypeTemplateParameter) parent;
|
||||
IASTTypeId typeId = simple.getDefaultType();
|
||||
if (typeId != null)
|
||||
return CPPVisitor.createType(typeId);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue