private AnalysisUnit(Node ast, InterpreterScope[] scopes, AnalysisUnit parent, bool forEval) { _ast = ast; _scopes = scopes; _parent = parent; _forEval = forEval; }
public override ISet<Namespace> GetMember(Node node, AnalysisUnit unit, string name) { var res = base.GetMember(node, unit, name); if (res.Count > 0) { _references.AddReference(node, unit, name); } return res; }
public override ISet<Namespace> Call(Node node, AnalysisUnit unit, ISet<Namespace>[] args, string[] keywordArgNames) { if (args.Length == 1) { _list.AppendItem(args[0]); } return ProjectState._noneInst.SelfSet; }
public override ISet<Namespace> Call(Node node, AnalysisUnit unit, ISet<Namespace>[] args, string[] keywordArgNames) { if (args.Length == 1) { _generator.AddSend(node, unit, args[0]); } return _generator.Yields; }
internal FunctionInfo(AnalysisUnit unit, ProjectEntry entry) : base(unit) { _entry = entry; _returnValue = new VariableDef(); _declVersion = entry.Version; // TODO: pass NoneInfo if we can't determine the function always returns }
public override void PostWalk(FunctionDefinition node) { if (node.Body != null && node.Name != null) { _scopes.Pop(); _scopeTree.Pop(); _curUnit = _analysisStack.Pop(); } }
public override void AugmentAssign(AugmentedAssignStatement node, AnalysisUnit unit, ISet<Namespace> value) { base.AugmentAssign(node, unit, value); var args = GetEventInvokeArgs(ProjectState, _type); foreach (var r in value) { r.Call(node, unit, args, ArrayUtils.EmptyStrings); } }
internal ClassInfo(AnalysisUnit unit, ProjectEntry entry) : base(unit) { _instanceInfo = new InstanceInfo(this); _bases = new List<ISet<Namespace>>(); _entry = entry; _scope = new ClassScope(this); _declVersion = entry.Version; }
public override ISet<Namespace> Call(Node node, AnalysisUnit unit, ISet<Namespace>[] args, string[] keywordArgNames) { if (args.Length == 1) { foreach (var type in args[0]) { _list.AppendItem(type.GetEnumeratorTypes(node, unit)); } } return ProjectState._noneInst.SelfSet; }
public OverviewWalker(ProjectEntry entry, AnalysisUnit topAnalysis) { _entry = entry; _curUnit = topAnalysis; _scopes = new List<InterpreterScope>(); _scopes.Push(entry.MyScope.Scope); _scopeTree = new Stack<ScopePositionInfo>(); _scopeTree.Push(new ScopePositionInfo(1, Int32.MaxValue, null)); }
public VariableDef CreateVariable(Node node, AnalysisUnit unit, string name, bool addRef = true) { var res = GetVariable(node, unit, name, addRef); if (res == null) { _variables[name] = res = new VariableDef(); if (addRef) { res.AddReference(node, unit); } } return res; }
public override ISet<Namespace> GetIndex(Node node, AnalysisUnit unit, ISet<Namespace> 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; }
/// <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 ISet<Namespace> Call(this ISet<Namespace> self, Node node, AnalysisUnit unit, ISet<Namespace>[] args, string[] keywordArgNames) { ISet<Namespace> res = EmptySet<Namespace>.Instance; bool madeSet = false; foreach (var ns in self) { var call = ns.Call(node, unit, args, keywordArgNames); Debug.Assert(call != null); res = res.Union(call, ref madeSet); } return res; }
public void AddDependentUnit(AnalysisUnit unit) { if (_dependentUnits != null) { var checking = unit; while (checking != null) { if (_dependentUnits.Contains(checking)) { return; } checking = checking.Parent; } } else { _dependentUnits = new HashSet<AnalysisUnit>(); } _dependentUnits.Add(unit); }
public override ISet<Namespace> BinaryOperation(Node node, AnalysisUnit unit, PythonOperator operation, ISet<Namespace> 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._boolType.Instance; } return base.BinaryOperation(node, unit, operation, rhs); }
public static ISet<Namespace> BinaryOperation(this ISet<Namespace> self, Node node, AnalysisUnit unit, PythonOperator operation, ISet<Namespace> rhs) { ISet<Namespace> res = null; bool madeSet = false; foreach (var ns in self) { ISet<Namespace> got = ns.BinaryOperation(node, unit, operation, rhs); if (res == null) { res = got; continue; } else if (!madeSet) { res = new HashSet<Namespace>(res); madeSet = true; } res.UnionWith(got); } return res ?? EmptySet<Namespace>.Instance; }
public override ISet<Namespace> GetMember(Node node, AnalysisUnit unit, string name) { switch (name) { case "append": EnsureAppend(); return _appendMethod.SelfSet; case "pop": EnsurePop(); return _popMethod.SelfSet; case "insert": EnsureInsert(); return _insertMethod.SelfSet; case "extend": EnsureExtend(); return _extendMethod.SelfSet; } return base.GetMember(node, unit, name); }
public ExpressionEvaluator(AnalysisUnit unit, InterpreterScope[] scopes) { _unit = unit; _currentScopes = scopes; }
/// <summary> /// Creates a new ExpressionEvaluator that will evaluate in the context of the top-level module. /// </summary> public ExpressionEvaluator(AnalysisUnit unit) { _unit = unit; _currentScopes = unit.Scopes; }
protected UserDefinedInfo(AnalysisUnit analysisUnit) { _analysisUnit = analysisUnit; }
public override ISet<Namespace> GetIndex(Node node, AnalysisUnit unit, ISet<Namespace> index) { return _valueTypes; }
public override ISet<Namespace> Call(Node node, AnalysisUnit unit, ISet<Namespace>[] args, string[] keywordArgNames) { if (args.Length <= 1) { return _myDict._valueTypes; } return _myDict._valueTypes.Union(args[1]); }
public void AddDependency(AnalysisUnit unit) { _dependencies.Add(unit.ProjectEntry); }
public override void SetMember(Node node, AnalysisUnit unit, string name, ISet<Namespace> value) { var variable = Scope.CreateVariable(node, unit, name, false); if (variable.AddTypes(node, unit, value)) { ModuleDefinition.EnqueueDependents(); } variable.AddAssignment(node, unit); }
public override ISet<Namespace> GetMember(Node node, AnalysisUnit unit, string name) { ModuleDefinition.AddDependency(unit); return Scope.CreateVariable(node, unit, name).Types; }
public VariableDef DefineVariable(Parameter node, AnalysisUnit unit) { return(Variables[node.Name] = new LocatedVariableDef(unit.DeclaringModule.ProjectEntry, node)); }
internal ProjectEntry(ProjectState state, string moduleName, string filePath, IAnalysisCookie cookie) { Debug.Assert(moduleName != null); Debug.Assert(filePath != null); _projectState = state; _moduleName = moduleName ?? ""; _filePath = filePath; _cookie = cookie; _myScope = new ModuleInfo(_moduleName, this); _unit = new AnalysisUnit(_tree, new InterpreterScope[] { _myScope.Scope }, null); }
private void Parse() { if (_tree == null) { return; } var oldParent = _myScope.ParentPackage; ProjectState.ModulesByFilename[_filePath] = _myScope; if (oldParent != null) { // update us in our parent package _myScope.ParentPackage = oldParent; oldParent.Scope.SetVariable(_tree, _unit, _moduleName.Substring(_moduleName.IndexOf('.') + 1), _myScope.SelfSet, false); } var unit = _unit = new AnalysisUnit(_tree, new InterpreterScope[] { _myScope.Scope }, null); // collect top-level definitions first var walker = new OverviewWalker(this, unit); _tree.Walk(walker); _scopeTree = walker.ScopeTree; PublishPackageChildrenInPackage(); // create new analysis object and analyze the code. var newAnalysis = new ModuleAnalysis(_unit, _scopeTree); _unit.Enqueue(); new DDG().Analyze(_projectState.Queue); // publish the analysis now that it's complete _currentAnalysis = newAnalysis; foreach (var variableInfo in _myScope.Scope.Variables) { variableInfo.Value.ClearOldValues(this); } }
public override ISet<Namespace> GetMember(Node node, AnalysisUnit unit, string name) { if (name == "get") { if (_getMethod == null) { var getter = ProjectState.GetMember<BuiltinMethodDescriptor>(ClrModule.GetPythonType(typeof(PythonDictionary)), "get"); _getMethod = new DictionaryGetMethod(getter, ProjectState, this).SelfSet; } return _getMethod; } return base.GetMember(node, unit, name); }
public override ISet<Namespace> Call(Node node, AnalysisUnit unit, ISet<Namespace>[] args, string[] keywordArgNames) { return _method.ReturnTypes; }
public override void SetIndex(Node node, AnalysisUnit unit, ISet<Namespace> index, ISet<Namespace> value) { _keyTypes.UnionWith(index); _valueTypes.UnionWith(value); }