emacs-pretest-bug
[Top][All Lists]
Advanced

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

Re: C indentation error.


From: Alan Mackenzie
Subject: Re: C indentation error.
Date: Mon, 3 Apr 2006 14:50:02 +0000 (GMT)

Hi, Michael, Tim and Richard!

On Sun, 19 Mar 2006, Michael Cadilhac wrote:

>>     >   I got an  error with some C indentation in  macro definitions in GNU
>>     >  Emacs 22.0.50.34 (i686-pc-linux-gnu, X toolkit, Xaw3d scroll bars) of
>>     >  2006-03-02.

>>     >   Error is triggered by:

>>     >   With emacs -Q :
>>     >   In scratch, insert the following:

>>     > #foo :\
>>     > bar

>>     >   Toggle to c-mode, and try to indent the last line.

>>     >   I get: Invalid search bound (wrong side of point).

, and on Fri, 24 Feb 2006, Tim Millet wrote:

> The following typedef describes the problem.  It shows that when the
> struct member is of a user defined type, the bitfield specification
> causes the line syntax to be mistaken.  The first struct member uses a
> builtin type and the indentation is correct.  This problem didn't occur
> in version 5.28

> typedef struct {
>      int chanCnt:5;                       // correct indentation
> u_char_t chanCntRsvd:3;     // INCORRECT indentation
> } CbChanCnt_t;

The following patch should fix both of these bugs.  :-)  Would you please
try it out and get back to me on address@hidden if it doesn't.

Unless there are problems with it, I will release this fix with the next
CC Mode release (5.31.4), whence it will find its way into the Emacs CVS
at savannah.gnu.org.


*** ../cc-mode-5.32.cvs/cc-engine.el    Sun Feb 19 11:19:05 2006
--- cc-engine.el        Sun Apr  2 15:35:42 2006
***************
*** 5791,5807 ****
        nil))))
  
  (defun c-forward-label (&optional assume-markup preceding-token-end limit)
!   ;; Assuming the point is at the beginning of a token, check if it
!   ;; starts a label and if so move over it and return t, otherwise
!   ;; don't move and return nil.  The end of the label is taken to be
!   ;; the end of the first submatch in `c-opt-extra-label-key' if it
!   ;; matched, otherwise it's the colon.  The point is directly after
!   ;; the end on return.  The terminating char is marked with
!   ;; `c-decl-end' to improve recognition of the following declaration
!   ;; or statement.
    ;;
    ;; If ASSUME-MARKUP is non-nil, it's assumed that the preceding
!   ;; label, if any, has been marked up like that.
    ;;
    ;; If PRECEDING-TOKEN-END is given, it should be the first position
    ;; after the preceding token, i.e. on the other side of the
--- 5791,5822 ----
        nil))))
  
  (defun c-forward-label (&optional assume-markup preceding-token-end limit)
!   ;; Assuming the point is at the beginning of a token, check if it starts a
!   ;; label and if so move over it and return t, otherwise don't move and
!   ;; return nil.  "Label" here means "most things with a colon".
!   ;;
!   ;; More precisely, a "label" is regarded as one of:
!   ;; (i) a goto target like "foo:";
!   ;; (ii) A case label - either the entire construct "case FOO:" or just the
!   ;;   bare "case", should the colon be missing;
!   ;; (iii) a keyword which needs a colon, like "default:" or "private:";
!   ;; (iv) One of QT's "extended" C++ variants of
!   ;; "private:"/"protected:"/"public:"/"more:" looking like "public slots:".
!   ;; (v) One of the keywords matched by `c-opt-extra-label-key' (without any
!   ;;   colon).  Currently (2006-03), this applies only to Objective C's
!   ;;   keywords "@private", "@protected", and "@public".
!   ;;
!   ;; One of the things which will NOT be recognised as a label is a bit-field
!   ;; element of a struct, something like "int foo:5".
!   ;;
!   ;; The end of the label is taken to be just after the colon, or the end of
!   ;; the first submatch in `c-opt-extra-label-key'.  The point is directly
!   ;; after the end on return.  The terminating char gets marked with
!   ;; `c-decl-end' to improve recognition of the following declaration or
!   ;; statement.
    ;;
    ;; If ASSUME-MARKUP is non-nil, it's assumed that the preceding
!   ;; label, if any, has already been marked up like that.
    ;;
    ;; If PRECEDING-TOKEN-END is given, it should be the first position
    ;; after the preceding token, i.e. on the other side of the
***************
*** 5817,5824 ****
    ;;
    ;; This function might do hidden buffer changes.
  
!   (let ((start (point)))
      (cond
       ((looking-at c-label-kwds-regexp)
        (let ((kwd-end (match-end 1)))
        ;; Record only the keyword itself for fontification, since in
--- 5832,5842 ----
    ;;
    ;; This function might do hidden buffer changes.
  
!   (let ((start (point))
!       qt-symbol-idx
!       macro-start)                    ; if we're in one.
      (cond
+      ;; "case" or "default" (Doesn't apply to AWK). 
       ((looking-at c-label-kwds-regexp)
        (let ((kwd-end (match-end 1)))
        ;; Record only the keyword itself for fontification, since in
***************
*** 5838,5844 ****
                 (match-beginning 2))
  
            (progn
!             (goto-char (match-beginning 2))
              (c-put-c-type-property (1- (point)) 'c-decl-end)
              t)
  
--- 5856,5862 ----
                 (match-beginning 2))
  
            (progn
!             (goto-char (match-beginning 2)) ; just after the :
              (c-put-c-type-property (1- (point)) 'c-decl-end)
              t)
  
***************
*** 5849,5854 ****
--- 5867,5873 ----
          (goto-char kwd-end)
          t)))
  
+      ;; @private, @protected, @public, in Objective C, or similar.
       ((and c-opt-extra-label-key
           (looking-at c-opt-extra-label-key))
        ;; For a `c-opt-extra-label-key' match, we record the whole
***************
*** 5860,5866 ****
        (c-put-c-type-property (1- (point)) 'c-decl-end)
        t)
  
!      ((and c-recognize-colon-labels
  
           ;; A colon label must have something before the colon.
           (not (eq (char-after) ?:))
--- 5879,5886 ----
        (c-put-c-type-property (1- (point)) 'c-decl-end)
        t)
  
!      ;; All other cases of labels.
!      ((and c-recognize-colon-labels   ; nil for AWK and IDL, otherwise t.
  
           ;; A colon label must have something before the colon.
           (not (eq (char-after) ?:))
***************
*** 5905,5930 ****
  
                ((eq (char-before preceding-token-end) ?:)
                 ;; Might be after another label, so check it recursively.
!                (save-excursion
!                  (goto-char (1- preceding-token-end))
!                  ;; Essentially the same as the
!                  ;; `c-syntactic-re-search-forward' regexp below.
!                  (c-syntactic-skip-backward "^-]:?;}=*/%&|,<>address@hidden" 
nil t)
!                  (let ((pte (point))
!                        ;; If the caller turned on recording for us,
!                        ;; it shouldn't apply when we check the
!                        ;; preceding label.
!                        c-record-type-identifiers)
!                    (c-forward-syntactic-ws)
!                    (c-forward-label nil pte start))))))))
! 
!          ;; Check that the next nonsymbol token is ":".  Allow '('
!          ;; for the sake of macro arguments.  FIXME: Should build
!          ;; this regexp from the language constants.
!          (c-syntactic-re-search-forward
!           "[[:?;{=*/%&|,<>address@hidden" limit t t)
!          (eq (char-before) ?:)
!          (not (eq (char-after) ?:)))
  
        (save-restriction
        (narrow-to-region start (point))
--- 5925,5976 ----
  
                ((eq (char-before preceding-token-end) ?:)
                 ;; Might be after another label, so check it recursively.
!                (save-restriction
!                  (save-excursion
!                    (goto-char (1- preceding-token-end))
!                    ;; Essentially the same as the
!                    ;; `c-syntactic-re-search-forward' regexp below.
!                    (setq macro-start
!                          (save-excursion (and (c-beginning-of-macro)
!                                               (point))))
!                    (if macro-start (narrow-to-region macro-start (point-max)))
!                    (c-syntactic-skip-backward 
"^-]:?;}=*/%&|,<>address@hidden" nil t)
!                    ;; Note: the following should work instead of the
!                    ;; narrow-to-region above.  Investigate why not,
!                    ;; sometime.  ACM, 2006-03-31.
!                    ;; (c-syntactic-skip-backward 
"^-]:?;}=*/%&|,<>address@hidden"
!                    ;;                             macro-start t)
!                    (let ((pte (point))
!                          ;; If the caller turned on recording for us,
!                          ;; it shouldn't apply when we check the
!                          ;; preceding label.
!                          c-record-type-identifiers)
!                      ;; A label can't start at a cpp directive.  Check for
!                      ;; this, since c-forward-syntactic-ws would foul up on 
it.
!                      (unless (and c-opt-cpp-prefix (looking-at 
c-opt-cpp-prefix))
!                        (c-forward-syntactic-ws)
!                        (c-forward-label nil pte start))))))))))
! 
!          ;; Check that the next nonsymbol token is ":", or that we're in one
!          ;; of QT's "slots" declarations.  Allow '(' for the sake of macro
!          ;; arguments.  FIXME: Should build this regexp from the language
!          ;; constants.
!          (when (c-syntactic-re-search-forward
!                 "[ \t[:?;{=*/%&|,<>address@hidden" limit t t) ; not at EOB
!            (backward-char)
!            (setq qt-symbol-idx
!                  (and (c-major-mode-is 'c++-mode)
!                       (string-match
!                        "\\(p\\(r\\(ivate\\|otected\\)\\|ublic\\)\\|more\\)\\>"
!                        (buffer-substring start (point)))))
!            (c-forward-syntactic-ws limit)
!            (when (or (looking-at ":\\([^:]\\|\\'\\)") ; A single colon.
!                      (and qt-symbol-idx
!                           (search-forward-regexp "\\=slots\\>" limit t)
!                           (progn (c-forward-syntactic-ws limit)
!                                  (looking-at ":\\([^:]\\|\\'\\)")))) ; A 
single colon
!              (forward-char)           ; to after the colon.
!              t)))
  
        (save-restriction
        (narrow-to-region start (point))



-- 
Alan Mackenzie (Munich, Germany)






reply via email to

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