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

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

Issue 9695015: Provide DartDomNameOfAttribute (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: fix native 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
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 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 if super_getter or super_setter: 213 if super_getter or super_setter:
214 if getter and not setter and super_getter and not super_setter: 214 if getter and not setter and super_getter and not super_setter:
215 if DartType(getter.type.id) == DartType(super_getter.type.id): 215 if DartType(getter.type.id) == DartType(super_getter.type.id):
216 # Compatible getter, use the superclass property. This works because 216 # Compatible getter, use the superclass property. This works because
217 # JavaScript will do its own dynamic dispatch. 217 # JavaScript will do its own dynamic dispatch.
218 self._members_emitter.Emit( 218 self._members_emitter.Emit(
219 '\n' 219 '\n'
220 ' // Use implementation from $SUPER.\n' 220 ' // Use implementation from $SUPER.\n'
221 ' // final $TYPE $NAME;\n', 221 ' // final $TYPE $NAME;\n',
222 SUPER=super_getter_interface.id, 222 SUPER=super_getter_interface.id,
223 NAME=getter.id, TYPE=output_type) 223 NAME=DartDomNameOfAttribute(getter), TYPE=output_type)
224 return 224 return
225 225
226 self._members_emitter.Emit('\n // Shadowing definition.') 226 self._members_emitter.Emit('\n // Shadowing definition.')
227 self._AddAttributeUsingProperties(getter, setter) 227 self._AddAttributeUsingProperties(getter, setter)
228 return 228 return
229 229
230 # Can't generate field if attribute has different name in JS and Dart.
231 if self._AttributeChangesName(getter or setter):
232 self._AddAttributeUsingProperties(getter, setter)
233 return
234
230 if getter and setter and input_type == output_type: 235 if getter and setter and input_type == output_type:
231 self._members_emitter.Emit( 236 self._members_emitter.Emit(
232 '\n $TYPE $NAME;\n', 237 '\n $TYPE $NAME;\n',
233 NAME=getter.id, TYPE=output_type) 238 NAME=DartDomNameOfAttribute(getter), TYPE=output_type)
234 return 239 return
235 if getter and not setter: 240 if getter and not setter:
236 self._members_emitter.Emit( 241 self._members_emitter.Emit(
237 '\n final $TYPE $NAME;\n', 242 '\n final $TYPE $NAME;\n',
238 NAME=getter.id, TYPE=output_type) 243 NAME=DartDomNameOfAttribute(getter), TYPE=output_type)
239 return 244 return
240 self._AddAttributeUsingProperties(getter, setter) 245 self._AddAttributeUsingProperties(getter, setter)
241 246
247 def _AttributeChangesName(self, attr):
248 return attr.id != DartDomNameOfAttribute(attr)
249
242 def _AddAttributeUsingProperties(self, getter, setter): 250 def _AddAttributeUsingProperties(self, getter, setter):
243 if getter: 251 if getter:
244 self._AddGetter(getter) 252 self._AddGetter(getter)
245 if setter: 253 if setter:
246 self._AddSetter(setter) 254 self._AddSetter(setter)
247 255
248 def _AddGetter(self, attr): 256 def _AddGetter(self, attr):
249 # TODO(sra): Remove native body when Issue 829 fixed. 257 # TODO(sra): Remove native body when Issue 829 fixed.
250 self._members_emitter.Emit( 258 self._members_emitter.Emit(
251 '\n $TYPE get $NAME() native "return this.$NAME;";\n', 259 '\n $TYPE get $NAME() native "return this.$NATIVE_NAME;";\n',
252 NAME=attr.id, TYPE=self._NarrowOutputType(attr.type.id)) 260 NAME=DartDomNameOfAttribute(attr),
261 NATIVE_NAME=attr.id,
262 TYPE=self._NarrowOutputType(attr.type.id))
253 263
254 def _AddSetter(self, attr): 264 def _AddSetter(self, attr):
255 # TODO(sra): Remove native body when Issue 829 fixed. 265 # TODO(sra): Remove native body when Issue 829 fixed.
256 self._members_emitter.Emit( 266 self._members_emitter.Emit(
257 ' void set $NAME($TYPE value) native "this.$NAME = value;";\n', 267 ' void set $NAME($TYPE value) native "this.$NATIVE_NAME = value;";\n',
258 NAME=attr.id, TYPE=self._NarrowInputType(attr.type.id)) 268 NAME=DartDomNameOfAttribute(attr),
269 NATIVE_NAME=attr.id,
270 TYPE=self._NarrowInputType(attr.type.id))
259 271
260 def _FindShadowedAttribute(self, attr): 272 def _FindShadowedAttribute(self, attr):
261 """Returns (attribute, superinterface) or (None, None).""" 273 """Returns (attribute, superinterface) or (None, None)."""
262 def FindInParent(interface): 274 def FindInParent(interface):
263 """Returns matching attribute in parent, or None.""" 275 """Returns matching attribute in parent, or None."""
264 if interface.parents: 276 if interface.parents:
265 parent = interface.parents[0] 277 parent = interface.parents[0]
266 if IsDartCollectionType(parent.type.id): 278 if IsDartCollectionType(parent.type.id):
267 return (None, None) 279 return (None, None)
268 if self._system._database.HasInterface(parent.type.id): 280 if self._system._database.HasInterface(parent.type.id):
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 if native_body: 373 if native_body:
362 native_body = " '''" + native_body + "'''" 374 native_body = " '''" + native_body + "'''"
363 375
364 self._members_emitter.Emit( 376 self._members_emitter.Emit(
365 '\n' 377 '\n'
366 ' $TYPE $NAME($PARAMS) native$NATIVESTRING;\n', 378 ' $TYPE $NAME($PARAMS) native$NATIVESTRING;\n',
367 TYPE=self._NarrowOutputType(info.type_name), 379 TYPE=self._NarrowOutputType(info.type_name),
368 NAME=info.name, 380 NAME=info.name,
369 PARAMS=params, 381 PARAMS=params,
370 NATIVESTRING=native_body) 382 NATIVESTRING=native_body)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698