Home | History | Annotate | Download | only in Framework
      1 //
      2 //  ANTLRRuntimeException.m
      3 //  ANTLR
      4 //
      5 //  Created by Alan Condit on 6/5/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 "ANTLRRuntimeException.h"
     33 
     34 
     35 @implementation ANTLRRuntimeException
     36 
     37 + (id) newException
     38 {
     39     return [[ANTLRRuntimeException alloc] init];
     40 }
     41 
     42 + (id) newException:(NSString *)aReason
     43 {
     44     return [[ANTLRRuntimeException alloc] init:aReason];
     45 }
     46 
     47 + (id) newException:(NSString *)aReason userInfo:(NSDictionary *)aUserInfo
     48 {
     49     return [[ANTLRRuntimeException alloc] init:aReason userInfo:aUserInfo];
     50 }
     51 
     52 + (id) newException:(NSString *)aName reason:(NSString *)aReason;
     53 {
     54     return [[ANTLRRuntimeException alloc] initWithName:aName reason:aReason];
     55 }
     56 
     57 + (id) newException:(NSString *)aName reason:(NSString *)aReason userInfo:(NSDictionary *)aUserInfo;
     58 {
     59     return [[ANTLRRuntimeException alloc] initWithName:aName reason:aReason userInfo:aUserInfo];
     60 }
     61 
     62 
     63 - (id) init
     64 {
     65     self = [super initWithName:@"ANTLRRuntimeException" reason:@"UnknownException" userInfo:nil];
     66     return(self);
     67 }
     68 
     69 - (id) init:(NSString *)aReason
     70 {
     71     self = [super initWithName:(NSString *)@"ANTLRRuntimeException" reason:(NSString *)aReason userInfo:(NSDictionary *)nil];
     72     return(self);
     73 }
     74 
     75 - (id) init:(NSString *)aReason userInfo:(NSDictionary *)aUserInfo
     76 {
     77     self = [super initWithName:@"ANTLRRuntimeException" reason:aReason userInfo:aUserInfo];
     78     return(self);
     79 }
     80 
     81 - (id) initWithName:(NSString *)aName reason:(NSString *)aReason
     82 {
     83     self = [super initWithName:(NSString *)aName reason:(NSString *)aReason userInfo:(NSDictionary *)nil];
     84     return(self);
     85 }
     86 
     87 - (id) initWithName:(NSString *)aName reason:(NSString *)aReason userInfo:(NSDictionary *)aUserInfo
     88 {
     89     self = [super initWithName:(NSString *)aName reason:(NSString *)aReason userInfo:(NSDictionary *)aUserInfo];
     90     return(self);
     91 }
     92 
     93 - (NSString *) Description
     94 {
     95     return [super reason];
     96 }
     97 
     98 - (id) stackTrace:(NSException *)e
     99 {
    100     NSArray *addrs = [e callStackReturnAddresses];
    101     NSArray *trace = [e callStackSymbols];
    102     
    103     for (NSString *traceStr in trace) {
    104         NSLog( @"%@", traceStr);
    105         // TODO: remove special after testing
    106         if ([traceStr hasPrefix:@"main("] > 0)
    107             return traceStr;
    108         if (![traceStr hasPrefix:@"org.stringtemplate"])
    109             return traceStr;
    110     }
    111     return trace;    
    112 }
    113 
    114 @end
    115 
    116 @implementation ANTLRIllegalArgumentException
    117 
    118 + (id) newException
    119 {
    120     return [[ANTLRIllegalArgumentException alloc] init];
    121 }
    122 
    123 + (id) newException:(NSString *)aReason
    124 {
    125     return [[ANTLRIllegalArgumentException alloc] init:aReason];
    126 }
    127 
    128 + (id) newException:(NSString *)aReason userInfo:(NSDictionary *)aUserInfo
    129 {
    130     return [[ANTLRIllegalArgumentException alloc] init:aReason userInfo:aUserInfo];
    131 }
    132 
    133 - (id) init
    134 {
    135     self = [super initWithName:@"ANTLRIllegalArgumentException" reason:@"UnknownException" userInfo:nil];
    136     return(self);
    137 }
    138 
    139 - (id) init:(NSString *)aReason
    140 {
    141     self = [super initWithName:@"ANTLRIllegalArgumentException" reason:(NSString *)aReason userInfo:nil];
    142     return(self);
    143 }
    144 
    145 - (id) init:(NSString *)aReason userInfo:(NSDictionary *)aUserInfo
    146 {
    147     self = [super initWithName:@"ANTLRIllegalArgumentException" reason:aReason userInfo:aUserInfo];
    148     return(self);
    149 }
    150 
    151 @end
    152 
    153 @implementation ANTLRIllegalStateException
    154 
    155 + (id) newException
    156 {
    157     return [[ANTLRIllegalStateException alloc] init];
    158 }
    159 
    160 + (id) newException:(NSString *)aReason
    161 {
    162     return [[ANTLRIllegalStateException alloc] init:aReason];
    163 }
    164 
    165 + (id) newException:(NSString *)aReason userInfo:(NSDictionary *)aUserInfo
    166 {
    167     return [[ANTLRIllegalStateException alloc] init:aReason userInfo:aUserInfo];
    168 }
    169 
    170 - (id) init
    171 {
    172     self = [super initWithName:@"ANTLRIllegalStateException" reason:@"UnknownException" userInfo:nil];
    173     return(self);
    174 }
    175 
    176 - (id) init:(NSString *)aReason
    177 {
    178     self = [super initWithName:@"ANTLRIllegalStateException" reason:(NSString *)aReason userInfo:nil];
    179     return(self);
    180 }
    181 
    182 - (id) init:(NSString *)aReason userInfo:(NSDictionary *)aUserInfo
    183 {
    184     self = [super initWithName:@"ANTLRIllegalStateException" reason:aReason userInfo:aUserInfo];
    185     return(self);
    186 }
    187 
    188 @end
    189 
    190 @implementation ANTLRNoSuchElementException
    191 
    192 + (id) newException
    193 {
    194     return [[ANTLRNoSuchElementException alloc] init];
    195 }
    196 
    197 + (id) newException:(NSString *)aReason
    198 {
    199     return [[ANTLRNoSuchElementException alloc] init:aReason];
    200 }
    201 
    202 + (id) newException:(NSString *)aReason userInfo:(NSDictionary *)aUserInfo
    203 {
    204     return [[ANTLRNoSuchElementException alloc] init:aReason userInfo:(NSDictionary *)aUserInfo];
    205 }
    206 
    207 - (id) init
    208 {
    209     self = [super initWithName:@"ANTLRNoSuchElementException" reason:@"UnknownException" userInfo:nil];
    210     return(self);
    211 }
    212 
    213 - (id) init:(NSString *)aReason
    214 {
    215     self = [super initWithName:@"ANTLRNoSuchElementException" reason:(NSString *)aReason userInfo:(NSDictionary *)nil];
    216     return(self);
    217 }
    218 
    219 - (id) init:(NSString *)aReason userInfo:(NSDictionary *)aUserInfo
    220 {
    221     self = [super initWithName:@"ANTLRNoSuchElementException" reason:aReason userInfo:aUserInfo];
    222     return(self);
    223 }
    224 
    225 - (id) initWithName:(NSString *)aName reason:(NSString *)aReason userInfo:(NSDictionary *)aUserInfo
    226 {
    227     self = [super initWithName:aName reason:aReason userInfo:aUserInfo];
    228     return(self);
    229 }
    230 
    231 @end
    232 
    233 @implementation ANTLRRewriteEarlyExitException
    234 
    235 + (id) newException
    236 {
    237 	return [[self alloc] init];
    238 }
    239 
    240 - (id) init
    241 {
    242 	self = [super initWithName:@"RewriteEarlyExitException" reason:nil userInfo:nil];
    243 	return self;
    244 }
    245 
    246 - (id) initWithName:(NSString *)aName reason:(NSString *)aReason userInfo:(NSDictionary *)aUserInfo
    247 {
    248     self = [super initWithName:aName reason:aReason userInfo:aUserInfo];
    249     return(self);
    250 }
    251 
    252 - (NSString *) description
    253 {
    254 	return [self name];
    255 }
    256 
    257 @end
    258 
    259 @implementation ANTLRUnsupportedOperationException
    260 
    261 + (id) newException:(NSString *)aReason
    262 {
    263     return [[ANTLRRuntimeException alloc] initWithName:@"Unsupported Operation Exception" reason:aReason userInfo:nil];
    264 }
    265 
    266 - (id) initWithName:(NSString *)aName reason:(NSString *)aReason
    267 {
    268     self=[super initWithName:aName reason:aReason userInfo:nil];
    269     return self;
    270 }
    271 
    272 - (id) initWithName:(NSString *)aName reason:(NSString *)aReason userInfo:(NSDictionary *)userInfo
    273 {
    274     self=[super initWithName:aName reason:aReason userInfo:userInfo];
    275     return self;
    276 }
    277 
    278 @end
    279 
    280