aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlan Mackenzie2016-08-30 15:36:15 +0000
committerAlan Mackenzie2016-08-30 15:36:15 +0000
commita9118afcd7d601190c5474820b58289b5ab5cd7e (patch)
tree7252c0845b7a318e471242d302892fec68422ae1
parent62b6c5d2805a07515cbc4368a32376e4d82cf2c3 (diff)
downloademacs-a9118afcd7d601190c5474820b58289b5ab5cd7e.tar.gz
emacs-a9118afcd7d601190c5474820b58289b5ab5cd7e.zip
Correctly analyze C++ list initialization in member init areas.
* lisp/progmodes/cc-engine.el (c-back-over-list-of-member-inits): Remove a superfluous call to c-backward-syntactic-ws. (c-looking-at-or-maybe-in-bracelist): Change calling convention, so that it reports encountering the Java "new" keyword. Add, as an alternative, a check that we can move back over member initializations, and handle this as finding a brace block. (c-looking-at-special-brace-list, c-guess-continued-construct): Adapt to the new calling convention of c-looking-at-or-maybe-in-bracelist. (c-guess-basic-syntax, CASE 5A.3): Replace lots of inline ad-hoc code with calls to c-backward-over-enum-header and c-looking-at-or-maybe-in-bracelist, using the extra info from the value of that function to generate a topmost-into-cont element where needed (in Java). * lisp/progmodes/cc-fonts.el (c-font-lock-declarations): Adapt to the new calling convention of c-looking-at-or-maybe-in-bracelist. * lisp/progmodes/cc-mode.el (c-fl-decl-start): Adapt to the new calling convention of c-looking-at-or-maybe-in-bracelist.
-rw-r--r--lisp/progmodes/cc-engine.el280
-rw-r--r--lisp/progmodes/cc-fonts.el6
-rw-r--r--lisp/progmodes/cc-mode.el2
3 files changed, 140 insertions, 148 deletions
diff --git a/lisp/progmodes/cc-engine.el b/lisp/progmodes/cc-engine.el
index 28d6618d8a0..83ed308e107 100644
--- a/lisp/progmodes/cc-engine.el
+++ b/lisp/progmodes/cc-engine.el
@@ -7434,7 +7434,6 @@ comment at the start of cc-engine.el for more info."
7434 (when (not (c-backward-<>-arglist nil)) 7434 (when (not (c-backward-<>-arglist nil))
7435 (throw 'done nil)) 7435 (throw 'done nil))
7436 (c-backward-syntactic-ws)) 7436 (c-backward-syntactic-ws))
7437 (c-backward-syntactic-ws)
7438 (when (not (c-back-over-compound-identifier)) 7437 (when (not (c-back-over-compound-identifier))
7439 (throw 'level nil)) 7438 (throw 'level nil))
7440 (c-backward-syntactic-ws))) 7439 (c-backward-syntactic-ws)))
@@ -9831,15 +9830,18 @@ comment at the start of cc-engine.el for more info."
9831 (or (looking-at c-brace-list-key) 9830 (or (looking-at c-brace-list-key)
9832 (progn (goto-char here) nil)))) 9831 (progn (goto-char here) nil))))
9833 9832
9834(defun c-looking-at-or-maybe-in-bracelist (containing-sexp &optional lim) 9833(defun c-looking-at-or-maybe-in-bracelist (&optional containing-sexp lim)
9835 ;; Point is at an open brace. If this starts a brace list, return the 9834 ;; Point is at an open brace. If this starts a brace list, return a list
9836 ;; buffer position of the start of the construct which introduces the list. 9835 ;; whose car is the buffer position of the start of the construct which
9837 ;; Otherwise, if point might be inside an enclosing brace list, return t. 9836 ;; introduces the list, and whose cdr is t if we have parsed a keyword
9838 ;; If point is definitely neither at nor in a brace list, return nil. 9837 ;; matching `c-opt-inexpr-brace-list-key' (e.g. Java's "new"), nil
9838 ;; otherwise. Otherwise, if point might be inside an enclosing brace list,
9839 ;; return t. If point is definitely neither at nor in a brace list, return
9840 ;; nil.
9839 ;; 9841 ;;
9840 ;; CONTAINING-SEXP is the position of the brace/paren/braacket enclosing 9842 ;; CONTAINING-SEXP is the position of the brace/paren/braacket enclosing
9841 ;; POINT, or nil if there is no such position. LIM is a backward search 9843 ;; POINT, or nil if there is no such position, or we do not know it. LIM is
9842 ;; limit. 9844 ;; a backward search limit.
9843 ;; 9845 ;;
9844 ;; Here, "brace list" does not include the body of an enum. 9846 ;; Here, "brace list" does not include the body of an enum.
9845 (save-excursion 9847 (save-excursion
@@ -9850,7 +9852,7 @@ comment at the start of cc-engine.el for more info."
9850 (and (c-major-mode-is 'pike-mode) 9852 (and (c-major-mode-is 'pike-mode)
9851 c-decl-block-key)) 9853 c-decl-block-key))
9852 (braceassignp 'dontknow) 9854 (braceassignp 'dontknow)
9853 bufpos macro-start res after-type-id-pos) 9855 inexpr-brace-list bufpos macro-start res pos after-type-id-pos)
9854 9856
9855 (setq res (c-backward-token-2 1 t lim)) 9857 (setq res (c-backward-token-2 1 t lim))
9856 ;; Checks to do only on the first sexp before the brace. 9858 ;; Checks to do only on the first sexp before the brace.
@@ -9886,7 +9888,9 @@ comment at the start of cc-engine.el for more info."
9886 (while (eq braceassignp 'dontknow) 9888 (while (eq braceassignp 'dontknow)
9887 (setq braceassignp 9889 (setq braceassignp
9888 (cond ((/= (c-backward-token-2 1 t lim) 0) nil) 9890 (cond ((/= (c-backward-token-2 1 t lim) 0) nil)
9889 ((looking-at c-opt-inexpr-brace-list-key) t) 9891 ((looking-at c-opt-inexpr-brace-list-key)
9892 (setq inexpr-brace-list t)
9893 t)
9890 ((looking-at "\\sw\\|\\s_\\|[.[]") 9894 ((looking-at "\\sw\\|\\s_\\|[.[]")
9891 ;; Carry on looking if this is an 9895 ;; Carry on looking if this is an
9892 ;; identifier (may contain "." in Java) 9896 ;; identifier (may contain "." in Java)
@@ -9894,104 +9898,116 @@ comment at the start of cc-engine.el for more info."
9894 'dontknow) 9898 'dontknow)
9895 (t nil))))) 9899 (t nil)))))
9896 9900
9897 ;; Checks to do on all sexps before the brace, up to the 9901 (setq pos (point))
9898 ;; beginning of the statement. 9902 (if (and after-type-id-pos
9899 (while (eq braceassignp 'dontknow) 9903 (goto-char after-type-id-pos)
9900 (cond ((eq (char-after) ?\;) 9904 (setq res (c-back-over-member-initializers))
9901 (setq braceassignp nil)) 9905 (goto-char res)
9902 ((and class-key 9906 (eq (car (c-beginning-of-decl-1 lim)) 'same))
9903 (looking-at class-key)) 9907 (cons (point) nil) ; Return value.
9904 (setq braceassignp nil)) 9908
9905 ((eq (char-after) ?=) 9909 (goto-char pos)
9906 ;; We've seen a =, but must check earlier tokens so 9910 ;; Checks to do on all sexps before the brace, up to the
9907 ;; that it isn't something that should be ignored. 9911 ;; beginning of the statement.
9908 (setq braceassignp 'maybe) 9912 (while (eq braceassignp 'dontknow)
9909 (while (and (eq braceassignp 'maybe) 9913 (cond ((eq (char-after) ?\;)
9910 (zerop (c-backward-token-2 1 t lim))) 9914 (setq braceassignp nil))
9911 (setq braceassignp 9915 ((and class-key
9912 (cond 9916 (looking-at class-key))
9913 ;; Check for operator = 9917 (setq braceassignp nil))
9914 ((and c-opt-op-identifier-prefix 9918 ((eq (char-after) ?=)
9915 (looking-at c-opt-op-identifier-prefix)) 9919 ;; We've seen a =, but must check earlier tokens so
9916 nil) 9920 ;; that it isn't something that should be ignored.
9917 ;; Check for `<opchar>= in Pike. 9921 (setq braceassignp 'maybe)
9918 ((and (c-major-mode-is 'pike-mode) 9922 (while (and (eq braceassignp 'maybe)
9919 (or (eq (char-after) ?`) 9923 (zerop (c-backward-token-2 1 t lim)))
9920 ;; Special case for Pikes 9924 (setq braceassignp
9921 ;; `[]=, since '[' is not in 9925 (cond
9922 ;; the punctuation class. 9926 ;; Check for operator =
9923 (and (eq (char-after) ?\[) 9927 ((and c-opt-op-identifier-prefix
9924 (eq (char-before) ?`)))) 9928 (looking-at c-opt-op-identifier-prefix))
9925 nil) 9929 nil)
9926 ((looking-at "\\s.") 'maybe) 9930 ;; Check for `<opchar>= in Pike.
9927 ;; make sure we're not in a C++ template 9931 ((and (c-major-mode-is 'pike-mode)
9928 ;; argument assignment 9932 (or (eq (char-after) ?`)
9929 ((and 9933 ;; Special case for Pikes
9930 (c-major-mode-is 'c++-mode) 9934 ;; `[]=, since '[' is not in
9931 (save-excursion 9935 ;; the punctuation class.
9932 (let ((here (point)) 9936 (and (eq (char-after) ?\[)
9933 (pos< (progn 9937 (eq (char-before) ?`))))
9934 (skip-chars-backward "^<>") 9938 nil)
9935 (point)))) 9939 ((looking-at "\\s.") 'maybe)
9936 (and (eq (char-before) ?<) 9940 ;; make sure we're not in a C++ template
9937 (not (c-crosses-statement-barrier-p 9941 ;; argument assignment
9938 pos< here)) 9942 ((and
9939 (not (c-in-literal)) 9943 (c-major-mode-is 'c++-mode)
9940 )))) 9944 (save-excursion
9941 nil) 9945 (let ((here (point))
9942 (t t)))))) 9946 (pos< (progn
9943 (if (and (eq braceassignp 'dontknow) 9947 (skip-chars-backward "^<>")
9944 (/= (c-backward-token-2 1 t lim) 0)) 9948 (point))))
9945 (setq braceassignp nil))) 9949 (and (eq (char-before) ?<)
9950 (not (c-crosses-statement-barrier-p
9951 pos< here))
9952 (not (c-in-literal))
9953 ))))
9954 nil)
9955 (t t))))))
9956 (if (and (eq braceassignp 'dontknow)
9957 (/= (c-backward-token-2 1 t lim) 0))
9958 (setq braceassignp nil)))
9946 9959
9947 (cond 9960 (cond
9948 (braceassignp 9961 (braceassignp
9949 ;; We've hit the beginning of the aggregate list. 9962 ;; We've hit the beginning of the aggregate list.
9950 (c-beginning-of-statement-1 containing-sexp) 9963 (c-beginning-of-statement-1 containing-sexp)
9951 (point)) 9964 (cons (point) inexpr-brace-list))
9952 ((and after-type-id-pos 9965 ((and after-type-id-pos
9953 (save-excursion 9966 (save-excursion
9954 (when (eq (char-after) ?\;) 9967 (when (eq (char-after) ?\;)
9955 (c-forward-token-2 1 t)) 9968 (c-forward-token-2 1 t))
9956 (setq bufpos (point)) 9969 (setq bufpos (point))
9957 (when (looking-at c-opt-<>-sexp-key) 9970 (when (looking-at c-opt-<>-sexp-key)
9958 (c-forward-token-2) 9971 (c-forward-token-2)
9959 (when (and (eq (char-after) ?<) 9972 (when (and (eq (char-after) ?<)
9960 (c-get-char-property (point) 'syntax-table)) 9973 (c-get-char-property (point) 'syntax-table))
9961 (c-go-list-forward nil after-type-id-pos) 9974 (c-go-list-forward nil after-type-id-pos)
9962 (c-forward-syntactic-ws))) 9975 (c-forward-syntactic-ws)))
9963 (and 9976 (and
9964 (or (not (looking-at c-class-key)) 9977 (or (not (looking-at c-class-key))
9965 (save-excursion 9978 (save-excursion
9966 (goto-char (match-end 1)) 9979 (goto-char (match-end 1))
9967 (c-forward-syntactic-ws) 9980 (c-forward-syntactic-ws)
9968 (not (eq (point) after-type-id-pos)))) 9981 (not (eq (point) after-type-id-pos))))
9969 (progn 9982 (progn
9970 (setq res 9983 (setq res
9971 (c-forward-decl-or-cast-1 9984 (c-forward-decl-or-cast-1
9972 (save-excursion (c-backward-syntactic-ws) (point)) 9985 (save-excursion (c-backward-syntactic-ws) (point))
9973 nil nil)) 9986 nil nil))
9974 (and (consp res) 9987 (and (consp res)
9975 (eq (car res) after-type-id-pos)))))) 9988 (eq (car res) after-type-id-pos))))))
9976 bufpos) 9989 (cons bufpos inexpr-brace-list))
9977 ((eq (char-after) ?\;) 9990 ((eq (char-after) ?\;)
9978 ;; Brace lists can't contain a semicolon, so we're done. 9991 ;; Brace lists can't contain a semicolon, so we're done.
9979 ;; (setq containing-sexp nil) 9992 ;; (setq containing-sexp nil)
9980 nil) 9993 nil)
9981 ((and (setq macro-start (point)) 9994 ((and (setq macro-start (point))
9982 (c-forward-to-cpp-define-body) 9995 (c-forward-to-cpp-define-body)
9983 (eq (point) start)) 9996 (eq (point) start))
9984 ;; We've a macro whose expansion starts with the '{'. 9997 ;; We've a macro whose expansion starts with the '{'.
9985 ;; Heuristically, if we have a ';' in it we've not got a 9998 ;; Heuristically, if we have a ';' in it we've not got a
9986 ;; brace list, otherwise we have. 9999 ;; brace list, otherwise we have.
9987 (let ((macro-end (progn (c-end-of-macro) (point)))) 10000 (let ((macro-end (progn (c-end-of-macro) (point))))
9988 (goto-char start) 10001 (goto-char start)
9989 (forward-char) 10002 (forward-char)
9990 (if (and (c-syntactic-re-search-forward "[;,]" macro-end t t) 10003 (if (and (c-syntactic-re-search-forward "[;,]" macro-end t t)
9991 (eq (char-before) ?\;)) 10004 (eq (char-before) ?\;))
9992 nil 10005 nil
9993 macro-start))) 10006 (cons macro-start nil)))) ; (2016-08-30): Lazy! We have no
9994 (t t)) ;; The caller can go up one level. 10007 ; languages where
10008 ; `c-opt-inexpr-brace-list-key' is
10009 ; non-nil and we have macros.
10010 (t t))) ;; The caller can go up one level.
9995 ))) 10011 )))
9996 10012
9997(defun c-inside-bracelist-p (containing-sexp paren-state) 10013(defun c-inside-bracelist-p (containing-sexp paren-state)
@@ -10040,7 +10056,7 @@ comment at the start of cc-engine.el for more info."
10040 (setq containing-sexp next-containing 10056 (setq containing-sexp next-containing
10041 lim nil 10057 lim nil
10042 next-containing nil)))) 10058 next-containing nil))))
10043 (and (numberp bufpos) bufpos))))) 10059 (and (consp bufpos) (car bufpos))))))
10044 10060
10045(defun c-looking-at-special-brace-list (&optional lim) 10061(defun c-looking-at-special-brace-list (&optional lim)
10046 ;; If we're looking at the start of a pike-style list, i.e., `({ })', 10062 ;; If we're looking at the start of a pike-style list, i.e., `({ })',
@@ -10688,7 +10704,7 @@ comment at the start of cc-engine.el for more info."
10688 10704
10689 ;; CASE B.2: brace-list-open 10705 ;; CASE B.2: brace-list-open
10690 ((or (consp special-brace-list) 10706 ((or (consp special-brace-list)
10691 (numberp 10707 (consp
10692 (c-looking-at-or-maybe-in-bracelist 10708 (c-looking-at-or-maybe-in-bracelist
10693 containing-sexp beg-of-same-or-containing-stmt)) 10709 containing-sexp beg-of-same-or-containing-stmt))
10694 ) 10710 )
@@ -11231,42 +11247,18 @@ comment at the start of cc-engine.el for more info."
11231 11247
11232 ;; CASE 5A.3: brace list open 11248 ;; CASE 5A.3: brace list open
11233 ((save-excursion 11249 ((save-excursion
11234 (c-beginning-of-decl-1 lim) 11250 (goto-char indent-point)
11235 (while (cond 11251 (skip-chars-forward " \t")
11236 ((looking-at c-specifier-key) 11252 (cond
11237 (c-forward-keyword-clause 1)) 11253 ((c-backward-over-enum-header)
11238 ((and c-opt-cpp-prefix 11254 (setq placeholder (c-point 'boi)))
11239 (looking-at c-noise-macro-with-parens-name-re)) 11255 ((consp (setq placeholder
11240 (c-forward-noise-clause)))) 11256 (c-looking-at-or-maybe-in-bracelist
11241 (setq placeholder (c-point 'boi)) 11257 containing-sexp lim)))
11242 (or (consp special-brace-list) 11258 (setq tmpsymbol (and (cdr placeholder) 'topmost-intro-cont))
11243 (and (or (save-excursion 11259 (setq placeholder (c-point 'boi (car placeholder))))))
11244 (goto-char indent-point)
11245 (setq tmpsymbol nil)
11246 (while (and (> (point) placeholder)
11247 (zerop (c-backward-token-2 1 t))
11248 (not (looking-at "=\\([^=]\\|$\\)")))
11249 (and c-opt-inexpr-brace-list-key
11250 (not tmpsymbol)
11251 (looking-at c-opt-inexpr-brace-list-key)
11252 (setq tmpsymbol 'topmost-intro-cont)))
11253 (looking-at "=\\([^=]\\|$\\)"))
11254 (looking-at c-brace-list-key)
11255 (looking-at c-return-key)
11256 (save-excursion
11257 (and (c-forward-type)
11258 (looking-at c-identifier-start)
11259 (not (looking-at c-keywords-regexp))
11260 (c-forward-token-2)
11261 (eq (point) (c-point 'boi indent-point)))))
11262 (save-excursion
11263 (while (and (< (point) indent-point)
11264 (zerop (c-forward-token-2 1 t))
11265 (not (memq (char-after) '(?\; ?\()))))
11266 (not (memq (char-after) '(?\; ?\()))
11267 ))))
11268 (if (and (not c-auto-newline-analysis) 11260 (if (and (not c-auto-newline-analysis)
11269 (c-major-mode-is 'java-mode) 11261 ;(c-major-mode-is 'java-mode) ; Not needed anymore (2016-08-30).
11270 (eq tmpsymbol 'topmost-intro-cont)) 11262 (eq tmpsymbol 'topmost-intro-cont))
11271 ;; We're in Java and have found that the open brace 11263 ;; We're in Java and have found that the open brace
11272 ;; belongs to a "new Foo[]" initialization list, 11264 ;; belongs to a "new Foo[]" initialization list,
diff --git a/lisp/progmodes/cc-fonts.el b/lisp/progmodes/cc-fonts.el
index bf8b857ca6e..a23dddf214e 100644
--- a/lisp/progmodes/cc-fonts.el
+++ b/lisp/progmodes/cc-fonts.el
@@ -1261,12 +1261,12 @@ casts and declarations are fontified. Used on level 2 and higher."
1261 c-restricted-<>-arglists nil) 1261 c-restricted-<>-arglists nil)
1262 (c-put-char-property (1- match-pos) 'c-type 1262 (c-put-char-property (1- match-pos) 'c-type
1263 'c-decl-arg-start)) 1263 'c-decl-arg-start))
1264 ;; We're inside an brace list. 1264 ;; We're inside a brace list.
1265 ((and (eq (char-before match-pos) ?{) 1265 ((and (eq (char-before match-pos) ?{)
1266 (save-excursion 1266 (save-excursion
1267 (goto-char (1- match-pos)) 1267 (goto-char (1- match-pos))
1268 (numberp 1268 (consp
1269 (c-looking-at-or-maybe-in-bracelist nil)))) 1269 (c-looking-at-or-maybe-in-bracelist))))
1270 (setq context 'not-decl 1270 (setq context 'not-decl
1271 c-restricted-<>-arglists nil) 1271 c-restricted-<>-arglists nil)
1272 (c-put-char-property (1- match-pos) 'c-type 1272 (c-put-char-property (1- match-pos) 'c-type
diff --git a/lisp/progmodes/cc-mode.el b/lisp/progmodes/cc-mode.el
index 5b324d6d24c..f2c62563c5f 100644
--- a/lisp/progmodes/cc-mode.el
+++ b/lisp/progmodes/cc-mode.el
@@ -1406,7 +1406,7 @@ Note that the style variables are always made local to the buffer."
1406 (and (eq (char-before) ?{) 1406 (and (eq (char-before) ?{)
1407 (save-excursion 1407 (save-excursion
1408 (backward-char) 1408 (backward-char)
1409 (numberp (c-looking-at-or-maybe-in-bracelist nil)))) 1409 (consp (c-looking-at-or-maybe-in-bracelist))))
1410 ))) 1410 )))
1411 (not (bobp))) 1411 (not (bobp)))
1412 (backward-char)) ; back over (, [, <. 1412 (backward-char)) ; back over (, [, <.