Flutter Engine
The Flutter Engine
Public Member Functions | List of all members
scripts.htmldartgenerator.HtmlDartGenerator Class Reference
Inheritance diagram for scripts.htmldartgenerator.HtmlDartGenerator:
scripts.systemhtml.Dart2JSBackend scripts.systemnative.DartiumBackend

Public Member Functions

def __init__ (self, interface, options, dart_use_blink, logger)
 
def EmitSupportCheck (self)
 
def EmitEventGetter (self, events_class_name)
 
def AddMembers (self, interface, declare_only=False, dart_js_interop=False)
 
def AddSecondaryMembers (self, interface)
 
def OmitOperationOverrides (self)
 
def AddConstant (self, constant)
 
def AddAttribute (self, attribute, declare_only=False)
 
def AddOperation (self, info, declare_only=False, dart_js_interop=False)
 
def AdditionalImplementedInterfaces (self)
 
def Mixins (self)
 
def AddConstructors (self, constructors, factory_name, factory_constructor_name, constructor_emitter)
 
def EmitHelpers (self, base_class, members_emitter)
 
def DeclareAttribute (self, attribute, attr_name, read_only)
 
def DeclareOperation (self, operation, return_type_name, method_name)
 
def EmitListMixin (self, element_name, nullable)
 
def SecureOutputType (self, type_name, is_dart_type=False, can_narrow_type=False, nullable=False)
 
def SecureBaseName (self, type_name)
 
def is_DOM_type (self, type_name)
 

Detailed Description

Definition at line 40 of file htmldartgenerator.py.

Constructor & Destructor Documentation

◆ __init__()

def scripts.htmldartgenerator.HtmlDartGenerator.__init__ (   self,
  interface,
  options,
  dart_use_blink,
  logger 
)

Reimplemented in scripts.systemnative.DartiumBackend, and scripts.systemhtml.Dart2JSBackend.

Definition at line 42 of file htmldartgenerator.py.

42 def __init__(self, interface, options, dart_use_blink, logger):
43 self._dart_use_blink = dart_use_blink
44 self._database = options.database
45 self._interface = interface
46 self._type_registry = options.type_registry
47 self._interface_type_info = self._type_registry.TypeInfo(
48 self._interface.id)
49 self._renamer = options.renamer
50 self._metadata = options.metadata
51 self._library_name = self._renamer.GetLibraryName(self._interface)
52 self._mdn_reader = MDNReader()
53 _logger.setLevel(logger.level)
54

Member Function Documentation

◆ AddAttribute()

def scripts.htmldartgenerator.HtmlDartGenerator.AddAttribute (   self,
  attribute,
  declare_only = False 
)
 Adds an attribute to the generated class.
Arguments:
attribute - The attribute which is to be added.
declare_only- True if the attribute should be declared as an abstract
member and not include invocation code.

Definition at line 297 of file htmldartgenerator.py.

297 def AddAttribute(self, attribute, declare_only=False):
298 """ Adds an attribute to the generated class.
299 Arguments:
300 attribute - The attribute which is to be added.
301 declare_only- True if the attribute should be declared as an abstract
302 member and not include invocation code.
303 """
304 dom_name = DartDomNameOfAttribute(attribute)
305 attr_name = self._renamer.RenameMember(self._interface.id, attribute,
306 dom_name, 'get:')
307 if not attr_name:
308 return
309
310 html_setter_name = self._renamer.RenameMember(
311 self._interface.id, attribute, dom_name, 'set:')
312 read_only = (attribute.is_read_only or
313 'Replaceable' in attribute.ext_attrs or
314 not html_setter_name)
315
316 # We don't yet handle inconsistent renames of the getter and setter yet.
317 assert (not html_setter_name or attr_name == html_setter_name)
318
319 # any is assumed to be nullable
320 if attribute.type.id == 'any':
321 attribute.type.nullable = True
322
323 if declare_only:
324 self.DeclareAttribute(attribute, attr_name, read_only)
325 else:
326 self.EmitAttribute(attribute, attr_name, read_only)
327

◆ AddConstant()

def scripts.htmldartgenerator.HtmlDartGenerator.AddConstant (   self,
  constant 
)

Definition at line 276 of file htmldartgenerator.py.

276 def AddConstant(self, constant):
277 const_name = self._renamer.RenameMember(
278 self._interface.id,
279 constant,
280 constant.id,
281 'get:',
282 dartify_name=False)
283 if not const_name:
284 return
285
286 annotations = self._metadata.GetFormattedMetadata(
287 self._library_name, self._interface, constant.id, ' ')
288
289 type = TypeOrNothing(self._DartType(constant.type.id), constant.type.id)
290 self._members_emitter.Emit(
291 '\n $(ANNOTATIONS)static const $TYPE$NAME = $VALUE;\n',
292 ANNOTATIONS=annotations,
293 NAME=const_name,
294 TYPE=type,
295 VALUE=constant.value)
296

◆ AddConstructors()

def scripts.htmldartgenerator.HtmlDartGenerator.AddConstructors (   self,
  constructors,
  factory_name,
  factory_constructor_name,
  constructor_emitter 
)
 Adds all of the constructors.
Arguments:
constructors - List of the constructors to be added.
factory_name - Name of the factory for this class.
factory_constructor_name - The name of the constructor on the
  factory_name to call (calls an autogenerated FactoryProvider
  if unspecified)
constructor_emitter - Emitter used to emit constructors when generating
  classes using the static extension pattern.

Definition at line 538 of file htmldartgenerator.py.

539 factory_constructor_name, constructor_emitter):
540 """ Adds all of the constructors.
541 Arguments:
542 constructors - List of the constructors to be added.
543 factory_name - Name of the factory for this class.
544 factory_constructor_name - The name of the constructor on the
545 factory_name to call (calls an autogenerated FactoryProvider
546 if unspecified)
547 constructor_emitter - Emitter used to emit constructors when generating
548 classes using the static extension pattern.
549 """
550 for constructor_info in constructors:
551 self._AddConstructor(constructor_info, factory_name,
552 factory_constructor_name, constructor_emitter)
553

◆ AdditionalImplementedInterfaces()

def scripts.htmldartgenerator.HtmlDartGenerator.AdditionalImplementedInterfaces (   self)

Reimplemented in scripts.systemhtml.Dart2JSBackend.

Definition at line 515 of file htmldartgenerator.py.

515 def AdditionalImplementedInterfaces(self):
516 # TODO: Include all implemented interfaces, including other Lists.
517 implements = []
518 if self._interface_type_info.list_item_type():
519 item_type = self._type_registry.TypeInfo(
520 self._interface_type_info.list_item_type()).dart_type()
521 if self._interface_type_info.list_item_type_nullable():
522 item_type += '?'
523 implements.append('List<%s>' % item_type)
524 return implements
525

◆ AddMembers()

def scripts.htmldartgenerator.HtmlDartGenerator.AddMembers (   self,
  interface,
  declare_only = False,
  dart_js_interop = False 
)

Definition at line 77 of file htmldartgenerator.py.

77 def AddMembers(self, interface, declare_only=False, dart_js_interop=False):
78 if self._interface.id == 'WebGLRenderingContextBase' or self._interface.id == 'WebGL2RenderingContextBase' or \
79 self._interface.id == 'WebGLDrawBuffers':
80 # Constants in classes WebGLRenderingContextBase, WebGL2RenderingContext, WebGLDrawBuffers are consolidated into
81 # one synthesized class (WebGL).
82 self._gl_constants.extend(interface.constants)
83 else:
84 for const in sorted(interface.constants, key=ConstantOutputOrder):
85 self.AddConstant(const)
86
87 for attr in sorted(interface.attributes, key=ConstantOutputOrder):
88 if attr.type.id != 'EventHandler' and attr.type.id != 'EventListener':
89 self.AddAttribute(attr, declare_only)
90
91 # The implementation should define an indexer if the interface directly
92 # extends List.
93 element_type = None
94 requires_indexer = False
95 if self._interface_type_info.list_item_type():
96 self.AddIndexer(self._interface_type_info.list_item_type(),
97 self._interface_type_info.list_item_type_nullable())
98 else:
99 for parent in self._database.Hierarchy(self._interface):
100 if parent == self._interface:
101 continue
102 parent_type_info = self._type_registry.TypeInfo(parent.id)
103 if parent_type_info.list_item_type():
104 self.AmendIndexer(parent_type_info.list_item_type())
105 break
106
107 # Group overloaded operations by name.
108 self._AddRenamedOverloads(interface)
109 operationsByName = self._OperationsByName(interface)
110 if self.OmitOperationOverrides():
111 self._RemoveShadowingOperationsWithSameSignature(
112 operationsByName, interface)
113
114 # Generate operations.
115 for id in sorted(operationsByName.keys()):
116 operations = operationsByName[id]
117 info = AnalyzeOperation(interface, operations)
118 self.AddOperation(info, declare_only, dart_js_interop)
119 if ('%s.%s' % (interface.id,
120 info.declared_name) in convert_to_future_members):
121 self.AddOperation(ConvertToFuture(info), declare_only)
122

◆ AddOperation()

def scripts.htmldartgenerator.HtmlDartGenerator.AddOperation (   self,
  info,
  declare_only = False,
  dart_js_interop = False 
)

Definition at line 328 of file htmldartgenerator.py.

328 def AddOperation(self, info, declare_only=False, dart_js_interop=False):
329 # TODO(terry): Hack window has 2 overloaded getter one returns Window and
330 # and other object (we'll always return Window)?
331 if self._interface.id == "Window" and info.name == '__getter__':
332 info.operations[1].type = info.operations[0].type
333 """ Adds an operation to the generated class.
334 Arguments:
335 info - The operation info of the operation to be added.
336 declare_only- True if the operation should be declared as an abstract
337 member and not include invocation code.
338 """
339 # FIXME: When we pass in operations[0] below, we're assuming all
340 # overloaded operations have the same security attributes. This
341 # is currently true, but we should consider filtering earlier or
342 # merging the relevant data into info itself.
343 method_name = self._renamer.RenameMember(
344 self._interface.id, info.operations[0], info.name, 'call:')
345 if not method_name:
346 if info.name == 'item':
347 # FIXME: item should be renamed to operator[], not removed.
348 self.EmitOperation(info, '_item')
349 return
350
351 if declare_only:
352 self.DeclareOperation(info,
353 self.SecureOutputType(info.type_name,
354 nullable=info.type_nullable),
355 method_name)
356 else:
357 self.EmitOperation(info, method_name, dart_js_interop)
358

◆ AddSecondaryMembers()

def scripts.htmldartgenerator.HtmlDartGenerator.AddSecondaryMembers (   self,
  interface 
)

Definition at line 123 of file htmldartgenerator.py.

123 def AddSecondaryMembers(self, interface):
124 secondary_parents = self._database.TransitiveSecondaryParents(
125 interface, not self._dart_use_blink)
126 remove_duplicate_parents = list(set(secondary_parents))
127 if len(secondary_parents) != len(remove_duplicate_parents):
128 secondary_parents = remove_duplicate_parents
129 parent_list = ", ".join(
130 [" %s" % (parent.id) for parent in secondary_parents])
131 _logger.warn('Interface %s has duplicate parent interfaces %s - ' \
132 'ignoring duplicates. Please file a bug with the dart:html team.' % (interface.id, parent_list))
133
134 for parent_interface in sorted(secondary_parents,
135 key=ConstantOutputOrder):
136 if isinstance(parent_interface, str):
137 continue
138
139 for attr in sorted(parent_interface.attributes,
140 key=ConstantOutputOrder):
141 if not FindMatchingAttribute(interface, attr):
142 if attr.type.id != 'EventHandler':
143 self.SecondaryContext(parent_interface)
144 self.AddAttribute(attr)
145
146 # Group overloaded operations by name.
147 operationsByName = self._OperationsByName(parent_interface)
148
149 if self.OmitOperationOverrides():
150 self._RemoveShadowingOperationsWithSameSignature(
151 operationsByName, interface)
152
153 # Generate operations.
154 for id in sorted(operationsByName.keys()):
155 if not any(op.id == id for op in interface.operations):
156 operations = operationsByName[id]
157 info = AnalyzeOperation(interface, operations)
158 self.SecondaryContext(parent_interface)
159 self.AddOperation(info)
160
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not set
Definition: switches.h:76
SIT bool any(const Vec< 1, T > &x)
Definition: SkVx.h:530
static SkString join(const CommandLineFlags::StringArray &)
Definition: skpbench.cpp:741

◆ DeclareAttribute()

def scripts.htmldartgenerator.HtmlDartGenerator.DeclareAttribute (   self,
  attribute,
  attr_name,
  read_only 
)
 Declares an attribute but does not include the code to invoke it.

Definition at line 834 of file htmldartgenerator.py.

834 def DeclareAttribute(self, attribute, attr_name, read_only):
835 """ Declares an attribute but does not include the code to invoke it.
836 """
837 if read_only:
838 # HACK(terry): Element is not abstract for Dartium so isContentEditable
839 # must have a body see impl_Element.darttemplate
840 if (self._interface.id == 'Element' and
841 attr_name == 'isContentEditable' and self._dart_js_interop):
842 return
843 else:
844 template = '\n $TYPE get $NAME;\n'
845 else:
846 template = '\n $TYPE get $NAME native;\n' \
847 '\n set $NAME($TYPE value) native;\n'
848
849 # Nullability is determined by attribute compatibility.
850 is_compat = self._mdn_reader.is_compatible(attribute)
851 nullable = attribute.type.nullable or not is_compat
852
853 self._members_emitter.Emit(template,
854 NAME=attr_name,
855 TYPE=self.SecureOutputType(
856 attribute.type.id, nullable=nullable))
857
static bool is_compatible(const GrSurfaceCharacterization &gsc, const GrBackendTexture &backendTex)

◆ DeclareOperation()

def scripts.htmldartgenerator.HtmlDartGenerator.DeclareOperation (   self,
  operation,
  return_type_name,
  method_name 
)
 Declares an operation but does not include the code to invoke it.
Arguments:
operation - The operation to be declared.
return_type_name - The name of the return type.
method_name - The name of the method.

Definition at line 858 of file htmldartgenerator.py.

858 def DeclareOperation(self, operation, return_type_name, method_name):
859 """ Declares an operation but does not include the code to invoke it.
860 Arguments:
861 operation - The operation to be declared.
862 return_type_name - The name of the return type.
863 method_name - The name of the method.
864 """
865 # HACK(terry): Element is not abstract for Dartium so click
866 # must have a body see impl_Element.darttemplate
867 if (self._interface.id == 'Element' and method_name == 'click' and
868 self._dart_js_interop):
869 return
870 else:
871 template = '\n $TYPE $NAME($PARAMS);\n'
872
873 self._members_emitter.Emit(
874 template,
875 TYPE=return_type_name,
876 NAME=method_name,
877 PARAMS=operation.ParametersAsDeclaration(self._DartType))
878

◆ EmitEventGetter()

def scripts.htmldartgenerator.HtmlDartGenerator.EmitEventGetter (   self,
  events_class_name 
)

Definition at line 70 of file htmldartgenerator.py.

70 def EmitEventGetter(self, events_class_name):
71 self._members_emitter.Emit(
72 "EventTarget.removeEventListener, EventTarget.dispatchEvent')"
73 "\n @deprecated"
74 "\n $TYPE get on =>\n new $TYPE(this);\n",
75 TYPE=events_class_name)
76

◆ EmitHelpers()

def scripts.htmldartgenerator.HtmlDartGenerator.EmitHelpers (   self,
  base_class,
  members_emitter 
)

Definition at line 821 of file htmldartgenerator.py.

821 def EmitHelpers(self, base_class, members_emitter):
822 if (not self._members_emitter) and (not members_emitter):
823 return
824
825 if self._interface.id not in custom_html_constructors:
826 target_emitter = members_emitter if members_emitter else \
827 self._members_emitter
828 target_emitter.Emit(
829 ' // To suppress missing implicit constructor warnings.\n'
830 ' factory $CLASSNAME._() { '
831 'throw new UnsupportedError("Not supported"); }\n',
832 CLASSNAME=self._interface_type_info.implementation_name())
833

◆ EmitListMixin()

def scripts.htmldartgenerator.HtmlDartGenerator.EmitListMixin (   self,
  element_name,
  nullable 
)

Definition at line 879 of file htmldartgenerator.py.

879 def EmitListMixin(self, element_name, nullable):
880 # TODO(sra): Use separate mixins for mutable implementations of List<T>.
881 # TODO(sra): Use separate mixins for typed array implementations of List<T>.
882 template_file = 'immutable_list_mixin.darttemplate'
883 has_length = False
884 has_length_setter = False
885
886 def _HasExplicitIndexedGetter(self):
887 return any(op.id == 'getItem' for op in self._interface.operations)
888
889 def _HasCustomIndexedGetter(self):
890 return 'CustomIndexedGetter' in self._interface.ext_attrs
891
892 def _HasNativeIndexedGetter(self):
893 return not (_HasCustomIndexedGetter(self) or
894 _HasExplicitIndexedGetter(self))
895
896 if _HasExplicitIndexedGetter(self):
897 getter_name = 'getItem'
898 else:
899 getter_name = '_nativeIndexedGetter'
900
901 for attr in self._interface.attributes:
902 if attr.id == 'length':
903 has_length = True
904 has_length_setter = not attr.is_read_only
905
906 has_num_items = any(
907 attr.id == 'numberOfItems' for attr in self._interface.attributes)
908
909 template = self._template_loader.Load(
910 template_file, {
911 'DEFINE_LENGTH_AS_NUM_ITEMS':
912 not has_length and has_num_items,
913 'DEFINE_LENGTH_SETTER':
914 not has_length_setter,
915 'USE_NATIVE_INDEXED_GETTER':
916 _HasNativeIndexedGetter(self) or
917 _HasExplicitIndexedGetter(self),
918 })
919 if nullable:
920 element_js = element_name + "|Null"
921 element_name += '?'
922 else:
923 element_js = element_name
924 self._members_emitter.Emit(
925 template, E=element_name, EJS=element_js, GETTER=getter_name)
926

◆ EmitSupportCheck()

def scripts.htmldartgenerator.HtmlDartGenerator.EmitSupportCheck (   self)

Definition at line 55 of file htmldartgenerator.py.

55 def EmitSupportCheck(self):
56 if self.HasSupportCheck():
57 check = self.GetSupportCheck()
58 if type(check) != tuple:
59 signature = 'get supported'
60 else:
61 signature = check[0]
62 check = check[1]
63 self._members_emitter.Emit(
64 '\n'
65 ' /// Checks if this type is supported on the current platform.\n'
66 ' static bool $SIGNATURE => $SUPPORT_CHECK;\n',
67 SIGNATURE=signature,
68 SUPPORT_CHECK=check)
69
GLenum type

◆ is_DOM_type()

def scripts.htmldartgenerator.HtmlDartGenerator.is_DOM_type (   self,
  type_name 
)

Definition at line 961 of file htmldartgenerator.py.

961 def is_DOM_type(self, type_name):
962 try:
963 self._type_registry.TypeInfo(type_name)
964 return True
965 except RuntimeError:
966 return False
967

◆ Mixins()

def scripts.htmldartgenerator.HtmlDartGenerator.Mixins (   self)

Definition at line 526 of file htmldartgenerator.py.

526 def Mixins(self):
527 mixins = []
528 if self._interface_type_info.list_item_type():
529 item_type = self._type_registry.TypeInfo(
530 self._interface_type_info.list_item_type()).dart_type()
531 if self._interface_type_info.list_item_type_nullable():
532 item_type += '?'
533 mixins.append('ListMixin<%s>' % item_type)
534 mixins.append('ImmutableListMixin<%s>' % item_type)
535
536 return mixins
537

◆ OmitOperationOverrides()

def scripts.htmldartgenerator.HtmlDartGenerator.OmitOperationOverrides (   self)

Reimplemented in scripts.systemhtml.Dart2JSBackend.

Definition at line 273 of file htmldartgenerator.py.

273 def OmitOperationOverrides(self):
274 return False
275

◆ SecureBaseName()

def scripts.htmldartgenerator.HtmlDartGenerator.SecureBaseName (   self,
  type_name 
)

Definition at line 957 of file htmldartgenerator.py.

957 def SecureBaseName(self, type_name):
958 if type_name in _secure_base_types:
959 return _secure_base_types[type_name]
960

◆ SecureOutputType()

def scripts.htmldartgenerator.HtmlDartGenerator.SecureOutputType (   self,
  type_name,
  is_dart_type = False,
  can_narrow_type = False,
  nullable = False 
)
 Converts the type name to the secure type name for return types.
Arguments:
can_narrow_type - True if the output type can be narrowed further than
what would be accepted for input, used to narrow num APIs down to double
or int.

Definition at line 927 of file htmldartgenerator.py.

931 nullable=False):
932 """ Converts the type name to the secure type name for return types.
933 Arguments:
934 can_narrow_type - True if the output type can be narrowed further than
935 what would be accepted for input, used to narrow num APIs down to double
936 or int.
937 """
938 if is_dart_type:
939 dart_name = type_name
940 else:
941 type_info = self._TypeInfo(type_name)
942 dart_name = type_info.dart_type()
943 if can_narrow_type and dart_name == 'num':
944 dart_name = type_info.native_type()
945
946 # We only need to secure Window. Only local History and Location are
947 # returned in generated code.
948 assert (dart_name != 'HistoryBase' and dart_name != 'LocationBase')
949 if dart_name == 'Window':
950 dart_name = _secure_base_types[dart_name]
951 if type_name == 'any':
952 dart_name = 'Object'
953 if nullable and dart_name != 'dynamic':
954 dart_name = dart_name + '?'
955 return dart_name
956

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