Fix up comment convention on the arch-tag lines.
[bpt/emacs.git] / lisp / progmodes / cc-engine.el
index a019f59..d5a3103 100644 (file)
@@ -1,7 +1,7 @@
 ;;; cc-engine.el --- core syntax guessing engine for CC mode
 
 ;; Copyright (C) 1985, 1987, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
-;;   1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007
+;;   1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
 ;;   Free Software Foundation, Inc.
 
 ;; Authors:    2001- Alan Mackenzie
@@ -81,8 +81,9 @@
 ;; assume that these text properties are used as described here.
 ;;
 ;; 'syntax-table
-;;   Used to modify the syntax of some characters.  Currently used to
-;;   mark the "<" and ">" of angle bracket parens with paren syntax.
+;;   Used to modify the syntax of some characters.  It is used to
+;;   mark the "<" and ">" of angle bracket parens with paren syntax, and
+;;   to "hide" obtrusive characters in preprocessor lines.
 ;;
 ;;   This property is used on single characters and is therefore
 ;;   always treated as front and rear nonsticky (or start and end open
@@ -604,7 +605,7 @@ comment at the start of cc-engine.el for more info."
   ;;         (e.g. if).
   ;;
   ;;
-  ;; The following diagram briefly outlines the PDA.  
+  ;; The following diagram briefly outlines the PDA.
   ;;
   ;; Common state:
   ;;   "else": Push state, goto state `else'.
@@ -1079,7 +1080,7 @@ single `?' is found, then `c-maybe-labelp' is cleared.
 
 For AWK, a statement which is terminated by an EOL (not a \; or a }) is
 regarded as having a \"virtual semicolon\" immediately after the last token on
-the line.  If this virtual semicolon is _at_ from, the function recognises it.
+the line.  If this virtual semicolon is _at_ from, the function recognizes it.
 
 Note that this function might do hidden buffer changes.  See the
 comment at the start of cc-engine.el for more info."
@@ -1916,7 +1917,7 @@ comment at the start of cc-engine.el for more info."
 (defun c-partial-ws-p (beg end)
   ;; Is the region (beg end) WS, and is there WS (or BOB/EOB) next to the
   ;; region?  This is a "heuristic" function.  .....
-  ;; 
+  ;;
   ;; The motivation for the second bit is to check whether removing this
   ;; region would coalesce two symbols.
   ;;
@@ -3291,7 +3292,7 @@ comment at the start of cc-engine.el for more info."
 ;; The workaround for this is for the AWK Mode initialisation to switch the
 ;; defalias for c-in-literal to c-slow-in-literal.  This will slow down other
 ;; cc-modes in Xemacs whenever an awk-buffer has been initialised.
-;; 
+;;
 ;; (Alan Mackenzie, 2003/4/30).
 
 (defun c-fast-in-literal (&optional lim detect-cpp)
@@ -3406,7 +3407,7 @@ comment at the start of cc-engine.el for more info."
        (if (and (consp range) (progn
                                 (goto-char (car range))
                                 (looking-at c-line-comment-starter)))
-           (let ((col (current-column)) 
+           (let ((col (current-column))
                  (beg (point))
                  (bopl (c-point 'bopl))
                  (end (cdr range)))
@@ -4045,7 +4046,7 @@ comment at the start of cc-engine.el for more info."
   ;; example, this happens to "foo" when "foo \n bar();" becomes
   ;; "foo(); \n bar();".  Such stale types, if not removed, foul up
   ;; the fontification.
-  ;; 
+  ;;
   ;; Have we, perhaps, added non-ws characters to the front/back of a found
   ;; type?
   (when (> end beg)
@@ -4064,7 +4065,7 @@ comment at the start of cc-engine.el for more info."
                        (c-beginning-of-current-token)))
            (c-unfind-type (buffer-substring-no-properties
                            (point) beg))))))
-           
+
   (if c-maybe-stale-found-type ; e.g. (c-decl-id-start "foo" 97 107 " (* ooka) " "o")
       (cond
        ;; Changing the amount of (already existing) whitespace - don't do anything.
@@ -5094,7 +5095,8 @@ comment at the start of cc-engine.el for more info."
   ;;
   ;;   The point is left at the first token after the first complete
   ;;   declarator, if there is one.  The return value is a cons where
-  ;;   the car is the position of the first token in the declarator.
+  ;;   the car is the position of the first token in the declarator.  (See
+  ;;   below for the cdr.)
   ;;   Some examples:
   ;;
   ;;    void foo (int a, char *b) stuff ...
@@ -5118,9 +5120,9 @@ comment at the start of cc-engine.el for more info."
   ;;     Foo::Foo (int b) : Base (b) {}
   ;; car ^                ^ point
   ;;
-  ;;   The cdr of the return value is non-nil if a
-  ;;   `c-typedef-decl-kwds' specifier is found in the declaration,
-  ;;   i.e. the declared identifier(s) are types.
+  ;;   The cdr of the return value is non-nil iff a `c-typedef-decl-kwds'
+  ;;   specifier (e.g. class, struct, enum, typedef) is found in the
+  ;;   declaration, i.e. the declared identifier(s) are types.
   ;;
   ;; If a cast is parsed:
   ;;
@@ -5135,7 +5137,7 @@ comment at the start of cc-engine.el for more info."
   ;; the first token in (the visible part of) the buffer.
   ;;
   ;; CONTEXT is a symbol that describes the context at the point:
-  ;; 'decl     In a comma-separatded declaration context (typically
+  ;; 'decl     In a comma-separated declaration context (typically
   ;;           inside a function declaration arglist).
   ;; '<>       In an angle bracket arglist.
   ;; 'arglist  Some other type of arglist.
@@ -5929,7 +5931,7 @@ comment at the start of cc-engine.el for more info."
        macro-start                     ; if we're in one.
        label-type)
     (cond
-     ;; "case" or "default" (Doesn't apply to AWK). 
+     ;; "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
@@ -6048,7 +6050,7 @@ comment at the start of cc-engine.el for more info."
                         (c-forward-label nil pte start))))))))))
 
           ;; Point is still at the beginning of the possible label construct.
-          ;; 
+          ;;
           ;; 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
@@ -6074,7 +6076,7 @@ comment at the start of cc-engine.el for more info."
                     (and (c-major-mode-is 'c++-mode)
                          (string-match
                           "\\(p\\(r\\(ivate\\|otected\\)\\|ublic\\)\\|more\\)\\>"
-                          (buffer-substring start (point)))))  
+                          (buffer-substring start (point)))))
               (c-forward-syntactic-ws limit)
               (cond
                ((looking-at ":\\([^:]\\|\\'\\)") ; A single colon.
@@ -6334,7 +6336,8 @@ comment at the start of cc-engine.el for more info."
       ;; the searchable range.
       (let* ((macro-start (c-query-macro-start))
             (lim (max (or lim (point-min)) (or macro-start (point-min))))
-            before-lparen after-rparen)
+            before-lparen after-rparen
+            (pp-count-out 20)) ; Max number of paren/brace constructs before we give up
        (narrow-to-region lim (c-point 'eol))
 
        ;; Search backwards for the defun's argument list.  We give up if we
@@ -6356,7 +6359,8 @@ comment at the start of cc-engine.el for more info."
        ;; {
 
        (catch 'knr
-         (while t ; go round one paren/bracket construct each time round.
+         (while (> pp-count-out 0) ; go back one paren/bracket pair each time.
+           (setq pp-count-out (1- pp-count-out))
            (c-syntactic-skip-backward "^)]}")
            (cond ((eq (char-before) ?\))
                   (setq after-rparen (point)))
@@ -7238,7 +7242,7 @@ comment at the start of cc-engine.el for more info."
   ;; needed with further syntax elements of the types `substatement',
   ;; `inexpr-statement', `arglist-cont-nonempty', `statement-block-intro', and
   ;; `defun-block-intro'.
-  ;; 
+  ;;
   ;; Do the generic processing to anchor the given syntax symbol on
   ;; the preceding statement: Skip over any labels and containing
   ;; statements on the same line, and then search backward until we
@@ -7424,7 +7428,7 @@ comment at the start of cc-engine.el for more info."
                                 c-other-decl-block-key-in-symbols-alist))
                     (max (c-point 'boi paren-pos) (point))))
                   (t (c-add-syntax 'defun-block-intro nil))))
-                            
+
                 (c-add-syntax 'statement-block-intro nil)))
 
          (if (= paren-pos boi)
@@ -8032,12 +8036,15 @@ comment at the start of cc-engine.el for more info."
 
             ;; CASE 5A.5: ordinary defun open
             (t
-             (goto-char placeholder)
-             (if (or containing-decl-open macro-start)
-                 (c-add-syntax 'defun-open (c-point 'boi))
-               ;; Bogus to use bol here, but it's the legacy.
-               (c-add-syntax 'defun-open (c-point 'bol)))
-             )))
+             (save-excursion
+               (c-beginning-of-decl-1 lim)
+               (while (looking-at c-specifier-key)
+                 (goto-char (match-end 1))
+                 (c-forward-syntactic-ws indent-point))
+               (c-add-syntax 'defun-open (c-point 'boi))
+               ;; Bogus to use bol here, but it's the legacy.  (Resolved,
+               ;; 2007-11-09)
+               ))))
 
           ;; CASE 5B: After a function header but before the body (or
           ;; the ending semicolon if there's no body).
@@ -8264,7 +8271,7 @@ comment at the start of cc-engine.el for more info."
                 'statement-cont)
               nil nil containing-sexp paren-state))
             ))
-          
+
           ;; CASE 5F: Close of a non-class declaration level block.
           ((and (eq char-after-ip ?})
                 (c-keyword-member containing-decl-kwd
@@ -8296,6 +8303,7 @@ comment at the start of cc-engine.el for more info."
 
           ;; CASE 5H: we could be looking at subsequent knr-argdecls
           ((and c-recognize-knr-p
+                (not containing-sexp)  ; can't be knr inside braces.
                 (not (eq char-before-ip ?}))
                 (save-excursion
                   (setq placeholder (cdr (c-beginning-of-decl-1 lim)))
@@ -9209,5 +9217,5 @@ Cannot combine absolute offsets %S and %S in `add' method"
 \f
 (cc-provide 'cc-engine)
 
-;;; arch-tag: 149add18-4673-4da5-ac47-6805e4eae089
+;; arch-tag: 149add18-4673-4da5-ac47-6805e4eae089
 ;;; cc-engine.el ends here