private IEnumerable <IAnalysisVariable> GetVariablesInScope(NameExpression name, InterpreterScope scope)
        {
            var result = new List <IAnalysisVariable>();

            result.AddRange(scope.GetMergedVariables(name.Name).SelectMany(ToVariables));

            // if a variable is imported from another module then also yield the defs/refs for the
            // value in the defining module.
            var linked = scope.GetLinkedVariablesNoCreate(name.Name);

            if (linked != null)
            {
                result.AddRange(linked.SelectMany(ToVariables));
            }

            var classScope = scope as ClassScope;

            if (classScope != null)
            {
                // if the member is defined in a base class as well include the base class member and references
                var cls = classScope.Class;
                if (cls.Push())
                {
                    try {
                        foreach (var baseNs in cls.Bases.SelectMany())
                        {
                            if (baseNs.Push())
                            {
                                try {
                                    ClassInfo baseClassNs = baseNs as ClassInfo;
                                    if (baseClassNs != null)
                                    {
                                        result.AddRange(
                                            baseClassNs.Scope.GetMergedVariables(name.Name).SelectMany(ToVariables)
                                            );
                                    }
                                } finally {
                                    baseNs.Pop();
                                }
                            }
                        }
                    } finally {
                        cls.Pop();
                    }
                }
            }

            return(result);
        }