From 6225f6b14f74193f7ff54938fd40f432f35e8b2f Mon Sep 17 00:00:00 2001 From: Markus Schorn Date: Fri, 14 Nov 2008 13:58:30 +0000 Subject: [PATCH] Cleanup handling of implicit template arguments in class templates, partial- and explicit specializations. --- .../tests/IndexCPPBindingResolutionTest.java | 8 ---- .../core/dom/parser/IASTInternalScope.java | 6 +-- .../core/dom/parser/cpp/CPPClassScope.java | 16 +++---- .../parser/cpp/semantics/CPPSemantics.java | 44 ++++++++++++++----- .../core/pdom/dom/cpp/PDOMCPPClassScope.java | 14 +++++- 5 files changed, 56 insertions(+), 32 deletions(-) diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPBindingResolutionTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPBindingResolutionTest.java index 1fc40c4abef..c585763c198 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPBindingResolutionTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPBindingResolutionTest.java @@ -445,12 +445,6 @@ public abstract class IndexCPPBindingResolutionTest extends IndexBindingResoluti IBinding _b10 = getBindingFromASTName("topFunc(){", 7); } - public void _testMultiVirtualBaseClassLookup() {fail("aftodo");} - public void _testMultiNonVirtualBaseClassLookup() {fail("aftodo");} - - public void _testQualifiedNamesForNamespaceAliases() {fail("aftodo");} - public void _testQualifiedNamesForNamespaces() {fail("aftodo");} - // // header content // namespace n1 { namespace n2 { struct S {}; } } // class c1 { public: class c2 { public: struct S {}; }; }; @@ -998,8 +992,6 @@ public abstract class IndexCPPBindingResolutionTest extends IndexBindingResoluti IBinding b24 = getBindingFromASTName("f;/*24*/", 1); } - public void _testAddressOfOverloadedMethod() throws DOMException { fail("aftodo"); } - // struct C { // int m1(int a); // int m2(int a) const; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/IASTInternalScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/IASTInternalScope.java index b3236244845..a2a7d862da7 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/IASTInternalScope.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/IASTInternalScope.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006 Wind River Systems, Inc. and others. + * Copyright (c) 2006, 2008 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 @@ -8,19 +8,19 @@ * Contributors: * Markus Schorn - initial API and implementation *******************************************************************************/ - package org.eclipse.cdt.internal.core.dom.parser; import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IBinding; +import org.eclipse.cdt.core.dom.ast.IScope; /** * Interface for methods on scopes that are internal to the AST. * @since 4.0 */ -public interface IASTInternalScope { +public interface IASTInternalScope extends IScope { /** * Return the physical IASTNode that this scope was created for */ diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassScope.java index ffb1588ffab..fe7bbeb11d5 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassScope.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassScope.java @@ -220,10 +220,10 @@ public class CPPClassScope extends CPPScope implements ICPPClassScope { char[] c = name.toCharArray(); ICPPASTCompositeTypeSpecifier compType = (ICPPASTCompositeTypeSpecifier) getPhysicalNode(); - IASTName compName = compType.getName(); - if (compName instanceof ICPPASTQualifiedName) { - compName = ((ICPPASTQualifiedName) compName).getLastName(); - } + IASTName compName = compType.getName().getLastName(); + if (compName instanceof ICPPASTTemplateId) { + compName= ((ICPPASTTemplateId) compName).getTemplateName(); + } if (CharArrayUtils.equals(c, compName.toCharArray())) { if (isConstructorReference(name)) { return CPPSemantics.resolveAmbiguities(name, getConstructors(bindings, resolve, name)); @@ -239,10 +239,10 @@ public class CPPClassScope extends CPPScope implements ICPPClassScope { char[] c = name.toCharArray(); ICPPASTCompositeTypeSpecifier compType = (ICPPASTCompositeTypeSpecifier) getPhysicalNode(); - IASTName compName = compType.getName(); - if (compName instanceof ICPPASTQualifiedName) { - compName = ((ICPPASTQualifiedName) compName).getLastName(); - } + IASTName compName = compType.getName().getLastName(); + if (compName instanceof ICPPASTTemplateId) { + compName= ((ICPPASTTemplateId) compName).getTemplateName(); + } IBinding[] result = null; if ((!prefixLookup && CharArrayUtils.equals(c, compName.toCharArray())) || (prefixLookup && CharArrayUtils.equals(compName.toCharArray(), 0, c.length, c, true))) { 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 9f338f8db29..9bc3d4d63a7 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 @@ -23,6 +23,7 @@ import java.util.HashSet; import java.util.List; import java.util.Set; +import org.eclipse.cdt.core.dom.IName; import org.eclipse.cdt.core.dom.ast.ASTNodeProperty; import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.IASTArraySubscriptExpression; @@ -94,6 +95,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTWhileStatement; import org.eclipse.cdt.core.dom.ast.cpp.ICPPBase; import org.eclipse.cdt.core.dom.ast.cpp.ICPPBlockScope; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassScope; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassSpecialization; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassTemplate; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassTemplatePartialSpecialization; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType; @@ -254,23 +256,38 @@ public class CPPSemantics { /* 14.6.1-1: Class template name without argument list is equivalent to the injected-class-name followed by * the template-parameters of the class template enclosed in <> */ if (binding instanceof ICPPClassTemplate) { + ICPPClassTemplate ct= (ICPPClassTemplate) binding; ASTNodeProperty prop = data.astName.getPropertyInParent(); if (prop != ICPPASTQualifiedName.SEGMENT_NAME && prop != ICPPASTTemplateId.TEMPLATE_NAME && binding instanceof ICPPInternalBinding) { try { - IASTNode def = ((ICPPInternalBinding)binding).getDefinition(); - if (def != null) { - def = def.getParent(); - IASTNode parent = data.astName.getParent(); - while (parent != null) { - if (parent == def) { - binding = CPPTemplates.instantiateWithinClassTemplate((ICPPClassTemplate) binding); - break; + IScope scope= CPPVisitor.getContainingScope(data.astName); + while (scope instanceof IASTInternalScope) { + final IASTInternalScope internalScope = (IASTInternalScope) scope; + if (scope instanceof ICPPClassScope) { + final IName scopeName = internalScope.getScopeName(); + if (scopeName instanceof IASTName) { + IBinding b= ((IASTName) scopeName).resolveBinding(); + if (binding == b) { + binding= CPPTemplates.instantiateWithinClassTemplate((ICPPClassTemplate) binding); + break; + } + if (b instanceof ICPPClassTemplatePartialSpecialization) { + ICPPClassTemplatePartialSpecialization pspec= (ICPPClassTemplatePartialSpecialization) b; + if (ct.isSameType(pspec.getPrimaryClassTemplate())) { + binding= CPPTemplates.instantiateWithinClassTemplate(pspec); + break; + } + } else if (b instanceof ICPPClassSpecialization) { + ICPPClassSpecialization specialization= (ICPPClassSpecialization) b; + if (ct.isSameType(specialization.getSpecializedBinding())) { + binding= specialization; + break; + } + } } - if (parent instanceof ICPPASTNamespaceDefinition) - break; - parent = parent.getParent(); } + scope= CPPVisitor.getContainingScope(internalScope.getPhysicalNode()); } } catch (DOMException e) { } @@ -1110,7 +1127,10 @@ public class CPPSemantics { nodes = comp.getMembers(); //9-2 a class name is also inserted into the scope of the class itself - IASTName n = comp.getName(); + IASTName n = comp.getName().getLastName(); + if (n instanceof ICPPASTTemplateId) { + n= ((ICPPASTTemplateId) n).getTemplateName(); + } if (nameMatches(data, n, scope)) { found = (IASTName[]) ArrayUtil.append(IASTName.class, found, n); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassScope.java index 5647b49803c..f6cb43da564 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassScope.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassScope.java @@ -28,8 +28,10 @@ import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.ICompositeType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassScope; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassTemplatePartialSpecialization; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization; import org.eclipse.cdt.core.index.IIndexBinding; import org.eclipse.cdt.core.index.IIndexFileSet; import org.eclipse.cdt.core.index.IIndexName; @@ -79,6 +81,10 @@ class PDOMCPPClassScope implements ICPPClassScope, IIndexScope { return CPPSemantics.resolveAmbiguities(name, fBinding.getConstructors()); } //9.2 ... The class-name is also inserted into the scope of the class itself + if (fBinding instanceof ICPPClassTemplatePartialSpecialization) + return ((ICPPClassTemplatePartialSpecialization) fBinding).getPrimaryClassTemplate(); + if (fBinding instanceof ICPPSpecialization) + return ((ICPPSpecialization) fBinding).getSpecializedBinding(); return fBinding; } @@ -101,7 +107,13 @@ class PDOMCPPClassScope implements ICPPClassScope, IIndexScope { if (CharArrayUtils.equals(fBinding.getNameCharArray(), 0, nameChars.length, nameChars, true)) { // 9.2 ... The class-name is also inserted into the scope of // the class itself - visitor.visit(fBinding); + IPDOMNode node= fBinding; + if (node instanceof ICPPClassTemplatePartialSpecialization) + node= (IPDOMNode) ((ICPPClassTemplatePartialSpecialization) fBinding).getPrimaryClassTemplate(); + else if (fBinding instanceof ICPPSpecialization) + node= (IPDOMNode) ((ICPPSpecialization) fBinding).getSpecializedBinding(); + + visitor.visit(node); } acceptViaCache(fBinding, visitor, true); result= visitor.getBindings();