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

Function CheckCheck

rtpose_wrapper/scripts/cpp_lint.py:3278–3402  ·  view source on GitHub ↗

Checks the use of CHECK and EXPECT macros. 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

3276
3277
3278def CheckCheck(filename, clean_lines, linenum, error):
3279 """Checks the use of CHECK and EXPECT macros.
3280
3281 Args:
3282 filename: The name of the current file.
3283 clean_lines: A CleansedLines instance containing the file.
3284 linenum: The number of the line to check.
3285 error: The function to call with any errors found.
3286 """
3287
3288 # Decide the set of replacement macros that should be suggested
3289 lines = clean_lines.elided
3290 check_macro = None
3291 start_pos = -1
3292 for macro in _CHECK_MACROS:
3293 i = lines[linenum].find(macro)
3294 if i >= 0:
3295 check_macro = macro
3296
3297 # Find opening parenthesis. Do a regular expression match here
3298 # to make sure that we are matching the expected CHECK macro, as
3299 # opposed to some other macro that happens to contain the CHECK
3300 # substring.
3301 matched = Match(r'^(.*\b' + check_macro + r'\s*)\(', lines[linenum])
3302 if not matched:
3303 continue
3304 start_pos = len(matched.group(1))
3305 break
3306 if not check_macro or start_pos < 0:
3307 # Don't waste time here if line doesn't contain 'CHECK' or 'EXPECT'
3308 return
3309
3310 # Find end of the boolean expression by matching parentheses
3311 (last_line, end_line, end_pos) = CloseExpression(
3312 clean_lines, linenum, start_pos)
3313 if end_pos < 0:
3314 return
3315 if linenum == end_line:
3316 expression = lines[linenum][start_pos + 1:end_pos - 1]
3317 else:
3318 expression = lines[linenum][start_pos + 1:]
3319 for i in xrange(linenum + 1, end_line):
3320 expression += lines[i]
3321 expression += last_line[0:end_pos - 1]
3322
3323 # Parse expression so that we can take parentheses into account.
3324 # This avoids false positives for inputs like "CHECK((a < 4) == b)",
3325 # which is not replaceable by CHECK_LE.
3326 lhs = ''
3327 rhs = ''
3328 operator = None
3329 while expression:
3330 matched = Match(r'^\s*(<<|<<=|>>|>>=|->\*|->|&&|\|\||'
3331 r'==|!=|>=|>|<=|<|\()(.*)$', expression)
3332 if matched:
3333 token = matched.group(1)
3334 if token == '(':
3335 # Parenthesized operand

Callers 1

CheckStyleFunction · 0.85

Calls 4

MatchFunction · 0.85
CloseExpressionFunction · 0.85
errorFunction · 0.85

Tested by

no test coverage detected