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

Unified Diff: ppapi/generators/idl_c_proto.py

Issue 11417010: Add support for generating thunk source from IDL. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Removed an unnecessary change Created 8 years, 1 month 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: ppapi/generators/idl_c_proto.py
diff --git a/ppapi/generators/idl_c_proto.py b/ppapi/generators/idl_c_proto.py
index c522babf4c39971cf2079173705dcc9ed1b75999..1d28b23f8aa723d4d70182ba1f8edb16104d390d 100755
--- a/ppapi/generators/idl_c_proto.py
+++ b/ppapi/generators/idl_c_proto.py
@@ -426,12 +426,15 @@ class CGen(object):
# include_name - If true, include member name in the signature.
# If false, leave it out. In any case, prefix and ptr_prefix
# are always included.
+ # include_version - if True, include version in the member name
#
def GetSignature(self, node, release, mode, prefix='', func_as_ptr=True,
- ptr_prefix='', include_name=True):
+ ptr_prefix='', include_name=True, include_version=False):
self.LogEnter('GetSignature %s %s as func=%s' %
(node, mode, func_as_ptr))
rtype, name, arrayspec, callspec = self.GetComponents(node, release, mode)
+ if include_version:
+ name = self.GetStructName(node, release, True)
out = self.Compose(rtype, name, arrayspec, callspec, prefix,
func_as_ptr, ptr_prefix, include_name)
self.LogExit('Exit GetSignature: %s' % out)
@@ -567,6 +570,44 @@ class CGen(object):
return CommentLines(lines, tabs)
+ def Indent(self, data, tabs=0):
+ """Handles indentation and 80-column line wrapping."""
+ tab = ' ' * tabs
+ lines = []
+ for line in data.split('\n'):
+ # Add indentation
+ line = tab + line
+ if len(line) > 80:
+ left = line.rfind('(') + 1
+ args = line[left:].split(',')
+ orig_args = args
+ orig_left = left
+ # Look for a better split.
+ while args[0][0] == ')':
dmichael (off chromium) 2012/11/16 18:24:44 Can you maybe put an example of the kind of code y
teravest 2012/11/16 18:52:36 Sure. Comment added.
+ left = line.rfind('(', 0, left - 1) + 1
+ if left == 0: # No more parens, take the original option
+ args = orig_args
+ left = orig_left
+ break
+ args = line[left:].split(',')
+
+ line_max = 0
+ for arg in args:
+ if len(arg) > line_max: line_max = len(arg)
+
+ if left + line_max >= 80:
+ space = '%s ' % tab
dmichael (off chromium) 2012/11/16 18:24:44 indent might be a better name than space?
teravest 2012/11/16 18:52:36 Done. I had left this unchanged from the previous
+ args = (',\n%s' % space).join([arg.strip() for arg in args])
+ lines.append('%s\n%s%s' % (line[:left], space, args))
+ else:
+ space = ' ' * (left - 1)
+ args = (',\n%s' % space).join(args)
+ lines.append('%s%s' % (line[:left], args))
+ else:
+ lines.append(line.rstrip())
dmichael (off chromium) 2012/11/16 18:24:44 I think I'd flip the if and the else, since in the
teravest 2012/11/16 18:52:36 Done.
+ return '\n'.join(lines)
+
+
# Define a top level object.
def Define(self, node, releases, tabs=0, prefix='', comment=False):
# If this request does not match unique release, or if the release is not
@@ -596,30 +637,10 @@ class CGen(object):
out += comment_txt
out += define_txt
- tab = ' ' * tabs
- lines = []
- for line in out.split('\n'):
- # Add indentation
- line = tab + line
- if len(line) > 80:
- left = line.rfind('(') + 1
- args = line[left:].split(',')
- line_max = 0
- for arg in args:
- if len(arg) > line_max: line_max = len(arg)
-
- if left + line_max >= 80:
- space = '%s ' % tab
- args = (',\n%s' % space).join([arg.strip() for arg in args])
- lines.append('%s\n%s%s' % (line[:left], space, args))
- else:
- space = ' ' * (left - 1)
- args = (',\n%s' % space).join(args)
- lines.append('%s%s' % (line[:left], args))
- else:
- lines.append(line.rstrip())
+ indented_out = self.Indent(out, tabs)
self.LogExit('Exit Define')
- return '\n'.join(lines)
+ return indented_out
+
# Clean a string representing an object definition and return then string
# as a single space delimited set of tokens.
@@ -692,4 +713,3 @@ def Main(args):
if __name__ == '__main__':
sys.exit(Main(sys.argv[1:]))
-
noelallen1 2012/11/15 22:03:18 Make sure to leave blank line to prevent windows p
teravest 2012/11/16 17:33:36 Done.

Powered by Google App Engine
This is Rietveld 408576698