| 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 | 11 import dependency |
| 12 from compute_interfaces_info_overall import interfaces_info | |
| 13 | |
| 14 | 12 |
| 15 new_asts = {} | 13 new_asts = {} |
| 16 | 14 |
| 17 | 15 |
| 18 _operation_suffix_map = { | 16 _operation_suffix_map = { |
| 19 '__getter__': "Getter", | 17 '__getter__': "Getter", |
| 20 '__setter__': "Setter", | 18 '__setter__': "Setter", |
| 21 '__delete__': "Deleter", | 19 '__delete__': "Deleter", |
| 22 } | 20 } |
| 23 | 21 |
| (...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 356 | 354 |
| 357 if is_blink: | 355 if is_blink: |
| 358 # implements is handled by the interface merging step (see the function | 356 # implements is handled by the interface merging step (see the function |
| 359 # merge_interface_dependencies). | 357 # merge_interface_dependencies). |
| 360 for interface in self.interfaces: | 358 for interface in self.interfaces: |
| 361 blink_interface = ast.interfaces.get(interface.id) | 359 blink_interface = ast.interfaces.get(interface.id) |
| 362 if filename_basename == self.DART_IDL: | 360 if filename_basename == self.DART_IDL: |
| 363 # Special handling for dart.idl we need to remember the interface, | 361 # Special handling for dart.idl we need to remember the interface, |
| 364 # since we could have many (not one interface / file). Then build up | 362 # since we could have many (not one interface / file). Then build up |
| 365 # the IDLImplementsStatement for any implements in dart.idl. | 363 # the IDLImplementsStatement for any implements in dart.idl. |
| 366 interface_info = interfaces_info['__dart_idl___']; | 364 interface_info = dependency.get_interfaces_info()['__dart_idl___']; |
| 367 | 365 |
| 368 self.implementsStatements = [] | 366 self.implementsStatements = [] |
| 369 | 367 |
| 370 implement_pairs = interface_info['implement_pairs'] | 368 implement_pairs = interface_info['implement_pairs'] |
| 371 for implement_pair in implement_pairs: | 369 for implement_pair in implement_pairs: |
| 372 interface_name = implement_pair[0] | 370 interface_name = implement_pair[0] |
| 373 implemented_name = implement_pair[1] | 371 implemented_name = implement_pair[1] |
| 374 | 372 |
| 375 implementor = new_asts[interface_name].interfaces.get(interface_name
) | 373 implementor = new_asts[interface_name].interfaces.get(interface_name
) |
| 376 implement_statement = self._createImplementsStatement(implementor, | 374 implement_statement = self._createImplementsStatement(implementor, |
| 377 implemented_na
me) | 375 implemented_na
me) |
| 378 | 376 |
| 379 self.implementsStatements.append(implement_statement) | 377 self.implementsStatements.append(implement_statement) |
| 380 elif interface.id in interfaces_info: | 378 elif interface.id in dependency.get_interfaces_info(): |
| 381 interface_info = interfaces_info[interface.id] | 379 interface_info = dependency.get_interfaces_info()[interface.id] |
| 382 | 380 |
| 383 implements = interface_info['implements_interfaces'] | 381 implements = interface_info['implements_interfaces'] if interface_info
.has_key('implements_interfaces') else [] |
| 384 if not(blink_interface.is_partial) and len(implements) > 0: | 382 if not(blink_interface.is_partial) and len(implements) > 0: |
| 385 implementor = new_asts[interface.id].interfaces.get(interface.id) | 383 implementor = new_asts[interface.id].interfaces.get(interface.id) |
| 386 | 384 |
| 387 self.implementsStatements = [] | 385 self.implementsStatements = [] |
| 388 | 386 |
| 389 # TODO(terry): Need to handle more than one implements. | 387 # TODO(terry): Need to handle more than one implements. |
| 390 for implemented_name in implements: | 388 for implemented_name in implements: |
| 391 implement_statement = self._createImplementsStatement(implementor, | 389 implement_statement = self._createImplementsStatement(implementor, |
| 392 implemented_
name) | 390 implemented_
name) |
| 393 self.implementsStatements.append(implement_statement) | 391 self.implementsStatements.append(implement_statement) |
| 394 else: | 392 else: |
| 395 self.implementsStatements = [] | 393 self.implementsStatements = [] |
| 396 else: | 394 else: |
| 397 self.implementsStatements = self._convert_all(ast, 'ImplStmt', | 395 self.implementsStatements = self._convert_all(ast, 'ImplStmt', |
| 398 IDLImplementsStatement) | 396 IDLImplementsStatement) |
| 399 | 397 |
| 400 # No reason to handle typedef they're already aliased in Blink's AST. | 398 # No reason to handle typedef they're already aliased in Blink's AST. |
| 401 self.typeDefs = [] if is_blink else self._convert_all(ast, 'TypeDef', IDLTyp
eDef) | 399 self.typeDefs = [] if is_blink else self._convert_all(ast, 'TypeDef', IDLTyp
eDef) |
| 402 | 400 |
| 401 # Hack to record typedefs that are unions. |
| 402 for typedefName in ast.typedefs: |
| 403 typedef_type = ast.typedefs[typedefName] |
| 404 if isinstance(typedef_type.idl_type, IdlUnionType): |
| 405 self.typeDefs.append(IDLTypeDef(typedef_type)) |
| 406 elif typedef_type.idl_type.base_type == 'Dictionary': |
| 407 dictionary = IDLDictionary(typedef_type, True) |
| 408 self.dictionaries.append(dictionary) |
| 409 |
| 403 self.enums = self._convert_all(ast, 'Enum', IDLEnum) | 410 self.enums = self._convert_all(ast, 'Enum', IDLEnum) |
| 404 | 411 |
| 405 def _createImplementsStatement(self, implementor, implemented_name): | 412 def _createImplementsStatement(self, implementor, implemented_name): |
| 406 implemented = new_asts[implemented_name].interfaces.get(implemented_name) | 413 implemented = new_asts[implemented_name].interfaces.get(implemented_name) |
| 407 | 414 |
| 408 implement_statement = IDLImplementsStatement(implemented) | 415 implement_statement = IDLImplementsStatement(implemented) |
| 409 | 416 |
| 410 implement_statement.implementor = IDLType(implementor) | 417 implement_statement.implementor = IDLType(implementor) |
| 411 implement_statement.implemented = IDLType(implemented) | 418 implement_statement.implemented = IDLType(implemented) |
| 412 | 419 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 426 | 433 |
| 427 # No reason to handle typedef they're already aliased in Blink's AST. | 434 # No reason to handle typedef they're already aliased in Blink's AST. |
| 428 self.typeDefs = [] if is_blink else self._convert_all(ast, 'TypeDef', IDLTyp
eDef) | 435 self.typeDefs = [] if is_blink else self._convert_all(ast, 'TypeDef', IDLTyp
eDef) |
| 429 | 436 |
| 430 self.enums = self._convert_all(ast, 'Enum', IDLNode) | 437 self.enums = self._convert_all(ast, 'Enum', IDLNode) |
| 431 | 438 |
| 432 if is_blink: | 439 if is_blink: |
| 433 # implements is handled by the interface merging step (see the function | 440 # implements is handled by the interface merging step (see the function |
| 434 # merge_interface_dependencies). | 441 # merge_interface_dependencies). |
| 435 for interface in self.interfaces: | 442 for interface in self.interfaces: |
| 436 interface_info = interfaces_info[interface.id] | 443 interface_info = get_interfaces_info()[interface.id] |
| 437 # TODO(terry): Same handling for implementsStatements as in IDLFile? | 444 # TODO(terry): Same handling for implementsStatements as in IDLFile? |
| 438 self.implementsStatements = interface_info['implements_interfaces'] | 445 self.implementsStatements = interface_info['implements_interfaces'] |
| 439 else: | 446 else: |
| 440 self.implementsStatements = self._convert_all(ast, 'ImplStmt', | 447 self.implementsStatements = self._convert_all(ast, 'ImplStmt', |
| 441 IDLImplementsStatement) | 448 IDLImplementsStatement) |
| 442 | 449 |
| 443 | 450 |
| 444 class IDLExtAttrs(IDLDictNode): | 451 class IDLExtAttrs(IDLDictNode): |
| 445 """IDLExtAttrs is an IDLDictNode that stores IDL Extended Attributes. | 452 """IDLExtAttrs is an IDLDictNode that stores IDL Extended Attributes. |
| 446 Modules, interfaces, members and arguments can all own IDLExtAttrs.""" | 453 Modules, interfaces, members and arguments can all own IDLExtAttrs.""" |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 560 self.id = value | 567 self.id = value |
| 561 else: | 568 else: |
| 562 self.id = self._label_to_type(label, ast) | 569 self.id = self._label_to_type(label, ast) |
| 563 elif isinstance(ast, str): | 570 elif isinstance(ast, str): |
| 564 self.id = ast | 571 self.id = ast |
| 565 # New blink handling. | 572 # New blink handling. |
| 566 elif ast.__module__ == "idl_types": | 573 elif ast.__module__ == "idl_types": |
| 567 if isinstance(ast, IdlType) or isinstance(ast, IdlArrayOrSequenceType) or
\ | 574 if isinstance(ast, IdlType) or isinstance(ast, IdlArrayOrSequenceType) or
\ |
| 568 isinstance(ast, IdlNullableType): | 575 isinstance(ast, IdlNullableType): |
| 569 type_name = str(ast) | 576 type_name = str(ast) |
| 570 | |
| 571 # TODO(terry): For now don't handle unrestricted types see | 577 # TODO(terry): For now don't handle unrestricted types see |
| 572 # https://code.google.com/p/chromium/issues/detail?id=35429
8 | 578 # https://code.google.com/p/chromium/issues/detail?id=35429
8 |
| 573 type_name = type_name.replace('unrestricted ', '', 1); | 579 type_name = type_name.replace('unrestricted ', '', 1); |
| 574 | 580 |
| 575 # TODO(terry): Handled ScalarValueString as a DOMString. | 581 # TODO(terry): Handled USVString as a DOMString. |
| 576 type_name = type_name.replace('ScalarValueString', 'DOMString', 1) | 582 type_name = type_name.replace('USVString', 'DOMString', 1) |
| 577 | 583 |
| 578 self.id = type_name | 584 self.id = type_name |
| 579 else: | 585 else: |
| 580 # IdlUnionType | 586 # IdlUnionType |
| 581 if ast.is_union_type: | 587 if ast.is_union_type: |
| 582 print 'WARNING type %s is union mapped to \'any\'' % self.id | 588 print 'WARNING type %s is union mapped to \'any\'' % self.id |
| 583 # TODO(terry): For union types use any otherwise type is unionType is | 589 # TODO(terry): For union types use any otherwise type is unionType is |
| 584 # not found and is removed during merging. | 590 # not found and is removed during merging. |
| 585 self.id = 'any' | 591 self.id = 'any' |
| 586 # TODO(terry): Any union type e.g. 'type1 or type2 or type2', | 592 # TODO(terry): Any union type e.g. 'type1 or type2 or type2', |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 628 def __init__(self, ast): | 634 def __init__(self, ast): |
| 629 IDLNode.__init__(self, ast) | 635 IDLNode.__init__(self, ast) |
| 630 self._convert_annotations(ast) | 636 self._convert_annotations(ast) |
| 631 self.type = self._convert_first(ast, 'Type', IDLType) | 637 self.type = self._convert_first(ast, 'Type', IDLType) |
| 632 | 638 |
| 633 | 639 |
| 634 class IDLDictionary(IDLNode): | 640 class IDLDictionary(IDLNode): |
| 635 """IDLDictionary node contains members, | 641 """IDLDictionary node contains members, |
| 636 as well as parent references.""" | 642 as well as parent references.""" |
| 637 | 643 |
| 638 def __init__(self, ast): | 644 def __init__(self, ast, typedefDictionary=False): |
| 639 IDLNode.__init__(self, ast) | 645 IDLNode.__init__(self, ast) |
| 640 | 646 |
| 641 self.javascript_binding_name = self.id | 647 self.javascript_binding_name = self.id |
| 642 self._convert_ext_attrs(ast) | 648 if (typedefDictionary): |
| 643 self._convert_constants(ast, self.id) | 649 # Dictionary is a typedef to a union. |
| 644 | 650 self._convert_ext_attrs(None) |
| 651 else: |
| 652 self._convert_ext_attrs(ast) |
| 653 self._convert_constants(ast, self.id) |
| 645 | 654 |
| 646 class IDLDictionaryMembers(IDLDictNode): | 655 class IDLDictionaryMembers(IDLDictNode): |
| 647 """IDLDictionaryMembers specialization for a list of FremontCut dictionary val
ues.""" | 656 """IDLDictionaryMembers specialization for a list of FremontCut dictionary val
ues.""" |
| 648 def __init__(self, ast=None, js_name=None): | 657 def __init__(self, ast=None, js_name=None): |
| 649 IDLDictNode.__init__(self, ast) | 658 IDLDictNode.__init__(self, ast) |
| 650 self.id = None | 659 self.id = None |
| 651 if not ast: | 660 if not ast: |
| 652 return | 661 return |
| 653 for member in self._find_all(ast, 'Member'): | 662 for member in self._find_all(ast, 'Member'): |
| 654 name = self._find_first(member, 'Id') | 663 name = self._find_first(member, 'Id') |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 747 self.specials = self._find_all(ast, 'Special') | 756 self.specials = self._find_all(ast, 'Special') |
| 748 # Special case: there are getters of the form | 757 # Special case: there are getters of the form |
| 749 # getter <ReturnType>(args). For now force the name to be __getter__, | 758 # getter <ReturnType>(args). For now force the name to be __getter__, |
| 750 # but it should be operator[] later. | 759 # but it should be operator[] later. |
| 751 if self.id is None: | 760 if self.id is None: |
| 752 if self.specials == ['getter']: | 761 if self.specials == ['getter']: |
| 753 if self.ext_attrs.get('Custom') == 'PropertyQuery': | 762 if self.ext_attrs.get('Custom') == 'PropertyQuery': |
| 754 # Handling __propertyQuery__ the extended attribute is: | 763 # Handling __propertyQuery__ the extended attribute is: |
| 755 # [Custom=PropertyQuery] getter boolean (DOMString name); | 764 # [Custom=PropertyQuery] getter boolean (DOMString name); |
| 756 self.id = '__propertyQuery__' | 765 self.id = '__propertyQuery__' |
| 766 elif self.ext_attrs.get('ImplementedAs'): |
| 767 self.id = self.ext_attrs.get('ImplementedAs') |
| 757 else: | 768 else: |
| 758 self.id = '__getter__' | 769 self.id = '__getter__' |
| 759 elif self.specials == ['setter']: | 770 elif self.specials == ['setter']: |
| 760 self.id = '__setter__' | 771 self.id = '__setter__' |
| 761 # Special case: if it's a setter, ignore 'declared' return type | 772 # Special case: if it's a setter, ignore 'declared' return type |
| 762 self.type = IDLType([('VoidType', None)]) | 773 self.type = IDLType([('VoidType', None)]) |
| 763 elif self.specials == ['deleter']: | 774 elif self.specials == ['deleter']: |
| 764 self.id = '__delete__' | 775 self.id = '__delete__' |
| 765 else: | 776 else: |
| 766 raise Exception('Cannot handle %s: operation has no id' % ast) | 777 raise Exception('Cannot handle %s: operation has no id' % ast) |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 862 """IDLDictNode specialization for one annotation.""" | 873 """IDLDictNode specialization for one annotation.""" |
| 863 def __init__(self, ast=None): | 874 def __init__(self, ast=None): |
| 864 IDLDictNode.__init__(self, ast) | 875 IDLDictNode.__init__(self, ast) |
| 865 self.id = None | 876 self.id = None |
| 866 if not ast: | 877 if not ast: |
| 867 return | 878 return |
| 868 for arg in self._find_all(ast, 'AnnotationArg'): | 879 for arg in self._find_all(ast, 'AnnotationArg'): |
| 869 name = self._find_first(arg, 'Id') | 880 name = self._find_first(arg, 'Id') |
| 870 value = self._find_first(arg, 'AnnotationArgValue') | 881 value = self._find_first(arg, 'AnnotationArgValue') |
| 871 self[name] = value | 882 self[name] = value |
| OLD | NEW |