Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarkus Schorn2011-09-15 14:44:08 +0000
committerMarkus Schorn2011-09-15 14:44:08 +0000
commit053b4c32c5291512e8d2f0ac7afcb0d94107b8d2 (patch)
treedae82b7976ab95dc42b8d9c4ab2d84910ad74287
parentca59d810e35c80d5d03322c9ce00fb00e21df333 (diff)
downloadorg.eclipse.cdt-053b4c32c5291512e8d2f0ac7afcb0d94107b8d2.tar.gz
org.eclipse.cdt-053b4c32c5291512e8d2f0ac7afcb0d94107b8d2.tar.xz
org.eclipse.cdt-053b4c32c5291512e8d2f0ac7afcb0d94107b8d2.zip
Bug 357308: Resolving references to parameters of template-template paramters.
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java7
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTTemplatedTypeTemplateParameter.java6
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTemplatedTypeTemplateParameter.java9
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateTemplateParameterScope.java35
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java9
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPTemplates.java15
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java10
7 files changed, 74 insertions, 17 deletions
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java
index 194e8879ab..e26814e4cb 100644
--- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java
@@ -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();
+ }
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTTemplatedTypeTemplateParameter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTTemplatedTypeTemplateParameter.java
index 099562a03d..dc285516c8 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTTemplatedTypeTemplateParameter.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTTemplatedTypeTemplateParameter.java
@@ -93,6 +93,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)};
*/
@Deprecated
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTemplatedTypeTemplateParameter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTemplatedTypeTemplateParameter.java
index d68d7a8cfe..dab0e9d2ee 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTemplatedTypeTemplateParameter.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTemplatedTypeTemplateParameter.java
@@ -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;
+ }
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateTemplateParameterScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateTemplateParameterScope.java
new file mode 100644
index 0000000000..cf1e2ad30c
--- /dev/null
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateTemplateParameterScope.java
@@ -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();
+ }
+}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java
index 9eb3b1bb79..c413f46c01 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java
@@ -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;
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPTemplates.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPTemplates.java
index 974deaa6e2..fe1e8b40d4 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPTemplates.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPTemplates.java
@@ -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
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java
index 323d31e342..c074fcfc1b 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java
@@ -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();

Back to the top