branch: externals/phps-mode commit 1a1245f18695b571ad5b44cb740932e9a8abdcdf Author: Christian Johansson <christ...@cvj.se> Commit: Christian Johansson <christ...@cvj.se>
Passing bookkeeping test isset and empty variables --- phps-mode-parser-sdt.el | 60 ++++++++++++++++++++++++++++++++++------------ test/phps-mode-test-ast.el | 2 +- 2 files changed, 46 insertions(+), 16 deletions(-) diff --git a/phps-mode-parser-sdt.el b/phps-mode-parser-sdt.el index 8537608f76..bf35794061 100644 --- a/phps-mode-parser-sdt.el +++ b/phps-mode-parser-sdt.el @@ -768,14 +768,6 @@ ;; (message "potential-uris: %S" potential-uris) )) - ;; TODO Below should alter symbol namespaces instead of build namespace data - ((equal space-type 'global) - (setq namespace nil) - (setq class nil) - (setq function nil) - (setq arrow-function nil) - (setq anonymous-function nil)) - ))) (setq scope-index (1+ scope-index))))) @@ -842,7 +834,6 @@ (when phps-mode-parser-sdt--bookkeeping-symbol-stack ;; Bookkeeping hit / misses of symbol references here - ;; TODO Should consider declaration position as well? (dolist ( symbol-list phps-mode-parser-sdt--bookkeeping-symbol-stack) @@ -867,7 +858,15 @@ ((gethash symbol-uri phps-mode-parser-sdt-bookkeeping) - (setq symbol-hit 1))) + (let ((matching-symbols + (gethash + symbol-uri + phps-mode-parser-sdt-bookkeeping))) + (dolist (matching-symbol matching-symbols) + (let ((matching-symbol-start (car matching-symbol)) + (matching-symbol-end (car (cdr matching-symbol)))) + (when (<= matching-symbol-start symbol-start) + (setq symbol-hit 1))))))) (puthash (list @@ -3428,7 +3427,6 @@ (plist-get property 'ast-type))) (cond ((equal property-type 'property-variable) - ;; TODO Bookkeep proerty-variable here (let ((symbol-name (plist-get property 'variable)) (symbol-start @@ -3929,7 +3927,6 @@ (puthash 358 (lambda(args _terminals) - ;; TODO Declare array-pair-list assignments here (let ((array-pair-list (nth 1 args))) (dolist (array-item array-pair-list) (let ((array-item-type (plist-get array-item 'ast-type))) @@ -6715,17 +6712,50 @@ ;; 561 ((internal_functions_in_yacc) (T_ISSET "(" isset_variables possible_comma ")")) (puthash 561 - (lambda(args _terminals) + (lambda(args terminals) + (when phps-mode-parser-sdt--bookkeeping-symbol-stack + (let ((isset-start (car (cdr (nth 1 terminals)))) + (isset-end (cdr (cdr (nth 4 terminals))))) + (dolist (item phps-mode-parser-sdt--bookkeeping-symbol-stack) + (let ((item-start (nth 2 item)) + (item-end (nth 3 item))) + (when (and + (> item-start isset-start) + (< item-end isset-end)) + (push + (list + (nth 0 item) + phps-mode-parser-sdt--bookkeeping-namespace + item-start + item-end) + phps-mode-parser-sdt--bookkeeping-symbol-assignment-stack)))))) `( ast-type internal-isset + isset-variables ,(nth 2 args))) phps-mode-parser--table-translations) ;; 562 ((internal_functions_in_yacc) (T_EMPTY "(" expr ")")) (puthash 562 - (lambda(args _terminals) + (lambda(args terminals) + (when phps-mode-parser-sdt--bookkeeping-symbol-stack + (let ((empty-start (car (cdr (nth 1 terminals)))) + (empty-end (cdr (cdr (nth 3 terminals))))) + (dolist (item phps-mode-parser-sdt--bookkeeping-symbol-stack) + (let ((item-start (nth 2 item)) + (item-end (nth 3 item))) + (when (and + (> item-start empty-start) + (< item-end empty-end)) + (push + (list + (nth 0 item) + phps-mode-parser-sdt--bookkeeping-namespace + item-start + item-end) + phps-mode-parser-sdt--bookkeeping-symbol-assignment-stack)))))) `( ast-type internal-empty-expr @@ -6806,7 +6836,7 @@ (puthash 570 (lambda(args _terminals) - (list args)) + args) phps-mode-parser--table-translations) (provide 'phps-mode-parser-sdt) diff --git a/test/phps-mode-test-ast.el b/test/phps-mode-test-ast.el index 51c7758fd9..4930dacd01 100644 --- a/test/phps-mode-test-ast.el +++ b/test/phps-mode-test-ast.el @@ -296,7 +296,7 @@ (phps-mode-test-ast--should-bookkeep "<?php\n\nif (isset($x)) {\n if ($x) {\n echo 'Hit';\n if (isset($i, $u)) {\n if ($i) {\n echo 'Hit';\n }\n if ($u) {\n echo 'Hit';\n }\n if ($x) {\n echo 'Hit';\n }\n }\n if ($i) {\n echo 'Miss';\n }\n if ($u) {\n echo 'Miss';\n }\n }\n}\nif ($x) {\n echo 'Miss';\n}\n\nif (!empty($y)) {\n if ( [...] "Bookkeeping of isset() and !empty() scoped variables" - '((" defined 1 id $x" 1) ((18 20) 1) ((33 35) 1) (" defined 1 defined 2 id $i" 1) (" defined 1 defined 2 id $u" 1) ((77 79) 1) ((81 83) 1) ((104 106) 1) ((168 170) 1) ((232 234) 1) ((302 304) 0) ((355 357) 0) ((408 410) 0) (" defined 3 id $y" 1) ((445 447) 1) ((460 462) 1) (" defined 3 defined 4 id $k" 1) (" defined 3 defined 4 id $L" 1) ((505 507) 1) ((519 521) 1) ((542 544) 1) ((606 608) 1) ((670 672) 1) ((740 742) 0) ((793 795) 0) ((846 848) 0))) + '((" id $i" ((77 79))) (" id $u" ((81 83))) (" id $x" ((18 20))) ((355 357) 1) ((302 304) 1) ((232 234) 1) ((168 170) 1) ((104 106) 1) ((81 83) 1) ((77 79) 1) ((33 35) 1) ((18 20) 1) ((408 410) 1) (" id $L" ((519 521))) (" id $k" ((505 507))) (" id $y" ((445 447))) ((793 795) 1) ((740 742) 1) ((670 672) 1) ((606 608) 1) ((542 544) 1) ((519 521) 1) ((505 507) 1) ((460 462) 1) ((445 447) 1) ((846 848) 1))) (phps-mode-test-ast--should-bookkeep "<?php\ninterface myInterface\n{\n function myFunction1();\n function myFunction2($x);\n}\n"