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

Side by Side Diff: tools/dom/scripts/idlnode.py

Issue 13704011: Map enums to strings. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 8 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 | « tools/dom/scripts/generator.py ('k') | tools/dom/scripts/idlrenderer.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/python 1 #!/usr/bin/python
2 # Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 2 # Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
3 # for details. All rights reserved. Use of this source code is governed by a 3 # for details. All rights reserved. Use of this source code is governed by a
4 # BSD-style license that can be found in the LICENSE file. 4 # BSD-style license that can be found in the LICENSE file.
5 5
6 import os 6 import os
7 import sys 7 import sys
8 8
9 9
10 class IDLNode(object): 10 class IDLNode(object):
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 """IDLFile is the top-level node in each IDL file. It may contain interfaces." "" 252 """IDLFile is the top-level node in each IDL file. It may contain interfaces." ""
253 253
254 def __init__(self, ast, filename=None): 254 def __init__(self, ast, filename=None):
255 IDLNode.__init__(self, ast) 255 IDLNode.__init__(self, ast)
256 self.filename = filename 256 self.filename = filename
257 self.interfaces = self._convert_all(ast, 'Interface', IDLInterface) 257 self.interfaces = self._convert_all(ast, 'Interface', IDLInterface)
258 modules = self._convert_all(ast, 'Module', IDLModule) 258 modules = self._convert_all(ast, 'Module', IDLModule)
259 self.implementsStatements = self._convert_all(ast, 'ImplStmt', 259 self.implementsStatements = self._convert_all(ast, 'ImplStmt',
260 IDLImplementsStatement) 260 IDLImplementsStatement)
261 self.typeDefs = self._convert_all(ast, 'TypeDef', IDLTypeDef) 261 self.typeDefs = self._convert_all(ast, 'TypeDef', IDLTypeDef)
262 self.enums = self._convert_all(ast, 'Enum', IDLEnum)
262 for module in modules: 263 for module in modules:
263 self.interfaces.extend(module.interfaces) 264 self.interfaces.extend(module.interfaces)
264 self.implementsStatements.extend(module.implementsStatements) 265 self.implementsStatements.extend(module.implementsStatements)
265 self.typeDefs.extend(module.typeDefs) 266 self.typeDefs.extend(module.typeDefs)
266 267
267 268
268 class IDLModule(IDLNode): 269 class IDLModule(IDLNode):
269 """IDLModule has an id, and may contain interfaces, type defs and 270 """IDLModule has an id, and may contain interfaces, type defs and
270 implements statements.""" 271 implements statements."""
271 def __init__(self, ast): 272 def __init__(self, ast):
272 IDLNode.__init__(self, ast) 273 IDLNode.__init__(self, ast)
273 self._convert_ext_attrs(ast) 274 self._convert_ext_attrs(ast)
274 self._convert_annotations(ast) 275 self._convert_annotations(ast)
275 self.interfaces = self._convert_all(ast, 'Interface', IDLInterface) 276 self.interfaces = self._convert_all(ast, 'Interface', IDLInterface)
276 self.typeDefs = self._convert_all(ast, 'TypeDef', IDLTypeDef) 277 self.typeDefs = self._convert_all(ast, 'TypeDef', IDLTypeDef)
278 self.enums = self._convert_all(ast, 'Enum', IDLNode)
277 self.implementsStatements = self._convert_all(ast, 'ImplStmt', 279 self.implementsStatements = self._convert_all(ast, 'ImplStmt',
278 IDLImplementsStatement) 280 IDLImplementsStatement)
279 281
280 282
281 class IDLExtAttrs(IDLDictNode): 283 class IDLExtAttrs(IDLDictNode):
282 """IDLExtAttrs is an IDLDictNode that stores IDL Extended Attributes. 284 """IDLExtAttrs is an IDLDictNode that stores IDL Extended Attributes.
283 Modules, interfaces, members and arguments can all own IDLExtAttrs.""" 285 Modules, interfaces, members and arguments can all own IDLExtAttrs."""
284 def __init__(self, ast=None): 286 def __init__(self, ast=None):
285 IDLDictNode.__init__(self, None) 287 IDLDictNode.__init__(self, None)
286 if not ast: 288 if not ast:
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 elif label.endswith('Type'): 373 elif label.endswith('Type'):
372 # Omit 'Type' suffix and lowercase the rest. 374 # Omit 'Type' suffix and lowercase the rest.
373 label = '%s%s' % (label[0].lower(), label[1:-4]) 375 label = '%s%s' % (label[0].lower(), label[1:-4])
374 376
375 # Add unsigned qualifier. 377 # Add unsigned qualifier.
376 if self._has(ast, 'Unsigned'): 378 if self._has(ast, 'Unsigned'):
377 label = 'unsigned %s' % label 379 label = 'unsigned %s' % label
378 return label 380 return label
379 381
380 382
383 class IDLEnum(IDLNode):
384 """IDLNode for 'enum [id] { [string]+ }'"""
385 def __init__(self, ast):
386 IDLNode.__init__(self, ast)
387 self._convert_annotations(ast)
388 # TODO(antonm): save enum values.
389
390
381 class IDLTypeDef(IDLNode): 391 class IDLTypeDef(IDLNode):
382 """IDLNode for 'typedef [type] [id]' declarations.""" 392 """IDLNode for 'typedef [type] [id]' declarations."""
383 def __init__(self, ast): 393 def __init__(self, ast):
384 IDLNode.__init__(self, ast) 394 IDLNode.__init__(self, ast)
385 self._convert_annotations(ast) 395 self._convert_annotations(ast)
386 self.type = self._convert_first(ast, 'Type', IDLType) 396 self.type = self._convert_first(ast, 'Type', IDLType)
387 397
388 398
389 class IDLInterface(IDLNode): 399 class IDLInterface(IDLNode):
390 """IDLInterface node contains operations, attributes, constants, 400 """IDLInterface node contains operations, attributes, constants,
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
527 """IDLDictNode specialization for one annotation.""" 537 """IDLDictNode specialization for one annotation."""
528 def __init__(self, ast=None): 538 def __init__(self, ast=None):
529 IDLDictNode.__init__(self, ast) 539 IDLDictNode.__init__(self, ast)
530 self.id = None 540 self.id = None
531 if not ast: 541 if not ast:
532 return 542 return
533 for arg in self._find_all(ast, 'AnnotationArg'): 543 for arg in self._find_all(ast, 'AnnotationArg'):
534 name = self._find_first(arg, 'Id') 544 name = self._find_first(arg, 'Id')
535 value = self._find_first(arg, 'AnnotationArgValue') 545 value = self._find_first(arg, 'AnnotationArgValue')
536 self[name] = value 546 self[name] = value
OLDNEW
« no previous file with comments | « tools/dom/scripts/generator.py ('k') | tools/dom/scripts/idlrenderer.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698