Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(703)

Unified Diff: sdk/lib/html/scripts/systemhtml.py

Issue 11365019: Merging dart:html interfaces and implementations (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Merging with latest. Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: sdk/lib/html/scripts/systemhtml.py
diff --git a/sdk/lib/html/scripts/systemhtml.py b/sdk/lib/html/scripts/systemhtml.py
index 9d867364901c1decad7596811320cbe7b49658ef..4def415849ecd14e528cd1f1980cfb9861d31751 100644
--- a/sdk/lib/html/scripts/systemhtml.py
+++ b/sdk/lib/html/scripts/systemhtml.py
@@ -9,6 +9,7 @@ Dart:html APIs from the IDL database."""
import emitter
import os
from generator import *
+from htmldartgenerator import *
_js_custom_members = set([
'AudioBufferSourceNode.start',
@@ -182,7 +183,7 @@ def EmitHtmlElementFactoryConstructors(emitter, infos, typename, class_name,
inits = emitter.Emit(
'\n'
' static $RETURN_TYPE $CONSTRUCTOR($PARAMS) {\n'
- ' $CLASS _e = _document.$dom_createElement("$TAG");\n'
+ ' $CLASS _e = document.$dom_createElement("$TAG");\n'
'$!INITS'
' return _e;\n'
' }\n',
@@ -233,11 +234,8 @@ class HtmlDartInterfaceGenerator(object):
def GenerateInterface(self):
interface_name = self._interface_type_info.interface_name()
- if (self._interface_type_info.has_generated_interface() and
- not self._interface_type_info.merged_into()):
- interface_emitter = self._library_emitter.FileEmitter(interface_name)
- else:
- interface_emitter = emitter.Emitter()
+ # TODO: this is just tossing the interface, need to skip it completely.
+ interface_emitter = emitter.Emitter()
template_file = 'interface_%s.darttemplate' % interface_name
interface_template = (self._template_loader.TryLoad(template_file) or
@@ -299,30 +297,46 @@ class HtmlDartInterfaceGenerator(object):
self._members_emitter,
self._top_level_emitter) = interface_emitter.Emit(
interface_template + '$!TOP_LEVEL',
- ID=interface_name,
+ ID='_I%s' % interface_name,
EXTENDS=implements_str)
- self._type_comment_emitter.Emit("/// @domName $DOMNAME",
- DOMNAME=self._interface.doc_js_name)
-
implementation_emitter = self._ImplementationEmitter()
- base_class = self._backend.RootClassName()
+ base_type_info = None
+
Anton Muhin 2012/11/06 12:28:43 nit: no need in blank line
blois 2012/11/06 22:11:44 Done.
if self._interface.parents:
supertype = self._interface.parents[0].type.id
if not IsDartCollectionType(supertype) and not IsPureInterface(supertype):
- type_info = self._type_registry.TypeInfo(supertype)
- if type_info.merged_into() and self._backend.ImplementsMergedMembers():
- type_info = self._type_registry.TypeInfo(type_info.merged_into())
- base_class = type_info.implementation_name()
+ base_type_info = self._type_registry.TypeInfo(supertype)
+ if base_type_info.merged_into() \
+ and self._backend.ImplementsMergedMembers():
+ base_type_info = self._type_registry.TypeInfo(
+ base_type_info.merged_into())
+
+ if base_type_info:
+ base_class = base_type_info.implementation_name()
+ else:
+ base_class = self._backend.RootClassName()
+
+ implements = self._backend.AdditionalImplementedInterfaces()
+ for parent in self._interface.parents:
+ parent_type_info = self._type_registry.TypeInfo(parent.type.id)
+ if parent_type_info != base_type_info:
+ implements.append(parent_type_info.interface_name())
+
+ if interface_name in _secure_base_types:
+ implements.append(_secure_base_types[interface_name])
+
+ implements_str = ''
+ if implements:
+ implements_str = ' implements ' + ', '.join(set(implements))
- implemented_interfaces = [interface_name] +\
- self._backend.AdditionalImplementedInterfaces()
self._implementation_members_emitter = implementation_emitter.Emit(
self._backend.ImplementationTemplate(),
CLASSNAME=self._interface_type_info.implementation_name(),
EXTENDS=' extends %s' % base_class if base_class else '',
- IMPLEMENTS=' implements ' + ', '.join(implemented_interfaces),
+ IMPLEMENTS=implements_str,
+ DOMNAME=self._interface.doc_js_name,
NATIVESPEC=self._backend.NativeSpec())
self._backend.StartInterface(self._implementation_members_emitter)
@@ -330,13 +344,17 @@ class HtmlDartInterfaceGenerator(object):
constructor_info.GenerateFactoryInvocation(
self._DartType, self._members_emitter, factory_provider)
- element_type = None
+ self._backend.AddConstructors(constructors, factory_provider,
+ self._interface_type_info.implementation_name(),
+ base_class)
+
+ 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():
- element_type = type_info.list_item_type()
+ typed_array_type = type_info.list_item_type()
break
- if element_type:
+ if typed_array_type:
Anton Muhin 2012/11/06 12:28:43 this code has been moved into the helper you intro
blois 2012/11/06 22:11:44 Yes, this is the interface generation code. I just
Anton Muhin 2012/11/07 08:50:55 Sorry, I meant you have pretty much the same code
self._members_emitter.Emit(
'\n'
' factory $CTOR(int length) =>\n'
@@ -348,7 +366,7 @@ class HtmlDartInterfaceGenerator(object):
' 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(element_type),
+ TYPE=self._DartType(typed_array_type),
FACTORY=factory_provider)
events_interface = self._event_generator.ProcessInterface(
@@ -356,7 +374,7 @@ class HtmlDartInterfaceGenerator(object):
self._backend.CustomJSMembers(),
interface_emitter, implementation_emitter)
if events_interface:
- self._EmitEventGetter(events_interface, '_%sImpl' % events_interface)
+ self._EmitEventGetter(events_interface, events_interface)
old_backend = self._backend
if not self._backend.ImplementsMergedMembers():
@@ -525,15 +543,15 @@ class HtmlDartInterfaceGenerator(object):
TYPE=type,
VALUE=constant.value)
+ self._backend.AddConstant(constant)
+
def _ImplementationEmitter(self):
- if IsPureInterface(self._interface.id):
- return emitter.Emitter()
basename = self._interface_type_info.implementation_name()
if (self._interface_type_info.merged_into() and
self._backend.ImplementsMergedMembers()):
# Merged members are implemented in target interface implementation.
return emitter.Emitter()
- return self._library_emitter.FileEmitter(basename.lstrip('_'))
+ return self._library_emitter.FileEmitter(basename)
def _EmitEventGetter(self, events_interface, events_class):
self._members_emitter.Emit(
@@ -545,6 +563,10 @@ class HtmlDartInterfaceGenerator(object):
TYPE=events_interface)
self._implementation_members_emitter.Emit(
+ '\n /**'
+ '\n * @domName EventTarget.addEventListener, '
+ 'EventTarget.removeEventListener, EventTarget.dispatchEvent'
+ '\n */'
'\n $TYPE get on =>\n new $TYPE(this);\n',
TYPE=events_class)
@@ -595,16 +617,18 @@ class HtmlGeneratorDummyBackend(object):
# ------------------------------------------------------------------------------
-class Dart2JSBackend(object):
+class Dart2JSBackend(HtmlDartGenerator):
"""Generates a dart2js class for the dart:html library from a DOM IDL
interface.
"""
def __init__(self, interface, options):
- self._interface = interface
+ super(Dart2JSBackend, self).__init__(interface, options)
+
self._database = options.database
self._template_loader = options.templates
self._type_registry = options.type_registry
+ self._renamer = options.renamer
self._interface_type_info = self._type_registry.TypeInfo(self._interface.id)
self._current_secondary_parent = None
@@ -618,11 +642,7 @@ class Dart2JSBackend(object):
return None
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))
+ implements = super(Dart2JSBackend, self).AdditionalImplementedInterfaces()
if self._interface_type_info.list_item_type():
implements.append('JavaScriptIndexingBehavior')
return implements
@@ -632,6 +652,9 @@ class Dart2JSBackend(object):
return ' native "%s"' % native_spec
def ImplementationTemplate(self):
+ if IsPureInterface(self._interface.id):
+ return self._template_loader.Load('pure_interface.darttemplate')
+
template_file = ('impl_%s.darttemplate' %
self._interface_type_info.interface_name())
return (self._template_loader.TryLoad(template_file) or
@@ -724,6 +747,10 @@ class Dart2JSBackend(object):
if self._HasCustomImplementation(attribute.id):
return
+ if IsPureInterface(self._interface.id):
+ self._AddInterfaceAttribute(attribute)
+ return
+
if attribute.id != html_name:
self._AddAttributeUsingProperties(attribute, html_name, read_only)
return
@@ -762,6 +789,7 @@ class Dart2JSBackend(object):
output_type = self._NarrowOutputType(attribute.type.id)
input_type = self._NarrowInputType(attribute.type.id)
+ self.EmitAttributeDocumentation(attribute)
if not read_only:
self._members_emitter.Emit(
'\n $TYPE $NAME;'
@@ -780,7 +808,16 @@ class Dart2JSBackend(object):
if not read_only:
self._AddRenamingSetter(attribute, html_name)
+ def _AddInterfaceAttribute(self, attribute):
+ self._members_emitter.Emit(
+ '\n $TYPE $NAME;'
+ '\n',
+ NAME=DartDomNameOfAttribute(attribute),
+ TYPE=self._NarrowOutputType(attribute.type.id))
+
def _AddRenamingGetter(self, attr, html_name):
+ self.EmitAttributeDocumentation(attr)
+
conversion = self._OutputConversion(attr.type.id, attr.id)
if conversion:
return self._AddConvertingGetter(attr, html_name, conversion)
@@ -794,6 +831,8 @@ class Dart2JSBackend(object):
TYPE=return_type)
def _AddRenamingSetter(self, attr, html_name):
+ self.EmitAttributeDocumentation(attr)
+
conversion = self._InputConversion(attr.type.id, attr.id)
if conversion:
return self._AddConvertingSetter(attr, html_name, conversion)
@@ -847,8 +886,12 @@ class Dart2JSBackend(object):
if self._HasCustomImplementation(info.name):
return
- # Any conversions needed?
- if any(self._OperationRequiresConversions(op) for op in info.overloads):
+ self.EmitOperationDocumentation(info)
+
+ if IsPureInterface(self._interface.id):
+ self._AddInterfaceOperation(info, html_name)
+ elif any(self._OperationRequiresConversions(op) for op in info.overloads):
+ # Any conversions needed?
self._AddOperationWithConversions(info, html_name)
else:
self._AddDirectNativeOperation(info, html_name)
@@ -1017,6 +1060,20 @@ class Dart2JSBackend(object):
argument_count = position
GenerateCall(operation, argument_count, [])
+ def _AddInterfaceOperation(self, info, html_name):
+ self._members_emitter.Emit(
+ '\n'
+ ' $TYPE $NAME($PARAMS);\n',
+ TYPE=self._NarrowOutputType(info.type_name),
+ NAME=info.name,
+ PARAMS=info.ParametersDeclaration(self._NarrowInputType))
+
+ def AddConstant(self, constant):
+ type = TypeOrNothing(self._DartType(constant.type.id), constant.type.id)
+ self._members_emitter.Emit('\n static const $TYPE$NAME = $VALUE;\n',
+ NAME=constant.id,
+ TYPE=type,
+ VALUE=constant.value)
def _IsOptional(self, operation, argument):
return IsOptional(argument)
@@ -1054,8 +1111,7 @@ class Dart2JSBackend(object):
return self._NarrowToImplementationType(type_name)
def _NarrowOutputType(self, type_name):
- secure_name = SecureOutputType(self, type_name, True)
- return self._NarrowToImplementationType(secure_name)
+ return SecureOutputType(self, type_name)
def _FindShadowedAttribute(self, attr):
"""Returns (attribute, superinterface) or (None, None)."""

Powered by Google App Engine
This is Rietveld 408576698