MCPcopy Create free account
hub / github.com/apache/mesos / InTemplateArgumentList

Method InTemplateArgumentList

support/cpplint.py:2478–2528  ·  view source on GitHub ↗

Check if current position is inside template argument list. Args: clean_lines: A CleansedLines instance containing the file. linenum: The number of the line to check. pos: position just after the suspected template argument. Returns: True if (linenum, pos) is inside

(self, clean_lines, linenum, pos)

Source from the content-addressed store, hash-verified

2476 return self.stack and self.stack[-1].inline_asm != _NO_ASM
2477
2478 def InTemplateArgumentList(self, clean_lines, linenum, pos):
2479 """Check if current position is inside template argument list.
2480
2481 Args:
2482 clean_lines: A CleansedLines instance containing the file.
2483 linenum: The number of the line to check.
2484 pos: position just after the suspected template argument.
2485 Returns:
2486 True if (linenum, pos) is inside template arguments.
2487 """
2488 while linenum < clean_lines.NumLines():
2489 # Find the earliest character that might indicate a template argument
2490 line = clean_lines.elided[linenum]
2491 match = Match(r'^[^{};=\[\]\.<>]*(.)', line[pos:])
2492 if not match:
2493 linenum += 1
2494 pos = 0
2495 continue
2496 token = match.group(1)
2497 pos += len(match.group(0))
2498
2499 # These things do not look like template argument list:
2500 # class Suspect {
2501 # class Suspect x; }
2502 if token in ('{', '}', ';'): return False
2503
2504 # These things look like template argument list:
2505 # template <class Suspect>
2506 # template <class Suspect = default_value>
2507 # template <class Suspect[]>
2508 # template <class Suspect...>
2509 if token in ('>', '=', '[', ']', '.'): return True
2510
2511 # Check if token is an unmatched '<'.
2512 # If not, move on to the next character.
2513 if token != '<':
2514 pos += 1
2515 if pos >= len(line):
2516 linenum += 1
2517 pos = 0
2518 continue
2519
2520 # We can't be sure if we just find a single '<', and need to
2521 # find the matching '>'.
2522 (_, end_line, end_pos) = CloseExpression(clean_lines, linenum, pos - 1)
2523 if end_pos < 0:
2524 # Not sure if template argument list or syntax error in file
2525 return False
2526 linenum = end_line
2527 pos = end_pos
2528 return False
2529
2530 def UpdatePreprocessor(self, line):
2531 """Update preprocessor stack.

Callers 1

UpdateMethod · 0.95

Calls 3

MatchFunction · 0.85
CloseExpressionFunction · 0.85
NumLinesMethod · 0.80

Tested by

no test coverage detected