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

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

Issue 11026039: Refactor idl to dart renaming logic for interfaces. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: . Created 8 years, 2 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/html/scripts/generator.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 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 import emitter 9 import emitter
10 import os 10 import os
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 info.name = interface_name 76 info.name = interface_name
77 info.constructor_name = self.name 77 info.constructor_name = self.name
78 info.js_name = None 78 info.js_name = None
79 info.type_name = interface_name 79 info.type_name = interface_name
80 info.param_infos = map(lambda tXn: ParamInfo(tXn[1], None, tXn[0], 'null'), 80 info.param_infos = map(lambda tXn: ParamInfo(tXn[1], None, tXn[0], 'null'),
81 self.opt_params) 81 self.opt_params)
82 return info 82 return info
83 83
84 _html_element_constructors = { 84 _html_element_constructors = {
85 'AnchorElement' : 85 'AnchorElement' :
86 ElementConstructorInfo(tag='a', opt_params=[('String', 'href')]), 86 ElementConstructorInfo(tag='a', opt_params=[('DOMString', 'href')]),
87 'AreaElement': 'area', 87 'AreaElement': 'area',
88 'ButtonElement': 'button', 88 'ButtonElement': 'button',
89 'BRElement': 'br', 89 'BRElement': 'br',
90 'BaseElement': 'base', 90 'BaseElement': 'base',
91 'BodyElement': 'body', 91 'BodyElement': 'body',
92 'ButtonElement': 'button', 92 'ButtonElement': 'button',
93 'CanvasElement': 93 'CanvasElement':
94 ElementConstructorInfo(tag='canvas', 94 ElementConstructorInfo(tag='canvas',
95 opt_params=[('int', 'width'), ('int', 'height')]), 95 opt_params=[('int', 'width'), ('int', 'height')]),
96 'ContentElement': 'content', 96 'ContentElement': 'content',
97 'DataListElement': 'datalist', 97 'DataListElement': 'datalist',
98 'DListElement': 'dl', 98 'DListElement': 'dl',
99 'DetailsElement': 'details', 99 'DetailsElement': 'details',
100 'DivElement': 'div', 100 'DivElement': 'div',
101 'EmbedElement': 'embed', 101 'EmbedElement': 'embed',
102 'FieldSetElement': 'fieldset', 102 'FieldSetElement': 'fieldset',
103 'FormElement': 'form', 103 'FormElement': 'form',
104 'HRElement': 'hr', 104 'HRElement': 'hr',
105 'HeadElement': 'head', 105 'HeadElement': 'head',
106 'HeadingElement': [ElementConstructorInfo('h1'), 106 'HeadingElement': [ElementConstructorInfo('h1'),
107 ElementConstructorInfo('h2'), 107 ElementConstructorInfo('h2'),
108 ElementConstructorInfo('h3'), 108 ElementConstructorInfo('h3'),
109 ElementConstructorInfo('h4'), 109 ElementConstructorInfo('h4'),
110 ElementConstructorInfo('h5'), 110 ElementConstructorInfo('h5'),
111 ElementConstructorInfo('h6')], 111 ElementConstructorInfo('h6')],
112 'HtmlElement': 'html', 112 'HtmlElement': 'html',
113 'IFrameElement': 'iframe', 113 'IFrameElement': 'iframe',
114 'ImageElement': 114 'ImageElement':
115 ElementConstructorInfo(tag='img', 115 ElementConstructorInfo(tag='img',
116 opt_params=[('String', 'src'), 116 opt_params=[('DOMString', 'src'),
117 ('int', 'width'), ('int', 'height')]), 117 ('int', 'width'), ('int', 'height')]),
118 'InputElement': 118 'InputElement':
119 ElementConstructorInfo(tag='input', opt_params=[('String', 'type')]), 119 ElementConstructorInfo(tag='input', opt_params=[('DOMString', 'type')]),
120 'KeygenElement': 'keygen', 120 'KeygenElement': 'keygen',
121 'LIElement': 'li', 121 'LIElement': 'li',
122 'LabelElement': 'label', 122 'LabelElement': 'label',
123 'LegendElement': 'legend', 123 'LegendElement': 'legend',
124 'LinkElement': 'link', 124 'LinkElement': 'link',
125 'MapElement': 'map', 125 'MapElement': 'map',
126 'MenuElement': 'menu', 126 'MenuElement': 'menu',
127 'MeterElement': 'meter', 127 'MeterElement': 'meter',
128 'OListElement': 'ol', 128 'OListElement': 'ol',
129 'ObjectElement': 'object', 129 'ObjectElement': 'object',
(...skipping 28 matching lines...) Expand all
158 if typename not in _html_element_constructors: 158 if typename not in _html_element_constructors:
159 return [] 159 return []
160 infos = _html_element_constructors[typename] 160 infos = _html_element_constructors[typename]
161 if isinstance(infos, str): 161 if isinstance(infos, str):
162 infos = ElementConstructorInfo(tag=infos) 162 infos = ElementConstructorInfo(tag=infos)
163 if not isinstance(infos, list): 163 if not isinstance(infos, list):
164 infos = [infos] 164 infos = [infos]
165 return infos 165 return infos
166 166
167 def EmitHtmlElementFactoryConstructors(emitter, infos, typename, class_name, 167 def EmitHtmlElementFactoryConstructors(emitter, infos, typename, class_name,
168 dart_type): 168 rename_type):
169 for info in infos: 169 for info in infos:
170 constructor_info = info.ConstructorInfo(typename) 170 constructor_info = info.ConstructorInfo(typename)
171 171
172 inits = emitter.Emit( 172 inits = emitter.Emit(
173 '\n' 173 '\n'
174 ' static $RETURN_TYPE $CONSTRUCTOR($PARAMS) {\n' 174 ' static $RETURN_TYPE $CONSTRUCTOR($PARAMS) {\n'
175 ' $CLASS _e = _document.$dom_createElement("$TAG");\n' 175 ' $CLASS _e = _document.$dom_createElement("$TAG");\n'
176 '$!INITS' 176 '$!INITS'
177 ' return _e;\n' 177 ' return _e;\n'
178 ' }\n', 178 ' }\n',
179 RETURN_TYPE=constructor_info.type_name, 179 RETURN_TYPE=rename_type(constructor_info.type_name),
180 CONSTRUCTOR=constructor_info.ConstructorFactoryName(dart_type), 180 CONSTRUCTOR=constructor_info.ConstructorFactoryName(rename_type),
181 CLASS=class_name, 181 CLASS=class_name,
182 TAG=info.tag, 182 TAG=info.tag,
183 PARAMS=constructor_info.ParametersInterfaceDeclaration(dart_type)) 183 PARAMS=constructor_info.ParametersInterfaceDeclaration(rename_type))
184 for param in constructor_info.param_infos: 184 for param in constructor_info.param_infos:
185 inits.Emit(' if ($E != null) _e.$E = $E;\n', E=param.name) 185 inits.Emit(' if ($E != null) _e.$E = $E;\n', E=param.name)
186 186
187 # ------------------------------------------------------------------------------ 187 # ------------------------------------------------------------------------------
188 188
189 class HtmlDartInterfaceGenerator(object): 189 class HtmlDartInterfaceGenerator(object):
190 """Generates dart interface and implementation for the DOM IDL interface.""" 190 """Generates dart interface and implementation for the DOM IDL interface."""
191 191
192 def __init__(self, options, library_emitter, event_generator, interface, 192 def __init__(self, options, library_emitter, event_generator, interface,
193 backend): 193 backend):
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 self._backend.EmitFactoryProvider( 274 self._backend.EmitFactoryProvider(
275 constructor_info, factory_provider, factory_provider_emitter) 275 constructor_info, factory_provider, factory_provider_emitter)
276 276
277 infos = HtmlElementConstructorInfos(typename) 277 infos = HtmlElementConstructorInfos(typename)
278 if infos: 278 if infos:
279 template = self._template_loader.Load( 279 template = self._template_loader.Load(
280 'factoryprovider_Elements.darttemplate') 280 'factoryprovider_Elements.darttemplate')
281 EmitHtmlElementFactoryConstructors( 281 EmitHtmlElementFactoryConstructors(
282 self._library_emitter.FileEmitter('_Elements', template), 282 self._library_emitter.FileEmitter('_Elements', template),
283 infos, 283 infos,
284 self._html_interface_name, 284 self._interface.id,
285 self._backend.ImplementationClassName(), 285 self._backend.ImplementationClassName(),
286 self._DartType) 286 self._DartType)
287 287
288 for info in infos: 288 for info in infos:
289 constructors.append(info.ConstructorInfo(typename)) 289 constructors.append(info.ConstructorInfo(self._interface.id))
290 if factory_provider: 290 if factory_provider:
291 assert factory_provider == info.factory_provider_name 291 assert factory_provider == info.factory_provider_name
292 else: 292 else:
293 factory_provider = info.factory_provider_name 293 factory_provider = info.factory_provider_name
294 294
295 # TODO(vsm): Add appropriate package / namespace syntax. 295 # TODO(vsm): Add appropriate package / namespace syntax.
296 (self._type_comment_emitter, 296 (self._type_comment_emitter,
297 self._members_emitter, 297 self._members_emitter,
298 self._top_level_emitter) = interface_emitter.Emit( 298 self._top_level_emitter) = interface_emitter.Emit(
299 interface_template + '$!TOP_LEVEL', 299 interface_template + '$!TOP_LEVEL',
(...skipping 592 matching lines...) Expand 10 before | Expand all | Expand 10 after
892 checks = filter(lambda e: e != 'true', checks) 892 checks = filter(lambda e: e != 'true', checks)
893 if checks: 893 if checks:
894 (stmts_emitter, call_emitter) = body.Emit( 894 (stmts_emitter, call_emitter) = body.Emit(
895 ' if ($CHECKS) {\n$!STMTS$!CALL }\n', 895 ' if ($CHECKS) {\n$!STMTS$!CALL }\n',
896 INDENT=' ', 896 INDENT=' ',
897 CHECKS=' &&\n '.join(checks)) 897 CHECKS=' &&\n '.join(checks))
898 else: 898 else:
899 (stmts_emitter, call_emitter) = body.Emit('$!A$!B', INDENT=' '); 899 (stmts_emitter, call_emitter) = body.Emit('$!A$!B', INDENT=' ');
900 900
901 method_version[0] += 1 901 method_version[0] += 1
902 target = '_%s_%d' % (html_name, method_version[0]) 902 target = '_%s_%d' % (html_name, method_version[0]);
903 arguments = [] 903 arguments = []
904 target_parameters = [] 904 target_parameters = []
905 for position, arg in enumerate(operation.arguments[:argument_count]): 905 for position, arg in enumerate(operation.arguments[:argument_count]):
906 conversion = self._InputConversion(arg.type.id, operation.id) 906 conversion = self._InputConversion(arg.type.id, operation.id)
907 param_name = operation.arguments[position].id 907 param_name = operation.arguments[position].id
908 if conversion: 908 if conversion:
909 temp_version[0] += 1 909 temp_version[0] += 1
910 temp_name = '%s_%s' % (param_name, temp_version[0]) 910 temp_name = '%s_%s' % (param_name, temp_version[0])
911 temp_type = conversion.output_type 911 temp_type = conversion.output_type
912 stmts_emitter.Emit( 912 stmts_emitter.Emit(
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
1034 'NodeList'] 1034 'NodeList']
1035 if type_name in do_not_narrow: 1035 if type_name in do_not_narrow:
1036 return False 1036 return False
1037 if self._database.HasInterface(type_name): 1037 if self._database.HasInterface(type_name):
1038 interface = self._database.GetInterface(type_name) 1038 interface = self._database.GetInterface(type_name)
1039 # Callbacks are typedef functions so don't have a class. 1039 # Callbacks are typedef functions so don't have a class.
1040 return 'Callback' not in interface.ext_attrs 1040 return 'Callback' not in interface.ext_attrs
1041 return False 1041 return False
1042 1042
1043 def _NarrowToImplementationType(self, type_name): 1043 def _NarrowToImplementationType(self, type_name):
1044 if type_name == 'Dynamic':
1045 return type_name
1044 if self._ShouldNarrowToImplementationType(type_name): 1046 if self._ShouldNarrowToImplementationType(type_name):
1045 return self._ImplClassName(self._DartType(type_name)) 1047 return self._ImplClassName(self._DartType(type_name))
1046 return self._DartType(type_name) 1048 return self._DartType(type_name)
1047 1049
1048 def _NarrowInputType(self, type_name): 1050 def _NarrowInputType(self, type_name):
1049 return self._NarrowToImplementationType(type_name) 1051 return self._NarrowToImplementationType(type_name)
1050 1052
1051 def _NarrowOutputType(self, type_name): 1053 def _NarrowOutputType(self, type_name):
1052 return self._NarrowToImplementationType(type_name) 1054 return self._NarrowToImplementationType(type_name)
1053 1055
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
1117 1119
1118 library_emitter = self._multiemitter.FileEmitter(library_file_path) 1120 library_emitter = self._multiemitter.FileEmitter(library_file_path)
1119 library_file_dir = os.path.dirname(library_file_path) 1121 library_file_dir = os.path.dirname(library_file_path)
1120 auxiliary_dir = os.path.relpath(auxiliary_dir, library_file_dir) 1122 auxiliary_dir = os.path.relpath(auxiliary_dir, library_file_dir)
1121 imports_emitter = library_emitter.Emit( 1123 imports_emitter = library_emitter.Emit(
1122 self._template, AUXILIARY_DIR=massage_path(auxiliary_dir)) 1124 self._template, AUXILIARY_DIR=massage_path(auxiliary_dir))
1123 for path in sorted(self._path_to_emitter.keys()): 1125 for path in sorted(self._path_to_emitter.keys()):
1124 relpath = os.path.relpath(path, library_file_dir) 1126 relpath = os.path.relpath(path, library_file_dir)
1125 imports_emitter.Emit( 1127 imports_emitter.Emit(
1126 "#source('$PATH');\n", PATH=massage_path(relpath)) 1128 "#source('$PATH');\n", PATH=massage_path(relpath))
OLDNEW
« no previous file with comments | « lib/html/scripts/generator.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698