aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlan Mackenzie2014-10-30 16:07:19 +0000
committerAlan Mackenzie2014-10-30 16:07:19 +0000
commitff73c2c3e2b99c1a759fd876464d36f6dd57a4b0 (patch)
tree6c258dd1e745ba5da9ee2d7e2916d4a0168c1b5d
parentff7ec46d34fa2371ca22b046d1b8654c88dc24db (diff)
downloademacs-ff73c2c3e2b99c1a759fd876464d36f6dd57a4b0.tar.gz
emacs-ff73c2c3e2b99c1a759fd876464d36f6dd57a4b0.zip
Add "enum classs" support to C++ mode.
progmodes/cc-langs.el (c-after-brace-list-decl-kwds) (c-after-brace-list-key): New language consts/variables. progmodes/cc-engine.el (c-looking-at-decl-block): Exclude spurious match of "enum struct" from decl-block recognition. (c-backward-colon-prefixed-type): New function. (c-backward-over-enum-header): Call above function to extend recognition of enum structure.
-rw-r--r--lisp/ChangeLog11
-rw-r--r--lisp/progmodes/cc-engine.el95
-rw-r--r--lisp/progmodes/cc-langs.el20
3 files changed, 102 insertions, 24 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 56da0d6e154..91f61aa448b 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,14 @@
12014-10-30 Alan Mackenzie <acm@muc.de>
2
3 Add "enum classs" support to C++ mode.
4 * progmodes/cc-langs.el (c-after-brace-list-decl-kwds)
5 (c-after-brace-list-key): New language consts/variables.
6 * progmodes/cc-engine.el (c-looking-at-decl-block): Exclude
7 spurious match of "enum struct" from decl-block recognition.
8 (c-backward-colon-prefixed-type): New function.
9 (c-backward-over-enum-header): Call above function to extend
10 recognition of enum structure.
11
12014-10-30 Stefan Monnier <monnier@iro.umontreal.ca> 122014-10-30 Stefan Monnier <monnier@iro.umontreal.ca>
2 13
3 * progmodes/cc-defs.el (c--macroexpand-all): New function (bug#18845). 14 * progmodes/cc-defs.el (c--macroexpand-all): New function (bug#18845).
diff --git a/lisp/progmodes/cc-engine.el b/lisp/progmodes/cc-engine.el
index ccc3f067571..0e8539b795b 100644
--- a/lisp/progmodes/cc-engine.el
+++ b/lisp/progmodes/cc-engine.el
@@ -8460,31 +8460,44 @@ comment at the start of cc-engine.el for more info."
8460 (cond 8460 (cond
8461 ((c-syntactic-re-search-forward c-decl-block-key open-brace t t t) 8461 ((c-syntactic-re-search-forward c-decl-block-key open-brace t t t)
8462 (goto-char (setq kwd-start (match-beginning 0))) 8462 (goto-char (setq kwd-start (match-beginning 0)))
8463 (or 8463 (and
8464 8464 ;; Exclude cases where we matched what would ordinarily
8465 ;; Found a keyword that can't be a type? 8465 ;; be a block declaration keyword, except where it's not
8466 (match-beginning 1) 8466 ;; legal because it's part of a "compound keyword" like
8467 8467 ;; "enum class". Of course, if c-after-brace-list-key
8468 ;; Can be a type too, in which case it's the return type of a 8468 ;; is nil, we can skip the test.
8469 ;; function (under the assumption that no declaration level 8469 (or (equal c-after-brace-list-key "\\<\\>")
8470 ;; block construct starts with a type). 8470 (save-match-data
8471 (not (c-forward-type)) 8471 (save-excursion
8472 8472 (not
8473 ;; Jumped over a type, but it could be a declaration keyword 8473 (and
8474 ;; followed by the declared identifier that we've jumped over 8474 (looking-at c-after-brace-list-key)
8475 ;; instead (e.g. in "class Foo {"). If it indeed is a type 8475 (= (c-backward-token-2 1 t) 0)
8476 ;; then we should be at the declarator now, so check for a 8476 (looking-at c-brace-list-key))))))
8477 ;; valid declarator start. 8477 (or
8478 ;; 8478 ;; Found a keyword that can't be a type?
8479 ;; Note: This doesn't cope with the case when a declared 8479 (match-beginning 1)
8480 ;; identifier is followed by e.g. '(' in a language where '(' 8480
8481 ;; also might be part of a declarator expression. Currently 8481 ;; Can be a type too, in which case it's the return type of a
8482 ;; there's no such language. 8482 ;; function (under the assumption that no declaration level
8483 (not (or (looking-at c-symbol-start) 8483 ;; block construct starts with a type).
8484 (looking-at c-type-decl-prefix-key))))) 8484 (not (c-forward-type))
8485
8486 ;; Jumped over a type, but it could be a declaration keyword
8487 ;; followed by the declared identifier that we've jumped over
8488 ;; instead (e.g. in "class Foo {"). If it indeed is a type
8489 ;; then we should be at the declarator now, so check for a
8490 ;; valid declarator start.
8491 ;;
8492 ;; Note: This doesn't cope with the case when a declared
8493 ;; identifier is followed by e.g. '(' in a language where '('
8494 ;; also might be part of a declarator expression. Currently
8495 ;; there's no such language.
8496 (not (or (looking-at c-symbol-start)
8497 (looking-at c-type-decl-prefix-key))))))
8485 8498
8486 ;; In Pike a list of modifiers may be followed by a brace 8499 ;; In Pike a list of modifiers may be followed by a brace
8487 ;; to make them apply to many identifiers. Note that the 8500 ;; to make them apply to many identifiers. Note that the
8488 ;; match data will be empty on return in this case. 8501 ;; match data will be empty on return in this case.
8489 ((and (c-major-mode-is 'pike-mode) 8502 ((and (c-major-mode-is 'pike-mode)
8490 (progn 8503 (progn
@@ -8586,11 +8599,44 @@ comment at the start of cc-engine.el for more info."
8586 (not (looking-at "="))))) 8599 (not (looking-at "=")))))
8587 b-pos))) 8600 b-pos)))
8588 8601
8602(defun c-backward-colon-prefixed-type ()
8603 ;; We're at the token after what might be a type prefixed with a colon. Try
8604 ;; moving backward over this type and the colon. On success, return t and
8605 ;; leave point before colon, on falure, leave point unchanged. Will clobber
8606 ;; match data.
8607 (let ((here (point))
8608 (colon-pos nil))
8609 (save-excursion
8610 (while
8611 (and (eql (c-backward-token-2) 0)
8612 (or (not (looking-at "\\s)"))
8613 (c-go-up-list-backward))
8614 (cond
8615 ((eql (char-after) ?:)
8616 (setq colon-pos (point))
8617 (forward-char)
8618 (c-forward-syntactic-ws)
8619 (or (and (c-forward-type)
8620 (progn (c-forward-syntactic-ws)
8621 (eq (point) here)))
8622 (setq colon-pos nil))
8623 nil)
8624 ((eql (char-after) ?\()
8625 t)
8626 ((looking-at c-symbol-key)
8627 t)
8628 (t nil)))))
8629 (when colon-pos
8630 (goto-char colon-pos)
8631 t)))
8632
8589(defun c-backward-over-enum-header () 8633(defun c-backward-over-enum-header ()
8590 ;; We're at a "{". Move back to the enum-like keyword that starts this 8634 ;; We're at a "{". Move back to the enum-like keyword that starts this
8591 ;; declaration and return t, otherwise don't move and return nil. 8635 ;; declaration and return t, otherwise don't move and return nil.
8592 (let ((here (point)) 8636 (let ((here (point))
8593 up-sexp-pos before-identifier) 8637 up-sexp-pos before-identifier)
8638 (when c-recognize-post-brace-list-type-p
8639 (c-backward-colon-prefixed-type))
8594 (while 8640 (while
8595 (and 8641 (and
8596 (eq (c-backward-token-2) 0) 8642 (eq (c-backward-token-2) 0)
@@ -8601,10 +8647,11 @@ comment at the start of cc-engine.el for more info."
8601 (not before-identifier)) 8647 (not before-identifier))
8602 (setq before-identifier t)) 8648 (setq before-identifier t))
8603 ((and before-identifier 8649 ((and before-identifier
8604 (or (eq (char-after) ?,) 8650 (or (eql (char-after) ?,)
8605 (looking-at c-postfix-decl-spec-key))) 8651 (looking-at c-postfix-decl-spec-key)))
8606 (setq before-identifier nil) 8652 (setq before-identifier nil)
8607 t) 8653 t)
8654 ((looking-at c-after-brace-list-key) t)
8608 ((looking-at c-brace-list-key) nil) 8655 ((looking-at c-brace-list-key) nil)
8609 ((and c-recognize-<>-arglists 8656 ((and c-recognize-<>-arglists
8610 (eq (char-after) ?<) 8657 (eq (char-after) ?<)
diff --git a/lisp/progmodes/cc-langs.el b/lisp/progmodes/cc-langs.el
index a8dc3b8968c..2a5db6d3c86 100644
--- a/lisp/progmodes/cc-langs.el
+++ b/lisp/progmodes/cc-langs.el
@@ -1807,6 +1807,26 @@ will be handled."
1807 t (c-make-keywords-re t (c-lang-const c-brace-list-decl-kwds))) 1807 t (c-make-keywords-re t (c-lang-const c-brace-list-decl-kwds)))
1808(c-lang-defvar c-brace-list-key (c-lang-const c-brace-list-key)) 1808(c-lang-defvar c-brace-list-key (c-lang-const c-brace-list-key))
1809 1809
1810(c-lang-defconst c-after-brace-list-decl-kwds
1811 "Keywords that might follow keywords in `c-brace-list-decl-kwds'
1812and precede the opening brace."
1813 t nil
1814 c++ '("class" "struct"))
1815
1816(c-lang-defconst c-after-brace-list-key
1817 ;; Regexp matching keywords that can fall between a brace-list
1818 ;; keyword and the associated brace list.
1819 t (c-make-keywords-re t (c-lang-const c-after-brace-list-decl-kwds)))
1820(c-lang-defvar c-after-brace-list-key (c-lang-const c-after-brace-list-key))
1821
1822(c-lang-defconst c-recognize-post-brace-list-type-p
1823 "Set to t when we recognize a colon and then a type after an enum,
1824e.g., enum foo : int { A, B, C };"
1825 t nil
1826 c++ t)
1827(c-lang-defvar c-recognize-post-brace-list-type-p
1828 (c-lang-const c-recognize-post-brace-list-type-p))
1829
1810(c-lang-defconst c-other-block-decl-kwds 1830(c-lang-defconst c-other-block-decl-kwds
1811 "Keywords where the following block (if any) contains another 1831 "Keywords where the following block (if any) contains another
1812declaration level that should not be considered a class. For every 1832declaration level that should not be considered a class. For every