1 new commit in cc-mode:
https://bitbucket.org/xemacs/cc-mode/commits/f317d82b1010/
Changeset: f317d82b1010
User: acm
Date: 2017-12-13 20:28:28+00:00
Summary: Don't misfontify "foo ()" inside C++ initialization parentheses
as a type
Also recognize and handle function names introduced by "extern" inside a
function.
* cc-engine.el (c-forward-decl-or-cast-1): Add a new element to the result
list which is t when our declaration is, or is to be treated as, being at top
level.
* cc-fonts.el (c-get-fontification-context): Detect being inside a C++ uniform
initialization and return (not-decl nil) for this case.
(c-font-lock-declarations): Use the new element 4 of the result of
c-forward-decl-or-cast-1.
* cc-langs.el (c-make-top-level-kwds, c-make-top-level-key): New lang
consts/vars.
Affected #: 3 files
diff -r 73e4dec237e8ae7a2ce08cc9f788c141e90e13db -r
f317d82b1010097a2b092dd010c6d0ec5b45a85d cc-engine.el
--- a/cc-engine.el
+++ b/cc-engine.el
@@ -8178,9 +8178,9 @@
;; 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 ...
@@ -8219,7 +8219,9 @@
;;
;; 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:
;;
@@ -8317,6 +8319,9 @@
;; 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
@@ -8348,7 +8353,9 @@
(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
@@ -8618,7 +8625,7 @@
;; 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)
@@ -8666,7 +8673,7 @@
;; 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) ?\)))
@@ -8923,6 +8930,7 @@
(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
@@ -9089,7 +9097,7 @@
;; 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.
@@ -9194,7 +9202,8 @@
(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.
diff -r 73e4dec237e8ae7a2ce08cc9f788c141e90e13db -r
f317d82b1010097a2b092dd010c6d0ec5b45a85d cc-fonts.el
--- a/cc-fonts.el
+++ b/cc-fonts.el
@@ -1251,6 +1251,17 @@
;; 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
@@ -1589,7 +1600,8 @@
(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))))
diff -r 73e4dec237e8ae7a2ce08cc9f788c141e90e13db -r
f317d82b1010097a2b092dd010c6d0ec5b45a85d cc-langs.el
--- a/cc-langs.el
+++ b/cc-langs.el
@@ -2338,6 +2338,16 @@
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
Repository URL:
https://bitbucket.org/xemacs/cc-mode/
--
This is a commit notification from
bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.