comparison lisp/progmodes/cc-engine.el @ 79408:a29ca195b71e

(c-crosses-statement-barrier-p): Fix typo in docstring.
author Juanma Barranquero <lekktu@gmail.com>
date Thu, 15 Nov 2007 18:27:06 +0000
parents b3cad8795b91
children a1342e6e097a
comparison
equal deleted inserted replaced
79407:d4b0de1c65bc 79408:a29ca195b71e
602 ;; pushed when we move back over a "continuation" token (e.g. else) 602 ;; pushed when we move back over a "continuation" token (e.g. else)
603 ;; and popped when we encounter the corresponding opening token 603 ;; and popped when we encounter the corresponding opening token
604 ;; (e.g. if). 604 ;; (e.g. if).
605 ;; 605 ;;
606 ;; 606 ;;
607 ;; The following diagram briefly outlines the PDA. 607 ;; The following diagram briefly outlines the PDA.
608 ;; 608 ;;
609 ;; Common state: 609 ;; Common state:
610 ;; "else": Push state, goto state `else'. 610 ;; "else": Push state, goto state `else'.
611 ;; "while": Push state, goto state `while'. 611 ;; "while": Push state, goto state `while'.
612 ;; "catch" or "finally": Push state, goto state `catch'. 612 ;; "catch" or "finally": Push state, goto state `catch'.
1077 might start a label (i.e. not part of `::' and not preceded by `?'). If a 1077 might start a label (i.e. not part of `::' and not preceded by `?'). If a
1078 single `?' is found, then `c-maybe-labelp' is cleared. 1078 single `?' is found, then `c-maybe-labelp' is cleared.
1079 1079
1080 For AWK, a statement which is terminated by an EOL (not a \; or a }) is 1080 For AWK, a statement which is terminated by an EOL (not a \; or a }) is
1081 regarded as having a \"virtual semicolon\" immediately after the last token on 1081 regarded as having a \"virtual semicolon\" immediately after the last token on
1082 the line. If this virtual semicolon is _at_ from, the function recognises it. 1082 the line. If this virtual semicolon is _at_ from, the function recognizes it.
1083 1083
1084 Note that this function might do hidden buffer changes. See the 1084 Note that this function might do hidden buffer changes. See the
1085 comment at the start of cc-engine.el for more info." 1085 comment at the start of cc-engine.el for more info."
1086 (let ((skip-chars c-stmt-delim-chars) 1086 (let ((skip-chars c-stmt-delim-chars)
1087 lit-range) 1087 lit-range)
1914 1914
1915 ;; Other whitespace tools 1915 ;; Other whitespace tools
1916 (defun c-partial-ws-p (beg end) 1916 (defun c-partial-ws-p (beg end)
1917 ;; Is the region (beg end) WS, and is there WS (or BOB/EOB) next to the 1917 ;; Is the region (beg end) WS, and is there WS (or BOB/EOB) next to the
1918 ;; region? This is a "heuristic" function. ..... 1918 ;; region? This is a "heuristic" function. .....
1919 ;; 1919 ;;
1920 ;; The motivation for the second bit is to check whether removing this 1920 ;; The motivation for the second bit is to check whether removing this
1921 ;; region would coalesce two symbols. 1921 ;; region would coalesce two symbols.
1922 ;; 1922 ;;
1923 ;; FIXME!!! This function doesn't check virtual semicolons in any way. Be 1923 ;; FIXME!!! This function doesn't check virtual semicolons in any way. Be
1924 ;; careful about using this function for, e.g. AWK. (2007/3/7) 1924 ;; careful about using this function for, e.g. AWK. (2007/3/7)
3289 ;; "string", and reports that the { is within a string started by the second /. 3289 ;; "string", and reports that the { is within a string started by the second /.
3290 ;; 3290 ;;
3291 ;; The workaround for this is for the AWK Mode initialisation to switch the 3291 ;; The workaround for this is for the AWK Mode initialisation to switch the
3292 ;; defalias for c-in-literal to c-slow-in-literal. This will slow down other 3292 ;; defalias for c-in-literal to c-slow-in-literal. This will slow down other
3293 ;; cc-modes in Xemacs whenever an awk-buffer has been initialised. 3293 ;; cc-modes in Xemacs whenever an awk-buffer has been initialised.
3294 ;; 3294 ;;
3295 ;; (Alan Mackenzie, 2003/4/30). 3295 ;; (Alan Mackenzie, 2003/4/30).
3296 3296
3297 (defun c-fast-in-literal (&optional lim detect-cpp) 3297 (defun c-fast-in-literal (&optional lim detect-cpp)
3298 ;; This function might do hidden buffer changes. 3298 ;; This function might do hidden buffer changes.
3299 (let ((context (buffer-syntactic-context))) 3299 (let ((context (buffer-syntactic-context)))
3404 (save-excursion 3404 (save-excursion
3405 (condition-case nil 3405 (condition-case nil
3406 (if (and (consp range) (progn 3406 (if (and (consp range) (progn
3407 (goto-char (car range)) 3407 (goto-char (car range))
3408 (looking-at c-line-comment-starter))) 3408 (looking-at c-line-comment-starter)))
3409 (let ((col (current-column)) 3409 (let ((col (current-column))
3410 (beg (point)) 3410 (beg (point))
3411 (bopl (c-point 'bopl)) 3411 (bopl (c-point 'bopl))
3412 (end (cdr range))) 3412 (end (cdr range)))
3413 ;; Got to take care in the backward direction to handle 3413 ;; Got to take care in the backward direction to handle
3414 ;; comments which are preceded by code. 3414 ;; comments which are preceded by code.
4040 ;; c-maybe-stale-found-type (set in c-before-change), removes a type 4040 ;; c-maybe-stale-found-type (set in c-before-change), removes a type
4041 ;; from `c-found-types', should this type have become stale. For 4041 ;; from `c-found-types', should this type have become stale. For
4042 ;; example, this happens to "foo" when "foo \n bar();" becomes 4042 ;; example, this happens to "foo" when "foo \n bar();" becomes
4043 ;; "foo(); \n bar();". Such stale types, if not removed, foul up 4043 ;; "foo(); \n bar();". Such stale types, if not removed, foul up
4044 ;; the fontification. 4044 ;; the fontification.
4045 ;; 4045 ;;
4046 ;; Have we, perhaps, added non-ws characters to the front/back of a found 4046 ;; Have we, perhaps, added non-ws characters to the front/back of a found
4047 ;; type? 4047 ;; type?
4048 (when (> end beg) 4048 (when (> end beg)
4049 (save-excursion 4049 (save-excursion
4050 (when (< end (point-max)) 4050 (when (< end (point-max))
4059 (if (and (c-end-of-current-token) ; only moves when we started in the middle 4059 (if (and (c-end-of-current-token) ; only moves when we started in the middle
4060 (progn (goto-char beg) 4060 (progn (goto-char beg)
4061 (c-beginning-of-current-token))) 4061 (c-beginning-of-current-token)))
4062 (c-unfind-type (buffer-substring-no-properties 4062 (c-unfind-type (buffer-substring-no-properties
4063 (point) beg)))))) 4063 (point) beg))))))
4064 4064
4065 (if c-maybe-stale-found-type ; e.g. (c-decl-id-start "foo" 97 107 " (* ooka) " "o") 4065 (if c-maybe-stale-found-type ; e.g. (c-decl-id-start "foo" 97 107 " (* ooka) " "o")
4066 (cond 4066 (cond
4067 ;; Changing the amount of (already existing) whitespace - don't do anything. 4067 ;; Changing the amount of (already existing) whitespace - don't do anything.
4068 ((and (c-partial-ws-p beg end) 4068 ((and (c-partial-ws-p beg end)
4069 (or (= beg end) ; removal of WS 4069 (or (= beg end) ; removal of WS
5924 label-end 5924 label-end
5925 qt-symbol-idx 5925 qt-symbol-idx
5926 macro-start ; if we're in one. 5926 macro-start ; if we're in one.
5927 label-type) 5927 label-type)
5928 (cond 5928 (cond
5929 ;; "case" or "default" (Doesn't apply to AWK). 5929 ;; "case" or "default" (Doesn't apply to AWK).
5930 ((looking-at c-label-kwds-regexp) 5930 ((looking-at c-label-kwds-regexp)
5931 (let ((kwd-end (match-end 1))) 5931 (let ((kwd-end (match-end 1)))
5932 ;; Record only the keyword itself for fontification, since in 5932 ;; Record only the keyword itself for fontification, since in
5933 ;; case labels the following is a constant expression and not 5933 ;; case labels the following is a constant expression and not
5934 ;; a label. 5934 ;; a label.
6043 (unless (and c-opt-cpp-prefix (looking-at c-opt-cpp-prefix)) 6043 (unless (and c-opt-cpp-prefix (looking-at c-opt-cpp-prefix))
6044 (c-forward-syntactic-ws) 6044 (c-forward-syntactic-ws)
6045 (c-forward-label nil pte start)))))))))) 6045 (c-forward-label nil pte start))))))))))
6046 6046
6047 ;; Point is still at the beginning of the possible label construct. 6047 ;; Point is still at the beginning of the possible label construct.
6048 ;; 6048 ;;
6049 ;; Check that the next nonsymbol token is ":", or that we're in one 6049 ;; Check that the next nonsymbol token is ":", or that we're in one
6050 ;; of QT's "slots" declarations. Allow '(' for the sake of macro 6050 ;; of QT's "slots" declarations. Allow '(' for the sake of macro
6051 ;; arguments. FIXME: Should build this regexp from the language 6051 ;; arguments. FIXME: Should build this regexp from the language
6052 ;; constants. 6052 ;; constants.
6053 (cond 6053 (cond
6069 (setq label-end (point)) 6069 (setq label-end (point))
6070 (setq qt-symbol-idx 6070 (setq qt-symbol-idx
6071 (and (c-major-mode-is 'c++-mode) 6071 (and (c-major-mode-is 'c++-mode)
6072 (string-match 6072 (string-match
6073 "\\(p\\(r\\(ivate\\|otected\\)\\|ublic\\)\\|more\\)\\>" 6073 "\\(p\\(r\\(ivate\\|otected\\)\\|ublic\\)\\|more\\)\\>"
6074 (buffer-substring start (point))))) 6074 (buffer-substring start (point)))))
6075 (c-forward-syntactic-ws limit) 6075 (c-forward-syntactic-ws limit)
6076 (cond 6076 (cond
6077 ((looking-at ":\\([^:]\\|\\'\\)") ; A single colon. 6077 ((looking-at ":\\([^:]\\|\\'\\)") ; A single colon.
6078 (forward-char) 6078 (forward-char)
6079 (setq label-type 6079 (setq label-type
7233 paren-state) 7233 paren-state)
7234 ;; Add the indicated SYNTAX-SYMBOL to `c-syntactic-context', extending it as 7234 ;; Add the indicated SYNTAX-SYMBOL to `c-syntactic-context', extending it as
7235 ;; needed with further syntax elements of the types `substatement', 7235 ;; needed with further syntax elements of the types `substatement',
7236 ;; `inexpr-statement', `arglist-cont-nonempty', `statement-block-intro', and 7236 ;; `inexpr-statement', `arglist-cont-nonempty', `statement-block-intro', and
7237 ;; `defun-block-intro'. 7237 ;; `defun-block-intro'.
7238 ;; 7238 ;;
7239 ;; Do the generic processing to anchor the given syntax symbol on 7239 ;; Do the generic processing to anchor the given syntax symbol on
7240 ;; the preceding statement: Skip over any labels and containing 7240 ;; the preceding statement: Skip over any labels and containing
7241 ;; statements on the same line, and then search backward until we 7241 ;; statements on the same line, and then search backward until we
7242 ;; find a statement or block start that begins at boi without a 7242 ;; find a statement or block start that begins at boi without a
7243 ;; label or comment. 7243 ;; label or comment.
7419 (c-add-syntax 7419 (c-add-syntax
7420 (cdr (assoc (match-string 1) 7420 (cdr (assoc (match-string 1)
7421 c-other-decl-block-key-in-symbols-alist)) 7421 c-other-decl-block-key-in-symbols-alist))
7422 (max (c-point 'boi paren-pos) (point)))) 7422 (max (c-point 'boi paren-pos) (point))))
7423 (t (c-add-syntax 'defun-block-intro nil)))) 7423 (t (c-add-syntax 'defun-block-intro nil))))
7424 7424
7425 (c-add-syntax 'statement-block-intro nil))) 7425 (c-add-syntax 'statement-block-intro nil)))
7426 7426
7427 (if (= paren-pos boi) 7427 (if (= paren-pos boi)
7428 ;; Always done if the open brace was at boi. The 7428 ;; Always done if the open brace was at boi. The
7429 ;; c-beginning-of-statement-1 call above is necessary 7429 ;; c-beginning-of-statement-1 call above is necessary
8259 ;; the first variable declaration. C.f. case 5N. 8259 ;; the first variable declaration. C.f. case 5N.
8260 'topmost-intro-cont 8260 'topmost-intro-cont
8261 'statement-cont) 8261 'statement-cont)
8262 nil nil containing-sexp paren-state)) 8262 nil nil containing-sexp paren-state))
8263 )) 8263 ))
8264 8264
8265 ;; CASE 5F: Close of a non-class declaration level block. 8265 ;; CASE 5F: Close of a non-class declaration level block.
8266 ((and (eq char-after-ip ?}) 8266 ((and (eq char-after-ip ?})
8267 (c-keyword-member containing-decl-kwd 8267 (c-keyword-member containing-decl-kwd
8268 'c-other-block-decl-kwds)) 8268 'c-other-block-decl-kwds))
8269 ;; This is inconsistent: Should use `containing-decl-open' 8269 ;; This is inconsistent: Should use `containing-decl-open'