public override IAnalysisSet Call(Node node, AnalysisUnit unit, IAnalysisSet[] args, NameExpression[] keywordArgNames) { if (args.Length == 1) { var res = unit.Scope.GetOrMakeNodeValue( node, (node_) => MakeFromIndexes(node_, unit.ProjectEntry) ) as SequenceInfo; List<IAnalysisSet> seqTypes = new List<IAnalysisSet>(); foreach (var type in args[0]) { SequenceInfo seqInfo = type as SequenceInfo; if (seqInfo != null) { for (int i = 0; i < seqInfo.IndexTypes.Length; i++) { if (seqTypes.Count == i) { seqTypes.Add(seqInfo.IndexTypes[i].Types); } else { seqTypes[i] = seqTypes[i].Union(seqInfo.IndexTypes[i].Types); } } } else { var defaultIndexType = type.GetIndex(node, unit, ProjectState.GetConstant(0)); if (seqTypes.Count == 0) { seqTypes.Add(defaultIndexType); } else { seqTypes[0] = seqTypes[0].Union(defaultIndexType); } } } res.AddTypes(unit, seqTypes.ToArray()); return res; } return base.Call(node, unit, args, keywordArgNames); }
internal bool AddTypes(Node node, AnalysisUnit unit, IAnalysisSet key, IAnalysisSet value, bool enqueue = true) { if (_keysAndValues.AddTypes(unit, key, value, enqueue)) { if (_keysVariable != null) { _keysVariable.MakeUnionStrongerIfMoreThan(ProjectState.Limits.DictKeyTypes, value); if (_keysVariable.AddTypes(unit, key, enqueue)) { if (_keysIter != null) { _keysIter.UnionType = null; } if (_keysList != null) { _keysList.UnionType = null; } } } if (_valuesVariable != null) { _valuesVariable.MakeUnionStrongerIfMoreThan(ProjectState.Limits.DictValueTypes, value); if (_valuesVariable.AddTypes(unit, value, enqueue)) { if (_valuesIter != null) { _valuesIter.UnionType = null; } if (_valuesList != null) { _valuesList.UnionType = null; } } } if (_keyValueTuple != null) { _keyValueTuple.IndexTypes[0].MakeUnionStrongerIfMoreThan(ProjectState.Limits.DictKeyTypes, key); _keyValueTuple.IndexTypes[1].MakeUnionStrongerIfMoreThan(ProjectState.Limits.DictValueTypes, value); _keyValueTuple.IndexTypes[0].AddTypes(unit, key, enqueue); _keyValueTuple.IndexTypes[1].AddTypes(unit, value, enqueue); } return true; } return false; }
public override IAnalysisSet Call(Node node, AnalysisUnit unit, IAnalysisSet[] args, NameExpression[] keywordArgNames) { if (_original == null) { return base.Call(node, unit, args, keywordArgNames); } return _original.Call(node, unit, args, keywordArgNames); }
public override IAnalysisSet Call(Node node, AnalysisUnit unit, IAnalysisSet[] args, NameExpression[] keywordArgNames) { var res = AnalysisSet.Empty; foreach (var member in _members) { res = res.Union(member.Call(node, unit, args, keywordArgNames)); } return res; }
public override IAnalysisSet Construct(Node node, AnalysisUnit unit, IAnalysisSet[] args) { var result = Call(node, unit, _instance.Proxy, args); if (result.Count != 0) { // function returned a value, we want to return any values // which are typed to object. foreach (var resultValue in result) { if (!resultValue.Value.IsObject) { // we need to do some filtering var tmpRes = AnalysisSet.Empty; foreach (var resultValue2 in result) { if (resultValue2.Value.IsObject) { tmpRes = tmpRes.Add(resultValue2); } } result = tmpRes; break; } } if (result.Count != 0) { return result; } } // we didn't return a value or returned a non-object // value. The result is our newly created instance object. return _instance.Proxy; }
public override IAnalysisSet Call(Node node, AnalysisUnit unit, IAnalysisSet[] args, NameExpression[] keywordArgNames) { var res = (DictionaryInfo)unit.Scope.GetOrMakeNodeValue( node, NodeValueKind.Dictionary, (node_) => new DictionaryInfo(unit.ProjectEntry, node) ); if (keywordArgNames.Length > 0) { for (int i = 0; i < keywordArgNames.Length; i++) { var curName = keywordArgNames[i].Name; var curArg = args[args.Length - keywordArgNames.Length + i]; if (curName == "**") { foreach (var value in curArg) { CopyFrom(args, res); } } else if (curName != "*") { res.AddTypes( node, unit, ProjectState.GetConstant(curName), curArg ); } } } else if (args.Length == 1) { foreach (var value in args[0]) { CopyFrom(args, res); } } return res; }
private static IAnalysisSet CloneSpecializationImpl(FunctionValue func, Node node, AnalysisUnit unit, IAnalysisSet @this, IAnalysisSet[] args) { if (args.Length > 0) { return args[0]; } return AnalysisSet.Empty; }
public override IAnalysisSet BinaryOperation(Node node, AnalysisUnit unit, PythonOperator operation, IAnalysisSet rhs) { var res = AnalysisSet.Empty; foreach (var member in _members) { res = res.Union(member.BinaryOperation(node, unit, operation, rhs)); } return res; }
public override IAnalysisSet BinaryOperation(Node node, AnalysisUnit unit, PythonOperator operation, IAnalysisSet rhs) { switch (operation) { case PythonOperator.GreaterThan: case PythonOperator.LessThan: case PythonOperator.LessThanOrEqual: case PythonOperator.GreaterThanOrEqual: case PythonOperator.Equal: case PythonOperator.NotEqual: case PythonOperator.Is: case PythonOperator.IsNot: return ProjectState.ClassInfos[BuiltinTypeId.Bool].Instance; case PythonOperator.TrueDivide: case PythonOperator.Add: case PythonOperator.Subtract: case PythonOperator.Multiply: case PythonOperator.MatMultiply: case PythonOperator.Divide: case PythonOperator.Mod: case PythonOperator.BitwiseAnd: case PythonOperator.BitwiseOr: case PythonOperator.Xor: case PythonOperator.LeftShift: case PythonOperator.RightShift: case PythonOperator.Power: case PythonOperator.FloorDivide: return ConstantInfo.NumericOp(node, this, unit, operation, rhs) ?? CallReverseBinaryOp(node, unit, operation, rhs); } return CallReverseBinaryOp(node, unit, operation, rhs); }
public override IAnalysisSet BinaryOperation(Node node, AnalysisUnit unit, Parsing.PythonOperator operation, IAnalysisSet rhs) { if (_original == null) { return base.BinaryOperation(node, unit, operation, rhs); } return _original.BinaryOperation(node, unit, operation, rhs); }
public override IAnalysisSet BinaryOperation(Node node, AnalysisUnit unit, Parsing.PythonOperator operation, IAnalysisSet rhs) { var res = AnalysisSet.Empty; switch (operation) { case PythonOperator.Add: foreach (var type in rhs) { if (type.IsOfType(ClassInfo)) { res = res.Union(ClassInfo.Instance); } else { res = res.Union(type.ReverseBinaryOperation(node, unit, operation, SelfSet)); } } break; case PythonOperator.Mod: if (_supportsMod) { res = SelfSet; } break; case PythonOperator.Multiply: foreach (var type in rhs) { if (type.IsOfType(ProjectState.ClassInfos[BuiltinTypeId.Int]) || type.IsOfType(ProjectState.ClassInfos[BuiltinTypeId.Long])) { res = res.Union(ClassInfo.Instance); } else { var partialRes = ConstantInfo.NumericOp(node, this, unit, operation, rhs); if (partialRes != null) { res = res.Union(partialRes); } } } break; } return res ?? base.BinaryOperation(node, unit, operation, rhs); }
private IAnalysisSet ListInsert(Node node, AnalysisUnit unit, IAnalysisSet[] args, NameExpression[] keywordArgNames) { if (args.Length == 2) { AppendItem(node, unit, args[1]); } return unit.ProjectState._noneInst; }
public override IAnalysisSet BinaryOperation(Node node, AnalysisUnit unit, PythonOperator operation, IAnalysisSet rhs) { IAnalysisSet res; switch (operation) { case PythonOperator.BitwiseOr: var seq = (SetInfo)unit.Scope.GetOrMakeNodeValue( node, _ => new SetInfo(ProjectState, node, unit.ProjectEntry) ); seq.AddTypes(unit, GetEnumeratorTypes(node, unit)); foreach (var type in rhs.Where(t => t.IsOfType(ClassInfo))) { seq.AddTypes(unit, type.GetEnumeratorTypes(node, unit)); } res = seq; break; case PythonOperator.BitwiseAnd: case PythonOperator.ExclusiveOr: case PythonOperator.Subtract: res = this; break; default: res = CallReverseBinaryOp(node, unit, operation, rhs); break; } return res; }
/// <summary> /// Performs a SetMember operation for the given name and propagates the /// given values types for the provided member name. /// </summary> public static void SetMember(this IAnalysisSet self, Node node, AnalysisUnit unit, string name, IAnalysisSet value) { if (name != null && name.Length > 0) { foreach (var ns in self) { ns.SetMember(node, unit, name, value); } } }
public override IAnalysisSet GetIndex(Node node, AnalysisUnit unit, IAnalysisSet index) { var res = base.GetIndex(node, unit, index); var names = index.OfType<ConstantInfo>() .Select(ci => ci.GetConstantValueAsString()) .Where(s => !string.IsNullOrEmpty(s)) .Distinct() .ToArray(); if (names.Length != 1) { // Unless you request a specific module by string literal, // you won't get any object out of sys.modules. return AnalysisSet.Empty; } var name = names[0]; lock (_owner.Modules) { IAnalysisSet knownValues; if (_owner.Modules.TryGetValue(name, out knownValues) && knownValues != null && knownValues.Any() ) { return knownValues; } } ModuleReference modRef; if (unit.ProjectState.Modules.TryImport(name, out modRef)) { return modRef.AnalysisModule; } return AnalysisSet.Empty; }
private IAnalysisSet SequenceIter(Node node, AnalysisUnit unit, IAnalysisSet[] args, NameExpression[] keywordArgNames) { if (_iterator == null) { var types = new [] { new VariableDef() }; types[0].AddTypes(unit, _indexTypes, false); _iterator = new IteratorInfo(types, IteratorInfo.GetIteratorTypeFromType(ClassInfo, unit), node); } return _iterator ?? AnalysisSet.Empty; }
public override bool AssignVariable(string name, Parsing.Ast.Node location, AnalysisUnit unit, IAnalysisSet values) { if (base.AssignVariable(name, location, unit, values)) { Module.ModuleDefinition.EnqueueDependents(); return true; } return false; }
public override IAnalysisSet Call(Node node, AnalysisUnit unit, IAnalysisSet @this, IAnalysisSet[] args) { var res = _call(this, node, unit, @this, args); if (_callBase) { return res.Union(base.Call(node, unit, @this, args)); } return res; }
public override void AugmentAssign(AugmentedAssignStatement node, AnalysisUnit unit, IAnalysisSet value) { if (_original == null) { base.AugmentAssign(node, unit, value); return; } _original.AugmentAssign(node, unit, value); }
public override IAnalysisSet GetIndex(Node node, AnalysisUnit unit, IAnalysisSet index) { IAnalysisSet res; if (TryInvokeMethod(node, unit, "__getitem__", new[] { index }, out res)) { return res; } return _instances.GetIndex(node, unit, index); }
private IAnalysisSet ListExtend(Node node, AnalysisUnit unit, IAnalysisSet[] args, NameExpression[] keywordArgNames) { if (args.Length == 1) { foreach (var type in args[0]) { AppendItem(node, unit, type.GetEnumeratorTypes(node, unit)); } } return unit.ProjectState._noneInst; }
public SequenceBuiltinClassInfo(IPythonType classObj, PythonAnalyzer projectState) : base(classObj, projectState) { var seqType = classObj as IPythonSequenceType; if (seqType != null && seqType.IndexTypes != null) { _indexTypes = projectState.GetAnalysisSetFromObjects(seqType.IndexTypes).GetInstanceType(); } else { _indexTypes = AnalysisSet.Empty; } }
public override bool AssignVariable(string name, Node location, AnalysisUnit unit, IAnalysisSet values) { var res = base.AssignVariable(name, location, unit, values); if (name == "__metaclass__") { // assignment to __metaclass__, save it in our metaclass variable Class.GetOrCreateMetaclassVariable().AddTypes(unit, values); } return res; }
internal void AddReturnTypes(Node node, AnalysisUnit unit, IAnalysisSet types, bool enqueue = true) { if (Coroutine != null) { Coroutine.AddReturn(node, unit, types, enqueue); } else if (Generator != null) { Generator.AddReturn(node, unit, types, enqueue); } else { ReturnValue.MakeUnionStrongerIfMoreThan(unit.ProjectState.Limits.ReturnTypes, types); ReturnValue.AddTypes(unit, types, enqueue); } }
private IAnalysisSet ObjectSetAttr(Node node, Analysis.AnalysisUnit unit, IAnalysisSet[] args, NameExpression[] keywordArgNames) { if (args.Length >= 3) { foreach (var ii in args[0].OfType<InstanceInfo>()) { foreach (var key in args[1].GetConstantValueAsString()) { ii.SetMember(node, unit, key, args[2]); } } } return AnalysisSet.Empty; }
private IAnalysisSet IterableIter(Node node, AnalysisUnit unit, IAnalysisSet[] args, NameExpression[] keywordArgNames) { if (args.Length == 0) { return unit.Scope.GetOrMakeNodeValue( node, NodeValueKind.Iterator, n => MakeIteratorInfo(n, unit) ); } return AnalysisSet.Empty; }
internal static IAnalysisSet NumericOp(Node node, BuiltinInstanceInfo lhs, AnalysisUnit unit, PythonOperator operation, IAnalysisSet rhs) { var res = AnalysisSet.Empty; var lhsType = lhs.TypeId; foreach(var ns in rhs) { var rhsType = ns.TypeId; // First handle string operations if (lhsType == BuiltinTypeId.Bytes || lhsType == BuiltinTypeId.Unicode) { if (operation == PythonOperator.Mod) { res = res.Union(lhs.ClassInfo.Instance); } else if (operation == PythonOperator.Add && (rhsType == BuiltinTypeId.Bytes || rhsType == BuiltinTypeId.Unicode)) { res = res.Union(lhs.ClassInfo.Instance); } else if (operation == PythonOperator.Multiply && (rhsType == BuiltinTypeId.Int || rhsType == BuiltinTypeId.Long)) { res = res.Union(lhs.ClassInfo.Instance); } continue; } else if (operation == PythonOperator.Multiply && (lhsType == BuiltinTypeId.Int || lhsType == BuiltinTypeId.Long)) { if (rhsType == BuiltinTypeId.Str || rhsType == BuiltinTypeId.Bytes || rhsType == BuiltinTypeId.Unicode || rhsType == BuiltinTypeId.Tuple || rhsType == BuiltinTypeId.List) { res = res.Union(unit.ProjectState.ClassInfos[rhsType].Instance); continue; } } // These specializations change rhsType before type promotion // rules are applied. if ((operation == PythonOperator.TrueDivide || (operation == PythonOperator.Divide && unit.ProjectState.LanguageVersion.Is3x())) && (lhsType == BuiltinTypeId.Int || lhsType == BuiltinTypeId.Long) && (rhsType == BuiltinTypeId.Int || rhsType == BuiltinTypeId.Long)) { rhsType = BuiltinTypeId.Float; } // Type promotion rules are applied if (lhsType == BuiltinTypeId.Unknown || lhsType > BuiltinTypeId.Complex || rhsType == BuiltinTypeId.Unknown || rhsType > BuiltinTypeId.Complex) { // Non-numeric types require the reverse operation res = res.Union(ns.ReverseBinaryOperation(node, unit, operation, lhs)); } else if (lhsType == BuiltinTypeId.Complex || rhsType == BuiltinTypeId.Complex) { res = res.Union(unit.ProjectState.ClassInfos[BuiltinTypeId.Complex].Instance); } else if (lhsType == BuiltinTypeId.Float || rhsType == BuiltinTypeId.Float) { res = res.Union(unit.ProjectState.ClassInfos[BuiltinTypeId.Float].Instance); } else if (lhsType == BuiltinTypeId.Long || rhsType == BuiltinTypeId.Long) { res = res.Union(unit.ProjectState.ClassInfos[BuiltinTypeId.Long].Instance); } else { res = res.Union(unit.ProjectState.ClassInfos[BuiltinTypeId.Int].Instance); } } return res.Count > 0 ? res : null; }
public override IAnalysisSet Call(Node node, AnalysisUnit unit, IAnalysisSet[] args, NameExpression[] keywordArgNames) { var newArgs = _args.Take(_args.Length - _keywordArgNames.Length) .Concat(args.Take(args.Length - keywordArgNames.Length)) .Concat(_args.Skip(_args.Length - _keywordArgNames.Length)) .Concat(args.Skip(args.Length - keywordArgNames.Length)) .ToArray(); var newKwArgs = _keywordArgNames.Concat(keywordArgNames).ToArray(); return _function.Call(node, unit, newArgs, newKwArgs); }
/// <summary> /// Performs a call operation propagating the argument types into any /// user defined functions or classes and returns the set of types which /// result from the call. /// </summary> public static IAnalysisSet Call(this IAnalysisSet self, Node node, AnalysisUnit unit, IAnalysisSet[] args, NameExpression[] keywordArgNames) { var res = AnalysisSet.Empty; foreach (var ns in self) { var call = ns.Call(node, unit, args, keywordArgNames); Debug.Assert(call != null); res = res.Union(call); } return res; }
public override IAnalysisSet GetIndex(Node node, AnalysisUnit unit, IAnalysisSet index) { // TODO: Return correct index value if we have a constant /*int? constIndex = SequenceInfo.GetConstantIndex(index); if (constIndex != null && constIndex.Value < _indexTypes.Count) { // TODO: Warn if outside known index and no appends? return _indexTypes[constIndex.Value]; }*/ return ProjectState.ClassInfos[BuiltinTypeId.Int].Instance; }
public IAnalysisSet CallReverseBinaryOp(Node node, AnalysisUnit unit, PythonOperator operation, IAnalysisSet rhs) { switch (operation) { case PythonOperator.Is: case PythonOperator.IsNot: case PythonOperator.In: case PythonOperator.NotIn: return(unit.DeclaringModule.ProjectEntry.ProjectState.ClassInfos[BuiltinTypeId.Bool].Instance); default: var res = AnalysisSet.Empty; foreach (var value in rhs) { res = res.Union(value.ReverseBinaryOperation(node, unit, operation, SelfSet)); } return(res); } }
public virtual IAnalysisSet GetIndex(Node node, AnalysisUnit unit, IAnalysisSet index) => GetTypeMember(node, unit, "__getitem__").Call(node, unit, new[] { index }, ExpressionEvaluator.EmptyNames);
public override void SetMember(Node node, AnalysisUnit unit, string name, IAnalysisSet value) { base.SetMember(node, unit, name, value); _referencedMembers.AddReference(node, unit, name); }
public override void SetIndex(Node node, AnalysisUnit unit, IAnalysisSet index, IAnalysisSet value) { AddTypes(node, unit, index, value); }
/// <summary> /// Performs a set index operation propagating the index types and value /// types into the provided object. /// </summary> public static void SetIndex(this IAnalysisSet self, Node node, AnalysisUnit unit, IAnalysisSet index, IAnalysisSet value) { foreach (var ns in self) { ns.SetIndex(node, unit, index, value); } }
/// <summary> /// Performs an augmented assignment propagating the value into the /// object. /// </summary> public static void AugmentAssign(this IAnalysisSet self, AugmentedAssignStatement node, AnalysisUnit unit, IAnalysisSet value) { foreach (var ns in self) { ns.AugmentAssign(node, unit, value); } }
public override bool AssignVariable(string name, Node location, AnalysisUnit unit, IAnalysisSet values) { var vars = CreateVariable(location, unit, name, false); var res = AssignVariableWorker(location, unit, values, vars); if (OuterScope != null) { var outerVar = OuterScope.GetVariable(location, unit, name, false); if (outerVar != null && outerVar != vars) { outerVar.AddAssignment(location, unit); outerVar.AddTypes(unit, values); } } return(res); }
private bool AreNullOrEqual(IAnalysisSet x, IAnalysisSet y) { return(x == null || x.IsObjectOrUnknown() || y == null || y.IsObjectOrUnknown() || x.SetEquals(y)); }
public override bool IsOfType(IAnalysisSet klass) => klass.Contains(ProjectState.ClassInfos[BuiltinTypeId.Function]);
public TypedDependencyInfo(int version, IAnalysisSet emptySet) : base(version) { _types = emptySet; }
public override void SetIndex(Node node, AnalysisUnit unit, IAnalysisSet index, IAnalysisSet value) { int?constIndex = GetConstantIndex(index); if (constIndex != null) { SetIndex(unit, constIndex.Value, value); } else { if (IndexTypes.Length == 0) { IndexTypes = new[] { new VariableDef() }; } IndexTypes[0].MakeUnionStrongerIfMoreThan(ProjectState.Limits.IndexTypes, value); IndexTypes[0].AddTypes(unit, value, true, DeclaringModule); } }
public override IAnalysisSet BinaryOperation(Node node, AnalysisUnit unit, PythonOperator operation, IAnalysisSet rhs) { SequenceInfo seq = null; VariableDef idx = null; var res = AnalysisSet.Empty; switch (operation) { case PythonOperator.Add: foreach (var type in rhs.Where(t => !t.IsOfType(ClassInfo))) { res = res.Union(CallReverseBinaryOp(node, unit, operation, rhs)); } foreach (var type in rhs.Where(t => t.IsOfType(ClassInfo))) { if (seq == null) { seq = (SequenceInfo)unit.Scope.GetOrMakeNodeValue(node, NodeValueKind.Sequence, _ => new SequenceInfo(new[] { new VariableDef() }, ClassInfo, node, unit.ProjectEntry) ); idx = seq.IndexTypes[0]; idx.AddTypes(unit, GetEnumeratorTypes(node, unit), true, DeclaringModule); } idx.AddTypes(unit, type.GetEnumeratorTypes(node, unit), true, DeclaringModule); idx.MakeUnionStrongerIfMoreThan(ProjectState.Limits.IndexTypes); } if (seq != null) { res = res.Union(seq); } break; case PythonOperator.Multiply: foreach (var type in rhs) { var typeId = type.TypeId; if (typeId == BuiltinTypeId.Int || typeId == BuiltinTypeId.Long) { res = res.Union(this); } else { res = res.Union(CallReverseBinaryOp(node, unit, operation, type)); } } break; default: res = CallReverseBinaryOp(node, unit, operation, rhs); break; } return(res); }
public virtual IAnalysisSet BinaryOperation(Node node, AnalysisUnit unit, PythonOperator operation, IAnalysisSet rhs) => CallReverseBinaryOp(node, unit, operation, rhs);
internal override bool IsOfType(IAnalysisSet klass) { return(klass.Contains(ProjectState.ClassInfos[BuiltinTypeId.Function])); }
public override IAnalysisSet AddNodeValue(Node node, NodeValueKind kind, IAnalysisSet variable) { return(OuterScope.AddNodeValue(node, kind, variable)); }
internal VariableDef CreateTypedVariable(Node node, AnalysisUnit unit, string name, IAnalysisSet types, bool addRef = true) { VariableDef res, outer, immediateOuter; if (!TryGetVariable(name, out res)) { // Normal CreateVariable would use AddVariable, which will put // the typed one in the wrong scope. res = base.AddVariable(name); } if (addRef) { res.AddReference(node, unit); } PropagateIsInstanceTypes(node, unit, types, res); foreach (var scope in OuterScope.EnumerateTowardsGlobal) { outer = scope.GetVariable(node, unit, name, addRef); if (scope.TryGetVariable(name, out immediateOuter) && immediateOuter != res) { if (addRef && immediateOuter != outer) { res.AddReference(node, unit); } PropagateIsInstanceTypes(node, unit, types, immediateOuter); scope.AddLinkedVariable(name, res); } if (!(scope is IsInstanceScope)) { break; } } return(res); }
/// <summary> /// Performs a delete index operation propagating the index types into /// the provided object. /// </summary> public static void DeleteIndex(this IAnalysisSet self, Node node, AnalysisUnit unit, IAnalysisSet index) { }
public DeferredDecorator(DjangoAnalyzer analyzer, IAnalysisSet name, Dictionary <string, TagInfo> tags) { _analyzer = analyzer; _name = name; _tags = tags; }
/// <summary> /// Performs a get index operation propagating any index types into the /// value and returns the associated types associated with the object. /// </summary> public static IAnalysisSet GetIndex(this IAnalysisSet self, Node node, AnalysisUnit unit, IAnalysisSet index) { var res = AnalysisSet.Empty; foreach (var ns in self) { res = res.Union(ns.GetIndex(node, unit, index)); } return(res); }
public override IAnalysisSet GetIndex(Node node, AnalysisUnit unit, IAnalysisSet index) { _keysAndValues.AddDependency(unit); return(_keysAndValues.GetValueType(index)); }
/// <summary> /// Returns a sequence of all recognized string values in the set. /// </summary> internal static IEnumerable <string> GetConstantValueAsString(this IAnalysisSet values) { return(values .Select(v => v.GetConstantValueAsString()) .Where(s => !string.IsNullOrEmpty(s))); }
public virtual bool IsOfType(IAnalysisSet klass) => false;
/// <summary> /// Returns true if the set contains no or only the object type /// </summary> internal static bool IsObjectOrUnknown(this IAnalysisSet res) { return(res.Count == 0 || (res.Count == 1 && res.First().TypeId == BuiltinTypeId.Object)); }
public virtual void SetIndex(Node node, AnalysisUnit unit, IAnalysisSet index, IAnalysisSet value) { }
/// <summary> /// Gets instance representations of all members of the set. /// </summary> public static IAnalysisSet GetInstanceType(this IAnalysisSet types) { return(AnalysisSet.Create(types.SelectMany(ns => ns.GetInstanceType()))); }
/// <summary> /// Provides implementation of __r*__methods (__radd__, __rsub__, etc...) /// /// This is dispatched to when the LHS doesn't understand the RHS. Unlike normal Python it's currently /// the LHS responsibility to dispatch to this. /// </summary> public virtual IAnalysisSet ReverseBinaryOperation(Node node, AnalysisUnit unit, PythonOperator operation, IAnalysisSet rhs) => AnalysisSet.Empty;
/// <summary> /// Performs the specified operation on the value and the rhs value. /// </summary> public static IAnalysisSet BinaryOperation(this IAnalysisSet self, Node node, AnalysisUnit unit, PythonOperator operation, IAnalysisSet rhs) { var res = AnalysisSet.Empty; foreach (var ns in self) { res = res.Union(ns.BinaryOperation(node, unit, operation, rhs)); } return(res); }
public override void AugmentAssign(AugmentedAssignStatement node, AnalysisUnit unit, IAnalysisSet value) { base.AugmentAssign(node, unit, value); var args = GetEventInvokeArgs(ProjectState); foreach (var r in value) { r.Call(node, unit, args, ExpressionEvaluator.EmptyNames); } }
public override void SetIndex(Node node, AnalysisUnit unit, IAnalysisSet index, IAnalysisSet value) { base.SetIndex(node, unit, index, value); foreach (var name in index.OfType <ConstantInfo>() .Select(ci => ci.GetConstantValueAsString()) .Where(s => !string.IsNullOrEmpty(s)) ) { lock (_owner.Modules) { _owner.Modules[name] = value; } var modules = value.OfType <ModuleInfo>().ToArray(); var modRef = unit.State.Modules.GetOrAdd(name); MultipleMemberInfo mmi; ModuleInfo mi; if ((mmi = modRef.Module as MultipleMemberInfo) != null) { if (modules.Except(mmi.Members.OfType <ModuleInfo>()).Any()) { modules = modules.Concat(mmi.Members.OfType <ModuleInfo>()).Distinct().ToArray(); } } else if ((mi = modRef.Module as ModuleInfo) != null) { if (!modules.Contains(mi)) { modules = modules.Concat(Enumerable.Repeat(mi, 1)).ToArray(); } } modRef.Module = MultipleMemberInfo.Create(modules) as IModule; foreach (var module in modules) { int lastDot = name.LastIndexOf('.'); if (lastDot > 0) { var parentName = name.Remove(lastDot); ModuleReference parent; if (ProjectState.Modules.TryImport(parentName, out parent)) { if ((mi = parent.AnalysisModule as ModuleInfo) != null) { mi.AddChildPackage(module, unit, name.Substring(lastDot + 1)); } } } } } }