1//
2//  ANTLRHashMap.h
3//  ANTLR
4//
5// Copyright (c) 2010 Alan Condit
6// All rights reserved.
7//
8// Redistribution and use in source and binary forms, with or without
9// modification, are permitted provided that the following conditions
10// are met:
11// 1. Redistributions of source code must retain the above copyright
12//    notice, this list of conditions and the following disclaimer.
13// 2. Redistributions in binary form must reproduce the above copyright
14//    notice, this list of conditions and the following disclaimer in the
15//    documentation and/or other materials provided with the distribution.
16// 3. The name of the author may not be used to endorse or promote products
17//    derived from this software without specific prior written permission.
18//
19// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22// IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24// NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
30#import <Cocoa/Cocoa.h>
31#import "ANTLRLinkBase.h"
32#import "ANTLRMapElement.h"
33
34#define GLOBAL_SCOPE       0
35#define LOCAL_SCOPE        1
36#define HASHSIZE         101
37#define HBUFSIZE      0x2000
38
39@interface ANTLRHashMap : ANTLRLinkBase {
40	//	ANTLRHashMap *fNext;
41    //    TStringPool *fPool;
42    NSInteger Scope;
43    NSInteger LastHash;
44    NSInteger BuffSize;
45    ANTLRMapElement *ptrBuffer[HASHSIZE];
46    NSInteger mode;
47}
48
49//@property (copy) ANTLRHashMap *fNext;
50//@property (copy) TStringPool *fPool;
51@property (getter=getScope, setter=setScope:) NSInteger Scope;
52@property (getter=getLastHash, setter=setLastHash:) NSInteger LastHash;
53
54// Contruction/Destruction
55+ (id)newANTLRHashMap;
56+ (id)newANTLRHashMapWithLen:(NSInteger)aBuffSize;
57- (id)init;
58- (id)initWithLen:(NSInteger)aBuffSize;
59- (void)dealloc;
60- (ANTLRHashMap *)PushScope:( ANTLRHashMap **)map;
61- (ANTLRHashMap *)PopScope:( ANTLRHashMap **)map;
62
63- (NSInteger)count;
64- (NSInteger)size;
65
66// Instance Methods
67/*    form hash value for string s */
68- (NSInteger)hash:(NSString *)s;
69/*   look for s in ptrBuffer  */
70- (ANTLRHashMap *)findscope:(int)level;
71/*   look for s in ptrBuffer  */
72- (id)lookup:(NSString *)s Scope:(int)scope;
73/*   look for s in ptrBuffer  */
74- (id)install:(ANTLRMapElement *)sym Scope:(int)scope;
75/*   look for s in ptrBuffer  */
76- (void)deleteANTLRHashMap:(ANTLRMapElement *)np;
77- (int)RemoveSym:(NSString *)s;
78- (void)delete_chain:(ANTLRMapElement *)np;
79#ifdef DONTUSEYET
80- (int)bld_symtab:(KW_TABLE *)toknams;
81#endif
82- (ANTLRMapElement **)getptrBuffer;
83- (ANTLRMapElement *)getptrBufferEntry:(int)idx;
84- (void)setptrBuffer:(ANTLRMapElement *)np Index:(int)idx;
85- (NSInteger)getScope;
86- (void)setScope:(NSInteger)i;
87- (ANTLRMapElement *)getTType:(NSString *)name;
88- (ANTLRMapElement *)getNameInList:(NSInteger)ttype;
89- (void)putNode:(NSString *)name TokenType:(NSInteger)ttype;
90- (NSInteger)getMode;
91- (void)setMode:(NSInteger)aMode;
92- (void) insertObject:(id)aRule atIndex:(NSInteger)idx;
93- (id) objectAtIndex:(NSInteger)idx;
94- (void) setObject:(id)aRule atIndex:(NSInteger)idx;
95- (void)addObject:(id)anObject;
96- (ANTLRMapElement *) getName:(NSString *)aName;
97- (void) putName:(NSString *)name Node:(id)aNode;
98
99- (NSEnumerator *)objectEnumerator;
100- (BOOL) hasNext;
101- (ANTLRMapElement *)nextObject;
102@end
103