;; If a declaration is parsed:
;;
;; The point is left at the first token after the first complete
- ;; declarator, if there is one. The return value is a list of 4 elements,
+ ;; declarator, if there is one. The return value is a list of 5 elements,
;; where the first is the position of the first token in the declarator.
- ;; (See below for the other three.)
+ ;; (See below for the other four.)
;; Some examples:
;;
;; void foo (int a, char *b) stuff ...
;;
;; The third element of the return value is non-nil when the declaration
;; parsed might be an expression. The fourth element is the position of
- ;; the start of the type identifier.
+ ;; the start of the type identifier. The fifth element is t if either
+ ;; CONTEXT was 'top, or the declaration is detected to be treated as top
+ ;; level (e.g. with the keyword "extern").
;;
;; If a cast is parsed:
;;
;; Set when the symbol before `preceding-token-end' is known to
;; terminate the previous construct, or when we're at point-min.
at-decl-start
+ ;; Set when we have encountered a keyword (e.g. "extern") which
+ ;; causes the following declaration to be treated as though top-level.
+ make-top
;; Save `c-record-type-identifiers' and
;; `c-record-ref-identifiers' since ranges are recorded
;; speculatively and should be thrown away if it turns out
(cond
;; Look for a specifier keyword clause.
- ((or (looking-at c-prefix-spec-kwds-re)
+ ((or (and (looking-at c-make-top-level-key)
+ (setq make-top t))
+ (looking-at c-prefix-spec-kwds-re)
(and (c-major-mode-is 'java-mode)
(looking-at "@[A-Za-z0-9]+")))
(save-match-data
;; construct here in C, since we want to recognize this as a
;; typeless function declaration.
(not (and (c-major-mode-is 'c-mode)
- (eq context 'top)
+ (or (eq context 'top) make-top)
(eq (char-after) ?\)))))
(if (eq (char-after) ?\))
(when (> paren-depth 0)
;; Recognize a top-level typeless
;; function declaration in C.
(and (c-major-mode-is 'c-mode)
- (eq context 'top)
+ (or (eq context 'top) make-top)
(eq (char-after) ?\))))))))
(setq pos (c-up-list-forward (point)))
(eq (char-before pos) ?\)))
(when (and got-identifier
(looking-at c-after-suffixed-type-decl-key)
(or (eq context 'top)
+ make-top
(and (eq context nil)
(match-beginning 1)))
(if (and got-parens
;; CASE 19
(or (eq context 'decl)
(and (c-major-mode-is 'c-mode)
- (eq context 'top))))))
+ (or (eq context 'top) make-top))))))
;; The point is now after the type decl expression.
(and (or at-type-decl at-typedef)
(cons at-type-decl at-typedef))
maybe-expression
- type-start))
+ type-start
+ (or (eq context 'top) make-top)))
(t
;; False alarm. Restore the recorded ranges.
;; Got a cached hit in some other type of arglist.
(type
(cons 'arglist t))
+ ;; We're at a C++ uniform initialization.
+ ((and (c-major-mode-is 'c++-mode)
+ (eq (char-before match-pos) ?\()
+ (save-excursion
+ (goto-char match-pos)
+ (and
+ (zerop (c-backward-token-2 2))
+ (looking-at c-identifier-start)
+ (c-got-face-at (point)
+ '(font-lock-variable-name-face)))))
+ (cons 'not-decl nil))
((and not-front-decl
;; The point is within the range of a previously
;; encountered type decl expression, so the arglist
(setq max-type-decl-end (point))))
(goto-char start-pos)
(c-font-lock-single-decl limit decl-or-cast match-pos
- context toplev))
+ context
+ (or toplev (nth 4 decl-or-cast))))
(t t))))
t nil
(c c++ objc) '("extern"))
+(c-lang-defconst c-make-top-level-kwds
+ "Keywords which make declarations they introduce be handled as top-level."
+ t nil
+ (c c++ objc) '("extern"))
+
+(c-lang-defconst c-make-top-level-key
+ ;; A regexp which matches any `c-make-top-level-kwds' keyword.
+ t (c-make-keywords-re t (c-lang-const c-make-top-level-kwds)))
+(c-lang-defvar c-make-top-level-key (c-lang-const c-make-top-level-key))
+
(c-lang-defconst c-type-list-kwds
"Keywords that may be followed by a comma separated list of type
identifiers, where each optionally can be prefixed by keywords. (Can