From f587c249dc7ea4be5cba7f8c532634df89b84258 Mon Sep 17 00:00:00 2001 From: Pablo Galindo Date: Mon, 27 Jul 2020 23:19:07 +0100 Subject: [PATCH 1/2] Validate the AST produced by the parser in debug mode --- Parser/pegen.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Parser/pegen.c b/Parser/pegen.c index e2cbf8ba2461ce..6da30cb8eec4c1 100644 --- a/Parser/pegen.c +++ b/Parser/pegen.c @@ -4,6 +4,7 @@ #include "pegen.h" #include "string_parser.h" +#include "ast.h" PyObject * _PyPegen_new_type_comment(Parser *p, char *s) @@ -1137,6 +1138,13 @@ _PyPegen_run_parser(Parser *p) return RAISE_SYNTAX_ERROR("multiple statements found while compiling a single statement"); } +#if defined(Py_DEBUG) && defined(Py_BUILD_CORE) + if (p->start_rule == Py_single_input || + p->start_rule == Py_file_input || + p->start_rule == Py_eval_input) { + assert(PyAST_Validate(res)); + } +#endif return res; } From f3f9032742fad885eafb587a2024386992dc284a Mon Sep 17 00:00:00 2001 From: Pablo Galindo Date: Mon, 27 Jul 2020 23:25:25 +0100 Subject: [PATCH 2/2] Update Parser/pegen.c Co-authored-by: Lysandros Nikolaou --- Parser/pegen.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Parser/pegen.c b/Parser/pegen.c index 6da30cb8eec4c1..f615907f5f571f 100644 --- a/Parser/pegen.c +++ b/Parser/pegen.c @@ -1141,7 +1141,8 @@ _PyPegen_run_parser(Parser *p) #if defined(Py_DEBUG) && defined(Py_BUILD_CORE) if (p->start_rule == Py_single_input || p->start_rule == Py_file_input || - p->start_rule == Py_eval_input) { + p->start_rule == Py_eval_input) + { assert(PyAST_Validate(res)); } #endif