MCPcopy Create free account
hub / github.com/4paradigm/OpenMLDB / CheckRedundantVirtual

Function CheckRedundantVirtual

steps/cpplint.py:6191–6252  ·  view source on GitHub ↗

Check if line contains a redundant "virtual" function-specifier. 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

6189
6190
6191def CheckRedundantVirtual(filename, clean_lines, linenum, error):
6192 """Check if line contains a redundant "virtual" function-specifier.
6193
6194 Args:
6195 filename: The name of the current file.
6196 clean_lines: A CleansedLines instance containing the file.
6197 linenum: The number of the line to check.
6198 error: The function to call with any errors found.
6199 """
6200 # Look for "virtual" on current line.
6201 line = clean_lines.elided[linenum]
6202 virtual = Match(r'^(.*)(\bvirtual\b)(.*)$', line)
6203 if not virtual: return
6204
6205 # Ignore "virtual" keywords that are near access-specifiers. These
6206 # are only used in class base-specifier and do not apply to member
6207 # functions.
6208 if (Search(r'\b(public|protected|private)\s+$', virtual.group(1)) or
6209 Match(r'^\s+(public|protected|private)\b', virtual.group(3))):
6210 return
6211
6212 # Ignore the "virtual" keyword from virtual base classes. Usually
6213 # there is a column on the same line in these cases (virtual base
6214 # classes are rare in google3 because multiple inheritance is rare).
6215 if Match(r'^.*[^:]:[^:].*$', line): return
6216
6217 # Look for the next opening parenthesis. This is the start of the
6218 # parameter list (possibly on the next line shortly after virtual).
6219 # TODO(unknown): doesn't work if there are virtual functions with
6220 # decltype() or other things that use parentheses, but csearch suggests
6221 # that this is rare.
6222 end_col = -1
6223 end_line = -1
6224 start_col = len(virtual.group(2))
6225 for start_line in xrange(linenum, min(linenum + 3, clean_lines.NumLines())):
6226 line = clean_lines.elided[start_line][start_col:]
6227 parameter_list = Match(r'^([^(]*)\(', line)
6228 if parameter_list:
6229 # Match parentheses to find the end of the parameter list
6230 (_, end_line, end_col) = CloseExpression(
6231 clean_lines, start_line, start_col + len(parameter_list.group(1)))
6232 break
6233 start_col = 0
6234
6235 if end_col < 0:
6236 return # Couldn't find end of parameter list, give up
6237
6238 # Look for "override" or "final" after the parameter list
6239 # (possibly on the next few lines).
6240 for i in xrange(end_line, min(end_line + 3, clean_lines.NumLines())):
6241 line = clean_lines.elided[i][end_col:]
6242 match = Search(r'\b(override|final)\b', line)
6243 if match:
6244 error(filename, linenum, 'readability/inheritance', 4,
6245 ('"virtual" is redundant since function is '
6246 'already declared as "%s"' % match.group(1)))
6247
6248 # Set end_col to check whole lines after we are done with the

Callers 1

ProcessLineFunction · 0.85

Calls 4

MatchFunction · 0.85
SearchFunction · 0.85
CloseExpressionFunction · 0.85
NumLinesMethod · 0.80

Tested by

no test coverage detected