• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 //  BufferedTreeNodeStream.h
3 //  ANTLR
4 //
5 // [The "BSD licence"]
6 // Copyright (c) 2010 Ian Michell 2010 Alan Condit
7 // All rights reserved.
8 //
9 // Redistribution and use in source and binary forms, with or without
10 // modification, are permitted provided that the following conditions
11 // are met:
12 // 1. Redistributions of source code must retain the above copyright
13 //    notice, this list of conditions and the following disclaimer.
14 // 2. Redistributions in binary form must reproduce the above copyright
15 //    notice, this list of conditions and the following disclaimer in the
16 //    documentation and/or other materials provided with the distribution.
17 // 3. The name of the author may not be used to endorse or promote products
18 //    derived from this software without specific prior written permission.
19 //
20 // THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 // IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 // IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24 // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 // NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 // THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 
31 #import <Foundation/Foundation.h>
32 #import "Tree.h"
33 #import "CommonTreeAdaptor.h"
34 #import "TokenStream.h"
35 #import "CommonTreeNodeStream.h"
36 #import "LookaheadStream.h"
37 #import "TreeIterator.h"
38 #import "IntArray.h"
39 #import "AMutableArray.h"
40 
41 #define DEFAULT_INITIAL_BUFFER_SIZE 100
42 #define INITIAL_CALL_STACK_SIZE 10
43 
44 #ifdef DONTUSENOMO
45 @interface StreamIterator : TreeIterator
46 {
47     NSInteger idx;
48     __strong BufferedTreeNodeStream *input;
49     __strong AMutableArray *nodes;
50 }
51 
52 + (id) newStreamIterator:(BufferedTreeNodeStream *) theStream;
53 
54 - (id) initWithStream:(BufferedTreeNodeStream *) theStream;
55 
56 - (BOOL) hasNext;
57 - (id) next;
58 - (void) remove;
59 @end
60 #endif
61 
62 @interface BufferedTreeNodeStream : NSObject <TreeNodeStream>
63 {
64 	id up;
65 	id down;
66 	id eof;
67 
68 	AMutableArray *nodes;
69 
70 	id root; // root
71 
72 	id<TokenStream> tokens;
73 	CommonTreeAdaptor *adaptor;
74 
75 	BOOL uniqueNavigationNodes;
76 	NSInteger index;
77 	NSInteger lastMarker;
78 	IntArray *calls;
79 
80 	NSEnumerator *e;
81     id currentSymbol;
82 
83 }
84 
85 @property (retain, getter=getUp, setter=setUp:) id up;
86 @property (retain, getter=getDown, setter=setDown:) id down;
87 @property (retain, getter=eof, setter=setEof:) id eof;
88 @property (retain, getter=getNodes, setter=setNodes:) AMutableArray *nodes;
89 @property (retain, getter=getTreeSource, setter=setTreeSource:) id root;
90 @property (retain, getter=getTokenStream, setter=setTokenStream:) id<TokenStream> tokens;
91 @property (retain, getter=getAdaptor, setter=setAdaptor:) CommonTreeAdaptor *adaptor;
92 @property (assign, getter=getUniqueNavigationNodes, setter=setUniqueNavigationNodes:) BOOL uniqueNavigationNodes;
93 @property (assign) NSInteger index;
94 @property (assign, getter=getLastMarker, setter=setLastMarker:) NSInteger lastMarker;
95 @property (retain, getter=getCalls, setter=setCalls:) IntArray *calls;
96 @property (retain, getter=getEnum, setter=setEnum:) NSEnumerator *e;
97 @property (retain, getter=getCurrentSymbol, setter=setCurrentSymbol:) id currentSymbol;
98 
99 + (BufferedTreeNodeStream *) newBufferedTreeNodeStream:(CommonTree *)tree;
100 + (BufferedTreeNodeStream *) newBufferedTreeNodeStream:(id<TreeAdaptor>)adaptor Tree:(CommonTree *)tree;
101 + (BufferedTreeNodeStream *) newBufferedTreeNodeStream:(id<TreeAdaptor>)adaptor Tree:(CommonTree *)tree withBufferSize:(NSInteger)initialBufferSize;
102 
103 #pragma mark Constructor
104 - (id) initWithTree:(CommonTree *)tree;
105 - (id) initWithTreeAdaptor:(CommonTreeAdaptor *)anAdaptor Tree:(CommonTree *)tree;
106 - (id) initWithTreeAdaptor:(CommonTreeAdaptor *)anAdaptor Tree:(CommonTree *)tree WithBufferSize:(NSInteger)bufferSize;
107 
108 - (void)dealloc;
109 - (id) copyWithZone:(NSZone *)aZone;
110 
111 // protected methods. DO NOT USE
112 #pragma mark Protected Methods
113 - (void) fillBuffer;
114 - (void) fillBufferWithTree:(CommonTree *) tree;
115 - (NSInteger) getNodeIndex:(CommonTree *) node;
116 - (void) addNavigationNode:(NSInteger) type;
117 - (id) get:(NSUInteger) i;
118 - (id) LT:(NSInteger) k;
119 - (id) getCurrentSymbol;
120 - (id) LB:(NSInteger) i;
121 #pragma mark General Methods
122 - (NSString *) getSourceName;
123 
124 - (id<TokenStream>) getTokenStream;
125 - (void) setTokenStream:(id<TokenStream>) tokens;
126 - (id<TreeAdaptor>) getTreeAdaptor;
127 - (void) setTreeAdaptor:(id<TreeAdaptor>) anAdaptor;
128 
129 - (BOOL)getUniqueNavigationNodes;
130 - (void) setUniqueNavigationNodes:(BOOL)aVal;
131 
132 - (void) consume;
133 - (NSInteger) LA:(NSInteger) i;
134 - (NSInteger) mark;
135 - (void) release:(NSInteger) marker;
136 - (void) rewind:(NSInteger) marker;
137 - (void) rewind;
138 - (void) seek:(NSInteger) idx;
139 
140 - (void) push:(NSInteger) i;
141 - (NSInteger) pop;
142 
143 - (void) reset;
144 - (NSUInteger) count;
145 - (NSEnumerator *) objectEnumerator;
146 - (void) replaceChildren:(id)parent From:(NSInteger)startChildIndex To:(NSInteger)stopChildIndex With:(id) t;
147 
148 - (NSString *) toTokenTypeString;
149 - (NSString *) toTokenString:(NSInteger)aStart ToEnd:(NSInteger)aStop;
150 - (NSString *) toStringFromNode:(id)aStart ToNode:(id)aStop;
151 
152 // getters and setters
153 - (AMutableArray *) getNodes;
154 - (id) eof;
155 - (void)setEof:(id)anEOF;
156 
157 @end
158