Search in sources :

Example 21 with Value

use of com.redhat.ceylon.model.typechecker.model.Value in project ceylon-compiler by ceylon.

the class StatementTransformer method closeInnerSubstituionsForSpecifiedValues.

/**
     * Removes the "inner substitutions" for any deferred values specified 
     * in the given control block
     */
private void closeInnerSubstituionsForSpecifiedValues(Tree.ControlClause contolClause) {
    if (contolClause != null) {
        ControlBlock controlBlock = contolClause.getControlBlock();
        java.util.Set<Value> assigned = controlBlock.getSpecifiedValues();
        if (assigned != null) {
            for (Value value : assigned) {
                DeferredSpecification ds = statementGen().getDeferredSpecification(value);
                if (ds != null) {
                    ds.closeInnerSubstitution();
                }
            }
        }
    }
}
Also used : ControlBlock(com.redhat.ceylon.model.typechecker.model.ControlBlock) Value(com.redhat.ceylon.model.typechecker.model.Value)

Example 22 with Value

use of com.redhat.ceylon.model.typechecker.model.Value in project ceylon-compiler by ceylon.

the class LocalTypeVisitor method visit.

@Override
public void visit(Tree.AttributeGetterDefinition that) {
    Value model = that.getDeclarationModel();
    collect(that, model);
    // stop at locals, who get a type generated for them
    if (model.isMember())
        super.visit(that);
}
Also used : Value(com.redhat.ceylon.model.typechecker.model.Value)

Example 23 with Value

use of com.redhat.ceylon.model.typechecker.model.Value in project ceylon-compiler by ceylon.

the class MethodDefinitionBuilder method getNonWideningParam.

public NonWideningParam getNonWideningParam(TypedReference typedRef, WideningRules wideningRules) {
    TypedDeclaration nonWideningDecl = null;
    int flags = 0;
    Type nonWideningType;
    FunctionOrValue mov = (FunctionOrValue) typedRef.getDeclaration();
    if (Decl.isValue(mov)) {
        TypedReference nonWideningTypedRef = gen.nonWideningTypeDecl(typedRef);
        nonWideningType = gen.nonWideningType(typedRef, nonWideningTypedRef);
        nonWideningDecl = nonWideningTypedRef.getDeclaration();
    } else {
        // Stef: So here's the thing. I know this is wrong for Function where we should do getFullType(), BUT
        // lots of methods call this and then feed the output into AT.makeJavaType(TypedDeclaration typeDecl, Type type, int flags)
        // which adds the Callable type, so if we fix it here we have to remove it from there and there's lots of callers of that
        // function which rely on its behaviour and frankly I've had enough of this refactoring, so a few callers of this function
        // have to add the Callable back. It sucks, yeah, but so far it works, which is amazing enough that I don't want to touch it
        // any more. More ambitious/courageous people are welcome to fix this properly.
        nonWideningType = typedRef.getType();
        nonWideningDecl = mov;
    }
    if (!CodegenUtil.isUnBoxed(nonWideningDecl))
        flags |= AbstractTransformer.JT_NO_PRIMITIVES;
    // make sure we don't accidentally narrow value parameters that would be erased in the topmost declaration
    if (wideningRules != WideningRules.NONE && mov instanceof Value) {
        TypedDeclaration refinedParameter = (TypedDeclaration) CodegenUtil.getTopmostRefinedDeclaration(mov);
        // mixin bridge methods have the same rules as when refining stuff except they are their own refined decl
        if (wideningRules == WideningRules.FOR_MIXIN || !Decl.equal(refinedParameter, mov)) {
            Type refinedParameterType;
            // in the refined parameter type
            if (refinedParameter instanceof Function)
                refinedParameterType = refinedParameter.appliedTypedReference(null, Collections.<Type>emptyList()).getFullType();
            else
                refinedParameterType = refinedParameter.getType();
            // if the supertype method itself got erased to Object, we can't do better than this
            if (gen.willEraseToObject(refinedParameterType) && !gen.willEraseToBestBounds(mov))
                nonWideningType = gen.typeFact().getObjectType();
            else if (CodegenUtil.isRaw(refinedParameter)) {
                flags |= AbstractTransformer.JT_RAW;
            } else {
                flags |= AbstractTransformer.JT_NARROWED;
            }
        }
    }
    // keep in sync with gen.willEraseToBestBounds()
    if (wideningRules != WideningRules.NONE && (gen.typeFact().isUnion(nonWideningType) || gen.typeFact().isIntersection(nonWideningType))) {
        final Type refinedType = ((TypedDeclaration) CodegenUtil.getTopmostRefinedDeclaration(nonWideningDecl)).getType();
        if (refinedType.isTypeParameter() && !refinedType.getSatisfiedTypes().isEmpty()) {
            nonWideningType = refinedType.getSatisfiedTypes().get(0);
            // Could be parameterized, and type param won't be in scope, so have to go raw
            flags |= AbstractTransformer.JT_RAW;
        }
    }
    // this is to be done on the parameter's containing method, to see if that method must have raw parameters
    if (mov.isParameter() && mov.getContainer() instanceof Declaration && gen.rawParameters((Declaration) mov.getContainer())) {
        flags |= AbstractTransformer.JT_RAW;
    }
    return new NonWideningParam(flags, nonWideningType, nonWideningDecl);
}
Also used : TypedDeclaration(com.redhat.ceylon.model.typechecker.model.TypedDeclaration) Function(com.redhat.ceylon.model.typechecker.model.Function) Type(com.redhat.ceylon.model.typechecker.model.Type) TypedReference(com.redhat.ceylon.model.typechecker.model.TypedReference) FunctionOrValue(com.redhat.ceylon.model.typechecker.model.FunctionOrValue) Value(com.redhat.ceylon.model.typechecker.model.Value) TypedDeclaration(com.redhat.ceylon.model.typechecker.model.TypedDeclaration) Declaration(com.redhat.ceylon.model.typechecker.model.Declaration) TypeDeclaration(com.redhat.ceylon.model.typechecker.model.TypeDeclaration) FunctionOrValue(com.redhat.ceylon.model.typechecker.model.FunctionOrValue)

Example 24 with Value

use of com.redhat.ceylon.model.typechecker.model.Value in project ceylon-compiler by ceylon.

the class DeclarationErrorVisitor method planAccordingToErrors.

/**
     * Update the plan according to the errors on the node
     */
private void planAccordingToErrors(Node that) {
    List<Message> errors = that.getErrors();
    for (Message message : errors) {
        if (isError(that, message)) {
            TransformationPlan plan;
            /*if (message.getCode() == MEMBER_HAS_WRONG_NUMBER_OF_PARAMETERS
                        && model.isActual()
                        && model.isClassMember()) {
                    plan = new ThrowerMethod(that, message);
                } else if (message.getCode() == TYPE_OF_PARAMETER_IS_DIFFERENT_TO_CORRESPONDING_PARAMETER
                        && model.isActual()
                        && model.isClassMember()) {
                    plan = new ThrowerMethod(that, message);
                } else if (message.getCode() == COULD_NOT_DETERMINE_PARAMETER_TYPE_SAME_AS_CORRESPONDING_PARAMETER
                        && model.isActual()
                        && model.isClassMember()) {
                    plan = new ThrowerMethod(that, message);
                } else if ((message.getCode() == REFINED_MEMBER_WRONG_NUM_PL
                                || message.getCode() == MISSING_PL_FUNCTION_DECL)
                        && model.isActual()
                        && model.isClassMember()) {
                    plan = new ThrowerMethod(that, message);
                } else*/
            if (message.getCode() == FORMAL_MEMBER_UNIMPLEMENTED_IN_CLASS_HIERARCHY && (model instanceof Class || (model instanceof Value && ((Value) model).getTypeDeclaration().isAnonymous()))) {
                plan = new ThrowerMethod(that, message);
            } else if (message.getCode() == PL_AND_CONSTRUCTORS && (model instanceof Class || (model instanceof Value && ((Value) model).getTypeDeclaration().isAnonymous()))) {
                plan = new ThrowerCatchallConstructor(that, message);
            } else {
                plan = new Drop(that, message);
            }
            newplan(plan);
        }
    }
}
Also used : Message(com.redhat.ceylon.compiler.typechecker.tree.Message) Value(com.redhat.ceylon.model.typechecker.model.Value) Class(com.redhat.ceylon.model.typechecker.model.Class) LazyClass(com.redhat.ceylon.model.loader.model.LazyClass)

Example 25 with Value

use of com.redhat.ceylon.model.typechecker.model.Value in project ceylon-compiler by ceylon.

the class MethodOrValueReferenceVisitor method capture.

private void capture(Tree.Primary that, boolean methodSpecifier) {
    if (that instanceof Tree.MemberOrTypeExpression) {
        final Declaration decl = ((Tree.MemberOrTypeExpression) that).getDeclaration();
        if (!(decl instanceof TypedDeclaration)) {
            return;
        }
        TypedDeclaration d = (TypedDeclaration) decl;
        if (Decl.equal(d, declaration) || (d.isNativeHeader() && d.getOverloads().contains(declaration))) {
            d = declaration;
            if (Decl.isParameter(d)) {
                // a reference from a default argument 
                // expression of the same parameter 
                // list does not capture a parameter
                Scope s = that.getScope();
                boolean sameScope = d.getContainer().equals(s) || (s instanceof Declaration && (Decl.isParameter((Declaration) s) || (s instanceof Value && !((Value) s).isTransient())) && d.getContainer().equals(s.getScope()));
                if (!sameScope || methodSpecifier || inLazySpecifierExpression) {
                    ((FunctionOrValue) d).setCaptured(true);
                }
                // Accessing another instance's member passed to a class initializer
                if (that instanceof Tree.QualifiedMemberExpression) {
                    if (d instanceof TypedDeclaration && ((TypedDeclaration) d).getOtherInstanceAccess()) {
                        ((FunctionOrValue) d).setCaptured(true);
                    }
                }
                if (isCapturableMplParameter(d)) {
                    ((FunctionOrValue) d).setCaptured(true);
                }
            } else if (Decl.isValue(d) || Decl.isGetter(d)) {
                Value v = (Value) d;
                v.setCaptured(true);
                if (Decl.isObjectValue(d)) {
                    v.setSelfCaptured(isSelfCaptured(that, d));
                }
                if (v.getSetter() != null) {
                    v.getSetter().setCaptured(true);
                }
            } else if (d instanceof Function) {
                ((Function) d).setCaptured(true);
            }
        /*if (d.isVariable() && !d.isClassMember() && !d.isToplevel()) {
                    that.addError("access to variable local from capturing scope: " + declaration.getName());
                }*/
        }
    }
}
Also used : TypedDeclaration(com.redhat.ceylon.model.typechecker.model.TypedDeclaration) Function(com.redhat.ceylon.model.typechecker.model.Function) Scope(com.redhat.ceylon.model.typechecker.model.Scope) FunctionOrValue(com.redhat.ceylon.model.typechecker.model.FunctionOrValue) Value(com.redhat.ceylon.model.typechecker.model.Value) TypedDeclaration(com.redhat.ceylon.model.typechecker.model.TypedDeclaration) Declaration(com.redhat.ceylon.model.typechecker.model.Declaration) TypeDeclaration(com.redhat.ceylon.model.typechecker.model.TypeDeclaration) FunctionOrValue(com.redhat.ceylon.model.typechecker.model.FunctionOrValue)

Aggregations

Value (com.redhat.ceylon.model.typechecker.model.Value)54 FunctionOrValue (com.redhat.ceylon.model.typechecker.model.FunctionOrValue)39 Declaration (com.redhat.ceylon.model.typechecker.model.Declaration)28 TypeDeclaration (com.redhat.ceylon.model.typechecker.model.TypeDeclaration)27 TypedDeclaration (com.redhat.ceylon.model.typechecker.model.TypedDeclaration)27 Function (com.redhat.ceylon.model.typechecker.model.Function)25 Type (com.redhat.ceylon.model.typechecker.model.Type)23 Class (com.redhat.ceylon.model.typechecker.model.Class)19 JCExpression (com.sun.tools.javac.tree.JCTree.JCExpression)19 JavaBeanValue (com.redhat.ceylon.model.loader.model.JavaBeanValue)16 TypedReference (com.redhat.ceylon.model.typechecker.model.TypedReference)15 TypeParameter (com.redhat.ceylon.model.typechecker.model.TypeParameter)14 JCNewClass (com.sun.tools.javac.tree.JCTree.JCNewClass)14 Tree (com.redhat.ceylon.compiler.typechecker.tree.Tree)13 Parameter (com.redhat.ceylon.model.typechecker.model.Parameter)12 JCTree (com.sun.tools.javac.tree.JCTree)12 AttributeDeclaration (com.redhat.ceylon.compiler.typechecker.tree.Tree.AttributeDeclaration)11 FieldValue (com.redhat.ceylon.model.loader.model.FieldValue)11 ParameterList (com.redhat.ceylon.model.typechecker.model.ParameterList)11 JCStatement (com.sun.tools.javac.tree.JCTree.JCStatement)11