MCPcopy Create free account
hub / github.com/SIPp/sipp / CheckForFunctionLengths

Function CheckForFunctionLengths

cpplint.py:1939–2006  ·  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

1937
1938
1939def CheckForFunctionLengths(filename, clean_lines, linenum,
1940 function_state, error):
1941 """Reports for long function bodies.
1942
1943 For an overview why this is done, see:
1944 http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml#Write_Short_Functions
1945
1946 Uses a simplistic algorithm assuming other style guidelines
1947 (especially spacing) are followed.
1948 Only checks unindented functions, so class members are unchecked.
1949 Trivial bodies are unchecked, so constructors with huge initializer lists
1950 may be missed.
1951 Blank/comment lines are not counted so as to avoid encouraging the removal
1952 of vertical space and comments just to get through a lint check.
1953 NOLINT *on the last line of a function* disables this check.
1954
1955 Args:
1956 filename: The name of the current file.
1957 clean_lines: A CleansedLines instance containing the file.
1958 linenum: The number of the line to check.
1959 function_state: Current function name and lines in body so far.
1960 error: The function to call with any errors found.
1961 """
1962 lines = clean_lines.lines
1963 line = lines[linenum]
1964 raw = clean_lines.raw_lines
1965 raw_line = raw[linenum]
1966 joined_line = ''
1967
1968 starting_func = False
1969 regexp = r'(\w(\w|::|\*|\&|\s)*)\(' # decls * & space::name( ...
1970 match_result = Match(regexp, line)
1971 if match_result:
1972 # If the name is all caps and underscores, figure it's a macro and
1973 # ignore it, unless it's TEST or TEST_F.
1974 function_name = match_result.group(1).split()[-1]
1975 if function_name == 'TEST' or function_name == 'TEST_F' or (
1976 not Match(r'[A-Z_]+$', function_name)):
1977 starting_func = True
1978
1979 if starting_func:
1980 body_found = False
1981 for start_linenum in xrange(linenum, clean_lines.NumLines()):
1982 start_line = lines[start_linenum]
1983 joined_line += ' ' + start_line.lstrip()
1984 if Search(r'(;|})', start_line): # Declarations and trivial functions
1985 body_found = True
1986 break # ... ignore
1987 elif Search(r'{', start_line):
1988 body_found = True
1989 function = Search(r'((\w|:)*)\(', line).group(1)
1990 if Match(r'TEST', function): # Handle TEST... macros
1991 parameter_regexp = Search(r'(\(.*\))', joined_line)
1992 if parameter_regexp: # Ignore bad syntax
1993 function += parameter_regexp.group(1)
1994 else:
1995 function += '()'
1996 function_state.Begin(function)

Callers 1

ProcessLineFunction · 0.85

Calls 7

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

Tested by

no test coverage detected