Search in sources :

Example 21 with Type

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

the class Attr method visitThrow.

public void visitThrow(JCThrow tree) {
    Type owntype = attribExpr(tree.expr, env, allowPoly ? Type.noType : syms.throwableType);
    if (allowPoly) {
        chk.checkType(tree, owntype, syms.throwableType);
    }
    result = null;
}
Also used : Type(org.eclipse.ceylon.langtools.tools.javac.code.Type)

Example 22 with Type

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

the class Attr method selectSym.

/*
    // Added by Ceylon
    private Symbol resolveIndyCall(JCTree tree,
                                   JCExpression indyReturnTypeExpression, List<JCExpression> indyParameterTypeExpressions,
                                   Name indyName,
                                   JCExpression bsmType, Name bsmName, List<Object> bsmStatic, 
                                   List<Type> parameterTypes){
        // build the list of static bsm arguments
        List<Type> bsm_staticArgs = List.of(syms.methodHandleLookupType,
                syms.stringType,
                syms.methodTypeType).appendList(bsmStaticArgToTypes(bsmStatic));

        // find the type of the bootstrap method class
        Type bsmSite = attribTree(bsmType, env, TYP, Infer.anyPoly);

        // find the bsm method
        Symbol bsm = rs.resolveInternalMethod(tree.pos(), env, bsmSite,
                                              bsmName, bsm_staticArgs, List.<Type>nil());

        if(!bsm.isStatic())
            log.error(tree.pos(), "ceylon", "Bootstrap method must be static: " + bsmName.toString());
        
        // find the type of the indy call
        Type indyReturnType = attribTree(indyReturnTypeExpression, env, TYP, Infer.anyPoly);
        ListBuffer<Type> indyParameterTypes = new ListBuffer<Type>();
        int c=0;
        List<Type> givenParameterTypes = parameterTypes;
        for(JCExpression expectedParamTypeExpr : indyParameterTypeExpressions){
            // also check that the parameter types we are passing to the method are compatible with the declared type
            Type givenParameterType = givenParameterTypes.head;
            if(givenParameterType == null) {
                log.error(tree.pos(), "ceylon", "Indy declared method expects more parameters than given. Expecting " + indyParameterTypeExpressions.size()
                        + ", but given " + c);
                return syms.errSymbol;
            }
            Type paramType = attribTree(expectedParamTypeExpr, env, TYP, Infer.anyPoly);
            if(!types.isAssignable(givenParameterType, paramType)) {
                log.error(tree.pos(), "ceylon", "Indy given method parameter "+c+" not compatible with expected parameter type: " + paramType
                        + ", but given " + givenParameterType);
                return syms.errSymbol;
            }
            indyParameterTypes.append(paramType);
            c++;
            givenParameterTypes = givenParameterTypes.tail;
        }
        if(!givenParameterTypes.isEmpty()) {
            log.error(tree.pos(), "ceylon", "Indy declared method expects less parameters than given. Expecting " + indyParameterTypeExpressions.size()
                    + ", but given " + parameterTypes.size());
            return syms.errSymbol;
        }
        
        MethodType indyType = new MethodType(indyParameterTypes.toList(), indyReturnType, List.<Type>nil(), syms.methodClass);
        
        // make an indy symbol for it
        DynamicMethodSymbol dynSym =
                new DynamicMethodSymbol(indyName,
                                        syms.noSymbol,
                                        bsm.isStatic() ?
                                            ClassFile.REF_invokeStatic :
                                            ClassFile.REF_invokeVirtual,
                                        (MethodSymbol)bsm,
                                        indyType,
                                        bsmStatic.toArray());
        return dynSym;
    }
    */
// where
/**
 * Determine symbol referenced by a Select expression,
 *
 *  @param tree   The select tree.
 *  @param site   The type of the selected expression,
 *  @param env    The current environment.
 *  @param resultInfo The current result.
 */
private Symbol selectSym(JCFieldAccess tree, Symbol location, Type site, Env<AttrContext> env, ResultInfo resultInfo) {
    DiagnosticPosition pos = tree.pos();
    Name name = tree.name;
    switch(site.getTag()) {
        case PACKAGE:
            return rs.accessBase(rs.findIdentInPackage(env, site.tsym, name, resultInfo.pkind), pos, location, site, name, true);
        case ARRAY:
        case CLASS:
            if (resultInfo.pt.hasTag(METHOD) || resultInfo.pt.hasTag(FORALL)) {
                return rs.resolveQualifiedMethod(pos, env, location, site, name, resultInfo.pt.getParameterTypes(), resultInfo.pt.getTypeArguments());
            } else if (name == names._this || name == names._super) {
                return rs.resolveSelf(pos, env, site.tsym, name);
            } else if (name == names._class) {
                // In this case, we have already made sure in
                // visitSelect that qualifier expression is a type.
                Type t = syms.classType;
                List<Type> typeargs = allowGenerics ? List.of(types.erasure(site)) : List.<Type>nil();
                t = new ClassType(t.getEnclosingType(), typeargs, t.tsym);
                return new VarSymbol(STATIC | PUBLIC | FINAL, names._class, t, site.tsym);
            } else {
                // We are seeing a plain identifier as selector.
                Symbol sym = rs.findIdentInType(env, site, name, resultInfo.pkind);
                if ((resultInfo.pkind & Kinds.ERRONEOUS) == 0)
                    sym = rs.accessBase(sym, pos, location, site, name, true);
                return sym;
            }
        case WILDCARD:
            throw new AssertionError(tree);
        case TYPEVAR:
            // Normally, site.getUpperBound() shouldn't be null.
            // It should only happen during memberEnter/attribBase
            // when determining the super type which *must* beac
            // done before attributing the type variables.  In
            // other words, we are seeing this illegal program:
            // class B<T> extends A<T.foo> {}
            Symbol sym = (site.getUpperBound() != null) ? selectSym(tree, location, capture(site.getUpperBound()), env, resultInfo) : null;
            if (sym == null) {
                log.error(pos, "type.var.cant.be.deref");
                return syms.errSymbol;
            } else {
                // Ceylon: relax the rules for private methods in wildcards, damnit, we want the private
                // method to be called, not any subtype's method we can't possibly know about, this is really
                // a lame Java decision.
                Symbol sym2 = (!sourceLanguage.isCeylon() && (sym.flags() & Flags.PRIVATE) != 0) ? rs.new AccessError(env, site, sym) : sym;
                rs.accessBase(sym2, pos, location, site, name, true);
                return sym;
            }
        case ERROR:
            // preserve identifier names through errors
            return types.createErrorType(name, site.tsym, site).tsym;
        default:
            // .class is allowed for these.
            if (name == names._class) {
                // In this case, we have already made sure in Select that
                // qualifier expression is a type.
                Type t = syms.classType;
                Type arg = types.boxedClass(site).type;
                t = new ClassType(t.getEnclosingType(), List.of(arg), t.tsym);
                return new VarSymbol(STATIC | PUBLIC | FINAL, names._class, t, site.tsym);
            } else {
                log.error(pos, "cant.deref", site);
                return syms.errSymbol;
            }
    }
}
Also used : Type(org.eclipse.ceylon.langtools.tools.javac.code.Type) DiagnosticPosition(org.eclipse.ceylon.langtools.tools.javac.util.JCDiagnostic.DiagnosticPosition) Symbol(org.eclipse.ceylon.langtools.tools.javac.code.Symbol)

Example 23 with Type

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

the class Attr method checkMethodIdInternal.

Type checkMethodIdInternal(JCTree tree, Type site, Symbol sym, Env<AttrContext> env, ResultInfo resultInfo) {
    if ((resultInfo.pkind & POLY) != 0) {
        Type pt = resultInfo.pt.map(deferredAttr.new RecoveryDeferredTypeMap(AttrMode.SPECULATIVE, sym, env.info.pendingResolutionPhase));
        Type owntype = checkIdInternal(tree, site, sym, pt, env, resultInfo);
        resultInfo.pt.map(deferredAttr.new RecoveryDeferredTypeMap(AttrMode.CHECK, sym, env.info.pendingResolutionPhase));
        return owntype;
    } else {
        return checkIdInternal(tree, site, sym, resultInfo.pt, env, resultInfo);
    }
}
Also used : Type(org.eclipse.ceylon.langtools.tools.javac.code.Type)

Example 24 with Type

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

the class Attr method visitBinary.

public void visitBinary(JCBinary tree) {
    // Attribute arguments.
    Type left = chk.checkNonVoid(tree.lhs.pos(), attribExpr(tree.lhs, env));
    Type right = chk.checkNonVoid(tree.lhs.pos(), attribExpr(tree.rhs, env));
    // Find operator.
    Symbol operator = tree.operator = rs.resolveBinaryOperator(tree.pos(), tree.getTag(), env, left, right);
    Type owntype = types.createErrorType(tree.type);
    if (operator.kind == MTH && !left.isErroneous() && !right.isErroneous()) {
        owntype = operator.type.getReturnType();
        // This will figure out when unboxing can happen and
        // choose the right comparison operator.
        int opc = chk.checkOperator(tree.lhs.pos(), (OperatorSymbol) operator, tree.getTag(), left, right);
        // If both arguments are constants, fold them.
        if (left.constValue() != null && right.constValue() != null) {
            Type ctype = cfolder.fold2(opc, left, right);
            if (ctype != null) {
                owntype = cfolder.coerce(ctype, owntype);
            }
        }
        // comparisons will not have an acmp* opc at this point.
        if ((opc == ByteCodes.if_acmpeq || opc == ByteCodes.if_acmpne)) {
            if (!types.isEqualityComparable(left, right, new Warner(tree.pos()))) {
                log.error(tree.pos(), "incomparable.types", left, right);
            }
        }
        chk.checkDivZero(tree.rhs.pos(), operator, right);
    }
    result = check(tree, owntype, VAL, resultInfo);
}
Also used : Type(org.eclipse.ceylon.langtools.tools.javac.code.Type) Symbol(org.eclipse.ceylon.langtools.tools.javac.code.Symbol)

Example 25 with Type

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

the class Attr method isBooleanOrNumeric.

// where
private boolean isBooleanOrNumeric(Env<AttrContext> env, JCExpression tree) {
    switch(tree.getTag()) {
        case LITERAL:
            return ((JCLiteral) tree).typetag.isSubRangeOf(DOUBLE) || ((JCLiteral) tree).typetag == BOOLEAN || ((JCLiteral) tree).typetag == BOT;
        case LAMBDA:
        case REFERENCE:
            return false;
        case PARENS:
            return isBooleanOrNumeric(env, ((JCParens) tree).expr);
        case CONDEXPR:
            JCConditional condTree = (JCConditional) tree;
            return isBooleanOrNumeric(env, condTree.truepart) && isBooleanOrNumeric(env, condTree.falsepart);
        case APPLY:
            JCMethodInvocation speculativeMethodTree = (JCMethodInvocation) deferredAttr.attribSpeculative(tree, env, unknownExprInfo);
            Type owntype = TreeInfo.symbol(speculativeMethodTree.meth).type.getReturnType();
            return types.unboxedTypeOrType(owntype).isPrimitive();
        case NEWCLASS:
            JCExpression className = removeClassParams.translate(((JCNewClass) tree).clazz);
            JCExpression speculativeNewClassTree = (JCExpression) deferredAttr.attribSpeculative(className, env, unknownTypeInfo);
            return types.unboxedTypeOrType(speculativeNewClassTree.type).isPrimitive();
        default:
            Type speculativeType = deferredAttr.attribSpeculative(tree, env, unknownExprInfo).type;
            speculativeType = types.unboxedTypeOrType(speculativeType);
            return speculativeType.isPrimitive();
    }
}
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