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

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

[elpa] externals/phps-mode 3109574727 1/4: Bookkeeping ignoring static p


From: Christian Johansson
Subject: [elpa] externals/phps-mode 3109574727 1/4: Bookkeeping ignoring static properties of other objects than self and static
Date: Mon, 30 Jan 2023 15:33:12 -0500 (EST)

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

    Bookkeeping ignoring static properties of other objects than self and static
---
 phps-mode-parser-sdt.el    | 18 +++++++++++++-----
 test/phps-mode-test-ast.el | 33 ++++++++++++++++++++-------------
 2 files changed, 33 insertions(+), 18 deletions(-)

diff --git a/phps-mode-parser-sdt.el b/phps-mode-parser-sdt.el
index f5e98e0ed8..43e24dc5b0 100644
--- a/phps-mode-parser-sdt.el
+++ b/phps-mode-parser-sdt.el
@@ -1601,11 +1601,19 @@
              (symbol-uri (car symbol-uri-object))
              (symbol-object-operator
               (nth 13 (nth 1 symbol-uri-object)))
+             (symbol-static-member
+              (nth 15 (nth 1 symbol-uri-object)))
              (symbol-hit 0))
 
-        (unless (and
-                 symbol-object-operator
-                 (not (string= (downcase symbol-object-operator) "$this")))
+        (unless (or
+                 (and
+                  symbol-object-operator
+                  (not (string= (downcase symbol-object-operator) "$this")))
+                 (and
+                  symbol-static-member
+                  (not
+                   (or (string= (downcase symbol-static-member) "self")
+                       (string= (downcase symbol-static-member) "static")))))
           (cond
 
            ;; Super-global variable
@@ -4548,11 +4556,11 @@
           ((and function-start function-end)
            (if phps-mode-parser-sdt-symbol-imenu--stack
                (push
-                (list (list 'function function-name function-start 
function-end))
+                (list (list 'function function-name function-index 
function-end))
                 phps-mode-parser-sdt-symbol-imenu--stack)
              (setq
               phps-mode-parser-sdt-symbol-imenu--stack
-              (list (list (list 'function function-name function-start 
function-end))))))
+              (list (list (list 'function function-name function-index 
function-end))))))
           (function-index
            (if phps-mode-parser-sdt-symbol-imenu--stack
                (push
diff --git a/test/phps-mode-test-ast.el b/test/phps-mode-test-ast.el
index d18141ff30..f1507d0cd8 100644
--- a/test/phps-mode-test-ast.el
+++ b/test/phps-mode-test-ast.el
@@ -132,8 +132,9 @@
   (message "-- Running tests for bookkeeping generation... --\n")
 
   ;; TODO v2 Should have more delicate handling of isset, !empty condition 
blocks
+  ;; TODO v2 Should properly bookkeep inside endlessly nested anonymous 
functions / arrow functions / anonymous classes
   ;; TODO v2 bookkeep and include constants in imenu
-  ;; TODO v2 imenu should contain redeclaration of variables
+  ;; TODO v2 imenu should contain declaration of variables, both define and 
namespace const and class, trait and interface const
 
   (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}"
@@ -168,7 +169,7 @@
    "<?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."
    '(((37 41) 1) ((86 91) 2) ((142 147) 4) ((163 168) 3) ((192 196) 0) ((259 
264) 0) ((327 332) 4) ((394 399) 3) ((485 490) 7) ((514 519) 5) ((543 547) 0) 
((610 615) 0) ((678 683) 0) ((746 751) 0) ((814 819) 7) ((881 886) 5) ((957 
961) 1) ((999 1004) 0) ((1043 1048) 0) ((1087 1092) 0) ((1131 1136) 0) ((1175 
1180) 0) ((1243 1248) 8) ((1293 1298) 9) ((1335 1341) 12) ((1357 1362) 10) 
((1386 1390) 0) ((1453 1458) 0) ((1521 1526) 0) ((1589 1594) 0) ((1657 1662) 0) 
((1725 1730) 0) ((1793 1798) [...]
-   '(("namespace myNamespaceA" ("declaration" . 18) ("$var" . 37) ("class 
myClassA" ("declaration" . 59) ("$var2" . 86) ("function myFunctionA" 
("declaration" . 149) ("$var3" . 142) ("$var4" . 163)) ("function myFunctionB" 
("declaration" . 500) ("$var5" . 485) ("$var6" . 514)))) ("namespace 
myNamespaceB" ("declaration" . 1224) ("$var7" . 1243) ("class myClassB" 
("declaration" . 1266) ("$var8" . 1293) ("function myFunctionA" ("declaration" 
. 1343) ("$var10" . 1335) ("$var9" . 1357)) ("fun [...]
+   '(("namespace myNamespaceA" ("declaration" . 18) ("$var" . 37) ("class 
myClassA" ("declaration" . 59) ("$var2" . 86) ("function myFunctionA" 
("declaration" . 130) ("$var3" . 142) ("$var4" . 163)) ("function myFunctionB" 
("declaration" . 473) ("$var5" . 485) ("$var6" . 514)))) ("namespace 
myNamespaceB" ("declaration" . 1224) ("$var7" . 1243) ("class myClassB" 
("declaration" . 1266) ("$var8" . 1293) ("function myFunctionA" ("declaration" 
. 1323) ("$var10" . 1335) ("$var9" . 1357)) ("fun [...]
 
   (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 ( [...]
@@ -180,7 +181,7 @@
    "<?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 
(static::$var2) {\n [...]
    "Bookkeeping of class properties"
    '(((93 98) 1) ((127 132) 2) ((145 150) 3) ((160 165) 4) ((208 213) 5) ((263 
268) 5) ((270 274) 1) ((330 335) 0) ((392 397) 2) ((455 460) 2) ((510 515) 5) 
((517 521) 3) ((571 576) 5) ((578 582) 4) ((632 637) 5) ((639 643) 0) ((751 
756) 0))
-   '(("class myParent" ("declaration" . 35)) ("class myClass" ("declaration" . 
54) ("$var1" . 93) ("$var2" . 127) ("$var3" . 145) ("$var4" . 160) ("function 
__construct" ("declaration" . 194)))))
+   '(("class myParent" ("declaration" . 35)) ("class myClass" ("declaration" . 
54) ("$var1" . 93) ("$var2" . 127) ("$var3" . 145) ("$var4" . 160) ("function 
__construct" ("declaration" . 180)))))
 
   (phps-mode-test-ast--should-bookkeep
    "<?php\n\ntry {\n    \n} catch (\\Exception $e) {\n    if ($e) {\n        
echo 'Hit';\n    }\n}\n\nif ($e) {\n    echo 'Miss';\n}\n"
@@ -198,7 +199,7 @@
    "<?php\nfinal class myClass {\n    function random() {}\n    function 
__construct()\n    {\n        $this->random();\n        $this->random['abc'] = 
123;\n    }\n}"
    "Method calls should be avoided in bookkeeping"
    '(((95 100) 2) ((120 125) 2) ((127 133) 0))
-   '(("class myClass" ("declaration" . 19) ("function random" ("declaration" . 
51)) ("function __construct" ("declaration" . 85)))))
+   '(("class myClass" ("declaration" . 19) ("function random" ("declaration" . 
42)) ("function __construct" ("declaration" . 67)))))
 
   (phps-mode-test-ast--should-bookkeep
    "<?php\n$items = array(1, 2, 3);\nforeach ($items as &$item) {\n    if 
($item) {\n        echo 'Hit';\n    }\n}\nforeach ($items as $key => &$item2) 
{\n    if ($item) {\n        echo 'Hit';\n    }\n}"
@@ -294,13 +295,13 @@
    "<?php\n\nstatic $a;\n\nif ($a) {}\n\nfunction test()\n{\n    static $a;\n  
  if ($a) {}\n}\n\nclass There\n{\n    function here()\n    {\n        static 
$a;\n        if ($a) {}\n    }\n}"
    "Bookkeeping of static variables in different scopes without namespaces"
    '(((15 17) 1) ((24 26) 1) ((61 63) 2) ((73 75) 2) ((138 140) 3) ((154 156) 
3))
-   '(("$a" . 15) ("function test" ("declaration" . 41) ("$a" . 61)) ("class 
There" ("declaration" . 89) ("function here" ("declaration" . 121) ("$a" . 
138)))))
+   '(("$a" . 15) ("function test" ("declaration" . 41) ("$a" . 61)) ("class 
There" ("declaration" . 89) ("function here" ("declaration" . 110) ("$a" . 
138)))))
 
   (phps-mode-test-ast--should-bookkeep
    "<?php\nclass There\n{\n    private $variable;\n    private \\My\\Random 
$variable2;\n    private string $variable3;\n    private static $variable4;\n   
 private static \\My\\Random $variable5;\n    private static string 
$variable6;\n    function here()\n    {\n        if ($this->variable) {}\n      
  if ($this->variable2) {}\n        if ($this->variable3) {}\n        if 
($this->variable4) {}\n        if (self::$variable4) {}\n        if 
(self::$variable5) {}\n        if (self::$varia [...]
    "Bookkeeping of typed class variables"
    '(((33 42) 1) ((67 77) 2) ((98 108) 3) ((129 139) 4) ((171 181) 5) ((209 
219) 6) ((259 264) 7) ((266 274) 1) ((291 296) 7) ((298 307) 2) ((324 329) 7) 
((331 340) 3) ((357 362) 7) ((364 373) 0) ((396 406) 4) ((429 439) 5) ((462 
472) 6))
-   '(("class There" ("declaration" . 13) ("$variable" . 33) ("$variable2" . 
67) ("$variable3" . 98) ("$variable4" . 129) ("$variable5" . 171) ("$variable6" 
. 209) ("function here" ("declaration" . 245)))))
+   '(("class There" ("declaration" . 13) ("$variable" . 33) ("$variable2" . 
67) ("$variable3" . 98) ("$variable4" . 129) ("$variable5" . 171) ("$variable6" 
. 209) ("function here" ("declaration" . 234)))))
 
   (phps-mode-test-ast--should-bookkeep
    "<?php\n\n$a = $b = $c = 3;\n\nif ($a) {\n    echo 'a=',$a;\n} else {\n    
echo '$a is undefined!';\n}\nif ($b) {\n    echo 'b=',$b;\n} else {\n    echo 
'$b is undefined!';\n}\nif ($c) {\n    echo 'c=',$c;\n} else {\n    echo '$c is 
undefined!';\n}"
@@ -312,43 +313,43 @@
    "<?php\nclass There\n{\n    private $variable;\n    private ?\\My\\Random 
$variable2;\n    private string $variable3;\n    private static $variable4;\n   
 private static \\My\\Random $variable5;\n    private static ?string 
$variable6;\n    function here()\n    {\n        if ($this->variable) {}\n      
  if ($this->variable2) {}\n        if ($this->variable3) {}\n        if 
($this->variable4) {}\n        if (self::$variable4) {}\n        if 
(self::$variable5) {}\n        if (self::$var [...]
    "Bookkeeping of nullable typed class variables"
    '(((33 42) 1) ((68 78) 2) ((99 109) 3) ((130 140) 4) ((172 182) 5) ((211 
221) 6) ((261 266) 7) ((268 276) 1) ((293 298) 7) ((300 309) 2) ((326 331) 7) 
((333 342) 3) ((359 364) 7) ((366 375) 0) ((398 408) 4) ((431 441) 5) ((464 
474) 6))
-   '(("class There" ("declaration" . 13) ("$variable" . 33) ("$variable2" . 
68) ("$variable3" . 99) ("$variable4" . 130) ("$variable5" . 172) ("$variable6" 
. 211) ("function here" ("declaration" . 247)))))
+   '(("class There" ("declaration" . 13) ("$variable" . 33) ("$variable2" . 
68) ("$variable3" . 99) ("$variable4" . 130) ("$variable5" . 172) ("$variable6" 
. 211) ("function here" ("declaration" . 236)))))
 
   (phps-mode-test-ast--should-bookkeep
    "<?php\nclass MyClass\n{\n    static function here()\n    {\n        if 
($this) {\n            // Miss;\n        }\n    }\n    function there()\n    
{\n        if ($this) {\n            // Hit\n        }\n    }\n}\n"
    "Bookkeeping of $this not available inside static method"
    '(((68 73) 0) ((153 158) 1))
-   '(("class MyClass" ("declaration" . 13) ("function here" ("declaration" . 
54)) ("function there" ("declaration" . 139)))))
+   '(("class MyClass" ("declaration" . 13) ("function here" ("declaration" . 
43)) ("function there" ("declaration" . 127)))))
 
   (phps-mode-test-ast--should-bookkeep
    "<?php\n\nclass myClass\n{\n    private $tost = 'abc';\n    public function 
test($d)\n    {\n        return fn($e) => $this->tost . $d . $e;\n    
}\n}\n\n$a = new myClass();\necho $a->test('def')('ghi');"
    "Bookkeeping of $this reference inside arrow function inside of method"
    '(((36 41) 1) ((76 78) 4) ((104 106) 2) ((111 116) 3) ((118 122) 1) ((125 
127) 4) ((130 132) 2) ((143 145) 5) ((168 170) 5))
-   '(("class myClass" ("declaration" . 14) ("$tost" . 36) ("function test" 
("declaration" . 84) ("$d" . 76) ("$e" . 104))) ("$a" . 143)))
+   '(("class myClass" ("declaration" . 14) ("$tost" . 36) ("function test" 
("declaration" . 71) ("$d" . 76) ("$e" . 104))) ("$a" . 143)))
 
   (phps-mode-test-ast--should-bookkeep
    "<?php\n\nclass myClass\n{\n    static $var = '123';\n    static function 
myMethod($a)\n    {\n        return fn($b) => self::$var . $a . $b;\n    
}\n}\n\necho myClass::myMethod('4')('5');"
    "Bookkeeping of self reference inside arrow function inside of static 
method"
    '(((35 39) 1) ((78 80) 3) ((106 108) 2) ((119 123) 1) ((126 128) 3) ((131 
133) 2))
-  '(("class myClass" ("declaration" . 14) ("$var" . 35) ("function myMethod" 
("declaration" . 86) ("$a" . 78) ("$b" . 106)))))
+  '(("class myClass" ("declaration" . 14) ("$var" . 35) ("function myMethod" 
("declaration" . 69) ("$a" . 78) ("$b" . 106)))))
 
   (phps-mode-test-ast--should-bookkeep
    "<?php\nnamespace myNamespace;\nclass myClass\n{\n    private $property1 = 
'';\n    private $property2;\n    protected function myMethod(\n        
$argument1,\n        $argument2,\n        $argument3\n    ) {\n        if 
($this->property2) {\n            echo 'was here';\n        }\n        /* 
@codingStandardsIgnoreEnd */\n        if (\n            $argument1\n            
&& $argument2\n            && $argument3\n            && $argument4\n           
 && !empty($argument1['index'])\n  [...]
    "Bookkeeping of properties inside if condition list"
    '(((58 68) 1) ((87 97) 2) ((140 150) 5) ((160 170) 6) ((180 190) 7) ((211 
216) 4) ((218 227) 2) ((335 345) 5) ((361 371) 6) ((387 397) 7) ((413 423) 0) 
((446 456) 3) ((482 487) 4) ((489 498) 1) ((514 524) 3) ((537 542) 4) ((544 
553) 1))
-  '(("namespace myNamespace" ("declaration" . 17) ("class myClass" 
("declaration" . 36) ("$property1" . 58) ("$property2" . 87) ("function 
myMethod" ("declaration" . 197) ("$argument2" . 160) ("$argument3" . 180) 
("$argument1" . 446))))))
+  '(("namespace myNamespace" ("declaration" . 17) ("class myClass" 
("declaration" . 36) ("$property1" . 58) ("$property2" . 87) ("function 
myMethod" ("declaration" . 122) ("$argument2" . 160) ("$argument3" . 180) 
("$argument1" . 446))))))
 
   (phps-mode-test-ast--should-bookkeep
    "<?php\ntrait MyTrait {\n    private $var = 'abc';\n    public function 
sayHello() {\n        if ($this->var) {\n            echo 'Hit';\n        }\n   
 }\n}\n"
    "A basic trait class"
    '(((35 39) 1) ((94 99) 2) ((101 104) 1))
-   '(("trait MyTrait" ("declaration") ("$var" . 35) ("function sayHello" 
("declaration" . 80)))))
+   '(("trait MyTrait" ("declaration") ("$var" . 35) ("function sayHello" 
("declaration" . 69)))))
 
   (phps-mode-test-ast--should-bookkeep
    "<?php\nclass Person {\n    public function __construct(\n        private 
string $name,\n        private int $age,\n        public $address\n    ) {}\n}"
    "Class with class properties in constructor."
    '(((78 83) 3) ((105 109) 5) ((126 134) 7))
-   '(("class Person" ("declaration" . 13) ("$name" . 78) ("$age" . 105) 
("$address" . 126) ("function __construct" ("declaration" . 141) ("$name" . 78) 
("$age" . 105) ("$address" . 126)))))
+   '(("class Person" ("declaration" . 13) ("function __construct" 
("declaration" . 42) ("$name" . 78) ("$age" . 105) ("$address" . 126)) ("$name" 
. 78) ("$age" . 105) ("$address" . 126))))
 
   (phps-mode-test-ast--should-bookkeep
    "<?php\nfunction myFunction()\n{\n    $variable = 123;\n    if ($variable 
=== 456) {\n        $variable = 789;\n    }\n}\n"
@@ -356,6 +357,12 @@
    '(((35 44) 1) ((60 69) 1) ((89 98) 1))
    '(("function myFunction" ("declaration" . 16) ("$variable" . 35))))
 
+  (phps-mode-test-ast--should-bookkeep
+   "<?php\n\nclass myClass\n{\n    static $abc = 123;\n    public function 
__construct()\n    {\n        if (self::$abc) {\n            echo 'Hit';\n      
  }\n        if (self::$abc2) {\n            echo 'Miss';\n        }\n        
if ($this->random()) {\n            echo 'Hit';\n        }\n        if 
(myClass::$random) {\n            echo 'Hit';\n        }\n        if 
(self::random()) {\n            echo 'Hit';\n        }\n        if 
(myClass::random()) {\n            echo 'Hit';\n     [...]
+   "Do not bookkeep class static properties other than self and static"
+   '(((35 39) 1) ((105 109) 1) ((165 170) 0) ((221 226) 2))
+   '(("class myClass" ("declaration" . 14) ("$abc" . 35) ("function 
__construct" ("declaration" . 67)))))
+
   (message "\n-- Ran tests for bookkeeping generation. --"))
 
 (defun phps-mode-test-ast ()



reply via email to

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