branch: externals/phps-mode commit e8b8c8db647d421edb323b2b0ebd1009cfd20ba7 Author: christian <christ...@cvj.se> Commit: christian <christ...@cvj.se>
Added bookkeeping of variable assignment via reference --- phps-mode-parser-sdt.el | 39 +++++++++++++++++++++++++++++++++++++++ test/phps-mode-test-ast.el | 7 ++++++- 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/phps-mode-parser-sdt.el b/phps-mode-parser-sdt.el index f2407329d8..f5e98e0ed8 100644 --- a/phps-mode-parser-sdt.el +++ b/phps-mode-parser-sdt.el @@ -5279,6 +5279,45 @@ (puthash 360 (lambda(args terminals) + ;; Save variable declaration in bookkeeping buffer + (let ((variable-type (plist-get (nth 0 args) 'ast-type))) + (cond + ((equal variable-type 'variable-callable-variable) + (let* ((callable-variable (plist-get (nth 0 args) 'callable-variable)) + (callable-variable-type (plist-get callable-variable 'ast-type))) + (cond + ((equal callable-variable-type 'callable-variable-simple-variable) + (let ((callable-variable-simple-variable (plist-get callable-variable 'simple-variable))) + (let ((callable-variable-simple-variable-type + (plist-get + callable-variable-simple-variable + 'ast-type))) + (cond + ((equal + callable-variable-simple-variable-type + 'simple-variable-variable) + (let* ((variable-name + (plist-get + callable-variable-simple-variable + 'variable)) + (symbol-name + variable-name) + (symbol-start + (car (cdr (car terminals)))) + (symbol-end + (cdr (cdr (car terminals)))) + (symbol-scope + phps-mode-parser-sdt--bookkeeping-namespace)) + + ;; (message "declared variable from terminals: %S" terminals) + (push + (list + symbol-name + symbol-scope + symbol-start + symbol-end) + phps-mode-parser-sdt--bookkeeping-symbol-assignment-stack)))))))))))) + `( ast-type expr-assign-variable-by-reference diff --git a/test/phps-mode-test-ast.el b/test/phps-mode-test-ast.el index 951d58ae20..d18141ff30 100644 --- a/test/phps-mode-test-ast.el +++ b/test/phps-mode-test-ast.el @@ -131,7 +131,6 @@ "Run test for bookkeeping generation." (message "-- Running tests for bookkeeping generation... --\n") - ;; TODO fix Should bookkeep assignment via reference $var = & $test ;; TODO v2 Should have more delicate handling of isset, !empty condition blocks ;; TODO v2 bookkeep and include constants in imenu ;; TODO v2 imenu should contain redeclaration of variables @@ -148,6 +147,12 @@ '(((8 12) 1) ((27 31) 1) ((72 77) 0)) '(("$var" . 8))) + (phps-mode-test-ast--should-bookkeep + "<?php\n\n$abc = 123;\n\n$var = & $abc;\nif ($var) {\n echo 'Hit';\n}" + "Bookkeeping in root level variable assignments #3" + '(((8 12) 1) ((21 25) 2) ((30 34) 1) ((40 44) 2)) + '(("$abc" . 8) ("$var" . 21))) + (phps-mode-test-ast--should-bookkeep "<?php\n\n$var2 = 4;\n\nfunction myFunction($var)\n{\n $var3 = 3;\n if ($var) {\n echo 'Hit';\n }\n if ($var2) {\n echo 'Miss';\n }\n if ($var3) {\n echo 'Hit';\n }\n}\n\nfunction myFunction2($abc)\n{\n if ($var) {\n echo 'Miss';\n }\n if ($abc) {\n echo 'Hit';\n }\n}\n\nif ($var) {\n echo 'Miss';\n}\nif ($var2) {\n echo 'Hit';\n}" "Bookkeeping in function level with variable assignments"