Beispiel #1
0
        private static string GetQualifiedFunctionName(string filename, int lineNo, string functionName, PythonLanguageVersion version)
        {
            PythonAst ast = null;

            try {
                using (var source = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read)) {
                    ast = Parser.CreateParser(source, version).ParseFile();
                }
            } catch (ArgumentException) {
            } catch (IOException) {
            } catch (UnauthorizedAccessException) {
            } catch (NotSupportedException) {
            } catch (System.Security.SecurityException) {
            }

            if (ast == null)
            {
                return(functionName);
            }

            return(QualifiedFunctionNameWalker.GetDisplayName(
                       lineNo,
                       functionName,
                       ast,
                       (a, n) => string.IsNullOrEmpty(a) ? n : Strings.DebugStackFrameNameInName.FormatUI(n, a)
                       ));
        }
Beispiel #2
0
        public static string GetDisplayName(int lineNo, string functionName, PythonAst ast, Func <string, string, string> nameAggregator)
        {
            QualifiedFunctionNameWalker walker = new QualifiedFunctionNameWalker(ast, lineNo, functionName);

            try
            {
                ast.Walk(walker);
            }
            catch (InvalidDataException)
            {
                // Walker ran into a mismatch between expected function name and AST, so we cannot
                // rely on AST to construct an accurate qualified name. Just return what we have.
                return(functionName);
            }

            var names = walker.Name;

            if (names.Any())
            {
                string qualName = names.Aggregate(nameAggregator);
                if (!string.IsNullOrEmpty(qualName))
                {
                    return(qualName);
                }
            }

            return(functionName);
        }
Beispiel #3
0
        private static string GetQualifiedFunctionName(string filename, int lineNo, string functionName, PythonLanguageVersion version)
        {
            PythonAst ast = null;

            try {
                using (var source = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read)) {
                    ast = Parser.CreateParser(source, version).ParseFile();
                }
            } catch (ArgumentException) {
            } catch (IOException) {
            } catch (UnauthorizedAccessException) {
            } catch (NotSupportedException) {
            } catch (System.Security.SecurityException) {
            }

            if (ast == null)
            {
                return(functionName);
            }

            var walker = new QualifiedFunctionNameWalker(ast, lineNo, functionName);

            try {
                ast.Walk(walker);
            } catch (InvalidDataException) {
                // Walker ran into a mismatch between expected function name and AST, so we cannot
                // rely on AST to construct an accurate qualified name. Just return what we have.
                return(functionName);
            }

            string qualName = walker.Name;

            if (string.IsNullOrEmpty(qualName))
            {
                return(functionName);
            }

            return(qualName);
        }
Beispiel #4
0
        /// <summary>
        /// Computes the fully qualified function name, including name of the enclosing class for methods,
        /// and, recursively, names of any outer functions.
        /// </summary>
        /// <example>
        /// Given this code:
        /// <code>
        /// class A:
        ///   def b(self):
        ///     def c():
        ///       class D:
        ///         def e(self):
        ///           pass
        /// </code>
        /// And with the current statement being <c>pass</c>, the qualified name is "D.e in c in A.b".
        /// </example>
        public string GetQualifiedFunctionName() {
            var ast = _thread.Process.GetAst(FileName);
            if (ast == null) {
                return FunctionName;
            }

            var walker = new QualifiedFunctionNameWalker(ast, LineNo, FunctionName);
            try {
                ast.Walk(walker);
            } catch (InvalidDataException) {
                // Walker ran into a mismatch between expected function name and AST, so we cannot
                // rely on AST to construct an accurate qualified name. Just return what we have.
                return FunctionName;
            }

            string qualName = walker.Name;
            if (string.IsNullOrEmpty(qualName)) {
                return FunctionName;
            }

            return qualName;
        }