MCPcopy Create free account
hub / github.com/alibaba/GraphScope / CheckCheck

Function CheckCheck

analytical_engine/misc/cpplint.py:4628–4743  ·  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

4626
4627
4628def CheckCheck(filename, clean_lines, linenum, error):
4629 """Checks the use of CHECK and EXPECT macros.
4630
4631 Args:
4632 filename: The name of the current file.
4633 clean_lines: A CleansedLines instance containing the file.
4634 linenum: The number of the line to check.
4635 error: The function to call with any errors found.
4636 """
4637
4638 # Decide the set of replacement macros that should be suggested
4639 lines = clean_lines.elided
4640 (check_macro, start_pos) = FindCheckMacro(lines[linenum])
4641 if not check_macro:
4642 return
4643
4644 # Find end of the boolean expression by matching parentheses
4645 (last_line, end_line, end_pos) = CloseExpression(
4646 clean_lines, linenum, start_pos)
4647 if end_pos < 0:
4648 return
4649
4650 # If the check macro is followed by something other than a
4651 # semicolon, assume users will log their own custom error messages
4652 # and don't suggest any replacements.
4653 if not Match(r'\s*;', last_line[end_pos:]):
4654 return
4655
4656 if linenum == end_line:
4657 expression = lines[linenum][start_pos + 1:end_pos - 1]
4658 else:
4659 expression = lines[linenum][start_pos + 1:]
4660 for i in xrange(linenum + 1, end_line):
4661 expression += lines[i]
4662 expression += last_line[0:end_pos - 1]
4663
4664 # Parse expression so that we can take parentheses into account.
4665 # This avoids false positives for inputs like "CHECK((a < 4) == b)",
4666 # which is not replaceable by CHECK_LE.
4667 lhs = ''
4668 rhs = ''
4669 operator = None
4670 while expression:
4671 matched = Match(r'^\s*(<<|<<=|>>|>>=|->\*|->|&&|\|\||'
4672 r'==|!=|>=|>|<=|<|\()(.*)$', expression)
4673 if matched:
4674 token = matched.group(1)
4675 if token == '(':
4676 # Parenthesized operand
4677 expression = matched.group(2)
4678 (end, _) = FindEndOfExpressionInLine(expression, 0, ['('])
4679 if end < 0:
4680 return # Unmatched parenthesis
4681 lhs += '(' + expression[0:end]
4682 expression = expression[end:]
4683 elif token in ('&&', '||'):
4684 # Logical and/or operators. This means the expression
4685 # contains more than one term, for example:

Callers 1

CheckStyleFunction · 0.85

Calls 6

FindCheckMacroFunction · 0.85
CloseExpressionFunction · 0.85
findMethod · 0.80
MatchFunction · 0.70
groupMethod · 0.45

Tested by

no test coverage detected