From: Alan Mackenzie Date: Mon, 21 Feb 2011 21:25:35 +0000 (+0000) Subject: (c-state-literal-at): Prevent positions in macros finding their way into X-Git-Url: https://git.hcoop.net/bpt/emacs.git/commitdiff_plain/e84efb7078b7251b8c8bf15f71fed653cfa535a5 (c-state-literal-at): Prevent positions in macros finding their way into c-state-nonlit-pos-cache. Strengthen the comments. (c-state-dump): New commented out diagnostic routine. --- diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 05c765e088..e4b30dfa31 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,11 @@ +2011-02-21 Alan Mackenzie + + Fix bug #7930. + * progmodes/cc-engine.el (c-state-literal-at): Prevent positions + in macros finding their way into c-state-nonlit-pos-cache. + Strengthen the comments. + (c-state-dump): New commented out diagnostic routine. + 2011-02-21 Michael Albinus * net/tramp.el (tramp-rfn-eshadow-setup-minibuffer): Do not use diff --git a/lisp/progmodes/cc-engine.el b/lisp/progmodes/cc-engine.el index de1debd645..654323e03e 100644 --- a/lisp/progmodes/cc-engine.el +++ b/lisp/progmodes/cc-engine.el @@ -2023,9 +2023,9 @@ comment at the start of cc-engine.el for more info." (defvar c-state-nonlit-pos-cache nil) (make-variable-buffer-local 'c-state-nonlit-pos-cache) -;; A list of buffer positions which are known not to be in a literal. This is -;; ordered with higher positions at the front of the list. Only those which -;; are less than `c-state-nonlit-pos-cache-limit' are valid. +;; A list of buffer positions which are known not to be in a literal or a cpp +;; construct. This is ordered with higher positions at the front of the list. +;; Only those which are less than `c-state-nonlit-pos-cache-limit' are valid. (defvar c-state-nonlit-pos-cache-limit 1) (make-variable-buffer-local 'c-state-nonlit-pos-cache-limit) @@ -2056,6 +2056,12 @@ comment at the start of cc-engine.el for more info." ;; This function is almost the same as `c-literal-limits'. It differs in ;; that it is a lower level function, and that it rigourously follows the ;; syntax from BOB, whereas `c-literal-limits' uses a "local" safe position. + ;; + ;; NOTE: This function manipulates `c-state-nonlit-pos-cache'. This cache + ;; MAY NOT contain any positions within macros, since macros are frequently + ;; turned into comments by use of the `c-cpp-delimiter' category properties. + ;; We cannot rely on this mechanism whilst determining a cache pos since + ;; this function is also called from outwith `c-parse-state'. (save-restriction (widen) (save-excursion @@ -2074,6 +2080,11 @@ comment at the start of cc-engine.el for more info." here) (setq lit (c-state-pp-to-literal pos npos)) (setq pos (or (cdr lit) npos)) ; end of literal containing npos. + (goto-char pos) + (when (and (c-beginning-of-macro) (/= (point) pos)) + (c-syntactic-end-of-macro) + (or (eobp) (forward-char)) + (setq pos (point))) (setq c-state-nonlit-pos-cache (cons pos c-state-nonlit-pos-cache))) (if (> pos c-state-nonlit-pos-cache-limit) @@ -2158,7 +2169,7 @@ comment at the start of cc-engine.el for more info." ;; of fruitless backward scans. (defvar c-state-brace-pair-desert nil) (make-variable-buffer-local 'c-state-brace-pair-desert) -;; Used only in `c-append-lower-brace-pair-to-state-cache'. It is set when an +;; Used only in `c-append-lower-brace-pair-to-state-cache'. It is set when ;; that defun has searched backwards for a brace pair and not found one. Its ;; value is either nil or a cons (PA . FROM), where PA is the position of the ;; enclosing opening paren/brace/bracket which bounds the backwards search (or @@ -2843,6 +2854,29 @@ comment at the start of cc-engine.el for more info." c-state-old-cpp-end nil) (c-state-mark-point-min-literal)) +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; Debugging routines to dump `c-state-cache' in a "replayable" form. +;; (defmacro c-sc-de (elt) ; "c-state-cache-dump-element" +;; `(format ,(concat "(setq " (symbol-name elt) " %s) ") ,elt)) +;; (defmacro c-sc-qde (elt) ; "c-state-cache-quote-dump-element" +;; `(format ,(concat "(setq " (symbol-name elt) " '%s) ") ,elt)) +;; (defun c-state-dump () +;; ;; For debugging. +;; ;(message +;; (concat +;; (c-sc-qde c-state-cache) +;; (c-sc-de c-state-cache-good-pos) +;; (c-sc-qde c-state-nonlit-pos-cache) +;; (c-sc-de c-state-nonlit-pos-cache-limit) +;; (c-sc-qde c-state-brace-pair-desert) +;; (c-sc-de c-state-point-min) +;; (c-sc-de c-state-point-min-lit-type) +;; (c-sc-de c-state-point-min-lit-start) +;; (c-sc-de c-state-min-scan-pos) +;; (c-sc-de c-state-old-cpp-beg) +;; (c-sc-de c-state-old-cpp-end))) +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + (defun c-invalidate-state-cache-1 (here) ;; Invalidate all info on `c-state-cache' that applies to the buffer at HERE ;; or higher and set `c-state-cache-good-pos' accordingly. The cache is