use of com.redhat.ceylon.compiler.typechecker.tree.Tree in project ceylon-compiler by ceylon.
the class StatementTransformer method transform.
/**
* Transforms a Ceylon destructuring assignment to Java code.
* @param stmt The Ceylon destructure
* @return The Java tree
*/
List<JCVariableDecl> transform(Tree.Destructure stmt) {
List<JCVariableDecl> result = List.nil();
// Create temp var to hold result of expression
Tree.Pattern pat = stmt.getPattern();
Naming.SyntheticName tmpVarName = naming.synthetic(pat);
Expression destExpr = stmt.getSpecifierExpression().getExpression();
JCExpression typeExpr = makeJavaType(destExpr.getTypeModel());
JCExpression expr = expressionGen().transformExpression(destExpr);
at(stmt);
JCVariableDecl tmpVar = makeVar(Flags.FINAL, tmpVarName, typeExpr, expr);
result = result.append(tmpVar);
// Now add the destructured variables
List<JCVariableDecl> vars = VarDefBuilder.buildAll(transformPattern(pat, tmpVarName.makeIdent()));
result = result.appendList(vars);
return result;
}
use of com.redhat.ceylon.compiler.typechecker.tree.Tree in project ceylon-compiler by ceylon.
the class StatementTransformer method getDocAnnotationText.
private String getDocAnnotationText(Tree.Assertion ass) {
String docText = null;
Tree.Annotation doc = getAnnotation(ass.getAnnotationList(), "doc");
if (doc != null) {
Tree.Expression expression = null;
if (doc.getPositionalArgumentList() != null) {
Tree.PositionalArgument arg = doc.getPositionalArgumentList().getPositionalArguments().get(0);
if (arg instanceof Tree.ListedArgument)
expression = ((Tree.ListedArgument) arg).getExpression();
else
throw new BugException(arg, "argument to doc annotation cannot be a spread argument or comprehension: " + arg);
} else if (doc.getNamedArgumentList() != null) {
Tree.SpecifiedArgument arg = (Tree.SpecifiedArgument) doc.getNamedArgumentList().getNamedArguments().get(0);
expression = arg.getSpecifierExpression().getExpression();
} else {
// Impossible on a well-formed tree
return null;
}
Tree.Literal literal = (Tree.Literal) expression.getTerm();
docText = literal.getText();
} else if (ass.getAnnotationList() != null && ass.getAnnotationList().getAnonymousAnnotation() != null) {
docText = ass.getAnnotationList().getAnonymousAnnotation().getStringLiteral().getText();
}
return docText;
}
use of com.redhat.ceylon.compiler.typechecker.tree.Tree in project ceylon-compiler by ceylon.
the class BoxingVisitor method visit.
@Override
public void visit(Tree.IfExpression that) {
super.visit(that);
if (that.getIfClause() == null || that.getElseClause() == null)
return;
Tree.Expression ifExpr = that.getIfClause().getExpression();
Tree.Expression elseExpr = that.getElseClause().getExpression();
if (ifExpr == null || elseExpr == null)
return;
if (CodegenUtil.isUnBoxed(ifExpr) && CodegenUtil.isUnBoxed(elseExpr) && !willEraseToObject(that.getUnit().denotableType(that.getTypeModel())))
CodegenUtil.markUnBoxed(that);
if (that.getTypeModel().isExactly(that.getUnit().getNullValueDeclaration().getType())) {
CodegenUtil.markTypeErased(that);
}
// An If expression can never be raw, type erased or untrusted because
// it uses a Let with a new variable declaration, so the rawness,
// erasedness and untrustedness of its branches cannot propagate further
// up the tree.
}
use of com.redhat.ceylon.compiler.typechecker.tree.Tree in project ceylon-compiler by ceylon.
the class BoxingVisitor method visit.
@Override
public void visit(Tree.SwitchExpression that) {
super.visit(that);
SwitchCaseList caseList = that.getSwitchCaseList();
if (caseList == null || caseList.getCaseClauses() == null)
return;
boolean unboxed = true;
for (Tree.CaseClause caseClause : caseList.getCaseClauses()) {
Expression expr = caseClause.getExpression();
if (expr == null)
return;
// a single boxed one makes the whole switch boxed
if (!CodegenUtil.isUnBoxed(expr))
unboxed = false;
// A Switch expression can never be raw, type erased or untrusted because
// it uses a Let with a new variable declaration, so the rawness,
// erasedness and untrustedness of its branches cannot propagate further
// up the tree.
}
if (caseList.getElseClause() != null) {
Expression expr = caseList.getElseClause().getExpression();
if (expr == null)
return;
// a single boxed one makes the whole switch boxed
if (!CodegenUtil.isUnBoxed(expr))
unboxed = false;
// see comment about about why we don't propagate rawness etc here.
}
if (unboxed && !willEraseToObject(that.getUnit().denotableType(that.getTypeModel())))
CodegenUtil.markUnBoxed(that);
if (that.getTypeModel().isExactly(that.getUnit().getNullValueDeclaration().getType())) {
CodegenUtil.markTypeErased(that);
}
}
Aggregations