diff options
| author | Alan Mackenzie | 2016-06-19 12:06:24 +0000 |
|---|---|---|
| committer | Alan Mackenzie | 2016-06-19 12:06:24 +0000 |
| commit | 4e9014f02574039ba7d131fba94af728efd41397 (patch) | |
| tree | 86a5bee881d7b3a559ac936dfac55ae58e33ef77 | |
| parent | 65885ccf29ce4723f100a45756005781e8e7ab46 (diff) | |
| download | emacs-4e9014f02574039ba7d131fba94af728efd41397.tar.gz emacs-4e9014f02574039ba7d131fba94af728efd41397.zip | |
Fix CC Mode fontification problem apparent in test file decls-6.cc.
* lisp/progmodes/cc-engine.el (c-forward-decl-or-cast-1): Recognize
"bar (gnu);" as a declarator only when the construct is directly inside a
class (etc.) called "bar".
(c-directly-in-class-called-p): New function.
| -rw-r--r-- | lisp/progmodes/cc-engine.el | 50 |
1 files changed, 43 insertions, 7 deletions
diff --git a/lisp/progmodes/cc-engine.el b/lisp/progmodes/cc-engine.el index 011d08031d1..595d57756eb 100644 --- a/lisp/progmodes/cc-engine.el +++ b/lisp/progmodes/cc-engine.el | |||
| @@ -7966,16 +7966,32 @@ comment at the start of cc-engine.el for more info." | |||
| 7966 | maybe-typeless | 7966 | maybe-typeless |
| 7967 | backup-maybe-typeless | 7967 | backup-maybe-typeless |
| 7968 | (eq at-decl-or-cast t) | 7968 | (eq at-decl-or-cast t) |
| 7969 | ;; Check whether we have "bar (gnu);" where we | ||
| 7970 | ;; are directly inside a class (etc.) called "bar". | ||
| 7969 | (save-excursion | 7971 | (save-excursion |
| 7970 | (goto-char name-start) | 7972 | (and |
| 7971 | (not (memq (c-forward-type) '(nil maybe)))))) | 7973 | (progn |
| 7974 | (goto-char name-start) | ||
| 7975 | (not (memq (c-forward-type) '(nil maybe)))) | ||
| 7976 | (progn | ||
| 7977 | (goto-char id-start) | ||
| 7978 | (c-directly-in-class-called-p | ||
| 7979 | (buffer-substring | ||
| 7980 | type-start | ||
| 7981 | (progn | ||
| 7982 | (goto-char type-start) | ||
| 7983 | (c-forward-type) | ||
| 7984 | (c-backward-syntactic-ws) | ||
| 7985 | (point))))))))) | ||
| 7972 | ;; Got a declaration of the form "foo bar (gnu);" or "bar | 7986 | ;; Got a declaration of the form "foo bar (gnu);" or "bar |
| 7973 | ;; (gnu);" where we've recognized "bar" as the type and "gnu" | 7987 | ;; (gnu);" where we've recognized "bar" as the type and "gnu" |
| 7974 | ;; as the declarator. In this case it's however more likely | 7988 | ;; as the declarator, and in the latter case, checked that |
| 7975 | ;; that "bar" is the declarator and "gnu" a function argument | 7989 | ;; "bar (gnu)" appears directly inside the class "bar". In |
| 7976 | ;; or initializer (if `c-recognize-paren-inits' is set), | 7990 | ;; this case it's however more likely that "bar" is the |
| 7977 | ;; since the parens around "gnu" would be superfluous if it's | 7991 | ;; declarator and "gnu" a function argument or initializer |
| 7978 | ;; a declarator. Shift the type one step backward. | 7992 | ;; (if `c-recognize-paren-inits' is set), since the parens |
| 7993 | ;; around "gnu" would be superfluous if it's a declarator. | ||
| 7994 | ;; Shift the type one step backward. | ||
| 7979 | (c-fdoc-shift-type-backward))) | 7995 | (c-fdoc-shift-type-backward))) |
| 7980 | 7996 | ||
| 7981 | ;; Found no identifier. | 7997 | ;; Found no identifier. |
| @@ -9414,6 +9430,26 @@ comment at the start of cc-engine.el for more info." | |||
| 9414 | 9430 | ||
| 9415 | kwd-start))) | 9431 | kwd-start))) |
| 9416 | 9432 | ||
| 9433 | (defun c-directly-in-class-called-p (name) | ||
| 9434 | ;; Check whether point is directly inside a brace block which is the brace | ||
| 9435 | ;; block of a class, struct, or union which is called NAME, a string. | ||
| 9436 | (let* ((paren-state (c-parse-state)) | ||
| 9437 | (brace-pos (c-pull-open-brace paren-state)) | ||
| 9438 | ) | ||
| 9439 | (when (eq (char-after brace-pos) ?{) | ||
| 9440 | (goto-char brace-pos) | ||
| 9441 | (save-excursion | ||
| 9442 | ; *c-looking-at-decl-block | ||
| 9443 | ; containing-sexp goto-start &optional | ||
| 9444 | ; limit) | ||
| 9445 | (when (and (c-looking-at-decl-block | ||
| 9446 | (c-pull-open-brace paren-state) | ||
| 9447 | nil) | ||
| 9448 | (looking-at c-class-key)) | ||
| 9449 | (goto-char (match-end 1)) | ||
| 9450 | (c-forward-syntactic-ws) | ||
| 9451 | (looking-at name)))))) | ||
| 9452 | |||
| 9417 | (defun c-search-uplist-for-classkey (paren-state) | 9453 | (defun c-search-uplist-for-classkey (paren-state) |
| 9418 | ;; Check if the closest containing paren sexp is a declaration | 9454 | ;; Check if the closest containing paren sexp is a declaration |
| 9419 | ;; block, returning a 2 element vector in that case. Aref 0 | 9455 | ;; block, returning a 2 element vector in that case. Aref 0 |