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 provides shared functionality for the system to generate | 6 """This module provides shared functionality for the system to generate |
7 Dart:html APIs from the IDL database.""" | 7 Dart:html APIs from the IDL database.""" |
8 | 8 |
9 import emitter | 9 import emitter |
10 import logging | 10 import logging |
(...skipping 770 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
781 indexed_getter = 'this.getItem(index)' | 781 indexed_getter = 'this.getItem(index)' |
782 elif any(op.id == 'item' for op in self._interface.operations): | 782 elif any(op.id == 'item' for op in self._interface.operations): |
783 indexed_getter = 'this.item(index)' | 783 indexed_getter = 'this.item(index)' |
784 | 784 |
785 if indexed_getter: | 785 if indexed_getter: |
786 self._members_emitter.Emit( | 786 self._members_emitter.Emit( |
787 '\n' | 787 '\n' |
788 ' $TYPE operator[](int index) {\n' | 788 ' $TYPE operator[](int index) {\n' |
789 ' if (JS("bool", "# >>> 0 !== # || # >= #", index,\n' | 789 ' if (JS("bool", "# >>> 0 !== # || # >= #", index,\n' |
790 ' index, index, length))\n' | 790 ' index, index, length))\n' |
791 ' throw new RangeError.range(index, 0, length);\n' | 791 ' throw new RangeError.index(index, this);\n' |
792 ' return $INDEXED_GETTER;\n' | 792 ' return $INDEXED_GETTER;\n' |
793 ' }', | 793 ' }', |
794 INDEXED_GETTER=indexed_getter, | 794 INDEXED_GETTER=indexed_getter, |
795 TYPE=self.SecureOutputType(element_type, False, True)) | 795 TYPE=self.SecureOutputType(element_type, False, True)) |
796 | 796 |
797 if 'CustomIndexedSetter' in self._interface.ext_attrs: | 797 if 'CustomIndexedSetter' in self._interface.ext_attrs: |
798 self._members_emitter.Emit( | 798 self._members_emitter.Emit( |
799 '\n' | 799 '\n' |
800 ' void operator[]=(int index, $TYPE value) {' | 800 ' void operator[]=(int index, $TYPE value) {' |
801 ' JS("void", "#[#] = #", this, index, value); }', | 801 ' JS("void", "#[#] = #", this, index, value); }', |
(...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1234 | 1234 |
1235 library_emitter = emitter.FileEmitter(self._dart_path) | 1235 library_emitter = emitter.FileEmitter(self._dart_path) |
1236 library_file_dir = os.path.dirname(self._dart_path) | 1236 library_file_dir = os.path.dirname(self._dart_path) |
1237 auxiliary_dir = os.path.relpath(auxiliary_dir, library_file_dir) | 1237 auxiliary_dir = os.path.relpath(auxiliary_dir, library_file_dir) |
1238 emitters = library_emitter.Emit( | 1238 emitters = library_emitter.Emit( |
1239 self._template, AUXILIARY_DIR=massage_path(auxiliary_dir)) | 1239 self._template, AUXILIARY_DIR=massage_path(auxiliary_dir)) |
1240 if isinstance(emitters, tuple): | 1240 if isinstance(emitters, tuple): |
1241 imports_emitter, map_emitter = emitters | 1241 imports_emitter, map_emitter = emitters |
1242 else: | 1242 else: |
1243 imports_emitter, map_emitter = emitters, None | 1243 imports_emitter, map_emitter = emitters, None |
1244 | 1244 |
1245 | 1245 |
1246 for path in sorted(self._paths): | 1246 for path in sorted(self._paths): |
1247 relpath = os.path.relpath(path, library_file_dir) | 1247 relpath = os.path.relpath(path, library_file_dir) |
1248 imports_emitter.Emit( | 1248 imports_emitter.Emit( |
1249 "part '$PATH';\n", PATH=massage_path(relpath)) | 1249 "part '$PATH';\n", PATH=massage_path(relpath)) |
1250 | 1250 |
1251 if map_emitter: | 1251 if map_emitter: |
1252 items = self._typeMap.items() | 1252 items = self._typeMap.items() |
1253 items.sort() | 1253 items.sort() |
1254 for (idl_name, dart_name) in items: | 1254 for (idl_name, dart_name) in items: |
1255 map_emitter.Emit( | 1255 map_emitter.Emit( |
1256 " '$IDL_NAME': () => $DART_NAME,\n", | 1256 " '$IDL_NAME': () => $DART_NAME,\n", |
1257 IDL_NAME=idl_name, | 1257 IDL_NAME=idl_name, |
1258 DART_NAME=dart_name) | 1258 DART_NAME=dart_name) |
1259 | 1259 |
1260 | 1260 |
1261 # ------------------------------------------------------------------------------ | 1261 # ------------------------------------------------------------------------------ |
1262 | 1262 |
1263 class DartLibraries(): | 1263 class DartLibraries(): |
1264 def __init__(self, libraries, template_loader, library_type, output_dir): | 1264 def __init__(self, libraries, template_loader, library_type, output_dir): |
1265 self._libraries = {} | 1265 self._libraries = {} |
1266 for library_name in libraries: | 1266 for library_name in libraries: |
1267 self._libraries[library_name] = DartLibrary( | 1267 self._libraries[library_name] = DartLibrary( |
1268 library_name, template_loader, library_type, output_dir) | 1268 library_name, template_loader, library_type, output_dir) |
1269 | 1269 |
1270 def AddFile(self, basename, library_name, path): | 1270 def AddFile(self, basename, library_name, path): |
1271 self._libraries[library_name].AddFile(path) | 1271 self._libraries[library_name].AddFile(path) |
1272 | 1272 |
1273 def AddTypeEntry(self, library_name, idl_name, dart_name): | 1273 def AddTypeEntry(self, library_name, idl_name, dart_name): |
1274 self._libraries[library_name].AddTypeEntry(idl_name, dart_name) | 1274 self._libraries[library_name].AddTypeEntry(idl_name, dart_name) |
1275 | 1275 |
1276 def Emit(self, emitter, auxiliary_dir): | 1276 def Emit(self, emitter, auxiliary_dir): |
1277 for lib in self._libraries.values(): | 1277 for lib in self._libraries.values(): |
1278 lib.Emit(emitter, auxiliary_dir) | 1278 lib.Emit(emitter, auxiliary_dir) |
OLD | NEW |