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

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

Powered by Google App Engine
This is Rietveld 408576698