emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 62f239e: C++ Mode: handle __attribute__, etc. inside constructor


From: Alan Mackenzie
Subject: master 62f239e: C++ Mode: handle __attribute__, etc. inside constructor argument lists
Date: Sat, 12 Sep 2020 12:41:24 -0400 (EDT)

branch: master
commit 62f239eec2be42d857cc91009b4b7d8c8cf31b4e
Author: Alan Mackenzie <acm@muc.de>
Commit: Alan Mackenzie <acm@muc.de>

    C++ Mode: handle __attribute__,etc. inside constructor argument lists
    
    This corrects both the fontification and indentation of these things, fixing
    bug #42270.
    
    * lisp/progmodes/cc-engine.el (c-do-declarators): Skip over "hangon keys" 
and
    noise macros whilst scanning a putative C++ function.
    (c-forward-decl-or-cast-1): When checking for typeless functions, skip over
    "hangon keys" and noise macros.
    
    * lisp/progmodes/cc-mode.el (c-fl-decl-end): Deal with certain invalid
    "nested declarators" by scanning over them with a recursive call of
    c-fl-decl-end.
    
    * lisp/progmodes/cc-vars.el (c-noise-macro-names)
    (c-noise-macro-with-parens-names): State in the doc strings that if either 
of
    these is a regexp, it must have a submatch 1 which matches the noise macro
    exactly.
---
 lisp/progmodes/cc-engine.el | 18 +++++++++++++++++-
 lisp/progmodes/cc-mode.el   | 34 +++++++++++++++++++++++++++-------
 lisp/progmodes/cc-vars.el   |  6 ++++--
 3 files changed, 48 insertions(+), 10 deletions(-)

diff --git a/lisp/progmodes/cc-engine.el b/lisp/progmodes/cc-engine.el
index 7ff424c..7d10027 100644
--- a/lisp/progmodes/cc-engine.el
+++ b/lisp/progmodes/cc-engine.el
@@ -2238,7 +2238,7 @@ comment at the start of cc-engine.el for more info."
 
             ((and c-opt-cpp-prefix
                   (looking-at c-noise-macro-name-re))
-             ;; Skip over a noise macro.
+             ;; Skip over a noise macro without parens.
              (goto-char (match-end 1))
              (not (eobp)))
 
@@ -9130,6 +9130,12 @@ This function might do hidden buffer changes."
                                  (catch 'is-function
                                    (while
                                        (progn
+                                         (while
+                                             (cond
+                                              ((looking-at c-decl-hangon-key)
+                                               (c-forward-keyword-clause 1))
+                                              ((looking-at 
c-noise-macro-with-parens-name-re)
+                                               (c-forward-noise-clause))))
                                          (if (eq (char-after) ?\))
                                              (throw 'is-function t))
                                          (setq cdd-got-type (c-forward-type))
@@ -9782,6 +9788,16 @@ This function might do hidden buffer changes."
                                  (save-excursion
                                    (goto-char after-paren-pos)
                                    (c-forward-syntactic-ws)
+                                   (progn
+                                     (while
+                                         (cond
+                                          ((and
+                                            c-opt-cpp-prefix
+                                            (looking-at 
c-noise-macro-with-parens-name-re))
+                                           (c-forward-noise-clause))
+                                          ((looking-at c-decl-hangon-key)
+                                           (c-forward-keyword-clause 1))))
+                                     t)
                                    (or (c-forward-type)
                                        ;; Recognize a top-level typeless
                                        ;; function declaration in C.
diff --git a/lisp/progmodes/cc-mode.el b/lisp/progmodes/cc-mode.el
index 73275cf..c6dd671 100644
--- a/lisp/progmodes/cc-mode.el
+++ b/lisp/progmodes/cc-mode.el
@@ -2266,7 +2266,8 @@ Note that this is a strict tail, so won't match, e.g. 
\"0x....\".")
 (defun c-fl-decl-end (pos)
   ;; If POS is inside a declarator, return the end of the token that follows
   ;; the declarator, otherwise return nil.  POS being in a literal does not
-  ;; count as being in a declarator (on pragmatic grounds).
+  ;; count as being in a declarator (on pragmatic grounds).  POINT is not
+  ;; preserved.
   (goto-char pos)
   (let ((lit-start (c-literal-start))
        enclosing-attribute pos1)
@@ -2279,12 +2280,31 @@ Note that this is a strict tail, so won't match, e.g. 
\"0x....\".")
        (let ((lim (save-excursion
                     (and (c-beginning-of-macro)
                          (progn (c-end-of-macro) (point))))))
-         (when (and (c-forward-declarator lim)
-                    (or (not (eq (char-after) ?\())
-                        (c-go-list-forward nil lim))
-                    (eq (c-forward-token-2 1 nil lim) 0))
-           (c-backward-syntactic-ws)
-           (point)))))))
+         (and (c-forward-declarator lim)
+              (if (eq (char-after) ?\()
+                  (and
+                   (c-go-list-forward nil lim)
+                   (progn (c-forward-syntactic-ws lim)
+                          (not (eobp)))
+                   (progn
+                     (if (looking-at c-symbol-char-key)
+                         ;; Deal with baz (foo((bar)) type var), where
+                         ;; foo((bar)) is not semantically valid.  The result
+                         ;; must be after var).
+                         (and
+                          (goto-char pos)
+                          (setq pos1 (c-on-identifier))
+                          (goto-char pos1)
+                          (progn
+                            (c-backward-syntactic-ws)
+                            (eq (char-before) ?\())
+                          (c-fl-decl-end (1- (point))))
+                       (c-backward-syntactic-ws)
+                       (point))))
+                (and (progn (c-forward-syntactic-ws lim)
+                            (not (eobp)))
+                     (c-backward-syntactic-ws)
+                     (point)))))))))
 
 (defun c-change-expand-fl-region (_beg _end _old-len)
   ;; Expand the region (c-new-BEG c-new-END) to an after-change font-lock
diff --git a/lisp/progmodes/cc-vars.el b/lisp/progmodes/cc-vars.el
index b885f6a..9e6f952 100644
--- a/lisp/progmodes/cc-vars.el
+++ b/lisp/progmodes/cc-vars.el
@@ -1670,7 +1670,8 @@ indented as a statement."
 like \"INLINE\" which are syntactic noise.  Such a macro/extension is complete
 in itself, never having parentheses.  All these names must be syntactically
 valid identifiers.  Alternatively, this variable may be a regular expression
-which matches the names of such macros.
+which matches the names of such macros, in which case it must have a submatch
+1 which matches the actual noise macro name.
 
 If you change this variable's value, call the function
 `c-make-noise-macro-regexps' to set the necessary internal variables (or do
@@ -1686,7 +1687,8 @@ this implicitly by reinitializing C/C++/Objc Mode on any 
buffer)."
 which optionally have arguments in parentheses, and which expand to nothing.
 All these names must be syntactically valid identifiers.  These are recognized
 by CC Mode only in declarations.  Alternatively, this variable may be a
-regular expression which matches the names of such macros.
+regular expression which matches the names of such macros, in which case it
+must have a submatch 1 which matches the actual noise macro name.
 
 If you change this variable's value, call the function
 `c-make-noise-macro-regexps' to set the necessary internal variables (or do



reply via email to

[Prev in Thread] Current Thread [Next in Thread]