diff options
| author | Alan Mackenzie | 2009-02-21 16:10:39 +0000 |
|---|---|---|
| committer | Alan Mackenzie | 2009-02-21 16:10:39 +0000 |
| commit | d28e7f288e4abb47c3143d5fd936f5ea440c3d96 (patch) | |
| tree | 27689676e8f9faeff5728ec2e997f7e049efc529 | |
| parent | 90005fd6f3fd5188e6a6de90474bed6fa1f56a5a (diff) | |
| download | emacs-d28e7f288e4abb47c3143d5fd936f5ea440c3d96.tar.gz emacs-d28e7f288e4abb47c3143d5fd936f5ea440c3d96.zip | |
cc-engine.el (c-beginning-of-statement-1): Enhance to parse case clauses
with (compile-time) expressions.
cc-langs.el (c-case-kwds-regexp): New variable for the above.
| -rw-r--r-- | lisp/progmodes/cc-engine.el | 39 | ||||
| -rw-r--r-- | lisp/progmodes/cc-langs.el | 11 |
2 files changed, 33 insertions, 17 deletions
diff --git a/lisp/progmodes/cc-engine.el b/lisp/progmodes/cc-engine.el index 3e6b58f822b..b2a36220a7f 100644 --- a/lisp/progmodes/cc-engine.el +++ b/lisp/progmodes/cc-engine.el | |||
| @@ -554,7 +554,7 @@ start of the definition in a \"#define\". Also stop at start of | |||
| 554 | macros before leaving them. | 554 | macros before leaving them. |
| 555 | 555 | ||
| 556 | Return: | 556 | Return: |
| 557 | 'label if stopped at a label; | 557 | 'label if stopped at a label or \"case...:\" or \"default:\"; |
| 558 | 'same if stopped at the beginning of the current statement; | 558 | 'same if stopped at the beginning of the current statement; |
| 559 | 'up if stepped to a containing statement; | 559 | 'up if stepped to a containing statement; |
| 560 | 'previous if stepped to a preceding statement; | 560 | 'previous if stepped to a preceding statement; |
| @@ -665,7 +665,7 @@ comment at the start of cc-engine.el for more info." | |||
| 665 | (c-stmt-delim-chars (if comma-delim | 665 | (c-stmt-delim-chars (if comma-delim |
| 666 | c-stmt-delim-chars-with-comma | 666 | c-stmt-delim-chars-with-comma |
| 667 | c-stmt-delim-chars)) | 667 | c-stmt-delim-chars)) |
| 668 | c-in-literal-cache c-maybe-labelp saved | 668 | c-in-literal-cache c-maybe-labelp after-case:-pos saved |
| 669 | ;; Current position. | 669 | ;; Current position. |
| 670 | pos | 670 | pos |
| 671 | ;; Position of last stmt boundary character (e.g. ;). | 671 | ;; Position of last stmt boundary character (e.g. ;). |
| @@ -979,7 +979,7 @@ comment at the start of cc-engine.el for more info." | |||
| 979 | ;; Like a C "continue". Analyze the next sexp. | 979 | ;; Like a C "continue". Analyze the next sexp. |
| 980 | (throw 'loop t))) | 980 | (throw 'loop t))) |
| 981 | 981 | ||
| 982 | sexp-loop-continue-pos) ; End of "go back a sexp" loop. | 982 | sexp-loop-continue-pos) ; End of "go back a sexp" loop condition. |
| 983 | (goto-char sexp-loop-continue-pos) | 983 | (goto-char sexp-loop-continue-pos) |
| 984 | (setq sexp-loop-end-pos sexp-loop-continue-pos | 984 | (setq sexp-loop-end-pos sexp-loop-continue-pos |
| 985 | sexp-loop-continue-pos nil)))) | 985 | sexp-loop-continue-pos nil)))) |
| @@ -997,19 +997,16 @@ comment at the start of cc-engine.el for more info." | |||
| 997 | ;; `c-crosses-statement-barrier-p' has found a colon, so we | 997 | ;; `c-crosses-statement-barrier-p' has found a colon, so we |
| 998 | ;; might be in a label now. Have we got a real label | 998 | ;; might be in a label now. Have we got a real label |
| 999 | ;; (including a case label) or something like C++'s "public:"? | 999 | ;; (including a case label) or something like C++'s "public:"? |
| 1000 | (if (or (not (looking-at c-nonlabel-token-key)) ; proper label | 1000 | ;; A case label might use an expression rather than a token. |
| 1001 | (save-excursion ; e.g. "case 'a':" ? | 1001 | (setq after-case:-pos (or tok start)) |
| 1002 | (and (c-safe (c-backward-sexp) t) | 1002 | (if (looking-at c-nonlabel-token-key) ; e.g. "while" or "'a'" |
| 1003 | (looking-at "\\<case\\>")))) ; FIXME!!! this is | 1003 | (setq c-maybe-labelp nil) |
| 1004 | ; wrong for AWK. 2006/1/14. | 1004 | (if after-labels-pos ; Have we already encountered a label? |
| 1005 | (progn | 1005 | (if (not last-label-pos) |
| 1006 | (if after-labels-pos ; Have we already encountered a label? | 1006 | (setq last-label-pos (or tok start))) |
| 1007 | (if (not last-label-pos) | 1007 | (setq after-labels-pos (or tok start))) |
| 1008 | (setq last-label-pos (or tok start))) | 1008 | (setq c-maybe-labelp t |
| 1009 | (setq after-labels-pos (or tok start))) | 1009 | label-good-pos nil))) ; bogus "label" |
| 1010 | (setq c-maybe-labelp t | ||
| 1011 | label-good-pos nil)) | ||
| 1012 | (setq c-maybe-labelp nil))) ; bogus "label" | ||
| 1013 | 1010 | ||
| 1014 | (when (and (not label-good-pos) ; i.e. no invalid "label"'s yet | 1011 | (when (and (not label-good-pos) ; i.e. no invalid "label"'s yet |
| 1015 | ; been found. | 1012 | ; been found. |
| @@ -1064,8 +1061,16 @@ comment at the start of cc-engine.el for more info." | |||
| 1064 | ;; Might have jumped over several labels. Go to the last one. | 1061 | ;; Might have jumped over several labels. Go to the last one. |
| 1065 | (setq pos last-label-pos))))) | 1062 | (setq pos last-label-pos))))) |
| 1066 | 1063 | ||
| 1067 | ;; Skip over the unary operators that can start the statement. | 1064 | ;; Have we got "case <expression>:"? |
| 1068 | (goto-char pos) | 1065 | (goto-char pos) |
| 1066 | (when (and after-case:-pos | ||
| 1067 | (not (eq ret 'beginning)) | ||
| 1068 | (looking-at c-case-kwds-regexp)) | ||
| 1069 | (if (< after-case:-pos start) | ||
| 1070 | (setq pos after-case:-pos) | ||
| 1071 | (setq ret 'label))) | ||
| 1072 | |||
| 1073 | ;; Skip over the unary operators that can start the statement. | ||
| 1069 | (while (progn | 1074 | (while (progn |
| 1070 | (c-backward-syntactic-ws) | 1075 | (c-backward-syntactic-ws) |
| 1071 | ;; protect AWK post-inc/decrement operators, etc. | 1076 | ;; protect AWK post-inc/decrement operators, etc. |
diff --git a/lisp/progmodes/cc-langs.el b/lisp/progmodes/cc-langs.el index fc3dfde58ee..1a4fba2c8a1 100644 --- a/lisp/progmodes/cc-langs.el +++ b/lisp/progmodes/cc-langs.el | |||
| @@ -2115,6 +2115,17 @@ nevertheless contains a list separated with ';' and not ','." | |||
| 2115 | (c-make-keywords-re t (c-lang-const c-asm-stmt-kwds)))) | 2115 | (c-make-keywords-re t (c-lang-const c-asm-stmt-kwds)))) |
| 2116 | (c-lang-defvar c-opt-asm-stmt-key (c-lang-const c-opt-asm-stmt-key)) | 2116 | (c-lang-defvar c-opt-asm-stmt-key (c-lang-const c-opt-asm-stmt-key)) |
| 2117 | 2117 | ||
| 2118 | (c-lang-defconst c-case-kwds | ||
| 2119 | "The keyword\(s) which introduce a \"case\" like construct. | ||
| 2120 | This construct is \"<keyword> <expression> :\"." | ||
| 2121 | t '("case") | ||
| 2122 | awk nil) | ||
| 2123 | |||
| 2124 | (c-lang-defconst c-case-kwds-regexp | ||
| 2125 | ;; Adorned regexp matching any "case"-like keyword. | ||
| 2126 | t (c-make-keywords-re t (c-lang-const c-case-kwds))) | ||
| 2127 | (c-lang-defvar c-case-kwds-regexp (c-lang-const c-case-kwds-regexp)) | ||
| 2128 | |||
| 2118 | (c-lang-defconst c-label-kwds | 2129 | (c-lang-defconst c-label-kwds |
| 2119 | "Keywords introducing colon terminated labels in blocks." | 2130 | "Keywords introducing colon terminated labels in blocks." |
| 2120 | t '("case" "default") | 2131 | t '("case" "default") |