MCPcopy Create free account
hub / github.com/BVLC/caffe / CheckForMultilineCommentsAndStrings

Function CheckForMultilineCommentsAndStrings

scripts/cpp_lint.py:1530–1565  ·  view source on GitHub ↗

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 continuatio

(filename, clean_lines, linenum, error)

Source from the content-addressed store, hash-verified

1528
1529
1530def CheckForMultilineCommentsAndStrings(filename, clean_lines, linenum, error):
1531 """Logs an error if we see /* ... */ or "..." that extend past one line.
1532
1533 /* ... */ comments are legit inside macros, for one line.
1534 Otherwise, we prefer // comments, so it's ok to warn about the
1535 other. Likewise, it's ok for strings to extend across multiple
1536 lines, as long as a line continuation character (backslash)
1537 terminates each line. Although not currently prohibited by the C++
1538 style guide, it's ugly and unnecessary. We don't do well with either
1539 in this lint program, so we warn about both.
1540
1541 Args:
1542 filename: The name of the current file.
1543 clean_lines: A CleansedLines instance containing the file.
1544 linenum: The number of the line to check.
1545 error: The function to call with any errors found.
1546 """
1547 line = clean_lines.elided[linenum]
1548
1549 # Remove all \\ (escaped backslashes) from the line. They are OK, and the
1550 # second (escaped) slash may trigger later \" detection erroneously.
1551 line = line.replace('\\\\', '')
1552
1553 if line.count('/*') > line.count('*/'):
1554 error(filename, linenum, 'readability/multiline_comment', 5,
1555 'Complex multi-line /*...*/-style comment found. '
1556 'Lint may give bogus warnings. '
1557 'Consider replacing these with //-style comments, '
1558 'with #if 0...#endif, '
1559 'or with more clearly structured multi-line comments.')
1560
1561 if (line.count('"') - line.count('\\"')) % 2:
1562 error(filename, linenum, 'readability/multiline_string', 5,
1563 'Multi-line string ("...") found. This lint script doesn\'t '
1564 'do well with such strings, and may give bogus warnings. '
1565 'Use C++11 raw strings or concatenation instead.')
1566
1567
1568caffe_alt_function_list = (

Callers 1

ProcessLineFunction · 0.85

Calls 1

countMethod · 0.80

Tested by

no test coverage detected