Skip to content

Commit

Permalink
Add support for generating thunk source from IDL.
Browse files Browse the repository at this point in the history
This introduces a few new IDL attributes:
  generate_thunk - Enables thunk generation for an IDL file.
  create_func - Overrides the guessed create function name.
  on_failure - Overrides the default return value on failure.
  report_errors - Allows error reporting to be disabled.

  By using these attributes, we can generate _thunk.cc files for many IDL
  files.

I'll send CLs for moving the thunks separately, as I found it tiring to
review them all in a big lump. I have PPB_Widget_Dev here as an example.

BUG=


Review URL: https://chromiumcodereview.appspot.com/11417010

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@168450 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
teravest@chromium.org committed Nov 17, 2012
1 parent d68206f commit 8c311f0
Show file tree
Hide file tree
Showing 11 changed files with 683 additions and 43 deletions.
15 changes: 13 additions & 2 deletions ppapi/PRESUBMIT.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,13 +157,24 @@ def CheckChange(input_api, output_api):
missing = []
for filename in idl_files:
if filename not in set(h_files):
missing.append(' ppapi/c/%s.idl' % filename)
missing.append('ppapi/api/%s.idl' % filename)

# An IDL change that includes [generate_thunk] doesn't need to have
# an update to the corresponding .h file.
new_thunk_files = []
for filename in missing:
lines = input_api.RightHandSideLines(lambda f: f.LocalPath() == filename)
for line in lines:
if line[2].strip() == '[generate_thunk]':
new_thunk_files.append(filename)
for filename in new_thunk_files:
missing.remove(filename)

if missing:
results.append(
output_api.PresubmitPromptWarning(
'Missing PPAPI header, no change or skipped generation?',
long_text='\n'.join(missing)))
long_text='\n '.join(missing)))

missing_dev = []
missing_stable = []
Expand Down
8 changes: 7 additions & 1 deletion ppapi/api/dev/ppb_widget_dev.idl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
* Implementation of the widgets interface.
*/

[generate_thunk]

label Chrome {
M14 = 0.3,
M23 = 0.4
Expand All @@ -26,6 +28,7 @@ interface PPB_Widget_Dev {
* Paint the given rectangle of the widget into the given image.
* Returns PP_TRUE on success, PP_FALSE on failure.
*/
[report_errors=False]
PP_Bool Paint([in] PP_Resource widget,
[in] PP_Rect rect,
[in] PP_Resource image);
Expand All @@ -34,24 +37,27 @@ interface PPB_Widget_Dev {
* Pass in an event to a widget. It'll return PP_TRUE if the event was
* consumed.
*/
[report_errors=False]
PP_Bool HandleEvent([in] PP_Resource widget, [in] PP_Resource input_event);

/**
* Get the location of the widget.
*/
[report_errors=False]
PP_Bool GetLocation([in] PP_Resource widget,
[out] PP_Rect location);

/**
* Set the location of the widget.
*/
[report_errors=False]
void SetLocation([in] PP_Resource widget,
[in] PP_Rect location);

/**
* Set scale used during paint operations.
*/
[version=0.4]
[version=0.4, report_errors=False]
void SetScale([in] PP_Resource widget,
[in] float_t scale);
};
3 changes: 2 additions & 1 deletion ppapi/generators/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from idl_outfile import IDLOutFile
from idl_parser import ParseFiles
from idl_c_header import HGen
from idl_thunk import TGen
from idl_gen_pnacl import PnaclGen


Expand All @@ -25,6 +26,7 @@ def Main(args):
'--wnone', '--cgen', '--range=start,end',
'--pnacl', '--pnaclshim',
'../native_client/src/untrusted/pnacl_irt_shim/pnacl_shim.c',
'--tgen',
]
current_dir = os.path.abspath(os.getcwd())
script_dir = os.path.abspath(os.path.dirname(__file__))
Expand Down Expand Up @@ -53,4 +55,3 @@ def Main(args):

if __name__ == '__main__':
sys.exit(Main(sys.argv[1:]))

1 change: 0 additions & 1 deletion ppapi/generators/idl_c_header.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

Option('dstroot', 'Base directory of output', default=os.path.join('..', 'c'))
Option('guard', 'Include guard prefix', default=os.path.join('ppapi', 'c'))
Option('out', 'List of output files', default='')


def GetOutFileName(filenode, relpath=None, prefix=None):
Expand Down
75 changes: 49 additions & 26 deletions ppapi/generators/idl_c_proto.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,12 +426,15 @@ def Compose(self, rtype, name, arrayspec, callspec, prefix, func_as_ptr,
# 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)
Expand Down Expand Up @@ -562,9 +565,49 @@ def DefineStruct(self, node, releases, prefix='', comment=False):
#
# Generate a comment or copyright block
#
def Copyright(self, node, tabs=0):
def Copyright(self, node, cpp_style=False):
lines = node.GetName().split('\n')
return CommentLines(lines, tabs)
if cpp_style:
return '//' + '\n//'.join(filter(lambda f: f != '', lines)) + '\n'
return CommentLines(lines)


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:
lines.append(line.rstrip())
else:
left = line.rfind('(') + 1
args = line[left:].split(',')
orig_args = args
orig_left = left
# Try to split on '(arg1)' or '(arg1, arg2)', not '()'
while args[0][0] == ')':
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:
indent = '%s ' % tab
args = (',\n%s' % indent).join([arg.strip() for arg in args])
lines.append('%s\n%s%s' % (line[:left], indent, args))
else:
indent = ' ' * (left - 1)
args = (',\n%s' % indent).join(args)
lines.append('%s%s' % (line[:left], args))
return '\n'.join(lines)


# Define a top level object.
Expand Down Expand Up @@ -596,30 +639,10 @@ def Define(self, node, releases, tabs=0, prefix='', comment=False):
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.
Expand Down
1 change: 1 addition & 0 deletions ppapi/generators/idl_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

GeneratorList = []

Option('out', 'List of output files', default='')
Option('release', 'Which release to generate.', default='')
Option('range', 'Which ranges in the form of MIN,MAX.', default='start,end')

Expand Down
Loading

0 comments on commit 8c311f0

Please sign in to comment.