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