Function: c-font-lock-single-decl

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

Signature

(c-font-lock-single-decl LIMIT DECL-OR-CAST MATCH-POS CONTEXT TOPLEV)

Source Code

;; Defined in /usr/src/emacs/lisp/progmodes/cc-fonts.el.gz
(defun c-font-lock-single-decl (limit decl-or-cast match-pos context toplev)
  ;; Try to fontify a single declaration, together with all its declarators.
  ;; Return nil if we're successful, non-nil if we fail.  POINT should be
  ;; positioned at the start of the putative declaration before calling.
  ;; POINT is left undefined by this function.
  ;;
  ;; LIMIT sets a maximum position we'll fontify out to.
  ;; DECL-OR-CAST has the form of a result from `c-forward-decl-or-cast-1',
  ;;   and must indicate a declaration (i.e. not be nil or 'cast).
  ;; MATCH-POS is the position after the last symbol before the decl.
  ;; CONTEXT is the context of the current decl., as determined by
  ;;   c-get-fontification-context.
  ;; TOPLEV is non-nil if the decl. is at the top level (i.e. outside any
  ;;   braces, or directly inside a class, namespace, etc.)

  ;; Do we have an expression as the second or third clause of
  ;; a "for" paren expression?
  (if (save-excursion
	(and
	 (car (cddr decl-or-cast))	; maybe-expression flag.
	 (c-go-up-list-backward nil (c-determine-limit 500))
	 (eq (char-after) ?\()
	 (progn (c-backward-syntactic-ws)
		(c-simple-skip-symbol-backward))
	 (looking-at c-paren-stmt-key)
	 (progn (goto-char match-pos)
		(while (and (eq (char-before) ?\))
			    (c-go-list-backward))
		  (c-backward-syntactic-ws))
		(eq (char-before) ?\;))))
      ;; We've got an expression in "for" parens.  Remove the
      ;; "type" that would spuriously get fontified.
      (let ((elt (and (consp c-record-type-identifiers)
		      (assq (cadr (cddr decl-or-cast))
			    c-record-type-identifiers))))
	(when elt
	  (setq c-record-type-identifiers
		(c-delq-from-dotted-list
		 elt c-record-type-identifiers)))
	t)
    ;; Back up to the type to fontify the declarator(s).
    (goto-char (car decl-or-cast))

    (let ((decl-list
	   (if (not (memq context '(nil top)))
	       ;; Should normally not fontify a list of
	       ;; declarators inside an arglist, but the first
	       ;; argument in the ';' separated list of a "for"
	       ;; statement is an exception.
	       (when (eq (char-before match-pos) ?\()
		 (save-excursion
		   (goto-char (1- match-pos))
		   (c-backward-syntactic-ws)
		   (and (c-simple-skip-symbol-backward)
			(looking-at c-paren-stmt-key))))
	     t))
	  (template-class (and (eq context '<>)
			       (save-excursion
				 (goto-char match-pos)
				 (c-forward-syntactic-ws)
				 (looking-at c-template-typename-key)))))
      ;; Fix the `c-decl-id-start' or `c-decl-type-start' property
      ;; before the first declarator if it's a list.
      ;; `c-font-lock-declarators' handles the rest.
      (when decl-list
	(save-excursion
	  (c-backward-syntactic-ws)
	  (unless (bobp)
	    (c-put-char-property (1- (point)) 'c-type
				 (if (cadr decl-or-cast)
				     'c-decl-type-start
				   'c-decl-id-start)))))
      (c-font-lock-declarators
       (min limit (point-max)) decl-list
       (not (null (cadr decl-or-cast)))
       (not toplev) template-class))

    ;; A declaration has been successfully identified, so do all the
    ;; fontification of types and refs that've been recorded.
    (c-fontify-recorded-types-and-refs)
    nil))