Search in sources :

Example 1 with QualifiedMemberExpression

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

the class GenerateJsVisitor method visit.

@Override
public void visit(final Tree.NotOp that) {
    final Term t = that.getTerm();
    final boolean omitParens = t instanceof BaseMemberExpression || t instanceof QualifiedMemberExpression || t instanceof Tree.IsOp || t instanceof Tree.Exists || t instanceof Tree.IdenticalOp || t instanceof Tree.InOp || t instanceof Tree.Nonempty || (t instanceof Tree.InvocationExpression && ((Tree.InvocationExpression) t).getNamedArgumentList() == null);
    if (omitParens) {
        Operators.unaryOp(that, "!", null, this);
    } else {
        Operators.unaryOp(that, "(!", ")", this);
    }
}
Also used : QualifiedMemberExpression(org.eclipse.ceylon.compiler.typechecker.tree.Tree.QualifiedMemberExpression) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree) Term(org.eclipse.ceylon.compiler.typechecker.tree.Tree.Term) BaseMemberExpression(org.eclipse.ceylon.compiler.typechecker.tree.Tree.BaseMemberExpression)

Example 2 with QualifiedMemberExpression

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

the class GenerateJsVisitor method arithmeticAssignOp.

private boolean arithmeticAssignOp(final Tree.AssignmentOp that, final String operand) {
    final Term lhs = that.getLeftTerm();
    final Type ltype = lhs.getTypeModel();
    final Type rtype = that.getRightTerm().getTypeModel();
    final boolean oneFloat = ltype.isFloat() || rtype.isFloat();
    if (TypeUtils.intsOrFloats(ltype, rtype)) {
        if (lhs instanceof BaseMemberExpression) {
            BaseMemberExpression lhsBME = (BaseMemberExpression) lhs;
            Declaration lhsDecl = lhsBME.getDeclaration();
            final String getLHS = memberAccess(lhsBME, null);
            out("(");
            BmeGenerator.generateMemberAccess(lhsBME, new GenerateCallback() {

                @Override
                public void generateValue() {
                    if (oneFloat) {
                        out(getClAlias(), "Float(");
                    }
                    out(getLHS, operand);
                    if (!isNaturalLiteral(that.getRightTerm())) {
                        that.getRightTerm().visit(GenerateJsVisitor.this);
                    }
                    if (oneFloat) {
                        out(")");
                    }
                }
            }, null, this);
            if (!hasSimpleGetterSetter(lhsDecl)) {
                out(",", getLHS);
            }
            out(")");
        } else if (lhs instanceof QualifiedMemberExpression) {
            QualifiedMemberExpression lhsQME = (QualifiedMemberExpression) lhs;
            if (TypeUtils.isNativeJs(lhsQME)) {
                // ($1.foo = Box($1.foo).operator($2))
                final String tmp = names.createTempVariable();
                final String dec = isInDynamicBlock() && lhsQME.getDeclaration() == null ? lhsQME.getIdentifier().getText() : lhsQME.getDeclaration().getName();
                out("(", tmp, "=");
                lhsQME.getPrimary().visit(this);
                out(",", tmp, ".", dec, "=");
                int boxType = boxStart(lhsQME);
                out(tmp, ".", dec);
                if (boxType == 4)
                    out("/*TODO: callable targs 8*/");
                boxUnboxEnd(boxType);
                out(operand);
                if (!isNaturalLiteral(that.getRightTerm())) {
                    that.getRightTerm().visit(this);
                }
                out(")");
            } else {
                final String lhsPrimaryVar = createRetainedTempVar();
                final String getLHS = memberAccess(lhsQME, lhsPrimaryVar);
                out("(", lhsPrimaryVar, "=");
                lhsQME.getPrimary().visit(this);
                out(",");
                BmeGenerator.generateMemberAccess(lhsQME, new GenerateCallback() {

                    @Override
                    public void generateValue() {
                        out(getLHS, operand);
                        if (!isNaturalLiteral(that.getRightTerm())) {
                            that.getRightTerm().visit(GenerateJsVisitor.this);
                        }
                    }
                }, lhsPrimaryVar, this);
                if (!hasSimpleGetterSetter(lhsQME.getDeclaration())) {
                    out(",", getLHS);
                }
                out(")");
            }
        } else if (lhs instanceof Tree.IndexExpression) {
            lhs.addUnsupportedError("Index expressions are not supported in this kind of assignment.");
        }
        return true;
    }
    return false;
}
Also used : IntersectionType(org.eclipse.ceylon.model.typechecker.model.IntersectionType) Type(org.eclipse.ceylon.model.typechecker.model.Type) ExtendedType(org.eclipse.ceylon.compiler.typechecker.tree.Tree.ExtendedType) QualifiedMemberExpression(org.eclipse.ceylon.compiler.typechecker.tree.Tree.QualifiedMemberExpression) Term(org.eclipse.ceylon.compiler.typechecker.tree.Tree.Term) 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)

Example 3 with QualifiedMemberExpression

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

the class GenerateJsVisitor method assignOp.

private void assignOp(final Tree.AssignmentOp that, final String functionName, final Map<TypeParameter, Type> targs) {
    if (errVisitor.hasErrors(that))
        return;
    Term lhs = that.getLeftTerm();
    final boolean isNative = "||".equals(functionName) || "&&".equals(functionName);
    if (lhs instanceof BaseMemberExpression) {
        BaseMemberExpression lhsBME = (BaseMemberExpression) lhs;
        Declaration lhsDecl = lhsBME.getDeclaration();
        final String getLHS = memberAccess(lhsBME, null);
        out("(");
        BmeGenerator.generateMemberAccess(lhsBME, new GenerateCallback() {

            @Override
            public void generateValue() {
                if (isNative) {
                    out(getLHS, functionName);
                } else {
                    out(getLHS, ".", functionName, "(");
                }
                if (!isNaturalLiteral(that.getRightTerm())) {
                    that.getRightTerm().visit(GenerateJsVisitor.this);
                }
                if (!isNative) {
                    if (targs != null) {
                        out(",");
                        TypeUtils.printTypeArguments(that, targs, GenerateJsVisitor.this, false, null);
                    }
                    out(")");
                }
            }
        }, null, this);
        if (!hasSimpleGetterSetter(lhsDecl)) {
            out(",", getLHS);
        }
        out(")");
    } else if (lhs instanceof QualifiedMemberExpression) {
        QualifiedMemberExpression lhsQME = (QualifiedMemberExpression) lhs;
        if (TypeUtils.isNativeJs(lhsQME)) {
            // ($1.foo = Box($1.foo).operator($2))
            final String tmp = names.createTempVariable();
            final String dec = isInDynamicBlock() && lhsQME.getDeclaration() == null ? lhsQME.getIdentifier().getText() : lhsQME.getDeclaration().getName();
            out("(", tmp, "=");
            lhsQME.getPrimary().visit(this);
            out(",", tmp, ".", dec, "=");
            int boxType = boxStart(lhsQME);
            out(tmp, ".", dec);
            if (boxType == 4)
                out("/*TODO: callable targs 8*/");
            boxUnboxEnd(boxType);
            out(".", functionName, "(");
            if (!isNaturalLiteral(that.getRightTerm())) {
                that.getRightTerm().visit(this);
            }
            out("))");
        } else {
            final String lhsPrimaryVar = createRetainedTempVar();
            final String getLHS = memberAccess(lhsQME, lhsPrimaryVar);
            out("(", lhsPrimaryVar, "=");
            lhsQME.getPrimary().visit(this);
            out(",");
            BmeGenerator.generateMemberAccess(lhsQME, new GenerateCallback() {

                @Override
                public void generateValue() {
                    out(getLHS, ".", functionName, "(");
                    Tree.Term term = that.getRightTerm();
                    if (!isNaturalLiteral(term)) {
                        term.visit(GenerateJsVisitor.this);
                    }
                    out(")");
                }
            }, lhsPrimaryVar, this);
            if (!hasSimpleGetterSetter(lhsQME.getDeclaration())) {
                out(",", getLHS);
            }
            out(")");
        }
    } else if (lhs instanceof Tree.IndexExpression) {
        lhs.addUnsupportedError("Index expressions are not supported in this kind of assignment.");
    }
}
Also used : QualifiedMemberExpression(org.eclipse.ceylon.compiler.typechecker.tree.Tree.QualifiedMemberExpression) Term(org.eclipse.ceylon.compiler.typechecker.tree.Tree.Term) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree) Term(org.eclipse.ceylon.compiler.typechecker.tree.Tree.Term) 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)

Example 4 with QualifiedMemberExpression

use of org.eclipse.ceylon.compiler.typechecker.tree.Tree.QualifiedMemberExpression 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

BaseMemberExpression (org.eclipse.ceylon.compiler.typechecker.tree.Tree.BaseMemberExpression)4 QualifiedMemberExpression (org.eclipse.ceylon.compiler.typechecker.tree.Tree.QualifiedMemberExpression)4 Tree (org.eclipse.ceylon.compiler.typechecker.tree.Tree)3 AttributeDeclaration (org.eclipse.ceylon.compiler.typechecker.tree.Tree.AttributeDeclaration)3 Term (org.eclipse.ceylon.compiler.typechecker.tree.Tree.Term)3 Declaration (org.eclipse.ceylon.model.typechecker.model.Declaration)3 TypeDeclaration (org.eclipse.ceylon.model.typechecker.model.TypeDeclaration)3 TypedDeclaration (org.eclipse.ceylon.model.typechecker.model.TypedDeclaration)3 ExtendedType (org.eclipse.ceylon.compiler.typechecker.tree.Tree.ExtendedType)1 StaticMemberOrTypeExpression (org.eclipse.ceylon.compiler.typechecker.tree.Tree.StaticMemberOrTypeExpression)1 IntersectionType (org.eclipse.ceylon.model.typechecker.model.IntersectionType)1 Type (org.eclipse.ceylon.model.typechecker.model.Type)1