X-Git-Url: https://code.delx.au/gnu-emacs/blobdiff_plain/68ed6bfb6599104e5f1635a862a373735d818722..b1c7207dbbc5b35aa2fa6e69a3041299e881dbb6:/lisp/progmodes/cc-engine.el diff --git a/lisp/progmodes/cc-engine.el b/lisp/progmodes/cc-engine.el index 66b5369bbb..4aff0dc14e 100644 --- a/lisp/progmodes/cc-engine.el +++ b/lisp/progmodes/cc-engine.el @@ -3501,6 +3501,9 @@ comment at the start of cc-engine.el for more info." (make-variable-buffer-local 'c-parse-state-state) (defun c-record-parse-state-state () (setq c-parse-state-point (point)) + (when (markerp (cdr (assq 'c-state-old-cpp-beg c-parse-state-state))) + (move-marker (cdr (assq 'c-state-old-cpp-beg c-parse-state-state)) nil) + (move-marker (cdr (assq 'c-state-old-cpp-end c-parse-state-state)) nil)) (setq c-parse-state-state (mapcar (lambda (arg) @@ -4288,8 +4291,7 @@ comment at the start of cc-engine.el for more info." (setq safe-pos-list (cdr safe-pos-list))) (unless (setq safe-pos (car-safe safe-pos-list)) (setq safe-pos (max (or (c-safe-position - (point) (or c-state-cache - (c-parse-state))) + (point) (c-parse-state)) 0) (point-min)) safe-pos-list (list safe-pos))) @@ -4337,107 +4339,108 @@ Non-nil is returned if the point moved, nil otherwise. Note that this function might do hidden buffer changes. See the comment at the start of cc-engine.el for more info." - (let ((start (point)) - state-2 - ;; A list of syntactically relevant positions in descending - ;; order. It's used to avoid scanning repeatedly over - ;; potentially large regions with `parse-partial-sexp' to verify - ;; each position. Used in `c-ssb-lit-begin' - safe-pos-list - ;; The result from `c-beginning-of-macro' at the start position or the - ;; start position itself if it isn't within a macro. Evaluated on - ;; demand. - start-macro-beg - ;; The earliest position after the current one with the same paren - ;; level. Used only when `paren-level' is set. - lit-beg - (paren-level-pos (point))) - - (while - (progn - ;; The next loop "tries" to find the end point each time round, - ;; loops when it hasn't succeeded. - (while - (and - (let ((pos (point))) - (while (and - (< (skip-chars-backward skip-chars limit) 0) - ;; Don't stop inside a literal. - (when (setq lit-beg (c-ssb-lit-begin)) - (goto-char lit-beg) - t))) - (< (point) pos)) + (c-self-bind-state-cache + (let ((start (point)) + state-2 + ;; A list of syntactically relevant positions in descending + ;; order. It's used to avoid scanning repeatedly over + ;; potentially large regions with `parse-partial-sexp' to verify + ;; each position. Used in `c-ssb-lit-begin' + safe-pos-list + ;; The result from `c-beginning-of-macro' at the start position or the + ;; start position itself if it isn't within a macro. Evaluated on + ;; demand. + start-macro-beg + ;; The earliest position after the current one with the same paren + ;; level. Used only when `paren-level' is set. + lit-beg + (paren-level-pos (point))) + + (while + (progn + ;; The next loop "tries" to find the end point each time round, + ;; loops when it hasn't succeeded. + (while + (and + (let ((pos (point))) + (while (and + (< (skip-chars-backward skip-chars limit) 0) + ;; Don't stop inside a literal. + (when (setq lit-beg (c-ssb-lit-begin)) + (goto-char lit-beg) + t))) + (< (point) pos)) + + (let ((pos (point)) state-2 pps-end-pos) - (let ((pos (point)) state-2 pps-end-pos) + (cond + ((and paren-level + (save-excursion + (setq state-2 (parse-partial-sexp + pos paren-level-pos -1) + pps-end-pos (point)) + (/= (car state-2) 0))) + ;; Not at the right level. + + (if (and (< (car state-2) 0) + ;; We stop above if we go out of a paren. + ;; Now check whether it precedes or is + ;; nested in the starting sexp. + (save-excursion + (setq state-2 + (parse-partial-sexp + pps-end-pos paren-level-pos + nil nil state-2)) + (< (car state-2) 0))) + + ;; We've stopped short of the starting position + ;; so the hit was inside a nested list. Go up + ;; until we are at the right level. + (condition-case nil + (progn + (goto-char (scan-lists pos -1 + (- (car state-2)))) + (setq paren-level-pos (point)) + (if (and limit (>= limit paren-level-pos)) + (progn + (goto-char limit) + nil) + t)) + (error + (goto-char (or limit (point-min))) + nil)) + + ;; The hit was outside the list at the start + ;; position. Go to the start of the list and exit. + (goto-char (1+ (elt state-2 1))) + nil)) + + ((c-beginning-of-macro limit) + ;; Inside a macro. + (if (< (point) + (or start-macro-beg + (setq start-macro-beg + (save-excursion + (goto-char start) + (c-beginning-of-macro limit) + (point))))) + t + + ;; It's inside the same macro we started in so it's + ;; a relevant match. + (goto-char pos) + nil)))))) - (cond - ((and paren-level - (save-excursion - (setq state-2 (parse-partial-sexp - pos paren-level-pos -1) - pps-end-pos (point)) - (/= (car state-2) 0))) - ;; Not at the right level. - - (if (and (< (car state-2) 0) - ;; We stop above if we go out of a paren. - ;; Now check whether it precedes or is - ;; nested in the starting sexp. - (save-excursion - (setq state-2 - (parse-partial-sexp - pps-end-pos paren-level-pos - nil nil state-2)) - (< (car state-2) 0))) - - ;; We've stopped short of the starting position - ;; so the hit was inside a nested list. Go up - ;; until we are at the right level. - (condition-case nil - (progn - (goto-char (scan-lists pos -1 - (- (car state-2)))) - (setq paren-level-pos (point)) - (if (and limit (>= limit paren-level-pos)) - (progn - (goto-char limit) - nil) - t)) - (error - (goto-char (or limit (point-min))) - nil)) - - ;; The hit was outside the list at the start - ;; position. Go to the start of the list and exit. - (goto-char (1+ (elt state-2 1))) - nil)) - - ((c-beginning-of-macro limit) - ;; Inside a macro. - (if (< (point) - (or start-macro-beg - (setq start-macro-beg - (save-excursion - (goto-char start) - (c-beginning-of-macro limit) - (point))))) - t - - ;; It's inside the same macro we started in so it's - ;; a relevant match. - (goto-char pos) - nil)))))) - - (> (point) - (progn - ;; Skip syntactic ws afterwards so that we don't stop at the - ;; end of a comment if `skip-chars' is something like "^/". - (c-backward-syntactic-ws) - (point))))) + (> (point) + (progn + ;; Skip syntactic ws afterwards so that we don't stop at the + ;; end of a comment if `skip-chars' is something like "^/". + (c-backward-syntactic-ws) + (point))))) - ;; We might want to extend this with more useful return values in - ;; the future. - (/= (point) start))) + ;; We might want to extend this with more useful return values in + ;; the future. + (/= (point) start)))) ;; The following is an alternative implementation of ;; `c-syntactic-skip-backward' that uses backward movement to keep @@ -5838,12 +5841,14 @@ comment at the start of cc-engine.el for more info." nil (cond ((looking-at c-keywords-regexp) (c-forward-keyword-clause 1)) - ((looking-at c-noise-macro-with-parens-name-re) + ((and c-opt-cpp-prefix + (looking-at c-noise-macro-with-parens-name-re)) (c-forward-noise-clause))))) - (when (memq res '(t known found prefix)) - ,(when (eq type 'ref) - `(when c-record-type-identifiers - (c-record-ref-id c-last-identifier-range))) + (when (memq res '(t known found prefix maybe)) + (when c-record-type-identifiers + ,(if (eq type 'type) + `(c-record-type-id c-last-identifier-range) + `(c-record-ref-id c-last-identifier-range))) t))) (defmacro c-forward-id-comma-list (type update-safe-pos) @@ -6083,7 +6088,7 @@ comment at the start of cc-engine.el for more info." (when (or (looking-at "extends") (looking-at "super")) - (forward-word) + (forward-word-strictly) (c-forward-syntactic-ws) (let ((c-promote-possible-types t) (c-record-found-types t)) @@ -6410,13 +6415,15 @@ comment at the start of cc-engine.el for more info." (eq (char-after) ?<)) ;; Maybe an angle bracket arglist. (when (let ((c-record-type-identifiers t) - (c-record-found-types t)) + (c-record-found-types t) + (c-last-identifier-range)) (c-forward-<>-arglist nil)) - (c-add-type start (1+ pos)) (c-forward-syntactic-ws) - (setq pos (point) - c-last-identifier-range nil) + (unless (eq (char-after) ?\() + (setq c-last-identifier-range nil) + (c-add-type start (1+ pos))) + (setq pos (point)) (if (and c-opt-identifier-concat-key (looking-at c-opt-identifier-concat-key)) @@ -6430,7 +6437,8 @@ comment at the start of cc-engine.el for more info." (c-forward-syntactic-ws) t) - (when (and c-record-type-identifiers id-start) + (when (and c-record-type-identifiers id-start + (not (eq (char-after) ?\())) (c-record-type-id (cons id-start id-end))) (setq res 'template) nil))) @@ -6506,7 +6514,8 @@ comment at the start of cc-engine.el for more info." (while (cond ((looking-at c-decl-hangon-key) (c-forward-keyword-clause 1)) - ((looking-at c-noise-macro-with-parens-name-re) + ((and c-opt-cpp-prefix + (looking-at c-noise-macro-with-parens-name-re)) (c-forward-noise-clause)))) (setq pos (point)) @@ -6611,9 +6620,18 @@ comment at the start of cc-engine.el for more info." ;; It's an identifier that might be a type. 'maybe)))) ((eq name-res 'template) - ;; A template is a type. + ;; A template is sometimes a type. (goto-char id-end) - (setq res t)) + (c-forward-syntactic-ws) + (setq res + (if (eq (char-after) ?\() + (if (c-check-type id-start id-end) + ;; It's an identifier that has been used as + ;; a type somewhere else. + 'found + ;; It's an identifier that might be a type. + 'maybe) + t))) (t ;; Otherwise it's an operator identifier, which is not a type. (goto-char start) @@ -6798,6 +6816,9 @@ comment at the start of cc-engine.el for more info." (c-backward-syntactic-ws)) (c-back-over-list-of-member-inits) (and (eq (char-before) ?:) + (save-excursion + (c-backward-token-2) + (not (looking-at c-:$-multichar-token-regexp))) (c-just-after-func-arglist-p)))) (while (and (not (and level-plausible @@ -6812,6 +6833,9 @@ comment at the start of cc-engine.el for more info." (c-backward-syntactic-ws) (c-back-over-list-of-member-inits) (and (eq (char-before) ?:) + (save-excursion + (c-backward-token-2) + (not (looking-at c-:$-multichar-token-regexp))) (c-just-after-func-arglist-p))))) (and at-top-level level-plausible))) @@ -6905,7 +6929,8 @@ comment at the start of cc-engine.el for more info." (cond ((looking-at c-decl-hangon-key) (c-forward-keyword-clause 1)) - ((looking-at c-noise-macro-with-parens-name-re) + ((and c-opt-cpp-prefix + (looking-at c-noise-macro-with-parens-name-re)) (c-forward-noise-clause)) ((and (looking-at c-type-decl-prefix-key) (if (and (c-major-mode-is 'c++-mode) @@ -6960,7 +6985,8 @@ comment at the start of cc-engine.el for more info." (while (cond ((looking-at c-decl-hangon-key) (c-forward-keyword-clause 1)) - ((looking-at c-noise-macro-with-parens-name-re) + ((and c-opt-cpp-prefix + (looking-at c-noise-macro-with-parens-name-re)) (c-forward-noise-clause)))) (<= (point) limit)) @@ -7155,7 +7181,8 @@ comment at the start of cc-engine.el for more info." (save-excursion (c-forward-keyword-clause 1) (setq kwd-clause-end (point)))) - ((looking-at c-noise-macro-with-parens-name-re) + ((and c-opt-cpp-prefix + (looking-at c-noise-macro-with-parens-name-re)) (setq noise-start (point)) (c-forward-noise-clause) (setq kwd-clause-end (point)))) @@ -7261,7 +7288,8 @@ comment at the start of cc-engine.el for more info." (while (cond ((looking-at c-decl-hangon-key) (c-forward-keyword-clause 1)) - ((looking-at c-noise-macro-with-parens-name-re) + ((and c-opt-cpp-prefix + (looking-at c-noise-macro-with-parens-name-re)) (c-forward-noise-clause)))) (setq id-start (point))) @@ -9032,7 +9060,8 @@ comment at the start of cc-engine.el for more info." ((eq (char-after) ?\() (and (eq (c-backward-token-2) 0) (or (looking-at c-decl-hangon-key) - (looking-at c-noise-macro-with-parens-name-re)))) + (and c-opt-cpp-prefix + (looking-at c-noise-macro-with-parens-name-re))))) ((and c-recognize-<>-arglists (eq (char-after) ?<) @@ -10297,7 +10326,8 @@ comment at the start of cc-engine.el for more info." (while (cond ((looking-at c-specifier-key) (c-forward-keyword-clause 1)) - ((looking-at c-noise-macro-with-parens-name-re) + ((and c-opt-cpp-prefix + (looking-at c-noise-macro-with-parens-name-re)) (c-forward-noise-clause)))) (setq placeholder (c-point 'boi)) (or (consp special-brace-list) @@ -10353,7 +10383,8 @@ comment at the start of cc-engine.el for more info." (while (cond ((looking-at c-specifier-key) (c-forward-keyword-clause 1)) - ((looking-at c-noise-macro-with-parens-name-re) + ((and c-opt-cpp-prefix + (looking-at c-noise-macro-with-parens-name-re)) (c-forward-noise-clause)))) (c-add-syntax 'defun-open (c-point 'boi)) ;; Bogus to use bol here, but it's the legacy. (Resolved, @@ -10988,7 +11019,8 @@ comment at the start of cc-engine.el for more info." (while (cond ((looking-at c-specifier-key) (c-forward-keyword-clause 1)) - ((looking-at c-noise-macro-with-parens-name-re) + ((and c-opt-cpp-prefix + (looking-at c-noise-macro-with-parens-name-re)) (c-forward-noise-clause)))) (c-add-syntax 'brace-list-open (c-point 'boi))))