internal override IAnalysisSet Resolve(AnalysisUnit unit, ResolutionContext context) { VariableDef[] newTypes; if (context.CallSite == null) { // No ability to come back to this instance later, so resolve and return // imitation type var union = AnalysisSet.Empty; bool changed = false; if (Push()) { try { union = UnionType.Resolve(unit, context, out changed); } finally { Pop(); } } var pi = new ProtocolInfo(DeclaringModule, ProjectState); pi.AddProtocol(new IterableProtocol(pi, union)); if (ClassInfo.TypeId == BuiltinTypeId.Tuple) { newTypes = VariableDef.Generator.Take(IndexTypes.Length).ToArray(); changed |= ResolveIndexTypes(unit, context, newTypes); if (newTypes.Length == 1) { pi.AddProtocol(new GetItemProtocol(pi, unit.State.ClassInfos[BuiltinTypeId.Int], newTypes[0].Types)); } else if (newTypes.Length > 1) { pi.AddProtocol(new TupleProtocol(pi, newTypes.Select(t => t.Types))); } } return(changed ? (AnalysisValue)pi : this); } if (unit.InterpreterScope.TryGetNodeValue(context.CallSite, NodeValueKind.Sequence, out var newSeq)) { newTypes = (newSeq as IterableValue)?.IndexTypes; if (newTypes != null) { ResolveIndexTypes(unit, context, newTypes); } return(newSeq); } else { newTypes = VariableDef.Generator.Take(Math.Max(1, IndexTypes.Length)).ToArray(); if (ResolveIndexTypes(unit, context, newTypes)) { return(unit.InterpreterScope.GetOrMakeNodeValue(context.CallSite, NodeValueKind.Sequence, n => CreateWithNewTypes(n, newTypes))); } } return(this); }
private IAnalysisSet MakeView(IPythonType type, IAnalysisSet values) { var pi = new ProtocolInfo(DeclaringModule, Self.State); var np = new NameProtocol(pi, type); var ip = new IterableProtocol(pi, values); np.ExtendDescription(ip.GetRichDescription()); pi.AddProtocol(np); pi.AddProtocol(ip); return(pi); }
private IAnalysisSet MakeIterable(IAnalysisSet values) { var pi = new ProtocolInfo(DeclaringModule, Self.State); pi.AddProtocol(new IterableProtocol(pi, values)); return(pi); }