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

Unified Diff: third_party/WebKit/Source/bindings/scripts/overload_set_algorithm.py

Issue 2731683002: [WebAgentsAPI]: Introduce OverloadSetAdapter. (Closed)
Patch Set: Created 3 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
« no previous file with comments | « no previous file | third_party/WebKit/Source/bindings/scripts/overload_set_algorithm_test.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/bindings/scripts/overload_set_algorithm.py
diff --git a/third_party/WebKit/Source/bindings/scripts/overload_set_algorithm.py b/third_party/WebKit/Source/bindings/scripts/overload_set_algorithm.py
index cda46c2b37013a0850a66e76d3fd191019227050..7f2803c4e952da67f9e60d87d229c5a77e49a9ce 100644
--- a/third_party/WebKit/Source/bindings/scripts/overload_set_algorithm.py
+++ b/third_party/WebKit/Source/bindings/scripts/overload_set_algorithm.py
@@ -14,7 +14,43 @@ def sort_and_groupby(list_to_sort, key=None):
return ((k, list(g)) for k, g in itertools.groupby(list_to_sort, key))
-def effective_overload_set(F): # pylint: disable=invalid-name
+class OverloadSetAdapter(object):
+ """Base class for the second effective_overload_set argument. Python is
+ a type-lax language, so this is mostly documentation of the expected
+ interface."""
+
+ def arguments(self, operation):
+ """Given an operation, return the list of its arguments."""
+ raise NotImplementedError
+
+ def type(self, argument):
+ """Given an argument, return its type."""
+ raise NotImplementedError
+
+ def is_optional(self, argument):
+ """Given an argument, return whether it is optional."""
+ raise NotImplementedError
+
+ def is_variadic(self, argument):
+ """"Given an argument, return whether it is variadic."""
+ raise NotImplementedError
+
+
+class MethodContextAdapter(OverloadSetAdapter):
+ def arguments(self, operation):
+ return operation['arguments']
+
+ def type(self, argument):
+ return argument['idl_type_object']
+
+ def is_optional(self, argument):
+ return argument['is_optional']
+
+ def is_variadic(self, argument):
+ return argument['is_variadic']
+
+
+def effective_overload_set(F, adapter): # pylint: disable=invalid-name
"""Returns the effective overload set of an overloaded function.
An effective overload set is the set of overloaded functions + signatures
@@ -45,6 +81,7 @@ def effective_overload_set(F): # pylint: disable=invalid-name
Arguments:
F: list of overloads for a given callable name.
+ value_reader: an OverloadSetValueReader instance.
Returns:
S: list of tuples of the form (callable, type list, optionality list).
@@ -64,21 +101,22 @@ def effective_overload_set(F): # pylint: disable=invalid-name
# 5. For each operation, extended attribute or callback function X in F:
for X in F: # X is the "callable". pylint: disable=invalid-name
- arguments = X['arguments'] # pylint: disable=invalid-name
+ arguments = adapter.arguments(X) # pylint: disable=invalid-name
# 1. Let n be the number of arguments X is declared to take.
n = len(arguments) # pylint: disable=invalid-name
# 2. Let t0..n−1 be a list of types, where ti is the type of X’s
# argument at index i.
# (“type list”)
- t = tuple(argument['idl_type_object'] # pylint: disable=invalid-name
+ t = tuple(adapter.type(argument) # pylint: disable=invalid-name
for argument in arguments)
# 3. Let o0..n−1 be a list of optionality values, where oi is “variadic”
# if X’s argument at index i is a final, variadic argument, “optional”
# if the argument is optional, and “required” otherwise.
# (“optionality list”)
# (We’re just using a boolean for optional/variadic vs. required.)
- o = tuple(argument['is_optional'] # pylint: disable=invalid-name
- or argument['is_variadic'] for argument in arguments)
+ o = tuple(adapter.is_optional(argument) # pylint: disable=invalid-name
+ or adapter.is_variadic(argument)
+ for argument in arguments)
# 4. Add to S the tuple <X, t0..n−1, o0..n−1>.
S.append((X, t, o))
# 5. If X is declared to be variadic, then:
@@ -99,7 +137,7 @@ def effective_overload_set(F): # pylint: disable=invalid-name
# 8. If n > 0 and all arguments of X are optional, then add to S the
# tuple <X, (), ()> (where “()” represents the empty list).
if n > 0 and all(oi for oi in o):
- S.append((X, [], []))
+ S.append((X, (), ()))
# 6. The effective overload set is S.
return S
@@ -110,7 +148,8 @@ def effective_overload_set_by_length(overloads):
# (callable, type list, optionality list)
return len(entry[1])
- effective_overloads = effective_overload_set(overloads)
+ effective_overloads = effective_overload_set(overloads,
+ MethodContextAdapter())
return list(sort_and_groupby(effective_overloads, type_list_length))
« no previous file with comments | « no previous file | third_party/WebKit/Source/bindings/scripts/overload_set_algorithm_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698