Home | History | Annotate | Download | only in Framework
      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     //    TStringPool *fPool;
     41     NSInteger Scope;
     42     NSInteger LastHash;
     43     NSInteger BuffSize;
     44     NSUInteger count;
     45     NSUInteger ptr;
     46     __strong NSMutableData *buffer;
     47     __strong ANTLRMapElement **ptrBuffer;
     48     NSInteger mode;
     49 }
     50 
     51 // Contruction/Destruction
     52 + (id)newANTLRHashMap;
     53 + (id)newANTLRHashMapWithLen:(NSInteger)aBuffSize;
     54 - (id)init;
     55 - (id)initWithLen:(NSInteger)aBuffSize;
     56 - (void)dealloc;
     57 - (ANTLRHashMap *)PushScope:( ANTLRHashMap **)map;
     58 - (ANTLRHashMap *)PopScope:( ANTLRHashMap **)map;
     59 
     60 - (NSInteger)count;
     61 - (NSInteger)size;
     62 
     63 // Instance Methods
     64 /*    form hash value for string s */
     65 - (NSInteger)hash:(NSString *)s;
     66 /*   look for s in ptrBuffer  */
     67 - (ANTLRHashMap *)findscope:(int)level;
     68 /*   look for s in ptrBuffer  */
     69 - (id)lookup:(NSString *)s Scope:(int)scope;
     70 /*   look for s in ptrBuffer  */
     71 - (id)install:(ANTLRMapElement *)sym Scope:(int)scope;
     72 /*   look for s in ptrBuffer  */
     73 - (void)deleteANTLRHashMap:(ANTLRMapElement *)np;
     74 - (int)RemoveSym:(NSString *)s;
     75 - (void)delete_chain:(ANTLRMapElement *)np;
     76 #ifdef DONTUSEYET
     77 - (int)bld_symtab:(KW_TABLE *)toknams;
     78 #endif
     79 - (ANTLRMapElement **)getptrBuffer;
     80 - (ANTLRMapElement *)getptrBufferEntry:(int)idx;
     81 - (void)setptrBuffer:(ANTLRMapElement *)np Index:(int)idx;
     82 - (NSInteger)getScope;
     83 - (void)setScope:(NSInteger)i;
     84 - (ANTLRMapElement *)getTType:(NSString *)name;
     85 - (ANTLRMapElement *)getNameInList:(NSInteger)ttype;
     86 - (void)putNode:(NSString *)name TokenType:(NSInteger)ttype;
     87 - (NSInteger)getMode;
     88 - (void)setMode:(NSInteger)aMode;
     89 - (void) insertObject:(id)aRule atIndex:(NSInteger)idx;
     90 - (id) objectAtIndex:(NSInteger)idx;
     91 - (void) setObject:(id)aRule atIndex:(NSInteger)idx;
     92 - (void)addObject:(id)anObject;
     93 - (ANTLRMapElement *) getName:(NSString *)aName;
     94 - (void) putName:(NSString *)name Node:(id)aNode;
     95 
     96 - (NSEnumerator *)objectEnumerator;
     97 - (BOOL) hasNext;
     98 - (ANTLRMapElement *)nextObject;
     99 
    100 //@property (copy) TStringPool *fPool;
    101 @property (getter=getScope, setter=setScope:) NSInteger Scope;
    102 @property (getter=getLastHash, setter=setLastHash:) NSInteger LastHash;
    103 
    104 @property (getter=getMode,setter=setMode:) NSInteger mode;
    105 @property NSInteger BuffSize;
    106 @property (getter=getCount, setter=setCount:) NSUInteger count;
    107 @property (assign) NSUInteger ptr;
    108 @property (retain, getter=getBuffer, setter=setBuffer:) NSMutableData *buffer;
    109 @property (assign, getter=getPtrBuffer, setter=setPtrBuffer:) ANTLRMapElement **ptrBuffer;
    110 @end
    111