Commit 9dee49ed authored by Alan Mackenzie's avatar Alan Mackenzie

Tidy up the literal cacheing in CC Mode, optimizing c-full-pp-to-literal

(Intermediate commit)

* lisp/progmodes/cc-engine.el, lisp/progmodes/cc-fonts.el
* lisp/progmodes/cc-mode.el : Rename:
c-state-semi-nonlit-pos-cache -> c-lit-pos-cache,
c-state-semi-nonlit-pos-cache-limit -> c-lit-pos-cache-limit,
c-state-semi-nonlit-near-cache -> c-semi-lit-near-cache,
c-truncate-semi-nonlit-pos-cache -> c-truncate-lit-pos-cache,
c-state-semi-trim-near-cache -> c-semi-trim-near-cache,
c-state-semi-get-near-cache-entry -> c-semi-get-near-cache-entry,
c-state-semi-put-near-cache-entry -> c-semi-put-near-cache-entry,
c-state-semi-pp-to-literal -> c-semi-pp-to-literal,
c-state-full-pp-to-literal -> c-full-pp-to-literal,
c-state-semi-trim-cache -> c-trim-lit-pos-cache.

* lisp/progmodes/cc-engine.el (c-semi-near-cache-limit): New variable.
(c-truncate-lit-pos-cache): This now truncates the cache variables for all
three lit- sub-caches.
(c-semi-put-near-cache-entry): Increase c-semi-near-cache-limit to the
position of the new entry.
(c-full-near-cache-limit, c-full-lit-near-cache): New variables.
(c-full-trim-near-cache, c-full-get-near-cache-entry)
(c-full-put-near-cache-entry): New functions.
(c-full-pp-to-literal): Amend to use the new functions, and to optimize the
use of the available caches, similarly to c-semi-pp-to-literal.
parent 56964f3d
......@@ -2544,17 +2544,17 @@ comment at the start of cc-engine.el for more info."
;; states going back to the beginning of the buffer, one entry every 3000
;; characters.
;;
;; When searching this cache, `c-state-semi-pp-to-literal' first seeks an
;; When searching this cache, `c-semi-pp-to-literal' first seeks an
;; exact match, then a "close" match from the near cache. If neither of these
;; succeed, the nearest entry in the far cache is used.
;;
;; Because either sub-cache can raise `c-state-semi-nonlit-pos-cache-limit',
;; Because either sub-cache can raise `c-lit-pos-cache-limit',
;; both of them are "trimmed" together after a buffer change to ensure
;; consistency.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defvar c-state-semi-nonlit-pos-cache nil)
(make-variable-buffer-local 'c-state-semi-nonlit-pos-cache)
(defvar c-lit-pos-cache nil)
(make-variable-buffer-local 'c-lit-pos-cache)
;; A list of elements in descending order of POS of one of the forms:
;; o - POS (when point is not in a literal);
;; o - (POS CHAR-1) (when the last character before point is potentially
......@@ -2569,43 +2569,53 @@ comment at the start of cc-engine.el for more info."
;; potentially forming the first half of a two-char construct (in Emacs <= 25
;; and XEmacs) or the syntax of the character (Emacs >= 26).
(defvar c-state-semi-nonlit-pos-cache-limit 1)
(make-variable-buffer-local 'c-state-semi-nonlit-pos-cache-limit)
;; An upper limit on valid entries in `c-state-semi-nonlit-pos-cache'. This
(defvar c-lit-pos-cache-limit 1)
(make-variable-buffer-local 'c-lit-pos-cache-limit)
;; An upper limit on valid entries in `c-lit-pos-cache'. This
;; is reduced by buffer changes, and increased by invocations of
;; `c-parse-ps-state-below'.
(defvar c-state-semi-nonlit-near-cache nil)
(make-variable-buffer-local 'c-state-semi-nonlit-near-cache)
;; A list of up to six recent results from `c-state-semi-pp-to-literal'. Each
(defvar c-semi-lit-near-cache nil)
(make-variable-buffer-local 'c-semi-lit-near-cache)
;; A list of up to six recent results from `c-semi-pp-to-literal'. Each
;; element is a cons of the buffer position and the `parse-partial-sexp' state
;; at that position.
(defsubst c-truncate-semi-nonlit-pos-cache (pos)
;; Truncate the upper bound of the cache `c-state-semi-nonlit-pos-cache' to
;; POS, if it is higher than that position.
(setq c-state-semi-nonlit-pos-cache-limit
(min c-state-semi-nonlit-pos-cache-limit pos)))
(defun c-state-semi-trim-near-cache ()
;; Remove stale entries in `c-state-semi-nonlit-near-cache', i.e. those
;; whose positions are above `c-state-semi-nonlit-pos-cache-limit'.
(let ((nc-list c-state-semi-nonlit-near-cache))
(defvar c-semi-near-cache-limit 1)
(make-variable-buffer-local 'c-semi-near-cache-limit)
;; An upper limit on valid entries in `c-semi-lit-near-cache'. This is
;; reduced by buffer changes, and increased by invocations of
;; `c-semi-pp-to-literal'.
(defsubst c-truncate-lit-pos-cache (pos)
;; Truncate the upper bound of each of the three caches to POS, if it is
;; higher than that position.
(setq c-lit-pos-cache-limit
(min c-lit-pos-cache-limit pos)
c-semi-near-cache-limit
(min c-semi-near-cache-limit pos)
c-full-near-cache-limit
(min c-full-near-cache-limit pos)))
(defun c-semi-trim-near-cache ()
;; Remove stale entries in `c-semi-lit-near-cache', i.e. those
;; whose positions are above `c-lit-pos-cache-limit'.
(let ((nc-list c-semi-lit-near-cache))
(while nc-list
(if (> (caar nc-list) c-state-semi-nonlit-pos-cache-limit)
(setq c-state-semi-nonlit-near-cache
(delq (car nc-list) c-state-semi-nonlit-near-cache)
nc-list c-state-semi-nonlit-near-cache) ; start again in case
(if (> (caar nc-list) c-lit-pos-cache-limit)
(setq c-semi-lit-near-cache
(delq (car nc-list) c-semi-lit-near-cache)
nc-list c-semi-lit-near-cache) ; start again in case
; of list breakage.
(setq nc-list (cdr nc-list))))))
(defun c-state-semi-get-near-cache-entry (here)
(defun c-semi-get-near-cache-entry (here)
;; Return the near cache entry at the highest postion before HERE, if any,
;; or nil. The near cache entry is of the form (POSITION . STATE), where
;; STATE has the form of a result of `parse-partial-sexp'.
(let ((nc-pos-state
(or (assq here c-state-semi-nonlit-near-cache)
(let ((nc-list c-state-semi-nonlit-near-cache)
(or (assq here c-semi-lit-near-cache)
(let ((nc-list c-semi-lit-near-cache)
pos (nc-pos 0) cand-pos-state)
(catch 'found
(while nc-list
......@@ -2622,22 +2632,24 @@ comment at the start of cc-engine.el for more info."
(setq nc-list (cdr nc-list)))
cand-pos-state)))))
(when (and nc-pos-state
(not (eq nc-pos-state (car c-state-semi-nonlit-near-cache))))
(not (eq nc-pos-state (car c-semi-lit-near-cache))))
;; Move the found cache entry to the front of the list.
(setq c-state-semi-nonlit-near-cache
(delq nc-pos-state c-state-semi-nonlit-near-cache))
(push nc-pos-state c-state-semi-nonlit-near-cache))
nc-pos-state))
(setq c-semi-lit-near-cache
(delq nc-pos-state c-semi-lit-near-cache))
(push nc-pos-state c-semi-lit-near-cache))
(copy-tree nc-pos-state)))
(defun c-state-semi-put-near-cache-entry (here state)
(defun c-semi-put-near-cache-entry (here state)
;; Put a new near cache entry into the near cache.
(while (>= (length c-state-semi-nonlit-near-cache) 6)
(setq c-state-semi-nonlit-near-cache
(delq (car (last c-state-semi-nonlit-near-cache))
c-state-semi-nonlit-near-cache)))
(push (cons here state) c-state-semi-nonlit-near-cache))
(defun c-state-semi-pp-to-literal (here &optional not-in-delimiter)
(while (>= (length c-semi-lit-near-cache) 6)
(setq c-semi-lit-near-cache
(delq (car (last c-semi-lit-near-cache))
c-semi-lit-near-cache)))
(push (cons here state) c-semi-lit-near-cache)
(setq c-semi-near-cache-limit
(max c-semi-near-cache-limit here)))
(defun c-semi-pp-to-literal (here &optional not-in-delimiter)
;; Do a parse-partial-sexp from a position in the buffer before HERE which
;; isn't in a literal, and return information about HERE, either:
;; (STATE TYPE BEG) if HERE is in a literal; or
......@@ -2656,11 +2668,11 @@ comment at the start of cc-engine.el for more info."
(save-excursion
(save-restriction
(widen)
(c-state-semi-trim-cache)
(c-state-semi-trim-near-cache)
(setq c-state-semi-nonlit-pos-cache-limit here)
(c-trim-lit-pos-cache)
(c-semi-trim-near-cache)
(setq c-lit-pos-cache-limit here)
(save-match-data
(let* ((pos-and-state (c-state-semi-get-near-cache-entry here))
(let* ((pos-and-state (c-semi-get-near-cache-entry here))
(pos (car pos-and-state))
(near-pos pos)
(s (cdr pos-and-state))
......@@ -2690,7 +2702,7 @@ comment at the start of cc-engine.el for more info."
(not (memq (char-before here) '(?\\ ?\n)))))))
(setq s (parse-partial-sexp pos here nil nil s)))
(when (not (eq near-pos here))
(c-state-semi-put-near-cache-entry here s))
(c-semi-put-near-cache-entry here s))
(cond
((or (nth 3 s)
(and (nth 4 s)
......@@ -2712,7 +2724,81 @@ comment at the start of cc-engine.el for more info."
(t (list s))))))))
(defun c-state-full-pp-to-literal (here &optional not-in-delimiter)
(defvar c-full-near-cache-limit 1)
(make-variable-buffer-local 'c-full-near-cache-limit)
;; An upper limit on valid entries in `c-full-lit-near-cache'. This
;; is reduced by buffer changes, and increased by invocations of
;; `c-full-pp-to-literal'.
(defvar c-full-lit-near-cache nil)
(make-variable-buffer-local 'c-full-lit-near-cache)
;; A list of up to six recent results from `c-full-pp-to-literal'. Each
;; element is a list (HERE STATE END)), where HERE is the buffer position the
;; function was called for, STATE is the `parse-partial-sexp' state there, and
;; END is the end of the literal enclosing HERE, if any, or nil otherwise.
(defun c-full-trim-near-cache ()
;; Remove stale entries in `c-full-lit-near-cache', i.e. those
;; whose END entries, or positions, are above
;; `c-state-full-nonlit-pos-cache-limit'.
(let ((nc-list c-full-lit-near-cache) elt)
(while nc-list
(let ((elt (car nc-list)))
(if (if (car (cddr elt))
(< c-full-near-cache-limit (car (cddr elt)))
(< c-full-near-cache-limit (car elt)))
(setq c-full-lit-near-cache
(delq elt c-full-lit-near-cache)
nc-list c-full-lit-near-cache) ; start again in
; case of list breakage.
(setq nc-list (cdr nc-list)))))))
(defun c-full-get-near-cache-entry (here)
;; Return a near cache entry which either represents a literal which
;; encloses HERE, or is at the highest position before HERE. The returned
;; cache entry is of the form (POSITION STATE END), where STATE has the form
;; of a result from `parse-partial-sexp' which is valid at POSITION and END
;; is the end of any enclosing literal, or nil.
(let ((nc-pos-state
(or (assq here c-full-lit-near-cache)
(let ((nc-list c-full-lit-near-cache)
elt match (nc-pos 0) cand-pos-state)
(setq match
(catch 'found
(while nc-list
(setq elt (car nc-list))
(when
(and (car (cddr elt))
(>= here (nth 8 (cadr elt)))
(< here (car (cddr elt))))
(throw 'found elt))
(when
(and (< (car elt) here)
(> (car elt) nc-pos))
(setq nc-pos (car elt)
cand-pos-state elt))
(setq nc-list (cdr nc-list)))
nil))
(or match cand-pos-state)))))
;; Move the found cache entry, if any, to the front of the list.
(when (and nc-pos-state
(not (eq nc-pos-state (car c-full-lit-near-cache))))
(setq c-full-lit-near-cache
(delq nc-pos-state c-full-lit-near-cache))
(push nc-pos-state c-full-lit-near-cache))
(copy-tree nc-pos-state)))
(defun c-full-put-near-cache-entry (here state end)
;; Put a new near chace entry into the near cache.
(while (>= (length c-full-lit-near-cache) 6)
(setq c-full-lit-near-cache
(delq (car (last c-full-lit-near-cache))
c-full-lit-near-cache)))
(push (list here state end) c-full-lit-near-cache)
(setq c-full-near-cache-limit
(max c-full-near-cache-limit (or end here))))
(defun c-full-pp-to-literal (here &optional not-in-delimiter)
;; This function will supersede c-state-pp-to-literal.
;;
;; Do a parse-partial-sexp from a position in the buffer before HERE which
......@@ -2733,28 +2819,43 @@ comment at the start of cc-engine.el for more info."
(save-excursion
(save-restriction
(widen)
(c-state-semi-trim-cache)
(c-state-semi-trim-near-cache)
(setq c-state-semi-nonlit-pos-cache-limit here)
(c-trim-lit-pos-cache)
(c-full-trim-near-cache)
(save-match-data
(let* ((base-and-state (c-state-semi-get-near-cache-entry here))
(base (car base-and-state))
(let* ((elt (c-full-get-near-cache-entry here))
(base (car elt))
(near-base base)
(s (cdr base-and-state))
(s (cadr elt))
(end (car (cddr elt)))
far-base-and-state far-base far-s ty start)
(if (or (not base)
(< base (- here 100)))
(if (or
(not base) ; FIXME!!! Compare base and far-base??
; (2019-05-21)
(not end)
(> here end))
(progn
(setq far-base-and-state (c-parse-ps-state-below here)
far-base (car far-base-and-state)
far-s (cdr far-base-and-state))
(when (or (not base) (> far-base base))
(setq base far-base
s far-s))))
(when (> here base)
s far-s
end nil))))
(when
(or
(and (> here base) (null end))
(null (nth 8 s))
(and end (> here end))
(not
(or
(and (nth 3 s) ; string
(not (eq (char-before here) ?\\)))
(and (nth 4 s) (not (nth 7 s)) ; Block comment
(not (memq (char-before here)
c-block-comment-awkward-chars)))
(and (nth 4 s) (nth 7 s) ; Line comment
(not (memq (char-before here) '(?\\ ?\n)))))))
(setq s (parse-partial-sexp base here nil nil s)))
(when (not (eq near-base here))
(c-state-semi-put-near-cache-entry here s))
(cond
((or (nth 3 s)
(and (nth 4 s)
......@@ -2764,12 +2865,16 @@ comment at the start of cc-engine.el for more info."
((nth 7 s) 'c++)
(t 'c)))
(setq start (nth 8 s))
(parse-partial-sexp here (point-max)
nil ; TARGETDEPTH
nil ; STOPBEFORE
s ; OLDSTATE
'syntax-table) ; stop at end of literal
(list s ty (cons start (point))))
(unless end
(parse-partial-sexp here (point-max)
nil ; TARGETDEPTH
nil ; STOPBEFORE
s ; OLDSTATE
'syntax-table) ; stop at end of literal
(setq end (point)))
(unless (eq near-base here)
(c-full-put-near-cache-entry here s end))
(list s ty (cons start end)))
((and (not not-in-delimiter) ; inside a comment starter
(not (bobp))
......@@ -2782,7 +2887,9 @@ comment at the start of cc-engine.el for more info."
(forward-comment 1)
(list s ty (cons start (point))))
(t (list s))))))))
(t
(c-full-put-near-cache-entry here s nil)
(list s))))))))
(defun c-state-pp-to-literal (from to &optional not-in-delimiter)
;; Do a parse-partial-sexp from FROM to TO, returning either
......@@ -2833,7 +2940,7 @@ comment at the start of cc-engine.el for more info."
(defun c-cache-to-parse-ps-state (elt)
;; Create a list suitable to use as the old-state parameter to
;; `parse-partial-sexp', out of ELT, a member of
;; `c-state-semi-nonlit-pos-cache'. ELT is either just a number, or a list
;; `c-lit-pos-cache'. ELT is either just a number, or a list
;; with 2, 3, or 4 members (See `c-parse-ps-state-to-cache'). That number
;; or the car of the list is the "position element" of ELT, the position
;; where ELT is valid.
......@@ -2890,7 +2997,7 @@ comment at the start of cc-engine.el for more info."
;; Note that as of 2019-05-27, the forms involving CHAR-1 are no longer used.
(defun c-parse-ps-state-to-cache (state)
;; Convert STATE, a `parse-partial-sexp' state valid at POINT, to an element
;; for the `c-state-semi-nonlit-pos-cache' cache. This is one of
;; for the `c-lit-pos-cache' cache. This is one of
;; o - POINT (when point is not in a literal);
;; o - (POINT CHAR-1) (when the last character before point is potentially
;; the first of a two-character construct
......@@ -2944,18 +3051,18 @@ comment at the start of cc-engine.el for more info."
(defsubst c-ps-state-cache-pos (elt)
;; Get the buffer position from ELT, an element from the cache
;; `c-state-semi-nonlit-pos-cache'.
;; `c-lit-pos-cache'.
(if (atom elt)
elt
(car elt)))
(defun c-state-semi-trim-cache ()
;; Trim the `c-state-semi-nonlit-pos-cache' to take account of buffer
;; changes, indicated by `c-state-semi-nonlit-pos-cache-limit'.
(while (and c-state-semi-nonlit-pos-cache
(> (c-ps-state-cache-pos (car c-state-semi-nonlit-pos-cache))
c-state-semi-nonlit-pos-cache-limit))
(setq c-state-semi-nonlit-pos-cache (cdr c-state-semi-nonlit-pos-cache))))
(defun c-trim-lit-pos-cache ()
;; Trim the `c-lit-pos-cache' to take account of buffer
;; changes, indicated by `c-lit-pos-cache-limit'.
(while (and c-lit-pos-cache
(> (c-ps-state-cache-pos (car c-lit-pos-cache))
c-lit-pos-cache-limit))
(setq c-lit-pos-cache (cdr c-lit-pos-cache))))
(defun c-parse-ps-state-below (here)
;; Given a buffer position HERE, Return a cons (CACHE-POS . STATE), where
......@@ -2967,8 +3074,8 @@ comment at the start of cc-engine.el for more info."
(save-excursion
(save-restriction
(widen)
(c-state-semi-trim-cache)
(let ((c c-state-semi-nonlit-pos-cache)
(c-trim-lit-pos-cache)
(let ((c c-lit-pos-cache)
elt state npos high-elt)
(while (and c (> (c-ps-state-cache-pos (car c)) here))
(setq high-elt (car c))
......@@ -2982,7 +3089,7 @@ comment at the start of cc-engine.el for more info."
(when (not high-elt)
;; We need to extend the cache. Add an element to
;; `c-state-semi-nonlit-pos-cache' each iteration of the following.
;; `c-lit-pos-cache' each iteration of the following.
(while
(<= (setq npos (+ (point) c-state-nonlit-pos-interval)) here)
(setq state (parse-partial-sexp (point) npos nil nil state))
......@@ -2999,11 +3106,11 @@ comment at the start of cc-engine.el for more info."
(setcar (nthcdr 5 state) nil)))
(setq elt (c-parse-ps-state-to-cache state))
(setq c-state-semi-nonlit-pos-cache
(cons elt c-state-semi-nonlit-pos-cache))))
(setq c-lit-pos-cache
(cons elt c-lit-pos-cache))))
(if (> (point) c-state-semi-nonlit-pos-cache-limit)
(setq c-state-semi-nonlit-pos-cache-limit (point)))
(if (> (point) c-lit-pos-cache-limit)
(setq c-lit-pos-cache-limit (point)))
(cons (point) state)))))
......@@ -3932,8 +4039,8 @@ comment at the start of cc-engine.el for more info."
c-state-cache-good-pos 1
c-state-nonlit-pos-cache nil
c-state-nonlit-pos-cache-limit 1
c-state-semi-nonlit-pos-cache nil
c-state-semi-nonlit-pos-cache-limit 1
c-lit-pos-cache nil
c-lit-pos-cache-limit 1
c-state-brace-pair-desert nil
c-state-point-min 1
c-state-point-min-lit-type nil
......@@ -3983,7 +4090,7 @@ comment at the start of cc-engine.el for more info."
;; HERE.
(if (<= here c-state-nonlit-pos-cache-limit)
(setq c-state-nonlit-pos-cache-limit (1- here)))
(c-truncate-semi-nonlit-pos-cache here)
(c-truncate-lit-pos-cache here)
;; `c-state-cache':
;; Case 1: if `here' is in a literal containing point-min, everything
......@@ -4208,8 +4315,8 @@ comment at the start of cc-engine.el for more info."
c-state-cache-good-pos
c-state-nonlit-pos-cache
c-state-nonlit-pos-cache-limit
c-state-semi-nonlit-pos-cache
c-state-semi-nonlit-pos-cache-limit
c-lit-pos-cache
c-lit-pos-cache-limit
c-state-brace-pair-desert
c-state-point-min
c-state-point-min-lit-type
......@@ -5287,7 +5394,7 @@ Note that this function might do hidden buffer changes. See the
comment at the start of cc-engine.el for more info."
(save-restriction
(widen)
(let ((lit (c-state-semi-pp-to-literal (point))))
(let ((lit (c-semi-pp-to-literal (point))))
(or (cadr lit)
(and detect-cpp
(save-excursion (c-beginning-of-macro))
......@@ -5322,7 +5429,7 @@ comment at the start of cc-engine.el for more info."
s
'syntax-table)
(point)))))
(let ((pp-to-lit (c-state-full-pp-to-literal pos not-in-delimiter)))
(let ((pp-to-lit (c-full-pp-to-literal pos not-in-delimiter)))
(car (cddr pp-to-lit))))))
(cond
(lit-limits)
......@@ -5371,7 +5478,7 @@ a known \"safe position\", i.e. outside of any string or comment."
(and (or (nth 3 s)
(and (nth 4 s) (not (eq (nth 7 s) 'syntax-table))))
(nth 8 s)))
(car (cddr (c-state-semi-pp-to-literal (point))))))
(car (cddr (c-semi-pp-to-literal (point))))))
;; In case external callers use this; it did have a docstring.
(defalias 'c-literal-limits-fast 'c-literal-limits)
......@@ -5442,7 +5549,7 @@ comment at the start of cc-engine.el for more info."
(c-backward-syntactic-ws)
(setq start (point))
(let* ((pos (max (- start try-size) (point-min)))
(s (c-state-semi-pp-to-literal pos))
(s (c-semi-pp-to-literal pos))
(cand (or (car (cddr s)) pos)))
(if (>= cand (point-min))
cand
......@@ -6836,7 +6943,7 @@ comment at the start of cc-engine.el for more info."
;;
;; Note: this function is dependant upon the correct syntax-table text
;; properties being set.
(let ((state (c-state-semi-pp-to-literal (point)))
(let ((state (c-semi-pp-to-literal (point)))
open-quote-pos open-paren-pos close-paren-pos close-quote-pos id)
(save-excursion
(when
......@@ -6917,7 +7024,7 @@ comment at the start of cc-engine.el for more info."
;; the 'syntax-table property from all of them.
(setq first (c-clear-char-property-with-value-on-char
open-quote open-paren 'syntax-table '(1) ?\"))
(if first (c-truncate-semi-nonlit-pos-cache first))
(if first (c-truncate-lit-pos-cache first))
(cond
((null open-paren-prop)
;; Should be a terminated raw string...
......@@ -6927,7 +7034,7 @@ comment at the start of cc-engine.el for more info."
(setq first (c-clear-char-property-with-value-on-char
(1+ (match-beginning 0)) (1- (match-end 0))
'syntax-table '(1) ?\"))
(if first (c-truncate-semi-nonlit-pos-cache first))
(if first (c-truncate-lit-pos-cache first))
;; Clear any random `syntax-table' text properties from the contents.
(let* ((closing-paren (match-beginning 0))
(first-st
......@@ -6945,7 +7052,7 @@ comment at the start of cc-engine.el for more info."
(when first-st
(c-clear-char-properties first-st (match-beginning 0)
'syntax-table)
(c-truncate-semi-nonlit-pos-cache first-st))
(c-truncate-lit-pos-cache first-st))
(when (c-get-char-property (1- (match-end 0)) 'syntax-table)
;; Was previously an unterminated (ordinary) string
(save-excursion
......@@ -6953,19 +7060,19 @@ comment at the start of cc-engine.el for more info."
(when (c-safe (c-forward-sexp)) ; to '(1) at EOL.
(c-clear-char-property (1- (point)) 'syntax-table))
(c-clear-char-property (1- (match-end 0)) 'syntax-table)
(c-truncate-semi-nonlit-pos-cache (1- (match-end 0))))))))
(c-truncate-lit-pos-cache (1- (match-end 0))))))))
((or (and (equal open-paren-prop '(15)) (null bound))
(equal open-paren-prop '(1)))
;; An unterminated raw string either not in a macro, or in a macro with
;; the open parenthesis right up against the end of macro
(c-clear-char-property open-quote 'syntax-table)
(c-truncate-semi-nonlit-pos-cache open-quote)
(c-truncate-lit-pos-cache open-quote)
(c-clear-char-property open-paren 'syntax-table))
(t
;; An unterminated string in a macro, with at least one char after the
;; open paren
(c-clear-char-property open-quote 'syntax-table)
(c-truncate-semi-nonlit-pos-cache open-quote)
(c-truncate-lit-pos-cache open-quote)
(c-clear-char-property open-paren 'syntax-table)
(c-clear-char-property-with-value (1+ open-paren) bound 'syntax-table
'(15))))))
......@@ -7085,7 +7192,7 @@ comment at the start of cc-engine.el for more info."
(while (and (skip-chars-forward "^\"" end)
(< (point) end))
(c-put-char-property (point) 'syntax-table '(1))
(c-truncate-semi-nonlit-pos-cache (point))
(c-truncate-lit-pos-cache (point))
(forward-char))))
(defun c-propertize-raw-string-opener (id open-quote open-paren bound)
......@@ -7112,12 +7219,12 @@ comment at the start of cc-engine.el for more info."
(while (progn (skip-syntax-forward "^\"" end-string)
(< (point) end-string))
(c-put-char-property (point) 'syntax-table '(1)) ; punctuation
(c-truncate-semi-nonlit-pos-cache (point))
(c-truncate-lit-pos-cache (point))
(forward-char))
(goto-char after-quote)
t)
(c-put-char-property open-quote 'syntax-table '(1)) ; punctuation
(c-truncate-semi-nonlit-pos-cache open-quote)
(c-truncate-lit-pos-cache open-quote)
(c-put-char-property open-paren 'syntax-table '(15)) ; generic string
(when bound
;; In a CPP construct, we try to apply a generic-string
......@@ -7148,10 +7255,10 @@ comment at the start of cc-engine.el for more info."
(if (match-beginning 10)
(progn
(c-put-char-property (match-beginning 10) 'syntax-table '(15))
(c-truncate-semi-nonlit-pos-cache (match-beginning 10)))
(c-truncate-lit-pos-cache (match-beginning 10)))
(c-put-char-property (match-beginning 5) 'syntax-table '(1))
(c-put-char-property (1+ (match-beginning 5)) 'syntax-table '(15))
(c-truncate-semi-nonlit-pos-cache (1+ (match-beginning 5))))
(c-truncate-lit-pos-cache (1+ (match-beginning 5))))
;; (c-put-char-property open-paren 'syntax-table '(1))
)
(goto-char bound))
......@@ -7179,7 +7286,7 @@ comment at the start of cc-engine.el for more info."
(setq eoll (c-point 'eoll))
(when (and (null c-old-END-literality)
(search-forward-regexp c-c++-raw-string-opener-re eoll t))
(setq state (c-state-semi-pp-to-literal end))
(setq state (c-semi-pp-to-literal end))
(when (eq (cadr state) 'string)
(unwind-protect
;; Temporarily insert a closing string delimiter....
......@@ -7191,7 +7298,7 @@ comment at the start of cc-engine.el for more info."
((eq (nth 3 (car state)) t)
(insert ?\")
(c-put-char-property end 'syntax-table '(15))))
(c-truncate-semi-nonlit-pos-cache end)
(c-truncate-lit-pos-cache end)
;; ....ensure c-new-END extends right to the end of the about
;; to be un-stringed raw string....
(save-excursion
......@@ -7231,7 +7338,7 @@ comment at the start of cc-engine.el for more info."
(goto-char (1- (cadr c-old-beg-rs)))
(unless (looking-at c-c++-raw-string-opener-re)
(c-clear-char-property (1+ (point)) 'syntax-table)
(c-truncate-semi-nonlit-pos-cache (1+ (point)))
(c-truncate-lit-pos-cache (1+ (point)))
(if (c-search-forward-char-property 'syntax-table '(15)
(c-point 'eol))
(c-clear-char-property (1- (point)) 'syntax-table))))
......@@ -7250,7 +7357,7 @@ comment at the start of cc-engine.el for more info."
(setq c-new-END (point-max))
(c-clear-char-properties (cadr c-old-beg-rs) c-new-END
'syntax-table)
(c-truncate-semi-nonlit-pos-cache (cadr c-old-beg-rs)))))
(c-truncate-lit-pos-cache (cadr c-old-beg-rs)))))
;; Have we terminated an existing raw string by inserting or removing
;; text?
(when (eq c-old-END-literality 'string)
......@@ -7268,13 +7375,13 @@ comment at the start of cc-engine.el for more info."
(while
(and
(setq found (search-backward (concat "R\"" id "(") nil t))
(setq state (c-state-semi-pp-to-literal (point)))
(setq state (c-semi-pp-to-literal (point)))
(memq (nth 3 (car state)) '(t ?\"))))
(when found
(setq c-new-BEG (min (point) c-new-BEG)
c-new-END (point-max))
(c-clear-char-properties (point) c-new-END 'syntax-table)
(c-truncate-semi-nonlit-pos-cache (point)))))
(c-truncate-lit-pos-cache (point)))))
;; Are there any raw strings in a newly created macro?
(when (< beg end)
......
......@@ -1681,7 +1681,7 @@ casts and declarations are fontified. Used on level 2 and higher."
;; font-lock-keyword-face. It always returns NIL to inhibit this and
;; prevent a repeat invocation. See elisp/lispref page "Search-based
;; Fontification".
(let* ((state (c-state-semi-pp-to-literal (point)))
(let* ((state (c-semi-pp-to-literal (point)))
(string-start (and (eq (cadr state) 'string)
(car (cddr state))))
(raw-id (and string-start
......
......@@ -1219,7 +1219,7 @@ Note that the style variables are always made local to the buffer."
(point-max) t t)
(progn
(c-clear-char-property (1- (point)) 'syntax-table)
(c-truncate-semi-nonlit-pos-cache (1- (point)))
(c-truncate-lit-pos-cache (1- (point)))
(not (memq (char-before) c-string-delims)))))
(memq (char-before) c-string-delims))
(progn
......@@ -1257,14 +1257,14 @@ Note that the style variables are always made local to the buffer."
(backward-sexp)
(c-clear-char-property eoll-1 'syntax-table)
(c-clear-char-property (point) 'syntax-table)
(c-truncate-semi-nonlit-pos-cache (point)))
(c-truncate-lit-pos-cache (point)))
;; Opening " at EOB.
(c-clear-char-property (1- (point)) 'syntax-table))
(when (and (c-search-backward-char-property 'syntax-table '(15) c-new-BEG)
(memq (char-after) c-string-delims)) ; Ignore an unterminated raw string's (.
;; Opening " on last line of text (without EOL).
(c-clear-char-property (point) 'syntax-table)
(c-truncate-semi-nonlit-pos-cache (point))
(c-truncate-lit-pos-cache (point))
(setq c-new-BEG (min c-new-BEG (point))))))
(t (goto-char end) ; point-max
......@@ -1273,7 +1273,7 @@ Note that the style variables are always made local to the buffer."
(c-search-backward-char-property 'syntax-table '(15) c-new-BEG)
(memq (char-after) c-string-delims))
(c-clear-char-property (point) 'syntax-table)
(c-truncate-semi-nonlit-pos-cache (point)))))
(c-truncate-lit-pos-cache (point)))))
(unless
(or (and
......@@ -1285,13 +1285,13 @@ Note that the style variables are always made local to the buffer."
(when (and (eq end-literal-type 'string)
(not (eq (char-before (cdr end-limits)) ?\()))
(c-clear-char-property (1- (cdr end-limits)) 'syntax-table)
(c-truncate-semi-nonlit-pos-cache (1- (cdr end-limits)))
(c-truncate-lit-pos-cache (1- (cdr end-limits)))
(setq c-new-END (max c-new-END (cdr end-limits))))
(when (and (eq beg-literal-type 'string)
(memq (char-after (car beg-limits)) c-string-delims))
(c-clear-char-property (car beg-limits) 'syntax-table)
(c-truncate-semi-nonlit-pos-cache (car beg-limits))
(c-truncate-lit-pos-cache (car beg-limits))
(setq c-new-BEG (min c-new-BEG (car beg-limits)))))))