Package org.python.indexer

Examples of org.python.indexer.Scope


    public void testClassTypeBuiltinAttrs() throws Exception {
        String file = "classtype_builtins.py";
        buildIndex(file);
        NModuleType module = (NModuleType)idx.moduleTable.lookupType(abspath(file));
        Scope mtable = module.getTable();
        assertTrue(mtable.lookupType("MyClass").isClassType());
        assertTrue(mtable.lookupType("MyClassNoDoc").isClassType());
        assertTrue(mtable.lookupType("MyClass").getTable().getParent() == mtable);
        assertEquals(NBinding.Kind.CLASS, mtable.lookup("MyClass").getKind());
        Scope t = mtable.lookupType("MyClass").getTable();
        assertTrue(t.lookupType("__bases__").isTupleType());
        assertTrue(t.lookupType("__dict__").isDictType());
        assertEquals(idx.builtins.BaseStr, t.lookupType("__name__"));
        assertEquals(idx.builtins.BaseStr, t.lookupType("__module__"));
        assertEquals(idx.builtins.BaseStr, t.lookupType("__doc__"));
        t = mtable.lookupType("MyClassNoDoc").getTable();
        assertEquals(idx.builtins.BaseStr, t.lookupType("__doc__"));
    }
View Full Code Here


    public void testMethodBuiltinAttrs() throws Exception {
        String file = "classtype_builtins.py";
        buildIndex(file);

        Scope mtable = idx.moduleTable.lookupType(abspath(file)).getTable();
        NBinding method = mtable.lookupType("MyClass").getTable().lookup("__init__");
        assertNotNull(method);
        assertEquals(NBinding.Kind.CONSTRUCTOR, method.getKind());
        assertEquals("classtype_builtins.MyClass.__init__", method.getQname());

        NType ftype = mtable.lookupType("MyClass").getTable().lookupType("__init__");
        assertTrue(ftype.isFuncType());

        NBinding c = mtable.lookup("MyClass");
        for (String special : new String[]{"im_class", "__class__", "im_self", "__self__"}) {
            NBinding attr = ftype.getTable().lookup(special);
            assertNotNull("missing binding for " + special, attr);
            assertEquals(c.getType(), attr.getType());
        }
View Full Code Here

    private NBinding makeProvisionalBinding(NType targetType) {
        if (targetType.isNative()) {
            return null;
        }

        Scope targetScope = targetType.getTable();

        // XXX:  Eventually we need to fix out all the cases where the path is
        // 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

        }
    }

    @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());
            }
View Full Code Here

        return name.id;
    }

    @Override
    protected void bindNames(Scope s) throws Exception {
        Scope owner = s.getScopeSymtab()// enclosing class, function or module

        setType(new NFuncType());
        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;
View Full Code Here

    @Override
    public NType resolve(Scope outer) throws Exception {
        resolveList(defaults, outer);
        resolveList(decoratorList, outer);

        Scope funcTable = getTable();
        NBinding selfBinding = funcTable.lookup("__self__");
        if (selfBinding != null && !selfBinding.getType().isClassType()) {
            selfBinding = null;
        }

        if (selfBinding != null) {
            if (args.size() < 1) {
                addWarning(name, "method should have at least one argument (self)");
            } else if (!(args.get(0) instanceof NName)) {
                addError(name, "self parameter must be an identifier");
            }
        }

        NTupleType fromType = new NTupleType();
        bindParamsToDefaults(selfBinding, fromType);

        if (varargs != null) {
            NBinding b = funcTable.lookupLocal(varargs.id);
            if (b != null) {
                fromType.add(b.getType());
            }
        }

        if (kwargs != null) {
            NBinding b = funcTable.lookupLocal(kwargs.id);
            if (b != null) {
                fromType.add(b.getType());
            }
        }
View Full Code Here

        return getType();
    }

    private void bindParamsToDefaults(NBinding selfBinding, NTupleType fromType) throws Exception {
        NameBinder param = NameBinder.make(PARAMETER);
        Scope funcTable = getTable();

        for (int i = 0; i < args.size(); i++) {
            NNode arg = args.get(i);
            NType argtype = ((i == 0 && selfBinding != null)
                             ? selfBinding.getType()
View Full Code Here

            qname = Util.moduleQname(file);
        }
        if (qname == null) {
            qname = name;
        }
        setTable(new Scope(parent, Scope.Type.MODULE));
        getTable().setPath(qname);

        // null during bootstrapping of built-in types
        if (Indexer.idx.builtins != null) {
            getTable().addSuper(Indexer.idx.builtins.BaseModule.getTable());
View Full Code Here

            Indexer.idx.reportFailedAssertion("Found non-module type for "
                                              + this + " in " + getFile() + ": " + thisType);
            return;
        }

        Scope table = mtype.getTable();
        for (NStr nstr : getExportedNameNodes()) {
            String name = nstr.n.toString();
            NBinding b = table.lookupLocal(name);
            if (b != null) {
                Indexer.idx.putLocation(nstr, b);
            }
        }
    }
View Full Code Here

        return true;
    }

    @Override
    protected void bindNames(Scope s) throws Exception {
        Scope container = s.getScopeSymtab();
        setType(new NClassType(name.id, container));

        // If we already defined this class in this scope, don't redefine it.
        NType existing = container.lookupType(name.id);
        if (existing != null && existing.isClassType()) {
            return;
        }

        NameBinder.make(NBinding.Kind.CLASS).bind(container, name, getType());
View Full Code Here

TOP

Related Classes of org.python.indexer.Scope

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.