Search in sources :

Example 51 with Type

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

the class ClassReader method readField.

/**
 **********************************************************************
 * Reading Symbols
 **********************************************************************
 */
/**
 * Read a field.
 */
VarSymbol readField() {
    long flags = adjustFieldFlags(nextChar());
    Name name = readName(nextChar());
    Type type = readType(nextChar());
    VarSymbol v = new VarSymbol(flags, name, type, currentOwner);
    readMemberAttrs(v);
    return v;
}
Also used : Type(org.eclipse.ceylon.langtools.tools.javac.code.Type)

Example 52 with Type

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

the class ClassReader method readEnclosingMethodAttr.

protected void readEnclosingMethodAttr(Symbol sym) {
    // sym is a nested class with an "Enclosing Method" attribute
    // remove sym from it's current owners scope and place it in
    // the scope specified by the attribute
    sym.owner.members().remove(sym);
    ClassSymbol self = (ClassSymbol) sym;
    ClassSymbol c = readClassSymbol(nextChar());
    NameAndType nt = readNameAndType(nextChar());
    if (c.members_field == null)
        throw badClassFile("bad.enclosing.class", self, c);
    MethodSymbol m = findMethod(nt, c.members_field, self.flags());
    if (nt != null && m == null)
        throw badClassFile("bad.enclosing.method", self);
    self.name = simpleBinaryName(self.flatname, c.flatname);
    self.owner = m != null ? m : c;
    if (self.name.isEmpty())
        self.fullname = names.empty;
    else
        self.fullname = ClassSymbol.formFullName(self.name, self.owner);
    if (m != null) {
        ((ClassType) sym.type).setEnclosingType(m.type);
    } else if ((self.flags_field & STATIC) == 0) {
        ((ClassType) sym.type).setEnclosingType(c.type);
    } else {
        ((ClassType) sym.type).setEnclosingType(Type.noType);
    }
    enterTypevars(self);
    if (!missingTypeVariables.isEmpty()) {
        ListBuffer<Type> typeVars = new ListBuffer<Type>();
        for (Type typevar : missingTypeVariables) {
            typeVars.append(findTypeVar(typevar.tsym.name));
        }
        foundTypeVariables = typeVars.toList();
    } else {
        foundTypeVariables = List.nil();
    }
}
Also used : Type(org.eclipse.ceylon.langtools.tools.javac.code.Type)

Example 53 with Type

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

the class Infer method checkWithinBounds.

// </editor-fold>
// <editor-fold defaultstate="collapsed" desc="Bound checking">
/**
 * Check bounds and perform incorporation
 */
void checkWithinBounds(InferenceContext inferenceContext, Warner warn) throws InferenceException {
    MultiUndetVarListener mlistener = new MultiUndetVarListener(inferenceContext.undetvars);
    List<Type> saved_undet = inferenceContext.save();
    try {
        while (true) {
            mlistener.reset();
            if (!allowGraphInference) {
                // cannot be run in parallel with other incoprporation rounds
                for (Type t : inferenceContext.undetvars) {
                    UndetVar uv = (UndetVar) t;
                    IncorporationStep.CHECK_BOUNDS.apply(uv, inferenceContext, warn);
                }
            }
            for (Type t : inferenceContext.undetvars) {
                UndetVar uv = (UndetVar) t;
                // bound incorporation
                EnumSet<IncorporationStep> incorporationSteps = allowGraphInference ? incorporationStepsGraph : incorporationStepsLegacy;
                for (IncorporationStep is : incorporationSteps) {
                    if (is.accepts(uv, inferenceContext)) {
                        is.apply(uv, inferenceContext, warn);
                    }
                }
            }
            if (!mlistener.changed || !allowGraphInference)
                break;
        }
    } finally {
        mlistener.detach();
        if (incorporationCache.size() == MAX_INCORPORATION_STEPS) {
            inferenceContext.rollback(saved_undet);
        }
        incorporationCache.clear();
    }
}
Also used : Type(org.eclipse.ceylon.langtools.tools.javac.code.Type)

Example 54 with Type

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

the class Infer method instantiateAsUninferredVars.

/**
 * Infer cyclic inference variables as described in 15.12.2.8.
 */
private void instantiateAsUninferredVars(List<Type> vars, InferenceContext inferenceContext) {
    ListBuffer<Type> todo = new ListBuffer<>();
    // step 1 - create fresh tvars
    for (Type t : vars) {
        UndetVar uv = (UndetVar) inferenceContext.asUndetVar(t);
        List<Type> upperBounds = uv.getBounds(InferenceBound.UPPER);
        if (Type.containsAny(upperBounds, vars)) {
            TypeSymbol fresh_tvar = new TypeVariableSymbol(Flags.SYNTHETIC, uv.qtype.tsym.name, null, uv.qtype.tsym.owner);
            fresh_tvar.type = new TypeVar(fresh_tvar, types.makeIntersectionType(uv.getBounds(InferenceBound.UPPER)), null);
            todo.append(uv);
            uv.inst = fresh_tvar.type;
        } else if (upperBounds.nonEmpty()) {
            uv.inst = types.glb(upperBounds);
        } else {
            uv.inst = syms.objectType;
        }
    }
    // step 2 - replace fresh tvars in their bounds
    List<Type> formals = vars;
    for (Type t : todo) {
        UndetVar uv = (UndetVar) t;
        TypeVar ct = (TypeVar) uv.inst;
        ct.bound = types.glb(inferenceContext.asInstTypes(types.getBounds(ct)));
        if (ct.bound.isErroneous()) {
            // report inference error if glb fails
            reportBoundError(uv, BoundErrorKind.BAD_UPPER);
        }
        formals = formals.tail;
    }
}
Also used : Type(org.eclipse.ceylon.langtools.tools.javac.code.Type)

Example 55 with Type

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

the class Infer method instantiatePolymorphicSignatureInstance.

/**
 * Compute a synthetic method type corresponding to the requested polymorphic
 * method signature. The target return type is computed from the immediately
 * enclosing scope surrounding the polymorphic-signature call.
 */
Type instantiatePolymorphicSignatureInstance(Env<AttrContext> env, // sig. poly. method or null if none
MethodSymbol spMethod, Resolve.MethodResolutionContext resolveContext, List<Type> argtypes) {
    final Type restype;
    switch(env.next.tree.getTag()) {
        case TYPECAST:
            JCTypeCast castTree = (JCTypeCast) env.next.tree;
            restype = (TreeInfo.skipParens(castTree.expr) == env.tree) ? castTree.clazz.type : syms.objectType;
            break;
        case EXEC:
            JCTree.JCExpressionStatement execTree = (JCTree.JCExpressionStatement) env.next.tree;
            restype = (TreeInfo.skipParens(execTree.expr) == env.tree) ? syms.voidType : syms.objectType;
            break;
        default:
            restype = syms.objectType;
    }
    List<Type> paramtypes = Type.map(argtypes, new ImplicitArgType(spMethod, resolveContext.step));
    List<Type> exType = spMethod != null ? spMethod.getThrownTypes() : // make it throw all exceptions
    List.of(syms.throwableType);
    MethodType mtype = new MethodType(paramtypes, restype, exType, syms.methodClass);
    return mtype;
}
Also used : Type(org.eclipse.ceylon.langtools.tools.javac.code.Type) JCTypeCast(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCTypeCast) JCTree(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree)

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