comparison lisp/emacs-lisp/edebug.el @ 51331:cf0bc7d12c33

(edebug-storing-offsets): Move indent and debug to inside the macro. (edebug-read-storing-offsets): Simplify. (edebug-read-quote, edebug-read-function): Place the start-position correctly. (edebug-read-backquote-new): Remove. (edebug-read-backquote-level): New var to replace it. (edebug-read-backquote): Increment it. Don't store offsets one extra time. (edebug-read-comma): Decrement it. Read the comma as a plain symbol if outside of any new-style backquote. (edebug-read-list): Use edebug-read-backquote-level. Don't call edebug-read-backquote directly. This way the extra offsets store is done exactly when it's needed. (edebug-read-vector): Use push. (defmacro): Add support for the `declare' thingy.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Fri, 30 May 2003 15:34:02 +0000
parents 8933bf0b436a
children 2607d23dcfe2
comparison
equal deleted inserted replaced
51330:8d150d95fc45 51331:cf0bc7d12c33
808 808
809 (defun edebug-ignore-offset () 809 (defun edebug-ignore-offset ()
810 ;; Ignore the last created offset pair. 810 ;; Ignore the last created offset pair.
811 (setcdr edebug-current-offset (cdr (cdr edebug-current-offset)))) 811 (setcdr edebug-current-offset (cdr (cdr edebug-current-offset))))
812 812
813 (def-edebug-spec edebug-storing-offsets (form body))
814 (put 'edebug-storing-offsets 'lisp-indent-hook 1)
815
816 (defmacro edebug-storing-offsets (point &rest body) 813 (defmacro edebug-storing-offsets (point &rest body)
814 (declare (debug (form body)) (indent 1))
817 `(unwind-protect 815 `(unwind-protect
818 (progn 816 (progn
819 (edebug-store-before-offset ,point) 817 (edebug-store-before-offset ,point)
820 ,@body) 818 ,@body)
821 (edebug-store-after-offset (point)))) 819 (edebug-store-after-offset (point))))
835 (lbracket . edebug-read-vector) 833 (lbracket . edebug-read-vector)
836 (hash . edebug-read-function) 834 (hash . edebug-read-function)
837 )) 835 ))
838 836
839 (defun edebug-read-storing-offsets (stream) 837 (defun edebug-read-storing-offsets (stream)
840 (let ((class (edebug-next-token-class)) 838 (let (edebug-read-dotted-list) ; see edebug-store-after-offset
841 func
842 edebug-read-dotted-list) ; see edebug-store-after-offset
843 (edebug-storing-offsets (point) 839 (edebug-storing-offsets (point)
844 (if (setq func (assq class edebug-read-alist)) 840 (funcall
845 (funcall (cdr func) stream) 841 (or (cdr (assq (edebug-next-token-class) edebug-read-alist))
846 ;; anything else, just read it. 842 ;; anything else, just read it.
847 (edebug-original-read stream)) 843 'edebug-original-read)
848 ))) 844 stream))))
849 845
850 (defun edebug-read-symbol (stream) 846 (defun edebug-read-symbol (stream)
851 (edebug-original-read stream)) 847 (edebug-original-read stream))
852 848
853 (defun edebug-read-string (stream) 849 (defun edebug-read-string (stream)
855 851
856 (defun edebug-read-quote (stream) 852 (defun edebug-read-quote (stream)
857 ;; Turn 'thing into (quote thing) 853 ;; Turn 'thing into (quote thing)
858 (forward-char 1) 854 (forward-char 1)
859 (list 855 (list
860 (edebug-storing-offsets (point) 'quote) 856 (edebug-storing-offsets (1- (point)) 'quote)
861 (edebug-read-storing-offsets stream))) 857 (edebug-read-storing-offsets stream)))
858
859 (defvar edebug-read-backquote-level 0
860 "If non-zero, we're in a new-style backquote.
861 It should never be negative. This controls how we read comma constructs.")
862 862
863 (defun edebug-read-backquote (stream) 863 (defun edebug-read-backquote (stream)
864 ;; Turn `thing into (\` thing) 864 ;; Turn `thing into (\` thing)
865 (let ((opoint (point))) 865 (forward-char 1)
866 (forward-char 1) 866 (list
867 ;; Generate the same structure of offsets we would have 867 (edebug-storing-offsets (1- (point)) '\`)
868 ;; if the resulting list appeared verbatim in the input text. 868 (let ((edebug-read-backquote-level (1+ edebug-read-backquote-level)))
869 (edebug-storing-offsets opoint 869 (edebug-read-storing-offsets stream))))
870 (list
871 (edebug-storing-offsets opoint '\`)
872 (edebug-read-storing-offsets stream)))))
873
874 (defvar edebug-read-backquote-new nil
875 "Non-nil if reading the inside of a new-style backquote with no parens around it.
876 Value of nil means reading the inside of an old-style backquote construct
877 which is surrounded by an extra set of parentheses.
878 This controls how we read comma constructs.")
879 870
880 (defun edebug-read-comma (stream) 871 (defun edebug-read-comma (stream)
881 ;; Turn ,thing into (\, thing). Handle ,@ and ,. also. 872 ;; Turn ,thing into (\, thing). Handle ,@ and ,. also.
882 (let ((opoint (point))) 873 (let ((opoint (point)))
883 (forward-char 1) 874 (forward-char 1)
888 ((eq (following-char) ?\@) 879 ((eq (following-char) ?\@)
889 (setq symbol '\,@) 880 (setq symbol '\,@)
890 (forward-char 1))) 881 (forward-char 1)))
891 ;; Generate the same structure of offsets we would have 882 ;; Generate the same structure of offsets we would have
892 ;; if the resulting list appeared verbatim in the input text. 883 ;; if the resulting list appeared verbatim in the input text.
893 (if edebug-read-backquote-new 884 (if (zerop edebug-read-backquote-level)
894 (list 885 (edebug-storing-offsets opoint symbol)
895 (edebug-storing-offsets opoint symbol) 886 (list
896 (edebug-read-storing-offsets stream)) 887 (edebug-storing-offsets opoint symbol)
897 (edebug-storing-offsets opoint symbol))))) 888 (let ((edebug-read-backquote-level (1- edebug-read-backquote-level)))
889 (edebug-read-storing-offsets stream)))))))
898 890
899 (defun edebug-read-function (stream) 891 (defun edebug-read-function (stream)
900 ;; Turn #'thing into (function thing) 892 ;; Turn #'thing into (function thing)
901 (forward-char 1) 893 (forward-char 1)
902 (cond ((eq ?\' (following-char)) 894 (cond ((eq ?\' (following-char))
903 (forward-char 1) 895 (forward-char 1)
904 (list 896 (list
905 (edebug-storing-offsets (point) 897 (edebug-storing-offsets (- (point) 2)
906 (if (featurep 'cl) 'function* 'function)) 898 (if (featurep 'cl) 'function* 'function))
907 (edebug-read-storing-offsets stream))) 899 (edebug-read-storing-offsets stream)))
908 ((memq (following-char) '(?: ?B ?O ?X ?b ?o ?x ?1 ?2 ?3 ?4 ?5 ?6 900 ((memq (following-char) '(?: ?B ?O ?X ?b ?o ?x ?1 ?2 ?3 ?4 ?5 ?6
909 ?7 ?8 ?9 ?0)) 901 ?7 ?8 ?9 ?0))
910 (backward-char 1) 902 (backward-char 1)
911 (edebug-original-read stream)) 903 (edebug-original-read stream))
912 (t (edebug-syntax-error "Bad char after #")))) 904 (t (edebug-syntax-error "Bad char after #"))))
913 905
914 (defun edebug-read-list (stream) 906 (defun edebug-read-list (stream)
915 (forward-char 1) ; skip \( 907 (forward-char 1) ; skip \(
916 (prog1 908 (prog1
917 (let ((elements)) 909 (let ((elements))
918 (while (not (memq (edebug-next-token-class) '(rparen dot))) 910 (while (not (memq (edebug-next-token-class) '(rparen dot)))
919 (if (eq (edebug-next-token-class) 'backquote) 911 (if (and (eq (edebug-next-token-class) 'backquote)
920 (let ((edebug-read-backquote-new (not (null elements))) 912 (null elements)
921 (opoint (point))) 913 (zerop edebug-read-backquote-level))
922 (if edebug-read-backquote-new 914 (progn
923 (setq elements (cons (edebug-read-backquote stream) elements)) 915 ;; Old style backquote.
924 (forward-char 1) ; Skip backquote. 916 (forward-char 1) ; Skip backquote.
925 ;; Call edebug-storing-offsets here so that we 917 ;; Call edebug-storing-offsets here so that we
926 ;; produce the same offsets we would have had 918 ;; produce the same offsets we would have had
927 ;; if the backquote were an ordinary symbol. 919 ;; if the backquote were an ordinary symbol.
928 (setq elements (cons (edebug-storing-offsets opoint '\`) 920 (push (edebug-storing-offsets (1- (point)) '\`) elements))
929 elements)))) 921 (push (edebug-read-storing-offsets stream) elements)))
930 (setq elements (cons (edebug-read-storing-offsets stream) elements))))
931 (setq elements (nreverse elements)) 922 (setq elements (nreverse elements))
932 (if (eq 'dot (edebug-next-token-class)) 923 (if (eq 'dot (edebug-next-token-class))
933 (let (dotted-form) 924 (let (dotted-form)
934 (forward-char 1) ; skip \. 925 (forward-char 1) ; skip \.
935 (setq dotted-form (edebug-read-storing-offsets stream)) 926 (setq dotted-form (edebug-read-storing-offsets stream))
945 (defun edebug-read-vector (stream) 936 (defun edebug-read-vector (stream)
946 (forward-char 1) ; skip \[ 937 (forward-char 1) ; skip \[
947 (prog1 938 (prog1
948 (let ((elements)) 939 (let ((elements))
949 (while (not (eq 'rbracket (edebug-next-token-class))) 940 (while (not (eq 'rbracket (edebug-next-token-class)))
950 (setq elements (cons (edebug-read-storing-offsets stream) elements))) 941 (push (edebug-read-storing-offsets stream) elements))
951 (apply 'vector (nreverse elements))) 942 (apply 'vector (nreverse elements)))
952 (forward-char 1) ; skip \] 943 (forward-char 1) ; skip \]
953 )) 944 ))
954 945
955 ;;; Cursors for traversal of list and vector elements with offsets. 946 ;;; Cursors for traversal of list and vector elements with offsets.
1981 (&define name lambda-list 1972 (&define name lambda-list
1982 [&optional stringp] 1973 [&optional stringp]
1983 [&optional ("interactive" interactive)] 1974 [&optional ("interactive" interactive)]
1984 def-body)) 1975 def-body))
1985 (def-edebug-spec defmacro 1976 (def-edebug-spec defmacro
1986 (&define name lambda-list def-body)) 1977 (&define name lambda-list [&optional ("declare" &rest sexp)] def-body))
1987 1978
1988 (def-edebug-spec arglist lambda-list) ;; deprecated - use lambda-list. 1979 (def-edebug-spec arglist lambda-list) ;; deprecated - use lambda-list.
1989 1980
1990 (def-edebug-spec lambda-list 1981 (def-edebug-spec lambda-list
1991 (([&rest arg] 1982 (([&rest arg]