1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Name resolution for user-defined function operator, bug 231277.

This commit is contained in:
Markus Schorn 2008-05-21 12:03:44 +00:00
parent d3afa14bd0
commit 3eb91c4fa0
4 changed files with 95 additions and 53 deletions

View file

@ -2386,6 +2386,19 @@ public class CPPSemantics {
data = new LookupData(astName); data = new LookupData(astName);
data.forceQualified = true; data.forceQualified = true;
data.functionParameters = IASTExpression.EMPTY_EXPRESSION_ARRAY; data.functionParameters = IASTExpression.EMPTY_EXPRESSION_ARRAY;
} else if (exp instanceof IASTFunctionCallExpression) {
astName.setName(OverloadableOperator.PAREN.toCharArray());
data = new LookupData(astName);
data.forceQualified = true;
final IASTExpression paramExpression = ((IASTFunctionCallExpression)exp).getParameterExpression();
if (paramExpression == null) {
data.functionParameters= IASTExpression.EMPTY_EXPRESSION_ARRAY;
}
else if (paramExpression instanceof IASTExpressionList) {
data.functionParameters= ((IASTExpressionList) paramExpression).getExpressions();
} else {
data.functionParameters = new IASTExpression[] {paramExpression};
}
} else { } else {
return null; return null;
} }

View file

@ -1864,6 +1864,13 @@ public class CPPVisitor {
if (ftype != null) if (ftype != null)
return ftype.getReturnType(); return ftype.getReturnType();
} }
t= getUltimateTypeUptoPointers(t);
if (t instanceof ICPPClassType) {
ICPPFunction op = CPPSemantics.findOperator(expression, (ICPPClassType) t);
if (op != null) {
return op.getType().getReturnType();
}
}
} catch(DOMException e) { } catch(DOMException e) {
return e.getProblem(); return e.getProblem();
} }

View file

@ -297,60 +297,73 @@ class LookupData {
* an IType[] of function arguments, including the implied object argument * an IType[] of function arguments, including the implied object argument
*/ */
public IType getImpliedObjectArgument() { public IType getImpliedObjectArgument() {
IType implied = null; if (astName == null)
return null;
if (astName != null) {
IASTName tempName = astName; IASTName tempName= astName;
while (tempName.getParent() instanceof IASTName) IASTNode tempNameParent= tempName.getParent();
tempName = (IASTName) tempName.getParent(); while (tempNameParent instanceof IASTName) {
tempName= (IASTName) tempNameParent;
ASTNodeProperty prop = tempName.getPropertyInParent(); tempNameParent= tempName.getParent();
if ((prop == CPPSemantics.STRING_LOOKUP_PROPERTY && tempName.getParent() instanceof ICPPASTUnaryExpression)) { }
ICPPASTUnaryExpression unaryExp = (ICPPASTUnaryExpression) tempName.getParent();
IASTExpression oprd= unaryExp.getOperand(); try {
return CPPVisitor.getExpressionType(oprd); final ASTNodeProperty prop = tempName.getPropertyInParent();
} else if (prop == IASTFieldReference.FIELD_NAME || if (prop == CPPSemantics.STRING_LOOKUP_PROPERTY) {
(prop == CPPSemantics.STRING_LOOKUP_PROPERTY && tempName.getParent() instanceof ICPPASTFieldReference)) { if (tempNameParent instanceof ICPPASTUnaryExpression) {
ICPPASTFieldReference fieldRef = (ICPPASTFieldReference) tempName.getParent(); ICPPASTUnaryExpression unaryExp = (ICPPASTUnaryExpression) tempNameParent;
implied = CPPVisitor.getExpressionType(fieldRef.getFieldOwner()); IASTExpression oprd= unaryExp.getOperand();
IType ultimateImplied= SemanticUtil.getUltimateTypeUptoPointers(implied); return CPPVisitor.getExpressionType(oprd);
if (prop != CPPSemantics.STRING_LOOKUP_PROPERTY && fieldRef.isPointerDereference() && }
ultimateImplied instanceof ICPPClassType) { if (tempNameParent instanceof ICPPASTFieldReference) {
ICPPFunction operator= CPPSemantics.findOperator(fieldRef, (ICPPClassType) ultimateImplied); ICPPASTFieldReference fieldRef = (ICPPASTFieldReference) tempNameParent;
try { IType implied = CPPVisitor.getExpressionType(fieldRef.getFieldOwner());
if (operator!=null) { if (fieldRef.isPointerDereference() && implied instanceof IPointerType) {
implied= operator.getType().getReturnType(); return ((IPointerType)implied).getType();
} }
} catch(DOMException de) { return implied;
return de.getProblem(); }
} if (tempNameParent instanceof IASTArraySubscriptExpression) {
} else if (fieldRef.isPointerDereference() && implied instanceof IPointerType) { IASTExpression exp = ((IASTArraySubscriptExpression)tempNameParent).getArrayExpression();
try { return CPPVisitor.getExpressionType(exp);
implied = ((IPointerType)implied).getType(); }
} catch (DOMException e) { if (tempNameParent instanceof IASTFunctionCallExpression) {
implied = e.getProblem(); return CPPVisitor.getExpressionType(((IASTFunctionCallExpression) tempNameParent).getFunctionNameExpression());
} }
} return null;
} else if (prop == IASTIdExpression.ID_NAME) { }
IScope scope = CPPVisitor.getContainingScope(tempName); if (prop == IASTFieldReference.FIELD_NAME) {
if (scope instanceof ICPPClassScope) { ICPPASTFieldReference fieldRef = (ICPPASTFieldReference) tempNameParent;
implied = ((ICPPClassScope)scope).getClassType(); IType implied = CPPVisitor.getExpressionType(fieldRef.getFieldOwner());
} else { IType ultimateImplied= SemanticUtil.getUltimateTypeUptoPointers(implied);
implied = CPPVisitor.getThisType(scope); if (fieldRef.isPointerDereference()) {
if (implied instanceof IPointerType) { if (ultimateImplied instanceof ICPPClassType) {
try { ICPPFunction operator= CPPSemantics.findOperator(fieldRef, (ICPPClassType) ultimateImplied);
implied = ((IPointerType)implied).getType(); if (operator!=null) {
} catch (DOMException e) { return operator.getType().getReturnType();
implied = e.getProblem(); }
} } else if (implied instanceof IPointerType) {
} return ((IPointerType)implied).getType();
} }
} else if (prop == CPPSemantics.STRING_LOOKUP_PROPERTY && tempName.getParent() instanceof IASTArraySubscriptExpression) { }
IASTExpression exp = ((IASTArraySubscriptExpression)tempName.getParent()).getArrayExpression(); return implied;
implied = CPPVisitor.getExpressionType(exp); }
} if (prop == IASTIdExpression.ID_NAME) {
IScope scope = CPPVisitor.getContainingScope(tempName);
if (scope instanceof ICPPClassScope) {
return ((ICPPClassScope)scope).getClassType();
}
IType implied = CPPVisitor.getThisType(scope);
if (implied instanceof IPointerType) {
return ((IPointerType)implied).getType();
}
return implied;
}
return null;
} catch (DOMException e) {
return e.getProblem();
} }
return implied;
} }
public boolean forFriendship() { public boolean forFriendship() {

View file

@ -103,6 +103,7 @@ public class CompletionTests extends AbstractContentAssistTest {
// C2* m123(); // C2* m123();
// C2* m12(); // C2* m12();
// C2* m23(); // C2* m23();
// C1* operator()(int x);
// //
//private: //private:
// void m2private(); // void m2private();
@ -1147,4 +1148,12 @@ public class CompletionTests extends AbstractContentAssistTest {
final String[] expected= {"enum0", "enum1", "enum2"}; final String[] expected= {"enum0", "enum1", "enum2"};
assertCompletionResults(expected); assertCompletionResults(expected);
} }
// void test() {
// C2 c2;
// c2(1)->iam/*cursor*/
public void testUserdefinedCallOperator_Bug231277() throws Exception {
final String[] expected= {"iam1()"};
assertCompletionResults(expected);
}
} }