]> git.eshelyaron.com Git - emacs.git/commitdiff
Make C++11 uniform init syntax work. New keywords "final" and "override"
authorAlan Mackenzie <acm@muc.de>
Fri, 19 Dec 2014 18:35:14 +0000 (18:35 +0000)
committerAlan Mackenzie <acm@muc.de>
Fri, 19 Dec 2014 18:35:14 +0000 (18:35 +0000)
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.

lisp/ChangeLog
lisp/progmodes/cc-engine.el
lisp/progmodes/cc-fonts.el
lisp/progmodes/cc-langs.el

index feeab01a106fe1358a9266fcac1d724b5084b0a8..12530a997ba817133428c655128c92f14dd0d2e8 100644 (file)
@@ -1,3 +1,19 @@
+2014-12-19  Alan Mackenzie  <acm@muc.de>
+
+       Make C++11 uniform init syntax work.  New keywords "final" and "override"
+
+       * progmodes/cc-engine.el (c-back-over-member-initializer-braces):
+       New function.
+       (c-guess-basic-syntax): Set `containing-sex' and `lim' using the
+       new function.
+
+       * progmodes/cc-fonts.el (c-font-lock-declarations): Check more
+       carefully for "are we at a declarator?" using
+       c-back-over-member-initializers.
+
+       * progmodes/cc-langs.el (c-type-modifier-kwds): include "final"
+       and "override" in the C++ value.
+
 2014-12-19  Martin Rudalics  <rudalics@gmx.at>
 
        * textmodes/ispell.el (ispell-command-loop): Don't use
index a24cb3d7488312739c033272eeedb56a16d81f83..9a6e975dd93158ff77eae58ea870cee2054ce72a 100644 (file)
@@ -6588,6 +6588,36 @@ comment at the start of cc-engine.el for more info."
      (prog1 (car ,ps)
        (setq ,ps (cdr ,ps)))))
 
+(defun c-back-over-member-initializer-braces ()
+  ;; Point is just after a closing brace/parenthesis.  Try to parse this as a
+  ;; C++ member initializer list, going back to just after the introducing ":"
+  ;; and returning t.  Otherwise return nil, leaving point unchanged.
+  (let ((here (point)) res)
+    (setq res
+       (catch 'done
+         (when (not (c-go-list-backward))
+           (throw 'done nil))
+         (c-backward-syntactic-ws)
+         (when (not (c-simple-skip-symbol-backward))
+           (throw 'done nil))
+         (c-backward-syntactic-ws)
+
+         (while (eq (char-before) ?,)
+           (backward-char)
+           (c-backward-syntactic-ws)
+           (when (not (memq (char-before) '(?\) ?})))
+             (throw 'done nil))
+           (when (not (c-go-list-backward))
+             (throw 'done nil))
+           (c-backward-syntactic-ws)
+           (when (not (c-simple-skip-symbol-backward))
+             (throw 'done nil))
+           (c-backward-syntactic-ws))
+
+         (eq (char-before) ?:)))
+    (or res (goto-char here))
+    res))
+
 (defun c-back-over-member-initializers ()
   ;; Test whether we are in a C++ member initializer list, and if so, go back
   ;; 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."
                                       (c-keyword-sym (match-string 1)))))
 
       ;; Init some position variables.
-      (if c-state-cache
+      (if paren-state
          (progn
            (setq containing-sexp (car paren-state)
                  paren-state (cdr paren-state))
            (if (consp containing-sexp)
-               (progn
-                 (setq lim (cdr containing-sexp))
-                 (if (cdr c-state-cache)
-                     ;; Ignore balanced paren.  The next entry
-                     ;; can't be another one.
-                     (setq containing-sexp (car (cdr c-state-cache))
-                           paren-state (cdr paren-state))
-                   ;; If there is no surrounding open paren then
-                   ;; put the last balanced pair back on paren-state.
-                   (setq paren-state (cons containing-sexp paren-state)
-                         containing-sexp nil)))
+             (save-excursion
+               (goto-char (cdr containing-sexp))
+               (if (and (c-major-mode-is 'c++-mode)
+                        (c-back-over-member-initializer-braces))
+                     (c-syntactic-skip-backward "^}" nil t))
+               (setq lim (point))
+               (if paren-state
+                   ;; Ignore balanced paren.    The next entry
+                   ;; can't be another one.
+                   (setq containing-sexp (car paren-state)
+                         paren-state (cdr paren-state))
+                 ;; If there is no surrounding open paren then
+                 ;; put the last balanced pair back on paren-state.
+                 (setq paren-state (cons containing-sexp paren-state)
+                       containing-sexp nil)))
              (setq lim (1+ containing-sexp))))
        (setq lim (point-min)))
 
index 448e76427f277de96e1e01aa92179b3534ea2238..d39376a2f03673fd491775e2d30174235705ae67 100644 (file)
@@ -1464,36 +1464,38 @@ casts and declarations are fontified.  Used on level 2 and higher."
                    c-recognize-knr-p) ; Strictly speaking, bogus, but it
                                       ; speeds up lisp.h tremendously.
                (save-excursion
-                 (unless (or (eobp)
-                             (looking-at "\\s(\\|\\s)"))
-                   (forward-char))
-                 (setq bod-res (car (c-beginning-of-decl-1 decl-search-lim)))
-                 (if (and (eq bod-res 'same)
-                          (save-excursion
-                            (c-backward-syntactic-ws)
-                            (eq (char-before) ?\})))
-                     (c-beginning-of-decl-1 decl-search-lim))
-
-                 ;; We're now putatively at the declaration.
-                 (setq paren-state (c-parse-state))
-                 ;; At top level or inside a "{"?
-                 (if (or (not (setq encl-pos
-                                    (c-most-enclosing-brace paren-state)))
-                         (eq (char-after encl-pos) ?\{))
-                     (progn
-                       (when (looking-at c-typedef-key) ; "typedef"
-                         (setq is-typedef t)
-                         (goto-char (match-end 0))
-                         (c-forward-syntactic-ws))
-                       ;; At a real declaration?
-                       (if (memq (c-forward-type t) '(t known found decltype))
-                           (progn
-                             (c-font-lock-declarators (point-max) t is-typedef)
-                             nil)
-                         ;; False alarm.  Return t to go on to the next check.
-                         (goto-char start-pos)
-                         t))
-                   t))))))
+                 (if (c-back-over-member-initializers)
+                    t                  ; Can't be at a declarator
+                   (unless (or (eobp)
+                               (looking-at "\\s(\\|\\s)"))
+                     (forward-char))
+                   (setq bod-res (car (c-beginning-of-decl-1 decl-search-lim)))
+                   (if (and (eq bod-res 'same)
+                            (save-excursion
+                              (c-backward-syntactic-ws)
+                              (eq (char-before) ?\})))
+                       (c-beginning-of-decl-1 decl-search-lim))
+
+                   ;; We're now putatively at the declaration.
+                   (setq paren-state (c-parse-state))
+                   ;; At top level or inside a "{"?
+                   (if (or (not (setq encl-pos
+                                      (c-most-enclosing-brace paren-state)))
+                           (eq (char-after encl-pos) ?\{))
+                       (progn
+                         (when (looking-at c-typedef-key) ; "typedef"
+                           (setq is-typedef t)
+                           (goto-char (match-end 0))
+                           (c-forward-syntactic-ws))
+                         ;; At a real declaration?
+                         (if (memq (c-forward-type t) '(t known found decltype))
+                             (progn
+                               (c-font-lock-declarators (point-max) t is-typedef)
+                               nil)
+                           ;; False alarm.  Return t to go on to the next check.
+                           (goto-char start-pos)
+                           t))
+                     t)))))))
 
          ;; It was a false alarm.  Check if we're in a label (or other
          ;; construct with `:' except bitfield) instead.
index b93cc7807325ed3f6ad5e584e9311f1dfc796b63..31298d74e4899d9501b999ec86f0265abebb2bc0 100644 (file)
@@ -1741,7 +1741,7 @@ but they don't build a type of themselves.  Unlike the keywords on
 not the type face."
   t    nil
   c    '("const" "restrict" "volatile")
-  c++  '("const" "constexpr" "noexcept" "volatile" "throw")
+  c++  '("const" "constexpr" "noexcept" "volatile" "throw" "final" "override")
   objc '("const" "volatile"))
 
 (c-lang-defconst c-opt-type-modifier-key