Search in sources :

Example 1 with Value

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

the class BoxingDeclarationVisitor method setBoxingState.

private void setBoxingState(TypedDeclaration declaration, TypedDeclaration refinedDeclaration, Node that) {
    Type type = declaration.getType();
    if (type == null) {
        // an error must have already been reported
        return;
    }
    // fetch the real refined declaration if required
    if (Decl.equal(declaration, refinedDeclaration) && declaration instanceof FunctionOrValue && ((FunctionOrValue) declaration).isParameter() && declaration.getContainer() instanceof Class) {
        // maybe it is really inherited from a field?
        FunctionOrValue methodOrValueForParam = (FunctionOrValue) declaration;
        if (methodOrValueForParam != null) {
            // make sure we get the refined version of that member
            refinedDeclaration = (TypedDeclaration) methodOrValueForParam.getRefinedDeclaration();
        }
    }
    // inherit underlying type constraints
    if (!Decl.equal(refinedDeclaration, declaration)) {
        // simple case
        if (type.getUnderlyingType() == null && refinedDeclaration.getType() != null) {
            if (type.isCached()) {
                type = type.clone();
            }
            type.setUnderlyingType(refinedDeclaration.getType().getUnderlyingType());
            declaration.setType(type);
        }
        // special case for variadics
        if (Decl.isValueParameter(refinedDeclaration)) {
            Parameter parameter = ((FunctionOrValue) refinedDeclaration).getInitializerParameter();
            if (parameter.isSequenced()) {
                // inherit the underlying type of the iterated type
                Type refinedIteratedType = refinedDeclaration.getType().getTypeArgumentList().get(0);
                if (refinedIteratedType.getUnderlyingType() != null) {
                    Type ourIteratedType = type.getTypeArgumentList().get(0);
                    if (ourIteratedType.getUnderlyingType() == null) {
                        if (ourIteratedType.isCached()) {
                            ourIteratedType = ourIteratedType.clone();
                        }
                        ourIteratedType.setUnderlyingType(refinedIteratedType.getUnderlyingType());
                        type.getTypeArgumentList().set(0, ourIteratedType);
                        // make sure we remove those types from the cache otherwise UGLY things happen
                        TypeCache cache = type.getDeclaration().getUnit().getCache();
                        if (cache != null) {
                            cache.remove(ourIteratedType);
                            cache.remove(type);
                        }
                    }
                }
            }
        }
    }
    // abort if our boxing state has already been set
    if (declaration.getUnboxed() != null)
        return;
    // functional parameter return values are always boxed if we're not creating a method for them
    if (declaration instanceof Function && ((Function) declaration).isParameter() && !JvmBackendUtil.createMethod((Function) declaration)) {
        declaration.setUnboxed(false);
        return;
    }
    if (!Decl.equal(refinedDeclaration, declaration)) {
        // make sure refined declarations have already been set
        if (refinedDeclaration.getUnboxed() == null)
            setBoxingState(refinedDeclaration, refinedDeclaration, that);
        // inherit
        declaration.setUnboxed(refinedDeclaration.getUnboxed());
    } else if (declaration instanceof Function && Strategy.useBoxedVoid((Function) declaration) && !(refinedDeclaration.getTypeDeclaration() instanceof TypeParameter) && !CodegenUtil.isContainerFunctionalParameter(refinedDeclaration) && !(refinedDeclaration instanceof Functional && Decl.isMpl((Functional) refinedDeclaration))) {
        declaration.setUnboxed(false);
    } else if ((isCeylonBasicType(type) || Decl.isUnboxedVoid(declaration)) && !(refinedDeclaration.getTypeDeclaration() instanceof TypeParameter) && (refinedDeclaration.getContainer() instanceof Declaration == false || !CodegenUtil.isContainerFunctionalParameter(refinedDeclaration)) && !(refinedDeclaration instanceof Functional && Decl.isMpl((Functional) refinedDeclaration))) {
        boolean unbox = !forceBoxedLocals || !(declaration instanceof Value) || !Decl.isLocal(declaration) || Decl.isParameter(declaration) || Decl.isTransient(declaration);
        // until it's used later by user code
        if (declaration.getOriginalDeclaration() != null && declaration.hasUncheckedNullType())
            unbox = false;
        declaration.setUnboxed(unbox);
    } else if (Decl.isValueParameter(declaration) && CodegenUtil.isContainerFunctionalParameter(declaration) && JvmBackendUtil.createMethod((FunctionOrValue) declaration.getContainer())) {
        Function functionalParameter = (Function) declaration.getContainer();
        TypedDeclaration refinedFrom = (TypedDeclaration) CodegenUtil.getTopmostRefinedDeclaration(functionalParameter, optimisedMethodSpecifiersToMethods);
        if (Decl.equal(refinedFrom, functionalParameter)) {
            // not a method return type (where void would be considered unboxed).
            if (declaration.getUnit().getAnythingType().isExactly(declaration.getType()) || declaration.getUnit().isOptionalType(declaration.getType())) {
                declaration.setUnboxed(false);
            } else {
                declaration.setUnboxed(true);
            }
        } else {
            // make sure refined declarations have already been set
            if (refinedFrom.getUnboxed() == null)
                setBoxingState(refinedFrom, refinedFrom, that);
            // inherit
            declaration.setUnboxed(refinedFrom.getUnboxed());
        }
    } else {
        declaration.setUnboxed(false);
    }
    // Any "@boxed" or "@unboxed" compiler annotation overrides
    boxFromAnnotation(declaration, that);
}
Also used : Functional(org.eclipse.ceylon.model.typechecker.model.Functional) Function(org.eclipse.ceylon.model.typechecker.model.Function) TypedDeclaration(org.eclipse.ceylon.model.typechecker.model.TypedDeclaration) AbstractTransformer.isPinnedType(org.eclipse.ceylon.compiler.java.codegen.AbstractTransformer.isPinnedType) Type(org.eclipse.ceylon.model.typechecker.model.Type) TypeParameter(org.eclipse.ceylon.model.typechecker.model.TypeParameter) FunctionOrValue(org.eclipse.ceylon.model.typechecker.model.FunctionOrValue) Value(org.eclipse.ceylon.model.typechecker.model.Value) Parameter(org.eclipse.ceylon.model.typechecker.model.Parameter) TypeParameter(org.eclipse.ceylon.model.typechecker.model.TypeParameter) Class(org.eclipse.ceylon.model.typechecker.model.Class) TypeCache(org.eclipse.ceylon.model.typechecker.context.TypeCache) TypedDeclaration(org.eclipse.ceylon.model.typechecker.model.TypedDeclaration) FunctionalParameterDeclaration(org.eclipse.ceylon.compiler.typechecker.tree.Tree.FunctionalParameterDeclaration) Declaration(org.eclipse.ceylon.model.typechecker.model.Declaration) AttributeDeclaration(org.eclipse.ceylon.compiler.typechecker.tree.Tree.AttributeDeclaration) FunctionOrValue(org.eclipse.ceylon.model.typechecker.model.FunctionOrValue)

Example 2 with Value

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

the class ClassOrPackageDoc method isConstantValue.

private boolean isConstantValue(Declaration d) {
    if (Decl.isValue(d)) {
        Value value = (Value) d;
        if (value.isShared() && !value.isVariable() && !value.isDynamicallyTyped()) {
            Unit unit = value.getUnit();
            Type type = value.getType();
            if (type.isSequential()) {
                type = unit.getSequentialElementType(type);
            }
            if (type.isString() || type.isInteger() || type.isFloat() || type.isCharacter()) {
                return true;
            }
        }
    }
    return false;
}
Also used : Util.isAbbreviatedType(org.eclipse.ceylon.ceylondoc.Util.isAbbreviatedType) Type(org.eclipse.ceylon.model.typechecker.model.Type) FunctionOrValue(org.eclipse.ceylon.model.typechecker.model.FunctionOrValue) Value(org.eclipse.ceylon.model.typechecker.model.Value) Unit(org.eclipse.ceylon.model.typechecker.model.Unit) PhasedUnit(org.eclipse.ceylon.compiler.typechecker.context.PhasedUnit)

Example 3 with Value

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

the class ClassOrPackageDoc method doc.

protected final void doc(String id, String name, Declaration d) throws IOException {
    String declarationName = Util.getDeclarationName(d);
    id = (id != null ? id : name);
    boolean alias = Util.nullSafeCompare(name, declarationName) != 0;
    // put the id on the td because IE8 doesn't support id attributes on tr (yeah right)
    open("tr");
    open("td id='" + id + "' nowrap");
    writeIcon(d);
    if (!(d instanceof Constructor)) {
        around("code class='decl-label'", name);
        close("td");
        open("td");
    }
    writeLinkOneSelf(id);
    if (alias) {
        writeTagged(d);
        writeAlias(d);
    } else {
        writeLinkSource(d);
        writeTagged(d);
        if (d instanceof Functional) {
            writeParameterLinksIfRequired((Functional) d);
        }
        open("code class='signature'");
        around("span class='modifiers'", getModifiers(d));
        write(" ");
        if (!ModelUtil.isConstructor(d)) {
            if (!Decl.isDynamic(d)) {
                if (d instanceof Functional && ((Functional) d).isDeclaredVoid()) {
                    around("span class='void'", "void");
                } else if (d instanceof TypedDeclaration) {
                    linkRenderer().to(((TypedDeclaration) d).getType()).useScope(d).write();
                } else {
                    linkRenderer().to(d).useScope(d).write();
                }
            } else {
                around("span class='dynamic'", "dynamic");
            }
        }
        write(" ");
        open("span class='identifier'");
        write(name);
        close("span");
        if (isConstantValue(d)) {
            writeConstantValue((Value) d);
        }
        if (d instanceof Generic) {
            writeTypeParameters(d.getTypeParameters(), d);
        }
        if (d instanceof Functional) {
            writeParameterList((Functional) d, d);
        }
        if (d instanceof Generic) {
            writeTypeParametersConstraints(d.getTypeParameters(), d);
        }
        if (d instanceof Value) {
            Setter setter = ((Value) d).getSetter();
            if (setter != null && Util.getAnnotation(setter.getUnit(), setter.getAnnotations(), "doc") != null) {
                tool.warningSetterDoc(d.getQualifiedNameString(), d);
            }
        }
        close("code");
        writeDescription(d);
    }
    close("td");
    close("tr");
}
Also used : Functional(org.eclipse.ceylon.model.typechecker.model.Functional) TypedDeclaration(org.eclipse.ceylon.model.typechecker.model.TypedDeclaration) Constructor(org.eclipse.ceylon.model.typechecker.model.Constructor) Generic(org.eclipse.ceylon.model.typechecker.model.Generic) FunctionOrValue(org.eclipse.ceylon.model.typechecker.model.FunctionOrValue) Value(org.eclipse.ceylon.model.typechecker.model.Value) Setter(org.eclipse.ceylon.model.typechecker.model.Setter)

Example 4 with Value

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

the class IndexApiDoc method collectDeclarations.

private List<Declaration> collectDeclarations() {
    List<Declaration> declarations = new ArrayList<Declaration>();
    for (Package pkg : tool.getPackages(module)) {
        if (tool.shouldInclude(pkg)) {
            List<Declaration> members = pkg.getMembers();
            for (Declaration member : members) {
                if (tool.shouldInclude(member)) {
                    if (member instanceof Value && ((Value) member).getTypeDeclaration().isAnonymous()) {
                        continue;
                    }
                    declarations.add(member);
                }
            }
        }
    }
    Collections.sort(declarations, ReferenceableComparatorByName.INSTANCE);
    return declarations;
}
Also used : ArrayList(java.util.ArrayList) Value(org.eclipse.ceylon.model.typechecker.model.Value) Declaration(org.eclipse.ceylon.model.typechecker.model.Declaration) Package(org.eclipse.ceylon.model.typechecker.model.Package)

Example 5 with Value

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

the class AnnotationModelVisitor method visit.

@Override
public void visit(Tree.BaseMemberExpression bme) {
    if (annotationConstructor != null) {
        Declaration declaration = bme.getDeclaration();
        if (checkingInvocationPrimary && isAnnotationConstructor(bme.getDeclaration())) {
            Function ctor = (Function) bme.getDeclaration();
            instantiation.setPrimary(ctor);
            if (ctor.getAnnotationConstructor() != null && ctor.getAnnotationConstructor() != instantiation) {
                for (AnnotationConstructorParameter p : ((AnnotationInvocation) ctor.getAnnotationConstructor()).getConstructorParameters()) {
                    instantiation.addConstructorParameter(p);
                }
            }
        } else if (checkingArguments || checkingDefaults) {
            if (declaration instanceof Value && ((Value) declaration).isParameter()) {
                Value constructorParameter = (Value) declaration;
                ParameterAnnotationTerm a = new ParameterAnnotationTerm();
                a.setSpread(spread);
                // XXX Is this right?
                a.setSourceParameter(constructorParameter.getInitializerParameter());
                this.term = a;
            } else if (isBooleanTrue(declaration)) {
                LiteralAnnotationTerm argument = new BooleanLiteralAnnotationTerm(true);
                appendLiteralArgument(bme, argument);
            } else if (isBooleanFalse(declaration)) {
                LiteralAnnotationTerm argument = new BooleanLiteralAnnotationTerm(false);
                appendLiteralArgument(bme, argument);
            } else if (bme.getUnit().isEmptyType(bme.getTypeModel()) && bme.getUnit().isIterableType(bme.getTypeModel()) && elements == null) {
                // If we're dealing with an iterable, empty means empty collection, not object
                endCollection(startCollection(bme), bme);
            } else if (Decl.isAnonCaseOfEnumeratedType(bme)) {
                LiteralAnnotationTerm argument = new ObjectLiteralAnnotationTerm(bme.getTypeModel());
                appendLiteralArgument(bme, argument);
            } else {
                bme.addError("compiler bug: unsupported base member expression in annotation constructor", Backend.Java);
            }
        } else {
            bme.addError("compiler bug: unsupported base member expression in annotation constructor", Backend.Java);
        }
    }
}
Also used : Function(org.eclipse.ceylon.model.typechecker.model.Function) Value(org.eclipse.ceylon.model.typechecker.model.Value) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) Declaration(org.eclipse.ceylon.model.typechecker.model.Declaration)

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