From: Alan Mackenzie <acm@muc.de>
Date: Mon, 25 Apr 2016 15:19:58 +0000 (+0000)
Subject: Add fontification for a C declaration which looks like a function call.
X-Git-Tag: emacs-26.0.90~2154
X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=fda715c6cb576502c987e599964b715687b05b15;p=emacs.git

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.
---

diff --git a/lisp/progmodes/cc-engine.el b/lisp/progmodes/cc-engine.el
index 4aff0dc14e0..c38a3a3b100 100644
--- a/lisp/progmodes/cc-engine.el
+++ b/lisp/progmodes/cc-engine.el
@@ -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
diff --git a/lisp/progmodes/cc-langs.el b/lisp/progmodes/cc-langs.el
index 6489199504b..94005be9075 100644
--- a/lisp/progmodes/cc-langs.el
+++ b/lisp/progmodes/cc-langs.el
@@ -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.