use of org.eclipse.ceylon.model.typechecker.model.TypedReference in project ceylon by eclipse.
the class AbstractTransformer method getGetterInterfaceType.
Type getGetterInterfaceType(TypedDeclaration attrTypedDecl) {
TypedReference typedRef = getTypedReference(attrTypedDecl);
TypedReference nonWideningTypedRef = nonWideningTypeDecl(typedRef);
Type nonWideningType = nonWideningType(typedRef, nonWideningTypedRef);
Type type;
boolean unboxed = CodegenUtil.isUnBoxed(attrTypedDecl);
if (unboxed && isCeylonBoolean(nonWideningType)) {
type = javacCeylonTypeToProducedType(syms().ceylonGetterBooleanType);
} else if (unboxed && isCeylonInteger(nonWideningType)) {
if (Decl.isSmall(attrTypedDecl)) {
type = javacCeylonTypeToProducedType(syms().ceylonGetterIntType);
} else {
type = javacCeylonTypeToProducedType(syms().ceylonGetterLongType);
}
} else if (unboxed && isCeylonFloat(nonWideningType)) {
if (Decl.isSmall(attrTypedDecl)) {
type = javacCeylonTypeToProducedType(syms().ceylonGetterFloatType);
} else {
type = javacCeylonTypeToProducedType(syms().ceylonGetterDoubleType);
}
} else if (unboxed && isCeylonCharacter(nonWideningType)) {
if (Decl.isSmall(attrTypedDecl)) {
type = javacCeylonTypeToProducedType(syms().ceylonGetterCharType);
} else {
type = javacCeylonTypeToProducedType(syms().ceylonGetterIntType);
}
} else if (unboxed && isCeylonByte(nonWideningType)) {
type = javacCeylonTypeToProducedType(syms().ceylonGetterByteType);
} else {
type = javacCeylonTypeToProducedType(syms().ceylonGetterType);
Type typeArg = nonWideningType;
if (unboxed && isCeylonString(typeArg)) {
typeArg = javacJavaTypeToProducedType(syms().stringType);
}
type = appliedType(type.getDeclaration(), typeArg);
}
return type;
}
use of org.eclipse.ceylon.model.typechecker.model.TypedReference in project ceylon by eclipse.
the class AbstractTransformer method nonWideningTypeDecl.
TypedReference nonWideningTypeDecl(TypedReference typedReference, Type currentType) {
TypedReference refinedTypedReference = getRefinedDeclaration(typedReference, currentType);
if (refinedTypedReference != null) {
/*
* We are widening if the type:
* - is not object
* - is erased to object
* - refines a declaration that is not erased to object
*/
Type declType = typedReference.getType();
Type refinedDeclType = refinedTypedReference.getType();
if (declType == null || refinedDeclType == null)
return typedReference;
boolean isWidening = isWidening(declType, refinedDeclType);
if (!isWidening) {
// make sure we get the instantiated refined decl
if (refinedDeclType.getDeclaration() instanceof TypeParameter && !(declType.getDeclaration() instanceof TypeParameter))
refinedDeclType = nonWideningType(typedReference, refinedTypedReference);
if (!typedReference.getTypeArguments().containsKey(simplifyType(refinedDeclType).getDeclaration())) {
isWidening = isWideningTypeArguments(declType, refinedDeclType, true);
}
}
if (isWidening)
return refinedTypedReference;
}
return typedReference;
}
use of org.eclipse.ceylon.model.typechecker.model.TypedReference in project ceylon by eclipse.
the class AbstractTransformer method isWideningTypeDecl.
public boolean isWideningTypeDecl(TypedReference typedReference, Type currentType) {
TypedReference refinedTypedReference = getRefinedDeclaration(typedReference, currentType);
if (refinedTypedReference == null)
return false;
/*
* We are widening if the type:
* - is not object
* - is erased to object
* - refines a declaration that is not erased to object
*/
Type declType = typedReference.getType();
Type refinedDeclType = refinedTypedReference.getType();
if (declType == null || refinedDeclType == null)
return false;
if (isWidening(declType, refinedDeclType))
return true;
// make sure we get the instantiated refined decl
if (refinedDeclType.getDeclaration() instanceof TypeParameter && !(declType.getDeclaration() instanceof TypeParameter))
refinedDeclType = nonWideningType(typedReference, refinedTypedReference);
if (isWideningTypeArguments(declType, refinedDeclType, true))
return true;
if (CodegenUtil.hasTypeErased(refinedTypedReference.getDeclaration()) && !willEraseToObject(declType))
return true;
return false;
}
use of org.eclipse.ceylon.model.typechecker.model.TypedReference in project ceylon by eclipse.
the class AbstractTransformer method getTypedSignature.
private java.util.List<Type> getTypedSignature(Type currentType, TypedDeclaration found) {
// check that its signature is compatible
java.util.List<ParameterList> parameterLists = ((Function) found).getParameterLists();
if (parameterLists == null || parameterLists.isEmpty())
return null;
// only consider first param list
java.util.List<Parameter> parameters = parameterLists.get(0).getParameters();
if (parameters == null)
return null;
TypedReference typedMember = currentType.getTypedMember(found, Collections.<Type>emptyList());
if (typedMember == null)
return null;
java.util.List<Type> typedSignature = new ArrayList<Type>(parameters.size());
for (Parameter p : parameters) {
Type parameterType = typedMember.getTypedParameter(p).getFullType();
typedSignature.add(parameterType);
}
return typedSignature;
}
use of org.eclipse.ceylon.model.typechecker.model.TypedReference in project ceylon by eclipse.
the class AbstractTransformer method nonWideningType.
Type nonWideningType(TypedReference declaration, TypedReference refinedDeclaration) {
final Reference pr;
if (declaration.equals(refinedDeclaration)) {
pr = declaration;
} else {
Type refinedType = refinedDeclaration.getType();
// since it may have changed name
if (refinedType.getDeclaration() instanceof TypeParameter && refinedType.getDeclaration().getContainer() instanceof Function) {
// find its index in the refined declaration
TypeParameter refinedTypeParameter = (TypeParameter) refinedType.getDeclaration();
Function refinedMethod = (Function) refinedTypeParameter.getContainer();
int i = 0;
for (TypeParameter tp : refinedMethod.getTypeParameters()) {
if (tp.getName().equals(refinedTypeParameter.getName()))
break;
i++;
}
if (i >= refinedMethod.getTypeParameters().size()) {
throw new BugException("can't find type parameter " + refinedTypeParameter.getName() + " in its container " + refinedMethod.getName());
}
// the refining method type parameter should be at the same index
if (declaration.getDeclaration() instanceof Function == false)
throw new BugException("refining declaration is not a method: " + declaration);
Function refiningMethod = (Function) declaration.getDeclaration();
if (i >= refiningMethod.getTypeParameters().size()) {
throw new BugException("refining method does not have enough type parameters to refine " + refinedMethod.getName());
}
pr = refiningMethod.getTypeParameters().get(i).getType();
} else {
pr = refinedType;
}
}
if (pr.getDeclaration() instanceof Functional && Decl.isMpl((Functional) pr.getDeclaration())) {
// the innermost Callable.
return getReturnTypeOfCallable(pr.getFullType());
}
return getPinnedType(declaration, pr.getType());
}
Aggregations