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 = false;//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);
            }
        }
 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>();
 }
Exemple #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>();
 }
        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);
#if FALSE
            _hasLocation = PythonTypeDatabase.TryGetLocation(valueDict, ref _line, ref _column);
#endif
            _hasLocation = false;

            typeDb.LookupType(type, typeValue => _type = typeValue);
        }
Exemple #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 = true;
            }

            _hasLocation = false;//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);
            }
        }
        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);
#if FALSE
            _hasLocation = PythonTypeDatabase.TryGetLocation(valueDict, ref _line, ref _column);
#endif
            _hasLocation = false;

            typeDb.LookupType(type, typeValue => _type = typeValue);
        }
Exemple #7
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 = false;//PythonTypeDatabase.TryGetLocation(typeTable, ref _line, ref _column);
        }
        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);
                    }
                }
            }
        }