CC Mode: Fix bug in "state cache" invalidation function.

* lisp/progmodes/cc-engine.el (c-invalidate-state-cache-1): Rewrite part of
it, following the code in c-parse-state-1, to get a proper setting of
c-state-cache-good-pos.
This commit is contained in:
Alan Mackenzie 2021-02-23 11:16:24 +00:00
parent b03d9d2c13
commit 7ebdecfcdf

View file

@ -4319,38 +4319,29 @@ mhtml-mode."
(setq c-state-nonlit-pos-cache-limit (1- here))) (setq c-state-nonlit-pos-cache-limit (1- here)))
(c-truncate-lit-pos-cache here) (c-truncate-lit-pos-cache here)
;; `c-state-cache': (cond
;; Case 1: if `here' is in a literal containing point-min, everything ;; `c-state-cache':
;; becomes (or is already) nil. ;; Case 1: if `here' is in a literal containing point-min, everything
(if (or (null c-state-cache-good-pos) ;; becomes (or is already) nil.
(< here (c-state-get-min-scan-pos))) ((or (null c-state-cache-good-pos)
(setq c-state-cache nil (< here (c-state-get-min-scan-pos)))
c-state-cache-good-pos nil (setq c-state-cache nil
c-state-min-scan-pos nil) c-state-cache-good-pos nil
c-state-min-scan-pos nil))
;; Truncate `c-state-cache' and set `c-state-cache-good-pos' to a value ;; Case 2: `here' is below `c-state-cache-good-pos', so we need to amend
;; below `here'. To maintain its consistency, we may need to insert a new ;; the entire `c-state-cache' data.
;; brace pair. ((< here c-state-cache-good-pos)
(let ((here-bol (c-point 'bol here)) (let* ((res (c-remove-stale-state-cache-backwards here))
too-high-pa ; recorded {/(/[ next above or just below here, or nil. (good-pos (car res))
dropped-cons) ; was the last removed element a brace pair? (scan-backward-pos (cadr res))
;; The easy bit - knock over-the-top bits off `c-state-cache'. (scan-forward-p (car (cddr res))))
(while (and c-state-cache (if scan-backward-pos
(>= (c-state-cache-top-paren) here)) (c-append-lower-brace-pair-to-state-cache scan-backward-pos here))
(setq dropped-cons (consp (car c-state-cache)) (setq c-state-cache-good-pos
too-high-pa (c-state-cache-top-lparen) (if scan-forward-p
c-state-cache (cdr c-state-cache))) (c-append-to-state-cache good-pos here)
good-pos)))))
;; Do we need to add in an earlier brace pair, having lopped one off?
(if (and dropped-cons
(<= too-high-pa here))
(c-append-lower-brace-pair-to-state-cache too-high-pa here here-bol))
(if (and c-state-cache-good-pos (< here c-state-cache-good-pos))
(setq c-state-cache-good-pos
(or (save-excursion
(goto-char here)
(c-literal-start))
here)))))
;; The brace-pair desert marker: ;; The brace-pair desert marker:
(when (car c-state-brace-pair-desert) (when (car c-state-brace-pair-desert)