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 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.º 3
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;
        }