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

Side by Side Diff: client/dom/scripts/systemwrapping.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, 10 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/systemnative.py ('k') | no next file » | 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 wrapping binding from the IDL database.""" 7 wrapping binding from the IDL database."""
8 8
9 import os 9 import os
10 from generator import * 10 from generator import *
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 164
165 def _AddGetter(self, attr): 165 def _AddGetter(self, attr):
166 # FIXME: Instead of injecting the interface name into the method when it is 166 # FIXME: Instead of injecting the interface name into the method when it is
167 # also implemented in the base class, suppress the method altogether if it 167 # also implemented in the base class, suppress the method altogether if it
168 # has the same signature. I.e., let the JS do the virtual dispatch instead. 168 # has the same signature. I.e., let the JS do the virtual dispatch instead.
169 method_name = self._MethodName('_get_', attr.id) 169 method_name = self._MethodName('_get_', attr.id)
170 self._members_emitter.Emit( 170 self._members_emitter.Emit(
171 '\n' 171 '\n'
172 ' $TYPE get $NAME() { return $METHOD(this); }\n' 172 ' $TYPE get $NAME() { return $METHOD(this); }\n'
173 ' static $TYPE $METHOD(var _this) native;\n', 173 ' static $TYPE $METHOD(var _this) native;\n',
174 NAME=attr.id, TYPE=attr.type.id, METHOD=method_name) 174 NAME=attr.id, TYPE=DartType(attr.type.id), METHOD=method_name)
175 175
176 def _AddSetter(self, attr): 176 def _AddSetter(self, attr):
177 # FIXME: See comment on getter. 177 # FIXME: See comment on getter.
178 method_name = self._MethodName('_set_', attr.id) 178 method_name = self._MethodName('_set_', attr.id)
179 self._members_emitter.Emit( 179 self._members_emitter.Emit(
180 '\n' 180 '\n'
181 ' void set $NAME($TYPE value) { $METHOD(this, value); }\n' 181 ' void set $NAME($TYPE value) { $METHOD(this, value); }\n'
182 ' static void $METHOD(var _this, $TYPE value) native;\n', 182 ' static void $METHOD(var _this, $TYPE value) native;\n',
183 NAME=attr.id, TYPE=attr.type.id, METHOD=method_name) 183 NAME=attr.id, TYPE=DartType(attr.type.id), METHOD=method_name)
184 184
185 def AddSecondaryAttribute(self, interface, getter, setter): 185 def AddSecondaryAttribute(self, interface, getter, setter):
186 self._SecondaryContext(interface) 186 self._SecondaryContext(interface)
187 self.AddAttribute(getter, setter) 187 self.AddAttribute(getter, setter)
188 188
189 def AddSecondaryOperation(self, interface, info): 189 def AddSecondaryOperation(self, interface, info):
190 self._SecondaryContext(interface) 190 self._SecondaryContext(interface)
191 self.AddOperation(info) 191 self.AddOperation(info)
192 192
193 def AddEventAttributes(self, event_attrs): 193 def AddEventAttributes(self, event_attrs):
(...skipping 16 matching lines...) Expand all
210 # interface Y extends X, List<T> ... 210 # interface Y extends X, List<T> ...
211 # 211 #
212 # In the non-root case we have to choose between: 212 # In the non-root case we have to choose between:
213 # 213 #
214 # class YImpl extends XImpl { add List<T> methods; } 214 # class YImpl extends XImpl { add List<T> methods; }
215 # 215 #
216 # and 216 # and
217 # 217 #
218 # class YImpl extends ListBase<T> { copies of transitive XImpl methods; } 218 # class YImpl extends ListBase<T> { copies of transitive XImpl methods; }
219 # 219 #
220 dart_element_type = DartType(element_type)
220 if self._HasNativeIndexGetter(self._interface): 221 if self._HasNativeIndexGetter(self._interface):
221 self._EmitNativeIndexGetter(self._interface, element_type) 222 self._EmitNativeIndexGetter(self._interface, dart_element_type)
222 else: 223 else:
223 self._members_emitter.Emit( 224 self._members_emitter.Emit(
224 '\n' 225 '\n'
225 ' $TYPE operator[](int index) {\n' 226 ' $TYPE operator[](int index) {\n'
226 ' return item(index);\n' 227 ' return item(index);\n'
227 ' }\n', 228 ' }\n',
228 TYPE=element_type) 229 TYPE=dart_element_type)
229 230
230 if self._HasNativeIndexSetter(self._interface): 231 if self._HasNativeIndexSetter(self._interface):
231 self._EmitNativeIndexSetter(self._interface, element_type) 232 self._EmitNativeIndexSetter(self._interface, dart_element_type)
232 else: 233 else:
233 self._members_emitter.Emit( 234 self._members_emitter.Emit(
234 '\n' 235 '\n'
235 ' void operator[]=(int index, $TYPE value) {\n' 236 ' void operator[]=(int index, $TYPE value) {\n'
236 ' throw new UnsupportedOperationException("Cannot assign element of immutable List.");\n' 237 ' throw new UnsupportedOperationException("Cannot assign element of immutable List.");\n'
237 ' }\n', 238 ' }\n',
238 TYPE=element_type) 239 TYPE=dart_element_type)
239 240
240 self._members_emitter.Emit( 241 self._members_emitter.Emit(
241 '\n' 242 '\n'
242 ' void add($TYPE value) {\n' 243 ' void add($TYPE value) {\n'
243 ' throw new UnsupportedOperationException("Cannot add to immutable Li st.");\n' 244 ' throw new UnsupportedOperationException("Cannot add to immutable Li st.");\n'
244 ' }\n' 245 ' }\n'
245 '\n' 246 '\n'
246 ' void addLast($TYPE value) {\n' 247 ' void addLast($TYPE value) {\n'
247 ' throw new UnsupportedOperationException("Cannot add to immutable Li st.");\n' 248 ' throw new UnsupportedOperationException("Cannot add to immutable Li st.");\n'
248 ' }\n' 249 ' }\n'
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 ' throw new NotImplementedException();\n' 318 ' throw new NotImplementedException();\n'
318 ' }\n' 319 ' }\n'
319 '\n' 320 '\n'
320 ' bool isEmpty() {\n' 321 ' bool isEmpty() {\n'
321 ' return length == 0;\n' 322 ' return length == 0;\n'
322 ' }\n' 323 ' }\n'
323 '\n' 324 '\n'
324 ' Iterator<$TYPE> iterator() {\n' 325 ' Iterator<$TYPE> iterator() {\n'
325 ' return new _FixedSizeListIterator<$TYPE>(this);\n' 326 ' return new _FixedSizeListIterator<$TYPE>(this);\n'
326 ' }\n', 327 ' }\n',
327 TYPE=element_type) 328 TYPE=dart_element_type)
328 329
329 def _HasNativeIndexGetter(self, interface): 330 def _HasNativeIndexGetter(self, interface):
330 return ('IndexedGetter' in interface.ext_attrs or 331 return ('IndexedGetter' in interface.ext_attrs or
331 'NumericIndexedGetter' in interface.ext_attrs) 332 'NumericIndexedGetter' in interface.ext_attrs)
332 333
333 def _EmitNativeIndexGetter(self, interface, element_type): 334 def _EmitNativeIndexGetter(self, interface, dart_element_type):
334 method_name = '_index' 335 method_name = '_index'
335 self._members_emitter.Emit( 336 self._members_emitter.Emit(
336 '\n' 337 '\n'
337 ' $TYPE operator[](int index) { return $METHOD(this, index); }\n' 338 ' $TYPE operator[](int index) { return $METHOD(this, index); }\n'
338 ' static $TYPE $METHOD(var _this, int index) native;\n', 339 ' static $TYPE $METHOD(var _this, int index) native;\n',
339 TYPE=element_type, METHOD=method_name) 340 TYPE=dart_element_type, METHOD=method_name)
340 341
341 def _HasNativeIndexSetter(self, interface): 342 def _HasNativeIndexSetter(self, interface):
342 return 'CustomIndexedSetter' in interface.ext_attrs 343 return 'CustomIndexedSetter' in interface.ext_attrs
343 344
344 def _EmitNativeIndexSetter(self, interface, element_type): 345 def _EmitNativeIndexSetter(self, interface, dart_element_type):
345 method_name = '_set_index' 346 method_name = '_set_index'
346 self._members_emitter.Emit( 347 self._members_emitter.Emit(
347 '\n' 348 '\n'
348 ' void operator[]=(int index, $TYPE value) {\n' 349 ' void operator[]=(int index, $TYPE value) {\n'
349 ' return $METHOD(this, index, value);\n' 350 ' return $METHOD(this, index, value);\n'
350 ' }\n' 351 ' }\n'
351 ' static $METHOD(_this, index, value) native;\n', 352 ' static $METHOD(_this, index, value) native;\n',
352 TYPE=element_type, METHOD=method_name) 353 TYPE=dart_element_type, METHOD=method_name)
353 354
354 def AddOperation(self, info): 355 def AddOperation(self, info):
355 """ 356 """
356 Arguments: 357 Arguments:
357 info: An OperationInfo object. 358 info: An OperationInfo object.
358 """ 359 """
359 body = self._members_emitter.Emit( 360 body = self._members_emitter.Emit(
360 '\n' 361 '\n'
361 ' $TYPE $NAME($PARAMS) {\n' 362 ' $TYPE $NAME($PARAMS) {\n'
362 '$!BODY' 363 '$!BODY'
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
457 positive = [] 458 positive = []
458 negative = [] 459 negative = []
459 first_overload = overloads[0] 460 first_overload = overloads[0]
460 (param_name, param_type, param_default) = info.arg_infos[position] 461 (param_name, param_type, param_default) = info.arg_infos[position]
461 462
462 if position < len(first_overload.arguments): 463 if position < len(first_overload.arguments):
463 # FIXME: This will not work if the second overload has a more 464 # FIXME: This will not work if the second overload has a more
464 # precise type than the first. E.g., 465 # precise type than the first. E.g.,
465 # void foo(Node x); 466 # void foo(Node x);
466 # void foo(Element x); 467 # void foo(Element x);
467 type = first_overload.arguments[position].type.id 468 type = DartType(first_overload.arguments[position].type.id)
468 test = TypeCheck(param_name, type) 469 test = TypeCheck(param_name, type)
469 pred = lambda op: len(op.arguments) > position and op.arguments[position]. type.id == type 470 pred = lambda op: len(op.arguments) > position and DartType(op.arguments[p osition].type.id) == type
470 else: 471 else:
471 type = None 472 type = None
472 test = NullCheck(param_name) 473 test = NullCheck(param_name)
473 pred = lambda op: position >= len(op.arguments) 474 pred = lambda op: position >= len(op.arguments)
474 475
475 for overload in overloads: 476 for overload in overloads:
476 if pred(overload): 477 if pred(overload):
477 positive.append(overload) 478 positive.append(overload)
478 else: 479 else:
479 negative.append(overload) 480 negative.append(overload)
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
511 # dispatch has removed f(X), leaving only f(Y), but there is no guarantee 512 # dispatch has removed f(X), leaving only f(Y), but there is no guarantee
512 # that Y = Z-X, so we need to check for Y. 513 # that Y = Z-X, so we need to check for Y.
513 true_code = emitter.Emit( 514 true_code = emitter.Emit(
514 '$(INDENT)if ($COND) {\n' 515 '$(INDENT)if ($COND) {\n'
515 '$!TRUE' 516 '$!TRUE'
516 '$(INDENT)}\n', 517 '$(INDENT)}\n',
517 COND=test, INDENT=indent) 518 COND=test, INDENT=indent)
518 self.GenerateDispatch( 519 self.GenerateDispatch(
519 true_code, info, indent + ' ', position + 1, positive) 520 true_code, info, indent + ' ', position + 1, positive)
520 return True 521 return True
OLDNEW
« no previous file with comments | « client/dom/scripts/systemnative.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698