mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-29 20:05:35 +02:00
Bug 357308: Resolving references to parameters of template-template paramters.
This commit is contained in:
parent
ca59d810e3
commit
053b4c32c5
7 changed files with 74 additions and 17 deletions
|
@ -5506,4 +5506,11 @@ public class AST2TemplateTests extends AST2BaseTest {
|
|||
public void testSpecializationOfUsingDeclaration_357293() throws Exception {
|
||||
parseAndCheckBindings();
|
||||
}
|
||||
|
||||
// template<typename T> struct SS {};
|
||||
// template<template<typename T, typename S = SS<T> > class Cont>
|
||||
// Cont<int> f() {}
|
||||
public void testReferenceToParameterOfTemplateTemplateParameter_357308() throws Exception {
|
||||
parseAndCheckBindings();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -92,6 +92,12 @@ public interface ICPPASTTemplatedTypeTemplateParameter extends ICPPASTTemplatePa
|
|||
*/
|
||||
public void setDefaultValue(IASTExpression expression);
|
||||
|
||||
/**
|
||||
* Returns the scope that contains the template parameters of this template-template parameter.
|
||||
* @since 5.4
|
||||
*/
|
||||
public ICPPScope asScope();
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #addTemplateParameter(ICPPASTTemplateParameter)};
|
||||
*/
|
||||
|
|
|
@ -17,6 +17,7 @@ import org.eclipse.cdt.core.dom.ast.IASTName;
|
|||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateParameter;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplatedTypeTemplateParameter;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope;
|
||||
import org.eclipse.cdt.core.parser.util.ArrayUtil;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent;
|
||||
|
@ -31,6 +32,7 @@ public class CPPASTTemplatedTypeTemplateParameter extends ASTNode implements
|
|||
private boolean fIsParameterPack;
|
||||
private IASTName fName;
|
||||
private IASTExpression fDefaultValue;
|
||||
private CPPTemplateTemplateParameterScope fScope;
|
||||
|
||||
public CPPASTTemplatedTypeTemplateParameter() {
|
||||
}
|
||||
|
@ -156,4 +158,11 @@ public class CPPASTTemplatedTypeTemplateParameter extends ASTNode implements
|
|||
fDefaultValue = (IASTExpression) other;
|
||||
}
|
||||
}
|
||||
|
||||
public ICPPScope asScope() {
|
||||
if (fScope == null) {
|
||||
fScope= new CPPTemplateTemplateParameterScope(this);
|
||||
}
|
||||
return fScope;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2011 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
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Markus Schorn - initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
||||
|
||||
import org.eclipse.cdt.core.dom.IName;
|
||||
import org.eclipse.cdt.core.dom.ast.EScopeKind;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplatedTypeTemplateParameter;
|
||||
|
||||
/**
|
||||
* Represents the scope of a template-template parameter.
|
||||
*/
|
||||
public class CPPTemplateTemplateParameterScope extends CPPScope {
|
||||
|
||||
public CPPTemplateTemplateParameterScope(ICPPASTTemplatedTypeTemplateParameter parameter) {
|
||||
super(parameter);
|
||||
}
|
||||
|
||||
public EScopeKind getKind() {
|
||||
return EScopeKind.eLocal;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IName getScopeName() {
|
||||
return ((ICPPASTTemplatedTypeTemplateParameter) getPhysicalNode()).getName();
|
||||
}
|
||||
}
|
|
@ -1426,6 +1426,15 @@ public class CPPSemantics {
|
|||
ASTInternal.addName(scope, enumerator.getName());
|
||||
}
|
||||
return;
|
||||
} else if (parent instanceof ICPPASTTemplatedTypeTemplateParameter) {
|
||||
// The template-template parameter scope contains the parameters
|
||||
for (ICPPASTTemplateParameter par : ((ICPPASTTemplatedTypeTemplateParameter) parent).getTemplateParameters()) {
|
||||
IASTName name= CPPTemplates.getTemplateParameterName(par);
|
||||
if (name != null) {
|
||||
ASTInternal.addName(scope, name);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
int idx = -1;
|
||||
|
|
|
@ -79,7 +79,6 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionType;
|
|||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPParameterPackType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPPointerToMemberType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateArgument;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateDefinition;
|
||||
|
@ -599,20 +598,6 @@ public class CPPTemplates {
|
|||
return new CPPTemplateNonTypeParameter(ASTQueries.findInnermostDeclarator(dtor).getName());
|
||||
}
|
||||
|
||||
static public ICPPScope getContainingScope(IASTNode node) {
|
||||
while (node != null) {
|
||||
if (node instanceof ICPPASTTemplateParameter) {
|
||||
IASTNode parent = node.getParent();
|
||||
if (parent instanceof ICPPASTTemplateDeclaration) {
|
||||
return ((ICPPASTTemplateDeclaration) parent).getScope();
|
||||
}
|
||||
}
|
||||
node = node.getParent();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static IBinding createBinding(ICPPASTTemplateId id) {
|
||||
if (!isClassTemplate(id)) {
|
||||
//functions are instantiated as part of the resolution process
|
||||
|
|
|
@ -908,7 +908,7 @@ public class CPPVisitor extends ASTQueries {
|
|||
if (result != null)
|
||||
return result;
|
||||
} else if (parent instanceof ICPPASTTemplateDeclaration) {
|
||||
return CPPTemplates.getContainingScope(node);
|
||||
return ((ICPPASTTemplateDeclaration) parent).getScope();
|
||||
}
|
||||
} else if (node instanceof IASTInitializer) {
|
||||
if (node instanceof ICPPASTConstructorChainInitializer) {
|
||||
|
@ -979,7 +979,13 @@ public class CPPVisitor extends ASTQueries {
|
|||
continue;
|
||||
}
|
||||
} else if (node instanceof ICPPASTTemplateParameter) {
|
||||
return CPPTemplates.getContainingScope(node);
|
||||
if (node instanceof ICPPASTTemplatedTypeTemplateParameter && node != inputNode) {
|
||||
return ((ICPPASTTemplatedTypeTemplateParameter) node).asScope();
|
||||
}
|
||||
IASTNode parent = node.getParent();
|
||||
if (parent instanceof ICPPASTTemplateDeclaration) {
|
||||
return ((ICPPASTTemplateDeclaration) parent).getScope();
|
||||
}
|
||||
} else if (node instanceof ICPPASTBaseSpecifier) {
|
||||
ICPPASTCompositeTypeSpecifier compSpec = (ICPPASTCompositeTypeSpecifier) node.getParent();
|
||||
IASTName n = compSpec.getName();
|
||||
|
|
Loading…
Add table
Reference in a new issue