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

Side by Side Diff: tools/dom/scripts/dartmetadata.py

Issue 14455007: Refactoring DOM annotations and comment generation, adding DOM API triage list (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 8 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 | « tools/dom/scripts/dartdomgenerator.py ('k') | tools/dom/scripts/generator.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #!/usr/bin/python
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
4 # BSD-style license that can be found in the LICENSE file.
5
6 """This module provides shared functionality for systems to generate
7 Dart APIs from the IDL database."""
8
9 import copy
10 import json
11 import monitored
12 import os
13 import re
14 from generator import ConstantOutputOrder
15 from htmlrenamer import renamed_html_members
16
17 # Annotations to be placed on native members. The table is indexed by the IDL
18 # interface and member name, and by IDL return or field type name. Both are
19 # used to assemble the annotations:
20 #
21 # INTERFACE.MEMBER: annotations for member.
22 # +TYPE: add annotations only if there are member annotations.
23 # -TYPE: add annotations only if there are no member annotations.
24 # TYPE: add regardless of member annotations.
25
26 _dart2js_annotations = monitored.Dict('dartmetadata._dart2js_annotations', {
27
28 'ArrayBufferView': [
29 "@Creates('TypedData')",
30 "@Returns('TypedData|Null')",
31 ],
32
33 'CanvasRenderingContext2D.createImageData': [
34 "@Creates('ImageData|=Object')",
35 ],
36
37 'CanvasRenderingContext2D.getImageData': [
38 "@Creates('ImageData|=Object')",
39 ],
40
41 'CanvasRenderingContext2D.webkitGetImageDataHD': [
42 "@Creates('ImageData|=Object')",
43 ],
44
45 'CanvasRenderingContext2D.fillStyle': [
46 "@Creates('String|CanvasGradient|CanvasPattern')",
47 "@Returns('String|CanvasGradient|CanvasPattern')",
48 ],
49
50 'CanvasRenderingContext2D.strokeStyle': [
51 "@Creates('String|CanvasGradient|CanvasPattern')",
52 "@Returns('String|CanvasGradient|CanvasPattern')",
53 ],
54
55 # Methods returning Window can return a local window, or a cross-frame
56 # window (=Object) that needs wrapping.
57 'DOMWindow': [
58 "@Creates('Window|=Object')",
59 "@Returns('Window|=Object')",
60 ],
61
62 'DOMWindow.openDatabase': [
63 "@Creates('SqlDatabase')",
64 ],
65
66 # To be in callback with the browser-created Event, we had to have called
67 # addEventListener on the target, so we avoid
68 'Event.currentTarget': [
69 "@Creates('Null')",
70 "@Returns('EventTarget|=Object')",
71 ],
72
73 # Only nodes in the DOM bubble and have target !== currentTarget.
74 'Event.target': [
75 "@Creates('Node')",
76 "@Returns('EventTarget|=Object')",
77 ],
78
79 'MouseEvent.relatedTarget': [
80 "@Creates('Node')",
81 "@Returns('EventTarget|=Object')",
82 ],
83
84 # Touch targets are Elements in a Document, or the Document.
85 'Touch.target': [
86 "@Creates('Element|Document')",
87 "@Returns('Element|Document')",
88 ],
89
90 'FileReader.result': ["@Creates('String|ByteBuffer|Null')"],
91
92 # Rather than have the result of an IDBRequest as a union over all possible
93 # results, we mark the result as instantiating any classes, and mark
94 # each operation with the classes that it could cause to be asynchronously
95 # instantiated.
96 'IDBRequest.result': ["@Creates('Null')"],
97
98 # The source is usually a participant in the operation that generated the
99 # IDBRequest.
100 'IDBRequest.source': ["@Creates('Null')"],
101
102 'IDBFactory.open': ["@Creates('Database')"],
103 'IDBFactory.webkitGetDatabaseNames': ["@Creates('DomStringList')"],
104
105 'IDBObjectStore.put': ["@_annotation_Creates_IDBKey"],
106 'IDBObjectStore.add': ["@_annotation_Creates_IDBKey"],
107 'IDBObjectStore.get': ["@annotation_Creates_SerializedScriptValue"],
108 'IDBObjectStore.openCursor': ["@Creates('Cursor')"],
109
110 'IDBIndex.get': ["@annotation_Creates_SerializedScriptValue"],
111 'IDBIndex.getKey': [
112 "@annotation_Creates_SerializedScriptValue",
113 # The source is the object store behind the index.
114 "@Creates('ObjectStore')",
115 ],
116 'IDBIndex.openCursor': ["@Creates('Cursor')"],
117 'IDBIndex.openKeyCursor': ["@Creates('Cursor')"],
118
119 'IDBCursorWithValue.value': [
120 '@annotation_Creates_SerializedScriptValue',
121 '@annotation_Returns_SerializedScriptValue',
122 ],
123
124 'IDBCursor.key': [
125 "@_annotation_Creates_IDBKey",
126 "@_annotation_Returns_IDBKey",
127 ],
128
129 '+IDBRequest': [
130 "@Returns('Request')",
131 "@Creates('Request')",
132 ],
133
134 '+IDBOpenDBRequest': [
135 "@Returns('Request')",
136 "@Creates('Request')",
137 ],
138
139 'MessageEvent.ports': ["@Creates('=List')"],
140
141 'MessageEvent.data': [
142 "@annotation_Creates_SerializedScriptValue",
143 "@annotation_Returns_SerializedScriptValue",
144 ],
145 'PopStateEvent.state': [
146 "@annotation_Creates_SerializedScriptValue",
147 "@annotation_Returns_SerializedScriptValue",
148 ],
149 'SerializedScriptValue': [
150 "@annotation_Creates_SerializedScriptValue",
151 "@annotation_Returns_SerializedScriptValue",
152 ],
153
154 'SQLResultSetRowList.item': ["@Creates('=Object')"],
155
156 'WebGLRenderingContext.getParameter': [
157 # Taken from http://www.khronos.org/registry/webgl/specs/latest/
158 # Section 5.14.3 Setting and getting state
159 "@Creates('Null|num|String|bool|=List|Float32List|Int32List|Uint32List"
160 "|Framebuffer|Renderbuffer|Texture')",
161 "@Returns('Null|num|String|bool|=List|Float32List|Int32List|Uint32List"
162 "|Framebuffer|Renderbuffer|Texture')",
163 ],
164
165 'XMLHttpRequest.response': [
166 "@Creates('ByteBuffer|Blob|Document|=Object|=List|String|num')",
167 ],
168 }, dart2jsOnly=True)
169
170 _indexed_db_annotations = [
171 "@SupportedBrowser(SupportedBrowser.CHROME)",
172 "@SupportedBrowser(SupportedBrowser.FIREFOX, '15')",
173 "@SupportedBrowser(SupportedBrowser.IE, '10')",
174 "@Experimental",
175 ]
176
177 _file_system_annotations = [
178 "@SupportedBrowser(SupportedBrowser.CHROME)",
179 "@Experimental",
180 ]
181
182 _all_but_ie9_annotations = [
183 "@SupportedBrowser(SupportedBrowser.CHROME)",
184 "@SupportedBrowser(SupportedBrowser.FIREFOX)",
185 "@SupportedBrowser(SupportedBrowser.IE, '10')",
186 "@SupportedBrowser(SupportedBrowser.SAFARI)",
187 ]
188
189 _history_annotations = _all_but_ie9_annotations
190
191 _no_ie_annotations = [
192 "@SupportedBrowser(SupportedBrowser.CHROME)",
193 "@SupportedBrowser(SupportedBrowser.FIREFOX)",
194 "@SupportedBrowser(SupportedBrowser.SAFARI)",
195 ]
196
197 _performance_annotations = [
198 "@SupportedBrowser(SupportedBrowser.CHROME)",
199 "@SupportedBrowser(SupportedBrowser.FIREFOX)",
200 "@SupportedBrowser(SupportedBrowser.IE)",
201 ]
202
203 _rtc_annotations = [ # Note: Firefox nightly builds also support this.
204 "@SupportedBrowser(SupportedBrowser.CHROME)",
205 "@Experimental",
206 ]
207
208 _shadow_dom_annotations = [
209 "@SupportedBrowser(SupportedBrowser.CHROME, '26')",
210 "@Experimental",
211 ]
212
213 _speech_recognition_annotations = [
214 "@SupportedBrowser(SupportedBrowser.CHROME, '25')",
215 "@Experimental",
216 ]
217
218 _svg_annotations = _all_but_ie9_annotations;
219
220 _web_sql_annotations = [
221 "@SupportedBrowser(SupportedBrowser.CHROME)",
222 "@SupportedBrowser(SupportedBrowser.SAFARI)",
223 "@Experimental",
224 ]
225
226 _webgl_annotations = [
227 "@SupportedBrowser(SupportedBrowser.CHROME)",
228 "@SupportedBrowser(SupportedBrowser.FIREFOX)",
229 "@Experimental",
230 ]
231
232 _webkit_experimental_annotations = [
233 "@SupportedBrowser(SupportedBrowser.CHROME)",
234 "@SupportedBrowser(SupportedBrowser.SAFARI)",
235 "@Experimental",
236 ]
237
238 # Annotations to be placed on generated members.
239 # The table is indexed as:
240 # INTERFACE: annotations to be added to the interface declaration
241 # INTERFACE.MEMBER: annotation to be added to the member declaration
242 _annotations = monitored.Dict('dartmetadata._annotations', {
243 'CSSHostRule': _shadow_dom_annotations,
244 'Crypto': _webkit_experimental_annotations,
245 'Database': _web_sql_annotations,
246 'DatabaseSync': _web_sql_annotations,
247 'DOMApplicationCache': [
248 "@SupportedBrowser(SupportedBrowser.CHROME)",
249 "@SupportedBrowser(SupportedBrowser.FIREFOX)",
250 "@SupportedBrowser(SupportedBrowser.IE, '10')",
251 "@SupportedBrowser(SupportedBrowser.OPERA)",
252 "@SupportedBrowser(SupportedBrowser.SAFARI)",
253 ],
254 'DOMFileSystem': _file_system_annotations,
255 'DOMFileSystemSync': _file_system_annotations,
256 'DOMWindow.webkitConvertPointFromNodeToPage': _webkit_experimental_annotations ,
257 'DOMWindow.webkitConvertPointFromPageToNode': _webkit_experimental_annotations ,
258 'DOMWindow.indexedDB': _indexed_db_annotations,
259 'DOMWindow.openDatabase': _web_sql_annotations,
260 'DOMWindow.performance': _performance_annotations,
261 'DOMWindow.webkitNotifications': _webkit_experimental_annotations,
262 'DOMWindow.webkitRequestFileSystem': _file_system_annotations,
263 'DOMWindow.webkitResolveLocalFileSystemURL': _file_system_annotations,
264 'Element.onwebkitTransitionEnd': _all_but_ie9_annotations,
265 # Placeholder to add experimental flag, implementation for this is
266 # pending in a separate CL.
267 'Element.webkitMatchesSelector': ['@Experimental()'],
268 'Element.webkitCreateShadowRoot': [
269 "@SupportedBrowser(SupportedBrowser.CHROME, '25')",
270 "@Experimental",
271 ],
272 'Event.clipboardData': _webkit_experimental_annotations,
273 'FormData': _all_but_ie9_annotations,
274 'HashChangeEvent': [
275 "@SupportedBrowser(SupportedBrowser.CHROME)",
276 "@SupportedBrowser(SupportedBrowser.FIREFOX)",
277 "@SupportedBrowser(SupportedBrowser.SAFARI)",
278 ],
279 'History.pushState': _history_annotations,
280 'History.replaceState': _history_annotations,
281 'HTMLContentElement': _shadow_dom_annotations,
282 'HTMLDataListElement': _all_but_ie9_annotations,
283 'HTMLDetailsElement': _webkit_experimental_annotations,
284 'HTMLEmbedElement': [
285 "@SupportedBrowser(SupportedBrowser.CHROME)",
286 "@SupportedBrowser(SupportedBrowser.IE)",
287 "@SupportedBrowser(SupportedBrowser.SAFARI)",
288 ],
289 'HTMLKeygenElement': _webkit_experimental_annotations,
290 'HTMLMeterElement': _no_ie_annotations,
291 'HTMLObjectElement': [
292 "@SupportedBrowser(SupportedBrowser.CHROME)",
293 "@SupportedBrowser(SupportedBrowser.IE)",
294 "@SupportedBrowser(SupportedBrowser.SAFARI)",
295 ],
296 'HTMLOutputElement': _no_ie_annotations,
297 'HTMLProgressElement': _all_but_ie9_annotations,
298 'HTMLShadowElement': _shadow_dom_annotations,
299 'HTMLTrackElement': [
300 "@SupportedBrowser(SupportedBrowser.CHROME)",
301 "@SupportedBrowser(SupportedBrowser.IE, '10')",
302 "@SupportedBrowser(SupportedBrowser.SAFARI)",
303 ],
304 'IDBFactory': _indexed_db_annotations,
305 'IDBDatabase': _indexed_db_annotations,
306 'LocalMediaStream': _rtc_annotations,
307 'MediaStream': _rtc_annotations,
308 'MediaStreamEvent': _rtc_annotations,
309 'MediaStreamTrack': _rtc_annotations,
310 'MediaStreamTrackEvent': _rtc_annotations,
311 'MutationObserver': [
312 "@SupportedBrowser(SupportedBrowser.CHROME)",
313 "@SupportedBrowser(SupportedBrowser.FIREFOX)",
314 "@SupportedBrowser(SupportedBrowser.SAFARI)",
315 "@Experimental",
316 ],
317 'NotificationCenter': _webkit_experimental_annotations,
318 'Performance': _performance_annotations,
319 'PopStateEvent': _history_annotations,
320 'RTCIceCandidate': _rtc_annotations,
321 'RTCPeerConnection': _rtc_annotations,
322 'RTCSessionDescription': _rtc_annotations,
323 'ShadowRoot': _shadow_dom_annotations,
324 'SpeechRecognition': _speech_recognition_annotations,
325 'SpeechRecognitionAlternative': _speech_recognition_annotations,
326 'SpeechRecognitionError': _speech_recognition_annotations,
327 'SpeechRecognitionEvent': _speech_recognition_annotations,
328 'SpeechRecognitionResult': _speech_recognition_annotations,
329 'SVGAltGlyphElement': _no_ie_annotations,
330 'SVGAnimateElement': _no_ie_annotations,
331 'SVGAnimateMotionElement': _no_ie_annotations,
332 'SVGAnimateTransformElement': _no_ie_annotations,
333 'SVGFEBlendElement': _svg_annotations,
334 'SVGFEColorMatrixElement': _svg_annotations,
335 'SVGFEComponentTransferElement': _svg_annotations,
336 'SVGFEConvolveMatrixElement': _svg_annotations,
337 'SVGFEDiffuseLightingElement': _svg_annotations,
338 'SVGFEDisplacementMapElement': _svg_annotations,
339 'SVGFEDistantLightElement': _svg_annotations,
340 'SVGFEFloodElement': _svg_annotations,
341 'SVGFEFuncAElement': _svg_annotations,
342 'SVGFEFuncBElement': _svg_annotations,
343 'SVGFEFuncGElement': _svg_annotations,
344 'SVGFEFuncRElement': _svg_annotations,
345 'SVGFEGaussianBlurElement': _svg_annotations,
346 'SVGFEImageElement': _svg_annotations,
347 'SVGFEMergeElement': _svg_annotations,
348 'SVGFEMergeNodeElement': _svg_annotations,
349 'SVGFEMorphologyElement': _svg_annotations,
350 'SVGFEOffsetElement': _svg_annotations,
351 'SVGFEPointLightElement': _svg_annotations,
352 'SVGFESpecularLightingElement': _svg_annotations,
353 'SVGFESpotLightElement': _svg_annotations,
354 'SVGFETileElement': _svg_annotations,
355 'SVGFETurbulenceElement': _svg_annotations,
356 'SVGFilterElement': _svg_annotations,
357 'SVGForeignObjectElement': _no_ie_annotations,
358 'SVGSetElement': _no_ie_annotations,
359 'SQLTransaction': _web_sql_annotations,
360 'SQLTransactionSync': _web_sql_annotations,
361 'WebGLRenderingContext': _webgl_annotations,
362 'WebKitCSSMatrix': _webkit_experimental_annotations,
363 'WebKitPoint': _webkit_experimental_annotations,
364 'WebSocket': _all_but_ie9_annotations,
365 'Worker': _all_but_ie9_annotations,
366 'XMLHttpRequest.onloadend': _all_but_ie9_annotations,
367 'XMLHttpRequest.onprogress': _all_but_ie9_annotations,
368 'XMLHttpRequest.response': _all_but_ie9_annotations,
369 'XMLHttpRequestProgressEvent': _webkit_experimental_annotations,
370 'XSLTProcessor': [
371 "@SupportedBrowser(SupportedBrowser.CHROME)",
372 "@SupportedBrowser(SupportedBrowser.FIREFOX)",
373 "@SupportedBrowser(SupportedBrowser.SAFARI)",
374 ],
375 })
376
377
378 class DartMetadata(object):
379 def __init__(self, api_status_path, doc_comments_path):
380 self._api_status_path = api_status_path
381 status_file = open(self._api_status_path, 'r+')
382 self._types = json.load(status_file)
383 status_file.close()
384
385 comments_file = open(doc_comments_path, 'r+')
386 self._doc_comments = json.load(comments_file)
387 comments_file.close()
388
389 def GetFormattedMetadata(self, library_name, interface_name, member_id=None,
390 indentation=''):
391 """ Gets all comments and annotations for an interface or member.
392 """
393 return self.FormatMetadata(
394 self.GetMetadata(library_name, interface_name, member_id),
395 indentation)
396
397 def GetMetadata(self, library_name, interface_name,
398 member_name=None, source_member_name=None):
399 """ Gets all comments and annotations for an interface or member.
400
401 Args:
402 source_member_name: If the member is dependent on a different member
403 then this is used to apply the support annotations from the other
404 member.
405 """
406 annotations = self._GetComments(library_name, interface_name, member_name)
407 annotations = annotations + self._GetCommonAnnotations(
408 interface_name, member_name, source_member_name)
409
410 return annotations
411
412 def GetDart2JSMetadata(self, idl_type, library_name,
413 interface_name, member_name,):
414 """ Gets all annotations for Dart2JS members- including annotations for
415 both dart2js and dartium.
416 """
417 annotations = self.GetMetadata(library_name, interface_name, member_name)
418
419 ann2 = self._GetDart2JSSpecificAnnotations(idl_type, interface_name, member_ name)
420 if ann2:
421 if annotations:
422 annotations.extend(ann2)
423 else:
424 annotations = ann2
425 return annotations
426
427 def _GetCommonAnnotations(self, interface_name, member_name=None,
428 source_member_name=None):
429 if member_name:
430 key = '%s.%s' % (interface_name, member_name)
431 else:
432 key = interface_name
433
434 annotations = ["@DomName('" + key + "')"]
435
436 # Only add this for members, so we don't add DocsEditable to templated
437 # classes (they get it from the default class template)
438 if member_name:
439 annotations.append('@DocsEditable');
440
441 if key in _annotations:
442 annotations.extend(_annotations[key])
443
444 if (member_name and member_name.startswith('webkit') and
445 key not in renamed_html_members):
446 annotations.extend(_webkit_experimental_annotations)
447
448 if source_member_name:
449 member_name = source_member_name
450
451 # TODO(blois): Emit support level annotations
452 self._GetSupportLevelAnnotation(interface_name, member_name)
453
454 return annotations
455
456 def _GetComments(self, library_name, interface_name, member_name=None):
457 """ Gets all comments for the interface or member and returns a list. """
458
459 # Add documentation from JSON.
460 comments = []
461 library_name = 'dart.dom.%s' % library_name
462 if library_name in self._doc_comments:
463 library_info = self._doc_comments[library_name]
464 if interface_name in library_info:
465 interface_info = library_info[interface_name]
466 if member_name:
467 if 'members' in interface_info and member_name in interface_info['memb ers']:
468 comments = interface_info['members'][member_name]
469 elif 'comment' in interface_info:
470 comments = interface_info['comment']
471
472 if comments:
473 comments = ['\n'.join(comments)]
474
475 return comments
476
477
478 def AnyConversionAnnotations(self, idl_type, interface_name, member_name):
479 if (_annotations.get('%s.%s' % (interface_name, member_name)) or
480 self._GetDart2JSSpecificAnnotations(idl_type, interface_name, member_nam e)):
481 return True
482 else:
483 return False
484
485 def FormatMetadata(self, metadata, indentation):
486 if metadata:
487 newline = '\n%s' % indentation
488 result = newline.join(metadata) + newline
489 return result
490 return ''
491
492 def _GetDart2JSSpecificAnnotations(self, idl_type, interface_name, member_name ):
493 """ Finds dart2js-specific annotations. This does not include ones shared wi th
494 dartium.
495 """
496 ann1 = _dart2js_annotations.get("%s.%s" % (interface_name, member_name))
497 if ann1:
498 ann2 = _dart2js_annotations.get('+' + idl_type)
499 if ann2:
500 return ann2 + ann1
501 ann2 = _dart2js_annotations.get(idl_type)
502 if ann2:
503 return ann2 + ann1
504 return ann1
505
506 ann2 = _dart2js_annotations.get('-' + idl_type)
507 if ann2:
508 return ann2
509 ann2 = _dart2js_annotations.get(idl_type)
510 return ann2
511
512 def _GetSupportLevel(self, interface_id, member_id=None):
513 """ Looks up the interface or member in the DOM status list and returns the
514 support level for it.
515 """
516 if interface_id in self._types:
517 type_info = self._types[interface_id]
518 else:
519 type_info = {
520 'members': {},
521 'support_level': 'untriaged',
522 }
523 self._types[interface_id] = type_info
524
525 if not member_id:
526 return type_info.get('support_level')
527
528 members = type_info['members']
529
530 if member_id in members:
531 member_info = members[member_id]
532 else:
533 if member_id == interface_id:
534 member_info = {}
535 else:
536 member_info = {'support_level': 'untriaged'}
537 members[member_id] = member_info
538
539 support_level = member_info.get('support_level')
540 # If unset then it inherits from the type.
541 if not support_level:
542 support_level = type_info.get('support_level')
543 return support_level
544
545 def _GetSupportLevelAnnotation(self, interface_id, member_id=None):
546 support_level = self._GetSupportLevel(interface_id, member_id)
547
548 if support_level == 'untriaged':
549 return '@Experimental'
550 elif support_level == 'experimental':
551 return '@Experimental'
552 elif support_level == 'nonstandard':
553 return '@Experimental'
554 elif support_level == 'stable':
555 return
556 elif support_level == 'deprecated':
557 return '@Deprecated'
sra1 2013/04/30 01:29:43 else raise error?
558
559 def Flush(self):
560 json_file = open(self._api_status_path, 'w+')
561 json.dump(self._types, json_file, indent=2, separators=(',', ': '), sort_key s=True)
562 json_file.close()
OLDNEW
« no previous file with comments | « tools/dom/scripts/dartdomgenerator.py ('k') | tools/dom/scripts/generator.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698