bug#61144: CC Mode 5.35.2 (C/*l); Incorrect fontification (but different from last time)
Po Lu via CC-Mode-help <[email protected]> Tue, 31 Jan 2023 09:23:01 +0800
| Newsgroups | gmane.emacs.cc-mode.general |
|---|---|
| Message-ID | <[email protected]> |
Alan Mackenzie <[email protected]> writes: > Hello, Po. > > On Sun, Jan 29, 2023 at 19:00:47 +0800, Po Lu via CC-Mode-help wrote: >> Package: cc-mode > >> Emacs : GNU Emacs 30.0.50 (build 41, x86_64-pc-linux-gnu) >> of 2023-01-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) > >> Insert the following text in a C Mode buffer: > >> static sfnt_f26dot6 >> sfnt_mul_f26dot6 (sfnt_f26dot6 a, sfnt_f26dot6 b) >> { >> #ifdef INT64_MAX >> return (sfnt_f26dot6) ((int64_t) a * b + (1 << 5) >> 6); >> #else >> int negative; >> unsigned short al, bl, ah, bh; >> unsigned int lowlong, midlong, hilong; > >> negative = 0; > >> /* Compensate for complement and determine if the result will be >> negative. */ > >> if (a < 0) >> { >> a = -a; >> negative = 1; >> } > >> if (b < 0) >> { >> b = -b; >> negative ^= true; >> } > >> /* Load low and high words from A and B. */ >> al = a & 0xffff; >> bl = b & 0xffff; >> ah = a >> 16; >> bh = b >> 16; > >> /* Multiply the various bits separately. */ >> midlong = (unsigned int) al * bh; >> #endif >> } > >> In ``al * bh'', al is fontified as a type, and bh an identifier. > > Yes. foo * bar is a difficult case, since it can either be a > multiplication or a declaration of bar as a pointer to foo. There is no > reliable way to distinguish these two cases without a full parser. No > doubt c-ts-mode will do better here. > > In another similar case, I have disambiguated these with "whitespace > asymmetry" - If there's WS both before and after the "*" or neither, > it's treated as a multiplication. Otherwise it's a declaration. > > I've extended this heuristic to treat the case in your test file. Would > you try out the attached patch, please (it applies cleanly to the master > branch). I would be in favour of putting the patch into the release > branch, but given the patch is ~90 lines long, Eli might object. > > Anyhow, please try it out, and let me know what you think about it. > Thanks! > > [ .... ] Thank you, this works here.