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

Side by Side Diff: tools/dom/scripts/generator.py

Issue 13811054: Update code generator for dartium dart:html with typeddata. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments Created 7 years, 8 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 | « tools/dom/idl/dart/dart.idl ('k') | tools/dom/scripts/htmldartgenerator.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 systems to generate 6 """This module provides shared functionality for systems to generate
7 Dart APIs from the IDL database.""" 7 Dart APIs from the IDL database."""
8 8
9 import copy 9 import copy
10 import json 10 import json
(...skipping 1311 matching lines...) Expand 10 before | Expand all | Expand 10 after
1322 conversion_cast = '%s::create(%s)' 1322 conversion_cast = '%s::create(%s)'
1323 else: 1323 else:
1324 conversion_cast = 'static_cast<%s*>(%s)' 1324 conversion_cast = 'static_cast<%s*>(%s)'
1325 conversion_cast = conversion_cast % (self.native_type(), value) 1325 conversion_cast = conversion_cast % (self.native_type(), value)
1326 return 'Dart%s::toDart(%s)' % (self._idl_type, conversion_cast) 1326 return 'Dart%s::toDart(%s)' % (self._idl_type, conversion_cast)
1327 1327
1328 def argument_expression(self, name, interface_name): 1328 def argument_expression(self, name, interface_name):
1329 return name if interface_name.endswith('List') else '%s->propertyReference() ' % name 1329 return name if interface_name.endswith('List') else '%s->propertyReference() ' % name
1330 1330
1331 1331
1332 class TypedListIDLTypeInfo(InterfaceIDLTypeInfo):
1333 def __init__(self, idl_type, data, interface_name, type_registry):
1334 super(TypedListIDLTypeInfo, self).__init__(
1335 idl_type, data, interface_name, type_registry)
1336
1337 def conversion_includes(self):
1338 return [ '"wtf/%s.h"' % self._idl_type ]
1339
1340 def to_dart_conversion(self, value, interface_name, attributes):
1341 return 'DartUtilities::arrayBufferViewToDart(%s)' % value
1342
1343 def to_native_info(self, idl_node, interface_name):
1344 return '%s.get()', 'RefPtr<%s>' % self._idl_type, 'DartUtilities', 'dartTo%s ' % self._idl_type
1345
1346
1347 class BasicTypedListIDLTypeInfo(InterfaceIDLTypeInfo):
1348 def __init__(self, idl_type, data, interface_name, type_registry):
1349 super(BasicTypedListIDLTypeInfo, self).__init__(
1350 idl_type, data, interface_name, type_registry)
1351
1352 def conversion_includes(self):
1353 return []
1354
1355 def to_dart_conversion(self, value, interface_name, attributes):
1356 function_name = 'DartUtilities::%sToDart' % self._idl_type
1357 function_name = function_name[0].lower() + function_name[1:]
1358 return '%s(%s)' % (function_name, value)
1359
1360 def to_native_info(self, idl_node, interface_name):
1361 return '%s.get()', 'RefPtr<%s>' % self._idl_type, 'DartUtilities', 'dartTo%s ' % self._idl_type
1362
1363
1332 class TypeData(object): 1364 class TypeData(object):
1333 def __init__(self, clazz, dart_type=None, native_type=None, 1365 def __init__(self, clazz, dart_type=None, native_type=None,
1334 merged_interface=None, merged_into=None, 1366 merged_interface=None, merged_into=None,
1335 custom_to_dart=False, custom_to_native=False, 1367 custom_to_dart=False, custom_to_native=False,
1336 conversion_includes=None, 1368 conversion_includes=None,
1337 webcore_getter_name='getAttribute', 1369 webcore_getter_name='getAttribute',
1338 webcore_setter_name='setAttribute', 1370 webcore_setter_name='setAttribute',
1339 item_type=None, suppress_interface=False, is_typed_array=False): 1371 item_type=None, suppress_interface=False, is_typed_array=False):
1340 self.clazz = clazz 1372 self.clazz = clazz
1341 self.dart_type = dart_type 1373 self.dart_type = dart_type
1342 self.native_type = native_type 1374 self.native_type = native_type
1343 self.merged_interface = merged_interface 1375 self.merged_interface = merged_interface
1344 self.merged_into = merged_into 1376 self.merged_into = merged_into
1345 self.custom_to_dart = custom_to_dart 1377 self.custom_to_dart = custom_to_dart
1346 self.custom_to_native = custom_to_native 1378 self.custom_to_native = custom_to_native
1347 self.conversion_includes = conversion_includes 1379 self.conversion_includes = conversion_includes
1348 self.webcore_getter_name = webcore_getter_name 1380 self.webcore_getter_name = webcore_getter_name
1349 self.webcore_setter_name = webcore_setter_name 1381 self.webcore_setter_name = webcore_setter_name
1350 self.item_type = item_type 1382 self.item_type = item_type
1351 self.suppress_interface = suppress_interface 1383 self.suppress_interface = suppress_interface
1352 self.is_typed_array = is_typed_array 1384 self.is_typed_array = is_typed_array
1353 1385
1354 1386
1355 def TypedArrayTypeData(item_type): 1387 def TypedListTypeData(item_type):
1356 return TypeData( 1388 return TypeData(
1357 clazz='Interface', 1389 clazz='TypedList',
1358 dart_type='List<%s>' % item_type, # TODO(antonm): proper typeddata interfa ces. 1390 dart_type='List<%s>' % item_type, # TODO(antonm): proper typeddata interfa ces.
1359 item_type=item_type, 1391 item_type=item_type,
1360 # TODO(antonm): should be autogenerated. Let the dust settle down.
1361 custom_to_dart=True, custom_to_native=True,
1362 is_typed_array=True) 1392 is_typed_array=True)
1363 1393
1364 1394
1365 _idl_type_registry = monitored.Dict('generator._idl_type_registry', { 1395 _idl_type_registry = monitored.Dict('generator._idl_type_registry', {
1366 'boolean': TypeData(clazz='Primitive', dart_type='bool', native_type='bool', 1396 'boolean': TypeData(clazz='Primitive', dart_type='bool', native_type='bool',
1367 webcore_getter_name='hasAttribute', 1397 webcore_getter_name='hasAttribute',
1368 webcore_setter_name='setBooleanAttribute'), 1398 webcore_setter_name='setBooleanAttribute'),
1369 'byte': TypeData(clazz='Primitive', dart_type='int', native_type='int'), 1399 'byte': TypeData(clazz='Primitive', dart_type='int', native_type='int'),
1370 'octet': TypeData(clazz='Primitive', dart_type='int', native_type='int'), 1400 'octet': TypeData(clazz='Primitive', dart_type='int', native_type='int'),
1371 'short': TypeData(clazz='Primitive', dart_type='int', native_type='int'), 1401 'short': TypeData(clazz='Primitive', dart_type='int', native_type='int'),
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
1455 item_type='SpeechInputResult', suppress_interface=True), 1485 item_type='SpeechInputResult', suppress_interface=True),
1456 'SpeechRecognitionResultList': TypeData(clazz='Interface', 1486 'SpeechRecognitionResultList': TypeData(clazz='Interface',
1457 item_type='SpeechRecognitionResult', suppress_interface=True), 1487 item_type='SpeechRecognitionResult', suppress_interface=True),
1458 'SQLResultSetRowList': TypeData(clazz='Interface', item_type='Dictionary'), 1488 'SQLResultSetRowList': TypeData(clazz='Interface', item_type='Dictionary'),
1459 'StyleSheetList': TypeData(clazz='Interface', 1489 'StyleSheetList': TypeData(clazz='Interface',
1460 item_type='StyleSheet', suppress_interface=True), 1490 item_type='StyleSheet', suppress_interface=True),
1461 'TextTrackCueList': TypeData(clazz='Interface', item_type='TextTrackCue'), 1491 'TextTrackCueList': TypeData(clazz='Interface', item_type='TextTrackCue'),
1462 'TextTrackList': TypeData(clazz='Interface', item_type='TextTrack'), 1492 'TextTrackList': TypeData(clazz='Interface', item_type='TextTrack'),
1463 'TouchList': TypeData(clazz='Interface', item_type='Touch'), 1493 'TouchList': TypeData(clazz='Interface', item_type='Touch'),
1464 1494
1465 'Float32Array': TypedArrayTypeData('double'), 1495 'Float32Array': TypedListTypeData('double'),
1466 'Float64Array': TypedArrayTypeData('double'), 1496 'Float64Array': TypedListTypeData('double'),
1467 'Int8Array': TypedArrayTypeData('int'), 1497 'Int8Array': TypedListTypeData('int'),
1468 'Int16Array': TypedArrayTypeData('int'), 1498 'Int16Array': TypedListTypeData('int'),
1469 'Int32Array': TypedArrayTypeData('int'), 1499 'Int32Array': TypedListTypeData('int'),
1470 'Uint8Array': TypedArrayTypeData('int'), 1500 'Uint8Array': TypedListTypeData('int'),
1471 'Uint8ClampedArray': TypedArrayTypeData('int'), 1501 'Uint8ClampedArray': TypedListTypeData('int'),
1472 'Uint16Array': TypedArrayTypeData('int'), 1502 'Uint16Array': TypedListTypeData('int'),
1473 'Uint32Array': TypedArrayTypeData('int'), 1503 'Uint32Array': TypedListTypeData('int'),
1474 # TODO(antonm): temporary ugly hack. 1504
1475 # While in transition phase we allow both DOM's ArrayBuffer 1505 'ArrayBufferView': TypeData(clazz='BasicTypedList'),
1476 # and dart:typeddata's ByteBuffer for IDLs' ArrayBuffers, 1506 'ArrayBuffer': TypeData(clazz='BasicTypedList'),
1477 # hence ArrayBuffer is mapped to dynamic in arguments and return
1478 # values.
1479 'ArrayBufferView': TypeData(clazz='Interface', dart_type='dynamic',
1480 custom_to_native=True, custom_to_dart=True),
1481 'ArrayBuffer': TypeData(clazz='Interface', dart_type='dynamic',
1482 custom_to_native=True, custom_to_dart=True),
1483 1507
1484 'SVGAngle': TypeData(clazz='SVGTearOff'), 1508 'SVGAngle': TypeData(clazz='SVGTearOff'),
1485 'SVGLength': TypeData(clazz='SVGTearOff'), 1509 'SVGLength': TypeData(clazz='SVGTearOff'),
1486 'SVGLengthList': TypeData(clazz='SVGTearOff', item_type='SVGLength'), 1510 'SVGLengthList': TypeData(clazz='SVGTearOff', item_type='SVGLength'),
1487 'SVGMatrix': TypeData(clazz='SVGTearOff'), 1511 'SVGMatrix': TypeData(clazz='SVGTearOff'),
1488 'SVGNumber': TypeData(clazz='SVGTearOff', native_type='SVGPropertyTearOff<fl oat>'), 1512 'SVGNumber': TypeData(clazz='SVGTearOff', native_type='SVGPropertyTearOff<fl oat>'),
1489 'SVGNumberList': TypeData(clazz='SVGTearOff', item_type='SVGNumber'), 1513 'SVGNumberList': TypeData(clazz='SVGTearOff', item_type='SVGNumber'),
1490 'SVGPathSegList': TypeData(clazz='SVGTearOff', item_type='SVGPathSeg', 1514 'SVGPathSegList': TypeData(clazz='SVGTearOff', item_type='SVGPathSeg',
1491 native_type='SVGPathSegListPropertyTearOff'), 1515 native_type='SVGPathSegListPropertyTearOff'),
1492 'SVGPoint': TypeData(clazz='SVGTearOff', native_type='SVGPropertyTearOff<Flo atPoint>'), 1516 'SVGPoint': TypeData(clazz='SVGTearOff', native_type='SVGPropertyTearOff<Flo atPoint>'),
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
1557 dart_interface_name = self._renamer.DartifyTypeName(type_name) 1581 dart_interface_name = self._renamer.DartifyTypeName(type_name)
1558 return InterfaceIDLTypeInfo(type_name, type_data, dart_interface_name, 1582 return InterfaceIDLTypeInfo(type_name, type_data, dart_interface_name,
1559 self) 1583 self)
1560 1584
1561 if type_data.clazz == 'SVGTearOff': 1585 if type_data.clazz == 'SVGTearOff':
1562 dart_interface_name = self._renamer.RenameInterface( 1586 dart_interface_name = self._renamer.RenameInterface(
1563 self._database.GetInterface(type_name)) 1587 self._database.GetInterface(type_name))
1564 return SVGTearOffIDLTypeInfo( 1588 return SVGTearOffIDLTypeInfo(
1565 type_name, type_data, dart_interface_name, self) 1589 type_name, type_data, dart_interface_name, self)
1566 1590
1591 if type_data.clazz == 'TypedList':
1592 dart_interface_name = self._renamer.RenameInterface(
1593 self._database.GetInterface(type_name))
1594 return TypedListIDLTypeInfo(
1595 type_name, type_data, dart_interface_name, self)
1596
1597 if type_data.clazz == 'BasicTypedList':
1598 dart_interface_name = self._renamer.RenameInterface(
1599 self._database.GetInterface(type_name))
1600 return BasicTypedListIDLTypeInfo(
1601 type_name, type_data, dart_interface_name, self)
1602
1567 class_name = '%sIDLTypeInfo' % type_data.clazz 1603 class_name = '%sIDLTypeInfo' % type_data.clazz
1568 return globals()[class_name](type_name, type_data) 1604 return globals()[class_name](type_name, type_data)
OLDNEW
« no previous file with comments | « tools/dom/idl/dart/dart.idl ('k') | tools/dom/scripts/htmldartgenerator.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698