use of com.sun.tools.javac.tree.JCTree.JCVariableDecl in project ceylon-compiler by ceylon.
the class AbstractTransformer method makeLetExpr.
private JCExpression makeLetExpr(String varBaseName, List<JCStatement> statements, JCExpression... args) {
String varName = null;
ListBuffer<JCStatement> decls = ListBuffer.lb();
int i;
for (i = 0; (i + 1) < args.length; i += 2) {
JCExpression typeExpr = args[i];
JCExpression valueExpr = args[i + 1];
varName = varBaseName + ((args.length > 3) ? "$" + i : "");
JCVariableDecl varDecl = makeVar(varName, typeExpr, valueExpr);
decls.append(varDecl);
}
JCExpression result;
if (i == args.length) {
result = makeUnquotedIdent(varName);
} else {
result = args[i];
}
if (statements != null) {
decls.appendList(statements);
}
return make().LetExpr(decls.toList(), result);
}
use of com.sun.tools.javac.tree.JCTree.JCVariableDecl in project ceylon-compiler by ceylon.
the class ClassTransformer method transformWrappedMethod.
public List<JCTree> transformWrappedMethod(Tree.AnyMethod def, TransformationPlan plan) {
final Function model = def.getDeclarationModel();
if (model.isParameter()) {
return List.nil();
}
naming.clearSubstitutions(model);
// Generate a wrapper class for the method
String name = def.getIdentifier().getText();
ClassDefinitionBuilder builder = ClassDefinitionBuilder.methodWrapper(this, name, Decl.isShared(def));
if (Decl.isAnnotationConstructor(def)) {
AnnotationInvocation ai = ((AnnotationInvocation) def.getDeclarationModel().getAnnotationConstructor());
if (ai != null) {
builder.annotations(List.of(makeAtAnnotationInstantiation(ai)));
builder.annotations(makeExprAnnotations(def, ai));
}
}
builder.methods(classGen().transform(def, plan, builder));
// Toplevel method
if (Strategy.generateMain(def)) {
// Add a main() method
builder.method(makeMainForFunction(model));
}
if (Decl.isLocal(model) || Decl.isToplevel(model)) {
builder.annotations(makeAtLocalDeclarations(def));
}
if (Decl.isLocal(model)) {
builder.annotations(makeAtLocalDeclaration(model.getQualifier(), false));
}
List<JCTree> result = builder.build();
if (Decl.isLocal(def)) {
// Inner method
JCVariableDecl call = at(def).VarDef(make().Modifiers(FINAL), naming.getSyntheticInstanceName(model), naming.makeSyntheticClassname(model), makeSyntheticInstance(model));
result = result.append(call);
}
//}
return result;
}
use of com.sun.tools.javac.tree.JCTree.JCVariableDecl in project ceylon-compiler by ceylon.
the class ExpressionTransformer method transform.
public JCExpression transform(Tree.ScaleOp op) {
OperatorTranslation operator = Operators.getOperator(Tree.ScaleOp.class);
Tree.Term scalableTerm = op.getRightTerm();
Type scalableTermType = getSupertype(scalableTerm, typeFact().getScalableDeclaration());
SyntheticName scaleableName = naming.alias("scalable");
JCVariableDecl scaleable = makeVar(scaleableName, makeJavaType(scalableTermType, JT_NO_PRIMITIVES), transformExpression(scalableTerm, BoxingStrategy.BOXED, scalableTermType));
Tree.Term scaleTerm = op.getLeftTerm();
SyntheticName scaleName = naming.alias("scale");
Type scaleType = getTypeArgument(scalableTermType, 0);
JCExpression scaleValue;
if (isCeylonInteger(scaleTerm.getTypeModel()) && isCeylonFloat(scaleType)) {
// Disgusting coercion
scaleValue = transformExpression(scaleTerm, BoxingStrategy.UNBOXED, scalableTerm.getTypeModel());
scaleValue = boxType(scaleValue, typeFact().getFloatType());
} else {
scaleValue = transformExpression(scaleTerm, BoxingStrategy.BOXED, scaleType);
}
JCVariableDecl scale = makeVar(scaleName, makeJavaType(scaleType, JT_NO_PRIMITIVES), scaleValue);
at(op);
return make().LetExpr(List.<JCStatement>of(scale, scaleable), transformOverridableBinaryOperator(operator, OptimisationStrategy.NONE, scaleableName.makeIdent(), scaleName.makeIdent(), null, null, op.getTypeModel()));
}
Aggregations