-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Switch to bison location tracking #3948
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Enable use of bison location tracking, keeping only information on the starting line number. Use this in a few places in the parser which currently perform manual zend_lineno manipulations.
If multiple nodes are created in a single action, either split it up or correct the used location info.
Create a zend_ast_loc from an ast node.
The end_lineno is still passed separately.
Also use the location of the lookahead token instead of the pre-reduction location in YYLLOC_DEFAULT for empty reductions.
For consistency.
Do we expect this to have any major impact on code coverage tools like
Xdebug, phpdbg, and pcov?
I would suppose not, or if anything a positive impact - increased accuracy
... But thought it worth clarifying?
Cheers
Joe
…On Fri, 15 Mar 2019, 16:36 Nikita Popov, ***@***.***> wrote:
This switches the location tracking for AST nodes from some custom code
based on CG(zend_lineno) to using bison location tracking.
What we were doing before is to take the zend_lineno (end line of a token)
of the first available AST child node, or the current zend_lineno if there
is none. This mostly works out okay, but is not fully precise, rather
convoluted and not extensible. If we ever want to have additional
information (such as precise offsets), the current approach will no longer
work.
This patch instead uses the native location tracking provided by bison.
Similar to AST nodes, locations are kept on a separate stack. Right now the
location is just the start line number, but this can now be easily extended.
------------------------------
You can view, comment on, or merge this pull request online at:
#3948
Commit Summary
- Basic use of bison location tracking
- Pass zend_ast_loc to all ast ctors
- Fixup some locations
- Add a zend_ast_get_loc() helper
- Pass loc to create_decl as well
- Pass location to lex_scan and handle it there
- Remove the increment_lineno concept
- Also pass loc to ast_create_znode
File Changes
- *M* Zend/zend_ast.c
<https://github.com/php/php-src/pull/3948/files#diff-0> (184)
- *M* Zend/zend_ast.h
<https://github.com/php/php-src/pull/3948/files#diff-1> (90)
- *M* Zend/zend_compile.c
<https://github.com/php/php-src/pull/3948/files#diff-2> (54)
- *M* Zend/zend_compile.h
<https://github.com/php/php-src/pull/3948/files#diff-3> (6)
- *M* Zend/zend_globals.h
<https://github.com/php/php-src/pull/3948/files#diff-4> (1)
- *M* Zend/zend_highlight.c
<https://github.com/php/php-src/pull/3948/files#diff-5> (8)
- *M* Zend/zend_language_parser.y
<https://github.com/php/php-src/pull/3948/files#diff-6> (554)
- *M* Zend/zend_language_scanner.l
<https://github.com/php/php-src/pull/3948/files#diff-7> (25)
- *M* ext/tokenizer/tokenizer.c
<https://github.com/php/php-src/pull/3948/files#diff-8> (15)
Patch Links:
- https://github.com/php/php-src/pull/3948.patch
- https://github.com/php/php-src/pull/3948.diff
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#3948>, or mute the thread
<https://github.com/notifications/unsubscribe-auth/ACIe6mqmOYOm-nhVg1KJbCqlh9Y7ws1Eks5vW74PgaJpZM4b2vS->
.
|
@krakjoe It may impact, but should only be positive. |
That's what I thought, but I was more looking for examples of where the current method is known to be inaccurate, so that we may document the reason for any possible subtle changes when this is merged. |
@krakjoe I'm not sure if anything would even change right now for coverage. I wanted to give something like
as an example, but this will still put the ZEND_ECHO on line 3 rather than 2. While the information in the AST node is now correct, the way the compiler works it's still prone to pick up the last rather than first lineno inside a node. I think the main thing this will impact is start line numbers in php-ast (which will now be 2 rather than 3 for the above example). |
ok, good |
Merged as e528762. |
Newbie question: set_error_handler(function( $errno , $errstr, $errfile, $errline, $errcontext, $new_errColumn ){
...
}); That would be great! |
I have a comprehensive error-reporting portal where I group the error messages by file, line and column. |
@nuxodin this is not the right channel for your question. I guess you should report a issue on bugs-net or open a discussion on the mailing list |
This switches the location tracking for AST nodes from some custom code based on CG(zend_lineno) to using bison location tracking.
What we were doing before is to take the zend_lineno (end line of a token) of the first available AST child node, or the current zend_lineno if there is none. This mostly works out okay, but is not fully precise, rather convoluted and not extensible. If we ever want to have additional information (such as precise offsets), the current approach will no longer work.
This patch instead uses the native location tracking provided by bison. Similar to AST nodes, locations are kept on a separate stack. Right now the location is just the start line number, but this can now be easily extended.
All the AST constructors now take
zend_ast_loc*
as the first argument, which is passed as&@$
(in most cases) on the bison side.