| 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 """This module generates Dart APIs from the IDL database.""" | 6 """This module generates Dart APIs from the IDL database.""" |
| 7 | 7 |
| 8 import emitter | 8 import emitter |
| 9 import idlnode | 9 import idlnode |
| 10 import logging | 10 import logging |
| (...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 404 self._GenerateJavaScriptExternsMonkey(database, output_dir) | 404 self._GenerateJavaScriptExternsMonkey(database, output_dir) |
| 405 self._GenerateJavaScriptExternsWrapping(database, output_dir) | 405 self._GenerateJavaScriptExternsWrapping(database, output_dir) |
| 406 | 406 |
| 407 | 407 |
| 408 def _ProcessInterface(self, interface, super_interface_name, | 408 def _ProcessInterface(self, interface, super_interface_name, |
| 409 source_filter, | 409 source_filter, |
| 410 common_prefix): | 410 common_prefix): |
| 411 """.""" | 411 """.""" |
| 412 _logger.info('Generating %s' % interface.id) | 412 _logger.info('Generating %s' % interface.id) |
| 413 | 413 |
| 414 | |
| 415 self._overloaded_types = set() | |
| 416 | |
| 417 dart_interface_generator = self._MakeDartInterfaceGenerator( | 414 dart_interface_generator = self._MakeDartInterfaceGenerator( |
| 418 interface, | 415 interface, |
| 419 common_prefix, | 416 common_prefix, |
| 420 super_interface_name, | 417 super_interface_name, |
| 421 source_filter) | 418 source_filter) |
| 422 | 419 |
| 423 monkey_interface_generator = self._MakeMonkeyInterfaceGenerator(interface) | 420 monkey_interface_generator = self._MakeMonkeyInterfaceGenerator(interface) |
| 424 | 421 |
| 425 wrapping_interface_generator = self._MakeWrappingImplInterfaceGenerator( | 422 wrapping_interface_generator = self._MakeWrappingImplInterfaceGenerator( |
| 426 interface, | 423 interface, |
| 427 common_prefix, | 424 common_prefix, |
| 428 super_interface_name, | 425 super_interface_name, |
| 429 source_filter) | 426 source_filter) |
| 430 | 427 |
| 431 frog_interface_generator = self._MakeFrogImplInterfaceGenerator( | 428 frog_interface_generator = self._MakeFrogImplInterfaceGenerator( |
| 432 interface, | 429 interface, |
| 433 common_prefix, | 430 common_prefix, |
| 434 super_interface_name, | 431 super_interface_name, |
| 435 source_filter) | 432 source_filter) |
| 436 | 433 |
| 437 dart_interface_generator.StartInterface() | 434 generators = [dart_interface_generator, |
| 438 monkey_interface_generator.StartInterface() | 435 monkey_interface_generator, |
| 439 wrapping_interface_generator.StartInterface() | 436 wrapping_interface_generator, |
| 440 frog_interface_generator.StartInterface() | 437 frog_interface_generator] |
| 438 |
| 439 for generator in generators: |
| 440 generator.StartInterface() |
| 441 | 441 |
| 442 for const in sorted(interface.constants, ConstantOutputOrder): | 442 for const in sorted(interface.constants, ConstantOutputOrder): |
| 443 dart_interface_generator.AddConstant(const) | 443 for generator in generators: |
| 444 generator.AddConstant(const) |
| 444 | 445 |
| 445 for attr in sorted(interface.attributes, AttributeOutputOrder): | 446 for attr in sorted(interface.attributes, AttributeOutputOrder): |
| 446 if attr.is_fc_getter: | 447 if attr.is_fc_getter: |
| 447 dart_interface_generator.AddGetter(attr) | 448 for generator in generators: |
| 448 monkey_interface_generator.AddGetter(attr) | 449 generator.AddGetter(attr) |
| 449 wrapping_interface_generator.AddGetter(attr) | |
| 450 frog_interface_generator.AddGetter(attr) | |
| 451 elif attr.is_fc_setter: | 450 elif attr.is_fc_setter: |
| 452 dart_interface_generator.AddSetter(attr) | 451 for generator in generators: |
| 453 monkey_interface_generator.AddSetter(attr) | 452 generator.AddSetter(attr) |
| 454 wrapping_interface_generator.AddSetter(attr) | |
| 455 frog_interface_generator.AddSetter(attr) | |
| 456 | 453 |
| 457 # The implementation should define an indexer if the interface directly | 454 # The implementation should define an indexer if the interface directly |
| 458 # extends List. | 455 # extends List. |
| 459 for parent in interface.parents: | 456 for parent in interface.parents: |
| 460 match = re.match(r'List<(\w*)>$', parent.type.id) | 457 match = re.match(r'List<(\w*)>$', parent.type.id) |
| 461 if match: | 458 if match: |
| 462 element_type = match.group(1) | 459 element_type = match.group(1) |
| 463 monkey_interface_generator.AddIndexer(element_type) | 460 for generator in generators: |
| 464 wrapping_interface_generator.AddListImplementation(element_type) | 461 generator.AddIndexer(element_type) |
| 465 frog_interface_generator.AddListImplementation(element_type) | |
| 466 break | 462 break |
| 467 | 463 |
| 468 # Group overloaded operations by id | 464 # Group overloaded operations by id |
| 469 operationsById = {} | 465 operationsById = {} |
| 470 for operation in interface.operations: | 466 for operation in interface.operations: |
| 471 if operation.id not in operationsById: | 467 if operation.id not in operationsById: |
| 472 operationsById[operation.id] = [] | 468 operationsById[operation.id] = [] |
| 473 operationsById[operation.id].append(operation) | 469 operationsById[operation.id].append(operation) |
| 474 | 470 |
| 475 # Generate operations | 471 # Generate operations |
| 476 for id in sorted(operationsById.keys()): | 472 for id in sorted(operationsById.keys()): |
| 477 operations = operationsById[id] | 473 operations = operationsById[id] |
| 478 info = self._AnalyzeOperation(interface, operations) | 474 info = self._AnalyzeOperation(interface, operations) |
| 479 dart_interface_generator.AddOperation(info) | 475 for generator in generators: |
| 480 monkey_interface_generator.AddOperation(info) | 476 generator.AddOperation(info) |
| 481 wrapping_interface_generator.AddOperation(info) | |
| 482 frog_interface_generator.AddOperation(info) | |
| 483 | 477 |
| 484 # With multiple inheritance, attributes and operations of non-first | 478 # With multiple inheritance, attributes and operations of non-first |
| 485 # interfaces need to be added. Sometimes the attribute or operation is | 479 # interfaces need to be added. Sometimes the attribute or operation is |
| 486 # defined in the current interface as well as a parent. In that case we | 480 # defined in the current interface as well as a parent. In that case we |
| 487 # avoid making a duplicate definition and pray that the signatures match. | 481 # avoid making a duplicate definition and pray that the signatures match. |
| 488 | 482 |
| 489 for parent_interface in self._TransitiveSecondaryParents(interface): | 483 for parent_interface in self._TransitiveSecondaryParents(interface): |
| 490 if isinstance(interface, str): # _IsDartCollectionType(parent_interface) | 484 if isinstance(interface, str): # _IsDartCollectionType(parent_interface) |
| 491 continue | 485 continue |
| 492 attributes = sorted(parent_interface.attributes, | 486 attributes = sorted(parent_interface.attributes, |
| 493 AttributeOutputOrder) | 487 AttributeOutputOrder) |
| 494 for attr in attributes: | 488 for attr in attributes: |
| 495 if not self._DefinesSameAttribute(interface, attr): | 489 if not self._DefinesSameAttribute(interface, attr): |
| 496 if attr.is_fc_getter: | 490 if attr.is_fc_getter: |
| 497 monkey_interface_generator.AddSecondaryGetter( | 491 for generator in generators: |
| 498 parent_interface, attr) | 492 generator.AddSecondaryGetter(parent_interface, attr) |
| 499 wrapping_interface_generator.AddSecondaryGetter( | |
| 500 parent_interface, attr) | |
| 501 frog_interface_generator.AddSecondaryGetter( | |
| 502 parent_interface, attr) | |
| 503 elif attr.is_fc_setter: | 493 elif attr.is_fc_setter: |
| 504 monkey_interface_generator.AddSecondarySetter( | 494 for generator in generators: |
| 505 parent_interface, attr) | 495 generator.AddSecondarySetter(parent_interface, attr) |
| 506 wrapping_interface_generator.AddSecondarySetter( | |
| 507 parent_interface, attr) | |
| 508 frog_interface_generator.AddSecondarySetter( | |
| 509 parent_interface, attr) | |
| 510 | 496 |
| 511 # Group overloaded operations by id | 497 # Group overloaded operations by id |
| 512 operationsById = {} | 498 operationsById = {} |
| 513 for operation in parent_interface.operations: | 499 for operation in parent_interface.operations: |
| 514 if operation.id not in operationsById: | 500 if operation.id not in operationsById: |
| 515 operationsById[operation.id] = [] | 501 operationsById[operation.id] = [] |
| 516 operationsById[operation.id].append(operation) | 502 operationsById[operation.id].append(operation) |
| 517 | 503 |
| 518 # Generate operations | 504 # Generate operations |
| 519 for id in sorted(operationsById.keys()): | 505 for id in sorted(operationsById.keys()): |
| 520 if not any(op.id == id for op in interface.operations): | 506 if not any(op.id == id for op in interface.operations): |
| 521 operations = operationsById[id] | 507 operations = operationsById[id] |
| 522 info = self._AnalyzeOperation(interface, operations) | 508 info = self._AnalyzeOperation(interface, operations) |
| 523 monkey_interface_generator.AddSecondaryOperation( | 509 for generator in generators: |
| 524 parent_interface, info) | 510 generator.AddSecondaryOperation(parent_interface, info) |
| 525 wrapping_interface_generator.AddSecondaryOperation( | |
| 526 parent_interface, info) | |
| 527 frog_interface_generator.AddSecondaryOperation( | |
| 528 parent_interface, info) | |
| 529 | 511 |
| 530 dart_interface_generator.FinishInterface(self._overloaded_types) | 512 for generator in generators: |
| 531 monkey_interface_generator.FinishInterface() | 513 generator.FinishInterface() |
| 532 wrapping_interface_generator.FinishInterface() | |
| 533 frog_interface_generator.FinishInterface() | |
| 534 return | 514 return |
| 535 | 515 |
| 536 def _DefinesSameAttribute(self, interface, attr1): | 516 def _DefinesSameAttribute(self, interface, attr1): |
| 537 return any(attr1.id == attr2.id | 517 return any(attr1.id == attr2.id |
| 538 and attr1.is_fc_getter == attr2.is_fc_getter | 518 and attr1.is_fc_getter == attr2.is_fc_getter |
| 539 and attr1.is_fc_setter == attr2.is_fc_setter | 519 and attr1.is_fc_setter == attr2.is_fc_setter |
| 540 for attr2 in interface.attributes) | 520 for attr2 in interface.attributes) |
| 541 | 521 |
| 542 def _TransitiveSecondaryParents(self, interface): | 522 def _TransitiveSecondaryParents(self, interface): |
| 543 """Returns a list of all non-primary parents. | 523 """Returns a list of all non-primary parents. |
| (...skipping 27 matching lines...) Expand all Loading... |
| 571 # Given a list of overloaded arguments, choose a suitable name. | 551 # Given a list of overloaded arguments, choose a suitable name. |
| 572 def OverloadedName(args): | 552 def OverloadedName(args): |
| 573 return '_OR_'.join(sorted(set(arg.id for arg in args))) | 553 return '_OR_'.join(sorted(set(arg.id for arg in args))) |
| 574 | 554 |
| 575 # Given a list of overloaded arguments, choose a suitable type. | 555 # Given a list of overloaded arguments, choose a suitable type. |
| 576 def OverloadedType(args): | 556 def OverloadedType(args): |
| 577 typeIds = sorted(set(arg.type.id for arg in args)) | 557 typeIds = sorted(set(arg.type.id for arg in args)) |
| 578 if len(typeIds) == 1: | 558 if len(typeIds) == 1: |
| 579 return typeIds[0] | 559 return typeIds[0] |
| 580 else: | 560 else: |
| 581 self._overloaded_types.add(tuple(typeIds)) | |
| 582 return TypeName(typeIds, interface) | 561 return TypeName(typeIds, interface) |
| 583 | 562 |
| 584 # Given a list of overloaded arguments, render a dart argument. | 563 # Given a list of overloaded arguments, render a dart argument. |
| 585 def DartArg(args): | 564 def DartArg(args): |
| 586 filtered = filter(None, args) | 565 filtered = filter(None, args) |
| 587 optional = any(not arg or arg.is_optional for arg in args) | 566 optional = any(not arg or arg.is_optional for arg in args) |
| 588 type = OverloadedType(filtered) | 567 type = OverloadedType(filtered) |
| 589 name = OverloadedName(filtered) | 568 name = OverloadedName(filtered) |
| 590 if optional: | 569 if optional: |
| 591 return (name, type, 'null') | 570 return (name, type, 'null') |
| (...skipping 509 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1101 | 1080 |
| 1102 comment = ' extends' | 1081 comment = ' extends' |
| 1103 if extends: | 1082 if extends: |
| 1104 extends_emitter.Emit(' extends $SUPERS', SUPERS=', '.join(extends)) | 1083 extends_emitter.Emit(' extends $SUPERS', SUPERS=', '.join(extends)) |
| 1105 comment = ',' | 1084 comment = ',' |
| 1106 if suppressed_extends: | 1085 if suppressed_extends: |
| 1107 extends_emitter.Emit(' /*$COMMENT $SUPERS */', | 1086 extends_emitter.Emit(' /*$COMMENT $SUPERS */', |
| 1108 COMMENT=comment, | 1087 COMMENT=comment, |
| 1109 SUPERS=', '.join(suppressed_extends)) | 1088 SUPERS=', '.join(suppressed_extends)) |
| 1110 | 1089 |
| 1111 def FinishInterface(self, overloaded_types): | 1090 def FinishInterface(self): |
| 1112 # Write snippet text that was inlined in the IDL. | 1091 # Write snippet text that was inlined in the IDL. |
| 1113 for snippet in self._interface.snippets: | 1092 for snippet in self._interface.snippets: |
| 1114 self._members_emitter.Emit('\n$LINES', | 1093 self._members_emitter.Emit('\n$LINES', |
| 1115 LINES=IndentText(snippets.text, ' ')) | 1094 LINES=IndentText(snippets.text, ' ')) |
| 1116 | 1095 |
| 1117 # TODO(vsm): Test if snippets are extra methods or extra types. | 1096 # TODO(vsm): Test if snippets are extra methods or extra types. |
| 1118 # Since Dart doesn't permit inner types, append after the interface. | 1097 # Since Dart doesn't permit inner types, append after the interface. |
| 1119 # Consider moving these types to auxilary classes instead. | 1098 # Consider moving these types to auxilary classes instead. |
| 1120 if self._extra_snippets is not None: | 1099 if self._extra_snippets is not None: |
| 1121 if 'interface' in self._extra_snippets: | 1100 if 'interface' in self._extra_snippets: |
| (...skipping 28 matching lines...) Expand all Loading... |
| 1150 VALUE=constant.value) | 1129 VALUE=constant.value) |
| 1151 | 1130 |
| 1152 def AddGetter(self, attr): | 1131 def AddGetter(self, attr): |
| 1153 self._members_emitter.Emit('\n $TYPE get $NAME();\n', | 1132 self._members_emitter.Emit('\n $TYPE get $NAME();\n', |
| 1154 NAME=attr.id, TYPE=attr.type.id) | 1133 NAME=attr.id, TYPE=attr.type.id) |
| 1155 | 1134 |
| 1156 def AddSetter(self, attr): | 1135 def AddSetter(self, attr): |
| 1157 self._members_emitter.Emit('\n void set $NAME($TYPE value);\n', | 1136 self._members_emitter.Emit('\n void set $NAME($TYPE value);\n', |
| 1158 NAME=attr.id, TYPE=attr.type.id) | 1137 NAME=attr.id, TYPE=attr.type.id) |
| 1159 | 1138 |
| 1139 def AddIndexer(self, element_type): |
| 1140 # Interface inherits all operations from List<element_type>. |
| 1141 pass |
| 1142 |
| 1160 def AddOperation(self, info): | 1143 def AddOperation(self, info): |
| 1161 """ | 1144 """ |
| 1162 Arguments: | 1145 Arguments: |
| 1163 operations - contains the overloads, one or more operations with the same | 1146 operations - contains the overloads, one or more operations with the same |
| 1164 name. | 1147 name. |
| 1165 """ | 1148 """ |
| 1166 self._members_emitter.Emit('\n' | 1149 self._members_emitter.Emit('\n' |
| 1167 ' $TYPE $NAME($ARGS);\n', | 1150 ' $TYPE $NAME($ARGS);\n', |
| 1168 TYPE=info.type_name, | 1151 TYPE=info.type_name, |
| 1169 NAME=info.name, | 1152 NAME=info.name, |
| 1170 ARGS=info.arg_interface_declaration) | 1153 ARGS=info.arg_interface_declaration) |
| 1171 | 1154 |
| 1155 # Interfaces get secondary members directly via the superinterfaces. |
| 1156 def AddSecondaryGetter(self, attr): |
| 1157 pass |
| 1158 def AddSecondarySetter(self, attr): |
| 1159 pass |
| 1160 def AddSecondaryOperation(self, attr): |
| 1161 pass |
| 1162 |
| 1172 | 1163 |
| 1173 # Given a sorted sequence of type identifiers, return an appropriate type | 1164 # Given a sorted sequence of type identifiers, return an appropriate type |
| 1174 # name | 1165 # name |
| 1175 def TypeName(typeIds, interface): | 1166 def TypeName(typeIds, interface): |
| 1176 # Dynamically type this field for now. | 1167 # Dynamically type this field for now. |
| 1177 return 'var' | 1168 return 'var' |
| 1178 | 1169 |
| 1179 | 1170 |
| 1180 # ------------------------------------------------------------------------------ | 1171 # ------------------------------------------------------------------------------ |
| 1181 | 1172 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1224 if interface.parents: | 1215 if interface.parents: |
| 1225 supertype = interface.parents[0].type.id | 1216 supertype = interface.parents[0].type.id |
| 1226 # FIXME: We're currently injecting List<..> and EventTarget as | 1217 # FIXME: We're currently injecting List<..> and EventTarget as |
| 1227 # supertypes in dart.idl. We should annotate/preserve as | 1218 # supertypes in dart.idl. We should annotate/preserve as |
| 1228 # attributes instead. For now, this hack lets the interfaces | 1219 # attributes instead. For now, this hack lets the interfaces |
| 1229 # inherit, but not the classes. | 1220 # inherit, but not the classes. |
| 1230 if (not _IsDartListType(supertype) and | 1221 if (not _IsDartListType(supertype) and |
| 1231 not supertype == 'EventTarget'): | 1222 not supertype == 'EventTarget'): |
| 1232 base = self._ImplClassName(supertype) | 1223 base = self._ImplClassName(supertype) |
| 1233 if _IsDartCollectionType(supertype): | 1224 if _IsDartCollectionType(supertype): |
| 1234 # List methods are injected in AddListImplementation. | 1225 # List methods are injected in AddIndexer. |
| 1235 pass | 1226 pass |
| 1236 elif supertype == 'EventTarget': | 1227 elif supertype == 'EventTarget': |
| 1237 # Most implementors of EventTarget specify the EventListener operations | 1228 # Most implementors of EventTarget specify the EventListener operations |
| 1238 # again. If the operations are not specified, try to inherit from the | 1229 # again. If the operations are not specified, try to inherit from the |
| 1239 # EventTarget implementation. | 1230 # EventTarget implementation. |
| 1240 # | 1231 # |
| 1241 # Applies to MessagePort. | 1232 # Applies to MessagePort. |
| 1242 if not [op for op in interface.operations if op.id == 'addEventListener'
]: | 1233 if not [op for op in interface.operations if op.id == 'addEventListener'
]: |
| 1243 base = self._ImplClassName(supertype) | 1234 base = self._ImplClassName(supertype) |
| 1244 else: | 1235 else: |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1261 CLASS=self._class_name, BASE=base, INTERFACE=interface_name) | 1252 CLASS=self._class_name, BASE=base, INTERFACE=interface_name) |
| 1262 | 1253 |
| 1263 def _ImplClassName(self, type_name): | 1254 def _ImplClassName(self, type_name): |
| 1264 return '_' + type_name + 'WrappingImplementation' | 1255 return '_' + type_name + 'WrappingImplementation' |
| 1265 | 1256 |
| 1266 def FinishInterface(self): | 1257 def FinishInterface(self): |
| 1267 """.""" | 1258 """.""" |
| 1268 pass | 1259 pass |
| 1269 | 1260 |
| 1270 def AddConstant(self, constant): | 1261 def AddConstant(self, constant): |
| 1262 # Constants are already defined on the interface. |
| 1271 pass | 1263 pass |
| 1272 | 1264 |
| 1273 def _MethodName(self, prefix, name): | 1265 def _MethodName(self, prefix, name): |
| 1274 method_name = prefix + name | 1266 method_name = prefix + name |
| 1275 if name in self._base_members: # Avoid illegal Dart 'static override'. | 1267 if name in self._base_members: # Avoid illegal Dart 'static override'. |
| 1276 method_name = method_name + '_' + self._interface.id | 1268 method_name = method_name + '_' + self._interface.id |
| 1277 return method_name | 1269 return method_name |
| 1278 | 1270 |
| 1279 def AddGetter(self, attr): | 1271 def AddGetter(self, attr): |
| 1280 # FIXME: Instead of injecting the interface name into the method when it is | 1272 # FIXME: Instead of injecting the interface name into the method when it is |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1329 | 1321 |
| 1330 def AddSecondaryOperation(self, interface, info): | 1322 def AddSecondaryOperation(self, interface, info): |
| 1331 self._SecondaryContext(interface) | 1323 self._SecondaryContext(interface) |
| 1332 self.AddOperation(info) | 1324 self.AddOperation(info) |
| 1333 | 1325 |
| 1334 def _SecondaryContext(self, interface): | 1326 def _SecondaryContext(self, interface): |
| 1335 if interface is not self._current_secondary_parent: | 1327 if interface is not self._current_secondary_parent: |
| 1336 self._current_secondary_parent = interface | 1328 self._current_secondary_parent = interface |
| 1337 self._members_emitter.Emit('\n // From $WHERE\n', WHERE=interface.id) | 1329 self._members_emitter.Emit('\n // From $WHERE\n', WHERE=interface.id) |
| 1338 | 1330 |
| 1339 | 1331 def AddIndexer(self, element_type): |
| 1340 def AddListImplementation(self, element_type): | |
| 1341 """Adds all the methods required to complete implementation of List.""" | 1332 """Adds all the methods required to complete implementation of List.""" |
| 1342 # We would like to simply inherit the implementation of everything except | 1333 # We would like to simply inherit the implementation of everything except |
| 1343 # get length(), [], and maybe []=. It is possible to extend from a base | 1334 # get length(), [], and maybe []=. It is possible to extend from a base |
| 1344 # array implementation class only when there is no other implementation | 1335 # array implementation class only when there is no other implementation |
| 1345 # inheritance. There might be no implementation inheritance other than | 1336 # inheritance. There might be no implementation inheritance other than |
| 1346 # DOMBaseWrapper for many classes, but there might be some where the | 1337 # DOMBaseWrapper for many classes, but there might be some where the |
| 1347 # array-ness is introduced by a non-root interface: | 1338 # array-ness is introduced by a non-root interface: |
| 1348 # | 1339 # |
| 1349 # interface Y extends X, List<T> ... | 1340 # interface Y extends X, List<T> ... |
| 1350 # | 1341 # |
| (...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1768 # {prototype: window.blah.blah.__proto__} | 1759 # {prototype: window.blah.blah.__proto__} |
| 1769 # perhaps we should return the real constructor: | 1760 # perhaps we should return the real constructor: |
| 1770 # window.blah.blah.constructor | 1761 # window.blah.blah.constructor |
| 1771 prefix = root; | 1762 prefix = root; |
| 1772 steps = [] | 1763 steps = [] |
| 1773 for accessor in accessors + ['__proto__']: | 1764 for accessor in accessors + ['__proto__']: |
| 1774 steps.append("(%s = %s.%s)" % (temp, prefix, accessor)); | 1765 steps.append("(%s = %s.%s)" % (temp, prefix, accessor)); |
| 1775 prefix = temp | 1766 prefix = temp |
| 1776 return "%s && (%s = {prototype: %s})" % (' && '.join(steps), temp, temp) | 1767 return "%s && (%s = {prototype: %s})" % (' && '.join(steps), temp, temp) |
| 1777 | 1768 |
| 1769 def AddConstant(self, constant): |
| 1770 pass |
| 1778 | 1771 |
| 1779 def AddGetter(self, attr): | 1772 def AddGetter(self, attr): |
| 1780 """Emits code to initialize an attribute getter.""" | 1773 """Emits code to initialize an attribute getter.""" |
| 1781 if attr.type.id in _evasive_types: | 1774 if attr.type.id in _evasive_types: |
| 1782 self._proto_code.Emit(' $PROTOREF.$NAME$getter = function() {' | 1775 self._proto_code.Emit(' $PROTOREF.$NAME$getter = function() {' |
| 1783 ' return DOM$fixValue$$TYPE(this.$NAME);' | 1776 ' return DOM$fixValue$$TYPE(this.$NAME);' |
| 1784 ' };\n', | 1777 ' };\n', |
| 1785 NAME=attr.id, TYPE=attr.type.id) | 1778 NAME=attr.id, TYPE=attr.type.id) |
| 1786 else: | 1779 else: |
| 1787 self._proto_code.Emit(' $PROTOREF.$NAME$getter = function() {' | 1780 self._proto_code.Emit(' $PROTOREF.$NAME$getter = function() {' |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1888 if interface.parents: | 1881 if interface.parents: |
| 1889 supertype = interface.parents[0].type.id | 1882 supertype = interface.parents[0].type.id |
| 1890 # FIXME: We're currently injecting List<..> and EventTarget as | 1883 # FIXME: We're currently injecting List<..> and EventTarget as |
| 1891 # supertypes in dart.idl. We should annotate/preserve as | 1884 # supertypes in dart.idl. We should annotate/preserve as |
| 1892 # attributes instead. For now, this hack lets the interfaces | 1885 # attributes instead. For now, this hack lets the interfaces |
| 1893 # inherit, but not the classes. | 1886 # inherit, but not the classes. |
| 1894 if (not _IsDartListType(supertype) and | 1887 if (not _IsDartListType(supertype) and |
| 1895 not supertype == 'EventTarget'): | 1888 not supertype == 'EventTarget'): |
| 1896 base = self._ImplClassName(supertype) | 1889 base = self._ImplClassName(supertype) |
| 1897 if _IsDartCollectionType(supertype): | 1890 if _IsDartCollectionType(supertype): |
| 1898 # List methods are injected in AddListImplementation. | 1891 # List methods are injected in AddIndexer. |
| 1899 pass | 1892 pass |
| 1900 elif supertype == 'EventTarget': | 1893 elif supertype == 'EventTarget': |
| 1901 # Most implementors of EventTarget specify the EventListener operations | 1894 # Most implementors of EventTarget specify the EventListener operations |
| 1902 # again. If the operations are not specified, try to inherit from the | 1895 # again. If the operations are not specified, try to inherit from the |
| 1903 # EventTarget implementation. | 1896 # EventTarget implementation. |
| 1904 # | 1897 # |
| 1905 # Applies to MessagePort. | 1898 # Applies to MessagePort. |
| 1906 if not [op for op in interface.operations if op.id == 'addEventListener'
]: | 1899 if not [op for op in interface.operations if op.id == 'addEventListener'
]: |
| 1907 base = self._ImplClassName(supertype) | 1900 base = self._ImplClassName(supertype) |
| 1908 else: | 1901 else: |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1961 | 1954 |
| 1962 def AddSecondaryOperation(self, interface, info): | 1955 def AddSecondaryOperation(self, interface, info): |
| 1963 self._SecondaryContext(interface) | 1956 self._SecondaryContext(interface) |
| 1964 self.AddOperation(info) | 1957 self.AddOperation(info) |
| 1965 | 1958 |
| 1966 def _SecondaryContext(self, interface): | 1959 def _SecondaryContext(self, interface): |
| 1967 if interface is not self._current_secondary_parent: | 1960 if interface is not self._current_secondary_parent: |
| 1968 self._current_secondary_parent = interface | 1961 self._current_secondary_parent = interface |
| 1969 self._members_emitter.Emit('\n // From $WHERE\n', WHERE=interface.id) | 1962 self._members_emitter.Emit('\n // From $WHERE\n', WHERE=interface.id) |
| 1970 | 1963 |
| 1971 | 1964 def AddIndexer(self, element_type): |
| 1972 def AddListImplementation(self, element_type): | |
| 1973 """Adds all the methods required to complete implementation of List.""" | 1965 """Adds all the methods required to complete implementation of List.""" |
| 1974 # We would like to simply inherit the implementation of everything except | 1966 # We would like to simply inherit the implementation of everything except |
| 1975 # get length(), [], and maybe []=. It is possible to extend from a base | 1967 # get length(), [], and maybe []=. It is possible to extend from a base |
| 1976 # array implementation class only when there is no other implementation | 1968 # array implementation class only when there is no other implementation |
| 1977 # inheritance. There might be no implementation inheritance other than | 1969 # inheritance. There might be no implementation inheritance other than |
| 1978 # DOMBaseWrapper for many classes, but there might be some where the | 1970 # DOMBaseWrapper for many classes, but there might be some where the |
| 1979 # array-ness is introduced by a non-root interface: | 1971 # array-ness is introduced by a non-root interface: |
| 1980 # | 1972 # |
| 1981 # interface Y extends X, List<T> ... | 1973 # interface Y extends X, List<T> ... |
| 1982 # | 1974 # |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1998 Arguments: | 1990 Arguments: |
| 1999 info: An OperationInfo object. | 1991 info: An OperationInfo object. |
| 2000 """ | 1992 """ |
| 2001 # TODO(vsm): Handle overloads. | 1993 # TODO(vsm): Handle overloads. |
| 2002 self._members_emitter.Emit( | 1994 self._members_emitter.Emit( |
| 2003 '\n' | 1995 '\n' |
| 2004 ' $TYPE $NAME($ARGS) native;\n', | 1996 ' $TYPE $NAME($ARGS) native;\n', |
| 2005 TYPE=info.type_name, | 1997 TYPE=info.type_name, |
| 2006 NAME=info.name, | 1998 NAME=info.name, |
| 2007 ARGS=info.arg_implementation_declaration) | 1999 ARGS=info.arg_implementation_declaration) |
| OLD | NEW |