[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/phps-mode c83b1c264e 060/212: Fixed SDT for isset_varia
From: |
Christian Johansson |
Subject: |
[elpa] externals/phps-mode c83b1c264e 060/212: Fixed SDT for isset_variables |
Date: |
Wed, 26 Jan 2022 01:50:43 -0500 (EST) |
branch: externals/phps-mode
commit c83b1c264eb83e0ba6e13afe0f2f53362bf3b36c
Author: Christian Johansson <christian@cvj.se>
Commit: Christian Johansson <christian@cvj.se>
Fixed SDT for isset_variables
---
phps-mode-ast-bookkeeping.el | 87 ++++++++++++++++++++++++++++++++++----------
phps-mode-parser-sdt.el | 11 +++++-
test/phps-mode-test-ast.el | 2 +-
3 files changed, 78 insertions(+), 22 deletions(-)
diff --git a/phps-mode-ast-bookkeeping.el b/phps-mode-ast-bookkeeping.el
index ab798591aa..1054f87282 100644
--- a/phps-mode-ast-bookkeeping.el
+++ b/phps-mode-ast-bookkeeping.el
@@ -105,8 +105,6 @@
name))
scope-string))
-;; TODO Should return a list of strings to support the case with a read-only
-;; variable inside a arrow function that should check outer scopes as well
(defun phps-mode-ast-bookkeeping--generate-variable-scope-string
(scope name &optional read-only)
"Generate variable scope string from SCOPE and NAME and optionally
READ-ONLY."
@@ -170,6 +168,16 @@
scope-string
scope-name)))
+ ((and
+ (equal scope-type 'defined)
+ scope-name)
+ (setq
+ scope-string
+ (format
+ "%s defined %s"
+ scope-string
+ scope-name)))
+
((and
(equal scope-type 'arrow-function)
scope-name)
@@ -212,7 +220,8 @@
(let ((bookkeeping (make-hash-table :test 'equal))
(bookkeeping-stack phps-mode-ast--tree)
(inline-function-count 0)
- (arrow-function-count 0))
+ (arrow-function-count 0)
+ (defined-count 0))
(while bookkeeping-stack
(let ((item-raw (pop bookkeeping-stack))
(item)
@@ -346,12 +355,58 @@
(push `(,sub-scope ,child) bookkeeping-stack)))))
((equal type 'if)
- (when-let ((children (reverse (plist-get item 'children))))
- (dolist (child children)
- (push `(,scope, child) bookkeeping-stack)))
- (when-let ((conditions (reverse (plist-get item 'condition))))
+ (let ((conditions (reverse (plist-get item 'condition)))
+ (found-defined-scope)
+ (sub-scope scope))
(dolist (condition conditions)
- (push `(,scope ,condition) bookkeeping-stack))))
+ (when-let ((condition-type (plist-get condition 'ast-type)))
+ (cond
+
+ ((equal condition-type 'isset-variables)
+ (let ((sub-scope scope))
+ (unless found-defined-scope
+ (setq defined-count (1+ defined-count))
+ (setq found-defined-scope t))
+ (push `(type defined name ,defined-count) sub-scope)
+ (let ((isset-variables (plist-get condition 'variables)))
+ (dolist (isset-variable isset-variables)
+ (let ((id
+
(phps-mode-ast-bookkeeping--generate-variable-scope-string
+ sub-scope
+ (plist-get isset-variable 'name))))
+ (puthash
+ id
+ 1
+ bookkeeping))))))
+
+ ((and
+ (equal condition-type 'negated-expression)
+ (equal (plist-get (plist-get condition 'expression)
'ast-type) 'empty-expression))
+ (let ((sub-scope scope))
+ (unless found-defined-scope
+ (setq defined-count (1+ defined-count))
+ (setq found-defined-scope t))
+ (push `(type defined name ,defined-count) sub-scope)
+ (let ((not-empty-variables (plist-get (plist-get
condition 'expression) 'variables)))
+ (dolist (not-empty-variable not-empty-variables)
+ (let ((id
+
(phps-mode-ast-bookkeeping--generate-variable-scope-string
+ sub-scope
+ (plist-get not-empty-variable 'name))))
+ (puthash
+ id
+ 1
+ bookkeeping))))))
+
+ )))
+ (when found-defined-scope
+ (push `(type defined name ,defined-count) sub-scope))
+ (when-let ((children (reverse (plist-get item 'children))))
+ (dolist (child children)
+ (push `(,sub-scope, child) bookkeeping-stack)))
+ (when conditions
+ (dolist (condition conditions)
+ (push `(,sub-scope ,condition) bookkeeping-stack)))))
((equal type 'foreach)
(when-let ((children (reverse (plist-get item 'children))))
@@ -568,13 +623,7 @@
(push `(,scope ,(plist-get item 'variable)) bookkeeping-stack))
((equal type 'negated-expression)
- (let ((expression (plist-get item 'expression)))
- ;; TODO Define sub-scope here
- (when (equal (plist-get expression 'ast-type) 'empty-expression)
- (let ((not-empty-variables (reverse (plist-get expression
'variables))))
- ;; TODO Define variable here
- ))
- (push `(,scope ,expression) bookkeeping-stack)))
+ (push `(,scope ,(plist-get item 'expression)) bookkeeping-stack))
((equal type 'try)
(when-let ((children (reverse (plist-get item
'inner-statement-list))))
@@ -636,10 +685,10 @@
(phps-mode-ast-bookkeeping--generate-symbol-scope-string
sub-scope
property-name))
- (bookkeeping-object
- (list
- (plist-get item 'property-start)
- (plist-get item 'property-end))))
+ (bookkeeping-object
+ (list
+ (plist-get item 'property-start)
+ (plist-get item 'property-end))))
;; (message "dereferenced: %S %S" variable-id symbol-id)
(when (gethash symbol-id bookkeeping)
(setq
diff --git a/phps-mode-parser-sdt.el b/phps-mode-parser-sdt.el
index c1f022d112..0a20e3414e 100644
--- a/phps-mode-parser-sdt.el
+++ b/phps-mode-parser-sdt.el
@@ -1030,7 +1030,7 @@
(puthash
538
(lambda(args _terminals)
- `(ast-type isset-variables variables ,(nth 2 args)))
+ `(ast-type isset-variables variables
,(phps-mode-parser-sdt--get-list-of-object (nth 2 args))))
phps-mode-parser--table-translations)
;; internal_functions_in_yacc -> (T_EMPTY "(" expr ")")
@@ -1044,7 +1044,7 @@
(puthash
545
(lambda(args _terminals)
- (list args))
+ args)
phps-mode-parser--table-translations)
;; isset_variables -> (isset_variables "," isset_variable)
@@ -1054,5 +1054,12 @@
(append (nth 0 args) (nth 2 args)))
phps-mode-parser--table-translations)
+;; isset_variable -> (expr)
+(puthash
+ 547
+ (lambda(args _terminals)
+ (list args))
+ phps-mode-parser--table-translations)
+
(provide 'phps-mode-parser-sdt)
;;; phps-mode-parser-sdt.el ends here
diff --git a/test/phps-mode-test-ast.el b/test/phps-mode-test-ast.el
index 43a557a682..e58001c914 100644
--- a/test/phps-mode-test-ast.el
+++ b/test/phps-mode-test-ast.el
@@ -603,7 +603,7 @@
(should
(equal
(phps-mode-test--hash-to-list phps-mode-ast-bookkeeping--index t)
- '((" defined 1 id $x" 1) ((18 20) 1) ((33 35) 1) (" defined 2 id $i" 1)
((77 79) 1) (" defined 2 id $u" 1) ((81 83) 1) ((104 106) 1) ((168 170) 1)
((232 234) 1) ((302 304) 0) ((355 357) 0) ((408 410) 0) (" defined 3 id $y" 1)
((445 447) 1) ((460 462) 1) (" defined 4 id $k" 1) ((505 507) 1) (" defined 4
id $L" 1) ((519 521) 1) ((542 544) 1) ((606 608) 1) ((670 672) 1) ((740 742) 0)
((793 795) 0) ((846 848) 0))))))
+ '((" defined 1 id $x" 1) ((18 20) 1) ((33 35) 1) (" defined 2 id $i" 1)
(" defined 2 id $u" 1) ((77 79) 1) ((81 83) 1) ((104 106) 1) ((168 170) 1)
((232 234) 1) ((302 304) 0) ((355 357) 0) ((408 410) 0) (" defined 3 id $y" 1)
((445 447) 1) ((460 462) 1) (" defined 4 id $k" 1) ((505 507) 1) (" defined 4
id $L" 1) ((519 521) 1) ((542 544) 1) ((606 608) 1) ((670 672) 1) ((740 742) 0)
((793 795) 0) ((846 848) 0))))))
(phps-mode-test-ast--buffer-contents
"<?php\ninterface myInterface\n{\n function myFunction1();\n function
myFunction2($x);\n}\n"
- [elpa] externals/phps-mode 3d54b6ff01 022/212: Passed another test for bookkeeping generated via parser SDT, (continued)
- [elpa] externals/phps-mode 3d54b6ff01 022/212: Passed another test for bookkeeping generated via parser SDT, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 442ad93cb2 018/212: Fix for function parameter formatting in AST, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 2a4d5dea37 019/212: Passed bookkeeping of function arguments, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode c29e35fea2 021/212: More work on bookkeeping, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 0daaa97f8d 025/212: SDT for for() loop started, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode fa3681141b 027/212: Passed test for bookkeeping of conditional assignment via parser SDT, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode fc4c763d68 030/212: Added SDT for class properties, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode f7c261cee1 032/212: Generate parser command now compatible with latest emacs-parser-generator, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode f82c9a377d 033/212: Re-generated parser to verify automation functionality, improved automation documentation, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode f858060096 034/212: More work on bookkeeping generated from parser SDT, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode c83b1c264e 060/212: Fixed SDT for isset_variables,
Christian Johansson <=
- [elpa] externals/phps-mode 8fa61fa1f2 063/212: Passing bookkeeping of interface method arguments, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 7a636ccd28 078/212: Removed obsolete file parser-grammar-macro.el, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode ee211dac6a 084/212: Started on indentation tests, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode f65ca852cd 092/212: Passed another indent test, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 9a2573939a 094/212: More wrestling, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 7c0cb57312 098/212: Added more multi-line assignment indent tests, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 3a594466d5 100/212: Passed indent test for multi-line assignments, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 7deebc5f79 101/212: Improved indent test descriptions, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode d5d80017bc 104/212: Passed indent tests for concatenated string, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode e083e90ac0 108/212: Passing more indentation tests for PSR-2, Christian Johansson, 2022/01/26