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

Side by Side Diff: lib/dom/scripts/systemfrog.py

Issue 10698108: Stop passing HtmlSystemShared around and move html renaming to IDLTypeInfo. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: . Created 8 years, 5 months 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « lib/dom/scripts/systembase.py ('k') | lib/dom/scripts/systemhtml.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 systems to generate 6 """This module provides shared functionality for the systems to generate
7 frog binding from the IDL database.""" 7 frog binding from the IDL database."""
8 8
9 import os 9 import os
10 from generator import * 10 from generator import *
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 elif native_spec[0] == '=': 104 elif native_spec[0] == '=':
105 # The implementation is a singleton with no prototype. 105 # The implementation is a singleton with no prototype.
106 extends = '' 106 extends = ''
107 else: 107 else:
108 extends = ' extends _DOMTypeJs' 108 extends = ' extends _DOMTypeJs'
109 109
110 # TODO: Include all implemented interfaces, including other Lists. 110 # TODO: Include all implemented interfaces, including other Lists.
111 implements = [interface_name] 111 implements = [interface_name]
112 element_type = MaybeTypedArrayElementType(self._interface) 112 element_type = MaybeTypedArrayElementType(self._interface)
113 if element_type: 113 if element_type:
114 implements.append('List<%s>' % DartType(element_type)) 114 implements.append('List<%s>' % self._DartType(element_type))
115 115
116 self._members_emitter = self._dart_code.Emit( 116 self._members_emitter = self._dart_code.Emit(
117 self._template, 117 self._template,
118 #class $CLASSNAME$EXTENDS$IMPLEMENTS$NATIVESPEC { 118 #class $CLASSNAME$EXTENDS$IMPLEMENTS$NATIVESPEC {
119 #$!MEMBERS 119 #$!MEMBERS
120 #} 120 #}
121 CLASSNAME=self._class_name, 121 CLASSNAME=self._class_name,
122 EXTENDS=extends, 122 EXTENDS=extends,
123 IMPLEMENTS=' implements ' + ', '.join(implements), 123 IMPLEMENTS=' implements ' + ', '.join(implements),
124 NATIVESPEC=' native "' + native_spec + '"') 124 NATIVESPEC=' native "' + native_spec + '"')
(...skipping 16 matching lines...) Expand all
141 template = self._system._templates.TryLoad(template_file) 141 template = self._system._templates.TryLoad(template_file)
142 if not template: 142 if not template:
143 template = self._system._templates.Load('factoryprovider.darttemplate') 143 template = self._system._templates.Load('factoryprovider.darttemplate')
144 144
145 factory_provider = '_' + interface_name + 'FactoryProvider' 145 factory_provider = '_' + interface_name + 'FactoryProvider'
146 emitter = self._system._ImplFileEmitter(factory_provider) 146 emitter = self._system._ImplFileEmitter(factory_provider)
147 emitter.Emit( 147 emitter.Emit(
148 template, 148 template,
149 FACTORYPROVIDER=factory_provider, 149 FACTORYPROVIDER=factory_provider,
150 CONSTRUCTOR=interface_name, 150 CONSTRUCTOR=interface_name,
151 PARAMETERS=constructor_info.ParametersImplementationDeclaration(), 151 PARAMETERS=constructor_info.ParametersImplementationDeclaration(self._Da rtType),
152 NAMEDCONSTRUCTOR=constructor_info.name or interface_name, 152 NAMEDCONSTRUCTOR=constructor_info.name or interface_name,
153 ARGUMENTS=constructor_info.ParametersAsArgumentList()) 153 ARGUMENTS=constructor_info.ParametersAsArgumentList())
154 154
155 def _ShouldNarrowToImplementationType(self, type_name): 155 def _ShouldNarrowToImplementationType(self, type_name):
156 # TODO(sra): Move into the 'system' and cache the result. 156 # TODO(sra): Move into the 'system' and cache the result.
157 if type_name == 'EventListener': 157 do_not_narrow = ['DOMStringList', 'DOMStringMap', 'EventListener',
158 # Callbacks are typedef functions so don't have a class. 158 'IDBAny', 'IDBKey', 'MediaQueryListListener']
159 if type_name in do_not_narrow:
159 return False 160 return False
160 if self._system._database.HasInterface(type_name): 161 if self._system._database.HasInterface(type_name):
161 interface = self._system._database.GetInterface(type_name) 162 interface = self._system._database.GetInterface(type_name)
162 if RecognizeCallback(interface): 163 if RecognizeCallback(interface):
163 # Callbacks are typedef functions so don't have a class. 164 # Callbacks are typedef functions so don't have a class.
164 return False 165 return False
165 elif type_name == 'MediaQueryListListener': 166 return True
166 # Somewhat like a callback. See Issue 3338.
167 return False
168 else:
169 return True
170 return False 167 return False
171 168
172 def _NarrowToImplementationType(self, type_name): 169 def _NarrowToImplementationType(self, type_name):
173 if self._ShouldNarrowToImplementationType(type_name): 170 if self._ShouldNarrowToImplementationType(type_name):
174 return self._ImplClassName(type_name) 171 return self._ImplClassName(self._DartType(type_name))
175 return type_name 172 return self._DartType(type_name)
176 173
177 def _NarrowInputType(self, type_name): 174 def _NarrowInputType(self, type_name):
178 return self._NarrowToImplementationType(DartType(type_name)) 175 return self._NarrowToImplementationType(type_name)
179 176
180 def _NarrowOutputType(self, type_name): 177 def _NarrowOutputType(self, type_name):
181 return self._NarrowToImplementationType(DartType(type_name)) 178 return self._NarrowToImplementationType(type_name)
182 179
183 def AddConstant(self, constant): 180 def AddConstant(self, constant):
184 # Since we are currently generating native classes without interfaces, 181 # Since we are currently generating native classes without interfaces,
185 # generate the constants as part of the class. This will need to go away 182 # generate the constants as part of the class. This will need to go away
186 # if we revert back to generating interfaces. 183 # if we revert back to generating interfaces.
187 self._members_emitter.Emit('\n static final $TYPE $NAME = $VALUE;\n', 184 self._members_emitter.Emit('\n static final $TYPE $NAME = $VALUE;\n',
188 NAME=constant.id, 185 NAME=constant.id,
189 TYPE=DartType(constant.type.id), 186 TYPE=self._DartType(constant.type.id),
190 VALUE=constant.value) 187 VALUE=constant.value)
191 188
192 pass 189 pass
193 190
194 def OverrideMember(self, member): 191 def OverrideMember(self, member):
195 return self._interface.id + '.' + member in _dom_frog_omitted_members 192 return self._interface.id + '.' + member in _dom_frog_omitted_members
196 193
197 def AddAttribute(self, attribute): 194 def AddAttribute(self, attribute):
198 getter = attribute 195 getter = attribute
199 setter = attribute if not IsReadOnly(attribute) else None 196 setter = attribute if not IsReadOnly(attribute) else None
200 if getter and self.OverrideMember('get:' + getter.id): 197 if getter and self.OverrideMember('get:' + getter.id):
201 getter = None 198 getter = None
202 if setter and self.OverrideMember('set:' + setter.id): 199 if setter and self.OverrideMember('set:' + setter.id):
203 setter = None 200 setter = None
204 if not getter and not setter: 201 if not getter and not setter:
205 return 202 return
206 203
207 output_type = getter and self._NarrowOutputType(getter.type.id) 204 output_type = getter and self._NarrowOutputType(getter.type.id)
208 input_type = setter and self._NarrowInputType(setter.type.id) 205 input_type = setter and self._NarrowInputType(setter.type.id)
209 206
210 # If the (getter, setter) pair is shadowing, we can't generate a shadowing 207 # If the (getter, setter) pair is shadowing, we can't generate a shadowing
211 # field (Issue 1633). 208 # field (Issue 1633).
212 (super_getter, super_getter_interface) = self._FindShadowedAttribute(getter) 209 (super_getter, super_getter_interface) = self._FindShadowedAttribute(getter)
213 (super_setter, super_setter_interface) = self._FindShadowedAttribute(setter) 210 (super_setter, super_setter_interface) = self._FindShadowedAttribute(setter)
214 if super_getter or super_setter: 211 if super_getter or super_setter:
215 if getter and not setter and super_getter and not super_setter: 212 if getter and not setter and super_getter and not super_setter:
216 if DartType(getter.type.id) == DartType(super_getter.type.id): 213 if self._DartType(getter.type.id) == self._DartType(super_getter.type.id ):
217 # Compatible getter, use the superclass property. This works because 214 # Compatible getter, use the superclass property. This works because
218 # JavaScript will do its own dynamic dispatch. 215 # JavaScript will do its own dynamic dispatch.
219 self._members_emitter.Emit( 216 self._members_emitter.Emit(
220 '\n' 217 '\n'
221 ' // Use implementation from $SUPER.\n' 218 ' // Use implementation from $SUPER.\n'
222 ' // final $TYPE $NAME;\n', 219 ' // final $TYPE $NAME;\n',
223 SUPER=super_getter_interface, 220 SUPER=super_getter_interface,
224 NAME=DartDomNameOfAttribute(getter), 221 NAME=DartDomNameOfAttribute(getter),
225 TYPE=output_type) 222 TYPE=output_type)
226 return 223 return
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 '\n' 357 '\n'
361 ' void operator[]=(int index, $TYPE value) {\n' 358 ' void operator[]=(int index, $TYPE value) {\n'
362 ' throw new UnsupportedOperationException("Cannot assign element of immutable List.");\n' 359 ' throw new UnsupportedOperationException("Cannot assign element of immutable List.");\n'
363 ' }\n', 360 ' }\n',
364 TYPE=self._NarrowInputType(element_type)) 361 TYPE=self._NarrowInputType(element_type))
365 362
366 # TODO(sra): Use separate mixins for mutable implementations of List<T>. 363 # TODO(sra): Use separate mixins for mutable implementations of List<T>.
367 # TODO(sra): Use separate mixins for typed array implementations of List<T>. 364 # TODO(sra): Use separate mixins for typed array implementations of List<T>.
368 template_file = 'immutable_list_mixin.darttemplate' 365 template_file = 'immutable_list_mixin.darttemplate'
369 template = self._system._templates.Load(template_file) 366 template = self._system._templates.Load(template_file)
370 self._members_emitter.Emit(template, E=DartType(element_type)) 367 self._members_emitter.Emit(template, E=self._DartType(element_type))
371 368
372 def AddOperation(self, info): 369 def AddOperation(self, info):
373 """ 370 """
374 Arguments: 371 Arguments:
375 info: An OperationInfo object. 372 info: An OperationInfo object.
376 """ 373 """
377 # TODO(vsm): Handle overloads. 374 # TODO(vsm): Handle overloads.
378 params = info.ParametersImplementationDeclaration( 375 params = info.ParametersImplementationDeclaration(
379 lambda type_name: self._NarrowInputType(type_name)) 376 lambda type_name: self._NarrowInputType(type_name))
380 377
381 native_string = '' 378 native_string = ''
382 if info.declared_name != info.name: 379 if info.declared_name != info.name:
383 native_string = " '%s'" % info.declared_name 380 native_string = " '%s'" % info.declared_name
384 381
385 native_body = dom_frog_native_bodies.get( 382 native_body = dom_frog_native_bodies.get(
386 self._interface.id + '.' + info.name, '') 383 self._interface.id + '.' + info.name, '')
387 if native_body: 384 if native_body:
388 native_string = " '''" + native_body + "'''" 385 native_string = " '''" + native_body + "'''"
389 386
390 self._members_emitter.Emit( 387 self._members_emitter.Emit(
391 '\n' 388 '\n'
392 ' $TYPE $NAME($PARAMS) native$NATIVESTRING;\n', 389 ' $TYPE $NAME($PARAMS) native$NATIVESTRING;\n',
393 TYPE=self._NarrowOutputType(info.type_name), 390 TYPE=self._NarrowOutputType(info.type_name),
394 NAME=info.name, 391 NAME=info.name,
395 PARAMS=params, 392 PARAMS=params,
396 NATIVESTRING=native_string) 393 NATIVESTRING=native_string)
OLDNEW
« no previous file with comments | « lib/dom/scripts/systembase.py ('k') | lib/dom/scripts/systemhtml.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698