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

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

Issue 10107010: Map IDBAny and IDBKey to Dynamic (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 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 | « lib/dom/scripts/systemfrog.py ('k') | lib/dom/scripts/systeminterface.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 system to generate 6 """This module provides shared functionality for the system to generate
7 Dart:html APIs from the IDL database.""" 7 Dart:html APIs from the IDL database."""
8 8
9 from systemfrog import * 9 from systemfrog import *
10 from systeminterface import * 10 from systeminterface import *
(...skipping 1304 matching lines...) Expand 10 before | Expand all | Expand 10 after
1315 1315
1316 factory_provider = '_' + interface_name + 'FactoryProvider' 1316 factory_provider = '_' + interface_name + 'FactoryProvider'
1317 emitter = self._system._ImplFileEmitter(factory_provider) 1317 emitter = self._system._ImplFileEmitter(factory_provider)
1318 emitter.Emit( 1318 emitter.Emit(
1319 template, 1319 template,
1320 FACTORYPROVIDER=factory_provider, 1320 FACTORYPROVIDER=factory_provider,
1321 CONSTRUCTOR=interface_name, 1321 CONSTRUCTOR=interface_name,
1322 PARAMETERS=constructor_info.ParametersImplementationDeclaration(), 1322 PARAMETERS=constructor_info.ParametersImplementationDeclaration(),
1323 NAMED_CONSTRUCTOR=constructor_info.name or interface_name, 1323 NAMED_CONSTRUCTOR=constructor_info.name or interface_name,
1324 ARGUMENTS=self._UnwrappedParameters(constructor_info, 1324 ARGUMENTS=self._UnwrappedParameters(constructor_info,
1325 len(constructor_info.arg_infos))) 1325 len(constructor_info.param_infos)))
1326 1326
1327 def _UnwrappedParameters(self, operation_info, length): 1327 def _UnwrappedParameters(self, operation_info, length):
1328 """Returns string for an argument list that unwraps first |length| 1328 """Returns string for an argument list that unwraps first |length|
1329 parameters.""" 1329 parameters."""
1330 def UnwrapArgInfo(arg_info): 1330 def UnwrapParamInfo(param_info):
1331 (name, type, value) = arg_info
1332 # TODO(sra): Type dependent unwrapping. 1331 # TODO(sra): Type dependent unwrapping.
1333 return '_unwrap(%s)' % name 1332 return '_unwrap(%s)' % param_info.name
1334 1333
1335 return ', '.join(map(UnwrapArgInfo, operation_info.arg_infos[:length])) 1334 return ', '.join(map(UnwrapParamInfo, operation_info.param_infos[:length]))
1336 1335
1337 def _BaseClassName(self, interface): 1336 def _BaseClassName(self, interface):
1338 if not interface.parents: 1337 if not interface.parents:
1339 return '_DOMTypeBase' 1338 return '_DOMTypeBase'
1340 1339
1341 supertype = DartType(interface.parents[0].type.id) 1340 supertype = DartType(interface.parents[0].type.id)
1342 1341
1343 if IsDartListType(supertype) or IsDartCollectionType(supertype): 1342 if IsDartListType(supertype) or IsDartCollectionType(supertype):
1344 return 'DOMWrapperBase' 1343 return 'DOMWrapperBase'
1345 1344
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
1607 Returns True if the dispatch can fall through on failure, False if the code 1606 Returns True if the dispatch can fall through on failure, False if the code
1608 always dispatches. 1607 always dispatches.
1609 """ 1608 """
1610 1609
1611 def NullCheck(name): 1610 def NullCheck(name):
1612 return '%s === null' % name 1611 return '%s === null' % name
1613 1612
1614 def TypeCheck(name, type): 1613 def TypeCheck(name, type):
1615 return '%s is %s' % (name, type) 1614 return '%s is %s' % (name, type)
1616 1615
1617 if position == len(info.arg_infos): 1616 if position == len(info.param_infos):
1618 if len(overloads) > 1: 1617 if len(overloads) > 1:
1619 raise Exception('Duplicate operations ' + str(overloads)) 1618 raise Exception('Duplicate operations ' + str(overloads))
1620 operation = overloads[0] 1619 operation = overloads[0]
1621 self.GenerateSingleOperation(emitter, info, indent, operation) 1620 self.GenerateSingleOperation(emitter, info, indent, operation)
1622 return False 1621 return False
1623 1622
1624 # FIXME: Consider a simpler dispatch that iterates over the 1623 # FIXME: Consider a simpler dispatch that iterates over the
1625 # overloads and generates an overload specific check. Revisit 1624 # overloads and generates an overload specific check. Revisit
1626 # when we move to named optional arguments. 1625 # when we move to named optional arguments.
1627 1626
1628 # Partition the overloads to divide and conquer on the dispatch. 1627 # Partition the overloads to divide and conquer on the dispatch.
1629 positive = [] 1628 positive = []
1630 negative = [] 1629 negative = []
1631 first_overload = overloads[0] 1630 first_overload = overloads[0]
1632 (param_name, param_type, param_default) = info.arg_infos[position] 1631 param = info.param_infos[position]
1633 1632
1634 if position < len(first_overload.arguments): 1633 if position < len(first_overload.arguments):
1635 # FIXME: This will not work if the second overload has a more 1634 # FIXME: This will not work if the second overload has a more
1636 # precise type than the first. E.g., 1635 # precise type than the first. E.g.,
1637 # void foo(Node x); 1636 # void foo(Node x);
1638 # void foo(Element x); 1637 # void foo(Element x);
1639 type = DartType(first_overload.arguments[position].type.id) 1638 type = DartType(first_overload.arguments[position].type.id)
1640 test = TypeCheck(param_name, type) 1639 test = TypeCheck(param.name, type)
1641 pred = lambda op: (len(op.arguments) > position and 1640 pred = lambda op: (len(op.arguments) > position and
1642 DartType(op.arguments[position].type.id) == type) 1641 DartType(op.arguments[position].type.id) == type)
1643 else: 1642 else:
1644 type = None 1643 type = None
1645 test = NullCheck(param_name) 1644 test = NullCheck(param.name)
1646 pred = lambda op: position >= len(op.arguments) 1645 pred = lambda op: position >= len(op.arguments)
1647 1646
1648 for overload in overloads: 1647 for overload in overloads:
1649 if pred(overload): 1648 if pred(overload):
1650 positive.append(overload) 1649 positive.append(overload)
1651 else: 1650 else:
1652 negative.append(overload) 1651 negative.append(overload)
1653 1652
1654 if positive and negative: 1653 if positive and negative:
1655 (true_code, false_code) = emitter.Emit( 1654 (true_code, false_code) = emitter.Emit(
(...skipping 11 matching lines...) Expand all
1667 1666
1668 if negative: 1667 if negative:
1669 raise Exception('Internal error, must be all positive') 1668 raise Exception('Internal error, must be all positive')
1670 1669
1671 # All overloads require the same test. Do we bother? 1670 # All overloads require the same test. Do we bother?
1672 1671
1673 # If the test is the same as the method's formal parameter then checked mode 1672 # If the test is the same as the method's formal parameter then checked mode
1674 # will have done the test already. (It could be null too but we ignore that 1673 # will have done the test already. (It could be null too but we ignore that
1675 # case since all the overload behave the same and we don't know which types 1674 # case since all the overload behave the same and we don't know which types
1676 # in the IDL are not nullable.) 1675 # in the IDL are not nullable.)
1677 if type == param_type: 1676 if type == param.dart_type:
1678 return self.GenerateDispatch( 1677 return self.GenerateDispatch(
1679 emitter, info, indent, position + 1, positive) 1678 emitter, info, indent, position + 1, positive)
1680 1679
1681 # Otherwise the overloads have the same type but the type is a substype of 1680 # Otherwise the overloads have the same type but the type is a substype of
1682 # the method's synthesized formal parameter. e.g we have overloads f(X) and 1681 # the method's synthesized formal parameter. e.g we have overloads f(X) and
1683 # f(Y), implemented by the synthesized method f(Z) where X<Z and Y<Z. The 1682 # f(Y), implemented by the synthesized method f(Z) where X<Z and Y<Z. The
1684 # dispatch has removed f(X), leaving only f(Y), but there is no guarantee 1683 # dispatch has removed f(X), leaving only f(Y), but there is no guarantee
1685 # that Y = Z-X, so we need to check for Y. 1684 # that Y = Z-X, so we need to check for Y.
1686 true_code = emitter.Emit( 1685 true_code = emitter.Emit(
1687 '$(INDENT)if ($COND) {\n' 1686 '$(INDENT)if ($COND) {\n'
1688 '$!TRUE' 1687 '$!TRUE'
1689 '$(INDENT)}\n', 1688 '$(INDENT)}\n',
1690 COND=test, INDENT=indent) 1689 COND=test, INDENT=indent)
1691 self.GenerateDispatch( 1690 self.GenerateDispatch(
1692 true_code, info, indent + ' ', position + 1, positive) 1691 true_code, info, indent + ' ', position + 1, positive)
1693 return True 1692 return True
OLDNEW
« no previous file with comments | « lib/dom/scripts/systemfrog.py ('k') | lib/dom/scripts/systeminterface.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698