Function: c-update-brace-stack
c-update-brace-stack is a byte-compiled function defined in
cc-engine.el.gz.
Signature
(c-update-brace-stack STACK FROM TO)
Source Code
;; Defined in /usr/src/emacs/lisp/progmodes/cc-engine.el.gz
(defvar c-parse-and-markup-<>-arglists) ;FIXME: Move definition here?
(defun c-update-brace-stack (stack from to)
;; Given a brace-stack which has the value STACK at position FROM, update it
;; to its value at position TO, where TO is after (or equal to) FROM.
;; Return a cons of either TO (if it is outside a literal) and this new
;; value, or of the next position after TO outside a literal and the new
;; value.
(let (match kwd-sym (prev-match-pos 1)
(s (cdr stack))
(bound-<> (car stack)))
(save-excursion
(cond
((and bound-<> (<= to bound-<>))
(goto-char to)) ; Nothing to do.
(bound-<>
(goto-char bound-<>)
(setq bound-<> nil))
(t (goto-char from)))
(while (and (< (point) to)
(c-syntactic-re-search-forward
(if (<= (car s) 0)
c-brace-stack-thing-key
c-brace-stack-no-semi-key)
to 'after-literal)
(> (point) prev-match-pos)) ; prevent infinite loop.
(setq prev-match-pos (point))
(setq match (match-string-no-properties 1)
kwd-sym (c-keyword-sym match))
(cond
((and (equal match "{")
(progn (backward-char)
(prog1 (looking-at "\\s(")
(forward-char))))
(setq s (if s
(cons (if (<= (car s) 0)
1
(1+ (car s)))
(cdr s))
(list 1))))
((and (equal match "}")
(progn (backward-char)
(prog1 (looking-at "\\s)")
(forward-char))))
(setq s
(cond
((and s (> (car s) 1))
(cons (1- (car s)) (cdr s)))
((and (cdr s) (eq (car s) 1))
(cdr s))
(t s))))
((and (equal match "<")
(progn (backward-char)
(prog1 (looking-at "\\s(")
(forward-char))))
(backward-char)
(if (let ((c-parse-and-markup-<>-arglists t)
c-restricted-<>-arglists)
(c-forward-<>-arglist nil)) ; Should always work.
(when (> (point) to)
(setq bound-<> (point)))
(forward-char)))
((and (equal match ":")
s
(eq (car s) 0))
(setq s (cons -1 (cdr s))))
((and (equal match ",")
(eq (car s) -1))) ; at "," in "class foo : bar, ..."
((member match '(";" "*" "," ")"))
(when (and s (cdr s) (<= (car s) 0))
(setq s (cdr s))))
((c-keyword-member kwd-sym 'c-flat-decl-block-kwds)
(push 0 s))))
(when (> prev-match-pos 1) ; Has the search matched at least once?
;; The failing `c-syntactic-re-search-forward' may have left us in the
;; middle of a token, which might be a significant token. Fix this!
(c-beginning-of-current-token))
(cons (point)
(cons bound-<> s)))))