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

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

Issue 8569017: Generate constructors for frog DOM (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Refresh the single file version Created 9 years, 1 month 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) 2011, the Dart project authors. Please see the AUTHORS file 2 # Copyright (c) 2011, 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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 # 58 #
59 _evasive_types = set(['CanvasPixelArray', 59 _evasive_types = set(['CanvasPixelArray',
60 'ImageData', # Not really unreachable, testing multi-hop 60 'ImageData', # Not really unreachable, testing multi-hop
61 'Notification', 61 'Notification',
62 'NotificationCenter', 62 'NotificationCenter',
63 'TouchList', 63 'TouchList',
64 'Touch' 64 'Touch'
65 ]) 65 ])
66 66
67 # 67 #
68 # Types with user-invocable constructors. We do not have enough
69 # information in IDL to create the signature.
70 #
71 # Each entry is of the form:
72 # type name: constructor parameters
73 _constructable_types = {
74 'FileReader': '',
75 'XMLHttpRequest': '',
76 'WebKitCSSMatrix': '[String spec]',
77 'WebKitPoint': 'num x, num y',
78 # dart:html types
79 'CSSMatrix': '[String spec]',
80 'Point': 'num x, num y',
81 }
82
83 #
68 # Custom methods that must be implemented by hand. 84 # Custom methods that must be implemented by hand.
69 # 85 #
70 _custom_methods = set([ 86 _custom_methods = set([
71 ('DOMWindow', 'setInterval'), 87 ('DOMWindow', 'setInterval'),
72 ('DOMWindow', 'setTimeout'), 88 ('DOMWindow', 'setTimeout'),
73 ('WorkerContext', 'setInterval'), 89 ('WorkerContext', 'setInterval'),
74 ('WorkerContext', 'setTimeout'), 90 ('WorkerContext', 'setTimeout'),
75 ('CanvasRenderingContext2D', 'setFillStyle'), 91 ('CanvasRenderingContext2D', 'setFillStyle'),
76 ('CanvasRenderingContext2D', 'setStrokeStyle'), 92 ('CanvasRenderingContext2D', 'setStrokeStyle'),
77 ('CanvasRenderingContext2D', 'setFillStyle'), 93 ('CanvasRenderingContext2D', 'setFillStyle'),
(...skipping 11 matching lines...) Expand all
89 # browsers, but are otherwise identical. The alternates are tried in order and 105 # browsers, but are otherwise identical. The alternates are tried in order and
90 # the first one defined is used. 106 # the first one defined is used.
91 # 107 #
92 # This can be probably be removed when Chrome renames initWebKitWheelEvent to 108 # This can be probably be removed when Chrome renames initWebKitWheelEvent to
93 # initWheelEvent. 109 # initWheelEvent.
94 # 110 #
95 _alternate_methods = { 111 _alternate_methods = {
96 ('WheelEvent', 'initWheelEvent'): ['initWebKitWheelEvent', 'initWheelEvent'] 112 ('WheelEvent', 'initWheelEvent'): ['initWebKitWheelEvent', 'initWheelEvent']
97 } 113 }
98 114
99
100 def _MatchSourceFilter(filter, thing): 115 def _MatchSourceFilter(filter, thing):
101 if not filter: 116 if not filter:
102 return True 117 return True
103 else: 118 else:
104 return any(token in thing.annotations for token in filter) 119 return any(token in thing.annotations for token in filter)
105 120
106 def _IsDartListType(type): 121 def _IsDartListType(type):
107 return type == 'List' or type.startswith('List<') 122 return type == 'List' or type.startswith('List<')
108 123
109 def _IsDartCollectionType(type): 124 def _IsDartCollectionType(type):
(...skipping 1796 matching lines...) Expand 10 before | Expand all | Expand 10 after
1906 if not [op for op in interface.operations if op.id == 'addEventListener' ]: 1921 if not [op for op in interface.operations if op.id == 'addEventListener' ]:
1907 base = self._ImplClassName(supertype) 1922 base = self._ImplClassName(supertype)
1908 else: 1923 else:
1909 base = self._ImplClassName(supertype) 1924 base = self._ImplClassName(supertype)
1910 1925
1911 if base: 1926 if base:
1912 extends = " extends " + base 1927 extends = " extends " + base
1913 else: 1928 else:
1914 extends = "" 1929 extends = ""
1915 1930
1931 if interface_name in _constructable_types.keys():
1932 parameters = _constructable_types[interface_name]
1933 constructor = ' %s(%s) native;\n\n' % (interface_name, parameters)
1934 else:
1935 constructor = ''
1936
1916 (self._members_emitter, self._base_emitter) = self._dart_code.Emit( 1937 (self._members_emitter, self._base_emitter) = self._dart_code.Emit(
1917 '\n' 1938 '\n'
1918 'class $CLASS$BASE native "$CLASS" {\n' 1939 'class $CLASS$BASE native "$CLASS" {\n'
1919 '$!MEMBERS' 1940 '$CONSTRUCTOR$!MEMBERS'
1920 '$!ADDITIONS' 1941 '$!ADDITIONS'
1921 '}\n', 1942 '}\n',
1922 CLASS=self._class_name, BASE=extends, INTERFACE=interface_name) 1943 CLASS=self._class_name, BASE=extends,
1944 INTERFACE=interface_name, CONSTRUCTOR=constructor)
1923 1945
1924 if not base: 1946 if not base:
1925 # Emit shared base functionality here as we have no common base type. 1947 # Emit shared base functionality here as we have no common base type.
1926 self._base_emitter.Emit( 1948 self._base_emitter.Emit(
1927 '\n' 1949 '\n'
1928 ' var dartObjectLocalStorage;\n' 1950 ' var dartObjectLocalStorage;\n'
1929 '\n' 1951 '\n'
1930 ' String get typeName() native;\n') 1952 ' String get typeName() native;\n')
1931 1953
1932 def _ImplClassName(self, type_name): 1954 def _ImplClassName(self, type_name):
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
1998 Arguments: 2020 Arguments:
1999 info: An OperationInfo object. 2021 info: An OperationInfo object.
2000 """ 2022 """
2001 # TODO(vsm): Handle overloads. 2023 # TODO(vsm): Handle overloads.
2002 self._members_emitter.Emit( 2024 self._members_emitter.Emit(
2003 '\n' 2025 '\n'
2004 ' $TYPE $NAME($ARGS) native;\n', 2026 ' $TYPE $NAME($ARGS) native;\n',
2005 TYPE=info.type_name, 2027 TYPE=info.type_name,
2006 NAME=info.name, 2028 NAME=info.name,
2007 ARGS=info.arg_implementation_declaration) 2029 ARGS=info.arg_implementation_declaration)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698