OLD | NEW |
---|---|
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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
51 'RequestAnimationFrameCallback': 'RequestAnimationFrameCallback', | 51 'RequestAnimationFrameCallback': 'RequestAnimationFrameCallback', |
52 | 52 |
53 # TODO(sra): Flags is really a dictionary: {create:bool, exclusive:bool} | 53 # TODO(sra): Flags is really a dictionary: {create:bool, exclusive:bool} |
54 # http://dev.w3.org/2009/dap/file-system/file-dir-sys.html#the-flags-interfa ce | 54 # http://dev.w3.org/2009/dap/file-system/file-dir-sys.html#the-flags-interfa ce |
55 'WebKitFlags': 'Object', | 55 'WebKitFlags': 'Object', |
56 } | 56 } |
57 | 57 |
58 _dart_to_idl_type_conversions = dict((v,k) for k, v in | 58 _dart_to_idl_type_conversions = dict((v,k) for k, v in |
59 _idl_to_dart_type_conversions.iteritems()) | 59 _idl_to_dart_type_conversions.iteritems()) |
60 | 60 |
61 _private_html_properties = { | |
sra1
2012/02/16 04:43:28
For each of these tables, add a comment saying wha
Jacob
2012/02/17 00:44:23
Done.
| |
62 'Element': set(['clientLeft', 'clientTop', 'clientWidth', 'clientHeight', | |
63 'offsetLeft', 'offsetTop', 'offsetWidth', 'offsetHeight', | |
64 'scrollLeft', 'scrollTop', 'scrollWidth', 'scrollHeight', | |
65 'childElementCount', 'firstElementChild', 'hasAttribute', | |
66 'getAttribute', 'removeAttribute', 'setAttribute', 'className', | |
67 'children']), | |
68 'Node' : set(['appendChild', 'removeChild', 'replaceChild', 'attributes', | |
69 'childNodes']), | |
70 # TODO(jacobr): other direct translate methods on node such as | |
71 # textContext->text | |
72 'Document': set(['createElement', 'createEvent']), | |
73 'Window': set(['getComputedStyle']), | |
74 'EventTarget': set(['removeEventListener', 'addEventListener', | |
75 'dispatchEvent']), | |
76 'Event': set(['initEvent', 'target', 'srcElement', 'currentTarget']) | |
77 } | |
78 | |
79 html_library_renames = { | |
80 'Document.createTextNode': 'Text.Text', | |
81 'Document.get:defaultView': 'Document.get:window', | |
82 'DocumentFragment.querySelector': 'Element.query', | |
83 'Element.querySelector': 'Element.query', | |
84 'Document.querySelector': 'Element.query', | |
85 'DocumentFragment.querySelectorAll': 'Element.queryAll', | |
86 'DocumentFragment.querySelectorAll': 'Element.queryAll', | |
87 'Element.querySelectorAll': 'Element.queryAll', | |
88 'Element.scrollIntoViewIfNeeded': 'Element.scrollIntoView', | |
89 'Node.cloneNode': 'Node.clone', | |
90 'Node.get:nextSibling': 'Node.get:nextNode', | |
91 'Node.get:ownerDocument': 'Node.get:document', | |
92 'Node.get:parentNode': 'Node.get:parent', | |
93 'Node.get:previousSibling': 'Node.get:previousNode', | |
94 } | |
95 | |
96 # TODO(jacobr): cleanup and augment this list. | |
97 _html_library_remove = set([ | |
sra1
2012/02/16 04:43:28
These tables are pretty huge.
Could you get a smal
Jacob
2012/02/17 00:44:23
Done.
| |
98 'Window.get:document', # Removed as we have a custom implementation. | |
99 'NodeList.item', | |
100 "Attr.*", | |
sra1
2012/02/16 04:43:28
Does this work?
Jacob
2012/02/17 00:44:23
Added a TODO. only parts of this table of stuff g
| |
101 # "BarProp.*", | |
102 # "BarInfo.*", | |
103 # "Blob.webkitSlice", | |
104 # "CDATASection.*", | |
105 # "Comment.*", | |
106 # "DOMImplementation.*", | |
107 # TODO(jacobr): listing title here is a temporary hack due to a frog bug | |
108 # involving when an interface inherits from another interface and defines | |
109 # the same field. | |
sra1
2012/02/16 04:43:28
This should be fixed - can you try it?
Jacob
2012/02/17 00:44:23
listed the bug# in the TODO
| |
110 "Document.get:title", | |
111 "Document.set:title", | |
112 "Element.get:title", | |
113 "Element.set:title", | |
114 "Document.get:documentElement", | |
115 "Document.get:forms", | |
116 # "Document.get:selectedStylesheetSet", | |
117 # "Document.set:selectedStylesheetSet", | |
118 # "Document.get:preferredStylesheetSet", | |
119 "Document.get:links", | |
120 "Document.getElementsByTagName", | |
121 "Document.set:domain", | |
122 "Document.get:implementation", | |
123 "Document.createAttributeNS", | |
124 "Document.get:inputEncoding", | |
125 "Document.getElementsByClassName", | |
126 "Document.get:compatMode", | |
127 "Document.importNode", | |
128 "Document.evaluate", | |
129 "Document.get:images", | |
130 "Document.querySelector", | |
131 "Document.createExpression", | |
132 "Document.getOverrideStyle", | |
133 "Document.get:xmlStandalone", | |
134 "Document.set:xmlStandalone", | |
135 "Document.createComment", | |
136 "Document.adoptNode", | |
137 "Document.get:characterSet", | |
138 "Document.createAttribute", | |
139 "Document.querySelectorAll", | |
140 "Document.get:URL", | |
141 "Document.createElementNS", | |
142 "Document.createEntityReference", | |
143 "Document.get:documentURI", | |
144 "Document.set:documentURI", | |
145 "Document.createNodeIterator", | |
146 "Document.createProcessingInstruction", | |
147 "Document.get:doctype", | |
148 "Document.getElementsByName", | |
149 "Document.createTreeWalker", | |
150 "Document.get:location", | |
151 "Document.set:location", | |
152 "Document.createNSResolver", | |
153 "Document.get:xmlEncoding", | |
154 "Document.get:defaultCharset", | |
155 "Document.get:applets", | |
156 "Document.getSelection", | |
157 "Document.get:xmlVersion", | |
158 "Document.set:xmlVersion", | |
159 "Document.get:anchors", | |
160 "Document.getElementsByTagNameNS", | |
161 "DocumentType.*", | |
162 "Element.hasAttributeNS", | |
163 "Element.getAttributeNS", | |
164 "Element.setAttributeNode", | |
165 "Element.getAttributeNode", | |
166 "Element.removeAttributeNode", | |
167 "Element.removeAttributeNS", | |
168 "Element.setAttributeNodeNS", | |
169 "Element.getAttributeNodeNS", | |
170 "Element.setAttributeNS", | |
171 # "EventSource.get:url", | |
172 # TODO(jacobr): should these be removed? | |
173 "Document.close", | |
174 "Document.hasFocus", | |
175 | |
176 "Document.get:vlinkColor", | |
177 "Document.set:vlinkColor", | |
178 "Document.captureEvents", | |
179 "Document.releaseEvents", | |
180 "Document.get:compatMode", | |
181 "Document.get:designMode", | |
182 "Document.set:designMode", | |
183 "Document.get:dir", | |
184 "Document.set:dir", | |
185 "Document.get:all", | |
186 "Document.set:all", | |
187 "Document.write", | |
188 "Document.get:fgColor", | |
189 "Document.set:fgColor", | |
190 "Document.get:bgColor", | |
191 "Document.set:bgColor", | |
192 "Document.get:plugins", | |
193 "Document.get:alinkColor", | |
194 "Document.set:alinkColor", | |
195 "Document.get:embeds", | |
196 "Document.open", | |
197 "Document.clear", | |
198 "Document.get:scripts", | |
199 "Document.writeln", | |
200 "Document.get:linkColor", | |
201 "Document.set:linkColor", | |
202 "Element.get:itemRef", | |
203 "Element.set:className", | |
204 "Element.get:outerText", | |
205 "Element.set:outerText", | |
206 "Element.get:accessKey", | |
207 "Element.set:accessKey", | |
208 "Element.get:itemType", | |
209 "Element.get:innerText", | |
210 "Element.set:innerText", | |
211 "Element.set:outerHTML", | |
212 "Element.get:itemScope", | |
213 "Element.set:itemScope", | |
214 "Element.get:itemValue", | |
215 "Element.set:itemValue", | |
216 "Element.get:itemId", | |
217 "Element.set:itemId", | |
218 "Element.get:itemProp", | |
219 "EmbedElement.getSVGDocument", | |
220 "FormElement.get:elements", | |
221 "HTMLFrameElement.*", | |
222 "HTMLFrameSetElement.*", | |
223 "HTMLHtmlElement.get:version", | |
224 "HTMLHtmlElement.set:version", | |
225 # "IFrameElement.getSVGDocument", #TODO(jacobr): should this be removed | |
226 "InputElement.get:dirName", | |
227 "InputElement.set:dirName", | |
228 "HTMLIsIndexElement.*", | |
229 "ObjectElement.getSVGDocument", | |
230 "HTMLOptionsCollection.*", | |
231 "HTMLPropertiesCollection.*", | |
232 "SelectElement.remove", | |
233 "TextAreaElement.get:dirName", | |
234 "TextAreaElement.set:dirName", | |
235 "NamedNodeMap.*", | |
236 "Node.isEqualNode", | |
237 "Node.get:TEXT_NODE", | |
238 "Node.hasAttributes", | |
239 "Node.get:DOCUMENT_TYPE_NODE", | |
240 "Node.get:DOCUMENT_POSITION_FOLLOWING", | |
241 "Node.get:childNodes", | |
242 "Node.lookupNamespaceURI", | |
243 "Node.get:ELEMENT_NODE", | |
244 "Node.get:namespaceURI", | |
245 "Node.get:DOCUMENT_FRAGMENT_NODE", | |
246 "Node.get:localName", | |
247 "Node.dispatchEvent", | |
248 "Node.isDefaultNamespace", | |
249 "Node.compareDocumentPosition", | |
250 "Node.get:baseURI", | |
251 "Node.isSameNode", | |
252 "Node.get:DOCUMENT_POSITION_DISCONNECTED", | |
253 "Node.get:DOCUMENT_NODE", | |
254 "Node.get:DOCUMENT_POSITION_CONTAINS", | |
255 "Node.get:COMMENT_NODE", | |
256 "Node.get:ENTITY_REFERENCE_NODE", | |
257 "Node.isSupported", | |
258 "Node.get:firstChild", | |
259 "Node.get:DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC", | |
260 "Node.get:lastChild", | |
261 "Node.get:attributes", | |
262 "Node.get:NOTATION_NODE", | |
263 "Node.normalize", | |
264 "Node.get:parentElement", | |
265 "Node.get:ATTRIBUTE_NODE", | |
266 "Node.get:ENTITY_NODE", | |
267 "Node.get:DOCUMENT_POSITION_CONTAINED_BY", | |
268 "Node.get:prefix", | |
269 "Node.set:prefix", | |
270 "Node.get:DOCUMENT_POSITION_PRECEDING", | |
271 "Node.get:nodeType", | |
272 "Node.removeEventListener", | |
273 "Node.get:nodeValue", | |
274 "Node.set:nodeValue", | |
275 "Node.get:CDATA_SECTION_NODE", | |
276 "Node.get:nodeName", | |
277 "Node.addEventListener", | |
278 "Node.lookupPrefix", | |
279 "Node.get:PROCESSING_INSTRUCTION_NODE", | |
280 "Notification.dispatchEvent", | |
281 "Notification.addEventListener", | |
282 "Notification.removeEventListener"]) | |
283 | |
284 # Events without onEventName attributes in the IDL we want to support. | |
285 _html_manual_events = { | |
286 'Element': ['touchleave', 'webkitTransitionEnd'], | |
287 'Window': ['DOMContentLoaded'] | |
288 } | |
289 | |
290 # Sadly these event names must be camel case when attaching event listeners | |
291 # using addEventListener even though the onEventName properties in the DOM for | |
292 # them are not camel case. | |
293 _on_attribute_to_event_name_mapping = { | |
294 'webkitanimationend': 'webkitAnimationEnd', | |
295 'webkitanimationiteration': 'webkitAnimationIteration', | |
296 'webkitanimationstart': 'webkitAnimationStart', | |
297 'webkitfullscreenchange': 'webkitFullScreenChange', | |
298 'webkitfullscreenerror': 'webkitFullScreenError', | |
299 'webkitspeechchange': 'webkitSpeechChange', | |
300 'webkittransitionend': 'webkitTransitionEnd', | |
301 } | |
302 | |
303 _html_event_names = { | |
304 'DOMContentLoaded': 'contentLoaded', | |
305 'touchleave': 'touchLeave', | |
306 'abort': 'abort', | |
307 'beforecopy': 'beforeCopy', | |
308 'beforecut': 'beforeCut', | |
309 'beforepaste': 'beforePaste', | |
310 'beforeunload': 'beforeUnload', | |
311 'blur': 'blur', | |
312 'cached': 'cached', | |
313 'canplay': 'canPlay', | |
314 'canplaythrough': 'canPlayThrough', | |
315 'change': 'change', | |
316 'checking': 'checking', | |
317 'click': 'click', | |
318 'close': 'close', | |
319 'contextmenu': 'contextMenu', | |
320 'copy': 'copy', | |
321 'cut': 'cut', | |
322 'dblclick': 'doubleClick', | |
323 'devicemotion': 'deviceMotion', | |
324 'deviceorientation': 'deviceOrientation', | |
325 'display': 'display', | |
326 'downloading': 'downloading', | |
327 'drag': 'drag', | |
328 'dragend': 'dragEnd', | |
329 'dragenter': 'dragEnter', | |
330 'dragleave': 'dragLeave', | |
331 'dragover': 'dragOver', | |
332 'dragstart': 'dragStart', | |
333 'drop': 'drop', | |
334 'durationchange': 'durationChange', | |
335 'emptied': 'emptied', | |
336 'ended': 'ended', | |
337 'error': 'error', | |
338 'focus': 'focus', | |
339 'hashchange': 'hashChange', | |
340 'input': 'input', | |
341 'invalid': 'invalid', | |
342 'keydown': 'keyDown', | |
343 'keypress': 'keyPress', | |
344 'keyup': 'keyUp', | |
345 'load': 'load', | |
346 'loadeddata': 'loadedData', | |
347 'loadedmetadata': 'loadedMetadata', | |
348 'loadend': 'loadEnd', | |
349 'loadstart': 'loadStart', | |
350 'message': 'message', | |
351 'mousedown': 'mouseDown', | |
352 'mousemove': 'mouseMove', | |
353 'mouseout': 'mouseOut', | |
354 'mouseover': 'mouseOver', | |
355 'mouseup': 'mouseUp', | |
356 'mousewheel': 'mouseWheel', | |
357 'noupdate': 'noUpdate', | |
358 'obsolete': 'obsolete', | |
359 'offline': 'offline', | |
360 'online': 'online', | |
361 'open': 'open', | |
362 'pagehide': 'pageHide', | |
363 'pageshow': 'pageShow', | |
364 'paste': 'paste', | |
365 'pause': 'pause', | |
366 'play': 'play', | |
367 'playing': 'playing', | |
368 'popstate': 'popState', | |
369 'progress': 'progress', | |
370 'ratechange': 'rateChange', | |
371 'readystatechange': 'readyStateChange', | |
372 'reset': 'reset', | |
373 'resize': 'resize', | |
374 'scroll': 'scroll', | |
375 'search': 'search', | |
376 'seeked': 'seeked', | |
377 'seeking': 'seeking', | |
378 'select': 'select', | |
379 'selectionchange': 'selectionChange', | |
380 'selectstart': 'selectStart', | |
381 'show': 'show', | |
382 'stalled': 'stalled', | |
383 'storage': 'storage', | |
384 'submit': 'submit', | |
385 'suspend': 'suspend', | |
386 'timeupdate': 'timeUpdate', | |
387 'touchcancel': 'touchCancel', | |
388 'touchend': 'touchEnd', | |
389 'touchmove': 'touchMove', | |
390 'touchstart': 'touchStart', | |
391 'unload': 'unload', | |
392 'updateready': 'updateReady', | |
393 'volumechange': 'volumeChange', | |
394 'waiting': 'waiting', | |
395 'webkitAnimationEnd': 'animationEnd', | |
396 'webkitAnimationIteration': 'animationIteration', | |
397 'webkitAnimationStart': 'animationStart', | |
398 'webkitFullScreenChange': 'fullScreenChange', | |
399 'webkitFullScreenError': 'fullScreenError', | |
400 'webkitSpeechChange': 'speechChange', | |
401 'webkitTransitionEnd': 'transitionEnd' | |
402 } | |
61 | 403 |
62 # | 404 # |
63 # Identifiers that are used in the IDL than need to be treated specially because | 405 # Identifiers that are used in the IDL than need to be treated specially because |
64 # *some* JavaScript processors forbid them as properties. | 406 # *some* JavaScript processors forbid them as properties. |
65 # | 407 # |
66 _javascript_keywords = ['delete', 'continue'] | 408 _javascript_keywords = ['delete', 'continue'] |
67 | 409 |
68 # | 410 # |
69 # Interface version of the DOM needs to delegate typed array constructors to a | 411 # Interface version of the DOM needs to delegate typed array constructors to a |
70 # factory provider. | 412 # factory provider. |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
118 # browsers, but are otherwise identical. The alternates are tried in order and | 460 # browsers, but are otherwise identical. The alternates are tried in order and |
119 # the first one defined is used. | 461 # the first one defined is used. |
120 # | 462 # |
121 # This can be probably be removed when Chrome renames initWebKitWheelEvent to | 463 # This can be probably be removed when Chrome renames initWebKitWheelEvent to |
122 # initWheelEvent. | 464 # initWheelEvent. |
123 # | 465 # |
124 _alternate_methods = { | 466 _alternate_methods = { |
125 ('WheelEvent', 'initWheelEvent'): ['initWebKitWheelEvent', 'initWheelEvent'] | 467 ('WheelEvent', 'initWheelEvent'): ['initWebKitWheelEvent', 'initWheelEvent'] |
126 } | 468 } |
127 | 469 |
470 def _OnAttributeToEventName(on_method): | |
471 event_name = on_method.id[2:] | |
472 if event_name in _on_attribute_to_event_name_mapping: | |
473 return _on_attribute_to_event_name_mapping[event_name] | |
474 else: | |
475 return event_name | |
128 | 476 |
129 def _MatchSourceFilter(filter, thing): | 477 def _MatchSourceFilter(filter, thing): |
130 if not filter: | 478 if not filter: |
131 return True | 479 return True |
132 else: | 480 else: |
133 return any(token in thing.annotations for token in filter) | 481 return any(token in thing.annotations for token in filter) |
134 | 482 |
135 def _IsDartListType(type): | 483 def _IsDartListType(type): |
136 return type == 'List' or type.startswith('List<') | 484 return type == 'List' or type.startswith('List<') |
137 | 485 |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
196 return None | 544 return None |
197 | 545 |
198 def LoadAuxiliary(self): | 546 def LoadAuxiliary(self): |
199 def Visitor(_, dirname, names): | 547 def Visitor(_, dirname, names): |
200 for name in names: | 548 for name in names: |
201 if name.endswith('.dart'): | 549 if name.endswith('.dart'): |
202 name = name[0:-5] # strip off ".dart" | 550 name = name[0:-5] # strip off ".dart" |
203 self._auxiliary_files[name] = os.path.join(dirname, name) | 551 self._auxiliary_files[name] = os.path.join(dirname, name) |
204 os.path.walk(self._auxiliary_dir, Visitor, None) | 552 os.path.walk(self._auxiliary_dir, Visitor, None) |
205 | 553 |
206 def RenameTypes(self, database, conversion_table=None): | 554 def RenameTypes(self, database, conversion_table, rename_native_names): |
207 """Renames interfaces using the given conversion table. | 555 """Renames interfaces using the given conversion table. |
208 | 556 |
209 References through all interfaces will be renamed as well. | 557 References through all interfaces will be renamed as well. |
210 | 558 |
211 Args: | 559 Args: |
212 database: the database to apply the renames to. | 560 database: the database to apply the renames to. |
213 conversion_table: maps old names to new names. | 561 conversion_table: maps old names to new names. |
214 """ | 562 """ |
215 | 563 |
216 if conversion_table is None: | 564 if conversion_table is None: |
217 conversion_table = {} | 565 conversion_table = {} |
218 | 566 |
219 # Rename interfaces: | 567 # Rename interfaces: |
220 for old_name, new_name in conversion_table.items(): | 568 for old_name, new_name in conversion_table.items(): |
221 if database.HasInterface(old_name): | 569 if database.HasInterface(old_name): |
222 _logger.info('renaming interface %s to %s' % | 570 _logger.info('renaming interface %s to %s' % (old_name, new_name)) |
223 (old_name, new_name)) | |
224 interface = database.GetInterface(old_name) | 571 interface = database.GetInterface(old_name) |
225 database.DeleteInterface(old_name) | 572 database.DeleteInterface(old_name) |
226 if not database.HasInterface(new_name): | 573 if not database.HasInterface(new_name): |
227 interface.id = new_name | 574 interface.id = new_name |
228 database.AddInterface(interface) | 575 database.AddInterface(interface) |
229 | 576 else: |
577 new_interface = database.GetInterface(new_name) | |
578 new_interface.merge(interface) | |
579 | |
580 interface.native_name = (old_name if rename_native_names | |
581 else new_name) | |
582 | |
230 # Fix references: | 583 # Fix references: |
231 for interface in database.GetInterfaces(): | 584 for interface in database.GetInterfaces(): |
232 for idl_type in interface.all(idlnode.IDLType): | 585 for idl_type in interface.all(idlnode.IDLType): |
233 type_name = self._StripModules(idl_type.id) | 586 type_name = self._StripModules(idl_type.id) |
234 if type_name in conversion_table: | 587 if type_name in conversion_table: |
235 idl_type.id = conversion_table[type_name] | 588 idl_type.id = conversion_table[type_name] |
236 | 589 |
237 def FilterMembersWithUnidentifiedTypes(self, database): | 590 def FilterMembersWithUnidentifiedTypes(self, database): |
238 """Removes unidentified types. | 591 """Removes unidentified types. |
239 | 592 |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
342 interface.parents = filter(HasAnnotations, interface.parents) | 695 interface.parents = filter(HasAnnotations, interface.parents) |
343 else: | 696 else: |
344 database.DeleteInterface(interface.id) | 697 database.DeleteInterface(interface.id) |
345 | 698 |
346 self.FilterMembersWithUnidentifiedTypes(database) | 699 self.FilterMembersWithUnidentifiedTypes(database) |
347 | 700 |
348 | 701 |
349 def Generate(self, database, output_dir, | 702 def Generate(self, database, output_dir, |
350 module_source_preference=[], source_filter=None, | 703 module_source_preference=[], source_filter=None, |
351 super_database=None, common_prefix=None, super_map={}, | 704 super_database=None, common_prefix=None, super_map={}, |
352 lib_dir=None, systems=[]): | 705 html_map={}, lib_dir=None, systems=[], |
706 generate_html_systems=False): | |
sra1
2012/02/16 04:43:28
We are passing 'systems' and 'generate_html_system
Jacob
2012/02/17 00:44:23
done
| |
353 """Generates Dart and JS files for the loaded interfaces. | 707 """Generates Dart and JS files for the loaded interfaces. |
354 | 708 |
355 Args: | 709 Args: |
356 database -- database containing interfaces to generate code for. | 710 database -- database containing interfaces to generate code for. |
357 output_dir -- directory to write generated files to. | 711 output_dir -- directory to write generated files to. |
358 module_source_preference -- priority order list of source annotations to | 712 module_source_preference -- priority order list of source annotations to |
359 use when choosing a module name, if none specified uses the module name | 713 use when choosing a module name, if none specified uses the module name |
360 from the database. | 714 from the database. |
361 source_filter -- if specified, only outputs interfaces that have one of | 715 source_filter -- if specified, only outputs interfaces that have one of |
362 these source annotation and rewrites the names of superclasses not | 716 these source annotation and rewrites the names of superclasses not |
363 marked with this source to use the common prefix. | 717 marked with this source to use the common prefix. |
364 super_database -- database containing super interfaces that the generated | 718 super_database -- database containing super interfaces that the generated |
365 interfaces should extend. | 719 interfaces should extend. |
366 common_prefix -- prefix for the common library, if any. | 720 common_prefix -- prefix for the common library, if any. |
367 lib_file_path -- filename for generated .lib file, None if not required. | 721 lib_file_path -- filename for generated .lib file, None if not required. |
368 lib_template -- template file in this directory for generated lib file. | 722 lib_template -- template file in this directory for generated lib file. |
369 """ | 723 """ |
370 | 724 |
371 self._emitters = multiemitter.MultiEmitter() | 725 self._emitters = multiemitter.MultiEmitter() |
372 self._database = database | 726 self._database = database |
373 self._output_dir = output_dir | 727 self._output_dir = output_dir |
374 | 728 |
375 self._ComputeInheritanceClosure() | 729 self._ComputeInheritanceClosure() |
376 | 730 |
377 self._systems = [] | 731 self._systems = [] |
378 | 732 |
379 # TODO(jmesserly): only create these if needed | 733 # TODO(jmesserly): only create these if needed |
380 interface_system = InterfacesSystem( | 734 if not generate_html_systems: |
381 TemplateLoader(self._template_dir, ['dom/interface', 'dom', '']), | 735 interface_system = InterfacesSystem( |
382 self._database, self._emitters, self._output_dir) | 736 TemplateLoader(self._template_dir, ['dom/interface', 'dom', '']), |
383 self._systems.append(interface_system) | 737 self._database, self._emitters, self._output_dir) |
738 self._systems.append(interface_system) | |
384 | 739 |
385 html_interface_system = HtmlInterfacesSystem( | 740 html_interface_system = HtmlInterfacesSystem( |
sra1
2012/02/16 04:43:28
Is this needed when 'not generate_html_systems' is
Jacob
2012/02/17 00:44:23
Nope. Done.
| |
386 TemplateLoader(self._template_dir, ['html/interface', 'html', '']), | 741 TemplateLoader(self._template_dir, ['html/interface', 'html', '']), |
387 self._database, self._emitters, self._output_dir) | 742 self._database, self._emitters, self._output_dir, self) |
388 self._systems.append(html_interface_system) | 743 self._systems.append(html_interface_system) |
389 | 744 |
390 if 'native' in systems: | 745 if 'native' in systems: |
391 native_system = NativeImplementationSystem( | 746 native_system = NativeImplementationSystem( |
392 TemplateLoader(self._template_dir, ['dom/native', 'dom', '']), | 747 TemplateLoader(self._template_dir, ['dom/native', 'dom', '']), |
393 self._database, self._emitters, self._auxiliary_dir, | 748 self._database, self._emitters, self._auxiliary_dir, |
394 self._output_dir) | 749 self._output_dir) |
395 | 750 |
396 self._systems.append(native_system) | 751 self._systems.append(native_system) |
397 | 752 |
(...skipping 21 matching lines...) Expand all Loading... | |
419 frog_system = FrogSystem( | 774 frog_system = FrogSystem( |
420 TemplateLoader(self._template_dir, ['dom/frog', 'dom', '']), | 775 TemplateLoader(self._template_dir, ['dom/frog', 'dom', '']), |
421 self._database, self._emitters, self._output_dir) | 776 self._database, self._emitters, self._output_dir) |
422 | 777 |
423 frog_system._interface_system = interface_system | 778 frog_system._interface_system = interface_system |
424 self._systems.append(frog_system) | 779 self._systems.append(frog_system) |
425 | 780 |
426 if 'htmlfrog' in systems: | 781 if 'htmlfrog' in systems: |
427 html_system = HtmlFrogSystem( | 782 html_system = HtmlFrogSystem( |
428 TemplateLoader(self._template_dir, ['html/frog', 'html', '']), | 783 TemplateLoader(self._template_dir, ['html/frog', 'html', '']), |
429 self._database, self._emitters, self._output_dir) | 784 self._database, self._emitters, self._output_dir, self) |
430 | 785 |
431 html_system._interface_system = html_interface_system | 786 html_system._interface_system = html_interface_system |
432 self._systems.append(html_system) | 787 self._systems.append(html_system) |
433 | 788 |
434 if 'htmldartium' in systems: | 789 if 'htmldartium' in systems: |
435 html_system = HtmlDartiumSystem( | 790 html_system = HtmlDartiumSystem( |
436 TemplateLoader(self._template_dir, ['html/dartium', 'html', '']), | 791 TemplateLoader(self._template_dir, ['html/dartium', 'html', '']), |
437 self._database, self._emitters, self._output_dir) | 792 self._database, self._emitters, self._output_dir, self) |
438 | 793 |
439 html_system._interface_system = html_interface_system | 794 html_system._interface_system = html_interface_system |
440 self._systems.append(html_system) | 795 self._systems.append(html_system) |
441 | 796 |
442 | |
443 # Collect interfaces | 797 # Collect interfaces |
444 interfaces = [] | 798 interfaces = [] |
445 for interface in database.GetInterfaces(): | 799 for interface in database.GetInterfaces(): |
446 if not _MatchSourceFilter(source_filter, interface): | 800 if not _MatchSourceFilter(source_filter, interface): |
447 # Skip this interface since it's not present in the required source | 801 # Skip this interface since it's not present in the required source |
448 _logger.info('Omitting interface - %s' % interface.id) | 802 _logger.info('Omitting interface - %s' % interface.id) |
449 continue | 803 continue |
450 interfaces.append(interface) | 804 interfaces.append(interface) |
451 | 805 |
452 # TODO(sra): Use this list of exception names to generate information to | 806 # TODO(sra): Use this list of exception names to generate information to |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
532 for const in sorted(interface.constants, ConstantOutputOrder): | 886 for const in sorted(interface.constants, ConstantOutputOrder): |
533 for generator in generators: | 887 for generator in generators: |
534 generator.AddConstant(const) | 888 generator.AddConstant(const) |
535 | 889 |
536 attributes = [attr for attr in interface.attributes | 890 attributes = [attr for attr in interface.attributes |
537 if not self._IsEventAttribute(interface, attr)] | 891 if not self._IsEventAttribute(interface, attr)] |
538 for (getter, setter) in _PairUpAttributes(attributes): | 892 for (getter, setter) in _PairUpAttributes(attributes): |
539 for generator in generators: | 893 for generator in generators: |
540 generator.AddAttribute(getter, setter) | 894 generator.AddAttribute(getter, setter) |
541 | 895 |
542 events = _PairUpAttributes([attr for attr in interface.attributes | 896 events = set([_OnAttributeToEventName(attr) for attr in interface.attributes |
543 if self._IsEventAttribute(interface, attr)]) | 897 if self._IsEventAttribute(interface, attr)]) |
898 | |
899 if interface.id in _html_manual_events: | |
900 for manual_event_name in _html_manual_events[interface.id]: | |
sra1
2012/02/16 04:43:28
Move this _html specific code into the generator.
Jacob
2012/02/17 00:44:23
Done.
| |
901 events.add(manual_event_name) | |
902 | |
903 events = sorted(events, key=lambda name: _html_event_names[name]) | |
904 | |
544 if events: | 905 if events: |
545 for generator in generators: | 906 for generator in generators: |
546 generator.AddEventAttributes(events) | 907 generator.AddEventAttributes(events) |
547 | 908 |
548 # The implementation should define an indexer if the interface directly | 909 # The implementation should define an indexer if the interface directly |
549 # extends List. | 910 # extends List. |
550 element_type = MaybeListElementType(interface) | 911 element_type = MaybeListElementType(interface) |
551 if element_type: | 912 if element_type: |
552 for generator in generators: | 913 for generator in generators: |
553 generator.AddIndexer(element_type) | 914 generator.AddIndexer(element_type) |
554 | |
555 # Group overloaded operations by id | 915 # Group overloaded operations by id |
556 operationsById = {} | 916 operationsById = {} |
557 for operation in interface.operations: | 917 for operation in interface.operations: |
558 if operation.id not in operationsById: | 918 if operation.id not in operationsById: |
559 operationsById[operation.id] = [] | 919 operationsById[operation.id] = [] |
560 operationsById[operation.id].append(operation) | 920 operationsById[operation.id].append(operation) |
561 | 921 |
562 # Generate operations | 922 # Generate operations |
563 for id in sorted(operationsById.keys()): | 923 for id in sorted(operationsById.keys()): |
564 operations = operationsById[id] | 924 operations = operationsById[id] |
(...skipping 30 matching lines...) Expand all Loading... | |
595 for generator in generators: | 955 for generator in generators: |
596 generator.AddSecondaryOperation(parent_interface, info) | 956 generator.AddSecondaryOperation(parent_interface, info) |
597 | 957 |
598 for generator in generators: | 958 for generator in generators: |
599 generator.FinishInterface() | 959 generator.FinishInterface() |
600 return | 960 return |
601 | 961 |
602 def _IsEventAttribute(self, interface, attr): | 962 def _IsEventAttribute(self, interface, attr): |
603 # Remove EventListener attributes like 'onclick' when addEventListener | 963 # Remove EventListener attributes like 'onclick' when addEventListener |
604 # is available. | 964 # is available. |
605 if attr.type.id == 'EventListener': | 965 return (attr.type.id == 'EventListener' and |
606 if 'EventTarget' in self._AllImplementedInterfaces(interface): | 966 'EventTarget' in self._AllImplementedInterfaces(interface)) |
607 return True | |
608 return False | |
609 | 967 |
610 def _TransitiveSecondaryParents(self, interface): | 968 def _TransitiveSecondaryParents(self, interface): |
611 """Returns a list of all non-primary parents. | 969 """Returns a list of all non-primary parents. |
612 | 970 |
613 The list contains the interface objects for interfaces defined in the | 971 The list contains the interface objects for interfaces defined in the |
614 database, and the name for undefined interfaces. | 972 database, and the name for undefined interfaces. |
615 """ | 973 """ |
616 def walk(parents): | 974 def walk(parents): |
617 for parent in parents: | 975 for parent in parents: |
618 if _IsDartCollectionType(parent.type.id): | 976 if _IsDartCollectionType(parent.type.id): |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
783 | 1141 |
784 Args: | 1142 Args: |
785 rename_type: A function that allows the types to be renamed. | 1143 rename_type: A function that allows the types to be renamed. |
786 """ | 1144 """ |
787 args = self.arg_infos | 1145 args = self.arg_infos |
788 if rename_type: | 1146 if rename_type: |
789 args = [(name, rename_type(type), default) | 1147 args = [(name, rename_type(type), default) |
790 for (name, type, default) in args] | 1148 for (name, type, default) in args] |
791 return self._FormatArgs(args, False) | 1149 return self._FormatArgs(args, False) |
792 | 1150 |
1151 def ParametersNameDeclaration(self): | |
sra1
2012/02/16 04:43:28
This is generating an argument list, no?
Then call
Jacob
2012/02/17 00:44:23
Done.
| |
1152 """Returns a formatted string declaring the parameters names. | |
1153 """ | |
1154 # TODO(jacobr) use lambda syntax. | |
1155 def FormatArg(arg_info): | |
1156 return arg_info[0] | |
1157 return ', '.join(map(FormatArg, self.arg_infos)) | |
793 | 1158 |
794 def _FormatArgs(self, args, is_interface): | 1159 def _FormatArgs(self, args, is_interface): |
795 def FormatArg(arg_info): | 1160 def FormatArg(arg_info): |
796 """Returns an argument declaration fragment for an argument info tuple.""" | 1161 """Returns an argument declaration fragment for an argument info tuple.""" |
797 (name, type, default) = arg_info | 1162 (name, type, default) = arg_info |
798 if default: | 1163 if default: |
799 return '%s %s = %s' % (type, name, default) | 1164 return '%s %s = %s' % (type, name, default) |
800 else: | 1165 else: |
801 return '%s %s' % (type, name) | 1166 return '%s %s' % (type, name) |
802 | 1167 |
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1052 | 1417 |
1053 | 1418 |
1054 def _FilePathForDartInterface(self, interface_name): | 1419 def _FilePathForDartInterface(self, interface_name): |
1055 """Returns the file path of the Dart interface definition.""" | 1420 """Returns the file path of the Dart interface definition.""" |
1056 return os.path.join(self._output_dir, 'src', 'interface', | 1421 return os.path.join(self._output_dir, 'src', 'interface', |
1057 '%s.dart' % interface_name) | 1422 '%s.dart' % interface_name) |
1058 | 1423 |
1059 | 1424 |
1060 # ------------------------------------------------------------------------------ | 1425 # ------------------------------------------------------------------------------ |
1061 | 1426 |
1062 class HtmlInterfacesSystem(System): | 1427 class HtmlSystem(System): |
1063 | 1428 |
1064 def __init__(self, templates, database, emitters, output_dir): | 1429 def __init__(self, templates, database, emitters, output_dir, generator): |
1430 super(HtmlSystem, self).__init__( | |
1431 templates, database, emitters, output_dir) | |
1432 self._event_classes = set() | |
1433 self._seen_event_names = {} | |
1434 self._generator = generator | |
1435 | |
1436 def _AllowInHtmlLibrary(self, interface, member): | |
1437 if self._PrivateInHtmlLibrary(interface, member): | |
1438 return False | |
1439 for interface_name in ([interface.id] + | |
1440 self._generator._AllImplementedInterfaces(interface)): | |
1441 if interface.id + '.' + member in _html_library_remove: | |
1442 return False | |
1443 return True | |
1444 | |
1445 def _PrivateInHtmlLibrary(self, interface, member): | |
1446 for interface_name in ([interface.id] + | |
1447 self._generator._AllImplementedInterfaces(interface)): | |
1448 if (interface_name in _private_html_properties and | |
1449 member in _private_html_properties[interface_name]): | |
1450 return True | |
1451 return False | |
1452 | |
1453 # TODO(jacobr): this already exists | |
1454 def _TraverseParents(self, interface, callback): | |
1455 for parent in interface.parents: | |
1456 parent_id = parent.type.id | |
1457 if self._database.HasInterface(parent_id): | |
1458 parent_interface = self._database.GetInterface(parent_id) | |
1459 callback(parent_interface) | |
1460 self._TraverseParents(parent_interface, callback) | |
1461 | |
1462 # TODO(jacobr): this isn't quite right.... | |
1463 def _GetParentsEventsClasses(self, interface): | |
1464 # Ugly hack as we don't specify that Document inherits from Element | |
1465 # in our IDL. | |
1466 if interface.id == 'Document': | |
1467 return ['ElementEvents'] | |
1468 | |
1469 interfaces_with_events = set() | |
1470 def visit(parent): | |
1471 if parent.id in self._event_classes: | |
1472 interfaces_with_events.add(parent) | |
1473 | |
1474 self._TraverseParents(interface, visit) | |
1475 if len(interfaces_with_events) == 0: | |
1476 return ['Events'] | |
1477 else: | |
1478 names = [] | |
1479 for interface in interfaces_with_events: | |
1480 names.append(interface.id + 'Events') | |
1481 return names | |
1482 | |
1483 class HtmlInterfacesSystem(HtmlSystem): | |
1484 | |
1485 def __init__(self, templates, database, emitters, output_dir, generator): | |
1065 super(HtmlInterfacesSystem, self).__init__( | 1486 super(HtmlInterfacesSystem, self).__init__( |
1066 templates, database, emitters, output_dir) | 1487 templates, database, emitters, output_dir, generator) |
1067 self._dart_interface_file_paths = [] | 1488 self._dart_interface_file_paths = [] |
1068 | 1489 |
1069 def InterfaceGenerator(self, | 1490 def InterfaceGenerator(self, |
1070 interface, | 1491 interface, |
1071 common_prefix, | 1492 common_prefix, |
1072 super_interface_name, | 1493 super_interface_name, |
1073 source_filter): | 1494 source_filter): |
1074 """.""" | 1495 """.""" |
1075 interface_name = interface.id | 1496 interface_name = interface.id |
1076 dart_interface_file_path = self._FilePathForDartInterface(interface_name) | 1497 dart_interface_file_path = self._FilePathForDartInterface(interface_name) |
1077 | 1498 |
1078 self._dart_interface_file_paths.append(dart_interface_file_path) | 1499 self._dart_interface_file_paths.append(dart_interface_file_path) |
1079 | 1500 |
1080 dart_interface_code = self._emitters.FileEmitter(dart_interface_file_path) | 1501 dart_interface_code = self._emitters.FileEmitter(dart_interface_file_path) |
1081 | 1502 |
1082 template_file = 'interface_%s.darttemplate' % interface_name | 1503 template_file = 'interface_%s.darttemplate' % interface_name |
1083 template = self._templates.TryLoad(template_file) | 1504 template = self._templates.TryLoad(template_file) |
1084 if not template: | 1505 if not template: |
1085 template = self._templates.Load('interface.darttemplate') | 1506 template = self._templates.Load('interface.darttemplate') |
1086 | 1507 |
1087 return HtmlDartInterfaceGenerator( | 1508 return HtmlDartInterfaceGenerator( |
1088 interface, dart_interface_code, | 1509 interface, dart_interface_code, |
1089 template, | 1510 template, |
1090 common_prefix, super_interface_name, | 1511 common_prefix, super_interface_name, |
1091 source_filter) | 1512 source_filter, self) |
1092 | 1513 |
1093 def ProcessCallback(self, interface, info): | 1514 def ProcessCallback(self, interface, info): |
1094 """Generates a typedef for the callback interface.""" | 1515 """Generates a typedef for the callback interface.""" |
1095 interface_name = interface.id | 1516 interface_name = interface.id |
1096 file_path = self._FilePathForDartInterface(interface_name) | 1517 file_path = self._FilePathForDartInterface(interface_name) |
1097 self._ProcessCallback(interface, info, file_path) | 1518 self._ProcessCallback(interface, info, file_path) |
1098 | 1519 |
1099 def GenerateLibraries(self, lib_dir): | 1520 def GenerateLibraries(self, lib_dir): |
1100 pass | 1521 pass |
1101 | 1522 |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1236 pass | 1657 pass |
1237 | 1658 |
1238 def _FilePathForFrogImpl(self, interface_name): | 1659 def _FilePathForFrogImpl(self, interface_name): |
1239 """Returns the file path of the Frog implementation.""" | 1660 """Returns the file path of the Frog implementation.""" |
1240 return os.path.join(self._output_dir, 'src', 'frog', | 1661 return os.path.join(self._output_dir, 'src', 'frog', |
1241 '%s.dart' % interface_name) | 1662 '%s.dart' % interface_name) |
1242 | 1663 |
1243 | 1664 |
1244 # ------------------------------------------------------------------------------ | 1665 # ------------------------------------------------------------------------------ |
1245 | 1666 |
1246 class HtmlFrogSystem(System): | 1667 class HtmlFrogSystem(HtmlSystem): |
1247 | 1668 |
1248 def __init__(self, templates, database, emitters, output_dir): | 1669 def __init__(self, templates, database, emitters, output_dir, generator): |
1249 super(HtmlFrogSystem, self).__init__( | 1670 super(HtmlFrogSystem, self).__init__( |
1250 templates, database, emitters, output_dir) | 1671 templates, database, emitters, output_dir, generator) |
1251 self._dart_frog_file_paths = [] | 1672 self._dart_frog_file_paths = [] |
1252 | 1673 |
1674 | |
1253 def InterfaceGenerator(self, | 1675 def InterfaceGenerator(self, |
1254 interface, | 1676 interface, |
1255 common_prefix, | 1677 common_prefix, |
1256 super_interface_name, | 1678 super_interface_name, |
1257 source_filter): | 1679 source_filter): |
1258 """.""" | 1680 """.""" |
1259 dart_frog_file_path = self._FilePathForFrogImpl(interface.id) | 1681 dart_frog_file_path = self._FilePathForFrogImpl(interface.id) |
1260 self._dart_frog_file_paths.append(dart_frog_file_path) | 1682 self._dart_frog_file_paths.append(dart_frog_file_path) |
1261 | 1683 |
1262 template_file = 'impl_%s.darttemplate' % interface.id | 1684 template_file = 'impl_%s.darttemplate' % interface.id |
1263 template = self._templates.TryLoad(template_file) | 1685 template = self._templates.TryLoad(template_file) |
1264 if not template: | 1686 if not template: |
1265 template = self._templates.Load('frog_impl.darttemplate') | 1687 template = self._templates.Load('frog_impl.darttemplate') |
1266 | 1688 |
1267 dart_code = self._emitters.FileEmitter(dart_frog_file_path) | 1689 dart_code = self._emitters.FileEmitter(dart_frog_file_path) |
1268 return HtmlFrogInterfaceGenerator(self, interface, template, | 1690 return HtmlFrogClassGenerator(self, interface, template, |
1269 super_interface_name, dart_code) | 1691 super_interface_name, dart_code) |
1270 | 1692 |
1271 def GenerateLibraries(self, lib_dir): | 1693 def GenerateLibraries(self, lib_dir): |
1272 self._GenerateLibFile( | 1694 self._GenerateLibFile( |
1273 'html_frog.darttemplate', | 1695 'html_frog.darttemplate', |
1274 os.path.join(lib_dir, 'html_frog.dart'), | 1696 os.path.join(lib_dir, 'html_frog.dart'), |
1275 (self._interface_system._dart_interface_file_paths + | 1697 (self._interface_system._dart_interface_file_paths + |
1276 self._interface_system._dart_callback_file_paths + | 1698 self._interface_system._dart_callback_file_paths + |
1277 self._dart_frog_file_paths)) | 1699 self._dart_frog_file_paths)) |
1278 | 1700 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1311 self._super_interface = super_interface | 1733 self._super_interface = super_interface |
1312 self._source_filter = source_filter | 1734 self._source_filter = source_filter |
1313 | 1735 |
1314 | 1736 |
1315 def StartInterface(self): | 1737 def StartInterface(self): |
1316 if self._super_interface: | 1738 if self._super_interface: |
1317 typename = self._super_interface | 1739 typename = self._super_interface |
1318 else: | 1740 else: |
1319 typename = self._interface.id | 1741 typename = self._interface.id |
1320 | 1742 |
1321 # TODO(vsm): Add appropriate package / namespace syntax. | |
1322 (extends_emitter, | |
1323 self._members_emitter, | |
1324 self._top_level_emitter) = self._emitter.Emit( | |
1325 self._template + '$!TOP_LEVEL', | |
1326 ID=typename) | |
1327 | 1743 |
1328 extends = [] | 1744 extends = [] |
1329 suppressed_extends = [] | 1745 suppressed_extends = [] |
1330 | 1746 |
1331 for parent in self._interface.parents: | 1747 for parent in self._interface.parents: |
1332 # TODO(vsm): Remove source_filter. | 1748 # TODO(vsm): Remove source_filter. |
1333 if _MatchSourceFilter(self._source_filter, parent): | 1749 if _MatchSourceFilter(self._source_filter, parent): |
1334 # Parent is a DOM type. | 1750 # Parent is a DOM type. |
1335 extends.append(parent.type.id) | 1751 extends.append(parent.type.id) |
1336 elif '<' in parent.type.id: | 1752 elif '<' in parent.type.id: |
1337 # Parent is a Dart collection type. | 1753 # Parent is a Dart collection type. |
1338 # TODO(vsm): Make this check more robust. | 1754 # TODO(vsm): Make this check more robust. |
1339 extends.append(parent.type.id) | 1755 extends.append(parent.type.id) |
1340 else: | 1756 else: |
1341 suppressed_extends.append('%s.%s' % | 1757 suppressed_extends.append('%s.%s' % |
1342 (self._common_prefix, parent.type.id)) | 1758 (self._common_prefix, parent.type.id)) |
1343 | 1759 |
1344 comment = ' extends' | 1760 comment = ' extends' |
1761 extends_str = '' | |
1345 if extends: | 1762 if extends: |
1346 extends_emitter.Emit(' extends $SUPERS', SUPERS=', '.join(extends)) | 1763 extends_str += ' extends ' + ', '.join(extends) |
1347 comment = ',' | 1764 comment = ',' |
1348 if suppressed_extends: | 1765 if suppressed_extends: |
1349 extends_emitter.Emit(' /*$COMMENT $SUPERS */', | 1766 extends_str += ' /*%s %s */' % (comment, ', '.join(suppressed_extends)) |
1350 COMMENT=comment, | |
1351 SUPERS=', '.join(suppressed_extends)) | |
1352 | 1767 |
1353 if typename in _interface_factories: | 1768 if typename in _interface_factories: |
1354 extends_emitter.Emit(' default $F', F=_interface_factories[typename]) | 1769 extends_str += ' default ' + _interface_factories[typename] |
1770 | |
1771 # TODO(vsm): Add appropriate package / namespace syntax. | |
1772 (self._members_emitter, | |
1773 self._top_level_emitter) = self._emitter.Emit( | |
1774 self._template + '$!TOP_LEVEL', | |
1775 ID=typename, | |
1776 EXTENDS=extends_str) | |
1355 | 1777 |
1356 element_type = MaybeTypedArrayElementType(self._interface) | 1778 element_type = MaybeTypedArrayElementType(self._interface) |
1357 if element_type: | 1779 if element_type: |
1358 self._members_emitter.Emit( | 1780 self._members_emitter.Emit( |
1359 '\n' | 1781 '\n' |
1360 ' $CTOR(int length);\n' | 1782 ' $CTOR(int length);\n' |
1361 '\n' | 1783 '\n' |
1362 ' $CTOR.fromList(List<$TYPE> list);\n' | 1784 ' $CTOR.fromList(List<$TYPE> list);\n' |
1363 '\n' | 1785 '\n' |
1364 ' $CTOR.fromBuffer(ArrayBuffer buffer);\n', | 1786 ' $CTOR.fromBuffer(ArrayBuffer buffer);\n', |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1437 return 'var' | 1859 return 'var' |
1438 | 1860 |
1439 # ------------------------------------------------------------------------------ | 1861 # ------------------------------------------------------------------------------ |
1440 | 1862 |
1441 # TODO(jmesserly): inheritance is probably not the right way to factor this long | 1863 # TODO(jmesserly): inheritance is probably not the right way to factor this long |
1442 # term, but it makes merging better for now. | 1864 # term, but it makes merging better for now. |
1443 class HtmlDartInterfaceGenerator(DartInterfaceGenerator): | 1865 class HtmlDartInterfaceGenerator(DartInterfaceGenerator): |
1444 """Generates Dart Interface definition for one DOM IDL interface.""" | 1866 """Generates Dart Interface definition for one DOM IDL interface.""" |
1445 | 1867 |
1446 def __init__(self, interface, emitter, template, | 1868 def __init__(self, interface, emitter, template, |
1447 common_prefix, super_interface, source_filter): | 1869 common_prefix, super_interface, source_filter, system): |
1448 super(HtmlDartInterfaceGenerator, self).__init__(interface, | 1870 super(HtmlDartInterfaceGenerator, self).__init__(interface, |
1449 emitter, template, common_prefix, super_interface, source_filter) | 1871 emitter, template, common_prefix, super_interface, source_filter) |
1872 self._system = system | |
1873 | |
1874 def StartInterface(self): | |
1875 typename = self._interface.id | |
1876 | |
1877 extends = [] | |
1878 suppressed_extends = [] | |
1879 | |
1880 for parent in self._interface.parents: | |
1881 # TODO(vsm): Remove source_filter. | |
1882 if _MatchSourceFilter(self._source_filter, parent): | |
1883 # Parent is a DOM type. | |
1884 extends.append(parent.type.id) | |
1885 elif '<' in parent.type.id: | |
1886 # Parent is a Dart collection type. | |
1887 # TODO(vsm): Make this check more robust. | |
1888 extends.append(parent.type.id) | |
1889 else: | |
1890 suppressed_extends.append('%s.%s' % | |
1891 (self._common_prefix, parent.type.id)) | |
1892 | |
1893 comment = ' extends' | |
1894 extends_str = '' | |
1895 if extends: | |
1896 extends_str += ' extends ' + ', '.join(extends) | |
1897 comment = ',' | |
1898 if suppressed_extends: | |
1899 extends_str += ' /*%s %s */' % (comment, ', '.join(suppressed_extends)) | |
1900 | |
1901 if typename in _interface_factories: | |
1902 extends_str += ' default ' + _interface_factories[typename] | |
1903 | |
1904 # TODO(vsm): Add appropriate package / namespace syntax. | |
1905 (self._members_emitter, | |
1906 self._top_level_emitter) = self._emitter.Emit( | |
1907 self._template + '$!TOP_LEVEL', | |
1908 ID=typename, | |
1909 EXTENDS=extends_str) | |
1910 | |
1911 element_type = MaybeTypedArrayElementType(self._interface) | |
1912 if element_type: | |
1913 self._members_emitter.Emit( | |
1914 '\n' | |
1915 ' $CTOR(int length);\n' | |
1916 '\n' | |
1917 ' $CTOR.fromList(List<$TYPE> list);\n' | |
1918 '\n' | |
1919 ' $CTOR.fromBuffer(ArrayBuffer buffer);\n', | |
1920 CTOR=self._interface.id, | |
1921 TYPE=element_type) | |
1922 | |
1923 def AddAttribute(self, getter, setter): | |
1924 if getter and not self._system._AllowInHtmlLibrary(self._interface, 'get:' + getter.id): | |
sra1
2012/02/16 04:43:28
Line length
Jacob
2012/02/17 00:44:23
Done.
| |
1925 getter = None | |
1926 if setter and not self._system._AllowInHtmlLibrary(self._interface, 'set:' + setter.id): | |
1927 setter = None | |
1928 if not getter and not setter: | |
1929 return | |
1930 if getter and setter and getter.type.id == setter.type.id: | |
1931 self._members_emitter.Emit('\n $TYPE $NAME;\n', | |
1932 NAME=getter.id, TYPE=getter.type.id); | |
1933 return | |
1934 if getter and not setter: | |
1935 self._members_emitter.Emit('\n final $TYPE $NAME;\n', | |
1936 NAME=getter.id, TYPE=getter.type.id); | |
1937 return | |
1938 raise Exception('Unexpected getter/setter combination %s %s' % | |
1939 (getter, setter)) | |
1940 | |
1941 def AddOperation(self, info): | |
1942 """ | |
1943 Arguments: | |
1944 operations - contains the overloads, one or more operations with the same | |
1945 name. | |
1946 """ | |
1947 if self._system._AllowInHtmlLibrary(self._interface, info.name): | |
1948 self._members_emitter.Emit('\n' | |
1949 ' $TYPE $NAME($PARAMS);\n', | |
1950 TYPE=info.type_name, | |
1951 NAME=info.name, | |
1952 PARAMS=info.ParametersInterfaceDeclaration()) | |
1953 | |
1954 def FinishInterface(self): | |
1955 pass | |
1956 | |
1957 def AddConstant(self, constant): | |
1958 self._EmitConstant(self._members_emitter, constant) | |
1450 | 1959 |
1451 def AddEventAttributes(self, event_attrs): | 1960 def AddEventAttributes(self, event_attrs): |
1961 self._system._event_classes.add(self._interface.id) | |
1452 events_interface = self._interface.id + 'Events' | 1962 events_interface = self._interface.id + 'Events' |
1453 self._members_emitter.Emit('\n $TYPE get on();\n', | 1963 self._members_emitter.Emit('\n $TYPE get on();\n', |
1454 TYPE=events_interface) | 1964 TYPE=events_interface) |
1455 events_members = self._emitter.Emit( | 1965 events_members = self._emitter.Emit( |
1456 '\ninterface $INTERFACE {\n$!MEMBERS}\n', | 1966 '\ninterface $INTERFACE extends $PARENTS {\n$!MEMBERS}\n', |
1457 INTERFACE=events_interface) | 1967 INTERFACE=events_interface, |
1968 PARENTS=', '.join( | |
1969 self._system._GetParentsEventsClasses(self._interface))) | |
1458 | 1970 |
1459 for getter, setter in event_attrs: | 1971 for event_name in event_attrs: |
1460 event = getter or setter | 1972 if event_name in _html_event_names: |
1461 events_members.Emit('\n EventListenerList get $NAME();\n', NAME=event.id) | 1973 events_members.Emit('\n EventListenerList get $NAME();\n', |
1462 | 1974 NAME=_html_event_names[event_name]) |
1975 else: | |
1976 raise Exception('No known html even name for event: ' + event_name) | |
1463 | 1977 |
1464 # ------------------------------------------------------------------------------ | 1978 # ------------------------------------------------------------------------------ |
1465 | 1979 |
1466 class DummyInterfaceGenerator(object): | 1980 class DummyInterfaceGenerator(object): |
1467 """Generates nothing.""" | 1981 """Generates nothing.""" |
1468 | 1982 |
1469 def __init__(self, system, interface): | 1983 def __init__(self, system, interface): |
1470 pass | 1984 pass |
1471 | 1985 |
1472 def StartInterface(self): | 1986 def StartInterface(self): |
(...skipping 507 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1980 self._interface = interface | 2494 self._interface = interface |
1981 self._template = template | 2495 self._template = template |
1982 self._super_interface = super_interface | 2496 self._super_interface = super_interface |
1983 self._dart_code = dart_code | 2497 self._dart_code = dart_code |
1984 self._current_secondary_parent = None | 2498 self._current_secondary_parent = None |
1985 | 2499 |
1986 | 2500 |
1987 def StartInterface(self): | 2501 def StartInterface(self): |
1988 interface = self._interface | 2502 interface = self._interface |
1989 interface_name = interface.id | 2503 interface_name = interface.id |
1990 | 2504 native_name = interface.native_name |
sra1
2012/02/16 04:43:28
Rather than 'rename' the interface.native_name, ca
Jacob
2012/02/17 00:44:23
discussed offline. this is needed.
changed name to
| |
1991 self._class_name = self._ImplClassName(interface_name) | 2505 self._class_name = self._ImplClassName(interface_name) |
1992 | 2506 |
1993 base = None | 2507 base = None |
1994 if interface.parents: | 2508 if interface.parents: |
1995 supertype = interface.parents[0].type.id | 2509 supertype = interface.parents[0].type.id |
1996 if _IsDartCollectionType(supertype): | 2510 if _IsDartCollectionType(supertype): |
1997 # List methods are injected in AddIndexer. | 2511 # List methods are injected in AddIndexer. |
1998 pass | 2512 pass |
1999 else: | 2513 else: |
2000 base = self._ImplClassName(supertype) | 2514 base = self._ImplClassName(supertype) |
2001 | 2515 |
2002 if interface_name in _frog_dom_custom_native_specs: | 2516 if native_name in _frog_dom_custom_native_specs: |
2003 native_spec = _frog_dom_custom_native_specs[interface_name] | 2517 native_spec = _frog_dom_custom_native_specs[native_name] |
2004 else: | 2518 else: |
2005 # Make the class 'hidden' so it is dynamically patched at runtime. This | 2519 # Make the class 'hidden' so it is dynamically patched at runtime. This |
2006 # is useful not only for browser compat, but to allow code that links | 2520 # is useful not only for browser compat, but to allow code that links |
2007 # against dart:dom to load in a worker isolate. | 2521 # against dart:dom to load in a worker isolate. |
2008 native_spec = '*' + interface_name | 2522 native_spec = '*' + interface_name |
2009 | 2523 |
2010 if base: | 2524 if base: |
2011 extends = ' extends ' + base | 2525 extends = ' extends ' + base |
2012 elif native_spec[0] == '=': | 2526 elif native_spec[0] == '=': |
2013 # The implementation is a singleton with no prototype. | 2527 # The implementation is a singleton with no prototype. |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2234 TYPE=self._NarrowOutputType(info.type_name), | 2748 TYPE=self._NarrowOutputType(info.type_name), |
2235 NAME=info.name, | 2749 NAME=info.name, |
2236 PARAMS=info.ParametersImplementationDeclaration( | 2750 PARAMS=info.ParametersImplementationDeclaration( |
2237 lambda type_name: self._NarrowInputType(type_name))) | 2751 lambda type_name: self._NarrowInputType(type_name))) |
2238 | 2752 |
2239 | 2753 |
2240 # ------------------------------------------------------------------------------ | 2754 # ------------------------------------------------------------------------------ |
2241 | 2755 |
2242 # TODO(jmesserly): inheritance is probably not the right way to factor this long | 2756 # TODO(jmesserly): inheritance is probably not the right way to factor this long |
2243 # term, but it makes merging better for now. | 2757 # term, but it makes merging better for now. |
2244 class HtmlFrogInterfaceGenerator(FrogInterfaceGenerator): | 2758 class HtmlFrogClassGenerator(FrogInterfaceGenerator): |
2245 """Generates a Frog class for the dart:html library from a DOM IDL | 2759 """Generates a Frog class for the dart:html library from a DOM IDL |
2246 interface. | 2760 interface. |
2247 """ | 2761 """ |
2248 | 2762 |
2249 def __init__(self, system, interface, template, super_interface, dart_code): | 2763 def __init__(self, system, interface, template, super_interface, dart_code): |
2250 super(HtmlFrogInterfaceGenerator, self).__init__( | 2764 super(HtmlFrogClassGenerator, self).__init__( |
2251 system, interface, template, super_interface, dart_code) | 2765 system, interface, template, super_interface, dart_code) |
2252 | 2766 |
2767 | |
2768 def StartInterface(self): | |
2769 interface = self._interface | |
2770 interface_name = interface.id | |
2771 native_interface_name = interface.native_name | |
2772 | |
2773 self._class_name = self._ImplClassName(interface_name) | |
2774 | |
2775 base = None | |
2776 if interface.parents: | |
2777 supertype = interface.parents[0].type.id | |
2778 # FIXME: We're currently injecting List<..> and EventTarget as | |
2779 # supertypes in dart.idl. We should annotate/preserve as | |
2780 # attributes instead. For now, this hack lets the interfaces | |
2781 # inherit, but not the classes. | |
2782 if (not _IsDartListType(supertype) and | |
2783 not supertype == 'EventTarget'): | |
2784 base = self._ImplClassName(supertype) | |
2785 if _IsDartCollectionType(supertype): | |
2786 # List methods are injected in AddIndexer. | |
2787 pass | |
2788 elif supertype == 'EventTarget': | |
2789 # Most implementors of EventTarget specify the EventListener operations | |
2790 # again. If the operations are not specified, try to inherit from the | |
2791 # EventTarget implementation. | |
2792 # | |
2793 # Applies to MessagePort. | |
2794 if not [op for op in interface.operations if op.id == 'addEventListener' ]: | |
2795 base = self._ImplClassName(supertype) | |
2796 else: | |
2797 base = self._ImplClassName(supertype) | |
2798 | |
2799 if native_interface_name in _frog_dom_custom_native_specs: | |
2800 native_spec = _frog_dom_custom_native_specs[native_interface_name] | |
2801 else: | |
2802 # Make the class 'hidden' so it is dynamically patched at runtime. This | |
2803 # is useful not only for browser compat, but to allow code that links | |
2804 # against dart:dom to load in a worker isolate. | |
2805 native_spec = '*' + native_interface_name | |
2806 | |
2807 extends = ' extends ' + base if base else '' | |
2808 | |
2809 # TODO: Include all implemented interfaces, including other Lists. | |
2810 implements = [interface_name] | |
2811 element_type = MaybeTypedArrayElementType(self._interface) | |
2812 if element_type: | |
2813 implements.append('List<' + element_type + '>') | |
2814 | |
2815 self._members_emitter = self._dart_code.Emit( | |
2816 self._template, | |
2817 #class $CLASSNAME$EXTENDS$IMPLEMENTS$NATIVESPEC { | |
2818 #$!MEMBERS | |
2819 #} | |
2820 CLASSNAME=self._class_name, | |
2821 EXTENDS=extends, | |
2822 IMPLEMENTS=' implements ' + ', '.join(implements), | |
2823 NATIVESPEC=' native "' + native_spec + '"') | |
2824 | |
2825 element_type = MaybeTypedArrayElementType(interface) | |
2826 if element_type: | |
2827 self.AddTypedArrayConstructors(element_type) | |
2828 | |
2829 def AddAttribute(self, getter, setter): | |
2830 | |
2831 if self._system._PrivateInHtmlLibrary(self._interface, getter.id): | |
2832 if getter: | |
2833 self._AddGetter(getter, True) | |
2834 if setter: | |
2835 self._AddSetter(setter, True) | |
sra1
2012/02/16 04:43:28
If you return after these two ifs you can drop the
Jacob
2012/02/17 00:44:23
Done
| |
2836 else: | |
2837 if getter and not self._system._AllowInHtmlLibrary(self._interface, 'get:' + getter.id): | |
sra1
2012/02/16 04:43:28
Line length.
Jacob
2012/02/17 00:44:23
Done.
| |
2838 getter = None | |
2839 if setter and not self._system._AllowInHtmlLibrary(self._interface, 'set:' + setter.id): | |
2840 setter = None | |
2841 if not getter and not setter: | |
2842 return | |
2843 # If the (getter, setter) pair is shadowing, we can't generate a shadowing | |
2844 # field (Issue 1633). | |
2845 (super_getter, super_getter_interface) = self._FindShadowedAttribute(gette r) | |
2846 (super_setter, super_setter_interface) = self._FindShadowedAttribute(sette r) | |
2847 if super_getter or super_setter: | |
2848 if getter and not setter and super_getter and not super_setter: | |
2849 if getter.type.id == super_getter.type.id: | |
2850 # Compatible getter, use the superclass property. This works becaus e | |
2851 # JavaScript will do its own dynamic dispatch. | |
2852 output_type = getter and self._NarrowOutputType(getter.type.id) | |
2853 self._members_emitter.Emit( | |
2854 '\n' | |
2855 ' // Use implementation from $SUPER.\n' | |
2856 ' // final $TYPE $NAME;\n', | |
2857 SUPER=super_getter_interface.id, | |
2858 NAME=getter.id, TYPE=output_type) | |
2859 return | |
2860 | |
2861 self._members_emitter.Emit('\n // Shadowing definition.') | |
2862 if getter: | |
sra1
2012/02/16 04:43:28
I've seen this before.
Copy _AddAttributeUsingProp
Jacob
2012/02/17 00:44:23
Done.
| |
2863 self._AddGetter(getter, False) | |
2864 if setter: | |
2865 self._AddSetter(setter, False) | |
2866 return | |
2867 | |
2868 if self._interface.id != 'Document': | |
2869 output_type = getter and self._NarrowOutputType(getter.type.id) | |
2870 input_type = setter and self._NarrowInputType(setter.type.id) | |
2871 if getter and setter and input_type == output_type: | |
2872 self._members_emitter.Emit( | |
2873 '\n $TYPE $NAME;\n', | |
2874 NAME=getter.id, TYPE=output_type) | |
2875 return | |
2876 if getter and not setter: | |
2877 self._members_emitter.Emit( | |
2878 '\n final $TYPE $NAME;\n', | |
2879 NAME=getter.id, TYPE=output_type) | |
2880 return | |
2881 if getter: | |
2882 self._AddGetter(getter, False) | |
2883 if setter: | |
2884 self._AddSetter(setter, False) | |
2885 | |
2886 def _AddGetter(self, attr, private): | |
2887 # TODO(sra): Remove native body when Issue 829 fixed. | |
2888 self._members_emitter.Emit( | |
2889 '\n $TYPE get $PRIVATE$NAME() native "return $THIS.$NAME;";\n', | |
2890 NAME=attr.id, TYPE=self._NarrowOutputType(attr.type.id), | |
2891 PRIVATE='_' if private else '', | |
2892 THIS='this.parentNode' if self._interface.id == 'Document' else 'this' | |
2893 ) | |
2894 | |
2895 def _AddSetter(self, attr, private): | |
2896 # TODO(sra): Remove native body when Issue 829 fixed. | |
2897 self._members_emitter.Emit( | |
2898 '\n void set $PRIVATE$NAME($TYPE value) native "$THIS.$NAME = value;";\ n', | |
2899 NAME=attr.id, TYPE=self._NarrowInputType(attr.type.id), | |
2900 PRIVATE='_' if private else '', | |
2901 THIS='this.parentNode' if self._interface.id == 'Document' else 'this') | |
2902 | |
2903 def AddOperation(self, info): | |
2904 """ | |
2905 Arguments: | |
2906 info: An OperationInfo object. | |
2907 """ | |
2908 private_in_html = self._system._PrivateInHtmlLibrary(self._interface, info.n ame) | |
2909 if private_in_html or self._interface.id == 'Document': | |
2910 # TODO(vsm): Handle overloads. | |
2911 # TODO(jacobr): handle document more efficiently for cases where any | |
2912 # document is fine. For example: use window.document instead of | |
2913 # this.parentNode. | |
2914 return_type = self._NarrowOutputType(info.type_name) | |
2915 self._members_emitter.Emit( | |
2916 '\n' | |
2917 ' $TYPE $PRIVATE$NAME($PARAMS) native "$(RETURN)$(THIS).$NAME($PARAMN AMES);";\n', | |
sra1
2012/02/16 04:43:28
Line length.
Jacob
2012/02/17 00:44:23
Done.
| |
2918 TYPE=return_type, | |
2919 RETURN='' if return_type == 'void' else 'return ', | |
2920 NAME=info.name, | |
2921 PRIVATE='_' if private_in_html else '', | |
2922 THIS='this.parentNode' if self._interface.id == 'Document' else 'this' , | |
2923 PARAMNAMES=info.ParametersNameDeclaration(), | |
sra1
2012/02/16 04:43:28
ARGUMENTS=info.ParemetersAsArguments(),
Jacob
2012/02/17 00:44:23
Done.
| |
2924 PARAMS=info.ParametersImplementationDeclaration( | |
2925 lambda type_name: self._NarrowInputType(type_name))) | |
2926 elif self._system._AllowInHtmlLibrary(self._interface, info.name): | |
2927 # TODO(jacobr): this is duplicated from the parent class. | |
2928 self._members_emitter.Emit( | |
2929 '\n' | |
2930 ' $TYPE $NAME($PARAMS) native;\n', | |
2931 TYPE=self._NarrowOutputType(info.type_name), | |
2932 NAME=info.name, | |
2933 PARAMS=info.ParametersImplementationDeclaration( | |
2934 lambda type_name: self._NarrowInputType(type_name))) | |
2935 | |
2253 def AddEventAttributes(self, event_attrs): | 2936 def AddEventAttributes(self, event_attrs): |
2254 events_class = self._interface.id + 'EventsImpl' | 2937 events_class = '_' + self._interface.id + 'EventsImpl' |
2255 events_interface = self._interface.id + 'Events' | 2938 events_interface = self._interface.id + 'Events' |
2256 self._members_emitter.Emit('\n $TYPE get on() =>\n new $TYPE(this);\n', | 2939 self._members_emitter.Emit('\n $TYPE get on() =>\n new $TYPE($EVENTTARGE T);\n', |
sra1
2012/02/16 04:43:28
Line length. Break like so:
.....Emit(
Jacob
2012/02/17 00:44:23
Done.
| |
2257 TYPE=events_class) | 2940 TYPE=events_class, |
2258 | 2941 EVENTTARGET='_jsDocument' if self._interface.id = = 'Document' else 'this') |
2942 | |
2943 self._system._event_classes.add(self._interface.id) | |
2944 | |
2945 parent_event_classes = self._system._GetParentsEventsClasses( | |
2946 self._interface) | |
2947 if len(parent_event_classes) != 1: | |
2948 raise Exception('Only one parent event class allowed ' | |
2949 + self._interface.id) | |
2950 | |
2951 # TODO(jacobr): specify the type of _ptr as EventTarget | |
2259 events_members = self._dart_code.Emit( | 2952 events_members = self._dart_code.Emit( |
2260 '\n' | 2953 '\n' |
2261 'class $CLASSNAME extends EventsImplementation ' | 2954 'class $CLASSNAME extends $SUPER ' |
2262 'implements $INTERFACE {\n' | 2955 'implements $INTERFACE {\n' |
sra1
2012/02/16 04:43:28
Does this fit on above line?
Jacob
2012/02/17 00:44:23
Done.
| |
2263 ' $CLASSNAME(_ptr) : super._wrap(_ptr);\n' | 2956 ' $CLASSNAME(_ptr) : super(_ptr);\n' |
2264 '$!MEMBERS}\n', | 2957 '$!MEMBERS}\n', |
2958 TARGETCLASS=self._NarrowOutputType(self._interface.id), | |
2265 CLASSNAME=events_class, | 2959 CLASSNAME=events_class, |
2266 INTERFACE=events_interface) | 2960 INTERFACE=events_interface, |
2267 | 2961 SUPER='_' + parent_event_classes[0] + 'Impl') |
2268 for getter, setter in event_attrs: | 2962 |
2269 event = getter or setter | 2963 for event_name in event_attrs: |
2270 events_members.Emit( | 2964 if event_name in _html_event_names: |
2271 "\n" | 2965 events_members.Emit( |
2272 "EventListenerList get $NAME() => _get('$NAME');\n", | 2966 "\n" |
2273 NAME=event.id) | 2967 " EventListenerList get $NAME() => _get('$RAWNAME');\n", |
2968 RAWNAME=event_name, | |
2969 NAME=_html_event_names[event_name]) | |
2970 else: | |
2971 raise Exception('No known html even name for event: ' + event_name) | |
2274 | 2972 |
2275 | 2973 |
2276 # ------------------------------------------------------------------------------ | 2974 # ------------------------------------------------------------------------------ |
2277 | 2975 |
2278 class NativeImplementationSystem(System): | 2976 class NativeImplementationSystem(System): |
2279 | 2977 |
2280 def __init__(self, templates, database, emitters, auxiliary_dir, output_dir): | 2978 def __init__(self, templates, database, emitters, auxiliary_dir, output_dir): |
2281 super(NativeImplementationSystem, self).__init__( | 2979 super(NativeImplementationSystem, self).__init__( |
2282 templates, database, emitters, output_dir) | 2980 templates, database, emitters, output_dir) |
2283 | 2981 |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2538 INDENT=indent, | 3236 INDENT=indent, |
2539 NATIVENAME=native_name, | 3237 NATIVENAME=native_name, |
2540 ARGS=argument_expressions) | 3238 ARGS=argument_expressions) |
2541 | 3239 |
2542 self._members_emitter.Emit(' $TYPE $NATIVE_NAME($PARAMS) native ' | 3240 self._members_emitter.Emit(' $TYPE $NATIVE_NAME($PARAMS) native ' |
2543 '"$(INTERFACE)$(NATIVE_NAME)_Callback";\n', | 3241 '"$(INTERFACE)$(NATIVE_NAME)_Callback";\n', |
2544 NATIVE_NAME=native_name, | 3242 NATIVE_NAME=native_name, |
2545 TYPE=info.type_name, | 3243 TYPE=info.type_name, |
2546 PARAMS=', '.join(arg_names), | 3244 PARAMS=', '.join(arg_names), |
2547 INTERFACE=self._interface.id) | 3245 INTERFACE=self._interface.id) |
OLD | NEW |