Flutter Engine
The Flutter Engine
Public Member Functions | Public Attributes | List of all members
scripts.idlnode.IDLType Class Reference
Inheritance diagram for scripts.idlnode.IDLType:
scripts.idlnode.IDLNode

Public Member Functions

def __init__ (self, ast, id=None)
 
- Public Member Functions inherited from scripts.idlnode.IDLNode
def __init__ (self, ast, id=None)
 
def __repr__ (self)
 
def __eq__ (self, other)
 
def __hash__ (self)
 
def reset_id (self, newId)
 
def all (self, type_filter=None)
 
def to_dict (self)
 
def to_hash (self)
 

Public Attributes

 nullable
 
 id
 
- Public Attributes inherited from scripts.idlnode.IDLNode
 id
 
 ext_attrs
 
 annotations
 
 members
 

Detailed Description

IDLType is used to describe constants, attributes and operations'
return and input types. IDLType matches AST labels such as ScopedName,
StringType, VoidType, IntegerType, etc.
NOTE: AST of None implies synthesize IDLType the id is passed in used by
    setlike.

Definition at line 654 of file idlnode.py.

Constructor & Destructor Documentation

◆ __init__()

def scripts.idlnode.IDLType.__init__ (   self,
  ast,
  id = None 
)
Initializes an IDLNode from a PegParser AST output.

Reimplemented from scripts.idlnode.IDLNode.

Definition at line 661 of file idlnode.py.

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 # Support synthesized IDLType with no AST (e.g., setlike support).
668 return
669
670 self.nullable = self._has(ast, 'Nullable')
671 # Search for a 'ScopedName' or any label ending with 'Type'.
672 if isinstance(ast, list):
673 self.id = self._find_first(ast, 'ScopedName')
674 if not self.id:
675 # FIXME: use regexp search instead
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 # TODO(terry): Remove array_modifiers id has [] appended, keep for old
690 # parsing.
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 # New blink handling.
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 # Report of union types mapped to any.
709 if not (self.id in _unions_to_any):
710 _unions_to_any.append(self.id)
711 # TODO(terry): For union types use any otherwise type is unionType is
712 # not found and is removed during merging.
713 self.id = 'any'
714 else:
715 type_name = str(ast)
716 # TODO(terry): For now don't handle unrestricted types see
717 # https://code.google.com/p/chromium/issues/detail?id=354298
718 type_name = type_name.replace('unrestricted ', '', 1)
719
720 # TODO(terry): Handled USVString as a DOMString.
721 type_name = type_name.replace('USVString', 'DOMString', 1)
722 type_name = type_name.replace('HTMLString', 'DOMString', 1)
723
724 # TODO(terry); WindowTimers setInterval/setTimeout overloads with a
725 # Function type - map to any until the IDL uses union.
726 type_name = type_name.replace('Function', 'any', 1)
727
728 self.id = type_name
729 else:
730 # IdlUnionType
731 if ast.is_union_type:
732 if not (self.id in _unions_to_any):
733 _unions_to_any.append(self.id)
734 # TODO(terry): For union types use any otherwise type is unionType is
735 # not found and is removed during merging.
736 self.id = 'any'
737 # TODO(terry): Any union type e.g. 'type1 or type2 or type2',
738 # 'typedef (Type1 or Type2) UnionType'
739 # Is a problem we need to extend IDLType and IDLTypeDef to handle more
740 # than one type.
741 #
742 # Also for typedef's e.g.,
743 # typedef (Type1 or Type2) UnionType
744 # should consider synthesizing a new interface (e.g., UnionType) that's
745 # both Type1 and Type2.
746 if not self.id:
747 print('>>>> __module__ %s' % ast.__module__)
748 raise SyntaxError('Could not parse type %s' % (ast))
749
def print(*args, **kwargs)
Definition: run_tests.py:49

Member Data Documentation

◆ id

scripts.idlnode.IDLType.id

Definition at line 673 of file idlnode.py.

◆ nullable

scripts.idlnode.IDLType.nullable

Definition at line 670 of file idlnode.py.


The documentation for this class was generated from the following file: