示例#1
0
        public IPythonType GetBuiltinType(BuiltinTypeId id)
        {
            IPythonType res;

            lock (_builtinTypes) {
                if (!_builtinTypes.TryGetValue(id, out res))
                {
                    var bm = ImportModule(BuiltinModuleName) as AstBuiltinsPythonModule;
                    res = bm?.GetAnyMember($"__{id}") as IPythonType;
                    if (res == null)
                    {
                        var name = SharedDatabaseState.GetBuiltinTypeName(id, _factory.Configuration.Version);
                        if (string.IsNullOrEmpty(name))
                        {
                            Debug.Assert(id == BuiltinTypeId.Unknown, $"no name for {id}");
                            if (!_builtinTypes.TryGetValue(BuiltinTypeId.Unknown, out res))
                            {
                                _builtinTypes[BuiltinTypeId.Unknown] = res = new AstPythonType("<unknown>");
                            }
                        }
                        else
                        {
                            res = new AstPythonType(name);
                        }
                    }
                    _builtinTypes[id] = res;
                }
            }
            return(res);
        }
示例#2
0
        public IPythonType GetBuiltinType(BuiltinTypeId id)
        {
            IPythonType res;

            lock (_builtinTypes) {
                if (!_builtinTypes.TryGetValue(id, out res))
                {
                    _builtinTypes[id] = res =
                        _builtinModule?.GetAnyMember(SharedDatabaseState.GetBuiltinTypeName(id, _factory.Configuration.Version)) as IPythonType ??
                        new AstPythonType(id.ToString());
                }
            }
            return(res);
        }
示例#3
0
        public KnownTypesView(IPythonInterpreter interpreter, Version version)
        {
            int count = (int)BuiltinTypeIdExtensions.LastTypeId;

            _children = new IAnalysisItemView[count];
            for (int value = 1; value <= count; ++value)
            {
                var    expectedName = SharedDatabaseState.GetBuiltinTypeName((BuiltinTypeId)value, version);
                string name         = string.Format("{0} ({1})",
                                                    expectedName,
                                                    Enum.GetName(typeof(BuiltinTypeId), value)
                                                    );

                IPythonType type;
                try {
                    type = interpreter.GetBuiltinType((BuiltinTypeId)value);
                    if (expectedName != type.Name)
                    {
                        name = string.Format("{2} ({1}/{0})",
                                             expectedName,
                                             Enum.GetName(typeof(BuiltinTypeId), value),
                                             type.Name
                                             );
                    }
                } catch {
                    type = null;
                }

                if (type != null)
                {
                    _children[value - 1] = new ClassView(
                        null,
                        name,
                        type
                        );
                }
                else
                {
                    _children[value - 1] = new NullMember(name);
                }
            }
        }
示例#4
0
        public IPythonType GetBuiltinType(BuiltinTypeId id)
        {
            if (id == BuiltinTypeId.Unknown)
            {
                return(null);
            }

            if (_typeDb == null)
            {
                throw new KeyNotFoundException(string.Format("{0} ({1})", id, (int)id));
            }

            var name = SharedDatabaseState.GetBuiltinTypeName(id, _typeDb.LanguageVersion);
            var res  = _typeDb.BuiltinModule.GetAnyMember(name) as IPythonType;

            if (res == null)
            {
                throw new KeyNotFoundException(string.Format("{0} ({1})", id, (int)id));
            }
            return(res);
        }
示例#5
0
 public FallbackBuiltinPythonType(PythonLanguageVersion version, BuiltinTypeId typeId)
 {
     DeclaringModule = version.Is3x() ? FallbackBuiltinModule.Instance3x : FallbackBuiltinModule.Instance2x;
     Name            = SharedDatabaseState.GetBuiltinTypeName(typeId, version.ToVersion());
     TypeId          = typeId;
 }
 public CPythonBuiltinModule(SharedDatabaseState typeDb, string moduleName, string filename, bool isBuiltin)
     : base(typeDb, moduleName, filename, isBuiltin)
 {
 }
 public CPythonBuiltinModule(SharedDatabaseState typeDb, string moduleName, string filename, bool isBuiltin)
     : base(typeDb, moduleName, filename, isBuiltin) {
 }