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

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


    private void assignOp(final Tree.AssignmentOp that, final String functionName, final Map<TypeParameter, ProducedType> targs) {
        Term lhs = that.getLeftTerm();
        final boolean isNative="||".equals(functionName)||"&&".equals(functionName);
        if (lhs instanceof BaseMemberExpression) {
            BaseMemberExpression lhsBME = (BaseMemberExpression) lhs;
            Declaration lhsDecl = lhsBME.getDeclaration();

            final String getLHS = memberAccess(lhsBME, null);
            out("(");
            BmeGenerator.generateMemberAccess(lhsBME, new GenerateCallback() {
                @Override public void generateValue() {
View Full Code Here


import com.redhat.ceylon.compiler.typechecker.tree.Tree;

public class BmeGenerator {

    static void generateBme(final Tree.BaseMemberExpression bme, final GenerateJsVisitor gen, final boolean forInvoke) {
        Declaration decl = bme.getDeclaration();
        if (decl != null) {
            String name = decl.getName();
            String pkgName = decl.getUnit().getPackage().getQualifiedNameString();

            // map Ceylon true/false/null directly to JS true/false/null
            if (Module.LANGUAGE_MODULE_NAME.equals(pkgName)) {
                if ("true".equals(name) || "false".equals(name) || "null".equals(name)) {
                    gen.out(name);
                    return;
                }
            }
        }
        String exp = gen.memberAccess(bme, null);
        if (decl == null && gen.isInDynamicBlock()) {
            gen.out("(typeof ", exp, "==='undefined'||", exp, "===null?");
            gen.generateThrow(null, "Undefined or null reference: " + exp, bme);
            gen.out(":", exp, ")");
        } else {
            final boolean isCallable = !forInvoke && decl instanceof Method
                    && bme.getUnit().getCallableDeclaration().equals(bme.getTypeModel().getDeclaration());
            String who = isCallable && decl.isMember() ? gen.getMember(bme, decl, null) : null;
            if (who == null || who.isEmpty()) {
                //We may not need to wrap this in certain cases
                ClassOrInterface cont = Util.getContainingClassOrInterface(bme.getScope());
                who=cont == null ? "0" : gen.getNames().self(cont);
            }
View Full Code Here

     * If lhs==null and the expression is a BaseMemberExpression
     * then the qualified path is prepended.
     */
    static void generateMemberAccess(Tree.StaticMemberOrTypeExpression expr,
                GenerateCallback callback, String lhs, final GenerateJsVisitor gen) {
        Declaration decl = expr.getDeclaration();
        boolean paren = false;
        String plainName = null;
        if (decl == null && gen.isInDynamicBlock()) {
            plainName = expr.getIdentifier().getText();
        } else if (GenerateJsVisitor.isNative(decl)) {
            // direct access to a native element
            plainName = decl.getName();
        }
        if (plainName != null) {
            if ((lhs != null) && (lhs.length() > 0)) {
                gen.out(lhs, ".");
            }
View Full Code Here

    private boolean isSelfReference(Tree.Primary that) {
        return that instanceof Tree.This || that instanceof Tree.Outer;
    }

    @Override public void visit(Tree.Declaration that) {
        Declaration dm = that.getDeclarationModel();
        if (dm==declaration.getContainer()
                || dm==declaration
                || (dm instanceof Setter && ((Setter) dm).getGetter()==declaration)) {
            inCapturingScope = false;
        }
View Full Code Here

                gen.out(")(");
            }
            if (d.isMember()) {
                //Make the chain to the top-level container
                ArrayList<Declaration> parents = new ArrayList<Declaration>(2);
                Declaration pd = (Declaration)d.getContainer();
                while (pd!=null) {
                    parents.add(0,pd);
                    pd = pd.isMember()?(Declaration)pd.getContainer():null;
                }
                for (Declaration _d : parents) {
                    gen.out(gen.getNames().name(_d), ".$$.prototype.");
                }
            }
View Full Code Here

    }

    static void generateMemberLiteral(final Tree.MemberLiteral that, final GenerateJsVisitor gen) {
        final com.redhat.ceylon.compiler.typechecker.model.ProducedReference ref = that.getTarget();
        final ProducedType ltype = that.getType() == null ? null : that.getType().getTypeModel();
        final Declaration d = ref.getDeclaration();
        final Class anonClass = d.isMember()&&d.getContainer() instanceof Class && ((Class)d.getContainer()).isAnonymous()?(Class)d.getContainer():null;
        if (that instanceof Tree.FunctionLiteral || d instanceof Method) {
            gen.out(gen.getClAlias(), d.isMember()&&anonClass==null?"AppliedMethod$meta$model(":"AppliedFunction$meta$model(");
            if (ltype == null) {
                if (anonClass != null) {
                    gen.qualify(that, anonClass);
                    gen.out(gen.getNames().objectName(anonClass), ".");
                } else {
                    gen.qualify(that, d);
                }
            } else {
                if (ltype.getDeclaration().isMember()) {
                    outputPathToDeclaration(that, ltype.getDeclaration(), gen);
                } else {
                    gen.qualify(that, ltype.getDeclaration());
                }
                gen.out(gen.getNames().name(ltype.getDeclaration()));
                gen.out(".$$.prototype.");
            }
            if (d instanceof Value) {
                gen.out("$prop$", gen.getNames().getter(d), ",");
            } else {
                gen.out(gen.getNames().name(d),",");
            }
            if (d.isMember()&&anonClass==null) {
                if (that.getTypeArgumentList()!=null) {
                    gen.out("[");
                    boolean first=true;
                    for (ProducedType targ : that.getTypeArgumentList().getTypeModels()) {
                        if (first)first=false;else gen.out(",");
                        gen.out(gen.getClAlias(),"typeLiteral$meta({Type$typeLiteral:");
                        TypeUtils.typeNameOrList(that, targ, gen, false);
                        gen.out("})");
                    }
                    gen.out("]");
                    gen.out(",");
                } else {
                    gen.out("undefined,");
                }
                TypeUtils.printTypeArguments(that, that.getTypeModel().getTypeArguments(), gen, false,
                        that.getTypeModel().getVarianceOverrides());
            } else {
                TypeUtils.printTypeArguments(that, that.getTypeModel().getTypeArguments(), gen, false,
                        that.getTypeModel().getVarianceOverrides());
                if (anonClass != null) {
                    gen.out(",");
                    gen.qualify(that, anonClass);
                    gen.out(gen.getNames().objectName(anonClass));
                }
                if (ref.getTypeArguments() != null && !ref.getTypeArguments().isEmpty()) {
                    if (anonClass == null) {
                        gen.out(",undefined");
                    }
                    gen.out(",");
                    TypeUtils.printTypeArguments(that, ref.getTypeArguments(), gen, false,
                            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) {
                    gen.out("undefined");
                } else {
View Full Code Here

        gen.out(gen.getClAlias(), "getModules$meta().find('",
                m.getNameAsString(), "','", m.getVersion(), "')");
    }

    static void outputPathToDeclaration(final Node that, final Declaration d, final GenerateJsVisitor gen) {
        final Declaration parent = Util.getContainingDeclaration(d);
        if (!gen.opts.isOptimize() && parent instanceof TypeDeclaration && Util.contains((Scope)parent, that.getScope())) {
            gen.out(gen.getNames().self((TypeDeclaration)parent), ".");
        } else {
            Declaration _md = d;
            final ArrayList<Declaration> parents = new ArrayList<>(3);
            while (_md.isMember()) {
                _md=Util.getContainingDeclaration(_md);
                parents.add(0, _md);
            }
            boolean first=true;
            boolean imported=false;
View Full Code Here

                return -1;
            }
            //Check the members
            for (Declaration d : t1.getDeclaration().getMembers()) {
                if (d instanceof TypedDeclaration || d instanceof ClassOrInterface) {
                    Declaration d2 = t2.getDeclaration().getMember(d.getName(), null, false);
                    if (d2 != null) {
                        final Declaration dd2 = Util.getContainingDeclaration(d2);
                        if (dd2 instanceof TypeDeclaration && t1.getDeclaration().inherits((TypeDeclaration)dd2)) {
                            return 1;
                        }
                    }
                }
            }
            for (Declaration d : t2.getDeclaration().getMembers()) {
                if (d instanceof TypedDeclaration || d instanceof ClassOrInterface) {
                    Declaration d2 = t1.getDeclaration().getMember(d.getName(), null, false);
                    if (d2 != null) {
                        final Declaration dd2 = Util.getContainingDeclaration(d2);
                        if (dd2 instanceof TypeDeclaration && t2.getDeclaration().inherits((TypeDeclaration)dd2)) {
                            return -1;
                        }
                    }
                }
View Full Code Here

            }
            if (targs != null && targs.getTypeModels() != null && !targs.getTypeModels().isEmpty()) {
                if (argList.getPositionalArguments().size() > 0) {
                    gen.out(",");
                }
                Declaration bmed = ((Tree.StaticMemberOrTypeExpression)typeArgSource).getDeclaration();
                if (bmed instanceof Functional) {
                    //If there are fewer arguments than there are parameters...
                    final int argsSize = argList.getPositionalArguments().size();
                    int paramArgDiff = ((Functional) bmed).getParameterLists().get(0).getParameters().size() - argsSize;
                    if (paramArgDiff > 0) {
View Full Code Here

                            } else {
                                gen.out(specialSpreadVar, ".$_get(0))");
                            }
                            //Find out if there are more params
                            final List<Parameter> moreParams;
                            final Declaration pdd = pd.getDeclaration();
                            boolean found = false;
                            if (pdd instanceof Method) {
                                moreParams = ((Method)pdd).getParameterLists().get(0).getParameters();
                            } else if (pdd instanceof com.redhat.ceylon.compiler.typechecker.model.Class) {
                                moreParams = ((com.redhat.ceylon.compiler.typechecker.model.Class)pdd).getParameterList().getParameters();
View Full Code Here

TOP

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

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.