CC Mode: Move the handling of keyword auto into type handling for C++.
This should allow auto, const, static, ... to be in any order. * lisp/progmodes/cc-engine.el (c-forward-type): New return value 'no-id for when auto precludes the parsing of a type identifier. Adapt processing for this. (c-forward-decl-or-cast-1): Use the new facility from c-forward-type. * lisp/progmodes/cc-langs.el (c-type-modifier-prefix-kwds): Insert the value of c-no-type-kwds into the value. (c-no-type-kwds, c-no-type-key): New lang consts/vars, basically "auto". (c-typeless-decl-kwds, c-modifier-kwds): Remove "auto" from the C++ value.
This commit is contained in:
parent
c7804ac401
commit
81fe8990c0
2 changed files with 55 additions and 34 deletions
|
@ -8426,6 +8426,7 @@ comment at the start of cc-engine.el for more info."
|
|||
;; o - 'found if it's a type that matches one in `c-found-types';
|
||||
;; o - 'maybe if it's an identifier that might be a type;
|
||||
;; o - 'decltype if it's a decltype(variable) declaration; - or
|
||||
;; o - 'no-id if "auto" precluded parsing a type identifier.
|
||||
;; o - nil if it can't be a type (the point isn't moved then).
|
||||
;;
|
||||
;; The point is assumed to be at the beginning of a token.
|
||||
|
@ -8450,9 +8451,12 @@ comment at the start of cc-engine.el for more info."
|
|||
;; prefix of a type.
|
||||
(when c-opt-type-modifier-prefix-key ; e.g. "const" "volatile", but NOT "typedef"
|
||||
(while (looking-at c-opt-type-modifier-prefix-key)
|
||||
(when (looking-at c-no-type-key)
|
||||
(setq res 'no-id))
|
||||
(goto-char (match-end 1))
|
||||
(c-forward-syntactic-ws)
|
||||
(setq res 'prefix)))
|
||||
(or (eq res 'no-id)
|
||||
(setq res 'prefix))))
|
||||
|
||||
(cond
|
||||
((looking-at c-typeof-key) ; e.g. C++'s "decltype".
|
||||
|
@ -8503,28 +8507,30 @@ comment at the start of cc-engine.el for more info."
|
|||
(setq res t))
|
||||
(unless res (goto-char start))) ; invalid syntax
|
||||
|
||||
((progn
|
||||
(setq pos nil)
|
||||
(if (looking-at c-identifier-start)
|
||||
(save-excursion
|
||||
(setq id-start (point)
|
||||
name-res (c-forward-name))
|
||||
(when name-res
|
||||
(setq id-end (point)
|
||||
id-range c-last-identifier-range))))
|
||||
(and (cond ((looking-at c-primitive-type-key)
|
||||
(setq res t))
|
||||
((c-with-syntax-table c-identifier-syntax-table
|
||||
(looking-at c-known-type-key))
|
||||
(setq res 'known)))
|
||||
(or (not id-end)
|
||||
(>= (save-excursion
|
||||
(save-match-data
|
||||
(goto-char (match-end 1))
|
||||
(c-forward-syntactic-ws)
|
||||
(setq pos (point))))
|
||||
id-end)
|
||||
(setq res nil))))
|
||||
((and
|
||||
(not (eq res 'no-id))
|
||||
(progn
|
||||
(setq pos nil)
|
||||
(if (looking-at c-identifier-start)
|
||||
(save-excursion
|
||||
(setq id-start (point)
|
||||
name-res (c-forward-name))
|
||||
(when name-res
|
||||
(setq id-end (point)
|
||||
id-range c-last-identifier-range))))
|
||||
(and (cond ((looking-at c-primitive-type-key)
|
||||
(setq res t))
|
||||
((c-with-syntax-table c-identifier-syntax-table
|
||||
(looking-at c-known-type-key))
|
||||
(setq res 'known)))
|
||||
(or (not id-end)
|
||||
(>= (save-excursion
|
||||
(save-match-data
|
||||
(goto-char (match-end 1))
|
||||
(c-forward-syntactic-ws)
|
||||
(setq pos (point))))
|
||||
id-end)
|
||||
(setq res nil)))))
|
||||
;; Looking at a primitive or known type identifier. We've
|
||||
;; checked for a name first so that we don't go here if the
|
||||
;; known type match only is a prefix of another name.
|
||||
|
@ -8599,7 +8605,7 @@ comment at the start of cc-engine.el for more info."
|
|||
(goto-char start)
|
||||
(setq res nil)))))
|
||||
|
||||
(when res
|
||||
(when (not (memq res '(nil no-id)))
|
||||
;; Skip trailing type modifiers. If any are found we know it's
|
||||
;; a type.
|
||||
(when c-opt-type-modifier-key
|
||||
|
@ -9452,12 +9458,11 @@ This function might do hidden buffer changes."
|
|||
|
||||
(when (setq found-type (c-forward-type t)) ; brace-block-too
|
||||
;; Found a known or possible type or a prefix of a known type.
|
||||
(when (and (c-major-mode-is 'c++-mode) ; C++11 style "auto"?
|
||||
(eq prev-kwd-sym (c-keyword-sym "auto"))
|
||||
(looking-at "[=(]")) ; FIXME!!! proper regexp.
|
||||
(setq new-style-auto t)
|
||||
(setq found-type nil)
|
||||
(goto-char start)) ; position of foo in "auto foo"
|
||||
(when (and (eq found-type 'no-id)
|
||||
(save-excursion
|
||||
(and (c-forward-name) ; over the identifier
|
||||
(looking-at "[=(]")))) ; FIXME!!! proper regexp.
|
||||
(setq new-style-auto t)) ; position of foo in "auto foo"
|
||||
|
||||
(when at-type
|
||||
;; Got two identifiers with nothing but whitespace
|
||||
|
@ -9540,7 +9545,7 @@ This function might do hidden buffer changes."
|
|||
;; over all specifiers and type identifiers. The reason
|
||||
;; to do this for a known type prefix is to make things
|
||||
;; like "unsigned INT16" work.
|
||||
(and found-type (not (eq found-type t))))))
|
||||
(and found-type (not (memq found-type '(t no-id)))))))
|
||||
|
||||
(cond
|
||||
((eq at-type t)
|
||||
|
@ -9560,6 +9565,10 @@ This function might do hidden buffer changes."
|
|||
;; followed by another type.
|
||||
(setq at-type t))
|
||||
|
||||
((eq at-type 'no-id)
|
||||
;; For an auto type, we assume we definitely have a type construct.
|
||||
(setq at-type t))
|
||||
|
||||
((not at-type)
|
||||
;; Got no type but set things up to continue anyway to handle
|
||||
;; the various cases when a declaration doesn't start with a
|
||||
|
|
|
@ -2121,7 +2121,9 @@ fontified with the keyword face and not the type face."
|
|||
t nil
|
||||
c '("const" "restrict" "volatile")
|
||||
c++ '("const" "noexcept" "volatile")
|
||||
objc '("const" "volatile"))
|
||||
objc '("const" "volatile")
|
||||
t (append (c-lang-const c-no-type-kwds)
|
||||
(c-lang-const c-type-modifier-prefix-kwds)))
|
||||
|
||||
(c-lang-defconst c-opt-type-modifier-prefix-key
|
||||
;; Adorned regexp matching `c-type-modifier-prefix-kwds', or nil in
|
||||
|
@ -2348,6 +2350,16 @@ will be handled."
|
|||
t (c-make-keywords-re t (c-lang-const c-using-kwds)))
|
||||
(c-lang-defvar c-using-key (c-lang-const c-using-key))
|
||||
|
||||
(c-lang-defconst c-no-type-kwds
|
||||
"Keywords which remove the need to specify a type in declarations"
|
||||
t nil
|
||||
c++ '("auto"))
|
||||
|
||||
(c-lang-defconst c-no-type-key
|
||||
;; Regexp matching an entry from `c-no-type-kwds'
|
||||
t (c-make-keywords-re t (c-lang-const c-no-type-kwds)))
|
||||
(c-lang-defvar c-no-type-key (c-lang-const c-no-type-key))
|
||||
|
||||
(c-lang-defconst c-typeless-decl-kwds
|
||||
"Keywords introducing declarations where the (first) identifier
|
||||
\(declarator) follows directly after the keyword, without any type.
|
||||
|
@ -2361,7 +2373,6 @@ will be handled."
|
|||
;; {...}").
|
||||
t (append (c-lang-const c-class-decl-kwds)
|
||||
(c-lang-const c-brace-list-decl-kwds))
|
||||
c++ (append (c-lang-const c-typeless-decl-kwds) '("auto")) ; C++11.
|
||||
;; Note: "manages" for CORBA CIDL clashes with its presence on
|
||||
;; `c-type-list-kwds' for IDL.
|
||||
idl (append (c-lang-const c-typeless-decl-kwds)
|
||||
|
@ -2396,7 +2407,8 @@ If any of these also are on `c-type-list-kwds', `c-ref-list-kwds',
|
|||
`c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses
|
||||
will be handled."
|
||||
t nil
|
||||
(c c++) '("auto" "extern" "inline" "register" "static")
|
||||
(c c++) '("extern" "inline" "register" "static")
|
||||
c (append '("auto") (c-lang-const c-modifier-kwds))
|
||||
c++ (append '("constexpr" "explicit" "friend" "mutable" "template"
|
||||
"thread_local" "virtual")
|
||||
;; "using" is now handled specially (2020-09-14).
|
||||
|
|
Loading…
Add table
Reference in a new issue