| 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 os | 6 import os |
| 7 import sys | 7 import sys |
| 8 | 8 |
| 9 import idl_definitions | 9 import idl_definitions |
| 10 from idl_types import IdlType, IdlNullableType, IdlUnionType, IdlArrayOrSequence
Type | 10 from idl_types import IdlType, IdlNullableType, IdlUnionType, IdlArrayOrSequence
Type |
| 11 import dependency | 11 import dependency |
| 12 | 12 |
| 13 new_asts = {} | 13 new_asts = {} |
| 14 | 14 |
| 15 # Report of union types mapped to any. |
| 16 _unions_to_any = [] |
| 17 |
| 18 def report_unions_to_any(): |
| 19 global _unions_to_any |
| 20 |
| 21 warnings = [] |
| 22 for union_id in sorted(_unions_to_any): |
| 23 warnings.append('Union type %s is mapped to \'any\'' % union_id) |
| 24 |
| 25 return warnings |
| 26 |
| 15 # Ugly but Chrome IDLs can reference typedefs in any IDL w/o an include. So we | 27 # Ugly but Chrome IDLs can reference typedefs in any IDL w/o an include. So we |
| 16 # need to remember any typedef seen then alias any reference to a typedef. | 28 # need to remember any typedef seen then alias any reference to a typedef. |
| 17 typeDefsFixup = [] | 29 typeDefsFixup = [] |
| 18 | 30 |
| 19 def _resolveTypedef(type): | 31 def _resolveTypedef(type): |
| 20 """ Given a type if it's a known typedef (only typedef's that aren't union) | 32 """ Given a type if it's a known typedef (only typedef's that aren't union) |
| 21 are remembered for fixup. typedefs that are union type are mapped to | 33 are remembered for fixup. typedefs that are union type are mapped to |
| 22 any so those we don't need to alias. typedefs referenced in the file | 34 any so those we don't need to alias. typedefs referenced in the file |
| 23 where the typedef was defined are automatically aliased to the real type. | 35 where the typedef was defined are automatically aliased to the real type. |
| 24 This resolves typedef where the declaration is in another IDL file. | 36 This resolves typedef where the declaration is in another IDL file. |
| (...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 357 """IDLFile is the top-level node in each IDL file. It may contain interfaces."
"" | 369 """IDLFile is the top-level node in each IDL file. It may contain interfaces."
"" |
| 358 | 370 |
| 359 DART_IDL = 'dart.idl' | 371 DART_IDL = 'dart.idl' |
| 360 | 372 |
| 361 def __init__(self, ast, filename=None): | 373 def __init__(self, ast, filename=None): |
| 362 IDLNode.__init__(self, ast) | 374 IDLNode.__init__(self, ast) |
| 363 self.filename = filename | 375 self.filename = filename |
| 364 | 376 |
| 365 filename_basename = os.path.basename(filename) | 377 filename_basename = os.path.basename(filename) |
| 366 | 378 |
| 379 # Report of union types mapped to any. |
| 380 |
| 367 self.interfaces = self._convert_all(ast, 'Interface', IDLInterface) | 381 self.interfaces = self._convert_all(ast, 'Interface', IDLInterface) |
| 368 self.dictionaries = self._convert_all(ast, 'Dictionary', IDLDictionary) | 382 self.dictionaries = self._convert_all(ast, 'Dictionary', IDLDictionary) |
| 369 | 383 |
| 370 is_blink = not(isinstance(ast, list)) and ast.__module__ == 'idl_definitions
' | 384 is_blink = not(isinstance(ast, list)) and ast.__module__ == 'idl_definitions
' |
| 371 | 385 |
| 372 if is_blink: | 386 if is_blink: |
| 373 # implements is handled by the interface merging step (see the function | 387 # implements is handled by the interface merging step (see the function |
| 374 # merge_interface_dependencies). | 388 # merge_interface_dependencies). |
| 375 for interface in self.interfaces: | 389 for interface in self.interfaces: |
| 376 blink_interface = ast.interfaces.get(interface.id) | 390 blink_interface = ast.interfaces.get(interface.id) |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 549 else: | 563 else: |
| 550 self.arguments = self._convert_all(arg_list_ast, 'Argument', IDLArgument) | 564 self.arguments = self._convert_all(arg_list_ast, 'Argument', IDLArgument) |
| 551 | 565 |
| 552 | 566 |
| 553 class IDLType(IDLNode): | 567 class IDLType(IDLNode): |
| 554 """IDLType is used to describe constants, attributes and operations' | 568 """IDLType is used to describe constants, attributes and operations' |
| 555 return and input types. IDLType matches AST labels such as ScopedName, | 569 return and input types. IDLType matches AST labels such as ScopedName, |
| 556 StringType, VoidType, IntegerType, etc.""" | 570 StringType, VoidType, IntegerType, etc.""" |
| 557 | 571 |
| 558 def __init__(self, ast): | 572 def __init__(self, ast): |
| 573 global _unions_to_any |
| 574 |
| 559 IDLNode.__init__(self, ast) | 575 IDLNode.__init__(self, ast) |
| 560 | 576 |
| 561 if ast: | 577 if ast: |
| 562 self.nullable = self._has(ast, 'Nullable') | 578 self.nullable = self._has(ast, 'Nullable') |
| 563 # Search for a 'ScopedName' or any label ending with 'Type'. | 579 # Search for a 'ScopedName' or any label ending with 'Type'. |
| 564 if isinstance(ast, list): | 580 if isinstance(ast, list): |
| 565 self.id = self._find_first(ast, 'ScopedName') | 581 self.id = self._find_first(ast, 'ScopedName') |
| 566 if not self.id: | 582 if not self.id: |
| 567 # FIXME: use regexp search instead | 583 # FIXME: use regexp search instead |
| 568 def findType(ast): | 584 def findType(ast): |
| (...skipping 19 matching lines...) Expand all Loading... |
| 588 self.id = value | 604 self.id = value |
| 589 else: | 605 else: |
| 590 self.id = self._label_to_type(label, ast) | 606 self.id = self._label_to_type(label, ast) |
| 591 elif isinstance(ast, str): | 607 elif isinstance(ast, str): |
| 592 self.id = ast | 608 self.id = ast |
| 593 # New blink handling. | 609 # New blink handling. |
| 594 elif ast.__module__ == "idl_types": | 610 elif ast.__module__ == "idl_types": |
| 595 if isinstance(ast, IdlType) or isinstance(ast, IdlArrayOrSequenceType) o
r \ | 611 if isinstance(ast, IdlType) or isinstance(ast, IdlArrayOrSequenceType) o
r \ |
| 596 isinstance(ast, IdlNullableType): | 612 isinstance(ast, IdlNullableType): |
| 597 if isinstance(ast, IdlNullableType) and ast.inner_type.is_union_type: | 613 if isinstance(ast, IdlNullableType) and ast.inner_type.is_union_type: |
| 598 print 'WARNING type %s is union mapped to \'any\'' % self.id | 614 # Report of union types mapped to any. |
| 615 if not(self.id in _unions_to_any): |
| 616 _unions_to_any.append(self.id) |
| 599 # TODO(terry): For union types use any otherwise type is unionType i
s | 617 # TODO(terry): For union types use any otherwise type is unionType i
s |
| 600 # not found and is removed during merging. | 618 # not found and is removed during merging. |
| 601 self.id = 'any' | 619 self.id = 'any' |
| 602 else: | 620 else: |
| 603 type_name = str(ast) | 621 type_name = str(ast) |
| 604 # TODO(terry): For now don't handle unrestricted types see | 622 # TODO(terry): For now don't handle unrestricted types see |
| 605 # https://code.google.com/p/chromium/issues/detail?id=3
54298 | 623 # https://code.google.com/p/chromium/issues/detail?id=3
54298 |
| 606 type_name = type_name.replace('unrestricted ', '', 1); | 624 type_name = type_name.replace('unrestricted ', '', 1); |
| 607 | 625 |
| 608 # TODO(terry): Handled USVString as a DOMString. | 626 # TODO(terry): Handled USVString as a DOMString. |
| 609 type_name = type_name.replace('USVString', 'DOMString', 1) | 627 type_name = type_name.replace('USVString', 'DOMString', 1) |
| 610 | 628 |
| 611 # TODO(terry); WindowTimers setInterval/setTimeout overloads with a | 629 # TODO(terry); WindowTimers setInterval/setTimeout overloads with a |
| 612 # Function type - map to any until the IDL uses union. | 630 # Function type - map to any until the IDL uses union. |
| 613 type_name = type_name.replace('Function', 'any', 1) | 631 type_name = type_name.replace('Function', 'any', 1) |
| 614 | 632 |
| 615 self.id = type_name | 633 self.id = type_name |
| 616 else: | 634 else: |
| 617 # IdlUnionType | 635 # IdlUnionType |
| 618 if ast.is_union_type: | 636 if ast.is_union_type: |
| 619 print 'WARNING type %s is union mapped to \'any\'' % self.id | 637 if not(self.id in _unions_to_any): |
| 620 # TODO(terry): For union types use any otherwise type is unionType is | 638 _unions_to_any.append(self.id) |
| 621 # not found and is removed during merging. | 639 # TODO(terry): For union types use any otherwise type is unionType i
s |
| 640 # not found and is removed during merging. |
| 622 self.id = 'any' | 641 self.id = 'any' |
| 623 # TODO(terry): Any union type e.g. 'type1 or type2 or type2', | 642 # TODO(terry): Any union type e.g. 'type1 or type2 or type2', |
| 624 # 'typedef (Type1 or Type2) UnionType' | 643 # 'typedef (Type1 or Type2) UnionType' |
| 625 # Is a problem we need to extend IDLType and IDLTypeDef to handle more | 644 # Is a problem we need to extend IDLType and IDLTypeDef to handle mo
re |
| 626 # than one type. | 645 # than one type. |
| 627 # | 646 # |
| 628 # Also for typedef's e.g., | 647 # Also for typedef's e.g., |
| 629 # typedef (Type1 or Type2) UnionType | 648 # typedef (Type1 or Type2) UnionType |
| 630 # should consider synthesizing a new interface (e.g., UnionType) that'
s | 649 # should consider synthesizing a new interface (e.g., UnionType) tha
t's |
| 631 # both Type1 and Type2. | 650 # both Type1 and Type2. |
| 632 if not self.id: | 651 if not self.id: |
| 633 print '>>>> __module__ %s' % ast.__module__ | 652 print '>>>> __module__ %s' % ast.__module__ |
| 634 raise SyntaxError('Could not parse type %s' % (ast)) | 653 raise SyntaxError('Could not parse type %s' % (ast)) |
| 635 | 654 |
| 636 def _label_to_type(self, label, ast): | 655 def _label_to_type(self, label, ast): |
| 637 if label == 'LongLongType': | 656 if label == 'LongLongType': |
| 638 label = 'long long' | 657 label = 'long long' |
| 639 elif label.endswith('Type'): | 658 elif label.endswith('Type'): |
| 640 # Omit 'Type' suffix and lowercase the rest. | 659 # Omit 'Type' suffix and lowercase the rest. |
| 641 label = '%s%s' % (label[0].lower(), label[1:-4]) | 660 label = '%s%s' % (label[0].lower(), label[1:-4]) |
| (...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 908 """IDLDictNode specialization for one annotation.""" | 927 """IDLDictNode specialization for one annotation.""" |
| 909 def __init__(self, ast=None): | 928 def __init__(self, ast=None): |
| 910 IDLDictNode.__init__(self, ast) | 929 IDLDictNode.__init__(self, ast) |
| 911 self.id = None | 930 self.id = None |
| 912 if not ast: | 931 if not ast: |
| 913 return | 932 return |
| 914 for arg in self._find_all(ast, 'AnnotationArg'): | 933 for arg in self._find_all(ast, 'AnnotationArg'): |
| 915 name = self._find_first(arg, 'Id') | 934 name = self._find_first(arg, 'Id') |
| 916 value = self._find_first(arg, 'AnnotationArgValue') | 935 value = self._find_first(arg, 'AnnotationArgValue') |
| 917 self[name] = value | 936 self[name] = value |
| OLD | NEW |