Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(63)

Side by Side Diff: class-dump/src/CDTypeLexer.m

Issue 7793008: Add the 3.3.3 sources for class-dump. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/deps/third_party/
Patch Set: Created 9 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « class-dump/src/CDTypeLexer.h ('k') | class-dump/src/CDTypeName.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 // -*- mode: ObjC -*-
2
3 // This file is part of class-dump, a utility for examining the Objective-C seg ment of Mach-O files.
4 // Copyright (C) 1997-1998, 2000-2001, 2004-2010 Steve Nygard.
5
6 #import "CDTypeLexer.h"
7
8 #import "NSScanner-Extensions.h"
9
10 static BOOL debug = NO;
11
12 static NSString *CDTypeLexerStateName(CDTypeLexerState state)
13 {
14 switch (state) {
15 case CDTypeLexerStateNormal: return @"Normal";
16 case CDTypeLexerStateIdentifier: return @"Identifier";
17 case CDTypeLexerStateTemplateTypes: return @"Template";
18 }
19
20 return @"Unknown";
21 }
22
23 @implementation CDTypeLexer
24
25 - (id)initWithString:(NSString *)aString;
26 {
27 if ([super init] == nil)
28 return nil;
29
30 scanner = [[NSScanner alloc] initWithString:aString];
31 [scanner setCharactersToBeSkipped:nil];
32 state = CDTypeLexerStateNormal;
33 shouldShowLexing = debug;
34
35 return self;
36 }
37
38 - (void)dealloc;
39 {
40 [scanner release];
41 [lexText release];
42
43 [super dealloc];
44 }
45
46 - (NSScanner *)scanner;
47 {
48 return scanner;
49 }
50
51 - (CDTypeLexerState)state;
52 {
53 return state;
54 }
55
56 - (void)setState:(CDTypeLexerState)newState;
57 {
58 if (debug) NSLog(@"CDTypeLexer - changing state from %u (%@) to %u (%@)", st ate, CDTypeLexerStateName(state), newState, CDTypeLexerStateName(newState));
59 state = newState;
60 }
61
62 - (BOOL)shouldShowLexing;
63 {
64 return shouldShowLexing;
65 }
66
67 - (void)setShouldShowLexing:(BOOL)newFlag;
68 {
69 shouldShowLexing = newFlag;
70 }
71
72 - (NSString *)string;
73 {
74 return [scanner string];
75 }
76
77 - (int)scanNextToken;
78 {
79 NSString *str;
80 unichar ch;
81
82 [self _setLexText:nil];
83
84 if ([scanner isAtEnd]) {
85 if (shouldShowLexing)
86 NSLog(@"%s [state=%d], token = TK_EOS", _cmd, state);
87 return TK_EOS;
88 }
89
90 if (state == CDTypeLexerStateTemplateTypes) {
91 // Skip whitespace, scan '<', ',', '>'. Everything else is lumped toget her as a string.
92 [scanner setCharactersToBeSkipped:[NSCharacterSet whitespaceCharacterSet ]];
93 if ([scanner scanString:@"<" intoString:NULL]) {
94 if (shouldShowLexing)
95 NSLog(@"%s [state=%d], token = %d '%c'", _cmd, state, '<', '<');
96 return '<';
97 }
98
99 if ([scanner scanString:@">" intoString:NULL]) {
100 if (shouldShowLexing)
101 NSLog(@"%s [state=%d], token = %d '%c'", _cmd, state, '>', '>');
102 return '>';
103 }
104
105 if ([scanner scanString:@"," intoString:NULL]) {
106 if (shouldShowLexing)
107 NSLog(@"%s [state=%d], token = %d '%c'", _cmd, state, ',', ',');
108 return ',';
109 }
110
111 if ([scanner my_scanCharactersFromSet:[NSScanner cdTemplateTypeCharacter Set] intoString:&str]) {
112 [self _setLexText:str];
113 if (shouldShowLexing)
114 NSLog(@"%s [state=%d], token = TK_TEMPLATE_TYPE (%@)", _cmd, sta te, lexText);
115 return TK_TEMPLATE_TYPE;
116 }
117
118 NSLog(@"Ooops, fell through in template types state.");
119 } else if (state == CDTypeLexerStateIdentifier) {
120 NSString *anIdentifier;
121
122 //NSLog(@"Scanning in identifier state.");
123 [scanner setCharactersToBeSkipped:nil];
124
125 if ([scanner scanIdentifierIntoString:&anIdentifier]) {
126 [self _setLexText:anIdentifier];
127 if (shouldShowLexing)
128 NSLog(@"%s [state=%d], token = TK_IDENTIFIER (%@)", _cmd, state, lexText);
129 state = CDTypeLexerStateNormal;
130 return TK_IDENTIFIER;
131 }
132 } else {
133 [scanner setCharactersToBeSkipped:nil];
134
135 if ([scanner scanString:@"\"" intoString:NULL]) {
136 if ([scanner scanUpToString:@"\"" intoString:&str])
137 [self _setLexText:str];
138 else
139 [self _setLexText:@""];
140 [scanner scanString:@"\"" intoString:NULL];
141 if (shouldShowLexing)
142 NSLog(@"%s [state=%d], token = TK_QUOTED_STRING (%@)", _cmd, sta te, lexText);
143 return TK_QUOTED_STRING;
144 }
145
146 if ([scanner my_scanCharactersFromSet:[NSCharacterSet decimalDigitCharac terSet] intoString:&str]) {
147 [self _setLexText:str];
148 if (shouldShowLexing)
149 NSLog(@"%s [state=%d], token = TK_NUMBER (%@)", _cmd, state, lex Text);
150 return TK_NUMBER;
151 }
152
153 if ([scanner scanCharacter:&ch]) {
154 if (shouldShowLexing)
155 NSLog(@"%s [state=%d], token = %d '%c'", _cmd, state, ch, ch);
156 return ch;
157 }
158 }
159
160 if (shouldShowLexing)
161 NSLog(@"%s [state=%d], token = TK_EOS", _cmd, state);
162
163 return TK_EOS;
164 }
165
166 - (NSString *)lexText;
167 {
168 return lexText;
169 }
170
171 - (void)_setLexText:(NSString *)newString;
172 {
173 if (newString == lexText)
174 return;
175
176 [lexText release];
177 lexText = [newString retain];
178 }
179
180 - (unichar)peekChar;
181 {
182 return [scanner peekChar];
183 }
184
185 - (NSString *)remainingString;
186 {
187 return [[scanner string] substringFromIndex:[scanner scanLocation]];
188 }
189
190 - (NSString *)peekIdentifier;
191 {
192 NSScanner *aScanner;
193 NSString *anIdentifier;
194
195 aScanner = [[NSScanner alloc] initWithString:[scanner string]];
196 [aScanner setScanLocation:[scanner scanLocation]];
197
198 if ([aScanner scanIdentifierIntoString:&anIdentifier]) {
199 [aScanner release];
200 return anIdentifier;
201 }
202
203 [aScanner release];
204
205 return nil;
206 }
207
208 @end
OLDNEW
« no previous file with comments | « class-dump/src/CDTypeLexer.h ('k') | class-dump/src/CDTypeName.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698