OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 2 # Copyright (c) 2012, 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 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
369 """ | 369 """ |
370 | 370 |
371 self._emitters = multiemitter.MultiEmitter() | 371 self._emitters = multiemitter.MultiEmitter() |
372 self._database = database | 372 self._database = database |
373 self._output_dir = output_dir | 373 self._output_dir = output_dir |
374 | 374 |
375 self._ComputeInheritanceClosure() | 375 self._ComputeInheritanceClosure() |
376 | 376 |
377 self._systems = [] | 377 self._systems = [] |
378 | 378 |
| 379 # TODO(jmesserly): only create these if needed |
379 interface_system = InterfacesSystem( | 380 interface_system = InterfacesSystem( |
380 TemplateLoader(self._template_dir, ['dom/interface', 'dom', '']), | 381 TemplateLoader(self._template_dir, ['dom/interface', 'dom', '']), |
381 self._database, self._emitters, self._output_dir) | 382 self._database, self._emitters, self._output_dir) |
382 self._systems.append(interface_system) | 383 self._systems.append(interface_system) |
383 | 384 |
| 385 html_interface_system = HtmlInterfacesSystem( |
| 386 TemplateLoader(self._template_dir, ['html/interface', 'html', '']), |
| 387 self._database, self._emitters, self._output_dir) |
| 388 self._systems.append(html_interface_system) |
| 389 |
384 if 'native' in systems: | 390 if 'native' in systems: |
385 native_system = NativeImplementationSystem( | 391 native_system = NativeImplementationSystem( |
386 TemplateLoader(self._template_dir, ['dom/native', 'dom', '']), | 392 TemplateLoader(self._template_dir, ['dom/native', 'dom', '']), |
387 self._database, self._emitters, self._auxiliary_dir, | 393 self._database, self._emitters, self._auxiliary_dir, |
388 self._output_dir) | 394 self._output_dir) |
389 | 395 |
390 self._systems.append(native_system) | 396 self._systems.append(native_system) |
391 | 397 |
392 if 'wrapping' in systems: | 398 if 'wrapping' in systems: |
393 wrapping_system = WrappingImplementationSystem( | 399 wrapping_system = WrappingImplementationSystem( |
(...skipping 16 matching lines...) Expand all Loading... |
410 self._systems.append(dummy_system) | 416 self._systems.append(dummy_system) |
411 | 417 |
412 if 'frog' in systems: | 418 if 'frog' in systems: |
413 frog_system = FrogSystem( | 419 frog_system = FrogSystem( |
414 TemplateLoader(self._template_dir, ['dom/frog', 'dom', '']), | 420 TemplateLoader(self._template_dir, ['dom/frog', 'dom', '']), |
415 self._database, self._emitters, self._output_dir) | 421 self._database, self._emitters, self._output_dir) |
416 | 422 |
417 frog_system._interface_system = interface_system | 423 frog_system._interface_system = interface_system |
418 self._systems.append(frog_system) | 424 self._systems.append(frog_system) |
419 | 425 |
| 426 if 'htmlfrog' in systems: |
| 427 html_system = HtmlFrogSystem( |
| 428 TemplateLoader(self._template_dir, ['html/frog', 'html', '']), |
| 429 self._database, self._emitters, self._output_dir) |
| 430 |
| 431 html_system._interface_system = html_interface_system |
| 432 self._systems.append(html_system) |
| 433 |
| 434 if 'htmldartium' in systems: |
| 435 html_system = HtmlDartiumSystem( |
| 436 TemplateLoader(self._template_dir, ['html/dartium', 'html', '']), |
| 437 self._database, self._emitters, self._output_dir) |
| 438 |
| 439 html_system._interface_system = html_interface_system |
| 440 self._systems.append(html_system) |
420 | 441 |
421 # Render all interfaces into Dart and save them in files. | 442 # Render all interfaces into Dart and save them in files. |
422 for interface in database.GetInterfaces(): | 443 for interface in database.GetInterfaces(): |
423 | 444 |
424 super_interface = None | 445 super_interface = None |
425 super_name = interface.id | 446 super_name = interface.id |
426 | 447 |
427 if not _MatchSourceFilter(source_filter, interface): | 448 if not _MatchSourceFilter(source_filter, interface): |
428 # Skip this interface since it's not present in the required source | 449 # Skip this interface since it's not present in the required source |
429 _logger.info('Omitting interface - %s' % interface.id) | 450 _logger.info('Omitting interface - %s' % interface.id) |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
476 for system in self._systems] | 497 for system in self._systems] |
477 | 498 |
478 for generator in generators: | 499 for generator in generators: |
479 generator.StartInterface() | 500 generator.StartInterface() |
480 | 501 |
481 for const in sorted(interface.constants, ConstantOutputOrder): | 502 for const in sorted(interface.constants, ConstantOutputOrder): |
482 for generator in generators: | 503 for generator in generators: |
483 generator.AddConstant(const) | 504 generator.AddConstant(const) |
484 | 505 |
485 attributes = [attr for attr in interface.attributes | 506 attributes = [attr for attr in interface.attributes |
486 if not self._OmitAttribute(interface, attr)] | 507 if not self._IsEventAttribute(interface, attr)] |
487 for (getter, setter) in _PairUpAttributes(attributes): | 508 for (getter, setter) in _PairUpAttributes(attributes): |
488 for generator in generators: | 509 for generator in generators: |
489 generator.AddAttribute(getter, setter) | 510 generator.AddAttribute(getter, setter) |
490 | 511 |
| 512 events = _PairUpAttributes([attr for attr in interface.attributes |
| 513 if self._IsEventAttribute(interface, attr)]) |
| 514 if events: |
| 515 for generator in generators: |
| 516 generator.AddEventAttributes(events) |
| 517 |
491 # The implementation should define an indexer if the interface directly | 518 # The implementation should define an indexer if the interface directly |
492 # extends List. | 519 # extends List. |
493 element_type = MaybeListElementType(interface) | 520 element_type = MaybeListElementType(interface) |
494 if element_type: | 521 if element_type: |
495 for generator in generators: | 522 for generator in generators: |
496 generator.AddIndexer(element_type) | 523 generator.AddIndexer(element_type) |
497 | 524 |
498 # Group overloaded operations by id | 525 # Group overloaded operations by id |
499 operationsById = {} | 526 operationsById = {} |
500 for operation in interface.operations: | 527 for operation in interface.operations: |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
535 if not any(op.id == id for op in interface.operations): | 562 if not any(op.id == id for op in interface.operations): |
536 operations = operationsById[id] | 563 operations = operationsById[id] |
537 info = _AnalyzeOperation(interface, operations) | 564 info = _AnalyzeOperation(interface, operations) |
538 for generator in generators: | 565 for generator in generators: |
539 generator.AddSecondaryOperation(parent_interface, info) | 566 generator.AddSecondaryOperation(parent_interface, info) |
540 | 567 |
541 for generator in generators: | 568 for generator in generators: |
542 generator.FinishInterface() | 569 generator.FinishInterface() |
543 return | 570 return |
544 | 571 |
545 def _OmitAttribute(self, interface, attr): | 572 def _IsEventAttribute(self, interface, attr): |
546 # Remove EventListener attributes like 'onclick' when addEventListener | 573 # Remove EventListener attributes like 'onclick' when addEventListener |
547 # is available. | 574 # is available. |
548 if attr.type.id == 'EventListener': | 575 if attr.type.id == 'EventListener': |
549 if 'EventTarget' in self._AllImplementedInterfaces(interface): | 576 if 'EventTarget' in self._AllImplementedInterfaces(interface): |
550 return True | 577 return True |
551 return False | 578 return False |
552 | 579 |
553 def _DefinesSameAttribute(self, interface, attr1): | 580 def _DefinesSameAttribute(self, interface, attr1): |
554 return any(attr1.id == attr2.id | 581 return any(attr1.id == attr2.id |
555 and attr1.is_fc_getter == attr2.is_fc_getter | 582 and attr1.is_fc_getter == attr2.is_fc_getter |
(...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
975 | 1002 |
976 | 1003 |
977 def _FilePathForDartInterface(self, interface_name): | 1004 def _FilePathForDartInterface(self, interface_name): |
978 """Returns the file path of the Dart interface definition.""" | 1005 """Returns the file path of the Dart interface definition.""" |
979 return os.path.join(self._output_dir, 'src', 'interface', | 1006 return os.path.join(self._output_dir, 'src', 'interface', |
980 '%s.dart' % interface_name) | 1007 '%s.dart' % interface_name) |
981 | 1008 |
982 | 1009 |
983 # ------------------------------------------------------------------------------ | 1010 # ------------------------------------------------------------------------------ |
984 | 1011 |
| 1012 class HtmlInterfacesSystem(System): |
| 1013 |
| 1014 def __init__(self, templates, database, emitters, output_dir): |
| 1015 super(HtmlInterfacesSystem, self).__init__( |
| 1016 templates, database, emitters, output_dir) |
| 1017 self._dart_interface_file_paths = [] |
| 1018 |
| 1019 def InterfaceGenerator(self, |
| 1020 interface, |
| 1021 common_prefix, |
| 1022 super_interface_name, |
| 1023 source_filter): |
| 1024 """.""" |
| 1025 interface_name = interface.id |
| 1026 dart_interface_file_path = self._FilePathForDartInterface(interface_name) |
| 1027 |
| 1028 self._dart_interface_file_paths.append(dart_interface_file_path) |
| 1029 |
| 1030 dart_interface_code = self._emitters.FileEmitter(dart_interface_file_path) |
| 1031 |
| 1032 template_file = 'interface_%s.darttemplate' % interface_name |
| 1033 template = self._templates.TryLoad(template_file) |
| 1034 if not template: |
| 1035 template = self._templates.Load('interface.darttemplate') |
| 1036 |
| 1037 return HtmlDartInterfaceGenerator( |
| 1038 interface, dart_interface_code, |
| 1039 template, |
| 1040 common_prefix, super_interface_name, |
| 1041 source_filter) |
| 1042 |
| 1043 def ProcessCallback(self, interface, info): |
| 1044 """Generates a typedef for the callback interface.""" |
| 1045 interface_name = interface.id |
| 1046 file_path = self._FilePathForDartInterface(interface_name) |
| 1047 self._ProcessCallback(interface, info, file_path) |
| 1048 |
| 1049 def GenerateLibraries(self, lib_dir): |
| 1050 pass |
| 1051 |
| 1052 |
| 1053 def _FilePathForDartInterface(self, interface_name): |
| 1054 """Returns the file path of the Dart interface definition.""" |
| 1055 # TODO(jmesserly): is this the right path |
| 1056 return os.path.join(self._output_dir, 'html', 'interface', |
| 1057 '%s.dart' % interface_name) |
| 1058 |
| 1059 |
| 1060 # ------------------------------------------------------------------------------ |
| 1061 |
985 class DummyImplementationSystem(System): | 1062 class DummyImplementationSystem(System): |
986 """Generates a dummy implementation for use by the editor analysis. | 1063 """Generates a dummy implementation for use by the editor analysis. |
987 | 1064 |
988 All the code comes from hand-written library files. | 1065 All the code comes from hand-written library files. |
989 """ | 1066 """ |
990 | 1067 |
991 def __init__(self, templates, database, emitters, output_dir): | 1068 def __init__(self, templates, database, emitters, output_dir): |
992 super(DummyImplementationSystem, self).__init__( | 1069 super(DummyImplementationSystem, self).__init__( |
993 templates, database, emitters, output_dir) | 1070 templates, database, emitters, output_dir) |
994 | 1071 |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1087 """.""" | 1164 """.""" |
1088 dart_frog_file_path = self._FilePathForFrogImpl(interface.id) | 1165 dart_frog_file_path = self._FilePathForFrogImpl(interface.id) |
1089 self._dart_frog_file_paths.append(dart_frog_file_path) | 1166 self._dart_frog_file_paths.append(dart_frog_file_path) |
1090 | 1167 |
1091 template_file = 'impl_%s.darttemplate' % interface.id | 1168 template_file = 'impl_%s.darttemplate' % interface.id |
1092 template = self._templates.TryLoad(template_file) | 1169 template = self._templates.TryLoad(template_file) |
1093 if not template: | 1170 if not template: |
1094 template = self._templates.Load('frog_impl.darttemplate') | 1171 template = self._templates.Load('frog_impl.darttemplate') |
1095 | 1172 |
1096 dart_code = self._emitters.FileEmitter(dart_frog_file_path) | 1173 dart_code = self._emitters.FileEmitter(dart_frog_file_path) |
1097 # dart_code.Emit(self._templates.Load('frog_impl.darttemplate')) | |
1098 return FrogInterfaceGenerator(self, interface, template, | 1174 return FrogInterfaceGenerator(self, interface, template, |
1099 super_interface_name, dart_code) | 1175 super_interface_name, dart_code) |
1100 | 1176 |
1101 #def ProcessCallback(self, interface, info): | |
1102 # """Generates a typedef for the callback interface.""" | |
1103 # file_path = self._FilePathForFrogImpl(interface.id) | |
1104 # self._ProcessCallback(interface, info, file_path) | |
1105 | |
1106 def GenerateLibraries(self, lib_dir): | 1177 def GenerateLibraries(self, lib_dir): |
1107 self._GenerateLibFile( | 1178 self._GenerateLibFile( |
1108 'frog_dom.darttemplate', | 1179 'frog_dom.darttemplate', |
1109 os.path.join(lib_dir, 'dom_frog.dart'), | 1180 os.path.join(lib_dir, 'dom_frog.dart'), |
1110 (self._interface_system._dart_interface_file_paths + | 1181 (self._interface_system._dart_interface_file_paths + |
1111 self._interface_system._dart_callback_file_paths + | 1182 self._interface_system._dart_callback_file_paths + |
1112 self._dart_frog_file_paths)) | 1183 self._dart_frog_file_paths)) |
1113 | 1184 |
1114 def Finish(self): | 1185 def Finish(self): |
1115 pass | 1186 pass |
1116 | 1187 |
1117 def _FilePathForFrogImpl(self, interface_name): | 1188 def _FilePathForFrogImpl(self, interface_name): |
1118 """Returns the file path of the Frog implementation.""" | 1189 """Returns the file path of the Frog implementation.""" |
1119 return os.path.join(self._output_dir, 'src', 'frog', | 1190 return os.path.join(self._output_dir, 'src', 'frog', |
1120 '%s.dart' % interface_name) | 1191 '%s.dart' % interface_name) |
1121 | 1192 |
| 1193 |
| 1194 # ------------------------------------------------------------------------------ |
| 1195 |
| 1196 class HtmlFrogSystem(System): |
| 1197 |
| 1198 def __init__(self, templates, database, emitters, output_dir): |
| 1199 super(HtmlFrogSystem, self).__init__( |
| 1200 templates, database, emitters, output_dir) |
| 1201 self._dart_frog_file_paths = [] |
| 1202 |
| 1203 def InterfaceGenerator(self, |
| 1204 interface, |
| 1205 common_prefix, |
| 1206 super_interface_name, |
| 1207 source_filter): |
| 1208 """.""" |
| 1209 dart_frog_file_path = self._FilePathForFrogImpl(interface.id) |
| 1210 self._dart_frog_file_paths.append(dart_frog_file_path) |
| 1211 |
| 1212 template_file = 'impl_%s.darttemplate' % interface.id |
| 1213 template = self._templates.TryLoad(template_file) |
| 1214 if not template: |
| 1215 template = self._templates.Load('frog_impl.darttemplate') |
| 1216 |
| 1217 dart_code = self._emitters.FileEmitter(dart_frog_file_path) |
| 1218 return HtmlFrogInterfaceGenerator(self, interface, template, |
| 1219 super_interface_name, dart_code) |
| 1220 |
| 1221 def GenerateLibraries(self, lib_dir): |
| 1222 self._GenerateLibFile( |
| 1223 'html_frog.darttemplate', |
| 1224 os.path.join(lib_dir, 'html_frog.dart'), |
| 1225 (self._interface_system._dart_interface_file_paths + |
| 1226 self._interface_system._dart_callback_file_paths + |
| 1227 self._dart_frog_file_paths)) |
| 1228 |
| 1229 def Finish(self): |
| 1230 pass |
| 1231 |
| 1232 def _FilePathForFrogImpl(self, interface_name): |
| 1233 """Returns the file path of the Frog implementation.""" |
| 1234 # TODO(jmesserly): is this the right path |
| 1235 return os.path.join(self._output_dir, 'html', 'frog', |
| 1236 '%s.dart' % interface_name) |
| 1237 |
1122 # ------------------------------------------------------------------------------ | 1238 # ------------------------------------------------------------------------------ |
1123 | 1239 |
1124 class DartInterfaceGenerator(object): | 1240 class DartInterfaceGenerator(object): |
1125 """Generates Dart Interface definition for one DOM IDL interface.""" | 1241 """Generates Dart Interface definition for one DOM IDL interface.""" |
1126 | 1242 |
1127 def __init__(self, interface, emitter, template, | 1243 def __init__(self, interface, emitter, template, |
1128 common_prefix, super_interface, source_filter): | 1244 common_prefix, super_interface, source_filter): |
1129 """Generates Dart code for the given interface. | 1245 """Generates Dart code for the given interface. |
1130 | 1246 |
1131 Args: | 1247 Args: |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1254 NAME=info.name, | 1370 NAME=info.name, |
1255 PARAMS=info.ParametersInterfaceDeclaration()) | 1371 PARAMS=info.ParametersInterfaceDeclaration()) |
1256 | 1372 |
1257 # Interfaces get secondary members directly via the superinterfaces. | 1373 # Interfaces get secondary members directly via the superinterfaces. |
1258 def AddSecondaryAttribute(self, interface, getter, setter): | 1374 def AddSecondaryAttribute(self, interface, getter, setter): |
1259 pass | 1375 pass |
1260 | 1376 |
1261 def AddSecondaryOperation(self, interface, attr): | 1377 def AddSecondaryOperation(self, interface, attr): |
1262 pass | 1378 pass |
1263 | 1379 |
| 1380 def AddEventAttributes(self, event_attrs): |
| 1381 pass |
1264 | 1382 |
1265 # Given a sorted sequence of type identifiers, return an appropriate type | 1383 # Given a sorted sequence of type identifiers, return an appropriate type |
1266 # name | 1384 # name |
1267 def TypeName(typeIds, interface): | 1385 def TypeName(typeIds, interface): |
1268 # Dynamically type this field for now. | 1386 # Dynamically type this field for now. |
1269 return 'var' | 1387 return 'var' |
1270 | 1388 |
| 1389 # ------------------------------------------------------------------------------ |
| 1390 |
| 1391 # TODO(jmesserly): inheritance is probably not the right way to factor this long |
| 1392 # term, but it makes merging better for now. |
| 1393 class HtmlDartInterfaceGenerator(DartInterfaceGenerator): |
| 1394 """Generates Dart Interface definition for one DOM IDL interface.""" |
| 1395 |
| 1396 def __init__(self, interface, emitter, template, |
| 1397 common_prefix, super_interface, source_filter): |
| 1398 super(HtmlDartInterfaceGenerator, self).__init__(interface, |
| 1399 emitter, template, common_prefix, super_interface, source_filter) |
| 1400 |
| 1401 def AddEventAttributes(self, event_attrs): |
| 1402 events_interface = self._interface.id + 'Events' |
| 1403 self._members_emitter.Emit('\n $TYPE get on();\n', |
| 1404 TYPE=events_interface) |
| 1405 events_members = self._emitter.Emit( |
| 1406 '\ninterface $INTERFACE {\n$!MEMBERS}\n', |
| 1407 INTERFACE=events_interface) |
| 1408 |
| 1409 for getter, setter in event_attrs: |
| 1410 event = getter or setter |
| 1411 events_members.Emit('\n EventListenerList get $NAME();\n', NAME=event.id) |
| 1412 |
1271 | 1413 |
1272 # ------------------------------------------------------------------------------ | 1414 # ------------------------------------------------------------------------------ |
1273 | 1415 |
1274 class DummyInterfaceGenerator(object): | 1416 class DummyInterfaceGenerator(object): |
1275 """Generates nothing.""" | 1417 """Generates nothing.""" |
1276 | 1418 |
1277 def __init__(self, system, interface): | 1419 def __init__(self, system, interface): |
1278 pass | 1420 pass |
1279 | 1421 |
1280 def StartInterface(self): | 1422 def StartInterface(self): |
(...skipping 16 matching lines...) Expand all Loading... |
1297 | 1439 |
1298 def AddIndexer(self, element_type): | 1440 def AddIndexer(self, element_type): |
1299 pass | 1441 pass |
1300 | 1442 |
1301 def AddTypedArrayConstructors(self, element_type): | 1443 def AddTypedArrayConstructors(self, element_type): |
1302 pass | 1444 pass |
1303 | 1445 |
1304 def AddOperation(self, info): | 1446 def AddOperation(self, info): |
1305 pass | 1447 pass |
1306 | 1448 |
| 1449 def AddEventAttributes(self, event_attrs): |
| 1450 pass |
| 1451 |
1307 # ------------------------------------------------------------------------------ | 1452 # ------------------------------------------------------------------------------ |
1308 | 1453 |
1309 class WrappingInterfaceGenerator(object): | 1454 class WrappingInterfaceGenerator(object): |
1310 """Generates Dart and JS implementation for one DOM IDL interface.""" | 1455 """Generates Dart and JS implementation for one DOM IDL interface.""" |
1311 | 1456 |
1312 def __init__(self, interface, super_interface, dart_code, base_members): | 1457 def __init__(self, interface, super_interface, dart_code, base_members): |
1313 """Generates Dart and JS code for the given interface. | 1458 """Generates Dart and JS code for the given interface. |
1314 | 1459 |
1315 Args: | 1460 Args: |
1316 | 1461 |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1425 NAME=attr.id, TYPE=attr.type.id, METHOD=method_name) | 1570 NAME=attr.id, TYPE=attr.type.id, METHOD=method_name) |
1426 | 1571 |
1427 def AddSecondaryAttribute(self, interface, getter, setter): | 1572 def AddSecondaryAttribute(self, interface, getter, setter): |
1428 self._SecondaryContext(interface) | 1573 self._SecondaryContext(interface) |
1429 self.AddAttribute(getter, setter) | 1574 self.AddAttribute(getter, setter) |
1430 | 1575 |
1431 def AddSecondaryOperation(self, interface, info): | 1576 def AddSecondaryOperation(self, interface, info): |
1432 self._SecondaryContext(interface) | 1577 self._SecondaryContext(interface) |
1433 self.AddOperation(info) | 1578 self.AddOperation(info) |
1434 | 1579 |
| 1580 def AddEventAttributes(self, event_attrs): |
| 1581 pass |
| 1582 |
1435 def _SecondaryContext(self, interface): | 1583 def _SecondaryContext(self, interface): |
1436 if interface is not self._current_secondary_parent: | 1584 if interface is not self._current_secondary_parent: |
1437 self._current_secondary_parent = interface | 1585 self._current_secondary_parent = interface |
1438 self._members_emitter.Emit('\n // From $WHERE\n', WHERE=interface.id) | 1586 self._members_emitter.Emit('\n // From $WHERE\n', WHERE=interface.id) |
1439 | 1587 |
1440 def AddIndexer(self, element_type): | 1588 def AddIndexer(self, element_type): |
1441 """Adds all the methods required to complete implementation of List.""" | 1589 """Adds all the methods required to complete implementation of List.""" |
1442 # We would like to simply inherit the implementation of everything except | 1590 # We would like to simply inherit the implementation of everything except |
1443 # get length(), [], and maybe []=. It is possible to extend from a base | 1591 # get length(), [], and maybe []=. It is possible to extend from a base |
1444 # array implementation class only when there is no other implementation | 1592 # array implementation class only when there is no other implementation |
(...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1922 NAME=attr.id, TYPE=self._NarrowInputType(attr.type.id)) | 2070 NAME=attr.id, TYPE=self._NarrowInputType(attr.type.id)) |
1923 | 2071 |
1924 def AddSecondaryAttribute(self, interface, getter, setter): | 2072 def AddSecondaryAttribute(self, interface, getter, setter): |
1925 self._SecondaryContext(interface) | 2073 self._SecondaryContext(interface) |
1926 self.AddAttribute(getter, setter) | 2074 self.AddAttribute(getter, setter) |
1927 | 2075 |
1928 def AddSecondaryOperation(self, interface, info): | 2076 def AddSecondaryOperation(self, interface, info): |
1929 self._SecondaryContext(interface) | 2077 self._SecondaryContext(interface) |
1930 self.AddOperation(info) | 2078 self.AddOperation(info) |
1931 | 2079 |
| 2080 def AddEventAttributes(self, event_attrs): |
| 2081 pass |
| 2082 |
1932 def _SecondaryContext(self, interface): | 2083 def _SecondaryContext(self, interface): |
1933 if interface is not self._current_secondary_parent: | 2084 if interface is not self._current_secondary_parent: |
1934 self._current_secondary_parent = interface | 2085 self._current_secondary_parent = interface |
1935 self._members_emitter.Emit('\n // From $WHERE\n', WHERE=interface.id) | 2086 self._members_emitter.Emit('\n // From $WHERE\n', WHERE=interface.id) |
1936 | 2087 |
1937 def AddIndexer(self, element_type): | 2088 def AddIndexer(self, element_type): |
1938 """Adds all the methods required to complete implementation of List.""" | 2089 """Adds all the methods required to complete implementation of List.""" |
1939 # We would like to simply inherit the implementation of everything except | 2090 # We would like to simply inherit the implementation of everything except |
1940 # get length(), [], and maybe []=. It is possible to extend from a base | 2091 # get length(), [], and maybe []=. It is possible to extend from a base |
1941 # array implementation class only when there is no other implementation | 2092 # array implementation class only when there is no other implementation |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2002 '\n' | 2153 '\n' |
2003 ' $TYPE $NAME($PARAMS) native;\n', | 2154 ' $TYPE $NAME($PARAMS) native;\n', |
2004 TYPE=self._NarrowOutputType(info.type_name), | 2155 TYPE=self._NarrowOutputType(info.type_name), |
2005 NAME=info.name, | 2156 NAME=info.name, |
2006 PARAMS=info.ParametersImplementationDeclaration( | 2157 PARAMS=info.ParametersImplementationDeclaration( |
2007 lambda type_name: self._NarrowInputType(type_name))) | 2158 lambda type_name: self._NarrowInputType(type_name))) |
2008 | 2159 |
2009 | 2160 |
2010 # ------------------------------------------------------------------------------ | 2161 # ------------------------------------------------------------------------------ |
2011 | 2162 |
| 2163 # TODO(jmesserly): inheritance is probably not the right way to factor this long |
| 2164 # term, but it makes merging better for now. |
| 2165 class HtmlFrogInterfaceGenerator(FrogInterfaceGenerator): |
| 2166 """Generates a Frog class for the dart:html library from a DOM IDL |
| 2167 interface. |
| 2168 """ |
| 2169 |
| 2170 def __init__(self, system, interface, template, super_interface, dart_code): |
| 2171 super(HtmlFrogInterfaceGenerator, self).__init__( |
| 2172 system, interface, template, super_interface, dart_code) |
| 2173 |
| 2174 def AddEventAttributes(self, event_attrs): |
| 2175 events_class = self._interface.id + 'EventsImpl' |
| 2176 events_interface = self._interface.id + 'Events' |
| 2177 self._members_emitter.Emit('\n $TYPE get on() =>\n new $TYPE(this);\n', |
| 2178 TYPE=events_class) |
| 2179 |
| 2180 events_members = self._dart_code.Emit( |
| 2181 '\n' |
| 2182 'class $CLASSNAME extends EventsImplementation ' |
| 2183 'implements $INTERFACE {\n' |
| 2184 ' $CLASSNAME(_ptr) : super._wrap(_ptr);\n' |
| 2185 '$!MEMBERS}\n', |
| 2186 CLASSNAME=events_class, |
| 2187 INTERFACE=events_interface) |
| 2188 |
| 2189 for getter, setter in event_attrs: |
| 2190 event = getter or setter |
| 2191 events_members.Emit( |
| 2192 "\n" |
| 2193 "EventListenerList get $NAME() => _get('$NAME');\n", |
| 2194 NAME=event.id) |
| 2195 |
| 2196 |
| 2197 # ------------------------------------------------------------------------------ |
| 2198 |
2012 class NativeImplementationSystem(System): | 2199 class NativeImplementationSystem(System): |
2013 | 2200 |
2014 def __init__(self, templates, database, emitters, auxiliary_dir, output_dir): | 2201 def __init__(self, templates, database, emitters, auxiliary_dir, output_dir): |
2015 super(NativeImplementationSystem, self).__init__( | 2202 super(NativeImplementationSystem, self).__init__( |
2016 templates, database, emitters, output_dir) | 2203 templates, database, emitters, output_dir) |
2017 | 2204 |
2018 self._auxiliary_dir = auxiliary_dir | 2205 self._auxiliary_dir = auxiliary_dir |
2019 self._dom_public_files = [] | 2206 self._dom_public_files = [] |
2020 self._dom_impl_files = [] | 2207 self._dom_impl_files = [] |
2021 | 2208 |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2212 INDENT=indent, | 2399 INDENT=indent, |
2213 NATIVENAME=native_name, | 2400 NATIVENAME=native_name, |
2214 ARGS=argument_expressions) | 2401 ARGS=argument_expressions) |
2215 | 2402 |
2216 self._members_emitter.Emit(' $TYPE $NATIVE_NAME($PARAMS) native ' | 2403 self._members_emitter.Emit(' $TYPE $NATIVE_NAME($PARAMS) native ' |
2217 '"$(INTERFACE)$(NATIVE_NAME)_Callback";\n', | 2404 '"$(INTERFACE)$(NATIVE_NAME)_Callback";\n', |
2218 NATIVE_NAME=native_name, | 2405 NATIVE_NAME=native_name, |
2219 TYPE=info.type_name, | 2406 TYPE=info.type_name, |
2220 PARAMS=', '.join(arg_names), | 2407 PARAMS=', '.join(arg_names), |
2221 INTERFACE=self._interface.id) | 2408 INTERFACE=self._interface.id) |
OLD | NEW |