Search in sources :

Example 96 with Type

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

the class Lower method accessSymbol.

/**
 * Return access symbol for a private or protected symbol from an inner class.
 *  @param sym        The accessed private symbol.
 *  @param tree       The accessing tree.
 *  @param enclOp     The closest enclosing operation node of tree,
 *                    null if tree is not a subtree of an operation.
 *  @param protAccess Is access to a protected symbol in another
 *                    package?
 *  @param refSuper   Is access via a (qualified) C.super?
 */
MethodSymbol accessSymbol(Symbol sym, JCTree tree, JCTree enclOp, boolean protAccess, boolean refSuper) {
    ClassSymbol accOwner = refSuper && protAccess ? // access symbol on T.
    (ClassSymbol) ((JCFieldAccess) tree).selected.type.tsym : // class which is a subclass of the symbol's owner.
    accessClass(sym, protAccess, tree);
    Symbol vsym = sym;
    if (sym.owner != accOwner) {
        vsym = sym.clone(accOwner);
        actualSymbols.put(vsym, sym);
    }
    // The access number of the access method.
    Integer anum = accessNums.get(vsym);
    if (anum == null) {
        anum = accessed.length();
        accessNums.put(vsym, anum);
        accessSyms.put(vsym, new MethodSymbol[NCODES]);
        accessed.append(vsym);
    // System.out.println("accessing " + vsym + " in " + vsym.location());
    }
    // The access code of the access method.
    int acode;
    // The argument types of the access method.
    List<Type> argtypes;
    // The result type of the access method.
    Type restype;
    // The thrown exceptions of the access method.
    List<Type> thrown;
    switch(vsym.kind) {
        case VAR:
            acode = accessCode(tree, enclOp);
            if (acode >= FIRSTASGOPcode) {
                OperatorSymbol operator = binaryAccessOperator(acode);
                if (operator.opcode == string_add)
                    argtypes = List.of(syms.objectType);
                else
                    argtypes = operator.type.getParameterTypes().tail;
            } else if (acode == ASSIGNcode)
                argtypes = List.of(vsym.erasure(types));
            else
                argtypes = List.nil();
            restype = vsym.erasure(types);
            thrown = List.nil();
            break;
        case MTH:
            acode = DEREFcode;
            argtypes = vsym.erasure(types).getParameterTypes();
            restype = vsym.erasure(types).getReturnType();
            thrown = vsym.type.getThrownTypes();
            break;
        default:
            throw new AssertionError();
    }
    // making it odd.
    if (protAccess && refSuper)
        acode++;
    // containing the access method.
    if ((vsym.flags() & STATIC) == 0) {
        argtypes = argtypes.prepend(vsym.owner.erasure(types));
    }
    MethodSymbol[] accessors = accessSyms.get(vsym);
    MethodSymbol accessor = accessors[acode];
    if (accessor == null) {
        accessor = new MethodSymbol(STATIC | SYNTHETIC, accessName(anum.intValue(), acode), new MethodType(argtypes, restype, thrown, syms.methodClass), accOwner);
        enterSynthetic(tree.pos(), accessor, accOwner.members());
        accessors[acode] = accessor;
    }
    return accessor;
}
Also used : Type(org.eclipse.ceylon.langtools.tools.javac.code.Type) Symbol(org.eclipse.ceylon.langtools.tools.javac.code.Symbol)

Example 97 with Type

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

the class Lower method boxArgs.

List<JCExpression> boxArgs(List<Type> parameters, List<JCExpression> _args, Type varargsElement) {
    List<JCExpression> args = _args;
    if (parameters.isEmpty())
        return args;
    boolean anyChanges = false;
    ListBuffer<JCExpression> result = new ListBuffer<JCExpression>();
    while (parameters.tail.nonEmpty()) {
        JCExpression arg = translate(args.head, parameters.head);
        anyChanges |= (arg != args.head);
        result.append(arg);
        args = args.tail;
        parameters = parameters.tail;
    }
    Type parameter = parameters.head;
    if (varargsElement != null) {
        anyChanges = true;
        ListBuffer<JCExpression> elems = new ListBuffer<JCExpression>();
        while (args.nonEmpty()) {
            JCExpression arg = translate(args.head, varargsElement);
            elems.append(arg);
            args = args.tail;
        }
        JCNewArray boxedArgs = make.NewArray(make.Type(varargsElement), List.<JCExpression>nil(), elems.toList());
        boxedArgs.type = new ArrayType(varargsElement, syms.arrayClass);
        result.append(boxedArgs);
    } else {
        if (args.length() != 1)
            throw new AssertionError(args);
        JCExpression arg = translate(args.head, parameter);
        anyChanges |= (arg != args.head);
        result.append(arg);
        if (!anyChanges)
            return _args;
    }
    return result.toList();
}
Also used : Type(org.eclipse.ceylon.langtools.tools.javac.code.Type)

Example 98 with Type

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

the class Lower method visitBinary.

public void visitBinary(JCBinary tree) {
    List<Type> formals = tree.operator.type.getParameterTypes();
    JCTree lhs = tree.lhs = translate(tree.lhs, formals.head);
    switch(tree.getTag()) {
        case OR:
            if (lhs.type.isTrue()) {
                result = lhs;
                return;
            }
            if (lhs.type.isFalse()) {
                result = translate(tree.rhs, formals.tail.head);
                return;
            }
            break;
        case AND:
            if (lhs.type.isFalse()) {
                result = lhs;
                return;
            }
            if (lhs.type.isTrue()) {
                result = translate(tree.rhs, formals.tail.head);
                return;
            }
            break;
    }
    tree.rhs = translate(tree.rhs, formals.tail.head);
    result = tree;
}
Also used : Type(org.eclipse.ceylon.langtools.tools.javac.code.Type) JCTree(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree)

Example 99 with Type

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

the class Lower method outerThisName.

/**
 * The name of a this$n field
 *  @param type   The class referenced by the this$n field
 */
Name outerThisName(Type type, Symbol owner) {
    Type t = type.getEnclosingType();
    int nestingLevel = 0;
    while (t.hasTag(CLASS)) {
        t = t.getEnclosingType();
        nestingLevel++;
    }
    Name result = names.fromString("this" + target.syntheticNameChar() + nestingLevel);
    while (owner.kind == TYP && ((ClassSymbol) owner).members().lookup(result).scope != null) result = names.fromString(result.toString() + target.syntheticNameChar());
    return result;
}
Also used : Type(org.eclipse.ceylon.langtools.tools.javac.code.Type)

Example 100 with Type

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

the class Lower method makeOuterThisVarSymbol.

private VarSymbol makeOuterThisVarSymbol(Symbol owner, long flags) {
    if (owner.kind == TYP && target.usePrivateSyntheticFields())
        flags |= PRIVATE;
    Type target = types.erasure(owner.enclClass().type.getEnclosingType());
    VarSymbol outerThis = new VarSymbol(flags, outerThisName(target, owner), target, owner);
    outerThisStack = outerThisStack.prepend(outerThis);
    return outerThis;
}
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