public KnownTypes(PythonAnalyzer state)
        {
            ITypeDatabaseReader  fallbackDb = null;
            IBuiltinPythonModule fallback   = null;

            int count = (int)BuiltinTypeIdExtensions.LastTypeId + 1;

            _types      = new IPythonType[count];
            _classInfos = new BuiltinClassInfo[count];

            var interpreter = state.Interpreter;

            for (int value = 0; value < count; ++value)
            {
                try {
                    _types[value] = interpreter.GetBuiltinType((BuiltinTypeId)value);
                } catch (KeyNotFoundException) {
                    if (fallback == null)
                    {
                        var tempDb = PythonTypeDatabase.CreateDefaultTypeDatabase(state.LanguageVersion.ToVersion());
                        fallbackDb = (ITypeDatabaseReader)tempDb;
                        fallback   = tempDb.BuiltinModule;
                    }

                    _types[value] = fallback.GetAnyMember(fallbackDb.GetBuiltinTypeName((BuiltinTypeId)value)) as IPythonType;
                }
                if (_types[value] != null)
                {
                    _classInfos[value] = state.GetBuiltinType(_types[value]);
                }
            }
        }
Exemplo n.º 2
0
 private void SetClassInfo(PythonAnalyzer state)
 {
     for (int value = 0; value < _types.Length; ++value)
     {
         if (_types[value] != null)
         {
             _classInfos[value] = state.GetBuiltinType(_types[value]);
         }
     }
 }
Exemplo n.º 3
0
        private void RecomputeBaseSpecialization()
        {
            IAnalysisSet builtinClassSet = AnalysisSet.Empty;

            foreach (var classInfo in _mro)
            {
                BuiltinClassInfo builtin = classInfo as BuiltinClassInfo;
                if (builtin != null && builtin.TypeId != BuiltinTypeId.Object)
                {
                    var builtinType = _projectState.GetBuiltinType(builtin.PythonType);

                    if (builtinType.GetType() != typeof(BuiltinClassInfo))
                    {
                        // we have a specialized built-in class, we want its behavior too...
                        builtinClassSet = builtinClassSet.Union(builtinType.SelfSet, true);
                    }
                }
            }
            _baseSpecialization = builtinClassSet;
        }