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

Unified Diff: client/dom/scripts/generator.py

Issue 9428050: Automatically generate most constructors (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: add test Created 8 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 | « client/dom/scripts/dartgenerator.py ('k') | client/dom/scripts/systemfrog.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: client/dom/scripts/generator.py
diff --git a/client/dom/scripts/generator.py b/client/dom/scripts/generator.py
index 6239fc89f8c8e422717e99b494aa12ab378cb571..971a91042e15771b69fb06e9203260c9d221c957 100644
--- a/client/dom/scripts/generator.py
+++ b/client/dom/scripts/generator.py
@@ -225,15 +225,9 @@ def MatchSourceFilter(filter, thing):
else:
return any(token in thing.annotations for token in filter)
-def AnalyzeOperation(interface, operations):
- """Makes operation calling convention decision for a set of overloads.
-
- Returns: An OperationInfo object.
- """
-
- # Zip together arguments from each overload by position, then convert
- # to a dart argument.
+# Given a list of overloaded arguments, render a dart argument.
+def _DartArg(args, interface):
# Given a list of overloaded arguments, choose a suitable name.
def OverloadedName(args):
return '_OR_'.join(sorted(set(arg.id for arg in args)))
@@ -246,18 +240,25 @@ def AnalyzeOperation(interface, operations):
else:
return TypeName(typeIds, interface)
- # Given a list of overloaded arguments, render a dart argument.
- def DartArg(args):
- filtered = filter(None, args)
- optional = any(not arg or arg.is_optional for arg in args)
- type = OverloadedType(filtered)
- name = OverloadedName(filtered)
- if optional:
- return (name, type, 'null')
- else:
- return (name, type, None)
+ filtered = filter(None, args)
+ optional = any(not arg or arg.is_optional for arg in args)
+ type = OverloadedType(filtered)
+ name = OverloadedName(filtered)
+ if optional:
+ return (name, type, 'null')
+ else:
+ return (name, type, None)
+
+
+def AnalyzeOperation(interface, operations):
+ """Makes operation calling convention decision for a set of overloads.
- args = map(lambda *args: DartArg(args),
+ Returns: An OperationInfo object.
+ """
+
+ # Zip together arguments from each overload by position, then convert
+ # to a dart argument.
+ args = map(lambda *args: _DartArg(args, interface),
*(op.arguments for op in operations))
info = OperationInfo()
@@ -269,6 +270,41 @@ def AnalyzeOperation(interface, operations):
info.arg_infos = args
return info
+
+def AnalyzeConstructor(interface):
+ """Returns an OperationInfo object for the constructor.
+
+ Returns None if the interface has no Constructor.
+ """
+ def GetArgs(func_value):
+ return map(lambda arg: _DartArg([arg], interface), func_value.arguments)
+
+ if 'Constructor' in interface.ext_attrs:
+ name = None
+ func_value = interface.ext_attrs.get('Constructor')
+ if func_value:
+ # [Constructor(param,...)]
+ args = GetArgs(func_value)
+ else: # [Constructor]
+ args = []
+ else:
+ func_value = interface.ext_attrs.get('NamedConstructor')
+ if func_value:
+ name = func_value.id
+ args = GetArgs(func_value)
+ else:
+ return None
+
+ info = OperationInfo()
+ info.overloads = None # [func_value]
+ info.declared_name = name
+ info.name = name
+ info.js_name = name
+ info.type_name = interface.id
+ info.arg_infos = args
+ return info
+
+
def RecognizeCallback(interface):
"""Returns the info for the callback method if the interface smells like a
callback.
@@ -295,6 +331,7 @@ def FindMatchingAttribute(interface, attr1):
return matches[0]
return None
+
class OperationInfo(object):
"""Holder for various derived information from a set of overloaded operations.
« no previous file with comments | « client/dom/scripts/dartgenerator.py ('k') | client/dom/scripts/systemfrog.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698