Search in sources :

Example 1 with Symbol

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

the class Lower method visitEnumSwitch.

public JCTree visitEnumSwitch(JCSwitch tree) {
    TypeSymbol enumSym = tree.selector.type.tsym;
    EnumMapping map = mapForEnum(tree.pos(), enumSym);
    make_at(tree.pos());
    Symbol ordinalMethod = lookupMethod(tree.pos(), names.ordinal, tree.selector.type, List.<Type>nil());
    JCArrayAccess selector = make.Indexed(map.mapVar, make.App(make.Select(tree.selector, ordinalMethod)));
    ListBuffer<JCCase> cases = new ListBuffer<JCCase>();
    for (JCCase c : tree.cases) {
        if (c.pat != null) {
            VarSymbol label = (VarSymbol) TreeInfo.symbol(c.pat);
            JCLiteral pat = map.forConstant(label);
            cases.append(make.Case(pat, c.stats));
        } else {
            cases.append(c);
        }
    }
    JCSwitch enumSwitch = make.Switch(selector, cases.toList());
    patchTargets(enumSwitch, tree, enumSwitch);
    return enumSwitch;
}
Also used : Symbol(org.eclipse.ceylon.langtools.tools.javac.code.Symbol)

Example 2 with Symbol

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

the class Lower method assertFlagTest.

// This code is not particularly robust if the user has
// previously declared a member named '$assertionsDisabled'.
// The same faulty idiom also appears in the translation of
// class literals above.  We should report an error if a
// previous declaration is not synthetic.
private JCExpression assertFlagTest(DiagnosticPosition pos) {
    // Outermost class may be either true class or an interface.
    ClassSymbol outermostClass = outermostClassDef.sym;
    // only classes can hold a non-public field, look for a usable one:
    ClassSymbol container = !currentClass.isInterface() ? currentClass : assertionsDisabledClass();
    VarSymbol assertDisabledSym = (VarSymbol) lookupSynthetic(dollarAssertionsDisabled, container.members());
    if (assertDisabledSym == null) {
        assertDisabledSym = new VarSymbol(STATIC | FINAL | SYNTHETIC, dollarAssertionsDisabled, syms.booleanType, container);
        enterSynthetic(pos, assertDisabledSym, container.members());
        Symbol desiredAssertionStatusSym = lookupMethod(pos, names.desiredAssertionStatus, types.erasure(syms.classType), List.<Type>nil());
        JCClassDecl containerDef = classDef(container);
        make_at(containerDef.pos());
        JCExpression notStatus = makeUnary(NOT, make.App(make.Select(classOfType(types.erasure(outermostClass.type), containerDef.pos()), desiredAssertionStatusSym)));
        JCVariableDecl assertDisabledDef = make.VarDef(assertDisabledSym, notStatus);
        containerDef.defs = containerDef.defs.prepend(assertDisabledDef);
        if (currentClass.isInterface()) {
            // need to load the assertions enabled/disabled state while
            // initializing the interface:
            JCClassDecl currentClassDef = classDef(currentClass);
            make_at(currentClassDef.pos());
            JCStatement dummy = make.If(make.QualIdent(assertDisabledSym), make.Skip(), null);
            JCBlock clinit = make.Block(STATIC, List.<JCStatement>of(dummy));
            currentClassDef.defs = currentClassDef.defs.prepend(clinit);
        }
    }
    make_at(pos);
    return makeUnary(NOT, make.Ident(assertDisabledSym));
}
Also used : Symbol(org.eclipse.ceylon.langtools.tools.javac.code.Symbol)

Example 3 with Symbol

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

the class Lower method visitMethodDefInternal.

// where
private void visitMethodDefInternal(JCMethodDecl tree) {
    if (tree.name == names.init && (currentClass.isInner() || currentClass.isLocal())) {
        // We are seeing a constructor of an inner class.
        MethodSymbol m = tree.sym;
        // Push a new proxy scope for constructor parameters.
        // and create definitions for any this$n and proxy parameters.
        proxies = proxies.dup(m);
        List<VarSymbol> prevOuterThisStack = outerThisStack;
        List<VarSymbol> fvs = freevars(currentClass);
        JCVariableDecl otdef = null;
        if (currentClass.hasOuterInstance())
            otdef = outerThisDef(tree.pos, m);
        List<JCVariableDecl> fvdefs = freevarDefs(tree.pos, fvs, m, PARAMETER);
        // Recursively translate result type, parameters and thrown list.
        tree.restype = translate(tree.restype);
        tree.params = translateVarDefs(tree.params);
        tree.thrown = translate(tree.thrown);
        // when compiling stubs, don't process body
        if (tree.body == null) {
            result = tree;
            return;
        }
        // Add this$n (if needed) in front of and free variables behind
        // constructor parameter list.
        tree.params = tree.params.appendList(fvdefs);
        if (currentClass.hasOuterInstance())
            tree.params = tree.params.prepend(otdef);
        // If this is an initial constructor, i.e., it does not start with
        // this(...), insert initializers for this$n and proxies
        // before (pre-1.4, after) the call to superclass constructor.
        JCStatement selfCall = translate(tree.body.stats.head);
        List<JCStatement> added = List.nil();
        if (fvs.nonEmpty()) {
            List<Type> addedargtypes = List.nil();
            for (List<VarSymbol> l = fvs; l.nonEmpty(); l = l.tail) {
                if (TreeInfo.isInitialConstructor(tree)) {
                    final Name pName = proxyName(l.head.name);
                    m.capturedLocals = m.capturedLocals.append((VarSymbol) (proxies.lookup(pName).sym));
                    added = added.prepend(initField(tree.body.pos, pName));
                }
                addedargtypes = addedargtypes.prepend(l.head.erasure(types));
            }
            Type olderasure = m.erasure(types);
            m.erasure_field = new MethodType(olderasure.getParameterTypes().appendList(addedargtypes), olderasure.getReturnType(), olderasure.getThrownTypes(), syms.methodClass);
        }
        if (currentClass.hasOuterInstance() && TreeInfo.isInitialConstructor(tree)) {
            added = added.prepend(initOuterThis(tree.body.pos));
        }
        // pop local variables from proxy stack
        proxies = proxies.leave();
        // recursively translate following local statements and
        // combine with this- or super-call
        List<JCStatement> stats = translate(tree.body.stats.tail);
        if (target.initializeFieldsBeforeSuper())
            tree.body.stats = stats.prepend(selfCall).prependList(added);
        else
            tree.body.stats = stats.prependList(added).prepend(selfCall);
        outerThisStack = prevOuterThisStack;
    } else {
        Map<Symbol, Symbol> prevLambdaTranslationMap = lambdaTranslationMap;
        try {
            lambdaTranslationMap = (tree.sym.flags() & SYNTHETIC) != 0 && tree.sym.name.startsWith(names.lambda) ? makeTranslationMap(tree) : null;
            super.visitMethodDef(tree);
        } finally {
            lambdaTranslationMap = prevLambdaTranslationMap;
        }
    }
    result = tree;
}
Also used : Symbol(org.eclipse.ceylon.langtools.tools.javac.code.Symbol) Type(org.eclipse.ceylon.langtools.tools.javac.code.Type)

Example 4 with Symbol

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

the class Lower method makeCall.

// where
/**
 * Create an attributed tree of the form left.name().
 */
private JCMethodInvocation makeCall(JCExpression left, Name name, List<JCExpression> args) {
    Assert.checkNonNull(left.type);
    Symbol funcsym = lookupMethod(make_pos, name, left.type, TreeInfo.types(args));
    return make.App(make.Select(left, funcsym), args);
}
Also used : Symbol(org.eclipse.ceylon.langtools.tools.javac.code.Symbol)

Example 5 with Symbol

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

the class Lower method unbox.

/**
 * Unbox an object to a primitive value.
 */
JCExpression unbox(JCExpression tree, Type primitive) {
    Type unboxedType = types.unboxedType(tree.type);
    if (unboxedType.hasTag(NONE)) {
        unboxedType = primitive;
        if (!unboxedType.isPrimitive())
            throw new AssertionError(unboxedType);
        make_at(tree.pos());
        tree = make.TypeCast(types.boxedClass(unboxedType).type, tree);
    } else {
        // There must be a conversion from unboxedType to primitive.
        if (!types.isSubtype(unboxedType, primitive))
            throw new AssertionError(tree);
    }
    make_at(tree.pos());
    Symbol valueSym = lookupMethod(tree.pos(), // x.intValue()
    unboxedType.tsym.name.append(names.Value), tree.type, List.<Type>nil());
    return make.App(make.Select(tree, valueSym));
}
Also used : Type(org.eclipse.ceylon.langtools.tools.javac.code.Type) Symbol(org.eclipse.ceylon.langtools.tools.javac.code.Symbol)

Aggregations

Symbol (org.eclipse.ceylon.langtools.tools.javac.code.Symbol)115 Type (org.eclipse.ceylon.langtools.tools.javac.code.Type)42 ClassSymbol (org.eclipse.ceylon.langtools.tools.javac.code.Symbol.ClassSymbol)16 MethodSymbol (org.eclipse.ceylon.langtools.tools.javac.code.Symbol.MethodSymbol)15 VarSymbol (org.eclipse.ceylon.langtools.tools.javac.code.Symbol.VarSymbol)12 TypeSymbol (org.eclipse.ceylon.langtools.tools.javac.code.Symbol.TypeSymbol)11 JCTree (org.eclipse.ceylon.langtools.tools.javac.tree.JCTree)11 DeferredAttrContext (org.eclipse.ceylon.langtools.tools.javac.comp.DeferredAttr.DeferredAttrContext)8 DeferredType (org.eclipse.ceylon.langtools.tools.javac.comp.DeferredAttr.DeferredType)8 DiagnosticType (org.eclipse.ceylon.langtools.tools.javac.util.JCDiagnostic.DiagnosticType)8 DynamicMethodSymbol (org.eclipse.ceylon.langtools.tools.javac.code.Symbol.DynamicMethodSymbol)6 MethodType (org.eclipse.ceylon.langtools.tools.javac.code.Type.MethodType)6 JavaFileObject (org.eclipse.ceylon.javax.tools.JavaFileObject)5 DiagnosticPosition (org.eclipse.ceylon.langtools.tools.javac.util.JCDiagnostic.DiagnosticPosition)4 ErrorType (org.eclipse.ceylon.javax.lang.model.type.ErrorType)3 Scope (org.eclipse.ceylon.langtools.tools.javac.code.Scope)3 PackageSymbol (org.eclipse.ceylon.langtools.tools.javac.code.Symbol.PackageSymbol)3 HashSet (java.util.HashSet)2 LinkedList (java.util.LinkedList)2 DeclaredType (org.eclipse.ceylon.javax.lang.model.type.DeclaredType)2