• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1//
2//  ANTLRBaseRecognizer.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#define SUCCESS (0)
33#define FAILURE (-1)
34
35#import "ANTLRBaseStack.h"
36#import "ANTLRTree.h"
37
38/*
39 * Start of ANTLRBaseStack
40 */
41@implementation ANTLRBaseStack
42
43@synthesize LastHash;
44
45+(ANTLRBaseStack *)newANTLRBaseStack
46{
47    return [[ANTLRBaseStack alloc] init];
48}
49
50+(ANTLRBaseStack *)newANTLRBaseStackWithLen:(NSInteger)cnt
51{
52    return [[ANTLRBaseStack alloc] initWithLen:cnt];
53}
54
55-(id)init
56{
57	self = [super initWithLen:HASHSIZE];
58	if ( self != nil ) {
59	}
60    return( self );
61}
62
63-(id)initWithLen:(NSInteger)cnt
64{
65	self = [super initWithLen:cnt];
66    if ( self != nil ) {
67	}
68    return( self );
69}
70
71- (void)dealloc
72{
73#ifdef DEBUG_DEALLOC
74    NSLog( @"called dealloc in ANTLRBaseStack" );
75#endif
76	[super dealloc];
77}
78
79- (id) copyWithZone:(NSZone *)aZone
80{
81    ANTLRBaseStack *copy;
82
83    copy = [super copyWithZone:aZone];
84    return copy;
85}
86
87- (NSUInteger)count
88{
89    NSUInteger aCnt = 0;
90
91    for (int i = 0; i < BuffSize; i++) {
92        if (ptrBuffer[i] != nil) {
93            aCnt++;
94        }
95    }
96    return aCnt;
97}
98
99- (NSUInteger) size
100{
101    return BuffSize;
102}
103
104-(void)deleteANTLRBaseStack:(ANTLRBaseStack *)np
105{
106    id tmp, rtmp;
107    NSInteger idx;
108
109    if ( self.fNext != nil ) {
110        for( idx = 0; idx < BuffSize; idx++ ) {
111            tmp = (ANTLRLinkBase *)ptrBuffer[idx];
112            while ( tmp ) {
113                rtmp = tmp;
114                tmp = [tmp getfNext];
115                [rtmp release];
116            }
117        }
118    }
119}
120
121- (NSInteger)getLastHash
122{
123    return LastHash;
124}
125
126- (void)setLastHash:(NSInteger)aVal
127{
128    LastHash = aVal;
129}
130
131@end
132