Chromium Code Reviews| Index: lib/html/scripts/htmldartgenerator.py |
| diff --git a/lib/html/scripts/htmldartgenerator.py b/lib/html/scripts/htmldartgenerator.py |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..b9244619c40821aaa2926455dbd8592e1cd5ef44 |
| --- /dev/null |
| +++ b/lib/html/scripts/htmldartgenerator.py |
| @@ -0,0 +1,61 @@ |
| +#!/usr/bin/python |
| +# Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| +# for details. All rights reserved. Use of this source code is governed by a |
| +# BSD-style license that can be found in the LICENSE file. |
| + |
| +"""This module provides shared functionality for the system to generate |
| +Dart:html APIs from the IDL database.""" |
| + |
| +from generator import * |
|
Anton Muhin
2012/11/02 12:55:47
maybe use names instead of globbing?
blois
2012/11/02 19:25:28
Done.
|
| + |
| +class HtmlDartGenerator(object): |
| + def __init__(self, interface, options): |
| + self._interface = interface |
| + |
| + def EmitAttributeDocumentation(self, attribute): |
| + dom_name = DartDomNameOfAttribute(attribute) |
| + self._members_emitter.Emit('\n /** @domName $DOMINTERFACE.$DOMNAME */', |
| + DOMINTERFACE=attribute.doc_js_interface_name, |
| + DOMNAME=dom_name) |
| + |
| + def AdditionalImplementedInterfaces(self): |
| + # TODO: Include all implemented interfaces, including other Lists. |
| + implements = [] |
| + if self._interface_type_info.is_typed_array(): |
| + element_type = self._interface_type_info.list_item_type() |
| + implements.append('List<%s>' % self._DartType(element_type)) |
| + if self._interface_type_info.list_item_type(): |
| + item_type_info = self._type_registry.TypeInfo( |
| + self._interface_type_info.list_item_type()) |
| + implements.append('List<%s>' % item_type_info.dart_type()) |
| + return implements |
| + |
| + def AddConstructors(self, constructors, factory_provider, class_name, |
| + base_class): |
| + for constructor_info in constructors: |
| + self._AddConstructor(constructor_info, factory_provider) |
| + |
| + typed_array_type = None |
| + for interface in self._database.Hierarchy(self._interface): |
| + type_info = self._type_registry.TypeInfo(interface.id) |
| + if type_info.is_typed_array(): |
| + typed_array_type = type_info.list_item_type() |
| + break |
| + if typed_array_type: |
| + self._members_emitter.Emit( |
| + '\n' |
| + ' factory $CTOR(int length) =>\n' |
| + ' $FACTORY.create$(CTOR)(length);\n' |
| + '\n' |
| + ' factory $CTOR.fromList(List<$TYPE> list) =>\n' |
| + ' $FACTORY.create$(CTOR)_fromList(list);\n' |
| + '\n' |
| + ' factory $CTOR.fromBuffer(ArrayBuffer buffer, [int byteOffset, int length]) => \n' |
| + ' $FACTORY.create$(CTOR)_fromBuffer(buffer, byteOffset, length);\n', |
| + CTOR=self._interface.id, |
| + TYPE=self._DartType(typed_array_type), |
| + FACTORY=factory_provider) |
| + |
| + def _AddConstructor(self, constructor_info, factory_provider): |
| + constructor_info.GenerateFactoryInvocation( |
| + self._DartType, self._members_emitter, factory_provider) |