Commit 578d9aaf authored by Alan Mackenzie's avatar Alan Mackenzie

Adapt CC Mode for C++11 uniform initialization.

For fontification, introduce a new "context", 'non-decl, to be used for
brace
lists; also a new value for the property 'c-type, called 'c-not-decl.

* lisp/progmodes/cc-engine.el (c-back-over-compound-identifier): Check that
an ostensible symbol we're going to move over isn't a keyword.
(c-forward-decl-or-cast-1): CASE 1: Where we have two consecutive identifiers
(hence a declaration), and an unmatched open paren, perform
c-fdoc-shift-type-backwards to recognize the partial construct correctly.
Whilst checking a type decl expression, check for and handle C++11's "copy
initialization", where we have <type>(<constant>).  Recognize
<id><id>(... (where the paren is unclosed) as a declaration.
(c-looking-at-or-maybe-in-bracelist): New function, extracted from
c-inside-bracelist-p.  Recognize as bracelists "{"s which are preceded by
valid tokens other than "=".  Recognize a bracelist when preceded by a
template declaration.
(c-inside-bracelist-p): Call c-looking-at-or-maybe-in-bracelist in place of
much inline code.
(c-looking-at-inexpr-block): Amend so that it won't wrongly recognise an
initialization starting "({" as an in-expression block, by checking for
semicolons, as opposed to commas, separating elements inside it.
(c-guess-continued-construct): (CASE B-2): Recognize a brace-list-open by
calling c-looking-at-or-maybe-in-bracelist rather than checking for a
preceding "=".  (CASE B-5): New code to recognize new construct "return {
...}".
(c-guess-basic-syntax): (CASE 5A.3): Additionally recognize a "{" preceded by
"return", or "{" preceded by <type><identifier> as a bracelist.

* lisp/progmodes/cc-fonts.el (c-font-lock-declarations): Recognize brace
lists, giving them `context' 'non-decl.  Pass over elements of one by regexp
search for "," rather than calling c-forward-decl-or-cast-1.

* lisp/progmodes/cc-langs.el (c-return-kwds, c-return-key): New lang
constants/variables to recognize "return".
(c-pre-id-bracelist-key): New lang constant/variable to recognize tokens
which, when preceding an identifier followed by a brace, signify the brace as
a bracelist.

* lisp/progmodes/cc-mode.el (c-fl-decl-start): When searching outwards for
the start of a "local" declaration, move out from an enclosing brace when
that is the start of a brace list.
parent 1f730256
This diff is collapsed.
This diff is collapsed.
......@@ -1772,6 +1772,16 @@ the appropriate place for that."
"array" "float" "function" "int" "mapping" "mixed" "multiset"
"object" "program" "string" "this_program" "void"))
(c-lang-defconst c-return-kwds
"Keywords which return a value to the calling function."
t '("return")
idl nil)
(c-lang-defconst c-return-key
;; Adorned regexp matching `c-return-kwds'.
t (c-make-keywords-re t (c-lang-const c-return-kwds)))
(c-lang-defvar c-return-key (c-lang-const c-return-key))
(c-lang-defconst c-primitive-type-key
;; An adorned regexp that matches `c-primitive-type-kwds'.
t (c-make-keywords-re t (c-lang-const c-primitive-type-kwds)))
......@@ -3150,6 +3160,13 @@ list."
c t)
(c-lang-defvar c-recognize-knr-p (c-lang-const c-recognize-knr-p))
(c-lang-defconst c-pre-id-bracelist-key
"A regexp matching tokens which, preceding an identifier, signify a bracelist.
"
t "\\<\\>"
c++ "new\\([^[:alnum:]_$]\\|$\\)\\|&&?\\(\\S.\\|$\\)")
(c-lang-defvar c-pre-id-bracelist-key (c-lang-const c-pre-id-bracelist-key))
(c-lang-defconst c-recognize-typeless-decls
"Non-nil means function declarations without return type should be
recognized. That can introduce an ambiguity with parenthesized macro
......
......@@ -1351,10 +1351,10 @@ Note that the style variables are always made local to the buffer."
(defun c-fl-decl-start (pos)
;; If the beginning of the line containing POS is in the middle of a "local"
;; declaration (i.e. one which does not start outside of braces enclosing
;; POS, such as a struct), return the beginning of that declaration.
;; Otherwise return nil. Note that declarations, in this sense, can be
;; nested.
;; declaration, return the beginning of that declaration. Otherwise return
;; nil. Note that declarations, in this sense, can be nested. (A local
;; declaration is one which does not start outside of struct braces (and
;; similar) enclosing POS. Brace list braces here are not "similar".
;;
;; This function is called indirectly from font locking stuff - either from
;; c-after-change (to prepare for after-change font-locking) or from font
......@@ -1402,7 +1402,12 @@ Note that the style variables are always made local to the buffer."
(and (eq (char-before) ?\<)
(eq (c-get-char-property
(1- (point)) 'syntax-table)
c-<-as-paren-syntax)))))
c-<-as-paren-syntax))
(and (eq (char-before) ?{)
(save-excursion
(backward-char)
(numberp (c-looking-at-or-maybe-in-bracelist nil))))
)))
(not (bobp)))
(backward-char)) ; back over (, [, <.
(when (and capture-opener (< capture-opener new-pos))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment