Search in sources :

Example 96 with JCVariableDecl

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);
}
Also used : JCExpression(com.sun.tools.javac.tree.JCTree.JCExpression) JCStatement(com.sun.tools.javac.tree.JCTree.JCStatement) JCVariableDecl(com.sun.tools.javac.tree.JCTree.JCVariableDecl)

Example 97 with JCVariableDecl

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;
}
Also used : Function(com.redhat.ceylon.model.typechecker.model.Function) JCTree(com.sun.tools.javac.tree.JCTree) JCVariableDecl(com.sun.tools.javac.tree.JCTree.JCVariableDecl)

Example 98 with JCVariableDecl

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()));
}
Also used : Type(com.redhat.ceylon.model.typechecker.model.Type) JCExpression(com.sun.tools.javac.tree.JCTree.JCExpression) Term(com.redhat.ceylon.compiler.typechecker.tree.Tree.Term) JCTree(com.sun.tools.javac.tree.JCTree) Tree(com.redhat.ceylon.compiler.typechecker.tree.Tree) SyntheticName(com.redhat.ceylon.compiler.java.codegen.Naming.SyntheticName) JCVariableDecl(com.sun.tools.javac.tree.JCTree.JCVariableDecl) AssignmentOperatorTranslation(com.redhat.ceylon.compiler.java.codegen.Operators.AssignmentOperatorTranslation) OperatorTranslation(com.redhat.ceylon.compiler.java.codegen.Operators.OperatorTranslation)

Aggregations

JCVariableDecl (com.sun.tools.javac.tree.JCTree.JCVariableDecl)98 JCExpression (com.sun.tools.javac.tree.JCTree.JCExpression)56 JCStatement (com.sun.tools.javac.tree.JCTree.JCStatement)36 JCTree (com.sun.tools.javac.tree.JCTree)31 JCMethodDecl (com.sun.tools.javac.tree.JCTree.JCMethodDecl)31 Name (com.sun.tools.javac.util.Name)31 JCBlock (com.sun.tools.javac.tree.JCTree.JCBlock)27 JavacNode (lombok.javac.JavacNode)27 ListBuffer (com.sun.tools.javac.util.ListBuffer)25 JCTypeParameter (com.sun.tools.javac.tree.JCTree.JCTypeParameter)24 JCClassDecl (com.sun.tools.javac.tree.JCTree.JCClassDecl)22 JCModifiers (com.sun.tools.javac.tree.JCTree.JCModifiers)18 JavacTreeMaker (lombok.javac.JavacTreeMaker)18 Tree (com.redhat.ceylon.compiler.typechecker.tree.Tree)13 JCAnnotation (com.sun.tools.javac.tree.JCTree.JCAnnotation)12 Type (com.redhat.ceylon.model.typechecker.model.Type)11 SyntheticName (com.redhat.ceylon.compiler.java.codegen.Naming.SyntheticName)9 JCMethodInvocation (com.sun.tools.javac.tree.JCTree.JCMethodInvocation)9 JCPrimitiveTypeTree (com.sun.tools.javac.tree.JCTree.JCPrimitiveTypeTree)8 Type (com.sun.tools.javac.code.Type)7