MCPcopy Create free account
hub / github.com/tensorflow/tfjs / CheckCheck

Function CheckCheck

tfjs-backend-wasm/tools/cpplint.py:4129–4244  ·  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

4127
4128
4129def CheckCheck(filename, clean_lines, linenum, error):
4130 """Checks the use of CHECK and EXPECT macros.
4131
4132 Args:
4133 filename: The name of the current file.
4134 clean_lines: A CleansedLines instance containing the file.
4135 linenum: The number of the line to check.
4136 error: The function to call with any errors found.
4137 """
4138
4139 # Decide the set of replacement macros that should be suggested
4140 lines = clean_lines.elided
4141 (check_macro, start_pos) = FindCheckMacro(lines[linenum])
4142 if not check_macro:
4143 return
4144
4145 # Find end of the boolean expression by matching parentheses
4146 (last_line, end_line, end_pos) = CloseExpression(
4147 clean_lines, linenum, start_pos)
4148 if end_pos < 0:
4149 return
4150
4151 # If the check macro is followed by something other than a
4152 # semicolon, assume users will log their own custom error messages
4153 # and don't suggest any replacements.
4154 if not Match(r'\s*;', last_line[end_pos:]):
4155 return
4156
4157 if linenum == end_line:
4158 expression = lines[linenum][start_pos + 1:end_pos - 1]
4159 else:
4160 expression = lines[linenum][start_pos + 1:]
4161 for i in xrange(linenum + 1, end_line):
4162 expression += lines[i]
4163 expression += last_line[0:end_pos - 1]
4164
4165 # Parse expression so that we can take parentheses into account.
4166 # This avoids false positives for inputs like "CHECK((a < 4) == b)",
4167 # which is not replaceable by CHECK_LE.
4168 lhs = ''
4169 rhs = ''
4170 operator = None
4171 while expression:
4172 matched = Match(r'^\s*(<<|<<=|>>|>>=|->\*|->|&&|\|\||'
4173 r'==|!=|>=|>|<=|<|\()(.*)$', expression)
4174 if matched:
4175 token = matched.group(1)
4176 if token == '(':
4177 # Parenthesized operand
4178 expression = matched.group(2)
4179 (end, _) = FindEndOfExpressionInLine(expression, 0, ['('])
4180 if end < 0:
4181 return # Unmatched parenthesis
4182 lhs += '(' + expression[0:end]
4183 expression = expression[end:]
4184 elif token in ('&&', '||'):
4185 # Logical and/or operators. This means the expression
4186 # contains more than one term, for example:

Callers 1

CheckStyleFunction · 0.85

Calls 5

FindCheckMacroFunction · 0.85
CloseExpressionFunction · 0.85
MatchFunction · 0.85
findMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…