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(")");
}
Aggregations