1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-22 22:22:11 +02:00

Bug 472818 - HeuristicResolver: support for EvalFunctionCall

Change-Id: Id0a76d748d5a03d70b8f75ca0e8d776d824b88e5
This commit is contained in:
Nathan Ridge 2016-01-31 23:24:41 -05:00
parent 01a74ee5f7
commit 6df72650e4
3 changed files with 27 additions and 19 deletions

View file

@ -12,7 +12,6 @@
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp.semantics;
import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.ExpressionTypes.typeFromReturnType;
import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.ExpressionTypes.valueCategoryFromFunctionCall;
import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.ExpressionTypes.valueCategoryFromReturnType;
import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.CVTYPE;
@ -34,7 +33,6 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPParameter;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameterMap;
import org.eclipse.cdt.internal.core.dom.parser.ISerializableEvaluation;
import org.eclipse.cdt.internal.core.dom.parser.ITypeMarshalBuffer;
import org.eclipse.cdt.internal.core.dom.parser.ProblemType;
import org.eclipse.cdt.internal.core.dom.parser.Value;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPFunction;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPEvaluation;
@ -124,24 +122,13 @@ public class EvalFunctionCall extends CPPDependentEvaluation {
ICPPFunction overload = getOverload(point);
if (overload != null)
return ExpressionTypes.typeFromFunctionCall(overload);
final ICPPEvaluation arg0 = fArguments[0];
IType t= SemanticUtil.getNestedType(arg0.getType(point), TDEF | REF | CVTYPE);
if (t instanceof ICPPClassType) {
return ProblemType.UNKNOWN_FOR_EXPRESSION;
ICPPEvaluation function = fArguments[0];
IType result = ExpressionTypes.typeFromFunctionCall(function.getType(point));
if (function instanceof EvalMemberAccess) {
result = ExpressionTypes.restoreTypedefs(result, ((EvalMemberAccess) function).getOwnerType());
}
if (t instanceof IPointerType) {
t= SemanticUtil.getNestedType(((IPointerType) t).getType(), TDEF | REF | CVTYPE);
}
if (t instanceof IFunctionType) {
t = typeFromReturnType(((IFunctionType) t).getReturnType());
if (arg0 instanceof EvalMemberAccess) {
t= ExpressionTypes.restoreTypedefs(t, ((EvalMemberAccess) arg0).getOwnerType());
}
return t;
}
return ProblemType.UNKNOWN_FOR_EXPRESSION;
return result;
}
@Override

View file

@ -22,6 +22,7 @@ import org.eclipse.cdt.core.dom.ast.c.ICQualifierType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPReferenceType;
import org.eclipse.cdt.internal.core.dom.parser.ProblemType;
import org.eclipse.cdt.internal.core.dom.parser.c.CQualifierType;
/**
@ -61,6 +62,18 @@ public class ExpressionTypes {
}
return ValueCategory.PRVALUE;
}
public static IType typeFromFunctionCall(IType functionType) {
IType t= SemanticUtil.getNestedType(functionType, TDEF | REF | CVTYPE);
if (t instanceof IPointerType) {
t= SemanticUtil.getNestedType(((IPointerType) t).getType(), TDEF | REF | CVTYPE);
}
if (t instanceof IFunctionType) {
t = typeFromReturnType(((IFunctionType) t).getReturnType());
return t;
}
return ProblemType.UNKNOWN_FOR_EXPRESSION;
}
public static IType typeFromFunctionCall(ICPPFunction function) {
final ICPPFunctionType ft = function.getType();

View file

@ -154,6 +154,14 @@ public class HeuristicResolver {
return typeForBinding(candidates[0]);
}
}
} else if (evaluation instanceof EvalFunctionCall) {
EvalFunctionCall evalFunctionCall = (EvalFunctionCall) evaluation;
ICPPEvaluation function = evalFunctionCall.getArguments()[0];
IType functionType = function.getType(point);
if (functionType instanceof ICPPUnknownType) {
functionType = resolveUnknownType((ICPPUnknownType) functionType, point);
}
return ExpressionTypes.typeFromFunctionCall(functionType);
}
// TODO(nathanridge): Handle more cases.
} else if (type instanceof ICPPUnknownMemberClass) {