Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(805)

Unified Diff: sky/engine/bindings2/scripts/templates/interface_cpp.template

Issue 914413004: Add a new bindings2/scripts directory for Dart bindings (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Remove idlrenderer.py it's not used Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: sky/engine/bindings2/scripts/templates/interface_cpp.template
diff --git a/sky/engine/bindings2/scripts/templates/interface_cpp.template b/sky/engine/bindings2/scripts/templates/interface_cpp.template
new file mode 100644
index 0000000000000000000000000000000000000000..f6c132d07c9d969cb8c606b830923dfb6ebf23ec
--- /dev/null
+++ b/sky/engine/bindings2/scripts/templates/interface_cpp.template
@@ -0,0 +1,160 @@
+{% extends 'interface_base_cpp.template' %}
+
+
+{# TODO(terry): Implement setter and deleter too #}
+
+
+{##############################################################################}
+{% block indexed_property_getter %}
+{% if indexed_property_getter and not indexed_property_getter.is_custom %}
+ {% set getter = indexed_property_getter %}
+static void indexedPropertyGetter(Dart_NativeArguments args)
+{
+ {{cpp_class}}* /* FIXME(vsm): Remove this. */ ALLOW_UNUSED receiver = GetReceiver<{{cpp_class}}>(args);
+ Dart_Handle exception = nullptr;
+ {
+ {% if indexed_property_getter.is_raises_exception %}
+ ExceptionState es;
+ {% endif %}
+
+ {# TODO(terry): Assume index is unsigned long, which all currently are. #}
+ unsigned index = DartConverter<unsigned>::FromArguments(args, 1, exception);
+ if (exception)
+ goto fail;
+ {{indexed_property_getter.cpp_type}} result = {{indexed_property_getter.cpp_value}};
+ if (!result)
+ return;
+ {{indexed_property_getter.dart_set_return_value}};
+
+ return;
+ }
+
+fail:
+ Dart_ThrowException(exception);
+ ASSERT_NOT_REACHED();
+}
+
+{% endif %}
+{# TODO(terry): Should handle custom index getter - none today. #}
+{% endblock %}
+
+
+{##############################################################################}
+{% block indexed_property_getter_resolver %}
+ {# TODO(terry): Support all indexed and named properties today only indexed getter is supported. #}
+ {# Resolver indexed properties #}
+ {% if indexed_property_getter and not indexed_property_getter.is_custom %}
+ {% for native_entry in indexed_property_getter.native_entries %}
+ {% set resolver_string = native_entry.resolver_string %}
+if (argumentCount == 2 && name == "{{resolver_string}}") {
+ *autoSetupScope = true;
+ return {{dart_class}}Internal::indexedPropertyGetter;
+}
+ {% endfor %}
+ {% endif %}
+{% endblock %}
+
+{##############################################################################}
+{% block named_property_getter_resolver %}
+ {# Resolver named properties #}
+ {% if named_property_getter %}
+ {% for native_entry in named_property_getter.native_entries %}
+ {% set resolver_string = native_entry.resolver_string %}
+if (argumentCount == 2 && (name == "{{resolver_string}}")) {
+ *autoSetupScope = true;
+ return {{dart_class}}Internal::propertyQuery;
+}
+ {% endfor %}
+ {% endif %}
+{% endblock %}
+
+{##############################################################################}
+{% block generate_symbolizer_indexed_property_getter %}
+ {% if indexed_property_getter and not indexed_property_getter.is_custom %}
+ {% for native_entry in indexed_property_getter.native_entries %}
+ {% set resolver_string = native_entry.resolver_string %}
+if (native_function == {{dart_class}}Internal::indexedPropertyGetter) {
+ return reinterpret_cast<const uint8_t*>("{{resolver_string}}");
+}
+ {% endfor %}
+ {% endif %}
+{% endblock %}
+
+{##############################################################################}
+{% block generate_symbolizer_named_property_getter %}
+ {# Resolver named properties #}
+ {% if named_property_getter %}
+ {% for native_entry in named_property_getter.native_entries %}
+ {% set resolver_string = native_entry.resolver_string %}
+if (native_function == {{dart_class}}Internal::propertyQuery) {
+ return reinterpret_cast<const uint8_t*>("{{resolver_string}}");
+}
+ {% endfor %}
+ {% endif %}
+{% endblock %}
+
+{##############################################################################}
+
+{% from 'methods_cpp.template' import static_method_name with context %}
+
+{##############################################################################}
+{% block overloaded_constructor %}
+{% if constructor_overloads %}
+static void constructorCallbackDispatcher(Dart_NativeArguments args)
+{
+ Dart_Handle exception = nullptr;
+ const int argOffset = 0;
+ int argCount = Dart_GetNativeArgumentCount(args) + argOffset;
+ {# 2. Initialize argcount to be min(maxarg, n). #}
+ switch (std::min({{constructor_overloads.maxarg}}, argCount)) {
+ {# 3. Remove from S all entries whose type list is not of length argcount. #}
+ {% for length, tests_constructors in constructor_overloads.length_tests_methods %}
+ case {{length}}:
+ {# Then resolve by testing argument #}
+ {% for test, constructor in tests_constructors %}
+ {# 10. If i = d, then: #}
+ if ({{test}}) {
+ {% if constructor.is_custom %}
+ {{static_method_name(constructor.name)}}(args);
+ {% else %}
+ {{static_method_name(constructor.name, constructor.overload_index)}}(args);
+ {% endif %}
+ return;
+ }
+ {% endfor %}
+ break;
+ {% endfor %}
+ default:
+ {# Invalid arity, throw error #}
+ {# Report full list of valid arities if gaps and above minimum #}
+ {% if constructor_overloads.valid_arities %}
+ if (argCount >= {{overloads.minarg}}) {
+ const String message = "Wrong arity, expected one of {{constructor_overloads.valid_arities}}";
+ // TODO(dart): exception = DartUtilities::coreArgumentErrorException(message);
+ goto fail;
+ }
+ {% endif %}
+ {# Otherwise just report "not enough arguments" #}
+ {
+ const String message = "Not enough arguments (at least {{constructor_overloads.minarg}} required)";
+ // TODO(dart): exception = DartUtilities::coreArgumentErrorException(message);
+ goto fail;
+ }
+ return;
+ }
+ {# No match, throw error #}
+ {
+ const String message = "No matching constructor signature.";
+ // TODO(dart): exception = DartUtilities::coreArgumentErrorException(message);
+ goto fail;
+ }
+ return;
+fail:
+ Dart_ThrowException(exception);
+ ASSERT_NOT_REACHED();
+}
+{% endif %}
+{% endblock %}
+
+
+{##############################################################################}

Powered by Google App Engine
This is Rietveld 408576698