Search in sources :

Example 1 with StaticMemberOrTypeExpression

use of org.eclipse.ceylon.compiler.typechecker.tree.Tree.StaticMemberOrTypeExpression in project ceylon by eclipse.

the class BoxingVisitor method visit.

@Override
public void visit(InvocationExpression that) {
    super.visit(that);
    if (isIndirectInvocation(that, true) && !Decl.isJavaStaticOrInterfacePrimary(that.getPrimary())) {
        // if the Callable is raw the invocation will be erased
        if (that.getPrimary().getTypeModel() != null && isRaw(that.getPrimary().getTypeModel()))
            CodegenUtil.markTypeErased(that);
        // These are always boxed
        return;
    }
    if (isByteLiteral(that))
        CodegenUtil.markUnBoxed(that);
    else
        propagateFromTerm(that, that.getPrimary());
    // then we mark the expression itself as erased as well
    if (that.getPrimary() instanceof StaticMemberOrTypeExpression) {
        StaticMemberOrTypeExpression expr = (StaticMemberOrTypeExpression) that.getPrimary();
        if (expr.getDeclaration() instanceof Function) {
            Function mth = (Function) expr.getDeclaration();
            if (isTypeParameter(mth.getType()) && (hasErasedTypeParameter(expr.getTarget(), expr.getTypeArguments()) || CodegenUtil.isRaw(that))) {
                CodegenUtil.markTypeErased(that);
                CodegenUtil.markUntrustedType(that);
            }
        }
    }
    if (that.getPrimary() instanceof Tree.MemberOrTypeExpression && Decl.isConstructor(((Tree.MemberOrTypeExpression) that.getPrimary()).getDeclaration())) {
        Constructor ctor = ModelUtil.getConstructor(((Tree.MemberOrTypeExpression) that.getPrimary()).getDeclaration());
        if (Decl.isJavaObjectArrayWith(ctor)) {
            CodegenUtil.markTypeErased(that);
        }
    }
}
Also used : Function(org.eclipse.ceylon.model.typechecker.model.Function) MemberOrTypeExpression(org.eclipse.ceylon.compiler.typechecker.tree.Tree.MemberOrTypeExpression) Constructor(org.eclipse.ceylon.model.typechecker.model.Constructor) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree) StaticMemberOrTypeExpression(org.eclipse.ceylon.compiler.typechecker.tree.Tree.StaticMemberOrTypeExpression) MemberOrTypeExpression(org.eclipse.ceylon.compiler.typechecker.tree.Tree.MemberOrTypeExpression) StaticMemberOrTypeExpression(org.eclipse.ceylon.compiler.typechecker.tree.Tree.StaticMemberOrTypeExpression)

Example 2 with StaticMemberOrTypeExpression

use of org.eclipse.ceylon.compiler.typechecker.tree.Tree.StaticMemberOrTypeExpression in project ceylon by eclipse.

the class NamedArgumentInvocation method makeThis.

private final JCVariableDecl makeThis() {
    // first append $this
    JCExpression defaultedParameterInstance;
    // TODO Fix how we figure out the thisType, because it's doesn't
    // handle type parameters correctly
    // we used to use thisType = gen.getThisType(getPrimaryDeclaration());
    final JCExpression thisType;
    Reference target = ((Tree.MemberOrTypeExpression) getPrimary()).getTarget();
    if (getPrimary() instanceof Tree.BaseMemberExpression && !gen.expressionGen().isWithinSyntheticClassBody()) {
        Declaration primaryDec = getPrimaryDeclaration();
        if (primaryDec.isClassOrInterfaceMember()) {
            // a member method
            thisType = gen.makeJavaType(target.getQualifyingType(), JT_NO_PRIMITIVES | (primaryDec.isInterfaceMember() && !primaryDec.isShared() ? JT_COMPANION : 0));
            TypeDeclaration outer = Decl.getOuterScopeOfMemberInvocation((StaticMemberOrTypeExpression) getPrimary(), primaryDec);
            if (outer instanceof Interface && primaryDec.isShared()) {
                defaultedParameterInstance = gen.naming.makeQuotedThis();
            } else {
                defaultedParameterInstance = gen.naming.makeQualifiedThis(gen.makeJavaType(((TypeDeclaration) outer).getType(), JT_NO_PRIMITIVES | (primaryDec.isInterfaceMember() && !primaryDec.isShared() ? JT_COMPANION : 0)));
            }
        } else {
            // a local or toplevel function
            thisType = gen.naming.makeName((TypedDeclaration) primaryDec, Naming.NA_WRAPPER);
            defaultedParameterInstance = gen.naming.makeName((TypedDeclaration) primaryDec, Naming.NA_MEMBER);
        }
    } else if (getPrimary() instanceof Tree.BaseTypeExpression || getPrimary() instanceof Tree.QualifiedTypeExpression) {
        TypeDeclaration declaration = (TypeDeclaration) ((Tree.MemberOrTypeExpression) getPrimary()).getDeclaration();
        thisType = gen.makeJavaType(declaration.getType(), JT_COMPANION);
        defaultedParameterInstance = gen.make().NewClass(null, null, gen.makeJavaType(declaration.getType(), JT_COMPANION), List.<JCExpression>nil(), null);
    } else {
        if (isOnValueType()) {
            thisType = gen.makeJavaType(target.getQualifyingType());
        } else {
            thisType = gen.makeJavaType(target.getQualifyingType(), JT_NO_PRIMITIVES);
        }
        defaultedParameterInstance = callVarName.makeIdent();
    }
    JCVariableDecl thisDecl = gen.makeVar(varBaseName.suffixedBy(Suffix.$argthis$), thisType, defaultedParameterInstance);
    return thisDecl;
}
Also used : TypedDeclaration(org.eclipse.ceylon.model.typechecker.model.TypedDeclaration) JCExpression(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCExpression) TypedReference(org.eclipse.ceylon.model.typechecker.model.TypedReference) Reference(org.eclipse.ceylon.model.typechecker.model.Reference) JCTree(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree) StaticMemberOrTypeExpression(org.eclipse.ceylon.compiler.typechecker.tree.Tree.StaticMemberOrTypeExpression) TypedDeclaration(org.eclipse.ceylon.model.typechecker.model.TypedDeclaration) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) Declaration(org.eclipse.ceylon.model.typechecker.model.Declaration) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) Interface(org.eclipse.ceylon.model.typechecker.model.Interface) ClassOrInterface(org.eclipse.ceylon.model.typechecker.model.ClassOrInterface) QualifiedTypeExpression(org.eclipse.ceylon.compiler.typechecker.tree.Tree.QualifiedTypeExpression) JCVariableDecl(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCVariableDecl)

Example 3 with StaticMemberOrTypeExpression

use of org.eclipse.ceylon.compiler.typechecker.tree.Tree.StaticMemberOrTypeExpression in project ceylon by eclipse.

the class GenerateJsVisitor method visit.

@Override
public void visit(final Tree.AssignOp that) {
    if (errVisitor.hasErrors(that))
        return;
    String returnValue = null;
    StaticMemberOrTypeExpression lhsExpr = null;
    final boolean leftDynamic = isInDynamicBlock() && ModelUtil.isTypeUnknown(that.getLeftTerm().getTypeModel());
    if (that.getLeftTerm() instanceof Tree.IndexExpression) {
        Tree.IndexExpression iex = (Tree.IndexExpression) that.getLeftTerm();
        if (leftDynamic) {
            iex.getPrimary().visit(this);
            out("[");
            ((Tree.Element) iex.getElementOrRange()).getExpression().visit(this);
            out("]=");
            that.getRightTerm().visit(this);
        } else {
            final String tv = createRetainedTempVar();
            out("(", tv, "=");
            that.getRightTerm().visit(this);
            out(",");
            iex.getPrimary().visit(this);
            TypeDeclaration td = iex.getPrimary().getTypeModel().getDeclaration();
            if (td != null && td.inherits(iex.getUnit().getKeyedCorrespondenceMutatorDeclaration())) {
                out(".put(");
            } else {
                out(".set(");
            }
            ((Tree.Element) iex.getElementOrRange()).getExpression().visit(this);
            out(",", tv, "), ", tv, ")");
        }
        return;
    }
    if (leftDynamic) {
        that.getLeftTerm().visit(this);
        out("=");
        int box = boxUnboxStart(that.getRightTerm(), that.getLeftTerm());
        that.getRightTerm().visit(this);
        if (box == 4)
            out("/*TODO: callable targs 6.2*/");
        boxUnboxEnd(box);
        return;
    }
    out("(");
    if (that.getLeftTerm() instanceof BaseMemberExpression) {
        BaseMemberExpression bme = (BaseMemberExpression) that.getLeftTerm();
        lhsExpr = bme;
        Declaration bmeDecl = bme.getDeclaration();
        boolean simpleSetter = hasSimpleGetterSetter(bmeDecl);
        if (!simpleSetter) {
            returnValue = memberAccess(bme, null);
        }
    } else if (that.getLeftTerm() instanceof QualifiedMemberExpression) {
        QualifiedMemberExpression qme = (QualifiedMemberExpression) that.getLeftTerm();
        lhsExpr = qme;
        boolean simpleSetter = hasSimpleGetterSetter(qme.getDeclaration());
        String lhsVar = null;
        if (!simpleSetter) {
            lhsVar = createRetainedTempVar();
            out(lhsVar, "=");
            super.visit(qme);
            out(",", lhsVar, ".");
            returnValue = memberAccess(qme, lhsVar);
        } else if (qme.getPrimary() instanceof Tree.Package == false) {
            super.visit(qme);
            out(".");
            if (qme.getDeclaration() != null && qme.getDeclaration().isStatic()) {
                out("$st$.");
            }
        }
    }
    BmeGenerator.generateMemberAccess(lhsExpr, new GenerateCallback() {

        @Override
        public void generateValue() {
            if (!isNaturalLiteral(that.getRightTerm())) {
                int boxType = boxUnboxStart(that.getRightTerm(), that.getLeftTerm());
                that.getRightTerm().visit(GenerateJsVisitor.this);
                if (boxType == 4)
                    out("/*TODO: callable targs 7*/");
                boxUnboxEnd(boxType);
            }
        }
    }, null, this);
    if (returnValue != null) {
        out(",", returnValue);
    }
    out(")");
}
Also used : QualifiedMemberExpression(org.eclipse.ceylon.compiler.typechecker.tree.Tree.QualifiedMemberExpression) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree) BaseMemberExpression(org.eclipse.ceylon.compiler.typechecker.tree.Tree.BaseMemberExpression) TypedDeclaration(org.eclipse.ceylon.model.typechecker.model.TypedDeclaration) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) Declaration(org.eclipse.ceylon.model.typechecker.model.Declaration) AttributeDeclaration(org.eclipse.ceylon.compiler.typechecker.tree.Tree.AttributeDeclaration) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) StaticMemberOrTypeExpression(org.eclipse.ceylon.compiler.typechecker.tree.Tree.StaticMemberOrTypeExpression)

Aggregations

Tree (org.eclipse.ceylon.compiler.typechecker.tree.Tree)3 StaticMemberOrTypeExpression (org.eclipse.ceylon.compiler.typechecker.tree.Tree.StaticMemberOrTypeExpression)3 Declaration (org.eclipse.ceylon.model.typechecker.model.Declaration)2 TypeDeclaration (org.eclipse.ceylon.model.typechecker.model.TypeDeclaration)2 TypedDeclaration (org.eclipse.ceylon.model.typechecker.model.TypedDeclaration)2 AttributeDeclaration (org.eclipse.ceylon.compiler.typechecker.tree.Tree.AttributeDeclaration)1 BaseMemberExpression (org.eclipse.ceylon.compiler.typechecker.tree.Tree.BaseMemberExpression)1 MemberOrTypeExpression (org.eclipse.ceylon.compiler.typechecker.tree.Tree.MemberOrTypeExpression)1 QualifiedMemberExpression (org.eclipse.ceylon.compiler.typechecker.tree.Tree.QualifiedMemberExpression)1 QualifiedTypeExpression (org.eclipse.ceylon.compiler.typechecker.tree.Tree.QualifiedTypeExpression)1 JCTree (org.eclipse.ceylon.langtools.tools.javac.tree.JCTree)1 JCExpression (org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCExpression)1 JCVariableDecl (org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCVariableDecl)1 ClassOrInterface (org.eclipse.ceylon.model.typechecker.model.ClassOrInterface)1 Constructor (org.eclipse.ceylon.model.typechecker.model.Constructor)1 Function (org.eclipse.ceylon.model.typechecker.model.Function)1 Interface (org.eclipse.ceylon.model.typechecker.model.Interface)1 Reference (org.eclipse.ceylon.model.typechecker.model.Reference)1 TypedReference (org.eclipse.ceylon.model.typechecker.model.TypedReference)1