Spelling fixes.
[bpt/emacs.git] / lisp / cedet / semantic / lex-spp.el
index e76b8cd..03a3f1b 100644 (file)
@@ -1,6 +1,6 @@
-;;; lex-spp.el --- Semantic Lexical Pre-processor
+;;; semantic/lex-spp.el --- Semantic Lexical Pre-processor
 
-;; Copyright (C) 2006, 2007, 2008, 2009, 2010  Free Software Foundation, Inc.
+;; Copyright (C) 2006-2011  Free Software Foundation, Inc.
 
 ;; Author: Eric M. Ludlam <zappo@gnu.org>
 
@@ -173,10 +173,42 @@ The search priority is:
       (setq semantic-lex-spp-dynamic-macro-symbol-obarray-stack
            (make-vector 13 0))))
 
+(defun semantic-lex-spp-value-valid-p (value)
+  "Return non-nil if VALUE is valid."
+  (or (null value)
+      (stringp value)
+      (and (consp value)
+          (or (semantic-lex-token-p (car value))
+              (eq (car (car value)) 'spp-arg-list)))))
+
+(defvar semantic-lex-spp-debug-symbol nil
+  "A symbol to break on if it is being set somewhere.")
+
+(defun semantic-lex-spp-enable-debug-symbol (sym)
+  "Enable debugging for symbol SYM.
+Disable debugging by entering nothing."
+  (interactive "sSymbol: ")
+  (if (string= sym "")
+      (setq semantic-lex-spp-debug-symbol nil)
+    (setq semantic-lex-spp-debug-symbol sym)))
+
+(defmacro semantic-lex-spp-validate-value (name value)
+  "Validate the NAME and VALUE of a macro before it is set."
+;  `(progn
+;     (when (not (semantic-lex-spp-value-valid-p ,value))
+;       (error "Symbol \"%s\" with bogus value %S" ,name ,value))
+;     (when (and semantic-lex-spp-debug-symbol
+;              (string= semantic-lex-spp-debug-symbol name))
+;       (debug))
+;     )
+  nil
+  )
+
 (defun semantic-lex-spp-symbol-set (name value &optional obarray-in)
   "Set value of spp symbol with NAME to VALUE and return VALUE.
 If optional OBARRAY-IN is non-nil, then use that obarray instead of
 the dynamic map."
+  (semantic-lex-spp-validate-value name value)
   (if (and (stringp value) (string= value "")) (setq value nil))
   (set (intern name (or obarray-in
                        (semantic-lex-spp-dynamic-map)))
@@ -192,6 +224,7 @@ the dynamic map."
 (defun semantic-lex-spp-symbol-push (name value)
   "Push macro NAME with VALUE into the map.
 Reverse with `semantic-lex-spp-symbol-pop'."
+  (semantic-lex-spp-validate-value name value)
   (let* ((map (semantic-lex-spp-dynamic-map))
         (stack (semantic-lex-spp-dynamic-map-stack))
         (mapsym (intern name map))
@@ -606,7 +639,7 @@ and what valid VAL values are."
 
 ;;; Macro Merging
 ;;
-;; Used when token streams from different macros include eachother.
+;; Used when token streams from different macros include each other.
 ;; Merged macro streams perform in place replacements.
 
 (defun semantic-lex-spp-merge-streams (raw-stream)
@@ -676,7 +709,7 @@ ARGVALUES are values for any arg list, or nil."
 
 ;;; Symbol Is Macro
 ;;
-;; An analyser that will push tokens from a macro in place
+;; An analyzer that will push tokens from a macro in place
 ;; of the macro symbol.
 ;;
 (defun semantic-lex-spp-anlyzer-do-replace (sym val beg end)
@@ -864,42 +897,45 @@ and variable state from the current buffer."
                           semantic-lex-spp-expanded-macro-stack
                           ))
         )
-    (with-current-buffer buf
-      (erase-buffer)
-      ;; Below is a painful hack to make sure everything is setup correctly.
-      (when (not (eq major-mode mode))
-       (save-match-data
-
-         ;; Protect against user-hooks that throw 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)
-         ))
+    (if (> semantic-lex-spp-hack-depth 5)
+       nil
+      (with-current-buffer buf
+       (erase-buffer)
+       ;; Below is a painful hack to make sure everything is setup correctly.
+       (when (not (eq major-mode mode))
+         (save-match-data
+
+           ;; Protect against user-hooks that throw 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)
+           ))
 
-      ;; Second Cheat: copy key variables regarding macro state from the
-      ;; the originating buffer we are parsing.  We need to do this every time
-      ;; since the state changes.
-      (dolist (V important-vars)
-       (set V (semantic-buffer-local-value V origbuff)))
-      (insert text)
-      (goto-char (point-min))
+       ;; Second Cheat: copy key variables regarding macro state from the
+       ;; the originating buffer we are parsing.  We need to do this every time
+       ;; since the state changes.
+       (dolist (V important-vars)
+         (set V (semantic-buffer-local-value V origbuff)))
+       (insert text)
+       (goto-char (point-min))
 
-      (setq fresh-toks (semantic-lex-spp-stream-for-macro (point-max))))
+       (setq fresh-toks (semantic-lex-spp-stream-for-macro (point-max))))
 
-    (dolist (tok fresh-toks)
-      (when (memq (semantic-lex-token-class tok) '(symbol semantic-list))
-       (setq toks (cons tok toks))))
+      (dolist (tok fresh-toks)
+       (when (memq (semantic-lex-token-class tok) '(symbol semantic-list))
+         (setq toks (cons tok toks)))))
 
     (nreverse toks)))
 
@@ -1031,7 +1067,7 @@ of type `spp-macro-undef' is to be created."
 ;;
 ;; These analyzers help a language define how include files
 ;; are identified.  These are ONLY for languages that perform
-;; an actual textual includesion, and not for imports.
+;; an actual textual inclusion, and not for imports.
 ;;
 ;; This section is supposed to allow the macros from the headers to be
 ;; added to the local dynamic macro table, but that hasn't been
@@ -1121,37 +1157,31 @@ The VALUE is a spp lexical table."
       (prin1 (car sym))
       (let* ((first (car (cdr sym)))
             (rest (cdr sym)))
-       (when (not (listp first))
-         (error "Error in macro \"%s\"" (car sym)))
-       (when (eq (car first) 'spp-arg-list)
-         (princ " ")
-         (prin1 first)
-         (setq rest (cdr rest))
-         )
-
-       (when rest
-         (princ " . ")
-         (let ((len (length (cdr rest))))
-           (cond ((< len 2)
-                  (condition-case nil
-                      (prin1 rest)
-                    (error
-                     (princ "nil ;; Error writing macro\n"))))
-                 ((< len semantic-lex-spp-macro-max-length-to-save)
-                  (princ "\n              ")
-                  (condition-case nil
-                      (prin1 rest)
-                    (error
-                     (princ "nil ;; Error writing macro\n          ")))
-                  )
-                 (t ;; Too Long!
-                  (princ "nil ;; Too Long!\n          ")
-                  ))))
-       )
-      (princ ")\n          ")
-      )
-    (princ ")\n"))
-)
+       (if (not (listp first))
+           (insert "nil ;; bogus macro found.\n")
+         (when (eq (car first) 'spp-arg-list)
+           (princ " ")
+           (prin1 first)
+           (setq rest (cdr rest)))
+
+         (when rest
+           (princ " . ")
+           (let ((len (length (cdr rest))))
+             (cond ((< len 2)
+                    (condition-case nil
+                        (prin1 rest)
+                      (error
+                       (princ "nil ;; Error writing macro\n"))))
+                   ((< len semantic-lex-spp-macro-max-length-to-save)
+                    (princ "\n              ")
+                    (condition-case nil
+                        (prin1 rest)
+                      (error
+                       (princ "nil ;; Error writing macro\n          "))))
+                   (t ;; Too Long!
+                    (princ "nil ;; Too Long!\n          ")))))))
+      (princ ")\n          "))
+    (princ ")\n")))
 
 ;;; MACRO TABLE DEBUG
 ;;
@@ -1200,5 +1230,4 @@ If BUFFER is not provided, use the current buffer."
 ;; generated-autoload-load-name: "semantic/lex-spp"
 ;; End:
 
-;; arch-tag: 8877d83e-07ea-4d86-a960-e3562138d8a5
-;;; semantic-lex-spp.el ends here
+;;; semantic/lex-spp.el ends here