Search in sources :

Example 36 with JCTree

use of org.eclipse.ceylon.langtools.tools.javac.tree.JCTree in project ceylon by eclipse.

the class Gen method genCond.

/**
 * Derived visitor method: generate code for a boolean
 *  expression in a control-flow context.
 *  @param _tree         The expression to be visited.
 *  @param markBranches The flag to indicate that the condition is
 *                      a flow controller so produced conditions
 *                      should contain a proper tree to generate
 *                      CharacterRangeTable branches for them.
 */
public CondItem genCond(JCTree _tree, boolean markBranches) {
    JCTree inner_tree = TreeInfo.skipParens(_tree);
    if (inner_tree.hasTag(CONDEXPR)) {
        JCConditional tree = (JCConditional) inner_tree;
        CondItem cond = genCond(tree.cond, CRT_FLOW_CONTROLLER);
        if (cond.isTrue()) {
            code.resolve(cond.trueJumps);
            CondItem result = genCond(tree.truepart, CRT_FLOW_TARGET);
            if (markBranches)
                result.tree = tree.truepart;
            return result;
        }
        if (cond.isFalse()) {
            code.resolve(cond.falseJumps);
            CondItem result = genCond(tree.falsepart, CRT_FLOW_TARGET);
            if (markBranches)
                result.tree = tree.falsepart;
            return result;
        }
        Chain secondJumps = cond.jumpFalse();
        code.resolve(cond.trueJumps);
        CondItem first = genCond(tree.truepart, CRT_FLOW_TARGET);
        if (markBranches)
            first.tree = tree.truepart;
        Chain falseJumps = first.jumpFalse();
        code.resolve(first.trueJumps);
        Chain trueJumps = code.branch(goto_);
        code.resolve(secondJumps);
        CondItem second = genCond(tree.falsepart, CRT_FLOW_TARGET);
        CondItem result = items.makeCondItem(second.opcode, Code.mergeChains(trueJumps, second.trueJumps), Code.mergeChains(falseJumps, second.falseJumps));
        if (markBranches)
            result.tree = tree.falsepart;
        return result;
    } else {
        CondItem result = genExpr(_tree, syms.booleanType).mkCond();
        if (markBranches)
            result.tree = _tree;
        return result;
    }
}
Also used : JCTree(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree)

Example 37 with JCTree

use of org.eclipse.ceylon.langtools.tools.javac.tree.JCTree in project ceylon by eclipse.

the class JavacProcessingEnvironment method getTopLevelClasses.

private List<ClassSymbol> getTopLevelClasses(List<? extends JCCompilationUnit> units) {
    List<ClassSymbol> classes = List.nil();
    for (JCCompilationUnit unit : units) {
        for (JCTree node : unit.defs) {
            if (node.hasTag(JCTree.Tag.CLASSDEF)) {
                ClassSymbol sym = ((JCClassDecl) node).sym;
                Assert.checkNonNull(sym);
                classes = classes.prepend(sym);
            }
        }
    }
    return classes.reverse();
}
Also used : JCTree(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree)

Example 38 with JCTree

use of org.eclipse.ceylon.langtools.tools.javac.tree.JCTree in project ceylon by eclipse.

the class Pretty method visitVarDef.

public void visitVarDef(JCVariableDecl tree) {
    try {
        if ((tree.mods.flags & ENUM) != 0) {
            print("/*public static final*/ ");
            print(tree.name);
            if (tree.init != null) {
                if (sourceOutput && tree.init.hasTag(NEWCLASS)) {
                    print(" /*enum*/ ");
                    JCNewClass init = (JCNewClass) tree.init;
                    if (init.args != null && init.args.nonEmpty()) {
                        print("(");
                        print(init.args);
                        print(")");
                    }
                    if (init.def != null && init.def.defs != null) {
                        print(" ");
                        printBlock(init.def.defs);
                    }
                    return;
                }
                print(" /* = ");
                printExpr(tree.init);
                print(" */");
            }
        } else {
            printExpr(tree.mods);
            if ((tree.mods.flags & VARARGS) != 0) {
                JCTree vartype = tree.vartype;
                List<JCAnnotation> tas = null;
                if (vartype instanceof JCAnnotatedType) {
                    tas = ((JCAnnotatedType) vartype).annotations;
                    vartype = ((JCAnnotatedType) vartype).underlyingType;
                }
                printExpr(((JCArrayTypeTree) vartype).elemtype);
                if (tas != null) {
                    print(' ');
                    printTypeAnnotations(tas);
                }
                print("... " + tree.name);
            } else {
                printExpr(tree.vartype);
                print(" " + tree.name);
            }
            if (tree.init != null) {
                print(" = ");
                printExpr(tree.init);
            }
            if (prec == TreeInfo.notExpression)
                print(";");
        }
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
Also used : JCTree(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree)

Example 39 with JCTree

use of org.eclipse.ceylon.langtools.tools.javac.tree.JCTree in project ceylon by eclipse.

the class Pretty method printBrackets.

// prints the brackets of a nested array in reverse order
// tree is either JCArrayTypeTree or JCAnnotatedTypeTree
private void printBrackets(JCTree tree) throws IOException {
    JCTree elem = tree;
    while (true) {
        if (elem.hasTag(ANNOTATED_TYPE)) {
            JCAnnotatedType atype = (JCAnnotatedType) elem;
            elem = atype.underlyingType;
            if (elem.hasTag(TYPEARRAY)) {
                print(' ');
                printTypeAnnotations(atype.annotations);
            }
        }
        if (elem.hasTag(TYPEARRAY)) {
            print("[]");
            elem = ((JCArrayTypeTree) elem).elemtype;
        } else {
            break;
        }
    }
}
Also used : JCTree(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree)

Example 40 with JCTree

use of org.eclipse.ceylon.langtools.tools.javac.tree.JCTree in project ceylon by eclipse.

the class TreeCopier method visitCompoundAssignment.

public JCTree visitCompoundAssignment(CompoundAssignmentTree node, P p) {
    JCAssignOp t = (JCAssignOp) node;
    JCTree lhs = copy(t.lhs, p);
    JCTree rhs = copy(t.rhs, p);
    return M.at(t.pos).Assignop(t.getTag(), lhs, rhs);
}
Also used : JCTree(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree)

Aggregations

JCTree (org.eclipse.ceylon.langtools.tools.javac.tree.JCTree)101 JCExpression (org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCExpression)19 Tree (org.eclipse.ceylon.compiler.typechecker.tree.Tree)18 Symbol (org.eclipse.ceylon.langtools.tools.javac.code.Symbol)12 JCVariableDecl (org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCVariableDecl)10 JCStatement (org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCStatement)9 JavaFileObject (org.eclipse.ceylon.javax.tools.JavaFileObject)8 Type (org.eclipse.ceylon.langtools.tools.javac.code.Type)8 JCNewClass (org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCNewClass)8 ListBuffer (org.eclipse.ceylon.langtools.tools.javac.util.ListBuffer)8 SyntheticName (org.eclipse.ceylon.compiler.java.codegen.Naming.SyntheticName)7 Type (org.eclipse.ceylon.model.typechecker.model.Type)6 JCAnnotation (org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCAnnotation)5 JCBlock (org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCBlock)4 JCClassDecl (org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCClassDecl)4 JCCompilationUnit (org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCCompilationUnit)4 JCPrimitiveTypeTree (org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCPrimitiveTypeTree)4 TypedDeclaration (org.eclipse.ceylon.model.typechecker.model.TypedDeclaration)4 IOException (java.io.IOException)3 TaskEvent (org.eclipse.ceylon.langtools.source.util.TaskEvent)3