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

Function CheckEmptyBlockBody

scripts/cpp_lint.py:3247–3279  ·  view source on GitHub ↗

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.

(filename, clean_lines, linenum, error)

Source from the content-addressed store, hash-verified

3245
3246
3247def CheckEmptyBlockBody(filename, clean_lines, linenum, error):
3248 """Look for empty loop/conditional body with only a single semicolon.
3249
3250 Args:
3251 filename: The name of the current file.
3252 clean_lines: A CleansedLines instance containing the file.
3253 linenum: The number of the line to check.
3254 error: The function to call with any errors found.
3255 """
3256
3257 # Search for loop keywords at the beginning of the line. Because only
3258 # whitespaces are allowed before the keywords, this will also ignore most
3259 # do-while-loops, since those lines should start with closing brace.
3260 #
3261 # We also check "if" blocks here, since an empty conditional block
3262 # is likely an error.
3263 line = clean_lines.elided[linenum]
3264 matched = Match(r'\s*(for|while|if)\s*\(', line)
3265 if matched:
3266 # Find the end of the conditional expression
3267 (end_line, end_linenum, end_pos) = CloseExpression(
3268 clean_lines, linenum, line.find('('))
3269
3270 # Output warning if what follows the condition expression is a semicolon.
3271 # No warning for all other cases, including whitespace or newline, since we
3272 # have a separate check for semicolons preceded by whitespace.
3273 if end_pos >= 0 and Match(r';', end_line[end_pos:]):
3274 if matched.group(1) == 'if':
3275 error(filename, end_linenum, 'whitespace/empty_conditional_body', 5,
3276 'Empty conditional bodies should use {}')
3277 else:
3278 error(filename, end_linenum, 'whitespace/empty_loop_body', 5,
3279 'Empty loop bodies should use {} or continue')
3280
3281
3282def CheckCheck(filename, clean_lines, linenum, error):

Callers 1

CheckStyleFunction · 0.85

Calls 2

MatchFunction · 0.85
CloseExpressionFunction · 0.85

Tested by

no test coverage detected