Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:80754 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 19537 invoked from network); 18 Jan 2015 17:22:27 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 18 Jan 2015 17:22:27 -0000 Authentication-Results: pb1.pair.com smtp.mail=php@golemon.com; spf=softfail; sender-id=softfail Authentication-Results: pb1.pair.com header.from=php@golemon.com; sender-id=softfail Received-SPF: softfail (pb1.pair.com: domain golemon.com does not designate 209.85.215.52 as permitted sender) X-PHP-List-Original-Sender: php@golemon.com X-Host-Fingerprint: 209.85.215.52 mail-la0-f52.google.com Received: from [209.85.215.52] ([209.85.215.52:56050] helo=mail-la0-f52.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 71/51-18613-2DBEBB45 for ; Sun, 18 Jan 2015 12:22:26 -0500 Received: by mail-la0-f52.google.com with SMTP id hs14so25423496lab.11 for ; Sun, 18 Jan 2015 09:22:22 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:sender:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=5nQyb20yolxZLAATgC05QcLeCtRXlPPF+GEdruMWmFI=; b=aygfV59BmfokWOc1qxEzoNK0zzSnSSoyJm0XNhD6rcWWy1lJVI+3vs3m/GebtG6T9G CtvhlDh4nVJ7IVr5WBb635izQvZ/AJutmrrMBjHbhhwJHB9JbNEYMenUFcmi0fSvojRl y0KPEsLqefh+JjuDuIMO+/+hdMIj0kk0rX/7fFIsItLnlGtRdjNB/F5nJkMMwHJWrmFA PFKf+F0wnjszGa3e/Usbiii3SSY46xFi/9DUGyiVheoRB+ZoSsEzheT23i0/K0sXWzeO j9g/JbhwOrYpkNTduHxu0uhvQ/o5HsmeXfNeefKCAyR1Op8i2R9muQ0JOCMzpJHFn6+j k7Qg== X-Gm-Message-State: ALoCoQnb4jGdwN6CMp9vbWsTdGOTizY+PgBskVeGXo4iRu5SFoNN9JoqjqjrKTtZxq0TtrXCBmcZ MIME-Version: 1.0 X-Received: by 10.112.183.197 with SMTP id eo5mr7630070lbc.81.1421601742591; Sun, 18 Jan 2015 09:22:22 -0800 (PST) Sender: php@golemon.com Received: by 10.112.126.65 with HTTP; Sun, 18 Jan 2015 09:22:22 -0800 (PST) X-Originating-IP: [69.63.185.56] In-Reply-To: References: Date: Sun, 18 Jan 2015 09:22:22 -0800 X-Google-Sender-Auth: uU5j7OKwyxpquJVYZsappY3yMEk Message-ID: To: Nikita Popov Cc: PHP internals Content-Type: text/plain; charset=UTF-8 Subject: Re: [PHP-DEV] Mind if I hook the compiler? From: pollita@php.net (Sara Golemon) On Sun, Jan 18, 2015 at 8:50 AM, Nikita Popov 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));