summaryrefslogtreecommitdiff
path: root/lisp/progmodes/cc-mode.el
diff options
context:
space:
mode:
authorAlan Mackenzie <acm@muc.de>2023-01-17 18:15:45 +0000
committerAlan Mackenzie <acm@muc.de>2023-01-17 18:15:45 +0000
commitdbac923b9df97706d3944c21edfc9117b408d80c (patch)
tree3d9d2651c6df46374078d96613b051febad4871f /lisp/progmodes/cc-mode.el
parent56d69c2fc4782dc23bd79ddcbccfbae9b263ecac (diff)
downloademacs-dbac923b9df97706d3944c21edfc9117b408d80c.tar.gz
emacs-dbac923b9df97706d3944c21edfc9117b408d80c.tar.bz2
emacs-dbac923b9df97706d3944c21edfc9117b408d80c.zip
CC Mode: On removal of "typedef", remove pertinent types from c-found-types
For this purpose, record the type names declared by typedef in a text property, c-typedef, on the typedef. On any change to that "typedef" or a type, remove the old identifier(s) from c-found-types. This should fix bug #59671. * lisp/progmodes/cc-defs.el (c-search-forward-non-nil-char-property): New macro. * lisp/progmodes/cc-engine.el (c-forward-decl-or-cast-1): Move the scope of identifier-start from the "inner" let form to the outer one. Amend the return value such that the middle element of the second element is now the position of the "typedef", not merely non-nil. * lisp/progmodes/cc-fonts.el (c-font-lock-declarators): Disregard the LIMIT parameter when fontifying the declarators of a typedef construct. Also in this case, set the c-typedef text property on the "typedef" to the list of declared types. Amend this list when these declared types change. (c-font-lock-single-decl): Massage the `types' argument given to c-font-lock-declarators. (c-font-lock-cut-off-declarators): Amend to work when the starting point of the fontification is inside a brace block. * lisp/progmodes/cc-mode.el (c-before-change-de-typedef) (c-after-change-de-typedef): New functions. (c-update-new-id): Replace the erroneous c-end-of-current-token with a clause containing c-forward-token-2. (c-before-change): Call c-before-change-de-typedef. (c-after-change): Call c-after-change-de-typedef.
Diffstat (limited to 'lisp/progmodes/cc-mode.el')
-rw-r--r--lisp/progmodes/cc-mode.el40
1 files changed, 39 insertions, 1 deletions
diff --git a/lisp/progmodes/cc-mode.el b/lisp/progmodes/cc-mode.el
index b04ed7584c4..330202bb5f9 100644
--- a/lisp/progmodes/cc-mode.el
+++ b/lisp/progmodes/cc-mode.el
@@ -2077,6 +2077,37 @@ with // and /*, not more generic line and block comments."
(not (eobp))))
(forward-char))))))
+(defun c-before-change-de-typedef (beg end)
+ ;; For each "typedef" starting in (BEG END), remove the defined types from
+ ;; c-found-types
+ (let (prop)
+ (save-excursion
+ (goto-char beg)
+ (while (and (< (point) end)
+ (setq prop (c-search-forward-non-nil-char-property
+ 'c-typedef)))
+ (dolist (type prop)
+ (c-unfind-type type))))))
+
+(defun c-after-change-de-typedef (beg end _old-len)
+ ;; For each former "typedef" in (BEG END), remove the defined types from
+ ;; those which are no longer typedefs.
+ (let (prop)
+ (save-excursion
+ (goto-char beg)
+ (c-backward-token-2
+ 1 nil (- (point) 20))
+ (while (and (< (point) end)
+ (setq prop (c-search-forward-non-nil-char-property
+ 'c-typedef end)))
+ (backward-char)
+ (when (or (not (looking-at c-typedef-key))
+ (<= (match-end 1) beg))
+ (dolist (type prop)
+ (c-unfind-type type))
+ (c-clear-char-property (point) 'c-typedef))
+ (forward-char)))))
+
(defun c-update-new-id (end)
;; Note the bounds of any identifier that END is in or just after, in
;; `c-new-id-start' and `c-new-id-end'. Otherwise set these variables to
@@ -2086,7 +2117,9 @@ with // and /*, not more generic line and block comments."
(let ((id-beg (c-on-identifier)))
(setq c-new-id-start id-beg
c-new-id-end (and id-beg
- (progn (c-end-of-current-token) (point)))
+ (progn (goto-char id-beg)
+ (c-forward-token-2)
+ (point)))
c-new-id-is-type nil))))
(defun c-post-command ()
@@ -2215,6 +2248,10 @@ with // and /*, not more generic line and block comments."
term-pos)
(buffer-substring-no-properties beg end)))))))
+ ;; If we're about to delete "typedef"s, clear the identifiers from
+ ;; `c-found-types'.
+ (c-before-change-de-typedef beg end)
+
(if c-get-state-before-change-functions
(mapc (lambda (fn)
(funcall fn beg end))
@@ -2306,6 +2343,7 @@ with // and /*, not more generic line and block comments."
(c-update-new-id end)
(c-trim-found-types beg end old-len) ; maybe we don't
; need all of these.
+ (c-after-change-de-typedef beg end old-len)
(c-invalidate-sws-region-after beg end old-len)
;; (c-invalidate-state-cache beg) ; moved to
;; `c-before-change'.