[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 [...]
- [elpa] externals/phps-mode 3332b2bfa9 109/135: Fixes syntax coloring of super-globals, (continued)
- [elpa] externals/phps-mode 3332b2bfa9 109/135: Fixes syntax coloring of super-globals, Christian Johansson, 2023/01/29
- [elpa] externals/phps-mode bddf800099 111/135: Added failing test, Christian Johansson, 2023/01/29
- [elpa] externals/phps-mode d98f6d78d8 114/135: Saving symbol-table after parse, Christian Johansson, 2023/01/29
- [elpa] externals/phps-mode 1594c15e9e 117/135: More work on imenu generation, Christian Johansson, 2023/01/29
- [elpa] externals/phps-mode 776c818ff9 121/135: Passing some more imenu tests, Christian Johansson, 2023/01/29
- [elpa] externals/phps-mode c6e4844753 122/135: Some byte-compilation fixes, Christian Johansson, 2023/01/29
- [elpa] externals/phps-mode 96eeff74f8 130/135: Added more todo items for bookkeeping and imenu, Christian Johansson, 2023/01/29
- [elpa] externals/phps-mode 66ad034207 025/135: SDT member_modifier, Christian Johansson, 2023/01/29
- [elpa] externals/phps-mode 34a595fa09 028/135: SDT class_const_list, Christian Johansson, 2023/01/29
- [elpa] externals/phps-mode 1332919417 049/135: Passing another bookkeeping test via SDT, Christian Johansson, 2023/01/29
- [elpa] externals/phps-mode 438ec520fc 051/135: Passing bookkeeping via SDT for conditional assignments,
Christian Johansson <=
- [elpa] externals/phps-mode 7fa721a85d 060/135: More work on bookkeeping static class properties, Christian Johansson, 2023/01/29
- [elpa] externals/phps-mode 0bf9b31fef 062/135: Passed bookkeeping via SDT for try catch variables, Christian Johansson, 2023/01/29
- [elpa] externals/phps-mode 40d7d88fb8 069/135: Work on bookkeeping global variables, Christian Johansson, 2023/01/29
- [elpa] externals/phps-mode a10656fc34 070/135: Passing bookkeeping test for global variables, Christian Johansson, 2023/01/29
- [elpa] externals/phps-mode 9c67facc86 075/135: Work on bookkeeping of class static properties, Christian Johansson, 2023/01/29
- [elpa] externals/phps-mode 39a6fe03ae 079/135: Improved is-varadic and is-reference argument flags, Christian Johansson, 2023/01/29
- [elpa] externals/phps-mode e8a5dbe153 126/135: Fix for trait and interface imenu, Christian Johansson, 2023/01/29
- [elpa] externals/phps-mode 579034d1c6 127/135: Passing imenu test via SDT, Christian Johansson, 2023/01/29
- [elpa] externals/phps-mode fb9a181135 088/135: Passed more bookkeeping tsts, Christian Johansson, 2023/01/29
- [elpa] externals/phps-mode e6bc401d0b 068/135: Work on improving test for global variable bookkeeping, Christian Johansson, 2023/01/29