コード例 #1
0
ファイル: AnalysisUnit.cs プロジェクト: TerabyteX/main
 private AnalysisUnit(Node ast, InterpreterScope[] scopes, AnalysisUnit parent, bool forEval)
 {
     _ast = ast;
     _scopes = scopes;
     _parent = parent;
     _forEval = forEval;
 }
コード例 #2
0
ファイル: ReflectedNamespace.cs プロジェクト: TerabyteX/main
 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;
 }
コード例 #3
0
        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;
        }
コード例 #4
0
        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
ファイル: FunctionInfo.cs プロジェクト: TerabyteX/main
 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
ファイル: OverviewWalker.cs プロジェクト: TerabyteX/main
 public override void PostWalk(FunctionDefinition node)
 {
     if (node.Body != null && node.Name != null) {
         _scopes.Pop();
         _scopeTree.Pop();
         _curUnit = _analysisStack.Pop();
     }
 }
コード例 #7
0
ファイル: BuiltinEventInfo.cs プロジェクト: TerabyteX/main
 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
ファイル: ClassInfo.cs プロジェクト: TerabyteX/main
 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;
 }
コード例 #9
0
        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
ファイル: OverviewWalker.cs プロジェクト: TerabyteX/main
        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
ファイル: InterpreterScope.cs プロジェクト: TerabyteX/main
 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
ファイル: RangeInfo.cs プロジェクト: TerabyteX/main
        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
ファイル: DependencyInfo.cs プロジェクト: TerabyteX/main
 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
ファイル: NumericInstanceInfo.cs プロジェクト: TerabyteX/main
 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
ファイル: ListInfo.cs プロジェクト: TerabyteX/main
        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
ファイル: ExpressionEvaluator.cs プロジェクト: TerabyteX/main
 public ExpressionEvaluator(AnalysisUnit unit, InterpreterScope[] scopes)
 {
     _unit = unit;
     _currentScopes = scopes;
 }
コード例 #19
0
ファイル: ExpressionEvaluator.cs プロジェクト: TerabyteX/main
 /// <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
ファイル: UserDefinedInfo.cs プロジェクト: TerabyteX/main
 protected UserDefinedInfo(AnalysisUnit analysisUnit)
 {
     _analysisUnit = analysisUnit;
 }
コード例 #21
0
ファイル: DictionaryInfo.cs プロジェクト: TerabyteX/main
 public override ISet<Namespace> GetIndex(Node node, AnalysisUnit unit, ISet<Namespace> index)
 {
     return _valueTypes;
 }
コード例 #22
0
ファイル: DictionaryInfo.cs プロジェクト: TerabyteX/main
            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
ファイル: ProjectEntry.cs プロジェクト: TerabyteX/main
 public void AddDependency(AnalysisUnit unit)
 {
     _dependencies.Add(unit.ProjectEntry);
 }
コード例 #24
0
ファイル: ModuleInfo.cs プロジェクト: TerabyteX/main
        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
ファイル: ModuleInfo.cs プロジェクト: TerabyteX/main
        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
ファイル: ProjectEntry.cs プロジェクト: TerabyteX/main
        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
ファイル: ProjectEntry.cs プロジェクト: TerabyteX/main
        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
ファイル: DictionaryInfo.cs プロジェクト: TerabyteX/main
        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
ファイル: DictionaryInfo.cs プロジェクト: TerabyteX/main
 public override void SetIndex(Node node, AnalysisUnit unit, ISet<Namespace> index, ISet<Namespace> value)
 {
     _keyTypes.UnionWith(index);
     _valueTypes.UnionWith(value);
 }