Search in sources :

Example 1 with DynamicMethodSymbol

use of com.sun.tools.javac.code.Symbol.DynamicMethodSymbol in project ceylon-compiler by ceylon.

the class Attr method resolveIndyCall.

// 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;
}
Also used : MethodType(com.sun.tools.javac.code.Type.MethodType) ClassType(com.sun.tools.javac.code.Type.ClassType) MethodType(com.sun.tools.javac.code.Type.MethodType) WildcardType(com.sun.tools.javac.code.Type.WildcardType) Type(com.sun.tools.javac.code.Type) ArrayType(com.sun.tools.javac.code.Type.ArrayType) UnionClassType(com.sun.tools.javac.code.Type.UnionClassType) JCExpression(com.sun.tools.javac.tree.JCTree.JCExpression) ClassSymbol(com.sun.tools.javac.code.Symbol.ClassSymbol) TypeSymbol(com.sun.tools.javac.code.Symbol.TypeSymbol) Symbol(com.sun.tools.javac.code.Symbol) PackageSymbol(com.sun.tools.javac.code.Symbol.PackageSymbol) VarSymbol(com.sun.tools.javac.code.Symbol.VarSymbol) DynamicMethodSymbol(com.sun.tools.javac.code.Symbol.DynamicMethodSymbol) MethodSymbol(com.sun.tools.javac.code.Symbol.MethodSymbol) OperatorSymbol(com.sun.tools.javac.code.Symbol.OperatorSymbol) ListBuffer(com.sun.tools.javac.util.ListBuffer) DynamicMethodSymbol(com.sun.tools.javac.code.Symbol.DynamicMethodSymbol) Lint(com.sun.tools.javac.code.Lint)

Aggregations

Lint (com.sun.tools.javac.code.Lint)1 Symbol (com.sun.tools.javac.code.Symbol)1 ClassSymbol (com.sun.tools.javac.code.Symbol.ClassSymbol)1 DynamicMethodSymbol (com.sun.tools.javac.code.Symbol.DynamicMethodSymbol)1 MethodSymbol (com.sun.tools.javac.code.Symbol.MethodSymbol)1 OperatorSymbol (com.sun.tools.javac.code.Symbol.OperatorSymbol)1 PackageSymbol (com.sun.tools.javac.code.Symbol.PackageSymbol)1 TypeSymbol (com.sun.tools.javac.code.Symbol.TypeSymbol)1 VarSymbol (com.sun.tools.javac.code.Symbol.VarSymbol)1 Type (com.sun.tools.javac.code.Type)1 ArrayType (com.sun.tools.javac.code.Type.ArrayType)1 ClassType (com.sun.tools.javac.code.Type.ClassType)1 MethodType (com.sun.tools.javac.code.Type.MethodType)1 UnionClassType (com.sun.tools.javac.code.Type.UnionClassType)1 WildcardType (com.sun.tools.javac.code.Type.WildcardType)1 JCExpression (com.sun.tools.javac.tree.JCTree.JCExpression)1 ListBuffer (com.sun.tools.javac.util.ListBuffer)1