Search in sources :

Example 96 with JCExpression

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())))));
}
Also used : JCExpression(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCExpression) JCTree(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree) SyntheticName(org.eclipse.ceylon.compiler.java.codegen.Naming.SyntheticName)

Example 97 with JCExpression

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);
    }
}
Also used : JCExpression(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCExpression) Term(org.eclipse.ceylon.compiler.typechecker.tree.Tree.Term) JCTree(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree)

Example 98 with JCExpression

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;
}
Also used : JCExpression(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCExpression)

Example 99 with JCExpression

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()))));
}
Also used : JCExpression(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCExpression) JCTree(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree) SyntheticName(org.eclipse.ceylon.compiler.java.codegen.Naming.SyntheticName)

Example 100 with JCExpression

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();
}
Also used : Type(org.eclipse.ceylon.model.typechecker.model.Type) JCExpression(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCExpression) Variable(org.eclipse.ceylon.compiler.typechecker.tree.Tree.Variable) ListBuffer(org.eclipse.ceylon.langtools.tools.javac.util.ListBuffer) CustomTree(org.eclipse.ceylon.compiler.typechecker.tree.CustomTree) JCTree(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree) JCCatch(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCCatch) JCVariableDecl(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCVariableDecl)

Aggregations

JCExpression (org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCExpression)224 JCTree (org.eclipse.ceylon.langtools.tools.javac.tree.JCTree)95 Type (org.eclipse.ceylon.model.typechecker.model.Type)95 Tree (org.eclipse.ceylon.compiler.typechecker.tree.Tree)74 JCStatement (org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCStatement)53 ListBuffer (org.eclipse.ceylon.langtools.tools.javac.util.ListBuffer)53 UnionType (org.eclipse.ceylon.model.typechecker.model.UnionType)45 SyntheticName (org.eclipse.ceylon.compiler.java.codegen.Naming.SyntheticName)41 TypeDeclaration (org.eclipse.ceylon.model.typechecker.model.TypeDeclaration)39 TypedDeclaration (org.eclipse.ceylon.model.typechecker.model.TypedDeclaration)38 Declaration (org.eclipse.ceylon.model.typechecker.model.Declaration)33 TypeParameter (org.eclipse.ceylon.model.typechecker.model.TypeParameter)32 Parameter (org.eclipse.ceylon.model.typechecker.model.Parameter)30 JCVariableDecl (org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCVariableDecl)28 Function (org.eclipse.ceylon.model.typechecker.model.Function)26 ClassOrInterface (org.eclipse.ceylon.model.typechecker.model.ClassOrInterface)22 Value (org.eclipse.ceylon.model.typechecker.model.Value)22 JCNewClass (org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCNewClass)21 FunctionOrValue (org.eclipse.ceylon.model.typechecker.model.FunctionOrValue)21 Class (org.eclipse.ceylon.model.typechecker.model.Class)17