Search in sources :

Example 16 with FunctionOrValue

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))));
}
Also used : FunctionOrValue(com.redhat.ceylon.model.typechecker.model.FunctionOrValue)

Example 17 with FunctionOrValue

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;
}
Also used : Type(com.redhat.ceylon.model.typechecker.model.Type) JCExpression(com.sun.tools.javac.tree.JCTree.JCExpression) TypedReference(com.redhat.ceylon.model.typechecker.model.TypedReference) Class(com.redhat.ceylon.model.typechecker.model.Class) JCNewClass(com.sun.tools.javac.tree.JCTree.JCNewClass) FunctionOrValue(com.redhat.ceylon.model.typechecker.model.FunctionOrValue)

Example 18 with FunctionOrValue

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;
            }
        });
    }
}
Also used : TypedDeclaration(com.redhat.ceylon.model.typechecker.model.TypedDeclaration) TypedReference(com.redhat.ceylon.model.typechecker.model.TypedReference) Function(com.redhat.ceylon.model.typechecker.model.Function) Type(com.redhat.ceylon.model.typechecker.model.Type) JCExpression(com.sun.tools.javac.tree.JCTree.JCExpression) FunctionOrValue(com.redhat.ceylon.model.typechecker.model.FunctionOrValue) FieldValue(com.redhat.ceylon.model.loader.model.FieldValue) Value(com.redhat.ceylon.model.typechecker.model.Value) JCTree(com.sun.tools.javac.tree.JCTree) Tree(com.redhat.ceylon.compiler.typechecker.tree.Tree) FunctionOrValue(com.redhat.ceylon.model.typechecker.model.FunctionOrValue)

Aggregations

FunctionOrValue (com.redhat.ceylon.model.typechecker.model.FunctionOrValue)18 Value (com.redhat.ceylon.model.typechecker.model.Value)10 Function (com.redhat.ceylon.model.typechecker.model.Function)9 Type (com.redhat.ceylon.model.typechecker.model.Type)7 Declaration (com.redhat.ceylon.model.typechecker.model.Declaration)6 TypedDeclaration (com.redhat.ceylon.model.typechecker.model.TypedDeclaration)6 Parameter (com.redhat.ceylon.model.typechecker.model.Parameter)5 TypeDeclaration (com.redhat.ceylon.model.typechecker.model.TypeDeclaration)5 TypeParameter (com.redhat.ceylon.model.typechecker.model.TypeParameter)5 TypedReference (com.redhat.ceylon.model.typechecker.model.TypedReference)5 Tree (com.redhat.ceylon.compiler.typechecker.tree.Tree)4 ArrayList (java.util.ArrayList)4 Class (com.redhat.ceylon.model.typechecker.model.Class)3 JCExpression (com.sun.tools.javac.tree.JCTree.JCExpression)3 Statement (com.redhat.ceylon.compiler.typechecker.tree.Tree.Statement)2 JavaBeanValue (com.redhat.ceylon.model.loader.model.JavaBeanValue)2 Functional (com.redhat.ceylon.model.typechecker.model.Functional)2 ParameterList (com.redhat.ceylon.model.typechecker.model.ParameterList)2 Scope (com.redhat.ceylon.model.typechecker.model.Scope)2 JCTree (com.sun.tools.javac.tree.JCTree)2