OLD | NEW |
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 sys | 6 import sys |
7 | 7 |
8 | 8 |
9 class IDLNode(object): | 9 class IDLNode(object): |
10 """Base class for all IDL elements. | 10 """Base class for all IDL elements. |
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
313 def __init__(self, ast): | 313 def __init__(self, ast): |
314 IDLNode.__init__(self, ast) | 314 IDLNode.__init__(self, ast) |
315 # Search for a 'ScopedName' or any label ending with 'Type'. | 315 # Search for a 'ScopedName' or any label ending with 'Type'. |
316 if isinstance(ast, list): | 316 if isinstance(ast, list): |
317 self.id = self._find_first(ast, 'ScopedName') | 317 self.id = self._find_first(ast, 'ScopedName') |
318 if not self.id: | 318 if not self.id: |
319 # FIXME: use regexp search instead | 319 # FIXME: use regexp search instead |
320 for childAst in ast: | 320 for childAst in ast: |
321 (label, childAst) = childAst | 321 (label, childAst) = childAst |
322 if label.endswith('Type'): | 322 if label.endswith('Type'): |
323 self.id = self.__label_to_type(label, ast) | 323 self.id = self._label_to_type(label, ast) |
324 break | 324 break |
325 elif isinstance(ast, tuple): | 325 elif isinstance(ast, tuple): |
326 (label, value) = ast | 326 (label, value) = ast |
327 if label == 'ScopedName': | 327 if label == 'ScopedName': |
328 self.id = value | 328 self.id = value |
329 else: | 329 else: |
330 self.id = self.__label_to_type(label, ast) | 330 self.id = self._label_to_type(label, ast) |
331 elif isinstance(ast, str): | 331 elif isinstance(ast, str): |
332 self.id = ast | 332 self.id = ast |
333 if not self.id: | 333 if not self.id: |
334 raise SyntaxError('Could not parse type %s' % (ast)) | 334 raise SyntaxError('Could not parse type %s' % (ast)) |
335 | 335 |
336 def __label_to_type(self, label, ast): | 336 def _label_to_type(self, label, ast): |
337 if label.endswith('Type'): | 337 if label == 'AnyArrayType': |
| 338 return 'any[]' |
| 339 if label == 'DOMStringArrayType': |
| 340 return 'DOMString[]' |
| 341 if label == 'LongLongType': |
| 342 label = 'long long' |
| 343 elif label.endswith('Type'): |
338 # Omit 'Type' suffix and lowercase the rest. | 344 # Omit 'Type' suffix and lowercase the rest. |
339 label = '%s%s' % (label[0].lower(), label[1:-4]) | 345 label = '%s%s' % (label[0].lower(), label[1:-4]) |
340 if label == 'longLong': | |
341 # Special case for LongLongType: | |
342 label = 'long long' | |
343 if label == 'anyArray': | |
344 label = 'any[]' | |
345 | 346 |
346 # Add unsigned qualifier. | 347 # Add unsigned qualifier. |
347 if self._has(ast, 'Unsigned'): | 348 if self._has(ast, 'Unsigned'): |
348 label = 'unsigned %s' % label | 349 label = 'unsigned %s' % label |
349 return label | 350 return label |
350 | 351 |
351 | 352 |
352 class IDLTypeDef(IDLNode): | 353 class IDLTypeDef(IDLNode): |
353 """IDLNode for 'typedef [type] [id]' declarations.""" | 354 """IDLNode for 'typedef [type] [id]' declarations.""" |
354 def __init__(self, ast): | 355 def __init__(self, ast): |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
483 """IDLDictNode specialization for one annotation.""" | 484 """IDLDictNode specialization for one annotation.""" |
484 def __init__(self, ast=None): | 485 def __init__(self, ast=None): |
485 IDLDictNode.__init__(self, ast) | 486 IDLDictNode.__init__(self, ast) |
486 self.id = None | 487 self.id = None |
487 if not ast: | 488 if not ast: |
488 return | 489 return |
489 for arg in self._find_all(ast, 'AnnotationArg'): | 490 for arg in self._find_all(ast, 'AnnotationArg'): |
490 name = self._find_first(arg, 'Id') | 491 name = self._find_first(arg, 'Id') |
491 value = self._find_first(arg, 'AnnotationArgValue') | 492 value = self._find_first(arg, 'AnnotationArgValue') |
492 self[name] = value | 493 self[name] = value |
OLD | NEW |