Beispiel #1
0
        protected override void AnalyzeWorker(DDG ddg, CancellationToken cancel)
        {
            base.AnalyzeWorker(ddg, cancel);

            var dict = (DictionaryInfo)Scope.Namespace;
            var node = (DictionaryComprehension)Ast;

            dict.SetIndex(node, this, ddg._eval.Evaluate(node.Key), ddg._eval.Evaluate(node.Value));
        }
Beispiel #2
0
        protected override void AnalyzeWorker(DDG ddg, CancellationToken cancel)
        {
            base.AnalyzeWorker(ddg, cancel);

            var list = (ListInfo)Scope.Namespace;
            var node = (ListComprehension)Ast;

            list.AddTypes(this, new[] { ddg._eval.Evaluate(node.Item) });
        }
Beispiel #3
0
        protected override void AnalyzeWorker(DDG ddg, CancellationToken cancel)
        {
            base.AnalyzeWorker(ddg, cancel);

            var set  = (SetInfo)Scope.Namespace;
            var node = (SetComprehension)Ast;

            set.AddTypes(this, ddg._eval.Evaluate(node.Item));
        }
Beispiel #4
0
        protected override void AnalyzeWorker(DDG ddg, CancellationToken cancel)
        {
            base.AnalyzeWorker(ddg, cancel);

            var generator = (GeneratorInfo)Scope.Namespace;
            var node      = (GeneratorExpression)Ast;

            generator.AddYield(node, this, ddg._eval.Evaluate(node.Item));
        }
Beispiel #5
0
        internal static INamespaceSet EvaluateBaseClass(DDG ddg, ClassInfo newClass, int indexInBaseList, Expression baseClass)
        {
            baseClass.Walk(ddg);
            var bases = ddg._eval.Evaluate(baseClass);

            foreach (var baseValue in bases)
            {
                ClassInfo ci = baseValue as ClassInfo;
                if (ci != null)
                {
                    ci.SubClasses.AddTypes(newClass.AnalysisUnit, new[] { newClass });
                }
            }

            return(bases);
        }
Beispiel #6
0
        public void Analyze(DDG ddg)
        {
#if DEBUG
            long startTime = _sw.ElapsedMilliseconds;
            try {
#endif
            //Console.WriteLine("Analying: {0} ({1})", Ast.Name == "<module>" ? this.ProjectEntry.ModuleName : Ast.Name, Ast.GetType().Name);
            AnalyzeWorker(ddg);
#if DEBUG
        }
        finally {
            long endTime = _sw.ElapsedMilliseconds;
            _analysisTime += endTime - startTime;
            if (_analysisTime >= 500)
            {
                Console.WriteLine("Analyzed: {0} {1} ({2} total)", this, endTime - startTime, _analysisTime);
            }
        }
#endif
        }
Beispiel #7
0
        protected override void AnalyzeWorker(DDG ddg, CancellationToken cancel)
        {
            ddg.SetCurrentUnit(this);

            InterpreterScope scope;

            if (!ddg.Scope.TryGetNodeScope(Ast, out scope))
            {
                return;
            }

            var classInfo = ((ClassScope)scope).Class;
            var bases     = ClassAnalysisUnit.EvaluateBaseClass(
                ddg,
                classInfo,
                _indexInBasesList,
                _baseClassNode
                );

            classInfo.SetBase(_indexInBasesList, bases);

            _outerUnit.Enqueue();
        }
Beispiel #8
0
        protected override void AnalyzeWorker(DDG ddg)
        {
            var newScope = (DeclaringModule.NodeScopes[Ast] as ClassScope).Class;

            newScope.Bases.Clear();
            // Process base classes
            foreach (var baseClass in Ast.Bases)
            {
                baseClass.Walk(ddg);
                var bases = ddg._eval.Evaluate(baseClass);
                newScope.Bases.Add(bases);

                foreach (var baseValue in bases)
                {
                    ClassInfo ci = baseValue as ClassInfo;
                    if (ci != null)
                    {
                        ci.SubClasses.AddTypes(Ast, newScope._analysisUnit, new[] { newScope });
                    }
                }
            }

            ddg.WalkBody(Ast.Body, newScope._analysisUnit);
        }
Beispiel #9
0
 protected virtual void AnalyzeWorker(DDG ddg)
 {
     Ast.Walk(ddg);
 }
Beispiel #10
0
        protected override void AnalyzeWorker(DDG ddg, CancellationToken cancel)
        {
            InterpreterScope scope;

            if (!ddg.Scope.TryGetNodeScope(Ast, out scope))
            {
                return;
            }

            var classInfo = ((ClassScope)scope).Class;
            var bases     = new List <INamespaceSet>();

            if (Ast.Bases.Count == 0)
            {
                if (ddg.ProjectState.LanguageVersion.Is3x())
                {
                    // 3.x all classes inherit from object by default
                    bases.Add(ddg.ProjectState.ClassInfos[BuiltinTypeId.Object]);
                }
            }
            else
            {
                // Process base classes
                for (int i = 0; i < Ast.Bases.Count; i++)
                {
                    var baseClassArg = Ast.Bases[i];

                    ddg.SetCurrentUnit(_baseEvals[i]);

                    if (baseClassArg.Name != null)
                    {
                        if (baseClassArg.Name == "metaclass")
                        {
                            var metaClass = baseClassArg.Expression;
                            metaClass.Walk(ddg);
                            var metaClassValue = ddg._eval.Evaluate(metaClass);
                            if (metaClassValue.Count > 0)
                            {
                                classInfo.GetOrCreateMetaclassVariable().AddTypes(_outerUnit, metaClassValue);
                            }
                        }
                        continue;
                    }

                    var baseExpr = baseClassArg.Expression;
                    var baseSet  = EvaluateBaseClass(ddg, classInfo, i, baseExpr);
                    bases.Add(baseSet);
                }
            }

            classInfo.SetBases(bases);

            foreach (var baseSet in bases)
            {
                foreach (var baseClassInfo in baseSet.OfType <ClassInfo>())
                {
                    baseClassInfo.Mro.AddDependency(this);
                }
            }

            ddg.SetCurrentUnit(this);
            ddg.WalkBody(Ast.Body, classInfo.AnalysisUnit);
        }