parameters: (func_name, ast_param, arg, args)
docstring: Returns tuple of (bool, str) and appends to args.
docstring_summary: Returns tuple of (bool, str) and appends to args.
docstring_tokens: Returns tuple of ( bool str ) and appends to args .
function: def _CreateInputParameter(func_name, ast_param, arg, args):
    """Returns tuple of (bool, str) and appends to args."""
    # First return value is bool check_nullptr.
    # Second return value is a string to create C++ stack var named arg.
    # Sideeffect: args += arg getter.
    ptype = ast_param.type
    ctype = ptype.cpp_type
    smartptr = (ctype.startswith('::std::unique_ptr') or
                ctype.startswith('::std::shared_ptr'))
    # std::function special case
    if not ctype:
      assert ptype.callable, 'Non-callable param has empty cpp_type'
      if len(ptype.callable.returns) > 1:
        raise ValueError('Callbacks may not have any output parameters, '
                         '%s param %s has %d' % (func_name, ast_param.name.native,
                                                 len(ptype.callable.returns)-1))
      args.append('std::move(%s)' % arg)
      return (
          False,
          'std::function<%s> %s;' % (
              astutils.StdFuncParamStr(ptype.callable), arg))
    # T*
    if ptype.cpp_raw_pointer:
      if ptype.cpp_toptr_conversion:
        args.append(arg)
        return (False, '%s %s;' % (ctype, arg))
      t = ctype[:-1]
      if ctype.endswith('*'):
        if ptype.cpp_abstract:
          if ptype.cpp_touniqptr_conversion:
            args.append(arg+'.get()')
            return (False, '::std::unique_ptr<%s> %s;' % (t, arg))
        elif ptype.cpp_has_public_dtor:
          # Create a copy on stack and pass its address.
          if ptype.cpp_has_def_ctor:
            args.append('&'+arg)
            return (False, '%s %s;' % (t, arg))
          else:
            args.append('&%s.value()' % arg)
            return (False, '::absl::optional<%s> %s;' % (t, arg))
      raise TypeError("Can't convert %s to %s" % (ptype.lang_type, ctype))
    if ((smartptr or ptype.cpp_abstract) and
        not ptype.cpp_touniqptr_conversion and
        not (ctype.startswith('::std::unique_ptr') and
             ast_param.default_value == 'default')):
      raise TypeError('Can\'t create "%s" variable (C++ type %s) in function %s'
                      ', no valid conversion defined'
                      % (ast_param.name.native, ctype, func_name))
    # unique_ptr<T>, shared_ptr<T>
    if smartptr:
      args.append('std::move(%s)' % arg)
      return (False, '%s %s;' % (ctype, arg))
    # T, [const] T&
    if ptype.cpp_toptr_conversion:
      args.append('*'+arg)
      return (True, '%s* %s;' % (ctype, arg))
    if ptype.cpp_abstract:  # for AbstractType &
      args.append('*'+arg)
      return (False, 'std::unique_ptr<%s> %s;' % (ctype, arg))
    # Create a copy on stack (even fot T&, most cases should have to_T* conv).
    if ptype.cpp_has_def_ctor:
      args.append('std::move(%s)' % arg)
      return (False, '%s %s;' % (ctype, arg))
    else:
      args.append(arg+'.value()')
      return (False, '::absl::optional<%s> %s;' % (ctype, arg))
function_tokens: def _CreateInputParameter ( func_name , ast_param , arg , args ) : # First return value is bool check_nullptr. # Second return value is a string to create C++ stack var named arg. # Sideeffect: args += arg getter. ptype = ast_param . type ctype = ptype . cpp_type smartptr = ( ctype . startswith ( '::std::unique_ptr' ) or ctype . startswith ( '::std::shared_ptr' ) ) # std::function special case if not ctype : assert ptype . callable , 'Non-callable param has empty cpp_type' if len ( ptype . callable . returns ) > 1 : raise ValueError ( 'Callbacks may not have any output parameters, ' '%s param %s has %d' % ( func_name , ast_param . name . native , len ( ptype . callable . returns ) - 1 ) ) args . append ( 'std::move(%s)' % arg ) return ( False , 'std::function<%s> %s;' % ( astutils . StdFuncParamStr ( ptype . callable ) , arg ) ) # T* if ptype . cpp_raw_pointer : if ptype . cpp_toptr_conversion : args . append ( arg ) return ( False , '%s %s;' % ( ctype , arg ) ) t = ctype [ : - 1 ] if ctype . endswith ( '*' ) : if ptype . cpp_abstract : if ptype . cpp_touniqptr_conversion : args . append ( arg + '.get()' ) return ( False , '::std::unique_ptr<%s> %s;' % ( t , arg ) ) elif ptype . cpp_has_public_dtor : # Create a copy on stack and pass its address. if ptype . cpp_has_def_ctor : args . append ( '&' + arg ) return ( False , '%s %s;' % ( t , arg ) ) else : args . append ( '&%s.value()' % arg ) return ( False , '::absl::optional<%s> %s;' % ( t , arg ) ) raise TypeError ( "Can't convert %s to %s" % ( ptype . lang_type , ctype ) ) if ( ( smartptr or ptype . cpp_abstract ) and not ptype . cpp_touniqptr_conversion and not ( ctype . startswith ( '::std::unique_ptr' ) and ast_param . default_value == 'default' ) ) : raise TypeError ( 'Can\'t create "%s" variable (C++ type %s) in function %s' ', no valid conversion defined' % ( ast_param . name . native , ctype , func_name ) ) # unique_ptr<T>, shared_ptr<T> if smartptr : args . append ( 'std::move(%s)' % arg ) return ( False , '%s %s;' % ( ctype , arg ) ) # T, [const] T& if ptype . cpp_toptr_conversion : args . append ( '*' + arg ) return ( True , '%s* %s;' % ( ctype , arg ) ) if ptype . cpp_abstract : # for AbstractType & args . append ( '*' + arg ) return ( False , 'std::unique_ptr<%s> %s;' % ( ctype , arg ) ) # Create a copy on stack (even fot T&, most cases should have to_T* conv). if ptype . cpp_has_def_ctor : args . append ( 'std::move(%s)' % arg ) return ( False , '%s %s;' % ( ctype , arg ) ) else : args . append ( arg + '.value()' ) return ( False , '::absl::optional<%s> %s;' % ( ctype , arg ) )