aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlan Mackenzie2018-09-26 17:09:43 +0000
committerAlan Mackenzie2018-09-26 17:09:43 +0000
commit420faac11072cb6a956784b208fc28e83f40108e (patch)
tree759754d191f0b556102e6973f84e42c9004b4df5
parentf1aa21a5b25b9371b42c267ef9ec557fa75ec95a (diff)
downloademacs-420faac11072cb6a956784b208fc28e83f40108e.tar.gz
emacs-420faac11072cb6a956784b208fc28e83f40108e.zip
CC Mode: consider tails of compound identifiers when seeking found types.
* lisp/progmodes/cc-engine.el (c-forward-over-token): New function, extracted from ... (c-forward-over-token-and-ws): Refactor to use the above. (c-forward-type): Use c-check-qualified-type in place of c-check-type (twice). (c-forward-over-compound-identifier): New function. (c-check-qualified-type): New function.
-rw-r--r--lisp/progmodes/cc-engine.el116
1 files changed, 85 insertions, 31 deletions
diff --git a/lisp/progmodes/cc-engine.el b/lisp/progmodes/cc-engine.el
index 278ade0560c..3ec7dbcc906 100644
--- a/lisp/progmodes/cc-engine.el
+++ b/lisp/progmodes/cc-engine.el
@@ -4295,6 +4295,41 @@ comment at the start of cc-engine.el for more info."
4295 "\\w\\|\\s_\\|\\s\"\\|\\s|" 4295 "\\w\\|\\s_\\|\\s\"\\|\\s|"
4296 "\\w\\|\\s_\\|\\s\"")) 4296 "\\w\\|\\s_\\|\\s\""))
4297 4297
4298(defun c-forward-over-token (&optional balanced)
4299 "Move forward over a token.
4300Return t if we moved, nil otherwise (i.e. we were at EOB, or a
4301non-token or BALANCED is non-nil and we can't move). If we
4302are at syntactic whitespace, move over this in place of a token.
4303
4304If BALANCED is non-nil move over any balanced parens we are at, and never move
4305out of an enclosing paren."
4306 (let ((jump-syntax (if balanced
4307 c-jump-syntax-balanced
4308 c-jump-syntax-unbalanced))
4309 (here (point)))
4310 (condition-case nil
4311 (cond
4312 ((/= (point)
4313 (progn (c-forward-syntactic-ws) (point)))
4314 ;; If we're at whitespace, count this as the token.
4315 t)
4316 ((eobp) nil)
4317 ((looking-at jump-syntax)
4318 (goto-char (scan-sexps (point) 1))
4319 t)
4320 ((looking-at c-nonsymbol-token-regexp)
4321 (goto-char (match-end 0))
4322 t)
4323 ((save-restriction
4324 (widen)
4325 (looking-at c-nonsymbol-token-regexp))
4326 nil)
4327 (t
4328 (forward-char)
4329 t))
4330 (error (goto-char here)
4331 nil))))
4332
4298(defun c-forward-over-token-and-ws (&optional balanced) 4333(defun c-forward-over-token-and-ws (&optional balanced)
4299 "Move forward over a token and any following whitespace 4334 "Move forward over a token and any following whitespace
4300Return t if we moved, nil otherwise (i.e. we were at EOB, or a 4335Return t if we moved, nil otherwise (i.e. we were at EOB, or a
@@ -4306,35 +4341,8 @@ out of an enclosing paren.
4306 4341
4307This function differs from `c-forward-token-2' in that it will move forward 4342This function differs from `c-forward-token-2' in that it will move forward
4308over the final token in a buffer, up to EOB." 4343over the final token in a buffer, up to EOB."
4309 (let ((jump-syntax (if balanced 4344 (prog1 (c-forward-over-token balanced)
4310 c-jump-syntax-balanced 4345 (c-forward-syntactic-ws)))
4311 c-jump-syntax-unbalanced))
4312 (here (point)))
4313 (when
4314 (condition-case nil
4315 (cond
4316 ((/= (point)
4317 (progn (c-forward-syntactic-ws) (point)))
4318 ;; If we're at whitespace, count this as the token.
4319 t)
4320 ((eobp) nil)
4321 ((looking-at jump-syntax)
4322 (goto-char (scan-sexps (point) 1))
4323 t)
4324 ((looking-at c-nonsymbol-token-regexp)
4325 (goto-char (match-end 0))
4326 t)
4327 ((save-restriction
4328 (widen)
4329 (looking-at c-nonsymbol-token-regexp))
4330 nil)
4331 (t
4332 (forward-char)
4333 t))
4334 (error (goto-char here)
4335 nil))
4336 (c-forward-syntactic-ws)
4337 t)))
4338 4346
4339(defun c-forward-token-2 (&optional count balanced limit) 4347(defun c-forward-token-2 (&optional count balanced limit)
4340 "Move forward by tokens. 4348 "Move forward by tokens.
@@ -7662,7 +7670,7 @@ comment at the start of cc-engine.el for more info."
7662 (c-record-type-id id-range)) 7670 (c-record-type-id id-range))
7663 (unless res 7671 (unless res
7664 (setq res 'found))) 7672 (setq res 'found)))
7665 (setq res (if (c-check-type id-start id-end) 7673 (setq res (if (c-check-qualified-type id-start)
7666 ;; It's an identifier that has been used as 7674 ;; It's an identifier that has been used as
7667 ;; a type somewhere else. 7675 ;; a type somewhere else.
7668 'found 7676 'found
@@ -7674,7 +7682,7 @@ comment at the start of cc-engine.el for more info."
7674 (c-forward-syntactic-ws) 7682 (c-forward-syntactic-ws)
7675 (setq res 7683 (setq res
7676 (if (eq (char-after) ?\() 7684 (if (eq (char-after) ?\()
7677 (if (c-check-type id-start id-end) 7685 (if (c-check-qualified-type id-start)
7678 ;; It's an identifier that has been used as 7686 ;; It's an identifier that has been used as
7679 ;; a type somewhere else. 7687 ;; a type somewhere else.
7680 'found 7688 'found
@@ -7799,6 +7807,37 @@ comment at the start of cc-engine.el for more info."
7799 (prog1 (car ,ps) 7807 (prog1 (car ,ps)
7800 (setq ,ps (cdr ,ps))))) 7808 (setq ,ps (cdr ,ps)))))
7801 7809
7810(defun c-forward-over-compound-identifier ()
7811 ;; Go over a possibly compound identifier, such as C++'s Foo::Bar::Baz,
7812 ;; returning that identifier (with any syntactic WS removed). Return nil if
7813 ;; we're not at an identifier.
7814 (when (c-on-identifier)
7815 (let ((consolidated "") (consolidated-:: "")
7816 start end)
7817 (while
7818 (progn
7819 (setq start (point))
7820 (c-forward-over-token)
7821 (setq consolidated
7822 (concat consolidated-::
7823 (buffer-substring-no-properties start (point))))
7824 (c-forward-syntactic-ws)
7825 (and c-opt-identifier-concat-key
7826 (looking-at c-opt-identifier-concat-key)
7827 (progn
7828 (setq start (point))
7829 (c-forward-over-token)
7830 (setq end (point))
7831 (c-forward-syntactic-ws)
7832 (and
7833 (c-on-identifier)
7834 (setq consolidated-::
7835 (concat consolidated
7836 (buffer-substring-no-properties start end))))))))
7837 (if (equal consolidated "")
7838 nil
7839 consolidated))))
7840
7802(defun c-back-over-compound-identifier () 7841(defun c-back-over-compound-identifier ()
7803 ;; Point is putatively just after a "compound identifier", i.e. something 7842 ;; Point is putatively just after a "compound identifier", i.e. something
7804 ;; looking (in C++) like this "FQN::of::base::Class". Move to the start of 7843 ;; looking (in C++) like this "FQN::of::base::Class". Move to the start of
@@ -7823,6 +7862,21 @@ comment at the start of cc-engine.el for more info."
7823 (goto-char end) 7862 (goto-char end)
7824 t))) 7863 t)))
7825 7864
7865(defun c-check-qualified-type (from)
7866 ;; Look up successive tails of a (possibly) qualified type in
7867 ;; `c-found-types'. If one of them matches, return it, else return nil.
7868 (save-excursion
7869 (goto-char from)
7870 (let ((compound (c-forward-over-compound-identifier)))
7871 (when compound
7872 (while (and c-opt-identifier-concat-key
7873 (> (length compound) 0)
7874 (not (gethash compound c-found-types))
7875 (string-match c-opt-identifier-concat-key compound))
7876 (setq compound (substring compound (match-end 0))))
7877 (and (gethash compound c-found-types)
7878 compound)))))
7879
7826(defun c-back-over-member-initializer-braces () 7880(defun c-back-over-member-initializer-braces ()
7827 ;; Point is just after a closing brace/parenthesis. Try to parse this as a 7881 ;; Point is just after a closing brace/parenthesis. Try to parse this as a
7828 ;; C++ member initializer list, going back to just after the introducing ":" 7882 ;; C++ member initializer list, going back to just after the introducing ":"