1//
2//  ANTLRRuleMemo.m
3//  ANTLR
4//
5//  Created by Alan Condit on 6/16/10.
6// [The "BSD licence"]
7// Copyright (c) 2010 Alan Condit
8// All rights reserved.
9//
10// Redistribution and use in source and binary forms, with or without
11// modification, are permitted provided that the following conditions
12// are met:
13// 1. Redistributions of source code must retain the above copyright
14//    notice, this list of conditions and the following disclaimer.
15// 2. Redistributions in binary form must reproduce the above copyright
16//    notice, this list of conditions and the following disclaimer in the
17//    documentation and/or other materials provided with the distribution.
18// 3. The name of the author may not be used to endorse or promote products
19//    derived from this software without specific prior written permission.
20//
21// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24// IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26// NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
32#import "ANTLRRuleMemo.h"
33
34
35@implementation ANTLRRuleMemo
36
37@synthesize startIndex;
38@synthesize stopIndex;
39
40+ (ANTLRRuleMemo *)newANTLRRuleMemo
41{
42    return [[ANTLRRuleMemo alloc] init];
43}
44
45+ (ANTLRRuleMemo *)newANTLRRuleMemoWithStartIndex:(NSNumber *)anIndex StopIndex:(NSNumber *)aStopIndex
46{
47    return [[ANTLRRuleMemo alloc] initWithStartIndex:anIndex StopIndex:aStopIndex];
48}
49
50- (id) init
51{
52    if ((self = [super init]) != nil ) {
53        startIndex = nil;
54        stopIndex = nil;
55    }
56    return (self);
57}
58
59- (id) initWithStartIndex:(NSNumber *)aStartIndex StopIndex:(NSNumber *)aStopIndex
60{
61    if ((self = [super init]) != nil ) {
62        [aStartIndex retain];
63        startIndex = aStartIndex;
64        [aStopIndex retain];
65        stopIndex = aStopIndex;
66    }
67    return (self);
68}
69
70- (id) copyWithZone:(NSZone *)aZone
71{
72    ANTLRRuleMemo *copy;
73
74    copy = [super copyWithZone:aZone];
75    copy.startIndex = startIndex;
76    copy.stopIndex = stopIndex;
77    return( copy );
78}
79
80- (NSInteger)count
81{
82    NSInteger aCnt = 0;
83
84    if (startIndex != nil) aCnt++;
85    if (stopIndex != nil) aCnt++;
86    return aCnt;
87}
88
89- (NSInteger) size
90{
91    return (2 * sizeof(id));
92}
93
94- (ANTLRRuleMemo *)getRuleWithStartIndex:(NSInteger)aStartIndex
95{
96    ANTLRRuleMemo *aMatchMemo = self;
97    do {
98        if (aStartIndex == [aMatchMemo.startIndex integerValue] ) {
99            return aMatchMemo;
100        }
101        aMatchMemo = aMatchMemo.fNext;
102    } while ( aMatchMemo != nil );
103    return nil;
104}
105
106- (NSNumber *)getStartIndex:(NSInteger)aStartIndex
107{
108    ANTLRRuleMemo *aMatchMemo = self;
109    do {
110        if (aStartIndex == [aMatchMemo.startIndex integerValue] ) {
111            return aMatchMemo.stopIndex;
112        }
113        aMatchMemo = aMatchMemo.fNext;
114    } while ( aMatchMemo != nil );
115    return nil;
116}
117
118- (NSNumber *)getStopIndex:(NSInteger)aStartIndex
119{
120    ANTLRRuleMemo *aMatchMemo = self;
121    do {
122        if (aStartIndex == [aMatchMemo.startIndex integerValue] ) {
123            return aMatchMemo.stopIndex;
124        }
125        aMatchMemo = aMatchMemo.fNext;
126    } while ( aMatchMemo != nil );
127    return nil;
128}
129
130- (NSNumber *)getStartIndex;
131{
132    return startIndex;
133}
134
135- (void)setStartIndex:(NSNumber *)aStartIndex
136{
137    if ( aStartIndex != startIndex ) {
138        if ( startIndex ) [startIndex release];
139        [aStartIndex retain];
140    }
141    startIndex = aStartIndex;
142}
143
144- (NSNumber *)getStopIndex;
145{
146    return stopIndex;
147}
148
149- (void)setStopIndex:(NSNumber *)aStopIndex
150{
151    if ( aStopIndex != stopIndex ) {
152        if ( stopIndex ) [stopIndex release];
153        [aStopIndex retain];
154    }
155    stopIndex = aStopIndex;
156}
157
158@end
159