1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-24 09:25:31 +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();
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.ObjectSet;
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.cpp.CPPClassType.CPPClassTypeProblem;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPSemantics;
@ -102,7 +103,7 @@ public class ClassTypeHelper {
} else {
for (IASTDeclarator dtor : dtors) {
if (dtor == null) break;
dtor= CPPVisitor.findInnermostDeclarator(dtor);
dtor= ASTQueries.findInnermostDeclarator(dtor);
resultSet.put(dtor.getName().resolveBinding());
}
}
@ -111,7 +112,7 @@ public class ClassTypeHelper {
ICPPASTDeclSpecifier declSpec = (ICPPASTDeclSpecifier) ((IASTFunctionDefinition)decl).getDeclSpecifier();
if (declSpec.isFriend()) {
IASTDeclarator dtor = ((IASTFunctionDefinition)decl).getDeclarator();
dtor= CPPVisitor.findInnermostDeclarator(dtor);
dtor= ASTQueries.findInnermostDeclarator(dtor);
resultSet.put(dtor.getName().resolveBinding());
}
}
@ -184,7 +185,7 @@ public class ClassTypeHelper {
if (decl instanceof IASTSimpleDeclaration) {
IASTDeclarator[] dtors = ((IASTSimpleDeclaration)decl).getDeclarators();
for (IASTDeclarator dtor : dtors) {
binding = CPPVisitor.findInnermostDeclarator(dtor).getName().resolveBinding();
binding = ASTQueries.findInnermostDeclarator(dtor).getName().resolveBinding();
if (binding instanceof ICPPField)
result = (ICPPField[]) ArrayUtil.append(ICPPField.class, result, binding);
}
@ -256,6 +257,10 @@ public class ClassTypeHelper {
if (host.getDefinition() == null) {
host.checkForDefinition();
if (host.getDefinition() == null) {
ICPPClassType backup= getBackupDefinition(host);
if (backup != null)
return backup.getDeclaredMethods();
IASTNode[] declarations= host.getDeclarations();
IASTNode node = (declarations != null && declarations.length > 0) ? declarations[0] : null;
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) {
IASTDeclarator[] dtors = ((IASTSimpleDeclaration)decl).getDeclarators();
for (IASTDeclarator dtor : dtors) {
binding = CPPVisitor.findInnermostDeclarator(dtor).getName().resolveBinding();
binding = ASTQueries.findInnermostDeclarator(dtor).getName().resolveBinding();
if (binding instanceof ICPPMethod)
result = (ICPPMethod[]) ArrayUtil.append(ICPPMethod.class, result, binding);
}
} else if (decl instanceof IASTFunctionDefinition) {
IASTDeclarator dtor = ((IASTFunctionDefinition)decl).getDeclarator();
dtor = CPPVisitor.findInnermostDeclarator(dtor);
dtor = ASTQueries.findInnermostDeclarator(dtor);
binding = dtor.getName().resolveBinding();
if (binding instanceof ICPPMethod) {
result = (ICPPMethod[]) ArrayUtil.append(ICPPMethod.class, result, binding);

View file

@ -844,6 +844,16 @@ public class CPPSemantics {
} 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)
return PROCESS_SKIP;
return PROCESS_CONTINUE;
@ -2234,17 +2244,23 @@ public class CPPSemantics {
if (t == null) {
return new ProblemBinding(astName, IProblemBinding.SEMANTIC_INVALID_TYPE);
}
IFunction unknown= null;
for (IFunction function : fns) {
if (function != null) {
try {
IType t2= function.getType().getReturnType();
if (t.isSameType(t2))
return function;
if (unknown == null && function instanceof ICPPUnknownBinding) {
unknown= function;
}
} catch (DOMException e) {
// ignore, try other candidates
}
}
}
if (unknown != null)
return unknown;
return new ProblemBinding(astName, IProblemBinding.SEMANTIC_NAME_NOT_FOUND);
}