Search in sources :

Example 16 with Parameter

use of com.redhat.ceylon.model.typechecker.model.Parameter 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 17 with Parameter

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

the class ClassTransformer method overloads.

private Iterable<java.util.List<Parameter>> overloads(Functional f) {
    java.util.List<java.util.List<Parameter>> result = new ArrayList<java.util.List<Parameter>>();
    result.add(f.getFirstParameterList().getParameters());
    int ii = 0;
    for (Parameter p : f.getFirstParameterList().getParameters()) {
        if (p.isDefaulted() || (p.isSequenced() && !p.isAtLeastOne())) {
            result.add(f.getFirstParameterList().getParameters().subList(0, ii));
        }
        ii++;
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) TypeParameter(com.redhat.ceylon.model.typechecker.model.TypeParameter) Parameter(com.redhat.ceylon.model.typechecker.model.Parameter) ArrayList(java.util.ArrayList) AnnotationList(com.redhat.ceylon.compiler.typechecker.tree.Tree.AnnotationList) List(com.sun.tools.javac.util.List) ParameterList(com.redhat.ceylon.model.typechecker.model.ParameterList)

Example 18 with Parameter

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

the class ClassTransformer method addRefinedThrowerInstantiatorMethod.

private void addRefinedThrowerInstantiatorMethod(ClassDefinitionBuilder classBuilder, String message, ClassOrInterface classModel, Class formalClass, Reference unrefined) {
    MethodDefinitionBuilder mdb = MethodDefinitionBuilder.systemMethod(this, naming.getInstantiatorMethodName(formalClass));
    mdb.modifiers(transformClassDeclFlags(formalClass) & ~ABSTRACT);
    for (TypeParameter tp : formalClass.getTypeParameters()) {
        mdb.typeParameter(tp);
        mdb.reifiedTypeParameter(tp);
    }
    for (Parameter formalP : formalClass.getParameterList().getParameters()) {
        ParameterDefinitionBuilder pdb = ParameterDefinitionBuilder.systemParameter(this, formalP.getName());
        pdb.sequenced(formalP.isSequenced());
        pdb.defaulted(formalP.isDefaulted());
        pdb.type(makeJavaType(unrefined.getTypedParameter(formalP).getType()), null);
        mdb.parameter(pdb);
    }
    mdb.resultType(makeJavaType(unrefined.getType()), null);
    mdb.body(makeThrowUnresolvedCompilationError(message));
    classBuilder.method(mdb);
}
Also used : TypeParameter(com.redhat.ceylon.model.typechecker.model.TypeParameter) TypeParameter(com.redhat.ceylon.model.typechecker.model.TypeParameter) Parameter(com.redhat.ceylon.model.typechecker.model.Parameter)

Example 19 with Parameter

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

the class MethodDefinitionBuilder method resultType.

public MethodDefinitionBuilder resultType(Function method, int flags) {
    if (method.isParameter()) {
        if (Decl.isUnboxedVoid(method) && !Strategy.useBoxedVoid(method)) {
            return resultType(gen.makeJavaTypeAnnotations(method, false), gen.make().Type(gen.syms().voidType));
        } else {
            Parameter parameter = method.getInitializerParameter();
            Type resultType = parameter.getType();
            for (int ii = 1; ii < method.getParameterLists().size(); ii++) {
                resultType = gen.typeFact().getCallableType(resultType);
            }
            return resultType(gen.makeJavaType(resultType, CodegenUtil.isUnBoxed(method) ? 0 : AbstractTransformer.JT_NO_PRIMITIVES), method);
        }
    }
    TypedReference typedRef = gen.getTypedReference(method);
    TypedReference nonWideningTypedRef = gen.nonWideningTypeDecl(typedRef);
    Type nonWideningType = gen.nonWideningType(typedRef, nonWideningTypedRef);
    if (method.isActual() && CodegenUtil.hasTypeErased(method))
        flags |= AbstractTransformer.JT_RAW;
    return resultType(makeResultType(nonWideningTypedRef.getDeclaration(), nonWideningType, flags), method);
}
Also used : Type(com.redhat.ceylon.model.typechecker.model.Type) TypedReference(com.redhat.ceylon.model.typechecker.model.TypedReference) TypeParameter(com.redhat.ceylon.model.typechecker.model.TypeParameter) Parameter(com.redhat.ceylon.model.typechecker.model.Parameter) JCTypeParameter(com.sun.tools.javac.tree.JCTree.JCTypeParameter)

Example 20 with Parameter

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

the class NamedArgumentInvocation method appendVarsForNamedArguments.

private void appendVarsForNamedArguments(java.util.List<Tree.NamedArgument> namedArguments, java.util.List<Parameter> declaredParams) {
    // Assign vars for each named argument given
    for (Tree.NamedArgument namedArg : namedArguments) {
        gen.at(namedArg);
        Parameter declaredParam = namedArg.getParameter();
        Naming.SyntheticName argName = argName(declaredParam);
        if (namedArg instanceof Tree.SpecifiedArgument) {
            bindSpecifiedArgument((Tree.SpecifiedArgument) namedArg, declaredParam, argName);
        } else if (namedArg instanceof Tree.MethodArgument) {
            bindMethodArgument((Tree.MethodArgument) namedArg, declaredParam, argName);
        } else if (namedArg instanceof Tree.ObjectArgument) {
            bindObjectArgument((Tree.ObjectArgument) namedArg, declaredParam, argName);
        } else if (namedArg instanceof Tree.AttributeArgument) {
            bindAttributeArgument((Tree.AttributeArgument) namedArg, declaredParam, argName);
        } else {
            throw BugException.unhandledNodeCase(namedArg);
        }
    }
}
Also used : JCTree(com.sun.tools.javac.tree.JCTree) Tree(com.redhat.ceylon.compiler.typechecker.tree.Tree) Parameter(com.redhat.ceylon.model.typechecker.model.Parameter)

Aggregations

Parameter (com.redhat.ceylon.model.typechecker.model.Parameter)56 TypeParameter (com.redhat.ceylon.model.typechecker.model.TypeParameter)40 JCExpression (com.sun.tools.javac.tree.JCTree.JCExpression)25 Type (com.redhat.ceylon.model.typechecker.model.Type)24 Function (com.redhat.ceylon.model.typechecker.model.Function)19 ParameterList (com.redhat.ceylon.model.typechecker.model.ParameterList)18 Tree (com.redhat.ceylon.compiler.typechecker.tree.Tree)17 JCTree (com.sun.tools.javac.tree.JCTree)15 Class (com.redhat.ceylon.model.typechecker.model.Class)14 ArrayList (java.util.ArrayList)14 FunctionOrValue (com.redhat.ceylon.model.typechecker.model.FunctionOrValue)13 JCNewClass (com.sun.tools.javac.tree.JCTree.JCNewClass)13 TypeDeclaration (com.redhat.ceylon.model.typechecker.model.TypeDeclaration)12 Value (com.redhat.ceylon.model.typechecker.model.Value)12 Declaration (com.redhat.ceylon.model.typechecker.model.Declaration)11 TypedDeclaration (com.redhat.ceylon.model.typechecker.model.TypedDeclaration)11 TypedReference (com.redhat.ceylon.model.typechecker.model.TypedReference)11 JCStatement (com.sun.tools.javac.tree.JCTree.JCStatement)10 JCPrimitiveTypeTree (com.sun.tools.javac.tree.JCTree.JCPrimitiveTypeTree)9 JCTypeParameter (com.sun.tools.javac.tree.JCTree.JCTypeParameter)9