public override INamespaceSet GetMember(Node node, AnalysisUnit unit, string name) { switch (name) { case "append": EnsureAppend(); if (_appendMethod != null) { return _appendMethod.SelfSet; } break; case "pop": EnsurePop(); if (_popMethod != null) { return _popMethod.SelfSet; } break; case "insert": EnsureInsert(); if (_insertMethod != null) { return _insertMethod.SelfSet; } break; case "extend": EnsureExtend(); if (_extendMethod != null) { return _extendMethod.SelfSet; } break; } return base.GetMember(node, unit, name); }
public override INamespaceSet Call(Node node, AnalysisUnit unit, INamespaceSet[] args, NameExpression[] keywordArgNames) { if (args.Length == 0) { return unit.Scope.GetOrMakeNodeValue(node, n => new IteratorInfo(_indexTypes, _iterClass, n)); } return NamespaceSet.Empty; }
public override INamespaceSet BinaryOperation(Node node, AnalysisUnit unit, JOperator operation, INamespaceSet rhs) { switch (operation) { case JOperator.GreaterThan: case JOperator.LessThan: case JOperator.LessThanOrEqual: case JOperator.GreaterThanOrEqual: case JOperator.Equal: case JOperator.NotEqual: case JOperator.Is: case JOperator.IsNot: return ProjectState._boolType.Instance; case JOperator.TrueDivide: case JOperator.Add: case JOperator.Subtract: case JOperator.Multiply: case JOperator.Divide: case JOperator.Mod: case JOperator.BitwiseAnd: case JOperator.BitwiseOr: case JOperator.Xor: case JOperator.LeftShift: case JOperator.RightShift: case JOperator.Power: case JOperator.FloorDivide: return ConstantInfo.NumericOp(node, this, unit, operation, rhs) ?? base.BinaryOperation(node, unit, operation, rhs); } return base.BinaryOperation(node, unit, operation, rhs); }
public override INamespaceSet GetMember(Node node, AnalysisUnit unit, string name) { if (unit.ProjectState.LanguageVersion.Is6x() && name == "next" || unit.ProjectState.LanguageVersion.Is7x() && name == "__next__") { if (_next == null) { var next = this._type.GetMember(unit.ProjectEntry.MyScope.InterpreterContext, name); if (next != null) { _next = new NextBoundMethod((BuiltinMethodInfo)unit.ProjectState.GetNamespaceFromObjects(next), this); } } if (_next != null) { return _next.SelfSet; } } else if (name == "__iter__") { if (_iter == null) { var iter = this._type.GetMember(unit.ProjectEntry.MyScope.InterpreterContext, name); if (iter != null) { _iter = new IterBoundBuiltinMethodInfo((BuiltinMethodInfo)unit.ProjectState.GetNamespaceFromObjects(iter), this); } } if (_iter != null) { return _iter.SelfSet; } } return base.GetMember(node, unit, name); }
public GeneratorInfo(JAnalyzer projectState, Node node) : base(projectState._generatorType) { _node = node; Yields = new VariableDef(); Sends = new VariableDef(); Returns = new VariableDef(); }
public override INamespaceSet Call(Node node, AnalysisUnit unit, INamespaceSet[] args, NameExpression[] keywordArgNames) { if (args.Length == 2) { _list.AppendItem(node, unit, args[1]); } return ProjectState._noneInst.SelfSet; }
/// <summary> /// Performs a delete index operation propagating the index types into the provided object. /// </summary> public static void DeleteMember(this INamespaceSet self, Node node, AnalysisUnit unit, string name) { if (name != null && name.Length > 0) { foreach (var ns in self) { ns.DeleteMember(node, unit, name); } } }
public DictionaryInfo(ProjectEntry declaringModule, Node node) : base(declaringModule.ProjectState._dictType) { _keysAndValues = new DependentKeyValue(); _declaringModule = declaringModule; _declVersion = declaringModule.AnalysisVersion; _node = node; }
public FunctionScope(FunctionInfo function, Node node, InterpreterScope declScope) : base(function, node, declScope) { ReturnValue = new VariableDef(); if (Function.FunctionDefinition.IsGenerator) { Generator = new GeneratorInfo(function.ProjectState, Function.FunctionDefinition); ReturnValue.AddTypes(function.ProjectEntry, Generator.SelfSet, false); } }
public static INamespaceSet BinaryOperation(this INamespaceSet self, Node node, AnalysisUnit unit, JOperator operation, INamespaceSet rhs) { var res = NamespaceSet.Empty; foreach (var ns in self) { res = res.Union(ns.BinaryOperation(node, unit, operation, rhs)); } return res; }
public override INamespaceSet Call(Node node, AnalysisUnit unit, INamespaceSet[] args, NameExpression[] keywordArgNames) { if (args.Length == 1) { _generator.AddSend(node, unit, args[0]); } _generator.Yields.AddDependency(unit); return _generator.Yields.Types; }
internal void AppendItem(Node node, AnalysisUnit unit, INamespaceSet set) { if (IndexTypes.Length == 0) { IndexTypes = new[] { new VariableDef() }; } IndexTypes[0].AddTypes(unit, set); UnionType = null; }
public override INamespaceSet Call(Node node, AnalysisUnit unit, INamespaceSet[] args, NameExpression[] keywordArgNames) { if (args.Length == 1) { foreach (var type in args[0]) { _list.AppendItem(node, unit, type.GetEnumeratorTypes(node, unit)); } } return ProjectState._noneInst.SelfSet; }
/// <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 INamespaceSet Call(this INamespaceSet self, Node node, AnalysisUnit unit, INamespaceSet[] args, NameExpression[] keywordArgNames) { var res = NamespaceSet.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 INamespaceSet GetIndex(Node node, AnalysisUnit unit, INamespaceSet 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._intType.SelfSet; }
public override INamespaceSet Call(Node node, AnalysisUnit unit, INamespaceSet[] args, NameExpression[] keywordArgNames) { var realArgs = args; if (_inst != null) { realArgs = Utils.Concat(_inst.SelfSet, args); } if (node is CallExpression) { return _call((CallExpression)node, unit, realArgs, keywordArgNames) ?? NamespaceSet.Empty; } return NamespaceSet.Empty; }
public InterpreterScope(Namespace ns, Node ast, InterpreterScope outerScope) { _ns = ns; _node = ast; OuterScope = outerScope; _nodeScopes = new Dictionary<Node, InterpreterScope>(); _nodeValues = new Dictionary<Node, INamespaceSet>(); _variables = new Dictionary<string, VariableDef>(); #if DEBUG NodeScopes = new ReadOnlyDictionary<Node, InterpreterScope>(_nodeScopes); NodeValues = new ReadOnlyDictionary<Node, INamespaceSet>(_nodeValues); Variables = new ReadOnlyDictionary<string, VariableDef>(_variables); #endif }
public override INamespaceSet Call(Node node, AnalysisUnit unit, INamespaceSet[] args, NameExpression[] keywordArgNames) { if (args.Length >= 1) { var instance = NamespaceSet.Empty; foreach (var n in args[0]) { var bci = n as BuiltinClassInfo; var ci = n as ClassInfo; if (bci != null) { instance = instance.Union(bci.Instance); } else if (ci != null) { instance = instance.Union(ci.Instance); } } return instance; } return ProjectState._objectType.Instance; }
public override INamespaceSet Call(Node node, AnalysisUnit unit, INamespaceSet[] args, NameExpression[] keywordArgNames) { var realArgs = args; if (_inst != null) { realArgs = Utils.Concat(_inst.SelfSet, args); } var analyzed = _original.Call(node, unit, args, keywordArgNames); var res = _call((CallExpression)node, unit, realArgs, keywordArgNames); if (res == null) { return analyzed; } else if (analyzed.Count == 0) { return res; } else { return res.Union(analyzed); } }
public override INamespaceSet BinaryOperation(Node node, AnalysisUnit unit, JOperator operation, INamespaceSet rhs) { switch (operation) { case JOperator.Multiply: INamespaceSet res = NamespaceSet.Empty; foreach (var type in rhs) { var typeId = type.TypeId; if (typeId == BuiltinTypeId.Int || typeId == BuiltinTypeId.Long) { res = res.Union(this); } else { var partialRes = type.ReverseBinaryOperation(node, unit, operation, SelfSet); if (partialRes != null) { res = res.Union(partialRes); } } } return res; } return base.BinaryOperation(node, unit, operation, rhs); }
public override INamespaceSet Call(Node node, AnalysisUnit unit, INamespaceSet[] args, NameExpression[] keywordArgNames) { if (args.Length == 1) { var res = unit.Scope.GetOrMakeNodeValue( node, (node_) => MakeFromIndexes(node_) ) as SequenceInfo; List<INamespaceSet> seqTypes = new List<INamespaceSet>(); 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); }
public override void SetMember(Node node, AnalysisUnit unit, string name, INamespaceSet value) { _original.SetMember(node, unit, name, value); }
public override void SetIndex(Node node, AnalysisUnit unit, INamespaceSet index, INamespaceSet value) { _original.SetIndex(node, unit, index, value); }
public override INamespaceSet ReverseBinaryOperation(Node node, AnalysisUnit unit, Parsing.JOperator operation, INamespaceSet rhs) { return _original.ReverseBinaryOperation(node, unit, operation, rhs); }
public override INamespaceSet GetMember(Node node, AnalysisUnit unit, string name) { return _original.GetMember(node, unit, name); }
public override INamespaceSet GetIndex(Node node, AnalysisUnit unit, INamespaceSet index) { return _original.GetIndex(node, unit, index); }
public override INamespaceSet GetEnumeratorTypes(Node node, AnalysisUnit unit) { return _original.GetEnumeratorTypes(node, unit); }
public override INamespaceSet UnaryOperation(Node node, AnalysisUnit unit, Parsing.JOperator operation) { return _original.UnaryOperation(node, unit, operation); }
internal override void AddReference(Node node, AnalysisUnit analysisUnit) { _original.AddReference(node, analysisUnit); }
public override INamespaceSet GetDescriptor(Node node, Namespace instance, Namespace context, AnalysisUnit unit) { if (_descriptor == null) { var res = _original.GetDescriptor(node, instance, context, unit); // TODO: This kinda sucks... if (Object.ReferenceEquals(res, _original)) { _descriptor = SelfSet; } else if (res.Count >= 1) { // TODO: Dictionary per-instance _descriptor = Clone(res.First(), instance); } else { _descriptor = Clone(_original, instance); } } return _descriptor; }