104498
|
1 ;;; srecode/compile --- Compilation of srecode template files.
|
|
2
|
|
3 ;;; Copyright (C) 2005, 2007, 2008, 2009 Free Software Foundation, Inc.
|
|
4
|
|
5 ;; Author: Eric M. Ludlam <zappo@gnu.org>
|
|
6 ;; Keywords: codegeneration
|
|
7
|
|
8 ;; This file is part of GNU Emacs.
|
|
9
|
|
10 ;; GNU Emacs is free software: you can redistribute it and/or modify
|
|
11 ;; it under the terms of the GNU General Public License as published by
|
|
12 ;; the Free Software Foundation, either version 3 of the License, or
|
|
13 ;; (at your option) any later version.
|
|
14
|
|
15 ;; GNU Emacs is distributed in the hope that it will be useful,
|
|
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
18 ;; GNU General Public License for more details.
|
|
19
|
|
20 ;; You should have received a copy of the GNU General Public License
|
|
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
|
|
22
|
|
23 ;;; Commentary:
|
|
24 ;;
|
|
25 ;; Compile a Semantic Recoder template file.
|
|
26 ;;
|
|
27 ;; Template files are parsed using a Semantic/Wisent parser into
|
|
28 ;; a tag table. The code therin is then further parsed down using
|
|
29 ;; a regular expression parser.
|
|
30 ;;
|
|
31 ;; The output are a series of EIEIO objects which represent the
|
|
32 ;; templates in a way that could be inserted later.
|
|
33
|
|
34 (require 'semantic)
|
|
35 (require 'eieio)
|
|
36 (require 'eieio-base)
|
|
37 (require 'srecode)
|
|
38 (require 'srecode/table)
|
|
39
|
|
40 (declare-function srecode-template-inserter-newline-child-p "srecode/insert")
|
|
41 (declare-function srecode-create-section-dictionary "srecode/dictionary")
|
|
42 (declare-function srecode-dictionary-compound-variable "srecode/dictionary")
|
|
43
|
|
44 ;;; Code:
|
|
45
|
|
46 ;;; Template Class
|
|
47 ;;
|
|
48 ;; Templatets describe a patter of text that can be inserted into a
|
|
49 ;; buffer.
|
|
50 ;;
|
|
51 (defclass srecode-template (eieio-named)
|
|
52 ((context :initarg :context
|
|
53 :initform nil
|
|
54 :documentation
|
|
55 "Context this template belongs to.")
|
|
56 (args :initarg :args
|
|
57 :documentation
|
|
58 "List of arguments that this template requires.")
|
|
59 (code :initarg :code
|
|
60 :documentation
|
|
61 "Compiled text from the template.")
|
|
62 (dictionary :initarg :dictionary
|
|
63 :type (or null srecode-dictionary)
|
|
64 :documentation
|
|
65 "List of section dictinaries.
|
|
66 The compiled template can contain lists of section dictionaries,
|
|
67 or values that are expected to be passed down into different
|
|
68 section macros. The template section dictionaries are merged in with
|
|
69 any incomming dictionaries values.")
|
|
70 (binding :initarg :binding
|
|
71 :documentation
|
|
72 "Preferred keybinding for this template in `srecode-minor-mode-map'.")
|
|
73 (active :allocation :class
|
|
74 :initform nil
|
|
75 :documentation
|
|
76 "During template insertion, this is the stack of active templates.
|
|
77 The top-most template is the 'active' template. Use the accessor methods
|
|
78 for push, pop, and peek for the active template.")
|
|
79 (table :initarg :table
|
|
80 :documentation
|
|
81 "The table this template lives in.")
|
|
82 )
|
|
83 "Class defines storage for semantic recoder templates.")
|
|
84
|
|
85 (defun srecode-flush-active-templates ()
|
|
86 "Flush the active template storage.
|
|
87 Useful if something goes wrong in SRecode, and the active tempalte
|
|
88 stack is broken."
|
|
89 (interactive)
|
|
90 (if (oref srecode-template active)
|
|
91 (when (y-or-n-p (format "%d active templates. Flush? "
|
|
92 (length (oref srecode-template active))))
|
|
93 (oset-default srecode-template active nil))
|
|
94 (message "No active templates to flush."))
|
|
95 )
|
|
96
|
|
97 ;;; Inserters
|
|
98 ;;
|
|
99 ;; Each inserter object manages a different thing that
|
|
100 ;; might be inserted into a template output stream.
|
|
101 ;;
|
|
102 ;; The 'srecode-insert-method' on each inserter does the actual
|
|
103 ;; work, and the smaller, simple inserter object is saved in
|
|
104 ;; the compiled templates.
|
|
105 ;;
|
|
106 ;; See srecode-insert.el for the specialized classes.
|
|
107 ;;
|
|
108 (defclass srecode-template-inserter (eieio-named)
|
|
109 ((secondname :initarg :secondname
|
|
110 :type (or null string)
|
|
111 :documentation
|
|
112 "If there is a colon in the inserter's name, it represents
|
|
113 additional static argument data."))
|
|
114 "This represents an item to be inserted via a template macro.
|
|
115 Plain text strings are not handled via this baseclass."
|
|
116 :abstract t)
|
|
117
|
|
118 (defmethod srecode-parse-input ((ins srecode-template-inserter)
|
|
119 tag input STATE)
|
|
120 "For the template inserter INS, parse INPUT.
|
|
121 Shorten input only by the amount needed.
|
|
122 Return the remains of INPUT.
|
|
123 STATE is the current compilation state."
|
|
124 input)
|
|
125
|
|
126 (defmethod srecode-match-end ((ins srecode-template-inserter) name)
|
|
127 "For the template inserter INS, do I end a section called NAME?"
|
|
128 nil)
|
|
129
|
|
130 (defmethod srecode-inserter-apply-state ((ins srecode-template-inserter) STATE)
|
|
131 "For the template inserter INS, apply information from STATE."
|
|
132 nil)
|
|
133
|
|
134 (defmethod srecode-inserter-prin-example :STATIC ((ins srecode-template-inserter)
|
|
135 escape-start escape-end)
|
|
136 "Insert an example using inserter INS.
|
|
137 Arguments ESCAPE-START and ESCAPE-END are the current escape sequences in use."
|
|
138 (princ " ")
|
|
139 (princ escape-start)
|
|
140 (when (and (slot-exists-p ins 'key) (oref ins key))
|
|
141 (princ (format "%c" (oref ins key))))
|
|
142 (princ "VARNAME")
|
|
143 (princ escape-end)
|
|
144 (terpri)
|
|
145 )
|
|
146
|
|
147
|
|
148 ;;; Compile State
|
|
149 (defclass srecode-compile-state ()
|
|
150 ((context :initform "declaration"
|
|
151 :documentation "The active context.")
|
|
152 (prompts :initform nil
|
|
153 :documentation "The active prompts.")
|
|
154 (escape_start :initform "{{"
|
|
155 :documentation "The starting escape sequence.")
|
|
156 (escape_end :initform "}}"
|
|
157 :documentation "The ending escape sequence.")
|
|
158 )
|
|
159 "Current state of the compile.")
|
|
160
|
|
161 (defmethod srecode-compile-add-prompt ((state srecode-compile-state)
|
|
162 prompttag)
|
|
163 "Add PROMPTTAG to the current list of prompts."
|
|
164 (with-slots (prompts) state
|
|
165 (let ((match (assoc (semantic-tag-name prompttag) prompts))
|
|
166 (newprompts prompts))
|
|
167 (when match
|
|
168 (let ((tmp prompts))
|
|
169 (setq newprompts nil)
|
|
170 (while tmp
|
|
171 (when (not (string= (car (car tmp))
|
|
172 (car prompttag)))
|
|
173 (setq newprompts (cons (car tmp)
|
|
174 newprompts)))
|
|
175 (setq tmp (cdr tmp)))))
|
|
176 (setq prompts (cons prompttag newprompts)))
|
|
177 ))
|
|
178
|
|
179 ;;; TEMPLATE COMPILER
|
|
180 ;;
|
|
181 (defun srecode-compile-file (fname)
|
|
182 "Compile the templates from the file FNAME."
|
|
183 (let ((peb (get-file-buffer fname)))
|
|
184 (save-excursion
|
|
185 ;; Make whatever it is local.
|
|
186 (if (not peb)
|
|
187 (set-buffer (semantic-find-file-noselect fname))
|
|
188 (set-buffer peb))
|
|
189 ;; Do the compile.
|
|
190 (srecode-compile-templates)
|
|
191 ;; Trash the buffer if we had to read it in.
|
|
192 (if (not peb)
|
|
193 (kill-buffer (current-buffer)))
|
|
194 )))
|
|
195
|
|
196 ;;;###autoload
|
|
197 (defun srecode-compile-templates ()
|
|
198 "Compile a semantic recode template file into a mode-local variable."
|
|
199 (interactive)
|
|
200 (require 'srecode-insert)
|
|
201 (message "Compiling template %s..."
|
|
202 (file-name-nondirectory (buffer-file-name)))
|
|
203 (let ((tags (semantic-fetch-tags))
|
|
204 (tag nil)
|
|
205 (class nil)
|
|
206 (table nil)
|
|
207 (STATE (srecode-compile-state (file-name-nondirectory
|
|
208 (buffer-file-name))))
|
|
209 (mode nil)
|
|
210 (application nil)
|
|
211 (priority nil)
|
|
212 (vars nil)
|
|
213 )
|
|
214
|
|
215 ;;
|
|
216 ;; COMPILE
|
|
217 ;;
|
|
218 (while tags
|
|
219 (setq tag (car tags)
|
|
220 class (semantic-tag-class tag))
|
|
221 ;; What type of item is it?
|
|
222 (cond
|
|
223 ;; CONTEXT tags specify the context all future tags
|
|
224 ;; belong to.
|
|
225 ((eq class 'context)
|
|
226 (oset STATE context (semantic-tag-name tag))
|
|
227 )
|
|
228
|
|
229 ;; PROMPT tags specify prompts for dictionary ? inserters
|
|
230 ;; which appear in the following templates
|
|
231 ((eq class 'prompt)
|
|
232 (srecode-compile-add-prompt STATE tag)
|
|
233 )
|
|
234
|
|
235 ;; VARIABLE tags can specify operational control
|
|
236 ((eq class 'variable)
|
|
237 (let* ((name (semantic-tag-name tag))
|
|
238 (value (semantic-tag-variable-default tag))
|
|
239 (firstvalue (car value)))
|
|
240 ;; If it is a single string, and one value, then
|
|
241 ;; look to see if it is one of our special variables.
|
|
242 (if (and (= (length value) 1) (stringp firstvalue))
|
|
243 (cond ((string= name "mode")
|
|
244 (setq mode (intern firstvalue)))
|
|
245 ((string= name "escape_start")
|
|
246 (oset STATE escape_start firstvalue)
|
|
247 )
|
|
248 ((string= name "escape_end")
|
|
249 (oset STATE escape_end firstvalue)
|
|
250 )
|
|
251 ((string= name "application")
|
|
252 (setq application (read firstvalue)))
|
|
253 ((string= name "priority")
|
|
254 (setq priority (read firstvalue)))
|
|
255 (t
|
|
256 ;; Assign this into some table of variables.
|
|
257 (setq vars (cons (cons name firstvalue) vars))
|
|
258 ))
|
|
259 ;; If it isn't a single string, then the value of the
|
|
260 ;; variable belongs to a compound dictionary value.
|
|
261 ;;
|
|
262 ;; Create a compound dictionary value from "value".
|
|
263 (require 'srecode/dictionary)
|
|
264 (let ((cv (srecode-dictionary-compound-variable
|
|
265 name :value value)))
|
|
266 (setq vars (cons (cons name cv) vars)))
|
|
267 ))
|
|
268 )
|
|
269
|
|
270 ;; FUNCTION tags are really templates.
|
|
271 ((eq class 'function)
|
|
272 (setq table (cons (srecode-compile-one-template-tag tag STATE)
|
|
273 table))
|
|
274 )
|
|
275
|
|
276 ;; Ooops
|
|
277 (t (error "Unknown TAG class %s" class))
|
|
278 )
|
|
279 ;; Continue
|
|
280 (setq tags (cdr tags)))
|
|
281
|
|
282 ;; MSG - Before install since nreverse whacks our list.
|
|
283 (message "%d templates compiled for %s"
|
|
284 (length table) mode)
|
|
285
|
|
286 ;;
|
|
287 ;; APPLY TO MODE
|
|
288 ;;
|
|
289 (if (not mode)
|
|
290 (error "You must specify a MODE for your templates"))
|
|
291
|
|
292 ;;
|
|
293 ;; Calculate priority
|
|
294 ;;
|
|
295 (if (not priority)
|
|
296 (let ((d (file-name-directory (buffer-file-name)))
|
|
297 (sd (file-name-directory (locate-library "srecode")))
|
|
298 (defaultdelta (if (eq mode 'default) 20 0)))
|
|
299 (if (string= d sd)
|
|
300 (setq priority (+ 80 defaultdelta))
|
|
301 (setq priority (+ 30 defaultdelta)))
|
|
302 (message "Templates %s has estimated priority of %d"
|
|
303 (file-name-nondirectory (buffer-file-name))
|
|
304 priority))
|
|
305 (message "Compiling templates %s priority %d... done!"
|
|
306 (file-name-nondirectory (buffer-file-name))
|
|
307 priority))
|
|
308
|
|
309 ;; Save it up!
|
|
310 (srecode-compile-template-table table mode priority application vars)
|
|
311 )
|
|
312 )
|
|
313
|
|
314 (defun srecode-compile-one-template-tag (tag STATE)
|
|
315 "Compile a template tag TAG into an srecode template class.
|
|
316 STATE is the current compile state as an object `srecode-compile-state'."
|
|
317 (require 'srecode/dictionary)
|
|
318 (let* ((context (oref STATE context))
|
|
319 (codeout (srecode-compile-split-code
|
|
320 tag (semantic-tag-get-attribute tag :code)
|
|
321 STATE))
|
|
322 (code (cdr codeout))
|
|
323 (args (semantic-tag-function-arguments tag))
|
|
324 (binding (semantic-tag-get-attribute tag :binding))
|
|
325 (rawdicts (semantic-tag-get-attribute tag :dictionaries))
|
|
326 (sdicts (srecode-create-section-dictionary rawdicts STATE))
|
|
327 (addargs nil)
|
|
328 )
|
|
329 ; (message "Compiled %s to %d codes with %d args and %d prompts."
|
|
330 ; (semantic-tag-name tag)
|
|
331 ; (length code)
|
|
332 ; (length args)
|
|
333 ; (length prompts))
|
|
334 (while args
|
|
335 (setq addargs (cons (intern (car args)) addargs))
|
|
336 (when (eq (car addargs) :blank)
|
|
337 ;; If we have a wrap, then put wrap inserters on both
|
|
338 ;; ends of the code.
|
|
339 (setq code (append
|
|
340 (list (srecode-compile-inserter "BLANK"
|
|
341 "\r"
|
|
342 STATE
|
|
343 :secondname nil
|
|
344 :where 'begin))
|
|
345 code
|
|
346 (list (srecode-compile-inserter "BLANK"
|
|
347 "\r"
|
|
348 STATE
|
|
349 :secondname nil
|
|
350 :where 'end))
|
|
351 )))
|
|
352 (setq args (cdr args)))
|
|
353 (srecode-template (semantic-tag-name tag)
|
|
354 :context context
|
|
355 :args (nreverse addargs)
|
|
356 :dictionary sdicts
|
|
357 :binding binding
|
|
358 :code code)
|
|
359 ))
|
|
360
|
|
361 (defun srecode-compile-do-hard-newline-p (comp)
|
|
362 "Examine COMP to decide if the upcoming newline should be hard.
|
|
363 It is hard if the previous inserter is a newline object."
|
|
364 (while (and comp (stringp (car comp)))
|
|
365 (setq comp (cdr comp)))
|
|
366 (or (not comp)
|
|
367 (require 'srecode/insert)
|
|
368 (srecode-template-inserter-newline-child-p (car comp))))
|
|
369
|
|
370 (defun srecode-compile-split-code (tag str STATE
|
|
371 &optional end-name)
|
|
372 "Split the code for TAG into something templatable.
|
|
373 STR is the string of code from TAG to split.
|
|
374 STATE is the current compile state.
|
|
375 ESCAPE_START and ESCAPE_END are regexps that indicate the beginning
|
|
376 escape character, and end escape character pattern for expandable
|
|
377 macro names.
|
|
378 Optional argument END-NAME specifies the name of a token upon which
|
|
379 parsing should stop.
|
|
380 If END-NAME is specified, and the input string"
|
|
381 (let* ((what str)
|
|
382 (end-token nil)
|
|
383 (comp nil)
|
|
384 (regex (concat "\n\\|" (regexp-quote (oref STATE escape_start))))
|
|
385 (regexend (regexp-quote (oref STATE escape_end)))
|
|
386 )
|
|
387 (while (and what (not end-token))
|
|
388 (cond
|
|
389 ((string-match regex what)
|
|
390 (let* ((prefix (substring what 0 (match-beginning 0)))
|
|
391 (match (substring what
|
|
392 (match-beginning 0)
|
|
393 (match-end 0)))
|
|
394 (namestart (match-end 0))
|
|
395 (junk (string-match regexend what namestart))
|
|
396 end tail name)
|
|
397 ;; Add string to compiled output
|
|
398 (when (> (length prefix) 0)
|
|
399 (setq comp (cons prefix comp)))
|
|
400 (if (string= match "\n")
|
|
401 ;; Do newline thingy.
|
|
402 (let ((new-inserter
|
|
403 (srecode-compile-inserter
|
|
404 "INDENT"
|
|
405 "\n"
|
|
406 STATE
|
|
407 :secondname nil
|
|
408 ;; This newline is "hard" meaning ALWAYS do it
|
|
409 ;; if the previous entry is also a newline.
|
|
410 ;; Without it, user entered blank lines will be
|
|
411 ;; ignored.
|
|
412 :hard (srecode-compile-do-hard-newline-p comp)
|
|
413 )))
|
|
414 ;; Trim WHAT back.
|
|
415 (setq what (substring what namestart))
|
|
416 (when (> (length what) 0)
|
|
417 ;; make the new inserter, but only if we aren't last.
|
|
418 (setq comp (cons new-inserter comp))
|
|
419 ))
|
|
420 ;; Regular inserter thingy.
|
|
421 (setq end (if junk
|
|
422 (match-beginning 0)
|
|
423 (error "Could not find end escape for %s"
|
|
424 (semantic-tag-name tag)))
|
|
425 tail (match-end 0))
|
|
426 (cond ((not end)
|
|
427 (error "No matching escape end for %s"
|
|
428 (semantic-tag-name tag)))
|
|
429 ((<= end namestart)
|
|
430 (error "Stray end escape for %s"
|
|
431 (semantic-tag-name tag)))
|
|
432 )
|
|
433 ;; Add string to compiled output
|
|
434 (setq name (substring what namestart end)
|
|
435 key nil)
|
|
436 ;; Trim WHAT back.
|
|
437 (setq what (substring what tail))
|
|
438 ;; Get the inserter
|
|
439 (let ((new-inserter
|
|
440 (srecode-compile-parse-inserter name STATE))
|
|
441 )
|
|
442 ;; If this is an end inserter, then assign into
|
|
443 ;; the end-token.
|
|
444 (if (srecode-match-end new-inserter end-name)
|
|
445 (setq end-token new-inserter))
|
|
446 ;; Add the inserter to our compilation stream.
|
|
447 (setq comp (cons new-inserter comp))
|
|
448 ;; Allow the inserter an opportunity to modify
|
|
449 ;; the input stream.
|
|
450 (setq what (srecode-parse-input new-inserter tag what
|
|
451 STATE))
|
|
452 )
|
|
453 )))
|
|
454 (t
|
|
455 (if end-name
|
|
456 (error "Unmatched section end %s" end-name))
|
|
457 (setq comp (cons what comp)
|
|
458 what nil))))
|
|
459 (cons what (nreverse comp))))
|
|
460
|
|
461 (defun srecode-compile-parse-inserter (txt STATE)
|
|
462 "Parse the inserter TXT with the current STATE.
|
|
463 Return an inserter object."
|
|
464 (let ((key (aref txt 0))
|
|
465 )
|
|
466 (if (and (or (< key ?A) (> key ?Z))
|
|
467 (or (< key ?a) (> key ?z)) )
|
|
468 (setq name (substring txt 1))
|
|
469 (setq name txt
|
|
470 key nil))
|
|
471 (let* ((junk (string-match ":" name))
|
|
472 (namepart (if junk
|
|
473 (substring name 0 (match-beginning 0))
|
|
474 name))
|
|
475 (secondname (if junk
|
|
476 (substring name (match-end 0))
|
|
477 nil))
|
|
478 (new-inserter (srecode-compile-inserter
|
|
479 namepart key STATE
|
|
480 :secondname secondname
|
|
481 )))
|
|
482 ;; Return the new inserter
|
|
483 new-inserter)))
|
|
484
|
|
485 (defun srecode-compile-inserter (name key STATE &rest props)
|
|
486 "Create an srecode inserter object for some macro NAME.
|
|
487 KEY indicates a single character key representing a type
|
|
488 of inserter to create.
|
|
489 STATE is the current compile state.
|
|
490 PROPS are additional properties that might need to be passed
|
|
491 to the inserter constructor."
|
|
492 ;;(message "Compile: %s %S" name props)
|
|
493 (if (not key)
|
|
494 (apply 'srecode-template-inserter-variable name props)
|
|
495 (let ((classes (class-children srecode-template-inserter))
|
|
496 (new nil))
|
|
497 ;; Loop over the various subclasses and
|
|
498 ;; create the correct inserter.
|
|
499 (while (and (not new) classes)
|
|
500 (setq classes (append classes (class-children (car classes))))
|
|
501 ;; Do we have a match?
|
|
502 (when (and (not (class-abstract-p (car classes)))
|
|
503 (equal (oref (car classes) key) key))
|
|
504 ;; Create the new class, and apply state.
|
|
505 (setq new (apply (car classes) name props))
|
|
506 (srecode-inserter-apply-state new STATE)
|
|
507 )
|
|
508 (setq classes (cdr classes)))
|
|
509 (if (not new) (error "SRECODE: Unknown macro code %S" key))
|
|
510 new)))
|
|
511
|
|
512 (defun srecode-compile-template-table (templates mode priority application vars)
|
|
513 "Compile a list of TEMPLATES into an semantic recode table.
|
|
514 The table being compiled is for MODE, or the string \"default\".
|
|
515 PRIORITY is a numerical value that indicates this tables location
|
|
516 in an ordered search.
|
|
517 APPLICATION is the name of the application these templates belong to.
|
|
518 A list of defined variables VARS provides a variable table."
|
|
519 (let ((namehash (make-hash-table :test 'equal
|
|
520 :size (length templates)))
|
|
521 (contexthash (make-hash-table :test 'equal :size 10))
|
|
522 (lp templates)
|
|
523 )
|
|
524
|
|
525 (while lp
|
|
526
|
|
527 (let* ((objname (oref (car lp) :object-name))
|
|
528 (context (oref (car lp) :context))
|
|
529 (globalname (concat context ":" objname))
|
|
530 )
|
|
531
|
|
532 ;; Place this template object into the global name hash.
|
|
533 (puthash globalname (car lp) namehash)
|
|
534
|
|
535 ;; Place this template into the specific context name hash.
|
|
536 (let ((hs (gethash context contexthash)))
|
|
537 ;; Make a new context if none was available.
|
|
538 (when (not hs)
|
|
539 (setq hs (make-hash-table :test 'equal :size 20))
|
|
540 (puthash context hs contexthash))
|
|
541 ;; Put into that contenxt's hash.
|
|
542 (puthash objname (car lp) hs)
|
|
543 )
|
|
544
|
|
545 (setq lp (cdr lp))))
|
|
546
|
|
547 (let* ((table (srecode-mode-table-new mode (buffer-file-name)
|
|
548 :templates (nreverse templates)
|
|
549 :namehash namehash
|
|
550 :contexthash contexthash
|
|
551 :variables vars
|
|
552 :major-mode mode
|
|
553 :priority priority
|
|
554 :application application))
|
|
555 (tmpl (oref table templates)))
|
|
556 ;; Loop over all the templates, and xref.
|
|
557 (while tmpl
|
|
558 (oset (car tmpl) :table table)
|
|
559 (setq tmpl (cdr tmpl))))
|
|
560 ))
|
|
561
|
|
562
|
|
563
|
|
564 ;;; DEBUG
|
|
565 ;;
|
|
566 ;; Dump out information about the current srecoder compiled templates.
|
|
567 ;;
|
|
568
|
|
569 (defmethod srecode-dump ((tmp srecode-template))
|
|
570 "Dump the contents of the SRecode template tmp."
|
|
571 (princ "== Template \"")
|
|
572 (princ (object-name-string tmp))
|
|
573 (princ "\" in context ")
|
|
574 (princ (oref tmp context))
|
|
575 (princ "\n")
|
|
576 (when (oref tmp args)
|
|
577 (princ " Arguments: ")
|
|
578 (prin1 (oref tmp args))
|
|
579 (princ "\n"))
|
|
580 (when (oref tmp dictionary)
|
|
581 (princ " Section Dictionaries:\n")
|
|
582 (srecode-dump (oref tmp dictionary) 4)
|
|
583 ;(princ "\n")
|
|
584 )
|
|
585 (when (and (slot-boundp tmp 'binding) (oref tmp binding))
|
|
586 (princ " Binding: ")
|
|
587 (prin1 (oref tmp binding))
|
|
588 (princ "\n"))
|
|
589 (princ " Compiled Codes:\n")
|
|
590 (srecode-dump-code-list (oref tmp code) " ")
|
|
591 (princ "\n\n")
|
|
592 )
|
|
593
|
|
594 (defun srecode-dump-code-list (code indent)
|
|
595 "Dump the CODE from a template code list to standard output.
|
|
596 Argument INDENT specifies the indentation level for the list."
|
|
597 (let ((i 1))
|
|
598 (while code
|
|
599 (princ indent)
|
|
600 (prin1 i)
|
|
601 (princ ") ")
|
|
602 (cond ((stringp (car code))
|
|
603 (prin1 (car code)))
|
|
604 ((srecode-template-inserter-child-p (car code))
|
|
605 (srecode-dump (car code) indent))
|
|
606 (t
|
|
607 (princ "Unknown Code: ")
|
|
608 (prin1 (car code))))
|
|
609 (setq code (cdr code)
|
|
610 i (1+ i))
|
|
611 (when code
|
|
612 (princ "\n"))))
|
|
613 )
|
|
614
|
|
615 (defmethod srecode-dump ((ins srecode-template-inserter) indent)
|
|
616 "Dump the state of the SRecode template inserter INS."
|
|
617 (princ "INS: \"")
|
|
618 (princ (object-name-string ins))
|
|
619 (when (oref ins :secondname)
|
|
620 (princ "\" : \"")
|
|
621 (princ (oref ins :secondname)))
|
|
622 (princ "\" type \"")
|
|
623 (let* ((oc (symbol-name (object-class ins)))
|
|
624 (junk (string-match "srecode-template-inserter-" oc))
|
|
625 (on (if junk
|
|
626 (substring oc (match-end 0))
|
|
627 oc)))
|
|
628 (princ on))
|
|
629 (princ "\"")
|
|
630 )
|
|
631
|
|
632 (provide 'srecode/compile)
|
|
633
|
|
634 ;; Local variables:
|
|
635 ;; generated-autoload-file: "loaddefs.el"
|
|
636 ;; generated-autoload-feature: srecode/loaddefs
|
|
637 ;; generated-autoload-load-name: "srecode/compile"
|
|
638 ;; End:
|
|
639
|
|
640 ;;; srecode/compile.el ends here
|