aboutsummaryrefslogtreecommitdiffstats
path: root/lisp
diff options
context:
space:
mode:
authorAlan Mackenzie2010-05-21 19:51:48 +0000
committerAlan Mackenzie2010-05-21 19:51:48 +0000
commitc0209c2c68aeb23ce0480d42e4bfcc7fd13ce374 (patch)
treecd87ee4566280563e0a1a42c7a9c28406239c43d /lisp
parent98fe5161c42a5ec64df3d0418f918a5ab8c909d6 (diff)
downloademacs-c0209c2c68aeb23ce0480d42e4bfcc7fd13ce374.tar.gz
emacs-c0209c2c68aeb23ce0480d42e4bfcc7fd13ce374.zip
Fix a bug which happens when doing (c-parse-state) in a CPP construct:
Exclude any "new" CPP construct from taking part in the scanning.
Diffstat (limited to 'lisp')
-rw-r--r--lisp/ChangeLog9
-rw-r--r--lisp/progmodes/cc-engine.el169
2 files changed, 102 insertions, 76 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 3671e2461aa..7c0fb21483f 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,12 @@
12010-05-21 Alan Mackenzie <acm@muc.de>
2
3 * progmodes/cc-engine.el (c-parse-state-get-strategy): Replace
4 parameter `here' with `here-' and `here-plus', which sandwich any
5 pertinent CPP construct.
6 (c-remove-stale-state-cache-backwards): Fix a bug which happens
7 when doing (c-parse-state) in a CPP construct: Exclude any "new"
8 CPP construct from taking part in the scanning.
9
12010-05-21 Michael Albinus <michael.albinus@gmx.de> 102010-05-21 Michael Albinus <michael.albinus@gmx.de>
2 11
3 * net/tramp.el (tramp-do-copy-or-rename-file) 12 * net/tramp.el (tramp-do-copy-or-rename-file)
diff --git a/lisp/progmodes/cc-engine.el b/lisp/progmodes/cc-engine.el
index 2d28d003fd5..1ee3c295fe1 100644
--- a/lisp/progmodes/cc-engine.el
+++ b/lisp/progmodes/cc-engine.el
@@ -2245,50 +2245,50 @@ comment at the start of cc-engine.el for more info."
2245 (setq cnt (1- cnt))))) 2245 (setq cnt (1- cnt)))))
2246 (point))) 2246 (point)))
2247 2247
2248(defun c-state-balance-parens-backwards (here top) 2248(defun c-state-balance-parens-backwards (here- here+ top)
2249 ;; Return the position of the opening paren/brace/bracket before HERE which 2249 ;; Return the position of the opening paren/brace/bracket before HERE- which
2250 ;; matches the outermost close p/b/b between HERE and TOP, like this: 2250 ;; matches the outermost close p/b/b between HERE+ and TOP. Except when
2251 ;; 2251 ;; there's a macro, HERE- and HERE+ are the same. Like this:
2252 ;; ...................................... 2252 ;;
2253 ;; | | 2253 ;; ............................................
2254 ;; ( [ ( ........... ) ( ) ] ) 2254 ;; | |
2255 ;; ^ ^ ^ 2255 ;; ( [ ( .........#macro.. ) ( ) ] )
2256 ;; | | | 2256 ;; ^ ^ ^ ^
2257 ;; return HERE TOP 2257 ;; | | | |
2258 ;; return HERE- HERE+ TOP
2258 ;; 2259 ;;
2259 ;; If there aren't enough opening paren/brace/brackets, return the position 2260 ;; If there aren't enough opening paren/brace/brackets, return the position
2260 ;; of the outermost one found, or HERE it there are none. If there are no 2261 ;; of the outermost one found, or HERE- if there are none. If there are no
2261 ;; closeing p/b/bs between HERE and TOP, return HERE. HERE and TOP must not 2262 ;; closeing p/b/bs between HERE+ and TOP, return HERE-. HERE-/+ and TOP
2262 ;; be inside literals. Only the accessible portion of the buffer will be 2263 ;; must not be inside literals. Only the accessible portion of the buffer
2263 ;; scanned. 2264 ;; will be scanned.
2264 2265
2265 ;; PART 1: scan from `here' up to `top', accumulating ")"s which enclose 2266 ;; PART 1: scan from `here+' up to `top', accumulating ")"s which enclose
2266 ;; `here'. Go round the next loop each time we pass over such a ")". These 2267 ;; `here'. Go round the next loop each time we pass over such a ")". These
2267 ;; probably match "("s before `here'. 2268 ;; probably match "("s before `here-'.
2268 (let (pos pa ren+1 lonely-rens) 2269 (let (pos pa ren+1 lonely-rens)
2269 (save-excursion 2270 (save-excursion
2270 (save-restriction 2271 (save-restriction
2271 (narrow-to-region (point-min) top) ; This can move point, sometimes. 2272 (narrow-to-region (point-min) top) ; This can move point, sometimes.
2272 (setq pos here) 2273 (setq pos here+)
2273 (c-safe 2274 (c-safe
2274 (while 2275 (while
2275 (setq ren+1 (scan-lists pos 1 1)) ; might signal 2276 (setq ren+1 (scan-lists pos 1 1)) ; might signal
2276 (setq lonely-rens (cons ren+1 lonely-rens) 2277 (setq lonely-rens (cons ren+1 lonely-rens)
2277 pos ren+1))))) 2278 pos ren+1)))))
2278 2279
2279 ;; PART 2: Scan back before `here' searching for the "("s 2280 ;; PART 2: Scan back before `here-' searching for the "("s
2280 ;; matching/mismatching the ")"s found above. We only need to direct the 2281 ;; matching/mismatching the ")"s found above. We only need to direct the
2281 ;; caller to scan when we've encountered unmatched right parens. 2282 ;; caller to scan when we've encountered unmatched right parens.
2282 (when lonely-rens 2283 (setq pos here-)
2283 (setq pos here) 2284 (when lonely-rens
2284 (c-safe 2285 (c-safe
2285 (while 2286 (while
2286 (and lonely-rens ; actual values aren't used. 2287 (and lonely-rens ; actual values aren't used.
2287 (setq pa (scan-lists pos -1 1))) 2288 (setq pa (scan-lists pos -1 1)))
2288 (setq pos pa) 2289 (setq pos pa)
2289 (setq lonely-rens (cdr lonely-rens)))) ;) 2290 (setq lonely-rens (cdr lonely-rens)))))
2290 ) 2291 pos))
2291 pos))
2292 2292
2293(defun c-parse-state-get-strategy (here good-pos) 2293(defun c-parse-state-get-strategy (here good-pos)
2294 ;; Determine the scanning strategy for adjusting `c-parse-state', attempting 2294 ;; Determine the scanning strategy for adjusting `c-parse-state', attempting
@@ -2746,6 +2746,7 @@ comment at the start of cc-engine.el for more info."
2746 lit ; (START . END) of a literal containing some point. 2746 lit ; (START . END) of a literal containing some point.
2747 here-lit-start here-lit-end ; bounds of literal containing `here' 2747 here-lit-start here-lit-end ; bounds of literal containing `here'
2748 ; or `here' itself. 2748 ; or `here' itself.
2749 here- here+ ; start/end of macro around HERE, or HERE
2749 (here-bol (c-point 'bol here)) 2750 (here-bol (c-point 'bol here))
2750 (too-far-back (max (- here c-state-cache-too-far) 1))) 2751 (too-far-back (max (- here c-state-cache-too-far) 1)))
2751 2752
@@ -2758,57 +2759,73 @@ comment at the start of cc-engine.el for more info."
2758 ;; At this stage, (> pos here); 2759 ;; At this stage, (> pos here);
2759 ;; (< (c-state-cache-top-lparen) here) (or is nil). 2760 ;; (< (c-state-cache-top-lparen) here) (or is nil).
2760 2761
2761 ;; CASE 1: The top of the cache is a brace pair which now encloses `here'. 2762 (cond
2762 ;; As good-pos, return the address. of the "{". 2763 ((and (consp (car c-state-cache))
2763 (if (and (consp (car c-state-cache)) 2764 (> (cdar c-state-cache) here))
2764 (> (cdar c-state-cache) here)) 2765 ;; CASE 1: The top of the cache is a brace pair which now encloses
2765 ;; Since we've no knowledge of what's inside these braces, we have no 2766 ;; `here'. As good-pos, return the address. of the "{". Since we've no
2766 ;; alternative but to direct the caller to scan the buffer from the 2767 ;; knowledge of what's inside these braces, we have no alternative but
2767 ;; opening brace. 2768 ;; to direct the caller to scan the buffer from the opening brace.
2768 (progn 2769 (setq pos (caar c-state-cache))
2769 (setq pos (caar c-state-cache)) 2770 (setcar c-state-cache pos)
2770 (setcar c-state-cache pos) 2771 (list (1+ pos) pos t)) ; return value. We've just converted a brace pair
2771 (list (1+ pos) pos t)) ; return value. We've just converted a brace 2772 ; entry into a { entry, so the caller needs to
2772 ; pair entry into a { entry, so the caller 2773 ; search for a brace pair before the {.
2773 ; needs to search for a brace pair before the 2774
2774 ; {. 2775 ;; `here' might be inside a literal. Check for this.
2775 2776 ((progn
2776 ;; ;; `here' might be inside a literal. Check for this. 2777 (setq lit (c-state-literal-at here)
2777 (setq lit (c-state-literal-at here) 2778 here-lit-start (or (car lit) here)
2778 here-lit-start (or (car lit) here) 2779 here-lit-end (or (cdr lit) here))
2779 here-lit-end (or (cdr lit) here)) 2780 ;; Has `here' just "newly entered" a macro?
2780 2781 (save-excursion
2781 ;; `here' might be nested inside any depth of parens (or brackets but 2782 (goto-char here-lit-start)
2782 ;; not braces). Scan backwards to find the outermost such opening 2783 (if (and (c-beginning-of-macro)
2783 ;; paren, if there is one. This will be the scan position to return. 2784 (or (null c-state-old-cpp-beg)
2784 (save-restriction 2785 (not (= (point) c-state-old-cpp-beg))))
2785 (narrow-to-region cache-pos (point-max)) 2786 (progn
2786 (setq pos (c-state-balance-parens-backwards here-lit-end pos))) 2787 (setq here- (point))
2787 2788 (c-end-of-macro)
2788 (if (< pos here-lit-start) 2789 (setq here+ (point)))
2789 ;; CASE 2: Address of outermost ( or [ which now encloses `here', 2790 (setq here- here-lit-start
2790 ;; but didn't enclose the (previous) `c-state-cache-good-pos'. If 2791 here+ here-lit-end)))
2791 ;; there is a brace pair preceding this, it will already be in 2792
2792 ;; `c-state-cache', unless there was a brace pair after it, 2793 ;; `here' might be nested inside any depth of parens (or brackets but
2793 ;; i.e. there'll only be one to scan for if we've just deleted one. 2794 ;; not braces). Scan backwards to find the outermost such opening
2794 (list pos (and dropped-cons pos) t) ; Return value. 2795 ;; paren, if there is one. This will be the scan position to return.
2795 2796 (save-restriction
2796 ;; `here' isn't enclosed in a (previously unrecorded) bracket/paren. 2797 (narrow-to-region cache-pos (point-max))
2797 ;; Further forward scanning isn't needed, but we still need to find a 2798 (setq pos (c-state-balance-parens-backwards here- here+ pos)))
2798 ;; GOOD-POS. Step out of all enclosing "("s on HERE's line. 2799 nil)) ; for the cond
2800
2801 ((< pos here-lit-start)
2802 ;; CASE 2: Address of outermost ( or [ which now encloses `here', but
2803 ;; didn't enclose the (previous) `c-state-cache-good-pos'. If there is
2804 ;; a brace pair preceding this, it will already be in `c-state-cache',
2805 ;; unless there was a brace pair after it, i.e. there'll only be one to
2806 ;; scan for if we've just deleted one.
2807 (list pos (and dropped-cons pos) t)) ; Return value.
2808
2809 ;; `here' isn't enclosed in a (previously unrecorded) bracket/paren.
2810 ;; Further forward scanning isn't needed, but we still need to find a
2811 ;; GOOD-POS. Step out of all enclosing "("s on HERE's line.
2812 ((progn
2799 (save-restriction 2813 (save-restriction
2800 (narrow-to-region here-bol (point-max)) 2814 (narrow-to-region here-bol (point-max))
2801 (setq pos here-lit-start) 2815 (setq pos here-lit-start)
2802 (c-safe (while (setq pa (scan-lists pos -1 1)) 2816 (c-safe (while (setq pa (scan-lists pos -1 1))
2803 (setq pos pa)))) ; might signal 2817 (setq pos pa)))) ; might signal
2804 (if (setq ren (c-safe-scan-lists pos -1 -1 too-far-back)) 2818 nil)) ; for the cond
2805 ;; CASE 3: After a }/)/] before `here''s BOL. 2819
2806 (list (1+ ren) (and dropped-cons pos) nil) ; Return value 2820 ((setq ren (c-safe-scan-lists pos -1 -1 too-far-back))
2807 2821 ;; CASE 3: After a }/)/] before `here''s BOL.
2808 ;; CASE 4; Best of a bad job: BOL before `here-bol', or beginning of 2822 (list (1+ ren) (and dropped-cons pos) nil)) ; Return value
2809 ;; literal containing it. 2823
2810 (setq good-pos (c-state-lit-beg (c-point 'bopl here-bol))) 2824 (t
2811 (list good-pos (and dropped-cons good-pos) nil)))))) 2825 ;; CASE 4; Best of a bad job: BOL before `here-bol', or beginning of
2826 ;; literal containing it.
2827 (setq good-pos (c-state-lit-beg (c-point 'bopl here-bol)))
2828 (list good-pos (and dropped-cons good-pos) nil)))))
2812 2829
2813 2830
2814;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 2831;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;