internal virtual void AnalyzeWorker(DDG ddg, CancellationToken cancel)
        {
            ddg.SetCurrentUnit(this);
            Ast.Walk(ddg);

            List <KeyValuePair <string, VariableDef> > toRemove = null;

            foreach (var variableInfo in DeclaringModule.Scope.AllVariables)
            {
                variableInfo.Value.ClearOldValues(ProjectEntry);
                if (!variableInfo.Value.HasTypes && !variableInfo.Value.IsAssigned && !variableInfo.Value.IsEphemeral)
                {
                    toRemove = toRemove ?? new List <KeyValuePair <string, VariableDef> >();
                    toRemove.Add(variableInfo);
                }
            }

            if (toRemove != null)
            {
                // Do not allow variable removal to re-enqueue our unit
                _suppressEnqueue = true;
                try {
                    foreach (var nameValue in toRemove)
                    {
                        DeclaringModule.Scope.RemoveVariable(nameValue.Key);
                        // if anyone read this value it could now be gone (e.g. user
                        // deletes a class definition) so anyone dependent upon it
                        // needs to be updated.
                        nameValue.Value.EnqueueDependents();
                    }
                } finally {
                    _suppressEnqueue = false;
                }
            }
        }
예제 #2
0
        internal virtual void AnalyzeWorker(DDG ddg, CancellationToken cancel)
        {
            DeclaringModule.Scope.ClearLinkedVariables();

            ddg.SetCurrentUnit(this);
            Ast.Walk(ddg);

            List <KeyValuePair <string, VariableDef> > toRemove = null;

            foreach (var variableInfo in DeclaringModule.Scope.AllVariables)
            {
                variableInfo.Value.ClearOldValues(ProjectEntry);
                if (variableInfo.Value._dependencies.Count == 0 &&
                    !variableInfo.Value.HasTypes)
                {
                    if (toRemove == null)
                    {
                        toRemove = new List <KeyValuePair <string, VariableDef> >();
                    }
                    toRemove.Add(variableInfo);
                }
            }
            if (toRemove != null)
            {
                foreach (var nameValue in toRemove)
                {
                    DeclaringModule.Scope.RemoveVariable(nameValue.Key);

                    // if anyone read this value it could now be gone (e.g. user
                    // deletes a class definition) so anyone dependent upon it
                    // needs to be updated.
                    nameValue.Value.EnqueueDependents();
                }
            }
        }
예제 #3
0
        internal 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 <IAnalysisSet>();

            if (Ast.BasesInternal.Length == 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.BasesInternal.Length; i++)
                {
                    var baseClassArg = Ast.BasesInternal[i];

                    if (baseClassArg.Name == null)
                    {
                        bases.Add(EvaluateBaseClass(ddg, classInfo, i, baseClassArg.Expression));
                    }
                    else 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);
                        }
                    }
                }
            }

            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);
        }
        internal virtual void AnalyzeWorker(DDG ddg, CancellationToken cancel)
        {
            Debug.Assert(ddg != null, "ddg unexpected null value");
            Debug.Assert(Ast != null, "Ast has unexpected null value");
            Debug.Assert(ProjectEntry != null, "ProjectEntry has unexpected null value");
            Debug.Assert(DeclaringModuleEnvironment != null, "DeclaringModuleEnvironment has unexpected null value");
            Debug.Assert(DeclaringModuleEnvironment.GlobalEnvironment != null, "DeclaringModuleEnvironment.GlobalEnvironment has unexpected null value");
            Debug.Assert(DeclaringModuleEnvironment.Variables != null, "DeclaringModuleEnvironment.Variables has unexpected null value");

            if (ddg == null || Ast == null || ProjectEntry == null || Tree != ProjectEntry.Tree || DeclaringModuleEnvironment?.Variables == null || DeclaringModuleEnvironment?.GlobalEnvironment == null)
            {
                // analysis unit properties are invalid or we were enqueued and a new version became available
                // don't re-analyze against the old version.
                return;
            }

            DeclaringModuleEnvironment.ClearLinkedVariables();

            ddg.SetCurrentUnit(this);
            Ast.Walk(ddg);

            var toRemove = new List <KeyValuePair <string, VariableDef> >();

            foreach (var variableInfo in DeclaringModuleEnvironment.Variables)
            {
                var value = variableInfo.Value;
                if (value == null)
                {
                    continue;
                }
                value.ClearOldValues(ProjectEntry);
                if (value._dependencies.Count == 0 && value.TypesNoCopy.Count == 0)
                {
                    toRemove.Add(variableInfo);
                }
            }

            foreach (var nameValue in toRemove)
            {
                var globalEnvironment = DeclaringModuleEnvironment.GlobalEnvironment;
                if (globalEnvironment != null)
                {
                    globalEnvironment.RemoveVariable(nameValue.Key);
                }

                // if anyone read this value it could now be gone (e.g. user
                // deletes a class definition) so anyone dependent upon it
                // needs to be updated.
                nameValue.Value?.EnqueueDependents();
            }
        }
예제 #5
0
        internal 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();
        }
예제 #6
0
        internal virtual void AnalyzeWorker(DDG ddg, CancellationToken cancel)
        {
            if (Tree != ProjectEntry.Tree)
            {
                // we were enqueued and a new version became available, don't re-analyze against
                // the old version.
                return;
            }

            DeclaringModuleEnvironment.ClearLinkedVariables();

            ddg.SetCurrentUnit(this);
            Ast.Walk(ddg);

            var toRemove = new List <KeyValuePair <string, VariableDef> >();

            foreach (var variableInfo in DeclaringModuleEnvironment.Variables)
            {
                variableInfo.Value.ClearOldValues(ProjectEntry);
                if (variableInfo.Value._dependencies.Count == 0 &&
                    variableInfo.Value.TypesNoCopy.Count == 0)
                {
                    toRemove.Add(variableInfo);
                }
            }

            foreach (var nameValue in toRemove)
            {
                DeclaringModuleEnvironment.GlobalEnvironment.RemoveVariable(nameValue.Key);

                // if anyone read this value it could now be gone (e.g. user
                // deletes a class definition) so anyone dependent upon it
                // needs to be updated.
                nameValue.Value.EnqueueDependents();
            }
        }