use of org.eclipse.ceylon.model.typechecker.model.TypedReference in project ceylon by eclipse.
the class CompilerBoxingDeclarationVisitor method getRefinedDeclarationForWideningRules.
@Override
protected TypedDeclaration getRefinedDeclarationForWideningRules(TypedDeclaration typedDeclaration) {
TypedReference typedReference = transformer.getTypedReference(typedDeclaration);
TypedReference refinedDeclaration = transformer.getRefinedDeclaration(typedReference, typedReference.getQualifyingType());
if (refinedDeclaration != null)
return refinedDeclaration.getDeclaration();
return null;
}
use of org.eclipse.ceylon.model.typechecker.model.TypedReference in project ceylon by eclipse.
the class ExpressionVisitor method visitGenericBaseMemberReference.
private void visitGenericBaseMemberReference(Tree.StaticMemberOrTypeExpression that, TypedDeclaration member) {
if (member instanceof Function && member.isParameterized()) {
Function generic = (Function) member;
Scope scope = that.getScope();
Type outerType = scope.getDeclaringType(member);
TypedReference target = member.appliedTypedReference(outerType, NO_TYPE_ARGS);
that.setTarget(target);
Type functionType = genericFunctionType(generic, scope, member, target, unit);
that.setTypeModel(functionType);
checkNotJvm(that, "type functions are not supported on the JVM: '" + member.getName(unit) + "' is generic (specify explicit type arguments)");
}
}
use of org.eclipse.ceylon.model.typechecker.model.TypedReference in project ceylon by eclipse.
the class TypeArgumentInference method getInferredTypeArgsForFunctionRef.
/**
* Infer the type arguments for a reference to a
* generic function that occurs as an argument in
* an invocation.
* @param receiverType
*/
List<Type> getInferredTypeArgsForFunctionRef(Tree.StaticMemberOrTypeExpression smte, Type receiverType, boolean secondList) {
Tree.TypeArguments typeArguments = smte.getTypeArguments();
if (typeArguments instanceof Tree.InferredTypeArguments) {
// the model object for the function ref
Declaration reference = smte.getDeclaration();
List<TypeParameter> typeParameters = getTypeParametersAccountingForTypeConstructor(reference);
if (typeParameters == null || typeParameters.isEmpty()) {
// nothing to infer
return NO_TYPE_ARGS;
} else {
// set earlier in inferParameterTypes()
TypedReference paramTypedRef = smte.getTargetParameter();
Type paramType = smte.getParameterType();
// the function ref is being passed
if (paramType == null && paramTypedRef != null) {
paramType = paramTypedRef.getFullType();
}
if (paramType == null) {
return null;
}
if (isArgumentToGenericParameter(paramTypedRef, paramType)) {
return null;
}
Declaration paramDec;
Declaration parameterizedDec;
if (paramTypedRef != null) {
paramDec = paramTypedRef.getDeclaration();
parameterizedDec = (Declaration) paramDec.getContainer();
} else {
paramDec = null;
parameterizedDec = null;
}
// better algorithm
if (!smte.getStaticMethodReferencePrimary() && reference instanceof Functional && paramDec instanceof Functional && paramTypedRef != null) {
// callable parameter
return inferFunctionRefTypeArgs(smte, receiverType, secondList, reference, typeParameters, paramTypedRef, paramDec, parameterizedDec);
} else {
// improve this, including in the spec)
if (unit.isSequentialType(paramType)) {
paramType = unit.getSequentialElementType(paramType);
}
if (unit.isCallableType(paramType)) {
// the parameter has type Callable
return inferFunctionRefTypeArgs(smte, receiverType, secondList, reference, typeParameters, paramType, parameterizedDec);
} else if (secondList) {
// arguments (NOT BLESSED BY SPEC!)
return inferNullaryFunctionCallTypeArgs(smte, receiverType, reference, typeParameters, paramType, parameterizedDec);
} else {
return null;
}
}
}
} else {
// not inferring
return null;
}
}
use of org.eclipse.ceylon.model.typechecker.model.TypedReference in project ceylon by eclipse.
the class ExpressionVisitor method inferParameterTypes.
/**
* Infer parameter types for an anonymous function.
*/
private boolean inferParameterTypes(Reference pr, Parameter param, Tree.Expression e, boolean variadic, boolean error) {
FunctionOrValue model = param.getModel();
if (e != null && model != null) {
Tree.Term term = unwrapExpressionUntilTerm(e.getTerm());
TypedReference tpr = pr.getTypedParameter(param);
if (term instanceof Tree.InvocationExpression) {
Tree.InvocationExpression ie = (Tree.InvocationExpression) term;
Tree.PositionalArgumentList pal = ie.getPositionalArgumentList();
Tree.NamedArgumentList nal = ie.getNamedArgumentList();
if (pal != null && pal.getPositionalArguments().isEmpty() || nal != null && nal.getNamedArguments().isEmpty()) {
term = ie.getPrimary();
}
}
if (term instanceof Tree.FunctionArgument) {
Tree.FunctionArgument anon = (Tree.FunctionArgument) term;
if (model instanceof Functional) {
// and could be removed
return inferParameterTypesFromCallableParameter(pr, param, anon, error);
} else {
Type paramType = tpr.getFullType();
if (variadic) {
paramType = unit.getIteratedType(paramType);
}
paramType = callableFromUnion(paramType);
if (unit.isCallableType(paramType)) {
return inferParameterTypesFromCallableType(paramType, param, anon, error);
}
}
}
}
return true;
}
use of org.eclipse.ceylon.model.typechecker.model.TypedReference in project ceylon by eclipse.
the class ExpressionVisitor method setupTargetParameters.
/**
* Set the "target parameter" for a reference, which
* will be used later for inferring type arguments for
* a function ref or generic function ref.
*/
private void setupTargetParameters(Reference pr, Parameter param, Tree.Expression e) {
if (e != null) {
Tree.Term term = unwrapExpressionUntilTerm(e.getTerm());
TypedReference tpr = pr.getTypedParameter(param);
if (term instanceof Tree.InvocationExpression) {
Tree.InvocationExpression ie = (Tree.InvocationExpression) term;
Tree.PositionalArgumentList pal = ie.getPositionalArgumentList();
Tree.NamedArgumentList nal = ie.getNamedArgumentList();
if (pal != null && pal.getPositionalArguments().isEmpty() || nal != null && nal.getNamedArguments().isEmpty()) {
term = ie.getPrimary();
}
}
if (term instanceof Tree.StaticMemberOrTypeExpression) {
// the "target parameter" is used later to
// infer type arguments for function refs
// and generic function refs
Tree.StaticMemberOrTypeExpression stme = (Tree.StaticMemberOrTypeExpression) term;
if (stme instanceof Tree.QualifiedMemberOrTypeExpression && stme.getStaticMethodReference()) {
Tree.QualifiedMemberOrTypeExpression qmte = (Tree.QualifiedMemberOrTypeExpression) stme;
Tree.StaticMemberOrTypeExpression ote = (Tree.StaticMemberOrTypeExpression) qmte.getPrimary();
ote.setTargetParameter(tpr);
stme.setParameterType(tpr.getFullType());
} else {
stme.setTargetParameter(tpr);
stme.setParameterType(tpr.getFullType());
}
}
}
}
Aggregations