From 9aba803749d7800c09113a3bc9535677cafe79e2 Mon Sep 17 00:00:00 2001 From: Eric Seidel Date: Tue, 17 Feb 2015 11:00:07 -0800 Subject: [PATCH] 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 --- engine/bindings/IDLExtendedAttributes.txt | 3 ++- engine/bindings/scripts/dart_methods.py | 1 + .../scripts/templates/interface_dart.template | 17 ++++++++++------- engine/core/dom/Node.idl | 3 +-- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/engine/bindings/IDLExtendedAttributes.txt b/engine/bindings/IDLExtendedAttributes.txt index 48d597282..02bfccb85 100644 --- a/engine/bindings/IDLExtendedAttributes.txt +++ b/engine/bindings/IDLExtendedAttributes.txt @@ -55,6 +55,7 @@ ImplementedAs=* InitializedByEventConstructor Iterable LegacyTreatAsPartialInterface +Named NamedConstructor=* NoImplHeader NoInterfaceObject @@ -70,9 +71,9 @@ ReflectInvalid=* ReflectMissing=* ReflectOnly=* Replaceable +SetterCallWith=ExecutionContext|ScriptArguments|ActiveWindow|FirstWindow SetWrapperReferenceFrom=* SetWrapperReferenceTo=* -SetterCallWith=ExecutionContext|ScriptArguments|ActiveWindow|FirstWindow SpecialWrapFor=* TreatNullAs=NullString|EmptyString TreatReturnedNullStringAs=Null|Undefined diff --git a/engine/bindings/scripts/dart_methods.py b/engine/bindings/scripts/dart_methods.py index 25b3d88bd..014f28b7b 100644 --- a/engine/bindings/scripts/dart_methods.py +++ b/engine/bindings/scripts/dart_methods.py @@ -125,6 +125,7 @@ def argument_context(interface, method, argument, index): 'local_cpp_type': local_cpp_type, # FIXME: check that the default value's type is compatible with the argument's 'default_value': default_value, + 'is_named': 'Named' in extended_attributes, 'dart_default_value': dart_default_value, 'enum_validation_expression': idl_type.enum_validation_expression, 'preprocessed_type': preprocessed_type, diff --git a/engine/bindings/scripts/templates/interface_dart.template b/engine/bindings/scripts/templates/interface_dart.template index 9037bd504..274760a30 100644 --- a/engine/bindings/scripts/templates/interface_dart.template +++ b/engine/bindings/scripts/templates/interface_dart.template @@ -5,23 +5,24 @@ // WARNING: Do not edit - generated code. part of sky.core; -abstract class {{interface_name}} extends {{ parent_interface if parent_interface else 'NativeFieldWrapperClass2' }} { - {% macro args_macro(args) -%} {%- for arg in args -%} {%- if arg.is_optional and (loop.first or not args[arg.index-1].is_optional) -%} - [ + {{ '{' if arg.is_named else '[' }} {%- endif -%} {{ arg.dart_type }} {{ arg.name }} {%- 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 -%} {%- if not loop.last %}, {% endif %} {%- endfor -%} -{%- endmacro %} +{%- endmacro -%} +abstract class {{interface_name}} extends {{ parent_interface if parent_interface else 'NativeFieldWrapperClass2' }} { + // Constructors {# 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"; factory {{interface_name}}({{ args_macro(constructor.arguments) }}) => _constructor( {%- for arg in constructor.arguments -%} @@ -30,6 +31,7 @@ abstract class {{interface_name}} extends {{ parent_interface if parent_interfac ); {% endfor %} + // Attributes {% for attribute in attributes %} {{ attribute.dart_type }} get {{ attribute.name }} native "{{interface_name}}_{{ attribute.name }}_Getter"; {% if not attribute.is_read_only %} @@ -37,7 +39,8 @@ abstract class {{interface_name}} extends {{ parent_interface if parent_interfac {% endif %} {% endfor %} + // 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 %} } diff --git a/engine/core/dom/Node.idl b/engine/core/dom/Node.idl index 8ed0c1472..4880568c8 100644 --- a/engine/core/dom/Node.idl +++ b/engine/core/dom/Node.idl @@ -3,8 +3,7 @@ // found in the LICENSE file. interface Node : EventTarget { - // TODO(abarth): This should actually be a named argument. - Node cloneNode(optional boolean deep); + Node cloneNode([Named] optional boolean deep = true); readonly attribute ParentNode owner; readonly attribute ParentNode parentNode; -- GitLab