[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/phps-mode 531c98cf2b 053/135: Improved bookkeeping of c
From: |
Christian Johansson |
Subject: |
[elpa] externals/phps-mode 531c98cf2b 053/135: Improved bookkeeping of class properties |
Date: |
Sun, 29 Jan 2023 03:11:03 -0500 (EST) |
branch: externals/phps-mode
commit 531c98cf2bba922d380565f3d55bfdc148af53bf
Author: Christian Johansson <christian@cvj.se>
Commit: Christian Johansson <christian@cvj.se>
Improved bookkeeping of class properties
---
phps-mode-parser-sdt.el | 157 ++++++++++++++++++++++++++++++---------------
test/phps-mode-test-ast.el | 2 +-
2 files changed, 108 insertions(+), 51 deletions(-)
diff --git a/phps-mode-parser-sdt.el b/phps-mode-parser-sdt.el
index 6416030b93..cdbed20839 100644
--- a/phps-mode-parser-sdt.el
+++ b/phps-mode-parser-sdt.el
@@ -3011,54 +3011,6 @@
(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
@@ -3118,7 +3070,6 @@
(plist-get property 'ast-type)))
(cond
((equal property-type 'property-variable)
- ;; TODO Bookkeep proerty-variable here
(let ((symbol-name
(plist-get property 'variable))
(symbol-start
@@ -3133,7 +3084,113 @@
symbol-scope
symbol-start
symbol-end)
-
phps-mode-parser-sdt--bookkeeping-symbol-assignment-stack))))))))))
+
phps-mode-parser-sdt--bookkeeping-symbol-assignment-stack))))))))
+
+ ((equal attributed-class-statement-type 'method)
+ ;; Go through stacks and modify symbol namespaces
+ ;; - add function scope but only for:
+ ;; - non-super-global variables
+ ;; - symbols defined inside function limits
+ (let ((function-name
+ (plist-get
+ attributed-class-statement
+ 'ast-name))
+ (function-start
+ (plist-get
+ attributed-class-statement
+ 'ast-start))
+ (function-end
+ (plist-get
+ attributed-class-statement
+ 'ast-end))
+ (function-parameter-list
+ (plist-get
+ attributed-class-statement
+ 'parameter-list))
+ (is-static-p))
+
+ (when-let (method-modifiers
+ (plist-get
+ attributed-class-statement
+ 'modifiers))
+ (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
+ (plist-get attributed-class-statement 'ast-start)
+ (plist-get attributed-class-statement 'ast-end))
+ 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))
+ (symbol-start (nth 2 symbol-list)))
+ (unless (or
+ (gethash
+ symbol-name
+
phps-mode-parser-sdt--bookkeeping--superglobal-variable-p)
+ (< symbol-start function-start)
+ (> symbol-start function-end))
+ (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))
+ (symbol-start (nth 2 symbol-list)))
+ (unless (or
+ (gethash
+ symbol-name
+
phps-mode-parser-sdt--bookkeeping--superglobal-variable-p)
+ (< symbol-start function-start)
+ (> symbol-start function-end))
+ (let ((symbol-scope (car (cdr symbol-list))))
+ (push
+ (list 'function function-name)
+ symbol-scope)
+ (setcar
+ (cdr symbol-list)
+ symbol-scope))))))
+
+ ;; Bookkeep method parameters
+ (let ((symbol-scope
+ phps-mode-parser-sdt--bookkeeping-namespace))
+ (push (list 'function function-name) symbol-scope)
+ (dolist (parameter function-parameter-list)
+ (let ((parameter-ast-type
+ (plist-get parameter 'ast-type)))
+ (cond
+ ((equal parameter-ast-type 'attributed-parameter)
+ (let* ((attributed-parameter
+ (plist-get
+ parameter
+ 'parameter))
+ (attributed-parameter-name
+ (plist-get attributed-parameter 'ast-name))
+ (symbol-name
+ attributed-parameter-name)
+ (symbol-start
+ (plist-get attributed-parameter 'ast-start))
+ (symbol-end
+ (plist-get attributed-parameter 'ast-end)))
+ (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 1569d34f48..43e9099371 100644
--- a/test/phps-mode-test-ast.el
+++ b/test/phps-mode-test-ast.el
@@ -236,7 +236,7 @@
(phps-mode-test-ast--should-bookkeep
"<?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."
- '((" 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 [...]
+ '((" namespace myNamespaceA id $var" ((37 41))) ((37 41) 1) (" namespace
myNamespaceA class myClassA function myFunctionB id $var5" ((485 490))) ("
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
$var3" ((142 147))) (" namespace myNamespaceA class myClassA function
myFunctionA id $var4" ((163 168))) (" n [...]
(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 ( [...]
- [elpa] externals/phps-mode d464cb1f01 077/135: Fixed bookkeeping of global variables, (continued)
- [elpa] externals/phps-mode d464cb1f01 077/135: Fixed bookkeeping of global variables, Christian Johansson, 2023/01/29
- [elpa] externals/phps-mode 1a1245f186 082/135: Passing bookkeeping test isset and empty variables, Christian Johansson, 2023/01/29
- [elpa] externals/phps-mode 696d66d7e7 085/135: Bookkeeping of static variable inside function, Christian Johansson, 2023/01/29
- [elpa] externals/phps-mode cffad0d620 131/135: Merge branch 'feature/full-sdt', Christian Johansson, 2023/01/29
- [elpa] externals/phps-mode 249f8a2a4d 087/135: Work on bookkeeping class static variable, Christian Johansson, 2023/01/29
- [elpa] externals/phps-mode 177b00f06a 132/135: Updated copyright years, Christian Johansson, 2023/01/29
- [elpa] externals/phps-mode 0654fe8899 134/135: Updated documentation, Christian Johansson, 2023/01/29
- [elpa] externals/phps-mode 6e43f9f6db 037/135: More messing around with SDT, Christian Johansson, 2023/01/29
- [elpa] externals/phps-mode 86ad9e35ee 047/135: Renamed symbol id to symbol URI, Christian Johansson, 2023/01/29
- [elpa] externals/phps-mode dbaf508512 052/135: Work on getting bookkeeping for class properties working, Christian Johansson, 2023/01/29
- [elpa] externals/phps-mode 531c98cf2b 053/135: Improved bookkeeping of class properties,
Christian Johansson <=
- [elpa] externals/phps-mode 5080effb1d 014/135: Added TODO item, Christian Johansson, 2023/01/29
- [elpa] externals/phps-mode cfcb795473 016/135: SDT for while_statement, Christian Johansson, 2023/01/29
- [elpa] externals/phps-mode 38ccb4e728 019/135: More SDT for argument and union_type and intersection_type, Christian Johansson, 2023/01/29
- [elpa] externals/phps-mode 7602348327 031/135: More SDT rules, Christian Johansson, 2023/01/29
- [elpa] externals/phps-mode 7dcaa1df9e 034/135: Added SDT rules for all productions, Christian Johansson, 2023/01/29
- [elpa] externals/phps-mode 258551c02a 035/135: More work on bookkeeping generation via SDT, Christian Johansson, 2023/01/29
- [elpa] externals/phps-mode e887dc91e3 043/135: Added TODO items, Christian Johansson, 2023/01/29
- [elpa] externals/phps-mode 002b27bfb7 054/135: Started on bookkeeping support via SDT for class properties via object operator, Christian Johansson, 2023/01/29
- [elpa] externals/phps-mode ad3b10e716 055/135: Added variable reference to bookkeeping stack where it is referencing $this, Christian Johansson, 2023/01/29
- [elpa] externals/phps-mode 911abb044e 024/135: SDT method_body, Christian Johansson, 2023/01/29