ppapi/generators/idl_thunk.py
def _MakeNormalMemberBody(filenode, release, node, member, rtype, args,
                          include_version, meta):
  """Returns the body of a typical function.

  Args:
    filenode - IDLNode for the file
    release - release to generate body for
    node - IDLNode for the interface
    member - IDLNode for the member function
    rtype - Return type for the member function
    args - List of 4-tuple arguments for the member function
    include_version - whether to include the version in the invocation
    meta - ThunkBodyMetadata for header hints
  """
  if len(args) == 0:
    # Calling into the "Shared" code for the interface seems like a reasonable
    # heuristic when we don't have any arguments; some thunk code follows this
    # convention today.
    meta.AddApi('ppapi/shared_impl/%s_shared.h' % _StripFileName(filenode))
    return 'return %s::%s();' % (_StripApiName(node.GetName()) + '_Shared',
                                 member.GetName())

  is_callback_func = args[len(args) - 1][0] == 'struct PP_CompletionCallback'

  if is_callback_func:
    call_args = args[:-1] + [('', 'enter.callback()', '', '')]
    meta.AddInclude('ppapi/c/pp_completion_callback.h')
  else:
    call_args = args

  if args[0][0] == 'PP_Instance':
    call_arglist = ', '.join(a[1] for a in call_args)
    function_container = 'functions'
  elif args[0][0] == 'PP_Resource':
    call_arglist = ', '.join(a[1] for a in call_args[1:])
    function_container = 'object'
  else:
    # Calling into the "Shared" code for the interface seems like a reasonable
    # heuristic when the first argument isn't a PP_Instance or a PP_Resource;
    # some thunk code follows this convention today.
    meta.AddApi('ppapi/shared_impl/%s_shared.h' % _StripFileName(filenode))
    return 'return %s::%s(%s);' % (_StripApiName(node.GetName()) + '_Shared',
                                   member.GetName(),
                                   ', '.join(a[1] for a in args))

  function_name = member.GetName()
  if include_version:
    version = node.GetVersion(release).replace('.', '_')
    function_name += version

  invocation = 'enter.%s()->%s(%s)' % (function_container,
                                       function_name,
                                       call_arglist)

  handle_errors = not (member.GetProperty('report_errors') == 'False')
  out_params = _GetOutputParams(member, release)
  if is_callback_func:
    body = '%s\n' % _MakeEnterLine(filenode, node, member, args[0],
                                   handle_errors, args[len(args) - 1][1], meta)
    failure_value = member.GetProperty('on_failure')
    if failure_value is None:
      failure_value = 'enter.retval()'
    failure_return = 'return %s;' % failure_value
    success_return = 'return enter.SetResult(%s);' % invocation
  elif rtype == 'void':
    body = '%s\n' % _MakeEnterLine(filenode, node, member, args[0],
                                   handle_errors, None, meta)
    failure_return = 'return;'
    success_return = '%s;' % invocation  # We don't return anything for void.
  else:
    body = '%s\n' % _MakeEnterLine(filenode, node, member, args[0],
                                   handle_errors, None, meta)
    failure_value = member.GetProperty('on_failure')
    if failure_value is None:
      failure_value = _GetDefaultFailureValue(rtype)
    if failure_value is None:
      raise TGenError('There is no default value for rtype %s. '
                      'Maybe you should provide an on_failure attribute '
                      'in the IDL file.' % rtype)
    failure_return = 'return %s;' % failure_value
    success_return = 'return %s;' % invocation

  if member.GetProperty('always_set_output_parameters'):
    body += 'if (enter.failed()) {\n'
    for param in out_params:
      body += '  memset(%s, 0, sizeof(*%s));\n' % (param, param)
    body += '  %s\n' % failure_return
    body += '}\n'
    body += '%s' % success_return
    meta.AddBuiltinInclude('string.h')
  else:
    body += 'if (enter.failed())\n'
    body += '  %s\n' % failure_return
    body += '%s' % success_return
  return body
Returns the body of a typical function.

  Args:
    filenode - IDLNode for the file
    release - release to generate body for
    node - IDLNode for the interface
    member - IDLNode for the member function
    rtype - Return type for the member function
    args - List of 4-tuple arguments for the member function
    include_version - whether to include the version in the invocation
    meta - ThunkBodyMetadata for header hints
  
Returns the body of a typical function.
Returns the body of a typical function .
def _MakeNormalMemberBody(filenode, release, node, member, rtype, args,
                          include_version, meta):
  if len(args) == 0:
    meta.AddApi('ppapi/shared_impl/%s_shared.h' % _StripFileName(filenode))
    return 'return %s::%s();' % (_StripApiName(node.GetName()) + '_Shared',
                                 member.GetName())
  is_callback_func = args[len(args) - 1][0] == 'struct PP_CompletionCallback'
  if is_callback_func:
    call_args = args[:-1] + [('', 'enter.callback()', '', '')]
    meta.AddInclude('ppapi/c/pp_completion_callback.h')
  else:
    call_args = args
  if args[0][0] == 'PP_Instance':
    call_arglist = ', '.join(a[1] for a in call_args)
    function_container = 'functions'
  elif args[0][0] == 'PP_Resource':
    call_arglist = ', '.join(a[1] for a in call_args[1:])
    function_container = 'object'
  else:
    meta.AddApi('ppapi/shared_impl/%s_shared.h' % _StripFileName(filenode))
    return 'return %s::%s(%s);' % (_StripApiName(node.GetName()) + '_Shared',
                                   member.GetName(),
                                   ', '.join(a[1] for a in args))
  function_name = member.GetName()
  if include_version:
    version = node.GetVersion(release).replace('.', '_')
    function_name += version
  invocation = 'enter.%s()->%s(%s)' % (function_container,
                                       function_name,
                                       call_arglist)
  handle_errors = not (member.GetProperty('report_errors') == 'False')
  out_params = _GetOutputParams(member, release)
  if is_callback_func:
    body = '%s\n' % _MakeEnterLine(filenode, node, member, args[0],
                                   handle_errors, args[len(args) - 1][1], meta)
    failure_value = member.GetProperty('on_failure')
    if failure_value is None:
      failure_value = 'enter.retval()'
    failure_return = 'return %s;' % failure_value
    success_return = 'return enter.SetResult(%s);' % invocation
  elif rtype == 'void':
    body = '%s\n' % _MakeEnterLine(filenode, node, member, args[0],
                                   handle_errors, None, meta)
    failure_return = 'return;'
    success_return = '%s;' % invocation  
  else:
    body = '%s\n' % _MakeEnterLine(filenode, node, member, args[0],
                                   handle_errors, None, meta)
    failure_value = member.GetProperty('on_failure')
    if failure_value is None:
      failure_value = _GetDefaultFailureValue(rtype)
    if failure_value is None:
      raise TGenError('There is no default value for rtype %s. '
                      'Maybe you should provide an on_failure attribute '
                      'in the IDL file.' % rtype)
    failure_return = 'return %s;' % failure_value
    success_return = 'return %s;' % invocation
  if member.GetProperty('always_set_output_parameters'):
    body += 'if (enter.failed()) {\n'
    for param in out_params:
      body += '  memset(%s, 0, sizeof(*%s));\n' % (param, param)
    body += '  %s\n' % failure_return
    body += '}\n'
    body += '%s' % success_return
    meta.AddBuiltinInclude('string.h')
  else:
    body += 'if (enter.failed())\n'
    body += '  %s\n' % failure_return
    body += '%s' % success_return
  return body
def _MakeNormalMemberBody ( filenode , release , node , member , rtype , args , include_version , meta ) : if len ( args ) == 0 : meta . AddApi ( 'ppapi/shared_impl/%s_shared.h' % _StripFileName ( filenode ) ) return 'return %s::%s();' % ( _StripApiName ( node . GetName ( ) ) + '_Shared' , member . GetName ( ) ) is_callback_func = args [ len ( args ) - 1 ] [ 0 ] == 'struct PP_CompletionCallback' if is_callback_func : call_args = args [ : - 1 ] + [ ( '' , 'enter.callback()' , '' , '' ) ] meta . AddInclude ( 'ppapi/c/pp_completion_callback.h' ) else : call_args = args if args [ 0 ] [ 0 ] == 'PP_Instance' : call_arglist = ', ' . join ( a [ 1 ] for a in call_args ) function_container = 'functions' elif args [ 0 ] [ 0 ] == 'PP_Resource' : call_arglist = ', ' . join ( a [ 1 ] for a in call_args [ 1 : ] ) function_container = 'object' else : meta . AddApi ( 'ppapi/shared_impl/%s_shared.h' % _StripFileName ( filenode ) ) return 'return %s::%s(%s);' % ( _StripApiName ( node . GetName ( ) ) + '_Shared' , member . GetName ( ) , ', ' . join ( a [ 1 ] for a in args ) ) function_name = member . GetName ( ) if include_version : version = node . GetVersion ( release ) . replace ( '.' , '_' ) function_name += version invocation = 'enter.%s()->%s(%s)' % ( function_container , function_name , call_arglist ) handle_errors = not ( member . GetProperty ( 'report_errors' ) == 'False' ) out_params = _GetOutputParams ( member , release ) if is_callback_func : body = '%s\n' % _MakeEnterLine ( filenode , node , member , args [ 0 ] , handle_errors , args [ len ( args ) - 1 ] [ 1 ] , meta ) failure_value = member . GetProperty ( 'on_failure' ) if failure_value is None : failure_value = 'enter.retval()' failure_return = 'return %s;' % failure_value success_return = 'return enter.SetResult(%s);' % invocation elif rtype == 'void' : body = '%s\n' % _MakeEnterLine ( filenode , node , member , args [ 0 ] , handle_errors , None , meta ) failure_return = 'return;' success_return = '%s;' % invocation else : body = '%s\n' % _MakeEnterLine ( filenode , node , member , args [ 0 ] , handle_errors , None , meta ) failure_value = member . GetProperty ( 'on_failure' ) if failure_value is None : failure_value = _GetDefaultFailureValue ( rtype ) if failure_value is None : raise TGenError ( 'There is no default value for rtype %s. ' 'Maybe you should provide an on_failure attribute ' 'in the IDL file.' % rtype ) failure_return = 'return %s;' % failure_value success_return = 'return %s;' % invocation if member . GetProperty ( 'always_set_output_parameters' ) : body += 'if (enter.failed()) {\n' for param in out_params : body += '  memset(%s, 0, sizeof(*%s));\n' % ( param , param ) body += '  %s\n' % failure_return body += '}\n' body += '%s' % success_return meta . AddBuiltinInclude ( 'string.h' ) else : body += 'if (enter.failed())\n' body += '  %s\n' % failure_return body += '%s' % success_return return body
Returns the body of a typical function.
Returns the body of a typical function .
"""Returns the body of a typical function.

  Args:
    filenode - IDLNode for the file
    release - release to generate body for
    node - IDLNode for the interface
    member - IDLNode for the member function
    rtype - Return type for the member function
    args - List of 4-tuple arguments for the member function
    include_version - whether to include the version in the invocation
    meta - ThunkBodyMetadata for header hints
  """ # Calling into the "Shared" code for the interface seems like a reasonable # heuristic when we don't have any arguments; some thunk code follows this # convention today. # Calling into the "Shared" code for the interface seems like a reasonable # heuristic when the first argument isn't a PP_Instance or a PP_Resource; # some thunk code follows this convention today. # We don't return anything for void.
filenode
release
node
member
rtype
args
include_version
meta