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

Function CheckSectionSpacing

scripts/cpp_lint.py:2995–3047  ·  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

2993
2994
2995def CheckSectionSpacing(filename, clean_lines, class_info, linenum, error):
2996 """Checks for additional blank line issues related to sections.
2997
2998 Currently the only thing checked here is blank line before protected/private.
2999
3000 Args:
3001 filename: The name of the current file.
3002 clean_lines: A CleansedLines instance containing the file.
3003 class_info: A _ClassInfo objects.
3004 linenum: The number of the line to check.
3005 error: The function to call with any errors found.
3006 """
3007 # Skip checks if the class is small, where small means 25 lines or less.
3008 # 25 lines seems like a good cutoff since that's the usual height of
3009 # terminals, and any class that can't fit in one screen can't really
3010 # be considered "small".
3011 #
3012 # Also skip checks if we are on the first line. This accounts for
3013 # classes that look like
3014 # class Foo { public: ... };
3015 #
3016 # If we didn't find the end of the class, last_line would be zero,
3017 # and the check will be skipped by the first condition.
3018 if (class_info.last_line - class_info.starting_linenum <= 24 or
3019 linenum <= class_info.starting_linenum):
3020 return
3021
3022 matched = Match(r'\s*(public|protected|private):', clean_lines.lines[linenum])
3023 if matched:
3024 # Issue warning if the line before public/protected/private was
3025 # not a blank line, but don't do this if the previous line contains
3026 # "class" or "struct". This can happen two ways:
3027 # - We are at the beginning of the class.
3028 # - We are forward-declaring an inner class that is semantically
3029 # private, but needed to be public for implementation reasons.
3030 # Also ignores cases where the previous line ends with a backslash as can be
3031 # common when defining classes in C macros.
3032 prev_line = clean_lines.lines[linenum - 1]
3033 if (not IsBlankLine(prev_line) and
3034 not Search(r'\b(class|struct)\b', prev_line) and
3035 not Search(r'\\$', prev_line)):
3036 # Try a bit harder to find the beginning of the class. This is to
3037 # account for multi-line base-specifier lists, e.g.:
3038 # class Derived
3039 # : public Base {
3040 end_class_head = class_info.starting_linenum
3041 for i in range(class_info.starting_linenum, linenum):
3042 if Search(r'\{\s*$', clean_lines.lines[i]):
3043 end_class_head = i
3044 break
3045 if end_class_head < linenum - 1:
3046 error(filename, linenum, 'whitespace/blank_line', 3,
3047 '"%s:" should be preceded by a blank line' % matched.group(1))
3048
3049
3050def GetPreviousNonBlankLine(clean_lines, linenum):

Callers 1

CheckStyleFunction · 0.85

Calls 3

MatchFunction · 0.85
IsBlankLineFunction · 0.85
SearchFunction · 0.85

Tested by

no test coverage detected