Esempio n. 1
0
        public CPythonType(IMemberContainer parent, ITypeDatabaseReader typeDb, string typeName, Dictionary<string, object> typeTable, BuiltinTypeId typeId) {
            Debug.Assert(parent is CPythonType || parent is CPythonModule);
            Debug.Assert(!typeId.IsVirtualId());

            _typeName = typeName;
            _typeId = typeId;
            _module = GetDeclaringModule(parent);

            object value;
            if (typeTable.TryGetValue("is_hidden", out value)) {
                _includeInModule = !Convert.ToBoolean(value);
            } else {
                _includeInModule = true;
            }

            if (typeTable.TryGetValue("doc", out value)) {
                _doc = value as string;
            }

            if (typeTable.TryGetValue("builtin", out value)) {
                _isBuiltin = Convert.ToBoolean(value);
            } else {
                _isBuiltin = true;
            }

            if (typeTable.TryGetValue("bases", out value)) {
                var basesList = (List<object>)value;
                if (basesList != null) {
                    _bases = new List<IPythonType>();
                    foreach (var baseType in basesList) {
                        typeDb.LookupType(baseType, StoreBase);
                    }
                }
            }

            if (typeTable.TryGetValue("mro", out value)) {
                var mroList = (List<object>)value;
                if (mroList != null && mroList.Count >= 1) {
                    _mro = new IPythonType[mroList.Count];
                    // Many scraped types have invalid MRO entries because they
                    // report their own module/name incorrectly. Since the first
                    // item in the MRO is always self, we set it now. If the MRO
                    // has a resolvable entry it will replace this one.
                    _mro[0] = this;
                    for (int i = 0; i < mroList.Count; ++i) {
                        var capturedI = i;
                        typeDb.LookupType(mroList[i], t => _mro[capturedI] = t);
                    }
                }
            }

            if (typeTable.TryGetValue("members", out value)) {
                var membersTable = (Dictionary<string, object>)value;
                if (membersTable != null) {
                    LoadMembers(typeDb, membersTable);
                }
            }

            _hasLocation = PythonTypeDatabase.TryGetLocation(typeTable, ref _line, ref _column);
        }
Esempio n. 2
0
        public CPythonFunction(ITypeDatabaseReader typeDb, string name, Dictionary<string, object> functionTable, IMemberContainer declaringType, bool isMethod = false) {
            _name = name;
            
            object doc;
            if (functionTable.TryGetValue("doc", out doc)) {
                _doc = doc as string;
            }

            object value;
            if (functionTable.TryGetValue("builtin", out value)) {
                _isBuiltin = Convert.ToBoolean(value);
            } else {
                _isBuiltin = true;
            }

            if (functionTable.TryGetValue("static", out value)) {
                _isStatic = Convert.ToBoolean(value);
            } else {
                _isStatic = true;
            }

            _hasLocation = PythonTypeDatabase.TryGetLocation(functionTable, ref _line, ref _column);

            _declaringModule = CPythonModule.GetDeclaringModuleFromContainer(declaringType);
            _declaringType = declaringType as IPythonType;

            if (functionTable.TryGetValue("overloads", out value)) {
                _overloads = LoadOverloads(typeDb, value, isMethod);
            }
        }
Esempio n. 3
0
 internal CPythonFunction(string name, string doc, bool isBuiltin, bool isStatic, IMemberContainer declaringType) {
     _name = name;
     _doc = doc;
     _isBuiltin = isBuiltin;
     _isStatic = isStatic;
     _declaringModule = CPythonModule.GetDeclaringModuleFromContainer(declaringType);
     _declaringType = declaringType as IPythonType;
     _overloads = new List<IPythonFunctionOverload>();
 }
Esempio n. 4
0
 internal CPythonFunction(string name, string doc, bool isBuiltin, bool isStatic, IMemberContainer declaringType)
 {
     _name            = name;
     _doc             = doc;
     _isBuiltin       = isBuiltin;
     _isStatic        = isStatic;
     _declaringModule = CPythonModule.GetDeclaringModuleFromContainer(declaringType);
     _declaringType   = declaringType as IPythonType;
     _overloads       = new List <IPythonFunctionOverload>();
 }
Esempio n. 5
0
        public CPythonFunction(ITypeDatabaseReader typeDb, string name, Dictionary <string, object> functionTable, IMemberContainer declaringType, bool isMethod = false)
        {
            _name = name;

            object doc;

            if (functionTable.TryGetValue("doc", out doc))
            {
                _doc = doc as string;
            }

            object value;

            if (functionTable.TryGetValue("builtin", out value))
            {
                _isBuiltin = Convert.ToBoolean(value);
            }
            else
            {
                _isBuiltin = true;
            }

            if (functionTable.TryGetValue("static", out value))
            {
                _isStatic = Convert.ToBoolean(value);
            }
            else
            {
                _isStatic = false;
            }

            if (functionTable.TryGetValue("classmethod", out value))
            {
                _isClassMethod = Convert.ToBoolean(value);
            }
            else
            {
                _isClassMethod = false;
            }

            _hasLocation = PythonTypeDatabase.TryGetLocation(functionTable, ref _line, ref _column);

            _declaringModule = CPythonModule.GetDeclaringModuleFromContainer(declaringType);
            _declaringType   = declaringType as IPythonType;

            if (functionTable.TryGetValue("overloads", out value))
            {
                _overloads = LoadOverloads(typeDb, value, isMethod);
            }
        }
Esempio n. 6
0
        public CPythonProperty(ITypeDatabaseReader typeDb, Dictionary<string, object> valueDict, IMemberContainer container) {
            _declaringModule = CPythonModule.GetDeclaringModuleFromContainer(container);

            object value;
            if (valueDict.TryGetValue("doc", out value)) {
                _doc = value as string;
            }

            object type;
            if (!valueDict.TryGetValue("type", out type) || type == null) {
                type = new[] { null, "object" };
            }

            _hasLocation = PythonTypeDatabase.TryGetLocation(valueDict, ref _line, ref _column);

            typeDb.LookupType(type, typeValue => _type = typeValue);
        }
Esempio n. 7
0
        public CPythonType(IMemberContainer parent, TypeDatabase typeDb, string typeName, Dictionary <string, object> typeTable, BuiltinTypeId typeId)
        {
            Debug.Assert(parent is CPythonType || parent is CPythonModule);

            _typeName = typeName;
            _typeId   = typeId;
            _module   = GetDeclaringModule(parent);

            object value;

            if (typeTable.TryGetValue("is_hidden", out value))
            {
                _includeInModule = !Convert.ToBoolean(value);
            }
            else
            {
                _includeInModule = true;
            }

            if (typeTable.TryGetValue("doc", out value))
            {
                _doc = value as string;
            }

            if (typeTable.TryGetValue("builtin", out value))
            {
                _isBuiltin = Convert.ToBoolean(value);
            }
            else
            {
                _isBuiltin = true;
            }

            object membersData;

            if (typeTable.TryGetValue("members", out membersData))
            {
                var membersTable = membersData as Dictionary <string, object>;
                if (membersTable != null)
                {
                    LoadMembers(typeDb, membersTable);
                }
            }
        }
        public CPythonProperty(ITypeDatabaseReader typeDb, Dictionary <string, object> valueDict, IMemberContainer container)
        {
            _declaringModule = CPythonModule.GetDeclaringModuleFromContainer(container);

            object value;

            if (valueDict.TryGetValue("doc", out value))
            {
                _doc = value as string;
            }

            object type;

            valueDict.TryGetValue("type", out type);

            _hasLocation = PythonTypeDatabase.TryGetLocation(valueDict, ref _line, ref _column);

            typeDb.LookupType(type, typeValue => _type = typeValue);
        }
Esempio n. 9
0
        public TypeDatabase(string databaseDirectory, bool is3x = false)
        {
            _dbDir = databaseDirectory;
            _modules["__builtin__"] = _builtinModule = new CPythonModule(this, "__builtin__", Path.Combine(databaseDirectory, is3x ? "builtins.idb" : "__builtin__.idb"), true);

            foreach (var file in Directory.GetFiles(databaseDirectory))
            {
                if (!file.EndsWith(".idb", StringComparison.OrdinalIgnoreCase))
                {
                    continue;
                }
                else if (String.Equals(Path.GetFileName(file), is3x ? "builtins.idb" : "__builtin__.idb", StringComparison.OrdinalIgnoreCase))
                {
                    continue;
                }

                string modName = Path.GetFileNameWithoutExtension(file);
                _modules[modName] = new CPythonModule(this, modName, file, false);
            }
        }
Esempio n. 10
0
        public CPythonFunction(TypeDatabase typeDb, string name, Dictionary <string, object> functionTable, IMemberContainer declaringType, bool isMethod = false)
        {
            _name = name;

            object doc;

            if (functionTable.TryGetValue("doc", out doc))
            {
                _doc = doc as string;
            }

            object value;

            if (functionTable.TryGetValue("builtin", out value))
            {
                _isBuiltin = Convert.ToBoolean(value);
            }
            else
            {
                _isBuiltin = true;
            }

            if (functionTable.TryGetValue("static", out value))
            {
                _isStatic = Convert.ToBoolean(value);
            }
            else
            {
                _isStatic = true;
            }

            _declaringModule = (declaringType as CPythonModule) ?? (CPythonModule)((CPythonType)declaringType).DeclaringModule;
            object overloads;

            functionTable.TryGetValue("overloads", out overloads);
            _overloads     = LoadOverloads(typeDb, overloads, isMethod);
            _declaringType = declaringType as CPythonType;
        }
Esempio n. 11
0
        internal void LoadDatabase(string databaseDirectory) {
            var addedModules = new Dictionary<string, IMember>();

            if (_dbDir == null) {
                _dbDir = databaseDirectory;
            }

            if (_builtinModule == null) {
                _builtinModule = MakeBuiltinModule(databaseDirectory);
            }
            _modules[_builtinName] = _builtinModule;
            if (_isDefaultDb && _langVersion.Major == 3) {
                _modules[BuiltinName2x] = _builtinModule;
            }

            foreach (var file in Directory.GetFiles(databaseDirectory)) {
                if (!file.EndsWith(".idb", StringComparison.OrdinalIgnoreCase) || file.IndexOf('$') != -1) {
                    continue;
                } else if (String.Equals(Path.GetFileNameWithoutExtension(file), _builtinName, StringComparison.OrdinalIgnoreCase)) {
                    continue;
                } else if (_isDefaultDb && String.Equals(Path.GetFileNameWithoutExtension(file), BuiltinName2x, StringComparison.OrdinalIgnoreCase)) {
                    continue;
                }

                string modName = Path.GetFileNameWithoutExtension(file);
                if (_isDefaultDb && _langVersion.Major == 3) {
                    // aliases for 3.x when using the default completion DB
                    switch (modName) {
                        case "cPickle": modName = "_pickle"; break;
                        case "thread": modName = "_thread"; break;
                    }
                }
                addedModules[modName] = _modules[modName] = new CPythonModule(this, modName, file, false);
            }

            foreach (var keyValue in addedModules) {
                List<Action<IMember>> fixups;
                if (_moduleFixups.TryGetValue(keyValue.Key, out fixups)) {
                    _moduleFixups.Remove(keyValue.Key);
                    foreach (var fixup in fixups) {
                        fixup(keyValue.Value);
                    }
                }
            }
        }
Esempio n. 12
0
        public CPythonType(IMemberContainer parent, ITypeDatabaseReader typeDb, string typeName, Dictionary <string, object> typeTable, BuiltinTypeId typeId)
        {
            Debug.Assert(parent is CPythonType || parent is CPythonModule);
            Debug.Assert(!typeId.IsVirtualId());

            _typeName = typeName;
            _typeId   = typeId;
            _module   = GetDeclaringModule(parent);

            object value;

            if (typeTable.TryGetValue("is_hidden", out value))
            {
                _includeInModule = !Convert.ToBoolean(value);
            }
            else
            {
                _includeInModule = true;
            }

            if (typeTable.TryGetValue("doc", out value))
            {
                _doc = value as string;
            }

            if (typeTable.TryGetValue("builtin", out value))
            {
                _isBuiltin = Convert.ToBoolean(value);
            }
            else
            {
                _isBuiltin = true;
            }

            if (typeTable.TryGetValue("bases", out value))
            {
                var basesList = (List <object>)value;
                if (basesList != null)
                {
                    _bases = new List <IPythonType>();
                    foreach (var baseType in basesList)
                    {
                        typeDb.LookupType(baseType, StoreBase);
                    }
                }
            }

            if (typeTable.TryGetValue("mro", out value))
            {
                var mroList = (List <object>)value;
                if (mroList != null && mroList.Count >= 1)
                {
                    _mro = new IPythonType[mroList.Count];
                    // Many scraped types have invalid MRO entries because they
                    // report their own module/name incorrectly. Since the first
                    // item in the MRO is always self, we set it now. If the MRO
                    // has a resolvable entry it will replace this one.
                    _mro[0] = this;
                    for (int i = 0; i < mroList.Count; ++i)
                    {
                        var capturedI = i;
                        typeDb.LookupType(mroList[i], t => _mro[capturedI] = t);
                    }
                }
            }

            if (typeTable.TryGetValue("members", out value))
            {
                var membersTable = (Dictionary <string, object>)value;
                if (membersTable != null)
                {
                    LoadMembers(typeDb, membersTable);
                }
            }

            _hasLocation = PythonTypeDatabase.TryGetLocation(typeTable, ref _line, ref _column);
        }