Commit 1ada2209 authored by Alan Mackenzie's avatar Alan Mackenzie
Browse files

CC Mode: Handle several K&R parameters per declaration

* cc-engine.el (c-in-knr-argdecl): Reformulate the latter part of this
function using c-do-declarators.

* knr-7.{c,res}: New test files.
parent f0a6bea52628
......@@ -10849,11 +10849,11 @@ comment at the start of cc-engine.el for more info."
(low-lim (max (or lim (point-min)) (or macro-start (point-min))))
before-lparen after-rparen
(here (point))
(pp-count-out 20) ; Max number of paren/brace constructs before
; we give up
ids ; List of identifiers in the parenthesised list.
(pp-count-out 20) ; Max number of paren/brace constructs before
; we give up.
ids ; List of identifiers in the parenthesized list.
id-start after-prec-token decl-or-cast decl-res
c-last-identifier-range identifier-ok)
c-last-identifier-range semi-position+1)
(narrow-to-region low-lim (or macro-end (point-max)))
 
;; Search backwards for the defun's argument list. We give up if we
......@@ -10887,8 +10887,8 @@ comment at the start of cc-engine.el for more info."
(setq after-rparen (point)))
((eq (char-before) ?\])
(setq after-rparen nil))
(t ; either } (hit previous defun) or = or no more
; parens/brackets.
(t ; either } (hit previous defun) or = or no more
; parens/brackets.
(throw 'knr nil)))
 
(if after-rparen
......@@ -10945,31 +10945,35 @@ comment at the start of cc-engine.el for more info."
(forward-char) ; over the )
(setq after-prec-token after-rparen)
(c-forward-syntactic-ws)
;; Each time around the following checks one
;; declaration (which may contain several identifiers).
(while (and
(or (consp (setq decl-or-cast
(c-forward-decl-or-cast-1
after-prec-token
nil ; Or 'arglist ???
nil)))
(progn
(goto-char after-prec-token)
(c-forward-syntactic-ws)
(setq identifier-ok (eq (char-after) ?{))
nil))
(eq (char-after) ?\;)
(setq after-prec-token (1+ (point)))
(consp (setq decl-or-cast
(c-forward-decl-or-cast-1
after-prec-token
nil ; Or 'arglist ???
nil)))
(memq (char-after) '(?\; ?\,))
(goto-char (car decl-or-cast))
(setq decl-res (c-forward-declarator))
(setq identifier-ok
(member (buffer-substring-no-properties
(car decl-res) (cadr decl-res))
ids))
(progn
(goto-char after-prec-token)
(prog1 (< (point) here)
(c-forward-syntactic-ws))))
(setq identifier-ok nil))
identifier-ok))
(save-excursion
(setq semi-position+1
(c-syntactic-re-search-forward
";" (+ (point) 1000) t)))
(c-do-declarators
semi-position+1 t nil nil
(lambda (id-start id-end _next _not-top
_func _init)
(if (not (member
(buffer-substring-no-properties
id-start id-end)
ids))
(throw 'knr nil))))
(progn (forward-char)
(<= (point) here))
(progn (c-forward-syntactic-ws)
t)))
t))
;; ...Yes. We've identified the function's argument list.
(throw 'knr
(progn (goto-char after-rparen)
......
int foo (i, j, k)
int i;
int j, k;
{
return i;
}
/* Check for mismatching params */
int foo (i, j, k)
int i;
int j, kk;
{
return i;
}
((topmost-intro <0,0>))
((knr-argdecl-intro <1,0>))
((knr-argdecl <1,4>))
((defun-open <3,0>))
((defun-block-intro <1,0>))
((defun-close <2,0>))
((topmost-intro <1,0>) (comment-intro))
((topmost-intro <2,0>))
((knr-argdecl-intro <1,0>))
((topmost-intro <1,0>))
((defun-open <1,0>))
((defun-block-intro <1,0>))
((defun-close <2,0>))
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment