aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlan Mackenzie2023-06-27 20:11:48 +0000
committerAlan Mackenzie2023-06-27 20:11:48 +0000
commitbe437883c6d85f3ff2eddd4359bbfb9230c92910 (patch)
treef86ceb719bd6a34537dcb873b22bb0e647de5df6
parentcf4ccc58284de50959ea66b1cd2655ab2fa4d15b (diff)
downloademacs-be437883c6d85f3ff2eddd4359bbfb9230c92910.tar.gz
emacs-be437883c6d85f3ff2eddd4359bbfb9230c92910.zip
Amend the handling of c-laomib-cache.
There was unstable syntactic analysis of lines which were brace lists. This fixes bug#64133. * lisp/progmodes/cc-engine.el (c-laomib-cache): Allow several entries with the same LIM element corresponding to distinct scanning regions. (c-laomib-get-cache): Add new parameter START. Adjust to be able to have entries with the same LIM element and handle them correctly. (c-laomib-put-cache): Amend the handling of cache entries with the same LIM element. (c-looking-at-or-maybe-in-bracelist): Supply the needed new argument to c-laomib-get-cache. Add in a new call to c-laomib-put-cache.
-rw-r--r--lisp/progmodes/cc-engine.el44
1 files changed, 32 insertions, 12 deletions
diff --git a/lisp/progmodes/cc-engine.el b/lisp/progmodes/cc-engine.el
index c4ae8aadd65..721daf9d53f 100644
--- a/lisp/progmodes/cc-engine.el
+++ b/lisp/progmodes/cc-engine.el
@@ -12997,11 +12997,19 @@ comment at the start of cc-engine.el for more info."
12997(defvar c-laomib-cache nil) 12997(defvar c-laomib-cache nil)
12998(make-variable-buffer-local 'c-laomib-cache) 12998(make-variable-buffer-local 'c-laomib-cache)
12999 12999
13000(defun c-laomib-get-cache (containing-sexp) 13000(defun c-laomib-get-cache (containing-sexp start)
13001 ;; Get an element from `c-laomib-cache' matching CONTAINING-SEXP. 13001 ;; Get an element from `c-laomib-cache' matching CONTAINING-SEXP, and which
13002 ;; is suitable for start postiion START.
13002 ;; Return that element or nil if one wasn't found. 13003 ;; Return that element or nil if one wasn't found.
13003 (let ((elt (assq containing-sexp c-laomib-cache))) 13004 (let ((ptr c-laomib-cache)
13004 (when elt 13005 elt)
13006 (while
13007 (and ptr
13008 (setq elt (car ptr))
13009 (or (not (eq (car elt) containing-sexp))
13010 (< start (car (cddr elt)))))
13011 (setq ptr (cdr ptr)))
13012 (when ptr
13005 ;; Move the fetched `elt' to the front of the cache. 13013 ;; Move the fetched `elt' to the front of the cache.
13006 (setq c-laomib-cache (delq elt c-laomib-cache)) 13014 (setq c-laomib-cache (delq elt c-laomib-cache))
13007 (push elt c-laomib-cache) 13015 (push elt c-laomib-cache)
@@ -13013,18 +13021,26 @@ comment at the start of cc-engine.el for more info."
13013 ;; the components of the new element (see comment for `c-laomib-cache'). 13021 ;; the components of the new element (see comment for `c-laomib-cache').
13014 ;; The return value is of no significance. 13022 ;; The return value is of no significance.
13015 (when lim 13023 (when lim
13016 (let ((old-elt (assq lim c-laomib-cache)) 13024 (let (old-elt
13017 ;; (elt (cons containing-sexp (cons start nil)))
13018 (new-elt (list lim start end result)) 13025 (new-elt (list lim start end result))
13019 big-ptr 13026 big-ptr
13020 (cur-ptr c-laomib-cache) 13027 (cur-ptr c-laomib-cache)
13021 togo (size 0) cur-size 13028 togo (size 0) cur-size)
13022 ) 13029
13023 (if old-elt (setq c-laomib-cache (delq old-elt c-laomib-cache))) 13030 ;; If there is an elt which overlaps with the new element, remove it.
13031 (while
13032 (and cur-ptr
13033 (setq old-elt (car cur-ptr))
13034 (or (not (eq (car old-elt) lim))
13035 (not (and (> start (car (cddr old-elt)))
13036 (<= start (cadr old-elt))))))
13037 (setq cur-ptr (cdr cur-ptr)))
13038 (when (and cur-ptr old-elt)
13039 (setq c-laomib-cache (delq old-elt c-laomib-cache)))
13024 13040
13025 (while (>= (length c-laomib-cache) 4) 13041 (while (>= (length c-laomib-cache) 4)
13026 ;; We delete the least recently used elt which doesn't enclose START, 13042 ;; We delete the least recently used elt which doesn't enclose START,
13027 ;; or.. 13043 ;; or ...
13028 (dolist (elt c-laomib-cache) 13044 (dolist (elt c-laomib-cache)
13029 (if (or (<= start (cadr elt)) 13045 (if (or (<= start (cadr elt))
13030 (> start (car (cddr elt)))) 13046 (> start (car (cddr elt))))
@@ -13032,8 +13048,10 @@ comment at the start of cc-engine.el for more info."
13032 13048
13033 ;; ... delete the least recently used elt which isn't the biggest. 13049 ;; ... delete the least recently used elt which isn't the biggest.
13034 (when (not togo) 13050 (when (not togo)
13051 (setq cur-ptr c-laomib-cache)
13035 (while (cdr cur-ptr) 13052 (while (cdr cur-ptr)
13036 (setq cur-size (- (nth 2 (cadr cur-ptr)) (car (cadr cur-ptr)))) 13053 (setq cur-size (- (cadr (cadr cur-ptr))
13054 (car (cddr (cadr cur-ptr)))))
13037 (when (> cur-size size) 13055 (when (> cur-size size)
13038 (setq size cur-size 13056 (setq size cur-size
13039 big-ptr cur-ptr)) 13057 big-ptr cur-ptr))
@@ -13225,7 +13243,7 @@ comment at the start of cc-engine.el for more info."
13225 (goto-char pos) 13243 (goto-char pos)
13226 (when (eq braceassignp 'dontknow) 13244 (when (eq braceassignp 'dontknow)
13227 (let* ((cache-entry (and containing-sexp 13245 (let* ((cache-entry (and containing-sexp
13228 (c-laomib-get-cache containing-sexp))) 13246 (c-laomib-get-cache containing-sexp pos)))
13229 (lim2 (or (cadr cache-entry) lim)) 13247 (lim2 (or (cadr cache-entry) lim))
13230 sub-bassign-p) 13248 sub-bassign-p)
13231 (if cache-entry 13249 (if cache-entry
@@ -13247,6 +13265,8 @@ comment at the start of cc-engine.el for more info."
13247 ) 13265 )
13248 (setq braceassignp (nth 3 cache-entry)) 13266 (setq braceassignp (nth 3 cache-entry))
13249 (goto-char (nth 2 cache-entry))) 13267 (goto-char (nth 2 cache-entry)))
13268 (c-laomib-put-cache containing-sexp
13269 start (point) sub-bassign-p)
13250 (setq braceassignp sub-bassign-p))) 13270 (setq braceassignp sub-bassign-p)))
13251 (t)) 13271 (t))
13252 13272