Subject: bug#63322: CC Mode 5.35.2 (C/*l); Various problems fontifying sfnt.c

From: Alan Mackenzie <[email-masked]>
Date: Wed, 10 May 2023 10:55:29 +0000

Hello, Po.

Thanks for the bug report.

On Sat, May 06, 2023 at 16:11:25 +0800, Po Lu via CC-Mode-help wrote:
> Package: cc-mode

> Go to src/sfnt.c in the feature/android branch of Emacs.
> Type M-s o ^sfnt RET, then visit each of the following function
> definitions:

> sfnt_scale_by_freedom_vector
> sfnt_interpret_iup_1
> sfnt_interpret_font_program
> sfnt_interpret_control_value_program
> sfnt_interpret_simple_glyph
> sfnt_interpret_compound_glyph

> In each of these definitions, the identifier name is not fontified as a
> function!

Yes.  There were actually two distinct problems here, one trivial to
solve and the other difficult.

For most of these function names, you just need to add the macro name
"TEST_STATIC" to c-noise-macro-names, as is done in .dir-locals for some
other names, and is explained fully in the chapter "Noise Macros" in the
CC Mode manual.

For the other two function names, the problem was that they followed a
large chunk of CPP macros, bigger than a search limit for one of CC
Mode's backward searches.  The fix was to check for this possibility and
handle it.

Would you please do the usual with the enclosed patch (which should
apply cleanly to both the emacs-29 branch and master), and let me know
how well it works.  Thanks!

> Emacs  : GNU Emacs 29.0.90 (build 1, x86_64-pc-linux-gnu)
>  of 2023-04-29
> Package: CC Mode 5.35.2 (C/*l)
> Buffer Style: GNU
> c-emacs-features: (pps-extended-state col-0-paren posix-char-classes gen-string-delim gen-comment-delim syntax-properties category-properties 1-bit)

-- 
Alan Mackenzie (Nuremberg, Germany).

diff -r 3d663572d4bf cc-engine.el
--- a/cc-engine.el	Wed May 03 09:45:37 2023 +0000
+++ b/cc-engine.el	Wed May 10 10:37:06 2023 +0000
@@ -6263,6 +6263,9 @@
   ;; prefix".  The declaration prefix is the earlier of `cfd-prop-match' and
   ;; `cfd-re-match'.  `cfd-match-pos' is set to the decl prefix.
   ;;
+  ;; The variables which this macro should set for `c-find-decl-spots' are
+  ;; `cfd-match-pos' and `cfd-continue-pos'.
+  ;;
   ;; This macro might do hidden buffer changes.
 
   '(progn
@@ -6615,11 +6618,17 @@
 	;; and so we can continue the search from this point.  If we
 	;; didn't hit `c-find-decl-syntactic-pos' then we're now in
 	;; the right spot to begin searching anyway.
-	(if (and (eq (point) c-find-decl-syntactic-pos)
-		 c-find-decl-match-pos)
-	    (setq cfd-match-pos c-find-decl-match-pos
-		  cfd-continue-pos syntactic-pos)
-
+	(cond
+	 ((and (eq (point) c-find-decl-syntactic-pos)
+	       c-find-decl-match-pos)
+	  (setq cfd-match-pos c-find-decl-match-pos
+		cfd-continue-pos syntactic-pos))
+	 ((save-excursion (c-beginning-of-macro))
+	  ;; The `c-backward-syntactic-ws' ~40 lines up failed to find non
+	  ;; syntactic-ws and hit its limit, leaving us in a macro.
+	  (setq cfd-match-pos cfd-start-pos
+		cfd-continue-pos cfd-start-pos))
+	 (t
 	  (setq c-find-decl-syntactic-pos syntactic-pos)
 
 	  (when (if (bobp)
@@ -6637,7 +6646,7 @@
 	    (c-find-decl-prefix-search)) ; sets cfd-continue-pos
 
 	  (setq c-find-decl-match-pos (and (< cfd-match-pos cfd-start-pos)
-					   cfd-match-pos))))) ; end of `cond'
+					   cfd-match-pos)))))) ; end of `cond'
 
       ;; Advance `cfd-continue-pos' if it's before the start position.
       ;; The closest continue position that might have effect at or
diff -r 3d663572d4bf cc-mode.el
--- a/cc-mode.el	Wed May 03 09:45:37 2023 +0000
+++ b/cc-mode.el	Wed May 10 10:37:06 2023 +0000
@@ -2425,8 +2425,6 @@
 			   (setq pseudo (c-cheap-inside-bracelist-p (c-parse-state)))))))
 	       (goto-char pseudo))
 	     t)
-	   (or (> (point) bod-lim)
-	       (eq bod-lim (point-min)))
 	   ;; Move forward to the start of the next declaration.
 	   (progn (c-forward-syntactic-ws)
 		  ;; Have we got stuck in a comment at EOB?