Compare commits

...

3 Commits

@ -130,39 +130,6 @@
(and (> (phpinspect-overlay-end ,overlay) ,point) (and (> (phpinspect-overlay-end ,overlay) ,point)
(<= (phpinspect-overlay-start ,overlay) ,point))))) (<= (phpinspect-overlay-start ,overlay) ,point)))))
(defmacro phpinspect-bmap-iterate-region (region place-and-bmap &rest body)
(declare (indent defun))
(let ((place (car place-and-bmap))
(bmap (gensym))
(bmap-stack (gensym))
(region-start (gensym))
(region-end (gensym)))
`(let ((,bmap)
,(when (symbolp place) place)
(,bmap-stack (list ,(cadr place-and-bmap)))
(,region-start (car ,region))
(,region-end (cadr ,region)))
(while (setq ,bmap (pop ,bmap-stack))
(phpinspect-bmap-iterate (,place ,bmap)
(when (and (<= ,region-start
(phpinspect-meta-start ,place))
(>= ,region-end
(phpinspect-meta-end ,place)))
,@body))))))
(defmacro phpinspect-bmap-iterate (place-and-bmap &rest body)
(declare (indent defun))
(let ((place (car place-and-bmap))
(bmap (gensym))
(ignored (gensym)))
`(let ((,bmap ,(cadr place-and-bmap)))
(maphash (lambda (,ignored ,place)
,@body
(when (phpinspect-meta-overlay ,place)
(phpinspect-splayt-traverse (,place (phpinspect-meta-children ,place))
,@body)))
(phpinspect-bmap-meta ,bmap)))))
(defsubst phpinspect-bmap-register (bmap start end token &optional whitespace-before overlay) (defsubst phpinspect-bmap-register (bmap start end token &optional whitespace-before overlay)
(let* ((starts (phpinspect-bmap-starts bmap)) (let* ((starts (phpinspect-bmap-starts bmap))
(ends (phpinspect-bmap-ends bmap)) (ends (phpinspect-bmap-ends bmap))
@ -254,14 +221,10 @@
(phpinspect-bmap-tokens-ending-at overlay point) (phpinspect-bmap-tokens-ending-at overlay point)
(gethash point (phpinspect-bmap-ends bmap))))) (gethash point (phpinspect-bmap-ends bmap)))))
(defsubst phpinspect-bmap-tokens-overlapping (bmap point) (defsubst phpinspect-bmap-tokens-overlapping (bmap point)
(let ((tokens)) (sort
(phpinspect-bmap-iterate (meta bmap) (phpinspect-meta-find-overlapping-children (phpinspect-bmap-root-meta bmap) point)
(when (phpinspect-meta-overlaps-point meta point) #'phpinspect-meta-sort-width))
(push meta tokens)))
(sort tokens #'phpinspect-meta-sort-width)))
(defsubst phpinspect-overlay-encloses-meta (overlay meta) (defsubst phpinspect-overlay-encloses-meta (overlay meta)
(and (>= (phpinspect-meta-start meta) (phpinspect-overlay-start overlay)) (and (>= (phpinspect-meta-start meta) (phpinspect-overlay-start overlay))

@ -168,7 +168,9 @@
(cl-defmethod phpinspect-meta-find-overlapping-child ((meta (head meta)) (point integer)) (cl-defmethod phpinspect-meta-find-overlapping-child ((meta (head meta)) (point integer))
(let ((child (phpinspect-splayt-find-largest-before (let ((child (phpinspect-splayt-find-largest-before
(phpinspect-meta-children meta) (phpinspect-meta--point-offset meta point)))) (phpinspect-meta-children meta)
;; Use point +1 as a child starting at point still overlaps
(+ (phpinspect-meta--point-offset meta point) 1))))
(when (and child (phpinspect-meta-overlaps-point child point)) (when (and child (phpinspect-meta-overlaps-point child point))
child))) child)))

@ -105,13 +105,11 @@ BODY can be any form."
(let ((item-sym (gensym)) (let ((item-sym (gensym))
(place (car place-and-queue)) (place (car place-and-queue))
(queue (cadr place-and-queue))) (queue (cadr place-and-queue)))
`(let* ((,item-sym (phpinspect-queue-first ,queue)) `(let* ((,item-sym (phpinspect-queue-first ,queue)))
(,place (when ,item-sym (phpinspect-queue-item-value ,item-sym)))) (while ,item-sym
(when ,place (let ((,place (phpinspect-queue-item-value ,item-sym)))
,@body ,@body
(while (setq ,item-sym (phpinspect-queue-item-next ,item-sym)) (setq ,item-sym (phpinspect-queue-item-next ,item-sym)))))))
(setq ,place (phpinspect-queue-item-value ,item-sym))
,@body)))))
(cl-defmethod phpinspect-queue-find (cl-defmethod phpinspect-queue-find
((queue phpinspect-queue) value comparison-func) ((queue phpinspect-queue) value comparison-func)

@ -245,8 +245,7 @@ apeared to be a little more performant than using `let'."
(,reverse-sym t) (,reverse-sym t)
,current-sym ,current-sym
,size-sym ,size-sym
,stack-sym ,stack-sym)
,(if (symbolp place) place (gensym)))
(while ,queue-sym (while ,queue-sym
(setq ,size-sym (length ,queue-sym)) (setq ,size-sym (length ,queue-sym))
@ -257,8 +256,8 @@ apeared to be a little more performant than using `let'."
(if ,reverse-sym (if ,reverse-sym
(push ,current-sym ,stack-sym) (push ,current-sym ,stack-sym)
(setf ,place ,current-sym) (let ((,place ,current-sym))
,@body) ,@body))
(when (phpinspect-splayt-node-right ,current-sym) (when (phpinspect-splayt-node-right ,current-sym)
(push (phpinspect-splayt-node-right ,current-sym) ,queue-sym)) (push (phpinspect-splayt-node-right ,current-sym) ,queue-sym))
@ -271,8 +270,8 @@ apeared to be a little more performant than using `let'."
(when ,reverse-sym (when ,reverse-sym
(while ,stack-sym (while ,stack-sym
(setq ,current-sym (pop ,stack-sym)) (setq ,current-sym (pop ,stack-sym))
(setf ,place ,current-sym) (let ((,place ,current-sym))
,@body)) ,@body)))
(setq ,reverse-sym (not ,reverse-sym))) (setq ,reverse-sym (not ,reverse-sym)))
@ -300,16 +299,15 @@ near the top of the tee.
(current (gensym)) (current (gensym))
(stack (gensym))) (stack (gensym)))
`(let* ((,current ,(cadr place-and-node)) `(let* ((,current ,(cadr place-and-node))
,stack ,stack)
,@(if (symbolp place) (list place)))
(while (or ,stack ,current) (while (or ,stack ,current)
(if ,current (if ,current
(progn (progn
(push ,current ,stack) (push ,current ,stack)
(setq ,current (phpinspect-splayt-node-left ,current))) (setq ,current (phpinspect-splayt-node-left ,current)))
(setq ,current (pop ,stack)) (setq ,current (pop ,stack))
(setf ,place ,current) (let ((,place ,current))
,@body ,@body)
(setq ,current (phpinspect-splayt-node-right ,current))))))) (setq ,current (phpinspect-splayt-node-right ,current)))))))
(defmacro phpinspect-splayt-traverse-lr (place-and-splayt &rest body) (defmacro phpinspect-splayt-traverse-lr (place-and-splayt &rest body)
@ -321,8 +319,8 @@ The PLACE is assigned the value of each node.
(declare (indent 1)) (declare (indent 1))
`(phpinspect-splayt-node-traverse-lr `(phpinspect-splayt-node-traverse-lr
(,(car place-and-splayt) (phpinspect-splayt-root-node ,(cadr place-and-splayt))) (,(car place-and-splayt) (phpinspect-splayt-root-node ,(cadr place-and-splayt)))
(setf ,(car place-and-splayt) (phpinspect-splayt-node-value ,(car place-and-splayt))) (let ((,(car place-and-splayt) (phpinspect-splayt-node-value ,(car place-and-splayt))))
,@body)) ,@body)))
(define-inline phpinspect-splayt-node-key-less-p (node key) (define-inline phpinspect-splayt-node-key-less-p (node key)
(inline-quote (> ,key (phpinspect-splayt-node-key ,node)))) (inline-quote (> ,key (phpinspect-splayt-node-key ,node))))

@ -64,10 +64,10 @@ that the collection is expected to contain")
;; see https://www.php.net/manual/ja/language.types.declarations.php ;; see https://www.php.net/manual/ja/language.types.declarations.php
;;; ;;;
;; However, this list does not need to be valid, it just needs to contain the ;; However, this list does not need to be valid, it just needs to contain the
;; list of type names that we should not attempt to resolve relatively. ;; list of type names that we should not attempst to resolve relatively.
'("array" "bool" "callable" "float" "int" "iterable" "mixed" "object" "string" "void" "self" "static" "this")) '("array" "bool" "callable" "float" "int" "iterable" "mixed" "object" "string" "void" "self" "static" "this"))
(defconst phpinspect-native-types (defvar phpinspect-native-types
(phpinspect--make-types (mapcar (lambda (name) (concat "\\" name)) (phpinspect--make-types (mapcar (lambda (name) (concat "\\" name))
phpinspect-native-typenames))) phpinspect-native-typenames)))
@ -75,11 +75,11 @@ that the collection is expected to contain")
(phpinspect--make-types '("\\array" "\\iterable" "\\SplObjectCollection" "\\mixed")) (phpinspect--make-types '("\\array" "\\iterable" "\\SplObjectCollection" "\\mixed"))
"FQNs of types that should be treated as collecitons when inferring types.") "FQNs of types that should be treated as collecitons when inferring types.")
(defconst phpinspect--object-type (phpinspect--make-type :name "\\object" :fully-qualified t)) (defvar phpinspect--object-type (phpinspect--make-type :name "\\object" :fully-qualified t))
(defconst phpinspect--static-type (phpinspect--make-type :name "\\static" :fully-qualified t)) (defvar phpinspect--static-type (phpinspect--make-type :name "\\static" :fully-qualified t))
(defconst phpinspect--self-type (phpinspect--make-type :name "\\self" :fully-qualified t)) (defvar phpinspect--self-type (phpinspect--make-type :name "\\self" :fully-qualified t))
(defconst phpinspect--this-type (phpinspect--make-type :name "\\this" :fully-qualified t)) (defvar phpinspect--this-type (phpinspect--make-type :name "\\this" :fully-qualified t))
(defconst phpinspect--null-type (phpinspect--make-type :name "\\null" :fully-qualified t)) (defvar phpinspect--null-type (phpinspect--make-type :name "\\null" :fully-qualified t))
(defun phpinspect-define-standard-types () (defun phpinspect-define-standard-types ()
(setq phpinspect-native-types (setq phpinspect-native-types

@ -64,47 +64,16 @@
(ert-deftest phpinspect-bmap-tokens-overlapping () (ert-deftest phpinspect-bmap-tokens-overlapping ()
(let ((bmap (phpinspect-make-bmap))) (let ((bmap (phpinspect-make-bmap)))
(phpinspect-bmap-register bmap 9 200 '(:node1))
(phpinspect-bmap-register bmap 20 200 '(:node2))
(phpinspect-bmap-register bmap 9 20 '(:node3)) (phpinspect-bmap-register bmap 9 20 '(:node3))
(phpinspect-bmap-register bmap 21 44 '(:node4)) (phpinspect-bmap-register bmap 21 44 '(:node4))
(phpinspect-bmap-register bmap 20 200 '(:node2))
(phpinspect-bmap-register bmap 9 200 '(:node1))
(phpinspect-bmap-register bmap 1 300 '(:root))
(let ((result (phpinspect-bmap-tokens-overlapping bmap 22))) (let ((result (phpinspect-bmap-tokens-overlapping bmap 22)))
(should (equal '((:node4) (:node2) (:node1)) (should (equal '((:node4) (:node2) (:node1))
(mapcar #'phpinspect-meta-token result)))))) (mapcar #'phpinspect-meta-token result))))))
(ert-deftest phpinspect-bmap-tokens-overlapping-overlayed ()
(let ((bmap (phpinspect-make-bmap))
(bmap2 (phpinspect-make-bmap))
(bmap3 (phpinspect-make-bmap))
result)
(phpinspect-bmap-register bmap 9 200 '(:token1))
(phpinspect-bmap-register bmap 20 200 '(:token2))
(phpinspect-bmap-register bmap 9 20 '(:token3))
(phpinspect-bmap-register bmap 21 44 '(:token4))
(phpinspect-bmap-register bmap2 200 230 '(:token5))
(phpinspect-bmap-register bmap3 300 305 '(:token6))
;; Should start at 220 of bmap2
(phpinspect-bmap-overlay
bmap2 bmap3 (phpinspect-bmap-token-starting-at bmap3 300) -80)
(setq result (phpinspect-bmap-tokens-overlapping bmap2 220))
(should (equal '((:token6) (:token5)) (mapcar #'phpinspect-meta-token result)))
(phpinspect-bmap-overlay
bmap bmap2 (phpinspect-bmap-token-starting-at bmap2 200) 20)
(phpinspect-bmap-overlay
bmap bmap2 (phpinspect-bmap-token-starting-at bmap2 220) 20)
(setq result (phpinspect-bmap-tokens-overlapping bmap 240))
(should (equal '((:token6) (:token5)) (mapcar #'phpinspect-meta-token result)))
(setq result (phpinspect-bmap-tokens-overlapping bmap 22))
(should (equal '((:token4) (:token2) (:token1)) (mapcar #'phpinspect-meta-token result)))))
(ert-deftest phpinspect-bmap-register () (ert-deftest phpinspect-bmap-register ()
(let* ((bmap (phpinspect-make-bmap)) (let* ((bmap (phpinspect-make-bmap))
(token1 `(:word "foo")) (token1 `(:word "foo"))

@ -71,7 +71,7 @@
;; attempt to iterate over an empty queue ;; attempt to iterate over an empty queue
(let ((have-iterated nil)) (let ((have-iterated nil))
(phpinspect-doqueue (thing (phpinspect-make-queue)) (phpinspect-doqueue (_thing (phpinspect-make-queue))
(setq have-iterated t)) (setq have-iterated t))
(should-not have-iterated))) (should-not have-iterated)))

Loading…
Cancel
Save