Update CEDET from upstream.
[bpt/emacs.git] / lisp / cedet / semantic / lex-spp.el
index 8009a25..5fe9004 100644 (file)
@@ -1,6 +1,6 @@
 ;;; semantic/lex-spp.el --- Semantic Lexical Pre-processor
 
-;; Copyright (C) 2006-2011  Free Software Foundation, Inc.
+;; Copyright (C) 2006-2012  Free Software Foundation, Inc.
 
 ;; Author: Eric M. Ludlam <zappo@gnu.org>
 
@@ -452,7 +452,7 @@ continue processing recursively."
         ;; If val is nil, that's probably wrong.
         ;; Found a system header case where this was true.
         ((null val) "")
-        ;; Debug wierd stuff.
+        ;; Debug weird stuff.
         (t (debug)))
        ))
      ((stringp txt)
@@ -497,7 +497,7 @@ and what valid VAL values are."
   ;;  (symbol "name" 569 . 573)
   ;;  (semantic-list "(int in)" 574 . 582))
   ;;
-  ;; In the second case, a macro with an argument list as the a rgs as the
+  ;; In the second case, a macro with an argument list as the args as the
   ;; first entry.
   ;;
   ;; CASE 3: Symbol text merge
@@ -577,13 +577,7 @@ and what valid VAL values are."
        (cond
         ;; CASE 3: Merge symbols together.
         ((eq (semantic-lex-token-class v) 'spp-symbol-merge)
-         ;; We need to merge the tokens in the 'text segement together,
-         ;; and produce a single symbol from it.
-         (let ((newsym
-                (mapconcat (lambda (tok)
-                             (semantic-lex-spp-one-token-to-txt tok))
-                           txt
-                           "")))
+         (let ((newsym (semantic-lex-spp-symbol-merge txt)))
            (semantic-lex-push-token
             (semantic-lex-token 'symbol beg end newsym))
            ))
@@ -637,6 +631,27 @@ and what valid VAL values are."
       (semantic-lex-spp-symbol-pop A))
     ))
 
+(defun semantic-lex-spp-symbol-merge (txt)
+  "Merge the tokens listed in TXT.
+TXT might contain further 'spp-symbol-merge, which will
+be merged recursively."
+  ;; We need to merge the tokens in the 'text segment together,
+  ;; and produce a single symbol from it.
+  (mapconcat (lambda (tok)
+              (cond
+               ((eq (car tok) 'symbol)
+                (semantic-lex-spp-one-token-to-txt tok))
+               ((eq (car tok) 'spp-symbol-merge)
+                ;; Call recursively for multiple merges, like
+                ;; #define FOO(a) foo##a##bar
+                (semantic-lex-spp-symbol-merge (cadr tok)))
+               (t
+                (message "Invalid merge macro ecountered; \
+will return empty string instead.")
+                "")))
+            txt
+            ""))
+
 ;;; Macro Merging
 ;;
 ;; Used when token streams from different macros include each other.
@@ -821,7 +836,7 @@ STR occurs in the current buffer between BEG and END."
 ;; a macro.
 
 (defun semantic-lex-spp-first-token-arg-list (token)
-  "If TOKEN is a semantic-list, turn it into a an SPP ARG LIST."
+  "If TOKEN is a semantic-list, turn it into an SPP ARG LIST."
   (when (and (consp token)
             (symbolp (car token))
             (eq 'semantic-list (car token)))
@@ -869,7 +884,14 @@ Parsing starts inside the parens, and ends at the end of TOKEN."
        (forward-char 1)
        (setq fresh-toks (semantic-lex-spp-stream-for-macro (1- end)))
        (dolist (tok fresh-toks)
-         (when (memq (semantic-lex-token-class tok) '(symbol semantic-list))
+         ;; march 2011: This is too restrictive!  For example "void"
+         ;; can't get through.  What elements was I trying to expunge
+         ;; to put this in here in the first place?  If I comment it
+         ;; out, does anything new break?
+         ;(when (memq (semantic-lex-token-class tok) '(symbol semantic-list))
+         ;; It appears the commas need to be dumped.  perhaps this is better,
+         ;; but will it cause more problems later?
+         (unless (eq (semantic-lex-token-class tok) 'punctuation)
            (setq toks (cons tok toks))))
 
        (nreverse toks)))))
@@ -890,6 +912,7 @@ and variable state from the current buffer."
         (fresh-toks nil)
         (toks nil)
         (origbuff (current-buffer))
+        (analyzer semantic-lex-analyzer)
         (important-vars '(semantic-lex-spp-macro-symbol-obarray
                           semantic-lex-spp-project-macro-symbol-obarray
                           semantic-lex-spp-dynamic-macro-symbol-obarray
@@ -913,6 +936,11 @@ and variable state from the current buffer."
            ;; Hack in mode-local
            (activate-mode-local-bindings)
 
+           ;; Call the major mode's setup function
+           (let ((entry (assq major-mode semantic-new-buffer-setup-functions)))
+             (when entry
+               (funcall (cdr entry))))
+
            ;; 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.
@@ -1067,7 +1095,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