[njs] Printing AST before trying to generate code.

Dmitry Volyntsev xeioex at nginx.com
Fri Jun 18 15:07:38 UTC 2021


details:   https://hg.nginx.org/njs/rev/d66e00e55b96
branches:  
changeset: 1664:d66e00e55b96
user:      Dmitry Volyntsev <xeioex at nginx.com>
date:      Fri Jun 18 15:01:12 2021 +0000
description:
Printing AST before trying to generate code.

diffstat:

 src/njs_vm.c |  34 +++++++++++++++++-----------------
 1 files changed, 17 insertions(+), 17 deletions(-)

diffs (51 lines):

diff -r 8d4bf6ec4002 -r d66e00e55b96 src/njs_vm.c
--- a/src/njs_vm.c	Fri Jun 18 15:00:32 2021 +0000
+++ b/src/njs_vm.c	Fri Jun 18 15:01:12 2021 +0000
@@ -150,6 +150,23 @@ njs_vm_compile(njs_vm_t *vm, u_char **st
         return NJS_ERROR;
     }
 
+    if (njs_slow_path(vm->options.ast)) {
+        njs_chb_init(&chain, vm->mem_pool);
+        ret = njs_parser_serialize_ast(parser.node, &chain);
+        if (njs_slow_path(ret == NJS_ERROR)) {
+            return ret;
+        }
+
+        if (njs_slow_path(njs_chb_join(&chain, &ast) != NJS_OK)) {
+            return NJS_ERROR;
+        }
+
+        njs_print(ast.start, ast.length);
+
+        njs_chb_destroy(&chain);
+        njs_mp_free(vm->mem_pool, ast.start);
+    }
+
     *start = lexer.start;
     scope = parser.scope;
 
@@ -209,23 +226,6 @@ njs_vm_compile(njs_vm_t *vm, u_char **st
         njs_disassembler(vm);
     }
 
-    if (njs_slow_path(vm->options.ast)) {
-        njs_chb_init(&chain, vm->mem_pool);
-        ret = njs_parser_serialize_ast(parser.node, &chain);
-        if (njs_slow_path(ret == NJS_ERROR)) {
-            return ret;
-        }
-
-        if (njs_slow_path(njs_chb_join(&chain, &ast) != NJS_OK)) {
-            return NJS_ERROR;
-        }
-
-        njs_print(ast.start, ast.length);
-
-        njs_chb_destroy(&chain);
-        njs_mp_free(vm->mem_pool, ast.start);
-    }
-
     return NJS_OK;
 }
 


More information about the nginx-devel mailing list