From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Daniel Colascione Newsgroups: gmane.emacs.devel Subject: "enum class" supports for cc-mode Date: Mon, 27 Oct 2014 18:36:09 +0000 Message-ID: <544E9099.7030409@dancol.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="jMpIOlHe16P7RwemNVWlGssOMift2bkgk" X-Trace: ger.gmane.org 1414435005 2804 80.91.229.3 (27 Oct 2014 18:36:45 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 27 Oct 2014 18:36:45 +0000 (UTC) To: Emacs developers , Alan Mackenzie Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Oct 27 19:36:39 2014 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Xip9f-0006TS-JL for ged-emacs-devel@m.gmane.org; Mon, 27 Oct 2014 19:36:35 +0100 Original-Received: from localhost ([::1]:35473 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xip9f-00071y-7h for ged-emacs-devel@m.gmane.org; Mon, 27 Oct 2014 14:36:35 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:43634) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xip9W-0006w7-NP for emacs-devel@gnu.org; Mon, 27 Oct 2014 14:36:33 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Xip9Q-0008T9-Bo for emacs-devel@gnu.org; Mon, 27 Oct 2014 14:36:26 -0400 Original-Received: from dancol.org ([2600:3c01::f03c:91ff:fedf:adf3]:44529) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xip9Q-0008SZ-0J for emacs-devel@gnu.org; Mon, 27 Oct 2014 14:36:20 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=dancol.org; s=x; h=Content-Type:Subject:To:MIME-Version:From:Date:Message-ID; bh=1M8qKdGTbQaPv8Ev7JjQ92gsN0T9CGRWgpFR74caE4s=; b=GklV2xIV2Xau5PSgBEo4te/Pi0a2Jftimb4BdoxbHFppcX/8F0aPS/VWCtio0xlr5P6BWwxPk6RWtLgTmPOyA6/TosPl93NrcIieeXpi1drqRjTx+Cuj3ZAeeGS5yu3A7XQSiqyTsHOy8j/wzUE6wUX16E8yVLPMEAmNMBBQJ0pdXajX1dfYIiU9SghLHkvSCrXO1JP4YvBiN0zHztECU7B1rVZCjnYGa9z//aHD0P3y/j5mAoAUJJ757aoEssHYvc2Buw7uhH58263anzE3GHoNTJGhFRpvaj/bitVmik3iFwnOi2GQjPArZGYmqL2NvfBjr2DoIa9e1p62Sb1d2Q==; Original-Received: from [195.89.19.114] (helo=[172.17.184.132]) by dancol.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.84) (envelope-from ) id 1Xip9N-00017U-Se; Mon, 27 Oct 2014 11:36:18 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.2.0 X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2600:3c01::f03c:91ff:fedf:adf3 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:175902 Archived-At: This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --jMpIOlHe16P7RwemNVWlGssOMift2bkgk Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Here's a small patch that teaches cc-mode about C++11 "enum class" syntax= =2E See http://msdn.microsoft.com/en-us/library/2dzy4k6e.aspx Alan, can you take a look? =3D=3D=3D modified file 'lisp/progmodes/cc-engine.el' --- lisp/progmodes/cc-engine.el 2014-10-18 10:02:59 +0000 +++ lisp/progmodes/cc-engine.el 2014-10-27 18:00:51 +0000 @@ -8460,28 +8460,41 @@ (cond ((c-syntactic-re-search-forward c-decl-block-key open-brace t t t) (goto-char (setq kwd-start (match-beginning 0))) - (or - - ;; Found a keyword that can't be a type? - (match-beginning 1) - - ;; Can be a type too, in which case it's the return type of a - ;; function (under the assumption that no declaration level - ;; block construct starts with a type). - (not (c-forward-type)) - - ;; Jumped over a type, but it could be a declaration keyword - ;; followed by the declared identifier that we've jumped over - ;; instead (e.g. in "class Foo {"). If it indeed is a type - ;; then we should be at the declarator now, so check for a - ;; valid declarator start. - ;; - ;; Note: This doesn't cope with the case when a declared - ;; identifier is followed by e.g. '(' in a language where '(' - ;; also might be part of a declarator expression. Currently - ;; there's no such language. - (not (or (looking-at c-symbol-start) - (looking-at c-type-decl-prefix-key))))) + (and + ;; Exclude cases where we matched what would ordinarily + ;; be a block declaration keyword, except where it's not + ;; legal because it's part of a "compound keyword" like + ;; "enum class". Of course, if c-after-brace-list-key + ;; is nil, we can skip the test. + (or (null c-after-brace-list-key) + (save-match-data + (save-excursion + (not + (and + (looking-at c-after-brace-list-key) + (=3D (c-backward-token-2 1 t) 0) + (looking-at c-brace-list-key)))))) + (or + ;; Found a keyword that can't be a type? + (match-beginning 1) + + ;; Can be a type too, in which case it's the return type = of a + ;; function (under the assumption that no declaration lev= el + ;; block construct starts with a type). + (not (c-forward-type)) + + ;; Jumped over a type, but it could be a declaration keyw= ord + ;; followed by the declared identifier that we've jumped = over + ;; instead (e.g. in "class Foo {"). If it indeed is a ty= pe + ;; then we should be at the declarator now, so check for = a + ;; valid declarator start. + ;; + ;; Note: This doesn't cope with the case when a declared + ;; identifier is followed by e.g. '(' in a language where= '(' + ;; also might be part of a declarator expression. Curren= tly + ;; there's no such language. + (not (or (looking-at c-symbol-start) + (looking-at c-type-decl-prefix-key)))))) =20 ;; In Pike a list of modifiers may be followed by a brace ;; to make them apply to many identifiers. Note that the @@ -8586,9 +8599,35 @@ (not (looking-at "=3D"))))) b-pos))) =20 +(defun c-backward-colon-prefixed-type () + ;; We're after what might be a type prefixed with a colon. Try + ;; moving backward over this type and the colon. On success, return + ;; t and leave point before colon, on falure, leave point unchanged. + ;; Will clobber match data. + (let ((colon-pos nil)) + (save-excursion + (while + (and (eql (c-backward-token-2) 0) + (or (not (looking-at "\\s)")) + (c-go-up-list-backward)) + (cond + ((eql (char-after) ?:) + (setq colon-pos (point)) + nil) + ((eql (char-after) ?\() + t) + ((looking-at c-symbol-key) + t) + (t nil))))) + (when colon-pos + (goto-char colon-pos) + t))) + (defun c-backward-over-enum-header () ;; We're at a "{". Move back to the enum-like keyword that starts thi= s ;; declaration and return t, otherwise don't move and return nil. + (when c-recognize-post-brace-list-type-p + (c-backward-colon-prefixed-type)) (let ((here (point)) up-sexp-pos before-identifier) (while @@ -8596,21 +8635,22 @@ (eq (c-backward-token-2) 0) (or (not (looking-at "\\s)")) (c-go-up-list-backward)) - (cond - ((and (looking-at c-symbol-key) (c-on-identifier) - (not before-identifier)) - (setq before-identifier t)) - ((and before-identifier - (or (eq (char-after) ?,) - (looking-at c-postfix-decl-spec-key))) - (setq before-identifier nil) - t) - ((looking-at c-brace-list-key) nil) - ((and c-recognize-<>-arglists - (eq (char-after) ?<) - (looking-at "\\s(")) - t) - (t nil)))) + (cond + ((and (looking-at c-symbol-key) (c-on-identifier) + (not before-identifier)) + (setq before-identifier t)) + ((and before-identifier + (or (eql (char-after) ?,) + (looking-at c-postfix-decl-spec-key))) + (setq before-identifier nil) + t) + ((looking-at c-after-brace-list-key) t) + ((looking-at c-brace-list-key) nil) + ((and c-recognize-<>-arglists + (eq (char-after) ?<) + (looking-at "\\s(")) + t) + (t nil)))) (or (looking-at c-brace-list-key) (progn (goto-char here) nil)))) =20 =3D=3D=3D modified file 'lisp/progmodes/cc-langs.el' --- lisp/progmodes/cc-langs.el 2014-10-12 20:09:15 +0000 +++ lisp/progmodes/cc-langs.el 2014-10-27 17:34:41 +0000 @@ -1805,8 +1805,31 @@ ;; Regexp matching the start of declarations where the following ;; block is a brace list. t (c-make-keywords-re t (c-lang-const c-brace-list-decl-kwds))) + (c-lang-defvar c-brace-list-key (c-lang-const c-brace-list-key)) =20 +(c-lang-defconst c-after-brace-list-decl-kwds + "Keywords that might follow keywords in `c-brace-list-decl-kwds' +and precede the opening brace." + t nil + c++ '("class" "struct")) + +(c-lang-defconst c-after-brace-list-key + ;; Regexp matching keywords that can fall between a brace-list + ;; keyword and the associated brace list. + t (c-make-keywords-re t (c-lang-const c-after-brace-list-decl-kwds))) + +(c-lang-defvar c-after-brace-list-key (c-lang-const c-after-brace-list-k= ey)) + +(c-lang-defconst c-recognize-post-brace-list-type-p + ;; Recognize a colon and then a type after an enum, e.g., + ;; enum foo : int { A, B, C }; + t nil + c++ t) + +(c-lang-defvar c-recognize-post-brace-list-type-p + (c-lang-const c-recognize-post-brace-list-type-p)) + (c-lang-defconst c-other-block-decl-kwds "Keywords where the following block (if any) contains another declaration level that should not be considered a class. For every @@ -2000,6 +2023,7 @@ ;; prefixes. t (delete-duplicates (append (c-lang-const c-class-decl-kwds) (c-lang-const c-brace-list-decl-kwds) + (c-lang-const c-after-brace-list-decl-kwd= s) (c-lang-const c-other-block-decl-kwds) (c-lang-const c-typedef-decl-kwds) (c-lang-const c-typeless-decl-kwds) --jMpIOlHe16P7RwemNVWlGssOMift2bkgk Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQIcBAEBCAAGBQJUTpCZAAoJEN4WImmbpWBlifoP/2YGAp59pSEAp1IKz+UJAHjd HTc0hM+01WJtGmSt6713KhwQxUvskqtilecOTvQqMmCqYt2qhPgifw3eQKW3OlOP Rkw7v/8BsukiVjWlWFoVjQVAk4Kny2WI9W0uZyMVUk6GaooS0z2LAwpzoLyqe0Qx uitgYc657zrLhMiq6MM1ieQpQZAuxULCBethZ6IIF8cBcK3XEtZZ9zGdd278fkyI ezZD0TYH6nEoOgW+sP2ktN9B4Uz3qQED30L4RcRrVUAjew2iIqU6b617OKwCjJnh Ry2vjqIl3U2jiJ7PJ40eujylb4cS1L3egCFHE053JTSAF/nNGAQU8kkEgOUN1mi4 xAoM0CS8HTAoKji7EFue+yBSNjfrLUFgEwaJJ6ngBMvp2zlXLaxDeJYKrEvV7j7X ihU2On9wQqKIyH7z+SOPdbWyVYqvmRRmxXJOQYjeav/mBVmro2YsJerufF1B6Tv7 VIMFPCxc6HbKV/3UFmx32q73dPmNRRZixaaO5geGEG4jfYIASpj7I4LjeYJ2pU3E 0l8IvqGmaYDMCgc6A5N+gY2R9ZnKQyLM1LHSfX5FCjkjENKERc/emJuSZQUnts7E LXJ//7sPJba0IQCvw3InwdM3EXNgRxA6b8EEw6anRhPIB6yIgitegZpaP+BnmcIX G6b7eeF9xidFc2PQnvOj =hwN6 -----END PGP SIGNATURE----- --jMpIOlHe16P7RwemNVWlGssOMift2bkgk--