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

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

Issue 952133004: Changes to support roll 39 IDLs (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Cleanup Created 5 years, 9 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/htmlrenamer.py ('k') | tools/dom/scripts/systemhtml.py » ('j') | 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) 2011, the Dart project authors. Please see the AUTHORS file 2 # Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
3 # for details. All rights reserved. Use of this source code is governed by a 3 # for details. All rights reserved. Use of this source code is governed by a
4 # BSD-style license that can be found in the LICENSE file. 4 # BSD-style license that can be found in the LICENSE file.
5 5
6 import os 6 import os
7 import sys 7 import sys
8 8
9 import idl_definitions 9 import idl_definitions
10 from idl_types import IdlType, IdlUnionType, IdlArrayOrSequenceType 10 from idl_types import IdlType, IdlNullableType, IdlUnionType, IdlArrayOrSequence Type
11 11
12 from compute_interfaces_info_overall import interfaces_info 12 from compute_interfaces_info_overall import interfaces_info
13 13
14 14
15 new_asts = {} 15 new_asts = {}
16 16
17 17
18 _operation_suffix_map = { 18 _operation_suffix_map = {
19 '__getter__': "Getter", 19 '__getter__': "Getter",
20 '__setter__': "Setter", 20 '__setter__': "Setter",
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 res.append(value) 159 res.append(value)
160 # TODO(terry): Seems bogus to check for so many things probably better to ju st 160 # TODO(terry): Seems bogus to check for so many things probably better to ju st
161 # pass in blink_compile and drive it off from that... 161 # pass in blink_compile and drive it off from that...
162 elif (ast and not(isinstance(ast, dict)) and 162 elif (ast and not(isinstance(ast, dict)) and
163 not(isinstance(ast, str)) and 163 not(isinstance(ast, str)) and
164 (ast.__module__ == "idl_definitions" or ast.__module__ == "idl_types") ): 164 (ast.__module__ == "idl_definitions" or ast.__module__ == "idl_types") ):
165 field_name = self._convert_label_to_field(label) 165 field_name = self._convert_label_to_field(label)
166 if hasattr(ast, field_name): 166 if hasattr(ast, field_name):
167 field_value = getattr(ast, field_name) 167 field_value = getattr(ast, field_name)
168 if field_value: 168 if field_value:
169 if label == 'Interface' or label == 'Enum': 169 if label == 'Interface' or label == 'Enum' or label == "Dictionary":
170 for key in field_value: 170 for key in field_value:
171 value = field_value[key] 171 value = field_value[key]
172 res.append(value) 172 res.append(value)
173 elif isinstance(field_value, list): 173 elif isinstance(field_value, list):
174 for item in field_value: 174 for item in field_value:
175 res.append(item) 175 res.append(item)
176 elif label == 'ParentInterface' or label == 'InterfaceType': 176 elif label == 'ParentInterface' or label == 'InterfaceType':
177 # Fetch the AST for the parent interface. 177 # Fetch the AST for the parent interface.
178 parent_idlnode = new_asts[field_value] 178 parent_idlnode = new_asts[field_value]
179 res.append(parent_idlnode.interfaces[field_value]) 179 res.append(parent_idlnode.interfaces[field_value])
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 'Argument': 'arguments', 215 'Argument': 'arguments',
216 'InterfaceType': 'name', 216 'InterfaceType': 'name',
217 'ConstExpr': 'value', 217 'ConstExpr': 'value',
218 'Static': 'is_static', 218 'Static': 'is_static',
219 'ReadOnly': 'is_read_only', 219 'ReadOnly': 'is_read_only',
220 'Optional': 'is_optional', 220 'Optional': 'is_optional',
221 'Nullable': 'is_nullable', 221 'Nullable': 'is_nullable',
222 'Enum': 'enumerations', 222 'Enum': 'enumerations',
223 'Annotation': '', # TODO(terry): Ignore annotation used for databa se cache. 223 'Annotation': '', # TODO(terry): Ignore annotation used for databa se cache.
224 'TypeDef': '', # typedef in an IDL are already resolved. 224 'TypeDef': '', # typedef in an IDL are already resolved.
225 'Dictionary': 'dictionaries',
226 'Member': 'members',
227 'Default': 'default_value', # Dictionary member default value
225 } 228 }
226 result = label_field.get(label) 229 result = label_field.get(label)
227 if result != '' and not(result): 230 if result != '' and not(result):
228 print 'FATAL ERROR: AST mapping name not found %s.' % label 231 print 'FATAL ERROR: AST mapping name not found %s.' % label
229 return result if result else '' 232 return result if result else ''
230 233
231 def _convert_all(self, ast, label, idlnode_ctor): 234 def _convert_all(self, ast, label, idlnode_ctor):
232 """Converts AST elements into IDLNode elements. 235 """Converts AST elements into IDLNode elements.
233 Uses _find_all to find elements with a given label and converts 236 Uses _find_all to find elements with a given label and converts
234 them into IDLNodes with a given constructor. 237 them into IDLNodes with a given constructor.
(...skipping 24 matching lines...) Expand all
259 return idlnode_ctor(childAst) 262 return idlnode_ctor(childAst)
260 263
261 def _convert_ext_attrs(self, ast): 264 def _convert_ext_attrs(self, ast):
262 """Helper method for uniform conversion of extended attributes.""" 265 """Helper method for uniform conversion of extended attributes."""
263 self.ext_attrs = IDLExtAttrs(ast) 266 self.ext_attrs = IDLExtAttrs(ast)
264 267
265 def _convert_annotations(self, ast): 268 def _convert_annotations(self, ast):
266 """Helper method for uniform conversion of annotations.""" 269 """Helper method for uniform conversion of annotations."""
267 self.annotations = IDLAnnotations(ast) 270 self.annotations = IDLAnnotations(ast)
268 271
272 def _convert_constants(self, ast, js_name):
273 """Helper method for uniform conversion of dictionary members."""
274 self.members = IDLDictionaryMembers(ast, js_name)
275
269 276
270 class IDLDictNode(IDLNode): 277 class IDLDictNode(IDLNode):
271 """Base class for dictionary-like IDL nodes such as extended attributes 278 """Base class for dictionary-like IDL nodes such as extended attributes
272 and annotations. The base class implements various dict interfaces.""" 279 and annotations. The base class implements various dict interfaces."""
273 280
274 def __init__(self, ast): 281 def __init__(self, ast):
275 IDLNode.__init__(self, None) 282 IDLNode.__init__(self, None)
276 if ast is not None and isinstance(ast, dict): 283 if ast is not None and isinstance(ast, dict):
277 self.__map = ast 284 self.__map = ast
278 else: 285 else:
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 343
337 DART_IDL = 'dart.idl' 344 DART_IDL = 'dart.idl'
338 345
339 def __init__(self, ast, filename=None): 346 def __init__(self, ast, filename=None):
340 IDLNode.__init__(self, ast) 347 IDLNode.__init__(self, ast)
341 self.filename = filename 348 self.filename = filename
342 349
343 filename_basename = os.path.basename(filename) 350 filename_basename = os.path.basename(filename)
344 351
345 self.interfaces = self._convert_all(ast, 'Interface', IDLInterface) 352 self.interfaces = self._convert_all(ast, 'Interface', IDLInterface)
353 self.dictionaries = self._convert_all(ast, 'Dictionary', IDLDictionary)
346 354
347 is_blink = not(isinstance(ast, list)) and ast.__module__ == 'idl_definitions ' 355 is_blink = not(isinstance(ast, list)) and ast.__module__ == 'idl_definitions '
348 356
349 if is_blink: 357 if is_blink:
350 # implements is handled by the interface merging step (see the function 358 # implements is handled by the interface merging step (see the function
351 # merge_interface_dependencies). 359 # merge_interface_dependencies).
352 for interface in self.interfaces: 360 for interface in self.interfaces:
353 blink_interface = ast.interfaces.get(interface.id) 361 blink_interface = ast.interfaces.get(interface.id)
354 if filename_basename == self.DART_IDL: 362 if filename_basename == self.DART_IDL:
355 # Special handling for dart.idl we need to remember the interface, 363 # Special handling for dart.idl we need to remember the interface,
356 # since we could have many (not one interface / file). Then build up 364 # since we could have many (not one interface / file). Then build up
357 # the IDLImplementsStatement for any implements in dart.idl. 365 # the IDLImplementsStatement for any implements in dart.idl.
358 interface_info = interfaces_info['__dart_idl___']; 366 interface_info = interfaces_info['__dart_idl___'];
359 367
360 self.implementsStatements = [] 368 self.implementsStatements = []
361 369
362 implement_pairs = interface_info['implement_pairs'] 370 implement_pairs = interface_info['implement_pairs']
363 for implement_pair in implement_pairs: 371 for implement_pair in implement_pairs:
364 interface_name = implement_pair[0] 372 interface_name = implement_pair[0]
365 implemented_name = implement_pair[1] 373 implemented_name = implement_pair[1]
366 374
367 implementor = new_asts[interface_name].interfaces.get(interface_name ) 375 implementor = new_asts[interface_name].interfaces.get(interface_name )
368 implement_statement = self._createImplementsStatement(implementor, 376 implement_statement = self._createImplementsStatement(implementor,
369 implemented_na me) 377 implemented_na me)
370 378
371 self.implementsStatements.append(implement_statement) 379 self.implementsStatements.append(implement_statement)
372 else: 380 elif interface.id in interfaces_info:
373 interface_info = interfaces_info[interface.id] 381 interface_info = interfaces_info[interface.id]
374 382
375 implements = interface_info['implements_interfaces'] 383 implements = interface_info['implements_interfaces']
376 if not(blink_interface.is_partial) and len(implements) > 0: 384 if not(blink_interface.is_partial) and len(implements) > 0:
377 implementor = new_asts[interface.id].interfaces.get(interface.id) 385 implementor = new_asts[interface.id].interfaces.get(interface.id)
378 386
379 self.implementsStatements = [] 387 self.implementsStatements = []
380 388
381 # TODO(terry): Need to handle more than one implements. 389 # TODO(terry): Need to handle more than one implements.
382 for implemented_name in implements: 390 for implemented_name in implements:
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
448 for constructor in ast.constructors: 456 for constructor in ast.constructors:
449 if constructor.name == 'NamedConstructor': 457 if constructor.name == 'NamedConstructor':
450 constructor_name = ast.extended_attributes['NamedConstructor'] 458 constructor_name = ast.extended_attributes['NamedConstructor']
451 else: 459 else:
452 constructor_name = None 460 constructor_name = None
453 func_value = IDLExtAttrFunctionValue(constructor_name, constructor.a rguments, True) 461 func_value = IDLExtAttrFunctionValue(constructor_name, constructor.a rguments, True)
454 if name == 'Constructor': 462 if name == 'Constructor':
455 self.setdefault('Constructor', []).append(func_value) 463 self.setdefault('Constructor', []).append(func_value)
456 else: 464 else:
457 self[name] = func_value 465 self[name] = func_value
466 elif name == 'SetWrapperReferenceTo':
467 # NOTE: No need to process handling for GC wrapper. But if its a refe rence
468 # to another type via an IdlArgument we'd need to convert to IDLArgume nt
469 # otherwise the type might be a reference to another type and the circ ularity
470 # will break deep_copy which is done later to the interfaces in the
471 # database. If we every need SetWrapperReferenceTo then we'd need to
472 # convert IdlArgument to IDLArgument.
473 continue
458 else: 474 else:
459 self[name] = value 475 self[name] = value
460 else: 476 else:
461 ext_attrs_ast = self._find_first(ast, 'ExtAttrs') 477 ext_attrs_ast = self._find_first(ast, 'ExtAttrs')
462 if not ext_attrs_ast: 478 if not ext_attrs_ast:
463 return 479 return
464 for ext_attr in self._find_all(ext_attrs_ast, 'ExtAttr'): 480 for ext_attr in self._find_all(ext_attrs_ast, 'ExtAttr'):
465 name = self._find_first(ext_attr, 'Id') 481 name = self._find_first(ext_attr, 'Id')
466 value = self._find_first(ext_attr, 'ExtAttrValue') 482 value = self._find_first(ext_attr, 'ExtAttrValue')
467 483
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
540 elif isinstance(ast, tuple): 556 elif isinstance(ast, tuple):
541 (label, value) = ast 557 (label, value) = ast
542 if label == 'ScopedName': 558 if label == 'ScopedName':
543 self.id = value 559 self.id = value
544 else: 560 else:
545 self.id = self._label_to_type(label, ast) 561 self.id = self._label_to_type(label, ast)
546 elif isinstance(ast, str): 562 elif isinstance(ast, str):
547 self.id = ast 563 self.id = ast
548 # New blink handling. 564 # New blink handling.
549 elif ast.__module__ == "idl_types": 565 elif ast.__module__ == "idl_types":
550 if isinstance(ast, IdlType) or isinstance(ast, IdlArrayOrSequenceType): 566 if isinstance(ast, IdlType) or isinstance(ast, IdlArrayOrSequenceType) or \
567 isinstance(ast, IdlNullableType):
551 type_name = str(ast) 568 type_name = str(ast)
552 569
553 # TODO(terry): For now don't handle unrestricted types see 570 # TODO(terry): For now don't handle unrestricted types see
554 # https://code.google.com/p/chromium/issues/detail?id=35429 8 571 # https://code.google.com/p/chromium/issues/detail?id=35429 8
555 type_name = type_name.replace('unrestricted ', '', 1); 572 type_name = type_name.replace('unrestricted ', '', 1);
556 573
557 # TODO(terry): Handled ScalarValueString as a DOMString. 574 # TODO(terry): Handled ScalarValueString as a DOMString.
558 type_name = type_name.replace('ScalarValueString', 'DOMString', 1) 575 type_name = type_name.replace('ScalarValueString', 'DOMString', 1)
559 576
560 self.id = type_name 577 self.id = type_name
561 else: 578 else:
562 # IdlUnionType 579 # IdlUnionType
563 if ast.is_union_type: 580 if ast.is_union_type:
564 print 'WARNING type %s is union mapped to \'any\'' % self.id 581 print 'WARNING type %s is union mapped to \'any\'' % self.id
565 # TODO(terry): For union types use any otherwise type is unionType is 582 # TODO(terry): For union types use any otherwise type is unionType is
566 # not found and is removed during merging. 583 # not found and is removed during merging.
567 self.id = 'any' 584 self.id = 'any'
568 # TODO(terry): Any union type e.g. 'type1 or type2 or type2', 585 # TODO(terry): Any union type e.g. 'type1 or type2 or type2',
569 # 'typedef (Type1 or Type2) UnionType' 586 # 'typedef (Type1 or Type2) UnionType'
570 # Is a problem we need to extend IDLType and IDLTypeDef to handle more 587 # Is a problem we need to extend IDLType and IDLTypeDef to handle more
571 # than one type. 588 # than one type.
572 # 589 #
573 # Also for typedef's e.g., 590 # Also for typedef's e.g.,
574 # typedef (Type1 or Type2) UnionType 591 # typedef (Type1 or Type2) UnionType
575 # should consider synthesizing a new interface (e.g., UnionType) that's 592 # should consider synthesizing a new interface (e.g., UnionType) that's
576 # both Type1 and Type2. 593 # both Type1 and Type2.
577 if not self.id: 594 if not self.id:
(...skipping 28 matching lines...) Expand all
606 623
607 624
608 class IDLTypeDef(IDLNode): 625 class IDLTypeDef(IDLNode):
609 """IDLNode for 'typedef [type] [id]' declarations.""" 626 """IDLNode for 'typedef [type] [id]' declarations."""
610 def __init__(self, ast): 627 def __init__(self, ast):
611 IDLNode.__init__(self, ast) 628 IDLNode.__init__(self, ast)
612 self._convert_annotations(ast) 629 self._convert_annotations(ast)
613 self.type = self._convert_first(ast, 'Type', IDLType) 630 self.type = self._convert_first(ast, 'Type', IDLType)
614 631
615 632
633 class IDLDictionary(IDLNode):
634 """IDLDictionary node contains members,
635 as well as parent references."""
636
637 def __init__(self, ast):
638 IDLNode.__init__(self, ast)
639
640 self.javascript_binding_name = self.id
641 self._convert_ext_attrs(ast)
642 self._convert_constants(ast, self.id)
643
644
645 class IDLDictionaryMembers(IDLDictNode):
646 """IDLDictionaryMembers specialization for a list of FremontCut dictionary val ues."""
647 def __init__(self, ast=None, js_name=None):
648 IDLDictNode.__init__(self, ast)
649 self.id = None
650 if not ast:
651 return
652 for member in self._find_all(ast, 'Member'):
653 name = self._find_first(member, 'Id')
654 value = IDLDictionaryMember(member, js_name)
655 self[name] = value
656
657
616 class IDLInterface(IDLNode): 658 class IDLInterface(IDLNode):
617 """IDLInterface node contains operations, attributes, constants, 659 """IDLInterface node contains operations, attributes, constants,
618 as well as parent references.""" 660 as well as parent references."""
619 661
620 def __init__(self, ast): 662 def __init__(self, ast):
621 IDLNode.__init__(self, ast) 663 IDLNode.__init__(self, ast)
622 self._convert_ext_attrs(ast) 664 self._convert_ext_attrs(ast)
623 self._convert_annotations(ast) 665 self._convert_annotations(ast)
624 666
625 self.parents = self._convert_all(ast, 'ParentInterface', 667 self.parents = self._convert_all(ast, 'ParentInterface',
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
778 self.optional = self._has(ast, 'Optional') 820 self.optional = self._has(ast, 'Optional')
779 self._convert_ext_attrs(ast) 821 self._convert_ext_attrs(ast)
780 # TODO(vsm): Recover this from the type instead. 822 # TODO(vsm): Recover this from the type instead.
781 if 'Callback' in self.type.id: 823 if 'Callback' in self.type.id:
782 self.ext_attrs['Callback'] = None 824 self.ext_attrs['Callback'] = None
783 825
784 def __repr__(self): 826 def __repr__(self):
785 return '<IDLArgument(type = %s, id = %s)>' % (self.type, self.id) 827 return '<IDLArgument(type = %s, id = %s)>' % (self.type, self.id)
786 828
787 829
830 class IDLDictionaryMember(IDLMember):
831 """IDLNode specialization for 'const type name = value' declarations."""
832 def __init__(self, ast, doc_js_interface_name):
833 IDLMember.__init__(self, ast, doc_js_interface_name)
834 default_value = self._find_first(ast, 'Default')
835 self.value = default_value.value if default_value else None
836
837
788 class IDLImplementsStatement(IDLNode): 838 class IDLImplementsStatement(IDLNode):
789 """IDLNode specialization for 'IMPLEMENTOR implements IMPLEMENTED' declaration s.""" 839 """IDLNode specialization for 'IMPLEMENTOR implements IMPLEMENTED' declaration s."""
790 def __init__(self, ast): 840 def __init__(self, ast):
791 IDLNode.__init__(self, ast) 841 IDLNode.__init__(self, ast)
792 if isinstance(ast, list) or ast.__module__ != 'idl_definitions': 842 if isinstance(ast, list) or ast.__module__ != 'idl_definitions':
793 self.implementor = self._convert_first(ast, 'ImplStmtImplementor', IDLType ) 843 self.implementor = self._convert_first(ast, 'ImplStmtImplementor', IDLType )
794 self.implemented = self._convert_first(ast, 'ImplStmtImplemented', IDLType ) 844 self.implemented = self._convert_first(ast, 'ImplStmtImplemented', IDLType )
795 845
796 846
797 class IDLAnnotations(IDLDictNode): 847 class IDLAnnotations(IDLDictNode):
(...skipping 13 matching lines...) Expand all
811 """IDLDictNode specialization for one annotation.""" 861 """IDLDictNode specialization for one annotation."""
812 def __init__(self, ast=None): 862 def __init__(self, ast=None):
813 IDLDictNode.__init__(self, ast) 863 IDLDictNode.__init__(self, ast)
814 self.id = None 864 self.id = None
815 if not ast: 865 if not ast:
816 return 866 return
817 for arg in self._find_all(ast, 'AnnotationArg'): 867 for arg in self._find_all(ast, 'AnnotationArg'):
818 name = self._find_first(arg, 'Id') 868 name = self._find_first(arg, 'Id')
819 value = self._find_first(arg, 'AnnotationArgValue') 869 value = self._find_first(arg, 'AnnotationArgValue')
820 self[name] = value 870 self[name] = value
OLDNEW
« no previous file with comments | « tools/dom/scripts/htmlrenamer.py ('k') | tools/dom/scripts/systemhtml.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698