Search in sources :

Example 6 with ParameterList

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

the class AbstractTransformer method getTypedSignature.

private java.util.List<Type> getTypedSignature(Type currentType, TypedDeclaration found) {
    // check that its signature is compatible
    java.util.List<ParameterList> parameterLists = ((Function) found).getParameterLists();
    if (parameterLists == null || parameterLists.isEmpty())
        return null;
    // only consider first param list
    java.util.List<Parameter> parameters = parameterLists.get(0).getParameters();
    if (parameters == null)
        return null;
    TypedReference typedMember = currentType.getTypedMember(found, Collections.<Type>emptyList());
    if (typedMember == null)
        return null;
    java.util.List<Type> typedSignature = new ArrayList<Type>(parameters.size());
    for (Parameter p : parameters) {
        Type parameterType = typedMember.getTypedParameter(p).getFullType();
        typedSignature.add(parameterType);
    }
    return typedSignature;
}
Also used : Function(com.redhat.ceylon.model.typechecker.model.Function) Type(com.redhat.ceylon.model.typechecker.model.Type) ModelUtil.appliedType(com.redhat.ceylon.model.typechecker.model.ModelUtil.appliedType) TypedReference(com.redhat.ceylon.model.typechecker.model.TypedReference) ArrayList(java.util.ArrayList) ParameterList(com.redhat.ceylon.model.typechecker.model.ParameterList) TypeParameter(com.redhat.ceylon.model.typechecker.model.TypeParameter) JCTypeParameter(com.sun.tools.javac.tree.JCTree.JCTypeParameter) Parameter(com.redhat.ceylon.model.typechecker.model.Parameter)

Example 7 with ParameterList

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

the class UnknownTypeCollector method visit.

public void visit(Tree.BaseMemberOrTypeExpression that) {
    super.visit(that);
    Declaration declaration = that.getDeclaration();
    if (declaration == null)
        return;
    if (declaration instanceof Functional) {
        Functional m = (Functional) declaration;
        collectUnknownTypes(m.getType());
        for (ParameterList pl : m.getParameterLists()) {
            for (Parameter p : pl.getParameters()) {
                collectUnknownTypes(p.getType());
            }
        }
    } else if (declaration instanceof Value) {
        Value v = (Value) declaration;
        collectUnknownTypes(v.getType());
    }
}
Also used : Functional(com.redhat.ceylon.model.typechecker.model.Functional) Value(com.redhat.ceylon.model.typechecker.model.Value) ParameterList(com.redhat.ceylon.model.typechecker.model.ParameterList) Parameter(com.redhat.ceylon.model.typechecker.model.Parameter) Declaration(com.redhat.ceylon.model.typechecker.model.Declaration) TypeDeclaration(com.redhat.ceylon.model.typechecker.model.TypeDeclaration)

Example 8 with ParameterList

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

the class ExpressionTransformer method transformConstructorDelegation.

/**
 * Transform a delegated constructor call ({@code extends XXX()})
 * which may be either a superclass initializer/constructor or a
 * same-class constructor.
 * @param extendedType
 * @param delegation The kind of delegation
 * @param invocation
 * @param classBuilder
 * @return
 */
JCStatement transformConstructorDelegation(Node extendedType, CtorDelegation delegation, Tree.InvocationExpression invocation, ClassDefinitionBuilder classBuilder, boolean forDelegationConstructor) {
    if (delegation != null && delegation.isError()) {
        return delegation.makeThrow(this);
    }
    Declaration primaryDeclaration = ((Tree.MemberOrTypeExpression) invocation.getPrimary()).getDeclaration();
    java.util.List<ParameterList> paramLists = ((Functional) primaryDeclaration).getParameterLists();
    if (paramLists.isEmpty()) {
        classBuilder.getInitBuilder().delegateCall(at(extendedType).Exec(makeErroneous(extendedType, "compiler bug: super class " + primaryDeclaration.getName() + " is missing parameter list")));
        return null;
    }
    SuperInvocation builder = new SuperInvocation(this, classBuilder.getForDefinition(), delegation, invocation, paramLists.get(0), forDelegationConstructor);
    CallBuilder callBuilder = CallBuilder.instance(this);
    boolean prevFnCall = withinInvocation(true);
    try {
        if (invocation.getPrimary() instanceof Tree.StaticMemberOrTypeExpression) {
            transformTypeArguments(callBuilder, (Tree.StaticMemberOrTypeExpression) invocation.getPrimary());
        }
        at(builder.getNode());
        JCExpression expr = null;
        Scope outerDeclaration;
        if (Decl.isConstructor(primaryDeclaration)) {
            outerDeclaration = builder.getPrimaryDeclaration().getContainer().getContainer();
        } else {
            outerDeclaration = builder.getPrimaryDeclaration().getContainer();
        }
        if ((Strategy.generateInstantiator(builder.getPrimaryDeclaration()) || builder.getPrimaryDeclaration() instanceof Class) && outerDeclaration instanceof Interface) {
            // If the subclass is inner to an interface then it will be
            // generated inner to the companion and we need to qualify the
            // super(), *unless* the subclass is nested within the same
            // interface as it's superclass.
            Scope outer = builder.getSub().getContainer();
            while (!(outer instanceof Package)) {
                if (outer == outerDeclaration) {
                    expr = naming.makeSuper();
                    break;
                }
                outer = outer.getContainer();
            }
            if (expr == null) {
                if (delegation.isSelfDelegation()) {
                    throw new BugException();
                }
                Interface iface = (Interface) outerDeclaration;
                JCExpression superQual;
                if (Decl.getClassOrInterfaceContainer(classBuilder.getForDefinition(), false) instanceof Interface) {
                    superQual = naming.makeCompanionAccessorCall(naming.makeQuotedThis(), iface);
                } else {
                    superQual = naming.makeCompanionFieldName(iface);
                }
                expr = naming.makeQualifiedSuper(superQual);
            }
        } else {
            expr = delegation.isSelfDelegation() ? naming.makeThis() : naming.makeSuper();
        }
        final List<JCExpression> superArguments = transformSuperInvocationArguments(classBuilder, builder, callBuilder);
        JCExpression superExpr = callBuilder.invoke(expr).arguments(superArguments).build();
        return at(extendedType).Exec(superExpr);
    // classBuilder.getInitBuilder().superCall(at(extendedType).Exec(superExpr));
    } finally {
        withinInvocation(prevFnCall);
    }
}
Also used : Functional(com.redhat.ceylon.model.typechecker.model.Functional) JCExpression(com.sun.tools.javac.tree.JCTree.JCExpression) Scope(com.redhat.ceylon.model.typechecker.model.Scope) ParameterList(com.redhat.ceylon.model.typechecker.model.ParameterList) JCTree(com.sun.tools.javac.tree.JCTree) Tree(com.redhat.ceylon.compiler.typechecker.tree.Tree) Class(com.redhat.ceylon.model.typechecker.model.Class) JCNewClass(com.sun.tools.javac.tree.JCTree.JCNewClass) TypedDeclaration(com.redhat.ceylon.model.typechecker.model.TypedDeclaration) Declaration(com.redhat.ceylon.model.typechecker.model.Declaration) TypeDeclaration(com.redhat.ceylon.model.typechecker.model.TypeDeclaration) Package(com.redhat.ceylon.model.typechecker.model.Package) Interface(com.redhat.ceylon.model.typechecker.model.Interface) ClassOrInterface(com.redhat.ceylon.model.typechecker.model.ClassOrInterface)

Example 9 with ParameterList

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

the class ExpressionTransformer method transformJavaStaticOrInterfaceMember.

private JCExpression transformJavaStaticOrInterfaceMember(Tree.QualifiedMemberOrTypeExpression qmte, Type staticType) {
    Declaration decl = qmte.getDeclaration();
    if (decl instanceof FieldValue) {
        Value member = (Value) decl;
        return naming.makeName(member, Naming.NA_FQ | Naming.NA_WRAPPER_UNQUOTED);
    } else if (decl instanceof Value) {
        Value member = (Value) decl;
        CallBuilder callBuilder = CallBuilder.instance(this);
        Type qualifyingType = ((TypeDeclaration) member.getContainer()).getType();
        callBuilder.invoke(naming.makeQualifiedName(makeJavaType(qualifyingType, JT_RAW | JT_NO_PRIMITIVES), member, Naming.NA_GETTER | Naming.NA_MEMBER));
        return utilInvocation().checkNull(callBuilder.build());
    } else if (decl instanceof Function) {
        Function method = (Function) decl;
        final ParameterList parameterList = method.getFirstParameterList();
        Type qualifyingType = qmte.getPrimary().getTypeModel();
        Tree.TypeArguments typeArguments = qmte.getTypeArguments();
        Reference producedReference = method.appliedReference(qualifyingType, typeArguments.getTypeModels());
        return utilInvocation().checkNull(makeJavaStaticInvocation(gen(), method, producedReference, parameterList));
    } else if (decl instanceof Class) {
        Class class_ = (Class) decl;
        if (class_.isStaticallyImportable()) {
            return naming.makeTypeDeclarationExpression(null, class_, Naming.DeclNameFlag.QUALIFIED);
        } else {
            final ParameterList parameterList = class_.getFirstParameterList();
            Reference producedReference = qmte.getTarget();
            return utilInvocation().checkNull(makeJavaStaticInvocation(gen(), class_, producedReference, parameterList));
        }
    } else if (decl instanceof Interface) {
        return naming.makeTypeDeclarationExpression(null, (Interface) decl, Naming.DeclNameFlag.QUALIFIED);
    } else {
        return makeErroneous(qmte, "compiler bug: unsupported static");
    }
}
Also used : Function(com.redhat.ceylon.model.typechecker.model.Function) Type(com.redhat.ceylon.model.typechecker.model.Type) Reference(com.redhat.ceylon.model.typechecker.model.Reference) TypedReference(com.redhat.ceylon.model.typechecker.model.TypedReference) FunctionOrValue(com.redhat.ceylon.model.typechecker.model.FunctionOrValue) FieldValue(com.redhat.ceylon.model.loader.model.FieldValue) Value(com.redhat.ceylon.model.typechecker.model.Value) ParameterList(com.redhat.ceylon.model.typechecker.model.ParameterList) JCTree(com.sun.tools.javac.tree.JCTree) Tree(com.redhat.ceylon.compiler.typechecker.tree.Tree) Class(com.redhat.ceylon.model.typechecker.model.Class) JCNewClass(com.sun.tools.javac.tree.JCTree.JCNewClass) TypedDeclaration(com.redhat.ceylon.model.typechecker.model.TypedDeclaration) Declaration(com.redhat.ceylon.model.typechecker.model.Declaration) TypeDeclaration(com.redhat.ceylon.model.typechecker.model.TypeDeclaration) FieldValue(com.redhat.ceylon.model.loader.model.FieldValue) Interface(com.redhat.ceylon.model.typechecker.model.Interface) ClassOrInterface(com.redhat.ceylon.model.typechecker.model.ClassOrInterface)

Example 10 with ParameterList

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

the class ClassTransformer method refineMethod.

private Function refineMethod(Scope container, TypedReference pr, ClassOrInterface classModel, Function formalMethod, Unit unit) {
    Function refined = new Function();
    refined.setActual(true);
    refined.setShared(formalMethod.isShared());
    refined.setContainer(container);
    // in case there are subclasses
    refined.setDefault(true);
    refined.setDeferred(false);
    refined.setDeprecated(formalMethod.isDeprecated());
    refined.setName(formalMethod.getName());
    refined.setRefinedDeclaration(formalMethod.getRefinedDeclaration());
    refined.setScope(container);
    refined.setType(pr.getType());
    refined.setUnit(unit);
    refined.setUnboxed(formalMethod.getUnboxed());
    refined.setUntrustedType(formalMethod.getUntrustedType());
    refined.setTypeErased(formalMethod.getTypeErased());
    ArrayList<TypeParameter> refinedTp = new ArrayList<TypeParameter>();
    ;
    for (TypeParameter formalTp : formalMethod.getTypeParameters()) {
        refinedTp.add(formalTp);
    }
    refined.setTypeParameters(refinedTp);
    for (ParameterList formalPl : formalMethod.getParameterLists()) {
        ParameterList refinedPl = new ParameterList();
        for (Parameter formalP : formalPl.getParameters()) {
            Parameter refinedP = new Parameter();
            refinedP.setAtLeastOne(formalP.isAtLeastOne());
            refinedP.setDeclaration(refined);
            refinedP.setDefaulted(formalP.isDefaulted());
            refinedP.setDeclaredAnything(formalP.isDeclaredAnything());
            refinedP.setHidden(formalP.isHidden());
            refinedP.setSequenced(formalP.isSequenced());
            refinedP.setName(formalP.getName());
            final TypedReference typedParameter = pr.getTypedParameter(formalP);
            FunctionOrValue paramModel;
            if (formalP.getModel() instanceof Value) {
                Value paramValueModel = refineValue((Value) formalP.getModel(), typedParameter, refined, classModel.getUnit());
                paramValueModel.setInitializerParameter(refinedP);
                paramModel = paramValueModel;
            } else {
                Function paramFunctionModel = refineMethod(refined, typedParameter, classModel, (Function) formalP.getModel(), unit);
                paramFunctionModel.setInitializerParameter(refinedP);
                paramModel = paramFunctionModel;
            }
            refinedP.setModel(paramModel);
            refinedPl.getParameters().add(refinedP);
        }
        refined.addParameterList(refinedPl);
    }
    return refined;
}
Also used : Function(com.redhat.ceylon.model.typechecker.model.Function) TypeParameter(com.redhat.ceylon.model.typechecker.model.TypeParameter) TypedReference(com.redhat.ceylon.model.typechecker.model.TypedReference) ArrayList(java.util.ArrayList) FunctionOrValue(com.redhat.ceylon.model.typechecker.model.FunctionOrValue) JavaBeanValue(com.redhat.ceylon.model.loader.model.JavaBeanValue) Value(com.redhat.ceylon.model.typechecker.model.Value) ParameterList(com.redhat.ceylon.model.typechecker.model.ParameterList) TypeParameter(com.redhat.ceylon.model.typechecker.model.TypeParameter) Parameter(com.redhat.ceylon.model.typechecker.model.Parameter) FunctionOrValue(com.redhat.ceylon.model.typechecker.model.FunctionOrValue)

Aggregations

ParameterList (com.redhat.ceylon.model.typechecker.model.ParameterList)19 Parameter (com.redhat.ceylon.model.typechecker.model.Parameter)13 TypeParameter (com.redhat.ceylon.model.typechecker.model.TypeParameter)11 Function (com.redhat.ceylon.model.typechecker.model.Function)8 Declaration (com.redhat.ceylon.model.typechecker.model.Declaration)7 TypedDeclaration (com.redhat.ceylon.model.typechecker.model.TypedDeclaration)7 Value (com.redhat.ceylon.model.typechecker.model.Value)7 FunctionOrValue (com.redhat.ceylon.model.typechecker.model.FunctionOrValue)6 Functional (com.redhat.ceylon.model.typechecker.model.Functional)6 Type (com.redhat.ceylon.model.typechecker.model.Type)6 TypeDeclaration (com.redhat.ceylon.model.typechecker.model.TypeDeclaration)6 Tree (com.redhat.ceylon.compiler.typechecker.tree.Tree)5 Class (com.redhat.ceylon.model.typechecker.model.Class)5 JCExpression (com.sun.tools.javac.tree.JCTree.JCExpression)5 JCNewClass (com.sun.tools.javac.tree.JCTree.JCNewClass)5 JCStatement (com.sun.tools.javac.tree.JCTree.JCStatement)5 ArrayList (java.util.ArrayList)5 TypedReference (com.redhat.ceylon.model.typechecker.model.TypedReference)4 JCTypeParameter (com.sun.tools.javac.tree.JCTree.JCTypeParameter)4 FieldValue (com.redhat.ceylon.model.loader.model.FieldValue)3