webkit  2cdf99a9e3038c7e01b3c37e8ad903ecbe5eecf1
https://github.com/WebKit/webkit
Classes | Functions | Variables
webkitpy.style.checkers.cpp Namespace Reference

Classes

class  _ClassInfo
 
class  _ClassState
 
class  _EnumState
 
class  _FileState
 
class  _FunctionState
 
class  _IncludeError
 
class  _IncludeState
 
class  CleansedLines
 
class  FileInfo
 
class  Parameter
 
class  Position
 
class  SingleLineView
 

Functions

def iteratively_replace_matches_with_char (pattern, char_replacement, s)
 
def up_to_unmatched_closing_paren (s)
 
def create_skeleton_parameters (all_parameters)
 
def find_parameter_name_index (skeleton_parameter)
 
def parameter_list (elided_lines, start_position, end_position)
 
def is_cpp_string (line)
 
def find_next_multi_line_comment_start (lines, line_index)
 
def find_next_multi_line_comment_end (lines, line_index)
 
def remove_multi_line_comments_from_range (lines, begin, end)
 
def remove_multi_line_comments (lines, error)
 
def cleanse_comments (line)
 
def close_expression (elided, position)
 
def check_for_copyright (lines, error)
 
def check_for_header_guard (lines, error)
 
def check_for_unicode_replacement_characters (lines, error)
 
def check_for_missing_new_line_at_eof (lines, error)
 
def check_for_extra_new_line_at_eof (lines, error)
 
def check_for_multiline_comments_and_strings (clean_lines, line_number, error)
 
def check_posix_threading (clean_lines, line_number, error)
 
def check_invalid_increment (clean_lines, line_number, error)
 
def regex_for_lambdas_and_blocks (line, line_number, file_state, error)
 
def check_for_non_standard_constructs (clean_lines, line_number, class_state, error)
 
def check_spacing_for_function_call (line, line_number, file_state, error)
 
def is_blank_line (line)
 
def detect_functions (clean_lines, line_number, function_state, error)
 
def check_for_function_lengths (clean_lines, line_number, function_state, error)
 
def check_function_definition (filename, file_extension, clean_lines, line_number, function_state, error)
 
def check_for_leaky_patterns (clean_lines, line_number, function_state, error)
 
def check_spacing (file_extension, clean_lines, line_number, file_state, error)
 
def check_member_initialization_list (clean_lines, line_number, error)
 
def get_previous_non_blank_line (clean_lines, line_number)
 
def check_namespace_indentation (clean_lines, line_number, file_extension, file_state, error)
 
def check_enum_casing (clean_lines, line_number, enum_state, error)
 
def check_directive_indentation (clean_lines, line_number, file_state, error)
 
def get_initial_spaces_for_line (clean_line)
 
def check_indentation_amount (clean_lines, line_number, error)
 
def check_using_std (clean_lines, line_number, file_state, error)
 
def check_using_namespace (clean_lines, line_number, file_extension, error)
 
def check_max_min_macros (clean_lines, line_number, file_state, error)
 
def check_wtf_move (clean_lines, line_number, file_state, error)
 
def check_ctype_functions (clean_lines, line_number, file_state, error)
 
def check_switch_indentation (clean_lines, line_number, error)
 
def check_braces (clean_lines, line_number, file_state, error)
 
def check_exit_statement_simplifications (clean_lines, line_number, error)
 

Variables

string INCLUDE_IO_INJECTION_KEY = 'include_header_io'
 

Function Documentation

◆ check_braces()

def webkitpy.style.checkers.cpp.check_braces (   clean_lines,
  line_number,
  file_state,
  error 
)
Looks for misplaced braces (e.g. at the end of line).

Args:
  clean_lines: A CleansedLines instance containing the file.
  line_number: The number of the line to check.
  error: The function to call with any errors found.

◆ check_ctype_functions()

def webkitpy.style.checkers.cpp.check_ctype_functions (   clean_lines,
  line_number,
  file_state,
  error 
)
Looks for use of the standard functions in ctype.h and suggest they be replaced
   by use of equivilent ones in <wtf/ASCIICType.h>?.

Args:
  clean_lines: A CleansedLines instance containing the file.
  line_number: The number of the line to check.
  file_state: A _FileState instance which maintains information about
              the state of things in the file.
  error: The function to call with any errors found.

◆ check_directive_indentation()

def webkitpy.style.checkers.cpp.check_directive_indentation (   clean_lines,
  line_number,
  file_state,
  error 
)
Looks for indentation of preprocessor directives.

Args:
  clean_lines: A CleansedLines instance containing the file.
  line_number: The number of the line to check.
  file_state: A _FileState instance which maintains information about
              the state of things in the file.
  error: The function to call with any errors found.

◆ check_enum_casing()

def webkitpy.style.checkers.cpp.check_enum_casing (   clean_lines,
  line_number,
  enum_state,
  error 
)
Looks for incorrectly named enum values.

Args:
  clean_lines: A CleansedLines instance containing the file.
  line_number: The number of the line to check.
  enum_state: A _EnumState instance which maintains enum declaration state.
  error: The function to call with any errors found.

◆ check_exit_statement_simplifications()

def webkitpy.style.checkers.cpp.check_exit_statement_simplifications (   clean_lines,
  line_number,
  error 
)
Looks for else or else-if statements that should be written as an
if statement when the prior if concludes with a return, break, continue or
goto statement.

Args:
  clean_lines: A CleansedLines instance containing the file.
  line_number: The number of the line to check.
  error: The function to call with any errors found.

◆ check_for_copyright()

def webkitpy.style.checkers.cpp.check_for_copyright (   lines,
  error 
)
Logs an error if no Copyright message appears at the top of the file.

◆ check_for_extra_new_line_at_eof()

def webkitpy.style.checkers.cpp.check_for_extra_new_line_at_eof (   lines,
  error 
)
Logs an error if there is not a single newline at the end of the file.

Args:
  lines: An array of strings, each representing a line of the file.
  error: The function to call with any errors found.

◆ check_for_function_lengths()

def webkitpy.style.checkers.cpp.check_for_function_lengths (   clean_lines,
  line_number,
  function_state,
  error 
)
Reports for long function bodies.

For an overview why this is done, see:
http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml#Write_Short_Functions

Blank/comment lines are not counted so as to avoid encouraging the removal
of vertical space and commments just to get through a lint check.
NOLINT *on the last line of a function* disables this check.

Args:
  clean_lines: A CleansedLines instance containing the file.
  line_number: The number of the line to check.
  function_state: Current function name and lines in body so far.
  error: The function to call with any errors found.

◆ check_for_header_guard()

def webkitpy.style.checkers.cpp.check_for_header_guard (   lines,
  error 
)
Checks that the file contains a header guard.

Logs an error if there was an #ifndef guard in a header
that should be a #pragma once guard.

Args:
  lines: An array of strings, each representing a line of the file.
  error: The function to call with any errors found.

◆ check_for_leaky_patterns()

def webkitpy.style.checkers.cpp.check_for_leaky_patterns (   clean_lines,
  line_number,
  function_state,
  error 
)
Check for constructs known to be leak prone.
Args:
  clean_lines: A CleansedLines instance containing the file.
  line_number: The number of the line to check.
  function_state: Current function name and lines in body so far.
  error: The function to call with any errors found.

◆ check_for_missing_new_line_at_eof()

def webkitpy.style.checkers.cpp.check_for_missing_new_line_at_eof (   lines,
  error 
)
Logs an error if there is not a newline character at the end of the file.

Args:
  lines: An array of strings, each representing a line of the file.
  error: The function to call with any errors found.

◆ check_for_multiline_comments_and_strings()

def webkitpy.style.checkers.cpp.check_for_multiline_comments_and_strings (   clean_lines,
  line_number,
  error 
)
Logs an error if we see /* ... */ or "..." that extend past one line.

/* ... */ comments are legit inside macros, for one line.
Otherwise, we prefer // comments, so it's ok to warn about the
other.  Likewise, it's ok for strings to extend across multiple
lines, as long as a line continuation character (backslash)
terminates each line. Although not currently prohibited by the C++
style guide, it's ugly and unnecessary. We don't do well with either
in this lint program, so we warn about both.

Args:
  clean_lines: A CleansedLines instance containing the file.
  line_number: The number of the line to check.
  error: The function to call with any errors found.

◆ check_for_non_standard_constructs()

def webkitpy.style.checkers.cpp.check_for_non_standard_constructs (   clean_lines,
  line_number,
  class_state,
  error 
)
Logs an error if we see certain non-ANSI constructs ignored by gcc-2.

Complain about several constructs which gcc-2 accepts, but which are
not standard C++.  Warning about these in lint is one way to ease the
transition to new compilers.
- put storage class first (e.g. "static const" instead of "const static").
- "%lld" instead of %qd" in printf-type functions.
- "%1$d" is non-standard in printf-type functions.
- "\%" is an undefined character escape sequence.
- text after #endif is not allowed.
- invalid inner-style forward declaration.
- >? and <? operators, and their >?= and <?= cousins.
- classes with virtual methods need virtual destructors (compiler warning
    available, but not turned on yet.)

Additionally, check for constructor/destructor style violations as it
is very convenient to do so while checking for gcc-2 compliance.

Args:
  clean_lines: A CleansedLines instance containing the file.
  line_number: The number of the line to check.
  class_state: A _ClassState instance which maintains information about
               the current stack of nested class declarations being parsed.
  error: A callable to which errors are reported, which takes parameters:
         line number, error level, and message

◆ check_for_unicode_replacement_characters()

def webkitpy.style.checkers.cpp.check_for_unicode_replacement_characters (   lines,
  error 
)
Logs an error for each line containing Unicode replacement characters.

These indicate that either the file contained invalid UTF-8 (likely)
or Unicode replacement characters (which it shouldn't).  Note that
it's possible for this to throw off line numbering if the invalid
UTF-8 occurred adjacent to a newline.

Args:
  lines: An array of strings, each representing a line of the file.
  error: The function to call with any errors found.

◆ check_function_definition()

def webkitpy.style.checkers.cpp.check_function_definition (   filename,
  file_extension,
  clean_lines,
  line_number,
  function_state,
  error 
)
Check that function definitions for style issues.

Specifically, check that parameter names in declarations add information.

Args:
   filename: Filename of the file that is being processed.
   file_extension: The current file extension, without the leading dot.
   clean_lines: A CleansedLines instance containing the file.
   line_number: The number of the line to check.
   function_state: Current function name and lines in body so far.
   error: The function to call with any errors found.

◆ check_indentation_amount()

def webkitpy.style.checkers.cpp.check_indentation_amount (   clean_lines,
  line_number,
  error 
)

◆ check_invalid_increment()

def webkitpy.style.checkers.cpp.check_invalid_increment (   clean_lines,
  line_number,
  error 
)
Checks for invalid increment *count++.

For example following function:
void increment_counter(int* count) {
    *count++;
}
is invalid, because it effectively does count++, moving pointer, and should
be replaced with ++*count, (*count)++ or *count += 1.

Args:
  clean_lines: A CleansedLines instance containing the file.
  line_number: The number of the line to check.
  error: The function to call with any errors found.

◆ check_max_min_macros()

def webkitpy.style.checkers.cpp.check_max_min_macros (   clean_lines,
  line_number,
  file_state,
  error 
)
Looks for use of MAX() and MIN() macros that should be replaced with std::max() and std::min().

Args:
  clean_lines: A CleansedLines instance containing the file.
  line_number: The number of the line to check.
  file_state: A _FileState instance which maintains information about
              the state of things in the file.
  error: The function to call with any errors found.

◆ check_member_initialization_list()

def webkitpy.style.checkers.cpp.check_member_initialization_list (   clean_lines,
  line_number,
  error 
)
Look for style errors in member initialization list of classes.

Args:
  clean_lines: A CleansedLines instance containing the file.
  line_number: The number of the line to check.
  error: The function to call with any errors found.

◆ check_namespace_indentation()

def webkitpy.style.checkers.cpp.check_namespace_indentation (   clean_lines,
  line_number,
  file_extension,
  file_state,
  error 
)
Looks for indentation errors inside of namespaces.

Args:
  clean_lines: A CleansedLines instance containing the file.
  line_number: The number of the line to check.
  file_extension: The extension (dot not included) of the file.
  file_state: A _FileState instance which maintains information about
              the state of things in the file.
  error: The function to call with any errors found.

◆ check_posix_threading()

def webkitpy.style.checkers.cpp.check_posix_threading (   clean_lines,
  line_number,
  error 
)
Checks for calls to thread-unsafe functions.

Much code has been originally written without consideration of
multi-threading. Also, engineers are relying on their old experience;
they have learned posix before threading extensions were added. These
tests guide the engineers to use thread-safe functions (when using
posix directly).

Args:
  clean_lines: A CleansedLines instance containing the file.
  line_number: The number of the line to check.
  error: The function to call with any errors found.

◆ check_spacing()

def webkitpy.style.checkers.cpp.check_spacing (   file_extension,
  clean_lines,
  line_number,
  file_state,
  error 
)
Checks for the correctness of various spacing issues in the code.

Things we check for: spaces around operators, spaces after
if/for/while/switch, no spaces around parens in function calls, two
spaces between code and comment, don't start a block with a blank
line, don't end a function with a blank line, don't have too many
blank lines in a row.

Args:
  file_extension: The current file extension, without the leading dot.
  clean_lines: A CleansedLines instance containing the file.
  line_number: The number of the line to check.
  error: The function to call with any errors found.

◆ check_spacing_for_function_call()

def webkitpy.style.checkers.cpp.check_spacing_for_function_call (   line,
  line_number,
  file_state,
  error 
)
Checks for the correctness of various spacing around function calls.

Args:
  line: The text of the line to check.
  line_number: The number of the line to check.
  error: The function to call with any errors found.

◆ check_switch_indentation()

def webkitpy.style.checkers.cpp.check_switch_indentation (   clean_lines,
  line_number,
  error 
)
Looks for indentation errors inside of switch statements.

Args:
  clean_lines: A CleansedLines instance containing the file.
  line_number: The number of the line to check.
  error: The function to call with any errors found.

◆ check_using_namespace()

def webkitpy.style.checkers.cpp.check_using_namespace (   clean_lines,
  line_number,
  file_extension,
  error 
)
Looks for 'using namespace foo;' which should be removed.

Args:
  clean_lines: A CleansedLines instance containing the file.
  line_number: The number of the line to check.
  file_extension: The extension (dot not included) of the file.
  error: The function to call with any errors found.

◆ check_using_std()

def webkitpy.style.checkers.cpp.check_using_std (   clean_lines,
  line_number,
  file_state,
  error 
)
Looks for 'using std::foo;' statements which should be replaced with 'using namespace std;'.

Args:
  clean_lines: A CleansedLines instance containing the file.
  line_number: The number of the line to check.
  file_state: A _FileState instance which maintains information about
              the state of things in the file.
  error: The function to call with any errors found.

◆ check_wtf_move()

def webkitpy.style.checkers.cpp.check_wtf_move (   clean_lines,
  line_number,
  file_state,
  error 
)
Looks for use of 'std::move()' which should be replaced with 'WTFMove()'.

Args:
  clean_lines: A CleansedLines instance containing the file.
  line_number: The number of the line to check.
  file_state: A _FileState instance which maintains information about
              the state of things in the file.
  error: The function to call with any errors found.

◆ cleanse_comments()

def webkitpy.style.checkers.cpp.cleanse_comments (   line)
Removes //-comments and single-line C-style /* */ comments.

Args:
  line: A line of C++ source.

Returns:
  The line with single-line comments removed.

◆ close_expression()

def webkitpy.style.checkers.cpp.close_expression (   elided,
  position 
)
If input points to ( or { or [, finds the position that closes it.

If elided[position.row][position.column] points to a '(' or '{' or '[',
finds the line_number/pos that correspond to the closing of the expression.

 Args:
   elided: A CleansedLines.elided instance containing the file.
   position: The position of the opening item.

 Returns:
  The Position *past* the closing brace, or Position(len(elided), -1)
  if we never find a close. Note we ignore strings and comments when matching.

◆ create_skeleton_parameters()

def webkitpy.style.checkers.cpp.create_skeleton_parameters (   all_parameters)
Converts a parameter list to a skeleton version.

The skeleton only has one word for the parameter name, one word for the type,
and commas after each parameter and only there. Everything in the skeleton
remains in the same columns as the original.

◆ detect_functions()

def webkitpy.style.checkers.cpp.detect_functions (   clean_lines,
  line_number,
  function_state,
  error 
)
Finds where functions start and end.

Uses a simplistic algorithm assuming other style guidelines
(especially spacing) are followed.
Trivial bodies are unchecked, so constructors with huge initializer lists
may be missed.

Args:
  clean_lines: A CleansedLines instance containing the file.
  line_number: The number of the line to check.
  function_state: Current function name and lines in body so far.
  error: The function to call with any errors found.

◆ find_next_multi_line_comment_end()

def webkitpy.style.checkers.cpp.find_next_multi_line_comment_end (   lines,
  line_index 
)
We are inside a comment, find the end marker.

◆ find_next_multi_line_comment_start()

def webkitpy.style.checkers.cpp.find_next_multi_line_comment_start (   lines,
  line_index 
)
Find the beginning marker for a multiline comment.

◆ find_parameter_name_index()

def webkitpy.style.checkers.cpp.find_parameter_name_index (   skeleton_parameter)
Determines where the parametere name starts given the skeleton parameter.

◆ get_initial_spaces_for_line()

def webkitpy.style.checkers.cpp.get_initial_spaces_for_line (   clean_line)

◆ get_previous_non_blank_line()

def webkitpy.style.checkers.cpp.get_previous_non_blank_line (   clean_lines,
  line_number 
)
Return the most recent non-blank line and its line number.

Args:
  clean_lines: A CleansedLines instance containing the file contents.
  line_number: The number of the line to check.

Returns:
  A tuple with two elements.  The first element is the contents of the last
  non-blank line before the current line, or the empty string if this is the
  first non-blank line.  The second is the line number of that line, or -1
  if this is the first non-blank line.

◆ is_blank_line()

def webkitpy.style.checkers.cpp.is_blank_line (   line)
Returns true if the given line is blank.

We consider a line to be blank if the line is empty or consists of
only white spaces.

Args:
  line: A line of a string.

Returns:
  True, if the given line is blank.

◆ is_cpp_string()

def webkitpy.style.checkers.cpp.is_cpp_string (   line)
Does line terminate so, that the next symbol is in string constant.

This function does not consider single-line nor multi-line comments.

Args:
  line: is a partial line of code starting from the 0..n.

Returns:
  True, if next character appended to 'line' is inside a
  string constant.

◆ iteratively_replace_matches_with_char()

def webkitpy.style.checkers.cpp.iteratively_replace_matches_with_char (   pattern,
  char_replacement,
  s 
)
Returns the string with replacement done.

Every character in the match is replaced with char.
Due to the iterative nature, pattern should not match char or
there will be an infinite loop.

Example:
  pattern = r'<[^>]>' # template parameters
  char_replacement =  '_'
  s =     'A<B<C, D>>'
  Returns 'A_________'

Args:
  pattern: The regex to match.
  char_replacement: The character to put in place of every
                    character of the match.
  s: The string on which to do the replacements.

Returns:
  True, if the given line is blank.

◆ parameter_list()

def webkitpy.style.checkers.cpp.parameter_list (   elided_lines,
  start_position,
  end_position 
)
Generator for a function's parameters.

◆ regex_for_lambdas_and_blocks()

def webkitpy.style.checkers.cpp.regex_for_lambdas_and_blocks (   line,
  line_number,
  file_state,
  error 
)

◆ remove_multi_line_comments()

def webkitpy.style.checkers.cpp.remove_multi_line_comments (   lines,
  error 
)
Removes multiline (c-style) comments from lines.

◆ remove_multi_line_comments_from_range()

def webkitpy.style.checkers.cpp.remove_multi_line_comments_from_range (   lines,
  begin,
  end 
)
Clears a range of lines for multi-line comments.

◆ up_to_unmatched_closing_paren()

def webkitpy.style.checkers.cpp.up_to_unmatched_closing_paren (   s)
Splits a string into two parts up to first unmatched ')'.

Args:
  s: a string which is a substring of line after '('
  (e.g., "a == (b + c))").

Returns:
  A pair of strings (prefix before first unmatched ')',
  remainder of s after first unmatched ')'), e.g.,
  up_to_unmatched_closing_paren("a == (b + c)) { ")
  returns "a == (b + c)", " {".
  Returns None, None if there is no unmatched ')'

Variable Documentation

◆ INCLUDE_IO_INJECTION_KEY

string webkitpy.style.checkers.cpp.INCLUDE_IO_INJECTION_KEY = 'include_header_io'