Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Functions | Variables
scripts.generate_blink_file Namespace Reference

Functions

 generate_parameter_entries (param_infos)
 
 rename_constructor (name)
 
 _Find_Match (interface_id, member, member_prefix, candidates)
 
 _Is_Native (interface, member)
 
 Select_Stub (template, is_native)
 
 Generate_Blink (output_dir, database, type_registry)
 
 _Emit_Extra_Operations (blink_file, interface_name)
 
 _Emit_Blink_Constructors (blink_file, analyzed_constructors)
 
 _Process_Attributes (blink_file, interface, attributes)
 
 _Process_Operations (blink_file, interface, operations, primary_interface=False)
 
 _Suppress_Secondary_Interface_Operation (interface, analyzed)
 
 _Emit_Blink_Operation (blink_file, interface, analyzeOperations, primary_interface)
 

Variables

 _js_custom_members
 
dict _additional_methods
 
str HEADER
 
str END_RESOLVER
 
str BLINK_UTILS
 
str CLASS_DEFINITION
 
str CLASS_DEFINITION_EXTENDS
 
list CONSTRUCTOR_0
 
list CONSTRUCTOR_ARGS
 
list ATTRIBUTE_GETTER
 
list ATTRIBUTE_SETTER
 
list OPERATION_0
 
list OPERATION_1
 
list OPERATION_2
 
list OPERATION_PQ
 
str ARGUMENT_NUM = "__arg_%s"
 
list OPERATION_ARGS
 
str CLASS_STATIC = 'Blink_JsNative_DomException.getProperty(js.context, "%s")'
 
list STATIC_ATTRIBUTE_GETTER
 
list STATIC_OPERATION_0
 
list STATIC_OPERATION_ARGS
 
str CLASS_DEFINITION_END
 
dict constructor_renames
 
dict suppressed_operations
 

Detailed Description

Generates sdk/lib/_blink/dartium/_blink_dartium.dart file.

Function Documentation

◆ _Emit_Blink_Constructors()

scripts.generate_blink_file._Emit_Blink_Constructors (   blink_file,
  analyzed_constructors 
)
protected

Definition at line 495 of file generate_blink_file.py.

495def _Emit_Blink_Constructors(blink_file, analyzed_constructors):
496 (arg_min_count, arg_max_count) = generate_parameter_entries(
497 analyzed_constructors.param_infos)
498 name = analyzed_constructors.js_name
499 if not (name):
500 name = analyzed_constructors.type_name
501
502 for callback_index in range(arg_min_count, arg_max_count):
503 if callback_index == 0:
504 blink_file.write(
505 Select_Stub(CONSTRUCTOR_0, _Is_Native(name, 'constructor')) %
506 (rename_constructor(name)))
507 else:
508 arguments = []
509 for i in range(0, callback_index):
510 arguments.append(ARGUMENT_NUM % i)
511 argument_list = ', '.join(arguments)
512 blink_file.write(
513 Select_Stub(CONSTRUCTOR_ARGS, _Is_Native(name, 'constructor')) %
514 (callback_index, argument_list, rename_constructor(name),
515 argument_list))
516
517

◆ _Emit_Blink_Operation()

scripts.generate_blink_file._Emit_Blink_Operation (   blink_file,
  interface,
  analyzeOperations,
  primary_interface 
)
protected

Definition at line 580 of file generate_blink_file.py.

581 primary_interface):
582 analyzed = AnalyzeOperation(interface, analyzeOperations)
583
584 if not (primary_interface) and _Suppress_Secondary_Interface_Operation(
585 interface, analyzed):
586 return
587
588 (arg_min_count,
589 arg_max_count) = generate_parameter_entries(analyzed.param_infos)
590 name = analyzed.js_name
591
592 is_native = _Is_Native(interface.id, name)
593
594 operation = analyzeOperations[0]
595 if (name.startswith('__') and \
596 ('getter' in operation.specials or \
597 'setter' in operation.specials or \
598 'deleter' in operation.specials)):
599 if name == '__propertyQuery__':
600 blink_file.write(
601 Select_Stub(OPERATION_PQ, is_native) % (name, interface.id))
602 else:
603 arg_min_count = arg_max_count
604 if arg_max_count == 2:
605 blink_file.write(
606 Select_Stub(OPERATION_1, is_native) % (name, interface.id,
607 name))
608 elif arg_max_count == 3:
609 blink_file.write(
610 Select_Stub(OPERATION_2, is_native) % (name, interface.id,
611 name))
612 else:
613 print("FATAL ERROR: _blink emitter operator %s.%s" %
614 (interface.id, name))
615 exit
616
617 return
618
619 for callback_index in range(arg_min_count, arg_max_count):
620 if callback_index == 0:
621 if operation.is_static:
622 class_property = CLASS_STATIC % interface.id
623 blink_file.write(
624 Select_Stub(STATIC_OPERATION_0, is_native) %
625 (name, class_property, interface.id, name))
626 else:
627 blink_file.write(
628 Select_Stub(OPERATION_0, is_native) % (name, interface.id,
629 name))
630 else:
631 arguments = []
632 for i in range(0, callback_index):
633 arguments.append(ARGUMENT_NUM % i)
634 argument_list = ', '.join(arguments)
635 if operation.is_static:
636 class_property = CLASS_STATIC % interface.id
637 blink_file.write(
638 Select_Stub(STATIC_OPERATION_ARGS, is_native) %
639 (name, callback_index, argument_list, class_property,
640 interface.id, name, argument_list))
641 else:
642 blink_file.write(
643 Select_Stub(OPERATION_ARGS, is_native) %
644 (name, callback_index, argument_list, interface.id, name,
645 argument_list))
void print(void *str)
Definition bridge.cpp:126

◆ _Emit_Extra_Operations()

scripts.generate_blink_file._Emit_Extra_Operations (   blink_file,
  interface_name 
)
protected

Definition at line 486 of file generate_blink_file.py.

486def _Emit_Extra_Operations(blink_file, interface_name):
487 if (interface_name in _additional_methods):
488 (name, arg_count, return_value) = _additional_methods[interface_name]
489 exposed_name = ''.join(['__get', '___', name]) if return_value else name
490 blink_file.write(
491 Select_Stub(OPERATION_1, False) % (exposed_name, interface_name,
492 name))
493
494

◆ _Find_Match()

scripts.generate_blink_file._Find_Match (   interface_id,
  member,
  member_prefix,
  candidates 
)
protected

Definition at line 409 of file generate_blink_file.py.

409def _Find_Match(interface_id, member, member_prefix, candidates):
410 member_name = interface_id + '.' + member
411 if member_name in candidates:
412 return member_name
413 member_name = interface_id + '.' + member_prefix + member
414 if member_name in candidates:
415 return member_name
416 member_name = interface_id + '.*'
417 if member_name in candidates:
418 return member_name
419
420

◆ _Is_Native()

scripts.generate_blink_file._Is_Native (   interface,
  member 
)
protected

Definition at line 421 of file generate_blink_file.py.

421def _Is_Native(interface, member):
422 return _Find_Match(interface, member, '', _js_custom_members)
423
424

◆ _Process_Attributes()

scripts.generate_blink_file._Process_Attributes (   blink_file,
  interface,
  attributes 
)
protected

Definition at line 518 of file generate_blink_file.py.

518def _Process_Attributes(blink_file, interface, attributes):
519 # Emit an interface's attributes and operations.
520 for attribute in sorted(attributes, key=ConstantOutputOrder):
521 name = attribute.id
522 is_native = _Is_Native(interface.id, name)
523 if attribute.is_read_only:
524 if attribute.is_static:
525 class_property = CLASS_STATIC % interface.id
526 blink_file.write(
527 Select_Stub(STATIC_ATTRIBUTE_GETTER, is_native) %
528 (name, class_property, interface.id, name))
529 else:
530 blink_file.write(
531 Select_Stub(ATTRIBUTE_GETTER, is_native) %
532 (name, interface.id, name))
533 else:
534 blink_file.write(
535 Select_Stub(ATTRIBUTE_GETTER, is_native) % (name, interface.id,
536 name))
537 blink_file.write(
538 Select_Stub(ATTRIBUTE_SETTER, is_native) % (name, interface.id,
539 name))
540
541

◆ _Process_Operations()

scripts.generate_blink_file._Process_Operations (   blink_file,
  interface,
  operations,
  primary_interface = False 
)
protected

Definition at line 542 of file generate_blink_file.py.

545 primary_interface=False):
546 analyzeOperations = []
547
548 for operation in sorted(operations, key=ConstantOutputOrder):
549 if len(analyzeOperations) == 0:
550 analyzeOperations.append(operation)
551 else:
552 if analyzeOperations[0].id == operation.id:
553 # Handle overloads
554 analyzeOperations.append(operation)
555 else:
556 _Emit_Blink_Operation(blink_file, interface, analyzeOperations,
557 primary_interface)
558 analyzeOperations = [operation]
559 if len(analyzeOperations) > 0:
560 _Emit_Blink_Operation(blink_file, interface, analyzeOperations,
561 primary_interface)
562
563
564# List of DartName operations to not emit (e.g., For now only WebGL2RenderingContextBase
565# has readPixels in both WebGLRenderingContextBase and WebGL2RenderingContextBase.
566# Furthermore, readPixels has the exact same number of arguments - in JavaScript
567# there is no typing so they're the same.

◆ _Suppress_Secondary_Interface_Operation()

scripts.generate_blink_file._Suppress_Secondary_Interface_Operation (   interface,
  analyzed 
)
protected

Definition at line 573 of file generate_blink_file.py.

573def _Suppress_Secondary_Interface_Operation(interface, analyzed):
574 if interface.id in suppressed_operations:
575 # Should this DartName (name property) be suppressed on this interface?
576 return analyzed.name in suppressed_operations[interface.id]
577 return False
578
579

◆ Generate_Blink()

scripts.generate_blink_file.Generate_Blink (   output_dir,
  database,
  type_registry 
)

Definition at line 432 of file generate_blink_file.py.

432def Generate_Blink(output_dir, database, type_registry):
433 blink_filename = os.path.join(output_dir, '_blink_dartium.dart')
434 blink_file = open(blink_filename, 'w')
435
436 blink_file.write(HEADER)
437
438 interfaces = database.GetInterfaces()
439 for interface in interfaces:
440 name = interface.id
441 resolver_entry = ' if (s == "%s") return Blink%s.instance;\n' % (name,
442 name)
443 blink_file.write(resolver_entry)
444
445 blink_file.write(END_RESOLVER)
446
447 for interface in interfaces:
448 name = interface.id
449
450 if interface.parents and len(
451 interface.parents) > 0 and interface.parents[0].id:
452 extends = interface.parents[0].id
453 class_def = CLASS_DEFINITION_EXTENDS % (name, extends, name)
454 else:
455 class_def = CLASS_DEFINITION % (name, name)
456 blink_file.write(class_def)
457
458 analyzed_constructors = AnalyzeConstructor(interface)
459 if analyzed_constructors:
460 _Emit_Blink_Constructors(blink_file, analyzed_constructors)
461 elif 'Constructor' in interface.ext_attrs:
462 # Zero parameter constructor.
463 blink_file.write(
464 Select_Stub(CONSTRUCTOR_0, _Is_Native(name, 'constructor')) %
465 rename_constructor(name))
466
467 _Process_Attributes(blink_file, interface, interface.attributes)
468 _Process_Operations(blink_file, interface, interface.operations, True)
469
470 _Emit_Extra_Operations(blink_file, name)
471
472 secondary_parents = database.TransitiveSecondaryParents(
473 interface, False)
474 for secondary in secondary_parents:
475 _Process_Attributes(blink_file, secondary, secondary.attributes)
476 _Process_Operations(blink_file, secondary, secondary.operations,
477 False)
478
479 blink_file.write(CLASS_DEFINITION_END)
480
481 blink_file.write(BLINK_UTILS)
482
483 blink_file.close()
484
485

◆ generate_parameter_entries()

scripts.generate_blink_file.generate_parameter_entries (   param_infos)

Definition at line 387 of file generate_blink_file.py.

387def generate_parameter_entries(param_infos):
388 optional_default_args = 0
389 for argument in param_infos:
390 if argument.is_optional:
391 optional_default_args += 1
392
393 arg_count = len(param_infos)
394 min_arg_count = arg_count - optional_default_args
395 lb = min_arg_count - 2 if min_arg_count > 2 else 0
396 return (lb, arg_count + 1)
397
398

◆ rename_constructor()

scripts.generate_blink_file.rename_constructor (   name)

Definition at line 405 of file generate_blink_file.py.

405def rename_constructor(name):
406 return constructor_renames[name] if name in constructor_renames else name
407
408

◆ Select_Stub()

scripts.generate_blink_file.Select_Stub (   template,
  is_native 
)

Definition at line 425 of file generate_blink_file.py.

425def Select_Stub(template, is_native):
426 if is_native:
427 return template[0] + template[2]
428 else:
429 return template[0] + template[1]
430
431

Variable Documentation

◆ _additional_methods

dict scripts.generate_blink_file._additional_methods
protected
Initial value:
1= {
2 # Support propertyIsEnumerable (available on all objects only needed by
3 # CSSStyleDeclaration decides if style property is supported (handling
4 # camelcase and inject hyphens between camelcase).
5 # Format of dictionary is 'operation name', arguments, returns value (True or False)
6 'CSSStyleDeclaration': ('propertyIsEnumerable', 1, True),
7}

Definition at line 84 of file generate_blink_file.py.

◆ _js_custom_members

scripts.generate_blink_file._js_custom_members
protected

Definition at line 15 of file generate_blink_file.py.

◆ ARGUMENT_NUM

str scripts.generate_blink_file.ARGUMENT_NUM = "__arg_%s"

Definition at line 352 of file generate_blink_file.py.

◆ ATTRIBUTE_GETTER

list scripts.generate_blink_file.ATTRIBUTE_GETTER
Initial value:
1= [
2 ' %s_Getter_(mthis)',
3 ' => Blink_JsNative_DomException.getProperty(mthis /* %s */, "%s");\n\n',
4 ' native "Blink_Getter_%s_%s";\n\n'
5]

Definition at line 313 of file generate_blink_file.py.

◆ ATTRIBUTE_SETTER

list scripts.generate_blink_file.ATTRIBUTE_SETTER
Initial value:
1= [
2 ' %s_Setter_(mthis, __arg_0)',
3 ' => Blink_JsNative_DomException.setProperty(mthis /* %s */, "%s", __arg_0);\n\n',
4 ' native "Blink_Setter_%s_%s";\n\n'
5]

Definition at line 319 of file generate_blink_file.py.

◆ BLINK_UTILS

str scripts.generate_blink_file.BLINK_UTILS

Definition at line 121 of file generate_blink_file.py.

◆ CLASS_DEFINITION

str scripts.generate_blink_file.CLASS_DEFINITION
Initial value:
1= """class Blink%s {
2 static final instance = new Blink%s();
3
4"""

Definition at line 286 of file generate_blink_file.py.

◆ CLASS_DEFINITION_END

str scripts.generate_blink_file.CLASS_DEFINITION_END
Initial value:
1= """}
2
3"""

Definition at line 383 of file generate_blink_file.py.

◆ CLASS_DEFINITION_EXTENDS

str scripts.generate_blink_file.CLASS_DEFINITION_EXTENDS
Initial value:
1= """class Blink%s extends Blink%s {
2 static final instance = new Blink%s();
3
4"""

Definition at line 291 of file generate_blink_file.py.

◆ CLASS_STATIC

str scripts.generate_blink_file.CLASS_STATIC = 'Blink_JsNative_DomException.getProperty(js.context, "%s")'

Definition at line 360 of file generate_blink_file.py.

◆ CONSTRUCTOR_0

list scripts.generate_blink_file.CONSTRUCTOR_0
Initial value:
1= [
2 ' constructorCallback_0_()',
3 ' => Blink_JsNative_DomException.callConstructor0("%s");\n\n',
4 ' native "Blink_Constructor_%s";\n\n'
5]

Definition at line 299 of file generate_blink_file.py.

◆ CONSTRUCTOR_ARGS

list scripts.generate_blink_file.CONSTRUCTOR_ARGS
Initial value:
1= [
2 ' constructorCallback_%s_(%s)',
3 ' => Blink_JsNative_DomException.callConstructor("%s", [%s]);\n\n',
4 ' native "Blink_Constructor_Args_%s" /* %s */;\n\n'
5]

Definition at line 306 of file generate_blink_file.py.

◆ constructor_renames

dict scripts.generate_blink_file.constructor_renames
Initial value:
1= {
2 'RTCPeerConnection': 'webkitRTCPeerConnection',
3 'SpeechRecognition': 'webkitSpeechRecognition',
4}

Definition at line 399 of file generate_blink_file.py.

◆ END_RESOLVER

str scripts.generate_blink_file.END_RESOLVER
Initial value:
1= """
2 // Failed to find it, check for custom renames
3 dynamic obj = resolverMap[s];
4 if (obj != null) return obj;
5 throw("No such interface exposed in blink: ${s}");
6}
7
8"""

Definition at line 112 of file generate_blink_file.py.

◆ HEADER

str scripts.generate_blink_file.HEADER
Initial value:
1= """/* Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 * for details. All rights reserved. Use of this source code is governed by a
3 * BSD-style license that can be found in the LICENSE file.
4 *
5 * DO NOT EDIT
6 * Auto-generated _blink library.
7 */
8library dart.dom._blink;
9
10import 'dart:async';
11import 'dart:js' as js;
12import 'dart:html' show DomException;
13import 'dart:_internal' as internal;
14// This is a place to put custom renames if we need them.
15final resolverMap = {
16};
17
18dynamic resolver(String s) {
19"""

Definition at line 92 of file generate_blink_file.py.

◆ OPERATION_0

list scripts.generate_blink_file.OPERATION_0
Initial value:
1= [
2 ' %s_Callback_0_(mthis)',
3 ' => Blink_JsNative_DomException.callMethod(mthis /* %s */, "%s", []);\n\n',
4 ' native "Blink_Operation_0_%s_%s";\n\n'
5]

Definition at line 326 of file generate_blink_file.py.

◆ OPERATION_1

list scripts.generate_blink_file.OPERATION_1
Initial value:
1= [
2 ' $%s_Callback_1_(mthis, __arg_0)',
3 ' => Blink_JsNative_DomException.callMethod(mthis /* %s */, "%s", [__arg_0]);\n\n',
4 ' native "Blink_Operation_1_%s_%s";\n\n'
5]

Definition at line 333 of file generate_blink_file.py.

◆ OPERATION_2

list scripts.generate_blink_file.OPERATION_2
Initial value:
1= [
2 ' $%s_Callback_2_(mthis, __arg_0, __arg_1)',
3 ' => Blink_JsNative_DomException.callMethod(mthis /* %s */, "%s", [__arg_0, __arg_1]);\n\n',
4 ' native "Blink_Operation_2_%s_%s";\n\n'
5]

Definition at line 339 of file generate_blink_file.py.

◆ OPERATION_ARGS

list scripts.generate_blink_file.OPERATION_ARGS
Initial value:
1= [
2 ' %s_Callback_%s_(mthis, %s)',
3 ' => Blink_JsNative_DomException.callMethod(mthis /* %s */, "%s", [%s]);\n\n',
4 ' native "Blink_Operation_%s_%s"; /* %s */\n\n'
5]

Definition at line 353 of file generate_blink_file.py.

◆ OPERATION_PQ

list scripts.generate_blink_file.OPERATION_PQ
Initial value:
1= [
2 ' $%s_Callback_1_(mthis, __arg_0)',
3 ' => Blink_JsNative_DomException.propertyQuery(mthis, __arg_0); /* %s */ \n\n',
4 ' native "Blink_Operation_PQ_%s";\n\n'
5]

Definition at line 345 of file generate_blink_file.py.

◆ STATIC_ATTRIBUTE_GETTER

list scripts.generate_blink_file.STATIC_ATTRIBUTE_GETTER
Initial value:
1= [
2 ' %s_Getter_()',
3 ' => Blink_JsNative_DomException.getProperty(%s /* %s */, "%s");\n\n',
4 ' /* %s */ native "Blink_Static_getter_%s_%s"'
5]

Definition at line 363 of file generate_blink_file.py.

◆ STATIC_OPERATION_0

list scripts.generate_blink_file.STATIC_OPERATION_0
Initial value:
1= [
2 ' %s_Callback_0_()',
3 ' => Blink_JsNative_DomException.callMethod(%s /* %s */, "%s", []);\n\n',
4 ' /* %s */ native "Blink_Static_Operation_0_%s_%s'
5]

Definition at line 370 of file generate_blink_file.py.

◆ STATIC_OPERATION_ARGS

list scripts.generate_blink_file.STATIC_OPERATION_ARGS
Initial value:
1= [
2 ' %s_Callback_%s_(%s)',
3 ' => Blink_JsNative_DomException.callMethod(%s /* %s */, "%s", [%s]);\n\n',
4 ' /* %s */ native "Blink_Static_Operations_%s_%s" /* %s */ \n\n'
5]

Definition at line 377 of file generate_blink_file.py.

◆ suppressed_operations

dict scripts.generate_blink_file.suppressed_operations
Initial value:
1= {
2 'WebGL2RenderingContextBase': ['readPixels2', 'texImage2D2'],
3}

Definition at line 568 of file generate_blink_file.py.