Search in sources :

Example 71 with Value

use of org.eclipse.ceylon.model.typechecker.model.Value in project ceylon by eclipse.

the class ExpressionVisitor method setTypeForElseVariable.

private void setTypeForElseVariable(Tree.Variable var, Tree.Switched switched) {
    Type switchExpressionType = getSwitchedExpressionType(switched);
    Tree.SwitchCaseList switchCaseList = switchCaseList();
    if (switchExpressionType != null && switchCaseList != null) {
        if (!isTypeUnknown(switchExpressionType)) {
            Type caseUnionType = caseUnionType(switchCaseList);
            if (caseUnionType != null) {
                Type complementType = switchExpressionType.minus(caseUnionType);
                complementType = unit.denotableType(complementType);
                Value dec = var.getDeclarationModel();
                if (!isCompletelyVisible(dec, complementType)) {
                    complementType = switchExpressionType;
                }
                Tree.Type local = var.getType();
                local.setTypeModel(complementType);
                dec.setType(complementType);
                if (local instanceof Tree.LocalModifier && switchHasUncheckedNulls(switched) && caseUnionType.isSubtypeOf(unit.getObjectType())) {
                    handleUncheckedNulls((Tree.LocalModifier) local, complementType, // TODO!!!
                    switched.getExpression(), dec);
                } else {
                    dec.setUncheckedNullType(false);
                }
            }
        }
    }
}
Also used : ModelUtil.intersectionType(org.eclipse.ceylon.model.typechecker.model.ModelUtil.intersectionType) ModelUtil.unionType(org.eclipse.ceylon.model.typechecker.model.ModelUtil.unionType) AnalyzerUtil.spreadType(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.spreadType) AnalyzerUtil.getTupleType(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getTupleType) Type(org.eclipse.ceylon.model.typechecker.model.Type) UnknownType(org.eclipse.ceylon.model.typechecker.model.UnknownType) ModelUtil.appliedType(org.eclipse.ceylon.model.typechecker.model.ModelUtil.appliedType) ModelUtil.genericFunctionType(org.eclipse.ceylon.model.typechecker.model.ModelUtil.genericFunctionType) Value(org.eclipse.ceylon.model.typechecker.model.Value) FunctionOrValue(org.eclipse.ceylon.model.typechecker.model.FunctionOrValue) CustomTree(org.eclipse.ceylon.compiler.typechecker.tree.CustomTree) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree)

Example 72 with Value

use of org.eclipse.ceylon.model.typechecker.model.Value in project ceylon by eclipse.

the class ValueDeclarationImpl method applyInternal.

protected <Get, Set> ceylon.language.meta.model.Value<Get, Set> applyInternal(TypeDescriptor $reifiedGet, TypeDescriptor $reifiedSet, ceylon.language.meta.model.Type<?> container) {
    org.eclipse.ceylon.model.typechecker.model.Value modelDecl = (org.eclipse.ceylon.model.typechecker.model.Value) declaration;
    Type qType;
    if (getStatic()) {
        qType = ((ClassImpl) container).producedType;
    } else {
        qType = null;
    }
    org.eclipse.ceylon.model.typechecker.model.TypedReference typedReference = modelDecl.appliedTypedReference(qType, Collections.<Type>emptyList());
    org.eclipse.ceylon.model.typechecker.model.Type getType = typedReference.getType();
    TypeDescriptor reifiedGet = Metamodel.getTypeDescriptorForProducedType(getType);
    // immutable values have Set=Nothing
    org.eclipse.ceylon.model.typechecker.model.Type setType = getVariable() ? getType : modelDecl.getUnit().getNothingType();
    TypeDescriptor reifiedSet = getVariable() ? reifiedGet : TypeDescriptor.NothingType;
    Metamodel.checkReifiedTypeArgument("apply", "Value<$1,$2>", Variance.OUT, getType, $reifiedGet, Variance.IN, setType, $reifiedSet);
    return new ValueImpl<Get, Set>(reifiedGet, reifiedSet, this, typedReference, container, null);
}
Also used : Type(org.eclipse.ceylon.model.typechecker.model.Type) OpenType(ceylon.language.meta.declaration.OpenType) TypeDescriptor(org.eclipse.ceylon.compiler.java.runtime.model.TypeDescriptor) Value(org.eclipse.ceylon.model.typechecker.model.Value) Type(org.eclipse.ceylon.model.typechecker.model.Type) ValueImpl(org.eclipse.ceylon.compiler.java.runtime.metamodel.meta.ValueImpl) Value(org.eclipse.ceylon.model.typechecker.model.Value) Metamodel(org.eclipse.ceylon.compiler.java.runtime.metamodel.Metamodel)

Example 73 with Value

use of org.eclipse.ceylon.model.typechecker.model.Value in project ceylon by eclipse.

the class ForGenerator method generateForLoop.

/**
 * Generates code for the beginning of a "for" loop, returning the name of the variable used for the item.
 */
private String generateForLoop(Tree.ForIterator that, boolean hasElse, Set<Value> capturedValues) {
    final Tree.SpecifierExpression iterable = that.getSpecifierExpression();
    final String itemVar;
    boolean captured = false;
    if (that instanceof Tree.ValueIterator) {
        final Value val = ((Tree.ValueIterator) that).getVariable().getDeclarationModel();
        captured = val.isJsCaptured();
        if (captured) {
            itemVar = gen.getNames().createTempVariable();
            capturedValues.add(val);
        } else {
            itemVar = gen.getNames().name(val);
        }
    } else {
        itemVar = gen.getNames().createTempVariable();
    }
    boolean isNative = iterateNative(iterable.getExpression().getTerm(), itemVar);
    if (!isNative) {
        final boolean checkEntered = that.getUnit().isNonemptyIterableType(iterable.getExpression().getTerm().getTypeModel());
        if (hasElse || !optimize(iterable, itemVar)) {
            gen.out("var ", itemVar);
            if (checkEntered) {
                enteredVar = gen.getNames().createTempVariable();
                gen.out(",", enteredVar);
            }
            gen.out(";for(var ", iterVar, "=");
            iterable.visit(gen);
            gen.out(".iterator();(", itemVar, "=", iterVar, ".next())!==", gen.getClAlias(), "finished();)");
        }
        gen.beginBlock();
        if (enteredVar != null) {
            gen.out(enteredVar, "=true;");
        }
    }
    if (that instanceof Tree.ValueIterator) {
        if (captured) {
            gen.out("var ", gen.getNames().name(((Tree.ValueIterator) that).getVariable().getDeclarationModel()), "=", itemVar, ";");
        }
        directAccess.add(((Tree.ValueIterator) that).getVariable().getDeclarationModel());
    } else if (that instanceof Tree.PatternIterator) {
        gen.out("var ");
        Destructurer d = new Destructurer(((Tree.PatternIterator) that).getPattern(), gen, directAccess, itemVar, true, false);
        if (d.getCapturedValues() != null) {
            capturedValues.addAll(d.getCapturedValues());
        }
        gen.endLine(true);
    }
    return itemVar;
}
Also used : Value(org.eclipse.ceylon.model.typechecker.model.Value) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree)

Example 74 with Value

use of org.eclipse.ceylon.model.typechecker.model.Value in project ceylon by eclipse.

the class GenerateJsVisitor method visit.

@Override
public void visit(final Tree.ObjectDefinition that) {
    if (errVisitor.hasErrors(that))
        return;
    if (NativeUtil.isNativeHeader(that) && ModelUtil.getNativeDeclaration(that.getDeclarationModel(), Backend.JavaScript) != null) {
        // It's a native header, remember it for later when we deal with its implementation
        headers.put(that.getDeclarationModel().getQualifiedNameString(), that);
        return;
    }
    // To accept this object it is either not native or native for this backend
    if (!(NativeUtil.isForBackend(that, Backend.JavaScript) || NativeUtil.isHeaderWithoutBackend(that, Backend.JavaScript))) {
        return;
    }
    Value d = that.getDeclarationModel();
    if (!(opts.isOptimize() && d.isClassOrInterfaceMember())) {
        comment(that);
        Singletons.objectDefinition(that, this, null);
    } else {
        // Don't even bother with nodes that have errors
        if (errVisitor.hasErrors(that))
            return;
        Class c = (Class) d.getTypeDeclaration();
        // Skip static objects
        if (d.isStatic())
            return;
        comment(that);
        outerSelf(d);
        out(".", names.privateName(d), "=");
        outerSelf(d);
        out(".", names.name(c), "()");
        endLine(true);
    }
}
Also used : Value(org.eclipse.ceylon.model.typechecker.model.Value) FunctionOrValue(org.eclipse.ceylon.model.typechecker.model.FunctionOrValue) Class(org.eclipse.ceylon.model.typechecker.model.Class)

Example 75 with Value

use of org.eclipse.ceylon.model.typechecker.model.Value in project ceylon by eclipse.

the class GenerateJsVisitor method forgetCapturedValues.

void forgetCapturedValues(Set<Value> caps) {
    if (caps == null) {
        return;
    }
    for (Value v : caps) {
        directAccess.remove(v);
        names.forceName(v, null);
    }
}
Also used : Value(org.eclipse.ceylon.model.typechecker.model.Value) FunctionOrValue(org.eclipse.ceylon.model.typechecker.model.FunctionOrValue)

Aggregations

Value (org.eclipse.ceylon.model.typechecker.model.Value)190 FunctionOrValue (org.eclipse.ceylon.model.typechecker.model.FunctionOrValue)135 TypeDeclaration (org.eclipse.ceylon.model.typechecker.model.TypeDeclaration)77 Declaration (org.eclipse.ceylon.model.typechecker.model.Declaration)74 TypedDeclaration (org.eclipse.ceylon.model.typechecker.model.TypedDeclaration)70 Tree (org.eclipse.ceylon.compiler.typechecker.tree.Tree)69 Type (org.eclipse.ceylon.model.typechecker.model.Type)68 Function (org.eclipse.ceylon.model.typechecker.model.Function)50 TypeParameter (org.eclipse.ceylon.model.typechecker.model.TypeParameter)47 Class (org.eclipse.ceylon.model.typechecker.model.Class)46 Parameter (org.eclipse.ceylon.model.typechecker.model.Parameter)42 JavaBeanValue (org.eclipse.ceylon.model.loader.model.JavaBeanValue)30 ClassOrInterface (org.eclipse.ceylon.model.typechecker.model.ClassOrInterface)30 ArrayList (java.util.ArrayList)29 ParameterList (org.eclipse.ceylon.model.typechecker.model.ParameterList)29 FieldValue (org.eclipse.ceylon.model.loader.model.FieldValue)28 Constructor (org.eclipse.ceylon.model.typechecker.model.Constructor)27 Scope (org.eclipse.ceylon.model.typechecker.model.Scope)26 CustomTree (org.eclipse.ceylon.compiler.typechecker.tree.CustomTree)24 UnknownType (org.eclipse.ceylon.model.typechecker.model.UnknownType)23