php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #70024 Add column information to AST
Submitted: 2015-07-08 14:47 UTC Modified: 2019-03-15 15:42 UTC
Votes:2
Avg. Score:3.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: krblock at computer dot org Assigned: nikic (profile)
Status: Assigned Package: *Compile Issues
PHP Version: 7.0.0alpha2 OS:
Private report: No CVE-ID: None
 [2015-07-08 14:47 UTC] krblock at computer dot org
Description:
------------
I am evaluating PHP Parsers to use in a Static Analysis tool. When defects are reported, we like to pin point the location of the issue as precisely as possible. We also like to provide cross reference information. It would be useful to have column location stored in the AST in addition to line location. 

Test script:
---------------
I used the AST dumper provided here:

https://github.com/nikic/php-ast

RFC for AST is here:

https://wiki.php.net/rfc/abstract_syntax_tree

Both omit column information.


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-07-09 07:41 UTC] kalle@php.net
-Status: Open +Status: Assigned -Assigned To: +Assigned To: nikic
 [2015-07-09 07:41 UTC] kalle@php.net
I don't think we uses columns anywhere in the code to help identify errors, so we would have to add it just for this feature, Nikita do you have any input on this? (Just unassign after if desired)
 [2015-07-09 09:42 UTC] nikic@php.net
Yeah, we currently only store the line number. Adding accurate position information would require an additional 16 bytes per AST node. I'm not sure if this is worthwhile if we don't need this info ourselves.
 [2015-07-09 13:18 UTC] krblock at computer dot org
Static Analysis is not run on every invocation of a compiler, so it is much more tolerant of performance degradation. The column information could be stored in a data structure on the side that could be generated on demand and could be correlated back to the AST. For example, when doing Java Static Analysis, we run the compiler in debug mode to get debug symbol information.

To build tools like PHPDOC and PHPXREF, this information will probably be needed as well, and the tools will also probably be tolerant of some performance degradation.
 [2015-07-10 00:37 UTC] rasmus@php.net
Performance-wise it doesn't make sense to add this to the regular build, but it might be possible to add when PHP is compiled in debug mode. That means you would need a separate PHP build, of course.
 [2015-07-18 13:09 UTC] nikic@php.net
I don't think there's much value in making this available only in debug builds. I mean, both things are pretty independent, there's no reason why you'd want to run a static analyzer using a slow debug build.

Having this in a separate on-demand structure sounds more useful, though not quite clear yet how it would like look.

In any case the first step towards this would be to start using bison location tracking instead of our current lineno tracking. Documentation for access in semantic actions is in http://www.gnu.org/software/bison/manual/html_node/Tracking-Locations.html#Tracking-Locations and the reentrant yylex API is documented in http://www.gnu.org/software/bison/manual/html_node/Pure-Calling.html#Pure-Calling.
 [2019-03-15 15:42 UTC] nikic@php.net
Finally got around to implementing the bison location tracking in https://github.com/php/php-src/pull/3948.

This would allow us to implement this FR from a technical perspective. As before, I'm not sure we actually want to do so though.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Oct 09 01:01:28 2024 UTC