1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-08 08:45:44 +02:00

Resolution of deferred conversion operator.

This commit is contained in:
Markus Schorn 2009-03-03 13:00:58 +00:00
parent 6c715831a4
commit d02a227446
3 changed files with 38 additions and 5 deletions

View file

@ -3942,4 +3942,16 @@ public class AST2TemplateTests extends AST2BaseTest {
final String code = getAboveComment(); final String code = getAboveComment();
parseAndCheckBindings(code, ParserLanguage.CPP); parseAndCheckBindings(code, ParserLanguage.CPP);
} }
// template<typename T> class XT {
// operator T() {return 0;}
// void m() {
// XT<T*> xt;
// xt.operator T*()->something();
// }
// };
public void testDeferredConversionOperator() throws Exception {
final String code = getAboveComment();
parseAndCheckBindings(code, ParserLanguage.CPP);
}
} }

View file

@ -59,6 +59,7 @@ import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.core.parser.util.CharArrayUtils; import org.eclipse.cdt.core.parser.util.CharArrayUtils;
import org.eclipse.cdt.core.parser.util.ObjectSet; import org.eclipse.cdt.core.parser.util.ObjectSet;
import org.eclipse.cdt.internal.core.dom.parser.ASTInternal; import org.eclipse.cdt.internal.core.dom.parser.ASTInternal;
import org.eclipse.cdt.internal.core.dom.parser.ASTQueries;
import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding; import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPClassType.CPPClassTypeProblem; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPClassType.CPPClassTypeProblem;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPSemantics; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPSemantics;
@ -102,7 +103,7 @@ public class ClassTypeHelper {
} else { } else {
for (IASTDeclarator dtor : dtors) { for (IASTDeclarator dtor : dtors) {
if (dtor == null) break; if (dtor == null) break;
dtor= CPPVisitor.findInnermostDeclarator(dtor); dtor= ASTQueries.findInnermostDeclarator(dtor);
resultSet.put(dtor.getName().resolveBinding()); resultSet.put(dtor.getName().resolveBinding());
} }
} }
@ -111,7 +112,7 @@ public class ClassTypeHelper {
ICPPASTDeclSpecifier declSpec = (ICPPASTDeclSpecifier) ((IASTFunctionDefinition)decl).getDeclSpecifier(); ICPPASTDeclSpecifier declSpec = (ICPPASTDeclSpecifier) ((IASTFunctionDefinition)decl).getDeclSpecifier();
if (declSpec.isFriend()) { if (declSpec.isFriend()) {
IASTDeclarator dtor = ((IASTFunctionDefinition)decl).getDeclarator(); IASTDeclarator dtor = ((IASTFunctionDefinition)decl).getDeclarator();
dtor= CPPVisitor.findInnermostDeclarator(dtor); dtor= ASTQueries.findInnermostDeclarator(dtor);
resultSet.put(dtor.getName().resolveBinding()); resultSet.put(dtor.getName().resolveBinding());
} }
} }
@ -184,7 +185,7 @@ public class ClassTypeHelper {
if (decl instanceof IASTSimpleDeclaration) { if (decl instanceof IASTSimpleDeclaration) {
IASTDeclarator[] dtors = ((IASTSimpleDeclaration)decl).getDeclarators(); IASTDeclarator[] dtors = ((IASTSimpleDeclaration)decl).getDeclarators();
for (IASTDeclarator dtor : dtors) { for (IASTDeclarator dtor : dtors) {
binding = CPPVisitor.findInnermostDeclarator(dtor).getName().resolveBinding(); binding = ASTQueries.findInnermostDeclarator(dtor).getName().resolveBinding();
if (binding instanceof ICPPField) if (binding instanceof ICPPField)
result = (ICPPField[]) ArrayUtil.append(ICPPField.class, result, binding); result = (ICPPField[]) ArrayUtil.append(ICPPField.class, result, binding);
} }
@ -256,6 +257,10 @@ public class ClassTypeHelper {
if (host.getDefinition() == null) { if (host.getDefinition() == null) {
host.checkForDefinition(); host.checkForDefinition();
if (host.getDefinition() == null) { if (host.getDefinition() == null) {
ICPPClassType backup= getBackupDefinition(host);
if (backup != null)
return backup.getDeclaredMethods();
IASTNode[] declarations= host.getDeclarations(); IASTNode[] declarations= host.getDeclarations();
IASTNode node = (declarations != null && declarations.length > 0) ? declarations[0] : null; IASTNode node = (declarations != null && declarations.length > 0) ? declarations[0] : null;
return new ICPPMethod[] { new CPPMethod.CPPMethodProblem(node, IProblemBinding.SEMANTIC_DEFINITION_NOT_FOUND, host.getNameCharArray()) }; return new ICPPMethod[] { new CPPMethod.CPPMethodProblem(node, IProblemBinding.SEMANTIC_DEFINITION_NOT_FOUND, host.getNameCharArray()) };
@ -271,13 +276,13 @@ public class ClassTypeHelper {
if (decl instanceof IASTSimpleDeclaration) { if (decl instanceof IASTSimpleDeclaration) {
IASTDeclarator[] dtors = ((IASTSimpleDeclaration)decl).getDeclarators(); IASTDeclarator[] dtors = ((IASTSimpleDeclaration)decl).getDeclarators();
for (IASTDeclarator dtor : dtors) { for (IASTDeclarator dtor : dtors) {
binding = CPPVisitor.findInnermostDeclarator(dtor).getName().resolveBinding(); binding = ASTQueries.findInnermostDeclarator(dtor).getName().resolveBinding();
if (binding instanceof ICPPMethod) if (binding instanceof ICPPMethod)
result = (ICPPMethod[]) ArrayUtil.append(ICPPMethod.class, result, binding); result = (ICPPMethod[]) ArrayUtil.append(ICPPMethod.class, result, binding);
} }
} else if (decl instanceof IASTFunctionDefinition) { } else if (decl instanceof IASTFunctionDefinition) {
IASTDeclarator dtor = ((IASTFunctionDefinition)decl).getDeclarator(); IASTDeclarator dtor = ((IASTFunctionDefinition)decl).getDeclarator();
dtor = CPPVisitor.findInnermostDeclarator(dtor); dtor = ASTQueries.findInnermostDeclarator(dtor);
binding = dtor.getName().resolveBinding(); binding = dtor.getName().resolveBinding();
if (binding instanceof ICPPMethod) { if (binding instanceof ICPPMethod) {
result = (ICPPMethod[]) ArrayUtil.append(ICPPMethod.class, result, binding); result = (ICPPMethod[]) ArrayUtil.append(ICPPMethod.class, result, binding);

View file

@ -844,6 +844,16 @@ public class CPPSemantics {
} catch (DOMException e) { } catch (DOMException e) {
} }
} }
if (b instanceof IVariable) {
try {
IType t= SemanticUtil.getUltimateType(((IVariable) b).getType(), true);
if (t instanceof ICPPUnknownBinding || t instanceof ICPPTemplateDefinition) {
result[0]= true;
return PROCESS_ABORT;
}
} catch (DOMException e) {
}
}
if (name instanceof ICPPASTTemplateId) if (name instanceof ICPPASTTemplateId)
return PROCESS_SKIP; return PROCESS_SKIP;
return PROCESS_CONTINUE; return PROCESS_CONTINUE;
@ -2234,17 +2244,23 @@ public class CPPSemantics {
if (t == null) { if (t == null) {
return new ProblemBinding(astName, IProblemBinding.SEMANTIC_INVALID_TYPE); return new ProblemBinding(astName, IProblemBinding.SEMANTIC_INVALID_TYPE);
} }
IFunction unknown= null;
for (IFunction function : fns) { for (IFunction function : fns) {
if (function != null) { if (function != null) {
try { try {
IType t2= function.getType().getReturnType(); IType t2= function.getType().getReturnType();
if (t.isSameType(t2)) if (t.isSameType(t2))
return function; return function;
if (unknown == null && function instanceof ICPPUnknownBinding) {
unknown= function;
}
} catch (DOMException e) { } catch (DOMException e) {
// ignore, try other candidates // ignore, try other candidates
} }
} }
} }
if (unknown != null)
return unknown;
return new ProblemBinding(astName, IProblemBinding.SEMANTIC_NAME_NOT_FOUND); return new ProblemBinding(astName, IProblemBinding.SEMANTIC_NAME_NOT_FOUND);
} }