public BaseAnalysisTest(IPythonInterpreterFactory factory, IPythonInterpreter interpreter) { InterpreterFactory = factory; Interpreter = interpreter; var objectType = Interpreter.GetBuiltinType(BuiltinTypeId.Object); Assert.IsNotNull(objectType); var intType = Interpreter.GetBuiltinType(BuiltinTypeId.Int); var bytesType = Interpreter.GetBuiltinType(BuiltinTypeId.Bytes); var listType = Interpreter.GetBuiltinType(BuiltinTypeId.List); var functionType = Interpreter.GetBuiltinType(BuiltinTypeId.Function); _objectMembers = objectType.GetMemberNames(DefaultContext).ToArray(); _strMembers = bytesType.GetMemberNames(DefaultContext).ToArray(); _listMembers = listType.GetMemberNames(DefaultContext).ToArray(); _intMembers = intType.GetMemberNames(DefaultContext).ToArray(); _functionMembers = functionType.GetMemberNames(DefaultContext).ToArray(); }
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); } } }
public BaseAnalysisTest(IPythonInterpreterFactory factory, IPythonInterpreter interpreter) { InterpreterFactory = factory; Interpreter = interpreter; var objectType = Interpreter.GetBuiltinType(BuiltinTypeId.Object); Assert.IsNotNull(objectType); var intType = Interpreter.GetBuiltinType(BuiltinTypeId.Int); var bytesType = Interpreter.GetBuiltinType(BuiltinTypeId.Bytes); var listType = Interpreter.GetBuiltinType(BuiltinTypeId.List); var functionType = Interpreter.GetBuiltinType(BuiltinTypeId.Function); _objectMembers = objectType.GetMemberNames(DefaultContext).ToArray(); _strMembers = bytesType.GetMemberNames(DefaultContext).ToArray(); _listMembers = listType.GetMemberNames(DefaultContext).ToArray(); _intMembers = intType.GetMemberNames(DefaultContext).ToArray(); _functionMembers = functionType.GetMemberNames(DefaultContext).ToArray(); }
internal void SetBases(IPythonInterpreter interpreter, IEnumerable <IPythonType> bases) { if (Bases != null) { throw new InvalidOperationException("cannot set Bases multiple times"); } Bases = bases.MaybeEnumerate().ToArray(); lock (_members) { if (Bases.Count > 0) { _members["__base__"] = Bases[0]; } _members["__bases__"] = new AstPythonSequence( interpreter?.GetBuiltinType(BuiltinTypeId.Tuple), DeclaringModule, Bases, interpreter?.GetBuiltinType(BuiltinTypeId.TupleIterator) ); } }
internal void SetBases(IPythonInterpreter interpreter, IEnumerable <IPythonType> bases) { lock (_members) { if (Bases != null) { return; // Already set } Bases = bases.MaybeEnumerate().ToArray(); if (Bases.Count > 0) { _members["__base__"] = Bases[0]; } _members["__bases__"] = new AstPythonSequence( interpreter?.GetBuiltinType(BuiltinTypeId.Tuple), DeclaringModule, Bases, interpreter?.GetBuiltinType(BuiltinTypeId.TupleIterator) ); } }
public PythonAnalyzer(IPythonInterpreter pythonInterpreter, PythonLanguageVersion langVersion) { _langVersion = langVersion; _interpreter = pythonInterpreter; _modules = new Dictionary <string, ModuleReference>(); _modulesByFilename = new Dictionary <string, ModuleInfo>(StringComparer.OrdinalIgnoreCase); _itemCache = new Dictionary <object, object>(); InitializeBuiltinModules(); pythonInterpreter.ModuleNamesChanged += new EventHandler(ModuleNamesChanged); _types = new KnownTypes(this); _builtinModule = (BuiltinModule)Modules["__builtin__"].Module; _propertyObj = GetBuiltin("property"); _classmethodObj = GetBuiltin("classmethod"); _staticmethodObj = GetBuiltin("staticmethod"); _typeObj = GetBuiltin("type"); _intType = GetBuiltin("int"); _stringType = (BuiltinClassInfo)GetBuiltin("str"); _objectSet = new HashSet <Namespace>(new[] { GetBuiltin("object") }); _setType = (BuiltinClassInfo)GetNamespaceFromObjects(_interpreter.GetBuiltinType(BuiltinTypeId.Set)); _rangeFunc = GetBuiltin("range"); _frozensetType = GetBuiltin("frozenset"); _functionType = GetNamespaceFromObjects(_interpreter.GetBuiltinType(BuiltinTypeId.Function)); _generatorType = (BuiltinClassInfo)GetNamespaceFromObjects(_interpreter.GetBuiltinType(BuiltinTypeId.Generator)); _dictType = (BuiltinClassInfo)GetNamespaceFromObjects(_interpreter.GetBuiltinType(BuiltinTypeId.Dict)); _boolType = (BuiltinClassInfo)GetNamespaceFromObjects(_interpreter.GetBuiltinType(BuiltinTypeId.Bool)); _noneInst = (ConstantInfo)GetNamespaceFromObjects(null); _listType = (BuiltinClassInfo)GetNamespaceFromObjects(_interpreter.GetBuiltinType(BuiltinTypeId.List)); _tupleType = (BuiltinClassInfo)GetNamespaceFromObjects(_interpreter.GetBuiltinType(BuiltinTypeId.Tuple)); _queue = new Deque <AnalysisUnit>(); SpecializeFunction("__builtin__", "range", (n, unit, args) => unit.DeclaringModule.GetOrMakeNodeVariable(n, (nn) => new RangeInfo(_types.List, unit.ProjectState).SelfSet)); SpecializeFunction("__builtin__", "min", ReturnUnionOfInputs); SpecializeFunction("__builtin__", "max", ReturnUnionOfInputs); pythonInterpreter.Initialize(this); _defaultContext = pythonInterpreter.CreateModuleContext(); // cached for quick checks to see if we're a call to clr.AddReference try { SpecializeFunction("wpf", "LoadComponent", LoadComponent); } catch (KeyNotFoundException) { // IronPython.Wpf.dll isn't available... } }
public AstAnalysisWalker( IPythonInterpreter interpreter, PythonAst ast, IPythonModule module, string filePath, Dictionary<string, IMember> members ) { _interpreter = interpreter; _ast = ast; _module = module; _filePath = filePath; _members = members; _scope = new Stack<Dictionary<string, IMember>>(); _noneInst = new AstPythonConstant(_interpreter.GetBuiltinType(BuiltinTypeId.NoneType)); }
public AstAnalysisWalker( IPythonInterpreter interpreter, PythonAst ast, IPythonModule module, string filePath, Dictionary <string, IMember> members ) { _interpreter = interpreter; _ast = ast; _module = module; _filePath = filePath; _members = members; _scope = new Stack <Dictionary <string, IMember> >(); _noneInst = new AstPythonConstant(_interpreter.GetBuiltinType(BuiltinTypeId.NoneType)); }
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); } } }
public PythonFString(string unparsedFString, IPythonInterpreter interpreter, LocationInfo location = null) : base(interpreter.GetBuiltinType(interpreter.GetUnicodeTypeId()), location) { UnparsedFString = unparsedFString; }
private IPythonType GetTypeFromExpression(Expression expr) { var ce = expr as ConstantExpression; if (ce != null) { if (ce.Value == null) { return(_interpreter.GetBuiltinType(BuiltinTypeId.NoneType)); } switch (Type.GetTypeCode(ce.Value.GetType())) { case TypeCode.Boolean: return(_interpreter.GetBuiltinType(BuiltinTypeId.Bool)); case TypeCode.Double: return(_interpreter.GetBuiltinType(BuiltinTypeId.Float)); case TypeCode.Int32: return(_interpreter.GetBuiltinType(BuiltinTypeId.Int)); case TypeCode.String: return(_interpreter.GetBuiltinType(BuiltinTypeId.Unicode)); case TypeCode.Object: if (ce.Value.GetType() == typeof(Complex)) { return(_interpreter.GetBuiltinType(BuiltinTypeId.Complex)); } else if (ce.Value.GetType() == typeof(AsciiString)) { return(_interpreter.GetBuiltinType(BuiltinTypeId.Bytes)); } else if (ce.Value.GetType() == typeof(BigInteger)) { return(_interpreter.GetBuiltinType(BuiltinTypeId.Long)); } else if (ce.Value.GetType() == typeof(Ellipsis)) { return(_interpreter.GetBuiltinType(BuiltinTypeId.Ellipsis)); } break; } return(null); } if (expr is ListExpression || expr is ListComprehension) { return(_interpreter.GetBuiltinType(BuiltinTypeId.List)); } if (expr is DictionaryExpression || expr is DictionaryComprehension) { return(_interpreter.GetBuiltinType(BuiltinTypeId.Dict)); } if (expr is TupleExpression) { return(_interpreter.GetBuiltinType(BuiltinTypeId.Tuple)); } if (expr is SetExpression || expr is SetComprehension) { return(_interpreter.GetBuiltinType(BuiltinTypeId.Set)); } if (expr is LambdaExpression) { return(_interpreter.GetBuiltinType(BuiltinTypeId.Function)); } return(null); }
public PythonAsciiString(AsciiString s, IPythonInterpreter interpreter) : base(s, interpreter.GetBuiltinType(interpreter.GetAsciiTypeId())) { }
public override IPythonIterator GetIterator() => new PythonRepeatingIterator(_interpreter.GetBuiltinType(BuiltinTypeId.SetIterator), _yieldValue);
public PythonUnicodeString(string s, IPythonInterpreter interpreter) : base(s, interpreter.GetBuiltinType(interpreter.GetUnicodeTypeId())) { }
internal IPythonType GetPythonType(BuiltinTypeId id) { return(_interpreter.GetBuiltinType(id)); }
public PythonGenerator(IPythonInterpreter interpreter, IMember yieldValue) : base(interpreter.GetBuiltinType(BuiltinTypeId.Generator), yieldValue) { _interpreter = interpreter; _yieldValue = yieldValue; }
public PythonFString(string unparsedFString, IPythonInterpreter interpreter) : base(interpreter.GetBuiltinType(interpreter.GetUnicodeTypeId())) { UnparsedFString = unparsedFString; }
public BaseAnalysisTest(IPythonInterpreter interpreter) { Interpreter = interpreter; PyObjectType = Interpreter.GetBuiltinType(BuiltinTypeId.Object); IntType = Interpreter.GetBuiltinType(BuiltinTypeId.Int); ComplexType = Interpreter.GetBuiltinType(BuiltinTypeId.Complex); StringType = Interpreter.GetBuiltinType(BuiltinTypeId.Str); FloatType = Interpreter.GetBuiltinType(BuiltinTypeId.Float); TypeType = Interpreter.GetBuiltinType(BuiltinTypeId.Type); ListType = Interpreter.GetBuiltinType(BuiltinTypeId.List); TupleType = Interpreter.GetBuiltinType(BuiltinTypeId.Tuple); BoolType = Interpreter.GetBuiltinType(BuiltinTypeId.Bool); FunctionType = Interpreter.GetBuiltinType(BuiltinTypeId.Function); GeneratorType = Interpreter.GetBuiltinType(BuiltinTypeId.Generator); _objectMembers = PyObjectType.GetMemberNames(IronPythonModuleContext.DontShowClrInstance).ToArray(); _strMembers = StringType.GetMemberNames(IronPythonModuleContext.DontShowClrInstance).ToArray(); _listMembers = ListType.GetMemberNames(IronPythonModuleContext.DontShowClrInstance).ToArray(); _intMembers = IntType.GetMemberNames(IronPythonModuleContext.DontShowClrInstance).ToArray(); _functionMembers = FunctionType.GetMemberNames(IronPythonModuleContext.DontShowClrInstance).ToArray(); }
public PythonAsciiString(AsciiString s, IPythonInterpreter interpreter, LocationInfo location = null) : base(s, interpreter.GetBuiltinType(interpreter.GetAsciiTypeId()), location) { }
private IMember GetValueFromExpression(Expression expr, Dictionary <string, IMember> scope) { var ne = expr as NameExpression; if (ne != null) { IMember existing = null; if (scope != null && scope.TryGetValue(ne.Name, out existing) && existing != null) { return(existing); } if (_members != null && _members.TryGetValue(ne.Name, out existing) && existing != null) { return(existing); } } IPythonType type; var me = expr as MemberExpression; if (me != null && me.Target != null && !string.IsNullOrEmpty(me.Name)) { var mc = GetValueFromExpression(me.Target, scope) as IMemberContainer; if (mc != null) { return(mc.GetMember(_context, me.Name)); } return(null); } if (expr is CallExpression) { var cae = (CallExpression)expr; var m = GetValueFromExpression(cae.Target, scope); type = m as IPythonType; if (type != null) { return(new AstPythonConstant(type, GetLoc(expr))); } var fn = m as IPythonFunction; if (fn != null) { return(new AstPythonConstant(_interpreter.GetBuiltinType(BuiltinTypeId.NoneType), GetLoc(expr))); } } type = GetTypeFromExpression(expr); if (type != null) { return(new AstPythonConstant(type, GetLoc(expr))); } return(null); }
public PythonUnicodeString(string s, IPythonInterpreter interpreter, LocationInfo location = null) : base(s, interpreter.GetBuiltinType(interpreter.GetUnicodeTypeId()), location) { }