use of org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCExpression in project ceylon by eclipse.
the class ExpressionTransformer method makeOptimizedInIntegerRange.
protected JCTree makeOptimizedInIntegerRange(Tree.InOp op, org.eclipse.ceylon.langtools.tools.javac.code.Type type) {
// x in y..z with x, y, z all Integer
org.eclipse.ceylon.langtools.tools.javac.code.Type ceylonType = syms().ceylonIntegerType;
Tree.RangeOp rangeOp = (Tree.RangeOp) op.getRightTerm();
JCExpression x = transformExpression(op.getLeftTerm(), BoxingStrategy.UNBOXED, typeFact().getObjectType());
JCExpression first = transformExpression(rangeOp.getLeftTerm(), BoxingStrategy.UNBOXED, rangeOp.getLeftTerm().getTypeModel());
JCExpression last = transformExpression(rangeOp.getRightTerm(), BoxingStrategy.UNBOXED, rangeOp.getRightTerm().getTypeModel());
SyntheticName xName = naming.temp("x");
SyntheticName firstName = naming.temp("y");
SyntheticName lastName = naming.temp("z");
SyntheticName recursiveName = naming.temp("recursive");
return make().LetExpr(List.<JCStatement>of(makeVar(xName, make().Type(type), x), makeVar(firstName, make().Type(type), first), makeVar(lastName, make().Type(type), last), makeVar(recursiveName, make().Type(syms().booleanType), make().Binary(JCTree.Tag.AND, make().Binary(JCTree.Tag.GT, firstName.makeIdent(), make().Binary(JCTree.Tag.PLUS, firstName.makeIdent(), make().Literal(1L))), make().Binary(JCTree.Tag.GT, make().Binary(JCTree.Tag.MINUS, lastName.makeIdent(), make().Literal(1L)), lastName.makeIdent())))), make().Conditional(recursiveName.makeIdent(), // x.offset(first) <= last.offset(first)
make().Binary(JCTree.Tag.LE, make().Apply(null, naming.makeSelect(make().QualIdent(ceylonType.tsym), "offset"), List.<JCExpression>of(xName.makeIdent(), firstName.makeIdent())), make().Apply(null, naming.makeSelect(make().QualIdent(ceylonType.tsym), "offset"), List.<JCExpression>of(lastName.makeIdent(), firstName.makeIdent()))), make().Binary(JCTree.Tag.OR, make().Binary(JCTree.Tag.AND, make().Binary(JCTree.Tag.LE, firstName.makeIdent(), xName.makeIdent()), make().Binary(JCTree.Tag.LE, xName.makeIdent(), lastName.makeIdent())), make().Binary(JCTree.Tag.AND, make().Binary(JCTree.Tag.LE, lastName.makeIdent(), xName.makeIdent()), make().Binary(JCTree.Tag.LE, xName.makeIdent(), firstName.makeIdent())))));
}
use of org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCExpression in project ceylon by eclipse.
the class ExpressionTransformer method transformInvocation.
public final JCExpression transformInvocation(final Invocation invocation) {
boolean prevFnCall = withinInvocation(true);
try {
final CallBuilder callBuilder = CallBuilder.instance(this);
if (invocation.getPrimary() instanceof Tree.StaticMemberOrTypeExpression) {
transformTypeArguments(callBuilder, (Tree.StaticMemberOrTypeExpression) invocation.getPrimary());
}
if (invocation instanceof CallableSpecifierInvocation) {
return transformCallableSpecifierInvocation(callBuilder, (CallableSpecifierInvocation) invocation);
} else {
at(invocation.getNode());
Tree.Term primary = Decl.unwrapExpressionsUntilTerm(invocation.getPrimary());
JCExpression result = transformTermForInvocation(primary, new InvocationTermTransformer(invocation, callBuilder));
return result;
}
} finally {
withinInvocation(prevFnCall);
}
}
use of org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCExpression in project ceylon by eclipse.
the class ExpressionTransformer method transformCallableSpecifierInvocation.
private JCExpression transformCallableSpecifierInvocation(CallBuilder callBuilder, CallableSpecifierInvocation invocation) {
at(invocation.getNode());
JCExpression result = callBuilder.invoke(naming.makeQuotedQualIdent(invocation.getCallable(), Naming.getCallableMethodName(invocation.getMethod()))).argumentsAndTypes(transformArguments(invocation, null, callBuilder)).build();
if (invocation.handleBoxing)
result = applyErasureAndBoxing(result, invocation.getReturnType(), invocation.erased, !invocation.unboxed, invocation.boxingStrategy, invocation.getReturnType(), 0);
return result;
}
use of org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCExpression in project ceylon by eclipse.
the class ExpressionTransformer method makeOptimizedInCharacterRange.
protected JCTree makeOptimizedInCharacterRange(Tree.InOp op) {
org.eclipse.ceylon.langtools.tools.javac.code.Type type = syms().intType;
org.eclipse.ceylon.langtools.tools.javac.code.Type ceylonType = syms().ceylonCharacterType;
// x in y..z with x, y, z all Character
Tree.RangeOp rangeOp = (Tree.RangeOp) op.getRightTerm();
JCExpression x = transformExpression(op.getLeftTerm(), BoxingStrategy.UNBOXED, typeFact().getObjectType());
JCExpression first = transformExpression(rangeOp.getLeftTerm(), BoxingStrategy.UNBOXED, rangeOp.getLeftTerm().getTypeModel());
JCExpression last = transformExpression(rangeOp.getRightTerm(), BoxingStrategy.UNBOXED, rangeOp.getRightTerm().getTypeModel());
SyntheticName xName = naming.temp("x");
SyntheticName firstName = naming.temp("first");
SyntheticName lastName = naming.temp("last");
SyntheticName recursiveName = naming.temp("recursive");
return make().LetExpr(List.<JCStatement>of(makeVar(xName, make().Type(type), x), makeVar(firstName, make().Type(type), first), makeVar(lastName, make().Type(type), last), // so we have to replicate that **short-circuit** logic here
makeVar(recursiveName, make().Type(syms().booleanType), make().Binary(JCTree.Tag.AND, make().Binary(JCTree.Tag.GT, firstName.makeIdent(), make().Apply(null, naming.makeSelect(make().QualIdent(ceylonType.tsym), "getSuccessor"), List.<JCExpression>of(firstName.makeIdent()))), make().Binary(JCTree.Tag.GT, make().Apply(null, naming.makeSelect(make().QualIdent(ceylonType.tsym), "getPredecessor"), List.<JCExpression>of(lastName.makeIdent())), lastName.makeIdent())))), make().Conditional(make().Binary(JCTree.Tag.LT, firstName.makeIdent(), lastName.makeIdent()), make().Binary(JCTree.Tag.AND, make().Binary(JCTree.Tag.LE, xName.makeIdent(), lastName.makeIdent()), make().Binary(JCTree.Tag.GE, xName.makeIdent(), firstName.makeIdent())), make().Binary(JCTree.Tag.AND, make().Binary(JCTree.Tag.GE, xName.makeIdent(), lastName.makeIdent()), make().Binary(JCTree.Tag.LE, xName.makeIdent(), firstName.makeIdent()))));
}
use of org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCExpression in project ceylon by eclipse.
the class StatementTransformer method transformCatchesPolymorphic.
/**
* Transforms a list of {@code CatchClause}s to a corresponding list
* of {@code JCCatch}.
* @see #transformCatchesIfElseIf(java.util.List)
*/
private List<JCCatch> transformCatchesPolymorphic(java.util.List<Tree.CatchClause> catchClauses) {
final ListBuffer<JCCatch> catches = new ListBuffer<JCCatch>();
for (Tree.CatchClause catchClause : catchClauses) {
at(catchClause);
Tree.Variable variable = catchClause.getCatchVariable().getVariable();
Type exceptionType = variable.getDeclarationModel().getType();
JCExpression type = makeJavaType(exceptionType, JT_CATCH);
JCVariableDecl param = make().VarDef(make().Modifiers(Flags.FINAL), names().fromString(variable.getIdentifier().getText()), type, null);
catches.add(make().Catch(param, transform(catchClause.getBlock())));
}
return catches.toList();
}
Aggregations