Add fontification for a C declaration which looks like a function call.
For example, "t1 *fn (t2 *b);". * lisp/progmodes/cc-engine.el (c-forward-decl-or-cast-1): Add new variable at-decl-start, setting it to whether the putative decl starts immediately after ; or { or }. Accept such a construct as a decl when at-decl-start is non-nil. * lisp/progmodes/cc-langs.el (c-pre-start-tokens): New language variable.
This commit is contained in:
parent
438b98e5b7
commit
fda715c6cb
2 changed files with 29 additions and 6 deletions
|
@ -7152,6 +7152,9 @@ comment at the start of cc-engine.el for more info."
|
|||
cast-end
|
||||
;; Have we got a new-style C++11 "auto"?
|
||||
new-style-auto
|
||||
;; 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
|
||||
;; Save `c-record-type-identifiers' and
|
||||
;; `c-record-ref-identifiers' since ranges are recorded
|
||||
;; speculatively and should be thrown away if it turns out
|
||||
|
@ -7159,6 +7162,15 @@ comment at the start of cc-engine.el for more info."
|
|||
(save-rec-type-ids c-record-type-identifiers)
|
||||
(save-rec-ref-ids c-record-ref-identifiers))
|
||||
|
||||
(save-excursion
|
||||
(goto-char preceding-token-end)
|
||||
(setq at-decl-start
|
||||
(or (bobp)
|
||||
(let ((tok-end (point)))
|
||||
(c-backward-token-2)
|
||||
(member (buffer-substring-no-properties (point) tok-end)
|
||||
c-pre-start-tokens)))))
|
||||
|
||||
(while (c-forward-annotation)
|
||||
(c-forward-syntactic-ws))
|
||||
|
||||
|
@ -7771,12 +7783,15 @@ comment at the start of cc-engine.el for more info."
|
|||
at-type
|
||||
(or at-decl-end (looking-at "=[^=]"))
|
||||
(not context)
|
||||
(not got-suffix))
|
||||
;; Got something like "foo * bar;". Since we're not inside an
|
||||
;; arglist it would be a meaningless expression because the
|
||||
;; result isn't used. We therefore choose to recognize it as
|
||||
;; a declaration. Do not allow a suffix since it could then
|
||||
;; be a function call.
|
||||
(or (not got-suffix)
|
||||
at-decl-start))
|
||||
;; Got something like "foo * bar;". Since we're not inside
|
||||
;; an arglist it would be a meaningless expression because
|
||||
;; the result isn't used. We therefore choose to recognize
|
||||
;; it as a declaration. We only allow a suffix (which makes
|
||||
;; the construct look like a function call) when
|
||||
;; `at-decl-start' provides additional evidence that we do
|
||||
;; have a declaration.
|
||||
(throw 'at-decl-or-cast t))
|
||||
|
||||
;; CASE 17
|
||||
|
|
|
@ -1330,6 +1330,14 @@ operators."
|
|||
(c-lang-defconst c-haskell-op-re
|
||||
t (c-make-keywords-re nil (c-lang-const c-haskell-op)))
|
||||
(c-lang-defvar c-haskell-op-re (c-lang-const c-haskell-op-re))
|
||||
|
||||
(c-lang-defconst c-pre-start-tokens
|
||||
"List of operators following which an apparent declaration \(e.g.
|
||||
\"t1 *fn (t2 *b);\") is most likely to be an actual declaration
|
||||
\(as opposed to an arithmetic expression)."
|
||||
t '(";" "{" "}"))
|
||||
(c-lang-defvar c-pre-start-tokens (c-lang-const c-pre-start-tokens))
|
||||
|
||||
|
||||
;;; Syntactic whitespace.
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue