On Sun, Jan 18, 2015 at 8:50 AM, Nikita Popov <nikita....@gmail.com> wrote:
> Totally okay with making that hookable, but not sure if compile_top_stmt is
> the best place to do that, at least in the form implemented in the PR.
> Assuming that you want to implement a preprocessing pass on the AST the fast
> that zend_compile_top_stmt is called recursively might be somewhat
> inconvenient. Maybe compile_top_stmt should at least also call
> compile_top_stmt instead of zend_compile_top_stmt?
>
I did think about that, and ended up with this spot on the idea that
one could just let the main implementation worry about recursive, and
only alter patters as they're seen.

For example, if my extension wants only wants to do constant folding,
I might wait until I get fed an ast node for looking up constants
rather than drilling down myself, then leaving the engine to drill
down again.

That said, I'm not married to that approach, I could add the hook more
here instead and be just as happy:

diff --git a/Zend/zend_language_scanner.l b/Zend/zend_language_scanner.l
index 2412631..0ebf0c2 100644
--- a/Zend/zend_language_scanner.l
+++ b/Zend/zend_language_scanner.l
@@ -586,6 +586,9 @@ ZEND_API zend_op_array
*compile_file(zend_file_handle *file_handle, int type)
                if (compiler_result != 0) { /* parser error */
                        zend_bailout();
                }
+               if (zend_ast_hook) {
+                       zend_ast_hook(CG(ast));
+               }
                zend_compile_top_stmt(CG(ast));
                zend_ast_destroy(CG(ast));
                zend_arena_destroy(CG(ast_arena));

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to