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

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

Issue 9290010: Revert "Implement List<T> operations on dom types via manual mixins." (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 11 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/generated/src/frog/Uint8Array.dart ('k') | client/dom/src/_Lists.dart » ('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 generates Dart APIs from the IDL database.""" 6 """This module generates Dart APIs from the IDL database."""
7 7
8 import emitter 8 import emitter
9 import idlnode 9 import idlnode
10 import logging 10 import logging
(...skipping 707 matching lines...) Expand 10 before | Expand all | Expand 10 after
718 if optional: 718 if optional:
719 raise Exception('Optional arguments cannot precede required ones: ' 719 raise Exception('Optional arguments cannot precede required ones: '
720 + str(args)) 720 + str(args))
721 required.append((name, type, None)) 721 required.append((name, type, None))
722 argtexts = map(FormatArg, required) 722 argtexts = map(FormatArg, required)
723 if optional: 723 if optional:
724 argtexts.append('[' + ', '.join(map(FormatArg, optional)) + ']') 724 argtexts.append('[' + ', '.join(map(FormatArg, optional)) + ']')
725 return ', '.join(argtexts) 725 return ', '.join(argtexts)
726 726
727 727
728 def MaybeListElementTypeName(type_name):
729 """Returns the List element type T from string of form "List<T>", or None."""
730 match = re.match(r'List<(\w*)>$', type_name)
731 if match:
732 return match.group(1)
733 return None
734
735 def MaybeListElementType(interface): 728 def MaybeListElementType(interface):
736 """Returns the List element type T, or None in interface does not implement 729 """Returns the List element type T, or None in interface does not implement
737 List<T>. 730 List<T>.
738 """ 731 """
739 for parent in interface.parents: 732 for parent in interface.parents:
740 element_type = MaybeListElementTypeName(parent.type.id) 733 match = re.match(r'List<(\w*)>$', parent.type.id)
741 if element_type: 734 if match:
742 return element_type 735 return match.group(1)
743 return None 736 return None
744 737
745 def MaybeTypedArrayElementType(interface): 738 def MaybeTypedArrayElementType(interface):
746 """Returns the typed array element type, or None in interface is not a 739 """Returns the typed array element type, or None in interface is not a
747 TypedArray. 740 TypedArray.
748 """ 741 """
749 # Typed arrays implement ArrayBufferView and List<T>. 742 # Typed arrays implement ArrayBufferView and List<T>.
750 for parent in interface.parents: 743 for parent in interface.parents:
751 if parent.type.id == 'ArrayBufferView': 744 if parent.type.id == 'ArrayBufferView':
752 return MaybeListElementType(interface) 745 return MaybeListElementType(interface)
(...skipping 1104 matching lines...) Expand 10 before | Expand all | Expand 10 after
1857 native_spec = _frog_dom_custom_native_specs[interface_name] 1850 native_spec = _frog_dom_custom_native_specs[interface_name]
1858 else: 1851 else:
1859 # Make the class 'hidden' so it is dynamically patched at runtime. This 1852 # Make the class 'hidden' so it is dynamically patched at runtime. This
1860 # is useful not only for browser compat, but to allow code that links 1853 # is useful not only for browser compat, but to allow code that links
1861 # against dart:dom to load in a worker isolate. 1854 # against dart:dom to load in a worker isolate.
1862 native_spec = '*' + interface_name 1855 native_spec = '*' + interface_name
1863 1856
1864 if base: 1857 if base:
1865 extends = ' extends ' + base 1858 extends = ' extends ' + base
1866 elif native_spec[0] == '=': 1859 elif native_spec[0] == '=':
1867 # The implementation is a singleton with no prototype.
1868 extends = '' 1860 extends = ''
1869 else: 1861 else:
1870 extends = ' extends DOMTypeJs' 1862 extends = ' extends DOMTypeJs'
1871 1863
1872 # TODO: Include all implemented interfaces, including other Lists. 1864 # TODO: Include all implemented interfaces, including other Lists.
1873 implements = [interface_name] 1865 implements = [interface_name]
1874 element_type = MaybeTypedArrayElementType(self._interface) 1866 element_type = MaybeTypedArrayElementType(self._interface)
1875 if element_type: 1867 if element_type:
1876 implements.append('List<' + element_type + '>') 1868 implements.append('List<' + element_type + '>')
1877 1869
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
1977 # In the non-root case we have to choose between: 1969 # In the non-root case we have to choose between:
1978 # 1970 #
1979 # class YImpl extends XImpl { add List<T> methods; } 1971 # class YImpl extends XImpl { add List<T> methods; }
1980 # 1972 #
1981 # and 1973 # and
1982 # 1974 #
1983 # class YImpl extends ListBase<T> { copies of transitive XImpl methods; } 1975 # class YImpl extends ListBase<T> { copies of transitive XImpl methods; }
1984 # 1976 #
1985 self._members_emitter.Emit( 1977 self._members_emitter.Emit(
1986 '\n' 1978 '\n'
1987 ' $TYPE operator[](int index) native "return this[index];";\n', 1979 ' $TYPE operator[](int index) native;\n',
1988 TYPE=self._NarrowOutputType(element_type)) 1980 TYPE=self._NarrowOutputType(element_type))
1989 1981
1990 if 'HasCustomIndexSetter' in self._interface.ext_attrs: 1982 if 'HasCustomIndexSetter' in self._interface.ext_attrs:
1991 self._members_emitter.Emit( 1983 self._members_emitter.Emit(
1992 '\n' 1984 '\n'
1993 ' void operator[]=(int index, $TYPE value) native "this[index] = valu e";\n', 1985 ' void operator[]=(int index, $TYPE value) native;\n',
1994 TYPE=self._NarrowInputType(element_type)) 1986 TYPE=self._NarrowInputType(element_type))
1995 else: 1987 else:
1996 self._members_emitter.Emit( 1988 self._members_emitter.Emit(
1997 '\n' 1989 '\n'
1998 ' void operator[]=(int index, $TYPE value) {\n' 1990 ' void operator[]=(int index, $TYPE value) {\n'
1999 ' throw new UnsupportedOperationException("Cannot assign element of immutable List.");\n' 1991 ' throw new UnsupportedOperationException("Cannot assign element of immutable List.");\n'
2000 ' }\n', 1992 ' }\n',
2001 TYPE=self._NarrowInputType(element_type)) 1993 TYPE=self._NarrowInputType(element_type))
2002 1994
2003 # TODO(sra): Use separate mixins for mutable implementations of List<T>.
2004 # TODO(sra): Use separate mixins for typed array implementations of List<T>.
2005 template_file = 'immutable_list_mixin.darttemplate'
2006 template = self._system._templates.Load(template_file)
2007 self._members_emitter.Emit(template, E=element_type)
2008
2009 1995
2010 def AddTypedArrayConstructors(self, element_type): 1996 def AddTypedArrayConstructors(self, element_type):
2011 self._members_emitter.Emit( 1997 self._members_emitter.Emit(
2012 '\n' 1998 '\n'
2013 ' factory $CTOR(int length) => _construct(length);\n' 1999 ' factory $CTOR(int length) => _construct(length);\n'
2014 '\n' 2000 '\n'
2015 ' factory $CTOR.fromList(List<$TYPE> list) => _construct(list);\n' 2001 ' factory $CTOR.fromList(List<$TYPE> list) => _construct(list);\n'
2016 '\n' 2002 '\n'
2017 ' factory $CTOR.fromBuffer(ArrayBuffer buffer) => _construct(buffer);\n ' 2003 ' factory $CTOR.fromBuffer(ArrayBuffer buffer) => _construct(buffer);\n '
2018 '\n' 2004 '\n'
2019 ' static _construct(arg) native \'return new $CTOR(arg);\';\n', 2005 ' static _construct(arg) native \'return new $CTOR(arg);\';\n',
2020 CTOR=self._interface.id, 2006 CTOR=self._interface.id,
2021 TYPE=element_type) 2007 TYPE=element_type)
2022 2008
2023 2009
2024 def AddOperation(self, info): 2010 def AddOperation(self, info):
2025 """ 2011 """
2026 Arguments: 2012 Arguments:
2027 info: An OperationInfo object. 2013 info: An OperationInfo object.
2028 """ 2014 """
2029 # TODO(vsm): Handle overloads. 2015 # TODO(vsm): Handle overloads.
2030 self._members_emitter.Emit( 2016 self._members_emitter.Emit(
2031 '\n' 2017 '\n'
2032 ' $TYPE $NAME($PARAMS) native;\n', 2018 ' $TYPE $NAME($PARAMS) native;\n',
2033 TYPE=self._NarrowOutputType(info.type_name), 2019 TYPE=self._NarrowOutputType(info.type_name),
2034 NAME=info.name, 2020 NAME=info.name,
2035 PARAMS=info.ParametersImplementationDeclaration( 2021 PARAMS=info.ParametersImplementationDeclaration(
2036 lambda type_name: self._NarrowInputType(type_name))) 2022 lambda type_name: self._NarrowInputType(type_name)))
OLDNEW
« no previous file with comments | « client/dom/generated/src/frog/Uint8Array.dart ('k') | client/dom/src/_Lists.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698