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; } } } }
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; } } } }
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); }
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); } }
public CJFunction(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 = JTypeDatabase.TryGetLocation(functionTable, ref _line, ref _column); _declaringModule = CJModule.GetDeclaringModuleFromContainer(declaringType); object overloads; functionTable.TryGetValue("overloads", out overloads); _overloads = LoadOverloads(typeDb, overloads, isMethod); _declaringType = declaringType as IJType; }
public CJModule(ITypeDatabaseReader typeDb, string moduleName, string databaseFilename, bool isBuiltin) { _modName = moduleName; _dbFile = databaseFilename; _typeDb = typeDb; _isBuiltin = isBuiltin; }
public CPythonMethodDescriptor(ITypeDatabaseReader typeDb, string name, Dictionary<string, object> valueDict, IMemberContainer declaringType) { _name = name; _func = new CPythonFunction(typeDb, name, valueDict, declaringType, isMethod: true); object value; if (valueDict.TryGetValue("bound", out value)) { _isBound = (value as bool?) ?? false; } }
private List<IPythonFunctionOverload> LoadOverloads(ITypeDatabaseReader typeDb, object data, bool isMethod) { var overloads = data as List<object>; if (overloads != null) { return overloads .OfType<Dictionary<string, object>>() .Select(o => new CPythonFunctionOverload(typeDb, this, o, isMethod)) .ToList<IPythonFunctionOverload>(); } return EmptyOverloads; }
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 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)); } } }
public CPythonMultipleMembers(IMemberContainer container, ITypeDatabaseReader typeDb, string name, IEnumerable<object> members) { _members = new List<IMember>(); _memberNames = members.OfType<Dictionary<string, object>>().ToList<object>(); _memberObjects = new IMember[_memberNames.Count]; // Copy the count because _memberNames may be cleared before the // loop finishes executing. int count = _memberNames.Count; for (int i = 0; i < count; ++i) { var capturedI = i; typeDb.ReadMember(name, (Dictionary<string, object>)_memberNames[i], (_, member) => AddType(capturedI, member), container); } }
private void LoadMembers(ITypeDatabaseReader typeDb, Dictionary <string, object> membersTable) { foreach (var memberEntry in membersTable) { var memberName = memberEntry.Key; var memberValue = memberEntry.Value as Dictionary <string, object>; if (memberValue != null) { _members[memberName] = null; typeDb.ReadMember(memberName, memberValue, StoreMember, this); } } }
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)); } } }
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 CPythonMultipleMembers(IMemberContainer container, ITypeDatabaseReader typeDb, string name, IEnumerable <object> members) { _members = new List <IMember>(); _memberNames = members.OfType <Dictionary <string, object> >().ToList <object>(); _memberObjects = new IMember[_memberNames.Count]; // Copy the count because _memberNames may be cleared before the // loop finishes executing. int count = _memberNames.Count; for (int i = 0; i < count; ++i) { var capturedI = i; typeDb.ReadMember(name, (Dictionary <string, object>)_memberNames[i], (_, member) => AddType(capturedI, member), container); } }
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); }
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 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); }
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); }
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; } } } }
public CJMethodDescriptor(ITypeDatabaseReader typeDb, string name, Dictionary<string, object> valueDict, IMemberContainer declaringType) { _name = name; _func = new CJFunction(typeDb, name, valueDict, declaringType, isMethod: true); }
private void LoadMembers(ITypeDatabaseReader typeDb, Dictionary<string, object> membersTable) { foreach (var memberEntry in membersTable) { var memberName = memberEntry.Key; var memberValue = memberEntry.Value as Dictionary<string, object>; if (memberValue != null) { typeDb.ReadMember(memberName, memberValue, StoreMember, this); } } }
private CJFunctionOverload LoadOverload(ITypeDatabaseReader typeDb, object overloadObj, bool isMethod) { return new CJFunctionOverload(typeDb, overloadObj as Dictionary<string, object>, isMethod); }
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); }
private CJFunctionOverload[] LoadOverloads(ITypeDatabaseReader typeDb, object overloads, bool isMethod) { var overloadsArr = overloads as IList<object>; if (overloadsArr != null) { CJFunctionOverload[] res = new CJFunctionOverload[overloadsArr.Count]; for (int i = 0; i < overloadsArr.Count; i++) { res[i] = LoadOverload(typeDb, overloadsArr[i], isMethod); } return res; } return EmptyOverloads; }