Пример #1
0
 private AnalysisUnit(Node ast, InterpreterScope[] scopes, AnalysisUnit parent, bool forEval)
 {
     _ast = ast;
     _scopes = scopes;
     _parent = parent;
     _forEval = forEval;
 }
Пример #2
0
 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;
        }
Пример #5
0
 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
 }
Пример #6
0
 public override void PostWalk(FunctionDefinition node)
 {
     if (node.Body != null && node.Name != null) {
         _scopes.Pop();
         _scopeTree.Pop();
         _curUnit = _analysisStack.Pop();
     }
 }
Пример #7
0
 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);
     }
 }
Пример #8
0
 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;
        }
Пример #10
0
        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));
        }
Пример #11
0
 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;
 }
Пример #12
0
        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;
        }
Пример #13
0
        /// <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;
        }
Пример #14
0
 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);
 }
Пример #15
0
 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);
 }
Пример #16
0
        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;
        }
Пример #17
0
        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);
        }
Пример #18
0
 public ExpressionEvaluator(AnalysisUnit unit, InterpreterScope[] scopes)
 {
     _unit = unit;
     _currentScopes = scopes;
 }
Пример #19
0
 /// <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;
 }
Пример #20
0
 protected UserDefinedInfo(AnalysisUnit analysisUnit)
 {
     _analysisUnit = analysisUnit;
 }
Пример #21
0
 public override ISet<Namespace> GetIndex(Node node, AnalysisUnit unit, ISet<Namespace> index)
 {
     return _valueTypes;
 }
Пример #22
0
            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]);
            }
Пример #23
0
 public void AddDependency(AnalysisUnit unit)
 {
     _dependencies.Add(unit.ProjectEntry);
 }
Пример #24
0
        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);
        }
Пример #25
0
        public override ISet<Namespace> GetMember(Node node, AnalysisUnit unit, string name)
        {
            ModuleDefinition.AddDependency(unit);

            return Scope.CreateVariable(node, unit, name).Types;
        }
Пример #26
0
 public VariableDef DefineVariable(Parameter node, AnalysisUnit unit)
 {
     return(Variables[node.Name] = new LocatedVariableDef(unit.DeclaringModule.ProjectEntry, node));
 }
Пример #27
0
        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);
        }
Пример #28
0
        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);
            }
        }
Пример #29
0
        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);
        }
Пример #30
0
 public override ISet<Namespace> Call(Node node, AnalysisUnit unit, ISet<Namespace>[] args, string[] keywordArgNames)
 {
     return _method.ReturnTypes;
 }
Пример #31
0
 public override void SetIndex(Node node, AnalysisUnit unit, ISet<Namespace> index, ISet<Namespace> value)
 {
     _keyTypes.UnionWith(index);
     _valueTypes.UnionWith(value);
 }