Package com.redhat.ceylon.compiler.typechecker.model

Examples of com.redhat.ceylon.compiler.typechecker.model.Value


        out(names.name(d), ".$$;");
    }

    private void addObjectToPrototype(ClassOrInterface type, final Tree.ObjectDefinition objDef) {
        objectDefinition(objDef);
        Value d = objDef.getDeclarationModel();
        Class c = (Class) d.getTypeDeclaration();
        out(names.self(type), ".", names.name(c), "=", names.name(c), ";",
                names.self(type), ".", names.name(c), ".$crtmm$=");
        TypeUtils.encodeForRuntime(objDef, d, this);
        endLine(true);
    }
View Full Code Here


        endLine(true);
    }

    @Override
    public void visit(final Tree.ObjectDefinition that) {
        Value d = that.getDeclarationModel();
        if (!(opts.isOptimize() && d.isClassOrInterfaceMember())) {
            objectDefinition(that);
        } else {
            //Don't even bother with nodes that have errors
            if (errVisitor.hasErrors(that))return;
            Class c = (Class) d.getTypeDeclaration();
            comment(that);
            outerSelf(d);
            out(".", names.privateName(d), "=");
            outerSelf(d);
            out(".", names.name(c), "()");
View Full Code Here

    private void objectDefinition(final Tree.ObjectDefinition that) {
        //Don't even bother with nodes that have errors
        if (errVisitor.hasErrors(that))return;
        comment(that);
        final Value d = that.getDeclarationModel();
        boolean addToPrototype = opts.isOptimize() && d.isClassOrInterfaceMember();
        final Class c = (Class) d.getTypeDeclaration();

        out(function, names.name(c));
        Map<TypeParameter, ProducedType> targs=new HashMap<TypeParameter, ProducedType>();
        if (that.getSatisfiedTypes() != null) {
            for (StaticType st : that.getSatisfiedTypes().getTypes()) {
                Map<TypeParameter, ProducedType> stargs = st.getTypeModel().getTypeArguments();
                if (stargs != null && !stargs.isEmpty()) {
                    targs.putAll(stargs);
                }
            }
        }
        out(targs.isEmpty()?"()":"($$targs$$)");
        beginBlock();
        instantiateSelf(c);
        referenceOuter(c);
       
        final List<Declaration> superDecs = new ArrayList<Declaration>();
        if (!opts.isOptimize()) {
            new SuperVisitor(superDecs).visit(that.getClassBody());
        }
        if (!targs.isEmpty()) {
            out(names.self(c), ".$$targs$$=$$targs$$"); endLine(true);
        }
        TypeGenerator.callSuperclass(that.getExtendedType(), c, that, superDecs, this);
        TypeGenerator.callInterfaces(that.getSatisfiedTypes(), c, that, superDecs, this);
       
        that.getClassBody().visit(this);
        out("return ", names.self(c), ";");
        indentLevel--;
        endLine();
        out("};", names.name(c), ".$crtmm$=");
        TypeUtils.encodeForRuntime(that, c, this);
        endLine(true);

        TypeGenerator.initializeType(that, this);

        if (!addToPrototype) {
            out("var ", names.name(d));
            //If it's a property, create the object here
            if (defineAsProperty(d)) {
                out("=", names.name(c), "(");
                if (!targs.isEmpty()) {
                    TypeUtils.printTypeArguments(that, targs, this, false, null);
                }
                out(")");
            }
            endLine(true);
        }

        if (!defineAsProperty(d)) {
            final String objvar = (addToPrototype ? "this.":"")+names.name(d);
            out(function, names.getter(d), "()");
            beginBlock();
            //Create the object lazily
            final String oname = names.objectName(c);
            out("if(", objvar, "===", getClAlias(), "INIT$)");
            generateThrow(getClAlias()+"InitializationError",
                    "Cyclic initialization trying to read the value of '" +
                    d.getName() + "' before it was set", that);
            endLine(true);
            out("if(", objvar, "===undefined){", objvar, "=", getClAlias(), "INIT$;",
                    objvar, "=$init$", oname);
            if (!oname.endsWith("()"))out("()");
            out("(");
            if (!targs.isEmpty()) {
                TypeUtils.printTypeArguments(that, targs, this, false, null);
            }
            out(");", objvar, ".$crtmm$=", names.getter(d), ".$crtmm$;}");
            endLine();
            out("return ", objvar, ";");
            endBlockNewLine();           
           
            if (addToPrototype || d.isShared()) {
                outerSelf(d);
                out(".", names.getter(d), "=", names.getter(d));
                endLine(true);
            }
            if (!d.isToplevel()) {
                if(outerSelf(d))out(".");
            }
            out(names.getter(d), ".$crtmm$=");
            TypeUtils.encodeForRuntime(d, that.getAnnotationList(), this);
            endLine(true);
            if (!d.isToplevel()) {
                if (outerSelf(d))out(".");
            }
            out("$prop$", names.getter(d), "={get:");
            if (!d.isToplevel()) {
                if (outerSelf(d))out(".");
            }
            out(names.getter(d), ",$crtmm$:");
            if (!d.isToplevel()) {
                if (outerSelf(d))out(".");
            }
            out(names.getter(d), ".$crtmm$}");
            endLine(true);
            //make available with the class name as well, for metamodel access
            out(names.getter(c), "=", names.getter(d), ";$prop$", names.getter(c), "=", names.getter(d));
            endLine(true);
            if (d.isToplevel()) {
                out("ex$.$prop$", names.getter(d), "=$prop$", names.getter(d));
                endLine(true);
            }
        }
        else {
View Full Code Here

        endLine(true);
    }

    @Override
    public void visit(final Tree.AttributeGetterDefinition that) {
        Value d = that.getDeclarationModel();
        if (opts.isOptimize()&&d.isClassOrInterfaceMember()) return;
        comment(that);
        if (defineAsProperty(d)) {
            defineAttribute(names.self((TypeDeclaration)d.getContainer()), names.name(d));
            AttributeGenerator.getter(that, this);
            final AttributeSetterDefinition setterDef = associatedSetterDefinition(d);
            if (setterDef == null) {
                out(",undefined");
            } else {
View Full Code Here

        }
    }

    private void addGetterToPrototype(TypeDeclaration outer,
            final Tree.AttributeGetterDefinition that) {
        Value d = that.getDeclarationModel();
        if (!opts.isOptimize()||!d.isClassOrInterfaceMember()) return;
        comment(that);
        defineAttribute(names.self(outer), names.name(d));
        AttributeGenerator.getter(that, this);
        final AttributeSetterDefinition setterDef = associatedSetterDefinition(d);
        if (setterDef == null) {
View Full Code Here

        return shared;
    }

    @Override
    public void visit(final Tree.AttributeDeclaration that) {
        final Value d = that.getDeclarationModel();
        //Check if the attribute corresponds to a class parameter
        //This is because of the new initializer syntax
        final com.redhat.ceylon.compiler.typechecker.model.Parameter param = d.isParameter() ?
                ((Functional)d.getContainer()).getParameter(d.getName()) : null;
        if (d.isFormal()) {
            if (!opts.isOptimize())generateAttributeMetamodel(that, false, false);
        } else {
            comment(that);
            SpecifierOrInitializerExpression specInitExpr =
                        that.getSpecifierOrInitializerExpression();
            final boolean addGetter = (specInitExpr != null) || (param != null) || !d.isMember()
                    || d.isVariable() || d.isLate();
            final boolean addSetter = (d.isVariable() || d.isLate()) && !defineAsProperty(d);
            if (opts.isOptimize() && d.isClassOrInterfaceMember()) {
                if ((specInitExpr != null
                        && !(specInitExpr instanceof LazySpecifierExpression)) || d.isLate()) {
                    outerSelf(d);
                    out(".", names.privateName(d), "=");
                    if (d.isLate()) {
                        out("undefined");
                    } else {
                        super.visit(that);
                    }
                    endLine(true);
                }
            }
            else if (specInitExpr instanceof LazySpecifierExpression) {
                final boolean property = defineAsProperty(d);
                if (property) {
                    defineAttribute(names.self((TypeDeclaration)d.getContainer()), names.name(d));
                    out("{");
                } else {
                    out(function, names.getter(d), "(){");
                }
                initSelf(that);
                out("return ");
                if (!isNaturalLiteral(specInitExpr.getExpression().getTerm())) {
                    int boxType = boxStart(specInitExpr.getExpression().getTerm());
                    specInitExpr.getExpression().visit(this);
                    if (boxType == 4) out("/*TODO: callable targs 1*/");
                    boxUnboxEnd(boxType);
                }
                out(";}");
                if (property) {
                    Tree.AttributeSetterDefinition setterDef = null;
                    if (d.isVariable()) {
                        setterDef = associatedSetterDefinition(d);
                        if (setterDef != null) {
                            out(",function(", names.name(setterDef.getDeclarationModel().getParameter()), ")");
                            AttributeGenerator.setter(setterDef, this);
                        }
View Full Code Here

        gen.shareSetter(d);
    }

    static void addGetterAndSetterToPrototype(final TypeDeclaration outer, final Tree.AttributeDeclaration that,
            final GenerateJsVisitor gen) {
        Value d = that.getDeclarationModel();
        if (!gen.opts.isOptimize()||d.isToplevel()) return;
        gen.comment(that);
        if (d.isFormal()) {
            gen.generateAttributeMetamodel(that, false, false);
        } else if (that.getSpecifierOrInitializerExpression() == null && gen.shouldStitch(d)) {
            gen.defineAttribute(gen.getNames().self(outer), gen.getNames().name(d));
            gen.out("{");
            if (!gen.stitchNative(d, that)) {
                gen.out("throw new Error('MISSING native code for " + d.getQualifiedNameString() + "');");
            }
            gen.out("},");
            Tree.AttributeSetterDefinition setterDef = null;
            if (d.isVariable()) {
                setterDef = gen.associatedSetterDefinition(d);
                if (setterDef != null) {
                    if (!gen.stitchNative(setterDef.getDeclarationModel(), that)) {
                        gen.out("function(", gen.getNames().name(setterDef.getDeclarationModel().getParameter()), ")");
                        setter(setterDef, gen);
                    }
                }
            }
            if (setterDef == null) {
                gen.out("undefined");
            }
            gen.out(",");
            TypeUtils.encodeForRuntime(d, that.getAnnotationList(), gen);
            if (setterDef != null) {
                gen.out(",");
                TypeUtils.encodeForRuntime(setterDef.getDeclarationModel(), that.getAnnotationList(), gen);
            }
            gen.out(")");
            gen.endLine(true);
        } else {
            com.redhat.ceylon.compiler.typechecker.model.Parameter param = null;
            if (d.isParameter()) {
                param = ((Functional)d.getContainer()).getParameter(d.getName());
            }
            final boolean isLate = d.isLate();
            if ((that.getSpecifierOrInitializerExpression() != null) || d.isVariable()
                        || param != null || isLate) {
                if (that.getSpecifierOrInitializerExpression()
                                instanceof LazySpecifierExpression) {
                    // attribute is defined by a lazy expression ("=>" syntax)
                    gen.defineAttribute(gen.getNames().self(outer), gen.getNames().name(d));
                    gen.beginBlock();
                    gen.initSelf(that);
                    gen.out("return ");
                    Expression expr = that.getSpecifierOrInitializerExpression().getExpression();
                    if (!gen.isNaturalLiteral(expr.getTerm())) {
                        final int boxType = gen.boxStart(expr.getTerm());
                        expr.visit(gen);
                        gen.endLine(true);
                        if (boxType == 4) gen.out("/*TODO: callable targs 3*/");
                        gen.boxUnboxEnd(boxType);
                    }
                    gen.endBlock();
                    Tree.AttributeSetterDefinition setterDef = null;
                    if (d.isVariable()) {
                        setterDef = gen.associatedSetterDefinition(d);
                        if (setterDef != null) {
                            gen.out(",function(", gen.getNames().name(setterDef.getDeclarationModel().getParameter()), ")");
                            setter(setterDef, gen);
                        }
                    }
                    if (setterDef == null) {
                        gen.out(",undefined");
                    }
                    gen.out(",");
                    TypeUtils.encodeForRuntime(d, that.getAnnotationList(), gen);
                    if (setterDef != null) {
                        gen.out(",");
                        TypeUtils.encodeForRuntime(setterDef.getDeclarationModel(), that.getAnnotationList(), gen);
                    }
                    gen.out(")");
                    gen.endLine(true);
                }
                else {
                    final String atname = gen.getNames().name(d);
                    final String privname = param == null ? gen.getNames().privateName(d) : gen.getNames().name(param)+"_";
                    gen.defineAttribute(gen.getNames().self(outer), atname);
                    gen.out("{");
                    if (isLate) {
                        gen.generateUnitializedAttributeReadCheck("this."+privname, atname);
                    }
                    gen.out("return this.", privname, ";}");
                    if (d.isVariable() || isLate) {
                        final String pname = gen.getNames().createTempVariable();
                        gen.out(",function(", pname, "){");
                        if (isLate && !d.isVariable()) {
                            gen.generateImmutableAttributeReassignmentCheck("this."+privname, atname);
                        }
                        gen.out("return this.", privname,
                                "=", pname, ";}");
                    } else {
View Full Code Here

                            ref.getType().getVarianceOverrides());
                }
            }
            gen.out(")");
        } else if (that instanceof ValueLiteral || d instanceof Value) {
            Value vd = (Value)d;
            if (vd.isMember() && anonClass==null) {
                gen.out(gen.getClAlias(), "$init$AppliedAttribute$meta$model()('");
                gen.out(d.getName(), "',");
            } else {
                gen.out(gen.getClAlias(), "$init$AppliedValue$jsint()(");
                if (anonClass == null) {
View Full Code Here

                        for (Tree.PositionalArgument arg : argList.getPositionalArguments()) {
                            if (p == null) {
                                p = new Parameter();
                                p.setName("arg"+c);
                                p.setDeclaration(that.getPrimary().getTypeModel().getDeclaration());
                                Value v = new Value();
                                v.setContainer(that.getPositionalArgumentList().getScope());
                                v.setType(argtype);
                                p.setModel(v);
                                if (callableArgs == null || isSequenced) {
                                    p.setSequenced(true);
                                } else if (!isSequenced) {
                                    ProducedType next = isUnion ? null : callableArgs.getTypeArgumentList().get(2);
View Full Code Here

            Parameter _p = null;
            if (tuple.equals(tdecl) || (tdecl.getCaseTypeDeclarations() != null
                    && tdecl.getCaseTypeDeclarations().size()==2
                    && tdecl.getCaseTypeDeclarations().contains(tuple))) {
                _p = new Parameter();
                _p.setModel(new Value());
                if (tuple.equals(tdecl)) {
                    _p.getModel().setType(_tuple.getTypeArgumentList().get(1));
                    _tuple = _tuple.getTypeArgumentList().get(2);
                } else {
                    //Handle union types for defaulted parameters
                    for (ProducedType mt : _tuple.getCaseTypes()) {
                        if (tuple.equals(mt.getDeclaration())) {
                            _p.getModel().setType(mt.getTypeArgumentList().get(1));
                            _tuple = mt.getTypeArgumentList().get(2);
                            break;
                        }
                    }
                    _p.setDefaulted(true);
                }
            } else if (tdecl.inherits(sequential)) {
                //Handle Sequence, for nonempty variadic parameters
                _p = new Parameter();
                _p.setModel(new Value());
                _p.getModel().setType(_tuple.getTypeArgumentList().get(0));
                _p.setSequenced(true);
                _tuple = empty.getType();
            }
            else {
View Full Code Here

TOP

Related Classes of com.redhat.ceylon.compiler.typechecker.model.Value

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.