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

Function CheckForFunctionLengths

util/cpplint.py:2950–3015  ·  view source on GitHub ↗

Reports for long function bodies. For an overview why this is done, see: https://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,

(filename, clean_lines, linenum,
                            function_state, error)

Source from the content-addressed store, hash-verified

2948
2949
2950def CheckForFunctionLengths(filename, clean_lines, linenum,
2951 function_state, error):
2952 """Reports for long function bodies.
2953
2954 For an overview why this is done, see:
2955 https://google-styleguide.googlecode.com/svn/trunk/cppguide.xml#Write_Short_Functions
2956
2957 Uses a simplistic algorithm assuming other style guidelines
2958 (especially spacing) are followed.
2959 Only checks unindented functions, so class members are unchecked.
2960 Trivial bodies are unchecked, so constructors with huge initializer lists
2961 may be missed.
2962 Blank/comment lines are not counted so as to avoid encouraging the removal
2963 of vertical space and comments just to get through a lint check.
2964 NOLINT *on the last line of a function* disables this check.
2965
2966 Args:
2967 filename: The name of the current file.
2968 clean_lines: A CleansedLines instance containing the file.
2969 linenum: The number of the line to check.
2970 function_state: Current function name and lines in body so far.
2971 error: The function to call with any errors found.
2972 """
2973 lines = clean_lines.lines
2974 line = lines[linenum]
2975 joined_line = ''
2976
2977 starting_func = False
2978 regexp = r'(\w(\w|::|\*|\&|\s)*)\(' # decls * & space::name( ...
2979 match_result = Match(regexp, line)
2980 if match_result:
2981 # If the name is all caps and underscores, figure it's a macro and
2982 # ignore it, unless it's TEST or TEST_F.
2983 function_name = match_result.group(1).split()[-1]
2984 if function_name == 'TEST' or function_name == 'TEST_F' or (
2985 not Match(r'[A-Z_]+$', function_name)):
2986 starting_func = True
2987
2988 if starting_func:
2989 body_found = False
2990 for start_linenum in range(linenum, clean_lines.NumLines()):
2991 start_line = lines[start_linenum]
2992 joined_line += ' ' + start_line.lstrip()
2993 if Search(r'(;|})', start_line): # Declarations and trivial functions
2994 body_found = True
2995 break # ... ignore
2996 elif Search(r'{', start_line):
2997 body_found = True
2998 function = Search(r'((\w|:)*)\(', line).group(1)
2999 if Match(r'TEST', function): # Handle TEST... macros
3000 parameter_regexp = Search(r'(\(.*\))', joined_line)
3001 if parameter_regexp: # Ignore bad syntax
3002 function += parameter_regexp.group(1)
3003 else:
3004 function += '()'
3005 function_state.Begin(function)
3006 break
3007 if not body_found:

Callers 1

ProcessLineFunction · 0.85

Calls 8

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

Tested by

no test coverage detected