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

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

[elpa] externals/phps-mode 438ec520fc 051/135: Passing bookkeeping via S


From: Christian Johansson
Subject: [elpa] externals/phps-mode 438ec520fc 051/135: Passing bookkeeping via SDT for conditional assignments
Date: Sun, 29 Jan 2023 03:11:03 -0500 (EST)

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

    Passing bookkeeping via SDT for conditional assignments
---
 phps-mode-parser-sdt.el    | 82 ++++++++++++++++++++++++++++++++++++----------
 test/phps-mode-test-ast.el |  2 +-
 2 files changed, 65 insertions(+), 19 deletions(-)

diff --git a/phps-mode-parser-sdt.el b/phps-mode-parser-sdt.el
index 33877f6bdb..5b3fbfd2bd 100644
--- a/phps-mode-parser-sdt.el
+++ b/phps-mode-parser-sdt.el
@@ -617,7 +617,8 @@
         (class)
         (interface)
         (trait)
-        (function))
+        (function)
+        (is-static-p))
     (when scope
       (dolist (item scope)
         (let ((space-type (car item))
@@ -632,7 +633,9 @@
            ((equal space-type 'trait)
             (setq trait space-name))
            ((equal space-type 'function)
-            (setq function space-name))))))
+            (setq function space-name))
+           ((equal space-type 'static)
+            (setq is-static-p t))))))
     (if (gethash
          name
          phps-mode-parser-sdt--bookkeeping--superglobal-variable-p)
@@ -641,6 +644,12 @@
              (format
               " id %s"
               name)))
+        (when is-static-p
+          (setq
+           new-symbol-name
+           (format
+            " static%s"
+            new-symbol-name)))
         (when function
           (setq
            new-symbol-name
@@ -1919,13 +1928,13 @@
                symbol-end)
               phps-mode-parser-sdt--bookkeeping-symbol-assignment-stack)))))))
 
-   (message "before:")
-   (message
-    "phps-mode-parser-sdt--bookkeeping-symbol-assignment-stack: %S"
-    phps-mode-parser-sdt--bookkeeping-symbol-assignment-stack)
-   (message
-    "phps-mode-parser-sdt--bookkeeping-symbol-stack: %S"
-    phps-mode-parser-sdt--bookkeeping-symbol-stack)
+   ;; (message "before:")
+   ;; (message
+   ;;  "phps-mode-parser-sdt--bookkeeping-symbol-assignment-stack: %S"
+   ;;  phps-mode-parser-sdt--bookkeeping-symbol-assignment-stack)
+   ;; (message
+   ;;  "phps-mode-parser-sdt--bookkeeping-symbol-stack: %S"
+   ;;  phps-mode-parser-sdt--bookkeeping-symbol-stack)
 
    ;; Go through stacks and modify symbol namespaces
    ;; - add function scope but only for non-super-global variables
@@ -1962,13 +1971,13 @@
                 symbol-scope)))))))
 
 
-   (message "after:")
-   (message
-    "phps-mode-parser-sdt--bookkeeping-symbol-assignment-stack: %S"
-    phps-mode-parser-sdt--bookkeeping-symbol-assignment-stack)
-   (message
-    "phps-mode-parser-sdt--bookkeeping-symbol-stack: %S"
-    phps-mode-parser-sdt--bookkeeping-symbol-stack)
+   ;; (message "after:")
+   ;; (message
+   ;;  "phps-mode-parser-sdt--bookkeeping-symbol-assignment-stack: %S"
+   ;;  phps-mode-parser-sdt--bookkeeping-symbol-assignment-stack)
+   ;; (message
+   ;;  "phps-mode-parser-sdt--bookkeeping-symbol-stack: %S"
+   ;;  phps-mode-parser-sdt--bookkeeping-symbol-stack)
 
 
    `(
@@ -2251,8 +2260,45 @@
 ;; 204 ((foreach_variable) (variable))
 (puthash
  204
- (lambda(args _terminals)
-   ;; TODO Declare variable here
+ (lambda(args terminals)
+   ;; Save variable declaration in bookkeeping buffer
+   (let ((variable-type (plist-get args 'ast-type)))
+     (cond
+      ((equal variable-type 'variable-callable-variable)
+       (let* ((callable-variable (plist-get 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 terminals)))
+                        (symbol-end
+                         (cdr (cdr terminals)))
+                        (symbol-scope
+                         phps-mode-parser-sdt--bookkeeping-namespace))
+                   ;; (message "declared foreach 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
diff --git a/test/phps-mode-test-ast.el b/test/phps-mode-test-ast.el
index 802b43289c..1569d34f48 100644
--- a/test/phps-mode-test-ast.el
+++ b/test/phps-mode-test-ast.el
@@ -241,7 +241,7 @@
   (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 ( [...]
    "Bookkeeping of conditional assignments"
-   '((" id $items" 1) ((36 42) 1) ((70 76) 1) (" id $item" 1) ((80 85) 1) ((97 
102) 1) ((143 149) 1) (" id $key" 1) ((153 157) 1) (" id $value" 1) ((161 167) 
1) ((179 183) 1) ((187 193) 1) (" id $i" 1) ((230 232) 1) ((238 240) 1) ((249 
255) 1) ((258 260) 1) ((274 276) 1) (" id $a" 1) ((312 314) 1) ((332 334) 1) (" 
id $b" 1) ((373 375) 1) ((393 395) 1) (" id $c" 1) ((457 459) 1)))
+   '((" id $items" ((36 42))) ((36 42) 1) (" id $item" ((80 85))) ((97 102) 1) 
((80 85) 1) ((70 76) 1) (" id $value" ((161 167))) (" id $key" ((153 157))) 
((187 193) 1) ((179 183) 1) ((161 167) 1) ((153 157) 1) ((143 149) 1) (" id $i" 
((230 232))) ((274 276) 1) ((258 260) 1) ((249 255) 1) ((238 240) 1) ((230 232) 
1) (" id $a" ((312 314))) ((332 334) 1) ((312 314) 1) (" id $b" ((373 375))) 
((393 395) 1) ((373 375) 1) (" id $c" ((457 459))) ((457 459) 1)))
 
   (phps-mode-test-ast--should-bookkeep
    "<?php\n\n// Class properties\n\nclass myParent {}\n\nclass myClass extends 
myParent {\n    private $var1 = 123;\n    protected static $var2;\n    public 
$var3;\n    var $var4;\n    function __construct() {\n        if ($this) {\n    
        echo 'Hit';\n        }\n        if ($this->var1) {\n            echo 
'Hit';\n        }\n        if (self::$var1) {\n            echo 'Miss';\n       
 }\n        if (self::$var2) {\n            echo 'Hit';\n        }\n        if 
($this->var3) {\n   [...]



reply via email to

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