Function: c-font-lock-declarators

c-font-lock-declarators is a byte-compiled function defined in cc-fonts.el.gz.

Signature

(c-font-lock-declarators LIMIT LIST TYPES NOT-TOP &optional TEMPLATE-CLASS ACCEPT-ANON)

Source Code

;; Defined in /usr/src/emacs/lisp/progmodes/cc-fonts.el.gz
(defun c-font-lock-declarators (limit list types not-top
				      &optional template-class accept-anon)
  ;; Assuming the point is at the start of a declarator in a declaration,
  ;; fontify the identifier it declares.  (If TYPES is t, it does this via the
  ;; macro `c-fontify-types-and-refs'.)
  ;;
  ;; If LIST is non-nil, also fontify the ids in any following declarators in
  ;; a comma separated list (e.g.  "foo" and "*bar" in "int foo = 17, *bar;");
  ;; additionally, mark the commas with c-type property 'c-decl-id-start or
  ;; 'c-decl-type-start (according to TYPES).  Stop at LIMIT.
  ;;
  ;; If TYPES is t, fontify all identifiers as types; if it is a number, a
  ;; buffer position, additionally set the `c-typedef' text property on the
  ;; keyword at that position; if it is nil fontify as either variables or
  ;; functions, otherwise TYPES is a face to use.  If NOT-TOP is non-nil, we
  ;; are not at the top-level ("top-level" includes being directly inside a
  ;; class or namespace, etc.).
  ;;
  ;; TEMPLATE-CLASS is non-nil when the declaration is in template delimiters
  ;; and was introduced by, e.g. "typename" or "class", such that if there is
  ;; a default (introduced by "="), it will be fontified as a type.
  ;; E.g. "<class X = Y>".
  ;;
  ;; ACCEPT-ANON is non-nil when we accept anonymous declarators.
  ;;
  ;; Nil is always returned.  The function leaves point at the delimiter after
  ;; the last declarator it processes.
  ;;
  ;; This function might do hidden buffer changes.

  ;;(message "c-font-lock-declarators from %s to %s" (point) limit)
  (c-fontify-types-and-refs
      ()
    ;; If we're altering the declarators in a typedef, we need to scan ALL of
    ;; them because of the way we check for changes.
    (let ((c-do-decl-limit (if (numberp types) (point-max) limit))
	  decl-ids)
    (c-do-declarators
     c-do-decl-limit
     list not-top
     (cond ((or (numberp types)
		(eq types t))
	    'c-decl-type-start)
	   ((null types) 'c-decl-id-start))
     (lambda (id-start id-end end-pos _not-top is-function init-char)
       (if (or (numberp types)
	       (eq types t))
	   (when id-start
	     ;; Register and fontify the identifier as a type.
	     (let ((c-promote-possible-types t))
	       (goto-char id-start)
	       (c-forward-type))
	     (when (numberp types)
	       (push (buffer-substring-no-properties id-start id-end)
		     decl-ids)))
	 (when id-start
	   (goto-char id-start)
	   (when c-opt-identifier-prefix-key
	     (unless (and (looking-at c-opt-identifier-prefix-key) ; For operator~
			  (eq (match-end 1) id-end))
	       (while (and (< (point) id-end)
			   (re-search-forward c-opt-identifier-prefix-key id-end t))
		 (c-forward-syntactic-ws c-do-decl-limit))))
	   ;; Only apply the face when the text doesn't have one yet.
	   ;; Exception: The "" in C++'s operator"" will already wrongly have
	   ;; string face.
	   (when (memq (get-text-property (point) 'face)
		       '(nil font-lock-string-face))
	     (c-put-font-lock-face (point) id-end
				   (cond
				    ((not (memq types '(nil t))) types)
				    (is-function 'font-lock-function-name-face)
				    (t 'font-lock-variable-name-face))))
	   ;; Fontify any _tag in C++'s operator"" _tag.
	   (when (and
		  (c-major-mode-is 'c++-mode)
		  (equal (buffer-substring-no-properties id-start id-end)
			 "\"\""))
	     (goto-char id-end)
	     (c-forward-syntactic-ws c-do-decl-limit)
	     (when (c-on-identifier)
	       (c-put-font-lock-face
		(point)
		(progn (c-forward-over-token) (point))
		font-lock-function-name-face)))))
       (and template-class
	    (eq init-char ?=)		; C++ "<class X = Y>"?
	    (progn
	      (goto-char end-pos)
	      (c-forward-token-2 1 nil c-do-decl-limit) ; Over "="
	      (let ((c-promote-possible-types t))
		(c-forward-type t)))))
     accept-anon)			; Last argument to c-do-declarators.
    ;; If we've changed types declared by a "typedef", update the `c-typedef'
    ;; text property.
    (when (numberp types)
      (let* ((old-decl-ids (c-get-char-property types 'c-typedef))
	     (old-types (c--set-difference old-decl-ids decl-ids :test #'equal))
	     (new-types (c--set-difference decl-ids old-decl-ids :test #'equal)))
	(dolist (type old-types)
	  (c-unfind-type type))
	;; The new types have already been added to `c-found-types', as needed.
	(when (or old-types new-types)
	  (c-put-char-property types 'c-typedef decl-ids)))))
    nil))