mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-20 15:35:24 +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);
|
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
|
// // header content
|
||||||
// namespace n1 { namespace n2 { struct S {}; } }
|
// namespace n1 { namespace n2 { struct S {}; } }
|
||||||
// class c1 { public: class c2 { public: 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);
|
IBinding b24 = getBindingFromASTName("f;/*24*/", 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void _testAddressOfOverloadedMethod() throws DOMException { fail("aftodo"); }
|
|
||||||
|
|
||||||
// struct C {
|
// struct C {
|
||||||
// int m1(int a);
|
// int m1(int a);
|
||||||
// int m2(int a) const;
|
// 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
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
|
@ -8,19 +8,19 @@
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Markus Schorn - initial API and implementation
|
* Markus Schorn - initial API and implementation
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
|
||||||
package org.eclipse.cdt.internal.core.dom.parser;
|
package org.eclipse.cdt.internal.core.dom.parser;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||||
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.IASTNode;
|
||||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
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.
|
* Interface for methods on scopes that are internal to the AST.
|
||||||
* @since 4.0
|
* @since 4.0
|
||||||
*/
|
*/
|
||||||
public interface IASTInternalScope {
|
public interface IASTInternalScope extends IScope {
|
||||||
/**
|
/**
|
||||||
* Return the physical IASTNode that this scope was created for
|
* Return the physical IASTNode that this scope was created for
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -220,9 +220,9 @@ public class CPPClassScope extends CPPScope implements ICPPClassScope {
|
||||||
char[] c = name.toCharArray();
|
char[] c = name.toCharArray();
|
||||||
|
|
||||||
ICPPASTCompositeTypeSpecifier compType = (ICPPASTCompositeTypeSpecifier) getPhysicalNode();
|
ICPPASTCompositeTypeSpecifier compType = (ICPPASTCompositeTypeSpecifier) getPhysicalNode();
|
||||||
IASTName compName = compType.getName();
|
IASTName compName = compType.getName().getLastName();
|
||||||
if (compName instanceof ICPPASTQualifiedName) {
|
if (compName instanceof ICPPASTTemplateId) {
|
||||||
compName = ((ICPPASTQualifiedName) compName).getLastName();
|
compName= ((ICPPASTTemplateId) compName).getTemplateName();
|
||||||
}
|
}
|
||||||
if (CharArrayUtils.equals(c, compName.toCharArray())) {
|
if (CharArrayUtils.equals(c, compName.toCharArray())) {
|
||||||
if (isConstructorReference(name)) {
|
if (isConstructorReference(name)) {
|
||||||
|
@ -239,9 +239,9 @@ public class CPPClassScope extends CPPScope implements ICPPClassScope {
|
||||||
char[] c = name.toCharArray();
|
char[] c = name.toCharArray();
|
||||||
|
|
||||||
ICPPASTCompositeTypeSpecifier compType = (ICPPASTCompositeTypeSpecifier) getPhysicalNode();
|
ICPPASTCompositeTypeSpecifier compType = (ICPPASTCompositeTypeSpecifier) getPhysicalNode();
|
||||||
IASTName compName = compType.getName();
|
IASTName compName = compType.getName().getLastName();
|
||||||
if (compName instanceof ICPPASTQualifiedName) {
|
if (compName instanceof ICPPASTTemplateId) {
|
||||||
compName = ((ICPPASTQualifiedName) compName).getLastName();
|
compName= ((ICPPASTTemplateId) compName).getTemplateName();
|
||||||
}
|
}
|
||||||
IBinding[] result = null;
|
IBinding[] result = null;
|
||||||
if ((!prefixLookup && CharArrayUtils.equals(c, compName.toCharArray()))
|
if ((!prefixLookup && CharArrayUtils.equals(c, compName.toCharArray()))
|
||||||
|
|
|
@ -23,6 +23,7 @@ import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
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.ASTNodeProperty;
|
||||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTArraySubscriptExpression;
|
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.ICPPBase;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBlockScope;
|
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.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.ICPPClassTemplate;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassTemplatePartialSpecialization;
|
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.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
|
/* 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 <> */
|
* the template-parameters of the class template enclosed in <> */
|
||||||
if (binding instanceof ICPPClassTemplate) {
|
if (binding instanceof ICPPClassTemplate) {
|
||||||
|
ICPPClassTemplate ct= (ICPPClassTemplate) binding;
|
||||||
ASTNodeProperty prop = data.astName.getPropertyInParent();
|
ASTNodeProperty prop = data.astName.getPropertyInParent();
|
||||||
if (prop != ICPPASTQualifiedName.SEGMENT_NAME && prop != ICPPASTTemplateId.TEMPLATE_NAME &&
|
if (prop != ICPPASTQualifiedName.SEGMENT_NAME && prop != ICPPASTTemplateId.TEMPLATE_NAME &&
|
||||||
binding instanceof ICPPInternalBinding) {
|
binding instanceof ICPPInternalBinding) {
|
||||||
try {
|
try {
|
||||||
IASTNode def = ((ICPPInternalBinding)binding).getDefinition();
|
IScope scope= CPPVisitor.getContainingScope(data.astName);
|
||||||
if (def != null) {
|
while (scope instanceof IASTInternalScope) {
|
||||||
def = def.getParent();
|
final IASTInternalScope internalScope = (IASTInternalScope) scope;
|
||||||
IASTNode parent = data.astName.getParent();
|
if (scope instanceof ICPPClassScope) {
|
||||||
while (parent != null) {
|
final IName scopeName = internalScope.getScopeName();
|
||||||
if (parent == def) {
|
if (scopeName instanceof IASTName) {
|
||||||
|
IBinding b= ((IASTName) scopeName).resolveBinding();
|
||||||
|
if (binding == b) {
|
||||||
binding= CPPTemplates.instantiateWithinClassTemplate((ICPPClassTemplate) binding);
|
binding= CPPTemplates.instantiateWithinClassTemplate((ICPPClassTemplate) binding);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (parent instanceof ICPPASTNamespaceDefinition)
|
if (b instanceof ICPPClassTemplatePartialSpecialization) {
|
||||||
|
ICPPClassTemplatePartialSpecialization pspec= (ICPPClassTemplatePartialSpecialization) b;
|
||||||
|
if (ct.isSameType(pspec.getPrimaryClassTemplate())) {
|
||||||
|
binding= CPPTemplates.instantiateWithinClassTemplate(pspec);
|
||||||
break;
|
break;
|
||||||
parent = parent.getParent();
|
|
||||||
}
|
}
|
||||||
|
} else if (b instanceof ICPPClassSpecialization) {
|
||||||
|
ICPPClassSpecialization specialization= (ICPPClassSpecialization) b;
|
||||||
|
if (ct.isSameType(specialization.getSpecializedBinding())) {
|
||||||
|
binding= specialization;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
scope= CPPVisitor.getContainingScope(internalScope.getPhysicalNode());
|
||||||
}
|
}
|
||||||
} catch (DOMException e) {
|
} catch (DOMException e) {
|
||||||
}
|
}
|
||||||
|
@ -1110,7 +1127,10 @@ public class CPPSemantics {
|
||||||
nodes = comp.getMembers();
|
nodes = comp.getMembers();
|
||||||
|
|
||||||
//9-2 a class name is also inserted into the scope of the class itself
|
//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)) {
|
if (nameMatches(data, n, scope)) {
|
||||||
found = (IASTName[]) ArrayUtil.append(IASTName.class, found, n);
|
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.IBinding;
|
||||||
import org.eclipse.cdt.core.dom.ast.ICompositeType;
|
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.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.ICPPClassType;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
|
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.IIndexBinding;
|
||||||
import org.eclipse.cdt.core.index.IIndexFileSet;
|
import org.eclipse.cdt.core.index.IIndexFileSet;
|
||||||
import org.eclipse.cdt.core.index.IIndexName;
|
import org.eclipse.cdt.core.index.IIndexName;
|
||||||
|
@ -79,6 +81,10 @@ class PDOMCPPClassScope implements ICPPClassScope, IIndexScope {
|
||||||
return CPPSemantics.resolveAmbiguities(name, fBinding.getConstructors());
|
return CPPSemantics.resolveAmbiguities(name, fBinding.getConstructors());
|
||||||
}
|
}
|
||||||
//9.2 ... The class-name is also inserted into the scope of the class itself
|
//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;
|
return fBinding;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -101,7 +107,13 @@ class PDOMCPPClassScope implements ICPPClassScope, IIndexScope {
|
||||||
if (CharArrayUtils.equals(fBinding.getNameCharArray(), 0, nameChars.length, nameChars, true)) {
|
if (CharArrayUtils.equals(fBinding.getNameCharArray(), 0, nameChars.length, nameChars, true)) {
|
||||||
// 9.2 ... The class-name is also inserted into the scope of
|
// 9.2 ... The class-name is also inserted into the scope of
|
||||||
// the class itself
|
// 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);
|
acceptViaCache(fBinding, visitor, true);
|
||||||
result= visitor.getBindings();
|
result= visitor.getBindings();
|
||||||
|
|
Loading…
Add table
Reference in a new issue