mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-08 02:06:01 +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, 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 {};
|
// class B {};
|
||||||
//
|
//
|
||||||
// template<class T, class U = B>
|
// template<class T, class U = B> class A {};
|
||||||
// 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;
|
// 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();
|
final String code = getAboveComment();
|
||||||
parseAndCheckBindings(code, ParserLanguage.CPP);
|
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.IASTInitializer;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTInitializerExpression;
|
import org.eclipse.cdt.core.dom.ast.IASTInitializerExpression;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
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.IType;
|
||||||
import org.eclipse.cdt.core.dom.ast.IValue;
|
import org.eclipse.cdt.core.dom.ast.IValue;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateArgument;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateArgument;
|
||||||
|
@ -37,12 +38,20 @@ public class CPPTemplateNonTypeParameter extends CPPTemplateParameter implements
|
||||||
}
|
}
|
||||||
|
|
||||||
public IASTExpression getDefault() {
|
public IASTExpression getDefault() {
|
||||||
IASTName name = getPrimaryDeclaration();
|
IASTName[] nds = getDeclarations();
|
||||||
IASTDeclarator dtor = (IASTDeclarator) name.getParent();
|
if (nds == null || nds.length == 0)
|
||||||
IASTInitializer initializer = dtor.getInitializer();
|
return null;
|
||||||
if( initializer instanceof IASTInitializerExpression )
|
|
||||||
return ((IASTInitializerExpression) initializer).getExpression();
|
|
||||||
|
|
||||||
|
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;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -158,7 +158,7 @@ public abstract class CPPTemplateParameter extends PlatformObject
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBinding#getDeclarations()
|
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBinding#getDeclarations()
|
||||||
*/
|
*/
|
||||||
public IASTNode[] getDeclarations() {
|
public IASTName[] getDeclarations() {
|
||||||
return declarations;
|
return declarations;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -91,14 +91,19 @@ public class CPPTemplateTemplateParameter extends CPPTemplateParameter implement
|
||||||
}
|
}
|
||||||
|
|
||||||
public IType getDefault() {
|
public IType getDefault() {
|
||||||
IASTNode[] nds = getDeclarations();
|
IASTName[] nds = getDeclarations();
|
||||||
if (nds == null || nds.length == 0)
|
if (nds == null || nds.length == 0)
|
||||||
return null;
|
return null;
|
||||||
IASTName name = (IASTName) nds[0];
|
for (IASTName nd : nds) {
|
||||||
ICPPASTTemplatedTypeTemplateParameter param = (ICPPASTTemplatedTypeTemplateParameter) name.getParent();
|
IASTNode parent = nd.getParent();
|
||||||
IASTExpression defaultValue = param.getDefaultValue();
|
assert parent instanceof ICPPASTTemplatedTypeTemplateParameter;
|
||||||
if (defaultValue != null)
|
if (parent instanceof ICPPASTTemplatedTypeTemplateParameter) {
|
||||||
return CPPVisitor.createType(defaultValue);
|
ICPPASTTemplatedTypeTemplateParameter param = (ICPPASTTemplatedTypeTemplateParameter) parent;
|
||||||
|
IASTExpression value = param.getDefaultValue();
|
||||||
|
if (value != null)
|
||||||
|
return CPPVisitor.createType(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -46,14 +46,19 @@ public class CPPTemplateTypeParameter extends CPPTemplateParameter implements
|
||||||
}
|
}
|
||||||
|
|
||||||
public IType getDefault() {
|
public IType getDefault() {
|
||||||
IASTNode[] nds = getDeclarations();
|
IASTName[] nds = getDeclarations();
|
||||||
if (nds == null || nds.length == 0)
|
if (nds == null || nds.length == 0)
|
||||||
return null;
|
return null;
|
||||||
IASTName name = (IASTName) nds[0];
|
for (IASTName nd : nds) {
|
||||||
ICPPASTSimpleTypeTemplateParameter simple = (ICPPASTSimpleTypeTemplateParameter) name.getParent();
|
IASTNode parent = nd.getParent();
|
||||||
|
assert parent instanceof ICPPASTSimpleTypeTemplateParameter;
|
||||||
|
if (parent instanceof ICPPASTSimpleTypeTemplateParameter) {
|
||||||
|
ICPPASTSimpleTypeTemplateParameter simple = (ICPPASTSimpleTypeTemplateParameter) parent;
|
||||||
IASTTypeId typeId = simple.getDefaultType();
|
IASTTypeId typeId = simple.getDefaultType();
|
||||||
if (typeId != null)
|
if (typeId != null)
|
||||||
return CPPVisitor.createType(typeId);
|
return CPPVisitor.createType(typeId);
|
||||||
|
}
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue