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

Function CheckSpacingForFunctionCall

rtpose_wrapper/scripts/cpp_lint.py:2301–2366  ·  view source on GitHub ↗

Checks for the correctness of various spacing around function calls. Args: filename: The name of the current file. line: The text of the line to check. linenum: The number of the line to check. error: The function to call with any errors found.

(filename, line, linenum, error)

Source from the content-addressed store, hash-verified

2299
2300
2301def CheckSpacingForFunctionCall(filename, line, linenum, error):
2302 """Checks for the correctness of various spacing around function calls.
2303
2304 Args:
2305 filename: The name of the current file.
2306 line: The text of the line to check.
2307 linenum: The number of the line to check.
2308 error: The function to call with any errors found.
2309 """
2310
2311 # Since function calls often occur inside if/for/while/switch
2312 # expressions - which have their own, more liberal conventions - we
2313 # first see if we should be looking inside such an expression for a
2314 # function call, to which we can apply more strict standards.
2315 fncall = line # if there's no control flow construct, look at whole line
2316 for pattern in (r'\bif\s*\((.*)\)\s*{',
2317 r'\bfor\s*\((.*)\)\s*{',
2318 r'\bwhile\s*\((.*)\)\s*[{;]',
2319 r'\bswitch\s*\((.*)\)\s*{'):
2320 match = Search(pattern, line)
2321 if match:
2322 fncall = match.group(1) # look inside the parens for function calls
2323 break
2324
2325 # Except in if/for/while/switch, there should never be space
2326 # immediately inside parens (eg "f( 3, 4 )"). We make an exception
2327 # for nested parens ( (a+b) + c ). Likewise, there should never be
2328 # a space before a ( when it's a function argument. I assume it's a
2329 # function argument when the char before the whitespace is legal in
2330 # a function name (alnum + _) and we're not starting a macro. Also ignore
2331 # pointers and references to arrays and functions coz they're too tricky:
2332 # we use a very simple way to recognize these:
2333 # " (something)(maybe-something)" or
2334 # " (something)(maybe-something," or
2335 # " (something)[something]"
2336 # Note that we assume the contents of [] to be short enough that
2337 # they'll never need to wrap.
2338 if ( # Ignore control structures.
2339 not Search(r'\b(if|for|while|switch|return|new|delete|catch|sizeof)\b',
2340 fncall) and
2341 # Ignore pointers/references to functions.
2342 not Search(r' \([^)]+\)\([^)]*(\)|,$)', fncall) and
2343 # Ignore pointers/references to arrays.
2344 not Search(r' \([^)]+\)\[[^\]]+\]', fncall)):
2345 if Search(r'\w\s*\(\s(?!\s*\\$)', fncall): # a ( used for a fn call
2346 error(filename, linenum, 'whitespace/parens', 4,
2347 'Extra space after ( in function call')
2348 elif Search(r'\(\s+(?!(\s*\\)|\()', fncall):
2349 error(filename, linenum, 'whitespace/parens', 2,
2350 'Extra space after (')
2351 if (Search(r'\w\s+\(', fncall) and
2352 not Search(r'#\s*define|typedef', fncall) and
2353 not Search(r'\w\s+\((\w+::)*\*\w+\)\(', fncall)):
2354 error(filename, linenum, 'whitespace/parens', 4,
2355 'Extra space before ( in function call')
2356 # If the ) is followed only by a newline or a { + newline, assume it's
2357 # part of a control statement (if/while/etc), and don't complain
2358 if Search(r'[^)]\s+\)\s*[^{\s]', fncall):

Callers 1

CheckSpacingFunction · 0.85

Calls 2

SearchFunction · 0.85
errorFunction · 0.85

Tested by

no test coverage detected