use of com.redhat.ceylon.model.typechecker.model.FunctionOrValue in project ceylon-compiler by ceylon.
the class ClassTransformer method makeFieldForParameter.
private void makeFieldForParameter(ClassDefinitionBuilder classBuilder, Parameter decl, Tree.Declaration annotated) {
FunctionOrValue model = decl.getModel();
classBuilder.defs(make().VarDef(make().Modifiers(transformClassParameterDeclFlags(decl) | PRIVATE, makeAtIgnore().prependList(expressionGen().transformAnnotations(OutputElement.FIELD, annotated))), names().fromString(Naming.quoteFieldName(decl.getName())), classGen().transformClassParameterType(decl), null));
classBuilder.getInitBuilder().init(make().Exec(make().Assign(naming.makeQualifiedName(naming.makeThis(), model, Naming.NA_IDENT), naming.makeName(model, Naming.NA_IDENT_PARAMETER_ALIASED))));
}
use of com.redhat.ceylon.model.typechecker.model.FunctionOrValue in project ceylon-compiler by ceylon.
the class ClassTransformer method transformClassParameterType.
/**
* Transforms the type of the given class parameter
* @param decl
* @return
*/
JCExpression transformClassParameterType(Parameter parameter) {
FunctionOrValue decl = parameter.getModel();
if (!(decl.getContainer() instanceof Class)) {
throw new BugException("expected parameter of Class");
}
JCExpression type;
FunctionOrValue attr = decl;
if (!Decl.isTransient(attr)) {
TypedReference typedRef = getTypedReference(attr);
TypedReference nonWideningTypedRef = nonWideningTypeDecl(typedRef);
Type paramType = nonWideningType(typedRef, nonWideningTypedRef);
type = makeJavaType(nonWideningTypedRef.getDeclaration(), paramType, 0);
} else {
Type paramType = decl.getType();
type = makeJavaType(decl, paramType, 0);
}
return type;
}
use of com.redhat.ceylon.model.typechecker.model.FunctionOrValue in project ceylon-compiler by ceylon.
the class ExpressionTransformer method transformAssignment.
private JCExpression transformAssignment(Node op, Tree.Term leftTerm, Tree.Term rightTerm) {
// Remember and disable inStatement for RHS
boolean tmpInStatement = inStatement;
inStatement = false;
// FIXME: can this be anything else than a Tree.MemberOrTypeExpression or Tree.ParameterizedExpression?
final JCExpression rhs;
BoxingStrategy boxing;
if (leftTerm instanceof Tree.MemberOrTypeExpression) {
TypedDeclaration decl = (TypedDeclaration) ((Tree.MemberOrTypeExpression) leftTerm).getDeclaration();
boxing = CodegenUtil.getBoxingStrategy(decl);
if (decl instanceof Value) {
Value val = (Value) decl;
if (val.getSetter() != null && val.getSetter().getUnboxed() != null) {
boxing = CodegenUtil.getBoxingStrategy(val.getSetter());
}
}
Type targetType = tmpInStatement ? leftTerm.getTypeModel() : rightTerm.getTypeModel();
// if we're dealing with widening do not trust the type of the declaration and get the real type
if (CodegenUtil.hasUntrustedType(decl)) {
TypedReference typedRef = (TypedReference) ((Tree.MemberOrTypeExpression) leftTerm).getTarget();
TypedReference nonWideningTypedRef = nonWideningTypeDecl(typedRef);
targetType = nonWideningType(typedRef, nonWideningTypedRef);
}
rhs = transformExpression(rightTerm, boxing, targetType, decl.hasUncheckedNullType() ? EXPR_TARGET_ACCEPTS_NULL : 0);
} else {
// instanceof Tree.ParameterizedExpression
boxing = CodegenUtil.getBoxingStrategy(leftTerm);
Tree.ParameterizedExpression paramExpr = (Tree.ParameterizedExpression) leftTerm;
FunctionOrValue decl = (FunctionOrValue) ((Tree.MemberOrTypeExpression) paramExpr.getPrimary()).getDeclaration();
CallableBuilder callableBuilder = CallableBuilder.anonymous(gen(), paramExpr, decl, (Tree.Expression) rightTerm, paramExpr.getParameterLists(), paramExpr.getPrimary().getTypeModel(), decl instanceof Function ? !((Function) decl).isDeferred() : false);
rhs = callableBuilder.build();
}
if (tmpInStatement) {
return transformAssignment(op, leftTerm, rhs);
} else {
Type valueType = rightTerm.getTypeModel();
if (isNull(valueType))
valueType = leftTerm.getTypeModel();
return transformAssignAndReturnOperation(op, leftTerm, boxing == BoxingStrategy.BOXED, leftTerm.getTypeModel(), valueType, new AssignAndReturnOperationFactory() {
@Override
public JCExpression getNewValue(JCExpression previousValue) {
return rhs;
}
});
}
}
Aggregations