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

Function CheckForFunctionLengths

scripts/cpp_lint.py:2388–2455  ·  view source on GitHub ↗

Reports for long function bodies. For an overview why this is done, see: http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml#Write_Short_Functions Uses a simplistic algorithm assuming other style guidelines (especially spacing) are followed. Only checks unindented functions, s

(filename, clean_lines, linenum,
                            function_state, error)

Source from the content-addressed store, hash-verified

2386
2387
2388def CheckForFunctionLengths(filename, clean_lines, linenum,
2389 function_state, error):
2390 """Reports for long function bodies.
2391
2392 For an overview why this is done, see:
2393 http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml#Write_Short_Functions
2394
2395 Uses a simplistic algorithm assuming other style guidelines
2396 (especially spacing) are followed.
2397 Only checks unindented functions, so class members are unchecked.
2398 Trivial bodies are unchecked, so constructors with huge initializer lists
2399 may be missed.
2400 Blank/comment lines are not counted so as to avoid encouraging the removal
2401 of vertical space and comments just to get through a lint check.
2402 NOLINT *on the last line of a function* disables this check.
2403
2404 Args:
2405 filename: The name of the current file.
2406 clean_lines: A CleansedLines instance containing the file.
2407 linenum: The number of the line to check.
2408 function_state: Current function name and lines in body so far.
2409 error: The function to call with any errors found.
2410 """
2411 lines = clean_lines.lines
2412 line = lines[linenum]
2413 raw = clean_lines.raw_lines
2414 raw_line = raw[linenum]
2415 joined_line = ''
2416
2417 starting_func = False
2418 regexp = r'(\w(\w|::|\*|\&|\s)*)\(' # decls * & space::name( ...
2419 match_result = Match(regexp, line)
2420 if match_result:
2421 # If the name is all caps and underscores, figure it's a macro and
2422 # ignore it, unless it's TEST or TEST_F.
2423 function_name = match_result.group(1).split()[-1]
2424 if function_name == 'TEST' or function_name == 'TEST_F' or (
2425 not Match(r'[A-Z_]+$', function_name)):
2426 starting_func = True
2427
2428 if starting_func:
2429 body_found = False
2430 for start_linenum in xrange(linenum, clean_lines.NumLines()):
2431 start_line = lines[start_linenum]
2432 joined_line += ' ' + start_line.lstrip()
2433 if Search(r'(;|})', start_line): # Declarations and trivial functions
2434 body_found = True
2435 break # ... ignore
2436 elif Search(r'{', start_line):
2437 body_found = True
2438 function = Search(r'((\w|:)*)\(', line).group(1)
2439 if Match(r'TEST', function): # Handle TEST... macros
2440 parameter_regexp = Search(r'(\(.*\))', joined_line)
2441 if parameter_regexp: # Ignore bad syntax
2442 function += parameter_regexp.group(1)
2443 else:
2444 function += '()'
2445 function_state.Begin(function)

Callers 1

ProcessLineFunction · 0.85

Calls 7

MatchFunction · 0.85
SearchFunction · 0.85
NumLinesMethod · 0.80
CheckMethod · 0.80
CountMethod · 0.80
BeginMethod · 0.45
EndMethod · 0.45

Tested by

no test coverage detected