1 ;;; wisent-debug.el --- GNU Bison for Emacs - Debugging
3 ;; Copyright (C) 2003, 2007 David Ponce
5 ;; Author: David Ponce <david@dponce.com>
6 ;; Maintainer: David Ponce <david@dponce.com>
7 ;; Created: 11 February 2003
9 ;; X-RCS: $Id: wisent-debug.el,v 1.1 2007-11-26 15:12:30 michaels Exp $
11 ;; This file is not part of GNU Emacs.
13 ;; This program is free software; you can redistribute it and/or
14 ;; modify it under the terms of the GNU General Public License as
15 ;; published by the Free Software Foundation; either version 2, or (at
16 ;; your option) any later version.
18 ;; This program is distributed in the hope that it will be useful, but
19 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 ;; General Public License for more details.
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with this program; see the file COPYING. If not, write to
25 ;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
26 ;; Boston, MA 02110-1301, USA.
30 ;; Investigating what is happening during execution of the Wisent parser.
32 ;; Wisent (the European Bison ;-) is an Elisp implementation of the
33 ;; GNU Compiler Compiler Bison.
35 ;; For more details on the basic concepts for understanding Wisent,
36 ;; read the Bison manual ;)
38 ;; For more details on Wisent itself read the Wisent manual.
47 (defsubst wisent-debug-on-entry-p (function)
48 "Return t if FUNCTION invoke debugger each time it is called.
49 FUNCTION must be a semantic action symbol."
50 (if (memq function debug-function-list)
53 (defun wisent-debug-on-automaton-p (automaton)
54 "Return t if there is a debug-enabled function in AUTOMATON."
58 (if (wisent-debug-on-entry-p function)
62 (defsubst wisent-debug-semantic-action-source (function)
63 "Return source expression of semantic action FUNCTION.
64 FUNCTION must be a semantic action symbol."
65 (symbol-function function))
67 (defun wisent-debug-read-entry (flag)
68 "Read a semantic action symbol from the minibuffer.
69 Return a list (AUTOMATON FUNCTION) suitable for an `interactive' spec.
70 AUTOMATON is a LALR automaton variable. FUNCTION is a semantic action
71 symbol defined in AUTOMATON. If FLAG is t, only consider
72 debug-enabled actions. If nil, only consider not debug-enabled
73 actions. If 'any consider all available semantic action symbols."
74 (let ((vn (completing-read
75 "LALR automaton name: " obarray
78 (and (wisent-automaton-p e)
79 (wisent-debug-on-automaton-p
84 (unless (string-equal "" vn)
85 (setq am (intern-soft vn)
86 ob (aref (symbol-value am) 3)
88 (format "Semantic action symbol in `%s': " am)
90 (unless (eq flag 'any)
92 (eq (wisent-debug-on-entry-p e) flag)))
94 (unless (string-equal "" vn)
95 (setq sy (intern-soft vn ob))))
98 (defun wisent-debug-check-entry (automaton function)
99 "Check that AUTOMATON owns symbol FUNCTION.
100 Always return a symbol FUNCTION interned in the semantic action symbol
102 (and (wisent-automaton-p automaton)
103 function (symbolp function)
104 (intern-soft (symbol-name function)
105 (aref (symbol-value automaton) 3))))
108 (defun wisent-debug-on-entry (automaton function)
109 "Request AUTOMATON's FUNCTION to invoke debugger each time it is called.
110 FUNCTION must be a semantic action symbol that exists in AUTOMATON."
111 (interactive (wisent-debug-read-entry nil))
112 (when (setq function (wisent-debug-check-entry automaton function))
113 (debug-on-entry function)))
116 (defun wisent-cancel-debug-on-entry (automaton function)
117 "Undo effect of \\[wisent-debug-on-entry] on AUTOMATON's FUNCTION.
118 FUNCTION must be a semantic action symbol that exists in AUTOMATON."
119 (interactive (wisent-debug-read-entry t))
120 (when (setq function (wisent-debug-check-entry automaton function))
121 (cancel-debug-on-entry function)))
128 (if (fboundp 'pprint-to-string)
130 (defalias 'wisent-debug-pp-to-string 'pprint-to-string))
132 (defalias 'wisent-debug-pp-to-string 'pp-to-string)))
135 (defun wisent-debug-show-entry (automaton function)
136 "Show the source of AUTOMATON's semantic action FUNCTION.
137 FUNCTION must be a semantic action symbol that exists in AUTOMATON."
138 (interactive (wisent-debug-read-entry 'any))
139 (when (setq function (wisent-debug-check-entry automaton function))
141 (get-buffer-create (format "*%s/%s*" automaton function))
143 (kill-all-local-variables)
145 (setq buffer-undo-list t
146 buffer-read-only nil)
149 (wisent-debug-pp-to-string
150 (wisent-debug-semantic-action-source function)))
151 (goto-char (point-min))
152 (pop-to-buffer (current-buffer)))))
154 (provide 'wisent-debug)
156 ;;; wisent-debug.el ends here