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