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

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

[elpa] externals/phps-mode 08329be 30/62: Fixed support for bookkeeping


From: Christian Johansson
Subject: [elpa] externals/phps-mode 08329be 30/62: Fixed support for bookkeeping of superglobals $GLOBALS and $_ENV
Date: Tue, 20 Apr 2021 10:56:18 -0400 (EDT)

branch: externals/phps-mode
commit 08329be054da446507f9504daf38c427fe9a778c
Author: Christian Johansson <christian@mediastrategi.se>
Commit: Christian Johansson <christian@mediastrategi.se>

    Fixed support for bookkeeping of superglobals $GLOBALS and $_ENV
---
 phps-mode-lex-analyzer.el           | 57 +++++++++++++++++++++++++++----------
 test/phps-mode-test-lex-analyzer.el |  9 +++---
 2 files changed, 47 insertions(+), 19 deletions(-)

diff --git a/phps-mode-lex-analyzer.el b/phps-mode-lex-analyzer.el
index 99b8574..13867bb 100644
--- a/phps-mode-lex-analyzer.el
+++ b/phps-mode-lex-analyzer.el
@@ -1222,22 +1222,32 @@ SQUARE-BRACKET-LEVEL and ROUND-BRACKET-LEVEL."
                       ;; Flag super-globals
                       (when (and (equal token 'T_VARIABLE)
                                  (or
+                                  (equal bookkeeping-variable-name "$GLOBALS")
                                   (equal bookkeeping-variable-name "$_COOKIE")
+                                  (equal bookkeeping-variable-name "$_ENV")
+                                  (equal bookkeeping-variable-name "$_FILES")
                                   (equal bookkeeping-variable-name "$_GET")
-                                  (equal bookkeeping-variable-name "$_GLOBALS")
                                   (equal bookkeeping-variable-name "$_POST")
                                   (equal bookkeeping-variable-name "$_REQUEST")
                                   (equal bookkeeping-variable-name "$_SERVER")
                                   (equal bookkeeping-variable-name "$_SESSION")
-                                  (equal bookkeeping-variable-name "$_FILES")))
+                                  ))
                         (setq bookkeeping-is-superglobal t))
 
                       ;; Build name-space
                       (when (and imenu-in-namespace-name
                                  (or imenu-in-class-name 
imenu-in-function-name))
-                        (setq bookkeeping-namespace (concat 
bookkeeping-namespace " namespace " imenu-in-namespace-name)))
+                        (setq bookkeeping-namespace
+                              (concat
+                               bookkeeping-namespace
+                               " namespace "
+                               imenu-in-namespace-name)))
                       (when imenu-in-class-name
-                        (setq bookkeeping-namespace (concat 
bookkeeping-namespace " class " imenu-in-class-name)))
+                        (setq bookkeeping-namespace
+                              (concat
+                               bookkeeping-namespace
+                               " class "
+                               imenu-in-class-name)))
 
                       (when (and
                              (equal token 'T_VARIABLE)
@@ -1266,14 +1276,21 @@ SQUARE-BRACKET-LEVEL and ROUND-BRACKET-LEVEL."
 
                       (unless bookkeeping-named
                         (when imenu-in-function-name
-                          (setq bookkeeping-namespace (concat 
bookkeeping-namespace " function " imenu-in-function-name))
+                          (setq bookkeeping-namespace
+                                (concat
+                                 bookkeeping-namespace
+                                 " function "
+                                 imenu-in-function-name))
 
                           ;; Add $this special variable in class function scope
                           (when (and imenu-in-class-name
                                      (not imenu-in-interface-class))
                             (let ((bookkeeping-method-this (concat 
bookkeeping-namespace " id $this")))
                               (unless (gethash bookkeeping-method-this 
bookkeeping)
-                                (puthash bookkeeping-method-this 1 
bookkeeping)))))
+                                (puthash
+                                 bookkeeping-method-this
+                                 1
+                                 bookkeeping)))))
 
                         ;; Anonymous function level
                         (when in-anonymous-function-nesting-level
@@ -1305,7 +1322,10 @@ SQUARE-BRACKET-LEVEL and ROUND-BRACKET-LEVEL."
                         (when bookkeeping-alternative-namespace
                           (setq bookkeeping-alternative-namespace (concat 
bookkeeping-alternative-namespace " id " bookkeeping-variable-name))))
 
-                      (phps-mode-debug-message (message 
"Bookkeeping-namespace: '%s'" bookkeeping-namespace))
+                      (phps-mode-debug-message
+                       (message
+                        "Bookkeeping-namespace: '%s'"
+                        bookkeeping-namespace))
 
                       ;; Support for ($i = 0), if ($a = ), if (!$ = ), while 
($a = ) and do {} while ($a = ) assignments here
                       (when (and
@@ -1411,13 +1431,18 @@ SQUARE-BRACKET-LEVEL and ROUND-BRACKET-LEVEL."
 
                       ;; Do we have a assignment?
                       (when bookkeeping-in-assignment
-                        (let ((declarations (gethash bookkeeping-namespace 
bookkeeping)))
+                        (let ((declarations
+                               (gethash
+                                bookkeeping-namespace
+                                bookkeeping)))
                           ;; Track number of times this variable is defined
                           (unless declarations
                             (setq declarations 0))
                           (setq declarations (1+ declarations))
                           (phps-mode-debug-message
-                           (message "Bookkeeping-assignment: '%s'" 
bookkeeping-namespace))
+                           (message
+                            "Bookkeeping-assignment: '%s'"
+                            bookkeeping-namespace))
                           (puthash bookkeeping-namespace declarations 
bookkeeping)))
 
                       (if bookkeeping-is-superglobal
@@ -1643,10 +1668,11 @@ SQUARE-BRACKET-LEVEL and ROUND-BRACKET-LEVEL."
 
                  ((string= token "}")
 
-                  (when (and imenu-open-namespace-level
-                             (= imenu-open-namespace-level imenu-nesting-level)
-                             imenu-in-namespace-name
-                             imenu-namespace-index)
+                  (when (and
+                         imenu-open-namespace-level
+                         (= imenu-open-namespace-level imenu-nesting-level)
+                         imenu-in-namespace-name
+                         imenu-namespace-index)
                     (let ((imenu-add-list (nreverse imenu-namespace-index)))
                       (push `(,imenu-in-namespace-name . ,imenu-add-list) 
imenu-index))
                     (setq imenu-in-namespace-name nil))
@@ -1680,8 +1706,9 @@ SQUARE-BRACKET-LEVEL and ROUND-BRACKET-LEVEL."
                     (setq imenu-namespace-index '())
                     (setq imenu-in-namespace-declaration nil))
 
-                   ((and (or (equal token 'T_STRING)
-                             (equal token 'T_NS_SEPARATOR))
+                   ((and (or (equal token 'T_NAME_RELATIVE)
+                             (equal token 'T_NAME_FULLY_QUALIFIED)
+                             (equal token 'T_NAME_QUALIFIED))
                          (setq
                           imenu-in-namespace-name
                           (concat
diff --git a/test/phps-mode-test-lex-analyzer.el 
b/test/phps-mode-test-lex-analyzer.el
index b6f6781..677ba4f 100644
--- a/test/phps-mode-test-lex-analyzer.el
+++ b/test/phps-mode-test-lex-analyzer.el
@@ -1404,11 +1404,12 @@
             (list (list " id $var2" 1) (list (list 8 13) 1) (list " function 
myFunction id $var" 1) (list (list 40 44) 1) (list " function myFunction id 
$var3" 1) (list (list 52 57) 1) (list (list 70 74) 1) (list (list 112 117) 0) 
(list (list 156 161) 1) (list " function myFunction2 id $abc" 1) (list (list 
215 219) 1) (list (list 231 235) 0) (list (list 274 278) 1) (list (list 315 
319) 0) (list (list 346 351) 1)))))
 
   (phps-mode-test--with-buffer
-   "<?php\n\n// Super-globals\n\nif ($_GET) {\n    echo 'Hit';\n}\nif ($_POST) 
{\n    echo 'Hit';\n}\nif ($_COOKIE) {\n    echo 'Hit';\n}\nif ($_SESSION) {\n  
  echo 'Hit';\n}\nif ($_REQUEST) {\n    echo 'Hit';\n}\nif ($_GLOBALS) {\n    
echo 'Hit';\n}\nif ($_SERVER) {\n    echo 'Hit';\n}\nif ($_FILES) {\n    echo 
'Hit';\n}\n"
+   "<?php\n\n// Super-globals\n\nif ($_GET) {\n    echo 'Hit';\n}\nif ($_POST) 
{\n    echo 'Hit';\n}\nif ($_COOKIE) {\n    echo 'Hit';\n}\nif ($_SESSION) {\n  
  echo 'Hit';\n}\nif ($_REQUEST) {\n    echo 'Hit';\n}\nif ($GLOBALS) {\n    
echo 'Hit';\n}\nif ($_SERVER) {\n    echo 'Hit';\n}\nif ($_FILES) {\n    echo 
'Hit';\n}\nif ($_ENV) {\n    echo 'Hit';\n}"
    "Bookkeeping of super-globals"
-   (should (equal
-            (phps-mode-test--hash-to-list 
(phps-mode-lex-analyzer--get-bookkeeping) t)
-            (list (list (list 30 35) 1) (list (list 61 67) 1) (list (list 93 
101) 1) (list (list 127 136) 1) (list (list 162 171) 1) (list (list 197 206) 1) 
(list (list 232 240) 1) (list (list 266 273) 1)))))
+   (should
+    (equal
+     (phps-mode-test--hash-to-list (phps-mode-lex-analyzer--get-bookkeeping) t)
+     (list (list (list 30 35) 1) (list (list 61 67) 1) (list (list 93 101) 1) 
(list (list 127 136) 1) (list (list 162 171) 1) (list (list 197 205) 1) (list 
(list 231 239) 1) (list (list 265 272) 1) (list (list 298 303) 1)))))
 
   (phps-mode-test--with-buffer
    "<?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 [...]



reply via email to

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