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

Function CheckCheck

steps/cpplint.py:4638–4753  ·  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

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

Callers 1

CheckStyleFunction · 0.85

Calls 4

FindCheckMacroFunction · 0.85
CloseExpressionFunction · 0.85
MatchFunction · 0.85

Tested by

no test coverage detected