use of com.redhat.ceylon.compiler.java.codegen.recovery.HasErrorException in project ceylon-compiler by ceylon.
the class ClassTransformer method transformMethodBlock.
private List<JCStatement> transformMethodBlock(final Tree.MethodDefinition def) {
final Function model = def.getDeclarationModel();
final Tree.Block block = def.getBlock();
List<JCStatement> body;
boolean prevNoExpressionlessReturn = statementGen().noExpressionlessReturn;
try {
statementGen().noExpressionlessReturn = Decl.isMpl(model) || Strategy.useBoxedVoid(model);
body = statementGen().transformBlock(block);
} finally {
statementGen().noExpressionlessReturn = prevNoExpressionlessReturn;
}
// We void methods need to have their Callables return null
// so adjust here.
HasErrorException error = errors().getFirstErrorBlock(block);
if ((Decl.isMpl(model) || Strategy.useBoxedVoid(model)) && !block.getDefinitelyReturns() && error == null) {
if (Decl.isUnboxedVoid(model)) {
body = body.append(make().Return(makeNull()));
} else {
body = body.append(make().Return(makeErroneous(block, "compiler bug: non-void method doesn't definitely return")));
}
}
return body;
}
use of com.redhat.ceylon.compiler.java.codegen.recovery.HasErrorException in project ceylon-compiler by ceylon.
the class StatementTransformer method transformBlock.
public List<JCStatement> transformBlock(Tree.Block block, boolean revertRet) {
if (block == null) {
return List.<JCStatement>nil();
}
at(block);
CeylonVisitor v = gen().visitor;
final ListBuffer<JCTree> prevDefs = v.defs;
final boolean prevInInitializer = v.inInitializer;
final ClassDefinitionBuilder prevClassBuilder = v.classBuilder;
List<JCStatement> result;
try {
v.defs = new ListBuffer<JCTree>();
v.inInitializer = false;
v.classBuilder = current();
java.util.Iterator<Statement> statements = block.getStatements().iterator();
while (statements.hasNext()) {
Tree.Statement stmt = statements.next();
Transformer<JCStatement, Return> returnTransformer;
if (revertRet && stmt instanceof Tree.Declaration) {
returnTransformer = returnTransformer(defaultReturnTransformer);
} else {
returnTransformer = this.returnTransformer;
}
try {
HasErrorException error = errors().getFirstErrorBlock(stmt);
if (error == null) {
stmt.visit(v);
} else {
v.append(this.makeThrowUnresolvedCompilationError(error));
break;
}
} finally {
returnTransformer(returnTransformer);
}
}
result = (List<JCStatement>) v.getResult().toList();
} finally {
v.classBuilder = prevClassBuilder;
v.inInitializer = prevInInitializer;
v.defs = prevDefs;
// Close Substitutions which were scoped to this block
Scope scope = block.getScope();
while (scope instanceof ConditionScope) {
scope = scope.getScope();
}
naming.closeScopedSubstitutions(scope);
}
return result;
}
use of com.redhat.ceylon.compiler.java.codegen.recovery.HasErrorException in project ceylon-compiler by ceylon.
the class AbstractTransformer method makeSetterBlock.
JCBlock makeSetterBlock(TypedDeclaration declarationModel, final Tree.Block block, final Tree.SpecifierOrInitializerExpression expression) {
List<JCStatement> stats;
if (block != null) {
stats = statementGen().transformBlock(block);
} else {
Type type = declarationModel.getType();
JCStatement transStmt;
HasErrorException error = errors().getFirstExpressionErrorAndMarkBrokenness(expression.getExpression());
if (error != null) {
transStmt = this.makeThrowUnresolvedCompilationError(error);
} else {
transStmt = make().Exec(expressionGen().transformExpression(expression.getExpression(), BoxingStrategy.INDIFFERENT, type));
}
stats = List.<JCStatement>of(transStmt);
}
JCBlock setterBlock = make().Block(0, stats);
return setterBlock;
}
use of com.redhat.ceylon.compiler.java.codegen.recovery.HasErrorException in project ceylon-compiler by ceylon.
the class StatementTransformer method transform.
// FIXME There is a similar implementation in ClassGen!
public List<JCStatement> transform(Tree.AttributeDeclaration decl) {
ListBuffer<JCStatement> result = ListBuffer.<JCStatement>lb();
// If the attribute is really from a parameter then don't generate a local variable
Parameter parameter = CodegenUtil.findParamForDecl(decl);
if (parameter == null) {
final Name attrName = names().fromString(naming.substitute(decl.getDeclarationModel()));
Type t = decl.getDeclarationModel().getType();
JCExpression initialValue = null;
SpecifierOrInitializerExpression initOrSpec = decl.getSpecifierOrInitializerExpression();
if (initOrSpec != null) {
HasErrorException error = errors().getFirstExpressionErrorAndMarkBrokenness(initOrSpec.getExpression().getTerm());
if (error != null) {
return List.<JCStatement>of(this.makeThrowUnresolvedCompilationError(error));
}
initialValue = expressionGen().transformExpression(initOrSpec.getExpression(), CodegenUtil.getBoxingStrategy(decl.getDeclarationModel()), decl.getDeclarationModel().getType());
} else if (decl.getDeclarationModel().isVariable()) {
// Java's definite initialization doesn't always work
// so give variable attribute declarations without
// initializers a default value. See #1153.
initialValue = makeDefaultExprForType(t);
if (CodegenUtil.getBoxingStrategy(decl.getDeclarationModel()) == BoxingStrategy.BOXED && canUnbox(t)) {
initialValue = boxType(initialValue, t);
}
}
List<JCAnnotation> annots = List.<JCAnnotation>nil();
int modifiers = transformLocalFieldDeclFlags(decl);
JCExpression typeExpr = makeJavaType(decl.getDeclarationModel(), t, modifiers);
result.append(at(decl.getIdentifier()).VarDef(at(decl.getIdentifier()).Modifiers(modifiers, annots), attrName, typeExpr, initialValue));
JCStatement outerSubs = openOuterSubstitutionIfNeeded(decl.getDeclarationModel(), t, annots, modifiers);
if (outerSubs != null) {
result.append(outerSubs);
}
}
return result.toList();
}
use of com.redhat.ceylon.compiler.java.codegen.recovery.HasErrorException in project ceylon-compiler by ceylon.
the class AbstractTransformer method makeGetterBlock.
JCBlock makeGetterBlock(TypedDeclaration declarationModel, final Tree.Block block, final Tree.SpecifierOrInitializerExpression expression) {
List<JCStatement> stats;
if (block != null) {
stats = statementGen().transformBlock(block);
} else {
BoxingStrategy boxing = CodegenUtil.getBoxingStrategy(declarationModel);
Type type = declarationModel.getType();
JCStatement transStat;
HasErrorException error = errors().getFirstExpressionErrorAndMarkBrokenness(expression.getExpression());
if (error != null) {
transStat = this.makeThrowUnresolvedCompilationError(error);
} else {
transStat = make().Return(expressionGen().transformExpression(expression.getExpression(), boxing, type));
}
stats = List.<JCStatement>of(transStat);
}
JCBlock getterBlock = make().Block(0, stats);
return getterBlock;
}
Aggregations