aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlan Mackenzie2018-06-09 21:39:43 +0000
committerAlan Mackenzie2018-06-09 21:39:43 +0000
commit89e2683d4430ffbe3bfe355ca389c349304bdcb9 (patch)
treecc934de8c169dbe43a3e5ac3d557902e4e0dec2a
parenta66a3b7f51792aa2a91c16ed9121d7e9efea4536 (diff)
downloademacs-89e2683d4430ffbe3bfe355ca389c349304bdcb9.tar.gz
emacs-89e2683d4430ffbe3bfe355ca389c349304bdcb9.zip
Implement the C++11 "using" type definition.
Cease using the long obsolete c++-template-syntax-table. * lisp/progmodes/cc-align.el (c-lineup-template-args): Cease using c++-template-syntax-table. * lisp/progmodes/cc-engine.el (c-beginning-of-inheritance-list) (c-search-decl-header-end, c-beginning-of-decl-1, c-end-of-decl-1) (c-guess-continued-construct, c-guess-basic-syntax): Cease using c++-template-syntax-table. (c-guess-basic-syntax): Add CASE 5D.6 to handle C++11's "using" type definition. * lisp/progmodes/cc-langs.el (c++-make-template-syntax-table) (c++-template-syntax-table): Remove. (c-equals-type-clause-kwds, c-equals-type-clause-key): New language constants/variables.
-rw-r--r--lisp/progmodes/cc-align.el11
-rw-r--r--lisp/progmodes/cc-engine.el152
-rw-r--r--lisp/progmodes/cc-langs.el33
3 files changed, 95 insertions, 101 deletions
diff --git a/lisp/progmodes/cc-align.el b/lisp/progmodes/cc-align.el
index 09887b02f3b..1b48a5a66c9 100644
--- a/lisp/progmodes/cc-align.el
+++ b/lisp/progmodes/cc-align.el
@@ -868,12 +868,11 @@ returned if there's no template argument on the first line.
868 868
869Works with: template-args-cont." 869Works with: template-args-cont."
870 (save-excursion 870 (save-excursion
871 (c-with-syntax-table c++-template-syntax-table 871 (beginning-of-line)
872 (beginning-of-line) 872 (backward-up-list 1)
873 (backward-up-list 1) 873 (if (and (eq (char-after) ?<)
874 (if (and (eq (char-after) ?<) 874 (zerop (c-forward-token-2 1 nil (c-point 'eol))))
875 (zerop (c-forward-token-2 1 nil (c-point 'eol)))) 875 (vector (current-column)))))
876 (vector (current-column))))))
877 876
878(defun c-lineup-ObjC-method-call (langelem) 877(defun c-lineup-ObjC-method-call (langelem)
879 "Line up selector args as Emacs Lisp mode does with function args: 878 "Line up selector args as Emacs Lisp mode does with function args:
diff --git a/lisp/progmodes/cc-engine.el b/lisp/progmodes/cc-engine.el
index 3d9e4fa0d35..36f5196c5e2 100644
--- a/lisp/progmodes/cc-engine.el
+++ b/lisp/progmodes/cc-engine.el
@@ -9510,11 +9510,10 @@ comment at the start of cc-engine.el for more info."
9510 ;; back we should search. 9510 ;; back we should search.
9511 ;; 9511 ;;
9512 ;; This function might do hidden buffer changes. 9512 ;; This function might do hidden buffer changes.
9513 (c-with-syntax-table c++-template-syntax-table 9513 (c-backward-token-2 0 t lim)
9514 (c-backward-token-2 0 t lim) 9514 (while (and (or (looking-at c-symbol-start)
9515 (while (and (or (looking-at c-symbol-start) 9515 (looking-at "[<,]\\|::"))
9516 (looking-at "[<,]\\|::")) 9516 (zerop (c-backward-token-2 1 t lim)))))
9517 (zerop (c-backward-token-2 1 t lim))))))
9518 9517
9519(defun c-in-method-def-p () 9518(defun c-in-method-def-p ()
9520 ;; Return nil if we aren't in a method definition, otherwise the 9519 ;; Return nil if we aren't in a method definition, otherwise the
@@ -9890,11 +9889,10 @@ comment at the start of cc-engine.el for more info."
9890 (and (c-safe (c-backward-sexp) t) 9889 (and (c-safe (c-backward-sexp) t)
9891 (looking-at c-opt-op-identifier-prefix))) 9890 (looking-at c-opt-op-identifier-prefix)))
9892 (and (eq (char-before) ?<) 9891 (and (eq (char-before) ?<)
9893 (c-with-syntax-table c++-template-syntax-table 9892 (if (c-safe (goto-char (c-up-list-forward (point))))
9894 (if (c-safe (goto-char (c-up-list-forward (point)))) 9893 t
9895 t 9894 (goto-char (point-max))
9896 (goto-char (point-max)) 9895 nil))))
9897 nil)))))
9898 (setq base (point))) 9896 (setq base (point)))
9899 9897
9900 (while (and 9898 (while (and
@@ -9987,28 +9985,25 @@ comment at the start of cc-engine.el for more info."
9987 ;; potentially can search over a large amount of text.). Take special 9985 ;; potentially can search over a large amount of text.). Take special
9988 ;; pains not to get mislead by C++'s "operator=", and the like. 9986 ;; pains not to get mislead by C++'s "operator=", and the like.
9989 (if (and (eq move 'previous) 9987 (if (and (eq move 'previous)
9990 (c-with-syntax-table (if (c-major-mode-is 'c++-mode) 9988 (save-excursion
9991 c++-template-syntax-table 9989 (and
9992 (syntax-table)) 9990 (progn
9993 (save-excursion 9991 (while ; keep going back to "[;={"s until we either find
9994 (and 9992 ; no more, or get to one which isn't an "operator ="
9995 (progn 9993 (and (c-syntactic-re-search-forward "[;={]" start t t t)
9996 (while ; keep going back to "[;={"s until we either find 9994 (eq (char-before) ?=)
9997 ; no more, or get to one which isn't an "operator =" 9995 c-overloadable-operators-regexp
9998 (and (c-syntactic-re-search-forward "[;={]" start t t t) 9996 c-opt-op-identifier-prefix
9999 (eq (char-before) ?=) 9997 (save-excursion
10000 c-overloadable-operators-regexp 9998 (eq (c-backward-token-2) 0)
10001 c-opt-op-identifier-prefix 9999 (looking-at c-overloadable-operators-regexp)
10002 (save-excursion 10000 (eq (c-backward-token-2) 0)
10003 (eq (c-backward-token-2) 0) 10001 (looking-at c-opt-op-identifier-prefix))))
10004 (looking-at c-overloadable-operators-regexp) 10002 (eq (char-before) ?=))
10005 (eq (c-backward-token-2) 0) 10003 (c-syntactic-re-search-forward "[;{]" start t t)
10006 (looking-at c-opt-op-identifier-prefix)))) 10004 (eq (char-before) ?{)
10007 (eq (char-before) ?=)) 10005 (c-safe (goto-char (c-up-list-forward (point))) t)
10008 (c-syntactic-re-search-forward "[;{]" start t t) 10006 (not (c-syntactic-re-search-forward ";" start t t)))))
10009 (eq (char-before) ?{)
10010 (c-safe (goto-char (c-up-list-forward (point))) t)
10011 (not (c-syntactic-re-search-forward ";" start t t))))))
10012 (cons 'same nil) 10007 (cons 'same nil)
10013 (cons move nil))))) 10008 (cons move nil)))))
10014 10009
@@ -10023,10 +10018,7 @@ comment at the start of cc-engine.el for more info."
10023 ;; `c-end-of-macro' instead in those cases. 10018 ;; `c-end-of-macro' instead in those cases.
10024 ;; 10019 ;;
10025 ;; This function might do hidden buffer changes. 10020 ;; This function might do hidden buffer changes.
10026 (let ((start (point)) 10021 (let ((start (point)))
10027 (decl-syntax-table (if (c-major-mode-is 'c++-mode)
10028 c++-template-syntax-table
10029 (syntax-table))))
10030 (catch 'return 10022 (catch 'return
10031 (c-search-decl-header-end) 10023 (c-search-decl-header-end)
10032 10024
@@ -10047,34 +10039,32 @@ comment at the start of cc-engine.el for more info."
10047 (throw 'return nil))) 10039 (throw 'return nil)))
10048 (if (or (not c-opt-block-decls-with-vars-key) 10040 (if (or (not c-opt-block-decls-with-vars-key)
10049 (save-excursion 10041 (save-excursion
10050 (c-with-syntax-table decl-syntax-table 10042 (let ((lim (point)))
10051 (let ((lim (point))) 10043 (goto-char start)
10052 (goto-char start) 10044 (not (and
10053 (not (and 10045 ;; Check for `c-opt-block-decls-with-vars-key'
10054 ;; Check for `c-opt-block-decls-with-vars-key' 10046 ;; before the first paren.
10055 ;; before the first paren. 10047 (c-syntactic-re-search-forward
10056 (c-syntactic-re-search-forward 10048 (concat "[;=\(\[{]\\|\\("
10057 (concat "[;=([{]\\|\\(" 10049 c-opt-block-decls-with-vars-key
10058 c-opt-block-decls-with-vars-key 10050 "\\)")
10059 "\\)") 10051 lim t t t)
10060 lim t t t) 10052 (match-beginning 1)
10061 (match-beginning 1) 10053 (not (eq (char-before) ?_))
10062 (not (eq (char-before) ?_)) 10054 ;; Check that the first following paren is
10063 ;; Check that the first following paren is 10055 ;; the block.
10064 ;; the block. 10056 (c-syntactic-re-search-forward "[;=\(\[{]"
10065 (c-syntactic-re-search-forward "[;=([{]" 10057 lim t t t)
10066 lim t t t) 10058 (eq (char-before) ?{))))))
10067 (eq (char-before) ?{)))))))
10068 ;; The declaration doesn't have any of the 10059 ;; The declaration doesn't have any of the
10069 ;; `c-opt-block-decls-with-vars' keywords in the 10060 ;; `c-opt-block-decls-with-vars' keywords in the
10070 ;; beginning, so it ends here at the end of the block. 10061 ;; beginning, so it ends here at the end of the block.
10071 (throw 'return t))) 10062 (throw 'return t)))
10072 10063
10073 (c-with-syntax-table decl-syntax-table 10064 (while (progn
10074 (while (progn 10065 (if (eq (char-before) ?\;)
10075 (if (eq (char-before) ?\;) 10066 (throw 'return t))
10076 (throw 'return t)) 10067 (c-syntactic-re-search-forward ";" nil 'move t)))
10077 (c-syntactic-re-search-forward ";" nil 'move t))))
10078 nil))) 10068 nil)))
10079 10069
10080(defun c-looking-at-decl-block (_containing-sexp goto-start &optional limit) 10070(defun c-looking-at-decl-block (_containing-sexp goto-start &optional limit)
@@ -11460,17 +11450,15 @@ comment at the start of cc-engine.el for more info."
11460 ((and (c-major-mode-is 'c++-mode) 11450 ((and (c-major-mode-is 'c++-mode)
11461 (save-excursion 11451 (save-excursion
11462 (goto-char indent-point) 11452 (goto-char indent-point)
11463 (c-with-syntax-table c++-template-syntax-table 11453 (setq placeholder (c-up-list-backward))
11464 (setq placeholder (c-up-list-backward)))
11465 (and placeholder 11454 (and placeholder
11466 (eq (char-after placeholder) ?<) 11455 (eq (char-after placeholder) ?<)
11467 (/= (char-before placeholder) ?<) 11456 (/= (char-before placeholder) ?<)
11468 (progn 11457 (progn
11469 (goto-char (1+ placeholder)) 11458 (goto-char (1+ placeholder))
11470 (not (looking-at c-<-op-cont-regexp)))))) 11459 (not (looking-at c-<-op-cont-regexp))))))
11471 (c-with-syntax-table c++-template-syntax-table 11460 (goto-char placeholder)
11472 (goto-char placeholder) 11461 (c-beginning-of-statement-1 containing-sexp t)
11473 (c-beginning-of-statement-1 containing-sexp t))
11474 (if (save-excursion 11462 (if (save-excursion
11475 (c-backward-syntactic-ws containing-sexp) 11463 (c-backward-syntactic-ws containing-sexp)
11476 (eq (char-before) ?<)) 11464 (eq (char-before) ?<))
@@ -12130,21 +12118,38 @@ comment at the start of cc-engine.el for more info."
12130 ;; NB: No c-after-special-operator-id stuff in this 12118 ;; NB: No c-after-special-operator-id stuff in this
12131 ;; clause - we assume only C++ needs it. 12119 ;; clause - we assume only C++ needs it.
12132 (c-syntactic-skip-backward "^;,=" lim t)) 12120 (c-syntactic-skip-backward "^;,=" lim t))
12121 (setq placeholder (point))
12133 (memq (char-before) '(?, ?= ?<))) 12122 (memq (char-before) '(?, ?= ?<)))
12134 (cond 12123 (cond
12135 12124
12125 ;; CASE 5D.6: Something like C++11's "using foo = <type-exp>"
12126 ((save-excursion
12127 (and (eq (char-before placeholder) ?=)
12128 (goto-char placeholder)
12129 (eq (c-backward-token-2 1 nil lim) 0)
12130 (eq (point) (1- placeholder))
12131 (eq (c-beginning-of-statement-1 lim) 'same)
12132 (looking-at c-equals-type-clause-key)
12133 (let ((preserve-point (point)))
12134 (when
12135 (and
12136 (eq (c-forward-token-2 1 nil nil) 0)
12137 (c-on-identifier))
12138 (setq placeholder preserve-point)))))
12139 (c-add-syntax
12140 'statement-cont placeholder)
12141 )
12142
12136 ;; CASE 5D.3: perhaps a template list continuation? 12143 ;; CASE 5D.3: perhaps a template list continuation?
12137 ((and (c-major-mode-is 'c++-mode) 12144 ((and (c-major-mode-is 'c++-mode)
12138 (save-excursion 12145 (save-excursion
12139 (save-restriction 12146 (save-restriction
12140 (c-with-syntax-table c++-template-syntax-table 12147 (goto-char indent-point)
12141 (goto-char indent-point) 12148 (setq placeholder (c-up-list-backward))
12142 (setq placeholder (c-up-list-backward)) 12149 (and placeholder
12143 (and placeholder 12150 (eq (char-after placeholder) ?<)))))
12144 (eq (char-after placeholder) ?<)))))) 12151 (goto-char placeholder)
12145 (c-with-syntax-table c++-template-syntax-table 12152 (c-beginning-of-statement-1 lim t)
12146 (goto-char placeholder)
12147 (c-beginning-of-statement-1 lim t))
12148 (if (save-excursion 12153 (if (save-excursion
12149 (c-backward-syntactic-ws lim) 12154 (c-backward-syntactic-ws lim)
12150 (eq (char-before) ?<)) 12155 (eq (char-before) ?<))
@@ -12168,8 +12173,7 @@ comment at the start of cc-engine.el for more info."
12168 (and (looking-at c-class-key) 12173 (and (looking-at c-class-key)
12169 (zerop (c-forward-token-2 2 nil indent-point)) 12174 (zerop (c-forward-token-2 2 nil indent-point))
12170 (if (eq (char-after) ?<) 12175 (if (eq (char-after) ?<)
12171 (c-with-syntax-table c++-template-syntax-table 12176 (zerop (c-forward-token-2 1 t indent-point))
12172 (zerop (c-forward-token-2 1 t indent-point)))
12173 t) 12177 t)
12174 (eq (char-after) ?:)))) 12178 (eq (char-after) ?:))))
12175 (goto-char placeholder) 12179 (goto-char placeholder)
diff --git a/lisp/progmodes/cc-langs.el b/lisp/progmodes/cc-langs.el
index 53cb7f7f725..1b44c75fe6c 100644
--- a/lisp/progmodes/cc-langs.el
+++ b/lisp/progmodes/cc-langs.el
@@ -392,27 +392,6 @@ The syntax tables aren't stored directly since they're quite large."
392 ;; the constants in this file are evaluated. 392 ;; the constants in this file are evaluated.
393 t (funcall (c-lang-const c-make-mode-syntax-table))) 393 t (funcall (c-lang-const c-make-mode-syntax-table)))
394 394
395(c-lang-defconst c++-make-template-syntax-table
396 ;; A variant of `c++-mode-syntax-table' that defines `<' and `>' as
397 ;; parenthesis characters. Used temporarily when template argument
398 ;; lists are parsed. Note that this encourages incorrect parsing of
399 ;; templates since they might contain normal operators that uses the
400 ;; '<' and '>' characters. Therefore this syntax table might go
401 ;; away when CC Mode handles templates correctly everywhere. WHILE
402 ;; THIS SYNTAX TABLE IS CURRENT, `c-parse-state' MUST _NOT_ BE
403 ;; CALLED!!!
404 t nil
405 (java c++) `(lambda ()
406 (let ((table (funcall ,(c-lang-const c-make-mode-syntax-table))))
407 (modify-syntax-entry ?< "(>" table)
408 (modify-syntax-entry ?> ")<" table)
409 table)))
410(c-lang-defvar c++-template-syntax-table
411 (and (c-lang-const c++-make-template-syntax-table)
412 ;; The next eval remove a superfluous ' from '(lambda. This
413 ;; gets rid of compilation warnings.
414 (funcall (eval (c-lang-const c++-make-template-syntax-table)))))
415
416(c-lang-defconst c-make-no-parens-syntax-table 395(c-lang-defconst c-make-no-parens-syntax-table
417 ;; A variant of the standard syntax table which is used to find matching 396 ;; A variant of the standard syntax table which is used to find matching
418 ;; "<"s and ">"s which have been marked as parens using syntax table 397 ;; "<"s and ">"s which have been marked as parens using syntax table
@@ -2210,6 +2189,18 @@ will be handled."
2210 pike (append (c-lang-const c-class-decl-kwds) 2189 pike (append (c-lang-const c-class-decl-kwds)
2211 '("constant"))) 2190 '("constant")))
2212 2191
2192(c-lang-defconst c-equals-type-clause-kwds
2193 "Keywords which are followed by an identifier then an \"=\"
2194 sign, which declares the identifier to be a type."
2195 t nil
2196 c++ '("using"))
2197
2198(c-lang-defconst c-equals-type-clause-key
2199 ;; A regular expression which matches any member of
2200 ;; `c-equals-type-clause-kwds'.
2201 t (c-make-keywords-re t (c-lang-const c-equals-type-clause-kwds)))
2202(c-lang-defvar c-equals-type-clause-key (c-lang-const c-equals-type-clause-key))
2203
2213(c-lang-defconst c-modifier-kwds 2204(c-lang-defconst c-modifier-kwds
2214 "Keywords that can prefix normal declarations of identifiers 2205 "Keywords that can prefix normal declarations of identifiers
2215\(and typically act as flags). Things like argument declarations 2206\(and typically act as flags). Things like argument declarations