Search in sources :

Example 6 with BaseMemberExpression

use of org.eclipse.ceylon.compiler.typechecker.tree.Tree.BaseMemberExpression 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)6 Tree (org.eclipse.ceylon.compiler.typechecker.tree.Tree)5 Declaration (org.eclipse.ceylon.model.typechecker.model.Declaration)5 TypeDeclaration (org.eclipse.ceylon.model.typechecker.model.TypeDeclaration)5 TypedDeclaration (org.eclipse.ceylon.model.typechecker.model.TypedDeclaration)5 AttributeDeclaration (org.eclipse.ceylon.compiler.typechecker.tree.Tree.AttributeDeclaration)4 QualifiedMemberExpression (org.eclipse.ceylon.compiler.typechecker.tree.Tree.QualifiedMemberExpression)4 Term (org.eclipse.ceylon.compiler.typechecker.tree.Tree.Term)4 ArrayList (java.util.ArrayList)2 ExtendedType (org.eclipse.ceylon.compiler.typechecker.tree.Tree.ExtendedType)2 StaticMemberOrTypeExpression (org.eclipse.ceylon.compiler.typechecker.tree.Tree.StaticMemberOrTypeExpression)2 Function (org.eclipse.ceylon.model.typechecker.model.Function)2 FunctionOrValue (org.eclipse.ceylon.model.typechecker.model.FunctionOrValue)2 IntersectionType (org.eclipse.ceylon.model.typechecker.model.IntersectionType)2 Parameter (org.eclipse.ceylon.model.typechecker.model.Parameter)2 ParameterList (org.eclipse.ceylon.model.typechecker.model.ParameterList)2 Type (org.eclipse.ceylon.model.typechecker.model.Type)2 TypeParameter (org.eclipse.ceylon.model.typechecker.model.TypeParameter)2 Value (org.eclipse.ceylon.model.typechecker.model.Value)2 LinkedList (java.util.LinkedList)1