diff options
| author | Alan Mackenzie | 2014-12-19 18:35:14 +0000 |
|---|---|---|
| committer | Alan Mackenzie | 2014-12-19 18:35:14 +0000 |
| commit | 948fa912de164a1374c87e9206cddca741b7fa33 (patch) | |
| tree | eae718e2393cf187800ae2fbfb2aa03b63dffb99 | |
| parent | 164cdfbf9e75a891bd8944a79f53bd403c6c2215 (diff) | |
| download | emacs-948fa912de164a1374c87e9206cddca741b7fa33.tar.gz emacs-948fa912de164a1374c87e9206cddca741b7fa33.zip | |
Make C++11 uniform init syntax work. New keywords "final" and "override"
cc-engine.el (c-back-over-member-initializer-braces): New function.
(c-guess-basic-syntax): Set `containing-sex' and `lim' using the new
function.
cc-fonts.el (c-font-lock-declarations): Check more carefully for "are we
at a declarator?" using c-back-over-member-initializers.
cc-langs.el (c-type-modifier-kwds): include "final" and "override" in
the
C++ value.
| -rw-r--r-- | lisp/ChangeLog | 16 | ||||
| -rw-r--r-- | lisp/progmodes/cc-engine.el | 58 | ||||
| -rw-r--r-- | lisp/progmodes/cc-fonts.el | 62 | ||||
| -rw-r--r-- | lisp/progmodes/cc-langs.el | 2 |
4 files changed, 95 insertions, 43 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index feeab01a106..12530a997ba 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,19 @@ | |||
| 1 | 2014-12-19 Alan Mackenzie <acm@muc.de> | ||
| 2 | |||
| 3 | Make C++11 uniform init syntax work. New keywords "final" and "override" | ||
| 4 | |||
| 5 | * progmodes/cc-engine.el (c-back-over-member-initializer-braces): | ||
| 6 | New function. | ||
| 7 | (c-guess-basic-syntax): Set `containing-sex' and `lim' using the | ||
| 8 | new function. | ||
| 9 | |||
| 10 | * progmodes/cc-fonts.el (c-font-lock-declarations): Check more | ||
| 11 | carefully for "are we at a declarator?" using | ||
| 12 | c-back-over-member-initializers. | ||
| 13 | |||
| 14 | * progmodes/cc-langs.el (c-type-modifier-kwds): include "final" | ||
| 15 | and "override" in the C++ value. | ||
| 16 | |||
| 1 | 2014-12-19 Martin Rudalics <rudalics@gmx.at> | 17 | 2014-12-19 Martin Rudalics <rudalics@gmx.at> |
| 2 | 18 | ||
| 3 | * textmodes/ispell.el (ispell-command-loop): Don't use | 19 | * textmodes/ispell.el (ispell-command-loop): Don't use |
diff --git a/lisp/progmodes/cc-engine.el b/lisp/progmodes/cc-engine.el index a24cb3d7488..9a6e975dd93 100644 --- a/lisp/progmodes/cc-engine.el +++ b/lisp/progmodes/cc-engine.el | |||
| @@ -6588,6 +6588,36 @@ comment at the start of cc-engine.el for more info." | |||
| 6588 | (prog1 (car ,ps) | 6588 | (prog1 (car ,ps) |
| 6589 | (setq ,ps (cdr ,ps))))) | 6589 | (setq ,ps (cdr ,ps))))) |
| 6590 | 6590 | ||
| 6591 | (defun c-back-over-member-initializer-braces () | ||
| 6592 | ;; Point is just after a closing brace/parenthesis. Try to parse this as a | ||
| 6593 | ;; C++ member initializer list, going back to just after the introducing ":" | ||
| 6594 | ;; and returning t. Otherwise return nil, leaving point unchanged. | ||
| 6595 | (let ((here (point)) res) | ||
| 6596 | (setq res | ||
| 6597 | (catch 'done | ||
| 6598 | (when (not (c-go-list-backward)) | ||
| 6599 | (throw 'done nil)) | ||
| 6600 | (c-backward-syntactic-ws) | ||
| 6601 | (when (not (c-simple-skip-symbol-backward)) | ||
| 6602 | (throw 'done nil)) | ||
| 6603 | (c-backward-syntactic-ws) | ||
| 6604 | |||
| 6605 | (while (eq (char-before) ?,) | ||
| 6606 | (backward-char) | ||
| 6607 | (c-backward-syntactic-ws) | ||
| 6608 | (when (not (memq (char-before) '(?\) ?}))) | ||
| 6609 | (throw 'done nil)) | ||
| 6610 | (when (not (c-go-list-backward)) | ||
| 6611 | (throw 'done nil)) | ||
| 6612 | (c-backward-syntactic-ws) | ||
| 6613 | (when (not (c-simple-skip-symbol-backward)) | ||
| 6614 | (throw 'done nil)) | ||
| 6615 | (c-backward-syntactic-ws)) | ||
| 6616 | |||
| 6617 | (eq (char-before) ?:))) | ||
| 6618 | (or res (goto-char here)) | ||
| 6619 | res)) | ||
| 6620 | |||
| 6591 | (defun c-back-over-member-initializers () | 6621 | (defun c-back-over-member-initializers () |
| 6592 | ;; Test whether we are in a C++ member initializer list, and if so, go back | 6622 | ;; Test whether we are in a C++ member initializer list, and if so, go back |
| 6593 | ;; to the introducing ":", returning the position of the opening paren of | 6623 | ;; to the introducing ":", returning the position of the opening paren of |
| @@ -9588,22 +9618,26 @@ comment at the start of cc-engine.el for more info." | |||
| 9588 | (c-keyword-sym (match-string 1))))) | 9618 | (c-keyword-sym (match-string 1))))) |
| 9589 | 9619 | ||
| 9590 | ;; Init some position variables. | 9620 | ;; Init some position variables. |
| 9591 | (if c-state-cache | 9621 | (if paren-state |
| 9592 | (progn | 9622 | (progn |
| 9593 | (setq containing-sexp (car paren-state) | 9623 | (setq containing-sexp (car paren-state) |
| 9594 | paren-state (cdr paren-state)) | 9624 | paren-state (cdr paren-state)) |
| 9595 | (if (consp containing-sexp) | 9625 | (if (consp containing-sexp) |
| 9596 | (progn | 9626 | (save-excursion |
| 9597 | (setq lim (cdr containing-sexp)) | 9627 | (goto-char (cdr containing-sexp)) |
| 9598 | (if (cdr c-state-cache) | 9628 | (if (and (c-major-mode-is 'c++-mode) |
| 9599 | ;; Ignore balanced paren. The next entry | 9629 | (c-back-over-member-initializer-braces)) |
| 9600 | ;; can't be another one. | 9630 | (c-syntactic-skip-backward "^}" nil t)) |
| 9601 | (setq containing-sexp (car (cdr c-state-cache)) | 9631 | (setq lim (point)) |
| 9602 | paren-state (cdr paren-state)) | 9632 | (if paren-state |
| 9603 | ;; If there is no surrounding open paren then | 9633 | ;; Ignore balanced paren. The next entry |
| 9604 | ;; put the last balanced pair back on paren-state. | 9634 | ;; can't be another one. |
| 9605 | (setq paren-state (cons containing-sexp paren-state) | 9635 | (setq containing-sexp (car paren-state) |
| 9606 | containing-sexp nil))) | 9636 | paren-state (cdr paren-state)) |
| 9637 | ;; If there is no surrounding open paren then | ||
| 9638 | ;; put the last balanced pair back on paren-state. | ||
| 9639 | (setq paren-state (cons containing-sexp paren-state) | ||
| 9640 | containing-sexp nil))) | ||
| 9607 | (setq lim (1+ containing-sexp)))) | 9641 | (setq lim (1+ containing-sexp)))) |
| 9608 | (setq lim (point-min))) | 9642 | (setq lim (point-min))) |
| 9609 | 9643 | ||
diff --git a/lisp/progmodes/cc-fonts.el b/lisp/progmodes/cc-fonts.el index 448e76427f2..d39376a2f03 100644 --- a/lisp/progmodes/cc-fonts.el +++ b/lisp/progmodes/cc-fonts.el | |||
| @@ -1464,36 +1464,38 @@ casts and declarations are fontified. Used on level 2 and higher." | |||
| 1464 | c-recognize-knr-p) ; Strictly speaking, bogus, but it | 1464 | c-recognize-knr-p) ; Strictly speaking, bogus, but it |
| 1465 | ; speeds up lisp.h tremendously. | 1465 | ; speeds up lisp.h tremendously. |
| 1466 | (save-excursion | 1466 | (save-excursion |
| 1467 | (unless (or (eobp) | 1467 | (if (c-back-over-member-initializers) |
| 1468 | (looking-at "\\s(\\|\\s)")) | 1468 | t ; Can't be at a declarator |
| 1469 | (forward-char)) | 1469 | (unless (or (eobp) |
| 1470 | (setq bod-res (car (c-beginning-of-decl-1 decl-search-lim))) | 1470 | (looking-at "\\s(\\|\\s)")) |
| 1471 | (if (and (eq bod-res 'same) | 1471 | (forward-char)) |
| 1472 | (save-excursion | 1472 | (setq bod-res (car (c-beginning-of-decl-1 decl-search-lim))) |
| 1473 | (c-backward-syntactic-ws) | 1473 | (if (and (eq bod-res 'same) |
| 1474 | (eq (char-before) ?\}))) | 1474 | (save-excursion |
| 1475 | (c-beginning-of-decl-1 decl-search-lim)) | 1475 | (c-backward-syntactic-ws) |
| 1476 | 1476 | (eq (char-before) ?\}))) | |
| 1477 | ;; We're now putatively at the declaration. | 1477 | (c-beginning-of-decl-1 decl-search-lim)) |
| 1478 | (setq paren-state (c-parse-state)) | 1478 | |
| 1479 | ;; At top level or inside a "{"? | 1479 | ;; We're now putatively at the declaration. |
| 1480 | (if (or (not (setq encl-pos | 1480 | (setq paren-state (c-parse-state)) |
| 1481 | (c-most-enclosing-brace paren-state))) | 1481 | ;; At top level or inside a "{"? |
| 1482 | (eq (char-after encl-pos) ?\{)) | 1482 | (if (or (not (setq encl-pos |
| 1483 | (progn | 1483 | (c-most-enclosing-brace paren-state))) |
| 1484 | (when (looking-at c-typedef-key) ; "typedef" | 1484 | (eq (char-after encl-pos) ?\{)) |
| 1485 | (setq is-typedef t) | 1485 | (progn |
| 1486 | (goto-char (match-end 0)) | 1486 | (when (looking-at c-typedef-key) ; "typedef" |
| 1487 | (c-forward-syntactic-ws)) | 1487 | (setq is-typedef t) |
| 1488 | ;; At a real declaration? | 1488 | (goto-char (match-end 0)) |
| 1489 | (if (memq (c-forward-type t) '(t known found decltype)) | 1489 | (c-forward-syntactic-ws)) |
| 1490 | (progn | 1490 | ;; At a real declaration? |
| 1491 | (c-font-lock-declarators (point-max) t is-typedef) | 1491 | (if (memq (c-forward-type t) '(t known found decltype)) |
| 1492 | nil) | 1492 | (progn |
| 1493 | ;; False alarm. Return t to go on to the next check. | 1493 | (c-font-lock-declarators (point-max) t is-typedef) |
| 1494 | (goto-char start-pos) | 1494 | nil) |
| 1495 | t)) | 1495 | ;; False alarm. Return t to go on to the next check. |
| 1496 | t)))))) | 1496 | (goto-char start-pos) |
| 1497 | t)) | ||
| 1498 | t))))))) | ||
| 1497 | 1499 | ||
| 1498 | ;; It was a false alarm. Check if we're in a label (or other | 1500 | ;; It was a false alarm. Check if we're in a label (or other |
| 1499 | ;; construct with `:' except bitfield) instead. | 1501 | ;; construct with `:' except bitfield) instead. |
diff --git a/lisp/progmodes/cc-langs.el b/lisp/progmodes/cc-langs.el index b93cc780732..31298d74e48 100644 --- a/lisp/progmodes/cc-langs.el +++ b/lisp/progmodes/cc-langs.el | |||
| @@ -1741,7 +1741,7 @@ but they don't build a type of themselves. Unlike the keywords on | |||
| 1741 | not the type face." | 1741 | not the type face." |
| 1742 | t nil | 1742 | t nil |
| 1743 | c '("const" "restrict" "volatile") | 1743 | c '("const" "restrict" "volatile") |
| 1744 | c++ '("const" "constexpr" "noexcept" "volatile" "throw") | 1744 | c++ '("const" "constexpr" "noexcept" "volatile" "throw" "final" "override") |
| 1745 | objc '("const" "volatile")) | 1745 | objc '("const" "volatile")) |
| 1746 | 1746 | ||
| 1747 | (c-lang-defconst c-opt-type-modifier-key | 1747 | (c-lang-defconst c-opt-type-modifier-key |