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

Side by Side Diff: frog/scripts/token_kind_gen.py

Issue 8763001: Fix names with '$' to not conflict with operators or internal helpers (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: merged again Created 9 years 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 | « frog/scripts/token_info.py ('k') | frog/token_kind.g.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 # Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
2 # for details. All rights reserved. Use of this source code is governed by a 2 # for details. All rights reserved. Use of this source code is governed by a
3 # BSD-style license that can be found in the LICENSE file. 3 # BSD-style license that can be found in the LICENSE file.
4 from token_info import tokens, keywords 4 from token_info import tokens, keywords
5 from codegen import CodeWriter 5 from codegen import CodeWriter
6 6
7 # TODO(jimhug): Compare perf of the switch pattern used here with maps and ifs 7 # TODO(jimhug): Compare perf of the switch pattern used here with maps and ifs
8 8
9 def main(): 9 def main():
10 '''Generates the TokenKind class into token_kind.g.dart.''' 10 '''Generates the TokenKind class into token_kind.g.dart.'''
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 53
54 cw.writeln('default: return -1;') 54 cw.writeln('default: return -1;')
55 cw.exitBlock('}') 55 cw.exitBlock('}')
56 cw.exitBlock('}') 56 cw.exitBlock('}')
57 57
58 cw.writeln() 58 cw.writeln()
59 cw.enterBlock('static String rawOperatorFromMethod(String name) {') 59 cw.enterBlock('static String rawOperatorFromMethod(String name) {')
60 cw.enterBlock('switch(name) {') 60 cw.enterBlock('switch(name) {')
61 for tok in tokens: 61 for tok in tokens:
62 if tok.methodName is not None: 62 if tok.methodName is not None:
63 dname = repr(tok.methodName).replace('$', '\\$') 63 cw.writeln('case %r: return %r;' % (tok.methodName, tok.text))
64 cw.writeln('case %s: return %s;' % (dname, repr(tok.text))) 64 cw.writeln("case ':ne': return '!=';");
65 cw.writeln("case '\\$ne': return '!=';");
66 cw.exitBlock('}') 65 cw.exitBlock('}')
67 cw.exitBlock('}') 66 cw.exitBlock('}')
68 67
69 cw.writeln() 68 cw.writeln()
70 cw.enterBlock('static String binaryMethodName(int kind) {') 69 cw.enterBlock('static String binaryMethodName(int kind) {')
71 cw.enterBlock('switch(kind) {') 70 cw.enterBlock('switch(kind) {')
72 for tok in tokens: 71 for tok in tokens:
73 if tok.methodName is not None: 72 if tok.methodName is not None:
74 dname = repr(tok.methodName).replace('$', '\\$') 73 dname = repr(tok.methodName).replace('$', '\\$')
75 cw.writeln('case %s: return %s;' % (tok.name, dname)) 74 cw.writeln('case %s: return %s;' % (tok.name, dname))
(...skipping 14 matching lines...) Expand all
90 cw.writeln('return -1;') 89 cw.writeln('return -1;')
91 cw.exitBlock('}') 90 cw.exitBlock('}')
92 91
93 92
94 93
95 cw.exitBlock('}') 94 cw.exitBlock('}')
96 95
97 cw.writeToFile('token_kind') 96 cw.writeToFile('token_kind')
98 97
99 if __name__ == '__main__': main() 98 if __name__ == '__main__': main()
OLDNEW
« no previous file with comments | « frog/scripts/token_info.py ('k') | frog/token_kind.g.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698