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

Unified Diff: tools/dom/scripts/htmldartgenerator.py

Issue 11896038: Some more refactorings of overload dispatcher generation. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 11 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 | « sdk/lib/indexed_db/dartium/indexed_db_dartium.dart ('k') | tools/dom/scripts/systemhtml.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/dom/scripts/htmldartgenerator.py
diff --git a/tools/dom/scripts/htmldartgenerator.py b/tools/dom/scripts/htmldartgenerator.py
index b813f7f17126a7178d9ea6bf5031c57511a483bb..a9fa2d78183b91595ed70a6542e0c315fcecd0ff 100644
--- a/tools/dom/scripts/htmldartgenerator.py
+++ b/tools/dom/scripts/htmldartgenerator.py
@@ -176,13 +176,41 @@ class HtmlDartGenerator(object):
self.EmitOperation(info, method_name)
def _GenerateDispatcherBody(self,
- emitter,
operations,
parameter_names,
+ declaration,
generate_call,
is_optional,
can_omit_type_check=lambda type, pos: False):
+ body_emitter = self._members_emitter.Emit(
+ '\n'
+ ' $DECLARATION {\n'
+ '$!BODY'
+ ' }\n',
+ DECLARATION=declaration)
+
+ version = [0]
+ def GenerateCall(operation, argument_count, checks):
+ if checks:
+ (stmts_emitter, call_emitter) = body_emitter.Emit(
+ ' if ($CHECKS) {\n$!STMTS$!CALL }\n',
+ INDENT=' ',
+ CHECKS=' && '.join(checks))
+ else:
+ (stmts_emitter, call_emitter) = body_emitter.Emit(
+ '$!STMTS$!CALL',
+ INDENT=' ');
+
+ if operation.type.id == 'void':
+ call_emitter = call_emitter.Emit('$(INDENT)$!CALL;\n$(INDENT)return;\n')
+ else:
+ call_emitter = call_emitter.Emit('$(INDENT)return $!CALL;\n')
+
+ version[0] += 1
+ generate_call(
+ stmts_emitter, call_emitter, version[0], operation, argument_count)
+
def GenerateChecksAndCall(operation, argument_count):
checks = []
for i in range(0, argument_count):
@@ -198,7 +226,7 @@ class HtmlDartGenerator(object):
# optional argument could have been passed by name, leaving 'holes'.
checks.extend(['!?%s' % name for name in parameter_names[argument_count:]])
- generate_call(operation, argument_count, checks)
+ GenerateCall(operation, argument_count, checks)
# TODO: Optimize the dispatch to avoid repeated checks.
if len(operations) > 1:
@@ -207,7 +235,7 @@ class HtmlDartGenerator(object):
if is_optional(operation, argument):
GenerateChecksAndCall(operation, position)
GenerateChecksAndCall(operation, len(operation.arguments))
- emitter.Emit(
+ body_emitter.Emit(
' throw new ArgumentError("Incorrect number or type of arguments");'
'\n');
else:
@@ -223,9 +251,9 @@ class HtmlDartGenerator(object):
# y is optional in WebCore, while z is not.
# In this case, if y was actually passed, we'd like to emit foo(x, y, z) invocation,
# not foo(x, y).
- generate_call(operation, argument_count, [check])
+ GenerateCall(operation, argument_count, [check])
argument_count = position
- generate_call(operation, argument_count, [])
+ GenerateCall(operation, argument_count, [])
def AdditionalImplementedInterfaces(self):
# TODO: Include all implemented interfaces, including other Lists.
« no previous file with comments | « sdk/lib/indexed_db/dartium/indexed_db_dartium.dart ('k') | tools/dom/scripts/systemhtml.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698