use of com.redhat.ceylon.compiler.java.codegen.recovery.TransformationPlan in project ceylon-compiler by ceylon.
the class CeylonVisitor method visit.
public void visit(Tree.AttributeDeclaration decl) {
TransformationPlan plan = gen.errors().hasDeclarationAndMarkBrokenness(decl);
if (plan instanceof Drop) {
return;
}
// To accept this method it is either not native, native for this
// backend or it's a native header with an implementation and there
// is no native implementation specifically for this backend
boolean accept = acceptDeclaration(decl);
if (!accept)
return;
int annots = gen.checkCompilerAnnotations(decl, defs);
if (Decl.withinClassOrInterface(decl) && !Decl.isLocalToInitializer(decl)) {
// Class attributes
gen.classGen().transform(decl, classBuilder);
} else if (Decl.isToplevel(decl)) {
topattrBuilder.add(decl);
} else if ((Decl.isLocal(decl)) && ((Decl.isCaptured(decl) && Decl.isVariable(decl)) || Decl.isTransient(decl) || Decl.hasSetter(decl))) {
// Captured local attributes get turned into an inner getter/setter class
appendList(gen.transform(decl));
} else {
// All other local attributes
appendList(gen.statementGen().transform(decl));
}
gen.resetCompilerAnnotations(annots);
}
use of com.redhat.ceylon.compiler.java.codegen.recovery.TransformationPlan in project ceylon-compiler by ceylon.
the class CeylonVisitor method visit.
public void visit(Tree.ObjectDefinition decl) {
TransformationPlan plan = gen.errors().hasDeclarationAndMarkBrokenness(decl);
if (plan instanceof Drop) {
return;
}
if (skipHeaderMergeLater(decl)) {
return;
}
// To accept this object it is either not native or native for this backend
if (!acceptDeclaration(decl))
return;
int annots = gen.checkCompilerAnnotations(decl, defs);
if (Decl.withinClass(decl)) {
classBuilder.defs(gen.classGen().transformObjectDefinition(decl, classBuilder));
} else {
appendList(gen.classGen().transformObjectDefinition(decl, null));
}
gen.resetCompilerAnnotations(annots);
}
use of com.redhat.ceylon.compiler.java.codegen.recovery.TransformationPlan in project ceylon-compiler by ceylon.
the class CeylonVisitor method visit.
public void visit(Tree.AttributeGetterDefinition decl) {
TransformationPlan plan = gen.errors().hasDeclarationAndMarkBrokenness(decl);
if (plan instanceof Drop) {
return;
}
if (!acceptDeclaration(decl))
return;
int annots = gen.checkCompilerAnnotations(decl, defs);
if (Decl.withinClass(decl) && !Decl.isLocalToInitializer(decl)) {
classBuilder.attribute(gen.classGen().transform(decl, false));
} else if (Decl.withinInterface(decl) && !Decl.isLocalToInitializer(decl)) {
classBuilder.attribute(gen.classGen().transform(decl, false));
AttributeDefinitionBuilder adb = gen.classGen().transform(decl, true);
if (decl.getDeclarationModel().isShared()) {
adb.ignoreAnnotations();
}
classBuilder.getCompanionBuilder((Interface) decl.getDeclarationModel().getContainer()).attribute(adb);
} else if (Decl.isToplevel(decl)) {
topattrBuilder.add(decl);
} else {
appendList(gen.transform(decl));
}
gen.resetCompilerAnnotations(annots);
}
use of com.redhat.ceylon.compiler.java.codegen.recovery.TransformationPlan in project ceylon-compiler by ceylon.
the class CeylonVisitor method visit.
public void visit(Tree.AnyMethod decl) {
TransformationPlan plan = gen.errors().hasDeclarationAndMarkBrokenness(decl);
if (plan instanceof Drop) {
return;
}
if (!acceptDeclaration(decl))
return;
int annots = gen.checkCompilerAnnotations(decl, defs);
if (Decl.withinClassOrInterface(decl) && (!Decl.isDeferred(decl) || Decl.isCaptured(decl))) {
classBuilder.method(decl, plan);
} else {
appendList(gen.classGen().transformWrappedMethod(decl, plan));
}
gen.resetCompilerAnnotations(annots);
}
use of com.redhat.ceylon.compiler.java.codegen.recovery.TransformationPlan in project ceylon-compiler by ceylon.
the class CeylonVisitor method transformConstructor.
private void transformConstructor(Tree.Declaration ctor, Tree.ParameterList parameterList, Tree.DelegatedConstructor delegatedCtor, Tree.Block block, Constructor ctorModel, Map<Constructor, CtorDelegation> delegates) {
TransformationPlan plan = gen.errors().hasDeclarationAndMarkBrokenness(ctor);
if (plan instanceof Drop) {
return;
}
if (parameterList != null) {
for (Parameter param : parameterList.getModel().getParameters()) {
if (Naming.aliasConstructorParameterName(param.getModel())) {
gen.naming.addVariableSubst(param.getModel(), gen.naming.suffixName(Suffix.$param$, param.getName()));
}
}
}
final CtorDelegation delegation = delegates.get(ctorModel);
ListBuffer<JCStatement> stmts = ListBuffer.lb();
boolean delegatedTo = CtorDelegation.isDelegatedTo(delegates, ctorModel);
if (delegatedTo && !ctorModel.isAbstract()) {
Tree.InvocationExpression chainedCtorInvocation;
if (delegatedCtor != null) {
chainedCtorInvocation = delegatedCtor.getInvocationExpression();
} else {
chainedCtorInvocation = null;
}
// We need to generate $delegation$ delegation constructor
makeDelegationConstructor(ctor, parameterList, delegatedCtor, block, ctorModel, delegation, chainedCtorInvocation);
JCStatement delegateExpr;
if (chainedCtorInvocation != null) {
delegateExpr = gen.expressionGen().transformConstructorDelegation(chainedCtorInvocation, delegation.isSelfDelegation() ? delegation : new CtorDelegation(ctorModel, ctorModel), chainedCtorInvocation, classBuilder, !delegation.isSelfDelegation());
} else {
// In this case there is no extends clause in the source code
// so we have to construct the argument list "by hand".
ListBuffer<JCExpression> arguments = ListBuffer.<JCExpression>lb();
for (TypeParameter tp : ((Class) delegation.getConstructor().getContainer()).getTypeParameters()) {
arguments.add(gen.makeReifiedTypeArgument(tp.getType()));
}
arguments.add(gen.naming.makeNamedConstructorName(delegation.getConstructor(), true));
for (Parameter p : delegation.getConstructor().getFirstParameterList().getParameters()) {
arguments.add(gen.naming.makeName(p.getModel(), Naming.NA_IDENT));
}
delegateExpr = gen.make().Exec(gen.make().Apply(null, gen.naming.makeThis(), arguments.toList()));
}
stmts.add(delegateExpr);
} else if (delegatedCtor != null) {
stmts.add(gen.expressionGen().transformConstructorDelegation(delegatedCtor, delegation, delegatedCtor.getInvocationExpression(), classBuilder, false));
} else {
// no explicit extends clause
}
final boolean addBody;
if (delegatedTo && (delegation.isAbstractSelfOrSuperDelegation())) {
if (delegation.getConstructor().isAbstract()) {
stmts.addAll(classBuilder.getInitBuilder().copyStatementsBetween(null, ctorModel));
addBody = true;
} else if (delegation.getExtendingConstructor() != null && delegation.getExtendingConstructor().isAbstract()) {
stmts.addAll(classBuilder.getInitBuilder().copyStatementsBetween(delegation.getExtendingConstructor(), ctorModel));
addBody = true;
} else {
addBody = false;
}
} else if (delegation.isAbstractSelfDelegation()) {
// delegating to abstract
stmts.addAll(classBuilder.getInitBuilder().copyStatementsBetween(delegation.getExtendingConstructor(), ctorModel));
addBody = true;
} else if (delegation.isConcreteSelfDelegation()) {
stmts.addAll(classBuilder.getInitBuilder().copyStatementsBetween(delegation.getExtendingConstructor(), ctorModel));
addBody = true;
} else {
// super delegation
stmts.addAll(classBuilder.getInitBuilder().copyStatementsBetween(null, ctorModel));
addBody = true;
}
if (ctorModel.isAbstract() && !delegatedTo) {
stmts.add(gen.make().Throw(gen.make().NewClass(null, List.<JCExpression>nil(), gen.make().QualIdent(gen.syms().ceylonUninvokableErrorType.tsym), List.<JCExpression>nil(), null)));
}
List<JCStatement> following = ctorModel.isAbstract() ? List.<JCStatement>nil() : classBuilder.getInitBuilder().copyStatementsBetween(ctorModel, null);
if (addBody) {
if (following.isEmpty()) {
stmts.addAll(gen.statementGen().transformBlock(block));
} else {
Name label = gen.naming.aliasName(Naming.Unfix.$return$.toString());
Transformer<JCStatement, Return> prev = gen.statementGen().returnTransformer(gen.statementGen().new ConstructorReturnTransformer(label));
try {
stmts.add(gen.make().Labelled(label, gen.make().DoLoop(gen.make().Block(0, gen.statementGen().transformBlock(block, true)), gen.make().Literal(false))));
} finally {
gen.statementGen().returnTransformer(prev);
}
}
}
ThrowVisitor visitor = new ThrowVisitor();
block.visit(visitor);
if (!visitor.getDefinitelyReturnsViaThrow()) {
stmts.addAll(following);
}
String ctorName = !Decl.isDefaultConstructor(ctorModel) ? gen.naming.makeTypeDeclarationName(ctorModel) : null;
classBuilder.defs(gen.classGen().makeNamedConstructor(ctor, parameterList, ctorModel, classBuilder, Strategy.generateInstantiator(ctorModel), gen.classGen().transformConstructorDeclFlags(ctorModel), false, ctorName, stmts.toList(), DeclNameFlag.QUALIFIED));
}
Aggregations