提交 9aba8037 编写于 作者: E Eric Seidel

Add support for named arguments to our bindings generation.

This doesn't yet support having both named and optional
arguments, but once I have an example of that it should
be trivial to add.

I also cleaned up the generation a little so the generated
dart file looks nicer. :)

R=abarth@chromium.org
BUG=

Review URL: https://codereview.chromium.org/923093003
上级 24b3a12e
...@@ -55,6 +55,7 @@ ImplementedAs=* ...@@ -55,6 +55,7 @@ ImplementedAs=*
InitializedByEventConstructor InitializedByEventConstructor
Iterable Iterable
LegacyTreatAsPartialInterface LegacyTreatAsPartialInterface
Named
NamedConstructor=* NamedConstructor=*
NoImplHeader NoImplHeader
NoInterfaceObject NoInterfaceObject
...@@ -70,9 +71,9 @@ ReflectInvalid=* ...@@ -70,9 +71,9 @@ ReflectInvalid=*
ReflectMissing=* ReflectMissing=*
ReflectOnly=* ReflectOnly=*
Replaceable Replaceable
SetterCallWith=ExecutionContext|ScriptArguments|ActiveWindow|FirstWindow
SetWrapperReferenceFrom=* SetWrapperReferenceFrom=*
SetWrapperReferenceTo=* SetWrapperReferenceTo=*
SetterCallWith=ExecutionContext|ScriptArguments|ActiveWindow|FirstWindow
SpecialWrapFor=* SpecialWrapFor=*
TreatNullAs=NullString|EmptyString TreatNullAs=NullString|EmptyString
TreatReturnedNullStringAs=Null|Undefined TreatReturnedNullStringAs=Null|Undefined
......
...@@ -125,6 +125,7 @@ def argument_context(interface, method, argument, index): ...@@ -125,6 +125,7 @@ def argument_context(interface, method, argument, index):
'local_cpp_type': local_cpp_type, 'local_cpp_type': local_cpp_type,
# FIXME: check that the default value's type is compatible with the argument's # FIXME: check that the default value's type is compatible with the argument's
'default_value': default_value, 'default_value': default_value,
'is_named': 'Named' in extended_attributes,
'dart_default_value': dart_default_value, 'dart_default_value': dart_default_value,
'enum_validation_expression': idl_type.enum_validation_expression, 'enum_validation_expression': idl_type.enum_validation_expression,
'preprocessed_type': preprocessed_type, 'preprocessed_type': preprocessed_type,
......
...@@ -5,23 +5,24 @@ ...@@ -5,23 +5,24 @@
// WARNING: Do not edit - generated code. // WARNING: Do not edit - generated code.
part of sky.core; part of sky.core;
abstract class {{interface_name}} extends {{ parent_interface if parent_interface else 'NativeFieldWrapperClass2' }} {
{% macro args_macro(args) -%} {% macro args_macro(args) -%}
{%- for arg in args -%} {%- for arg in args -%}
{%- if arg.is_optional and (loop.first or not args[arg.index-1].is_optional) -%} {%- if arg.is_optional and (loop.first or not args[arg.index-1].is_optional) -%}
[ {{ '{' if arg.is_named else '[' }}
{%- endif -%} {%- endif -%}
{{ arg.dart_type }} {{ arg.name }} {{ arg.dart_type }} {{ arg.name }}
{%- if arg.is_optional %} = {{ arg.dart_default_value }} {%- if arg.is_optional %} = {{ arg.dart_default_value }}
{%- if loop.last -%}]{%- endif -%} {#- TODO(eseidel): This does not support having both optional and named arguments! -#}
{%- if loop.last -%}{{ '}' if arg.is_named else ']' }}{%- endif -%}
{%- endif -%} {%- endif -%}
{%- if not loop.last %}, {% endif %} {%- if not loop.last %}, {% endif %}
{%- endfor -%} {%- endfor -%}
{%- endmacro %} {%- endmacro -%}
abstract class {{interface_name}} extends {{ parent_interface if parent_interface else 'NativeFieldWrapperClass2' }} {
// Constructors
{# TODO(eseidel): We only ever have one constructor. #} {# TODO(eseidel): We only ever have one constructor. #}
{% for constructor in constructors %} {%- for constructor in constructors -%}
static {{interface_name}} _constructor({{ args_macro(constructor.arguments) }}) native "{{interface_name}}_constructorCallback"; static {{interface_name}} _constructor({{ args_macro(constructor.arguments) }}) native "{{interface_name}}_constructorCallback";
factory {{interface_name}}({{ args_macro(constructor.arguments) }}) => _constructor( factory {{interface_name}}({{ args_macro(constructor.arguments) }}) => _constructor(
{%- for arg in constructor.arguments -%} {%- for arg in constructor.arguments -%}
...@@ -30,6 +31,7 @@ abstract class {{interface_name}} extends {{ parent_interface if parent_interfac ...@@ -30,6 +31,7 @@ abstract class {{interface_name}} extends {{ parent_interface if parent_interfac
); );
{% endfor %} {% endfor %}
// Attributes
{% for attribute in attributes %} {% for attribute in attributes %}
{{ attribute.dart_type }} get {{ attribute.name }} native "{{interface_name}}_{{ attribute.name }}_Getter"; {{ attribute.dart_type }} get {{ attribute.name }} native "{{interface_name}}_{{ attribute.name }}_Getter";
{% if not attribute.is_read_only %} {% if not attribute.is_read_only %}
...@@ -37,7 +39,8 @@ abstract class {{interface_name}} extends {{ parent_interface if parent_interfac ...@@ -37,7 +39,8 @@ abstract class {{interface_name}} extends {{ parent_interface if parent_interfac
{% endif %} {% endif %}
{% endfor %} {% endfor %}
// Methods
{% for method in methods %} {% for method in methods %}
{{method.dart_type}} {{method.name}}({{ args_macro(method.arguments)}} ) native "{{interface_name}}_{{ method.name }}_Callback"; {{method.dart_type}} {{method.name}}({{ args_macro(method.arguments)}}) native "{{interface_name}}_{{ method.name }}_Callback";
{% endfor %} {% endfor %}
} }
...@@ -3,8 +3,7 @@ ...@@ -3,8 +3,7 @@
// found in the LICENSE file. // found in the LICENSE file.
interface Node : EventTarget { interface Node : EventTarget {
// TODO(abarth): This should actually be a named argument. Node cloneNode([Named] optional boolean deep = true);
Node cloneNode(optional boolean deep);
readonly attribute ParentNode owner; readonly attribute ParentNode owner;
readonly attribute ParentNode parentNode; readonly attribute ParentNode parentNode;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册