MCPcopy Create free account
hub / github.com/OpenPTrack/open_ptrack_v2 / CheckForFunctionLengths

Function CheckForFunctionLengths

rtpose_wrapper/scripts/cpp_lint.py:2384–2451  ·  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

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

Callers 1

ProcessLineFunction · 0.85

Calls 9

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

Tested by

no test coverage detected