comparison lisp/progmodes/cc-engine.el @ 83554:b8d9a391daf3

Merged from emacs@sv.gnu.org Patches applied: * emacs@sv.gnu.org/emacs--devo--0--patch-599 Merge from erc--main--0 * emacs@sv.gnu.org/emacs--devo--0--patch-600 Merge from erc--main--0 * emacs@sv.gnu.org/emacs--devo--0--patch-601 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-602 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-603 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-604 Merge from gnus--rel--5.10 * emacs@sv.gnu.org/emacs--devo--0--patch-605 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-606 Merge from gnus--rel--5.10 * emacs@sv.gnu.org/emacs--devo--0--patch-607 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-608 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-609 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-610 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-611 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-612 Merge from gnus--rel--5.10 * emacs@sv.gnu.org/emacs--devo--0--patch-613 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-614 Make byte compiler correctly write circular constants * emacs@sv.gnu.org/emacs--devo--0--patch-615 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-616 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-617 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-618 Update from CVS * emacs@sv.gnu.org/gnus--rel--5.10--patch-192 Merge from emacs--devo--0 * emacs@sv.gnu.org/gnus--rel--5.10--patch-193 Update from CVS * emacs@sv.gnu.org/gnus--rel--5.10--patch-194 Merge from emacs--devo--0 * emacs@sv.gnu.org/gnus--rel--5.10--patch-195 Update from CVS * emacs@sv.gnu.org/gnus--rel--5.10--patch-196 Update from CVS git-archimport-id: lorentey@elte.hu--2004/emacs--multi-tty--0--patch-594
author Karoly Lorentey <lorentey@elte.hu>
date Mon, 29 Jan 2007 22:21:19 +0000
parents e3694f1cb928
children 33cf1027eb42 95d0cdf160ea
comparison
equal deleted inserted replaced
83553:32073cbc5eb6 83554:b8d9a391daf3
1 ;;; cc-engine.el --- core syntax guessing engine for CC mode 1 ;;; cc-engine.el --- core syntax guessing engine for CC mode
2 2
3 ;; Copyright (C) 1985, 1987, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 3 ;; Copyright (C) 1985, 1987, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
4 ;; 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software 4 ;; 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007
5 ;; Foundation, Inc. 5 ;; Free Software Foundation, Inc.
6 6
7 ;; Authors: 1998- Martin Stjernholm 7 ;; Authors: 2001- Alan Mackenzie
8 ;; 1998- Martin Stjernholm
8 ;; 1992-1999 Barry A. Warsaw 9 ;; 1992-1999 Barry A. Warsaw
9 ;; 1987 Dave Detlefs and Stewart Clamen 10 ;; 1987 Dave Detlefs and Stewart Clamen
10 ;; 1985 Richard M. Stallman 11 ;; 1985 Richard M. Stallman
11 ;; Maintainer: bug-cc-mode@gnu.org 12 ;; Maintainer: bug-cc-mode@gnu.org
12 ;; Created: 22-Apr-1997 (split from cc-mode.el) 13 ;; Created: 22-Apr-1997 (split from cc-mode.el)
6218 ;; Return the position of the first argument declaration if point is 6219 ;; Return the position of the first argument declaration if point is
6219 ;; inside a K&R style argument declaration list, nil otherwise. 6220 ;; inside a K&R style argument declaration list, nil otherwise.
6220 ;; `c-recognize-knr-p' is not checked. If LIM is non-nil, it's a 6221 ;; `c-recognize-knr-p' is not checked. If LIM is non-nil, it's a
6221 ;; position that bounds the backward search for the argument list. 6222 ;; position that bounds the backward search for the argument list.
6222 ;; 6223 ;;
6223 ;; Note: A declaration level context is assumed; the test can return 6224 ;; Point must be within a possible K&R region, e.g. just before a top-level
6224 ;; false positives for statements. 6225 ;; "{". It must be outside of parens and brackets. The test can return
6226 ;; false positives otherwise.
6225 ;; 6227 ;;
6226 ;; This function might do hidden buffer changes. 6228 ;; This function might do hidden buffer changes.
6227 6229
6228 (save-excursion 6230 (save-excursion
6229 (save-restriction 6231 (save-restriction
6230 6232 ;; If we're in a macro, our search range is restricted to it. Narrow to
6231 ;; Go back to the closest preceding normal parenthesis sexp. We 6233 ;; the searchable range.
6232 ;; take that as the argument list in the function header. Then 6234 (let* ((macro-start (c-query-macro-start))
6233 ;; check that it's followed by some symbol before the next ';' 6235 (lim (max (or lim (point-min)) (or macro-start (point-min))))
6234 ;; or '{'. If it does, it's the header of the K&R argdecl we're 6236 before-lparen after-rparen)
6235 ;; in. 6237 (narrow-to-region lim (c-point 'eol))
6236 (if lim (narrow-to-region lim (c-point 'eol))) 6238
6237 (let ((outside-macro (not (c-query-macro-start))) 6239 ;; Search backwards for the defun's argument list. We give up if we
6238 paren-end) 6240 ;; encounter a "}" (end of a previous defun) or BOB.
6239 6241 ;;
6240 (catch 'done 6242 ;; The criterion for a paren structure being the arg list is:
6241 (while (if (and (setq paren-end (c-down-list-backward (point))) 6243 ;; o - there is non-WS stuff after it but before any "{"; AND
6242 (eq (char-after paren-end) ?\))) 6244 ;; o - the token after it isn't a ";" AND
6243 (progn 6245 ;; o - it is preceded by either an identifier (the function name) or
6244 (goto-char (1+ paren-end)) 6246 ;; a macro expansion like "DEFUN (...)"; AND
6245 (if outside-macro 6247 ;; o - its content is a non-empty comma-separated list of identifiers
6246 (c-beginning-of-macro))) 6248 ;; (an empty arg list won't have a knr region).
6247 (throw 'done nil)))) 6249 ;;
6248 6250 ;; The following snippet illustrates these rules:
6249 (and (progn 6251 ;; int foo (bar, baz, yuk)
6250 (c-forward-syntactic-ws) 6252 ;; int bar [] ;
6251 (looking-at "\\w\\|\\s_")) 6253 ;; int (*baz) (my_type) ;
6252 6254 ;; int (*) (void) (*yuk) (void) ;
6253 (save-excursion 6255 ;; {
6254 ;; The function header in a K&R declaration should only 6256
6255 ;; contain identifiers separated by comma. It should 6257 (catch 'knr
6256 ;; also contain at least one identifier since there 6258 (while t ; go round one paren/bracket construct each time round.
6257 ;; wouldn't be anything to declare in the K&R region 6259 (or (c-syntactic-skip-backward "^)]}")
6258 ;; otherwise. 6260 (throw 'knr nil)) ; no more bpb pairs left.
6259 (when (c-go-up-list-backward paren-end) 6261 (cond ((eq (char-before) ?\))
6260 (forward-char) 6262 (setq after-rparen (point)))
6261 (catch 'knr-ok 6263 ((eq (char-before) ?\})
6262 (while t 6264 (throw 'knr nil))
6263 (c-forward-syntactic-ws) 6265 (t (setq after-rparen nil))) ; "]"
6264 (if (or (looking-at c-known-type-key) 6266
6265 (looking-at c-keywords-regexp)) 6267 (if after-rparen
6266 (throw 'knr-ok nil)) 6268 ;; We're inside a paren. Could it be our argument list....?
6267 (c-forward-token-2) 6269 (if
6268 (if (eq (char-after) ?,) 6270 (and
6269 (forward-char) 6271 (progn
6270 (throw 'knr-ok (and (eq (char-after) ?\)) 6272 (goto-char after-rparen)
6271 (= (point) paren-end)))))))) 6273 (unless (c-go-list-backward) (throw 'knr nil)) ;
6272 6274 ;; FIXME!!! What about macros between the parens? 2007/01/20
6273 (save-excursion 6275 (setq before-lparen (point)))
6274 ;; If it's a K&R declaration then we're now at the 6276
6275 ;; beginning of the function arglist. Check that there 6277 ;; It can't be the arg list if next token is ; or {
6276 ;; isn't a '=' before it in this statement since that 6278 (progn (goto-char after-rparen)
6277 ;; means it some kind of initialization instead. 6279 (c-forward-syntactic-ws)
6278 (c-syntactic-skip-backward "^;=}{") 6280 (not (memq (char-after) '(?\; ?\{))))
6279 (not (eq (char-before) ?=))) 6281
6280 6282 ;; Is the thing preceding the list an identifier (the
6281 (point)))))) 6283 ;; function name), or a macro expansion?
6284 (progn
6285 (goto-char before-lparen)
6286 (eq (c-backward-token-2) 0)
6287 (or (c-on-identifier)
6288 (and (eq (char-after) ?\))
6289 (c-go-up-list-backward)
6290 (eq (c-backward-token-2) 0)
6291 (c-on-identifier))))
6292
6293 ;; Have we got a non-empty list of comma-separated
6294 ;; identifiers?
6295 (progn
6296 (goto-char before-lparen)
6297 (c-forward-token-2) ; to first token inside parens
6298 (and
6299 (c-on-identifier)
6300 (c-forward-token-2)
6301 (catch 'id-list
6302 (while (eq (char-after) ?\,)
6303 (c-forward-token-2)
6304 (unless (c-on-identifier) (throw 'id-list nil))
6305 (c-forward-token-2))
6306 (eq (char-after) ?\))))))
6307
6308 ;; ...Yes. We've identified the function's argument list.
6309 (throw 'knr
6310 (progn (goto-char after-rparen)
6311 (c-forward-syntactic-ws)
6312 (point)))
6313
6314 ;; ...No. The current parens aren't the function's arg list.
6315 (goto-char before-lparen))
6316
6317 (or (c-go-list-backward) ; backwards over [ .... ]
6318 (throw 'knr nil)))))))))
6282 6319
6283 (defun c-skip-conditional () 6320 (defun c-skip-conditional ()
6284 ;; skip forward over conditional at point, including any predicate 6321 ;; skip forward over conditional at point, including any predicate
6285 ;; statements in parentheses. No error checking is performed. 6322 ;; statements in parentheses. No error checking is performed.
6286 ;; 6323 ;;