Remove commented code + tidy some formatting

WIP-incremental-parsing
Hugo Thunnissen 1 year ago
parent 224bbd7916
commit 8cd4dc2025

@ -85,49 +85,6 @@ pattern. See `phpinspect--match-sequence'."
"Match SEQUENCE to PATTERN."
(funcall (phpinspect--pattern-matcher pattern) sequence))
;; (defmacro phpinspect--match-sequence (sequence &rest pattern)
;; "Match SEQUENCE to positional matchers defined in PATTERN.
;; PATTERN is a plist with the allowed keys being :m and :f. Each
;; key-value pair in the plist defines a match operation that is
;; applied to the corresponding index of SEQUENCE (so for ex.: key 0
;; is applied to pos. 0 of SEQUENCE, key 1 to pos. 1, and so on).
;; Possible match operations:
;; :m - This key can be used to match a list element to the literal
;; value supplied for it, using the `equal' comparison function. For
;; example, providing `(\"foobar\") as value will result in the
;; comparison (equal (elt SEQUENCE pos) `(\"foobar\")). There is one
;; exception to this rule: using the symbol * as value for the :m
;; key will match anything, essentially skipping comparison for the
;; element at this position in SEQUENCE.
;; :f - This key can be used to match a list element by executing
;; the function provided as value. The function is executed with the
;; list element as argument, and will be considered as matching if
;; it evaluates to a non-nil value."
;; (let ((pattern-length (length pattern))
;; (count 0)
;; (sequence-pos 0)
;; (and-statement))
;; (while (< count pattern-length)
;; (let ((key (elt pattern count))
;; (value (elt pattern (+ count 1))))
;; (unless (keywordp key)
;; (error (format "Invalid, expected keyword, got %s" key)))
;; (cond ((eq key :m)
;; (unless (eq value '*)
;; (push `(equal ,value (elt ,sequence ,sequence-pos)) and-statement)))
;; ((eq key :f)
;; (push `(,value (elt ,sequence ,sequence-pos)) and-statement))
;; (t (error (format "Invalid keyword: %s" key))))
;; (setq count (+ count 2)
;; sequence-pos (+ sequence-pos 1))))
;; `(when (= ,sequence-pos (length ,sequence)) (and ,@and-statement))))
(defun phpinspect--match-sequence (sequence &rest pattern)
"Match SEQUENCE to positional matchers defined in PATTERN.
@ -151,31 +108,29 @@ the function provided as value. The function is executed with the
list element as argument, and will be considered as matching if
it evaluates to a non-nil value."
(let* ((pattern-length (length pattern))
(count 0)
(sequence-pos 0)
(sequence-length (/ pattern-length 2)))
(count 0)
(sequence-pos 0)
(sequence-length (/ pattern-length 2)))
(and (= sequence-length (length sequence))
(catch 'found
(while (< count pattern-length)
(let ((key (elt pattern count))
(value (elt pattern (+ count 1))))
(unless (keywordp key)
(error (format "Invalid, expected keyword, got %s" key)))
(cond ((eq key :m)
(unless (eq value '*)
(unless (equal value (elt sequence sequence-pos))
(throw 'found nil))))
((eq key :f)
(unless (funcall value (elt sequence sequence-pos))
(throw 'found nil)))
(t (error (format "Invalid keyword: %s" key))))
(setq count (+ count 2)
sequence-pos (+ sequence-pos 1))))
(throw 'found t)))))
(catch 'found
(while (< count pattern-length)
(let ((key (elt pattern count))
(value (elt pattern (+ count 1))))
(unless (keywordp key)
(error (format "Invalid, expected keyword, got %s" key)))
(cond ((eq key :m)
(unless (eq value '*)
(unless (equal value (elt sequence sequence-pos))
(throw 'found nil))))
((eq key :f)
(unless (funcall value (elt sequence sequence-pos))
(throw 'found nil)))
(t (error (format "Invalid keyword: %s" key))))
(setq count (+ count 2)
sequence-pos (+ sequence-pos 1))))
(throw 'found t)))))
(defun phpinspect--pattern-concat (pattern1 pattern2)
(let* ((pattern1-sequence-length (/ (length (phpinspect--pattern-code pattern1)) 2)))

@ -604,41 +604,6 @@ resolve types of function argument variables."
(phpinspect-get-pattern-type-in-block
resolvecontext (phpinspect--make-pattern :m `(:variable ,variable-name))
php-block type-resolver function-arg-list)))
;; else
;; (let* ((assignments
;; (phpinspect--find-assignments-by-predicate
;; php-block (phpinspect--match-sequence-lambda
;; :m `(:variable ,variable-name))))
;; (last-assignment (when assignments (car (last assignments))))
;; (last-assignment-value (when last-assignment
;; (phpinspect--assignment-from last-assignment)))
;; (result))
;; (if (not assignments)
;; (progn
;; (phpinspect--log "No assignments found for variable %s, checking function arguments"
;; variable-name)
;; (setq result (phpinspect-get-variable-type-in-function-arg-list
;; variable-name type-resolver function-arg-list)))
;; (setq result
;; (phpinspect--interpret-expression-type-in-context
;; resolvecontext php-block type-resolver
;; last-assignment-value function-arg-list)))
;; (phpinspect--log "Type interpreted from last assignment expression of variable %s: %s"
;; variable-name result)
;; ;; Detect array access
;; (if (and last-assignment-value result
;; (< 1 (length last-assignment-value))
;; (phpinspect-array-p (car (last last-assignment-value))))
;; (progn
;; (phpinspect--log (concat
;; "Detected array access in last assignment of variable %s"
;; ", collection type: %s")
;; variable-name result)
;; (phpinspect--type-contains result))
;; result))))
(defun phpinspect-get-pattern-type-in-block
(resolvecontext pattern php-block type-resolver &optional function-arg-list)

Loading…
Cancel
Save