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 CJType(IMemberContainer parent, ITypeDatabaseReader typeDb, string typeName, Dictionary<string, object> typeTable, BuiltinTypeId typeId)
        {
            Debug.Assert(parent is CJType || parent is CJModule);

            _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 = value as List<object>;
                if (basesList != null) {
                    _bases = new List<IJType>();
                    foreach (var baseType in basesList) {
                        typeDb.LookupType(baseType, StoreBase);
                    }
                }
            }

            if (typeTable.TryGetValue("mro", out value)) {
                var mroList = value as List<object>;
                if (mroList != null) {
                    _mro = new List<CJType>();
                    foreach (var mroType in mroList) {
                        typeDb.LookupType(mroType, StoreMro);
                    }
                }
            }

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

            _hasLocation = JTypeDatabase.TryGetLocation(typeTable, ref _line, ref _column);
        }
        public CPythonParameterInfo(ITypeDatabaseReader typeDb, Dictionary<string, object> parameterTable) {
            if (parameterTable != null) {
                object value;

                if (parameterTable.TryGetValue("type", out value)) {
                    _type = new List<IPythonType>();
                    typeDb.LookupType(value, type => _type.Add(type));
                }
                
                if (parameterTable.TryGetValue("name", out value)) {
                    _name = value as string;
                }

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

                if (parameterTable.TryGetValue("default_value", out value)) {
                    _defaultValue = value as string;
                }
                
                if (parameterTable.TryGetValue("arg_format", out value)) {
                    switch (value as string) {
                        case "*": _isSplat = true; break;
                        case "**": _isKeywordSplat = true; break;
                    }

                }
            }
        }
Esempio n. 4
0
        internal void AssignTypes(ITypeDatabaseReader typeDb, Action <IPythonType> assign)
        {
            var names   = _memberNames;
            var objects = _memberObjects;

            if (names == null || objects == null)
            {
                foreach (var member in _members.OfType <IPythonType>())
                {
                    assign(member);
                }
            }
            else
            {
                for (int i = 0; i < names.Count; ++i)
                {
                    IPythonType type;
                    if ((type = objects[i] as IPythonType) != null)
                    {
                        assign(type);
                    }
                    else if (objects[i] == null)
                    {
                        typeDb.LookupType(names[i], assign);
                    }
                }
            }
        }
Esempio n. 5
0
        public CJParameterInfo(ITypeDatabaseReader typeDb, Dictionary<string, object> parameterTable)
        {
            if (parameterTable != null) {
                object typeObj;

                if (parameterTable.TryGetValue("type", out typeObj)) {
                    typeDb.LookupType(typeObj, (value, fromInstanceDb) => _type = value);
                }
                _typeObj = typeObj;

                object nameObj;
                if (parameterTable.TryGetValue("name", out nameObj)) {
                    _name = nameObj as string;
                }

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

                object defaultValueObj;
                if (parameterTable.TryGetValue("default_value", out defaultValueObj)) {
                    _defaultValue = defaultValueObj as string;
                }

                object argFormatObj;
                if (parameterTable.TryGetValue("arg_format", out argFormatObj)) {
                    switch (argFormatObj as string) {
                        case "*": _isSplat = true; break;
                        case "**": _isKeywordSplat = true; break;
                    }

                }
            }
        }
Esempio n. 6
0
        public CJFunctionOverload(ITypeDatabaseReader typeDb, Dictionary<string, object> argInfo, bool isMethod)
        {
            if (argInfo != null) {
                object args;
                IList<object> argList;
                if (argInfo.TryGetValue("args", out args)) {
                    argList = (IList<object>)args;
                    if (argList != null) {
                        if (argList.Count == 0 || (isMethod && argList.Count == 1)) {
                            _parameters = EmptyParameters;
                        } else {
                            _parameters = new CJParameterInfo[isMethod ? argList.Count - 1 : argList.Count];
                            for (int i = 0; i < _parameters.Length; i++) {
                                _parameters[i] = new CJParameterInfo(typeDb, (isMethod ? argList[i + 1] : argList[i]) as Dictionary<string, object>);
                            }
                        }
                    }
                }

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

                if (argInfo.TryGetValue("return_doc", out docObj)) {
                    _returnDoc = docObj as string;
                }

                object retTypeObj;
                argInfo.TryGetValue("ret_type", out retTypeObj);

                typeDb.LookupType(retTypeObj, (value, fromInstanceDb) => _retType = value);
            }
        }
Esempio n. 7
0
        public CPythonSequenceType(IPythonType baseType, ITypeDatabaseReader typeDb, List<object> indexTypes) {
            _type = baseType;

            if (indexTypes != null) {
                _indexTypes = new List<IPythonType>();

                foreach (var indexType in indexTypes) {
                    typeDb.LookupType(indexType, type => _indexTypes.Add(type));
                }
            }
        }
Esempio n. 8
0
        public CPythonSequenceType(IPythonType baseType, ITypeDatabaseReader typeDb, List <object> indexTypes)
        {
            _type = baseType;

            if (indexTypes != null)
            {
                _indexTypes = new List <IPythonType>();

                foreach (var indexType in indexTypes)
                {
                    typeDb.LookupType(indexType, type => _indexTypes.Add(type));
                }
            }
        }
Esempio n. 9
0
        public CJProperty(ITypeDatabaseReader typeDb, Dictionary<string, object> valueDict, IMemberContainer container)
        {
            _declaringModule = CJModule.GetDeclaringModuleFromContainer(container);

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

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

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

            typeDb.LookupType(type, (typeValue, fromInstanceDb) => _type = typeValue);
        }
Esempio n. 10
0
        public CPythonFunctionOverload(
            ITypeDatabaseReader typeDb,
            CPythonFunction function,
            Dictionary <string, object> argInfo,
            bool isMethod
            )
        {
            _parameters = EmptyParameters;

            if (argInfo != null)
            {
                object   args;
                object[] argList;
                if (argInfo.TryGetValue("args", out args) && (argList = args as object[]) != null)
                {
                    if ((isMethod && argList.Length > 1) || (!isMethod && argList.Length > 0))
                    {
                        _parameters = argList.Skip(isMethod ? 1 : 0)
                                      .OfType <Dictionary <string, object> >()
                                      .Select(arg => new CPythonParameterInfo(typeDb, arg))
                                      .ToArray();
                    }
                }

                object docObj;
                if (argInfo.TryGetValue("doc", out docObj))
                {
                    _doc = docObj as string;
                }
                if (string.IsNullOrEmpty(_doc))
                {
                    _doc = function.Documentation;
                }

                if (argInfo.TryGetValue("return_doc", out docObj))
                {
                    _returnDoc = docObj as string;
                }

                object retType;
                if (argInfo.TryGetValue("ret_type", out retType))
                {
                    _retType = new List <IPythonType>();
                    typeDb.LookupType(retType, value => _retType.Add(value));
                }
            }
        }
Esempio n. 11
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. 12
0
        internal void AssignTypes(ITypeDatabaseReader typeDb, Action<IPythonType> assign) {
            var names = _memberNames;
            var objects = _memberObjects;

            if (names == null || objects == null) {
                foreach (var member in _members.OfType<IPythonType>()) {
                    assign(member);
                }
            } else {
                for (int i = 0; i < names.Count; ++i) {
                    IPythonType type;
                    if ((type = objects[i] as IPythonType) != null) {
                        assign(type);
                    } else if (objects[i] == null) {
                        typeDb.LookupType(names[i], assign);
                    }
                }
            }
        }
        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. 14
0
        public CPythonFunctionOverload(
            ITypeDatabaseReader typeDb,
            CPythonFunction function,
            Dictionary<string, object> argInfo,
            bool isMethod
        ) {
            _parameters = EmptyParameters;

            if (argInfo != null) {
                object args;
                object[] argList;
                if (argInfo.TryGetValue("args", out args) && (argList = args as object[]) != null) {
                    if ((isMethod && argList.Length > 1) || (!isMethod && argList.Length > 0)) {
                        _parameters = argList.Skip(isMethod ? 1 : 0)
                            .OfType<Dictionary<string, object>>()
                            .Select(arg => new CPythonParameterInfo(typeDb, arg))
                            .ToArray();
                    }
                }

                object docObj;
                if (argInfo.TryGetValue("doc", out docObj)) {
                    _doc = docObj as string;
                }
                if (string.IsNullOrEmpty(_doc)) {
                    _doc = function.Documentation;
                }

                if (argInfo.TryGetValue("return_doc", out docObj)) {
                    _returnDoc = docObj as string;
                }

                object retType;
                if (argInfo.TryGetValue("ret_type", out retType)) {
                    _retType = new List<IPythonType>();
                    typeDb.LookupType(retType, value => _retType.Add(value));
                }
            }
        }
        public CPythonParameterInfo(ITypeDatabaseReader typeDb, Dictionary <string, object> parameterTable)
        {
            if (parameterTable != null)
            {
                object value;

                if (parameterTable.TryGetValue("type", out value))
                {
                    _type = new List <IPythonType>();
                    typeDb.LookupType(value, type => _type.Add(type));
                }

                if (parameterTable.TryGetValue("name", out value))
                {
                    _name = value as string;
                }

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

                if (parameterTable.TryGetValue("default_value", out value))
                {
                    _defaultValue = value as string;
                }

                if (parameterTable.TryGetValue("arg_format", out value))
                {
                    switch (value as string)
                    {
                    case "*": _isSplat = true; break;

                    case "**": _isKeywordSplat = true; break;
                    }
                }
            }
        }
Esempio n. 16
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);
        }