Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | List of all members
scripts.databasebuilder.DatabaseBuilder Class Reference
Inheritance diagram for scripts.databasebuilder.DatabaseBuilder:

Public Member Functions

 __init__ (self, database)
 
 merge_imported_interfaces (self)
 
 import_idl_files (self, file_paths, import_options, is_dart_idl)
 
 fix_displacements (self, source)
 
 normalize_annotations (self, sources)
 
 map_dictionaries (self)
 
 fetch_constructor_data (self, options)
 
 examine_database (self)
 

Public Attributes

 conditionals_met
 
 build
 
 global_type_defs
 

Protected Member Functions

 _resolve_type_defs (self, idl_file)
 
 _strip_ext_attributes (self, idl_file)
 
 _rename_types (self, idl_file, import_options)
 
 _annotate (self, interface, import_options)
 
 _sign (self, node)
 
 _build_signatures_map (self, idl_node_list)
 
 _get_parent_interfaces (self, interface)
 
 _merge_ext_attrs (self, old_attrs, new_attrs)
 
 _merge_nodes (self, old_list, new_list, import_options)
 
 _merge_interfaces (self, old_interface, new_interface, import_options)
 
 _merge_impl_stmt (self, impl_stmt, import_options)
 
 _compute_dart_idl_implements (self, idl_filename)
 
 _blink_compile_idl_files (self, file_paths, import_options, is_dart_idl)
 
 _process_ast (self, filename, ast)
 
 _process_idl_file (self, idl_file, import_options, dart_idl=False)
 
 _is_node_enabled (self, node, idl_defines)
 
 _output_examination (self, check_dictionaries=True)
 
 _mark_usage (self, interface, operation_or_attribute=None, check_dictionaries=True)
 
 _remember_usage (self, node, check_dictionaries=True)
 
 _dictionary_used (self, type_node)
 
 _no_interface_used (self, type_node)
 
 _constructors (self, interface, check_dictionaries=True)
 
 _attribute_operation (self, interface, operation_attribute, check_dictionaries=True)
 
 _dictionary_constructor_types (self, node)
 
 _no_interface_constructor_types (self, node)
 
 _TABULATE_WIDTH (self)
 
 _tabulate_title (self, row_title)
 
 _tabulate_break (self)
 
 _tabulate (self, columns)
 

Protected Attributes

 _info_collector
 
 _database
 
 _imported_interfaces
 
 _impl_stmts
 
 _diag_dictionaries
 
 _dictionaries_used_types
 
 _diag_no_interfaces
 
 _no_interfaces_used_types
 
 _dictionary_used
 
 _no_interface_used
 

Detailed Description

Definition at line 173 of file databasebuilder.py.

Constructor & Destructor Documentation

◆ __init__()

scripts.databasebuilder.DatabaseBuilder.__init__ (   self,
  database 
)
DatabaseBuilder is used for importing and merging interfaces into
the Database

Definition at line 175 of file databasebuilder.py.

175 def __init__(self, database):
176 """DatabaseBuilder is used for importing and merging interfaces into
177 the Database"""
178 self._info_collector = InterfaceInfoCollector()
179
180 self._database = database
181 self._imported_interfaces = []
182 self._impl_stmts = []
183 self.conditionals_met = set()
184
185 # Spin up the new IDL parser.
186 self.build = Build(self)
187
188 # Global typedef to mapping.
189 self.global_type_defs = monitored.Dict(
190 'databasebuilder.global_type_defs', {
191 'Transferable': 'MessagePort',
192 })
193

Member Function Documentation

◆ _annotate()

scripts.databasebuilder.DatabaseBuilder._annotate (   self,
  interface,
  import_options 
)
protected
Adds @ annotations based on the source and source_attributes
members of import_options.

Definition at line 243 of file databasebuilder.py.

243 def _annotate(self, interface, import_options):
244 """Adds @ annotations based on the source and source_attributes
245 members of import_options."""
246
247 source = import_options.source
248 if not source:
249 return
250
251 def add_source_annotation(idl_node):
252 annotation = IDLAnnotation(
253 copy.deepcopy(import_options.source_attributes))
254 idl_node.annotations[source] = annotation
255 if ((isinstance(idl_node, IDLInterface) or
256 isinstance(idl_node, IDLMember)) and
257 idl_node.is_fc_suppressed):
258 annotation['suppressed'] = None
259
260 add_source_annotation(interface)
261
262 list(map(add_source_annotation, interface.parents))
263 list(map(add_source_annotation, interface.constants))
264 list(map(add_source_annotation, interface.attributes))
265 list(map(add_source_annotation, interface.operations))
266

◆ _attribute_operation()

scripts.databasebuilder.DatabaseBuilder._attribute_operation (   self,
  interface,
  operation_attribute,
  check_dictionaries = True 
)
protected

Definition at line 1033 of file databasebuilder.py.

1036 check_dictionaries=True):
1037 if check_dictionaries:
1038 self._dictionaries_used_types = []
1039 used = self._dictionary_used
1040 else:
1041 self._no_interfaces_used_types = []
1042 used = self._no_interface_used
1043
1044 list(map(used, operation_attribute.all(IDLType)))
1045
1046 self._remember_usage(
1047 operation_attribute, check_dictionaries=check_dictionaries)
1048 self._mark_usage(
1049 interface,
1050 operation_attribute,
1051 check_dictionaries=check_dictionaries)
1052

◆ _blink_compile_idl_files()

scripts.databasebuilder.DatabaseBuilder._blink_compile_idl_files (   self,
  file_paths,
  import_options,
  is_dart_idl 
)
protected

Definition at line 586 of file databasebuilder.py.

586 def _blink_compile_idl_files(self, file_paths, import_options, is_dart_idl):
587 if not (is_dart_idl):
588 start_time = time.time()
589
590 # Compute information for individual files
591 # Information is stored in global variables interfaces_info and
592 # partial_interface_files.
593 for file_path in file_paths:
594 self._info_collector.collect_info(file_path)
595
596 end_time = time.time()
597 print('Compute dependencies %s seconds' % round(
598 (end_time - start_time), 2))
599 else:
600 # Compute the interface_info for dart.idl for implements defined. This
601 # file is special in that more than one interface can exist in this file.
602 implement_pairs = self._compute_dart_idl_implements(file_paths[0])
603
604 self._info_collector.interfaces_info['__dart_idl___'] = {
605 'implement_pairs': implement_pairs,
606 }
607
608 # Parse the IDL files serially.
609 start_time = time.time()
610
611 for file_path in file_paths:
612 file_path = os.path.normpath(file_path)
613 ast = _compile_idl_file(self.build, file_path, import_options)
614 self._process_ast(
615 os.path.splitext(os.path.basename(file_path))[0], ast)
616
617 end_time = time.time()
618 print('Compiled %s IDL files in %s seconds' %
619 (len(file_paths), round((end_time - start_time), 2)))
620
static void round(SkPoint *p)
void print(void *str)
Definition bridge.cpp:126

◆ _build_signatures_map()

scripts.databasebuilder.DatabaseBuilder._build_signatures_map (   self,
  idl_node_list 
)
protected
Creates a hash table mapping signatures to idl_nodes for the
given list of nodes

Definition at line 308 of file databasebuilder.py.

308 def _build_signatures_map(self, idl_node_list):
309 """Creates a hash table mapping signatures to idl_nodes for the
310 given list of nodes"""
311 res = {}
312 for idl_node in idl_node_list:
313 sig = self._sign(idl_node)
314 if sig is None:
315 continue
316 if sig in res:
317 op = res[sig]
318 # Only report if the operations that match are either both suppressed
319 # or both not suppressed. Optional args aren't part of type signature
320 # for this routine. Suppressing a non-optional type and supplementing
321 # with an optional type appear the same.
322 if idl_node.is_fc_suppressed == op.is_fc_suppressed:
323 raise RuntimeError(
324 'Warning: Multiple members have the same '
325 ' signature: "%s"' % sig)
326 res[sig] = idl_node
327 return res
328

◆ _compute_dart_idl_implements()

scripts.databasebuilder.DatabaseBuilder._compute_dart_idl_implements (   self,
  idl_filename 
)
protected

Definition at line 572 of file databasebuilder.py.

572 def _compute_dart_idl_implements(self, idl_filename):
573 full_path = os.path.realpath(idl_filename)
574
575 with open(full_path) as f:
576 idl_file_contents = f.read()
577
578 implements_re = (r'^\s*' r'(\w+)\s+' r'implements\s+' r'(\w+)\s*' r';')
579
580 implements_matches = re.finditer(implements_re, idl_file_contents,
581 re.MULTILINE)
582 return [match.groups() for match in implements_matches]
583

◆ _constructors()

scripts.databasebuilder.DatabaseBuilder._constructors (   self,
  interface,
  check_dictionaries = True 
)
protected

Definition at line 1019 of file databasebuilder.py.

1019 def _constructors(self, interface, check_dictionaries=True):
1020 if check_dictionaries:
1021 self._dictionaries_used_types = []
1022 constructor_function = self._dictionary_constructor_types
1023 else:
1024 self._no_interfaces_used_types = []
1025 constructor_function = self._no_interface_constructor_types
1026
1027 list(map(constructor_function, interface.all(IDLExtAttrFunctionValue)))
1028
1029 self._mark_usage(interface, check_dictionaries=check_dictionaries)
1030

◆ _dictionary_constructor_types()

scripts.databasebuilder.DatabaseBuilder._dictionary_constructor_types (   self,
  node 
)
protected

Definition at line 1055 of file databasebuilder.py.

1055 def _dictionary_constructor_types(self, node):
1056 self._dictionaries_used_types = []
1057 list(map(self._dictionary_used, node.all(IDLType)))
1058 self._remember_usage(node)
1059

◆ _dictionary_used()

scripts.databasebuilder.DatabaseBuilder._dictionary_used (   self,
  type_node 
)
protected

Definition at line 989 of file databasebuilder.py.

989 def _dictionary_used(self, type_node):
990 if hasattr(type_node, 'dictionary'):
991 dictionary_id = type_node.dictionary
992 if self._database.HasDictionary(dictionary_id):
993 for diag_dictionary in self._diag_dictionaries:
994 if diag_dictionary['dictionary'].id == dictionary_id:
995 # Record the dictionary that was referenced.
996 self._dictionaries_used_types.append(dictionary_id)
997 return
998
999 # If we get to this point, the IDL dictionary was never defined ... oops.
1000 print('DIAGNOSE_ERROR: IDL Dictionary %s doesn\'t exist.' %
1001 dictionary_id)
1002
static void append(char **dst, size_t *count, const char *src, size_t n)
Definition editor.cpp:211

◆ _get_parent_interfaces()

scripts.databasebuilder.DatabaseBuilder._get_parent_interfaces (   self,
  interface 
)
protected
Return a list of all the parent interfaces of a given interface

Definition at line 329 of file databasebuilder.py.

329 def _get_parent_interfaces(self, interface):
330 """Return a list of all the parent interfaces of a given interface"""
331 res = []
332
333 def recurse(current_interface):
334 if current_interface in res:
335 return
336 res.append(current_interface)
337 for parent in current_interface.parents:
338 parent_name = parent.type.id
339 if self._database.HasInterface(parent_name):
340 recurse(self._database.GetInterface(parent_name))
341
342 recurse(interface)
343 return res[1:]
344

◆ _is_node_enabled()

scripts.databasebuilder.DatabaseBuilder._is_node_enabled (   self,
  node,
  idl_defines 
)
protected

Definition at line 688 of file databasebuilder.py.

688 def _is_node_enabled(self, node, idl_defines):
689 if not 'Conditional' in node.ext_attrs:
690 return True
691
692 def enabled(condition):
693 return 'ENABLE_%s' % condition in idl_defines
694
695 conditional = node.ext_attrs['Conditional']
696 if conditional.find('&') != -1:
697 for condition in conditional.split('&'):
698 condition = condition.strip()
699 self.conditionals_met.add(condition)
700 if not enabled(condition):
701 return False
702 return True
703
704 for condition in conditional.split('|'):
705 condition = condition.strip()
706 self.conditionals_met.add(condition)
707 if enabled(condition):
708 return True
709 return False
710

◆ _mark_usage()

scripts.databasebuilder.DatabaseBuilder._mark_usage (   self,
  interface,
  operation_or_attribute = None,
  check_dictionaries = True 
)
protected

Definition at line 930 of file databasebuilder.py.

933 check_dictionaries=True):
934 for diag in self._diag_dictionaries if check_dictionaries else self._diag_no_interfaces:
935 for usage in diag['usages']:
936 if not usage['interface']:
937 usage['interface'] = interface.id
938 if isinstance(operation_or_attribute, IDLOperation):
939 usage['operation'] = operation_or_attribute.id
940 if check_dictionaries:
941 usage['result'] = hasattr(operation_or_attribute.type, 'dictionary') and \
942 operation_or_attribute.type.dictionary == diag['dictionary'].id
943 else:
944 usage[
945 'result'] = operation_or_attribute.type.id == diag[
946 'no_interface_object'].id
947 usage['argument'] = False
948 for argument in operation_or_attribute.arguments:
949 if check_dictionaries:
950 arg = hasattr(
951 argument.type, 'dictionary'
952 ) and argument.type.dictionary == diag[
953 'dictionary'].id
954 else:
955 arg = argument.type.id == diag[
956 'no_interface_object'].id
957 if arg:
958 usage['argument'] = arg
959 elif isinstance(operation_or_attribute, IDLAttribute):
960 usage['attribute'] = operation_or_attribute.id
961 usage['result'] = True
962 usage[
963 'argument'] = not operation_or_attribute.is_read_only
964 elif not operation_or_attribute:
965 # Its a constructor only argument is dictionary or interface with NoInterfaceObject.
966 usage['operation'] = 'constructor'
967 usage['result'] = False
968 usage['argument'] = True
969

◆ _merge_ext_attrs()

scripts.databasebuilder.DatabaseBuilder._merge_ext_attrs (   self,
  old_attrs,
  new_attrs 
)
protected
Merges two sets of extended attributes.

Returns: True if old_attrs has changed.

Definition at line 345 of file databasebuilder.py.

345 def _merge_ext_attrs(self, old_attrs, new_attrs):
346 """Merges two sets of extended attributes.
347
348 Returns: True if old_attrs has changed.
349 """
350 changed = False
351 for (name, value) in new_attrs.items():
352 if name in old_attrs and old_attrs[name] == value:
353 pass # Identical
354 else:
355 if name == 'ImplementedAs' and name in old_attrs:
356 continue
357 old_attrs[name] = value
358 changed = True
359 return changed
360

◆ _merge_impl_stmt()

scripts.databasebuilder.DatabaseBuilder._merge_impl_stmt (   self,
  impl_stmt,
  import_options 
)
protected
Applies "X implements Y" statements on the proper places in the
database

Definition at line 507 of file databasebuilder.py.

507 def _merge_impl_stmt(self, impl_stmt, import_options):
508 """Applies "X implements Y" statements on the proper places in the
509 database"""
510 implementor_name = impl_stmt.implementor.id
511 implemented_name = impl_stmt.implemented.id
512 _logger.info('merging impl stmt %s implements %s' % (implementor_name,
513 implemented_name))
514
515 source = import_options.source
516 if self._database.HasInterface(implementor_name):
517 interface = self._database.GetInterface(implementor_name)
518 if interface.parents is None:
519 interface.parents = []
520 for parent in interface.parents:
521 if parent.type.id == implemented_name:
522 if source and source not in parent.annotations:
523 parent.annotations[source] = IDLAnnotation(
524 import_options.source_attributes)
525 return
526 # not found, so add new one
527 parent = IDLParentInterface(None)
528 parent.type = IDLType(implemented_name)
529 if source:
530 parent.annotations[source] = IDLAnnotation(
531 import_options.source_attributes)
532 interface.parents.append(parent)
533

◆ _merge_interfaces()

scripts.databasebuilder.DatabaseBuilder._merge_interfaces (   self,
  old_interface,
  new_interface,
  import_options 
)
protected
Merges the new_interface into the old_interface, annotating the
interface with the sources of each change.

Definition at line 452 of file databasebuilder.py.

452 def _merge_interfaces(self, old_interface, new_interface, import_options):
453 """Merges the new_interface into the old_interface, annotating the
454 interface with the sources of each change."""
455
456 changed = False
457
458 source = import_options.source
459 if (source and source not in old_interface.annotations and
460 source in new_interface.annotations and
461 not new_interface.is_supplemental):
462 old_interface.annotations[source] = new_interface.annotations[
463 source]
464 changed = True
465
466 def merge_list(what):
467 old_list = old_interface.__dict__[what]
468 new_list = new_interface.__dict__[what]
469
470 if what != 'parents' and old_interface.id != new_interface.id:
471 for node in new_list:
472 node.doc_js_interface_name = old_interface.id
473 node.ext_attrs['ImplementedBy'] = new_interface.id
474
475 changed = self._merge_nodes(old_list, new_list, import_options)
476
477 # Delete list items with zero remaining annotations.
478 if changed and import_options.obsolete_old_declarations:
479
480 def has_annotations(idl_node):
481 return len(idl_node.annotations)
482
483 old_interface.__dict__[what] = \
484 list(filter(has_annotations, old_list))
485
486 return changed
487
488 # Smartly merge various declarations:
489 if merge_list('parents'):
490 changed = True
491 if merge_list('constants'):
492 changed = True
493 if merge_list('attributes'):
494 changed = True
495 if merge_list('operations'):
496 changed = True
497
498 if self._merge_ext_attrs(old_interface.ext_attrs,
499 new_interface.ext_attrs):
500 changed = True
501
502 _logger.info('merged interface %s (changed=%s, supplemental=%s)' %
503 (old_interface.id, changed, new_interface.is_supplemental))
504
505 return changed
506

◆ _merge_nodes()

scripts.databasebuilder.DatabaseBuilder._merge_nodes (   self,
  old_list,
  new_list,
  import_options 
)
protected
Merges two lists of nodes. Annotates nodes with the source of each
node.

Returns:
True if the old_list has changed.

Args:
old_list -- the list to merge into.
new_list -- list containing more nodes.
import_options -- controls how merging is done.

Definition at line 361 of file databasebuilder.py.

361 def _merge_nodes(self, old_list, new_list, import_options):
362 """Merges two lists of nodes. Annotates nodes with the source of each
363 node.
364
365 Returns:
366 True if the old_list has changed.
367
368 Args:
369 old_list -- the list to merge into.
370 new_list -- list containing more nodes.
371 import_options -- controls how merging is done.
372 """
373 changed = False
374
375 source = import_options.source
376
377 old_signatures_map = self._build_signatures_map(old_list)
378 new_signatures_map = self._build_signatures_map(new_list)
379
380 # Merge new items
381 for (sig, new_node) in new_signatures_map.items():
382 if sig not in old_signatures_map:
383 # New node:
384 old_list.append(new_node)
385 changed = True
386 else:
387 # Merge old and new nodes:
388 old_node = old_signatures_map[sig]
389 if (source not in old_node.annotations and
390 source in new_node.annotations):
391 old_node.annotations[source] = new_node.annotations[source]
392 changed = True
393 # Maybe rename arguments:
394 if isinstance(old_node, IDLOperation):
395 for i in range(0, len(old_node.arguments)):
396 old_arg = old_node.arguments[i]
397 new_arg = new_node.arguments[i]
398
399 old_arg_name = old_arg.id
400 new_arg_name = new_arg.id
401 if (old_arg_name != new_arg_name and
402 (old_arg_name == 'arg' or
403 old_arg_name.endswith('Arg') or
404 import_options.rename_operation_arguments_on_merge)
405 ):
406 old_node.arguments[i].id = new_arg_name
407 changed = True
408
409 if self._merge_ext_attrs(old_arg.ext_attrs,
410 new_arg.ext_attrs):
411 changed = True
412
413 # Merge in [Default=Undefined] and DOMString a = null handling in
414 # IDL. The IDL model (IDLArgument) coalesces these two different
415 # default value syntaxes into the default_value* models.
416 old_default_value = old_arg.default_value
417 new_default_value = new_arg.default_value
418 old_default_value_is_null = old_arg.default_value_is_null
419 new_default_value_is_null = new_arg.default_value_is_null
420 if old_default_value != new_default_value:
421 old_arg.default_value = new_default_value
422 changed = True
423 if old_default_value_is_null != new_default_value_is_null:
424 old_arg.default_value_is_null = new_default_value_is_null
425 changed = True
426
427 # Merge in any optional argument differences.
428 old_optional = old_arg.optional
429 new_optional = new_arg.optional
430 if old_optional != new_optional:
431 old_arg.optional = new_optional
432 changed = True
433 # Maybe merge annotations:
434 if (isinstance(old_node, IDLAttribute) or
435 isinstance(old_node, IDLOperation)):
436 if self._merge_ext_attrs(old_node.ext_attrs,
437 new_node.ext_attrs):
438 changed = True
439
440 # Remove annotations on obsolete items from the same source
441 if import_options.obsolete_old_declarations:
442 for (sig, old_node) in old_signatures_map.items():
443 if (source in old_node.annotations and
444 sig not in new_signatures_map):
445 _logger.warn(
446 '%s not available in %s anymore' % (sig, source))
447 del old_node.annotations[source]
448 changed = True
449
450 return changed
451

◆ _no_interface_constructor_types()

scripts.databasebuilder.DatabaseBuilder._no_interface_constructor_types (   self,
  node 
)
protected

Definition at line 1062 of file databasebuilder.py.

1062 def _no_interface_constructor_types(self, node):
1063 self._no_interfaces_used_types = []
1064 list(map(self._no_interface_used, node.all(IDLType)))
1065 self._remember_usage(node, check_dictionaries=False)
1066

◆ _no_interface_used()

scripts.databasebuilder.DatabaseBuilder._no_interface_used (   self,
  type_node 
)
protected

Definition at line 1005 of file databasebuilder.py.

1005 def _no_interface_used(self, type_node):
1006 if hasattr(type_node, 'id'):
1007 no_interface_id = type_node.id
1008 if self._database.HasInterface(no_interface_id):
1009 no_interface = self._database.GetInterface(no_interface_id)
1010 if no_interface.is_no_interface_object:
1011 for diag_no_interface in self._diag_no_interfaces:
1012 if diag_no_interface[
1013 'no_interface_object'].id == no_interface_id:
1014 # Record the interface marked with NoInterfaceObject.
1015 self._no_interfaces_used_types.append(
1016 no_interface_id)
1017 return
1018

◆ _output_examination()

scripts.databasebuilder.DatabaseBuilder._output_examination (   self,
  check_dictionaries = True 
)
protected

Definition at line 886 of file databasebuilder.py.

886 def _output_examination(self, check_dictionaries=True):
887 # Output diagnostics. First columns is Dictionary or NoInterfaceObject e.g.,
888 # | Dictionary | Used In Interface | Usage Operation/Attribute |
889 print('\n\n')
890 title_bar = ['Dictionary', 'Used In Interface', 'Usage Operation/Attribute'] if check_dictionaries \
891 else ['NoInterfaceObject (Ops,Props,New)', 'Used In Interface', 'Usage Operation/Attribute']
892 self._tabulate_title(title_bar)
893 diags = self._diag_dictionaries if check_dictionaries else self._diag_no_interfaces
894 for diag in diags:
895 if not (check_dictionaries):
896 interface = diag['no_interface_object']
897 ops_count = len(interface.operations)
898 properties_count = len(interface.attributes)
899 any_constructors = 'Constructor' in interface.ext_attrs
900 constructors = 'T(%s)' % len(interface.ext_attrs['Constructor']
901 ) if any_constructors else 'F'
902 interface_detail = '%s (%s,%s,%s)' % \
903 (diag['no_interface_object'].id,
904 ops_count,
905 properties_count,
906 constructors)
907 self._tabulate([interface_detail, '', ''])
908 else:
909 dictionary = diag['dictionary']
910 any_constructors = 'Constructor' in dictionary.ext_attrs
911 self._tabulate([
912 '%s%s' % (dictionary.id,
913 ' (New)' if any_constructors else ''), '', ''
914 ])
915 for usage in diag['usages']:
916 detail = ''
917 if 'attribute' in usage:
918 attribute_type = 'READ-ONLY' if not usage[
919 'argument'] else 'GET/SET'
920 detail = '(%s) %s' % (attribute_type, usage['attribute'])
921 elif 'operation' in usage:
922 detail = '%s %s%s' % ('RETURN' if usage['result'] else '',
923 usage['operation'], '(ARGUMENT)'
924 if usage['argument'] else '')
925 self._tabulate([None, usage['interface'], detail])
926 self._tabulate_break()
927

◆ _process_ast()

scripts.databasebuilder.DatabaseBuilder._process_ast (   self,
  filename,
  ast 
)
protected

Definition at line 621 of file databasebuilder.py.

621 def _process_ast(self, filename, ast):
622 if len(ast) == 1:
623 ast = next(iter(ast.values()))
624 else:
625 print('ERROR: Processing AST: ' + os.path.basename(file_name))
626 new_asts[filename] = ast
627
static float next(float f)

◆ _process_idl_file()

scripts.databasebuilder.DatabaseBuilder._process_idl_file (   self,
  idl_file,
  import_options,
  dart_idl = False 
)
protected

Definition at line 649 of file databasebuilder.py.

649 def _process_idl_file(self, idl_file, import_options, dart_idl=False):
650 # TODO(terry): strip_ext_attributes on an idl_file does nothing.
651 #self._strip_ext_attributes(idl_file)
652 self._resolve_type_defs(idl_file)
653 self._rename_types(idl_file, import_options)
654
655 def enabled(idl_node):
656 return self._is_node_enabled(idl_node, import_options.idl_defines)
657
658 for interface in idl_file.interfaces:
659 if not self._is_node_enabled(interface, import_options.idl_defines):
660 _logger.info('skipping interface %s (source=%s)' %
661 (interface.id, import_options.source))
662 continue
663
664 _logger.info('importing interface %s (source=%s file=%s)' %
665 (interface.id, import_options.source,
666 os.path.basename(idl_file.filename)))
667
668 interface.attributes = list(filter(enabled, interface.attributes))
669 interface.operations = list(filter(enabled, interface.operations))
670 self._imported_interfaces.append((interface, import_options))
671
672 # If an IDL dictionary then there is no implementsStatements.
673 if hasattr(idl_file, 'implementsStatements'):
674 for implStmt in idl_file.implementsStatements:
675 self._impl_stmts.append((implStmt, import_options))
676
677 for enum in idl_file.enums:
678 self._database.AddEnum(enum)
679
680 for dictionary in idl_file.dictionaries:
681 self._database.AddDictionary(dictionary)
682
683 # TODO(terry): Hack to remember all typedef unions they're mapped to any
684 # - no type.
685 for typedef in idl_file.typeDefs:
686 self._database.AddTypeDef(typedef)
687

◆ _remember_usage()

scripts.databasebuilder.DatabaseBuilder._remember_usage (   self,
  node,
  check_dictionaries = True 
)
protected

Definition at line 970 of file databasebuilder.py.

970 def _remember_usage(self, node, check_dictionaries=True):
971 if check_dictionaries:
972 used_types = self._dictionaries_used_types
973 diag_list = self._diag_dictionaries
974 diag_name = 'dictionary'
975 else:
976 used_types = self._no_interfaces_used_types
977 diag_list = self._diag_no_interfaces
978 diag_name = 'no_interface_object'
979
980 if len(used_types) > 0:
981 normalized_used = list(set(used_types))
982 for recorded_id in normalized_used:
983 for diag in diag_list:
984 if diag[diag_name].id == recorded_id:
985 diag['usages'].append({'interface': None, 'node': node})
986

◆ _rename_types()

scripts.databasebuilder.DatabaseBuilder._rename_types (   self,
  idl_file,
  import_options 
)
protected
Rename interface and type names with names provided in the
options. Also clears scopes from scoped names

Definition at line 222 of file databasebuilder.py.

222 def _rename_types(self, idl_file, import_options):
223 """Rename interface and type names with names provided in the
224 options. Also clears scopes from scoped names"""
225
226 strip_modules = lambda name: name.split('::')[-1]
227
228 def rename_node(idl_node):
229 idl_node.reset_id(strip_modules(idl_node.id))
230
231 def rename_ext_attrs(ext_attrs_node):
232 for type_valued_attribute_name in ['DartSupplemental']:
233 if type_valued_attribute_name in ext_attrs_node:
234 value = ext_attrs_node[type_valued_attribute_name]
235 if isinstance(value, str):
236 ext_attrs_node[
237 type_valued_attribute_name] = strip_modules(value)
238
239 list(map(rename_node, idl_file.all(IDLInterface)))
240 list(map(rename_node, idl_file.all(IDLType)))
241 list(map(rename_ext_attrs, idl_file.all(IDLExtAttrs)))
242

◆ _resolve_type_defs()

scripts.databasebuilder.DatabaseBuilder._resolve_type_defs (   self,
  idl_file 
)
protected

Definition at line 197 of file databasebuilder.py.

197 def _resolve_type_defs(self, idl_file):
198 for type_node in idl_file.all(IDLType):
199 resolved = False
200 type_name = type_node.id
201 for typedef in self.global_type_defs:
202 seq_name_typedef = 'sequence<%s>' % typedef
203 if type_name == typedef:
204 type_node.id = self.global_type_defs[typedef]
205 resolved = True
206 elif type_name == seq_name_typedef:
207 type_node.id = 'sequence<%s>' % self.global_type_defs[
208 typedef]
209 resolved = True
210 if not (resolved):
211 for typedef in idl_file.typeDefs:
212 if type_name == typedef.id:
213 type_node.id = typedef.type.id
214 resolved = True
215

◆ _sign()

scripts.databasebuilder.DatabaseBuilder._sign (   self,
  node 
)
protected
Computes a unique signature for the node, for merging purposed, by
concatenating types and names in the declaration.

Definition at line 267 of file databasebuilder.py.

267 def _sign(self, node):
268 """Computes a unique signature for the node, for merging purposed, by
269 concatenating types and names in the declaration."""
270 if isinstance(node, IDLType):
271 res = node.id
272 if res.startswith('unsigned '):
273 res = res[len('unsigned '):]
274 if hasattr(node, 'nullable') and node.nullable:
275 res += '?'
276 return res
277
278 res = []
279 if isinstance(node, IDLInterface):
280 res = ['interface', node.id]
281 elif isinstance(node, IDLParentInterface):
282 res = ['parent', self._sign(node.type)]
283 elif isinstance(node, IDLOperation):
284 res = ['op']
285 for special in node.specials:
286 res.append(special)
287 if node.id is not None:
288 res.append(node.id)
289 for arg in node.arguments:
290 res.append(self._sign(arg.type))
291 res.append(self._sign(node.type))
292 elif isinstance(node, IDLAttribute):
293 res = []
294 if node.is_read_only:
295 res.append('readonly')
296 res.append(node.id)
297 res.append(self._sign(node.type))
298 elif isinstance(node, IDLConstant):
299 res = []
300 res.append('const')
301 res.append(node.id)
302 res.append(node.value)
303 res.append(self._sign(node.type))
304 else:
305 raise TypeError("Can't sign input of type %s" % type(node))
306 return ':'.join(res)
307

◆ _strip_ext_attributes()

scripts.databasebuilder.DatabaseBuilder._strip_ext_attributes (   self,
  idl_file 
)
protected
Strips unuseful extended attributes.

Definition at line 216 of file databasebuilder.py.

216 def _strip_ext_attributes(self, idl_file):
217 """Strips unuseful extended attributes."""
218 for ext_attrs in idl_file.all(IDLExtAttrs):
219 # TODO: Decide which attributes are uninteresting.
220 pass
221

◆ _tabulate()

scripts.databasebuilder.DatabaseBuilder._tabulate (   self,
  columns 
)
protected
Tabulate a list of columns for a row.  Each item in columns is a column
value each column will be padded up to _TABULATE_WIDTH.  Each
column starts/ends with a vertical bar '|' the format a row:

   | columns[0] | columns[1] | columns[2] | ... |

Definition at line 1081 of file databasebuilder.py.

1081 def _tabulate(self, columns):
1082 """Tabulate a list of columns for a row. Each item in columns is a column
1083 value each column will be padded up to _TABULATE_WIDTH. Each
1084 column starts/ends with a vertical bar '|' the format a row:
1085
1086 | columns[0] | columns[1] | columns[2] | ... |
1087 """
1088 if len(columns) > 0:
1089 for column in columns:
1090 value = '' if not column else column
1091 sys.stdout.write('|{0:^{1}}'.format(value,
1092 self._TABULATE_WIDTH()))
1093 else:
1094 sys.stdout.write('|{0:^{1}}'.format('', self._TABULATE_WIDTH()))
1095
1096 sys.stdout.write('|\n')
uint32_t uint32_t * format

◆ _tabulate_break()

scripts.databasebuilder.DatabaseBuilder._tabulate_break (   self)
protected

Definition at line 1077 of file databasebuilder.py.

1077 def _tabulate_break(self):
1078 break_separator = "-" * self._TABULATE_WIDTH()
1079 self._tabulate([break_separator, break_separator, break_separator])
1080

◆ _tabulate_title()

scripts.databasebuilder.DatabaseBuilder._tabulate_title (   self,
  row_title 
)
protected

Definition at line 1071 of file databasebuilder.py.

1071 def _tabulate_title(self, row_title):
1072 title_separator = "=" * self._TABULATE_WIDTH()
1073 self._tabulate([title_separator, title_separator, title_separator])
1074 self._tabulate(row_title)
1075 self._tabulate([title_separator, title_separator, title_separator])
1076

◆ _TABULATE_WIDTH()

scripts.databasebuilder.DatabaseBuilder._TABULATE_WIDTH (   self)
protected

Definition at line 1068 of file databasebuilder.py.

1068 def _TABULATE_WIDTH(self):
1069 return 45
1070

◆ examine_database()

scripts.databasebuilder.DatabaseBuilder.examine_database (   self)

Definition at line 822 of file databasebuilder.py.

822 def examine_database(self):
823 # Contains list of dictionary structure: {'dictionary': dictionary, 'usages': []}
824 self._diag_dictionaries = []
825 self._dictionaries_used_types = []
826
827 # Record any dictionary.
828 for dictionary in self._database.GetDictionaries():
829 self._diag_dictionaries.append({
830 'dictionary': dictionary,
831 'usages': []
832 })
833
834 # Contains list of NoInterfaceObject structures: {'no_interface_object': dictionary, 'usages': []}
835 self._diag_no_interfaces = []
836 self._no_interfaces_used_types = []
837
838 # Record any interface with Blink IDL Extended Attribute 'NoInterfaceObject'.
839 for interface in self._database.GetInterfaces():
840 if interface.is_no_interface_object:
841 self._diag_no_interfaces.append({
842 'no_interface_object':
843 interface,
844 'usages': []
845 })
846
847 for interface in self._database.GetInterfaces():
848 self._constructors(interface)
849 self._constructors(interface, check_dictionaries=False)
850
851 for attribute in interface.attributes:
852 self._attribute_operation(interface, attribute)
853 self._attribute_operation(
854 interface, attribute, check_dictionaries=False)
855
856 for operation in interface.operations:
857 self._attribute_operation(interface, operation)
858 self._attribute_operation(
859 interface, operation, check_dictionaries=False)
860
861 # Report all dictionaries and their usage.
862 self._output_examination()
863 # Report all interface marked with NoInterfaceObject and their usage.
864 self._output_examination(check_dictionaries=False)
865
866 print('''
867Key:
868 (READ-ONLY) - read-only attribute has relationship
869 (GET/SET) - attribute has relationship
870 RETURN - operation\'s returned value has relationship
871 (ARGUMENT) - operation\'s argument(s) has relationship
872
873 (New) - After dictionary name if constructor(s) exist
874 (Ops,Props,New) after a NoInterfaceObject name is defined as:
875 Ops - number of operations for a NoInterfaceObject
876 Props - number of properties for a NoInterfaceObject
877 New - T(#) number constructors for a NoInterfaceObject
878 F no constructors for a NoInterfaceObject
879 e.g., an interface 5 operations, 3 properties and 2
880 constructors would display (5,3,T(2))
881
882
883Examination Complete
884''')
885

◆ fetch_constructor_data()

scripts.databasebuilder.DatabaseBuilder.fetch_constructor_data (   self,
  options 
)

Definition at line 801 of file databasebuilder.py.

801 def fetch_constructor_data(self, options):
802 window_interface = self._database.GetInterface('Window')
803 for attr in window_interface.attributes:
804 type = attr.type.id
805 if not type.endswith('Constructor'):
806 continue
807 type = re.sub('(Constructor)+$', '', type)
808 # TODO(antonm): Ideally we'd like to have pristine copy of WebKit IDLs and fetch
809 # this information directly from it. Unfortunately right now database is massaged
810 # a lot so it's difficult to maintain necessary information on Window itself.
811 interface = self._database.GetInterface(type)
812 if 'V8EnabledPerContext' in attr.ext_attrs:
813 interface.ext_attrs['synthesizedV8EnabledPerContext'] = \
814 attr.ext_attrs['V8EnabledPerContext']
815 if 'V8EnabledAtRuntime' in attr.ext_attrs:
816 interface.ext_attrs['synthesizedV8EnabledAtRuntime'] = \
817 attr.ext_attrs['V8EnabledAtRuntime'] or attr.id
818

◆ fix_displacements()

scripts.databasebuilder.DatabaseBuilder.fix_displacements (   self,
  source 
)
E.g. In W3C, something is declared on HTMLDocument but in WebKit
its on Document, so we need to mark that something in HTMLDocument
with @WebKit(via=Document). The 'via' attribute specifies the
parent interface that has the declaration.

Definition at line 711 of file databasebuilder.py.

711 def fix_displacements(self, source):
712 """E.g. In W3C, something is declared on HTMLDocument but in WebKit
713 its on Document, so we need to mark that something in HTMLDocument
714 with @WebKit(via=Document). The 'via' attribute specifies the
715 parent interface that has the declaration."""
716
717 for interface in self._database.GetInterfaces():
718 changed = False
719
720 _logger.info('fixing displacements in %s' % interface.id)
721
722 for parent_interface in self._get_parent_interfaces(interface):
723 _logger.info('scanning parent %s of %s' % (parent_interface.id,
724 interface.id))
725
726 def fix_nodes(local_list, parent_list):
727 changed = False
728 parent_signatures_map = self._build_signatures_map(
729 parent_list)
730 for idl_node in local_list:
731 sig = self._sign(idl_node)
732 if sig in parent_signatures_map:
733 parent_member = parent_signatures_map[sig]
734 if (source in parent_member.annotations and
735 source not in idl_node.annotations and
736 _VIA_ANNOTATION_ATTR_NAME not in
737 parent_member.annotations[source]):
738 idl_node.annotations[source] = IDLAnnotation({
739 _VIA_ANNOTATION_ATTR_NAME:
740 parent_interface.id
741 })
742 changed = True
743 return changed
744
745 changed = fix_nodes(interface.constants,
746 parent_interface.constants) or changed
747 changed = fix_nodes(interface.attributes,
748 parent_interface.attributes) or changed
749 changed = fix_nodes(interface.operations,
750 parent_interface.operations) or changed
751 if changed:
752 _logger.info(
753 'fixed displaced declarations in %s' % interface.id)
754

◆ import_idl_files()

scripts.databasebuilder.DatabaseBuilder.import_idl_files (   self,
  file_paths,
  import_options,
  is_dart_idl 
)

Definition at line 628 of file databasebuilder.py.

628 def import_idl_files(self, file_paths, import_options, is_dart_idl):
629 self._blink_compile_idl_files(file_paths, import_options, is_dart_idl)
630
631 start_time = time.time()
632
633 # Parse the IDL files in serial.
634 for file_path in file_paths:
635 file_path = os.path.normpath(file_path)
636 idl_file = _load_idl_file(self.build, file_path, import_options)
637 _logger.info('Processing %s' % os.path.splitext(
638 os.path.basename(file_path))[0])
639 self._process_idl_file(idl_file, import_options, is_dart_idl)
640
641 end_time = time.time()
642
643 for warning in report_unions_to_any():
644 _logger.warning(warning)
645
646 print('Total %s files %sprocessed in databasebuilder in %s seconds' % \
647 (len(file_paths), '', round((end_time - start_time), 2)))
648

◆ map_dictionaries()

scripts.databasebuilder.DatabaseBuilder.map_dictionaries (   self)
Changes the type of operations/constructors arguments from an IDL
dictionary to a Dictionary.  The IDL dictionary is just an enums of
strings which are checked at run-time.

Definition at line 783 of file databasebuilder.py.

783 def map_dictionaries(self):
784 """Changes the type of operations/constructors arguments from an IDL
785 dictionary to a Dictionary. The IDL dictionary is just an enums of
786 strings which are checked at run-time."""
787
788 def dictionary_to_map(type_node):
789 if self._database.HasDictionary(type_node.id):
790 type_node.dictionary = type_node.id
791 type_node.id = 'Dictionary'
792
793 def all_types(node):
794 list(map(dictionary_to_map, node.all(IDLType)))
795
796 for interface in self._database.GetInterfaces():
797 list(map(all_types, interface.all(IDLExtAttrFunctionValue)))
798 list(map(all_types, interface.attributes))
799 list(map(all_types, interface.operations))
800

◆ merge_imported_interfaces()

scripts.databasebuilder.DatabaseBuilder.merge_imported_interfaces (   self)
Merges all imported interfaces and loads them into the DB.

Definition at line 534 of file databasebuilder.py.

534 def merge_imported_interfaces(self):
535 """Merges all imported interfaces and loads them into the DB."""
536 imported_interfaces = self._imported_interfaces
537
538 # Step 1: Pre process imported interfaces
539 for interface, import_options in imported_interfaces:
540 self._annotate(interface, import_options)
541
542 # Step 2: Add all new interfaces and merge overlapping ones
543 for interface, import_options in imported_interfaces:
544 if not interface.is_supplemental:
545 if self._database.HasInterface(interface.id):
546 old_interface = self._database.GetInterface(interface.id)
547 self._merge_interfaces(old_interface, interface,
548 import_options)
549 else:
550 if import_options.add_new_interfaces:
551 self._database.AddInterface(interface)
552
553 # Step 3: Merge in supplemental interfaces
554 for interface, import_options in imported_interfaces:
555 if interface.is_supplemental:
556 target = interface.id
557 if self._database.HasInterface(target):
558 old_interface = self._database.GetInterface(target)
559 self._merge_interfaces(old_interface, interface,
560 import_options)
561 else:
562 _logger.warning("Supplemental target '%s' not found",
563 target)
564
565 # Step 4: Resolve 'implements' statements
566 for impl_stmt, import_options in self._impl_stmts:
567 self._merge_impl_stmt(impl_stmt, import_options)
568
569 self._impl_stmts = []
570 self._imported_interfaces = []
571

◆ normalize_annotations()

scripts.databasebuilder.DatabaseBuilder.normalize_annotations (   self,
  sources 
)
Makes the IDLs less verbose by removing annotation attributes
that are identical to the ones defined at the interface level.

Args:
sources -- list of source names to normalize.

Definition at line 755 of file databasebuilder.py.

755 def normalize_annotations(self, sources):
756 """Makes the IDLs less verbose by removing annotation attributes
757 that are identical to the ones defined at the interface level.
758
759 Args:
760 sources -- list of source names to normalize."""
761 for interface in self._database.GetInterfaces():
762 _logger.debug('normalizing annotations for %s' % interface.id)
763 for source in sources:
764 if (source not in interface.annotations or
765 not interface.annotations[source]):
766 continue
767 top_level_annotation = interface.annotations[source]
768
769 def normalize(idl_node):
770 if (source in idl_node.annotations and
771 idl_node.annotations[source]):
772 annotation = idl_node.annotations[source]
773 for name, value in list(annotation.items()):
774 if (name in top_level_annotation and
775 value == top_level_annotation[name]):
776 del annotation[name]
777
778 list(map(normalize, interface.parents))
779 list(map(normalize, interface.constants))
780 list(map(normalize, interface.attributes))
781 list(map(normalize, interface.operations))
782
static void normalize(int n, double *gauss)

Member Data Documentation

◆ _database

scripts.databasebuilder.DatabaseBuilder._database
protected

Definition at line 180 of file databasebuilder.py.

◆ _diag_dictionaries

scripts.databasebuilder.DatabaseBuilder._diag_dictionaries
protected

Definition at line 824 of file databasebuilder.py.

◆ _diag_no_interfaces

scripts.databasebuilder.DatabaseBuilder._diag_no_interfaces
protected

Definition at line 835 of file databasebuilder.py.

◆ _dictionaries_used_types

scripts.databasebuilder.DatabaseBuilder._dictionaries_used_types
protected

Definition at line 825 of file databasebuilder.py.

◆ _dictionary_used

scripts.databasebuilder.DatabaseBuilder._dictionary_used
protected

Definition at line 1057 of file databasebuilder.py.

◆ _impl_stmts

scripts.databasebuilder.DatabaseBuilder._impl_stmts
protected

Definition at line 182 of file databasebuilder.py.

◆ _imported_interfaces

scripts.databasebuilder.DatabaseBuilder._imported_interfaces
protected

Definition at line 181 of file databasebuilder.py.

◆ _info_collector

scripts.databasebuilder.DatabaseBuilder._info_collector
protected

Definition at line 178 of file databasebuilder.py.

◆ _no_interface_used

scripts.databasebuilder.DatabaseBuilder._no_interface_used
protected

Definition at line 1064 of file databasebuilder.py.

◆ _no_interfaces_used_types

scripts.databasebuilder.DatabaseBuilder._no_interfaces_used_types
protected

Definition at line 836 of file databasebuilder.py.

◆ build

scripts.databasebuilder.DatabaseBuilder.build

Definition at line 186 of file databasebuilder.py.

◆ conditionals_met

scripts.databasebuilder.DatabaseBuilder.conditionals_met

Definition at line 183 of file databasebuilder.py.

◆ global_type_defs

scripts.databasebuilder.DatabaseBuilder.global_type_defs

Definition at line 189 of file databasebuilder.py.


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