Exemple #1
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);
            }
        }
        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);
        }
Exemple #3
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);
        }