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

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

Issue 9432024: Do not rename idl types to dart types at top level - this info is needed for native bindings genera… (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Update html frog system. Created 8 years, 9 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 | « client/dom/scripts/generator.py ('k') | client/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 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 elif native_spec[0] == '=': 97 elif native_spec[0] == '=':
98 # The implementation is a singleton with no prototype. 98 # The implementation is a singleton with no prototype.
99 extends = '' 99 extends = ''
100 else: 100 else:
101 extends = ' extends _DOMTypeJs' 101 extends = ' extends _DOMTypeJs'
102 102
103 # TODO: Include all implemented interfaces, including other Lists. 103 # TODO: Include all implemented interfaces, including other Lists.
104 implements = [interface_name] 104 implements = [interface_name]
105 element_type = MaybeTypedArrayElementType(self._interface) 105 element_type = MaybeTypedArrayElementType(self._interface)
106 if element_type: 106 if element_type:
107 implements.append('List<' + element_type + '>') 107 implements.append('List<%s>' % DartType(element_type))
108 108
109 self._members_emitter = self._dart_code.Emit( 109 self._members_emitter = self._dart_code.Emit(
110 self._template, 110 self._template,
111 #class $CLASSNAME$EXTENDS$IMPLEMENTS$NATIVESPEC { 111 #class $CLASSNAME$EXTENDS$IMPLEMENTS$NATIVESPEC {
112 #$!MEMBERS 112 #$!MEMBERS
113 #} 113 #}
114 CLASSNAME=self._class_name, 114 CLASSNAME=self._class_name,
115 EXTENDS=extends, 115 EXTENDS=extends,
116 IMPLEMENTS=' implements ' + ', '.join(implements), 116 IMPLEMENTS=' implements ' + ', '.join(implements),
117 NATIVESPEC=' native "' + native_spec + '"') 117 NATIVESPEC=' native "' + native_spec + '"')
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 if self._system._database.HasInterface(type_name): 157 if self._system._database.HasInterface(type_name):
158 interface = self._system._database.GetInterface(type_name) 158 interface = self._system._database.GetInterface(type_name)
159 if RecognizeCallback(interface): 159 if RecognizeCallback(interface):
160 # Callbacks are typedef functions so don't have a class. 160 # Callbacks are typedef functions so don't have a class.
161 return type_name 161 return type_name
162 else: 162 else:
163 return self._ImplClassName(type_name) 163 return self._ImplClassName(type_name)
164 return type_name 164 return type_name
165 165
166 def _NarrowInputType(self, type_name): 166 def _NarrowInputType(self, type_name):
167 return self._NarrowToImplementationType(type_name) 167 return self._NarrowToImplementationType(DartType(type_name))
168 168
169 def _NarrowOutputType(self, type_name): 169 def _NarrowOutputType(self, type_name):
170 return self._NarrowToImplementationType(type_name) 170 return self._NarrowToImplementationType(DartType(type_name))
171 171
172 def AddConstant(self, constant): 172 def AddConstant(self, constant):
173 # Since we are currently generating native classes without interfaces, 173 # Since we are currently generating native classes without interfaces,
174 # generate the constants as part of the class. This will need to go away 174 # generate the constants as part of the class. This will need to go away
175 # if we revert back to generating interfaces. 175 # if we revert back to generating interfaces.
176 self._members_emitter.Emit('\n static final $TYPE $NAME = $VALUE;\n', 176 self._members_emitter.Emit('\n static final $TYPE $NAME = $VALUE;\n',
177 NAME=constant.id, 177 NAME=constant.id,
178 TYPE=constant.type.id, 178 TYPE=DartType(constant.type.id),
179 VALUE=constant.value) 179 VALUE=constant.value)
180 180
181 pass 181 pass
182 182
183 def AddAttribute(self, getter, setter): 183 def AddAttribute(self, getter, setter):
184 output_type = getter and self._NarrowOutputType(getter.type.id) 184 output_type = getter and self._NarrowOutputType(getter.type.id)
185 input_type = setter and self._NarrowInputType(setter.type.id) 185 input_type = setter and self._NarrowInputType(setter.type.id)
186 186
187 # If the (getter, setter) pair is shadowing, we can't generate a shadowing 187 # If the (getter, setter) pair is shadowing, we can't generate a shadowing
188 # field (Issue 1633). 188 # field (Issue 1633).
189 (super_getter, super_getter_interface) = self._FindShadowedAttribute(getter) 189 (super_getter, super_getter_interface) = self._FindShadowedAttribute(getter)
190 (super_setter, super_setter_interface) = self._FindShadowedAttribute(setter) 190 (super_setter, super_setter_interface) = self._FindShadowedAttribute(setter)
191 if super_getter or super_setter: 191 if super_getter or super_setter:
192 if getter and not setter and super_getter and not super_setter: 192 if getter and not setter and super_getter and not super_setter:
193 if getter.type.id == super_getter.type.id: 193 if DartType(getter.type.id) == DartType(super_getter.type.id):
194 # Compatible getter, use the superclass property. This works because 194 # Compatible getter, use the superclass property. This works because
195 # JavaScript will do its own dynamic dispatch. 195 # JavaScript will do its own dynamic dispatch.
196 self._members_emitter.Emit( 196 self._members_emitter.Emit(
197 '\n' 197 '\n'
198 ' // Use implementation from $SUPER.\n' 198 ' // Use implementation from $SUPER.\n'
199 ' // final $TYPE $NAME;\n', 199 ' // final $TYPE $NAME;\n',
200 SUPER=super_getter_interface.id, 200 SUPER=super_getter_interface.id,
201 NAME=getter.id, TYPE=output_type) 201 NAME=getter.id, TYPE=output_type)
202 return 202 return
203 203
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 '\n' 304 '\n'
305 ' void operator[]=(int index, $TYPE value) {\n' 305 ' void operator[]=(int index, $TYPE value) {\n'
306 ' throw new UnsupportedOperationException("Cannot assign element of immutable List.");\n' 306 ' throw new UnsupportedOperationException("Cannot assign element of immutable List.");\n'
307 ' }\n', 307 ' }\n',
308 TYPE=self._NarrowInputType(element_type)) 308 TYPE=self._NarrowInputType(element_type))
309 309
310 # TODO(sra): Use separate mixins for mutable implementations of List<T>. 310 # TODO(sra): Use separate mixins for mutable implementations of List<T>.
311 # TODO(sra): Use separate mixins for typed array implementations of List<T>. 311 # TODO(sra): Use separate mixins for typed array implementations of List<T>.
312 template_file = 'immutable_list_mixin.darttemplate' 312 template_file = 'immutable_list_mixin.darttemplate'
313 template = self._system._templates.Load(template_file) 313 template = self._system._templates.Load(template_file)
314 self._members_emitter.Emit(template, E=element_type) 314 self._members_emitter.Emit(template, E=DartType(element_type))
315 315
316 316
317 def AddTypedArrayConstructors(self, element_type): 317 def AddTypedArrayConstructors(self, element_type):
318 self._members_emitter.Emit( 318 self._members_emitter.Emit(
319 '\n' 319 '\n'
320 ' factory $CTOR(int length) => _construct_$CTOR(length);\n' 320 ' factory $CTOR(int length) => _construct_$CTOR(length);\n'
321 '\n' 321 '\n'
322 ' factory $CTOR.fromList(List<$TYPE> list) => _construct_$CTOR(list);\n ' 322 ' factory $CTOR.fromList(List<$TYPE> list) => _construct_$CTOR(list);\n '
323 '\n' 323 '\n'
324 ' factory $CTOR.fromBuffer(ArrayBuffer buffer) => _construct_$CTOR(buff er);\n' 324 ' factory $CTOR.fromBuffer(ArrayBuffer buffer) => _construct_$CTOR(buff er);\n'
325 '\n' 325 '\n'
326 ' static _construct_$CTOR(arg) native \'return new $CTOR(arg);\';\n', 326 ' static _construct_$CTOR(arg) native \'return new $CTOR(arg);\';\n',
327 CTOR=self._interface.id, 327 CTOR=self._interface.id,
328 TYPE=element_type) 328 TYPE=DartType(element_type))
329 329
330 330
331 def AddOperation(self, info): 331 def AddOperation(self, info):
332 """ 332 """
333 Arguments: 333 Arguments:
334 info: An OperationInfo object. 334 info: An OperationInfo object.
335 """ 335 """
336 # TODO(vsm): Handle overloads. 336 # TODO(vsm): Handle overloads.
337 params = info.ParametersImplementationDeclaration( 337 params = info.ParametersImplementationDeclaration(
338 lambda type_name: self._NarrowInputType(type_name)) 338 lambda type_name: self._NarrowInputType(type_name))
339 339
340 native_body = dom_frog_native_bodies.get( 340 native_body = dom_frog_native_bodies.get(
341 self._interface.id + '.' + info.name, '') 341 self._interface.id + '.' + info.name, '')
342 if native_body: 342 if native_body:
343 native_body = " '''" + native_body + "'''" 343 native_body = " '''" + native_body + "'''"
344 344
345 self._members_emitter.Emit( 345 self._members_emitter.Emit(
346 '\n' 346 '\n'
347 ' $TYPE $NAME($PARAMS) native$NATIVESTRING;\n', 347 ' $TYPE $NAME($PARAMS) native$NATIVESTRING;\n',
348 TYPE=self._NarrowOutputType(info.type_name), 348 TYPE=self._NarrowOutputType(info.type_name),
349 NAME=info.name, 349 NAME=info.name,
350 PARAMS=params, 350 PARAMS=params,
351 NATIVESTRING=native_body) 351 NATIVESTRING=native_body)
OLDNEW
« no previous file with comments | « client/dom/scripts/generator.py ('k') | client/dom/scripts/systemhtml.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698