Search in sources :

Example 6 with Reference

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

the class ExpressionTransformer method transform.

public JCExpression transform(Tree.InvocationExpression ce) {
    JCExpression ret = checkForInvocationExpressionOptimisation(ce);
    if (ret != null)
        return ret;
    Tree.Term primary = Decl.unwrapExpressionsUntilTerm(ce.getPrimary());
    Declaration primaryDeclaration = null;
    Reference producedReference = null;
    if (primary instanceof Tree.MemberOrTypeExpression) {
        producedReference = ((Tree.MemberOrTypeExpression) primary).getTarget();
        primaryDeclaration = ((Tree.MemberOrTypeExpression) primary).getDeclaration();
    }
    Invocation invocation;
    if (ce.getPositionalArgumentList() != null) {
        if ((isIndirectInvocation(ce) || isWithinDefaultParameterExpression(primaryDeclaration.getContainer())) && !Decl.isJavaStaticOrInterfacePrimary(ce.getPrimary())) {
            // indirect invocation
            invocation = new IndirectInvocation(this, primary, primaryDeclaration, ce);
        } else {
            // direct invocation
            java.util.List<Parameter> parameters = ((Functional) primaryDeclaration).getFirstParameterList().getParameters();
            invocation = new PositionalInvocation(this, primary, primaryDeclaration, producedReference, ce, parameters);
        }
    } else if (ce.getNamedArgumentList() != null) {
        invocation = new NamedArgumentInvocation(this, primary, primaryDeclaration, producedReference, ce);
    } else {
        return makeErroneous(ce, "no arguments");
    }
    return transformInvocation(invocation);
}
Also used : AnalyzerUtil.isIndirectInvocation(com.redhat.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.isIndirectInvocation) JCMethodInvocation(com.sun.tools.javac.tree.JCTree.JCMethodInvocation) Term(com.redhat.ceylon.compiler.typechecker.tree.Tree.Term) Reference(com.redhat.ceylon.model.typechecker.model.Reference) TypedReference(com.redhat.ceylon.model.typechecker.model.TypedReference) JCExpression(com.sun.tools.javac.tree.JCTree.JCExpression) AnalyzerUtil.isIndirectInvocation(com.redhat.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.isIndirectInvocation) JCTree(com.sun.tools.javac.tree.JCTree) Tree(com.redhat.ceylon.compiler.typechecker.tree.Tree) TypeParameter(com.redhat.ceylon.model.typechecker.model.TypeParameter) Parameter(com.redhat.ceylon.model.typechecker.model.Parameter) TypedDeclaration(com.redhat.ceylon.model.typechecker.model.TypedDeclaration) Declaration(com.redhat.ceylon.model.typechecker.model.Declaration) TypeDeclaration(com.redhat.ceylon.model.typechecker.model.TypeDeclaration)

Example 7 with Reference

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

the class ClassTransformer method addMissingUnrefinedMembers.

/** 
     * Recover from members not being refined in the class hierarchy 
     * by generating a stub method that throws.
     */
private void addMissingUnrefinedMembers(Node def, Class classModel, ClassDefinitionBuilder classBuilder) {
    for (Reference unrefined : classModel.getUnimplementedFormals()) {
        //classModel.getMember(memberName, null, false);
        Declaration formalMember = unrefined.getDeclaration();
        String errorMessage = "formal member '" + formalMember.getName() + "' of '" + ((TypeDeclaration) formalMember.getContainer()).getName() + "' not implemented in class hierarchy";
        java.util.List<Type> params = new java.util.ArrayList<Type>();
        if (formalMember instanceof Generic) {
            for (TypeParameter tp : ((Generic) formalMember).getTypeParameters()) {
                params.add(tp.getType());
            }
        }
        if (formalMember instanceof Value) {
            addRefinedThrowerAttribute(classBuilder, errorMessage, classModel, (Value) formalMember);
        } else if (formalMember instanceof Function) {
            addRefinedThrowerMethod(classBuilder, errorMessage, classModel, (Function) formalMember);
        } else if (formalMember instanceof Class && formalMember.isClassMember()) {
            addRefinedThrowerInstantiatorMethod(classBuilder, errorMessage, classModel, (Class) formalMember, unrefined);
        }
    // formal member class of interface handled in
    // makeDelegateToCompanion()
    }
}
Also used : TypeParameter(com.redhat.ceylon.model.typechecker.model.TypeParameter) Reference(com.redhat.ceylon.model.typechecker.model.Reference) TypedReference(com.redhat.ceylon.model.typechecker.model.TypedReference) Generic(com.redhat.ceylon.model.typechecker.model.Generic) ArrayList(java.util.ArrayList) Function(com.redhat.ceylon.model.typechecker.model.Function) Type(com.redhat.ceylon.model.typechecker.model.Type) FunctionOrValue(com.redhat.ceylon.model.typechecker.model.FunctionOrValue) JavaBeanValue(com.redhat.ceylon.model.loader.model.JavaBeanValue) Value(com.redhat.ceylon.model.typechecker.model.Value) 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) MethodDeclaration(com.redhat.ceylon.compiler.typechecker.tree.Tree.MethodDeclaration) AttributeDeclaration(com.redhat.ceylon.compiler.typechecker.tree.Tree.AttributeDeclaration) TypeDeclaration(com.redhat.ceylon.model.typechecker.model.TypeDeclaration)

Example 8 with Reference

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

the class NamedArgumentInvocation method makeVarRefArgumentList.

// Make a list of ($arg0, $arg1, ... , $argN)
// or ($arg$this$, $arg0, $arg1, ... , $argN)
private List<JCExpression> makeVarRefArgumentList(Parameter param) {
    ListBuffer<JCExpression> names = ListBuffer.<JCExpression>lb();
    if (!Strategy.defaultParameterMethodStatic(getPrimaryDeclaration()) && Strategy.defaultParameterMethodTakesThis(param.getModel())) {
        names.append(varBaseName.suffixedBy(Suffix.$argthis$).makeIdent());
    }
    // put all the required reified type args too
    Reference ref = gen.resolveAliasesForReifiedTypeArguments(producedReference);
    int tpCount = gen.getTypeParameters(ref).size();
    for (int tpIndex = 0; tpIndex < tpCount; tpIndex++) {
        names.append(reifiedTypeArgName(tpIndex).makeIdent());
    }
    final int parameterIndex = parameterIndex(param);
    for (int ii = 0; ii < parameterIndex; ii++) {
        names.append(this.argsNamesByIndex.get(ii).makeIdent());
    }
    return names.toList();
}
Also used : JCExpression(com.sun.tools.javac.tree.JCTree.JCExpression) Reference(com.redhat.ceylon.model.typechecker.model.Reference) TypedReference(com.redhat.ceylon.model.typechecker.model.TypedReference)

Example 9 with Reference

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

the class NamedArgumentInvocation method addReifiedArguments.

@Override
protected void addReifiedArguments(ListBuffer<ExpressionAndType> result) {
    Reference ref = gen.resolveAliasesForReifiedTypeArguments(producedReference);
    if (!gen.supportsReified(ref.getDeclaration()))
        return;
    int tpCount = gen.getTypeParameters(ref).size();
    for (int tpIndex = 0; tpIndex < tpCount; tpIndex++) {
        result.append(new ExpressionAndType(reifiedTypeArgName(tpIndex).makeIdent(), gen.makeTypeDescriptorType()));
    }
}
Also used : Reference(com.redhat.ceylon.model.typechecker.model.Reference) TypedReference(com.redhat.ceylon.model.typechecker.model.TypedReference)

Example 10 with Reference

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

the class NamedArgumentInvocation method makeThis.

private final JCVariableDecl makeThis() {
    // first append $this
    JCExpression defaultedParameterInstance;
    // TODO Fix how we figure out the thisType, because it's doesn't 
    // handle type parameters correctly
    // we used to use thisType = gen.getThisType(getPrimaryDeclaration());
    final JCExpression thisType;
    Reference target = ((Tree.MemberOrTypeExpression) getPrimary()).getTarget();
    if (getPrimary() instanceof Tree.BaseMemberExpression && !gen.expressionGen().isWithinSyntheticClassBody()) {
        if (Decl.withinClassOrInterface(getPrimaryDeclaration())) {
            // a member method
            thisType = gen.makeJavaType(target.getQualifyingType(), JT_NO_PRIMITIVES);
            defaultedParameterInstance = gen.naming.makeThis();
        } else {
            // a local or toplevel function
            thisType = gen.naming.makeName((TypedDeclaration) getPrimaryDeclaration(), Naming.NA_WRAPPER);
            defaultedParameterInstance = gen.naming.makeName((TypedDeclaration) getPrimaryDeclaration(), Naming.NA_MEMBER);
        }
    } else if (getPrimary() instanceof Tree.BaseTypeExpression || getPrimary() instanceof Tree.QualifiedTypeExpression) {
        TypeDeclaration declaration = (TypeDeclaration) ((Tree.MemberOrTypeExpression) getPrimary()).getDeclaration();
        thisType = gen.makeJavaType(declaration.getType(), JT_COMPANION);
        defaultedParameterInstance = gen.make().NewClass(null, null, gen.makeJavaType(declaration.getType(), JT_COMPANION), List.<JCExpression>nil(), null);
    } else {
        if (isOnValueType()) {
            thisType = gen.makeJavaType(target.getQualifyingType());
        } else {
            thisType = gen.makeJavaType(target.getQualifyingType(), JT_NO_PRIMITIVES);
        }
        defaultedParameterInstance = callVarName.makeIdent();
    }
    JCVariableDecl thisDecl = gen.makeVar(varBaseName.suffixedBy(Suffix.$argthis$), thisType, defaultedParameterInstance);
    return thisDecl;
}
Also used : TypedDeclaration(com.redhat.ceylon.model.typechecker.model.TypedDeclaration) JCExpression(com.sun.tools.javac.tree.JCTree.JCExpression) Reference(com.redhat.ceylon.model.typechecker.model.Reference) TypedReference(com.redhat.ceylon.model.typechecker.model.TypedReference) JCTree(com.sun.tools.javac.tree.JCTree) Tree(com.redhat.ceylon.compiler.typechecker.tree.Tree) TypeDeclaration(com.redhat.ceylon.model.typechecker.model.TypeDeclaration) QualifiedTypeExpression(com.redhat.ceylon.compiler.typechecker.tree.Tree.QualifiedTypeExpression) JCVariableDecl(com.sun.tools.javac.tree.JCTree.JCVariableDecl)

Aggregations

Reference (com.redhat.ceylon.model.typechecker.model.Reference)15 TypedReference (com.redhat.ceylon.model.typechecker.model.TypedReference)14 TypeDeclaration (com.redhat.ceylon.model.typechecker.model.TypeDeclaration)12 TypedDeclaration (com.redhat.ceylon.model.typechecker.model.TypedDeclaration)12 Type (com.redhat.ceylon.model.typechecker.model.Type)11 Declaration (com.redhat.ceylon.model.typechecker.model.Declaration)10 Function (com.redhat.ceylon.model.typechecker.model.Function)10 Tree (com.redhat.ceylon.compiler.typechecker.tree.Tree)7 TypeParameter (com.redhat.ceylon.model.typechecker.model.TypeParameter)7 JCExpression (com.sun.tools.javac.tree.JCTree.JCExpression)7 JCTree (com.sun.tools.javac.tree.JCTree)6 Class (com.redhat.ceylon.model.typechecker.model.Class)5 ClassOrInterface (com.redhat.ceylon.model.typechecker.model.ClassOrInterface)5 FunctionOrValue (com.redhat.ceylon.model.typechecker.model.FunctionOrValue)5 Interface (com.redhat.ceylon.model.typechecker.model.Interface)5 Value (com.redhat.ceylon.model.typechecker.model.Value)5 JCNewClass (com.sun.tools.javac.tree.JCTree.JCNewClass)5 AttributeDeclaration (com.redhat.ceylon.compiler.typechecker.tree.Tree.AttributeDeclaration)4 MethodDeclaration (com.redhat.ceylon.compiler.typechecker.tree.Tree.MethodDeclaration)4 ArrayList (java.util.ArrayList)4