Search in sources :

Example 81 with Type

use of org.eclipse.ceylon.langtools.tools.javac.code.Type in project ceylon by eclipse.

the class Gen method appendString.

/**
 * Append value (on tos) to string buffer (on tos - 1).
 */
void appendString(JCTree tree) {
    Type t = tree.type.baseType();
    if (!t.isPrimitive() && t.tsym != syms.stringType.tsym) {
        t = syms.objectType;
    }
    items.makeMemberItem(getStringBufferAppend(tree, t), false).invoke();
}
Also used : Type(org.eclipse.ceylon.langtools.tools.javac.code.Type)

Example 82 with Type

use of org.eclipse.ceylon.langtools.tools.javac.code.Type in project ceylon by eclipse.

the class Gen method initCode.

private int initCode(JCMethodDecl tree, Env<GenContext> env, boolean fatcode) {
    MethodSymbol meth = tree.sym;
    // Create a new code structure.
    meth.code = code = new Code(meth, fatcode, lineDebugInfo ? toplevel.lineMap : null, varDebugInfo, stackMap, debugCode, genCrt ? new CRTable(tree, env.toplevel.endPositions) : null, syms, types, pool);
    items = new Items(pool, code, syms, types);
    if (code.debugCode) {
        System.err.println(meth + " for body " + tree);
    }
    // for `this'.
    if ((tree.mods.flags & STATIC) == 0) {
        Type selfType = meth.owner.type;
        if (meth.isConstructor() && selfType != syms.objectType)
            selfType = UninitializedType.uninitializedThis(selfType);
        code.setDefined(code.newLocal(new VarSymbol(FINAL, names._this, selfType, meth.owner)));
    }
    // the method.
    for (List<JCVariableDecl> l = tree.params; l.nonEmpty(); l = l.tail) {
        checkDimension(l.head.pos(), l.head.sym.type);
        code.setDefined(code.newLocal(l.head.sym));
    }
    // Get ready to generate code for method body.
    int startpcCrt = genCrt ? code.curCP() : 0;
    code.entryPoint();
    // Suppress initial stackmap
    code.pendingStackMap = false;
    return startpcCrt;
}
Also used : Type(org.eclipse.ceylon.langtools.tools.javac.code.Type) Items(org.eclipse.ceylon.langtools.tools.javac.jvm.Items) Code(org.eclipse.ceylon.langtools.tools.javac.jvm.Code)

Example 83 with Type

use of org.eclipse.ceylon.langtools.tools.javac.code.Type in project ceylon by eclipse.

the class Gen method visitNewArray.

public void visitNewArray(JCNewArray tree) {
    setTypeAnnotationPositions(tree.pos);
    if (tree.elems != null) {
        Type elemtype = types.elemtype(tree.type);
        loadIntConst(tree.elems.length());
        Item arr = makeNewArray(tree.pos(), tree.type, 1);
        int i = 0;
        for (List<JCExpression> l = tree.elems; l.nonEmpty(); l = l.tail) {
            arr.duplicate();
            loadIntConst(i);
            i++;
            genExpr(l.head, elemtype).load();
            items.makeIndexedItem(elemtype).store();
        }
        result = arr;
    } else {
        for (List<JCExpression> l = tree.dims; l.nonEmpty(); l = l.tail) {
            genExpr(l.head, syms.intType).load();
        }
        result = makeNewArray(tree.pos(), tree.type, tree.dims.length());
    }
}
Also used : Type(org.eclipse.ceylon.langtools.tools.javac.code.Type)

Example 84 with Type

use of org.eclipse.ceylon.langtools.tools.javac.code.Type in project ceylon by eclipse.

the class Gen method genExpr.

/**
 * Visitor method: generate code for an expression, catching and reporting
 *  any completion failures.
 *  @param tree    The expression to be visited.
 *  @param pt      The expression's expected type (proto-type).
 */
public Item genExpr(JCTree tree, Type pt) {
    Type prevPt = this.pt;
    try {
        if (tree.type.constValue() != null) {
            // Short circuit any expressions which are constants
            tree.accept(classReferenceVisitor);
            checkStringConstant(tree.pos(), tree.type.constValue());
            result = items.makeImmediateItem(tree.type, tree.type.constValue());
        } else {
            this.pt = pt;
            tree.accept(this);
        }
        return result.coerce(pt);
    } catch (CompletionFailure ex) {
        chk.completionError(tree.pos(), ex);
        code.state.stacksize = 1;
        return items.makeStackItem(pt);
    } finally {
        this.pt = prevPt;
    }
}
Also used : Type(org.eclipse.ceylon.langtools.tools.javac.code.Type)

Example 85 with Type

use of org.eclipse.ceylon.langtools.tools.javac.code.Type in project ceylon by eclipse.

the class TreeMaker method Type.

/**
 * Create a tree representing given type.
 */
public JCExpression Type(Type t) {
    if (t == null)
        return null;
    JCExpression tp;
    switch(t.getTag()) {
        case BYTE:
        case CHAR:
        case SHORT:
        case INT:
        case LONG:
        case FLOAT:
        case DOUBLE:
        case BOOLEAN:
        case VOID:
            tp = TypeIdent(t.getTag());
            break;
        case TYPEVAR:
            tp = Ident(t.tsym);
            break;
        case WILDCARD:
            {
                WildcardType a = ((WildcardType) t);
                tp = Wildcard(TypeBoundKind(a.kind), Type(a.type));
                break;
            }
        case CLASS:
            Type outer = t.getEnclosingType();
            JCExpression clazz = outer.hasTag(CLASS) && t.tsym.owner.kind == TYP ? Select(Type(outer), t.tsym) : QualIdent(t.tsym);
            tp = t.getTypeArguments().isEmpty() ? clazz : TypeApply(clazz, Types(t.getTypeArguments()));
            break;
        case ARRAY:
            tp = TypeArray(Type(types.elemtype(t)));
            break;
        case ERROR:
            tp = TypeIdent(ERROR);
            break;
        default:
            throw new AssertionError("unexpected type: " + t);
    }
    return tp.setType(t);
}
Also used : Type(org.eclipse.ceylon.langtools.tools.javac.code.Type)

Aggregations

Type (org.eclipse.ceylon.langtools.tools.javac.code.Type)164 Symbol (org.eclipse.ceylon.langtools.tools.javac.code.Symbol)46 DeferredType (org.eclipse.ceylon.langtools.tools.javac.comp.DeferredAttr.DeferredType)13 DiagnosticType (org.eclipse.ceylon.langtools.tools.javac.util.JCDiagnostic.DiagnosticType)13 ArrayType (org.eclipse.ceylon.langtools.tools.javac.code.Type.ArrayType)10 MethodType (org.eclipse.ceylon.langtools.tools.javac.code.Type.MethodType)10 ClassSymbol (org.eclipse.ceylon.langtools.tools.javac.code.Symbol.ClassSymbol)9 JCTree (org.eclipse.ceylon.langtools.tools.javac.tree.JCTree)9 MethodSymbol (org.eclipse.ceylon.langtools.tools.javac.code.Symbol.MethodSymbol)8 JavaFileObject (org.eclipse.ceylon.javax.tools.JavaFileObject)7 TypeSymbol (org.eclipse.ceylon.langtools.tools.javac.code.Symbol.TypeSymbol)7 DiagnosticPosition (org.eclipse.ceylon.langtools.tools.javac.util.JCDiagnostic.DiagnosticPosition)7 JavacType (org.eclipse.ceylon.compiler.java.loader.mirror.JavacType)5 PackageSymbol (org.eclipse.ceylon.langtools.tools.javac.code.Symbol.PackageSymbol)5 FunctionalInterfaceType (org.eclipse.ceylon.model.loader.mirror.FunctionalInterfaceType)5 UnknownType (org.eclipse.ceylon.model.typechecker.model.UnknownType)5 HashSet (java.util.HashSet)4 CompletionFailure (org.eclipse.ceylon.langtools.tools.javac.code.Symbol.CompletionFailure)4 VarSymbol (org.eclipse.ceylon.langtools.tools.javac.code.Symbol.VarSymbol)4 FreeTypeListener (org.eclipse.ceylon.langtools.tools.javac.comp.Infer.FreeTypeListener)4