Ejemplo n.º 1
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 static string GetQualifiedFunctionName(PythonProcess process, string filename, int lineNo, string functionName)
        {
            var ast = 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);
        }
Ejemplo n.º 2
0
        public static string GetDisplayName(int lineNo, string functionName, PythonAst ast, Func <string, string, string> nameAggregator)
        {
            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);
            }

            var names = walker.Name;

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

            return(functionName);
        }
Ejemplo n.º 3
0
        public static string GetQualifiedFunctionName(PythonProcess process, string filename, int lineNo, string functionName)
        {
            var ast = process.GetAst(filename);

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

            return(QualifiedFunctionNameWalker.GetDisplayName(
                       lineNo,
                       functionName,
                       ast,
                       (a, n) => string.IsNullOrEmpty(a) ? n : Strings.DebugStackFrameNameInName.FormatUI(n, a)
                       ));
        }
Ejemplo n.º 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);

            ast.Walk(walker);

            string qualName = walker.Name;

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

            return(qualName);
        }