Logo SoCRocket

Transaction-Level Modeling Framework for Space Applications

Classes | Functions | Variables
core.tools.cpplint Namespace Reference

Classes

class  CleansedLines
 

Functions

def CleanseRawStrings
 
def FindNextMultiLineCommentStart
 
def FindNextMultiLineCommentEnd
 
def RemoveMultiLineCommentsFromRange
 
def RemoveMultiLineComments
 
def CleanseComments
 
def FindEndOfExpressionInLine
 
def CloseExpression
 
def FindStartOfExpressionInLine
 
def ReverseCloseExpression
 
def CheckForCopyright
 
def GetHeaderGuardCPPVariable
 
def CheckForHeaderGuard
 
def CheckForBadCharacters
 
def CheckForNewlineAtEOF
 
def CheckForMultilineCommentsAndStrings
 

Variables

string _USAGE
 
list _ERROR_CATEGORIES
 
list _DEFAULT_FILTERS = ['-build/include_alpha']
 
tuple _CPP_HEADERS
 
list _CHECK_MACROS
 
tuple _CHECK_REPLACEMENT = dict([(m, {}) for m in _CHECK_MACROS])
 
dictionary _ALT_TOKEN_REPLACEMENT
 
tuple _ALT_TOKEN_REPLACEMENT_PATTERN
 

Function Documentation

def core.tools.cpplint.CheckForBadCharacters (   filename,
  lines,
  error 
)
Logs an error for each line containing bad characters.

Two kinds of bad characters:

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

2. NUL bytes.  These are problematic for some tools.

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

References v.error.

def core.tools.cpplint.CheckForCopyright (   filename,
  lines,
  error 
)
Logs an error if no Copyright message appears at the top of the file.

References v.error.

def core.tools.cpplint.CheckForHeaderGuard (   filename,
  lines,
  error 
)
Checks that the file contains a header guard.

Logs an error if no #ifndef header guard is present.  For other
headers, checks that the full pathname is used.

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

References v.error, and core.tools.cpplint.GetHeaderGuardCPPVariable().

Here is the call graph for this function:

def core.tools.cpplint.CheckForMultilineCommentsAndStrings (   filename,
  clean_lines,
  linenum,
  error 
)
Logs an error if we see /* ... */ or "..." that extend past one line.

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

Args:
  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.

References v.error.

def core.tools.cpplint.CheckForNewlineAtEOF (   filename,
  lines,
  error 
)
Logs an error if there is no newline char at the end of the file.

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

References v.error.

def core.tools.cpplint.CleanseComments (   line)
Removes //-comments and single-line C-style /* */ comments.

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

Returns:
  The line with single-line comments removed.
def core.tools.cpplint.CleanseRawStrings (   raw_lines)
Removes C++11 raw strings from lines.

  Before:
    static const char kData[] = R"(
        multi-line string
        )";

  After:
    static const char kData[] = ""
        (replaced by blank line)
        "";

Args:
  raw_lines: list of raw lines.

Returns:
  list of lines with C++11 raw strings replaced by empty strings.

References find().

Here is the call graph for this function:

def core.tools.cpplint.CloseExpression (   clean_lines,
  linenum,
  pos 
)
If input points to ( or { or [ or <, finds the position that closes it.

If lines[linenum][pos] points to a '(' or '{' or '[' or '<', finds the
linenum/pos that correspond to the closing of the expression.

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

Returns:
  A tuple (line, linenum, pos) pointer *past* the closing brace, or
  (line, len(lines), -1) if we never find a close.  Note we ignore
  strings and comments when matching; and the line we return is the
  'cleansed' line at linenum.

References core.tools.cpplint.FindEndOfExpressionInLine().

Here is the call graph for this function:

def core.tools.cpplint.FindEndOfExpressionInLine (   line,
  startpos,
  depth,
  startchar,
  endchar 
)
Find the position just after the matching endchar.

Args:
  line: a CleansedLines line.
  startpos: start searching at this position.
  depth: nesting level at startpos.
  startchar: expression opening character.
  endchar: expression closing character.

Returns:
  On finding matching endchar: (index just after matching endchar, 0)
  Otherwise: (-1, new depth at end of this line)

Referenced by core.tools.cpplint.CloseExpression().

def core.tools.cpplint.FindNextMultiLineCommentEnd (   lines,
  lineix 
)
We are inside a comment, find the end marker.

Referenced by core.tools.cpplint.RemoveMultiLineComments().

def core.tools.cpplint.FindNextMultiLineCommentStart (   lines,
  lineix 
)
Find the beginning marker for a multiline comment.

References find().

Referenced by core.tools.cpplint.RemoveMultiLineComments().

Here is the call graph for this function:

def core.tools.cpplint.FindStartOfExpressionInLine (   line,
  endpos,
  depth,
  startchar,
  endchar 
)
Find position at the matching startchar.

This is almost the reverse of FindEndOfExpressionInLine, but note
that the input position and returned position differs by 1.

Args:
  line: a CleansedLines line.
  endpos: start searching at this position.
  depth: nesting level at endpos.
  startchar: expression opening character.
  endchar: expression closing character.

Returns:
  On finding matching startchar: (index at matching startchar, 0)
  Otherwise: (-1, new depth at beginning of this line)

Referenced by core.tools.cpplint.ReverseCloseExpression().

def core.tools.cpplint.GetHeaderGuardCPPVariable (   filename)
Returns the CPP variable that should be used as a header guard.

Args:
  filename: The name of a C++ header file.

Returns:
  The CPP variable that should be used as a header guard in the
  named file.

Referenced by core.tools.cpplint.CheckForHeaderGuard().

def core.tools.cpplint.RemoveMultiLineComments (   filename,
  lines,
  error 
)
Removes multiline (c-style) comments from lines.

References v.error, core.tools.cpplint.FindNextMultiLineCommentEnd(), core.tools.cpplint.FindNextMultiLineCommentStart(), and core.tools.cpplint.RemoveMultiLineCommentsFromRange().

Here is the call graph for this function:

def core.tools.cpplint.RemoveMultiLineCommentsFromRange (   lines,
  begin,
  end 
)
Clears a range of lines for multi-line comments.

Referenced by core.tools.cpplint.RemoveMultiLineComments().

def core.tools.cpplint.ReverseCloseExpression (   clean_lines,
  linenum,
  pos 
)
If input points to ) or } or ] or >, finds the position that opens it.

If lines[linenum][pos] points to a ')' or '}' or ']' or '>', finds the
linenum/pos that correspond to the opening of the expression.

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

Returns:
  A tuple (line, linenum, pos) pointer *at* the opening brace, or
  (line, 0, -1) if we never find the matching opening brace.  Note
  we ignore strings and comments when matching; and the line we
  return is the 'cleansed' line at linenum.

References core.tools.cpplint.FindStartOfExpressionInLine().

Here is the call graph for this function:

Variable Documentation

dictionary core.tools.cpplint._ALT_TOKEN_REPLACEMENT
Initial value:
1 = {
2  'and': '&&',
3  'bitor': '|',
4  'or': '||',
5  'xor': '^',
6  'compl': '~',
7  'bitand': '&',
8  'and_eq': '&=',
9  'or_eq': '|=',
10  'xor_eq': '^=',
11  'not': '!',
12  'not_eq': '!='
13  }
tuple core.tools.cpplint._ALT_TOKEN_REPLACEMENT_PATTERN
list core.tools.cpplint._CHECK_MACROS
Initial value:
1 = [
2  'DCHECK', 'CHECK',
3  'EXPECT_TRUE_M', 'EXPECT_TRUE',
4  'ASSERT_TRUE_M', 'ASSERT_TRUE',
5  'EXPECT_FALSE_M', 'EXPECT_FALSE',
6  'ASSERT_FALSE_M', 'ASSERT_FALSE',
7  ]
tuple core.tools.cpplint._CHECK_REPLACEMENT = dict([(m, {}) for m in _CHECK_MACROS])
tuple core.tools.cpplint._CPP_HEADERS
list core.tools.cpplint._DEFAULT_FILTERS = ['-build/include_alpha']
list core.tools.cpplint._ERROR_CATEGORIES
string core.tools.cpplint._USAGE