branch: externals/phps-mode commit 8a3492da41877a1d2d5b3467ef2ce146192145d4 Author: Christian Johansson <christ...@cvj.se> Commit: Christian Johansson <christ...@cvj.se>
Improved bookkeeping of referenced variable --- phps-mode-parser-sdt.el | 42 +++++++++++------------------------------- test/phps-mode-test-ast.el | 16 +++++++++++----- 2 files changed, 22 insertions(+), 36 deletions(-) diff --git a/phps-mode-parser-sdt.el b/phps-mode-parser-sdt.el index 7d0bfe8c7c..4f9804b375 100644 --- a/phps-mode-parser-sdt.el +++ b/phps-mode-parser-sdt.el @@ -5393,59 +5393,35 @@ 360 (lambda(args terminals) ;; Save variable declaration in bookkeeping buffer - (let ((variable-type1 (plist-get (nth 0 args) 'ast-type)) - (variable-type2 (plist-get (nth 3 args) 'ast-type))) + (let ((variable-type1 (plist-get (nth 0 args) 'ast-type))) (cond - ((and - (equal variable-type1 'variable-callable-variable) - (equal variable-type2 'variable-callable-variable)) + ((equal variable-type1 'variable-callable-variable) (let* ((callable-variable1 (plist-get (nth 0 args) 'callable-variable)) - (callable-variable-type1 (plist-get callable-variable1 'ast-type)) - (callable-variable2 (plist-get (nth 3 args) 'callable-variable)) - (callable-variable-type2 (plist-get callable-variable2 'ast-type))) + (callable-variable-type1 (plist-get callable-variable1 'ast-type))) (cond - ((and - (equal callable-variable-type1 'callable-variable-simple-variable) - (equal callable-variable-type2 'callable-variable-simple-variable)) + ((equal callable-variable-type1 'callable-variable-simple-variable) (let* ((callable-variable-simple-variable1 (plist-get callable-variable1 'simple-variable)) (callable-variable-simple-variable-type1 (plist-get callable-variable-simple-variable1 - 'ast-type)) - (callable-variable-simple-variable2 - (plist-get callable-variable2 'simple-variable)) - (callable-variable-simple-variable-type2 - (plist-get - callable-variable-simple-variable2 'ast-type))) (cond - ((and - (equal - callable-variable-simple-variable-type1 - 'simple-variable-variable) - (equal - callable-variable-simple-variable-type2 - 'simple-variable-variable)) + ((equal + callable-variable-simple-variable-type1 + 'simple-variable-variable) (let* ((variable-name1 (plist-get callable-variable-simple-variable1 'variable)) - (variable-name2 - (plist-get - callable-variable-simple-variable2 - 'variable)) (symbol-name1 variable-name1) - (symbol-name2 - variable-name2) (symbol-start (car (cdr (car terminals)))) (symbol-end (cdr (cdr (car terminals)))) (symbol-scope phps-mode-parser-sdt--bookkeeping-namespace)) - (push `(reference ,symbol-name2) symbol-scope) (push (list symbol-name1 @@ -7204,6 +7180,7 @@ (cond ((equal constant-name-type 'string-name) + ;; BLAHA ;; TODO When reading this symbol should check global namespace ;; and namespace constants for hit (let ((symbol-scope phps-mode-parser-sdt--bookkeeping-namespace)) @@ -7217,10 +7194,12 @@ phps-mode-parser-sdt--bookkeeping-symbol-stack))) ((equal constant-name-type 'qualified-name) + ;; BLAHA\BLAHA ;; TODO Handle this ) ((equal constant-name-type 'fully-qualified-name) + ;; \BLAHA (let* ((constant-namespace) (string-pos 0) (namespace-pos @@ -7252,6 +7231,7 @@ phps-mode-parser-sdt--bookkeeping-symbol-stack))) ((equal constant-name-type 'relative-name) + ;; namespace\A inside namespace X\Y resolves to X\Y\A. ;; TODO Handle this ) diff --git a/test/phps-mode-test-ast.el b/test/phps-mode-test-ast.el index 2362f06d2c..5e96cf133b 100644 --- a/test/phps-mode-test-ast.el +++ b/test/phps-mode-test-ast.el @@ -134,11 +134,11 @@ ;; TODO v2 Should properly bookkeep inside potentially endlessly nested anonymous functions / arrow functions / anonymous classes ;; TODO v2 bookkeep and include all kind of constants in imenu - (phps-mode-test-ast--should-bookkeep - "<?php\n\nnamespace mySpace\n{\n define('MY_CONSTANT', 'abc123');\n const MY_CONSTANT2 = 'def456';\n\n if (\\MY_CONSTANT) {\n echo 'hit';\n }\n if (MY_CONSTANT) {\n echo 'hit';\n }\n if (MY_CONSTANT2) {\n echo 'hit';\n }\n if (\\mySpace\\MY_CONSTANT2) {\n echo 'hit';\n }\n\n if (\\YOUR_CONSTANT) {\n echo 'miss';\n }\n if (YOUR_CONSTANT) {\n echo 'miss';\n }\n if (\\MY_CONSTANT2) {\n echo 'mis [...] - "Constants in all possible scopes" - '(((159 170) 1) ((208 220) 1) ((371 384) 0) ((848 862) 5) ((900 911) 1) ((1000 1011) 1)) - '(("abc"))) + ;; (phps-mode-test-ast--should-bookkeep + ;; "<?php\n\nnamespace mySpace\n{\n define('MY_CONSTANT', 'abc123');\n const MY_CONSTANT2 = 'def456';\n\n if (\\MY_CONSTANT) {\n echo 'hit';\n }\n if (MY_CONSTANT) {\n echo 'hit';\n }\n if (MY_CONSTANT2) {\n echo 'hit';\n }\n if (\\mySpace\\MY_CONSTANT2) {\n echo 'hit';\n }\n\n if (\\YOUR_CONSTANT) {\n echo 'miss';\n }\n if (YOUR_CONSTANT) {\n echo 'miss';\n }\n if (\\MY_CONSTANT2) {\n echo ' [...] + ;; "Constants in all possible scopes" + ;; '(((159 170) 1) ((208 220) 1) ((371 384) 0) ((848 862) 5) ((900 911) 1) ((1000 1011) 1)) + ;; '(("abc"))) (phps-mode-test-ast--should-bookkeep "<?php\n\n$var = 'abc';\n\nif ($var2) {\n echo 'This never happens';\n}\nif ($var) {\n echo 'This happens';\n}" @@ -158,6 +158,12 @@ '(((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$var = ['abc' => 123];\n\n$ref = &$var['abc'];" + "Bookkeeping in root level variable assignments #4" + '(((8 12) 1) ((32 36) 2) ((40 44) 1)) + '(("$var" . 8) ("$ref" . 32))) + (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"