mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-30 21:55:31 +02:00
Cleanup handling of implicit template arguments in class templates, partial- and explicit specializations.
This commit is contained in:
parent
973949d7e4
commit
6225f6b14f
5 changed files with 56 additions and 32 deletions
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
*/
|
||||
|
|
|
@ -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))) {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Add table
Reference in a new issue