aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlan Mackenzie2017-01-21 15:14:15 +0000
committerAlan Mackenzie2017-01-21 15:16:49 +0000
commitde3336051ef74e0c3069374ced5b5fc7bb9fba15 (patch)
tree8517f111c357081d0eee84ba92e0f9ea28565c2a
parent6a788d2fc18c23dcfc5d0352649b2f690e9cbff7 (diff)
downloademacs-de3336051ef74e0c3069374ced5b5fc7bb9fba15.tar.gz
emacs-de3336051ef74e0c3069374ced5b5fc7bb9fba15.zip
Fix low-level handling of (big) C macros.
In particular, ensure that a comment detected by its syntax is not a CPP construct marked with generic comment delimiter syntax-table text properties. * lisp/progmodes/cc-engine.el (c-beginning-of-macro, c-end-of-macro): Set c-macro-cache-syntactic to nil when the cached macro changes. (c-syntactic-end-of-macro, c-no-comment-end-of-macro) (c-state-semi-pp-to-literal, c-state-full-pp-to-literal) (c-state-pp-to-literal, c-parse-ps-state-to-cache) (c-state-cache-non-literal-place, c-literal-limits, c-literal-start) (c-determine-limit): When checking a parse syntax for a comment, check that we're not in a CPP construct marked by syntax-table generic comment delimiter text property. (c-state-pp-to-literal): Change from a defsubst to a defun. * lisp/progmodes/cc-mode.el (c-neutralize-syntax-in-and-mark-CPP): Check a parse syntax as described above under cc-engine.el.
-rw-r--r--lisp/progmodes/cc-engine.el48
-rw-r--r--lisp/progmodes/cc-mode.el3
2 files changed, 34 insertions, 17 deletions
diff --git a/lisp/progmodes/cc-engine.el b/lisp/progmodes/cc-engine.el
index e84c4cebf69..fd7aa50840f 100644
--- a/lisp/progmodes/cc-engine.el
+++ b/lisp/progmodes/cc-engine.el
@@ -313,7 +313,8 @@ comment at the start of cc-engine.el for more info."
313 (c-macro-is-genuine-p)) 313 (c-macro-is-genuine-p))
314 (progn 314 (progn
315 (setq c-macro-cache (cons (point) nil) 315 (setq c-macro-cache (cons (point) nil)
316 c-macro-cache-start-pos here) 316 c-macro-cache-start-pos here
317 c-macro-cache-syntactic nil)
317 t) 318 t)
318 (goto-char here) 319 (goto-char here)
319 nil)))))) 320 nil))))))
@@ -344,7 +345,8 @@ comment at the start of cc-engine.el for more info."
344 (forward-char) 345 (forward-char)
345 t))) 346 t)))
346 (when (car c-macro-cache) 347 (when (car c-macro-cache)
347 (setcdr c-macro-cache (point))))) 348 (setcdr c-macro-cache (point))
349 (setq c-macro-cache-syntactic nil))))
348 350
349(defun c-syntactic-end-of-macro () 351(defun c-syntactic-end-of-macro ()
350 ;; Go to the end of a CPP directive, or a "safe" pos just before. 352 ;; Go to the end of a CPP directive, or a "safe" pos just before.
@@ -364,7 +366,8 @@ comment at the start of cc-engine.el for more info."
364 (goto-char c-macro-cache-syntactic) 366 (goto-char c-macro-cache-syntactic)
365 (setq s (parse-partial-sexp here there)) 367 (setq s (parse-partial-sexp here there))
366 (while (and (or (nth 3 s) ; in a string 368 (while (and (or (nth 3 s) ; in a string
367 (nth 4 s)) ; in a comment (maybe at end of line comment) 369 (and (nth 4 s) ; in a comment (maybe at end of line comment)
370 (not (eq (nth 7 s) 'syntax-table)))) ; Not a pseudo comment
368 (> there here)) ; No infinite loops, please. 371 (> there here)) ; No infinite loops, please.
369 (setq there (1- (nth 8 s))) 372 (setq there (1- (nth 8 s)))
370 (setq s (parse-partial-sexp here there))) 373 (setq s (parse-partial-sexp here there)))
@@ -389,7 +392,8 @@ comment at the start of cc-engine.el for more info."
389 (> there here)) ; No infinite loops, please. 392 (> there here)) ; No infinite loops, please.
390 (setq here (1+ (nth 8 s))) 393 (setq here (1+ (nth 8 s)))
391 (setq s (parse-partial-sexp here there))) 394 (setq s (parse-partial-sexp here there)))
392 (when (nth 4 s) 395 (when (and (nth 4 s)
396 (not (eq (nth 7 s) 'syntax-table))) ; no pseudo comments.
393 (goto-char (1- (nth 8 s)))) 397 (goto-char (1- (nth 8 s))))
394 (setq c-macro-cache-no-comment (point))) 398 (setq c-macro-cache-no-comment (point)))
395 (point))) 399 (point)))
@@ -2407,7 +2411,9 @@ comment at the start of cc-engine.el for more info."
2407 (s (parse-partial-sexp base here nil nil s)) 2411 (s (parse-partial-sexp base here nil nil s))
2408 ty) 2412 ty)
2409 (cond 2413 (cond
2410 ((or (nth 3 s) (nth 4 s)) ; in a string or comment 2414 ((or (nth 3 s)
2415 (and (nth 4 s)
2416 (not (eq (nth 7 s) 'syntax-table)))) ; in a string or comment
2411 (setq ty (cond 2417 (setq ty (cond
2412 ((nth 3 s) 'string) 2418 ((nth 3 s) 'string)
2413 ((nth 7 s) 'c++) 2419 ((nth 7 s) 'c++)
@@ -2453,7 +2459,9 @@ comment at the start of cc-engine.el for more info."
2453 (s (parse-partial-sexp base here nil nil s)) 2459 (s (parse-partial-sexp base here nil nil s))
2454 ty start) 2460 ty start)
2455 (cond 2461 (cond
2456 ((or (nth 3 s) (nth 4 s)) ; in a string or comment 2462 ((or (nth 3 s)
2463 (and (nth 4 s)
2464 (not (eq (nth 7 s) 'syntax-table)))) ; in a string or comment
2457 (setq ty (cond 2465 (setq ty (cond
2458 ((nth 3 s) 'string) 2466 ((nth 3 s) 'string)
2459 ((nth 7 s) 'c++) 2467 ((nth 7 s) 'c++)
@@ -2479,7 +2487,7 @@ comment at the start of cc-engine.el for more info."
2479 2487
2480 (t (list s)))))))) 2488 (t (list s))))))))
2481 2489
2482(defsubst c-state-pp-to-literal (from to &optional not-in-delimiter) 2490(defun c-state-pp-to-literal (from to &optional not-in-delimiter)
2483 ;; Do a parse-partial-sexp from FROM to TO, returning either 2491 ;; Do a parse-partial-sexp from FROM to TO, returning either
2484 ;; (STATE TYPE (BEG . END)) if TO is in a literal; or 2492 ;; (STATE TYPE (BEG . END)) if TO is in a literal; or
2485 ;; (STATE) otherwise, 2493 ;; (STATE) otherwise,
@@ -2498,7 +2506,9 @@ comment at the start of cc-engine.el for more info."
2498 (let ((s (parse-partial-sexp from to)) 2506 (let ((s (parse-partial-sexp from to))
2499 ty co-st) 2507 ty co-st)
2500 (cond 2508 (cond
2501 ((or (nth 3 s) (nth 4 s)) ; in a string or comment 2509 ((or (nth 3 s)
2510 (and (nth 4 s)
2511 (not (eq (nth 7 s) 'syntax-table)))) ; in a string or comment
2502 (setq ty (cond 2512 (setq ty (cond
2503 ((nth 3 s) 'string) 2513 ((nth 3 s) 'string)
2504 ((nth 7 s) 'c++) 2514 ((nth 7 s) 'c++)
@@ -2560,7 +2570,8 @@ comment at the start of cc-engine.el for more info."
2560 (cond 2570 (cond
2561 ((nth 3 state) ; A string 2571 ((nth 3 state) ; A string
2562 (list (point) (nth 3 state) (nth 8 state))) 2572 (list (point) (nth 3 state) (nth 8 state)))
2563 ((nth 4 state) ; A comment 2573 ((and (nth 4 state) ; A comment
2574 (not (eq (nth 7 state) 'syntax-table))) ; but not a psuedo comment.
2564 (list (point) 2575 (list (point)
2565 (if (eq (nth 7 state) 1) 'c++ 'c) 2576 (if (eq (nth 7 state) 1) 'c++ 'c)
2566 (nth 8 state))) 2577 (nth 8 state)))
@@ -2697,7 +2708,7 @@ comment at the start of cc-engine.el for more info."
2697 (widen) 2708 (widen)
2698 (save-excursion 2709 (save-excursion
2699 (let ((pos (c-state-safe-place here))) 2710 (let ((pos (c-state-safe-place here)))
2700 (car (cddr (c-state-pp-to-literal pos here))))))) 2711 (car (cddr (c-state-pp-to-literal pos here)))))))
2701 2712
2702(defsubst c-state-lit-beg (pos) 2713(defsubst c-state-lit-beg (pos)
2703 ;; Return the start of the literal containing POS, or POS itself. 2714 ;; Return the start of the literal containing POS, or POS itself.
@@ -2708,7 +2719,8 @@ comment at the start of cc-engine.el for more info."
2708 ;; Return a position outside of a string/comment/macro at or before POS. 2719 ;; Return a position outside of a string/comment/macro at or before POS.
2709 ;; STATE is the parse-partial-sexp state at POS. 2720 ;; STATE is the parse-partial-sexp state at POS.
2710 (let ((res (if (or (nth 3 state) ; in a string? 2721 (let ((res (if (or (nth 3 state) ; in a string?
2711 (nth 4 state)) ; in a comment? 2722 (and (nth 4 state)
2723 (not (eq (nth 7 state) 'syntax-table)))) ; in a comment?
2712 (nth 8 state) 2724 (nth 8 state)
2713 pos))) 2725 pos)))
2714 (save-excursion 2726 (save-excursion
@@ -3467,7 +3479,7 @@ comment at the start of cc-engine.el for more info."
3467 ((and (consp (car c-state-cache)) 3479 ((and (consp (car c-state-cache))
3468 (> (cdar c-state-cache) here)) 3480 (> (cdar c-state-cache) here))
3469 ;; CASE 1: The top of the cache is a brace pair which now encloses 3481 ;; CASE 1: The top of the cache is a brace pair which now encloses
3470 ;; `here'. As good-pos, return the address. of the "{". Since we've no 3482 ;; `here'. As good-pos, return the address of the "{". Since we've no
3471 ;; knowledge of what's inside these braces, we have no alternative but 3483 ;; knowledge of what's inside these braces, we have no alternative but
3472 ;; to direct the caller to scan the buffer from the opening brace. 3484 ;; to direct the caller to scan the buffer from the opening brace.
3473 (setq pos (caar c-state-cache)) 3485 (setq pos (caar c-state-cache))
@@ -4952,7 +4964,8 @@ comment at the start of cc-engine.el for more info."
4952 (lit-limits 4964 (lit-limits
4953 (if lim 4965 (if lim
4954 (let ((s (parse-partial-sexp lim (point)))) 4966 (let ((s (parse-partial-sexp lim (point))))
4955 (when (or (nth 3 s) (nth 4 s)) 4967 (when (or (nth 3 s)
4968 (and (nth 4 s) (not (eq (nth 7 s) 'syntax-table))))
4956 (cons (nth 8 s) 4969 (cons (nth 8 s)
4957 (progn (parse-partial-sexp (point) (point-max) 4970 (progn (parse-partial-sexp (point) (point-max)
4958 nil nil 4971 nil nil
@@ -5005,7 +5018,8 @@ point isn't in one. SAFE-POS, if non-nil, is a position before point which is
5005a known \"safe position\", i.e. outside of any string or comment." 5018a known \"safe position\", i.e. outside of any string or comment."
5006 (if safe-pos 5019 (if safe-pos
5007 (let ((s (parse-partial-sexp safe-pos (point)))) 5020 (let ((s (parse-partial-sexp safe-pos (point))))
5008 (and (or (nth 3 s) (nth 4 s)) 5021 (and (or (nth 3 s)
5022 (and (nth 4 s) (not (eq (nth 7 s) 'syntax-table))))
5009 (nth 8 s))) 5023 (nth 8 s)))
5010 (car (cddr (c-state-semi-pp-to-literal (point)))))) 5024 (car (cddr (c-state-semi-pp-to-literal (point))))))
5011 5025
@@ -5106,7 +5120,8 @@ comment at the start of cc-engine.el for more info."
5106 'syntax-table)) ; stop-comment 5120 'syntax-table)) ; stop-comment
5107 5121
5108 ;; Gather details of the non-literal-bit - starting pos and size. 5122 ;; Gather details of the non-literal-bit - starting pos and size.
5109 (setq size (- (if (or (nth 4 s) (nth 3 s)) 5123 (setq size (- (if (or (and (nth 4 s) (not (eq (nth 7 s) 'syntax-table)))
5124 (nth 3 s))
5110 (nth 8 s) 5125 (nth 8 s)
5111 (point)) 5126 (point))
5112 pos)) 5127 pos))
@@ -5114,7 +5129,8 @@ comment at the start of cc-engine.el for more info."
5114 (setq stack (cons (cons pos size) stack))) 5129 (setq stack (cons (cons pos size) stack)))
5115 5130
5116 ;; Move forward to the end of the comment/string. 5131 ;; Move forward to the end of the comment/string.
5117 (if (or (nth 4 s) (nth 3 s)) 5132 (if (or (and (nth 4 s) (not (eq (nth 7 s) 'syntax-table)))
5133 (nth 3 s))
5118 (setq s (parse-partial-sexp 5134 (setq s (parse-partial-sexp
5119 (point) 5135 (point)
5120 start 5136 start
diff --git a/lisp/progmodes/cc-mode.el b/lisp/progmodes/cc-mode.el
index 7e3c6ba15a5..e2969c607a5 100644
--- a/lisp/progmodes/cc-mode.el
+++ b/lisp/progmodes/cc-mode.el
@@ -1068,7 +1068,8 @@ Note that the style variables are always made local to the buffer."
1068 (parse-partial-sexp pps-position (point) nil nil pps-state) 1068 (parse-partial-sexp pps-position (point) nil nil pps-state)
1069 pps-position (point)) 1069 pps-position (point))
1070 (or (nth 3 pps-state) ; in a string? 1070 (or (nth 3 pps-state) ; in a string?
1071 (nth 4 pps-state)))) ; in a comment? 1071 (and (nth 4 pps-state)
1072 (not (eq (nth 7 pps-state) 'syntax-table)))))) ; in a comment?
1072 (goto-char (match-beginning 1)) 1073 (goto-char (match-beginning 1))
1073 (setq mbeg (point)) 1074 (setq mbeg (point))
1074 (if (> (c-no-comment-end-of-macro) mbeg) 1075 (if (> (c-no-comment-end-of-macro) mbeg)