Package org.python.indexer.types

Examples of org.python.indexer.types.NType


            return;
        }

        // XXX:  we've disabled support for NInstanceType for now
        NBinding b = getBinding(bindingQname);
        NType btype = b.followType();
        assertTrue(btype.isInstanceType());
        NType ctype = getTypeBinding(classQname);
        assertEquals(btype.asInstanceType().getClassType(), ctype);
    }
View Full Code Here


     * an assignment, in which case it is called in lieu of {@link #resolve}.<p>
     */
    public void setAttr(Scope s, NType v) throws Exception {
        setType(new NUnknownType());

        NType targetType = resolveExpr(target, s);
        if (targetType.isUnionType()) {
            targetType = targetType.asUnionType().firstKnownNonNullAlternate();
            if (targetType == null) {
                return;
            }
        }

        targetType = targetType.follow();
        if (targetType == Indexer.idx.builtins.None) {
            return;
        }
        NBinding b = targetType.getTable().putAttr(attr.id, attr, v, ATTRIBUTE);
        if (b != null) {
            setType(attr.setType(b.followType()));
        }
    }
View Full Code Here

    @Override
    public NType resolve(Scope s) throws Exception {
        setType(new NUnknownType());

        NType targetType = resolveExpr(target, s);

        if (targetType.isUnionType()) {
            NType ret = new NUnknownType();
            for (NType tp : targetType.asUnionType().getTypes()) {
                resolveAttributeOnType(tp);
                ret = NUnionType.union(ret, getType());
            }
            setType(attr.setType(ret.follow()));
        } else {
            resolveAttributeOnType(targetType);
        }

        return getType();
View Full Code Here

        return getType();
    }

    private void resolveAttributeOnType(NType targetType) {
        NType ttype = targetType.follow();
        NBinding b = ttype.getTable().lookupAttr(attr.id);
        if (b == null) {
            b = makeProvisionalBinding(ttype);
        }
        if (b != null) {
            Indexer.idx.putLocation(attr, b);
View Full Code Here

        // is empty here.  For now, avoid an IndexingException.
        if ("".equals(targetScope.getPath())) {
            return null;
        }

        NType utype = new NUnknownType();
        NBinding b = targetScope.putAttr(attr.id, null, utype, ATTRIBUTE);
        if (b != null) {
            b.setProvisional(true);
            utype.getTable().setPath(b.getQname());
        }
        return b;
    }
View Full Code Here

        ensureTable();
        table.put(id, b);
    }

    private void updateType(NBinding b, NNode loc, NType type, NBinding.Kind kind) {
        NType curType = b.followType();
        if (!isNewType(curType, type)) {
            if (loc != null
                && !(loc instanceof NUrl)
                && !b.getDefs().contains(loc)) {
                Indexer.idx.putLocation(loc, b);
            }
            return;
        }

        if (loc != null && !b.getRefs().contains(loc)) {
            b.addDef(loc);
            b.setProvisional(false);
        }

        // The union ordering matters here.  If they're two different unknown
        // types, union() points the first one to the second one.  We want to
        // keep the binding's existing type iff its table contains provisional
        // attribute bindings that we need to look up later.
        NType btype = b.getType();
        NType t1, t2;
        if (btype.isUnknownType() && !btype.getTable().isEmpty()) {
            t1 = type;
            t2 = btype;
        } else {
            t1 = btype;
            t2 = type;
        }
        NType newType = NUnionType.union(t1, t2);
        b.setType(newType);

        if (curType.isUnknownType()) {
            b.setKind(kind);
        }
View Full Code Here

    public NType lookupType(String name, boolean localOnly) {
        NBinding b = localOnly ? lookupLocal(name) : lookup(name);
        if (b == null) {
            return null;
        }
        NType ret = b.followType();
        // XXX:  really need to make ModuleTable polymorphic...
        if (this == Indexer.idx.moduleTable) {
            if (ret.isModuleType()) {
                return ret;
            }
            if (ret.isUnionType()) {
                for (NType t : ret.asUnionType().getTypes()) {
                    NType realType = t.follow();
                    if (realType.isModuleType()) {
                        return realType;
                    }
                }
            }
            Indexer.idx.warn("Found non-module type in module table: " + b);
View Full Code Here

    @Override
    public NType resolve(Scope s) throws Exception {
        Scope scope = s.getScopeSymtab();
        for (NAlias a : aliases) {
            NType modtype = resolveExpr(a, s);
            if (modtype.isModuleType()) {
                importName(scope, a, modtype.asModuleType());
            }
        }
        return getType();
    }
View Full Code Here

        }
        if (bindings.isEmpty()) {
            return;
        }
        NBinding nb = bindings.get(0);
        NType t = nb.followType();
        if (t.isUnionType()) {
            t = t.asUnionType().firstKnownNonNullAlternate();
            if (t == null) {
                return;
            }
        }
        NType tt = t.follow();
        if (!tt.isUnknownType() && !tt.isFuncType()) {
            ref.markAsNew();
        }
    }
View Full Code Here

        Scope funcTable = new Scope(s.getEnclosingLexicalScope(), Scope.Type.FUNCTION);
        getType().setTable(funcTable);
        funcTable.setPath(owner.extendPath(getBindingName(owner)));

        // If we already defined this function in this scope, don't try it again.
        NType existing = owner.lookupType(getBindingName(owner), true /* local scope */);
        if (existing != null && existing.isFuncType()) {
            return;
        }

        bindFunctionName(owner);
        bindFunctionParams(funcTable);
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.