KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > antlr > works > debugger > tivo > DBRecorderEventListener


1 package org.antlr.works.debugger.tivo;
2
3 import org.antlr.runtime.RecognitionException;
4 import org.antlr.runtime.Token;
5 import org.antlr.runtime.debug.DebugEventListener;
6 import org.antlr.runtime.debug.RemoteDebugEventSocketListener;
7 import org.antlr.runtime.debug.RemoteDebugEventSocketListener.ProxyTree;
8 import org.antlr.works.debugger.events.DBEvent;
9 import org.antlr.works.debugger.events.DBEventFactory;
10 import org.antlr.works.debugger.tree.DBTreeToken;
11 /*
12
13 [The "BSD licence"]
14 Copyright (c) 2005-2006 Jean Bovet
15 All rights reserved.
16
17 Redistribution and use in source and binary forms, with or without
18 modification, are permitted provided that the following conditions
19 are met:
20
21 1. Redistributions of source code must retain the above copyright
22 notice, this list of conditions and the following disclaimer.
23 2. Redistributions in binary form must reproduce the above copyright
24 notice, this list of conditions and the following disclaimer in the
25 documentation and/or other materials provided with the distribution.
26 3. The name of the author may not be used to endorse or promote products
27 derived from this software without specific prior written permission.
28
29 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
30 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
31 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
32 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
33 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
34 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
38 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39
40 */

41
42 public class DBRecorderEventListener implements DebugEventListener {
43
44     public DBRecorder recorder;
45
46     public DBRecorderEventListener(DBRecorder recorder) {
47         this.recorder = recorder;
48     }
49
50     public void event(DBEvent event) {
51         recorder.listenerEvent(event);
52     }
53
54     public void commence() {
55         event(DBEventFactory.createCommence());
56     }
57
58     public void terminate() {
59         event(DBEventFactory.createTerminate());
60     }
61
62     public void enterRule(String JavaDoc ruleName) {
63         event(DBEventFactory.createEnterRule(ruleName));
64     }
65
66     public void exitRule(String JavaDoc ruleName) {
67         event(DBEventFactory.createExitRule(ruleName));
68     }
69
70     public void enterSubRule(int decisionNumber) {
71         event(DBEventFactory.createEnterSubRule(decisionNumber));
72     }
73
74     public void exitSubRule(int decisionNumber) {
75         event(DBEventFactory.createExitSubRule(decisionNumber));
76     }
77
78     public void enterDecision(int decisionNumber) {
79         event(DBEventFactory.createEnterDecision(decisionNumber));
80     }
81
82     public void exitDecision(int decisionNumber) {
83         event(DBEventFactory.createExitDecision(decisionNumber));
84     }
85
86     public void enterAlt(int alt) {
87         event(DBEventFactory.createEnterAlt(alt));
88     }
89
90     public void location(int line, int pos) {
91         event(DBEventFactory.createLocation(line, pos));
92     }
93
94     public void consumeToken(Token token) {
95         event(DBEventFactory.createConsumeToken(token));
96     }
97
98     public void consumeHiddenToken(Token token) {
99         event(DBEventFactory.createConsumeHiddenToken(token));
100     }
101
102     public void LT(int i, Token token) {
103         event(DBEventFactory.createLT(i, token));
104     }
105
106     public void mark(int i) {
107         event(DBEventFactory.createMark(i));
108     }
109
110     public void rewind(int i) {
111         event(DBEventFactory.createRewind(i));
112     }
113
114     public void rewind() {
115         event(DBEventFactory.createRewind());
116     }
117
118     public void beginBacktrack(int level) {
119         event(DBEventFactory.createBeginBacktrack(level));
120     }
121
122     public void endBacktrack(int level, boolean successful) {
123         event(DBEventFactory.createEndBacktrack(level, successful));
124     }
125
126     public void recognitionException(RecognitionException e) {
127         event(DBEventFactory.createRecognitionException(e));
128     }
129
130     public void beginResync() {
131         event(DBEventFactory.createBeginResync());
132     }
133
134     public void endResync() {
135         event(DBEventFactory.createEndResync());
136     }
137
138     public void semanticPredicate(boolean result, String JavaDoc predicate) {
139         /** Currently ignored */
140     }
141
142     /** AST events */
143
144     public void nilNode(Object JavaDoc t) {
145         RemoteDebugEventSocketListener.ProxyTree p = (RemoteDebugEventSocketListener.ProxyTree)t;
146         event(DBEventFactory.createNilNode(p.ID));
147     }
148
149     public void createNode(Object JavaDoc t) {
150         RemoteDebugEventSocketListener.ProxyTree p = (RemoteDebugEventSocketListener.ProxyTree)t;
151         event(DBEventFactory.createCreateNode(p.ID, p.text, p.type));
152     }
153
154     public void createNode(Object JavaDoc node, Token token) {
155         RemoteDebugEventSocketListener.ProxyTree p = (RemoteDebugEventSocketListener.ProxyTree)node;
156         event(DBEventFactory.createCreateNode(p.ID, token.getTokenIndex()));
157     }
158
159     public void becomeRoot(Object JavaDoc newRoot, Object JavaDoc oldRoot) {
160         RemoteDebugEventSocketListener.ProxyTree n = (RemoteDebugEventSocketListener.ProxyTree)newRoot;
161         RemoteDebugEventSocketListener.ProxyTree o = (RemoteDebugEventSocketListener.ProxyTree)oldRoot;
162         event(DBEventFactory.createBecomeRoot(n.ID, o.ID));
163     }
164
165     public void addChild(Object JavaDoc root, Object JavaDoc child) {
166         RemoteDebugEventSocketListener.ProxyTree r = (RemoteDebugEventSocketListener.ProxyTree)root;
167         RemoteDebugEventSocketListener.ProxyTree c = (RemoteDebugEventSocketListener.ProxyTree)child;
168         event(DBEventFactory.createAddChild(r.ID, c.ID));
169     }
170
171     public void setTokenBoundaries(Object JavaDoc t, int tokenStartIndex, int tokenStopIndex) {
172         RemoteDebugEventSocketListener.ProxyTree p = (RemoteDebugEventSocketListener.ProxyTree)t;
173         event(DBEventFactory.createSetTokenBoundaries(p.ID, tokenStartIndex, tokenStopIndex));
174     }
175
176     /** Tree parsing */
177
178     public void consumeNode(Object JavaDoc t) {
179         ProxyTree p = (ProxyTree)t;
180         /** Create a special kind of token holding information about the tree node. This allow
181          * us to use the same method for token parser and tree parser.
182          */

183         event(DBEventFactory.createConsumeToken(new DBTreeToken(p)));
184     }
185
186     public void LT(int i, Object JavaDoc t) {
187         ProxyTree p = (ProxyTree)t;
188         /** See consumeNode() comment */
189         event(DBEventFactory.createLT(i, new DBTreeToken(p)));
190     }
191
192 }
193
Popular Tags