;; 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 - 'no-id if "auto" precluded parsing a type identifier (C++)
+ ;; or the type int was implicit (C).
;; 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.
;; Skip leading type modifiers. If any are found we know it's a
;; 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))
+ (when c-maybe-typeless-specifier-re
+ (while (looking-at c-maybe-typeless-specifier-re)
+ (save-match-data
+ (when (looking-at c-no-type-key)
+ (setq res 'no-id)))
(goto-char (match-end 1))
(c-forward-syntactic-ws)
(or (eq res 'no-id)
(not (eq res 'no-id))
(progn
(setq pos nil)
+ (while (and c-opt-cpp-prefix
+ (looking-at c-noise-macro-with-parens-name-re))
+ (c-forward-noise-clause))
(if (looking-at c-identifier-start)
(save-excursion
(setq id-start (point)
(goto-char (match-end 1))
(c-forward-syntactic-ws)))))
+ ((and (eq name-res t)
+ (eq res 'prefix)
+ (c-major-mode-is 'c-mode)
+ (save-excursion
+ (goto-char id-end)
+ (and (not (looking-at c-symbol-start))
+ (not (looking-at c-type-decl-prefix-key)))))
+ ;; A C specifier followed by an implicit int, e.g.
+ ;; "register count;"
+ (goto-char id-start)
+ (setq res 'no-id))
+
(name-res
(cond ((eq name-res t)
;; A normal identifier.
(t
;; Otherwise it's an operator identifier, which is not a type.
(goto-char start)
- (setq res nil)))))
+ (setq res nil))))
+
+ ((eq res 'prefix)
+ ;; Deal with "extern "C" foo_t my_foo;"
+ (setq res nil)))
(when (not (memq res '(nil no-id)))
;; Skip trailing type modifiers. If any are found we know it's
got-suffix-after-parens id-start
paren-depth 0))
- (if (setq at-type (if (eq backup-at-type 'prefix)
- t
- backup-at-type))
+ (if (not (memq
+ (setq at-type (if (eq backup-at-type 'prefix)
+ t
+ backup-at-type))
+ '(nil no-id)))
(setq type-start backup-type-start
id-start backup-id-start)
(setq type-start start-pos
;; Record the type's coordinates in `c-record-type-identifiers' for
;; later fontification.
- (when (and c-record-type-identifiers at-type ;; (not (eq at-type t))
+ (when (and c-record-type-identifiers
+ (not (memq at-type '(nil no-id)))
;; There seems no reason to exclude a token from
;; fontification just because it's "a known type that can't
;; be a name or other expression". 2013-09-18.
t)
"\\>")))
+(c-lang-defconst c-maybe-typeless-specifier-re
+ "Regexp matching keywords which might, but needn't, declare variables with
+no explicit type given, or nil in languages without such specifiers."
+ t (c-lang-const c-opt-type-modifier-prefix-key)
+ c (c-lang-const c-type-decl-prefix-keywords-key))
+(c-lang-defvar c-maybe-typeless-specifier-re
+ (c-lang-const c-maybe-typeless-specifier-re))
+
(c-lang-defconst c-type-decl-prefix-key
"Regexp matching any declarator operator that might precede the
identifier in a declaration, e.g. the \"*\" in \"char *argv\". This