MCPcopy Create free account
hub / github.com/dmtcp/dmtcp / CheckSectionSpacing

Function CheckSectionSpacing

util/cpplint.py:3589–3641  ·  view source on GitHub ↗

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.

(filename, clean_lines, class_info, linenum, error)

Source from the content-addressed store, hash-verified

3587
3588
3589def CheckSectionSpacing(filename, clean_lines, class_info, linenum, error):
3590 """Checks for additional blank line issues related to sections.
3591
3592 Currently the only thing checked here is blank line before protected/private.
3593
3594 Args:
3595 filename: The name of the current file.
3596 clean_lines: A CleansedLines instance containing the file.
3597 class_info: A _ClassInfo objects.
3598 linenum: The number of the line to check.
3599 error: The function to call with any errors found.
3600 """
3601 # Skip checks if the class is small, where small means 25 lines or less.
3602 # 25 lines seems like a good cutoff since that's the usual height of
3603 # terminals, and any class that can't fit in one screen can't really
3604 # be considered "small".
3605 #
3606 # Also skip checks if we are on the first line. This accounts for
3607 # classes that look like
3608 # class Foo { public: ... };
3609 #
3610 # If we didn't find the end of the class, last_line would be zero,
3611 # and the check will be skipped by the first condition.
3612 if (class_info.last_line - class_info.starting_linenum <= 24 or
3613 linenum <= class_info.starting_linenum):
3614 return
3615
3616 matched = Match(r'\s*(public|protected|private):', clean_lines.lines[linenum])
3617 if matched:
3618 # Issue warning if the line before public/protected/private was
3619 # not a blank line, but don't do this if the previous line contains
3620 # "class" or "struct". This can happen two ways:
3621 # - We are at the beginning of the class.
3622 # - We are forward-declaring an inner class that is semantically
3623 # private, but needed to be public for implementation reasons.
3624 # Also ignores cases where the previous line ends with a backslash as can be
3625 # common when defining classes in C macros.
3626 prev_line = clean_lines.lines[linenum - 1]
3627 if (not IsBlankLine(prev_line) and
3628 not Search(r'\b(class|struct)\b', prev_line) and
3629 not Search(r'\\$', prev_line)):
3630 # Try a bit harder to find the beginning of the class. This is to
3631 # account for multi-line base-specifier lists, e.g.:
3632 # class Derived
3633 # : public Base {
3634 end_class_head = class_info.starting_linenum
3635 for i in range(class_info.starting_linenum, linenum):
3636 if Search(r'\{\s*$', clean_lines.lines[i]):
3637 end_class_head = i
3638 break
3639 if end_class_head < linenum - 1:
3640 error(filename, linenum, 'whitespace/blank_line', 3,
3641 '"%s:" should be preceded by a blank line' % matched.group(1))
3642
3643
3644def GetPreviousNonBlankLine(clean_lines, linenum):

Callers 1

CheckStyleFunction · 0.85

Calls 4

MatchFunction · 0.85
IsBlankLineFunction · 0.85
SearchFunction · 0.85
errorFunction · 0.85

Tested by

no test coverage detected