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

Unified Diff: Source/bindings/dart/scripts/templates/interface_cpp.template

Issue 668733002: C++ overload resolution in bindings layer (Closed) Base URL: svn://svn.chromium.org/blink/branches/dart/dartium
Patch Set: Rebase fixups Created 6 years, 2 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: Source/bindings/dart/scripts/templates/interface_cpp.template
diff --git a/Source/bindings/dart/scripts/templates/interface_cpp.template b/Source/bindings/dart/scripts/templates/interface_cpp.template
index f795069e76d4e4c641c233d1a19878f012969c30..7eab6f48d539889774485b8c3a8803345047cd5b 100644
--- a/Source/bindings/dart/scripts/templates/interface_cpp.template
+++ b/Source/bindings/dart/scripts/templates/interface_cpp.template
@@ -137,3 +137,67 @@ Dart_Handle toDartNoInline({{cpp_class}}* impl, DartDOMData* domData)
return {{dart_class}}::toDart(impl);
}
{% 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 = 0;
+ 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}}";
+ 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)";
+ exception = DartUtilities::coreArgumentErrorException(message);
+ goto fail;
+ }
+ return;
+ }
+ {# No match, throw error #}
+ {
+ const String message = "No matching constructor signature.";
+ 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