cpython/Python/ast_unparse.c

#include "Python.h"
#include "pycore_ast.h"           // expr_ty
#include "pycore_pystate.h"       // _PyInterpreterState_GET()
#include "pycore_runtime.h"       // _Py_ID()
#include <stdbool.h>

/* This limited unparser is used to convert annotations back to strings
 * during compilation rather than being a full AST unparser.
 * See ast.unparse for a full unparser (written in Python)
 */

_Py_DECLARE_STR(dbl_open_br, "{{");
_Py_DECLARE_STR(dbl_close_br, "}}");

/* Forward declarations for recursion via helper functions. */
static PyObject *
expr_as_unicode(expr_ty e, int level);
static int
append_ast_expr(_PyUnicodeWriter *writer, expr_ty e, int level);
static int
append_joinedstr(_PyUnicodeWriter *writer, expr_ty e, bool is_format_spec);
static int
append_formattedvalue(_PyUnicodeWriter *writer, expr_ty e);
static int
append_ast_slice(_PyUnicodeWriter *writer, expr_ty e);

static int
append_charp(_PyUnicodeWriter *writer, const char *charp)
{}

#define APPEND_STR_FINISH(str)

#define APPEND_STR(str)

#define APPEND_STR_IF(cond, str)

#define APPEND_STR_IF_NOT_FIRST(str)

#define APPEND_EXPR(expr, pr)

#define APPEND(type, value)

static int
append_repr(_PyUnicodeWriter *writer, PyObject *obj)
{}

/* Priority levels */

enum {};

static int
append_ast_boolop(_PyUnicodeWriter *writer, expr_ty e, int level)
{}

static int
append_ast_binop(_PyUnicodeWriter *writer, expr_ty e, int level)
{}

static int
append_ast_unaryop(_PyUnicodeWriter *writer, expr_ty e, int level)
{}

static int
append_ast_arg(_PyUnicodeWriter *writer, arg_ty arg)
{}

static int
append_ast_args(_PyUnicodeWriter *writer, arguments_ty args)
{}

static int
append_ast_lambda(_PyUnicodeWriter *writer, expr_ty e, int level)
{}

static int
append_ast_ifexp(_PyUnicodeWriter *writer, expr_ty e, int level)
{}

static int
append_ast_dict(_PyUnicodeWriter *writer, expr_ty e)
{}

static int
append_ast_set(_PyUnicodeWriter *writer, expr_ty e)
{}

static int
append_ast_list(_PyUnicodeWriter *writer, expr_ty e)
{}

static int
append_ast_tuple(_PyUnicodeWriter *writer, expr_ty e, int level)
{}

static int
append_ast_comprehension(_PyUnicodeWriter *writer, comprehension_ty gen)
{}

static int
append_ast_comprehensions(_PyUnicodeWriter *writer, asdl_comprehension_seq *comprehensions)
{}

static int
append_ast_genexp(_PyUnicodeWriter *writer, expr_ty e)
{}

static int
append_ast_listcomp(_PyUnicodeWriter *writer, expr_ty e)
{}

static int
append_ast_setcomp(_PyUnicodeWriter *writer, expr_ty e)
{}

static int
append_ast_dictcomp(_PyUnicodeWriter *writer, expr_ty e)
{}

static int
append_ast_compare(_PyUnicodeWriter *writer, expr_ty e, int level)
{}

static int
append_ast_keyword(_PyUnicodeWriter *writer, keyword_ty kw)
{}

static int
append_ast_call(_PyUnicodeWriter *writer, expr_ty e)
{}

static PyObject *
escape_braces(PyObject *orig)
{}

static int
append_fstring_unicode(_PyUnicodeWriter *writer, PyObject *unicode)
{}

static int
append_fstring_element(_PyUnicodeWriter *writer, expr_ty e, bool is_format_spec)
{}

/* Build body separately to enable wrapping the entire stream of Strs,
   Constants and FormattedValues in one opening and one closing quote. */
static PyObject *
build_fstring_body(asdl_expr_seq *values, bool is_format_spec)
{}

static int
append_joinedstr(_PyUnicodeWriter *writer, expr_ty e, bool is_format_spec)
{}

static int
append_formattedvalue(_PyUnicodeWriter *writer, expr_ty e)
{}

static int
append_ast_constant(_PyUnicodeWriter *writer, PyObject *constant)
{}

static int
append_ast_attribute(_PyUnicodeWriter *writer, expr_ty e)
{}

static int
append_ast_slice(_PyUnicodeWriter *writer, expr_ty e)
{}

static int
append_ast_subscript(_PyUnicodeWriter *writer, expr_ty e)
{}

static int
append_ast_starred(_PyUnicodeWriter *writer, expr_ty e)
{}

static int
append_ast_yield(_PyUnicodeWriter *writer, expr_ty e)
{}

static int
append_ast_yield_from(_PyUnicodeWriter *writer, expr_ty e)
{}

static int
append_ast_await(_PyUnicodeWriter *writer, expr_ty e, int level)
{}

static int
append_named_expr(_PyUnicodeWriter *writer, expr_ty e, int level)
{}

static int
append_ast_expr(_PyUnicodeWriter *writer, expr_ty e, int level)
{}

static PyObject *
expr_as_unicode(expr_ty e, int level)
{}

PyObject *
_PyAST_ExprAsUnicode(expr_ty e)
{}