| 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, IdlUnionType | 10 from idl_types import IdlType, IdlUnionType |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 sub_res = self._find_all(childAst, label, | 153 sub_res = self._find_all(childAst, label, |
| 154 max_results - len(res)) | 154 max_results - len(res)) |
| 155 res.extend(sub_res) | 155 res.extend(sub_res) |
| 156 elif isinstance(ast, tuple): | 156 elif isinstance(ast, tuple): |
| 157 (nodeLabel, value) = ast | 157 (nodeLabel, value) = ast |
| 158 if nodeLabel == label: | 158 if nodeLabel == label: |
| 159 res.append(value) | 159 res.append(value) |
| 160 # TODO(terry): Seems bogus to check for so many things probably better to ju
st | 160 # TODO(terry): Seems bogus to check for so many things probably better to ju
st |
| 161 # pass in blink_compile and drive it off from that... | 161 # pass in blink_compile and drive it off from that... |
| 162 elif (ast and not(isinstance(ast, dict)) and | 162 elif (ast and not(isinstance(ast, dict)) and |
| 163 not(isinstance(ast, str)) and ast.__module__ == "idl_definitions"): | 163 not(isinstance(ast, str)) and |
| 164 (ast.__module__ == "idl_definitions" or ast.__module__ == "idl_types")
): |
| 164 field_name = self._convert_label_to_field(label) | 165 field_name = self._convert_label_to_field(label) |
| 165 if hasattr(ast, field_name): | 166 if hasattr(ast, field_name): |
| 166 field_value = getattr(ast, field_name) | 167 field_value = getattr(ast, field_name) |
| 167 if field_value: | 168 if field_value: |
| 168 if label == 'Interface' or label == 'Enum': | 169 if label == 'Interface' or label == 'Enum': |
| 169 for key in field_value: | 170 for key in field_value: |
| 170 value = field_value[key] | 171 value = field_value[key] |
| 171 res.append(value) | 172 res.append(value) |
| 172 elif isinstance(field_value, list): | 173 elif isinstance(field_value, list): |
| 173 for item in field_value: | 174 for item in field_value: |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 363 self.interfaces = self._convert_all(ast, 'Interface', IDLInterface) | 364 self.interfaces = self._convert_all(ast, 'Interface', IDLInterface) |
| 364 | 365 |
| 365 is_blink = not(isinstance(ast, list)) and ast.__module__ == 'idl_definitions
' | 366 is_blink = not(isinstance(ast, list)) and ast.__module__ == 'idl_definitions
' |
| 366 | 367 |
| 367 if is_blink: | 368 if is_blink: |
| 368 # implements is handled by the interface merging step (see the function | 369 # implements is handled by the interface merging step (see the function |
| 369 # merge_interface_dependencies). | 370 # merge_interface_dependencies). |
| 370 for interface in self.interfaces: | 371 for interface in self.interfaces: |
| 371 blink_interface = ast.interfaces.get(interface.id) | 372 blink_interface = ast.interfaces.get(interface.id) |
| 372 if filename_basename == self.DART_IDL: | 373 if filename_basename == self.DART_IDL: |
| 373 # TODO(terry): Does this seem right? | 374 # Special handling for dart.idl we need to remember the interface, |
| 375 # since we could have many (not one interface / file). Then build up |
| 376 # the IDLImplementsStatement for any implements in dart.idl. |
| 377 interface_info = interfaces_info['__dart_idl___']; |
| 378 |
| 374 self.implementsStatements = [] | 379 self.implementsStatements = [] |
| 380 |
| 381 implement_pairs = interface_info['implement_pairs'] |
| 382 for implement_pair in implement_pairs: |
| 383 interface_name = implement_pair[0] |
| 384 implemented_name = implement_pair[1] |
| 385 |
| 386 implementor = new_asts[interface_name].interfaces.get(interface_name
) |
| 387 implement_statement = self._createImplementsStatement(implementor, |
| 388 implemented_na
me) |
| 389 |
| 390 self.implementsStatements.append(implement_statement) |
| 375 else: | 391 else: |
| 376 interface_info = interfaces_info[interface.id] | 392 interface_info = interfaces_info[interface.id] |
| 377 | 393 |
| 378 implements = interface_info['implements_interfaces'] | 394 implements = interface_info['implements_interfaces'] |
| 379 if not(blink_interface.is_partial) and len(implements) > 0: | 395 if not(blink_interface.is_partial) and len(implements) > 0: |
| 380 implementor = new_asts[interface.id].interfaces.get(interface.id) | 396 implementor = new_asts[interface.id].interfaces.get(interface.id) |
| 381 | 397 |
| 382 self.implementsStatements = [] | 398 self.implementsStatements = [] |
| 383 | 399 |
| 384 # TODO(terry): Need to handle more than one implements. | 400 # TODO(terry): Need to handle more than one implements. |
| 385 for implemented_name in implements: | 401 for implemented_name in implements: |
| 386 implemented = new_asts[implemented_name].interfaces.get(implemente
d_name) | 402 implement_statement = self._createImplementsStatement(implementor, |
| 387 | 403 implemented_
name) |
| 388 implement_statement = IDLImplementsStatement(implemented) | |
| 389 | |
| 390 implement_statement.implementor = IDLType(implementor) | |
| 391 implement_statement.implemented = IDLType(implemented) | |
| 392 | |
| 393 self.implementsStatements.append(implement_statement) | 404 self.implementsStatements.append(implement_statement) |
| 394 else: | 405 else: |
| 395 self.implementsStatements = [] | 406 self.implementsStatements = [] |
| 396 else: | 407 else: |
| 397 self.implementsStatements = self._convert_all(ast, 'ImplStmt', | 408 self.implementsStatements = self._convert_all(ast, 'ImplStmt', |
| 398 IDLImplementsStatement) | 409 IDLImplementsStatement) |
| 399 | 410 |
| 400 # No reason to handle typedef they're already aliased in Blink's AST. | 411 # 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) | 412 self.typeDefs = [] if is_blink else self._convert_all(ast, 'TypeDef', IDLTyp
eDef) |
| 402 | 413 |
| 403 self.enums = self._convert_all(ast, 'Enum', IDLEnum) | 414 self.enums = self._convert_all(ast, 'Enum', IDLEnum) |
| 404 | 415 |
| 416 def _createImplementsStatement(self, implementor, implemented_name): |
| 417 implemented = new_asts[implemented_name].interfaces.get(implemented_name) |
| 418 |
| 419 implement_statement = IDLImplementsStatement(implemented) |
| 420 |
| 421 implement_statement.implementor = IDLType(implementor) |
| 422 implement_statement.implemented = IDLType(implemented) |
| 423 |
| 424 return implement_statement |
| 425 |
| 405 | 426 |
| 406 class IDLModule(IDLNode): | 427 class IDLModule(IDLNode): |
| 407 """IDLModule has an id, and may contain interfaces, type defs and | 428 """IDLModule has an id, and may contain interfaces, type defs and |
| 408 implements statements.""" | 429 implements statements.""" |
| 409 def __init__(self, ast): | 430 def __init__(self, ast): |
| 410 IDLNode.__init__(self, ast) | 431 IDLNode.__init__(self, ast) |
| 411 self._convert_ext_attrs(ast) | 432 self._convert_ext_attrs(ast) |
| 412 self._convert_annotations(ast) | 433 self._convert_annotations(ast) |
| 413 self.interfaces = self._convert_all(ast, 'Interface', IDLInterface) | 434 self.interfaces = self._convert_all(ast, 'Interface', IDLInterface) |
| 414 | 435 |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 552 # https://code.google.com/p/chromium/issues/detail?id=35429
8 | 573 # https://code.google.com/p/chromium/issues/detail?id=35429
8 |
| 553 type_name = type_name.replace('unrestricted ', '', 1); | 574 type_name = type_name.replace('unrestricted ', '', 1); |
| 554 | 575 |
| 555 # TODO(terry): Handled ScalarValueString as a DOMString. | 576 # TODO(terry): Handled ScalarValueString as a DOMString. |
| 556 type_name = type_name.replace('ScalarValueString', 'DOMString', 1) | 577 type_name = type_name.replace('ScalarValueString', 'DOMString', 1) |
| 557 | 578 |
| 558 self.id = type_name | 579 self.id = type_name |
| 559 else: | 580 else: |
| 560 # IdlUnionType | 581 # IdlUnionType |
| 561 assert ast.is_union_type | 582 assert ast.is_union_type |
| 562 self.id = self._label_to_type('UnionType', ast) | 583 # TODO(terry): For union types use any otherwise type is unionType is |
| 584 # not found and is removed during merging. |
| 585 self.id = 'any' |
| 586 # TODO(terry): Any union type e.g. 'type1 or type2 or type2', |
| 587 # 'typedef (Type1 or Type2) UnionType' |
| 588 # Is a problem we need to extend IDLType and IDLTypeDef to handle more |
| 589 # than one type. |
| 590 # |
| 591 # Also for typedef's e.g., |
| 592 # typedef (Type1 or Type2) UnionType |
| 593 # should consider synthesizing a new interface (e.g., UnionType) that's |
| 594 # both Type1 and Type2. |
| 563 if not self.id: | 595 if not self.id: |
| 564 print '>>>> __module__ %s' % ast.__module__ | 596 print '>>>> __module__ %s' % ast.__module__ |
| 565 raise SyntaxError('Could not parse type %s' % (ast)) | 597 raise SyntaxError('Could not parse type %s' % (ast)) |
| 566 | 598 |
| 567 def _label_to_type(self, label, ast): | 599 def _label_to_type(self, label, ast): |
| 568 if label == 'LongLongType': | 600 if label == 'LongLongType': |
| 569 label = 'long long' | 601 label = 'long long' |
| 570 elif label.endswith('Type'): | 602 elif label.endswith('Type'): |
| 571 # Omit 'Type' suffix and lowercase the rest. | 603 # Omit 'Type' suffix and lowercase the rest. |
| 572 label = '%s%s' % (label[0].lower(), label[1:-4]) | 604 label = '%s%s' % (label[0].lower(), label[1:-4]) |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 797 """IDLDictNode specialization for one annotation.""" | 829 """IDLDictNode specialization for one annotation.""" |
| 798 def __init__(self, ast=None): | 830 def __init__(self, ast=None): |
| 799 IDLDictNode.__init__(self, ast) | 831 IDLDictNode.__init__(self, ast) |
| 800 self.id = None | 832 self.id = None |
| 801 if not ast: | 833 if not ast: |
| 802 return | 834 return |
| 803 for arg in self._find_all(ast, 'AnnotationArg'): | 835 for arg in self._find_all(ast, 'AnnotationArg'): |
| 804 name = self._find_first(arg, 'Id') | 836 name = self._find_first(arg, 'Id') |
| 805 value = self._find_first(arg, 'AnnotationArgValue') | 837 value = self._find_first(arg, 'AnnotationArgValue') |
| 806 self[name] = value | 838 self[name] = value |
| OLD | NEW |