Package org.python.indexer.types

Examples of org.python.indexer.types.NType


    }

    @Override
    public NType resolve(Scope s) throws Exception {
        if (op == OpType.AND) {
            NType last = null;
            for (NNode e : values) {
                last = resolveExpr(e, s);
            }
            return setType(last == null ? new NUnknownType() : last);
        }
View Full Code Here


        // This try-catch enables error recovery when there are bugs in
        // the indexer.  Rather than unwinding all the way up to the module
        // level (and failing to load the module), we record an error for this
        // node and continue.
        try {
            NType result = n.resolve(s);
            if (result == null) {
                Indexer.idx.warn(n + " resolved to a null type");
                return n.setType(new NUnknownType());
            }
            return result;
View Full Code Here

            return Indexer.idx.globaltable;
        }
        NNode up = this;
        while ((up = up.parent) != null) {
            if (up.isFunctionDef() || up.isClassDef() || up.isModule()) {
                NType type = up.getType();
                if (type == null || type.getTable() == null) {
                    return Indexer.idx.globaltable;
                }
                return type.getTable();
            }
        }
        return Indexer.idx.globaltable;
    }
View Full Code Here

    protected NType resolveListAsUnion(List<? extends NNode> nodes, Scope s) {
        if (nodes == null || nodes.isEmpty()) {
            return new NUnknownType();
        }

        NType result = null;
        for (NNode node : nodes) {
            NType nodeType = resolveExpr(node, s);
            if (result == null) {
                result = nodeType;
            } else {
                result = NUnionType.union(result, nodeType);
            }
View Full Code Here

        addChildren(optional_vars, context_expr, body);
    }

    @Override
    public NType resolve(Scope s) throws Exception {
        NType val = resolveExpr(context_expr, s);
        NameBinder.make().bind(s, optional_vars, val);
        return setType(resolveExpr(body, s));
    }
View Full Code Here

     * @return the filename associated with the type (if present)
     *     or the first definition (if present), otherwise a string
     *     describing what is known about the binding's source.
     */
    public String getFirstFile() {
        NType bt = getType();
        if (bt instanceof NModuleType) {
            String file = bt.asModuleType().getFile();
            return file != null ? file : "<built-in module>";
        }
        if (defs != null) {
            for (Def def : defs) {
                String file = def.getFile();
View Full Code Here

        addChildren(value, slice);
    }

    @Override
    public NType resolve(Scope s) throws Exception {
        NType vt = resolveExpr(value, s);
        NType st = resolveExpr(slice, s);

        // slicing
        if (vt.isUnknownType()) {
            if (st.isListType()) {
                return setType(vt);
            }
            return setType(new NUnknownType());
        }

        if (st.isListType()) {
            NType getslice_type = vt.getTable().lookupTypeAttr("__getslice__");
            if (getslice_type == null) {
                addError("The type can't be sliced: " + vt);
                return setType(new NUnknownType());
            }
            if (!getslice_type.isFuncType()) {
                addError("The type's __getslice__ method is not a function: "
                                       + getslice_type);
                return setType(new NUnknownType());
            }
            return setType(getslice_type.asFuncType().getReturnType().follow());
        }

        // subscription
        if (slice instanceof NIndex) {
            if (vt.isListType()) {
                warnUnlessNumIndex(st);
                return setType(vt.asListType().getElementType());
            }
            if (vt.isTupleType()) {
                warnUnlessNumIndex(st);
                return setType(vt.asTupleType().toListType().getElementType());
            }
            if (vt.isStrType()) {
                warnUnlessNumIndex(st);
                return setType(Indexer.idx.builtins.BaseStr);
            }
            // XXX:  unicode, buffer, xrange

            if (vt.isDictType()) {
                if (!st.follow().equals(vt.asDictType().getKeyType())) {
                    addWarning("Possible KeyError (wrong type for subscript)");
                }
                return setType(vt.asDictType().getValueType())// infer it regardless
            }
            // else fall through
        }

        // subscription via delegation
        if (vt.isUnionType()) {
            for (NType u : vt.asUnionType().getTypes()) {
                NType gt = vt.getTable().lookupTypeAttr("__getitem__");
                if (gt != null) {
                    return setType(get__getitem__type(gt, gt));
                }
            }
        }
        NType gt = vt.getTable().lookupTypeAttr("__getitem__");
        return setType(get__getitem__type(gt, vt));
    }
View Full Code Here

        NType gt = vt.getTable().lookupTypeAttr("__getitem__");
        return setType(get__getitem__type(gt, vt));
    }

    private void warnUnlessNumIndex(NType subscriptType) {
        NType follow = subscriptType.follow();
        if (!follow.isNumType() && !follow.isUnknownType()) {
            addWarning("Possible KeyError: subscript should be a number; found " + follow);
        }
    }
View Full Code Here

        for (NBinding nb : entries) {
            Def signode = nb.getSignatureNode();
            List<Entry> kids = null;

            if (nb.getKind() == NBinding.Kind.CLASS) {
                NType realType = nb.followType();
                if (realType.isUnionType()) {
                    for (NType t : realType.asUnionType().getTypes()) {
                        if (t.isClassType()) {
                            realType = t;
                            break;
                        }
                    }
                }
                kids = generate(realType.getTable(), path);
            }

            Entry kid = kids != null ? new Branch() : new Leaf();
            kid.setOffset(signode.start());
            kid.setQname(nb.getQname());
View Full Code Here

        }
    }

    @Override
    public NType resolve(Scope s) throws Exception {
        NType valueType = resolveExpr(rvalue, s);
        switch (targets.size()) {
            case 0:
                break;
            case 1:
                NameBinder.make().bind(s, targets.get(0), valueType);
View Full Code Here

TOP

Related Classes of org.python.indexer.types.NType

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.