]> code.delx.au - gnu-emacs/commitdiff
Add fontification for a C declaration which looks like a function call.
authorAlan Mackenzie <acm@muc.de>
Mon, 25 Apr 2016 15:19:58 +0000 (15:19 +0000)
committerAlan Mackenzie <acm@muc.de>
Mon, 25 Apr 2016 15:19:58 +0000 (15:19 +0000)
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.

lisp/progmodes/cc-engine.el
lisp/progmodes/cc-langs.el

index 4aff0dc14e094dfa05715b2f18f0bee96527c4da..c38a3a3b100f8bbb8dfe872e7e47c8540911b56b 100644 (file)
@@ -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
index 6489199504bc4fc799ee937166b67121253ce871..94005be907520fef13ec60b0e24f45aa3daaa43c 100644 (file)
@@ -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))
+
 \f
 ;;; Syntactic whitespace.