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