1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2025-12-15 10:30:25 -08:00

CC Mode: Fontify cast types without adding them to c-found-types

* lisp/progmodes/cc-engine.el (c-forward-type): Test for the special new
value `just-one' of c-promote-possible-types, and if found, fontify the type,
but don't add it to c-found-types.
(c-forward-decl-or-cast-1): Add the new &optional parameter inside-macro.
Whilst checking for a cast construct, analyze the text following the closing
paren more rigorously.
Check for, and allow, the closing paren of a macro arglist before the putative
cast construct.

* lisp/progmodes/cc-fonts.el (c-font-lock-declarations): In the lambda
function, pass the parameter inside-macro to c-forward-decl-or-cast-1.

* lisp/progmodes/cc-langs.el (c-primary-expr-regexp-details): New
c-lang-defvar which calculates `c-primary-expr-regexp' and three match
numbers for various sub-expressions in the regexp.
(c-primary-expr-regexp): Now extracted from `c-primary-expr-regexp-details'.
(c-per-++---match, c-per-&*+--match, c-per-\(-match): New
c-lang-defconsts/vars extracted from `c-primary-expr-regexp-details'.
This commit is contained in:
Alan Mackenzie 2022-10-28 17:50:33 +00:00
parent d79cdcd4ff
commit 622724e95d
3 changed files with 209 additions and 78 deletions

View file

@ -3489,6 +3489,150 @@ Note that Java specific rules are currently applied to tell this from
(c-lang-defvar c-regular-keywords-regexp
(c-lang-const c-regular-keywords-regexp))
(c-lang-defconst c-primary-expr-regexp-details
;; A list of c-primary-expr-regexp and three numbers identifying particular
;; matches in it.
t (let* ((prefix-ops
;All prefix ops
(c-filter-ops (c-lang-const c-operators)
'(prefix)
(lambda (op)
;; Filter out the special case prefix
;; operators that are close parens.
(not (string-match "\\s)" op)))))
(postfix-ops
;; All postfix ops.
(c-filter-ops (c-lang-const c-operators)
'(postfix)
(lambda (op) (not (string-match "\\s)" op)))))
(in-or-postfix-ops
;; All ops which are postfix, etc.
(c-filter-ops (c-lang-const c-operators)
'(postfix
postfix-if-paren
left-assoc
right-assoc
right-assoc-sequence)
t))
(nonkeyword-prefix-ops
;; All prefix ops apart from those which are keywords.
(c-filter-ops prefix-ops
t
"\\`\\(\\s.\\|\\s(\\|\\s)\\)+\\'"))
(nonkeyword-postfix-ops
;; All postfix ops apart from those which are keywords.
(c-filter-ops postfix-ops
t
"\\`\\(\\s.\\|\\s(\\|\\s)\\)+\\'"))
(cast-ops
;; All prefix ops which have syntax open-paren.
(c-filter-ops prefix-ops
t
"\\`\\s(\\'"))
(ambiguous-pre/postfix-ops
;; All non-keyword ops which are both prefix and postfix, apart
;; from (.
(c--set-difference (c--intersection nonkeyword-prefix-ops
nonkeyword-postfix-ops
:test 'string-equal)
cast-ops :test 'string-equal))
(unambiguous-prefix-ops
;; All non-keyword ops which are prefix ops and not any other type
;; of op.
(c--set-difference nonkeyword-prefix-ops
in-or-postfix-ops
:test 'string-equal))
(ambiguous-prefix-ops
;; All non-keyword ops which are prefix ops and also some other
;; type of op.
(c--intersection nonkeyword-prefix-ops
in-or-postfix-ops
:test 'string-equal)) ; This has everything we
; need, plus (, ++, --.
(ambiguous-prefix-non-postfix-ops
;; All non-keyword prefix ops which are also other types of ops
;; apart from postfix ops.
(c--set-difference (c--set-difference ambiguous-prefix-ops
ambiguous-pre/postfix-ops
:test 'string-equal)
cast-ops :test 'string-equal))
(primary-expression-keywords-string
;; Take out all symbol class operators from `prefix-ops' and make
;; the first submatch from them together with
;; `c-primary-expr-kwds'.
(c-make-keywords-re t
(append (c-lang-const c-primary-expr-kwds)
(c--set-difference prefix-ops nonkeyword-prefix-ops
:test 'string-equal))))
(primary-expression-keywords-string-depth
(regexp-opt-depth primary-expression-keywords-string))
(ambiguous-pre/postfix-string
(c-make-keywords-re nil ambiguous-pre/postfix-ops))
(ambiguous-pre/postfix-string-depth
(regexp-opt-depth ambiguous-pre/postfix-string))
(ambiguous-prefix-non-postfix-string
(c-make-keywords-re nil ambiguous-prefix-non-postfix-ops))
(ambiguous-prefix-non-postfix-string-depth
(regexp-opt-depth ambiguous-prefix-non-postfix-string))
(per-++---match (+ 2 primary-expression-keywords-string-depth))
(per-&*+--match (+ 1 per-++---match
ambiguous-pre/postfix-string-depth))
(per-\(-match (+ 1 per-&*+--match
ambiguous-prefix-non-postfix-string-depth)))
(list
(concat
"\\(" ; 1
primary-expression-keywords-string
"\\|"
;; Match all ambiguous operators.
"\\(" ; 2 + primary-expression-keywords-string-depth
ambiguous-pre/postfix-string
"\\)\\|\\(" ; 3 + primary-expression-keywords-string-depth
; + ambiguous-pre/postfix-string-depth
ambiguous-prefix-non-postfix-string
"\\)\\|"
"\\((\\)" ; 4 + primary-expression-keywords-string-depth
; + ambiguous-pre/postfix-string-depth
; + ambiguous-prefix-non-postfix-string-depth
"\\)"
"\\|"
;; Now match all other symbols.
(c-lang-const c-symbol-start)
"\\|"
;; The chars that can start integer and floating point
;; constants.
"\\.?[0-9]"
"\\|"
;; The unambiguous operators from `prefix-ops'.
(c-make-keywords-re nil
;; (c--set-difference nonkeyword-prefix-ops in-or-postfix-ops
;; :test 'string-equal)
unambiguous-prefix-ops
)
"\\|"
;; Match string and character literals.
"\\s\""
(if (memq 'gen-string-delim c-emacs-features)
"\\|\\s|"
""))
per-++---match
per-&*+--match
per-\(-match)))
(c-lang-defconst c-primary-expr-regexp
;; Regexp matching the start of any primary expression, i.e. any
;; literal, symbol, prefix operator, and '('. It doesn't need to
@ -3497,68 +3641,27 @@ Note that Java specific rules are currently applied to tell this from
;; matches then it is an ambiguous primary expression; it could also
;; be a match of e.g. an infix operator. (The case with ambiguous
;; keyword operators isn't handled.)
t (let* ((prefix-ops
(c-filter-ops (c-lang-const c-operators)
'(prefix)
(lambda (op)
;; Filter out the special case prefix
;; operators that are close parens.
(not (string-match "\\s)" op)))))
(nonkeyword-prefix-ops
(c-filter-ops prefix-ops
t
"\\`\\(\\s.\\|\\s(\\|\\s)\\)+\\'"))
(in-or-postfix-ops
(c-filter-ops (c-lang-const c-operators)
'(postfix
postfix-if-paren
left-assoc
right-assoc
right-assoc-sequence)
t)))
(concat
"\\("
;; Take out all symbol class operators from `prefix-ops' and make the
;; first submatch from them together with `c-primary-expr-kwds'.
(c-make-keywords-re t
(append (c-lang-const c-primary-expr-kwds)
(c--set-difference prefix-ops nonkeyword-prefix-ops
:test 'string-equal)))
"\\|"
;; Match all ambiguous operators.
(c-make-keywords-re nil
(c--intersection nonkeyword-prefix-ops in-or-postfix-ops
:test 'string-equal))
"\\)"
"\\|"
;; Now match all other symbols.
(c-lang-const c-symbol-start)
"\\|"
;; The chars that can start integer and floating point
;; constants.
"\\.?[0-9]"
"\\|"
;; The unambiguous operators from `prefix-ops'.
(c-make-keywords-re nil
(c--set-difference nonkeyword-prefix-ops in-or-postfix-ops
:test 'string-equal))
"\\|"
;; Match string and character literals.
"\\s\""
(if (memq 'gen-string-delim c-emacs-features)
"\\|\\s|"
""))))
t (car (c-lang-const c-primary-expr-regexp-details)))
(c-lang-defvar c-primary-expr-regexp (c-lang-const c-primary-expr-regexp))
(c-lang-defconst c-per-++---match
;; Match number for group in `c-primary-expr-regexp' which matches (in C)
;; the ++ and -- operators, and any similar ones in other languages.
t (cadr (c-lang-const c-primary-expr-regexp-details)))
(c-lang-defvar c-per-++---match (c-lang-const c-per-++---match))
(c-lang-defconst c-per-&*+--match
;; Match number for group in `c-primary-expr-regexp' which matches (in C)
;; the &, *, +, and - operators, and any similar ones in other languages.
t (car (cddr (c-lang-const c-primary-expr-regexp-details))))
(c-lang-defvar c-per-&*+--match (c-lang-const c-per-&*+--match))
(c-lang-defconst c-per-\(-match
;; Match number for group in `c-primary-expr-regexp' which matches (in C)
;; the ( operator, and any similar ones in other languages.
t (cadr (cddr (c-lang-const c-primary-expr-regexp-details))))
(c-lang-defvar c-per-\(-match (c-lang-const c-per-\(-match))
;;; Additional constants for parser-level constructs.