parameters: (filename, linenum, line, raw_line, cast_type, pattern,
                      error)
docstring: Checks for a C-style cast by looking for the pattern.
  
    This also handles sizeof(type) warnings, due to similarity of content.
  
    Args:
      filename: The name of the current file.
      linenum: The number of the line to check.
      line: The line of code to check.
      raw_line: The raw line of code to check, with comments.
      cast_type: The string for the C++ cast to recommend.  This is either
        reinterpret_cast or static_cast, depending.
      pattern: The regular expression used to find C-style casts.
      error: The function to call with any errors found.
docstring_summary: Checks for a C-style cast by looking for the pattern.
docstring_tokens: Checks for a C - style cast by looking for the pattern .
function: def CheckCStyleCast(filename, linenum, line, raw_line, cast_type, pattern,
                      error):
    """Checks for a C-style cast by looking for the pattern.
  
    This also handles sizeof(type) warnings, due to similarity of content.
  
    Args:
      filename: The name of the current file.
      linenum: The number of the line to check.
      line: The line of code to check.
      raw_line: The raw line of code to check, with comments.
      cast_type: The string for the C++ cast to recommend.  This is either
        reinterpret_cast or static_cast, depending.
      pattern: The regular expression used to find C-style casts.
      error: The function to call with any errors found.
    """
    match = Search(pattern, line)
    if not match:
      return
  
    # e.g., sizeof(int)
    sizeof_match = Match(r'.*sizeof\s*$', line[0:match.start(1) - 1])
    if sizeof_match:
      error(filename, linenum, 'runtime/sizeof', 1,
            'Using sizeof(type).  Use sizeof(varname) instead if possible')
      return
  
    remainder = line[match.end(0):]
  
    # The close paren is for function pointers as arguments to a function.
    # eg, void foo(void (*bar)(int));
    # The semicolon check is a more basic function check; also possibly a
    # function pointer typedef.
    # eg, void foo(int); or void foo(int) const;
    # The equals check is for function pointer assignment.
    # eg, void *(*foo)(int) = ...
    #
    # Right now, this will only catch cases where there's a single argument, and
    # it's unnamed.  It should probably be expanded to check for multiple
    # arguments with some unnamed.
    function_match = Match(r'\s*(\)|=|(const)?\s*(;|\{|throw\(\)))', remainder)
    if function_match:
      if (not function_match.group(3) or
          function_match.group(3) == ';' or
          raw_line.find('/*') < 0):
        error(filename, linenum, 'readability/function', 3,
              'All parameters should be named in a function')
      return
  
    # At this point, all that should be left is actual casts.
    error(filename, linenum, 'readability/casting', 4,
          'Using C-style cast.  Use %s<%s>(...) instead' %
          (cast_type, match.group(1)))
function_tokens: def CheckCStyleCast ( filename , linenum , line , raw_line , cast_type , pattern , error ) : match = Search ( pattern , line ) if not match : return # e.g., sizeof(int) sizeof_match = Match ( r'.*sizeof\s*$' , line [ 0 : match . start ( 1 ) - 1 ] ) if sizeof_match : error ( filename , linenum , 'runtime/sizeof' , 1 , 'Using sizeof(type).  Use sizeof(varname) instead if possible' ) return remainder = line [ match . end ( 0 ) : ] # The close paren is for function pointers as arguments to a function. # eg, void foo(void (*bar)(int)); # The semicolon check is a more basic function check; also possibly a # function pointer typedef. # eg, void foo(int); or void foo(int) const; # The equals check is for function pointer assignment. # eg, void *(*foo)(int) = ... # # Right now, this will only catch cases where there's a single argument, and # it's unnamed.  It should probably be expanded to check for multiple # arguments with some unnamed. function_match = Match ( r'\s*(\)|=|(const)?\s*(;|\{|throw\(\)))' , remainder ) if function_match : if ( not function_match . group ( 3 ) or function_match . group ( 3 ) == ';' or raw_line . find ( '/*' ) < 0 ) : error ( filename , linenum , 'readability/function' , 3 , 'All parameters should be named in a function' ) return # At this point, all that should be left is actual casts. error ( filename , linenum , 'readability/casting' , 4 , 'Using C-style cast.  Use %s<%s>(...) instead' % ( cast_type , match . group ( 1 ) ) )