emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/phps-mode 1332919417 049/135: Passing another bookkeepi


From: Christian Johansson
Subject: [elpa] externals/phps-mode 1332919417 049/135: Passing another bookkeeping test via SDT
Date: Sun, 29 Jan 2023 03:11:03 -0500 (EST)

branch: externals/phps-mode
commit 13329194179c3947e8386ebe6b8c55641ff30ad2
Author: Christian Johansson <christian@cvj.se>
Commit: Christian Johansson <christian@cvj.se>

    Passing another bookkeeping test via SDT
---
 phps-mode-parser-sdt.el    | 51 ++++++++++++++++++++++++++++++++++++++++++++--
 test/phps-mode-test-ast.el |  4 ++--
 2 files changed, 51 insertions(+), 4 deletions(-)

diff --git a/phps-mode-parser-sdt.el b/phps-mode-parser-sdt.el
index 5720b3b4d9..585cb6857a 100644
--- a/phps-mode-parser-sdt.el
+++ b/phps-mode-parser-sdt.el
@@ -2961,6 +2961,54 @@
 (puthash
  300
  (lambda(args terminals)
+   ;; Go through stacks and modify symbol namespaces
+   ;; - add function scope but only for non-super-global variables
+   (let ((function-name (nth 3 args))
+         (is-static-p))
+     (when-let (method-modifiers (nth 0 args))
+       (dolist (method-modifier method-modifiers)
+         (when (equal method-modifier 'static)
+           (setq is-static-p t))))
+     (unless is-static-p
+       (push
+        (list
+         "$this"
+         phps-mode-parser-sdt--bookkeeping-namespace
+         (car (cdr (car (nth 10 terminals))))
+         (cdr (cdr (car (cdr (cdr (nth 10 terminals)))))))
+        phps-mode-parser-sdt--bookkeeping-symbol-assignment-stack))
+     (when phps-mode-parser-sdt--bookkeeping-symbol-assignment-stack
+       (dolist (
+                symbol-list
+                phps-mode-parser-sdt--bookkeeping-symbol-assignment-stack)
+         (let ((symbol-name (car symbol-list)))
+           (unless (gethash
+                    symbol-name
+                    phps-mode-parser-sdt--bookkeeping--superglobal-variable-p)
+             (let ((symbol-scope (car (cdr symbol-list))))
+               (push
+                (list 'function function-name)
+                symbol-scope)
+               (setcar
+                (cdr symbol-list)
+                symbol-scope))))))
+
+     (when phps-mode-parser-sdt--bookkeeping-symbol-stack
+       (dolist (
+                symbol-list
+                phps-mode-parser-sdt--bookkeeping-symbol-stack)
+         (let ((symbol-name (car symbol-list)))
+           (unless (gethash
+                    symbol-name
+                    phps-mode-parser-sdt--bookkeeping--superglobal-variable-p)
+             (let ((symbol-scope (car (cdr symbol-list))))
+               (push
+                (list 'function function-name)
+                symbol-scope)
+               (setcar
+                (cdr symbol-list)
+                symbol-scope)))))))
+
    `(
      ast-type
      method
@@ -2987,8 +3035,7 @@
      ast-end
      ,(if (nth 10 args)
           (cdr (cdr (car (cdr (cdr (nth 10 terminals))))))
-        nil)
-     ))
+        nil)))
  phps-mode-parser--table-translations)
 
 ;; 301 ((attributed_class_statement) (enum_case))
diff --git a/test/phps-mode-test-ast.el b/test/phps-mode-test-ast.el
index 826b20ccbc..802b43289c 100644
--- a/test/phps-mode-test-ast.el
+++ b/test/phps-mode-test-ast.el
@@ -234,9 +234,9 @@
    '(((30 35) 1) ((61 67) 1) ((93 101) 1) ((127 136) 1) ((162 171) 1) ((197 
205) 1) ((231 239) 1) ((265 272) 1) ((298 303) 1) ((329 334) 1) ((360 365) 1) 
((391 414) 1)))
 
   (phps-mode-test-ast--should-bookkeep
-   "<?php\n\nnamespace myNamespaceA {\n    $var = 123;\n    class myClassA {\n 
       private $var2 = 123;\n        function myFunctionA($var3) {\n            
$var4 = 123;\n            if ($var) {\n                echo 'Miss';\n           
 }\n            if ($var2) {\n                echo 'Miss';\n            }\n     
       if ($var3) {\n                echo 'Hit';\n            }\n            if 
($var4) {\n                echo 'Hit';\n            }\n        }\n\n        
function myFuncti [...]
+   "<?php\n\nnamespace myNamespaceA {\n    $var = 123;\n    class myClassA {\n 
       private $var2 = 123;\n        public static function myFunctionA($var3) 
{\n            $var4 = 123;\n            if ($var) {\n                echo 
'Miss';\n            }\n            if ($var2) {\n                echo 
'Miss';\n            }\n            if ($var3) {\n                echo 'Hit';\n 
           }\n            if ($var4) {\n                echo 'Hit';\n           
 }\n        }\n\n        fun [...]
    "Bookkeeping in maximum level with namespaces, classes and functions."
-   '((" id $var" 1) ((37 41) 1) (" namespace myNamespaceA class myClassA id 
$var2" 1) ((86 91) 1) (" namespace myNamespaceA class myClassA function 
myFunctionA id $this" 1) (" namespace myNamespaceA class myClassA function 
myFunctionA id $var3" 1) ((128 133) 1) (" namespace myNamespaceA class myClassA 
function myFunctionA id $var4" 1) ((149 154) 1) ((178 182) 0) ((245 250) 0) 
((313 318) 1) ((380 385) 1) (" namespace myNamespaceA class myClassA function 
myFunctionB id $this" 1) (" namespa [...]
+   '((" namespace myNamespaceA id $var" ((37 41))) ((37 41) 1) (" namespace 
myNamespaceA class myClassA function myFunctionB id $this" ((500 941))) (" 
namespace myNamespaceA class myClassA function myFunctionB id $var6" ((514 
519))) (" namespace myNamespaceA class myClassA function myFunctionA id $var4" 
((163 168))) (" namespace myNamespaceA class myClassA function myFunctionA id 
$var2" ((86 91))) ((881 886) 1) ((814 819) 0) ((746 751) 0) ((678 683) 0) ((610 
615) 0) ((543 547) 0) ((514 5 [...]
 
   (phps-mode-test-ast--should-bookkeep
    "<?php\n\n// Conditional assignments\n\n$items = array(1, 2, 3);\nforeach 
($items as $item) {\n    if ($item) {\n        echo 'Hit';\n    }\n}\nforeach 
($items as $key => $value) {\n    if ($key || $value) {\n        echo 'Hit';\n  
  }\n}\nfor ($i = 0; $i < count($items); $i++) {\n    if ($i) {\n        echo 
'Hit';\n    }\n}\nif ($a = 123) {\n    if ($a) {\n        echo 'Hit';\n    
}\n}\nwhile ($b = 123) {\n    if ($a) {\n        echo 'Hit';\n    }\n}\ndo {\n  
  echo 'Hit';\n} while ( [...]



reply via email to

[Prev in Thread] Current Thread [Next in Thread]