| 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 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 359 self._database = database | 359 self._database = database |
| 360 self._output_dir = output_dir | 360 self._output_dir = output_dir |
| 361 | 361 |
| 362 self._StartGenerateInterfaceLibrary() | 362 self._StartGenerateInterfaceLibrary() |
| 363 self._StartGenerateJavaScriptMonkeyImpl(database, output_dir) | 363 self._StartGenerateJavaScriptMonkeyImpl(database, output_dir) |
| 364 self._StartGenerateWrappingImpl(output_dir) | 364 self._StartGenerateWrappingImpl(output_dir) |
| 365 self._StartGenerateFrogImpl(output_dir) | 365 self._StartGenerateFrogImpl(output_dir) |
| 366 | 366 |
| 367 # Render all interfaces into Dart and save them in files. | 367 # Render all interfaces into Dart and save them in files. |
| 368 dart_file_paths = [] | 368 dart_file_paths = [] |
| 369 processed_interfaces = [] |
| 369 for interface in database.GetInterfaces(): | 370 for interface in database.GetInterfaces(): |
| 370 | 371 |
| 371 super_interface = None | 372 super_interface = None |
| 372 super_name = interface.id | 373 super_name = interface.id |
| 373 | 374 |
| 374 if not _MatchSourceFilter(source_filter, interface): | 375 if not _MatchSourceFilter(source_filter, interface): |
| 375 # Skip this interface since it's not present in the required source | 376 # Skip this interface since it's not present in the required source |
| 376 _logger.info('Omitting interface - %s' % interface.id) | 377 _logger.info('Omitting interface - %s' % interface.id) |
| 377 continue | 378 continue |
| 378 | 379 |
| 379 if super_name in super_map: | 380 if super_name in super_map: |
| 380 super_name = super_map[super_name] | 381 super_name = super_map[super_name] |
| 381 | 382 |
| 382 if (super_database is not None and | 383 if (super_database is not None and |
| 383 super_database.HasInterface(super_name)): | 384 super_database.HasInterface(super_name)): |
| 384 super_interface = super_name | 385 super_interface = super_name |
| 385 | 386 |
| 386 interface_name = interface.id | 387 interface_name = interface.id |
| 387 auxiliary_file = self._auxiliary_files.get(interface_name) | 388 auxiliary_file = self._auxiliary_files.get(interface_name) |
| 388 if auxiliary_file is not None: | 389 if auxiliary_file is not None: |
| 389 _logger.info('Skipping %s because %s exists' % ( | 390 _logger.info('Skipping %s because %s exists' % ( |
| 390 interface_name, auxiliary_file)) | 391 interface_name, auxiliary_file)) |
| 391 continue | 392 continue |
| 392 | 393 |
| 393 self._ProcessInterface(interface, super_interface, | 394 self._ProcessInterface(interface, super_interface, |
| 394 source_filter, common_prefix) | 395 source_filter, common_prefix) |
| 396 processed_interfaces.append(interface) |
| 397 |
| 398 self._GenerateBrowserAnalysis(processed_interfaces, output_dir) |
| 399 |
| 395 | 400 |
| 396 # Libraries | 401 # Libraries |
| 397 if lib_dir: | 402 if lib_dir: |
| 398 # New version: Monkey-patching interface library. | 403 # New version: Monkey-patching interface library. |
| 399 self.GenerateLibFile('template_monkey_dom.darttemplate', | 404 self.GenerateLibFile('template_monkey_dom.darttemplate', |
| 400 os.path.join(lib_dir, 'monkey_dom.dart'), | 405 os.path.join(lib_dir, 'monkey_dom.dart'), |
| 401 self._dart_interface_file_paths) | 406 self._dart_interface_file_paths) |
| 402 | 407 |
| 403 # New version: Wrapping implementation combined interface and | 408 # New version: Wrapping implementation combined interface and |
| 404 # implementation library. | 409 # implementation library. |
| (...skipping 571 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 976 props.add(name + '$setter') | 981 props.add(name + '$setter') |
| 977 | 982 |
| 978 # Define members. | 983 # Define members. |
| 979 operations = [op.ext_attrs.get('DartName', op.id) | 984 operations = [op.ext_attrs.get('DartName', op.id) |
| 980 for op in interface.operations] | 985 for op in interface.operations] |
| 981 members = sorted(set(operations)) | 986 members = sorted(set(operations)) |
| 982 for name in members: | 987 for name in members: |
| 983 props.add(name + '$member') | 988 props.add(name + '$member') |
| 984 | 989 |
| 985 | 990 |
| 991 def _GenerateBrowserAnalysis(self, interfaces, output_dir): |
| 992 """Generate a JavaScript file that provides info from the browser. |
| 993 """ |
| 994 js_file_name = os.path.join(output_dir, 'browser_analysis.html') |
| 995 code = self._emitters.FileEmitter(js_file_name) |
| 996 |
| 997 template = """<head> |
| 998 <script> |
| 999 function addText(e, text) { |
| 1000 var node = document.createElement('text'); |
| 1001 node.innerHTML = String(text); |
| 1002 e.appendChild(node); |
| 1003 } |
| 1004 function check() { |
| 1005 var supported = []; |
| 1006 var missing = []; |
| 1007 $!CHECKS |
| 1008 addText(document.getElementById('agent'), navigator.userAgent); |
| 1009 |
| 1010 function fill(tag, elems) { |
| 1011 addText(document.getElementById(tag + '_count'), elems.length); |
| 1012 for (var i = 0; i < elems.length; ++i) { |
| 1013 var e = document.createElement('div'); |
| 1014 e.innerHTML = ' "' + elems[i] + '",' |
| 1015 document.getElementById(tag).appendChild(e); |
| 1016 } |
| 1017 } |
| 1018 fill('supported', supported); |
| 1019 fill('missing', missing); |
| 1020 } |
| 1021 window.onload = check; |
| 1022 </script> |
| 1023 </head> |
| 1024 <div> |
| 1025 { 'userAgent': '<span id='agent'></span>', |
| 1026 </div> |
| 1027 <div> |
| 1028 'supported': [ // (<span id='supported_count'></span>) |
| 1029 <div id='supported' style='font-size: -2;'></div> |
| 1030 ],</div> |
| 1031 <div> |
| 1032 'missing': [ // (<span id='missing_count'></span>) |
| 1033 <div id='missing' style='font-size: -2;'></div> |
| 1034 ]}</div> |
| 1035 |
| 1036 """ |
| 1037 checks = code.Emit(template) |
| 1038 names = sorted(interface.id for interface in interfaces) |
| 1039 for id in names: |
| 1040 checks.Emit( |
| 1041 ' if (typeof $ID == "undefined")\n' |
| 1042 ' missing.push("$ID");\n' |
| 1043 ' else\n' |
| 1044 ' supported.push("$ID");\n', |
| 1045 ID=id); |
| 1046 |
| 1047 |
| 986 class OperationInfo(object): | 1048 class OperationInfo(object): |
| 987 """Holder for various derived information from a set of overloaded operations. | 1049 """Holder for various derived information from a set of overloaded operations. |
| 988 | 1050 |
| 989 Attributes: | 1051 Attributes: |
| 990 overloads: A list of IDL operation overloads with the same name. | 1052 overloads: A list of IDL operation overloads with the same name. |
| 991 name: A string, the simple name of the operation. | 1053 name: A string, the simple name of the operation. |
| 992 type_name: A string, the name of the return type of the operation. | 1054 type_name: A string, the name of the return type of the operation. |
| 993 arg_declarations: A list of strings, Dart argument declarations for the | 1055 arg_declarations: A list of strings, Dart argument declarations for the |
| 994 member that implements the set of overloads. Each string is of the form | 1056 member that implements the set of overloads. Each string is of the form |
| 995 "T arg" or "T arg = null". | 1057 "T arg" or "T arg = null". |
| (...skipping 1029 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2025 Arguments: | 2087 Arguments: |
| 2026 info: An OperationInfo object. | 2088 info: An OperationInfo object. |
| 2027 """ | 2089 """ |
| 2028 # TODO(vsm): Handle overloads. | 2090 # TODO(vsm): Handle overloads. |
| 2029 self._members_emitter.Emit( | 2091 self._members_emitter.Emit( |
| 2030 '\n' | 2092 '\n' |
| 2031 ' $TYPE $NAME($ARGS) native;\n', | 2093 ' $TYPE $NAME($ARGS) native;\n', |
| 2032 TYPE=info.type_name, | 2094 TYPE=info.type_name, |
| 2033 NAME=info.name, | 2095 NAME=info.name, |
| 2034 ARGS=info.arg_implementation_declaration) | 2096 ARGS=info.arg_implementation_declaration) |
| OLD | NEW |