def CheckPosixThreading(filename, clean_lines, linenum, error):

line = clean_lines.elided[linenum]<EOL>for single_thread_func, multithread_safe_func, pattern in _THREADING_LIST:<EOL><INDENT>if Search(pattern, line):<EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:2>,<EOL>'<STR_LIT>' + multithread_safe_func +<EOL>'<STR_LIT>' + single_thread_func +<EOL>'<STR_LIT>')<EOL><DEDENT><DEDENT>

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:
      filename: The name of the current file.
      clean_lines: A CleansedLines instance containing the file.
      linenum: The number of the line to check.
      error: The function to call with any errors found.


def CheckVlogArguments(filename, clean_lines, linenum, error):

line = clean_lines.elided[linenum]<EOL>if Search(r'<STR_LIT>', line):<EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:5>,<EOL>'<STR_LIT>'<EOL>'<STR_LIT>')<EOL><DEDENT>

Checks that VLOG() is only used for defining a logging level.

    For example, VLOG(2) is correct. VLOG(INFO), VLOG(WARNING), VLOG(ERROR), and
    VLOG(FATAL) are not.

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


def CheckInvalidIncrement(filename, clean_lines, linenum, error):

line = clean_lines.elided[linenum]<EOL>if _RE_PATTERN_INVALID_INCREMENT.match(line):<EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:5>,<EOL>'<STR_LIT>')<EOL><DEDENT>

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:
      filename: The name of the current file.
      clean_lines: A CleansedLines instance containing the file.
      linenum: The number of the line to check.
      error: The function to call with any errors found.


def CheckForNonStandardConstructs(filename, clean_lines, linenum,<EOL>nesting_state, error):

<EOL>line = clean_lines.lines[linenum]<EOL>if Search(r'<STR_LIT>', line):<EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:3>,<EOL>'<STR_LIT>')<EOL><DEDENT>if Search(r'<STR_LIT>', line):<EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:2>,<EOL>'<STR_LIT>')<EOL><DEDENT>line = line.replace('<STR_LIT>', '<STR_LIT>')<EOL>if Search(r'<STR_LIT>', line):<EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:3>,<EOL>'<STR_LIT>')<EOL><DEDENT>line = clean_lines.elided[linenum]<EOL>if Search(r'<STR_LIT>'<EOL>r'<STR_LIT>'<EOL>r'<STR_LIT>'<EOL>r'<STR_LIT>',<EOL>line):<EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:5>,<EOL>'<STR_LIT>'<EOL>'<STR_LIT>')<EOL><DEDENT>if Match(r'<STR_LIT>', line):<EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:5>,<EOL>'<STR_LIT>')<EOL><DEDENT>if Match(r'<STR_LIT>', line):<EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:5>,<EOL>'<STR_LIT>')<EOL><DEDENT>if Search(r'<STR_LIT>',<EOL>line):<EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:3>,<EOL>'<STR_LIT>')<EOL><DEDENT>if Search(r'<STR_LIT>', line):<EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:2>,<EOL>'<STR_LIT>'<EOL>'<STR_LIT>')<EOL><DEDENT>classinfo = nesting_state.InnermostClass()<EOL>if not classinfo or not classinfo.seen_open_brace:<EOL><INDENT>return<EOL><DEDENT>base_classname = classinfo.name.split('<STR_LIT>')[-<NUM_LIT:1>]<EOL>explicit_constructor_match = Match(<EOL>r'<STR_LIT>'<EOL>r'<STR_LIT>'<EOL>% re.escape(base_classname),<EOL>line)<EOL>if explicit_constructor_match:<EOL><INDENT>is_marked_explicit = explicit_constructor_match.group(<NUM_LIT:1>)<EOL>if not explicit_constructor_match.group(<NUM_LIT:2>):<EOL><INDENT>constructor_args = []<EOL><DEDENT>else:<EOL><INDENT>constructor_args = explicit_constructor_match.group(<NUM_LIT:2>).split('<STR_LIT:U+002C>')<EOL><DEDENT>i = <NUM_LIT:0><EOL>while i < len(constructor_args):<EOL><INDENT>constructor_arg = constructor_args[i]<EOL>while (constructor_arg.count('<STR_LIT:<>') > constructor_arg.count('<STR_LIT:>>') or<EOL>constructor_arg.count('<STR_LIT:(>') > constructor_arg.count('<STR_LIT:)>')):<EOL><INDENT>constructor_arg += '<STR_LIT:U+002C>' + constructor_args[i + <NUM_LIT:1>]<EOL>del constructor_args[i + <NUM_LIT:1>]<EOL><DEDENT>constructor_args[i] = constructor_arg<EOL>i += <NUM_LIT:1><EOL><DEDENT>variadic_args = [arg for arg in constructor_args if '<STR_LIT>' in arg]<EOL>defaulted_args = [arg for arg in constructor_args if '<STR_LIT:=>' in arg]<EOL>noarg_constructor = (not constructor_args or  <EOL>(len(constructor_args) == <NUM_LIT:1> and<EOL>constructor_args[<NUM_LIT:0>].strip() == '<STR_LIT>'))<EOL>onearg_constructor = ((len(constructor_args) == <NUM_LIT:1> and  <EOL>not noarg_constructor) or<EOL>(len(constructor_args) >= <NUM_LIT:1> and<EOL>not noarg_constructor and<EOL>len(defaulted_args) >= len(constructor_args) - <NUM_LIT:1>) or<EOL>(len(constructor_args) <= <NUM_LIT:2> and<EOL>len(variadic_args) >= <NUM_LIT:1>))<EOL>initializer_list_constructor = bool(<EOL>onearg_constructor and<EOL>Search(r'<STR_LIT>', constructor_args[<NUM_LIT:0>]))<EOL>copy_constructor = bool(<EOL>onearg_constructor and<EOL>Match(r'<STR_LIT>'<EOL>% re.escape(base_classname), constructor_args[<NUM_LIT:0>].strip()))<EOL>if (not is_marked_explicit and<EOL>onearg_constructor and<EOL>not initializer_list_constructor and<EOL>not copy_constructor):<EOL><INDENT>if defaulted_args or variadic_args:<EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:5>,<EOL>'<STR_LIT>'<EOL>'<STR_LIT>')<EOL><DEDENT>else:<EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:5>,<EOL>'<STR_LIT>')<EOL><DEDENT><DEDENT>elif is_marked_explicit and not onearg_constructor:<EOL><INDENT>if noarg_constructor:<EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:5>,<EOL>'<STR_LIT>')<EOL><DEDENT><DEDENT><DEDENT>

r"""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.

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

    Args:
      filename: The name of the current file.
      clean_lines: A CleansedLines instance containing the file.
      linenum: The number of the line to check.
      nesting_state: A NestingState instance which maintains information about
                     the current stack of nested blocks being parsed.
      error: A callable to which errors are reported, which takes 4 arguments:
             filename, line number, error level, and message


def CheckSpacingForFunctionCall(filename, clean_lines, linenum, error):

line = clean_lines.elided[linenum]<EOL>fncall = line    <EOL>for pattern in (r'<STR_LIT>',<EOL>r'<STR_LIT>',<EOL>r'<STR_LIT>',<EOL>r'<STR_LIT>'):<EOL><INDENT>match = Search(pattern, line)<EOL>if match:<EOL><INDENT>fncall = match.group(<NUM_LIT:1>)    <EOL>break<EOL><DEDENT><DEDENT>if (  <EOL>not Search(r'<STR_LIT>',<EOL>fncall) and<EOL>not Search(r'<STR_LIT>', fncall) and<EOL>not Search(r'<STR_LIT>', fncall)):<EOL><INDENT>if Search(r'<STR_LIT>', fncall):      <EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:4>,<EOL>'<STR_LIT>')<EOL><DEDENT>elif Search(r'<STR_LIT>', fncall):<EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:2>,<EOL>'<STR_LIT>')<EOL><DEDENT>if (Search(r'<STR_LIT>', fncall) and<EOL>not Search(r'<STR_LIT>', fncall) and<EOL>not Search(r'<STR_LIT>', fncall) and<EOL>not Search(r'<STR_LIT>', fncall) and<EOL>not Search(r'<STR_LIT>', fncall)):<EOL><INDENT>if Search(r'<STR_LIT>', line):<EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:0>,<EOL>'<STR_LIT>')<EOL><DEDENT>else:<EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:4>,<EOL>'<STR_LIT>')<EOL><DEDENT><DEDENT>if Search(r'<STR_LIT>', fncall):<EOL><INDENT>if Search(r'<STR_LIT>', fncall):<EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:2>,<EOL>'<STR_LIT>')<EOL><DEDENT>else:<EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:2>,<EOL>'<STR_LIT>')<EOL><DEDENT><DEDENT><DEDENT>

Checks for the correctness of various spacing around function calls.

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


return not line or line.isspace()<EOL>

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.


def CheckForFunctionLengths(filename, clean_lines, linenum,<EOL>function_state, error):

lines = clean_lines.lines<EOL>line = lines[linenum]<EOL>joined_line = '<STR_LIT>'<EOL>starting_func = False<EOL>regexp = r'<STR_LIT>'  <EOL>match_result = Match(regexp, line)<EOL>if match_result:<EOL><INDENT>function_name = match_result.group(<NUM_LIT:1>).split()[-<NUM_LIT:1>]<EOL>if function_name == '<STR_LIT>' or function_name == '<STR_LIT>' or (<EOL>not Match(r'<STR_LIT>', function_name)):<EOL><INDENT>starting_func = True<EOL><DEDENT><DEDENT>if starting_func:<EOL><INDENT>body_found = False<EOL>for start_linenum in range(linenum, clean_lines.NumLines()):<EOL><INDENT>start_line = lines[start_linenum]<EOL>joined_line += '<STR_LIT:U+0020>' + start_line.lstrip()<EOL>if Search(r'<STR_LIT>', start_line):  <EOL><INDENT>body_found = True<EOL>break                              <EOL><DEDENT>elif Search(r'<STR_LIT:{>', start_line):<EOL><INDENT>body_found = True<EOL>function = Search(r'<STR_LIT>', line).group(<NUM_LIT:1>)<EOL>if Match(r'<STR_LIT>', function):    <EOL><INDENT>parameter_regexp = Search(r'<STR_LIT>', joined_line)<EOL>if parameter_regexp:             <EOL><INDENT>function += parameter_regexp.group(<NUM_LIT:1>)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>function += '<STR_LIT>'<EOL><DEDENT>function_state.Begin(function)<EOL>break<EOL><DEDENT><DEDENT>if not body_found:<EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:5>,<EOL>'<STR_LIT>')<EOL><DEDENT><DEDENT>elif Match(r'<STR_LIT>', line):  <EOL><INDENT>function_state.Check(error, filename, linenum)<EOL>function_state.End()<EOL><DEDENT>elif not Match(r'<STR_LIT>', line):<EOL><INDENT>function_state.Count()<EOL><DEDENT>

Reports for long function bodies.

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

    Uses a simplistic algorithm assuming other style guidelines
    (especially spacing) are followed.
    Only checks unindented functions, so class members are unchecked.
    Trivial bodies are unchecked, so constructors with huge initializer lists
    may be missed.
    Blank/comment lines are not counted so as to avoid encouraging the removal
    of vertical space and comments just to get through a lint check.
    NOLINT *on the last line of a function* disables this check.

    Args:
      filename: The name of the current file.
      clean_lines: A CleansedLines instance containing the file.
      linenum: 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.


def CheckComment(line, filename, linenum, next_line_start, error):

commentpos = line.find('<STR_LIT>')<EOL>if commentpos != -<NUM_LIT:1>:<EOL><INDENT>if re.sub(r'<STR_LIT>', '<STR_LIT>', line[<NUM_LIT:0>:commentpos]).count('<STR_LIT:">') % <NUM_LIT:2> == <NUM_LIT:0>:<EOL><INDENT>if (not (Match(r'<STR_LIT>', line) and next_line_start == commentpos) and<EOL>((commentpos >= <NUM_LIT:1> and<EOL>line[commentpos-<NUM_LIT:1>] not in string.whitespace) or<EOL>(commentpos >= <NUM_LIT:2> and<EOL>line[commentpos-<NUM_LIT:2>] not in string.whitespace))):<EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:2>,<EOL>'<STR_LIT>')<EOL><DEDENT>comment = line[commentpos:]<EOL>match = _RE_PATTERN_TODO.match(comment)<EOL>if match:<EOL><INDENT>leading_whitespace = match.group(<NUM_LIT:1>)<EOL>if len(leading_whitespace) > <NUM_LIT:1>:<EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:2>,<EOL>'<STR_LIT>')<EOL><DEDENT>username = match.group(<NUM_LIT:2>)<EOL>if not username:<EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:2>,<EOL>'<STR_LIT>'<EOL>'<STR_LIT>')<EOL><DEDENT>middle_whitespace = match.group(<NUM_LIT:3>)<EOL>if middle_whitespace != '<STR_LIT:U+0020>' and middle_whitespace != '<STR_LIT>':<EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:2>,<EOL>'<STR_LIT>')<EOL><DEDENT><DEDENT>if (Match(r'<STR_LIT>', comment) and<EOL>not Match(r'<STR_LIT>', comment)):<EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:4>,<EOL>'<STR_LIT>')<EOL><DEDENT><DEDENT><DEDENT>

Checks for common mistakes in comments.

    Args:
      line: The line in question.
      filename: The name of the current file.
      linenum: The number of the line to check.
      next_line_start: The first non-whitespace column of the next line.
      error: The function to call with any errors found.


def CheckAccess(filename, clean_lines, linenum, nesting_state, error):

line = clean_lines.elided[linenum]  <EOL>matched = Match((r'<STR_LIT>'<EOL>r'<STR_LIT>'), line)<EOL>if not matched:<EOL><INDENT>return<EOL><DEDENT>if nesting_state.stack and isinstance(nesting_state.stack[-<NUM_LIT:1>], _ClassInfo):<EOL><INDENT>if nesting_state.stack[-<NUM_LIT:1>].access != '<STR_LIT>':<EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:3>,<EOL>'<STR_LIT>' % matched.group(<NUM_LIT:1>))<EOL><DEDENT><DEDENT>else:<EOL><INDENT>pass<EOL><DEDENT>

Checks for improper use of DISALLOW* macros.

    Args:
      filename: The name of the current file.
      clean_lines: A CleansedLines instance containing the file.
      linenum: The number of the line to check.
      nesting_state: A NestingState instance which maintains information about
                     the current stack of nested blocks being parsed.
      error: The function to call with any errors found.


def CheckSpacing(filename, clean_lines, linenum, nesting_state, error):

<EOL>raw = clean_lines.lines_without_raw_strings<EOL>line = raw[linenum]<EOL>if (IsBlankLine(line) and<EOL>not nesting_state.InNamespaceBody() and<EOL>not nesting_state.InExternC()):<EOL><INDENT>elided = clean_lines.elided<EOL>prev_line = elided[linenum - <NUM_LIT:1>]<EOL>prevbrace = prev_line.rfind('<STR_LIT:{>')<EOL>if prevbrace != -<NUM_LIT:1> and prev_line[prevbrace:].find('<STR_LIT:}>') == -<NUM_LIT:1>:<EOL><INDENT>exception = False<EOL>if Match(r'<STR_LIT>', prev_line):  <EOL><INDENT>search_position = linenum-<NUM_LIT:2><EOL>while (search_position >= <NUM_LIT:0><EOL>and Match(r'<STR_LIT>', elided[search_position])):<EOL><INDENT>search_position -= <NUM_LIT:1><EOL><DEDENT>exception = (search_position >= <NUM_LIT:0><EOL>and elided[search_position][:<NUM_LIT:5>] == '<STR_LIT>')<EOL><DEDENT>else:<EOL><INDENT>exception = (Match(r'<STR_LIT>',<EOL>prev_line)<EOL>or Match(r'<STR_LIT>', prev_line))<EOL><DEDENT>if not exception:<EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:2>,<EOL>'<STR_LIT>'<EOL>'<STR_LIT>')<EOL><DEDENT><DEDENT>if linenum + <NUM_LIT:1> < clean_lines.NumLines():<EOL><INDENT>next_line = raw[linenum + <NUM_LIT:1>]<EOL>if (next_line<EOL>and Match(r'<STR_LIT>', next_line)<EOL>and next_line.find('<STR_LIT>') == -<NUM_LIT:1>):<EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:3>,<EOL>'<STR_LIT>'<EOL>'<STR_LIT>')<EOL><DEDENT><DEDENT>matched = Match(r'<STR_LIT>', prev_line)<EOL>if matched:<EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:3>,<EOL>'<STR_LIT>' % matched.group(<NUM_LIT:1>))<EOL><DEDENT><DEDENT>next_line_start = <NUM_LIT:0><EOL>if linenum + <NUM_LIT:1> < clean_lines.NumLines():<EOL><INDENT>next_line = raw[linenum + <NUM_LIT:1>]<EOL>next_line_start = len(next_line) - len(next_line.lstrip())<EOL><DEDENT>CheckComment(line, filename, linenum, next_line_start, error)<EOL>line = clean_lines.elided[linenum]<EOL>if Search(r'<STR_LIT>', line) and not Search(r'<STR_LIT>', line):<EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:5>,<EOL>'<STR_LIT>')<EOL><DEDENT>if (Search(r'<STR_LIT>', line) or<EOL>Search(r'<STR_LIT>', line)):<EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:2>,<EOL>'<STR_LIT>')<EOL><DEDENT>

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 add a blank line
    after public/protected/private, don't have too many blank lines in a row.

    Args:
      filename: The name of the current file.
      clean_lines: A CleansedLines instance containing the file.
      linenum: The number of the line to check.
      nesting_state: A NestingState instance which maintains information about
                     the current stack of nested blocks being parsed.
      error: The function to call with any errors found.


def CheckOperatorSpacing(filename, clean_lines, linenum, error):

line = clean_lines.elided[linenum]<EOL>while True:<EOL><INDENT>match = Match(r'<STR_LIT>', line)<EOL>if match:<EOL><INDENT>line = match.group(<NUM_LIT:1>) + ('<STR_LIT:_>' * len(match.group(<NUM_LIT:2>))) + match.group(<NUM_LIT:3>)<EOL><DEDENT>else:<EOL><INDENT>break<EOL><DEDENT><DEDENT>if ((Search(r'<STR_LIT>', line) or<EOL>Search(r'<STR_LIT>', line))<EOL>and not Search(r'<STR_LIT>', line)<EOL>and not Search(r'<STR_LIT>', line)<EOL>and not Search(r'<STR_LIT>', line)):<EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:4>,<EOL>'<STR_LIT>')<EOL><DEDENT>match = Search(r'<STR_LIT>', line)<EOL>if match:<EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:3>,<EOL>'<STR_LIT>' % match.group(<NUM_LIT:1>))<EOL><DEDENT>elif not Match(r'<STR_LIT>', line):<EOL><INDENT>match = Match(r'<STR_LIT>', line)<EOL>if match:<EOL><INDENT>(_, _, end_pos) = CloseExpression(<EOL>clean_lines, linenum, len(match.group(<NUM_LIT:1>)))<EOL>if end_pos <= -<NUM_LIT:1>:<EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:3>,<EOL>'<STR_LIT>')<EOL><DEDENT><DEDENT>match = Match(r'<STR_LIT>', line)<EOL>if match:<EOL><INDENT>(_, _, start_pos) = ReverseCloseExpression(<EOL>clean_lines, linenum, len(match.group(<NUM_LIT:1>)))<EOL>if start_pos <= -<NUM_LIT:1>:<EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:3>,<EOL>'<STR_LIT>')<EOL><DEDENT><DEDENT><DEDENT>match = Search(r'<STR_LIT>', line)<EOL>if (match and not (match.group(<NUM_LIT:1>).isdigit() and match.group(<NUM_LIT:2>).isdigit()) and<EOL>not (match.group(<NUM_LIT:1>) == '<STR_LIT>' and match.group(<NUM_LIT:2>) == '<STR_LIT:;>')):<EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:3>,<EOL>'<STR_LIT>')<EOL><DEDENT>match = Search(r'<STR_LIT>', line)<EOL>if match:<EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:3>,<EOL>'<STR_LIT>')<EOL><DEDENT>match = Search(r'<STR_LIT>', line)<EOL>if match:<EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:4>,<EOL>'<STR_LIT>' % match.group(<NUM_LIT:1>))<EOL><DEDENT>

Checks for horizontal spacing around operators.

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


def CheckParenthesisSpacing(filename, clean_lines, linenum, error):

line = clean_lines.elided[linenum]<EOL>match = Search(r'<STR_LIT>', line)<EOL>if match:<EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:5>,<EOL>'<STR_LIT>' % match.group(<NUM_LIT:1>))<EOL><DEDENT>match = Search(r'<STR_LIT>'<EOL>r'<STR_LIT>',<EOL>line)<EOL>if match:<EOL><INDENT>if len(match.group(<NUM_LIT:2>)) != len(match.group(<NUM_LIT:4>)):<EOL><INDENT>if not (match.group(<NUM_LIT:3>) == '<STR_LIT:;>' and<EOL>len(match.group(<NUM_LIT:2>)) == <NUM_LIT:1> + len(match.group(<NUM_LIT:4>)) or<EOL>not match.group(<NUM_LIT:2>) and Search(r'<STR_LIT>', line)):<EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:5>,<EOL>'<STR_LIT>' % match.group(<NUM_LIT:1>))<EOL><DEDENT><DEDENT>if len(match.group(<NUM_LIT:2>)) not in [<NUM_LIT:0>, <NUM_LIT:1>]:<EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:5>,<EOL>'<STR_LIT>' %<EOL>match.group(<NUM_LIT:1>))<EOL><DEDENT><DEDENT>

Checks for horizontal spacing around parentheses.

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


def CheckCommaSpacing(filename, clean_lines, linenum, error):

raw = clean_lines.lines_without_raw_strings<EOL>line = clean_lines.elided[linenum]<EOL>if (Search(r'<STR_LIT>', ReplaceAll(r'<STR_LIT>', '<STR_LIT>', line)) and<EOL>Search(r'<STR_LIT>', raw[linenum])):<EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:3>,<EOL>'<STR_LIT>')<EOL><DEDENT>if Search(r'<STR_LIT>', line):<EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:3>,<EOL>'<STR_LIT>')<EOL><DEDENT>

Checks for horizontal spacing near commas and semicolons.

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


def _IsType(clean_lines, nesting_state, expr):

<EOL>last_word = Match(r'<STR_LIT>', expr)<EOL>if last_word:<EOL><INDENT>token = last_word.group(<NUM_LIT:1>)<EOL><DEDENT>else:<EOL><INDENT>token = expr<EOL><DEDENT>if _TYPES.match(token):<EOL><INDENT>return True<EOL><DEDENT>typename_pattern = (r'<STR_LIT>' + re.escape(token) +<EOL>r'<STR_LIT>')<EOL>block_index = len(nesting_state.stack) - <NUM_LIT:1><EOL>while block_index >= <NUM_LIT:0>:<EOL><INDENT>if isinstance(nesting_state.stack[block_index], _NamespaceInfo):<EOL><INDENT>return False<EOL><DEDENT>last_line = nesting_state.stack[block_index].starting_linenum<EOL>next_block_start = <NUM_LIT:0><EOL>if block_index > <NUM_LIT:0>:<EOL><INDENT>next_block_start = nesting_state.stack[block_index - <NUM_LIT:1>].starting_linenum<EOL><DEDENT>first_line = last_line<EOL>while first_line >= next_block_start:<EOL><INDENT>if clean_lines.elided[first_line].find('<STR_LIT>') >= <NUM_LIT:0>:<EOL><INDENT>break<EOL><DEDENT>first_line -= <NUM_LIT:1><EOL><DEDENT>if first_line < next_block_start:<EOL><INDENT>block_index -= <NUM_LIT:1><EOL>continue<EOL><DEDENT>for i in xrange(first_line, last_line + <NUM_LIT:1>, <NUM_LIT:1>):<EOL><INDENT>if Search(typename_pattern, clean_lines.elided[i]):<EOL><INDENT>return True<EOL><DEDENT><DEDENT>block_index -= <NUM_LIT:1><EOL><DEDENT>return False<EOL>

Check if expression looks like a type name, returns true if so.

    Args:
      clean_lines: A CleansedLines instance containing the file.
      nesting_state: A NestingState instance which maintains information about
                     the current stack of nested blocks being parsed.
      expr: The expression to check.
    Returns:
      True, if token looks like a type.


def CheckBracesSpacing(filename, clean_lines, linenum, nesting_state, error):

line = clean_lines.elided[linenum]<EOL>match = Match(r'<STR_LIT>', line)<EOL>if match:<EOL><INDENT>leading_text = match.group(<NUM_LIT:1>)<EOL>(endline, endlinenum, endpos) = CloseExpression(<EOL>clean_lines, linenum, len(match.group(<NUM_LIT:1>)))<EOL>trailing_text = '<STR_LIT>'<EOL>if endpos > -<NUM_LIT:1>:<EOL><INDENT>trailing_text = endline[endpos:]<EOL><DEDENT>for offset in xrange(endlinenum + <NUM_LIT:1>,<EOL>min(endlinenum + <NUM_LIT:3>, clean_lines.NumLines() - <NUM_LIT:1>)):<EOL><INDENT>trailing_text += clean_lines.elided[offset]<EOL><DEDENT>if (not Match(r'<STR_LIT>', trailing_text)<EOL>and not _IsType(clean_lines, nesting_state, leading_text)):<EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:5>,<EOL>'<STR_LIT>')<EOL><DEDENT><DEDENT>if Search(r'<STR_LIT>', line):<EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:5>,<EOL>'<STR_LIT>')<EOL><DEDENT>if Search(r'<STR_LIT>', line):<EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:5>,<EOL>'<STR_LIT>')<EOL><DEDENT>elif Search(r'<STR_LIT>', line):<EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:5>,<EOL>'<STR_LIT>'<EOL>'<STR_LIT>')<EOL><DEDENT>elif (Search(r'<STR_LIT>', line) and<EOL>not Search(r'<STR_LIT>', line)):<EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:5>,<EOL>'<STR_LIT>'<EOL>'<STR_LIT>')<EOL><DEDENT>

Checks for horizontal spacing near commas.

    Args:
      filename: The name of the current file.
      clean_lines: A CleansedLines instance containing the file.
      linenum: The number of the line to check.
      nesting_state: A NestingState instance which maintains information about
                     the current stack of nested blocks being parsed.
      error: The function to call with any errors found.


def IsDecltype(clean_lines, linenum, column):

(text, _, start_col) = ReverseCloseExpression(clean_lines, linenum, column)<EOL>if start_col < <NUM_LIT:0>:<EOL><INDENT>return False<EOL><DEDENT>if Search(r'<STR_LIT>', text[<NUM_LIT:0>:start_col]):<EOL><INDENT>return True<EOL><DEDENT>return False<EOL>

Check if the token ending on (linenum, column) is decltype().

    Args:
      clean_lines: A CleansedLines instance containing the file.
      linenum: the number of the line to check.
      column: end column of the token to check.
    Returns:
      True if this token is decltype() expression, False otherwise.


def CheckSectionSpacing(filename, clean_lines, class_info, linenum, error):

<EOL>if (class_info.last_line - class_info.starting_linenum <= <NUM_LIT> or<EOL>linenum <= class_info.starting_linenum):<EOL><INDENT>return<EOL><DEDENT>matched = Match(r'<STR_LIT>', clean_lines.lines[linenum])<EOL>if matched:<EOL><INDENT>prev_line = clean_lines.lines[linenum - <NUM_LIT:1>]<EOL>if (not IsBlankLine(prev_line) and<EOL>not Search(r'<STR_LIT>', prev_line) and<EOL>not Search(r'<STR_LIT>', prev_line)):<EOL><INDENT>end_class_head = class_info.starting_linenum<EOL>for i in range(class_info.starting_linenum, linenum):<EOL><INDENT>if Search(r'<STR_LIT>', clean_lines.lines[i]):<EOL><INDENT>end_class_head = i<EOL>break<EOL><DEDENT><DEDENT>if end_class_head < linenum - <NUM_LIT:1>:<EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:3>,<EOL>'<STR_LIT>' % matched.group(<NUM_LIT:1>))<EOL><DEDENT><DEDENT><DEDENT>

Checks for additional blank line issues related to sections.

    Currently the only thing checked here is blank line before protected/private.

    Args:
      filename: The name of the current file.
      clean_lines: A CleansedLines instance containing the file.
      class_info: A _ClassInfo objects.
      linenum: The number of the line to check.
      error: The function to call with any errors found.


prevlinenum = linenum - <NUM_LIT:1><EOL>while prevlinenum >= <NUM_LIT:0>:<EOL><INDENT>prevline = clean_lines.elided[prevlinenum]<EOL>if not IsBlankLine(prevline):     <EOL><INDENT>return (prevline, prevlinenum)<EOL><DEDENT>prevlinenum -= <NUM_LIT:1><EOL><DEDENT>return ('<STR_LIT>', -<NUM_LIT:1>)<EOL>

Return the most recent non-blank line and its line number.

    Args:
      clean_lines: A CleansedLines instance containing the file contents.
      linenum: 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.


def CheckBraces(filename, clean_lines, linenum, error):

line = clean_lines.elided[linenum]        <EOL>if Match(r'<STR_LIT>', line):<EOL><INDENT>prevline = GetPreviousNonBlankLine(clean_lines, linenum)[<NUM_LIT:0>]<EOL>if (not Search(r'<STR_LIT>', prevline) and<EOL>not Match(r'<STR_LIT>', prevline) and<EOL>not (GetLineWidth(prevline) > _line_length - <NUM_LIT:2> and '<STR_LIT>' in prevline)):<EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:4>,<EOL>'<STR_LIT>')<EOL><DEDENT><DEDENT>if Match(r'<STR_LIT>', line):<EOL><INDENT>prevline = GetPreviousNonBlankLine(clean_lines, linenum)[<NUM_LIT:0>]<EOL>if Match(r'<STR_LIT>', prevline):<EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:4>,<EOL>'<STR_LIT>')<EOL><DEDENT><DEDENT>if Search(r'<STR_LIT>', line):       <EOL><INDENT>brace_on_left = bool(Search(r'<STR_LIT>', line))<EOL>pos = line.find('<STR_LIT>')<EOL>pos = line.find('<STR_LIT:(>', pos)<EOL>if pos > <NUM_LIT:0>:<EOL><INDENT>(endline, _, endpos) = CloseExpression(clean_lines, linenum, pos)<EOL>brace_on_right = endline[endpos:].find('<STR_LIT:{>') != -<NUM_LIT:1><EOL>if brace_on_left != brace_on_right:    <EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:5>,<EOL>'<STR_LIT>')<EOL><DEDENT><DEDENT><DEDENT>elif Search(r'<STR_LIT>', line) or Match(r'<STR_LIT>', line):<EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:5>,<EOL>'<STR_LIT>')<EOL><DEDENT>if Search(r'<STR_LIT>', line) and not Search(r'<STR_LIT>', line):<EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:4>,<EOL>'<STR_LIT>')<EOL><DEDENT>if Match(r'<STR_LIT>', line):<EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:4>,<EOL>'<STR_LIT>')<EOL><DEDENT>if_else_match = Search(r'<STR_LIT>', line)<EOL>if if_else_match and not Match(r'<STR_LIT>', line):<EOL><INDENT>if_indent = GetIndentLevel(line)<EOL>endline, endlinenum, endpos = line, linenum, if_else_match.end()<EOL>if_match = Search(r'<STR_LIT>', line)<EOL>if if_match:<EOL><INDENT>pos = if_match.end() - <NUM_LIT:1><EOL>(endline, endlinenum, endpos) = CloseExpression(clean_lines, linenum, pos)<EOL><DEDENT>if (not Match(r'<STR_LIT>', endline[endpos:])<EOL>and not (Match(r'<STR_LIT>', endline[endpos:])<EOL>and endlinenum < (len(clean_lines.elided) - <NUM_LIT:1>)<EOL>and Match(r'<STR_LIT>', clean_lines.elided[endlinenum + <NUM_LIT:1>]))):<EOL><INDENT>while (endlinenum < len(clean_lines.elided)<EOL>and '<STR_LIT:;>' not in clean_lines.elided[endlinenum][endpos:]):<EOL><INDENT>endlinenum += <NUM_LIT:1><EOL>endpos = <NUM_LIT:0><EOL><DEDENT>if endlinenum < len(clean_lines.elided):<EOL><INDENT>endline = clean_lines.elided[endlinenum]<EOL>endpos = endline.find('<STR_LIT:;>')<EOL>if not Match(r'<STR_LIT>', endline[endpos:]):<EOL><INDENT>if not Match(r'<STR_LIT>',<EOL>endline):<EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:4>,<EOL>'<STR_LIT>')<EOL><DEDENT><DEDENT>elif endlinenum < len(clean_lines.elided) - <NUM_LIT:1>:<EOL><INDENT>next_line = clean_lines.elided[endlinenum + <NUM_LIT:1>]<EOL>next_indent = GetIndentLevel(next_line)<EOL>if (if_match and Match(r'<STR_LIT>', next_line)<EOL>and next_indent != if_indent):<EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:4>,<EOL>'<STR_LIT>'<EOL>'<STR_LIT>')<EOL><DEDENT>elif next_indent > if_indent:<EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:4>,<EOL>'<STR_LIT>')<EOL><DEDENT><DEDENT><DEDENT><DEDENT><DEDENT>

Looks for misplaced braces (e.g. at the end of line).

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


def CheckTrailingSemicolon(filename, clean_lines, linenum, error):

line = clean_lines.elided[linenum]<EOL>match = Match(r'<STR_LIT>', line)<EOL>if match:<EOL><INDENT>closing_brace_pos = match.group(<NUM_LIT:1>).rfind('<STR_LIT:)>')<EOL>opening_parenthesis = ReverseCloseExpression(<EOL>clean_lines, linenum, closing_brace_pos)<EOL>if opening_parenthesis[<NUM_LIT:2>] > -<NUM_LIT:1>:<EOL><INDENT>line_prefix = opening_parenthesis[<NUM_LIT:0>][<NUM_LIT:0>:opening_parenthesis[<NUM_LIT:2>]]<EOL>macro = Search(r'<STR_LIT>', line_prefix)<EOL>func = Match(r'<STR_LIT>', line_prefix)<EOL>if ((macro and<EOL>macro.group(<NUM_LIT:1>) not in (<EOL>'<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>',<EOL>'<STR_LIT>', '<STR_LIT>',<EOL>'<STR_LIT>', '<STR_LIT>')) or<EOL>(func and not Search(r'<STR_LIT>', func.group(<NUM_LIT:1>))) or<EOL>Search(r'<STR_LIT>', line_prefix) or<EOL>Search(r'<STR_LIT>', line_prefix) or<EOL>Search(r'<STR_LIT>', line_prefix)):<EOL><INDENT>match = None<EOL><DEDENT><DEDENT>if (match and<EOL>opening_parenthesis[<NUM_LIT:1>] > <NUM_LIT:1> and<EOL>Search(r'<STR_LIT>', clean_lines.elided[opening_parenthesis[<NUM_LIT:1>] - <NUM_LIT:1>])):<EOL><INDENT>match = None<EOL><DEDENT><DEDENT>else:<EOL><INDENT>match = Match(r'<STR_LIT>', line)<EOL>if not match:<EOL><INDENT>prevline = GetPreviousNonBlankLine(clean_lines, linenum)[<NUM_LIT:0>]<EOL>if prevline and Search(r'<STR_LIT>', prevline):<EOL><INDENT>match = Match(r'<STR_LIT>', line)<EOL><DEDENT><DEDENT><DEDENT>if match:<EOL><INDENT>(endline, endlinenum, endpos) = CloseExpression(<EOL>clean_lines, linenum, len(match.group(<NUM_LIT:1>)))<EOL>if endpos > -<NUM_LIT:1> and Match(r'<STR_LIT>', endline[endpos:]):<EOL><INDENT>raw_lines = clean_lines.raw_lines<EOL>ParseNolintSuppressions(filename, raw_lines[endlinenum-<NUM_LIT:1>], endlinenum-<NUM_LIT:1>,<EOL>error)<EOL>ParseNolintSuppressions(filename, raw_lines[endlinenum], endlinenum,<EOL>error)<EOL>error(filename, endlinenum, '<STR_LIT>', <NUM_LIT:4>,<EOL>"<STR_LIT>")<EOL><DEDENT><DEDENT>

Looks for redundant trailing semicolon.

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


def CheckEmptyBlockBody(filename, clean_lines, linenum, error):

<EOL>line = clean_lines.elided[linenum]<EOL>matched = Match(r'<STR_LIT>', line)<EOL>if matched:<EOL><INDENT>(end_line, end_linenum, end_pos) = CloseExpression(<EOL>clean_lines, linenum, line.find('<STR_LIT:(>'))<EOL>if end_pos >= <NUM_LIT:0> and Match(r'<STR_LIT:;>', end_line[end_pos:]):<EOL><INDENT>if matched.group(<NUM_LIT:1>) == '<STR_LIT>':<EOL><INDENT>error(filename, end_linenum, '<STR_LIT>', <NUM_LIT:5>,<EOL>'<STR_LIT>')<EOL><DEDENT>else:<EOL><INDENT>error(filename, end_linenum, '<STR_LIT>', <NUM_LIT:5>,<EOL>'<STR_LIT>')<EOL><DEDENT><DEDENT>if end_pos >= <NUM_LIT:0> and matched.group(<NUM_LIT:1>) == '<STR_LIT>':<EOL><INDENT>opening_linenum = end_linenum<EOL>opening_line_fragment = end_line[end_pos:]<EOL>while not Search(r'<STR_LIT>', opening_line_fragment):<EOL><INDENT>if Search(r'<STR_LIT>', opening_line_fragment):<EOL><INDENT>return<EOL><DEDENT>opening_linenum += <NUM_LIT:1><EOL>if opening_linenum == len(clean_lines.elided):<EOL><INDENT>return<EOL><DEDENT>opening_line_fragment = clean_lines.elided[opening_linenum]<EOL><DEDENT>opening_line = clean_lines.elided[opening_linenum]<EOL>opening_pos = opening_line_fragment.find('<STR_LIT:{>')<EOL>if opening_linenum == end_linenum:<EOL><INDENT>opening_pos += end_pos<EOL><DEDENT>(closing_line, closing_linenum, closing_pos) = CloseExpression(<EOL>clean_lines, opening_linenum, opening_pos)<EOL>if closing_pos < <NUM_LIT:0>:<EOL><INDENT>return<EOL><DEDENT>if (clean_lines.raw_lines[opening_linenum] !=<EOL>CleanseComments(clean_lines.raw_lines[opening_linenum])):<EOL><INDENT>return<EOL><DEDENT>if closing_linenum > opening_linenum:<EOL><INDENT>bodylist = list(opening_line[opening_pos+<NUM_LIT:1>:])<EOL>bodylist.extend(clean_lines.raw_lines[opening_linenum+<NUM_LIT:1>:closing_linenum])<EOL>bodylist.append(clean_lines.elided[closing_linenum][:closing_pos-<NUM_LIT:1>])<EOL>body = '<STR_LIT:\n>'.join(bodylist)<EOL><DEDENT>else:<EOL><INDENT>body = opening_line[opening_pos+<NUM_LIT:1>:closing_pos-<NUM_LIT:1>]<EOL><DEDENT>if not _EMPTY_CONDITIONAL_BODY_PATTERN.search(body):<EOL><INDENT>return<EOL><DEDENT>current_linenum = closing_linenum<EOL>current_line_fragment = closing_line[closing_pos:]<EOL>while Search(r'<STR_LIT>', current_line_fragment):<EOL><INDENT>if Search(r'<STR_LIT>', current_line_fragment):<EOL><INDENT>return<EOL><DEDENT>current_linenum += <NUM_LIT:1><EOL>if current_linenum == len(clean_lines.elided):<EOL><INDENT>break<EOL><DEDENT>current_line_fragment = clean_lines.elided[current_linenum]<EOL><DEDENT>error(filename, end_linenum, '<STR_LIT>', <NUM_LIT:4>,<EOL>('<STR_LIT>'))<EOL><DEDENT><DEDENT>

Look for empty loop/conditional body with only a single semicolon.

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


for macro in _CHECK_MACROS:<EOL><INDENT>i = line.find(macro)<EOL>if i >= <NUM_LIT:0>:<EOL><INDENT>matched = Match(r'<STR_LIT>' + macro + r'<STR_LIT>', line)<EOL>if not matched:<EOL><INDENT>continue<EOL><DEDENT>return (macro, len(matched.group(<NUM_LIT:1>)))<EOL><DEDENT><DEDENT>return (None, -<NUM_LIT:1>)<EOL>

Find a replaceable CHECK-like macro.

    Args:
      line: line to search on.
    Returns:
      (macro name, start position), or (None, -1) if no replaceable
      macro is found.


def CheckCheck(filename, clean_lines, linenum, error):

<EOL>lines = clean_lines.elided<EOL>(check_macro, start_pos) = FindCheckMacro(lines[linenum])<EOL>if not check_macro:<EOL><INDENT>return<EOL><DEDENT>(last_line, end_line, end_pos) = CloseExpression(<EOL>clean_lines, linenum, start_pos)<EOL>if end_pos < <NUM_LIT:0>:<EOL><INDENT>return<EOL><DEDENT>if not Match(r'<STR_LIT>', last_line[end_pos:]):<EOL><INDENT>return<EOL><DEDENT>if linenum == end_line:<EOL><INDENT>expression = lines[linenum][start_pos + <NUM_LIT:1>:end_pos - <NUM_LIT:1>]<EOL><DEDENT>else:<EOL><INDENT>expression = lines[linenum][start_pos + <NUM_LIT:1>:]<EOL>for i in xrange(linenum + <NUM_LIT:1>, end_line):<EOL><INDENT>expression += lines[i]<EOL><DEDENT>expression += last_line[<NUM_LIT:0>:end_pos - <NUM_LIT:1>]<EOL><DEDENT>lhs = '<STR_LIT>'<EOL>rhs = '<STR_LIT>'<EOL>operator = None<EOL>while expression:<EOL><INDENT>matched = Match(r'<STR_LIT>'<EOL>r'<STR_LIT>', expression)<EOL>if matched:<EOL><INDENT>token = matched.group(<NUM_LIT:1>)<EOL>if token == '<STR_LIT:(>':<EOL><INDENT>expression = matched.group(<NUM_LIT:2>)<EOL>(end, _) = FindEndOfExpressionInLine(expression, <NUM_LIT:0>, ['<STR_LIT:(>'])<EOL>if end < <NUM_LIT:0>:<EOL><INDENT>return  <EOL><DEDENT>lhs += '<STR_LIT:(>' + expression[<NUM_LIT:0>:end]<EOL>expression = expression[end:]<EOL><DEDENT>elif token in ('<STR_LIT>', '<STR_LIT>'):<EOL><INDENT>return<EOL><DEDENT>elif token in ('<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>'):<EOL><INDENT>lhs += token<EOL>expression = matched.group(<NUM_LIT:2>)<EOL><DEDENT>else:<EOL><INDENT>operator = token<EOL>rhs = matched.group(<NUM_LIT:2>)<EOL>break<EOL><DEDENT><DEDENT>else:<EOL><INDENT>matched = Match(r'<STR_LIT>', expression)<EOL>if not matched:<EOL><INDENT>matched = Match(r'<STR_LIT>', expression)<EOL>if not matched:<EOL><INDENT>break<EOL><DEDENT><DEDENT>lhs += matched.group(<NUM_LIT:1>)<EOL>expression = matched.group(<NUM_LIT:2>)<EOL><DEDENT><DEDENT>if not (lhs and operator and rhs):<EOL><INDENT>return<EOL><DEDENT>if rhs.find('<STR_LIT>') > -<NUM_LIT:1> or rhs.find('<STR_LIT>') > -<NUM_LIT:1>:<EOL><INDENT>return<EOL><DEDENT>lhs = lhs.strip()<EOL>rhs = rhs.strip()<EOL>match_constant = r'<STR_LIT>'<EOL>if Match(match_constant, lhs) or Match(match_constant, rhs):<EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:2>,<EOL>'<STR_LIT>' % (<EOL>_CHECK_REPLACEMENT[check_macro][operator],<EOL>check_macro, operator))<EOL><DEDENT>

Checks the use of CHECK and EXPECT macros.

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


def CheckAltTokens(filename, clean_lines, linenum, error):

line = clean_lines.elided[linenum]<EOL>if Match(r'<STR_LIT>', line):<EOL><INDENT>return<EOL><DEDENT>if line.find('<STR_LIT>') >= <NUM_LIT:0> or line.find('<STR_LIT>') >= <NUM_LIT:0>:<EOL><INDENT>return<EOL><DEDENT>for match in _ALT_TOKEN_REPLACEMENT_PATTERN.finditer(line):<EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:2>,<EOL>'<STR_LIT>' % (<EOL>_ALT_TOKEN_REPLACEMENT[match.group(<NUM_LIT:1>)], match.group(<NUM_LIT:1>)))<EOL><DEDENT>

Check alternative keywords being used in boolean expressions.

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


if isinstance(line, unicode):<EOL><INDENT>width = <NUM_LIT:0><EOL>for uc in unicodedata.normalize('<STR_LIT>', line):<EOL><INDENT>if unicodedata.east_asian_width(uc) in ('<STR_LIT>', '<STR_LIT:F>'):<EOL><INDENT>width += <NUM_LIT:2><EOL><DEDENT>elif not unicodedata.combining(uc):<EOL><INDENT>width += <NUM_LIT:1><EOL><DEDENT><DEDENT>return width<EOL><DEDENT>else:<EOL><INDENT>return len(line)<EOL><DEDENT>

Determines the width of the line in column positions.

    Args:
      line: A string, which may be a Unicode string.

    Returns:
      The width of the line in column positions, accounting for Unicode
      combining characters and wide characters.


def CheckStyle(filename, clean_lines, linenum, file_extension, nesting_state,<EOL>error):

<EOL>raw_lines = clean_lines.lines_without_raw_strings<EOL>line = raw_lines[linenum]<EOL>prev = raw_lines[linenum - <NUM_LIT:1>] if linenum > <NUM_LIT:0> else '<STR_LIT>'<EOL>if line.find('<STR_LIT:\t>') != -<NUM_LIT:1>:<EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:1>,<EOL>'<STR_LIT>')<EOL><DEDENT>scope_or_label_pattern = r'<STR_LIT>'<EOL>classinfo = nesting_state.InnermostClass()<EOL>initial_spaces = <NUM_LIT:0><EOL>cleansed_line = clean_lines.elided[linenum]<EOL>while initial_spaces < len(line) and line[initial_spaces] == '<STR_LIT:U+0020>':<EOL><INDENT>initial_spaces += <NUM_LIT:1><EOL><DEDENT>if (not Search(r'<STR_LIT>', prev) and<EOL>(initial_spaces == <NUM_LIT:1> or initial_spaces == <NUM_LIT:3>) and<EOL>not Match(scope_or_label_pattern, cleansed_line) and<EOL>not (clean_lines.raw_lines[linenum] != line and<EOL>Match(r'<STR_LIT>', line))):<EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:3>,<EOL>'<STR_LIT>'<EOL>'<STR_LIT>')<EOL><DEDENT>if line and line[-<NUM_LIT:1>].isspace():<EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:4>,<EOL>'<STR_LIT>')<EOL><DEDENT>is_header_guard = False<EOL>if file_extension in GetHeaderExtensions():<EOL><INDENT>cppvar = GetHeaderGuardCPPVariable(filename)<EOL>if (line.startswith('<STR_LIT>' % cppvar) or<EOL>line.startswith('<STR_LIT>' % cppvar) or<EOL>line.startswith('<STR_LIT>' % cppvar)):<EOL><INDENT>is_header_guard = True<EOL><DEDENT><DEDENT>if (not line.startswith('<STR_LIT>') and not is_header_guard and<EOL>not Match(r'<STR_LIT>', line) and<EOL>not Match(r'<STR_LIT>', line) and<EOL>not Match(r'<STR_LIT>', line) and<EOL>not Match(r'<STR_LIT>', line)):<EOL><INDENT>line_width = GetLineWidth(line)<EOL>if line_width > _line_length:<EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:2>,<EOL>'<STR_LIT>' % _line_length)<EOL><DEDENT><DEDENT>if (cleansed_line.count('<STR_LIT:;>') > <NUM_LIT:1> and<EOL>not Match(r'<STR_LIT>',<EOL>line) and<EOL>cleansed_line.find('<STR_LIT>') == -<NUM_LIT:1> and<EOL>(GetPreviousNonBlankLine(clean_lines, linenum)[<NUM_LIT:0>].find('<STR_LIT>') == -<NUM_LIT:1> or<EOL>GetPreviousNonBlankLine(clean_lines, linenum)[<NUM_LIT:0>].find('<STR_LIT:;>') != -<NUM_LIT:1>) and<EOL>not ((cleansed_line.find('<STR_LIT>') != -<NUM_LIT:1> or<EOL>cleansed_line.find('<STR_LIT>') != -<NUM_LIT:1>) and<EOL>cleansed_line.find('<STR_LIT>') != -<NUM_LIT:1>)):<EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:0>,<EOL>'<STR_LIT>')<EOL><DEDENT>CheckBraces(filename, clean_lines, linenum, error)<EOL>CheckTrailingSemicolon(filename, clean_lines, linenum, error)<EOL>CheckEmptyBlockBody(filename, clean_lines, linenum, error)<EOL>CheckAccess(filename, clean_lines, linenum, nesting_state, error)<EOL>CheckSpacing(filename, clean_lines, linenum, nesting_state, error)<EOL>CheckOperatorSpacing(filename, clean_lines, linenum, error)<EOL>CheckParenthesisSpacing(filename, clean_lines, linenum, error)<EOL>CheckCommaSpacing(filename, clean_lines, linenum, error)<EOL>CheckBracesSpacing(filename, clean_lines, linenum, nesting_state, error)<EOL>CheckSpacingForFunctionCall(filename, clean_lines, linenum, error)<EOL>CheckCheck(filename, clean_lines, linenum, error)<EOL>CheckAltTokens(filename, clean_lines, linenum, error)<EOL>classinfo = nesting_state.InnermostClass()<EOL>if classinfo:<EOL><INDENT>CheckSectionSpacing(filename, clean_lines, classinfo, linenum, error)<EOL><DEDENT>

Checks rules from the 'C++ style rules' section of cppguide.html.

    Most of these rules are hard to test (naming, comment style), but we
    do what we can.  In particular we check for 2-space indents, line lengths,
    tab usage, spaces inside code, etc.

    Args:
      filename: The name of the current file.
      clean_lines: A CleansedLines instance containing the file.
      linenum: The number of the line to check.
      file_extension: The extension (without the dot) of the filename.
      nesting_state: A NestingState instance which maintains information about
                     the current stack of nested blocks being parsed.
      error: The function to call with any errors found.


for suffix in itertools.chain(<EOL>('<STR_LIT>' % (test_suffix.lstrip('<STR_LIT:_>'), ext)<EOL>for test_suffix, ext in itertools.product(_test_suffixes, GetNonHeaderExtensions())),<EOL>('<STR_LIT>' % (suffix, ext)<EOL>for suffix, ext in itertools.product(['<STR_LIT>', '<STR_LIT>', '<STR_LIT>'], GetHeaderExtensions()))):<EOL><INDENT>if (filename.endswith(suffix) and len(filename) > len(suffix) and<EOL>filename[-len(suffix) - <NUM_LIT:1>] in ('<STR_LIT:->', '<STR_LIT:_>')):<EOL><INDENT>return filename[:-len(suffix) - <NUM_LIT:1>]<EOL><DEDENT><DEDENT>return os.path.splitext(filename)[<NUM_LIT:0>]<EOL>

Drops common suffixes like _test.cc or -inl.h from filename.

    For example:
      >>> _DropCommonSuffixes('foo/foo-inl.h')
      'foo/foo'
      >>> _DropCommonSuffixes('foo/bar/foo.cc')
      'foo/bar/foo'
      >>> _DropCommonSuffixes('foo/foo_internal.h')
      'foo/foo'
      >>> _DropCommonSuffixes('foo/foo_unusualinternal.h')
      'foo/foo_unusualinternal'

    Args:
      filename: The input filename.

    Returns:
      The filename with the common suffix removed.


def _ClassifyInclude(fileinfo, include, is_system):

<EOL>is_cpp_h = include in _CPP_HEADERS<EOL>if is_system and os.path.splitext(include)[<NUM_LIT:1>] in ['<STR_LIT>', '<STR_LIT>', '<STR_LIT>']:<EOL><INDENT>is_system = False<EOL><DEDENT>if is_system:<EOL><INDENT>if is_cpp_h:<EOL><INDENT>return _CPP_SYS_HEADER<EOL><DEDENT>else:<EOL><INDENT>return _C_SYS_HEADER<EOL><DEDENT><DEDENT>target_dir, target_base = (<EOL>os.path.split(_DropCommonSuffixes(fileinfo.RepositoryName())))<EOL>include_dir, include_base = os.path.split(_DropCommonSuffixes(include))<EOL>target_dir_pub = os.path.normpath(target_dir + '<STR_LIT>')<EOL>target_dir_pub = target_dir_pub.replace('<STR_LIT:\\>', '<STR_LIT:/>')<EOL>if target_base == include_base and (<EOL>include_dir == target_dir or<EOL>include_dir == target_dir_pub):<EOL><INDENT>return _LIKELY_MY_HEADER<EOL><DEDENT>target_first_component = _RE_FIRST_COMPONENT.match(target_base)<EOL>include_first_component = _RE_FIRST_COMPONENT.match(include_base)<EOL>if (target_first_component and include_first_component and<EOL>target_first_component.group(<NUM_LIT:0>) ==<EOL>include_first_component.group(<NUM_LIT:0>)):<EOL><INDENT>return _POSSIBLE_MY_HEADER<EOL><DEDENT>return _OTHER_HEADER<EOL>

Figures out what kind of header 'include' is.

    Args:
      fileinfo: The current file cpplint is running over. A FileInfo instance.
      include: The path to a #included file.
      is_system: True if the #include used <> rather than "".

    Returns:
      One of the _XXX_HEADER constants.

    For example:
      >>> _ClassifyInclude(FileInfo('foo/foo.cc'), 'stdio.h', True)
      _C_SYS_HEADER
      >>> _ClassifyInclude(FileInfo('foo/foo.cc'), 'string', True)
      _CPP_SYS_HEADER
      >>> _ClassifyInclude(FileInfo('foo/foo.cc'), 'foo/foo.h', False)
      _LIKELY_MY_HEADER
      >>> _ClassifyInclude(FileInfo('foo/foo_unknown_extension.cc'),
      ...                  'bar/foo_other_ext.h', False)
      _POSSIBLE_MY_HEADER
      >>> _ClassifyInclude(FileInfo('foo/foo.cc'), 'foo/bar.h', False)
      _OTHER_HEADER


def CheckIncludeLine(filename, clean_lines, linenum, include_state, error):

fileinfo = FileInfo(filename)<EOL>line = clean_lines.lines[linenum]<EOL>match = Match(r'<STR_LIT>', line)<EOL>if match and not _THIRD_PARTY_HEADERS_PATTERN.match(match.group(<NUM_LIT:1>)):<EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:4>,<EOL>'<STR_LIT>')<EOL><DEDENT>match = _RE_PATTERN_INCLUDE.search(line)<EOL>if match:<EOL><INDENT>include = match.group(<NUM_LIT:2>)<EOL>is_system = (match.group(<NUM_LIT:1>) == '<STR_LIT:<>')<EOL>duplicate_line = include_state.FindHeader(include)<EOL>if duplicate_line >= <NUM_LIT:0>:<EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:4>,<EOL>'<STR_LIT>' %<EOL>(include, filename, duplicate_line))<EOL>return<EOL><DEDENT>for extension in GetNonHeaderExtensions():<EOL><INDENT>if (include.endswith('<STR_LIT:.>' + extension) and<EOL>os.path.dirname(fileinfo.RepositoryName()) != os.path.dirname(include)):<EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:4>,<EOL>'<STR_LIT>' + extension + '<STR_LIT>')<EOL>return<EOL><DEDENT><DEDENT>if not _THIRD_PARTY_HEADERS_PATTERN.match(include):<EOL><INDENT>include_state.include_list[-<NUM_LIT:1>].append((include, linenum))<EOL>error_message = include_state.CheckNextIncludeOrder(<EOL>_ClassifyInclude(fileinfo, include, is_system))<EOL>if error_message:<EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:4>,<EOL>'<STR_LIT>' %<EOL>(error_message, fileinfo.BaseName()))<EOL><DEDENT>canonical_include = include_state.CanonicalizeAlphabeticalOrder(include)<EOL>if not include_state.IsInAlphabeticalOrder(<EOL>clean_lines, linenum, canonical_include):<EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:4>,<EOL>'<STR_LIT>' % include)<EOL><DEDENT>include_state.SetLastHeader(canonical_include)<EOL><DEDENT><DEDENT>

Check rules that are applicable to #include lines.

    Strings on #include lines are NOT removed from elided line, to make
    certain tasks easier. However, to prevent false positives, checks
    applicable to #include lines in CheckLanguage must be put here.

    Args:
      filename: The name of the current file.
      clean_lines: A CleansedLines instance containing the file.
      linenum: The number of the line to check.
      include_state: An _IncludeState instance in which the headers are inserted.
      error: The function to call with any errors found.


<EOL>matching_punctuation = {'<STR_LIT:(>': '<STR_LIT:)>', '<STR_LIT:{>': '<STR_LIT:}>', '<STR_LIT:[>': '<STR_LIT:]>'}<EOL>closing_punctuation = set(itervalues(matching_punctuation))<EOL>match = re.search(start_pattern, text, re.M)<EOL>if not match:  <EOL><INDENT>return None<EOL><DEDENT>start_position = match.end(<NUM_LIT:0>)<EOL>assert start_position > <NUM_LIT:0>, (<EOL>'<STR_LIT>')<EOL>assert text[start_position - <NUM_LIT:1>] in matching_punctuation, (<EOL>'<STR_LIT>')<EOL>punctuation_stack = [matching_punctuation[text[start_position - <NUM_LIT:1>]]]<EOL>position = start_position<EOL>while punctuation_stack and position < len(text):<EOL><INDENT>if text[position] == punctuation_stack[-<NUM_LIT:1>]:<EOL><INDENT>punctuation_stack.pop()<EOL><DEDENT>elif text[position] in closing_punctuation:<EOL><INDENT>return None<EOL><DEDENT>elif text[position] in matching_punctuation:<EOL><INDENT>punctuation_stack.append(matching_punctuation[text[position]])<EOL><DEDENT>position += <NUM_LIT:1><EOL><DEDENT>if punctuation_stack:<EOL><INDENT>return None<EOL><DEDENT>return text[start_position:position - <NUM_LIT:1>]<EOL>

r"""Retrieves all the text between matching open and close parentheses.

    Given a string of lines and a regular expression string, retrieve all the text
    following the expression and between opening punctuation symbols like
    (, [, or {, and the matching close-punctuation symbol. This properly nested
    occurrences of the punctuations, so for the text like
      printf(a(), b(c()));
    a call to _GetTextInside(text, r'printf\(') will return 'a(), b(c())'.
    start_pattern must match string having an open punctuation symbol at the end.

    Args:
      text: The lines to extract text. Its comments and strings must be elided.
             It can be single line and can span multiple lines.
      start_pattern: The regexp string indicating where to start extracting
                     the text.
    Returns:
      The extracted text.
      None if either the opening string or ending punctuation could not be found.


def CheckLanguage(filename, clean_lines, linenum, file_extension,<EOL>include_state, nesting_state, error):

<EOL>line = clean_lines.elided[linenum]<EOL>if not line:<EOL><INDENT>return<EOL><DEDENT>match = _RE_PATTERN_INCLUDE.search(line)<EOL>if match:<EOL><INDENT>CheckIncludeLine(filename, clean_lines, linenum, include_state, error)<EOL>return<EOL><DEDENT>match = Match(r'<STR_LIT>', line)<EOL>if match:<EOL><INDENT>include_state.ResetSection(match.group(<NUM_LIT:1>))<EOL><DEDENT>CheckCasts(filename, clean_lines, linenum, error)<EOL>CheckGlobalStatic(filename, clean_lines, linenum, error)<EOL>CheckPrintf(filename, clean_lines, linenum, error)<EOL>if file_extension in GetHeaderExtensions():<EOL><INDENT>pass<EOL><DEDENT>if Search(r'<STR_LIT>', line):<EOL><INDENT>if not Search(r'<STR_LIT>', line):<EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:4>,<EOL>'<STR_LIT>')<EOL><DEDENT><DEDENT>else:<EOL><INDENT>match = Search(r'<STR_LIT>', line)<EOL>if match:<EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:4>,<EOL>'<STR_LIT>' % match.group(<NUM_LIT:1>))<EOL><DEDENT><DEDENT>if Search(r'<STR_LIT>', line):<EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:4>,<EOL>'<STR_LIT>')<EOL><DEDENT>if Search(r'<STR_LIT>', line):<EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:4>,<EOL>'<STR_LIT>')<EOL><DEDENT>printf_args = _GetTextInside(line, r'<STR_LIT>')<EOL>if printf_args:<EOL><INDENT>match = Match(r'<STR_LIT>', printf_args)<EOL>if match and match.group(<NUM_LIT:1>) != '<STR_LIT>':<EOL><INDENT>function_name = re.search(r'<STR_LIT>',<EOL>line, re.I).group(<NUM_LIT:1>)<EOL>error(filename, linenum, '<STR_LIT>', <NUM_LIT:4>,<EOL>'<STR_LIT>'<EOL>% (function_name, match.group(<NUM_LIT:1>)))<EOL><DEDENT><DEDENT>match = Search(r'<STR_LIT>', line)<EOL>if match and not Match(r"<STR_LIT>", match.group(<NUM_LIT:2>)):<EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:4>,<EOL>'<STR_LIT>'<EOL>% (match.group(<NUM_LIT:1>), match.group(<NUM_LIT:2>)))<EOL><DEDENT>if Search(r'<STR_LIT>', line):<EOL><INDENT>if Search(r'<STR_LIT>', line):<EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:5>,<EOL>'<STR_LIT>'<EOL>'<STR_LIT>')<EOL><DEDENT>else:<EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:5>,<EOL>'<STR_LIT>'<EOL>'<STR_LIT>')<EOL><DEDENT><DEDENT>match = Match(r'<STR_LIT>', line)<EOL>if (match and match.group(<NUM_LIT:2>) != '<STR_LIT>' and match.group(<NUM_LIT:2>) != '<STR_LIT>' and<EOL>match.group(<NUM_LIT:3>).find('<STR_LIT:]>') == -<NUM_LIT:1>):<EOL><INDENT>tokens = re.split(r'<STR_LIT>', match.group(<NUM_LIT:3>))<EOL>is_const = True<EOL>skip_next = False<EOL>for tok in tokens:<EOL><INDENT>if skip_next:<EOL><INDENT>skip_next = False<EOL>continue<EOL><DEDENT>if Search(r'<STR_LIT>', tok): continue<EOL>if Search(r'<STR_LIT>', tok): continue<EOL>tok = tok.lstrip('<STR_LIT:(>')<EOL>tok = tok.rstrip('<STR_LIT:)>')<EOL>if not tok: continue<EOL>if Match(r'<STR_LIT>', tok): continue<EOL>if Match(r'<STR_LIT>', tok): continue<EOL>if Match(r'<STR_LIT>', tok): continue<EOL>if Match(r'<STR_LIT>', tok): continue<EOL>if Match(r'<STR_LIT>', tok): continue<EOL>if tok.startswith('<STR_LIT>'):<EOL><INDENT>skip_next = True<EOL>continue<EOL><DEDENT>is_const = False<EOL>break<EOL><DEDENT>if not is_const:<EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:1>,<EOL>'<STR_LIT>'<EOL>"<STR_LIT>")<EOL><DEDENT><DEDENT>if (file_extension in GetHeaderExtensions()<EOL>and Search(r'<STR_LIT>', line)<EOL>and line[-<NUM_LIT:1>] != '<STR_LIT:\\>'):<EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:4>,<EOL>'<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>')<EOL><DEDENT>

Checks rules from the 'C++ language rules' section of cppguide.html.

    Some of these rules are hard to test (function overloading, using
    uint32 inappropriately), but we do the best we can.

    Args:
      filename: The name of the current file.
      clean_lines: A CleansedLines instance containing the file.
      linenum: The number of the line to check.
      file_extension: The extension (without the dot) of the filename.
      include_state: An _IncludeState instance in which the headers are inserted.
      nesting_state: A NestingState instance which maintains information about
                     the current stack of nested blocks being parsed.
      error: The function to call with any errors found.


def CheckGlobalStatic(filename, clean_lines, linenum, error):

line = clean_lines.elided[linenum]<EOL>if linenum + <NUM_LIT:1> < clean_lines.NumLines() and not Search(r'<STR_LIT>', line):<EOL><INDENT>line += clean_lines.elided[linenum + <NUM_LIT:1>].strip()<EOL><DEDENT>match = Match(<EOL>r'<STR_LIT>'<EOL>r'<STR_LIT>',<EOL>line)<EOL>if (match and<EOL>not Search(r'<STR_LIT>', line) and<EOL>not Search(r'<STR_LIT>', line) and<EOL>not Match(r'<STR_LIT>', match.group(<NUM_LIT:4>))):<EOL><INDENT>if Search(r'<STR_LIT>', line):<EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:4>,<EOL>'<STR_LIT>'<EOL>'<STR_LIT>' %<EOL>(match.group(<NUM_LIT:1>), match.group(<NUM_LIT:2>) or '<STR_LIT>', match.group(<NUM_LIT:3>)))<EOL><DEDENT>else:<EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:4>,<EOL>'<STR_LIT>')<EOL><DEDENT><DEDENT>if (Search(r'<STR_LIT>', line) or<EOL>Search(r'<STR_LIT>', line)):<EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:4>,<EOL>'<STR_LIT>')<EOL><DEDENT>

Check for unsafe global or static objects.

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


def CheckPrintf(filename, clean_lines, linenum, error):

line = clean_lines.elided[linenum]<EOL>match = Search(r'<STR_LIT>', line)<EOL>if match and match.group(<NUM_LIT:2>) != '<STR_LIT:0>':<EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:3>,<EOL>'<STR_LIT>'<EOL>'<STR_LIT>' % (match.group(<NUM_LIT:1>), match.group(<NUM_LIT:2>)))<EOL><DEDENT>if Search(r'<STR_LIT>', line):<EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:5>,<EOL>'<STR_LIT>')<EOL><DEDENT>match = Search(r'<STR_LIT>', line)<EOL>if match:<EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:4>,<EOL>'<STR_LIT>' % match.group(<NUM_LIT:1>))<EOL><DEDENT>

Check for printf related issues.

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


<EOL>for i in xrange(linenum, max(-<NUM_LIT:1>, linenum - <NUM_LIT:10>), -<NUM_LIT:1>):<EOL><INDENT>match = Match(r'<STR_LIT>', clean_lines.elided[i])<EOL>if match:<EOL><INDENT>line, _, closing_paren = CloseExpression(<EOL>clean_lines, i, len(match.group(<NUM_LIT:1>)))<EOL>return (closing_paren >= <NUM_LIT:0> and<EOL>Search(r'<STR_LIT>', line[closing_paren:]))<EOL><DEDENT><DEDENT>return False<EOL>

Check if current line contains an inherited function.

    Args:
      clean_lines: A CleansedLines instance containing the file.
      linenum: The number of the line to check.
    Returns:
      True if current line contains a function with "override"
      virt-specifier.


<EOL>for i in xrange(linenum, max(-<NUM_LIT:1>, linenum - <NUM_LIT:10>), -<NUM_LIT:1>):<EOL><INDENT>if Match(r'<STR_LIT>', clean_lines.elided[i]):<EOL><INDENT>return Match(r'<STR_LIT>', clean_lines.elided[i]) is not None<EOL><DEDENT><DEDENT>return False<EOL>

Check if current line contains an out-of-line method definition.

    Args:
      clean_lines: A CleansedLines instance containing the file.
      linenum: The number of the line to check.
    Returns:
      True if current line contains an out-of-line method definition.


for i in xrange(linenum, <NUM_LIT:1>, -<NUM_LIT:1>):<EOL><INDENT>line = clean_lines.elided[i]<EOL>if i == linenum:<EOL><INDENT>remove_function_body = Match(r'<STR_LIT>', line)<EOL>if remove_function_body:<EOL><INDENT>line = remove_function_body.group(<NUM_LIT:1>)<EOL><DEDENT><DEDENT>if Search(r'<STR_LIT>', line):<EOL><INDENT>return True<EOL><DEDENT>if Search(r'<STR_LIT>', line):<EOL><INDENT>return True<EOL><DEDENT>if Search(r'<STR_LIT>', line):<EOL><INDENT>return False<EOL><DEDENT><DEDENT>return False<EOL>

Check if current line is inside constructor initializer list.

    Args:
      clean_lines: A CleansedLines instance containing the file.
      linenum: The number of the line to check.
    Returns:
      True if current line appears to be inside constructor initializer
      list, False otherwise.


def CheckForNonConstReference(filename, clean_lines, linenum,<EOL>nesting_state, error):

<EOL>line = clean_lines.elided[linenum]<EOL>if '<STR_LIT:&>' not in line:<EOL><INDENT>return<EOL><DEDENT>if IsDerivedFunction(clean_lines, linenum):<EOL><INDENT>return<EOL><DEDENT>if IsOutOfLineMethodDefinition(clean_lines, linenum):<EOL><INDENT>return<EOL><DEDENT>if linenum > <NUM_LIT:1>:<EOL><INDENT>previous = None<EOL>if Match(r'<STR_LIT>', line):<EOL><INDENT>previous = Search(r'<STR_LIT>',<EOL>clean_lines.elided[linenum - <NUM_LIT:1>])<EOL><DEDENT>elif Match(r'<STR_LIT>', line):<EOL><INDENT>previous = Search(r'<STR_LIT>',<EOL>clean_lines.elided[linenum - <NUM_LIT:1>])<EOL><DEDENT>if previous:<EOL><INDENT>line = previous.group(<NUM_LIT:1>) + line.lstrip()<EOL><DEDENT>else:<EOL><INDENT>endpos = line.rfind('<STR_LIT:>>')<EOL>if endpos > -<NUM_LIT:1>:<EOL><INDENT>(_, startline, startpos) = ReverseCloseExpression(<EOL>clean_lines, linenum, endpos)<EOL>if startpos > -<NUM_LIT:1> and startline < linenum:<EOL><INDENT>line = '<STR_LIT>'<EOL>for i in xrange(startline, linenum + <NUM_LIT:1>):<EOL><INDENT>line += clean_lines.elided[i].strip()<EOL><DEDENT><DEDENT><DEDENT><DEDENT><DEDENT>if (nesting_state.previous_stack_top and<EOL>not (isinstance(nesting_state.previous_stack_top, _ClassInfo) or<EOL>isinstance(nesting_state.previous_stack_top, _NamespaceInfo))):<EOL><INDENT>return<EOL><DEDENT>if linenum > <NUM_LIT:0>:<EOL><INDENT>for i in xrange(linenum - <NUM_LIT:1>, max(<NUM_LIT:0>, linenum - <NUM_LIT:10>), -<NUM_LIT:1>):<EOL><INDENT>previous_line = clean_lines.elided[i]<EOL>if not Search(r'<STR_LIT>', previous_line):<EOL><INDENT>break<EOL><DEDENT>if Match(r'<STR_LIT>', previous_line):<EOL><INDENT>return<EOL><DEDENT><DEDENT><DEDENT>if Search(r'<STR_LIT>', line):<EOL><INDENT>return<EOL><DEDENT>if IsInitializerList(clean_lines, linenum):<EOL><INDENT>return<EOL><DEDENT>whitelisted_functions = (r'<STR_LIT>'<EOL>r'<STR_LIT>'<EOL>r'<STR_LIT>'<EOL>r'<STR_LIT>')<EOL>if Search(whitelisted_functions, line):<EOL><INDENT>return<EOL><DEDENT>elif not Search(r'<STR_LIT>', line):<EOL><INDENT>for i in xrange(<NUM_LIT:2>):<EOL><INDENT>if (linenum > i and<EOL>Search(whitelisted_functions, clean_lines.elided[linenum - i - <NUM_LIT:1>])):<EOL><INDENT>return<EOL><DEDENT><DEDENT><DEDENT>decls = ReplaceAll(r'<STR_LIT>', '<STR_LIT:U+0020>', line)  <EOL>for parameter in re.findall(_RE_PATTERN_REF_PARAM, decls):<EOL><INDENT>if (not Match(_RE_PATTERN_CONST_REF_PARAM, parameter) and<EOL>not Match(_RE_PATTERN_REF_STREAM_PARAM, parameter)):<EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:2>,<EOL>'<STR_LIT>'<EOL>'<STR_LIT>' +<EOL>ReplaceAll('<STR_LIT>', '<STR_LIT:<>', parameter))<EOL><DEDENT><DEDENT>

Check for non-const references.

    Separate from CheckLanguage since it scans backwards from current
    line, instead of scanning forward.

    Args:
      filename: The name of the current file.
      clean_lines: A CleansedLines instance containing the file.
      linenum: The number of the line to check.
      nesting_state: A NestingState instance which maintains information about
                     the current stack of nested blocks being parsed.
      error: The function to call with any errors found.


def CheckCasts(filename, clean_lines, linenum, error):

line = clean_lines.elided[linenum]<EOL>match = Search(<EOL>r'<STR_LIT>'<EOL>r'<STR_LIT>'<EOL>r'<STR_LIT>', line)<EOL>expecting_function = ExpectingFunctionArgs(clean_lines, linenum)<EOL>if match and not expecting_function:<EOL><INDENT>matched_type = match.group(<NUM_LIT:2>)<EOL>matched_new_or_template = match.group(<NUM_LIT:1>)<EOL>if Match(r'<STR_LIT>', match.group(<NUM_LIT:3>)):<EOL><INDENT>return<EOL><DEDENT>matched_funcptr = match.group(<NUM_LIT:3>)<EOL>if (matched_new_or_template is None and<EOL>not (matched_funcptr and<EOL>(Match(r'<STR_LIT>',<EOL>matched_funcptr) or<EOL>matched_funcptr.startswith('<STR_LIT>'))) and<EOL>not Match(r'<STR_LIT>' + matched_type, line) and<EOL>not Search(r'<STR_LIT>' + matched_type, line)):<EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:4>,<EOL>'<STR_LIT>'<EOL>'<STR_LIT>' %<EOL>matched_type)<EOL><DEDENT><DEDENT>if not expecting_function:<EOL><INDENT>CheckCStyleCast(filename, clean_lines, linenum, '<STR_LIT>',<EOL>r'<STR_LIT>', error)<EOL><DEDENT>if CheckCStyleCast(filename, clean_lines, linenum, '<STR_LIT>',<EOL>r'<STR_LIT>', error):<EOL><INDENT>pass<EOL><DEDENT>else:<EOL><INDENT>CheckCStyleCast(filename, clean_lines, linenum, '<STR_LIT>',<EOL>r'<STR_LIT>', error)<EOL><DEDENT>match = Search(<EOL>r'<STR_LIT>'<EOL>r'<STR_LIT>', line)<EOL>if match:<EOL><INDENT>parenthesis_error = False<EOL>match = Match(r'<STR_LIT>', line)<EOL>if match:<EOL><INDENT>_, y1, x1 = CloseExpression(clean_lines, linenum, len(match.group(<NUM_LIT:1>)))<EOL>if x1 >= <NUM_LIT:0> and clean_lines.elided[y1][x1] == '<STR_LIT:(>':<EOL><INDENT>_, y2, x2 = CloseExpression(clean_lines, y1, x1)<EOL>if x2 >= <NUM_LIT:0>:<EOL><INDENT>extended_line = clean_lines.elided[y2][x2:]<EOL>if y2 < clean_lines.NumLines() - <NUM_LIT:1>:<EOL><INDENT>extended_line += clean_lines.elided[y2 + <NUM_LIT:1>]<EOL><DEDENT>if Match(r'<STR_LIT>', extended_line):<EOL><INDENT>parenthesis_error = True<EOL><DEDENT><DEDENT><DEDENT><DEDENT>if parenthesis_error:<EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:4>,<EOL>('<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>'))<EOL><DEDENT>else:<EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:4>,<EOL>('<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>'))<EOL><DEDENT><DEDENT>

Various cast related checks.

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


def CheckCStyleCast(filename, clean_lines, linenum, cast_type, pattern, error):

line = clean_lines.elided[linenum]<EOL>match = Search(pattern, line)<EOL>if not match:<EOL><INDENT>return False<EOL><DEDENT>context = line[<NUM_LIT:0>:match.start(<NUM_LIT:1>) - <NUM_LIT:1>]<EOL>if Match(r'<STR_LIT>', context):<EOL><INDENT>return False<EOL><DEDENT>if linenum > <NUM_LIT:0>:<EOL><INDENT>for i in xrange(linenum - <NUM_LIT:1>, max(<NUM_LIT:0>, linenum - <NUM_LIT:5>), -<NUM_LIT:1>):<EOL><INDENT>context = clean_lines.elided[i] + context<EOL><DEDENT><DEDENT>if Match(r'<STR_LIT>', context):<EOL><INDENT>return False<EOL><DEDENT>if context.endswith('<STR_LIT>') or context.endswith('<STR_LIT>'):<EOL><INDENT>return False<EOL><DEDENT>remainder = line[match.end(<NUM_LIT:0>):]<EOL>if Match(r'<STR_LIT>',<EOL>remainder):<EOL><INDENT>return False<EOL><DEDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:4>,<EOL>'<STR_LIT>' %<EOL>(cast_type, match.group(<NUM_LIT:1>)))<EOL>return True<EOL>

Checks for a C-style cast by looking for the pattern.

    Args:
      filename: The name of the current file.
      clean_lines: A CleansedLines instance containing the file.
      linenum: The number of the line to check.
      cast_type: The string for the C++ cast to recommend.  This is either
        reinterpret_cast, static_cast, or const_cast, depending.
      pattern: The regular expression used to find C-style casts.
      error: The function to call with any errors found.

    Returns:
      True if an error was emitted.
      False otherwise.


line = clean_lines.elided[linenum]<EOL>return (Match(r'<STR_LIT>', line) or<EOL>(linenum >= <NUM_LIT:2> and<EOL>(Match(r'<STR_LIT>',<EOL>clean_lines.elided[linenum - <NUM_LIT:1>]) or<EOL>Match(r'<STR_LIT>',<EOL>clean_lines.elided[linenum - <NUM_LIT:2>]) or<EOL>Search(r'<STR_LIT>',<EOL>clean_lines.elided[linenum - <NUM_LIT:1>]))))<EOL>

Checks whether where function type arguments are expected.

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

    Returns:
      True if the line at 'linenum' is inside something that expects arguments
      of function types.


fileinfo_cc = FileInfo(filename_cc)<EOL>if not fileinfo_cc.Extension().lstrip('<STR_LIT:.>') in GetNonHeaderExtensions():<EOL><INDENT>return (False, '<STR_LIT>')<EOL><DEDENT>fileinfo_h = FileInfo(filename_h)<EOL>if not fileinfo_h.Extension().lstrip('<STR_LIT:.>') in GetHeaderExtensions():<EOL><INDENT>return (False, '<STR_LIT>')<EOL><DEDENT>filename_cc = filename_cc[:-(len(fileinfo_cc.Extension()))]<EOL>matched_test_suffix = Search(_TEST_FILE_SUFFIX, fileinfo_cc.BaseName())<EOL>if matched_test_suffix:<EOL><INDENT>filename_cc = filename_cc[:-len(matched_test_suffix.group(<NUM_LIT:1>))]<EOL><DEDENT>filename_cc = filename_cc.replace('<STR_LIT>', '<STR_LIT:/>')<EOL>filename_cc = filename_cc.replace('<STR_LIT>', '<STR_LIT:/>')<EOL>filename_h = filename_h[:-(len(fileinfo_h.Extension()))]<EOL>if filename_h.endswith('<STR_LIT>'):<EOL><INDENT>filename_h = filename_h[:-len('<STR_LIT>')]<EOL><DEDENT>filename_h = filename_h.replace('<STR_LIT>', '<STR_LIT:/>')<EOL>filename_h = filename_h.replace('<STR_LIT>', '<STR_LIT:/>')<EOL>files_belong_to_same_module = filename_cc.endswith(filename_h)<EOL>common_path = '<STR_LIT>'<EOL>if files_belong_to_same_module:<EOL><INDENT>common_path = filename_cc[:-len(filename_h)]<EOL><DEDENT>return files_belong_to_same_module, common_path<EOL>

Check if these two filenames belong to the same module.

    The concept of a 'module' here is a as follows:
    foo.h, foo-inl.h, foo.cc, foo_test.cc and foo_unittest.cc belong to the
    same 'module' if they are in the same directory.
    some/path/public/xyzzy and some/path/internal/xyzzy are also considered
    to belong to the same module here.

    If the filename_cc contains a longer path than the filename_h, for example,
    '/absolute/path/to/base/sysinfo.cc', and this file would include
    'base/sysinfo.h', this function also produces the prefix needed to open the
    header. This is used by the caller of this function to more robustly open the
    header file. We don't have access to the real include paths in this context,
    so we need this guesswork here.

    Known bugs: tools/base/bar.cc and base/bar.h belong to the same module
    according to this implementation. Because of this, this function gives
    some false positives. This should be sufficiently rare in practice.

    Args:
      filename_cc: is the path for the source (e.g. .cc) file
      filename_h: is the path for the header path

    Returns:
      Tuple with a bool and a string:
      bool: True if filename_cc and filename_h belong to the same module.
      string: the additional prefix needed to open the header file.


def UpdateIncludeState(filename, include_dict, io=codecs):

headerfile = None<EOL>try:<EOL><INDENT>headerfile = io.open(filename, '<STR_LIT:r>', '<STR_LIT:utf8>', '<STR_LIT:replace>')<EOL><DEDENT>except IOError:<EOL><INDENT>return False<EOL><DEDENT>linenum = <NUM_LIT:0><EOL>for line in headerfile:<EOL><INDENT>linenum += <NUM_LIT:1><EOL>clean_line = CleanseComments(line)<EOL>match = _RE_PATTERN_INCLUDE.search(clean_line)<EOL>if match:<EOL><INDENT>include = match.group(<NUM_LIT:2>)<EOL>include_dict.setdefault(include, linenum)<EOL><DEDENT><DEDENT>return True<EOL>

Fill up the include_dict with new includes found from the file.

    Args:
      filename: the name of the header to read.
      include_dict: a dictionary in which the headers are inserted.
      io: The io factory to use to read the file. Provided for testability.

    Returns:
      True if a header was successfully added. False otherwise.


def CheckForIncludeWhatYouUse(filename, clean_lines, include_state, error,<EOL>io=codecs):

required = {}  <EOL>for linenum in range(clean_lines.NumLines()):<EOL><INDENT>line = clean_lines.elided[linenum]<EOL>if not line or line[<NUM_LIT:0>] == '<STR_LIT:#>':<EOL><INDENT>continue<EOL><DEDENT>matched = _RE_PATTERN_STRING.search(line)<EOL>if matched:<EOL><INDENT>prefix = line[:matched.start()]<EOL>if prefix.endswith('<STR_LIT>') or not prefix.endswith('<STR_LIT>'):<EOL><INDENT>required['<STR_LIT>'] = (linenum, '<STR_LIT:string>')<EOL><DEDENT><DEDENT>for pattern, template, header in _re_pattern_headers_maybe_templates:<EOL><INDENT>if pattern.search(line):<EOL><INDENT>required[header] = (linenum, template)<EOL><DEDENT><DEDENT>if not '<STR_LIT:<>' in line:  <EOL><INDENT>continue<EOL><DEDENT>for pattern, template, header in _re_pattern_templates:<EOL><INDENT>if pattern.search(line):<EOL><INDENT>required[header] = (linenum, template)<EOL><DEDENT><DEDENT><DEDENT>include_dict = dict([item for sublist in include_state.include_list<EOL>for item in sublist])<EOL>header_found = False<EOL>abs_filename = FileInfo(filename).FullName()<EOL>abs_filename = re.sub(r'<STR_LIT>', '<STR_LIT>', abs_filename)<EOL>header_keys = list(include_dict.keys())<EOL>for header in header_keys:<EOL><INDENT>(same_module, common_path) = FilesBelongToSameModule(abs_filename, header)<EOL>fullpath = common_path + header<EOL>if same_module and UpdateIncludeState(fullpath, include_dict, io):<EOL><INDENT>header_found = True<EOL><DEDENT><DEDENT>if not header_found:<EOL><INDENT>for extension in GetNonHeaderExtensions():<EOL><INDENT>if filename.endswith('<STR_LIT:.>' + extension):<EOL><INDENT>return<EOL><DEDENT><DEDENT><DEDENT>for required_header_unstripped in sorted(required, key=required.__getitem__):<EOL><INDENT>template = required[required_header_unstripped][<NUM_LIT:1>]<EOL>if required_header_unstripped.strip('<STR_LIT>') not in include_dict:<EOL><INDENT>error(filename, required[required_header_unstripped][<NUM_LIT:0>],<EOL>'<STR_LIT>', <NUM_LIT:4>,<EOL>'<STR_LIT>' + required_header_unstripped + '<STR_LIT>' + template)<EOL><DEDENT><DEDENT>

Reports for missing stl includes.

    This function will output warnings to make sure you are including the headers
    necessary for the stl containers and functions that you use. We only give one
    reason to include a header. For example, if you use both equal_to<> and
    less<> in a .h file, only one (the latter in the file) of these will be
    reported as a reason to include the <functional>.

    Args:
      filename: The name of the current file.
      clean_lines: A CleansedLines instance containing the file.
      include_state: An _IncludeState instance.
      error: The function to call with any errors found.
      io: The IO factory to use to read the header file. Provided for unittest
          injection.


def CheckMakePairUsesDeduction(filename, clean_lines, linenum, error):

line = clean_lines.elided[linenum]<EOL>match = _RE_PATTERN_EXPLICIT_MAKEPAIR.search(line)<EOL>if match:<EOL><INDENT>error(filename, linenum, '<STR_LIT>',<EOL><NUM_LIT:4>,  <EOL>'<STR_LIT>'<EOL>'<STR_LIT>')<EOL><DEDENT>

Check that make_pair's template arguments are deduced.

    G++ 4.6 in C++11 mode fails badly if make_pair's template arguments are
    specified explicitly, and such use isn't intended in any case.

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


def CheckRedundantVirtual(filename, clean_lines, linenum, error):

<EOL>line = clean_lines.elided[linenum]<EOL>virtual = Match(r'<STR_LIT>', line)<EOL>if not virtual: return<EOL>if (Search(r'<STR_LIT>', virtual.group(<NUM_LIT:1>)) or<EOL>Match(r'<STR_LIT>', virtual.group(<NUM_LIT:3>))):<EOL><INDENT>return<EOL><DEDENT>if Match(r'<STR_LIT>', line): return<EOL>end_col = -<NUM_LIT:1><EOL>end_line = -<NUM_LIT:1><EOL>start_col = len(virtual.group(<NUM_LIT:2>))<EOL>for start_line in xrange(linenum, min(linenum + <NUM_LIT:3>, clean_lines.NumLines())):<EOL><INDENT>line = clean_lines.elided[start_line][start_col:]<EOL>parameter_list = Match(r'<STR_LIT>', line)<EOL>if parameter_list:<EOL><INDENT>(_, end_line, end_col) = CloseExpression(<EOL>clean_lines, start_line, start_col + len(parameter_list.group(<NUM_LIT:1>)))<EOL>break<EOL><DEDENT>start_col = <NUM_LIT:0><EOL><DEDENT>if end_col < <NUM_LIT:0>:<EOL><INDENT>return  <EOL><DEDENT>for i in xrange(end_line, min(end_line + <NUM_LIT:3>, clean_lines.NumLines())):<EOL><INDENT>line = clean_lines.elided[i][end_col:]<EOL>match = Search(r'<STR_LIT>', line)<EOL>if match:<EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:4>,<EOL>('<STR_LIT>'<EOL>'<STR_LIT>' % match.group(<NUM_LIT:1>)))<EOL><DEDENT>end_col = <NUM_LIT:0><EOL>if Search(r'<STR_LIT>', line):<EOL><INDENT>break<EOL><DEDENT><DEDENT>

Check if line contains a redundant "virtual" function-specifier.

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


def CheckRedundantOverrideOrFinal(filename, clean_lines, linenum, error):

<EOL>line = clean_lines.elided[linenum]<EOL>declarator_end = line.rfind('<STR_LIT:)>')<EOL>if declarator_end >= <NUM_LIT:0>:<EOL><INDENT>fragment = line[declarator_end:]<EOL><DEDENT>else:<EOL><INDENT>if linenum > <NUM_LIT:1> and clean_lines.elided[linenum - <NUM_LIT:1>].rfind('<STR_LIT:)>') >= <NUM_LIT:0>:<EOL><INDENT>fragment = line<EOL><DEDENT>else:<EOL><INDENT>return<EOL><DEDENT><DEDENT>if Search(r'<STR_LIT>', fragment) and Search(r'<STR_LIT>', fragment):<EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:4>,<EOL>('<STR_LIT>'<EOL>'<STR_LIT>'))<EOL><DEDENT>

Check if line contains a redundant "override" or "final" virt-specifier.

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


if is_forward_declaration:<EOL><INDENT>return len(nesting_state.stack) >= <NUM_LIT:1> and (<EOL>isinstance(nesting_state.stack[-<NUM_LIT:1>], _NamespaceInfo))<EOL><DEDENT>return (len(nesting_state.stack) > <NUM_LIT:1> and<EOL>nesting_state.stack[-<NUM_LIT:1>].check_namespace_indentation and<EOL>isinstance(nesting_state.stack[-<NUM_LIT:2>], _NamespaceInfo))<EOL>

Checks that the new block is directly in a namespace.

    Args:
      nesting_state: The _NestingState object that contains info about our state.
      is_forward_declaration: If the class is a forward declared class.
    Returns:
      Whether or not the new block is directly in a namespace.


def ShouldCheckNamespaceIndentation(nesting_state, is_namespace_indent_item,<EOL>raw_lines_no_comments, linenum):

is_forward_declaration = IsForwardClassDeclaration(raw_lines_no_comments,<EOL>linenum)<EOL>if not (is_namespace_indent_item or is_forward_declaration):<EOL><INDENT>return False<EOL><DEDENT>if IsMacroDefinition(raw_lines_no_comments, linenum):<EOL><INDENT>return False<EOL><DEDENT>return IsBlockInNameSpace(nesting_state, is_forward_declaration)<EOL>

This method determines if we should apply our namespace indentation check.

    Args:
      nesting_state: The current nesting state.
      is_namespace_indent_item: If we just put a new class on the stack, True.
        If the top of the stack is not a class, or we did not recently
        add the class, False.
      raw_lines_no_comments: The lines without the comments.
      linenum: The current line number we are processing.

    Returns:
      True if we should apply our namespace indentation check. Currently, it
      only works for classes and namespaces inside of a namespace.


def ProcessLine(filename, file_extension, clean_lines, line,<EOL>include_state, function_state, nesting_state, error,<EOL>extra_check_functions=None):

raw_lines = clean_lines.raw_lines<EOL>ParseNolintSuppressions(filename, raw_lines[line], line, error)<EOL>nesting_state.Update(filename, clean_lines, line, error)<EOL>CheckForNamespaceIndentation(filename, nesting_state, clean_lines, line,<EOL>error)<EOL>if nesting_state.InAsmBlock(): return<EOL>CheckForFunctionLengths(filename, clean_lines, line, function_state, error)<EOL>CheckForMultilineCommentsAndStrings(filename, clean_lines, line, error)<EOL>CheckStyle(filename, clean_lines, line, file_extension, nesting_state, error)<EOL>CheckLanguage(filename, clean_lines, line, file_extension, include_state,<EOL>nesting_state, error)<EOL>CheckForNonConstReference(filename, clean_lines, line, nesting_state, error)<EOL>CheckForNonStandardConstructs(filename, clean_lines, line,<EOL>nesting_state, error)<EOL>CheckVlogArguments(filename, clean_lines, line, error)<EOL>CheckPosixThreading(filename, clean_lines, line, error)<EOL>CheckInvalidIncrement(filename, clean_lines, line, error)<EOL>CheckMakePairUsesDeduction(filename, clean_lines, line, error)<EOL>CheckRedundantVirtual(filename, clean_lines, line, error)<EOL>CheckRedundantOverrideOrFinal(filename, clean_lines, line, error)<EOL>if extra_check_functions:<EOL><INDENT>for check_fn in extra_check_functions:<EOL><INDENT>check_fn(filename, clean_lines, line, error)<EOL><DEDENT><DEDENT>

Processes a single line in the file.

    Args:
      filename: Filename of the file that is being processed.
      file_extension: The extension (dot not included) of the file.
      clean_lines: An array of strings, each representing a line of the file,
                   with comments stripped.
      line: Number of line being processed.
      include_state: An _IncludeState instance in which the headers are inserted.
      function_state: A _FunctionState instance which counts function lines, etc.
      nesting_state: A NestingState instance which maintains information about
                     the current stack of nested blocks being parsed.
      error: A callable to which errors are reported, which takes 4 arguments:
             filename, line number, error level, and message
      extra_check_functions: An array of additional check functions that will be
                             run on each source line. Each function takes 4
                             arguments: filename, clean_lines, line, error


def FlagCxx11Features(filename, clean_lines, linenum, error):

line = clean_lines.elided[linenum]<EOL>include = Match(r'<STR_LIT>', line)<EOL>if include and include.group(<NUM_LIT:1>).startswith('<STR_LIT>'):<EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:5>,<EOL>('<STR_LIT>') % include.group(<NUM_LIT:1>))<EOL><DEDENT>if include and include.group(<NUM_LIT:1>) in ('<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>):<EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:5>,<EOL>('<STR_LIT>') % include.group(<NUM_LIT:1>))<EOL><DEDENT>if Match(r'<STR_LIT>', line) and not Match(r'<STR_LIT>', line): return<EOL>for top_name in (<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>):<EOL><INDENT>if Search(r'<STR_LIT>' % top_name, line):<EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:5>,<EOL>('<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>') % top_name)<EOL><DEDENT><DEDENT>

Flag those c++11 features that we only allow in certain places.

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


def FlagCxx14Features(filename, clean_lines, linenum, error):

line = clean_lines.elided[linenum]<EOL>include = Match(r'<STR_LIT>', line)<EOL>if include and include.group(<NUM_LIT:1>) in ('<STR_LIT>', '<STR_LIT>'):<EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:5>,<EOL>('<STR_LIT>') % include.group(<NUM_LIT:1>))<EOL><DEDENT>

Flag those C++14 features that we restrict.

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


def ProcessFileData(filename, file_extension, lines, error,<EOL>extra_check_functions=None):

lines = (['<STR_LIT>'] + lines +<EOL>['<STR_LIT>'])<EOL>include_state = _IncludeState()<EOL>function_state = _FunctionState()<EOL>nesting_state = NestingState()<EOL>ResetNolintSuppressions()<EOL>CheckForCopyright(filename, lines, error)<EOL>ProcessGlobalSuppresions(lines)<EOL>RemoveMultiLineComments(filename, lines, error)<EOL>clean_lines = CleansedLines(lines)<EOL>if file_extension in GetHeaderExtensions():<EOL><INDENT>CheckForHeaderGuard(filename, clean_lines, error)<EOL><DEDENT>for line in range(clean_lines.NumLines()):<EOL><INDENT>ProcessLine(filename, file_extension, clean_lines, line,<EOL>include_state, function_state, nesting_state, error,<EOL>extra_check_functions)<EOL>FlagCxx11Features(filename, clean_lines, line, error)<EOL><DEDENT>nesting_state.CheckCompletedBlocks(filename, error)<EOL>CheckForIncludeWhatYouUse(filename, clean_lines, include_state, error)<EOL>if _IsSourceExtension(file_extension):<EOL><INDENT>CheckHeaderFileIncluded(filename, include_state, error)<EOL><DEDENT>CheckForBadCharacters(filename, lines, error)<EOL>CheckForNewlineAtEOF(filename, lines, error)<EOL>

Performs lint checks and reports any errors to the given error function.

    Args:
      filename: Filename of the file that is being processed.
      file_extension: The extension (dot not included) of the file.
      lines: An array of strings, each representing a line of the file, with the
             last element being empty if the file is terminated with a newline.
      error: A callable to which errors are reported, which takes 4 arguments:
             filename, line number, error level, and message
      extra_check_functions: An array of additional check functions that will be
                             run on each source line. Each function takes 4
                             arguments: filename, clean_lines, line, error


abs_filename = os.path.abspath(filename)<EOL>cfg_filters = []<EOL>keep_looking = True<EOL>while keep_looking:<EOL><INDENT>abs_path, base_name = os.path.split(abs_filename)<EOL>if not base_name:<EOL><INDENT>break  <EOL><DEDENT>cfg_file = os.path.join(abs_path, "<STR_LIT>")<EOL>abs_filename = abs_path<EOL>if not os.path.isfile(cfg_file):<EOL><INDENT>continue<EOL><DEDENT>try:<EOL><INDENT>with open(cfg_file) as file_handle:<EOL><INDENT>for line in file_handle:<EOL><INDENT>line, _, _ = line.partition('<STR_LIT:#>')  <EOL>if not line.strip():<EOL><INDENT>continue<EOL><DEDENT>name, _, val = line.partition('<STR_LIT:=>')<EOL>name = name.strip()<EOL>val = val.strip()<EOL>if name == '<STR_LIT>':<EOL><INDENT>keep_looking = False<EOL><DEDENT>elif name == '<STR_LIT>':<EOL><INDENT>cfg_filters.append(val)<EOL><DEDENT>elif name == '<STR_LIT>':<EOL><INDENT>if base_name:<EOL><INDENT>pattern = re.compile(val)<EOL>if pattern.match(base_name):<EOL><INDENT>_cpplint_state.PrintInfo('<STR_LIT>'<EOL>'<STR_LIT>' %<EOL>(filename, cfg_file, base_name, val))<EOL>return False<EOL><DEDENT><DEDENT><DEDENT>elif name == '<STR_LIT>':<EOL><INDENT>global _line_length<EOL>try:<EOL><INDENT>_line_length = int(val)<EOL><DEDENT>except ValueError:<EOL><INDENT>_cpplint_state.PrintError('<STR_LIT>')<EOL><DEDENT><DEDENT>elif name == '<STR_LIT>':<EOL><INDENT>global _valid_extensions<EOL>try:<EOL><INDENT>extensions = [ext.strip() for ext in val.split('<STR_LIT:U+002C>')]<EOL>_valid_extensions = set(extensions)<EOL><DEDENT>except ValueError:<EOL><INDENT>sys.stderr.write('<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>' % (val,))<EOL><DEDENT><DEDENT>elif name == '<STR_LIT>':<EOL><INDENT>global _header_extensions<EOL>try:<EOL><INDENT>extensions = [ext.strip() for ext in val.split('<STR_LIT:U+002C>')]<EOL>_header_extensions = set(extensions)<EOL><DEDENT>except ValueError:<EOL><INDENT>sys.stderr.write('<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>' % (val,))<EOL><DEDENT><DEDENT>elif name == '<STR_LIT:root>':<EOL><INDENT>global _root<EOL>_root = val<EOL><DEDENT>else:<EOL><INDENT>_cpplint_state.PrintError(<EOL>'<STR_LIT>' %<EOL>(name, cfg_file))<EOL><DEDENT><DEDENT><DEDENT><DEDENT>except IOError:<EOL><INDENT>_cpplint_state.PrintError(<EOL>"<STR_LIT>" % cfg_file)<EOL>keep_looking = False<EOL><DEDENT><DEDENT>for cfg_filter in reversed(cfg_filters):<EOL><INDENT>_AddFilters(cfg_filter)<EOL><DEDENT>return True<EOL>

Loads the configuration files and processes the config overrides.

    Args:
      filename: The name of the file being processed by the linter.

    Returns:
      False if the current |filename| should not be processed further.


def ProcessFile(filename, vlevel, extra_check_functions=None):

_SetVerboseLevel(vlevel)<EOL>_BackupFilters()<EOL>if not ProcessConfigOverrides(filename):<EOL><INDENT>_RestoreFilters()<EOL>return<EOL><DEDENT>lf_lines = []<EOL>crlf_lines = []<EOL>try:<EOL><INDENT>if filename == '<STR_LIT:->':<EOL><INDENT>lines = codecs.StreamReaderWriter(sys.stdin,<EOL>codecs.getreader('<STR_LIT:utf8>'),<EOL>codecs.getwriter('<STR_LIT:utf8>'),<EOL>'<STR_LIT:replace>').read().split('<STR_LIT:\n>')<EOL><DEDENT>else:<EOL><INDENT>lines = codecs.open(filename, '<STR_LIT:r>', '<STR_LIT:utf8>', '<STR_LIT:replace>').read().split('<STR_LIT:\n>')<EOL><DEDENT>for linenum in range(len(lines) - <NUM_LIT:1>):<EOL><INDENT>if lines[linenum].endswith('<STR_LIT:\r>'):<EOL><INDENT>lines[linenum] = lines[linenum].rstrip('<STR_LIT:\r>')<EOL>crlf_lines.append(linenum + <NUM_LIT:1>)<EOL><DEDENT>else:<EOL><INDENT>lf_lines.append(linenum + <NUM_LIT:1>)<EOL><DEDENT><DEDENT><DEDENT>except IOError:<EOL><INDENT>_cpplint_state.PrintError(<EOL>"<STR_LIT>" % filename)<EOL>_RestoreFilters()<EOL>return<EOL><DEDENT>file_extension = filename[filename.rfind('<STR_LIT:.>') + <NUM_LIT:1>:]<EOL>if filename != '<STR_LIT:->' and file_extension not in GetAllExtensions():<EOL><INDENT>bazel_gen_files = set([ <EOL>"<STR_LIT>",<EOL>"<STR_LIT>", <EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>])<EOL>if not filename in bazel_gen_files:<EOL><INDENT>_cpplint_state.PrintError('<STR_LIT>'<EOL>'<STR_LIT>' % (filename, '<STR_LIT:U+002CU+0020>'.join(GetAllExtensions())))<EOL><DEDENT><DEDENT>else:<EOL><INDENT>ProcessFileData(filename, file_extension, lines, Error,<EOL>extra_check_functions)<EOL>if lf_lines and crlf_lines:<EOL><INDENT>for linenum in crlf_lines:<EOL><INDENT>Error(filename, linenum, '<STR_LIT>', <NUM_LIT:1>,<EOL>'<STR_LIT>')<EOL><DEDENT><DEDENT><DEDENT>_RestoreFilters()<EOL>

Does google-lint on a single file.

    Args:
      filename: The name of the file to parse.

      vlevel: The level of errors to report.  Every error of confidence
      >= verbose_level will be reported.  0 is a good default.

      extra_check_functions: An array of additional check functions that will be
                             run on each source line. Each function takes 4
                             arguments: filename, clean_lines, line, error


sys.stderr.write(_USAGE)<EOL>if message:<EOL><INDENT>sys.exit('<STR_LIT>' + message)<EOL><DEDENT>else:<EOL><INDENT>sys.exit(<NUM_LIT:0>)<EOL><DEDENT>

Prints a brief usage string and exits, optionally with an error message.

    Args:
      message: The optional error message.


sys.stderr.write('<STR_LIT>'.join('<STR_LIT>' % cat for cat in _ERROR_CATEGORIES))<EOL>sys.exit(<NUM_LIT:0>)<EOL>

Prints a list of all the error-categories used by error messages.

    These are the categories used to filter messages via --filter.


try:<EOL><INDENT>(opts, filenames) = getopt.getopt(args, '<STR_LIT>', ['<STR_LIT>', '<STR_LIT>', '<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>'])<EOL><DEDENT>except getopt.GetoptError:<EOL><INDENT>PrintUsage('<STR_LIT>')<EOL><DEDENT>verbosity = _VerboseLevel()<EOL>output_format = _OutputFormat()<EOL>filters = '<STR_LIT>'<EOL>counting_style = '<STR_LIT>'<EOL>recursive = False<EOL>for (opt, val) in opts:<EOL><INDENT>if opt == '<STR_LIT>':<EOL><INDENT>PrintUsage(None)<EOL><DEDENT>elif opt == '<STR_LIT>':<EOL><INDENT>if val not in ('<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>'):<EOL><INDENT>PrintUsage('<STR_LIT>'<EOL>'<STR_LIT>')<EOL><DEDENT>output_format = val<EOL><DEDENT>elif opt == '<STR_LIT>':<EOL><INDENT>verbosity = int(val)<EOL><DEDENT>elif opt == '<STR_LIT>':<EOL><INDENT>filters = val<EOL>if not filters:<EOL><INDENT>PrintCategories()<EOL><DEDENT><DEDENT>elif opt == '<STR_LIT>':<EOL><INDENT>if val not in ('<STR_LIT>', '<STR_LIT>', '<STR_LIT>'):<EOL><INDENT>PrintUsage('<STR_LIT>')<EOL><DEDENT>counting_style = val<EOL><DEDENT>elif opt == '<STR_LIT>':<EOL><INDENT>global _root<EOL>_root = val<EOL><DEDENT>elif opt == '<STR_LIT>':<EOL><INDENT>global _repository<EOL>_repository = val<EOL><DEDENT>elif opt == '<STR_LIT>':<EOL><INDENT>global _line_length<EOL>try:<EOL><INDENT>_line_length = int(val)<EOL><DEDENT>except ValueError:<EOL><INDENT>PrintUsage('<STR_LIT>')<EOL><DEDENT><DEDENT>elif opt == '<STR_LIT>':<EOL><INDENT>global _excludes<EOL>if not _excludes:<EOL><INDENT>_excludes = set()<EOL><DEDENT>_excludes.update(glob.glob(val))<EOL><DEDENT>elif opt == '<STR_LIT>':<EOL><INDENT>global _valid_extensions<EOL>try:<EOL><INDENT>_valid_extensions = set(val.split('<STR_LIT:U+002C>'))<EOL><DEDENT>except ValueError:<EOL><INDENT>PrintUsage('<STR_LIT>')<EOL><DEDENT><DEDENT>elif opt == '<STR_LIT>':<EOL><INDENT>global _header_extensions<EOL>try:<EOL><INDENT>_header_extensions = set(val.split('<STR_LIT:U+002C>'))<EOL><DEDENT>except ValueError:<EOL><INDENT>PrintUsage('<STR_LIT>')<EOL><DEDENT><DEDENT>elif opt == '<STR_LIT>':<EOL><INDENT>recursive = True<EOL><DEDENT>elif opt == '<STR_LIT>':<EOL><INDENT>global _quiet<EOL>_quiet = True<EOL><DEDENT><DEDENT>if not filenames:<EOL><INDENT>PrintUsage('<STR_LIT>')<EOL><DEDENT>if recursive:<EOL><INDENT>filenames = _ExpandDirectories(filenames)<EOL><DEDENT>if _excludes:<EOL><INDENT>filenames = _FilterExcludedFiles(filenames)<EOL><DEDENT>_SetOutputFormat(output_format)<EOL>_SetVerboseLevel(verbosity)<EOL>_SetFilters(filters)<EOL>_SetCountingStyle(counting_style)<EOL>return filenames<EOL>

Parses the command line arguments.

    This may set the output format and verbosity level as side-effects.

    Args:
      args: The command line arguments:

    Returns:
      The list of filenames to lint.


expanded = set()<EOL>for filename in filenames:<EOL><INDENT>if not os.path.isdir(filename):<EOL><INDENT>expanded.add(filename)<EOL>continue<EOL><DEDENT>for root, _, files in os.walk(filename):<EOL><INDENT>for loopfile in files:<EOL><INDENT>fullname = os.path.join(root, loopfile)<EOL>if fullname.startswith('<STR_LIT:.>' + os.path.sep):<EOL><INDENT>fullname = fullname[len('<STR_LIT:.>' + os.path.sep):]<EOL><DEDENT>expanded.add(fullname)<EOL><DEDENT><DEDENT><DEDENT>filtered = []<EOL>for filename in expanded:<EOL><INDENT>if os.path.splitext(filename)[<NUM_LIT:1>][<NUM_LIT:1>:] in GetAllExtensions():<EOL><INDENT>filtered.append(filename)<EOL><DEDENT><DEDENT>return filtered<EOL>

Searches a list of filenames and replaces directories in the list with
    all files descending from those directories. Files with extensions not in
    the valid extensions list are excluded.

    Args:
      filenames: A list of files or directories

    Returns:
      A list of all files that are members of filenames or descended from a
      directory in filenames


exclude_paths = [os.path.abspath(f) for f in _excludes]<EOL>return [f for f in filenames if os.path.abspath(f) not in exclude_paths]<EOL>

Filters out files listed in the --exclude command line switch. File paths
    in the switch are evaluated relative to the current working directory


for section_list in self.include_list:<EOL><INDENT>for f in section_list:<EOL><INDENT>if f[<NUM_LIT:0>] == header:<EOL><INDENT>return f[<NUM_LIT:1>]<EOL><DEDENT><DEDENT><DEDENT>return -<NUM_LIT:1><EOL>

Check if a header has already been included.

        Args:
          header: header to check.
        Returns:
          Line number of previous occurrence, or -1 if the header has not
          been seen before.


<EOL>self._section = self._INITIAL_SECTION<EOL>self._last_header = '<STR_LIT>'<EOL>if directive in ('<STR_LIT>', '<STR_LIT>', '<STR_LIT>'):<EOL><INDENT>self.include_list.append([])<EOL><DEDENT>elif directive in ('<STR_LIT>', '<STR_LIT>'):<EOL><INDENT>self.include_list[-<NUM_LIT:1>] = []<EOL><DEDENT>

Reset section checking for preprocessor directive.

        Args:
          directive: preprocessor directive (e.g. "if", "else").


return header_path.replace('<STR_LIT>', '<STR_LIT>').replace('<STR_LIT:->', '<STR_LIT:_>').lower()<EOL>

Returns a path canonicalized for alphabetical comparison.

        - replaces "-" with "_" so they both cmp the same.
        - removes '-inl' since we don't require them to be after the main header.
        - lowercase everything, just in case.

        Args:
          header_path: Path to be canonicalized.

        Returns:
          Canonicalized path.