Add 2010 to copyright years.
[bpt/emacs.git] / lisp / cedet / semantic / bovine / c.el
index 9bcf6b1..1f8b96a 100644 (file)
@@ -1,7 +1,7 @@
 ;;; semantic/bovine/c.el --- Semantic details for C
 
 ;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
-;;   2008, 2009  Free Software Foundation, Inc.
+;;   2008, 2009, 2010  Free Software Foundation, Inc.
 
 ;; Author: Eric M. Ludlam <zappo@gnu.org>
 
@@ -74,7 +74,7 @@ This function does not do any hidden buffer changes."
 (defcustom-mode-local-semantic-dependency-system-include-path
   c-mode semantic-c-dependency-system-include-path
   '("/usr/include")
-  "The system include path used by the C langauge.")
+  "The system include path used by the C language.")
 
 (defcustom semantic-default-c-path nil
   "Default set of include paths for C code.
@@ -207,7 +207,7 @@ to store your global macros in a more natural way."
   )
 
 (defcustom semantic-c-member-of-autocast 't
-  "Non-nil means classes with a '->' operator will cast to it's return type.
+  "Non-nil means classes with a '->' operator will cast to its return type.
 
 For Examples:
 
@@ -228,7 +228,7 @@ if `semantic-c-member-of-autocast' is nil :
 (define-lex-spp-macro-declaration-analyzer semantic-lex-cpp-define
   "A #define of a symbol with some value.
 Record the symbol in the semantic preprocessor.
-Return the the defined symbol as a special spp lex token."
+Return the defined symbol as a special spp lex token."
   "^\\s-*#\\s-*define\\s-+\\(\\(\\sw\\|\\s_\\)+\\)" 1
   (goto-char (match-end 0))
   (skip-chars-forward " \t")
@@ -264,7 +264,7 @@ Return the the defined symbol as a special spp lex token."
 (define-lex-spp-macro-undeclaration-analyzer semantic-lex-cpp-undef
   "A #undef of a symbol.
 Remove the symbol from the semantic preprocessor.
-Return the the defined symbol as a special spp lex token."
+Return the defined symbol as a special spp lex token."
   "^\\s-*#\\s-*undef\\s-+\\(\\(\\sw\\|\\s_\\)+\\)" 1)
 
 \f
@@ -444,7 +444,7 @@ It is really there, but if a majority of uses is to squeeze out
 the second namespace in use, then it should not be included.
 
 If you are having problems with smart completion and STL templates,
-it may that this is set incorrectly.  After changing the value
+it may be that this is set incorrectly.  After changing the value
 of this flag, you will need to delete any semanticdb cache files
 that may have been incorrectly parsed."
   :group 'semantic
@@ -620,7 +620,7 @@ Use semantic-cpp-lexer for parsing text inside a CPP macro."
 
 (define-mode-local-override semantic-parse-region c-mode
   (start end &optional nonterminal depth returnonerror)
-  "Calls 'semantic-parse-region-default', except in a macro expansion.
+  "Calls `semantic-parse-region-default', except in a macro expansion.
 MACRO expansion mode is handled through the nature of Emacs's non-lexical
 binding of variables.
 START, END, NONTERMINAL, DEPTH, and RETURNONERRORS are the same
@@ -703,8 +703,7 @@ the regular parser."
         (symtext (semantic-lex-token-text lexicaltoken))
         (macros (get-text-property 0 'macros symtext))
         )
-    (save-excursion
-      (set-buffer buf)
+    (with-current-buffer buf
       (erase-buffer)
       (when (not (eq major-mode mode))
        (save-match-data
@@ -712,19 +711,26 @@ the regular parser."
          ;; Protect against user hooks throwing errors.
          (condition-case nil
              (funcall mode)
-           (error nil))
-
-         ;; Hack in mode-local
-         (activate-mode-local-bindings)
-         ;; CHEATER!  The following 3 lines are from
-         ;; `semantic-new-buffer-fcn', but we don't want to turn
-         ;; on all the other annoying modes for this little task.
-         (setq semantic-new-buffer-fcn-was-run t)
-         (semantic-lex-init)
-         (semantic-clear-toplevel-cache)
-         (remove-hook 'semantic-lex-reset-hooks 'semantic-lex-spp-reset-hook
-                      t)
-         ))
+           (error
+            (if (y-or-n-p
+                 (format "There was an error initializing %s in buffer \"%s\".  Debug your hooks? "
+                         mode (buffer-name)))
+                (semantic-c-debug-mode-init mode)
+              (message "Macro parsing state may be broken...")
+              (sit-for 1))))
+         ) ; save match data
+
+       ;; Hack in mode-local
+       (activate-mode-local-bindings)
+       ;; CHEATER!  The following 3 lines are from
+       ;; `semantic-new-buffer-fcn', but we don't want to turn
+       ;; on all the other annoying modes for this little task.
+       (setq semantic-new-buffer-fcn-was-run t)
+       (semantic-lex-init)
+       (semantic-clear-toplevel-cache)
+       (remove-hook 'semantic-lex-reset-hooks 'semantic-lex-spp-reset-hook
+                    t)
+       )
       ;; Get the macro symbol table right.
       (setq semantic-lex-spp-dynamic-macro-symbol-obarray spp-syms)
       ;; (message "%S" macros)
@@ -751,6 +757,41 @@ the regular parser."
       )
     stream))
 
+(defvar semantic-c-debug-mode-init-last-mode nil
+  "The most recent mode needing debugging.")
+
+(defun semantic-c-debug-mode-init (mm)
+  "Debug mode init for major mode MM after we're done parsing now."
+  (interactive (list semantic-c-debug-mode-init-last-mode))
+  (if (called-interactively-p 'interactive)
+      ;; Do the debug.
+      (progn
+       (switch-to-buffer (get-buffer-create "*MODE HACK TEST*"))
+       (let ((debug-on-error t))
+         (funcall mm)))
+
+    ;; Notify about the debug
+    (setq semantic-c-debug-mode-init-last-mode mm)
+
+    (add-hook 'post-command-hook 'semantic-c-debug-mode-init-pch)))
+
+(defun semantic-c-debug-mode-init-pch ()
+  "Notify user about needing to debug their major mode hooks."
+  (let ((mm semantic-c-debug-mode-init-last-mode))
+    (switch-to-buffer-other-window
+     (get-buffer-create "*MODE HACK TEST*"))
+    (erase-buffer)
+    (insert "A failure occurred while parsing your buffers.
+
+The failure occurred while attempting to initialize " (symbol-name mm) " in a
+buffer not associated with a file.  To debug this problem, type
+
+M-x semantic-c-debug-mode-init
+
+now.
+")
+    (remove-hook 'post-command-hook 'semantic-c-debug-mode-init-pch)))
+
 (defun semantic-expand-c-tag (tag)
   "Expand TAG into a list of equivalent tags, or nil."
   (let ((return-list nil)
@@ -926,7 +967,7 @@ the regular parser."
   "At parse time, assign a class or struct name text here.
 It is picked up by `semantic-c-reconstitute-token' to determine
 if something is a constructor.  Value should be:
-  ( TYPENAME .  TYPEOFTYPE)
+  (TYPENAME .  TYPEOFTYPE)
 where typename is the name of the type, and typeoftype is \"class\"
 or \"struct\".")
 
@@ -1217,7 +1258,7 @@ Optional PARENT and COLOR as specified with
 
 (define-mode-local-override semantic-format-tag-uml-prototype
   c-mode (token &optional parent color)
-  "Return an uml string describing TOKEN for C and C++.
+  "Return an UML string describing TOKEN for C and C++.
 Optional PARENT and COLOR as specified with
 `semantic-abbreviate-tag-default'."
   ;; If we have special template things, append.
@@ -1340,7 +1381,7 @@ TYPE-DECLARATION is passed through."
 (defun semantic-c-dereference-namespace (type scope &optional type-declaration)
   "Dereference namespace which might hold an 'alias' for TYPE.
 Such an alias can be created through 'using' statements in a
-namespace declaration. This function checks the namespaces in
+namespace declaration.  This function checks the namespaces in
 SCOPE for such statements."
   (let ((scopetypes (oref scope scopetypes))
        typename currentns tmp usingname result namespaces)
@@ -1477,7 +1518,7 @@ Handle typedef, template instantiation, and '->' operator."
     (list type type-declaration))
 
 (define-mode-local-override semantic-analyze-type-constants c-mode (type)
-  "When TYPE is a tag for an enum, return it's parts.
+  "When TYPE is a tag for an enum, return its parts.
 These are constants which are of type TYPE."
   (if (and (eq (semantic-tag-class type) 'type)
           (string= (semantic-tag-type type) "enum"))
@@ -1577,7 +1618,7 @@ DO NOT return the list of tags encompassing point."
       (semantic-idle-summary-current-symbol-info-default))))
 
 (defvar-mode-local c-mode semantic-orphaned-member-metaparent-type "struct"
-  "When lost memberes are found in the class hierarchy generator, use a struct.")
+  "When lost members are found in the class hierarchy generator, use a struct.")
 
 (defvar-mode-local c-mode semantic-symbol->name-assoc-list
   '((type     . "Types")
@@ -1603,7 +1644,7 @@ DO NOT return the list of tags encompassing point."
   "Separator characters between something of a given type, and a field.")
 
 (defvar-mode-local c-mode semantic-command-separation-character ";"
-  "Commen separation character for C")
+  "Command separation character for C.")
 
 (defvar-mode-local c-mode senator-step-at-tag-classes '(function variable)
   "Tag classes where senator will stop at the end.")
@@ -1718,6 +1759,24 @@ DO NOT return the list of tags encompassing point."
          (princ "\n")
          ))
 
+      (when (arrayp semantic-lex-spp-project-macro-symbol-obarray)
+       (princ "\n  Project symbol map:\n")
+       (princ "      Your project symbol map is derived from the EDE object:\n      ")
+       (princ (object-print ede-object))
+       (princ "\n\n")
+       (let ((macros nil))
+         (mapatoms
+          #'(lambda (symbol)
+              (setq macros (cons symbol macros)))
+          semantic-lex-spp-project-macro-symbol-obarray)
+         (dolist (S macros)
+           (princ "    ")
+           (princ (symbol-name S))
+           (princ " = ")
+           (princ (symbol-value S))
+           (princ "\n")
+           )))
+
       (princ "\n\n  Use: M-x semantic-lex-spp-describe RET\n")
       (princ "\n  to see the complete macro table.\n")
 
@@ -1729,8 +1788,8 @@ DO NOT return the list of tags encompassing point."
 
 ;; Local variables:
 ;; generated-autoload-file: "../loaddefs.el"
-;; generated-autoload-feature: semantic/loaddefs
 ;; generated-autoload-load-name: "semantic/bovine/c"
 ;; End:
 
+;; arch-tag: 263951a8-0f18-445d-8e73-eb8f9ac8e2a3
 ;;; semantic/bovine/c.el ends here