Function: c-font-lock-c++-new
c-font-lock-c++-new is a byte-compiled function defined in
cc-fonts.el.gz.
Signature
(c-font-lock-c++-new LIMIT)
Source Code
;; Defined in /usr/src/emacs/lisp/progmodes/cc-fonts.el.gz
(defun c-font-lock-c++-new (limit)
;; FIXME!!! Put in a comment about the context of this function's
;; invocation. I think it's called as an ANCHORED-MATCHER within an
;; ANCHORED-HIGHLIGHTER. (2007/2/10).
;;
;; Assuming point is after a "new" word, check that it isn't inside
;; a string or comment, and if so try to fontify the type in the
;; allocation expression. Nil is always returned.
;;
;; As usual, C++ takes the prize in coming up with a hard to parse
;; syntax. :P
;;
;; This function might do hidden buffer changes.
(unless (c-skip-comments-and-strings limit)
(save-excursion
(catch 'false-alarm
;; A "new" keyword is followed by one to three expressions, where
;; the type is the middle one, and the only required part.
(let (expr1-pos expr2-pos
;; Enable recording of identifier ranges in `c-forward-type'
;; etc for later fontification. Not using
;; `c-fontify-types-and-refs' here since the ranges should
;; be fontified selectively only when an allocation
;; expression is successfully recognized.
(c-record-type-identifiers t)
c-record-ref-identifiers
;; The font-lock package in Emacs is known to clobber
;; `parse-sexp-lookup-properties' (when it exists).
(parse-sexp-lookup-properties
(cc-eval-when-compile
(boundp 'parse-sexp-lookup-properties))))
(c-forward-syntactic-ws)
;; The first placement arglist is always parenthesized, if it
;; exists.
(when (eq (char-after) ?\()
(setq expr1-pos (1+ (point)))
(condition-case nil
(c-forward-sexp)
(scan-error (throw 'false-alarm t)))
(c-forward-syntactic-ws))
;; The second expression is either a type followed by some "*" or
;; "[...]" or similar, or a parenthesized type followed by a full
;; identifierless declarator.
(setq expr2-pos (1+ (point)))
(cond ((eq (char-after) ?\())
((let ((c-promote-possible-types t))
(c-forward-type)))
(t (setq expr2-pos nil)))
(when expr1-pos
(cond
((not expr2-pos)
;; No second expression, so the first has to be a
;; parenthesized type.
(goto-char expr1-pos)
(let ((c-promote-possible-types t))
(c-forward-type)))
((eq (char-before expr2-pos) ?\()
;; Got two parenthesized expressions, so we have to look
;; closer at them to decide which is the type. No need to
;; handle `c-record-ref-identifiers' since all references
;; have already been handled by other fontification rules.
(let (expr1-res expr2-res)
(goto-char expr1-pos)
(when (setq expr1-res (c-forward-type))
(unless (looking-at
(cc-eval-when-compile
(concat (c-lang-const c-symbol-start c++)
"\\|[*:)[]")))
;; There's something after the would-be type that
;; can't be there, so this is a placement arglist.
(setq expr1-res nil)))
(goto-char expr2-pos)
(when (setq expr2-res (c-forward-type))
(unless (looking-at
(cc-eval-when-compile
(concat (c-lang-const c-symbol-start c++)
"\\|[*:)[]")))
;; There's something after the would-be type that can't
;; be there, so this is an initialization expression.
(setq expr2-res nil))
(when (and (c-go-up-list-forward)
(progn (c-forward-syntactic-ws)
(eq (char-after) ?\()))
;; If there's a third initialization expression
;; then the second one is the type, so demote the
;; first match.
(setq expr1-res nil)))
;; We fontify the most likely type, with a preference for
;; the first argument since a placement arglist is more
;; unusual than an initializer.
(cond ((memq expr1-res '(t known prefix)))
((memq expr2-res '(t known prefix)))
;; Presumably 'decltype's will be fontified elsewhere.
((eq expr1-res 'decltype))
((eq expr2-res 'decltype))
((eq expr1-res 'found)
(let ((c-promote-possible-types t))
(goto-char expr1-pos)
(c-forward-type)))
((eq expr2-res 'found)
(let ((c-promote-possible-types t))
(goto-char expr2-pos)
(c-forward-type)))
((and (eq expr1-res 'maybe) (not expr2-res))
(let ((c-promote-possible-types t))
(goto-char expr1-pos)
(c-forward-type)))
((and (not expr1-res) (eq expr2-res 'maybe))
(let ((c-promote-possible-types t))
(goto-char expr2-pos)
(c-forward-type)))
;; If both type matches are 'maybe then we're
;; too uncertain to promote either of them.
)))))
;; Fontify the type that now is recorded in
;; `c-record-type-identifiers', if any.
(c-fontify-recorded-types-and-refs)))))
nil)