Compare commits
22 Commits
master
...
WIP-increm
Author | SHA1 | Date |
---|---|---|
Hugo Thunnissen | 55b8a0c562 | 10 months ago |
Hugo Thunnissen | b89ef3611f | 10 months ago |
Hugo Thunnissen | fa2967ddba | 10 months ago |
Hugo Thunnissen | 67fd01e68d | 10 months ago |
Hugo Thunnissen | fc46349bfe | 10 months ago |
Hugo Thunnissen | 4abc3f405a | 10 months ago |
Hugo Thunnissen | 8e612d76e5 | 10 months ago |
Hugo Thunnissen | 0f24f7577f | 10 months ago |
Hugo Thunnissen | 92ae43fe6e | 10 months ago |
Hugo Thunnissen | 292b4ca123 | 10 months ago |
Hugo Thunnissen | 35a89eb554 | 10 months ago |
Hugo Thunnissen | 0f2045b107 | 10 months ago |
Hugo Thunnissen | a748f32629 | 10 months ago |
Hugo Thunnissen | 0deb528df1 | 10 months ago |
Hugo Thunnissen | feb92c2025 | 10 months ago |
Hugo Thunnissen | 5e5b73e47d | 10 months ago |
Hugo Thunnissen | dfb59591ae | 10 months ago |
Hugo Thunnissen | 93f6c702c5 | 10 months ago |
Hugo Thunnissen | f3a5e1d658 | 10 months ago |
Hugo Thunnissen | 2e6edd70b2 | 10 months ago |
Hugo Thunnissen | bab8deba01 | 10 months ago |
Hugo Thunnissen | 08d80d3a38 | 10 months ago |
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,70 @@
|
||||
|
||||
(require 'phpinspect-parser)
|
||||
|
||||
|
||||
(defun phpinspect-parse-current-buffer ()
|
||||
(phpinspect-parse-buffer-until-point
|
||||
(current-buffer)
|
||||
(point-max)))
|
||||
|
||||
|
||||
(let ((here (file-name-directory (or load-file-name buffer-file-name))))
|
||||
|
||||
(with-temp-buffer
|
||||
;; (setq-local phpinspect-current-buffer (phpinspect-make-buffer :buffer (current-buffer)))
|
||||
|
||||
(insert-file-contents (concat here "/Response.php"))
|
||||
|
||||
(message "Incremental parse (warmup):")
|
||||
(phpinspect-with-parse-context (phpinspect-make-pctx :incremental t)
|
||||
(benchmark 1 '(phpinspect-parse-current-buffer)))
|
||||
|
||||
(let ((bmap (phpinspect-make-bmap))
|
||||
(bmap2 (phpinspect-make-bmap)))
|
||||
(message "Incremental parse:")
|
||||
(phpinspect-with-parse-context (phpinspect-make-pctx :incremental t :bmap bmap)
|
||||
(benchmark 1 '(phpinspect-parse-current-buffer)))
|
||||
|
||||
(message "Incremental parse (no edits):")
|
||||
(phpinspect-with-parse-context (phpinspect-make-pctx :incremental t :bmap bmap2 :previous-bmap bmap :edtrack (phpinspect-make-edtrack))
|
||||
(benchmark 1 '(phpinspect-parse-current-buffer)))
|
||||
|
||||
(message "Incremental parse repeat (no edits):")
|
||||
(phpinspect-with-parse-context (phpinspect-make-pctx :incremental t :previous-bmap bmap2 :edtrack (phpinspect-make-edtrack))
|
||||
(benchmark 1 '(phpinspect-parse-current-buffer)))
|
||||
|
||||
(let ((edtrack (phpinspect-make-edtrack))
|
||||
(bmap (phpinspect-make-bmap)))
|
||||
;; Fresh
|
||||
(phpinspect-with-parse-context (phpinspect-make-pctx :incremental t :bmap bmap)
|
||||
(phpinspect-parse-current-buffer))
|
||||
|
||||
(message "Incremental parse after buffer edit:")
|
||||
;; Removes closing curly brace of __construct
|
||||
(goto-char 9062)
|
||||
(delete-backward-char 1)
|
||||
|
||||
(phpinspect-edtrack-register-edit edtrack 9061 9061 1)
|
||||
(phpinspect-with-parse-context (phpinspect-make-pctx :incremental t :previous-bmap bmap :edtrack edtrack)
|
||||
(benchmark 1 '(phpinspect-parse-current-buffer)))))
|
||||
|
||||
|
||||
|
||||
|
||||
;; (message "Metadata parse:")
|
||||
;; (benchmark 1 '(phpinspect-buffer-parse phpinspect-current-buffer))
|
||||
|
||||
(message "Bare (no token reuse) parse (warmup):")
|
||||
(benchmark 1 '(phpinspect-parse-current-buffer))
|
||||
|
||||
|
||||
(message "Bare (no token reuse) parse:")
|
||||
(benchmark 1 '(phpinspect-parse-current-buffer))))
|
||||
|
||||
|
||||
;; (goto-char (floor (/ (point-max) 2 )))
|
||||
;; (insert "abc")
|
||||
;; (phpinspect-buffer-register-edit phpinspect-current-buffer (- (point) 3) (point) 0)
|
||||
|
||||
;; (message "Metadata parse incremental:")
|
||||
;; (benchmark 1 '(phpinspect-buffer-parse phpinspect-current-buffer))))
|
@ -0,0 +1,359 @@
|
||||
;;; phpinspect-bmap.el --- PHP parsing and completion package -*- lexical-binding: t; -*-
|
||||
|
||||
;; Copyright (C) 2021 Free Software Foundation, Inc
|
||||
|
||||
;; Author: Hugo Thunnissen <devel@hugot.nl>
|
||||
;; Keywords: php, languages, tools, convenience
|
||||
;; Version: 0
|
||||
|
||||
;; This program is free software; you can redistribute it and/or modify
|
||||
;; it under the terms of the GNU General Public License as published by
|
||||
;; the Free Software Foundation, either version 3 of the License, or
|
||||
;; (at your option) any later version.
|
||||
|
||||
;; This program is distributed in the hope that it will be useful,
|
||||
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
;; GNU General Public License for more details.
|
||||
|
||||
;; You should have received a copy of the GNU General Public License
|
||||
;; along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
;;; Commentary:
|
||||
|
||||
;;; Code:
|
||||
|
||||
(cl-defstruct (phpinspect-bmap (:constructor phpinspect-make-bmap))
|
||||
(starts (make-hash-table :test #'eql
|
||||
:size (floor (/ (point-max) 4))
|
||||
:rehash-size 1.5))
|
||||
(ends (make-hash-table :test #'eql
|
||||
:size (floor (/ (point-max) 4))
|
||||
:rehash-size 1.5))
|
||||
(meta (make-hash-table :test #'eq
|
||||
:size (floor (/ (point-max) 4))
|
||||
:rehash-size 1.5))
|
||||
(token-stack nil
|
||||
:type list)
|
||||
(overlays nil
|
||||
:type list)
|
||||
(last-token-start nil
|
||||
:type integer))
|
||||
|
||||
(defsubst phpinspect-make-region (start end)
|
||||
(list start end))
|
||||
|
||||
(defalias 'phpinspect-region-start #'car)
|
||||
(defalias 'phpinspect-region-end #'cadr)
|
||||
|
||||
(defsubst phpinspect-region-size (region)
|
||||
(- (phpinspect-region-end region) (phpinspect-region-start region)))
|
||||
|
||||
(defsubst phpinspect-region> (reg1 reg2)
|
||||
(> (phpinspect-region-size reg1) (phpinspect-region-size reg2)))
|
||||
|
||||
(defsubst phpinspect-region< (reg1 reg2)
|
||||
(< (phpinspect-region-size reg1) (phpinspect-region-size reg2)))
|
||||
|
||||
(defsubst phpinspect-region-overlaps-point (reg point)
|
||||
(and (> (phpinspect-region-end reg) point)
|
||||
(<= (phpinspect-region-start reg) point)))
|
||||
|
||||
(defsubst phpinspect-region-overlaps (reg1 reg2)
|
||||
(or (phpinspect-region-reg2s-point reg1 (phpinspect-region-start reg2))
|
||||
(phpinspect-region-reg2s-point reg1 (- (phpinspect-region-end reg2) 1))
|
||||
(phpinspect-region-reg2s-point reg2 (phpinspect-region-start reg1))
|
||||
(phpinspect-region-reg2s-point reg2 (- (phpinspect-region-end reg1) 1))))
|
||||
|
||||
(defsubst phpinspect-region-encloses (reg1 reg2)
|
||||
(and (<= (phpinspect-region-start reg1) (phpinspect-region-start reg2))
|
||||
(>= (phpinspect-region-end reg1) (phpinspect-region-end reg2))))
|
||||
|
||||
(defsubst phpinspect-make-meta (parent start end whitespace-before token &optional overlay right-siblings)
|
||||
(list 'meta parent start end whitespace-before token overlay right-siblings))
|
||||
|
||||
(defsubst phpinspect-meta-parent (meta)
|
||||
(cadr meta))
|
||||
|
||||
(gv-define-setter phpinspect-meta-end (end meta) `(setcar (cdddr ,meta) ,end))
|
||||
(gv-define-setter phpinspect-meta-start (start meta) `(setcar (cddr ,meta) ,start))
|
||||
(gv-define-setter phpinspect-meta-overlay (overlay meta) `(setcar (nthcdr 6 ,meta) ,overlay))
|
||||
(gv-define-setter phpinspect-meta-parent (parent meta) `(setcar (cdr ,meta) ,parent))
|
||||
(gv-define-setter phpinspect-meta-right-siblings (siblings meta) `(setcar (nthcdr 7 ,meta) ,siblings))
|
||||
|
||||
(defsubst phpinspect-meta-right-siblings (meta)
|
||||
(car (nthcdr 7 meta)))
|
||||
|
||||
(defsubst phpinspect-meta-overlay (meta)
|
||||
(car (nthcdr 6 meta)))
|
||||
|
||||
(defsubst phpinspect-meta-token (meta)
|
||||
(car (nthcdr 5 meta)))
|
||||
|
||||
(defsubst phpinspect-meta-end (meta)
|
||||
(cadddr meta))
|
||||
|
||||
(defsubst phpinspect-meta-width (meta)
|
||||
(- (phpinspect-meta-end meta) (phpinspect-meta-start meta)))
|
||||
|
||||
(defun phpinspect-meta-sort-width (meta1 meta2)
|
||||
(< (phpinspect-meta-width meta1) (phpinspect-meta-width meta2)))
|
||||
|
||||
(defsubst phpinspect-meta-start (meta)
|
||||
(caddr meta))
|
||||
|
||||
(defsubst phpinspect-meta-overlaps-point (meta point)
|
||||
(and (> (phpinspect-meta-end meta) point)
|
||||
(<= (phpinspect-meta-start meta) point)))
|
||||
|
||||
(defsubst phpinspect-meta-find-parent-matching-token (meta predicate)
|
||||
(if (funcall predicate (phpinspect-meta-token meta))
|
||||
meta
|
||||
(catch 'found
|
||||
(while (phpinspect-meta-parent meta)
|
||||
(setq meta (phpinspect-meta-parent meta))
|
||||
(when (funcall predicate (phpinspect-meta-token meta))
|
||||
(throw 'found meta))))))
|
||||
|
||||
(gv-define-setter phpinspect-overlay-end (end overlay) `(setcar (cddr ,overlay) ,end))
|
||||
(gv-define-setter phpinspect-overlay-start (start overlay) `(setcar (cdr ,overlay) ,start))
|
||||
(gv-define-setter phpinspect-overlay-delta (delta overlay) `(setcar (cdddr ,overlay) ,delta))
|
||||
|
||||
(defsubst phpinspect-overlay-bmap (overlay)
|
||||
(car (nthcdr 4 overlay)))
|
||||
|
||||
(defsubst phpinspect-overlay-delta (overlay)
|
||||
(cadddr overlay))
|
||||
|
||||
(defsubst phpinspect-overlay-start (overlay)
|
||||
(cadr overlay))
|
||||
|
||||
(defsubst phpinspect-overlay-end (overlay)
|
||||
(caddr overlay))
|
||||
|
||||
(defsubst phpinspect-overlay-token-meta (overlay)
|
||||
(car (nthcdr 5 overlay)))
|
||||
|
||||
(defsubst phpinspect-overlay-overlaps-point (overlay point)
|
||||
(and (> (phpinspect-overlay-end 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)
|
||||
(,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))
|
||||
(bmap-stack (gensym))
|
||||
(_ignored (gensym))
|
||||
(overlay-start (gensym))
|
||||
(overlay-end (gensym)))
|
||||
`(let ((,bmap-stack (list ,(cadr place-and-bmap)))
|
||||
(,bmap))
|
||||
(while (setq ,bmap (pop ,bmap-stack))
|
||||
(if (phpinspect-overlay-p ,bmap)
|
||||
(let ((,overlay-start (phpinspect-overlay-start ,bmap))
|
||||
(,overlay-end (phpinspect-overlay-end ,bmap)))
|
||||
(maphash (lambda (,_ignored ,place)
|
||||
(setq ,place (phpinspect-overlay-wrap-meta ,bmap ,place))
|
||||
(when (and (<= ,overlay-start
|
||||
(phpinspect-meta-start ,place))
|
||||
(>= ,overlay-end
|
||||
(phpinspect-meta-end ,place)))
|
||||
(if (phpinspect-meta-overlay ,place)
|
||||
(push (phpinspect-meta-overlay ,place) ,bmap-stack)
|
||||
,@body)))
|
||||
(phpinspect-bmap-meta (phpinspect-overlay-bmap ,bmap))))
|
||||
(maphash (lambda (,_ignored ,place)
|
||||
(if (phpinspect-meta-overlay ,place)
|
||||
(push (phpinspect-meta-overlay ,place) ,bmap-stack)
|
||||
,@body))
|
||||
(phpinspect-bmap-meta ,bmap)))))))
|
||||
|
||||
(defsubst phpinspect-bmap-register (bmap start end token &optional whitespace-before overlay)
|
||||
(let* ((starts (phpinspect-bmap-starts bmap))
|
||||
(ends (phpinspect-bmap-ends bmap))
|
||||
(meta (phpinspect-bmap-meta bmap))
|
||||
(last-token-start (phpinspect-bmap-last-token-start bmap))
|
||||
(existing-end (gethash end ends))
|
||||
(token-meta (phpinspect-make-meta nil start end whitespace-before token overlay)))
|
||||
(unless whitespace-before
|
||||
(setq whitespace-before ""))
|
||||
|
||||
(puthash start token-meta starts)
|
||||
|
||||
(if existing-end
|
||||
(push token existing-end)
|
||||
(puthash end (list token-meta) ends))
|
||||
|
||||
(puthash token token-meta meta)
|
||||
|
||||
(when (and last-token-start
|
||||
(<= start last-token-start))
|
||||
(let ((child)
|
||||
(stack (phpinspect-bmap-token-stack bmap))
|
||||
(right-siblings))
|
||||
|
||||
(while (and (car stack) (>= (phpinspect-meta-start (car stack))
|
||||
start))
|
||||
(setq child (pop stack))
|
||||
(setf (phpinspect-meta-parent child) token-meta)
|
||||
(when (phpinspect-meta-overlay child)
|
||||
(setf (phpinspect-meta-parent
|
||||
(phpinspect-overlay-token-meta
|
||||
(phpinspect-meta-overlay child)))
|
||||
token-meta))
|
||||
|
||||
(setf (phpinspect-meta-right-siblings child) right-siblings)
|
||||
(when (phpinspect-meta-overlay child)
|
||||
(setf (phpinspect-meta-right-siblings
|
||||
(phpinspect-overlay-token-meta
|
||||
(phpinspect-meta-overlay child)))
|
||||
right-siblings))
|
||||
(push (phpinspect-meta-token child) right-siblings))
|
||||
|
||||
(setf (phpinspect-bmap-token-stack bmap) stack)))
|
||||
|
||||
(setf (phpinspect-bmap-last-token-start bmap) start)
|
||||
(push token-meta (phpinspect-bmap-token-stack bmap))))
|
||||
|
||||
(defsubst phpinspect-overlay-p (overlay)
|
||||
(and (listp overlay)
|
||||
(eq 'overlay (car overlay))))
|
||||
|
||||
(defsubst phpinspect-overlay-wrap-meta (overlay meta)
|
||||
(when meta
|
||||
(setq meta (cl-copy-list meta))
|
||||
(setf (phpinspect-meta-start meta)
|
||||
(+ (phpinspect-meta-start meta) (phpinspect-overlay-delta overlay)))
|
||||
(setf (phpinspect-meta-end meta)
|
||||
(+ (phpinspect-meta-end meta) (phpinspect-overlay-delta overlay)))
|
||||
|
||||
(when (phpinspect-meta-overlay meta)
|
||||
(let ((meta-overlay (cl-copy-list (phpinspect-meta-overlay meta))))
|
||||
(setf (phpinspect-overlay-start meta-overlay)
|
||||
(+ (phpinspect-overlay-start meta-overlay)
|
||||
(phpinspect-overlay-delta overlay)))
|
||||
(setf (phpinspect-overlay-end meta-overlay)
|
||||
(+ (phpinspect-overlay-end meta-overlay)
|
||||
(phpinspect-overlay-delta overlay)))
|
||||
(setf (phpinspect-overlay-delta meta-overlay)
|
||||
(+ (phpinspect-overlay-delta meta-overlay)
|
||||
(phpinspect-overlay-delta overlay)))
|
||||
(setf (phpinspect-meta-overlay meta) meta-overlay)))
|
||||
|
||||
meta))
|
||||
|
||||
(cl-defmethod phpinspect-bmap-token-starting-at ((overlay (head overlay)) point)
|
||||
(phpinspect-overlay-wrap-meta
|
||||
overlay
|
||||
(phpinspect-bmap-token-starting-at
|
||||
(phpinspect-overlay-bmap overlay) (- point (phpinspect-overlay-delta overlay)))))
|
||||
|
||||
(cl-defmethod phpinspect-bmap-token-starting-at ((bmap phpinspect-bmap) point)
|
||||
(let ((overlay (phpinspect-bmap-overlay-at-point bmap point)))
|
||||
(if overlay
|
||||
(phpinspect-bmap-token-starting-at overlay point)
|
||||
(gethash point (phpinspect-bmap-starts bmap)))))
|
||||
|
||||
(cl-defmethod phpinspect-bmap-tokens-ending-at ((overlay (head overlay)) point)
|
||||
(mapcar (lambda (meta) (phpinspect-overlay-wrap-meta overlay meta))
|
||||
(phpinspect-bmap-tokens-ending-at
|
||||
(phpinspect-overlay-bmap overlay) (- point (phpinspect-overlay-delta overlay)))))
|
||||
|
||||
(cl-defmethod phpinspect-bmap-tokens-ending-at ((bmap phpinspect-bmap) point)
|
||||
(let ((overlay (phpinspect-bmap-overlay-at-point bmap point)))
|
||||
(if overlay
|
||||
(phpinspect-bmap-tokens-ending-at overlay point)
|
||||
(gethash point (phpinspect-bmap-ends bmap)))))
|
||||
|
||||
(defsubst phpinspect-bmap-overlay-at-point (bmap point)
|
||||
(catch 'found
|
||||
(dolist (overlay (phpinspect-bmap-overlays bmap))
|
||||
(when (phpinspect-overlay-overlaps-point overlay point)
|
||||
(throw 'found overlay)))))
|
||||
|
||||
(defsubst phpinspect-bmap-tokens-overlapping (bmap point)
|
||||
(let ((tokens))
|
||||
(phpinspect-bmap-iterate (meta bmap)
|
||||
(when (phpinspect-meta-overlaps-point meta point)
|
||||
(push meta tokens)))
|
||||
|
||||
(sort tokens #'phpinspect-meta-sort-width)))
|
||||
|
||||
(cl-defmethod phpinspect-bmap-token-meta ((overlay (head overlay)) token)
|
||||
(phpinspect-bmap-token-meta (phpinspect-overlay-bmap overlay) token))
|
||||
|
||||
(cl-defmethod phpinspect-bmap-token-meta ((bmap phpinspect-bmap) token)
|
||||
(or (gethash token (phpinspect-bmap-meta bmap))
|
||||
(let ((found?))
|
||||
(catch 'found
|
||||
(dolist (overlay (phpinspect-bmap-overlays bmap))
|
||||
(when (setq found? (phpinspect-bmap-token-meta overlay token))
|
||||
(throw 'found found?)))))))
|
||||
|
||||
(defsubst phpinspect-probably-token-p (token)
|
||||
(and (listp token)
|
||||
(symbolp (car token))))
|
||||
|
||||
(defsubst phpinspect-bmap-last-token-before-point (bmap point)
|
||||
(let* ((ends (phpinspect-bmap-ends bmap))
|
||||
(ending))
|
||||
(unless (hash-table-empty-p ends)
|
||||
(while (not (or (<= point 0) (setq ending (phpinspect-bmap-tokens-ending-at bmap point))))
|
||||
(setq point (- point 1)))
|
||||
(car (last ending)))))
|
||||
|
||||
(defsubst phpinspect-bmap-overlay (bmap bmap-overlay token-meta pos-delta &optional whitespace-before)
|
||||
(let* ((overlays (phpinspect-bmap-overlays bmap))
|
||||
(start (+ (phpinspect-meta-start token-meta) pos-delta))
|
||||
(end (+ (phpinspect-meta-end token-meta) pos-delta))
|
||||
(overlay `(overlay ,start ,end ,pos-delta ,bmap-overlay ,token-meta))
|
||||
(before))
|
||||
(phpinspect-bmap-register bmap start end (phpinspect-meta-token token-meta) whitespace-before overlay)
|
||||
|
||||
(if overlays
|
||||
(progn
|
||||
(catch 'break
|
||||
(while (setq before (car overlays))
|
||||
(if (> (phpinspect-overlay-start overlay) (phpinspect-overlay-end before))
|
||||
(throw 'break nil)
|
||||
(setq overlays (cdr overlays)))))
|
||||
|
||||
(if (and before (cdr overlays))
|
||||
;; Append after
|
||||
(progn
|
||||
(setcdr overlays (cons overlay (cdr overlays))))
|
||||
;; Append at end of overlay list
|
||||
(nconc (phpinspect-bmap-overlays bmap) (list overlay))))
|
||||
|
||||
;; No exising overlays, overwrite
|
||||
(push overlay (phpinspect-bmap-overlays bmap)))))
|
||||
|
||||
(defun phpinspect-bmap-make-location-resolver (bmap)
|
||||
(lambda (token)
|
||||
(let ((meta (phpinspect-bmap-token-meta bmap token)))
|
||||
(if meta
|
||||
(phpinspect-make-region (phpinspect-meta-start meta)
|
||||
(phpinspect-meta-end meta))
|
||||
(phpinspect-make-region 0 0)))))
|
||||
|
||||
(provide 'phpinspect-bmap)
|
||||
;;; phpinspect-bmap.el ends here
|
@ -0,0 +1,198 @@
|
||||
;;; phpinspect-edtrack.el --- PHP parsing and completion package -*- lexical-binding: t; -*-
|
||||
|
||||
;; Copyright (C) 2021 Free Software Foundation, Inc
|
||||
|
||||
;; Author: Hugo Thunnissen <devel@hugot.nl>
|
||||
;; Keywords: php, languages, tools, convenience
|
||||
;; Version: 0
|
||||
|
||||
;; This program is free software; you can redistribute it and/or modify
|
||||
;; it under the terms of the GNU General Public License as published by
|
||||
;; the Free Software Foundation, either version 3 of the License, or
|
||||
;; (at your option) any later version.
|
||||
|
||||
;; This program is distributed in the hope that it will be useful,
|
||||
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
;; GNU General Public License for more details.
|
||||
|
||||
;; You should have received a copy of the GNU General Public License
|
||||
;; along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
;;; Commentary:
|
||||
|
||||
;;; Code:
|
||||
|
||||
(cl-defstruct (phpinspect-edtrack (:constructor phpinspect-make-edtrack))
|
||||
(edits nil
|
||||
:type list)
|
||||
(taint-pool nil
|
||||
:type list))
|
||||
|
||||
(defsubst phpinspect-edtrack-make-taint-iterator (track)
|
||||
(cons (car (phpinspect-edtrack-taint-pool track))
|
||||
(cl-copy-list (cdr (phpinspect-edtrack-taint-pool track)))))
|
||||
|
||||
(gv-define-setter phpinspect-taint-iterator-current (current iter) `(setcar ,iter ,current))
|
||||
|
||||
(defsubst phpinspect-taint-iterator-current (iter)
|
||||
(car iter))
|
||||
|
||||
(defsubst phpinspect-taint-iterator-follow (iter pos)
|
||||
(or (while (and (phpinspect-taint-iterator-current iter)
|
||||
(> pos (phpinspect-taint-end
|
||||
(phpinspect-taint-iterator-current iter))))
|
||||
(setf (phpinspect-taint-iterator-current iter) (pop (cdr iter))))
|
||||
(phpinspect-taint-iterator-current iter)))
|
||||
|
||||
(defsubst phpinspect-taint-iterator-token-is-tainted-p (iter meta)
|
||||
(and (phpinspect-taint-iterator-follow iter (phpinspect-meta-start meta))
|
||||
(phpinspect-taint-overlaps-meta
|
||||
(phpinspect-taint-iterator-current iter) meta)))
|
||||
|
||||
(defsubst phpinspect-taint-iterator-region-is-tainted-p (iter start end)
|
||||
(and (phpinspect-taint-iterator-follow iter start)
|
||||
(phpinspect-taint-overlaps-region
|
||||
(phpinspect-taint-iterator-current iter) start end)))
|
||||
|
||||
(defsubst phpinspect-edit-original-end (edit)
|
||||
(or (caar edit) 0))
|
||||
|
||||
(defsubst phpinspect-edit-end (edit)
|
||||
(if edit
|
||||
(let ((end (or (caar edit) 0))
|
||||
(delta 0)
|
||||
(previous-edit (cdr edit)))
|
||||
(+ end (phpinspect-edit-delta previous-edit)))))
|
||||
|
||||
(defsubst phpinspect-edit-delta (edit)
|
||||
(let ((delta (or (cdar edit) 0))
|
||||
(previous-edit edit))
|
||||
(while (setq previous-edit (cdr previous-edit))
|
||||
(setq delta (+ delta (cdar previous-edit))))
|
||||
delta))
|
||||
|
||||
(defsubst phpinspect-edtrack-original-position-at-point (track point)
|
||||
(let ((edit (phpinspect-edtrack-edits track)))
|
||||
(while (and edit (< point (phpinspect-edit-end edit)))
|
||||
(setq edit (cdr edit)))
|
||||
|
||||
(- point (phpinspect-edit-delta edit))))
|
||||
|
||||
(defsubst phpinspect-edtrack-current-position-at-point (track point)
|
||||
(let ((edit (phpinspect-edtrack-edits track)))
|
||||
(while (and edit (< point (phpinspect-edit-original-end edit)))
|
||||
(setq edit (cdr edit)))
|
||||
|
||||
(+ point (phpinspect-edit-delta edit))))
|
||||
|
||||
(defsubst phpinspect-edtrack-register-edit (track start end pre-change-length)
|
||||
(let ((edit-before (phpinspect-edtrack-edits track)))
|
||||
(while (and edit-before (< end (phpinspect-edit-end edit-before)))
|
||||
(setq edit-before (cdr edit-before)))
|
||||
|
||||
(phpinspect-edtrack-register-taint
|
||||
track
|
||||
(phpinspect-edtrack-original-position-at-point track start)
|
||||
(phpinspect-edtrack-original-position-at-point track end))
|
||||
|
||||
(let* ((new-edit (cons
|
||||
;; The end location of the edited region, before being
|
||||
;; edited, with the delta edits that happened at preceding
|
||||
;; points in the buffer subtratted. This corresponds with
|
||||
;; the original position of the region end before the
|
||||
;; buffer was ever edited.
|
||||
(- (+ start pre-change-length) (or (phpinspect-edit-delta edit-before) 0))
|
||||
|
||||
;; The delta of this edit.
|
||||
(- (- end start) pre-change-length))))
|
||||
(if edit-before
|
||||
(progn
|
||||
(setcdr edit-before (cons (car edit-before) (cdr edit-before)))
|
||||
(setcar edit-before new-edit))
|
||||
(if (phpinspect-edtrack-edits track)
|
||||
(push new-edit (cdr (last (phpinspect-edtrack-edits track))))
|
||||
(push new-edit (phpinspect-edtrack-edits track)))))))
|
||||
|
||||
(defsubst phpinspect-taint-start (taint)
|
||||
(car taint))
|
||||
|
||||
(defsubst phpinspect-taint-end (taint)
|
||||
(cdr taint))
|
||||
|
||||
(defsubst phpinspect-make-taint (start end)
|
||||
(cons start end))
|
||||
|
||||
(defsubst phpinspect-taint-overlaps-point (taint point)
|
||||
(and (> (phpinspect-taint-end taint) point)
|
||||
(<= (phpinspect-taint-start taint) point)))
|
||||
|
||||
(defsubst phpinspect-taint-overlaps-region (taint start end)
|
||||
(or (phpinspect-taint-overlaps-point taint start)
|
||||
(phpinspect-taint-overlaps-point taint end)
|
||||
(and (> end (phpinspect-taint-start taint))
|
||||
(<= start (phpinspect-taint-start taint)))
|
||||
(and (> end (phpinspect-taint-end taint))
|
||||
(<= start (phpinspect-taint-end taint)))))
|
||||
|
||||
(defsubst phpinspect-taint-overlaps (taint1 taint2)
|
||||
(or (phpinspect-taint-overlaps-point taint1 (phpinspect-taint-start taint2))
|
||||
(phpinspect-taint-overlaps-point taint1 (phpinspect-taint-end taint2))
|
||||
(phpinspect-taint-overlaps-point taint2 (phpinspect-taint-start taint1))
|
||||
(phpinspect-taint-overlaps-point taint2 (phpinspect-taint-end taint1))))
|
||||
|
||||
(defsubst phpinspect-taint-overlaps-meta (taint meta)
|
||||
(or (phpinspect-taint-overlaps-point taint (phpinspect-meta-start meta))
|
||||
(phpinspect-taint-overlaps-point taint (phpinspect-meta-end meta))
|
||||
(phpinspect-meta-overlaps-point meta (phpinspect-taint-start taint))
|
||||
(phpinspect-meta-overlaps-point meta (phpinspect-taint-end taint))))
|
||||
|
||||
(defsubst phpinspect-edtrack-clear-taint-pool (track)
|
||||
(setf (phpinspect-edtrack-taint-pool track) nil))
|
||||
|
||||
(defsubst phpinspect-edtrack-clear (track)
|
||||
(setf (phpinspect-edtrack-edits track) nil)
|
||||
(phpinspect-edtrack-clear-taint-pool track))
|
||||
|
||||
(defsubst phpinspect-edtrack-register-taint (track start end)
|
||||
(let ((pool (phpinspect-edtrack-taint-pool track))
|
||||
(idx 0)
|
||||
(overlap-start)
|
||||
(overlap-end)
|
||||
(left-neighbour)
|
||||
(taint (phpinspect-make-taint start end)))
|
||||
(catch 'break
|
||||
(while pool
|
||||
(if (phpinspect-taint-overlaps taint (car pool))
|
||||
(progn
|
||||
(when (< (phpinspect-taint-start (car pool)) start)
|
||||
(setcar taint (phpinspect-taint-start (car pool))))
|
||||
(when (> (phpinspect-taint-end (car pool)) end)
|
||||
(setcdr taint (phpinspect-taint-end (car pool))))
|
||||
|
||||
(when (not overlap-start)
|
||||
(setq overlap-start idx))
|
||||
(setq overlap-end idx))
|
||||
|
||||
;; Else
|
||||
(when overlap-start
|
||||
(throw 'break nil))
|
||||
|
||||
(when (> start (phpinspect-taint-end (car pool)))
|
||||
(setq left-neighbour pool)
|
||||
(throw 'break nil)))
|
||||
|
||||
(setq pool (cdr pool)
|
||||
idx (+ idx 1))))
|
||||
|
||||
(cond (overlap-start
|
||||
(setq pool (phpinspect-edtrack-taint-pool track))
|
||||
(setcar (nthcdr overlap-start pool) taint)
|
||||
(setcdr (nthcdr overlap-start pool) (nthcdr (+ 1 overlap-end) pool)))
|
||||
(left-neighbour
|
||||
(setcdr left-neighbour (cons taint (cdr left-neighbour))))
|
||||
(t
|
||||
(push taint (phpinspect-edtrack-taint-pool track))))))
|
||||
|
||||
(provide 'phpinspect-edtrack)
|
||||
;;; phpinspect-edtrack.el ends here
|
@ -0,0 +1,105 @@
|
||||
|
||||
|
||||
(cl-defstruct (phpinspect-queue-item
|
||||
(:constructor phpinspect-make-queue-item))
|
||||
(next nil
|
||||
:type phpinspect-queue-item
|
||||
:documentation
|
||||
"The next item in the queue")
|
||||
(thing nil
|
||||
:type any
|
||||
:documentation
|
||||
"The thing stored in the queue")
|
||||
(previous nil
|
||||
:type phpinspect-queue-item
|
||||
:documentation
|
||||
"The previous item in the queue")
|
||||
(subscription nil
|
||||
:type function
|
||||
:read-only t
|
||||
:documentation
|
||||
"A function that should be called when items are
|
||||
enqueued."))
|
||||
|
||||
(defsubst phpinspect-make-queue (&optional subscription)
|
||||
(phpinspect-make-queue-item :subscription subscription))
|
||||
|
||||
;; Recursion causes max-eval-depth error here for long queues. Hence the loop
|
||||
;; implementation for these two functions.
|
||||
(cl-defmethod phpinspect-queue-last ((item phpinspect-queue-item))
|
||||
"Get the last item in the queue that ITEM is part of."
|
||||
(while (phpinspect-queue-item-next item)
|
||||
(setq item (phpinspect-queue-item-next item)))
|
||||
item)
|
||||
|
||||
(cl-defmethod phpinspect-queue-first ((item phpinspect-queue-item))
|
||||
"Get the first item in the queue that ITEM is part of."
|
||||
(while (phpinspect-queue-item-previous item)
|
||||
(setq item (phpinspect-queue-item-previous item)))
|
||||
item)
|
||||
|
||||
(cl-defmethod phpinspect-queue-enqueue ((item phpinspect-queue-item) thing)
|
||||
"Add THING to the end of the queue that ITEM is part of."
|
||||
(let ((last (phpinspect-queue-last item)))
|
||||
(if (not (phpinspect-queue-item-thing last))
|
||||
(setf (phpinspect-queue-item-thing last) thing)
|
||||
(setf (phpinspect-queue-item-next last)
|
||||
(phpinspect-make-queue-item
|
||||
:previous last
|
||||
:thing thing
|
||||
:subscription (phpinspect-queue-item-subscription item)))))
|
||||
(when (phpinspect-queue-item-subscription item)
|
||||
(funcall (phpinspect-queue-item-subscription item))))
|
||||
|
||||
(cl-defmethod phpinspect-queue-dequeue ((item phpinspect-queue-item))
|
||||
"Remove the thing at the front of the queue that ITEM is part of and return it."
|
||||
(let* ((first (phpinspect-queue-first item))
|
||||
(thing (phpinspect-queue-item-thing first))
|
||||
(next (phpinspect-queue-item-next first)))
|
||||
(when next (setf (phpinspect-queue-item-previous next) nil))
|
||||
(cond ((and (eq item first) (not next))
|
||||
(setf (phpinspect-queue-item-thing item)
|
||||
nil))
|
||||
((eq item first)
|
||||
(setf (phpinspect-queue-item-thing item)
|
||||
(phpinspect-queue-item-thing next))
|
||||
(setf (phpinspect-queue-item-next item)
|
||||
(phpinspect-queue-item-next next))))
|
||||
thing))
|
||||
|
||||
(defmacro phpinspect-doqueue (place-and-queue &rest body)
|
||||
"Loop over queue defined in PLACE-AND-QUEUE executing BODY.
|
||||
|
||||
PLACE-AND-QUEUE is a two-member list. The first item should be
|
||||
the place that the current thing in the queue should be assigned
|
||||
to upon each iteration. The second item should be a queue-item
|
||||
belonging to the queue that must be iterated over.
|
||||
|
||||
BODY can be any form."
|
||||
(declare (indent defun))
|
||||
(let ((item-sym (gensym))
|
||||
(place (car place-and-queue))
|
||||
(queue (cadr place-and-queue)))
|
||||
`(let* ((,item-sym (phpinspect-queue-first ,queue))
|
||||
(,place (phpinspect-queue-item-thing ,item-sym)))
|
||||
(when ,place
|
||||
,@body
|
||||
(while (setq ,item-sym (phpinspect-queue-item-next ,item-sym))
|
||||
(setq ,place (phpinspect-queue-item-thing ,item-sym))
|
||||
,@body)))))
|
||||
|
||||
(cl-defmethod phpinspect-queue-find
|
||||
((item phpinspect-queue-item) thing comparison-func)
|
||||
"Find THING in the queue that ITEM is part of using COMPARISON-FUNC."
|
||||
(catch 'found
|
||||
(phpinspect-doqueue (current-thing item)
|
||||
(when (funcall comparison-func current-thing thing)
|
||||
(throw 'found current-thing)))))
|
||||
|
||||
(cl-defmethod phpinspect-queue-enqueue-noduplicate
|
||||
((item phpinspect-queue-item) thing comparison-func)
|
||||
|
||||
(when (not (phpinspect-queue-find item thing comparison-func))
|
||||
(phpinspect-queue-enqueue item thing)))
|
||||
|
||||
(provide 'phpinspect-queue)
|
@ -0,0 +1,176 @@
|
||||
;;; phpinspect-resolvecontext.el --- PHP parsing and completion package -*- lexical-binding: t; -*-
|
||||
|
||||
;; Copyright (C) 2021 Free Software Foundation, Inc
|
||||
|
||||
;; Author: Hugo Thunnissen <devel@hugot.nl>
|
||||
;; Keywords: php, languages, tools, convenience
|
||||
;; Version: 0
|
||||
|
||||
;; This program is free software; you can redistribute it and/or modify
|
||||
;; it under the terms of the GNU General Public License as published by
|
||||
;; the Free Software Foundation, either version 3 of the License, or
|
||||
;; (at your option) any later version.
|
||||
|
||||
;; This program is distributed in the hope that it will be useful,
|
||||
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
;; GNU General Public License for more details.
|
||||
|
||||
;; You should have received a copy of the GNU General Public License
|
||||
;; along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
;;; Commentary:
|
||||
|
||||
;;; Code:
|
||||
|
||||
(require 'phpinspect-bmap)
|
||||
(require 'phpinspect-project)
|
||||
(require 'phpinspect-parser)
|
||||
(require 'phpinspect-type)
|
||||
|
||||
(cl-defstruct (phpinspect--resolvecontext
|
||||
(:constructor phpinspect--make-resolvecontext))
|
||||
(subject nil
|
||||
:type phpinspect--token
|
||||
:documentation
|
||||
"The statement we're trying to resolve the type of.")
|
||||
(project-root nil
|
||||
:type string
|
||||
:documentation
|
||||
"The root directory of the project we're resolving types for.")
|
||||
(enclosing-tokens nil
|
||||
:type list
|
||||
:documentation
|
||||
"Tokens that enclose the subject."))
|
||||
|
||||
(cl-defmethod phpinspect--resolvecontext-push-enclosing-token
|
||||
((resolvecontext phpinspect--resolvecontext) enclosing-token)
|
||||
"Add ENCLOSING-TOKEN to RESOLVECONTEXTs enclosing token stack."
|
||||
(push enclosing-token (phpinspect--resolvecontext-enclosing-tokens
|
||||
resolvecontext)))
|
||||
|
||||
(defsubst phpinspect-blocklike-p (token)
|
||||
(or (phpinspect-block-p token)
|
||||
(phpinspect-function-p token)
|
||||
(phpinspect-class-p token)
|
||||
(phpinspect-namespace-p token)))
|
||||
|
||||
(defun phpinspect-find-statement-before-point (bmap meta point)
|
||||
(phpinspect--log "going through %s" (phpinspect-meta-token meta))
|
||||
(let ((children (reverse (cdr (phpinspect-meta-token meta)))))
|
||||
(let ((previous-siblings))
|
||||
(catch 'return
|
||||
(dolist (child children)
|
||||
(when (phpinspect-probably-token-p child)
|
||||
(phpinspect--log "probably token: %s" child)
|
||||
;; (phpinspect--log "Child: %s" child)
|
||||
(setq child (phpinspect-bmap-token-meta bmap child))
|
||||
(when (< (phpinspect-meta-start child) point)
|
||||
(if (and (not previous-siblings) (phpinspect-blocklike-p (phpinspect-meta-token child)))
|
||||
(progn
|
||||
(phpinspect--log "recursing into %s" (phpinspect-meta-token child))
|
||||
(throw 'return (phpinspect-find-statement-before-point bmap child point)))
|
||||
(when (phpinspect-end-of-statement-p (phpinspect-meta-token child))
|
||||
(phpinspect--log "returning %s, end of statement: %s" previous-siblings (phpinspect-meta-token child))
|
||||
(throw 'return previous-siblings))
|
||||
(push (phpinspect-meta-token child) previous-siblings)))))
|
||||
previous-siblings))))
|
||||
|
||||
(cl-defmethod phpinspect-get-resolvecontext
|
||||
((bmap phpinspect-bmap) (point integer))
|
||||
(let* ((enclosing-tokens)
|
||||
;; When there are no enclosing tokens, point is probably at the absolute
|
||||
;; end of the buffer, so we find the last child before point.
|
||||
(subject (phpinspect-bmap-last-token-before-point bmap point))
|
||||
(subject-token)
|
||||
(siblings))
|
||||
;; Dig down through tokens that can contain statements
|
||||
(catch 'break
|
||||
(while (and subject (phpinspect-enclosing-token-p (phpinspect-meta-token subject)))
|
||||
(phpinspect--log "Token %s is enclosing" (phpinspect-meta-token subject))
|
||||
(let ((new-subject
|
||||
(phpinspect-bmap-token-meta
|
||||
bmap (car (last (phpinspect-meta-token subject))))))
|
||||
(if new-subject
|
||||
(setq subject new-subject)
|
||||
(throw 'break nil)))))
|
||||
|
||||
(phpinspect--log "Initial resolvecontext subject token: %s"
|
||||
(phpinspect-meta-token subject))
|
||||
(when subject
|
||||
(setq subject-token
|
||||
(phpinspect-find-statement-before-point
|
||||
bmap
|
||||
(phpinspect-meta-parent subject)
|
||||
point))
|
||||
|
||||
(phpinspect--log "Ultimate resolvecontext subject token: %s. Parent: %s"
|
||||
subject-token (phpinspect-meta-token
|
||||
(phpinspect-meta-parent subject)))
|
||||
|
||||
;; Iterate through subject parents to build stack of enclosing tokens
|
||||
(let ((parent (phpinspect-meta-parent subject)))
|
||||
(while parent
|
||||
(let ((granny (phpinspect-meta-parent parent)))
|
||||
(unless (and (phpinspect-block-p (phpinspect-meta-token parent))
|
||||
(or (not granny)
|
||||
(phpinspect-function-p (phpinspect-meta-token granny))
|
||||
(phpinspect-class-p (phpinspect-meta-token granny))))
|
||||
(push (phpinspect-meta-token parent) enclosing-tokens))
|
||||
(setq parent (phpinspect-meta-parent parent))))))
|
||||
|
||||
(phpinspect--make-resolvecontext
|
||||
:subject (phpinspect--get-last-statement-in-token subject-token)
|
||||
:enclosing-tokens (nreverse enclosing-tokens)
|
||||
:project-root (phpinspect-current-project-root))))
|
||||
|
||||
(defun phpinspect--get-resolvecontext (token &optional resolvecontext)
|
||||
"Find the deepest nested incomplete token in TOKEN.
|
||||
If RESOLVECONTEXT is nil, it is created. Returns RESOLVECONTEXT
|
||||
of type `phpinspect--resolvecontext' containing the last
|
||||
statement of the innermost incomplete token as subject
|
||||
accompanied by all of its enclosing tokens."
|
||||
(unless resolvecontext
|
||||
(setq resolvecontext (phpinspect--make-resolvecontext
|
||||
:project-root (phpinspect-current-project-root))))
|
||||
|
||||
(let ((last-token (car (last token)))
|
||||
(last-encountered-token (car
|
||||
(phpinspect--resolvecontext-enclosing-tokens
|
||||
resolvecontext))))
|
||||
(unless (and (or (phpinspect-function-p last-encountered-token)
|
||||
(phpinspect-class-p last-encountered-token))
|
||||
(phpinspect-block-p token))
|
||||
;; When a class or function has been inserted already, its block
|
||||
;; doesn't need to be added on top.
|
||||
(phpinspect--resolvecontext-push-enclosing-token resolvecontext token))
|
||||
|
||||
(if (phpinspect-incomplete-token-p last-token)
|
||||
(phpinspect--get-resolvecontext last-token resolvecontext)
|
||||
;; else
|
||||
(setf (phpinspect--resolvecontext-subject resolvecontext)
|
||||
(phpinspect--get-last-statement-in-token token))
|
||||
|
||||
resolvecontext)))
|
||||
|
||||
(defun phpinspect--make-type-resolver-for-resolvecontext
|
||||
(resolvecontext)
|
||||
(let ((namespace-or-root
|
||||
(seq-find #'phpinspect-namespace-or-root-p
|
||||
(phpinspect--resolvecontext-enclosing-tokens
|
||||
resolvecontext)))
|
||||
(namespace-name))
|
||||
(when (phpinspect-namespace-p namespace-or-root)
|
||||
(setq namespace-name (cadadr namespace-or-root))
|
||||
(setq namespace-or-root (phpinspect-namespace-body namespace-or-root)))
|
||||
|
||||
(phpinspect--make-type-resolver
|
||||
(phpinspect--uses-to-types
|
||||
(seq-filter #'phpinspect-use-p namespace-or-root))
|
||||
(seq-find #'phpinspect-class-p
|
||||
(phpinspect--resolvecontext-enclosing-tokens
|
||||
resolvecontext))
|
||||
namespace-name)))
|
||||
|
||||
(provide 'phpinspect-resolvecontext)
|
||||
;;; phpinspect-resolvecontext.el ends here
|
@ -1 +1 @@
|
||||
(:root (:word "declare") (:list (:word "strict_types") (:assignment "=")) (:terminator ";") (:namespace (:word "App\\Controller") (:incomplete-block (:use (:word "Symfony\\Component\\HttpFoundation\\Response") (:terminator ";")) (:use (:word "App\\Entity\\Address") (:terminator ";")) (:use (:word "Symfony\\Component\\HttpFoundation\\RedirectResponse") (:terminator ";")) (:use (:word "App\\Repository\\AddressRepository") (:terminator ";")) (:use (:word "App\\Repository\\UserRepository") (:terminator ";")) (:use (:word "Doctrine\\ORM\\EntityManagerInterface") (:terminator ";")) (:use (:word "Twig\\Environment") (:terminator ";")) (:use (:word "Symfony\\Component\\HttpFoundation\\Request") (:terminator ";")) (:use (:word "Symfony\\Component\\Routing\\Annotation\\Route") (:terminator ";")) (:word "class") (:word "AddressController") (:incomplete-block (:const (:word "A_CONSTANT_FOR_THE_SAKE_OF_HAVING_ONE") (:assignment "=") (:string "a value") (:terminator ";")) (:public (:const (:word "ARRAY_CONSTANT") (:assignment "=") (:array (:string "key") (:fat-arrow "=>") (:string "value") (:comma ",") (:string "key") (:fat-arrow "=>")) (:terminator ";"))) (:private (:variable "repo") (:terminator ";")) (:private (:variable "user_repo") (:terminator ";")) (:private (:variable "twig") (:terminator ";")) (:private (:variable "em") (:terminator ";")) (:public (:function (:declaration (:word "function") (:word "__construct") (:list (:word "AddressRepository") (:variable "repo") (:comma ",") (:word "UserRepository") (:variable "user_repo") (:comma ",") (:word "Environment") (:variable "twig") (:comma ",") (:word "EntityManagerInterface") (:variable "em"))) (:block (:variable "this") (:object-attrib (:word "repo")) (:assignment "=") (:variable "repo") (:terminator ";") (:variable "this") (:object-attrib (:word "user_repo")) (:assignment "=") (:variable "user_repo") (:terminator ";") (:variable "this") (:object-attrib (:word "twig")) (:assignment "=") (:variable "twig") (:terminator ";") (:variable "this") (:object-attrib (:word "em")) (:assignment "=") (:variable "em") (:terminator ";")))) (:doc-block (:annotation "Route")) (:public (:function (:declaration (:word "function") (:word "addAddressPage") (:list (:word "Request") (:variable "req")) (:word "Response")) (:block (:variable "user") (:assignment "=") (:variable "this") (:object-attrib (:word "user_repo")) (:object-attrib (:word "findOne")) (:list (:variable "req") (:object-attrib (:word "get")) (:list (:string "user"))) (:terminator ";") (:word "return") (:word "new") (:word "Response") (:list (:variable "this") (:object-attrib (:word "twig")) (:object-attrib (:word "render")) (:list (:string "address/create.html.twig") (:comma ",") (:array (:string "user") (:fat-arrow "=>") (:variable "user") (:comma ",")))) (:terminator ";")))) (:doc-block (:annotation "Route")) (:public (:function (:declaration (:word "function") (:word "addAddressAction") (:list (:word "Request") (:variable "req")) (:word "Response")) (:block (:variable "user") (:assignment "=") (:variable "this") (:object-attrib (:word "user_repo")) (:object-attrib (:word "findOne")) (:list (:variable "req") (:object-attrib (:word "request")) (:object-attrib (:word "get")) (:list (:string "user"))) (:terminator ";") (:variable "address_string") (:assignment "=") (:variable "req") (:object-attrib (:word "request")) (:object-attrib (:word "get")) (:list (:string "address")) (:terminator ";") (:variable "address") (:assignment "=") (:word "new") (:word "Address") (:list (:variable "user") (:comma ",") (:variable "address_string")) (:terminator ";") (:variable "this") (:object-attrib (:word "em")) (:object-attrib (:word "persist")) (:list (:variable "address")) (:terminator ";") (:variable "this") (:object-attrib (:word "em")) (:object-attrib (:word "flush")) (:list) (:terminator ";") (:word "return") (:word "new") (:word "RedirectResponse") (:list (:string "/user/") (:variable "user") (:object-attrib (:word "getLoginName")) (:list) (:string "/manage")) (:terminator ";")))) (:doc-block (:annotation "Route")) (:public (:function (:declaration (:word "function") (:word "deleteAddressAction") (:list (:word "Request") (:variable "req")) (:word "Response")) (:incomplete-block (:variable "address") (:assignment "=") (:variable "this") (:object-attrib (:word "repo")) (:object-attrib (:word "find")) (:list (:variable "req") (:object-attrib (:word "request")) (:object-attrib (:word "get")) (:list (:string "address"))) (:terminator ";") (:comment) (:comment) (:variable "this") (:object-attrib (:word "em")) (:object-attrib (:word "remove")) (:incomplete-list (:variable "this") (:object-attrib (:word "em")) (:object-attrib nil)))))))))
|
||||
(:root (:word "declare") (:list (:word "strict_types") (:assignment "=")) (:terminator ";") (:namespace (:word "App\\Controller") (:incomplete-block (:use (:word "Symfony\\Component\\HttpFoundation\\Response") (:terminator ";")) (:use (:word "App\\Entity\\Address") (:terminator ";")) (:use (:word "Symfony\\Component\\HttpFoundation\\RedirectResponse") (:terminator ";")) (:use (:word "App\\Repository\\AddressRepository") (:terminator ";")) (:use (:word "App\\Repository\\UserRepository") (:terminator ";")) (:use (:word "Doctrine\\ORM\\EntityManagerInterface") (:terminator ";")) (:use (:word "Twig\\Environment") (:terminator ";")) (:use (:word "Symfony\\Component\\HttpFoundation\\Request") (:terminator ";")) (:use (:word "Symfony\\Component\\Routing\\Annotation\\Route") (:terminator ";")) (:class (:declaration (:word "class") (:word "AddressController")) (:incomplete-block (:const (:word "A_CONSTANT_FOR_THE_SAKE_OF_HAVING_ONE") (:assignment "=") (:string "a value") (:terminator ";")) (:public (:const (:word "ARRAY_CONSTANT") (:assignment "=") (:array (:string "key") (:fat-arrow "=>") (:string "value") (:comma ",") (:string "key") (:fat-arrow "=>")) (:terminator ";"))) (:private (:variable "repo") (:terminator ";")) (:private (:variable "user_repo") (:terminator ";")) (:private (:variable "twig") (:terminator ";")) (:private (:variable "em") (:terminator ";")) (:public (:function (:declaration (:word "function") (:word "__construct") (:list (:word "AddressRepository") (:variable "repo") (:comma ",") (:word "UserRepository") (:variable "user_repo") (:comma ",") (:word "Environment") (:variable "twig") (:comma ",") (:word "EntityManagerInterface") (:variable "em"))) (:block (:variable "this") (:object-attrib (:word "repo")) (:assignment "=") (:variable "repo") (:terminator ";") (:variable "this") (:object-attrib (:word "user_repo")) (:assignment "=") (:variable "user_repo") (:terminator ";") (:variable "this") (:object-attrib (:word "twig")) (:assignment "=") (:variable "twig") (:terminator ";") (:variable "this") (:object-attrib (:word "em")) (:assignment "=") (:variable "em") (:terminator ";")))) (:doc-block (:annotation "Route")) (:public (:function (:declaration (:word "function") (:word "addAddressPage") (:list (:word "Request") (:variable "req")) (:word "Response")) (:block (:variable "user") (:assignment "=") (:variable "this") (:object-attrib (:word "user_repo")) (:object-attrib (:word "findOne")) (:list (:variable "req") (:object-attrib (:word "get")) (:list (:string "user"))) (:terminator ";") (:word "return") (:word "new") (:word "Response") (:list (:variable "this") (:object-attrib (:word "twig")) (:object-attrib (:word "render")) (:list (:string "address/create.html.twig") (:comma ",") (:array (:string "user") (:fat-arrow "=>") (:variable "user") (:comma ",")))) (:terminator ";")))) (:doc-block (:annotation "Route")) (:public (:function (:declaration (:word "function") (:word "addAddressAction") (:list (:word "Request") (:variable "req")) (:word "Response")) (:block (:variable "user") (:assignment "=") (:variable "this") (:object-attrib (:word "user_repo")) (:object-attrib (:word "findOne")) (:list (:variable "req") (:object-attrib (:word "request")) (:object-attrib (:word "get")) (:list (:string "user"))) (:terminator ";") (:variable "address_string") (:assignment "=") (:variable "req") (:object-attrib (:word "request")) (:object-attrib (:word "get")) (:list (:string "address")) (:terminator ";") (:variable "address") (:assignment "=") (:word "new") (:word "Address") (:list (:variable "user") (:comma ",") (:variable "address_string")) (:terminator ";") (:variable "this") (:object-attrib (:word "em")) (:object-attrib (:word "persist")) (:list (:variable "address")) (:terminator ";") (:variable "this") (:object-attrib (:word "em")) (:object-attrib (:word "flush")) (:list) (:terminator ";") (:word "return") (:word "new") (:word "RedirectResponse") (:list (:string "/user/") (:variable "user") (:object-attrib (:word "getLoginName")) (:list) (:string "/manage")) (:terminator ";")))) (:doc-block (:annotation "Route")) (:public (:function (:declaration (:word "function") (:word "deleteAddressAction") (:list (:word "Request") (:variable "req")) (:word "Response")) (:incomplete-block (:variable "address") (:assignment "=") (:variable "this") (:object-attrib (:word "repo")) (:object-attrib (:word "find")) (:list (:variable "req") (:object-attrib (:word "request")) (:object-attrib (:word "get")) (:list (:string "address"))) (:terminator ";") (:comment) (:comment) (:variable "this") (:object-attrib (:word "em")) (:object-attrib (:word "remove")) (:incomplete-list (:variable "this") (:object-attrib (:word "em")) (:object-attrib nil))))))))))
|
File diff suppressed because one or more lines are too long
@ -1 +1 @@
|
||||
`(phpinspect--root-index (imports \, (list)) (classes ,(list (phpinspect--make-type :name "\\App\\Entity\\AuthToken" :collection nil :contains nil :fully-qualified t) `(phpinspect--indexed-class (class-name \, (phpinspect--make-type :name "\\App\\Entity\\AuthToken" :collection nil :contains nil :fully-qualified t)) (imports \, (list (cons (phpinspect-intern-name "ORM") (phpinspect--make-type :name "\\Doctrine\\ORM\\Mapping" :collection nil :contains nil :fully-qualified t)))) (methods \, (list (phpinspect--make-function :name "arrayReturn" :scope '(:public) :arguments (list) :return-type (phpinspect--make-type :name "\\array" :collection t :contains (phpinspect--make-type :name "\\App\\Entity\\DateTime" :collection nil :contains nil :fully-qualified t) :fully-qualified t)) (phpinspect--make-function :name "getCreationTime" :scope '(:public) :arguments (list) :return-type (phpinspect--make-type :name "\\DateTime" :collection nil :contains nil :fully-qualified t)) (phpinspect--make-function :name "isValid" :scope '(:public) :arguments (list) :return-type (phpinspect--make-type :name "\\bool" :collection nil :contains nil :fully-qualified t)) (phpinspect--make-function :name "hasStudentRole" :scope '(:public) :arguments (list) :return-type (phpinspect--make-type :name "\\bool" :collection nil :contains nil :fully-qualified t)) (phpinspect--make-function :name "getUser" :scope '(:public) :arguments (list) :return-type (phpinspect--make-type :name "\\App\\Entity\\User" :collection nil :contains nil :fully-qualified t)) (phpinspect--make-function :name "getToken" :scope '(:public) :arguments (list) :return-type (phpinspect--make-type :name "\\string" :collection nil :contains nil :fully-qualified t)) (phpinspect--make-function :name "__construct" :scope '(:public) :arguments (list (list "token" (phpinspect--make-type :name "\\string" :collection nil :contains nil :fully-qualified t)) (list "user" (phpinspect--make-type :name "\\App\\Entity\\User" :collection nil :contains nil :fully-qualified t)) (list "valid" (phpinspect--make-type :name "\\bool" :collection nil :contains nil :fully-qualified t)) (list "creation_time" (phpinspect--make-type :name "\\DateTime" :collection nil :contains nil :fully-qualified t))) :return-type (phpinspect--make-type :name "\\null" :collection nil :contains nil :fully-qualified t)))) (static-methods \, (list)) (static-variables \, (list)) (variables \, (list (phpinspect--make-variable :name "creation_time" :type (phpinspect--make-type :name "\\DateTime" :collection nil :contains nil :fully-qualified t) :scope '(:private)) (phpinspect--make-variable :name "valid" :type (phpinspect--make-type :name "\\bool" :collection nil :contains nil :fully-qualified t) :scope '(:private)) (phpinspect--make-variable :name "user" :type (phpinspect--make-type :name "\\App\\Entity\\App\\\\Entity\\\\User" :collection nil :contains nil :fully-qualified t) :scope '(:private)) (phpinspect--make-variable :name "token" :type (phpinspect--make-type :name "\\string" :collection nil :contains nil :fully-qualified t) :scope '(:private)))) (constants \, (list)) (extends \, (list)) (implements \, (list))))) (functions \, (list)))
|
||||
`(phpinspect--root-index (imports \, (list)) (classes \, (list (cons (phpinspect--make-type :name "\\App\\Entity\\AuthToken" :collection nil :contains nil :fully-qualified t) `(phpinspect--indexed-class (class-name \, (phpinspect--make-type :name "\\App\\Entity\\AuthToken" :collection nil :contains nil :fully-qualified t)) (imports \, (list (cons (phpinspect-intern-name "ORM") (phpinspect--make-type :name "\\Doctrine\\ORM\\Mapping" :collection nil :contains nil :fully-qualified t)))) (methods \, (list (phpinspect--make-function :name "arrayReturn" :scope '(:public) :arguments (list) :return-type (phpinspect--make-type :name "\\array" :collection t :contains (phpinspect--make-type :name "\\App\\Entity\\DateTime" :collection nil :contains nil :fully-qualified t) :fully-qualified t)) (phpinspect--make-function :name "getCreationTime" :scope '(:public) :arguments (list) :return-type (phpinspect--make-type :name "\\DateTime" :collection nil :contains nil :fully-qualified t)) (phpinspect--make-function :name "isValid" :scope '(:public) :arguments (list) :return-type (phpinspect--make-type :name "\\bool" :collection nil :contains nil :fully-qualified t)) (phpinspect--make-function :name "hasStudentRole" :scope '(:public) :arguments (list) :return-type (phpinspect--make-type :name "\\bool" :collection nil :contains nil :fully-qualified t)) (phpinspect--make-function :name "getUser" :scope '(:public) :arguments (list) :return-type (phpinspect--make-type :name "\\App\\Entity\\User" :collection nil :contains nil :fully-qualified t)) (phpinspect--make-function :name "getToken" :scope '(:public) :arguments (list) :return-type (phpinspect--make-type :name "\\string" :collection nil :contains nil :fully-qualified t)) (phpinspect--make-function :name "__construct" :scope '(:public) :arguments (list (list "token" (phpinspect--make-type :name "\\string" :collection nil :contains nil :fully-qualified t)) (list "user" (phpinspect--make-type :name "\\App\\Entity\\User" :collection nil :contains nil :fully-qualified t)) (list "valid" (phpinspect--make-type :name "\\bool" :collection nil :contains nil :fully-qualified t)) (list "creation_time" (phpinspect--make-type :name "\\DateTime" :collection nil :contains nil :fully-qualified t))) :return-type (phpinspect--make-type :name "\\null" :collection nil :contains nil :fully-qualified t)))) (static-methods \, (list)) (static-variables \, (list)) (variables \, (list (phpinspect--make-variable :name "creation_time" :type (phpinspect--make-type :name "\\DateTime" :collection nil :contains nil :fully-qualified t) :scope '(:private)) (phpinspect--make-variable :name "valid" :type (phpinspect--make-type :name "\\bool" :collection nil :contains nil :fully-qualified t) :scope '(:private)) (phpinspect--make-variable :name "user" :type (phpinspect--make-type :name "\\App\\Entity\\App\\\\Entity\\\\User" :collection nil :contains nil :fully-qualified t) :scope '(:private)) (phpinspect--make-variable :name "token" :type (phpinspect--make-type :name "\\string" :collection nil :contains nil :fully-qualified t) :scope '(:private)))) (constants \, (list)) (extends \, (list)) (implements \, (list)))))) (functions \, (list)))
|
@ -1 +1 @@
|
||||
`(phpinspect--root-index (imports \, (list)) (classes ,(list (phpinspect--make-type :name "\\App\\Entity\\AuthToken" :collection nil :contains nil :fully-qualified t) `(phpinspect--indexed-class (class-name \, (phpinspect--make-type :name "\\App\\Entity\\AuthToken" :collection nil :contains nil :fully-qualified t)) (imports \, (list (cons (phpinspect-intern-name "ORM") (phpinspect--make-type :name "\\Doctrine\\ORM\\Mapping" :collection nil :contains nil :fully-qualified t)))) (methods \, (list (phpinspect--make-function :name "getCreationTime" :scope '(:public) :arguments (list) :return-type (phpinspect--make-type :name "\\DateTime" :collection nil :contains nil :fully-qualified t)) (phpinspect--make-function :name "anAddedFunction" :scope '(:public) :arguments (list) :return-type (phpinspect--make-type :name "\\null" :collection nil :contains nil :fully-qualified t)) (phpinspect--make-function :name "isValid" :scope '(:public) :arguments (list) :return-type (phpinspect--make-type :name "\\bool" :collection nil :contains nil :fully-qualified t)) (phpinspect--make-function :name "hasStudentRole" :scope '(:public) :arguments (list) :return-type (phpinspect--make-type :name "\\bool" :collection nil :contains nil :fully-qualified t)) (phpinspect--make-function :name "getUser" :scope '(:public) :arguments (list) :return-type (phpinspect--make-type :name "\\App\\Entity\\User" :collection nil :contains nil :fully-qualified t)) (phpinspect--make-function :name "getToken" :scope '(:public) :arguments (list) :return-type (phpinspect--make-type :name "\\bool" :collection nil :contains nil :fully-qualified t)) (phpinspect--make-function :name "__construct" :scope '(:public) :arguments (list (list "token" (phpinspect--make-type :name "\\string" :collection nil :contains nil :fully-qualified t)) (list "user" (phpinspect--make-type :name "\\App\\Entity\\User" :collection nil :contains nil :fully-qualified t)) (list "valid" (phpinspect--make-type :name "\\bool" :collection nil :contains nil :fully-qualified t)) (list "creation_time" (phpinspect--make-type :name "\\DateTime" :collection nil :contains nil :fully-qualified t))) :return-type (phpinspect--make-type :name "\\null" :collection nil :contains nil :fully-qualified t)))) (static-methods \, (list)) (static-variables \, (list)) (variables \, (list (phpinspect--make-variable :name "creation_time" :type (phpinspect--make-type :name "\\DateTime" :collection nil :contains nil :fully-qualified t) :scope '(:private)) (phpinspect--make-variable :name "valid" :type (phpinspect--make-type :name "\\bool" :collection nil :contains nil :fully-qualified t) :scope '(:private)) (phpinspect--make-variable :name "user" :type (phpinspect--make-type :name "\\App\\Entity\\App\\\\Entity\\\\User" :collection nil :contains nil :fully-qualified t) :scope '(:private)) (phpinspect--make-variable :name "extra" :type nil :scope '(:private)) (phpinspect--make-variable :name "token" :type (phpinspect--make-type :name "\\string" :collection nil :contains nil :fully-qualified t) :scope '(:private)))) (constants \, (list)) (extends \, (list)) (implements \, (list))))) (functions \, (list)))
|
||||
`(phpinspect--root-index (imports \, (list)) (classes \, (list (cons (phpinspect--make-type :name "\\App\\Entity\\AuthToken" :collection nil :contains nil :fully-qualified t) `(phpinspect--indexed-class (class-name \, (phpinspect--make-type :name "\\App\\Entity\\AuthToken" :collection nil :contains nil :fully-qualified t)) (imports \, (list (cons (phpinspect-intern-name "ORM") (phpinspect--make-type :name "\\Doctrine\\ORM\\Mapping" :collection nil :contains nil :fully-qualified t)))) (methods \, (list (phpinspect--make-function :name "getCreationTime" :scope '(:public) :arguments (list) :return-type (phpinspect--make-type :name "\\DateTime" :collection nil :contains nil :fully-qualified t)) (phpinspect--make-function :name "anAddedFunction" :scope '(:public) :arguments (list) :return-type (phpinspect--make-type :name "\\null" :collection nil :contains nil :fully-qualified t)) (phpinspect--make-function :name "isValid" :scope '(:public) :arguments (list) :return-type (phpinspect--make-type :name "\\bool" :collection nil :contains nil :fully-qualified t)) (phpinspect--make-function :name "hasStudentRole" :scope '(:public) :arguments (list) :return-type (phpinspect--make-type :name "\\bool" :collection nil :contains nil :fully-qualified t)) (phpinspect--make-function :name "getUser" :scope '(:public) :arguments (list) :return-type (phpinspect--make-type :name "\\App\\Entity\\User" :collection nil :contains nil :fully-qualified t)) (phpinspect--make-function :name "getToken" :scope '(:public) :arguments (list) :return-type (phpinspect--make-type :name "\\bool" :collection nil :contains nil :fully-qualified t)) (phpinspect--make-function :name "__construct" :scope '(:public) :arguments (list (list "token" (phpinspect--make-type :name "\\string" :collection nil :contains nil :fully-qualified t)) (list "user" (phpinspect--make-type :name "\\App\\Entity\\User" :collection nil :contains nil :fully-qualified t)) (list "valid" (phpinspect--make-type :name "\\bool" :collection nil :contains nil :fully-qualified t)) (list "creation_time" (phpinspect--make-type :name "\\DateTime" :collection nil :contains nil :fully-qualified t))) :return-type (phpinspect--make-type :name "\\null" :collection nil :contains nil :fully-qualified t)))) (static-methods \, (list)) (static-variables \, (list)) (variables \, (list (phpinspect--make-variable :name "creation_time" :type (phpinspect--make-type :name "\\DateTime" :collection nil :contains nil :fully-qualified t) :scope '(:private)) (phpinspect--make-variable :name "valid" :type (phpinspect--make-type :name "\\bool" :collection nil :contains nil :fully-qualified t) :scope '(:private)) (phpinspect--make-variable :name "user" :type (phpinspect--make-type :name "\\App\\Entity\\App\\\\Entity\\\\User" :collection nil :contains nil :fully-qualified t) :scope '(:private)) (phpinspect--make-variable :name "extra" :type nil :scope '(:private)) (phpinspect--make-variable :name "token" :type (phpinspect--make-type :name "\\string" :collection nil :contains nil :fully-qualified t) :scope '(:private)))) (constants \, (list)) (extends \, (list)) (implements \, (list)))))) (functions \, (list)))
|
@ -0,0 +1,102 @@
|
||||
|
||||
(require 'phpinspect-bmap)
|
||||
|
||||
(ert-deftest phpinspect-bmap-overlay ()
|
||||
(let ((bmap (phpinspect-make-bmap))
|
||||
(bmap2 (phpinspect-make-bmap))
|
||||
(bmap3 (phpinspect-make-bmap)))
|
||||
|
||||
(phpinspect-bmap-register bmap 10 20 'token)
|
||||
(phpinspect-bmap-register bmap2 20 24 'token2)
|
||||
(phpinspect-bmap-register bmap3 40 50 'token3)
|
||||
|
||||
(should (phpinspect-bmap-token-starting-at bmap 10))
|
||||
|
||||
(phpinspect-bmap-overlay
|
||||
bmap bmap3 (phpinspect-bmap-token-starting-at bmap3 40) 10)
|
||||
|
||||
(should (phpinspect-bmap-token-starting-at bmap 50))
|
||||
|
||||
(phpinspect-bmap-overlay
|
||||
bmap2 bmap (phpinspect-bmap-token-starting-at bmap 10) -3)
|
||||
|
||||
(phpinspect-bmap-overlay
|
||||
bmap2 bmap (phpinspect-bmap-token-starting-at bmap 50) 5)
|
||||
|
||||
|
||||
(should (eq 'token2 (phpinspect-meta-token
|
||||
(phpinspect-bmap-token-starting-at bmap2 20))))
|
||||
(should (eq 'token (phpinspect-meta-token
|
||||
(phpinspect-bmap-token-starting-at bmap2 7))))
|
||||
|
||||
(should (phpinspect-bmap-token-meta bmap 'token))
|
||||
(should (phpinspect-bmap-token-meta bmap2 'token2))
|
||||
(should (phpinspect-bmap-token-meta bmap2 'token))
|
||||
(should (phpinspect-bmap-token-meta bmap2 'token3))))
|
||||
|
||||
(ert-deftest phpinspect-bmap-nest-parent ()
|
||||
(let ((bmap (phpinspect-make-bmap)))
|
||||
(phpinspect-bmap-register bmap 10 20 'child)
|
||||
(phpinspect-bmap-register bmap 5 25 'parent)
|
||||
(phpinspect-bmap-register bmap 2 30 'granny)
|
||||
|
||||
(let ((child (phpinspect-bmap-token-meta bmap 'child))
|
||||
(parent (phpinspect-bmap-token-meta bmap 'parent)))
|
||||
(should (eq 'parent (phpinspect-meta-token
|
||||
(phpinspect-meta-parent child))))
|
||||
(should (eq 'granny (phpinspect-meta-token (phpinspect-meta-parent parent)))))))
|
||||
|
||||
|
||||
(ert-deftest phpinspect-bmap-tokens-overlapping ()
|
||||
(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 21 44 'node4)
|
||||
|
||||
(setq result (phpinspect-bmap-tokens-overlapping bmap 22))
|
||||
(should (equal '(node4 node2 node1) (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)))
|
||||
(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)
|
||||
|
||||
(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 ()
|
||||
(let* ((bmap (phpinspect-make-bmap))
|
||||
(token1 `(:word "foo"))
|
||||
(token2 `(:word "bar"))
|
||||
(token3 `(:block ,token1 ,token2))
|
||||
(token4 `(:list ,token3)))
|
||||
(phpinspect-bmap-register bmap 10 20 token1)
|
||||
(phpinspect-bmap-register bmap 20 30 token2)
|
||||
(phpinspect-bmap-register bmap 9 31 token3)
|
||||
(phpinspect-bmap-register bmap 8 32 token4)
|
||||
|
||||
(should (phpinspect-bmap-token-meta bmap token1))
|
||||
(should (phpinspect-bmap-token-meta bmap token2))
|
||||
(should (phpinspect-bmap-token-meta bmap token3))
|
||||
(should (phpinspect-bmap-token-meta bmap token4))))
|
@ -0,0 +1,75 @@
|
||||
(require 'ert)
|
||||
(require 'phpinspect-edtrack)
|
||||
|
||||
(ert-deftest phpinspect-edit-end ()
|
||||
(let ((edit (list (cons 10 3) (cons 6 5) (cons 4 -2))))
|
||||
(should (= 13 (phpinspect-edit-end edit)))))
|
||||
|
||||
(ert-deftest phpinspect-edtrack-register-edit ()
|
||||
(let* ((edtrack (phpinspect-make-edtrack))
|
||||
(edit1 (phpinspect-edtrack-register-edit edtrack 5 10 10))
|
||||
(edit3 (phpinspect-edtrack-register-edit edtrack 100 200 150))
|
||||
(edit2 (phpinspect-edtrack-register-edit edtrack 15 22 7)))
|
||||
|
||||
(should (equal `((255 . -50) (27 . 0) (15 . -5)) (phpinspect-edtrack-edits edtrack)))))
|
||||
;; (pp (phpinspect-edtrack-edits edtrack))
|
||||
;; (should (= 10 (phpinspect-edit-end edit1)))
|
||||
;; (should (= 22 (phpinspect-edit-end edit2)))
|
||||
|
||||
;; (should (= 30 (phpinspect-edtrack-original-position-at-point edtrack 25)))
|
||||
;; (should (= 4 (phpinspect-edtrack-original-position-at-point edtrack 4)))
|
||||
;; (should (= 260 (phpinspect-edtrack-original-position-at-point edtrack 205)))))
|
||||
|
||||
(ert-deftest phpinsepct-edtrack-register-multi-edits ()
|
||||
(let ((track (phpinspect-make-edtrack)))
|
||||
(phpinspect-edtrack-register-edit track 10 20 5)
|
||||
(phpinspect-edtrack-register-edit track 25 30 0)
|
||||
(phpinspect-edtrack-register-edit track 13 20 0)
|
||||
|
||||
(should (= 42 (phpinspect-edtrack-current-position-at-point track 25)))))
|
||||
|
||||
(ert-deftest phpinspect-edtrack-register-multi-edits-deletions ()
|
||||
(let ((track (phpinspect-make-edtrack)))
|
||||
(phpinspect-edtrack-register-edit track 10 20 5)
|
||||
(phpinspect-edtrack-register-edit track 25 30 20)
|
||||
(phpinspect-edtrack-register-edit track 13 20 0)
|
||||
|
||||
(should (= 42 (phpinspect-edtrack-current-position-at-point track 45)))))
|
||||
|
||||
(ert-deftest phpinspect-edtrack-register-taint ()
|
||||
(let* ((track (phpinspect-make-edtrack)))
|
||||
(phpinspect-edtrack-register-taint track 0 5)
|
||||
(phpinspect-edtrack-register-taint track 10 20)
|
||||
(should (equal (list (cons 0 5) (cons 10 20)) (phpinspect-edtrack-taint-pool track)))
|
||||
|
||||
(phpinspect-edtrack-register-taint track 3 20)
|
||||
|
||||
(should (equal (list (cons 0 20)) (phpinspect-edtrack-taint-pool track)))))
|
||||
|
||||
(ert-deftest phpinspect-edtrack-taint-iterator ()
|
||||
(let ((track (phpinspect-make-edtrack))
|
||||
(iterator))
|
||||
(phpinspect-edtrack-register-taint track 120 150)
|
||||
(phpinspect-edtrack-register-taint track 5 30)
|
||||
(phpinspect-edtrack-register-taint track 25 50)
|
||||
(phpinspect-edtrack-register-taint track 70 100)
|
||||
|
||||
(setq iterator (phpinspect-edtrack-make-taint-iterator track))
|
||||
|
||||
(should-not (phpinspect-taint-iterator-token-is-tainted-p
|
||||
iterator (phpinspect-make-meta nil 1 4 nil nil)))
|
||||
|
||||
(should (phpinspect-taint-iterator-token-is-tainted-p
|
||||
iterator (phpinspect-make-meta nil 4 7 nil nil)))
|
||||
|
||||
(should (phpinspect-taint-iterator-token-is-tainted-p
|
||||
iterator (phpinspect-make-meta nil 20 30 nil nil)))
|
||||
|
||||
(should-not (phpinspect-taint-iterator-token-is-tainted-p
|
||||
iterator (phpinspect-make-meta nil 51 55 nil nil)))
|
||||
|
||||
(should (phpinspect-taint-iterator-token-is-tainted-p
|
||||
iterator (phpinspect-make-meta nil 65 73 nil nil)))
|
||||
|
||||
(should (phpinspect-taint-iterator-token-is-tainted-p
|
||||
iterator (phpinspect-make-meta nil 100 130 nil nil)))))
|
@ -0,0 +1,32 @@
|
||||
|
||||
(require 'phpinspect-parser)
|
||||
|
||||
(ert-deftest phpinspect-parse-bmap ()
|
||||
(let* ((ctx (phpinspect-make-pctx :incremental t))
|
||||
(code "
|
||||
class TestClass {
|
||||
public function getCurrentStatisticAction(): JsonResponse
|
||||
{
|
||||
$statistic = $this->repository->getCurrentStatistic();
|
||||
if (!$this->authorization->isGranted(EntityAction::VIEW, $statistic)) {
|
||||
return $this->responder->respondUnauthorized();
|
||||
}
|
||||
|
||||
return $this->responder->respond($statistic);
|
||||
}
|
||||
}")
|
||||
(bmap))
|
||||
(phpinspect-with-parse-context ctx
|
||||
(phpinspect-parse-string code))
|
||||
(setq bmap (phpinspect-pctx-bmap ctx))
|
||||
|
||||
(let ((enclosing (phpinspect-bmap-tokens-overlapping bmap 350))
|
||||
(parent))
|
||||
(should enclosing)
|
||||
(should (phpinspect-variable-p (phpinspect-meta-token (car enclosing))))
|
||||
(should (string= "statistic" (cadr (phpinspect-meta-token (car enclosing)))))
|
||||
(should (phpinspect-meta-parent (car enclosing)))
|
||||
|
||||
(setq parent (phpinspect-meta-parent (car enclosing)))
|
||||
(should (phpinspect-list-p (phpinspect-meta-token parent)))
|
||||
(should (phpinspect-block-p (phpinspect-meta-token (phpinspect-meta-parent parent)))))))
|
@ -0,0 +1,109 @@
|
||||
|
||||
(require 'phpinspect-resolvecontext)
|
||||
|
||||
(ert-deftest phinspect-get-resolvecontext ()
|
||||
(let* ((ctx (phpinspect-make-pctx :incremental t))
|
||||
(code "
|
||||
class TestClass {
|
||||
public function getCurrentStatisticAction(): JsonResponse
|
||||
{
|
||||
$statistic = $this->repository->getCurrentStatistic();
|
||||
if (!$this->authorization->isGranted(EntityAction::VIEW, $statistic)) {
|
||||
return $this->responder->respondUnauthorized();
|
||||
}
|
||||
|
||||
$this->
|
||||
|
||||
return $this->responder->respond($statistic);
|
||||
}
|
||||
}")
|
||||
(bmap))
|
||||
(phpinspect-with-parse-context ctx
|
||||
(phpinspect-parse-string code))
|
||||
(setq bmap (phpinspect-pctx-bmap ctx))
|
||||
|
||||
(let ((rctx (phpinspect-get-resolvecontext bmap 317)))
|
||||
(should (phpinspect--resolvecontext-subject rctx))
|
||||
(should (phpinspect--resolvecontext-enclosing-tokens rctx)))))
|
||||
|
||||
|
||||
(ert-deftest phpinspect-type-resolver-for-resolvecontext ()
|
||||
(with-temp-buffer
|
||||
(insert-file-contents (concat phpinspect-test-php-file-directory "/IncompleteClass.php"))
|
||||
(let* ((bmap (phpinspect-parse-string-to-bmap (buffer-string)))
|
||||
(resolvecontext (phpinspect-get-resolvecontext bmap (point-max)))
|
||||
(type-resolver (phpinspect--make-type-resolver-for-resolvecontext
|
||||
resolvecontext)))
|
||||
|
||||
(should (phpinspect--type= (phpinspect--make-type :name "\\array")
|
||||
(funcall type-resolver
|
||||
(phpinspect--make-type :name "array"))))
|
||||
(should (phpinspect--type= (phpinspect--make-type :name "\\array")
|
||||
(funcall type-resolver
|
||||
(phpinspect--make-type :name "\\array"))))
|
||||
(should (phpinspect--type= (phpinspect--make-type
|
||||
:name "\\Symfony\\Component\\HttpFoundation\\Response")
|
||||
(funcall type-resolver (phpinspect--make-type :name "Response"))))
|
||||
(should (phpinspect--type= (phpinspect--make-type :name "\\Response")
|
||||
(funcall type-resolver
|
||||
(phpinspect--make-type :name "\\Response"))))
|
||||
(should (phpinspect--type= (phpinspect--make-type :name "\\App\\Controller\\GastonLagaffe")
|
||||
(funcall type-resolver
|
||||
(phpinspect--make-type :name "GastonLagaffe"))))
|
||||
(should (phpinspect--type=
|
||||
(phpinspect--make-type :name "\\App\\Controller\\Dupuis\\GastonLagaffe")
|
||||
(funcall type-resolver
|
||||
(phpinspect--make-type :name "Dupuis\\GastonLagaffe")))))))
|
||||
|
||||
(ert-deftest phpinspect-type-resolver-for-resolvecontext-namespace-block ()
|
||||
(with-temp-buffer
|
||||
(insert-file-contents (concat phpinspect-test-php-file-directory "/IncompleteClassBlockedNamespace.php"))
|
||||
(let* ((bmap (phpinspect-parse-string-to-bmap (buffer-string)))
|
||||
(resolvecontext (phpinspect-get-resolvecontext bmap (point-max)))
|
||||
(type-resolver (phpinspect--make-type-resolver-for-resolvecontext
|
||||
resolvecontext)))
|
||||
|
||||
(should (phpinspect--type= (phpinspect--make-type :name "\\array")
|
||||
(funcall type-resolver (phpinspect--make-type :name "array"))))
|
||||
(should (phpinspect--type= (phpinspect--make-type :name "\\array")
|
||||
(funcall type-resolver (phpinspect--make-type :name "\\array"))))
|
||||
(should (phpinspect--type= (phpinspect--make-type
|
||||
:name "\\Symfony\\Component\\HttpFoundation\\Response")
|
||||
(funcall type-resolver (phpinspect--make-type :name "Response"))))
|
||||
(should (phpinspect--type= (phpinspect--make-type :name "\\Response")
|
||||
(funcall type-resolver (phpinspect--make-type :name "\\Response"))))
|
||||
(should (phpinspect--type= (phpinspect--make-type :name "\\App\\Controller\\GastonLagaffe")
|
||||
(funcall type-resolver (phpinspect--make-type
|
||||
:name "GastonLagaffe"))))
|
||||
(should (phpinspect--type= (phpinspect--make-type
|
||||
:name "\\App\\Controller\\Dupuis\\GastonLagaffe")
|
||||
(funcall type-resolver (phpinspect--make-type :name "Dupuis\\GastonLagaffe")))))))
|
||||
|
||||
(ert-deftest phpinspect-type-resolver-for-resolvecontext-multiple-namespace-blocks ()
|
||||
(with-temp-buffer
|
||||
(insert-file-contents (concat phpinspect-test-php-file-directory "/IncompleteClassMultipleNamespaces.php"))
|
||||
(let* ((bmap (phpinspect-parse-string-to-bmap (buffer-string)))
|
||||
(resolvecontext (phpinspect--get-resolvecontext
|
||||
(phpinspect-test-read-fixture-data
|
||||
"IncompleteClassMultipleNamespaces")))
|
||||
(type-resolver (phpinspect--make-type-resolver-for-resolvecontext
|
||||
resolvecontext)))
|
||||
|
||||
(should (phpinspect--type= (phpinspect--make-type :name "\\array")
|
||||
(funcall type-resolver
|
||||
(phpinspect--make-type :name "array"))))
|
||||
(should (phpinspect--type= (phpinspect--make-type :name "\\array")
|
||||
(funcall type-resolver
|
||||
(phpinspect--make-type :name "\\array"))))
|
||||
(should (phpinspect--type= (phpinspect--make-type
|
||||
:name "\\Symfony\\Component\\HttpFoundation\\Response")
|
||||
(funcall type-resolver (phpinspect--make-type :name "Response"))))
|
||||
(should (phpinspect--type= (phpinspect--make-type :name "\\Response")
|
||||
(funcall type-resolver
|
||||
(phpinspect--make-type :name "\\Response"))))
|
||||
(should (phpinspect--type= (phpinspect--make-type :name "\\App\\Controller\\GastonLagaffe")
|
||||
(funcall type-resolver (phpinspect--make-type :name "GastonLagaffe"))))
|
||||
(should (phpinspect--type= (phpinspect--make-type
|
||||
:name "\\App\\Controller\\Dupuis\\GastonLagaffe")
|
||||
(funcall type-resolver (phpinspect--make-type
|
||||
:name "Dupuis\\GastonLagaffe")))))))
|
Loading…
Reference in New Issue