661 def __init__(self, ast, id=None):
662 global _unions_to_any
663
664 IDLNode.__init__(self, ast, id)
665
666 if not ast:
667
668 return
669
670 self.nullable = self._has(ast, 'Nullable')
671
672 if isinstance(ast, list):
673 self.id = self._find_first(ast, 'ScopedName')
674 if not self.id:
675
676 def findType(ast):
677 for label, childAst in ast:
678 if label.endswith('Type'):
679 type = self._label_to_type(label, ast)
680 if type != 'sequence':
681 return type
682 type_ast = self._find_first(childAst, 'Type')
683 if not type_ast:
684 return type
685 return 'sequence<%s>' % findType(type_ast)
686 raise Exception('No type declaration found in %s' % ast)
687
688 self.id = findType(ast)
689
690
691 array_modifiers = self._find_first(ast, 'ArrayModifiers')
692 if array_modifiers:
693 self.id += array_modifiers
694 elif isinstance(ast, tuple):
695 (label, value) = ast
696 if label == 'ScopedName':
697 self.id = value
698 else:
699 self.id = self._label_to_type(label, ast)
700 elif isinstance(ast, str):
701 self.id = ast
702
703 elif ast.__module__ == "idl_types":
704 if isinstance(ast, IdlType) or isinstance(ast, IdlArrayOrSequenceType) or \
705 isinstance(ast, IdlNullableType):
706 if isinstance(ast,
707 IdlNullableType) and ast.inner_type.is_union_type:
708
709 if not (self.id in _unions_to_any):
710 _unions_to_any.append(self.id)
711
712
713 self.id = 'any'
714 else:
715 type_name = str(ast)
716
717
718 type_name = type_name.replace('unrestricted ', '', 1)
719
720
721 type_name = type_name.replace('USVString', 'DOMString', 1)
722 type_name = type_name.replace('HTMLString', 'DOMString', 1)
723
724
725
726 type_name = type_name.replace('Function', 'any', 1)
727
728 self.id = type_name
729 else:
730
731 if ast.is_union_type:
732 if not (self.id in _unions_to_any):
733 _unions_to_any.append(self.id)
734
735
736 self.id = 'any'
737
738
739
740
741
742
743
744
745
746 if not self.id:
747 print(
'>>>> __module__ %s' % ast.__module__)
748 raise SyntaxError('Could not parse type %s' % (ast))
749