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();
            }
        }
예제 #2
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();
            }
        }