mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-24 09:25:31 +02:00
Bug 417147 - Organize Includes ignores an overloaded operator.
This commit is contained in:
parent
79cd2757f5
commit
5c358c649c
2 changed files with 42 additions and 4 deletions
|
@ -373,6 +373,21 @@ public class BindingClassifierTest extends OneSourceMultipleHeadersTestCase {
|
|||
assertDeclared();
|
||||
}
|
||||
|
||||
// struct A {
|
||||
// int x;
|
||||
// };
|
||||
// inline bool operator==(const A& a1, const A& a2) {
|
||||
// return a1.x == a2.x;
|
||||
// }
|
||||
|
||||
// bool test(const A& a, const A& b) {
|
||||
// return a == b;
|
||||
// }
|
||||
public void testOverloadedOperator() throws Exception {
|
||||
assertDefined("operator ==");
|
||||
assertDeclared("A");
|
||||
}
|
||||
|
||||
// struct A {};
|
||||
// template<typename T> struct B {};
|
||||
// template<typename T, typename U = B<T>> struct C {};
|
||||
|
|
|
@ -78,6 +78,7 @@ import org.eclipse.cdt.core.dom.ast.IProblemBinding;
|
|||
import org.eclipse.cdt.core.dom.ast.IType;
|
||||
import org.eclipse.cdt.core.dom.ast.ITypedef;
|
||||
import org.eclipse.cdt.core.dom.ast.IVariable;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTBinaryExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCatchHandler;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier;
|
||||
|
@ -90,10 +91,12 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNewExpression;
|
|||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateId;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTypeId;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTUnaryExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassScope;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPEnumeration;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMember;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace;
|
||||
|
@ -524,7 +527,12 @@ public class BindingClassifier {
|
|||
return true;
|
||||
}
|
||||
|
||||
private void declareFunction(IFunction function, IASTFunctionCallExpression functionCallExpression) {
|
||||
private void defineFunction(IFunction function, IASTInitializerClause[] arguments) {
|
||||
defineBinding(function);
|
||||
declareFunction(function, arguments);
|
||||
}
|
||||
|
||||
private void declareFunction(IFunction function, IASTInitializerClause[] arguments) {
|
||||
// Handle return or expression type of the function or constructor call.
|
||||
IType returnType = function.getType().getReturnType();
|
||||
if (!(returnType instanceof IPointerType) && !(returnType instanceof ICPPReferenceType)) {
|
||||
|
@ -533,7 +541,7 @@ public class BindingClassifier {
|
|||
}
|
||||
|
||||
// Handle parameters.
|
||||
processFunctionParameters(function, functionCallExpression.getArguments());
|
||||
processFunctionParameters(function, arguments);
|
||||
}
|
||||
|
||||
private class BindingCollector extends ASTVisitor {
|
||||
|
@ -921,6 +929,13 @@ public class BindingClassifier {
|
|||
* }
|
||||
*/
|
||||
IASTUnaryExpression unaryExpression = (IASTUnaryExpression) expression;
|
||||
if (unaryExpression instanceof ICPPASTUnaryExpression) {
|
||||
ICPPFunction overload = ((ICPPASTUnaryExpression) unaryExpression).getOverload();
|
||||
if (overload != null) {
|
||||
defineFunction(overload, new IASTInitializerClause[] { unaryExpression.getOperand() });
|
||||
return PROCESS_CONTINUE;
|
||||
}
|
||||
}
|
||||
|
||||
boolean expressionDefinitionRequired = true;
|
||||
switch (unaryExpression.getOperator()) {
|
||||
|
@ -970,6 +985,14 @@ public class BindingClassifier {
|
|||
* }
|
||||
*/
|
||||
IASTBinaryExpression binaryExpression = (IASTBinaryExpression) expression;
|
||||
if (binaryExpression instanceof ICPPASTBinaryExpression) {
|
||||
ICPPFunction overload = ((ICPPASTBinaryExpression) binaryExpression).getOverload();
|
||||
if (overload != null) {
|
||||
defineFunction(overload,
|
||||
new IASTInitializerClause[] { binaryExpression.getOperand1(), binaryExpression.getOperand2() });
|
||||
return PROCESS_CONTINUE;
|
||||
}
|
||||
}
|
||||
|
||||
IType operand1Type = binaryExpression.getOperand1().getExpressionType();
|
||||
IType operand2Type = binaryExpression.getOperand2().getExpressionType();
|
||||
|
@ -1049,7 +1072,7 @@ public class BindingClassifier {
|
|||
if (functionNameExpression instanceof IASTIdExpression) {
|
||||
IBinding binding = ((IASTIdExpression) functionNameExpression).getName().resolveBinding();
|
||||
if (binding instanceof IFunction) {
|
||||
declareFunction((IFunction) binding, functionCallExpression);
|
||||
declareFunction((IFunction) binding, functionCallExpression.getArguments());
|
||||
} else {
|
||||
if (binding instanceof IType)
|
||||
defineBinding(binding);
|
||||
|
@ -1059,7 +1082,7 @@ public class BindingClassifier {
|
|||
for (IASTName name : implicitNames) {
|
||||
binding = name.resolveBinding();
|
||||
if (binding instanceof IFunction) {
|
||||
declareFunction((IFunction) binding, functionCallExpression);
|
||||
defineFunction((IFunction) binding, functionCallExpression.getArguments());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue